Title: [246851] trunk
Revision
246851
Author
[email protected]
Date
2019-06-26 16:07:28 -0700 (Wed, 26 Jun 2019)

Log Message

speciesConstruct needs to throw if the result is a DataView
https://bugs.webkit.org/show_bug.cgi?id=199231

Reviewed by Mark Lam.

JSTests:

* stress/typedarray-filter.js:
(subclasses.forEach):
* stress/typedarray-map.js:
(subclasses.forEach):
* stress/typedarray-slice.js:
(typedArrays.forEach):
* stress/typedarray-subarray.js:
(subclasses.forEach):

Source/_javascript_Core:

Previously, we only checked that the result was a
JSArrayBufferView, which can include DataViews. This is incorrect
as the result should be only be a TypedArray.

* runtime/JSGenericTypedArrayViewPrototypeFunctions.h:
(JSC::speciesConstruct):

Modified Paths

Diff

Modified: trunk/JSTests/ChangeLog (246850 => 246851)


--- trunk/JSTests/ChangeLog	2019-06-26 22:25:48 UTC (rev 246850)
+++ trunk/JSTests/ChangeLog	2019-06-26 23:07:28 UTC (rev 246851)
@@ -1,3 +1,19 @@
+2019-06-26  Keith Miller  <[email protected]>
+
+        speciesConstruct needs to throw if the result is a DataView
+        https://bugs.webkit.org/show_bug.cgi?id=199231
+
+        Reviewed by Mark Lam.
+
+        * stress/typedarray-filter.js:
+        (subclasses.forEach):
+        * stress/typedarray-map.js:
+        (subclasses.forEach):
+        * stress/typedarray-slice.js:
+        (typedArrays.forEach):
+        * stress/typedarray-subarray.js:
+        (subclasses.forEach):
+
 2019-06-24  Commit Queue  <[email protected]>
 
         Unreviewed, rolling out r246714.

Modified: trunk/JSTests/stress/typedarray-filter.js (246850 => 246851)


--- trunk/JSTests/stress/typedarray-filter.js	2019-06-26 22:25:48 UTC (rev 246850)
+++ trunk/JSTests/stress/typedarray-filter.js	2019-06-26 23:07:28 UTC (rev 246851)
@@ -91,6 +91,17 @@
 subclasses.forEach(function(constructor) { constructor[Symbol.species] = undefined; });
 shouldBeTrue("forEachTypedArray(subclasses, testSpeciesIsDefault)");
 
+subclasses.forEach(function(constructor) { constructor[Symbol.species] = () => new DataView(new ArrayBuffer()); });
+function testSpeciesReturnsDataView(array, constructor) {
+    try {
+        array.filter(accept);
+    } catch (e) {
+        return e instanceof TypeError;
+    }
+    return false;
+}
+shouldBeTrue("forEachTypedArray(subclasses, testSpeciesReturnsDataView)");
+
 subclasses = typedArrays.map(function(constructor) { return class extends constructor { } } );
 function testSpeciesRemoveConstructor(array, constructor) {
     array.constructor = undefined;
@@ -100,4 +111,5 @@
 }
 
 shouldBeTrue("forEachTypedArray(subclasses, testSpeciesRemoveConstructor)");
+
 finishJSTest();

Modified: trunk/JSTests/stress/typedarray-map.js (246850 => 246851)


--- trunk/JSTests/stress/typedarray-map.js	2019-06-26 22:25:48 UTC (rev 246850)
+++ trunk/JSTests/stress/typedarray-map.js	2019-06-26 23:07:28 UTC (rev 246851)
@@ -90,6 +90,17 @@
 subclasses.forEach(function(constructor) { constructor[Symbol.species] = undefined; });
 shouldBeTrue("forEachTypedArray(subclasses, testSpeciesIsDefault)");
 
