Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Side by Side Diff: pkg/compiler/lib/src/js_backend/constant_emitter.dart

Issue 930263002: dart2js: Avoid escaping in strings if it's not necessary. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix bad semicolon. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 { 7 class ConstantEmitter {
8 ConstantReferenceEmitter _referenceEmitter; 8 ConstantReferenceEmitter _referenceEmitter;
9 ConstantLiteralEmitter _literalEmitter; 9 ConstantLiteralEmitter _literalEmitter;
10 10
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 } 234 }
235 } 235 }
236 236
237 /** 237 /**
238 * Write the contents of the quoted string to a [CodeBuffer] in 238 * Write the contents of the quoted string to a [CodeBuffer] in
239 * a form that is valid as JavaScript string literal content. 239 * a form that is valid as JavaScript string literal content.
240 * The string is assumed quoted by double quote characters. 240 * The string is assumed quoted by double quote characters.
241 */ 241 */
242 @override 242 @override
243 jsAst.Expression visitString(StringConstantValue constant, [_]) { 243 jsAst.Expression visitString(StringConstantValue constant, [_]) {
244 StringBuffer sb = new StringBuffer(); 244 return js.escapedString(constant.primitiveValue.slowToString());
245 writeJsonEscapedCharsOn(constant.primitiveValue.slowToString(), sb);
246 return new jsAst.LiteralString('"$sb"');
247 } 245 }
248 246
249 @override 247 @override
250 jsAst.Expression visitList(ListConstantValue constant, [_]) { 248 jsAst.Expression visitList(ListConstantValue constant, [_]) {
251 List<jsAst.Expression> elements = _array(constant.entries); 249 List<jsAst.Expression> elements = _array(constant.entries);
252 jsAst.ArrayInitializer array = new jsAst.ArrayInitializer(elements); 250 jsAst.ArrayInitializer array = new jsAst.ArrayInitializer(elements);
253 jsAst.Expression value = makeConstantListTemplate.instantiate([array]); 251 jsAst.Expression value = makeConstantListTemplate.instantiate([array]);
254 return maybeAddTypeArguments(constant.type, value); 252 return maybeAddTypeArguments(constant.type, value);
255 } 253 }
256 254
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 [value, argumentList]); 396 [value, argumentList]);
399 } 397 }
400 return value; 398 return value;
401 } 399 }
402 400
403 @override 401 @override
404 jsAst.Expression visitDeferred(DeferredConstantValue constant, [_]) { 402 jsAst.Expression visitDeferred(DeferredConstantValue constant, [_]) {
405 return constantEmitter.reference(constant.referenced); 403 return constantEmitter.reference(constant.referenced);
406 } 404 }
407 } 405 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698