OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 part of js_backend; | 5 part of js_backend; |
6 | 6 |
7 /** | 7 /** |
8 * A function element that represents a closure call. The signature is copied | 8 * A function element that represents a closure call. The signature is copied |
9 * from the given element. | 9 * from the given element. |
10 */ | 10 */ |
(...skipping 3141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3152 } | 3152 } |
3153 if (hasBool) { | 3153 if (hasBool) { |
3154 block.statements.add(buildInterceptorCheck(backend.jsBoolClass)); | 3154 block.statements.add(buildInterceptorCheck(backend.jsBoolClass)); |
3155 } | 3155 } |
3156 // TODO(ahe): It might be faster to check for Array before | 3156 // TODO(ahe): It might be faster to check for Array before |
3157 // function and bool. | 3157 // function and bool. |
3158 if (hasArray) { | 3158 if (hasArray) { |
3159 block.statements.add(buildInterceptorCheck(backend.jsArrayClass)); | 3159 block.statements.add(buildInterceptorCheck(backend.jsArrayClass)); |
3160 } | 3160 } |
3161 | 3161 |
3162 // Recognize JavaScript functions that correspond to Dart constructors | |
3163 // (generated by defineClass that adds the property 'builtin$cls'). | |
3164 // TODO(ahe): Either integrate this with native dispatchProperty, or use a | |
3165 // mixin approach in defineClass. | |
3166 block.statements.add( | |
3167 js.if_(r'typeof receiver == "function" && "builtin$cls" in receiver', | |
3168 buildReturnInterceptor(backend.jsRuntimeType))); | |
3169 | |
3170 // Recognize JavaScript object literals that are used to encode function | |
3171 // types. These objects are generated by | |
3172 // [TypeRepresentationGenerator.visitFunctionType] and always have the | |
ngeoffray
2013/09/10 10:42:26
missing something after 'and'.
| |
3173 // "func" property (namer.functionTypeTag()). | |
3174 // TODO(ahe): This should be a real Dart object and we should be able to | |
3175 // remove this test (so I'm keeping the redundant "object" test). | |
3176 block.statements.add( | |
3177 js.if_(r'typeof receiver == "object"' | |
3178 // JavaScript object literals have Object as constructor. | |
3179 ' && receiver.constructor === Object' | |
3180 ' && "${namer.functionTypeTag()}" in receiver', | |
3181 buildReturnInterceptor(backend.jsFunctionType))); | |
3182 | |
3162 if (hasNative) { | 3183 if (hasNative) { |
3163 block.statements.add( | 3184 block.statements.add( |
3164 js.if_( | 3185 js.if_('typeof receiver != "object"', js.return_('receiver'))); |
3165 js('(typeof receiver) != "object"'), | |
3166 js.return_(js('receiver')))); | |
3167 | 3186 |
3168 // if (receiver instanceof $.Object) return receiver; | |
3169 // return $.getNativeInterceptor(receiver); | |
3170 block.statements.add( | 3187 block.statements.add( |
3171 js.if_(js('receiver instanceof #', | 3188 js.if_(js('receiver instanceof #', |
3172 js(namer.isolateAccess(compiler.objectClass))), | 3189 js(namer.isolateAccess(compiler.objectClass))), |
3173 js.return_(js('receiver')))); | 3190 js.return_('receiver'))); |
3174 block.statements.add( | 3191 block.statements.add( |
3175 js.return_( | 3192 js.return_( |
3176 js(namer.isolateAccess(backend.getNativeInterceptorMethod))( | 3193 js(namer.isolateAccess(backend.getNativeInterceptorMethod))( |
3177 ['receiver']))); | 3194 ['receiver']))); |
3178 | 3195 |
3179 } else { | 3196 } else { |
3180 ClassElement jsUnknown = backend.jsUnknownJavaScriptObjectClass; | 3197 ClassElement jsUnknown = backend.jsUnknownJavaScriptObjectClass; |
3181 if (compiler.codegenWorld.instantiatedClasses.contains(jsUnknown)) { | 3198 if (compiler.codegenWorld.instantiatedClasses.contains(jsUnknown)) { |
3182 block.statements.add( | 3199 block.statements.add( |
3183 js.if_(js('!(receiver instanceof #)', | 3200 js.if_(js('!(receiver instanceof #)', |
(...skipping 1017 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4201 | 4218 |
4202 const String HOOKS_API_USAGE = """ | 4219 const String HOOKS_API_USAGE = """ |
4203 // The code supports the following hooks: | 4220 // The code supports the following hooks: |
4204 // dartPrint(message) - if this function is defined it is called | 4221 // dartPrint(message) - if this function is defined it is called |
4205 // instead of the Dart [print] method. | 4222 // instead of the Dart [print] method. |
4206 // dartMainRunner(main) - if this function is defined, the Dart [main] | 4223 // dartMainRunner(main) - if this function is defined, the Dart [main] |
4207 // method will not be invoked directly. | 4224 // method will not be invoked directly. |
4208 // Instead, a closure that will invoke [main] is | 4225 // Instead, a closure that will invoke [main] is |
4209 // passed to [dartMainRunner]. | 4226 // passed to [dartMainRunner]. |
4210 """; | 4227 """; |
OLD | NEW |