@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
@@ -21,18 +21,19 @@ import { NAMED } from "./dictionary-keys.js";
21
21
  import { compileUnit, Domain, definitionNames, findScript } from "./domain.js";
22
22
  import { isViewRangeError, SharedMemoryView } from "./domain-memory.js";
23
23
  import { continues, dictionaryAt, elementName, elementsAt, enumerated, forgetStep, INT_ATOM_LIMIT, nextIndex, ownNames, pairIndex, pairOf, sparseElement, traitsAt, walkless, } from "./enumeration.js";
24
- import { AsError, describe, detailOf, errorMessage, stackOf, UnsupportedError } from "./errors.js";
24
+ import { AsError, caught, describe, detailOf, errorMessage, stackOf, UnsupportedError, } from "./errors.js";
25
25
  import { FloatValue, floatValue } from "./float.js";
26
26
  import { hookedBinding } from "./hooks.js";
27
27
  import { installMethod, nativeFactory, noBodyFactory, unverifiedFactory, verifyErrorFactory, } from "./method-factories.js";
28
28
  import { Modules } from "./modules.js";
29
- import { arrayIndex, CONSTANT_Multiname, CONSTANT_MultinameA, CONSTANT_MultinameL, CONSTANT_MultinameLA, CONSTANT_Qname, CONSTANT_RTQname, CONSTANT_RTQnameA, CONSTANT_RTQnameL, CONSTANT_RTQnameLA, MADE_Number, MADE_Value, Multiname, Namespace, NS_Private, NS_Public, namespace, prefixedNamespace, prefixOf, publicNs, publicQname, qname, TypeName, } from "./names.js";
29
+ import { arrayIndex, CONSTANT_Multiname, CONSTANT_MultinameA, CONSTANT_MultinameL, CONSTANT_MultinameLA, CONSTANT_Qname, CONSTANT_RTQname, CONSTANT_RTQnameA, CONSTANT_RTQnameL, CONSTANT_RTQnameLA, MADE_Number, MADE_Value, Multiname, Namespace, NS_Private, NS_Public, namespace, prefixOf, publicNs, publicQname, qname, TypeName, } from "./names.js";
30
30
  import { FloatVector, setFloatElement } from "./natives/float-vector.js";
31
31
  import { storeDouble, storeInt, storeObject, } from "./natives/vector-elements.js";
32
- import { escapeAttributeValue, escapeElementValue } from "./natives/xml/escape.js";
32
+ import { escapeAttributeValue } from "./natives/xml/escape.js";
33
33
  import { numberToString, stringToNumber } from "./number-strings.js";
34
34
  import { defaultPrint, memoryFiles, } from "./options.js";
35
35
  import { cached, epoch, IC_Call, IC_Const, IC_Dynamic, IC_Get, IC_GetSet, IC_Method, IC_Set, IC_Slot, invalidate, NO_CACHE, ScopeFinds, UNFILLED, } from "./property-cache.js";
36
+ import { checkFilter, escapeElement, getDescendants, setDefaultXmlNamespace, } from "./runtime-xml.js";
36
37
  import { BIND_Const, BIND_Get, BIND_GetSet, BIND_Method, BIND_Set, BIND_Var, boundKey, ClassRef, methodKey, slotKey, Traits, untypedSetKey, VectorRef, } from "./traits.js";
37
38
  export { NOT_FOUND } from "./descriptors.js";
38
39
  /**
@@ -87,6 +88,7 @@ export class Runtime {
87
88
  classHooks;
88
89
  print;
89
90
  debugger;
91
+ /** @internal */
90
92
  onUnsupported;
91
93
  compileAbc;
92
94
  files;
