-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Test new Web IDL class string behavior #23140
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
"use strict"; | ||
|
||
test(() => { | ||
assert_own_property(Blob.prototype, Symbol.toStringTag); | ||
|
||
const propDesc = Object.getOwnPropertyDescriptor(Blob.prototype, Symbol.toStringTag); | ||
assert_equals(propDesc.value, "Blob", "value"); | ||
assert_equals(propDesc.configurable, true, "configurable"); | ||
assert_equals(propDesc.enumerable, false, "enumerable"); | ||
assert_equals(propDesc.writable, false, "writable"); | ||
}, "@@toStringTag exists on the prototype with the appropriate descriptor"); | ||
|
||
test(() => { | ||
assert_not_own_property(new Blob(), Symbol.toStringTag); | ||
}, "@@toStringTag must not exist on the instance"); | ||
|
||
test(() => { | ||
assert_equals(Object.prototype.toString.call(Blob.prototype), "[object Blob]"); | ||
}, "Object.prototype.toString applied to the prototype"); | ||
|
||
test(() => { | ||
assert_equals(Object.prototype.toString.call(new Blob()), "[object Blob]"); | ||
}, "Object.prototype.toString applied to an instance"); | ||
|
||
test(t => { | ||
assert_own_property(Blob.prototype, Symbol.toStringTag, "Precondition for this test: @@toStringTag on the prototype"); | ||
|
||
t.add_cleanup(() => { | ||
Object.defineProperty(Blob.prototype, Symbol.toStringTag, { value: "Blob" }); | ||
}); | ||
|
||
Object.defineProperty(Blob.prototype, Symbol.toStringTag, { value: "NotABlob" }); | ||
assert_equals(Object.prototype.toString.call(Blob.prototype), "[object NotABlob]", "prototype"); | ||
assert_equals(Object.prototype.toString.call(new Blob()), "[object NotABlob]", "instance"); | ||
}, "Object.prototype.toString applied after modifying the prototype's @@toStringTag"); | ||
|
||
test(t => { | ||
const instance = new Blob(); | ||
assert_not_own_property(instance, Symbol.toStringTag, "Precondition for this test: no @@toStringTag on the instance"); | ||
|
||
Object.defineProperty(instance, Symbol.toStringTag, { value: "NotABlob" }); | ||
assert_equals(Object.prototype.toString.call(instance), "[object NotABlob]"); | ||
}, "Object.prototype.toString applied to the instance after modifying the instance's @@toStringTag"); | ||
|
||
// Chrome had a bug (https://bugs.chromium.org/p/chromium/issues/detail?id=793406) where if there | ||
// was no @@toStringTag in the prototype, it would fall back to a magic class string. This tests | ||
// that the bug is fixed. | ||
|
||
test(() => { | ||
const instance = new Blob(); | ||
Object.setPrototypeOf(instance, null); | ||
|
||
assert_equals(Object.prototype.toString.call(instance), "[object Object]"); | ||
}, "Object.prototype.toString applied to a null-prototype instance"); | ||
|
||
// This test must be last. | ||
test(() => { | ||
delete Blob.prototype[Symbol.toStringTag]; | ||
|
||
assert_equals(Object.prototype.toString.call(Blob.prototype), "[object Object]", "prototype"); | ||
assert_equals(Object.prototype.toString.call(new Blob()), "[object Object]", "instance"); | ||
}, "Object.prototype.toString applied after deleting @@toStringTag"); |
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
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.
nit: It may be better to save the original property descriptor and restore it.
Historically Chrome implements IDL attributes as data properties for example. This clean up might change the original settings.
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.
s/Chrome implements/Chrome implemented/
Chrome still implements cross origin attributes as data properties, though.
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.
I think it is OK, as if the test "@@toStringTag exists on the prototype with the appropriate descriptor" passes, then this will have the intended behavior.
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.
If you really expect the side effect (the original definition is gone and your new definition will be available), then maybe such code should be outside of "cleanup"? I'd expect that "cleanup" restores the testing environment.
Anyway, this is a nit.