Title: [275438] trunk
Revision
275438
Author
[email protected]
Date
2021-04-02 14:10:28 -0700 (Fri, 02 Apr 2021)

Log Message

JSTests:
Add tests for the new type method on certain JS-API wasm objects.
https://bugs.webkit.org/show_bug.cgi?id=222412

Patch by Jessica Tallon <[email protected]> on 2021-04-02
Reviewed by Yusuke Suzuki.

* wasm/js-api/global.js: Added.
(assert.throws):
* wasm/js-api/table.js:
(assert.truthy):
* wasm/js-api/test_memory.js:

LayoutTests/imported/w3c:
Update wasm JS-API tests for the type method to latest upstream.
https://bugs.webkit.org/show_bug.cgi?id=222412

Patch by Jessica Tallon <[email protected]> on 2021-04-02
Reviewed by Yusuke Suzuki.

The upstream tests has recently added a test for the table type method and
updated the other type tests to methods to keep up with a recent spec change.
This adds those updated tests as well as now expectations they pass.

* web-platform-tests/wasm/jsapi/global/type.tentative.any-expected.txt:
* web-platform-tests/wasm/jsapi/global/type.tentative.any.js:
(assert_type):
(string_appeared_here.test):
* web-platform-tests/wasm/jsapi/global/type.tentative.any.worker-expected.txt:
* web-platform-tests/wasm/jsapi/memory/type.tentative.any-expected.txt:
* web-platform-tests/wasm/jsapi/memory/type.tentative.any.js:
(assert_type):
* web-platform-tests/wasm/jsapi/memory/type.tentative.any.worker-expected.txt:

Source/_javascript_Core:
Add type method to WebAssembly.Memory, WebAssembly.Table & WebAssembly.Global objects
https://bugs.webkit.org/show_bug.cgi?id=222412

Patch by Jessica Tallon <[email protected]> on 2021-04-02
Reviewed by Yusuke Suzuki.

This adds a type method to several WASM objects as part of the work to add WASM
type reflections to the JS-API. The methods return a JSON object which describes
the type of the object and can be passed to the constructor to create a new wasm
object of that type.

 * wasm/js/JSWebAssemblyGlobal.cpp:
(JSC::JSWebAssemblyGlobal::type):
* wasm/js/JSWebAssemblyGlobal.h:
* wasm/js/JSWebAssemblyMemory.cpp:
(JSC::JSWebAssemblyMemory::type):
* wasm/js/JSWebAssemblyMemory.h:
* wasm/js/JSWebAssemblyTable.cpp:
(JSC::JSWebAssemblyTable::type):
* wasm/js/JSWebAssemblyTable.h:
* wasm/js/WebAssemblyGlobalPrototype.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
* wasm/js/WebAssemblyGlobalPrototype.h:
* wasm/js/WebAssemblyMemoryPrototype.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
* wasm/js/WebAssemblyTablePrototype.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):

Modified Paths

Added Paths

Diff

Modified: trunk/JSTests/ChangeLog (275437 => 275438)


--- trunk/JSTests/ChangeLog	2021-04-02 21:07:18 UTC (rev 275437)
+++ trunk/JSTests/ChangeLog	2021-04-02 21:10:28 UTC (rev 275438)
@@ -1,3 +1,16 @@
+2021-04-02  Jessica Tallon  <[email protected]>
+
+        Add tests for the new type method on certain JS-API wasm objects.
+        https://bugs.webkit.org/show_bug.cgi?id=222412
+
+        Reviewed by Yusuke Suzuki.
+
+        * wasm/js-api/global.js: Added.
+        (assert.throws):
+        * wasm/js-api/table.js:
+        (assert.truthy):
+        * wasm/js-api/test_memory.js:
+
 2021-04-01  Alexey Shvayka  <[email protected]>
 
         Optimize createListFromArrayLike() and Proxy's [[OwnPropertyKeys]] method

Added: trunk/JSTests/wasm/js-api/global.js (0 => 275438)


--- trunk/JSTests/wasm/js-api/global.js	                        (rev 0)
+++ trunk/JSTests/wasm/js-api/global.js	2021-04-02 21:10:28 UTC (rev 275438)
@@ -0,0 +1,29 @@
+import * as assert from '../assert.js';
+{
+    assert.throws(() => {
+        const g = new WebAssembly.Global({value: "i32", mutable: false});
+        g.type.call({});
+    }, TypeError, "expected |this| value to be an instance of WebAssembly.Global");
+
+    const i32 = new WebAssembly.Global({value: "i32", mutable: false}).type();
+    assert.eq(Object.keys(i32).length, 2);
+    assert.eq(i32.value, "i32");
+    assert.eq(i32.mutable, false);
+
+    const i32m = new WebAssembly.Global({value: "i32", mutable: true}).type();
+    assert.eq(i32m.value, "i32");
+    assert.eq(i32m.mutable, true);
+
+    const i64 = new WebAssembly.Global({value: "i64", mutable: true}).type();
+    assert.eq(i64.value, "i64");
+
+    const f32 = new WebAssembly.Global({value: "f32", mutable: true}).type();
+    assert.eq(f32.value, "f32");
+
+    const f64 = new WebAssembly.Global({value: "f64", mutable: true}).type();
+    assert.eq(f64.value, "f64");
+
+    const f64n = new WebAssembly.Global(f64).type();
+    assert.eq(f64.value, f64n.value);
+    assert.eq(f64.mutable, f64n.mutable);
+}
\ No newline at end of file

Modified: trunk/JSTests/wasm/js-api/table.js (275437 => 275438)


--- trunk/JSTests/wasm/js-api/table.js	2021-04-02 21:07:18 UTC (rev 275437)
+++ trunk/JSTests/wasm/js-api/table.js	2021-04-02 21:10:28 UTC (rev 275438)
@@ -390,3 +390,33 @@
     }
     assert.truthy(threw);
 }
+
+{
+    assert.throws(() => {
+        const t = new WebAssembly.Table({minimum: 5, element: "funcref"});
+        t.type.call({});
+    }, TypeError, "expected |this| value to be an instance of WebAssembly.Table");
+
+    const t0 = new WebAssembly.Table({minimum: 5, element: "funcref"}).type();
+    assert.eq(Object.keys(t0).length, 2);
+    assert.eq(t0.minimum, 5);
+    assert.eq(t0.element, "funcref");
+
+    const t1 = new WebAssembly.Table({minimum: 5, maximum: 10, element: "funcref"}).type();
+    assert.eq(Object.keys(t1).length, 3);
+    assert.eq(t1.minimum, 5);
+    assert.eq(t1.maximum, 10)
+    assert.eq(t1.element, "funcref");
+
+    const t2 = new WebAssembly.Table({minimum: 5, maximum: 10, element: "externref"}).type();
+    assert.eq(Object.keys(t2).length, 3);
+    assert.eq(t2.minimum, 5);
+    assert.eq(t2.maximum, 10)
+    assert.eq(t2.element, "externref");
+
+    const t3 = new WebAssembly.Table(t2).type();
+    assert.eq(Object.keys(t2).length, Object.keys(t3).length);
+    assert.eq(t2.minimum, t3.minimum);
+    assert.eq(t2.maximum, t3.maximum)
+    assert.eq(t2.element, t3.element);
+}
\ No newline at end of file

Modified: trunk/JSTests/wasm/js-api/test_memory.js (275437 => 275438)


--- trunk/JSTests/wasm/js-api/test_memory.js	2021-04-02 21:07:18 UTC (rev 275437)
+++ trunk/JSTests/wasm/js-api/test_memory.js	2021-04-02 21:10:28 UTC (rev 275438)
@@ -399,3 +399,33 @@
     assert.eq(instance.exports.memory.buffer.byteLength, 20 * pageSize);
     assert.truthy(instance.exports.memory instanceof WebAssembly.Memory);
 }
+
+test(function() {
+    assert.throws(() => {
+        const m = new WebAssembly.Memory({minimum:40, maximum: 100});
+        m.type.call({});
+    }, TypeError, "WebAssembly.Memory.prototype.buffer getter called with non WebAssembly.Memory |this| value");
+
+    const memory = new WebAssembly.Memory({initial: 20});
+    assert.eq(Object.keys(memory.type()).length, 2);
+    assert.eq(memory.type().minimum, 20);
+    assert.eq(memory.type().shared, false);
+
+    const memory2 = new WebAssembly.Memory({minimum:40, maximum: 100});
+    assert.eq(Object.keys(memory2.type()).length, 3);
+    assert.eq(memory2.type().minimum, 40);
+    assert.eq(memory2.type().maximum, 100);
+    assert.eq(memory.type().shared, false);
+
+    const memory3 = new WebAssembly.Memory(memory2.type());
+    assert.eq(Object.keys(memory2.type()).length, Object.keys(memory3.type()).length);
+    assert.eq(memory2.type().minimum, memory3.type().minimum);
+    assert.eq(memory2.type().maximum, memory3.type().maximum);
+    assert.eq(memory.type().shared, false);
+
+    const memory4 = new WebAssembly.Memory({minimum: 10, maximum: 20, shared:true});
+    assert.eq(Object.keys(memory4.type()).length, 3);
+    assert.eq(memory4.type().minimum, 10);
+    assert.eq(memory4.type().maximum, 20);
+    assert.eq(memory4.type().shared, true);
+})
\ No newline at end of file

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (275437 => 275438)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2021-04-02 21:07:18 UTC (rev 275437)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2021-04-02 21:10:28 UTC (rev 275438)
@@ -1,3 +1,24 @@
+2021-04-02  Jessica Tallon  <[email protected]>
+
+        Update wasm JS-API tests for the type method to latest upstream.
+        https://bugs.webkit.org/show_bug.cgi?id=222412
+
+        Reviewed by Yusuke Suzuki.
+
+        The upstream tests has recently added a test for the table type method and
+        updated the other type tests to methods to keep up with a recent spec change.
+        This adds those updated tests as well as now expectations they pass.
+
+        * web-platform-tests/wasm/jsapi/global/type.tentative.any-expected.txt:
+        * web-platform-tests/wasm/jsapi/global/type.tentative.any.js:
+        (assert_type):
+        (string_appeared_here.test):
+        * web-platform-tests/wasm/jsapi/global/type.tentative.any.worker-expected.txt:
+        * web-platform-tests/wasm/jsapi/memory/type.tentative.any-expected.txt:
+        * web-platform-tests/wasm/jsapi/memory/type.tentative.any.js:
+        (assert_type):
+        * web-platform-tests/wasm/jsapi/memory/type.tentative.any.worker-expected.txt:
+
 2021-04-02  Chris Lord  <[email protected]>
 
         Implement text rendering on OffscreenCanvas in a Worker

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/type.tentative.any-expected.txt (275437 => 275438)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/type.tentative.any-expected.txt	2021-04-02 21:07:18 UTC (rev 275437)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/type.tentative.any-expected.txt	2021-04-02 21:10:28 UTC (rev 275438)
@@ -1,15 +1,15 @@
 
