Skip to content
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

lib: save a reference to intrinsic constructs #12981

Closed
wants to merge 1 commit into from

Conversation

refack
Copy link
Contributor

@refack refack commented May 11, 2017

Take a snapshot of some intrinsic constructs, so we can use them when we need to protect against userland monkey patching.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

lib

@nodejs-github-bot nodejs-github-bot added the util Issues and PRs related to the built-in util module. label May 11, 2017
@refack refack added the lib / src Issues and PRs related to general changes in the lib or src directory. label May 11, 2017
@refack refack requested review from addaleax and cjihrig May 11, 2017 18:26
@refack refack self-assigned this May 11, 2017
@Trott
Copy link
Member

Trott commented May 11, 2017

Not sure what I think of this just yet, but my immediate reaction is that I'd rather we add things as needed rather than try to add a bunch of stuff up front that we're not currently using and might never use.

@Trott
Copy link
Member

Trott commented May 11, 2017

Oh, also, this definitely needs tests.

Copy link
Member

@Trott Trott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs tests.

@refack
Copy link
Contributor Author

refack commented May 11, 2017

Oh, also, this definitely needs tests.

Ack. Just need to figure out how to test it...

@mscdex
Copy link
Contributor

mscdex commented May 11, 2017

I agree we should only add them as needed.

@TimothyGu
Copy link
Member

I mentioned snapshotting all intrinsics as a reductio-ad-absurdum argument against saving references to intrinsics, as it seemed to be something impractical to do…

Copy link
Member

@TimothyGu TimothyGu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the naming of these properties, the ES spec provides a definitive list of well-known intrinsic objects.

@@ -278,3 +278,14 @@ promisify.custom = kCustomPromisifiedSymbol;

exports.promisify = promisify;
exports.customPromisifyArgs = kCustomPromisifyArgsSymbol;

exports.intrinsic = {
FunctionApply: Function.prototype.apply,
Copy link
Member

@TimothyGu TimothyGu May 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized: it's impossible to actually save a pristine and usable Function.prototype.apply method in JS, since one can just change Function.prototype.apply.call and Function.prototype.apply.apply… That's probably why V8 Extras supply an uncurryThis() function.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reflect.apply is the correct answer to this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right.

ObjectSetPrototypeOf: Object.setPrototypeOf,
Object: Object,
Array: Array,
ObjectPrototype: Object.assign({}, Object.prototype),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather save the prototype methods individually, and set ObjectPrototype to the initial Object.prototype.

@@ -278,3 +278,14 @@ promisify.custom = kCustomPromisifiedSymbol;

exports.promisify = promisify;
exports.customPromisifyArgs = kCustomPromisifyArgsSymbol;

exports.intrinsic = {
FunctionApply: Function.prototype.apply,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly I just realized that util.promisify did not follow the module.exports = {} pattern and should be updated. For new exports from this module, can you use the module.exports = {} above rather than the exports.whatever = ... model?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack.
Ref: #12712

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll be opening a pr to fix up the promisify export, btw

@refack refack force-pushed the save-call-apply branch 2 times, most recently from 806c286 to 3963e0f Compare May 16, 2017 19:29
@BridgeAR
Copy link
Member

It seems like a majority thinks that these things should only be added when needed. @refack I guess this should be closed therefore?

@daurnimator
Copy link

This PR should probably be closed; a better solution (if we decide we actually want this) is to expose them using the names from https://tc39.github.io/ecma262/#sec-well-known-intrinsic-objects

@jasnell
Copy link
Member

jasnell commented Aug 29, 2017

+1 to closing this. @refack we can revisit if necessary

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lib / src Issues and PRs related to general changes in the lib or src directory. util Issues and PRs related to the built-in util module.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants