jseption 0.0.0-stage → 0.0.1

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 (114) hide show
  1. package/LICENSE +26 -0
  2. package/README.md +191 -2
  3. package/dist/atoms.d.ts +255 -0
  4. package/dist/atoms.js +445 -0
  5. package/dist/atoms.js.map +1 -0
  6. package/dist/builtins/array.d.ts +3 -0
  7. package/dist/builtins/array.js +116 -0
  8. package/dist/builtins/array.js.map +1 -0
  9. package/dist/builtins/bigint.d.ts +3 -0
  10. package/dist/builtins/bigint.js +122 -0
  11. package/dist/builtins/bigint.js.map +1 -0
  12. package/dist/builtins/boolean.d.ts +2 -0
  13. package/dist/builtins/boolean.js +26 -0
  14. package/dist/builtins/boolean.js.map +1 -0
  15. package/dist/builtins/date.d.ts +3 -0
  16. package/dist/builtins/date.js +1046 -0
  17. package/dist/builtins/date.js.map +1 -0
  18. package/dist/builtins/error.d.ts +2 -0
  19. package/dist/builtins/error.js +154 -0
  20. package/dist/builtins/error.js.map +1 -0
  21. package/dist/builtins/function.d.ts +5 -0
  22. package/dist/builtins/function.js +164 -0
  23. package/dist/builtins/function.js.map +1 -0
  24. package/dist/builtins/global.d.ts +2 -0
  25. package/dist/builtins/global.js +29 -0
  26. package/dist/builtins/global.js.map +1 -0
  27. package/dist/builtins/index.d.ts +3 -0
  28. package/dist/builtins/index.js +139 -0
  29. package/dist/builtins/index.js.map +1 -0
  30. package/dist/builtins/json.d.ts +6 -0
  31. package/dist/builtins/json.js +984 -0
  32. package/dist/builtins/json.js.map +1 -0
  33. package/dist/builtins/mapset.d.ts +4 -0
  34. package/dist/builtins/mapset.js +234 -0
  35. package/dist/builtins/mapset.js.map +1 -0
  36. package/dist/builtins/math.d.ts +2 -0
  37. package/dist/builtins/math.js +62 -0
  38. package/dist/builtins/math.js.map +1 -0
  39. package/dist/builtins/native.d.ts +22 -0
  40. package/dist/builtins/native.js +250 -0
  41. package/dist/builtins/native.js.map +1 -0
  42. package/dist/builtins/number.d.ts +4 -0
  43. package/dist/builtins/number.js +76 -0
  44. package/dist/builtins/number.js.map +1 -0
  45. package/dist/builtins/object.d.ts +12 -0
  46. package/dist/builtins/object.js +575 -0
  47. package/dist/builtins/object.js.map +1 -0
  48. package/dist/builtins/promise.d.ts +13 -0
  49. package/dist/builtins/promise.js +582 -0
  50. package/dist/builtins/promise.js.map +1 -0
  51. package/dist/builtins/proxy.d.ts +3 -0
  52. package/dist/builtins/proxy.js +226 -0
  53. package/dist/builtins/proxy.js.map +1 -0
  54. package/dist/builtins/reflect.d.ts +2 -0
  55. package/dist/builtins/reflect.js +109 -0
  56. package/dist/builtins/reflect.js.map +1 -0
  57. package/dist/builtins/regexp.d.ts +2 -0
  58. package/dist/builtins/regexp.js +203 -0
  59. package/dist/builtins/regexp.js.map +1 -0
  60. package/dist/builtins/string.d.ts +4 -0
  61. package/dist/builtins/string.js +135 -0
  62. package/dist/builtins/string.js.map +1 -0
  63. package/dist/builtins/symbol.d.ts +3 -0
  64. package/dist/builtins/symbol.js +98 -0
  65. package/dist/builtins/symbol.js.map +1 -0
  66. package/dist/builtins/typedarray.d.ts +15 -0
  67. package/dist/builtins/typedarray.js +1838 -0
  68. package/dist/builtins/typedarray.js.map +1 -0
  69. package/dist/builtins/weakref.d.ts +18 -0
  70. package/dist/builtins/weakref.js +130 -0
  71. package/dist/builtins/weakref.js.map +1 -0
  72. package/dist/dump.d.ts +2 -0
  73. package/dist/dump.js +124 -0
  74. package/dist/dump.js.map +1 -0
  75. package/dist/embed.d.ts +18 -0
  76. package/dist/embed.js +286 -0
  77. package/dist/embed.js.map +1 -0
  78. package/dist/interpreter.d.ts +81 -0
  79. package/dist/interpreter.js +3768 -0
  80. package/dist/interpreter.js.map +1 -0
  81. package/dist/jit.d.ts +59 -0
  82. package/dist/jit.js +3429 -0
  83. package/dist/jit.js.map +1 -0
  84. package/dist/jit_hook.d.ts +21 -0
  85. package/dist/jit_hook.js +4 -0
  86. package/dist/jit_hook.js.map +1 -0
  87. package/dist/jit_runtime.d.ts +101 -0
  88. package/dist/jit_runtime.js +690 -0
  89. package/dist/jit_runtime.js.map +1 -0
  90. package/dist/jit_stack.d.ts +24 -0
  91. package/dist/jit_stack.js +227 -0
  92. package/dist/jit_stack.js.map +1 -0
  93. package/dist/jseption.d.ts +15 -0
  94. package/dist/jseption.js +61 -0
  95. package/dist/jseption.js.map +1 -0
  96. package/dist/opcodes.d.ts +347 -0
  97. package/dist/opcodes.js +322 -0
  98. package/dist/opcodes.js.map +1 -0
  99. package/dist/parser.d.ts +283 -0
  100. package/dist/parser.js +9752 -0
  101. package/dist/parser.js.map +1 -0
  102. package/dist/qjs.d.ts +2 -0
  103. package/dist/qjs.js +122 -0
  104. package/dist/qjs.js.map +1 -0
  105. package/dist/quickjs.d.ts +460 -0
  106. package/dist/quickjs.js +3408 -0
  107. package/dist/quickjs.js.map +1 -0
  108. package/dist/std.d.ts +4 -0
  109. package/dist/std.js +273 -0
  110. package/dist/std.js.map +1 -0
  111. package/dist/values.d.ts +447 -0
  112. package/dist/values.js +461 -0
  113. package/dist/values.js.map +1 -0
  114. package/package.json +59 -4
