| 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 part of dart2js.js_emitter; | 5 part of dart2js.js_emitter; |
| 6 | 6 |
| 7 | 7 |
| 8 class OldEmitter implements Emitter { | 8 class OldEmitter implements Emitter { |
| 9 final Compiler compiler; | 9 final Compiler compiler; |
| 10 final CodeEmitterTask task; | 10 final CodeEmitterTask task; |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 jsAst.Expression metadataAccess = | 343 jsAst.Expression metadataAccess = |
| 344 generateEmbeddedGlobalAccess(embeddedNames.METADATA); | 344 generateEmbeddedGlobalAccess(embeddedNames.METADATA); |
| 345 jsAst.Expression interceptorsByTagAccess = | 345 jsAst.Expression interceptorsByTagAccess = |
| 346 generateEmbeddedGlobalAccess(embeddedNames.INTERCEPTORS_BY_TAG); | 346 generateEmbeddedGlobalAccess(embeddedNames.INTERCEPTORS_BY_TAG); |
| 347 jsAst.Expression leafTagsAccess = | 347 jsAst.Expression leafTagsAccess = |
| 348 generateEmbeddedGlobalAccess(embeddedNames.LEAF_TAGS); | 348 generateEmbeddedGlobalAccess(embeddedNames.LEAF_TAGS); |
| 349 | 349 |
| 350 return js(''' | 350 return js(''' |
| 351 function(collectedClasses, isolateProperties, existingIsolateProperties) { | 351 function(collectedClasses, isolateProperties, existingIsolateProperties) { |
| 352 var pendingClasses = Object.create(null); | 352 var pendingClasses = Object.create(null); |
| 353 if (!#) # = Object.create(null); // embedded allClasses. | 353 if (!#allClasses) #allClasses = Object.create(null); |
| 354 var allClasses = #; // embedded allClasses; | 354 var allClasses = #allClasses; |
| 355 | 355 |
| 356 if (#) // DEBUG_FAST_OBJECTS | 356 if (#debugFastObjects) // DEBUG_FAST_OBJECTS |
| 357 print("Number of classes: " + | 357 print("Number of classes: " + |
| 358 Object.getOwnPropertyNames(\$\$).length); | 358 Object.getOwnPropertyNames(\$\$).length); |
| 359 | 359 |
| 360 var hasOwnProperty = Object.prototype.hasOwnProperty; | 360 var hasOwnProperty = Object.prototype.hasOwnProperty; |
| 361 | 361 |
| 362 if (typeof dart_precompiled == "function") { | 362 if (typeof dart_precompiled == "function") { |
| 363 var constructors = dart_precompiled(collectedClasses); | 363 var constructors = dart_precompiled(collectedClasses); |
| 364 } else { | 364 } else { |
| 365 var combinedConstructorFunction = | 365 var combinedConstructorFunction = |
| 366 "function \$reflectable(fn){fn.$reflectableField=1;return fn};\\n"+ | 366 "function \$reflectable(fn){fn.$reflectableField=1;return fn};\\n"+ |
| 367 "var \$desc;\\n"; | 367 "var \$desc;\\n"; |
| 368 var constructorsList = []; | 368 var constructorsList = []; |
| 369 } | 369 } |
| 370 | 370 |
| 371 for (var cls in collectedClasses) { | 371 for (var cls in collectedClasses) { |
| 372 var desc = collectedClasses[cls]; | 372 var desc = collectedClasses[cls]; |
| 373 if (desc instanceof Array) desc = desc[1]; | 373 if (desc instanceof Array) desc = desc[1]; |
| 374 | 374 |
| 375 /* The 'fields' are either a constructor function or a | 375 /* The 'fields' are either a constructor function or a |
| 376 * string encoding fields, constructor and superclass. Get | 376 * string encoding fields, constructor and superclass. Get |
| 377 * the superclass and the fields in the format | 377 * the superclass and the fields in the format |
| 378 * '[name/]Super;field1,field2' | 378 * '[name/]Super;field1,field2' |
| 379 * from the CLASS_DESCRIPTOR_PROPERTY property on the descriptor. | 379 * from the CLASS_DESCRIPTOR_PROPERTY property on the descriptor. |
| 380 * The 'name/' is optional and contains the name that should be used | 380 * The 'name/' is optional and contains the name that should be used |
| 381 * when printing the runtime type string. It is used, for example, | 381 * when printing the runtime type string. It is used, for example, |
| 382 * to print the runtime type JSInt as 'int'. | 382 * to print the runtime type JSInt as 'int'. |
| 383 */ | 383 */ |
| 384 var classData = desc["${namer.classDescriptorProperty}"], | 384 var classData = desc["${namer.classDescriptorProperty}"], |
| 385 supr, name = cls, fields = classData; | 385 supr, name = cls, fields = classData; |
| 386 if (#) // backend.hasRetainedMetadata | 386 if (#hasRetainedMetadata) |
| 387 if (typeof classData == "object" && | 387 if (typeof classData == "object" && |
| 388 classData instanceof Array) { | 388 classData instanceof Array) { |
| 389 classData = fields = classData[0]; | 389 classData = fields = classData[0]; |
| 390 } | 390 } |
| 391 if (typeof classData == "string") { | 391 if (typeof classData == "string") { |
| 392 var split = classData.split("/"); | 392 var split = classData.split("/"); |
| 393 if (split.length == 2) { | 393 if (split.length == 2) { |
| 394 name = split[0]; | 394 name = split[0]; |
| 395 fields = split[1]; | 395 fields = split[1]; |
| 396 } | 396 } |
| 397 } | 397 } |
| 398 | 398 |
| 399 var s = fields.split(";"); | 399 var s = fields.split(";"); |
| 400 fields = s[1] == "" ? [] : s[1].split(","); | 400 fields = s[1] == "" ? [] : s[1].split(","); |
| 401 supr = s[0]; | 401 supr = s[0]; |
| 402 split = supr.split(":"); | 402 split = supr.split(":"); |
| 403 if (split.length == 2) { | 403 if (split.length == 2) { |
| 404 supr = split[0]; | 404 supr = split[0]; |
| 405 var functionSignature = split[1]; | 405 var functionSignature = split[1]; |
| 406 if (functionSignature) | 406 if (functionSignature) |
| 407 desc.\$signature = (function(s) { | 407 desc.\$signature = (function(s) { |
| 408 return function(){ return #[s]; }; // embedded metadata. | 408 return function(){ return #metadata[s]; }; |
| 409 })(functionSignature); | 409 })(functionSignature); |
| 410 } | 410 } |
| 411 | 411 |
| 412 if (#) // needsMixinSupport | 412 if (#needsMixinSupport) |
| 413 if (supr && supr.indexOf("+") > 0) { | 413 if (supr && supr.indexOf("+") > 0) { |
| 414 s = supr.split("+"); | 414 s = supr.split("+"); |
| 415 supr = s[0]; | 415 supr = s[0]; |
| 416 var mixin = collectedClasses[s[1]]; | 416 var mixin = collectedClasses[s[1]]; |
| 417 if (mixin instanceof Array) mixin = mixin[1]; | 417 if (mixin instanceof Array) mixin = mixin[1]; |
| 418 for (var d in mixin) { | 418 for (var d in mixin) { |
| 419 if (hasOwnProperty.call(mixin, d) && | 419 if (hasOwnProperty.call(mixin, d) && |
| 420 !hasOwnProperty.call(desc, d)) | 420 !hasOwnProperty.call(desc, d)) |
| 421 desc[d] = mixin[d]; | 421 desc[d] = mixin[d]; |
| 422 } | 422 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 440 | 440 |
| 441 for (var i = 0; i < constructors.length; i++) { | 441 for (var i = 0; i < constructors.length; i++) { |
| 442 var constructor = constructors[i]; | 442 var constructor = constructors[i]; |
| 443 var cls = constructor.name; | 443 var cls = constructor.name; |
| 444 var desc = collectedClasses[cls]; | 444 var desc = collectedClasses[cls]; |
| 445 var globalObject = isolateProperties; | 445 var globalObject = isolateProperties; |
| 446 if (desc instanceof Array) { | 446 if (desc instanceof Array) { |
| 447 globalObject = desc[0] || isolateProperties; | 447 globalObject = desc[0] || isolateProperties; |
| 448 desc = desc[1]; | 448 desc = desc[1]; |
| 449 } | 449 } |
| 450 if (#) //backend.isTreeShakingDisabled, | 450 if (#isTreeShakingDisabled) |
| 451 constructor["${namer.metadataField}"] = desc; | 451 constructor["${namer.metadataField}"] = desc; |
| 452 allClasses[cls] = constructor; | 452 allClasses[cls] = constructor; |
| 453 globalObject[cls] = constructor; | 453 globalObject[cls] = constructor; |
| 454 } | 454 } |
| 455 | 455 |
| 456 constructors = null; | 456 constructors = null; |
| 457 | 457 |
| 458 var finishedClasses = Object.create(null); | 458 var finishedClasses = Object.create(null); |
| 459 # = Object.create(null); // embedded interceptorsByTag. | 459 #interceptorsByTag = Object.create(null); |
| 460 # = Object.create(null); // embedded leafTags. | 460 #leafTags = Object.create(null); // embedded leafTags. |
| 461 | 461 |
| 462 #; // buildFinishClass(), | 462 #finishClassCall; |
| 463 | 463 |
| 464 #; // buildTrivialNsmHandlers() | 464 #trivialNsmHandlers; |
| 465 | 465 |
| 466 for (var cls in pendingClasses) finishClass(cls); | 466 for (var cls in pendingClasses) finishClass(cls); |
| 467 }''', [ | 467 }''', { 'allClasses': allClassesAccess, |
| 468 allClassesAccess, allClassesAccess, | 468 'debugFastObjects': DEBUG_FAST_OBJECTS, |
| 469 allClassesAccess, | 469 'hasRetainedMetadata': backend.hasRetainedMetadata, |
| 470 DEBUG_FAST_OBJECTS, | 470 'metadata': metadataAccess, |
| 471 backend.hasRetainedMetadata, | 471 'needsMixinSupport': needsMixinSupport, |
| 472 metadataAccess, | 472 'isTreeShakingDisabled': backend.isTreeShakingDisabled, |
| 473 needsMixinSupport, | 473 'interceptorsByTag': interceptorsByTagAccess, |
| 474 backend.isTreeShakingDisabled, | 474 'leafTags': leafTagsAccess, |
| 475 interceptorsByTagAccess, | 475 'finishClassCall': buildFinishClass(), |
| 476 leafTagsAccess, | 476 'trivialNsmHandlers': nsmEmitter.buildTrivialNsmHandlers()}); |
| 477 buildFinishClass(), | |
| 478 nsmEmitter.buildTrivialNsmHandlers()]); | |
| 479 } | 477 } |
| 480 | 478 |
| 481 jsAst.Node optional(bool condition, jsAst.Node node) { | 479 jsAst.Node optional(bool condition, jsAst.Node node) { |
| 482 return condition ? node : new jsAst.EmptyStatement(); | 480 return condition ? node : new jsAst.EmptyStatement(); |
| 483 } | 481 } |
| 484 | 482 |
| 485 jsAst.FunctionDeclaration buildFinishClass() { | 483 jsAst.FunctionDeclaration buildFinishClass() { |
| 486 String specProperty = '"${namer.nativeSpecProperty}"'; // "%" | 484 String specProperty = '"${namer.nativeSpecProperty}"'; // "%" |
| 487 | 485 |
| 488 jsAst.Expression interceptorsByTagAccess = | 486 jsAst.Expression interceptorsByTagAccess = |
| (...skipping 1500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1989 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { | 1987 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { |
| 1990 if (element.isInstanceMember) { | 1988 if (element.isInstanceMember) { |
| 1991 cachedClassBuilders.remove(element.enclosingClass); | 1989 cachedClassBuilders.remove(element.enclosingClass); |
| 1992 | 1990 |
| 1993 nativeEmitter.cachedBuilders.remove(element.enclosingClass); | 1991 nativeEmitter.cachedBuilders.remove(element.enclosingClass); |
| 1994 | 1992 |
| 1995 } | 1993 } |
| 1996 } | 1994 } |
| 1997 } | 1995 } |
| 1998 } | 1996 } |
| OLD | NEW |