| 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 library dart2js.js_emitter.native_emitter; | 5 library dart2js.js_emitter.native_emitter; |
| 6 | 6 |
| 7 import '../common.dart'; | 7 import '../common.dart'; |
| 8 import '../common_elements.dart' show CommonElements; | 8 import '../common_elements.dart' show CommonElements; |
| 9 import '../elements/types.dart' show DartType, FunctionType; | 9 import '../elements/types.dart' show DartType, FunctionType; |
| 10 import '../elements/entities.dart'; | 10 import '../elements/entities.dart'; |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 // must be turned into a JS call to: | 304 // must be turned into a JS call to: |
| 305 // foo(null, y). | 305 // foo(null, y). |
| 306 | 306 |
| 307 List<jsAst.Statement> statements = <jsAst.Statement>[]; | 307 List<jsAst.Statement> statements = <jsAst.Statement>[]; |
| 308 potentiallyConvertDartClosuresToJs(statements, member, stubParameters); | 308 potentiallyConvertDartClosuresToJs(statements, member, stubParameters); |
| 309 | 309 |
| 310 String target; | 310 String target; |
| 311 jsAst.Expression receiver; | 311 jsAst.Expression receiver; |
| 312 List<jsAst.Expression> arguments; | 312 List<jsAst.Expression> arguments; |
| 313 | 313 |
| 314 assert(invariant(member, nativeMethods.contains(member))); | 314 assert(nativeMethods.contains(member), failedAt(member)); |
| 315 // When calling a JS method, we call it with the native name, and only the | 315 // When calling a JS method, we call it with the native name, and only the |
| 316 // arguments up until the last one provided. | 316 // arguments up until the last one provided. |
| 317 target = _nativeData.getFixedBackendName(member); | 317 target = _nativeData.getFixedBackendName(member); |
| 318 | 318 |
| 319 if (isInterceptedMethod) { | 319 if (isInterceptedMethod) { |
| 320 receiver = argumentsBuffer[0]; | 320 receiver = argumentsBuffer[0]; |
| 321 arguments = argumentsBuffer.sublist( | 321 arguments = argumentsBuffer.sublist( |
| 322 1, indexOfLastOptionalArgumentInParameters + 1); | 322 1, indexOfLastOptionalArgumentInParameters + 1); |
| 323 } else { | 323 } else { |
| 324 // Native methods that are not intercepted must be static. | 324 // Native methods that are not intercepted must be static. |
| 325 assert(invariant(member, member.isStatic)); | 325 assert(member.isStatic, failedAt(member)); |
| 326 arguments = argumentsBuffer.sublist( | 326 arguments = argumentsBuffer.sublist( |
| 327 0, indexOfLastOptionalArgumentInParameters + 1); | 327 0, indexOfLastOptionalArgumentInParameters + 1); |
| 328 if (_nativeData.isJsInteropMember(member)) { | 328 if (_nativeData.isJsInteropMember(member)) { |
| 329 // fixedBackendPath is allowed to have the form foo.bar.baz for | 329 // fixedBackendPath is allowed to have the form foo.bar.baz for |
| 330 // interop. This template is uncached to avoid possibly running out of | 330 // interop. This template is uncached to avoid possibly running out of |
| 331 // memory when Dart2Js is run in server mode. In reality the risk of | 331 // memory when Dart2Js is run in server mode. In reality the risk of |
| 332 // caching these templates causing an issue is very low as each class | 332 // caching these templates causing an issue is very low as each class |
| 333 // and library that uses typed JavaScript interop will create only 1 | 333 // and library that uses typed JavaScript interop will create only 1 |
| 334 // unique template. | 334 // unique template. |
| 335 receiver = js | 335 receiver = js |
| (...skipping 23 matching lines...) Expand all Loading... |
| 359 // satisfy a check against [element], in which case an interceptor must be | 359 // satisfy a check against [element], in which case an interceptor must be |
| 360 // used. We should also use an interceptor if the check can't be satisfied | 360 // used. We should also use an interceptor if the check can't be satisfied |
| 361 // by a native class in case we get a native instance that tries to spoof | 361 // by a native class in case we get a native instance that tries to spoof |
| 362 // the type info. i.e the criteria for whether or not to use an interceptor | 362 // the type info. i.e the criteria for whether or not to use an interceptor |
| 363 // is whether the receiver can be native, not the type of the test. | 363 // is whether the receiver can be native, not the type of the test. |
| 364 ClassEntity cls = element; | 364 ClassEntity cls = element; |
| 365 if (_nativeData.isNativeOrExtendsNative(cls)) return true; | 365 if (_nativeData.isNativeOrExtendsNative(cls)) return true; |
| 366 return isSupertypeOfNativeClass(element); | 366 return isSupertypeOfNativeClass(element); |
| 367 } | 367 } |
| 368 } | 368 } |
| OLD | NEW |