22
22
#include " node_contextify.h"
23
23
24
24
#include " base_object-inl.h"
25
+ #include " cppgc/allocation.h"
25
26
#include " memory_tracker-inl.h"
26
27
#include " module_wrap.h"
27
28
#include " node_context_data.h"
@@ -960,6 +961,12 @@ void ContextifyScript::RegisterExternalReferences(
960
961
registry->Register (RunInContext);
961
962
}
962
963
964
+ ContextifyScript* ContextifyScript::New (Environment* env,
965
+ Local<Object> object) {
966
+ return cppgc::MakeGarbageCollected<ContextifyScript>(
967
+ env->isolate ()->GetCppHeap ()->GetAllocationHandle (), env, object);
968
+ }
969
+
963
970
void ContextifyScript::New (const FunctionCallbackInfo<Value>& args) {
964
971
Environment* env = Environment::GetCurrent (args);
965
972
Isolate* isolate = env->isolate ();
@@ -1010,8 +1017,7 @@ void ContextifyScript::New(const FunctionCallbackInfo<Value>& args) {
1010
1017
id_symbol = args[7 ].As <Symbol>();
1011
1018
}
1012
1019
1013
- ContextifyScript* contextify_script =
1014
- new ContextifyScript (env, args.This ());
1020
+ ContextifyScript* contextify_script = New (env, args.This ());
1015
1021
1016
1022
if (*TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED (
1017
1023
TRACING_CATEGORY_NODE2 (vm, script)) != 0 ) {
@@ -1069,9 +1075,7 @@ void ContextifyScript::New(const FunctionCallbackInfo<Value>& args) {
1069
1075
return ;
1070
1076
}
1071
1077
1072
- contextify_script->script_ .Reset (isolate, v8_script);
1073
- contextify_script->script_ .SetWeak ();
1074
- contextify_script->object ()->SetInternalField (kUnboundScriptSlot , v8_script);
1078
+ contextify_script->set_unbound_script (v8_script);
1075
1079
1076
1080
std::unique_ptr<ScriptCompiler::CachedData> new_cached_data;
1077
1081
if (produce_cached_data) {
@@ -1174,11 +1178,9 @@ void ContextifyScript::CreateCachedData(
1174
1178
const FunctionCallbackInfo<Value>& args) {
1175
1179
Environment* env = Environment::GetCurrent (args);
1176
1180
ContextifyScript* wrapped_script;
1177
- ASSIGN_OR_RETURN_UNWRAP (&wrapped_script, args.This ());
1178
- Local<UnboundScript> unbound_script =
1179
- PersistentToLocal::Default (env->isolate (), wrapped_script->script_ );
1181
+ ASSIGN_OR_RETURN_UNWRAP_CPPGC (&wrapped_script, args.This ());
1180
1182
std::unique_ptr<ScriptCompiler::CachedData> cached_data (
1181
- ScriptCompiler::CreateCodeCache (unbound_script));
1183
+ ScriptCompiler::CreateCodeCache (wrapped_script-> unbound_script () ));
1182
1184
if (!cached_data) {
1183
1185
args.GetReturnValue ().Set (Buffer::New (env, 0 ).ToLocalChecked ());
1184
1186
} else {
@@ -1192,9 +1194,8 @@ void ContextifyScript::CreateCachedData(
1192
1194
1193
1195
void ContextifyScript::RunInContext (const FunctionCallbackInfo<Value>& args) {
1194
1196
Environment* env = Environment::GetCurrent (args);
1195
-
1196
1197
ContextifyScript* wrapped_script;
1197
- ASSIGN_OR_RETURN_UNWRAP (&wrapped_script, args.This ());
1198
+ ASSIGN_OR_RETURN_UNWRAP_CPPGC (&wrapped_script, args.This ());
1198
1199
1199
1200
CHECK_EQ (args.Length (), 5 );
1200
1201
CHECK (args[0 ]->IsObject () || args[0 ]->IsNull ());
@@ -1264,10 +1265,9 @@ bool ContextifyScript::EvalMachine(Local<Context> context,
1264
1265
1265
1266
TryCatchScope try_catch (env);
1266
1267
ContextifyScript* wrapped_script;
1267
- ASSIGN_OR_RETURN_UNWRAP (&wrapped_script, args.This (), false );
1268
- Local<UnboundScript> unbound_script =
1269
- PersistentToLocal::Default (env->isolate (), wrapped_script->script_ );
1270
- Local<Script> script = unbound_script->BindToCurrentContext ();
1268
+ ASSIGN_OR_RETURN_UNWRAP_CPPGC (&wrapped_script, args.This (), false );
1269
+ Local<Script> script =
1270
+ wrapped_script->unbound_script ()->BindToCurrentContext ();
1271
1271
1272
1272
#if HAVE_INSPECTOR
1273
1273
if (break_on_first_line) {
@@ -1349,9 +1349,21 @@ bool ContextifyScript::EvalMachine(Local<Context> context,
1349
1349
return true ;
1350
1350
}
1351
1351
1352
- ContextifyScript::ContextifyScript (Environment* env, Local<Object> object)
1353
- : BaseObject(env, object) {
1354
- MakeWeak ();
1352
+ Local<UnboundScript> ContextifyScript::unbound_script () const {
1353
+ return script_.Get (env ()->isolate ());
1354
+ }
1355
+
1356
+ void ContextifyScript::set_unbound_script (Local<UnboundScript> script) {
1357
+ script_.Reset (env ()->isolate (), script);
1358
+ }
1359
+
1360
+ void ContextifyScript::Trace (cppgc::Visitor* visitor) const {
1361
+ CppgcMixin::Trace (visitor);
1362
+ visitor->Trace (script_);
1363
+ }
1364
+
1365
+ ContextifyScript::ContextifyScript (Environment* env, Local<Object> object) {
1366
+ CppgcMixin::Wrap (this , env, object);
1355
1367
}
1356
1368
1357
1369
ContextifyScript::~ContextifyScript () {}
0 commit comments