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

Side by Side Diff: pkg/compiler/lib/src/js_backend/backend_helpers.dart

Issue 1859343004: dartfmt pkg/compiler (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 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
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 dart2js.js_backend.helpers; 5 library dart2js.js_backend.helpers;
6 6
7 import '../common.dart'; 7 import '../common.dart';
8 import '../common/names.dart' show 8 import '../common/names.dart' show Identifiers, Uris;
9 Identifiers, 9 import '../common/resolution.dart' show Resolution;
10 Uris; 10 import '../compiler.dart' show Compiler;
11 import '../common/resolution.dart' show 11 import '../core_types.dart' show CoreClasses;
12 Resolution; 12 import '../elements/elements.dart'
13 import '../compiler.dart' show 13 show
14 Compiler; 14 AbstractFieldElement,
15 import '../core_types.dart' show 15 ClassElement,
16 CoreClasses; 16 ConstructorElement,
17 import '../elements/elements.dart' show 17 Element,
18 AbstractFieldElement, 18 EnumClassElement,
19 ClassElement, 19 FunctionElement,
20 ConstructorElement, 20 LibraryElement,
21 Element, 21 MethodElement;
22 EnumClassElement, 22 import '../library_loader.dart' show LoadedLibraries;
23 FunctionElement,
24 LibraryElement,
25 MethodElement;
26 import '../library_loader.dart' show
27 LoadedLibraries;
28 23
29 import 'js_backend.dart'; 24 import 'js_backend.dart';
30 25
31 /// Helper classes and functions for the JavaScript backend. 26 /// Helper classes and functions for the JavaScript backend.
32 class BackendHelpers { 27 class BackendHelpers {
33 static final Uri DART_JS_HELPER = new Uri(scheme: 'dart', path: '_js_helper'); 28 static final Uri DART_JS_HELPER = new Uri(scheme: 'dart', path: '_js_helper');
34 static final Uri DART_INTERCEPTORS = 29 static final Uri DART_INTERCEPTORS =
35 new Uri(scheme: 'dart', path: '_interceptors'); 30 new Uri(scheme: 'dart', path: '_interceptors');
36 static final Uri DART_FOREIGN_HELPER = 31 static final Uri DART_FOREIGN_HELPER =
37 new Uri(scheme: 'dart', path: '_foreign_helper'); 32 new Uri(scheme: 'dart', path: '_foreign_helper');
38 static final Uri DART_JS_MIRRORS = 33 static final Uri DART_JS_MIRRORS =
39 new Uri(scheme: 'dart', path: '_js_mirrors'); 34 new Uri(scheme: 'dart', path: '_js_mirrors');
40 static final Uri DART_JS_NAMES = 35 static final Uri DART_JS_NAMES = new Uri(scheme: 'dart', path: '_js_names');
41 new Uri(scheme: 'dart', path: '_js_names');
42 static final Uri DART_EMBEDDED_NAMES = 36 static final Uri DART_EMBEDDED_NAMES =
43 new Uri(scheme: 'dart', path: '_js_embedded_names'); 37 new Uri(scheme: 'dart', path: '_js_embedded_names');
44 static final Uri DART_ISOLATE_HELPER = 38 static final Uri DART_ISOLATE_HELPER =
45 new Uri(scheme: 'dart', path: '_isolate_helper'); 39 new Uri(scheme: 'dart', path: '_isolate_helper');
46 static final Uri PACKAGE_JS = 40 static final Uri PACKAGE_JS = new Uri(scheme: 'package', path: 'js/js.dart');
47 new Uri(scheme: 'package', path: 'js/js.dart');
48 41
49 static const String INVOKE_ON = '_getCachedInvocation'; 42 static const String INVOKE_ON = '_getCachedInvocation';
50 static const String START_ROOT_ISOLATE = 'startRootIsolate'; 43 static const String START_ROOT_ISOLATE = 'startRootIsolate';
51 44
52 final Compiler compiler; 45 final Compiler compiler;
53 46
54 Element cachedCheckConcurrentModificationError; 47 Element cachedCheckConcurrentModificationError;
55 48
56 BackendHelpers(this.compiler); 49 BackendHelpers(this.compiler);
57 50
58 JavaScriptBackend get backend => compiler.backend; 51 JavaScriptBackend get backend => compiler.backend;
59 52
60 Resolution get resolution => backend.resolution; 53 Resolution get resolution => backend.resolution;
61 54
62 CoreClasses get coreClasses => compiler.coreClasses; 55 CoreClasses get coreClasses => compiler.coreClasses;
63 56
64 DiagnosticReporter get reporter => compiler.reporter; 57 DiagnosticReporter get reporter => compiler.reporter;
65 58
66 MethodElement assertTest; 59 MethodElement assertTest;
67 MethodElement assertThrow; 60 MethodElement assertThrow;
68 MethodElement assertHelper; 61 MethodElement assertHelper;
69 62
70
71 LibraryElement jsHelperLibrary; 63 LibraryElement jsHelperLibrary;
72 LibraryElement asyncLibrary; 64 LibraryElement asyncLibrary;
73 LibraryElement interceptorsLibrary; 65 LibraryElement interceptorsLibrary;
74 LibraryElement foreignLibrary; 66 LibraryElement foreignLibrary;
75 LibraryElement isolateHelperLibrary; 67 LibraryElement isolateHelperLibrary;
76 68
77 /// Reference to the internal library to lookup functions to always inline. 69 /// Reference to the internal library to lookup functions to always inline.
78 LibraryElement internalLibrary; 70 LibraryElement internalLibrary;
79 71
80 ClassElement closureClass; 72 ClassElement closureClass;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 } 188 }
197 189
198 void onLibraryCreated(LibraryElement library) { 190 void onLibraryCreated(LibraryElement library) {
199 Uri uri = library.canonicalUri; 191 Uri uri = library.canonicalUri;
200 if (uri == DART_JS_HELPER) { 192 if (uri == DART_JS_HELPER) {
201 jsHelperLibrary = library; 193 jsHelperLibrary = library;
202 } else if (uri == Uris.dart_async) { 194 } else if (uri == Uris.dart_async) {
203 asyncLibrary = library; 195 asyncLibrary = library;
204 } else if (uri == Uris.dart__internal) { 196 } else if (uri == Uris.dart__internal) {
205 internalLibrary = library; 197 internalLibrary = library;
206 } else if (uri == DART_INTERCEPTORS) { 198 } else if (uri == DART_INTERCEPTORS) {
207 interceptorsLibrary = library; 199 interceptorsLibrary = library;
208 } else if (uri == DART_FOREIGN_HELPER) { 200 } else if (uri == DART_FOREIGN_HELPER) {
209 foreignLibrary = library; 201 foreignLibrary = library;
210 } else if (uri == DART_ISOLATE_HELPER) { 202 } else if (uri == DART_ISOLATE_HELPER) {
211 isolateHelperLibrary = library; 203 isolateHelperLibrary = library;
212 } 204 }
213 } 205 }
214 206
215 void initializeHelperClasses(DiagnosticReporter reporter) { 207 void initializeHelperClasses(DiagnosticReporter reporter) {
216 final List missingHelperClasses = []; 208 final List missingHelperClasses = [];
217 ClassElement lookupHelperClass(String name) { 209 ClassElement lookupHelperClass(String name) {
218 ClassElement result = findHelper(name); 210 ClassElement result = findHelper(name);
219 if (result == null) { 211 if (result == null) {
220 missingHelperClasses.add(name); 212 missingHelperClasses.add(name);
221 } 213 }
222 return result; 214 return result;
223 } 215 }
224 jsInvocationMirrorClass = lookupHelperClass('JSInvocationMirror'); 216 jsInvocationMirrorClass = lookupHelperClass('JSInvocationMirror');
225 boundClosureClass = lookupHelperClass('BoundClosure'); 217 boundClosureClass = lookupHelperClass('BoundClosure');
226 closureClass = lookupHelperClass('Closure'); 218 closureClass = lookupHelperClass('Closure');
227 if (!missingHelperClasses.isEmpty) { 219 if (!missingHelperClasses.isEmpty) {
228 reporter.internalError(jsHelperLibrary, 220 reporter.internalError(
221 jsHelperLibrary,
229 'dart:_js_helper library does not contain required classes: ' 222 'dart:_js_helper library does not contain required classes: '
230 '$missingHelperClasses'); 223 '$missingHelperClasses');
231 } 224 }
232 } 225 }
233 226
234 void onLibraryScanned(LibraryElement library) { 227 void onLibraryScanned(LibraryElement library) {
235 Uri uri = library.canonicalUri; 228 Uri uri = library.canonicalUri;
236 229
237 FunctionElement findMethod(String name) { 230 FunctionElement findMethod(String name) {
238 return find(library, name); 231 return find(library, name);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 jsBuiltinEnum = find(library, 'JsBuiltin'); 295 jsBuiltinEnum = find(library, 'JsBuiltin');
303 } else if (uri == Uris.dart__native_typed_data) { 296 } else if (uri == Uris.dart__native_typed_data) {
304 typedArrayClass = findClass('NativeTypedArray'); 297 typedArrayClass = findClass('NativeTypedArray');
305 typedArrayOfIntClass = findClass('NativeTypedArrayOfInt'); 298 typedArrayOfIntClass = findClass('NativeTypedArrayOfInt');
306 } else if (uri == PACKAGE_JS) { 299 } else if (uri == PACKAGE_JS) {
307 jsAnnotationClass = find(library, 'JS'); 300 jsAnnotationClass = find(library, 'JS');
308 jsAnonymousClass = find(library, '_Anonymous'); 301 jsAnonymousClass = find(library, '_Anonymous');
309 } 302 }
310 } 303 }
311 304
312
313 void onLibrariesLoaded(LoadedLibraries loadedLibraries) { 305 void onLibrariesLoaded(LoadedLibraries loadedLibraries) {
314 assert(loadedLibraries.containsLibrary(Uris.dart_core)); 306 assert(loadedLibraries.containsLibrary(Uris.dart_core));
315 assert(loadedLibraries.containsLibrary(DART_INTERCEPTORS)); 307 assert(loadedLibraries.containsLibrary(DART_INTERCEPTORS));
316 assert(loadedLibraries.containsLibrary(DART_JS_HELPER)); 308 assert(loadedLibraries.containsLibrary(DART_JS_HELPER));
317 309
318 if (jsInvocationMirrorClass != null) { 310 if (jsInvocationMirrorClass != null) {
319 jsInvocationMirrorClass.ensureResolved(resolution); 311 jsInvocationMirrorClass.ensureResolved(resolution);
320 invokeOnMethod = jsInvocationMirrorClass.lookupLocalMember(INVOKE_ON); 312 invokeOnMethod = jsInvocationMirrorClass.lookupLocalMember(INVOKE_ON);
321 } 313 }
322 314
(...skipping 10 matching lines...) Expand all
333 jsFixedArrayClass.ensureResolved(resolution); 325 jsFixedArrayClass.ensureResolved(resolution);
334 } 326 }
335 if (jsExtendableArrayClass != null) { 327 if (jsExtendableArrayClass != null) {
336 jsExtendableArrayClass.ensureResolved(resolution); 328 jsExtendableArrayClass.ensureResolved(resolution);
337 } 329 }
338 if (jsUnmodifiableArrayClass != null) { 330 if (jsUnmodifiableArrayClass != null) {
339 jsUnmodifiableArrayClass.ensureResolved(resolution); 331 jsUnmodifiableArrayClass.ensureResolved(resolution);
340 } 332 }
341 333
342 jsIndexableClass.ensureResolved(resolution); 334 jsIndexableClass.ensureResolved(resolution);
343 jsIndexableLength = compiler.lookupElementIn( 335 jsIndexableLength = compiler.lookupElementIn(jsIndexableClass, 'length');
344 jsIndexableClass, 'length');
345 if (jsIndexableLength != null && jsIndexableLength.isAbstractField) { 336 if (jsIndexableLength != null && jsIndexableLength.isAbstractField) {
346 AbstractFieldElement element = jsIndexableLength; 337 AbstractFieldElement element = jsIndexableLength;
347 jsIndexableLength = element.getter; 338 jsIndexableLength = element.getter;
348 } 339 }
349 340
350 jsArrayClass.ensureResolved(resolution); 341 jsArrayClass.ensureResolved(resolution);
351 jsArrayTypedConstructor = compiler.lookupElementIn(jsArrayClass, 'typed'); 342 jsArrayTypedConstructor = compiler.lookupElementIn(jsArrayClass, 'typed');
352 jsArrayRemoveLast = compiler.lookupElementIn(jsArrayClass, 'removeLast'); 343 jsArrayRemoveLast = compiler.lookupElementIn(jsArrayClass, 'removeLast');
353 jsArrayAdd = compiler.lookupElementIn(jsArrayClass, 'add'); 344 jsArrayAdd = compiler.lookupElementIn(jsArrayClass, 'add');
354 345
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 } 380 }
390 381
391 FunctionElement get closureFromTearOff { 382 FunctionElement get closureFromTearOff {
392 return findHelper('closureFromTearOff'); 383 return findHelper('closureFromTearOff');
393 } 384 }
394 385
395 Element get isJsIndexable { 386 Element get isJsIndexable {
396 return findHelper('isJsIndexable'); 387 return findHelper('isJsIndexable');
397 } 388 }
398 389
399
400 Element get throwIllegalArgumentException { 390 Element get throwIllegalArgumentException {
401 return findHelper('iae'); 391 return findHelper('iae');
402 } 392 }
403 393
404 Element get throwIndexOutOfRangeException { 394 Element get throwIndexOutOfRangeException {
405 return findHelper('ioore'); 395 return findHelper('ioore');
406 } 396 }
407 397
408 Element get exceptionUnwrapper { 398 Element get exceptionUnwrapper {
409 return findHelper('unwrapException'); 399 return findHelper('unwrapException');
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 return classElement.lookupConstructor(""); 591 return classElement.lookupConstructor("");
602 } 592 }
603 593
604 Element get syncCompleterConstructor { 594 Element get syncCompleterConstructor {
605 ClassElement classElement = find(compiler.asyncLibrary, "Completer"); 595 ClassElement classElement = find(compiler.asyncLibrary, "Completer");
606 classElement.ensureResolved(resolution); 596 classElement.ensureResolved(resolution);
607 return classElement.lookupConstructor("sync"); 597 return classElement.lookupConstructor("sync");
608 } 598 }
609 599
610 Element get asyncStarController { 600 Element get asyncStarController {
611 ClassElement classElement = 601 ClassElement classElement = findAsyncHelper("_AsyncStarStreamController");
612 findAsyncHelper("_AsyncStarStreamController");
613 classElement.ensureResolved(resolution); 602 classElement.ensureResolved(resolution);
614 return classElement; 603 return classElement;
615 } 604 }
616 605
617 Element get asyncStarControllerConstructor { 606 Element get asyncStarControllerConstructor {
618 ClassElement classElement = asyncStarController; 607 ClassElement classElement = asyncStarController;
619 return classElement.lookupConstructor(""); 608 return classElement.lookupConstructor("");
620 } 609 }
621 610
622 Element get streamIteratorConstructor { 611 Element get streamIteratorConstructor {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 MethodElement _objectNoSuchMethod; 673 MethodElement _objectNoSuchMethod;
685 674
686 MethodElement get objectNoSuchMethod { 675 MethodElement get objectNoSuchMethod {
687 if (_objectNoSuchMethod == null) { 676 if (_objectNoSuchMethod == null) {
688 _objectNoSuchMethod = 677 _objectNoSuchMethod =
689 coreClasses.objectClass.lookupLocalMember(Identifiers.noSuchMethod_); 678 coreClasses.objectClass.lookupLocalMember(Identifiers.noSuchMethod_);
690 } 679 }
691 return _objectNoSuchMethod; 680 return _objectNoSuchMethod;
692 } 681 }
693 } 682 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_backend/backend.dart ('k') | pkg/compiler/lib/src/js_backend/backend_impact.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698