Skip to content

Commit ceb62e5

Browse files
legendecasdanielleadams
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 a82e768 commit ceb62e5

File tree

4 files changed

+34
-33
lines changed

4 files changed

+34
-33
lines changed

src/node_builtins.cc

Lines changed: 11 additions & 11 deletions
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
}

src/node_contextify.cc

Lines 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;
@@ -1126,11 +1125,15 @@ void ContextifyContext::CompileFunction(
11261125
}
11271126
}
11281127

1129-
Local<ScriptOrModule> script;
1130-
MaybeLocal<Function> maybe_fn = ScriptCompiler::CompileFunctionInContext(
1131-
parsing_context, &source, params.size(), params.data(),
1132-
context_extensions.size(), context_extensions.data(), options,
1133-
v8::ScriptCompiler::NoCacheReason::kNoCacheNoReason, &script);
1128+
MaybeLocal<Function> maybe_fn = ScriptCompiler::CompileFunction(
1129+
parsing_context,
1130+
&source,
1131+
params.size(),
1132+
params.data(),
1133+
context_extensions.size(),
1134+
context_extensions.data(),
1135+
options,
1136+
v8::ScriptCompiler::NoCacheReason::kNoCacheNoReason);
11341137

11351138
Local<Function> fn;
11361139
if (!maybe_fn.ToLocal(&fn)) {
@@ -1146,7 +1149,7 @@ void ContextifyContext::CompileFunction(
11461149
context).ToLocal(&cache_key)) {
11471150
return;
11481151
}
1149-
CompiledFnEntry* entry = new CompiledFnEntry(env, cache_key, id, script);
1152+
CompiledFnEntry* entry = new CompiledFnEntry(env, cache_key, id, fn);
11501153
env->id_to_function_map.emplace(id, entry);
11511154

11521155
Local<Object> result = Object::New(isolate);
@@ -1192,16 +1195,14 @@ void CompiledFnEntry::WeakCallback(
11921195
CompiledFnEntry::CompiledFnEntry(Environment* env,
11931196
Local<Object> object,
11941197
uint32_t id,
1195-
Local<ScriptOrModule> script)
1196-
: BaseObject(env, object),
1197-
id_(id),
1198-
script_(env->isolate(), script) {
1199-
script_.SetWeak(this, WeakCallback, v8::WeakCallbackType::kParameter);
1198+
Local<Function> fn)
1199+
: BaseObject(env, object), id_(id), fn_(env->isolate(), fn) {
1200+
fn_.SetWeak(this, WeakCallback, v8::WeakCallbackType::kParameter);
12001201
}
12011202

12021203
CompiledFnEntry::~CompiledFnEntry() {
12031204
env()->id_to_function_map.erase(id_);
1204-
script_.ClearWeak();
1205+
fn_.ClearWeak();
12051206
}
12061207

12071208
static void StartSigintWatchdog(const FunctionCallbackInfo<Value>& args) {

src/node_contextify.h

Lines 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
};

src/node_snapshotable.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,13 +1335,13 @@ void CompileSerializeMain(const FunctionCallbackInfo<Value>& args) {
13351335
};
13361336
ScriptCompiler::Source script_source(source, origin);
13371337
Local<Function> fn;
1338-
if (ScriptCompiler::CompileFunctionInContext(context,
1339-
&script_source,
1340-
parameters.size(),
1341-
parameters.data(),
1342-
0,
1343-
nullptr,
1344-
ScriptCompiler::kEagerCompile)
1338+
if (ScriptCompiler::CompileFunction(context,
1339+
&script_source,
1340+
parameters.size(),
1341+
parameters.data(),
1342+
0,
1343+
nullptr,
1344+
ScriptCompiler::kEagerCompile)
13451345
.ToLocal(&fn)) {
13461346
args.GetReturnValue().Set(fn);
13471347
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy