[WASM-References] Rename anyfunc to funcref
https://bugs.webkit.org/show_bug.cgi?id=198983

Reviewed by Yusuke Suzuki.

JSTests:

* wasm/function-tests/basic-element.js:
* wasm/function-tests/context-switch.js:
(import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.makeInstance):
(makeInstance):
(assert.eq.makeInstance):
* wasm/function-tests/exceptions.js:
(import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.makeInstance):
* wasm/function-tests/grow-memory-2.js:
(assert.eq.instance.exports.foo):
* wasm/function-tests/nameSection.js:
(const.compile):
* wasm/function-tests/stack-overflow.js:
(import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.makeInstance):
(assertOverflows.makeInstance):
* wasm/function-tests/table-basic-2.js:
(import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.makeInstance):
* wasm/function-tests/table-basic.js:
(import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.makeInstance):
* wasm/function-tests/trap-from-start-async.js:
* wasm/function-tests/trap-from-start.js:
* wasm/js-api/Module.exports.js:
(assert.truthy):
* wasm/js-api/Module.imports.js:
(assert.truthy):
* wasm/js-api/call-indirect.js:
(const.oneTable):
(const.multiTable):
(multiTable.const.makeTable):
(multiTable):
(multiTable.Polyphic2Import):
(multiTable.VirtualImport):
* wasm/js-api/element-data.js:
* wasm/js-api/element.js:
(assert.throws.new.WebAssembly.Module.builder.WebAssembly):
(assert.throws):
(badInstantiation.makeModule):
(badInstantiation.test):
(badInstantiation):
* wasm/js-api/extension-MemoryMode.js:
* wasm/js-api/table.js:
(new.WebAssembly.Module):
(assert.throws):
(assertBadTableImport):
(assert.throws.WebAssembly.Table.prototype.grow):
(new.WebAssembly.Table):
(assertBadTable):
(assert.truthy):
* wasm/js-api/test_basic_api.js:
(const.c.in.constructorProperties.switch):
* wasm/js-api/unique-signature.js:
(CallIndirectWithDuplicateSignatures):
* wasm/js-api/wrapper-function.js:
* wasm/modules/table.wat:
* wasm/modules/wasm-imports-js-re-exports-wasm-exports/imports.wat:
* wasm/modules/wasm-imports-js-re-exports-wasm-exports/sum.wat:
* wasm/modules/wasm-imports-wasm-exports/imports.wat:
* wasm/modules/wasm-imports-wasm-exports/sum.wat:
* wasm/references/anyref_table.js:
* wasm/references/anyref_table_import.js:
(doSet):
(assert.throws):
* wasm/references/func_ref.js:
(makeFuncrefIdent):
(assert.eq.instance.exports.fix):
(GetLocal.0.I32Const.0.TableSet.0.End.End.WebAssembly.assert.throws):
(GetLocal.0.I32Const.0.TableSet.0.End.End.WebAssembly):
(let.importedFun.of):
(makeAnyfuncIdent): Deleted.
(makeAnyfuncIdent.fun): Deleted.
* wasm/references/multitable.js:
(assert.eq):
(assert.throws):
* wasm/references/table_misc.js:
(GetLocal.0.TableFill.0.End.End.WebAssembly):
* wasm/references/validation.js:
(assert.throws.new.WebAssembly.Module.bin):
(assert.throws):
* wasm/spec-harness/index.js:
* wasm/spec-harness/wasm-constants.js:
* wasm/spec-harness/wasm-module-builder.js:
(WasmModuleBuilder.prototype.toArray):
* wasm/spec-harness/wast.js:
(elem_type):
(string_of_elem_type):
(string_of_table_type):
* wasm/spec-tests/jsapi.js:
* wasm/stress/wasm-table-grow-initialize.js:
* wasm/wasm.json:

Source/JavaScriptCore:

Anyfunc should become funcref since it was renamed in the spec. We should also support the string 'anyfunc' in the table constructor since this is
the only non-binary-format place where it is exposed to users.

