[ES6] Add TypedArray.prototype functionality.
authorkeith_miller@apple.com <keith_miller@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 Oct 2015 20:20:10 +0000 (20:20 +0000)
committerkeith_miller@apple.com <keith_miller@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 Oct 2015 20:20:10 +0000 (20:20 +0000)
https://bugs.webkit.org/show_bug.cgi?id=148035

Reviewed by Geoffrey Garen.

Source/JavaScriptCore:

This patch should add most of the functionality for
the prototype properties of TypedArray objects in ES6.
There are a few exceptions to this, which will be added
in upcoming patches:

1) First we do not use the species constructor for some
of the TypedArray prototype functions (namely: map, filter,
slice, and subarray). That will need to be added when
species constructors are finished.

2) TypedArrays still have a length, byteOffset, byteLength,
and buffer are still attached to the TypedArray instance (in
the spec they are on the TypedArray.prototype instance object)
since the JIT currently assumes those properties are fixed.

3) The TypedArray.constructor property is not added yet
as it should point to the TypedArray instance object,
which will be added in a future patch.

* CMakeLists.txt:
* JavaScriptCore.vcxproj/JavaScriptCore.vcxproj:
* JavaScriptCore.vcxproj/JavaScriptCore.vcxproj.filters:
* JavaScriptCore.xcodeproj/project.pbxproj:
* builtins/TypedArray.prototype.js: Added.
(every):
(find):
(findIndex):
(forEach):
(some):
(sort.min):
(sort.merge):
(sort.mergeSort):
(sort):
(reduce):
(reduceRight):
(map):
(filter):
(toLocaleString):
* runtime/ArrayPrototype.cpp:
* runtime/ArrayPrototype.h:
* runtime/CommonIdentifiers.h:
* runtime/JSGenericTypedArrayView.h:
(JSC::JSGenericTypedArrayView::toAdaptorNativeFromValue):
(JSC::JSGenericTypedArrayView::setRangeToValue):
(JSC::JSGenericTypedArrayView::sort):
(JSC::JSGenericTypedArrayView::purifyArray):
(JSC::JSGenericTypedArrayView::sortComparison):
(JSC::JSGenericTypedArrayView::sortFloat):
* runtime/JSGenericTypedArrayViewInlines.h:
* runtime/JSGenericTypedArrayViewPrototypeFunctions.h: Added.
(JSC::argumentClampedIndexFromStartOrEnd):
(JSC::genericTypedArrayViewProtoFuncSet):
(JSC::genericTypedArrayViewProtoFuncEntries):
(JSC::genericTypedArrayViewProtoFuncCopyWithin):
(JSC::genericTypedArrayViewProtoFuncFill):
(JSC::genericTypedArrayViewProtoFuncIndexOf):
(JSC::genericTypedArrayViewProtoFuncJoin):
(JSC::genericTypedArrayViewProtoFuncKeys):
(JSC::genericTypedArrayViewProtoFuncLastIndexOf):
(JSC::genericTypedArrayViewProtoGetterFuncLength):
(JSC::genericTypedArrayViewProtoGetterFuncByteLength):
(JSC::genericTypedArrayViewProtoGetterFuncByteOffset):
(JSC::genericTypedArrayViewProtoFuncReverse):
(JSC::genericTypedArrayViewPrivateFuncSort):
(JSC::genericTypedArrayViewProtoFuncSlice):
(JSC::genericTypedArrayViewProtoFuncSubarray):
(JSC::typedArrayViewProtoFuncValues):
* runtime/JSGenericTypedArrayViewPrototypeInlines.h:
(JSC::JSGenericTypedArrayViewPrototype<ViewClass>::finishCreation):
(JSC::genericTypedArrayViewProtoFuncSet): Deleted.
(JSC::genericTypedArrayViewProtoFuncSubarray): Deleted.
* runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::init):
* runtime/JSObject.h:
* runtime/JSTypedArrayPrototypes.cpp:
* runtime/JSTypedArrayPrototypes.h:
* runtime/JSTypedArrayViewPrototype.cpp: Added.
(JSC::typedArrayViewPrivateFuncLength):
(JSC::typedArrayViewPrivateFuncSort):
(JSC::typedArrayViewProtoFuncSet):
(JSC::typedArrayViewProtoFuncEntries):
(JSC::typedArrayViewProtoFuncCopyWithin):
(JSC::typedArrayViewProtoFuncFill):
(JSC::typedArrayViewProtoFuncLastIndexOf):
(JSC::typedArrayViewProtoFuncIndexOf):
(JSC::typedArrayViewProtoFuncJoin):
(JSC::typedArrayViewProtoFuncKeys):
(JSC::typedArrayViewProtoGetterFuncLength):
(JSC::typedArrayViewProtoGetterFuncByteLength):
(JSC::typedArrayViewProtoGetterFuncByteOffset):
(JSC::typedArrayViewProtoFuncReverse):
(JSC::typedArrayViewProtoFuncSubarray):
(JSC::typedArrayViewProtoFuncSlice):
(JSC::typedArrayViewProtoFuncValues):
(JSC::JSTypedArrayViewPrototype::JSTypedArrayViewPrototype):
(JSC::JSTypedArrayViewPrototype::finishCreation):
(JSC::JSTypedArrayViewPrototype::create):
(JSC::JSTypedArrayViewPrototype::createStructure):
* runtime/JSTypedArrayViewPrototype.h: Copied from Source/JavaScriptCore/runtime/JSTypedArrayPrototypes.cpp.
* tests/es6.yaml:
* tests/stress/resources/standalone-pre.js: Added.
(description):
(debug):
(escapeString):
(testPassed):
(testFailed):
(areNumbersEqual):
(areArraysEqual):
(isMinusZero):
(isTypedArray):
(isResultCorrect):
(stringify):
(shouldBe):
(dfgShouldBe):
(shouldBeType):
(shouldBeTrue):
(shouldBeFalse):
(shouldBeNaN):
(shouldBeNull):
(shouldBeEqualToString):
(shouldBeUndefined):
(shouldNotThrow):
(shouldThrow):
(dfgCompiled):
(dfgIncrement):
(noInline):
(finishJSTest):
* tests/stress/resources/typedarray-test-helper-functions.js: Added.
(forEachTypedArray):
(isSameFunctionForEachTypedArrayPrototype.eq):
(isSameFunctionForEachTypedArrayPrototype):
(hasSameValues):
(foo):
(testPrototypeFunctionHelper):
(testPrototypeFunctionOnSigned):
(testPrototypeFunctionOnFloat):
(testPrototypeFunction):
(tester):
(testPrototypeReceivesArray):
* tests/stress/typedarray-copyWithin.js: Added.
* tests/stress/typedarray-every.js: Added.
(isBigEnough):
(isBigEnoughAndChange):
(isBigEnoughAndException):
* tests/stress/typedarray-fill.js: Added.
* tests/stress/typedarray-filter.js: Added.
(keepEven):
(keepEvenAndChange):
(isBigEnoughAndException):
* tests/stress/typedarray-find.js: Added.
(keepEven):
(keepEvenAndChange):
(isBigEnoughAndException):
* tests/stress/typedarray-findIndex.js: Added.
(keepEven):
(keepEvenAndChange):
(isBigEnoughAndException):
* tests/stress/typedarray-forEach.js: Added.
(checkCorrect.let.list):
(checkCorrect):
(createChecker):
(foo):
(changeArray):
(isBigEnoughAndException):
* tests/stress/typedarray-indexOf.js: Added.
(keepEven):
* tests/stress/typedarray-lastIndexOf.js: Added.
* tests/stress/typedarray-map.js: Added.
(even):
(evenAndChange):
(isBigEnoughAndException):
* tests/stress/typedarray-reduce.js: Added.
(createArray):
(sum):
(createArrayAndChange):
(isBigEnoughAndException):
* tests/stress/typedarray-reduceRight.js: Added.
(createArray):
(sum):
(createArrayAndChange):
(isBigEnoughAndException):
* tests/stress/typedarray-slice.js: Added.
* tests/stress/typedarray-some.js: Added.
(isBigEnough):
(isBigEnoughAndChange):
(isBigEnoughAndException):
* tests/stress/typedarray-sort.js: Added.
(sortBackwards):
(compareException):

LayoutTests:

Fixed tests for new toString behavior on TypedArrays.

* fast/canvas/webgl/type-conversion-test-expected.txt:
* fast/dom/Window/window-postmessage-clone-expected.txt:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@190429 268f45cc-cd09-0410-ab3c-d52691b4dbfc

40 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/canvas/webgl/type-conversion-test-expected.txt
LayoutTests/fast/dom/Window/window-postmessage-clone-expected.txt
Source/JavaScriptCore/CMakeLists.txt
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/JavaScriptCore.vcxproj/JavaScriptCore.vcxproj
Source/JavaScriptCore/JavaScriptCore.vcxproj/JavaScriptCore.vcxproj.filters
Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
Source/JavaScriptCore/builtins/TypedArray.prototype.js [new file with mode: 0644]
Source/JavaScriptCore/runtime/ArrayPrototype.cpp
Source/JavaScriptCore/runtime/ArrayPrototype.h
Source/JavaScriptCore/runtime/CommonIdentifiers.h
Source/JavaScriptCore/runtime/JSGenericTypedArrayView.h
Source/JavaScriptCore/runtime/JSGenericTypedArrayViewInlines.h
Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototypeFunctions.h [new file with mode: 0644]
Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototypeInlines.h
Source/JavaScriptCore/runtime/JSGlobalObject.cpp
Source/JavaScriptCore/runtime/JSObject.h
Source/JavaScriptCore/runtime/JSTypedArrayPrototypes.cpp
Source/JavaScriptCore/runtime/JSTypedArrayPrototypes.h
Source/JavaScriptCore/runtime/JSTypedArrayViewPrototype.cpp [new file with mode: 0644]
Source/JavaScriptCore/runtime/JSTypedArrayViewPrototype.h [new file with mode: 0644]
Source/JavaScriptCore/tests/es6.yaml
Source/JavaScriptCore/tests/stress/resources/standalone-pre.js [new file with mode: 0644]
Source/JavaScriptCore/tests/stress/resources/typedarray-test-helper-functions.js [new file with mode: 0644]
Source/JavaScriptCore/tests/stress/typedarray-copyWithin.js [new file with mode: 0644]
Source/JavaScriptCore/tests/stress/typedarray-every.js [new file with mode: 0644]
Source/JavaScriptCore/tests/stress/typedarray-fill.js [new file with mode: 0644]
Source/JavaScriptCore/tests/stress/typedarray-filter.js [new file with mode: 0644]
Source/JavaScriptCore/tests/stress/typedarray-find.js [new file with mode: 0644]
Source/JavaScriptCore/tests/stress/typedarray-findIndex.js [new file with mode: 0644]
Source/JavaScriptCore/tests/stress/typedarray-forEach.js [new file with mode: 0644]
Source/JavaScriptCore/tests/stress/typedarray-indexOf.js [new file with mode: 0644]
Source/JavaScriptCore/tests/stress/typedarray-lastIndexOf.js [new file with mode: 0644]
Source/JavaScriptCore/tests/stress/typedarray-map.js [new file with mode: 0644]
Source/JavaScriptCore/tests/stress/typedarray-reduce.js [new file with mode: 0644]
Source/JavaScriptCore/tests/stress/typedarray-reduceRight.js [new file with mode: 0644]
Source/JavaScriptCore/tests/stress/typedarray-slice.js [new file with mode: 0644]
Source/JavaScriptCore/tests/stress/typedarray-some.js [new file with mode: 0644]
Source/JavaScriptCore/tests/stress/typedarray-sort.js [new file with mode: 0644]

index 3f3973d..c3e5005 100644 (file)
@@ -1,3 +1,15 @@
+2015-10-01  Keith Miller  <keith_miller@apple.com>
+
+        [ES6] Add TypedArray.prototype functionality.
+        https://bugs.webkit.org/show_bug.cgi?id=148035
+
+        Reviewed by Geoffrey Garen.
+
+        Fixed tests for new toString behavior on TypedArrays.
+
+        * fast/canvas/webgl/type-conversion-test-expected.txt:
+        * fast/dom/Window/window-postmessage-clone-expected.txt:
+
 2015-10-01  Brent Fulgham  <bfulgham@apple.com>
 
         Latch does not clear when a scroll snap animation is triggered
index bc75926..e8bfab7 100644 (file)
@@ -765,7 +765,7 @@ PASS context.uniform4f(loc, 0, argument, 0, 0) is undefined.
 PASS context.uniform4f(loc, 0, 0, argument, 0) is undefined.
 PASS context.uniform4f(loc, 0, 0, 0, argument) is undefined.
 
-testing type of TypedArray : value = [object Float32Array]
+testing type of TypedArray : value = 0
 PASS context.bindAttribLocation(program, argument, 'foo') is undefined.
 PASS context.blendColor(argument, argument, argument, argument) is undefined.
 PASS context.bufferData(context.ARRAY_BUFFER, argument, context.STATIC_DRAW) is undefined.
index aaa96be..0ce9c3d 100644 (file)
@@ -46,9 +46,9 @@ LOG: [object Object] => entry
 LOG: [object Set] => true
 LOG: [object Map] => [object Object]
 PASS: eventData is [object ImageData] of type object
-PASS: eventData is [object Uint8ClampedArray] of type object
+PASS: eventData is 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143 of type object
 PASS: eventData is [object ImageData] of type object
-PASS: eventData is [object Uint8ClampedArray] of type object
+PASS: eventData is 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143 of type object
 PASS: eventData is 42 of type number
 PASS: eventData is 42 of type number
 PASS: evalThunk OK
index 5a13260..d671e50 100644 (file)
@@ -574,6 +574,7 @@ set(JavaScriptCore_RUNTIME_SOURCES
     runtime/JSTemplateRegistryKey.cpp
     runtime/JSTypedArrayConstructors.cpp
     runtime/JSTypedArrayPrototypes.cpp
+    runtime/JSTypedArrayViewPrototype.cpp
     runtime/JSTypedArrays.cpp
     runtime/JSWeakMap.cpp
     runtime/JSWeakSet.cpp
@@ -1088,6 +1089,7 @@ set(JavaScriptCore_BUILTINS_SOURCES
     ${JAVASCRIPTCORE_DIR}/builtins/ReflectObject.js
     ${JAVASCRIPTCORE_DIR}/builtins/StringConstructor.js
     ${JAVASCRIPTCORE_DIR}/builtins/StringIterator.prototype.js
+    ${JAVASCRIPTCORE_DIR}/builtins/TypedArray.prototype.js
 )
 
 add_custom_command(
index 60b8f85..be28490 100644 (file)
@@ -1,3 +1,200 @@
+2015-10-01  Keith Miller  <keith_miller@apple.com>
+
+        [ES6] Add TypedArray.prototype functionality.
+        https://bugs.webkit.org/show_bug.cgi?id=148035
+
+        Reviewed by Geoffrey Garen.
+
+        This patch should add most of the functionality for
+        the prototype properties of TypedArray objects in ES6.
+        There are a few exceptions to this, which will be added
+        in upcoming patches:
+
+        1) First we do not use the species constructor for some
+        of the TypedArray prototype functions (namely: map, filter,
+        slice, and subarray). That will need to be added when
+        species constructors are finished.
+
+        2) TypedArrays still have a length, byteOffset, byteLength,
+        and buffer are still attached to the TypedArray instance (in
+        the spec they are on the TypedArray.prototype instance object)
+        since the JIT currently assumes those properties are fixed.
+
+        3) The TypedArray.constructor property is not added yet
+        as it should point to the TypedArray instance object,
+        which will be added in a future patch.
+
+        * CMakeLists.txt:
+        * JavaScriptCore.vcxproj/JavaScriptCore.vcxproj:
+        * JavaScriptCore.vcxproj/JavaScriptCore.vcxproj.filters:
+        * JavaScriptCore.xcodeproj/project.pbxproj:
+        * builtins/TypedArray.prototype.js: Added.
+        (every):
+        (find):
+        (findIndex):
+        (forEach):
+        (some):
+        (sort.min):
+        (sort.merge):
+        (sort.mergeSort):
+        (sort):
+        (reduce):
+        (reduceRight):
+        (map):
+        (filter):
+        (toLocaleString):
+        * runtime/ArrayPrototype.cpp:
+        * runtime/ArrayPrototype.h:
+        * runtime/CommonIdentifiers.h:
+        * runtime/JSGenericTypedArrayView.h:
+        (JSC::JSGenericTypedArrayView::toAdaptorNativeFromValue):
+        (JSC::JSGenericTypedArrayView::setRangeToValue):
+        (JSC::JSGenericTypedArrayView::sort):
+        (JSC::JSGenericTypedArrayView::purifyArray):
+        (JSC::JSGenericTypedArrayView::sortComparison):
+        (JSC::JSGenericTypedArrayView::sortFloat):
+        * runtime/JSGenericTypedArrayViewInlines.h:
+        * runtime/JSGenericTypedArrayViewPrototypeFunctions.h: Added.
+        (JSC::argumentClampedIndexFromStartOrEnd):
+        (JSC::genericTypedArrayViewProtoFuncSet):
+        (JSC::genericTypedArrayViewProtoFuncEntries):
+        (JSC::genericTypedArrayViewProtoFuncCopyWithin):
+        (JSC::genericTypedArrayViewProtoFuncFill):
+        (JSC::genericTypedArrayViewProtoFuncIndexOf):
+        (JSC::genericTypedArrayViewProtoFuncJoin):
+        (JSC::genericTypedArrayViewProtoFuncKeys):
+        (JSC::genericTypedArrayViewProtoFuncLastIndexOf):
+        (JSC::genericTypedArrayViewProtoGetterFuncLength):
+        (JSC::genericTypedArrayViewProtoGetterFuncByteLength):
+        (JSC::genericTypedArrayViewProtoGetterFuncByteOffset):
+        (JSC::genericTypedArrayViewProtoFuncReverse):
+        (JSC::genericTypedArrayViewPrivateFuncSort):
+        (JSC::genericTypedArrayViewProtoFuncSlice):
+        (JSC::genericTypedArrayViewProtoFuncSubarray):
+        (JSC::typedArrayViewProtoFuncValues):
+        * runtime/JSGenericTypedArrayViewPrototypeInlines.h:
+        (JSC::JSGenericTypedArrayViewPrototype<ViewClass>::finishCreation):
+        (JSC::genericTypedArrayViewProtoFuncSet): Deleted.
+        (JSC::genericTypedArrayViewProtoFuncSubarray): Deleted.
+        * runtime/JSGlobalObject.cpp:
+        (JSC::JSGlobalObject::init):
+        * runtime/JSObject.h:
+        * runtime/JSTypedArrayPrototypes.cpp:
+        * runtime/JSTypedArrayPrototypes.h:
+        * runtime/JSTypedArrayViewPrototype.cpp: Added.
+        (JSC::typedArrayViewPrivateFuncLength):
+        (JSC::typedArrayViewPrivateFuncSort):
+        (JSC::typedArrayViewProtoFuncSet):
+        (JSC::typedArrayViewProtoFuncEntries):
+        (JSC::typedArrayViewProtoFuncCopyWithin):
+        (JSC::typedArrayViewProtoFuncFill):
+        (JSC::typedArrayViewProtoFuncLastIndexOf):
+        (JSC::typedArrayViewProtoFuncIndexOf):
+        (JSC::typedArrayViewProtoFuncJoin):
+        (JSC::typedArrayViewProtoFuncKeys):
+        (JSC::typedArrayViewProtoGetterFuncLength):
+        (JSC::typedArrayViewProtoGetterFuncByteLength):
+        (JSC::typedArrayViewProtoGetterFuncByteOffset):
+        (JSC::typedArrayViewProtoFuncReverse):
+        (JSC::typedArrayViewProtoFuncSubarray):
+        (JSC::typedArrayViewProtoFuncSlice):
+        (JSC::typedArrayViewProtoFuncValues):
+        (JSC::JSTypedArrayViewPrototype::JSTypedArrayViewPrototype):
+        (JSC::JSTypedArrayViewPrototype::finishCreation):
+        (JSC::JSTypedArrayViewPrototype::create):
+        (JSC::JSTypedArrayViewPrototype::createStructure):
+        * runtime/JSTypedArrayViewPrototype.h: Copied from Source/JavaScriptCore/runtime/JSTypedArrayPrototypes.cpp.
+        * tests/es6.yaml:
+        * tests/stress/resources/standalone-pre.js: Added.
+        (description):
+        (debug):
+        (escapeString):
+        (testPassed):
+        (testFailed):
+        (areNumbersEqual):
+        (areArraysEqual):
+        (isMinusZero):
+        (isTypedArray):
+        (isResultCorrect):
+        (stringify):
+        (shouldBe):
+        (dfgShouldBe):
+        (shouldBeType):
+        (shouldBeTrue):
+        (shouldBeFalse):
+        (shouldBeNaN):
+        (shouldBeNull):
+        (shouldBeEqualToString):
+        (shouldBeUndefined):
+        (shouldNotThrow):
+        (shouldThrow):
+        (dfgCompiled):
+        (dfgIncrement):
+        (noInline):
+        (finishJSTest):
+        * tests/stress/resources/typedarray-test-helper-functions.js: Added.
+        (forEachTypedArray):
+        (isSameFunctionForEachTypedArrayPrototype.eq):
+        (isSameFunctionForEachTypedArrayPrototype):
+        (hasSameValues):
+        (foo):
+        (testPrototypeFunctionHelper):
+        (testPrototypeFunctionOnSigned):
+        (testPrototypeFunctionOnFloat):
+        (testPrototypeFunction):
+        (tester):
+        (testPrototypeReceivesArray):
+        * tests/stress/typedarray-copyWithin.js: Added.
+        * tests/stress/typedarray-every.js: Added.
+        (isBigEnough):
+        (isBigEnoughAndChange):
+        (isBigEnoughAndException):
+        * tests/stress/typedarray-fill.js: Added.
+        * tests/stress/typedarray-filter.js: Added.
+        (keepEven):
+        (keepEvenAndChange):
+        (isBigEnoughAndException):
+        * tests/stress/typedarray-find.js: Added.
+        (keepEven):
+        (keepEvenAndChange):
+        (isBigEnoughAndException):
+        * tests/stress/typedarray-findIndex.js: Added.
+        (keepEven):
+        (keepEvenAndChange):
+        (isBigEnoughAndException):
+        * tests/stress/typedarray-forEach.js: Added.
+        (checkCorrect.let.list):
+        (checkCorrect):
+        (createChecker):
+        (foo):
+        (changeArray):
+        (isBigEnoughAndException):
+        * tests/stress/typedarray-indexOf.js: Added.
+        (keepEven):
+        * tests/stress/typedarray-lastIndexOf.js: Added.
+        * tests/stress/typedarray-map.js: Added.
+        (even):
+        (evenAndChange):
+        (isBigEnoughAndException):
+        * tests/stress/typedarray-reduce.js: Added.
+        (createArray):
+        (sum):
+        (createArrayAndChange):
+        (isBigEnoughAndException):
+        * tests/stress/typedarray-reduceRight.js: Added.
+        (createArray):
+        (sum):
+        (createArrayAndChange):
+        (isBigEnoughAndException):
+        * tests/stress/typedarray-slice.js: Added.
+        * tests/stress/typedarray-some.js: Added.
+        (isBigEnough):
+        (isBigEnoughAndChange):
+        (isBigEnoughAndException):
+        * tests/stress/typedarray-sort.js: Added.
+        (sortBackwards):
+        (compareException):
+
 2015-10-01  Yusuke Suzuki  <utatane.tea@gmail.com>
 
         Introduce SymbolUse optimization into CompareEq and CompareStrictEq
