Skip to content

Commit 43d1791

Browse files
addaleaxBethGriggs
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 caa703d commit 43d1791

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
@@ -466,6 +466,14 @@ MultiIsolatePlatform* GetMainThreadMultiIsolatePlatform() {
466466
return per_process::v8_platform.Platform();
467467
}
468468

469+
IsolateData* GetEnvironmentIsolateData(Environment* env) {
470+
return env->isolate_data();
471+
}
472+
473+
ArrayBufferAllocator* GetArrayBufferAllocator(IsolateData* isolate_data) {
474+
return isolate_data->node_allocator();
475+
}
476+
469477
MultiIsolatePlatform* GetMultiIsolatePlatform(Environment* env) {
470478
return GetMultiIsolatePlatform(env->isolate_data());
471479
}

src/node.h

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

501501
// This may return nullptr if context is not associated with a Node instance.
502502
NODE_EXTERN Environment* GetCurrentEnvironment(v8::Local<v8::Context> context);
503+
NODE_EXTERN IsolateData* GetEnvironmentIsolateData(Environment* env);
504+
NODE_EXTERN ArrayBufferAllocator* GetArrayBufferAllocator(IsolateData* data);
503505

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

test/cctest/test_environment.cc

+3
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,9 @@ TEST_F(NodeZeroIsolateTestFixture, CtrlCWithOnlySafeTerminationTest) {
627627
{}),
628628
node::FreeEnvironment};
629629
CHECK(environment);
630+
EXPECT_EQ(node::GetEnvironmentIsolateData(environment.get()),
631+
isolate_data.get());
632+
EXPECT_EQ(node::GetArrayBufferAllocator(isolate_data.get()), nullptr);
630633

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

0 commit comments

Comments
 (0)