1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-23 15:49:44 -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:
Kenta Moriuchi 2023-05-02 19:15:45 +09:00 committed by Levente Kurusa
parent 2a14ac58fa
commit ec1fb08a88
No known key found for this signature in database
GPG key ID: 9F72F3C05BA137C4
10 changed files with 25 additions and 24 deletions

View file

@ -21,7 +21,7 @@ const {
MapPrototypeSet,
MathCeil,
ObjectKeys,
ObjectPrototypeHasOwnProperty,
ObjectHasOwn,
ObjectPrototypeIsPrototypeOf,
Promise,
SafeArrayIterator,
@ -166,7 +166,7 @@ function assertOps(fn) {
const details = [];
for (const key in post.ops) {
if (!ObjectPrototypeHasOwnProperty(post.ops, key)) {
if (!ObjectHasOwn(post.ops, key)) {
continue;
}
const preOp = pre.ops[key] ??

3
core/internal.d.ts vendored
View file

@ -637,7 +637,6 @@ declare namespace __bootstrap {
export const Object: typeof globalThis.Object;
export const ObjectLength: typeof Object.length;
export const ObjectName: typeof Object.name;
export const ObjectPrototype: typeof Object.prototype;
export const ObjectAssign: typeof Object.assign;
export const ObjectGetOwnPropertyDescriptor:
typeof Object.getOwnPropertyDescriptor;
@ -646,6 +645,7 @@ declare namespace __bootstrap {
export const ObjectGetOwnPropertyNames: typeof Object.getOwnPropertyNames;
export const ObjectGetOwnPropertySymbols:
typeof Object.getOwnPropertySymbols;
export const ObjectHasOwn: typeof Object.hasOwn;
export const ObjectIs: typeof Object.is;
export const ObjectPreventExtensions: typeof Object.preventExtensions;
export const ObjectSeal: typeof Object.seal;
@ -662,6 +662,7 @@ declare namespace __bootstrap {
export const ObjectEntries: typeof Object.entries;
export const ObjectFromEntries: typeof Object.fromEntries;
export const ObjectValues: typeof Object.values;
export const ObjectPrototype: typeof Object.prototype;
export const ObjectPrototype__defineGetter__: UncurryThis<
typeof Object.prototype.__defineGetter__
>;

View file

@ -68,10 +68,10 @@ const {
ObjectGetOwnPropertyNames,
ObjectGetOwnPropertySymbols,
ObjectGetPrototypeOf,
ObjectHasOwn,
ObjectIs,
ObjectKeys,
ObjectPrototype,
ObjectPrototypeHasOwnProperty,
ObjectPrototypeIsPrototypeOf,
ObjectPrototypePropertyIsEnumerable,
ObjectPrototypeToString,
@ -710,7 +710,7 @@ function formatValue(
}
function getClassBase(value, constructor, tag) {
const hasName = ObjectPrototypeHasOwnProperty(value, "name");
const hasName = ObjectHasOwn(value, "name");
const name = (hasName && value.name) || "(anonymous)";
let base = `class ${name}`;
if (constructor !== "Function" && constructor !== null) {
@ -1148,7 +1148,7 @@ function addPrototypeProperties(
// Ignore the `constructor` property and keys that exist on layers above.
if (
key === "constructor" ||
ObjectPrototypeHasOwnProperty(main, key) ||
ObjectHasOwn(main, key) ||
(depth !== 0 && SetPrototypeHas(keySet, key))
) {
continue;
@ -1315,7 +1315,7 @@ function formatArray(ctx, value, recurseTimes) {
const output = [];
for (let i = 0; i < len; i++) {
// Special handle sparse arrays.
if (!ObjectPrototypeHasOwnProperty(value, i)) {
if (!ObjectHasOwn(value, i)) {
return formatSpecialArray(ctx, value, recurseTimes, len, output, i);
}
ArrayPrototypePush(
@ -2291,7 +2291,7 @@ function hasOwnProperty(obj, v) {
if (obj == null) {
return false;
}
return ObjectPrototypeHasOwnProperty(obj, v);
return ObjectHasOwn(obj, v);
}
// Copyright Joyent, Inc. and other Node contributors. MIT license.
@ -3603,7 +3603,7 @@ function wrapConsole(consoleFromDeno, consoleFromV8) {
const keys = ObjectKeys(consoleFromV8);
for (let i = 0; i < keys.length; ++i) {
const key = keys[i];
if (ObjectPrototypeHasOwnProperty(consoleFromDeno, key)) {
if (ObjectHasOwn(consoleFromDeno, key)) {
consoleFromDeno[key] = FunctionPrototypeBind(
callConsole,
consoleFromDeno,

View file

@ -27,7 +27,7 @@ const {
JSONStringify,
MathCeil,
ObjectAssign,
ObjectPrototypeHasOwnProperty,
ObjectHasOwn,
ObjectPrototypeIsPrototypeOf,
SafeArrayIterator,
SafeWeakMap,
@ -211,7 +211,7 @@ function normalizeAlgorithm(algorithm, op) {
// 5.
let desiredType = undefined;
for (const key in registeredAlgorithms) {
if (!ObjectPrototypeHasOwnProperty(registeredAlgorithms, key)) {
if (!ObjectHasOwn(registeredAlgorithms, key)) {
continue;
}
if (
@ -246,7 +246,7 @@ function normalizeAlgorithm(algorithm, op) {
const dict = simpleAlgorithmDictionaries[desiredType];
// 10.
for (const member in dict) {
if (!ObjectPrototypeHasOwnProperty(dict, member)) {
if (!ObjectHasOwn(dict, member)) {
continue;
}
const idlType = dict[member];

View file

@ -28,8 +28,8 @@ const {
ArrayPrototypeJoin,
ArrayPrototypeSplice,
ArrayPrototypeFilter,
ObjectPrototypeHasOwnProperty,
ObjectEntries,
ObjectHasOwn,
RegExpPrototypeTest,
SafeArrayIterator,
SafeRegExp,
@ -79,7 +79,7 @@ function fillHeaders(headers, object) {
}
} else {
for (const key in object) {
if (!ObjectPrototypeHasOwnProperty(object, key)) {
if (!ObjectHasOwn(object, key)) {
continue;
}
appendHeader(headers, key, object[key]);

View file

@ -10,7 +10,7 @@ const {
ArrayPrototypeJoin,
DataViewPrototypeGetByteLength,
ObjectDefineProperty,
ObjectPrototypeHasOwnProperty,
ObjectHasOwn,
ObjectPrototypeIsPrototypeOf,
Number,
NumberIsSafeInteger,
@ -439,7 +439,7 @@ class DynamicLibrary {
constructor(path, symbols) {
({ 0: this.#rid, 1: this.symbols } = ops.op_ffi_load({ path, symbols }));
for (const symbol in symbols) {
if (!ObjectPrototypeHasOwnProperty(symbols, symbol)) {
if (!ObjectHasOwn(symbols, symbol)) {
continue;
}

View file

@ -16,7 +16,7 @@ const {
ArrayPrototypeSplice,
ObjectGetOwnPropertyDescriptor,
ObjectGetPrototypeOf,
ObjectPrototypeHasOwnProperty,
ObjectHasOwn,
ObjectSetPrototypeOf,
ObjectKeys,
ObjectEntries,
@ -433,7 +433,7 @@ const CircularRequirePrototypeWarningProxy = new Proxy({}, {
getOwnPropertyDescriptor(target, prop) {
if (
ObjectPrototypeHasOwnProperty(target, prop) || prop === "__esModule"
ObjectHasOwn(target, prop) || prop === "__esModule"
) {
return ObjectGetOwnPropertyDescriptor(target, prop);
}

View file

@ -34,7 +34,7 @@ import {
ArrayPrototypeSlice,
ArrayPrototypeSort,
ArrayPrototypeUnshift,
ObjectPrototypeHasOwnProperty,
ObjectHasOwn,
StringPrototypeToUpperCase,
} from "ext:deno_node/internal/primordials.mjs";
import { kEmptyObject } from "ext:deno_node/internal/util.mjs";
@ -429,7 +429,7 @@ function copyProcessEnvToEnv(
if (
Deno.env.get(name) &&
(!optionEnv ||
!ObjectPrototypeHasOwnProperty(optionEnv, name))
!ObjectHasOwn(optionEnv, name))
) {
env[name] = Deno.env.get(name);
}

View file

@ -12,7 +12,7 @@ export const ArrayPrototypeSort = (that, ...args) => that.sort(...args);
export const ArrayPrototypeUnshift = (that, ...args) => that.unshift(...args);
export const ObjectAssign = Object.assign;
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 RegExpPrototypeExec = RegExp.prototype.exec;
export const StringFromCharCode = String.fromCharCode;

View file

@ -47,7 +47,7 @@ const {
ObjectGetOwnPropertyDescriptor,
ObjectGetOwnPropertyDescriptors,
ObjectGetPrototypeOf,
ObjectPrototypeHasOwnProperty,
ObjectHasOwn,
ObjectPrototypeIsPrototypeOf,
ObjectIs,
PromisePrototypeThen,
@ -920,7 +920,7 @@ function createRecordConverter(keyConverter, valueConverter) {
// Fast path for common case (not a Proxy)
if (!core.isProxy(V)) {
for (const key in V) {
if (!ObjectPrototypeHasOwnProperty(V, key)) {
if (!ObjectHasOwn(V, key)) {
continue;
}
const typedKey = keyConverter(key, prefix, context, opts);
@ -1133,7 +1133,7 @@ function mixinPairIterable(name, prototype, dataSymbol, keyKey, valueKey) {
function configurePrototype(prototype) {
const descriptors = ObjectGetOwnPropertyDescriptors(prototype.prototype);
for (const key in descriptors) {
if (!ObjectPrototypeHasOwnProperty(descriptors, key)) {
if (!ObjectHasOwn(descriptors, key)) {
continue;
}
if (key === "constructor") continue;