Skip to content

Commit

Permalink
[Gin] Add feature to control optimization in V8.
Browse files Browse the repository at this point in the history
Change-Id: I7ff3a987d132d4ca8e0f350e851020b53d4fb009
Reviewed-on: https://chromium-review.googlesource.com/980947
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Mythri Alle <mythria@chromium.org>
Cr-Commit-Position: refs/heads/master@{#546143}
  • Loading branch information
rmcilroy authored and Commit Bot committed Mar 27, 2018
1 parent c184793 commit 45e9500
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions gin/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ component("gin") {
"function_template.cc",
"function_template.h",
"gin_export.h",
"gin_features.cc",
"gin_features.h",
"handle.h",
"interceptor.cc",
"interceptor.h",
Expand Down
13 changes: 13 additions & 0 deletions gin/gin_features.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "gin/gin_features.h"

namespace features {

// Enables optimization of JavaScript in V8.
const base::Feature kV8OptimizeJavascript{"V8OptimizeJavascript",
base::FEATURE_ENABLED_BY_DEFAULT};

} // namespace features
17 changes: 17 additions & 0 deletions gin/gin_features.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef GIN_GIN_FEATURES_H_
#define GIN_GIN_FEATURES_H_

#include "base/feature_list.h"
#include "gin/gin_export.h"

namespace features {

GIN_EXPORT extern const base::Feature kV8OptimizeJavascript;

} // namespace features

#endif // GIN_GIN_FEATURES_H_
9 changes: 9 additions & 0 deletions gin/v8_initializer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "base/threading/platform_thread.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "gin/gin_features.h"

#if defined(V8_USE_EXTERNAL_STARTUP_DATA)
#if defined(OS_ANDROID)
Expand Down Expand Up @@ -242,6 +243,14 @@ void V8Initializer::Initialize(IsolateHolder::ScriptMode mode,

v8::V8::InitializePlatform(V8Platform::Get());

if (base::FeatureList::IsEnabled(features::kV8OptimizeJavascript)) {
static const char optimize[] = "--opt";
v8::V8::SetFlagsFromString(optimize, sizeof(optimize) - 1);
} else {
static const char no_optimize[] = "--no-opt";
v8::V8::SetFlagsFromString(no_optimize, sizeof(no_optimize) - 1);
}

if (IsolateHolder::kStrictMode == mode) {
static const char use_strict[] = "--use_strict";
v8::V8::SetFlagsFromString(use_strict, sizeof(use_strict) - 1);
Expand Down

0 comments on commit 45e9500

Please sign in to comment.