21
21
22
22
#include " node_contextify.h"
23
23
24
+ #include " cppgc/allocation.h"
24
25
#include " base_object-inl.h"
25
26
#include " memory_tracker-inl.h"
26
27
#include " module_wrap.h"
@@ -826,8 +827,9 @@ void ContextifyScript::New(const FunctionCallbackInfo<Value>& args) {
826
827
id_symbol = args[7 ].As <Symbol>();
827
828
}
828
829
829
- ContextifyScript* contextify_script =
830
- new ContextifyScript (env, args.This ());
830
+
831
+ ContextifyScript* contextify_script = cppgc::MakeGarbageCollected<ContextifyScript>(
832
+ env->isolate ()->GetCppHeap ()->GetAllocationHandle (), env, args.This ());
831
833
832
834
if (*TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED (
833
835
TRACING_CATEGORY_NODE2 (vm, script)) != 0 ) {
@@ -887,8 +889,6 @@ void ContextifyScript::New(const FunctionCallbackInfo<Value>& args) {
887
889
}
888
890
889
891
contextify_script->script_ .Reset (isolate, v8_script);
890
- contextify_script->script_ .SetWeak ();
891
- contextify_script->object ()->SetInternalField (kUnboundScriptSlot , v8_script);
892
892
893
893
std::unique_ptr<ScriptCompiler::CachedData> new_cached_data;
894
894
if (produce_cached_data) {
@@ -990,10 +990,9 @@ bool ContextifyScript::InstanceOf(Environment* env,
990
990
void ContextifyScript::CreateCachedData (
991
991
const FunctionCallbackInfo<Value>& args) {
992
992
Environment* env = Environment::GetCurrent (args);
993
- ContextifyScript* wrapped_script;
994
- ASSIGN_OR_RETURN_UNWRAP (&wrapped_script, args.Holder ());
995
- Local<UnboundScript> unbound_script =
996
- PersistentToLocal::Default (env->isolate (), wrapped_script->script_ );
993
+ ContextifyScript* wrapped_script = CppgcMixin::Unwrap<ContextifyScript>(args.Holder ());
994
+ CHECK_NOT_NULL (wrapped_script);
995
+ Local<UnboundScript> unbound_script = wrapped_script->script_ .Get (env->isolate ());
997
996
std::unique_ptr<ScriptCompiler::CachedData> cached_data (
998
997
ScriptCompiler::CreateCodeCache (unbound_script));
999
998
if (!cached_data) {
@@ -1010,8 +1009,8 @@ void ContextifyScript::CreateCachedData(
1010
1009
void ContextifyScript::RunInContext (const FunctionCallbackInfo<Value>& args) {
1011
1010
Environment* env = Environment::GetCurrent (args);
1012
1011
1013
- ContextifyScript* wrapped_script;
1014
- ASSIGN_OR_RETURN_UNWRAP (& wrapped_script, args. Holder () );
1012
+ ContextifyScript* wrapped_script = CppgcMixin::Unwrap<ContextifyScript>(args. Holder ()) ;
1013
+ CHECK_NOT_NULL ( wrapped_script);
1015
1014
1016
1015
CHECK_EQ (args.Length (), 5 );
1017
1016
CHECK (args[0 ]->IsObject () || args[0 ]->IsNull ());
@@ -1081,10 +1080,9 @@ bool ContextifyScript::EvalMachine(Local<Context> context,
1081
1080
1082
1081
TryCatchScope try_catch (env);
1083
1082
Isolate::SafeForTerminationScope safe_for_termination (env->isolate ());
1084
- ContextifyScript* wrapped_script;
1085
- ASSIGN_OR_RETURN_UNWRAP (&wrapped_script, args.Holder (), false );
1086
- Local<UnboundScript> unbound_script =
1087
- PersistentToLocal::Default (env->isolate (), wrapped_script->script_ );
1083
+ ContextifyScript* wrapped_script = CppgcMixin::Unwrap<ContextifyScript>(args.Holder ());
1084
+ CHECK_NOT_NULL (wrapped_script);
1085
+ Local<UnboundScript> unbound_script = wrapped_script->script_ .Get (env->isolate ());
1088
1086
Local<Script> script = unbound_script->BindToCurrentContext ();
1089
1087
1090
1088
#if HAVE_INSPECTOR
@@ -1152,9 +1150,13 @@ bool ContextifyScript::EvalMachine(Local<Context> context,
1152
1150
return true ;
1153
1151
}
1154
1152
1155
- ContextifyScript::ContextifyScript (Environment* env, Local<Object> object)
1156
- : BaseObject(env, object) {
1157
- MakeWeak ();
1153
+ void ContextifyScript::Trace (cppgc::Visitor* visitor) const {
1154
+ CppgcMixin::Trace (visitor);
1155
+ visitor->Trace (script_);
1156
+ }
1157
+
1158
+ ContextifyScript::ContextifyScript (Environment* env, Local<Object> object) {
1159
+ InitializeCppgc (this , env, object);
1158
1160
}
1159
1161
1160
1162
ContextifyScript::~ContextifyScript () {}
0 commit comments