| 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 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 | 266 |
| 267 @override | 267 @override |
| 268 jsAst.PropertyAccess typeAccess(Element element) { | 268 jsAst.PropertyAccess typeAccess(Element element) { |
| 269 return globalPropertyAccess(element); | 269 return globalPropertyAccess(element); |
| 270 } | 270 } |
| 271 | 271 |
| 272 List<jsAst.Statement> buildTrivialNsmHandlers(){ | 272 List<jsAst.Statement> buildTrivialNsmHandlers(){ |
| 273 return nsmEmitter.buildTrivialNsmHandlers(); | 273 return nsmEmitter.buildTrivialNsmHandlers(); |
| 274 } | 274 } |
| 275 | 275 |
| 276 jsAst.FunctionDeclaration get generateAccessorFunction { | 276 jsAst.Statement buildNativeInfoHandler( |
| 277 const RANGE1_SIZE = RANGE1_LAST - RANGE1_FIRST + 1; | 277 jsAst.Expression infoAccess, |
| 278 const RANGE2_SIZE = RANGE2_LAST - RANGE2_FIRST + 1; | 278 jsAst.Expression constructorAccess, |
| 279 const RANGE1_ADJUST = - (FIRST_FIELD_CODE - RANGE1_FIRST); | 279 jsAst.Expression subclassReadGenerator(jsAst.Expression subclass), |
| 280 const RANGE2_ADJUST = - (FIRST_FIELD_CODE + RANGE1_SIZE - RANGE2_FIRST); | 280 jsAst.Expression interceptorsByTagAccess, |
| 281 const RANGE3_ADJUST = | 281 jsAst.Expression leafTagsAccess) { |
| 282 - (FIRST_FIELD_CODE + RANGE1_SIZE + RANGE2_SIZE - RANGE3_FIRST); | 282 return nativeEmitter.buildNativeInfoHandler(infoAccess, constructorAccess, |
| 283 | 283 subclassReadGenerator, |
| 284 String receiverParamName = compiler.enableMinification ? "r" : "receiver"; | 284 interceptorsByTagAccess, |
| 285 String valueParamName = compiler.enableMinification ? "v" : "value"; | 285 leafTagsAccess); |
| 286 String reflectableField = namer.reflectableField; | |
| 287 | |
| 288 return js.statement(''' | |
| 289 function generateAccessor(fieldDescriptor, accessors, cls) { | |
| 290 var fieldInformation = fieldDescriptor.split("-"); | |
| 291 var field = fieldInformation[0]; | |
| 292 var len = field.length; | |
| 293 var code = field.charCodeAt(len - 1); | |
| 294 var reflectable; | |
| 295 if (fieldInformation.length > 1) reflectable = true; | |
| 296 else reflectable = false; | |
| 297 code = ((code >= $RANGE1_FIRST) && (code <= $RANGE1_LAST)) | |
| 298 ? code - $RANGE1_ADJUST | |
| 299 : ((code >= $RANGE2_FIRST) && (code <= $RANGE2_LAST)) | |
| 300 ? code - $RANGE2_ADJUST | |
| 301 : ((code >= $RANGE3_FIRST) && (code <= $RANGE3_LAST)) | |
| 302 ? code - $RANGE3_ADJUST | |
| 303 : $NO_FIELD_CODE; | |
| 304 | |
| 305 if (code) { // needsAccessor | |
| 306 var getterCode = code & 3; | |
| 307 var setterCode = code >> 2; | |
| 308 var accessorName = field = field.substring(0, len - 1); | |
| 309 | |
| 310 var divider = field.indexOf(":"); | |
| 311 if (divider > 0) { // Colon never in first position. | |
| 312 accessorName = field.substring(0, divider); | |
| 313 field = field.substring(divider + 1); | |
| 314 } | |
| 315 | |
| 316 if (getterCode) { // needsGetter | |
| 317 var args = (getterCode & 2) ? "$receiverParamName" : ""; | |
| 318 var receiver = (getterCode & 1) ? "this" : "$receiverParamName"; | |
| 319 var body = "return " + receiver + "." + field; | |
| 320 var property = | |
| 321 cls + ".prototype.${namer.getterPrefix}" + accessorName + "="; | |
| 322 var fn = "function(" + args + "){" + body + "}"; | |
| 323 if (reflectable) | |
| 324 accessors.push(property + "\$reflectable(" + fn + ");\\n"); | |
| 325 else | |
| 326 accessors.push(property + fn + ";\\n"); | |
| 327 } | |
| 328 | |
| 329 if (setterCode) { // needsSetter | |
| 330 var args = (setterCode & 2) | |
| 331 ? "$receiverParamName,${_}$valueParamName" | |
| 332 : "$valueParamName"; | |
| 333 var receiver = (setterCode & 1) ? "this" : "$receiverParamName"; | |
| 334 var body = receiver + "." + field + "$_=$_$valueParamName"; | |
| 335 var property = | |
| 336 cls + ".prototype.${namer.setterPrefix}" + accessorName + "="; | |
| 337 var fn = "function(" + args + "){" + body + "}"; | |
| 338 if (reflectable) | |
| 339 accessors.push(property + "\$reflectable(" + fn + ");\\n"); | |
| 340 else | |
| 341 accessors.push(property + fn + ";\\n"); | |
| 342 } | |
| 343 } | |
| 344 | |
| 345 return field; | |
| 346 }'''); | |
| 347 } | 286 } |
| 348 | 287 |
| 349 List<jsAst.Node> get defineClassFunction { | 288 jsAst.ObjectInitializer generateInterceptedNamesSet() { |
| 350 // First the class name, then the field names in an array and the members | 289 return interceptorEmitter.generateInterceptedNamesSet(); |
| 351 // (inside an Object literal). | |
| 352 // The caller can also pass in the constructor as a function if needed. | |
| 353 // | |
| 354 // Example: | |
| 355 // defineClass("A", ["x", "y"], { | |
| 356 // foo$1: function(y) { | |
| 357 // print(this.x + y); | |
| 358 // }, | |
| 359 // bar$2: function(t, v) { | |
| 360 // this.x = t - v; | |
| 361 // }, | |
| 362 // }); | |
| 363 | |
| 364 bool hasIsolateSupport = compiler.hasIsolateSupport; | |
| 365 String fieldNamesProperty = FIELD_NAMES_PROPERTY_NAME; | |
| 366 | |
| 367 jsAst.Expression defineClass = js(r''' | |
| 368 function(name, fields) { | |
| 369 var accessors = []; | |
| 370 | |
| 371 var str = "function " + name + "("; | |
| 372 var body = ""; | |
| 373 if (#hasIsolateSupport) { var fieldNames = ""; } | |
| 374 | |
| 375 for (var i = 0; i < fields.length; i++) { | |
| 376 if(i != 0) str += ", "; | |
| 377 | |
| 378 var field = generateAccessor(fields[i], accessors, name); | |
| 379 if (#hasIsolateSupport) { fieldNames += "'" + field + "',"; } | |
| 380 var parameter = "p_" + field; | |
| 381 str += parameter; | |
| 382 body += ("this." + field + " = " + parameter + ";\n"); | |
| 383 } | |
| 384 if (supportsDirectProtoAccess) { | |
| 385 body += "this." + #deferredAction + "();"; | |
| 386 } | |
| 387 str += ") {\n" + body + "}\n"; | |
| 388 str += name + ".builtin$cls=\"" + name + "\";\n"; | |
| 389 str += "$desc=$collectedClasses." + name + "[1];\n"; | |
| 390 str += name + ".prototype = $desc;\n"; | |
| 391 if (typeof defineClass.name != "string") { | |
| 392 str += name + ".name=\"" + name + "\";\n"; | |
| 393 } | |
| 394 if (#hasIsolateSupport) { | |
| 395 str += name + "." + #fieldNamesProperty + "=[" + fieldNames | |
| 396 + "];\n"; | |
| 397 } | |
| 398 str += accessors.join(""); | |
| 399 | |
| 400 return str; | |
| 401 }''', { 'deferredAction': js.string(namer.deferredAction), | |
| 402 'hasIsolateSupport': hasIsolateSupport, | |
| 403 'fieldNamesProperty': js.string(fieldNamesProperty)}); | |
| 404 | |
| 405 // Declare a function called "generateAccessor". This is used in | |
| 406 // defineClassFunction. | |
| 407 List result = <jsAst.Node>[ | |
| 408 generateAccessorFunction, | |
| 409 new jsAst.FunctionDeclaration( | |
| 410 new jsAst.VariableDeclaration('defineClass'), defineClass) ]; | |
| 411 | |
| 412 if (compiler.hasIncrementalSupport) { | |
| 413 result.add( | |
| 414 js(r'#.defineClass = defineClass', [namer.accessIncrementalHelper])); | |
| 415 } | |
| 416 | |
| 417 if (hasIsolateSupport) { | |
| 418 jsAst.Expression createNewIsolateFunctionAccess = | |
| 419 generateEmbeddedGlobalAccess(embeddedNames.CREATE_NEW_ISOLATE); | |
| 420 var createIsolateAssignment = | |
| 421 js('# = function() { return new ${namer.isolateName}(); }', | |
| 422 createNewIsolateFunctionAccess); | |
| 423 | |
| 424 jsAst.Expression classIdExtractorAccess = | |
| 425 generateEmbeddedGlobalAccess(embeddedNames.CLASS_ID_EXTRACTOR); | |
| 426 var classIdExtractorAssignment = | |
| 427 js('# = function(o) { return o.constructor.name; }', | |
| 428 classIdExtractorAccess); | |
| 429 | |
| 430 jsAst.Expression classFieldsExtractorAccess = | |
| 431 generateEmbeddedGlobalAccess(embeddedNames.CLASS_FIELDS_EXTRACTOR); | |
| 432 var classFieldsExtractorAssignment = js(''' | |
| 433 # = function(o) { | |
| 434 var fieldNames = o.constructor.$fieldNamesProperty; | |
| 435 if (!fieldNames) return []; // TODO(floitsch): do something else here. | |
| 436 var result = []; | |
| 437 result.length = fieldNames.length; | |
| 438 for (var i = 0; i < fieldNames.length; i++) { | |
| 439 result[i] = o[fieldNames[i]]; | |
| 440 } | |
| 441 return result; | |
| 442 }''', classFieldsExtractorAccess); | |
| 443 | |
| 444 jsAst.Expression instanceFromClassIdAccess = | |
| 445 generateEmbeddedGlobalAccess(embeddedNames.INSTANCE_FROM_CLASS_ID); | |
| 446 jsAst.Expression allClassesAccess = | |
| 447 generateEmbeddedGlobalAccess(embeddedNames.ALL_CLASSES); | |
| 448 var instanceFromClassIdAssignment = | |
| 449 js('# = function(name) { return new #[name](); }', | |
| 450 [instanceFromClassIdAccess, allClassesAccess]); | |
| 451 | |
| 452 jsAst.Expression initializeEmptyInstanceAccess = | |
| 453 generateEmbeddedGlobalAccess(embeddedNames.INITIALIZE_EMPTY_INSTANCE); | |
| 454 var initializeEmptyInstanceAssignment = js(''' | |
| 455 # = function(name, o, fields) { | |
| 456 #[name].apply(o, fields); | |
| 457 return o; | |
| 458 }''', [ initializeEmptyInstanceAccess, allClassesAccess ]); | |
| 459 | |
| 460 result.addAll([createIsolateAssignment, | |
| 461 classIdExtractorAssignment, | |
| 462 classFieldsExtractorAssignment, | |
| 463 instanceFromClassIdAssignment, | |
| 464 initializeEmptyInstanceAssignment]); | |
| 465 } | |
| 466 | |
| 467 return result; | |
| 468 } | |
| 469 | |
| 470 /** Needs defineClass to be defined. */ | |
| 471 jsAst.Expression buildInheritFrom() { | |
| 472 jsAst.Expression result = js(r""" | |
| 473 // If the browser supports changing the prototype via __proto__, we make | |
| 474 // use of that feature. Otherwise, we copy the properties into a new | |
| 475 // constructor. | |
| 476 supportsDirectProtoAccess ? | |
| 477 function(constructor, superConstructor) { | |
| 478 var prototype = constructor.prototype; | |
| 479 prototype.__proto__ = superConstructor.prototype; | |
| 480 // Use a function for `true` here, as functions are stored in the | |
| 481 // hidden class and not as properties in the object. | |
| 482 prototype.constructor = constructor; | |
| 483 prototype[#operatorIsPrefix + constructor.name] = constructor; | |
| 484 return convertToFastObject(prototype); | |
| 485 } : | |
| 486 function() { | |
| 487 function tmp() {} | |
| 488 return function (constructor, superConstructor) { | |
| 489 tmp.prototype = superConstructor.prototype; | |
| 490 var object = new tmp(); | |
| 491 convertToSlowObject(object); | |
| 492 var properties = constructor.prototype; | |
| 493 var members = Object.keys(properties); | |
| 494 for (var i = 0; i < members.length; i++) { | |
| 495 var member = members[i]; | |
| 496 object[member] = properties[member]; | |
| 497 } | |
| 498 // Use a function for `true` here, as functions are stored in the | |
| 499 // hidden class and not as properties in the object. | |
| 500 object[#operatorIsPrefix + constructor.name] = constructor; | |
| 501 object.constructor = constructor; | |
| 502 constructor.prototype = object; | |
| 503 return object; | |
| 504 }; | |
| 505 }() | |
| 506 """, { 'operatorIsPrefix' : js.string(namer.operatorIsPrefix)}); | |
| 507 if (compiler.hasIncrementalSupport) { | |
| 508 result = js( | |
| 509 r'#.inheritFrom = #', [namer.accessIncrementalHelper, result]); | |
| 510 } | |
| 511 return js(r'var inheritFrom = #', [result]); | |
| 512 } | |
| 513 | |
| 514 jsAst.Statement buildFinishClass(bool needsNativeSupport) { | |
| 515 String specProperty = '"${namer.nativeSpecProperty}"'; // "%" | |
| 516 | |
| 517 jsAst.Expression finishedClassesAccess = | |
| 518 generateEmbeddedGlobalAccess(embeddedNames.FINISHED_CLASSES); | |
| 519 | |
| 520 jsAst.Expression nativeInfoAccess = js('prototype[$specProperty]', []); | |
| 521 jsAst.Expression constructorAccess = js('constructor', []); | |
| 522 Function subclassReadGenerator = | |
| 523 (jsAst.Expression subclass) => js('allClasses[#]', subclass); | |
| 524 jsAst.Expression interceptorsByTagAccess = | |
| 525 generateEmbeddedGlobalAccess(embeddedNames.INTERCEPTORS_BY_TAG); | |
| 526 jsAst.Expression leafTagsAccess = | |
| 527 generateEmbeddedGlobalAccess(embeddedNames.LEAF_TAGS); | |
| 528 jsAst.Statement nativeInfoHandler = nativeEmitter.buildNativeInfoHandler( | |
| 529 nativeInfoAccess, | |
| 530 constructorAccess, | |
| 531 subclassReadGenerator, | |
| 532 interceptorsByTagAccess, | |
| 533 leafTagsAccess); | |
| 534 | |
| 535 return js.statement(''' | |
| 536 { | |
| 537 var finishedClasses = #finishedClassesAccess; | |
| 538 | |
| 539 function finishClass(cls) { | |
| 540 | |
| 541 if (finishedClasses[cls]) return; | |
| 542 finishedClasses[cls] = true; | |
| 543 | |
| 544 var superclass = processedClasses.pending[cls]; | |
| 545 | |
| 546 if (#needsMixinSupport) { | |
| 547 if (superclass && superclass.indexOf("+") > 0) { | |
| 548 var s = superclass.split("+"); | |
| 549 superclass = s[0]; | |
| 550 var mixinClass = s[1]; | |
| 551 finishClass(mixinClass); | |
| 552 var mixin = allClasses[mixinClass]; | |
| 553 var mixinPrototype = mixin.prototype; | |
| 554 var clsPrototype = allClasses[cls].prototype; | |
| 555 | |
| 556 var properties = Object.keys(mixinPrototype); | |
| 557 for (var i = 0; i < properties.length; i++) { | |
| 558 var d = properties[i]; | |
| 559 if (!hasOwnProperty.call(clsPrototype, d)) | |
| 560 clsPrototype[d] = mixinPrototype[d]; | |
| 561 } | |
| 562 } | |
| 563 } | |
| 564 | |
| 565 // The superclass is only false (empty string) for the Dart Object | |
| 566 // class. The minifier together with noSuchMethod can put methods on | |
| 567 // the Object.prototype object, and they show through here, so we check | |
| 568 // that we have a string. | |
| 569 if (!superclass || typeof superclass != "string") { | |
| 570 // Inlined special case of InheritFrom here for performance reasons. | |
| 571 // Fix up the the Dart Object class' prototype. | |
| 572 var constructor = allClasses[cls]; | |
| 573 var prototype = constructor.prototype; | |
| 574 prototype.constructor = constructor; | |
| 575 prototype.#isObject = constructor; | |
| 576 prototype.#deferredAction = #markerFun; | |
| 577 return; | |
| 578 } | |
| 579 finishClass(superclass); | |
| 580 var superConstructor = allClasses[superclass]; | |
| 581 | |
| 582 if (!superConstructor) { | |
| 583 superConstructor = existingIsolateProperties[superclass]; | |
| 584 } | |
| 585 | |
| 586 var constructor = allClasses[cls]; | |
| 587 var prototype = inheritFrom(constructor, superConstructor); | |
| 588 | |
| 589 if (#needsNativeSupport) { | |
| 590 if (Object.prototype.hasOwnProperty.call(prototype, $specProperty)) { | |
| 591 #nativeInfoHandler; | |
| 592 // As native classes can come into existence without a constructor | |
| 593 // call, we have to ensure that the class has been fully | |
| 594 // initialized. | |
| 595 if (constructor.prototype.#deferredAction) | |
| 596 finishAddStubsHelper(constructor.prototype); | |
| 597 } | |
| 598 } | |
| 599 // Interceptors (or rather their prototypes) are also used without | |
| 600 // first instantiating them first. | |
| 601 if (prototype.#isInterceptorClass && | |
| 602 constructor.prototype.#deferredAction) { | |
| 603 finishAddStubsHelper(constructor.prototype); | |
| 604 } | |
| 605 } | |
| 606 }''', {'deferredAction': namer.deferredAction, | |
| 607 'finishedClassesAccess': finishedClassesAccess, | |
| 608 'markerFun': markerFun, | |
| 609 'needsMixinSupport': needsMixinSupport, | |
| 610 'needsNativeSupport': needsNativeSupport, | |
| 611 'nativeInfoHandler': nativeInfoHandler, | |
| 612 'isInterceptorClass': namer.operatorIs(backend.jsInterceptorClass), | |
| 613 'isObject' : namer.operatorIs(compiler.objectClass) }); | |
| 614 } | 290 } |
| 615 | 291 |
| 616 void emitFinishIsolateConstructorInvocation(CodeOutput output) { | 292 void emitFinishIsolateConstructorInvocation(CodeOutput output) { |
| 617 String isolate = namer.isolateName; | 293 String isolate = namer.isolateName; |
| 618 output.add("$isolate = $finishIsolateConstructorName($isolate)$N"); | 294 output.add("$isolate = $finishIsolateConstructorName($isolate)$N"); |
| 619 } | 295 } |
| 620 | 296 |
| 621 /// In minified mode we want to keep the name for the most common core types. | 297 /// In minified mode we want to keep the name for the most common core types. |
| 622 bool _isNativeTypeNeedingReflectionName(Element element) { | 298 bool _isNativeTypeNeedingReflectionName(Element element) { |
| 623 if (!element.isClass) return false; | 299 if (!element.isClass) return false; |
| (...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1493 mainOutput.add('${globalsHolder}.$globalObject$_=${_}'); | 1169 mainOutput.add('${globalsHolder}.$globalObject$_=${_}'); |
| 1494 } | 1170 } |
| 1495 mainOutput.add('map()$N'); | 1171 mainOutput.add('map()$N'); |
| 1496 } | 1172 } |
| 1497 | 1173 |
| 1498 mainOutput.add('function ${namer.isolateName}()$_{}\n'); | 1174 mainOutput.add('function ${namer.isolateName}()$_{}\n'); |
| 1499 if (isProgramSplit) { | 1175 if (isProgramSplit) { |
| 1500 mainOutput.add( | 1176 mainOutput.add( |
| 1501 '${globalsHolder}.${namer.isolateName}$_=$_${namer.isolateName}$N' | 1177 '${globalsHolder}.${namer.isolateName}$_=$_${namer.isolateName}$N' |
| 1502 '${globalsHolder}.$initName$_=${_}$initName$N' | 1178 '${globalsHolder}.$initName$_=${_}$initName$N' |
| 1503 '${globalsHolder}.$parseReflectionDataName$_=$_' | 1179 '${globalsHolder}.$setupProgramName$_=$_' |
| 1504 '$parseReflectionDataName$N'); | 1180 '$setupProgramName$N'); |
| 1505 } | 1181 } |
| 1506 mainOutput.add('init()$N$n'); | 1182 mainOutput.add('init()$N$n'); |
| 1507 mainOutput.add('$isolateProperties$_=$_$isolatePropertiesName$N'); | 1183 mainOutput.add('$isolateProperties$_=$_$isolatePropertiesName$N'); |
| 1508 | 1184 |
| 1509 emitFunctionThatReturnsNull(mainOutput); | 1185 emitFunctionThatReturnsNull(mainOutput); |
| 1510 mainFragment.libraries.forEach(emitLibrary); | 1186 mainFragment.libraries.forEach(emitLibrary); |
| 1511 | 1187 |
| 1512 Iterable<LibraryElement> libraries = | 1188 Iterable<LibraryElement> libraries = |
| 1513 task.outputLibraryLists[mainOutputUnit]; | 1189 task.outputLibraryLists[mainOutputUnit]; |
| 1514 if (libraries == null) libraries = []; | 1190 if (libraries == null) libraries = []; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1536 if (element is LibraryElement) { | 1212 if (element is LibraryElement) { |
| 1537 writeLibraryDescriptor(libraryBuffer, element); | 1213 writeLibraryDescriptor(libraryBuffer, element); |
| 1538 elementDescriptors.remove(element); | 1214 elementDescriptors.remove(element); |
| 1539 } | 1215 } |
| 1540 } | 1216 } |
| 1541 } | 1217 } |
| 1542 | 1218 |
| 1543 bool needsNativeSupport = program.needsNativeSupport; | 1219 bool needsNativeSupport = program.needsNativeSupport; |
| 1544 mainOutput.addBuffer( | 1220 mainOutput.addBuffer( |
| 1545 jsAst.prettyPrint( | 1221 jsAst.prettyPrint( |
| 1546 getReflectionDataParser(this, backend, needsNativeSupport), | 1222 buildSetupProgram(program, compiler, backend, namer, this), |
| 1547 compiler)); | 1223 compiler)); |
| 1548 | 1224 |
| 1549 // The argument to reflectionDataParser is assigned to a temporary 'dart' | 1225 // The argument to reflectionDataParser is assigned to a temporary 'dart' |
| 1550 // so that 'dart.' will appear as the prefix to dart methods in stack | 1226 // so that 'dart.' will appear as the prefix to dart methods in stack |
| 1551 // traces and profile entries. | 1227 // traces and profile entries. |
| 1552 mainOutput..add('var dart = [$n') | 1228 mainOutput..add('var dart = [$n') |
| 1553 ..addBuffer(libraryBuffer) | 1229 ..addBuffer(libraryBuffer) |
| 1554 ..add(']$N'); | 1230 ..add(']$N'); |
| 1555 if (compiler.useContentSecurityPolicy) { | 1231 if (compiler.useContentSecurityPolicy) { |
| 1556 jsAst.Statement precompiledFunctionAst = | 1232 jsAst.Statement precompiledFunctionAst = |
| 1557 buildCspPrecompiledFunctionFor(mainOutputUnit); | 1233 buildCspPrecompiledFunctionFor(mainOutputUnit); |
| 1558 mainOutput.addBuffer( | 1234 mainOutput.addBuffer( |
| 1559 jsAst.prettyPrint( | 1235 jsAst.prettyPrint( |
| 1560 precompiledFunctionAst, | 1236 precompiledFunctionAst, |
| 1561 compiler, | 1237 compiler, |
| 1562 monitor: compiler.dumpInfoTask, | 1238 monitor: compiler.dumpInfoTask, |
| 1563 allowVariableMinification: false)); | 1239 allowVariableMinification: false)); |
| 1564 mainOutput.add(N); | 1240 mainOutput.add(N); |
| 1565 } | 1241 } |
| 1566 | 1242 |
| 1567 mainOutput.add('$parseReflectionDataName(dart)$N'); | 1243 mainOutput.add('$setupProgramName(dart)$N'); |
| 1568 | 1244 |
| 1569 interceptorEmitter.emitGetInterceptorMethods(mainOutput); | 1245 interceptorEmitter.emitGetInterceptorMethods(mainOutput); |
| 1570 interceptorEmitter.emitOneShotInterceptors(mainOutput); | 1246 interceptorEmitter.emitOneShotInterceptors(mainOutput); |
| 1571 | 1247 |
| 1572 if (task.outputContainsConstantList) { | 1248 if (task.outputContainsConstantList) { |
| 1573 emitMakeConstantList(mainOutput); | 1249 emitMakeConstantList(mainOutput); |
| 1574 } | 1250 } |
| 1575 | 1251 |
| 1576 // Constants in checked mode call into RTI code to set type information | 1252 // Constants in checked mode call into RTI code to set type information |
| 1577 // which may need getInterceptor (and one-shot interceptor) methods, so | 1253 // which may need getInterceptor (and one-shot interceptor) methods, so |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1989 ..add(buildGeneratedBy()) | 1665 ..add(buildGeneratedBy()) |
| 1990 ..add('${deferredInitializers}.current$_=$_' | 1666 ..add('${deferredInitializers}.current$_=$_' |
| 1991 'function$_(${globalsHolder}) {$N'); | 1667 'function$_(${globalsHolder}) {$N'); |
| 1992 for (String globalObject in Namer.reservedGlobalObjectNames) { | 1668 for (String globalObject in Namer.reservedGlobalObjectNames) { |
| 1993 output | 1669 output |
| 1994 .add('var $globalObject$_=$_' | 1670 .add('var $globalObject$_=$_' |
| 1995 '${globalsHolder}.$globalObject$N'); | 1671 '${globalsHolder}.$globalObject$N'); |
| 1996 } | 1672 } |
| 1997 output | 1673 output |
| 1998 ..add('var init$_=$_${globalsHolder}.init$N') | 1674 ..add('var init$_=$_${globalsHolder}.init$N') |
| 1999 ..add('var $parseReflectionDataName$_=$_' | 1675 ..add('var $setupProgramName$_=$_' |
| 2000 '$globalsHolder.$parseReflectionDataName$N') | 1676 '$globalsHolder.$setupProgramName$N') |
| 2001 ..add('var ${namer.isolateName}$_=$_' | 1677 ..add('var ${namer.isolateName}$_=$_' |
| 2002 '${globalsHolder}.${namer.isolateName}$N'); | 1678 '${globalsHolder}.${namer.isolateName}$N'); |
| 2003 if (libraryDescriptorBuffer != null) { | 1679 if (libraryDescriptorBuffer != null) { |
| 2004 // TODO(ahe): This defines a lot of properties on the | 1680 // TODO(ahe): This defines a lot of properties on the |
| 2005 // Isolate.prototype object. We know this will turn it into a | 1681 // Isolate.prototype object. We know this will turn it into a |
| 2006 // slow object in V8, so instead we should do something similar | 1682 // slow object in V8, so instead we should do something similar |
| 2007 // to Isolate.$finishIsolateConstructor. | 1683 // to Isolate.$finishIsolateConstructor. |
| 2008 output | 1684 output |
| 2009 ..add('var ${namer.currentIsolate}$_=$_$isolatePropertiesName$N') | 1685 ..add('var ${namer.currentIsolate}$_=$_$isolatePropertiesName$N') |
| 2010 // The argument to reflectionDataParser is assigned to a temporary | 1686 // The argument to reflectionDataParser is assigned to a temporary |
| 2011 // 'dart' so that 'dart.' will appear as the prefix to dart methods | 1687 // 'dart' so that 'dart.' will appear as the prefix to dart methods |
| 2012 // in stack traces and profile entries. | 1688 // in stack traces and profile entries. |
| 2013 ..add('var dart = [$n ') | 1689 ..add('var dart = [$n ') |
| 2014 ..addBuffer(libraryDescriptorBuffer) | 1690 ..addBuffer(libraryDescriptorBuffer) |
| 2015 ..add(']$N'); | 1691 ..add(']$N'); |
| 2016 | 1692 |
| 2017 if (compiler.useContentSecurityPolicy) { | 1693 if (compiler.useContentSecurityPolicy) { |
| 2018 jsAst.Statement precompiledFunctionAst = | 1694 jsAst.Statement precompiledFunctionAst = |
| 2019 buildCspPrecompiledFunctionFor(outputUnit); | 1695 buildCspPrecompiledFunctionFor(outputUnit); |
| 2020 | 1696 |
| 2021 output.addBuffer( | 1697 output.addBuffer( |
| 2022 jsAst.prettyPrint( | 1698 jsAst.prettyPrint( |
| 2023 precompiledFunctionAst, compiler, | 1699 precompiledFunctionAst, compiler, |
| 2024 monitor: compiler.dumpInfoTask, | 1700 monitor: compiler.dumpInfoTask, |
| 2025 allowVariableMinification: false)); | 1701 allowVariableMinification: false)); |
| 2026 output.add(N); | 1702 output.add(N); |
| 2027 } | 1703 } |
| 2028 output.add('$parseReflectionDataName(dart)$N'); | 1704 output.add('$setupProgramName(dart)$N'); |
| 2029 } | 1705 } |
| 2030 | 1706 |
| 2031 // Set the currentIsolate variable to the current isolate (which is | 1707 // Set the currentIsolate variable to the current isolate (which is |
| 2032 // provided as second argument). | 1708 // provided as second argument). |
| 2033 // We need to do this, because we use the same variable for setting up | 1709 // We need to do this, because we use the same variable for setting up |
| 2034 // the isolate-properties and for storing the current isolate. During | 1710 // the isolate-properties and for storing the current isolate. During |
| 2035 // the setup (the code above this lines) we must set the variable to | 1711 // the setup (the code above this lines) we must set the variable to |
| 2036 // the isolate-properties. | 1712 // the isolate-properties. |
| 2037 // After we have done the setup it must point to the current Isolate. | 1713 // After we have done the setup it must point to the current Isolate. |
| 2038 // Otherwise all methods/functions accessing isolate variables will | 1714 // Otherwise all methods/functions accessing isolate variables will |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2128 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { | 1804 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { |
| 2129 if (element.isInstanceMember) { | 1805 if (element.isInstanceMember) { |
| 2130 cachedClassBuilders.remove(element.enclosingClass); | 1806 cachedClassBuilders.remove(element.enclosingClass); |
| 2131 | 1807 |
| 2132 nativeEmitter.cachedBuilders.remove(element.enclosingClass); | 1808 nativeEmitter.cachedBuilders.remove(element.enclosingClass); |
| 2133 | 1809 |
| 2134 } | 1810 } |
| 2135 } | 1811 } |
| 2136 } | 1812 } |
| 2137 } | 1813 } |
| OLD | NEW |