+subclasses.forEach(function(constructor) { constructor[Symbol.species] = () => new DataView(new ArrayBuffer()); });
+function testSpeciesReturnsDataView(array, constructor) {
+    try {
+        array.map(id);
+    } catch (e) {
+        return e instanceof TypeError;
+    }
+    return false;
+}
+shouldBeTrue("forEachTypedArray(subclasses, testSpeciesReturnsDataView)");
+
 subclasses = typedArrays.map(function(constructor) { return class extends constructor { } } );
 function testSpeciesRemoveConstructor(array, constructor) {
     array.constructor = undefined;

Modified: trunk/JSTests/stress/typedarray-slice.js (246850 => 246851)


--- trunk/JSTests/stress/typedarray-slice.js	2019-06-26 22:25:48 UTC (rev 246850)
+++ trunk/JSTests/stress/typedarray-slice.js	2019-06-26 23:07:28 UTC (rev 246851)
@@ -169,4 +169,15 @@
 
 shouldBeTrue("forEachTypedArray(typedArrays, testSpeciesWithTransferring)");
 
+typedArrays.forEach(function(constructor) { constructor[Symbol.species] = () => new DataView(new ArrayBuffer()); });
+function testSpeciesReturnsDataView(array, constructor) {
+    try {
+        array.slice(0, 1);
+    } catch (e) {
+        return e instanceof TypeError;
+    }
+    return false;
+}
+shouldBeTrue("forEachTypedArray(typedArrays, testSpeciesReturnsDataView)");
+
 finishJSTest();

Modified: trunk/JSTests/stress/typedarray-subarray.js (246850 => 246851)


--- trunk/JSTests/stress/typedarray-subarray.js	2019-06-26 22:25:48 UTC (rev 246850)
+++ trunk/JSTests/stress/typedarray-subarray.js	2019-06-26 23:07:28 UTC (rev 246851)
@@ -48,6 +48,17 @@
 subclasses.forEach(function(constructor) { constructor[Symbol.species] = undefined; });
 shouldBeTrue("forEachTypedArray(subclasses, testSpeciesIsDefault)");
 
+subclasses.forEach(function(constructor) { constructor[Symbol.species] = () => new DataView(new ArrayBuffer()); });
+function testSpeciesReturnsDataView(array, constructor) {
+    try {
+        array.subarray(0, 0);
+    } catch (e) {
+        return e instanceof TypeError;
+    }
+    return false;
+}
+shouldBeTrue("forEachTypedArray(subclasses, testSpeciesReturnsDataView)");
+
 subclasses = typedArrays.map(function(constructor) { return class extends constructor { } } );
 function testSpeciesRemoveConstructor(array, constructor) {
     array.constructor = undefined;

Modified: trunk/Source/_javascript_Core/ChangeLog (246850 => 246851)


--- trunk/Source/_javascript_Core/ChangeLog	2019-06-26 22:25:48 UTC (rev 246850)
+++ trunk/Source/_javascript_Core/ChangeLog	2019-06-26 23:07:28 UTC (rev 246851)
@@ -1,3 +1,17 @@
+2019-06-26  Keith Miller  <[email protected]>
+
+        speciesConstruct needs to throw if the result is a DataView
+        https://bugs.webkit.org/show_bug.cgi?id=199231
+
+        Reviewed by Mark Lam.
+
+        Previously, we only checked that the result was a
+        JSArrayBufferView, which can include DataViews. This is incorrect
+        as the result should be only be a TypedArray.
+
+        * runtime/JSGenericTypedArrayViewPrototypeFunctions.h:
+        (JSC::speciesConstruct):
+
 2019-06-26  Joseph Pecoraro  <[email protected]>
 
         Web Inspector: Implement console.countReset

Modified: trunk/Source/_javascript_Core/runtime/JSGenericTypedArrayViewPrototypeFunctions.h (246850 => 246851)


--- trunk/Source/_javascript_Core/runtime/JSGenericTypedArrayViewPrototypeFunctions.h	2019-06-26 22:25:48 UTC (rev 246850)
+++ trunk/Source/_javascript_Core/runtime/JSGenericTypedArrayViewPrototypeFunctions.h	2019-06-26 23:07:28 UTC (rev 246851)
@@ -70,6 +70,11 @@
     RETURN_IF_EXCEPTION(scope, nullptr);
 
     if (JSArrayBufferView* view = jsDynamicCast<JSArrayBufferView*>(vm, result)) {
+        if (view->type() == DataViewType) {
+            throwTypeError(exec, scope, "species constructor did not return a TypedArray View"_s);
+            return nullptr;
+        }
+
         if (!view->isNeutered())
             return view;
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to