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

Native context: run prologue.js before runtime.js

R=mvstanton@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#30217}
parent 1ecc6715
......@@ -203,8 +203,8 @@ action("js2c") {
sources = [
"src/macros.py",
"src/messages.h",
"src/runtime.js",
"src/prologue.js",
"src/runtime.js",
"src/v8natives.js",
"src/symbol.js",
"src/array.js",
......
......@@ -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;
......
......@@ -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;
});
})
......@@ -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;
});
})
......@@ -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);
......
......@@ -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) \
......
......@@ -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',
......
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