@awayfl/avm2
Version:
Virtual machine for executing AS3 code
23 lines (22 loc) • 899 B
JavaScript
import { checkValue } from './checkValue';
import { release } from '@awayfl/swf-loader';
import { scopeStacks } from './scopeStacks';
export function ensureBoxedReceiver(sec, receiver, callable) {
if (receiver && typeof receiver === 'object') {
release || checkValue(receiver);
return receiver;
}
var boxedReceiver = sec.box(receiver);
// Boxing still leaves `null` and `undefined` unboxed, so return the current global instead.
if (!boxedReceiver) {
if (scopeStacks.length) {
boxedReceiver = scopeStacks[scopeStacks.length - 1].topScope().global.object;
}
else if (callable.receiver) {
// If no scripts are on the stack (e.g., for ExternalInterface calls), use the function's
// own global.
boxedReceiver = callable.receiver.scope.global.object;
}
}
return boxedReceiver;
}