macro JSON_NUMBER_TO_STRING(arg) = ((%_IsSmi(%IS_VAR(arg)) || arg - arg == 0) ? %_NumberToString(arg) : "null");
macro HAS_OWN_PROPERTY(arg, index) = (%_CallFunction(arg, index, ObjectHasOwnProperty));
macro HAS_INDEX(array, index, is_array) = ((is_array && %_HasFastPackedElements(%IS_VAR(array))) ? (index < array.length) : (index in array));
+macro MAX_SIMPLE(argA, argB) = (argA < argB ? argB : argA);
+macro MIN_SIMPLE(argA, argB) = (argA < argB ? argA : argB);
# Private names.
macro IS_PRIVATE(sym) = (%SymbolIsPrivate(sym));
TYPED_ARRAYS(DECLARE_GLOBALS)
-var MathMax;
-var MathMin;
var ToNumber;
utils.Import(function(from) {
- MathMax = from.MathMax;
- MathMin = from.MathMin;
ToNumber = from.ToNumber;
});
}
var beginInt = TO_INTEGER(begin);
if (!IS_UNDEFINED(end)) {
- end = TO_INTEGER(end);
+ var endInt = TO_INTEGER(end);
+ var srcLength = %_TypedArrayGetLength(this);
+ } else {
+ var srcLength = %_TypedArrayGetLength(this);
+ var endInt = srcLength;
}
- var srcLength = %_TypedArrayGetLength(this);
if (beginInt < 0) {
- beginInt = MathMax(0, srcLength + beginInt);
+ beginInt = MAX_SIMPLE(0, srcLength + beginInt);
} else {
- beginInt = MathMin(srcLength, beginInt);
+ beginInt = MIN_SIMPLE(beginInt, srcLength);
}
- var endInt = IS_UNDEFINED(end) ? srcLength : end;
if (endInt < 0) {
- endInt = MathMax(0, srcLength + endInt);
+ endInt = MAX_SIMPLE(0, srcLength + endInt);
} else {
- endInt = MathMin(endInt, srcLength);
+ endInt = MIN_SIMPLE(endInt, srcLength);
}
+
if (endInt < beginInt) {
endInt = beginInt;
}
+
var newLength = endInt - beginInt;
var beginByteOffset =
%_ArrayBufferViewGetByteOffset(this) + beginInt * ELEMENT_SIZE;