From 64d23cd941ae1c1f2ce525c4163ac15a560ae1c7 Mon Sep 17 00:00:00 2001 From: Ryan Hunt Date: Fri, 15 Jan 2021 16:54:28 +0000 Subject: [PATCH] Bug 1637430 - Add tests. r=lth Differential Revision: https://phabricator.services.mozilla.com/D74971 --- .../jit-test/tests/wasm/ref-types/ref-func.js | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/js/src/jit-test/tests/wasm/ref-types/ref-func.js b/js/src/jit-test/tests/wasm/ref-types/ref-func.js index 9fbda7e83f8b..cba653d760a3 100644 --- a/js/src/jit-test/tests/wasm/ref-types/ref-func.js +++ b/js/src/jit-test/tests/wasm/ref-types/ref-func.js @@ -242,3 +242,51 @@ for (let mutable of [true, false]) { } } } + +// Test invalid ref.func indices + +function testCodeRefFuncIndex(index) { + assertErrorMessage(() => { + new WebAssembly.Module(moduleWithSections( + [v2vSigSection, + declSection([0]), // One function + bodySection( + [funcBody( + {locals:[], + body:[ + RefFuncCode, + ...varU32(index), + DropCode + ]})]) + ])) + }, + WebAssembly.CompileError, + /(function index out of range)|(function index out of bounds)/); +} + +testCodeRefFuncIndex(1); +testCodeRefFuncIndex(2); +testCodeRefFuncIndex(10); +testCodeRefFuncIndex(1000); + +function testGlobalRefFuncIndex(index) { + assertErrorMessage(() => { + new WebAssembly.Module(moduleWithSections( + [v2vSigSection, + globalSection([ + { + valType: AnyFuncCode, + flags: 0, + initExpr: [RefFuncCode, ...varU32(index), EndCode], + } + ]) + ])) + }, + WebAssembly.CompileError, + /(function index out of range)|(function index out of bounds)/); +} + +testGlobalRefFuncIndex(1); +testGlobalRefFuncIndex(2); +testGlobalRefFuncIndex(10); +testGlobalRefFuncIndex(1000);