avm2: Throw TypeError when 'astype' receives a null/undefined class
This commit is contained in:
parent
7e56c20973
commit
ce0ba7795c
|
@ -2901,17 +2901,23 @@ impl<'a, 'gc> Activation<'a, 'gc> {
|
|||
let class = self
|
||||
.pop_stack()
|
||||
.as_object()
|
||||
.and_then(|c| c.as_class_object())
|
||||
.ok_or("Cannot coerce a value to a type that is null, undefined, or not a class")?;
|
||||
.and_then(|c| c.as_class_object());
|
||||
let value = self.pop_stack();
|
||||
|
||||
if value.is_of_type(self, class) {
|
||||
self.push_stack(value);
|
||||
if let Some(class) = class {
|
||||
if value.is_of_type(self, class) {
|
||||
self.push_stack(value);
|
||||
} else {
|
||||
self.push_stack(Value::Null);
|
||||
}
|
||||
Ok(FrameControl::Continue)
|
||||
} else {
|
||||
self.push_stack(Value::Null);
|
||||
return Err(Error::AvmError(type_error(
|
||||
self,
|
||||
"Error #1009: Cannot access a property or method of a null object reference.",
|
||||
1009,
|
||||
)?));
|
||||
}
|
||||
|
||||
Ok(FrameControl::Continue)
|
||||
}
|
||||
|
||||
fn op_instance_of(&mut self) -> Result<FrameControl<'gc>, Error<'gc>> {
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
package {
|
||||
import flash.display.MovieClip;
|
||||
public class Test {
|
||||
public function Test() {
|
||||
tryCast("Hello", null);
|
||||
tryCast("Hello", undefined);
|
||||
tryCast("Hello", Class);
|
||||
tryCast(Object, null);
|
||||
tryCast(Object, undefined);
|
||||
tryCast(Object, Class);
|
||||
tryCast(null, null);
|
||||
tryCast(null, undefined);
|
||||
tryCast(undefined, null);
|
||||
tryCast(undefined, undefined);
|
||||
}
|
||||
|
||||
private function tryCast(val: *, klass: Class) {
|
||||
try {
|
||||
trace(val + " as " + klass + ": " + (val as klass));
|
||||
} catch(e) {
|
||||
trace("Caught error from `" + val + " as " + klass + "`: " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
Caught error from `Hello as null`: TypeError: Error #1009: Cannot access a property or method of a null object reference.
|
||||
Caught error from `Hello as null`: TypeError: Error #1009: Cannot access a property or method of a null object reference.
|
||||
Hello as [class Class]: null
|
||||
Caught error from `[class Object] as null`: TypeError: Error #1009: Cannot access a property or method of a null object reference.
|
||||
Caught error from `[class Object] as null`: TypeError: Error #1009: Cannot access a property or method of a null object reference.
|
||||
[class Object] as [class Class]: [class Object]
|
||||
Caught error from `null as null`: TypeError: Error #1009: Cannot access a property or method of a null object reference.
|
||||
Caught error from `null as null`: TypeError: Error #1009: Cannot access a property or method of a null object reference.
|
||||
Caught error from `undefined as null`: TypeError: Error #1009: Cannot access a property or method of a null object reference.
|
||||
Caught error from `undefined as null`: TypeError: Error #1009: Cannot access a property or method of a null object reference.
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1 @@
|
|||
num_frames = 1
|
Loading…
Reference in New Issue