Skip to content

Commit 9d401f5

Browse files
committed
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.
1 parent ec44403 commit 9d401f5

File tree

4 files changed

+34
-33
lines changed

4 files changed

+34
-33
lines changed

Diff for: src/node_builtins.cc

+11-11
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,9 @@ MaybeLocal<Function> BuiltinLoader::LookupAndCompileInternal(
243243
ScriptCompiler::CachedData* cached_data = nullptr;
244244
{
245245
// Note: The lock here should not extend into the
246-
// `CompileFunctionInContext()` call below, because this function may
247-
// recurse if there is a syntax error during bootstrap (because the fatal
248-
// exception handler is invoked, which may load built-in modules).
246+
// `CompileFunction()` call below, because this function may recurse if
247+
// there is a syntax error during bootstrap (because the fatal exception
248+
// handler is invoked, which may load built-in modules).
249249
Mutex::ScopedLock lock(code_cache_mutex_);
250250
auto cache_it = code_cache_.find(id);
251251
if (cache_it != code_cache_.end()) {
@@ -267,20 +267,20 @@ MaybeLocal<Function> BuiltinLoader::LookupAndCompileInternal(
267267
has_cache ? "with" : "without");
268268

269269
MaybeLocal<Function> maybe_fun =
270-
ScriptCompiler::CompileFunctionInContext(context,
271-
&script_source,
272-
parameters->size(),
273-
parameters->data(),
274-
0,
275-
nullptr,
276-
options);
270+
ScriptCompiler::CompileFunction(context,
271+
&script_source,
272+
parameters->size(),
273+
parameters->data(),
274+
0,
275+
nullptr,
276+
options);
277277

278278
// This could fail when there are early errors in the built-in modules,
279279
// e.g. the syntax errors
280280
Local<Function> fun;
281281
if (!maybe_fun.ToLocal(&fun)) {
282282
// In the case of early errors, v8 is already capable of
283-
// decorating the stack for us - note that we use CompileFunctionInContext
283+
// decorating the stack for us - note that we use CompileFunction
284284
// so there is no need to worry about wrappers.
285285
return MaybeLocal<Function>();
286286
}

Diff for: src/node_contextify.cc

+14-13
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) {

Diff for: src/node_contextify.h

+2-2
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
};

Diff for: src/node_snapshotable.cc

+7-7
Original file line numberDiff line numberDiff line change
@@ -1329,13 +1329,13 @@ void CompileSerializeMain(const FunctionCallbackInfo<Value>& args) {
13291329
};
13301330
ScriptCompiler::Source script_source(source, origin);
13311331
Local<Function> fn;
1332-
if (ScriptCompiler::CompileFunctionInContext(context,
1333-
&script_source,
1334-
parameters.size(),
1335-
parameters.data(),
1336-
0,
1337-
nullptr,
1338-
ScriptCompiler::kEagerCompile)
1332+
if (ScriptCompiler::CompileFunction(context,
1333+
&script_source,
1334+
parameters.size(),
1335+
parameters.data(),
1336+
0,
1337+
nullptr,
1338+
ScriptCompiler::kEagerCompile)
13391339
.ToLocal(&fn)) {
13401340
args.GetReturnValue().Set(fn);
13411341
}

0 commit comments

Comments
 (0)