Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9614907

Browse filesBrowse files
legendecasruyadorno
authored andcommitted
src: remove usage on ScriptCompiler::CompileFunctionInContext
V8 APIs like HostImportModuleDynamicallyCallback and ScriptCompiler::CompileFunction is moving away from ScriptOrModule. Replaces ScriptCompiler::CompileFunctionInContext with ScriptCompiler::CompileFunction to remove the usages on the optional out param ScriptOrModule. PR-URL: #44198 Fixes: nodejs/node-v8#214 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent f5e2f6c commit 9614907
Copy full SHA for 9614907

File tree

Expand file treeCollapse file tree

4 files changed

+34
-33
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+34
-33
lines changed
Open diff view settings
Collapse file

‎src/node_contextify.cc‎

Copy file name to clipboardExpand all lines: src/node_contextify.cc
+14-13Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ using v8::PropertyHandlerFlags;
7070
using v8::Script;
7171
using v8::ScriptCompiler;
7272
using v8::ScriptOrigin;
73-
using v8::ScriptOrModule;
7473
using v8::String;
7574
using v8::Uint32;
7675
using v8::UnboundScript;
@@ -1130,11 +1129,15 @@ void ContextifyContext::CompileFunction(
11301129
}
11311130
}
11321131

1133-
Local<ScriptOrModule> script;
1134-
MaybeLocal<Function> maybe_fn = ScriptCompiler::CompileFunctionInContext(
1135-
parsing_context, &source, params.size(), params.data(),
1136-
context_extensions.size(), context_extensions.data(), options,
1137-
v8::ScriptCompiler::NoCacheReason::kNoCacheNoReason, &script);
1132+
MaybeLocal<Function> maybe_fn = ScriptCompiler::CompileFunction(
1133+
parsing_context,
1134+
&source,
1135+
params.size(),
1136+
params.data(),
1137+
context_extensions.size(),
1138+
context_extensions.data(),
1139+
options,
1140+
v8::ScriptCompiler::NoCacheReason::kNoCacheNoReason);
11381141

11391142
Local<Function> fn;
11401143
if (!maybe_fn.ToLocal(&fn)) {
@@ -1150,7 +1153,7 @@ void ContextifyContext::CompileFunction(
11501153
context).ToLocal(&cache_key)) {
11511154
return;
11521155
}
1153-
CompiledFnEntry* entry = new CompiledFnEntry(env, cache_key, id, script);
1156+
CompiledFnEntry* entry = new CompiledFnEntry(env, cache_key, id, fn);
11541157
env->id_to_function_map.emplace(id, entry);
11551158

11561159
Local<Object> result = Object::New(isolate);
@@ -1196,16 +1199,14 @@ void CompiledFnEntry::WeakCallback(
11961199
CompiledFnEntry::CompiledFnEntry(Environment* env,
11971200
Local<Object> object,
11981201
uint32_t id,
1199-
Local<ScriptOrModule> script)
1200-
: BaseObject(env, object),
1201-
id_(id),
1202-
script_(env->isolate(), script) {
1203-
script_.SetWeak(this, WeakCallback, v8::WeakCallbackType::kParameter);
1202+
Local<Function> fn)
1203+
: BaseObject(env, object), id_(id), fn_(env->isolate(), fn) {
1204+
fn_.SetWeak(this, WeakCallback, v8::WeakCallbackType::kParameter);
12041205
}
12051206

12061207
CompiledFnEntry::~CompiledFnEntry() {
12071208
env()->id_to_function_map.erase(id_);
1208-
script_.ClearWeak();
1209+
fn_.ClearWeak();
12091210
}
12101211

12111212
static void StartSigintWatchdog(const FunctionCallbackInfo<Value>& args) {
Collapse file

‎src/node_contextify.h‎

Copy file name to clipboardExpand all lines: src/node_contextify.h
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,14 @@ class CompiledFnEntry final : public BaseObject {
174174
CompiledFnEntry(Environment* env,
175175
v8::Local<v8::Object> object,
176176
uint32_t id,
177-
v8::Local<v8::ScriptOrModule> script);
177+
v8::Local<v8::Function> fn);
178178
~CompiledFnEntry();
179179

180180
bool IsNotIndicativeOfMemoryLeakAtExit() const override { return true; }
181181

182182
private:
183183
uint32_t id_;
184-
v8::Global<v8::ScriptOrModule> script_;
184+
v8::Global<v8::Function> fn_;
185185

186186
static void WeakCallback(const v8::WeakCallbackInfo<CompiledFnEntry>& data);
187187
};
Collapse file

‎src/node_native_module.cc‎

Copy file name to clipboardExpand all lines: src/node_native_module.cc
+11-11Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,9 @@ MaybeLocal<Function> NativeModuleLoader::LookupAndCompileInternal(
256256
ScriptCompiler::CachedData* cached_data = nullptr;
257257
{
258258
// Note: The lock here should not extend into the
259-
// `CompileFunctionInContext()` call below, because this function may
260-
// recurse if there is a syntax error during bootstrap (because the fatal
261-
// exception handler is invoked, which may load built-in modules).
259+
// `CompileFunction()` call below, because this function may recurse if
260+
// there is a syntax error during bootstrap (because the fatal exception
261+
// handler is invoked, which may load built-in modules).
262262
Mutex::ScopedLock lock(code_cache_mutex_);
263263
auto cache_it = code_cache_.find(id);
264264
if (cache_it != code_cache_.end()) {
@@ -280,20 +280,20 @@ MaybeLocal<Function> NativeModuleLoader::LookupAndCompileInternal(
280280
has_cache ? "with" : "without");
281281

282282
MaybeLocal<Function> maybe_fun =
283-
ScriptCompiler::CompileFunctionInContext(context,
284-
&script_source,
285-
parameters->size(),
286-
parameters->data(),
287-
0,
288-
nullptr,
289-
options);
283+
ScriptCompiler::CompileFunction(context,
284+
&script_source,
285+
parameters->size(),
286+
parameters->data(),
287+
0,
288+
nullptr,
289+
options);
290290

291291
// This could fail when there are early errors in the native modules,
292292
// e.g. the syntax errors
293293
Local<Function> fun;
294294
if (!maybe_fun.ToLocal(&fun)) {
295295
// In the case of early errors, v8 is already capable of
296-
// decorating the stack for us - note that we use CompileFunctionInContext
296+
// decorating the stack for us - note that we use CompileFunction
297297
// so there is no need to worry about wrappers.
298298
return MaybeLocal<Function>();
299299
}
Collapse file

‎src/node_snapshotable.cc‎

Copy file name to clipboardExpand all lines: src/node_snapshotable.cc
+7-7Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -484,13 +484,13 @@ void CompileSerializeMain(const FunctionCallbackInfo<Value>& args) {
484484
};
485485
ScriptCompiler::Source script_source(source, origin);
486486
Local<Function> fn;
487-
if (ScriptCompiler::CompileFunctionInContext(context,
488-
&script_source,
489-
parameters.size(),
490-
parameters.data(),
491-
0,
492-
nullptr,
493-
ScriptCompiler::kEagerCompile)
487+
if (ScriptCompiler::CompileFunction(context,
488+
&script_source,
489+
parameters.size(),
490+
parameters.data(),
491+
0,
492+
nullptr,
493+
ScriptCompiler::kEagerCompile)
494494
.ToLocal(&fn)) {
495495
args.GetReturnValue().Set(fn);
496496
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.