@swf2es/runtime 0.1.20 → 0.1.21

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.
Files changed (64) hide show
  1. package/dist/avm2/amf.d.ts +1 -1
  2. package/dist/avm2/amf.d.ts.map +1 -1
  3. package/dist/avm2/amf.js +1 -1
  4. package/dist/avm2/amf.js.map +1 -1
  5. package/dist/avm2/enumeration.d.ts +1 -19
  6. package/dist/avm2/enumeration.d.ts.map +1 -1
  7. package/dist/avm2/enumeration.js +1 -51
  8. package/dist/avm2/enumeration.js.map +1 -1
  9. package/dist/avm2/errors.d.ts +2 -0
  10. package/dist/avm2/errors.d.ts.map +1 -1
  11. package/dist/avm2/errors.js +40 -2
  12. package/dist/avm2/errors.js.map +1 -1
  13. package/dist/avm2/index.d.ts +3 -1
  14. package/dist/avm2/index.d.ts.map +1 -1
  15. package/dist/avm2/index.js +3 -1
  16. package/dist/avm2/index.js.map +1 -1
  17. package/dist/avm2/natives/aliases.js +1 -1
  18. package/dist/avm2/natives/aliases.js.map +1 -1
  19. package/dist/avm2/natives/bytearray.d.ts +0 -160
  20. package/dist/avm2/natives/bytearray.d.ts.map +1 -1
  21. package/dist/avm2/natives/bytearray.js +1 -506
  22. package/dist/avm2/natives/bytearray.js.map +1 -1
  23. package/dist/avm2/natives/bytes.d.ts +141 -0
  24. package/dist/avm2/natives/bytes.d.ts.map +1 -0
  25. package/dist/avm2/natives/bytes.js +458 -0
  26. package/dist/avm2/natives/bytes.js.map +1 -0
  27. package/dist/avm2/natives/concurrent.js +1 -1
  28. package/dist/avm2/natives/concurrent.js.map +1 -1
  29. package/dist/avm2/natives/shared-bytes.d.ts +45 -0
  30. package/dist/avm2/natives/shared-bytes.d.ts.map +1 -0
  31. package/dist/avm2/natives/shared-bytes.js +52 -0
  32. package/dist/avm2/natives/shared-bytes.js.map +1 -0
  33. package/dist/avm2/natives/shell.d.ts.map +1 -1
  34. package/dist/avm2/natives/shell.js +3 -1
  35. package/dist/avm2/natives/shell.js.map +1 -1
  36. package/dist/avm2/options.d.ts +1 -1
  37. package/dist/avm2/options.d.ts.map +1 -1
  38. package/dist/avm2/runtime-xml.d.ts +11 -0
  39. package/dist/avm2/runtime-xml.d.ts.map +1 -0
  40. package/dist/avm2/runtime-xml.js +44 -0
  41. package/dist/avm2/runtime-xml.js.map +1 -0
  42. package/dist/avm2/runtime.d.ts +5 -13
  43. package/dist/avm2/runtime.d.ts.map +1 -1
  44. package/dist/avm2/runtime.js +17 -67
  45. package/dist/avm2/runtime.js.map +1 -1
  46. package/dist/avm2/sparse-indices.d.ts +34 -0
  47. package/dist/avm2/sparse-indices.d.ts.map +1 -0
  48. package/dist/avm2/sparse-indices.js +54 -0
  49. package/dist/avm2/sparse-indices.js.map +1 -0
  50. package/package.json +2 -2
  51. package/src/avm2/amf.ts +1 -1
  52. package/src/avm2/enumeration.ts +1 -76
  53. package/src/avm2/errors.ts +48 -3
  54. package/src/avm2/index.ts +9 -12
  55. package/src/avm2/natives/aliases.ts +1 -1
  56. package/src/avm2/natives/bytearray.ts +1 -616
  57. package/src/avm2/natives/bytes.ts +543 -0
  58. package/src/avm2/natives/concurrent.ts +1 -1
  59. package/src/avm2/natives/shared-bytes.ts +99 -0
  60. package/src/avm2/natives/shell.ts +3 -8
  61. package/src/avm2/options.ts +1 -1
  62. package/src/avm2/runtime-xml.ts +54 -0
  63. package/src/avm2/runtime.ts +31 -78
  64. package/src/avm2/sparse-indices.ts +80 -0