* wasm/WasmAirIRGenerator.cpp:
(JSC::Wasm::AirIRGenerator::gFuncref):
(JSC::Wasm::AirIRGenerator::tmpForType):
(JSC::Wasm::AirIRGenerator::emitCCall):
(JSC::Wasm::AirIRGenerator::moveOpForValueType):
(JSC::Wasm::AirIRGenerator::AirIRGenerator):
(JSC::Wasm::AirIRGenerator::addLocal):
(JSC::Wasm::AirIRGenerator::addConstant):
(JSC::Wasm::AirIRGenerator::addRefFunc):
(JSC::Wasm::AirIRGenerator::addReturn):
(JSC::Wasm::AirIRGenerator::gAnyfunc): Deleted.
* wasm/WasmCallingConvention.h:
(JSC::Wasm::CallingConventionAir::marshallArgument const):
(JSC::Wasm::CallingConventionAir::setupCall const):
* wasm/WasmExceptionType.h:
* wasm/WasmFormat.h:
(JSC::Wasm::isValueType):
(JSC::Wasm::isSubtype):
(JSC::Wasm::TableInformation::wasmType const):
* wasm/WasmFunctionParser.h:
(JSC::Wasm::FunctionParser<Context>::parseExpression):
* wasm/WasmSectionParser.cpp:
(JSC::Wasm::SectionParser::parseTableHelper):
(JSC::Wasm::SectionParser::parseElement):
(JSC::Wasm::SectionParser::parseInitExpr):
* wasm/WasmValidate.cpp:
(JSC::Wasm::Validate::addRefFunc):
* wasm/js/JSToWasm.cpp:
(JSC::Wasm::createJSToWasmWrapper):
* wasm/js/WasmToJS.cpp:
(JSC::Wasm::wasmToJS):
* wasm/js/WebAssemblyFunction.cpp:
(JSC::callWebAssemblyFunction):
(JSC::WebAssemblyFunction::jsCallEntrypointSlow):
* wasm/js/WebAssemblyModuleRecord.cpp:
(JSC::WebAssemblyModuleRecord::link):
* wasm/js/WebAssemblyTableConstructor.cpp:
(JSC::constructJSWebAssemblyTable):
* wasm/wasm.json:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@246589 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/JSTests/wasm/js-api/Module.exports.js b/JSTests/wasm/js-api/Module.exports.js
index 76e3fd3..777fd06 100644
--- a/JSTests/wasm/js-api/Module.exports.js
+++ b/JSTests/wasm/js-api/Module.exports.js
@@ -17,7 +17,7 @@
             .Type().End()
             .Function().End()
             .Table()
-                .Table({initial: 20, maximum: 30, element: "anyfunc"})
+                .Table({initial: 20, maximum: 30, element: "funcref"})
             .End()
             .Memory().InitialMaxPages(1, 1).End()
             .Global().I32(42, "immutable").End()
diff --git a/JSTests/wasm/js-api/Module.imports.js b/JSTests/wasm/js-api/Module.imports.js
index 1fc2dd5..b991c62 100644
--- a/JSTests/wasm/js-api/Module.imports.js
+++ b/JSTests/wasm/js-api/Module.imports.js
@@ -17,7 +17,7 @@
             .Type().End()
             .Import()
                 .Function("fooFunction", "barFunction", { params: [] })
-                .Table("fooTable", "barTable", {initial: 20, element: "anyfunc"})
+                .Table("fooTable", "barTable", {initial: 20, element: "funcref"})
                 .Memory("fooMemory", "barMemory", {initial: 20})
                 .Global().I32("fooGlobal", "barGlobal", "immutable").End()
             .End()
diff --git a/JSTests/wasm/js-api/call-indirect.js b/JSTests/wasm/js-api/call-indirect.js
index 2fafcc1..1545484 100644
--- a/JSTests/wasm/js-api/call-indirect.js
+++ b/JSTests/wasm/js-api/call-indirect.js
@@ -6,7 +6,7 @@
         .Type().End()
         .Import()
             .Function("imp", "func", { params: ["i32"] })
-            .Table("imp", "table", { initial: 1, maximum: 1, element: "anyfunc"})
+            .Table("imp", "table", { initial: 1, maximum: 1, element: "funcref"})
         .End()
         .Function().End()
         .Export()
@@ -36,8 +36,8 @@
         .Type().End()
         .Import()
             .Function("imp", "func", { params: ["i32"] })
