@awayfl/avm2
Version:
Virtual machine for executing AS3 code
26 lines (25 loc) • 1.19 kB
JavaScript
import { Namespace } from '../abc/lazy/Namespace';
import { assert } from '@awayjs/graphics';
import { release, defineReadOnlyProperty } from '@awayfl/swf-loader';
import { ASNamespace } from '../natives/xml';
import { checkValue } from './checkValue';
export function applyTraits(object, traits) {
release || assert(!object.hasOwnProperty('traits'));
defineReadOnlyProperty(object, 'traits', traits);
var T = traits.getTraitsList();
for (var i = 0; i < T.length; i++) {
var t = T[i];
var p = t;
if (p.value instanceof Namespace) {
// We can't call |object.sec.AXNamespace.FromNamespace(...)| because the
// AXNamespace class may not have been loaded yet. However, at this point we do have a
// valid reference to |object.sec.AXNamespace| because |prepareNativeClass| has
// been called.
p = { value: ASNamespace.FromNamespace.call(object.sec.AXNamespace, p.value) };
}
if (!release && (t.kind === 0 /* TRAIT.Slot */ || t.kind === 6 /* TRAIT.Const */)) {
checkValue(p.value);
}
Object.defineProperty(object, t.multiname.getMangledName(), p);
}
}