Reviewers: jochen (traveling), domenic,
Message:
This replaces https://codereview.chromium.org/1128113006/.
Description:
Introduce extras export object.
BUG=
Please review this at https://codereview.chromium.org/1140333003/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+58, -8 lines):
M build/standalone.gypi
M include/v8.h
M src/api.cc
M src/bootstrapper.cc
M src/contexts.h
M src/runtime/runtime-test.cc
M test/cctest/test-api.cc
A + test/cctest/test-extra.js
Index: build/standalone.gypi
diff --git a/build/standalone.gypi b/build/standalone.gypi
index
57bc8af94c5145b30c07aaad4ebb8b2e55c05a66..24f2e7a74f44e16907330197d9d0b8aaaeb49994
100644
--- a/build/standalone.gypi
+++ b/build/standalone.gypi
@@ -100,6 +100,9 @@
'msan%': '<(msan)',
'tsan%': '<(tsan)',
+ # Add a simple extra solely for the purpose of the cctests
+ 'v8_extra_library_files': ['../test/cctest/test-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
# things as the set of warnings to enable, and whether warnings are
treated
Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index
d4b664a5495a2481f3db61274be6ef6948889371..3ba8065bc98764d0fd24644ea134f20f895b6589
100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -6372,6 +6372,13 @@ class V8_EXPORT Context {
V8_INLINE Local<Value> GetEmbedderData(int index);
/**
+ * Gets the exports object used by V8 extras. Extra natives get a
reference
+ * to this object and can use it to export functionality.
+ * If there are no extra native scripts, return an emtpy handle.
+ */
+ MaybeLocal<Object> GetExtrasExportsObject();
+
+ /**
* Sets the embedder data with the given index, growing the data as
* needed. Note that index 0 currently has a special meaning for Chrome's
* debugger.
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index
4ad40423b13ccb21ecfb03540682c6c5cd94d838..0cd34a116cc81758876f00d71bdf2ad9d2065cb4
100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -5493,6 +5493,16 @@ void Context::DetachGlobal() {
}
+MaybeLocal<v8::Object> Context::GetExtrasExportsObject() {
+ i::Handle<i::Context> context = Utils::OpenHandle(this);
+ i::Isolate* isolate = context->GetIsolate();
+ i::Object* extras_exports = context->extras_exports_object();
+ if (!extras_exports->IsJSObject()) return MaybeLocal<v8::Object>();
+ i::Handle<i::JSObject> exports(i::JSObject::cast(extras_exports),
isolate);
+ return Utils::ToLocal(exports);
+}
+
+
void Context::AllowCodeGenerationFromStrings(bool allow) {
i::Handle<i::Context> context = Utils::OpenHandle(this);
i::Isolate* isolate = context->GetIsolate();
Index: src/bootstrapper.cc
diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc
index
55b5b3141e1b723f72ce1c5fad5c7ebfd1b38b62..c86e7aa6ae53e78dacf20ad5404540868065387e
100644
--- a/src/bootstrapper.cc
+++ b/src/bootstrapper.cc
@@ -1467,7 +1467,7 @@ bool Genesis::CompileExtraBuiltin(Isolate* isolate,
int index) {
Handle<String> source_code =
isolate->bootstrapper()->SourceLookup<ExtraNatives>(index);
Handle<Object> global = isolate->global_object();
- Handle<Object> exports = isolate->builtin_exports_object();
+ Handle<Object> exports = isolate->extras_exports_object();
Handle<Object> args[] = {global, exports};
return CompileNative(isolate, name, source_code, arraysize(args), args);
}
@@ -1918,12 +1918,19 @@ bool Genesis::InstallNatives() {
factory()->NewJSObject(isolate()->object_function());
JSObject::NormalizeProperties(shared, CLEAR_INOBJECT_PROPERTIES, 16,
"container to share between native
scripts");
+
Handle<JSObject> builtin_exports =
factory()->NewJSObject(isolate()->object_function());
JSObject::NormalizeProperties(builtin_exports,
CLEAR_INOBJECT_PROPERTIES, 16,
"container to export to experimental
natives");
native_context()->set_builtin_exports_object(*builtin_exports);
+ Handle<JSObject> extras_exports =
+ factory()->NewJSObject(isolate()->object_function());
+ JSObject::NormalizeProperties(builtin_exports,
CLEAR_INOBJECT_PROPERTIES, 2,
+ "container to export to extra natives");
+ native_context()->set_extras_exports_object(*extras_exports);
+
if (FLAG_expose_natives_as != NULL) {
Handle<String> shared_key =
factory()->NewStringFromAsciiChecked("shared");
JSObject::AddProperty(builtins, shared_key, shared, NONE);
Index: src/contexts.h
diff --git a/src/contexts.h b/src/contexts.h
index
f120788609f2d748ed0015684cc0f91f0900d899..9c9ffdc0a092cd80eb724f9d1c61b1f05fd4d24d
100644
--- a/src/contexts.h
+++ b/src/contexts.h
@@ -187,7 +187,8 @@ enum BindingFlags {
V(SET_ITERATOR_MAP_INDEX, Map,
set_iterator_map) \
V(ARRAY_VALUES_ITERATOR_INDEX, JSFunction,
array_values_iterator) \
V(SCRIPT_CONTEXT_TABLE_INDEX, ScriptContextTable,
script_context_table) \
- V(BUILTIN_EXPORTS_OBJECT_INDEX, Object, builtin_exports_object)
+ V(BUILTIN_EXPORTS_OBJECT_INDEX, Object,
builtin_exports_object) \
+ V(EXTRAS_EXPORTS_OBJECT_INDEX, Object, extras_exports_object)
// A table of all script contexts. Every loaded top-level script with
top-level
@@ -426,6 +427,7 @@ class Context: public FixedArray {
MAP_CACHE_INDEX,
TO_LENGTH_FUN_INDEX,
BUILTIN_EXPORTS_OBJECT_INDEX,
+ EXTRAS_EXPORTS_OBJECT_INDEX,
// Properties from here are treated as weak references by the full GC.
// Scavenge treats them as strong references.
Index: src/runtime/runtime-test.cc
diff --git a/src/runtime/runtime-test.cc b/src/runtime/runtime-test.cc
index
6b238cea782b9ac2c12e914faadce0234c339f78..1f39ed8f6a90a186814f2daba677d599f21a4a0a
100644
--- a/src/runtime/runtime-test.cc
+++ b/src/runtime/runtime-test.cc
@@ -372,7 +372,8 @@ RUNTIME_FUNCTION(Runtime_AbortJS) {
RUNTIME_FUNCTION(Runtime_NativeScriptsCount) {
DCHECK(args.length() == 0);
- return Smi::FromInt(Natives::GetBuiltinsCount());
+ return Smi::FromInt(Natives::GetBuiltinsCount() +
+ ExtraNatives::GetBuiltinsCount());
}
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index
9e9e03a937910963966f923e4bad19aa7d30c2ce..23c42ecd7709a993f84aa5a9d7453a632e432304
100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -21101,3 +21101,22 @@ TEST(StrongModeArityCallFromApi2) {
CHECK(!try_catch.HasCaught());
}
}
+
+
+TEST(ExtrasExportsObject) {
+ v8::Isolate* isolate = CcTest::isolate();
+ v8::HandleScope handle_scope(isolate);
+ LocalContext env;
+
+ // standalone.gypi ensures we include the test-extra.js file, which
should
+ // add the testExtraShouldReturnFive export
+ v8::Local<v8::Object> exports;
+ CHECK(env->GetExtrasExportsObject().ToLocal(&exports));
+
+ auto func =
+ exports->Get(v8_str("testExtraShouldReturnFive")).As<v8::Function>();
+ auto undefined = v8::Undefined(isolate);
+ auto result = func->Call(undefined, 0, {}).As<v8::Number>();
+
+ CHECK(result->Value() == 5.0);
+}
Index: test/cctest/test-extra.js
diff --git a/test/message/export-duplicate-as.js b/test/cctest/test-extra.js
similarity index 58%
copy from test/message/export-duplicate-as.js
copy to test/cctest/test-extra.js
index
49b52d4b17177e9443445f00379227cce07a034d..9c63d9c103836a714ab48f420d62c62fea44cb78
100644
--- a/test/message/export-duplicate-as.js
+++ b/test/cctest/test-extra.js
@@ -1,9 +1,10 @@
// 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.
-//
-// MODULE
-var a, b;
-export { a as c };
-export { a, b as c };
+(function (global, exports) {
+ 'use strict';
+ exports.testExtraShouldReturnFive = function () {
+ return 5;
+ };
+})
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.