diff --git a/common.gypi b/common.gypi index 570a7f6d101144..ca0a986bc4f8f4 100644 --- a/common.gypi +++ b/common.gypi @@ -38,7 +38,7 @@ # Reset this number to 0 on major V8 upgrades. # Increment by one for each non-official patch applied to deps/v8. - 'v8_embedder_string': '-node.13', + 'v8_embedder_string': '-node.14', ##### V8 defaults for Node.js ##### diff --git a/deps/v8/include/v8.h b/deps/v8/include/v8.h index 09da82fd61ed40..bfd049d1fbbd9e 100644 --- a/deps/v8/include/v8.h +++ b/deps/v8/include/v8.h @@ -1670,6 +1670,13 @@ class V8_EXPORT ScriptCompiler { CompileOptions options = kNoCompileOptions, NoCacheReason no_cache_reason = kNoCacheNoReason); + static V8_WARN_UNUSED_RESULT MaybeLocal CompileFunctionInContext( + Local context, Source* source, size_t arguments_count, + Local arguments[], size_t context_extension_count, + Local context_extensions[], CompileOptions options, + NoCacheReason no_cache_reason, + Local* script_or_module_out); + /** * Creates and returns code cache for the specified unbound_script. * This will return nullptr if the script cannot be serialized. The diff --git a/deps/v8/src/api/api.cc b/deps/v8/src/api/api.cc index 399aca7eb61dff..80592ca0ba4fde 100644 --- a/deps/v8/src/api/api.cc +++ b/deps/v8/src/api/api.cc @@ -2442,69 +2442,92 @@ MaybeLocal ScriptCompiler::CompileFunctionInContext( Local arguments[], size_t context_extension_count, Local context_extensions[], CompileOptions options, NoCacheReason no_cache_reason) { - PREPARE_FOR_EXECUTION(v8_context, ScriptCompiler, CompileFunctionInContext, - Function); - TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.ScriptCompiler"); + return ScriptCompiler::CompileFunctionInContext( + v8_context, source, arguments_count, arguments, context_extension_count, + context_extensions, options, no_cache_reason, nullptr); +} - DCHECK(options == CompileOptions::kConsumeCodeCache || - options == CompileOptions::kEagerCompile || - options == CompileOptions::kNoCompileOptions); +MaybeLocal ScriptCompiler::CompileFunctionInContext( + Local v8_context, Source* source, size_t arguments_count, + Local arguments[], size_t context_extension_count, + Local context_extensions[], CompileOptions options, + NoCacheReason no_cache_reason, + Local* script_or_module_out) { + Local result; - i::Handle context = Utils::OpenHandle(*v8_context); + { + PREPARE_FOR_EXECUTION(v8_context, ScriptCompiler, CompileFunctionInContext, + Function); + TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.ScriptCompiler"); - DCHECK(context->IsNativeContext()); - i::Handle outer_info( - context->empty_function().shared(), isolate); - - i::Handle fun; - i::Handle arguments_list = - isolate->factory()->NewFixedArray(static_cast(arguments_count)); - for (int i = 0; i < static_cast(arguments_count); i++) { - i::Handle argument = Utils::OpenHandle(*arguments[i]); - if (!IsIdentifier(isolate, argument)) return Local(); - arguments_list->set(i, *argument); - } - - for (size_t i = 0; i < context_extension_count; ++i) { - i::Handle extension = - Utils::OpenHandle(*context_extensions[i]); - if (!extension->IsJSObject()) return Local(); - context = isolate->factory()->NewWithContext( - context, - i::ScopeInfo::CreateForWithScope( - isolate, - context->IsNativeContext() - ? i::Handle::null() - : i::Handle(context->scope_info(), isolate)), - extension); - } + DCHECK(options == CompileOptions::kConsumeCodeCache || + options == CompileOptions::kEagerCompile || + options == CompileOptions::kNoCompileOptions); - i::Compiler::ScriptDetails script_details = GetScriptDetails( - isolate, source->resource_name, source->resource_line_offset, - source->resource_column_offset, source->source_map_url, - source->host_defined_options); + i::Handle context = Utils::OpenHandle(*v8_context); - i::ScriptData* script_data = nullptr; - if (options == kConsumeCodeCache) { - DCHECK(source->cached_data); - // ScriptData takes care of pointer-aligning the data. - script_data = new i::ScriptData(source->cached_data->data, - source->cached_data->length); + DCHECK(context->IsNativeContext()); + + i::Handle arguments_list = + isolate->factory()->NewFixedArray(static_cast(arguments_count)); + for (int i = 0; i < static_cast(arguments_count); i++) { + i::Handle argument = Utils::OpenHandle(*arguments[i]); + if (!IsIdentifier(isolate, argument)) return Local(); + arguments_list->set(i, *argument); + } + + for (size_t i = 0; i < context_extension_count; ++i) { + i::Handle extension = + Utils::OpenHandle(*context_extensions[i]); + if (!extension->IsJSObject()) return Local(); + context = isolate->factory()->NewWithContext( + context, + i::ScopeInfo::CreateForWithScope( + isolate, + context->IsNativeContext() + ? i::Handle::null() + : i::Handle(context->scope_info(), isolate)), + extension); + } + + i::Compiler::ScriptDetails script_details = GetScriptDetails( + isolate, source->resource_name, source->resource_line_offset, + source->resource_column_offset, source->source_map_url, + source->host_defined_options); + + i::ScriptData* script_data = nullptr; + if (options == kConsumeCodeCache) { + DCHECK(source->cached_data); + // ScriptData takes care of pointer-aligning the data. + script_data = new i::ScriptData(source->cached_data->data, + source->cached_data->length); + } + + i::Handle scoped_result; + has_pending_exception = + !i::Compiler::GetWrappedFunction( + Utils::OpenHandle(*source->source_string), arguments_list, context, + script_details, source->resource_options, script_data, options, + no_cache_reason) + .ToHandle(&scoped_result); + if (options == kConsumeCodeCache) { + source->cached_data->rejected = script_data->rejected(); + } + delete script_data; + RETURN_ON_FAILED_EXECUTION(Function); + result = handle_scope.Escape(Utils::CallableToLocal(scoped_result)); } - i::Handle result; - has_pending_exception = - !i::Compiler::GetWrappedFunction( - Utils::OpenHandle(*source->source_string), arguments_list, context, - script_details, source->resource_options, script_data, options, - no_cache_reason) - .ToHandle(&result); - if (options == kConsumeCodeCache) { - source->cached_data->rejected = script_data->rejected(); + if (script_or_module_out != nullptr) { + i::Handle function = + i::Handle::cast(Utils::OpenHandle(*result)); + i::Isolate* isolate = function->GetIsolate(); + i::Handle shared(function->shared(), isolate); + i::Handle script(i::Script::cast(shared->script()), isolate); + *script_or_module_out = v8::Utils::ScriptOrModuleToLocal(script); } - delete script_data; - RETURN_ON_FAILED_EXECUTION(Function); - RETURN_ESCAPED(Utils::CallableToLocal(result)); + + return result; } void ScriptCompiler::ScriptStreamingTask::Run() { data_->task->Run(); } diff --git a/deps/v8/test/cctest/test-compiler.cc b/deps/v8/test/cctest/test-compiler.cc index 28867a89efa809..660ee98a9a110c 100644 --- a/deps/v8/test/cctest/test-compiler.cc +++ b/deps/v8/test/cctest/test-compiler.cc @@ -650,11 +650,16 @@ TEST(CompileFunctionInContextScriptOrigin) { v8::Integer::New(CcTest::isolate(), 22), v8::Integer::New(CcTest::isolate(), 41)); v8::ScriptCompiler::Source script_source(v8_str("throw new Error()"), origin); + Local script; v8::Local fun = - v8::ScriptCompiler::CompileFunctionInContext(env.local(), &script_source, - 0, nullptr, 0, nullptr) + v8::ScriptCompiler::CompileFunctionInContext( + env.local(), &script_source, 0, nullptr, 0, nullptr, + v8::ScriptCompiler::CompileOptions::kNoCompileOptions, + v8::ScriptCompiler::NoCacheReason::kNoCacheNoReason, &script) .ToLocalChecked(); CHECK(!fun.IsEmpty()); + CHECK(!script.IsEmpty()); + CHECK(script->GetResourceName()->StrictEquals(v8_str("test"))); v8::TryCatch try_catch(CcTest::isolate()); CcTest::isolate()->SetCaptureStackTraceForUncaughtExceptions(true); CHECK(fun->Call(env.local(), env->Global(), 0, nullptr).IsEmpty());