Introduce extras export object.
BUG= Review URL: https://codereview.chromium.org/1140333003 Cr-Commit-Position: refs/heads/master@{#28499}
This commit is contained in:
parent
dd0f469da3
commit
9a1490ad6f
@ -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
|
||||
|
@ -6430,6 +6430,12 @@ 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.
|
||||
*/
|
||||
Local<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
|
||||
|
@ -5495,6 +5495,14 @@ void Context::DetachGlobal() {
|
||||
}
|
||||
|
||||
|
||||
Local<v8::Object> Context::GetExtrasExportsObject() {
|
||||
i::Handle<i::Context> context = Utils::OpenHandle(this);
|
||||
i::Isolate* isolate = context->GetIsolate();
|
||||
i::Handle<i::JSObject> exports(context->extras_exports_object(), isolate);
|
||||
return Utils::ToLocal(exports);
|
||||
}
|
||||
|
||||
|
||||
void Context::AllowCodeGenerationFromStrings(bool allow) {
|
||||
i::Handle<i::Context> context = Utils::OpenHandle(this);
|
||||
i::Isolate* isolate = context->GetIsolate();
|
||||
|
@ -1472,7 +1472,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);
|
||||
}
|
||||
@ -1925,12 +1925,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(extras_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);
|
||||
|
@ -188,7 +188,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, JSObject, extras_exports_object)
|
||||
|
||||
|
||||
// A table of all script contexts. Every loaded top-level script with top-level
|
||||
@ -428,6 +429,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.
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
||||
|
@ -21106,3 +21106,21 @@ 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 = env->GetExtrasExportsObject();
|
||||
|
||||
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);
|
||||
}
|
||||
|
10
test/cctest/test-extra.js
Normal file
10
test/cctest/test-extra.js
Normal file
@ -0,0 +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.
|
||||
|
||||
(function (global, exports) {
|
||||
'use strict';
|
||||
exports.testExtraShouldReturnFive = function () {
|
||||
return 5;
|
||||
};
|
||||
})
|
Loading…
Reference in New Issue
Block a user