Title: [269832] trunk
Revision
269832
Author
[email protected]
Date
2020-11-15 11:58:07 -0800 (Sun, 15 Nov 2020)

Log Message

[JSC] Wasm should get byte length from source typed array
https://bugs.webkit.org/show_bug.cgi?id=218955

Reviewed by Sam Weinig.

LayoutTests/imported/w3c:

* web-platform-tests/wasm/jsapi/constructor/validate.any-expected.txt:
* web-platform-tests/wasm/jsapi/constructor/validate.any.worker-expected.txt:

Source/_javascript_Core:

WebAssembly's module source should be read with byteLength instead of length of typed-array.

* runtime/JSArrayBufferView.cpp:
(JSC::JSArrayBufferView::byteLength const):
(JSC::JSArrayBufferView::slowDownAndWasteMemory):
* runtime/JSArrayBufferView.h:
* wasm/js/JSWebAssemblyHelpers.h:
(JSC::getWasmBufferFromValue):

Modified Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (269831 => 269832)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2020-11-15 18:55:42 UTC (rev 269831)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2020-11-15 19:58:07 UTC (rev 269832)
@@ -1,3 +1,13 @@
+2020-11-15  Yusuke Suzuki  <[email protected]>
+
+        [JSC] Wasm should get byte length from source typed array
+        https://bugs.webkit.org/show_bug.cgi?id=218955
+
+        Reviewed by Sam Weinig.
+
+        * web-platform-tests/wasm/jsapi/constructor/validate.any-expected.txt:
+        * web-platform-tests/wasm/jsapi/constructor/validate.any.worker-expected.txt:
+
 2020-11-14  Rob Buis  <[email protected]>
 
         Remove -webkit-aspect-ratio support

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/constructor/validate.any-expected.txt (269831 => 269832)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/constructor/validate.any-expected.txt	2020-11-15 18:55:42 UTC (rev 269831)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/constructor/validate.any-expected.txt	2020-11-15 19:58:07 UTC (rev 269832)
@@ -32,10 +32,10 @@
 PASS Validating module [0 61 73 6d 1 0 0] in Int8Array
 PASS Validating module [0 61 73 6d 1 0 0 0] in Uint8Array
 PASS Validating module [0 61 73 6d 1 0 0 0] in Int8Array
-FAIL Validating module [0 61 73 6d 1 0 0 0] in Uint16Array assert_equals: expected true but got false
-FAIL Validating module [0 61 73 6d 1 0 0 0] in Int16Array assert_equals: expected true but got false
-FAIL Validating module [0 61 73 6d 1 0 0 0] in Uint32Array assert_equals: expected true but got false
-FAIL Validating module [0 61 73 6d 1 0 0 0] in Int32Array assert_equals: expected true but got false
+PASS Validating module [0 61 73 6d 1 0 0 0] in Uint16Array
+PASS Validating module [0 61 73 6d 1 0 0 0] in Int16Array
+PASS Validating module [0 61 73 6d 1 0 0 0] in Uint32Array
+PASS Validating module [0 61 73 6d 1 0 0 0] in Int32Array
 PASS Validating module [0 61 73 6d 0 0 0 0] in Uint8Array
 PASS Validating module [0 61 73 6d 0 0 0 0] in Int8Array
 PASS Validating module [0 61 73 6d 0 0 0 0] in Uint16Array
@@ -56,9 +56,9 @@
 PASS Validating module [0 61 73 6d 1 0 0 0 0 1 0] in Int8Array
 PASS Validating module [0 61 73 6d 1 0 0 0 0 2 1 61] in Uint8Array
 PASS Validating module [0 61 73 6d 1 0 0 0 0 2 1 61] in Int8Array
