Diff
Modified: trunk/LayoutTests/ChangeLog (203106 => 203107)
--- trunk/LayoutTests/ChangeLog 2016-07-12 04:47:02 UTC (rev 203106)
+++ trunk/LayoutTests/ChangeLog 2016-07-12 05:06:25 UTC (rev 203107)
@@ -1,3 +1,22 @@
+2016-07-11 Caio Lima <[email protected]>
+
+ ECMAScript 2016: %TypedArray%.prototype.includes implementation
+ https://bugs.webkit.org/show_bug.cgi?id=159385
+
+ Reviewed by Benjamin Poulain.
+
+ This patch implements test case to ECMAScript 2016:
+ %TypedArray%.prototype.includes implementation
+ following spec 22.2.3.14
+ https://tc39.github.io/ecma262/2016/#sec-%typedarray%.prototype.includes
+
+ * js/regress/script-tests/typed-array-includes.js: Added.
+ (assertProperError):
+ (testIntTypedArray):
+ (testFloatTypedArray):
+ * js/typed-array-includes-expected.txt: Added.
+ * js/typed-array-includes.html: Added.
+
2016-07-11 Frederic Wang <[email protected]>
Disable some a failing test.
Added: trunk/LayoutTests/js/script-tests/typed-array-includes.js (0 => 203107)
--- trunk/LayoutTests/js/script-tests/typed-array-includes.js (rev 0)
+++ trunk/LayoutTests/js/script-tests/typed-array-includes.js 2016-07-12 05:06:25 UTC (rev 203107)
@@ -0,0 +1,228 @@
+function assertProperError(e) {
+ if ((!(e instanceof TypeError)) || e.message.indexOf("Receiver should be a typed array view but was not an object") === -1)
+ shouldBeTrue("false");
+}
+
+var tArray;
+
+function testIntTypedArray(TypedArray) {
+
+ tArray = new TypedArray([0,2,3]);
+ shouldBeTrue("tArray.includes(2)");
+ shouldBeTrue("!tArray.includes(4)");
+ shouldBeTrue("!tArray.includes(3, 3)");
+ shouldBeTrue("tArray.includes(3, -1)");
+ shouldBeTrue("tArray.includes(3, {valueOf: () => -1})");
+
+ // Test non-array-native values
+ shouldBeTrue("tArray.includes(2.0)");
+ shouldBeTrue("!tArray.includes(2.5)");
+ shouldBeTrue("!tArray.includes(\"abc\")");
+ shouldBeTrue("!tArray.includes(null)");
+ shouldBeTrue("!tArray.includes(undefined)");
+ shouldBeTrue("!tArray.includes({1: ''})");
+ shouldBeTrue("!tArray.includes(\"\")");
+
+ // Testing TypeError handling
+ try {
+ tArray = new TypedArray([0, 1, 2]);
+ tArray.includes.call(null, 2);
+ } catch(e) {
+ assertProperError(e);
+ }
+
+ try {
+ tArray = new TypedArray([0, 1, 2]);
+ tArray.includes.call(undefined, 2);
+ } catch(e) {
+ assertProperError(e);
+ }
+
+}
+
+testIntTypedArray(Uint8Array);
+testIntTypedArray(Int8Array);
+testIntTypedArray(Uint8ClampedArray);
+testIntTypedArray(Uint16Array);
+testIntTypedArray(Int16Array);
+testIntTypedArray(Uint32Array);
+testIntTypedArray(Int32Array);
+
+var fArray;
+
+function testFloatTypedArray(TypedArray) {
+
+ fArray = new TypedArray([1.0, 2.0 , 3.0]);
+ shouldBeTrue("fArray.includes(2.0)");
+ shouldBeTrue("!fArray.includes(4.0)");
+ shouldBeTrue("!fArray.includes(3.0, 3)");
+ shouldBeTrue("fArray.includes(3, -1)");
+
+ fArray = new TypedArray([NaN]);
+ shouldBeTrue("!fArray.includes(\"abc\")");
+ shouldBeTrue("!fArray.includes(null)");
+ shouldBeTrue("!fArray.includes(undefined)");
+ shouldBeTrue("!fArray.includes({1: ''})");
+ shouldBeTrue("!fArray.includes(\"\")");
+
+ // Testing TypeError handling
+ try {
+ fArray = new TypedArray([0, 1, 2]);
+ fArray.includes.call(null, 2);
+ } catch(e) {
+ assertProperError(e);
+ }
+
+ try {
+ fArray = new TypedArray([0, 1, 2]);
+ fArray.includes.call(undefined, 2);
+ } catch(e) {
+ assertProperError(e);
+ }
+
+}
+
+// NaN handling (only true for Float32 and Float64)
+shouldBeTrue("!(new Uint8Array([NaN]).includes(NaN))");
+shouldBeTrue("new Float32Array([NaN]).includes(NaN)");
+shouldBeTrue("new Float64Array([NaN]).includes(NaN)");
+
+var descriptor;
+var gTypedArray;
+
+function testDescriptor(TypedArray) {
+ gTypedArray = TypedArray;
+ descriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(TypedArray.prototype), "includes");
+
+ shouldBeTrue("descriptor.configurable");
+ shouldBeTrue("descriptor.writable");
+ shouldBeTrue("!descriptor.enumerable");
+ shouldBeTrue("descriptor.get === undefined");
+ shouldBeTrue("descriptor.set === undefined");
+
+ shouldBeTrue("Object.getPrototypeOf(gTypedArray.prototype).includes.name === \"includes\"");
+ shouldBeTrue("Object.getPrototypeOf(gTypedArray.prototype).includes.length === 1");
+}
+
+testDescriptor(Uint8Array);
+testDescriptor(Int8Array);
+testDescriptor(Uint8ClampedArray);
+testDescriptor(Uint16Array);
+testDescriptor(Int16Array);
+testDescriptor(Uint32Array);
+testDescriptor(Int32Array);
+testDescriptor(Float32Array);
+testDescriptor(Float64Array);
+
+// Testing boundaries
+
+var arr = new Uint8Array([0, 254]);
+shouldBeTrue("arr.includes(0)");
+shouldBeTrue("arr.includes(254)");
+shouldBeTrue("!arr.includes(255)");
+shouldBeTrue("!arr.includes(-1)");
+
+arr = new Int8Array([-128, 127]);
+shouldBeTrue("arr.includes(-128)");
+shouldBeTrue("arr.includes(127)");
+shouldBeTrue("!arr.includes(128)");
+shouldBeTrue("!arr.includes(-129)");
+
+arr = new Uint8ClampedArray([-128, 256]);
+shouldBeTrue("arr.includes(255)");
+shouldBeTrue("arr.includes(0)");
+shouldBeTrue("!arr.includes(-128)");
+shouldBeTrue("!arr.includes(-256)");
+
+arr = new Uint16Array([0, 65535]);
+shouldBeTrue("arr.includes(0)");
+shouldBeTrue("arr.includes(65535)");
+shouldBeTrue("!arr.includes(65536)");
+shouldBeTrue("!arr.includes(-1)");
+
+arr = new Int16Array([-32768, 32767]);
+shouldBeTrue("arr.includes(-32768)");
+shouldBeTrue("arr.includes(32767)");
+shouldBeTrue("!arr.includes(32768)");
+shouldBeTrue("!arr.includes(-32769)");
+
+arr = new Uint32Array([0, 4294967295]);
+shouldBeTrue("arr.includes(0)");
+shouldBeTrue("arr.includes(4294967295)");
+shouldBeTrue("!arr.includes(4294967296)");
+shouldBeTrue("!arr.includes(-1)");
+
+arr = new Int32Array([-2147483648, 2147483647]);
+shouldBeTrue("arr.includes(-2147483648)");
+shouldBeTrue("arr.includes(2147483647)");
+shouldBeTrue("!arr.includes(2147483648)");
+shouldBeTrue("!arr.includes(-2147483649)");
+
+arr = new Float32Array([-3.402820018375656e+38, 3.402820018375656e+38]);
+shouldBeTrue("arr.includes(-3.402820018375656e+38)");
+shouldBeTrue("arr.includes(3.402820018375656e+38)");
+shouldBeTrue("!arr.includes(3.50282e+38)");
+shouldBeTrue("!arr.includes(-3.50282e+38)");
+
+arr = new Float64Array([-1.79769e+308, 1.79769e+308]);
+shouldBeTrue("arr.includes(-1.79769e+308)");
+shouldBeTrue("arr.includes(1.79769e+308)");
+shouldBeTrue("!arr.includes(-1.89769e+308)");
+shouldBeTrue("!arr.includes(1.89769e+308)");
+
+// Testing Infinity
+
+function testInfinity(TypedArray) {
+ arr = new TypedArray([Infinity]);
+ shouldBeTrue("arr.includes(Infinity)");
+ shouldBeTrue("!arr.includes(-Infinity)");
+ shouldBeTrue("!arr.includes(NaN)");
+
+ arr = new TypedArray([-Infinity]);
+ shouldBeTrue("arr.includes(-Infinity)");
+ shouldBeTrue("!arr.includes(Infinity)");
+ shouldBeTrue("!arr.includes(NaN)");
+}
+
+testInfinity(Float32Array);
+testInfinity(Float64Array);
+
+// Test float->double precision
+
+shouldBeTrue("!(new Float32Array([2.40282e+38]).includes(2.40282e+38))");
+
+// Checking spec
+var funcCallCount;
+
+function checkingValueOfCall(TypedArray) {
+ tArray = new TypedArray([0, 1, 2]);
+ funcCallCount = {callCount: 0, valueOf: function() {this.callCount++; return 0;}};
+
+ tArray.includes(0, funcCallCount);
+ shouldBeTrue("funcCallCount.callCount === 1");
+
+ tArray.includes("abc", funcCallCount);
+ shouldBeTrue("funcCallCount.callCount === 2");
+
+ tArray.includes(null, funcCallCount);
+ shouldBeTrue("funcCallCount.callCount === 3");
+
+ tArray.includes(undefined, funcCallCount);
+ shouldBeTrue("funcCallCount.callCount === 4");
+
+ tArray.includes({1: ''}, funcCallCount);
+ shouldBeTrue("funcCallCount.callCount === 5");
+
+ tArray.includes("", funcCallCount);
+ shouldBeTrue("funcCallCount.callCount === 6");
+}
+
+checkingValueOfCall(Uint8Array);
+checkingValueOfCall(Int8Array);
+checkingValueOfCall(Uint8ClampedArray);
+checkingValueOfCall(Uint16Array);
+checkingValueOfCall(Int16Array);
+checkingValueOfCall(Uint32Array);
+checkingValueOfCall(Int32Array);
+checkingValueOfCall(Float32Array);
+checkingValueOfCall(Float64Array);
Added: trunk/LayoutTests/js/typed-array-includes-expected.txt (0 => 203107)
--- trunk/LayoutTests/js/typed-array-includes-expected.txt (rev 0)
+++ trunk/LayoutTests/js/typed-array-includes-expected.txt 2016-07-12 05:06:25 UTC (rev 203107)
@@ -0,0 +1,257 @@
+PASS tArray.includes(2) is true
+PASS !tArray.includes(4) is true
+PASS !tArray.includes(3, 3) is true
+PASS tArray.includes(3, -1) is true
+PASS tArray.includes(3, {valueOf: () => -1}) is true
+PASS tArray.includes(2.0) is true
+PASS !tArray.includes(2.5) is true
+PASS !tArray.includes("abc") is true
+PASS !tArray.includes(null) is true
+PASS !tArray.includes(undefined) is true
+PASS !tArray.includes({1: ''}) is true
+PASS !tArray.includes("") is true
+PASS tArray.includes(2) is true
+PASS !tArray.includes(4) is true
+PASS !tArray.includes(3, 3) is true
+PASS tArray.includes(3, -1) is true
+PASS tArray.includes(3, {valueOf: () => -1}) is true
+PASS tArray.includes(2.0) is true
+PASS !tArray.includes(2.5) is true
+PASS !tArray.includes("abc") is true
+PASS !tArray.includes(null) is true
+PASS !tArray.includes(undefined) is true
+PASS !tArray.includes({1: ''}) is true
+PASS !tArray.includes("") is true
+PASS tArray.includes(2) is true
+PASS !tArray.includes(4) is true
+PASS !tArray.includes(3, 3) is true
+PASS tArray.includes(3, -1) is true
+PASS tArray.includes(3, {valueOf: () => -1}) is true
+PASS tArray.includes(2.0) is true
+PASS !tArray.includes(2.5) is true
+PASS !tArray.includes("abc") is true
+PASS !tArray.includes(null) is true
+PASS !tArray.includes(undefined) is true
+PASS !tArray.includes({1: ''}) is true
+PASS !tArray.includes("") is true
+PASS tArray.includes(2) is true
+PASS !tArray.includes(4) is true
+PASS !tArray.includes(3, 3) is true
+PASS tArray.includes(3, -1) is true
+PASS tArray.includes(3, {valueOf: () => -1}) is true
+PASS tArray.includes(2.0) is true
+PASS !tArray.includes(2.5) is true
+PASS !tArray.includes("abc") is true
+PASS !tArray.includes(null) is true
+PASS !tArray.includes(undefined) is true
+PASS !tArray.includes({1: ''}) is true
+PASS !tArray.includes("") is true
+PASS tArray.includes(2) is true
+PASS !tArray.includes(4) is true
+PASS !tArray.includes(3, 3) is true
+PASS tArray.includes(3, -1) is true
+PASS tArray.includes(3, {valueOf: () => -1}) is true
+PASS tArray.includes(2.0) is true
+PASS !tArray.includes(2.5) is true
+PASS !tArray.includes("abc") is true
+PASS !tArray.includes(null) is true
+PASS !tArray.includes(undefined) is true
+PASS !tArray.includes({1: ''}) is true
+PASS !tArray.includes("") is true
+PASS tArray.includes(2) is true
+PASS !tArray.includes(4) is true
+PASS !tArray.includes(3, 3) is true
+PASS tArray.includes(3, -1) is true
+PASS tArray.includes(3, {valueOf: () => -1}) is true
+PASS tArray.includes(2.0) is true
+PASS !tArray.includes(2.5) is true
+PASS !tArray.includes("abc") is true
+PASS !tArray.includes(null) is true
+PASS !tArray.includes(undefined) is true
+PASS !tArray.includes({1: ''}) is true
+PASS !tArray.includes("") is true
+PASS tArray.includes(2) is true
+PASS !tArray.includes(4) is true
+PASS !tArray.includes(3, 3) is true
+PASS tArray.includes(3, -1) is true
+PASS tArray.includes(3, {valueOf: () => -1}) is true
+PASS tArray.includes(2.0) is true
+PASS !tArray.includes(2.5) is true
+PASS !tArray.includes("abc") is true
+PASS !tArray.includes(null) is true
+PASS !tArray.includes(undefined) is true
+PASS !tArray.includes({1: ''}) is true
+PASS !tArray.includes("") is true
+PASS !(new Uint8Array([NaN]).includes(NaN)) is true
+PASS new Float32Array([NaN]).includes(NaN) is true
+PASS new Float64Array([NaN]).includes(NaN) is true
+PASS descriptor.configurable is true
+PASS descriptor.writable is true
+PASS !descriptor.enumerable is true
+PASS descriptor.get === undefined is true
+PASS descriptor.set === undefined is true
+PASS Object.getPrototypeOf(gTypedArray.prototype).includes.name === "includes" is true
+PASS Object.getPrototypeOf(gTypedArray.prototype).includes.length === 1 is true
+PASS descriptor.configurable is true
+PASS descriptor.writable is true
+PASS !descriptor.enumerable is true
+PASS descriptor.get === undefined is true
+PASS descriptor.set === undefined is true
+PASS Object.getPrototypeOf(gTypedArray.prototype).includes.name === "includes" is true
+PASS Object.getPrototypeOf(gTypedArray.prototype).includes.length === 1 is true
+PASS descriptor.configurable is true
+PASS descriptor.writable is true
+PASS !descriptor.enumerable is true
+PASS descriptor.get === undefined is true
+PASS descriptor.set === undefined is true
+PASS Object.getPrototypeOf(gTypedArray.prototype).includes.name === "includes" is true
+PASS Object.getPrototypeOf(gTypedArray.prototype).includes.length === 1 is true
+PASS descriptor.configurable is true
+PASS descriptor.writable is true
+PASS !descriptor.enumerable is true
+PASS descriptor.get === undefined is true
+PASS descriptor.set === undefined is true
+PASS Object.getPrototypeOf(gTypedArray.prototype).includes.name === "includes" is true
+PASS Object.getPrototypeOf(gTypedArray.prototype).includes.length === 1 is true
+PASS descriptor.configurable is true
+PASS descriptor.writable is true
+PASS !descriptor.enumerable is true
+PASS descriptor.get === undefined is true
+PASS descriptor.set === undefined is true
+PASS Object.getPrototypeOf(gTypedArray.prototype).includes.name === "includes" is true
+PASS Object.getPrototypeOf(gTypedArray.prototype).includes.length === 1 is true
+PASS descriptor.configurable is true
+PASS descriptor.writable is true
+PASS !descriptor.enumerable is true
+PASS descriptor.get === undefined is true
+PASS descriptor.set === undefined is true
+PASS Object.getPrototypeOf(gTypedArray.prototype).includes.name === "includes" is true
+PASS Object.getPrototypeOf(gTypedArray.prototype).includes.length === 1 is true
+PASS descriptor.configurable is true
+PASS descriptor.writable is true
+PASS !descriptor.enumerable is true
+PASS descriptor.get === undefined is true
+PASS descriptor.set === undefined is true
+PASS Object.getPrototypeOf(gTypedArray.prototype).includes.name === "includes" is true
+PASS Object.getPrototypeOf(gTypedArray.prototype).includes.length === 1 is true
+PASS descriptor.configurable is true
+PASS descriptor.writable is true
+PASS !descriptor.enumerable is true
+PASS descriptor.get === undefined is true
+PASS descriptor.set === undefined is true
+PASS Object.getPrototypeOf(gTypedArray.prototype).includes.name === "includes" is true
+PASS Object.getPrototypeOf(gTypedArray.prototype).includes.length === 1 is true
+PASS descriptor.configurable is true
+PASS descriptor.writable is true
+PASS !descriptor.enumerable is true
+PASS descriptor.get === undefined is true
+PASS descriptor.set === undefined is true
+PASS Object.getPrototypeOf(gTypedArray.prototype).includes.name === "includes" is true
+PASS Object.getPrototypeOf(gTypedArray.prototype).includes.length === 1 is true
+PASS arr.includes(0) is true
+PASS arr.includes(254) is true
+PASS !arr.includes(255) is true
+PASS !arr.includes(-1) is true
+PASS arr.includes(-128) is true
+PASS arr.includes(127) is true
+PASS !arr.includes(128) is true
+PASS !arr.includes(-129) is true
+PASS arr.includes(255) is true
+PASS arr.includes(0) is true
+PASS !arr.includes(-128) is true
+PASS !arr.includes(-256) is true
+PASS arr.includes(0) is true
+PASS arr.includes(65535) is true
+PASS !arr.includes(65536) is true
+PASS !arr.includes(-1) is true
+PASS arr.includes(-32768) is true
+PASS arr.includes(32767) is true
+PASS !arr.includes(32768) is true
+PASS !arr.includes(-32769) is true
+PASS arr.includes(0) is true
+PASS arr.includes(4294967295) is true
+PASS !arr.includes(4294967296) is true
+PASS !arr.includes(-1) is true
+PASS arr.includes(-2147483648) is true
+PASS arr.includes(2147483647) is true
+PASS !arr.includes(2147483648) is true
+PASS !arr.includes(-2147483649) is true
+PASS arr.includes(-3.402820018375656e+38) is true
+PASS arr.includes(3.402820018375656e+38) is true
+PASS !arr.includes(3.50282e+38) is true
+PASS !arr.includes(-3.50282e+38) is true
+PASS arr.includes(-1.79769e+308) is true
+PASS arr.includes(1.79769e+308) is true
+PASS !arr.includes(-1.89769e+308) is true
+PASS !arr.includes(1.89769e+308) is true
+PASS arr.includes(Infinity) is true
+PASS !arr.includes(-Infinity) is true
+PASS !arr.includes(NaN) is true
+PASS arr.includes(-Infinity) is true
+PASS !arr.includes(Infinity) is true
+PASS !arr.includes(NaN) is true
+PASS arr.includes(Infinity) is true
+PASS !arr.includes(-Infinity) is true
+PASS !arr.includes(NaN) is true
+PASS arr.includes(-Infinity) is true
+PASS !arr.includes(Infinity) is true
+PASS !arr.includes(NaN) is true
+PASS !(new Float32Array([2.40282e+38]).includes(2.40282e+38)) is true
+PASS funcCallCount.callCount === 1 is true
+PASS funcCallCount.callCount === 2 is true
+PASS funcCallCount.callCount === 3 is true
+PASS funcCallCount.callCount === 4 is true
+PASS funcCallCount.callCount === 5 is true
+PASS funcCallCount.callCount === 6 is true
+PASS funcCallCount.callCount === 1 is true
+PASS funcCallCount.callCount === 2 is true
+PASS funcCallCount.callCount === 3 is true
+PASS funcCallCount.callCount === 4 is true
+PASS funcCallCount.callCount === 5 is true
+PASS funcCallCount.callCount === 6 is true
+PASS funcCallCount.callCount === 1 is true
+PASS funcCallCount.callCount === 2 is true
+PASS funcCallCount.callCount === 3 is true
+PASS funcCallCount.callCount === 4 is true
+PASS funcCallCount.callCount === 5 is true
+PASS funcCallCount.callCount === 6 is true
+PASS funcCallCount.callCount === 1 is true
+PASS funcCallCount.callCount === 2 is true
+PASS funcCallCount.callCount === 3 is true
+PASS funcCallCount.callCount === 4 is true
+PASS funcCallCount.callCount === 5 is true
+PASS funcCallCount.callCount === 6 is true
+PASS funcCallCount.callCount === 1 is true
+PASS funcCallCount.callCount === 2 is true
+PASS funcCallCount.callCount === 3 is true
+PASS funcCallCount.callCount === 4 is true
+PASS funcCallCount.callCount === 5 is true
+PASS funcCallCount.callCount === 6 is true
+PASS funcCallCount.callCount === 1 is true
+PASS funcCallCount.callCount === 2 is true
+PASS funcCallCount.callCount === 3 is true
+PASS funcCallCount.callCount === 4 is true
+PASS funcCallCount.callCount === 5 is true
+PASS funcCallCount.callCount === 6 is true
+PASS funcCallCount.callCount === 1 is true
+PASS funcCallCount.callCount === 2 is true
+PASS funcCallCount.callCount === 3 is true
+PASS funcCallCount.callCount === 4 is true
+PASS funcCallCount.callCount === 5 is true
+PASS funcCallCount.callCount === 6 is true
+PASS funcCallCount.callCount === 1 is true
+PASS funcCallCount.callCount === 2 is true
+PASS funcCallCount.callCount === 3 is true
+PASS funcCallCount.callCount === 4 is true
+PASS funcCallCount.callCount === 5 is true
+PASS funcCallCount.callCount === 6 is true
+PASS funcCallCount.callCount === 1 is true
+PASS funcCallCount.callCount === 2 is true
+PASS funcCallCount.callCount === 3 is true
+PASS funcCallCount.callCount === 4 is true
+PASS funcCallCount.callCount === 5 is true
+PASS funcCallCount.callCount === 6 is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/js/typed-array-includes.html (0 => 203107)
--- trunk/LayoutTests/js/typed-array-includes.html (rev 0)
+++ trunk/LayoutTests/js/typed-array-includes.html 2016-07-12 05:06:25 UTC (rev 203107)
@@ -0,0 +1,11 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+ <head>
+ <script src=""
+ </head>
+ <body>
+ <script src=""
+ <script src=""
+ </body>
+</html>
+
Modified: trunk/Source/_javascript_Core/ChangeLog (203106 => 203107)
--- trunk/Source/_javascript_Core/ChangeLog 2016-07-12 04:47:02 UTC (rev 203106)
+++ trunk/Source/_javascript_Core/ChangeLog 2016-07-12 05:06:25 UTC (rev 203107)
@@ -1,3 +1,21 @@
+2016-07-11 Caio Lima <[email protected]>
+
+ ECMAScript 2016: %TypedArray%.prototype.includes implementation
+ https://bugs.webkit.org/show_bug.cgi?id=159385
+
+ Reviewed by Benjamin Poulain.
+
+ This patch implements the ECMAScript 2016:
+ %TypedArray%.prototype.includes
+ following spec 22.2.3.14
+ https://tc39.github.io/ecma262/2016/#sec-%typedarray%.prototype.includes
+
+ * runtime/JSGenericTypedArrayViewPrototypeFunctions.h:
+ (JSC::genericTypedArrayViewProtoFuncIncludes):
+ * runtime/JSTypedArrayViewPrototype.cpp:
+ (JSC::typedArrayViewProtoFuncIncludes):
+ (JSC::JSTypedArrayViewPrototype::finishCreation):
+
2016-07-11 Benjamin Poulain <[email protected]>
[JSC] Array.from() and Array.of() try to build objects even if "this" is not a constructor
Modified: trunk/Source/_javascript_Core/runtime/JSGenericTypedArrayView.h (203106 => 203107)
--- trunk/Source/_javascript_Core/runtime/JSGenericTypedArrayView.h 2016-07-12 04:47:02 UTC (rev 203106)
+++ trunk/Source/_javascript_Core/runtime/JSGenericTypedArrayView.h 2016-07-12 05:06:25 UTC (rev 203107)
@@ -178,6 +178,8 @@
static ElementType toAdaptorNativeFromValue(ExecState* exec, JSValue jsValue) { return toNativeFromValue<Adaptor>(exec, jsValue); }
+ static bool toAdaptorNativeFromValue(ExecState* exec, JSValue jsValue, ElementType& result) { return toNativeFromValue<Adaptor>(exec, jsValue, result); }
+
bool setRangeToValue(ExecState* exec, unsigned start, unsigned end, JSValue jsValue)
{
ASSERT(0 <= start && start <= end && end <= m_length);
Modified: trunk/Source/_javascript_Core/runtime/JSGenericTypedArrayViewPrototypeFunctions.h (203106 => 203107)
--- trunk/Source/_javascript_Core/runtime/JSGenericTypedArrayViewPrototypeFunctions.h 2016-07-12 04:47:02 UTC (rev 203106)
+++ trunk/Source/_javascript_Core/runtime/JSGenericTypedArrayViewPrototypeFunctions.h 2016-07-12 05:06:25 UTC (rev 203107)
@@ -202,6 +202,48 @@
}
template<typename ViewClass>
+EncodedJSValue JSC_HOST_CALL genericTypedArrayViewProtoFuncIncludes(ExecState* exec)
+{
+ ViewClass* thisObject = jsCast<ViewClass*>(exec->thisValue());
+ if (thisObject->isNeutered())
+ return throwVMTypeError(exec, typedArrayBufferHasBeenDetachedErrorMessage);
+
+ unsigned length = thisObject->length();
+
+ if (!length)
+ return JSValue::encode(jsBoolean(false));
+
+ JSValue valueToFind = exec->argument(0);
+
+ unsigned index = argumentClampedIndexFromStartOrEnd(exec, 1, length);
+
+ if (!valueToFind.isNumber())
+ return JSValue::encode(jsBoolean(false));
+
+ typename ViewClass::ElementType* array = thisObject->typedVector();
+ typename ViewClass::ElementType target;
+ if (!ViewClass::toAdaptorNativeFromValue(exec, valueToFind, target))
+ return JSValue::encode(jsBoolean(false));
+
+ if (exec->hadException())
+ return JSValue::encode(jsUndefined());
+
+ if (std::isnan(static_cast<double>(target))) {
+ for (; index < length; ++index) {
+ if (std::isnan(static_cast<double>(array[index])))
+ return JSValue::encode(jsBoolean(true));
+ }
+ } else {
+ for (; index < length; ++index) {
+ if (array[index] == target)
+ return JSValue::encode(jsBoolean(true));
+ }
+ }
+
+ return JSValue::encode(jsBoolean(false));
+}
+
+template<typename ViewClass>
EncodedJSValue JSC_HOST_CALL genericTypedArrayViewProtoFuncIndexOf(ExecState* exec)
{
// 22.2.3.13
Modified: trunk/Source/_javascript_Core/runtime/JSTypedArrayViewPrototype.cpp (203106 => 203107)
--- trunk/Source/_javascript_Core/runtime/JSTypedArrayViewPrototype.cpp 2016-07-12 04:47:02 UTC (rev 203106)
+++ trunk/Source/_javascript_Core/runtime/JSTypedArrayViewPrototype.cpp 2016-07-12 05:06:25 UTC (rev 203107)
@@ -122,6 +122,14 @@
CALL_GENERIC_TYPEDARRAY_PROTOTYPE_FUNCTION(genericTypedArrayViewProtoFuncFill);
}
+static EncodedJSValue JSC_HOST_CALL typedArrayViewProtoFuncIncludes(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(genericTypedArrayViewProtoFuncIncludes);
+}
+
static EncodedJSValue JSC_HOST_CALL typedArrayViewProtoFuncLastIndexOf(ExecState* exec)
{
JSValue thisValue = exec->thisValue();
@@ -260,6 +268,7 @@
JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION("sort", typedArrayPrototypeSortCodeGenerator, DontEnum);
JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->builtinNames().entriesPublicName(), typedArrayPrototypeEntriesCodeGenerator, DontEnum);
JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("fill", typedArrayViewProtoFuncFill, DontEnum, 1);
+ JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("includes", typedArrayViewProtoFuncIncludes, DontEnum, 1);
JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION("find", typedArrayPrototypeFindCodeGenerator, DontEnum);
JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION("findIndex", typedArrayPrototypeFindIndexCodeGenerator, DontEnum);
JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->forEach, typedArrayPrototypeForEachCodeGenerator, DontEnum);
Modified: trunk/Source/_javascript_Core/runtime/ToNativeFromValue.h (203106 => 203107)
--- trunk/Source/_javascript_Core/runtime/ToNativeFromValue.h 2016-07-12 04:47:02 UTC (rev 203106)
+++ trunk/Source/_javascript_Core/runtime/ToNativeFromValue.h 2016-07-12 05:06:25 UTC (rev 203107)
@@ -48,6 +48,16 @@
return Adaptor::toNativeFromDouble(value.toNumber(exec));
}
+template<typename Adaptor>
+bool toNativeFromValue(ExecState* exec, JSValue value, typename Adaptor::Type& result)
+{
+ if (value.isInt32())
+ return Adaptor::toNativeFromInt32(value.asInt32(), result);
+ if (value.isNumber())
+ return Adaptor::toNativeFromDouble(value.asDouble(), result);
+ return Adaptor::toNativeFromDouble(value.toNumber(exec), result);
+}
+
} // namespace JSC
#endif // ToNativeFromValue_h
Modified: trunk/Source/_javascript_Core/runtime/TypedArrayAdaptors.h (203106 => 203107)
--- trunk/Source/_javascript_Core/runtime/TypedArrayAdaptors.h 2016-07-12 04:47:02 UTC (rev 203106)
+++ trunk/Source/_javascript_Core/runtime/TypedArrayAdaptors.h 2016-07-12 05:06:25 UTC (rev 203107)
@@ -40,6 +40,8 @@
typedef ViewTypeArg ViewType;
typedef JSViewTypeArg JSViewType;
static const TypedArrayType typeValue = typeValueArg;
+ constexpr static const TypeArg minValue = std::numeric_limits<TypeArg>::lowest();
+ constexpr static const TypeArg maxValue = std::numeric_limits<TypeArg>::max();
static JSValue toJSValue(Type value)
{
@@ -76,6 +78,38 @@
return OtherAdaptor::toNativeFromUint32(value);
return OtherAdaptor::toNativeFromInt32(value);
}
+
+ static bool toNativeFromInt32(int32_t value, Type& result)
+ {
+ if ((value >= 0 && static_cast<uint32_t>(value) > static_cast<uint32_t>(maxValue)) || value < static_cast<int32_t>(minValue))
+ return false;
+
+ result = static_cast<Type>(value);
+
+ return true;
+ }
+
+ static bool toNativeFromUint32(uint32_t value, Type& result)
+ {
+ if (value > static_cast<uint32_t>(maxValue))
+ return false;
+
+ result = static_cast<Type>(value);
+
+ return true;
+ }
+
+ static bool toNativeFromDouble(double value, Type& result)
+ {
+ Type integer = static_cast<Type>(value);
+ if (static_cast<double>(integer) != value)
+ return false;
+
+ if (value < 0)
+ return toNativeFromInt32(static_cast<int32_t>(value), result);
+
+ return toNativeFromUint32(static_cast<uint32_t>(value), result);
+ }
};
template<
@@ -86,12 +120,14 @@
typedef ViewTypeArg ViewType;
typedef JSViewTypeArg JSViewType;
static const TypedArrayType typeValue = typeValueArg;
-
+ constexpr static const TypeArg minValue = std::numeric_limits<TypeArg>::lowest();
+ constexpr static const TypeArg maxValue = std::numeric_limits<TypeArg>::max();
+
static JSValue toJSValue(Type value)
{
return jsDoubleNumber(purifyNaN(value));
}
-
+
static double toDouble(Type value)
{
return static_cast<double>(value);
@@ -101,22 +137,47 @@
{
return static_cast<Type>(value);
}
-
+
static Type toNativeFromUint32(uint32_t value)
{
return static_cast<Type>(value);
}
-
+
static Type toNativeFromDouble(double value)
{
- return value;
+ return static_cast<Type>(value);
}
-
+
template<typename OtherAdaptor>
static typename OtherAdaptor::Type convertTo(Type value)
{
return OtherAdaptor::toNativeFromDouble(value);
}
+
+ static bool toNativeFromInt32(int32_t value, Type& result)
+ {
+ result = static_cast<Type>(value);
+ return true;
+ }
+
+ static Type toNativeFromDouble(double value, Type& result)
+ {
+ if (std::isnan(value) || std::isinf(value)) {
+ result = static_cast<Type>(value);
+ return true;
+ }
+
+ Type valueResult = static_cast<Type>(value);
+
+ if (static_cast<double>(valueResult) != value)
+ return false;
+
+ if (value < minValue || value > maxValue)
+ return false;
+
+ result = valueResult;
+ return true;
+ }
};
struct Int8Adaptor;
@@ -165,27 +226,29 @@
typedef Uint8ClampedArray ViewType;
typedef JSUint8ClampedArray JSViewType;
static const TypedArrayType typeValue = TypeUint8Clamped;
-
+ constexpr static const uint8_t minValue = std::numeric_limits<uint8_t>::lowest();
+ constexpr static const uint8_t maxValue = std::numeric_limits<uint8_t>::max();
+
static JSValue toJSValue(uint8_t value)
{
return jsNumber(value);
}
-
+
static double toDouble(uint8_t value)
{
return static_cast<double>(value);
}
-
+
static Type toNativeFromInt32(int32_t value)
{
return clamp(value);
}
-
+
static Type toNativeFromUint32(uint32_t value)
{
return std::min(static_cast<uint32_t>(255), value);
}
-
+
static Type toNativeFromDouble(double value)
{
if (std::isnan(value) || value < 0)
@@ -194,7 +257,7 @@
return 255;
return static_cast<uint8_t>(lrint(value));
}
-
+
template<typename OtherAdaptor>
static typename OtherAdaptor::Type convertTo(uint8_t value)
{
@@ -201,6 +264,26 @@
return OtherAdaptor::toNativeFromInt32(value);
}
+ static bool toNativeFromInt32(int32_t value, Type& result)
+ {
+ if (value > maxValue || value < minValue)
+ return false;
+
+ result = static_cast<Type>(value);
+
+ return true;
+ }
+
+ static bool toNativeFromDouble(double value, uint8_t& result)
+ {
+ uint8_t integer = static_cast<uint8_t>(value);
+ if (static_cast<double>(integer) != value)
+ return false;
+
+ result = integer;
+ return true;
+ }
+
private:
static uint8_t clamp(int32_t value)
{