| 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('scanner/scannerlib.dart'); | 9 #import('scanner/scannerlib.dart'); |
| 10 #import('ssa/ssa.dart'); | 10 #import('ssa/ssa.dart'); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 cls.superclass, | 32 cls.superclass, |
| 33 () => <ClassElement>[]); | 33 () => <ClassElement>[]); |
| 34 directSubtypes.add(cls); | 34 directSubtypes.add(cls); |
| 35 } | 35 } |
| 36 | 36 |
| 37 void processNativeClassesInLibrary(Enqueuer world, | 37 void processNativeClassesInLibrary(Enqueuer world, |
| 38 CodeEmitterTask emitter, | 38 CodeEmitterTask emitter, |
| 39 LibraryElement library) { | 39 LibraryElement library) { |
| 40 bool hasNativeClass = false; | 40 bool hasNativeClass = false; |
| 41 final compiler = emitter.compiler; | 41 final compiler = emitter.compiler; |
| 42 for (Link<Element> link = library.topLevelElements; | 42 for (Link<Element> link = library.localMembers; |
| 43 !link.isEmpty(); link = link.tail) { | 43 !link.isEmpty(); link = link.tail) { |
| 44 Element element = link.head; | 44 Element element = link.head; |
| 45 if (element.kind == ElementKind.CLASS) { | 45 if (element.kind == ElementKind.CLASS) { |
| 46 ClassElement classElement = element; | 46 ClassElement classElement = element; |
| 47 if (classElement.isNative()) { | 47 if (classElement.isNative()) { |
| 48 hasNativeClass = true; | 48 hasNativeClass = true; |
| 49 world.registerInstantiatedClass(classElement); | 49 world.registerInstantiatedClass(classElement); |
| 50 // Also parse the node to know all its methods because | 50 // Also parse the node to know all its methods because |
| 51 // otherwise it will only be parsed if there is a call to | 51 // otherwise it will only be parsed if there is a call to |
| 52 // one of its constructor. | 52 // one of its constructor. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 69 const SourceString('defineProperty'))); | 69 const SourceString('defineProperty'))); |
| 70 world.registerStaticUse(compiler.findHelper( | 70 world.registerStaticUse(compiler.findHelper( |
| 71 const SourceString('toStringForNativeObject'))); | 71 const SourceString('toStringForNativeObject'))); |
| 72 } | 72 } |
| 73 } | 73 } |
| 74 | 74 |
| 75 void maybeEnableNative(Compiler compiler, | 75 void maybeEnableNative(Compiler compiler, |
| 76 LibraryElement library, | 76 LibraryElement library, |
| 77 Uri uri) { | 77 Uri uri) { |
| 78 String libraryName = uri.toString(); | 78 String libraryName = uri.toString(); |
| 79 if (library.script.name.contains('dart/tests/compiler/dart2js_native') | 79 if (library.entryCompilationUnit.script.name.contains( |
| 80 'dart/tests/compiler/dart2js_native') |
| 80 || libraryName == 'dart:dom_deprecated' | 81 || libraryName == 'dart:dom_deprecated' |
| 81 || libraryName == 'dart:isolate' | 82 || libraryName == 'dart:isolate' |
| 82 || libraryName == 'dart:html') { | 83 || libraryName == 'dart:html') { |
| 83 library.canUseNative = true; | 84 library.canUseNative = true; |
| 84 library.define(compiler.findHelper(const SourceString('JS')), compiler); | 85 library.addToScope(compiler.findHelper(const SourceString('JS')), compiler); |
| 85 if (compiler.jsIndexingBehaviorInterface !== null) { | 86 if (compiler.jsIndexingBehaviorInterface !== null) { |
| 86 library.define(compiler.jsIndexingBehaviorInterface, compiler); | 87 library.addToScope(compiler.jsIndexingBehaviorInterface, compiler); |
| 87 } | 88 } |
| 88 } | 89 } |
| 89 } | 90 } |
| 90 | 91 |
| 91 void checkAllowedLibrary(ElementListener listener, Token token) { | 92 void checkAllowedLibrary(ElementListener listener, Token token) { |
| 92 LibraryElement currentLibrary = listener.compilationUnitElement.getLibrary(); | 93 LibraryElement currentLibrary = listener.compilationUnitElement.getLibrary(); |
| 93 if (!currentLibrary.canUseNative) { | 94 if (!currentLibrary.canUseNative) { |
| 94 listener.recoverableError("Unexpected token", token: token); | 95 listener.recoverableError("Unexpected token", token: token); |
| 95 } | 96 } |
| 96 } | 97 } |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 String parameters) { | 330 String parameters) { |
| 330 buffer.add(" if (Object.getPrototypeOf(this).hasOwnProperty"); | 331 buffer.add(" if (Object.getPrototypeOf(this).hasOwnProperty"); |
| 331 buffer.add("('$methodName')) {\n"); | 332 buffer.add("('$methodName')) {\n"); |
| 332 buffer.add(" $code"); | 333 buffer.add(" $code"); |
| 333 buffer.add(" } else {\n"); | 334 buffer.add(" } else {\n"); |
| 334 buffer.add(" return Object.prototype.$methodName.call(this"); | 335 buffer.add(" return Object.prototype.$methodName.call(this"); |
| 335 buffer.add(parameters == '' ? '' : ', $parameters'); | 336 buffer.add(parameters == '' ? '' : ', $parameters'); |
| 336 buffer.add(");\n"); | 337 buffer.add(");\n"); |
| 337 buffer.add(" }\n"); | 338 buffer.add(" }\n"); |
| 338 } | 339 } |
| OLD | NEW |