• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2015 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5var array = [];
6var funky = {
7  toJSON: function() { array.length = 1; return "funky"; }
8};
9for (var i = 0; i < 10; i++) array[i] = i;
10array[0] = funky;
11assertEquals('["funky",null,null,null,null,null,null,null,null,null]',
12             JSON.stringify(array));
13
14array = [];
15funky = {
16  get value() { array.length = 1; return "funky"; }
17};
18for (var i = 0; i < 10; i++) array[i] = i;
19array[3] = funky;
20assertEquals('[0,1,2,{"value":"funky"},null,null,null,null,null,null]',
21             JSON.stringify(array));
22
23array = [];
24funky = {
25  get value() { array.pop(); return "funky"; }
26};
27for (var i = 0; i < 10; i++) array[i] = i;
28array[3] = funky;
29assertEquals('[0,1,2,{"value":"funky"},4,5,6,7,8,null]', JSON.stringify(array));
30
31array = [];
32funky = {
33  get value() { delete array[9]; return "funky"; }
34};
35for (var i = 0; i < 10; i++) array[i] = i;
36array[3] = funky;
37assertEquals('[0,1,2,{"value":"funky"},4,5,6,7,8,null]', JSON.stringify(array));
38
39array = [];
40funky = {
41  get value() { delete array[6]; return "funky"; }
42};
43for (var i = 0; i < 10; i++) array[i] = i;
44array[3] = funky;
45assertEquals('[0,1,2,{"value":"funky"},4,5,null,7,8,9]', JSON.stringify(array));
46
47array = [];
48funky = {
49  get value() { array[12] = 12; return "funky"; }
50};
51for (var i = 0; i < 10; i++) array[i] = i;
52array[3] = funky;
53assertEquals('[0,1,2,{"value":"funky"},4,5,6,7,8,9]', JSON.stringify(array));
54
55array = [];
56funky = {
57  get value() { array[10000000] = 12; return "funky"; }
58};
59for (var i = 0; i < 10; i++) array[i] = i;
60array[3] = funky;
61assertEquals('[0,1,2,{"value":"funky"},4,5,6,7,8,9]', JSON.stringify(array));
62