-FAIL i32, mutable undefined is not an object (evaluating 'myglobal.type.value')
-FAIL i32, immutable undefined is not an object (evaluating 'myglobal.type.value')
-FAIL i64, mutable undefined is not an object (evaluating 'myglobal.type.value')
-FAIL i64, immutable undefined is not an object (evaluating 'myglobal.type.value')
-FAIL f32, mutable undefined is not an object (evaluating 'myglobal.type.value')
-FAIL f32, immutable undefined is not an object (evaluating 'myglobal.type.value')
-FAIL f64, mutable undefined is not an object (evaluating 'myglobal.type.value')
-FAIL f64, immutable undefined is not an object (evaluating 'myglobal.type.value')
-FAIL anyref, mutable undefined is not an object (evaluating 'myglobal.type.value')
-FAIL anyref, immutable undefined is not an object (evaluating 'myglobal.type.value')
-FAIL funcref, mutable undefined is not an object (evaluating 'myglobal.type.value')
-FAIL funcref, immutable undefined is not an object (evaluating 'myglobal.type.value')
-FAIL key ordering undefined is not an object (evaluating 'Object.getOwnPropertyNames(myglobal.type)')
+PASS i32, mutable
+PASS i32, immutable
+PASS i64, mutable
+PASS i64, immutable
+PASS f32, mutable
+PASS f32, immutable
+PASS f64, mutable
+PASS f64, immutable
+PASS anyref, mutable
+PASS anyref, immutable
+PASS funcref, mutable
+PASS funcref, immutable
+PASS key ordering
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/type.tentative.any.js (275437 => 275438)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/type.tentative.any.js	2021-04-02 21:07:18 UTC (rev 275437)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/type.tentative.any.js	2021-04-02 21:10:28 UTC (rev 275438)
@@ -3,9 +3,10 @@
 
 function assert_type(argument) {
     const myglobal = new WebAssembly.Global(argument);
+    const globaltype = myglobal.type();
 
-    assert_equals(myglobal.type.value, argument.value);
-    assert_equals(myglobal.type.mutable, argument.mutable);
+    assert_equals(globaltype.value, argument.value);
+    assert_equals(globaltype.mutable, argument.mutable);
 }
 
 test(() => {
@@ -58,7 +59,7 @@
 
 test(() => {
     const myglobal = new WebAssembly.Global({"value": "i32", "mutable": true});
-    const propertyNames = Object.getOwnPropertyNames(myglobal.type);
+    const propertyNames = Object.getOwnPropertyNames(myglobal.type());
     assert_equals(propertyNames[0], "mutable");
     assert_equals(propertyNames[1], "value");
 }, "key ordering");

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/type.tentative.any.worker-expected.txt (275437 => 275438)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/type.tentative.any.worker-expected.txt	2021-04-02 21:07:18 UTC (rev 275437)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/type.tentative.any.worker-expected.txt	2021-04-02 21:10:28 UTC (rev 275438)
@@ -1,15 +1,15 @@
 
-FAIL i32, mutable undefined is not an object (evaluating 'myglobal.type.value')
-FAIL i32, immutable undefined is not an object (evaluating 'myglobal.type.value')
-FAIL i64, mutable undefined is not an object (evaluating 'myglobal.type.value')
-FAIL i64, immutable undefined is not an object (evaluating 'myglobal.type.value')
-FAIL f32, mutable undefined is not an object (evaluating 'myglobal.type.value')
-FAIL f32, immutable undefined is not an object (evaluating 'myglobal.type.value')
-FAIL f64, mutable undefined is not an object (evaluating 'myglobal.type.value')
-FAIL f64, immutable undefined is not an object (evaluating 'myglobal.type.value')
-FAIL anyref, mutable undefined is not an object (evaluating 'myglobal.type.value')
-FAIL anyref, immutable undefined is not an object (evaluating 'myglobal.type.value')
-FAIL funcref, mutable undefined is not an object (evaluating 'myglobal.type.value')
-FAIL funcref, immutable undefined is not an object (evaluating 'myglobal.type.value')
-FAIL key ordering undefined is not an object (evaluating 'Object.getOwnPropertyNames(myglobal.type)')
+PASS i32, mutable
+PASS i32, immutable
+PASS i64, mutable
+PASS i64, immutable
+PASS f32, mutable
+PASS f32, immutable
+PASS f64, mutable
+PASS f64, immutable
+PASS anyref, mutable
+PASS anyref, immutable
+PASS funcref, mutable
+PASS funcref, immutable
+PASS key ordering
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/type.tentative.any-expected.txt (275437 => 275438)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/type.tentative.any-expected.txt	2021-04-02 21:07:18 UTC (rev 275437)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/type.tentative.any-expected.txt	2021-04-02 21:10:28 UTC (rev 275438)
@@ -1,8 +1,8 @@
 
-FAIL Zero initial, no maximum undefined is not an object (evaluating 'memory.type.minimum')
-FAIL Non-zero initial, no maximum undefined is not an object (evaluating 'memory.type.minimum')
-FAIL Zero maximum undefined is not an object (evaluating 'memory.type.minimum')
-FAIL None-zero maximum undefined is not an object (evaluating 'memory.type.minimum')
-FAIL non-shared memory undefined is not an object (evaluating 'memory.type.minimum')
-FAIL shared memory undefined is not an object (evaluating 'memory.type.minimum')
+PASS Zero initial, no maximum
+PASS Non-zero initial, no maximum
+PASS Zero maximum
+PASS None-zero maximum
+PASS non-shared memory
+PASS shared memory
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/type.tentative.any.js (275437 => 275438)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/type.tentative.any.js	2021-04-02 21:07:18 UTC (rev 275437)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/type.tentative.any.js	2021-04-02 21:10:28 UTC (rev 275438)
@@ -3,11 +3,12 @@
 
 function assert_type(argument) {
     const memory = new WebAssembly.Memory(argument);
+    const memorytype = memory.type()
 
-    assert_equals(memory.type.minimum, argument.minimum);
-    assert_equals(memory.type.maximum, argument.maximum);
+    assert_equals(memorytype.minimum, argument.minimum);
+    assert_equals(memorytype.maximum, argument.maximum);
     if (argument.shared !== undefined) {
-        assert_equals(memory.type.shared, argument.shared);
+        assert_equals(memorytype.shared, argument.shared);
     }
 }
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/type.tentative.any.worker-expected.txt (275437 => 275438)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/type.tentative.any.worker-expected.txt	2021-04-02 21:07:18 UTC (rev 275437)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/type.tentative.any.worker-expected.txt	2021-04-02 21:10:28 UTC (rev 275438)
@@ -1,8 +1,8 @@
 
-FAIL Zero initial, no maximum undefined is not an object (evaluating 'memory.type.minimum')
-FAIL Non-zero initial, no maximum undefined is not an object (evaluating 'memory.type.minimum')
-FAIL Zero maximum undefined is not an object (evaluating 'memory.type.minimum')
-FAIL None-zero maximum undefined is not an object (evaluating 'memory.type.minimum')
-FAIL non-shared memory undefined is not an object (evaluating 'memory.type.minimum')
-FAIL shared memory undefined is not an object (evaluating 'memory.type.minimum')
+PASS Zero initial, no maximum
+PASS Non-zero initial, no maximum
+PASS Zero maximum
+PASS None-zero maximum
+PASS non-shared memory
+PASS shared memory
 

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/type.tentative.any-expected.txt (0 => 275438)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/type.tentative.any-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/type.tentative.any-expected.txt	2021-04-02 21:10:28 UTC (rev 275438)
@@ -0,0 +1,6 @@
+
+PASS Zero initial, no maximum
+PASS Non-zero initial, no maximum
+PASS Zero maximum
+PASS None-zero maximum
+

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/type.tentative.any.html (0 => 275438)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/type.tentative.any.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/type.tentative.any.html	2021-04-02 21:10:28 UTC (rev 275438)
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/type.tentative.any.js (0 => 275438)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/type.tentative.any.js	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/type.tentative.any.js	2021-04-02 21:10:28 UTC (rev 275438)
@@ -0,0 +1,26 @@
+// META: global=window,dedicatedworker,jsshell
+// META: script=/wasm/jsapi/assertions.js
+
+function assert_type(argument) {
+    const mytable = new WebAssembly.Table(argument);
+    const tabletype = mytable.type()
+    assert_equals(tabletype.minimum, argument.minimum);
+    assert_equals(tabletype.maximum, argument.maximum);
+    assert_equals(tabletype.element, argument.element);
+}
+
+test(() => {
+    assert_type({ "minimum": 0, "element": "funcref"});
+}, "Zero initial, no maximum");
+
+test(() => {
+    assert_type({ "minimum": 5, "element": "funcref" });
+}, "Non-zero initial, no maximum");
+
+test(() => {
+    assert_type({ "minimum": 0, "maximum": 0, "element": "funcref" });
+}, "Zero maximum");
+
+test(() => {
+    assert_type({ "minimum": 0, "maximum": 5, "element": "funcref" });
+}, "None-zero maximum");

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/type.tentative.any.worker-expected.txt (0 => 275438)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/type.tentative.any.worker-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/type.tentative.any.worker-expected.txt	2021-04-02 21:10:28 UTC (rev 275438)
@@ -0,0 +1,6 @@
+
+PASS Zero initial, no maximum
+PASS Non-zero initial, no maximum
+PASS Zero maximum
+PASS None-zero maximum
+

Modified: trunk/Source/_javascript_Core/ChangeLog (275437 => 275438)


--- trunk/Source/_javascript_Core/ChangeLog	2021-04-02 21:07:18 UTC (rev 275437)
+++ trunk/Source/_javascript_Core/ChangeLog	2021-04-02 21:10:28 UTC (rev 275438)
@@ -1,3 +1,32 @@
+2021-04-02  Jessica Tallon  <[email protected]>
+
+        Add type method to WebAssembly.Memory, WebAssembly.Table & WebAssembly.Global objects
+        https://bugs.webkit.org/show_bug.cgi?id=222412
+
+        Reviewed by Yusuke Suzuki.
+
+        This adds a type method to several WASM objects as part of the work to add WASM
+        type reflections to the JS-API. The methods return a JSON object which describes
+        the type of the object and can be passed to the constructor to create a new wasm
+        object of that type.
+
+         * wasm/js/JSWebAssemblyGlobal.cpp:
+        (JSC::JSWebAssemblyGlobal::type):
+        * wasm/js/JSWebAssemblyGlobal.h:
+        * wasm/js/JSWebAssemblyMemory.cpp:
+        (JSC::JSWebAssemblyMemory::type):
+        * wasm/js/JSWebAssemblyMemory.h:
+        * wasm/js/JSWebAssemblyTable.cpp:
+        (JSC::JSWebAssemblyTable::type):
+        * wasm/js/JSWebAssemblyTable.h:
+        * wasm/js/WebAssemblyGlobalPrototype.cpp:
+        (JSC::JSC_DEFINE_HOST_FUNCTION):
+        * wasm/js/WebAssemblyGlobalPrototype.h:
+        * wasm/js/WebAssemblyMemoryPrototype.cpp:
+        (JSC::JSC_DEFINE_HOST_FUNCTION):
+        * wasm/js/WebAssemblyTablePrototype.cpp:
+        (JSC::JSC_DEFINE_HOST_FUNCTION):
+
 2021-04-01  Yusuke Suzuki  <[email protected]>
 
         [WTF] Introduce RobinHoodHashTable

Modified: trunk/Source/_javascript_Core/wasm/js/JSWebAssemblyGlobal.cpp (275437 => 275438)


--- trunk/Source/_javascript_Core/wasm/js/JSWebAssemblyGlobal.cpp	2021-04-02 21:07:18 UTC (rev 275437)
+++ trunk/Source/_javascript_Core/wasm/js/JSWebAssemblyGlobal.cpp	2021-04-02 21:10:28 UTC (rev 275438)
@@ -25,6 +25,7 @@
 
 #include "config.h"
 #include "JSWebAssemblyGlobal.h"
+#include "ObjectConstructor.h"
 
 #if ENABLE(WEBASSEMBLY)
 
@@ -81,6 +82,43 @@
     thisObject->global()->visitAggregate(visitor);
 }
 
+JSObject* JSWebAssemblyGlobal::type(JSGlobalObject* globalObject)
+{
+    VM& vm = globalObject->vm();
+
+    JSObject* result = constructEmptyObject(globalObject, globalObject->objectPrototype(), 2);
+
+    result->putDirect(vm, Identifier::fromString(vm, "mutable"), jsBoolean(m_global->mutability() == Wasm::GlobalInformation::Mutable));
+
+    Wasm::Type valueType = m_global->type();
+    JSString* valueString = nullptr;
+    switch (valueType.kind) {
+    case Wasm::TypeKind::I32:
+        valueString = jsNontrivialString(vm, "i32");
+        break;
+    case Wasm::TypeKind::I64:
+        valueString = jsNontrivialString(vm, "i64");
+        break;
+    case Wasm::TypeKind::F32:
+        valueString = jsNontrivialString(vm, "f32");
+        break;
+    case Wasm::TypeKind::F64:
+        valueString = jsNontrivialString(vm, "f64");
+        break;
+    case Wasm::TypeKind::Externref:
+        valueString = jsNontrivialString(vm, "externref");
+        break;
+    case Wasm::TypeKind::Funcref:
+        valueString = jsNontrivialString(vm, "funcref");
+        break;
+    default:
+        RELEASE_ASSERT_NOT_REACHED();
+    }
+    result->putDirect(vm, Identifier::fromString(vm, "value"), valueString);
+
+    return result;
+}
+
 DEFINE_VISIT_CHILDREN(JSWebAssemblyGlobal);
 
 } // namespace JSC

