MCPcopy Create free account
hub / github.com/Botloader/botloader / create_isolate

Method create_isolate

components/vm/src/vm.rs:146–199  ·  view source on GitHub ↗
(
        extension_factory: &ExtensionFactory,
        module_manager: Rc<ModuleManager>,
        script_load_states: ScriptsStateStoreHandle,
        shutdown_handle: VmShutdownHandle,
    )

Source from the content-addressed store, hash-verified

144 }
145
146 fn create_isolate(
147 extension_factory: &ExtensionFactory,
148 module_manager: Rc<ModuleManager>,
149 script_load_states: ScriptsStateStoreHandle,
150 shutdown_handle: VmShutdownHandle,
151 ) -> JsRuntime {
152 let mut extensions = extension_factory();
153 let cloned_load_states = script_load_states.clone();
154
155 extensions.insert(
156 0,
157 bl_core::init_ops_and_esm(crate::BlCoreOptions { cloned_load_states }),
158 );
159
160 let options = RuntimeOptions {
161 extensions,
162 module_loader: Some(module_manager),
163 get_error_class_fn: Some(&|err| {
164 deno_core::error::get_custom_error_class(err).unwrap_or("Error")
165 }),
166 // yeah i have no idea what these values needs to be aligned to, but this seems to work so whatever
167 // if it breaks when you update deno or v8 try different values until it works, if only they'd document the alignment requirements somewhere...
168 create_params: Some(
169 CreateParams::default()
170 .heap_limits(512 * 1024, 50 * 1024 * 1024)
171 .allow_atomics_wait(false),
172 ),
173 startup_snapshot: Some(crate::BOTLOADER_CORE_SNAPSHOT),
174 // js_error_create_fn: Some(create_err_fn),
175 source_map_getter: Some(Rc::new(ScriptStateStoreWrapper(script_load_states))),
176 ..Default::default()
177 };
178
179 let another_handle = shutdown_handle.clone();
180
181 let mut rt = JsRuntime::new(options);
182 {
183 let op_state = rt.op_state();
184 op_state.borrow_mut().put(another_handle);
185 }
186 rt.add_near_heap_limit_callback(move |current, initial| {
187 info!(
188 "near heap limit: current: {}, initial: {}",
189 current, initial
190 );
191 shutdown_handle.shutdown_vm(ShutdownReason::OutOfMemory, true);
192 if current != initial {
193 current
194 } else {
195 current + initial
196 }
197 });
198 rt
199 }
200
201 fn emit_isolate_handle(&mut self) {
202 let handle = self.runtime.v8_isolate().thread_safe_handle();

Callers

nothing calls this directly

Calls 3

putMethod · 0.80
shutdown_vmMethod · 0.80

Tested by

no test coverage detected