Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: Improve ergonomics by replacing GcContext by StringContext #18105

Merged
merged 3 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions core/src/avm1/activation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::display_object::{
};
use crate::ecma_conversions::{f64_to_wrapping_i32, f64_to_wrapping_u32};
use crate::loader::MovieLoaderVMData;
use crate::string::{AvmString, SwfStrExt as _, WStr, WString};
use crate::string::{AvmString, StringContext, SwfStrExt as _, WStr, WString};
use crate::tag_utils::SwfSlice;
use crate::vminterface::Instantiator;
use crate::{avm_error, avm_warn};
Expand Down Expand Up @@ -239,10 +239,15 @@ impl<'a, 'gc> Activation<'a, 'gc> {
/// Convenience method to retrieve the current GC context. Note that explicitly writing
/// `self.context.gc_context` can be sometimes necessary to satisfy the borrow checker.
#[inline(always)]
pub fn gc(&self) -> &'gc gc_arena::Mutation<'gc> {
pub fn gc(&self) -> &'gc Mutation<'gc> {
self.context.gc_context
}

#[inline(always)]
pub fn strings(&mut self) -> &mut StringContext<'gc> {
&mut self.context.strings
}

#[allow(clippy::too_many_arguments)]
pub fn from_action(
context: &'a mut UpdateContext<'gc>,
Expand Down Expand Up @@ -863,15 +868,11 @@ impl<'a, 'gc> Activation<'a, 'gc> {
&mut self,
action: ConstantPool,
) -> Result<FrameControl<'gc>, Error<'gc>> {
let encoding = self.encoding();
let constants = action
.strings
.iter()
.map(|s| {
self.context
.interner
.intern_wstr(self.context.gc_context, s.decode(self.encoding()))
.into()
})
.map(|s| self.strings().intern_wstr(s.decode(encoding)).into())
.collect();

self.context
Expand Down
7 changes: 3 additions & 4 deletions core/src/avm1/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ use crate::avm1::function::{Executable, FunctionObject};
use crate::avm1::property::Attribute;
use crate::avm1::property_decl::{define_properties_on, Declaration};
use crate::avm1::{Object, ScriptObject, TObject, Value};
use crate::context::GcContext;
use crate::display_object::{DisplayObject, TDisplayObject, TDisplayObjectContainer};
use crate::string::{AvmString, WStr, WString};
use crate::string::{AvmString, StringContext, WStr, WString};
use gc_arena::Collect;
use std::str;

Expand Down Expand Up @@ -518,7 +517,7 @@ pub struct SystemPrototypes<'gc> {

/// Initialize default global scope and builtins for an AVM1 instance.
pub fn create_globals<'gc>(
context: &mut GcContext<'_, 'gc>,
context: &mut StringContext<'gc>,
) -> (
SystemPrototypes<'gc>,
Object<'gc>,
Expand Down Expand Up @@ -1207,7 +1206,7 @@ mod tests {
use super::*;

fn setup<'gc>(activation: &mut Activation<'_, 'gc>) -> Object<'gc> {
create_globals(&mut activation.context.borrow_gc()).1
create_globals(activation.strings()).1
}

test_method!(boolean_function, "Boolean", setup,
Expand Down
4 changes: 2 additions & 2 deletions core/src/avm1/globals/accessibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::avm1::error::Error;
use crate::avm1::property_decl::{define_properties_on, Declaration};
use crate::avm1::{Object, ScriptObject, Value};
use crate::avm1_stub;
use crate::context::GcContext;
use crate::string::StringContext;

const OBJECT_DECLS: &[Declaration] = declare_properties! {
"isActive" => method(is_active; DONT_DELETE | READ_ONLY);
Expand Down Expand Up @@ -41,7 +41,7 @@ pub fn update_properties<'gc>(
}

pub fn create_accessibility_object<'gc>(
context: &mut GcContext<'_, 'gc>,
context: &mut StringContext<'gc>,
proto: Object<'gc>,
fn_proto: Object<'gc>,
) -> Object<'gc> {
Expand Down
7 changes: 3 additions & 4 deletions core/src/avm1/globals/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ use crate::avm1::error::Error;
use crate::avm1::function::{Executable, FunctionObject};
use crate::avm1::property_decl::{define_properties_on, Declaration};
use crate::avm1::{ArrayObject, Object, TObject, Value};
use crate::context::GcContext;
use crate::ecma_conversions::f64_to_wrapping_i32;
use crate::string::AvmString;
use crate::string::{AvmString, StringContext};
use bitflags::bitflags;
use std::cmp::Ordering;

Expand Down Expand Up @@ -62,7 +61,7 @@ const OBJECT_DECLS: &[Declaration] = declare_properties! {
};

pub fn create_array_object<'gc>(
context: &mut GcContext<'_, 'gc>,
context: &mut StringContext<'gc>,
array_proto: Object<'gc>,
fn_proto: Object<'gc>,
) -> Object<'gc> {
Expand Down Expand Up @@ -743,7 +742,7 @@ fn qsort<'gc>(
}

pub fn create_proto<'gc>(
context: &mut GcContext<'_, 'gc>,
context: &mut StringContext<'gc>,
proto: Object<'gc>,
fn_proto: Object<'gc>,
) -> Object<'gc> {
Expand Down
5 changes: 2 additions & 3 deletions core/src/avm1/globals/as_broadcaster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use crate::avm1::object::TObject;
use crate::avm1::property::Attribute;
use crate::avm1::property_decl::Declaration;
use crate::avm1::{Activation, ArrayObject, Object, ScriptObject, Value};
use crate::context::GcContext;
use crate::string::AvmString;
use crate::string::{AvmString, StringContext};
use gc_arena::{Collect, Mutation};

const OBJECT_DECLS: &[Declaration] = declare_properties! {
Expand All @@ -19,7 +18,7 @@ const OBJECT_DECLS: &[Declaration] = declare_properties! {
};

pub fn create<'gc>(
context: &mut GcContext<'_, 'gc>,
context: &mut StringContext<'gc>,
proto: Object<'gc>,
fn_proto: Object<'gc>,
) -> (BroadcasterFunctions<'gc>, Object<'gc>) {
Expand Down
7 changes: 3 additions & 4 deletions core/src/avm1/globals/bevel_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use crate::avm1::function::{Executable, FunctionObject};
use crate::avm1::object::NativeObject;
use crate::avm1::property_decl::{define_properties_on, Declaration};
use crate::avm1::{Activation, Error, Object, ScriptObject, TObject, Value};
use crate::context::GcContext;
use crate::string::{AvmString, WStr};
use crate::string::{AvmString, StringContext, WStr};
use gc_arena::{Collect, GcCell, Mutation};
use std::ops::Deref;
use swf::{BevelFilterFlags, Color, Fixed16, Fixed8, GradientFilterFlags};
Expand Down Expand Up @@ -533,7 +532,7 @@ fn method<'gc>(
}

pub fn create_proto<'gc>(
context: &mut GcContext<'_, 'gc>,
context: &mut StringContext<'gc>,
proto: Object<'gc>,
fn_proto: Object<'gc>,
) -> Object<'gc> {
Expand All @@ -543,7 +542,7 @@ pub fn create_proto<'gc>(
}

