Skip to content

Commit cc16643

Browse files
relrelbHerschel
authored andcommitted
avm2: Activation::is_of_type is infallible
1 parent ce5bf55 commit cc16643

File tree

8 files changed

+25
-30
lines changed

8 files changed

+25
-30
lines changed

core/src/avm2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ impl<'gc> Avm2<'gc> {
263263
if let Some(object) = object {
264264
let mut activation = Activation::from_nothing(context.reborrow());
265265

266-
if object.is_of_type(on_type, &mut activation)? {
266+
if object.is_of_type(on_type, &mut activation) {
267267
Avm2::dispatch_event(&mut activation.context, event, object)?;
268268
}
269269
}

core/src/avm2/activation.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2644,7 +2644,7 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
26442644
let multiname = self.pool_multiname_static(method, type_name_index)?;
26452645
let type_object = self.resolve_class(&multiname)?;
26462646

2647-
let is_instance_of = value.is_of_type(self, type_object)?;
2647+
let is_instance_of = value.is_of_type(self, type_object);
26482648
self.context.avm2.push(is_instance_of);
26492649

26502650
Ok(FrameControl::Continue)
@@ -2660,8 +2660,7 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
26602660
.ok_or("Cannot check if value is of a type that is null, undefined, or not a class")?;
26612661
let value = self.context.avm2.pop();
26622662

2663-
let is_instance_of = value.is_of_type(self, type_object)?;
2664-
2663+
let is_instance_of = value.is_of_type(self, type_object);
26652664
self.context.avm2.push(is_instance_of);
26662665

26672666
Ok(FrameControl::Continue)
@@ -2677,7 +2676,7 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
26772676
let multiname = self.pool_multiname_static(method, type_name_index)?;
26782677
let class = self.resolve_class(&multiname)?;
26792678

2680-
if value.is_of_type(self, class)? {
2679+
if value.is_of_type(self, class) {
26812680
self.context.avm2.push(value);
26822681
} else {
26832682
self.context.avm2.push(Value::Null);
@@ -2696,7 +2695,7 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
26962695
.ok_or("Cannot coerce a value to a type that is null, undefined, or not a class")?;
26972696
let value = self.context.avm2.pop();
26982697

2699-
if value.is_of_type(self, class)? {
2698+
if value.is_of_type(self, class) {
27002699
self.context.avm2.push(value);
27012700
} else {
27022701
self.context.avm2.push(Value::Null);

core/src/avm2/globals/json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ impl<'gc> AvmSerializer<'gc> {
233233
return Err("TypeError: Error #1129: Cyclic structure cannot be converted to JSON string.".into());
234234
}
235235
self.obj_stack.push(obj);
236-
let value = if obj.is_of_type(activation.avm2().classes().array, activation)? {
236+
let value = if obj.is_of_type(activation.avm2().classes().array, activation) {
237237
// TODO: Vectors
238238
self.serialize_iterable(activation, obj)?
239239
} else {

core/src/avm2/globals/string.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ fn match_s<'gc>(
223223
let this = Value::from(this).coerce_to_string(activation)?;
224224

225225
let regexp_class = activation.avm2().classes().regexp;
226-
let pattern = if !pattern.is_of_type(activation, regexp_class)? {
226+
let pattern = if !pattern.is_of_type(activation, regexp_class) {
227227
let string = pattern.coerce_to_string(activation)?;
228228
regexp_class.construct(activation, &[Value::String(string)])?
229229
} else {

core/src/avm2/globals/vector.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ pub fn concat<'gc>(
331331
let arg_class = arg_obj
332332
.instance_of_class_definition()
333333
.ok_or("TypeError: Tried to concat from a bare object")?;
334-
if !arg.is_of_type(activation, my_class)? {
334+
if !arg.is_of_type(activation, my_class) {
335335
return Err(format!(
336336
"TypeError: Cannot coerce argument of type {:?} to argument of type {:?}",
337337
arg_class.read().name(),
@@ -349,7 +349,7 @@ pub fn concat<'gc>(
349349

350350
for val in old_vec {
351351
if let Ok(val_obj) = val.coerce_to_object(activation) {
352-
if !val.is_of_type(activation, val_class)? {
352+
if !val.is_of_type(activation, val_class) {
353353
let other_val_class = val_obj
354354
.instance_of_class_definition()
355355
.ok_or("TypeError: Tried to concat a bare object into a Vector")?;

core/src/avm2/object.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -810,17 +810,17 @@ pub trait TObject<'gc>: 'gc + Collect + Debug + Into<Object<'gc>> + Clone + Copy
810810
&self,
811811
test_class: ClassObject<'gc>,
812812
activation: &mut Activation<'_, 'gc, '_>,
813-
) -> Result<bool, Error> {
813+
) -> bool {
814814
let my_class = self.instance_of();
815815

816816
// ES3 objects are not class instances but are still treated as
817817
// instances of Object, which is an ES4 class.
818818
if my_class.is_none() && Object::ptr_eq(test_class, activation.avm2().classes().object) {
819-
Ok(true)
819+
true
820820
} else if let Some(my_class) = my_class {
821821
my_class.has_class_in_chain(test_class)
822822
} else {
823-
Ok(false)
823+
false
824824
}
825825
}
826826

core/src/avm2/object/class_object.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -426,42 +426,38 @@ impl<'gc> ClassObject<'gc> {
426426
/// interface we are checking against this class.
427427
///
428428
/// To test if a class *instance* is of a given type, see is_of_type.
429-
pub fn has_class_in_chain(self, test_class: ClassObject<'gc>) -> Result<bool, Error> {
429+
pub fn has_class_in_chain(self, test_class: ClassObject<'gc>) -> bool {
430430
let mut my_class = Some(self);
431431

432432
while let Some(class) = my_class {
433433
if Object::ptr_eq(class, test_class) {
434-
return Ok(true);
434+
return true;
435435
}
436436

437437
for interface in class.interfaces() {
438438
if Object::ptr_eq(interface, test_class) {
439-
return Ok(true);
439+
return true;
440440
}
441441
}
442442

443443
if let (Some(my_param), Some(test_param)) =
444444
(class.as_class_params(), test_class.as_class_params())
445445
{
446-
let mut are_all_params_coercible = true;
447-
448-
are_all_params_coercible &= match (my_param, test_param) {
449-
(Some(my_param), Some(test_param)) => {
450-
my_param.has_class_in_chain(test_param)?
451-
}
446+
let are_all_params_coercible = match (my_param, test_param) {
447+
(Some(my_param), Some(test_param)) => my_param.has_class_in_chain(test_param),
452448
(None, Some(_)) => false,
453449
_ => true,
454450
};
455451

456452
if are_all_params_coercible {
457-
return Ok(true);
453+
return true;
458454
}
459455
}
460456

461457
my_class = class.superclass_object()
462458
}
463459

464-
Ok(false)
460+
false
465461
}
466462

467463
/// Call the instance initializer.

core/src/avm2/value.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ impl<'gc> Value<'gc> {
940940
}
941941

942942
if let Ok(object) = self.coerce_to_object(activation) {
943-
if object.is_of_type(class, activation)? {
943+
if object.is_of_type(class, activation) {
944944
return Ok(object.into());
945945
}
946946

@@ -1013,21 +1013,21 @@ impl<'gc> Value<'gc> {
10131013
&self,
10141014
activation: &mut Activation<'_, 'gc, '_>,
10151015
type_object: ClassObject<'gc>,
1016-
) -> Result<bool, Error> {
1016+
) -> bool {
10171017
if Object::ptr_eq(type_object, activation.avm2().classes().number) {
1018-
return Ok(self.is_number());
1018+
return self.is_number();
10191019
}
10201020
if Object::ptr_eq(type_object, activation.avm2().classes().uint) {
1021-
return Ok(self.is_u32());
1021+
return self.is_u32();
10221022
}
10231023
if Object::ptr_eq(type_object, activation.avm2().classes().int) {
1024-
return Ok(self.is_i32());
1024+
return self.is_i32();
10251025
}
10261026

10271027
if let Ok(o) = self.coerce_to_object(activation) {
10281028
o.is_of_type(type_object, activation)
10291029
} else {
1030-
Ok(false)
1030+
false
10311031
}
10321032
}
10331033

0 commit comments

Comments
 (0)