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.
5 // Flags: --harmony-classes --allow-natives-syntax
8 (function TestSingleClass() {
16 assertEquals(1, f(1));
17 var g = f.toMethod(ClassD.prototype);
18 assertEquals(1, g(1));
19 assertEquals(undefined, f[%HomeObjectSymbol()]);
20 assertEquals(ClassD.prototype, g[%HomeObjectSymbol()]);
24 (function TestClassHierarchy() {
26 return function g(y) { x++; return x + y; };
30 function Derived() { }
31 Derived.prototype = Object.create(Base.prototype);
34 assertEquals(2, q(1));
35 assertEquals(3, q(1));
36 var g = q.toMethod(Derived.prototype);
38 assertEquals(4, g(1));
39 assertEquals(5, q(1));
43 (function TestErrorCases() {
44 var sFun = Function.prototype.toMethod;
45 assertThrows(function() { sFun.call({}); }, TypeError);
46 assertThrows(function() { sFun.call({}, {}); }, TypeError);
48 assertThrows(function() { f.toMethod(1); }, TypeError);
52 (function TestPrototypeChain() {
59 var fMeth = f.toMethod(o);
60 assertEquals(o, fMeth[%HomeObjectSymbol()]);
62 assertEquals(undefined, g[%HomeObjectSymbol()]);
63 var gMeth = g.toMethod(o1);
64 assertEquals(fMeth, gMeth.__proto__);
65 assertEquals(o, fMeth[%HomeObjectSymbol()]);
66 assertEquals(o1, gMeth[%HomeObjectSymbol()]);
70 (function TestBoundFunction() {
75 function f(x, y, z, w) {
76 assertEquals(o, this);
84 var fBound = f.bind(o, 1, 2, 3);
85 var fMeth = fBound.toMethod(p);
86 assertEquals(10, fMeth(4));
87 assertEquals(10, fMeth.call(p, 4));
88 var fBound1 = fBound.bind(o, 4);
89 assertEquals(10, fBound1());
90 var fMethBound = fMeth.bind(o, 4);
91 assertEquals(10, fMethBound());
94 (function TestOptimized() {
99 assertEquals(15, f(o));
100 assertEquals(15, f(o));
101 %OptimizeFunctionOnNextCall(f);
102 assertEquals(15, f(o));
103 var g = f.toMethod({});
104 var o1 = {y : 1024, x : "abc"};
105 assertEquals("abc", f(o1));
106 assertEquals("abc", g(o1));
109 (function TestExtensibility() {
111 Object.preventExtensions(f);
112 assertFalse(Object.isExtensible(f));
113 var m = f.toMethod({});
114 assertTrue(Object.isExtensible(m));