Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
67 lines (59 loc) · 6.14 KB

File metadata and controls

67 lines (59 loc) · 6.14 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
// Some of the Array.prototype built-in functions set the length property of the array object and
// should throw a TypeError if setting the length property fails. Tests in this file verify that
// we throw TypeError when we're supposed to.
// See BLUE: 559834 for more details
if (this.WScript && this.WScript.LoadScriptFile) { // Check for running in ch
this.WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
}
var tests = [
{
name: "Array.prototype built-in functions called with object that has length property with no setter",
body: function () {
var obj = { 0: 0, 1: 1, get length() { return 2; }};
assert.throws(function() { Array.prototype.pop.call(obj); }, TypeError, "Array.prototype.pop throws when obj has a getter for length but is missing a setter", "Cannot define property: object is not extensible");
assert.throws(function() { Array.prototype.push.call(obj, 2); }, TypeError, "Array.prototype.push throws when obj has a getter for length but is missing a setter", "Cannot define property: object is not extensible");
assert.throws(function() { Array.prototype.shift.call(obj); }, TypeError, "Array.prototype.shift throws when obj has a getter for length but is missing a setter", "Cannot define property: object is not extensible");
assert.throws(function() { Array.prototype.unshift.call(obj, 2); }, TypeError, "Array.prototype.unshift throws when obj has a getter for length but is missing a setter", "Cannot define property: object is not extensible");
assert.throws(function() { Array.prototype.splice.call(obj, 0, 1); }, TypeError, "Array.prototype.splice throws when obj has a getter for length but is missing a setter", "Cannot define property: object is not extensible");
}
},
{
name: "Array.prototype built-in functions called with object that has length property with no setter and length property has zero value",
body: function () {
var obj = { 0: 0, 1: 1, get length() { return 0; }};
assert.throws(function() { Array.prototype.pop.call(obj); }, TypeError, "Array.prototype.pop throws when obj has a getter for length which returns zero", "Cannot define property: object is not extensible");
assert.throws(function() { Array.prototype.push.call(obj, 2); }, TypeError, "Array.prototype.push throws when obj has a getter for length which returns zero", "Cannot define property: object is not extensible");
assert.throws(function() { Array.prototype.shift.call(obj); }, TypeError, "Array.prototype.shift throws when obj has a getter for length which returns zero", "Cannot define property: object is not extensible");
assert.throws(function() { Array.prototype.unshift.call(obj, 2); }, TypeError, "Array.prototype.unshift throws when obj has a getter for length which returns zero", "Cannot define property: object is not extensible");
assert.throws(function() { Array.prototype.splice.call(obj, 0, 1); }, TypeError, "Array.prototype.splice throws when obj has a getter for length which returns zero", "Cannot define property: object is not extensible");
}
},
{
name: "Array.prototype built-in functions called with object that has length property which is non-configurable and non-writable",
body: function () {
var obj = { 0: 0, 1: 1 };
Object.defineProperty(obj, "length", { value: 2, writable: false, configurable: false });
assert.throws(function() { Array.prototype.pop.call(obj); }, TypeError, "Array.prototype.pop throws when obj has a length property which is not writable and not configurable", "Object doesn't support this action");
assert.throws(function() { Array.prototype.push.call(obj, 2); }, TypeError, "Array.prototype.push throws when obj has a length property which is not writable and not configurable", "Object doesn't support this action");
assert.throws(function() { Array.prototype.shift.call(obj); }, TypeError, "Array.prototype.shift throws when obj has a length property which is not writable and not configurable", "Object doesn't support this action");
assert.throws(function() { Array.prototype.unshift.call(obj, 2); }, TypeError, "Array.prototype.unshift throws when obj has a length property which is not writable and not configurable", "Object doesn't support this action");
assert.throws(function() { Array.prototype.splice.call(obj, 0, 1); }, TypeError, "Array.prototype.splice throws when obj has a length property which is not writable and not configurable", "Object doesn't support this action");
}
},
{
name: "Array.prototype built-in functions called with object that has properties with index we need to set in prototype chain and property is an accessor with no setter",
body: function () {
var proto = {};
var obj = {0:1, 1:1, 2:1, 3:-109, length:4};
obj.__proto__ = proto;
Object.defineProperty(proto, "4", {configurable: true, get: function() { return 31; }});
assert.throws(function() { Array.prototype.unshift.call(obj, 200, 201, 202); }, TypeError, "Array.prototype.unshift throws when obj prototype-chain has a property named one of the indices we need to set which is an accessor with no setter", "Cannot define property: object is not extensible");
assert.throws(function() { Array.prototype.push.call(obj, 200); }, TypeError, "Array.prototype.push throws when obj prototype-chain has a property named one of the indices we need to set which is an accessor with no setter", "Cannot define property: object is not extensible");
}
},
];
testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });
Morty Proxy This is a proxified and sanitized view of the page, visit original site.