Skip to content

Commit ab71370

Browse files
Toad06Herschel
authored andcommitted
avm1: Minimal implementation of XML.getBytesTotal and XML.getBytesLoaded
1 parent 44c9e30 commit ab71370

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

core/src/avm1/globals/xml.rs

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::avm1::activation::Activation;
44
use crate::avm1::error::Error;
55
use crate::avm1::function::ExecutionReason;
66
use crate::avm1::object::xml_object::XmlObject;
7+
use crate::avm1::property::Attribute;
78
use crate::avm1::property_decl::{define_properties_on, Declaration};
89
use crate::avm1::{Object, TObject, Value};
910
use crate::avm_warn;
@@ -21,6 +22,8 @@ const PROTO_DECLS: &[Declaration] = declare_properties! {
2122
"status" => property(status);
2223
"createElement" => method(create_element);
2324
"createTextNode" => method(create_text_node);
25+
"getBytesLoaded" => method(get_bytes_loaded);
26+
"getBytesTotal" => method(get_bytes_total);
2427
"parseXML" => method(parse_xml);
2528
"load" => method(load);
2629
"sendAndLoad" => method(send_and_load);
@@ -85,6 +88,24 @@ fn create_text_node<'gc>(
8588
Ok(Value::Undefined)
8689
}
8790

91+
fn get_bytes_loaded<'gc>(
92+
activation: &mut Activation<'_, 'gc>,
93+
this: Object<'gc>,
94+
_args: &[Value<'gc>],
95+
) -> Result<Value<'gc>, Error<'gc>> {
96+
// Forwards to undocumented property on the object.
97+
this.get("_bytesLoaded", activation)
98+
}
99+
100+
fn get_bytes_total<'gc>(
101+
activation: &mut Activation<'_, 'gc>,
102+
this: Object<'gc>,
103+
_args: &[Value<'gc>],
104+
) -> Result<Value<'gc>, Error<'gc>> {
105+
// Forwards to undocumented property on the object.
106+
this.get("_bytesTotal", activation)
107+
}
108+
88109
fn parse_xml<'gc>(
89110
activation: &mut Activation<'_, 'gc>,
90111
this: Object<'gc>,
@@ -272,7 +293,39 @@ fn spawn_xml_fetch<'gc>(
272293
Request::get(url)
273294
};
274295

275-
this.set("loaded", false.into(), activation)?;
296+
// Create hidden properties on object.
297+
if !this.has_property(activation, "_bytesLoaded".into()) {
298+
this.define_value(
299+
activation.context.gc_context,
300+
"_bytesLoaded",
301+
0.into(),
302+
Attribute::DONT_DELETE | Attribute::DONT_ENUM,
303+
);
304+
} else {
305+
this.set("_bytesLoaded", 0.into(), activation)?;
306+
}
307+
308+
if !this.has_property(activation, "_bytesTotal".into()) {
309+
this.define_value(
310+
activation.context.gc_context,
311+
"_bytesTotal",
312+
Value::Undefined,
313+
Attribute::DONT_DELETE | Attribute::DONT_ENUM,
314+
);
315+
} else {
316+
this.set("_bytesTotal", Value::Undefined, activation)?;
317+
}
318+
319+
if !this.has_property(activation, "loaded".into()) {
320+
this.define_value(
321+
activation.context.gc_context,
322+
"loaded",
323+
false.into(),
324+
Attribute::DONT_DELETE | Attribute::DONT_ENUM,
325+
);
326+
} else {
327+
this.set("loaded", false.into(), activation)?;
328+
}
276329

277330
let future = activation.context.load_manager.load_form_into_load_vars(
278331
activation.context.player.clone(),

0 commit comments

Comments
 (0)