Reland "Use function wrapper argument to expose internal arrays to native scripts."
authoryangguo <yangguo@chromium.org>
Tue, 12 May 2015 14:00:47 +0000 (07:00 -0700)
committerCommit bot <commit-bot@chromium.org>
Tue, 12 May 2015 14:00:45 +0000 (14:00 +0000)
Review URL: https://codereview.chromium.org/1138173002

Cr-Commit-Position: refs/heads/master@{#28367}

35 files changed:
src/array.js
src/bootstrapper.cc
src/contexts.h
src/date.js
src/harmony-array-includes.js
src/harmony-array.js
src/harmony-object.js
src/harmony-reflect.js
src/harmony-regexp.js
src/harmony-spread.js
src/harmony-tostring.js
src/harmony-typedarray.js
src/json.js
src/math.js
src/messages.js
src/object-observe.js
src/objects.h
src/promise.js
src/regexp.js
src/string.js
src/templates.js
src/uri.js
src/v8natives.js
test/cctest/test-heap.cc
test/mjsunit/debug-stepout-scope-part1.js
test/mjsunit/debug-stepout-scope-part2.js
test/mjsunit/debug-stepout-scope-part3.js
test/mjsunit/debug-stepout-scope-part4.js
test/mjsunit/debug-stepout-scope-part5.js
test/mjsunit/debug-stepout-scope-part6.js
test/mjsunit/debug-stepout-scope-part7.js
test/mjsunit/debug-stepout-scope-part8.js
test/mjsunit/global-deleted-property-keyed.js
test/mjsunit/regress/regress-1878.js
test/mjsunit/samevalue.js

index 3f9bd68bbf483bd0c8b42472905ebf9237af13e5..93378cfb00b1b14c0150e5b179c6de5f6a8852a2 100644 (file)
@@ -19,7 +19,12 @@ var $innerArrayEvery;
 
 %CheckIsBootstrapping();
 
+// -------------------------------------------------------------------
+// Imports
+
 var GlobalArray = global.Array;
+var InternalArray = exports.InternalArray;
+var InternalPackedArray = exports.InternalPackedArray;
 
 // -------------------------------------------------------------------
 
index f3dd682871b74964a4afd0860aed1381c49c1944..f0278ca666724daf7faf1f0a10384e2a1e4f9d1e 100644 (file)
@@ -217,7 +217,7 @@ class Genesis BASE_EMBEDDED {
   HARMONY_SHIPPING(DECLARE_FEATURE_INITIALIZATION)
 #undef DECLARE_FEATURE_INITIALIZATION
 
-  Handle<JSFunction> InstallInternalArray(Handle<JSBuiltinsObject> builtins,
+  Handle<JSFunction> InstallInternalArray(Handle<JSObject> target,
                                           const char* name,
                                           ElementsKind elements_kind);
   bool InstallNatives();
@@ -307,19 +307,15 @@ class Genesis BASE_EMBEDDED {
                                            FunctionMode function_mode);
   void SetStrongFunctionInstanceDescriptor(Handle<Map> map);
 
-  static bool CompileBuiltin(Isolate* isolate, int index);
+  static bool CompileBuiltin(Isolate* isolate, int index,
+                             Handle<JSObject> shared);
   static bool CompileExperimentalBuiltin(Isolate* isolate, int index);
   static bool CompileExtraBuiltin(Isolate* isolate, int index);
-  static bool CompileNative(Isolate* isolate,
-                            Vector<const char> name,
-                            Handle<String> source);
-  static bool CompileScriptCached(Isolate* isolate,
-                                  Vector<const char> name,
-                                  Handle<String> source,
-                                  SourceCodeCache* cache,
-                                  v8::Extension* extension,
-                                  Handle<Context> top_context,
-                                  bool use_runtime_context);
+  static bool CompileNative(Isolate* isolate, Vector<const char> name,
+                            Handle<String> source, int argc,
+                            Handle<Object> argv[]);
+
+  static bool CompileExtension(Isolate* isolate, v8::Extension* extension);
 
   Isolate* isolate_;
   Handle<Context> result_;
@@ -1441,34 +1437,45 @@ void Genesis::InitializeExperimentalGlobal() {
 }
 
 
-bool Genesis::CompileBuiltin(Isolate* isolate, int index) {
+bool Genesis::CompileBuiltin(Isolate* isolate, int index,
+                             Handle<JSObject> shared) {
   Vector<const char> name = Natives::GetScriptName(index);
   Handle<String> source_code =
       isolate->bootstrapper()->SourceLookup<Natives>(index);
-  return CompileNative(isolate, name, source_code);
+  Handle<Object> global = isolate->global_object();
+  Handle<Object> exports = isolate->builtin_exports_object();
+  Handle<Object> args[] = {global, shared, exports};
+  return CompileNative(isolate, name, source_code, arraysize(args), args);
 }
 
 
 bool Genesis::CompileExperimentalBuiltin(Isolate* isolate, int index) {
+  HandleScope scope(isolate);
   Vector<const char> name = ExperimentalNatives::GetScriptName(index);
   Handle<String> source_code =
       isolate->bootstrapper()->SourceLookup<ExperimentalNatives>(index);
-  return CompileNative(isolate, name, source_code);
+  Handle<Object> global = isolate->global_object();
+  Handle<Object> exports = isolate->builtin_exports_object();
+  Handle<Object> args[] = {global, exports};
+  return CompileNative(isolate, name, source_code, arraysize(args), args);
 }
 
 
 bool Genesis::CompileExtraBuiltin(Isolate* isolate, int index) {
+  HandleScope scope(isolate);
   Vector<const char> name = ExtraNatives::GetScriptName(index);
   Handle<String> source_code =
       isolate->bootstrapper()->SourceLookup<ExtraNatives>(index);
-  return CompileNative(isolate, name, source_code);
+  Handle<Object> global = isolate->global_object();
+  Handle<Object> exports = isolate->builtin_exports_object();
+  Handle<Object> args[] = {global, exports};
+  return CompileNative(isolate, name, source_code, arraysize(args), args);
 }
 
 
-bool Genesis::CompileNative(Isolate* isolate,
-                            Vector<const char> name,
-                            Handle<String> source) {
-  HandleScope scope(isolate);
+bool Genesis::CompileNative(Isolate* isolate, Vector<const char> name,
+                            Handle<String> source, int argc,
+                            Handle<Object> argv[]) {
   SuppressDebug compiling_natives(isolate->debug());
   // During genesis, the boilerplate for stack overflow won't work until the
   // environment has been at least partially initialized. Add a stack check
@@ -1476,78 +1483,72 @@ bool Genesis::CompileNative(Isolate* isolate,
   StackLimitCheck check(isolate);
   if (check.HasOverflowed()) return false;
 
-  bool result = CompileScriptCached(isolate,
-                                    name,
-                                    source,
-                                    NULL,
-                                    NULL,
-                                    Handle<Context>(isolate->context()),
-                                    true);
-  DCHECK(isolate->has_pending_exception() != result);
-  if (!result) isolate->clear_pending_exception();
-  return result;
+  Handle<Context> context(isolate->context());
+
+  Handle<String> script_name =
+      isolate->factory()->NewStringFromUtf8(name).ToHandleChecked();
+  Handle<SharedFunctionInfo> function_info = Compiler::CompileScript(
+      source, script_name, 0, 0, false, false, Handle<Object>(), context, NULL,
+      NULL, ScriptCompiler::kNoCompileOptions, NATIVES_CODE, false);
+
+  DCHECK(context->IsNativeContext());
+
+  Handle<Context> runtime_context(context->runtime_context());
+  Handle<JSBuiltinsObject> receiver(context->builtins());
+  Handle<JSFunction> fun =
+      isolate->factory()->NewFunctionFromSharedFunctionInfo(function_info,
+                                                            runtime_context);
+
+  // For non-extension scripts, run script to get the function wrapper.
+  Handle<Object> wrapper;
+  if (!Execution::Call(isolate, fun, receiver, 0, NULL).ToHandle(&wrapper)) {
+    return false;
+  }
+  // Then run the function wrapper.
+  return !Execution::Call(isolate, Handle<JSFunction>::cast(wrapper), receiver,
+                          argc, argv).is_null();
 }
 
 
-bool Genesis::CompileScriptCached(Isolate* isolate,
-                                  Vector<const char> name,
-                                  Handle<String> source,
-                                  SourceCodeCache* cache,
-                                  v8::Extension* extension,
-                                  Handle<Context> top_context,
-                                  bool use_runtime_context) {
+bool Genesis::CompileExtension(Isolate* isolate, v8::Extension* extension) {
   Factory* factory = isolate->factory();
   HandleScope scope(isolate);
   Handle<SharedFunctionInfo> function_info;
 
+  Handle<String> source =
+      isolate->factory()
+          ->NewExternalStringFromOneByte(extension->source())
+          .ToHandleChecked();
+  DCHECK(source->IsOneByteRepresentation());
+
   // If we can't find the function in the cache, we compile a new
   // function and insert it into the cache.
-  if (cache == NULL || !cache->Lookup(name, &function_info)) {
-    DCHECK(source->IsOneByteRepresentation());
+  Vector<const char> name = CStrVector(extension->name());
+  SourceCodeCache* cache = isolate->bootstrapper()->extensions_cache();
+  Handle<Context> context(isolate->context());
+  DCHECK(context->IsNativeContext());
+
+  if (!cache->Lookup(name, &function_info)) {
     Handle<String> script_name =
         factory->NewStringFromUtf8(name).ToHandleChecked();
     function_info = Compiler::CompileScript(
-        source, script_name, 0, 0, false, false, Handle<Object>(), top_context,
-        extension, NULL, ScriptCompiler::kNoCompileOptions,
-        use_runtime_context ? NATIVES_CODE : NOT_NATIVES_CODE, false);
+        source, script_name, 0, 0, false, false, Handle<Object>(), context,
+        extension, NULL, ScriptCompiler::kNoCompileOptions, NOT_NATIVES_CODE,
+        false);
     if (function_info.is_null()) return false;
-    if (cache != NULL) cache->Add(name, function_info);
+    cache->Add(name, function_info);
   }
 
   // Set up the function context. Conceptually, we should clone the
   // function before overwriting the context but since we're in a
   // single-threaded environment it is not strictly necessary.
-  DCHECK(top_context->IsNativeContext());
-  Handle<Context> context =
-      Handle<Context>(use_runtime_context
-                      ? Handle<Context>(top_context->runtime_context())
-                      : top_context);
   Handle<JSFunction> fun =
       factory->NewFunctionFromSharedFunctionInfo(function_info, context);
 
   // Call function using either the runtime object or the global
   // object as the receiver. Provide no parameters.
-  Handle<Object> receiver =
-      Handle<Object>(use_runtime_context
-                     ? top_context->builtins()
-                     : top_context->global_object(),
-                     isolate);
-  MaybeHandle<Object> result;
-  if (extension == NULL) {
-    // For non-extension scripts, run script to get the function wrapper.
-    Handle<Object> wrapper;
-    if (!Execution::Call(isolate, fun, receiver, 0, NULL).ToHandle(&wrapper)) {
-      return false;
-    }
-    // Then run the function wrapper.
-    Handle<Object> global_obj(top_context->global_object(), isolate);
-    Handle<Object> args[] = {global_obj};
-    result = Execution::Call(isolate, Handle<JSFunction>::cast(wrapper),
-                             receiver, arraysize(args), args);
-  } else {
-    result = Execution::Call(isolate, fun, receiver, 0, NULL);
-  }
-  return !result.is_null();
+  Handle<Object> receiver = isolate->global_object();
+  return !Execution::Call(isolate, fun, receiver, 0, NULL).is_null();
 }
 
 
@@ -1818,10 +1819,9 @@ void Genesis::InitializeGlobal_harmony_tostring() {
 }
 
 
-Handle<JSFunction> Genesis::InstallInternalArray(
-    Handle<JSBuiltinsObject> builtins,
-    const char* name,
-    ElementsKind elements_kind) {
+Handle<JSFunction> Genesis::InstallInternalArray(Handle<JSObject> target,
+                                                 const char* name,
+                                                 ElementsKind elements_kind) {
   // --- I n t e r n a l   A r r a y ---
   // An array constructor on the builtins object that works like
   // the public Array constructor, except that its prototype
@@ -1830,9 +1830,9 @@ Handle<JSFunction> Genesis::InstallInternalArray(
   // must not be leaked to user code.
   Handle<JSObject> prototype =
       factory()->NewJSObject(isolate()->object_function(), TENURED);
-  Handle<JSFunction> array_function = InstallFunction(
-      builtins, name, JS_ARRAY_TYPE, JSArray::kSize,
-      prototype, Builtins::kInternalArrayCode);
+  Handle<JSFunction> array_function =
+      InstallFunction(target, name, JS_ARRAY_TYPE, JSArray::kSize, prototype,
+                      Builtins::kInternalArrayCode);
 
   InternalArrayConstructorStub internal_array_constructor_stub(isolate());
   Handle<Code> code = internal_array_constructor_stub.GetCode();
@@ -1910,6 +1910,19 @@ bool Genesis::InstallNatives() {
 
   native_context()->set_runtime_context(*context);
 
+  // Set up shared object to set up cross references between native scripts.
+  // "shared" is used for cross references between native scripts that are part
+  // of the snapshot. "builtin_exports" is used for experimental natives.
+  Handle<JSObject> shared =
+      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);
+
   {  // -- S c r i p t
     // Builtin functions for Script.
     Handle<JSFunction> script_fun = InstallFunction(
@@ -2082,13 +2095,13 @@ bool Genesis::InstallNatives() {
   // through a common bottleneck that would make the SMI_ONLY -> FAST_ELEMENT
   // transition easy to trap. Moreover, they rarely are smi-only.
   {
-    Handle<JSFunction> array_function =
-        InstallInternalArray(builtins, "InternalArray", FAST_HOLEY_ELEMENTS);
+    HandleScope scope(isolate());
+    Handle<JSObject> builtin_exports =
+        Handle<JSObject>::cast(isolate()->builtin_exports_object());
+    Handle<JSFunction> array_function = InstallInternalArray(
+        builtin_exports, "InternalArray", FAST_HOLEY_ELEMENTS);
     native_context()->set_internal_array_function(*array_function);
-  }
-
-  {
-    InstallInternalArray(builtins, "InternalPackedArray", FAST_ELEMENTS);
+    InstallInternalArray(builtin_exports, "InternalPackedArray", FAST_ELEMENTS);
   }
 
   {  // -- S e t I t e r a t o r
@@ -2181,13 +2194,15 @@ bool Genesis::InstallNatives() {
 #undef INSTALL_PUBLIC_SYMBOL
   }
 
-  // Install natives.
+  // Install natives. Everything exported to experimental natives is also
+  // shared to regular natives.
+  TransferNamedProperties(builtin_exports, shared);
   int i = Natives::GetDebuggerCount();
-  if (!CompileBuiltin(isolate(), i)) return false;
+  if (!CompileBuiltin(isolate(), i, shared)) return false;
   if (!InstallJSBuiltins(builtins)) return false;
 
   for (++i; i < Natives::GetBuiltinsCount(); ++i) {
-    if (!CompileBuiltin(isolate(), i)) return false;
+    if (!CompileBuiltin(isolate(), i, shared)) return false;
   }
 
   InstallNativeFunctions();
@@ -2502,14 +2517,21 @@ bool Genesis::InstallSpecialObjects(Handle<Context> native_context) {
   Handle<Smi> stack_trace_limit(Smi::FromInt(FLAG_stack_trace_limit), isolate);
   JSObject::AddProperty(Error, name, stack_trace_limit, NONE);
 
+  Handle<Object> builtin_exports(native_context->builtin_exports_object(),
+                                 isolate);
+  native_context->set_builtin_exports_object(Smi::FromInt(0));
+
   // Expose the natives in global if a name for it is specified.
   if (FLAG_expose_natives_as != NULL && strlen(FLAG_expose_natives_as) != 0) {
-    Handle<String> natives =
+    Handle<String> natives_key =
         factory->InternalizeUtf8String(FLAG_expose_natives_as);
     uint32_t dummy_index;
-    if (natives->AsArrayIndex(&dummy_index)) return true;
-    JSObject::AddProperty(global, natives, handle(global->builtins()),
-                          DONT_ENUM);
+    if (natives_key->AsArrayIndex(&dummy_index)) return true;
+    Handle<JSBuiltinsObject> natives(global->builtins());
+    JSObject::AddProperty(global, natives_key, natives, DONT_ENUM);
+    Handle<String> builtin_exports_key =
+        factory->NewStringFromAsciiChecked("builtin_exports");
+    JSObject::AddProperty(natives, builtin_exports_key, builtin_exports, NONE);
   }
 
   // Expose the stack trace symbol to native JS.
@@ -2653,17 +2675,7 @@ bool Genesis::InstallExtension(Isolate* isolate,
     }
   }
   // We do not expect this to throw an exception. Change this if it does.
-  Handle<String> source_code =
-      isolate->factory()
-          ->NewExternalStringFromOneByte(extension->source())
-          .ToHandleChecked();
-  bool result = CompileScriptCached(isolate,
-                                    CStrVector(extension->name()),
-                                    source_code,
-                                    isolate->bootstrapper()->extensions_cache(),
-                                    extension,
-                                    Handle<Context>(isolate->context()),
-                                    false);
+  bool result = CompileExtension(isolate, extension);
   DCHECK(isolate->has_pending_exception() != result);
   if (!result) {
     // We print out the name of the extension that fail to install.
@@ -2914,6 +2926,7 @@ Genesis::Genesis(Isolate* isolate,
 
   // We can only de-serialize a context if the isolate was initialized from
   // a snapshot. Otherwise we have to build the context from scratch.
+  // Also create a context from scratch to expose natives, if required by flag.
   Handle<FixedArray> outdated_contexts;
   if (!isolate->initialized_from_snapshot() ||
       !Snapshot::NewContextFromSnapshot(isolate, global_proxy,
index 2d04da29b3bd1d2444c54bb76a01fb02314e9a66..066e8a1ec33a86126a5fdaf39e5b16d5d5a9d796 100644 (file)
@@ -185,7 +185,8 @@ enum BindingFlags {
   V(MAP_ITERATOR_MAP_INDEX, Map, map_iterator_map)                             \
   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(SCRIPT_CONTEXT_TABLE_INDEX, ScriptContextTable, script_context_table)      \
+  V(BUILTIN_EXPORTS_OBJECT_INDEX, Object, builtin_exports_object)
 
 
 // A table of all script contexts. Every loaded top-level script with top-level
@@ -422,6 +423,7 @@ class Context: public FixedArray {
     SCRIPT_CONTEXT_TABLE_INDEX,
     MAP_CACHE_INDEX,
     TO_LENGTH_FUN_INDEX,
+    BUILTIN_EXPORTS_OBJECT_INDEX,
 
     // Properties from here are treated as weak references by the full GC.
     // Scavenge treats them as strong references.
index 0cd18250e4e93b6afc221402f3cdc391aceacf81..7b6f539eaa356dd692c4dda3eb96bb67bbef3493 100644 (file)
@@ -16,7 +16,13 @@ var $createDate;
 
 %CheckIsBootstrapping();
 
+// -------------------------------------------------------------------
+// Imports
+
 var GlobalDate = global.Date;
+var InternalArray = shared.InternalArray;
+
+// -------------------------------------------------------------------
 
 // This file contains date support implemented in JavaScript.
 
index 109499ea6b90236b97ef6c8e31306a33ddf80dae..e4ac07b63ee1579c4570b4ef0fbce2d20ff82d36 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-(function(global, shared, exports) {
+(function(global, exports) {
 
 'use strict';
 
index f9283b9c0c93f0a8e7ab7d96ead1cc448db1aeb0..8520f351d158e7693d11fba3f15c1ce41a78fdbd 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-(function(global, shared, exports) {
+(function(global, exports) {
 
 'use strict';
 
index acf74dd326c1f4d01295d549d2fb5fa74458a961..bbb6437e14227e7ac39851f90495d9b23070afc5 100644 (file)
@@ -3,7 +3,7 @@
 // found in the LICENSE file.
 //
 
-(function(global, shared, exports) {
+(function(global, exports) {
 
 "use strict";
 
index eee6df40d537e9ea1bdb50f0fc5f51dd6f2e3a8b..4f78b2a4933f28ab0deb721531e2667221756be0 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-(function(global, shared, exports) {
+(function(global, exports) {
 
 'use strict';
 
index 6a32f16c75662f76372943c97d1dee1a59653e9a..21c2c71a513c97c051d1da4cdd7209d5b3ed289f 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-(function(global, shared, exports) {
+(function(global, exports) {
 
 'use strict';
 
index a523d26e38cac42a80812840d65a866f9685037a..8eade4b0e13d4751eeefd71baab8565c4af8b6e9 100644 (file)
@@ -5,10 +5,16 @@
 var $spreadArguments;
 var $spreadIterable;
 
-(function(global, shared, exports) {
+(function(global, exports) {
 
 'use strict';
 
+// -------------------------------------------------------------------
+// Imports
+var InternalArray = exports.InternalArray;
+
+// -------------------------------------------------------------------
+
 function SpreadArguments() {
   var count = %_ArgumentsLength();
   var args = new InternalArray();
index b3783c444e1bd8406bd8ca661c9a11504acacc34..d29d9c6c5f6373cbe586f65187a95850ac41a3a4 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-(function(global, shared, exports) {
+(function(global, exports) {
 
 "use strict";
 
index 18b4ca014bede8773173dcc21b82366a0fcb82b0..bbdb91fc20b24e323d58b648d1cacf59315318dd 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-(function(global, shared, exports) {
+(function(global, exports) {
 
 "use strict";
 
index f093e5c1b10ed8349b4d0e54fb13fd78a7953faf..2e6bbbbce2d2bf6217a5ea61700d61f8eb3a5635 100644 (file)
@@ -10,7 +10,11 @@ var $jsonSerializeAdapter;
 
 %CheckIsBootstrapping();
 
+// -------------------------------------------------------------------
+// Imports
+
 var GlobalJSON = global.JSON;
+var InternalArray = shared.InternalArray;
 
 // -------------------------------------------------------------------
 
index af2d0acda06c28c2aeab06cb51b2a2ff47a9982a..633a5d02c45d37ef830afbb221c8e5fc5138e08c 100644 (file)
@@ -16,7 +16,11 @@ var $min;
 
 %CheckIsBootstrapping();
 
+// -------------------------------------------------------------------
+// Imports
+
 var GlobalObject = global.Object;
+var InternalArray = shared.InternalArray;
 
 //-------------------------------------------------------------------
 
index 4b67c2e8ba54a5869cc9e835ffeb66a5f325565f..eb6e07fb07bdf6df49ead6f9288edf183127dae0 100644 (file)
@@ -35,7 +35,14 @@ var MakeTypeErrorEmbedded;
 
 %CheckIsBootstrapping();
 
+// -------------------------------------------------------------------
+// Imports
+
 var GlobalObject = global.Object;
+var InternalArray = shared.InternalArray;
+
+// -------------------------------------------------------------------
+
 var GlobalError;
 var GlobalTypeError;
 var GlobalRangeError;
@@ -44,8 +51,6 @@ var GlobalSyntaxError;
 var GlobalReferenceError;
 var GlobalEvalError;
 
-// -------------------------------------------------------------------
-
 var kMessages = {
   // Error
   constructor_is_generator:      ["Class constructor may not be a generator"],
index 00bf85d8b2223924d31517303f4fb33ed5726382..3dfc35e8e5ec9e36ed621ca9be7d30ef3f3c091b 100644 (file)
@@ -16,8 +16,12 @@ var $observeNativeObjectNotifierPerformChange;
 
 %CheckIsBootstrapping();
 
+// -------------------------------------------------------------------
+// Imports
+
 var GlobalArray = global.Array;
 var GlobalObject = global.Object;
+var InternalArray = shared.InternalArray;
 
 // -------------------------------------------------------------------
 
index f27ce21ab9dc1d76dba7d9b46fdd51e524e8a5af..54375305bced4c8846dd5816ba333df065d9821b 100644 (file)
@@ -1700,9 +1700,6 @@ class JSReceiver: public HeapObject {
 // Forward declaration for JSObject::GetOrCreateHiddenPropertiesHashTable.
 class ObjectHashTable;
 
-// Forward declaration for JSObject::Copy.
-class AllocationSite;
-
 
 // The JSObject describes real heap allocated JavaScript objects with
 // properties.
@@ -2163,7 +2160,6 @@ class JSObject: public JSReceiver {
   // Copy object.
   enum DeepCopyHints { kNoHints = 0, kObjectIsShallow = 1 };
 
-  static Handle<JSObject> Copy(Handle<JSObject> object);
   MUST_USE_RESULT static MaybeHandle<JSObject> DeepCopy(
       Handle<JSObject> object,
       AllocationSiteUsageContext* site_context,
index b0d1aa088b587c76ab8bb0776a10b8d27c006250..97a0b4c967c8ac20603198a2e001e2d5066ef3a7 100644 (file)
@@ -18,6 +18,11 @@ var $promiseValue;
 
 %CheckIsBootstrapping();
 
+// -------------------------------------------------------------------
+// Imports
+
+var InternalArray = shared.InternalArray;
+
 // -------------------------------------------------------------------
 
 // Status values: 0 = pending, +1 = resolved, -1 = rejected
index 3ac59872029eb8fe4c3dc90bcaa2891a52c55a32..b6bf3f983750b4a44f42ccec4cfebb2babca3cb0 100644 (file)
@@ -13,7 +13,13 @@ var harmony_unicode_regexps = false;
 
 %CheckIsBootstrapping();
 
+// -------------------------------------------------------------------
+// Imports
+
 var GlobalRegExp = global.RegExp;
+var InternalPackedArray = shared.InternalPackedArray;
+
+// -------------------------------------------------------------------
 
 // Property of the builtins object for recording the result of the last
 // regexp match.  The property $regexpLastMatchInfo includes the matchIndices
index 03979fded3fe61a481568f4538ed93a930381c70..1fc7b020c912897d55bc5b21b397ca8b5ffffc57 100644 (file)
@@ -10,8 +10,13 @@ var $stringSubstring;
 
 %CheckIsBootstrapping();
 
+// -------------------------------------------------------------------
+// Imports
+
 var GlobalRegExp = global.RegExp;
 var GlobalString = global.String;
+var InternalArray = shared.InternalArray;
+var InternalPackedArray = shared.InternalPackedArray;
 
 //-------------------------------------------------------------------
 
index ff94683fb13c0909b3bb72bc801d6d68f818ee48..e49cb3ef734aff80d743a076221377af7ad68ee6 100644 (file)
@@ -12,9 +12,17 @@ var $getTemplateCallSite;
 
 %CheckIsBootstrapping();
 
-var callSiteCache = new global.Map;
-var mapGetFn = global.Map.prototype.get;
-var mapSetFn = global.Map.prototype.set;
+// -------------------------------------------------------------------
+// Imports
+
+var GlobalMap = global.Map;
+var InternalArray = shared.InternalArray;
+
+// -------------------------------------------------------------------
+
+var callSiteCache = new GlobalMap;
+var mapGetFn = GlobalMap.prototype.get;
+var mapSetFn = GlobalMap.prototype.set;
 
 
 function SameCallSiteElements(rawStrings, other) {
index 1f4b8b626241d7d1931243ffa7779eae4a66fe7e..d3ecac9645a06d4eae3ad4ef92be5a4fb062e9ef 100644 (file)
 
 %CheckIsBootstrapping();
 
+//- ------------------------------------------------------------------
+// Imports
+
 var GlobalObject = global.Object;
 var GlobalArray = global.Array;
+var InternalArray = shared.InternalArray;
 
 // -------------------------------------------------------------------
 // Define internal helper functions.
index ce54c758ed923b10ecf80a44dc37acb241386bcf..94133bff7fe05dfd496a1e42172bc679aca140aa 100644 (file)
@@ -36,11 +36,15 @@ var $toNameArray;
 
 %CheckIsBootstrapping();
 
+// ----------------------------------------------------------------------------
+// Imports
+
 var GlobalArray = global.Array;
 var GlobalBoolean = global.Boolean;
 var GlobalFunction = global.Function;
 var GlobalNumber = global.Number;
 var GlobalObject = global.Object;
+var InternalArray = shared.InternalArray;
 
 // ----------------------------------------------------------------------------
 
index d8c89aec1b4b242a9702c3a018681bdb9b2569bc..5730cde1bb24e309c4422f84696e843d5a4912a4 100644 (file)
@@ -5430,3 +5430,56 @@ TEST(PreprocessStackTrace) {
     CHECK(!element->IsCode());
   }
 }
+
+
+static bool shared_has_been_collected = false;
+static bool builtin_exports_has_been_collected = false;
+
+static void SharedHasBeenCollected(
+    const v8::WeakCallbackInfo<v8::Persistent<v8::Object>>& data) {
+  shared_has_been_collected = true;
+  data.GetParameter()->Reset();
+}
+
+
+static void BuiltinExportsHasBeenCollected(
+    const v8::WeakCallbackInfo<v8::Persistent<v8::Object>>& data) {
+  builtin_exports_has_been_collected = true;
+  data.GetParameter()->Reset();
+}
+
+
+TEST(BootstrappingExports) {
+  FLAG_expose_natives_as = "natives";
+  CcTest::InitializeVM();
+  v8::Isolate* isolate = CcTest::isolate();
+
+  if (Snapshot::HaveASnapshotToStartFrom(CcTest::i_isolate())) return;
+
+  shared_has_been_collected = false;
+  builtin_exports_has_been_collected = false;
+
+  v8::Persistent<v8::Object> shared;
+  v8::Persistent<v8::Object> builtin_exports;
+
+  {
+    v8::HandleScope scope(isolate);
+    v8::Handle<v8::Object> natives =
+        CcTest::global()->Get(v8_str("natives"))->ToObject(isolate);
+    shared.Reset(isolate, natives->Get(v8_str("shared"))->ToObject(isolate));
+    natives->Delete(v8_str("shared"));
+    builtin_exports.Reset(
+        isolate, natives->Get(v8_str("builtin_exports"))->ToObject(isolate));
+    natives->Delete(v8_str("builtin_exports"));
+  }
+
+  shared.SetWeak(&shared, SharedHasBeenCollected,
+                 v8::WeakCallbackType::kParameter);
+  builtin_exports.SetWeak(&builtin_exports, BuiltinExportsHasBeenCollected,
+                          v8::WeakCallbackType::kParameter);
+
+  CcTest::heap()->CollectAllAvailableGarbage("fire weak callbacks");
+
+  CHECK(shared_has_been_collected);
+  CHECK(builtin_exports_has_been_collected);
+}
index f49b1a07eb37354b357ddd843b8fd1d709626aa5..cce88b73dcf35fe2d6ac0e9da3815105ec797635 100644 (file)
@@ -25,7 +25,7 @@
 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-// Flags: --expose-debug-as debug --expose-natives-as=builtins
+// Flags: --expose-debug-as debug
 
 // Check that the ScopeIterator can properly recreate the scope at
 // every point when stepping through functions.
index 69cee994aa3e95eb8d3ad550a998a32395ccfc1f..ba05317979686a7cb2b671e588cae35841af24e9 100644 (file)
@@ -25,7 +25,7 @@
 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-// Flags: --expose-debug-as debug --expose-natives-as=builtins
+// Flags: --expose-debug-as debug
 
 // Check that the ScopeIterator can properly recreate the scope at
 // every point when stepping through functions.
index 319f87991f3b35fd22fc15c880f6611db14a4369..c120640605585eb0977ce9e0d1ec4f5dec0c8aaf 100644 (file)
@@ -25,7 +25,7 @@
 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-// Flags: --expose-debug-as debug --expose-natives-as=builtins
+// Flags: --expose-debug-as debug
 
 // Check that the ScopeIterator can properly recreate the scope at
 // every point when stepping through functions.
index eb9c82f8c728923199e98d8167bdf3367d01fff3..a5743fe56632fb973aeed25112613f03c0f95f1a 100644 (file)
@@ -25,7 +25,7 @@
 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-// Flags: --expose-debug-as debug --expose-natives-as=builtins
+// Flags: --expose-debug-as debug
 
 // Check that the ScopeIterator can properly recreate the scope at
 // every point when stepping through functions.
index 250bee4d815fbb9bd7ba0bf5c80dc7ac66f44b5d..cabacbaa8eeec00e5af11e8582e07f3d2f36fd78 100644 (file)
@@ -25,7 +25,7 @@
 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-// Flags: --expose-debug-as debug --expose-natives-as=builtins
+// Flags: --expose-debug-as debug
 
 // Check that the ScopeIterator can properly recreate the scope at
 // every point when stepping through functions.
index 2d8357fea49f0db2d6267bc37f09f99ea0bd542f..f222fbd4fb863e29d4c222dd35aba492db0cf03e 100644 (file)
@@ -25,7 +25,7 @@
 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-// Flags: --expose-debug-as debug --expose-natives-as=builtins
+// Flags: --expose-debug-as debug
 
 // Check that the ScopeIterator can properly recreate the scope at
 // every point when stepping through functions.
index 4f0c0668433dd79c9dc36f0aad65e39d8118bdaa..eba115d26f2ed925edb73f3909f76a6bcd70103a 100644 (file)
@@ -25,7 +25,7 @@
 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-// Flags: --expose-debug-as debug --expose-natives-as=builtins
+// Flags: --expose-debug-as debug
 
 // Check that the ScopeIterator can properly recreate the scope at
 // every point when stepping through functions.
index f91fab5e4df0220abc84dcf60e2bf50e19ba1b6e..c0a8a0034a2f1d4139539e11219ea31ee65ec96a 100644 (file)
@@ -25,7 +25,7 @@
 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-// Flags: --expose-debug-as debug --expose-natives-as=builtins
+// Flags: --expose-debug-as debug
 
 // Check that the ScopeIterator can properly recreate the scope at
 // every point when stepping through functions.
index dba3a4d4057c93f4d73ae156be9c08c0c6269e8d..a0e48ffdebc4f26c1f2aa9da94e3da173171b5a9 100644 (file)
@@ -26,9 +26,9 @@
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 
-// Flags: --expose-natives_as natives
-// Test keyed access to deleted property in a global object without access checks.
-// Regression test that exposed the_hole value from Runtime_KeyedGetPoperty.
+// Flags: --expose-natives-as natives
+// Test keyed access to deleted property in a global object w/o access checks.
+// Regression test that exposed the_hole value from Runtime_KeyedGetProperty.
 
 var name = "fisk";
 natives[name] = name;
index fbc47bdd1463d09d67220cd640eb96c56b57d1c7..b1d47b588a95aa7be870eca8e1473f1d47891962 100644 (file)
 
 // See: http://code.google.com/p/v8/issues/detail?id=1878
 
-// Flags: --allow-natives-syntax --expose_natives_as=natives
+// Flags: --allow-natives-syntax --expose-natives-as=natives
 
 var a = Array();
 
 for (var i = 0; i < 1000; i++) {
-  var ai = natives.InternalArray(10000);
+  var ai = natives.builtin_exports.InternalArray(10000);
   assertFalse(%HaveSameMap(ai, a));
   assertTrue(%HasFastObjectElements(ai));
 }
 
 for (var i = 0; i < 1000; i++) {
-  var ai = new natives.InternalArray(10000);
+  var ai = new natives.builtin_exports.InternalArray(10000);
   assertFalse(%HaveSameMap(ai, a));
   assertTrue(%HasFastObjectElements(ai));
 }
index 36a7dea3eaf63e37aca9ccc1d8b368637b44a20b..229db0db4c32c1e2f2b25aa9487b5eae0e7f5c32 100644 (file)
@@ -26,7 +26,7 @@
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 
-// Flags: --expose-natives_as natives
+// Flags: --expose-natives-as natives
 // Test the SameValue internal method.
 
 var obj1 = {x: 10, y: 11, z: "test"};