summaryrefslogtreecommitdiff
path: root/deps/v8/test/message/wasm-recognize-imports.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/test/message/wasm-recognize-imports.js')
-rw-r--r--deps/v8/test/message/wasm-recognize-imports.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/deps/v8/test/message/wasm-recognize-imports.js b/deps/v8/test/message/wasm-recognize-imports.js
new file mode 100644
index 0000000000..70d7e053e9
--- /dev/null
+++ b/deps/v8/test/message/wasm-recognize-imports.js
@@ -0,0 +1,45 @@
+// Copyright 2023 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: --experimental-wasm-stringref --allow-natives-syntax
+// Flags: --trace-wasm-inlining --liftoff
+
+d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
+
+let builder = new WasmModuleBuilder();
+let sig_w_w = makeSig([kWasmStringRef], [kWasmStringRef]);
+let toLowerCase = builder.addImport("m", "toLowerCase", sig_w_w);
+
+builder.addFunction('call_tolower', sig_w_w).exportFunc().addBody([
+ kExprLocalGet, 0,
+ kExprCallFunction, toLowerCase,
+]);
+
+let module = builder.toModule();
+
+let recognizable = Function.prototype.call.bind(String.prototype.toLowerCase);
+let recognizable_imports = { m: { toLowerCase: recognizable } };
+
+let instance1 = new WebAssembly.Instance(module, recognizable_imports);
+let call_tolower = instance1.exports.call_tolower;
+call_tolower("ABC");
+%WasmTierUpFunction(call_tolower);
+call_tolower("ABC");
+
+// Creating a second instance with identical imports should not cause
+// recompilation.
+console.log("Second instance.");
+let instance2 = new WebAssembly.Instance(module, recognizable_imports);
+let call_tolower2 = instance2.exports.call_tolower;
+call_tolower2("DEF");
+console.log("Still optimized: " + %IsTurboFanFunction(call_tolower2));
+
+// Creating a third instance with different imports must not reuse the
+// existing optimized code.
+console.log("Third instance.");
+let other_imports = { m: { toLowerCase: () => "foo" } };
+let instance3 = new WebAssembly.Instance(module, other_imports);
+let call_tolower3 = instance3.exports.call_tolower;
+call_tolower3("GHI");
+console.log("Still optimized: " + %IsTurboFanFunction(call_tolower3));