| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 import '../common.dart'; | 5 import '../common.dart'; |
| 6 import '../constants/values.dart'; | 6 import '../constants/values.dart'; |
| 7 import '../elements/resolution_types.dart'; | 7 import '../elements/resolution_types.dart'; |
| 8 import '../elements/elements.dart'; | 8 import '../elements/elements.dart'; |
| 9 import '../js/js.dart' as js; | 9 import '../js/js.dart' as js; |
| 10 import '../js_emitter/js_emitter.dart' show NativeEmitter; | 10 import '../js_emitter/js_emitter.dart' show NativeEmitter; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 // No longer supported, this is now done with @JSName('foo') and case 1. | 41 // No longer supported, this is now done with @JSName('foo') and case 1. |
| 42 // 3) foo() native "return 42"; | 42 // 3) foo() native "return 42"; |
| 43 // hasBody = true | 43 // hasBody = true |
| 44 bool hasBody = false; | 44 bool hasBody = false; |
| 45 assert(builder.nativeData.isNativeMember(element)); | 45 assert(builder.nativeData.isNativeMember(element)); |
| 46 String nativeMethodName = builder.nativeData.getFixedBackendName(element); | 46 String nativeMethodName = builder.nativeData.getFixedBackendName(element); |
| 47 if (nativeBody != null) { | 47 if (nativeBody != null) { |
| 48 LiteralString jsCode = nativeBody.asLiteralString(); | 48 LiteralString jsCode = nativeBody.asLiteralString(); |
| 49 String str = jsCode.dartString.slowToString(); | 49 String str = jsCode.dartString.slowToString(); |
| 50 if (nativeRedirectionRegExp.hasMatch(str)) { | 50 if (nativeRedirectionRegExp.hasMatch(str)) { |
| 51 throw new SpannableAssertionFailure( | 51 failedAt(nativeBody, "Deprecated syntax, use @JSName('name') instead."); |
| 52 nativeBody, "Deprecated syntax, use @JSName('name') instead."); | |
| 53 } | 52 } |
| 54 hasBody = true; | 53 hasBody = true; |
| 55 } | 54 } |
| 56 | 55 |
| 57 if (!hasBody) { | 56 if (!hasBody) { |
| 58 nativeEmitter.nativeMethods.add(element); | 57 nativeEmitter.nativeMethods.add(element); |
| 59 } | 58 } |
| 60 | 59 |
| 61 FunctionSignature parameters = element.functionSignature; | 60 FunctionSignature parameters = element.functionSignature; |
| 62 if (!hasBody) { | 61 if (!hasBody) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 82 | 81 |
| 83 String foreignParameters = arguments.join(','); | 82 String foreignParameters = arguments.join(','); |
| 84 String nativeMethodCall; | 83 String nativeMethodCall; |
| 85 if (element.kind == ElementKind.FUNCTION) { | 84 if (element.kind == ElementKind.FUNCTION) { |
| 86 nativeMethodCall = '$receiver$nativeMethodName($foreignParameters)'; | 85 nativeMethodCall = '$receiver$nativeMethodName($foreignParameters)'; |
| 87 } else if (element.kind == ElementKind.GETTER) { | 86 } else if (element.kind == ElementKind.GETTER) { |
| 88 nativeMethodCall = '$receiver$nativeMethodName'; | 87 nativeMethodCall = '$receiver$nativeMethodName'; |
| 89 } else if (element.kind == ElementKind.SETTER) { | 88 } else if (element.kind == ElementKind.SETTER) { |
| 90 nativeMethodCall = '$receiver$nativeMethodName = $foreignParameters'; | 89 nativeMethodCall = '$receiver$nativeMethodName = $foreignParameters'; |
| 91 } else { | 90 } else { |
| 92 throw new SpannableAssertionFailure( | 91 failedAt(element, 'Unexpected kind: "${element.kind}".'); |
| 93 element, 'Unexpected kind: "${element.kind}".'); | |
| 94 } | 92 } |
| 95 | 93 |
| 96 builder.push(new HForeignCode( | 94 builder.push(new HForeignCode( |
| 97 // TODO(sra): This could be cached. The number of templates should | 95 // TODO(sra): This could be cached. The number of templates should |
| 98 // be proportional to the number of native methods, which is bounded | 96 // be proportional to the number of native methods, which is bounded |
| 99 // by the dart: libraries. | 97 // by the dart: libraries. |
| 100 js.js.uncachedExpressionTemplate(nativeMethodCall), | 98 js.js.uncachedExpressionTemplate(nativeMethodCall), |
| 101 builder.commonMasks.dynamicType, | 99 builder.commonMasks.dynamicType, |
| 102 inputs, | 100 inputs, |
| 103 effects: new SideEffects())); | 101 effects: new SideEffects())); |
| 104 // TODO(johnniwinther): Provide source information. | 102 // TODO(johnniwinther): Provide source information. |
| 105 builder | 103 builder |
| 106 .close(new HReturn(builder.pop(), null)) | 104 .close(new HReturn(builder.pop(), null)) |
| 107 .addSuccessor(builder.graph.exit); | 105 .addSuccessor(builder.graph.exit); |
| 108 } else { | 106 } else { |
| 109 if (parameters.parameterCount != 0) { | 107 if (parameters.parameterCount != 0) { |
| 110 throw new SpannableAssertionFailure( | 108 failedAt( |
| 111 nativeBody, | 109 nativeBody, |
| 112 'native "..." syntax is restricted to ' | 110 'native "..." syntax is restricted to ' |
| 113 'functions with zero parameters.'); | 111 'functions with zero parameters.'); |
| 114 } | 112 } |
| 115 LiteralString jsCode = nativeBody.asLiteralString(); | 113 LiteralString jsCode = nativeBody.asLiteralString(); |
| 116 builder.push(new HForeignCode.statement( | 114 builder.push(new HForeignCode.statement( |
| 117 js.js.statementTemplateYielding( | 115 js.js.statementTemplateYielding( |
| 118 new js.LiteralStatement(jsCode.dartString.slowToString())), | 116 new js.LiteralStatement(jsCode.dartString.slowToString())), |
| 119 <HInstruction>[], | 117 <HInstruction>[], |
| 120 new SideEffects(), | 118 new SideEffects(), |
| 121 null, | 119 null, |
| 122 builder.commonMasks.dynamicType)); | 120 builder.commonMasks.dynamicType)); |
| 123 } | 121 } |
| 124 } | 122 } |
| OLD | NEW |