Skip to content

Commit 4e69296

Browse files
committed
harness: Simplify verifyCallableProperty
Ref tc39#4468 Match the data property defaults from https://tc39.es/ecma262/multipage/ecmascript-standard-built-in-objects.html (writable true, enumerable false, configurable true).
1 parent e764feb commit 4e69296

File tree

5 files changed

+24
-22
lines changed

5 files changed

+24
-22
lines changed

harness/propertyHelper.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,15 @@ function isWritable(obj, name, verifyProp, value) {
209209
}
210210

211211
/**
212+
* Verify that there is a function of specified name, length, and containing
213+
* descriptor associated with `obj[name]` and following the conventions for
214+
* built-in objects.
215+
*
212216
* @param {object} obj
213217
* @param {string|symbol} name
214218
* @param {string} [functionName] defaults to name for strings, `[${name.description}]` for symbols
215219
* @param {number} functionLength
216-
* @param {PropertyDescriptor} desc
220+
* @param {PropertyDescriptor} [desc] defaults to data property conventions (writable, non-enumerable, configurable)
217221
* @param {object} [options]
218222
* @param {boolean} [options.restore] revert mutations from verifying writable/configurable
219223
*/
@@ -223,7 +227,21 @@ function verifyCallableProperty(obj, name, functionName, functionLength, desc, o
223227
assert.sameValue(typeof value, "function",
224228
"obj['" + String(name) + "'] descriptor should be a function");
225229

226-
if (!__hasOwnProperty(desc, "value")) desc.value = value;
230+
// Every other data property described in clauses 19 through 28 and in
231+
// Annex B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false,
232+
// [[Configurable]]: true } unless otherwise specified.
233+
// https://tc39.es/ecma262/multipage/ecmascript-standard-built-in-objects.html
234+
if (desc === undefined) {
235+
desc = {
236+
writable: true,
237+
enumerable: false,
238+
configurable: true,
239+
value: value
240+
};
241+
} else if (!__hasOwnProperty(desc, "value") && !__hasOwnProperty(desc, "get")) {
242+
desc.value = value;
243+
}
244+
227245
verifyProperty(obj, name, desc, options);
228246

229247
if (functionName === undefined) {

test/built-ins/isFinite/prop-desc.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,4 @@ description: >
88
includes: [propertyHelper.js]
99
---*/
1010

11-
verifyPrimordialCallableProperty(this, "isFinite", "isFinite", 1, {
12-
writable: true,
13-
enumerable: false,
14-
configurable: true
15-
});
11+
verifyPrimordialCallableProperty(this, "isFinite", "isFinite", 1);

test/built-ins/isNaN/prop-desc.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,4 @@ description: >
88
includes: [propertyHelper.js]
99
---*/
1010

11-
verifyPrimordialCallableProperty(this, "isNaN", "isNaN", 1, {
12-
writable: true,
13-
enumerable: false,
14-
configurable: true
15-
});
11+
verifyPrimordialCallableProperty(this, "isNaN", "isNaN", 1);

test/built-ins/parseFloat/prop-desc.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,4 @@ info: |
1212
includes: [propertyHelper.js]
1313
---*/
1414

15-
verifyPrimordialCallableProperty(this, "parseFloat", "parseFloat", 1, {
16-
writable: true,
17-
enumerable: false,
18-
configurable: true
19-
});
15+
verifyPrimordialCallableProperty(this, "parseFloat", "parseFloat", 1);

test/built-ins/parseInt/prop-desc.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,4 @@ info: |
1111
includes: [propertyHelper.js]
1212
---*/
1313

14-
verifyPrimordialCallableProperty(this, "parseInt", "parseInt", 2, {
15-
writable: true,
16-
enumerable: false,
17-
configurable: true
18-
});
14+
verifyPrimordialCallableProperty(this, "parseInt", "parseInt", 2);

0 commit comments

Comments
 (0)