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

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

Issue 475423003: Implement Function.prototype.toMethod. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Name for the last test Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 //
28 // Flags: --harmony-classes --allow-natives-syntax
29
30
31 (function ToMethodSingleClass() {
32 function f(x) {
33 var a = [0, 1, 2]
34 return a[x];
35 }
36
37 function ClassD() { }
38
39 assertEquals(1, f(1));
40 var g = f.toMethod(ClassD.prototype);
41 assertEquals(1, g(1));
42 assertEquals(undefined, f[%HomeObjectSymbol()]);
43 assertEquals(ClassD.prototype, g[%HomeObjectSymbol()]);
44 }());
45
46
47 (function ToMethodClassHierarchy() {
48 function f(x) {
49 return function g(y) { x++; return x + y; };
50 }
51
52 function Base() {}
53 function Derived() { }
54 Derived.prototype = Object.create(Base.prototype);
55
56 var q = f(0);
57 assertEquals(2, q(1));
58 assertEquals(3, q(1));
59 var g = q.toMethod(Derived.prototype);
60 assertFalse(g === q);
61 assertEquals(4, g(1));
62 assertEquals(5, q(1));
63 }());
64
65
66 (function ToMethodErrorCases() {
67 var sFun = Function.prototype.toMethod;
68 assertThrows(function() { sFun.call({}); }, TypeError);
69 assertThrows(function() { sFun.call({}, {}); }, TypeError);
70 function f(){};
71 assertThrows(function() { f.toMethod(1); }, TypeError);
72 }());
73
74
75 (function ToMethodPrototypeChain() {
76 var o = {};
77 var o1 = {};
78 function f() { }
79
80 function g() { }
81
82 var fMeth = f.toMethod(o);
83 assertEquals(o, fMeth[%HomeObjectSymbol()]);
84 g.__proto__ = fMeth;
85 assertEquals(undefined, g[%HomeObjectSymbol()]);
86 var gMeth = g.toMethod(o1);
87 assertEquals(fMeth, gMeth.__proto__);
88 assertEquals(o1, gMeth[%HomeObjectSymbol()]);
89 }());
90
91
92 (function ToMethodBoundFunction() {
93 var o = {};
94 var p = {};
95
96
97 function f(x, y, z) {
Toon Verwaest 2014/08/18 14:15:35 Add flag "called = false" on the outside, and set
Dmitry Lomov (no reviews) 2014/08/19 20:02:48 Checking return value instead.
98 assertEquals(o, this);
99 assertEquals(1, x);
100 assertEquals(2, y);
101 assertEquals(3, z);
102 }
103
104 var fBound = f.bind(o, 1, 2, 3);
105 var fMeth = fBound.toMethod(p);
106 fMeth();
107 fMeth.call(p);
108 }());
Toon Verwaest 2014/08/18 14:15:35 What about tests for rebinding a method, given tha
Dmitry Lomov (no reviews) 2014/08/19 20:02:48 Done.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698