| Index: lib/compiler/implementation/lib/js_helper.dart
|
| diff --git a/lib/compiler/implementation/lib/js_helper.dart b/lib/compiler/implementation/lib/js_helper.dart
|
| index f818cdba5b875e159a95e8c5a23ceac6c00d8374..e9570715466ff9dc8ffb46edfcbe07ea6424f4fc 100644
|
| --- a/lib/compiler/implementation/lib/js_helper.dart
|
| +++ b/lib/compiler/implementation/lib/js_helper.dart
|
| @@ -29,10 +29,12 @@ bool checkNumbers(var a, var b) {
|
| return false;
|
| }
|
|
|
| +
|
| bool isJsArray(var value) {
|
| return value !== null && JS('bool', @'#.constructor === Array', value);
|
| }
|
|
|
| +
|
| add(var a, var b) {
|
| if (checkNumbers(a, b)) {
|
| return JS('num', @'# + #', a, b);
|
| @@ -246,14 +248,80 @@ checkMutable(list, reason) {
|
| }
|
| }
|
|
|
| +builtin$add$1(var receiver, var value) {
|
| + if (isJsArray(receiver)) {
|
| + checkGrowable(receiver, 'add');
|
| + JS('Object', @'#.push(#)', receiver, value);
|
| + return;
|
| + }
|
| + return UNINTERCEPTED(receiver.add(value));
|
| +}
|
| +
|
| +builtin$removeLast$0(var receiver) {
|
| + if (isJsArray(receiver)) {
|
| + checkGrowable(receiver, 'removeLast');
|
| + if (receiver.length === 0) throw new IndexOutOfRangeException(-1);
|
| + return JS('Object', @'#.pop()', receiver);
|
| + }
|
| + return UNINTERCEPTED(receiver.removeLast());
|
| +}
|
| +
|
| +builtin$filter$1(var receiver, var predicate) {
|
| + if (!isJsArray(receiver)) {
|
| + return UNINTERCEPTED(receiver.filter(predicate));
|
| + } else {
|
| + return Collections.filter(receiver, [], predicate);
|
| + }
|
| +}
|
| +
|
| +
|
| +builtin$get$length(var receiver) {
|
| + if (receiver is String || isJsArray(receiver)) {
|
| + return JS('num', @'#.length', receiver);
|
| + } else {
|
| + return UNINTERCEPTED(receiver.length);
|
| + }
|
| +}
|
| +
|
| +builtin$set$length(receiver, newLength) {
|
| + if (isJsArray(receiver)) {
|
| + checkNull(newLength); // TODO(ahe): This is not specified but co19 tests it.
|
| + if (newLength is !int) throw new IllegalArgumentException(newLength);
|
| + if (newLength < 0) throw new IndexOutOfRangeException(newLength);
|
| + checkGrowable(receiver, 'set length');
|
| + JS('void', @'#.length = #', receiver, newLength);
|
| + } else {
|
| + UNINTERCEPTED(receiver.length = newLength);
|
| + }
|
| + return newLength;
|
| +}
|
| +
|
| checkGrowable(list, reason) {
|
| if (JS('bool', @'!!(#.fixed$length)', list)) {
|
| throw new UnsupportedOperationException(reason);
|
| }
|
| }
|
|
|
| +builtin$toString$0(var value) {
|
| + if (JS('bool', @'typeof # == "object"', value)) {
|
| + if (isJsArray(value)) {
|
| + return Collections.collectionToString(value);
|
| + } else {
|
| + return UNINTERCEPTED(value.toString());
|
| + }
|
| + }
|
| + if (JS('bool', @'# === 0 && (1 / #) < 0', value, value)) {
|
| + return '-0.0';
|
| + }
|
| + if (value === null) return 'null';
|
| + if (JS('bool', @'typeof # == "function"', value)) {
|
| + return 'Closure';
|
| + }
|
| + return JS('string', @'String(#)', value);
|
| +}
|
| +
|
| String stringToString(value) {
|
| - var res = value.toString();
|
| + var res = builtin$toString$0(value);
|
| if (res is !String) throw new IllegalArgumentException(value);
|
| return res;
|
| }
|
| @@ -264,6 +332,12 @@ String stringConcat(String receiver, String other) {
|
| return JS('String', @'# + #', receiver, other);
|
| }
|
|
|
| +builtin$iterator$0(receiver) {
|
| + if (isJsArray(receiver)) {
|
| + return new ListIterator(receiver);
|
| + }
|
| + return UNINTERCEPTED(receiver.iterator());
|
| +}
|
|
|
| class ListIterator<T> implements Iterator<T> {
|
| int i;
|
| @@ -278,6 +352,24 @@ class ListIterator<T> implements Iterator<T> {
|
| }
|
| }
|
|
|
| +builtin$charCodeAt$1(var receiver, int index) {
|
| + if (receiver is String) {
|
| + if (index is !num) throw new IllegalArgumentException(index);
|
| + if (index < 0) throw new IndexOutOfRangeException(index);
|
| + if (index >= receiver.length) throw new IndexOutOfRangeException(index);
|
| + return JS('int', @'#.charCodeAt(#)', receiver, index);
|
| + } else {
|
| + return UNINTERCEPTED(receiver.charCodeAt(index));
|
| + }
|
| +}
|
| +
|
| +builtin$isEmpty$0(receiver) {
|
| + if (receiver is String || isJsArray(receiver)) {
|
| + return JS('bool', @'#.length === 0', receiver);
|
| + }
|
| + return UNINTERCEPTED(receiver.isEmpty());
|
| +}
|
| +
|
| class Primitives {
|
| static void printString(String string) {
|
| var hasConsole = JS('bool', @'typeof console == "object"');
|
| @@ -434,6 +526,38 @@ class Primitives {
|
| }
|
| }
|
|
|
| +builtin$compareTo$1(a, b) {
|
| + if (checkNumbers(a, b)) {
|
| + if (a < b) {
|
| + return -1;
|
| + } else if (a > b) {
|
| + return 1;
|
| + } else if (a == b) {
|
| + if (a == 0) {
|
| + bool aIsNegative = a.isNegative();
|
| + bool bIsNegative = b.isNegative();
|
| + if (aIsNegative == bIsNegative) return 0;
|
| + if (aIsNegative) return -1;
|
| + return 1;
|
| + }
|
| + return 0;
|
| + } else if (a.isNaN()) {
|
| + if (b.isNaN()) {
|
| + return 0;
|
| + }
|
| + return 1;
|
| + } else {
|
| + return -1;
|
| + }
|
| + } else if (a is String) {
|
| + if (b is !String) throw new IllegalArgumentException(b);
|
| + return JS('bool', @'# == #', a, b) ? 0
|
| + : JS('bool', @'# < #', a, b) ? -1 : 1;
|
| + } else {
|
| + return UNINTERCEPTED(a.compareTo(b));
|
| + }
|
| +}
|
| +
|
| /**
|
| * Called by generated code to throw an illegal-argument exception,
|
| * for example, if a non-integer index is given to an optimized
|
| @@ -452,6 +576,99 @@ ioore(index) {
|
| throw new IndexOutOfRangeException(index);
|
| }
|
|
|
| +builtin$addAll$1(receiver, collection) {
|
| + if (!isJsArray(receiver)) return UNINTERCEPTED(receiver.addAll(collection));
|
| +
|
| + // TODO(ahe): Use for-in when it is implemented correctly.
|
| + var iterator = collection.iterator();
|
| + while (iterator.hasNext()) {
|
| + receiver.add(iterator.next());
|
| + }
|
| +}
|
| +
|
| +builtin$addLast$1(receiver, value) {
|
| + if (!isJsArray(receiver)) return UNINTERCEPTED(receiver.addLast(value));
|
| +
|
| + checkGrowable(receiver, 'addLast');
|
| + JS('Object', @'#.push(#)', receiver, value);
|
| +}
|
| +
|
| +builtin$clear$0(receiver) {
|
| + if (!isJsArray(receiver)) return UNINTERCEPTED(receiver.clear());
|
| + receiver.length = 0;
|
| +}
|
| +
|
| +builtin$forEach$1(receiver, f) {
|
| + if (!isJsArray(receiver)) {
|
| + return UNINTERCEPTED(receiver.forEach(f));
|
| + } else {
|
| + return Collections.forEach(receiver, f);
|
| + }
|
| +}
|
| +
|
| +builtin$map$1(receiver, f) {
|
| + if (!isJsArray(receiver)) {
|
| + return UNINTERCEPTED(receiver.map(f));
|
| + } else {
|
| + return Collections.map(receiver, [], f);
|
| + }
|
| +}
|
| +
|
| +builtin$getRange$2(receiver, start, length) {
|
| + if (!isJsArray(receiver)) {
|
| + return UNINTERCEPTED(receiver.getRange(start, length));
|
| + }
|
| + if (0 === length) return [];
|
| + checkNull(start); // TODO(ahe): This is not specified but co19 tests it.
|
| + checkNull(length); // TODO(ahe): This is not specified but co19 tests it.
|
| + if (start is !int) throw new IllegalArgumentException(start);
|
| + if (length is !int) throw new IllegalArgumentException(length);
|
| + if (length < 0) throw new IllegalArgumentException(length);
|
| + if (start < 0) throw new IndexOutOfRangeException(start);
|
| + var end = start + length;
|
| + if (end > receiver.length) {
|
| + throw new IndexOutOfRangeException(length);
|
| + }
|
| + if (length < 0) throw new IllegalArgumentException(length);
|
| + return JS('Object', @'#.slice(#, #)', receiver, start, end);
|
| +}
|
| +
|
| +builtin$indexOf$1(receiver, element) {
|
| + if (isJsArray(receiver) || receiver is String) {
|
| + return builtin$indexOf$2(receiver, element, 0);
|
| + }
|
| + return UNINTERCEPTED(receiver.indexOf(element));
|
| +}
|
| +
|
| +builtin$indexOf$2(receiver, element, start) {
|
| + if (isJsArray(receiver)) {
|
| + if (start is !int) throw new IllegalArgumentException(start);
|
| + var length = JS('num', @'#.length', receiver);
|
| + return Arrays.indexOf(receiver, element, start, length);
|
| + } else if (receiver is String) {
|
| + checkNull(element);
|
| + if (start is !int) throw new IllegalArgumentException(start);
|
| + if (element is !String) throw new IllegalArgumentException(element);
|
| + if (start < 0) return -1; // TODO(ahe): Is this correct?
|
| + return JS('int', @'#.indexOf(#, #)', receiver, element, start);
|
| + }
|
| + return UNINTERCEPTED(receiver.indexOf(element, start));
|
| +}
|
| +
|
| +builtin$insertRange$2(receiver, start, length) {
|
| + if (isJsArray(receiver)) {
|
| + return builtin$insertRange$3(receiver, start, length, null);
|
| + }
|
| + return UNINTERCEPTED(receiver.insertRange(start, length));
|
| +}
|
| +
|
| +builtin$insertRange$3(receiver, start, length, initialValue) {
|
| + if (!isJsArray(receiver)) {
|
| + return UNINTERCEPTED(receiver.insertRange(start, length, initialValue));
|
| + }
|
| + return listInsertRange(receiver, start, length, initialValue);
|
| +}
|
| +
|
| listInsertRange(receiver, start, length, initialValue) {
|
| if (length === 0) {
|
| return;
|
| @@ -480,9 +697,127 @@ listInsertRange(receiver, start, length, initialValue) {
|
| receiver.length = receiverLength + length;
|
| }
|
|
|
| +builtin$last$0(receiver) {
|
| + if (!isJsArray(receiver)) {
|
| + return UNINTERCEPTED(receiver.last());
|
| + }
|
| + return receiver[receiver.length - 1];
|
| +}
|
| +
|
| +builtin$lastIndexOf$1(receiver, element) {
|
| + if (isJsArray(receiver)) {
|
| + var start = JS('num', @'#.length', receiver);
|
| + return Arrays.lastIndexOf(receiver, element, start);
|
| + } else if (receiver is String) {
|
| + checkNull(element);
|
| + if (element is !String) throw new IllegalArgumentException(element);
|
| + return JS('int', @'#.lastIndexOf(#)', receiver, element);
|
| + }
|
| + return UNINTERCEPTED(receiver.lastIndexOf(element));
|
| +}
|
| +
|
| +builtin$lastIndexOf$2(receiver, element, start) {
|
| + if (isJsArray(receiver)) {
|
| + return Arrays.lastIndexOf(receiver, element, start);
|
| + } else if (receiver is String) {
|
| + checkNull(element);
|
| + if (element is !String) throw new IllegalArgumentException(element);
|
| + if (start !== null) {
|
| + if (start is !num) throw new IllegalArgumentException(start);
|
| + if (start < 0) return -1;
|
| + if (start >= receiver.length) {
|
| + if (element == "") return receiver.length;
|
| + start = receiver.length - 1;
|
| + }
|
| + }
|
| + return stringLastIndexOfUnchecked(receiver, element, start);
|
| + }
|
| + return UNINTERCEPTED(receiver.lastIndexOf(element, start));
|
| +}
|
| +
|
| stringLastIndexOfUnchecked(receiver, element, start)
|
| => JS('int', @'#.lastIndexOf(#, #)', receiver, element, start);
|
|
|
| +builtin$removeRange$2(receiver, start, length) {
|
| + if (!isJsArray(receiver)) {
|
| + return UNINTERCEPTED(receiver.removeRange(start, length));
|
| + }
|
| + checkGrowable(receiver, 'removeRange');
|
| + if (length == 0) {
|
| + return;
|
| + }
|
| + checkNull(start); // TODO(ahe): This is not specified but co19 tests it.
|
| + checkNull(length); // TODO(ahe): This is not specified but co19 tests it.
|
| + if (start is !int) throw new IllegalArgumentException(start);
|
| + if (length is !int) throw new IllegalArgumentException(length);
|
| + if (length < 0) throw new IllegalArgumentException(length);
|
| + var receiverLength = JS('num', @'#.length', receiver);
|
| + if (start < 0 || start >= receiverLength) {
|
| + throw new IndexOutOfRangeException(start);
|
| + }
|
| + if (start + length > receiverLength) {
|
| + throw new IndexOutOfRangeException(start + length);
|
| + }
|
| + Arrays.copy(receiver,
|
| + start + length,
|
| + receiver,
|
| + start,
|
| + receiverLength - length - start);
|
| + receiver.length = receiverLength - length;
|
| +}
|
| +
|
| +builtin$setRange$3(receiver, start, length, from) {
|
| + if (isJsArray(receiver)) {
|
| + return builtin$setRange$4(receiver, start, length, from, 0);
|
| + }
|
| + return UNINTERCEPTED(receiver.setRange(start, length, from));
|
| +}
|
| +
|
| +builtin$setRange$4(receiver, start, length, from, startFrom) {
|
| + if (!isJsArray(receiver)) {
|
| + return UNINTERCEPTED(receiver.setRange(start, length, from, startFrom));
|
| + }
|
| +
|
| + checkMutable(receiver, 'indexed set');
|
| + if (length === 0) return;
|
| + checkNull(start); // TODO(ahe): This is not specified but co19 tests it.
|
| + checkNull(length); // TODO(ahe): This is not specified but co19 tests it.
|
| + checkNull(from); // TODO(ahe): This is not specified but co19 tests it.
|
| + checkNull(startFrom); // TODO(ahe): This is not specified but co19 tests it.
|
| + if (start is !int) throw new IllegalArgumentException(start);
|
| + if (length is !int) throw new IllegalArgumentException(length);
|
| + if (startFrom is !int) throw new IllegalArgumentException(startFrom);
|
| + if (length < 0) throw new IllegalArgumentException(length);
|
| + if (start < 0) throw new IndexOutOfRangeException(start);
|
| + if (start + length > receiver.length) {
|
| + throw new IndexOutOfRangeException(start + length);
|
| + }
|
| +
|
| + Arrays.copy(from, startFrom, receiver, start, length);
|
| +}
|
| +
|
| +builtin$some$1(receiver, f) {
|
| + if (!isJsArray(receiver)) {
|
| + return UNINTERCEPTED(receiver.some(f));
|
| + } else {
|
| + return Collections.some(receiver, f);
|
| + }
|
| +}
|
| +
|
| +builtin$every$1(receiver, f) {
|
| + if (!isJsArray(receiver)) {
|
| + return UNINTERCEPTED(receiver.every(f));
|
| + } else {
|
| + return Collections.every(receiver, f);
|
| + }
|
| +}
|
| +
|
| +builtin$sort$1(receiver, compare) {
|
| + if (!isJsArray(receiver)) return UNINTERCEPTED(receiver.sort(compare));
|
| +
|
| + checkMutable(receiver, 'sort');
|
| + DualPivotQuicksort.sort(receiver, compare);
|
| +}
|
|
|
| checkNull(object) {
|
| if (object === null) throw new NullPointerException();
|
| @@ -521,9 +856,255 @@ checkString(value) {
|
| return value;
|
| }
|
|
|
| +builtin$isNegative$0(receiver) {
|
| + if (receiver is num) {
|
| + return (receiver === 0) ? (1 / receiver) < 0 : receiver < 0;
|
| + } else {
|
| + return UNINTERCEPTED(receiver.isNegative());
|
| + }
|
| +}
|
| +
|
| +builtin$isNaN$0(receiver) {
|
| + if (receiver is num) {
|
| + return JS('bool', @'isNaN(#)', receiver);
|
| + } else {
|
| + return UNINTERCEPTED(receiver.isNegative());
|
| + }
|
| +}
|
| +
|
| +builtin$remainder$1(a, b) {
|
| + if (checkNumbers(a, b)) {
|
| + return JS('num', @'# % #', a, b);
|
| + } else {
|
| + return UNINTERCEPTED(a.remainder(b));
|
| + }
|
| +}
|
| +
|
| +builtin$abs$0(receiver) {
|
| + if (receiver is !num) return UNINTERCEPTED(receiver.abs());
|
| +
|
| + return JS('num', @'Math.abs(#)', receiver);
|
| +}
|
| +
|
| +builtin$toInt$0(receiver) {
|
| + if (receiver is !num) return UNINTERCEPTED(receiver.toInt());
|
| +
|
| + if (receiver.isNaN()) throw new BadNumberFormatException('NaN');
|
| +
|
| + if (receiver.isInfinite()) throw new BadNumberFormatException('Infinity');
|
| +
|
| + var truncated = receiver.truncate();
|
| + return JS('bool', @'# == -0.0', truncated) ? 0 : truncated;
|
| +}
|
| +
|
| +builtin$ceil$0(receiver) {
|
| + if (receiver is !num) return UNINTERCEPTED(receiver.ceil());
|
| +
|
| + return JS('num', @'Math.ceil(#)', receiver);
|
| +}
|
| +
|
| +builtin$floor$0(receiver) {
|
| + if (receiver is !num) return UNINTERCEPTED(receiver.floor());
|
| +
|
| + return JS('num', @'Math.floor(#)', receiver);
|
| +}
|
| +
|
| +builtin$isInfinite$0(receiver) {
|
| + if (receiver is !num) return UNINTERCEPTED(receiver.isInfinite());
|
| +
|
| + return JS('bool', @'# == Infinity', receiver)
|
| + || JS('bool', @'# == -Infinity', receiver);
|
| +}
|
| +
|
| +builtin$negate$0(receiver) {
|
| + if (receiver is !num) return UNINTERCEPTED(receiver.negate());
|
| +
|
| + return JS('num', @'-#', receiver);
|
| +}
|
| +
|
| +builtin$round$0(receiver) {
|
| + if (receiver is !num) return UNINTERCEPTED(receiver.round());
|
| +
|
| + if (JS('bool', @'# < 0', receiver)) {
|
| + return JS('num', @'-Math.round(-#)', receiver);
|
| + } else {
|
| + return JS('num', @'Math.round(#)', receiver);
|
| + }
|
| +}
|
| +
|
| +builtin$toDouble$0(receiver) {
|
| + if (receiver is !num) return UNINTERCEPTED(receiver.toDouble());
|
| +
|
| + return receiver;
|
| +}
|
| +
|
| +builtin$truncate$0(receiver) {
|
| + if (receiver is !num) return UNINTERCEPTED(receiver.truncate());
|
| +
|
| + return receiver < 0 ? receiver.ceil() : receiver.floor();
|
| +}
|
| +
|
| +builtin$toStringAsFixed$1(receiver, fractionDigits) {
|
| + if (receiver is !num) {
|
| + return UNINTERCEPTED(receiver.toStringAsFixed(fractionDigits));
|
| + }
|
| + checkNum(fractionDigits);
|
| +
|
| + String result = JS('String', @'#.toFixed(#)', receiver, fractionDigits);
|
| + if (receiver == 0 && receiver.isNegative()) return "-$result";
|
| + return result;
|
| +}
|
| +
|
| +builtin$toStringAsExponential$1(receiver, fractionDigits) {
|
| + if (receiver is !num) {
|
| + return UNINTERCEPTED(receiver.toStringAsExponential(fractionDigits));
|
| + }
|
| + if (fractionDigits !== null) checkNum(fractionDigits);
|
| +
|
| + String result = JS('String', @'#.toExponential(#)',
|
| + receiver, fractionDigits);
|
| + if (receiver == 0 && receiver.isNegative()) return "-$result";
|
| + return result;
|
| +}
|
| +
|
| +builtin$toStringAsPrecision$1(receiver, fractionDigits) {
|
| + if (receiver is !num) {
|
| + return UNINTERCEPTED(receiver.toStringAsPrecision(fractionDigits));
|
| + }
|
| + checkNum(fractionDigits);
|
| +
|
| + String result = JS('String', @'#.toPrecision(#)',
|
| + receiver, fractionDigits);
|
| + if (receiver == 0 && receiver.isNegative()) return "-$result";
|
| + return result;
|
| +}
|
| +
|
| +builtin$toRadixString$1(receiver, radix) {
|
| + if (receiver is !num) {
|
| + return UNINTERCEPTED(receiver.toRadixString(radix));
|
| + }
|
| + checkNum(radix);
|
| +
|
| + return JS('String', @'#.toString(#)', receiver, radix);
|
| +}
|
| +
|
| +builtin$allMatches$1(receiver, str) {
|
| + if (receiver is !String) return UNINTERCEPTED(receiver.allMatches(str));
|
| + checkString(str);
|
| + return allMatchesInStringUnchecked(receiver, str);
|
| +}
|
| +
|
| +builtin$concat$1(receiver, other) {
|
| + if (receiver is !String) return UNINTERCEPTED(receiver.concat(other));
|
| +
|
| + if (other is !String) throw new IllegalArgumentException(other);
|
| + return JS('String', @'# + #', receiver, other);
|
| +}
|
| +
|
| +builtin$contains$1(receiver, other) {
|
| + if (receiver is !String) {
|
| + return UNINTERCEPTED(receiver.contains(other));
|
| + }
|
| + return builtin$contains$2(receiver, other, 0);
|
| +}
|
| +
|
| +builtin$contains$2(receiver, other, startIndex) {
|
| + if (receiver is !String) {
|
| + return UNINTERCEPTED(receiver.contains(other, startIndex));
|
| + }
|
| + checkNull(other);
|
| + return stringContainsUnchecked(receiver, other, startIndex);
|
| +}
|
| +
|
| +builtin$endsWith$1(receiver, other) {
|
| + if (receiver is !String) return UNINTERCEPTED(receiver.endsWith(other));
|
| +
|
| + checkString(other);
|
| + int receiverLength = receiver.length;
|
| + int otherLength = other.length;
|
| + if (otherLength > receiverLength) return false;
|
| + return other == receiver.substring(receiverLength - otherLength);
|
| +}
|
| +
|
| +builtin$replaceAll$2(receiver, from, to) {
|
| + if (receiver is !String) return UNINTERCEPTED(receiver.replaceAll(from, to));
|
| +
|
| + checkString(to);
|
| + return stringReplaceAllUnchecked(receiver, from, to);
|
| +}
|
| +
|
| +builtin$replaceFirst$2(receiver, from, to) {
|
| + if (receiver is !String) {
|
| + return UNINTERCEPTED(receiver.replaceFirst(from, to));
|
| + }
|
| + checkString(to);
|
| + return stringReplaceFirstUnchecked(receiver, from, to);
|
| +}
|
| +
|
| +builtin$split$1(receiver, pattern) {
|
| + if (receiver is !String) return UNINTERCEPTED(receiver.split(pattern));
|
| + checkNull(pattern);
|
| + return stringSplitUnchecked(receiver, pattern);
|
| +}
|
| +
|
| +builtin$splitChars$0(receiver) {
|
| + if (receiver is !String) return UNINTERCEPTED(receiver.splitChars());
|
| +
|
| + return JS('List', @'#.split("")', receiver);
|
| +}
|
| +
|
| +builtin$startsWith$1(receiver, other) {
|
| + if (receiver is !String) return UNINTERCEPTED(receiver.startsWith(other));
|
| + checkString(other);
|
| +
|
| + int length = other.length;
|
| + if (length > receiver.length) return false;
|
| + return JS('bool', @'# == #', other,
|
| + JS('String', @'#.substring(0, #)', receiver, length));
|
| +}
|
| +
|
| +builtin$substring$1(receiver, startIndex) {
|
| + if (receiver is !String) return UNINTERCEPTED(receiver.substring(startIndex));
|
| +
|
| + return builtin$substring$2(receiver, startIndex, null);
|
| +}
|
| +
|
| +builtin$substring$2(receiver, startIndex, endIndex) {
|
| + if (receiver is !String) {
|
| + return UNINTERCEPTED(receiver.substring(startIndex, endIndex));
|
| + }
|
| + checkNum(startIndex);
|
| + var length = receiver.length;
|
| + if (endIndex === null) endIndex = length;
|
| + checkNum(endIndex);
|
| + if (startIndex < 0 ) throw new IndexOutOfRangeException(startIndex);
|
| + if (startIndex > endIndex) throw new IndexOutOfRangeException(startIndex);
|
| + if (endIndex > length) throw new IndexOutOfRangeException(endIndex);
|
| + return substringUnchecked(receiver, startIndex, endIndex);
|
| +}
|
| +
|
| substringUnchecked(receiver, startIndex, endIndex)
|
| => JS('String', @'#.substring(#, #)', receiver, startIndex, endIndex);
|
|
|
| +
|
| +builtin$toLowerCase$0(receiver) {
|
| + if (receiver is !String) return UNINTERCEPTED(receiver.toLowerCase());
|
| +
|
| + return JS('String', @'#.toLowerCase()', receiver);
|
| +}
|
| +
|
| +builtin$toUpperCase$0(receiver) {
|
| + if (receiver is !String) return UNINTERCEPTED(receiver.toUpperCase());
|
| +
|
| + return JS('String', @'#.toUpperCase()', receiver);
|
| +}
|
| +
|
| +builtin$trim$0(receiver) {
|
| + if (receiver is !String) return UNINTERCEPTED(receiver.trim());
|
| +
|
| + return JS('String', @'#.trim()', receiver);
|
| +}
|
| +
|
| class MathNatives {
|
| static int parseInt(str) {
|
| checkString(str);
|
| @@ -596,6 +1177,33 @@ class MathNatives {
|
| }
|
|
|
| /**
|
| + * This is the [Jenkins hash function][1] but using masking to keep
|
| + * values in SMI range. This was inspired by jmesserly's work in
|
| + * Frog.
|
| + *
|
| + * [1]: http://en.wikipedia.org/wiki/Jenkins_hash_function
|
| + */
|
| +builtin$hashCode$0(receiver) {
|
| + // TODO(ahe): This method shouldn't have to use JS. Update when our
|
| + // optimizations are smarter.
|
| + if (receiver is num) return JS('int', @'# & 0x1FFFFFFF', receiver);
|
| + if (receiver is !String) return UNINTERCEPTED(receiver.hashCode());
|
| + int hash = 0;
|
| + int length = JS('int', @'#.length', receiver);
|
| + for (int i = 0; i < length; i++) {
|
| + hash = 0x1fffffff & (hash + JS('int', @'#.charCodeAt(#)', receiver, i));
|
| + hash = 0x1fffffff & (hash + JS('int', @'# << #', 0x0007ffff & hash, 10));
|
| + hash ^= hash >> 6;
|
| + }
|
| + hash = 0x1fffffff & (hash + JS('int', @'# << #', 0x03ffffff & hash, 3));
|
| + hash ^= hash >> 11;
|
| + return 0x1fffffff & (hash + JS('int', @'# << #', 0x00003fff & hash, 15));
|
| +}
|
| +
|
| +// TODO(ahe): Dynamic may be overridden.
|
| +builtin$get$dynamic(receiver) => receiver;
|
| +
|
| +/**
|
| * Called by generated code to capture the stacktrace before throwing
|
| * an exception.
|
| */
|
| @@ -615,6 +1223,16 @@ captureStackTrace(ex) {
|
| */
|
| toStringWrapper() => JS('Object', @'this.dartException').toString();
|
|
|
| +builtin$charCodes$0(receiver) {
|
| + if (receiver is !String) return UNINTERCEPTED(receiver.charCodes());
|
| + int len = receiver.length;
|
| + List<int> result = new List<int>(len);
|
| + for (int i = 0; i < len; i++) {
|
| + result[i] = receiver.charCodeAt(i);
|
| + }
|
| + return result;
|
| +}
|
| +
|
| makeLiteralListConst(list) {
|
| JS('bool', @'#.immutable$list = #', list, true);
|
| JS('bool', @'#.fixed$length = #', list, true);
|
| @@ -753,6 +1371,16 @@ jsPropertyAccess(var jsObject, String property) {
|
| */
|
| getFallThroughError() => const FallThroughError();
|
|
|
| +builtin$isEven$0(receiver) {
|
| + if (receiver is !int) return UNINTERCEPTED(receiver.isEven());
|
| + return (receiver & 1) === 0;
|
| +}
|
| +
|
| +builtin$isOdd$0(receiver) {
|
| + if (receiver is !int) return UNINTERCEPTED(receiver.isOdd());
|
| + return (receiver & 1) === 1;
|
| +}
|
| +
|
| /**
|
| * Represents the type Dynamic. The compiler treats this specially.
|
| */
|
| @@ -768,6 +1396,8 @@ class Null {
|
| }
|
| }
|
|
|
| +builtin$get$toString(receiver) => () => builtin$toString$0(receiver);
|
| +
|
| setRuntimeTypeInfo(target, typeInfo) {
|
| // We have to check for null because factories may return null.
|
| if (target !== null) JS('var', @'#.builtin$typeInfo = #', target, typeInfo);
|
|
|