Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(229)

Side by Side Diff: lib/compiler/implementation/native_handler.dart

Issue 10830303: Refactor Library/CompilationUnit and how we define local Scope. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix reference in dart2js_mirror.dart Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 22 matching lines...) Expand all
33 cls.superclass, 33 cls.superclass,
34 () => <ClassElement>[]); 34 () => <ClassElement>[]);
35 directSubtypes.add(cls); 35 directSubtypes.add(cls);
36 } 36 }
37 37
38 void processNativeClassesInLibrary(Enqueuer world, 38 void processNativeClassesInLibrary(Enqueuer world,
39 CodeEmitterTask emitter, 39 CodeEmitterTask emitter,
40 LibraryElement library) { 40 LibraryElement library) {
41 bool hasNativeClass = false; 41 bool hasNativeClass = false;
42 final compiler = emitter.compiler; 42 final compiler = emitter.compiler;
43 for (Link<Element> link = library.topLevelElements; 43 for (Link<Element> link = library.localMembers;
44 !link.isEmpty(); link = link.tail) { 44 !link.isEmpty(); link = link.tail) {
45 Element element = link.head; 45 Element element = link.head;
46 if (element.kind == ElementKind.CLASS) { 46 if (element.kind == ElementKind.CLASS) {
47 ClassElement classElement = element; 47 ClassElement classElement = element;
48 if (classElement.isNative()) { 48 if (classElement.isNative()) {
49 hasNativeClass = true; 49 hasNativeClass = true;
50 world.registerInstantiatedClass(classElement); 50 world.registerInstantiatedClass(classElement);
51 // Also parse the node to know all its methods because 51 // Also parse the node to know all its methods because
52 // otherwise it will only be parsed if there is a call to 52 // otherwise it will only be parsed if there is a call to
53 // one of its constructor. 53 // one of its constructor.
(...skipping 16 matching lines...) Expand all
70 const SourceString('defineProperty'))); 70 const SourceString('defineProperty')));
71 world.registerStaticUse(compiler.findHelper( 71 world.registerStaticUse(compiler.findHelper(
72 const SourceString('toStringForNativeObject'))); 72 const SourceString('toStringForNativeObject')));
73 } 73 }
74 } 74 }
75 75
76 void maybeEnableNative(Compiler compiler, 76 void maybeEnableNative(Compiler compiler,
77 LibraryElement library, 77 LibraryElement library,
78 Uri uri) { 78 Uri uri) {
79 String libraryName = uri.toString(); 79 String libraryName = uri.toString();
80 if (library.script.name.contains('dart/tests/compiler/dart2js_native') 80 if (library.entryCompilationUnit.script.name.contains(
81 'dart/tests/compiler/dart2js_native')
81 || libraryName == 'dart:dom_deprecated' 82 || libraryName == 'dart:dom_deprecated'
82 || libraryName == 'dart:isolate' 83 || libraryName == 'dart:isolate'
83 || libraryName == 'dart:html') { 84 || libraryName == 'dart:html') {
84 library.canUseNative = true; 85 library.canUseNative = true;
85 library.define(compiler.findHelper(const SourceString('JS')), compiler); 86 library.addToScope(compiler.findHelper(const SourceString('JS')), compiler);
86 if (compiler.jsIndexingBehaviorInterface !== null) { 87 if (compiler.jsIndexingBehaviorInterface !== null) {
87 library.define(compiler.jsIndexingBehaviorInterface, compiler); 88 library.addToScope(compiler.jsIndexingBehaviorInterface, compiler);
88 } 89 }
89 } 90 }
90 } 91 }
91 92
92 void checkAllowedLibrary(ElementListener listener, Token token) { 93 void checkAllowedLibrary(ElementListener listener, Token token) {
93 LibraryElement currentLibrary = listener.compilationUnitElement.getLibrary(); 94 LibraryElement currentLibrary = listener.compilationUnitElement.getLibrary();
94 if (!currentLibrary.canUseNative) { 95 if (!currentLibrary.canUseNative) {
95 listener.recoverableError("Unexpected token", token: token); 96 listener.recoverableError("Unexpected token", token: token);
96 } 97 }
97 } 98 }
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 String parameters) { 331 String parameters) {
331 buffer.add(" if (Object.getPrototypeOf(this).hasOwnProperty"); 332 buffer.add(" if (Object.getPrototypeOf(this).hasOwnProperty");
332 buffer.add("('$methodName')) {\n"); 333 buffer.add("('$methodName')) {\n");
333 buffer.add(" $code"); 334 buffer.add(" $code");
334 buffer.add(" } else {\n"); 335 buffer.add(" } else {\n");
335 buffer.add(" return Object.prototype.$methodName.call(this"); 336 buffer.add(" return Object.prototype.$methodName.call(this");
336 buffer.add(parameters == '' ? '' : ', $parameters'); 337 buffer.add(parameters == '' ? '' : ', $parameters');
337 buffer.add(");\n"); 338 buffer.add(");\n");
338 buffer.add(" }\n"); 339 buffer.add(" }\n");
339 } 340 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698