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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/lib/js_helper.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 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 #library('dart:_js_helper'); 5 #library('dart:_js_helper');
6 6
7 #import('dart:coreimpl'); 7 #import('dart:coreimpl');
8 #import('dart:collection'); 8 #import('dart:collection');
9 9
10 #source('constant_map.dart'); 10 #source('constant_map.dart');
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 if ((length is !int) || (length < 0)) { 527 if ((length is !int) || (length < 0)) {
528 throw new ArgumentError(length); 528 throw new ArgumentError(length);
529 } 529 }
530 var result = JS('Object', r'new Array(#)', length); 530 var result = JS('Object', r'new Array(#)', length);
531 JS('void', r'#.fixed$length = #', result, true); 531 JS('void', r'#.fixed$length = #', result, true);
532 return result; 532 return result;
533 } 533 }
534 534
535 static num dateNow() => JS('num', r'Date.now()'); 535 static num dateNow() => JS('num', r'Date.now()');
536 536
537 static const MAX_CODE_UNIT = 0xffff;
538 static const MAX_CODE_POINT = 0x10ffff;
539 static const SURROGATE_BASE = 0xd800;
540 static const SURROGATE_END = 0xdfff;
541 static const LEAD_BASE = 0xd800;
542 static const TRAIL_BASE = 0xdc00;
543 static const SURROGATE_MASK = 0x3ff;
544 static const SURROGATE_ENCODING_BASE = 0x10000;
545
537 static String stringFromCharCodes(charCodes) { 546 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
547 bool surrogatePairs = false;
538 for (var i in charCodes) { 548 for (var i in charCodes) {
539 if (i is !int) throw new ArgumentError(i); 549 if (i is !int) throw new ArgumentError(i);
550 if (i > MAX_CODE_POINT) throw new ArgumentError(i);
551 if (i > MAX_CODE_UNIT) surrogatePairs = true;
552 if (i >= SURROGATE_BASE && i <= SURROGATE_END) throw new ArgumentError(i);
540 } 553 }
541 return JS('String', r'String.fromCharCode.apply(#, #)', null, charCodes); 554 if (!surrogatePairs) {
555 return JS('String', r'String.fromCharCode.apply(#, #)', null, charCodes);
556 }
557 var expanded = [];
558 for (var i in charCodes) {
559 if (i <= MAX_CODE_UNIT) {
560 expanded.add(i);
561 } else {
562 expanded.add(LEAD_BASE +
563 (((i - SURROGATE_ENCODING_BASE) >> 10) & SURROGATE_MASK));
564 expanded.add(TRAIL_BASE + (i & SURROGATE_MASK));
565 }
566 }
567 return JS('String', r'String.fromCharCode.apply(#, #)', null, expanded);
568 }
569
570 static String stringFromCodeUnits(codeUnits) {
571 for (var i in codeUnits) {
572 if (i is !int) throw new ArgumentError(i);
573 if (i > MAX_CODE_UNIT) throw new ArgumentError(i);
574 }
575 return JS('String', r'String.fromCharCode.apply(#, #)', null, codeUnits);
542 } 576 }
543 577
544 static String getTimeZoneName(receiver) { 578 static String getTimeZoneName(receiver) {
545 // When calling toString on a Date it will emit the timezone in parenthesis. 579 // When calling toString on a Date it will emit the timezone in parenthesis.
546 // Example: "Wed May 16 2012 21:13:00 GMT+0200 (CEST)". 580 // Example: "Wed May 16 2012 21:13:00 GMT+0200 (CEST)".
547 // We extract this name using a regexp. 581 // We extract this name using a regexp.
548 var d = lazyAsJsDate(receiver); 582 var d = lazyAsJsDate(receiver);
549 return JS('String', r'/\((.*)\)/.exec(#.toString())[1]', d); 583 return JS('String', r'/\((.*)\)/.exec(#.toString())[1]', d);
550 } 584 }
551 585
(...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after
1477 result = new TypeImpl(key); 1511 result = new TypeImpl(key);
1478 JS('var', r'#[#] = #', runtimeTypeCache, key, result); 1512 JS('var', r'#[#] = #', runtimeTypeCache, key, result);
1479 } 1513 }
1480 return result; 1514 return result;
1481 } 1515 }
1482 1516
1483 String getRuntimeTypeString(var object) { 1517 String getRuntimeTypeString(var object) {
1484 var typeInfo = JS('Object', r'#.builtin$typeInfo', object); 1518 var typeInfo = JS('Object', r'#.builtin$typeInfo', object);
1485 return JS('String', r'#.runtimeType', typeInfo); 1519 return JS('String', r'#.runtimeType', typeInfo);
1486 } 1520 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698