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 part of dart2js; | 5 part of dart2js; |
6 | 6 |
7 /** | 7 /** |
8 * If true, print a warning for each method that was resolved, but not | 8 * If true, print a warning for each method that was resolved, but not |
9 * compiled. | 9 * compiled. |
10 */ | 10 */ |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 ClassElement dynamicClass; | 121 ClassElement dynamicClass; |
122 ClassElement boolClass; | 122 ClassElement boolClass; |
123 ClassElement numClass; | 123 ClassElement numClass; |
124 ClassElement intClass; | 124 ClassElement intClass; |
125 ClassElement doubleClass; | 125 ClassElement doubleClass; |
126 ClassElement stringClass; | 126 ClassElement stringClass; |
127 ClassElement functionClass; | 127 ClassElement functionClass; |
128 ClassElement nullClass; | 128 ClassElement nullClass; |
129 ClassElement listClass; | 129 ClassElement listClass; |
130 ClassElement mapClass; | 130 ClassElement mapClass; |
| 131 ClassElement jsInvocationMirrorClass; |
131 Element assertMethod; | 132 Element assertMethod; |
132 Element identicalFunction; | 133 Element identicalFunction; |
133 Element functionApplyMethod; | 134 Element functionApplyMethod; |
| 135 Element invokeOnMethod; |
134 | 136 |
135 Element get currentElement => _currentElement; | 137 Element get currentElement => _currentElement; |
136 withCurrentElement(Element element, f()) { | 138 withCurrentElement(Element element, f()) { |
137 Element old = currentElement; | 139 Element old = currentElement; |
138 _currentElement = element; | 140 _currentElement = element; |
139 try { | 141 try { |
140 return f(); | 142 return f(); |
141 } on SpannableAssertionFailure catch (ex) { | 143 } on SpannableAssertionFailure catch (ex) { |
142 if (!hasCrashed) { | 144 if (!hasCrashed) { |
143 SourceSpan span = spanFromSpannable(ex.node); | 145 SourceSpan span = spanFromSpannable(ex.node); |
(...skipping 30 matching lines...) Expand all Loading... |
174 closureMapping.ClosureTask closureToClassMapper; | 176 closureMapping.ClosureTask closureToClassMapper; |
175 TypeCheckerTask checker; | 177 TypeCheckerTask checker; |
176 ti.TypesTask typesTask; | 178 ti.TypesTask typesTask; |
177 Backend backend; | 179 Backend backend; |
178 ConstantHandler constantHandler; | 180 ConstantHandler constantHandler; |
179 EnqueueTask enqueuer; | 181 EnqueueTask enqueuer; |
180 | 182 |
181 static const SourceString MAIN = const SourceString('main'); | 183 static const SourceString MAIN = const SourceString('main'); |
182 static const SourceString CALL_OPERATOR_NAME = const SourceString('call'); | 184 static const SourceString CALL_OPERATOR_NAME = const SourceString('call'); |
183 static const SourceString NO_SUCH_METHOD = const SourceString('noSuchMethod'); | 185 static const SourceString NO_SUCH_METHOD = const SourceString('noSuchMethod'); |
| 186 static const int NO_SUCH_METHOD_ARG_COUNT = 1; |
| 187 static const SourceString INVOKE_ON = const SourceString('invokeOn'); |
184 static const SourceString RUNTIME_TYPE = const SourceString('runtimeType'); | 188 static const SourceString RUNTIME_TYPE = const SourceString('runtimeType'); |
185 static const SourceString START_ROOT_ISOLATE = | 189 static const SourceString START_ROOT_ISOLATE = |
186 const SourceString('startRootIsolate'); | 190 const SourceString('startRootIsolate'); |
187 bool enabledNoSuchMethod = false; | 191 bool enabledNoSuchMethod = false; |
188 bool enabledRuntimeType = false; | 192 bool enabledRuntimeType = false; |
189 bool enabledFunctionApply = false; | 193 bool enabledFunctionApply = false; |
| 194 bool enabledInvokeOn = false; |
190 | 195 |
191 Stopwatch progress; | 196 Stopwatch progress; |
192 | 197 |
193 static const int PHASE_SCANNING = 0; | 198 static const int PHASE_SCANNING = 0; |
194 static const int PHASE_RESOLVING = 1; | 199 static const int PHASE_RESOLVING = 1; |
195 static const int PHASE_COMPILING = 2; | 200 static const int PHASE_COMPILING = 2; |
196 int phase; | 201 int phase; |
197 | 202 |
198 bool compilationFailed = false; | 203 bool compilationFailed = false; |
199 | 204 |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 // TODO(ahe): Move this method to Enqueuer. | 341 // TODO(ahe): Move this method to Enqueuer. |
337 if (enabledNoSuchMethod) return; | 342 if (enabledNoSuchMethod) return; |
338 if (identical(element.getEnclosingClass(), objectClass)) { | 343 if (identical(element.getEnclosingClass(), objectClass)) { |
339 enqueuer.resolution.registerDynamicInvocationOf(element); | 344 enqueuer.resolution.registerDynamicInvocationOf(element); |
340 return; | 345 return; |
341 } | 346 } |
342 enabledNoSuchMethod = true; | 347 enabledNoSuchMethod = true; |
343 Selector selector = new Selector.noSuchMethod(); | 348 Selector selector = new Selector.noSuchMethod(); |
344 enqueuer.resolution.registerInvocation(NO_SUCH_METHOD, selector); | 349 enqueuer.resolution.registerInvocation(NO_SUCH_METHOD, selector); |
345 enqueuer.codegen.registerInvocation(NO_SUCH_METHOD, selector); | 350 enqueuer.codegen.registerInvocation(NO_SUCH_METHOD, selector); |
| 351 |
| 352 Element createInvocationMirrorElement = |
| 353 findHelper(const SourceString('createInvocationMirror')); |
| 354 enqueuer.resolution.addToWorkList(createInvocationMirrorElement); |
| 355 enqueuer.codegen.addToWorkList(createInvocationMirrorElement); |
346 } | 356 } |
347 | 357 |
348 void enableIsolateSupport(LibraryElement element) { | 358 void enableIsolateSupport(LibraryElement element) { |
349 // TODO(ahe): Move this method to Enqueuer. | 359 // TODO(ahe): Move this method to Enqueuer. |
350 isolateLibrary = element.patch; | 360 isolateLibrary = element.patch; |
351 enqueuer.resolution.addToWorkList(isolateLibrary.find(START_ROOT_ISOLATE)); | 361 enqueuer.resolution.addToWorkList(isolateLibrary.find(START_ROOT_ISOLATE)); |
352 enqueuer.resolution.addToWorkList( | 362 enqueuer.resolution.addToWorkList( |
353 isolateLibrary.find(const SourceString('_currentIsolate'))); | 363 isolateLibrary.find(const SourceString('_currentIsolate'))); |
354 enqueuer.resolution.addToWorkList( | 364 enqueuer.resolution.addToWorkList( |
355 isolateLibrary.find(const SourceString('_callInIsolate'))); | 365 isolateLibrary.find(const SourceString('_callInIsolate'))); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 } | 397 } |
388 objectClass = lookupSpecialClass(const SourceString('Object')); | 398 objectClass = lookupSpecialClass(const SourceString('Object')); |
389 boolClass = lookupSpecialClass(const SourceString('bool')); | 399 boolClass = lookupSpecialClass(const SourceString('bool')); |
390 numClass = lookupSpecialClass(const SourceString('num')); | 400 numClass = lookupSpecialClass(const SourceString('num')); |
391 intClass = lookupSpecialClass(const SourceString('int')); | 401 intClass = lookupSpecialClass(const SourceString('int')); |
392 doubleClass = lookupSpecialClass(const SourceString('double')); | 402 doubleClass = lookupSpecialClass(const SourceString('double')); |
393 stringClass = lookupSpecialClass(const SourceString('String')); | 403 stringClass = lookupSpecialClass(const SourceString('String')); |
394 functionClass = lookupSpecialClass(const SourceString('Function')); | 404 functionClass = lookupSpecialClass(const SourceString('Function')); |
395 listClass = lookupSpecialClass(const SourceString('List')); | 405 listClass = lookupSpecialClass(const SourceString('List')); |
396 mapClass = lookupSpecialClass(const SourceString('Map')); | 406 mapClass = lookupSpecialClass(const SourceString('Map')); |
| 407 jsInvocationMirrorClass = |
| 408 lookupSpecialClass(const SourceString('JSInvocationMirror')); |
397 closureClass = lookupSpecialClass(const SourceString('Closure')); | 409 closureClass = lookupSpecialClass(const SourceString('Closure')); |
398 dynamicClass = lookupSpecialClass(const SourceString('Dynamic_')); | 410 dynamicClass = lookupSpecialClass(const SourceString('Dynamic_')); |
399 nullClass = lookupSpecialClass(const SourceString('Null')); | 411 nullClass = lookupSpecialClass(const SourceString('Null')); |
400 types = new Types(this, dynamicClass); | 412 types = new Types(this, dynamicClass); |
401 if (!coreLibValid) { | 413 if (!coreLibValid) { |
402 cancel('core library does not contain required classes'); | 414 cancel('core library does not contain required classes'); |
403 } | 415 } |
404 } | 416 } |
405 | 417 |
406 void scanBuiltinLibraries() { | 418 void scanBuiltinLibraries() { |
(...skipping 12 matching lines...) Expand all Loading... |
419 addForeignFunctions(interceptorsLibrary); | 431 addForeignFunctions(interceptorsLibrary); |
420 | 432 |
421 assertMethod = jsHelperLibrary.find(const SourceString('assertHelper')); | 433 assertMethod = jsHelperLibrary.find(const SourceString('assertHelper')); |
422 identicalFunction = coreLibrary.find(const SourceString('identical')); | 434 identicalFunction = coreLibrary.find(const SourceString('identical')); |
423 | 435 |
424 initializeSpecialClasses(); | 436 initializeSpecialClasses(); |
425 | 437 |
426 functionClass.ensureResolved(this); | 438 functionClass.ensureResolved(this); |
427 functionApplyMethod = | 439 functionApplyMethod = |
428 functionClass.lookupLocalMember(const SourceString('apply')); | 440 functionClass.lookupLocalMember(const SourceString('apply')); |
| 441 jsInvocationMirrorClass.ensureResolved(this); |
| 442 invokeOnMethod = jsInvocationMirrorClass.lookupLocalMember( |
| 443 const SourceString('invokeOn')); |
429 } | 444 } |
430 | 445 |
431 void loadCoreImplLibrary() { | 446 void loadCoreImplLibrary() { |
432 Uri coreImplUri = new Uri.fromComponents(scheme: 'dart', path: 'coreimpl'); | 447 Uri coreImplUri = new Uri.fromComponents(scheme: 'dart', path: 'coreimpl'); |
433 coreImplLibrary = libraryLoader.loadLibrary(coreImplUri, null, coreImplUri); | 448 coreImplLibrary = libraryLoader.loadLibrary(coreImplUri, null, coreImplUri); |
434 } | 449 } |
435 | 450 |
436 void importHelperLibrary(LibraryElement library) { | 451 void importHelperLibrary(LibraryElement library) { |
437 if (jsHelperLibrary != null) { | 452 if (jsHelperLibrary != null) { |
438 libraryLoader.importLibrary(library, jsHelperLibrary, null); | 453 libraryLoader.importLibrary(library, jsHelperLibrary, null); |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
891 // TODO(johnniwinther): Use [spannable] and [message] to provide better | 906 // TODO(johnniwinther): Use [spannable] and [message] to provide better |
892 // information on assertion errors. | 907 // information on assertion errors. |
893 if (condition is Function){ | 908 if (condition is Function){ |
894 condition = condition(); | 909 condition = condition(); |
895 } | 910 } |
896 if (spannable == null || !condition) { | 911 if (spannable == null || !condition) { |
897 throw new SpannableAssertionFailure(spannable, message); | 912 throw new SpannableAssertionFailure(spannable, message); |
898 } | 913 } |
899 return true; | 914 return true; |
900 } | 915 } |
OLD | NEW |