fresh/lib.rs
1// Editor library - exposes all core modules for testing
2
3// Initialize V8 platform once per process
4//
5// This is required because:
6// 1. V8 platform must be initialized before any JsRuntime instances are created
7// See: https://docs.rs/deno_core/latest/deno_core/struct.JsRuntime.html#method.init_platform
8// 2. V8 platform initialization is process-wide and cannot be done more than once
9// See: https://v8.github.io/api/head/classv8_1_1V8.html (V8::Dispose is permanent)
10// 3. Multiple Editor instances can be created sequentially (e.g., in tests) as long as
11// they share the same V8 platform initialized once at process startup
12// See: https://docs.rs/deno_core/latest/deno_core/struct.JsRuntime.html
13//
14// Without this, creating multiple Editor instances sequentially causes segfaults
15// because V8 cannot be reinitialized after disposal.
16use std::sync::Once;
17static INIT_V8: Once = Once::new();
18
19/// Initialize V8 platform exactly once per process
20/// This is called automatically when the library is loaded
21fn init_v8_platform() {
22 INIT_V8.call_once(|| {
23 deno_core::JsRuntime::init_platform(None);
24 });
25}
26
27// Call V8 initialization when library loads using .init_array section
28// This ensures initialization happens before any Editor instances are created
29#[used]
30#[link_section = ".init_array"]
31static INITIALIZER: extern "C" fn() = {
32 extern "C" fn init() {
33 init_v8_platform();
34 }
35 init
36};
37
38// Core modules at root level
39pub mod config;
40pub mod state;
41
42// Organized modules
43pub mod app;
44pub mod input;
45pub mod model;
46pub mod primitives;
47pub mod services;
48pub mod view;