-
-
Notifications
You must be signed in to change notification settings - Fork 30
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
fix: Add [ImplicitThis]
behaviour
#166
Conversation
b8ee8ef
to
fdb0c75
Compare
778968e
to
1aed7f7
Compare
[ImplicitThis]
behaviour[ImplicitThis]
behaviour
I think this phrasing is confusing since there is no extended attribute [ImplicitThis].
This is not correct, right? I.e. merging this would not fix that bug. As for the approach, I wish there were a way to generate this only for the cases where it matters, i.e. functions on the prototype chain of the global object. From what I understand that's more of how browser implementations do it. But this works I guess, and the generated code isn't too heavyweight. And there is some value in following the spec as close as possible. So I'm inclined to go with this approach, although it'd be good to get other maintainers' thoughts. |
This is how whatwg/webidl#155 is specified to behave. Case in point: https://heycam.github.io/webidl/#dfn-create-operation-function |
Yes, as I said above,
|
Right, I somehow missed the paragraph after the horizontal line. As for jsdom/jsdom#2830, that will be fully fixed once this is released and jsdom/jsdom#2835 is merged. |
I guess we should be sure not to merge this until Window.js has appropriate brand checks on all its methods; otherwise it would be a regression. |
Wait, no, that's wrong, I was confused. Is there any reason to hold off on merging this? I guess maybe because it adds to the output code size slightly for no observable gain at this point... |
It removes the need to use the ///// METHODS for [ImplicitThis] hack
// See https://lists.w3.org/Archives/Public/public-script-coord/2015JanMar/0109.html
this.addEventListener = this.addEventListener.bind(this);
this.removeEventListener = this.removeEventListener.bind(this);
this.dispatchEvent = this.dispatchEvent.bind(this); |
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.
Looks good. One question.
let objName = `this`; | ||
if (onInstance) { // we're in a setup method | ||
objName = `obj`; | ||
} |
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.
Can you tell me if my understanding is correct: this isn't needed because for unforgeable methods/properties this
always points to obj
anyway?
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.
Well, yes, unless you were to use unforgeableMethod.call
, in which case this
will be whatever was passed to call
as the thisArg
parameter.
addMethod("toString", [], ` | ||
if (!this || !exports.is(this)) { | ||
const esValue = this; |
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.
This is correct per spec: https://heycam.github.io/webidl/#es-stringifier, whatwg/webidl#855.
This implements the
[ImplicitThis]
behaviour present on all WebIDL attributes and operations.Needed for jsdom/jsdom#2835
Will allow fixing jsdom/jsdom#2830
See whatwg/webidl#155 for details.