Skip to content

Commit

Permalink
core: rename GcContext to StringContext; improve ergonomics
Browse files Browse the repository at this point in the history
- Rename `borrow_gc()` methods to `strings_mut()`.
- Rename `context.interner` to `context.strings`.
- Add `Activation::strings()` convenience method.
- Take a `StringContext` instead of a `&mut StringContext`
  in most methods.
  • Loading branch information
moulins committed Sep 26, 2024
1 parent 2c9033f commit b1ce502
Show file tree
Hide file tree
Showing 82 changed files with 268 additions and 272 deletions.
14 changes: 11 additions & 3 deletions core/src/avm1/activation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ use crate::avm1::runtime::skip_actions;
use crate::avm1::scope::{Scope, ScopeClass};
use crate::avm1::{fscommand, globals, scope, ArrayObject, ScriptObject, Value};
use crate::backend::navigator::{NavigationMethod, Request};
use crate::context::UpdateContext;
use crate::context::{StringContext, UpdateContext};
use crate::display_object::{
DisplayObject, DisplayObjectContainer, MovieClip, TDisplayObject, TDisplayObjectContainer,
};
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, AvmStringInterner, SwfStrExt as _, WStr, WString};
use crate::tag_utils::SwfSlice;
use crate::vminterface::Instantiator;
use crate::{avm_error, avm_warn};
Expand Down Expand Up @@ -243,6 +243,14 @@ impl<'a, 'gc> Activation<'a, 'gc> {
self.context.gc_context
}

pub fn strings(&self) -> &AvmStringInterner<'gc> {
self.context.strings
}

pub fn strings_mut(&mut self) -> StringContext<'_, 'gc> {
self.context.strings_mut()
}

#[allow(clippy::too_many_arguments)]
pub fn from_action(
context: &'a mut UpdateContext<'gc>,
Expand Down Expand Up @@ -868,7 +876,7 @@ impl<'a, 'gc> Activation<'a, 'gc> {
.iter()
.map(|s| {
self.context
.interner
.strings
.intern_wstr(self.context.gc_context, s.decode(self.encoding()))
.into()
})
Expand Down
6 changes: 3 additions & 3 deletions core/src/avm1/globals.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::property::Attribute;
use crate::avm1::property_decl::{define_properties_on, Declaration};
use crate::avm1::{Object, ScriptObject, TObject, Value};
use crate::context::GcContext;
use crate::context::StringContext;
use crate::display_object::{DisplayObject, TDisplayObject, TDisplayObjectContainer};
use crate::string::{AvmString, WStr, WString};
use gc_arena::Collect;
Expand Down Expand Up @@ -518,7 +518,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 +1207,7 @@ mod tests {
use super::*;

fn setup<'gc>(activation: &mut Activation<'_, 'gc>) -> Object<'gc> {
create_globals(&mut activation.context.borrow_gc()).1
create_globals(&mut activation.strings_mut()).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::context::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
6 changes: 3 additions & 3 deletions core/src/avm1/globals/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ 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::context::StringContext;
use crate::ecma_conversions::f64_to_wrapping_i32;
use crate::string::AvmString;
use bitflags::bitflags;
Expand Down Expand Up @@ -62,7 +62,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 +743,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
4 changes: 2 additions & 2 deletions core/src/avm1/globals/as_broadcaster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +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::context::StringContext;
use crate::string::AvmString;
use gc_arena::{Collect, Mutation};

Expand All @@ -19,7 +19,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
6 changes: 3 additions & 3 deletions core/src/avm1/globals/bevel_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::context::StringContext;
use crate::string::{AvmString, WStr};
use gc_arena::{Collect, GcCell, Mutation};
use std::ops::Deref;
Expand Down Expand Up @@ -533,7 +533,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 +543,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,7 +12,7 @@ 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::context::StringContext;
use crate::display_object::DisplayObject;
use crate::swf::BlendMode;
use crate::{avm1_stub, avm_error};
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
4 changes: 2 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,7 @@ 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::{StringContext, UpdateContext};
use ruffle_render::filters::Filter;

const PROTO_DECLS: &[Declaration] = declare_properties! {
Expand Down Expand Up @@ -194,7 +194,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::context::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
6 changes: 3 additions & 3 deletions core/src/avm1/globals/boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +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::context::StringContext;
use crate::string::AvmString;

const PROTO_DECLS: &[Declaration] = declare_properties! {
Expand Down Expand Up @@ -46,7 +46,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 +61,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
4 changes: 2 additions & 2 deletions core/src/avm1/globals/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ 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::context::StringContext;
use crate::display_object::{Avm1Button, TDisplayObject, TInteractiveObject};
use crate::string::AvmString;

Expand Down Expand Up @@ -52,7 +52,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,7 +8,7 @@ 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::context::StringContext;
use crate::display_object::{DisplayObject, TDisplayObject};

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::context::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
4 changes: 2 additions & 2 deletions core/src/avm1/globals/color_transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +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::context::StringContext;
use crate::string::AvmString;
use gc_arena::{Collect, GcCell};
use swf::{ColorTransform, Fixed8};
Expand Down Expand Up @@ -265,7 +265,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,7 +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::context::StringContext;
use crate::context_menu;
use crate::display_object::DisplayObject;

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
4 changes: 2 additions & 2 deletions core/src/avm1/globals/context_menu_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +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::context::StringContext;
use crate::string::AvmString;

const PROTO_DECLS: &[Declaration] = declare_properties! {
Expand Down Expand Up @@ -90,7 +90,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
6 changes: 3 additions & 3 deletions core/src/avm1/globals/convolution_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,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, UpdateContext};
use crate::context::{StringContext, UpdateContext};
use gc_arena::{Collect, GcCell, Mutation};
use std::ops::Deref;
use swf::{Color, ConvolutionFilterFlags};
Expand Down Expand Up @@ -408,7 +408,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 @@ -418,7 +418,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
Loading

0 comments on commit b1ce502

Please sign in to comment.