| 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('dart:uri'); | 6 #import('dart:uri'); |
| 7 #import('leg.dart'); | 7 #import('leg.dart'); |
| 8 #import('elements/elements.dart'); | 8 #import('elements/elements.dart'); |
| 9 #import('js_backend/js_backend.dart'); | 9 #import('js_backend/js_backend.dart'); |
| 10 #import('scanner/scannerlib.dart'); | 10 #import('scanner/scannerlib.dart'); |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 element.setNative(); | 183 element.setNative(); |
| 184 NativeEmitter nativeEmitter = builder.emitter.nativeEmitter; | 184 NativeEmitter nativeEmitter = builder.emitter.nativeEmitter; |
| 185 // If what we're compiling is a getter named 'typeName' and the native | 185 // If what we're compiling is a getter named 'typeName' and the native |
| 186 // class is named 'DOMType', we generate a call to the typeNameOf | 186 // class is named 'DOMType', we generate a call to the typeNameOf |
| 187 // function attached on the isolate. | 187 // function attached on the isolate. |
| 188 // The DOM classes assume that their 'typeName' property, which is | 188 // The DOM classes assume that their 'typeName' property, which is |
| 189 // not a JS property on the DOM types, returns the type name. | 189 // not a JS property on the DOM types, returns the type name. |
| 190 if (element.name == const SourceString('typeName') | 190 if (element.name == const SourceString('typeName') |
| 191 && element.isGetter() | 191 && element.isGetter() |
| 192 && nativeEmitter.toNativeName(element.getEnclosingClass()) == 'DOMType') { | 192 && nativeEmitter.toNativeName(element.getEnclosingClass()) == 'DOMType') { |
| 193 Element methodElement = | 193 Element helper = |
| 194 compiler.findHelper(const SourceString('getTypeNameOf')); | 194 compiler.findHelper(const SourceString('getTypeNameOf')); |
| 195 HStatic method = new HStatic(methodElement); | 195 builder.pushInvokeHelper1(helper, builder.localsHandler.readThis()); |
| 196 builder.add(method); | |
| 197 builder.push(new HInvokeStatic(Selector.INVOCATION_1, | |
| 198 <HInstruction>[method, builder.localsHandler.readThis()])); | |
| 199 builder.close(new HReturn(builder.pop())).addSuccessor(builder.graph.exit); | 196 builder.close(new HReturn(builder.pop())).addSuccessor(builder.graph.exit); |
| 200 } | 197 } |
| 201 | 198 |
| 202 HInstruction convertDartClosure(Element parameter, FunctionType type) { | 199 HInstruction convertDartClosure(Element parameter, FunctionType type) { |
| 203 HInstruction local = builder.localsHandler.readLocal(parameter); | 200 HInstruction local = builder.localsHandler.readLocal(parameter); |
| 201 HInstruction arity = builder.graph.addConstantInt(type.computeArity()); |
| 204 // TODO(ngeoffray): For static methods, we could pass a method with a | 202 // TODO(ngeoffray): For static methods, we could pass a method with a |
| 205 // defined arity. | 203 // defined arity. |
| 206 builder.push(new HStatic(builder.interceptors.getClosureConverter())); | 204 Element helper = builder.interceptors.getClosureConverter(); |
| 207 HInstruction arity = builder.graph.addConstantInt(type.computeArity()); | 205 builder.pushInvokeHelper2(helper, local, arity); |
| 208 List<HInstruction> callInputs = <HInstruction>[builder.pop(), local, arity]; | 206 HInstruction closure = builder.pop(); |
| 209 HInstruction closure = new HInvokeStatic(Selector.INVOCATION_1, callInputs); | |
| 210 builder.add(closure); | |
| 211 return closure; | 207 return closure; |
| 212 } | 208 } |
| 213 | 209 |
| 214 // Check which pattern this native method follows: | 210 // Check which pattern this native method follows: |
| 215 // 1) foo() native; hasBody = false, isRedirecting = false | 211 // 1) foo() native; hasBody = false, isRedirecting = false |
| 216 // 2) foo() native "bar"; hasBody = false, isRedirecting = true | 212 // 2) foo() native "bar"; hasBody = false, isRedirecting = true |
| 217 // 3) foo() native "return 42"; hasBody = true, isRedirecting = false | 213 // 3) foo() native "return 42"; hasBody = true, isRedirecting = false |
| 218 RegExp nativeRedirectionRegExp = const RegExp(@'^[a-zA-Z][a-zA-Z_$0-9]*$'); | 214 RegExp nativeRedirectionRegExp = const RegExp(@'^[a-zA-Z][a-zA-Z_$0-9]*$'); |
| 219 bool hasBody = false; | 215 bool hasBody = false; |
| 220 bool isRedirecting = false; | 216 bool isRedirecting = false; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 String parameters) { | 326 String parameters) { |
| 331 buffer.add(" if (Object.getPrototypeOf(this).hasOwnProperty"); | 327 buffer.add(" if (Object.getPrototypeOf(this).hasOwnProperty"); |
| 332 buffer.add("('$methodName')) {\n"); | 328 buffer.add("('$methodName')) {\n"); |
| 333 buffer.add(" $code"); | 329 buffer.add(" $code"); |
| 334 buffer.add(" } else {\n"); | 330 buffer.add(" } else {\n"); |
| 335 buffer.add(" return Object.prototype.$methodName.call(this"); | 331 buffer.add(" return Object.prototype.$methodName.call(this"); |
| 336 buffer.add(parameters == '' ? '' : ', $parameters'); | 332 buffer.add(parameters == '' ? '' : ', $parameters'); |
| 337 buffer.add(");\n"); | 333 buffer.add(");\n"); |
| 338 buffer.add(" }\n"); | 334 buffer.add(" }\n"); |
| 339 } | 335 } |
| OLD | NEW |