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 7var v = 0; 8 9// Test that elements setters/getters on prototype chain set after the fact are 10// property detected and don't lead to overzealous optimization. 11var my_array_proto = {}; 12my_array_proto.__proto__ = [].__proto__; 13 14function push_wrapper_2(array, value) { 15 array.push(value); 16} 17array = []; 18array.__proto__ = my_array_proto; 19push_wrapper_2(array, 66); 20assertEquals(1, array.length); 21assertEquals(0, v); 22assertEquals(66, array[0]); 23push_wrapper_2(array, 77); 24assertEquals(2, array.length); 25assertEquals(0, v); 26assertEquals(77, array[1]); 27%OptimizeFunctionOnNextCall(push_wrapper_2); 28push_wrapper_2(array, 88); 29assertEquals(3, array.length); 30assertEquals(0, v); 31assertEquals(88, array[2]); 32assertOptimized(push_wrapper_2); 33// Defining accessor should deopt optimized push. 34Object.defineProperty(my_array_proto, "3", { 35get: function() { return "get " + v; }, 36set: function(value) { v += value; } 37}); 38assertUnoptimized(push_wrapper_2); 39push_wrapper_2(array, 99); 40assertEquals(4, array.length); 41assertEquals(99, v); 42assertEquals("get 99", array[3]); 43