Skip to content
File

Blob: src/rust/jsg/modules.rs

rust26 lines
1// Copyright (c) 2026 Cloudflare, Inc.
2// Licensed under the Apache 2.0 license found in the LICENSE file or at:
3// https://opensource.org/licenses/Apache-2.0
4 
5use std::pin::Pin;
6 
7pub use ffi::ModuleType;
8 
9use crate::v8::ffi;
10 
11/// Registers a builtin module with the given specifier and module type.
12///
13/// The callback is invoked when JavaScript imports the module, receiving the isolate pointer
14/// and returning a V8 Local handle to the module's exports object.
15pub fn add_builtin(
16 registry: Pin<&mut ffi::ModuleRegistry>,
17 specifier: &str,
18 callback: fn(*mut ffi::Isolate) -> ffi::Local,
19 module_type: ModuleType,
20) {
21 // SAFETY: registry is a valid pinned ModuleRegistry; specifier and callback are valid.
22 unsafe {
23 ffi::register_add_builtin_module(registry, specifier, callback, module_type);
24 }
25}