avm1: Implement updateAfterEvent

This commit is contained in:
Mike Welsh 2020-07-08 14:33:11 -07:00
parent 8715589f50
commit 3322c2d916
5 changed files with 29 additions and 1 deletions

View File

@ -206,6 +206,17 @@ pub fn clear_interval<'a, 'gc>(
Ok(Value::Undefined)
}
pub fn update_after_event<'a, 'gc>(
_activation: &mut Activation<'_, 'gc>,
context: &mut UpdateContext<'a, 'gc, '_>,
_this: Object<'gc>,
_args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> {
*context.needs_render = true;
Ok(Value::Undefined)
}
/// This structure represents all system builtins that are used regardless of
/// whatever the hell happens to `_global`. These are, of course,
/// user-modifiable.
@ -556,6 +567,13 @@ pub fn create_globals<'gc>(
EnumSet::empty(),
Some(function_proto),
);
globals.force_set_function(
"updateAfterEvent",
update_after_event,
gc_context,
EnumSet::empty(),
Some(function_proto),
);
globals.add_property(
gc_context,

View File

@ -917,6 +917,7 @@ mod tests {
shared_objects: &mut HashMap::new(),
unbound_text_fields: &mut Vec::new(),
timers: &mut Timers::new(),
needs_render: &mut false,
};
root.post_instantiation(&mut avm, &mut context, root, None, false);

View File

@ -73,6 +73,7 @@ where
shared_objects: &mut HashMap::new(),
unbound_text_fields: &mut Vec::new(),
timers: &mut Timers::new(),
needs_render: &mut false,
};
root.post_instantiation(&mut avm, &mut context, root, None, false);
root.set_name(context.gc_context, "");

View File

@ -46,6 +46,9 @@ pub struct UpdateContext<'a, 'gc, 'gc_context> {
/// variables.
pub player_version: u8,
/// Requests a that the player re-renders after this execution (e.g. due to `updateAfterEvent`).
pub needs_render: &'a mut bool,
/// The root SWF file.
pub swf: &'a Arc<SwfMovie>,

View File

@ -551,7 +551,9 @@ impl Player {
Self::run_actions(avm, context);
});
self.is_mouse_down = is_mouse_down;
self.needs_render = needs_render;
if needs_render {
self.needs_render = true;
}
}
/// Update dragged object, if any.
@ -912,6 +914,7 @@ impl Player {
system_properties,
instance_counter,
storage,
needs_render,
) = (
self.player_version,
&self.swf,
@ -928,6 +931,7 @@ impl Player {
&mut self.system,
&mut self.instance_counter,
self.storage.deref_mut(),
&mut self.needs_render,
);
self.gc_arena.mutate(|gc_context, gc_root| {
@ -971,6 +975,7 @@ impl Player {
shared_objects,
unbound_text_fields,
timers,
needs_render,
};
let ret = f(avm, &mut update_context);