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

Side by Side Diff: compiler/lib/implementation/core.js

Issue 8845002: Function type checking: Part Deux (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Nits checked Created 9 years 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
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /** 5 /**
6 * Helpers for lazy static initialization. 6 * Helpers for lazy static initialization.
7 */ 7 */
8 var static$uninitialized = {}; 8 var static$uninitialized = {};
9 var static$initializing = {}; 9 var static$initializing = {};
10 10
11 // Optimized versions of closure bindings. 11 function $maybeBindRtt(fun, fRtt, thisObj) {
12 // Name convention: $bind<number-of-scopes>_<number-of-arguments>(fn, this, scop es, args) 12 if (fRtt) {
13 function $bind0_0(fn, thisObj) { 13 fun.$lookupRTT = function() {
14 return function() { 14 return fRtt.call(thisObj);
15 return fn.call(thisObj); 15 }
16 }
17 }
18 function $bind0_1(fn, thisObj) {
19 return function(arg) {
20 return fn.call(thisObj, arg);
21 }
22 }
23 function $bind0_2(fn, thisObj) {
24 return function(arg1, arg2) {
25 return fn.call(thisObj, arg1, arg2);
26 }
27 }
28 function $bind0_3(fn, thisObj) {
29 return function(arg1, arg2, arg3) {
30 return fn.call(thisObj, arg1, arg2, arg3);
31 }
32 }
33 function $bind0_4(fn, thisObj) {
34 return function(arg1, arg2, arg3, arg4) {
35 return fn.call(thisObj, arg1, arg2, arg3, arg4);
36 }
37 }
38 function $bind0_5(fn, thisObj) {
39 return function(arg1, arg2, arg3, arg4, arg5) {
40 return fn.call(thisObj, arg1, arg2, arg3, arg4, arg5);
41 } 16 }
42 } 17 }
43 18
44 function $bind1_0(fn, thisObj, scope) { 19 // Optimized versions of closure bindings.
45 return function() { 20 // Name convention: $bind<number-of-scopes>_<number-of-arguments>(fn, this, scop es, args)
21 function $bind0_0(fn, fRtt, thisObj) {
22 var fun = function() {
23 return fn.call(thisObj);
24 }
25 $maybeBindRtt(fun, fRtt, thisObj);
26 return fun;
27 }
28 function $bind0_1(fn, fRtt, thisObj) {
29 var fun = function(arg) {
30 return fn.call(thisObj, arg);
31 }
32 $maybeBindRtt(fun, fRtt, thisObj);
33 return fun;
34 }
35 function $bind0_2(fn, fRtt, thisObj) {
36 var fun = function(arg1, arg2) {
37 return fn.call(thisObj, arg1, arg2);
38 }
39 $maybeBindRtt(fun, fRtt, thisObj);
40 return fun;
41 }
42 function $bind0_3(fn, fRtt, thisObj) {
43 var fun = function(arg1, arg2, arg3) {
44 return fn.call(thisObj, arg1, arg2, arg3);
45 }
46 $maybeBindRtt(fun, fRtt, thisObj);
47 return fun;
48 }
49 function $bind0_4(fn, fRtt, thisObj) {
50 var fun = function(arg1, arg2, arg3, arg4) {
51 return fn.call(thisObj, arg1, arg2, arg3, arg4);
52 }
53 $maybeBindRtt(fun, fRtt, thisObj);
54 return fun;
55 }
56 function $bind0_5(fn, fRtt, thisObj) {
57 var fun = function(arg1, arg2, arg3, arg4, arg5) {
58 return fn.call(thisObj, arg1, arg2, arg3, arg4, arg5);
59 }
60 $maybeBindRtt(fun, fRtt, thisObj);
61 return fun;
62 }
63
64 function $bind1_0(fn, fRtt, thisObj, scope) {
65 var fun = function() {
46 return fn.call(thisObj, scope); 66 return fn.call(thisObj, scope);
47 } 67 }
68 $maybeBindRtt(fun, fRtt, thisObj);
69 return fun;
48 } 70 }
49 function $bind1_1(fn, thisObj, scope) { 71 function $bind1_1(fn, fRtt, thisObj, scope) {
50 return function(arg) { 72 var fun = function(arg) {
51 return fn.call(thisObj, scope, arg); 73 return fn.call(thisObj, scope, arg);
52 } 74 }
75 $maybeBindRtt(fun, fRtt, thisObj);
76 return fun;
53 } 77 }
54 function $bind1_2(fn, thisObj, scope) { 78 function $bind1_2(fn, fRtt, thisObj, scope) {
55 return function(arg1, arg2) { 79 var fun = function(arg1, arg2) {
56 return fn.call(thisObj, scope, arg1, arg2); 80 return fn.call(thisObj, scope, arg1, arg2);
57 } 81 }
82 $maybeBindRtt(fun, fRtt, thisObj);
83 return fun;
58 } 84 }
59 function $bind1_3(fn, thisObj, scope) { 85 function $bind1_3(fn, fRtt, thisObj, scope) {
60 return function(arg1, arg2, arg3) { 86 var fun = function(arg1, arg2, arg3) {
61 return fn.call(thisObj, scope, arg1, arg2, arg3); 87 return fn.call(thisObj, scope, arg1, arg2, arg3);
62 } 88 }
89 $maybeBindRtt(fun, fRtt, thisObj);
90 return fun;
63 } 91 }
64 function $bind1_4(fn, thisObj, scope) { 92 function $bind1_4(fn, fRtt, thisObj, scope) {
65 return function(arg1, arg2, arg3, arg4) { 93 var fun = function(arg1, arg2, arg3, arg4) {
66 return fn.call(thisObj, scope, arg1, arg2, arg3, arg4); 94 return fn.call(thisObj, scope, arg1, arg2, arg3, arg4);
67 } 95 }
96 $maybeBindRtt(fun, fRtt, thisObj);
97 return fun;
68 } 98 }
69 function $bind1_5(fn, thisObj, scope) { 99 function $bind1_5(fn, fRtt, thisObj, scope) {
70 return function(arg1, arg2, arg3, arg4, arg5) { 100 var fun = function(arg1, arg2, arg3, arg4, arg5) {
71 return fn.call(thisObj, scope, arg1, arg2, arg3, arg4, arg5); 101 return fn.call(thisObj, scope, arg1, arg2, arg3, arg4, arg5);
72 } 102 }
103 $maybeBindRtt(fun, fRtt, thisObj);
104 return fun;
73 } 105 }
74 106
75 function $bind2_0(fn, thisObj, scope1, scope2) { 107 function $bind2_0(fn, fRtt, thisObj, scope1, scope2) {
76 return function() { 108 var fun = function() {
77 return fn.call(thisObj, scope1, scope2); 109 return fn.call(thisObj, scope1, scope2);
78 } 110 }
111 $maybeBindRtt(fun, fRtt, thisObj);
112 return fun;
79 } 113 }
80 function $bind2_1(fn, thisObj, scope1, scope2) { 114 function $bind2_1(fn, fRtt, thisObj, scope1, scope2) {
81 return function(arg) { 115 var fun = function(arg) {
82 return fn.call(thisObj, scope1, scope2, arg); 116 return fn.call(thisObj, scope1, scope2, arg);
83 } 117 }
118 $maybeBindRtt(fun, fRtt, thisObj);
119 return fun;
84 } 120 }
85 function $bind2_2(fn, thisObj, scope1, scope2) { 121 function $bind2_2(fn, fRtt, thisObj, scope1, scope2) {
86 return function(arg1, arg2) { 122 var fun = function(arg1, arg2) {
87 return fn.call(thisObj, scope1, scope2, arg1, arg2); 123 return fn.call(thisObj, scope1, scope2, arg1, arg2);
88 } 124 }
125 $maybeBindRtt(fun, fRtt, thisObj);
126 return fun;
89 } 127 }
90 function $bind2_3(fn, thisObj, scope1, scope2) { 128 function $bind2_3(fn, fRtt, thisObj, scope1, scope2) {
91 return function(arg1, arg2, arg3) { 129 var fun = function(arg1, arg2, arg3) {
92 return fn.call(thisObj, scope1, scope2, arg1, arg2, arg3); 130 return fn.call(thisObj, scope1, scope2, arg1, arg2, arg3);
93 } 131 }
132 $maybeBindRtt(fun, fRtt, thisObj);
133 return fun;
94 } 134 }
95 function $bind2_4(fn, thisObj, scope1, scope2) { 135 function $bind2_4(fn, fRtt, thisObj, scope1, scope2) {
96 return function(arg1, arg2, arg3, arg4) { 136 var fun = function(arg1, arg2, arg3, arg4) {
97 return fn.call(thisObj, scope1, scope2, arg1, arg2, arg3, arg4); 137 return fn.call(thisObj, scope1, scope2, arg1, arg2, arg3, arg4);
98 } 138 }
139 $maybeBindRtt(fun, fRtt, thisObj);
140 return fun;
99 } 141 }
100 function $bind2_5(fn, thisObj, scope1, scope2) { 142 function $bind2_5(fn, fRtt, thisObj, scope1, scope2) {
101 return function(arg1, arg2, arg3, arg4, arg5) { 143 var fun = function(arg1, arg2, arg3, arg4, arg5) {
102 return fn.call(thisObj, scope1, scope2, arg1, arg2, arg3, arg4, arg5); 144 return fn.call(thisObj, scope1, scope2, arg1, arg2, arg3, arg4, arg5);
103 } 145 }
146 $maybeBindRtt(fun, fRtt, thisObj);
147 return fun;
104 } 148 }
105 149
106 function $bind3_0(fn, thisObj, scope1, scope2, scope3) { 150 function $bind3_0(fn, fRtt, thisObj, scope1, scope2, scope3) {
107 return function() { 151 var fun = function() {
108 return fn.call(thisObj, scope1, scope2, scope3); 152 return fn.call(thisObj, scope1, scope2, scope3);
109 } 153 }
154 $maybeBindRtt(fun, fRtt, thisObj);
155 return fun;
110 } 156 }
111 function $bind3_1(fn, thisObj, scope1, scope2, scope3) { 157 function $bind3_1(fn, fRtt, thisObj, scope1, scope2, scope3) {
112 return function(arg) { 158 var fun = function(arg) {
113 return fn.call(thisObj, scope1, scope2, scope3, arg); 159 return fn.call(thisObj, scope1, scope2, scope3, arg);
114 } 160 }
161 $maybeBindRtt(fun, fRtt, thisObj);
162 return fun;
115 } 163 }
116 function $bind3_2(fn, thisObj, scope1, scope2, scope3) { 164 function $bind3_2(fn, fRtt, thisObj, scope1, scope2, scope3) {
117 return function(arg1, arg2) { 165 var fun = function(arg1, arg2) {
118 return fn.call(thisObj, scope1, scope2, scope3, arg1, arg2); 166 return fn.call(thisObj, scope1, scope2, scope3, arg1, arg2);
119 } 167 }
168 $maybeBindRtt(fun, fRtt, thisObj);
169 return fun;
120 } 170 }
121 function $bind3_3(fn, thisObj, scope1, scope2, scope3) { 171 function $bind3_3(fn, fRtt, thisObj, scope1, scope2, scope3) {
122 return function(arg1, arg2, arg3) { 172 var fun = function(arg1, arg2, arg3) {
123 return fn.call(thisObj, scope1, scope2, scope3, arg1, arg2, arg3); 173 return fn.call(thisObj, scope1, scope2, scope3, arg1, arg2, arg3);
124 } 174 }
175 $maybeBindRtt(fun, fRtt, thisObj);
176 return fun;
125 } 177 }
126 function $bind3_4(fn, thisObj, scope1, scope2, scope3) { 178 function $bind3_4(fn, fRtt, thisObj, scope1, scope2, scope3) {
127 return function(arg1, arg2, arg3, arg4) { 179 var fun = function(arg1, arg2, arg3, arg4) {
128 return fn.call(thisObj, scope1, scope2, scope3, arg1, arg2, arg3, arg4); 180 return fn.call(thisObj, scope1, scope2, scope3, arg1, arg2, arg3, arg4);
129 } 181 }
182 $maybeBindRtt(fun, fRtt, thisObj);
183 return fun;
130 } 184 }
131 function $bind3_5(fn, thisObj, scope1, scope2, scope3) { 185 function $bind3_5(fn, fRtt, thisObj, scope1, scope2, scope3) {
132 return function(arg1, arg2, arg3, arg4, arg5) { 186 var fun = function(arg1, arg2, arg3, arg4, arg5) {
133 return fn.call(thisObj, scope1, scope2, scope3, arg1, arg2, arg3, arg4, arg5 ); 187 return fn.call(thisObj, scope1, scope2, scope3, arg1, arg2, arg3, arg4, arg5 );
134 } 188 }
189 $maybeBindRtt(fun, fRtt, thisObj);
190 return fun;
135 } 191 }
136 192
137 /** 193 /**
138 * Implements extends for dart classes on javascript prototypes. 194 * Implements extends for dart classes on javascript prototypes.
139 * @param {Function} child 195 * @param {Function} child
140 * @param {Function} parent 196 * @param {Function} parent
141 */ 197 */
142 function $inherits(child, parent) { 198 function $inherits(child, parent) {
143 if (child.prototype.__proto__) { 199 if (child.prototype.__proto__) {
144 child.prototype.__proto__ = parent.prototype; 200 child.prototype.__proto__ = parent.prototype;
145 } else { 201 } else {
146 function tmp() {}; 202 function tmp() {};
147 tmp.prototype = parent.prototype; 203 tmp.prototype = parent.prototype;
148 child.prototype = new tmp(); 204 child.prototype = new tmp();
149 child.prototype.constructor = child; 205 child.prototype.constructor = child;
150 } 206 }
151 } 207 }
152 208
153 /** 209 /**
154 * @param {Function} fn 210 * @param {Function} fn
211 * @param {Function=} fRtt
155 * @param {Object|undefined} thisObj 212 * @param {Object|undefined} thisObj
156 * @param {...*} var_args 213 * @param {...*} var_args
157 */ 214 */
158 function $bind(fn, thisObj, var_args) { 215 function $bind(fn, fRtt, thisObj, var_args) {
159 if (arguments.length > 2) { 216 var func;
160 var boundArgs = Array.prototype.slice.call(arguments, 2); 217 if (arguments.length > 3) {
161 return function() { 218 var boundArgs = Array.prototype.slice.call(arguments, 3);
219 func = function() {
162 // Prepend the bound arguments to the current arguments. 220 // Prepend the bound arguments to the current arguments.
163 var newArgs = Array.prototype.slice.call(arguments); 221 var newArgs = Array.prototype.slice.call(arguments);
164 Array.prototype.unshift.apply(newArgs, boundArgs); 222 Array.prototype.unshift.apply(newArgs, boundArgs);
165 return fn.apply(thisObj, newArgs); 223 return fn.apply(thisObj, newArgs);
166 }; 224 };
167 } else { 225 } else {
168 return function() { 226 func = function() {
169 return fn.apply(thisObj, arguments); 227 return fn.apply(thisObj, arguments);
170 }; 228 };
171 } 229 }
230 if(fRtt) {
231 func.$lookupRTT = function() {
232 return fRtt.apply(thisObj, arguments);
233 };
234 }
235 return func;
172 } 236 }
173 237
174 /** 238 /**
175 * Dart null object that should be used by JS implementation to test for 239 * Dart null object that should be used by JS implementation to test for
176 * Dart null. 240 * Dart null.
177 * 241 *
178 * TODO(ngeoffray): update dartc to generate this variable instead of 242 * TODO(ngeoffray): update dartc to generate this variable instead of
179 * undefined. 243 * undefined.
180 * @const 244 * @const
181 */ 245 */
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 return match; 527 return match;
464 } 528 }
465 o.$dartConstId = id; 529 o.$dartConstId = id;
466 $consts[key] = o; 530 $consts[key] = o;
467 return o; 531 return o;
468 } 532 }
469 533
470 function $Dart$MapLiteralFactory() { 534 function $Dart$MapLiteralFactory() {
471 return native__CoreJsUtil__newMapLiteral(); 535 return native__CoreJsUtil__newMapLiteral();
472 } 536 }
OLDNEW
« no previous file with comments | « compiler/javatests/com/google/dart/compiler/common/GenerateSourceMapTest.java ('k') | compiler/lib/implementation/rtt.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698