-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
modules: add setter for module.parent #35522
Conversation
Review requested:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM pending lint
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the CITGM results that have completed this has fixed the node-gyp test suite, thanks.
137222b
to
80384e8
Compare
This comment has been minimized.
This comment has been minimized.
BTW, this should have the label |
This comment has been minimized.
This comment has been minimized.
My only issue with converting |
'module.parent is deprecated due to accuracy issues. Please use ' + | ||
'require.main to find program entry point instead.', | ||
'DEP0144' | ||
) : setModuleParent, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make delete work:
) : setModuleParent, | |
) : setModuleParent, | |
configurable: true, |
@ExE-Boss making the property configurable should make delete work. |
'DEP0144' | ||
); | ||
|
||
module.parent = undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
module.parent = undefined; | |
module.parent = undefined; | |
delete module.parent; | |
assert.strictEqual('parent' in module, false); |
// Flags: --pending-deprecation | ||
|
||
'use strict'; | ||
const common = require('../common'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const common = require('../common'); | |
const common = require('../common'); | |
const assert = require('assert'); |
function setModuleParent(value) { | ||
moduleParentCache.set(this, value); | ||
} | ||
|
||
ObjectDefineProperty(Module.prototype, 'parent', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moving this to be on the module itself is needed to make delete
work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't that trigger a new deprecation warning for each Module
instance?
module.parent; // triggers one warning
module.parent?.parent; // triggers another warning?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, because the deprecation uses a deprecation code:
Lines 77 to 82 in ce84bac
if (code !== undefined) { | |
if (!codesWarned.has(code)) { | |
process.emitWarning(msg, 'DeprecationWarning', code, deprecated); | |
codesWarned.add(code); | |
} | |
} else { |
@ExE-Boss Would it be fine for you if we land this PR as is, and then someone else (maybe you?) opens another PR with the changes you're suggesting? I'm afraid I don't have the bandwidth to work on this currently, and I wouldn't want it to miss the v15.x release. |
@aduh95 I don’t mind either way. |
PR-URL: nodejs#35522 Reviewed-By: Jan Krems <jan.krems@gmail.com> Reviewed-By: Bradley Farias <bradley.meck@gmail.com> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Ujjwal Sharma <ryzokuken@disroot.org> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
80384e8
to
aaf225a
Compare
Landed in aaf225a |
module.parent
breaks the ecosystem when read-only (see #32217 (comment)). This PR adds a setter to allow user to change its value instead of throwing.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes