OLD | NEW |
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:_interceptors'); | 5 #library('dart:_interceptors'); |
6 | 6 |
7 #import('coreimpl.dart'); | 7 #import('coreimpl.dart'); |
8 #import('js_helper.dart'); | 8 #import('js_helper.dart'); |
9 | 9 |
10 add$1(var receiver, var value) { | 10 add$1(var receiver, var value) { |
11 if (isJsArray(receiver)) { | 11 if (isJsArray(receiver)) { |
12 checkGrowable(receiver, 'add'); | 12 checkGrowable(receiver, 'add'); |
13 JS('Object', r'#.push(#)', receiver, value); | 13 JS('Object', r'#.push(#)', receiver, value); |
14 return; | 14 return; |
15 } | 15 } |
16 return UNINTERCEPTED(receiver.add(value)); | 16 return UNINTERCEPTED(receiver.add(value)); |
17 } | 17 } |
18 | 18 |
19 removeAt$1(var receiver, var index) { | 19 removeAt$1(var receiver, var index) { |
20 if (isJsArray(receiver)) { | 20 if (isJsArray(receiver)) { |
21 if (index is !int) throw new IllegalArgumentException(index); | 21 if (index is !int) throw new ArgumentError(index); |
22 if (index < 0 || index >= receiver.length) { | 22 if (index < 0 || index >= receiver.length) { |
23 throw new IndexOutOfRangeException(index); | 23 throw new IndexOutOfRangeException(index); |
24 } | 24 } |
25 checkGrowable(receiver, 'removeAt'); | 25 checkGrowable(receiver, 'removeAt'); |
26 return JS("Object", r'#.splice(#, 1)[0]', receiver, index); | 26 return JS("Object", r'#.splice(#, 1)[0]', receiver, index); |
27 } | 27 } |
28 return UNINTERCEPTED(receiver.removeAt(index)); | 28 return UNINTERCEPTED(receiver.removeAt(index)); |
29 } | 29 } |
30 | 30 |
31 removeLast(var receiver) { | 31 removeLast(var receiver) { |
(...skipping 17 matching lines...) Expand all Loading... |
49 if (receiver is String || isJsArray(receiver)) { | 49 if (receiver is String || isJsArray(receiver)) { |
50 return JS('num', r'#.length', receiver); | 50 return JS('num', r'#.length', receiver); |
51 } else { | 51 } else { |
52 return UNINTERCEPTED(receiver.length); | 52 return UNINTERCEPTED(receiver.length); |
53 } | 53 } |
54 } | 54 } |
55 | 55 |
56 set$length(receiver, newLength) { | 56 set$length(receiver, newLength) { |
57 if (isJsArray(receiver)) { | 57 if (isJsArray(receiver)) { |
58 checkNull(newLength); // TODO(ahe): This is not specified but co19 tests it. | 58 checkNull(newLength); // TODO(ahe): This is not specified but co19 tests it. |
59 if (newLength is !int) throw new IllegalArgumentException(newLength); | 59 if (newLength is !int) throw new ArgumentError(newLength); |
60 if (newLength < 0) throw new IndexOutOfRangeException(newLength); | 60 if (newLength < 0) throw new IndexOutOfRangeException(newLength); |
61 checkGrowable(receiver, 'set length'); | 61 checkGrowable(receiver, 'set length'); |
62 JS('void', r'#.length = #', receiver, newLength); | 62 JS('void', r'#.length = #', receiver, newLength); |
63 } else { | 63 } else { |
64 UNINTERCEPTED(receiver.length = newLength); | 64 UNINTERCEPTED(receiver.length = newLength); |
65 } | 65 } |
66 return newLength; | 66 return newLength; |
67 } | 67 } |
68 | 68 |
69 toString(var value) { | 69 toString(var value) { |
(...skipping 16 matching lines...) Expand all Loading... |
86 | 86 |
87 iterator(receiver) { | 87 iterator(receiver) { |
88 if (isJsArray(receiver)) { | 88 if (isJsArray(receiver)) { |
89 return new ListIterator(receiver); | 89 return new ListIterator(receiver); |
90 } | 90 } |
91 return UNINTERCEPTED(receiver.iterator()); | 91 return UNINTERCEPTED(receiver.iterator()); |
92 } | 92 } |
93 | 93 |
94 charCodeAt(var receiver, int index) { | 94 charCodeAt(var receiver, int index) { |
95 if (receiver is String) { | 95 if (receiver is String) { |
96 if (index is !num) throw new IllegalArgumentException(index); | 96 if (index is !num) throw new ArgumentError(index); |
97 if (index < 0) throw new IndexOutOfRangeException(index); | 97 if (index < 0) throw new IndexOutOfRangeException(index); |
98 if (index >= receiver.length) throw new IndexOutOfRangeException(index); | 98 if (index >= receiver.length) throw new IndexOutOfRangeException(index); |
99 return JS('int', r'#.charCodeAt(#)', receiver, index); | 99 return JS('int', r'#.charCodeAt(#)', receiver, index); |
100 } else { | 100 } else { |
101 return UNINTERCEPTED(receiver.charCodeAt(index)); | 101 return UNINTERCEPTED(receiver.charCodeAt(index)); |
102 } | 102 } |
103 } | 103 } |
104 | 104 |
105 isEmpty(receiver) { | 105 isEmpty(receiver) { |
106 if (receiver is String || isJsArray(receiver)) { | 106 if (receiver is String || isJsArray(receiver)) { |
(...skipping 19 matching lines...) Expand all Loading... |
126 return 0; | 126 return 0; |
127 } else if (a.isNaN()) { | 127 } else if (a.isNaN()) { |
128 if (b.isNaN()) { | 128 if (b.isNaN()) { |
129 return 0; | 129 return 0; |
130 } | 130 } |
131 return 1; | 131 return 1; |
132 } else { | 132 } else { |
133 return -1; | 133 return -1; |
134 } | 134 } |
135 } else if (a is String) { | 135 } else if (a is String) { |
136 if (b is !String) throw new IllegalArgumentException(b); | 136 if (b is !String) throw new ArgumentError(b); |
137 return JS('bool', r'# == #', a, b) ? 0 | 137 return JS('bool', r'# == #', a, b) ? 0 |
138 : JS('bool', r'# < #', a, b) ? -1 : 1; | 138 : JS('bool', r'# < #', a, b) ? -1 : 1; |
139 } else { | 139 } else { |
140 return UNINTERCEPTED(a.compareTo(b)); | 140 return UNINTERCEPTED(a.compareTo(b)); |
141 } | 141 } |
142 } | 142 } |
143 | 143 |
144 addAll(receiver, collection) { | 144 addAll(receiver, collection) { |
145 if (!isJsArray(receiver)) return UNINTERCEPTED(receiver.addAll(collection)); | 145 if (!isJsArray(receiver)) return UNINTERCEPTED(receiver.addAll(collection)); |
146 | 146 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 } | 187 } |
188 } | 188 } |
189 | 189 |
190 getRange(receiver, start, length) { | 190 getRange(receiver, start, length) { |
191 if (!isJsArray(receiver)) { | 191 if (!isJsArray(receiver)) { |
192 return UNINTERCEPTED(receiver.getRange(start, length)); | 192 return UNINTERCEPTED(receiver.getRange(start, length)); |
193 } | 193 } |
194 if (0 === length) return []; | 194 if (0 === length) return []; |
195 checkNull(start); // TODO(ahe): This is not specified but co19 tests it. | 195 checkNull(start); // TODO(ahe): This is not specified but co19 tests it. |
196 checkNull(length); // TODO(ahe): This is not specified but co19 tests it. | 196 checkNull(length); // TODO(ahe): This is not specified but co19 tests it. |
197 if (start is !int) throw new IllegalArgumentException(start); | 197 if (start is !int) throw new ArgumentError(start); |
198 if (length is !int) throw new IllegalArgumentException(length); | 198 if (length is !int) throw new ArgumentError(length); |
199 if (length < 0) throw new IllegalArgumentException(length); | 199 if (length < 0) throw new ArgumentError(length); |
200 if (start < 0) throw new IndexOutOfRangeException(start); | 200 if (start < 0) throw new IndexOutOfRangeException(start); |
201 var end = start + length; | 201 var end = start + length; |
202 if (end > receiver.length) { | 202 if (end > receiver.length) { |
203 throw new IndexOutOfRangeException(length); | 203 throw new IndexOutOfRangeException(length); |
204 } | 204 } |
205 if (length < 0) throw new IllegalArgumentException(length); | 205 if (length < 0) throw new ArgumentError(length); |
206 return JS('Object', r'#.slice(#, #)', receiver, start, end); | 206 return JS('Object', r'#.slice(#, #)', receiver, start, end); |
207 } | 207 } |
208 | 208 |
209 indexOf$1(receiver, element) { | 209 indexOf$1(receiver, element) { |
210 if (isJsArray(receiver)) { | 210 if (isJsArray(receiver)) { |
211 var length = JS('num', r'#.length', receiver); | 211 var length = JS('num', r'#.length', receiver); |
212 return Arrays.indexOf(receiver, element, 0, length); | 212 return Arrays.indexOf(receiver, element, 0, length); |
213 } else if (receiver is String) { | 213 } else if (receiver is String) { |
214 checkNull(element); | 214 checkNull(element); |
215 if (element is !String) throw new IllegalArgumentException(element); | 215 if (element is !String) throw new ArgumentError(element); |
216 return JS('int', r'#.indexOf(#)', receiver, element); | 216 return JS('int', r'#.indexOf(#)', receiver, element); |
217 } | 217 } |
218 return UNINTERCEPTED(receiver.indexOf(element)); | 218 return UNINTERCEPTED(receiver.indexOf(element)); |
219 } | 219 } |
220 | 220 |
221 indexOf$2(receiver, element, start) { | 221 indexOf$2(receiver, element, start) { |
222 if (isJsArray(receiver)) { | 222 if (isJsArray(receiver)) { |
223 if (start is !int) throw new IllegalArgumentException(start); | 223 if (start is !int) throw new ArgumentError(start); |
224 var length = JS('num', r'#.length', receiver); | 224 var length = JS('num', r'#.length', receiver); |
225 return Arrays.indexOf(receiver, element, start, length); | 225 return Arrays.indexOf(receiver, element, start, length); |
226 } else if (receiver is String) { | 226 } else if (receiver is String) { |
227 checkNull(element); | 227 checkNull(element); |
228 if (start is !int) throw new IllegalArgumentException(start); | 228 if (start is !int) throw new ArgumentError(start); |
229 if (element is !String) throw new IllegalArgumentException(element); | 229 if (element is !String) throw new ArgumentError(element); |
230 if (start < 0) return -1; // TODO(ahe): Is this correct? | 230 if (start < 0) return -1; // TODO(ahe): Is this correct? |
231 return JS('int', r'#.indexOf(#, #)', receiver, element, start); | 231 return JS('int', r'#.indexOf(#, #)', receiver, element, start); |
232 } | 232 } |
233 return UNINTERCEPTED(receiver.indexOf(element, start)); | 233 return UNINTERCEPTED(receiver.indexOf(element, start)); |
234 } | 234 } |
235 | 235 |
236 insertRange$2(receiver, start, length) { | 236 insertRange$2(receiver, start, length) { |
237 if (isJsArray(receiver)) { | 237 if (isJsArray(receiver)) { |
238 return insertRange$3(receiver, start, length, null); | 238 return insertRange$3(receiver, start, length, null); |
239 } | 239 } |
(...skipping 13 matching lines...) Expand all Loading... |
253 } | 253 } |
254 return receiver[receiver.length - 1]; | 254 return receiver[receiver.length - 1]; |
255 } | 255 } |
256 | 256 |
257 lastIndexOf$1(receiver, element) { | 257 lastIndexOf$1(receiver, element) { |
258 if (isJsArray(receiver)) { | 258 if (isJsArray(receiver)) { |
259 var start = JS('num', r'#.length', receiver); | 259 var start = JS('num', r'#.length', receiver); |
260 return Arrays.lastIndexOf(receiver, element, start); | 260 return Arrays.lastIndexOf(receiver, element, start); |
261 } else if (receiver is String) { | 261 } else if (receiver is String) { |
262 checkNull(element); | 262 checkNull(element); |
263 if (element is !String) throw new IllegalArgumentException(element); | 263 if (element is !String) throw new ArgumentError(element); |
264 return JS('int', r'#.lastIndexOf(#)', receiver, element); | 264 return JS('int', r'#.lastIndexOf(#)', receiver, element); |
265 } | 265 } |
266 return UNINTERCEPTED(receiver.lastIndexOf(element)); | 266 return UNINTERCEPTED(receiver.lastIndexOf(element)); |
267 } | 267 } |
268 | 268 |
269 lastIndexOf$2(receiver, element, start) { | 269 lastIndexOf$2(receiver, element, start) { |
270 if (isJsArray(receiver)) { | 270 if (isJsArray(receiver)) { |
271 return Arrays.lastIndexOf(receiver, element, start); | 271 return Arrays.lastIndexOf(receiver, element, start); |
272 } else if (receiver is String) { | 272 } else if (receiver is String) { |
273 checkNull(element); | 273 checkNull(element); |
274 if (element is !String) throw new IllegalArgumentException(element); | 274 if (element is !String) throw new ArgumentError(element); |
275 if (start !== null) { | 275 if (start !== null) { |
276 if (start is !num) throw new IllegalArgumentException(start); | 276 if (start is !num) throw new ArgumentError(start); |
277 if (start < 0) return -1; | 277 if (start < 0) return -1; |
278 if (start >= receiver.length) { | 278 if (start >= receiver.length) { |
279 if (element == "") return receiver.length; | 279 if (element == "") return receiver.length; |
280 start = receiver.length - 1; | 280 start = receiver.length - 1; |
281 } | 281 } |
282 } | 282 } |
283 return stringLastIndexOfUnchecked(receiver, element, start); | 283 return stringLastIndexOfUnchecked(receiver, element, start); |
284 } | 284 } |
285 return UNINTERCEPTED(receiver.lastIndexOf(element, start)); | 285 return UNINTERCEPTED(receiver.lastIndexOf(element, start)); |
286 } | 286 } |
287 | 287 |
288 removeRange(receiver, start, length) { | 288 removeRange(receiver, start, length) { |
289 if (!isJsArray(receiver)) { | 289 if (!isJsArray(receiver)) { |
290 return UNINTERCEPTED(receiver.removeRange(start, length)); | 290 return UNINTERCEPTED(receiver.removeRange(start, length)); |
291 } | 291 } |
292 checkGrowable(receiver, 'removeRange'); | 292 checkGrowable(receiver, 'removeRange'); |
293 if (length == 0) { | 293 if (length == 0) { |
294 return; | 294 return; |
295 } | 295 } |
296 checkNull(start); // TODO(ahe): This is not specified but co19 tests it. | 296 checkNull(start); // TODO(ahe): This is not specified but co19 tests it. |
297 checkNull(length); // TODO(ahe): This is not specified but co19 tests it. | 297 checkNull(length); // TODO(ahe): This is not specified but co19 tests it. |
298 if (start is !int) throw new IllegalArgumentException(start); | 298 if (start is !int) throw new ArgumentError(start); |
299 if (length is !int) throw new IllegalArgumentException(length); | 299 if (length is !int) throw new ArgumentError(length); |
300 if (length < 0) throw new IllegalArgumentException(length); | 300 if (length < 0) throw new ArgumentError(length); |
301 var receiverLength = JS('num', r'#.length', receiver); | 301 var receiverLength = JS('num', r'#.length', receiver); |
302 if (start < 0 || start >= receiverLength) { | 302 if (start < 0 || start >= receiverLength) { |
303 throw new IndexOutOfRangeException(start); | 303 throw new IndexOutOfRangeException(start); |
304 } | 304 } |
305 if (start + length > receiverLength) { | 305 if (start + length > receiverLength) { |
306 throw new IndexOutOfRangeException(start + length); | 306 throw new IndexOutOfRangeException(start + length); |
307 } | 307 } |
308 Arrays.copy(receiver, | 308 Arrays.copy(receiver, |
309 start + length, | 309 start + length, |
310 receiver, | 310 receiver, |
(...skipping 13 matching lines...) Expand all Loading... |
324 if (!isJsArray(receiver)) { | 324 if (!isJsArray(receiver)) { |
325 return UNINTERCEPTED(receiver.setRange(start, length, from, startFrom)); | 325 return UNINTERCEPTED(receiver.setRange(start, length, from, startFrom)); |
326 } | 326 } |
327 | 327 |
328 checkMutable(receiver, 'indexed set'); | 328 checkMutable(receiver, 'indexed set'); |
329 if (length === 0) return; | 329 if (length === 0) return; |
330 checkNull(start); // TODO(ahe): This is not specified but co19 tests it. | 330 checkNull(start); // TODO(ahe): This is not specified but co19 tests it. |
331 checkNull(length); // TODO(ahe): This is not specified but co19 tests it. | 331 checkNull(length); // TODO(ahe): This is not specified but co19 tests it. |
332 checkNull(from); // TODO(ahe): This is not specified but co19 tests it. | 332 checkNull(from); // TODO(ahe): This is not specified but co19 tests it. |
333 checkNull(startFrom); // TODO(ahe): This is not specified but co19 tests it. | 333 checkNull(startFrom); // TODO(ahe): This is not specified but co19 tests it. |
334 if (start is !int) throw new IllegalArgumentException(start); | 334 if (start is !int) throw new ArgumentError(start); |
335 if (length is !int) throw new IllegalArgumentException(length); | 335 if (length is !int) throw new ArgumentError(length); |
336 if (startFrom is !int) throw new IllegalArgumentException(startFrom); | 336 if (startFrom is !int) throw new ArgumentError(startFrom); |
337 if (length < 0) throw new IllegalArgumentException(length); | 337 if (length < 0) throw new ArgumentError(length); |
338 if (start < 0) throw new IndexOutOfRangeException(start); | 338 if (start < 0) throw new IndexOutOfRangeException(start); |
339 if (start + length > receiver.length) { | 339 if (start + length > receiver.length) { |
340 throw new IndexOutOfRangeException(start + length); | 340 throw new IndexOutOfRangeException(start + length); |
341 } | 341 } |
342 | 342 |
343 Arrays.copy(from, startFrom, receiver, start, length); | 343 Arrays.copy(from, startFrom, receiver, start, length); |
344 } | 344 } |
345 | 345 |
346 some(receiver, f) { | 346 some(receiver, f) { |
347 if (!isJsArray(receiver)) { | 347 if (!isJsArray(receiver)) { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 receiver, fractionDigits); | 484 receiver, fractionDigits); |
485 if (receiver == 0 && receiver.isNegative()) return "-$result"; | 485 if (receiver == 0 && receiver.isNegative()) return "-$result"; |
486 return result; | 486 return result; |
487 } | 487 } |
488 | 488 |
489 toRadixString(receiver, radix) { | 489 toRadixString(receiver, radix) { |
490 if (receiver is !num) { | 490 if (receiver is !num) { |
491 return UNINTERCEPTED(receiver.toRadixString(radix)); | 491 return UNINTERCEPTED(receiver.toRadixString(radix)); |
492 } | 492 } |
493 checkNum(radix); | 493 checkNum(radix); |
494 if (radix < 2 || radix > 36) throw new IllegalArgumentException(radix); | 494 if (radix < 2 || radix > 36) throw new ArgumentError(radix); |
495 return JS('String', r'#.toString(#)', receiver, radix); | 495 return JS('String', r'#.toString(#)', receiver, radix); |
496 } | 496 } |
497 | 497 |
498 allMatches(receiver, str) { | 498 allMatches(receiver, str) { |
499 if (receiver is !String) return UNINTERCEPTED(receiver.allMatches(str)); | 499 if (receiver is !String) return UNINTERCEPTED(receiver.allMatches(str)); |
500 checkString(str); | 500 checkString(str); |
501 return allMatchesInStringUnchecked(receiver, str); | 501 return allMatchesInStringUnchecked(receiver, str); |
502 } | 502 } |
503 | 503 |
504 concat(receiver, other) { | 504 concat(receiver, other) { |
505 if (receiver is !String) return UNINTERCEPTED(receiver.concat(other)); | 505 if (receiver is !String) return UNINTERCEPTED(receiver.concat(other)); |
506 | 506 |
507 if (other is !String) throw new IllegalArgumentException(other); | 507 if (other is !String) throw new ArgumentError(other); |
508 return JS('String', r'# + #', receiver, other); | 508 return JS('String', r'# + #', receiver, other); |
509 } | 509 } |
510 | 510 |
511 contains$1(receiver, other) { | 511 contains$1(receiver, other) { |
512 if (receiver is !String) { | 512 if (receiver is !String) { |
513 return UNINTERCEPTED(receiver.contains(other)); | 513 return UNINTERCEPTED(receiver.contains(other)); |
514 } | 514 } |
515 return contains$2(receiver, other, 0); | 515 return contains$2(receiver, other, 0); |
516 } | 516 } |
517 | 517 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 } else if (receiver is String) { | 659 } else if (receiver is String) { |
660 return getOrCreateCachedRuntimeType('String'); | 660 return getOrCreateCachedRuntimeType('String'); |
661 } else if (receiver is double) { | 661 } else if (receiver is double) { |
662 return getOrCreateCachedRuntimeType('double'); | 662 return getOrCreateCachedRuntimeType('double'); |
663 } else if (receiver is List) { | 663 } else if (receiver is List) { |
664 return getOrCreateCachedRuntimeType('List'); | 664 return getOrCreateCachedRuntimeType('List'); |
665 } else { | 665 } else { |
666 return UNINTERCEPTED(receiver.runtimeType()); | 666 return UNINTERCEPTED(receiver.runtimeType()); |
667 } | 667 } |
668 } | 668 } |
OLD | NEW |