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

Unified Diff: sdk/lib/_internal/compiler/js_lib/js_number.dart

Issue 87523003: Change dart2js int.toRadixString to not return spurious format on IE. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update CL Created 5 years, 11 months 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/corelib.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/compiler/js_lib/js_number.dart
diff --git a/sdk/lib/_internal/compiler/js_lib/js_number.dart b/sdk/lib/_internal/compiler/js_lib/js_number.dart
index 81adc2b979c219c52be1f030b37ed02f8a045ab5..63afa4b29b2dabdb6e67a2024dbfac06efa961d5 100644
--- a/sdk/lib/_internal/compiler/js_lib/js_number.dart
+++ b/sdk/lib/_internal/compiler/js_lib/js_number.dart
@@ -110,8 +110,7 @@ class JSNumber extends Interceptor implements num {
toDouble() => this;
String toStringAsFixed(int fractionDigits) {
- checkNum(fractionDigits);
- // TODO(floitsch): fractionDigits must be an integer.
+ checkInt(fractionDigits);
if (fractionDigits < 0 || fractionDigits > 20) {
throw new RangeError(fractionDigits);
}
@@ -123,8 +122,7 @@ class JSNumber extends Interceptor implements num {
String toStringAsExponential([int fractionDigits]) {
String result;
if (fractionDigits != null) {
- // TODO(floitsch): fractionDigits must be an integer.
- checkNum(fractionDigits);
+ checkInt(fractionDigits);
if (fractionDigits < 0 || fractionDigits > 20) {
throw new RangeError(fractionDigits);
}
@@ -137,8 +135,7 @@ class JSNumber extends Interceptor implements num {
}
String toStringAsPrecision(int precision) {
- // TODO(floitsch): precision must be an integer.
- checkNum(precision);
+ checkInt(precision);
if (precision < 1 || precision > 21) {
throw new RangeError(precision);
}
@@ -149,9 +146,33 @@ class JSNumber extends Interceptor implements num {
}
String toRadixString(int radix) {
- checkNum(radix);
+ checkInt(radix);
if (radix < 2 || radix > 36) throw new RangeError(radix);
- return JS('String', r'#.toString(#)', this, radix);
+ String result = JS('String', r'#.toString(#)', this, radix);
+ const int rightParenCode = 0x29;
+ if (result.codeUnitAt(result.length - 1) != rightParenCode) {
+ return result;
+ }
+ return _handleIEtoString(result);
+ }
+
+ static String _handleIEtoString(String result) {
+ // Result is probably IE's untraditional format for large numbers,
+ // e.g., "8.0000000000008(e+15)" for 0x8000000000000800.toString(16).
+ var match = JS('List|Null',
+ r'/^([\da-z]+)(?:\.([\da-z]+))?\(e\+(\d+)\)$/.exec(#)',
+ result);
+ if (match == null) {
+ // Then we don't know how to handle it at all.
+ throw new UnsupportedError("Unexpected toString result: $result");
+ }
+ String result = JS('String', '#', match[1]);
+ int exponent = JS("int", "+#", match[3]);
+ if (match[2] != null) {
+ result = JS('String', '# + #', result, match[2]);
+ exponent -= JS('int', '#.length', match[2]);
+ }
+ return result + "0" * exponent;
}
// Note: if you change this, also change the function [S].
« no previous file with comments | « no previous file | tests/corelib/corelib.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698