From 51666c5315ee674d3157544497d933310e2cd6b8 Mon Sep 17 00:00:00 2001 From: Alexey Shvayka Date: Thu, 10 Dec 2020 20:40:02 +0200 Subject: [PATCH] Improve coverage of mapped arguments' [[DefineOwnProperty]] method --- ...erable-configurable-accessor-descriptor.js | 44 ++++++++++++++++++ ...configurable-descriptors-define-failure.js | 43 ++++++++++++++++++ ...able-enumerable-configurable-descriptor.js | 45 +++++++++++++++++++ 3 files changed, 132 insertions(+) create mode 100644 test/language/arguments-object/mapped/enumerable-configurable-accessor-descriptor.js create mode 100644 test/language/arguments-object/mapped/nonconfigurable-descriptors-define-failure.js create mode 100644 test/language/arguments-object/mapped/writable-enumerable-configurable-descriptor.js diff --git a/test/language/arguments-object/mapped/enumerable-configurable-accessor-descriptor.js b/test/language/arguments-object/mapped/enumerable-configurable-accessor-descriptor.js new file mode 100644 index 0000000000..38b651203d --- /dev/null +++ b/test/language/arguments-object/mapped/enumerable-configurable-accessor-descriptor.js @@ -0,0 +1,44 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-arguments-exotic-objects-defineownproperty-p-desc +description: > + Index gets unmapped when redefined with accessor. Unmapped index is created. +info: | + [[DefineOwnProperty]] ( P, Desc ) + + [...] + 6. Let allowed be ? OrdinaryDefineOwnProperty(args, P, newArgDesc). + 7. If allowed is false, return false. + 8. If isMapped is true, then + a. If IsAccessorDescriptor(Desc) is true, then + i. Call map.[[Delete]](P). + [...] + 9. Return true. +flags: [noStrict] +---*/ + +(function(a) { + let setCalls = 0; + Object.defineProperty(arguments, "0", { + set(_v) { setCalls += 1; }, + enumerable: true, + configurable: true, + }); + + arguments[0] = "foo"; + + assert.sameValue(setCalls, 1); + assert.sameValue(a, 0); + assert.sameValue(arguments[0], undefined); + + + Object.defineProperty(arguments, "1", { + get: () => "bar", + enumerable: true, + configurable: true, + }); + + assert.sameValue(arguments[1], "bar"); +})(0); diff --git a/test/language/arguments-object/mapped/nonconfigurable-descriptors-define-failure.js b/test/language/arguments-object/mapped/nonconfigurable-descriptors-define-failure.js new file mode 100644 index 0000000000..d7175bf3de --- /dev/null +++ b/test/language/arguments-object/mapped/nonconfigurable-descriptors-define-failure.js @@ -0,0 +1,43 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-arguments-exotic-objects-defineownproperty-p-desc +description: > + OrdinaryDefineOwnProperty returning `false` doesn't leave `arguments` in a + corrupted state, for both mapped and unmapped indices. +info: | + [[DefineOwnProperty]] ( P, Desc ) + + [...] + 6. Let allowed be ? OrdinaryDefineOwnProperty(args, P, newArgDesc). + 7. If allowed is false, return false. +flags: [noStrict] +---*/ + +(function(a) { + Object.defineProperty(arguments, "0", {configurable: false}); + + assert.throws(TypeError, () => { + Object.defineProperty(arguments, "0", {configurable: true}); + }); + + a = 2; + assert.sameValue(arguments[0], 2); + + + Object.defineProperty(arguments, "1", { + get: () => 3, + configurable: false, + }); + + assert.throws(TypeError, () => { + Object.defineProperty(arguments, "1", {value: "foo"}); + }); + + assert.sameValue(arguments[1], 3); + assert.throws(TypeError, () => { + "use strict"; + delete arguments[1]; + }); +})(0); diff --git a/test/language/arguments-object/mapped/writable-enumerable-configurable-descriptor.js b/test/language/arguments-object/mapped/writable-enumerable-configurable-descriptor.js new file mode 100644 index 0000000000..bf0d76a3b7 --- /dev/null +++ b/test/language/arguments-object/mapped/writable-enumerable-configurable-descriptor.js @@ -0,0 +1,45 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-arguments-exotic-objects-defineownproperty-p-desc +description: > + Index stays mapped when redefined with complete descriptor, which differs only + by the [[Value]] field. Unmapped index is created. +info: | + [[DefineOwnProperty]] ( P, Desc ) + + [...] + 6. Let allowed be ? OrdinaryDefineOwnProperty(args, P, newArgDesc). + 7. If allowed is false, return false. + 8. If isMapped is true, then + [...] + b. Else, + i. If Desc.[[Value]] is present, then + 1. Let setStatus be Set(map, P, Desc.[[Value]], false). + 2. Assert: setStatus is true because formal parameters mapped by argument objects are always writable. + 9. Return true. +flags: [noStrict] +---*/ + +(function(a) { + Object.defineProperty(arguments, "0", { + value: "foo", + writable: true, + enumerable: true, + configurable: true, + }); + + assert.sameValue(a, "foo"); + assert.sameValue(arguments[0], "foo"); + + + Object.defineProperty(arguments, "1", { + value: "bar", + writable: true, + enumerable: true, + configurable: true, + }); + + assert.sameValue(arguments[1], "bar"); +})(0);