Safe version of `run_repl_loop` that is able to return errors.
(self)
| 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) => { |
no test coverage detected