array-push7.js 1.36 KB
Newer Older
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
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Flags: --allow-natives-syntax

var v = 0;

function push_wrapper(array, value) {
  array.push(value);
}
function pop_wrapper(array) {
  return array.pop();
}

// Test that Object.observe() notification events are properly sent from
// Array.push() and Array.pop() both from optimized and un-optimized code.
var array = [];

function somethingChanged(changes) {
  v++;
}

Object.observe(array, somethingChanged);
push_wrapper(array, 1);
%RunMicrotasks();
assertEquals(1, array.length);
assertEquals(1, v);
push_wrapper(array, 1);
%RunMicrotasks();
assertEquals(2, array.length);
assertEquals(2, v);
%OptimizeFunctionOnNextCall(push_wrapper);
push_wrapper(array, 1);
%RunMicrotasks();
assertEquals(3, array.length);
assertEquals(3, v);
push_wrapper(array, 1);
%RunMicrotasks();
assertEquals(4, array.length);
assertEquals(4, v);

pop_wrapper(array);
%RunMicrotasks();
assertEquals(3, array.length);
assertEquals(5, v);
pop_wrapper(array);
%RunMicrotasks();
assertEquals(2, array.length);
assertEquals(6, v);
%OptimizeFunctionOnNextCall(pop_wrapper);
pop_wrapper(array);
%RunMicrotasks();
assertEquals(1, array.length);
assertEquals(7, v);
pop_wrapper(array);
%RunMicrotasks();
assertEquals(0, array.length);
assertEquals(8, v);