avm2: Fix function prototype

This commit is contained in:
Lord-McSweeney 2024-06-20 11:24:39 -07:00 committed by Lord-McSweeney
parent bac18c1a84
commit 13ee356b8c
4 changed files with 11 additions and 10 deletions

View File

@ -2726,25 +2726,24 @@ impl<'a, 'gc> Activation<'a, 'gc> {
Value::Bool(_) => "boolean",
Value::Number(_) | Value::Integer(_) => "number",
Value::Object(o) => {
// Subclasses always have a typeof = "object", must be a subclass if the prototype chain is > 2, or not a subclass if <=2
let is_not_subclass = o
.proto()
.and_then(|p| p.proto())
.and_then(|p| p.proto())
.is_none();
let classes = self.avm2().classes();
match o {
Object::FunctionObject(_) => {
if is_not_subclass {
if o.instance_class() == Some(classes.function.inner_class_definition()) {
"function"
} else {
// Subclasses always have a typeof = "object"
"object"
}
}
Object::XmlObject(_) | Object::XmlListObject(_) => {
if is_not_subclass {
if o.instance_class() == Some(classes.xml_list.inner_class_definition())
|| o.instance_class() == Some(classes.xml.inner_class_definition())
{
"xml"
} else {
// Subclasses always have a typeof = "object"
"object"
}
}

View File

@ -564,6 +564,10 @@ pub fn load_player_globals<'gc>(
let object_class = object_class.into_finished_class(activation)?;
let fn_class = fn_class.into_finished_class(activation)?;
// Function's prototype is an instance of itself
let fn_proto = fn_class.construct(activation, &[])?;
fn_class.link_prototype(activation, fn_proto)?;
// Construct the global class.
let global_classdef = global_scope::create_class(activation);
let global_class = ClassObject::from_class(activation, global_classdef, Some(object_class))?;

View File

@ -1,2 +1 @@
num_frames = 1
known_failure = true

View File

@ -1,2 +1 @@
num_ticks = 1
known_failure = true