swf2js 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE-GPL +680 -0
- package/README.md +208 -2
- package/package.json +24 -4
- package/src/cli.js +272 -0
- package/src/decoder/button-decoder.js +136 -0
- package/src/decoder/shape-decoder.js +786 -0
- package/src/decoder/symbol-table.js +36 -0
- package/src/decoder/tag-decoder.js +1190 -0
- package/src/decoder/tag-types.js +258 -0
- package/src/emitter/asset-encoder.js +708 -0
- package/src/emitter/bundle-emitter.js +596 -0
- package/src/emitter/embedded-swf.js +246 -0
- package/src/emitter/font-encoder.js +365 -0
- package/src/emitter/timeline-data-codec.js +58 -0
- package/src/model/swf-document.js +59 -0
- package/src/model/transpile-result.js +32 -0
- package/src/parser/bit-reader.js +237 -0
- package/src/parser/decompressor.js +91 -0
- package/src/parser/swf-parser.js +164 -0
- package/src/pretty-printer/pretty-printer.js +137 -0
- package/src/runtime/avm1-runtime.js +4907 -0
- package/src/runtime/avm2-runtime.js +1591 -0
- package/src/runtime/embedded-movie-runtime.js +208 -0
- package/src/runtime/index.js +17 -0
- package/src/runtime/movie-runtime.js +306 -0
- package/src/runtime/swflib.js +14050 -0
- package/src/transpiler/actionscript.js +390 -0
- package/src/transpiler/avm1/avm1-ir.js +205 -0
- package/src/transpiler/avm1/avm1-opcodes.js +149 -0
- package/src/transpiler/avm1/avm1-rewrite.js +291 -0
- package/src/transpiler/avm1/avm1-transpiler.js +2082 -0
- package/src/transpiler/avm2/abc-reader.js +416 -0
- package/src/transpiler/avm2/avm2-transpiler.js +2560 -0
- package/src/transpiler/cfg-structurer.js +876 -0
- package/src/transpiler/timeline/display-list.js +643 -0
- package/src/transpiler/timeline/timeline-codegen.js +6354 -0
- package/src/util/diagnostics.js +50 -0
- package/src/util/logger.js +40 -0
|
@@ -0,0 +1,1591 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create AVM2 state for one generated movie. The function is serialized into
|
|
3
|
+
* swflib.js and standalone output, so dependencies stay inside the factory.
|
|
4
|
+
*/
|
|
5
|
+
export function createAvm2Runtime(globalThis, swflib) {
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
var _classes = (swflib && swflib.builtins)
|
|
9
|
+
? Object.assign(Object.create(null), swflib.builtins)
|
|
10
|
+
: {};
|
|
11
|
+
var _avm2PublicTextField = _classes.TextField;
|
|
12
|
+
var _avm2MovieCharacters = globalThis.__swoof?.characters;
|
|
13
|
+
if (_avm2PublicTextField && _avm2MovieCharacters && typeof swflib?.createMovieTextField === 'function') {
|
|
14
|
+
var movieTextField = swflib.createMovieTextField(_avm2MovieCharacters, _avm2PublicTextField);
|
|
15
|
+
_classes.TextField = movieTextField;
|
|
16
|
+
_classes['flash.text.TextField'] = movieTextField;
|
|
17
|
+
_classes['flash.text::TextField'] = movieTextField;
|
|
18
|
+
}
|
|
19
|
+
var _avm2FontDescription = _classes.FontDescription;
|
|
20
|
+
var _avm2MovieFontLookup = globalThis.__swoof?.fontLookup;
|
|
21
|
+
var _avm2TimerFunctions = Object.create(null);
|
|
22
|
+
var _avm2HostTimers = Object.create(null);
|
|
23
|
+
var _avm2UtilsPackage = swflib && swflib.packages && swflib.packages.utils;
|
|
24
|
+
for (var _avm2TimerName of ['setInterval', 'setTimeout', 'clearInterval', 'clearTimeout']) {
|
|
25
|
+
var _avm2TimerFunction = _avm2UtilsPackage && _avm2UtilsPackage[_avm2TimerName];
|
|
26
|
+
if (typeof _avm2TimerFunction === 'function') {
|
|
27
|
+
_avm2TimerFunctions[_avm2TimerName] = _avm2TimerFunctions['flash.utils.' + _avm2TimerName] = _avm2TimerFunction;
|
|
28
|
+
_avm2HostTimers[_avm2TimerName] = globalThis[_avm2TimerName];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (_avm2UtilsPackage?.Proxy) _classes['flash.utils.Proxy'] = _avm2UtilsPackage.Proxy;
|
|
32
|
+
if (_classes.Vector) _classes['__AS3__.vec.Vector'] = _classes.Vector;
|
|
33
|
+
var _avm2Int = _classes.int || (_classes.int = function int(value) { return value | 0; });
|
|
34
|
+
var _avm2Uint = _classes.uint || (_classes.uint = function uint(value) { return value >>> 0; });
|
|
35
|
+
var _avm2ClassMarker = globalThis.Symbol.for('swoof.avm2Class');
|
|
36
|
+
var _avm2BuiltinClassTypes = new globalThis.Set([
|
|
37
|
+
globalThis.Object, globalThis.Function, globalThis.Array, globalThis.Boolean, globalThis.Number,
|
|
38
|
+
globalThis.String, globalThis.Date, globalThis.RegExp, globalThis.Error, globalThis.EvalError,
|
|
39
|
+
globalThis.RangeError, globalThis.ReferenceError, globalThis.SyntaxError, globalThis.TypeError, globalThis.URIError,
|
|
40
|
+
_avm2Int, _avm2Uint, _classes.Vector, _classes.XML, _classes.XMLList,
|
|
41
|
+
]);
|
|
42
|
+
var _avm2XmlPrototype = _classes.XML?.prototype;
|
|
43
|
+
var _avm2XmlListPrototype = _classes.XMLList?.prototype;
|
|
44
|
+
for (var _avm2RuntimeClass of [Class, Namespace, QName]) _markAvm2Class(_avm2RuntimeClass);
|
|
45
|
+
_classes.trace = function trace() {
|
|
46
|
+
if (globalThis.console && typeof globalThis.console.log === 'function') {
|
|
47
|
+
globalThis.console.log.apply(globalThis.console, arguments);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var _avm2ClassLexicalTraits = new globalThis.WeakMap();
|
|
51
|
+
var _avm2EmptyLexicalTraits = new globalThis.Set();
|
|
52
|
+
var _avm2GlobalSlotNames = Object.create(null);
|
|
53
|
+
var _avm2ScriptScopeObjects = Object.create(null);
|
|
54
|
+
var _avm2SuperFrames = [];
|
|
55
|
+
var _avm2InstanceDefaults = new globalThis.WeakMap();
|
|
56
|
+
var _avm2StagedInstances = new globalThis.WeakMap();
|
|
57
|
+
|
|
58
|
+
function _avm2SuperParent(owner, target) {
|
|
59
|
+
var parent = _avm2SuperFrames[_avm2SuperFrames.length - 1];
|
|
60
|
+
return parent && parent.target === target && parent.base === owner ? parent : null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function _initializeAvm2Instance(receiver, owner, target) {
|
|
64
|
+
var parent = _avm2SuperParent(owner, target);
|
|
65
|
+
if (parent && _avm2StagedInstances.has(parent.values)) {
|
|
66
|
+
_applyAvm2Super(receiver, owner, target, parent);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
for (var [key, value] of _avm2InstanceDefaults.get(owner) || []) receiver[key] = value;
|
|
70
|
+
if (parent) _applyAvm2Super(receiver, owner, target, parent);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function _createAvm2PreSuper(owner, target) {
|
|
74
|
+
var parent = _avm2SuperParent(owner, target);
|
|
75
|
+
if (parent && _avm2StagedInstances.has(parent.values)) return parent.values;
|
|
76
|
+
|
|
77
|
+
var values = Object.create(null);
|
|
78
|
+
var constructors = [];
|
|
79
|
+
for (var type = target; typeof type === 'function'; type = Object.getPrototypeOf(type)) {
|
|
80
|
+
constructors.unshift(type);
|
|
81
|
+
}
|
|
82
|
+
for (var type of constructors) {
|
|
83
|
+
for (var [key, value] of _avm2InstanceDefaults.get(type) || []) values[key] = value;
|
|
84
|
+
}
|
|
85
|
+
_avm2StagedInstances.set(values, { type: target, receiver: null });
|
|
86
|
+
return values;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function _beginAvm2Super(owner, target, values, args) {
|
|
90
|
+
var frame = {
|
|
91
|
+
target: target,
|
|
92
|
+
base: Object.getPrototypeOf(owner),
|
|
93
|
+
parent: _avm2SuperParent(owner, target),
|
|
94
|
+
values: values,
|
|
95
|
+
args: args,
|
|
96
|
+
applied: false,
|
|
97
|
+
};
|
|
98
|
+
_avm2SuperFrames.push(frame);
|
|
99
|
+
return frame;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function _endAvm2Super(frame) {
|
|
103
|
+
if (frame && _avm2SuperFrames[_avm2SuperFrames.length - 1] === frame) _avm2SuperFrames.pop();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// The earliest compiled base with a real receiver can expose all staged
|
|
107
|
+
// derived properties before its ActionScript body calls an override.
|
|
108
|
+
function _applyAvm2Super(receiver, owner, target, frame) {
|
|
109
|
+
frame = frame || _avm2SuperParent(owner, target);
|
|
110
|
+
while (frame && !frame.applied) {
|
|
111
|
+
var values = frame.values;
|
|
112
|
+
var staged = _avm2StagedInstances.get(values);
|
|
113
|
+
if (!staged || !staged.receiver) {
|
|
114
|
+
Object.assign(receiver, values);
|
|
115
|
+
// Slot writes can create bookkeeping that Object.assign does not copy.
|
|
116
|
+
for (var key of ['__slots', '__avm2ConstSlotsWritten']) {
|
|
117
|
+
var descriptor = Object.getOwnPropertyDescriptor(values, key);
|
|
118
|
+
if (descriptor) {
|
|
119
|
+
var existing = Object.getOwnPropertyDescriptor(receiver, key);
|
|
120
|
+
if (existing) Object.assign(existing.value, descriptor.value);
|
|
121
|
+
else Object.defineProperty(receiver, key, descriptor);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (staged) staged.receiver = receiver;
|
|
125
|
+
}
|
|
126
|
+
frame.applied = true;
|
|
127
|
+
frame = frame.parent;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Linked frame children must be available to the authored constructor.
|
|
132
|
+
function _bindAvm2Symbol(instance) {
|
|
133
|
+
if (typeof globalThis.__swoof_bindAs3SymbolInstance === 'function') {
|
|
134
|
+
globalThis.__swoof_bindAs3SymbolInstance(instance);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
var _avm2DispatchIds = new WeakMap();
|
|
139
|
+
function _markAvm2Class(type) {
|
|
140
|
+
// Class values can cross movie runtimes within the same bundle.
|
|
141
|
+
Object.defineProperty(type, _avm2ClassMarker, { value: true });
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function _inheritAvm2Accessor(prototype, key) {
|
|
145
|
+
var own = Object.getOwnPropertyDescriptor(prototype, key);
|
|
146
|
+
if (!own || 'value' in own || (own.get && own.set)) return;
|
|
147
|
+
for (var base = Object.getPrototypeOf(prototype); base; base = Object.getPrototypeOf(base)) {
|
|
148
|
+
var inherited = Object.getOwnPropertyDescriptor(base, key);
|
|
149
|
+
if (!inherited) continue;
|
|
150
|
+
// ABC overrides each accessor separately. A JS accessor descriptor shadows both.
|
|
151
|
+
var get = own.get || inherited.get, set = own.set || inherited.set;
|
|
152
|
+
if (get !== own.get || set !== own.set) {
|
|
153
|
+
Object.defineProperty(prototype, key, { ...own, get: get, set: set });
|
|
154
|
+
}
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function _registerAvm2Class(type, classTable, classIndex, name, traits = {}) {
|
|
160
|
+
_markAvm2Class(type);
|
|
161
|
+
if (traits.definitionKey) Object.defineProperty(type, 'name', { value: name, configurable: true });
|
|
162
|
+
if (traits.instanceValues) _avm2InstanceDefaults.set(type, traits.instanceValues);
|
|
163
|
+
for (var [key, value] of traits.staticValues || []) {
|
|
164
|
+
if (key === 'name') {
|
|
165
|
+
// AS3 static fields can use the otherwise read-only JS class name.
|
|
166
|
+
Object.defineProperty(type, key, { value: value, writable: true, configurable: true });
|
|
167
|
+
} else {
|
|
168
|
+
type[key] = value;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
_avm2ClassLexicalTraits.set(type, traits.lexical ? new globalThis.Set(traits.lexical) : _avm2EmptyLexicalTraits);
|
|
172
|
+
var base = Object.getPrototypeOf(type) || {};
|
|
173
|
+
type.__avm2InstanceSlots = Object.assign(Object.create(base.__avm2InstanceSlots || null), traits.instanceSlotNames);
|
|
174
|
+
type.__avm2StaticSlots = traits.staticSlotNames || {};
|
|
175
|
+
type.__avm2InstanceConstSlots = Object.assign(Object.create(base.__avm2InstanceConstSlots || null), traits.instanceConstSlots);
|
|
176
|
+
type.__avm2StaticConstSlots = traits.staticConstSlots || {};
|
|
177
|
+
var dispatch = Object.create(base.__avm2DispatchMethods || null);
|
|
178
|
+
var baseDispatchIds = _avm2DispatchIds.get(base);
|
|
179
|
+
var qualifiedIds = Object.create(baseDispatchIds?.qualified || null);
|
|
180
|
+
var protectedIds = Object.create(baseDispatchIds?.protected || null);
|
|
181
|
+
var automatic = Object.create(baseDispatchIds?.automatic || null);
|
|
182
|
+
var automaticSlots = Object.create(baseDispatchIds?.automaticSlots || null);
|
|
183
|
+
var automaticProtectedSlots = Object.create(baseDispatchIds?.automaticProtectedSlots || null);
|
|
184
|
+
// Adobe's Object contributes three instance methods. callmethod encodes
|
|
185
|
+
// the vtable offset plus one. Other native bases lack a known layout here.
|
|
186
|
+
var next = baseDispatchIds?.next ?? (traits.objectDispatchBase ? 4 : null);
|
|
187
|
+
for (var [id, method, traitName, protectedName, overrides, kind = 1] of traits.dispatch || []) {
|
|
188
|
+
if (next != null) {
|
|
189
|
+
var slot = protectedName
|
|
190
|
+
? (overrides || kind !== 1 ? automaticProtectedSlots[protectedName] : null)
|
|
191
|
+
: automaticSlots[traitName];
|
|
192
|
+
if (slot == null) {
|
|
193
|
+
slot = next;
|
|
194
|
+
next += kind === 1 ? 1 : 2;
|
|
195
|
+
}
|
|
196
|
+
automaticSlots[traitName] = slot;
|
|
197
|
+
if (protectedName) automaticProtectedSlots[protectedName] = slot;
|
|
198
|
+
if (kind === 1) automatic[slot] = type.prototype[method];
|
|
199
|
+
}
|
|
200
|
+
if (kind !== 1) {
|
|
201
|
+
// Protected namespace families are linked separately after registration.
|
|
202
|
+
if (!protectedName) _inheritAvm2Accessor(type.prototype, method);
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
if (protectedName) {
|
|
206
|
+
// Each class has its own protected namespace. Follow the declared
|
|
207
|
+
// override family through its superclass rather than comparing QNames.
|
|
208
|
+
id = id || (overrides ? protectedIds[protectedName] : 0);
|
|
209
|
+
protectedIds[protectedName] = id || 0;
|
|
210
|
+
} else {
|
|
211
|
+
id = id || (overrides !== false ? qualifiedIds[traitName] : 0);
|
|
212
|
+
}
|
|
213
|
+
if (!id) continue;
|
|
214
|
+
dispatch[id] = type.prototype[method];
|
|
215
|
+
qualifiedIds[traitName] = id;
|
|
216
|
+
}
|
|
217
|
+
type.__avm2DispatchMethods = dispatch;
|
|
218
|
+
_avm2DispatchIds.set(type, {
|
|
219
|
+
qualified: qualifiedIds, protected: protectedIds, automatic, automaticSlots, automaticProtectedSlots, next,
|
|
220
|
+
});
|
|
221
|
+
classTable[classIndex] = type;
|
|
222
|
+
var qualifiedName = traits.namespace ? traits.namespace + '.' + name : name;
|
|
223
|
+
type.__swoofQualifiedName = qualifiedName;
|
|
224
|
+
if (traits.reflection) Object.defineProperty(type, '__avm2Reflection', { value: traits.reflection });
|
|
225
|
+
type.__swoofDynamic = !traits.sealed;
|
|
226
|
+
_classes[traits.definitionKey || qualifiedName] = type;
|
|
227
|
+
if (traits.propertyKey && !Object.prototype.hasOwnProperty.call(_classes, traits.propertyKey)) {
|
|
228
|
+
_classes[traits.propertyKey] = type;
|
|
229
|
+
}
|
|
230
|
+
if (!traits.definitionKey && !Object.prototype.hasOwnProperty.call(_classes, name)) _classes[name] = type;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function _registerAvm2Methods(type, table, methods) {
|
|
234
|
+
for (var [index, name, isStatic] of methods) {
|
|
235
|
+
table[index] = _avm2MethodEntry(isStatic ? type : type.prototype, name, true);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
var _avm2NamespaceKeys = globalThis.Symbol.for('swoof.avm2NamespaceKeys');
|
|
240
|
+
var _avm2NamespaceKind = globalThis.Symbol.for('swoof.avm2NamespaceKind');
|
|
241
|
+
var _avm2QNameNamespace = globalThis.Symbol.for('swoof.avm2QNameNamespace');
|
|
242
|
+
var _avm2NamespaceConstants = new globalThis.Map();
|
|
243
|
+
|
|
244
|
+
function Namespace(prefix, uri) {
|
|
245
|
+
if (!(this instanceof Namespace)) return Reflect.construct(Namespace, Array.from(arguments));
|
|
246
|
+
var copied = arguments.length === 1 && prefix && prefix[_avm2NamespaceKeys];
|
|
247
|
+
if (copied) {
|
|
248
|
+
this.prefix = prefix.prefix;
|
|
249
|
+
this.uri = prefix.uri;
|
|
250
|
+
} else {
|
|
251
|
+
var source = arguments.length > 1 ? uri : prefix;
|
|
252
|
+
this.uri = source && _avm2QNameNamespace in Object(source) ? (source.uri ?? '')
|
|
253
|
+
: arguments.length ? String(source) : '';
|
|
254
|
+
this.prefix = arguments.length > 1 ? prefix == null ? undefined : String(prefix)
|
|
255
|
+
: this.uri ? undefined : '';
|
|
256
|
+
if (!this.uri && this.prefix !== '') throw new TypeError('Empty namespace URI requires an empty prefix');
|
|
257
|
+
}
|
|
258
|
+
var hash = 0x811c9dc5;
|
|
259
|
+
for (var i = 0; i < this.uri.length; i++) hash = Math.imul(hash ^ this.uri.charCodeAt(i), 0x01000193);
|
|
260
|
+
var publicKey = this.uri === 'http://adobe.com/AS3/2006/builtin' ? '' : this.uri + '.';
|
|
261
|
+
var keys = this.uri ? ['__avm2ns_8_uri_' + (hash >>> 0).toString(16) + '_', publicKey] : [''];
|
|
262
|
+
Object.defineProperty(this, _avm2NamespaceKeys, { value: copied || keys });
|
|
263
|
+
Object.defineProperty(this, _avm2NamespaceKind, { value: copied ? prefix[_avm2NamespaceKind] : 0x08 });
|
|
264
|
+
Object.freeze(this);
|
|
265
|
+
}
|
|
266
|
+
Namespace.prototype.toString = function () { return this.uri; };
|
|
267
|
+
|
|
268
|
+
function QName(namespace, name) {
|
|
269
|
+
if (!(this instanceof QName)) return Reflect.construct(QName, Array.from(arguments));
|
|
270
|
+
if (arguments.length === 1 && namespace && _avm2QNameNamespace in Object(namespace)) {
|
|
271
|
+
this.localName = namespace.localName;
|
|
272
|
+
namespace = namespace[_avm2QNameNamespace];
|
|
273
|
+
} else if (arguments.length < 2) {
|
|
274
|
+
this.localName = arguments.length ? String(namespace) : '';
|
|
275
|
+
namespace = Namespace();
|
|
276
|
+
} else {
|
|
277
|
+
this.localName = name && _avm2QNameNamespace in Object(name) ? name.localName : String(name);
|
|
278
|
+
if (namespace !== null && !(namespace && namespace[_avm2NamespaceKeys])) {
|
|
279
|
+
namespace = namespace === undefined ? Namespace() : Namespace(namespace);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
this.uri = namespace === null ? null : namespace.uri;
|
|
283
|
+
Object.defineProperty(this, _avm2QNameNamespace, { value: namespace });
|
|
284
|
+
Object.freeze(this);
|
|
285
|
+
}
|
|
286
|
+
QName.prototype.toString = function () { return this.uri === '' ? this.localName : (this.uri ?? '*') + '::' + this.localName; };
|
|
287
|
+
_classes.Namespace = Namespace;
|
|
288
|
+
_classes.QName = QName;
|
|
289
|
+
|
|
290
|
+
function _avm2NamespaceConstant(uri, prefixes, kind = 0x08) {
|
|
291
|
+
if (kind === 0x16) kind = 0x08; // Namespace and PackageNamespace are both public.
|
|
292
|
+
var id = JSON.stringify([uri, prefixes, kind]);
|
|
293
|
+
if (_avm2NamespaceConstants.has(id)) return _avm2NamespaceConstants.get(id);
|
|
294
|
+
var value = Object.create(Namespace.prototype);
|
|
295
|
+
value.uri = uri;
|
|
296
|
+
value.prefix = uri ? undefined : '';
|
|
297
|
+
Object.defineProperty(value, _avm2NamespaceKeys, { value: prefixes });
|
|
298
|
+
Object.defineProperty(value, _avm2NamespaceKind, { value: kind });
|
|
299
|
+
Object.freeze(value);
|
|
300
|
+
_avm2NamespaceConstants.set(id, value);
|
|
301
|
+
return value;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function _avm2Equals(left, right) {
|
|
305
|
+
if (left === right) return true;
|
|
306
|
+
var leftKind = left?.[_avm2NamespaceKind];
|
|
307
|
+
var rightKind = right?.[_avm2NamespaceKind];
|
|
308
|
+
if (leftKind !== undefined || rightKind !== undefined) {
|
|
309
|
+
return leftKind === rightKind && leftKind !== 0x05 && left.uri === right.uri;
|
|
310
|
+
}
|
|
311
|
+
return left == right;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function _avm2RuntimeKeys(namespace, name, prefixes) {
|
|
315
|
+
if (name && _avm2QNameNamespace in Object(name)) {
|
|
316
|
+
namespace = name[_avm2QNameNamespace];
|
|
317
|
+
name = name.localName;
|
|
318
|
+
if (namespace === null) throw new TypeError('Wildcard runtime QName property access is unsupported');
|
|
319
|
+
prefixes = null;
|
|
320
|
+
}
|
|
321
|
+
if (!prefixes) {
|
|
322
|
+
prefixes = namespace && namespace[_avm2NamespaceKeys];
|
|
323
|
+
if (!prefixes) throw new TypeError('Runtime namespace operand must be a Namespace');
|
|
324
|
+
}
|
|
325
|
+
var local = String(name);
|
|
326
|
+
return prefixes.map(function (prefix) { return prefix + local; });
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function _avm2E4XProperty(receiver, operation, attribute, namespace, name, uris, value, defaultXmlNamespace) {
|
|
330
|
+
if (!receiver || typeof receiver._swoofXmlProperty !== 'function') {
|
|
331
|
+
throw new TypeError('XML selector requires XML or XMLList');
|
|
332
|
+
}
|
|
333
|
+
var prefix;
|
|
334
|
+
var explicit = Boolean(namespace);
|
|
335
|
+
if (name && _avm2QNameNamespace in Object(name)) {
|
|
336
|
+
explicit = true;
|
|
337
|
+
namespace = name[_avm2QNameNamespace];
|
|
338
|
+
uris = namespace === null ? [null] : null;
|
|
339
|
+
name = name.localName;
|
|
340
|
+
}
|
|
341
|
+
if (!uris) {
|
|
342
|
+
if (!namespace || !namespace[_avm2NamespaceKeys]) throw new TypeError('Runtime XML namespace must be a Namespace');
|
|
343
|
+
uris = [namespace.uri];
|
|
344
|
+
prefix = namespace.prefix;
|
|
345
|
+
}
|
|
346
|
+
name = String(name);
|
|
347
|
+
if (!attribute && name.startsWith('@')) {
|
|
348
|
+
attribute = true;
|
|
349
|
+
name = name.slice(1);
|
|
350
|
+
}
|
|
351
|
+
if (!attribute && !explicit && name !== '*' && defaultXmlNamespace !== undefined &&
|
|
352
|
+
uris.includes('') && !uris.includes(null)) uris = [defaultXmlNamespace];
|
|
353
|
+
return receiver._swoofXmlProperty(operation, { name: name, uris: uris, attribute: attribute, prefix: prefix }, value);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
function _avm2GetLexicalXmlAttribute(scopes, attribute, namespace, name, uris) {
|
|
357
|
+
for (var index = scopes.length - 1; index >= 0; index--) {
|
|
358
|
+
var scope = scopes[index];
|
|
359
|
+
if (typeof scope?._swoofXmlProperty === 'function') {
|
|
360
|
+
return _avm2E4XProperty(scope, 'get', attribute, namespace, name, uris);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
throw new ReferenceError('XML attribute ' + name + ' was not found');
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
function _avm2UsesPublicArrayIndex(receiver, operands) {
|
|
367
|
+
var name = operands[1];
|
|
368
|
+
return Array.isArray(receiver) && operands[0] == null && operands[2]?.includes('') &&
|
|
369
|
+
(typeof name === 'number' || typeof name === 'string') && /^(0|[1-9]\d*)$/.test(name) &&
|
|
370
|
+
Number(name) < 0xffffffff;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
function _avm2GetLateProperty(receiver, operands, xmlUris, defaultXmlNamespace) {
|
|
374
|
+
var name = operands[1];
|
|
375
|
+
if (_avm2IsDictionaryKey(receiver, operands)) return receiver.get(name);
|
|
376
|
+
if (_avm2UsesPublicArrayIndex(receiver, operands)) return receiver[name];
|
|
377
|
+
if (receiver && typeof receiver._swoofXmlProperty === 'function' && !((typeof name === 'string' || typeof name === 'number') && /^\d+$/.test(name))) {
|
|
378
|
+
return _avm2E4XProperty(receiver, 'get', false, operands[0], name, xmlUris, undefined, defaultXmlNamespace);
|
|
379
|
+
}
|
|
380
|
+
return _avm2GetProperty(receiver, '', _avm2RuntimeKeys(...operands));
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function _avm2DeleteLateProperty(receiver, operands, xmlUris, defaultXmlNamespace) {
|
|
384
|
+
var name = operands[1];
|
|
385
|
+
if (_avm2IsDictionaryKey(receiver, operands)) { receiver.delete(name); return true; }
|
|
386
|
+
if (_avm2UsesPublicArrayIndex(receiver, operands)) return delete receiver[name];
|
|
387
|
+
if (receiver && typeof receiver._swoofXmlProperty === 'function' && !((typeof name === 'string' || typeof name === 'number') && /^\d+$/.test(name))) {
|
|
388
|
+
return _avm2E4XProperty(receiver, 'delete', false, operands[0], name, xmlUris, undefined, defaultXmlNamespace);
|
|
389
|
+
}
|
|
390
|
+
return _avm2DeleteProperty(receiver, '', _avm2RuntimeKeys(...operands));
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
function _avm2NamedXmlProperty(receiver, operation, name, keys, localName, xmlUris, defaultXmlNamespace, value) {
|
|
394
|
+
if (receiver && typeof receiver._swoofXmlProperty === 'function' && !/^\d+$/.test(localName)) {
|
|
395
|
+
return _avm2E4XProperty(receiver, operation, false, null, localName, xmlUris, value, defaultXmlNamespace);
|
|
396
|
+
}
|
|
397
|
+
if (operation === 'get') return _avm2GetProperty(receiver, name, keys);
|
|
398
|
+
if (operation === 'delete') return keys ? _avm2DeleteProperty(receiver, name, keys) : delete receiver[name];
|
|
399
|
+
if (keys) return _avm2SetProperty(receiver, name, value, keys);
|
|
400
|
+
return receiver[name] = value;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
function _avm2XmlConstructorArgs(ctor, args, defaultXmlNamespace) {
|
|
404
|
+
if (!defaultXmlNamespace) return args;
|
|
405
|
+
var builtins = swflib && swflib.builtins;
|
|
406
|
+
if (builtins && (ctor === builtins.XML || ctor === builtins.XMLList)) return [args[0], defaultXmlNamespace];
|
|
407
|
+
if (ctor === QName && args.length === 1 && !(args[0] && _avm2QNameNamespace in Object(args[0]))) {
|
|
408
|
+
return [Namespace(defaultXmlNamespace), args[0]];
|
|
409
|
+
}
|
|
410
|
+
if (ctor === QName && args.length > 1 && args[0] === undefined) {
|
|
411
|
+
return [Namespace(defaultXmlNamespace), args[1]];
|
|
412
|
+
}
|
|
413
|
+
return args;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
function _avm2Construct(ctor, args, defaultXmlNamespace) {
|
|
417
|
+
return Reflect.construct(ctor, _avm2XmlConstructorArgs(ctor, args, defaultXmlNamespace));
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
function _avm2SetLateProperty(receiver, operands, value, xmlUris, defaultXmlNamespace) {
|
|
421
|
+
var name = operands[1];
|
|
422
|
+
if (_avm2IsDictionaryKey(receiver, operands)) return receiver.set(name, value);
|
|
423
|
+
if (_avm2UsesPublicArrayIndex(receiver, operands)) return receiver[name] = value;
|
|
424
|
+
if (receiver && typeof receiver._swoofSetXmlIndex === 'function' &&
|
|
425
|
+
(typeof name === 'number' || typeof name === 'string') && /^(0|[1-9]\d*)$/.test(name)) {
|
|
426
|
+
return receiver._swoofSetXmlIndex(Number(name), value);
|
|
427
|
+
}
|
|
428
|
+
if (arguments.length > 3 && receiver && typeof receiver._swoofXmlProperty === 'function' &&
|
|
429
|
+
!((typeof name === 'string' || typeof name === 'number') && /^\d+$/.test(name))) {
|
|
430
|
+
return _avm2E4XProperty(receiver, 'set', false, operands[0], name, xmlUris, value, defaultXmlNamespace);
|
|
431
|
+
}
|
|
432
|
+
var qname = name && _avm2QNameNamespace in Object(name);
|
|
433
|
+
if (!qname) name = String(name);
|
|
434
|
+
var keys = _avm2RuntimeKeys(operands[0], name, operands[2]);
|
|
435
|
+
return _avm2SetProperty(receiver, qname ? name.localName : name, value, keys);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
function _avm2CallLateProperty(receiver, operands, args, lexical, defaultXmlNamespace) {
|
|
439
|
+
if (_avm2IsDictionaryKey(receiver, operands)) {
|
|
440
|
+
return _avm2Call(receiver.get(operands[1]), lexical ? null : receiver, args, defaultXmlNamespace);
|
|
441
|
+
}
|
|
442
|
+
var keys = _avm2RuntimeKeys(...operands);
|
|
443
|
+
return _avm2CallProperty(receiver, keys[0], args, keys, lexical, defaultXmlNamespace);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
function _avm2ConstructLateProperty(receiver, operands, args, defaultXmlNamespace) {
|
|
447
|
+
if (_avm2IsDictionaryKey(receiver, operands)) {
|
|
448
|
+
return _avm2Construct(receiver.get(operands[1]), args, defaultXmlNamespace);
|
|
449
|
+
}
|
|
450
|
+
var keys = _avm2RuntimeKeys(...operands);
|
|
451
|
+
return _avm2Construct(_avm2GetProperty(receiver, keys[0], keys), args, defaultXmlNamespace);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
function _createAvm2NamespaceKeys(prefixSets, entries) {
|
|
455
|
+
var cache = new Array(entries.length);
|
|
456
|
+
function lookup(index) {
|
|
457
|
+
if (cache[index]) return cache[index];
|
|
458
|
+
var [set, name] = entries[index];
|
|
459
|
+
return cache[index] = prefixSets[set].map(function (prefix) { return prefix + name; });
|
|
460
|
+
}
|
|
461
|
+
lookup.prefixes = function (index) { return prefixSets[index]; };
|
|
462
|
+
return lookup;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
var _avm2ClassScopes = new globalThis.WeakMap();
|
|
466
|
+
|
|
467
|
+
function _captureAvm2ClassScopes(type, scopes, defaultXmlNamespace) {
|
|
468
|
+
if (typeof type === 'function') _avm2ClassScopes.set(type, { captured: scopes, defaultXmlNamespace: defaultXmlNamespace, cache: new globalThis.Map() });
|
|
469
|
+
return type;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
function _avm2ClassDefaultXmlNamespace(type) {
|
|
473
|
+
return _avm2ClassScopes.get(type)?.defaultXmlNamespace;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
function _avm2ClassParent(type) {
|
|
477
|
+
var parent = Object.getPrototypeOf(type);
|
|
478
|
+
if (typeof parent === 'function' && parent !== globalThis.Function.prototype) return parent;
|
|
479
|
+
// Native display shims can link instance prototypes without linking their
|
|
480
|
+
// JavaScript constructors.
|
|
481
|
+
var prototype = type.prototype && Object.getPrototypeOf(type.prototype);
|
|
482
|
+
return prototype && prototype.constructor;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
function _getAvm2OuterScopes(type, scriptScope, depth, instance) {
|
|
486
|
+
if (!depth) return [];
|
|
487
|
+
if (typeof type !== 'function') return [scriptScope].concat(new Array(depth - 1));
|
|
488
|
+
var state = _avm2ClassScopes.get(type);
|
|
489
|
+
if (!state) _avm2ClassScopes.set(type, state = { captured: null, cache: new globalThis.Map() });
|
|
490
|
+
var key = depth * 2 + (instance ? 1 : 0);
|
|
491
|
+
if (state.cache.has(key)) return state.cache.get(key);
|
|
492
|
+
|
|
493
|
+
var scopes;
|
|
494
|
+
if (state.captured) {
|
|
495
|
+
scopes = state.captured.slice();
|
|
496
|
+
if (instance) scopes.push(type);
|
|
497
|
+
scopes.length = depth;
|
|
498
|
+
} else {
|
|
499
|
+
// Class initializers are queued before script initialization. Until the
|
|
500
|
+
// corresponding newclass executes, infer the usual class scope layout.
|
|
501
|
+
var types = instance ? [type] : [];
|
|
502
|
+
var visited = new globalThis.Set([type]);
|
|
503
|
+
for (var parent = _avm2ClassParent(type); typeof parent === 'function' && !visited.has(parent); parent = _avm2ClassParent(parent)) {
|
|
504
|
+
visited.add(parent);
|
|
505
|
+
types.push(parent);
|
|
506
|
+
}
|
|
507
|
+
types = types.slice(0, depth - 1).reverse();
|
|
508
|
+
scopes = [scriptScope].concat(new Array(depth - 1 - types.length), types);
|
|
509
|
+
}
|
|
510
|
+
state.cache.set(key, scopes);
|
|
511
|
+
return scopes;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
function _scriptScopeKey(abcId, scopeId) { return String(abcId) + ':' + String(scopeId); }
|
|
515
|
+
|
|
516
|
+
function _createAvm2ScriptScope(abcId, scopeId, parent, scopeCount) {
|
|
517
|
+
var key = _scriptScopeKey(abcId, scopeId);
|
|
518
|
+
var scope = scopeCount <= 1 ? (parent || globalThis) : Object.create(parent || globalThis);
|
|
519
|
+
_avm2ScriptScopeObjects[key] = scope;
|
|
520
|
+
return scope;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
function _createAvm2ScriptScopes(abcId, scripts) {
|
|
524
|
+
var scopes = [];
|
|
525
|
+
var parent = globalThis;
|
|
526
|
+
for (var i = 0; i < scripts.length; i++) {
|
|
527
|
+
parent = _createAvm2ScriptScope(abcId, i, parent, scripts.length);
|
|
528
|
+
scopes.push(parent);
|
|
529
|
+
}
|
|
530
|
+
for (var i = 0; i < scripts.length; i++) {
|
|
531
|
+
var scope = scopes[i];
|
|
532
|
+
for (var trait of scripts[i]) {
|
|
533
|
+
if (typeof trait === 'string') _seedScriptTrait(scope, trait);
|
|
534
|
+
else {
|
|
535
|
+
var name = trait[0];
|
|
536
|
+
_seedScriptTrait(scope, name, trait[4]);
|
|
537
|
+
if (trait.length === 5 && name !== trait[3]) {
|
|
538
|
+
_seedScriptTrait(scope, trait[3], trait[4]);
|
|
539
|
+
_classes[trait[3]] = trait[4];
|
|
540
|
+
}
|
|
541
|
+
if (trait[1]) _registerGlobalSlot(abcId, i, trait[1], trait[2] === 4 ? trait[3] || name : name, trait[2], scope);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
return scopes;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
var _avm2ScriptMethodScopes = new Map();
|
|
549
|
+
function _registerAvm2ScriptMethod(scope, name, method, qualifiedName) {
|
|
550
|
+
var bound = method.bind(scope);
|
|
551
|
+
_seedScriptTrait(scope, name, bound);
|
|
552
|
+
if (qualifiedName) _seedScriptTrait(scope, qualifiedName, bound);
|
|
553
|
+
_avm2ScriptMethodScopes.set(qualifiedName || name, scope);
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
function _registerGlobalSlot(abcId, scopeId, slotId, name, kind, scope) {
|
|
557
|
+
// Retain the previous helper signature for out-of-tree generated bundles.
|
|
558
|
+
if (arguments.length <= 4) {
|
|
559
|
+
kind = name; name = slotId; slotId = scopeId; scopeId = 0;
|
|
560
|
+
}
|
|
561
|
+
var key = _scriptScopeKey(abcId, scopeId);
|
|
562
|
+
var slots = _avm2GlobalSlotNames[key] || (_avm2GlobalSlotNames[key] = Object.create(null));
|
|
563
|
+
slots[slotId] = { name: name, kind: kind };
|
|
564
|
+
if (scope) _avm2ScriptScopeObjects[key] = scope;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
function _getGlobalSlot(abcId, scopeId, slotId) {
|
|
568
|
+
if (slotId === undefined) { slotId = scopeId; scopeId = 0; }
|
|
569
|
+
var key = _scriptScopeKey(abcId, scopeId);
|
|
570
|
+
var slots = _avm2GlobalSlotNames[key];
|
|
571
|
+
var entry = slots && slots[slotId];
|
|
572
|
+
if (!entry) return globalThis.__slots && globalThis.__slots[slotId];
|
|
573
|
+
var scope = _avm2ScriptScopeObjects[key] || globalThis;
|
|
574
|
+
if (entry.kind === 4) {
|
|
575
|
+
var type = entry.name in scope ? scope[entry.name] : _getlex(entry.name);
|
|
576
|
+
if (type !== undefined) return type;
|
|
577
|
+
}
|
|
578
|
+
return scope[entry.name];
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
function _setGlobalSlot(abcId, scopeId, slotId, value) {
|
|
582
|
+
if (arguments.length === 3) { value = slotId; slotId = scopeId; scopeId = 0; }
|
|
583
|
+
var key = _scriptScopeKey(abcId, scopeId);
|
|
584
|
+
var slots = _avm2GlobalSlotNames[key];
|
|
585
|
+
var entry = slots && slots[slotId];
|
|
586
|
+
var scope = _avm2ScriptScopeObjects[key] || globalThis;
|
|
587
|
+
if (entry) scope[entry.name] = value;
|
|
588
|
+
else {
|
|
589
|
+
if (!globalThis.__slots) globalThis.__slots = [];
|
|
590
|
+
globalThis.__slots[slotId] = value;
|
|
591
|
+
}
|
|
592
|
+
return value;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
var _avm2VectorTypeCache = new WeakMap();
|
|
596
|
+
var _avm2ClassInitializers = [];
|
|
597
|
+
var _avm2ScriptInitializers = [];
|
|
598
|
+
var _avm2PendingInterfaces = [];
|
|
599
|
+
|
|
600
|
+
function _queueAvm2ClassInitializer(initializer) { _avm2ClassInitializers.push(initializer); }
|
|
601
|
+
function _queueAvm2ScriptInitializer(initializer) { _avm2ScriptInitializers.push(initializer); }
|
|
602
|
+
function _runAvm2Initializers() {
|
|
603
|
+
_linkAvm2Interfaces();
|
|
604
|
+
var classInitializers = _avm2ClassInitializers.splice(0);
|
|
605
|
+
var scriptInitializers = _avm2ScriptInitializers.splice(0);
|
|
606
|
+
for (var i = 0; i < classInitializers.length; i++) classInitializers[i]();
|
|
607
|
+
for (var j = 0; j < scriptInitializers.length; j++) scriptInitializers[j]();
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
var _avm2ProtectedTraits = globalThis.Symbol.for('swoof.avm2ProtectedTraits');
|
|
611
|
+
|
|
612
|
+
function _ownAvm2ProtectedTraits(prototype) {
|
|
613
|
+
return prototype && Object.prototype.hasOwnProperty.call(prototype, _avm2ProtectedTraits)
|
|
614
|
+
? prototype[_avm2ProtectedTraits] : null;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
function _defineAvm2ProtectedSlot(prototype, key) {
|
|
618
|
+
// A slot lives on the instance. A prototype descriptor makes inherited
|
|
619
|
+
// namespace aliases and lexical super share that one storage location.
|
|
620
|
+
Object.defineProperty(prototype, key, {
|
|
621
|
+
configurable: true,
|
|
622
|
+
get: function () {
|
|
623
|
+
var slot = Object.getOwnPropertyDescriptor(this, key);
|
|
624
|
+
return slot && slot.value;
|
|
625
|
+
},
|
|
626
|
+
set: function (value) {
|
|
627
|
+
Object.defineProperty(this, key, { value: value, writable: true, enumerable: true, configurable: true });
|
|
628
|
+
},
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
function _registerAvm2ProtectedTraits(type, prefix, declared, slots = []) {
|
|
633
|
+
var prototype = type.prototype;
|
|
634
|
+
var parent = Object.getPrototypeOf(prototype);
|
|
635
|
+
var inherited = _ownAvm2ProtectedTraits(parent);
|
|
636
|
+
var members = new globalThis.Map();
|
|
637
|
+
var overrides = new globalThis.Map(declared);
|
|
638
|
+
for (var slot of slots) _defineAvm2ProtectedSlot(prototype, prefix + slot);
|
|
639
|
+
var names = new globalThis.Set([...overrides.keys(), ...slots, ...(inherited ? inherited.members.keys() : [])]);
|
|
640
|
+
for (var name of names) {
|
|
641
|
+
var key = prefix + name;
|
|
642
|
+
var own = Object.getOwnPropertyDescriptor(prototype, key);
|
|
643
|
+
var aliases = inherited && inherited.members.get(name);
|
|
644
|
+
var bindsInherited = false;
|
|
645
|
+
if (aliases) {
|
|
646
|
+
var base = Object.getOwnPropertyDescriptor(parent, inherited.prefix + name);
|
|
647
|
+
var accessor = own && !('value' in own) && !('value' in base);
|
|
648
|
+
if (!own) {
|
|
649
|
+
Object.defineProperty(prototype, key, base);
|
|
650
|
+
} else if (accessor) {
|
|
651
|
+
// A subclass can introduce one accessor while retaining the other.
|
|
652
|
+
own = { get: own.get || base.get, set: own.set || base.set, configurable: true };
|
|
653
|
+
Object.defineProperty(prototype, key, own);
|
|
654
|
+
}
|
|
655
|
+
if (own && (overrides.get(name) || accessor)) {
|
|
656
|
+
for (var alias of aliases) {
|
|
657
|
+
if (alias !== key) Object.defineProperty(prototype, alias, own);
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
bindsInherited = !own || overrides.get(name) || accessor;
|
|
661
|
+
}
|
|
662
|
+
members.set(name, bindsInherited ? [key, ...aliases.filter(alias => alias !== key)] : [key]);
|
|
663
|
+
}
|
|
664
|
+
Object.defineProperty(prototype, _avm2ProtectedTraits, { value: { prefix, members } });
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
function _avm2SuperKey(type, name, candidates) {
|
|
668
|
+
var prototype = type.prototype;
|
|
669
|
+
var parent = Object.getPrototypeOf(prototype);
|
|
670
|
+
var own = _ownAvm2ProtectedTraits(prototype);
|
|
671
|
+
var inherited = _ownAvm2ProtectedTraits(parent);
|
|
672
|
+
for (var key of candidates || [name]) {
|
|
673
|
+
if (key in parent) return key;
|
|
674
|
+
if (own && inherited && key.startsWith(own.prefix)) {
|
|
675
|
+
var local = key.slice(own.prefix.length);
|
|
676
|
+
if (inherited.members.has(local)) return inherited.prefix + local;
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
return name;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
function _registerAvm2Interfaces(type, interfaceNames, traits) {
|
|
683
|
+
if (traits) Object.defineProperty(type, '__avm2InterfaceTraits', { value: traits });
|
|
684
|
+
if (interfaceNames.length) _avm2PendingInterfaces.push({ type: type, names: interfaceNames });
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
function _ownAvm2Interfaces(type) {
|
|
688
|
+
return type && Object.prototype.hasOwnProperty.call(type, '__avm2Interfaces') ? type.__avm2Interfaces : [];
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
function _resolveAvm2Interface(name) {
|
|
692
|
+
var type = _getDefinition(name);
|
|
693
|
+
if (type == null) {
|
|
694
|
+
var domain = swflib?.builtins?.ApplicationDomain?.currentDomain;
|
|
695
|
+
try { type = domain?.getDefinition(name); } catch (_) {}
|
|
696
|
+
}
|
|
697
|
+
return type && Object.prototype.hasOwnProperty.call(type, '__avm2InterfaceTraits') ? type : null;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
function _collectAvm2Interfaces(type, result) {
|
|
701
|
+
if (result.has(type)) return;
|
|
702
|
+
result.add(type);
|
|
703
|
+
for (var parent of _ownAvm2Interfaces(type)) _collectAvm2Interfaces(parent, result);
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
function _linkAvm2Interfaces() {
|
|
707
|
+
var pending = _avm2PendingInterfaces.splice(0);
|
|
708
|
+
// Resolve all edges before walking interface inheritance, including declarations in later ABCs.
|
|
709
|
+
for (var spec of pending) {
|
|
710
|
+
var types = spec.names.map(_resolveAvm2Interface).filter(Boolean);
|
|
711
|
+
Object.defineProperty(spec.type, '__avm2Interfaces', { value: types });
|
|
712
|
+
}
|
|
713
|
+
for (var spec of pending) {
|
|
714
|
+
if (Object.prototype.hasOwnProperty.call(spec.type, '__avm2InterfaceTraits')) continue;
|
|
715
|
+
var interfaces = new Set();
|
|
716
|
+
for (var type of _ownAvm2Interfaces(spec.type)) _collectAvm2Interfaces(type, interfaces);
|
|
717
|
+
var prototype = spec.type.prototype;
|
|
718
|
+
for (var type of interfaces) {
|
|
719
|
+
for (var [qualifiedName, publicName, access] of type.__avm2InterfaceTraits) {
|
|
720
|
+
if (qualifiedName === publicName || qualifiedName in prototype) continue;
|
|
721
|
+
_defineAvm2InterfaceAlias(prototype, qualifiedName, publicName, access);
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
function _defineAvm2InterfaceAlias(prototype, qualifiedName, publicName, access) {
|
|
728
|
+
var descriptor = { configurable: true };
|
|
729
|
+
// Resolve on the receiver so inherited aliases call overrides in subclasses.
|
|
730
|
+
if (access & 1) descriptor.get = function () { return this[publicName]; };
|
|
731
|
+
if (access & 2) descriptor.set = function (value) { this[publicName] = value; };
|
|
732
|
+
Object.defineProperty(prototype, qualifiedName, descriptor);
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
function _implementsAvm2Interface(value, interfaceType) {
|
|
736
|
+
var interfaces = new Set();
|
|
737
|
+
for (var prototype = Object.getPrototypeOf(Object(value)); prototype; prototype = Object.getPrototypeOf(prototype)) {
|
|
738
|
+
var type = Object.prototype.hasOwnProperty.call(prototype, 'constructor') && prototype.constructor;
|
|
739
|
+
for (var implemented of _ownAvm2Interfaces(type)) _collectAvm2Interfaces(implemented, interfaces);
|
|
740
|
+
if (interfaces.has(interfaceType)) return true;
|
|
741
|
+
}
|
|
742
|
+
return false;
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
// The cache belongs to the emitted method so closures also retain identity
|
|
746
|
+
// when a loaded movie reads a method from its parent application domain.
|
|
747
|
+
var _avm2MethodClosureCache = Symbol.for('swoof.avm2MethodClosures');
|
|
748
|
+
function _avm2MarkMethod(method) {
|
|
749
|
+
if (typeof method === 'function' && !method[_avm2MethodClosureCache]) {
|
|
750
|
+
Object.defineProperty(method, _avm2MethodClosureCache, { value: true, writable: true });
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
function _avm2BindMethod(receiver, value) {
|
|
754
|
+
if (typeof value !== 'function') return value;
|
|
755
|
+
var cache = value[_avm2MethodClosureCache];
|
|
756
|
+
if (!cache) return value;
|
|
757
|
+
if (cache === true) value[_avm2MethodClosureCache] = cache = new WeakMap();
|
|
758
|
+
var closure = cache.get(receiver);
|
|
759
|
+
if (!closure) {
|
|
760
|
+
closure = Function.prototype.bind.call(value, receiver);
|
|
761
|
+
cache.set(receiver, closure);
|
|
762
|
+
}
|
|
763
|
+
return closure;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
var _avm2ArraySortFlags = { CASEINSENSITIVE: 1, DESCENDING: 2, UNIQUESORT: 4, RETURNINDEXEDARRAY: 8, NUMERIC: 16 };
|
|
767
|
+
var _avm2ArraySortOnKey = new Namespace('http://adobe.com/AS3/2006/builtin')[_avm2NamespaceKeys][0] + 'sortOn';
|
|
768
|
+
_avm2MarkMethod(_avm2ArraySortOn);
|
|
769
|
+
|
|
770
|
+
function _avm2ArrayProperty(target, key) {
|
|
771
|
+
if (target === globalThis.Array && Object.hasOwn(_avm2ArraySortFlags, key)) return _avm2ArraySortFlags[key];
|
|
772
|
+
if ((key === 'sortOn' || key === _avm2ArraySortOnKey) &&
|
|
773
|
+
Array.isArray(target) && !Object.hasOwn(target, '__swoofVectorType')) return _avm2ArraySortOn;
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
function _avm2ArraySortOn(fieldName, options) {
|
|
777
|
+
var fields = Array.isArray(fieldName) ? fieldName.map(String) : [String(fieldName)];
|
|
778
|
+
if (!fields.length) return;
|
|
779
|
+
var flags = _avm2ArraySortFlags;
|
|
780
|
+
var orders = Array.isArray(options)
|
|
781
|
+
? fields.map(function (_, index) { return options.length === fields.length ? options[index] | 0 : 0; })
|
|
782
|
+
: fields.map(function () { return options | 0; });
|
|
783
|
+
var slots = [], entries = [];
|
|
784
|
+
for (var property of Object.getOwnPropertyNames(this)) {
|
|
785
|
+
var index = property >>> 0;
|
|
786
|
+
if (String(index) !== property || index >= this.length) continue;
|
|
787
|
+
var value = this[index];
|
|
788
|
+
var keys = fields.map(function (field, index) {
|
|
789
|
+
var key = value?.[field];
|
|
790
|
+
if (key === undefined) return undefined;
|
|
791
|
+
if (orders[index] & flags.NUMERIC) {
|
|
792
|
+
var numeric = Number(key);
|
|
793
|
+
return Number.isNaN(numeric) ? undefined : numeric;
|
|
794
|
+
}
|
|
795
|
+
var text = String(key);
|
|
796
|
+
return orders[index] & flags.CASEINSENSITIVE ? text.toLowerCase() : text;
|
|
797
|
+
});
|
|
798
|
+
slots.push(index);
|
|
799
|
+
entries.push({ index: index, value: value, keys: keys });
|
|
800
|
+
}
|
|
801
|
+
function compare(left, right) {
|
|
802
|
+
for (var i = 0; i < fields.length; i++) {
|
|
803
|
+
var a = left.keys[i], b = right.keys[i];
|
|
804
|
+
if (a === b) continue;
|
|
805
|
+
if (a === undefined || b === undefined) return a === undefined ? 1 : -1;
|
|
806
|
+
var direction = orders[i] & flags.DESCENDING ? -1 : 1;
|
|
807
|
+
return (a < b ? -1 : 1) * direction;
|
|
808
|
+
}
|
|
809
|
+
return 0;
|
|
810
|
+
}
|
|
811
|
+
entries.sort(compare);
|
|
812
|
+
if (orders[0] & flags.UNIQUESORT) {
|
|
813
|
+
for (var i = 1; i < entries.length; i++) {
|
|
814
|
+
if (compare(entries[i - 1], entries[i]) === 0) return 0;
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
if (orders[0] & flags.RETURNINDEXEDARRAY) return entries.map(function (entry) { return entry.index; });
|
|
818
|
+
for (var i = 0; i < entries.length; i++) this[i] = entries[i].value;
|
|
819
|
+
for (var slot of slots) {
|
|
820
|
+
if (slot >= entries.length) delete this[slot];
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
function _avm2GetProperty(object, name, namespaceKeys) {
|
|
825
|
+
if (object == null) throw new TypeError('Cannot read property ' + String(name) + ' of ' + object);
|
|
826
|
+
var target = Object(object);
|
|
827
|
+
if (typeof target._swoofXmlProperty === 'function' && (!namespaceKeys || namespaceKeys.includes(name)) &&
|
|
828
|
+
!/^\d+$/.test(name)) {
|
|
829
|
+
return _avm2E4XProperty(target, 'get', false, null, name, ['']);
|
|
830
|
+
}
|
|
831
|
+
if (!namespaceKeys) return _avm2BindMethod(target, _avm2ReadProperty(target, name));
|
|
832
|
+
for (var i = 0; i < namespaceKeys.length; i++) {
|
|
833
|
+
var key = namespaceKeys[i];
|
|
834
|
+
if (_avm2PropertyExists(target, key)) return _avm2BindMethod(target, _avm2ReadProperty(target, key));
|
|
835
|
+
}
|
|
836
|
+
return undefined;
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
function _avm2GetMethod(object, name, namespaceKeys) {
|
|
840
|
+
if (object == null) throw new TypeError('Cannot read property ' + String(name) + ' of ' + object);
|
|
841
|
+
var target = Object(object);
|
|
842
|
+
// Namespace sets can include same-named, uninitialized slots. For a call
|
|
843
|
+
// opcode, prefer an actual method trait over those placeholders, then try
|
|
844
|
+
// the ordinary public method emitted for public ActionScript traits.
|
|
845
|
+
for (var i = 0; i < namespaceKeys.length; i++) {
|
|
846
|
+
var key = namespaceKeys[i];
|
|
847
|
+
if (_avm2PropertyExists(target, key)) {
|
|
848
|
+
var value = _avm2ReadProperty(target, key);
|
|
849
|
+
if (typeof value === 'function') return _avm2BindMethod(target, value);
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
return _avm2GetProperty(target, name, namespaceKeys);
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
function _avm2SetProperty(object, name, value, namespaceKeys) {
|
|
856
|
+
if (object == null) throw new TypeError('Cannot set property ' + String(name) + ' of ' + object);
|
|
857
|
+
var target = Object(object);
|
|
858
|
+
// A new dynamic member is public when the namespace set permits it.
|
|
859
|
+
var key = !namespaceKeys.length || namespaceKeys.includes(name) ? name : namespaceKeys[0];
|
|
860
|
+
for (var i = 0; i < namespaceKeys.length; i++) {
|
|
861
|
+
if (_avm2PropertyExists(target, namespaceKeys[i])) { key = namespaceKeys[i]; break; }
|
|
862
|
+
}
|
|
863
|
+
target[key] = value;
|
|
864
|
+
return value;
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
function _avm2DeleteProperty(object, name, namespaceKeys) {
|
|
868
|
+
if (object == null) throw new TypeError('Cannot delete property ' + String(name) + ' of ' + object);
|
|
869
|
+
var target = Object(object), key = namespaceKeys.length ? namespaceKeys[0] : name;
|
|
870
|
+
for (var i = 0; i < namespaceKeys.length; i++) {
|
|
871
|
+
if (_avm2PropertyExists(target, namespaceKeys[i])) { key = namespaceKeys[i]; break; }
|
|
872
|
+
}
|
|
873
|
+
return delete target[key];
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
function _hasAvm2Property(object, name, namespaceKeys) {
|
|
877
|
+
if (object == null) return false;
|
|
878
|
+
var target = Object(object);
|
|
879
|
+
if (name === 'name' && typeof target._swoofXmlName === 'function' &&
|
|
880
|
+
(!namespaceKeys || namespaceKeys.includes(name))) return true;
|
|
881
|
+
if (!namespaceKeys) return _avm2PropertyExists(target, name);
|
|
882
|
+
for (var i = 0; i < namespaceKeys.length; i++) {
|
|
883
|
+
if (_avm2PropertyExists(target, namespaceKeys[i])) return true;
|
|
884
|
+
}
|
|
885
|
+
return false;
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
function _isAvm2StaticProtectedKey(key) {
|
|
889
|
+
return typeof key === 'string' && key.startsWith('__avm2ns_26_');
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
function _avm2ErrorStackTrace() {
|
|
893
|
+
if (typeof this.stack !== 'string') return null;
|
|
894
|
+
var trace = [Error.prototype.toString.call(this)];
|
|
895
|
+
for (var line of this.stack.split('\n')) {
|
|
896
|
+
// Keep function names in release-player traces. Browser stacks also
|
|
897
|
+
// include local paths, source locations and eval details.
|
|
898
|
+
var frame = /^\s*at ([\w.$<> ]+) \(/.exec(line) || /^([\w.$<> ]+)@/.exec(line);
|
|
899
|
+
if (frame) trace.push(' at ' + frame[1] + '()');
|
|
900
|
+
}
|
|
901
|
+
return trace.join('\n');
|
|
902
|
+
}
|
|
903
|
+
_avm2MarkMethod(_avm2ErrorStackTrace);
|
|
904
|
+
|
|
905
|
+
function _avm2BuiltinProperty(target, key) {
|
|
906
|
+
if (key === 'getStackTrace' && target instanceof globalThis.Error) return _avm2ErrorStackTrace;
|
|
907
|
+
return _avm2ArrayProperty(target, key);
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
function _avm2ReadProperty(target, key) {
|
|
911
|
+
if (target === _avm2FontDescription && key === 'isFontCompatible' && _avm2MovieFontLookup) {
|
|
912
|
+
return _avm2MovieFontLookup.isFontCompatible;
|
|
913
|
+
}
|
|
914
|
+
if (typeof target === 'function' && _isAvm2StaticProtectedKey(key) &&
|
|
915
|
+
!Object.prototype.hasOwnProperty.call(target, key)) return undefined;
|
|
916
|
+
var builtin = _avm2BuiltinProperty(target, key);
|
|
917
|
+
return builtin !== undefined && !(key in target) ? builtin : target[key];
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
function _avm2PropertyExists(target, key) {
|
|
921
|
+
return typeof target === 'function' && _isAvm2StaticProtectedKey(key)
|
|
922
|
+
? Object.prototype.hasOwnProperty.call(target, key)
|
|
923
|
+
: key in target || _avm2BuiltinProperty(target, key) !== undefined;
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
function _avm2StaticProtectedOwner(type, name, namespaceKeys) {
|
|
927
|
+
var keys = (namespaceKeys || [name]).filter(_isAvm2StaticProtectedKey);
|
|
928
|
+
if (!keys.length) return null;
|
|
929
|
+
for (var owner = type; typeof owner === 'function'; owner = Object.getPrototypeOf(owner)) {
|
|
930
|
+
if (keys.some(function (key) { return Object.prototype.hasOwnProperty.call(owner, key); })) return owner;
|
|
931
|
+
}
|
|
932
|
+
return null;
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
function _hasAvm2ScopeProperty(scope, name, namespaceKeys) {
|
|
936
|
+
var traits = typeof scope === 'function' && _avm2ClassLexicalTraits.get(scope);
|
|
937
|
+
if (!traits) return _hasAvm2Property(scope, name, namespaceKeys);
|
|
938
|
+
// Class scopes contain declared statics. JS constructor fields such as
|
|
939
|
+
// length and name must not shadow an outer ActionScript variable.
|
|
940
|
+
return namespaceKeys ? namespaceKeys.some(function (key) { return traits.has(key); }) : traits.has(name);
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
function _hasAvm2LexicalProperty(scope, name, namespaceKeys, ambientTimer) {
|
|
944
|
+
if (!ambientTimer || !scope || (scope !== globalThis && !Object.prototype.isPrototypeOf.call(globalThis, scope))) {
|
|
945
|
+
return _hasAvm2ScopeProperty(scope, name, namespaceKeys);
|
|
946
|
+
}
|
|
947
|
+
return (namespaceKeys || [name]).some(function (key) {
|
|
948
|
+
if (key !== ambientTimer) return _hasAvm2Property(scope, key);
|
|
949
|
+
// An imported Flash timer can be shadowed by a declared AVM2 member,
|
|
950
|
+
// but the public candidate on the browser global is a different API.
|
|
951
|
+
for (var owner = scope; owner && owner !== globalThis; owner = Object.getPrototypeOf(owner)) {
|
|
952
|
+
if (Object.prototype.hasOwnProperty.call(owner, key)) return true;
|
|
953
|
+
}
|
|
954
|
+
return Object.prototype.hasOwnProperty.call(globalThis, key) && globalThis[key] !== _avm2HostTimers[key];
|
|
955
|
+
});
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
function _findProp(name, obj, scopes, strict, globalOnly, lexicalClass, namespaceKeys, scriptScope) {
|
|
959
|
+
var scopeList = scopes || [];
|
|
960
|
+
var timerName = _avm2TimerFunctions[name] && _resolveAs3Name(name);
|
|
961
|
+
var qualifiedTimer = timerName && 'flash.utils.' + timerName;
|
|
962
|
+
var ambientTimer = timerName && (name === qualifiedTimer || (namespaceKeys && namespaceKeys.includes(qualifiedTimer))) ? timerName : null;
|
|
963
|
+
if (!globalOnly) {
|
|
964
|
+
for (var i = scopeList.length - 1; i >= 0; i--) {
|
|
965
|
+
var scope = scopeList[i];
|
|
966
|
+
if (_hasAvm2LexicalProperty(scope, name, namespaceKeys, ambientTimer)) return scope;
|
|
967
|
+
}
|
|
968
|
+
if (_hasAvm2LexicalProperty(obj, name, namespaceKeys, ambientTimer)) return obj;
|
|
969
|
+
var ownTraits = lexicalClass && _avm2ClassLexicalTraits.get(lexicalClass);
|
|
970
|
+
if (ownTraits && (namespaceKeys ? namespaceKeys.some(function (key) { return ownTraits.has(key); }) : ownTraits.has(name))) return lexicalClass;
|
|
971
|
+
var staticOwner = lexicalClass && _avm2StaticProtectedOwner(lexicalClass, name, namespaceKeys);
|
|
972
|
+
if (staticOwner) return staticOwner;
|
|
973
|
+
if (_hasAvm2LexicalProperty(scriptScope, name, namespaceKeys, ambientTimer)) return scriptScope;
|
|
974
|
+
}
|
|
975
|
+
if (ambientTimer) {
|
|
976
|
+
return _hasAvm2LexicalProperty(globalThis, name, namespaceKeys, ambientTimer) ? globalThis : _avm2TimerFunctions;
|
|
977
|
+
}
|
|
978
|
+
if (_hasAvm2Property(globalThis, name, namespaceKeys)) return globalThis;
|
|
979
|
+
for (var key of namespaceKeys || [name]) {
|
|
980
|
+
var scriptOwner = _avm2ScriptMethodScopes.get(key);
|
|
981
|
+
if (scriptOwner) return scriptOwner;
|
|
982
|
+
}
|
|
983
|
+
if (_hasAvm2Property(_classes, name, namespaceKeys)) return _classes;
|
|
984
|
+
// Qualified Flash built-ins (for example flash.events.EventDispatcher and
|
|
985
|
+
// flash.utils.Timer) are exposed through the package tree and registered in
|
|
986
|
+
// _classes by their short name. findpropstrict must resolve their scope
|
|
987
|
+
// without throwing before the emitted package-aware getlex fallback runs.
|
|
988
|
+
var shortName = _resolveAs3Name(name);
|
|
989
|
+
if (shortName !== name && shortName in _classes) return _classes;
|
|
990
|
+
if (strict) throw new ReferenceError('Property ' + String(name) + ' was not found');
|
|
991
|
+
return globalThis;
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
function _isAvm2VectorType(type) {
|
|
995
|
+
if (typeof type !== 'function') return false;
|
|
996
|
+
return type === _classes['__AS3__.vec.Vector'] || type === globalThis.Vector ||
|
|
997
|
+
(type.name === 'Vector' && !type.__swoofQualifiedName) || type.__swoofVector === true;
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
function _vectorElementDefault(type) {
|
|
1001
|
+
if (_avm2VectorPrimitiveName(type)) {
|
|
1002
|
+
if (type === globalThis.Number) return NaN;
|
|
1003
|
+
return 0;
|
|
1004
|
+
}
|
|
1005
|
+
if (type === globalThis.Boolean) return false;
|
|
1006
|
+
return null;
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
function _avm2VectorPrimitiveName(type) {
|
|
1010
|
+
if (type === _avm2Int) return 'int';
|
|
1011
|
+
if (type === _avm2Uint) return 'uint';
|
|
1012
|
+
if (type === globalThis.Number) return 'Number';
|
|
1013
|
+
// Standalone callers can provide a primitive shim.
|
|
1014
|
+
return typeof type === 'function' && !type.__swoofQualifiedName &&
|
|
1015
|
+
(type.name === 'int' || type.name === 'uint') ? type.name : null;
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
function _coerceVectorElement(value, type) {
|
|
1019
|
+
var name = _avm2VectorPrimitiveName(type);
|
|
1020
|
+
if (value == null && !name && type !== globalThis.Boolean) return null;
|
|
1021
|
+
if (name === 'int') return Number(value) | 0;
|
|
1022
|
+
if (name === 'uint') return Number(value) >>> 0;
|
|
1023
|
+
if (type === Number) return Number(value);
|
|
1024
|
+
if (type === Boolean) return Boolean(value);
|
|
1025
|
+
if (type === String) return value == null ? null : String(value);
|
|
1026
|
+
if (type === Object || type == null) return value;
|
|
1027
|
+
if (_isType(value, type)) return value;
|
|
1028
|
+
throw new TypeError('Value does not match Vector element type ' + (name || String(type)));
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
function _matchesAvm2Vector(value, elementType) {
|
|
1032
|
+
if (!Array.isArray(value)) return false;
|
|
1033
|
+
if (Object.prototype.hasOwnProperty.call(value, '__swoofVectorElementClass')) {
|
|
1034
|
+
return value.__swoofVectorElementClass === elementType;
|
|
1035
|
+
}
|
|
1036
|
+
// Native/base and AMF vectors use the storage tags instead.
|
|
1037
|
+
var tag = value.__swoofVectorType;
|
|
1038
|
+
if (elementType === _avm2Int) return tag === 'int';
|
|
1039
|
+
if (elementType === _avm2Uint) return tag === 'uint';
|
|
1040
|
+
if (elementType === globalThis.Number) return tag === 'Number';
|
|
1041
|
+
return elementType === null && tag === 'Object' && value.__swoofVectorTypeName === 'Object';
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
function _applyType(type, typeArgs) {
|
|
1045
|
+
if (!_isAvm2VectorType(type) || !typeArgs || typeArgs.length === 0) return type;
|
|
1046
|
+
// swflib's Vector factory returns arrays; align the factory's prototype with
|
|
1047
|
+
// those array values so instances satisfy both base and specialized checks.
|
|
1048
|
+
if (type.prototype !== Array.prototype) {
|
|
1049
|
+
try { type.prototype = Array.prototype; } catch (_) {}
|
|
1050
|
+
}
|
|
1051
|
+
var elementType = typeArgs[0] ?? null;
|
|
1052
|
+
var specializations = _avm2VectorTypeCache.get(type);
|
|
1053
|
+
if (!specializations) _avm2VectorTypeCache.set(type, specializations = new Map());
|
|
1054
|
+
if (specializations.has(elementType)) return specializations.get(elementType);
|
|
1055
|
+
var SpecializedVector = function VectorSpecialization(length, fixed) {
|
|
1056
|
+
var count = length == null ? 0 : Number(length) | 0;
|
|
1057
|
+
if (count < 0) throw new RangeError('Vector length must not be negative');
|
|
1058
|
+
var initial = _vectorElementDefault(elementType);
|
|
1059
|
+
var values = new Array(count);
|
|
1060
|
+
for (var i = 0; i < count; i++) values[i] = initial;
|
|
1061
|
+
values.fixed = Boolean(fixed);
|
|
1062
|
+
var rawElementName = elementType === Object ? 'Object' : (typeof elementType === 'function' ? elementType.name : 'Object');
|
|
1063
|
+
var vectorElementName = _avm2VectorPrimitiveName(elementType) || 'Object';
|
|
1064
|
+
var vectorTypeName = elementType === Object ? 'Object' : (elementType && elementType.__swoofQualifiedName) || rawElementName || 'Object';
|
|
1065
|
+
Object.defineProperty(values, '__swoofVectorElementClass', { value: elementType });
|
|
1066
|
+
Object.defineProperty(values, '__swoofVectorType', { value: vectorElementName, writable: true, configurable: true, enumerable: false });
|
|
1067
|
+
Object.defineProperty(values, '__swoofVectorTypeName', { value: vectorTypeName, writable: true, configurable: true, enumerable: false });
|
|
1068
|
+
return new Proxy(values, {
|
|
1069
|
+
set: function (target, key, value) {
|
|
1070
|
+
if (key === 'length') {
|
|
1071
|
+
var newLength = Number(value) >>> 0;
|
|
1072
|
+
if (target.fixed && newLength !== target.length) throw new RangeError('Cannot change the length of a fixed Vector');
|
|
1073
|
+
return Reflect.set(target, key, newLength, target);
|
|
1074
|
+
}
|
|
1075
|
+
if (typeof key === 'string' && /^(0|[1-9][0-9]*)$/.test(key)) {
|
|
1076
|
+
var index = Number(key);
|
|
1077
|
+
if (target.fixed && index >= target.length) throw new RangeError('Cannot extend a fixed Vector');
|
|
1078
|
+
if (index >= target.length) {
|
|
1079
|
+
var oldLength = target.length;
|
|
1080
|
+
target.length = index + 1;
|
|
1081
|
+
for (var j = oldLength; j < index; j++) target[j] = _vectorElementDefault(elementType);
|
|
1082
|
+
}
|
|
1083
|
+
value = _coerceVectorElement(value, elementType);
|
|
1084
|
+
}
|
|
1085
|
+
return Reflect.set(target, key, value, target);
|
|
1086
|
+
},
|
|
1087
|
+
});
|
|
1088
|
+
};
|
|
1089
|
+
Object.defineProperty(SpecializedVector, 'name', { value: 'Vector', configurable: true });
|
|
1090
|
+
Object.defineProperty(SpecializedVector, globalThis.Symbol.hasInstance, {
|
|
1091
|
+
value: function (value) { return _matchesAvm2Vector(value, elementType); },
|
|
1092
|
+
});
|
|
1093
|
+
// The implementation values are real arrays, so their Array prototype is
|
|
1094
|
+
// also the specialization prototype for AVM2 Vector type checks.
|
|
1095
|
+
SpecializedVector.prototype = Array.prototype;
|
|
1096
|
+
_markAvm2Class(SpecializedVector);
|
|
1097
|
+
specializations.set(elementType, SpecializedVector);
|
|
1098
|
+
return SpecializedVector;
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
function _seedScriptTrait(scope, name, value) {
|
|
1102
|
+
if (arguments.length === 1) { name = scope; scope = globalThis; }
|
|
1103
|
+
var existing = Object.getOwnPropertyDescriptor(scope, name);
|
|
1104
|
+
if (existing) {
|
|
1105
|
+
if (value !== undefined && existing.writable && existing.value === undefined) scope[name] = value;
|
|
1106
|
+
return;
|
|
1107
|
+
}
|
|
1108
|
+
Object.defineProperty(scope, name, { value: value, writable: true, enumerable: true, configurable: true });
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
function _stubClass(name) {
|
|
1112
|
+
function AS3Stub() {}
|
|
1113
|
+
AS3Stub.displayName = name;
|
|
1114
|
+
AS3Stub.prototype = {};
|
|
1115
|
+
_markAvm2Class(AS3Stub);
|
|
1116
|
+
return AS3Stub;
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
/** AS3 Class type — functions count as classes for `x instanceof Class`. */
|
|
1120
|
+
function Class(value) {
|
|
1121
|
+
if (arguments.length !== 1) throw new TypeError('Class coercion requires one argument');
|
|
1122
|
+
return _coerceType(value, Class, 'Class');
|
|
1123
|
+
}
|
|
1124
|
+
Object.defineProperty(Class, Symbol.hasInstance, {
|
|
1125
|
+
value: function (v) { return typeof v === 'function'; },
|
|
1126
|
+
});
|
|
1127
|
+
try { globalThis.Class = Class; } catch (_) {}
|
|
1128
|
+
_classes.Class = Class;
|
|
1129
|
+
|
|
1130
|
+
function _resolveAs3Name(name) {
|
|
1131
|
+
if (typeof name !== 'string') return name;
|
|
1132
|
+
// flash.events.Event / flash.events::Event → Event
|
|
1133
|
+
var n = name.replace(/::/g, '.').split('.').pop();
|
|
1134
|
+
return n || name;
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
function _getlex(name) {
|
|
1138
|
+
if (typeof name === 'string') {
|
|
1139
|
+
// AS3 undefined/null/NaN lex — never stub these as classes
|
|
1140
|
+
if (name === 'undefined' || name === 'void') return undefined;
|
|
1141
|
+
if (name === 'null') return null;
|
|
1142
|
+
if (name === 'NaN') return NaN;
|
|
1143
|
+
if (name === 'Infinity') return Infinity;
|
|
1144
|
+
if (name === 'TextField' && movieTextField && globalThis.TextField === _avm2PublicTextField) return _classes.TextField;
|
|
1145
|
+
if (name.startsWith('flash.utils')) {
|
|
1146
|
+
var timer = _avm2TimerFunctions[name.replace('::', '.')];
|
|
1147
|
+
if (timer) return timer;
|
|
1148
|
+
}
|
|
1149
|
+
// Timeline/instance props wrongly emitted as getlex — prefer document class / root
|
|
1150
|
+
if (name === 'root' || name === 'currentFrame' || name === 'totalFrames' ||
|
|
1151
|
+
name === 'framesLoaded' || name === 'currentLabel' || name === 'currentLabels' ||
|
|
1152
|
+
name === 'scenes' || name === 'currentScene') {
|
|
1153
|
+
try {
|
|
1154
|
+
var swoof = globalThis.__swoof;
|
|
1155
|
+
var main = swoof && swoof.main;
|
|
1156
|
+
if (name === 'root') return main || (swoof && swoof.root) || null;
|
|
1157
|
+
if (main && main[name] != null) return main[name];
|
|
1158
|
+
if (swoof && swoof.root && swoof.root[name] != null) return swoof.root[name];
|
|
1159
|
+
if (swoof && swoof.timeline && name === 'currentFrame') {
|
|
1160
|
+
return (swoof.timeline.frame | 0) + 1;
|
|
1161
|
+
}
|
|
1162
|
+
} catch (_) {}
|
|
1163
|
+
}
|
|
1164
|
+
var short = _resolveAs3Name(name);
|
|
1165
|
+
if (name in globalThis && globalThis[name] != null) return globalThis[name];
|
|
1166
|
+
if (name in _classes && _classes[name] != null) return _classes[name];
|
|
1167
|
+
if (short in globalThis && globalThis[short] != null) return globalThis[short];
|
|
1168
|
+
if (short in _classes && _classes[short] != null) return _classes[short];
|
|
1169
|
+
// flash.events.Event via packages
|
|
1170
|
+
try {
|
|
1171
|
+
if (swflib && swflib.packages) {
|
|
1172
|
+
var parts = name.replace(/::/g, '.').split('.');
|
|
1173
|
+
if (parts[0] === 'flash' && parts.length >= 2) {
|
|
1174
|
+
var pkg = swflib.packages;
|
|
1175
|
+
for (var i = 1; i < parts.length; i++) {
|
|
1176
|
+
if (!pkg) break;
|
|
1177
|
+
pkg = pkg[parts[i]];
|
|
1178
|
+
}
|
|
1179
|
+
if (pkg != null) return pkg;
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
} catch (_) {}
|
|
1183
|
+
// Missing flash.* types — stub so document-class constructors can finish
|
|
1184
|
+
var stub = _stubClass(short);
|
|
1185
|
+
try { globalThis[short] = stub; } catch (_) {}
|
|
1186
|
+
_classes[short] = stub;
|
|
1187
|
+
return stub;
|
|
1188
|
+
}
|
|
1189
|
+
return Object;
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
function _getlexScoped(name, receiver, scopes, lexicalClass, namespaceKeys, scriptScope, exactType, definitionKey) {
|
|
1193
|
+
var host = _findProp(name, receiver, scopes, false, false, lexicalClass, namespaceKeys, scriptScope);
|
|
1194
|
+
if (definitionKey && host === _classes) return _getDefinition(definitionKey);
|
|
1195
|
+
if (_hasAvm2Property(host, name, namespaceKeys)) {
|
|
1196
|
+
var scopedValue = _avm2GetProperty(host, name, namespaceKeys);
|
|
1197
|
+
if (scopedValue !== undefined || (!exactType && !definitionKey && host !== globalThis)) return scopedValue;
|
|
1198
|
+
// Script class names are predeclared on globalThis before class emission.
|
|
1199
|
+
// Their placeholder is undefined, while the actual class lives in _classes.
|
|
1200
|
+
// Let that registered definition fill the placeholder; explicit null still
|
|
1201
|
+
// shadows outer/global values as normal.
|
|
1202
|
+
}
|
|
1203
|
+
if (definitionKey) return _getDefinition(definitionKey);
|
|
1204
|
+
if (exactType) return _avm2GetProperty(_classes, name, namespaceKeys);
|
|
1205
|
+
return _getlex(name);
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
function _avm2NamespacedConstructor(receiver, propertyKey, definitionKey) {
|
|
1209
|
+
return receiver === _classes ? _getDefinition(definitionKey) : _avm2GetProperty(receiver, propertyKey);
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
function _getDefinition(name) {
|
|
1213
|
+
if (Object.prototype.hasOwnProperty.call(_classes, name)) return _classes[name];
|
|
1214
|
+
}
|
|
1215
|
+
if (swflib && typeof swflib.setAvm2DefinitionLookup === 'function') {
|
|
1216
|
+
swflib.setAvm2DefinitionLookup(_getDefinition);
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
function getDefinitionByName(name) {
|
|
1220
|
+
return _getlex(String(name));
|
|
1221
|
+
}
|
|
1222
|
+
try { globalThis.getDefinitionByName = getDefinitionByName; } catch (_) {}
|
|
1223
|
+
|
|
1224
|
+
function _avm2MethodEntry(owner, key, markMethod) {
|
|
1225
|
+
if (markMethod) _avm2MarkMethod(owner[key]);
|
|
1226
|
+
return [owner, key];
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
function _callStatic(methodTable, methodIdx, recv, args) {
|
|
1230
|
+
if (recv == null) throw new TypeError('Cannot call static method on null or undefined');
|
|
1231
|
+
var entry = methodTable && methodTable[methodIdx];
|
|
1232
|
+
if (typeof entry === 'function') return entry(recv, args);
|
|
1233
|
+
if (!Array.isArray(entry)) return undefined;
|
|
1234
|
+
// Look up the property on the declaring object for each call. Inherited
|
|
1235
|
+
// static methods or accessor-backed slot replacements must stay visible.
|
|
1236
|
+
var fn = entry[0] && entry[0][entry[1]];
|
|
1237
|
+
return typeof fn === 'function' ? fn.apply(recv, args) : undefined;
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
function _createAvm2ExecutionBudget() {
|
|
1241
|
+
var remaining = 100000;
|
|
1242
|
+
return function () {
|
|
1243
|
+
if (--remaining < 0) throw new Error('AVM2 execution limit exceeded');
|
|
1244
|
+
};
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
function _callMethodById(receiver, dispatchId, args) {
|
|
1248
|
+
if (receiver == null) throw new TypeError('Cannot call method on null or undefined');
|
|
1249
|
+
var prototype = Object.getPrototypeOf(Object(receiver));
|
|
1250
|
+
var ctor = prototype && prototype.constructor;
|
|
1251
|
+
var table = ctor && ctor.__avm2DispatchMethods;
|
|
1252
|
+
var fn = table?.[dispatchId] || _avm2DispatchIds.get(ctor)?.automatic?.[dispatchId];
|
|
1253
|
+
if (typeof fn !== 'function') return undefined;
|
|
1254
|
+
return fn.apply(receiver, args);
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
function _callSuperById(receiver, dispatchId, args, owner) {
|
|
1258
|
+
if (receiver == null) throw new TypeError('Cannot call super method on null or undefined');
|
|
1259
|
+
if (!owner) {
|
|
1260
|
+
var prototype = Object.getPrototypeOf(Object(receiver));
|
|
1261
|
+
owner = prototype && prototype.constructor;
|
|
1262
|
+
}
|
|
1263
|
+
var superClass = owner && Object.getPrototypeOf(owner);
|
|
1264
|
+
var table = superClass && superClass.__avm2DispatchMethods;
|
|
1265
|
+
var fn = table?.[dispatchId] || _avm2DispatchIds.get(superClass)?.automatic?.[dispatchId];
|
|
1266
|
+
if (typeof fn !== 'function') return undefined;
|
|
1267
|
+
return fn.apply(receiver, args);
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
var _avm2ActivationSlots = new WeakMap();
|
|
1271
|
+
function _registerAvm2ActivationSlots(object, slots) {
|
|
1272
|
+
_avm2ActivationSlots.set(object, slots);
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
function _createAvm2Activation(traits) {
|
|
1276
|
+
var activation = Object.create(null);
|
|
1277
|
+
var slots = Object.create(null);
|
|
1278
|
+
for (var [slot, name, value] of traits) {
|
|
1279
|
+
activation[name] = value;
|
|
1280
|
+
slots[slot] = name;
|
|
1281
|
+
}
|
|
1282
|
+
_registerAvm2ActivationSlots(activation, slots);
|
|
1283
|
+
return activation;
|
|
1284
|
+
}
|
|
1285
|
+
|
|
1286
|
+
function _avm2IsDictionary(object) {
|
|
1287
|
+
var dictionary = swflib && swflib.builtins && swflib.builtins.Dictionary;
|
|
1288
|
+
return typeof dictionary === 'function' && object instanceof dictionary;
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
function _avm2IsDictionaryKey(receiver, operands) {
|
|
1292
|
+
if (!_avm2IsDictionary(receiver)) return false;
|
|
1293
|
+
var name = operands[1];
|
|
1294
|
+
if (name && _avm2QNameNamespace in Object(name)) return false;
|
|
1295
|
+
var namespace = operands[0];
|
|
1296
|
+
var prefixes = operands[2] || (namespace && namespace[_avm2NamespaceKeys]);
|
|
1297
|
+
return !!prefixes && prefixes.includes('');
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
function _avm2In(key, object) {
|
|
1301
|
+
return _avm2IsDictionary(object) ? object.hasOwnProperty(key) : key in object;
|
|
1302
|
+
}
|
|
1303
|
+
|
|
1304
|
+
function _avm2HasNext(index, object) {
|
|
1305
|
+
index |= 0;
|
|
1306
|
+
if (_avm2IsDictionary(object)) return object._swoofNextIndex(Math.max(index, 0));
|
|
1307
|
+
return index < Object.keys(object || {}).length ? index + 1 : 0;
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
function _avm2NextName(object, index) {
|
|
1311
|
+
if (_avm2IsDictionary(object)) return object._swoofNextName(index | 0);
|
|
1312
|
+
return Object.keys(object || {})[(index | 0) - 1];
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
function _avm2NextValue(object, index) {
|
|
1316
|
+
if (_avm2IsDictionary(object)) return object._swoofNextValue(index | 0);
|
|
1317
|
+
return Object.values(object || {})[(index | 0) - 1];
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1320
|
+
function _slotMap(obj) {
|
|
1321
|
+
if (obj == null) throw new TypeError('Cannot access slot on null or undefined');
|
|
1322
|
+
var staged = _avm2StagedInstances.get(obj);
|
|
1323
|
+
if (staged && staged.receiver) obj = staged.receiver;
|
|
1324
|
+
var isClass = typeof obj === 'function';
|
|
1325
|
+
var prototype = isClass ? null : Object.getPrototypeOf(Object(obj));
|
|
1326
|
+
var ctor = staged ? staged.type : isClass ? obj : prototype && prototype.constructor;
|
|
1327
|
+
return {
|
|
1328
|
+
owner: obj,
|
|
1329
|
+
ctor: ctor,
|
|
1330
|
+
map: _avm2ActivationSlots.get(obj) || (ctor && ctor[isClass ? '__avm2StaticSlots' : '__avm2InstanceSlots']),
|
|
1331
|
+
constMap: ctor && ctor[isClass ? '__avm2StaticConstSlots' : '__avm2InstanceConstSlots'],
|
|
1332
|
+
dynamic: !ctor || ctor.__swoofDynamic !== false,
|
|
1333
|
+
className: ctor && (ctor.__swoofQualifiedName || ctor.name) || 'Object',
|
|
1334
|
+
};
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
function _getSlot(obj, slotId) {
|
|
1338
|
+
var slot = _slotMap(obj);
|
|
1339
|
+
if (!Number.isInteger(slotId) || slotId <= 0) throw new ReferenceError('Invalid AVM2 slot ID ' + slotId + ' on ' + slot.className);
|
|
1340
|
+
var name = slot.map && slot.map[slotId];
|
|
1341
|
+
if (name != null) return slot.owner[name];
|
|
1342
|
+
if (!slot.dynamic) throw new ReferenceError('Unknown AVM2 slot ID ' + slotId + ' on sealed ' + slot.className);
|
|
1343
|
+
return slot.owner.__slots && slot.owner.__slots[slotId];
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
|
+
function _setSlot(obj, slotId, value, initializing) {
|
|
1347
|
+
var slot = _slotMap(obj);
|
|
1348
|
+
if (!Number.isInteger(slotId) || slotId <= 0) throw new ReferenceError('Invalid AVM2 slot ID ' + slotId + ' on ' + slot.className);
|
|
1349
|
+
var name = slot.map && slot.map[slotId];
|
|
1350
|
+
if (name != null) {
|
|
1351
|
+
if (slot.constMap && slot.constMap[slotId]) {
|
|
1352
|
+
if (!initializing) throw new TypeError('Cannot assign to constant AVM2 slot ' + name);
|
|
1353
|
+
var written = slot.owner.__avm2ConstSlotsWritten;
|
|
1354
|
+
if (!written) Object.defineProperty(slot.owner, '__avm2ConstSlotsWritten', { value: Object.create(null), configurable: true });
|
|
1355
|
+
written = slot.owner.__avm2ConstSlotsWritten;
|
|
1356
|
+
if (written[slotId]) throw new TypeError('Cannot initialize constant AVM2 slot ' + name + ' more than once');
|
|
1357
|
+
written[slotId] = true;
|
|
1358
|
+
}
|
|
1359
|
+
slot.owner[name] = value;
|
|
1360
|
+
} else {
|
|
1361
|
+
if (!slot.dynamic) throw new ReferenceError('Unknown AVM2 slot ID ' + slotId + ' on sealed ' + slot.className);
|
|
1362
|
+
if (!Object.prototype.hasOwnProperty.call(slot.owner, '__slots')) {
|
|
1363
|
+
Object.defineProperty(slot.owner, '__slots', { value: [], writable: true, configurable: true, enumerable: false });
|
|
1364
|
+
}
|
|
1365
|
+
slot.owner.__slots[slotId] = value;
|
|
1366
|
+
}
|
|
1367
|
+
return value;
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1370
|
+
function _requireAvm2Class(type) {
|
|
1371
|
+
if (typeof type !== 'function' || type.prototype == null) {
|
|
1372
|
+
throw new TypeError('Right-hand operand of AVM2 is/as must be a class');
|
|
1373
|
+
}
|
|
1374
|
+
return type;
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1377
|
+
function _avm2TypeOf(value) {
|
|
1378
|
+
var type = typeof value;
|
|
1379
|
+
if (type === 'function') {
|
|
1380
|
+
return Object.hasOwn(value, _avm2ClassMarker) || _avm2BuiltinClassTypes.has(value) ||
|
|
1381
|
+
swflib?.qualifiedAvm2BuiltinName?.(value) ? 'object' : 'function';
|
|
1382
|
+
}
|
|
1383
|
+
if (type === 'object' && value !== null) {
|
|
1384
|
+
var prototype = Object.getPrototypeOf(value);
|
|
1385
|
+
if (prototype === _avm2XmlPrototype || prototype === _avm2XmlListPrototype) return 'xml';
|
|
1386
|
+
}
|
|
1387
|
+
return type;
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
function _avm2Call(fn, receiver, args, defaultXmlNamespace) {
|
|
1391
|
+
if (typeof fn === 'function') {
|
|
1392
|
+
var name = Object.hasOwn(fn, '__swoofQualifiedName') ? fn.__swoofQualifiedName
|
|
1393
|
+
: swflib?.qualifiedAvm2BuiltinName?.(fn) || (Object.hasOwn(fn, '__avm2InterfaceTraits') ? fn.name : null);
|
|
1394
|
+
if (name) {
|
|
1395
|
+
if (args.length !== 1) throw new TypeError(name + ' coercion requires one argument');
|
|
1396
|
+
return _coerceType(args[0], fn, name);
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
return Reflect.apply(fn, receiver, _avm2XmlConstructorArgs(fn, args, defaultXmlNamespace));
|
|
1400
|
+
}
|
|
1401
|
+
|
|
1402
|
+
function _avm2CallProperty(receiver, name, args, namespaceKeys, lexical, defaultXmlNamespace) {
|
|
1403
|
+
if (name === 'name' && typeof receiver?._swoofXmlName === 'function' &&
|
|
1404
|
+
(!namespaceKeys || namespaceKeys.includes(name))) {
|
|
1405
|
+
var nodeName = receiver._swoofXmlName();
|
|
1406
|
+
return nodeName ? new QName(nodeName[0], nodeName[1]) : null;
|
|
1407
|
+
}
|
|
1408
|
+
if (typeof receiver?._swoofXmlNamespace === 'function' &&
|
|
1409
|
+
(namespaceKeys ? namespaceKeys.includes('namespace') : name === 'namespace')) {
|
|
1410
|
+
var namespace = receiver._swoofXmlNamespace(...args);
|
|
1411
|
+
return namespace ? new Namespace(namespace[0], namespace[1]) : namespace;
|
|
1412
|
+
}
|
|
1413
|
+
if (typeof receiver?._swoofXmlNamespaces === 'function') {
|
|
1414
|
+
var declarations = namespaceKeys ? namespaceKeys.includes('namespaceDeclarations') : name === 'namespaceDeclarations';
|
|
1415
|
+
var inScope = namespaceKeys ? namespaceKeys.includes('inScopeNamespaces') : name === 'inScopeNamespaces';
|
|
1416
|
+
if (declarations || inScope) {
|
|
1417
|
+
return receiver._swoofXmlNamespaces(declarations).map(function ([prefix, uri]) {
|
|
1418
|
+
return new Namespace(prefix, uri);
|
|
1419
|
+
});
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
if (typeof receiver?._swoofMutateXmlNamespace === 'function') {
|
|
1423
|
+
var add = namespaceKeys ? namespaceKeys.includes('addNamespace') : name === 'addNamespace';
|
|
1424
|
+
var remove = namespaceKeys ? namespaceKeys.includes('removeNamespace') : name === 'removeNamespace';
|
|
1425
|
+
if (add || remove) {
|
|
1426
|
+
var value = args[0];
|
|
1427
|
+
var operand = value?.[_avm2NamespaceKeys] ? value : new Namespace(value);
|
|
1428
|
+
return receiver._swoofMutateXmlNamespace(add, operand.prefix, operand.uri);
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
var callable = namespaceKeys ? _avm2GetMethod(receiver, name, namespaceKeys)
|
|
1432
|
+
: lexical ? _avm2GetProperty(receiver, name)
|
|
1433
|
+
: _avm2ReadProperty(receiver, name);
|
|
1434
|
+
return _avm2Call(callable, lexical ? null : receiver, args, defaultXmlNamespace);
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1437
|
+
function _asType(value, type) {
|
|
1438
|
+
if (value == null) return null;
|
|
1439
|
+
if (type === globalThis.Object) return value;
|
|
1440
|
+
if (type === _avm2Int) return typeof value === 'number' && (value | 0) === value ? value : null;
|
|
1441
|
+
if (type === _avm2Uint) return typeof value === 'number' && (value >>> 0) === value ? value : null;
|
|
1442
|
+
if (type === globalThis.String) return typeof value === 'string' || value instanceof type ? value : null;
|
|
1443
|
+
if (type === globalThis.Number) return typeof value === 'number' || value instanceof type ? value : null;
|
|
1444
|
+
if (type === globalThis.Boolean) return typeof value === 'boolean' || value instanceof type ? value : null;
|
|
1445
|
+
if (typeof type !== 'function') return null;
|
|
1446
|
+
if (Object.prototype.hasOwnProperty.call(type, '__avm2InterfaceTraits')) {
|
|
1447
|
+
return _implementsAvm2Interface(value, type) ? value : null;
|
|
1448
|
+
}
|
|
1449
|
+
try { return value instanceof type ? value : null; } catch (_) { return null; }
|
|
1450
|
+
}
|
|
1451
|
+
|
|
1452
|
+
function _isType(value, type) { return _asType(value, type) !== null; }
|
|
1453
|
+
|
|
1454
|
+
function _convertObject(value) {
|
|
1455
|
+
if (value == null) throw new TypeError('Cannot convert ' + value + ' to object');
|
|
1456
|
+
return value;
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1459
|
+
function _coerceString(value) { return value == null ? null : globalThis.String(value); }
|
|
1460
|
+
|
|
1461
|
+
function _coerceType(value, type, typeName) {
|
|
1462
|
+
if (typeName === '*' || typeName == null || typeName === '') return value;
|
|
1463
|
+
if (type === _avm2Int) return globalThis.Number(value) | 0;
|
|
1464
|
+
if (type === _avm2Uint) return globalThis.Number(value) >>> 0;
|
|
1465
|
+
if (type === globalThis.Number) return globalThis.Number(value);
|
|
1466
|
+
if (type === globalThis.String) return _coerceString(value);
|
|
1467
|
+
if (type === globalThis.Boolean) return globalThis.Boolean(value);
|
|
1468
|
+
if (value == null) return null;
|
|
1469
|
+
var result = _asType(value, type);
|
|
1470
|
+
if (result !== null) return result;
|
|
1471
|
+
throw new TypeError('Cannot coerce ' + (value && value.constructor && value.constructor.name || typeof value) + ' to ' + typeName);
|
|
1472
|
+
}
|
|
1473
|
+
|
|
1474
|
+
// Every compiled method closes over its defining movie's domain. The
|
|
1475
|
+
// embedded movie runtime supplies a child-local ApplicationDomain class.
|
|
1476
|
+
var _owningDomain = swflib?.builtins?.ApplicationDomain?.currentDomain;
|
|
1477
|
+
if (typeof _owningDomain?._getDomainMemoryView !== 'function') _owningDomain = null;
|
|
1478
|
+
var _standaloneMemoryView = _owningDomain ? null : new DataView(new ArrayBuffer(1024));
|
|
1479
|
+
|
|
1480
|
+
function _setDomainMemory(memory) {
|
|
1481
|
+
if (_owningDomain) {
|
|
1482
|
+
_owningDomain.domainMemory = memory;
|
|
1483
|
+
return memory;
|
|
1484
|
+
}
|
|
1485
|
+
if (memory == null) {
|
|
1486
|
+
_standaloneMemoryView = new DataView(new ArrayBuffer(1024));
|
|
1487
|
+
return memory;
|
|
1488
|
+
}
|
|
1489
|
+
if (memory instanceof ArrayBuffer) {
|
|
1490
|
+
_standaloneMemoryView = new DataView(memory);
|
|
1491
|
+
return memory;
|
|
1492
|
+
}
|
|
1493
|
+
if (ArrayBuffer.isView(memory)) {
|
|
1494
|
+
_standaloneMemoryView = new DataView(memory.buffer, memory.byteOffset, memory.byteLength);
|
|
1495
|
+
return memory;
|
|
1496
|
+
}
|
|
1497
|
+
if (memory && typeof memory._getU8 === 'function') {
|
|
1498
|
+
var bytes = memory._getU8();
|
|
1499
|
+
if (ArrayBuffer.isView(bytes)) {
|
|
1500
|
+
_standaloneMemoryView = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
1501
|
+
return memory;
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
if (memory && memory.buffer instanceof ArrayBuffer) {
|
|
1505
|
+
var offset = Number(memory.byteOffset) || 0;
|
|
1506
|
+
var length = memory.byteLength == null ? memory.buffer.byteLength - offset : Number(memory.byteLength);
|
|
1507
|
+
_standaloneMemoryView = new DataView(memory.buffer, offset, length);
|
|
1508
|
+
return memory;
|
|
1509
|
+
}
|
|
1510
|
+
throw new TypeError('ApplicationDomain.domainMemory must expose an ArrayBuffer');
|
|
1511
|
+
}
|
|
1512
|
+
try { globalThis.__swoof_setDomainMemory = _setDomainMemory; } catch (_) {}
|
|
1513
|
+
|
|
1514
|
+
function _memAddress(index, width, view) {
|
|
1515
|
+
if (index < 0 || index + width > view.byteLength) {
|
|
1516
|
+
throw new RangeError('Domain memory access out of bounds');
|
|
1517
|
+
}
|
|
1518
|
+
return index;
|
|
1519
|
+
}
|
|
1520
|
+
|
|
1521
|
+
function _memRead(op, addr) {
|
|
1522
|
+
var index = Number(addr) | 0;
|
|
1523
|
+
var view = _owningDomain ? _owningDomain._getDomainMemoryView() : _standaloneMemoryView;
|
|
1524
|
+
switch (op) {
|
|
1525
|
+
case 0x35: return view.getUint8(_memAddress(index, 1, view));
|
|
1526
|
+
case 0x36: return view.getUint16(_memAddress(index, 2, view), true);
|
|
1527
|
+
case 0x37: return view.getInt32(_memAddress(index, 4, view), true);
|
|
1528
|
+
case 0x38: return view.getFloat32(_memAddress(index, 4, view), true);
|
|
1529
|
+
case 0x39: return view.getFloat64(_memAddress(index, 8, view), true);
|
|
1530
|
+
default: throw new Error('Unknown AVM2 domain memory load opcode 0x' + Number(op).toString(16));
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
|
|
1534
|
+
function _memWrite(op, addr, val) {
|
|
1535
|
+
var value = Number(val);
|
|
1536
|
+
var index = Number(addr) | 0;
|
|
1537
|
+
var view = _owningDomain ? _owningDomain._getDomainMemoryView() : _standaloneMemoryView;
|
|
1538
|
+
switch (op) {
|
|
1539
|
+
case 0x3a: view.setInt8(_memAddress(index, 1, view), value); return;
|
|
1540
|
+
case 0x3b: view.setInt16(_memAddress(index, 2, view), value, true); return;
|
|
1541
|
+
case 0x3c: view.setInt32(_memAddress(index, 4, view), value, true); return;
|
|
1542
|
+
case 0x3d: view.setFloat32(_memAddress(index, 4, view), value, true); return;
|
|
1543
|
+
case 0x3e: view.setFloat64(_memAddress(index, 8, view), value, true); return;
|
|
1544
|
+
default: throw new Error('Unknown AVM2 domain memory store opcode 0x' + Number(op).toString(16));
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
|
|
1548
|
+
function _signExtend(value, bits) {
|
|
1549
|
+
var shift = 32 - bits;
|
|
1550
|
+
return (Number(value) << shift) >> shift;
|
|
1551
|
+
}
|
|
1552
|
+
|
|
1553
|
+
return {
|
|
1554
|
+
_classes, _avm2ClassLexicalTraits, _avm2ScriptScopeObjects,
|
|
1555
|
+
_beginAvm2Super, _endAvm2Super, _applyAvm2Super, _createAvm2PreSuper, _initializeAvm2Instance,
|
|
1556
|
+
_bindAvm2Symbol, _registerAvm2Class, _registerAvm2Methods, _createAvm2NamespaceKeys, _avm2NamespaceConstant, _avm2Equals, _avm2RuntimeKeys, _avm2E4XProperty, _avm2GetLexicalXmlAttribute, _avm2NamedXmlProperty, _avm2Construct, _avm2ClassDefaultXmlNamespace, _avm2GetLateProperty, _avm2DeleteLateProperty, _avm2SetLateProperty, _avm2CallLateProperty, _avm2ConstructLateProperty,
|
|
1557
|
+
_createAvm2ScriptScope, _createAvm2ScriptScopes, _captureAvm2ClassScopes, _getAvm2OuterScopes, _registerAvm2ScriptMethod, _registerGlobalSlot, _getGlobalSlot, _setGlobalSlot,
|
|
1558
|
+
_queueAvm2ClassInitializer, _queueAvm2ScriptInitializer, _runAvm2Initializers,
|
|
1559
|
+
_registerAvm2Interfaces, _registerAvm2ProtectedTraits, _avm2SuperKey, _avm2Call, _avm2CallProperty,
|
|
1560
|
+
_avm2MarkMethod, _avm2BindMethod, _avm2GetProperty, _avm2GetMethod, _avm2SetProperty, _avm2DeleteProperty, _findProp,
|
|
1561
|
+
_applyType, _seedScriptTrait, _getlex, _getlexScoped, _getDefinition, _avm2NamespacedConstructor,
|
|
1562
|
+
_avm2MethodEntry, _callStatic, _callMethodById, _callSuperById, _createAvm2ExecutionBudget,
|
|
1563
|
+
_registerAvm2ActivationSlots, _createAvm2Activation, _getSlot, _setSlot,
|
|
1564
|
+
_avm2HasNext, _avm2NextName, _avm2NextValue, _avm2In,
|
|
1565
|
+
_requireAvm2Class, _avm2TypeOf, _asType, _isType, _convertObject, _coerceString, _coerceType,
|
|
1566
|
+
_setDomainMemory, _memRead, _memWrite, _signExtend
|
|
1567
|
+
};
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1570
|
+
const bindings = `
|
|
1571
|
+
_classes, _avm2ClassLexicalTraits, _avm2ScriptScopeObjects,
|
|
1572
|
+
_beginAvm2Super, _endAvm2Super, _applyAvm2Super, _createAvm2PreSuper, _initializeAvm2Instance,
|
|
1573
|
+
_bindAvm2Symbol, _registerAvm2Class, _registerAvm2Methods, _createAvm2NamespaceKeys, _avm2NamespaceConstant, _avm2Equals, _avm2RuntimeKeys, _avm2E4XProperty, _avm2GetLexicalXmlAttribute, _avm2NamedXmlProperty, _avm2Construct, _avm2ClassDefaultXmlNamespace, _avm2GetLateProperty, _avm2DeleteLateProperty, _avm2SetLateProperty, _avm2CallLateProperty, _avm2ConstructLateProperty,
|
|
1574
|
+
_createAvm2ScriptScope, _createAvm2ScriptScopes, _captureAvm2ClassScopes, _getAvm2OuterScopes, _registerAvm2ScriptMethod, _registerGlobalSlot, _getGlobalSlot, _setGlobalSlot,
|
|
1575
|
+
_queueAvm2ClassInitializer, _queueAvm2ScriptInitializer, _runAvm2Initializers,
|
|
1576
|
+
_registerAvm2Interfaces, _registerAvm2ProtectedTraits, _avm2SuperKey, _avm2Call, _avm2CallProperty,
|
|
1577
|
+
_avm2MarkMethod, _avm2BindMethod, _avm2GetProperty, _avm2GetMethod, _avm2SetProperty, _avm2DeleteProperty, _findProp,
|
|
1578
|
+
_applyType, _seedScriptTrait, _getlex, _getlexScoped, _getDefinition, _avm2NamespacedConstructor,
|
|
1579
|
+
_avm2MethodEntry, _callStatic, _callMethodById, _callSuperById, _createAvm2ExecutionBudget,
|
|
1580
|
+
_registerAvm2ActivationSlots, _createAvm2Activation, _getSlot, _setSlot,
|
|
1581
|
+
_avm2HasNext, _avm2NextName, _avm2NextValue, _avm2In,
|
|
1582
|
+
_requireAvm2Class, _avm2TypeOf, _asType, _isType, _convertObject, _coerceString, _coerceType,
|
|
1583
|
+
_setDomainMemory, _memRead, _memWrite, _signExtend
|
|
1584
|
+
`;
|
|
1585
|
+
|
|
1586
|
+
export const AVM2_RUNTIME_BOOTSTRAP = `// AVM2 helpers for this movie
|
|
1587
|
+
var {${bindings}} = __swoof_swflib.createAvm2Runtime(globalThis, __swoof_swflib);`;
|
|
1588
|
+
|
|
1589
|
+
export const AVM2_RUNTIME_STUB = `// Standalone AVM2 helpers for this movie
|
|
1590
|
+
var {${bindings}} = (${createAvm2Runtime.toString()})(globalThis,
|
|
1591
|
+
typeof __swoof_swflib === 'undefined' ? undefined : __swoof_swflib);`;
|