avm2: Add class call handlers for Boolean, Number, and (u)int
This commit is contained in:
parent
043f7cdea7
commit
0c6a0e80af
|
@ -82,6 +82,19 @@ fn class_init<'gc>(
|
|||
Ok(Value::Undefined)
|
||||
}
|
||||
|
||||
pub fn call_handler<'gc>(
|
||||
_activation: &mut Activation<'_, 'gc>,
|
||||
_this: Object<'gc>,
|
||||
args: &[Value<'gc>],
|
||||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
Ok(args
|
||||
.get(0)
|
||||
.cloned()
|
||||
.unwrap_or(Value::Bool(false))
|
||||
.coerce_to_boolean()
|
||||
.into())
|
||||
}
|
||||
|
||||
/// Implements `Boolean.toString`
|
||||
fn to_string<'gc>(
|
||||
_activation: &mut Activation<'_, 'gc>,
|
||||
|
@ -131,6 +144,11 @@ pub fn create_class<'gc>(activation: &mut Activation<'_, 'gc>) -> GcCell<'gc, Cl
|
|||
"<Boolean native instance initializer>",
|
||||
mc,
|
||||
));
|
||||
write.set_call_handler(Method::from_builtin(
|
||||
call_handler,
|
||||
"<Boolean call handler>",
|
||||
mc,
|
||||
));
|
||||
|
||||
const AS3_INSTANCE_METHODS: &[(&str, NativeMethodImpl)] =
|
||||
&[("toString", to_string), ("valueOf", value_of)];
|
||||
|
|
|
@ -135,6 +135,19 @@ fn class_init<'gc>(
|
|||
Ok(Value::Undefined)
|
||||
}
|
||||
|
||||
pub fn call_handler<'gc>(
|
||||
activation: &mut Activation<'_, 'gc>,
|
||||
_this: Object<'gc>,
|
||||
args: &[Value<'gc>],
|
||||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
Ok(args
|
||||
.get(0)
|
||||
.cloned()
|
||||
.unwrap_or(Value::Integer(0))
|
||||
.coerce_to_i32(activation)?
|
||||
.into())
|
||||
}
|
||||
|
||||
/// Implements `int.toExponential`
|
||||
use crate::avm2::globals::number::to_exponential;
|
||||
|
||||
|
@ -228,6 +241,7 @@ pub fn create_class<'gc>(activation: &mut Activation<'_, 'gc>) -> GcCell<'gc, Cl
|
|||
"<int native instance initializer>",
|
||||
mc,
|
||||
));
|
||||
write.set_call_handler(Method::from_builtin(call_handler, "<int call handler>", mc));
|
||||
|
||||
// 'length' is a weird undocumented constant in int.
|
||||
// We need to define it, since it shows up in 'describeType'
|
||||
|
|
|
@ -135,6 +135,19 @@ fn class_init<'gc>(
|
|||
Ok(Value::Undefined)
|
||||
}
|
||||
|
||||
pub fn call_handler<'gc>(
|
||||
activation: &mut Activation<'_, 'gc>,
|
||||
_this: Object<'gc>,
|
||||
args: &[Value<'gc>],
|
||||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
Ok(args
|
||||
.get(0)
|
||||
.cloned()
|
||||
.unwrap_or(Value::Number(0.0))
|
||||
.coerce_to_number(activation)?
|
||||
.into())
|
||||
}
|
||||
|
||||
/// Implements `Number.toExponential`
|
||||
pub fn to_exponential<'gc>(
|
||||
activation: &mut Activation<'_, 'gc>,
|
||||
|
@ -373,6 +386,11 @@ pub fn create_class<'gc>(activation: &mut Activation<'_, 'gc>) -> GcCell<'gc, Cl
|
|||
"<Number native instance initializer>",
|
||||
mc,
|
||||
));
|
||||
write.set_call_handler(Method::from_builtin(
|
||||
call_handler,
|
||||
"<Number call handler>",
|
||||
mc,
|
||||
));
|
||||
|
||||
const CLASS_CONSTANTS_NUMBER: &[(&str, f64)] = &[
|
||||
("MAX_VALUE", f64::MAX),
|
||||
|
|
|
@ -135,6 +135,19 @@ fn class_init<'gc>(
|
|||
Ok(Value::Undefined)
|
||||
}
|
||||
|
||||
pub fn call_handler<'gc>(
|
||||
activation: &mut Activation<'_, 'gc>,
|
||||
_this: Object<'gc>,
|
||||
args: &[Value<'gc>],
|
||||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
Ok(args
|
||||
.get(0)
|
||||
.cloned()
|
||||
.unwrap_or(Value::Integer(0))
|
||||
.coerce_to_u32(activation)?
|
||||
.into())
|
||||
}
|
||||
|
||||
/// Implements `uint.toExponential`
|
||||
use crate::avm2::globals::number::to_exponential;
|
||||
|
||||
|
@ -229,6 +242,11 @@ pub fn create_class<'gc>(activation: &mut Activation<'_, 'gc>) -> GcCell<'gc, Cl
|
|||
"<uint native instance initializer>",
|
||||
mc,
|
||||
));
|
||||
write.set_call_handler(Method::from_builtin(
|
||||
call_handler,
|
||||
"<uint call handler>",
|
||||
mc,
|
||||
));
|
||||
|
||||
const CLASS_CONSTANTS_UINT: &[(&str, u32)] =
|
||||
&[("MAX_VALUE", u32::MAX), ("MIN_VALUE", u32::MIN)];
|
||||
|
|
Loading…
Reference in New Issue