index cc8306e..cf30f8c 100644 (file)
     <ClCompile Include="..\runtime\JSTypedArrayConstructors.cpp" />
     <ClCompile Include="..\runtime\JSTypedArrayPrototypes.cpp" />
     <ClCompile Include="..\runtime\JSTypedArrays.cpp" />
+    <ClCompile Include="..\runtime\JSTypedArrayViewPrototype.cpp" />
     <ClCompile Include="..\runtime\JSEnvironmentRecord.cpp" />
     <ClCompile Include="..\runtime\JSWeakMap.cpp" />
     <ClCompile Include="..\runtime\JSWeakSet.cpp" />
     <ClInclude Include="..\runtime\JSGenericTypedArrayViewConstructorInlines.h" />
     <ClInclude Include="..\runtime\JSGenericTypedArrayViewInlines.h" />
     <ClInclude Include="..\runtime\JSGenericTypedArrayViewPrototype.h" />
+    <ClInclude Include="..\runtime\JSGenericTypedArrayViewPrototypeFunctions.h" />
     <ClInclude Include="..\runtime\JSGenericTypedArrayViewPrototypeInlines.h" />
     <ClInclude Include="..\runtime\JSGlobalObject.h" />
     <ClInclude Include="..\runtime\JSGlobalObjectFunctions.h" />
     <ClInclude Include="..\runtime\JSTypedArrayConstructors.h" />
     <ClInclude Include="..\runtime\JSTypedArrayPrototypes.h" />
     <ClInclude Include="..\runtime\JSTypedArrays.h" />
+    <ClInclude Include="..\runtime\JSTypedArrayViewPrototype.h" />
     <ClInclude Include="..\runtime\JSUint16Array.h" />
     <ClInclude Include="..\runtime\JSUint32Array.h" />
     <ClInclude Include="..\runtime\JSUint8Array.h" />
index abef320..9469f89 100644 (file)
     <ClCompile Include="..\runtime\JSTypedArrays.cpp">
       <Filter>runtime</Filter>
     </ClCompile>
+    <ClCompile Include="..\runtime\JSTypedArrayViewPrototype.cpp">
+      <Filter>runtime</Filter>
+    </ClCompile>
     <ClCompile Include="..\runtime\DataView.cpp">
       <Filter>runtime</Filter>
     </ClCompile>
     <ClInclude Include="..\runtime\JSGenericTypedArrayViewPrototype.h">
       <Filter>runtime</Filter>
     </ClInclude>
+    <ClInclude Include="..\runtime\JSGenericTypedArrayViewPrototypeFunctions.h">
+      <Filter>runtime</Filter>
+    </ClInclude>
     <ClInclude Include="..\runtime\JSInternalPromise.h">
       <Filter>runtime</Filter>
     </ClInclude>
     <ClInclude Include="..\runtime\JSTypedArrays.h">
       <Filter>runtime</Filter>
     </ClInclude>
+    <ClInclude Include="..\runtime\JSTypedArrayViewPrototype.h">
+      <Filter>runtime</Filter>
+    </ClCompile>
     <ClInclude Include="..\runtime\JSUint16Array.h">
       <Filter>runtime</Filter>
     </ClInclude>
index c25b84b..a7cc8f2 100644 (file)
                52C0611F1AA51E1C00B4ADBA /* RuntimeType.h in Headers */ = {isa = PBXBuildFile; fileRef = 52C0611D1AA51E1B00B4ADBA /* RuntimeType.h */; settings = {ATTRIBUTES = (Private, ); }; };
                52C952B719A289850069B386 /* TypeProfiler.h in Headers */ = {isa = PBXBuildFile; fileRef = 52C952B619A289850069B386 /* TypeProfiler.h */; settings = {ATTRIBUTES = (Private, ); }; };
                52C952B919A28A1C0069B386 /* TypeProfiler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 52C952B819A28A1C0069B386 /* TypeProfiler.cpp */; };
+               53917E7B1B7906FA000EBD33 /* JSGenericTypedArrayViewPrototypeFunctions.h in Headers */ = {isa = PBXBuildFile; fileRef = 53917E7A1B7906E4000EBD33 /* JSGenericTypedArrayViewPrototypeFunctions.h */; };
                5D53726F0E1C54880021E549 /* Tracing.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D53726E0E1C54880021E549 /* Tracing.h */; };
                5D5D8AD10E0D0EBE00F9C692 /* libedit.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D5D8AD00E0D0EBE00F9C692 /* libedit.dylib */; };
                5DBB151B131D0B310056AD36 /* testapi.js in Copy Support Script */ = {isa = PBXBuildFile; fileRef = 14D857740A4696C80032146C /* testapi.js */; };
                C4F4B6F51A05C984005CAB76 /* generate_objc_protocol_types_implementation.py in Headers */ = {isa = PBXBuildFile; fileRef = C4F4B6D71A05C76F005CAB76 /* generate_objc_protocol_types_implementation.py */; settings = {ATTRIBUTES = (Private, ); }; };
                C4F4B6F61A05C984005CAB76 /* objc_generator_templates.py in Headers */ = {isa = PBXBuildFile; fileRef = C4F4B6D81A05C76F005CAB76 /* objc_generator_templates.py */; settings = {ATTRIBUTES = (Private, ); }; };
                DC00039319D8BE6F00023EB0 /* DFGPreciseLocalClobberize.h in Headers */ = {isa = PBXBuildFile; fileRef = DC00039019D8BE6F00023EB0 /* DFGPreciseLocalClobberize.h */; };
+               DEA7E2441BBC677200D78440 /* JSTypedArrayViewPrototype.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53F256E11B87E28000B4B768 /* JSTypedArrayViewPrototype.cpp */; };
+               DEA7E2451BBC677F00D78440 /* JSTypedArrayViewPrototype.h in Headers */ = {isa = PBXBuildFile; fileRef = 53917E7C1B791106000EBD33 /* JSTypedArrayViewPrototype.h */; settings = {ATTRIBUTES = (Private, ); }; };
                E124A8F70E555775003091F1 /* OpaqueJSString.h in Headers */ = {isa = PBXBuildFile; fileRef = E124A8F50E555775003091F1 /* OpaqueJSString.h */; settings = {ATTRIBUTES = (Private, ); }; };
                E124A8F80E555775003091F1 /* OpaqueJSString.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E124A8F60E555775003091F1 /* OpaqueJSString.cpp */; };
                E18E3A590DF9278C00D90B34 /* VM.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E18E3A570DF9278C00D90B34 /* VM.cpp */; };
                52C0611D1AA51E1B00B4ADBA /* RuntimeType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RuntimeType.h; sourceTree = "<group>"; };
                52C952B619A289850069B386 /* TypeProfiler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TypeProfiler.h; sourceTree = "<group>"; };
                52C952B819A28A1C0069B386 /* TypeProfiler.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = TypeProfiler.cpp; sourceTree = "<group>"; };
+               53917E7A1B7906E4000EBD33 /* JSGenericTypedArrayViewPrototypeFunctions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSGenericTypedArrayViewPrototypeFunctions.h; sourceTree = "<group>"; };
+               53917E7C1B791106000EBD33 /* JSTypedArrayViewPrototype.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSTypedArrayViewPrototype.h; sourceTree = "<group>"; };
+               53917E831B791CB8000EBD33 /* TypedArray.prototype.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = TypedArray.prototype.js; path = builtins/TypedArray.prototype.js; sourceTree = SOURCE_ROOT; };
+               53F256E11B87E28000B4B768 /* JSTypedArrayViewPrototype.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSTypedArrayViewPrototype.cpp; sourceTree = "<group>"; };
                5540758418F4A37500602A5D /* CompileRuntimeToLLVMIR.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = CompileRuntimeToLLVMIR.xcconfig; sourceTree = "<group>"; };
                593D43CCA0BBE06D89C59707 /* MapDataInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MapDataInlines.h; sourceTree = "<group>"; };
                5D53726D0E1C546B0021E549 /* Tracing.d */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Tracing.d; sourceTree = "<group>"; };
                                0F2B66C517B6B5AB00A7AE3F /* JSGenericTypedArrayViewConstructorInlines.h */,
                                0F2B66C617B6B5AB00A7AE3F /* JSGenericTypedArrayViewInlines.h */,
                                0F2B66C717B6B5AB00A7AE3F /* JSGenericTypedArrayViewPrototype.h */,
+                               53917E7A1B7906E4000EBD33 /* JSGenericTypedArrayViewPrototypeFunctions.h */,
                                0F2B66C817B6B5AB00A7AE3F /* JSGenericTypedArrayViewPrototypeInlines.h */,
                                797E07A71B8FCFB9008400BA /* JSGlobalLexicalEnvironment.cpp */,
                                797E07A81B8FCFB9008400BA /* JSGlobalLexicalEnvironment.h */,
                                0F2B66CF17B6B5AB00A7AE3F /* JSTypedArrayPrototypes.h */,
                                0F2B66D017B6B5AB00A7AE3F /* JSTypedArrays.cpp */,
                                0F2B66D117B6B5AB00A7AE3F /* JSTypedArrays.h */,
+                               53F256E11B87E28000B4B768 /* JSTypedArrayViewPrototype.cpp */,
+                               53917E7C1B791106000EBD33 /* JSTypedArrayViewPrototype.h */,
                                6507D2970E871E4A00D7D896 /* JSTypeInfo.h */,
                                0F2B66D417B6B5AB00A7AE3F /* JSUint16Array.h */,
                                0F2B66D517B6B5AB00A7AE3F /* JSUint32Array.h */,
                                7CF9BC5F1B65D9B1009DB1EF /* ReflectObject.js */,
                                7CF9BC601B65D9B1009DB1EF /* StringConstructor.js */,
                                7CF9BC611B65D9B1009DB1EF /* StringIterator.prototype.js */,
+                               53917E831B791CB8000EBD33 /* TypedArray.prototype.js */,
                        );
                        path = builtins;
                        sourceTree = "<group>";
                                0FB17663196B8F9E0091052A /* DFGPureValue.h in Headers */,
                                0F3A1BFA1A9ECB7D000DE01A /* DFGPutStackSinkingPhase.h in Headers */,
                                86EC9DD11328DF82002B2AD7 /* DFGRegisterBank.h in Headers */,
+                               DEA7E2451BBC677F00D78440 /* JSTypedArrayViewPrototype.h in Headers */,
                                0F2FCCFC18A60070001A27F8 /* DFGSafepoint.h in Headers */,
                                A77A424317A0BBFD00A8DB81 /* DFGSafeToExecute.h in Headers */,
                                A741017F179DAF80002EB8BA /* DFGSaneStringGetByValSlowPathGenerator.h in Headers */,
                                2AABCDE718EF294200002096 /* GCLogging.h in Headers */,
                                A54E8EB018BFFBBB00556D28 /* GCSegmentedArray.h in Headers */,
                                A54E8EB118BFFBBE00556D28 /* GCSegmentedArrayInlines.h in Headers */,
-                               C2239D1B16262BDD005AC5FD /* GCThread.h in Headers */,
                                A532439418569709002ED692 /* generate-combined-inspector-json.py in Headers */,
                                C4703CC0192844960013FBEA /* generate-inspector-protocol-bindings.py in Headers */,
                                2DFB8AFE1BB323BD0093D237 /* generate-js-builtins in Headers */,
                                86E3C614167BABD7006D760A /* JSExport.h in Headers */,
                                A7B4ACAF1484C9CE00B38A36 /* JSExportMacros.h in Headers */,
                                0F2B66EF17B6B5AB00A7AE3F /* JSFloat32Array.h in Headers */,
+                               53917E7B1B7906FA000EBD33 /* JSGenericTypedArrayViewPrototypeFunctions.h in Headers */,
                                0F2B66F017B6B5AB00A7AE3F /* JSFloat64Array.h in Headers */,
                                BC18C41F0E16F5CD00B34460 /* JSFunction.h in Headers */,
                                A72028BA1797603D0098028C /* JSFunctionInlines.h in Headers */,
                                2AACE63C18CA5A0300ED0191 /* GCActivityCallback.cpp in Sources */,
                                0F766D2F15A8DCE0008F363E /* GCAwareJITStubRoutine.cpp in Sources */,
                                2ADFA26318EF3540004F9FCC /* GCLogging.cpp in Sources */,
-                               C2239D1A16262BDD005AC5FD /* GCThread.cpp in Sources */,
                                0F93329F14CA7DCA0085F3C6 /* GetByIdStatus.cpp in Sources */,
                                0F0332C318B01763005F979A /* GetByIdVariant.cpp in Sources */,
                                14280855107EC0E70013E7B2 /* GetterSetter.cpp in Sources */,
                                0F98206016BFE38100240D02 /* PreciseJumpTargets.cpp in Sources */,
                                95742F650DD11F5A000917FB /* Profile.cpp in Sources */,
                                95CD45760E1C4FDD0085358E /* ProfileGenerator.cpp in Sources */,
+                               DEA7E2441BBC677200D78440 /* JSTypedArrayViewPrototype.cpp in Sources */,
                                95AB83560DA43C3000BC83F3 /* ProfileNode.cpp in Sources */,
                                0FF729AD166AD35C000F5BA3 /* ProfilerBytecode.cpp in Sources */,
                                0FF729AE166AD35C000F5BA3 /* ProfilerBytecodes.cpp in Sources */,
