Skip to content

Commit 6232833

Browse files
committed
add nw_enter_dom and nw_leave_dom hook
1 parent bcca8fa commit 6232833

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/node.cc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5048,6 +5048,28 @@ NODE_EXTERN void g_uv_init_nw(int worker) {
50485048
void UvNoOp(uv_async_t* handle) {
50495049
}
50505050

5051+
NODE_EXTERN bool g_nw_enter_dom() {
5052+
thread_ctx_st* tls_ctx = (struct thread_ctx_st*)uv_key_get(&thread_ctx_key);
5053+
if (tls_ctx && tls_ctx->env) {
5054+
v8::Isolate* isolate = tls_ctx->env->isolate();
5055+
v8::HandleScope handleScope(isolate);
5056+
v8::Local<v8::Context> context = isolate->GetEnteredContext();
5057+
if (context == tls_ctx->env->context())
5058+
context->Exit();
5059+
return true;
5060+
}
5061+
return false;
5062+
}
5063+
5064+
NODE_EXTERN void g_nw_leave_dom(bool reenter) {
5065+
thread_ctx_st* tls_ctx = (struct thread_ctx_st*)uv_key_get(&thread_ctx_key);
5066+
if (reenter && tls_ctx && tls_ctx->env) {
5067+
v8::Isolate* isolate = tls_ctx->env->isolate();
5068+
v8::HandleScope handleScope(isolate);
5069+
tls_ctx->env->context()->Enter();
5070+
}
5071+
}
5072+
50515073
NODE_EXTERN void g_msg_pump_ctor_osx(msg_pump_context_t* ctx, void* EmbedThreadRunner, void* kevent_hook, void* data, int worker_support) {
50525074
uv_init_nw(worker_support);
50535075
g_worker_support = worker_support;

src/node_webkit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,7 @@ typedef void (*VoidVoidFn)();
4747
typedef int (*IntVoidFn)();
4848
typedef void (*VoidIntFn)(int);
4949
typedef bool (*BoolPtrFn)(void*);
50+
typedef bool (*BoolVoidFn)();
51+
typedef void (*VoidBoolFn)(bool);
5052

5153
#endif

0 commit comments

Comments
 (0)