summaryrefslogtreecommitdiff
path: root/ext/ffi/00_ffi.js
AgeCommit message (Collapse)Author
2024-09-06fix(runtime): use more null proto objects again (#25040)Kenta Moriuchi
proceed with #23921 This PR is a preparation for https://github.com/denoland/deno_lint/pull/1307 --------- Signed-off-by: Kenta Moriuchi <moriken@kimamass.com> Co-authored-by: Luca Casonato <hello@lcas.dev>
2024-09-04refactor(ext): align error messages (#25310)Ian Bull
2024-05-30BREAKING(ffi/unstable): use BigInt representation in turbocall (#23983)Aapo Alasuutari
Built ontop of #23981, this sets FFI turbocalls (Fast Call API) to use the BigInt representation.
2024-05-28BREAKING(ffi/unstable): always return u64 as bigint (#23981)Divy Srivastava
The mixed `number | bigint` representation was useful optimization for pointers. Now, pointers are represented as V8 externals. As part of the FFI stabilization effort we want to make `bigint` the only representation for `u64` and `i64`. BigInt representation performance is almost on par with mixed representation with the added benefit that its less confusing and users don't need manual checks and conversions for doing operations on the value. ``` cpu: AMD Ryzen 5 7530U with Radeon Graphics runtime: deno 1.43.6+92a8d09 (x86_64-unknown-linux-gnu) file:///home/divy/gh/ffi/main.ts benchmark time (avg) iter/s (min … max) p75 p99 p995 -------------------------------------------------------------------------- ----------------------------- nop 4.01 ns/iter 249,533,690.5 (3.97 ns … 10.8 ns) 3.97 ns 4.36 ns 9.03 ns ret bigint 7.74 ns/iter 129,127,186.8 (7.72 ns … 10.46 ns) 7.72 ns 8.11 ns 8.82 ns ret i32 7.81 ns/iter 128,087,100.5 (7.77 ns … 12.72 ns) 7.78 ns 8.57 ns 9.75 ns ret bigint (add op) 15.02 ns/iter 66,588,253.2 (14.64 ns … 24.99 ns) 14.76 ns 19.13 ns 19.44 ns ret i32 (add op) 12.02 ns/iter 83,209,131.8 (11.95 ns … 18.18 ns) 11.98 ns 13.11 ns 14.5 ns ```
2024-05-23fix(runtime): use more null proto objects (#23921)Luca Casonato
This is a primordialization effort to improve resistance against users tampering with the global `Object` prototype. --------- Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2024-01-29refactor: Use virtul ops module (#22175)Bartek Iwańczuk
Follow up to #22157. This leaves us with 4 usages of `ensureFastOps()` in `deno` itself. There's also about 150 usages of `Deno.core.ops.<op_name>` left as well.
2024-01-10refactor: use `core.ensureFastOps()` (#21888)Kenta Moriuchi
2024-01-04fix: strict type check for cross realms (#21669)Kenta Moriuchi
Deno v1.39 introduces `vm.runInNewContext`. This may cause problems when using `Object.prototype.isPrototypeOf` to check built-in types. ```js import vm from "node:vm"; const err = new Error(); const crossErr = vm.runInNewContext(`new Error()`); console.assert( !(crossErr instanceof Error) ); console.assert( Object.getPrototypeOf(err) !== Object.getPrototypeOf(crossErr) ); ``` This PR changes to check using internal slots solves them. --- current: ``` > import vm from "node:vm"; undefined > vm.runInNewContext(`new Error("message")`) Error {} > vm.runInNewContext(`new Date("2018-12-10T02:26:59.002Z")`) Date {} ``` this PR: ``` > import vm from "node:vm"; undefined > vm.runInNewContext(`new Error("message")`) Error: message at <anonymous>:1:1 > vm.runInNewContext(`new Date("2018-12-10T02:26:59.002Z")`) 2018-12-10T02:26:59.002Z ``` --------- Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2024-01-01chore: update copyright to 2024 (#21753)David Sherret
2023-12-27perf: remove opAsync (#21690)Matt Mastracci
`opAsync` requires a lookup by name on each async call. This is a mechanical translation of all opAsync calls to ensureFastOps. The `opAsync` API on Deno.core will be removed at a later time.
2023-12-07refactor: pull 'core', 'internals', 'primordials' from ES module (#21462)Bartek Iwańczuk
This commit refactors how we access "core", "internals" and "primordials" objects coming from `deno_core`, in our internal JavaScript code. Instead of capturing them from "globalThis.__bootstrap" namespace, we import them from recently added "ext:core/mod.js" file.
2023-11-09perf: remove knowledge of promise IDs from deno (#21132)Matt Mastracci
We can move all promise ID knowledge to deno_core, allowing us to better experiment with promise implementation in deno_core. `{un,}refOpPromise(promise)` is equivalent to `{un,}refOp(promise[promiseIdSymbol])`
2023-10-05chore(ext/ffi): migrate from op -> op2 for ffi (#20509)Matt Mastracci
Migrate to op2. Making a few decisions to get this across the line: - Empty slices, no matter where the come from, are null pointers. The v8 bugs (https://bugs.chromium.org/p/v8/issues/detail?id=13489) and (https://bugs.chromium.org/p/v8/issues/detail?id=13488) make passing around zero-length slice pointers too dangerous as they might be uninitialized or null data. - Offsets and lengths are `#[number] isize` and `#[number] usize` respectively -- 53 bits should be enough for anyone - Pointers are bigints. This is a u64 in the fastcall world, and can accept Integer/Int32/Number/BigInt v8 types in the slow world.
2023-05-07fix(ext/ffi): UnsafeCallback can hang with 'deno test' (#19018)Aapo Alasuutari
2023-05-02refactor(core): Use `ObjectHasOwn` instead of ↵Kenta Moriuchi
`ObjectPrototypeHasOwnProperty` (#18952) ES2022 `Object.hasOwn` can be used in snapshot, so I migrate to use it.
2023-04-14fix(core): Use safe primordials wrappers (#18687)Kenta Moriuchi
2023-04-03feat(ext/ffi): support marking symbols as optional (#18529)Dj
2023-04-02chore: Turn back on dlintPreferPrimordials (#17715)Kenta Moriuchi
Closes #17709
2023-04-01fix(ext/ffi): crash when same reference struct is used in two fields (#18531)Dj
fix #17482
2023-03-08refactor: rename InternalModuleLoader to ExtModuleLoader, use ext: scheme ↵Bartek Iwańczuk
for snapshotted modules (#18041) This commit renames "deno_core::InternalModuleLoader" to "ExtModuleLoader" and changes the specifiers used by the modules loaded from this loader to "ext:". "internal:" scheme was really ambiguous and it's more characters than "ext:", which should result in slightly smaller snapshot size. Closes https://github.com/denoland/deno/issues/18020
2023-03-05refactor: move "pathFromURL" to deno_web extension (#18037)Bartek Iwańczuk
This API is required by several extensions like "ext/node", "ext/ffi" and also FS APIs that we want to move to a separate crate. Because of that "pathFromURL" API was moved to "deno_web" extension so other extension crates can rely on it.
2023-03-05feat(ext/ffi): Make External pointers keep reference to V8 buffer (#17955)Aapo Alasuutari
2023-02-22fix(ext/ffi): Fix re-ref'ing UnsafeCallback (#17704)Aapo Alasuutari
2023-02-22feat(ext/ffi): Replace pointer integers with v8::External objects (#16889)Aapo Alasuutari
2023-02-07refactor: Use ES modules for internal runtime code (#17648)Leo Kettmeir
This PR refactors all internal js files (except core) to be written as ES modules. `__bootstrap`has been mostly replaced with static imports in form in `internal:[path to file from repo root]`. To specify if files are ESM, an `esm` method has been added to `Extension`, similar to the `js` method. A new ModuleLoader called `InternalModuleLoader` has been added to enable the loading of internal specifiers, which is used in all situations except when a snapshot is only loaded, and not a new one is created from it. --------- Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2023-01-16chore: update dlint to v0.37.0 for GitHub Actions (#17295)Kenta Moriuchi
Updated third_party dlint to v0.37.0 for GitHub Actions. This PR includes following changes: * fix(prefer-primordials): Stop using array pattern assignments * fix(prefer-primordials): Stop using global intrinsics except for `SharedArrayBuffer` * feat(guard-for-in): Apply new guard-for-in rule
2023-01-15fix(ext/ffi): use SafeMap in getTypeSizeAndAlignment (#17305)Garcia
2023-01-08feat(ext/ffi): structs by value (#15060)Dj
Adds support for passing and returning structs as buffers to FFI. This does not implement fastapi support for structs. Needed for certain system APIs such as AppKit on macOS.
2023-01-02chore: update copyright year to 2023 (#17247)David Sherret
Yearly tradition of creating extra noise in git.
2022-12-20chore: Update dlint (#17031)Kenta Moriuchi
Introduces `SafeSetIterator` and `SafeMapIterator` to primordials
2022-10-20feat(ext/ffi): Make op_ffi_ptr_of fast (#16297)Aapo Alasuutari
Makes `op_ffi_ptr_of` fast. One of the tests changed from printing `false` to `true` as the fast `&[u8]` slice path creates the slice with a null pointer. Thus the `op_ffi_ptr_of` will now return a null pointer value whereas previously it returned a dangling pointer value.
2022-10-20perf(ext/ffi): Fast UnsafePointerView read functions (#16351)Aapo Alasuutari
This PR makes pointer read methods of `Deno.UnsafePointerView` Fast API compliant, with the exception of `getCString` which cannot be made fast with current V8 Fast API.
2022-10-15fix(ext/ffi): Fix UnsafeCallback ref'ing making Deno enter a live-loop (#16216)Aapo Alasuutari
Fixes #15136 Currently `UnsafeCallback` class' `ref()` and `unref()` methods rely on the `event_loop_middleware` implementation in core. If even a single `UnsafeCallback` is ref'ed, then the FFI event loop middleware will always return `true` to signify that there may still be more work for the event loop to do. The middleware handling in core does not wait a moment to check again, but will instead synchronously directly re-poll the event loop and middlewares for more work. This becomes a live-loop. This PR introduces a `Future` implementation for the `CallbackInfo` struct that acts as the intermediary data storage between an `UnsafeCallback` and the `libffi` C callback. Ref'ing a callback now means calling an async op that binds to the `CallbackInfo` Future and only resolves once the callback is unref'ed. The `libffi` C callback will call the waker of this Future when it fires to make sure that the main thread wakes up to receive the callback.
2022-10-13fix(ext/ffi): Invalid 'function' return type check logic, remove U32x2 as ↵Aapo Alasuutari
unnecessary (#16259) The return type checking for `"function"` type FFI values was incorrect and presumed that functions were still being registered as objects containing a "function" key. While here, I also removed the whole return type checking logic as it was needed for optionally creating BigInts on return when needed, but serde_v8 does this automatically now (I think).
2022-09-05feat(ext/ffi): Support bool FFI type (#15754)Aapo Alasuutari
2022-08-23BREAKING(ext/ffi): specialized `buffer` type (#15518)Divy Srivastava
2022-08-11perf(ops): Monomorphic sync op calls (#15337)Aapo Alasuutari
Welcome to better optimised op calls! Currently opSync is called with parameters of every type and count. This most definitely makes the call megamorphic. Additionally, it seems that spread params leads to V8 not being able to optimise the calls quite as well (apparently Fast Calls cannot be used with spread params). Monomorphising op calls should lead to some improved performance. Now that unwrapping of sync ops results is done on Rust side, this is pretty simple: ``` opSync("op_foo", param1, param2); // -> turns to ops.op_foo(param1, param2); ``` This means sync op calls are now just directly calling the native binding function. When V8 Fast API Calls are enabled, this will enable those to be called on the optimised path. Monomorphising async ops likely requires using callbacks and is left as an exercise to the reader.
2022-08-05feat(ext/ffi): Add static method variants to Deno.UnsafePointerView (#15146)Aapo Alasuutari
2022-07-28perf(ext/ffi): use fast api calls for 64bit return types (#15313)Divy Srivastava
2022-07-24feat(ext/ffi): Safe number pointers (#15173)Aapo Alasuutari
2022-07-23feat(ext/ffi): Add support to get ArrayBuffers from UnsafePointerView (#15143)Aapo Alasuutari
2022-07-22perf(ext/ffi): Optimise common pointer related APIs (#15144)Aapo Alasuutari
2022-07-09fix(ext/ffi): Avoid keeping JsRuntimeState RefCell borrowed for event loop ↵Aapo Alasuutari
middleware calls (#15116)
2022-06-29perf(ext/ffi): optimize synchronous calls (#14945)Divy Srivastava
2022-06-28feat(ext/ffi): Thread safe callbacks (#14942)Aapo Alasuutari
2022-06-20BREAKING(ext/ffi): Remove `Deno.UnsafePointer` indirection (#14915)Divy Srivastava
2022-06-20feat(ext/ffi): Callbacks (#14663)Aapo Alasuutari
This commit adds support for unstable FFI callbacks. A callback is registered using the `Deno.UnsafeCallback` API. The backing memory for the callback can be disposed of using `Deno.UnsafeCallback#close`. It is not safe to pass the callback after calling close. Callbacks from other than the isolate thread are not supported. Co-authored-by: Divy Srivastava <dj.srivastava23@gmail.com> Co-authored-by: Bert Belder <bertbelder@gmail.com>
2022-06-08feat(ext/ffi): support passing and returning bigints (#14523)Elias Sjögreen
2022-02-18feat(ext/ffi): Support read only global statics (#13662)Aapo Alasuutari
2022-02-01refactor: primordials for instanceof (#13527)Bartek Iwańczuk