Skip to content

Commit ca0f5a0

Browse files
jasnelltargos
authored andcommitted
src: add env->cppgc_allocation_handle() convenience method
Reduce some of the boilerplate code needed to access the cppgc::AllocationHandle from the Node.js Environment. PR-URL: #58483 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
1 parent 80cc17f commit ca0f5a0

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

src/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,7 @@ MyWrap* MyWrap::New(Environment* env, v8::Local<v8::Object> object) {
11931193
// pointer with this, as this is not managed by the native memory
11941194
// allocator but by V8.
11951195
return cppgc::MakeGarbageCollected<MyWrap>(
1196-
env->isolate()->GetCppHeap()->GetAllocationHandle(), env, object);
1196+
env->cppgc_allocation_handle(), env, object);
11971197
}
11981198
11991199
// Binding method to be invoked by JavaScript.

src/env-inl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ inline v8::Isolate* Environment::isolate() const {
205205
return isolate_;
206206
}
207207

208+
inline cppgc::AllocationHandle& Environment::cppgc_allocation_handle() const {
209+
return isolate_->GetCppHeap()->GetAllocationHandle();
210+
}
211+
208212
inline v8::ExternalMemoryAccounter* Environment::external_memory_accounter()
209213
const {
210214
return external_memory_accounter_;

src/env.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,7 @@ class Environment final : public MemoryRetainer {
692692
void StartProfilerIdleNotifier();
693693

694694
inline v8::Isolate* isolate() const;
695+
inline cppgc::AllocationHandle& cppgc_allocation_handle() const;
695696
inline v8::ExternalMemoryAccounter* external_memory_accounter() const;
696697
inline uv_loop_t* event_loop() const;
697698
void TryLoadAddon(const char* filename,

src/node_contextify.cc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,7 @@ ContextifyContext* ContextifyContext::New(Local<Context> v8_context,
330330
}
331331
DCHECK_NOT_NULL(env->isolate()->GetCppHeap());
332332
result = cppgc::MakeGarbageCollected<ContextifyContext>(
333-
env->isolate()->GetCppHeap()->GetAllocationHandle(),
334-
env,
335-
wrapper,
336-
v8_context,
337-
options);
333+
env->cppgc_allocation_handle(), env, wrapper, v8_context, options);
338334
}
339335

340336
Local<Object> wrapper_holder =
@@ -975,7 +971,7 @@ ContextifyScript* ContextifyScript::New(Environment* env,
975971
Local<Object> object) {
976972
DCHECK_NOT_NULL(env->isolate()->GetCppHeap());
977973
return cppgc::MakeGarbageCollected<ContextifyScript>(
978-
env->isolate()->GetCppHeap()->GetAllocationHandle(), env, object);
974+
env->cppgc_allocation_handle(), env, object);
979975
}
980976

981977
void ContextifyScript::New(const FunctionCallbackInfo<Value>& args) {

0 commit comments

Comments
 (0)