summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/wasm/jsapi/constructor/toStringTag.any.js
blob: 5fae8304f8c0f60aa47c6fcd8b6269a35784e759 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// META: global=window,dedicatedworker,jsshell,shadowrealm

"use strict";
// https://webidl.spec.whatwg.org/#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");