OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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_emitter.lazy_emitter.model_emitter; | 5 library dart2js.js_emitter.lazy_emitter.model_emitter; |
6 | 6 |
7 import 'package:js_runtime/shared/embedded_names.dart' | 7 import 'package:js_runtime/shared/embedded_names.dart' |
8 show | 8 show |
9 CREATE_NEW_ISOLATE, | 9 CREATE_NEW_ISOLATE, |
10 DEFERRED_LIBRARY_URIS, | 10 DEFERRED_LIBRARY_URIS, |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 | 431 |
432 js.Expression isHunkInitializedFunction = | 432 js.Expression isHunkInitializedFunction = |
433 js.js("function(hash) { return false; }"); | 433 js.js("function(hash) { return false; }"); |
434 globals.add(new js.Property( | 434 globals.add(new js.Property( |
435 js.string(IS_HUNK_INITIALIZED), isHunkInitializedFunction)); | 435 js.string(IS_HUNK_INITIALIZED), isHunkInitializedFunction)); |
436 | 436 |
437 js.Expression typesAccess = generateEmbeddedGlobalAccess(TYPES); | 437 js.Expression typesAccess = generateEmbeddedGlobalAccess(TYPES); |
438 | 438 |
439 /// See [emitEmbeddedGlobalsForDeferredLoading] for the format of the | 439 /// See [emitEmbeddedGlobalsForDeferredLoading] for the format of the |
440 /// deferred hunk. | 440 /// deferred hunk. |
441 js.Expression initializeLoadedHunkFunction = js.js( | 441 js.Expression initializeLoadedHunkFunction = js.js(""" |
442 """ | |
443 function(hash) { | 442 function(hash) { |
444 var hunk = $deferredInitializersGlobal[hash]; | 443 var hunk = $deferredInitializersGlobal[hash]; |
445 $setupProgramName(hunk[0], #typesAccess.length); | 444 $setupProgramName(hunk[0], #typesAccess.length); |
446 eval(hunk[1]); | 445 eval(hunk[1]); |
447 var deferredTypes = eval(hunk[2]); | 446 var deferredTypes = eval(hunk[2]); |
448 #typesAccess.push.apply(#typesAccess, deferredTypes); | 447 #typesAccess.push.apply(#typesAccess, deferredTypes); |
449 }""", | 448 }""", {'typesAccess': typesAccess}); |
450 {'typesAccess': typesAccess}); | |
451 | 449 |
452 globals.add(new js.Property( | 450 globals.add(new js.Property( |
453 js.string(INITIALIZE_LOADED_HUNK), initializeLoadedHunkFunction)); | 451 js.string(INITIALIZE_LOADED_HUNK), initializeLoadedHunkFunction)); |
454 | 452 |
455 return globals; | 453 return globals; |
456 } | 454 } |
457 | 455 |
458 js.Property emitGetTypeFromName() { | 456 js.Property emitGetTypeFromName() { |
459 js.Expression function = js.js("""function(name) { | 457 js.Expression function = js.js("""function(name) { |
460 return holdersMap[name][name].ensureResolved(); | 458 return holdersMap[name][name].ensureResolved(); |
461 }"""); | 459 }"""); |
462 return new js.Property(js.string(GET_TYPE_FROM_NAME), function); | 460 return new js.Property(js.string(GET_TYPE_FROM_NAME), function); |
463 } | 461 } |
464 | 462 |
465 static final String readMetadataTypeName = "readMetadataType"; | 463 static final String readMetadataTypeName = "readMetadataType"; |
466 | 464 |
467 js.Statement get readMetadataTypeFunction { | 465 js.Statement get readMetadataTypeFunction { |
468 // Types are non-evaluated and must be compiled at first use. | 466 // Types are non-evaluated and must be compiled at first use. |
469 // Compiled strings are guaranteed not to be strings, and it's thus safe | 467 // Compiled strings are guaranteed not to be strings, and it's thus safe |
470 // to use a type-test to determine if a type has already been compiled. | 468 // to use a type-test to determine if a type has already been compiled. |
471 return js.js.statement( | 469 return js.js.statement('''function $readMetadataTypeName(index) { |
472 '''function $readMetadataTypeName(index) { | |
473 var type = #typesAccess[index]; | 470 var type = #typesAccess[index]; |
474 if (typeof type == 'string') { | 471 if (typeof type == 'string') { |
475 type = expressionCompile(type); | 472 type = expressionCompile(type); |
476 #typesAccess[index] = type; | 473 #typesAccess[index] = type; |
477 } | 474 } |
478 return type; | 475 return type; |
479 }''', | 476 }''', {"typesAccess": generateEmbeddedGlobalAccess(TYPES)}); |
480 {"typesAccess": generateEmbeddedGlobalAccess(TYPES)}); | |
481 } | 477 } |
482 | 478 |
483 js.Template get templateForReadType { | 479 js.Template get templateForReadType { |
484 // TODO(floitsch): make sure that no local variable shadows the access to | 480 // TODO(floitsch): make sure that no local variable shadows the access to |
485 // the readMetadataType function. | 481 // the readMetadataType function. |
486 return js.js.expressionTemplateFor('$readMetadataTypeName(#)'); | 482 return js.js.expressionTemplateFor('$readMetadataTypeName(#)'); |
487 } | 483 } |
488 | 484 |
489 static final String readMetadataName = "readLazyMetadata"; | 485 static final String readMetadataName = "readLazyMetadata"; |
490 static final String lazyMetadataName = "lazy_$METADATA"; | 486 static final String lazyMetadataName = "lazy_$METADATA"; |
491 | 487 |
492 js.Statement get readMetadataFunction { | 488 js.Statement get readMetadataFunction { |
493 // Types are non-evaluated and must be compiled at first use. | 489 // Types are non-evaluated and must be compiled at first use. |
494 // Compiled strings are guaranteed not to be strings, and it's thus safe | 490 // Compiled strings are guaranteed not to be strings, and it's thus safe |
495 // to use a type-test to determine if a type has already been compiled. | 491 // to use a type-test to determine if a type has already been compiled. |
496 return js.js.statement( | 492 return js.js.statement('''function $readMetadataName(index) { |
497 '''function $readMetadataName(index) { | |
498 var lazyMetadata = #lazyMetadataAccess[index]; | 493 var lazyMetadata = #lazyMetadataAccess[index]; |
499 if (typeof lazyMetadata == 'string') { | 494 if (typeof lazyMetadata == 'string') { |
500 #metadataAccess[index] = expressionCompile(lazyMetadata); | 495 #metadataAccess[index] = expressionCompile(lazyMetadata); |
501 #lazyMetadataAccess[index] = null; | 496 #lazyMetadataAccess[index] = null; |
502 } | 497 } |
503 return #metadataAccess[index]; | 498 return #metadataAccess[index]; |
504 }''', | 499 }''', { |
505 { | 500 "lazyMetadataAccess": generateEmbeddedGlobalAccess(lazyMetadataName), |
506 "lazyMetadataAccess": generateEmbeddedGlobalAccess(lazyMetadataName), | 501 "metadataAccess": generateEmbeddedGlobalAccess(METADATA) |
507 "metadataAccess": generateEmbeddedGlobalAccess(METADATA) | 502 }); |
508 }); | |
509 } | 503 } |
510 | 504 |
511 js.Template get templateForReadMetadata { | 505 js.Template get templateForReadMetadata { |
512 // TODO(floitsch): make sure that no local variable shadows the access to | 506 // TODO(floitsch): make sure that no local variable shadows the access to |
513 // the readMetadata function. | 507 // the readMetadata function. |
514 return js.js.expressionTemplateFor('$readMetadataName(#)'); | 508 return js.js.expressionTemplateFor('$readMetadataName(#)'); |
515 } | 509 } |
516 | 510 |
517 List<js.Property> emitMetadata(Program program) { | 511 List<js.Property> emitMetadata(Program program) { |
518 List<js.Property> metadataGlobals = <js.Property>[]; | 512 List<js.Property> metadataGlobals = <js.Property>[]; |
(...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1288 #eagerClasses; | 1282 #eagerClasses; |
1289 | 1283 |
1290 var end = Date.now(); | 1284 var end = Date.now(); |
1291 // print('Setup: ' + (end - start) + ' ms.'); | 1285 // print('Setup: ' + (end - start) + ' ms.'); |
1292 | 1286 |
1293 #invokeMain; // Start main. | 1287 #invokeMain; // Start main. |
1294 | 1288 |
1295 })(Date.now(), #code) | 1289 })(Date.now(), #code) |
1296 }"""; | 1290 }"""; |
1297 } | 1291 } |
OLD | NEW |