summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenta Moriuchi <moriken@kimamass.com>2023-05-02 19:15:45 +0900
committerGitHub <noreply@github.com>2023-05-02 12:15:45 +0200
commit49eb887cc6325e14211ec4a241ffc4ac98f0f7a9 (patch)
tree8dec27c42c45b8e0bfaa7d4b886546fbdc942b64
parentcf893741c3206f55eaac1999f50f1018122f7b85 (diff)
refactor(core): Use `ObjectHasOwn` instead of `ObjectPrototypeHasOwnProperty` (#18952)
ES2022 `Object.hasOwn` can be used in snapshot, so I migrate to use it.
-rw-r--r--cli/js/40_testing.js4
-rw-r--r--core/internal.d.ts3
-rw-r--r--ext/console/01_console.js12
-rw-r--r--ext/crypto/00_crypto.js6
-rw-r--r--ext/fetch/20_headers.js4
-rw-r--r--ext/ffi/00_ffi.js4
-rw-r--r--ext/node/polyfills/01_require.js4
-rw-r--r--ext/node/polyfills/internal/child_process.ts4
-rw-r--r--ext/node/polyfills/internal/primordials.mjs2
-rw-r--r--ext/webidl/00_webidl.js6
10 files changed, 25 insertions, 24 deletions
diff --git a/cli/js/40_testing.js b/cli/js/40_testing.js
index 8afcb74ee..e269b9c9f 100644
--- a/cli/js/40_testing.js
+++ b/cli/js/40_testing.js
@@ -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] ??
diff --git a/core/internal.d.ts b/core/internal.d.ts
index c78310aeb..b09d188d8 100644
--- a/core/internal.d.ts
+++ b/core/internal.d.ts
@@ -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__
>;
diff --git a/ext/console/01_console.js b/ext/console/01_console.js
index 3b2f44917..31431f120 100644
--- a/ext/console/01_console.js
+++ b/ext/console/01_console.js
@@ -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,
diff --git a/ext/crypto/00_crypto.js b/ext/crypto/00_crypto.js
index 5be2e0c1c..1008f4cf6 100644
--- a/ext/crypto/00_crypto.js
+++ b/ext/crypto/00_crypto.js
@@ -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];
diff --git a/ext/fetch/20_headers.js b/ext/fetch/20_headers.js
index 7ec6751fa..89b9e1a2b 100644
--- a/ext/fetch/20_headers.js
+++ b/ext/fetch/20_headers.js
@@ -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]);
diff --git a/ext/ffi/00_ffi.js b/ext/ffi/00_ffi.js
index f36690226..2091a55b3 100644
--- a/ext/ffi/00_ffi.js
+++ b/ext/ffi/00_ffi.js
@@ -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;
}
diff --git a/ext/node/polyfills/01_require.js b/ext/node/polyfills/01_require.js
index ce7312ee8..c73701ba8 100644
--- a/ext/node/polyfills/01_require.js
+++ b/ext/node/polyfills/01_require.js
@@ -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);
}
diff --git a/ext/node/polyfills/internal/child_process.ts b/ext/node/polyfills/internal/child_process.ts
index 7c72cb0ca..edc4caa5e 100644
--- a/ext/node/polyfills/internal/child_process.ts
+++ b/ext/node/polyfills/internal/child_process.ts
@@ -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);
}
diff --git a/ext/node/polyfills/internal/primordials.mjs b/ext/node/polyfills/internal/primordials.mjs
index 1639efdb5..8127eebac 100644
--- a/ext/node/polyfills/internal/primordials.mjs
+++ b/ext/node/polyfills/internal/primordials.mjs
@@ -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;
diff --git a/ext/webidl/00_webidl.js b/ext/webidl/00_webidl.js
index 71b7982b7..247ebfe0d 100644
--- a/ext/webidl/00_webidl.js
+++ b/ext/webidl/00_webidl.js
@@ -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;