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