Skip to content

Commit 93f947a

Browse files
codebytereBethGriggs
authored andcommittedOct 13, 2020
src: expose v8::Isolate setup callbacks
PR-URL: #35512 Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Juan José Arboleda <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 2f13199 commit 93f947a

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
@@ -30,14 +30,14 @@ using v8::PropertyDescriptor;
3030
using v8::String;
3131
using v8::Value;
3232

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

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

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

243243
if ((s.flags & SHOULD_NOT_SET_PROMISE_REJECTION_CALLBACK) == 0) {
244244
auto* promise_reject_cb = s.promise_reject_callback ?
245-
s.promise_reject_callback : task_queue::PromiseRejectCallback;
245+
s.promise_reject_callback : PromiseRejectCallback;
246246
isolate->SetPromiseRejectCallback(promise_reject_cb);
247247
}
248248

‎src/node.h

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

503+
NODE_EXTERN void OnFatalError(const char* location, const char* message);
504+
NODE_EXTERN void PromiseRejectCallback(v8::PromiseRejectMessage message);
505+
NODE_EXTERN bool AllowWasmCodeGenerationCallback(v8::Local<v8::Context> context,
506+
v8::Local<v8::String>);
507+
NODE_EXTERN bool ShouldAbortOnUncaughtException(v8::Isolate* isolate);
508+
NODE_EXTERN v8::MaybeLocal<v8::Value> PrepareStackTraceCallback(
509+
v8::Local<v8::Context> context,
510+
v8::Local<v8::Value> exception,
511+
v8::Local<v8::Array> trace);
512+
503513
// This returns the MultiIsolatePlatform used in the main thread of Node.js.
504514
// If NODE_USE_V8_PLATFORM has not been defined when Node.js was built,
505515
// it returns nullptr.

‎src/node_internals.h

-4
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

+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.