Modified: trunk/Source/_javascript_Core/wasm/js/JSWebAssemblyGlobal.h (275437 => 275438)


--- trunk/Source/_javascript_Core/wasm/js/JSWebAssemblyGlobal.h	2021-04-02 21:07:18 UTC (rev 275437)
+++ trunk/Source/_javascript_Core/wasm/js/JSWebAssemblyGlobal.h	2021-04-02 21:10:28 UTC (rev 275438)
@@ -55,6 +55,7 @@
     DECLARE_INFO;
 
     Wasm::Global* global() { return m_global.ptr(); }
+    JSObject* type(JSGlobalObject*);
 
 private:
     JSWebAssemblyGlobal(VM&, Structure*, Ref<Wasm::Global>&&);

Modified: trunk/Source/_javascript_Core/wasm/js/JSWebAssemblyMemory.cpp (275437 => 275438)


--- trunk/Source/_javascript_Core/wasm/js/JSWebAssemblyMemory.cpp	2021-04-02 21:07:18 UTC (rev 275437)
+++ trunk/Source/_javascript_Core/wasm/js/JSWebAssemblyMemory.cpp	2021-04-02 21:10:28 UTC (rev 275438)
@@ -131,6 +131,27 @@
     return grown.value();
 }
 
+JSObject* JSWebAssemblyMemory::type(JSGlobalObject* globalObject)
+{
+    VM& vm = globalObject->vm();
+
+    Wasm::PageCount minimum = m_memory->initial();
+    Wasm::PageCount maximum = m_memory->maximum();
+
+    JSObject* result;
+    if (maximum.isValid()) {
+        result = constructEmptyObject(globalObject, globalObject->objectPrototype(), 3);
+        result->putDirect(vm, Identifier::fromString(vm, "maximum"), jsNumber(maximum.pageCount()));
+    } else
+        result = constructEmptyObject(globalObject, globalObject->objectPrototype(), 2);
+
+    result->putDirect(vm, Identifier::fromString(vm, "minimum"), jsNumber(minimum.pageCount()));
+    result->putDirect(vm, Identifier::fromString(vm, "shared"), jsBoolean(m_memory->sharingMode() == Wasm::MemorySharingMode::Shared));
+
+    return result;
+}
+
+
 void JSWebAssemblyMemory::growSuccessCallback(VM& vm, Wasm::PageCount oldPageCount, Wasm::PageCount newPageCount)
 {
     // We need to clear out the old array buffer because it might now be pointing to stale memory.

Modified: trunk/Source/_javascript_Core/wasm/js/JSWebAssemblyMemory.h (275437 => 275438)


--- trunk/Source/_javascript_Core/wasm/js/JSWebAssemblyMemory.h	2021-04-02 21:07:18 UTC (rev 275437)
+++ trunk/Source/_javascript_Core/wasm/js/JSWebAssemblyMemory.h	2021-04-02 21:10:28 UTC (rev 275438)
@@ -60,6 +60,8 @@
     Wasm::PageCount grow(VM&, JSGlobalObject*, uint32_t delta);
     JS_EXPORT_PRIVATE void growSuccessCallback(VM&, Wasm::PageCount oldPageCount, Wasm::PageCount newPageCount);
 
+    JSObject* type(JSGlobalObject*);
+
 private:
     JSWebAssemblyMemory(VM&, Structure*);
     void finishCreation(VM&);

Modified: trunk/Source/_javascript_Core/wasm/js/JSWebAssemblyTable.cpp (275437 => 275438)


--- trunk/Source/_javascript_Core/wasm/js/JSWebAssemblyTable.cpp	2021-04-02 21:07:18 UTC (rev 275437)
+++ trunk/Source/_javascript_Core/wasm/js/JSWebAssemblyTable.cpp	2021-04-02 21:10:28 UTC (rev 275438)
@@ -126,6 +126,37 @@
     m_table->clear(index);
 }
 
