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