mirror of
https://github.com/tc39/test262.git
synced 2025-07-25 15:04:43 +02:00
initial tests of Array.prototpe.splice requiring settable "length"
add test of object with only "length" getter *fix typo per comments from @anba, thanks! * remove needless checks * add "splice" method fix es5id
This commit is contained in:
parent
e2aa196a93
commit
485059c46d
24
test/built-ins/Array/prototype/splice/S15.4.4.12_A6.1_T1.js
vendored
Normal file
24
test/built-ins/Array/prototype/splice/S15.4.4.12_A6.1_T1.js
vendored
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
// Copyright 2014 Ecma International. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
info: Array.prototype.splice sets `length` on `this`
|
||||||
|
es5id: 15.4.4.12_A6.1_T1
|
||||||
|
description: Array.prototype.splice sets `length` on Array
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var a = [0, 1, 2];
|
||||||
|
|
||||||
|
a.splice(1, 2, 4);
|
||||||
|
|
||||||
|
if (a.length !== 2) {
|
||||||
|
$ERROR("Expected a.length === 2, actually " + a.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (a[0] !== 0) {
|
||||||
|
$ERROR("Expected a[0] === 0, actually " + a[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (a[1] !== 4) {
|
||||||
|
$ERROR("Expected a[1] === 4, actually " + a[1]);
|
||||||
|
}
|
17
test/built-ins/Array/prototype/splice/S15.4.4.12_A6.1_T2.js
vendored
Normal file
17
test/built-ins/Array/prototype/splice/S15.4.4.12_A6.1_T2.js
vendored
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// Copyright 2014 Ecma International. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
info: Array.prototype.splice sets `length` on `this`
|
||||||
|
es5id: 15.4.4.12_A6.1_T2
|
||||||
|
description: Array.prototype.splice throws if `length` is read-only
|
||||||
|
negative: TypeError
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var a = [0, 1, 2];
|
||||||
|
|
||||||
|
Object.defineProperty(a, 'length', {
|
||||||
|
writable: false
|
||||||
|
});
|
||||||
|
|
||||||
|
a.splice(1, 2, 4);
|
22
test/built-ins/Array/prototype/splice/S15.4.4.12_A6.1_T3.js
vendored
Normal file
22
test/built-ins/Array/prototype/splice/S15.4.4.12_A6.1_T3.js
vendored
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// Copyright 2014 Ecma International. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
info: Array.prototype.splice sets `length` on `this`
|
||||||
|
es5id: 15.4.4.12_A6.1_T3
|
||||||
|
description: Array.prototype.splice throws if `length` is read-only
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var a = {
|
||||||
|
get length() { return 0; },
|
||||||
|
splice: Array.prototype.splice
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
a.splice(1, 2, 4);
|
||||||
|
$ERROR("Expected a TypeError");
|
||||||
|
} catch (e) {
|
||||||
|
if (!(e instanceof TypeError)) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user