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 const RANGE1_SIZE = RANGE1_LAST - RANGE1_FIRST + 1; | 17 const RANGE1_SIZE = RANGE1_LAST - RANGE1_FIRST + 1; |
18 const RANGE2_SIZE = RANGE2_LAST - RANGE2_FIRST + 1; | 18 const RANGE2_SIZE = RANGE2_LAST - RANGE2_FIRST + 1; |
19 const RANGE1_ADJUST = - (FIRST_FIELD_CODE - RANGE1_FIRST); | 19 const RANGE1_ADJUST = - (FIRST_FIELD_CODE - RANGE1_FIRST); |
20 const RANGE2_ADJUST = - (FIRST_FIELD_CODE + RANGE1_SIZE - RANGE2_FIRST); | 20 const RANGE2_ADJUST = - (FIRST_FIELD_CODE + RANGE1_SIZE - RANGE2_FIRST); |
21 const RANGE3_ADJUST = | 21 const RANGE3_ADJUST = |
22 - (FIRST_FIELD_CODE + RANGE1_SIZE + RANGE2_SIZE - RANGE3_FIRST); | 22 - (FIRST_FIELD_CODE + RANGE1_SIZE + RANGE2_SIZE - RANGE3_FIRST); |
23 | 23 |
24 const String setupProgramName ='setupProgram'; | 24 const String setupProgramName ='setupProgram'; |
25 // TODO(floitsch): make sure this property can't clash with anything. It's | |
26 // unlikely since it lives on types, but still. | |
27 const String typeNameProperty = r'builtin$cls'; | |
28 | 25 |
29 jsAst.Statement buildSetupProgram(Program program, Compiler compiler, | 26 jsAst.Statement buildSetupProgram(Program program, Compiler compiler, |
30 JavaScriptBackend backend, | 27 JavaScriptBackend backend, |
31 Namer namer, | 28 Namer namer, |
32 OldEmitter emitter) { | 29 OldEmitter emitter) { |
33 | 30 |
34 jsAst.Expression typeInformationAccess = | 31 jsAst.Expression typeInformationAccess = |
35 emitter.generateEmbeddedGlobalAccess(embeddedNames.TYPE_INFORMATION); | 32 emitter.generateEmbeddedGlobalAccess(embeddedNames.TYPE_INFORMATION); |
36 jsAst.Expression globalFunctionsAccess = | 33 jsAst.Expression globalFunctionsAccess = |
37 emitter.generateEmbeddedGlobalAccess(embeddedNames.GLOBAL_FUNCTIONS); | 34 emitter.generateEmbeddedGlobalAccess(embeddedNames.GLOBAL_FUNCTIONS); |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 var field = generateAccessor(fields[i], accessors, name); | 229 var field = generateAccessor(fields[i], accessors, name); |
233 if (#hasIsolateSupport) { fieldNames += "'" + field + "',"; } | 230 if (#hasIsolateSupport) { fieldNames += "'" + field + "',"; } |
234 var parameter = "p_" + field; | 231 var parameter = "p_" + field; |
235 str += parameter; | 232 str += parameter; |
236 body += ("this." + field + " = " + parameter + ";\\n"); | 233 body += ("this." + field + " = " + parameter + ";\\n"); |
237 } | 234 } |
238 if (supportsDirectProtoAccess) { | 235 if (supportsDirectProtoAccess) { |
239 body += "this." + #deferredActionString + "();"; | 236 body += "this." + #deferredActionString + "();"; |
240 } | 237 } |
241 str += ") {\\n" + body + "}\\n"; | 238 str += ") {\\n" + body + "}\\n"; |
242 str += name + ".$typeNameProperty=\\"" + name + "\\";\\n"; | |
243 str += "\$desc=\$collectedClasses." + name + "[1];\\n"; | 239 str += "\$desc=\$collectedClasses." + name + "[1];\\n"; |
244 str += name + ".prototype = \$desc;\\n"; | 240 str += name + ".prototype = \$desc;\\n"; |
245 if (typeof defineClass.name != "string") { | 241 if (typeof defineClass.name != "string") { |
| 242 // IE does not store the name, but allows to modify the property. |
246 str += name + ".name=\\"" + name + "\\";\\n"; | 243 str += name + ".name=\\"" + name + "\\";\\n"; |
247 } | 244 } |
248 if (#hasIsolateSupport) { | 245 if (#hasIsolateSupport) { |
249 str += name + "." + #fieldNamesProperty + "=[" + fieldNames | 246 str += name + "." + #fieldNamesProperty + "=[" + fieldNames |
250 + "];\\n"; | 247 + "];\\n"; |
251 } | 248 } |
252 str += accessors.join(""); | 249 str += accessors.join(""); |
253 | 250 |
254 return str; | 251 return str; |
255 } | 252 } |
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
845 (function() { | 842 (function() { |
846 var result = $array[$index]; | 843 var result = $array[$index]; |
847 if ($check) { | 844 if ($check) { |
848 throw new Error( | 845 throw new Error( |
849 name + ": expected value of type \'$type\' at index " + ($index) + | 846 name + ": expected value of type \'$type\' at index " + ($index) + |
850 " but got " + (typeof result)); | 847 " but got " + (typeof result)); |
851 } | 848 } |
852 return result; | 849 return result; |
853 })()'''; | 850 })()'''; |
854 } | 851 } |
OLD | NEW |