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 Symbol.toStringTag value of namespace objects #24717

Merged
Show file tree
Hide file tree
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
40 changes: 40 additions & 0 deletions console/console-namespace-object-class-string.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"use strict";
// https://heycam.github.io/webidl/#es-namespaces
// https://console.spec.whatwg.org/#console-namespace

test(() => {
assert_own_property(console, Symbol.toStringTag);

const propDesc = Object.getOwnPropertyDescriptor(console, Symbol.toStringTag);
assert_equals(propDesc.value, "console", "value");
assert_equals(propDesc.writable, false, "writable");
assert_equals(propDesc.enumerable, false, "enumerable");
assert_equals(propDesc.configurable, true, "configurable");
}, "@@toStringTag exists on the namespace object with the appropriate descriptor");

test(() => {
assert_equals(console.toString(), "[object console]");
assert_equals(Object.prototype.toString.call(console), "[object console]");
}, "Object.prototype.toString applied to the namespace object");

test(t => {
assert_own_property(console, Symbol.toStringTag, "Precondition: @@toStringTag on the namespace object");
t.add_cleanup(() => {
Object.defineProperty(console, Symbol.toStringTag, { value: "console" });
});

Object.defineProperty(console, Symbol.toStringTag, { value: "Test" });
assert_equals(console.toString(), "[object Test]");
assert_equals(Object.prototype.toString.call(console), "[object Test]");
}, "Object.prototype.toString applied after modifying the namespace object's @@toStringTag");

test(t => {
assert_own_property(console, Symbol.toStringTag, "Precondition: @@toStringTag on the namespace object");
t.add_cleanup(() => {
Object.defineProperty(console, Symbol.toStringTag, { value: "console" });
});

assert_true(delete console[Symbol.toStringTag]);
assert_equals(console.toString(), "[object Object]");
assert_equals(Object.prototype.toString.call(console), "[object Object]");
}, "Object.prototype.toString applied after deleting @@toStringTag");
47 changes: 47 additions & 0 deletions css/cssom/CSS-namespace-object-class-string.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!doctype html>
<meta charset="utf-8">
<title>CSSOM - Symbol.toStringTag value of CSS namespace object</title>
<link rel="help" href="https://heycam.github.io/webidl/#es-namespaces">
<link rel="help" href="https://drafts.csswg.org/cssom/#namespacedef-css">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
"use strict";

test(() => {
assert_own_property(CSS, Symbol.toStringTag);

const propDesc = Object.getOwnPropertyDescriptor(CSS, Symbol.toStringTag);
assert_equals(propDesc.value, "CSS", "value");
assert_equals(propDesc.writable, false, "writable");
assert_equals(propDesc.enumerable, false, "enumerable");
assert_equals(propDesc.configurable, true, "configurable");
}, "@@toStringTag exists on the namespace object with the appropriate descriptor");

test(() => {
assert_equals(CSS.toString(), "[object CSS]");
assert_equals(Object.prototype.toString.call(CSS), "[object CSS]");
}, "Object.prototype.toString applied to the namespace object");

test(t => {
assert_own_property(CSS, Symbol.toStringTag, "Precondition: @@toStringTag on the namespace object");
t.add_cleanup(() => {
Object.defineProperty(CSS, Symbol.toStringTag, { value: "CSS" });
});

Object.defineProperty(CSS, Symbol.toStringTag, { value: "Test" });
assert_equals(CSS.toString(), "[object Test]");
assert_equals(Object.prototype.toString.call(CSS), "[object Test]");
}, "Object.prototype.toString applied after modifying the namespace object's @@toStringTag");

test(t => {
assert_own_property(CSS, Symbol.toStringTag, "Precondition: @@toStringTag on the namespace object");
t.add_cleanup(() => {
Object.defineProperty(CSS, Symbol.toStringTag, { value: "CSS" });
});

assert_true(delete CSS[Symbol.toStringTag]);
assert_equals(CSS.toString(), "[object Object]");
assert_equals(Object.prototype.toString.call(CSS), "[object Object]");
}, "Object.prototype.toString applied after deleting @@toStringTag");
</script>
40 changes: 40 additions & 0 deletions wasm/jsapi/namespace-object-class-string.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"use strict";
// https://heycam.github.io/webidl/#es-namespaces
// https://webassembly.github.io/spec/js-api/#namespacedef-webassembly

test(() => {
assert_own_property(WebAssembly, Symbol.toStringTag);

const propDesc = Object.getOwnPropertyDescriptor(WebAssembly, Symbol.toStringTag);
assert_equals(propDesc.value, "WebAssembly", "value");
assert_equals(propDesc.writable, false, "writable");
assert_equals(propDesc.enumerable, false, "enumerable");
assert_equals(propDesc.configurable, true, "configurable");
}, "@@toStringTag exists on the namespace object with the appropriate descriptor");

test(() => {
assert_equals(WebAssembly.toString(), "[object WebAssembly]");
assert_equals(Object.prototype.toString.call(WebAssembly), "[object WebAssembly]");
}, "Object.prototype.toString applied to the namespace object");

test(t => {
assert_own_property(WebAssembly, Symbol.toStringTag, "Precondition: @@toStringTag on the namespace object");
t.add_cleanup(() => {
Object.defineProperty(WebAssembly, Symbol.toStringTag, { value: "WebAssembly" });
});

Object.defineProperty(WebAssembly, Symbol.toStringTag, { value: "Test" });
assert_equals(WebAssembly.toString(), "[object Test]");
assert_equals(Object.prototype.toString.call(WebAssembly), "[object Test]");
}, "Object.prototype.toString applied after modifying the namespace object's @@toStringTag");

test(t => {
assert_own_property(WebAssembly, Symbol.toStringTag, "Precondition: @@toStringTag on the namespace object");
t.add_cleanup(() => {
Object.defineProperty(WebAssembly, Symbol.toStringTag, { value: "WebAssembly" });
});

assert_true(delete WebAssembly[Symbol.toStringTag]);
assert_equals(WebAssembly.toString(), "[object Object]");
assert_equals(Object.prototype.toString.call(WebAssembly), "[object Object]");
}, "Object.prototype.toString applied after deleting @@toStringTag");