From 92920b6973e896022020f22c5566db51575c95c1 Mon Sep 17 00:00:00 2001 From: Alexey Shvayka Date: Thu, 23 Jul 2020 15:17:14 +0300 Subject: [PATCH] Add WebAssembly[Symbol.toStringTag] test --- .../namespace-object-class-string.any.js | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 wasm/jsapi/namespace-object-class-string.any.js diff --git a/wasm/jsapi/namespace-object-class-string.any.js b/wasm/jsapi/namespace-object-class-string.any.js new file mode 100644 index 00000000000000..2f63aca2c55e5b --- /dev/null +++ b/wasm/jsapi/namespace-object-class-string.any.js @@ -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");