core: Support failiable constructors
This commit is contained in:
parent
b3dd5c0c0b
commit
23a9c7143a
|
@ -1666,7 +1666,13 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
|
||||||
let constructor = object.get(&method_name.coerce_to_string(self)?, self)?;
|
let constructor = object.get(&method_name.coerce_to_string(self)?, self)?;
|
||||||
if let Value::Object(constructor) = constructor {
|
if let Value::Object(constructor) = constructor {
|
||||||
//TODO: What happens if you `ActionNewMethod` without a method name?
|
//TODO: What happens if you `ActionNewMethod` without a method name?
|
||||||
let this = constructor.construct(self, &args)?;
|
|
||||||
|
let this = match constructor.construct(self, &args) {
|
||||||
|
Ok(x) => Ok(Value::Object(x)),
|
||||||
|
Err(Error::ConstructorFailure) => Ok(Value::Undefined),
|
||||||
|
Err(e) => Err(e),
|
||||||
|
}?;
|
||||||
|
|
||||||
self.context.avm1.push(this);
|
self.context.avm1.push(this);
|
||||||
} else {
|
} else {
|
||||||
avm_warn!(
|
avm_warn!(
|
||||||
|
@ -1692,7 +1698,11 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
|
||||||
let name_value: Value<'gc> = self.resolve(&fn_name)?.into();
|
let name_value: Value<'gc> = self.resolve(&fn_name)?.into();
|
||||||
let constructor = name_value.coerce_to_object(self);
|
let constructor = name_value.coerce_to_object(self);
|
||||||
|
|
||||||
let this = constructor.construct(self, &args)?;
|
let this = match constructor.construct(self, &args) {
|
||||||
|
Ok(x) => Ok(Value::Object(x)),
|
||||||
|
Err(Error::ConstructorFailure) => Ok(Value::Undefined),
|
||||||
|
Err(e) => Err(e),
|
||||||
|
}?;
|
||||||
|
|
||||||
self.context.avm1.push(this);
|
self.context.avm1.push(this);
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,9 @@ pub enum Error<'gc> {
|
||||||
|
|
||||||
#[error("A script has thrown a custom error.")]
|
#[error("A script has thrown a custom error.")]
|
||||||
ThrownValue(Value<'gc>),
|
ThrownValue(Value<'gc>),
|
||||||
|
|
||||||
|
#[error("An object constructor failed.")]
|
||||||
|
ConstructorFailure,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error<'_> {
|
impl Error<'_> {
|
||||||
|
@ -35,6 +38,7 @@ impl Error<'_> {
|
||||||
Error::InvalidSwf(_) => true,
|
Error::InvalidSwf(_) => true,
|
||||||
Error::InvalidDisplayObjectHierarchy => true,
|
Error::InvalidDisplayObjectHierarchy => true,
|
||||||
Error::ThrownValue(_) => false,
|
Error::ThrownValue(_) => false,
|
||||||
|
Error::ConstructorFailure => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ pub fn constructor<'gc>(
|
||||||
|
|
||||||
if width > 2880 || height > 2880 || width <= 0 || height <= 0 {
|
if width > 2880 || height > 2880 || width <= 0 || height <= 0 {
|
||||||
log::warn!("Invalid BitmapData size {}x{}", width, height);
|
log::warn!("Invalid BitmapData size {}x{}", width, height);
|
||||||
return Ok(Value::Undefined);
|
return Err(Error::ConstructorFailure);
|
||||||
}
|
}
|
||||||
|
|
||||||
let transparency = args
|
let transparency = args
|
||||||
|
|
|
@ -12,6 +12,18 @@ false
|
||||||
10
|
10
|
||||||
// bitmap.height (after set to 100)
|
// bitmap.height (after set to 100)
|
||||||
10
|
10
|
||||||
|
// no_args
|
||||||
|
undefined
|
||||||
|
// no_args.width
|
||||||
|
undefined
|
||||||
|
// no_args.height
|
||||||
|
undefined
|
||||||
|
// big_bitmap
|
||||||
|
undefined
|
||||||
|
// big_bitmap.width
|
||||||
|
undefined
|
||||||
|
// big_bitmap.height
|
||||||
|
undefined
|
||||||
// get/set pixel with transparent = true
|
// get/set pixel with transparent = true
|
||||||
// getPixel32(0, 0) after setPixel32(0, 0, 0xffffffff)
|
// getPixel32(0, 0) after setPixel32(0, 0, 0xffffffff)
|
||||||
-1
|
-1
|
||||||
|
@ -906,6 +918,15 @@ a: 32, r: 32, g:32, b:32
|
||||||
-16711936
|
-16711936
|
||||||
// src.getPixel32(1, 1)
|
// src.getPixel32(1, 1)
|
||||||
-1
|
-1
|
||||||
|
// dest.copyChannel(src, src.rectangle, {x: 0, y: 0}, 1, 1)
|
||||||
|
// src.getPixel32(0, 0)
|
||||||
|
-65536
|
||||||
|
// src.getPixel32(0, 1)
|
||||||
|
-16776961
|
||||||
|
// src.getPixel32(1, 0)
|
||||||
|
-16711936
|
||||||
|
// src.getPixel32(1, 1)
|
||||||
|
-1
|
||||||
// dest.copyChannel(src, src.rectangle, Point(0, 0), 1, 2)
|
// dest.copyChannel(src, src.rectangle, Point(0, 0), 1, 2)
|
||||||
// src.getPixel32(0, 0)
|
// src.getPixel32(0, 0)
|
||||||
-65536
|
-65536
|
||||||
|
@ -1086,3 +1107,12 @@ a: 32, r: 32, g:32, b:32
|
||||||
-16711936
|
-16711936
|
||||||
// src.getPixel32(1, 1)
|
// src.getPixel32(1, 1)
|
||||||
-1
|
-1
|
||||||
|
// dest.copyChannel(src, src.rectangle, Point(0, 0), 1, 1)
|
||||||
|
// src.getPixel32(0, 0)
|
||||||
|
-65536
|
||||||
|
// src.getPixel32(0, 1)
|
||||||
|
-16776961
|
||||||
|
// src.getPixel32(1, 0)
|
||||||
|
-16711936
|
||||||
|
// src.getPixel32(1, 1)
|
||||||
|
-1
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue