Skip to content

Commit 56dbbf9

Browse files
committed
src: slim down env-inl.h
nodejs/node#43745
1 parent d646d29 commit 56dbbf9

File tree

1 file changed

+27
-28
lines changed

1 file changed

+27
-28
lines changed

patches/node/be_compatible_with_cppgc.patch

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -45,53 +45,52 @@ This patch should be upstreamed to Node.
4545

4646
See also: https://source.chromium.org/chromium/chromium/src/+/main:v8/include/v8-cppgc.h;l=70-76;drc=5a758a97032f0b656c3c36a3497560762495501a
4747

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

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+
}
5568

56-
+namespace {
5769
+// This just has to be different from the Chromium ones:
5870
+// https://source.chromium.org/chromium/chromium/src/+/main:gin/public/gin_embedders.h;l=18-23;drc=5a758a97032f0b656c3c36a3497560762495501a
5971
+// Otherwise, when Node is loaded in an isolate which uses cppgc, cppgc will
6072
+// misinterpret the data stored in the embedder fields and try to garbage
6173
+// collect them.
62-
+static uint16_t kNodeEmbedderId = 0x90de;
63-
+}
74+
+uint16_t kNodeEmbedderId = 0x90de;
6475
+
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)
6678
: persistent_handle_(env->isolate(), object), env_(env) {
6779
CHECK_EQ(false, object.IsEmpty());
6880
- CHECK_GT(object->InternalFieldCount(), 0);
6981
+ CHECK_GT(object->InternalFieldCount(), BaseObject::kSlot);
7082
+ object->SetAlignedPointerInInternalField(BaseObject::kWrapperType,
7183
+ &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() {
7688
void BaseObject::LazilyInitializedJSTemplateConstructor(
77-
const v8::FunctionCallbackInfo<v8::Value>& args) {
89+
const FunctionCallbackInfo<Value>& args) {
7890
DCHECK(args.IsConstructCall());
7991
- DCHECK_GT(args.This()->InternalFieldCount(), 0);
8092
+ DCHECK_GT(args.This()->InternalFieldCount(), BaseObject::kSlot);
8193
+ args.This()->SetAlignedPointerInInternalField(BaseObject::kWrapperType, &kNodeEmbedderId);
8294
args.This()->SetAlignedPointerInInternalField(BaseObject::kSlot, nullptr);
8395
}
8496

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

Comments
 (0)