Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Side by Side Diff: test/mjsunit/harmony/toMethod.js

Issue 914713002: Remove Function.prototype.toMethod (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Remove comment Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/mjsunit/harmony/super.js ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // Flags: --harmony-classes --allow-natives-syntax 5 // Flags: --harmony-classes --allow-natives-syntax
6 6
7 7
8 (function TestSingleClass() { 8 (function TestSingleClass() {
9 function f(x) { 9 function f(x) {
10 var a = [0, 1, 2] 10 var a = [0, 1, 2]
11 return a[x]; 11 return a[x];
12 } 12 }
13 13
14 function ClassD() { } 14 function ClassD() { }
15 15
16 assertEquals(1, f(1)); 16 assertEquals(1, f(1));
17 var g = f.toMethod(ClassD.prototype); 17 var g = %ToMethod(f, ClassD.prototype);
18 assertEquals(1, g(1)); 18 assertEquals(1, g(1));
19 assertEquals(undefined, f[%HomeObjectSymbol()]); 19 assertEquals(undefined, f[%HomeObjectSymbol()]);
20 assertEquals(ClassD.prototype, g[%HomeObjectSymbol()]); 20 assertEquals(ClassD.prototype, g[%HomeObjectSymbol()]);
21 }()); 21 }());
22 22
23 23
24 (function TestClassHierarchy() { 24 (function TestClassHierarchy() {
25 function f(x) { 25 function f(x) {
26 return function g(y) { x++; return x + y; }; 26 return function g(y) { x++; return x + y; };
27 } 27 }
28 28
29 function Base() {} 29 function Base() {}
30 function Derived() { } 30 function Derived() { }
31 Derived.prototype = Object.create(Base.prototype); 31 Derived.prototype = Object.create(Base.prototype);
32 32
33 var q = f(0); 33 var q = f(0);
34 assertEquals(2, q(1)); 34 assertEquals(2, q(1));
35 assertEquals(3, q(1)); 35 assertEquals(3, q(1));
36 var g = q.toMethod(Derived.prototype); 36 var g = %ToMethod(q, Derived.prototype);
37 assertFalse(g === q); 37 assertFalse(g === q);
38 assertEquals(4, g(1)); 38 assertEquals(4, g(1));
39 assertEquals(5, q(1)); 39 assertEquals(5, q(1));
40 }()); 40 }());
41 41
42 42
43 (function TestErrorCases() {
44 var sFun = Function.prototype.toMethod;
45 assertThrows(function() { sFun.call({}); }, TypeError);
46 assertThrows(function() { sFun.call({}, {}); }, TypeError);
47 function f(){};
48 assertThrows(function() { f.toMethod(1); }, TypeError);
49 }());
50
51
52 (function TestPrototypeChain() { 43 (function TestPrototypeChain() {
53 var o = {}; 44 var o = {};
54 var o1 = {}; 45 var o1 = {};
55 function f() { } 46 function f() { }
56 47
57 function g() { } 48 function g() { }
58 49
59 var fMeth = f.toMethod(o); 50 var fMeth = %ToMethod(f, o);
60 assertEquals(o, fMeth[%HomeObjectSymbol()]); 51 assertEquals(o, fMeth[%HomeObjectSymbol()]);
61 g.__proto__ = fMeth; 52 g.__proto__ = fMeth;
62 assertEquals(undefined, g[%HomeObjectSymbol()]); 53 assertEquals(undefined, g[%HomeObjectSymbol()]);
63 var gMeth = g.toMethod(o1); 54 var gMeth = %ToMethod(g, o1);
64 assertEquals(fMeth, gMeth.__proto__); 55 assertEquals(fMeth, gMeth.__proto__);
65 assertEquals(o, fMeth[%HomeObjectSymbol()]); 56 assertEquals(o, fMeth[%HomeObjectSymbol()]);
66 assertEquals(o1, gMeth[%HomeObjectSymbol()]); 57 assertEquals(o1, gMeth[%HomeObjectSymbol()]);
67 }()); 58 }());
68 59
69 60
70 (function TestBoundFunction() { 61 (function TestBoundFunction() {
71 var o = {}; 62 var o = {};
72 var p = {}; 63 var p = {};
73 64
74 65
75 function f(x, y, z, w) { 66 function f(x, y, z, w) {
76 assertEquals(o, this); 67 assertEquals(o, this);
77 assertEquals(1, x); 68 assertEquals(1, x);
78 assertEquals(2, y); 69 assertEquals(2, y);
79 assertEquals(3, z); 70 assertEquals(3, z);
80 assertEquals(4, w); 71 assertEquals(4, w);
81 return x+y+z+w; 72 return x+y+z+w;
82 } 73 }
83 74
84 var fBound = f.bind(o, 1, 2, 3); 75 var fBound = f.bind(o, 1, 2, 3);
85 var fMeth = fBound.toMethod(p); 76 var fMeth = %ToMethod(fBound, p);
86 assertEquals(10, fMeth(4)); 77 assertEquals(10, fMeth(4));
87 assertEquals(10, fMeth.call(p, 4)); 78 assertEquals(10, fMeth.call(p, 4));
88 var fBound1 = fBound.bind(o, 4); 79 var fBound1 = fBound.bind(o, 4);
89 assertEquals(10, fBound1()); 80 assertEquals(10, fBound1());
90 var fMethBound = fMeth.bind(o, 4); 81 var fMethBound = fMeth.bind(o, 4);
91 assertEquals(10, fMethBound()); 82 assertEquals(10, fMethBound());
92 }()); 83 }());
93 84
94 (function TestOptimized() { 85 (function TestOptimized() {
95 function f(o) { 86 function f(o) {
96 return o.x; 87 return o.x;
97 } 88 }
98 var o = {x : 15}; 89 var o = {x : 15};
99 assertEquals(15, f(o)); 90 assertEquals(15, f(o));
100 assertEquals(15, f(o)); 91 assertEquals(15, f(o));
101 %OptimizeFunctionOnNextCall(f); 92 %OptimizeFunctionOnNextCall(f);
102 assertEquals(15, f(o)); 93 assertEquals(15, f(o));
103 var g = f.toMethod({}); 94 var g = %ToMethod(f, {});
104 var o1 = {y : 1024, x : "abc"}; 95 var o1 = {y : 1024, x : "abc"};
105 assertEquals("abc", f(o1)); 96 assertEquals("abc", f(o1));
106 assertEquals("abc", g(o1)); 97 assertEquals("abc", g(o1));
107 } ()); 98 } ());
108 99
109 (function TestExtensibility() { 100 (function TestExtensibility() {
110 function f() {} 101 function f() {}
111 Object.preventExtensions(f); 102 Object.preventExtensions(f);
112 assertFalse(Object.isExtensible(f)); 103 assertFalse(Object.isExtensible(f));
113 var m = f.toMethod({}); 104 var m = %ToMethod(f, {});
114 assertTrue(Object.isExtensible(m)); 105 assertTrue(Object.isExtensible(m));
115 }()); 106 }());
OLDNEW
« no previous file with comments | « test/mjsunit/harmony/super.js ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698