Bug 1139769 - Self-host %TypedArray%.prototype.subarray. r=till

--HG--
extra : rebase_source : 183d35ba530088a578d8afc1a482fd0dba1c0e3d
This commit is contained in:
Jeff Walden 2015-03-03 11:29:49 -08:00
Родитель b6c434b930
Коммит 7048331318
4 изменённых файлов: 53 добавлений и 11 удалений

Просмотреть файл

@ -749,6 +749,52 @@ function TypedArraySome(callbackfn, thisArg = undefined) {
return false;
}
// ES6 draft 20150304 %TypedArray%.prototype.subarray
function TypedArraySubarray(begin, end) {
// Step 1.
var obj = this;
// Steps 2-3.
// This function is not generic.
if (!IsObject(obj) || !IsTypedArray(obj)) {
return callFunction(CallTypedArrayMethodIfWrapped, this, begin, end,
"TypedArraySubarray");
}
// Steps 4-6.
var buffer = TypedArrayBuffer(obj);
var srcLength = TypedArrayLength(obj);
// Steps 7-9.
var relativeBegin = ToInteger(begin);
var beginIndex = relativeBegin < 0 ? std_Math_max(srcLength + relativeBegin, 0)
: std_Math_min(relativeBegin, srcLength);
// Steps 10-12.
var relativeEnd = end === undefined ? srcLength : ToInteger(end);
var endIndex = relativeEnd < 0 ? std_Math_max(srcLength + relativeEnd, 0)
: std_Math_min(relativeEnd, srcLength);
// Step 13.
var newLength = std_Math_max(endIndex - beginIndex, 0);
// Steps 14-15, altered to use a shift instead of a size for performance.
var elementShift = TypedArrayElementShift(obj);
// Step 16.
var srcByteOffset = TypedArrayByteOffset(obj);
// Step 17.
var beginByteOffset = srcByteOffset + (beginIndex << elementShift);
// Steps 18-20.
var defaultConstructor = _ConstructorForTypedArray(obj);
var constructor = SpeciesConstructor(obj, defaultConstructor);
// Steps 21-22.
return new constructor(buffer, beginByteOffset, newLength);
}
// ES6 draft rev30 (2014/12/24) 22.2.3.30 %TypedArray%.prototype.values()
function TypedArrayValues() {
// Step 1.

Просмотреть файл

@ -481,7 +481,12 @@ class TypedArrayMethods
typedef typename SomeTypedArray::template OfType<uint8_clamped>::Type Uint8ClampedArrayType;
public:
/* subarray(start[, end]) */
// subarray(start[, end])
// %TypedArray%.prototype.subarray is a self-hosted method, so this code is
// only used for shared typed arrays. We should self-host both methods
// eventually (but note TypedArraySubarray will require changes to be used
// with shared typed arrays), but we need to rejigger the shared typed
// array prototype chain before we can do that.
static bool
subarray(JSContext *cx, CallArgs args)
{

Просмотреть файл

@ -779,17 +779,9 @@ TypedArrayObject::set(JSContext *cx, unsigned argc, Value *vp)
TypedArrayMethods<TypedArrayObject>::set>(cx, args);
}
/* static */ bool
TypedArrayObject::subarray(JSContext *cx, unsigned argc, Value *vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
return CallNonGenericMethod<TypedArrayObject::is,
TypedArrayMethods<TypedArrayObject>::subarray>(cx, args);
}
/* static */ const JSFunctionSpec
TypedArrayObject::protoFunctions[] = {
JS_FN("subarray", TypedArrayObject::subarray, 2, 0),
JS_SELF_HOSTED_FN("subarray", "TypedArraySubarray", 2, 0),
JS_FN("set", TypedArrayObject::set, 2, 0),
JS_SELF_HOSTED_FN("copyWithin", "TypedArrayCopyWithin", 3, 0),
JS_SELF_HOSTED_FN("every", "TypedArrayEvery", 2, 0),

Просмотреть файл

@ -215,7 +215,6 @@ class TypedArrayObject : public NativeObject
static bool is(HandleValue v);
static bool set(JSContext *cx, unsigned argc, Value *vp);
static bool subarray(JSContext *cx, unsigned argc, Value *vp);
};
inline bool