| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 492b7cb commit 7d411f4
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -38,7 +38,7 @@ | |||
| 38 | 38 | ||
| 39 | 39 | # Reset this number to 0 on major V8 upgrades. | |
| 40 | 40 | # Increment by one for each non-official patch applied to deps/v8. | |
| 41 | - 'v8_embedder_string': '-node.13', | ||
| 41 | + 'v8_embedder_string': '-node.14', | ||
| 42 | 42 | ||
| 43 | 43 | ##### V8 defaults for Node.js ##### | |
| 44 | 44 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1670,6 +1670,13 @@ class V8_EXPORT ScriptCompiler { | |||
| 1670 | 1670 | CompileOptions options = kNoCompileOptions, | |
| 1671 | 1671 | NoCacheReason no_cache_reason = kNoCacheNoReason); | |
| 1672 | 1672 | ||
| 1673 | + static V8_WARN_UNUSED_RESULT MaybeLocal<Function> CompileFunctionInContext( | ||
| 1674 | + Local<Context> context, Source* source, size_t arguments_count, | ||
| 1675 | + Local<String> arguments[], size_t context_extension_count, | ||
| 1676 | + Local<Object> context_extensions[], CompileOptions options, | ||
| 1677 | + NoCacheReason no_cache_reason, | ||
| 1678 | + Local<ScriptOrModule>* script_or_module_out); | ||
| 1679 | + | ||
| 1673 | 1680 | /** | |
| 1674 | 1681 | * Creates and returns code cache for the specified unbound_script. | |
| 1675 | 1682 | * This will return nullptr if the script cannot be serialized. The | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2442,69 +2442,92 @@ MaybeLocal<Function> ScriptCompiler::CompileFunctionInContext( | |||
| 2442 | 2442 | Local<String> arguments[], size_t context_extension_count, | |
| 2443 | 2443 | Local<Object> context_extensions[], CompileOptions options, | |
| 2444 | 2444 | NoCacheReason no_cache_reason) { | |
| 2445 | - PREPARE_FOR_EXECUTION(v8_context, ScriptCompiler, CompileFunctionInContext, | ||
| 2446 | - Function); | ||
| 2447 | - TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.ScriptCompiler"); | ||
| 2445 | + return ScriptCompiler::CompileFunctionInContext( | ||
| 2446 | + v8_context, source, arguments_count, arguments, context_extension_count, | ||
| 2447 | + context_extensions, options, no_cache_reason, nullptr); | ||
| 2448 | + } | ||
| 2448 | 2449 | ||
| 2449 | - DCHECK(options == CompileOptions::kConsumeCodeCache || | ||
| 2450 | - options == CompileOptions::kEagerCompile || | ||
| 2451 | - options == CompileOptions::kNoCompileOptions); | ||
| 2450 | + MaybeLocal<Function> ScriptCompiler::CompileFunctionInContext( | ||
| 2451 | + Local<Context> v8_context, Source* source, size_t arguments_count, | ||
| 2452 | + Local<String> arguments[], size_t context_extension_count, | ||
| 2453 | + Local<Object> context_extensions[], CompileOptions options, | ||
| 2454 | + NoCacheReason no_cache_reason, | ||
| 2455 | + Local<ScriptOrModule>* script_or_module_out) { | ||
| 2456 | + Local<Function> result; | ||
| 2452 | 2457 | ||
| 2453 | - i::Handle<i::Context> context = Utils::OpenHandle(*v8_context); | ||
| 2458 | + { | ||
| 2459 | + PREPARE_FOR_EXECUTION(v8_context, ScriptCompiler, CompileFunctionInContext, | ||
| 2460 | + Function); | ||
| 2461 | + TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.ScriptCompiler"); | ||
| 2454 | 2462 | ||
| 2455 | - DCHECK(context->IsNativeContext()); | ||
| 2456 | - i::Handle<i::SharedFunctionInfo> outer_info( | ||
| 2457 | - context->empty_function().shared(), isolate); | ||
| 2458 | - | ||
| 2459 | - i::Handle<i::JSFunction> fun; | ||
| 2460 | - i::Handle<i::FixedArray> arguments_list = | ||
| 2461 | - isolate->factory()->NewFixedArray(static_cast<int>(arguments_count)); | ||
| 2462 | - for (int i = 0; i < static_cast<int>(arguments_count); i++) { | ||
| 2463 | - i::Handle<i::String> argument = Utils::OpenHandle(*arguments[i]); | ||
| 2464 | - if (!IsIdentifier(isolate, argument)) return Local<Function>(); | ||
| 2465 | - arguments_list->set(i, *argument); | ||
| 2466 | - } | ||
| 2467 | - | ||
| 2468 | - for (size_t i = 0; i < context_extension_count; ++i) { | ||
| 2469 | - i::Handle<i::JSReceiver> extension = | ||
| 2470 | - Utils::OpenHandle(*context_extensions[i]); | ||
| 2471 | - if (!extension->IsJSObject()) return Local<Function>(); | ||
| 2472 | - context = isolate->factory()->NewWithContext( | ||
| 2473 | - context, | ||
| 2474 | - i::ScopeInfo::CreateForWithScope( | ||
| 2475 | - isolate, | ||
| 2476 | - context->IsNativeContext() | ||
| 2477 | - ? i::Handle<i::ScopeInfo>::null() | ||
| 2478 | - : i::Handle<i::ScopeInfo>(context->scope_info(), isolate)), | ||
| 2479 | - extension); | ||
| 2480 | - } | ||
| 2463 | + DCHECK(options == CompileOptions::kConsumeCodeCache || | ||
| 2464 | + options == CompileOptions::kEagerCompile || | ||
| 2465 | + options == CompileOptions::kNoCompileOptions); | ||
| 2481 | 2466 | ||
| 2482 | - i::Compiler::ScriptDetails script_details = GetScriptDetails( | ||
| 2483 | - isolate, source->resource_name, source->resource_line_offset, | ||
| 2484 | - source->resource_column_offset, source->source_map_url, | ||
| 2485 | - source->host_defined_options); | ||
| 2467 | + i::Handle<i::Context> context = Utils::OpenHandle(*v8_context); | ||
| 2486 | 2468 | ||
| 2487 | - i::ScriptData* script_data = nullptr; | ||
| 2488 | - if (options == kConsumeCodeCache) { | ||
| 2489 | - DCHECK(source->cached_data); | ||
| 2490 | - // ScriptData takes care of pointer-aligning the data. | ||
| 2491 | - script_data = new i::ScriptData(source->cached_data->data, | ||
| 2492 | - source->cached_data->length); | ||
| 2469 | + DCHECK(context->IsNativeContext()); | ||
| 2470 | + | ||
| 2471 | + i::Handle<i::FixedArray> arguments_list = | ||
| 2472 | + isolate->factory()->NewFixedArray(static_cast<int>(arguments_count)); | ||
| 2473 | + for (int i = 0; i < static_cast<int>(arguments_count); i++) { | ||
| 2474 | + i::Handle<i::String> argument = Utils::OpenHandle(*arguments[i]); | ||
| 2475 | + if (!IsIdentifier(isolate, argument)) return Local<Function>(); | ||
| 2476 | + arguments_list->set(i, *argument); | ||
| 2477 | + } | ||
| 2478 | + | ||
| 2479 | + for (size_t i = 0; i < context_extension_count; ++i) { | ||
| 2480 | + i::Handle<i::JSReceiver> extension = | ||
| 2481 | + Utils::OpenHandle(*context_extensions[i]); | ||
| 2482 | + if (!extension->IsJSObject()) return Local<Function>(); | ||
| 2483 | + context = isolate->factory()->NewWithContext( | ||
| 2484 | + context, | ||
| 2485 | + i::ScopeInfo::CreateForWithScope( | ||
| 2486 | + isolate, | ||
| 2487 | + context->IsNativeContext() | ||
| 2488 | + ? i::Handle<i::ScopeInfo>::null() | ||
| 2489 | + : i::Handle<i::ScopeInfo>(context->scope_info(), isolate)), | ||
| 2490 | + extension); | ||
| 2491 | + } | ||
| 2492 | + | ||
| 2493 | + i::Compiler::ScriptDetails script_details = GetScriptDetails( | ||
| 2494 | + isolate, source->resource_name, source->resource_line_offset, | ||
| 2495 | + source->resource_column_offset, source->source_map_url, | ||
| 2496 | + source->host_defined_options); | ||
| 2497 | + | ||
| 2498 | + i::ScriptData* script_data = nullptr; | ||
| 2499 | + if (options == kConsumeCodeCache) { | ||
| 2500 | + DCHECK(source->cached_data); | ||
| 2501 | + // ScriptData takes care of pointer-aligning the data. | ||
| 2502 | + script_data = new i::ScriptData(source->cached_data->data, | ||
| 2503 | + source->cached_data->length); | ||
| 2504 | + } | ||
| 2505 | + | ||
| 2506 | + i::Handle<i::JSFunction> scoped_result; | ||
| 2507 | + has_pending_exception = | ||
| 2508 | + !i::Compiler::GetWrappedFunction( | ||
| 2509 | + Utils::OpenHandle(*source->source_string), arguments_list, context, | ||
| 2510 | + script_details, source->resource_options, script_data, options, | ||
| 2511 | + no_cache_reason) | ||
| 2512 | + .ToHandle(&scoped_result); | ||
| 2513 | + if (options == kConsumeCodeCache) { | ||
| 2514 | + source->cached_data->rejected = script_data->rejected(); | ||
| 2515 | + } | ||
| 2516 | + delete script_data; | ||
| 2517 | + RETURN_ON_FAILED_EXECUTION(Function); | ||
| 2518 | + result = handle_scope.Escape(Utils::CallableToLocal(scoped_result)); | ||
| 2493 | 2519 | } | |
| 2494 | 2520 | ||
| 2495 | - i::Handle<i::JSFunction> result; | ||
| 2496 | - has_pending_exception = | ||
| 2497 | - !i::Compiler::GetWrappedFunction( | ||
| 2498 | - Utils::OpenHandle(*source->source_string), arguments_list, context, | ||
| 2499 | - script_details, source->resource_options, script_data, options, | ||
| 2500 | - no_cache_reason) | ||
| 2501 | - .ToHandle(&result); | ||
| 2502 | - if (options == kConsumeCodeCache) { | ||
| 2503 | - source->cached_data->rejected = script_data->rejected(); | ||
| 2521 | + if (script_or_module_out != nullptr) { | ||
| 2522 | + i::Handle<i::JSFunction> function = | ||
| 2523 | + i::Handle<i::JSFunction>::cast(Utils::OpenHandle(*result)); | ||
| 2524 | + i::Isolate* isolate = function->GetIsolate(); | ||
| 2525 | + i::Handle<i::SharedFunctionInfo> shared(function->shared(), isolate); | ||
| 2526 | + i::Handle<i::Script> script(i::Script::cast(shared->script()), isolate); | ||
| 2527 | + *script_or_module_out = v8::Utils::ScriptOrModuleToLocal(script); | ||
| 2504 | 2528 | } | |
| 2505 | - delete script_data; | ||
| 2506 | - RETURN_ON_FAILED_EXECUTION(Function); | ||
| 2507 | - RETURN_ESCAPED(Utils::CallableToLocal(result)); | ||
| 2529 | + | ||
| 2530 | + return result; | ||
| 2508 | 2531 | } | |
| 2509 | 2532 | ||
| 2510 | 2533 | void ScriptCompiler::ScriptStreamingTask::Run() { data_->task->Run(); } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -650,11 +650,16 @@ TEST(CompileFunctionInContextScriptOrigin) { | |||
| 650 | 650 | v8::Integer::New(CcTest::isolate(), 22), | |
| 651 | 651 | v8::Integer::New(CcTest::isolate(), 41)); | |
| 652 | 652 | v8::ScriptCompiler::Source script_source(v8_str("throw new Error()"), origin); | |
| 653 | + Local<ScriptOrModule> script; | ||
| 653 | 654 | v8::Local<v8::Function> fun = | |
| 654 | - v8::ScriptCompiler::CompileFunctionInContext(env.local(), &script_source, | ||
| 655 | - 0, nullptr, 0, nullptr) | ||
| 655 | + v8::ScriptCompiler::CompileFunctionInContext( | ||
| 656 | + env.local(), &script_source, 0, nullptr, 0, nullptr, | ||
| 657 | + v8::ScriptCompiler::CompileOptions::kNoCompileOptions, | ||
| 658 | + v8::ScriptCompiler::NoCacheReason::kNoCacheNoReason, &script) | ||
| 656 | 659 | .ToLocalChecked(); | |
| 657 | 660 | CHECK(!fun.IsEmpty()); | |
| 661 | + CHECK(!script.IsEmpty()); | ||
| 662 | + CHECK(script->GetResourceName()->StrictEquals(v8_str("test"))); | ||
| 658 | 663 | v8::TryCatch try_catch(CcTest::isolate()); | |
| 659 | 664 | CcTest::isolate()->SetCaptureStackTraceForUncaughtExceptions(true); | |
| 660 | 665 | CHECK(fun->Call(env.local(), env->Global(), 0, nullptr).IsEmpty()); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments