| 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; |
| 11 const REQUIRED_PARAMETER_INDEX = 3; | 11 const REQUIRED_PARAMETER_INDEX = 3; |
| 12 const OPTIONAL_PARAMETER_INDEX = 4; | 12 const OPTIONAL_PARAMETER_INDEX = 4; |
| 13 const DEFAULT_ARGUMENTS_INDEX = 5; | 13 const DEFAULT_ARGUMENTS_INDEX = 5; |
| 14 | 14 |
| 15 const bool VALIDATE_DATA = false; | 15 const bool VALIDATE_DATA = false; |
| 16 | 16 |
| 17 // TODO(ahe): This code should be integrated in CodeEmitterTask.finishClasses. | 17 // TODO(ahe): This code should be integrated in CodeEmitterTask.finishClasses. |
| 18 jsAst.Expression getReflectionDataParser(String classesCollector, | 18 jsAst.Expression getReflectionDataParser(String classesCollector, |
| 19 JavaScriptBackend backend) { | 19 JavaScriptBackend backend) { |
| 20 var text = getReflectionDataParserAsString(classesCollector, backend); |
| 21 return js(text); |
| 22 } |
| 23 |
| 24 |
| 25 String getReflectionDataParserAsString(String classesCollector, |
| 26 JavaScriptBackend backend) { |
| 20 Namer namer = backend.namer; | 27 Namer namer = backend.namer; |
| 21 Compiler compiler = backend.compiler; | 28 Compiler compiler = backend.compiler; |
| 22 Element closureFromTearOff = compiler.findHelper('closureFromTearOff'); | 29 Element closureFromTearOff = compiler.findHelper('closureFromTearOff'); |
| 23 String tearOffAccess; | 30 String tearOffAccess; |
| 24 String tearOffGlobalObjectName; | 31 String tearOffGlobalObjectName; |
| 25 String tearOffGlobalObject; | 32 String tearOffGlobalObject; |
| 26 if (closureFromTearOff != null) { | 33 if (closureFromTearOff != null) { |
| 27 tearOffAccess = namer.isolateAccess(closureFromTearOff); | 34 tearOffAccess = namer.isolateAccess(closureFromTearOff); |
| 28 tearOffGlobalObjectName = tearOffGlobalObject = | 35 tearOffGlobalObjectName = tearOffGlobalObject = |
| 29 namer.globalObjectFor(closureFromTearOff); | 36 namer.globalObjectFor(closureFromTearOff); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 49 | 56 |
| 50 String unmangledNameIndex = backend.mustRetainMetadata | 57 String unmangledNameIndex = backend.mustRetainMetadata |
| 51 ? ' 3 * optionalParameterCount + 2 * requiredParameterCount + 3' | 58 ? ' 3 * optionalParameterCount + 2 * requiredParameterCount + 3' |
| 52 : ' 2 * optionalParameterCount + requiredParameterCount + 3'; | 59 : ' 2 * optionalParameterCount + requiredParameterCount + 3'; |
| 53 | 60 |
| 54 | 61 |
| 55 String header = ''' | 62 String header = ''' |
| 56 (function (reflectionData) { | 63 (function (reflectionData) { |
| 57 "use strict"; | 64 "use strict"; |
| 58 | 65 |
| 59 // [map] returns an object literal that V8 shouldn not try to optimize with a | 66 // [map] returns an object literal that V8 shouldn't try to optimize with a |
| 60 // hidden class. This prevents a potential performance problem where V8 tries | 67 // hidden class. This prevents a potential performance problem where V8 tries |
| 61 // to build a hidden class for an object used as a hashMap. | 68 // to build a hidden class for an object used as a hashMap. |
| 62 | 69 |
| 63 function map(x){x={x:x};delete x.x;return x} | 70 function map(x){x={x:x};delete x.x;return x} |
| 64 '''; | 71 '''; |
| 65 | 72 |
| 66 String processStatics = ''' | 73 String processStatics = ''' |
| 67 function processStatics(descriptor) { | 74 function processStatics(descriptor) { |
| 68 for (var property in descriptor) { | 75 for (var property in descriptor) { |
| 69 if (!hasOwnProperty.call(descriptor, property)) continue; | 76 if (!hasOwnProperty.call(descriptor, property)) continue; |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 '''; | 314 '''; |
| 308 | 315 |
| 309 String footer = ''' | 316 String footer = ''' |
| 310 processStatics(descriptor); | 317 processStatics(descriptor); |
| 311 libraries.push([name, uri, classes, functions, metadata, fields, isRoot, | 318 libraries.push([name, uri, classes, functions, metadata, fields, isRoot, |
| 312 globalObject]); | 319 globalObject]); |
| 313 } | 320 } |
| 314 }) | 321 }) |
| 315 '''; | 322 '''; |
| 316 | 323 |
| 317 return js('$header$processStatics$addStubs$tearOff$init$footer'); | 324 return '$header$processStatics$addStubs$tearOff$init$footer'; |
| 318 } | 325 } |
| 319 | 326 |
| 320 String readString(String array, String index) { | 327 String readString(String array, String index) { |
| 321 return readChecked( | 328 return readChecked( |
| 322 array, index, 'result != null && typeof result != "string"', 'string'); | 329 array, index, 'result != null && typeof result != "string"', 'string'); |
| 323 } | 330 } |
| 324 | 331 |
| 325 String readInt(String array, String index) { | 332 String readInt(String array, String index) { |
| 326 return readChecked( | 333 return readChecked( |
| 327 array, index, | 334 array, index, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 350 (function() { | 357 (function() { |
| 351 var result = $array[$index]; | 358 var result = $array[$index]; |
| 352 if ($check) { | 359 if ($check) { |
| 353 throw new Error( | 360 throw new Error( |
| 354 name + ": expected value of type \'$type\' at index " + ($index) + | 361 name + ": expected value of type \'$type\' at index " + ($index) + |
| 355 " but got " + (typeof result)); | 362 " but got " + (typeof result)); |
| 356 } | 363 } |
| 357 return result; | 364 return result; |
| 358 })()'''; | 365 })()'''; |
| 359 } | 366 } |
| OLD | NEW |