[bootstrapper] extra natives must not use natives syntax.

R=bmeurer@chromium.org, domenic@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#33770}
This commit is contained in:
yangguo 2016-02-05 04:33:20 -08:00 committed by Commit bot
parent 4094d6b567
commit 8a2d571734
9 changed files with 58 additions and 16 deletions

View File

@ -1821,7 +1821,7 @@ bool Bootstrapper::CompileBuiltin(Isolate* isolate, int index) {
Handle<Object> args[] = {global, utils, extras_utils};
return Bootstrapper::CompileNative(isolate, name, source_code,
arraysize(args), args);
arraysize(args), args, NATIVES_CODE);
}
@ -1834,7 +1834,7 @@ bool Bootstrapper::CompileExperimentalBuiltin(Isolate* isolate, int index) {
Handle<Object> utils = isolate->natives_utils_object();
Handle<Object> args[] = {global, utils};
return Bootstrapper::CompileNative(isolate, name, source_code,
arraysize(args), args);
arraysize(args), args, NATIVES_CODE);
}
@ -1848,7 +1848,7 @@ bool Bootstrapper::CompileExtraBuiltin(Isolate* isolate, int index) {
Handle<Object> extras_utils = isolate->extras_utils_object();
Handle<Object> args[] = {global, binding, extras_utils};
return Bootstrapper::CompileNative(isolate, name, source_code,
arraysize(args), args);
arraysize(args), args, EXTENSION_CODE);
}
@ -1863,13 +1863,13 @@ bool Bootstrapper::CompileExperimentalExtraBuiltin(Isolate* isolate,
Handle<Object> extras_utils = isolate->extras_utils_object();
Handle<Object> args[] = {global, binding, extras_utils};
return Bootstrapper::CompileNative(isolate, name, source_code,
arraysize(args), args);
arraysize(args), args, EXTENSION_CODE);
}
bool Bootstrapper::CompileNative(Isolate* isolate, Vector<const char> name,
Handle<String> source, int argc,
Handle<Object> argv[]) {
Handle<Object> argv[],
NativesFlag natives_flag) {
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
@ -1886,7 +1886,7 @@ bool Bootstrapper::CompileNative(Isolate* isolate, Vector<const char> name,
isolate->factory()->NewStringFromUtf8(name).ToHandleChecked();
Handle<SharedFunctionInfo> function_info = Compiler::CompileScript(
source, script_name, 0, 0, ScriptOriginOptions(), Handle<Object>(),
context, NULL, NULL, ScriptCompiler::kNoCompileOptions, NATIVES_CODE,
context, NULL, NULL, ScriptCompiler::kNoCompileOptions, natives_flag,
false);
if (function_info.is_null()) return false;
@ -1944,7 +1944,7 @@ bool Genesis::CompileExtension(Isolate* isolate, v8::Extension* extension) {
function_info = Compiler::CompileScript(
source, script_name, 0, 0, ScriptOriginOptions(), Handle<Object>(),
context, extension, NULL, ScriptCompiler::kNoCompileOptions,
NOT_NATIVES_CODE, false);
EXTENSION_CODE, false);
if (function_info.is_null()) return false;
cache->Add(name, function_info);
}

View File

@ -109,7 +109,7 @@ class Bootstrapper final {
static bool CompileNative(Isolate* isolate, Vector<const char> name,
Handle<String> source, int argc,
Handle<Object> argv[]);
Handle<Object> argv[], NativesFlag natives_flag);
static bool CompileBuiltin(Isolate* isolate, int index);
static bool CompileExperimentalBuiltin(Isolate* isolate, int index);
static bool CompileExtraBuiltin(Isolate* isolate, int index);

View File

@ -1471,6 +1471,9 @@ Handle<SharedFunctionInfo> Compiler::CompileScript(
if (natives == NATIVES_CODE) {
script->set_type(Script::TYPE_NATIVE);
script->set_hide_source(true);
} else if (natives == EXTENSION_CODE) {
script->set_type(Script::TYPE_EXTENSION);
script->set_hide_source(true);
}
if (!script_name.is_null()) {
script->set_name(*script_name);

View File

@ -36,10 +36,10 @@ typedef SimpleStringResource<char, v8::String::ExternalOneByteStringResource>
typedef SimpleStringResource<uc16, v8::String::ExternalStringResource>
SimpleTwoByteStringResource;
const char* const ExternalizeStringExtension::kSource =
"native function externalizeString();"
"native function isOneByteString();";
"native function isOneByteString();"
"function x() { return 1; }";
v8::Local<v8::FunctionTemplate>
ExternalizeStringExtension::GetNativeFunctionTemplate(

View File

@ -529,7 +529,7 @@ enum VisitMode {
};
// Flag indicating whether code is built into the VM (one of the natives files).
enum NativesFlag { NOT_NATIVES_CODE, NATIVES_CODE };
enum NativesFlag { NOT_NATIVES_CODE, EXTENSION_CODE, NATIVES_CODE };
// JavaScript defines two kinds of 'nil'.
enum NilValue { kNullValue, kUndefinedValue };

View File

@ -377,8 +377,7 @@ RUNTIME_FUNCTION(Runtime_AbortJS) {
RUNTIME_FUNCTION(Runtime_NativeScriptsCount) {
DCHECK(args.length() == 0);
return Smi::FromInt(Natives::GetBuiltinsCount() +
ExtraNatives::GetBuiltinsCount());
return Smi::FromInt(Natives::GetBuiltinsCount());
}

View File

@ -24169,6 +24169,37 @@ static void ExtrasBindingTestRuntimeFunction(
args.GetReturnValue().Set(v8_num(7));
}
TEST(ExtrasFunctionSource) {
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope handle_scope(isolate);
LocalContext env;
v8::Local<v8::Object> binding = env->GetExtrasBindingObject();
// Functions defined in extras do not expose source code.
auto func = binding->Get(env.local(), v8_str("testFunctionToString"))
.ToLocalChecked()
.As<v8::Function>();
auto undefined = v8::Undefined(isolate);
auto result = func->Call(env.local(), undefined, 0, {})
.ToLocalChecked()
.As<v8::String>();
CHECK(result->StrictEquals(v8_str("function foo() { [native code] }")));
// Functions defined in extras do not show up in the stack trace.
auto wrapper = binding->Get(env.local(), v8_str("testStackTrace"))
.ToLocalChecked()
.As<v8::Function>();
CHECK(env->Global()->Set(env.local(), v8_str("wrapper"), wrapper).FromJust());
ExpectString(
"function f(x) { return wrapper(x) }"
"function g() { return new Error().stack; }"
"f(g)",
"Error\n"
" at g (<anonymous>:1:58)\n"
" at f (<anonymous>:1:24)\n"
" at <anonymous>:1:78");
}
TEST(ExtrasBindingObject) {
v8::Isolate* isolate = CcTest::isolate();

View File

@ -12,6 +12,15 @@
return binding.runtime(3);
};
binding.testFunctionToString = function() {
function foo() { return 1; }
return foo.toString();
};
binding.testStackTrace = function(f) {
return f();
}
// Exercise all of the extras utils:
// - v8.createPrivateSymbol
// - v8.simpleBind, v8.uncurryThis

View File

@ -73,8 +73,8 @@ for (i = 0; i < scripts.length; i++) {
// This has to be updated if the number of native scripts change.
assertEquals(%NativeScriptsCount(), named_native_count);
// Only the 'gc' extension is loaded.
assertEquals(1, extension_count);
// The 'gc' extension and one extras script is loaded.
assertEquals(2, extension_count);
// This script and mjsunit.js has been loaded. If using d8, d8 loads
// a normal script during startup too.
assertTrue(normal_count == 2 || normal_count == 3);