| 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 native; | 5 library native; |
| 6 | 6 |
| 7 import 'dart:uri'; | 7 import 'dart:uri'; |
| 8 import 'dart2jslib.dart' hide SourceString; | 8 import 'dart2jslib.dart' hide SourceString; |
| 9 import 'elements/elements.dart'; | 9 import 'elements/elements.dart'; |
| 10 import 'js_backend/js_backend.dart'; | 10 import 'js_backend/js_backend.dart'; |
| (...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 } else { | 865 } else { |
| 866 builder.compiler.internalError('unexpected kind: "${element.kind}"', | 866 builder.compiler.internalError('unexpected kind: "${element.kind}"', |
| 867 element: element); | 867 element: element); |
| 868 } | 868 } |
| 869 | 869 |
| 870 DartString jsCode = new DartString.literal(nativeMethodCall); | 870 DartString jsCode = new DartString.literal(nativeMethodCall); |
| 871 builder.push( | 871 builder.push( |
| 872 new HForeign(jsCode, const LiteralDartString('Object'), inputs)); | 872 new HForeign(jsCode, const LiteralDartString('Object'), inputs)); |
| 873 builder.close(new HReturn(builder.pop())).addSuccessor(builder.graph.exit); | 873 builder.close(new HReturn(builder.pop())).addSuccessor(builder.graph.exit); |
| 874 } else { | 874 } else { |
| 875 // This is JS code written in a Dart file with the construct | 875 if (parameters.parameterCount != 0) { |
| 876 // native """ ... """;. It does not work well with mangling, | 876 compiler.cancel( |
| 877 // but there should currently be no clash between leg mangling | 877 'native "..." syntax is restricted to functions with zero parameters', |
| 878 // and the library where this construct is being used. This | 878 node: nativeBody); |
| 879 // mangling problem will go away once we switch these libraries | 879 } |
| 880 // to use Leg's 'JS' function. | |
| 881 parameters.forEachParameter((Element parameter) { | |
| 882 DartType type = parameter.computeType(compiler).unalias(compiler); | |
| 883 if (type is FunctionType) { | |
| 884 // The parameter type is a function type either directly or through | |
| 885 // typedef(s). | |
| 886 HInstruction jsClosure = convertDartClosure(parameter, type); | |
| 887 // Because the JS code references the argument name directly, | |
| 888 // we must keep the name and assign the JS closure to it. | |
| 889 builder.add(new HForeign( | |
| 890 new DartString.literal('${parameter.name.slowToString()} = #'), | |
| 891 const LiteralDartString('void'), | |
| 892 <HInstruction>[jsClosure])); | |
| 893 } | |
| 894 }); | |
| 895 LiteralString jsCode = nativeBody.asLiteralString(); | 880 LiteralString jsCode = nativeBody.asLiteralString(); |
| 896 builder.push(new HForeign.statement(jsCode.dartString, <HInstruction>[])); | 881 builder.push(new HForeign.statement(jsCode.dartString, <HInstruction>[])); |
| 897 } | 882 } |
| 898 } | 883 } |
| OLD | NEW |