Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 1946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1957 * | 1957 * |
| 1958 * Further assumes that [reflectionInfo] is the end of the array created by | 1958 * Further assumes that [reflectionInfo] is the end of the array created by |
| 1959 * [dart2js.js_emitter.ContainerBuilder.addMemberMethod] starting with | 1959 * [dart2js.js_emitter.ContainerBuilder.addMemberMethod] starting with |
| 1960 * required parameter count. | 1960 * required parameter count. |
| 1961 * | 1961 * |
| 1962 * Caution: this function may be called when building constants. | 1962 * Caution: this function may be called when building constants. |
| 1963 * TODO(ahe): Don't call this function when building constants. | 1963 * TODO(ahe): Don't call this function when building constants. |
| 1964 */ | 1964 */ |
| 1965 static fromTearOff(receiver, | 1965 static fromTearOff(receiver, |
| 1966 List functions, | 1966 List functions, |
| 1967 List reflectionInfo, | 1967 var reflectionInfo, |
| 1968 bool isStatic, | 1968 bool isStatic, |
| 1969 jsArguments, | 1969 jsArguments, |
| 1970 String propertyName) { | 1970 String propertyName) { |
| 1971 JS_EFFECT(() { | 1971 JS_EFFECT(() { |
| 1972 BoundClosure.receiverOf(JS('BoundClosure', 'void 0')); | 1972 BoundClosure.receiverOf(JS('BoundClosure', 'void 0')); |
| 1973 BoundClosure.selfOf(JS('BoundClosure', 'void 0')); | 1973 BoundClosure.selfOf(JS('BoundClosure', 'void 0')); |
| 1974 }); | 1974 }); |
| 1975 // 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 |
| 1976 // through the namer. | 1976 // through the namer. |
| 1977 var function = JS('', '#[#]', functions, 0); | 1977 var function = JS('', '#[#]', functions, 0); |
| 1978 String name = JS('String|Null', '#.\$stubName', function); | 1978 String name = JS('String|Null', '#.\$stubName', function); |
| 1979 String callName = JS('String|Null', '#.\$callName', function); | 1979 String callName = JS('String|Null', '#.\$callName', function); |
| 1980 | 1980 |
| 1981 JS('', '#.\$reflectionInfo = #', function, reflectionInfo); | 1981 var functionType; |
| 1982 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 } | |
| 1983 | 1989 |
| 1984 var functionType = info.functionType; | |
| 1985 | 1990 |
| 1986 // function tmp() {}; | 1991 // function tmp() {}; |
| 1987 // tmp.prototype = BC.prototype; | 1992 // tmp.prototype = BC.prototype; |
| 1988 // var proto = new tmp; | 1993 // var proto = new tmp; |
| 1989 // for each computed prototype property: | 1994 // for each computed prototype property: |
| 1990 // proto[property] = ...; | 1995 // proto[property] = ...; |
| 1991 // proto._init = BC; | 1996 // proto._init = BC; |
| 1992 // var dynClosureConstructor = | 1997 // var dynClosureConstructor = |
| 1993 // new Function('self', 'target', 'receiver', 'name', | 1998 // new Function('self', 'target', 'receiver', 'name', |
| 1994 // 'this._init(self, target, receiver, name)'); | 1999 // 'this._init(self, target, receiver, name)'); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2057 var getReceiver = isIntercepted | 2062 var getReceiver = isIntercepted |
| 2058 ? RAW_DART_FUNCTION_REF(BoundClosure.receiverOf) | 2063 ? RAW_DART_FUNCTION_REF(BoundClosure.receiverOf) |
| 2059 : RAW_DART_FUNCTION_REF(BoundClosure.selfOf); | 2064 : RAW_DART_FUNCTION_REF(BoundClosure.selfOf); |
| 2060 signatureFunction = JS( | 2065 signatureFunction = JS( |
| 2061 '', | 2066 '', |
| 2062 'function(f,r){' | 2067 'function(f,r){' |
| 2063 'return function(){' | 2068 'return function(){' |
| 2064 'return f.apply({\$receiver:r(this)},arguments)' | 2069 'return f.apply({\$receiver:r(this)},arguments)' |
| 2065 '}' | 2070 '}' |
| 2066 '}(#,#)', functionType, getReceiver); | 2071 '}(#,#)', functionType, getReceiver); |
| 2067 } else { | 2072 } else if (functionType != null) { |
| 2073 // TODO(herhut): Disallow null again once we have function types. | |
| 2068 throw 'Error in reflectionInfo.'; | 2074 throw 'Error in reflectionInfo.'; |
| 2069 } | 2075 } |
| 2070 | 2076 |
| 2071 JS('', '#[#] = #', prototype, JS_SIGNATURE_NAME(), signatureFunction); | 2077 JS('', '#[#] = #', prototype, JS_SIGNATURE_NAME(), signatureFunction); |
| 2072 | 2078 |
| 2073 JS('', '#[#] = #', prototype, callName, trampoline); | 2079 JS('', '#[#] = #', prototype, callName, trampoline); |
| 2074 for (int i = 1; i < functions.length; i++) { | 2080 for (int i = 1; i < functions.length; i++) { |
| 2075 var stub = functions[i]; | 2081 var stub = functions[i]; |
| 2076 var stubCallName = JS('String|Null', '#.\$callName', stub); | 2082 var stubCallName = JS('String|Null', '#.\$callName', stub); |
| 2077 if (stubCallName != null) { | 2083 if (stubCallName != null) { |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2316 /// Called from implicit method getter (aka tear-off). | 2322 /// Called from implicit method getter (aka tear-off). |
| 2317 closureFromTearOff(receiver, | 2323 closureFromTearOff(receiver, |
| 2318 functions, | 2324 functions, |
| 2319 reflectionInfo, | 2325 reflectionInfo, |
| 2320 isStatic, | 2326 isStatic, |
| 2321 jsArguments, | 2327 jsArguments, |
| 2322 name) { | 2328 name) { |
| 2323 return Closure.fromTearOff( | 2329 return Closure.fromTearOff( |
| 2324 receiver, | 2330 receiver, |
| 2325 JSArray.markFixedList(functions), | 2331 JSArray.markFixedList(functions), |
| 2326 JSArray.markFixedList(reflectionInfo), | 2332 reflectionInfo is List ? JSArray.markFixedList(reflectionInfo) : reflectio nInfo, |
|
zarah
2015/02/02 08:20:11
long line.
| |
| 2327 JS('bool', '!!#', isStatic), | 2333 JS('bool', '!!#', isStatic), |
| 2328 jsArguments, | 2334 jsArguments, |
| 2329 JS('String', '#', name)); | 2335 JS('String', '#', name)); |
| 2330 } | 2336 } |
| 2331 | 2337 |
| 2332 /// Represents an implicit closure of a function. | 2338 /// Represents an implicit closure of a function. |
| 2333 class TearOffClosure extends Closure { | 2339 class TearOffClosure extends Closure { |
| 2334 } | 2340 } |
| 2335 | 2341 |
| 2336 /// 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 Loading... | |
| 3449 throw new MainError("No top-level function named 'main'."); | 3455 throw new MainError("No top-level function named 'main'."); |
| 3450 } | 3456 } |
| 3451 | 3457 |
| 3452 void badMain() { | 3458 void badMain() { |
| 3453 throw new MainError("'main' is not a function."); | 3459 throw new MainError("'main' is not a function."); |
| 3454 } | 3460 } |
| 3455 | 3461 |
| 3456 void mainHasTooManyParameters() { | 3462 void mainHasTooManyParameters() { |
| 3457 throw new MainError("'main' expects too many parameters."); | 3463 throw new MainError("'main' expects too many parameters."); |
| 3458 } | 3464 } |
| OLD | NEW |