@@ -2880,44 +2882,13 @@ export class Runtime {
2880
2882
  describe(v) {
2881
2883
  return describe(this, v);
2882
2884
  }
2883
- /** An exception as AS3 catches it: a stack overflow is an AS3 Error; the runtime's own errors are not caught. */
2885
+ /** See caught in errors.ts. */
2884
2886
  caught(e) {
2885
- if (e instanceof RangeError && /call stack/.test(e.message)) {
2886
- return this.error("Error", 1023);
2887
- }
2888
- // Domain memory's, in the handler's own method (see memoryError).
2889
- if (isViewRangeError(e)) {
2890
- return this.error("RangeError", 1506);
2891
- }
2892
- if (e instanceof UnsupportedError) {
2893
- return this.unsupportedCaught(e);
2894
- }
2895
- if (e instanceof Error && !(e instanceof AsError)) {
2896
- throw e;
2897
- }
2898
- return e;
2887
+ return caught(this, e);
2899
2888
  }
2900
- /** What a catch was told of already (unsupportedCaught). */
2889
+ /** What a catch was told of already (unsupportedCaught in errors.ts). */
2890
+ /** @internal */
2901
2891
  unsupportedTold = new Set();
2902
- /**
2903
- * What is not supported as the AS3 error a catch gets: an
2904
- * IllegalOperationError with its message, or an Error where the player's
2905
- * classes are not loaded; said once to the host, as the code may say nothing.
2906
- */
2907
- unsupportedCaught(e) {
2908
- if (!this.unsupportedTold.has(e.message)) {
2909
- this.unsupportedTold.add(e.message);
2910
- this.onUnsupported?.(e.message);
2911
- }
2912
- let cls;
2913
- try {
2914
- cls = this.resolve(this.cls(namespace(NS_Public, "flash.errors"), "IllegalOperationError"));
2915
- }
2916
- catch {
2917
- cls = this.builtinClass("Error");
2918
- }
2919
- return this.constructClass(cls, [e.message, 0]);
2920
- }
2921
2892
  catches(e, type) {
2922
2893
  return this.isInstanceOf(e, this.traitsOfType(type));
2923
2894
  }
@@ -3046,13 +3017,9 @@ export class Runtime {
3046
3017
  this.memoryView.setFloat64(at, this.toNumber(value), true);
3047
3018
  }
3048
3019
  // E4X.
3049
- /** getdescendants: x..name, on XML or XMLList; anything else, as avmplus, TypeError 1016. */
3020
+ /** See getDescendants in runtime-xml.ts. */
3050
3021
  getDescendants(o, mn) {
3051
- const properties = o?.$traits?.properties;
3052
- if (!properties) {
3053
- throw this.error("TypeError", 1016, this.describe(o));
3054
- }
3055
- return properties.descendants(this, o, mn);
3022
+ return getDescendants(this, o, mn);
3056
3023
  }
3057
3024
  /**
3058
3025
  * The default XML namespace, as dxns and dxnslate set it. avmplus keeps
@@ -3066,34 +3033,17 @@ export class Runtime {
3066
3033
  enterDxns() {
3067
3034
  return this.defaultXmlNamespace;
3068
3035
  }
3036
+ /** See setDefaultXmlNamespace in runtime-xml.ts. */
3069
3037
  setDefaultXmlNamespace(ns) {
3070
- if (ns instanceof Namespace) {
3071
- this.defaultXmlNamespace = ns;
3072
- }
3073
- else {
3074
- const uri = this.toString(ns);
3075
- this.defaultXmlNamespace = prefixedNamespace(uri === "" ? "" : undefined, uri);
3076
- }
3038
+ setDefaultXmlNamespace(this, ns);
3077
3039
  }
3078
- /** checkfilter: x.(...) filters XML and XMLList only, else TypeError 1123. */
3040
+ /** See checkFilter in runtime-xml.ts. */
3079
3041
  checkFilter(v) {
3080
- if (!v?.$traits?.properties) {
3081
- throw this.error("TypeError", 1123, this.describe(v));
3082
- }
3042
+ checkFilter(this, v);
3083
3043
  }
3084
- /** esc_xelem, as AvmCore::ToXMLString: XML's own XML, else a string escaped and trimmed. */
3044
+ /** See escapeElement in runtime-xml.ts. */
3085
3045
  escapeElement(v) {
3086
- if (typeof v === "string") {
3087
- return escapeElementValue(v, true);
3088
- }
3089
- if (typeof v !== "object" || v === null) {
3090
- return this.toString(v);
3091
- }
3092
- const properties = v.$traits?.properties;
3093
- if (properties) {
3094
- return properties.toXMLString(this, v);
3095
- }
3096
- return escapeElementValue(this.toString(v), true);
3046
+ return escapeElement(this, v);
3097
3047
  }
3098
3048
  escapeAttribute(v) {
3099
3049
  return escapeAttributeValue(this.toString(v));