Skip to content

Commit 09cf132

Browse files
committed
src: expose v8::Isolate setup callbacks
1 parent 1cef9c6 commit 09cf132

File tree

4 files changed

+37
-32
lines changed

4 files changed

+37
-32
lines changed

src/api/environment.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ using v8::SealHandleScope;
3131
using v8::String;
3232
using v8::Value;
3333

34-
static bool AllowWasmCodeGenerationCallback(Local<Context> context,
35-
Local<String>) {
34+
bool AllowWasmCodeGenerationCallback(Local<Context> context,
35+
Local<String>) {
3636
Local<Value> wasm_code_gen =
3737
context->GetEmbedderData(ContextEmbedderIndex::kAllowWasmCodeGeneration);
3838
return wasm_code_gen->IsUndefined() || wasm_code_gen->IsTrue();
3939
}
4040

41-
static bool ShouldAbortOnUncaughtException(Isolate* isolate) {
41+
bool ShouldAbortOnUncaughtException(Isolate* isolate) {
4242
DebugSealHandleScope scope(isolate);
4343
Environment* env = Environment::GetCurrent(isolate);
4444
return env != nullptr &&
@@ -48,9 +48,9 @@ static bool ShouldAbortOnUncaughtException(Isolate* isolate) {
4848
!env->inside_should_not_abort_on_uncaught_scope();
4949
}
5050

51-
static MaybeLocal<Value> PrepareStackTraceCallback(Local<Context> context,
52-
Local<Value> exception,
53-
Local<Array> trace) {
51+
MaybeLocal<Value> PrepareStackTraceCallback(Local<Context> context,
52+
Local<Value> exception,
53+
Local<Array> trace) {
5454
Environment* env = Environment::GetCurrent(context);
5555
if (env == nullptr) {
5656
return exception->ToString(context).FromMaybe(Local<Value>());
@@ -245,7 +245,7 @@ void SetIsolateMiscHandlers(v8::Isolate* isolate, const IsolateSettings& s) {
245245

246246
if ((s.flags & SHOULD_NOT_SET_PROMISE_REJECTION_CALLBACK) == 0) {
247247
auto* promise_reject_cb = s.promise_reject_callback ?
248-
s.promise_reject_callback : task_queue::PromiseRejectCallback;
248+
s.promise_reject_callback : PromiseRejectCallback;
249249
isolate->SetPromiseRejectCallback(promise_reject_cb);
250250
}
251251

src/node.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,16 @@ NODE_EXTERN void DefaultProcessExitHandler(Environment* env, int exit_code);
495495
// This may return nullptr if context is not associated with a Node instance.
496496
NODE_EXTERN Environment* GetCurrentEnvironment(v8::Local<v8::Context> context);
497497

498+
NODE_EXTERN void OnFatalError(const char* location, const char* message);
499+
NODE_EXTERN void PromiseRejectCallback(v8::PromiseRejectMessage message);
500+
NODE_EXTERN bool AllowWasmCodeGenerationCallback(v8::Local<v8::Context> context,
501+
v8::Local<v8::String>);
502+
NODE_EXTERN bool ShouldAbortOnUncaughtException(v8::Isolate* isolate);
503+
NODE_EXTERN v8::MaybeLocal<v8::Value> PrepareStackTraceCallback(
504+
v8::Local<v8::Context> context,
505+
v8::Local<v8::Value> exception,
506+
v8::Local<v8::Array> trace);
507+
498508
// This returns the MultiIsolatePlatform used in the main thread of Node.js.
499509
// If NODE_USE_V8_PLATFORM has not been defined when Node.js was built,
500510
// it returns nullptr.

src/node_internals.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,6 @@ std::string GetHumanReadableProcessName();
100100
void InitializeContextRuntime(v8::Local<v8::Context>);
101101
bool InitializePrimordials(v8::Local<v8::Context> context);
102102

103-
namespace task_queue {
104-
void PromiseRejectCallback(v8::PromiseRejectMessage message);
105-
} // namespace task_queue
106-
107103
class NodeArrayBufferAllocator : public ArrayBufferAllocator {
108104
public:
109105
inline uint32_t* zero_fill_field() { return &zero_fill_field_; }

src/node_task_queue.cc

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,6 @@ using v8::PromiseRejectEvent;
2929
using v8::PromiseRejectMessage;
3030
using v8::Value;
3131

32-
namespace task_queue {
33-
34-
static void EnqueueMicrotask(const FunctionCallbackInfo<Value>& args) {
35-
Environment* env = Environment::GetCurrent(args);
36-
Isolate* isolate = env->isolate();
37-
38-
CHECK(args[0]->IsFunction());
39-
40-
isolate->EnqueueMicrotask(args[0].As<Function>());
41-
}
42-
43-
static void RunMicrotasks(const FunctionCallbackInfo<Value>& args) {
44-
MicrotasksScope::PerformCheckpoint(args.GetIsolate());
45-
}
46-
47-
static void SetTickCallback(const FunctionCallbackInfo<Value>& args) {
48-
Environment* env = Environment::GetCurrent(args);
49-
CHECK(args[0]->IsFunction());
50-
env->set_tick_callback_function(args[0].As<Function>());
51-
}
52-
5332
void PromiseRejectCallback(PromiseRejectMessage message) {
5433
static std::atomic<uint64_t> unhandledRejections{0};
5534
static std::atomic<uint64_t> rejectionsHandledAfter{0};
@@ -109,6 +88,26 @@ void PromiseRejectCallback(PromiseRejectMessage message) {
10988
PrintCaughtException(isolate, env->context(), try_catch);
11089
}
11190
}
91+
namespace task_queue {
92+
93+
static void EnqueueMicrotask(const FunctionCallbackInfo<Value>& args) {
94+
Environment* env = Environment::GetCurrent(args);
95+
Isolate* isolate = env->isolate();
96+
97+
CHECK(args[0]->IsFunction());
98+
99+
isolate->EnqueueMicrotask(args[0].As<Function>());
100+
}
101+
102+
static void RunMicrotasks(const FunctionCallbackInfo<Value>& args) {
103+
MicrotasksScope::PerformCheckpoint(args.GetIsolate());
104+
}
105+
106+
static void SetTickCallback(const FunctionCallbackInfo<Value>& args) {
107+
Environment* env = Environment::GetCurrent(args);
108+
CHECK(args[0]->IsFunction());
109+
env->set_tick_callback_function(args[0].As<Function>());
110+
}
112111

113112
static void SetPromiseRejectCallback(
114113
const FunctionCallbackInfo<Value>& args) {

0 commit comments

Comments
 (0)