(&mut self, message: Cow<'static, str>)
| 283 | |
| 284 | impl<'gc> State<'gc> { |
| 285 | fn runtime_error(&mut self, message: Cow<'static, str>) -> VmError { |
| 286 | let mut error_message = String::from(message); |
| 287 | for i in (0..self.frame_count).rev() { |
| 288 | let frame = &self.frames[i]; |
| 289 | // Break loop if reach the un-initialized callframe. |
| 290 | // Call Vm::eval_function directly will reach this case, |
| 291 | // since it never init the root script. |
| 292 | if frame.ip == 0 { |
| 293 | break; |
| 294 | } |
| 295 | let function = &frame.closure.function; |
| 296 | error_message.push_str(&format!( |
| 297 | "\n[line {}] in ", |
| 298 | function.chunk.line(frame.ip - 1) |
| 299 | )); |
| 300 | let name = if let Some(name) = function.name { |
| 301 | name.to_str().unwrap() |
| 302 | } else { |
| 303 | "script" |
| 304 | }; |
| 305 | error_message.push_str(name); |
| 306 | error_message.push('\n'); |
| 307 | } |
| 308 | VmError::RuntimeError(error_message) |
| 309 | } |
| 310 | |
| 311 | fn current_frame(&mut self) -> &mut CallFrame<'gc> { |
| 312 | &mut self.frames[self.frame_count - 1] |
no test coverage detected