+JSObject* JSWebAssemblyTable::type(JSGlobalObject* globalObject)
+{
+    VM& vm = globalObject->vm();
+
+    Wasm::TableElementType element = m_table->type();
+    JSString* elementString = nullptr;
+    switch (element) {
+    case Wasm::TableElementType::Funcref:
+        elementString = jsNontrivialString(vm, "funcref");
+        break;
+    case Wasm::TableElementType::Externref:
+        elementString = jsNontrivialString(vm, "externref");
+        break;
+    default:
+        RELEASE_ASSERT_NOT_REACHED();
+    }
+
+    JSObject* result;
+    auto maximum = m_table->maximum();
+    if (maximum) {
+        result = constructEmptyObject(globalObject, globalObject->objectPrototype(), 3);
+        result->putDirect(vm, Identifier::fromString(vm, "maximum"), jsNumber(*maximum));
+    } else
+        result = constructEmptyObject(globalObject, globalObject->objectPrototype(), 2);
+
+    uint32_t minimum = m_table->length();
+    result->putDirect(vm, Identifier::fromString(vm, "minimum"), jsNumber(minimum));
+    result->putDirect(vm, Identifier::fromString(vm, "element"), elementString);
+    return result;
+}
+
 } // namespace JSC
 
 #endif // ENABLE(WEBASSEMBLY)

