summaryrefslogtreecommitdiff
path: root/deps/v8/test/mjsunit/prototype-changes.js
blob: e7fcc7ee953238aa71f2cce6cdaf2b4f72f589c6 (plain)
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
// 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);
}
f(undefined);
f(undefined);
%OptimizeFunctionOnNextCall(f);
f(undefined);
a.z = "z";
f("z");
f("z");

// Test updating .__proto__ pointers.
var p1 = {foo: 1.5};
var p2 = {}; p2.__proto__ = p1;
var p3 = {}; p3.__proto__ = p2;
var o = {}; o.__proto__ = p3;

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);
Object.defineProperty(p1a, "foo", {get: function() { return "foo"}});
g(o, "foo");