summaryrefslogtreecommitdiff
path: root/lib/internal/url.js
diff options
context:
space:
mode:
authorMichaël Zasso <targos@protonmail.com>2019-11-22 18:04:46 +0100
committerMichaël Zasso <targos@protonmail.com>2019-11-25 10:28:15 +0100
commit0646eda4fc0affb98e13c30acb522e63b7fd6dde (patch)
tree078209f50b044e24ea2c72cbbe7dca6e34bb7e25 /lib/internal/url.js
parent35c6e0cc2b56a5380e6808ef5603ecc2b167e032 (diff)
downloadandroid-node-v8-0646eda4fc0affb98e13c30acb522e63b7fd6dde.tar.gz
android-node-v8-0646eda4fc0affb98e13c30acb522e63b7fd6dde.tar.bz2
android-node-v8-0646eda4fc0affb98e13c30acb522e63b7fd6dde.zip
lib: flatten access to primordials
Store all primordials as properties of the primordials object. Static functions are prefixed by the constructor's name and prototype methods are prefixed by the constructor's name followed by "Prototype". For example: primordials.Object.keys becomes primordials.ObjectKeys. PR-URL: https://github.com/nodejs/node/pull/30610 Refs: https://github.com/nodejs/node/issues/29766 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Diffstat (limited to 'lib/internal/url.js')
-rw-r--r--lib/internal/url.js45
1 files changed, 27 insertions, 18 deletions
diff --git a/lib/internal/url.js b/lib/internal/url.js
index 860fa4d7ad..b4c047be52 100644
--- a/lib/internal/url.js
+++ b/lib/internal/url.js
@@ -1,6 +1,15 @@
'use strict';
-const { Object, Reflect } = primordials;
+const {
+ ObjectCreate,
+ ObjectDefineProperties,
+ ObjectDefineProperty,
+ ObjectGetOwnPropertySymbols,
+ ObjectGetPrototypeOf,
+ ObjectKeys,
+ ReflectGetOwnPropertyDescriptor,
+ ReflectOwnKeys,
+} = primordials;
const { inspect } = require('internal/util/inspect');
const {
@@ -74,8 +83,8 @@ const searchParams = Symbol('query');
const kFormat = Symbol('format');
// https://tc39.github.io/ecma262/#sec-%iteratorprototype%-object
-const IteratorPrototype = Object.getPrototypeOf(
- Object.getPrototypeOf([][Symbol.iterator]())
+const IteratorPrototype = ObjectGetPrototypeOf(
+ ObjectGetPrototypeOf([][Symbol.iterator]())
);
const unpairedSurrogateRe =
@@ -164,10 +173,10 @@ class URLSearchParams {
// Record<USVString, USVString>
// Need to use reflection APIs for full spec compliance.
this[searchParams] = [];
- const keys = Reflect.ownKeys(init);
+ const keys = ReflectOwnKeys(init);
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
- const desc = Reflect.getOwnPropertyDescriptor(init, key);
+ const desc = ReflectGetOwnPropertyDescriptor(init, key);
if (desc !== undefined && desc.enumerable) {
const typedKey = toUSVString(key);
const typedValue = toUSVString(init[key]);
@@ -338,7 +347,7 @@ class URL {
[inspect.custom](depth, opts) {
if (this == null ||
- Object.getPrototypeOf(this[context]) !== URLContext.prototype) {
+ ObjectGetPrototypeOf(this[context]) !== URLContext.prototype) {
throw new ERR_INVALID_THIS('URL');
}
@@ -347,7 +356,7 @@ class URL {
const ctor = getConstructorOf(this);
- const obj = Object.create({
+ const obj = ObjectCreate({
constructor: ctor === null ? URL : ctor
});
@@ -374,7 +383,7 @@ class URL {
}
}
-Object.defineProperties(URL.prototype, {
+ObjectDefineProperties(URL.prototype, {
[kFormat]: {
enumerable: false,
configurable: false,
@@ -846,7 +855,7 @@ function serializeParams(array) {
// Mainly to mitigate func-name-matching ESLint rule
function defineIDLClass(proto, classStr, obj) {
// https://heycam.github.io/webidl/#dfn-class-string
- Object.defineProperty(proto, Symbol.toStringTag, {
+ ObjectDefineProperty(proto, Symbol.toStringTag, {
writable: false,
enumerable: false,
configurable: true,
@@ -854,16 +863,16 @@ function defineIDLClass(proto, classStr, obj) {
});
// https://heycam.github.io/webidl/#es-operations
- for (const key of Object.keys(obj)) {
- Object.defineProperty(proto, key, {
+ for (const key of ObjectKeys(obj)) {
+ ObjectDefineProperty(proto, key, {
writable: true,
enumerable: true,
configurable: true,
value: obj[key]
});
}
- for (const key of Object.getOwnPropertySymbols(obj)) {
- Object.defineProperty(proto, key, {
+ for (const key of ObjectGetOwnPropertySymbols(obj)) {
+ ObjectDefineProperty(proto, key, {
writable: true,
enumerable: false,
configurable: true,
@@ -1137,7 +1146,7 @@ defineIDLClass(URLSearchParams.prototype, 'URLSearchParams', {
});
// https://heycam.github.io/webidl/#es-iterable-entries
-Object.defineProperty(URLSearchParams.prototype, Symbol.iterator, {
+ObjectDefineProperty(URLSearchParams.prototype, Symbol.iterator, {
writable: true,
configurable: true,
value: URLSearchParams.prototype.entries
@@ -1145,7 +1154,7 @@ Object.defineProperty(URLSearchParams.prototype, Symbol.iterator, {
// https://heycam.github.io/webidl/#dfn-default-iterator-object
function createSearchParamsIterator(target, kind) {
- const iterator = Object.create(URLSearchParamsIteratorPrototype);
+ const iterator = ObjectCreate(URLSearchParamsIteratorPrototype);
iterator[context] = {
target,
kind,
@@ -1155,12 +1164,12 @@ function createSearchParamsIterator(target, kind) {
}
// https://heycam.github.io/webidl/#dfn-iterator-prototype-object
-const URLSearchParamsIteratorPrototype = Object.create(IteratorPrototype);
+const URLSearchParamsIteratorPrototype = ObjectCreate(IteratorPrototype);
defineIDLClass(URLSearchParamsIteratorPrototype, 'URLSearchParams Iterator', {
next() {
if (!this ||
- Object.getPrototypeOf(this) !== URLSearchParamsIteratorPrototype) {
+ ObjectGetPrototypeOf(this) !== URLSearchParamsIteratorPrototype) {
throw new ERR_INVALID_THIS('URLSearchParamsIterator');
}
@@ -1402,7 +1411,7 @@ function constructUrl(flags, protocol, username, password,
ctx.fragment = fragment;
ctx.host = host;
- const url = Object.create(URL.prototype);
+ const url = ObjectCreate(URL.prototype);
url[context] = ctx;
const params = new URLSearchParams();
url[searchParams] = params;