pub fn create_constructor<'gc>(
context: &mut GcContext<'_, 'gc>,
context: &mut StringContext<'gc>,
proto: Object<'gc>,
fn_proto: Object<'gc>,
) -> Object<'gc> {
Expand Down
4 changes: 2 additions & 2 deletions core/src/avm1/globals/bitmap_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use crate::bitmap::bitmap_data::{BitmapDataDrawError, IBitmapDrawable};
use crate::bitmap::bitmap_data::{ChannelOptions, ThresholdOperation};
use crate::bitmap::{is_size_valid, operations};
use crate::character::Character;
use crate::context::GcContext;
use crate::display_object::DisplayObject;
use crate::string::StringContext;
use crate::swf::BlendMode;
use crate::{avm1_stub, avm_error};
use gc_arena::{GcCell, Mutation};
Expand Down Expand Up @@ -1522,7 +1522,7 @@ fn load_bitmap<'gc>(
}

pub fn create_constructor<'gc>(
context: &mut GcContext<'_, 'gc>,
context: &mut StringContext<'gc>,
proto: ScriptObject<'gc>,
fn_proto: Object<'gc>,
) -> Object<'gc> {
Expand Down
5 changes: 3 additions & 2 deletions core/src/avm1/globals/bitmap_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ use crate::avm1::globals::gradient_filter::GradientFilter;
use crate::avm1::object::NativeObject;
use crate::avm1::property_decl::{define_properties_on, Declaration};
use crate::avm1::{Attribute, Object, ScriptObject, TObject, Value};
use crate::context::{GcContext, UpdateContext};
use crate::context::UpdateContext;
use crate::string::StringContext;
use ruffle_render::filters::Filter;

