summaryrefslogtreecommitdiff
path: root/deps/v8/test/mjsunit/wasm/anyfunc.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/test/mjsunit/wasm/anyfunc.js')
-rw-r--r--deps/v8/test/mjsunit/wasm/anyfunc.js43
1 files changed, 43 insertions, 0 deletions
diff --git a/deps/v8/test/mjsunit/wasm/anyfunc.js b/deps/v8/test/mjsunit/wasm/anyfunc.js
new file mode 100644
index 0000000000..30faef12a7
--- /dev/null
+++ b/deps/v8/test/mjsunit/wasm/anyfunc.js
@@ -0,0 +1,43 @@
+// Copyright 2019 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --expose-wasm --experimental-wasm-anyref --expose-gc
+
+load("test/mjsunit/wasm/wasm-constants.js");
+load("test/mjsunit/wasm/wasm-module-builder.js");
+
+(function testAnyRefIdentityFunction() {
+ print(arguments.callee.name);
+ const builder = new WasmModuleBuilder();
+ builder.addFunction('main', kSig_a_a)
+ .addBody([kExprGetLocal, 0])
+ .exportFunc();
+
+
+ const instance = builder.instantiate();
+
+ assertThrows(() => instance.exports.main(print), TypeError);
+ assertThrows(() => instance.exports.main({'hello' : 'world'}), TypeError);
+ assertSame(
+ instance.exports.main, instance.exports.main(instance.exports.main));
+})();
+
+(function testPassAnyRefToImportedFunction() {
+ print(arguments.callee.name);
+ const builder = new WasmModuleBuilder();
+ const sig_index = builder.addType(kSig_v_a);
+ const imp_index = builder.addImport("q", "func", sig_index);
+ builder.addFunction('main', sig_index)
+ .addBody([kExprGetLocal, 0,
+ kExprCallFunction, imp_index])
+ .exportFunc();
+
+ const main = builder.instantiate({q: {func: checkFunction}}).exports.main;
+
+ function checkFunction(value) {
+ assertSame(main, value);
+ }
+
+ main(main);
+})();