-
-
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
Merged
+1,150
−676
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f365d33
feat(Global): Add `[ImplicitThis]` behaviour
ExE-Boss fdb0c75
fix: Use correct `[ImplicitThis]` behaviour
ExE-Boss 6d07394
fix: Add `globalObject` to scope of `_internalSetup`
ExE-Boss 1aed7f7
fix: Undefined `esValue` in attribute stringifiers
ExE-Boss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,19 +23,15 @@ class Attribute { | |
|
||
const onInstance = utils.isOnInstance(this.idl, this.interface.idl); | ||
|
||
let objName = `this`; | ||
if (onInstance) { // we're in a setup method | ||
objName = `obj`; | ||
} | ||
let brandCheck = ` | ||
if (!this || !exports.is(this)) { | ||
if (!exports.is(esValue)) { | ||
throw new TypeError("Illegal invocation"); | ||
} | ||
`; | ||
let getterBody = `return utils.tryWrapperForImpl(${objName}[impl]["${this.idl.name}"]);`; | ||
let setterBody = `${objName}[impl]["${this.idl.name}"] = V;`; | ||
let getterBody = `return utils.tryWrapperForImpl(esValue[impl]["${this.idl.name}"]);`; | ||
let setterBody = `esValue[impl]["${this.idl.name}"] = V;`; | ||
if (conversions[this.idl.idlType.idlType]) { | ||
getterBody = `return ${objName}[impl]["${this.idl.name}"];`; | ||
getterBody = `return esValue[impl]["${this.idl.name}"];`; | ||
} | ||
|
||
const addMethod = this.static ? | ||
|
@@ -51,8 +47,8 @@ class Attribute { | |
throw new Error("Unknown reflector type: " + this.idl.idlType.idlType); | ||
} | ||
const attrName = shouldReflect.rhs && shouldReflect.rhs.value.replace(/_/g, "-") || this.idl.name; | ||
getterBody = reflector[this.idl.idlType.idlType].get(objName, attrName.toLowerCase()); | ||
setterBody = reflector[this.idl.idlType.idlType].set(objName, attrName.toLowerCase()); | ||
getterBody = reflector[this.idl.idlType.idlType].get("esValue", attrName.toLowerCase()); | ||
setterBody = reflector[this.idl.idlType.idlType].set("esValue", attrName.toLowerCase()); | ||
} | ||
|
||
if (utils.getExtAttr(this.idl.extAttrs, "LenientThis")) { | ||
|
@@ -71,6 +67,7 @@ class Attribute { | |
} | ||
|
||
addMethod(this.idl.name, [], ` | ||
const esValue = this !== null && this !== undefined ? this : globalObject; | ||
${brandCheck} | ||
${getterBody} | ||
`, "get", { configurable }); | ||
|
@@ -95,19 +92,22 @@ class Attribute { | |
} | ||
|
||
addMethod(this.idl.name, ["V"], ` | ||
const esValue = this !== null && this !== undefined ? this : globalObject; | ||
${brandCheck} | ||
${idlConversion} | ||
${setterBody} | ||
`, "set", { configurable }); | ||
} else if (utils.getExtAttr(this.idl.extAttrs, "PutForwards")) { | ||
addMethod(this.idl.name, ["V"], ` | ||
const esValue = this !== null && this !== undefined ? this : globalObject; | ||
${brandCheck} | ||
this.${this.idl.name}.${utils.getExtAttr(this.idl.extAttrs, "PutForwards").rhs.value} = V; | ||
`, "set", { configurable }); | ||
} else if (utils.getExtAttr(this.idl.extAttrs, "Replaceable")) { | ||
addMethod(this.idl.name, ["V"], ` | ||
const esValue = this !== null && this !== undefined ? this : globalObject; | ||
${brandCheck} | ||
Object.defineProperty(this, "${this.idl.name}", { | ||
Object.defineProperty(esValue, "${this.idl.name}", { | ||
configurable: true, | ||
enumerable: true, | ||
value: V, | ||
|
@@ -118,10 +118,12 @@ class Attribute { | |
|
||
if (!this.static && this.idl.special === "stringifier") { | ||
addMethod("toString", [], ` | ||
if (!this || !exports.is(this)) { | ||
const esValue = this; | ||
Comment on lines
120
to
+121
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
if (!exports.is(esValue)) { | ||
throw new TypeError("Illegal invocation"); | ||
} | ||
${getterBody}; | ||
|
||
${getterBody} | ||
`, "regular", { configurable, writable: configurable }); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 toobj
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 casethis
will be whatever was passed tocall
as thethisArg
parameter.