-
-
Notifications
You must be signed in to change notification settings - Fork 864
/
Copy patherror.rs
51 lines (46 loc) · 1.57 KB
/
error.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use crate::avm2::activation::Activation;
pub use crate::avm2::object::error_allocator;
use crate::avm2::string::AvmString;
use crate::avm2::value::Value;
use crate::avm2::Error;
use crate::avm2::TObject;
use crate::PlayerMode;
pub fn call_handler<'gc>(
activation: &mut Activation<'_, 'gc>,
_this: Value<'gc>,
args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> {
activation
.avm2()
.classes()
.error
.construct(activation, args)
}
pub fn get_stack_trace<'gc>(
activation: &mut Activation<'_, 'gc>,
this: Value<'gc>,
_args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> {
let this = this.as_object().unwrap();
// See <https://docs.ruffle.rs/en_US/FlashPlatform/reference/actionscript/3/Error.html#getStackTrace()>
// But note that the behavior also depends on SWF version.
let stack_trace_enabled = if activation.context.player_version >= 18
&& activation.caller_movie_or_root().version() >= 18
{
// For Flash Player 11.5+ and SWF>=18, stack traces are always enabled.
true
} else {
// For Flash Player Player 11.4 and earlier, or for SWF<18, stack traces are enabled for debug only.
activation.context.player_mode == PlayerMode::Debug
};
if !stack_trace_enabled {
return Ok(Value::Null);
}
if let Some(error) = this.as_error_object() {
let call_stack = error.call_stack();
if !call_stack.is_empty() {
return Ok(AvmString::new(activation.gc(), error.display_full()?).into());
}
}
Ok(Value::Null)
}