@@ -2500,69 +2500,92 @@ MaybeLocal<Function> ScriptCompiler::CompileFunctionInContext(
25002500 Local<String> arguments[], size_t context_extension_count,
25012501 Local<Object> context_extensions[], CompileOptions options,
25022502 NoCacheReason no_cache_reason) {
2503- PREPARE_FOR_EXECUTION (v8_context, ScriptCompiler, CompileFunctionInContext,
2504- Function);
2505- TRACE_EVENT_CALL_STATS_SCOPED (isolate, " v8" , " V8.ScriptCompiler" );
2503+ return ScriptCompiler::CompileFunctionInContext (
2504+ v8_context, source, arguments_count, arguments, context_extension_count,
2505+ context_extensions, options, no_cache_reason, nullptr );
2506+ }
25062507
2507- DCHECK (options == CompileOptions::kConsumeCodeCache ||
2508- options == CompileOptions::kEagerCompile ||
2509- options == CompileOptions::kNoCompileOptions );
2508+ MaybeLocal<Function> ScriptCompiler::CompileFunctionInContext (
2509+ Local<Context> v8_context, Source* source, size_t arguments_count,
2510+ Local<String> arguments[], size_t context_extension_count,
2511+ Local<Object> context_extensions[], CompileOptions options,
2512+ NoCacheReason no_cache_reason,
2513+ Local<ScriptOrModule>* script_or_module_out) {
2514+ Local<Function> result;
25102515
2511- i::Handle<i::Context> context = Utils::OpenHandle (*v8_context);
2516+ {
2517+ PREPARE_FOR_EXECUTION (v8_context, ScriptCompiler, CompileFunctionInContext,
2518+ Function);
2519+ TRACE_EVENT_CALL_STATS_SCOPED (isolate, " v8" , " V8.ScriptCompiler" );
25122520
2513- DCHECK (context->IsNativeContext ());
2514- i::Handle<i::SharedFunctionInfo> outer_info (
2515- context->empty_function ()->shared (), isolate);
2516-
2517- i::Handle<i::JSFunction> fun;
2518- i::Handle<i::FixedArray> arguments_list =
2519- isolate->factory ()->NewFixedArray (static_cast <int >(arguments_count));
2520- for (int i = 0 ; i < static_cast <int >(arguments_count); i++) {
2521- i::Handle<i::String> argument = Utils::OpenHandle (*arguments[i]);
2522- if (!IsIdentifier (isolate, argument)) return Local<Function>();
2523- arguments_list->set (i, *argument);
2524- }
2525-
2526- for (size_t i = 0 ; i < context_extension_count; ++i) {
2527- i::Handle<i::JSReceiver> extension =
2528- Utils::OpenHandle (*context_extensions[i]);
2529- if (!extension->IsJSObject ()) return Local<Function>();
2530- context = isolate->factory ()->NewWithContext (
2531- context,
2532- i::ScopeInfo::CreateForWithScope (
2533- isolate,
2534- context->IsNativeContext ()
2535- ? i::Handle<i::ScopeInfo>::null ()
2536- : i::Handle<i::ScopeInfo>(context->scope_info (), isolate)),
2537- extension);
2538- }
2521+ DCHECK (options == CompileOptions::kConsumeCodeCache ||
2522+ options == CompileOptions::kEagerCompile ||
2523+ options == CompileOptions::kNoCompileOptions );
25392524
2540- i::Compiler::ScriptDetails script_details = GetScriptDetails (
2541- isolate, source->resource_name , source->resource_line_offset ,
2542- source->resource_column_offset , source->source_map_url ,
2543- source->host_defined_options );
2525+ i::Handle<i::Context> context = Utils::OpenHandle (*v8_context);
25442526
2545- i::ScriptData* script_data = nullptr ;
2546- if (options == kConsumeCodeCache ) {
2547- DCHECK (source->cached_data );
2548- // ScriptData takes care of pointer-aligning the data.
2549- script_data = new i::ScriptData (source->cached_data ->data ,
2550- source->cached_data ->length );
2527+ DCHECK (context->IsNativeContext ());
2528+
2529+ i::Handle<i::FixedArray> arguments_list =
2530+ isolate->factory ()->NewFixedArray (static_cast <int >(arguments_count));
2531+ for (int i = 0 ; i < static_cast <int >(arguments_count); i++) {
2532+ i::Handle<i::String> argument = Utils::OpenHandle (*arguments[i]);
2533+ if (!IsIdentifier (isolate, argument)) return Local<Function>();
2534+ arguments_list->set (i, *argument);
2535+ }
2536+
2537+ for (size_t i = 0 ; i < context_extension_count; ++i) {
2538+ i::Handle<i::JSReceiver> extension =
2539+ Utils::OpenHandle (*context_extensions[i]);
2540+ if (!extension->IsJSObject ()) return Local<Function>();
2541+ context = isolate->factory ()->NewWithContext (
2542+ context,
2543+ i::ScopeInfo::CreateForWithScope (
2544+ isolate,
2545+ context->IsNativeContext ()
2546+ ? i::Handle<i::ScopeInfo>::null ()
2547+ : i::Handle<i::ScopeInfo>(context->scope_info (), isolate)),
2548+ extension);
2549+ }
2550+
2551+ i::Compiler::ScriptDetails script_details = GetScriptDetails (
2552+ isolate, source->resource_name , source->resource_line_offset ,
2553+ source->resource_column_offset , source->source_map_url ,
2554+ source->host_defined_options );
2555+
2556+ i::ScriptData* script_data = nullptr ;
2557+ if (options == kConsumeCodeCache ) {
2558+ DCHECK (source->cached_data );
2559+ // ScriptData takes care of pointer-aligning the data.
2560+ script_data = new i::ScriptData (source->cached_data ->data ,
2561+ source->cached_data ->length );
2562+ }
2563+
2564+ i::Handle<i::JSFunction> scoped_result;
2565+ has_pending_exception =
2566+ !i::Compiler::GetWrappedFunction (
2567+ Utils::OpenHandle (*source->source_string ), arguments_list, context,
2568+ script_details, source->resource_options , script_data, options,
2569+ no_cache_reason)
2570+ .ToHandle (&scoped_result);
2571+ if (options == kConsumeCodeCache ) {
2572+ source->cached_data ->rejected = script_data->rejected ();
2573+ }
2574+ delete script_data;
2575+ RETURN_ON_FAILED_EXECUTION (Function);
2576+ result = handle_scope.Escape (Utils::CallableToLocal (scoped_result));
25512577 }
25522578
2553- i::Handle<i::JSFunction> result;
2554- has_pending_exception =
2555- !i::Compiler::GetWrappedFunction (
2556- Utils::OpenHandle (*source->source_string ), arguments_list, context,
2557- script_details, source->resource_options , script_data, options,
2558- no_cache_reason)
2559- .ToHandle (&result);
2560- if (options == kConsumeCodeCache ) {
2561- source->cached_data ->rejected = script_data->rejected ();
2579+ if (script_or_module_out != nullptr ) {
2580+ i::Handle<i::JSFunction> function =
2581+ i::Handle<i::JSFunction>::cast (Utils::OpenHandle (*result));
2582+ i::Isolate* isolate = function->GetIsolate ();
2583+ i::Handle<i::SharedFunctionInfo> shared (function->shared (), isolate);
2584+ i::Handle<i::Script> script (i::Script::cast (shared->script ()), isolate);
2585+ *script_or_module_out = v8::Utils::ScriptOrModuleToLocal (script);
25622586 }
2563- delete script_data;
2564- RETURN_ON_FAILED_EXECUTION (Function);
2565- RETURN_ESCAPED (Utils::CallableToLocal (result));
2587+
2588+ return result;
25662589}
25672590
25682591void ScriptCompiler::ScriptStreamingTask::Run () { data_->task ->Run (); }
0 commit comments