Added: trunk/JSTests/wasm/function-references-spec-tests/call-null-ref.wast.js (0 => 289182)
--- trunk/JSTests/wasm/function-references-spec-tests/call-null-ref.wast.js (rev 0)
+++ trunk/JSTests/wasm/function-references-spec-tests/call-null-ref.wast.js 2022-02-06 22:21:55 UTC (rev 289182)
@@ -0,0 +1,18 @@
+/*
+(module
+ (type $ii (func (param i32) (result i32)))
+
+ (func (export "null") (result i32)
+ (call_ref (i32.const 1) (ref.null $ii))
+ )
+)
+
+(assert_trap (invoke "null") "null function")
+*/
+
+// call-null-ref.wast:1
+let $1 = instance("\x00\x61\x73\x6d\x01\x00\x00\x00\x01\x8a\x80\x80\x80\x00\x02\x60\x01\x7f\x01\x7f\x60\x00\x01\x7f\x03\x82\x80\x80\x80\x00\x01\x01\x07\x88\x80\x80\x80\x00\x01\x04\x6e\x75\x6c\x6c\x00\x00\x0a\x8d\x80\x80\x80\x00\x01\x87\x80\x80\x80\x00\x00\x41\x01\xd0\x00\x14\x0b");
+
+// call-null-ref.wast:9
+for (let i = 0; i < 1e4; ++i)
+ assert_trap(() => call($1, "null", []));
Modified: trunk/Source/_javascript_Core/wasm/WasmB3IRGenerator.cpp (289181 => 289182)
--- trunk/Source/_javascript_Core/wasm/WasmB3IRGenerator.cpp 2022-02-06 21:10:45 UTC (rev 289181)
+++ trunk/Source/_javascript_Core/wasm/WasmB3IRGenerator.cpp 2022-02-06 22:21:55 UTC (rev 289182)
@@ -3087,14 +3087,6 @@
// can be to the embedder for our stack check calculation.
m_maxNumJSCallArguments = std::max(m_maxNumJSCallArguments, static_cast<uint32_t>(args.size()));
- Value* jsInstanceOffset = constant(pointerType(), safeCast<int32_t>(WebAssemblyFunctionBase::offsetOfInstance()));
- Value* jsCalleeInstance = m_currentBlock->appendNew<MemoryValue>(m_proc, Load, pointerType(), origin(),
- m_currentBlock->appendNew<Value>(m_proc, Add, origin(), callee, jsInstanceOffset));
-
- Value* instanceOffset = constant(pointerType(), safeCast<int32_t>(JSWebAssemblyInstance::offsetOfInstance()));
- Value* calleeInstance = m_currentBlock->appendNew<MemoryValue>(m_proc, Load, pointerType(), origin(),
- m_currentBlock->appendNew<Value>(m_proc, Add, origin(), jsCalleeInstance, instanceOffset));
-
// Check the target reference for null.
{
CheckValue* check = m_currentBlock->appendNew<CheckValue>(m_proc, Check, origin(),
@@ -3104,6 +3096,14 @@
});
}
+ Value* jsInstanceOffset = constant(pointerType(), safeCast<int32_t>(WebAssemblyFunctionBase::offsetOfInstance()));
+ Value* jsCalleeInstance = m_currentBlock->appendNew<MemoryValue>(m_proc, Load, pointerType(), origin(),
+ m_currentBlock->appendNew<Value>(m_proc, Add, origin(), callee, jsInstanceOffset));
+
+ Value* instanceOffset = constant(pointerType(), safeCast<int32_t>(JSWebAssemblyInstance::offsetOfInstance()));
+ Value* calleeInstance = m_currentBlock->appendNew<MemoryValue>(m_proc, Load, pointerType(), origin(),
+ m_currentBlock->appendNew<Value>(m_proc, Add, origin(), jsCalleeInstance, instanceOffset));
+
Value* calleeCode = m_currentBlock->appendNew<MemoryValue>(m_proc, Load, pointerType(), origin(),
m_currentBlock->appendNew<MemoryValue>(m_proc, Load, pointerType(), origin(), callee,
safeCast<int32_t>(WebAssemblyFunctionBase::offsetOfEntrypointLoadLocation())));