diff --git a/examples/wasm-test/TestImports.gd b/examples/wasm-test/TestImports.gd index fa88f7c..2f0f77f 100644 --- a/examples/wasm-test/TestImports.gd +++ b/examples/wasm-test/TestImports.gd @@ -112,6 +112,7 @@ func test_inspect(): "min": 0, "max": PAGES_MAX, "current": 0, + "import": false, } } expect_eq(inspect, expected) diff --git a/examples/wasm-test/TestMemory.gd b/examples/wasm-test/TestMemory.gd index fc94591..c72d039 100644 --- a/examples/wasm-test/TestMemory.gd +++ b/examples/wasm-test/TestMemory.gd @@ -33,6 +33,7 @@ func test_inspect_memory(): var expected = { "min": PAGE_SIZE, "max": PAGES_MAX, + "import": false, } expect_eq(inspect.get("memory"), expected) # Exported memory post-instantiation @@ -43,6 +44,7 @@ func test_inspect_memory(): "min": PAGE_SIZE, "max": PAGES_MAX, "current": PAGE_SIZE, + "import": false, } expect_eq(inspect.get("memory"), expected) diff --git a/examples/wasm-test/TestMemoryImport.gd b/examples/wasm-test/TestMemoryImport.gd index e5f1a4d..da5cbab 100644 --- a/examples/wasm-test/TestMemoryImport.gd +++ b/examples/wasm-test/TestMemoryImport.gd @@ -37,6 +37,35 @@ func test_module_memory(): expect(wasm.memory is StreamPeer) expect_empty() +func test_inspect_memory_import(): + # Imported memory pre-instantiation + var wasm = Wasm.new() + var buffer = read_file("memory-import") + var error = wasm.compile(buffer) + expect_eq(error, OK) + var inspect = wasm.inspect() + var expected = { + "min": PAGE_SIZE * 100, + "max": PAGES_MAX, + "import": true, + } + expect_eq(inspect.get("memory"), expected) + # Imported memory post-instantiation + var memory = WasmMemory.new() + error = memory.grow(100) + expect_eq(error, OK) + var imports = { "memory": memory } + error = wasm.instantiate(imports) + expect_eq(error, OK) + inspect = wasm.inspect() + expected = { + "min": PAGE_SIZE * 100, + "max": PAGES_MAX, + "current": PAGE_SIZE * 100, + "import": true, + } + expect_eq(inspect.get("memory"), expected) + func test_memory_import(): var memory = WasmMemory.new() var error = memory.grow(100) diff --git a/src/wasm.cpp b/src/wasm.cpp index 70507fc..77f18b6 100644 --- a/src/wasm.cpp +++ b/src/wasm.cpp @@ -402,7 +402,9 @@ namespace godot { dict["import_functions"] = import_func_sigs; dict["export_globals"] = export_global_sigs; dict["export_functions"] = export_func_sigs; - dict["memory"] = memory != NULL && memory->get_memory() ? memory->inspect() : get_memory_limits(module, memory_context); + Dictionary dict_memory = memory != NULL && memory->get_memory() ? memory->inspect() : get_memory_limits(module, memory_context); + if (memory_context != NULL) dict_memory["import"] = memory_context->import; + dict["memory"] = dict_memory; return dict; }