Skip to content

Commit cf250f7

Browse files
avm2: Coerce return value of native methods
1 parent 2fb9f3a commit cf250f7

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

core/src/avm2/function.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ pub fn exec<'gc>(
201201
}
202202

203203
let signature = &*method.resolved_param_config();
204+
let return_type = method.resolved_return_type();
204205

205206
// Check for too many arguments
206207
if arguments.len() > signature.len() && !method.is_variadic() && !method.is_unchecked()
@@ -231,7 +232,15 @@ pub fn exec<'gc>(
231232
.context
232233
.avm2
233234
.push_call(activation.gc(), method, bound_class);
234-
native_method(&mut activation, receiver, &arguments)
235+
236+
let result = native_method(&mut activation, receiver, &arguments);
237+
result.and_then(|v| {
238+
if let Some(return_type) = return_type {
239+
v.coerce_to_type(&mut activation, return_type)
240+
} else {
241+
Ok(v)
242+
}
243+
})
235244
}
236245
MethodKind::Bytecode(_) => {
237246
// This used to be a one step called Activation::from_method,

0 commit comments

Comments
 (0)