From c966a224aefdc6c6490964f171dcf1e81e77931d Mon Sep 17 00:00:00 2001 From: RedYetiDev <38299977+RedYetiDev@users.noreply.github.com> Date: Fri, 20 Sep 2024 17:58:36 -0400 Subject: [PATCH] domain: eol deprecate `MakeCallback` with `domain` property --- doc/api/deprecations.md | 5 ++- lib/domain.js | 17 -------- .../make-callback-domain-warning/binding.cc | 32 -------------- .../make-callback-domain-warning/binding.gyp | 9 ---- .../make-callback-domain-warning/test.js | 43 ------------------- 5 files changed, 4 insertions(+), 102 deletions(-) delete mode 100644 test/addons/make-callback-domain-warning/binding.cc delete mode 100644 test/addons/make-callback-domain-warning/binding.gyp delete mode 100644 test/addons/make-callback-domain-warning/test.js diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index f10265b9ddd98a..5a6d17d92c3ce2 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -2087,12 +2087,15 @@ Type: Runtime -Type: Runtime +Type: End-of-Life Users of `MakeCallback` that add the `domain` property to carry context, should start using the `async_context` variant of `MakeCallback` or diff --git a/lib/domain.js b/lib/domain.js index 03d240e98d4506..564e285df075cc 100644 --- a/lib/domain.js +++ b/lib/domain.js @@ -136,25 +136,8 @@ process.setUncaughtExceptionCaptureCallback = function(fn) { throw err; }; - -let sendMakeCallbackDeprecation = false; -function emitMakeCallbackDeprecation({ target, method }) { - if (!sendMakeCallbackDeprecation) { - process.emitWarning( - 'Using a domain property in MakeCallback is deprecated. Use the ' + - 'async_context variant of MakeCallback or the AsyncResource class ' + - 'instead. ' + - `(Triggered by calling ${method?.name || ''} ` + - `on ${target?.constructor?.name}.)`, - 'DeprecationWarning', 'DEP0097'); - sendMakeCallbackDeprecation = true; - } -} - function topLevelDomainCallback(cb, ...args) { const domain = this.domain; - if (exports.active && domain) - emitMakeCallbackDeprecation({ target: this, method: cb }); if (domain) domain.enter(); diff --git a/test/addons/make-callback-domain-warning/binding.cc b/test/addons/make-callback-domain-warning/binding.cc deleted file mode 100644 index d02c8f517661eb..00000000000000 --- a/test/addons/make-callback-domain-warning/binding.cc +++ /dev/null @@ -1,32 +0,0 @@ -#include "node.h" -#include "v8.h" - -#include - -using v8::Function; -using v8::FunctionCallbackInfo; -using v8::Isolate; -using v8::Local; -using v8::Object; -using v8::Value; - -namespace { - -void MakeCallback(const FunctionCallbackInfo& args) { - assert(args[0]->IsObject()); - assert(args[1]->IsFunction()); - Isolate* isolate = args.GetIsolate(); - Local recv = args[0].As(); - Local method = args[1].As(); - - node::MakeCallback(isolate, recv, method, 0, nullptr, - node::async_context{0, 0}); -} - -void Initialize(Local exports) { - NODE_SET_METHOD(exports, "makeCallback", MakeCallback); -} - -} // namespace - -NODE_MODULE(NODE_GYP_MODULE_NAME, Initialize) diff --git a/test/addons/make-callback-domain-warning/binding.gyp b/test/addons/make-callback-domain-warning/binding.gyp deleted file mode 100644 index 55fbe7050f18e4..00000000000000 --- a/test/addons/make-callback-domain-warning/binding.gyp +++ /dev/null @@ -1,9 +0,0 @@ -{ - 'targets': [ - { - 'target_name': 'binding', - 'sources': [ 'binding.cc' ], - 'includes': ['../common.gypi'], - } - ] -} diff --git a/test/addons/make-callback-domain-warning/test.js b/test/addons/make-callback-domain-warning/test.js deleted file mode 100644 index e6eaa9d337c179..00000000000000 --- a/test/addons/make-callback-domain-warning/test.js +++ /dev/null @@ -1,43 +0,0 @@ -'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, function someMethod() { setImmediate(cb); }); -} - -let latestWarning = null; -process.on('warning', (warning) => { - latestWarning = warning; -}); - -const d = domain.create(); - -class Resource { - constructor(domain) { - this.domain = domain; - } -} - -// When domain is disabled, no warning will be emitted -makeCallback(new Resource(d), common.mustCall(() => { - assert.strictEqual(latestWarning, null); - - d.run(common.mustCall(() => { - // No warning will be emitted when no domain property is applied - makeCallback({}, common.mustCall(() => { - assert.strictEqual(latestWarning, null); - - // Warning is emitted when domain property is used and domain is enabled - makeCallback(new Resource(d), common.mustCall(() => { - assert.match(latestWarning.message, - /Triggered by calling someMethod on Resource\./); - assert.strictEqual(latestWarning.name, 'DeprecationWarning'); - assert.strictEqual(latestWarning.code, 'DEP0097'); - })); - })); - })); -}));