summaryrefslogtreecommitdiff
path: root/deps/v8/src/api.cc
diff options
context:
space:
mode:
authorGus Caplan <me@gus.host>2019-07-19 09:22:56 -0500
committerGus Caplan <me@gus.host>2019-07-19 16:45:45 -0500
commitb7bcfc9d7e0083a2f8aedd4010853140163eefc5 (patch)
tree8e1c35a3cfe5a4080600e8b3c72dcdccab72e98c /deps/v8/src/api.cc
parent15d44bf6f0cf0cd390009c7c547a5113c7bcb7d0 (diff)
downloadandroid-node-v8-b7bcfc9d7e0083a2f8aedd4010853140163eefc5.tar.gz
android-node-v8-b7bcfc9d7e0083a2f8aedd4010853140163eefc5.tar.bz2
android-node-v8-b7bcfc9d7e0083a2f8aedd4010853140163eefc5.zip
deps: V8: backport b33af60
Original commit message: [api] Get ScriptOrModule from CompileFunctionInContext Adds a new out param which allows accessing the ScriptOrModule of a function, which allows an embedder such as Node.js to use the function's i::Script lifetime. Refs: https://github.com/nodejs/node-v8/issues/111 Change-Id: I34346d94d76e8f9b8377c97d948673f4b95eb9d5 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1699698 Reviewed-by: Yang Guo <yangguo@chromium.org> Commit-Queue: Yang Guo <yangguo@chromium.org> Cr-Commit-Position: refs/heads/master@{#62830} Refs: https://github.com/v8/v8/commit/b33af60dd9e7e5b2557b9fbf3fdb80209f6db844 PR-URL: https://github.com/nodejs/node/pull/28671 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Guy Bedford <guybedford@gmail.com>
Diffstat (limited to 'deps/v8/src/api.cc')
-rw-r--r--deps/v8/src/api.cc125
1 files changed, 69 insertions, 56 deletions
diff --git a/deps/v8/src/api.cc b/deps/v8/src/api.cc
index 98f75217cf..dc92ff2e79 100644
--- a/deps/v8/src/api.cc
+++ b/deps/v8/src/api.cc
@@ -2499,70 +2499,83 @@ MaybeLocal<Function> ScriptCompiler::CompileFunctionInContext(
Local<Context> v8_context, Source* source, size_t arguments_count,
Local<String> arguments[], size_t context_extension_count,
Local<Object> 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");
+ NoCacheReason no_cache_reason,
+ Local<ScriptOrModule>* script_or_module_out) {
+ Local<Function> result;
- DCHECK(options == CompileOptions::kConsumeCodeCache ||
- options == CompileOptions::kEagerCompile ||
- options == CompileOptions::kNoCompileOptions);
+ {
+ PREPARE_FOR_EXECUTION(v8_context, ScriptCompiler, CompileFunctionInContext,
+ Function);
+ TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.ScriptCompiler");
- i::Handle<i::Context> context = Utils::OpenHandle(*v8_context);
+ DCHECK(options == CompileOptions::kConsumeCodeCache ||
+ options == CompileOptions::kEagerCompile ||
+ options == CompileOptions::kNoCompileOptions);
- DCHECK(context->IsNativeContext());
- i::Handle<i::SharedFunctionInfo> outer_info(
- context->empty_function()->shared(), isolate);
-
- i::Handle<i::JSFunction> fun;
- i::Handle<i::FixedArray> arguments_list =
- isolate->factory()->NewFixedArray(static_cast<int>(arguments_count));
- for (int i = 0; i < static_cast<int>(arguments_count); i++) {
- i::Handle<i::String> argument = Utils::OpenHandle(*arguments[i]);
- if (!IsIdentifier(isolate, argument)) return Local<Function>();
- arguments_list->set(i, *argument);
- }
-
- for (size_t i = 0; i < context_extension_count; ++i) {
- i::Handle<i::JSReceiver> extension =
- Utils::OpenHandle(*context_extensions[i]);
- if (!extension->IsJSObject()) return Local<Function>();
- context = isolate->factory()->NewWithContext(
- context,
- i::ScopeInfo::CreateForWithScope(
- isolate,
- context->IsNativeContext()
- ? i::Handle<i::ScopeInfo>::null()
- : i::Handle<i::ScopeInfo>(context->scope_info(), isolate)),
- extension);
- }
+ i::Handle<i::Context> context = Utils::OpenHandle(*v8_context);
- 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);
+ DCHECK(context->IsNativeContext());
- 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<i::FixedArray> arguments_list =
+ isolate->factory()->NewFixedArray(static_cast<int>(arguments_count));
+ for (int i = 0; i < static_cast<int>(arguments_count); i++) {
+ i::Handle<i::String> argument = Utils::OpenHandle(*arguments[i]);
+ if (!IsIdentifier(isolate, argument)) return Local<Function>();
+ arguments_list->set(i, *argument);
+ }
+
+ for (size_t i = 0; i < context_extension_count; ++i) {
+ i::Handle<i::JSReceiver> extension =
+ Utils::OpenHandle(*context_extensions[i]);
+ if (!extension->IsJSObject()) return Local<Function>();
+ context = isolate->factory()->NewWithContext(
+ context,
+ i::ScopeInfo::CreateForWithScope(
+ isolate,
+ context->IsNativeContext()
+ ? i::Handle<i::ScopeInfo>::null()
+ : i::Handle<i::ScopeInfo>(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<i::JSFunction> 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<i::JSFunction> 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<i::JSFunction> function =
+ i::Handle<i::JSFunction>::cast(Utils::OpenHandle(*result));
+ i::Isolate* isolate = function->GetIsolate();
+ i::Handle<i::SharedFunctionInfo> shared(function->shared(), isolate);
+ i::Handle<i::Script> 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(); }