Index: sdk/lib/_internal/compiler/implementation/lib/js_helper.dart |
diff --git a/sdk/lib/_internal/compiler/implementation/lib/js_helper.dart b/sdk/lib/_internal/compiler/implementation/lib/js_helper.dart |
index 5b4f36a612dd73f37a56a7c035d18e5b31ec40dd..6d05190f6c909fd747a384fae44bda4c5b69dea4 100644 |
--- a/sdk/lib/_internal/compiler/implementation/lib/js_helper.dart |
+++ b/sdk/lib/_internal/compiler/implementation/lib/js_helper.dart |
@@ -534,11 +534,45 @@ class Primitives { |
static num dateNow() => JS('num', r'Date.now()'); |
+ static const MAX_CODE_UNIT = 0xffff; |
+ static const MAX_CODE_POINT = 0x10ffff; |
+ static const SURROGATE_BASE = 0xd800; |
+ static const SURROGATE_END = 0xdfff; |
+ static const LEAD_BASE = 0xd800; |
+ static const TRAIL_BASE = 0xdc00; |
+ static const SURROGATE_MASK = 0x3ff; |
+ static const SURROGATE_ENCODING_BASE = 0x10000; |
+ |
static String stringFromCharCodes(charCodes) { |
floitsch
2012/11/08 15:28:21
I would move this code to the patch-class and redi
ngeoffray
2012/11/15 13:24:20
I don't think the patch classes have access to 'JS
|
+ bool surrogatePairs = false; |
+ for (var i in charCodes) { |
+ if (i is !int) throw new ArgumentError(i); |
+ if (i > MAX_CODE_POINT) throw new ArgumentError(i); |
+ if (i > MAX_CODE_UNIT) surrogatePairs = true; |
+ if (i >= SURROGATE_BASE && i <= SURROGATE_END) throw new ArgumentError(i); |
+ } |
+ if (!surrogatePairs) { |
+ return JS('String', r'String.fromCharCode.apply(#, #)', null, charCodes); |
+ } |
+ var expanded = []; |
for (var i in charCodes) { |
+ if (i <= MAX_CODE_UNIT) { |
+ expanded.add(i); |
+ } else { |
+ expanded.add(LEAD_BASE + |
+ (((i - SURROGATE_ENCODING_BASE) >> 10) & SURROGATE_MASK)); |
+ expanded.add(TRAIL_BASE + (i & SURROGATE_MASK)); |
+ } |
+ } |
+ return JS('String', r'String.fromCharCode.apply(#, #)', null, expanded); |
+ } |
+ |
+ static String stringFromCodeUnits(codeUnits) { |
+ for (var i in codeUnits) { |
if (i is !int) throw new ArgumentError(i); |
+ if (i > MAX_CODE_UNIT) throw new ArgumentError(i); |
} |
- return JS('String', r'String.fromCharCode.apply(#, #)', null, charCodes); |
+ return JS('String', r'String.fromCharCode.apply(#, #)', null, codeUnits); |
} |
static String getTimeZoneName(receiver) { |