| 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 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 } | 787 } |
| 788 return false; | 788 return false; |
| 789 } | 789 } |
| 790 | 790 |
| 791 final RegExp nativeRedirectionRegExp = new RegExp(r'^[a-zA-Z][a-zA-Z_$0-9]*$'); | 791 final RegExp nativeRedirectionRegExp = new RegExp(r'^[a-zA-Z][a-zA-Z_$0-9]*$'); |
| 792 | 792 |
| 793 void handleSsaNative(SsaBuilder builder, Expression nativeBody) { | 793 void handleSsaNative(SsaBuilder builder, Expression nativeBody) { |
| 794 Compiler compiler = builder.compiler; | 794 Compiler compiler = builder.compiler; |
| 795 FunctionElement element = builder.work.element; | 795 FunctionElement element = builder.work.element; |
| 796 NativeEmitter nativeEmitter = builder.emitter.nativeEmitter; | 796 NativeEmitter nativeEmitter = builder.emitter.nativeEmitter; |
| 797 // If what we're compiling is a getter named 'typeName' and the native | |
| 798 // class is named 'DOMType', we generate a call to the typeNameOf | |
| 799 // function attached on the isolate. | |
| 800 // The DOM classes assume that their 'typeName' property, which is | |
| 801 // not a JS property on the DOM types, returns the type name. | |
| 802 if (element.name == const SourceString('typeName') | |
| 803 && element.isGetter() | |
| 804 && nativeEmitter.toNativeName(element.getEnclosingClass()) == 'DOMType') { | |
| 805 Element helper = | |
| 806 compiler.findHelper(const SourceString('getTypeNameOf')); | |
| 807 builder.pushInvokeHelper1(helper, builder.localsHandler.readThis()); | |
| 808 builder.close(new HReturn(builder.pop())).addSuccessor(builder.graph.exit); | |
| 809 } | |
| 810 | 797 |
| 811 HInstruction convertDartClosure(Element parameter, FunctionType type) { | 798 HInstruction convertDartClosure(Element parameter, FunctionType type) { |
| 812 HInstruction local = builder.localsHandler.readLocal(parameter); | 799 HInstruction local = builder.localsHandler.readLocal(parameter); |
| 813 Constant arityConstant = | 800 Constant arityConstant = |
| 814 builder.constantSystem.createInt(type.computeArity()); | 801 builder.constantSystem.createInt(type.computeArity()); |
| 815 HInstruction arity = builder.graph.addConstant(arityConstant); | 802 HInstruction arity = builder.graph.addConstant(arityConstant); |
| 816 // TODO(ngeoffray): For static methods, we could pass a method with a | 803 // TODO(ngeoffray): For static methods, we could pass a method with a |
| 817 // defined arity. | 804 // defined arity. |
| 818 Element helper = builder.interceptors.getClosureConverter(); | 805 Element helper = builder.interceptors.getClosureConverter(); |
| 819 builder.pushInvokeHelper2(helper, local, arity); | 806 builder.pushInvokeHelper2(helper, local, arity); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 901 builder.add(new HForeign( | 888 builder.add(new HForeign( |
| 902 new DartString.literal('${parameter.name.slowToString()} = #'), | 889 new DartString.literal('${parameter.name.slowToString()} = #'), |
| 903 const LiteralDartString('void'), | 890 const LiteralDartString('void'), |
| 904 <HInstruction>[jsClosure])); | 891 <HInstruction>[jsClosure])); |
| 905 } | 892 } |
| 906 }); | 893 }); |
| 907 LiteralString jsCode = nativeBody.asLiteralString(); | 894 LiteralString jsCode = nativeBody.asLiteralString(); |
| 908 builder.push(new HForeign.statement(jsCode.dartString, <HInstruction>[])); | 895 builder.push(new HForeign.statement(jsCode.dartString, <HInstruction>[])); |
| 909 } | 896 } |
| 910 } | 897 } |
| OLD | NEW |