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

Unified Diff: sdk/lib/_internal/compiler/implementation/lib/js_helper.dart

Issue 11415130: Dart2js: Fix stack overflow in new String.fromCharCodes bug=6919 (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
« no previous file with comments | « no previous file | tests/corelib/string_from_list_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 ea31fe24088f2941034de76a538745bf5acd89e5..7d838f891fecb121f1c7180ee638838f08abae08 100644
--- a/sdk/lib/_internal/compiler/implementation/lib/js_helper.dart
+++ b/sdk/lib/_internal/compiler/implementation/lib/js_helper.dart
@@ -535,7 +535,22 @@ class Primitives {
static num dateNow() => JS('num', r'Date.now()');
- static stringFromCodePoints(codePoints) {
+ // This is to fix http://dartbug.com/6919
floitsch 2012/11/26 12:01:28 Please add a little bit of context, so that you do
erikcorry 2012/12/03 12:37:24 Done.
+ static String _doFromCharCode(List<int> array) {
floitsch 2012/11/26 12:01:28 _fromCharCodeApply ?
erikcorry 2012/12/03 12:37:24 Done.
+ String acc = "";
floitsch 2012/11/26 12:01:28 result
erikcorry 2012/12/03 12:37:24 Done.
+ const kMaxApply = 500;
+ int end = array.length;
+ for (var i = 0; i < end; i += kMaxApply) {
+ var subarray = end <= kMaxApply ? array :
floitsch 2012/11/26 12:01:28 nit: I would prefer having an "if" there.
erikcorry 2012/12/03 12:37:24 Done.
+ JS('List<int>', r'array.slice(#, #)',
sra1 2012/12/03 16:22:44 JS('=List', ...) The result of Array.prototype.sl
+ i, i + kMaxApply < end ? i + kMaxApply: end);
+ acc = JS('String', '# + String.fromCharCode.apply(#, #)',
+ acc, null, subarray);
+ }
+ return acc;
+ }
+
+ static String stringFromCodePoints(codePoints) {
List<int> a = <int>[];
for (var i in codePoints) {
if (i is !int) throw new ArgumentError(i);
@@ -548,7 +563,7 @@ class Primitives {
throw new ArgumentError(i);
}
}
- return JS('String', r'String.fromCharCode.apply(#, #)', null, a);
+ _doFromCharCode(a);
}
static String stringFromCharCodes(charCodes) {
@@ -557,7 +572,7 @@ class Primitives {
if (i < 0) throw new ArgumentError(i);
if (i > 0xffff) return stringFromCodePoints(charCodes);
}
- return JS('String', r'String.fromCharCode.apply(#, #)', null, charCodes);
+ _doFromCharCode(a);
}
static String getTimeZoneName(receiver) {
« no previous file with comments | « no previous file | tests/corelib/string_from_list_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698