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

Side by Side Diff: tool/input_sdk/private/js_helper.dart

Issue 1348453004: fix some errors in our SDK, mostly around numbers (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 3 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 unified diff | Download patch
« no previous file with comments | « tool/input_sdk/private/js_array.dart ('k') | tool/input_sdk/private/js_number.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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:collection'; 7 import 'dart:collection';
8 8
9 import 'dart:_foreign_helper' show 9 import 'dart:_foreign_helper' show
10 JS, 10 JS,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 source); 77 source);
78 int digitsIndex = 1; 78 int digitsIndex = 1;
79 int hexIndex = 2; 79 int hexIndex = 2;
80 int decimalIndex = 3; 80 int decimalIndex = 3;
81 int nonDecimalHexIndex = 4; 81 int nonDecimalHexIndex = 4;
82 if (radix == null) { 82 if (radix == null) {
83 radix = 10; 83 radix = 10;
84 if (match != null) { 84 if (match != null) {
85 if (match[hexIndex] != null) { 85 if (match[hexIndex] != null) {
86 // Cannot fail because we know that the digits are all hex. 86 // Cannot fail because we know that the digits are all hex.
87 return JS('num', r'parseInt(#, 16)', source); 87 return JS('int', r'parseInt(#, 16)', source);
88 } 88 }
89 if (match[decimalIndex] != null) { 89 if (match[decimalIndex] != null) {
90 // Cannot fail because we know that the digits are all decimal. 90 // Cannot fail because we know that the digits are all decimal.
91 return JS('num', r'parseInt(#, 10)', source); 91 return JS('int', r'parseInt(#, 10)', source);
92 } 92 }
93 return handleError(source); 93 return handleError(source);
94 } 94 }
95 } else { 95 } else {
96 if (radix is! int) throw new ArgumentError("Radix is not an integer"); 96 if (radix is! int) throw new ArgumentError("Radix is not an integer");
97 if (radix < 2 || radix > 36) { 97 if (radix < 2 || radix > 36) {
98 throw new RangeError("Radix $radix not in range 2..36"); 98 throw new RangeError("Radix $radix not in range 2..36");
99 } 99 }
100 if (match != null) { 100 if (match != null) {
101 if (radix == 10 && match[decimalIndex] != null) { 101 if (radix == 10 && match[decimalIndex] != null) {
102 // Cannot fail because we know that the digits are all decimal. 102 // Cannot fail because we know that the digits are all decimal.
103 return JS('num', r'parseInt(#, 10)', source); 103 return JS('int', r'parseInt(#, 10)', source);
104 } 104 }
105 if (radix < 10 || match[decimalIndex] == null) { 105 if (radix < 10 || match[decimalIndex] == null) {
106 // We know that the characters must be ASCII as otherwise the 106 // We know that the characters must be ASCII as otherwise the
107 // regexp wouldn't have matched. Lowercasing by doing `| 0x20` is thus 107 // regexp wouldn't have matched. Lowercasing by doing `| 0x20` is thus
108 // guaranteed to be a safe operation, since it preserves digits 108 // guaranteed to be a safe operation, since it preserves digits
109 // and lower-cases ASCII letters. 109 // and lower-cases ASCII letters.
110 int maxCharCode; 110 int maxCharCode;
111 if (radix <= 10) { 111 if (radix <= 10) {
112 // Allow all digits less than the radix. For example 0, 1, 2 for 112 // Allow all digits less than the radix. For example 0, 1, 2 for
113 // radix 3. 113 // radix 3.
(...skipping 11 matching lines...) Expand all
125 for (int i = 0; i < digitsPart.length; i++) { 125 for (int i = 0; i < digitsPart.length; i++) {
126 int characterCode = digitsPart.codeUnitAt(0) | 0x20; 126 int characterCode = digitsPart.codeUnitAt(0) | 0x20;
127 if (digitsPart.codeUnitAt(i) > maxCharCode) { 127 if (digitsPart.codeUnitAt(i) > maxCharCode) {
128 return handleError(source); 128 return handleError(source);
129 } 129 }
130 } 130 }
131 } 131 }
132 } 132 }
133 } 133 }
134 if (match == null) return handleError(source); 134 if (match == null) return handleError(source);
135 return JS('num', r'parseInt(#, #)', source, radix); 135 return JS('int', r'parseInt(#, #)', source, radix);
136 } 136 }
137 137
138 static double parseDouble(String source, double handleError(String source)) { 138 static double parseDouble(String source, double handleError(String source)) {
139 checkString(source); 139 checkString(source);
140 // TODO(vsm): Make _throwFormatException generic and use directly 140 // TODO(vsm): Make _throwFormatException generic and use directly
141 // to avoid closure allocation. 141 // to avoid closure allocation.
142 if (handleError == null) handleError = (s) => _throwFormatException(s); 142 if (handleError == null) handleError = (s) => _throwFormatException(s);
143 // Notice that JS parseFloat accepts garbage at the end of the string. 143 // Notice that JS parseFloat accepts garbage at the end of the string.
144 // Accept only: 144 // Accept only:
145 // - [+/-]NaN 145 // - [+/-]NaN
(...skipping 27 matching lines...) Expand all
173 return getRuntimeType(object).toString(); 173 return getRuntimeType(object).toString();
174 } 174 }
175 175
176 /// In minified mode, uses the unminified names if available. 176 /// In minified mode, uses the unminified names if available.
177 static String objectToString(Object object) { 177 static String objectToString(Object object) {
178 // String name = objectTypeName(object); 178 // String name = objectTypeName(object);
179 String name = JS('String', 'dart.typeName(dart.realRuntimeType(#))', object) ; 179 String name = JS('String', 'dart.typeName(dart.realRuntimeType(#))', object) ;
180 return "Instance of '$name'"; 180 return "Instance of '$name'";
181 } 181 }
182 182
183 static num dateNow() => JS('int', r'Date.now()'); 183 static int dateNow() => JS('int', r'Date.now()');
184 184
185 static void initTicker() { 185 static void initTicker() {
186 if (timerFrequency != null) return; 186 if (timerFrequency != null) return;
187 // Start with low-resolution. We overwrite the fields if we find better. 187 // Start with low-resolution. We overwrite the fields if we find better.
188 timerFrequency = 1000; 188 timerFrequency = 1000;
189 timerTicks = dateNow; 189 timerTicks = dateNow;
190 if (JS('bool', 'typeof window == "undefined"')) return; 190 if (JS('bool', 'typeof window == "undefined"')) return;
191 var jsWindow = JS('var', 'window'); 191 var jsWindow = JS('var', 'window');
192 if (jsWindow == null) return; 192 if (jsWindow == null) return;
193 var performance = JS('var', '#.performance', jsWindow); 193 var performance = JS('var', '#.performance', jsWindow);
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 788
789 SyncIterable(this._generator, this._args); 789 SyncIterable(this._generator, this._args);
790 790
791 // TODO(jmesserly): this should be [Symbol.iterator]() method. Unfortunately 791 // TODO(jmesserly): this should be [Symbol.iterator]() method. Unfortunately
792 // we have no way of telling the compiler yet, so it will generate an extra 792 // we have no way of telling the compiler yet, so it will generate an extra
793 // layer of indirection that wraps the SyncIterator. 793 // layer of indirection that wraps the SyncIterator.
794 _jsIterator() => JS('', '#(...#)', _generator, _args); 794 _jsIterator() => JS('', '#(...#)', _generator, _args);
795 795
796 Iterator<E> get iterator => new SyncIterator<E>(_jsIterator()); 796 Iterator<E> get iterator => new SyncIterator<E>(_jsIterator());
797 } 797 }
OLDNEW
« no previous file with comments | « tool/input_sdk/private/js_array.dart ('k') | tool/input_sdk/private/js_number.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698