Skip to content
Snippets Groups Projects
Commit 485059c4 authored by Sam Mikes's avatar Sam Mikes Committed by Brian Terlson
Browse files

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
parent e2aa196a
No related branches found
No related tags found
No related merge requests found
// 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]);
}
// 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);
// 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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment