Skip to content

Commit 535bbb0

Browse files
Lord-McSweeneyLord-McSweeney
Lord-McSweeney
authored andcommitted
avm2: Fix define_fn_on_global hack
1 parent 47439bd commit 535bbb0

File tree

2 files changed

+11
-59
lines changed

2 files changed

+11
-59
lines changed

core/src/avm2.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -708,11 +708,17 @@ impl<'gc> Avm2<'gc> {
708708

709709
// The second script (script #1) is Toplevel.as, and includes important
710710
// builtin classes such as Namespace, QName, and XML.
711-
tunit
711+
let toplevel_script = tunit
712712
.load_script(1, &mut activation)
713713
.expect("Script should load");
714714
init_builtin_system_classes(&mut activation);
715715

716+
activation.avm2().toplevel_global_object = Some(
717+
toplevel_script
718+
.globals(activation.context)
719+
.expect("Script should load"),
720+
);
721+
716722
// The first script (script #0) is globals.as, and includes other builtin
717723
// classes that are less critical for the AVM to load.
718724
tunit

core/src/avm2/globals.rs

+4-58
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::avm2::{Avm2, Error, Multiname, Namespace, QName};
1212
use crate::string::{AvmString, WStr};
1313
use crate::tag_utils::{self, ControlFlow, SwfMovie, SwfSlice, SwfStream};
1414
use gc_arena::Collect;
15+
use ruffle_macros::istr;
1516
use std::sync::Arc;
1617
use swf::TagCode;
1718

@@ -384,25 +385,6 @@ impl<'gc> SystemClassDefs<'gc> {
384385
}
385386
}
386387

387-
/// Looks up a function defined in the script domain, and defines it on the global object.
388-
///
389-
/// This expects the looked-up value to be a function.
390-
fn define_fn_on_global<'gc>(
391-
activation: &mut Activation<'_, 'gc>,
392-
name: &'static str,
393-
script: Script<'gc>,
394-
) {
395-
let (_, global, domain) = script.init();
396-
let qname = QName::new(activation.avm2().namespaces.public_all(), name);
397-
let func = domain
398-
.get_defined_value(activation, qname)
399-
.expect("Function being defined on global should be defined in domain!");
400-
401-
Value::from(global)
402-
.init_property(&qname.into(), func, activation)
403-
.expect("Should set property");
404-
}
405-
406388
/// Add a fully-formed class object builtin to the global scope.
407389
///
408390
/// This allows the caller to pre-populate the class's prototype with dynamic
@@ -485,30 +467,14 @@ pub fn load_player_globals<'gc>(
485467
void_def,
486468
));
487469

488-
// Unfortunately we need to specify the global traits manually, at least until
489-
// all the builtin classes are defined in AS.
470+
// Unfortunately we need to specify the global traits manually
490471
let mut global_traits = Vec::new();
491472

492473
let public_ns = activation.avm2().namespaces.public_all();
493474

494475
let class_trait_list = &[
495-
(public_ns, "Object", object_i_class),
496-
(public_ns, "Class", class_i_class),
497-
];
498-
499-
// "trace" is the only builtin function not defined on the toplevel global object
500-
let function_trait_list = &[
501-
"decodeURI",
502-
"decodeURIComponent",
503-
"encodeURI",
504-
"encodeURIComponent",
505-
"escape",
506-
"unescape",
507-
"isXMLName",
508-
"isFinite",
509-
"isNaN",
510-
"parseFloat",
511-
"parseInt",
476+
(public_ns, istr!("Object"), object_i_class),
477+
(public_ns, istr!("Class"), class_i_class),
512478
];
513479

514480
for (namespace, name, class) in class_trait_list {
@@ -517,19 +483,6 @@ pub fn load_player_globals<'gc>(
517483
global_traits.push(Trait::from_class(qname, *class));
518484
}
519485

520-
for function_name in function_trait_list {
521-
let qname = QName::new(public_ns, *function_name);
522-
523-
// FIXME: These should be TraitKind::Methods, to match how they are when
524-
// defined on the AS global object, but we don't have the actual Methods
525-
// right now.
526-
global_traits.push(Trait::from_const(
527-
qname,
528-
Some(activation.avm2().multinames.function),
529-
Some(Value::Null),
530-
));
531-
}
532-
533486
// Create the builtin globals' classdef
534487
let global_classdef = global_scope::create_class(activation, global_traits);
535488

@@ -595,8 +548,6 @@ pub fn load_player_globals<'gc>(
595548

596549
globals.set_vtable(mc, global_obj_vtable);
597550

598-
activation.context.avm2.toplevel_global_object = Some(globals);
599-
600551
// Initialize the script
601552
let script = Script::empty_script(mc, globals, domain);
602553

@@ -613,11 +564,6 @@ pub fn load_player_globals<'gc>(
613564
// this call.
614565
load_playerglobal(activation, domain)?;
615566

616-
for function_name in function_trait_list {
617-
// Now copy those functions to the global object.
618-
define_fn_on_global(activation, function_name, script);
619-
}
620-
621567
Ok(())
622568
}
623569

0 commit comments

Comments
 (0)