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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 var field = generateAccessor(fields[i], accessors, name); | 230 var field = generateAccessor(fields[i], accessors, name); |
234 if (#hasIsolateSupport) { fieldNames += "'" + field + "',"; } | 231 if (#hasIsolateSupport) { fieldNames += "'" + field + "',"; } |
235 var parameter = "p_" + field; | 232 var parameter = "p_" + field; |
236 str += parameter; | 233 str += parameter; |
237 body += ("this." + field + " = " + parameter + ";\\n"); | 234 body += ("this." + field + " = " + parameter + ";\\n"); |
238 } | 235 } |
239 if (supportsDirectProtoAccess) { | 236 if (supportsDirectProtoAccess) { |
240 body += "this." + #deferredActionString + "();"; | 237 body += "this." + #deferredActionString + "();"; |
241 } | 238 } |
242 str += ") {\\n" + body + "}\\n"; | 239 str += ") {\\n" + body + "}\\n"; |
243 str += name + ".$typeNameProperty=\\"" + name + "\\";\\n"; | |
244 str += "\$desc=\$collectedClasses." + name + "[1];\\n"; | 240 str += "\$desc=\$collectedClasses." + name + "[1];\\n"; |
245 str += name + ".prototype = \$desc;\\n"; | 241 str += name + ".prototype = \$desc;\\n"; |
246 if (typeof defineClass.name != "string") { | 242 if (typeof defineClass.name != "string") { |
| 243 // IE does not store the name, but allows to modify the property. |
247 str += name + ".name=\\"" + name + "\\";\\n"; | 244 str += name + ".name=\\"" + name + "\\";\\n"; |
248 } | 245 } |
249 if (#hasIsolateSupport) { | 246 if (#hasIsolateSupport) { |
250 str += name + "." + #fieldNamesProperty + "=[" + fieldNames | 247 str += name + "." + #fieldNamesProperty + "=[" + fieldNames |
251 + "];\\n"; | 248 + "];\\n"; |
252 } | 249 } |
253 str += accessors.join(""); | 250 str += accessors.join(""); |
254 | 251 |
255 return str; | 252 return str; |
256 } | 253 } |
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 (function() { | 843 (function() { |
847 var result = $array[$index]; | 844 var result = $array[$index]; |
848 if ($check) { | 845 if ($check) { |
849 throw new Error( | 846 throw new Error( |
850 name + ": expected value of type \'$type\' at index " + ($index) + | 847 name + ": expected value of type \'$type\' at index " + ($index) + |
851 " but got " + (typeof result)); | 848 " but got " + (typeof result)); |
852 } | 849 } |
853 return result; | 850 return result; |
854 })()'''; | 851 })()'''; |
855 } | 852 } |
OLD | NEW |