-            .Table("imp", "table0", { initial: 0, maximum: 0, element: "anyfunc"})
-            .Table("imp", "table", { initial: 1, maximum: 1, element: "anyfunc"})
+            .Table("imp", "table0", { initial: 0, maximum: 0, element: "funcref"})
+            .Table("imp", "table", { initial: 1, maximum: 1, element: "funcref"})
         .End()
         .Function().End()
         .Export()
@@ -65,7 +65,7 @@
 for (const wasmModuleWhichImportJS of [oneTable, multiTable]) {
 
 const makeTable = () => {
-    return new WebAssembly.Table({initial: 1, maximum: 1, element: "anyfunc"});
+    return new WebAssembly.Table({initial: 1, maximum: 1, element: "funcref"});
 };
 
 (function MonomorphicImport() {
@@ -73,7 +73,7 @@
     const counterSetter = v => counter = v;
     const table = makeTable();
     const module = wasmModuleWhichImportJS();
-    const instance = new WebAssembly.Instance(module, { imp: { func: counterSetter, table, table0: new WebAssembly.Table({initial: 0, maximum: 0, element: "anyfunc"}) } });
+    const instance = new WebAssembly.Instance(module, { imp: { func: counterSetter, table, table0: new WebAssembly.Table({initial: 0, maximum: 0, element: "funcref"}) } });
     table.set(0, instance.exports.callFunc);
     for (let i = 0; i < 4096; ++i) {
         // Invoke this a bunch of times to make sure the IC in the wasm -> JS stub works correctly.
@@ -90,11 +90,11 @@
     const module = wasmModuleWhichImportJS();
 
     const tableA = makeTable();
-    const instanceA = new WebAssembly.Instance(module, { imp: { func: counterASetter, table: tableA, table0: new WebAssembly.Table({initial: 0, maximum: 0, element: "anyfunc"}) } });
+    const instanceA = new WebAssembly.Instance(module, { imp: { func: counterASetter, table: tableA, table0: new WebAssembly.Table({initial: 0, maximum: 0, element: "funcref"}) } });
     tableA.set(0, instanceA.exports.callFunc);
 
     const tableB = makeTable();
-    const instanceB = new WebAssembly.Instance(module, { imp: { func: counterBSetter, table: tableB, table0: new WebAssembly.Table({initial: 0, maximum: 0, element: "anyfunc"}) } });
+    const instanceB = new WebAssembly.Instance(module, { imp: { func: counterBSetter, table: tableB, table0: new WebAssembly.Table({initial: 0, maximum: 0, element: "funcref"}) } });
     tableB.set(0, instanceB.exports.callFunc);
     for (let i = 0; i < 2048; ++i) {
         instanceA.exports.changeCounter(i, 0);
@@ -126,7 +126,7 @@
     let instances = [];
     for (let i = 0; i < num; ++i) {
         let table = makeTable();
-        instances[i] = new WebAssembly.Instance(module, { imp: { func: counterSetters[i], table, table0: new WebAssembly.Table({initial: 0, maximum: 0, element: "anyfunc"}) } });
+        instances[i] = new WebAssembly.Instance(module, { imp: { func: counterSetters[i], table, table0: new WebAssembly.Table({initial: 0, maximum: 0, element: "funcref"}) } });
         table.set(0, instances[i].exports.callFunc);
     }
     for (let i = 0; i < 2048; ++i) {
diff --git a/JSTests/wasm/js-api/element-data.js b/JSTests/wasm/js-api/element-data.js
index cb43f4f..49f2867 100644
--- a/JSTests/wasm/js-api/element-data.js
+++ b/JSTests/wasm/js-api/element-data.js
@@ -10,7 +10,7 @@
         .Type().End()
         .Import()
             .Memory("imp", "memory", memoryDescription)
-            .Table("imp", "table", {element: "anyfunc", initial: 19}) // unspecified maximum.
+            .Table("imp", "table", {element: "funcref", initial: 19}) // unspecified maximum.
         .End()
         .Function().End()
         .Element()
@@ -30,7 +30,7 @@
     const bin = builder.WebAssembly().get();
     const module = new WebAssembly.Module(bin);
     const memory = new WebAssembly.Memory(memoryDescription);
-    const table = new WebAssembly.Table({element: "anyfunc", initial: 19});
+    const table = new WebAssembly.Table({element: "funcref", initial: 19});
     const imports = {
         imp: {
             memory: memory,
diff --git a/JSTests/wasm/js-api/element.js b/JSTests/wasm/js-api/element.js
index fcbe282..acf99f8 100644
--- a/JSTests/wasm/js-api/element.js
+++ b/JSTests/wasm/js-api/element.js
@@ -27,7 +27,7 @@
         .Type().End()
         .Function().End()
         .Table()
-            .Table({element: "anyfunc", initial: 20})
+            .Table({element: "funcref", initial: 20})
         .End()
         .Element()
             .Element({tableIndex: 1, offset: 0, functionIndices: [0]})
@@ -50,7 +50,7 @@
         .Type().End()
         .Function().End()
         .Table()
-            .Table({element: "anyfunc", initial: 20, maximum: 20})
+            .Table({element: "funcref", initial: 20, maximum: 20})
         .End()
         .Element()
             .Element({offset: 19, functionIndices: [0, 0]})
@@ -74,7 +74,7 @@
         .Type().End()
         .Function().End()
         .Table()
-            .Table({element: "anyfunc", initial: 20, maximum: 20})
+            .Table({element: "funcref", initial: 20, maximum: 20})
         .End()
         .Element()
             .Element({offset: 20, functionIndices: [0]})
@@ -98,7 +98,7 @@
         .Type().End()
         .Function().End()
         .Table()
-            .Table({element: "anyfunc", initial: 20, maximum: 20})
+            .Table({element: "funcref", initial: 20, maximum: 20})
         .End()
         .Element()
             .Element({offset: 0, functionIndices: [0, 0, 1]})
@@ -121,7 +121,7 @@
         const builder = new Builder()
             .Type().End()
             .Import()
-                .Table("imp", "table", {element: "anyfunc", initial: 19}) // unspecified maximum.
+                .Table("imp", "table", {element: "funcref", initial: 19}) // unspecified maximum.
             .End()
             .Function().End()
             .Element()
@@ -142,7 +142,7 @@
     }
 
     for (let i = 19; i < 19 + 5; i++) {
-        const table = new WebAssembly.Table({element: "anyfunc", initial: i});
+        const table = new WebAssembly.Table({element: "funcref", initial: i});
         badInstantiation(table, WebAssembly.LinkError, "Element is trying to set an out of bounds table index (evaluating 'new WebAssembly.Instance(module, {imp: {table: actualTable}})')");
     }
 }
@@ -152,7 +152,7 @@
         const builder = new Builder()
             .Type().End()
             .Import()
-                .Table("imp", "table", {element: "anyfunc", initial: 19}) // unspecified maximum.
+                .Table("imp", "table", {element: "funcref", initial: 19}) // unspecified maximum.
                 .Global().I32("imp", "global", "immutable").End()
             .End()
             .Function().End()
@@ -173,7 +173,7 @@
     }
 
     function test(i) {
-        const table = new WebAssembly.Table({element: "anyfunc", initial: 19});
+        const table = new WebAssembly.Table({element: "funcref", initial: 19});
         const global = i;
         const module = makeModule();
         const instance = new WebAssembly.Instance(module, {imp: {table, global}});
@@ -195,7 +195,7 @@
         const builder = new Builder()
             .Type().End()
             .Import()
-                .Table("imp", "table", {element: "anyfunc", initial: 19}) // unspecified maximum.
+                .Table("imp", "table", {element: "funcref", initial: 19}) // unspecified maximum.
                 .Global().F32("imp", "global", "immutable").End()
             .End()
             .Function().End()
diff --git a/JSTests/wasm/js-api/extension-MemoryMode.js b/JSTests/wasm/js-api/extension-MemoryMode.js
index 5608526..2f13b2c 100644
--- a/JSTests/wasm/js-api/extension-MemoryMode.js
+++ b/JSTests/wasm/js-api/extension-MemoryMode.js
@@ -18,7 +18,7 @@
 assert.throws(() => WebAssemblyMemoryMode(""), TypeError, message);
 assert.throws(() => WebAssemblyMemoryMode({}), TypeError, message);
 assert.throws(() => WebAssemblyMemoryMode(new WebAssembly.Module(emptyModuleArray)), TypeError, message);
-assert.throws(() => WebAssemblyMemoryMode(new WebAssembly.Table({initial: 1, element: "anyfunc"})), TypeError, message);
+assert.throws(() => WebAssemblyMemoryMode(new WebAssembly.Table({initial: 1, element: "funcref"})), TypeError, message);
 
 const validateMode = what => {
     const mode = WebAssemblyMemoryMode(what);
diff --git a/JSTests/wasm/js-api/table.js b/JSTests/wasm/js-api/table.js
index 1b844431..aa67d20 100644
--- a/JSTests/wasm/js-api/table.js
+++ b/JSTests/wasm/js-api/table.js
@@ -5,11 +5,11 @@
     const builder = new Builder()
         .Type().End()
         .Import()
-            .Table("imp", "table", {initial: 20, element: "anyfunc"})
+            .Table("imp", "table", {initial: 20, element: "funcref"})
         .End()
         .Function().End()
         .Table()
-            .Table({initial: 20, maximum: 30, element: "anyfunc"})
+            .Table({initial: 20, maximum: 30, element: "funcref"})
         .End()
         .Code()
         .End();
@@ -33,8 +33,8 @@
         .Type().End()
         .Function().End()
         .Table()
-            .Table({initial: 20, maximum: 30, element: "anyfunc"})
-            .Table({initial: 20, maximum: 30, element: "anyfunc"})
+            .Table({initial: 20, maximum: 30, element: "funcref"})
+            .Table({initial: 20, maximum: 30, element: "funcref"})
         .End()
         .Code()
         .End();
@@ -62,7 +62,7 @@
         .Type().End()
         .Function().End()
         .Table()
-            .Table({initial:20, element:"anyfunc"})
+            .Table({initial:20, element:"funcref"})
         .End()
         .Export()
             .Function("foo")
@@ -81,8 +81,8 @@
         .Type().End()
         .Function().End()
         .Table()
-            .Table({initial:20, element:"anyfunc"})
-            .Table({initial:20, element:"anyfunc"})
+            .Table({initial:20, element:"funcref"})
+            .Table({initial:20, element:"funcref"})
         .End()
         .Export()
             .Function("foo")
@@ -116,7 +116,7 @@
         .Type().End()
         .Function().End()
         .Table()
-            .Table({initial: 20, maximum: 30, element: "anyfunc"})
+            .Table({initial: 20, maximum: 30, element: "funcref"})
         .End()
         .Export()
             .Table("foo", 1)
@@ -153,40 +153,40 @@
 {
     let badDescriptions = [
         [{initial: 10, element: "i32"},
-         "WebAssembly.Module doesn't parse at byte 18: Table type should be anyfunc or anyref, got -1 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')",
-         "WebAssembly.Module doesn't parse at byte 26: Table type should be anyfunc or anyref, got -1 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')"],
+         "WebAssembly.Module doesn't parse at byte 18: Table type should be funcref or anyref, got -1 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')",
+         "WebAssembly.Module doesn't parse at byte 26: Table type should be funcref or anyref, got -1 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')"],
         [{initial: 10, element: "f32"},
-         "WebAssembly.Module doesn't parse at byte 18: Table type should be anyfunc or anyref, got -3 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')",
-         "WebAssembly.Module doesn't parse at byte 26: Table type should be anyfunc or anyref, got -3 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')"],
+         "WebAssembly.Module doesn't parse at byte 18: Table type should be funcref or anyref, got -3 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')",
+         "WebAssembly.Module doesn't parse at byte 26: Table type should be funcref or anyref, got -3 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')"],
         [{initial: 10, element: "f64"},
-         "WebAssembly.Module doesn't parse at byte 18: Table type should be anyfunc or anyref, got -4 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')",
-         "WebAssembly.Module doesn't parse at byte 26: Table type should be anyfunc or anyref, got -4 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')"],
+         "WebAssembly.Module doesn't parse at byte 18: Table type should be funcref or anyref, got -4 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')",
+         "WebAssembly.Module doesn't parse at byte 26: Table type should be funcref or anyref, got -4 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')"],
         [{initial: 10, element: "i64"},
-         "WebAssembly.Module doesn't parse at byte 18: Table type should be anyfunc or anyref, got -2 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')",
-         "WebAssembly.Module doesn't parse at byte 26: Table type should be anyfunc or anyref, got -2 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')"],
+         "WebAssembly.Module doesn't parse at byte 18: Table type should be funcref or anyref, got -2 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')",
+         "WebAssembly.Module doesn't parse at byte 26: Table type should be funcref or anyref, got -2 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')"],
         [{initial: 10, maximum: 20, element: "i32"},
-         "WebAssembly.Module doesn't parse at byte 18: Table type should be anyfunc or anyref, got -1 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')",
-         "WebAssembly.Module doesn't parse at byte 26: Table type should be anyfunc or anyref, got -1 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')"],
+         "WebAssembly.Module doesn't parse at byte 18: Table type should be funcref or anyref, got -1 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')",
+         "WebAssembly.Module doesn't parse at byte 26: Table type should be funcref or anyref, got -1 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')"],
         [{initial: 10, maximum: 20, element: "f32"},
-         "WebAssembly.Module doesn't parse at byte 18: Table type should be anyfunc or anyref, got -3 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')",
-         "WebAssembly.Module doesn't parse at byte 26: Table type should be anyfunc or anyref, got -3 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')"],
+         "WebAssembly.Module doesn't parse at byte 18: Table type should be funcref or anyref, got -3 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')",
+         "WebAssembly.Module doesn't parse at byte 26: Table type should be funcref or anyref, got -3 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')"],
         [{initial: 10, maximum: 20, element: "f64"},
-         "WebAssembly.Module doesn't parse at byte 18: Table type should be anyfunc or anyref, got -4 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')",
-         "WebAssembly.Module doesn't parse at byte 26: Table type should be anyfunc or anyref, got -4 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')"],
+         "WebAssembly.Module doesn't parse at byte 18: Table type should be funcref or anyref, got -4 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')",
+         "WebAssembly.Module doesn't parse at byte 26: Table type should be funcref or anyref, got -4 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')"],
         [{initial: 10, maximum: 20, element: "i64"},
-         "WebAssembly.Module doesn't parse at byte 18: Table type should be anyfunc or anyref, got -2 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')",
-         "WebAssembly.Module doesn't parse at byte 26: Table type should be anyfunc or anyref, got -2 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')"],
+         "WebAssembly.Module doesn't parse at byte 18: Table type should be funcref or anyref, got -2 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')",
+         "WebAssembly.Module doesn't parse at byte 26: Table type should be funcref or anyref, got -2 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')"],
 
-        [{initial: 10, maximum: 9, element: "anyfunc"},
+        [{initial: 10, maximum: 9, element: "funcref"},
          "WebAssembly.Module doesn't parse at byte 21: resizable limits has a initial page count of 10 which is greater than its maximum 9 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')",
          "WebAssembly.Module doesn't parse at byte 29: resizable limits has a initial page count of 10 which is greater than its maximum 9 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')"],
-        [{initial: 1, maximum: 0, element: "anyfunc"},
+        [{initial: 1, maximum: 0, element: "funcref"},
          "WebAssembly.Module doesn't parse at byte 21: resizable limits has a initial page count of 1 which is greater than its maximum 0 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')",
          "WebAssembly.Module doesn't parse at byte 29: resizable limits has a initial page count of 1 which is greater than its maximum 0 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')"],
-        [{initial: 2**32 - 1, maximum: 2**32 - 2, element: "anyfunc"},
+        [{initial: 2**32 - 1, maximum: 2**32 - 2, element: "funcref"},
          "WebAssembly.Module doesn't parse at byte 29: resizable limits has a initial page count of 4294967295 which is greater than its maximum 4294967294 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')",
          "WebAssembly.Module doesn't parse at byte 37: resizable limits has a initial page count of 4294967295 which is greater than its maximum 4294967294 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')"],
-        [{initial: 2**31, element: "anyfunc"},
+        [{initial: 2**31, element: "funcref"},
          "WebAssembly.Module doesn't parse at byte 24: Table's initial page count of 2147483648 is too big, maximum 10000000 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')",
          "WebAssembly.Module doesn't parse at byte 32: Table's initial page count of 2147483648 is too big, maximum 10000000 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')"],
     ];
@@ -201,8 +201,8 @@
     const builder = new Builder()
         .Type().End()
         .Import()
-            .Table("imp", "table", {initial: 20, element: "anyfunc"})
-            .Table("imp", "table", {initial: 20, element: "anyfunc"})
+            .Table("imp", "table", {initial: 20, element: "funcref"})
+            .Table("imp", "table", {initial: 20, element: "funcref"})
         .End()
         .Function().End()
         .Code()
@@ -226,10 +226,10 @@
     }
 
     const badTables = [
-        [{initial: 100, maximum:100, element:"anyfunc"}, new WebAssembly.Table({initial:100, element: "anyfunc"}), "Table import imp:table does not have a 'maximum' but the module requires that it does (evaluating 'new WebAssembly.Instance(module, {imp: {table}})')"],
-        [{initial: 100, maximum:100, element:"anyfunc"}, new WebAssembly.Table({initial:100, maximum:101, element: "anyfunc"}), "Imported Table imp:table 'maximum' is larger than the module's expected 'maximum' (evaluating 'new WebAssembly.Instance(module, {imp: {table}})')"],
-        [{initial: 100, element:"anyfunc"}, new WebAssembly.Table({initial:10, element: "anyfunc"}), "Table import imp:table provided an 'initial' that is too small (evaluating 'new WebAssembly.Instance(module, {imp: {table}})')"],
-        [{initial: 10, element:"anyfunc"}, new WebAssembly.Table({initial:9, element: "anyfunc"}), "Table import imp:table provided an 'initial' that is too small (evaluating 'new WebAssembly.Instance(module, {imp: {table}})')"],
+        [{initial: 100, maximum:100, element:"funcref"}, new WebAssembly.Table({initial:100, element: "funcref"}), "Table import imp:table does not have a 'maximum' but the module requires that it does (evaluating 'new WebAssembly.Instance(module, {imp: {table}})')"],
+        [{initial: 100, maximum:100, element:"funcref"}, new WebAssembly.Table({initial:100, maximum:101, element: "funcref"}), "Imported Table imp:table 'maximum' is larger than the module's expected 'maximum' (evaluating 'new WebAssembly.Instance(module, {imp: {table}})')"],
+        [{initial: 100, element:"funcref"}, new WebAssembly.Table({initial:10, element: "funcref"}), "Table import imp:table provided an 'initial' that is too small (evaluating 'new WebAssembly.Instance(module, {imp: {table}})')"],
+        [{initial: 10, element:"funcref"}, new WebAssembly.Table({initial:9, element: "funcref"}), "Table import imp:table provided an 'initial' that is too small (evaluating 'new WebAssembly.Instance(module, {imp: {table}})')"],
     ];
     for (const [d, t, m] of badTables) {
         assertBadTableInstance(d, t, m);
@@ -240,7 +240,7 @@
 
 {
     {
-        const table = new WebAssembly.Table({element: "anyfunc", initial: 20, maximum: 30});
+        const table = new WebAssembly.Table({element: "funcref", initial: 20, maximum: 30});
         assert.eq(20, table.grow(0));
         assert.eq(20, table.length);
         assert.eq(20, table.grow(1));
@@ -248,14 +248,14 @@
     }
 
     {
-        const table = new WebAssembly.Table({element: "anyfunc", initial: 20, maximum: 30});
+        const table = new WebAssembly.Table({element: "funcref", initial: 20, maximum: 30});
         assert.eq(20, table.grow(10));
         assert.eq(30, table.grow(0));
         assert.throws(() => table.grow(1), RangeError, "WebAssembly.Table.prototype.grow could not grow the table");
     }
 
     {
-        const table = new WebAssembly.Table({element: "anyfunc", initial: 20});
+        const table = new WebAssembly.Table({element: "funcref", initial: 20});
         let called = false;
         table.grow({valueOf() { called = true; return 42; }});
         assert.truthy(called);
@@ -263,14 +263,14 @@
     }
 
     {
-        const table = new WebAssembly.Table({element: "anyfunc", initial: 20});
+        const table = new WebAssembly.Table({element: "funcref", initial: 20});
         assert.throws(() => table.get(20), RangeError, "WebAssembly.Table.prototype.get expects an integer less than the length of the table");
         for (let i = 0; i < 20; i++)
             assert.eq(table.get(i), null);
     }
 
     {
-        const table = new WebAssembly.Table({element: "anyfunc", initial: 20});
+        const table = new WebAssembly.Table({element: "funcref", initial: 20});
         assert.throws(() => table.set(20, null), RangeError, "WebAssembly.Table.prototype.set expects an integer less than the length of the table");
         for (let i = 0; i < 20; i++)
             table.set(i, null);
@@ -278,7 +278,7 @@
 
     {
         // This should not throw
-        new WebAssembly.Table({initial: 2**20, maximum: 2**32 - 1, element: "anyfunc"});
+        new WebAssembly.Table({initial: 2**20, maximum: 2**32 - 1, element: "funcref"});
     }
 }
 
@@ -288,7 +288,7 @@
         const builder = new Builder()
             .Type().End()
             .Import()
-                .Table("imp", "table", {initial: 25, element: "anyfunc"})
+                .Table("imp", "table", {initial: 25, element: "funcref"})
             .End()
             .Function().End()
             .Code()
@@ -306,7 +306,7 @@
     const builder = new Builder()
         .Type().End()
         .Import()
-            .Table("imp", "table", {initial: 25, element: "anyfunc"})
+            .Table("imp", "table", {initial: 25, element: "funcref"})
         .End()
         .Function().End()
         .Export()
@@ -316,7 +316,7 @@
         .Code().End();
 
     const module = new WebAssembly.Module(builder.WebAssembly().get());
-    const table = new WebAssembly.Table({element: "anyfunc", initial: 25});
+    const table = new WebAssembly.Table({element: "funcref", initial: 25});
     const instance = new WebAssembly.Instance(module, {imp: {table}});
     assert.truthy(table === instance.exports.table);
     assert.truthy(table === instance.exports.table2);
@@ -327,7 +327,7 @@
         .Type().End()
         .Function().End()
         .Table()
-            .Table({initial: 20, maximum: 30, element: "anyfunc"})
+            .Table({initial: 20, maximum: 30, element: "funcref"})
         .End()
         .Export()
             .Table("table", 0)
@@ -347,8 +347,8 @@
         .Type().End()
         .Function().End()
         .Table()
-            .Table({initial: 0, maximum: 1, element: "anyfunc"})
-            .Table({initial: 20, maximum: 30, element: "anyfunc"})
+            .Table({initial: 0, maximum: 1, element: "funcref"})
+            .Table({initial: 20, maximum: 30, element: "funcref"})
         .End()
         .Export()
             .Table("table0", 0)
diff --git a/JSTests/wasm/js-api/test_basic_api.js b/JSTests/wasm/js-api/test_basic_api.js
index 1a2d222..2158743 100644
--- a/JSTests/wasm/js-api/test_basic_api.js
+++ b/JSTests/wasm/js-api/test_basic_api.js
@@ -93,9 +93,9 @@
         new WebAssembly.Memory({initial: 20});
         break;
     case "Table":
-        new WebAssembly.Table({initial: 20, element: "anyfunc"});
-        new WebAssembly.Table({initial: 20, maximum: 20, element: "anyfunc"});
-        new WebAssembly.Table({initial: 20, maximum: 25, element: "anyfunc"});
+        new WebAssembly.Table({initial: 20, element: "funcref"});
+        new WebAssembly.Table({initial: 20, maximum: 20, element: "funcref"});
+        new WebAssembly.Table({initial: 20, maximum: 25, element: "funcref"});
         break;
     case "CompileError":
     case "LinkError":
diff --git a/JSTests/wasm/js-api/unique-signature.js b/JSTests/wasm/js-api/unique-signature.js
index 8f5a55f..6e669e8 100644
--- a/JSTests/wasm/js-api/unique-signature.js
+++ b/JSTests/wasm/js-api/unique-signature.js
@@ -16,7 +16,7 @@
         .End()
         .Function().End()
         .Table()
-            .Table({initial: 4, maximum: 4, element: "anyfunc"})
+            .Table({initial: 4, maximum: 4, element: "funcref"})
         .End()
         .Export()
             .Function("entry")
diff --git a/JSTests/wasm/js-api/wrapper-function.js b/JSTests/wasm/js-api/wrapper-function.js
index e3bc398..c6c0320 100644
--- a/JSTests/wasm/js-api/wrapper-function.js
+++ b/JSTests/wasm/js-api/wrapper-function.js
@@ -56,7 +56,7 @@
 }
 
 {
-    const tableDescription = {element: "anyfunc", initial: 2};
+    const tableDescription = {element: "funcref", initial: 2};
     function makeInstance(type, imp) {
         const builder = new Builder()
             .Type()