OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 js_backend; | 5 part of js_backend; |
6 | 6 |
7 class ConstantEmitter implements ConstantVisitor { | 7 class ConstantEmitter implements ConstantVisitor { |
8 final Compiler compiler; | 8 final Compiler compiler; |
9 final Namer namer; | 9 final Namer namer; |
10 | 10 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 buffer.add("true"); | 80 buffer.add("true"); |
81 } | 81 } |
82 | 82 |
83 void visitFalse(FalseConstant constant) { | 83 void visitFalse(FalseConstant constant) { |
84 buffer.add("false"); | 84 buffer.add("false"); |
85 } | 85 } |
86 | 86 |
87 /** | 87 /** |
88 * Write the contents of the quoted string to a [CodeBuffer] in | 88 * Write the contents of the quoted string to a [CodeBuffer] in |
89 * a form that is valid as JavaScript string literal content. | 89 * a form that is valid as JavaScript string literal content. |
90 * The string is assumed quoted by single quote characters. | 90 * The string is assumed quoted by double quote characters. |
91 */ | 91 */ |
92 void writeEscapedString(DartString string, | |
93 CodeBuffer buffer, | |
94 Node diagnosticNode) { | |
floitsch
2012/11/21 16:16:50
woot! no diagnostic node anymore :)
| |
95 void onError(code) { | |
96 compiler.reportError( | |
97 diagnosticNode, | |
98 'Unhandled non-BMP character: U+${code.toRadixString(16)}'); | |
99 } | |
100 writeJsonEscapedCharsOn(string.iterator(), buffer, onError); | |
101 } | |
102 | |
103 void visitString(StringConstant constant) { | 92 void visitString(StringConstant constant) { |
104 buffer.add("'"); | 93 buffer.add('"'); |
105 writeEscapedString(constant.value, buffer, constant.node); | 94 writeJsonEscapedCharsOn(constant.value.slowToString(), buffer); |
106 buffer.add("'"); | 95 buffer.add('"'); |
107 } | 96 } |
108 | 97 |
109 void emitCanonicalVersion(Constant constant) { | 98 void emitCanonicalVersion(Constant constant) { |
110 String name = namer.constantName(constant); | 99 String name = namer.constantName(constant); |
111 buffer.add(namer.isolatePropertiesAccessForConstant(name)); | 100 buffer.add(namer.isolatePropertiesAccessForConstant(name)); |
112 } | 101 } |
113 | 102 |
114 void visitList(ListConstant constant) { | 103 void visitList(ListConstant constant) { |
115 if (shouldEmitCanonicalVersion) { | 104 if (shouldEmitCanonicalVersion) { |
116 emitCanonicalVersion(constant); | 105 emitCanonicalVersion(constant); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
228 buffer.add(getJsConstructor(constant.type.element)); | 217 buffer.add(getJsConstructor(constant.type.element)); |
229 buffer.add("("); | 218 buffer.add("("); |
230 for (int i = 0; i < constant.fields.length; i++) { | 219 for (int i = 0; i < constant.fields.length; i++) { |
231 if (i != 0) buffer.add(", "); | 220 if (i != 0) buffer.add(", "); |
232 _visit(constant.fields[i]); | 221 _visit(constant.fields[i]); |
233 } | 222 } |
234 buffer.add(")"); | 223 buffer.add(")"); |
235 } | 224 } |
236 } | 225 } |
237 } | 226 } |
OLD | NEW |