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 #import('../../lib/uri/uri.dart'); | 6 #import('../../lib/uri/uri.dart'); |
7 #import('leg.dart'); | 7 #import('leg.dart'); |
8 #import('elements/elements.dart'); | 8 #import('elements/elements.dart'); |
9 #import('scanner/scannerlib.dart'); | 9 #import('scanner/scannerlib.dart'); |
10 #import('ssa/ssa.dart'); | 10 #import('ssa/ssa.dart'); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 // Register NoSuchMethodException and captureStackTrace in the compiler | 130 // Register NoSuchMethodException and captureStackTrace in the compiler |
131 // because the dynamic dispatch for native classes may use them. | 131 // because the dynamic dispatch for native classes may use them. |
132 Compiler compiler = builder.compiler; | 132 Compiler compiler = builder.compiler; |
133 ClassElement cls = compiler.coreLibrary.find( | 133 ClassElement cls = compiler.coreLibrary.find( |
134 Compiler.NO_SUCH_METHOD_EXCEPTION); | 134 Compiler.NO_SUCH_METHOD_EXCEPTION); |
135 cls.resolve(compiler); | 135 cls.resolve(compiler); |
136 compiler.addToWorklist(cls.lookupConstructor(cls.name)); | 136 compiler.addToWorklist(cls.lookupConstructor(cls.name)); |
137 compiler.registerStaticUse( | 137 compiler.registerStaticUse( |
138 compiler.findHelper(new SourceString('captureStackTrace'))); | 138 compiler.findHelper(new SourceString('captureStackTrace'))); |
139 | 139 |
| 140 FunctionElement element = builder.work.element; |
| 141 NativeEmitter nativeEmitter = compiler.emitter.nativeEmitter; |
| 142 // If what we're compiling is a getter named 'typeName' and the native |
| 143 // class is named 'DOMType', we generate a call to the typeNameOf |
| 144 // function attached on the isolate. |
| 145 // The DOM classes assume that their 'typeName' property, which is |
| 146 // not a JS property on the DOM types, returns the type name. |
| 147 if (element.name == const SourceString('typeName') |
| 148 && element.isGetter() |
| 149 && nativeEmitter.toNativeName(element.enclosingElement) == 'DOMType') { |
| 150 DartString jsCode = new DartString.literal( |
| 151 '${nativeEmitter.typeNameOfName}(\$0)'); |
| 152 List<HInstruction> inputs = |
| 153 <HInstruction>[builder.localsHandler.readThis()]; |
| 154 builder.push(new HForeign( |
| 155 jsCode, const LiteralDartString('String'), inputs)); |
| 156 return; |
| 157 } |
| 158 |
140 if (node.arguments.isEmpty()) { | 159 if (node.arguments.isEmpty()) { |
141 List<String> arguments = <String>[]; | 160 List<String> arguments = <String>[]; |
142 List<HInstruction> inputs = <HInstruction>[]; | 161 List<HInstruction> inputs = <HInstruction>[]; |
143 FunctionElement element = builder.work.element; | |
144 FunctionParameters parameters = element.computeParameters(builder.compiler); | 162 FunctionParameters parameters = element.computeParameters(builder.compiler); |
145 int i = 0; | 163 int i = 0; |
146 String receiver = ''; | 164 String receiver = ''; |
147 if (element.isInstanceMember()) { | 165 if (element.isInstanceMember()) { |
148 receiver = '\$$i.'; | 166 receiver = '\$$i.'; |
149 i++; | 167 i++; |
150 inputs.add(builder.localsHandler.readThis()); | 168 inputs.add(builder.localsHandler.readThis()); |
151 } | 169 } |
152 Compiler compiler = builder.compiler; | 170 Compiler compiler = builder.compiler; |
153 parameters.forEachParameter((Element parameter) { | 171 parameters.forEachParameter((Element parameter) { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 | 273 |
256 } else if (!node.arguments.tail.isEmpty()) { | 274 } else if (!node.arguments.tail.isEmpty()) { |
257 builder.compiler.cancel('More than one argument to native'); | 275 builder.compiler.cancel('More than one argument to native'); |
258 } else { | 276 } else { |
259 LiteralString jsCode = node.arguments.head; | 277 LiteralString jsCode = node.arguments.head; |
260 builder.push(new HForeign(jsCode.dartString, | 278 builder.push(new HForeign(jsCode.dartString, |
261 const LiteralDartString('Object'), | 279 const LiteralDartString('Object'), |
262 <HInstruction>[])); | 280 <HInstruction>[])); |
263 } | 281 } |
264 } | 282 } |
OLD | NEW |