-FAIL Validating module [0 61 73 6d 1 0 0 0 0 2 1 61] in Uint16Array assert_equals: expected true but got false
-FAIL Validating module [0 61 73 6d 1 0 0 0 0 2 1 61] in Int16Array assert_equals: expected true but got false
-FAIL Validating module [0 61 73 6d 1 0 0 0 0 2 1 61] in Uint32Array assert_equals: expected true but got false
-FAIL Validating module [0 61 73 6d 1 0 0 0 0 2 1 61] in Int32Array assert_equals: expected true but got false
+PASS Validating module [0 61 73 6d 1 0 0 0 0 2 1 61] in Uint16Array
+PASS Validating module [0 61 73 6d 1 0 0 0 0 2 1 61] in Int16Array
+PASS Validating module [0 61 73 6d 1 0 0 0 0 2 1 61] in Uint32Array
+PASS Validating module [0 61 73 6d 1 0 0 0 0 2 1 61] in Int32Array
 PASS Stray argument
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/constructor/validate.any.worker-expected.txt (269831 => 269832)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/constructor/validate.any.worker-expected.txt	2020-11-15 18:55:42 UTC (rev 269831)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/constructor/validate.any.worker-expected.txt	2020-11-15 19:58:07 UTC (rev 269832)
@@ -32,10 +32,10 @@
 PASS Validating module [0 61 73 6d 1 0 0] in Int8Array
 PASS Validating module [0 61 73 6d 1 0 0 0] in Uint8Array
 PASS Validating module [0 61 73 6d 1 0 0 0] in Int8Array
-FAIL Validating module [0 61 73 6d 1 0 0 0] in Uint16Array assert_equals: expected true but got false
-FAIL Validating module [0 61 73 6d 1 0 0 0] in Int16Array assert_equals: expected true but got false
-FAIL Validating module [0 61 73 6d 1 0 0 0] in Uint32Array assert_equals: expected true but got false
-FAIL Validating module [0 61 73 6d 1 0 0 0] in Int32Array assert_equals: expected true but got false
+PASS Validating module [0 61 73 6d 1 0 0 0] in Uint16Array
+PASS Validating module [0 61 73 6d 1 0 0 0] in Int16Array
+PASS Validating module [0 61 73 6d 1 0 0 0] in Uint32Array
+PASS Validating module [0 61 73 6d 1 0 0 0] in Int32Array
 PASS Validating module [0 61 73 6d 0 0 0 0] in Uint8Array
 PASS Validating module [0 61 73 6d 0 0 0 0] in Int8Array
 PASS Validating module [0 61 73 6d 0 0 0 0] in Uint16Array
@@ -56,9 +56,9 @@
 PASS Validating module [0 61 73 6d 1 0 0 0 0 1 0] in Int8Array
 PASS Validating module [0 61 73 6d 1 0 0 0 0 2 1 61] in Uint8Array
 PASS Validating module [0 61 73 6d 1 0 0 0 0 2 1 61] in Int8Array
-FAIL Validating module [0 61 73 6d 1 0 0 0 0 2 1 61] in Uint16Array assert_equals: expected true but got false
-FAIL Validating module [0 61 73 6d 1 0 0 0 0 2 1 61] in Int16Array assert_equals: expected true but got false
-FAIL Validating module [0 61 73 6d 1 0 0 0 0 2 1 61] in Uint32Array assert_equals: expected true but got false
-FAIL Validating module [0 61 73 6d 1 0 0 0 0 2 1 61] in Int32Array assert_equals: expected true but got false
+PASS Validating module [0 61 73 6d 1 0 0 0 0 2 1 61] in Uint16Array
+PASS Validating module [0 61 73 6d 1 0 0 0 0 2 1 61] in Int16Array
+PASS Validating module [0 61 73 6d 1 0 0 0 0 2 1 61] in Uint32Array
+PASS Validating module [0 61 73 6d 1 0 0 0 0 2 1 61] in Int32Array
 PASS Stray argument
 

Modified: trunk/Source/_javascript_Core/ChangeLog (269831 => 269832)