@@ -0,0 +1,141 @@
1
+ import type { AsObject } from "../descriptors.js";
2
+ import type { Runtime } from "../runtime.js";
3
+ import { type SharedBytesMemory } from "./shared-bytes.js";
4
+ /** DomainEnv::GLOBAL_MEMORY_MIN_SIZE: domain memory's least length. */
5
+ export declare const GLOBAL_MEMORY_MIN_SIZE = 1024;
6
+ /** The capacity of `rt`'s ByteArrays, which avmshell's System counts in its memory. */
7
+ export declare function byteArrayCapacity(rt: Runtime): number;
8
+ /**
9
+ * A ByteArray's state: its buffer, as long as its capacity, and its length
10
+ * and position. A read or write takes its offset first: growing replaces
11
+ * the buffer and its view.
12
+ *
13
+ * A length or position is stored through `>>> 0`, as a uint32: an int32
14
+ * while below 2^31, and a double only from there.
15
+ * JavaScriptCore keeps a number its JIT once made a double a double, and
16
+ * an addition that has seen one makes doubles from then on: a double
17
+ * offset fails the int32 check of a DataView or typed array access, and
18
+ * after enough failures JavaScriptCore calls DataView's methods instead
19
+ * of inlining them, a quarter slower on every read and write. V8 makes
20
+ * small integers of them itself.
21
+ */
22
+ export declare class Bytes {
23
+ readonly rt: Runtime;
24
+ readonly owner: AsObject;
25
+ buffer: Uint8Array;
26
+ view: DataView<ArrayBufferLike>;
27
+ length: number;
28
+ position: number;
29
+ littleEndian: boolean;
30
+ /** As ByteArray's constructor: ByteArray.defaultObjectEncoding when it is made. */
31
+ objectEncoding: number;
32
+ /** Whether it is the domain memory, which it then tells when its buffer or length changes. */
33
+ subscribed: boolean;
34
+ /**
35
+ * Whether `shareable` was set true, which cannot be undone: the
36
+ * ByteArray then crosses to another worker as its memory, not a copy.
37
+ */
38
+ shareable: boolean;
39
+ /**
40
+ * Its memory once it has crossed to another worker (share), which its
41
+ * buffer and view are then over, tracking its length as it grows; null
42
+ * until then, when it is a ByteArray like any other.
43
+ */
44
+ shared: SharedBytesMemory | null;
45
+ /** The shared memory's words, the length first, and its bytes as words for the atomics. */
46
+ private sharedWords;
47
+ private sharedInts;
48
+ /** Its runtime's capacity count, and its own part of it. */
49
+ private readonly capacity;
50
+ constructor(rt: Runtime, owner: AsObject);
51
+ /** Its buffer replaced by `next`, its runtime's capacity count with it. */
52
+ setBuffer(next: Uint8Array<ArrayBuffer>): void;
53
+ get available(): number;
54
+ /** As Grower::ReallocBackingStore: a new buffer, the old length's bytes copied and the rest zero. */
55
+ private realloc;
56
+ /** As Grower::EnsureWritableCapacity: double, at least `minimum`, and 4096 unless the setter sizes an empty one. */
57
+ private ensure;
58
+ /** As ByteArray::SetLengthCommon. */
59
+ setLength(length: number, fromSetter?: boolean): void;
60
+ /**
61
+ * The length made at least `length`, as a write past the end makes it:
62
+ * shared, by a compare and swap that only ever raises it, so that
63
+ * workers appending at once never lower what another made it.
64
+ */
65
+ extend(length: number): void;
66
+ /** A shared length raised to `length` unless another worker made it as long. */
67
+ private raise;
68
+ /** As Grower::SetLengthCommon, before the length is set: the capacity for `length`. */
69
+ private reserve;
70
+ /** Tell the domain memory, if this is it, where the bytes are now: a new view only if they moved or their length changed. */
71
+ notify(): void;
72
+ /** As ByteArray::Clear: no buffer at all; shared, every worker's ByteArray for it empty. */
73
+ clear(): void;
74
+ /**
75
+ * Its memory, shared from now on: a growable SharedArrayBuffer its bytes
76
+ * move to once, and that this ByteArray, and every worker's ByteArray for
77
+ * it, uses from then on. Where memory cannot be shared, the error that
78
+ * names cross-origin isolation.
79
+ */
80
+ share(): SharedBytesMemory;
81
+ /**
82
+ * Use `memory`, shared, as its bytes and length from now on. Its length
83
+ * becomes an accessor of the memory's word on this object alone, so that
84
+ * every read sees another worker's change and every write is seen, and
85
+ * a ByteArray that shares nothing reads a plain field as before.
86
+ */
87
+ adopt(memory: SharedBytesMemory): void;
88
+ /**
89
+ * A shared memory's capacity made at least `capacity`: it grows in place,
90
+ * which every worker sees, and never shrinks, as another worker may have
91
+ * grown it past what this one asks for since. Nor is what a smaller
92
+ * buffer would drop zeroed: without avmplus' safepoint, another worker
93
+ * may have grown the length again and written there meanwhile, so bytes
94
+ * past a lowered length may come back when it grows again.
95
+ */
96
+ private reshare;
97
+ /** As ByteArray::CAS, once the index is checked: atomic where the memory is shared. */
98
+ compareAndSwapInt(at: number, expected: number, next: number): number;
99
+ /**
100
+ * As UnprotectedAtomicCompareAndSwapLength: the length set to `next`, as
101
+ * its setter sets it, if it is `expected`; the length before. Shared,
102
+ * the capacity is made first and the length swapped atomically, so that
103
+ * of workers growing it at once one wins.
104
+ */
105
+ compareAndSwapLength(expected: number, next: number): number;
106
+ /** As requestBytesForShortRead: the offset of `n` bytes to read, or EOFError. */
107
+ shortRead(n: number): number;
108
+ /** As requestBytesForShortWrite: the offset of `n` bytes to write, the length grown to hold them. */
109
+ shortWrite(n: number): number;
110
+ /** As DataInput::CheckEOF. */
111
+ checkEOF(count: number): void;
112
+ /** As ByteArray::Read: `count` bytes from the position. */
113
+ read(count: number): Uint8Array;
114
+ /** As read, but the bytes themselves, not a copy: for a caller that only reads them, at once. */
115
+ readView(count: number): Uint8Array;
116
+ /**
117
+ * As ByteArray::Write: `count` bytes of `source` from `offset`, all of
118
+ * it by default, at the position; the length grows to the position after.
119
+ */
120
+ write(source: Uint8Array, offset?: number, count?: number): void;
121
+ /**
122
+ * As ByteArray::Write but for the bytes, which the caller writes itself:
123
+ * room for `count` at the position, which moves past them, the length
124
+ * growing to it. Where in the buffer they start.
125
+ */
126
+ claim(count: number): number;
127
+ /** As ByteArray's operator[] for a write: the length grows to hold `index`. */
128
+ setByte(index: number, value: number): void;
129
+ }
130
+ /**
131
+ * `count` bytes of `source` from `offset` copied into `target` at `at`,
132
+ * as memmove copies them where the two are one array. Part of `source`,
133
+ * fewer than COPY_LOOP_LENGTH bytes, is copied one at a time: the
134
+ * subarray set() would take costs more than they do, in JavaScriptCore up
135
+ * to about 64 bytes and in V8 up to about 32. All of it set() copies
136
+ * faster than a loop in V8, and as fast in JavaScriptCore.
137
+ */
138
+ export declare function copyBytes(target: Uint8Array, at: number, source: Uint8Array, offset: number, count: number): void;
139
+ /** A ByteArray's state, made the first time a native needs it. */
140
+ export declare function bytesOf(rt: Runtime, o: AsObject): Bytes;
141
+ //# sourceMappingURL=bytes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bytes.d.ts","sourceRoot":"","sources":["../../../src/avm2/natives/bytes.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAKL,KAAK,iBA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,IAAI,CAYN;AAED,kEAAkE;AAClE,wBAAgB,OAAO,CAAC,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,QAAQ,GAAG,KAAK,CAMvD"}
@@ -0,0 +1,458 @@
1
+ import { canShareMemory, notIsolated, sharedObjectsOf, } from "./shared-bytes.js";
2
+ const kGrowthIncr = 4096;
3
+ const kHugeGrowthThreshold = 24 * 1024 * 1024;
4
+ const kHugeGrowthIncr = 24 * 1024 * 1024;
5
+ /**
6
+ * The most a ByteArray holds: what a 32-bit avmshell, as the oracle's, can
7
+ * allocate, beyond which it fails with MemoryError 1000, and less than a
8
+ * browser's ArrayBuffer may be refused at.
9
+ */
10
+ const kMaxCapacity = 0x80000000;
11
+ /** DomainEnv::GLOBAL_MEMORY_MIN_SIZE: domain memory's least length. */
12
+ export const GLOBAL_MEMORY_MIN_SIZE = 1024;
13
+ /** The capacity of each runtime's ByteArrays, live or not yet collected. */
14
+ const runtimeCapacity = new WeakMap();
15
+ /** A ByteArray collected: its capacity no longer counted, by its runtime's count and its own. */
16
+ const collected = new FinalizationRegistry(({ runtime, own }) => {
17
+ runtime.bytes -= own.bytes;
18
+ });
19
+ /** The capacity of `rt`'s ByteArrays, which avmshell's System counts in its memory. */
20
+ export function byteArrayCapacity(rt) {
21
+ return runtimeCapacity.get(rt)?.bytes ?? 0;
22
+ }
23
+ /**
24
+ * A ByteArray's state: its buffer, as long as its capacity, and its length
25
+ * and position. A read or write takes its offset first: growing replaces
26
+ * the buffer and its view.
27
+ *
28
+ * A length or position is stored through `>>> 0`, as a uint32: an int32
29
+ * while below 2^31, and a double only from there.
30
+ * JavaScriptCore keeps a number its JIT once made a double a double, and
31
+ * an addition that has seen one makes doubles from then on: a double
32
+ * offset fails the int32 check of a DataView or typed array access, and
33
+ * after enough failures JavaScriptCore calls DataView's methods instead
34
+ * of inlining them, a quarter slower on every read and write. V8 makes
35
+ * small integers of them itself.
36
+ */
37
+ export class Bytes {
38
+ rt;
39
+ owner;
40
+ buffer = new Uint8Array(0);
41
+ view = new DataView(this.buffer.buffer);
42
+ length = 0;
43
+ position = 0;
44
+ littleEndian = false;
45
+ /** As ByteArray's constructor: ByteArray.defaultObjectEncoding when it is made. */
46
+ objectEncoding;
47
+ /** Whether it is the domain memory, which it then tells when its buffer or length changes. */
48
+ subscribed = false;
49
+ /**
50
+ * Whether `shareable` was set true, which cannot be undone: the
51
+ * ByteArray then crosses to another worker as its memory, not a copy.
52
+ */
53
+ shareable = false;
54
+ /**
55
+ * Its memory once it has crossed to another worker (share), which its
56
+ * buffer and view are then over, tracking its length as it grows; null
57
+ * until then, when it is a ByteArray like any other.
58
+ */
59
+ shared = null;
60
+ /** The shared memory's words, the length first, and its bytes as words for the atomics. */
61
+ sharedWords = null;
62
+ sharedInts = null;
63
+ /** Its runtime's capacity count, and its own part of it. */
64
+ capacity;
65
+ constructor(rt, owner) {
66
+ this.rt = rt;
67
+ this.owner = owner;
68
+ this.objectEncoding = rt.defaultObjectEncoding;
69
+ let runtime = runtimeCapacity.get(rt);
70
+ if (!runtime) {
71
+ runtime = { bytes: 0 };
72
+ runtimeCapacity.set(rt, runtime);
73
+ }
74
+ this.capacity = { runtime, own: { bytes: 0 } };
75
+ collected.register(this, this.capacity);
76
+ }
77
+ /** Its buffer replaced by `next`, its runtime's capacity count with it. */
78
+ setBuffer(next) {
79
+ const { runtime, own } = this.capacity;
80
+ runtime.bytes += next.length - own.bytes;
81
+ own.bytes = next.length;
82
+ this.buffer = next;
83
+ this.view = new DataView(next.buffer);
84
+ }
85
+ get available() {
86
+ return this.length > this.position ? this.length - this.position : 0;
87
+ }
88
+ /** As Grower::ReallocBackingStore: a new buffer, the old length's bytes copied and the rest zero. */
89
+ realloc(capacityIn, minimum, fromSetter) {
90
+ let capacity = capacityIn;
91
+ if (capacity < minimum) {
92
+ capacity = minimum;
93
+ }
94
+ if (!(this.buffer.length === 0 && fromSetter) && capacity < kGrowthIncr) {
95
+ capacity = kGrowthIncr;
96
+ }
97
+ if (minimum > kMaxCapacity) {
98
+ throw this.rt.error("flash.errors::MemoryError", 1000);
99
+ }
100
+ capacity = Math.min(capacity, kMaxCapacity);
101
+ if (capacity === this.buffer.length) {
102
+ return;
103
+ }
104
+ if (this.shared !== null) {
105
+ this.reshare(capacity);
106
+ return;
107
+ }
108
+ let next;
109
+ try {
110
+ next = new Uint8Array(capacity);
111
+ }
112
+ catch {
113
+ // The host would not give it the memory, as the system would not give avmplus.
114
+ throw this.rt.error("flash.errors::MemoryError", 1000);
115
+ }
116
+ next.set(this.buffer.subarray(0, Math.min(capacity, this.length)));
117
+ this.setBuffer(next);
118
+ }
119
+ /** As Grower::EnsureWritableCapacity: double, at least `minimum`, and 4096 unless the setter sizes an empty one. */
120
+ ensure(minimum, fromSetter) {
121
+ if (minimum > 0xffffffff - 2 * 4096) {
122
+ throw this.rt.error("flash.errors::MemoryError", 1000);
123
+ }
124
+ if (minimum > this.buffer.length) {
125
+ this.realloc(this.buffer.length * 2, minimum, fromSetter);
126
+ }
127
+ }
128
+ /** As ByteArray::SetLengthCommon. */
129
+ setLength(length, fromSetter = false) {
130
+ if (this.subscribed && length < GLOBAL_MEMORY_MIN_SIZE) {
131
+ throw this.rt.error("RangeError", 1506);
132
+ }
133
+ this.reserve(length, fromSetter);
134
+ this.length = length >>> 0;
135
+ if (this.position > length) {
136
+ this.position = length >>> 0;
137
+ }
138
+ this.notify();
139
+ }
140
+ /**
141
+ * The length made at least `length`, as a write past the end makes it:
142
+ * shared, by a compare and swap that only ever raises it, so that
143
+ * workers appending at once never lower what another made it.
144
+ */
145
+ extend(length) {
146
+ if (this.shared === null) {
147
+ this.setLength(length);
148
+ return;
149
+ }
150
+ this.reserve(length, false);
151
+ this.raise(length);
152
+ this.notify();
153
+ }
154
+ /** A shared length raised to `length` unless another worker made it as long. */
155
+ raise(length) {
156
+ const words = this.sharedWords;
157
+ for (;;) {
158
+ const now = Atomics.load(words, 0) >>> 0;
159
+ if (now >= length || Atomics.compareExchange(words, 0, now | 0, length | 0) >>> 0 === now) {
160
+ return;
161
+ }
162
+ }
163
+ }
164
+ /** As Grower::SetLengthCommon, before the length is set: the capacity for `length`. */
165
+ reserve(length, fromSetter) {
166
+ if (!fromSetter || (length < kHugeGrowthThreshold && this.length < kHugeGrowthThreshold)) {
167
+ if (length > this.buffer.length) {
168
+ this.ensure(length, fromSetter);
169
+ }
170
+ }
171
+ else {
172
+ const rounded = Math.ceil(length / kHugeGrowthIncr) * kHugeGrowthIncr;
173
+ const capacity = rounded <= 0xffffffff - 2 * 4096 ? rounded : length;
174
+ if (capacity !== this.buffer.length) {
175
+ this.realloc(capacity, length, true);
176
+ }
177
+ }
178
+ }
179
+ /** Tell the domain memory, if this is it, where the bytes are now: a new view only if they moved or their length changed. */
180
+ notify() {
181
+ const rt = this.rt;
182
+ if (this.subscribed &&
183
+ (rt.memory.buffer !== this.buffer.buffer || rt.memoryLength !== this.length)) {
184
+ rt.memory = new DataView(this.buffer.buffer, 0, this.length);
185
+ }
186
+ }
187
+ /** As ByteArray::Clear: no buffer at all; shared, every worker's ByteArray for it empty. */
188
+ clear() {
189
+ if (this.subscribed) {
190
+ throw this.rt.error("RangeError", 1506);
191
+ }
192
+ this.position = 0;
193
+ if (this.shared !== null) {
194
+ // The memory cannot shrink: what it held is zeroed, as a new buffer
195
+ // would be once it grows again, before the length is told, so that a
196
+ // worker that grows it once it is empty writes into zeroes already.
197
+ this.buffer.fill(0);
198
+ this.length = 0;
199
+ return;
200
+ }
201
+ this.setBuffer(new Uint8Array(0));
202
+ this.length = 0;
203
+ }
204
+ /**
205
+ * Its memory, shared from now on: a growable SharedArrayBuffer its bytes
206
+ * move to once, and that this ByteArray, and every worker's ByteArray for
207
+ * it, uses from then on. Where memory cannot be shared, the error that
208
+ * names cross-origin isolation.
209
+ */
210
+ share() {
211
+ if (this.shared !== null) {
212
+ return this.shared;
213
+ }
214
+ if (!canShareMemory()) {
215
+ throw notIsolated("a shareable ByteArray");
216
+ }
217
+ const capacity = Math.max(this.buffer.length, this.length);
218
+ const Shared = SharedArrayBuffer;
219
+ let data = null;
220
+ // As much room to grow as a ByteArray has, or as much as the host reserves.
221
+ for (let max = kMaxCapacity; data === null; max /= 2) {
222
+ try {
223
+ data = new Shared(capacity, { maxByteLength: Math.max(max, capacity) });
224
+ }
225
+ catch {
226
+ if (max <= capacity) {
227
+ throw this.rt.error("flash.errors::MemoryError", 1000);
228
+ }
229
+ }
230
+ }
231
+ new Uint8Array(data).set(this.buffer);
232
+ const memory = {
233
+ id: Math.floor(Math.random() * 2 ** 52),
234
+ meta: new SharedArrayBuffer(8),
235
+ data,
236
+ };
237
+ new Int32Array(memory.meta)[0] = this.length | 0;
238
+ this.adopt(memory);
239
+ sharedObjectsOf(this.rt).set(memory.id, new WeakRef(this.owner));
240
+ return memory;
241
+ }
242
+ /**
243
+ * Use `memory`, shared, as its bytes and length from now on. Its length
244
+ * becomes an accessor of the memory's word on this object alone, so that
245
+ * every read sees another worker's change and every write is seen, and
246
+ * a ByteArray that shares nothing reads a plain field as before.
247
+ */
248
+ adopt(memory) {
249
+ this.shared = memory;
250
+ this.shareable = true;
251
+ const words = new Int32Array(memory.meta);
252
+ this.sharedWords = words;
253
+ Object.defineProperty(this, "length", {
254
+ get: () => Atomics.load(words, 0) >>> 0,
255
+ set: (length) => Atomics.store(words, 0, length | 0),
256
+ configurable: true,
257
+ });
258
+ // Views that track the memory's length as any worker grows it.
259
+ this.buffer = new Uint8Array(memory.data);
260
+ this.view = new DataView(memory.data);
261
+ this.sharedInts = new Int32Array(memory.data);
262
+ const { runtime, own } = this.capacity;
263
+ runtime.bytes += memory.data.byteLength - own.bytes;
264
+ own.bytes = memory.data.byteLength;
265
+ if (this.subscribed) {
266
+ this.rt.refreshMemory = () => this.notify();
267
+ }
268
+ this.notify();
269
+ }
270
+ /**
271
+ * A shared memory's capacity made at least `capacity`: it grows in place,
272
+ * which every worker sees, and never shrinks, as another worker may have
273
+ * grown it past what this one asks for since. Nor is what a smaller
274
+ * buffer would drop zeroed: without avmplus' safepoint, another worker
275
+ * may have grown the length again and written there meanwhile, so bytes
276
+ * past a lowered length may come back when it grows again.
277
+ */
278
+ reshare(capacity) {
279
+ const data = this.shared.data;
280
+ if (capacity <= data.byteLength) {
281
+ return;
282
+ }
283
+ if (capacity > data.maxByteLength) {
284
+ throw this.rt.error("flash.errors::MemoryError", 1000);
285
+ }
286
+ try {
287
+ data.grow(capacity);
288
+ }
289
+ catch {
290
+ // Another worker grew it meanwhile, to as much or more, or the host refused.
291
+ if (data.byteLength < capacity) {
292
+ throw this.rt.error("flash.errors::MemoryError", 1000);
293
+ }
294
+ }
295
+ const { runtime, own } = this.capacity;
296
+ runtime.bytes += data.byteLength - own.bytes;
297
+ own.bytes = data.byteLength;
298
+ }
299
+ /** As ByteArray::CAS, once the index is checked: atomic where the memory is shared. */
300
+ compareAndSwapInt(at, expected, next) {
301
+ if (this.sharedInts !== null) {
302
+ return Atomics.compareExchange(this.sharedInts, at >> 2, expected, next);
303
+ }
304
+ const previous = this.view.getInt32(at, true);
305
+ if (previous === expected) {
306
+ this.view.setInt32(at, next, true);
307
+ }
308
+ return previous;
309
+ }
310
+ /**
311
+ * As UnprotectedAtomicCompareAndSwapLength: the length set to `next`, as
312
+ * its setter sets it, if it is `expected`; the length before. Shared,
313
+ * the capacity is made first and the length swapped atomically, so that
314
+ * of workers growing it at once one wins.
315
+ */
316
+ compareAndSwapLength(expected, next) {
317
+ if (this.shared === null) {
318
+ const previous = this.length;
319
+ if (previous === expected) {
320
+ this.setLength(next, true);
321
+ }
322
+ return previous;
323
+ }
324
+ // Read once: another worker may change it between two reads.
325
+ const now = this.length;
326
+ if (now !== expected) {
327
+ return now;
328
+ }
329
+ // Only grows the memory, so it does nothing another worker would undo if the swap fails.
330
+ this.reserve(next, true);
331
+ const previous = Atomics.compareExchange(this.sharedWords, 0, expected | 0, next | 0) >>> 0;
332
+ if (previous === expected && this.position > next) {
333
+ this.position = next;
334
+ }
335
+ this.notify();
336
+ return previous;
337
+ }
338
+ /** As requestBytesForShortRead: the offset of `n` bytes to read, or EOFError. */
339
+ shortRead(n) {
340
+ const at = this.position;
341
+ if (at >= this.length || at + n > this.length) {
342
+ throw this.rt.error("flash.errors::EOFError", 2030);
343
+ }
344
+ this.position = (at + n) >>> 0;
345
+ return at;
346
+ }
347
+ /** As requestBytesForShortWrite: the offset of `n` bytes to write, the length grown to hold them. */
348
+ shortWrite(n) {
349
+ const at = this.position;
350
+ if (at >= this.length || at + n > this.length) {
351
+ if (at + n > 0xffffffff) {
352
+ throw this.rt.error("flash.errors::MemoryError", 1000);
353
+ }
354
+ this.extend(at + n);
355
+ }
356
+ this.position = (at + n) >>> 0;
357
+ return at;
358
+ }
359
+ /** As DataInput::CheckEOF. */
360
+ checkEOF(count) {
361
+ if (this.available < count) {
362
+ throw this.rt.error("flash.errors::EOFError", 2030);
363
+ }
364
+ }
365
+ /** As ByteArray::Read: `count` bytes from the position. */
366
+ read(count) {
367
+ this.checkEOF(count);
368
+ const bytes = this.buffer.slice(this.position, this.position + count);
369
+ this.position = (this.position + count) >>> 0;
370
+ return bytes;
371
+ }
372
+ /** As read, but the bytes themselves, not a copy: for a caller that only reads them, at once. */
373
+ readView(count) {
374
+ this.checkEOF(count);
375
+ const bytes = this.buffer.subarray(this.position, this.position + count);
376
+ this.position = (this.position + count) >>> 0;
377
+ return bytes;
378
+ }
379
+ /**
380
+ * As ByteArray::Write: `count` bytes of `source` from `offset`, all of
381
+ * it by default, at the position; the length grows to the position after.
382
+ */
383
+ write(source, offset = 0, count = source.length) {
384
+ // Before the buffer is read: making room may replace it.
385
+ const at = this.claim(count);
386
+ copyBytes(this.buffer, at, source, offset, count);
387
+ }
388
+ /**
389
+ * As ByteArray::Write but for the bytes, which the caller writes itself:
390
+ * room for `count` at the position, which moves past them, the length
391
+ * growing to it. Where in the buffer they start.
392
+ */
393
+ claim(count) {
394
+ if (count > 0xffffffff - this.position) {
395
+ throw this.rt.error("flash.errors::MemoryError", 1000);
396
+ }
397
+ const at = this.position;
398
+ const end = (at + count) >>> 0;
399
+ if (end > this.buffer.length) {
400
+ this.ensure(end, false);
401
+ }
402
+ this.position = end;
403
+ if (this.length < end) {
404
+ if (this.shared === null) {
405
+ this.length = end;
406
+ }
407
+ else {
408
+ this.raise(end);
409
+ }
410
+ }
411
+ this.notify();
412
+ return at;
413
+ }
414
+ /** As ByteArray's operator[] for a write: the length grows to hold `index`. */
415
+ setByte(index, value) {
416
+ if (index >= this.length) {
417
+ if (index === 0xffffffff) {
418
+ throw this.rt.error("flash.errors::MemoryError", 1000);
419
+ }
420
+ this.extend(index + 1);
421
+ }
422
+ this.buffer[index] = value;
423
+ }
424
+ }
425
+ /** Below this many bytes, copyBytes copies one at a time. */
426
+ const COPY_LOOP_LENGTH = 32;
427
+ /**
428
+ * `count` bytes of `source` from `offset` copied into `target` at `at`,
429
+ * as memmove copies them where the two are one array. Part of `source`,
430
+ * fewer than COPY_LOOP_LENGTH bytes, is copied one at a time: the
431
+ * subarray set() would take costs more than they do, in JavaScriptCore up
432
+ * to about 64 bytes and in V8 up to about 32. All of it set() copies
433
+ * faster than a loop in V8, and as fast in JavaScriptCore.
434
+ */
435
+ export function copyBytes(target, at, source, offset, count) {
436
+ if (source === target) {
437
+ target.copyWithin(at, offset, offset + count);
438
+ }
439
+ else if (offset === 0 && count === source.length) {
440
+ target.set(source, at);
441
+ }
442
+ else if (count < COPY_LOOP_LENGTH) {
443
+ for (let i = 0; i < count; i++) {
444
+ target[at + i] = source[offset + i];
445
+ }
446
+ }
447
+ else {
448
+ target.set(source.subarray(offset, offset + count), at);
449
+ }
450
+ }
451
+ /** A ByteArray's state, made the first time a native needs it. */
452
+ export function bytesOf(rt, o) {
453
+ if (!o.$bytes) {
454
+ o.$bytes = new Bytes(rt, o);
455
+ }
456
+ return o.$bytes;
457
+ }
458
+ //# sourceMappingURL=bytes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bytes.js","sourceRoot":"","sources":["../../../src/avm2/natives/bytes.ts"],"names":[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E,EAAE,CAAC,CAAC;IAC1D,CAAC;AACH,CAAC;AAED,kEAAkE;AAClE,MAAM,UAAU,OAAO,CAAC,EAAW,EAAE,CAAW;IAC9C,IAAI,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;QACd,CAAC,CAAC,MAAM,GAAG,IAAI,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IAC9B,CAAC;IAED,OAAO,CAAC,CAAC,MAAM,CAAC;AAClB,CAAC"}
@@ -4,7 +4,7 @@
4
4
  // object for each, as avmplus interns one for its State. And
5
5
  // avm2.intrinsics.memory's compare and swap. Crossbridge uses them all on
6
6
  // startup whether or not it starts workers.
7
- import { bytesOf } from "./bytearray.js";
7
+ import { bytesOf } from "./bytes.js";
8
8
  import { plain, registerNativeClass } from "./define.js";
9
9
  import { newSyncMemory, Sync, SyncFull, SyncTimeout } from "./sync.js";
10
10
  const vmSyncs = new WeakMap();