const PROTO_DECLS: &[Declaration] = declare_properties! {
Expand Down Expand Up @@ -194,7 +195,7 @@ pub fn create_instance<'gc>(
}

pub fn create_proto<'gc>(
context: &mut GcContext<'_, 'gc>,
context: &mut StringContext<'gc>,
proto: Object<'gc>,
fn_proto: Object<'gc>,
) -> Object<'gc> {
Expand Down
6 changes: 3 additions & 3 deletions core/src/avm1/globals/blur_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::avm1::function::{Executable, FunctionObject};
use crate::avm1::object::NativeObject;
use crate::avm1::property_decl::{define_properties_on, Declaration};
use crate::avm1::{Activation, Error, Object, ScriptObject, TObject, Value};
use crate::context::GcContext;
use crate::string::StringContext;
use gc_arena::{Collect, GcCell, Mutation};
use std::ops::Deref;
use swf::{BlurFilterFlags, Fixed16};
Expand Down Expand Up @@ -186,7 +186,7 @@ fn method<'gc>(
}

pub fn create_proto<'gc>(
context: &mut GcContext<'_, 'gc>,
context: &mut StringContext<'gc>,
proto: Object<'gc>,
fn_proto: Object<'gc>,
) -> Object<'gc> {
Expand All @@ -196,7 +196,7 @@ pub fn create_proto<'gc>(
}

pub fn create_constructor<'gc>(
context: &mut GcContext<'_, 'gc>,
context: &mut StringContext<'gc>,
proto: Object<'gc>,
fn_proto: Object<'gc>,
) -> Object<'gc> {
Expand Down
7 changes: 3 additions & 4 deletions core/src/avm1/globals/boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use crate::avm1::function::{Executable, FunctionObject};
use crate::avm1::object::value_object::ValueObject;
use crate::avm1::property_decl::{define_properties_on, Declaration};
use crate::avm1::{Object, TObject, Value};
use crate::context::GcContext;
use crate::string::AvmString;
use crate::string::{AvmString, StringContext};

const PROTO_DECLS: &[Declaration] = declare_properties! {
"toString" => method(to_string; DONT_ENUM | DONT_DELETE);
Expand Down Expand Up @@ -46,7 +45,7 @@ pub fn boolean_function<'gc>(
}

pub fn create_boolean_object<'gc>(
context: &mut GcContext<'_, 'gc>,
context: &mut StringContext<'gc>,
boolean_proto: Object<'gc>,
fn_proto: Object<'gc>,
) -> Object<'gc> {
Expand All @@ -61,7 +60,7 @@ pub fn create_boolean_object<'gc>(

/// Creates `Boolean.prototype`.
pub fn create_proto<'gc>(
context: &mut GcContext<'_, 'gc>,
context: &mut StringContext<'gc>,
proto: Object<'gc>,
fn_proto: Object<'gc>,
) -> Object<'gc> {
Expand Down
5 changes: 2 additions & 3 deletions core/src/avm1/globals/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ use crate::avm1::property_decl::{define_properties_on, Declaration};
use crate::avm1::ArrayObject;
use crate::avm1::{globals, Object, ScriptObject, TObject, Value};
use crate::avm1_stub;
use crate::context::GcContext;
use crate::display_object::{Avm1Button, TDisplayObject, TInteractiveObject};
use crate::string::AvmString;
use crate::string::{AvmString, StringContext};

macro_rules! button_getter {
($name:ident) => {
Expand Down Expand Up @@ -52,7 +51,7 @@ const PROTO_DECLS: &[Declaration] = declare_properties! {
};

pub fn create_proto<'gc>(
context: &mut GcContext<'_, 'gc>,
context: &mut StringContext<'gc>,
proto: Object<'gc>,
fn_proto: Object<'gc>,
) -> Object<'gc> {
Expand Down
4 changes: 2 additions & 2 deletions core/src/avm1/globals/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use crate::avm1::error::Error;
use crate::avm1::property::Attribute;
use crate::avm1::property_decl::{define_properties_on, Declaration};
use crate::avm1::{Object, ScriptObject, TObject, Value};
use crate::context::GcContext;
use crate::display_object::{DisplayObject, TDisplayObject};
use crate::string::StringContext;

use swf::Fixed8;

Expand Down Expand Up @@ -38,7 +38,7 @@ pub fn constructor<'gc>(
}

