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