summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author李瑞丰 <li15227870916@gmail.com>2021-09-25 01:07:22 +0800
committerGitHub <noreply@github.com>2021-09-25 02:07:22 +0900
commit46245b830a24930ab36f8ce2831325cdd1da17d3 (patch)
treec96c2a69a30120d2cdf639b72a3bace836417151
parent9705efd419ffa05b0d88e788e0ceb77e38078449 (diff)
fix(ext/webidl): correctly apply [SymbolToStringTag] to interfaces (#11851)
Co-authored-by: Luca Casonato <hello@lcas.dev> Co-authored-by: Yoshiya Hinosawa <stibium121@gmail.com>
-rw-r--r--ext/crypto/00_crypto.js14
-rw-r--r--ext/fetch/20_headers.js5
-rw-r--r--ext/fetch/21_formdata.js5
-rw-r--r--ext/fetch/23_request.js5
-rw-r--r--ext/fetch/23_response.js5
-rw-r--r--ext/timers/02_performance.js9
-rw-r--r--ext/url/00_url.js9
-rw-r--r--ext/web/01_dom_exception.js5
-rw-r--r--ext/web/02_event.js29
-rw-r--r--ext/web/03_abort_signal.js9
-rw-r--r--ext/web/06_streams.js45
-rw-r--r--ext/web/08_text_encoding.js17
-rw-r--r--ext/web/09_file.js9
-rw-r--r--ext/web/10_filereader.js5
-rw-r--r--ext/web/13_message_port.js9
-rw-r--r--ext/webidl/00_webidl.js6
-rw-r--r--runtime/js/11_workers.js3
-rw-r--r--tools/wpt/expectation.json15
18 files changed, 29 insertions, 175 deletions
diff --git a/ext/crypto/00_crypto.js b/ext/crypto/00_crypto.js
index 50ee9a7db..a503d316a 100644
--- a/ext/crypto/00_crypto.js
+++ b/ext/crypto/00_crypto.js
@@ -27,7 +27,6 @@
StringFromCharCode,
Symbol,
SymbolFor,
- SymbolToStringTag,
WeakMap,
WeakMapPrototypeGet,
WeakMapPrototypeSet,
@@ -270,10 +269,6 @@
return this[_algorithm];
}
- get [SymbolToStringTag]() {
- return "CryptoKey";
- }
-
[SymbolFor("Deno.customInspect")](inspect) {
return `${this.constructor.name} ${
inspect({
@@ -1570,10 +1565,6 @@
return result;
}
-
- get [SymbolToStringTag]() {
- return "SubtleCrypto";
- }
}
async function generateKey(normalizedAlgorithm, extractable, usages) {
@@ -2027,6 +2018,7 @@
}
}
+ webidl.configurePrototype(SubtleCrypto);
const subtle = webidl.createBranded(SubtleCrypto);
class Crypto {
@@ -2079,10 +2071,6 @@
return subtle;
}
- get [SymbolToStringTag]() {
- return "Crypto";
- }
-
[SymbolFor("Deno.customInspect")](inspect) {
return `${this.constructor.name} ${inspect({})}`;
}
diff --git a/ext/fetch/20_headers.js b/ext/fetch/20_headers.js
index 7503029d8..a99a297b3 100644
--- a/ext/fetch/20_headers.js
+++ b/ext/fetch/20_headers.js
@@ -36,7 +36,6 @@
Symbol,
SymbolFor,
SymbolIterator,
- SymbolToStringTag,
StringPrototypeReplaceAll,
StringPrototypeIncludes,
TypeError,
@@ -411,10 +410,6 @@
}
return `Headers ${inspect(headers)}`;
}
-
- get [SymbolToStringTag]() {
- return "Headers";
- }
}
webidl.mixinPairIterable("Headers", Headers, _iterableHeaders, 0, 1);
diff --git a/ext/fetch/21_formdata.js b/ext/fetch/21_formdata.js
index 25ed32c2d..d8e6d2da2 100644
--- a/ext/fetch/21_formdata.js
+++ b/ext/fetch/21_formdata.js
@@ -26,7 +26,6 @@
MapPrototypeSet,
MathRandom,
Symbol,
- SymbolToStringTag,
StringFromCharCode,
StringPrototypeTrim,
StringPrototypeSlice,
@@ -72,10 +71,6 @@
*/
class FormData {
- get [SymbolToStringTag]() {
- return "FormData";
- }
-
/** @type {FormDataEntry[]} */
[entryList] = [];
diff --git a/ext/fetch/23_request.js b/ext/fetch/23_request.js
index 51ea9b3bc..06843d60c 100644
--- a/ext/fetch/23_request.js
+++ b/ext/fetch/23_request.js
@@ -39,7 +39,6 @@
RegExpPrototypeTest,
Symbol,
SymbolFor,
- SymbolToStringTag,
TypeError,
} = window.__bootstrap.primordials;
@@ -397,10 +396,6 @@
);
}
- get [SymbolToStringTag]() {
- return "Request";
- }
-
[SymbolFor("Deno.customInspect")](inspect) {
return inspect(consoleInternal.createFilteredInspectProxy({
object: this,
diff --git a/ext/fetch/23_response.js b/ext/fetch/23_response.js
index 0db20e90e..32ce88d42 100644
--- a/ext/fetch/23_response.js
+++ b/ext/fetch/23_response.js
@@ -37,7 +37,6 @@
RegExpPrototypeTest,
Symbol,
SymbolFor,
- SymbolToStringTag,
TypeError,
} = window.__bootstrap.primordials;
@@ -373,10 +372,6 @@
return second;
}
- get [SymbolToStringTag]() {
- return "Response";
- }
-
[SymbolFor("Deno.customInspect")](inspect) {
return inspect(consoleInternal.createFilteredInspectProxy({
object: this,
diff --git a/ext/timers/02_performance.js b/ext/timers/02_performance.js
index f752ba933..e09a6f9c0 100644
--- a/ext/timers/02_performance.js
+++ b/ext/timers/02_performance.js
@@ -11,7 +11,6 @@
ObjectKeys,
Symbol,
SymbolFor,
- SymbolToStringTag,
TypeError,
} = window.__bootstrap.primordials;
@@ -192,8 +191,6 @@
const _detail = Symbol("[[detail]]");
class PerformanceMark extends PerformanceEntry {
- [SymbolToStringTag] = "PerformanceMark";
-
[_detail] = null;
get detail() {
@@ -261,8 +258,6 @@
webidl.configurePrototype(PerformanceMark);
class PerformanceMeasure extends PerformanceEntry {
- [SymbolToStringTag] = "PerformanceMeasure";
-
[_detail] = null;
get detail() {
@@ -552,10 +547,6 @@
keys: [],
}));
}
-
- get [SymbolToStringTag]() {
- return "Performance";
- }
}
webidl.configurePrototype(Performance);
diff --git a/ext/url/00_url.js b/ext/url/00_url.js
index e63d70bf8..b1b3818a3 100644
--- a/ext/url/00_url.js
+++ b/ext/url/00_url.js
@@ -22,7 +22,6 @@
Symbol,
SymbolFor,
SymbolIterator,
- SymbolToStringTag,
TypeError,
} = window.__bootstrap.primordials;
@@ -291,10 +290,6 @@
webidl.assertBranded(this, URLSearchParams);
return core.opSync("op_url_stringify_search_params", this[_list]);
}
-
- get [SymbolToStringTag]() {
- return "URLSearchParams";
- }
}
webidl.mixinPairIterable("URLSearchParams", URLSearchParams, _list, 0, 1);
@@ -596,10 +591,6 @@
webidl.assertBranded(this, URL);
return this[_url].href;
}
-
- get [SymbolToStringTag]() {
- return "URL";
- }
}
webidl.configurePrototype(URL);
diff --git a/ext/web/01_dom_exception.js b/ext/web/01_dom_exception.js
index 0d9e82c56..ae478da2b 100644
--- a/ext/web/01_dom_exception.js
+++ b/ext/web/01_dom_exception.js
@@ -18,7 +18,6 @@
ObjectEntries,
ObjectSetPrototypeOf,
SymbolFor,
- SymbolToStringTag,
} = window.__bootstrap.primordials;
const webidl = window.__bootstrap.webidl;
const consoleInternal = window.__bootstrap.console;
@@ -120,10 +119,6 @@
return this.#code;
}
- get [SymbolToStringTag]() {
- return "DOMException";
- }
-
[SymbolFor("Deno.customInspect")](inspect) {
if (this instanceof DOMException) {
return `DOMException: ${this.#message}`;
diff --git a/ext/web/02_event.js b/ext/web/02_event.js
index c61f0955d..f54e3d8a3 100644
--- a/ext/web/02_event.js
+++ b/ext/web/02_event.js
@@ -395,6 +395,9 @@
get timeStamp() {
return this[_attributes].timeStamp;
}
+
+ // TODO(lucacasonato): remove when this interface is spec aligned
+ [SymbolToStringTag] = "Event";
}
function defineEnumerableProps(
@@ -988,15 +991,13 @@
return dispatch(self, event);
}
- get [SymbolToStringTag]() {
- return "EventTarget";
- }
-
getParent(_event) {
return null;
}
}
+ webidl.configurePrototype(EventTarget);
+
defineEnumerableProps(EventTarget, [
"addEventListener",
"removeEventListener",
@@ -1052,10 +1053,6 @@
this.#error = error;
}
- get [SymbolToStringTag]() {
- return "ErrorEvent";
- }
-
[SymbolFor("Deno.privateCustomInspect")](inspect) {
return inspect(consoleInternal.createFilteredInspectProxy({
object: this,
@@ -1070,6 +1067,9 @@
],
}));
}
+
+ // TODO(lucacasonato): remove when this interface is spec aligned
+ [SymbolToStringTag] = "ErrorEvent";
}
defineEnumerableProps(ErrorEvent, [
@@ -1158,6 +1158,9 @@
],
}));
}
+
+ // TODO(lucacasonato): remove when this interface is spec aligned
+ [SymbolToStringTag] = "CloseEvent";
}
class CustomEvent extends Event {
@@ -1176,10 +1179,6 @@
return this.#detail;
}
- get [SymbolToStringTag]() {
- return "CustomEvent";
- }
-
[SymbolFor("Deno.privateCustomInspect")](inspect) {
return inspect(consoleInternal.createFilteredInspectProxy({
object: this,
@@ -1190,6 +1189,9 @@
],
}));
}
+
+ // TODO(lucacasonato): remove when this interface is spec aligned
+ [SymbolToStringTag] = "CustomEvent";
}
ReflectDefineProperty(CustomEvent.prototype, "detail", {
@@ -1219,6 +1221,9 @@
],
}));
}
+
+ // TODO(lucacasonato): remove when this interface is spec aligned
+ [SymbolToStringTag] = "ProgressEvent";
}
const _eventHandlers = Symbol("eventHandlers");
diff --git a/ext/web/03_abort_signal.js b/ext/web/03_abort_signal.js
index 511ad216f..98f14f47a 100644
--- a/ext/web/03_abort_signal.js
+++ b/ext/web/03_abort_signal.js
@@ -13,7 +13,6 @@
SetPrototypeAdd,
SetPrototypeDelete,
Symbol,
- SymbolToStringTag,
TypeError,
} = window.__bootstrap.primordials;
@@ -72,10 +71,6 @@
get aborted() {
return Boolean(this[aborted]);
}
-
- get [SymbolToStringTag]() {
- return "AbortSignal";
- }
}
defineEventHandler(AbortSignal.prototype, "abort");
@@ -91,10 +86,6 @@
abort() {
this.#signal[signalAbort]();
}
-
- get [SymbolToStringTag]() {
- return "AbortController";
- }
}
webidl.configurePrototype(AbortController);
diff --git a/ext/web/06_streams.js b/ext/web/06_streams.js
index 4199be6e0..d062f7fbc 100644
--- a/ext/web/06_streams.js
+++ b/ext/web/06_streams.js
@@ -31,7 +31,6 @@
Symbol,
SymbolAsyncIterator,
SymbolFor,
- SymbolToStringTag,
TypeError,
Uint8Array,
WeakMap,
@@ -3031,10 +3030,6 @@
],
}));
}
-
- get [SymbolToStringTag]() {
- return "ByteLengthQueuingStrategy";
- }
}
webidl.configurePrototype(ByteLengthQueuingStrategy);
@@ -3087,10 +3082,6 @@
],
}));
}
-
- get [SymbolToStringTag]() {
- return "CountQueuingStrategy";
- }
}
webidl.configurePrototype(CountQueuingStrategy);
@@ -3339,10 +3330,6 @@
[SymbolFor("Deno.privateCustomInspect")](inspect) {
return `${this.constructor.name} ${inspect({ locked: this.locked })}`;
}
-
- get [SymbolToStringTag]() {
- return "ReadableStream";
- }
}
// TODO(lucacasonato): should be moved to webidl crate
@@ -3459,10 +3446,6 @@
[SymbolFor("Deno.privateCustomInspect")](inspect) {
return `${this.constructor.name} ${inspect({ closed: this.closed })}`;
}
-
- get [SymbolToStringTag]() {
- return "ReadableStreamDefaultReader";
- }
}
webidl.configurePrototype(ReadableStreamDefaultReader);
@@ -3582,10 +3565,6 @@
}));
}
- get [SymbolToStringTag]() {
- return "ReadableByteStreamController";
- }
-
/**
* @param {any} reason
* @returns {Promise<void>}
@@ -3707,10 +3686,6 @@
}));
}
- get [SymbolToStringTag]() {
- return "ReadableStreamDefaultController";
- }
-
/**
* @param {any} reason
* @returns {Promise<void>}
@@ -3861,10 +3836,6 @@
inspect({ readable: this.readable, writable: this.writable })
}`;
}
-
- get [SymbolToStringTag]() {
- return "TransformStream";
- }
}
webidl.configurePrototype(TransformStream);
@@ -3928,10 +3899,6 @@
keys: ["desiredSize"],
}));
}
-
- get [SymbolToStringTag]() {
- return "TransformStreamDefaultController";
- }
}
webidl.configurePrototype(TransformStreamDefaultController);
@@ -4062,10 +4029,6 @@
[SymbolFor("Deno.privateCustomInspect")](inspect) {
return `${this.constructor.name} ${inspect({ locked: this.locked })}`;
}
-
- get [SymbolToStringTag]() {
- return "WritableStream";
- }
}
webidl.configurePrototype(WritableStream);
@@ -4211,10 +4174,6 @@
],
}));
}
-
- get [SymbolToStringTag]() {
- return "WritableStreamDefaultWriter";
- }
}
webidl.configurePrototype(WritableStreamDefaultWriter);
@@ -4268,10 +4227,6 @@
}));
}
- get [SymbolToStringTag]() {
- return "WritableStreamDefaultController";
- }
-
/**
* @param {any=} reason
* @returns {Promise<void>}
diff --git a/ext/web/08_text_encoding.js b/ext/web/08_text_encoding.js
index e37fbdcd7..28f2848b8 100644
--- a/ext/web/08_text_encoding.js
+++ b/ext/web/08_text_encoding.js
@@ -20,7 +20,6 @@
PromiseResolve,
StringPrototypeCharCodeAt,
StringPrototypeSlice,
- SymbolToStringTag,
TypedArrayPrototypeSubarray,
TypedArrayPrototypeSlice,
Uint8Array,
@@ -126,10 +125,6 @@
}
}
}
-
- get [SymbolToStringTag]() {
- return "TextDecoder";
- }
}
webidl.configurePrototype(TextDecoder);
@@ -182,10 +177,6 @@
});
return core.opSync("op_encoding_encode_into", source, destination);
}
-
- get [SymbolToStringTag]() {
- return "TextEncoder";
- }
}
webidl.configurePrototype(TextEncoder);
@@ -272,10 +263,6 @@
webidl.assertBranded(this, TextDecoderStream);
return this.#transform.writable;
}
-
- get [SymbolToStringTag]() {
- return "TextDecoderStream";
- }
}
webidl.configurePrototype(TextDecoderStream);
@@ -345,10 +332,6 @@
webidl.assertBranded(this, TextEncoderStream);
return this.#transform.writable;
}
-
- get [SymbolToStringTag]() {
- return "TextEncoderStream";
- }
}
webidl.configurePrototype(TextEncoderStream);
diff --git a/ext/web/09_file.js b/ext/web/09_file.js
index 64cdb7b8a..6681f7a13 100644
--- a/ext/web/09_file.js
+++ b/ext/web/09_file.js
@@ -30,7 +30,6 @@
Symbol,
SymbolFor,
TypedArrayPrototypeSet,
- SymbolToStringTag,
TypeError,
Uint8Array,
} = window.__bootstrap.primordials;
@@ -359,10 +358,6 @@
return bytes.buffer;
}
- get [SymbolToStringTag]() {
- return "Blob";
- }
-
[SymbolFor("Deno.customInspect")](inspect) {
return inspect(consoleInternal.createFilteredInspectProxy({
object: this,
@@ -472,10 +467,6 @@
webidl.assertBranded(this, File);
return this[_LastModified];
}
-
- get [SymbolToStringTag]() {
- return "File";
- }
}
webidl.configurePrototype(File);
diff --git a/ext/web/10_filereader.js b/ext/web/10_filereader.js
index f93eb5fee..56794d8b8 100644
--- a/ext/web/10_filereader.js
+++ b/ext/web/10_filereader.js
@@ -31,7 +31,6 @@
queueMicrotask,
StringFromCodePoint,
Symbol,
- SymbolToStringTag,
TypedArrayPrototypeSet,
TypeError,
Uint8Array,
@@ -44,10 +43,6 @@
const handlerSymbol = Symbol("eventHandlers");
class FileReader extends EventTarget {
- get [SymbolToStringTag]() {
- return "FileReader";
- }
-
/** @type {"empty" | "loading" | "done"} */
[state] = "empty";
/** @type {null | string | ArrayBuffer} */
diff --git a/ext/web/13_message_port.js b/ext/web/13_message_port.js
index 2768c0a92..c02b373d6 100644
--- a/ext/web/13_message_port.js
+++ b/ext/web/13_message_port.js
@@ -22,7 +22,6 @@
ObjectSetPrototypeOf,
Symbol,
SymbolFor,
- SymbolToStringTag,
TypeError,
WeakSet,
WeakSetPrototypeAdd,
@@ -59,10 +58,6 @@
inspect({ port1: this.port1, port2: this.port2 })
}`;
}
-
- get [SymbolToStringTag]() {
- return "MessageChannel";
- }
}
webidl.configurePrototype(MessageChannel);
@@ -174,10 +169,6 @@
this[_id] = null;
}
}
-
- get [SymbolToStringTag]() {
- return "MessagePort";
- }
}
defineEventHandler(MessagePort.prototype, "message", function (self) {
diff --git a/ext/webidl/00_webidl.js b/ext/webidl/00_webidl.js
index b75616354..0b8d5c03d 100644
--- a/ext/webidl/00_webidl.js
+++ b/ext/webidl/00_webidl.js
@@ -1053,6 +1053,12 @@
});
}
}
+ ObjectDefineProperty(prototype.prototype, SymbolToStringTag, {
+ value: prototype.name,
+ enumerable: false,
+ configurable: true,
+ writable: false,
+ });
}
window.__bootstrap ??= {};
diff --git a/runtime/js/11_workers.js b/runtime/js/11_workers.js
index c9bfc172a..d7d153098 100644
--- a/runtime/js/11_workers.js
+++ b/runtime/js/11_workers.js
@@ -10,6 +10,7 @@
StringPrototypeStartsWith,
String,
SymbolIterator,
+ SymbolToStringTag,
} = window.__bootstrap.primordials;
const webidl = window.__bootstrap.webidl;
const { URL } = window.__bootstrap.url;
@@ -351,6 +352,8 @@
hostTerminateWorker(this.#id);
}
}
+
+ [SymbolToStringTag] = "Worker";
}
defineEventHandler(Worker.prototype, "error");
diff --git a/tools/wpt/expectation.json b/tools/wpt/expectation.json
index 10aa98abe..551e240e1 100644
--- a/tools/wpt/expectation.json
+++ b/tools/wpt/expectation.json
@@ -12150,16 +12150,7 @@
},
"historical.any.html": false,
"idlharness.https.any.html": [
- "SubtleCrypto interface: operation encrypt(AlgorithmIdentifier, CryptoKey, BufferSource)",
- "SubtleCrypto interface: operation decrypt(AlgorithmIdentifier, CryptoKey, BufferSource)",
- "SubtleCrypto interface: operation sign(AlgorithmIdentifier, CryptoKey, BufferSource)",
- "SubtleCrypto interface: operation verify(AlgorithmIdentifier, CryptoKey, BufferSource, BufferSource)",
- "SubtleCrypto interface: operation digest(AlgorithmIdentifier, BufferSource)",
- "SubtleCrypto interface: operation generateKey(AlgorithmIdentifier, boolean, sequence<KeyUsage>)",
"SubtleCrypto interface: operation deriveKey(AlgorithmIdentifier, CryptoKey, AlgorithmIdentifier, boolean, sequence<KeyUsage>)",
- "SubtleCrypto interface: operation deriveBits(AlgorithmIdentifier, CryptoKey, unsigned long)",
- "SubtleCrypto interface: operation importKey(KeyFormat, (BufferSource or JsonWebKey), AlgorithmIdentifier, boolean, sequence<KeyUsage>)",
- "SubtleCrypto interface: operation exportKey(KeyFormat, CryptoKey)",
"SubtleCrypto interface: operation wrapKey(KeyFormat, CryptoKey, CryptoKey, AlgorithmIdentifier)",
"SubtleCrypto interface: operation unwrapKey(KeyFormat, BufferSource, CryptoKey, AlgorithmIdentifier, AlgorithmIdentifier, boolean, sequence<KeyUsage>)",
"SubtleCrypto interface: crypto.subtle must inherit property \"deriveKey(AlgorithmIdentifier, CryptoKey, AlgorithmIdentifier, boolean, sequence<KeyUsage>)\" with the proper type",
@@ -13572,9 +13563,7 @@
"If the implementation has a stack property on normal errors, it also does on DOMExceptions"
]
},
- "class-string-interface.any.html": [
- "@@toStringTag exists on the prototype with the appropriate descriptor"
- ],
+ "class-string-interface.any.html": true,
"class-string-iterator-prototype-object.any.html": true,
"global-immutable-prototype.any.html": [
"Setting to a different prototype"
@@ -14573,4 +14562,4 @@
"Pattern: [{\"pathname\":\"/foo/bar\"}] Inputs: [\"./foo/bar\",\"https://example.com\"]"
]
}
-} \ No newline at end of file
+}