avm2: Implement valueOf
This commit is contained in:
parent
aca23b744e
commit
931080cd49
|
@ -304,18 +304,14 @@ pub fn class_init<'gc>(
|
|||
Ok(Value::Undefined)
|
||||
}
|
||||
|
||||
/// Implements `time` property's getter, and the `getTime` method.
|
||||
/// Implements `time` property's getter, and the `getTime` method. This will also be used for `valueOf`.
|
||||
pub fn time<'gc>(
|
||||
_activation: &mut Activation<'_, 'gc, '_>,
|
||||
activation: &mut Activation<'_, 'gc, '_>,
|
||||
this: Option<Object<'gc>>,
|
||||
_args: &[Value<'gc>],
|
||||
) -> Result<Value<'gc>, Error> {
|
||||
if let Some(this) = this.and_then(|this| this.as_date_object()) {
|
||||
if let Some(date) = this.date_time() {
|
||||
return Ok((date.timestamp_millis() as f64).into());
|
||||
} else {
|
||||
return Ok(f64::NAN.into());
|
||||
}
|
||||
return this.value_of(activation.context.gc_context);
|
||||
}
|
||||
|
||||
Ok(Value::Undefined)
|
||||
|
@ -998,6 +994,7 @@ pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>
|
|||
("setUTCFullYear", set_full_year_utc),
|
||||
("getUTCDay", day_utc),
|
||||
("getTimezoneOffset", timezone_offset),
|
||||
("valueOf", time),
|
||||
];
|
||||
write.define_public_builtin_instance_methods(mc, PUBLIC_INSTANCE_METHODS);
|
||||
|
||||
|
|
|
@ -77,7 +77,11 @@ impl<'gc> TObject<'gc> for DateObject<'gc> {
|
|||
}
|
||||
|
||||
fn value_of(&self, _mc: MutationContext<'gc, '_>) -> Result<Value<'gc>, Error> {
|
||||
Ok(Value::Object(Object::from(*self)))
|
||||
if let Some(date) = self.date_time() {
|
||||
return Ok((date.timestamp_millis() as f64).into());
|
||||
} else {
|
||||
return Ok(f64::NAN.into());
|
||||
}
|
||||
}
|
||||
|
||||
fn as_date_object(&self) -> Option<DateObject<'gc>> {
|
||||
|
|
Loading…
Reference in New Issue