Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
node-sass
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
楚学文
node-sass
Commits
8420fd9d
Commit
8420fd9d
authored
Aug 19, 2015
by
Marcin Cieslak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add comments to indicate V8 context
parent
f129ff39
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
10 deletions
+51
-10
callback_bridge.h
src/callback_bridge.h
+51
-10
No files found.
src/callback_bridge.h
View file @
8420fd9d
...
@@ -55,7 +55,10 @@ Nan::Persistent<v8::Function> CallbackBridge<T, L>::wrapper_constructor;
...
@@ -55,7 +55,10 @@ Nan::Persistent<v8::Function> CallbackBridge<T, L>::wrapper_constructor;
template
<
typename
T
,
typename
L
>
template
<
typename
T
,
typename
L
>
CallbackBridge
<
T
,
L
>::
CallbackBridge
(
Nan
::
Callback
*
callback
,
bool
is_sync
)
:
callback
(
callback
),
is_sync
(
is_sync
)
{
CallbackBridge
<
T
,
L
>::
CallbackBridge
(
Nan
::
Callback
*
callback
,
bool
is_sync
)
:
callback
(
callback
),
is_sync
(
is_sync
)
{
// This assumes the main thread will be the one instantiating the bridge
/*
* This is invoked from the main JavaScript thread.
* V8 context is available.
*/
if
(
!
is_sync
)
{
if
(
!
is_sync
)
{
this
->
async
=
new
uv_async_t
;
this
->
async
=
new
uv_async_t
;
this
->
async
->
data
=
(
void
*
)
this
;
this
->
async
->
data
=
(
void
*
)
this
;
...
@@ -81,6 +84,14 @@ template <typename T, typename L>
...
@@ -81,6 +84,14 @@ template <typename T, typename L>
T
CallbackBridge
<
T
,
L
>::
operator
()(
std
::
vector
<
void
*>
argv
)
{
T
CallbackBridge
<
T
,
L
>::
operator
()(
std
::
vector
<
void
*>
argv
)
{
// argv.push_back(wrapper);
// argv.push_back(wrapper);
if
(
this
->
is_sync
)
{
if
(
this
->
is_sync
)
{
/*
* This is invoked from the main JavaScript thread.
* V8 context is available.
*
* Establish Local<> scope for all functions
* from types invoked by pre_process_args() and
* post_process_args().
*/
Nan
::
HandleScope
scope
;
Nan
::
HandleScope
scope
;
std
::
vector
<
v8
::
Local
<
v8
::
Value
>>
argv_v8
=
pre_process_args
(
argv
);
std
::
vector
<
v8
::
Local
<
v8
::
Value
>>
argv_v8
=
pre_process_args
(
argv
);
argv_v8
.
push_back
(
Nan
::
New
(
wrapper
));
argv_v8
.
push_back
(
Nan
::
New
(
wrapper
));
...
@@ -88,22 +99,45 @@ T CallbackBridge<T, L>::operator()(std::vector<void*> argv) {
...
@@ -88,22 +99,45 @@ T CallbackBridge<T, L>::operator()(std::vector<void*> argv) {
return
this
->
post_process_return_value
(
return
this
->
post_process_return_value
(
this
->
callback
->
Call
(
argv_v8
.
size
(),
&
argv_v8
[
0
])
this
->
callback
->
Call
(
argv_v8
.
size
(),
&
argv_v8
[
0
])
);
);
}
else
{
/*
* This is invoked from the worker thread.
* No V8 context and functions available.
* Just wait for response from asynchronously
* scheduled JavaScript code
*
* XXX Issue #1048: We block here even if the
* event loop stops and the callback
* would never be executed.
* XXX Issue #857: By waiting here we occupy
* one of the threads taken from the
* uv threadpool. Might deadlock if
* async I/O executed from JavaScript callbacks.
*/
this
->
argv
=
argv
;
std
::
unique_lock
<
std
::
mutex
>
lock
(
this
->
cv_mutex
);
this
->
has_returned
=
false
;
uv_async_send
(
this
->
async
);
this
->
condition_variable
.
wait
(
lock
,
[
this
]
{
return
this
->
has_returned
;
});
return
this
->
return_value
;
}
}
this
->
argv
=
argv
;
std
::
unique_lock
<
std
::
mutex
>
lock
(
this
->
cv_mutex
);
this
->
has_returned
=
false
;
uv_async_send
(
this
->
async
);
this
->
condition_variable
.
wait
(
lock
,
[
this
]
{
return
this
->
has_returned
;
});
return
this
->
return_value
;
}
}
template
<
typename
T
,
typename
L
>
template
<
typename
T
,
typename
L
>
void
CallbackBridge
<
T
,
L
>::
dispatched_async_uv_callback
(
uv_async_t
*
req
)
{
void
CallbackBridge
<
T
,
L
>::
dispatched_async_uv_callback
(
uv_async_t
*
req
)
{
CallbackBridge
*
bridge
=
static_cast
<
CallbackBridge
*>
(
req
->
data
);
CallbackBridge
*
bridge
=
static_cast
<
CallbackBridge
*>
(
req
->
data
);
/*
* Function scheduled via uv_async mechanism, therefore
* it is invoked from the main JavaScript thread.
* V8 context is available.
*
* Establish Local<> scope for all functions
* from types invoked by pre_process_args() and
* post_process_args().
*/
Nan
::
HandleScope
scope
;
Nan
::
HandleScope
scope
;
Nan
::
TryCatch
try_catch
;
Nan
::
TryCatch
try_catch
;
...
@@ -120,6 +154,13 @@ void CallbackBridge<T, L>::dispatched_async_uv_callback(uv_async_t *req) {
...
@@ -120,6 +154,13 @@ void CallbackBridge<T, L>::dispatched_async_uv_callback(uv_async_t *req) {
template
<
typename
T
,
typename
L
>
template
<
typename
T
,
typename
L
>
NAN_METHOD
(
CallbackBridge
<
T
COMMA
L
>::
ReturnCallback
)
{
NAN_METHOD
(
CallbackBridge
<
T
COMMA
L
>::
ReturnCallback
)
{
/*
* Callback function invoked by the user code.
* It is invoked from the main JavaScript thread.
* V8 context is available.
*
* Implicit Local<> handle scope created by NAN_METHOD(.)
*/
CallbackBridge
<
T
,
L
>*
bridge
=
static_cast
<
CallbackBridge
<
T
,
L
>*>
(
Nan
::
GetInternalFieldPointer
(
info
.
This
(),
0
));
CallbackBridge
<
T
,
L
>*
bridge
=
static_cast
<
CallbackBridge
<
T
,
L
>*>
(
Nan
::
GetInternalFieldPointer
(
info
.
This
(),
0
));
Nan
::
TryCatch
try_catch
;
Nan
::
TryCatch
try_catch
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment