Skip to content

Commit d313bf7

Browse files
addaleaxnodejs-github-bot
authored andcommitted
src: add way to get IsolateData and allocator from Environment
Add a way to get the current `IsolateData*` and, from it, the current Node.js `ArrayBufferAllocator` if there is one. This can be useful for re-using either one of these structures as an embedder. PR-URL: #36441 Reviewed-By: Daniel Bevenius <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 7069d22 commit d313bf7

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

src/api/environment.cc

+8
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,14 @@ Environment* GetCurrentEnvironment(Local<Context> context) {
438438
return Environment::GetCurrent(context);
439439
}
440440

441+
IsolateData* GetEnvironmentIsolateData(Environment* env) {
442+
return env->isolate_data();
443+
}
444+
445+
ArrayBufferAllocator* GetArrayBufferAllocator(IsolateData* isolate_data) {
446+
return isolate_data->node_allocator();
447+
}
448+
441449
MultiIsolatePlatform* GetMultiIsolatePlatform(Environment* env) {
442450
return GetMultiIsolatePlatform(env->isolate_data());
443451
}

src/node.h

+2
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,8 @@ NODE_EXTERN void DefaultProcessExitHandler(Environment* env, int exit_code);
464464

465465
// This may return nullptr if context is not associated with a Node instance.
466466
NODE_EXTERN Environment* GetCurrentEnvironment(v8::Local<v8::Context> context);
467+
NODE_EXTERN IsolateData* GetEnvironmentIsolateData(Environment* env);
468+
NODE_EXTERN ArrayBufferAllocator* GetArrayBufferAllocator(IsolateData* data);
467469

468470
NODE_EXTERN void OnFatalError(const char* location, const char* message);
469471
NODE_EXTERN void PromiseRejectCallback(v8::PromiseRejectMessage message);

test/cctest/test_environment.cc

+3
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,9 @@ TEST_F(NodeZeroIsolateTestFixture, CtrlCWithOnlySafeTerminationTest) {
586586
{}),
587587
node::FreeEnvironment};
588588
CHECK(environment);
589+
EXPECT_EQ(node::GetEnvironmentIsolateData(environment.get()),
590+
isolate_data.get());
591+
EXPECT_EQ(node::GetArrayBufferAllocator(isolate_data.get()), nullptr);
589592

590593
v8::Local<v8::Value> main_ret =
591594
node::LoadEnvironment(environment.get(),

0 commit comments

Comments
 (0)