Improve coverage of mapped arguments' [[DefineOwnProperty]] method

This commit is contained in:
Alexey Shvayka 2020-12-10 20:40:02 +02:00 committed by Rick Waldron
parent 734c867ac3
commit 51666c5315
3 changed files with 132 additions and 0 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);