avm1: Avoid unnecessary calls to `search_prototype`

The signature of `search_prototype` is going to change in a following
commit.
Use `TObject::call_method` instead.
This commit is contained in:
relrelb 2021-06-25 01:04:53 +03:00 committed by Mike Welsh
parent d0763607e2
commit 09f72b880d
1 changed files with 17 additions and 29 deletions

View File

@ -6,7 +6,6 @@
//! //!
//! TODO: Could we use this for AVM2 timers as well? //! TODO: Could we use this for AVM2 timers as well?
use crate::avm1::object::search_prototype;
use crate::avm1::{Activation, ActivationIdentifier, AvmString, Object, TObject, Value}; use crate::avm1::{Activation, ActivationIdentifier, AvmString, Object, TObject, Value};
use crate::context::UpdateContext; use crate::context::UpdateContext;
use gc_arena::Collect; use gc_arena::Collect;
@ -49,10 +48,6 @@ impl<'gc> Timers<'gc> {
level0, level0,
); );
// TODO: `this` is undefined for non-method timer callbacks, but our VM
// currently doesn't allow `this` to be a Value (#843).
let undefined = Value::Undefined.coerce_to_object(&mut activation);
let mut tick_count = 0; let mut tick_count = 0;
let cur_time = activation.context.timers.cur_time; let cur_time = activation.context.timers.cur_time;
@ -88,32 +83,25 @@ impl<'gc> Timers<'gc> {
let params = timer.params.clone(); let params = timer.params.clone();
let callback = timer.callback.clone(); let callback = timer.callback.clone();
let callback = match callback { match callback {
TimerCallback::Function(f) => Some((undefined, None, f)), TimerCallback::Function(function) => {
TimerCallback::Method { this, method_name } => { // TODO: `this` is undefined for non-method timer callbacks, but our VM
// Fetch the callback method from the object. // currently doesn't allow `this` to be a Value (#843).
if let Ok((f, base_proto)) = let this = Value::Undefined.coerce_to_object(&mut activation);
search_prototype(Value::Object(this), method_name, &mut activation, this)
{
let f = f.coerce_to_object(&mut activation);
Some((this, base_proto, f))
} else {
None
}
}
};
if let Some((this, base_proto, function)) = callback {
let _ = function.call( let _ = function.call(
"[Timer Callback]".into(), "[Timer Callback]".into(),
&mut activation, &mut activation,
this, this,
base_proto, None,
&params, &params,
); );
}
TimerCallback::Method { this, method_name } => {
let _ = this.call_method(method_name, &params, &mut activation);
}
}
crate::player::Player::run_actions(&mut activation.context); crate::player::Player::run_actions(&mut activation.context);
}
let mut timer = activation.context.timers.peek_mut().unwrap(); let mut timer = activation.context.timers.peek_mut().unwrap();
if timer.is_timeout { if timer.is_timeout {