mirror of
https://github.com/denoland/deno.git
synced 2024-12-23 15:49:44 -05:00
refactor: use primordials
in runtime, extensions and core (#11500)
This commit is contained in:
parent
df26a3563e
commit
865d9ddd51
14 changed files with 107 additions and 77 deletions
|
@ -1,3 +1,4 @@
|
|||
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
||||
const { core } = Deno;
|
||||
|
||||
class DOMException {
|
||||
|
|
|
@ -51,6 +51,7 @@
|
|||
RegExpPrototypeToString,
|
||||
Set,
|
||||
SetPrototypeEntries,
|
||||
Symbol,
|
||||
SymbolPrototypeToString,
|
||||
SymbolToStringTag,
|
||||
SymbolHasInstance,
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
ArrayPrototypeFind,
|
||||
ArrayBufferIsView,
|
||||
ArrayPrototypeIncludes,
|
||||
BigInt64Array,
|
||||
StringPrototypeToUpperCase,
|
||||
Symbol,
|
||||
SymbolFor,
|
||||
|
@ -187,7 +188,7 @@
|
|||
return this[_algorithm];
|
||||
}
|
||||
|
||||
get [Symbol.toStringTag]() {
|
||||
get [SymbolToStringTag]() {
|
||||
return "CryptoKey";
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
const { isReadableStreamDisturbed, errorReadableStream, createProxy } =
|
||||
globalThis.__bootstrap.streams;
|
||||
const {
|
||||
ArrayBuffer,
|
||||
ArrayBufferIsView,
|
||||
ArrayPrototypePush,
|
||||
ArrayPrototypeMap,
|
||||
|
|
|
@ -20,8 +20,10 @@
|
|||
ObjectKeys,
|
||||
StringPrototypeSlice,
|
||||
Symbol,
|
||||
SymbolFor,
|
||||
SymbolIterator,
|
||||
SymbolToStringTag,
|
||||
TypeError,
|
||||
} = window.__bootstrap.primordials;
|
||||
|
||||
const _list = Symbol("list");
|
||||
|
@ -280,7 +282,7 @@
|
|||
this[_url] = parts;
|
||||
}
|
||||
|
||||
[Symbol.for("Deno.privateCustomInspect")](inspect) {
|
||||
[SymbolFor("Deno.privateCustomInspect")](inspect) {
|
||||
const object = {
|
||||
href: this.href,
|
||||
origin: this.origin,
|
||||
|
|
|
@ -11,10 +11,12 @@
|
|||
|
||||
((window) => {
|
||||
const {
|
||||
Error,
|
||||
ErrorPrototype,
|
||||
ObjectDefineProperty,
|
||||
ObjectEntries,
|
||||
ObjectSetPrototypeOf,
|
||||
SymbolFor,
|
||||
SymbolToStringTag,
|
||||
} = window.__bootstrap.primordials;
|
||||
const webidl = window.__bootstrap.webidl;
|
||||
const consoleInternal = window.__bootstrap.console;
|
||||
|
@ -106,11 +108,11 @@
|
|||
return this.#code;
|
||||
}
|
||||
|
||||
get [Symbol.toStringTag]() {
|
||||
get [SymbolToStringTag]() {
|
||||
return "DOMException";
|
||||
}
|
||||
|
||||
[Symbol.for("Deno.customInspect")](inspect) {
|
||||
[SymbolFor("Deno.customInspect")](inspect) {
|
||||
if (this instanceof DOMException) {
|
||||
return `DOMException: ${this.#message}`;
|
||||
} else {
|
||||
|
@ -127,7 +129,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
ObjectSetPrototypeOf(DOMException.prototype, Error.prototype);
|
||||
ObjectSetPrototypeOf(DOMException.prototype, ErrorPrototype);
|
||||
|
||||
webidl.configurePrototype(DOMException);
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
Symbol,
|
||||
SymbolFor,
|
||||
SymbolToStringTag,
|
||||
TypeError,
|
||||
WeakMap,
|
||||
WeakMapPrototypeGet,
|
||||
WeakMapPrototypeSet,
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
ArrayPrototypeJoin,
|
||||
StringFromCharCode,
|
||||
TypedArrayFrom,
|
||||
Uint8Array,
|
||||
} = window.__bootstrap.primordials;
|
||||
|
||||
/**
|
||||
|
|
|
@ -28,7 +28,10 @@
|
|||
PromiseReject,
|
||||
queueMicrotask,
|
||||
RangeError,
|
||||
Symbol,
|
||||
SymbolAsyncIterator,
|
||||
SymbolFor,
|
||||
SymbolToStringTag,
|
||||
TypeError,
|
||||
Uint8Array,
|
||||
WeakMap,
|
||||
|
@ -198,7 +201,7 @@
|
|||
function transferArrayBuffer(O) {
|
||||
assert(!isDetachedBuffer(O));
|
||||
const transferredIshVersion = O.slice(0);
|
||||
Object.defineProperty(O, "byteLength", {
|
||||
ObjectDefineProperty(O, "byteLength", {
|
||||
get() {
|
||||
return 0;
|
||||
},
|
||||
|
@ -3018,7 +3021,7 @@
|
|||
return WeakMapPrototypeGet(byteSizeFunctionWeakMap, this[_globalObject]);
|
||||
}
|
||||
|
||||
[Symbol.for("Deno.customInspect")](inspect) {
|
||||
[SymbolFor("Deno.customInspect")](inspect) {
|
||||
return inspect(consoleInternal.createFilteredInspectProxy({
|
||||
object: this,
|
||||
evaluate: this instanceof ByteLengthQueuingStrategy,
|
||||
|
@ -3029,7 +3032,7 @@
|
|||
}));
|
||||
}
|
||||
|
||||
get [Symbol.toStringTag]() {
|
||||
get [SymbolToStringTag]() {
|
||||
return "ByteLengthQueuingStrategy";
|
||||
}
|
||||
}
|
||||
|
@ -3074,7 +3077,7 @@
|
|||
return WeakMapPrototypeGet(countSizeFunctionWeakMap, this[_globalObject]);
|
||||
}
|
||||
|
||||
[Symbol.for("Deno.customInspect")](inspect) {
|
||||
[SymbolFor("Deno.customInspect")](inspect) {
|
||||
return inspect(consoleInternal.createFilteredInspectProxy({
|
||||
object: this,
|
||||
evaluate: this instanceof CountQueuingStrategy,
|
||||
|
@ -3085,7 +3088,7 @@
|
|||
}));
|
||||
}
|
||||
|
||||
get [Symbol.toStringTag]() {
|
||||
get [SymbolToStringTag]() {
|
||||
return "CountQueuingStrategy";
|
||||
}
|
||||
}
|
||||
|
@ -3333,11 +3336,11 @@
|
|||
return iterator;
|
||||
}
|
||||
|
||||
[Symbol.for("Deno.privateCustomInspect")](inspect) {
|
||||
[SymbolFor("Deno.privateCustomInspect")](inspect) {
|
||||
return `${this.constructor.name} ${inspect({ locked: this.locked })}`;
|
||||
}
|
||||
|
||||
get [Symbol.toStringTag]() {
|
||||
get [SymbolToStringTag]() {
|
||||
return "ReadableStream";
|
||||
}
|
||||
}
|
||||
|
@ -3453,11 +3456,11 @@
|
|||
return readableStreamReaderGenericCancel(this, reason);
|
||||
}
|
||||
|
||||
[Symbol.for("Deno.privateCustomInspect")](inspect) {
|
||||
[SymbolFor("Deno.privateCustomInspect")](inspect) {
|
||||
return `${this.constructor.name} ${inspect({ closed: this.closed })}`;
|
||||
}
|
||||
|
||||
get [Symbol.toStringTag]() {
|
||||
get [SymbolToStringTag]() {
|
||||
return "ReadableStreamDefaultReader";
|
||||
}
|
||||
}
|
||||
|
@ -3571,7 +3574,7 @@
|
|||
readableByteStreamControllerError(this, e);
|
||||
}
|
||||
|
||||
[Symbol.for("Deno.customInspect")](inspect) {
|
||||
[SymbolFor("Deno.customInspect")](inspect) {
|
||||
return inspect(consoleInternal.createFilteredInspectProxy({
|
||||
object: this,
|
||||
evaluate: this instanceof ReadableByteStreamController,
|
||||
|
@ -3579,7 +3582,7 @@
|
|||
}));
|
||||
}
|
||||
|
||||
get [Symbol.toStringTag]() {
|
||||
get [SymbolToStringTag]() {
|
||||
return "ReadableByteStreamController";
|
||||
}
|
||||
|
||||
|
@ -3696,7 +3699,7 @@
|
|||
readableStreamDefaultControllerError(this, e);
|
||||
}
|
||||
|
||||
[Symbol.for("Deno.customInspect")](inspect) {
|
||||
[SymbolFor("Deno.customInspect")](inspect) {
|
||||
return inspect(consoleInternal.createFilteredInspectProxy({
|
||||
object: this,
|
||||
evaluate: this instanceof ReadableStreamDefaultController,
|
||||
|
@ -3704,7 +3707,7 @@
|
|||
}));
|
||||
}
|
||||
|
||||
get [Symbol.toStringTag]() {
|
||||
get [SymbolToStringTag]() {
|
||||
return "ReadableStreamDefaultController";
|
||||
}
|
||||
|
||||
|
@ -3854,13 +3857,13 @@
|
|||
return this[_writable];
|
||||
}
|
||||
|
||||
[Symbol.for("Deno.privateCustomInspect")](inspect) {
|
||||
[SymbolFor("Deno.privateCustomInspect")](inspect) {
|
||||
return `${this.constructor.name} ${
|
||||
inspect({ readable: this.readable, writable: this.writable })
|
||||
}`;
|
||||
}
|
||||
|
||||
get [Symbol.toStringTag]() {
|
||||
get [SymbolToStringTag]() {
|
||||
return "TransformStream";
|
||||
}
|
||||
}
|
||||
|
@ -3919,7 +3922,7 @@
|
|||
transformStreamDefaultControllerTerminate(this);
|
||||
}
|
||||
|
||||
[Symbol.for("Deno.customInspect")](inspect) {
|
||||
[SymbolFor("Deno.customInspect")](inspect) {
|
||||
return inspect(consoleInternal.createFilteredInspectProxy({
|
||||
object: this,
|
||||
evaluate: this instanceof TransformStreamDefaultController,
|
||||
|
@ -3927,7 +3930,7 @@
|
|||
}));
|
||||
}
|
||||
|
||||
get [Symbol.toStringTag]() {
|
||||
get [SymbolToStringTag]() {
|
||||
return "TransformStreamDefaultController";
|
||||
}
|
||||
}
|
||||
|
@ -4057,11 +4060,11 @@
|
|||
return acquireWritableStreamDefaultWriter(this);
|
||||
}
|
||||
|
||||
[Symbol.for("Deno.privateCustomInspect")](inspect) {
|
||||
[SymbolFor("Deno.privateCustomInspect")](inspect) {
|
||||
return `${this.constructor.name} ${inspect({ locked: this.locked })}`;
|
||||
}
|
||||
|
||||
get [Symbol.toStringTag]() {
|
||||
get [SymbolToStringTag]() {
|
||||
return "WritableStream";
|
||||
}
|
||||
}
|
||||
|
@ -4198,7 +4201,7 @@
|
|||
return writableStreamDefaultWriterWrite(this, chunk);
|
||||
}
|
||||
|
||||
[Symbol.for("Deno.customInspect")](inspect) {
|
||||
[SymbolFor("Deno.customInspect")](inspect) {
|
||||
return inspect(consoleInternal.createFilteredInspectProxy({
|
||||
object: this,
|
||||
evaluate: this instanceof WritableStreamDefaultWriter,
|
||||
|
@ -4210,7 +4213,7 @@
|
|||
}));
|
||||
}
|
||||
|
||||
get [Symbol.toStringTag]() {
|
||||
get [SymbolToStringTag]() {
|
||||
return "WritableStreamDefaultWriter";
|
||||
}
|
||||
}
|
||||
|
@ -4258,7 +4261,7 @@
|
|||
writableStreamDefaultControllerError(this, e);
|
||||
}
|
||||
|
||||
[Symbol.for("Deno.customInspect")](inspect) {
|
||||
[SymbolFor("Deno.customInspect")](inspect) {
|
||||
return inspect(consoleInternal.createFilteredInspectProxy({
|
||||
object: this,
|
||||
evaluate: this instanceof WritableStreamDefaultController,
|
||||
|
@ -4266,7 +4269,7 @@
|
|||
}));
|
||||
}
|
||||
|
||||
get [Symbol.toStringTag]() {
|
||||
get [SymbolToStringTag]() {
|
||||
return "WritableStreamDefaultController";
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
MapPrototypeGet,
|
||||
MapPrototypeSet,
|
||||
ObjectDefineProperty,
|
||||
queueMicrotask,
|
||||
StringFromCodePoint,
|
||||
Symbol,
|
||||
SymbolToStringTag,
|
||||
|
|
|
@ -14,6 +14,13 @@
|
|||
const { setEventTargetData } = window.__bootstrap.eventTarget;
|
||||
const { defineEventHandler } = window.__bootstrap.event;
|
||||
const { DOMException } = window.__bootstrap.domException;
|
||||
const {
|
||||
ObjectSetPrototypeOf,
|
||||
Symbol,
|
||||
SymbolFor,
|
||||
SymbolToStringTag,
|
||||
TypeError,
|
||||
} = window.__bootstrap.primordials;
|
||||
|
||||
class MessageChannel {
|
||||
/** @type {MessagePort} */
|
||||
|
@ -40,13 +47,13 @@
|
|||
return this.#port2;
|
||||
}
|
||||
|
||||
[Symbol.for("Deno.inspect")](inspect) {
|
||||
[SymbolFor("Deno.inspect")](inspect) {
|
||||
return `MessageChannel ${
|
||||
inspect({ port1: this.port1, port2: this.port2 })
|
||||
}`;
|
||||
}
|
||||
|
||||
get [Symbol.toStringTag]() {
|
||||
get [SymbolToStringTag]() {
|
||||
return "MessageChannel";
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +69,7 @@
|
|||
*/
|
||||
function createMessagePort(id) {
|
||||
const port = core.createHostObject();
|
||||
Object.setPrototypeOf(port, MessagePort.prototype);
|
||||
ObjectSetPrototypeOf(port, MessagePort.prototype);
|
||||
port[webidl.brand] = webidl.brand;
|
||||
setEventTargetData(port);
|
||||
port[_id] = id;
|
||||
|
@ -155,7 +162,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
get [Symbol.toStringTag]() {
|
||||
get [SymbolToStringTag]() {
|
||||
return "MessagePort";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,8 +12,10 @@
|
|||
const {
|
||||
ArrayBuffer,
|
||||
ArrayBufferIsView,
|
||||
ArrayPrototypeForEach,
|
||||
ArrayPrototypePush,
|
||||
ArrayPrototypeSort,
|
||||
ArrayIteratorPrototype,
|
||||
BigInt,
|
||||
BigIntAsIntN,
|
||||
BigIntAsUintN,
|
||||
|
@ -497,45 +499,48 @@
|
|||
ObjectGetPrototypeOf(Uint8Array).prototype,
|
||||
SymbolToStringTag,
|
||||
).get;
|
||||
[
|
||||
Int8Array,
|
||||
Int16Array,
|
||||
Int32Array,
|
||||
Uint8Array,
|
||||
Uint16Array,
|
||||
Uint32Array,
|
||||
Uint8ClampedArray,
|
||||
Float32Array,
|
||||
Float64Array,
|
||||
].forEach((func) => {
|
||||
const name = func.name;
|
||||
const article = RegExpPrototypeTest(/^[AEIOU]/, name) ? "an" : "a";
|
||||
converters[name] = (V, opts = {}) => {
|
||||
if (!ArrayBufferIsView(V) || typedArrayNameGetter.call(V) !== name) {
|
||||
throw makeException(
|
||||
TypeError,
|
||||
`is not ${article} ${name} object`,
|
||||
opts,
|
||||
);
|
||||
}
|
||||
if (!opts.allowShared && isSharedArrayBuffer(V.buffer)) {
|
||||
throw makeException(
|
||||
TypeError,
|
||||
"is a view on a SharedArrayBuffer, which is not allowed",
|
||||
opts,
|
||||
);
|
||||
}
|
||||
if (isArrayBufferDetached(V.buffer)) {
|
||||
throw makeException(
|
||||
TypeError,
|
||||
"is a view on a detached ArrayBuffer",
|
||||
opts,
|
||||
);
|
||||
}
|
||||
ArrayPrototypeForEach(
|
||||
[
|
||||
Int8Array,
|
||||
Int16Array,
|
||||
Int32Array,
|
||||
Uint8Array,
|
||||
Uint16Array,
|
||||
Uint32Array,
|
||||
Uint8ClampedArray,
|
||||
Float32Array,
|
||||
Float64Array,
|
||||
],
|
||||
(func) => {
|
||||
const name = func.name;
|
||||
const article = RegExpPrototypeTest(/^[AEIOU]/, name) ? "an" : "a";
|
||||
converters[name] = (V, opts = {}) => {
|
||||
if (!ArrayBufferIsView(V) || typedArrayNameGetter.call(V) !== name) {
|
||||
throw makeException(
|
||||
TypeError,
|
||||
`is not ${article} ${name} object`,
|
||||
opts,
|
||||
);
|
||||
}
|
||||
if (!opts.allowShared && isSharedArrayBuffer(V.buffer)) {
|
||||
throw makeException(
|
||||
TypeError,
|
||||
"is a view on a SharedArrayBuffer, which is not allowed",
|
||||
opts,
|
||||
);
|
||||
}
|
||||
if (isArrayBufferDetached(V.buffer)) {
|
||||
throw makeException(
|
||||
TypeError,
|
||||
"is a view on a detached ArrayBuffer",
|
||||
opts,
|
||||
);
|
||||
}
|
||||
|
||||
return V;
|
||||
};
|
||||
});
|
||||
return V;
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
// Common definitions
|
||||
|
||||
|
@ -921,9 +926,7 @@
|
|||
|
||||
const _iteratorInternal = Symbol("iterator internal");
|
||||
|
||||
const globalIteratorPrototype = ObjectGetPrototypeOf(ObjectGetPrototypeOf(
|
||||
[][SymbolIterator](),
|
||||
));
|
||||
const globalIteratorPrototype = ObjectGetPrototypeOf(ArrayIteratorPrototype);
|
||||
|
||||
function mixinPairIterable(name, prototype, dataSymbol, keyKey, valueKey) {
|
||||
const iteratorPrototype = ObjectCreate(globalIteratorPrototype, {
|
||||
|
|
|
@ -2,8 +2,14 @@
|
|||
"use strict";
|
||||
|
||||
((window) => {
|
||||
const { ObjectDefineProperty, StringPrototypeReplace, TypeError, Promise } =
|
||||
window.__bootstrap.primordials;
|
||||
const {
|
||||
ObjectDefineProperty,
|
||||
StringPrototypeReplace,
|
||||
TypeError,
|
||||
Promise,
|
||||
decodeURIComponent,
|
||||
Error,
|
||||
} = window.__bootstrap.primordials;
|
||||
const { build } = window.__bootstrap.build;
|
||||
const { URL } = window.__bootstrap.url;
|
||||
let logDebug = false;
|
||||
|
|
|
@ -552,7 +552,7 @@ delete Object.prototype.__proto__;
|
|||
ObjectDefineProperties(globalThis, windowOrWorkerGlobalScope);
|
||||
ObjectDefineProperties(globalThis, workerRuntimeGlobalProperties);
|
||||
ObjectDefineProperties(globalThis, { name: util.readOnly(name) });
|
||||
Object.setPrototypeOf(globalThis, DedicatedWorkerGlobalScope.prototype);
|
||||
ObjectSetPrototypeOf(globalThis, DedicatedWorkerGlobalScope.prototype);
|
||||
|
||||
const consoleFromDeno = globalThis.console;
|
||||
wrapConsole(consoleFromDeno, consoleFromV8);
|
||||
|
|
Loading…
Reference in a new issue