mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
refactor: clean up webidl protype configuration (#10871)
This commit is contained in:
parent
3b220c64f6
commit
3a4a47799f
13 changed files with 49 additions and 134 deletions
|
@ -158,10 +158,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.defineProperty(Crypto.prototype, "subtle", {
|
webidl.configurePrototype(Crypto);
|
||||||
configurable: true,
|
|
||||||
enumerable: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
window.__bootstrap.crypto = {
|
window.__bootstrap.crypto = {
|
||||||
SubtleCrypto,
|
SubtleCrypto,
|
||||||
|
|
|
@ -392,6 +392,8 @@
|
||||||
|
|
||||||
webidl.mixinPairIterable("Headers", Headers, _iterableHeaders, 0, 1);
|
webidl.mixinPairIterable("Headers", Headers, _iterableHeaders, 0, 1);
|
||||||
|
|
||||||
|
webidl.configurePrototype(Headers);
|
||||||
|
|
||||||
webidl.converters["sequence<ByteString>"] = webidl
|
webidl.converters["sequence<ByteString>"] = webidl
|
||||||
.createSequenceConverter(webidl.converters["ByteString"]);
|
.createSequenceConverter(webidl.converters["ByteString"]);
|
||||||
webidl.converters["sequence<sequence<ByteString>>"] = webidl
|
webidl.converters["sequence<sequence<ByteString>>"] = webidl
|
||||||
|
|
|
@ -241,6 +241,8 @@
|
||||||
|
|
||||||
webidl.mixinPairIterable("FormData", FormData, entryList, "name", "value");
|
webidl.mixinPairIterable("FormData", FormData, entryList, "name", "value");
|
||||||
|
|
||||||
|
webidl.configurePrototype(FormData);
|
||||||
|
|
||||||
class MultipartBuilder {
|
class MultipartBuilder {
|
||||||
/**
|
/**
|
||||||
* @param {FormData} formData
|
* @param {FormData} formData
|
||||||
|
|
|
@ -384,31 +384,7 @@
|
||||||
|
|
||||||
mixinBody(Request, _body, _mimeType);
|
mixinBody(Request, _body, _mimeType);
|
||||||
|
|
||||||
Object.defineProperty(Request.prototype, "method", {
|
webidl.configurePrototype(Request);
|
||||||
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.converters["Request"] = webidl.createInterfaceConverter(
|
webidl.converters["Request"] = webidl.createInterfaceConverter(
|
||||||
"Request",
|
"Request",
|
||||||
|
|
|
@ -377,39 +377,7 @@
|
||||||
|
|
||||||
mixinBody(Response, _body, _mimeType);
|
mixinBody(Response, _body, _mimeType);
|
||||||
|
|
||||||
Object.defineProperty(Response.prototype, "type", {
|
webidl.configurePrototype(Response);
|
||||||
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.converters["Response"] = webidl.createInterfaceConverter(
|
webidl.converters["Response"] = webidl.createInterfaceConverter(
|
||||||
"Response",
|
"Response",
|
||||||
|
|
|
@ -291,6 +291,8 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
webidl.configurePrototype(Blob);
|
||||||
|
|
||||||
webidl.converters["Blob"] = webidl.createInterfaceConverter("Blob", Blob);
|
webidl.converters["Blob"] = webidl.createInterfaceConverter("Blob", Blob);
|
||||||
webidl.converters["BlobPart"] = (V, opts) => {
|
webidl.converters["BlobPart"] = (V, opts) => {
|
||||||
// Union for ((ArrayBuffer or ArrayBufferView) or Blob or USVString)
|
// Union for ((ArrayBuffer or ArrayBufferView) or Blob or USVString)
|
||||||
|
@ -392,6 +394,8 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
webidl.configurePrototype(File);
|
||||||
|
|
||||||
webidl.converters["FilePropertyBag"] = webidl.createDictionaryConverter(
|
webidl.converters["FilePropertyBag"] = webidl.createDictionaryConverter(
|
||||||
"FilePropertyBag",
|
"FilePropertyBag",
|
||||||
blobPropertyBagDictionary,
|
blobPropertyBagDictionary,
|
||||||
|
|
|
@ -328,6 +328,8 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
webidl.configurePrototype(FileReader);
|
||||||
|
|
||||||
Object.defineProperty(FileReader, "EMPTY", {
|
Object.defineProperty(FileReader, "EMPTY", {
|
||||||
writable: false,
|
writable: false,
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
|
|
|
@ -105,9 +105,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
defineProperty(DOMException.prototype, "message", { enumerable: true });
|
webidl.configurePrototype(DOMException);
|
||||||
defineProperty(DOMException.prototype, "name", { enumerable: true });
|
|
||||||
defineProperty(DOMException.prototype, "code", { enumerable: true });
|
|
||||||
|
|
||||||
for (
|
for (
|
||||||
const [key, value] of Object.entries({
|
const [key, value] of Object.entries({
|
||||||
|
|
|
@ -60,6 +60,9 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
defineEventHandler(AbortSignal.prototype, "abort");
|
defineEventHandler(AbortSignal.prototype, "abort");
|
||||||
|
|
||||||
|
webidl.configurePrototype(AbortSignal);
|
||||||
|
|
||||||
class AbortController {
|
class AbortController {
|
||||||
#signal = new AbortSignal(illegalConstructorKey);
|
#signal = new AbortSignal(illegalConstructorKey);
|
||||||
|
|
||||||
|
@ -76,6 +79,8 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
webidl.configurePrototype(AbortController);
|
||||||
|
|
||||||
const handlerSymbol = Symbol("eventHandlers");
|
const handlerSymbol = Symbol("eventHandlers");
|
||||||
|
|
||||||
function makeWrappedHandler(handler) {
|
function makeWrappedHandler(handler) {
|
||||||
|
|
|
@ -121,23 +121,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.defineProperty(TextDecoder.prototype, "encoding", {
|
webidl.configurePrototype(TextDecoder);
|
||||||
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,
|
|
||||||
});
|
|
||||||
|
|
||||||
class TextEncoder {
|
class TextEncoder {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -189,20 +173,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.defineProperty(TextEncoder.prototype, "encoding", {
|
webidl.configurePrototype(TextEncoder);
|
||||||
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,
|
|
||||||
});
|
|
||||||
|
|
||||||
class TextDecoderStream {
|
class TextDecoderStream {
|
||||||
/** @type {TextDecoder} */
|
/** @type {TextDecoder} */
|
||||||
|
@ -293,26 +264,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.defineProperty(TextDecoderStream.prototype, "encoding", {
|
webidl.configurePrototype(TextDecoderStream);
|
||||||
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,
|
|
||||||
});
|
|
||||||
|
|
||||||
class TextEncoderStream {
|
class TextEncoderStream {
|
||||||
/** @type {string | null} */
|
/** @type {string | null} */
|
||||||
|
@ -382,18 +334,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.defineProperty(TextEncoderStream.prototype, "encoding", {
|
webidl.configurePrototype(TextEncoderStream);
|
||||||
enumerable: true,
|
|
||||||
configurable: true,
|
|
||||||
});
|
|
||||||
Object.defineProperty(TextEncoderStream.prototype, "readable", {
|
|
||||||
enumerable: true,
|
|
||||||
configurable: true,
|
|
||||||
});
|
|
||||||
Object.defineProperty(TextEncoderStream.prototype, "writable", {
|
|
||||||
enumerable: true,
|
|
||||||
configurable: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
webidl.converters.TextDecoderOptions = webidl.createDictionaryConverter(
|
webidl.converters.TextDecoderOptions = webidl.createDictionaryConverter(
|
||||||
"TextDecoderOptions",
|
"TextDecoderOptions",
|
||||||
|
|
|
@ -897,6 +897,26 @@
|
||||||
return Object.assign(prototype.prototype, methods);
|
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 ??= {};
|
||||||
window.__bootstrap.webidl = {
|
window.__bootstrap.webidl = {
|
||||||
makeException,
|
makeException,
|
||||||
|
@ -913,5 +933,6 @@
|
||||||
assertBranded,
|
assertBranded,
|
||||||
illegalConstructor,
|
illegalConstructor,
|
||||||
mixinPairIterable,
|
mixinPairIterable,
|
||||||
|
configurePrototype,
|
||||||
};
|
};
|
||||||
})(this);
|
})(this);
|
||||||
|
|
5
extensions/webidl/internal.d.ts
vendored
5
extensions/webidl/internal.d.ts
vendored
|
@ -298,6 +298,11 @@ declare namespace globalThis {
|
||||||
keyKey: string | number | symbol,
|
keyKey: string | number | symbol,
|
||||||
valueKey: string | number | symbol,
|
valueKey: string | number | symbol,
|
||||||
): void;
|
): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure prototype properties enumerability / writability / configurability.
|
||||||
|
*/
|
||||||
|
declare function configurePrototype(prototype: any);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,6 @@
|
||||||
"Non-secure context window does not have access to SubtleCrypto"
|
"Non-secure context window does not have access to SubtleCrypto"
|
||||||
],
|
],
|
||||||
"idlharness.https.any.html": [
|
"idlharness.https.any.html": [
|
||||||
"Crypto interface: operation getRandomValues(ArrayBufferView)",
|
|
||||||
"CryptoKey interface: existence and properties of interface object",
|
"CryptoKey interface: existence and properties of interface object",
|
||||||
"CryptoKey interface object length",
|
"CryptoKey interface object length",
|
||||||
"CryptoKey interface object name",
|
"CryptoKey interface object name",
|
||||||
|
@ -1028,11 +1027,6 @@
|
||||||
"redirect-to-dataurl.any.html": true
|
"redirect-to-dataurl.any.html": true
|
||||||
},
|
},
|
||||||
"idlharness.any.html": [
|
"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>",
|
"Headers interface: iterable<ByteString, ByteString>",
|
||||||
"Request interface: attribute destination",
|
"Request interface: attribute destination",
|
||||||
"Request interface: attribute referrer",
|
"Request interface: attribute referrer",
|
||||||
|
|
Loading…
Add table
Reference in a new issue