diff --git a/Source/JavaScriptCore/builtins/TypedArray.prototype.js b/Source/JavaScriptCore/builtins/TypedArray.prototype.js
new file mode 100644 (file)
index 0000000..5283420
--- /dev/null
@@ -0,0 +1,287 @@
+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+// Note that the intrisic @typedArrayLength checks the that the argument passed is a typed array
+// and throws if it is not.
+
+function every(callback /*, thisArg */)
+{
+    "use strict";
+    var length = @typedArrayLength(this);
+    var thisArg = arguments.length > 1 ? arguments[1] : undefined;
+
+    if (typeof callback !== "function")
+        throw new @TypeError("TypedArray.prototype.every callback must be a function");
+
+    for (var i = 0; i < length; i++) {
+        if (!callback.@call(thisArg, this[i], i, this))
+            return false;
+    }
+
+    return true;
+}
+
+function find(callback /* [, thisArg] */)
+{
+    "use strict";
+    var length = @typedArrayLength(this);
+    var thisArg = arguments.length > 1 ? arguments[1] : undefined;
+
+    if (typeof callback !== "function")
+        throw new @TypeError("TypedArray.prototype.find callback must be a function");
+
+    for (var i = 0; i < length; i++) {
+        let elem = this[i];
+        if (callback.@call(thisArg, elem, i, this))
+            return elem;
+    }
+    return undefined;
+}
+
+function findIndex(callback /* [, thisArg] */)
+{
+    "use strict";
+    var length = @typedArrayLength(this);
+    var thisArg = arguments.length > 1 ? arguments[1] : undefined;
+
+    if (typeof callback !== "function")
+        throw new @TypeError("TypedArray.prototype.findIndex callback must be a function");
+
+    for (var i = 0; i < length; i++) {
+        if (callback.@call(thisArg, this[i], i, this))
+            return i;
+    }
+    return -1;
+}
+
+function forEach(callback /* [, thisArg] */)
+{
+    "use strict";
+    var length = @typedArrayLength(this);
+    var thisArg = arguments.length > 1 ? arguments[1] : undefined;
+
+    if (typeof callback !== "function")
+        throw new @TypeError("TypedArray.prototype.findIndex callback must be a function");
+
+    for (var i = 0; i < length; i++)
+        callback.@call(thisArg, this[i], i, this);
+}
+
+function some(callback /* [, thisArg] */)
+{
+    // 22.2.3.24
+    "use strict";
+    var length = @typedArrayLength(this);
+    var thisArg = arguments.length > 1 ? arguments[1] : undefined;
+
+    if (typeof callback !== "function")
+        throw new @TypeError("TypedArray.prototype.some callback must be a function");
+
+    for (var i = 0; i < length; i++) {
+        if (callback.@call(thisArg, this[i], i, this))
+            return true;
+    }
+
+    return false;
+}
+
+function sort(comparator)
+{
+    // 22.2.3.25
+    "use strict";
+
+    function min(a, b)
+    {
+        return a < b ? a : b;
+    }
+
+    function merge(dst, src, srcIndex, srcEnd, width, comparator)
+    {
+        var left = srcIndex;
+        var leftEnd = min(left + width, srcEnd);
+        var right = leftEnd;
+        var rightEnd = min(right + width, srcEnd);
+
+        for (var dstIndex = left; dstIndex < rightEnd; ++dstIndex) {
+            if (right < rightEnd) {
+                if (left >= leftEnd || comparator(src[right], src[left]) < 0) {
+                    dst[dstIndex] = src[right++];
+                    continue;
+                }
+            }
+
+            dst[dstIndex] = src[left++];
+        }
+    }
+
+    function mergeSort(array, valueCount, comparator)
+    {
+        var buffer = [ ];
+        buffer.length = valueCount;
+
+        var dst = buffer;
+        var src = array;
+
+        for (var width = 1; width < valueCount; width *= 2) {
+            for (var srcIndex = 0; srcIndex < valueCount; srcIndex += 2 * width)
+                merge(dst, src, srcIndex, valueCount, width, comparator);
+
+            var tmp = src;
+            src = dst;
+            dst = tmp;
+        }
+
+        if (src != array) {
+            for(var i = 0; i < valueCount; i++)
+                array[i] = src[i];
+        }
+    }
+
+    var length = @typedArrayLength(this);
+
+    if (length < 2)
+        return;
+
+    if (typeof comparator == "function")
+        mergeSort(this, length, comparator);
+    else
+        @typedArraySort(this);
+    
+    return this;
+}
+
+function reduce(callback /* [, initialValue] */)
+{
+    // 22.2.3.19
+    "use strict";
+
+    var length = @typedArrayLength(this);
+
+    if (typeof callback !== "function")
+        throw new @TypeError("TypedArray.prototype.reduce callback must be a function");
+
+    if (length === 0 && arguments.length < 2)
+        throw new @TypeError("TypedArray.prototype.reduce of empty array with no initial value");
+
+    var accumulator, k = 0;
+    if (arguments.length > 1)
+        accumulator = arguments[1];
+    else
+        accumulator = this[k++];
+
+    for (; k < length; k++)
+        accumulator = callback.@call(undefined, accumulator, this[k], k, this);
+
+    return accumulator;
+}
+
+function reduceRight(callback /* [, initialValue] */)
+{
+    // 22.2.3.20
+    "use strict";
+
+    var length = @typedArrayLength(this);
+
+    if (typeof callback !== "function")
+        throw new @TypeError("TypedArray.prototype.reduceRight callback must be a function");
+
+    if (length === 0 && arguments.length < 2)
+        throw new @TypeError("TypedArray.prototype.reduceRight of empty array with no initial value");
+
+    var accumulator, k = length - 1;
+    if (arguments.length > 1)
+        accumulator = arguments[1];
+    else
+        accumulator = this[k--];
+
+    for (; k >= 0; k--)
+        accumulator = callback.@call(undefined, accumulator, this[k], k, this);
+
+    return accumulator;
+}
+
+function map(callback /*, thisArg */)
+{
+    // 22.2.3.18
+    "use strict";
+
+    var length = @typedArrayLength(this);
+
+    if (typeof callback !== "function")
+        throw new @TypeError("TypedArray.prototype.map callback must be a function");
+
+    var thisArg = arguments.length > 1 ? arguments[1] : undefined;
+    // FIXME: This should be a species constructor.
+    var result = new this.constructor(length);
+    for (var i = 0; i < length; i++) {
+        var mappedValue = callback.@call(thisArg, this[i], i, this);
+        result[i] = mappedValue;
+    }
+    return result;
+}
+
+function filter(callback /*, thisArg */)
+{
+    "use strict";
+
+    var length = @typedArrayLength(this);
+
+    if (typeof callback !== "function")
+        throw new @TypeError("Array.prototype.map callback must be a function");
+
+    var thisArg = arguments.length > 1 ? arguments[1] : undefined;
+
+    var kept = [];
+
+    for (var i = 0; i < length; i++) {
+        var value = this[i];
+        if (callback.@call(thisArg, value, i, this))
+            kept.push(value);
+    }
+
+    // FIXME: This should be a species constructor.
+    var result = new this.constructor(kept.length);
+
+    for (var i = 0; i < kept.length; i++)
+        result[i] = kept[i];
+
+    return result;
+}
+
+function toLocaleString()
+{
+    "use strint";
+
+    var length = @typedArrayLength(this);
+
+    if (length == 0)
+        return "";
+
+    var string = this[0].toLocaleString();
+    for (var i = 1; i < length; i++)
+        string += "," + this[i].toLocaleString();
+
+    return string;
+}
index 3cc351b..2db2592 100644 (file)
@@ -46,7 +46,6 @@
 
 namespace JSC {
 
-EncodedJSValue JSC_HOST_CALL arrayProtoFuncToString(ExecState*);
 EncodedJSValue JSC_HOST_CALL arrayProtoFuncToLocaleString(ExecState*);
 EncodedJSValue JSC_HOST_CALL arrayProtoFuncConcat(ExecState*);
 EncodedJSValue JSC_HOST_CALL arrayProtoFuncJoin(ExecState*);
index 39412c2..2d933bd 100644 (file)
@@ -46,6 +46,7 @@ protected:
     void finishCreation(VM&, JSGlobalObject*);
 };
 
+EncodedJSValue JSC_HOST_CALL arrayProtoFuncToString(ExecState*);
 EncodedJSValue JSC_HOST_CALL arrayProtoFuncValues(ExecState*);
 
 } // namespace JSC
index 03306c8..3355002 100644 (file)
     macro(getPrototypeOf) \
     macro(getOwnPropertyNames) \
     macro(TypeError) \
+    macro(typedArrayLength) \
+    macro(typedArraySort) \
     macro(undefined) \
     macro(BuiltinLog) \
     macro(homeObject) \
index a3a756c..6e55a31 100644 (file)
@@ -87,6 +87,8 @@ template<typename Adaptor>
 class JSGenericTypedArrayView : public JSArrayBufferView {
 public:
     typedef JSArrayBufferView Base;
+    typedef typename Adaptor::Type ElementType;
+
     static const unsigned StructureFlags = Base::StructureFlags | OverridesGetPropertyNames | OverridesGetOwnPropertySlot | InterceptsGetOwnPropertySlotByIndexEvenWhenLengthIsNotZero;
 
     static const unsigned elementSize = sizeof(typename Adaptor::Type);
@@ -168,7 +170,48 @@ public:
         setIndexQuicklyToNativeValue(i, value);
         return true;
     }
-    
+
+    static Optional<typename Adaptor::Type> toAdaptorNativeFromValue(ExecState* exec, JSValue jsValue)
+    {
+        typename Adaptor::Type value = toNativeFromValue<Adaptor>(exec, jsValue);
+        if (exec->hadException())
+            return Nullopt;
+        return value;
+    }
+
+    bool setRangeToValue(ExecState* exec, unsigned start, unsigned end, JSValue jsValue)
+    {
+        ASSERT(0 <= start && start <= end && end <= m_length);
+
+        typename Adaptor::Type value = toNativeFromValue<Adaptor>(exec, jsValue);
+        if (exec->hadException())
+            return false;
+
+        // We might want to do something faster here (e.g. SIMD) if this is too slow.
+        typename Adaptor::Type* array = typedVector();
+        for (unsigned i = start; i < end; ++i)
+            array[i] = value;
+
+        return true;
+    }
+
+    void sort()
+    {
+        switch (Adaptor::typeValue) {
+        case TypeFloat32:
+            sortFloat<int32_t>();
+            break;
+        case TypeFloat64:
+            sortFloat<int64_t>();
+            break;
+        default: {
+            ElementType* array = typedVector();
+            std::sort(array, array + m_length);
+            break;
+        }
+        }
+    }
+
     bool canAccessRangeQuickly(unsigned offset, unsigned length)
     {
         return offset <= m_length
@@ -257,6 +300,64 @@ private:
     bool setWithSpecificType(
         ExecState*, JSGenericTypedArrayView<OtherAdaptor>*,
         unsigned offset, unsigned length);
+
+    // The ECMA 6 spec states that floating point Typed Arrays should have the following ordering:
+    //
+    // -Inifinity < negative finite numbers < -0.0 < 0.0 < positive finite numbers < Infinity < NaN
+    // Note: regardless of the sign or exact representation of a NaN it is greater than all other values.
+    //
+    // An interesting fact about IEEE 754 floating point numbers is that have an adjacent representation
+    // i.e. for any finite floating point x there does not exist a finite floating point y such that
+    // ((float) ((int) x + 1)) > y > x (where int represents a signed bit integer with the same number
+    // of bits as float). Thus, if we have an array of floating points if we view it as an
+    // array of signed bit integers it will sort in the format we desire. Note, denormal
+    // numbers fit this property as they are floating point numbers with a exponent field of all
+    // zeros so they will be closer to the signed zeros than any normalized number.
+    //
+    // All the processors we support, however, use twos complement. Fortunately, if you compare a signed
+    // bit number as if it were twos complement the result will be correct assuming both numbers are not
+    // negative. e.g.
+    //
+    //    - <=> - = reversed (-30 > -20 = true)
+    //    + <=> + = ordered (30 > 20 = true)
+    //    - <=> + = ordered (-30 > 20 = false)
+    //    + <=> - = ordered (30 > -20 = true)
+    //
+    // For NaN, we normalize the NaN to a peticular representation; the sign bit is 0, all exponential bits
+    // are 1 and only the MSB of the mantissa is 1. So, NaN is recognized as the largest integral numbers.
+
+    void purifyArray()
+    {
+        ElementType* array = typedVector();
+        for (unsigned i = 0; i < m_length; i++)
+            array[i] = purifyNaN(array[i]);
+    }
+
+    template<typename IntegralType>
+    static bool ALWAYS_INLINE sortComparison(IntegralType a, IntegralType b)
+    {
+        if (a >= 0 || b >= 0)
+            return a < b;
+        return a > b;
+    }
+
+    template<typename IntegralType>
+    void sortFloat()
+    {
+        ASSERT(sizeof(IntegralType) == sizeof(ElementType));
+
+        // Since there might be another view that sets the bits of
+        // our floats to NaNs with negative sign bits we need to
+        // purify the array.
+        // We use a separate function here to avoid the strict aliasing rule.
+        // We could use a union but ASAN seems to frown upon that.
+        purifyArray();
+
+        IntegralType* array = reinterpret_cast<IntegralType*>(typedVector());
+        std::sort(array, array + m_length, sortComparison<IntegralType>);
+
+    }
+
 };
 
 template<typename Adaptor>
index e9ed1e9..2be4f44 100644 (file)
@@ -30,6 +30,7 @@
 #include "DeferGC.h"
 #include "Error.h"
 #include "ExceptionHelpers.h"
+#include "JSArrayBuffer.h"
 #include "JSGenericTypedArrayView.h"
 #include "Reject.h"
 #include "TypedArrays.h"
diff --git a/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototypeFunctions.h b/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototypeFunctions.h
new file mode 100644 (file)
index 0000000..ee5bdea
--- /dev/null
@@ -0,0 +1,399 @@
+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef JSGenericTypedArrayViewPrototypeFunctions_h
+#define JSGenericTypedArrayViewPrototypeFunctions_h
+
+#include "ArrayPrototype.h"
+#include "Error.h"
+#include "ExceptionHelpers.h"
+#include "JSArrayBufferViewInlines.h"
+#include "JSArrayIterator.h"
+#include "JSCBuiltins.h"
+#include "JSCJSValueInlines.h"
+#include "JSFunction.h"
+#include "JSGenericTypedArrayViewInlines.h"
+#include "JSGenericTypedArrayViewPrototypeInlines.h"
+#include "JSStringJoiner.h"
+#include "StructureInlines.h"
+#include "TypedArrayAdaptors.h"
+#include <wtf/StdLibExtras.h>
+
+namespace JSC {
+
+inline unsigned argumentClampedIndexFromStartOrEnd(ExecState* exec, int argument, unsigned length, unsigned undefinedValue = 0)
+{
+    JSValue value = exec->argument(argument);
+    if (value.isUndefined())
+        return undefinedValue;
+
+    double indexDouble = value.toInteger(exec);
+    if (indexDouble < 0) {
+        indexDouble += length;
+        return indexDouble < 0 ? 0 : static_cast<unsigned>(indexDouble);
+    }
+    return indexDouble > length ? length : static_cast<unsigned>(indexDouble);
+}
+
+template<typename ViewClass>
+EncodedJSValue JSC_HOST_CALL genericTypedArrayViewProtoFuncSet(ExecState* exec)
+{
+    // 22.2.3.22
+    ViewClass* thisObject = jsCast<ViewClass*>(exec->thisValue());
+
+    if (!exec->argumentCount())
+        return throwVMError(exec, createTypeError(exec, "Expected at least one argument"));
+
+    JSObject* sourceArray = jsDynamicCast<JSObject*>(exec->uncheckedArgument(0));
+    if (!sourceArray)
+        return throwVMError(exec, createTypeError(exec, "First argument should be an object"));
+
+    unsigned offset;
+    if (exec->argumentCount() >= 2) {
+        offset = exec->uncheckedArgument(1).toUInt32(exec);
+        if (exec->hadException())
+            return JSValue::encode(jsUndefined());
+    } else
+        offset = 0;
+
+    unsigned length = sourceArray->get(exec, exec->vm().propertyNames->length).toUInt32(exec);
+    if (exec->hadException())
+        return JSValue::encode(jsUndefined());
+
+    thisObject->set(exec, sourceArray, offset, length);
+    return JSValue::encode(jsUndefined());
+}
+
+template<typename ViewClass>
+EncodedJSValue JSC_HOST_CALL genericTypedArrayViewProtoFuncEntries(ExecState* exec)
+{
+    // 22.2.3.6
+    ViewClass* thisObject = jsCast<ViewClass*>(exec->thisValue());
+
+    return JSValue::encode(JSArrayIterator::create(exec, exec->callee()->globalObject()->arrayIteratorStructure(), ArrayIterateKeyValue, thisObject));
+}
+
+template<typename ViewClass>
+EncodedJSValue JSC_HOST_CALL genericTypedArrayViewProtoFuncCopyWithin(ExecState* exec)
+{
+    // 22.2.3.5
+    ViewClass* thisObject = jsCast<ViewClass*>(exec->thisValue());
+
+    if (exec->argumentCount() < 2)
+        return throwVMError(exec, createTypeError(exec, "Expected at least two arguments"));
+
+    if (exec->hadException())
+        return JSValue::encode(jsUndefined());
+
+    long length = thisObject->length();
+    long to = argumentClampedIndexFromStartOrEnd(exec, 0, length);
+    long from = argumentClampedIndexFromStartOrEnd(exec, 1, length);
+    long final = argumentClampedIndexFromStartOrEnd(exec, 2, length, length);
+
+    if (final < from)
+        return JSValue::encode(exec->thisValue());
+
+    long count = std::min(length - std::max(to, from), final - from);
+
+    typename ViewClass::ElementType* array = thisObject->typedVector();
+    memmove(array + to, array + from, count * thisObject->elementSize);
+
+    return JSValue::encode(exec->thisValue());
+}
+
+template<typename ViewClass>
+EncodedJSValue JSC_HOST_CALL genericTypedArrayViewProtoFuncFill(ExecState* exec)
+{
+    // 22.2.3.8
+    ViewClass* thisObject = jsCast<ViewClass*>(exec->thisValue());
+
+    JSValue valueToInsert = exec->argument(0);
+    if (exec->hadException())
+        return JSValue::encode(jsUndefined());
+
+    unsigned length = thisObject->length();
+    unsigned begin = argumentClampedIndexFromStartOrEnd(exec, 1, length);
+    unsigned end = argumentClampedIndexFromStartOrEnd(exec, 2, length, length);
+
+    if (end < begin)
+        return JSValue::encode(exec->thisValue());
+
+    if (!thisObject->setRangeToValue(exec, begin, end, valueToInsert))
+        return JSValue::encode(jsUndefined());
+
+    return JSValue::encode(exec->thisValue());
+}
+
+template<typename ViewClass>
+EncodedJSValue JSC_HOST_CALL genericTypedArrayViewProtoFuncIndexOf(ExecState* exec)
+{
+    // 22.2.3.13
+    ViewClass* thisObject = jsCast<ViewClass*>(exec->thisValue());
+
+    if (!exec->argumentCount())
+        return throwVMError(exec, createTypeError(exec, "Expected at least one argument"));
+
+    unsigned length = thisObject->length();
+
+    JSValue valueToFind = exec->argument(0);
+    unsigned index = argumentClampedIndexFromStartOrEnd(exec, 1, length);
+
+    auto targetOpt = ViewClass::toAdaptorNativeFromValue(exec, valueToFind);
+    if (!targetOpt)
+        return JSValue::encode(jsUndefined());
+
+    typename ViewClass::ElementType target = targetOpt.value();
+    typename ViewClass::ElementType* array = thisObject->typedVector();
+
+    for (; index < length; ++index) {
+        if (array[index] == target)
+            return JSValue::encode(jsNumber(index));
+    }
+
+    return JSValue::encode(jsNumber(-1));
+}
+
+template<typename ViewClass>
+EncodedJSValue JSC_HOST_CALL genericTypedArrayViewProtoFuncJoin(ExecState* exec)
+{
+    // 22.2.3.14
+    ViewClass* thisObject = jsCast<ViewClass*>(exec->thisValue());
+
+    unsigned length = thisObject->length();
+
+    JSValue separatorValue = exec->argument(0);
+    JSString* separatorString;
+    StringView separator;
+
+    if (separatorValue.isUndefined()) {
+        const LChar* comma = reinterpret_cast<const LChar*>(",");
+        separator = { comma, 1 };
+    } else {
+        separatorString = separatorValue.toString(exec);
+        if (exec->hadException())
+            return JSValue::encode(jsUndefined());
+        separator = separatorString->view(exec);
+    }
+
+    JSStringJoiner joiner(*exec, separator, length);
+    if (exec->hadException())
+        return JSValue::encode(jsUndefined());
+
+    for (unsigned i = 0; i < length; i++) {
+        joiner.append(*exec, thisObject->getIndexQuickly(i));
+        if (exec->hadException())
+            return JSValue::encode(jsUndefined());
+    }
+
+    return JSValue::encode(joiner.join(*exec));
+}
+
+template<typename ViewClass>
+EncodedJSValue JSC_HOST_CALL genericTypedArrayViewProtoFuncKeys(ExecState* exec)
+{
+    // 22.2.3.15
+    ViewClass* thisObject = jsCast<ViewClass*>(exec->thisValue());
+
+    return JSValue::encode(JSArrayIterator::create(exec, exec->callee()->globalObject()->arrayIteratorStructure(), ArrayIterateKey, thisObject));
+}
+
+template<typename ViewClass>
+EncodedJSValue JSC_HOST_CALL genericTypedArrayViewProtoFuncLastIndexOf(ExecState* exec)
+{
+    // 22.2.3.16
+    ViewClass* thisObject = jsCast<ViewClass*>(exec->thisValue());
+
+    if (!exec->argumentCount())
+        return throwVMError(exec, createTypeError(exec, "Expected at least one argument"));
+
+    unsigned length = thisObject->length();
+
+    JSValue valueToFind = exec->argument(0);
+
+    int index = length - 1;
+    if (exec->argumentCount() >= 2) {
+        JSValue fromValue = exec->uncheckedArgument(1);
+        double fromDouble = fromValue.toInteger(exec);
+        if (fromDouble < 0) {
+            fromDouble += length;
+            if (fromDouble < 0)
+                return JSValue::encode(jsNumber(-1));
+        }
+        if (fromDouble < length)
+            index = static_cast<unsigned>(fromDouble);
+    }
+
+    auto targetOpt = ViewClass::toAdaptorNativeFromValue(exec, valueToFind);
+    if (!targetOpt)
+        return JSValue::encode(jsUndefined());
+
+    typename ViewClass::ElementType target = targetOpt.value();
+    typename ViewClass::ElementType* array = thisObject->typedVector();
+
+
+    for (; index >= 0; --index) {
+        if (array[index] == target)
+            return JSValue::encode(jsNumber(index));
+    }
+
+    return JSValue::encode(jsNumber(-1));
+}
+
+template<typename ViewClass>
+EncodedJSValue JSC_HOST_CALL genericTypedArrayViewProtoGetterFuncLength(ExecState* exec)
+{
+    // 22.2.3.17
+    ViewClass* thisObject = jsCast<ViewClass*>(exec->thisValue());
+
+    return JSValue::encode(jsNumber(thisObject->length()));
+}
+
+template<typename ViewClass>
+EncodedJSValue JSC_HOST_CALL genericTypedArrayViewProtoGetterFuncByteLength(ExecState* exec)
+{
+    // 22.2.3.2
+    ViewClass* thisObject = jsCast<ViewClass*>(exec->thisValue());
+
+    return JSValue::encode(jsNumber(thisObject->byteLength()));
+}
+
+template<typename ViewClass>
+EncodedJSValue JSC_HOST_CALL genericTypedArrayViewProtoGetterFuncByteOffset(ExecState* exec)
+{
+    // 22.2.3.3
+    ViewClass* thisObject = jsCast<ViewClass*>(exec->thisValue());
+
+    return JSValue::encode(jsNumber(thisObject->byteOffset()));
+}
+
+
+template<typename ViewClass>
+EncodedJSValue JSC_HOST_CALL genericTypedArrayViewProtoFuncReverse(ExecState* exec)
+{
+    // 22.2.3.21
+    ViewClass* thisObject = jsCast<ViewClass*>(exec->thisValue());
+
+    typename ViewClass::ElementType* array = thisObject->typedVector();
+    std::reverse(array, array + thisObject->length());
+
+    return JSValue::encode(thisObject);
+}
+
+template<typename ViewClass>
+EncodedJSValue JSC_HOST_CALL genericTypedArrayViewPrivateFuncSort(ExecState* exec)
+{
+    // 22.2.3.25
+    ViewClass* thisObject = jsCast<ViewClass*>(exec->argument(0));
+
+    thisObject->sort();
+
+    return JSValue::encode(thisObject);
+}
+
+template<typename ViewClass>
+EncodedJSValue JSC_HOST_CALL genericTypedArrayViewProtoFuncSlice(ExecState* exec)
+{
+    // 22.2.3.26
+    JSFunction* callee = jsCast<JSFunction*>(exec->callee());
+
+    ViewClass* thisObject = jsCast<ViewClass*>(exec->thisValue());
+
+    if (!exec->argumentCount())
+        return throwVMError(exec, createTypeError(exec, "Expected at least one argument"));
+
+    unsigned thisLength = thisObject->length();
+
+    unsigned begin = argumentClampedIndexFromStartOrEnd(exec, 0, thisLength);
+    unsigned end = argumentClampedIndexFromStartOrEnd(exec, 1, thisLength, thisLength);
+
+    // Clamp end to begin.
+    end = std::max(begin, end);
+
+    ASSERT(end >= begin);
+    unsigned length = end - begin;
+
+    typename ViewClass::ElementType* array = thisObject->typedVector();
+
+    Structure* structure =
+    callee->globalObject()->typedArrayStructure(ViewClass::TypedArrayStorageType);
+
+    ViewClass* result = ViewClass::createUninitialized(exec, structure, length);
+
+    // We can use memcpy since we know this a new buffer
+    memcpy(static_cast<void*>(result->typedVector()), static_cast<void*>(array + begin), length * thisObject->elementSize);
+
+    return JSValue::encode(result);
+}
+
+template<typename ViewClass>
+EncodedJSValue JSC_HOST_CALL genericTypedArrayViewProtoFuncSubarray(ExecState* exec)
+{
+    // 22.2.3.23
+    JSFunction* callee = jsCast<JSFunction*>(exec->callee());
+
+    ViewClass* thisObject = jsCast<ViewClass*>(exec->thisValue());
+
+    if (!exec->argumentCount())
+        return throwVMError(exec, createTypeError(exec, "Expected at least one argument"));
+
+    // Get the length here; later assert that the length didn't change.
+    unsigned thisLength = thisObject->length();
+
+    unsigned begin = argumentClampedIndexFromStartOrEnd(exec, 0, thisLength);
+    unsigned end = argumentClampedIndexFromStartOrEnd(exec, 1, thisLength, thisLength);
+
+    // Clamp end to begin.
+    end = std::max(begin, end);
+
+    ASSERT(end >= begin);
+    unsigned offset = begin;
+    unsigned length = end - begin;
+
+    RefPtr<ArrayBuffer> arrayBuffer = thisObject->buffer();
+    RELEASE_ASSERT(thisLength == thisObject->length());
+
+    Structure* structure =
+    callee->globalObject()->typedArrayStructure(ViewClass::TypedArrayStorageType);
+
+    ViewClass* result = ViewClass::create(
+        exec, structure, arrayBuffer,
+        thisObject->byteOffset() + offset * ViewClass::elementSize,
+        length);
+
+    return JSValue::encode(result);
+}
+
+template<typename ViewClass>
+EncodedJSValue JSC_HOST_CALL typedArrayViewProtoFuncValues(ExecState* exec)
+{
+    // 22.2.3.29
+    ViewClass* thisObject = jsCast<ViewClass*>(exec->thisValue());
+
+    return JSValue::encode(JSArrayIterator::create(exec, exec->callee()->globalObject()->arrayIteratorStructure(), ArrayIterateValue, thisObject));
+}
+
+} // namespace JSC
+
+#endif /* JSGenericTypedArrayViewPrototypeFunctions_h */
index 459997a..dab55bc 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2013-2015 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 #ifndef JSGenericTypedArrayViewPrototypeInlines_h
 #define JSGenericTypedArrayViewPrototypeInlines_h
 
