Skip to content

Commit 9fdd90a

Browse files
committed
add nw_enter_dom and nw_leave_dom hook
1 parent a935600 commit 9fdd90a

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

src/node.cc

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

5055+
NODE_EXTERN bool g_nw_enter_dom() {
5056+
thread_ctx_st* tls_ctx = (struct thread_ctx_st*)uv_key_get(&thread_ctx_key);
5057+
if (tls_ctx && tls_ctx->env) {
5058+
v8::Isolate* isolate = tls_ctx->env->isolate();
5059+
v8::HandleScope handleScope(isolate);
5060+
v8::Local<v8::Context> context = isolate->GetEnteredContext();
5061+
if (context == tls_ctx->env->context())
5062+
context->Exit();
5063+
return true;
5064+
}
5065+
return false;
5066+
}
5067+
5068+
NODE_EXTERN void g_nw_leave_dom(bool reenter) {
5069+
thread_ctx_st* tls_ctx = (struct thread_ctx_st*)uv_key_get(&thread_ctx_key);
5070+
if (reenter && tls_ctx && tls_ctx->env) {
5071+
v8::Isolate* isolate = tls_ctx->env->isolate();
5072+
v8::HandleScope handleScope(isolate);
5073+
tls_ctx->env->context()->Enter();
5074+
}
5075+
}
5076+
50555077
NODE_EXTERN void g_msg_pump_ctor_osx(msg_pump_context_t* ctx, void* EmbedThreadRunner, void* kevent_hook, void* data, int worker_support) {
50565078
uv_init_nw(worker_support);
50575079
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)