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

Unified Diff: dart/lib/compiler/implementation/js_backend/constant_emitter.dart

Issue 11364025: Remove dependency on dart:json. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | dart/lib/compiler/implementation/scanner/scanner_task.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/lib/compiler/implementation/js_backend/constant_emitter.dart
diff --git a/dart/lib/compiler/implementation/js_backend/constant_emitter.dart b/dart/lib/compiler/implementation/js_backend/constant_emitter.dart
index ad7b2b055f31b680a7b176a195af55da1fb5f454..a9e49c0f3a94f4bd2e4135cc72eef5626c55527f 100644
--- a/dart/lib/compiler/implementation/js_backend/constant_emitter.dart
+++ b/dart/lib/compiler/implementation/js_backend/constant_emitter.dart
@@ -92,51 +92,12 @@ class ConstantEmitter implements ConstantVisitor {
void writeEscapedString(DartString string,
CodeBuffer buffer,
Node diagnosticNode) {
- Iterator<int> iterator = string.iterator();
- while (iterator.hasNext) {
- int code = iterator.next();
- if (identical(code, $SQ)) {
- buffer.add(r"\'");
- } else if (identical(code, $LF)) {
- buffer.add(r'\n');
- } else if (identical(code, $CR)) {
- buffer.add(r'\r');
- } else if (identical(code, $LS)) {
- // This Unicode line terminator and $PS are invalid in JS string
- // literals.
- buffer.add(r'\u2028');
- } else if (identical(code, $PS)) {
- buffer.add(r'\u2029');
- } else if (identical(code, $BACKSLASH)) {
- buffer.add(r'\\');
- } else {
- if (code > 0xffff) {
- compiler.reportError(
- diagnosticNode,
- 'Unhandled non-BMP character: U+${code.toRadixString(16)}');
- }
- // TODO(lrn): Consider whether all codes above 0x7f really need to
- // be escaped. We build a Dart string here, so it should be a literal
- // stage that converts it to, e.g., UTF-8 for a JS interpreter.
- if (code < 0x20) {
- buffer.add(r'\x');
- if (code < 0x10) buffer.add('0');
- buffer.add(code.toRadixString(16));
- } else if (code >= 0x80) {
- if (code < 0x100) {
- buffer.add(r'\x');
- } else {
- buffer.add(r'\u');
- if (code < 0x1000) {
- buffer.add('0');
- }
- }
- buffer.add(code.toRadixString(16));
- } else {
- buffer.addCharCode(code);
- }
- }
+ void onError(code) {
+ compiler.reportError(
+ diagnosticNode,
+ 'Unhandled non-BMP character: U+${code.toRadixString(16)}');
}
+ writeJsonEscapedCharsOn(string.iterator(), buffer, onError);
}
void visitString(StringConstant constant) {
« no previous file with comments | « no previous file | dart/lib/compiler/implementation/scanner/scanner_task.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698