| 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) { | |
| 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 buffer.add(getJsConstructor(constant.type.element)); | 195 buffer.add(getJsConstructor(constant.type.element)); |
| 207 buffer.add("("); | 196 buffer.add("("); |
| 208 for (int i = 0; i < constant.fields.length; i++) { | 197 for (int i = 0; i < constant.fields.length; i++) { |
| 209 if (i != 0) buffer.add(", "); | 198 if (i != 0) buffer.add(", "); |
| 210 _visit(constant.fields[i]); | 199 _visit(constant.fields[i]); |
| 211 } | 200 } |
| 212 buffer.add(")"); | 201 buffer.add(")"); |
| 213 } | 202 } |
| 214 } | 203 } |
| 215 } | 204 } |
| OLD | NEW |