Skip to content

Commit

Permalink
avm2/core: Add EventObject::http_status_event and use it
Browse files Browse the repository at this point in the history
  • Loading branch information
Lord-McSweeney authored and Lord-McSweeney committed Jan 14, 2025
1 parent 9bb1334 commit f711eaa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 45 deletions.
20 changes: 20 additions & 0 deletions core/src/avm2/object/event_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,26 @@ impl<'gc> EventObject<'gc> {
)
.unwrap()
}

pub fn http_status_event(
activation: &mut Activation<'_, 'gc>,
status: u16,
redirected: bool,
) -> Value<'gc> {
let class = activation.avm2().classes().httpstatusevent;
class
.construct(
activation,
&[
"httpStatus".into(),
false.into(),
false.into(),
status.into(),
redirected.into(),
],
)
.unwrap()
}
}

impl<'gc> TObject<'gc> for EventObject<'gc> {
Expand Down
54 changes: 9 additions & 45 deletions core/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1632,21 +1632,8 @@ impl<'gc> Loader<'gc> {

Avm2::dispatch_event(activation.context, progress_evt, target);

let http_status_evt = activation
.avm2()
.classes()
.httpstatusevent
.construct(
&mut activation,
&[
"httpStatus".into(),
false.into(),
false.into(),
status.into(),
redirected.into(),
],
)
.unwrap();
let http_status_evt =
Avm2EventObject::http_status_event(&mut activation, status, redirected);

Avm2::dispatch_event(activation.context, http_status_evt, target);

Expand All @@ -1673,21 +1660,11 @@ impl<'gc> Loader<'gc> {
} else {
(0, false)
};
let http_status_evt = activation
.avm2()
.classes()
.httpstatusevent
.construct(
&mut activation,
&[
"httpStatus".into(),
false.into(),
false.into(),
status_code.into(),
redirected.into(),
],
)
.unwrap();
let http_status_evt = Avm2EventObject::http_status_event(
&mut activation,
status_code,
redirected,
);

Avm2::dispatch_event(activation.context, http_status_evt, target);

Expand Down Expand Up @@ -2569,21 +2546,8 @@ impl<'gc> Loader<'gc> {
MovieLoaderVMData::Avm2 { loader_info, .. } => {
let mut activation = Avm2Activation::from_nothing(uc);

let http_status_evt = activation
.avm2()
.classes()
.httpstatusevent
.construct(
&mut activation,
&[
"httpStatus".into(),
false.into(),
false.into(),
status.into(),
redirected.into(),
],
)
.unwrap();
let http_status_evt =
Avm2EventObject::http_status_event(&mut activation, status, redirected);

Avm2::dispatch_event(activation.context, http_status_evt, loader_info.into());

Expand Down

0 comments on commit f711eaa

Please sign in to comment.