refactor: clean up webidl protype configuration (#10871)

This commit is contained in:
Luca Casonato 2021-06-07 10:04:10 +02:00 committed by GitHub
parent 3b220c64f6
commit 3a4a47799f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 49 additions and 134 deletions

View file

@ -158,10 +158,7 @@
}
}
Object.defineProperty(Crypto.prototype, "subtle", {
configurable: true,
enumerable: true,
});
webidl.configurePrototype(Crypto);
window.__bootstrap.crypto = {
SubtleCrypto,

View file

@ -392,6 +392,8 @@
webidl.mixinPairIterable("Headers", Headers, _iterableHeaders, 0, 1);
webidl.configurePrototype(Headers);
webidl.converters["sequence<ByteString>"] = webidl
.createSequenceConverter(webidl.converters["ByteString"]);
webidl.converters["sequence<sequence<ByteString>>"] = webidl

View file

@ -241,6 +241,8 @@
webidl.mixinPairIterable("FormData", FormData, entryList, "name", "value");
webidl.configurePrototype(FormData);
class MultipartBuilder {
/**
* @param {FormData} formData

View file

@ -384,31 +384,7 @@
mixinBody(Request, _body, _mimeType);
Object.defineProperty(Request.prototype, "method", {
enumerable: true,
configurable: true,
});
Object.defineProperty(Request.prototype, "url", {
enumerable: true,
configurable: true,
});
Object.defineProperty(Request.prototype, "headers", {
enumerable: true,
configurable: true,
});
Object.defineProperty(Request.prototype, "redirect", {
enumerable: true,
configurable: true,
});
Object.defineProperty(Request.prototype, "signal", {
enumerable: true,
configurable: true,
});
Object.defineProperty(Request.prototype, "clone", {
enumerable: true,
writable: true,
configurable: true,
});
webidl.configurePrototype(Request);
webidl.converters["Request"] = webidl.createInterfaceConverter(
"Request",

View file

@ -377,39 +377,7 @@
mixinBody(Response, _body, _mimeType);
Object.defineProperty(Response.prototype, "type", {
enumerable: true,
configurable: true,
});
Object.defineProperty(Response.prototype, "url", {
enumerable: true,
configurable: true,
});
Object.defineProperty(Response.prototype, "redirected", {
enumerable: true,
configurable: true,
});
Object.defineProperty(Response.prototype, "status", {
enumerable: true,
configurable: true,
});
Object.defineProperty(Response.prototype, "ok", {
enumerable: true,
configurable: true,
});
Object.defineProperty(Response.prototype, "statusText", {
enumerable: true,
configurable: true,
});
Object.defineProperty(Response.prototype, "headers", {
enumerable: true,
configurable: true,
});
Object.defineProperty(Response.prototype, "clone", {
enumerable: true,
writable: true,
configurable: true,
});
webidl.configurePrototype(Response);
webidl.converters["Response"] = webidl.createInterfaceConverter(
"Response",

View file

@ -291,6 +291,8 @@
}
}
webidl.configurePrototype(Blob);
webidl.converters["Blob"] = webidl.createInterfaceConverter("Blob", Blob);
webidl.converters["BlobPart"] = (V, opts) => {
// Union for ((ArrayBuffer or ArrayBufferView) or Blob or USVString)
@ -392,6 +394,8 @@
}
}
webidl.configurePrototype(File);
webidl.converters["FilePropertyBag"] = webidl.createDictionaryConverter(
"FilePropertyBag",
blobPropertyBagDictionary,

View file

@ -328,6 +328,8 @@
}
}
webidl.configurePrototype(FileReader);
Object.defineProperty(FileReader, "EMPTY", {
writable: false,
enumerable: true,

View file

@ -105,9 +105,7 @@
}
}
defineProperty(DOMException.prototype, "message", { enumerable: true });
defineProperty(DOMException.prototype, "name", { enumerable: true });
defineProperty(DOMException.prototype, "code", { enumerable: true });
webidl.configurePrototype(DOMException);
for (
const [key, value] of Object.entries({

View file

@ -60,6 +60,9 @@
}
}
defineEventHandler(AbortSignal.prototype, "abort");
webidl.configurePrototype(AbortSignal);
class AbortController {
#signal = new AbortSignal(illegalConstructorKey);
@ -76,6 +79,8 @@
}
}
webidl.configurePrototype(AbortController);
const handlerSymbol = Symbol("eventHandlers");
function makeWrappedHandler(handler) {

View file

@ -121,23 +121,7 @@
}
}
Object.defineProperty(TextDecoder.prototype, "encoding", {
enumerable: true,
configurable: true,
});
Object.defineProperty(TextDecoder.prototype, "fatal", {
enumerable: true,
configurable: true,
});
Object.defineProperty(TextDecoder.prototype, "ignoreBOM", {
enumerable: true,
configurable: true,
});
Object.defineProperty(TextDecoder.prototype, "decode", {
enumerable: true,
writable: true,
configurable: true,
});
webidl.configurePrototype(TextDecoder);
class TextEncoder {
constructor() {
@ -189,20 +173,7 @@
}
}
Object.defineProperty(TextEncoder.prototype, "encoding", {
enumerable: true,
configurable: true,
});
Object.defineProperty(TextEncoder.prototype, "encode", {
enumerable: true,
writable: true,
configurable: true,
});
Object.defineProperty(TextEncoder.prototype, "encodeInto", {
enumerable: true,
writable: true,
configurable: true,
});
webidl.configurePrototype(TextEncoder);
class TextDecoderStream {
/** @type {TextDecoder} */
@ -293,26 +264,7 @@
}
}
Object.defineProperty(TextDecoderStream.prototype, "encoding", {
enumerable: true,
configurable: true,
});
Object.defineProperty(TextDecoderStream.prototype, "fatal", {
enumerable: true,
configurable: true,
});
Object.defineProperty(TextDecoderStream.prototype, "ignoreBOM", {
enumerable: true,
configurable: true,
});
Object.defineProperty(TextDecoderStream.prototype, "readable", {
enumerable: true,
configurable: true,
});
Object.defineProperty(TextDecoderStream.prototype, "writable", {
enumerable: true,
configurable: true,
});
webidl.configurePrototype(TextDecoderStream);
class TextEncoderStream {
/** @type {string | null} */
@ -382,18 +334,7 @@
}
}
Object.defineProperty(TextEncoderStream.prototype, "encoding", {
enumerable: true,
configurable: true,
});
Object.defineProperty(TextEncoderStream.prototype, "readable", {
enumerable: true,
configurable: true,
});
Object.defineProperty(TextEncoderStream.prototype, "writable", {
enumerable: true,
configurable: true,
});
webidl.configurePrototype(TextEncoderStream);
webidl.converters.TextDecoderOptions = webidl.createDictionaryConverter(
"TextDecoderOptions",

View file

@ -897,6 +897,26 @@
return Object.assign(prototype.prototype, methods);
}
function configurePrototype(prototype) {
const descriptors = Object.getOwnPropertyDescriptors(prototype.prototype);
for (const key in descriptors) {
if (key === "constructor") continue;
const descriptor = descriptors[key];
if ("value" in descriptor && typeof descriptor.value === "function") {
Object.defineProperty(prototype.prototype, key, {
enumerable: true,
writable: true,
configurable: true,
});
} else if ("get" in descriptor) {
Object.defineProperty(prototype.prototype, key, {
enumerable: true,
configurable: true,
});
}
}
}
window.__bootstrap ??= {};
window.__bootstrap.webidl = {
makeException,
@ -913,5 +933,6 @@
assertBranded,
illegalConstructor,
mixinPairIterable,
configurePrototype,
};
})(this);

View file

@ -298,6 +298,11 @@ declare namespace globalThis {
keyKey: string | number | symbol,
valueKey: string | number | symbol,
): void;
/**
* Configure prototype properties enumerability / writability / configurability.
*/
declare function configurePrototype(prototype: any);
}
}
}

View file

@ -75,7 +75,6 @@
"Non-secure context window does not have access to SubtleCrypto"
],
"idlharness.https.any.html": [
"Crypto interface: operation getRandomValues(ArrayBufferView)",
"CryptoKey interface: existence and properties of interface object",
"CryptoKey interface object length",
"CryptoKey interface object name",
@ -1028,11 +1027,6 @@
"redirect-to-dataurl.any.html": true
},
"idlharness.any.html": [
"Headers interface: operation append(ByteString, ByteString)",
"Headers interface: operation delete(ByteString)",
"Headers interface: operation get(ByteString)",
"Headers interface: operation has(ByteString)",
"Headers interface: operation set(ByteString, ByteString)",
"Headers interface: iterable<ByteString, ByteString>",
"Request interface: attribute destination",
"Request interface: attribute referrer",