Skip to content

Commit 501bf15

Browse files
committed
Adding tests for the fixes in ArraySetLength().
1 parent 3f4fa50 commit 501bf15

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) 2020, 2020, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
6+
*/
7+
8+
load('assert.js');
9+
10+
// valueOf() should be invoked twice (from ToUint32() and ToNumber())
11+
var valueOfCalls = 0;
12+
Object.defineProperty([0, 1, 2], 'length', {
13+
value: {
14+
valueOf: function () {
15+
valueOfCalls++;
16+
return 3;
17+
}
18+
}
19+
});
20+
assertSame(2, valueOfCalls);
21+
22+
// length should remain writable when its re-definition is refused
23+
var array = [42, 211];
24+
assertThrows(function () {
25+
Object.defineProperty(array, 'length', {
26+
writable: false,
27+
configurable: true
28+
});
29+
}, TypeError);
30+
array.length = 5;
31+
assertSame(5, array.length);
32+
33+
// length should be constant after re-definition with "writable: false"
34+
var array = [0, 1, 2];
35+
Object.defineProperty(array, 'length', {
36+
value: 3,
37+
writable: false
38+
});
39+
assertThrows(function () {
40+
array.splice(1, 2, 4);
41+
}, TypeError);
42+
assertSame(3, array.length);
43+
assertSame(array[0], 0);
44+
assertSame(array[1], 4);
45+
assertSame(array[2], undefined);
46+
47+
true;

0 commit comments

Comments
 (0)