• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright JS Foundation and other contributors, http://js.foundation
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15var array = ["foo", [], Infinity, 4]
16assert(array.length === 4);
17
18assert(array.pop() === 4)
19assert(array.length === 3);
20
21assert(array.pop() === Infinity);
22assert(array.length === 2);
23
24var a = array.pop()
25assert(a instanceof Array);
26assert(array.length === 1);
27
28assert(array.pop() === "foo");
29assert(array.length === 0);
30
31assert(array.pop() === undefined);
32assert(array.length === 0);
33
34// Checking behavior when unable to get length
35var obj = { pop : Array.prototype.pop };
36Object.defineProperty(obj, 'length', { 'get' : function () {throw new ReferenceError ("foo"); } });
37
38try {
39  obj.pop();
40  assert(false);
41} catch (e) {
42  assert(e.message === "foo");
43  assert(e instanceof ReferenceError);
44}
45
46// Checking behavior when unable to set length
47var obj = { pop : Array.prototype.pop };
48Object.defineProperty(obj, 'length', { 'set' : function () {throw new ReferenceError ("foo"); } });
49
50try {
51  obj.pop();
52  assert(false);
53} catch (e) {
54  assert(e.message === "foo");
55  assert(e instanceof ReferenceError);
56}
57
58// Checking behavior when no length property defined
59var obj = { pop : Array.prototype.pop };
60assert(obj.length === undefined)
61assert(obj.pop() === undefined)
62assert(obj.length === 0)
63
64// Checking behavior when unable to get element
65var obj = { pop : Array.prototype.pop, length : 1 };
66Object.defineProperty(obj, '0', { 'get' : function () {throw new ReferenceError ("foo"); } });
67
68try {
69  obj.pop();
70  assert(false);
71} catch (e) {
72  assert(e.message === "foo");
73  assert(e instanceof ReferenceError);
74}
75
76/* ES v5.1 15.4.4.6.5.c
77   Checking behavior when unable to delete property */
78var obj = {pop : Array.prototype.pop, length : 2};
79Object.defineProperty(obj, '1', function () {});
80
81try {
82  obj.pop();
83  assert(false);
84} catch (e) {
85  assert(e instanceof TypeError);
86}
87
88/* ES v5.1 15.4.4.6.5.d
89   Checking behavior when array is not modifiable */
90var obj = {pop : Array.prototype.pop, length : 2};
91Object.freeze(obj);
92
93try {
94  obj.pop();
95  assert(false);
96} catch (e) {
97  assert(e instanceof TypeError);
98}
99