Fix isWritable throwing RangeError on Array "length"

This commit is contained in:
Alexey Shvayka 2020-03-13 16:17:40 +02:00 committed by Rick Waldron
parent 1eff480aca
commit 17fc10942e
2 changed files with 16 additions and 1 deletions

View File

@ -140,7 +140,8 @@ function isSameValue(a, b) {
}
function isWritable(obj, name, verifyProp, value) {
var newValue = value || "unlikelyValue";
var unlikelyValue = Array.isArray(obj) && name === "length" ? 217493 : "unlikelyValue";
var newValue = value || unlikelyValue;
var hadValue = Object.prototype.hasOwnProperty.call(obj, name);
var oldValue = obj[name];
var writeSucceeded;

View File

@ -0,0 +1,14 @@
// Copyright (C) 2020 Alexey Shvayka. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
"length" property of Arrays is tested with valid value.
includes: [propertyHelper.js]
---*/
var array = [1, 2, 3];
verifyWritable(array, "length");
assert.sameValue(array.length, 3, '`verifyWritable` should be non-destructive.');