Skip to content

Commit dec004f

Browse files
codebytereMylesBorins
authored andcommittedNov 16, 2020
src: expose v8::Isolate setup callbacks
PR-URL: #35512 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 5faaa60 commit dec004f

File tree

4 files changed

+37
-32
lines changed

4 files changed

+37
-32
lines changed
 

‎src/api/environment.cc

+7-7
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ using v8::PropertyDescriptor;
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>());
@@ -252,7 +252,7 @@ void SetIsolateMiscHandlers(v8::Isolate* isolate, const IsolateSettings& s) {
252252

253253
if ((s.flags & SHOULD_NOT_SET_PROMISE_REJECTION_CALLBACK) == 0) {
254254
auto* promise_reject_cb = s.promise_reject_callback ?
255-
s.promise_reject_callback : task_queue::PromiseRejectCallback;
255+
s.promise_reject_callback : PromiseRejectCallback;
256256
isolate->SetPromiseRejectCallback(promise_reject_cb);
257257
}
258258

‎src/node.h

+10
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,16 @@ NODE_EXTERN void DefaultProcessExitHandler(Environment* env, int exit_code);
479479
// This may return nullptr if context is not associated with a Node instance.
480480
NODE_EXTERN Environment* GetCurrentEnvironment(v8::Local<v8::Context> context);
481481

482+
NODE_EXTERN void OnFatalError(const char* location, const char* message);
483+
NODE_EXTERN void PromiseRejectCallback(v8::PromiseRejectMessage message);
484+
NODE_EXTERN bool AllowWasmCodeGenerationCallback(v8::Local<v8::Context> context,
485+
v8::Local<v8::String>);
486+
NODE_EXTERN bool ShouldAbortOnUncaughtException(v8::Isolate* isolate);
487+
NODE_EXTERN v8::MaybeLocal<v8::Value> PrepareStackTraceCallback(
488+
v8::Local<v8::Context> context,
489+
v8::Local<v8::Value> exception,
490+
v8::Local<v8::Array> trace);
491+
482492
// This returns the MultiIsolatePlatform used in the main thread of Node.js.
483493
// If NODE_USE_V8_PLATFORM has not been defined when Node.js was built,
484494
// it returns nullptr.

‎src/node_internals.h

-4
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,6 @@ std::string GetHumanReadableProcessName();
104104
void InitializeContextRuntime(v8::Local<v8::Context>);
105105
bool InitializePrimordials(v8::Local<v8::Context> context);
106106

107-
namespace task_queue {
108-
void PromiseRejectCallback(v8::PromiseRejectMessage message);
109-
} // namespace task_queue
110-
111107
class NodeArrayBufferAllocator : public ArrayBufferAllocator {
112108
public:
113109
inline uint32_t* zero_fill_field() { return &zero_fill_field_; }

‎src/node_task_queue.cc

+20-21
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,6 @@ using v8::PromiseRejectEvent;
2828
using v8::PromiseRejectMessage;
2929
using v8::Value;
3030

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

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

0 commit comments

Comments
 (0)
Please sign in to comment.