diff --git a/src/api/environment.cc b/src/api/environment.cc index fa91ed8b404af4..57d05c963df348 100644 --- a/src/api/environment.cc +++ b/src/api/environment.cc @@ -31,14 +31,14 @@ using v8::PropertyDescriptor; using v8::String; using v8::Value; -static bool AllowWasmCodeGenerationCallback(Local context, - Local) { +bool AllowWasmCodeGenerationCallback(Local context, + Local) { Local wasm_code_gen = context->GetEmbedderData(ContextEmbedderIndex::kAllowWasmCodeGeneration); return wasm_code_gen->IsUndefined() || wasm_code_gen->IsTrue(); } -static bool ShouldAbortOnUncaughtException(Isolate* isolate) { +bool ShouldAbortOnUncaughtException(Isolate* isolate) { DebugSealHandleScope scope(isolate); Environment* env = Environment::GetCurrent(isolate); return env != nullptr && @@ -48,9 +48,9 @@ static bool ShouldAbortOnUncaughtException(Isolate* isolate) { !env->inside_should_not_abort_on_uncaught_scope(); } -static MaybeLocal PrepareStackTraceCallback(Local context, - Local exception, - Local trace) { +MaybeLocal PrepareStackTraceCallback(Local context, + Local exception, + Local trace) { Environment* env = Environment::GetCurrent(context); if (env == nullptr) { return exception->ToString(context).FromMaybe(Local()); @@ -252,7 +252,7 @@ void SetIsolateMiscHandlers(v8::Isolate* isolate, const IsolateSettings& s) { if ((s.flags & SHOULD_NOT_SET_PROMISE_REJECTION_CALLBACK) == 0) { auto* promise_reject_cb = s.promise_reject_callback ? - s.promise_reject_callback : task_queue::PromiseRejectCallback; + s.promise_reject_callback : PromiseRejectCallback; isolate->SetPromiseRejectCallback(promise_reject_cb); } diff --git a/src/node.h b/src/node.h index 001d4972fadb67..2fda6d125e7e09 100644 --- a/src/node.h +++ b/src/node.h @@ -479,6 +479,16 @@ NODE_EXTERN void DefaultProcessExitHandler(Environment* env, int exit_code); // This may return nullptr if context is not associated with a Node instance. NODE_EXTERN Environment* GetCurrentEnvironment(v8::Local context); +NODE_EXTERN void OnFatalError(const char* location, const char* message); +NODE_EXTERN void PromiseRejectCallback(v8::PromiseRejectMessage message); +NODE_EXTERN bool AllowWasmCodeGenerationCallback(v8::Local context, + v8::Local); +NODE_EXTERN bool ShouldAbortOnUncaughtException(v8::Isolate* isolate); +NODE_EXTERN v8::MaybeLocal PrepareStackTraceCallback( + v8::Local context, + v8::Local exception, + v8::Local trace); + // This returns the MultiIsolatePlatform used in the main thread of Node.js. // If NODE_USE_V8_PLATFORM has not been defined when Node.js was built, // it returns nullptr. diff --git a/src/node_internals.h b/src/node_internals.h index 25d279e615109b..fd0b14b0284532 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -104,10 +104,6 @@ std::string GetHumanReadableProcessName(); void InitializeContextRuntime(v8::Local); bool InitializePrimordials(v8::Local context); -namespace task_queue { -void PromiseRejectCallback(v8::PromiseRejectMessage message); -} // namespace task_queue - class NodeArrayBufferAllocator : public ArrayBufferAllocator { public: inline uint32_t* zero_fill_field() { return &zero_fill_field_; } diff --git a/src/node_task_queue.cc b/src/node_task_queue.cc index 3c7d9bae0884c5..b55a2a4387d655 100644 --- a/src/node_task_queue.cc +++ b/src/node_task_queue.cc @@ -28,27 +28,6 @@ using v8::PromiseRejectEvent; using v8::PromiseRejectMessage; using v8::Value; -namespace task_queue { - -static void EnqueueMicrotask(const FunctionCallbackInfo& args) { - Environment* env = Environment::GetCurrent(args); - Isolate* isolate = env->isolate(); - - CHECK(args[0]->IsFunction()); - - isolate->EnqueueMicrotask(args[0].As()); -} - -static void RunMicrotasks(const FunctionCallbackInfo& args) { - MicrotasksScope::PerformCheckpoint(args.GetIsolate()); -} - -static void SetTickCallback(const FunctionCallbackInfo& args) { - Environment* env = Environment::GetCurrent(args); - CHECK(args[0]->IsFunction()); - env->set_tick_callback_function(args[0].As()); -} - void PromiseRejectCallback(PromiseRejectMessage message) { static std::atomic unhandledRejections{0}; static std::atomic rejectionsHandledAfter{0}; @@ -108,6 +87,26 @@ void PromiseRejectCallback(PromiseRejectMessage message) { PrintCaughtException(isolate, env->context(), try_catch); } } +namespace task_queue { + +static void EnqueueMicrotask(const FunctionCallbackInfo& args) { + Environment* env = Environment::GetCurrent(args); + Isolate* isolate = env->isolate(); + + CHECK(args[0]->IsFunction()); + + isolate->EnqueueMicrotask(args[0].As()); +} + +static void RunMicrotasks(const FunctionCallbackInfo& args) { + MicrotasksScope::PerformCheckpoint(args.GetIsolate()); +} + +static void SetTickCallback(const FunctionCallbackInfo& args) { + Environment* env = Environment::GetCurrent(args); + CHECK(args[0]->IsFunction()); + env->set_tick_callback_function(args[0].As()); +} static void SetPromiseRejectCallback( const FunctionCallbackInfo& args) {