Modified: trunk/Source/_javascript_Core/wasm/js/JSWebAssemblyTable.h (275437 => 275438)


--- trunk/Source/_javascript_Core/wasm/js/JSWebAssemblyTable.h	2021-04-02 21:07:18 UTC (rev 275437)
+++ trunk/Source/_javascript_Core/wasm/js/JSWebAssemblyTable.h	2021-04-02 21:10:28 UTC (rev 275438)
@@ -64,6 +64,7 @@
     void set(uint32_t, WebAssemblyWrapperFunction*);
     void set(uint32_t, JSValue);
     void clear(uint32_t);
+    JSObject* type(JSGlobalObject*);
 
     Wasm::Table* table() { return m_table.ptr(); }
 

Modified: trunk/Source/_javascript_Core/wasm/js/WebAssemblyGlobalPrototype.cpp (275437 => 275438)


--- trunk/Source/_javascript_Core/wasm/js/WebAssemblyGlobalPrototype.cpp	2021-04-02 21:07:18 UTC (rev 275437)
+++ trunk/Source/_javascript_Core/wasm/js/WebAssemblyGlobalPrototype.cpp	2021-04-02 21:10:28 UTC (rev 275438)
@@ -38,6 +38,7 @@
 static JSC_DECLARE_HOST_FUNCTION(webAssemblyGlobalProtoFuncValueOf);
 static JSC_DECLARE_HOST_FUNCTION(webAssemblyGlobalProtoGetterFuncValue);
 static JSC_DECLARE_HOST_FUNCTION(webAssemblyGlobalProtoSetterFuncValue);
