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

Side by Side Diff: sdk/lib/_internal/compiler/js_lib/js_helper.dart

Issue 895083002: Support tearoffs in the new emitter. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Comments 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 | Annotate | Revision Log
« no previous file with comments | « pkg/compiler/lib/src/js_emitter/old_emitter/reflection_data_parser.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 library _js_helper; 5 library _js_helper;
6 6
7 import 'dart:_js_embedded_names' show 7 import 'dart:_js_embedded_names' show
8 GET_TYPE_FROM_NAME, 8 GET_TYPE_FROM_NAME,
9 GET_ISOLATE_TAG, 9 GET_ISOLATE_TAG,
10 INTERCEPTED_NAMES, 10 INTERCEPTED_NAMES,
(...skipping 1938 matching lines...) Expand 10 before | Expand all | Expand 10 after
1949 * 1949 *
1950 * Called from [closureFromTearOff] as well as from reflection when tearing 1950 * Called from [closureFromTearOff] as well as from reflection when tearing
1951 * of a method via [:getField:]. 1951 * of a method via [:getField:].
1952 * 1952 *
1953 * This method assumes that [functions] was created by the JavaScript function 1953 * This method assumes that [functions] was created by the JavaScript function
1954 * `addStubs` in `reflection_data_parser.dart`. That is, a list of JavaScript 1954 * `addStubs` in `reflection_data_parser.dart`. That is, a list of JavaScript
1955 * function objects with properties `$stubName` and `$callName`. 1955 * function objects with properties `$stubName` and `$callName`.
1956 * 1956 *
1957 * Further assumes that [reflectionInfo] is the end of the array created by 1957 * Further assumes that [reflectionInfo] is the end of the array created by
1958 * [dart2js.js_emitter.ContainerBuilder.addMemberMethod] starting with 1958 * [dart2js.js_emitter.ContainerBuilder.addMemberMethod] starting with
1959 * required parameter count. 1959 * required parameter count or, in case of the new emitter, the runtime
1960 * representation of the function's type.
1960 * 1961 *
1961 * Caution: this function may be called when building constants. 1962 * Caution: this function may be called when building constants.
1962 * TODO(ahe): Don't call this function when building constants. 1963 * TODO(ahe): Don't call this function when building constants.
1963 */ 1964 */
1964 static fromTearOff(receiver, 1965 static fromTearOff(receiver,
1965 List functions, 1966 List functions,
1966 List reflectionInfo, 1967 var reflectionInfo,
1967 bool isStatic, 1968 bool isStatic,
1968 jsArguments, 1969 jsArguments,
1969 String propertyName) { 1970 String propertyName) {
1970 JS_EFFECT(() { 1971 JS_EFFECT(() {
1971 BoundClosure.receiverOf(JS('BoundClosure', 'void 0')); 1972 BoundClosure.receiverOf(JS('BoundClosure', 'void 0'));
1972 BoundClosure.selfOf(JS('BoundClosure', 'void 0')); 1973 BoundClosure.selfOf(JS('BoundClosure', 'void 0'));
1973 }); 1974 });
1974 // TODO(ahe): All the place below using \$ should be rewritten to go 1975 // TODO(ahe): All the place below using \$ should be rewritten to go
1975 // through the namer. 1976 // through the namer.
1976 var function = JS('', '#[#]', functions, 0); 1977 var function = JS('', '#[#]', functions, 0);
1977 String name = JS('String|Null', '#.\$stubName', function); 1978 String name = JS('String|Null', '#.\$stubName', function);
1978 String callName = JS('String|Null', '#.\$callName', function); 1979 String callName = JS('String|Null', '#.\$callName', function);
1979 1980
1980 JS('', '#.\$reflectionInfo = #', function, reflectionInfo); 1981 var functionType;
1981 ReflectionInfo info = new ReflectionInfo(function); 1982 if (reflectionInfo is List) {
1983 JS('', '#.\$reflectionInfo = #', function, reflectionInfo);
1984 ReflectionInfo info = new ReflectionInfo(function);
1985 functionType = info.functionType;
1986 } else {
1987 functionType = reflectionInfo;
1988 }
1982 1989
1983 var functionType = info.functionType;
1984 1990
1985 // function tmp() {}; 1991 // function tmp() {};
1986 // tmp.prototype = BC.prototype; 1992 // tmp.prototype = BC.prototype;
1987 // var proto = new tmp; 1993 // var proto = new tmp;
1988 // for each computed prototype property: 1994 // for each computed prototype property:
1989 // proto[property] = ...; 1995 // proto[property] = ...;
1990 // proto._init = BC; 1996 // proto._init = BC;
1991 // var dynClosureConstructor = 1997 // var dynClosureConstructor =
1992 // new Function('self', 'target', 'receiver', 'name', 1998 // new Function('self', 'target', 'receiver', 'name',
1993 // 'this._init(self, target, receiver, name)'); 1999 // 'this._init(self, target, receiver, name)');
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
2315 /// Called from implicit method getter (aka tear-off). 2321 /// Called from implicit method getter (aka tear-off).
2316 closureFromTearOff(receiver, 2322 closureFromTearOff(receiver,
2317 functions, 2323 functions,
2318 reflectionInfo, 2324 reflectionInfo,
2319 isStatic, 2325 isStatic,
2320 jsArguments, 2326 jsArguments,
2321 name) { 2327 name) {
2322 return Closure.fromTearOff( 2328 return Closure.fromTearOff(
2323 receiver, 2329 receiver,
2324 JSArray.markFixedList(functions), 2330 JSArray.markFixedList(functions),
2325 JSArray.markFixedList(reflectionInfo), 2331 reflectionInfo is List ? JSArray.markFixedList(reflectionInfo)
2332 : reflectionInfo,
2326 JS('bool', '!!#', isStatic), 2333 JS('bool', '!!#', isStatic),
2327 jsArguments, 2334 jsArguments,
2328 JS('String', '#', name)); 2335 JS('String', '#', name));
2329 } 2336 }
2330 2337
2331 /// Represents an implicit closure of a function. 2338 /// Represents an implicit closure of a function.
2332 class TearOffClosure extends Closure { 2339 class TearOffClosure extends Closure {
2333 } 2340 }
2334 2341
2335 /// Represents a 'tear-off' closure, that is an instance method bound 2342 /// Represents a 'tear-off' closure, that is an instance method bound
(...skipping 1112 matching lines...) Expand 10 before | Expand all | Expand 10 after
3448 throw new MainError("No top-level function named 'main'."); 3455 throw new MainError("No top-level function named 'main'.");
3449 } 3456 }
3450 3457
3451 void badMain() { 3458 void badMain() {
3452 throw new MainError("'main' is not a function."); 3459 throw new MainError("'main' is not a function.");
3453 } 3460 }
3454 3461
3455 void mainHasTooManyParameters() { 3462 void mainHasTooManyParameters() {
3456 throw new MainError("'main' expects too many parameters."); 3463 throw new MainError("'main' expects too many parameters.");
3457 } 3464 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_emitter/old_emitter/reflection_data_parser.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698