@@ -45,53 +45,52 @@ This patch should be upstreamed to Node.
45
45
46
46
See also: https://source.chromium.org/chromium/chromium/src/+/main:v8/include/v8-cppgc.h;l=70-76;drc=5a758a97032f0b656c3c36a3497560762495501a
47
47
48
- diff --git a/src/base_object-inl.h b/src/base_object-inl.h
49
- index bb1e8d4b46bce3bf08f730ac5d43f7113d17ae39..6da0669943fc6465ffc47a1c8c3dadfea6beb1c9 100644
50
- --- a/src/base_object-inl.h
51
- +++ b/src/base_object-inl.h
52
- @@ -32,10 +32,21 @@
48
+ diff --git a/src/base_object.h b/src/base_object.h
49
+ index 842f763a56d75c55509534e3d44a8080dd283127..b6078fe83c82a5edec0f7652b8c2d1b6c2491ca4 100644
50
+ --- a/src/base_object.h
51
+ +++ b/src/base_object.h
52
+ @@ -40,7 +40,7 @@ class TransferData;
53
+
54
+ class BaseObject : public MemoryRetainer {
55
+ public:
56
+ - enum InternalFields { kSlot, kInternalFieldCount };
57
+ + enum InternalFields { kWrapperType, kSlot, kInternalFieldCount };
53
58
54
- namespace node {
59
+ // Associates this object with `object`. It uses the 0th internal field for
60
+ // that, and in particular aborts if there is no such field.
61
+ diff --git a/src/env.cc b/src/env.cc
62
+ index 22be69ec30a5b8466caacc698c791494891e5dee..cc44d578df9e146aa72f8273c1271d6a3c00d610 100644
63
+ --- a/src/env.cc
64
+ +++ b/src/env.cc
65
+ @@ -2119,11 +2119,20 @@ void Environment::RunWeakRefCleanup() {
66
+ isolate()->ClearKeptObjects();
67
+ }
55
68
56
- + namespace {
57
69
+ // This just has to be different from the Chromium ones:
58
70
+ // https://source.chromium.org/chromium/chromium/src/+/main:gin/public/gin_embedders.h;l=18-23;drc=5a758a97032f0b656c3c36a3497560762495501a
59
71
+ // Otherwise, when Node is loaded in an isolate which uses cppgc, cppgc will
60
72
+ // misinterpret the data stored in the embedder fields and try to garbage
61
73
+ // collect them.
62
- + static uint16_t kNodeEmbedderId = 0x90de;
63
- + }
74
+ + uint16_t kNodeEmbedderId = 0x90de;
64
75
+
65
- BaseObject::BaseObject(Environment* env, v8::Local<v8::Object> object)
76
+ // Not really any better place than env.cc at this moment.
77
+ BaseObject::BaseObject(Environment* env, Local<Object> object)
66
78
: persistent_handle_(env->isolate(), object), env_(env) {
67
79
CHECK_EQ(false, object.IsEmpty());
68
80
- CHECK_GT(object->InternalFieldCount(), 0);
69
81
+ CHECK_GT(object->InternalFieldCount(), BaseObject::kSlot);
70
82
+ object->SetAlignedPointerInInternalField(BaseObject::kWrapperType,
71
83
+ &kNodeEmbedderId);
72
- object->SetAlignedPointerInInternalField(
73
- BaseObject::kSlot,
74
- static_cast<void*>(this));
75
- @@ -151 ,7 +162 ,8 @@ bool BaseObject::IsWeakOrDetached() const {
84
+ object->SetAlignedPointerInInternalField(BaseObject::kSlot,
85
+ static_cast<void*>(this));
86
+ env->AddCleanupHook(DeleteMe, static_cast<void*>(this));
87
+ @@ -2177 ,7 +2186 ,8 @@ void BaseObject::MakeWeak() {
76
88
void BaseObject::LazilyInitializedJSTemplateConstructor(
77
- const v8:: FunctionCallbackInfo<v8:: Value>& args) {
89
+ const FunctionCallbackInfo<Value>& args) {
78
90
DCHECK(args.IsConstructCall());
79
91
- DCHECK_GT(args.This()->InternalFieldCount(), 0);
80
92
+ DCHECK_GT(args.This()->InternalFieldCount(), BaseObject::kSlot);
81
93
+ args.This()->SetAlignedPointerInInternalField(BaseObject::kWrapperType, &kNodeEmbedderId);
82
94
args.This()->SetAlignedPointerInInternalField(BaseObject::kSlot, nullptr);
83
95
}
84
96
85
- diff --git a/src/base_object.h b/src/base_object.h
86
- index 1c63da92fd80c042d5ea729bdd70049cae51a141..3b8127e884187b21cebeabb39b60bd3010b62217 100644
87
- --- a/src/base_object.h
88
- +++ b/src/base_object.h
89
- @@ -40,7 +40,7 @@ class TransferData;
90
-
91
- class BaseObject : public MemoryRetainer {
92
- public:
93
- - enum InternalFields { kSlot, kInternalFieldCount };
94
- + enum InternalFields { kWrapperType, kSlot, kInternalFieldCount };
95
-
96
- // Associates this object with `object`. It uses the 0th internal field for
97
- // that, and in particular aborts if there is no such field.
0 commit comments