Skip to content

Commit

Permalink
add nw_enter_dom and nw_leave_dom hook
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerwang committed Dec 11, 2016
1 parent 9b3d912 commit c720fd6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5068,6 +5068,29 @@ NODE_EXTERN void g_uv_init_nw(int worker) {
void UvNoOp(uv_async_t* handle) {
}

NODE_EXTERN bool g_nw_enter_dom() {
thread_ctx_st* tls_ctx = (struct thread_ctx_st*)uv_key_get(&thread_ctx_key);
if (tls_ctx && tls_ctx->env) {
v8::Isolate* isolate = tls_ctx->env->isolate();
v8::HandleScope handleScope(isolate);
v8::Local<v8::Context> context = isolate->GetEnteredContext();
if (context == tls_ctx->env->context()) {
context->Exit();
return true;
}
}
return false;
}

NODE_EXTERN void g_nw_leave_dom(bool reenter) {
thread_ctx_st* tls_ctx = (struct thread_ctx_st*)uv_key_get(&thread_ctx_key);
if (reenter && tls_ctx && tls_ctx->env) {
v8::Isolate* isolate = tls_ctx->env->isolate();
v8::HandleScope handleScope(isolate);
tls_ctx->env->context()->Enter();
}
}

NODE_EXTERN void g_msg_pump_ctor_osx(msg_pump_context_t* ctx, void* EmbedThreadRunner, void* kevent_hook, void* data, int worker_support) {
uv_init_nw(worker_support);
g_worker_support = worker_support;
Expand Down
2 changes: 2 additions & 0 deletions src/node_webkit.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,7 @@ typedef void (*VoidVoidFn)();
typedef int (*IntVoidFn)();
typedef void (*VoidIntFn)(int);
typedef bool (*BoolPtrFn)(void*);
typedef bool (*BoolVoidFn)();
typedef void (*VoidBoolFn)(bool);

#endif

0 comments on commit c720fd6

Please sign in to comment.