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

Test new Web IDL class string behavior #23140

Merged
merged 3 commits into from
Apr 23, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
62 changes: 62 additions & 0 deletions WebIDL/ecmascript-binding/class-string.any.js
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" });
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

});

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");
12 changes: 0 additions & 12 deletions WebIDL/ecmascript-binding/interface-prototype-object.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,6 @@
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
// A specification issue was raised for this behavior.
// https://www.w3.org/Bugs/Public/show_bug.cgi?id=28244
test(function() {
// Checks toString() behavior.
assert_class_string(Document.prototype, "DocumentPrototype");

assert_true(Document.prototype.hasOwnProperty(Symbol.toStringTag),
"An interface prototype object should have toStringTag property.");
assert_equals(Document.prototype[Symbol.toStringTag], "DocumentPrototype");
}, "The class string of an interface prototype object is the concatenation of " +
"the interface's identifier and the string 'Prototype'.");

test(function() {
// https://heycam.github.io/webidl/#create-an-interface-prototype-object
assert_own_property(Element.prototype, Symbol.unscopables, "Element.prototype has @@unscopables.");
Expand Down