@@ -0,0 +1,116 @@
1
+ /*
2
+ * Array objects (port of the Array part of quickjs.c)
3
+ *
4
+ * Guest arrays are host arrays with the guest Array.prototype, so every
5
+ * Array.prototype method and the static methods are borrowed host natives
6
+ * (see builtins/native.ts); only the constructor and Symbol.species are
7
+ * engine code. Arrays created by the natives (ArrayCreate, or
8
+ * ArraySpeciesCreate falling back to %Array%) are re-prototyped by the
9
+ * fixers; species created arrays come from the guest constructor and are
10
+ * already guest arrays.
11
+ */
12
+ import { JS_EXCEPTION, JS_IsException, JS_IsNumber, js_create_from_ctor, JS_SetProperty, JS_SetPropertyInt64, JS_DefinePropertyValue, JS_DefinePropertyValueStr, JS_NewObjectProto, JS_ToArrayLengthFree, JS_SetPropertyFunctionList, JS_NATIVE_DEF, JS_CGETSET_DEF, JS_ALIAS_DEF, JS_NewGlobalCConstructor, JS_PROP_C_W_E, JS_PROP_CONFIGURABLE, JS_ATOM_length, JS_ATOM_Symbol_iterator, JS_ATOM_Symbol_species, JS_ATOM_Symbol_unscopables, } from "../quickjs.js";
13
+ import { fix_any, fix_array_iterator } from "./native.js";
14
+ /* ---------------------------------------------------------------------
15
+ Array constructor and static methods
16
+ --------------------------------------------------------------------- */
17
+ export function js_array_constructor(ctx, new_target, argv) {
18
+ const argc = argv.length;
19
+ const obj = js_create_from_ctor(ctx, new_target, 2 /* JSClassID.ARRAY */);
20
+ if (JS_IsException(obj))
21
+ return obj;
22
+ if (argc === 1 && JS_IsNumber(argv[0])) {
23
+ const len = JS_ToArrayLengthFree(ctx, argv[0], true);
24
+ if (len < 0)
25
+ return JS_EXCEPTION;
26
+ if (JS_SetProperty(ctx, obj, JS_ATOM_length, len) < 0)
27
+ return JS_EXCEPTION;
28
+ }
29
+ else {
30
+ for (let i = 0; i < argc; i++) {
31
+ if (JS_SetPropertyInt64(ctx, obj, i, argv[i]) < 0)
32
+ return JS_EXCEPTION;
33
+ }
34
+ }
35
+ return obj;
36
+ }
37
+ function js_get_this(ctx, this_val) {
38
+ return this_val;
39
+ }
40
+ const A = Array;
41
+ const AP = Array.prototype;
42
+ const js_array_funcs = [
43
+ JS_NATIVE_DEF('isArray', 1, A.isArray),
44
+ /* `this` is the guest constructor; ArrayCreate is used when it is not a
45
+ constructor, hence the fixer */
46
+ JS_NATIVE_DEF('from', 1, A.from, fix_any),
47
+ JS_NATIVE_DEF('of', 0, A.of, fix_any),
48
+ JS_CGETSET_DEF(JS_ATOM_Symbol_species, js_get_this, null),
49
+ ];
50
+ /* ---------------------------------------------------------------------
51
+ Array.prototype
52
+ --------------------------------------------------------------------- */
53
+ /* Methods returning an element, a primitive or undefined need no fixer.
54
+ Methods returning `this` (fill, sort, reverse, copyWithin) may return
55
+ the ToObject() wrapper of a primitive receiver, and methods creating
56
+ arrays may create host arrays: both go through fix_any. */
57
+ const js_array_proto_funcs = [
58
+ JS_NATIVE_DEF('at', 1, AP.at),
59
+ JS_NATIVE_DEF('with', 2, AP.with, fix_any),
60
+ JS_NATIVE_DEF('concat', 1, AP.concat, fix_any),
61
+ JS_NATIVE_DEF('every', 1, AP.every),
62
+ JS_NATIVE_DEF('some', 1, AP.some),
63
+ JS_NATIVE_DEF('forEach', 1, AP.forEach),
64
+ JS_NATIVE_DEF('map', 1, AP.map, fix_any),
65
+ JS_NATIVE_DEF('filter', 1, AP.filter, fix_any),
66
+ JS_NATIVE_DEF('reduce', 1, AP.reduce),
67
+ JS_NATIVE_DEF('reduceRight', 1, AP.reduceRight),
68
+ JS_NATIVE_DEF('fill', 1, AP.fill, fix_any),
69
+ JS_NATIVE_DEF('find', 1, AP.find),
70
+ JS_NATIVE_DEF('findIndex', 1, AP.findIndex),
71
+ JS_NATIVE_DEF('findLast', 1, AP.findLast),
72
+ JS_NATIVE_DEF('findLastIndex', 1, AP.findLastIndex),
73
+ JS_NATIVE_DEF('indexOf', 1, AP.indexOf),
74
+ JS_NATIVE_DEF('lastIndexOf', 1, AP.lastIndexOf),
75
+ JS_NATIVE_DEF('includes', 1, AP.includes),
76
+ JS_NATIVE_DEF('join', 1, AP.join),
77
+ JS_NATIVE_DEF('toString', 0, AP.toString),
78
+ JS_NATIVE_DEF('toLocaleString', 0, AP.toLocaleString),
79
+ JS_NATIVE_DEF('pop', 0, AP.pop),
80
+ JS_NATIVE_DEF('push', 1, AP.push),
81
+ JS_NATIVE_DEF('shift', 0, AP.shift),
82
+ JS_NATIVE_DEF('unshift', 1, AP.unshift),
83
+ JS_NATIVE_DEF('reverse', 0, AP.reverse, fix_any),
84
+ JS_NATIVE_DEF('toReversed', 0, AP.toReversed, fix_any),
85
+ JS_NATIVE_DEF('sort', 1, AP.sort, fix_any),
86
+ JS_NATIVE_DEF('toSorted', 1, AP.toSorted, fix_any),
87
+ JS_NATIVE_DEF('slice', 2, AP.slice, fix_any),
88
+ JS_NATIVE_DEF('splice', 2, AP.splice, fix_any),
89
+ JS_NATIVE_DEF('toSpliced', 2, AP.toSpliced, fix_any),
90
+ JS_NATIVE_DEF('copyWithin', 2, AP.copyWithin, fix_any),
91
+ JS_NATIVE_DEF('flatMap', 1, AP.flatMap, fix_any),
92
+ JS_NATIVE_DEF('flat', 0, AP.flat, fix_any),
93
+ JS_NATIVE_DEF('values', 0, AP.values, fix_array_iterator),
94
+ JS_ALIAS_DEF(JS_ATOM_Symbol_iterator, 'values'),
95
+ JS_NATIVE_DEF('keys', 0, AP.keys, fix_array_iterator),
96
+ JS_NATIVE_DEF('entries', 0, AP.entries, fix_array_iterator),
97
+ ];
98
+ /* Array.prototype[Symbol.unscopables] */
99
+ const unscopables = [
100
+ 'at', 'copyWithin', 'entries', 'fill', 'find', 'findIndex', 'findLast', 'findLastIndex', 'flat', 'flatMap',
101
+ 'includes', 'keys', 'toReversed', 'toSorted', 'toSpliced', 'values',
102
+ ];
103
+ export function JS_AddIntrinsicArray(ctx) {
104
+ const proto = ctx.class_proto[2 /* JSClassID.ARRAY */];
105
+ JS_SetPropertyFunctionList(ctx, proto, js_array_proto_funcs);
106
+ const obj = JS_NewGlobalCConstructor(ctx, 'Array', js_array_constructor, 1, proto);
107
+ ctx.array_ctor = obj;
108
+ JS_SetPropertyFunctionList(ctx, obj, js_array_funcs);
109
+ /* initialize Array.prototype[Symbol.unscopables] */
110
+ const obj1 = JS_NewObjectProto(ctx, null);
111
+ for (const name of unscopables) {
112
+ JS_DefinePropertyValueStr(ctx, obj1, name, true, JS_PROP_C_W_E);
113
+ }
114
+ JS_DefinePropertyValue(ctx, proto, JS_ATOM_Symbol_unscopables, obj1, JS_PROP_CONFIGURABLE);
115
+ }
116
+ //# sourceMappingURL=array.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array.js","sourceRoot":"","sources":["../../src/builtins/array.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EACoC,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,mBAAmB,EACvG,c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,WAAW,yBAAkB,CAAC;IAChD,0BAA0B,CAAC,GAAG,EAAE,KAAK,EAAE,oBAAoB,CAAC,CAAC;IAE7D,MAAM,GAAG,GAAG,wBAAwB,CAAC,GAAG,EAAE,OAAO,EAAE,oBAAoB,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;IACnF,GAAG,CAAC,UAAU,GAAG,GAAe,CAAC;IACjC,0BAA0B,CAAC,GAAG,EAAE,GAAG,EAAE,cAAc,CAAC,CAAC;IAErD,oDAAoD;IACpD,MAAM,IAAI,GAAG,iBAAiB,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAC1C,KAAK,MAAM,IAAI,IAAI,WAAW,EAAE,CAAC;QAC/B,yBAAyB,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC;IAClE,CAAC;IACD,sBAAsB,CAAC,GAAG,EAAE,KAAK,EAAE,0BAA0B,EAAE,IAAI,EAAE,oBAAoB,CAAC,CAAC;AAC7F,CAAC","sourcesContent":["/*\n * Array objects (port of the Array part of quickjs.c)\n *\n * Guest arrays are host arrays with the guest Array.prototype, so every\n * Array.prototype method and the static methods are borrowed host natives\n * (see builtins/native.ts); only the constructor and Symbol.species are\n * engine code. Arrays created by the natives (ArrayCreate, or\n * ArraySpeciesCreate falling back to %Array%) are re-prototyped by the\n * fixers; species created arrays come from the guest constructor and are\n * already guest arrays.\n */\nimport {\n JSContext, JSValue, JSObject, JSClassID, JS_EXCEPTION, JS_IsException, JS_IsNumber, js_create_from_ctor,\n JS_SetProperty, JS_SetPropertyInt64, JS_DefinePropertyValue, JS_DefinePropertyValueStr, JS_NewObjectProto,\n JS_ToArrayLengthFree, JS_SetPropertyFunctionList, JS_NATIVE_DEF, JS_CGETSET_DEF, JS_ALIAS_DEF,\n JS_NewGlobalCConstructor, JS_PROP_C_W_E, JS_PROP_CONFIGURABLE, JS_ATOM_length, JS_ATOM_Symbol_iterator,\n JS_ATOM_Symbol_species, JS_ATOM_Symbol_unscopables,\n} from '../quickjs.ts';\nimport { fix_any, fix_array_iterator } from './native.ts';\n\n/* ---------------------------------------------------------------------\n Array constructor and static methods\n --------------------------------------------------------------------- */\n\nexport function js_array_constructor(ctx: JSContext, new_target: JSValue, argv: JSValue[]): JSValue {\n const argc = argv.length;\n const obj = js_create_from_ctor(ctx, new_target, JSClassID.ARRAY);\n if (JS_IsException(obj)) return obj;\n if (argc === 1 && JS_IsNumber(argv[0])) {\n const len = JS_ToArrayLengthFree(ctx, argv[0], true);\n if (len < 0) return JS_EXCEPTION;\n if (JS_SetProperty(ctx, obj, JS_ATOM_length, len) < 0) return JS_EXCEPTION;\n } else {\n for (let i = 0; i < argc; i++) {\n if (JS_SetPropertyInt64(ctx, obj, i, argv[i]) < 0) return JS_EXCEPTION;\n }\n }\n return obj;\n}\n\nfunction js_get_this(ctx: JSContext, this_val: JSValue): JSValue {\n return this_val;\n}\n\nconst A = Array;\nconst AP = Array.prototype;\n\nconst js_array_funcs = [\n JS_NATIVE_DEF('isArray', 1, A.isArray),\n /* `this` is the guest constructor; ArrayCreate is used when it is not a\n constructor, hence the fixer */\n JS_NATIVE_DEF('from', 1, A.from, fix_any),\n JS_NATIVE_DEF('of', 0, A.of, fix_any),\n JS_CGETSET_DEF(JS_ATOM_Symbol_species, js_get_this, null),\n];\n\n/* ---------------------------------------------------------------------\n Array.prototype\n --------------------------------------------------------------------- */\n\n/* Methods returning an element, a primitive or undefined need no fixer.\n Methods returning `this` (fill, sort, reverse, copyWithin) may return\n the ToObject() wrapper of a primitive receiver, and methods creating\n arrays may create host arrays: both go through fix_any. */\nconst js_array_proto_funcs = [\n JS_NATIVE_DEF('at', 1, AP.at),\n JS_NATIVE_DEF('with', 2, AP.with, fix_any),\n JS_NATIVE_DEF('concat', 1, AP.concat, fix_any),\n JS_NATIVE_DEF('every', 1, AP.every),\n JS_NATIVE_DEF('some', 1, AP.some),\n JS_NATIVE_DEF('forEach', 1, AP.forEach),\n JS_NATIVE_DEF('map', 1, AP.map, fix_any),\n JS_NATIVE_DEF('filter', 1, AP.filter, fix_any),\n JS_NATIVE_DEF('reduce', 1, AP.reduce),\n JS_NATIVE_DEF('reduceRight', 1, AP.reduceRight),\n JS_NATIVE_DEF('fill', 1, AP.fill, fix_any),\n JS_NATIVE_DEF('find', 1, AP.find),\n JS_NATIVE_DEF('findIndex', 1, AP.findIndex),\n JS_NATIVE_DEF('findLast', 1, AP.findLast),\n JS_NATIVE_DEF('findLastIndex', 1, AP.findLastIndex),\n JS_NATIVE_DEF('indexOf', 1, AP.indexOf),\n JS_NATIVE_DEF('lastIndexOf', 1, AP.lastIndexOf),\n JS_NATIVE_DEF('includes', 1, AP.includes),\n JS_NATIVE_DEF('join', 1, AP.join),\n JS_NATIVE_DEF('toString', 0, AP.toString),\n JS_NATIVE_DEF('toLocaleString', 0, AP.toLocaleString),\n JS_NATIVE_DEF('pop', 0, AP.pop),\n JS_NATIVE_DEF('push', 1, AP.push),\n JS_NATIVE_DEF('shift', 0, AP.shift),\n JS_NATIVE_DEF('unshift', 1, AP.unshift),\n JS_NATIVE_DEF('reverse', 0, AP.reverse, fix_any),\n JS_NATIVE_DEF('toReversed', 0, AP.toReversed, fix_any),\n JS_NATIVE_DEF('sort', 1, AP.sort, fix_any),\n JS_NATIVE_DEF('toSorted', 1, AP.toSorted, fix_any),\n JS_NATIVE_DEF('slice', 2, AP.slice, fix_any),\n JS_NATIVE_DEF('splice', 2, AP.splice, fix_any),\n JS_NATIVE_DEF('toSpliced', 2, AP.toSpliced, fix_any),\n JS_NATIVE_DEF('copyWithin', 2, AP.copyWithin, fix_any),\n JS_NATIVE_DEF('flatMap', 1, AP.flatMap, fix_any),\n JS_NATIVE_DEF('flat', 0, AP.flat, fix_any),\n JS_NATIVE_DEF('values', 0, AP.values, fix_array_iterator),\n JS_ALIAS_DEF(JS_ATOM_Symbol_iterator, 'values'),\n JS_NATIVE_DEF('keys', 0, AP.keys, fix_array_iterator),\n JS_NATIVE_DEF('entries', 0, AP.entries, fix_array_iterator),\n];\n\n/* Array.prototype[Symbol.unscopables] */\nconst unscopables = [\n 'at', 'copyWithin', 'entries', 'fill', 'find', 'findIndex', 'findLast', 'findLastIndex', 'flat', 'flatMap',\n 'includes', 'keys', 'toReversed', 'toSorted', 'toSpliced', 'values',\n];\n\nexport function JS_AddIntrinsicArray(ctx: JSContext): void {\n const proto = ctx.class_proto[JSClassID.ARRAY]!;\n JS_SetPropertyFunctionList(ctx, proto, js_array_proto_funcs);\n\n const obj = JS_NewGlobalCConstructor(ctx, 'Array', js_array_constructor, 1, proto);\n ctx.array_ctor = obj as JSObject;\n JS_SetPropertyFunctionList(ctx, obj, js_array_funcs);\n\n /* initialize Array.prototype[Symbol.unscopables] */\n const obj1 = JS_NewObjectProto(ctx, null);\n for (const name of unscopables) {\n JS_DefinePropertyValueStr(ctx, obj1, name, true, JS_PROP_C_W_E);\n }\n JS_DefinePropertyValue(ctx, proto, JS_ATOM_Symbol_unscopables, obj1, JS_PROP_CONFIGURABLE);\n}\n"]}
@@ -0,0 +1,3 @@
1
+ import { JSContext } from '../quickjs.ts';
2
+ export declare function js_bigint_to_string1(ctx: JSContext, val: bigint, radix: number): string;
3
+ export declare function JS_AddIntrinsicBigInt(ctx: JSContext): void;
@@ -0,0 +1,122 @@
1
+ /*
2
+ * BigInt objects (port of the BigInt part of quickjs.c)
3
+ */
4
+ import * as Q from "../quickjs.js";
5
+ import { JS_EXCEPTION, JS_IsException, JS_IsUndefined, JS_NewObject, JS_NewGlobalCConstructor, JS_ToPrimitive, HINT_NUMBER, JS_ToBigInt, JS_ToIndex, js_string_to_bigint, JS_ThrowTypeError, JS_ThrowRangeError, JS_ThrowSyntaxError, JS_SetPropertyFunctionList, JS_CFUNC_DEF, JS_CFUNC_MAGIC_DEF, JS_PROP_STRING_DEF, JS_PROP_CONFIGURABLE, JS_ATOM_Symbol_toStringTag, } from "../quickjs.js";
6
+ import { js_get_radix } from "./number.js";
7
+ /* JS_StringToBigIntErr */
8
+ function JS_StringToBigIntErr(ctx, str) {
9
+ const r = js_string_to_bigint(str);
10
+ if (r === null)
11
+ return JS_ThrowSyntaxError(ctx, 'invalid bigint literal');
12
+ return r;
13
+ }
14
+ /* ToBigInt as used by the BigInt() function: numbers are accepted when
15
+ they are integers (JS_ToBigIntCtorFree) */
16
+ function JS_ToBigIntCtorFree(ctx, val) {
17
+ for (;;) {
18
+ switch (typeof val) {
19
+ case 'boolean':
20
+ return val ? 1n : 0n;
21
+ case 'bigint':
22
+ return val;
23
+ case 'number': {
24
+ const d = val;
25
+ if (!Number.isFinite(d))
26
+ return JS_ThrowRangeError(ctx, 'cannot convert NaN or Infinity to BigInt');
27
+ if (Math.trunc(d) !== d)
28
+ return JS_ThrowRangeError(ctx, 'cannot convert to BigInt: not an integer');
29
+ return BigInt(d);
30
+ }
31
+ case 'string':
32
+ return JS_StringToBigIntErr(ctx, val);
33
+ case 'symbol':
34
+ return JS_ThrowTypeError(ctx, 'cannot convert symbol to bigint');
35
+ case 'object':
36
+ case 'function':
37
+ if (Q.JS_IsObject(val)) {
38
+ val = JS_ToPrimitive(ctx, val, HINT_NUMBER);
39
+ if (JS_IsException(val))
40
+ return val;
41
+ continue;
42
+ }
43
+ return JS_ThrowTypeError(ctx, 'cannot convert to BigInt');
44
+ default:
45
+ return JS_ThrowTypeError(ctx, 'cannot convert to BigInt');
46
+ }
47
+ }
48
+ }
49
+ function js_bigint_constructor(ctx, new_target, argv) {
50
+ if (!JS_IsUndefined(new_target))
51
+ return JS_ThrowTypeError(ctx, 'not a constructor');
52
+ return JS_ToBigIntCtorFree(ctx, argv[0]);
53
+ }
54
+ function js_thisBigIntValue(ctx, this_val) {
55
+ if (typeof this_val === 'bigint')
56
+ return this_val;
57
+ if (Q.JS_IsObject(this_val) && Q.JS_GetClassID(this_val) === 33 /* JSClassID.BIG_INT */) {
58
+ if (typeof Q.JS_GetAnyOpaque(this_val) === 'bigint')
59
+ return Q.JS_GetAnyOpaque(this_val);
60
+ }
61
+ return JS_ThrowTypeError(ctx, 'not a BigInt');
62
+ }
63
+ /* js_bigint_to_string1 */
64
+ export function js_bigint_to_string1(ctx, val, radix) {
65
+ return val.toString(radix);
66
+ }
67
+ function js_bigint_toString(ctx, this_val, argv) {
68
+ const val = js_thisBigIntValue(ctx, this_val);
69
+ if (JS_IsException(val))
70
+ return val;
71
+ let base;
72
+ if (JS_IsUndefined(argv[0])) {
73
+ base = 10;
74
+ }
75
+ else {
76
+ base = js_get_radix(ctx, argv[0]);
77
+ if (base < 0)
78
+ return JS_EXCEPTION;
79
+ }
80
+ return js_bigint_to_string1(ctx, val, base);
81
+ }
82
+ /* not in quickjs.c (which has no BigInt.prototype.toLocaleString): same as toString() */
83
+ function js_bigint_toLocaleString(ctx, this_val, argv) {
84
+ const val = js_thisBigIntValue(ctx, this_val);
85
+ if (JS_IsException(val))
86
+ return val;
87
+ return js_bigint_to_string1(ctx, val, 10);
88
+ }
89
+ function js_bigint_valueOf(ctx, this_val, argv) {
90
+ return js_thisBigIntValue(ctx, this_val);
91
+ }
92
+ function js_bigint_asUintN(ctx, this_val, argv, asIntN) {
93
+ const bits = JS_ToIndex(ctx, argv[0]);
94
+ if (bits < 0)
95
+ return JS_EXCEPTION;
96
+ const a = JS_ToBigInt(ctx, argv[1]);
97
+ if (JS_IsException(a))
98
+ return JS_EXCEPTION;
99
+ if (bits === 0)
100
+ return 0n;
101
+ if (asIntN)
102
+ return BigInt.asIntN(bits, a);
103
+ return BigInt.asUintN(bits, a);
104
+ }
105
+ const js_bigint_funcs = [
106
+ JS_CFUNC_MAGIC_DEF('asUintN', 2, js_bigint_asUintN, 0),
107
+ JS_CFUNC_MAGIC_DEF('asIntN', 2, js_bigint_asUintN, 1),
108
+ ];
109
+ const js_bigint_proto_funcs = [
110
+ JS_CFUNC_DEF('toString', 0, js_bigint_toString),
111
+ JS_CFUNC_DEF('valueOf', 0, js_bigint_valueOf),
112
+ JS_CFUNC_DEF('toLocaleString', 0, js_bigint_toLocaleString),
113
+ JS_PROP_STRING_DEF(JS_ATOM_Symbol_toStringTag, 'BigInt', JS_PROP_CONFIGURABLE),
114
+ ];
115
+ export function JS_AddIntrinsicBigInt(ctx) {
116
+ const proto = JS_NewObject(ctx);
117
+ ctx.class_proto[33 /* JSClassID.BIG_INT */] = proto;
118
+ JS_SetPropertyFunctionList(ctx, proto, js_bigint_proto_funcs);
119
+ const obj1 = JS_NewGlobalCConstructor(ctx, 'BigInt', js_bigint_constructor, 1, proto);
120
+ JS_SetPropertyFunctionList(ctx, obj1, js_bigint_funcs);
121
+ }
122
+ //# sourceMappingURL=bigint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bigint.js","sourceRoot":"","sources":["../../src/builtins/bigint.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,CAAC,MAAM,eAAe,CAAC;AACnC,OAAO,EACoC,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,YAAY,EACnG,wBAAwB,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,mBAAmB,EACnG,iBAAiB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,0BAA0B,EAAE,YAAY,EACpG,kBAAkB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,0BAA0B,GACzF,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,0BAA0B;AAC1B,SAAS,oBAAoB,CAAC,GAAc,EAAE,GAAW;IACvD,MAAM,CAAC,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC;IACnC,IAAI,CAAC,KAAK,IAAI;QAAE,OAAO,mBAAmB,CAAC,GAAG,EAAE,wBAAwB,CAAC,CAAC;IAC1E,OAAO,CAAC,CAAC;AACX,CAAC;AAED;6CAC6C;AAC7C,SAAS,mBAAmB,CAAC,GAAc,EAAE,GAAY;IACvD,SAAS,CAAC;QACR,QAAQ,OAAO,GAAG,EAAE,CAAC;YACnB,KAAK,SAAS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,CAAC,SAAS,EAAE,CAAC,EAAE,iBAAiB,CAAC;IAC7C,YAAY,CAAC,gBAAgB,EAAE,CAAC,EAAE,wBAAwB,CAAC;IAC3D,kBAAkB,CAAC,0BAA0B,EAAE,QAAQ,EAAE,oBAAoB,CAAC;CAC/E,CAAC;AAEF,MAAM,UAAU,qBAAqB,CAAC,GAAc;IAClD,MAAM,KAAK,GAAG,YAAY,CAAC,GAAG,CAAa,CAAC;IAC5C,GAAG,CAAC,WAAW,4BAAmB,GAAG,KAAK,CAAC;IAC3C,0BAA0B,CAAC,GAAG,EAAE,KAAK,EAAE,qBAAqB,CAAC,CAAC;IAC9D,MAAM,IAAI,GAAG,wBAAwB,CAAC,GAAG,EAAE,QAAQ,EAAE,qBAAqB,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;IACtF,0BAA0B,CAAC,GAAG,EAAE,IAAI,EAAE,eAAe,CAAC,CAAC;AACzD,CAAC","sourcesContent":["/*\n * BigInt objects (port of the BigInt part of quickjs.c)\n */\nimport * as Q from '../quickjs.ts';\nimport {\n JSContext, JSValue, JSObject, JSClassID, JS_EXCEPTION, JS_IsException, JS_IsUndefined, JS_NewObject,\n JS_NewGlobalCConstructor, JS_ToPrimitive, HINT_NUMBER, JS_ToBigInt, JS_ToIndex, js_string_to_bigint,\n JS_ThrowTypeError, JS_ThrowRangeError, JS_ThrowSyntaxError, JS_SetPropertyFunctionList, JS_CFUNC_DEF,\n JS_CFUNC_MAGIC_DEF, JS_PROP_STRING_DEF, JS_PROP_CONFIGURABLE, JS_ATOM_Symbol_toStringTag,\n} from '../quickjs.ts';\nimport { js_get_radix } from './number.ts';\n\n/* JS_StringToBigIntErr */\nfunction JS_StringToBigIntErr(ctx: JSContext, str: string): JSValue {\n const r = js_string_to_bigint(str);\n if (r === null) return JS_ThrowSyntaxError(ctx, 'invalid bigint literal');\n return r;\n}\n\n/* ToBigInt as used by the BigInt() function: numbers are accepted when\n they are integers (JS_ToBigIntCtorFree) */\nfunction JS_ToBigIntCtorFree(ctx: JSContext, val: JSValue): JSValue {\n for (;;) {\n switch (typeof val) {\n case 'boolean':\n return val ? 1n : 0n;\n case 'bigint':\n return val;\n case 'number': {\n const d = val;\n if (!Number.isFinite(d)) return JS_ThrowRangeError(ctx, 'cannot convert NaN or Infinity to BigInt');\n if (Math.trunc(d) !== d) return JS_ThrowRangeError(ctx, 'cannot convert to BigInt: not an integer');\n return BigInt(d);\n }\n case 'string':\n return JS_StringToBigIntErr(ctx, val);\n case 'symbol':\n return JS_ThrowTypeError(ctx, 'cannot convert symbol to bigint');\n case 'object':\n case 'function':\n if (Q.JS_IsObject(val)) {\n val = JS_ToPrimitive(ctx, val, HINT_NUMBER);\n if (JS_IsException(val)) return val;\n continue;\n }\n return JS_ThrowTypeError(ctx, 'cannot convert to BigInt');\n default:\n return JS_ThrowTypeError(ctx, 'cannot convert to BigInt');\n }\n }\n}\n\nfunction js_bigint_constructor(ctx: JSContext, new_target: JSValue, argv: JSValue[]): JSValue {\n if (!JS_IsUndefined(new_target)) return JS_ThrowTypeError(ctx, 'not a constructor');\n return JS_ToBigIntCtorFree(ctx, argv[0]);\n}\n\nfunction js_thisBigIntValue(ctx: JSContext, this_val: JSValue): JSValue {\n if (typeof this_val === 'bigint') return this_val;\n if (Q.JS_IsObject(this_val) && Q.JS_GetClassID(this_val) === JSClassID.BIG_INT) {\n if (typeof Q.JS_GetAnyOpaque(this_val) === 'bigint') return Q.JS_GetAnyOpaque(this_val);\n }\n return JS_ThrowTypeError(ctx, 'not a BigInt');\n}\n\n/* js_bigint_to_string1 */\nexport function js_bigint_to_string1(ctx: JSContext, val: bigint, radix: number): string {\n return val.toString(radix);\n}\n\nfunction js_bigint_toString(ctx: JSContext, this_val: JSValue, argv: JSValue[]): JSValue {\n const val = js_thisBigIntValue(ctx, this_val);\n if (JS_IsException(val)) return val;\n let base: number;\n if (JS_IsUndefined(argv[0])) {\n base = 10;\n } else {\n base = js_get_radix(ctx, argv[0]);\n if (base < 0) return JS_EXCEPTION;\n }\n return js_bigint_to_string1(ctx, val as bigint, base);\n}\n\n/* not in quickjs.c (which has no BigInt.prototype.toLocaleString): same as toString() */\nfunction js_bigint_toLocaleString(ctx: JSContext, this_val: JSValue, argv: JSValue[]): JSValue {\n const val = js_thisBigIntValue(ctx, this_val);\n if (JS_IsException(val)) return val;\n return js_bigint_to_string1(ctx, val as bigint, 10);\n}\n\nfunction js_bigint_valueOf(ctx: JSContext, this_val: JSValue, argv: JSValue[]): JSValue {\n return js_thisBigIntValue(ctx, this_val);\n}\n\nfunction js_bigint_asUintN(ctx: JSContext, this_val: JSValue, argv: JSValue[], asIntN: number): JSValue {\n const bits = JS_ToIndex(ctx, argv[0]);\n if (bits < 0) return JS_EXCEPTION;\n const a = JS_ToBigInt(ctx, argv[1]);\n if (JS_IsException(a)) return JS_EXCEPTION;\n if (bits === 0) return 0n;\n if (asIntN) return BigInt.asIntN(bits, a as bigint);\n return BigInt.asUintN(bits, a as bigint);\n}\n\nconst js_bigint_funcs = [\n JS_CFUNC_MAGIC_DEF('asUintN', 2, js_bigint_asUintN, 0),\n JS_CFUNC_MAGIC_DEF('asIntN', 2, js_bigint_asUintN, 1),\n];\n\nconst js_bigint_proto_funcs = [\n JS_CFUNC_DEF('toString', 0, js_bigint_toString),\n JS_CFUNC_DEF('valueOf', 0, js_bigint_valueOf),\n JS_CFUNC_DEF('toLocaleString', 0, js_bigint_toLocaleString),\n JS_PROP_STRING_DEF(JS_ATOM_Symbol_toStringTag, 'BigInt', JS_PROP_CONFIGURABLE),\n];\n\nexport function JS_AddIntrinsicBigInt(ctx: JSContext): void {\n const proto = JS_NewObject(ctx) as JSObject;\n ctx.class_proto[JSClassID.BIG_INT] = proto;\n JS_SetPropertyFunctionList(ctx, proto, js_bigint_proto_funcs);\n const obj1 = JS_NewGlobalCConstructor(ctx, 'BigInt', js_bigint_constructor, 1, proto);\n JS_SetPropertyFunctionList(ctx, obj1, js_bigint_funcs);\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import { JSContext } from '../quickjs.ts';
2
+ export declare function JS_AddIntrinsicBoolean(ctx: JSContext): void;
@@ -0,0 +1,26 @@
1
+ /*
2
+ * Boolean objects (port of the Boolean part of quickjs.c). Boolean wrapper
3
+ * objects are host Boolean objects with the guest prototype, so the
4
+ * prototype methods are borrowed host natives.
5
+ */
6
+ import * as Q from "../quickjs.js";
7
+ import { JS_IsUndefined, JS_NewGlobalCConstructor, JS_ToBool, JS_SetPropertyFunctionList, JS_NATIVE_DEF, } from "../quickjs.js";
8
+ function js_boolean_constructor(ctx, new_target, argv) {
9
+ const val = JS_ToBool(ctx, argv[0]);
10
+ if (!JS_IsUndefined(new_target)) {
11
+ return Q.js_create_wrapper_from_ctor(ctx, new_target, 6 /* JSClassID.BOOLEAN */, val);
12
+ }
13
+ return val;
14
+ }
15
+ const js_boolean_proto_funcs = [
16
+ JS_NATIVE_DEF('toString', 0, Boolean.prototype.toString),
17
+ JS_NATIVE_DEF('valueOf', 0, Boolean.prototype.valueOf),
18
+ ];
19
+ export function JS_AddIntrinsicBoolean(ctx) {
20
+ /* Boolean.prototype is a Boolean object with value false */
21
+ const proto = Q.js_new_primitive_wrapper(ctx, ctx.class_proto[1 /* JSClassID.OBJECT */], 6 /* JSClassID.BOOLEAN */, false);
22
+ ctx.class_proto[6 /* JSClassID.BOOLEAN */] = proto;
23
+ JS_SetPropertyFunctionList(ctx, proto, js_boolean_proto_funcs);
24
+ JS_NewGlobalCConstructor(ctx, 'Boolean', js_boolean_constructor, 1, proto);
25
+ }
26
+ //# sourceMappingURL=boolean.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"boolean.js","sourceRoot":"","sources":["../../src/builtins/boolean.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,CAAC,MAAM,eAAe,CAAC;AACnC,OAAO,EACoC,cAAc,EAAE,wBAAwB,EAAE,SAAS,EAC5F,0BAA0B,EAAE,aAAa,GAC1C,MAAM,eAAe,CAAC;AAEvB,SAAS,sBAAsB,CAAC,GAAc,EAAE,UAAmB,EAAE,IAAe;IAClF,MAAM,GAAG,GAAG,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IACpC,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,EAAE,CAAC;QAChC,OAAO,CAAC,CAAC,2BAA2B,CAAC,GAAG,EAAE,UAAU,6BAAqB,GAAG,CAAC,CAAC;IAChF,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,sBAAsB,GAAG;IAC7B,aAAa,CAAC,UAAU,EAAE,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC;IACxD,aAAa,CAAC,SAAS,EAAE,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC;CACvD,CAAC;AAEF,MAAM,UAAU,sBAAsB,CAAC,GAAc;IACnD,4DAA4D;IAC5D,MAAM,KAAK,GAAG,CAAC,CAAC,wBAAwB,CAAC,GAAG,EAAE,GAAG,CAAC,WAAW,0BAAkB,6BAAqB,KAAK,CAAa,CAAC;IACvH,GAAG,CAAC,WAAW,2BAAmB,GAAG,KAAK,CAAC;IAC3C,0BAA0B,CAAC,GAAG,EAAE,KAAK,EAAE,sBAAsB,CAAC,CAAC;IAC/D,wBAAwB,CAAC,GAAG,EAAE,SAAS,EAAE,sBAAsB,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;AAC7E,CAAC","sourcesContent":["/*\n * Boolean objects (port of the Boolean part of quickjs.c). Boolean wrapper\n * objects are host Boolean objects with the guest prototype, so the\n * prototype methods are borrowed host natives.\n */\nimport * as Q from '../quickjs.ts';\nimport {\n JSContext, JSValue, JSObject, JSClassID, JS_IsUndefined, JS_NewGlobalCConstructor, JS_ToBool,\n JS_SetPropertyFunctionList, JS_NATIVE_DEF,\n} from '../quickjs.ts';\n\nfunction js_boolean_constructor(ctx: JSContext, new_target: JSValue, argv: JSValue[]): JSValue {\n const val = JS_ToBool(ctx, argv[0]);\n if (!JS_IsUndefined(new_target)) {\n return Q.js_create_wrapper_from_ctor(ctx, new_target, JSClassID.BOOLEAN, val);\n }\n return val;\n}\n\nconst js_boolean_proto_funcs = [\n JS_NATIVE_DEF('toString', 0, Boolean.prototype.toString),\n JS_NATIVE_DEF('valueOf', 0, Boolean.prototype.valueOf),\n];\n\nexport function JS_AddIntrinsicBoolean(ctx: JSContext): void {\n /* Boolean.prototype is a Boolean object with value false */\n const proto = Q.js_new_primitive_wrapper(ctx, ctx.class_proto[JSClassID.OBJECT], JSClassID.BOOLEAN, false) as JSObject;\n ctx.class_proto[JSClassID.BOOLEAN] = proto;\n JS_SetPropertyFunctionList(ctx, proto, js_boolean_proto_funcs);\n JS_NewGlobalCConstructor(ctx, 'Boolean', js_boolean_constructor, 1, proto);\n}\n"]}
@@ -0,0 +1,3 @@
1
+ import { JSContext, JSValue } from '../quickjs.ts';
2
+ export declare function JS_NewDate(ctx: JSContext, epoch_ms: number): JSValue;
3
+ export declare function JS_AddIntrinsicDate(ctx: JSContext): void;