Chromium Code Reviews| 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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 } | 154 } |
| 155 | 155 |
| 156 HInstruction thenInstruction; | 156 HInstruction thenInstruction; |
| 157 void visitThen() { | 157 void visitThen() { |
| 158 SourceString jsCode = new SourceString(nativeMethodCall); | 158 SourceString jsCode = new SourceString(nativeMethodCall); |
| 159 thenInstruction = | 159 thenInstruction = |
| 160 new HForeign(jsCode, const SourceString('Object'), inputs); | 160 new HForeign(jsCode, const SourceString('Object'), inputs); |
| 161 builder.add(thenInstruction); | 161 builder.add(thenInstruction); |
| 162 } | 162 } |
| 163 | 163 |
| 164 if (!element.isInstanceMember()) { | 164 bool isNativeLiteral; |
|
kasperl
2012/03/02 13:11:33
Initialize to false?
ngeoffray
2012/03/05 08:28:00
Thanks for spotting this. I was convinced it would
| |
| 165 // If the method is a non-instance method, we just generate a direct | 165 if (element.enclosingElement.kind == ElementKind.CLASS) { |
| 166 ClassElement classElement = element.enclosingElement; | |
| 167 String nativeName = classElement.nativeName.slowToString(); | |
| 168 isNativeLiteral = | |
| 169 builder.compiler.emitter.nativeEmitter.isNativeLiteral(nativeName); | |
| 170 } | |
| 171 if (!element.isInstanceMember() || isNativeLiteral) { | |
| 172 // If the method is a non-instance method, or is a member of a native | |
| 173 // class that represents a literal, we just generate a direct | |
| 166 // call to the native method. | 174 // call to the native method. |
| 167 visitThen(); | 175 visitThen(); |
| 168 builder.stack.add(thenInstruction); | 176 builder.stack.add(thenInstruction); |
| 169 } else { | 177 } else { |
| 170 // If the method is an instance method, we generate the following code: | 178 // If the method is an instance method, we generate the following code: |
| 171 // function(params) { | 179 // function(params) { |
| 172 // return Object.getPrototypeOf(this).hasOwnProperty(dartMethodName)) | 180 // return Object.getPrototypeOf(this).hasOwnProperty(dartMethodName)) |
| 173 // ? this.methodName(params) | 181 // ? this.methodName(params) |
| 174 // : Object.prototype.methodName.call(this, params); | 182 // : Object.prototype.methodName.call(this, params); |
| 175 // } | 183 // } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 } else if (!node.arguments.tail.isEmpty()) { | 223 } else if (!node.arguments.tail.isEmpty()) { |
| 216 builder.compiler.cancel('More than one argument to native'); | 224 builder.compiler.cancel('More than one argument to native'); |
| 217 } else { | 225 } else { |
| 218 LiteralString jsCode = node.arguments.head; | 226 LiteralString jsCode = node.arguments.head; |
| 219 int start = jsCode.value.slowToString()[0] === '@' ? 1 : 0; | 227 int start = jsCode.value.slowToString()[0] === '@' ? 1 : 0; |
| 220 builder.push(new HForeign(builder.unquote(jsCode, start), | 228 builder.push(new HForeign(builder.unquote(jsCode, start), |
| 221 const SourceString('Object'), | 229 const SourceString('Object'), |
| 222 <HInstruction>[])); | 230 <HInstruction>[])); |
| 223 } | 231 } |
| 224 } | 232 } |
| OLD | NEW |