RESOLVED FIXED222412
Add type method for WASM Global, Memory and Table JS API classes
https://bugs.webkit.org/show_bug.cgi?id=222412
Summary Add type method for WASM Global, Memory and Table JS API classes
jtallon
Reported 2021-02-25 04:28:12 PST
Supporting the type method on WebAssembly.Global, WebAssembly.Memory and WebAssembly.Table in the wasm JS-API would allow us to inspect the type of those objects as well as create new objects with the same type by passing the type return by the new type method to the constructor. This is outlined in https://github.com/WebAssembly/js-types/blob/master/proposals/js-types/Overview.md#extensions-to-api-functions
Attachments
Patch (32.71 KB, patch)
2021-02-25 04:42 PST, jtallon
no flags
Patch (34.04 KB, patch)
2021-03-11 06:55 PST, jtallon
no flags
Patch (33.75 KB, patch)
2021-03-16 07:24 PDT, jtallon
no flags
Patch (33.06 KB, patch)
2021-03-16 09:41 PDT, jtallon
no flags
Patch (33.31 KB, patch)
2021-03-18 05:19 PDT, jtallon
no flags
Patch (33.22 KB, patch)
2021-03-26 01:55 PDT, jtallon
no flags
Patch (32.84 KB, patch)
2021-03-29 09:14 PDT, jtallon
no flags
Patch (32.80 KB, patch)
2021-03-30 01:46 PDT, jtallon
no flags
Patch (32.65 KB, patch)
2021-03-31 05:35 PDT, jtallon
no flags
jtallon
Comment 1 2021-02-25 04:42:25 PST
EWS Watchlist
Comment 2 2021-02-25 04:43:27 PST
This patch modifies the imported WPT tests. Please ensure that any changes on the tests (not coming from a WPT import) are exported to WPT. Please see https://trac.webkit.org/wiki/WPTExportProcess
Yusuke Suzuki
Comment 3 2021-02-25 16:11:12 PST
Comment on attachment 421514 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=421514&action=review Commented. > Source/JavaScriptCore/wasm/js/JSWebAssemblyGlobal.cpp:115 > + default: > + RELEASE_ASSERT_NOT_REACHED(); > + } We need to handle all types that are supported in WebAssembly.Global (e.g. funcref). > Source/JavaScriptCore/wasm/js/WebAssemblyGlobalPrototype.cpp:90 > + return JSValue::encode(global->type(globalObject)); Use RELEASE_AND_RETURN(throwScope, JSValue::encode(global->type(globalObject))); > Source/JavaScriptCore/wasm/js/WebAssemblyMemoryPrototype.cpp:112 > + JSObject* memoryType = memory->type(globalObject); > + RETURN_IF_EXCEPTION(throwScope, { }); > + > + RELEASE_AND_RETURN(throwScope, JSValue::encode(memoryType)); Do, RELEASE_AND_RETURN(throwScope, JSValue::encode(memory->type(globalObject))); > Source/JavaScriptCore/wasm/js/WebAssemblyTablePrototype.cpp:178 > + JSObject* tableType = table->type(globalObject); > + return JSValue::encode(tableType); Do RELEASE_AND_RETURN(throwScope, JSValue::encode(table->type(globalObject)));
Radar WebKit Bug Importer
Comment 4 2021-03-04 04:29:14 PST
jtallon
Comment 5 2021-03-11 06:55:17 PST
jtallon
Comment 6 2021-03-16 07:24:28 PDT
jtallon
Comment 7 2021-03-16 09:41:05 PDT
jtallon
Comment 8 2021-03-16 23:40:23 PDT
This is ready for review. I saw that some windows tests are failing but taking a look at the crashed test I don't think it's related to my patch.
Yusuke Suzuki
Comment 9 2021-03-17 00:36:48 PDT
(In reply to jtallon from comment #8) > This is ready for review. I saw that some windows tests are failing but > taking a look at the crashed test I don't think it's related to my patch. Could you set r? for the patch requesting the review?
Caio Lima
Comment 10 2021-03-17 05:39:43 PDT
Comment on attachment 423340 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=423340&action=review > Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.cpp:139 > + JSObject* result = constructEmptyObject(globalObject, globalObject->objectPrototype(), 2); We are setting `inlineCapacity` to 2 here, but there are cases where we will potentially have 3 properties. This will make such object allocate a butterfly when we have the third property, increasing the amount of memory we use for this object, and slowing down the access of such property (because it will be stored inside the butterfly). Since `maximum` property is conditional, I think we could move the creation of `result` after we know if it will be included or not. > Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.cpp:133 > + JSObject* result = constructEmptyObject(globalObject, globalObject->objectPrototype(), 3); Ditto here. But in this case we are setting 3 while we don't know if `maximum` is going to be present. In such situation, we are allocating some space that might be useless.
jtallon
Comment 11 2021-03-18 05:19:40 PDT
Caio Lima
Comment 12 2021-03-18 06:54:45 PDT
Comment on attachment 423589 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=423589&action=review > Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.cpp:143 > + auto maximum = m_table->maximum(); I have a legit question. Is there any reason why `JSWebAssemblyMemory::maximum` can throw, but `JSWebAssemblyTable::maximum` doesn't?
Yusuke Suzuki
Comment 13 2021-03-18 10:28:36 PDT
Comment on attachment 423589 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=423589&action=review > Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.cpp:140 > + RETURN_IF_EXCEPTION(throwScope, { }); Yes, this will not throw an error. Let's remove it. > Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.cpp:143 > + RETURN_IF_EXCEPTION(throwScope, { }); Ditto.
jtallon
Comment 14 2021-03-26 01:55:46 PDT
jtallon
Comment 15 2021-03-29 09:14:47 PDT
jtallon
Comment 16 2021-03-30 01:46:25 PDT
Yusuke Suzuki
Comment 17 2021-03-31 01:08:48 PDT
Comment on attachment 424625 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=424625&action=review r=me with comments > Source/JavaScriptCore/wasm/js/JSWebAssemblyGlobal.cpp:96 > + result->putDirect(vm, Identifier::fromString(vm, "mutable"), jsBoolean(isMutable)); Use result->putDirect(vm, Identifier::fromString(vm, "mutable"), jsBoolean(m_global->mutability() == Wasm::GlobalInformation::Mutable)); > Source/JavaScriptCore/wasm/js/JSWebAssemblyGlobal.cpp:98 > + Wasm::Type value = m_global->type(); valueType would be better. > Source/JavaScriptCore/wasm/js/JSWebAssemblyGlobal.cpp:99 > + JSString* valueStr = nullptr; Use `valueString`. > Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.cpp:154 > + Wasm::MemorySharingMode shared = m_memory->sharingMode(); > + if (shared == Wasm::MemorySharingMode::Default) > + result->putDirect(vm, Identifier::fromString(vm, "shared"), jsBoolean(false)); > + else > + result->putDirect(vm, Identifier::fromString(vm, "shared"), jsBoolean(true)); Make it, result->putDirect(vm, Identifier::fromString(vm, "shared"), jsBoolean(m_memory->sharingMode() == Wasm::MemorySharingMode::Shared)); > Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.cpp:134 > + JSString* elementStr = nullptr; Use `elementString` instead. We like non-abbreviated names. > Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.cpp:138 > + elementStr = jsNontrivialString(vm, "externref"); Let's make it switch to list things in a readable way. 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(); break; }
jtallon
Comment 18 2021-03-31 05:35:35 PDT
Yusuke Suzuki
Comment 19 2021-04-02 14:05:16 PDT
Comment on attachment 424758 [details] Patch r=me, nice!
EWS
Comment 20 2021-04-02 14:10:34 PDT
Committed r275438: <https://commits.webkit.org/r275438> All reviewed patches have been landed. Closing bug and clearing flags on attachment 424758 [details].
Note You need to log in before you can comment on or make changes to this bug.