--- trunk/Source/_javascript_Core/ChangeLog	2020-11-15 18:55:42 UTC (rev 269831)
+++ trunk/Source/_javascript_Core/ChangeLog	2020-11-15 19:58:07 UTC (rev 269832)
@@ -1,3 +1,19 @@
+2020-11-15  Yusuke Suzuki  <[email protected]>
+
+        [JSC] Wasm should get byte length from source typed array
+        https://bugs.webkit.org/show_bug.cgi?id=218955
+
+        Reviewed by Sam Weinig.
+
+        WebAssembly's module source should be read with byteLength instead of length of typed-array.
+
+        * runtime/JSArrayBufferView.cpp:
+        (JSC::JSArrayBufferView::byteLength const):
+        (JSC::JSArrayBufferView::slowDownAndWasteMemory):
+        * runtime/JSArrayBufferView.h:
+        * wasm/js/JSWebAssemblyHelpers.h:
+        (JSC::getWasmBufferFromValue):
+
 2020-11-14  Don Olmstead  <[email protected]>
 
         [clang-tidy] Run modernize-use-override through JSC

Modified: trunk/Source/_javascript_Core/runtime/JSArrayBufferView.cpp (269831 => 269832)


--- trunk/Source/_javascript_Core/runtime/JSArrayBufferView.cpp	2020-11-15 18:55:42 UTC (rev 269831)
+++ trunk/Source/_javascript_Core/runtime/JSArrayBufferView.cpp	2020-11-15 19:58:07 UTC (rev 269832)
@@ -233,6 +233,7 @@
 #define FACTORY(type) sizeof(typename type ## Adaptor::Type),
     FOR_EACH_TYPED_ARRAY_TYPE_EXCLUDING_DATA_VIEW(FACTORY)
 #undef FACTORY
+    1, // DataViewType
 };
 
 #define FACTORY(type) static_assert(std::is_final<JS ## type ## Array>::value, "");
@@ -241,10 +242,16 @@
 
 static inline size_t elementSize(JSType type)
 {
-    ASSERT(type >= Int8ArrayType && type <= Float64ArrayType);
+    ASSERT(type >= Int8ArrayType && type <= DataViewType);
+    static_assert(Float64ArrayType + 1 == DataViewType);
     return ElementSizeData[type - Int8ArrayType];
 }
 
+unsigned JSArrayBufferView::byteLength() const
+{
+    return length() * elementSize(type());
+}
+
 ArrayBuffer* JSArrayBufferView::slowDownAndWasteMemory()
 {
     ASSERT(m_mode == FastTypedArray || m_mode == OversizeTypedArray);
@@ -269,7 +276,7 @@
     Structure* structure = this->structure(vm);
 
     RefPtr<ArrayBuffer> buffer;
-    unsigned byteLength = m_length * elementSize(type());
+    unsigned byteLength = this->byteLength();
 
     switch (m_mode) {
     case FastTypedArray: {

Modified: trunk/Source/_javascript_Core/runtime/JSArrayBufferView.h (269831 => 269832)


--- trunk/Source/_javascript_Core/runtime/JSArrayBufferView.h	2020-11-15 18:55:42 UTC (rev 269831)
+++ trunk/Source/_javascript_Core/runtime/JSArrayBufferView.h	2020-11-15 19:58:07 UTC (rev 269832)
@@ -195,6 +195,7 @@
     inline Optional<unsigned> byteOffsetConcurrently();
 
     unsigned length() const { return m_length; }
+    unsigned byteLength() const;
 
     DECLARE_EXPORT_INFO;
     

Modified: trunk/Source/_javascript_Core/wasm/js/JSWebAssemblyHelpers.h (269831 => 269832)


--- trunk/Source/_javascript_Core/wasm/js/JSWebAssemblyHelpers.h	2020-11-15 18:55:42 UTC (rev 269831)
+++ trunk/Source/_javascript_Core/wasm/js/JSWebAssemblyHelpers.h	2020-11-15 19:58:07 UTC (rev 269832)
@@ -84,7 +84,7 @@
     }
 
     uint8_t* base = arrayBufferView ? static_cast<uint8_t*>(arrayBufferView->vector()) : static_cast<uint8_t*>(arrayBuffer->impl()->data());
-    size_t byteSize = arrayBufferView ? arrayBufferView->length() : arrayBuffer->impl()->byteLength();
+    size_t byteSize = arrayBufferView ? arrayBufferView->byteLength() : arrayBuffer->impl()->byteLength();
     return { base, byteSize };
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to