[WASM-References] Add optional default value parameter for Table.constructor, Table.grow and Table.set
https://bugs.webkit.org/show_bug.cgi?id=220323
Patch by Dmitry Bezhetskov <dbezhetskov@igalia.com> on 2021-01-08
Reviewed by Yusuke Suzuki.
JSTests:
Add tests for Table.grow, Table.set and Table ctor with optional initializing parameter.
Spec: https://webassembly.github.io/reference-types/js-api/index.html#tables.
* wasm/references/table_js_api.js: Added.
(Pelmen):
(testTableGrowForExternrefTables):
(async testTableGrowForFuncrefTables):
(testTableConstructorForExternrefTables):
(async testTableConstructorForFuncrefTables):
(async testTableSetForFuncrefTables):
Source/JavaScriptCore:
Introduce the new optional parameter "defaultValue" for Table.grow(numOfElementsToAdd, [defaultValue]).
It is used to initialize newly added table elements.
Introduce the new optional parameter "defaultValue" for Table({initial: N, element:type}, [defaultValue]).
After Table is created we append initial times defaultValue to table if it is present.
Also add type check for funcref's table for Table.grow, Table ctor and Table.set.
Spec: https://webassembly.github.io/reference-types/js-api/index.html#tables.
* wasm/WasmOperations.cpp:
(JSC::Wasm::JSC_DEFINE_JIT_OPERATION):
* wasm/WasmTable.cpp:
(JSC::Wasm::Table::grow):
* wasm/WasmTable.h:
(JSC::Wasm::Table::isFuncrefTable const):
* wasm/js/JSWebAssemblyTable.cpp:
(JSC::JSWebAssemblyTable::grow):
* wasm/js/JSWebAssemblyTable.h:
* wasm/js/WebAssemblyTableConstructor.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
* wasm/js/WebAssemblyTablePrototype.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@271303 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/JavaScriptCore/wasm/WasmTable.h b/Source/JavaScriptCore/wasm/WasmTable.h
index 580f0ef..5619874 100644
--- a/Source/JavaScriptCore/wasm/WasmTable.h
+++ b/Source/JavaScriptCore/wasm/WasmTable.h
@@ -67,6 +67,7 @@
TableElementType type() const { return m_type; }
bool isExternrefTable() const { return m_type == TableElementType::Externref; }
+ bool isFuncrefTable() const { return m_type == TableElementType::Funcref; }
FuncRefTable* asFuncrefTable();
static bool isValidLength(uint32_t length) { return length < maxTableEntries; }
@@ -75,7 +76,7 @@
void set(uint32_t, JSValue);
JSValue get(uint32_t) const;
- Optional<uint32_t> grow(uint32_t delta);
+ Optional<uint32_t> grow(uint32_t delta, JSValue defaultValue);
void copy(const Table* srcTable, uint32_t dstIndex, uint32_t srcIndex);
void visitAggregate(SlotVisitor&);