Skip to content

Commit a4ef410

Browse files
Lord-McSweeneyLord-McSweeney
Lord-McSweeney
authored andcommitted
core: Use interned strings for ClipEvent names
1 parent 2aab1df commit a4ef410

File tree

4 files changed

+36
-22
lines changed

4 files changed

+36
-22
lines changed

core/src/display_object/avm1_button.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -525,12 +525,12 @@ impl<'gc> TInteractiveObject<'gc> for Avm1Button<'gc> {
525525
// Queue ActionScript-defined event handlers after the SWF defined ones.
526526
// (e.g., clip.onRelease = foo).
527527
if self.should_fire_event_handlers(context, event) {
528-
if let Some(name) = event.method_name() {
528+
if let Some(name) = event.method_name(&context.strings) {
529529
context.action_queue.queue_action(
530530
self_display_object,
531531
ActionType::Method {
532532
object: self.0.object.get().unwrap(),
533-
name: name.into(),
533+
name,
534534
args: vec![],
535535
},
536536
false,

core/src/display_object/movie_clip.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -2330,7 +2330,10 @@ impl<'gc> MovieClip<'gc> {
23302330
ClipEvent::BUTTON_EVENT_METHODS
23312331
.iter()
23322332
.copied()
2333-
.any(|handler| object.has_property(&mut activation, handler.into()))
2333+
.any(|handler| {
2334+
let handler = AvmString::new_utf8(activation.gc(), handler);
2335+
object.has_property(&mut activation, handler)
2336+
})
23342337
} else {
23352338
false
23362339
}
@@ -2989,12 +2992,12 @@ impl<'gc> TInteractiveObject<'gc> for MovieClip<'gc> {
29892992
// Queue ActionScript-defined event handlers after the SWF defined ones.
29902993
// (e.g., clip.onEnterFrame = foo).
29912994
if self.should_fire_event_handlers(context, event) {
2992-
if let Some(name) = event.method_name() {
2995+
if let Some(name) = event.method_name(&context.strings) {
29932996
context.action_queue.queue_action(
29942997
self.into(),
29952998
ActionType::Method {
29962999
object,
2997-
name: name.into(),
3000+
name,
29983001
args: vec![],
29993002
},
30003003
event == ClipEvent::Unload,

core/src/events.rs

+20-17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use crate::{display_object::InteractiveObject, input::InputEvent};
1+
use crate::display_object::InteractiveObject;
2+
use crate::input::InputEvent;
3+
use crate::string::{AvmString, StringContext};
4+
use ruffle_macros::istr;
25
use std::str::FromStr;
36
use swf::ClipEventFlag;
47

@@ -391,27 +394,27 @@ impl ClipEvent<'_> {
391394
/// `ClipEvent::Data` returns `None` rather than `onData` because its behavior
392395
/// differs from the other events: the method must fire before the SWF-defined
393396
/// event handler, so we'll explicitly call `onData` in the appropriate places.
394-
pub const fn method_name(self) -> Option<&'static str> {
397+
pub fn method_name<'gc>(self, ctx: &StringContext<'gc>) -> Option<AvmString<'gc>> {
395398
match self {
396399
ClipEvent::Construct => None,
397400
ClipEvent::Data => None,
398-
ClipEvent::DragOut { .. } => Some("onDragOut"),
399-
ClipEvent::DragOver { .. } => Some("onDragOver"),
400-
ClipEvent::EnterFrame => Some("onEnterFrame"),
401+
ClipEvent::DragOut { .. } => Some(istr!(ctx, "onDragOut")),
402+
ClipEvent::DragOver { .. } => Some(istr!(ctx, "onDragOver")),
403+
ClipEvent::EnterFrame => Some(istr!(ctx, "onEnterFrame")),
401404
ClipEvent::Initialize => None,
402-
ClipEvent::KeyDown => Some("onKeyDown"),
405+
ClipEvent::KeyDown => Some(istr!(ctx, "onKeyDown")),
403406
ClipEvent::KeyPress { .. } => None,
404-
ClipEvent::KeyUp => Some("onKeyUp"),
405-
ClipEvent::Load => Some("onLoad"),
406-
ClipEvent::MouseDown => Some("onMouseDown"),
407-
ClipEvent::MouseMove => Some("onMouseMove"),
408-
ClipEvent::MouseUp => Some("onMouseUp"),
409-
ClipEvent::Press { .. } => Some("onPress"),
410-
ClipEvent::RollOut { .. } => Some("onRollOut"),
411-
ClipEvent::RollOver { .. } => Some("onRollOver"),
412-
ClipEvent::Release { .. } => Some("onRelease"),
413-
ClipEvent::ReleaseOutside => Some("onReleaseOutside"),
414-
ClipEvent::Unload => Some("onUnload"),
407+
ClipEvent::KeyUp => Some(istr!(ctx, "onKeyUp")),
408+
ClipEvent::Load => Some(istr!(ctx, "onLoad")),
409+
ClipEvent::MouseDown => Some(istr!(ctx, "onMouseDown")),
410+
ClipEvent::MouseMove => Some(istr!(ctx, "onMouseMove")),
411+
ClipEvent::MouseUp => Some(istr!(ctx, "onMouseUp")),
412+
ClipEvent::Press { .. } => Some(istr!(ctx, "onPress")),
413+
ClipEvent::RollOut { .. } => Some(istr!(ctx, "onRollOut")),
414+
ClipEvent::RollOver { .. } => Some(istr!(ctx, "onRollOver")),
415+
ClipEvent::Release { .. } => Some(istr!(ctx, "onRelease")),
416+
ClipEvent::ReleaseOutside => Some(istr!(ctx, "onReleaseOutside")),
417+
ClipEvent::Unload => Some(istr!(ctx, "onUnload")),
415418
_ => None,
416419
}
417420
}

core/src/string/common.rs

+8
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ define_common_strings! {
192192
str_onComplete: b"onComplete",
193193
str_onConnect: b"onConnect",
194194
str_onData: b"onData",
195+
str_onDragOut: b"onDragOut",
196+
str_onDragOver: b"onDragOver",
197+
str_onEnterFrame: b"onEnterFrame",
195198
str_onFullScreen: b"onFullScreen",
196199
str_onIOError: b"onIOError",
197200
str_onHTTPError: b"onHTTPError",
@@ -209,9 +212,14 @@ define_common_strings! {
209212
str_onMouseUp: b"onMouseUp",
210213
str_onMouseWheel: b"onMouseWheel",
211214
str_onOpen: b"onOpen",
215+
str_onPress: b"onPress",
212216
str_onProgress: b"onProgress",
217+
str_onRelease: b"onRelease",
218+
str_onReleaseOutside: b"onReleaseOutside",
213219
str_onResize: b"onResize",
214220
str_onResult: b"onResult",
221+
str_onRollOut: b"onRollOut",
222+
str_onRollOver: b"onRollOver",
215223
str_onScroller: b"onScroller",
216224
str_onSelect: b"onSelect",
217225
str_onSetFocus: b"onSetFocus",

0 commit comments

Comments
 (0)