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

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

Issue 11368138: Add some support for the code-point code-unit distinction. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
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
Index: sdk/lib/_internal/compiler/implementation/js_backend/constant_emitter.dart
diff --git a/sdk/lib/_internal/compiler/implementation/js_backend/constant_emitter.dart b/sdk/lib/_internal/compiler/implementation/js_backend/constant_emitter.dart
index ad7b2b055f31b680a7b176a195af55da1fb5f454..5e7575bd1a987f9def335be6cb086396d34699da 100644
--- a/sdk/lib/_internal/compiler/implementation/js_backend/constant_emitter.dart
+++ b/sdk/lib/_internal/compiler/implementation/js_backend/constant_emitter.dart
@@ -84,6 +84,26 @@ class ConstantEmitter implements ConstantVisitor {
buffer.add("false");
}
+ void addHexEscape(CodeBuffer buffer, int code) {
+ assert(code < 0x10000);
+ if (code < 0x20) {
+ buffer.add(r'\x');
+ if (code < 0x10) buffer.add('0');
+ buffer.add(code.toRadixString(16));
+ } else {
+ if (code < 0x100) {
+ assert(code >= 0x80);
+ buffer.add(r'\x');
+ } else {
+ buffer.add(r'\u');
+ if (code < 0x1000) {
+ buffer.add('0');
+ }
+ }
+ buffer.add(code.toRadixString(16));
+ }
+ }
+
/**
* Write the contents of the quoted string to a [CodeBuffer] in
* a form that is valid as JavaScript string literal content.
@@ -104,34 +124,25 @@ class ConstantEmitter implements ConstantVisitor {
} else if (identical(code, $LS)) {
// This Unicode line terminator and $PS are invalid in JS string
// literals.
- buffer.add(r'\u2028');
+ addHexEscape(buffer, 0x2028);
} else if (identical(code, $PS)) {
- buffer.add(r'\u2029');
+ addHexEscape(buffer, 0x2029);
} 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));
+ addHexEscape(buffer, code);
} else if (code >= 0x80) {
- if (code < 0x100) {
- buffer.add(r'\x');
+ // 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 >= 0x10000) {
floitsch 2012/11/08 15:28:21 Why not move the surrogate-code into addHexEscape?
erikcorry 2012/11/15 13:28:25 This part has all been rewritten with the new JSON
+ // Surrogate pair.
+ addHexEscape(buffer, 0xd800 + (((code - 0x10000) >> 10) & 0x3ff));
+ addHexEscape(buffer, 0xdc00 + (code & 0x3ff));
} else {
- buffer.add(r'\u');
- if (code < 0x1000) {
- buffer.add('0');
- }
+ addHexEscape(buffer, code);
}
- buffer.add(code.toRadixString(16));
} else {
buffer.addCharCode(code);
}

Powered by Google App Engine
This is Rietveld 408576698