Reviewers: mvstanton,

Description:
Native context: run prologue.js before runtime.js

[email protected]

Please review this at https://codereview.chromium.org/1294803004/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+62, -35 lines):
  M src/bootstrapper.cc
  M src/prologue.js
  M src/runtime.js
  M src/runtime/runtime.h
  M src/runtime/runtime-internal.cc
  M tools/gyp/v8.gyp


Index: src/bootstrapper.cc
diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc
index 5f4e0995f843a69dc8915b9be04cabdddc415d5e..a5b4b1b8380788c06ae70e4f74ffcc9f199b5416 100644
--- a/src/bootstrapper.cc
+++ b/src/bootstrapper.cc
@@ -2086,20 +2086,23 @@ bool Genesis::InstallNatives(ContextType context_type) {

   native_context()->set_runtime_context(*context);

-  if (context_type == THIN_CONTEXT) {
-    int js_builtins_script_index = Natives::GetDebuggerCount();
-    if (!Bootstrapper::CompileBuiltin(isolate(), js_builtins_script_index))
-      return false;
-    if (!InstallJSBuiltins(builtins)) return false;
-    return true;
-  }
-
   // Set up the utils object as shared container between native scripts.
Handle<JSObject> utils = factory()->NewJSObject(isolate()->object_function());
   JSObject::NormalizeProperties(utils, CLEAR_INOBJECT_PROPERTIES, 16,
                                 "utils container for native scripts");
   native_context()->set_natives_utils_object(*utils);

+  int builtin_index = Natives::GetDebuggerCount();
+  // Only run prologue.js and runtime.js at this point.
+  DCHECK_EQ(builtin_index, Natives::GetIndex("prologue"));
+ if (!Bootstrapper::CompileBuiltin(isolate(), builtin_index++)) return false;
+  DCHECK_EQ(builtin_index, Natives::GetIndex("runtime"));
+ if (!Bootstrapper::CompileBuiltin(isolate(), builtin_index++)) return false;
+  if (!InstallJSBuiltins(builtins)) return false;
+
+  // A thin context is ready at this point.
+  if (context_type == THIN_CONTEXT) return true;
+
   if (FLAG_expose_natives_as != NULL) {
Handle<String> utils_key = factory()->NewStringFromAsciiChecked("utils");
     JSObject::AddProperty(builtins, utils_key, utils, NONE);
@@ -2385,13 +2388,9 @@ bool Genesis::InstallNatives(ContextType context_type) {
 #undef INSTALL_PUBLIC_SYMBOL
   }

-  int i = Natives::GetDebuggerCount();
-  if (!Bootstrapper::CompileBuiltin(isolate(), i)) return false;
-
-  if (!InstallJSBuiltins(builtins)) return false;
-
-  for (++i; i < Natives::GetBuiltinsCount(); ++i) {
-    if (!Bootstrapper::CompileBuiltin(isolate(), i)) return false;
+  // Run the rest of the native scripts.
+  while (builtin_index < Natives::GetBuiltinsCount()) {
+ if (!Bootstrapper::CompileBuiltin(isolate(), builtin_index++)) return false;
   }

   if (!CallUtilsFunction(isolate(), "PostNatives")) return false;
Index: src/prologue.js
diff --git a/src/prologue.js b/src/prologue.js
index 720f1de075431decb1ac2c98c7d5a80f6de0f51e..d41146fb5bdef0d61c515bcab233fcf909aaa0eb 100644
--- a/src/prologue.js
+++ b/src/prologue.js
@@ -76,17 +76,7 @@ function InstallConstants(object, constants) {


 function InstallFunctions(object, attributes, functions) {
-  %CheckIsBootstrapping();
- %OptimizeObjectForAddingMultipleProperties(object, functions.length >> 1);
-  for (var i = 0; i < functions.length; i += 2) {
-    var key = functions[i];
-    var f = functions[i + 1];
-    SetFunctionName(f, key);
-    %FunctionRemovePrototype(f);
-    %AddNamedProperty(object, key, f, attributes);
-    %SetNativeFlag(f);
-  }
-  %ToFastProperties(object);
+  %InstallFunctionsFromArray(object, attributes, functions);
 }


@@ -266,12 +256,4 @@ InstallFunctions(utils, NONE, [
   "PostDebug", PostDebug,
 ]);

-// TODO(yangguo): run prologue.js before runtime.js
-ExportToRuntime(function(to) {
-  to.ToNumber = $toNumber;
-  to.ToString = $toString;
-  to.ToInteger = $toInteger;
-  to.ToLength = $toLength;
-});
-
 })
Index: src/runtime.js
diff --git a/src/runtime.js b/src/runtime.js
index 4de9c2997df1a5debf4341aaef8fdb6d212b2902..20b608e9072430597cbdb5607ceb0f0237709522 100644
--- a/src/runtime.js
+++ b/src/runtime.js
@@ -897,6 +897,7 @@ function ToPositiveInteger(x, rangeErrorIndex) {
 %FunctionSetPrototype(GlobalArray, new GlobalArray(0));

// ----------------------------------------------------------------------------
+// Exports

 $concatIterableToArray = ConcatIterableToArray;
 $defaultNumber = DefaultNumber;
@@ -915,4 +916,11 @@ $toPositiveInteger = ToPositiveInteger;
 $toPrimitive = ToPrimitive;
 $toString = ToString;

+utils.ExportToRuntime(function(to) {
+  to.ToNumber = $toNumber;
+  to.ToString = $toString;
+  to.ToInteger = $toInteger;
+  to.ToLength = $toLength;
+});
+
 })
Index: src/runtime/runtime-internal.cc
diff --git a/src/runtime/runtime-internal.cc b/src/runtime/runtime-internal.cc index fa9ac008965efd918c8ed571281f71cbc58a0ccb..97edea53369078a99588b1832a6ad62dfeb07850 100644
--- a/src/runtime/runtime-internal.cc
+++ b/src/runtime/runtime-internal.cc
@@ -6,6 +6,7 @@

 #include "src/arguments.h"
 #include "src/bootstrapper.h"
+#include "src/conversions.h"
 #include "src/debug/debug.h"
 #include "src/frames-inl.h"
 #include "src/messages.h"
@@ -44,6 +45,42 @@ RUNTIME_FUNCTION(Runtime_ImportExperimentalToRuntime) {
 }


+RUNTIME_FUNCTION(Runtime_InstallFunctionsFromArray) {
+  HandleScope scope(isolate);
+  DCHECK(args.length() == 3);
+  CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0);
+  CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 1);
+  CONVERT_ARG_HANDLE_CHECKED(JSArray, functions, 2);
+  RUNTIME_ASSERT(isolate->bootstrapper()->IsActive());
+
+  int num_items = NumberToInt32(functions->length()) / 2;
+  if (!object->IsJSGlobalObject() && object->HasFastProperties()) {
+ JSObject::NormalizeProperties(object, KEEP_INOBJECT_PROPERTIES, num_items,
+                                  "InstallFunctions");
+  }
+
+  Handle<FixedArray> array(FixedArray::cast(functions->elements()));
+  for (int i = 0; i < num_items; ++i) {
+    RUNTIME_ASSERT(array->get(i * 2)->IsString());
+    RUNTIME_ASSERT(array->get(i * 2 + 1)->IsJSFunction());
+    Handle<String> name(String::cast(array->get(i * 2)));
+    Handle<JSFunction> fun(JSFunction::cast(array->get(i * 2 + 1)));
+    fun->shared()->set_name(*name);
+    RUNTIME_ASSERT(fun->RemovePrototype());
+    fun->shared()->set_native(true);
+    RETURN_FAILURE_ON_EXCEPTION(
+        isolate,
+ JSObject::SetOwnPropertyIgnoreAttributes(object, name, fun, attrs));
+  }
+
+  if (!object->IsJSGlobalObject()) {
+    JSObject::MigrateSlowToFast(object, 0, "InstallFunctions");
+  }
+
+  return isolate->heap()->undefined_value();
+}
+
+
 RUNTIME_FUNCTION(Runtime_Throw) {
   HandleScope scope(isolate);
   DCHECK(args.length() == 1);
Index: src/runtime/runtime.h
diff --git a/src/runtime/runtime.h b/src/runtime/runtime.h
index e145b2db0fb151d308b98d5a739d1048a8e3cc59..3ff446ae0c48795a02a7621d8200f8f1dc41a882 100644
--- a/src/runtime/runtime.h
+++ b/src/runtime/runtime.h
@@ -303,6 +303,7 @@ namespace internal {
   F(CheckIsBootstrapping, 0, 1)               \
   F(ImportToRuntime, 1, 1)                    \
   F(ImportExperimentalToRuntime, 1, 1)        \
+  F(InstallFunctionsFromArray, 3, 1)          \
   F(Throw, 1, 1)                              \
   F(ReThrow, 1, 1)                            \
   F(UnwindAndFindExceptionHandler, 0, 1)      \
Index: tools/gyp/v8.gyp
diff --git a/tools/gyp/v8.gyp b/tools/gyp/v8.gyp
index 0ac43deaf5fe5a463e3f5f65b5e9b2a6c6bd305f..34e2c97d823e943101cfeb047a01a42dadd45dde 100644
--- a/tools/gyp/v8.gyp
+++ b/tools/gyp/v8.gyp
@@ -1771,8 +1771,8 @@
         'library_files': [
           '../../src/macros.py',
           '../../src/messages.h',
-          '../../src/runtime.js',
           '../../src/prologue.js',
+          '../../src/runtime.js',
           '../../src/v8natives.js',
           '../../src/symbol.js',
           '../../src/array.js',


--
--
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.

Reply via email to