Commit 6f582f08 authored by domenic's avatar domenic Committed by Commit bot

Add experimental, non-snapshotted V8 extras

Embedders would use these for features which must be able to be turned
off at runtime, despite being compiled into V8. They can be turned on
and off by the embedder using the --experimental_extras flag, e.g. via
v8::SetFlagsFromString.

R=yangguo@chromium.org, mlippautz@chromium.org, hpayer@chromium.org
BUG=chromium:507137
LOG=Y

Review URL: https://codereview.chromium.org/1284413002

Cr-Commit-Position: refs/heads/master@{#30260}
parent de26ce05
......@@ -367,6 +367,36 @@ action("js2c_extras") {
}
}
action("js2c_experimental_extras") {
visibility = [ ":*" ] # Only targets in this file can depend on this.
script = "tools/js2c.py"
# The script depends on this other script, this rule causes a rebuild if it
# changes.
inputs = [ "tools/jsmin.py" ]
sources = v8_experimental_extra_library_files
outputs = [
"$target_gen_dir/experimental-extras-libraries.cc",
]
args = [
rebase_path("$target_gen_dir/experimental-extras-libraries.cc",
root_build_dir),
"EXPERIMENTAL_EXTRAS",
] + rebase_path(sources, root_build_dir)
if (v8_use_external_startup_data) {
outputs += [ "$target_gen_dir/libraries_experimental_extras.bin" ]
args += [
"--startup_blob",
rebase_path("$target_gen_dir/libraries_experimental_extras.bin", root_build_dir),
]
}
}
action("d8_js2c") {
visibility = [ ":*" ] # Only targets in this file can depend on this.
......@@ -394,6 +424,7 @@ if (v8_use_external_startup_data) {
":js2c_code_stubs",
":js2c_experimental",
":js2c_extras",
":js2c_experimental_extras",
]
sources = [
......@@ -401,6 +432,7 @@ if (v8_use_external_startup_data) {
"$target_gen_dir/libraries_code_stub.bin",
"$target_gen_dir/libraries_experimental.bin",
"$target_gen_dir/libraries_extras.bin",
"$target_gen_dir/libraries_experimental_extras.bin",
]
outputs = [
......@@ -487,6 +519,7 @@ source_set("v8_nosnapshot") {
":js2c_code_stubs",
":js2c_experimental",
":js2c_extras",
":js2c_experimental_extras",
":v8_base",
]
......@@ -495,6 +528,7 @@ source_set("v8_nosnapshot") {
"$target_gen_dir/code-stub-libraries.cc",
"$target_gen_dir/experimental-libraries.cc",
"$target_gen_dir/extras-libraries.cc",
"$target_gen_dir/experimental-extras-libraries.cc",
"src/snapshot/snapshot-empty.cc",
]
......@@ -520,6 +554,7 @@ source_set("v8_snapshot") {
":js2c_code_stubs",
":js2c_experimental",
":js2c_extras",
":js2c_experimental_extras",
":v8_base",
]
public_deps = [
......@@ -533,6 +568,7 @@ source_set("v8_snapshot") {
"$target_gen_dir/code-stub-libraries.cc",
"$target_gen_dir/experimental-libraries.cc",
"$target_gen_dir/extras-libraries.cc",
"$target_gen_dir/experimental-extras-libraries.cc",
"$target_gen_dir/snapshot.cc",
]
......@@ -554,6 +590,7 @@ if (v8_use_external_startup_data) {
":js2c_code_stubs",
":js2c_experimental",
":js2c_extras",
":js2c_experimental_extras",
":v8_base",
]
public_deps = [
......
......@@ -144,8 +144,9 @@
'cfi_vptr%': '<(cfi_vptr)',
'cfi_diag%': '<(cfi_diag)',
# Add a simple extra solely for the purpose of the cctests
# Add a simple extras solely for the purpose of the cctests
'v8_extra_library_files': ['../test/cctest/test-extra.js'],
'v8_experimental_extra_library_files': ['../test/cctest/test-experimental-extra.js'],
# .gyp files or targets should set v8_code to 1 if they build V8 specific
# code, as opposed to external code. This variable is used to control such
......
......@@ -51,6 +51,8 @@ Handle<String> Bootstrapper::SourceLookup(int index) {
template Handle<String> Bootstrapper::SourceLookup<Natives>(int index);
template Handle<String> Bootstrapper::SourceLookup<ExperimentalNatives>(
int index);
template Handle<String> Bootstrapper::SourceLookup<ExperimentalExtraNatives>(
int index);
template Handle<String> Bootstrapper::SourceLookup<ExtraNatives>(int index);
template Handle<String> Bootstrapper::SourceLookup<CodeStubNatives>(int index);
......@@ -121,7 +123,10 @@ void Bootstrapper::TearDown() {
DeleteNativeSources(Natives::GetSourceCache(isolate_->heap()));
DeleteNativeSources(ExperimentalNatives::GetSourceCache(isolate_->heap()));
DeleteNativeSources(ExtraNatives::GetSourceCache(isolate_->heap()));
DeleteNativeSources(
ExperimentalExtraNatives::GetSourceCache(isolate_->heap()));
DeleteNativeSources(CodeStubNatives::GetSourceCache(isolate_->heap()));
extensions_cache_.Initialize(isolate_, false); // Yes, symmetrical
}
......@@ -206,6 +211,7 @@ class Genesis BASE_EMBEDDED {
Handle<JSFunction>* fun);
bool InstallExperimentalNatives();
bool InstallExtraNatives();
bool InstallExperimentalExtraNatives();
bool InstallDebuggerNatives();
void InstallBuiltinFunctionIds();
void InstallExperimentalBuiltinFunctionIds();
......@@ -1532,6 +1538,21 @@ bool Bootstrapper::CompileExtraBuiltin(Isolate* isolate, int index) {
}
bool Bootstrapper::CompileExperimentalExtraBuiltin(Isolate* isolate,
int index) {
HandleScope scope(isolate);
Vector<const char> name = ExperimentalExtraNatives::GetScriptName(index);
Handle<String> source_code =
isolate->bootstrapper()->SourceLookup<ExperimentalExtraNatives>(index);
Handle<Object> global = isolate->global_object();
Handle<Object> binding = isolate->extras_binding_object();
Handle<Object> args[] = {global, binding};
return Bootstrapper::CompileNative(
isolate, name, Handle<JSObject>(isolate->native_context()->builtins()),
source_code, arraysize(args), args);
}
bool Bootstrapper::CompileCodeStubBuiltin(Isolate* isolate, int index) {
HandleScope scope(isolate);
Vector<const char> name = CodeStubNatives::GetScriptName(index);
......@@ -2638,6 +2659,17 @@ bool Genesis::InstallExtraNatives() {
}
bool Genesis::InstallExperimentalExtraNatives() {
for (int i = ExperimentalExtraNatives::GetDebuggerCount();
i < ExperimentalExtraNatives::GetBuiltinsCount(); i++) {
if (!Bootstrapper::CompileExperimentalExtraBuiltin(isolate(), i))
return false;
}
return true;
}
bool Genesis::InstallDebuggerNatives() {
for (int i = 0; i < Natives::GetDebuggerCount(); ++i) {
if (!Bootstrapper::CompileBuiltin(isolate(), i)) return false;
......@@ -3237,6 +3269,11 @@ Genesis::Genesis(Isolate* isolate,
if (!isolate->serializer_enabled()) {
InitializeExperimentalGlobal();
if (!InstallExperimentalNatives()) return;
if (FLAG_experimental_extras) {
if (!InstallExperimentalExtraNatives()) return;
}
// By now the utils object is useless and can be removed.
native_context()->set_natives_utils_object(
isolate->heap()->undefined_value());
......
......@@ -115,6 +115,7 @@ class Bootstrapper final {
static bool CompileBuiltin(Isolate* isolate, int index);
static bool CompileExperimentalBuiltin(Isolate* isolate, int index);
static bool CompileExtraBuiltin(Isolate* isolate, int index);
static bool CompileExperimentalExtraBuiltin(Isolate* isolate, int index);
static bool CompileCodeStubBuiltin(Isolate* isolate, int index);
static bool InstallCodeStubNatives(Isolate* isolate);
......
......@@ -167,6 +167,9 @@ struct MaybeBoolFlag {
//
#define FLAG FLAG_FULL
DEFINE_BOOL(experimental_extras, false,
"enable code compiled in via v8_experimental_extra_library_files")
// Flags for language modes and experimental language features.
DEFINE_BOOL(use_strict, false, "enforce strict mode")
DEFINE_BOOL(use_strong, false, "enforce strong mode")
......
......@@ -3307,6 +3307,9 @@ void Heap::CreateInitialObjects() {
set_extra_natives_source_cache(
*factory->NewFixedArray(ExtraNatives::GetBuiltinsCount()));
set_experimental_extra_natives_source_cache(
*factory->NewFixedArray(ExperimentalExtraNatives::GetBuiltinsCount()));
set_code_stub_natives_source_cache(
*factory->NewFixedArray(CodeStubNatives::GetBuiltinsCount()));
......
......@@ -162,6 +162,8 @@ namespace internal {
V(FixedArray, experimental_natives_source_cache, \
ExperimentalNativesSourceCache) \
V(FixedArray, extra_natives_source_cache, ExtraNativesSourceCache) \
V(FixedArray, experimental_extra_natives_source_cache, \
ExperimentalExtraNativesSourceCache) \
V(FixedArray, code_stub_natives_source_cache, CodeStubNativesSourceCache) \
V(Script, empty_script, EmptyScript) \
V(NameDictionary, intrinsic_function_names, IntrinsicFunctionNames) \
......
......@@ -29,6 +29,12 @@ FixedArray* NativesCollection<EXTRAS>::GetSourceCache(Heap* heap) {
}
template <>
FixedArray* NativesCollection<EXPERIMENTAL_EXTRAS>::GetSourceCache(Heap* heap) {
return heap->experimental_extra_natives_source_cache();
}
template <>
FixedArray* NativesCollection<CODE_STUB>::GetSourceCache(Heap* heap) {
return heap->code_stub_natives_source_cache();
......@@ -51,6 +57,8 @@ template void NativesCollection<CORE>::UpdateSourceCache(Heap* heap);
template void NativesCollection<CODE_STUB>::UpdateSourceCache(Heap* heap);
template void NativesCollection<EXPERIMENTAL>::UpdateSourceCache(Heap* heap);
template void NativesCollection<EXTRAS>::UpdateSourceCache(Heap* heap);
template void NativesCollection<EXPERIMENTAL_EXTRAS>::UpdateSourceCache(
Heap* heap);
} // namespace internal
} // namespace v8
......@@ -161,6 +161,8 @@ void ReadNatives() {
NativesHolder<EXPERIMENTAL>::set(
NativesStore::MakeFromScriptsSource(&bytes));
NativesHolder<EXTRAS>::set(NativesStore::MakeFromScriptsSource(&bytes));
NativesHolder<EXPERIMENTAL_EXTRAS>::set(
NativesStore::MakeFromScriptsSource(&bytes));
DCHECK(!bytes.HasMore());
}
}
......@@ -189,6 +191,7 @@ void DisposeNatives() {
NativesHolder<CODE_STUB>::Dispose();
NativesHolder<EXPERIMENTAL>::Dispose();
NativesHolder<EXTRAS>::Dispose();
NativesHolder<EXPERIMENTAL_EXTRAS>::Dispose();
}
......@@ -241,6 +244,7 @@ INSTANTIATE_TEMPLATES(CORE)
INSTANTIATE_TEMPLATES(CODE_STUB)
INSTANTIATE_TEMPLATES(EXPERIMENTAL)
INSTANTIATE_TEMPLATES(EXTRAS)
INSTANTIATE_TEMPLATES(EXPERIMENTAL_EXTRAS)
#undef INSTANTIATE_TEMPLATES
} // namespace internal
......
......@@ -13,7 +13,15 @@ namespace v8 { class StartupData; } // Forward declaration.
namespace v8 {
namespace internal {
enum NativeType { CORE, CODE_STUB, EXPERIMENTAL, EXTRAS, D8, TEST };
enum NativeType {
CORE,
CODE_STUB,
EXPERIMENTAL,
EXTRAS,
EXPERIMENTAL_EXTRAS,
D8,
TEST
};
template <NativeType type>
class NativesCollection {
......@@ -44,6 +52,7 @@ typedef NativesCollection<CORE> Natives;
typedef NativesCollection<CODE_STUB> CodeStubNatives;
typedef NativesCollection<EXPERIMENTAL> ExperimentalNatives;
typedef NativesCollection<EXTRAS> ExtraNatives;
typedef NativesCollection<EXPERIMENTAL_EXTRAS> ExperimentalExtraNatives;
#ifdef V8_USE_EXTERNAL_STARTUP_DATA
......
......@@ -21616,14 +21616,14 @@ TEST(StrongObjectDelete) {
}
static void ExtrasExportsTestRuntimeFunction(
static void ExtrasBindingTestRuntimeFunction(
const v8::FunctionCallbackInfo<v8::Value>& args) {
CHECK_EQ(3, args[0]->Int32Value());
args.GetReturnValue().Set(v8_num(7));
}
TEST(ExtrasExportsObject) {
TEST(ExtrasBindingObject) {
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope handle_scope(isolate);
LocalContext env;
......@@ -21639,7 +21639,7 @@ TEST(ExtrasExportsObject) {
CHECK_EQ(5, result->Int32Value());
v8::Handle<v8::FunctionTemplate> runtimeFunction =
v8::FunctionTemplate::New(isolate, ExtrasExportsTestRuntimeFunction);
v8::FunctionTemplate::New(isolate, ExtrasBindingTestRuntimeFunction);
binding->Set(v8_str("runtime"), runtimeFunction->GetFunction());
func =
binding->Get(v8_str("testExtraShouldCallToRuntime")).As<v8::Function>();
......@@ -21648,6 +21648,33 @@ TEST(ExtrasExportsObject) {
}
TEST(ExperimentalExtras) {
i::FLAG_experimental_extras = true;
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope handle_scope(isolate);
LocalContext env;
// standalone.gypi ensures we include the test-experimental-extra.js file,
// which should export the tested functions.
v8::Local<v8::Object> binding = env->GetExtrasBindingObject();
auto func = binding->Get(v8_str("testExperimentalExtraShouldReturnTen"))
.As<v8::Function>();
auto undefined = v8::Undefined(isolate);
auto result = func->Call(undefined, 0, {}).As<v8::Number>();
CHECK_EQ(10, result->Int32Value());
v8::Handle<v8::FunctionTemplate> runtimeFunction =
v8::FunctionTemplate::New(isolate, ExtrasBindingTestRuntimeFunction);
binding->Set(v8_str("runtime"), runtimeFunction->GetFunction());
func = binding->Get(v8_str("testExperimentalExtraShouldCallToRuntime"))
.As<v8::Function>();
result = func->Call(undefined, 0, {}).As<v8::Number>();
CHECK_EQ(7, result->Int32Value());
}
TEST(Map) {
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope handle_scope(isolate);
......
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
(function (global, binding) {
'use strict';
binding.testExperimentalExtraShouldReturnTen = function () {
return 10;
};
binding.testExperimentalExtraShouldCallToRuntime = function() {
return binding.runtime(3);
};
})
......@@ -32,6 +32,7 @@
'v8_random_seed%': 314159265,
'embed_script%': "",
'v8_extra_library_files%': [],
'v8_experimental_extra_library_files%': [],
'mksnapshot_exec': '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)mksnapshot<(EXECUTABLE_SUFFIX)',
},
'includes': ['../../build/toolchain.gypi', '../../build/features.gypi'],
......@@ -182,6 +183,7 @@
'<(SHARED_INTERMEDIATE_DIR)/code-stub-libraries.cc',
'<(SHARED_INTERMEDIATE_DIR)/experimental-libraries.cc',
'<(SHARED_INTERMEDIATE_DIR)/extras-libraries.cc',
'<(SHARED_INTERMEDIATE_DIR)/experimental-extras-libraries.cc',
'<(INTERMEDIATE_DIR)/snapshot.cc',
],
'actions': [
......@@ -228,6 +230,7 @@
'<(SHARED_INTERMEDIATE_DIR)/code-stub-libraries.cc',
'<(SHARED_INTERMEDIATE_DIR)/experimental-libraries.cc',
'<(SHARED_INTERMEDIATE_DIR)/extras-libraries.cc',
'<(SHARED_INTERMEDIATE_DIR)/experimental-extras-libraries.cc',
'../../src/snapshot/snapshot-empty.cc',
],
'conditions': [
......@@ -1714,6 +1717,7 @@
'<(SHARED_INTERMEDIATE_DIR)/libraries-code-stub.bin',
'<(SHARED_INTERMEDIATE_DIR)/libraries-experimental.bin',
'<(SHARED_INTERMEDIATE_DIR)/libraries-extras.bin',
'<(SHARED_INTERMEDIATE_DIR)/libraries-experimental-extras.bin',
],
'conditions': [
['want_separate_host_toolset==1', {
......@@ -1834,6 +1838,7 @@
'libraries_code_stub_bin_file': '<(SHARED_INTERMEDIATE_DIR)/libraries-code-stub.bin',
'libraries_experimental_bin_file': '<(SHARED_INTERMEDIATE_DIR)/libraries-experimental.bin',
'libraries_extras_bin_file': '<(SHARED_INTERMEDIATE_DIR)/libraries-extras.bin',
'libraries_experimental_extras_bin_file': '<(SHARED_INTERMEDIATE_DIR)/libraries-experimental-extras.bin',
},
'actions': [
{
......@@ -1938,6 +1943,31 @@
}],
],
},
{
'action_name': 'js2c_experimental_extras',
'inputs': [
'../../tools/js2c.py',
'<@(v8_experimental_extra_library_files)',
],
'outputs': [
'<(SHARED_INTERMEDIATE_DIR)/experimental-extras-libraries.cc',
],
'action': [
'python',
'../../tools/js2c.py',
'<(SHARED_INTERMEDIATE_DIR)/experimental-extras-libraries.cc',
'EXPERIMENTAL_EXTRAS',
'<@(v8_experimental_extra_library_files)',
],
'conditions': [
[ 'v8_use_external_startup_data==1', {
'outputs': ['<@(libraries_experimental_extras_bin_file)'],
'action': [
'--startup_blob', '<@(libraries_experimental_extras_bin_file)',
],
}],
],
},
],
},
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment