Cleanup NewFunctionFromSharedFunctionInfo

NewFunctionFromSharedFunctionInfo is not called with `undefined`
anymore, and so can be changed to just accept `Handle<Context>`.

Additionally, reporting script compilation to the debugger can now
be moved into `Compiler::PostInstantiation`.

R=yangguo@chromium.org

Change-Id: I0a9b3fa51f87f41b4fc97a29f79c110c6246f273
Reviewed-on: https://chromium-review.googlesource.com/1024832
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Commit-Queue: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52749}
This commit is contained in:
Ingvar Stepanyan 2018-04-23 22:20:24 +01:00 committed by Commit Bot
parent 7f8e83b56d
commit 1c23f888a1
4 changed files with 20 additions and 29 deletions

View File

@ -76,6 +76,7 @@ Gwang Yoon Hwang <ryumiel@company100.net>
Henrique Ferreiro <henrique.ferreiro@gmail.com> Henrique Ferreiro <henrique.ferreiro@gmail.com>
Hirofumi Mako <mkhrfm@gmail.com> Hirofumi Mako <mkhrfm@gmail.com>
Honggyu Kim <honggyu.kp@gmail.com> Honggyu Kim <honggyu.kp@gmail.com>
Ingvar Stepanyan <me@rreverser.com>
Ioseb Dzmanashvili <ioseb.dzmanashvili@gmail.com> Ioseb Dzmanashvili <ioseb.dzmanashvili@gmail.com>
Isiah Meadows <impinball@gmail.com> Isiah Meadows <impinball@gmail.com>
Jaime Bernardo <jaime@janeasystems.com> Jaime Bernardo <jaime@janeasystems.com>

View File

@ -1957,6 +1957,12 @@ void Compiler::PostInstantiation(Handle<JSFunction> function,
function->set_code(code); function->set_code(code);
} }
} }
if (shared->is_toplevel() || shared->is_wrapped()) {
// If it's a top-level script, report compilation to the debugger.
Handle<Script> script(handle(Script::cast(shared->script())));
script->GetIsolate()->debug()->OnAfterCompile(script);
}
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@ -2137,17 +2137,15 @@ DEFINE_ERROR(WasmRuntimeError, wasm_runtime_error)
Handle<JSFunction> Factory::NewFunction(Handle<Map> map, Handle<JSFunction> Factory::NewFunction(Handle<Map> map,
Handle<SharedFunctionInfo> info, Handle<SharedFunctionInfo> info,
Handle<Object> context_or_undefined, Handle<Context> context,
PretenureFlag pretenure) { PretenureFlag pretenure) {
Handle<JSFunction> function(JSFunction::cast(New(map, pretenure)), isolate()); Handle<JSFunction> function(JSFunction::cast(New(map, pretenure)), isolate());
DCHECK(context_or_undefined->IsContext() ||
context_or_undefined->IsUndefined(isolate()));
function->initialize_properties(); function->initialize_properties();
function->initialize_elements(); function->initialize_elements();
function->set_shared(*info); function->set_shared(*info);
function->set_code(info->GetCode()); function->set_code(info->GetCode());
function->set_context(*context_or_undefined); function->set_context(*context);
function->set_feedback_cell(*many_closures_cell()); function->set_feedback_cell(*many_closures_cell());
int header_size; int header_size;
if (map->has_prototype_slot()) { if (map->has_prototype_slot()) {
@ -2298,31 +2296,24 @@ Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo(
Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo( Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo(
Handle<Map> initial_map, Handle<SharedFunctionInfo> info, Handle<Map> initial_map, Handle<SharedFunctionInfo> info,
Handle<Object> context_or_undefined, PretenureFlag pretenure) { Handle<Context> context, PretenureFlag pretenure) {
DCHECK_EQ(JS_FUNCTION_TYPE, initial_map->instance_type()); DCHECK_EQ(JS_FUNCTION_TYPE, initial_map->instance_type());
Handle<JSFunction> result = Handle<JSFunction> result =
NewFunction(initial_map, info, context_or_undefined, pretenure); NewFunction(initial_map, info, context, pretenure);
if (context_or_undefined->IsContext()) { // Give compiler a chance to pre-initialize.
// Give compiler a chance to pre-initialize. Compiler::PostInstantiation(result, pretenure);
Compiler::PostInstantiation(result, pretenure);
}
if (info->is_toplevel() || info->is_wrapped()) {
// Report script compilation to debugger.
isolate()->debug()->OnAfterCompile(handle(Script::cast(info->script())));
}
return result; return result;
} }
Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo( Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo(
Handle<Map> initial_map, Handle<SharedFunctionInfo> info, Handle<Map> initial_map, Handle<SharedFunctionInfo> info,
Handle<Object> context_or_undefined, Handle<FeedbackCell> feedback_cell, Handle<Context> context, Handle<FeedbackCell> feedback_cell,
PretenureFlag pretenure) { PretenureFlag pretenure) {
DCHECK_EQ(JS_FUNCTION_TYPE, initial_map->instance_type()); DCHECK_EQ(JS_FUNCTION_TYPE, initial_map->instance_type());
Handle<JSFunction> result = Handle<JSFunction> result =
NewFunction(initial_map, info, context_or_undefined, pretenure); NewFunction(initial_map, info, context, pretenure);
// Bump the closure count that is encoded in the feedback cell's map. // Bump the closure count that is encoded in the feedback cell's map.
if (feedback_cell->map() == *no_closures_cell_map()) { if (feedback_cell->map() == *no_closures_cell_map()) {
@ -2342,15 +2333,8 @@ Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo(
} }
result->set_feedback_cell(*feedback_cell); result->set_feedback_cell(*feedback_cell);
if (context_or_undefined->IsContext()) { // Give compiler a chance to pre-initialize.
// Give compiler a chance to pre-initialize. Compiler::PostInstantiation(result, pretenure);
Compiler::PostInstantiation(result, pretenure);
}
if (info->is_toplevel() || info->is_wrapped()) {
// Report script compilation to debugger.
isolate()->debug()->OnAfterCompile(handle(Script::cast(info->script())));
}
return result; return result;
} }

View File

@ -682,7 +682,7 @@ class V8_EXPORT_PRIVATE Factory {
Handle<JSFunction> NewFunctionFromSharedFunctionInfo( Handle<JSFunction> NewFunctionFromSharedFunctionInfo(
Handle<Map> initial_map, Handle<SharedFunctionInfo> function_info, Handle<Map> initial_map, Handle<SharedFunctionInfo> function_info,
Handle<Object> context_or_undefined, Handle<FeedbackCell> feedback_cell, Handle<Context> context, Handle<FeedbackCell> feedback_cell,
PretenureFlag pretenure = TENURED); PretenureFlag pretenure = TENURED);
Handle<JSFunction> NewFunctionFromSharedFunctionInfo( Handle<JSFunction> NewFunctionFromSharedFunctionInfo(
@ -691,7 +691,7 @@ class V8_EXPORT_PRIVATE Factory {
Handle<JSFunction> NewFunctionFromSharedFunctionInfo( Handle<JSFunction> NewFunctionFromSharedFunctionInfo(
Handle<Map> initial_map, Handle<SharedFunctionInfo> function_info, Handle<Map> initial_map, Handle<SharedFunctionInfo> function_info,
Handle<Object> context_or_undefined, PretenureFlag pretenure = TENURED); Handle<Context> context, PretenureFlag pretenure = TENURED);
Handle<JSFunction> NewFunctionFromSharedFunctionInfo( Handle<JSFunction> NewFunctionFromSharedFunctionInfo(
Handle<SharedFunctionInfo> function_info, Handle<Context> context, Handle<SharedFunctionInfo> function_info, Handle<Context> context,
@ -701,7 +701,7 @@ class V8_EXPORT_PRIVATE Factory {
// initialization. All other utility methods call into this. // initialization. All other utility methods call into this.
Handle<JSFunction> NewFunction(Handle<Map> map, Handle<JSFunction> NewFunction(Handle<Map> map,
Handle<SharedFunctionInfo> info, Handle<SharedFunctionInfo> info,
Handle<Object> context_or_undefined, Handle<Context> context,
PretenureFlag pretenure = TENURED); PretenureFlag pretenure = TENURED);
// Create a serialized scope info. // Create a serialized scope info.