OLD | NEW |
| (Empty) |
1 // Copyright 2014 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 | |
5 // Flags: --harmony-object-observe | |
6 // Flags: --allow-natives-syntax | |
7 | |
8 var v = 0; | |
9 | |
10 function push_wrapper(array, value) { | |
11 array.push(value); | |
12 } | |
13 function pop_wrapper(array) { | |
14 return array.pop(); | |
15 } | |
16 | |
17 // Test that Object.observe() notification events are properly sent from | |
18 // Array.push() and Array.pop() both from optimized and un-optimized code. | |
19 var array = []; | |
20 | |
21 function somethingChanged(changes) { | |
22 v++; | |
23 } | |
24 | |
25 Object.observe(array, somethingChanged); | |
26 push_wrapper(array, 1); | |
27 %RunMicrotasks(); | |
28 assertEquals(1, array.length); | |
29 assertEquals(1, v); | |
30 push_wrapper(array, 1); | |
31 %RunMicrotasks(); | |
32 assertEquals(2, array.length); | |
33 assertEquals(2, v); | |
34 %OptimizeFunctionOnNextCall(push_wrapper); | |
35 push_wrapper(array, 1); | |
36 %RunMicrotasks(); | |
37 assertEquals(3, array.length); | |
38 assertEquals(3, v); | |
39 push_wrapper(array, 1); | |
40 %RunMicrotasks(); | |
41 assertEquals(4, array.length); | |
42 assertEquals(4, v); | |
43 | |
44 pop_wrapper(array); | |
45 %RunMicrotasks(); | |
46 assertEquals(3, array.length); | |
47 assertEquals(5, v); | |
48 pop_wrapper(array); | |
49 %RunMicrotasks(); | |
50 assertEquals(2, array.length); | |
51 assertEquals(6, v); | |
52 %OptimizeFunctionOnNextCall(pop_wrapper); | |
53 pop_wrapper(array); | |
54 %RunMicrotasks(); | |
55 assertEquals(1, array.length); | |
56 assertEquals(7, v); | |
57 pop_wrapper(array); | |
58 %RunMicrotasks(); | |
59 assertEquals(0, array.length); | |
60 assertEquals(8, v); | |
OLD | NEW |