+static JSC_DECLARE_HOST_FUNCTION(webAssemblyGlobalProtoFuncType);
 }
 
 #include "WebAssemblyGlobalPrototype.lut.h"
@@ -49,6 +50,8 @@
 /* Source for WebAssemblyGlobalPrototype.lut.h
  @begin prototypeGlobalWebAssemblyGlobal
  valueOf webAssemblyGlobalProtoFuncValueOf Function 0
+ type    webAssemblyGlobalProtoFuncType    Function 0
+
  @end
  */
 
@@ -76,6 +79,17 @@
     RELEASE_AND_RETURN(throwScope, JSValue::encode(global->global()->get(globalObject)));
 }
 
+JSC_DEFINE_HOST_FUNCTION(webAssemblyGlobalProtoFuncType, (JSGlobalObject* globalObject, CallFrame* callFrame))
+{
+    VM& vm = globalObject->vm();
+    auto throwScope = DECLARE_THROW_SCOPE(vm);
+
+    JSWebAssemblyGlobal* global = getGlobal(globalObject, vm, callFrame->thisValue());
+    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+
+    RELEASE_AND_RETURN(throwScope, JSValue::encode(global->type(globalObject)));
+}
+
 JSC_DEFINE_HOST_FUNCTION(webAssemblyGlobalProtoGetterFuncValue, (JSGlobalObject* globalObject, CallFrame* callFrame))
 {
     VM& vm = globalObject->vm();
@@ -83,7 +97,6 @@
 
     JSWebAssemblyGlobal* global = getGlobal(globalObject, vm, callFrame->thisValue());
     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
-
     RELEASE_AND_RETURN(throwScope, JSValue::encode(global->global()->get(globalObject)));
 }
 

Modified: trunk/Source/_javascript_Core/wasm/js/WebAssemblyGlobalPrototype.h (275437 => 275438)


--- trunk/Source/_javascript_Core/wasm/js/WebAssemblyGlobalPrototype.h	2021-04-02 21:07:18 UTC (rev 275437)
+++ trunk/Source/_javascript_Core/wasm/js/WebAssemblyGlobalPrototype.h	2021-04-02 21:10:28 UTC (rev 275438)
@@ -48,6 +48,8 @@
 
     DECLARE_INFO;
 
