MCPcopy Index your code
hub / github.com/endbasic/endbasic / safe_run_repl_loop

Method safe_run_repl_loop

web/src/lib.rs:258–357  ·  view source on GitHub ↗

Safe version of `run_repl_loop` that is able to return errors.

(self)

Source from the content-addressed store, hash-verified

256
257 /// Safe version of `run_repl_loop` that is able to return errors.
258 async fn safe_run_repl_loop(self) -> io::Result<()> {
259 let location = match web_sys::window() {
260 Some(window) => match window.location().href() {
261 Ok(href) => match Url::parse(&href) {
262 Ok(url) => url,
263 Err(e) => log_and_panic!("Failed to parse window's location href: {:?}", e),
264 },
265 Err(e) => log_and_panic!("Failed to get window's location href: {:?}", e),
266 },
267 None => log_and_panic!("Failed to get window"),
268 };
269
270 let yielder = self.yielder.clone();
271
272 let console = Rc::from(RefCell::from(self.console));
273 let mut builder = endbasic_std::MachineBuilder::default()
274 .with_console(console.clone())
275 .with_datetime(Rc::from(WebDateTime::new(yielder.clone())))
276 .with_yielder(Rc::from(RefCell::from(self.yielder.clone())))
277 .with_signals_chan(self.signals_chan);
278 let program = Rc::from(RefCell::from(endbasic_repl::editor::Editor::default()));
279 let storage = Rc::from(RefCell::from(endbasic_std::storage::Storage::default()));
280 setup_storage(&mut storage.borrow_mut());
281
282 let service =
283 Rc::from(RefCell::from(endbasic_client::CloudService::new(&self.service_url)?));
284 endbasic_client::add_all(
285 &mut builder,
286 service,
287 console.clone(),
288 storage.clone(),
289 format!("{}/", location.origin().unicode_serialization()),
290 );
291
292 let mut machine = builder
293 .make_interactive()
294 .with_program(program.clone())
295 .with_storage(storage.clone())
296 .build();
297
298 endbasic_repl::print_welcome(&mut *console.borrow_mut())?;
299
300 let mut auto_run = None;
301 for (name, value) in location.query_pairs() {
302 if name == "run" {
303 auto_run = Some(value);
304 break;
305 }
306 }
307 if let Some(auto_run) = auto_run {
308 let is_abs_path = auto_run.contains(':');
309 let path = if is_abs_path {
310 auto_run.into_owned()
311 } else {
312 match endbasic_repl::mount_cloud_share(console.clone(), storage.clone(), &auto_run)
313 {
314 Ok(path) => path,
315 Err(e) => {

Callers 1

run_repl_loopMethod · 0.80

Calls 15

parseFunction · 0.85
print_welcomeFunction · 0.85
mount_cloud_shareFunction · 0.85
run_from_storage_pathFunction · 0.85
try_load_autoexecFunction · 0.85
with_signals_chanMethod · 0.80
with_yielderMethod · 0.80
with_datetimeMethod · 0.80
with_consoleMethod · 0.80
with_storageMethod · 0.80
with_programMethod · 0.80
make_interactiveMethod · 0.80

Tested by

no test coverage detected