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
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/internal/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.

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

FunctionCall: Function.prototype.call,
ObjectAssign: Object.assign,
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.

ArrayPrototype: Object.assign({}, Array.prototype)
};