avm2: Fix toString for primitive objects
This commit is contained in:
parent
787b6f5dfb
commit
3f17523879
|
@ -2,6 +2,7 @@
|
|||
|
||||
use crate::avm2::activation::Activation;
|
||||
use crate::avm2::class::{Class, ClassAttributes};
|
||||
use crate::avm2::error::make_error_1004;
|
||||
use crate::avm2::method::{Method, NativeMethodImpl};
|
||||
use crate::avm2::object::{primitive_allocator, FunctionObject, Object, TObject};
|
||||
use crate::avm2::value::Value;
|
||||
|
@ -95,9 +96,9 @@ pub fn call_handler<'gc>(
|
|||
.into())
|
||||
}
|
||||
|
||||
/// Implements `Boolean.toString`
|
||||
/// Implements `Boolean.prototype.toString`
|
||||
fn to_string<'gc>(
|
||||
_activation: &mut Activation<'_, 'gc>,
|
||||
activation: &mut Activation<'_, 'gc>,
|
||||
this: Object<'gc>,
|
||||
_args: &[Value<'gc>],
|
||||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
|
@ -109,7 +110,12 @@ fn to_string<'gc>(
|
|||
};
|
||||
}
|
||||
|
||||
Ok("false".into())
|
||||
let boolean_proto = activation.avm2().classes().boolean.prototype();
|
||||
if Object::ptr_eq(boolean_proto, this) {
|
||||
return Ok("false".into());
|
||||
}
|
||||
|
||||
Err(make_error_1004(activation, "Boolean.prototype.toString"))
|
||||
}
|
||||
|
||||
/// Implements `Boolean.valueOf`
|
||||
|
|
|
@ -311,7 +311,7 @@ pub fn print_with_radix<'gc>(
|
|||
))
|
||||
}
|
||||
|
||||
/// Implements `Number.toString`
|
||||
/// Implements `Number.prototype.toString`
|
||||
fn to_string<'gc>(
|
||||
activation: &mut Activation<'_, 'gc>,
|
||||
this: Object<'gc>,
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use crate::avm2::activation::Activation;
|
||||
use crate::avm2::class::{Class, ClassAttributes};
|
||||
use crate::avm2::error::make_error_1004;
|
||||
use crate::avm2::method::{Method, NativeMethodImpl};
|
||||
use crate::avm2::object::{primitive_allocator, FunctionObject, Object, TObject};
|
||||
use crate::avm2::regexp::RegExpFlags;
|
||||
|
@ -619,9 +620,9 @@ fn to_lower_case<'gc>(
|
|||
.into())
|
||||
}
|
||||
|
||||
/// Implements `String.toString`
|
||||
/// Implements `String.prototype.toString`
|
||||
fn to_string<'gc>(
|
||||
_activation: &mut Activation<'_, 'gc>,
|
||||
activation: &mut Activation<'_, 'gc>,
|
||||
this: Object<'gc>,
|
||||
_args: &[Value<'gc>],
|
||||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
|
@ -631,7 +632,12 @@ fn to_string<'gc>(
|
|||
}
|
||||
}
|
||||
|
||||
Ok("".into())
|
||||
let string_proto = activation.avm2().classes().string.prototype();
|
||||
if Object::ptr_eq(string_proto, this) {
|
||||
return Ok("".into());
|
||||
}
|
||||
|
||||
Err(make_error_1004(activation, "String.prototype.toString"))
|
||||
}
|
||||
|
||||
/// Implements `String.valueOf`
|
||||
|
|
|
@ -115,10 +115,6 @@ impl<'gc> TObject<'gc> for PrimitiveObject<'gc> {
|
|||
self.0.as_ptr() as *const ObjectPtr
|
||||
}
|
||||
|
||||
fn to_string(&self, _activation: &mut Activation<'_, 'gc>) -> Result<Value<'gc>, Error<'gc>> {
|
||||
Ok(self.0.read().primitive)
|
||||
}
|
||||
|
||||
fn to_locale_string(
|
||||
&self,
|
||||
activation: &mut Activation<'_, 'gc>,
|
||||
|
|
Loading…
Reference in New Issue