Skip to content

Commit b388929

Browse files
avm2: Remove uses of more static strings
1. We no longer create a static AvmString to compare broadcast event types to to ensure they're a whitelisted event. 2. We now allocate an AvmString for looking up builtin classes before storing them on SystemClasses/SystemClassDefs.
1 parent 9b6f356 commit b388929

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

core/src/avm2.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ use self::api_version::ApiVersion;
9797
use self::object::WeakObject;
9898
use self::scope::Scope;
9999

100-
const BROADCAST_WHITELIST: [&str; 4] = ["enterFrame", "exitFrame", "frameConstructed", "render"];
100+
const BROADCAST_WHITELIST: [&[u8]; 4] =
101+
[b"enterFrame", b"exitFrame", b"frameConstructed", b"render"];
101102

102103
const PREALLOCATED_STACK_SIZE: usize = 120000;
103104

@@ -483,10 +484,7 @@ impl<'gc> Avm2<'gc> {
483484
object: Object<'gc>,
484485
event_name: AvmString<'gc>,
485486
) {
486-
if !BROADCAST_WHITELIST
487-
.iter()
488-
.any(|x| AvmString::from(*x) == event_name)
489-
{
487+
if !BROADCAST_WHITELIST.iter().any(|x| *x == &event_name) {
490488
return;
491489
}
492490

@@ -521,10 +519,7 @@ impl<'gc> Avm2<'gc> {
521519
) {
522520
let event_name = event.event().event_type();
523521

524-
if !BROADCAST_WHITELIST
525-
.iter()
526-
.any(|x| AvmString::from(*x) == event_name)
527-
{
522+
if !BROADCAST_WHITELIST.iter().any(|x| *x == &event_name) {
528523
return;
529524
}
530525

core/src/avm2/globals.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::avm2::traits::Trait;
99
use crate::avm2::value::Value;
1010
use crate::avm2::vtable::VTable;
1111
use crate::avm2::{Avm2, Error, Multiname, Namespace, QName};
12+
use crate::string::WStr;
1213
use crate::tag_utils::{self, ControlFlow, SwfMovie, SwfSlice, SwfStream};
1314
use gc_arena::Collect;
1415
use std::sync::Arc;
@@ -812,9 +813,16 @@ macro_rules! avm2_system_classes_playerglobal {
812813
($activation:expr, [$(($package:expr, $class_name:expr, $field:ident)),* $(,)?]) => {
813814
let activation = $activation;
814815
$(
816+
// Package and class names are ASCII
817+
let package = WStr::from_units($package.as_bytes());
818+
let class_name = WStr::from_units($class_name.as_bytes());
819+
820+
let package = activation.strings().intern_static(package);
821+
let class_name = activation.strings().intern_static(class_name);
822+
815823
// Lookup with the highest version, so we we see all defined classes here
816-
let ns = Namespace::package($package, ApiVersion::VM_INTERNAL, activation.strings());
817-
let name = QName::new(ns, $class_name);
824+
let ns = Namespace::package(package, ApiVersion::VM_INTERNAL, activation.strings());
825+
let name = QName::new(ns, class_name);
818826
let class_object = activation.domain().get_defined_value(activation, name).unwrap_or_else(|e| panic!("Failed to lookup {name:?}: {e:?}"));
819827
let class_object = class_object.as_object().unwrap().as_class_object().unwrap();
820828
let sc = activation.avm2().system_classes.as_mut().unwrap();
@@ -827,11 +835,18 @@ macro_rules! avm2_system_class_defs_playerglobal {
827835
($activation:expr, [$(($package:expr, $class_name:expr, $field:ident)),* $(,)?]) => {
828836
let activation = $activation;
829837
$(
838+
// Package and class names are ASCII
839+
let package = WStr::from_units($package.as_bytes());
840+
let class_name = WStr::from_units($class_name.as_bytes());
841+
842+
let package = activation.strings().intern_static(package);
843+
let class_name = activation.strings().intern_static(class_name);
844+
830845
let domain = activation.domain();
831846

832847
// Lookup with the highest version, so we we see all defined classes here
833-
let ns = Namespace::package($package, ApiVersion::VM_INTERNAL, activation.strings());
834-
let name = Multiname::new(ns, $class_name);
848+
let ns = Namespace::package(package, ApiVersion::VM_INTERNAL, activation.strings());
849+
let name = Multiname::new(ns, class_name);
835850
let class_def = domain.get_class(activation.context, &name).unwrap_or_else(|| panic!("Failed to lookup {name:?}"));
836851
let sc = activation.avm2().system_class_defs.as_mut().unwrap();
837852
sc.$field = class_def;

0 commit comments

Comments
 (0)