avm1: Merge avm1::Error and avm1::ExecutionError for now. It's plausible that nested inside actions we can encounter an ExecutionError, so at that point it doesn't make sense to have a separation.

This commit is contained in:
Nathan Adams 2020-06-20 22:25:21 +02:00 committed by Mike Welsh
parent e2c607c70f
commit f5da954b32
5 changed files with 18 additions and 47 deletions

View File

@ -47,7 +47,7 @@ pub mod xml_object;
#[cfg(test)]
mod tests;
use crate::avm1::error::{Error, ExecutionError};
use crate::avm1::error::Error;
use crate::avm1::listeners::SystemListener;
use crate::avm1::value::f64_to_wrapping_u32;
pub use activation::Activation;
@ -401,19 +401,12 @@ impl<'gc> Avm1<'gc> {
&mut self,
context: &mut UpdateContext<'_, 'gc, '_>,
func: F,
) -> Result<R, ExecutionError>
) -> Result<R, Error>
where
F: FnOnce(
&mut Self,
&mut Reader<'_>,
&mut UpdateContext<'_, 'gc, '_>,
) -> Result<R, ExecutionError>,
F: FnOnce(&mut Self, &mut Reader<'_>, &mut UpdateContext<'_, 'gc, '_>) -> Result<R, Error>,
{
let (frame_cell, swf_version, data, pc) = {
let frame = self
.stack_frames
.last()
.ok_or(ExecutionError::NoStackFrame)?;
let frame = self.stack_frames.last().ok_or(Error::NoStackFrame)?;
let mut frame_ref = frame.write(context.gc_context);
frame_ref.lock()?;
@ -469,7 +462,7 @@ impl<'gc> Avm1<'gc> {
pub fn run_stack_till_empty(
&mut self,
context: &mut UpdateContext<'_, 'gc, '_>,
) -> Result<(), ExecutionError> {
) -> Result<(), Error> {
while !self.stack_frames.is_empty() {
self.with_current_reader_mut(context, |this, r, context| {
this.do_next_action(context, r)
@ -492,7 +485,7 @@ impl<'gc> Avm1<'gc> {
&mut self,
context: &mut UpdateContext<'_, 'gc, '_>,
stop_frame: GcCell<'gc, Activation<'gc>>,
) -> Result<(), ExecutionError> {
) -> Result<(), Error> {
let mut stop_frame_id = None;
for (index, frame) in self.stack_frames.iter().enumerate() {
if GcCell::ptr_eq(stop_frame, *frame) {
@ -514,7 +507,7 @@ impl<'gc> Avm1<'gc> {
Ok(())
} else {
Err(ExecutionError::FrameNotOnStack)
Err(Error::FrameNotOnStack)
}
}
@ -523,7 +516,7 @@ impl<'gc> Avm1<'gc> {
&mut self,
context: &mut UpdateContext<'_, 'gc, '_>,
reader: &mut Reader<'_>,
) -> Result<(), ExecutionError> {
) -> Result<(), Error> {
let data = self.current_stack_frame().unwrap().read().data();
if reader.pos() >= (data.end - data.start) {
@ -654,7 +647,7 @@ impl<'gc> Avm1<'gc> {
};
if let Err(e) = result {
log::error!("AVM1 error: {}", e);
return Err(ExecutionError::ScriptError(e));
return Err(e);
}
} else {
//The explicit end opcode was encountered so return here

View File

@ -1,7 +1,6 @@
//! Activation records
use crate::avm1::error::Error;
use crate::avm1::error::ExecutionError;
use crate::avm1::return_value::ReturnValue;
use crate::avm1::scope::Scope;
use crate::avm1::{Avm1, Object, Value};
@ -408,9 +407,9 @@ impl<'gc> Activation<'gc> {
/// Attempts to lock the activation frame for execution.
///
/// If this frame is already executing, that is an error condition.
pub fn lock(&mut self) -> Result<(), ExecutionError> {
pub fn lock(&mut self) -> Result<(), Error> {
if self.is_executing {
return Err(ExecutionError::AlreadyExecutingFrame);
return Err(Error::AlreadyExecutingFrame);
}
self.is_executing = true;

View File

@ -4,22 +4,16 @@ use thiserror::Error;
pub enum Error {
#[error("Prototype recursion limit has been exceeded")]
PrototypeRecursionLimit,
}
#[derive(Error, Debug)]
pub enum ExecutionError {
#[error("Couldn't parse SWF")]
#[error("Couldn't parse SWF. This may or may not be a bug in Ruffle, please help us by reporting it to https://github.com/ruffle-rs/ruffle/issues and include the swf that triggered it.")]
InvalidSwf(#[from] swf::error::Error),
#[error("No stack frame to execute")]
#[error("No stack frame to execute. This is probably a bug in Ruffle, please report it to https://github.com/ruffle-rs/ruffle/issues and include the swf that triggered it.")]
NoStackFrame,
#[error("Attempted to run a frame not on the current interpreter stack")]
#[error("Attempted to run a frame not on the current interpreter stack. This is probably a bug in Ruffle, please report it to https://github.com/ruffle-rs/ruffle/issues and include the swf that triggered it.")]
FrameNotOnStack,
#[error("Attempted to execute the same frame twice")]
#[error("Attempted to execute the same frame twice. This is probably a bug in Ruffle, please report it to https://github.com/ruffle-rs/ruffle/issues and include the swf that triggered it.")]
AlreadyExecutingFrame,
#[error("Script error")]
ScriptError(#[from] Error),
}

View File

@ -2,7 +2,6 @@
use crate::avm1::activation::Activation;
use crate::avm1::error::Error;
use crate::avm1::error::ExecutionError;
use crate::avm1::{Avm1, Object, Value};
use crate::context::UpdateContext;
use gc_arena::{Collect, GcCell};
@ -95,19 +94,7 @@ impl<'gc> ReturnValue<'gc> {
match self {
Immediate(val) => Ok(val),
ResultOf(frame) => {
match avm.run_current_frame(context, frame) {
Err(ExecutionError::ScriptError(e)) => {
return Err(e);
}
Err(e) => {
log::warn!(
"Couldn't resolve value, encountered an avm1 execution error: {}",
e
);
}
_ => {}
}
avm.run_current_frame(context, frame)?;
Ok(avm.pop())
}
}

View File

@ -1,6 +1,5 @@
//! Management of async loaders
use crate::avm1::error::ExecutionError;
use crate::avm1::{Object, TObject, Value};
use crate::backend::navigator::OwnedFuture;
use crate::context::{ActionQueue, ActionType};
@ -41,7 +40,7 @@ pub enum Error {
NetworkError(#[from] std::io::Error),
#[error("Error running avm1 script: {0}")]
Avm1Error(#[from] crate::avm1::error::ExecutionError),
Avm1Error(#[from] crate::avm1::error::Error),
}
/// Holds all in-progress loads for the player.
@ -471,8 +470,7 @@ impl<'gc> Loader<'gc> {
};
for (k, v) in form_urlencoded::parse(&data) {
that.set(&k, v.into_owned().into(), avm, uc)
.map_err(|e| Error::Avm1Error(ExecutionError::ScriptError(e)))?;
that.set(&k, v.into_owned().into(), avm, uc)?;
}
Ok(())