diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2022-07-12 06:33:05 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-12 06:33:05 +0530 |
commit | 77d065e034db7ed21a0e110bbbfc5eb5287d009c (patch) | |
tree | 4f2ad3195f2f4d52b69432fcc5bf72496c0eaf6a /test_ffi/tests/test.js | |
parent | 5db16d122914336124620a5152655917e58f05a6 (diff) |
fix(ext/ffi): trampoline for fast calls (#15139)
Diffstat (limited to 'test_ffi/tests/test.js')
-rw-r--r-- | test_ffi/tests/test.js | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/test_ffi/tests/test.js b/test_ffi/tests/test.js index 94c2069c0..4e05be3ed 100644 --- a/test_ffi/tests/test.js +++ b/test_ffi/tests/test.js @@ -1,6 +1,8 @@ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // deno-lint-ignore-file +// Run using cargo test or `--v8-options=--allow-natives-syntax` + import { assertThrows } from "../../test_util/std/testing/asserts.ts"; const targetDir = Deno.execPath().replace(/[^\/\\]+$/, ""); @@ -182,8 +184,9 @@ const dylib = Deno.dlopen(libPath, { type: "pointer", }, }); +const { symbols } = dylib; -dylib.symbols.printSomething(); +symbols.printSomething(); const buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); const buffer2 = new Uint8Array([9, 10]); dylib.symbols.print_buffer(buffer, buffer.length); @@ -238,7 +241,15 @@ const before = performance.now(); await sleepNonBlocking.call(100); console.log(performance.now() - before >= 100); -console.log(dylib.symbols.add_u32(123, 456)); +const { add_u32 } = symbols; +function addU32Fast(a, b) { + return add_u32(a, b); +}; + +%PrepareFunctionForOptimization(addU32Fast); +console.log(addU32Fast(123, 456)); +%OptimizeFunctionOnNextCall(addU32Fast); +console.log(addU32Fast(123, 456)); console.log(dylib.symbols.add_i32(123, 456)); console.log(dylib.symbols.add_u64(0xffffffffn, 0xffffffffn)); @@ -448,4 +459,4 @@ After: ${postStr}`, } console.log("Correct number of resources"); -})(); +})();
\ No newline at end of file |