@opencode/codemode 2.2.6 → 2.3.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/README.md +115 -29
- package/dist/{vm/async.d.ts → async.d.ts} +1 -1
- package/dist/codemode.d.ts +13 -22
- package/dist/codemode.js +18 -39
- package/dist/data.d.ts +4 -19
- package/dist/data.js +1 -82
- package/dist/extension.d.ts +20 -1
- package/dist/extension.js +14 -1
- package/dist/{vm/host.d.ts → host.d.ts} +5 -2
- package/dist/{vm/host.js → host.js} +9 -4
- package/dist/index.d.ts +1 -1
- package/dist/{vm/opcodes.d.ts → opcodes.d.ts} +1 -1
- package/dist/{vm/prelude → prelude}/helpers.js +1 -1
- package/dist/{vm/runtime → runtime}/driver.d.ts +18 -8
- package/dist/{vm/runtime → runtime}/driver.js +90 -20
- package/dist/{vm/runtime → runtime}/errors.js +2 -2
- package/dist/{vm/runtime → runtime}/execute.d.ts +18 -9
- package/dist/{vm/runtime → runtime}/execute.js +45 -15
- package/dist/{vm/runtime → runtime}/extensions.d.ts +2 -2
- package/dist/{vm/runtime → runtime}/extensions.js +121 -19
- package/dist/{vm/runtime → runtime}/globals.js +1 -1
- package/dist/{vm/runtime → runtime}/interpreter.d.ts +4 -1
- package/dist/{vm/runtime → runtime}/interpreter.js +2 -0
- package/dist/{vm/runtime → runtime}/model.d.ts +1 -1
- package/dist/{vm/runtime → runtime}/objects.d.ts +1 -1
- package/dist/{vm/runtime → runtime}/objects.js +1 -1
- package/dist/{vm/runtime → runtime}/operations.d.ts +1 -1
- package/dist/{vm/runtime → runtime}/operations.js +1 -1
- package/dist/scan.js +2 -2
- package/dist/{vm/scheduler.d.ts → scheduler.d.ts} +16 -4
- package/dist/{vm/scheduler.js → scheduler.js} +13 -2
- package/dist/{vm/snapshot → snapshot}/codec.d.ts +37 -6
- package/dist/{vm/snapshot → snapshot}/codec.js +112 -8
- package/dist/{vm/snapshot → snapshot}/snapshot.d.ts +13 -6
- package/dist/{vm/snapshot → snapshot}/snapshot.js +19 -4
- package/dist/{vm/snapshot.js → snapshot.js} +5 -2
- package/dist/stdlib/array.d.ts +14 -9
- package/dist/stdlib/array.js +89 -276
- package/dist/stdlib/bytes.d.ts +11 -7
- package/dist/stdlib/bytes.js +112 -79
- package/dist/stdlib/collections.d.ts +7 -7
- package/dist/stdlib/collections.js +30 -339
- package/dist/stdlib/console.d.ts +2 -2
- package/dist/stdlib/console.js +3 -3
- package/dist/stdlib/date.d.ts +2 -2
- package/dist/stdlib/date.js +21 -30
- package/dist/stdlib/headers.d.ts +2 -2
- package/dist/stdlib/headers.js +15 -33
- package/dist/stdlib/iterator.d.ts +2 -2
- package/dist/stdlib/iterator.js +10 -303
- package/dist/stdlib/json.d.ts +2 -2
- package/dist/stdlib/json.js +15 -31
- package/dist/stdlib/math.d.ts +2 -7
- package/dist/stdlib/math.js +6 -30
- package/dist/stdlib/number.d.ts +3 -3
- package/dist/stdlib/number.js +8 -8
- package/dist/stdlib/object.d.ts +4 -4
- package/dist/stdlib/object.js +12 -30
- package/dist/stdlib/regexp.d.ts +6 -5
- package/dist/stdlib/regexp.js +18 -13
- package/dist/stdlib/string.d.ts +2 -2
- package/dist/stdlib/string.js +53 -53
- package/dist/stdlib/url.d.ts +21 -9
- package/dist/stdlib/url.js +55 -55
- package/dist/stdlib/value.d.ts +3 -4
- package/dist/stdlib/value.js +5 -6
- package/dist/stdlib/web.d.ts +4 -4
- package/dist/stdlib/web.js +7 -7
- package/dist/tool-runtime.d.ts +34 -12
- package/dist/tool-runtime.js +350 -68
- package/dist/tool-schema.d.ts +5 -0
- package/dist/tool-schema.js +36 -16
- package/dist/tool.d.ts +60 -2
- package/dist/tool.js +17 -1
- package/dist/{vm/vm.d.ts → vm.d.ts} +4 -3
- package/dist/{vm/vm.js → vm.js} +1 -1
- package/package.json +5 -7
- package/dist/interpreter/callback.d.ts +0 -24
- package/dist/interpreter/callback.js +0 -86
- package/dist/interpreter/errors.js +0 -173
- package/dist/interpreter/execute.d.ts +0 -14
- package/dist/interpreter/execute.js +0 -207
- package/dist/interpreter/extensions.d.ts +0 -9
- package/dist/interpreter/extensions.js +0 -248
- package/dist/interpreter/generators.d.ts +0 -3
- package/dist/interpreter/generators.js +0 -168
- package/dist/interpreter/globals.js +0 -144
- package/dist/interpreter/interpreter.d.ts +0 -48
- package/dist/interpreter/interpreter.js +0 -2253
- package/dist/interpreter/intrinsics.d.ts +0 -15
- package/dist/interpreter/intrinsics.js +0 -105
- package/dist/interpreter/model.d.ts +0 -68
- package/dist/interpreter/model.js +0 -54
- package/dist/interpreter/native.d.ts +0 -17
- package/dist/interpreter/native.js +0 -35
- package/dist/interpreter/objects.d.ts +0 -301
- package/dist/interpreter/objects.js +0 -592
- package/dist/interpreter/promises.d.ts +0 -18
- package/dist/interpreter/promises.js +0 -292
- package/dist/interpreter/runner.d.ts +0 -188
- package/dist/interpreter/runner.js +0 -492
- package/dist/interpreter/scope.d.ts +0 -16
- package/dist/interpreter/scope.js +0 -79
- package/dist/suspend-error.d.ts +0 -23
- package/dist/suspend-error.js +0 -25
- package/dist/vm/data.d.ts +0 -7
- package/dist/vm/data.js +0 -13
- package/dist/vm/index.d.ts +0 -6
- package/dist/vm/index.js +0 -6
- package/dist/vm/runtime/errors.d.ts +0 -23
- package/dist/vm/runtime/globals.d.ts +0 -6
- package/dist/vm/runtime/limits.d.ts +0 -10
- package/dist/vm/runtime/limits.js +0 -19
- package/dist/vm/runtime/modules.d.ts +0 -4
- package/dist/vm/runtime/modules.js +0 -33
- package/dist/vm/runtime/references.d.ts +0 -8
- package/dist/vm/runtime/references.js +0 -51
- package/dist/vm/stdlib/array.d.ts +0 -16
- package/dist/vm/stdlib/array.js +0 -311
- package/dist/vm/stdlib/bytes.d.ts +0 -11
- package/dist/vm/stdlib/bytes.js +0 -222
- package/dist/vm/stdlib/collections.d.ts +0 -7
- package/dist/vm/stdlib/collections.js +0 -188
- package/dist/vm/stdlib/console.d.ts +0 -6
- package/dist/vm/stdlib/console.js +0 -93
- package/dist/vm/stdlib/date.d.ts +0 -2
- package/dist/vm/stdlib/date.js +0 -123
- package/dist/vm/stdlib/headers.d.ts +0 -2
- package/dist/vm/stdlib/headers.js +0 -92
- package/dist/vm/stdlib/iterator.d.ts +0 -2
- package/dist/vm/stdlib/iterator.js +0 -30
- package/dist/vm/stdlib/json.d.ts +0 -3
- package/dist/vm/stdlib/json.js +0 -42
- package/dist/vm/stdlib/math.d.ts +0 -3
- package/dist/vm/stdlib/math.js +0 -73
- package/dist/vm/stdlib/number.d.ts +0 -3
- package/dist/vm/stdlib/number.js +0 -72
- package/dist/vm/stdlib/object.d.ts +0 -6
- package/dist/vm/stdlib/object.js +0 -201
- package/dist/vm/stdlib/regexp.d.ts +0 -8
- package/dist/vm/stdlib/regexp.js +0 -119
- package/dist/vm/stdlib/string.d.ts +0 -2
- package/dist/vm/stdlib/string.js +0 -272
- package/dist/vm/stdlib/url.d.ts +0 -25
- package/dist/vm/stdlib/url.js +0 -255
- package/dist/vm/stdlib/value.d.ts +0 -6
- package/dist/vm/stdlib/value.js +0 -32
- package/dist/vm/stdlib/web.d.ts +0 -5
- package/dist/vm/stdlib/web.js +0 -97
- /package/dist/{vm/async.js → async.js} +0 -0
- /package/dist/{vm/code.d.ts → code.d.ts} +0 -0
- /package/dist/{vm/code.js → code.js} +0 -0
- /package/dist/{vm/compiler → compiler}/compile.d.ts +0 -0
- /package/dist/{vm/compiler → compiler}/compile.js +0 -0
- /package/dist/{vm/compiler → compiler}/scope.d.ts +0 -0
- /package/dist/{vm/compiler → compiler}/scope.js +0 -0
- /package/dist/{vm/generators.d.ts → generators.d.ts} +0 -0
- /package/dist/{vm/generators.js → generators.js} +0 -0
- /package/dist/{vm/internal-prelude.d.ts → internal-prelude.d.ts} +0 -0
- /package/dist/{vm/internal-prelude.js → internal-prelude.js} +0 -0
- /package/dist/{vm/opcodes.js → opcodes.js} +0 -0
- /package/dist/{vm/prelude → prelude}/bytecode.d.ts +0 -0
- /package/dist/{vm/prelude → prelude}/bytecode.js +0 -0
- /package/dist/{vm/prelude → prelude}/bytecode.json +0 -0
- /package/dist/{vm/prelude → prelude}/helpers.d.ts +0 -0
- /package/dist/{vm/prelude → prelude}/prelude.d.ts +0 -0
- /package/dist/{vm/prelude → prelude}/prelude.js +0 -0
- /package/dist/{vm/prelude → prelude}/source.d.ts +0 -0
- /package/dist/{vm/prelude → prelude}/source.js +0 -0
- /package/dist/{vm/runtime → runtime}/callback.d.ts +0 -0
- /package/dist/{vm/runtime → runtime}/callback.js +0 -0
- /package/dist/{interpreter → runtime}/errors.d.ts +0 -0
- /package/dist/{vm/runtime → runtime}/generators.d.ts +0 -0
- /package/dist/{vm/runtime → runtime}/generators.js +0 -0
- /package/dist/{interpreter → runtime}/globals.d.ts +0 -0
- /package/dist/{vm/runtime → runtime}/intrinsic-names.d.ts +0 -0
- /package/dist/{vm/runtime → runtime}/intrinsic-names.js +0 -0
- /package/dist/{vm/runtime → runtime}/intrinsics.d.ts +0 -0
- /package/dist/{vm/runtime → runtime}/intrinsics.js +0 -0
- /package/dist/{interpreter → runtime}/limits.d.ts +0 -0
- /package/dist/{interpreter → runtime}/limits.js +0 -0
- /package/dist/{vm/runtime → runtime}/model.js +0 -0
- /package/dist/{interpreter → runtime}/modules.d.ts +0 -0
- /package/dist/{interpreter → runtime}/modules.js +0 -0
- /package/dist/{vm/runtime → runtime}/native.d.ts +0 -0
- /package/dist/{vm/runtime → runtime}/native.js +0 -0
- /package/dist/{vm/runtime → runtime}/promises.d.ts +0 -0
- /package/dist/{vm/runtime → runtime}/promises.js +0 -0
- /package/dist/{interpreter → runtime}/references.d.ts +0 -0
- /package/dist/{interpreter → runtime}/references.js +0 -0
- /package/dist/{vm/runtime → runtime}/signals.d.ts +0 -0
- /package/dist/{vm/runtime → runtime}/signals.js +0 -0
- /package/dist/{vm/runtime → runtime}/source.d.ts +0 -0
- /package/dist/{vm/runtime → runtime}/source.js +0 -0
- /package/dist/{vm/runtime → runtime}/table.d.ts +0 -0
- /package/dist/{vm/runtime → runtime}/table.js +0 -0
- /package/dist/{vm/snapshot.d.ts → snapshot.d.ts} +0 -0
package/dist/stdlib/regexp.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { constructor, methods, prototypeFrom, receiver } from "../
|
|
2
|
-
import { syntaxError, typeError } from "../
|
|
3
|
-
import { define, defineAccessor, Arr, Obj, RegExpObj, record, coerceToNumber, coerceToString, } from "../
|
|
1
|
+
import { constructor, methods, prototypeFrom, receiver } from "../runtime/native.js";
|
|
2
|
+
import { syntaxError, typeError } from "../runtime/model.js";
|
|
3
|
+
import { define, defineAccessor, Arr, Obj, RegExpObj, record, coerceToNumber, coerceToString, } from "../runtime/objects.js";
|
|
4
4
|
const flagProperties = [
|
|
5
5
|
"hasIndices",
|
|
6
6
|
"global",
|
|
@@ -13,11 +13,15 @@ const flagProperties = [
|
|
|
13
13
|
];
|
|
14
14
|
const regexFailureReason = (error) => (error instanceof Error ? error.message : String(error)).replace(/^Invalid regular expression:\s*/i, "");
|
|
15
15
|
const escapeRegexHint = 'To match special characters like ( ) [ ] { } + * ? . literally, escape them with a backslash (e.g. "\\\\(") or test for them with String.includes instead.';
|
|
16
|
-
|
|
16
|
+
/** Runs host regex work on a RegExp argument, sharing its `lastIndex`, or on a pattern string compiled for the call. */
|
|
17
|
+
export const withHostRegex = (arg, method, extraFlags, work) => {
|
|
17
18
|
if (arg instanceof RegExpObj)
|
|
18
|
-
return arg.
|
|
19
|
+
return arg.use(work);
|
|
19
20
|
// Anything else is a pattern string, as `new RegExp(arg)` would read it: undefined is the empty pattern.
|
|
20
21
|
const source = arg === undefined ? "" : coerceToString(arg);
|
|
22
|
+
return work(compilePattern(source, method, extraFlags));
|
|
23
|
+
};
|
|
24
|
+
const compilePattern = (source, method, extraFlags) => {
|
|
21
25
|
try {
|
|
22
26
|
return new RegExp(source, extraFlags);
|
|
23
27
|
}
|
|
@@ -39,12 +43,12 @@ export const matchToValue = (builtins, match) => {
|
|
|
39
43
|
};
|
|
40
44
|
export const constructRegExp = (builtins, args, proto = builtins.RegExp) => {
|
|
41
45
|
const first = args[0];
|
|
42
|
-
const pattern = first instanceof RegExpObj ? first.
|
|
46
|
+
const pattern = first instanceof RegExpObj ? first.source : first === undefined ? "" : coerceToString(first);
|
|
43
47
|
const flagsArg = args[1];
|
|
44
48
|
if (flagsArg !== undefined && typeof flagsArg !== "string") {
|
|
45
49
|
throw syntaxError(`RegExp flags must be a string of flag characters (e.g. "g", "gi"), not ${flagsArg === null ? "null" : typeof flagsArg}.`);
|
|
46
50
|
}
|
|
47
|
-
const flags = flagsArg ?? (first instanceof RegExpObj ? first.
|
|
51
|
+
const flags = flagsArg ?? (first instanceof RegExpObj ? first.flags : "");
|
|
48
52
|
try {
|
|
49
53
|
return new RegExpObj(proto, pattern, flags);
|
|
50
54
|
}
|
|
@@ -77,11 +81,11 @@ export const regexpGlobal = (ctx) => {
|
|
|
77
81
|
],
|
|
78
82
|
]);
|
|
79
83
|
const self = (thisValue, name) => receiver(RegExpObj, thisValue, `RegExp.prototype.${name}`);
|
|
80
|
-
defineAccessor(proto, "source", (thisValue) => self(thisValue, "source").
|
|
81
|
-
defineAccessor(proto, "flags", (thisValue) => self(thisValue, "flags").
|
|
82
|
-
//
|
|
83
|
-
defineAccessor(proto, "lastIndex", (thisValue) => self(thisValue, "lastIndex").
|
|
84
|
-
self(thisValue, "lastIndex").
|
|
84
|
+
defineAccessor(proto, "source", (thisValue) => self(thisValue, "source").source);
|
|
85
|
+
defineAccessor(proto, "flags", (thisValue) => self(thisValue, "flags").flags);
|
|
86
|
+
// One lastIndex per RegExp, so exec/test and the String methods share one counter.
|
|
87
|
+
defineAccessor(proto, "lastIndex", (thisValue) => self(thisValue, "lastIndex").lastIndex, (thisValue, value) => {
|
|
88
|
+
self(thisValue, "lastIndex").lastIndex = coerceToNumber(value);
|
|
85
89
|
});
|
|
86
90
|
for (const name of flagProperties)
|
|
87
91
|
defineAccessor(proto, name, (thisValue) => self(thisValue, name).regex[name]);
|
|
@@ -90,7 +94,8 @@ export const regexpGlobal = (ctx) => {
|
|
|
90
94
|
1,
|
|
91
95
|
(thisValue, args) => {
|
|
92
96
|
const value = self(thisValue, name);
|
|
93
|
-
const
|
|
97
|
+
const input = coerceToString(args[0]);
|
|
98
|
+
const matched = value.use((regex) => regex.exec(input));
|
|
94
99
|
if (name === "test")
|
|
95
100
|
return matched !== null;
|
|
96
101
|
return matched === null ? null : matchToValue(builtins, matched);
|
package/dist/stdlib/string.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Interpreter } from "../
|
|
2
|
-
export declare const stringGlobal: <R>(ctx: Interpreter<R>) => import("../
|
|
1
|
+
import type { Interpreter } from "../runtime/interpreter.js";
|
|
2
|
+
export declare const stringGlobal: <R>(ctx: Interpreter<R>) => import("../runtime/objects.js").Native;
|
package/dist/stdlib/string.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
1
|
+
import { Invoke } from "../runtime/signals.js";
|
|
2
|
+
import { constructor, fn, methods } from "../runtime/native.js";
|
|
3
|
+
import { checkArrayLength, checkStringLength } from "../runtime/limits.js";
|
|
4
|
+
import { invalidData, IteratorSymbol, rangeError, typeError } from "../runtime/model.js";
|
|
5
|
+
import { define, get, hidden, Arr, positionIterator, Obj, RegExpObj, record, coerceToInteger, coerceToNumber, coerceToString, } from "../runtime/objects.js";
|
|
6
|
+
import { containsOpaqueReference, typeofValue } from "../runtime/references.js";
|
|
7
|
+
import { isSupportedCallback, requireCallback, withPrimitives } from "../runtime/callback.js";
|
|
8
|
+
import { matchToValue, withHostRegex } from "./regexp.js";
|
|
9
|
+
import { coerce } from "./value.js";
|
|
9
10
|
// console is intercepted by the interpreter before reaching here.
|
|
10
11
|
const requireDataArgument = (name, index, arg) => {
|
|
11
12
|
if (containsOpaqueReference(arg)) {
|
|
@@ -18,9 +19,10 @@ const replaceAllNeedsGlobal = (pattern) => {
|
|
|
18
19
|
throw typeError(`String.replaceAll requires a regular expression with the global (g) flag: write /${pattern.source}/${pattern.flags}g, or use String.replace to replace only the first match.`);
|
|
19
20
|
}
|
|
20
21
|
};
|
|
21
|
-
|
|
22
|
+
// The matches are found first, as the host replaces; then the callback runs for each in order.
|
|
23
|
+
const replaceWithCallback = (ctx, value, name, args) => {
|
|
22
24
|
const builtins = ctx.builtins;
|
|
23
|
-
const
|
|
25
|
+
const callback = requireCallback(args[1], `String.${name}`);
|
|
24
26
|
const matches = [];
|
|
25
27
|
// The host calls back with (match, ...captures, offset, string, groups?); only groups is not already a Value.
|
|
26
28
|
const collect = (...callbackArgs) => {
|
|
@@ -36,12 +38,14 @@ function* replaceWithCallback(ctx, value, name, args) {
|
|
|
36
38
|
};
|
|
37
39
|
const pattern = args[0];
|
|
38
40
|
if (pattern instanceof RegExpObj) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
pattern.use((regex) => {
|
|
42
|
+
if (name === "replaceAll")
|
|
43
|
+
replaceAllNeedsGlobal(regex);
|
|
44
|
+
if (name === "replace")
|
|
45
|
+
value.replace(regex, collect);
|
|
46
|
+
else
|
|
47
|
+
value.replaceAll(regex, collect);
|
|
48
|
+
});
|
|
45
49
|
}
|
|
46
50
|
else {
|
|
47
51
|
const search = coerceToString(requireDataArgument(name, 0, pattern));
|
|
@@ -50,22 +54,20 @@ function* replaceWithCallback(ctx, value, name, args) {
|
|
|
50
54
|
else
|
|
51
55
|
value.replaceAll(search, collect);
|
|
52
56
|
}
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return output.join("");
|
|
62
|
-
}
|
|
57
|
+
const pieces = matches.map((match, index) => new Arr(builtins.Array, [
|
|
58
|
+
value.slice(index === 0 ? 0 : matches[index - 1].offset + matches[index - 1].match.length, match.offset),
|
|
59
|
+
new Arr(builtins.Array, match.args),
|
|
60
|
+
]));
|
|
61
|
+
const last = matches.at(-1);
|
|
62
|
+
const rest = value.slice(last === undefined ? 0 : last.offset + last.match.length);
|
|
63
|
+
return new Invoke(ctx.prelude.fn("replaceWith"), undefined, [new Arr(builtins.Array, pieces), rest, callback], undefined);
|
|
64
|
+
};
|
|
63
65
|
export const stringGlobal = (ctx) => {
|
|
64
66
|
const builtins = ctx.builtins;
|
|
65
67
|
const string = constructor(builtins, builtins.String, {
|
|
66
68
|
name: "String",
|
|
67
69
|
length: 1,
|
|
68
|
-
call:
|
|
70
|
+
call: (_, args) => coerce(ctx, "String", args),
|
|
69
71
|
});
|
|
70
72
|
const codeUnits = (name, op) => [
|
|
71
73
|
name,
|
|
@@ -78,7 +80,7 @@ export const stringGlobal = (ctx) => {
|
|
|
78
80
|
[
|
|
79
81
|
"raw",
|
|
80
82
|
1,
|
|
81
|
-
|
|
83
|
+
(_, args) => {
|
|
82
84
|
const template = args[0];
|
|
83
85
|
const raw = template instanceof Obj ? get(template, "raw") : undefined;
|
|
84
86
|
if (!(raw instanceof Obj))
|
|
@@ -87,12 +89,11 @@ export const stringGlobal = (ctx) => {
|
|
|
87
89
|
checkArrayLength(count);
|
|
88
90
|
// Each literal is followed by its substitution, except the last literal, or when substitutions run out.
|
|
89
91
|
const parts = Array.from({ length: count }, (_, index) => index + 1 < count && index + 1 < args.length ? [get(raw, index), args[index + 1]] : [get(raw, index)]).flat();
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return output;
|
|
92
|
+
return withPrimitives("string", parts, (strings) => {
|
|
93
|
+
const output = strings.map(coerceToString).join("");
|
|
94
|
+
checkStringLength(output.length);
|
|
95
|
+
return output;
|
|
96
|
+
}, true);
|
|
96
97
|
},
|
|
97
98
|
],
|
|
98
99
|
]);
|
|
@@ -118,7 +119,7 @@ export const stringGlobal = (ctx) => {
|
|
|
118
119
|
if (thisValue === null || thisValue === undefined) {
|
|
119
120
|
throw typeError(`String.prototype.${name} called on null or undefined.`);
|
|
120
121
|
}
|
|
121
|
-
return withPrimitives(
|
|
122
|
+
return withPrimitives(["string", ...hints], [thisValue, ...args.slice(0, hints.length)], ([value, ...primitives]) => op(coerceToString(value), [...primitives, ...args.slice(hints.length)]));
|
|
122
123
|
},
|
|
123
124
|
];
|
|
124
125
|
// includes, startsWith, and endsWith reject a RegExp before converting their search string and position.
|
|
@@ -126,15 +127,15 @@ export const stringGlobal = (ctx) => {
|
|
|
126
127
|
if (args[0] instanceof RegExpObj) {
|
|
127
128
|
throw typeError(`String.${name} cannot take a regular expression; use regex.test(string) or String.search instead.`);
|
|
128
129
|
}
|
|
129
|
-
return withPrimitives(
|
|
130
|
+
return withPrimitives(["string", "number"], args.slice(0, 2), (primitives) => op(value, str(name, primitives, 0), optNum(name, primitives, 1)));
|
|
130
131
|
});
|
|
131
132
|
// match, matchAll, and search read a RegExp as is and convert anything else to its pattern text.
|
|
132
|
-
const withPattern = (args, op) => args[0] instanceof RegExpObj ? op(args[0]) : withPrimitives(
|
|
133
|
+
const withPattern = (args, op) => args[0] instanceof RegExpObj ? op(args[0]) : withPrimitives("string", [args[0]], ([text]) => op(text));
|
|
133
134
|
const replace = (name) => simple(name, 2, (value, args) => {
|
|
134
135
|
const pattern = args[0];
|
|
135
136
|
const replacer = args[1];
|
|
136
137
|
// A RegExp pattern is used as is; a plain one converts to its search string, then a non-callable replacement.
|
|
137
|
-
return withPrimitives(
|
|
138
|
+
return withPrimitives("string", [pattern instanceof RegExpObj ? undefined : pattern, isSupportedCallback(replacer) ? undefined : replacer], ([search, replacement]) => {
|
|
138
139
|
if (isSupportedCallback(replacer)) {
|
|
139
140
|
return replaceWithCallback(ctx, value, name, [pattern instanceof RegExpObj ? pattern : search, replacer]);
|
|
140
141
|
}
|
|
@@ -143,11 +144,12 @@ export const stringGlobal = (ctx) => {
|
|
|
143
144
|
}
|
|
144
145
|
const primitives = [search, replacement];
|
|
145
146
|
if (pattern instanceof RegExpObj) {
|
|
146
|
-
const regex = pattern.regex;
|
|
147
147
|
const text = str(name, primitives, 1);
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
148
|
+
return pattern.use((regex) => {
|
|
149
|
+
if (name === "replaceAll")
|
|
150
|
+
replaceAllNeedsGlobal(regex);
|
|
151
|
+
return name === "replace" ? value.replace(regex, text) : value.replaceAll(regex, text);
|
|
152
|
+
});
|
|
151
153
|
}
|
|
152
154
|
if (name === "replace")
|
|
153
155
|
return value.replace(str(name, primitives, 0), str(name, primitives, 1));
|
|
@@ -180,7 +182,7 @@ export const stringGlobal = (ctx) => {
|
|
|
180
182
|
simple("split", 2, (value, args) => {
|
|
181
183
|
const separator = args[0];
|
|
182
184
|
// A RegExp separator is used as is; the limit converts before a plain separator does, as in the spec.
|
|
183
|
-
return withPrimitives(
|
|
185
|
+
return withPrimitives(["number", "string"], [args[1], separator instanceof RegExpObj ? undefined : separator], ([limit, pattern]) => {
|
|
184
186
|
const wrap = (parts) => new Arr(builtins.Array, parts);
|
|
185
187
|
// Native: an undefined separator returns the whole string, not a split on "undefined",
|
|
186
188
|
// unless the limit truncates to zero.
|
|
@@ -189,7 +191,7 @@ export const stringGlobal = (ctx) => {
|
|
|
189
191
|
return wrap(requestedLimit !== undefined && requestedLimit >>> 0 === 0 ? [] : [value]);
|
|
190
192
|
}
|
|
191
193
|
const parts = separator instanceof RegExpObj
|
|
192
|
-
? value.split(
|
|
194
|
+
? separator.use((regex) => value.split(regex, requestedLimit))
|
|
193
195
|
: value.split(str("split", [pattern], 0), requestedLimit === undefined ? undefined : requestedLimit >>> 0);
|
|
194
196
|
checkArrayLength(parts.length);
|
|
195
197
|
return wrap(parts);
|
|
@@ -209,8 +211,7 @@ export const stringGlobal = (ctx) => {
|
|
|
209
211
|
simple("lastIndexOf", 1, (value, args) => value.lastIndexOf(str("lastIndexOf", args, 0), optNum("lastIndexOf", args, 1)), ["string", "number"]),
|
|
210
212
|
replace("replace"),
|
|
211
213
|
replace("replaceAll"),
|
|
212
|
-
simple("match", 1, (value, args) => withPattern(args, (arg) => {
|
|
213
|
-
const regex = toHostRegex(arg, "match");
|
|
214
|
+
simple("match", 1, (value, args) => withPattern(args, (arg) => withHostRegex(arg, "match", "", (regex) => {
|
|
214
215
|
const matched = value.match(regex);
|
|
215
216
|
if (matched === null)
|
|
216
217
|
return null;
|
|
@@ -218,9 +219,8 @@ export const stringGlobal = (ctx) => {
|
|
|
218
219
|
if (regex.global)
|
|
219
220
|
return new Arr(builtins.Array, [...matched]);
|
|
220
221
|
return matchToValue(builtins, matched);
|
|
221
|
-
})),
|
|
222
|
-
simple("matchAll", 1, (value, args) => withPattern(args, (arg) => {
|
|
223
|
-
const regex = toHostRegex(arg, "matchAll", "g");
|
|
222
|
+
}))),
|
|
223
|
+
simple("matchAll", 1, (value, args) => withPattern(args, (arg) => withHostRegex(arg, "matchAll", "g", (regex) => {
|
|
224
224
|
if (!regex.global) {
|
|
225
225
|
throw typeError(`String.matchAll requires a regular expression with the global (g) flag: write /${regex.source}/${regex.flags}g, or use String.match for a single match.`);
|
|
226
226
|
}
|
|
@@ -230,8 +230,8 @@ export const stringGlobal = (ctx) => {
|
|
|
230
230
|
matches.push(matchToValue(builtins, match));
|
|
231
231
|
}
|
|
232
232
|
return new Arr(builtins.Array, matches);
|
|
233
|
-
})),
|
|
234
|
-
simple("search", 1, (value, args) => withPattern(args, (arg) =>
|
|
233
|
+
}))),
|
|
234
|
+
simple("search", 1, (value, args) => withPattern(args, (arg) => withHostRegex(arg, "search", "", (regex) => value.search(regex)))),
|
|
235
235
|
simple("repeat", 1, (value, args) => {
|
|
236
236
|
const count = num("repeat", args, 0);
|
|
237
237
|
if (!Number.isFinite(count) || count < 0) {
|
|
@@ -261,12 +261,12 @@ export const stringGlobal = (ctx) => {
|
|
|
261
261
|
simple("toWellFormed", 0, (value) => value.toWellFormed()),
|
|
262
262
|
simple("charCodeAt", 1, (value, args) => value.charCodeAt(optNum("charCodeAt", args, 0) ?? 0), ["number"]),
|
|
263
263
|
simple("codePointAt", 1, (value, args) => value.codePointAt(optNum("codePointAt", args, 0) ?? 0), ["number"]),
|
|
264
|
-
simple("concat", 1, (value, args) => withPrimitives(
|
|
264
|
+
simple("concat", 1, (value, args) => withPrimitives("string", args, (parts) => {
|
|
265
265
|
const joined = value.concat(...parts.map((_, index) => str("concat", parts, index)));
|
|
266
266
|
checkStringLength(joined.length);
|
|
267
267
|
return joined;
|
|
268
268
|
})),
|
|
269
269
|
]);
|
|
270
|
-
define(builtins.String, IteratorSymbol, fn(builtins, "[Symbol.iterator]", 0, (thisValue) =>
|
|
270
|
+
define(builtins.String, IteratorSymbol, fn(builtins, "[Symbol.iterator]", 0, (thisValue) => positionIterator(builtins, self(thisValue, "[Symbol.iterator]"), "values")), hidden);
|
|
271
271
|
return string;
|
|
272
272
|
};
|
package/dist/stdlib/url.d.ts
CHANGED
|
@@ -1,13 +1,25 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { type Value } from "../
|
|
3
|
-
import type { Interpreter } from "../
|
|
1
|
+
import { Invoke } from "../runtime/signals.js";
|
|
2
|
+
import { Obj, type Callable, type Value } from "../runtime/objects.js";
|
|
3
|
+
import type { Interpreter } from "../runtime/interpreter.js";
|
|
4
4
|
type UriFunction = "encodeURI" | "encodeURIComponent" | "decodeURI" | "decodeURIComponent";
|
|
5
|
-
export declare const uriGlobal: <R>(ctx: Interpreter<R>, name: UriFunction) => import("../
|
|
6
|
-
export declare const urlGlobal: <R>(ctx: Interpreter<R>) => import("../
|
|
5
|
+
export declare const uriGlobal: <R>(ctx: Interpreter<R>, name: UriFunction) => import("../runtime/objects.js").Native;
|
|
6
|
+
export declare const urlGlobal: <R>(ctx: Interpreter<R>) => import("../runtime/objects.js").Native;
|
|
7
|
+
/** What `readPairs` builds from `[name, value]` pairs, or from a record of names to values when `init` is no iterable. */
|
|
8
|
+
export type PairsInto = {
|
|
9
|
+
readonly kind: "Headers" | "URLSearchParams";
|
|
10
|
+
readonly proto: Obj;
|
|
11
|
+
};
|
|
7
12
|
/**
|
|
8
|
-
* Reads a synchronous iterable of `[name, value]` pairs as strings
|
|
9
|
-
* WebIDL, the whole sequence is converted before any
|
|
13
|
+
* Reads a synchronous iterable of `[name, value]` pairs as strings (in the prelude), then builds `into` from them; a
|
|
14
|
+
* record of names to values when `init` is not iterable. As in WebIDL, the whole sequence is converted before any
|
|
15
|
+
* pair's length is checked.
|
|
10
16
|
*/
|
|
11
|
-
export declare
|
|
12
|
-
|
|
17
|
+
export declare const readPairs: <R>(ctx: Interpreter<R>, init: Value, label: string, into: PairsInto) => Invoke;
|
|
18
|
+
/** What `readPairs` makes of the pairs it read (an array of arrays of strings), or of a record. */
|
|
19
|
+
export declare const buildPairs: (into: PairsInto, value: Value, label: string) => Value;
|
|
20
|
+
/** The host validates header names and values and throws its own TypeError; the program gets one of its own. */
|
|
21
|
+
export declare const attempt: <T>(run: () => T) => T;
|
|
22
|
+
/** Headers and URLSearchParams `forEach`: the callback sees each `[name, value]` pair as listed when it started. */
|
|
23
|
+
export declare const pairsForEach: <R>(ctx: Interpreter<R>, target: Value, pairs: Array<[string, string]>, callback: Callable, thisArg: Value) => Invoke;
|
|
24
|
+
export declare const urlSearchParamsGlobal: <R>(ctx: Interpreter<R>) => import("../runtime/objects.js").Native;
|
|
13
25
|
export {};
|
package/dist/stdlib/url.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { Invoke } from "../runtime/signals.js";
|
|
2
|
+
import { constructor, fn, methods, prototypeFrom, receiver, requiresNew, iteratorMethods, } from "../runtime/native.js";
|
|
3
|
+
import { IteratorSymbol, PendingThrow, typeError, uriError } from "../runtime/model.js";
|
|
4
|
+
import { define, defineAccessor, entries, get, hidden, Arr, Obj, URLObj, URLSearchParamsObj, HeadersObj, coerceToString, isRuntimeReference, } from "../runtime/objects.js";
|
|
5
|
+
import { requireCallback } from "../runtime/callback.js";
|
|
5
6
|
const urlProperties = [
|
|
6
7
|
"href",
|
|
7
8
|
"origin",
|
|
@@ -94,42 +95,54 @@ export const urlGlobal = (ctx) => {
|
|
|
94
95
|
]);
|
|
95
96
|
return url;
|
|
96
97
|
};
|
|
97
|
-
function* readPair(ctx, value, label) {
|
|
98
|
-
const cursor = yield* ctx.iterate(value);
|
|
99
|
-
if (cursor === undefined)
|
|
100
|
-
throw typeError(`${label} expects iterable [name, value] pairs.`);
|
|
101
|
-
const items = [];
|
|
102
|
-
while (true) {
|
|
103
|
-
const step = yield* cursor.next();
|
|
104
|
-
if (step.done)
|
|
105
|
-
return items;
|
|
106
|
-
items.push(yield* preserveConsumerError(cursor.close, pairString(step.value)));
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
// A step, so a failing conversion closes the pair's iterator.
|
|
110
|
-
function* pairString(value) {
|
|
111
|
-
return coerceToString(value);
|
|
112
|
-
}
|
|
113
98
|
/**
|
|
114
|
-
* Reads a synchronous iterable of `[name, value]` pairs as strings
|
|
115
|
-
* WebIDL, the whole sequence is converted before any
|
|
99
|
+
* Reads a synchronous iterable of `[name, value]` pairs as strings (in the prelude), then builds `into` from them; a
|
|
100
|
+
* record of names to values when `init` is not iterable. As in WebIDL, the whole sequence is converted before any
|
|
101
|
+
* pair's length is checked.
|
|
116
102
|
*/
|
|
117
|
-
export
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
103
|
+
export const readPairs = (ctx, init, label, into) => new Invoke(ctx.prelude.fn("readPairs"), undefined, [init, label, into.kind, into.proto], undefined);
|
|
104
|
+
/** What `readPairs` makes of the pairs it read (an array of arrays of strings), or of a record. */
|
|
105
|
+
export const buildPairs = (into, value, label) => {
|
|
106
|
+
if (!(value instanceof Arr))
|
|
107
|
+
return fromRecord(into, value);
|
|
108
|
+
const pairs = value.items.map((pair) => pair.items);
|
|
109
|
+
if (pairs.some((entry) => entry.length !== 2))
|
|
110
|
+
throw typeError(`${label} expects iterable [name, value] pairs.`);
|
|
111
|
+
if (into.kind === "URLSearchParams") {
|
|
112
|
+
return new URLSearchParamsObj(into.proto, new URLSearchParams(pairs));
|
|
113
|
+
}
|
|
114
|
+
return new HeadersObj(into.proto, attempt(() => new Headers(pairs)));
|
|
115
|
+
};
|
|
116
|
+
const fromRecord = (into, init) => {
|
|
117
|
+
if (into.kind === "Headers") {
|
|
118
|
+
if (!(init instanceof Obj) || isRuntimeReference(init)) {
|
|
119
|
+
throw typeError("new Headers(...) expects a record of names to values, iterable [name, value] pairs, or Headers.");
|
|
128
120
|
}
|
|
129
|
-
|
|
121
|
+
return new HeadersObj(into.proto, attempt(() => new Headers(Object.fromEntries(entries(init).map(([key, value]) => [key, coerceToString(value)])))));
|
|
122
|
+
}
|
|
123
|
+
if (isRuntimeReference(init)) {
|
|
124
|
+
throw typeError("new URLSearchParams(...) expects a query string, data object, or synchronous iterable pairs.");
|
|
125
|
+
}
|
|
126
|
+
if (!(init instanceof Obj)) {
|
|
127
|
+
throw typeError("new URLSearchParams(...) expects a query string, data object, iterable pairs, or URLSearchParams.");
|
|
128
|
+
}
|
|
129
|
+
return new URLSearchParamsObj(into.proto, new URLSearchParams(Object.fromEntries(entries(init).map(([key, value]) => [key, coerceToString(value)]))));
|
|
130
|
+
};
|
|
131
|
+
/** The host validates header names and values and throws its own TypeError; the program gets one of its own. */
|
|
132
|
+
export const attempt = (run) => {
|
|
133
|
+
try {
|
|
134
|
+
return run();
|
|
130
135
|
}
|
|
131
|
-
|
|
132
|
-
|
|
136
|
+
catch (error) {
|
|
137
|
+
throw typeError(error instanceof Error ? error.message : String(error));
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
/** Headers and URLSearchParams `forEach`: the callback sees each `[name, value]` pair as listed when it started. */
|
|
141
|
+
export const pairsForEach = (ctx, target, pairs, callback, thisArg) => {
|
|
142
|
+
const list = new Arr(ctx.builtins.Array, pairs.map((pair) => new Arr(ctx.builtins.Array, pair)));
|
|
143
|
+
return new Invoke(ctx.prelude.fn("pairsForEach"), undefined, [target, list, callback, thisArg], undefined);
|
|
144
|
+
};
|
|
145
|
+
const constructURLSearchParams = (ctx, init, proto) => {
|
|
133
146
|
const wrap = (params) => new URLSearchParamsObj(proto, params);
|
|
134
147
|
if (init === undefined)
|
|
135
148
|
return wrap(new URLSearchParams());
|
|
@@ -140,17 +153,8 @@ function* constructURLSearchParams(ctx, init, proto) {
|
|
|
140
153
|
if (init === null || typeof init === "number" || typeof init === "boolean") {
|
|
141
154
|
return wrap(new URLSearchParams(coerceToString(init)));
|
|
142
155
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
return wrap(new URLSearchParams(pairs));
|
|
146
|
-
if (isRuntimeReference(init)) {
|
|
147
|
-
throw typeError("new URLSearchParams(...) expects a query string, data object, or synchronous iterable pairs.");
|
|
148
|
-
}
|
|
149
|
-
if (!(init instanceof Obj)) {
|
|
150
|
-
throw typeError("new URLSearchParams(...) expects a query string, data object, iterable pairs, or URLSearchParams.");
|
|
151
|
-
}
|
|
152
|
-
return wrap(new URLSearchParams(Object.fromEntries(entries(init).map(([key, value]) => [key, coerceToString(value)]))));
|
|
153
|
-
}
|
|
156
|
+
return readPairs(ctx, init, "new URLSearchParams(...)", { kind: "URLSearchParams", proto });
|
|
157
|
+
};
|
|
154
158
|
export const urlSearchParamsGlobal = (ctx) => {
|
|
155
159
|
const builtins = ctx.builtins;
|
|
156
160
|
const proto = builtins.URLSearchParams;
|
|
@@ -233,20 +237,16 @@ export const urlSearchParamsGlobal = (ctx) => {
|
|
|
233
237
|
return undefined;
|
|
234
238
|
},
|
|
235
239
|
],
|
|
236
|
-
|
|
237
|
-
["values", 0, (thisValue) => hostIterator(builtins, self(thisValue, "values").params.values())],
|
|
238
|
-
["entries", 0, (thisValue) => hostIterator(builtins, self(thisValue, "entries").iterator(builtins))],
|
|
240
|
+
...iteratorMethods(builtins, self),
|
|
239
241
|
["toString", 0, (thisValue) => self(thisValue, "toString").params.toString()],
|
|
240
242
|
[
|
|
241
243
|
"forEach",
|
|
242
244
|
1,
|
|
243
|
-
|
|
245
|
+
(thisValue, args) => {
|
|
244
246
|
requireArgs("forEach", args, 1);
|
|
245
247
|
const target = self(thisValue, "forEach");
|
|
246
|
-
const
|
|
247
|
-
|
|
248
|
-
yield* apply([value, key, target], args[1]);
|
|
249
|
-
return undefined;
|
|
248
|
+
const callback = requireCallback(args[0], "URLSearchParams.forEach");
|
|
249
|
+
return pairsForEach(ctx, target, Array.from(target.params.entries()), callback, args[1]);
|
|
250
250
|
},
|
|
251
251
|
],
|
|
252
252
|
]);
|
package/dist/stdlib/value.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { type Native, type Value } from "../
|
|
2
|
-
import type { Interpreter } from "../
|
|
3
|
-
export declare const compoundOperators: Set<string>;
|
|
1
|
+
import { type Native, type Value } from "../runtime/objects.js";
|
|
2
|
+
import type { Interpreter } from "../runtime/interpreter.js";
|
|
4
3
|
export type Coercion = "Number" | "String" | "Boolean" | "parseInt" | "parseFloat" | "isFinite" | "isNaN";
|
|
5
|
-
export declare const coerce: <R>(ctx: Interpreter<R>, name: Coercion, args: Array<Value>) => import("../
|
|
4
|
+
export declare const coerce: <R>(ctx: Interpreter<R>, name: Coercion, args: Array<Value>) => import("../runtime/objects.js").NativeResult;
|
|
6
5
|
/** A global coercion function such as `Number` or `parseInt`. */
|
|
7
6
|
export declare const coercion: <R>(ctx: Interpreter<R>, name: Coercion, length?: number) => Native;
|
package/dist/stdlib/value.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { fn } from "../
|
|
2
|
-
import { coerceToNumber, coerceToString } from "../
|
|
3
|
-
import { withPrimitives } from "../
|
|
4
|
-
export const compoundOperators = new Set(["+=", "-=", "*=", "/=", "%=", "**=", "&=", "|=", "^=", "<<=", ">>=", ">>>="]);
|
|
1
|
+
import { fn } from "../runtime/native.js";
|
|
2
|
+
import { coerceToNumber, coerceToString } from "../runtime/objects.js";
|
|
3
|
+
import { withPrimitives } from "../runtime/callback.js";
|
|
5
4
|
export const coerce = (ctx, name, args) => {
|
|
6
5
|
// Native: Number() is 0 and String() is "", unlike their undefined-argument forms; the
|
|
7
6
|
// other coercers match native through the undefined-argument path below.
|
|
@@ -15,9 +14,9 @@ export const coerce = (ctx, name, args) => {
|
|
|
15
14
|
if (name === "Boolean")
|
|
16
15
|
return Boolean(raw);
|
|
17
16
|
if (name === "parseInt") {
|
|
18
|
-
return withPrimitives(
|
|
17
|
+
return withPrimitives(["string", "number"], [raw, args[1]], ([text, radix]) => parseInt(coerceToString(text), coerceToNumber(radix)));
|
|
19
18
|
}
|
|
20
|
-
return withPrimitives(
|
|
19
|
+
return withPrimitives(name === "String" || name === "parseFloat" ? "string" : "number", [raw], ([value]) => {
|
|
21
20
|
if (name === "Number")
|
|
22
21
|
return coerceToNumber(value);
|
|
23
22
|
if (name === "isFinite")
|
package/dist/stdlib/web.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Obj } from "../
|
|
2
|
-
import type { Interpreter } from "../
|
|
3
|
-
export declare const base64Global: <R>(ctx: Interpreter<R>, name: "atob" | "btoa") => import("../
|
|
4
|
-
export declare const structuredCloneGlobal: <R>(ctx: Interpreter<R>) => import("../
|
|
1
|
+
import { Obj } from "../runtime/objects.js";
|
|
2
|
+
import type { Interpreter } from "../runtime/interpreter.js";
|
|
3
|
+
export declare const base64Global: <R>(ctx: Interpreter<R>, name: "atob" | "btoa") => import("../runtime/objects.js").Native;
|
|
4
|
+
export declare const structuredCloneGlobal: <R>(ctx: Interpreter<R>) => import("../runtime/objects.js").Native;
|
|
5
5
|
export declare const cryptoGlobal: <R>(ctx: Interpreter<R>) => Obj;
|
package/dist/stdlib/web.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { fn, methods } from "../
|
|
2
|
-
import { typeError } from "../
|
|
3
|
-
import { define, entries, get, getOwn, hasOwn, hidden, isRuntimeReference, Arr, Bytes, DateObj, ErrorObj, MapObj, Obj, RegExpObj, SetObj, WeakMapObj, WeakSetObj, coerceToString, } from "../
|
|
4
|
-
import { createErrorValue, isErrorType } from "../
|
|
5
|
-
import { describeValue } from "../
|
|
1
|
+
import { fn, methods } from "../runtime/native.js";
|
|
2
|
+
import { typeError } from "../runtime/model.js";
|
|
3
|
+
import { define, entries, get, getOwn, hasOwn, hidden, isRuntimeReference, Arr, Bytes, DateObj, ErrorObj, MapObj, Obj, RegExpObj, SetObj, WeakMapObj, WeakSetObj, coerceToString, } from "../runtime/objects.js";
|
|
4
|
+
import { createErrorValue, isErrorType } from "../runtime/intrinsics.js";
|
|
5
|
+
import { describeValue } from "../runtime/references.js";
|
|
6
6
|
import { ToolReference } from "../tool-runtime.js";
|
|
7
7
|
// WebIDL DOMString conversion: a missing argument is a TypeError, anything else stringifies. Invalid input is a
|
|
8
8
|
// TypeError as well; browsers throw a DOMException named InvalidCharacterError, which CodeMode does not have.
|
|
@@ -45,14 +45,14 @@ export const structuredCloneGlobal = (ctx) => fn(ctx.builtins, "structuredClone"
|
|
|
45
45
|
}
|
|
46
46
|
if (value instanceof SetObj) {
|
|
47
47
|
const copy = remember(new SetObj(builtins.Set));
|
|
48
|
-
for (const item of value.set)
|
|
48
|
+
for (const item of value.set.liveKeys())
|
|
49
49
|
copy.set.add(clone(item));
|
|
50
50
|
return copy;
|
|
51
51
|
}
|
|
52
52
|
if (value instanceof DateObj)
|
|
53
53
|
return remember(new DateObj(builtins.Date, value.time));
|
|
54
54
|
if (value instanceof RegExpObj) {
|
|
55
|
-
return remember(new RegExpObj(builtins.RegExp, value.
|
|
55
|
+
return remember(new RegExpObj(builtins.RegExp, value.source, value.flags));
|
|
56
56
|
}
|
|
57
57
|
if (value instanceof Bytes)
|
|
58
58
|
return remember(new Bytes(builtins.Uint8Array, new Uint8Array(value.bytes)));
|