mirror of https://github.com/tc39/test262.git
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
|
@ -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]);
|
||||
}
|
|
@ -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);
|
|
@ -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…
Reference in New Issue