avm2/tests: use try_get_object in JSON/Add test for undefined receiver

This commit is contained in:
Lord-McSweeney 2023-04-24 20:19:48 -07:00 committed by Nathan Adams
parent 319886587d
commit f412f62127
3 changed files with 4 additions and 3 deletions

View File

@ -268,7 +268,7 @@ pub fn parse<'gc>(
args: &[Value<'gc>], args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> { ) -> Result<Value<'gc>, Error<'gc>> {
let input = args.get_string(activation, 0)?; let input = args.get_string(activation, 0)?;
let reviver = args.get_value(1).as_object(); let reviver = args.try_get_object(activation, 1);
let parsed = if let Ok(parsed) = serde_json::from_str(&input.to_utf8_lossy()) { let parsed = if let Ok(parsed) = serde_json::from_str(&input.to_utf8_lossy()) {
parsed parsed
@ -290,10 +290,10 @@ pub fn stringify<'gc>(
args: &[Value<'gc>], args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> { ) -> Result<Value<'gc>, Error<'gc>> {
let val = args.get_value(0); let val = args.get_value(0);
let replacer = args.get_value(1).as_object(); let replacer = args.try_get_object(activation, 1);
let spaces = args.get_value(2); let spaces = args.get_value(2);
// If the replacer is None, that means it was a primitive (as_object returns None for primitives), and therefore not a valid replacer // If the replacer is None, that means it was either undefined or null.
if replacer.is_none() && !matches!(args.get(1).unwrap(), Value::Null) { if replacer.is_none() && !matches!(args.get(1).unwrap(), Value::Null) {
return Err(Error::AvmError(type_error( return Err(Error::AvmError(type_error(
activation, activation,

View File

@ -6,3 +6,4 @@ Recursive JSON, invalid object replacer:TypeError|1131
{} {}
Recursive, with null replacer:TypeError|1129 Recursive, with null replacer:TypeError|1129
{"a":8} {"a":8}
Valid, with undefined replacer:TypeError|1131