prototype-changes.js 1.04 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
// Copyright 2015 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

function A() {
  this.a = "a";
}
var a = new A();

function B() {
  this.b = "b";
}
B.prototype = a;

function C() {
  this.c = "c";
}
C.prototype = new B();

var c = new C();

function f(expected) {
  var result = c.z;
  assertEquals(expected, result);
27 28
};
%PrepareFunctionForOptimization(f);
29 30 31 32 33 34 35 36 37 38
f(undefined);
f(undefined);
%OptimizeFunctionOnNextCall(f);
f(undefined);
a.z = "z";
f("z");
f("z");

// Test updating .__proto__ pointers.
var p1 = {foo: 1.5};
39 40 41 42 43 44
var p2 = {};
p2.__proto__ = p1;
var p3 = {};
p3.__proto__ = p2;
var o = {};
o.__proto__ = p3;
45 46 47 48 49 50 51 52 53 54 55 56 57 58

for (var i = 0; i < 2; i++) o.foo;  // Force registration.

var p1a = {foo: 1.7};
p2.__proto__ = p1a;

function g(o, expected) {
  var result = o.foo;
  assertEquals(expected, result);
}

g(o, 1.7);
g(o, 1.7);
g(o, 1.7);
59 60 61 62 63
Object.defineProperty(p1a, 'foo', {
  get: function() {
    return 'foo';
  }
});
64
g(o, "foo");