bun_runtime/node_tls_wrap.rs
1// @trace REQ-ENG-007 [api:node _tls_wrap module]
2//
3// Internal TLS wrap module. In Bun, `_tls_wrap` is an alias for `node:tls`
4// (see HardcodedModule.zig: `.{ "_tls_wrap", .{ .path = "node:tls" ... } }`).
5//
6// Bao replicates this: look up the already-registered `builtin:tls` module
7// from gc_store and cache it under the `_tls_wrap` key. This ensures
8// `require("_tls_wrap")` returns the same object as `require("tls")`.
9
10use mozjs::jsapi::*;
11use mozjs::rooted;
12
13/// Install _tls_wrap module — alias for the `tls` module.
14pub fn install(cx: &mut mozjs::context::JSContext) {
15 let cache_key = "builtin:_tls_wrap";
16 // Guard: never clobber a natively-implemented module.
17 if let Some(existing) = crate::gc_store::gc_store_get(unsafe { cx.raw_cx() }, cache_key) {
18 if !existing.is_null() {
19 return;
20 }
21 }
22
23 // Look up the tls module (already installed by node_tls::install)
24 let tls_key = "builtin:tls";
25 let tls_obj = match crate::gc_store::gc_store_get(unsafe { cx.raw_cx() }, tls_key) {
26 Some(obj) if !obj.is_null() => obj,
27 _ => return, // tls not yet registered; skip (will be available via stub fallback)
28 };
29
30 crate::require::cache_builtin(cx, "_tls_wrap", tls_obj);
31}