-#include "Error.h"
-#include "ExceptionHelpers.h"
-#include "JSFunction.h"
 #include "JSGenericTypedArrayViewPrototype.h"
-#include <wtf/StdLibExtras.h>
 
 namespace JSC {
-
-template<typename ViewClass>
-EncodedJSValue JSC_HOST_CALL genericTypedArrayViewProtoFuncSet(ExecState* exec)
-{
-    ViewClass* thisObject = jsDynamicCast<ViewClass*>(exec->thisValue());
-    if (!thisObject)
-        return throwVMError(exec, createTypeError(exec, "Receiver should be a typed array view"));
-    
-    if (!exec->argumentCount())
-        return throwVMError(exec, createTypeError(exec, "Expected at least one argument"));
     
-    JSObject* sourceArray = jsDynamicCast<JSObject*>(exec->uncheckedArgument(0));
-    if (!sourceArray)
-        return throwVMError(exec, createTypeError(exec, "First argument should be an object"));
-    
-    unsigned offset;
-    if (exec->argumentCount() >= 2) {
-        offset = exec->uncheckedArgument(1).toUInt32(exec);
-        if (exec->hadException())
-            return JSValue::encode(jsUndefined());
-    } else
-        offset = 0;
-    
-    unsigned length = sourceArray->get(exec, exec->vm().propertyNames->length).toUInt32(exec);
-    if (exec->hadException())
-        return JSValue::encode(jsUndefined());
-    
-    thisObject->set(exec, sourceArray, offset, length);
-    return JSValue::encode(jsUndefined());
-}
-
-template<typename ViewClass>
-EncodedJSValue JSC_HOST_CALL genericTypedArrayViewProtoFuncSubarray(ExecState* exec)
-{
-    JSFunction* callee = jsCast<JSFunction*>(exec->callee());
-    
-    ViewClass* thisObject = jsDynamicCast<ViewClass*>(exec->thisValue());
-    if (!thisObject)
-        return throwVMError(exec, createTypeError(exec, "Receiver should be a typed array view"));
-    
-    if (!exec->argumentCount())
-        return throwVMError(exec, createTypeError(exec, "Expected at least one argument"));
-    
-    int32_t begin = exec->uncheckedArgument(0).toInt32(exec);
-    if (exec->hadException())
-        return JSValue::encode(jsUndefined());
-    
-    int32_t end;
-    if (exec->argumentCount() >= 2) {
-        end = exec->uncheckedArgument(1).toInt32(exec);
-        if (exec->hadException())
-            return JSValue::encode(jsUndefined());
-    } else
-        end = thisObject->length();
-    
-    // Get the length here; later assert that the length didn't change.
-    unsigned thisLength = thisObject->length();
-    
-    // Handle negative indices: -x => length - x
-    if (begin < 0)
-        begin = std::max(static_cast<int>(thisLength + begin), 0);
-    if (end < 0)
-        end = std::max(static_cast<int>(thisLength + end), 0);
-    
-    // Clamp the indices to the bounds of the array.
-    ASSERT(begin >= 0);
-    ASSERT(end >= 0);
-    begin = std::min(begin, static_cast<int32_t>(thisLength));
-    end = std::min(end, static_cast<int32_t>(thisLength));
-    
-    // Clamp end to begin.
-    end = std::max(begin, end);
-    
-    ASSERT(end >= begin);
-    unsigned offset = begin;
-    unsigned length = end - begin;
-    
-    RefPtr<ArrayBuffer> arrayBuffer = thisObject->buffer();
-    RELEASE_ASSERT(thisLength == thisObject->length());
-    
-    Structure* structure =
-        callee->globalObject()->typedArrayStructure(ViewClass::TypedArrayStorageType);
-    
-    ViewClass* result = ViewClass::create(
-        exec, structure, arrayBuffer,
-        thisObject->byteOffset() + offset * ViewClass::elementSize,
-        length);
-    
-    return JSValue::encode(result);
-}
-
 template<typename ViewClass>
 JSGenericTypedArrayViewPrototype<ViewClass>::JSGenericTypedArrayViewPrototype(VM& vm, Structure* structure)
     : Base(vm, structure)
@@ -132,15 +38,14 @@ JSGenericTypedArrayViewPrototype<ViewClass>::JSGenericTypedArrayViewPrototype(VM
 
 template<typename ViewClass>
 void JSGenericTypedArrayViewPrototype<ViewClass>::finishCreation(
-    VM& vm, JSGlobalObject* globalObject)
+    VM& vm, JSGlobalObject*)
 {
     Base::finishCreation(vm);
     
     ASSERT(inherits(info()));
-    
-    JSC_NATIVE_FUNCTION(vm.propertyNames->set, genericTypedArrayViewProtoFuncSet<ViewClass>, DontEnum, 2);
-    JSC_NATIVE_FUNCTION(vm.propertyNames->subarray, genericTypedArrayViewProtoFuncSubarray<ViewClass>, DontEnum, 2);
+
     putDirect(vm, vm.propertyNames->BYTES_PER_ELEMENT, jsNumber(ViewClass::elementSize), DontEnum | ReadOnly | DontDelete);
+
 }
 
 template<typename ViewClass>
index c9ec9d9..5272678 100644 (file)
@@ -99,6 +99,7 @@
 #include "JSTemplateRegistryKey.h"
 #include "JSTypedArrayConstructors.h"
 #include "JSTypedArrayPrototypes.h"
+#include "JSTypedArrayViewPrototype.h"
 #include "JSTypedArrays.h"
 #include "JSWASMModule.h"
 #include "JSWeakMap.h"
@@ -294,16 +295,18 @@ void JSGlobalObject::init(VM& vm)
     protoAccessor->setSetter(vm, this, JSFunction::create(vm, this, 0, String(), globalFuncProtoSetter));
     m_objectPrototype->putDirectNonIndexAccessor(vm, vm.propertyNames->underscoreProto, protoAccessor, Accessor | DontEnum);
     m_functionPrototype->structure()->setPrototypeWithoutTransition(vm, m_objectPrototype.get());
-    
-    m_typedArrays[toIndex(TypeInt8)].prototype.set(vm, this, JSInt8ArrayPrototype::create(vm, this, JSInt8ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
-    m_typedArrays[toIndex(TypeInt16)].prototype.set(vm, this, JSInt16ArrayPrototype::create(vm, this, JSInt16ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
-    m_typedArrays[toIndex(TypeInt32)].prototype.set(vm, this, JSInt32ArrayPrototype::create(vm, this, JSInt32ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
-    m_typedArrays[toIndex(TypeUint8)].prototype.set(vm, this, JSUint8ArrayPrototype::create(vm, this, JSUint8ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
-    m_typedArrays[toIndex(TypeUint8Clamped)].prototype.set(vm, this, JSUint8ClampedArrayPrototype::create(vm, this, JSUint8ClampedArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
-    m_typedArrays[toIndex(TypeUint16)].prototype.set(vm, this, JSUint16ArrayPrototype::create(vm, this, JSUint16ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
-    m_typedArrays[toIndex(TypeUint32)].prototype.set(vm, this, JSUint32ArrayPrototype::create(vm, this, JSUint32ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
-    m_typedArrays[toIndex(TypeFloat32)].prototype.set(vm, this, JSFloat32ArrayPrototype::create(vm, this, JSFloat32ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
-    m_typedArrays[toIndex(TypeFloat64)].prototype.set(vm, this, JSFloat64ArrayPrototype::create(vm, this, JSFloat64ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
+
+    JSTypedArrayViewPrototype* typedArrayProto = JSTypedArrayViewPrototype::create(vm, this, JSTypedArrayViewPrototype::createStructure(vm, this, m_objectPrototype.get()));
+
+    m_typedArrays[toIndex(TypeInt8)].prototype.set(vm, this, JSInt8ArrayPrototype::create(vm, this, JSInt8ArrayPrototype::createStructure(vm, this, typedArrayProto)));
+    m_typedArrays[toIndex(TypeInt16)].prototype.set(vm, this, JSInt16ArrayPrototype::create(vm, this, JSInt16ArrayPrototype::createStructure(vm, this, typedArrayProto)));
+    m_typedArrays[toIndex(TypeInt32)].prototype.set(vm, this, JSInt32ArrayPrototype::create(vm, this, JSInt32ArrayPrototype::createStructure(vm, this, typedArrayProto)));
+    m_typedArrays[toIndex(TypeUint8)].prototype.set(vm, this, JSUint8ArrayPrototype::create(vm, this, JSUint8ArrayPrototype::createStructure(vm, this, typedArrayProto)));
+    m_typedArrays[toIndex(TypeUint8Clamped)].prototype.set(vm, this, JSUint8ClampedArrayPrototype::create(vm, this, JSUint8ClampedArrayPrototype::createStructure(vm, this, typedArrayProto)));
+    m_typedArrays[toIndex(TypeUint16)].prototype.set(vm, this, JSUint16ArrayPrototype::create(vm, this, JSUint16ArrayPrototype::createStructure(vm, this, typedArrayProto)));
+    m_typedArrays[toIndex(TypeUint32)].prototype.set(vm, this, JSUint32ArrayPrototype::create(vm, this, JSUint32ArrayPrototype::createStructure(vm, this, typedArrayProto)));
+    m_typedArrays[toIndex(TypeFloat32)].prototype.set(vm, this, JSFloat32ArrayPrototype::create(vm, this, JSFloat32ArrayPrototype::createStructure(vm, this, typedArrayProto)));
+    m_typedArrays[toIndex(TypeFloat64)].prototype.set(vm, this, JSFloat64ArrayPrototype::create(vm, this, JSFloat64ArrayPrototype::createStructure(vm, this, typedArrayProto)));
     m_typedArrays[toIndex(TypeDataView)].prototype.set(vm, this, JSDataViewPrototype::create(vm, JSDataViewPrototype::createStructure(vm, this, m_objectPrototype.get())));
     
     m_typedArrays[toIndex(TypeInt8)].structure.set(vm, this, JSInt8Array::createStructure(vm, this, m_typedArrays[toIndex(TypeInt8)].prototype.get()));
@@ -487,6 +490,8 @@ putDirectWithoutTransition(vm, vm.propertyNames-> jsName, lowerName ## Construct
     JSFunction* privateFuncGetTemplateObject = JSFunction::create(vm, this, 0, String(), getTemplateObject);
     JSFunction* privateFuncToLength = JSFunction::createBuiltinFunction(vm, globalObjectToLengthCodeGenerator(vm), this);
     JSFunction* privateFuncToInteger = JSFunction::createBuiltinFunction(vm, globalObjectToIntegerCodeGenerator(vm), this);
+    JSFunction* privateFuncTypedArrayLength = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncLength);
+    JSFunction* privateFuncTypedArraySort = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncSort);
 
     GlobalPropertyInfo staticGlobals[] = {
         GlobalPropertyInfo(vm.propertyNames->NaN, jsNaN(), DontEnum | DontDelete | ReadOnly),
@@ -498,6 +503,8 @@ putDirectWithoutTransition(vm, vm.propertyNames-> jsName, lowerName ## Construct
         GlobalPropertyInfo(vm.propertyNames->getTemplateObjectPrivateName, privateFuncGetTemplateObject, DontEnum | DontDelete | ReadOnly),
         GlobalPropertyInfo(vm.propertyNames->enqueueJobPrivateName, JSFunction::create(vm, this, 0, String(), enqueueJob), DontEnum | DontDelete | ReadOnly),
         GlobalPropertyInfo(vm.propertyNames->TypeErrorPrivateName, m_typeErrorConstructor.get(), DontEnum | DontDelete | ReadOnly),
+        GlobalPropertyInfo(vm.propertyNames->typedArrayLengthPrivateName, privateFuncTypedArrayLength, DontEnum | DontDelete | ReadOnly),
+        GlobalPropertyInfo(vm.propertyNames->typedArraySortPrivateName, privateFuncTypedArraySort, DontEnum | DontDelete | ReadOnly),
         GlobalPropertyInfo(vm.propertyNames->BuiltinLogPrivateName, builtinLog, DontEnum | DontDelete | ReadOnly),
         GlobalPropertyInfo(vm.propertyNames->ArrayPrivateName, arrayConstructor, DontEnum | DontDelete | ReadOnly),
         GlobalPropertyInfo(vm.propertyNames->NumberPrivateName, numberConstructor, DontEnum | DontDelete | ReadOnly),
index 13ad863..61bb150 100644 (file)
@@ -1475,6 +1475,16 @@ ALWAYS_INLINE Identifier makeIdentifier(VM&, const Identifier& name)
     putDirectBuiltinFunction(\
         vm, globalObject, makeIdentifier(vm, (jsName)), (generatorName)(vm), (attributes))
 
+// Helper for defining native getters on properties.
+#define JSC_NATIVE_GETTER(jsName, cppName, attributes, length) do { \
+        Identifier ident = makeIdentifier(vm, (jsName)); \
+        GetterSetter* accessor = GetterSetter::create(vm, globalObject); \
+        JSFunction* function = JSFunction::create(vm, globalObject, (length), ident.string(), (cppName)); \
+        accessor->setGetter(vm, globalObject, function); \
+        putDirectNonIndexAccessor(vm, ident, accessor, (attributes) | Accessor); \
+    } while (false)
+
+
 } // namespace JSC
 
 #endif // JSObject_h
index c01d8f8..d9282ea 100644 (file)
@@ -31,6 +31,9 @@
 
 namespace JSC {
 
+const ClassInfo JSTypedArrayViewPrototype::s_info = {"Prototype", &JSTypedArrayViewPrototype::Base::s_info, 0,
+    CREATE_METHOD_TABLE(JSTypedArrayViewPrototype)};
+
 #define MAKE_S_INFO(type) \
     template<> const ClassInfo JS##type##Prototype::s_info = {#type "Prototype", &JS##type##Prototype::Base::s_info, 0, CREATE_METHOD_TABLE(JS##type##Prototype)}
 
index b0f1c11..8ede860 100644 (file)
@@ -27,6 +27,7 @@
 #define JSTypedArrayPrototypes_h
 
 #include "JSGenericTypedArrayViewPrototype.h"
+#include "JSTypedArrayViewPrototype.h"
 #include "JSTypedArrays.h"
 
 namespace JSC {
diff --git a/Source/JavaScriptCore/runtime/JSTypedArrayViewPrototype.cpp b/Source/JavaScriptCore/runtime/JSTypedArrayViewPrototype.cpp
new file mode 100644 (file)
index 0000000..a61f204
--- /dev/null
@@ -0,0 +1,266 @@
+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "JSTypedArrayViewPrototype.h"
+
+#include "CallFrame.h"
+#include "GetterSetter.h"
+#include "JSCellInlines.h"
+#include "JSFunction.h"
+#include "JSGenericTypedArrayViewPrototypeFunctions.h"
+#include "TypedArrayAdaptors.h"
+
+namespace JSC {
+
+#define CALL_GENERIC_TYPEDARRAY_PROTOTYPE_FUNCTION(functionName) do {                           \
+    switch (thisValue.getObject()->classInfo()->typedArrayStorageType) {                        \
+    case TypeUint8Clamped:                                                                      \
+        return functionName<JSUint8ClampedArray>(exec);                                         \
+    case TypeInt32:                                                                             \
+        return functionName<JSInt32Array>(exec);                                                \
+    case TypeUint32:                                                                            \
+        return functionName<JSUint32Array>(exec);                                               \
+    case TypeFloat64:                                                                           \
+        return functionName<JSFloat64Array>(exec);                                              \
+    case TypeFloat32:                                                                           \
+        return functionName<JSFloat32Array>(exec);                                              \
+    case TypeInt8:                                                                              \
+        return functionName<JSInt8Array>(exec);                                                 \
+    case TypeUint8:                                                                             \
+        return functionName<JSUint8Array>(exec);                                                \
+    case TypeInt16:                                                                             \
+        return functionName<JSInt16Array>(exec);                                                \
+    case TypeUint16:                                                                            \
+        return functionName<JSUint16Array>(exec);                                               \
+    case NotTypedArray:                                                                         \
+    case TypeDataView:                                                                          \
+        return throwVMError(exec, createTypeError(exec,                                         \
+            "Receiver should be a typed array view"));                                          \
+    }                                                                                           \
+    RELEASE_ASSERT_NOT_REACHED();                                                               \
+} while (false)
+
+EncodedJSValue JSC_HOST_CALL typedArrayViewPrivateFuncLength(ExecState* exec)
+{
+    JSArrayBufferView* thisObject = jsDynamicCast<JSArrayBufferView*>(exec->argument(0));
+    if (!thisObject)
+        return throwVMError(exec, createTypeError(exec, "Receiver should be a typed array view"));
+
+    return JSValue::encode(jsNumber(thisObject->length()));
+}
+
+EncodedJSValue JSC_HOST_CALL typedArrayViewPrivateFuncSort(ExecState* exec)
+{
+    JSValue thisValue = exec->argument(0);
+    if (!thisValue.isObject())
+        return throwVMError(exec, createTypeError(exec, "Receiver should be a typed array view but was not an object"));
+    CALL_GENERIC_TYPEDARRAY_PROTOTYPE_FUNCTION(genericTypedArrayViewPrivateFuncSort);
+}
+
+static EncodedJSValue JSC_HOST_CALL typedArrayViewProtoFuncSet(ExecState* exec)
+{
+    JSValue thisValue = exec->thisValue();
+    if (!thisValue.isObject())
+        return throwVMError(exec, createTypeError(exec, "Receiver should be a typed array view but was not an object"));
+    CALL_GENERIC_TYPEDARRAY_PROTOTYPE_FUNCTION(genericTypedArrayViewProtoFuncSet);
+}
+
+static EncodedJSValue JSC_HOST_CALL typedArrayViewProtoFuncEntries(ExecState* exec)
+{
+    JSValue thisValue = exec->thisValue();
+    if (!thisValue.isObject())
+        return throwVMError(exec, createTypeError(exec, "Receiver should be a typed array view but was not an object"));
+    CALL_GENERIC_TYPEDARRAY_PROTOTYPE_FUNCTION(genericTypedArrayViewProtoFuncEntries);
+}
+
+static EncodedJSValue JSC_HOST_CALL typedArrayViewProtoFuncCopyWithin(ExecState* exec)
+{
+    JSValue thisValue = exec->thisValue();
+    if (!thisValue.isObject())
+        return throwVMError(exec, createTypeError(exec, "Receiver should be a typed array view but was not an object"));
+    CALL_GENERIC_TYPEDARRAY_PROTOTYPE_FUNCTION(genericTypedArrayViewProtoFuncCopyWithin);
+}
+
+static EncodedJSValue JSC_HOST_CALL typedArrayViewProtoFuncFill(ExecState* exec)
+{
+    JSValue thisValue = exec->thisValue();
+    if (!thisValue.isObject())
+        return throwVMError(exec, createTypeError(exec, "Receiver should be a typed array view but was not an object"));
+    CALL_GENERIC_TYPEDARRAY_PROTOTYPE_FUNCTION(genericTypedArrayViewProtoFuncFill);
+}
+
+static EncodedJSValue JSC_HOST_CALL typedArrayViewProtoFuncLastIndexOf(ExecState* exec)
+{
+    JSValue thisValue = exec->thisValue();
+    if (!thisValue.isObject())
+        return throwVMError(exec, createTypeError(exec, "Receiver should be a typed array view but was not an object"));
+    CALL_GENERIC_TYPEDARRAY_PROTOTYPE_FUNCTION(genericTypedArrayViewProtoFuncLastIndexOf);
+}
+
+static EncodedJSValue JSC_HOST_CALL typedArrayViewProtoFuncIndexOf(ExecState* exec)
+{
+    JSValue thisValue = exec->thisValue();
+    if (!thisValue.isObject())
+        return throwVMError(exec, createTypeError(exec, "Receiver should be a typed array view but was not an object"));
+    CALL_GENERIC_TYPEDARRAY_PROTOTYPE_FUNCTION(genericTypedArrayViewProtoFuncIndexOf);
+}
+
+static EncodedJSValue JSC_HOST_CALL typedArrayViewProtoFuncJoin(ExecState* exec)
+{
+    JSValue thisValue = exec->thisValue();
+    if (!thisValue.isObject())
+        return throwVMError(exec, createTypeError(exec, "Receiver should be a typed array view but was not an object"));
+    CALL_GENERIC_TYPEDARRAY_PROTOTYPE_FUNCTION(genericTypedArrayViewProtoFuncJoin);
+}
+
+static EncodedJSValue JSC_HOST_CALL typedArrayViewProtoFuncKeys(ExecState* exec)
+{
+    JSValue thisValue = exec->thisValue();
+    if (!thisValue.isObject())
+        return throwVMError(exec, createTypeError(exec, "Receiver should be a typed array view but was not an object"));
+    CALL_GENERIC_TYPEDARRAY_PROTOTYPE_FUNCTION(genericTypedArrayViewProtoFuncKeys);
+}
+
+static EncodedJSValue JSC_HOST_CALL typedArrayViewProtoGetterFuncLength(ExecState* exec)
+{
+    JSValue thisValue = exec->thisValue();
+    if (!thisValue.isObject())
+        return throwVMError(exec, createTypeError(exec, "Receiver should be a typed array view but was not an object"));
+    CALL_GENERIC_TYPEDARRAY_PROTOTYPE_FUNCTION(genericTypedArrayViewProtoGetterFuncLength);
+}
+
+static EncodedJSValue JSC_HOST_CALL typedArrayViewProtoGetterFuncByteLength(ExecState* exec)
+{
+    JSValue thisValue = exec->thisValue();
+    if (!thisValue.isObject())
+        return throwVMError(exec, createTypeError(exec, "Receiver should be a typed array view but was not an object"));
+    CALL_GENERIC_TYPEDARRAY_PROTOTYPE_FUNCTION(genericTypedArrayViewProtoGetterFuncByteLength);
+}
+
+static EncodedJSValue JSC_HOST_CALL typedArrayViewProtoGetterFuncByteOffset(ExecState* exec)
+{
+    JSValue thisValue = exec->thisValue();
+    if (!thisValue.isObject())
+        return throwVMError(exec, createTypeError(exec, "Receiver should be a typed array view but was not an object"));
+    CALL_GENERIC_TYPEDARRAY_PROTOTYPE_FUNCTION(genericTypedArrayViewProtoGetterFuncByteOffset);
+}
+
+static EncodedJSValue JSC_HOST_CALL typedArrayViewProtoFuncReverse(ExecState* exec)
+{
+    JSValue thisValue = exec->thisValue();
+    if (!thisValue.isObject())
+        return throwVMError(exec, createTypeError(exec, "Receiver should be a typed array view but was not an object"));
+    CALL_GENERIC_TYPEDARRAY_PROTOTYPE_FUNCTION(genericTypedArrayViewProtoFuncReverse);
+}
+
+static EncodedJSValue JSC_HOST_CALL typedArrayViewProtoFuncSubarray(ExecState* exec)
+{
+    JSValue thisValue = exec->thisValue();
+    if (!thisValue.isObject())
+        return throwVMError(exec, createTypeError(exec, "Receiver should be a typed array view but was not an object"));
+    CALL_GENERIC_TYPEDARRAY_PROTOTYPE_FUNCTION(genericTypedArrayViewProtoFuncSubarray);
+}
+
+static EncodedJSValue JSC_HOST_CALL typedArrayViewProtoFuncSlice(ExecState* exec)
+{
+    JSValue thisValue = exec->thisValue();
+    if (!thisValue.isObject())
+        return throwVMError(exec, createTypeError(exec, "Receiver should be a typed array view but was not an object"));
+    CALL_GENERIC_TYPEDARRAY_PROTOTYPE_FUNCTION(genericTypedArrayViewProtoFuncSlice);
+}
+
+static EncodedJSValue JSC_HOST_CALL typedArrayViewProtoFuncValues(ExecState* exec)
+{
+    JSValue thisValue = exec->thisValue();
+    if (!thisValue.isObject())
+        return throwVMError(exec, createTypeError(exec, "Receiver should be a typed array view but was not an object"));
+    CALL_GENERIC_TYPEDARRAY_PROTOTYPE_FUNCTION(typedArrayViewProtoFuncValues);
+}
+
+#undef CALL_GENERIC_TYPEDARRAY_PROTOTYPE_FUNCTION
+
+JSTypedArrayViewPrototype::JSTypedArrayViewPrototype(VM& vm, Structure* structure)
+    : Base(vm, structure)
+{
+}
+
+void JSTypedArrayViewPrototype::finishCreation(VM& vm, JSGlobalObject* globalObject)
+{
+    Base::finishCreation(vm);
+
+    ASSERT(inherits(info()));
+
+    JSC_NATIVE_GETTER(vm.propertyNames->byteLength, typedArrayViewProtoGetterFuncByteLength, DontEnum | ReadOnly | DontDelete, 0);
+    JSC_NATIVE_GETTER(vm.propertyNames->byteOffset, typedArrayViewProtoGetterFuncByteOffset, DontEnum | ReadOnly | DontDelete, 0);
+    JSC_NATIVE_FUNCTION("copyWithin", typedArrayViewProtoFuncCopyWithin, DontEnum, 2);
+    JSC_BUILTIN_FUNCTION("every", typedArrayPrototypeEveryCodeGenerator, DontEnum);
+    JSC_BUILTIN_FUNCTION("filter", typedArrayPrototypeFilterCodeGenerator, DontEnum);
+    JSC_BUILTIN_FUNCTION("sort", typedArrayPrototypeSortCodeGenerator, DontEnum);
+    JSC_NATIVE_FUNCTION(vm.propertyNames->entries, typedArrayViewProtoFuncEntries, DontEnum, 0);
+    JSC_NATIVE_FUNCTION("fill", typedArrayViewProtoFuncFill, DontEnum, 1);
+    JSC_BUILTIN_FUNCTION("find", typedArrayPrototypeFindCodeGenerator, DontEnum);
+    JSC_BUILTIN_FUNCTION("findIndex", typedArrayPrototypeFindIndexCodeGenerator, DontEnum);
+    JSC_BUILTIN_FUNCTION(vm.propertyNames->forEach, typedArrayPrototypeForEachCodeGenerator, DontEnum);
+    JSC_NATIVE_FUNCTION("indexOf", typedArrayViewProtoFuncIndexOf, DontEnum, 1);
+    JSC_NATIVE_FUNCTION(vm.propertyNames->join, typedArrayViewProtoFuncJoin, DontEnum, 1);
+    JSC_NATIVE_FUNCTION(vm.propertyNames->keys, typedArrayViewProtoFuncKeys, DontEnum, 0);
+    JSC_NATIVE_FUNCTION("lastIndexOf", typedArrayViewProtoFuncLastIndexOf, DontEnum, 1);
+    JSC_NATIVE_GETTER(vm.propertyNames->length, typedArrayViewProtoGetterFuncLength, DontEnum | ReadOnly | DontDelete, 0);
+    JSC_BUILTIN_FUNCTION("map", typedArrayPrototypeMapCodeGenerator, DontEnum);
+    JSC_BUILTIN_FUNCTION("reduce", typedArrayPrototypeReduceCodeGenerator, DontEnum);
+    JSC_BUILTIN_FUNCTION("reduceRight", typedArrayPrototypeReduceRightCodeGenerator, DontEnum);
+    JSC_NATIVE_FUNCTION("reverse", typedArrayViewProtoFuncReverse, DontEnum, 0);
+    JSC_NATIVE_FUNCTION(vm.propertyNames->set, typedArrayViewProtoFuncSet, DontEnum, 1);
+    JSC_NATIVE_FUNCTION(vm.propertyNames->slice, typedArrayViewProtoFuncSlice, DontEnum, 2);
+    JSC_BUILTIN_FUNCTION("some", typedArrayPrototypeSomeCodeGenerator, DontEnum);
+    JSC_NATIVE_FUNCTION(vm.propertyNames->subarray, typedArrayViewProtoFuncSubarray, DontEnum, 2);
+    JSC_BUILTIN_FUNCTION(vm.propertyNames->toLocaleString, typedArrayPrototypeToLocaleStringCodeGenerator, DontEnum);
+    JSC_NATIVE_FUNCTION(vm.propertyNames->toString, arrayProtoFuncToString, DontEnum, 0);
+
+    JSFunction* valuesFunction = JSFunction::create(vm, globalObject, 0, vm.propertyNames->values.string(), typedArrayViewProtoFuncValues);
+
+    putDirectWithoutTransition(vm, vm.propertyNames->values, valuesFunction, DontEnum);
+    putDirectWithoutTransition(vm, vm.propertyNames->iteratorSymbol, valuesFunction, DontEnum);
+
+}
+
+JSTypedArrayViewPrototype* JSTypedArrayViewPrototype::create(
+    VM& vm, JSGlobalObject* globalObject, Structure* structure)
+{
+    JSTypedArrayViewPrototype* prototype =
+    new (NotNull, allocateCell<JSTypedArrayViewPrototype>(vm.heap))
+    JSTypedArrayViewPrototype(vm, structure);
+    prototype->finishCreation(vm, globalObject);
+    return prototype;
+}
+
+Structure* JSTypedArrayViewPrototype::createStructure(
+    VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+{
+    return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
+}
+
+} // namespace JSC
diff --git a/Source/JavaScriptCore/runtime/JSTypedArrayViewPrototype.h b/Source/JavaScriptCore/runtime/JSTypedArrayViewPrototype.h
new file mode 100644 (file)
index 0000000..ad9df60
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef JSTypedArrayViewPrototype_h
+#define JSTypedArrayViewPrototype_h
+
+#include "JSObject.h"
+
+namespace JSC {
+
+class JSTypedArrayViewPrototype : public JSNonFinalObject {
+public:
+    typedef JSNonFinalObject Base;
+
+protected:
+    JSTypedArrayViewPrototype(VM&, Structure*);
+    void finishCreation(VM&, JSGlobalObject*);
+
+public:
+    static JSTypedArrayViewPrototype* create(VM&, JSGlobalObject*, Structure*);
+
+    DECLARE_INFO;
+
+    static Structure* createStructure(VM&, JSGlobalObject*, JSValue prototype);
+};
+
+EncodedJSValue JSC_HOST_CALL typedArrayViewPrivateFuncSort(ExecState*);
+EncodedJSValue JSC_HOST_CALL typedArrayViewPrivateFuncLength(ExecState*);
+
+    
+} // namespace JSC
+
+#endif /* JSTypedArrayViewPrototype_h */
index cce0164..52f0d7b 100644 (file)
 - path: es6/typed_arrays_%TypedArray%.of.js
   cmd: runES6 :fail
 - path: es6/typed_arrays_%TypedArray%.prototype.copyWithin.js
-  cmd: runES6 :fail
+  cmd: runES6 :normal
 - path: es6/typed_arrays_%TypedArray%.prototype.entries.js
-  cmd: runES6 :fail
+  cmd: runES6 :normal
 - path: es6/typed_arrays_%TypedArray%.prototype.every.js
-  cmd: runES6 :fail
+  cmd: runES6 :normal
 - path: es6/typed_arrays_%TypedArray%.prototype.fill.js
-  cmd: runES6 :fail
+  cmd: runES6 :normal
 - path: es6/typed_arrays_%TypedArray%.prototype.filter.js
-  cmd: runES6 :fail
+  cmd: runES6 :normal
 - path: es6/typed_arrays_%TypedArray%.prototype.find.js
-  cmd: runES6 :fail
+  cmd: runES6 :normal
 - path: es6/typed_arrays_%TypedArray%.prototype.findIndex.js
-  cmd: runES6 :fail
+  cmd: runES6 :normal
 - path: es6/typed_arrays_%TypedArray%.prototype.forEach.js
-  cmd: runES6 :fail
+  cmd: runES6 :normal
 - path: es6/typed_arrays_%TypedArray%.prototype.indexOf.js
-  cmd: runES6 :fail
+  cmd: runES6 :normal
 - path: es6/typed_arrays_%TypedArray%.prototype.join.js
-  cmd: runES6 :fail
+  cmd: runES6 :normal
 - path: es6/typed_arrays_%TypedArray%.prototype.keys.js
-  cmd: runES6 :fail
+  cmd: runES6 :normal
 - path: es6/typed_arrays_%TypedArray%.prototype.lastIndexOf.js
-  cmd: runES6 :fail
+  cmd: runES6 :normal
 - path: es6/typed_arrays_%TypedArray%.prototype.map.js
-  cmd: runES6 :fail
+  cmd: runES6 :normal
 - path: es6/typed_arrays_%TypedArray%.prototype.reduce.js
-  cmd: runES6 :fail
+  cmd: runES6 :normal
 - path: es6/typed_arrays_%TypedArray%.prototype.reduceRight.js
-  cmd: runES6 :fail
+  cmd: runES6 :normal
 - path: es6/typed_arrays_%TypedArray%.prototype.reverse.js
-  cmd: runES6 :fail
+  cmd: runES6 :normal
 - path: es6/typed_arrays_%TypedArray%.prototype.slice.js
-  cmd: runES6 :fail
+  cmd: runES6 :normal
 - path: es6/typed_arrays_%TypedArray%.prototype.some.js
-  cmd: runES6 :fail
+  cmd: runES6 :normal
 - path: es6/typed_arrays_%TypedArray%.prototype.sort.js
-  cmd: runES6 :fail
+  cmd: runES6 :normal
 - path: es6/typed_arrays_%TypedArray%.prototype.values.js
-  cmd: runES6 :fail
+  cmd: runES6 :normal
 - path: es6/typed_arrays_%TypedArray%.prototype[Symbol.iterator].js
-  cmd: runES6 :fail
+  cmd: runES6 :normal
 - path: es6/typed_arrays_%TypedArray%[Symbol.species].js
   cmd: runES6 :fail
 - path: es6/typed_arrays_ArrayBuffer[Symbol.species].js
diff --git a/Source/JavaScriptCore/tests/stress/resources/standalone-pre.js b/Source/JavaScriptCore/tests/stress/resources/standalone-pre.js
new file mode 100644 (file)
index 0000000..99df379
--- /dev/null
@@ -0,0 +1,332 @@
+var errorMessage;
+var self = this;
+
+self.testRunner = {
+    neverInlineFunction: neverInlineFunction,
+    numberOfDFGCompiles: numberOfDFGCompiles
+};
+
+var silentMode = true;
+var silentTestPass, didPassSomeTestsSilently, didFailSomeTests, successfullyParsed;
+silentTestPass = false;
+didPassSomeTestsSilenty = false;
+didFaileSomeTests = false;
+
+function description(msg)
+{
+    if (silentMode)
+        return;
+    print(msg);
+    print("\nOn success, you will see a series of \"PASS\" messages, followed by \"TEST COMPLETE\".\n");
+    print();
+}
+
+function debug(msg)
+{
+    if (silentMode)
+        return;
+    print(msg);
+}
+
+function escapeString(text)
+{
+    return text.replace(/\0/g, "");
+}
+
+function testPassed(msg)
+{
+    if (silentTestPass)
+        didPassSomeTestsSilently = true;
+    else if (silentMode)
+        return;
+    else
+        print("PASS", escapeString(msg));
+}
+
+function testFailed(msg)
+{
+    didFailSomeTests = true;
+    if (silentMode)
+        return;
+    print("FAIL", escapeString(msg));
+}
+
+function areNumbersEqual(_actual, _expected)
+{
+    if (_expected === 0)
+        return _actual === _expected && (1/_actual) === (1/_expected);
+    if (_actual === _expected)
+        return true;
+    if (typeof(_expected) == "number" && isNaN(_expected))
+        return typeof(_actual) == "number" && isNaN(_actual);
+    return false;
+}
+
+function areArraysEqual(_a, _b)
+{
+    try {
+        if (_a.length !== _b.length)
+            return false;
+        for (var i = 0; i < _a.length; i++)
+            if (!areNumbersEqual(_a[i], _b[i]))
+                return false;
+    } catch (ex) {
+        return false;
+    }
+    return true;
+}
+
+function isMinusZero(n)
+{
+    // the only way to tell 0 from -0 in JS is the fact that 1/-0 is
+    // -Infinity instead of Infinity
+    return n === 0 && 1/n < 0;
+}
+
+function isTypedArray(array)
+{
+    return array instanceof Int8Array
+        || array instanceof Int16Array
+        || array instanceof Int32Array
+        || array instanceof Uint8Array
+        || array instanceof Uint8ClampedArray
+        || array instanceof Uint16Array
+        || array instanceof Uint32Array
+        || array instanceof Float32Array
+        || array instanceof Float64Array;
+}
+
+function isResultCorrect(_actual, _expected)
+{
+    if (areNumbersEqual(_actual, _expected))
+        return true;
+    if (_expected
+        && (Object.prototype.toString.call(_expected) ==
+            Object.prototype.toString.call([])
+            || isTypedArray(_expected)))
+        return areArraysEqual(_actual, _expected);
+    return false;
+}
+
+function stringify(v)
+{
+    if (v === 0 && 1/v < 0)
+        return "-0";
+    else if (isTypedArray(v))
+        return v.__proto__.constructor.name + ":[" + Array.prototype.join.call(v, ",") + "]";
+    else
+        return "" + v;
+}
+
+function shouldBe(_a, _b)
+{
+  if (typeof _a != "string" || typeof _b != "string")
+    debug("WARN: shouldBe() expects string arguments");
+  var exception;
+  var _av;
+  try {
+     _av = eval(_a);
+  } catch (e) {
+     exception = e;
+  }
+  var _bv = eval(_b);
+
+  if (exception)
+    testFailed(_a + " should be " + stringify(_bv) + ". Threw exception " + exception);
+  else if (isResultCorrect(_av, _bv))
+    testPassed(_a + " is " + _b);
+  else if (typeof(_av) == typeof(_bv))
+    testFailed(_a + " should be " + stringify(_bv) + ". Was " + stringify(_av) + ".");
+  else
+    testFailed(_a + " should be " + stringify(_bv) + " (of type " + typeof _bv + "). Was " + _av + " (of type " + typeof _av + ").");
+}
+
+function dfgShouldBe(theFunction, _a, _b)
+{
+  if (typeof theFunction != "function" || typeof _a != "string" || typeof _b != "string")
+    debug("WARN: dfgShouldBe() expects a function and two strings");
+  noInline(theFunction);
+  var exception;
+  var values = [];
+
+  // Defend against tests that muck with numeric properties on array.prototype.
+  values.__proto__ = null;
+  values.push = Array.prototype.push;
+  
+  try {
+    while (!dfgCompiled({f:theFunction}))
+      values.push(eval(_a));
+    values.push(eval(_a));
+  } catch (e) {
+    exception = e;
+  }
+
+  var _bv = eval(_b);
+  if (exception)
+    testFailed(_a + " should be " + stringify(_bv) + ". On iteration " + (values.length + 1) + ", threw exception " + exception);
+  else {
+    var allPassed = true;
+    for (var i = 0; i < values.length; ++i) {
+      var _av = values[i];
+      if (isResultCorrect(_av, _bv))
+        continue;
+      if (typeof(_av) == typeof(_bv))
+        testFailed(_a + " should be " + stringify(_bv) + ". On iteration " + (i + 1) + ", was " + stringify(_av) + ".");
+      else
+        testFailed(_a + " should be " + stringify(_bv) + " (of type " + typeof _bv + "). On iteration " + (i + 1) + ", was " + _av + " (of type " + typeof _av + ").");
+      allPassed = false;
+    }
+    if (allPassed)
+      testPassed(_a + " is " + _b + " on all iterations including after DFG tier-up.");
+  }
+  
+  return values.length;
+}
+
+function shouldBeType(_a, _type) {
+  var exception;
+  var _av;
+  try {
+    _av = eval(_a);
+  } catch (e) {
+    exception = e;
+  }
+
+  var _typev = eval(_type);
+  if (_av instanceof _typev) {
+    testPassed(_a + " is an instance of " + _type);
+  } else {
+    testFailed(_a + " is not an instance of " + _type);
+  }
+}
+
+function shouldBeTrue(_a) { shouldBe(_a, "true"); }
+function shouldBeFalse(_a) { shouldBe(_a, "false"); }
+function shouldBeNaN(_a) { shouldBe(_a, "NaN"); }
+function shouldBeNull(_a) { shouldBe(_a, "null"); }
+
+function shouldBeEqualToString(a, b)
+{
+  if (typeof a !== "string" || typeof b !== "string")
+    debug("WARN: shouldBeEqualToString() expects string arguments");
+  var unevaledString = JSON.stringify(b);
+  shouldBe(a, unevaledString);
+}
+
+function shouldBeUndefined(_a)
+{
+  var exception;
+  var _av;
+  try {
+     _av = eval(_a);
+  } catch (e) {
+     exception = e;
+  }
+
+  if (exception)
+    testFailed(_a + " should be undefined. Threw exception " + exception);
+  else if (typeof _av == "undefined")
+    testPassed(_a + " is undefined.");
+  else
+    testFailed(_a + " should be undefined. Was " + _av);
+}
+
+function shouldNotThrow(_a) {
+    try {
+        eval(_a);
+        testPassed(_a + " did not throw exception.");
+    } catch (e) {
+        testFailed(_a + " should not throw exception. Threw exception " + e + ".");
+    }
+}
+
+function shouldThrow(_a, _e)
+{
+  var exception;
+  var _av;
+  try {
+     _av = eval(_a);
+  } catch (e) {
+     exception = e;
+  }
+
+  var _ev;
+  if (_e)
+      _ev =  eval(_e);
+
+  if (exception) {
+    if (typeof _e == "undefined" || exception == _ev)
+      testPassed(_a + " threw exception " + exception + ".");
+    else
+      testFailed(_a + " should throw " + (typeof _e == "undefined" ? "an exception" : _ev) + ". Threw exception " + exception + ".");
+  } else if (typeof _av == "undefined")
+    testFailed(_a + " should throw " + (typeof _e == "undefined" ? "an exception" : _ev) + ". Was undefined.");
+  else
+    testFailed(_a + " should throw " + (typeof _e == "undefined" ? "an exception" : _ev) + ". Was " + _av + ".");
+}
+
+function isSuccessfullyParsed()
+{
+    // FIXME: Remove this and only report unexpected syntax errors.
+    if (!errorMessage)
+        successfullyParsed = true;
+    shouldBeTrue("successfullyParsed");
+    if (silentTestPass && didPassSomeTestsSilently)
+        debug("Passed some tests silently.");
+    if (silentTestPass && didFailSomeTests)
+        debug("Some tests failed.");
+    debug("\nTEST COMPLETE\n");
+}
+
+
+function dfgCompiled(argument)
+{
+    var numberOfCompiles = "compiles" in argument ? argument.compiles : 1;
+    
+    if (!("f" in argument))
+        throw new Error("dfgCompiled called with invalid argument.");
+    
+    if (argument.f instanceof Array) {
+        for (var i = 0; i < argument.f.length; ++i) {
+            if (testRunner.numberOfDFGCompiles(argument.f[i]) < numberOfCompiles)
+                return false;
+        }
+    } else {
+        if (testRunner.numberOfDFGCompiles(argument.f) < numberOfCompiles)
+            return false;
+    }
+    
+    return true;
+}
+
+function dfgIncrement(argument)
+{
+    if (!self.testRunner)
+        return argument.i;
+    
+    if (argument.i < argument.n)
+        return argument.i;
+    
+    if (didFailSomeTests)
+        return argument.i;
+    
+    if (!dfgCompiled(argument))
+        return "start" in argument ? argument.start : 0;
+    
+    return argument.i;
+}
+
+function noInline(theFunction)
+{
+    if (!self.testRunner)
+        return;
+    
+    testRunner.neverInlineFunction(theFunction);
+}
+
+function finishJSTest()
+{
+    isSuccessfullyParsed();
+    if (didFailSomeTests)
+        throw new Error("Some Tests Failed");
+}
diff --git a/Source/JavaScriptCore/tests/stress/resources/typedarray-test-helper-functions.js b/Source/JavaScriptCore/tests/stress/resources/typedarray-test-helper-functions.js
new file mode 100644 (file)
index 0000000..7cd174b
--- /dev/null
@@ -0,0 +1,103 @@
+load("./resources/standalone-pre.js");
+
+var typedArrays = [Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array];
+
+var signedArrays = [Int8Array, Int16Array, Int32Array, Float32Array, Float64Array];
+
+var floatArrays = [Float32Array, Float64Array];
+
+function forEachTypedArray(constructors, testFunction /* , initialValues */ ) {
+    let initialValues = arguments[2];
+    for (let i = 0; i < constructors.length; ++i) {
+        let typedArray = constructors[i];
+
+        let array;
+        if (initialValues) {
+            array = new typedArray(initialValues);
+        } else
+            array = new typedArray();
+
+        let testResult = testFunction(array, typedArray)
+        if (testResult !== true)
+            return testResult;
+    }
+
+    return true;
+}
+
+function isSameFunctionForEachTypedArrayPrototype(name) {
+    function eq(array) { return array[name] === Int32Array.prototype[name]; }
+    return forEachTypedArray(typedArrays, eq);
+}
+
+function hasSameValues(msg, array1, array2) {
+    if (array1.length !== array2.length) {
+        debug(msg +  " first array: " + array1 + " second array: " + array2);
+        return false;
+    }
+
+    let allSame = true;
+    for (let i = 0; i < array1.length; ++i) {
+        allSame = allSame && Object.is(array1[i], array2[i]);
+    }
+
+    if (!allSame)
+        debug(msg +  " first array: " + array1 + " second array: " + array2);
+    return allSame;
+
+}
+
+function testPrototypeFunctionHelper(constructors, name, args, init, result, expectedArray) {
+
+    function foo(array, constructor) {
+        let res = eval("array." + name + args);
+
+        if (expectedArray) {
+            if (!hasSameValues("array did not change correctly on " + constructor + ",", array, expectedArray))
+                return false;
+        }
+
+        if (typeof result === "object")
+            return hasSameValues(name + " returned the wrong result on " + constructor + ",", res, result);
+        else {
+            if (res !== result) {
+                debug(name + " returned the wrong result on " + constructor + ", returned: " + res + " but expected: " + result);
+                return false;
+            }
+            return true;
+        }
+    }
+
+    return forEachTypedArray(constructors, foo, init);
+}
+
+function testPrototypeFunctionOnSigned(name, args, init, result /* expectedArray */) {
+    return testPrototypeFunctionHelper(signedArrays, name, args, init, result, arguments[4]);
+}
+
+function testPrototypeFunctionOnFloat(name, args, init, result /* expectedArray */) {
+    return testPrototypeFunctionHelper(floatArrays, name, args, init, result, arguments[4]);
+}
+
+function testPrototypeFunction(name, args, init, result /* expectedArray */) {
+    return testPrototypeFunctionHelper(typedArrays, name, args, init, result, arguments[4]);
+}
+
+function testPrototypeReceivesArray(name, thisValues) {
+    function tester (array, constructor) {
+        var passed = true;
+        for (var thisValue of thisValues) {
+            try {
+                eval("array." + name).call(thisValue);
+                passed = false;
+                debug("did not throw an error when given an invalid |this| on " + constructor);
+            } catch (err) {}
+
+        }
+
+        return passed;
+    }
+
+    return forEachTypedArray(typedArrays, tester);
+}
+
diff --git a/Source/JavaScriptCore/tests/stress/typedarray-copyWithin.js b/Source/JavaScriptCore/tests/stress/typedarray-copyWithin.js
new file mode 100644 (file)
index 0000000..e5e79aa
--- /dev/null
@@ -0,0 +1,16 @@
+load("./resources/typedarray-test-helper-functions.js");
+description("This test checks the behavior of the TypedArray.prototype.copyWithin function");
+
+
+shouldBe("Int32Array.prototype.copyWithin.length", "2");
+shouldBe("Int32Array.prototype.copyWithin.name", "'copyWithin'");
+
+shouldBeTrue("isSameFunctionForEachTypedArrayPrototype('copyWithin')");
+shouldBeTrue("testPrototypeReceivesArray('copyWithin', [undefined, this, { }, [ ], true, ''])");
+
+shouldBeTrue("testPrototypeFunction('copyWithin', '(0, 3)', [1, 2, 3, 4, 5], [4, 5, 3, 4, 5])");
+shouldBeTrue("testPrototypeFunction('copyWithin', '(0, 3, 4)', [1, 2, 3, 4, 5], [4, 2, 3, 4, 5])");
+shouldBeTrue("testPrototypeFunction('copyWithin', '(0, -2, -1)', [1, 2, 3, 4, 5], [4, 2, 3, 4, 5])");
+shouldBeTrue("testPrototypeFunction('copyWithin', '(5, -5, 5)', [1, 2, 3, 4, 5], [1, 2, 3, 4, 5])");
+shouldBeTrue("testPrototypeFunction('copyWithin', '(1, -5, 5)', [1, 2, 3, 4, 5], [1, 1, 2, 3, 4])");
+finishJSTest();
diff --git a/Source/JavaScriptCore/tests/stress/typedarray-every.js b/Source/JavaScriptCore/tests/stress/typedarray-every.js
new file mode 100644 (file)
index 0000000..27bf58d
--- /dev/null
@@ -0,0 +1,56 @@
+load("./resources/typedarray-test-helper-functions.js");
+description(
+"This test checks the behavior of the TypedArray.prototype.every function"
+);
+
+shouldBe("Int32Array.prototype.every.length", "1");
+shouldBe("Int32Array.prototype.every.name", "'every'");
+shouldBeTrue("isSameFunctionForEachTypedArrayPrototype('every')");
+shouldBeTrue("testPrototypeReceivesArray('every', [undefined, this, { }, [ ], true, ''])");
+debug("");
+
+debug("testPrototypeFunction has the following arg list (name, args, init, result [ , expectedArray ])");
+debug("");
+
+debug("1.0 Single Argument Testing");
+function isBigEnough(element, index, array) {
+    if (this.value)
+        return element >= this.value;
+    return element >= 10;
+}
+shouldBeTrue("testPrototypeFunction('every', '(isBigEnough)', [12, 5, 8, 13, 44], false)");
+shouldBeTrue("testPrototypeFunction('every', '(isBigEnough)', [12, 54, 18, 13, 44], true)");
+debug("");
+
+debug("2.0 Two Argument Testing");
+var thisValue = { value: 11 };
+shouldBeTrue("testPrototypeFunction('every', '(isBigEnough, thisValue)', [12, 15, 10, 13, 44], false)");
+shouldBeTrue("testPrototypeFunction('every', '(isBigEnough, thisValue)', [12, 54, 82, 13, 44], true)");
+debug("");
+
+debug("3.0 Array Element Changing");
+function isBigEnoughAndChange(element, index, array) {
+    array[array.length - 1 - index] = 5;
+    return (element >= 10);
+}
+shouldBeTrue("testPrototypeFunction('every', '(isBigEnoughAndChange)', [12, 15, 1, 13, 44], false, [12, 15, 5, 5, 5])");
+shouldBeTrue("testPrototypeFunction('every', '(isBigEnoughAndChange)', [12, 15, 10, 13, 44], false, [12, 5, 5, 5, 5])");
+debug("");
+
+debug("4.0 Exception Test");
+function isBigEnoughAndException(element, index, array) {
+    if(index==1) throw "exception from function";
+    return (element >= 10);
+}
+shouldThrow("testPrototypeFunction('every', '(isBigEnoughAndException)', [12, 15, 10, 13, 44], false)");
+debug("");
+
+debug("5.0 Wrong Type for Callback Test");
+shouldThrow("testPrototypeFunction('every', '(8)', [12, 15, 10, 13, 44], false)");
+shouldThrow("testPrototypeFunction('every', '(\"wrong\")', [12, 15, 10, 13, 44], false)");
+shouldThrow("testPrototypeFunction('every', '(new Object())', [12, 15, 10, 13, 44], false)");
+shouldThrow("testPrototypeFunction('every', '(null)', [12, 15, 10, 13, 44], false)");
+shouldThrow("testPrototypeFunction('every', '()', [12, 15, 10, 13, 44], false)");
+debug("");
+
+finishJSTest();
diff --git a/Source/JavaScriptCore/tests/stress/typedarray-fill.js b/Source/JavaScriptCore/tests/stress/typedarray-fill.js
new file mode 100644 (file)
index 0000000..32c5d08
--- /dev/null
@@ -0,0 +1,35 @@
+load("./resources/typedarray-test-helper-functions.js");
+description(
+"This test checks the behavior of the TypedArray.prototype.fill function"
+);
+
+shouldBe("Int32Array.prototype.fill.length", "1");
+shouldBe("Int32Array.prototype.fill.name", "'fill'");
+shouldBeTrue("isSameFunctionForEachTypedArrayPrototype('fill')");
+shouldBeTrue("testPrototypeReceivesArray('fill', [undefined, this, { }, [ ], true, ''])");
+debug("");
+
+debug("testPrototypeFunction has the following arg list (name, args, init, result [ , expectedArray ])");
+debug("");
+
+debug("1.0 Single Argument Testing");
+shouldBeTrue("testPrototypeFunction('fill', '(12)', [15, 5, 8, 13, 44], [12,12,12,12,12])");
+shouldBeTrue("testPrototypeFunction('fill', '(true)', [12, 54, 18, 13, 44], [1,1,1,1,1])");
+debug("");
+
+debug("2.0 Two Argument Testing");
+shouldBeTrue("testPrototypeFunction('fill', '(12, 2)', [14, 15, 10, 13, 44], [14, 15, 12, 12, 12])");
+shouldBeTrue("testPrototypeFunction('fill', '(4, NaN)', [14, 15, 10, 13, 44], [4, 4, 4, 4, 4])");
+shouldBeTrue("testPrototypeFunction('fill', '(4, -5)', [14, 15, 10, 13, 44], [4, 4, 4, 4, 4])");
+shouldBeTrue("testPrototypeFunction('fill', '(4, -1)', [14, 15, 10, 13, 44], [14, 15, 10, 13, 4])");
+debug("");
+
+debug("3.0 Three Argument Testing");
+shouldBeTrue("testPrototypeFunction('fill', '(4, -1, 0)', [14, 15, 10, 13, 44], [14, 15, 10, 13, 44])");
+shouldBeTrue("testPrototypeFunction('fill', '(4, 1, 1)', [14, 15, 10, 13, 44], [14, 15, 10, 13, 44])");
+shouldBeTrue("testPrototypeFunction('fill', '(4, 1, NaN)', [14, 15, 10, 13, 44], [14, 15, 10, 13, 44])");
+shouldBeTrue("testPrototypeFunction('fill', '(4, NaN, NaN)', [14, 15, 10, 13, 44], [14, 15, 10, 13, 44])");
+shouldBeTrue("testPrototypeFunction('fill', '(4, NaN, 5)', [14, 15, 10, 13, 44], [4, 4, 4, 4, 4])");
+shouldBeTrue("testPrototypeFunction('fill', '(4, -3, -2)', [14, 15, 10, 13, 44], [14, 15, 4, 13, 44])");
+shouldBeTrue("testPrototypeFunction('fill', '(4, 5, 5)', [14, 15, 10, 13, 44], [14, 15, 10, 13, 44])");
+finishJSTest();
diff --git a/Source/JavaScriptCore/tests/stress/typedarray-filter.js b/Source/JavaScriptCore/tests/stress/typedarray-filter.js
new file mode 100644 (file)
index 0000000..da9eda9
--- /dev/null
@@ -0,0 +1,51 @@
+load("./resources/typedarray-test-helper-functions.js");
+description(
+"This test checks the behavior of the TypedArray.prototype.filter function"
+);
+
+shouldBe("Int32Array.prototype.filter.length", "1");
+shouldBe("Int32Array.prototype.filter.name", "'filter'");
+shouldBeTrue("isSameFunctionForEachTypedArrayPrototype('filter')");
+shouldBeTrue("testPrototypeReceivesArray('filter', [undefined, this, { }, [ ], true, ''])");
+debug("");
+
+debug("testPrototypeFunction has the following arg list (name, args, init, result [ , expectedArray ])");
+debug("");
+
+debug("1.0 Single Argument Testing");
+function keepEven(e, i) {
+    return !(e & 1) || (this.keep ? this.keep.indexOf(i) >= 0 : false);
+}
+shouldBeTrue("testPrototypeFunction('filter', '(keepEven)', [12, 5, 8, 13, 44], [12, 8, 44])");
+shouldBeTrue("testPrototypeFunction('filter', '(keepEven)', [11, 54, 18, 13, 1], [54, 18])");
+debug("");
+
+debug("2.0 Two Argument Testing");
+var thisValue = { keep: [1, 3] };
+shouldBeTrue("testPrototypeFunction('filter', '(keepEven, thisValue)', [12, 23, 11, 1, 45], [12, 23, 1])");
+debug("");
+
+debug("3.0 Array Element Changing");
+function keepEvenAndChange(e, i, a) {
+    a[a.length - 1 - i] = 5;
+    return !(e & 1);
+}
+shouldBeTrue("testPrototypeFunction('filter', '(keepEvenAndChange)', [12, 15, 2, 13, 44], [12, 2], [5, 5, 5, 5, 5])");
+debug("");
+
+debug("4.0 Exception Test");
+function isBigEnoughAndException(element, index, array) {
+    if(index==1) throw "exception from function";
+    return (element >= 10);
+}
+shouldThrow("testPrototypeFunction('filter', '(isBigEnoughAndException)', [12, 15, 10, 13, 44], false)");
+debug("");
+
+debug("5.0 Wrong Type for Callback Test");
+shouldThrow("testPrototypeFunction('filter', '(8)', [12, 15, 10, 13, 44], false)");
+shouldThrow("testPrototypeFunction('filter', '(\"wrong\")', [12, 15, 10, 13, 44], false)");
+shouldThrow("testPrototypeFunction('filter', '(new Object())', [12, 15, 10, 13, 44], false)");
+shouldThrow("testPrototypeFunction('filter', '(null)', [12, 15, 10, 13, 44], false)");
+shouldThrow("testPrototypeFunction('filter', '()', [12, 15, 10, 13, 44], false)");
+debug("");
+finishJSTest();
diff --git a/Source/JavaScriptCore/tests/stress/typedarray-find.js b/Source/JavaScriptCore/tests/stress/typedarray-find.js
new file mode 100644 (file)
index 0000000..c90d2fd
--- /dev/null
@@ -0,0 +1,53 @@
+load("./resources/typedarray-test-helper-functions.js");
+description(
+"This test checks the behavior of the TypedArray.prototype.find function"
+);
+
+shouldBe("Int32Array.prototype.find.length", "1");
+shouldBe("Int32Array.prototype.find.name", "'find'");
+shouldBeTrue("isSameFunctionForEachTypedArrayPrototype('find')");
+shouldBeTrue("testPrototypeReceivesArray('find', [undefined, this, { }, [ ], true, ''])");
+debug("");
+
+debug("testPrototypeFunction has the following arg list (name, args, init, result [ , expectedArray ])");
+debug("");
+
+debug("1.0 Single Argument Testing");
+function keepEven(e, i) {
+    return !(e & 1) || (this.keep ? this.keep === i : false);
+}
+shouldBeTrue("testPrototypeFunction('find', '(keepEven)', [12, 5, 8, 13, 44], 12)");
+shouldBeTrue("testPrototypeFunction('find', '(keepEven)', [11, 13, 17, 13, 22], 22)");
+shouldBeTrue("testPrototypeFunction('find', '(keepEven)', [11, 13, 17, 13, 11], undefined)");
+debug("");
+
+debug("2.0 Two Argument Testing");
+var thisValue = { keep: 3 };
+shouldBeTrue("testPrototypeFunction('find', '(keepEven, thisValue)', [11, 23, 11, 1, 44], 1)");
+debug("");
+
+debug("3.0 Array Element Changing");
+function keepEvenAndChange(e, i, a) {
+    a[a.length - 1 - i] = 5;
+    return !(e & 1);
+}
+shouldBeTrue("testPrototypeFunction('find', '(keepEvenAndChange)', [11, 15, 3, 12, 44], undefined, [5, 5, 5, 5, 5])");
+debug("");
+
+debug("4.0 Exception Test");
+function isBigEnoughAndException(element, index, array) {
+    if(index==1) throw "exception from function";
+    return (element >= 10);
+}
+shouldBeTrue("testPrototypeFunction('find', '(isBigEnoughAndException)', [12, 15, 10, 13, 44], 12)");
+shouldThrow("testPrototypeFunction('find', '(isBigEnoughAndException)', [9, 15, 10, 13, 44], false)");
+debug("");
+
+debug("5.0 Wrong Type for Callback Test");
+shouldThrow("testPrototypeFunction('find', '(8)', [12, 15, 10, 13, 44], false)");
+shouldThrow("testPrototypeFunction('find', '(\"wrong\")', [12, 15, 10, 13, 44], false)");
+shouldThrow("testPrototypeFunction('find', '(new Object())', [12, 15, 10, 13, 44], false)");
+shouldThrow("testPrototypeFunction('find', '(null)', [12, 15, 10, 13, 44], false)");
+shouldThrow("testPrototypeFunction('find', '()', [12, 15, 10, 13, 44], false)");
+debug("");
+finishJSTest();
diff --git a/Source/JavaScriptCore/tests/stress/typedarray-findIndex.js b/Source/JavaScriptCore/tests/stress/typedarray-findIndex.js
new file mode 100644 (file)
index 0000000..945d3c3
--- /dev/null
@@ -0,0 +1,53 @@
+load("./resources/typedarray-test-helper-functions.js");
+description(
+"This test checks the behavior of the TypedArray.prototype.findIndex function"
+);
+
+shouldBe("Int32Array.prototype.findIndex.length", "1");
+shouldBe("Int32Array.prototype.findIndex.name", "'findIndex'");
+shouldBeTrue("isSameFunctionForEachTypedArrayPrototype('findIndex')");
+shouldBeTrue("testPrototypeReceivesArray('findIndex', [undefined, this, { }, [ ], true, ''])");
+debug("");
+
+debug("testPrototypeFunction has the following arg list (name, args, init, result [ , expectedArray ])");
+debug("");
+
+debug("1.0 Single Argument Testing");
+function keepEven(e, i) {
+    return !(e & 1) || (this.keep ? this.keep === i : false);
+}
+shouldBeTrue("testPrototypeFunction('findIndex', '(keepEven)', [12, 5, 8, 13, 44], 0)");
+shouldBeTrue("testPrototypeFunction('findIndex', '(keepEven)', [11, 13, 17, 13, 22], 4)");
+shouldBeTrue("testPrototypeFunction('findIndex', '(keepEven)', [11, 13, 17, 13, 11], -1)");
+debug("");
+
+debug("2.0 Two Argument Testing");
+var thisValue = { keep: 3 };
+shouldBeTrue("testPrototypeFunction('findIndex', '(keepEven, thisValue)', [11, 23, 11, 1, 44], 3)");
+debug("");
+
+debug("3.0 Array Element Changing");
+function keepEvenAndChange(e, i, a) {
+    a[a.length - 1 - i] = 5;
+    return !(e & 1);
+}
+shouldBeTrue("testPrototypeFunction('findIndex', '(keepEvenAndChange)', [11, 15, 3, 12, 44], -1, [5, 5, 5, 5, 5])");
+debug("");
+
+debug("4.0 Exception Test");
+function isBigEnoughAndException(element, index, array) {
+    if(index==1) throw "exception from function";
+    return (element >= 10);
+}
+shouldBeTrue("testPrototypeFunction('findIndex', '(isBigEnoughAndException)', [12, 15, 10, 13, 44], 0)");
+shouldThrow("testPrototypeFunction('findIndex', '(isBigEnoughAndException)', [9, 15, 10, 13, 44], false)");
+debug("");
+
+debug("5.0 Wrong Type for Callback Test");
+shouldThrow("testPrototypeFunction('findIndex', '(8)', [12, 15, 10, 13, 44], false)");
+shouldThrow("testPrototypeFunction('findIndex', '(\"wrong\")', [12, 15, 10, 13, 44], false)");
+shouldThrow("testPrototypeFunction('findIndex', '(new Object())', [12, 15, 10, 13, 44], false)");
+shouldThrow("testPrototypeFunction('findIndex', '(null)', [12, 15, 10, 13, 44], false)");
+shouldThrow("testPrototypeFunction('findIndex', '()', [12, 15, 10, 13, 44], false)");
+debug("");
+finishJSTest();
diff --git a/Source/JavaScriptCore/tests/stress/typedarray-forEach.js b/Source/JavaScriptCore/tests/stress/typedarray-forEach.js
new file mode 100644 (file)
index 0000000..e332c3f
--- /dev/null
@@ -0,0 +1,91 @@
+load("./resources/typedarray-test-helper-functions.js");
+description(
+"This test checks the behavior of the TypedArray.prototype.forEach function"
+);
+
+shouldBe("Int32Array.prototype.forEach.length", "1");
+shouldBe("Int32Array.prototype.forEach.name", "'forEach'");
+shouldBeTrue("isSameFunctionForEachTypedArrayPrototype('forEach')");
+shouldBeTrue("testPrototypeReceivesArray('forEach', [undefined, this, { }, [ ], true, ''])");
+debug("");
+
+var passed = true;
+var thisPassed = true;
+var typedArray;
+function createChecker(expected, callback, thisValue) {
+    function checkCorrect(array) {
+        let list = []
+        function accumulate(e, i, a) {
+            list.push(callback.call(this, e, i, a));
+        }
+
+        typedArray = array;
+        array.forEach(accumulate, thisValue);
+
+        if (list.length !== expected.length) {
+            debug("forEach did not work correctly, computed array: " + list + " expected array: " + expected);
+            passed = false;
+        }
+
+        for (let i = 0; i < list.length; ++i)
+            if (list[i] !== expected[i]) {
+                debug("forEach did not work correctly, computed array: " + list + " expected array: " + expected);
+                passed = false;
+            }
+    }
+
+    return checkCorrect;
+}
+
+function foo(e, i) {
+    if (this.value !== 3)
+        thisPassed = false;
+    return e;
+}
+
+
+debug("1.0 Single Argument Testing");
+
+forEachTypedArray(typedArrays, createChecker([1, 2, 3, 4, 5], foo, undefined), [1, 2, 3, 4, 5]);
+shouldBeTrue("passed");
+debug("");
+
+debug("2.0 Two Argument Testing");
+passed = true;
+thisPassed = true;
+
+forEachTypedArray(typedArrays, createChecker([1, 2, 3, 4, 5], foo, { value: 3 }), [1, 2, 3, 4, 5]);
+shouldBeTrue("passed && thisPassed");
+
+passed = true;
+thisPassed = true;
+forEachTypedArray(typedArrays, createChecker([1, 2, 3, 4, 5], foo, { value: 2 }), [1, 2, 3, 4, 5]);
+shouldBeTrue("passed && !thisPassed");
+debug("");
+
+debug("3.0 Array Element Changing");
+function changeArray(e, i, a) {
+    a[a.length - 1 - i] = 5;
+    return e;
+}
+
+forEachTypedArray(typedArrays, createChecker([11, 12, 13, 5, 5], changeArray), [11, 12, 13, 14, 15]);
+shouldBeTrue("passed && hasSameValues('array did not mutate correctly', typedArray, [5, 5, 5, 5, 5])");
+debug("");
+
+debug("4.0 Exception Test");
+function isBigEnoughAndException(element, index, array) {
+    if(index==1) throw "exception from function";
+    return (element);
+}
+shouldThrow("testPrototypeFunction('forEach', '(isBigEnoughAndException)', [9, 15, 10, 13, 44], false)");
+debug("");
+
+debug("5.0 Wrong Type for Callback Test");
+shouldThrow("testPrototypeFunction('forEach', '(8)', [12, 15, 10, 13, 44], false)");
+shouldThrow("testPrototypeFunction('forEach', '(\"wrong\")', [12, 15, 10, 13, 44], false)");
+shouldThrow("testPrototypeFunction('forEach', '(new Object())', [12, 15, 10, 13, 44], false)");
+shouldThrow("testPrototypeFunction('forEach', '(null)', [12, 15, 10, 13, 44], false)");
+shouldThrow("testPrototypeFunction('forEach', '()', [12, 15, 10, 13, 44], false)");
+debug("");
+finishJSTest();
diff --git a/Source/JavaScriptCore/tests/stress/typedarray-indexOf.js b/Source/JavaScriptCore/tests/stress/typedarray-indexOf.js
new file mode 100644 (file)
index 0000000..19273c8
--- /dev/null
@@ -0,0 +1,31 @@
+load("./resources/typedarray-test-helper-functions.js");
+description(
+"This test checks the behavior of the TypedArray.prototype.indexOf function"
+);
+
+shouldBe("Int32Array.prototype.indexOf.length", "1");
+shouldBe("Int32Array.prototype.indexOf.name", "'indexOf'");
+shouldBeTrue("isSameFunctionForEachTypedArrayPrototype('indexOf')");
+shouldBeTrue("testPrototypeReceivesArray('indexOf', [undefined, this, { }, [ ], true, ''])");
+debug("");
+
+debug("testPrototypeFunction has the following arg list (name, args, init, result [ , expectedArray ])");
+debug("");
+
+function keepEven(e, i) {
+    return !(e & 1) || (this.keep ? this.keep === i : false);
+}
+
+var array = [2, 5, 9, 2]
+
+shouldBeTrue("testPrototypeFunction('indexOf', '(2, -500)', array, 0)");
+shouldBeTrue("testPrototypeFunction('indexOf', '(9, 500)', array, -1)");
+shouldBeTrue("testPrototypeFunction('indexOf', '(2)', array, 0)");
+shouldBeTrue("testPrototypeFunction('indexOf', '(7)', array, -1)");
+shouldBeTrue("testPrototypeFunction('indexOf', '(2, 3)', array, 3)");
+shouldBeTrue("testPrototypeFunction('indexOf', '(2, 2)', array, 3)");
+shouldBeTrue("testPrototypeFunction('indexOf', '(2, 0)', array, 0)");
+shouldBeTrue("testPrototypeFunction('indexOf', '(2, -1)', array, 3)");
+shouldBeTrue("testPrototypeFunction('indexOf', '(2, -2)', array, 3)");
+debug("");
+finishJSTest();
diff --git a/Source/JavaScriptCore/tests/stress/typedarray-lastIndexOf.js b/Source/JavaScriptCore/tests/stress/typedarray-lastIndexOf.js
new file mode 100644 (file)
index 0000000..a386e45
--- /dev/null
@@ -0,0 +1,28 @@
+load("./resources/typedarray-test-helper-functions.js");
+description(
+"This test checks the behavior of the TypedArray.prototype.lastIndexOf function"
+);
+
+shouldBe("Int32Array.prototype.lastIndexOf.length", "1");
+shouldBe("Int32Array.prototype.lastIndexOf.name", "'lastIndexOf'");
+shouldBeTrue("isSameFunctionForEachTypedArrayPrototype('lastIndexOf')");
+shouldBeTrue("testPrototypeReceivesArray('lastIndexOf', [undefined, this, { }, [ ], true, ''])");
+debug("");
+
+debug("testPrototypeFunction has the following arg list (name, args, init, result [ , expectedArray ])");
+debug("");
+
+var array = [2, 5, 9, 2]
+
+shouldBeTrue("testPrototypeFunction('lastIndexOf', '(2, -500)', array, -1)");
+shouldBeTrue("testPrototypeFunction('lastIndexOf', '(9, 500)', array, 2)");
+shouldBeTrue("testPrototypeFunction('lastIndexOf', '(2)', array, 3)");
+shouldBeTrue("testPrototypeFunction('lastIndexOf', '(5)', array, 1)");
+shouldBeTrue("testPrototypeFunction('lastIndexOf', '(7)', array, -1)");
+shouldBeTrue("testPrototypeFunction('lastIndexOf', '(2, 3)', array, 3)");
+shouldBeTrue("testPrototypeFunction('lastIndexOf', '(2, 2)', array, 0)");
+shouldBeTrue("testPrototypeFunction('lastIndexOf', '(2, 0)', array, 0)");
+shouldBeTrue("testPrototypeFunction('lastIndexOf', '(2, -1)', array, 3)");
+shouldBeTrue("testPrototypeFunction('lastIndexOf', '(2, -2)', array, 0)");
+debug("");
+finishJSTest();
diff --git a/Source/JavaScriptCore/tests/stress/typedarray-map.js b/Source/JavaScriptCore/tests/stress/typedarray-map.js
new file mode 100644 (file)
index 0000000..bce73f5
--- /dev/null
@@ -0,0 +1,51 @@
+load("./resources/typedarray-test-helper-functions.js");
+description(
+"This test checks the behavior of the TypedArray.prototype.map function"
+);
+
+shouldBe("Int32Array.prototype.map.length", "1");
+shouldBe("Int32Array.prototype.map.name", "'map'");
+shouldBeTrue("isSameFunctionForEachTypedArrayPrototype('map')");
+shouldBeTrue("testPrototypeReceivesArray('map', [undefined, this, { }, [ ], true, ''])");
+debug("");
+
+debug("testPrototypeFunction has the following arg list (name, args, init, result [ , expectedArray ])");
+debug("");
+
+debug("1.0 Single Argument Testing");
+function even(e, i) {
+    return !(e & 1) || (this.change ? this.change.indexOf(i) >= 0 : false);
+}
+shouldBeTrue("testPrototypeFunction('map', '(even)', [12, 5, 8, 13, 44], [1, 0, 1, 0, 1], [12, 5, 8, 13, 44])");
+shouldBeTrue("testPrototypeFunction('map', '(even)', [11, 54, 18, 13, 1], [0, 1, 1, 0, 0])");
+debug("");
+
+debug("2.0 Two Argument Testing");
+var thisValue = { change: [1, 3] };
+shouldBeTrue("testPrototypeFunction('map', '(even, thisValue)', [12, 23, 11, 1, 45], [1, 1, 0, 1, 0])");
+debug("");
+
+debug("3.0 Array Element Changing");
+function evenAndChange(e, i, a) {
+    a[a.length - 1 - i] = 5;
+    return !(e & 1);
+}
+shouldBeTrue("testPrototypeFunction('map', '(evenAndChange)', [12, 15, 2, 13, 44], [1, 0, 1, 0, 0], [5, 5, 5, 5, 5])");
+debug("");
+
+debug("4.0 Exception Test");
+function isBigEnoughAndException(element, index, array) {
+    if(index==1) throw "exception from function";
+    return (element >= 10);
+}
+shouldThrow("testPrototypeFunction('map', '(isBigEnoughAndException)', [12, 15, 10, 13, 44], false)");
+debug("");
+
+debug("5.0 Wrong Type for Callback Test");
+shouldThrow("testPrototypeFunction('map', '(8)', [12, 15, 10, 13, 44], false)");
+shouldThrow("testPrototypeFunction('map', '(\"wrong\")', [12, 15, 10, 13, 44], false)");
+shouldThrow("testPrototypeFunction('map', '(new Object())', [12, 15, 10, 13, 44], false)");
+shouldThrow("testPrototypeFunction('map', '(null)', [12, 15, 10, 13, 44], false)");
+shouldThrow("testPrototypeFunction('map', '()', [12, 15, 10, 13, 44], false)");
+debug("");
+finishJSTest();
diff --git a/Source/JavaScriptCore/tests/stress/typedarray-reduce.js b/Source/JavaScriptCore/tests/stress/typedarray-reduce.js
new file mode 100644 (file)
index 0000000..eee2dcb
--- /dev/null
@@ -0,0 +1,58 @@
+load("./resources/typedarray-test-helper-functions.js");
+description(
+"This test checks the behavior of the TypedArray.prototype.reduce function"
+);
+
+shouldBe("Int32Array.prototype.reduce.length", "1");
+shouldBe("Int32Array.prototype.reduce.name", "'reduce'");
+shouldBeTrue("isSameFunctionForEachTypedArrayPrototype('reduce')");
+shouldBeTrue("testPrototypeReceivesArray('reduce', [undefined, this, { }, [ ], true, ''])");
+debug("");
+
+debug("testPrototypeFunction has the following arg list (name, args, init, result [ , expectedArray ])");
+debug("");
+
+debug("1.0 Single Argument Testing");
+function createArray(acc, e, i, a) {
+    if (typeof acc !== "object")
+        acc = [acc];
+    acc.push(e);
+    return acc;
+}
+
+function sum(acc, e, i, a) { return acc + e; }
+
+shouldBeTrue("testPrototypeFunction('reduce', '(createArray)', [12, 5, 8, 13, 44], [12, 5, 8, 13, 44], [12, 5, 8, 13, 44])");
+shouldBeTrue("testPrototypeFunction('reduce', '(sum)', [1, 2, 3, 4, 5], 15)");
+debug("");
+
+debug("2.0 Two Argument Testing");
+
+shouldBeTrue("testPrototypeFunction('reduce', '(createArray, [1])', [12, 23, 11, 1, 45], [1, 12, 23, 11, 1, 45], [12, 23, 11, 1, 45])");
+debug("");
+
+debug("3.0 Array Element Changing");
+function createArrayAndChange(acc, e, i, a) {
+    a[a.length - 1 - i] = 5;
+    acc.push(e);
+    return acc;
+}
+shouldBeTrue("testPrototypeFunction('reduce', '(createArrayAndChange, [])', [12, 15, 2, 13, 44], [12, 15, 2, 5, 5], [5, 5, 5, 5, 5])");
+debug("");
+
+debug("4.0 Exception Test");
+function isBigEnoughAndException(acc, element, index, array) {
+    if(index==1) throw "exception from function";
+    return (element >= 10);
+}
+shouldThrow("testPrototypeFunction('reduce', '(isBigEnoughAndException)', [12, 15, 10, 13, 44], false)");
+debug("");
+
+debug("5.0 Wrong Type for Callback Test");
+shouldThrow("testPrototypeFunction('reduce', '(8)', [12, 15, 10, 13, 44], false)");
+shouldThrow("testPrototypeFunction('reduce', '(\"wrong\")', [12, 15, 10, 13, 44], false)");
+shouldThrow("testPrototypeFunction('reduce', '(new Object())', [12, 15, 10, 13, 44], false)");
+shouldThrow("testPrototypeFunction('reduce', '(null)', [12, 15, 10, 13, 44], false)");
+shouldThrow("testPrototypeFunction('reduce', '()', [12, 15, 10, 13, 44], false)");
+debug("");
+finishJSTest();
diff --git a/Source/JavaScriptCore/tests/stress/typedarray-reduceRight.js b/Source/JavaScriptCore/tests/stress/typedarray-reduceRight.js
new file mode 100644 (file)
index 0000000..18533ef
--- /dev/null
@@ -0,0 +1,58 @@
+load("./resources/typedarray-test-helper-functions.js");
+description(
+"This test checks the behavior of the TypedArray.prototype.reduceRight function"
+);
+
+shouldBe("Int32Array.prototype.reduceRight.length", "1");
+shouldBe("Int32Array.prototype.reduceRight.name", "'reduceRight'");
+shouldBeTrue("isSameFunctionForEachTypedArrayPrototype('reduceRight')");
+shouldBeTrue("testPrototypeReceivesArray('reduceRight', [undefined, this, { }, [ ], true, ''])");
+debug("");
+
+debug("testPrototypeFunction has the following arg list (name, args, init, result [ , expectedArray ])");
+debug("");
+
+debug("1.0 Single Argument Testing");
+function createArray(acc, e, i, a) {
+    if (typeof acc !== "object")
+        acc = [acc];
+    acc.push(e);
+    return acc;
+}
+
+function sum(acc, e, i, a) { return acc + e; }
+
+shouldBeTrue("testPrototypeFunction('reduceRight', '(createArray)', [12, 5, 8, 13, 44], [12, 5, 8, 13, 44].reverse(), [12, 5, 8, 13, 44])");
+shouldBeTrue("testPrototypeFunction('reduceRight', '(sum)', [1, 2, 3, 4, 5], 15)");
+debug("");
+
+debug("2.0 Two Argument Testing");
+
+shouldBeTrue("testPrototypeFunction('reduceRight', '(createArray, [1])', [12, 23, 11, 1, 45], [1, 45, 1, 11, 23, 12], [12, 23, 11, 1, 45])");
+debug("");
+
+debug("3.0 Array Element Changing");
+function createArrayAndChange(acc, e, i, a) {
+    a[a.length - 1 - i] = 5;
+    acc.push(e);
+    return acc;
+}
+shouldBeTrue("testPrototypeFunction('reduceRight', '(createArrayAndChange, [])', [12, 15, 2, 13, 44], [44, 13, 2, 5, 5], [5, 5, 5, 5, 5])");
+debug("");
+
+debug("4.0 Exception Test");
+function isBigEnoughAndException(acc, element, index, array) {
+    if(index==1) throw "exception from function";
+    return (element >= 10);
+}
+shouldThrow("testPrototypeFunction('reduceRight', '(isBigEnoughAndException)', [12, 15, 10, 13, 44], false)");
+debug("");
+
+debug("5.0 Wrong Type for Callback Test");
+shouldThrow("testPrototypeFunction('reduceRight', '(8)', [12, 15, 10, 13, 44], false)");
+shouldThrow("testPrototypeFunction('reduceRight', '(\"wrong\")', [12, 15, 10, 13, 44], false)");
+shouldThrow("testPrototypeFunction('reduceRight', '(new Object())', [12, 15, 10, 13, 44], false)");
+shouldThrow("testPrototypeFunction('reduceRight', '(null)', [12, 15, 10, 13, 44], false)");
+shouldThrow("testPrototypeFunction('reduceRight', '()', [12, 15, 10, 13, 44], false)");
+debug("");
+finishJSTest();
diff --git a/Source/JavaScriptCore/tests/stress/typedarray-slice.js b/Source/JavaScriptCore/tests/stress/typedarray-slice.js
new file mode 100644 (file)
index 0000000..b74c93a
--- /dev/null
@@ -0,0 +1,44 @@
+load("./resources/typedarray-test-helper-functions.js");
+description(
+"This test checks the behavior of the TypedArray.prototype.slice function"
+);
+
+shouldBe("Int32Array.prototype.slice.length", "2");
+shouldBe("Int32Array.prototype.slice.name", "'slice'");
+shouldBeTrue("isSameFunctionForEachTypedArrayPrototype('slice')");
+shouldBeTrue("testPrototypeReceivesArray('slice', [undefined, this, { }, [ ], true, ''])");
+debug("");
+
+debug("testPrototypeFunction has the following arg list (name, args, init, result [ , expectedArray ])");
+debug("");
+
+debug("1.0 Test Basic Functionality");
+shouldBeTrue("testPrototypeFunction('slice', '(2, 3)', [12, 5, 8, 13, 44], [8], [12, 5, 8, 13, 44])");
+shouldBeTrue("testPrototypeFunction('slice', '(5, 5)', [12, 5, 8, 13, 44], [])");
+shouldBeTrue("testPrototypeFunction('slice', '(0, 5)', [12, 5, 8, 13, 44], [12, 5, 8, 13, 44])");
+shouldBeTrue("testPrototypeFunction('slice', '(0, -5)', [12, 5, 8, 13, 44], [])");
+shouldBeTrue("testPrototypeFunction('slice', '(-3, -2)', [12, 5, 8, 13, 44], [8])");
+shouldBeTrue("testPrototypeFunction('slice', '(4, 2)', [12, 5, 8, 13, 44], [])");
+shouldBeTrue("testPrototypeFunction('slice', '(-50, 50)', [12, 5, 8, 13, 44], [12, 5, 8, 13, 44])");
+debug("");
+
+debug("2.0 Preserve Underlying bits");
+
+var intView = new Int32Array(5);
+intView[0] = -1;
+var floatView = new Float32Array(intView.buffer);
+floatView = floatView.slice(0,1);
+intView = new Int32Array(floatView.buffer);
+
+shouldBe("intView[0]", "-1");
+debug("");
+
+debug("3.0 Creates New Buffer");
+
+var intView = new Int32Array(1)
+var newView = intView.slice(0,1);
+newView[0] = 1;
+
+shouldBe("intView[0]", "0");
+debug("");
+finishJSTest();
diff --git a/Source/JavaScriptCore/tests/stress/typedarray-some.js b/Source/JavaScriptCore/tests/stress/typedarray-some.js
new file mode 100644 (file)
index 0000000..5bbee60
--- /dev/null
@@ -0,0 +1,56 @@
+load("./resources/typedarray-test-helper-functions.js");
+description(
+"This test checks the behavior of the TypedArray.prototype.some function"
+);
+
+shouldBe("Int32Array.prototype.some.length", "1");
+shouldBe("Int32Array.prototype.some.name", "'some'");
+shouldBeTrue("isSameFunctionForEachTypedArrayPrototype('some')");
+shouldBeTrue("testPrototypeReceivesArray('some', [undefined, this, { }, [ ], true, ''])");
+debug("");
+
+debug("testPrototypeFunction has the following arg list (name, args, init, result [ , expectedArray ])");
+debug("");
+
+debug("1.0 Single Argument Testing");
+function isBigEnough(element, index, array) {
+    if (this.value)
+        return element >= this.value;
+    return element >= 10;
+}
+shouldBeTrue("testPrototypeFunction('some', '(isBigEnough)', [12, 5, 8, 13, 44], true, [12, 5, 8, 13, 44])");
+shouldBeTrue("testPrototypeFunction('some', '(isBigEnough)', [2, 4, 8, 3, 4], false)");
+debug("");
+
+debug("2.0 Two Argument Testing");
+var thisValue = { value: 11 };
+shouldBeTrue("testPrototypeFunction('some', '(isBigEnough, thisValue)', [2, 5, 10, 3, 4], false)");
+shouldBeTrue("testPrototypeFunction('some', '(isBigEnough, thisValue)', [12, 54, 82, 13, 44], true)");
+debug("");
+
+debug("3.0 Array Element Changing");
+function isBigEnoughAndChange(element, index, array) {
+    array[array.length - 1 - index] = 5;
+    return (element >= 10);
+}
+shouldBeTrue("testPrototypeFunction('some', '(isBigEnoughAndChange)', [2, 5, 1, 13, 44], false, [5, 5, 5, 5, 5])");
+shouldBeTrue("testPrototypeFunction('some', '(isBigEnoughAndChange)', [12, 15, 10, 13, 44], true, [12, 15, 10, 13, 5])");
+debug("");
+
+debug("4.0 Exception Test");
+function isBigEnoughAndException(element, index, array) {
+    if(index==1) throw "exception from function";
+    return (element >= 10);
+}
+shouldBeTrue("testPrototypeFunction('some', '(isBigEnoughAndException)', [12, 15, 10, 13, 44], true)");
+shouldThrow("testPrototypeFunction('some', '(isBigEnoughAndException)', [1, 15, 10, 13, 44], false)");
+debug("");
+
+debug("5.0 Wrong Type for Callback Test");
+shouldThrow("testPrototypeFunction('some', '(8)', [12, 15, 10, 13, 44], false)");
+shouldThrow("testPrototypeFunction('some', '(\"wrong\")', [12, 15, 10, 13, 44], false)");
+shouldThrow("testPrototypeFunction('some', '(new Object())', [12, 15, 10, 13, 44], false)");
+shouldThrow("testPrototypeFunction('some', '(null)', [12, 15, 10, 13, 44], false)");
+shouldThrow("testPrototypeFunction('some', '()', [12, 15, 10, 13, 44], false)");
+debug("");
+finishJSTest();
diff --git a/Source/JavaScriptCore/tests/stress/typedarray-sort.js b/Source/JavaScriptCore/tests/stress/typedarray-sort.js
new file mode 100644 (file)
index 0000000..6941e0a
--- /dev/null
@@ -0,0 +1,57 @@
+load("./resources/typedarray-test-helper-functions.js");
+description(
+"This test checks the behavior of the TypedArray.prototype.sort function"
+);
+
+shouldBe("Int32Array.prototype.sort.length", "1");
+shouldBe("Int32Array.prototype.sort.name", "'sort'");
+shouldBeTrue("isSameFunctionForEachTypedArrayPrototype('sort')");
+shouldBeTrue("testPrototypeReceivesArray('sort', [undefined, this, { }, [ ], true, ''])");
+debug("");
+
+debug("testPrototypeFunction has the following arg list (name, args, init, result [ , expectedArray ])");
+debug("");
+
+debug("1.0 No Argument Testing");
+shouldBeTrue("testPrototypeFunction('sort', '()', [12, 5, 8, 13, 44], [5, 8, 12, 13, 44], [5, 8, 12, 13, 44])");
+shouldBeTrue("testPrototypeFunction('sort', '()', [2, 4, 8, 3, 4], [2, 3, 4, 4, 8])");
+debug("");
+
+debug("1.1 Signed Numbers");
+shouldBeTrue("testPrototypeFunctionOnSigned('sort', '()', [12, -5, 8, -13, 44], [-13, -5, 8, 12, 44])");
+debug("");
+
+debug("1.2 Float Numbers");
+shouldBeTrue("testPrototypeFunctionOnFloat('sort', '()', [12, -5, 0, -0, -13, 44], [-13, -5, -0, 0, 12, 44])");
+
+debug("1.3 Negative NaNs");
+var buffer = new ArrayBuffer(8);
+var intView = new Int32Array(buffer);
+var floatView = new Float32Array(buffer);
+intView[0] = -1;
+
+floatView.sort();
+shouldBeTrue("Object.is(floatView[0],0) && Object.is(floatView[1], NaN)");
+debug("");
+
+debug("2.0 Custom Function Testing");
+function sortBackwards(a, b) { return b - a; }
+shouldBeTrue("testPrototypeFunction('sort', '(sortBackwards)', [2, 5, 10, 3, 4], [10, 5, 4, 3, 2])");
+debug("");
+
+debug("3.0 Exception Test");
+var count = 0;
+function compareException(a, b) {
+    if(count++ === 4) throw "exception from function";
+    return a < b;
+}
+shouldThrow("testPrototypeFunction('sort', '(compareException)', [12, 15, 10, 13, 44], true)");
+debug("");
+
+debug("4.0 Wrong Type for Callback Test");
+shouldBeTrue("testPrototypeFunction('sort', '(8)', [12, 15, 10, 13, 44], [10, 12, 13, 15, 44])");
+shouldBeTrue("testPrototypeFunction('sort', '(\"wrong\")', [12, 15, 10, 13, 44], [10, 12, 13, 15, 44])");
+shouldBeTrue("testPrototypeFunction('sort', '(new Object())', [12, 15, 10, 13, 44], [10, 12, 13, 15, 44])");
+shouldBeTrue("testPrototypeFunction('sort', '(null)', [12, 15, 10, 13, 44], [10, 12, 13, 15, 44])");
+debug("");
+finishJSTest();