Skip to content

Commit

Permalink
refactor(core): Use ObjectHasOwn instead of `ObjectPrototypeHasOwnP…
Browse files Browse the repository at this point in the history
…roperty` (#18952)

ES2022 `Object.hasOwn` can be used in snapshot, so I migrate to use it.
  • Loading branch information
petamoriken committed May 2, 2023
1 parent cf89374 commit 49eb887
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 24 deletions.
4 changes: 2 additions & 2 deletions cli/js/40_testing.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 21,7 @@ const {
MapPrototypeSet,
MathCeil,
ObjectKeys,
ObjectPrototypeHasOwnProperty,
ObjectHasOwn,
ObjectPrototypeIsPrototypeOf,
Promise,
SafeArrayIterator,
Expand Down Expand Up @@ -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] ??
Expand Down
3 changes: 2 additions & 1 deletion core/internal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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__
>;
Expand Down
12 changes: 6 additions & 6 deletions ext/console/01_console.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 68,10 @@ const {
ObjectGetOwnPropertyNames,
ObjectGetOwnPropertySymbols,
ObjectGetPrototypeOf,
ObjectHasOwn,
ObjectIs,
ObjectKeys,
ObjectPrototype,
ObjectPrototypeHasOwnProperty,
ObjectPrototypeIsPrototypeOf,
ObjectPrototypePropertyIsEnumerable,
ObjectPrototypeToString,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions ext/crypto/00_crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 27,7 @@ const {
JSONStringify,
MathCeil,
ObjectAssign,
ObjectPrototypeHasOwnProperty,
ObjectHasOwn,
ObjectPrototypeIsPrototypeOf,
SafeArrayIterator,
SafeWeakMap,
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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];
Expand Down
4 changes: 2 additions & 2 deletions ext/fetch/20_headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 28,8 @@ const {
ArrayPrototypeJoin,
ArrayPrototypeSplice,
ArrayPrototypeFilter,
ObjectPrototypeHasOwnProperty,
ObjectEntries,
ObjectHasOwn,
RegExpPrototypeTest,
SafeArrayIterator,
SafeRegExp,
Expand Down Expand Up @@ -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]);
Expand Down
4 changes: 2 additions & 2 deletions ext/ffi/00_ffi.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 10,7 @@ const {
ArrayPrototypeJoin,
DataViewPrototypeGetByteLength,
ObjectDefineProperty,
ObjectPrototypeHasOwnProperty,
ObjectHasOwn,
ObjectPrototypeIsPrototypeOf,
Number,
NumberIsSafeInteger,
Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions ext/node/polyfills/01_require.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 16,7 @@ const {
ArrayPrototypeSplice,
ObjectGetOwnPropertyDescriptor,
ObjectGetPrototypeOf,
ObjectPrototypeHasOwnProperty,
ObjectHasOwn,
ObjectSetPrototypeOf,
ObjectKeys,
ObjectEntries,
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions ext/node/polyfills/internal/child_process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -429,7 429,7 @@ function copyProcessEnvToEnv(
if (
Deno.env.get(name) &&
(!optionEnv ||
!ObjectPrototypeHasOwnProperty(optionEnv, name))
!ObjectHasOwn(optionEnv, name))
) {
env[name] = Deno.env.get(name);
}
Expand Down
2 changes: 1 addition & 1 deletion ext/node/polyfills/internal/primordials.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions ext/webidl/00_webidl.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 47,7 @@ const {
ObjectGetOwnPropertyDescriptor,
ObjectGetOwnPropertyDescriptors,
ObjectGetPrototypeOf,
ObjectPrototypeHasOwnProperty,
ObjectHasOwn,
ObjectPrototypeIsPrototypeOf,
ObjectIs,
PromisePrototypeThen,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 49eb887

Please sign in to comment.