mirror of
https://github.com/denoland/deno.git
synced 2024-12-27 01:29:14 -05:00
fix(core): Use primordials for methods (#18839)
I would like to get this change into Deno before merging https://github.com/denoland/deno_lint/pull/1152
This commit is contained in:
parent
0ddad2486c
commit
3d0b879c0d
17 changed files with 378 additions and 270 deletions
|
@ -28,13 +28,13 @@
|
|||
SafeArrayIterator,
|
||||
SafeMap,
|
||||
SafePromisePrototypeFinally,
|
||||
setQueueMicrotask,
|
||||
StringPrototypeSlice,
|
||||
StringPrototypeSplit,
|
||||
SymbolFor,
|
||||
SyntaxError,
|
||||
TypeError,
|
||||
URIError,
|
||||
setQueueMicrotask,
|
||||
} = window.__bootstrap.primordials;
|
||||
const { ops, asyncOps } = window.Deno.core;
|
||||
|
||||
|
|
11
ext/cache/01_cache.js
vendored
11
ext/cache/01_cache.js
vendored
|
@ -4,9 +4,12 @@ const core = globalThis.Deno.core;
|
|||
import * as webidl from "ext:deno_webidl/00_webidl.js";
|
||||
const primordials = globalThis.__bootstrap.primordials;
|
||||
const {
|
||||
ArrayPrototypePush,
|
||||
ObjectPrototypeIsPrototypeOf,
|
||||
StringPrototypeSplit,
|
||||
StringPrototypeTrim,
|
||||
Symbol,
|
||||
TypeError,
|
||||
ObjectPrototypeIsPrototypeOf,
|
||||
} = primordials;
|
||||
import {
|
||||
Request,
|
||||
|
@ -101,10 +104,10 @@ class Cache {
|
|||
// Step 7.
|
||||
const varyHeader = getHeader(innerResponse.headerList, "vary");
|
||||
if (varyHeader) {
|
||||
const fieldValues = varyHeader.split(",");
|
||||
const fieldValues = StringPrototypeSplit(varyHeader, ",");
|
||||
for (let i = 0; i < fieldValues.length; ++i) {
|
||||
const field = fieldValues[i];
|
||||
if (field.trim() === "*") {
|
||||
if (StringPrototypeTrim(field) === "*") {
|
||||
throw new TypeError("Vary header must not contain '*'");
|
||||
}
|
||||
}
|
||||
|
@ -258,7 +261,7 @@ class Cache {
|
|||
statusText: meta.responseStatusText,
|
||||
},
|
||||
);
|
||||
responses.push(response);
|
||||
ArrayPrototypePush(responses, response);
|
||||
}
|
||||
}
|
||||
// Step 5.4-5.5: don't apply in this context.
|
||||
|
|
|
@ -6,118 +6,134 @@ const core = globalThis.Deno.core;
|
|||
const internals = globalThis.__bootstrap.internals;
|
||||
const primordials = globalThis.__bootstrap.primordials;
|
||||
const {
|
||||
DateNow,
|
||||
Boolean,
|
||||
ObjectKeys,
|
||||
ObjectAssign,
|
||||
ObjectCreate,
|
||||
ObjectFreeze,
|
||||
ObjectValues,
|
||||
ObjectFromEntries,
|
||||
ObjectPrototypeHasOwnProperty,
|
||||
ObjectPrototypeIsPrototypeOf,
|
||||
ObjectDefineProperty,
|
||||
String,
|
||||
SafeStringIterator,
|
||||
DatePrototype,
|
||||
MapPrototypeEntries,
|
||||
SetPrototypeGetSize,
|
||||
StringPrototypeRepeat,
|
||||
StringPrototypeEndsWith,
|
||||
StringPrototypeIndexOf,
|
||||
RegExpPrototypeExec,
|
||||
RegExpPrototypeSymbolReplace,
|
||||
StringPrototypeReplace,
|
||||
StringPrototypeReplaceAll,
|
||||
ObjectPrototype,
|
||||
FunctionPrototypeCall,
|
||||
StringPrototypeSplit,
|
||||
StringPrototypeSlice,
|
||||
StringPrototypeCharCodeAt,
|
||||
MathFloor,
|
||||
StringPrototypePadEnd,
|
||||
ObjectGetOwnPropertySymbols,
|
||||
ObjectGetOwnPropertyNames,
|
||||
SymbolPrototypeGetDescription,
|
||||
SymbolPrototypeToString,
|
||||
ArrayPrototypePushApply,
|
||||
ObjectPrototypePropertyIsEnumerable,
|
||||
StringPrototypeMatch,
|
||||
StringPrototypePadStart,
|
||||
StringPrototypeTrim,
|
||||
StringPrototypeIncludes,
|
||||
NumberIsInteger,
|
||||
NumberParseInt,
|
||||
SafeArrayIterator,
|
||||
SafeMap,
|
||||
ArrayPrototypeShift,
|
||||
AggregateErrorPrototype,
|
||||
RegExpPrototypeTest,
|
||||
ObjectPrototypeToString,
|
||||
ArrayPrototypeSort,
|
||||
ArrayPrototypeUnshift,
|
||||
DatePrototypeGetTime,
|
||||
DatePrototypeToISOString,
|
||||
SafeRegExp,
|
||||
SetPrototype,
|
||||
Symbol,
|
||||
SymbolToStringTag,
|
||||
SymbolHasInstance,
|
||||
SymbolFor,
|
||||
ObjectGetOwnPropertyDescriptor,
|
||||
ObjectIs,
|
||||
Uint8Array,
|
||||
isNaN,
|
||||
TypedArrayPrototypeGetSymbolToStringTag,
|
||||
TypedArrayPrototypeGetLength,
|
||||
ReflectOwnKeys,
|
||||
Array,
|
||||
RegExpPrototypeToString,
|
||||
ArrayIsArray,
|
||||
SymbolIterator,
|
||||
ArrayBufferIsView,
|
||||
ArrayPrototypeJoin,
|
||||
ArrayPrototypeMap,
|
||||
ArrayPrototypeReduce,
|
||||
ObjectSetPrototypeOf,
|
||||
ArrayPrototypePush,
|
||||
ArrayPrototypeIncludes,
|
||||
ArrayBufferPrototypeGetByteLength,
|
||||
ArrayIsArray,
|
||||
ArrayPrototypeFill,
|
||||
ArrayPrototypeFilter,
|
||||
ArrayPrototypeFind,
|
||||
FunctionPrototypeBind,
|
||||
MapPrototype,
|
||||
MapPrototypeHas,
|
||||
MapPrototypeGet,
|
||||
MapPrototypeSet,
|
||||
MapPrototypeDelete,
|
||||
MapPrototypeForEach,
|
||||
MapPrototypeGetSize,
|
||||
ArrayPrototypeForEach,
|
||||
ArrayPrototypeIncludes,
|
||||
ArrayPrototypeJoin,
|
||||
ArrayPrototypeMap,
|
||||
ArrayPrototypePop,
|
||||
ArrayPrototypePush,
|
||||
ArrayPrototypePushApply,
|
||||
ArrayPrototypeReduce,
|
||||
ArrayPrototypeShift,
|
||||
ArrayPrototypeSlice,
|
||||
ArrayPrototypeSort,
|
||||
ArrayPrototypeSplice,
|
||||
ArrayPrototypeUnshift,
|
||||
BigIntPrototypeValueOf,
|
||||
Boolean,
|
||||
BooleanPrototypeValueOf,
|
||||
DateNow,
|
||||
DatePrototype,
|
||||
DatePrototypeGetTime,
|
||||
DatePrototypeToISOString,
|
||||
Error,
|
||||
ErrorPrototype,
|
||||
ErrorCaptureStackTrace,
|
||||
MathSqrt,
|
||||
ErrorPrototype,
|
||||
FunctionPrototypeBind,
|
||||
FunctionPrototypeCall,
|
||||
FunctionPrototypeToString,
|
||||
MapPrototype,
|
||||
MapPrototypeDelete,
|
||||
MapPrototypeEntries,
|
||||
MapPrototypeForEach,
|
||||
MapPrototypeGet,
|
||||
MapPrototypeGetSize,
|
||||
MapPrototypeHas,
|
||||
MapPrototypeSet,
|
||||
MathAbs,
|
||||
MathFloor,
|
||||
MathMax,
|
||||
MathMin,
|
||||
MathRound,
|
||||
MathSqrt,
|
||||
Number,
|
||||
NumberIsInteger,
|
||||
NumberParseInt,
|
||||
NumberPrototypeToString,
|
||||
NumberPrototypeValueOf,
|
||||
ObjectAssign,
|
||||
ObjectCreate,
|
||||
ObjectDefineProperty,
|
||||
ObjectFreeze,
|
||||
ObjectFromEntries,
|
||||
ObjectGetOwnPropertyDescriptor,
|
||||
ObjectGetOwnPropertyNames,
|
||||
ObjectGetOwnPropertySymbols,
|
||||
ObjectGetPrototypeOf,
|
||||
ObjectIs,
|
||||
ObjectKeys,
|
||||
ObjectPrototype,
|
||||
ObjectPrototypeHasOwnProperty,
|
||||
ObjectPrototypeIsPrototypeOf,
|
||||
ObjectPrototypePropertyIsEnumerable,
|
||||
ObjectPrototypeToString,
|
||||
ObjectSetPrototypeOf,
|
||||
ObjectValues,
|
||||
Proxy,
|
||||
ReflectGet,
|
||||
ReflectGetOwnPropertyDescriptor,
|
||||
ReflectGetPrototypeOf,
|
||||
ReflectHas,
|
||||
BigIntPrototypeValueOf,
|
||||
ObjectGetPrototypeOf,
|
||||
FunctionPrototypeToString,
|
||||
StringPrototypeStartsWith,
|
||||
SetPrototypeValues,
|
||||
ReflectOwnKeys,
|
||||
RegExpPrototypeExec,
|
||||
RegExpPrototypeSymbolReplace,
|
||||
RegExpPrototypeTest,
|
||||
RegExpPrototypeToString,
|
||||
SafeArrayIterator,
|
||||
SafeMap,
|
||||
SafeMapIterator,
|
||||
SafeRegExp,
|
||||
SafeSet,
|
||||
SafeSetIterator,
|
||||
SafeStringIterator,
|
||||
SetPrototype,
|
||||
SetPrototypeAdd,
|
||||
SetPrototypeHas,
|
||||
SetPrototypeGetSize,
|
||||
SetPrototypeValues,
|
||||
String,
|
||||
StringPrototypeCharCodeAt,
|
||||
StringPrototypeCodePointAt,
|
||||
StringPrototypeEndsWith,
|
||||
StringPrototypeIncludes,
|
||||
StringPrototypeIndexOf,
|
||||
StringPrototypeLastIndexOf,
|
||||
StringPrototypeMatch,
|
||||
StringPrototypeNormalize,
|
||||
StringPrototypePadEnd,
|
||||
StringPrototypePadStart,
|
||||
StringPrototypeRepeat,
|
||||
StringPrototypeReplace,
|
||||
StringPrototypeReplaceAll,
|
||||
StringPrototypeSlice,
|
||||
StringPrototypeSplit,
|
||||
StringPrototypeStartsWith,
|
||||
StringPrototypeToLowerCase,
|
||||
StringPrototypeTrim,
|
||||
StringPrototypeValueOf,
|
||||
Symbol,
|
||||
SymbolFor,
|
||||
SymbolHasInstance,
|
||||
SymbolIterator,
|
||||
SymbolPrototypeGetDescription,
|
||||
SymbolPrototypeToString,
|
||||
SymbolPrototypeValueOf,
|
||||
SymbolToStringTag,
|
||||
TypedArrayPrototypeGetByteLength,
|
||||
SafeMapIterator,
|
||||
ArrayBufferPrototype,
|
||||
TypedArrayPrototypeGetLength,
|
||||
TypedArrayPrototypeGetSymbolToStringTag,
|
||||
Uint8Array,
|
||||
WeakMapPrototypeHas,
|
||||
WeakSetPrototypeHas,
|
||||
isNaN,
|
||||
} = primordials;
|
||||
|
||||
let noColor = false;
|
||||
|
@ -227,45 +243,9 @@ defineColorAlias("inverse", "swapColors");
|
|||
defineColorAlias("inverse", "swapcolors");
|
||||
defineColorAlias("doubleunderline", "doubleUnderline");
|
||||
|
||||
// https://tc39.es/ecma262/#sec-boolean.prototype.valueof
|
||||
const _booleanValueOf = Boolean.prototype.valueOf;
|
||||
|
||||
// https://tc39.es/ecma262/#sec-number.prototype.valueof
|
||||
const _numberValueOf = Number.prototype.valueOf;
|
||||
|
||||
// https://tc39.es/ecma262/#sec-string.prototype.valueof
|
||||
const _stringValueOf = String.prototype.valueOf;
|
||||
|
||||
// https://tc39.es/ecma262/#sec-symbol.prototype.valueof
|
||||
const _symbolValueOf = Symbol.prototype.valueOf;
|
||||
|
||||
// https://tc39.es/ecma262/#sec-weakmap.prototype.has
|
||||
const _weakMapHas = WeakMap.prototype.has;
|
||||
|
||||
// https://tc39.es/ecma262/#sec-weakset.prototype.has
|
||||
const _weakSetHas = WeakSet.prototype.has;
|
||||
|
||||
// https://tc39.es/ecma262/#sec-get-arraybuffer.prototype.bytelength
|
||||
const _getArrayBufferByteLength = ObjectGetOwnPropertyDescriptor(
|
||||
ArrayBufferPrototype,
|
||||
"byteLength",
|
||||
).get;
|
||||
|
||||
// https://tc39.es/ecma262/#sec-get-sharedarraybuffer.prototype.bytelength
|
||||
let _getSharedArrayBufferByteLength;
|
||||
|
||||
// https://tc39.es/ecma262/#sec-get-set.prototype.size
|
||||
const _getSetSize = ObjectGetOwnPropertyDescriptor(
|
||||
SetPrototype,
|
||||
"size",
|
||||
).get;
|
||||
|
||||
// https://tc39.es/ecma262/#sec-get-map.prototype.size
|
||||
const _getMapSize = ObjectGetOwnPropertyDescriptor(
|
||||
MapPrototype,
|
||||
"size",
|
||||
).get;
|
||||
|
||||
function isObjectLike(value) {
|
||||
return value !== null && typeof value === "object";
|
||||
}
|
||||
|
@ -284,7 +264,7 @@ export function isArgumentsObject(value) {
|
|||
|
||||
export function isArrayBuffer(value) {
|
||||
try {
|
||||
_getArrayBufferByteLength.call(value);
|
||||
ArrayBufferPrototypeGetByteLength(value);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
|
@ -311,7 +291,7 @@ export function isBooleanObject(value) {
|
|||
}
|
||||
|
||||
try {
|
||||
_booleanValueOf.call(value);
|
||||
BooleanPrototypeValueOf(value);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
|
@ -352,7 +332,7 @@ export function isGeneratorFunction(
|
|||
|
||||
export function isMap(value) {
|
||||
try {
|
||||
_getMapSize.call(value);
|
||||
MapPrototypeGetSize(value);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
|
@ -391,7 +371,7 @@ export function isNumberObject(value) {
|
|||
}
|
||||
|
||||
try {
|
||||
_numberValueOf.call(value);
|
||||
NumberPrototypeValueOf(value);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
|
@ -427,7 +407,7 @@ export function isRegExp(value) {
|
|||
|
||||
export function isSet(value) {
|
||||
try {
|
||||
_getSetSize.call(value);
|
||||
SetPrototypeGetSize(value);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
|
@ -454,7 +434,7 @@ export function isSharedArrayBuffer(
|
|||
).get;
|
||||
|
||||
try {
|
||||
_getSharedArrayBufferByteLength.call(value);
|
||||
FunctionPrototypeCall(_getSharedArrayBufferByteLength, value);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
|
@ -467,7 +447,7 @@ export function isStringObject(value) {
|
|||
}
|
||||
|
||||
try {
|
||||
_stringValueOf.call(value);
|
||||
StringPrototypeValueOf(value);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
|
@ -480,7 +460,7 @@ export function isSymbolObject(value) {
|
|||
}
|
||||
|
||||
try {
|
||||
_symbolValueOf.call(value);
|
||||
SymbolPrototypeValueOf(value);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
|
@ -491,7 +471,7 @@ export function isWeakMap(
|
|||
value,
|
||||
) {
|
||||
try {
|
||||
_weakMapHas.call(value, null);
|
||||
WeakMapPrototypeHas(value, null);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
|
@ -502,7 +482,7 @@ export function isWeakSet(
|
|||
value,
|
||||
) {
|
||||
try {
|
||||
_weakSetHas.call(value, null);
|
||||
WeakSetPrototypeHas(value, null);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
|
@ -552,7 +532,7 @@ const keyStrRegExp = new SafeRegExp("^[a-zA-Z_][a-zA-Z_0-9]*$");
|
|||
const numberRegExp = new SafeRegExp("^(0|[1-9][0-9]*)$");
|
||||
|
||||
// TODO(wafuwafu13): Figure out
|
||||
const escapeFn = (str) => meta[str.charCodeAt(0)];
|
||||
const escapeFn = (str) => meta[StringPrototypeCharCodeAt(str, 0)];
|
||||
|
||||
function stylizeNoColor(str) {
|
||||
return str;
|
||||
|
@ -711,16 +691,16 @@ function formatValue(
|
|||
|
||||
// Using an array here is actually better for the average case than using
|
||||
// a Set. `seen` will only check for the depth and will never grow too large.
|
||||
if (ctx.seen.includes(value)) {
|
||||
if (ArrayPrototypeIncludes(ctx.seen, value)) {
|
||||
let index = 1;
|
||||
if (ctx.circular === undefined) {
|
||||
ctx.circular = new SafeMap();
|
||||
ctx.circular.set(value, index);
|
||||
MapPrototypeSet(ctx.circular, value, index);
|
||||
} else {
|
||||
index = ctx.circular.get(value);
|
||||
if (index === undefined) {
|
||||
index = ctx.circular.size + 1;
|
||||
ctx.circular.set(value, index);
|
||||
MapPrototypeSet(ctx.circular, value, index);
|
||||
}
|
||||
}
|
||||
return ctx.stylize(`[Circular *${index}]`, "special");
|
||||
|
@ -1006,7 +986,7 @@ function formatRaw(ctx, value, recurseTimes, typedArray, proxyDetails) {
|
|||
} else if (isModuleNamespaceObject(value)) {
|
||||
braces[0] = `${getPrefix(constructor, tag, "Module")}{`;
|
||||
// Special handle keys for namespace objects.
|
||||
formatter = formatNamespaceObject.bind(null, keys);
|
||||
formatter = FunctionPrototypeBind(formatNamespaceObject, null, keys);
|
||||
} else if (isBoxedPrimitive(value)) {
|
||||
base = getBoxedBase(value, ctx, keys, constructor, tag);
|
||||
if (keys.length === 0 && protoProps === undefined) {
|
||||
|
@ -1039,7 +1019,7 @@ function formatRaw(ctx, value, recurseTimes, typedArray, proxyDetails) {
|
|||
}
|
||||
recurseTimes += 1;
|
||||
|
||||
ctx.seen.push(value);
|
||||
ArrayPrototypePush(ctx.seen, value);
|
||||
ctx.currentDepth = recurseTimes;
|
||||
let output;
|
||||
const indentationLvl = ctx.indentationLvl;
|
||||
|
@ -1075,15 +1055,19 @@ function formatRaw(ctx, value, recurseTimes, typedArray, proxyDetails) {
|
|||
}
|
||||
}
|
||||
}
|
||||
ctx.seen.pop();
|
||||
ArrayPrototypePop(ctx.seen);
|
||||
|
||||
if (ctx.sorted) {
|
||||
const comparator = ctx.sorted === true ? undefined : ctx.sorted;
|
||||
if (extrasType === kObjectType) {
|
||||
output = ArrayPrototypeSort(output, comparator);
|
||||
} else if (keys.length > 1) {
|
||||
const sorted = output.slice(output.length - keys.length).sort(comparator);
|
||||
output.splice(
|
||||
const sorted = ArrayPrototypeSort(
|
||||
ArrayPrototypeSlice(output, output.length - keys.length),
|
||||
comparator,
|
||||
);
|
||||
ArrayPrototypeSplice(
|
||||
output,
|
||||
output.length - keys.length,
|
||||
keys.length,
|
||||
...new SafeArrayIterator(sorted),
|
||||
|
@ -1118,8 +1102,9 @@ function formatRaw(ctx, value, recurseTimes, typedArray, proxyDetails) {
|
|||
|
||||
const builtInObjectsRegExp = new SafeRegExp("^[A-Z][a-zA-Z0-9]+$");
|
||||
const builtInObjects = new SafeSet(
|
||||
ObjectGetOwnPropertyNames(globalThis).filter((e) =>
|
||||
builtInObjectsRegExp.test(e)
|
||||
ArrayPrototypeFilter(
|
||||
ObjectGetOwnPropertyNames(globalThis),
|
||||
(e) => RegExpPrototypeTest(builtInObjectsRegExp, e),
|
||||
),
|
||||
);
|
||||
|
||||
|
@ -1145,7 +1130,7 @@ function addPrototypeProperties(
|
|||
if (
|
||||
descriptor !== undefined &&
|
||||
typeof descriptor.value === "function" &&
|
||||
builtInObjects.has(descriptor.value.name)
|
||||
SetPrototypeHas(builtInObjects, descriptor.value.name)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
@ -1154,18 +1139,17 @@ function addPrototypeProperties(
|
|||
if (depth === 0) {
|
||||
keySet = new SafeSet();
|
||||
} else {
|
||||
Array.prototype.forEach.call(keys, (key) => keySet.add(key));
|
||||
ArrayPrototypeForEach(keys, (key) => SetPrototypeAdd(keySet, key));
|
||||
}
|
||||
// Get all own property names and symbols.
|
||||
keys = ReflectOwnKeys(obj);
|
||||
Array.prototype.push.call(ctx.seen, main);
|
||||
ArrayPrototypePush(ctx.seen, main);
|
||||
for (const key of new SafeArrayIterator(keys)) {
|
||||
// Ignore the `constructor` property and keys that exist on layers above.
|
||||
if (
|
||||
key === "constructor" ||
|
||||
// deno-lint-ignore no-prototype-builtins
|
||||
main.hasOwnProperty(key) ||
|
||||
(depth !== 0 && keySet.has(key))
|
||||
ObjectPrototypeHasOwnProperty(main, key) ||
|
||||
(depth !== 0 && SetPrototypeHas(keySet, key))
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
@ -1184,12 +1168,12 @@ function addPrototypeProperties(
|
|||
);
|
||||
if (ctx.colors) {
|
||||
// Faint!
|
||||
Array.prototype.push.call(output, `\u001b[2m${value}\u001b[22m`);
|
||||
ArrayPrototypePush(output, `\u001b[2m${value}\u001b[22m`);
|
||||
} else {
|
||||
Array.prototype.push.call(output, value);
|
||||
ArrayPrototypePush(output, value);
|
||||
}
|
||||
}
|
||||
Array.prototype.pop.call(ctx.seen);
|
||||
ArrayPrototypePop(ctx.seen);
|
||||
// Limit the inspection to up to three prototype layers. Using `recurseTimes`
|
||||
// is not a good choice here, because it's as if the properties are declared
|
||||
// on the current object from the users perspective.
|
||||
|
@ -1218,7 +1202,7 @@ function getConstructorName(obj, ctx, recurseTimes, protoProps) {
|
|||
if (
|
||||
protoProps !== undefined &&
|
||||
(firstProto !== obj ||
|
||||
!builtInObjects.has(descriptor.value.name))
|
||||
!SetPrototypeHas(builtInObjects, descriptor.value.name))
|
||||
) {
|
||||
addPrototypeProperties(
|
||||
ctx,
|
||||
|
@ -1273,7 +1257,7 @@ function formatPrimitive(fn, value, ctx) {
|
|||
let trailer = "";
|
||||
if (value.length > ctx.maxStringLength) {
|
||||
const remaining = value.length - ctx.maxStringLength;
|
||||
value = value.slice(0, ctx.maxStringLength);
|
||||
value = StringPrototypeSlice(value, 0, ctx.maxStringLength);
|
||||
trailer = `... ${remaining} more character${remaining > 1 ? "s" : ""}`;
|
||||
}
|
||||
if (
|
||||
|
@ -1283,10 +1267,13 @@ function formatPrimitive(fn, value, ctx) {
|
|||
value.length > kMinLineLength &&
|
||||
value.length > ctx.breakLength - ctx.indentationLvl - 4
|
||||
) {
|
||||
return value
|
||||
.split(formatPrimitiveRegExp)
|
||||
.map((line) => fn(quoteString(line, ctx), "string"))
|
||||
.join(` +\n${" ".repeat(ctx.indentationLvl + 2)}`) + trailer;
|
||||
return ArrayPrototypeJoin(
|
||||
ArrayPrototypeMap(
|
||||
StringPrototypeSplit(value, formatPrimitiveRegExp),
|
||||
(line) => fn(quoteString(line, ctx), "string"),
|
||||
),
|
||||
` +\n${StringPrototypeRepeat(" ", ctx.indentationLvl + 2)}`,
|
||||
) + trailer;
|
||||
}
|
||||
return fn(quoteString(value, ctx), "string") + trailer;
|
||||
}
|
||||
|
@ -1328,14 +1315,19 @@ function formatArray(ctx, value, recurseTimes) {
|
|||
const output = [];
|
||||
for (let i = 0; i < len; i++) {
|
||||
// Special handle sparse arrays.
|
||||
// deno-lint-ignore no-prototype-builtins
|
||||
if (!value.hasOwnProperty(i)) {
|
||||
if (!ObjectPrototypeHasOwnProperty(value, i)) {
|
||||
return formatSpecialArray(ctx, value, recurseTimes, len, output, i);
|
||||
}
|
||||
output.push(formatProperty(ctx, value, recurseTimes, i, kArrayType));
|
||||
ArrayPrototypePush(
|
||||
output,
|
||||
formatProperty(ctx, value, recurseTimes, i, kArrayType),
|
||||
);
|
||||
}
|
||||
if (remaining > 0) {
|
||||
output.push(`... ${remaining} more item${remaining > 1 ? "s" : ""}`);
|
||||
ArrayPrototypePush(
|
||||
output,
|
||||
`... ${remaining} more item${remaining > 1 ? "s" : ""}`,
|
||||
);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
@ -1393,10 +1385,13 @@ function formatSet(value, ctx, _ignored, recurseTimes) {
|
|||
const remaining = valLen - len;
|
||||
const output = [];
|
||||
for (let i = 0; i < len; i++) {
|
||||
output.push(formatValue(ctx, values[i], recurseTimes));
|
||||
ArrayPrototypePush(output, formatValue(ctx, values[i], recurseTimes));
|
||||
}
|
||||
if (remaining > 0) {
|
||||
output.push(`... ${remaining} more item${remaining > 1 ? "s" : ""}`);
|
||||
ArrayPrototypePush(
|
||||
output,
|
||||
`... ${remaining} more item${remaining > 1 ? "s" : ""}`,
|
||||
);
|
||||
}
|
||||
|
||||
ctx.indentationLvl -= 2;
|
||||
|
@ -1413,14 +1408,18 @@ function formatMap(value, ctx, _gnored, recurseTimes) {
|
|||
const remaining = valLen - len;
|
||||
const output = [];
|
||||
for (let i = 0; i < len; i++) {
|
||||
output.push(
|
||||
ArrayPrototypePush(
|
||||
output,
|
||||
`${formatValue(ctx, values[i][0], recurseTimes)} => ${
|
||||
formatValue(ctx, values[i][1], recurseTimes)
|
||||
}`,
|
||||
);
|
||||
}
|
||||
if (remaining > 0) {
|
||||
output.push(`... ${remaining} more item${remaining > 1 ? "s" : ""}`);
|
||||
ArrayPrototypePush(
|
||||
output,
|
||||
`... ${remaining} more item${remaining > 1 ? "s" : ""}`,
|
||||
);
|
||||
}
|
||||
|
||||
ctx.indentationLvl -= 2;
|
||||
|
@ -1460,7 +1459,7 @@ function formatTypedArray(
|
|||
])
|
||||
) {
|
||||
const str = formatValue(ctx, value[key], recurseTimes, true);
|
||||
Array.prototype.push.call(output, `[${key}]: ${str}`);
|
||||
ArrayPrototypePush(output, `[${key}]: ${str}`);
|
||||
}
|
||||
ctx.indentationLvl -= 2;
|
||||
}
|
||||
|
@ -1484,7 +1483,11 @@ function formatIterator(braces, ctx, value, recurseTimes) {
|
|||
const { 0: entries, 1: isKeyValue } = value;
|
||||
if (isKeyValue) {
|
||||
// Mark entry iterators as such.
|
||||
braces[0] = braces[0].replace(iteratorRegExp, " Entries] {");
|
||||
braces[0] = StringPrototypeReplace(
|
||||
braces[0],
|
||||
iteratorRegExp,
|
||||
" Entries] {",
|
||||
);
|
||||
return formatMapIterInner(ctx, recurseTimes, entries, kMapEntries);
|
||||
}
|
||||
|
||||
|
@ -1627,8 +1630,13 @@ function formatArrayBuffer(ctx, value) {
|
|||
} catch {
|
||||
return [ctx.stylize("(detached)", "special")];
|
||||
}
|
||||
let str = hexSlice(buffer, 0, MathMin(ctx.maxArrayLength, buffer.length))
|
||||
.replace(arrayBufferRegExp, "$1 ").trim();
|
||||
let str = StringPrototypeTrim(
|
||||
StringPrototypeReplace(
|
||||
hexSlice(buffer, 0, MathMin(ctx.maxArrayLength, buffer.length)),
|
||||
arrayBufferRegExp,
|
||||
"$1 ",
|
||||
),
|
||||
);
|
||||
|
||||
const remaining = buffer.length - ctx.maxArrayLength;
|
||||
if (remaining > 0) {
|
||||
|
@ -1703,7 +1711,7 @@ function formatProperty(
|
|||
ctx.indentationLvl += diff;
|
||||
str = formatValue(ctx, desc.value, recurseTimes);
|
||||
if (diff === 3 && ctx.breakLength < getStringWidth(str, ctx.colors)) {
|
||||
extra = `\n${" ".repeat(ctx.indentationLvl)}`;
|
||||
extra = `\n${StringPrototypeRepeat(" ", ctx.indentationLvl)}`;
|
||||
}
|
||||
ctx.indentationLvl -= diff;
|
||||
} else if (desc.get !== undefined) {
|
||||
|
@ -1716,7 +1724,7 @@ function formatProperty(
|
|||
(ctx.getters === "set" && desc.set !== undefined))
|
||||
) {
|
||||
try {
|
||||
const tmp = desc.get.call(original);
|
||||
const tmp = FunctionPrototypeCall(desc.get, original);
|
||||
ctx.indentationLvl += 2;
|
||||
if (tmp === null) {
|
||||
str = `${s(`[${label}:`, sp)} ${s("null", "null")}${s("]", sp)}`;
|
||||
|
@ -1747,7 +1755,11 @@ function formatProperty(
|
|||
} else if (key === "__proto__") {
|
||||
name = "['__proto__']";
|
||||
} else if (desc.enumerable === false) {
|
||||
const tmp = key.replace(strEscapeSequencesReplacer, escapeFn);
|
||||
const tmp = StringPrototypeReplace(
|
||||
key,
|
||||
strEscapeSequencesReplacer,
|
||||
escapeFn,
|
||||
);
|
||||
|
||||
name = `[${tmp}]`;
|
||||
} else if (keyStrRegExp.test(key)) {
|
||||
|
@ -1780,7 +1792,7 @@ function handleMaxCallStackSize(
|
|||
|
||||
const colorRegExp = new SafeRegExp("\u001b\\[\\d\\d?m", "g");
|
||||
function removeColors(str) {
|
||||
return str.replace(colorRegExp, "");
|
||||
return StringPrototypeReplace(str, colorRegExp, "");
|
||||
}
|
||||
|
||||
function isBelowBreakLength(ctx, output, start, base) {
|
||||
|
@ -1836,10 +1848,10 @@ function formatNamespaceObject(
|
|||
// this aligned, even though this is a hacky way of dealing with this.
|
||||
const tmp = { [keys[i]]: "" };
|
||||
output[i] = formatProperty(ctx, tmp, recurseTimes, keys[i], kObjectType);
|
||||
const pos = output[i].lastIndexOf(" ");
|
||||
const pos = StringPrototypeLastIndexOf(output[i], " ");
|
||||
// We have to find the last whitespace and have to replace that value as
|
||||
// it will be visualized as a regular string.
|
||||
output[i] = output[i].slice(0, pos + 1) +
|
||||
output[i] = StringPrototypeSlice(output[i], 0, pos + 1) +
|
||||
ctx.stylize("<uninitialized>", "special");
|
||||
}
|
||||
}
|
||||
|
@ -1873,13 +1885,16 @@ function formatSpecialArray(
|
|||
const emptyItems = tmp - index;
|
||||
const ending = emptyItems > 1 ? "s" : "";
|
||||
const message = `<${emptyItems} empty item${ending}>`;
|
||||
output.push(ctx.stylize(message, "undefined"));
|
||||
ArrayPrototypePush(output, ctx.stylize(message, "undefined"));
|
||||
index = tmp;
|
||||
if (output.length === maxLength) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
output.push(formatProperty(ctx, value, recurseTimes, key, kArrayType));
|
||||
ArrayPrototypePush(
|
||||
output,
|
||||
formatProperty(ctx, value, recurseTimes, key, kArrayType),
|
||||
);
|
||||
index++;
|
||||
}
|
||||
const remaining = value.length - index;
|
||||
|
@ -1887,10 +1902,13 @@ function formatSpecialArray(
|
|||
if (remaining > 0) {
|
||||
const ending = remaining > 1 ? "s" : "";
|
||||
const message = `<${remaining} empty item${ending}>`;
|
||||
output.push(ctx.stylize(message, "undefined"));
|
||||
ArrayPrototypePush(output, ctx.stylize(message, "undefined"));
|
||||
}
|
||||
} else if (remaining > 0) {
|
||||
output.push(`... ${remaining} more item${remaining > 1 ? "s" : ""}`);
|
||||
ArrayPrototypePush(
|
||||
output,
|
||||
`... ${remaining} more item${remaining > 1 ? "s" : ""}`,
|
||||
);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
@ -1902,22 +1920,28 @@ function getBoxedBase(
|
|||
constructor,
|
||||
tag,
|
||||
) {
|
||||
let type;
|
||||
let type, primitive;
|
||||
if (isNumberObject(value)) {
|
||||
type = "Number";
|
||||
primitive = NumberPrototypeValueOf(value);
|
||||
} else if (isStringObject(value)) {
|
||||
type = "String";
|
||||
primitive = StringPrototypeValueOf(value);
|
||||
// For boxed Strings, we have to remove the 0-n indexed entries,
|
||||
// since they just noisy up the output and are redundant
|
||||
// Make boxed primitive Strings look like such
|
||||
keys.splice(0, value.length);
|
||||
ArrayPrototypeSplice(keys, 0, value.length);
|
||||
} else if (isBooleanObject(value)) {
|
||||
type = "Boolean";
|
||||
primitive = BooleanPrototypeValueOf(value);
|
||||
} else if (isBigIntObject(value)) {
|
||||
type = "BigInt";
|
||||
primitive = BigIntPrototypeValueOf(value);
|
||||
} else {
|
||||
type = "Symbol";
|
||||
primitive = SymbolPrototypeValueOf(value);
|
||||
}
|
||||
|
||||
let base = `[${type}`;
|
||||
if (type !== constructor) {
|
||||
if (constructor === null) {
|
||||
|
@ -1926,15 +1950,14 @@ function getBoxedBase(
|
|||
base += ` (${constructor})`;
|
||||
}
|
||||
}
|
||||
|
||||
base += `: ${formatPrimitive(stylizeNoColor, value.valueOf(), ctx)}]`;
|
||||
base += `: ${formatPrimitive(stylizeNoColor, primitive, ctx)}]`;
|
||||
if (tag !== "" && tag !== constructor) {
|
||||
base += ` [${tag}]`;
|
||||
}
|
||||
if (keys.length !== 0 || ctx.stylize === stylizeNoColor) {
|
||||
return base;
|
||||
}
|
||||
return ctx.stylize(base, type.toLowerCase());
|
||||
return ctx.stylize(base, StringPrototypeToLowerCase(type));
|
||||
}
|
||||
|
||||
function reduceToSingleString(
|
||||
|
@ -2140,7 +2163,7 @@ function formatMapIterInner(
|
|||
const len = entries.length / 2;
|
||||
const remaining = len - maxArrayLength;
|
||||
const maxLength = MathMin(maxArrayLength, len);
|
||||
let output = new Array(maxLength);
|
||||
const output = new Array(maxLength);
|
||||
let i = 0;
|
||||
ctx.indentationLvl += 2;
|
||||
if (state === kWeak) {
|
||||
|
@ -2154,7 +2177,7 @@ function formatMapIterInner(
|
|||
// retrieved ones exist, we can not reliably return the same output) if the
|
||||
// output is not sorted anyway.
|
||||
if (!ctx.sorted) {
|
||||
output = output.sort();
|
||||
ArrayPrototypeSort(output);
|
||||
}
|
||||
} else {
|
||||
for (; i < maxLength; i++) {
|
||||
|
@ -2175,7 +2198,10 @@ function formatMapIterInner(
|
|||
}
|
||||
ctx.indentationLvl -= 2;
|
||||
if (remaining > 0) {
|
||||
output.push(`... ${remaining} more item${remaining > 1 ? "s" : ""}`);
|
||||
ArrayPrototypePush(
|
||||
output,
|
||||
`... ${remaining} more item${remaining > 1 ? "s" : ""}`,
|
||||
);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
@ -2198,11 +2224,11 @@ function formatSetIterInner(
|
|||
// Sort all entries to have a halfway reliable output (if more entries than
|
||||
// retrieved ones exist, we can not reliably return the same output) if the
|
||||
// output is not sorted anyway.
|
||||
output.sort();
|
||||
ArrayPrototypeSort(output);
|
||||
}
|
||||
const remaining = entries.length - maxLength;
|
||||
if (remaining > 0) {
|
||||
Array.prototype.push.call(
|
||||
ArrayPrototypePush(
|
||||
output,
|
||||
`... ${remaining} more item${remaining > 1 ? "s" : ""}`,
|
||||
);
|
||||
|
@ -2229,9 +2255,9 @@ export function getStringWidth(str, removeControlChars = true) {
|
|||
if (removeControlChars) {
|
||||
str = stripVTControlCharacters(str);
|
||||
}
|
||||
str = str.normalize("NFC");
|
||||
str = StringPrototypeNormalize(str, "NFC");
|
||||
for (const char of new SafeStringIterator(str)) {
|
||||
const code = char.codePointAt(0);
|
||||
const code = StringPrototypeCodePointAt(char, 0);
|
||||
if (isFullWidthCodePoint(code)) {
|
||||
width += 2;
|
||||
} else if (!isZeroWidthCodePoint(code)) {
|
||||
|
@ -2258,7 +2284,7 @@ const isZeroWidthCodePoint = (code) => {
|
|||
* Remove all VT control characters. Use to estimate displayed string width.
|
||||
*/
|
||||
export function stripVTControlCharacters(str) {
|
||||
return str.replace(ansi, "");
|
||||
return StringPrototypeReplace(str, ansi, "");
|
||||
}
|
||||
|
||||
function hasOwnProperty(obj, v) {
|
||||
|
@ -2353,7 +2379,10 @@ function cliTable(head, columns) {
|
|||
(n, a) => MathMax(n, a.length),
|
||||
0,
|
||||
);
|
||||
const columnRightAlign = new Array(columnWidths.length).fill(true);
|
||||
const columnRightAlign = ArrayPrototypeFill(
|
||||
new Array(columnWidths.length),
|
||||
true,
|
||||
);
|
||||
|
||||
for (let i = 0; i < head.length; i++) {
|
||||
const column = columns[i];
|
||||
|
@ -3349,7 +3378,7 @@ class Console {
|
|||
const values = [];
|
||||
|
||||
let hasPrimitives = false;
|
||||
keys.forEach((k, idx) => {
|
||||
ArrayPrototypeForEach(keys, (k, idx) => {
|
||||
const value = resultData[k];
|
||||
const primitive = value === null ||
|
||||
(typeof value !== "function" && typeof value !== "object");
|
||||
|
|
|
@ -12,11 +12,12 @@ const primordials = globalThis.__bootstrap.primordials;
|
|||
import * as webidl from "ext:deno_webidl/00_webidl.js";
|
||||
import DOMException from "ext:deno_web/01_dom_exception.js";
|
||||
const {
|
||||
ArrayBufferPrototype,
|
||||
ArrayBufferPrototypeSlice,
|
||||
ArrayBufferPrototypeGetByteLength,
|
||||
ArrayBufferIsView,
|
||||
ArrayBufferPrototype,
|
||||
ArrayBufferPrototypeGetByteLength,
|
||||
ArrayBufferPrototypeSlice,
|
||||
ArrayPrototypeEvery,
|
||||
ArrayPrototypeFilter,
|
||||
ArrayPrototypeFind,
|
||||
ArrayPrototypeIncludes,
|
||||
DataViewPrototypeGetBuffer,
|
||||
|
@ -28,21 +29,21 @@ const {
|
|||
ObjectAssign,
|
||||
ObjectPrototypeHasOwnProperty,
|
||||
ObjectPrototypeIsPrototypeOf,
|
||||
StringPrototypeToLowerCase,
|
||||
StringPrototypeToUpperCase,
|
||||
StringPrototypeCharCodeAt,
|
||||
StringFromCharCode,
|
||||
SafeArrayIterator,
|
||||
SafeWeakMap,
|
||||
StringFromCharCode,
|
||||
StringPrototypeCharCodeAt,
|
||||
StringPrototypeToLowerCase,
|
||||
StringPrototypeToUpperCase,
|
||||
Symbol,
|
||||
SymbolFor,
|
||||
SyntaxError,
|
||||
TypedArrayPrototypeSlice,
|
||||
TypeError,
|
||||
TypedArrayPrototypeGetBuffer,
|
||||
TypedArrayPrototypeGetByteLength,
|
||||
TypedArrayPrototypeGetByteOffset,
|
||||
TypedArrayPrototypeGetSymbolToStringTag,
|
||||
TypeError,
|
||||
TypedArrayPrototypeSlice,
|
||||
Uint8Array,
|
||||
WeakMapPrototypeGet,
|
||||
WeakMapPrototypeSet,
|
||||
|
@ -388,7 +389,10 @@ function constructKey(type, extractable, usages, algorithm, handle) {
|
|||
* @returns
|
||||
*/
|
||||
function usageIntersection(a, b) {
|
||||
return a.filter((i) => b.includes(i));
|
||||
return ArrayPrototypeFilter(
|
||||
a,
|
||||
(i) => ArrayPrototypeIncludes(b, i),
|
||||
);
|
||||
}
|
||||
|
||||
// TODO(lucacasonato): this should be moved to rust
|
||||
|
|
|
@ -37,6 +37,7 @@ const {
|
|||
ObjectKeys,
|
||||
ObjectPrototypeIsPrototypeOf,
|
||||
RegExpPrototypeTest,
|
||||
StringPrototypeStartsWith,
|
||||
Symbol,
|
||||
SymbolFor,
|
||||
TypeError,
|
||||
|
@ -90,7 +91,11 @@ function processUrlList(urlList, urlListProcessed) {
|
|||
*/
|
||||
function newInnerRequest(method, url, headerList, body, maybeBlob) {
|
||||
let blobUrlEntry = null;
|
||||
if (maybeBlob && typeof url === "string" && url.startsWith("blob:")) {
|
||||
if (
|
||||
maybeBlob &&
|
||||
typeof url === "string" &&
|
||||
StringPrototypeStartsWith(url, "blob:")
|
||||
) {
|
||||
blobUrlEntry = blobFromObjectUrl(url);
|
||||
}
|
||||
return {
|
||||
|
|
|
@ -7,12 +7,15 @@ const {
|
|||
ArrayPrototypeFilter,
|
||||
Date,
|
||||
DatePrototype,
|
||||
DatePrototypeGetTime,
|
||||
Error,
|
||||
Function,
|
||||
MathTrunc,
|
||||
ObjectEntries,
|
||||
ObjectPrototypeIsPrototypeOf,
|
||||
ObjectValues,
|
||||
StringPrototypeSlice,
|
||||
StringPrototypeStartsWith,
|
||||
SymbolAsyncIterator,
|
||||
SymbolIterator,
|
||||
Uint32Array,
|
||||
|
@ -232,8 +235,8 @@ function createByteStruct(types) {
|
|||
for (let i = 0; i < typeEntries.length; ++i) {
|
||||
let { 0: name, 1: type } = typeEntries[i];
|
||||
|
||||
const optional = type.startsWith("?");
|
||||
if (optional) type = type.slice(1);
|
||||
const optional = StringPrototypeStartsWith(type, "?");
|
||||
if (optional) type = StringPrototypeSlice(type, 1);
|
||||
|
||||
if (type == "u64") {
|
||||
if (!optional) {
|
||||
|
@ -369,7 +372,7 @@ async function link(oldpath, newpath) {
|
|||
|
||||
function toUnixTimeFromEpoch(value) {
|
||||
if (ObjectPrototypeIsPrototypeOf(DatePrototype, value)) {
|
||||
const time = value.valueOf();
|
||||
const time = DatePrototypeGetTime(value);
|
||||
const seconds = MathTrunc(time / 1e3);
|
||||
const nanoseconds = MathTrunc(time - (seconds * 1e3)) * 1e6;
|
||||
|
||||
|
|
|
@ -37,14 +37,15 @@ import {
|
|||
import { TcpConn } from "ext:deno_net/01_net.js";
|
||||
const {
|
||||
ObjectPrototypeIsPrototypeOf,
|
||||
PromisePrototypeCatch,
|
||||
SafeSet,
|
||||
SafeSetIterator,
|
||||
SetPrototypeAdd,
|
||||
SetPrototypeDelete,
|
||||
Symbol,
|
||||
TypeError,
|
||||
Uint8ArrayPrototype,
|
||||
Uint8Array,
|
||||
Uint8ArrayPrototype,
|
||||
} = primordials;
|
||||
|
||||
const {
|
||||
|
@ -667,7 +668,7 @@ async function serve(arg1, arg2) {
|
|||
if (req === 0xffffffff) {
|
||||
break;
|
||||
}
|
||||
callback(req).catch((error) => {
|
||||
PromisePrototypeCatch(callback(req), (error) => {
|
||||
// Abnormal exit
|
||||
console.error(
|
||||
"Terminating Deno.serve loop due to unexpected error",
|
||||
|
|
|
@ -54,8 +54,9 @@ const {
|
|||
SetPrototypeDelete,
|
||||
StringPrototypeCharCodeAt,
|
||||
StringPrototypeIncludes,
|
||||
StringPrototypeToLowerCase,
|
||||
StringPrototypeSplit,
|
||||
StringPrototypeToLowerCase,
|
||||
StringPrototypeToUpperCase,
|
||||
Symbol,
|
||||
SymbolAsyncIterator,
|
||||
TypeError,
|
||||
|
@ -497,17 +498,20 @@ function buildCaseInsensitiveCommaValueFinder(checkText) {
|
|||
StringPrototypeToLowerCase(checkText),
|
||||
"",
|
||||
),
|
||||
(c) => [c.charCodeAt(0), c.toUpperCase().charCodeAt(0)],
|
||||
(c) => [
|
||||
StringPrototypeCharCodeAt(c, 0),
|
||||
StringPrototypeCharCodeAt(StringPrototypeToUpperCase(c), 0),
|
||||
],
|
||||
);
|
||||
/** @type {number} */
|
||||
let i;
|
||||
/** @type {number} */
|
||||
let char;
|
||||
|
||||
/** @param value {string} */
|
||||
/** @param {string} value */
|
||||
return function (value) {
|
||||
for (i = 0; i < value.length; i++) {
|
||||
char = value.charCodeAt(i);
|
||||
char = StringPrototypeCharCodeAt(value, i);
|
||||
skipWhitespace(value);
|
||||
|
||||
if (hasWord(value)) {
|
||||
|
|
|
@ -11,13 +11,16 @@ import {
|
|||
import * as abortSignal from "ext:deno_web/03_abort_signal.js";
|
||||
const primordials = globalThis.__bootstrap.primordials;
|
||||
const {
|
||||
ArrayPrototypeFilter,
|
||||
ArrayPrototypeForEach,
|
||||
ArrayPrototypePush,
|
||||
Error,
|
||||
ObjectPrototypeIsPrototypeOf,
|
||||
PromiseResolve,
|
||||
SymbolAsyncIterator,
|
||||
SymbolFor,
|
||||
TypedArrayPrototypeSubarray,
|
||||
TypeError,
|
||||
TypedArrayPrototypeSubarray,
|
||||
Uint8Array,
|
||||
} = primordials;
|
||||
|
||||
|
@ -97,15 +100,16 @@ class Conn {
|
|||
const promise = core.read(this.rid, buffer);
|
||||
const promiseId = promise[promiseIdSymbol];
|
||||
if (this.#unref) core.unrefOp(promiseId);
|
||||
this.#pendingReadPromiseIds.push(promiseId);
|
||||
ArrayPrototypePush(this.#pendingReadPromiseIds, promiseId);
|
||||
let nread;
|
||||
try {
|
||||
nread = await promise;
|
||||
} catch (e) {
|
||||
throw e;
|
||||
} finally {
|
||||
this.#pendingReadPromiseIds = this.#pendingReadPromiseIds.filter((id) =>
|
||||
id !== promiseId
|
||||
this.#pendingReadPromiseIds = ArrayPrototypeFilter(
|
||||
this.#pendingReadPromiseIds,
|
||||
(id) => id !== promiseId,
|
||||
);
|
||||
}
|
||||
return nread === 0 ? null : nread;
|
||||
|
@ -141,7 +145,7 @@ class Conn {
|
|||
if (this.#readable) {
|
||||
readableStreamForRidUnrefableRef(this.#readable);
|
||||
}
|
||||
this.#pendingReadPromiseIds.forEach((id) => core.refOp(id));
|
||||
ArrayPrototypeForEach(this.#pendingReadPromiseIds, (id) => core.refOp(id));
|
||||
}
|
||||
|
||||
unref() {
|
||||
|
@ -149,7 +153,10 @@ class Conn {
|
|||
if (this.#readable) {
|
||||
readableStreamForRidUnrefableUnref(this.#readable);
|
||||
}
|
||||
this.#pendingReadPromiseIds.forEach((id) => core.unrefOp(id));
|
||||
ArrayPrototypeForEach(
|
||||
this.#pendingReadPromiseIds,
|
||||
(id) => core.unrefOp(id),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,13 +17,14 @@ const {
|
|||
ArrayPrototypeSort,
|
||||
ArrayPrototypeSplice,
|
||||
ObjectKeys,
|
||||
Uint32Array,
|
||||
SafeArrayIterator,
|
||||
StringPrototypeSlice,
|
||||
StringPrototypeStartsWith,
|
||||
Symbol,
|
||||
SymbolFor,
|
||||
SymbolIterator,
|
||||
TypeError,
|
||||
Uint32Array,
|
||||
} = primordials;
|
||||
|
||||
const _list = Symbol("list");
|
||||
|
@ -421,7 +422,10 @@ class URL {
|
|||
|
||||
#hasAuthority() {
|
||||
// https://github.com/servo/rust-url/blob/1d307ae51a28fecc630ecec03380788bfb03a643/url/src/lib.rs#L824
|
||||
return this.#serialization.slice(this.#schemeEnd).startsWith("://");
|
||||
return StringPrototypeStartsWith(
|
||||
StringPrototypeSlice(this.#serialization, this.#schemeEnd),
|
||||
"://",
|
||||
);
|
||||
}
|
||||
|
||||
/** @return {string} */
|
||||
|
@ -429,7 +433,7 @@ class URL {
|
|||
webidl.assertBranded(this, URLPrototype);
|
||||
// https://github.com/servo/rust-url/blob/1d307ae51a28fecc630ecec03380788bfb03a643/url/src/quirks.rs#L263
|
||||
return this.#fragmentStart
|
||||
? trim(this.#serialization.slice(this.#fragmentStart))
|
||||
? trim(StringPrototypeSlice(this.#serialization, this.#fragmentStart))
|
||||
: "";
|
||||
}
|
||||
|
||||
|
@ -455,7 +459,11 @@ class URL {
|
|||
get host() {
|
||||
webidl.assertBranded(this, URLPrototype);
|
||||
// https://github.com/servo/rust-url/blob/1d307ae51a28fecc630ecec03380788bfb03a643/url/src/quirks.rs#L101
|
||||
return this.#serialization.slice(this.#hostStart, this.#pathStart);
|
||||
return StringPrototypeSlice(
|
||||
this.#serialization,
|
||||
this.#hostStart,
|
||||
this.#pathStart,
|
||||
);
|
||||
}
|
||||
|
||||
/** @param {string} value */
|
||||
|
@ -480,7 +488,11 @@ class URL {
|
|||
get hostname() {
|
||||
webidl.assertBranded(this, URLPrototype);
|
||||
// https://github.com/servo/rust-url/blob/1d307ae51a28fecc630ecec03380788bfb03a643/url/src/lib.rs#L988
|
||||
return this.#serialization.slice(this.#hostStart, this.#hostEnd);
|
||||
return StringPrototypeSlice(
|
||||
this.#serialization,
|
||||
this.#hostStart,
|
||||
this.#hostEnd,
|
||||
);
|
||||
}
|
||||
|
||||
/** @param {string} value */
|
||||
|
@ -523,7 +535,11 @@ class URL {
|
|||
get origin() {
|
||||
webidl.assertBranded(this, URLPrototype);
|
||||
// https://github.com/servo/rust-url/blob/1d307ae51a28fecc630ecec03380788bfb03a643/url/src/origin.rs#L14
|
||||
const scheme = this.#serialization.slice(0, this.#schemeEnd);
|
||||
const scheme = StringPrototypeSlice(
|
||||
this.#serialization,
|
||||
0,
|
||||
this.#schemeEnd,
|
||||
);
|
||||
if (
|
||||
scheme === "http" || scheme === "https" || scheme === "ftp" ||
|
||||
scheme === "ws" || scheme === "wss"
|
||||
|
@ -552,7 +568,8 @@ class URL {
|
|||
this.#usernameEnd !== this.#serialization.length &&
|
||||
this.#serialization[this.#usernameEnd] === ":"
|
||||
) {
|
||||
return this.#serialization.slice(
|
||||
return StringPrototypeSlice(
|
||||
this.#serialization,
|
||||
this.#usernameEnd + 1,
|
||||
this.#hostStart - 1,
|
||||
);
|
||||
|
@ -583,11 +600,15 @@ class URL {
|
|||
webidl.assertBranded(this, URLPrototype);
|
||||
// https://github.com/servo/rust-url/blob/1d307ae51a28fecc630ecec03380788bfb03a643/url/src/lib.rs#L1203
|
||||
if (!this.#queryStart && !this.#fragmentStart) {
|
||||
return this.#serialization.slice(this.#pathStart);
|
||||
return StringPrototypeSlice(this.#serialization, this.#pathStart);
|
||||
}
|
||||
|
||||
const nextComponentStart = this.#queryStart || this.#fragmentStart;
|
||||
return this.#serialization.slice(this.#pathStart, nextComponentStart);
|
||||
return StringPrototypeSlice(
|
||||
this.#serialization,
|
||||
this.#pathStart,
|
||||
nextComponentStart,
|
||||
);
|
||||
}
|
||||
|
||||
/** @param {string} value */
|
||||
|
@ -613,9 +634,14 @@ class URL {
|
|||
webidl.assertBranded(this, URLPrototype);
|
||||
// https://github.com/servo/rust-url/blob/1d307ae51a28fecc630ecec03380788bfb03a643/url/src/quirks.rs#L196
|
||||
if (this.#port === NO_PORT) {
|
||||
return this.#serialization.slice(this.#hostEnd, this.#pathStart);
|
||||
return StringPrototypeSlice(
|
||||
this.#serialization,
|
||||
this.#hostEnd,
|
||||
this.#pathStart,
|
||||
);
|
||||
} else {
|
||||
return this.#serialization.slice(
|
||||
return StringPrototypeSlice(
|
||||
this.#serialization,
|
||||
this.#hostEnd + 1, /* : */
|
||||
this.#pathStart,
|
||||
);
|
||||
|
@ -644,7 +670,11 @@ class URL {
|
|||
get protocol() {
|
||||
webidl.assertBranded(this, URLPrototype);
|
||||
// https://github.com/servo/rust-url/blob/1d307ae51a28fecc630ecec03380788bfb03a643/url/src/quirks.rs#L56
|
||||
return this.#serialization.slice(0, this.#schemeEnd + 1 /* : */);
|
||||
return StringPrototypeSlice(
|
||||
this.#serialization,
|
||||
0,
|
||||
this.#schemeEnd + 1, /* : */
|
||||
);
|
||||
}
|
||||
|
||||
/** @param {string} value */
|
||||
|
@ -672,7 +702,9 @@ class URL {
|
|||
const afterPath = this.#queryStart || this.#fragmentStart ||
|
||||
this.#serialization.length;
|
||||
const afterQuery = this.#fragmentStart || this.#serialization.length;
|
||||
return trim(this.#serialization.slice(afterPath, afterQuery));
|
||||
return trim(
|
||||
StringPrototypeSlice(this.#serialization, afterPath, afterQuery),
|
||||
);
|
||||
}
|
||||
|
||||
/** @param {string} value */
|
||||
|
@ -703,7 +735,8 @@ class URL {
|
|||
this.#hasAuthority() &&
|
||||
this.#usernameEnd > this.#schemeEnd + schemeSeperatorLen
|
||||
) {
|
||||
return this.#serialization.slice(
|
||||
return StringPrototypeSlice(
|
||||
this.#serialization,
|
||||
this.#schemeEnd + schemeSeperatorLen,
|
||||
this.#usernameEnd,
|
||||
);
|
||||
|
|
|
@ -13,8 +13,9 @@ import * as webidl from "ext:deno_webidl/00_webidl.js";
|
|||
const primordials = globalThis.__bootstrap.primordials;
|
||||
const {
|
||||
ArrayPrototypeMap,
|
||||
ObjectKeys,
|
||||
ArrayPrototypePop,
|
||||
ObjectFromEntries,
|
||||
ObjectKeys,
|
||||
RegExpPrototypeExec,
|
||||
RegExpPrototypeTest,
|
||||
SafeRegExp,
|
||||
|
@ -178,7 +179,7 @@ class URLPattern {
|
|||
|
||||
const { 0: values, 1: inputs } = res;
|
||||
if (inputs[1] === null) {
|
||||
inputs.pop();
|
||||
ArrayPrototypePop(inputs);
|
||||
}
|
||||
|
||||
/** @type {URLPatternResult} */
|
||||
|
|
|
@ -19,9 +19,10 @@ import {
|
|||
const primordials = globalThis.__bootstrap.primordials;
|
||||
const {
|
||||
ArrayBuffer,
|
||||
ArrayBufferIsView,
|
||||
ArrayBufferPrototype,
|
||||
ArrayBufferPrototypeGetByteLength,
|
||||
ArrayBufferIsView,
|
||||
ArrayBufferPrototypeSlice,
|
||||
ArrayPrototypeMap,
|
||||
ArrayPrototypePush,
|
||||
ArrayPrototypeShift,
|
||||
|
@ -34,12 +35,12 @@ const {
|
|||
DataViewPrototypeGetByteOffset,
|
||||
Float32Array,
|
||||
Float64Array,
|
||||
Int8Array,
|
||||
Int16Array,
|
||||
Int32Array,
|
||||
Int8Array,
|
||||
MathMin,
|
||||
NumberIsInteger,
|
||||
NumberIsNaN,
|
||||
MathMin,
|
||||
ObjectCreate,
|
||||
ObjectDefineProperties,
|
||||
ObjectDefineProperty,
|
||||
|
@ -52,14 +53,13 @@ const {
|
|||
PromisePrototypeThen,
|
||||
PromiseReject,
|
||||
PromiseResolve,
|
||||
queueMicrotask,
|
||||
RangeError,
|
||||
ReflectHas,
|
||||
SafeFinalizationRegistry,
|
||||
SafePromiseAll,
|
||||
SafeWeakMap,
|
||||
// TODO(lucacasonato): add SharedArrayBuffer to primordials
|
||||
// SharedArrayBufferPrototype
|
||||
// SharedArrayBufferPrototype,
|
||||
Symbol,
|
||||
SymbolAsyncIterator,
|
||||
SymbolFor,
|
||||
|
@ -70,13 +70,14 @@ const {
|
|||
TypedArrayPrototypeGetSymbolToStringTag,
|
||||
TypedArrayPrototypeSet,
|
||||
TypedArrayPrototypeSlice,
|
||||
Uint8Array,
|
||||
Uint16Array,
|
||||
Uint32Array,
|
||||
Uint8Array,
|
||||
Uint8ClampedArray,
|
||||
WeakMapPrototypeGet,
|
||||
WeakMapPrototypeHas,
|
||||
WeakMapPrototypeSet,
|
||||
queueMicrotask,
|
||||
} = primordials;
|
||||
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
|
||||
import { assert, AssertionError } from "ext:deno_web/00_infra.js";
|
||||
|
@ -1252,7 +1253,16 @@ function readableByteStreamControllerEnqueueClonedChunkToQueue(
|
|||
) {
|
||||
let cloneResult;
|
||||
try {
|
||||
if (ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, buffer)) {
|
||||
cloneResult = ArrayBufferPrototypeSlice(
|
||||
buffer,
|
||||
byteOffset,
|
||||
byteOffset + byteLength,
|
||||
);
|
||||
} else {
|
||||
// TODO(lucacasonato): add SharedArrayBuffer to primordials
|
||||
cloneResult = buffer.slice(byteOffset, byteOffset + byteLength);
|
||||
}
|
||||
} catch (e) {
|
||||
readableByteStreamControllerError(controller, e);
|
||||
}
|
||||
|
@ -1864,7 +1874,7 @@ function readableByteStreamControllerPullInto(
|
|||
return;
|
||||
}
|
||||
}
|
||||
controller[_pendingPullIntos].push(pullIntoDescriptor);
|
||||
ArrayPrototypePush(controller[_pendingPullIntos], pullIntoDescriptor);
|
||||
readableStreamAddReadIntoRequest(stream, readIntoRequest);
|
||||
readableByteStreamControllerCallPullIfNeeded(controller);
|
||||
}
|
||||
|
@ -4481,7 +4491,7 @@ function writableStreamMarkCloseRequestInFlight(stream) {
|
|||
function writableStreamMarkFirstWriteRequestInFlight(stream) {
|
||||
assert(stream[_inFlightWriteRequest] === undefined);
|
||||
assert(stream[_writeRequests].length);
|
||||
const writeRequest = stream[_writeRequests].shift();
|
||||
const writeRequest = ArrayPrototypeShift(stream[_writeRequests]);
|
||||
stream[_inFlightWriteRequest] = writeRequest;
|
||||
}
|
||||
|
||||
|
|
|
@ -259,7 +259,7 @@ function serializeJsMessageData(data, transferables) {
|
|||
);
|
||||
}
|
||||
j++;
|
||||
transferredArrayBuffers.push(ab);
|
||||
ArrayPrototypePush(transferredArrayBuffers, ab);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ const primordials = globalThis.__bootstrap.primordials;
|
|||
const {
|
||||
ArrayPrototypeJoin,
|
||||
ArrayPrototypeMap,
|
||||
DateNow,
|
||||
Error,
|
||||
ObjectPrototypeIsPrototypeOf,
|
||||
PromisePrototypeCatch,
|
||||
|
@ -27,8 +28,8 @@ const {
|
|||
StringPrototypeToLowerCase,
|
||||
Symbol,
|
||||
SymbolFor,
|
||||
TypedArrayPrototypeGetByteLength,
|
||||
TypeError,
|
||||
TypedArrayPrototypeGetByteLength,
|
||||
Uint8ArrayPrototype,
|
||||
} = primordials;
|
||||
|
||||
|
@ -281,7 +282,7 @@ class WebSocketStream {
|
|||
this[_closed].state === "pending"
|
||||
) {
|
||||
if (
|
||||
new Date().getTime() - await this[_closeSent].promise <=
|
||||
DateNow() - await this[_closeSent].promise <=
|
||||
CLOSE_RESPONSE_TIMEOUT
|
||||
) {
|
||||
return pull(controller);
|
||||
|
@ -404,7 +405,7 @@ class WebSocketStream {
|
|||
core.opAsync("op_ws_close", this[_rid], code, closeInfo.reason),
|
||||
() => {
|
||||
setTimeout(() => {
|
||||
this[_closeSent].resolve(new Date().getTime());
|
||||
this[_closeSent].resolve(DateNow());
|
||||
}, 0);
|
||||
},
|
||||
(err) => {
|
||||
|
|
|
@ -4,10 +4,11 @@ const core = globalThis.Deno.core;
|
|||
const ops = core.ops;
|
||||
const primordials = globalThis.__bootstrap.primordials;
|
||||
const {
|
||||
ArrayPrototypeFilter,
|
||||
Error,
|
||||
ObjectPrototypeIsPrototypeOf,
|
||||
StringPrototypeStartsWith,
|
||||
String,
|
||||
StringPrototypeStartsWith,
|
||||
SymbolIterator,
|
||||
SymbolToStringTag,
|
||||
} = primordials;
|
||||
|
@ -192,8 +193,9 @@ class Worker extends EventTarget {
|
|||
const event = new MessageEvent("message", {
|
||||
cancelable: false,
|
||||
data: message,
|
||||
ports: transferables.filter((t) =>
|
||||
ObjectPrototypeIsPrototypeOf(MessagePortPrototype, t)
|
||||
ports: ArrayPrototypeFilter(
|
||||
transferables,
|
||||
(t) => ObjectPrototypeIsPrototypeOf(MessagePortPrototype, t),
|
||||
),
|
||||
});
|
||||
this.dispatchEvent(event);
|
||||
|
|
|
@ -6,10 +6,12 @@ import { Event, EventTarget } from "ext:deno_web/02_event.js";
|
|||
const primordials = globalThis.__bootstrap.primordials;
|
||||
const {
|
||||
Error,
|
||||
FunctionPrototypeBind,
|
||||
SymbolFor,
|
||||
} = primordials;
|
||||
|
||||
const windowDispatchEvent = EventTarget.prototype.dispatchEvent.bind(
|
||||
const windowDispatchEvent = FunctionPrototypeBind(
|
||||
EventTarget.prototype.dispatchEvent,
|
||||
globalThis,
|
||||
);
|
||||
|
||||
|
|
|
@ -12,27 +12,28 @@ const ops = core.ops;
|
|||
const internals = globalThis.__bootstrap.internals;
|
||||
const primordials = globalThis.__bootstrap.primordials;
|
||||
const {
|
||||
ArrayPrototypeFilter,
|
||||
ArrayPrototypeIndexOf,
|
||||
ArrayPrototypeMap,
|
||||
ArrayPrototypePush,
|
||||
ArrayPrototypeShift,
|
||||
ArrayPrototypeSplice,
|
||||
ArrayPrototypeMap,
|
||||
DateNow,
|
||||
Error,
|
||||
ErrorPrototype,
|
||||
FunctionPrototypeCall,
|
||||
FunctionPrototypeBind,
|
||||
FunctionPrototypeCall,
|
||||
ObjectAssign,
|
||||
ObjectDefineProperty,
|
||||
ObjectDefineProperties,
|
||||
ObjectDefineProperty,
|
||||
ObjectFreeze,
|
||||
ObjectPrototypeIsPrototypeOf,
|
||||
ObjectSetPrototypeOf,
|
||||
PromisePrototypeThen,
|
||||
PromiseResolve,
|
||||
SafeWeakMap,
|
||||
Symbol,
|
||||
SymbolIterator,
|
||||
PromisePrototypeThen,
|
||||
SafeWeakMap,
|
||||
TypeError,
|
||||
WeakMapPrototypeDelete,
|
||||
WeakMapPrototypeGet,
|
||||
|
@ -147,8 +148,10 @@ async function pollForMessages() {
|
|||
const msgEvent = new event.MessageEvent("message", {
|
||||
cancelable: false,
|
||||
data: message,
|
||||
ports: transferables.filter((t) =>
|
||||
ObjectPrototypeIsPrototypeOf(messagePort.MessagePortPrototype, t)
|
||||
ports: ArrayPrototypeFilter(
|
||||
transferables,
|
||||
(t) =>
|
||||
ObjectPrototypeIsPrototypeOf(messagePort.MessagePortPrototype, t),
|
||||
),
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue