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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 registerMethod(Element method) { | 185 registerMethod(Element method) { |
186 if (isNativeMethod(method)) { | 186 if (isNativeMethod(method)) { |
187 processNativeBehavior( | 187 processNativeBehavior( |
188 NativeBehavior.ofMethod(method, compiler), | 188 NativeBehavior.ofMethod(method, compiler), |
189 method); | 189 method); |
190 flushQueue(); | 190 flushQueue(); |
191 } | 191 } |
192 } | 192 } |
193 | 193 |
194 bool isNativeMethod(Element element) { | 194 bool isNativeMethod(Element element) { |
| 195 if (!element.getLibrary().canUseNative) return false; |
195 // Native method? | 196 // Native method? |
196 Node node = element.parseNode(compiler); | 197 return compiler.withCurrentElement(element, () { |
197 if (node is! FunctionExpression) return false; | 198 Node node = element.parseNode(compiler); |
198 node = node.body; | 199 if (node is! FunctionExpression) return false; |
199 Token token = node.getBeginToken(); | 200 node = node.body; |
200 if (token.stringValue == 'native') return true; | 201 Token token = node.getBeginToken(); |
201 return false; | 202 if (identical(token.stringValue, 'native')) return true; |
| 203 return false; |
| 204 }); |
202 } | 205 } |
203 | 206 |
204 void registerFieldLoad(Element field) { | 207 void registerFieldLoad(Element field) { |
205 processNativeBehavior( | 208 processNativeBehavior( |
206 NativeBehavior.ofFieldLoad(field, compiler), | 209 NativeBehavior.ofFieldLoad(field, compiler), |
207 field); | 210 field); |
208 flushQueue(); | 211 flushQueue(); |
209 } | 212 } |
210 | 213 |
211 void registerFieldStore(Element field) { | 214 void registerFieldStore(Element field) { |
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 String parameters) { | 837 String parameters) { |
835 buffer.add(" if (Object.getPrototypeOf(this).hasOwnProperty"); | 838 buffer.add(" if (Object.getPrototypeOf(this).hasOwnProperty"); |
836 buffer.add("('$methodName')) {\n"); | 839 buffer.add("('$methodName')) {\n"); |
837 buffer.add(" $code"); | 840 buffer.add(" $code"); |
838 buffer.add(" } else {\n"); | 841 buffer.add(" } else {\n"); |
839 buffer.add(" return Object.prototype.$methodName.call(this"); | 842 buffer.add(" return Object.prototype.$methodName.call(this"); |
840 buffer.add(parameters == '' ? '' : ', $parameters'); | 843 buffer.add(parameters == '' ? '' : ', $parameters'); |
841 buffer.add(");\n"); | 844 buffer.add(");\n"); |
842 buffer.add(" }\n"); | 845 buffer.add(" }\n"); |
843 } | 846 } |
OLD | NEW |