Skip to content

Commit

Permalink
[Refactor] create and use helpers/isPropertyKey
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Apr 23, 2024
1 parent f0cddec commit 783ee6e
Show file tree
Hide file tree
Showing 192 changed files with 487 additions and 512 deletions.
6 changes: 3 additions & 3 deletions 2015/CreateDataProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var $TypeError = require('es-errors/type');

var IsPropertyKey = require('./IsPropertyKey');
var isPropertyKey = require('../helpers/isPropertyKey');
var OrdinaryDefineOwnProperty = require('./OrdinaryDefineOwnProperty');

var isObject = require('../helpers/isObject');
Expand All @@ -13,8 +13,8 @@ module.exports = function CreateDataProperty(O, P, V) {
if (!isObject(O)) {
throw new $TypeError('Assertion failed: Type(O) is not Object');
}
if (!IsPropertyKey(P)) {
throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true');
if (!isPropertyKey(P)) {
throw new $TypeError('Assertion failed: P is not a Property Key');
}
var newDesc = {
'[[Configurable]]': true,
Expand Down
6 changes: 3 additions & 3 deletions 2015/CreateDataPropertyOrThrow.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
var $TypeError = require('es-errors/type');

var CreateDataProperty = require('./CreateDataProperty');
var IsPropertyKey = require('./IsPropertyKey');

var isObject = require('../helpers/isObject');
var isPropertyKey = require('../helpers/isPropertyKey');

// // https://262.ecma-international.org/6.0/#sec-createdatapropertyorthrow

module.exports = function CreateDataPropertyOrThrow(O, P, V) {
if (!isObject(O)) {
throw new $TypeError('Assertion failed: Type(O) is not Object');
}
if (!IsPropertyKey(P)) {
throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true');
if (!isPropertyKey(P)) {
throw new $TypeError('Assertion failed: P is not a Property Key');
}
var success = CreateDataProperty(O, P, V);
if (!success) {
Expand Down
6 changes: 3 additions & 3 deletions 2015/CreateMethodProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var DefineOwnProperty = require('../helpers/DefineOwnProperty');

var FromPropertyDescriptor = require('./FromPropertyDescriptor');
var IsDataDescriptor = require('./IsDataDescriptor');
var IsPropertyKey = require('./IsPropertyKey');
var isPropertyKey = require('../helpers/isPropertyKey');
var SameValue = require('./SameValue');

var isObject = require('../helpers/isObject');
Expand All @@ -18,8 +18,8 @@ module.exports = function CreateMethodProperty(O, P, V) {
throw new $TypeError('Assertion failed: Type(O) is not Object');
}

if (!IsPropertyKey(P)) {
throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true');
if (!isPropertyKey(P)) {
throw new $TypeError('Assertion failed: P is not a Property Key');
}

var newDesc = {
Expand Down
6 changes: 3 additions & 3 deletions 2015/DefinePropertyOrThrow.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var DefineOwnProperty = require('../helpers/DefineOwnProperty');

var FromPropertyDescriptor = require('./FromPropertyDescriptor');
var IsDataDescriptor = require('./IsDataDescriptor');
var IsPropertyKey = require('./IsPropertyKey');
var isPropertyKey = require('../helpers/isPropertyKey');
var SameValue = require('./SameValue');
var ToPropertyDescriptor = require('./ToPropertyDescriptor');

Expand All @@ -20,8 +20,8 @@ module.exports = function DefinePropertyOrThrow(O, P, desc) {
throw new $TypeError('Assertion failed: Type(O) is not Object');
}

if (!IsPropertyKey(P)) {
throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true');
if (!isPropertyKey(P)) {
throw new $TypeError('Assertion failed: P is not a Property Key');
}

var Desc = isPropertyDescriptor(desc) ? desc : ToPropertyDescriptor(desc);
Expand Down
7 changes: 3 additions & 4 deletions 2015/DeletePropertyOrThrow.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

var $TypeError = require('es-errors/type');

var IsPropertyKey = require('./IsPropertyKey');

var isObject = require('../helpers/isObject');
var isPropertyKey = require('../helpers/isPropertyKey');

// https://262.ecma-international.org/6.0/#sec-deletepropertyorthrow

Expand All @@ -13,8 +12,8 @@ module.exports = function DeletePropertyOrThrow(O, P) {
throw new $TypeError('Assertion failed: Type(O) is not Object');
}

if (!IsPropertyKey(P)) {
throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true');
if (!isPropertyKey(P)) {
throw new $TypeError('Assertion failed: P is not a Property Key');
}

// eslint-disable-next-line no-param-reassign
Expand Down
7 changes: 3 additions & 4 deletions 2015/Get.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ var $TypeError = require('es-errors/type');

var inspect = require('object-inspect');

var IsPropertyKey = require('./IsPropertyKey');

var isObject = require('../helpers/isObject');
var isPropertyKey = require('../helpers/isPropertyKey');

// https://262.ecma-international.org/6.0/#sec-get-o-p

Expand All @@ -16,8 +15,8 @@ module.exports = function Get(O, P) {
throw new $TypeError('Assertion failed: Type(O) is not Object');
}
// 7.3.1.2
if (!IsPropertyKey(P)) {
throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true, got ' + inspect(P));
if (!isPropertyKey(P)) {
throw new $TypeError('Assertion failed: P is not a Property Key, got ' + inspect(P));
}
// 7.3.1.3
return O[P];
Expand Down
6 changes: 3 additions & 3 deletions 2015/GetMethod.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ var $TypeError = require('es-errors/type');

var GetV = require('./GetV');
var IsCallable = require('./IsCallable');
var IsPropertyKey = require('./IsPropertyKey');
var isPropertyKey = require('../helpers/isPropertyKey');

var inspect = require('object-inspect');

// https://262.ecma-international.org/6.0/#sec-getmethod

module.exports = function GetMethod(O, P) {
// 7.3.9.1
if (!IsPropertyKey(P)) {
throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true');
if (!isPropertyKey(P)) {
throw new $TypeError('Assertion failed: P is not a Property Key');
}

// 7.3.9.2
Expand Down
6 changes: 3 additions & 3 deletions 2015/GetV.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ var $TypeError = require('es-errors/type');

var inspect = require('object-inspect');

var IsPropertyKey = require('./IsPropertyKey');
var isPropertyKey = require('../helpers/isPropertyKey');
// var ToObject = require('./ToObject');

// https://262.ecma-international.org/6.0/#sec-getv

module.exports = function GetV(V, P) {
// 7.3.2.1
if (!IsPropertyKey(P)) {
throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true, got ' + inspect(P));
if (!isPropertyKey(P)) {
throw new $TypeError('Assertion failed: P is not a Property Key, got ' + inspect(P));
}

// 7.3.2.2-3
Expand Down
5 changes: 2 additions & 3 deletions 2015/HasOwnProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ var $TypeError = require('es-errors/type');

var hasOwn = require('hasown');

var IsPropertyKey = require('./IsPropertyKey');

var isObject = require('../helpers/isObject');
var isPropertyKey = require('../helpers/isPropertyKey');

// https://262.ecma-international.org/6.0/#sec-hasownproperty

module.exports = function HasOwnProperty(O, P) {
if (!isObject(O)) {
throw new $TypeError('Assertion failed: `O` must be an Object');
}
if (!IsPropertyKey(P)) {
if (!isPropertyKey(P)) {
throw new $TypeError('Assertion failed: `P` must be a Property Key');
}
return hasOwn(O, P);
Expand Down
5 changes: 2 additions & 3 deletions 2015/HasProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@

var $TypeError = require('es-errors/type');

var IsPropertyKey = require('./IsPropertyKey');

var isObject = require('../helpers/isObject');
var isPropertyKey = require('../helpers/isPropertyKey');

// https://262.ecma-international.org/6.0/#sec-hasproperty

module.exports = function HasProperty(O, P) {
if (!isObject(O)) {
throw new $TypeError('Assertion failed: `O` must be an Object');
}
if (!IsPropertyKey(P)) {
if (!isPropertyKey(P)) {
throw new $TypeError('Assertion failed: `P` must be a Property Key');
}
return P in O;
Expand Down
4 changes: 2 additions & 2 deletions 2015/Invoke.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ var $TypeError = require('es-errors/type');
var Call = require('./Call');
var IsArray = require('./IsArray');
var GetV = require('./GetV');
var IsPropertyKey = require('./IsPropertyKey');
var isPropertyKey = require('../helpers/isPropertyKey');

// https://262.ecma-international.org/6.0/#sec-invoke

module.exports = function Invoke(O, P) {
if (!IsPropertyKey(P)) {
if (!isPropertyKey(P)) {
throw new $TypeError('Assertion failed: P must be a Property Key');
}
var argumentsList = arguments.length > 2 ? arguments[2] : [];
Expand Down
4 changes: 3 additions & 1 deletion 2015/IsPropertyKey.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
'use strict';

var isPropertyKey = require('../helpers/isPropertyKey');

// https://262.ecma-international.org/6.0/#sec-ispropertykey

module.exports = function IsPropertyKey(argument) {
return typeof argument === 'string' || typeof argument === 'symbol';
return isPropertyKey(argument);
};
4 changes: 2 additions & 2 deletions 2015/OrdinaryDefineOwnProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var isPropertyDescriptor = require('../helpers/records/property-descriptor');

var IsAccessorDescriptor = require('./IsAccessorDescriptor');
var IsExtensible = require('./IsExtensible');
var IsPropertyKey = require('./IsPropertyKey');
var isPropertyKey = require('../helpers/isPropertyKey');
var ToPropertyDescriptor = require('./ToPropertyDescriptor');
var SameValue = require('./SameValue');
var ValidateAndApplyPropertyDescriptor = require('./ValidateAndApplyPropertyDescriptor');
Expand All @@ -21,7 +21,7 @@ module.exports = function OrdinaryDefineOwnProperty(O, P, Desc) {
if (!isObject(O)) {
throw new $TypeError('Assertion failed: O must be an Object');
}
if (!IsPropertyKey(P)) {
if (!isPropertyKey(P)) {
throw new $TypeError('Assertion failed: P must be a Property Key');
}
if (!isPropertyDescriptor(Desc)) {
Expand Down
4 changes: 2 additions & 2 deletions 2015/OrdinaryGetOwnProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var $isEnumerable = callBound('Object.prototype.propertyIsEnumerable');
var hasOwn = require('hasown');

var IsArray = require('./IsArray');
var IsPropertyKey = require('./IsPropertyKey');
var isPropertyKey = require('../helpers/isPropertyKey');
var IsRegExp = require('./IsRegExp');
var ToPropertyDescriptor = require('./ToPropertyDescriptor');

Expand All @@ -22,7 +22,7 @@ module.exports = function OrdinaryGetOwnProperty(O, P) {
if (!isObject(O)) {
throw new $TypeError('Assertion failed: O must be an Object');
}
if (!IsPropertyKey(P)) {
if (!isPropertyKey(P)) {
throw new $TypeError('Assertion failed: P must be a Property Key');
}
if (!hasOwn(O, P)) {
Expand Down
5 changes: 2 additions & 3 deletions 2015/OrdinaryHasProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@

var $TypeError = require('es-errors/type');

var IsPropertyKey = require('./IsPropertyKey');

var isObject = require('../helpers/isObject');
var isPropertyKey = require('../helpers/isPropertyKey');

// https://262.ecma-international.org/6.0/#sec-ordinaryhasproperty

module.exports = function OrdinaryHasProperty(O, P) {
if (!isObject(O)) {
throw new $TypeError('Assertion failed: Type(O) is not Object');
}
if (!IsPropertyKey(P)) {
if (!isPropertyKey(P)) {
throw new $TypeError('Assertion failed: P must be a Property Key');
}
return P in O;
Expand Down
4 changes: 2 additions & 2 deletions 2015/Set.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var $TypeError = require('es-errors/type');

var IsPropertyKey = require('./IsPropertyKey');
var isPropertyKey = require('../helpers/isPropertyKey');
var SameValue = require('./SameValue');

var isObject = require('../helpers/isObject');
Expand All @@ -23,7 +23,7 @@ module.exports = function Set(O, P, V, Throw) {
if (!isObject(O)) {
throw new $TypeError('Assertion failed: `O` must be an Object');
}
if (!IsPropertyKey(P)) {
if (!isPropertyKey(P)) {
throw new $TypeError('Assertion failed: `P` must be a Property Key');
}
if (typeof Throw !== 'boolean') {
Expand Down
4 changes: 2 additions & 2 deletions 2015/StringGetIndexProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ var unbox = require('unbox-primitive');

var CanonicalNumericIndexString = require('./CanonicalNumericIndexString');
var IsInteger = require('./IsInteger');
var IsPropertyKey = require('./IsPropertyKey');
var isPropertyKey = require('../helpers/isPropertyKey');

// https://262.ecma-international.org/6.0/#sec-stringgetindexproperty

module.exports = function StringGetIndexProperty(S, P) {
if (typeof S === 'string' || !isString(S)) {
throw new $TypeError('Assertion failed: `S` must be a boxed String Object');
}
if (!IsPropertyKey(P)) {
if (!isPropertyKey(P)) {
throw new $TypeError('Assertion failed: `P` must be a Property Key');
}

Expand Down
4 changes: 2 additions & 2 deletions 2015/ValidateAndApplyPropertyDescriptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var FromPropertyDescriptor = require('./FromPropertyDescriptor');
var IsAccessorDescriptor = require('./IsAccessorDescriptor');
var IsDataDescriptor = require('./IsDataDescriptor');
var IsGenericDescriptor = require('./IsGenericDescriptor');
var IsPropertyKey = require('./IsPropertyKey');
var isPropertyKey = require('../helpers/isPropertyKey');
var SameValue = require('./SameValue');

var isObject = require('../helpers/isObject');
Expand All @@ -33,7 +33,7 @@ module.exports = function ValidateAndApplyPropertyDescriptor(O, P, extensible, D
if (typeof current !== 'undefined' && !isPropertyDescriptor(current)) {
throw new $TypeError('Assertion failed: current must be a Property Descriptor, or undefined');
}
if (typeof O !== 'undefined' && !IsPropertyKey(P)) {
if (typeof O !== 'undefined' && !isPropertyKey(P)) {
throw new $TypeError('Assertion failed: if O is not undefined, P must be a Property Key');
}
if (typeof current === 'undefined') {
Expand Down
6 changes: 3 additions & 3 deletions 2016/CreateDataProperty.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions 2016/CreateDataPropertyOrThrow.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 783ee6e

Please sign in to comment.