| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // TODO(ahe): Share these with js_helper.dart. | 7 // TODO(ahe): Share these with js_helper.dart. |
| 8 const FUNCTION_INDEX = 0; | 8 const FUNCTION_INDEX = 0; |
| 9 const NAME_INDEX = 1; | 9 const NAME_INDEX = 1; |
| 10 const CALL_NAME_INDEX = 2; | 10 const CALL_NAME_INDEX = 2; |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 processedClasses.constructorsList.push(cls); | 133 processedClasses.constructorsList.push(cls); |
| 134 } | 134 } |
| 135 processedClasses.collected[cls] = [globalObject, newDesc]; | 135 processedClasses.collected[cls] = [globalObject, newDesc]; |
| 136 classes.push(cls); | 136 classes.push(cls); |
| 137 } | 137 } |
| 138 }''', {'embeddedStatics': staticsAccess, | 138 }''', {'embeddedStatics': staticsAccess, |
| 139 'hasRetainedMetadata': backend.hasRetainedMetadata, | 139 'hasRetainedMetadata': backend.hasRetainedMetadata, |
| 140 'metadata': metadataAccess, | 140 'metadata': metadataAccess, |
| 141 'notInCspMode': !compiler.useContentSecurityPolicy}); | 141 'notInCspMode': !compiler.useContentSecurityPolicy}); |
| 142 | 142 |
| 143 // TODO(zarah): Remove empty else branches in output when if(#hole) is false. |
| 143 jsAst.Statement processStatics = js.statement(''' | 144 jsAst.Statement processStatics = js.statement(''' |
| 144 function processStatics(descriptor, processedClasses) { | 145 function processStatics(descriptor, processedClasses) { |
| 145 for (var property in descriptor) { | 146 for (var property in descriptor) { |
| 146 if (!hasOwnProperty.call(descriptor, property)) continue; | 147 if (!hasOwnProperty.call(descriptor, property)) continue; |
| 147 if (property === "${namer.classDescriptorProperty}") continue; | 148 if (property === "${namer.classDescriptorProperty}") continue; |
| 148 var element = descriptor[property]; | 149 var element = descriptor[property]; |
| 149 var firstChar = property.substring(0, 1); | 150 var firstChar = property.substring(0, 1); |
| 150 var previousProperty; | 151 var previousProperty; |
| 151 if (firstChar === "+") { | 152 if (firstChar === "+") { |
| 152 mangledGlobalNames[previousProperty] = property.substring(1); | 153 mangledGlobalNames[previousProperty] = property.substring(1); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 163 var optionalMethods = descriptor.$methodsWithOptionalArgumentsField; | 164 var optionalMethods = descriptor.$methodsWithOptionalArgumentsField; |
| 164 if (!optionalMethods) { | 165 if (!optionalMethods) { |
| 165 descriptor.$methodsWithOptionalArgumentsField = optionalMethods = {} | 166 descriptor.$methodsWithOptionalArgumentsField = optionalMethods = {} |
| 166 } | 167 } |
| 167 optionalMethods[property] = previousProperty; | 168 optionalMethods[property] = previousProperty; |
| 168 } else if (typeof element === "function") { | 169 } else if (typeof element === "function") { |
| 169 globalObject[previousProperty = property] = element; | 170 globalObject[previousProperty = property] = element; |
| 170 functions.push(property); | 171 functions.push(property); |
| 171 #globalFunctions[property] = element; | 172 #globalFunctions[property] = element; |
| 172 } else if (element.constructor === Array) { | 173 } else if (element.constructor === Array) { |
| 173 addStubs(globalObject, element, property, | 174 if (#needsArrayInitializerSupport) { |
| 174 true, descriptor, functions); | 175 addStubs(globalObject, element, property, |
| 176 true, descriptor, functions); |
| 177 } |
| 175 } else { | 178 } else { |
| 176 // We will not enter this case if no classes are defined. | 179 // We will not enter this case if no classes are defined. |
| 177 if (#hasClasses) { | 180 if (#hasClasses) { |
| 178 previousProperty = property; | 181 previousProperty = property; |
| 179 processClassData(property, element, processedClasses); | 182 processClassData(property, element, processedClasses); |
| 180 } | 183 } |
| 181 } | 184 } |
| 182 } | 185 } |
| 183 } | 186 } |
| 184 ''', {'typeInformation': typeInformationAccess, | 187 ''', {'typeInformation': typeInformationAccess, |
| 185 'globalFunctions': globalFunctionsAccess, | 188 'globalFunctions': globalFunctionsAccess, |
| 186 'hasClasses': oldEmitter.needsClassSupport}); | 189 'hasClasses': oldEmitter.needsClassSupport, |
| 190 'needsArrayInitializerSupport': oldEmitter.needsArrayInitializerSupport}); |
| 187 | 191 |
| 188 | 192 |
| 189 /** | 193 /** |
| 190 * See [dart2js.js_emitter.ContainerBuilder.addMemberMethod] for format of | 194 * See [dart2js.js_emitter.ContainerBuilder.addMemberMethod] for format of |
| 191 * [array]. | 195 * [array]. |
| 192 */ | 196 */ |
| 193 jsAst.Statement addStubs = js.statement(''' | 197 jsAst.Statement addStubs = js.statement(''' |
| 194 function addStubs(descriptor, array, name, isStatic, | 198 function addStubs(descriptor, array, name, isStatic, |
| 195 originalDescriptor, functions) { | 199 originalDescriptor, functions) { |
| 196 var index = $FUNCTION_INDEX, alias = array[index], f; | 200 var index = $FUNCTION_INDEX, alias = array[index], f; |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 (function (reflectionData) { | 426 (function (reflectionData) { |
| 423 "use strict"; | 427 "use strict"; |
| 424 #header; | 428 #header; |
| 425 if (#needsClassSupport) { | 429 if (#needsClassSupport) { |
| 426 #defineClass; | 430 #defineClass; |
| 427 #inheritFrom; | 431 #inheritFrom; |
| 428 #finishClasses; | 432 #finishClasses; |
| 429 #processClassData; | 433 #processClassData; |
| 430 } | 434 } |
| 431 #processStatics; | 435 #processStatics; |
| 432 #addStubs; | 436 if (#needsArrayInitializerSupport) { |
| 433 #tearOffCode; | 437 #addStubs; |
| 438 #tearOffCode; |
| 439 } |
| 434 #incrementalSupport; | 440 #incrementalSupport; |
| 435 #init; | 441 #init; |
| 436 })''', { | 442 })''', { |
| 437 'header': header, | 443 'header': header, |
| 438 'defineClass': oldEmitter.defineClassFunction, | 444 'defineClass': oldEmitter.defineClassFunction, |
| 439 'inheritFrom': oldEmitter.buildInheritFrom(), | 445 'inheritFrom': oldEmitter.buildInheritFrom(), |
| 440 'processClassData': processClassData, | 446 'processClassData': processClassData, |
| 441 'processStatics': processStatics, | 447 'processStatics': processStatics, |
| 442 'incrementalSupport': incrementalSupport, | 448 'incrementalSupport': incrementalSupport, |
| 443 'addStubs': addStubs, | 449 'addStubs': addStubs, |
| 444 'tearOffCode': tearOffCode, | 450 'tearOffCode': tearOffCode, |
| 445 'init': init, | 451 'init': init, |
| 446 'finishClasses': finishClasses, | 452 'finishClasses': finishClasses, |
| 447 'needsClassSupport': oldEmitter.needsClassSupport}); | 453 'needsClassSupport': oldEmitter.needsClassSupport, |
| 454 'needsArrayInitializerSupport': oldEmitter.needsArrayInitializerSupport}); |
| 448 } | 455 } |
| 449 | 456 |
| 450 | 457 |
| 451 List<jsAst.Statement> buildTearOffCode(JavaScriptBackend backend) { | 458 List<jsAst.Statement> buildTearOffCode(JavaScriptBackend backend) { |
| 452 Namer namer = backend.namer; | 459 Namer namer = backend.namer; |
| 453 Compiler compiler = backend.compiler; | 460 Compiler compiler = backend.compiler; |
| 454 | 461 |
| 455 Element closureFromTearOff = backend.findHelper('closureFromTearOff'); | 462 Element closureFromTearOff = backend.findHelper('closureFromTearOff'); |
| 456 String tearOffAccessText; | 463 String tearOffAccessText; |
| 457 jsAst.Expression tearOffAccessExpression; | 464 jsAst.Expression tearOffAccessExpression; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 (function() { | 566 (function() { |
| 560 var result = $array[$index]; | 567 var result = $array[$index]; |
| 561 if ($check) { | 568 if ($check) { |
| 562 throw new Error( | 569 throw new Error( |
| 563 name + ": expected value of type \'$type\' at index " + ($index) + | 570 name + ": expected value of type \'$type\' at index " + ($index) + |
| 564 " but got " + (typeof result)); | 571 " but got " + (typeof result)); |
| 565 } | 572 } |
| 566 return result; | 573 return result; |
| 567 })()'''; | 574 })()'''; |
| 568 } | 575 } |
| OLD | NEW |