From 99867ff6185c31703cba3e5e9cb574c2b8365920 Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Wed, 28 May 2025 16:53:15 -0400 Subject: [PATCH] harness: Simplify verifyCallableProperty (#4507) Ref #4468 --- harness/propertyHelper.js | 22 ++++++++++++++++++++-- test/built-ins/isFinite/prop-desc.js | 6 +----- test/built-ins/isNaN/prop-desc.js | 6 +----- test/built-ins/parseFloat/prop-desc.js | 6 +----- test/built-ins/parseInt/prop-desc.js | 6 +----- 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/harness/propertyHelper.js b/harness/propertyHelper.js index 0b702b0764..51cc80c880 100644 --- a/harness/propertyHelper.js +++ b/harness/propertyHelper.js @@ -209,11 +209,15 @@ function isWritable(obj, name, verifyProp, value) { } /** + * Verify that there is a function of specified name, length, and containing + * descriptor associated with `obj[name]` and following the conventions for + * built-in objects. + * * @param {object} obj * @param {string|symbol} name * @param {string} [functionName] defaults to name for strings, `[${name.description}]` for symbols * @param {number} functionLength - * @param {PropertyDescriptor} desc + * @param {PropertyDescriptor} [desc] defaults to data property conventions (writable, non-enumerable, configurable) * @param {object} [options] * @param {boolean} [options.restore] revert mutations from verifying writable/configurable */ @@ -223,7 +227,21 @@ function verifyCallableProperty(obj, name, functionName, functionLength, desc, o assert.sameValue(typeof value, "function", "obj['" + String(name) + "'] descriptor should be a function"); - if (!__hasOwnProperty(desc, "value")) desc.value = value; + // Every other data property described in clauses 19 through 28 and in + // Annex B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false, + // [[Configurable]]: true } unless otherwise specified. + // https://tc39.es/ecma262/multipage/ecmascript-standard-built-in-objects.html + if (desc === undefined) { + desc = { + writable: true, + enumerable: false, + configurable: true, + value: value + }; + } else if (!__hasOwnProperty(desc, "value") && !__hasOwnProperty(desc, "get")) { + desc.value = value; + } + verifyProperty(obj, name, desc, options); if (functionName === undefined) { diff --git a/test/built-ins/isFinite/prop-desc.js b/test/built-ins/isFinite/prop-desc.js index 0532a4a7da..f73f905bad 100644 --- a/test/built-ins/isFinite/prop-desc.js +++ b/test/built-ins/isFinite/prop-desc.js @@ -8,8 +8,4 @@ description: > includes: [propertyHelper.js] ---*/ -verifyPrimordialCallableProperty(this, "isFinite", "isFinite", 1, { - writable: true, - enumerable: false, - configurable: true -}); +verifyPrimordialCallableProperty(this, "isFinite", "isFinite", 1); diff --git a/test/built-ins/isNaN/prop-desc.js b/test/built-ins/isNaN/prop-desc.js index 3c52a36617..7b0d823a00 100644 --- a/test/built-ins/isNaN/prop-desc.js +++ b/test/built-ins/isNaN/prop-desc.js @@ -8,8 +8,4 @@ description: > includes: [propertyHelper.js] ---*/ -verifyPrimordialCallableProperty(this, "isNaN", "isNaN", 1, { - writable: true, - enumerable: false, - configurable: true -}); +verifyPrimordialCallableProperty(this, "isNaN", "isNaN", 1); diff --git a/test/built-ins/parseFloat/prop-desc.js b/test/built-ins/parseFloat/prop-desc.js index cc5970b9be..02d288dc1b 100644 --- a/test/built-ins/parseFloat/prop-desc.js +++ b/test/built-ins/parseFloat/prop-desc.js @@ -12,8 +12,4 @@ info: | includes: [propertyHelper.js] ---*/ -verifyPrimordialCallableProperty(this, "parseFloat", "parseFloat", 1, { - writable: true, - enumerable: false, - configurable: true -}); +verifyPrimordialCallableProperty(this, "parseFloat", "parseFloat", 1); diff --git a/test/built-ins/parseInt/prop-desc.js b/test/built-ins/parseInt/prop-desc.js index dad9021dae..99c292ff86 100644 --- a/test/built-ins/parseInt/prop-desc.js +++ b/test/built-ins/parseInt/prop-desc.js @@ -11,8 +11,4 @@ info: | includes: [propertyHelper.js] ---*/ -verifyPrimordialCallableProperty(this, "parseInt", "parseInt", 2, { - writable: true, - enumerable: false, - configurable: true -}); +verifyPrimordialCallableProperty(this, "parseInt", "parseInt", 2);