Skip to content

Commit 46ce6c0

Browse files
committed
fixup! src: make realm binding data store weak
1 parent 9a300b2 commit 46ce6c0

File tree

6 files changed

+37
-5
lines changed

6 files changed

+37
-5
lines changed

src/env.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ void Environment::AssignToContext(Local<v8::Context> context,
595595
TrackContext(context);
596596
}
597597

598-
void Environment::UnassignToContext(Local<v8::Context> context) {
598+
void Environment::UnassignFromContext(Local<v8::Context> context) {
599599
if (!context.IsEmpty()) {
600600
context->SetAlignedPointerInEmbedderData(ContextEmbedderIndex::kEnvironment,
601601
nullptr);

src/env.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ class Environment : public MemoryRetainer {
645645
void AssignToContext(v8::Local<v8::Context> context,
646646
Realm* realm,
647647
const ContextInfo& info);
648-
void UnassignToContext(v8::Local<v8::Context> context);
648+
void UnassignFromContext(v8::Local<v8::Context> context);
649649
void TrackShadowRealm(shadow_realm::ShadowRealm* realm);
650650
void UntrackShadowRealm(shadow_realm::ShadowRealm* realm);
651651

src/node_contextify.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ ContextifyContext::~ContextifyContext() {
163163
Isolate* isolate = env()->isolate();
164164
HandleScope scope(isolate);
165165

166-
env()->UnassignToContext(PersistentToLocal::Weak(isolate, context_));
166+
env()->UnassignFromContext(PersistentToLocal::Weak(isolate, context_));
167167
context_.Reset();
168168
}
169169

src/node_realm.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ PrincipalRealm::~PrincipalRealm() {
309309
DCHECK(!context_.IsEmpty());
310310

311311
HandleScope handle_scope(isolate());
312-
env_->UnassignToContext(context());
312+
env_->UnassignFromContext(context());
313313
}
314314

315315
MaybeLocal<Value> PrincipalRealm::BootstrapRealm() {

src/node_shadow_realm.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ ShadowRealm::~ShadowRealm() {
8585

8686
{
8787
HandleScope handle_scope(isolate());
88-
env_->UnassignToContext(context());
88+
env_->UnassignFromContext(context());
8989
}
9090
}
9191

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Flags: --experimental-shadow-realm --expose-internals
2+
'use strict';
3+
require('../common');
4+
const { validateSnapshotNodes } = require('../common/heap');
5+
6+
validateSnapshotNodes('Node / ShadowRealm', []);
7+
const realm = new ShadowRealm();
8+
{
9+
// Create a bunch of un-referenced ShadowRealms to make sure the heap
10+
// snapshot can handle it.
11+
for (let i = 0; i < 100; i++) {
12+
const realm = new ShadowRealm();
13+
realm.evaluate('undefined');
14+
}
15+
}
16+
validateSnapshotNodes('Node / Environment', [
17+
{
18+
children: [
19+
{ node_name: 'Node / shadow_realms', edge_name: 'shadow_realms' },
20+
],
21+
},
22+
]);
23+
validateSnapshotNodes('Node / shadow_realms', [
24+
{
25+
children: [
26+
{ node_name: 'Node / ShadowRealm' },
27+
],
28+
},
29+
]);
30+
31+
// Keep the realm alive.
32+
realm.evaluate('undefined');

0 commit comments

Comments
 (0)