Reviewers: mvstanton,

Description:
Native context: Fix issue when running prologue.js before runtime.js

%InstallFunctionsFromArray is not entirely equivalent to the old
InstallFunctions implementation, which causes gc stress failures.

TBR=mvstan...@chromium.org

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

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

Affected files (+34, -59 lines):
  M src/prologue.js
  M src/runtime/runtime.h
  M src/runtime/runtime-internal.cc


Index: src/prologue.js
diff --git a/src/prologue.js b/src/prologue.js
index d41146fb5bdef0d61c515bcab233fcf909aaa0eb..3153db6e157aba04288fabef4ff7f6e2d6cf6b42 100644
--- a/src/prologue.js
+++ b/src/prologue.js
@@ -23,7 +23,7 @@ var exports_to_runtime = UNDEFINED;
 function Export(f) {
   f.next = exports;
   exports = f;
-};
+}


 // Export to the native context for calls from the runtime.
@@ -39,7 +39,7 @@ function ExportToRuntime(f) {
 function Import(f) {
   f.next = imports;
   imports = f;
-};
+}


 // In normal natives, import from experimental natives.
@@ -47,7 +47,7 @@ function Import(f) {
 function ImportFromExperimental(f) {
   f.next = imports_from_experimental;
   imports_from_experimental = f;
-};
+}


 function SetFunctionName(f, name, prefix) {
@@ -76,7 +76,17 @@ function InstallConstants(object, constants) {


 function InstallFunctions(object, attributes, functions) {
-  %InstallFunctionsFromArray(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);
 }


@@ -192,7 +202,7 @@ function PostNatives(utils) {

   utils.PostNatives = UNDEFINED;
   utils.ImportFromExperimental = UNDEFINED;
-};
+}


 function PostExperimentals(utils) {
@@ -221,7 +231,7 @@ function PostExperimentals(utils) {
   utils.PostDebug = UNDEFINED;
   utils.Import = UNDEFINED;
   utils.Export = UNDEFINED;
-};
+}


 function PostDebug(utils) {
@@ -236,24 +246,26 @@ function PostDebug(utils) {
   utils.PostExperimentals = UNDEFINED;
   utils.Import = UNDEFINED;
   utils.Export = UNDEFINED;
-};
+}

 // -----------------------------------------------------------------------

-InstallFunctions(utils, NONE, [
-  "Import", Import,
-  "Export", Export,
-  "ExportToRuntime", ExportToRuntime,
-  "ImportFromExperimental", ImportFromExperimental,
-  "SetFunctionName", SetFunctionName,
-  "InstallConstants", InstallConstants,
-  "InstallFunctions", InstallFunctions,
-  "InstallGetter", InstallGetter,
-  "InstallGetterSetter", InstallGetterSetter,
-  "SetUpLockedPrototype", SetUpLockedPrototype,
-  "PostNatives", PostNatives,
-  "PostExperimentals", PostExperimentals,
-  "PostDebug", PostDebug,
-]);
+%OptimizeObjectForAddingMultipleProperties(utils, 13);
+
+utils.Import = Import;
+utils.Export = Export;
+utils.ExportToRuntime = ExportToRuntime;
+utils.ImportFromExperimental = ImportFromExperimental;
+utils.SetFunctionName = SetFunctionName;
+utils.InstallConstants = InstallConstants;
+utils.InstallFunctions = InstallFunctions;
+utils.InstallGetter = InstallGetter;
+utils.InstallGetterSetter = InstallGetterSetter;
+utils.SetUpLockedPrototype = SetUpLockedPrototype;
+utils.PostNatives = PostNatives;
+utils.PostExperimentals = PostExperimentals;
+utils.PostDebug = PostDebug;
+
+%ToFastProperties(utils);

 })
Index: src/runtime/runtime-internal.cc
diff --git a/src/runtime/runtime-internal.cc b/src/runtime/runtime-internal.cc index 97edea53369078a99588b1832a6ad62dfeb07850..e6ea9fd3b78165bc47a75451b82ca4c90606d9c3 100644
--- a/src/runtime/runtime-internal.cc
+++ b/src/runtime/runtime-internal.cc
@@ -45,42 +45,6 @@ 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 3ff446ae0c48795a02a7621d8200f8f1dc41a882..e145b2db0fb151d308b98d5a739d1048a8e3cc59 100644
--- a/src/runtime/runtime.h
+++ b/src/runtime/runtime.h
@@ -303,7 +303,6 @@ 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)      \


--
--
v8-dev mailing list
v8-dev@googlegroups.com
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 v8-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to