pub fn create_proto<'gc>(
context: &mut GcContext<'_, 'gc>,
context: &mut StringContext<'gc>,
proto: Object<'gc>,
fn_proto: Object<'gc>,
) -> Object<'gc> {
Expand Down
6 changes: 3 additions & 3 deletions core/src/avm1/globals/color_matrix_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::avm1::function::{Executable, FunctionObject};
use crate::avm1::object::NativeObject;
use crate::avm1::property_decl::{define_properties_on, Declaration};
use crate::avm1::{Activation, ArrayObject, Error, Object, ScriptObject, TObject, Value};
use crate::context::GcContext;
use crate::string::StringContext;
use gc_arena::{Collect, GcCell, Mutation};
use std::ops::Deref;

Expand Down Expand Up @@ -158,7 +158,7 @@ fn method<'gc>(
}

pub fn create_proto<'gc>(
context: &mut GcContext<'_, 'gc>,
context: &mut StringContext<'gc>,
proto: Object<'gc>,
fn_proto: Object<'gc>,
) -> Object<'gc> {
Expand All @@ -168,7 +168,7 @@ pub fn create_proto<'gc>(
}

pub fn create_constructor<'gc>(
context: &mut GcContext<'_, 'gc>,
context: &mut StringContext<'gc>,
proto: Object<'gc>,
fn_proto: Object<'gc>,
) -> Object<'gc> {
Expand Down
5 changes: 2 additions & 3 deletions core/src/avm1/globals/color_transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
use crate::avm1::object::NativeObject;
use crate::avm1::property_decl::{define_properties_on, Declaration};
use crate::avm1::{Activation, Error, Object, ScriptObject, TObject, Value};
use crate::context::GcContext;
use crate::string::AvmString;
use crate::string::{AvmString, StringContext};
use gc_arena::{Collect, GcCell};
use swf::{ColorTransform, Fixed8};

Expand Down Expand Up @@ -265,7 +264,7 @@ fn concat<'gc>(
}

pub fn create_proto<'gc>(
context: &mut GcContext<'_, 'gc>,
context: &mut StringContext<'gc>,
proto: Object<'gc>,
fn_proto: Object<'gc>,
) -> Object<'gc> {
Expand Down
4 changes: 2 additions & 2 deletions core/src/avm1/globals/context_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use crate::avm1::object::TObject;
use crate::avm1::property_decl::{define_properties_on, Declaration};
use crate::avm1::Object;
use crate::avm1::{ScriptObject, Value};
use crate::context::GcContext;
use crate::context_menu;
use crate::display_object::DisplayObject;
use crate::string::StringContext;

const PROTO_DECLS: &[Declaration] = declare_properties! {
"copy" => method(copy; DONT_ENUM | DONT_DELETE);
Expand Down Expand Up @@ -142,7 +142,7 @@ pub fn hide_builtin_items<'gc>(
}

pub fn create_proto<'gc>(
context: &mut GcContext<'_, 'gc>,
context: &mut StringContext<'gc>,
proto: Object<'gc>,
fn_proto: Object<'gc>,
) -> Object<'gc> {
Expand Down
5 changes: 2 additions & 3 deletions core/src/avm1/globals/context_menu_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use crate::avm1::object::TObject;
use crate::avm1::property_decl::{define_properties_on, Declaration};
use crate::avm1::Object;
use crate::avm1::{ScriptObject, Value};
use crate::context::GcContext;
use crate::string::AvmString;
use crate::string::{AvmString, StringContext};

const PROTO_DECLS: &[Declaration] = declare_properties! {
"copy" => method(copy; DONT_ENUM | DONT_DELETE);
Expand Down Expand Up @@ -90,7 +89,7 @@ pub fn copy<'gc>(
}

pub fn create_proto<'gc>(
context: &mut GcContext<'_, 'gc>,
context: &mut StringContext<'gc>,
proto: Object<'gc>,
fn_proto: Object<'gc>,
) -> Object<'gc> {
Expand Down
Loading