Bug 1806994 - Define @@toStringTag on namespace objects. r=smaug

Namespace objects have a class string (https://webidl.spec.whatwg.org/#ref-for-dfn-class-string⑨)
so they need to have a @@toStringTag property (https://webidl.spec.whatwg.org/#ref-for-dfn-class-string).

Differential Revision: https://phabricator.services.mozilla.com/D165457
This commit is contained in:
Peter Van der Beken 2023-01-09 22:19:53 +00:00
Родитель 492fde44b3
Коммит b1f8e6a7ef
4 изменённых файлов: 23 добавлений и 58 удалений

Просмотреть файл

@ -819,6 +819,14 @@ static bool DefineConstructor(JSContext* cx, JS::Handle<JSObject*> global,
return DefineConstructor(cx, global, nameKey, constructor);
}
static bool DefineToStringTag(JSContext* cx, JS::Handle<JSObject*> obj,
JS::Handle<JSString*> class_name) {
JS::Rooted<jsid> toStringTagId(
cx, JS::GetWellKnownSymbolKey(cx, JS::SymbolCode::toStringTag));
return JS_DefinePropertyById(cx, obj, toStringTagId, class_name,
JSPROP_READONLY);
}
// name must be an atom (or JS::PropertyKey::NonIntAtom will assert).
static JSObject* CreateInterfaceObject(
JSContext* cx, JS::Handle<JSObject*> global,
@ -905,6 +913,10 @@ static JSObject* CreateInterfaceObject(
}
}
if (isNamespace && !DefineToStringTag(cx, constructor, name)) {
return nullptr;
}
if (proto && !JS_LinkConstructorAndPrototype(cx, constructor, proto)) {
return nullptr;
}
@ -986,10 +998,7 @@ static JSObject* CreateInterfacePrototypeObject(
}
}
JS::Rooted<jsid> toStringTagId(
cx, JS::GetWellKnownSymbolKey(cx, JS::SymbolCode::toStringTag));
if (!JS_DefinePropertyById(cx, ourProto, toStringTagId, name,
JSPROP_READONLY)) {
if (!DefineToStringTag(cx, ourProto, name)) {
return nullptr;
}

Просмотреть файл

@ -10,9 +10,11 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1112014
<script src="property_database.js"></script>
<script type="application/javascript">
const InspectorUtils = SpecialPowers.InspectorUtils;
SimpleTest.waitForExplicitFinish();
SimpleTest.requestLongerTimeout(2);
SimpleTest.requestLongerTimeout(2);
async function test() {
const InspectorUtils = SpecialPowers.InspectorUtils;
// This holds a canonical test value for each TYPE_ constant.
let testValues = {
@ -43,14 +45,9 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1112014
// Ensure that all the TYPE_ constants have a representative
// test value, to try to ensure that this test is updated
// whenever a new type is added.
let reps = [];
for (let tc in InspectorUtils) {
if (/TYPE_/.test(tc)) {
if (!(tc in testValues)) {
reps.push(tc);
}
}
}
let reps = await SpecialPowers.spawn(window, [], () => {
return Object.getOwnPropertyNames(InspectorUtils).filter(tc => /TYPE_/.test(tc));
}).then(v => v.filter(tc => !(tc in testValues)));
is(reps.join(","), "", "all types have representative test value");
for (let propertyName in gCSSProperties) {
@ -76,9 +73,11 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1112014
ok(!InspectorUtils.cssPropertySupportsType("--variable", "color"),
"cssPropertySupportsType returns false for variable");
SimpleTest.finish();
}
</script>
</head>
<body>
<body onload="test()">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1112014">Mozilla Bug 1112014</a>
<p id="display"></p>
<div id="content" style="display: none">

Просмотреть файл

@ -1,30 +0,0 @@
[console-namespace-object-class-string.any.html]
expected:
if (os == "android") and fission: [OK, TIMEOUT]
[Object.prototype.toString applied after deleting @@toStringTag]
expected: FAIL
[@@toStringTag exists on the namespace object with the appropriate descriptor]
expected: FAIL
[Object.prototype.toString applied after modifying the namespace object's @@toStringTag]
expected: FAIL
[Object.prototype.toString applied to the namespace object]
expected: FAIL
[console-namespace-object-class-string.any.worker.html]
expected:
if (os == "android") and fission: [OK, TIMEOUT]
[Object.prototype.toString applied after deleting @@toStringTag]
expected: FAIL
[@@toStringTag exists on the namespace object with the appropriate descriptor]
expected: FAIL
[Object.prototype.toString applied after modifying the namespace object's @@toStringTag]
expected: FAIL
[Object.prototype.toString applied to the namespace object]
expected: FAIL

Просмотреть файл

@ -1,13 +0,0 @@
[CSS-namespace-object-class-string.html]
[Object.prototype.toString applied after deleting @@toStringTag]
expected: FAIL
[@@toStringTag exists on the namespace object with the appropriate descriptor]
expected: FAIL
[Object.prototype.toString applied after modifying the namespace object's @@toStringTag]
expected: FAIL
[Object.prototype.toString applied to the namespace object]
expected: FAIL