Skip to content

Commit fdc2ba2

Browse files
committed
avm2: Do not reference trivially copyable objects
1 parent b2f412c commit fdc2ba2

File tree

9 files changed

+32
-32
lines changed

9 files changed

+32
-32
lines changed

core/src/avm2/domain.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl<'gc> Domain<'gc> {
121121
}
122122

123123
#[cfg(feature = "egui")]
124-
pub fn children(&self, mc: &Mutation<'gc>) -> Vec<Domain<'gc>> {
124+
pub fn children(self, mc: &Mutation<'gc>) -> Vec<Domain<'gc>> {
125125
// Take this opportunity to clean up dead children.
126126
let mut output = Vec::new();
127127
self.cell_mut(mc).children.retain(|child| {
@@ -327,7 +327,7 @@ impl<'gc> Domain<'gc> {
327327
res
328328
}
329329

330-
pub fn get_defined_names(&self) -> Vec<QName<'gc>> {
330+
pub fn get_defined_names(self) -> Vec<QName<'gc>> {
331331
self.cell()
332332
.defs
333333
.iter()
@@ -349,7 +349,7 @@ impl<'gc> Domain<'gc> {
349349
/// Export a class into the current application domain.
350350
///
351351
/// This does nothing if the definition already exists in this domain or a parent.
352-
pub fn export_class(&self, export_name: QName<'gc>, class: Class<'gc>, mc: &Mutation<'gc>) {
352+
pub fn export_class(self, export_name: QName<'gc>, class: Class<'gc>, mc: &Mutation<'gc>) {
353353
if self.has_class(export_name) {
354354
return;
355355
}
@@ -371,7 +371,7 @@ impl<'gc> Domain<'gc> {
371371
std::ptr::eq(domain_memory_ptr, default_domain_memory_ptr)
372372
}
373373

374-
pub fn domain_memory(&self) -> ByteArrayObject<'gc> {
374+
pub fn domain_memory(self) -> ByteArrayObject<'gc> {
375375
self.0
376376
.domain_memory
377377
.get()

core/src/avm2/globals/avmplus.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ fn describe_internal_body<'gc>(
295295
activation.gc(),
296296
);
297297

298-
let params = write_params(&method.method, activation);
298+
let params = write_params(method.method, activation);
299299
method_obj.set_dynamic_property(
300300
istr!("parameters"),
301301
params.into(),
@@ -416,7 +416,7 @@ fn describe_internal_body<'gc>(
416416
if let Some(constructor) = constructor.filter(|c| {
417417
!c.signature().is_empty() && flags.contains(DescribeTypeFlags::INCLUDE_CONSTRUCTOR)
418418
}) {
419-
let params = write_params(&constructor, activation);
419+
let params = write_params(constructor, activation);
420420
traits.set_dynamic_property(istr!("constructor"), params.into(), activation.gc());
421421
} else {
422422
// This is needed to override the normal 'constructor' property
@@ -452,7 +452,7 @@ fn display_name<'gc>(
452452
}
453453

454454
fn write_params<'gc>(
455-
method: &Method<'gc>,
455+
method: Method<'gc>,
456456
activation: &mut Activation<'_, 'gc>,
457457
) -> ArrayObject<'gc> {
458458
let params = ArrayObject::empty(activation);

core/src/avm2/globals/string.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ pub fn replace<'gc>(
305305
{
306306
// Replacement is either a function or treatable as string.
307307
if let Some(f) = replacement.as_object().and_then(|o| o.as_function_object()) {
308-
return Ok(RegExp::replace_fn(regexp, activation, this, &f)?.into());
308+
return Ok(RegExp::replace_fn(regexp, activation, this, f)?.into());
309309
} else {
310310
let replacement = replacement.coerce_to_string(activation)?;
311311
return Ok(RegExp::replace_string(regexp, activation, this, replacement)?.into());

core/src/avm2/method.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -233,16 +233,16 @@ impl<'gc> Method<'gc> {
233233
}
234234

235235
/// Get the underlying ABC file.
236-
pub fn abc(&self) -> Rc<AbcFile> {
236+
pub fn abc(self) -> Rc<AbcFile> {
237237
self.0.txunit.abc()
238238
}
239239

240240
/// Get the underlying translation unit this method was defined in.
241-
pub fn translation_unit(&self) -> TranslationUnit<'gc> {
241+
pub fn translation_unit(self) -> TranslationUnit<'gc> {
242242
self.0.txunit
243243
}
244244

245-
pub fn abc_method_index(&self) -> u32 {
245+
pub fn abc_method_index(self) -> u32 {
246246
self.0.abc_method
247247
}
248248

@@ -252,7 +252,7 @@ impl<'gc> Method<'gc> {
252252
}
253253

254254
/// Get a reference to the SwfMovie this method came from.
255-
pub fn owner_movie(&self) -> Arc<SwfMovie> {
255+
pub fn owner_movie(self) -> Arc<SwfMovie> {
256256
self.0.txunit.movie()
257257
}
258258

@@ -296,7 +296,7 @@ impl<'gc> Method<'gc> {
296296
&self.0.resolved_info.get().unwrap().param_config
297297
}
298298

299-
pub fn resolved_return_type(&self) -> Option<Class<'gc>> {
299+
pub fn resolved_return_type(self) -> Option<Class<'gc>> {
300300
self.0.resolved_info.get().unwrap().return_type
301301
}
302302

@@ -351,22 +351,22 @@ impl<'gc> Method<'gc> {
351351
/// Determine if a given method is variadic.
352352
///
353353
/// Variadic methods shove excess parameters into a final register.
354-
pub fn is_variadic(&self) -> bool {
354+
pub fn is_variadic(self) -> bool {
355355
self.method()
356356
.flags
357357
.intersects(AbcMethodFlags::NEED_ARGUMENTS | AbcMethodFlags::NEED_REST)
358358
}
359359

360360
/// Check if this method needs `arguments`.
361-
pub fn needs_arguments_object(&self) -> bool {
361+
pub fn needs_arguments_object(self) -> bool {
362362
self.method().flags.contains(AbcMethodFlags::NEED_ARGUMENTS)
363363
}
364364

365365
pub fn method_kind(&self) -> &MethodKind<'gc> {
366366
&self.0.method_kind
367367
}
368368

369-
pub fn return_type(&self) -> Option<Gc<'gc, Multiname<'gc>>> {
369+
pub fn return_type(self) -> Option<Gc<'gc, Multiname<'gc>>> {
370370
self.0.return_type
371371
}
372372

@@ -392,7 +392,7 @@ impl<'gc> Method<'gc> {
392392
///
393393
/// * The method was declared as a free-standing function
394394
/// * The function's parameters have no declared types or default values
395-
pub fn is_unchecked(&self) -> bool {
395+
pub fn is_unchecked(self) -> bool {
396396
self.0.is_unchecked
397397
}
398398
}

core/src/avm2/namespace.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -245,27 +245,27 @@ impl<'gc> Namespace<'gc> {
245245
)))
246246
}
247247

248-
pub fn is_public(&self) -> bool {
248+
pub fn is_public(self) -> bool {
249249
matches!(self.0.as_deref(), Some(NamespaceData::Namespace(name, _)) if name.as_wstr().is_empty())
250250
}
251251

252-
pub fn is_public_ignoring_ns(&self) -> bool {
252+
pub fn is_public_ignoring_ns(self) -> bool {
253253
matches!(self.0.as_deref(), Some(NamespaceData::Namespace(_, _)))
254254
}
255255

256-
pub fn is_any(&self) -> bool {
256+
pub fn is_any(self) -> bool {
257257
self.0.is_none()
258258
}
259259

260-
pub fn is_private(&self) -> bool {
260+
pub fn is_private(self) -> bool {
261261
matches!(self.0.as_deref(), Some(NamespaceData::Private(_)))
262262
}
263263

264-
pub fn is_namespace(&self) -> bool {
264+
pub fn is_namespace(self) -> bool {
265265
matches!(self.0.as_deref(), Some(NamespaceData::Namespace(_, _)))
266266
}
267267

268-
pub fn as_uri_opt(&self) -> Option<AvmString<'gc>> {
268+
pub fn as_uri_opt(self) -> Option<AvmString<'gc>> {
269269
self.0.map(|data| match *data {
270270
NamespaceData::Namespace(a, _) => a.into(),
271271
NamespaceData::PackageInternal(a) => a.into(),
@@ -279,7 +279,7 @@ impl<'gc> Namespace<'gc> {
279279
/// Get the string value of this namespace, ignoring its type.
280280
///
281281
/// TODO: Is this *actually* the namespace URI?
282-
pub fn as_uri(&self, context: &mut StringContext<'gc>) -> AvmString<'gc> {
282+
pub fn as_uri(self, context: &mut StringContext<'gc>) -> AvmString<'gc> {
283283
self.as_uri_opt().unwrap_or_else(|| context.empty())
284284
}
285285

@@ -289,7 +289,7 @@ impl<'gc> Namespace<'gc> {
289289
///
290290
/// Namespace does not implement `PartialEq`, so that each caller is required
291291
/// to explicitly choose either `exact_version_match` or `matches_ns`.
292-
pub fn exact_version_match(&self, other: Self) -> bool {
292+
pub fn exact_version_match(self, other: Self) -> bool {
293293
if self.0.map(Gc::as_ptr) == other.0.map(Gc::as_ptr) {
294294
true
295295
} else if self.is_private() || other.is_private() {
@@ -304,7 +304,7 @@ impl<'gc> Namespace<'gc> {
304304
/// seen by the other). This is used to implement `PropertyMap`, where we want to
305305
/// a definition with `ApiVersion::SWF_16` to be visible when queried from
306306
/// a SWF with `ApiVersion::SWF_16` or any higher version.
307-
pub fn matches_ns(&self, other: Self) -> bool {
307+
pub fn matches_ns(self, other: Self) -> bool {
308308
if self.exact_version_match(other) {
309309
return true;
310310
}
@@ -321,7 +321,7 @@ impl<'gc> Namespace<'gc> {
321321
_ => false,
322322
}
323323
}
324-
pub fn matches_api_version(&self, match_version: ApiVersion) -> bool {
324+
pub fn matches_api_version(self, match_version: ApiVersion) -> bool {
325325
match self.0.as_deref() {
326326
Some(NamespaceData::Namespace(_, version)) => version <= &match_version,
327327
_ => true,

core/src/avm2/regexp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ impl<'gc> RegExp<'gc> {
228228
regexp: RegExpObject<'gc>,
229229
activation: &mut Activation<'_, 'gc>,
230230
text: AvmString<'gc>,
231-
f: &FunctionObject<'gc>,
231+
f: FunctionObject<'gc>,
232232
) -> Result<AvmString<'gc>, Error<'gc>> {
233233
Self::replace_with_fn(regexp, activation, &text, |activation, txt, m| {
234234
let args = std::iter::once(Some(&m.range))

core/src/avm2/script.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ impl<'gc> TranslationUnit<'gc> {
233233
}
234234

235235
/// Gets a script in the ABC file by index.
236-
pub fn get_script(&self, index: usize) -> Option<Script<'gc>> {
236+
pub fn get_script(self, index: usize) -> Option<Script<'gc>> {
237237
self.0.scripts.get(index).and_then(|s| s.get()).copied()
238238
}
239239

core/src/avm2/specification.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ struct FunctionInfo {
154154
}
155155

156156
impl FunctionInfo {
157-
pub fn from_method(method: &Method, stubbed: bool) -> Self {
157+
pub fn from_method(method: Method, stubbed: bool) -> Self {
158158
Self {
159159
returns: method
160160
.return_type()
@@ -388,7 +388,7 @@ impl Definition {
388388
output
389389
.get_or_insert_default()
390390
.function
391-
.insert(trait_name, FunctionInfo::from_method(method, stubbed));
391+
.insert(trait_name, FunctionInfo::from_method(*method, stubbed));
392392
}
393393
TraitKind::Getter { method, .. } => {
394394
let stubbed = stubs.has_getter(&trait_name);

core/src/avm2/stack.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl<'gc> Stack<'gc> {
7272
StackFrame::for_data(subslice)
7373
}
7474

75-
pub fn dispose_stack_frame(&self, stack_frame: StackFrame<'_, 'gc>) {
75+
pub fn dispose_stack_frame(self, stack_frame: StackFrame<'_, 'gc>) {
7676
self.0
7777
.stack_pointer
7878
.set(self.0.stack_pointer.get() - stack_frame.data.len());

0 commit comments

Comments
 (0)