+    JSObject* type(JSGlobalObject*);
+
 private:
     WebAssemblyGlobalPrototype(VM&, Structure*);
     void finishCreation(VM&, JSGlobalObject*);

Modified: trunk/Source/_javascript_Core/wasm/js/WebAssemblyMemoryPrototype.cpp (275437 => 275438)


--- trunk/Source/_javascript_Core/wasm/js/WebAssemblyMemoryPrototype.cpp	2021-04-02 21:07:18 UTC (rev 275437)
+++ trunk/Source/_javascript_Core/wasm/js/WebAssemblyMemoryPrototype.cpp	2021-04-02 21:10:28 UTC (rev 275438)
@@ -40,6 +40,7 @@
 namespace JSC {
 static JSC_DECLARE_HOST_FUNCTION(webAssemblyMemoryProtoFuncGrow);
 static JSC_DECLARE_HOST_FUNCTION(webAssemblyMemoryProtoFuncBuffer);
+static JSC_DECLARE_HOST_FUNCTION(webAssemblyMemoryProtoFuncType);
 }
 
 #include "WebAssemblyMemoryPrototype.lut.h"
@@ -53,6 +54,7 @@
 @begin prototypeTableWebAssemblyMemory
  grow   webAssemblyMemoryProtoFuncGrow   Function 1
  buffer webAssemblyMemoryProtoFuncBuffer Accessor 0
+ type   webAssemblyMemoryProtoFuncType   Function 0
 @end
 */
 
@@ -96,6 +98,17 @@
     RELEASE_AND_RETURN(throwScope, JSValue::encode(memory->buffer(globalObject)));
 }
 
+JSC_DEFINE_HOST_FUNCTION(webAssemblyMemoryProtoFuncType, (JSGlobalObject* globalObject, CallFrame* callFrame))
+{
+    VM& vm = globalObject->vm();
+    auto throwScope = DECLARE_THROW_SCOPE(vm);
+
+    JSWebAssemblyMemory* memory = getMemory(globalObject, vm, callFrame->thisValue());
+    RETURN_IF_EXCEPTION(throwScope, { });
+    RELEASE_AND_RETURN(throwScope, JSValue::encode(memory->type(globalObject)));
+}
+
+
 WebAssemblyMemoryPrototype* WebAssemblyMemoryPrototype::create(VM& vm, JSGlobalObject*, Structure* structure)
 {
     auto* object = new (NotNull, allocateCell<WebAssemblyMemoryPrototype>(vm.heap)) WebAssemblyMemoryPrototype(vm, structure);

Modified: trunk/Source/_javascript_Core/wasm/js/WebAssemblyTablePrototype.cpp (275437 => 275438)


--- trunk/Source/_javascript_Core/wasm/js/WebAssemblyTablePrototype.cpp	2021-04-02 21:07:18 UTC (rev 275437)
+++ trunk/Source/_javascript_Core/wasm/js/WebAssemblyTablePrototype.cpp	2021-04-02 21:10:28 UTC (rev 275438)
@@ -41,6 +41,7 @@
 static JSC_DECLARE_HOST_FUNCTION(webAssemblyTableProtoFuncGrow);
 static JSC_DECLARE_HOST_FUNCTION(webAssemblyTableProtoFuncGet);
 static JSC_DECLARE_HOST_FUNCTION(webAssemblyTableProtoFuncSet);
+static JSC_DECLARE_HOST_FUNCTION(webAssemblyTableProtoFuncType);
 }
 
 #include "WebAssemblyTablePrototype.lut.h"
@@ -55,6 +56,7 @@
  grow   webAssemblyTableProtoFuncGrow   Function 1
  get    webAssemblyTableProtoFuncGet    Function 1
  set    webAssemblyTableProtoFuncSet    Function 2
+ type   webAssemblyTableProtoFuncType   Function 0
  @end
  */
 
@@ -164,6 +166,16 @@
     return JSValue::encode(jsUndefined());
 }
 
+JSC_DEFINE_HOST_FUNCTION(webAssemblyTableProtoFuncType, (JSGlobalObject* globalObject, CallFrame* callFrame))
+{
+    VM& vm = globalObject->vm();
+    auto throwScope = DECLARE_THROW_SCOPE(vm);
+
+    JSWebAssemblyTable* table = getTable(globalObject, vm, callFrame->thisValue());
+    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+    RELEASE_AND_RETURN(throwScope, JSValue::encode(table->type(globalObject)));
+}
+
 WebAssemblyTablePrototype* WebAssemblyTablePrototype::create(VM& vm, JSGlobalObject*, Structure* structure)
 {
     auto* object = new (NotNull, allocateCell<WebAssemblyTablePrototype>(vm.heap)) WebAssemblyTablePrototype(vm, structure);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to