Skip to content

Commit

Permalink
src: deprecate legacy node::MakeCallback
Browse files Browse the repository at this point in the history
The legacy MakeCallback functions do not provide a mechanism to
propagate async context. This means that any native modules using these
directly is likely breaking async debugging & tracing tools. For
example it is possible that such a module will cause incorrect async
stack traces to be reported (even when the module is not on the stack).

The new MakeCallback allow the user to specify the async context in
which the callback is to be executed.

Ref: nodejs#13254
PR-URL: nodejs#18632
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
Reviewed-By: Jan Krems <[email protected]>
Reviewed-By: Andreas Madsen <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Gibson Fahnestock <[email protected]>
  • Loading branch information
ofrobots committed Feb 16, 2018
1 parent 3b9cc42 commit efb3259
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
9 changes: 9 additions & 0 deletions doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,15 @@ Use [`asyncResource.runInAsyncScope()`][] API instead which provides a much
safer, and more convenient, alternative. See
https://github.com/nodejs/node/pull/18513 for more details.
<a id="DEP0098"></a>
### DEP0098: async context-unaware node::MakeCallback C++ APIs
Type: Compile-time
Certain versions of `node::MakeCallback` APIs available to native modules are
deprecated. Please use the versions of the API that accept an `async_context`
parameter.
[`--pending-deprecation`]: cli.html#cli_pending_deprecation
[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size
[`Buffer.from(array)`]: buffer.html#buffer_class_method_buffer_from_array
Expand Down
41 changes: 22 additions & 19 deletions src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,27 +151,30 @@ inline v8::Local<v8::Value> UVException(int errorno,
* These methods need to be called in a HandleScope.
*
* It is preferred that you use the `MakeCallback` overloads taking
* `async_id` arguments.
* `async_context` arguments.
*/

NODE_EXTERN v8::Local<v8::Value> MakeCallback(
v8::Isolate* isolate,
v8::Local<v8::Object> recv,
const char* method,
int argc,
v8::Local<v8::Value>* argv);
NODE_EXTERN v8::Local<v8::Value> MakeCallback(
v8::Isolate* isolate,
v8::Local<v8::Object> recv,
v8::Local<v8::String> symbol,
int argc,
v8::Local<v8::Value>* argv);
NODE_EXTERN v8::Local<v8::Value> MakeCallback(
v8::Isolate* isolate,
v8::Local<v8::Object> recv,
v8::Local<v8::Function> callback,
int argc,
v8::Local<v8::Value>* argv);
NODE_DEPRECATED("Use MakeCallback(..., async_context)",
NODE_EXTERN v8::Local<v8::Value> MakeCallback(
v8::Isolate* isolate,
v8::Local<v8::Object> recv,
const char* method,
int argc,
v8::Local<v8::Value>* argv));
NODE_DEPRECATED("Use MakeCallback(..., async_context)",
NODE_EXTERN v8::Local<v8::Value> MakeCallback(
v8::Isolate* isolate,
v8::Local<v8::Object> recv,
v8::Local<v8::String> symbol,
int argc,
v8::Local<v8::Value>* argv));
NODE_DEPRECATED("Use MakeCallback(..., async_context)",
NODE_EXTERN v8::Local<v8::Value> MakeCallback(
v8::Isolate* isolate,
v8::Local<v8::Object> recv,
v8::Local<v8::Function> callback,
int argc,
v8::Local<v8::Value>* argv));

} // namespace node

Expand Down

0 comments on commit efb3259

Please sign in to comment.