mirror of
https://github.com/denoland/deno.git
synced 2024-11-25 15:29:32 -05:00
refactor(core): Use ObjectHasOwn
instead of ObjectPrototypeHasOwnProperty
(#18952)
ES2022 `Object.hasOwn` can be used in snapshot, so I migrate to use it.
This commit is contained in:
parent
2a14ac58fa
commit
ec1fb08a88
10 changed files with 25 additions and 24 deletions
|
@ -21,7 +21,7 @@ const {
|
||||||
MapPrototypeSet,
|
MapPrototypeSet,
|
||||||
MathCeil,
|
MathCeil,
|
||||||
ObjectKeys,
|
ObjectKeys,
|
||||||
ObjectPrototypeHasOwnProperty,
|
ObjectHasOwn,
|
||||||
ObjectPrototypeIsPrototypeOf,
|
ObjectPrototypeIsPrototypeOf,
|
||||||
Promise,
|
Promise,
|
||||||
SafeArrayIterator,
|
SafeArrayIterator,
|
||||||
|
@ -166,7 +166,7 @@ function assertOps(fn) {
|
||||||
|
|
||||||
const details = [];
|
const details = [];
|
||||||
for (const key in post.ops) {
|
for (const key in post.ops) {
|
||||||
if (!ObjectPrototypeHasOwnProperty(post.ops, key)) {
|
if (!ObjectHasOwn(post.ops, key)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const preOp = pre.ops[key] ??
|
const preOp = pre.ops[key] ??
|
||||||
|
|
3
core/internal.d.ts
vendored
3
core/internal.d.ts
vendored
|
@ -637,7 +637,6 @@ declare namespace __bootstrap {
|
||||||
export const Object: typeof globalThis.Object;
|
export const Object: typeof globalThis.Object;
|
||||||
export const ObjectLength: typeof Object.length;
|
export const ObjectLength: typeof Object.length;
|
||||||
export const ObjectName: typeof Object.name;
|
export const ObjectName: typeof Object.name;
|
||||||
export const ObjectPrototype: typeof Object.prototype;
|
|
||||||
export const ObjectAssign: typeof Object.assign;
|
export const ObjectAssign: typeof Object.assign;
|
||||||
export const ObjectGetOwnPropertyDescriptor:
|
export const ObjectGetOwnPropertyDescriptor:
|
||||||
typeof Object.getOwnPropertyDescriptor;
|
typeof Object.getOwnPropertyDescriptor;
|
||||||
|
@ -646,6 +645,7 @@ declare namespace __bootstrap {
|
||||||
export const ObjectGetOwnPropertyNames: typeof Object.getOwnPropertyNames;
|
export const ObjectGetOwnPropertyNames: typeof Object.getOwnPropertyNames;
|
||||||
export const ObjectGetOwnPropertySymbols:
|
export const ObjectGetOwnPropertySymbols:
|
||||||
typeof Object.getOwnPropertySymbols;
|
typeof Object.getOwnPropertySymbols;
|
||||||
|
export const ObjectHasOwn: typeof Object.hasOwn;
|
||||||
export const ObjectIs: typeof Object.is;
|
export const ObjectIs: typeof Object.is;
|
||||||
export const ObjectPreventExtensions: typeof Object.preventExtensions;
|
export const ObjectPreventExtensions: typeof Object.preventExtensions;
|
||||||
export const ObjectSeal: typeof Object.seal;
|
export const ObjectSeal: typeof Object.seal;
|
||||||
|
@ -662,6 +662,7 @@ declare namespace __bootstrap {
|
||||||
export const ObjectEntries: typeof Object.entries;
|
export const ObjectEntries: typeof Object.entries;
|
||||||
export const ObjectFromEntries: typeof Object.fromEntries;
|
export const ObjectFromEntries: typeof Object.fromEntries;
|
||||||
export const ObjectValues: typeof Object.values;
|
export const ObjectValues: typeof Object.values;
|
||||||
|
export const ObjectPrototype: typeof Object.prototype;
|
||||||
export const ObjectPrototype__defineGetter__: UncurryThis<
|
export const ObjectPrototype__defineGetter__: UncurryThis<
|
||||||
typeof Object.prototype.__defineGetter__
|
typeof Object.prototype.__defineGetter__
|
||||||
>;
|
>;
|
||||||
|
|
|
@ -68,10 +68,10 @@ const {
|
||||||
ObjectGetOwnPropertyNames,
|
ObjectGetOwnPropertyNames,
|
||||||
ObjectGetOwnPropertySymbols,
|
ObjectGetOwnPropertySymbols,
|
||||||
ObjectGetPrototypeOf,
|
ObjectGetPrototypeOf,
|
||||||
|
ObjectHasOwn,
|
||||||
ObjectIs,
|
ObjectIs,
|
||||||
ObjectKeys,
|
ObjectKeys,
|
||||||
ObjectPrototype,
|
ObjectPrototype,
|
||||||
ObjectPrototypeHasOwnProperty,
|
|
||||||
ObjectPrototypeIsPrototypeOf,
|
ObjectPrototypeIsPrototypeOf,
|
||||||
ObjectPrototypePropertyIsEnumerable,
|
ObjectPrototypePropertyIsEnumerable,
|
||||||
ObjectPrototypeToString,
|
ObjectPrototypeToString,
|
||||||
|
@ -710,7 +710,7 @@ function formatValue(
|
||||||
}
|
}
|
||||||
|
|
||||||
function getClassBase(value, constructor, tag) {
|
function getClassBase(value, constructor, tag) {
|
||||||
const hasName = ObjectPrototypeHasOwnProperty(value, "name");
|
const hasName = ObjectHasOwn(value, "name");
|
||||||
const name = (hasName && value.name) || "(anonymous)";
|
const name = (hasName && value.name) || "(anonymous)";
|
||||||
let base = `class ${name}`;
|
let base = `class ${name}`;
|
||||||
if (constructor !== "Function" && constructor !== null) {
|
if (constructor !== "Function" && constructor !== null) {
|
||||||
|
@ -1148,7 +1148,7 @@ function addPrototypeProperties(
|
||||||
// Ignore the `constructor` property and keys that exist on layers above.
|
// Ignore the `constructor` property and keys that exist on layers above.
|
||||||
if (
|
if (
|
||||||
key === "constructor" ||
|
key === "constructor" ||
|
||||||
ObjectPrototypeHasOwnProperty(main, key) ||
|
ObjectHasOwn(main, key) ||
|
||||||
(depth !== 0 && SetPrototypeHas(keySet, key))
|
(depth !== 0 && SetPrototypeHas(keySet, key))
|
||||||
) {
|
) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -1315,7 +1315,7 @@ function formatArray(ctx, value, recurseTimes) {
|
||||||
const output = [];
|
const output = [];
|
||||||
for (let i = 0; i < len; i++) {
|
for (let i = 0; i < len; i++) {
|
||||||
// Special handle sparse arrays.
|
// Special handle sparse arrays.
|
||||||
if (!ObjectPrototypeHasOwnProperty(value, i)) {
|
if (!ObjectHasOwn(value, i)) {
|
||||||
return formatSpecialArray(ctx, value, recurseTimes, len, output, i);
|
return formatSpecialArray(ctx, value, recurseTimes, len, output, i);
|
||||||
}
|
}
|
||||||
ArrayPrototypePush(
|
ArrayPrototypePush(
|
||||||
|
@ -2291,7 +2291,7 @@ function hasOwnProperty(obj, v) {
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return ObjectPrototypeHasOwnProperty(obj, v);
|
return ObjectHasOwn(obj, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copyright Joyent, Inc. and other Node contributors. MIT license.
|
// Copyright Joyent, Inc. and other Node contributors. MIT license.
|
||||||
|
@ -3603,7 +3603,7 @@ function wrapConsole(consoleFromDeno, consoleFromV8) {
|
||||||
const keys = ObjectKeys(consoleFromV8);
|
const keys = ObjectKeys(consoleFromV8);
|
||||||
for (let i = 0; i < keys.length; ++i) {
|
for (let i = 0; i < keys.length; ++i) {
|
||||||
const key = keys[i];
|
const key = keys[i];
|
||||||
if (ObjectPrototypeHasOwnProperty(consoleFromDeno, key)) {
|
if (ObjectHasOwn(consoleFromDeno, key)) {
|
||||||
consoleFromDeno[key] = FunctionPrototypeBind(
|
consoleFromDeno[key] = FunctionPrototypeBind(
|
||||||
callConsole,
|
callConsole,
|
||||||
consoleFromDeno,
|
consoleFromDeno,
|
||||||
|
|
|
@ -27,7 +27,7 @@ const {
|
||||||
JSONStringify,
|
JSONStringify,
|
||||||
MathCeil,
|
MathCeil,
|
||||||
ObjectAssign,
|
ObjectAssign,
|
||||||
ObjectPrototypeHasOwnProperty,
|
ObjectHasOwn,
|
||||||
ObjectPrototypeIsPrototypeOf,
|
ObjectPrototypeIsPrototypeOf,
|
||||||
SafeArrayIterator,
|
SafeArrayIterator,
|
||||||
SafeWeakMap,
|
SafeWeakMap,
|
||||||
|
@ -211,7 +211,7 @@ function normalizeAlgorithm(algorithm, op) {
|
||||||
// 5.
|
// 5.
|
||||||
let desiredType = undefined;
|
let desiredType = undefined;
|
||||||
for (const key in registeredAlgorithms) {
|
for (const key in registeredAlgorithms) {
|
||||||
if (!ObjectPrototypeHasOwnProperty(registeredAlgorithms, key)) {
|
if (!ObjectHasOwn(registeredAlgorithms, key)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
|
@ -246,7 +246,7 @@ function normalizeAlgorithm(algorithm, op) {
|
||||||
const dict = simpleAlgorithmDictionaries[desiredType];
|
const dict = simpleAlgorithmDictionaries[desiredType];
|
||||||
// 10.
|
// 10.
|
||||||
for (const member in dict) {
|
for (const member in dict) {
|
||||||
if (!ObjectPrototypeHasOwnProperty(dict, member)) {
|
if (!ObjectHasOwn(dict, member)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const idlType = dict[member];
|
const idlType = dict[member];
|
||||||
|
|
|
@ -28,8 +28,8 @@ const {
|
||||||
ArrayPrototypeJoin,
|
ArrayPrototypeJoin,
|
||||||
ArrayPrototypeSplice,
|
ArrayPrototypeSplice,
|
||||||
ArrayPrototypeFilter,
|
ArrayPrototypeFilter,
|
||||||
ObjectPrototypeHasOwnProperty,
|
|
||||||
ObjectEntries,
|
ObjectEntries,
|
||||||
|
ObjectHasOwn,
|
||||||
RegExpPrototypeTest,
|
RegExpPrototypeTest,
|
||||||
SafeArrayIterator,
|
SafeArrayIterator,
|
||||||
SafeRegExp,
|
SafeRegExp,
|
||||||
|
@ -79,7 +79,7 @@ function fillHeaders(headers, object) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (const key in object) {
|
for (const key in object) {
|
||||||
if (!ObjectPrototypeHasOwnProperty(object, key)) {
|
if (!ObjectHasOwn(object, key)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
appendHeader(headers, key, object[key]);
|
appendHeader(headers, key, object[key]);
|
||||||
|
|
|
@ -10,7 +10,7 @@ const {
|
||||||
ArrayPrototypeJoin,
|
ArrayPrototypeJoin,
|
||||||
DataViewPrototypeGetByteLength,
|
DataViewPrototypeGetByteLength,
|
||||||
ObjectDefineProperty,
|
ObjectDefineProperty,
|
||||||
ObjectPrototypeHasOwnProperty,
|
ObjectHasOwn,
|
||||||
ObjectPrototypeIsPrototypeOf,
|
ObjectPrototypeIsPrototypeOf,
|
||||||
Number,
|
Number,
|
||||||
NumberIsSafeInteger,
|
NumberIsSafeInteger,
|
||||||
|
@ -439,7 +439,7 @@ class DynamicLibrary {
|
||||||
constructor(path, symbols) {
|
constructor(path, symbols) {
|
||||||
({ 0: this.#rid, 1: this.symbols } = ops.op_ffi_load({ path, symbols }));
|
({ 0: this.#rid, 1: this.symbols } = ops.op_ffi_load({ path, symbols }));
|
||||||
for (const symbol in symbols) {
|
for (const symbol in symbols) {
|
||||||
if (!ObjectPrototypeHasOwnProperty(symbols, symbol)) {
|
if (!ObjectHasOwn(symbols, symbol)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ const {
|
||||||
ArrayPrototypeSplice,
|
ArrayPrototypeSplice,
|
||||||
ObjectGetOwnPropertyDescriptor,
|
ObjectGetOwnPropertyDescriptor,
|
||||||
ObjectGetPrototypeOf,
|
ObjectGetPrototypeOf,
|
||||||
ObjectPrototypeHasOwnProperty,
|
ObjectHasOwn,
|
||||||
ObjectSetPrototypeOf,
|
ObjectSetPrototypeOf,
|
||||||
ObjectKeys,
|
ObjectKeys,
|
||||||
ObjectEntries,
|
ObjectEntries,
|
||||||
|
@ -433,7 +433,7 @@ const CircularRequirePrototypeWarningProxy = new Proxy({}, {
|
||||||
|
|
||||||
getOwnPropertyDescriptor(target, prop) {
|
getOwnPropertyDescriptor(target, prop) {
|
||||||
if (
|
if (
|
||||||
ObjectPrototypeHasOwnProperty(target, prop) || prop === "__esModule"
|
ObjectHasOwn(target, prop) || prop === "__esModule"
|
||||||
) {
|
) {
|
||||||
return ObjectGetOwnPropertyDescriptor(target, prop);
|
return ObjectGetOwnPropertyDescriptor(target, prop);
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ import {
|
||||||
ArrayPrototypeSlice,
|
ArrayPrototypeSlice,
|
||||||
ArrayPrototypeSort,
|
ArrayPrototypeSort,
|
||||||
ArrayPrototypeUnshift,
|
ArrayPrototypeUnshift,
|
||||||
ObjectPrototypeHasOwnProperty,
|
ObjectHasOwn,
|
||||||
StringPrototypeToUpperCase,
|
StringPrototypeToUpperCase,
|
||||||
} from "ext:deno_node/internal/primordials.mjs";
|
} from "ext:deno_node/internal/primordials.mjs";
|
||||||
import { kEmptyObject } from "ext:deno_node/internal/util.mjs";
|
import { kEmptyObject } from "ext:deno_node/internal/util.mjs";
|
||||||
|
@ -429,7 +429,7 @@ function copyProcessEnvToEnv(
|
||||||
if (
|
if (
|
||||||
Deno.env.get(name) &&
|
Deno.env.get(name) &&
|
||||||
(!optionEnv ||
|
(!optionEnv ||
|
||||||
!ObjectPrototypeHasOwnProperty(optionEnv, name))
|
!ObjectHasOwn(optionEnv, name))
|
||||||
) {
|
) {
|
||||||
env[name] = Deno.env.get(name);
|
env[name] = Deno.env.get(name);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ export const ArrayPrototypeSort = (that, ...args) => that.sort(...args);
|
||||||
export const ArrayPrototypeUnshift = (that, ...args) => that.unshift(...args);
|
export const ArrayPrototypeUnshift = (that, ...args) => that.unshift(...args);
|
||||||
export const ObjectAssign = Object.assign;
|
export const ObjectAssign = Object.assign;
|
||||||
export const ObjectCreate = Object.create;
|
export const ObjectCreate = Object.create;
|
||||||
export const ObjectPrototypeHasOwnProperty = Object.hasOwn;
|
export const ObjectHasOwn = Object.hasOwn;
|
||||||
export const RegExpPrototypeTest = (that, ...args) => that.test(...args);
|
export const RegExpPrototypeTest = (that, ...args) => that.test(...args);
|
||||||
export const RegExpPrototypeExec = RegExp.prototype.exec;
|
export const RegExpPrototypeExec = RegExp.prototype.exec;
|
||||||
export const StringFromCharCode = String.fromCharCode;
|
export const StringFromCharCode = String.fromCharCode;
|
||||||
|
|
|
@ -47,7 +47,7 @@ const {
|
||||||
ObjectGetOwnPropertyDescriptor,
|
ObjectGetOwnPropertyDescriptor,
|
||||||
ObjectGetOwnPropertyDescriptors,
|
ObjectGetOwnPropertyDescriptors,
|
||||||
ObjectGetPrototypeOf,
|
ObjectGetPrototypeOf,
|
||||||
ObjectPrototypeHasOwnProperty,
|
ObjectHasOwn,
|
||||||
ObjectPrototypeIsPrototypeOf,
|
ObjectPrototypeIsPrototypeOf,
|
||||||
ObjectIs,
|
ObjectIs,
|
||||||
PromisePrototypeThen,
|
PromisePrototypeThen,
|
||||||
|
@ -920,7 +920,7 @@ function createRecordConverter(keyConverter, valueConverter) {
|
||||||
// Fast path for common case (not a Proxy)
|
// Fast path for common case (not a Proxy)
|
||||||
if (!core.isProxy(V)) {
|
if (!core.isProxy(V)) {
|
||||||
for (const key in V) {
|
for (const key in V) {
|
||||||
if (!ObjectPrototypeHasOwnProperty(V, key)) {
|
if (!ObjectHasOwn(V, key)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const typedKey = keyConverter(key, prefix, context, opts);
|
const typedKey = keyConverter(key, prefix, context, opts);
|
||||||
|
@ -1133,7 +1133,7 @@ function mixinPairIterable(name, prototype, dataSymbol, keyKey, valueKey) {
|
||||||
function configurePrototype(prototype) {
|
function configurePrototype(prototype) {
|
||||||
const descriptors = ObjectGetOwnPropertyDescriptors(prototype.prototype);
|
const descriptors = ObjectGetOwnPropertyDescriptors(prototype.prototype);
|
||||||
for (const key in descriptors) {
|
for (const key in descriptors) {
|
||||||
if (!ObjectPrototypeHasOwnProperty(descriptors, key)) {
|
if (!ObjectHasOwn(descriptors, key)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (key === "constructor") continue;
|
if (key === "constructor") continue;
|
||||||
|
|
Loading…
Reference in a new issue