forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
domain: runtime deprecate MakeCallback
Users of MakeCallback that adds the domain property to carry context, should start using the async_context variant of MakeCallback or the AsyncResource class. PR-URL: nodejs#17417 Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
- Loading branch information
1 parent
a46da78
commit f945de3
Showing
5 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include "node.h" | ||
#include "v8.h" | ||
|
||
#include <assert.h> | ||
|
||
using v8::Function; | ||
using v8::FunctionCallbackInfo; | ||
using v8::Isolate; | ||
using v8::Local; | ||
using v8::Object; | ||
using v8::Value; | ||
|
||
namespace { | ||
|
||
void MakeCallback(const FunctionCallbackInfo<Value>& args) { | ||
assert(args[0]->IsObject()); | ||
assert(args[1]->IsFunction()); | ||
Isolate* isolate = args.GetIsolate(); | ||
Local<Object> recv = args[0].As<Object>(); | ||
Local<Function> method = args[1].As<Function>(); | ||
|
||
node::MakeCallback(isolate, recv, method, 0, nullptr); | ||
} | ||
|
||
void Initialize(Local<Object> exports) { | ||
NODE_SET_METHOD(exports, "makeCallback", MakeCallback); | ||
} | ||
|
||
} // namespace | ||
|
||
NODE_MODULE(NODE_GYP_MODULE_NAME, Initialize) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
'targets': [ | ||
{ | ||
'target_name': 'binding', | ||
'defines': [ 'V8_DEPRECATION_WARNINGS=1' ], | ||
'sources': [ 'binding.cc' ] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict'; | ||
|
||
const common = require('../../common'); | ||
const assert = require('assert'); | ||
const domain = require('domain'); | ||
const binding = require(`./build/${common.buildType}/binding`); | ||
|
||
function makeCallback(object, cb) { | ||
binding.makeCallback(object, () => setImmediate(cb)); | ||
} | ||
|
||
let latestWarning = null; | ||
process.on('warning', function(warning) { | ||
latestWarning = warning; | ||
}); | ||
|
||
const d = domain.create(); | ||
|
||
// When domain is disabled, no warning will be emitted | ||
makeCallback({ domain: d }, common.mustCall(function() { | ||
assert.strictEqual(latestWarning, null); | ||
|
||
d.run(common.mustCall(function() { | ||
// No warning will be emitted when no domain property is applied | ||
makeCallback({}, common.mustCall(function() { | ||
assert.strictEqual(latestWarning, null); | ||
|
||
// Warning is emitted when domain property is used and domain is enabled | ||
makeCallback({ domain: d }, common.mustCall(function() { | ||
assert.strictEqual(latestWarning.name, 'DeprecationWarning'); | ||
assert.strictEqual(latestWarning.code, 'DEP0097'); | ||
})); | ||
})); | ||
})); | ||
})); |