Commit c01f419e authored by yangguo's avatar yangguo Committed by Commit bot

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=mvstanton@chromium.org

Review URL: https://codereview.chromium.org/1287203006

Cr-Commit-Position: refs/heads/master@{#30220}
parent 00df60d1
...@@ -23,7 +23,7 @@ var exports_to_runtime = UNDEFINED; ...@@ -23,7 +23,7 @@ var exports_to_runtime = UNDEFINED;
function Export(f) { function Export(f) {
f.next = exports; f.next = exports;
exports = f; exports = f;
}; }
// Export to the native context for calls from the runtime. // Export to the native context for calls from the runtime.
...@@ -39,7 +39,7 @@ function ExportToRuntime(f) { ...@@ -39,7 +39,7 @@ function ExportToRuntime(f) {
function Import(f) { function Import(f) {
f.next = imports; f.next = imports;
imports = f; imports = f;
}; }
// In normal natives, import from experimental natives. // In normal natives, import from experimental natives.
...@@ -47,7 +47,7 @@ function Import(f) { ...@@ -47,7 +47,7 @@ function Import(f) {
function ImportFromExperimental(f) { function ImportFromExperimental(f) {
f.next = imports_from_experimental; f.next = imports_from_experimental;
imports_from_experimental = f; imports_from_experimental = f;
}; }
function SetFunctionName(f, name, prefix) { function SetFunctionName(f, name, prefix) {
...@@ -76,7 +76,17 @@ function InstallConstants(object, constants) { ...@@ -76,7 +76,17 @@ function InstallConstants(object, constants) {
function InstallFunctions(object, attributes, functions) { 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) { ...@@ -192,7 +202,7 @@ function PostNatives(utils) {
utils.PostNatives = UNDEFINED; utils.PostNatives = UNDEFINED;
utils.ImportFromExperimental = UNDEFINED; utils.ImportFromExperimental = UNDEFINED;
}; }
function PostExperimentals(utils) { function PostExperimentals(utils) {
...@@ -221,7 +231,7 @@ function PostExperimentals(utils) { ...@@ -221,7 +231,7 @@ function PostExperimentals(utils) {
utils.PostDebug = UNDEFINED; utils.PostDebug = UNDEFINED;
utils.Import = UNDEFINED; utils.Import = UNDEFINED;
utils.Export = UNDEFINED; utils.Export = UNDEFINED;
}; }
function PostDebug(utils) { function PostDebug(utils) {
...@@ -236,24 +246,26 @@ function PostDebug(utils) { ...@@ -236,24 +246,26 @@ function PostDebug(utils) {
utils.PostExperimentals = UNDEFINED; utils.PostExperimentals = UNDEFINED;
utils.Import = UNDEFINED; utils.Import = UNDEFINED;
utils.Export = UNDEFINED; utils.Export = UNDEFINED;
}; }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
InstallFunctions(utils, NONE, [ %OptimizeObjectForAddingMultipleProperties(utils, 13);
"Import", Import,
"Export", Export, utils.Import = Import;
"ExportToRuntime", ExportToRuntime, utils.Export = Export;
"ImportFromExperimental", ImportFromExperimental, utils.ExportToRuntime = ExportToRuntime;
"SetFunctionName", SetFunctionName, utils.ImportFromExperimental = ImportFromExperimental;
"InstallConstants", InstallConstants, utils.SetFunctionName = SetFunctionName;
"InstallFunctions", InstallFunctions, utils.InstallConstants = InstallConstants;
"InstallGetter", InstallGetter, utils.InstallFunctions = InstallFunctions;
"InstallGetterSetter", InstallGetterSetter, utils.InstallGetter = InstallGetter;
"SetUpLockedPrototype", SetUpLockedPrototype, utils.InstallGetterSetter = InstallGetterSetter;
"PostNatives", PostNatives, utils.SetUpLockedPrototype = SetUpLockedPrototype;
"PostExperimentals", PostExperimentals, utils.PostNatives = PostNatives;
"PostDebug", PostDebug, utils.PostExperimentals = PostExperimentals;
]); utils.PostDebug = PostDebug;
%ToFastProperties(utils);
}) })
...@@ -45,42 +45,6 @@ RUNTIME_FUNCTION(Runtime_ImportExperimentalToRuntime) { ...@@ -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) { RUNTIME_FUNCTION(Runtime_Throw) {
HandleScope scope(isolate); HandleScope scope(isolate);
DCHECK(args.length() == 1); DCHECK(args.length() == 1);
......
...@@ -303,7 +303,6 @@ namespace internal { ...@@ -303,7 +303,6 @@ namespace internal {
F(CheckIsBootstrapping, 0, 1) \ F(CheckIsBootstrapping, 0, 1) \
F(ImportToRuntime, 1, 1) \ F(ImportToRuntime, 1, 1) \
F(ImportExperimentalToRuntime, 1, 1) \ F(ImportExperimentalToRuntime, 1, 1) \
F(InstallFunctionsFromArray, 3, 1) \
F(Throw, 1, 1) \ F(Throw, 1, 1) \
F(ReThrow, 1, 1) \ F(ReThrow, 1, 1) \
F(UnwindAndFindExceptionHandler, 0, 1) \ F(UnwindAndFindExceptionHandler, 0, 1) \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment