@@ -2499,70 +2499,83 @@ MaybeLocal<Function> ScriptCompiler::CompileFunctionInContext(
24992499 Local<Context> v8_context, Source* source, size_t arguments_count,
25002500 Local<String> arguments[], size_t context_extension_count,
25012501 Local<Object> context_extensions[], CompileOptions options,
2502- NoCacheReason no_cache_reason) {
2503- PREPARE_FOR_EXECUTION (v8_context, ScriptCompiler, CompileFunctionInContext,
2504- Function);
2505- TRACE_EVENT_CALL_STATS_SCOPED (isolate, " v8" , " V8.ScriptCompiler" );
2502+ NoCacheReason no_cache_reason,
2503+ Local<ScriptOrModule>* script_or_module_out) {
2504+ Local<Function> result;
25062505
2507- DCHECK (options == CompileOptions::kConsumeCodeCache ||
2508- options == CompileOptions::kEagerCompile ||
2509- options == CompileOptions::kNoCompileOptions );
2506+ {
2507+ PREPARE_FOR_EXECUTION (v8_context, ScriptCompiler, CompileFunctionInContext,
2508+ Function);
2509+ TRACE_EVENT_CALL_STATS_SCOPED (isolate, " v8" , " V8.ScriptCompiler" );
25102510
2511- i::Handle<i::Context> context = Utils::OpenHandle (*v8_context);
2511+ DCHECK (options == CompileOptions::kConsumeCodeCache ||
2512+ options == CompileOptions::kEagerCompile ||
2513+ options == CompileOptions::kNoCompileOptions );
25122514
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- }
2515+ i::Handle<i::Context> context = Utils::OpenHandle (*v8_context);
25392516
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 );
2517+ DCHECK (context->IsNativeContext ());
25442518
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 );
2519+ i::Handle<i::FixedArray> arguments_list =
2520+ isolate->factory ()->NewFixedArray (static_cast <int >(arguments_count));
2521+ for (int i = 0 ; i < static_cast <int >(arguments_count); i++) {
2522+ i::Handle<i::String> argument = Utils::OpenHandle (*arguments[i]);
2523+ if (!IsIdentifier (isolate, argument)) return Local<Function>();
2524+ arguments_list->set (i, *argument);
2525+ }
2526+
2527+ for (size_t i = 0 ; i < context_extension_count; ++i) {
2528+ i::Handle<i::JSReceiver> extension =
2529+ Utils::OpenHandle (*context_extensions[i]);
2530+ if (!extension->IsJSObject ()) return Local<Function>();
2531+ context = isolate->factory ()->NewWithContext (
2532+ context,
2533+ i::ScopeInfo::CreateForWithScope (
2534+ isolate,
2535+ context->IsNativeContext ()
2536+ ? i::Handle<i::ScopeInfo>::null ()
2537+ : i::Handle<i::ScopeInfo>(context->scope_info (), isolate)),
2538+ extension);
2539+ }
2540+
2541+ i::Compiler::ScriptDetails script_details = GetScriptDetails (
2542+ isolate, source->resource_name , source->resource_line_offset ,
2543+ source->resource_column_offset , source->source_map_url ,
2544+ source->host_defined_options );
2545+
2546+ i::ScriptData* script_data = nullptr ;
2547+ if (options == kConsumeCodeCache ) {
2548+ DCHECK (source->cached_data );
2549+ // ScriptData takes care of pointer-aligning the data.
2550+ script_data = new i::ScriptData (source->cached_data ->data ,
2551+ source->cached_data ->length );
2552+ }
2553+
2554+ i::Handle<i::JSFunction> scoped_result;
2555+ has_pending_exception =
2556+ !i::Compiler::GetWrappedFunction (
2557+ Utils::OpenHandle (*source->source_string ), arguments_list, context,
2558+ script_details, source->resource_options , script_data, options,
2559+ no_cache_reason)
2560+ .ToHandle (&scoped_result);
2561+ if (options == kConsumeCodeCache ) {
2562+ source->cached_data ->rejected = script_data->rejected ();
2563+ }
2564+ delete script_data;
2565+ RETURN_ON_FAILED_EXECUTION (Function);
2566+ result = handle_scope.Escape (Utils::CallableToLocal (scoped_result));
25512567 }
25522568
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 ();
2569+ if (script_or_module_out != nullptr ) {
2570+ i::Handle<i::JSFunction> function =
2571+ i::Handle<i::JSFunction>::cast (Utils::OpenHandle (*result));
2572+ i::Isolate* isolate = function->GetIsolate ();
2573+ i::Handle<i::SharedFunctionInfo> shared (function->shared (), isolate);
2574+ i::Handle<i::Script> script (i::Script::cast (shared->script ()), isolate);
2575+ *script_or_module_out = v8::Utils::ScriptOrModuleToLocal (script);
25622576 }
2563- delete script_data;
2564- RETURN_ON_FAILED_EXECUTION (Function);
2565- RETURN_ESCAPED (Utils::CallableToLocal (result));
2577+
2578+ return result;
25662579}
25672580
25682581void ScriptCompiler::ScriptStreamingTask::Run () { data_->task ->Run (); }
0 commit comments