poe-code 14.0.55 → 14.0.57
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/dist/index.js +150 -53
- package/dist/index.js.map +3 -3
- package/dist/metafile.json +1 -1
- package/package.json +1 -1
- package/packages/safe-js/dist/chunks/{chunk-G5LQ37D4.js → chunk-H4O5OPM2.js} +2 -2
- package/packages/safe-js/dist/chunks/{chunk-6LFWVA64.js → chunk-N3CN2ACZ.js} +145 -53
- package/packages/safe-js/dist/chunks/chunk-N3CN2ACZ.js.map +7 -0
- package/packages/safe-js/dist/cli.js +2 -2
- package/packages/safe-js/dist/core.js +1 -1
- package/packages/safe-js/dist/index.js +2 -2
- package/packages/safe-js/dist/interp/globals/misc.js +20 -7
- package/packages/safe-js/dist/interp/methods/regex.d.ts +4 -4
- package/packages/safe-js/dist/interp/methods/regex.js +47 -8
- package/packages/safe-js/dist/interp/methods/string.js +59 -26
- package/packages/safe-js/dist/interp/regex/engine.d.ts +1 -0
- package/packages/safe-js/dist/interp/regex/engine.js +3 -3
- package/packages/safe-js/dist/interp/values.d.ts +6 -3
- package/packages/safe-js/dist/interp/values.js +19 -6
- package/packages/safe-js/dist/snapshot/replay-data.d.ts +1 -1
- package/packages/safe-js/dist/snapshot/replay-data.js +4 -4
- package/packages/safe-js/dist/snapshot/restore.js +8 -0
- package/packages/safe-js/dist/snapshot/serialize.d.ts +6 -1
- package/packages/safe-js/dist/snapshot/serialize.js +14 -1
- package/packages/safe-js/dist/snapshot/validation.js +8 -2
- package/packages/safe-js/dist/chunks/chunk-6LFWVA64.js.map +0 -7
- /package/packages/safe-js/dist/chunks/{chunk-G5LQ37D4.js.map → chunk-H4O5OPM2.js.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -127268,7 +127268,7 @@ function encodeReplayData(value, options = {}) {
|
|
|
127268
127268
|
kind: "regex",
|
|
127269
127269
|
source: entry.source,
|
|
127270
127270
|
flags: entry.flags,
|
|
127271
|
-
lastIndex: entry.lastIndex
|
|
127271
|
+
lastIndex: child(entry.lastIndex, "lastIndex")
|
|
127272
127272
|
};
|
|
127273
127273
|
} else if (isSandboxArguments(entry)) {
|
|
127274
127274
|
nodes[id] = { kind: "arguments", data: serializeArguments(entry, child) };
|
|
@@ -127435,11 +127435,12 @@ function decodeReplayData(input, options = {}, parent) {
|
|
|
127435
127435
|
return result3;
|
|
127436
127436
|
}
|
|
127437
127437
|
if (kind === "regex") {
|
|
127438
|
-
if (typeof node.source !== "string" || typeof node.flags !== "string" ||
|
|
127438
|
+
if (typeof node.source !== "string" || typeof node.flags !== "string" || !Object.hasOwn(node, "lastIndex")) {
|
|
127439
127439
|
throw new TypeError("Invalid replay regular expression.");
|
|
127440
127440
|
}
|
|
127441
|
-
const result3 = createSandboxRegex(node.source, node.flags,
|
|
127441
|
+
const result3 = createSandboxRegex(node.source, node.flags, 0, compilation);
|
|
127442
127442
|
restored.set(id, result3);
|
|
127443
|
+
result3.lastIndex = child(own(node, "lastIndex"));
|
|
127443
127444
|
return result3;
|
|
127444
127445
|
}
|
|
127445
127446
|
if (kind === "arguments") {
|
|
@@ -128445,10 +128446,10 @@ function charge(context) {
|
|
|
128445
128446
|
allocateRegexSteps(context.steps);
|
|
128446
128447
|
}
|
|
128447
128448
|
function normalizeLastIndex(lastIndex) {
|
|
128448
|
-
if (
|
|
128449
|
+
if (Number.isNaN(lastIndex) || lastIndex <= 0) {
|
|
128449
128450
|
return 0;
|
|
128450
128451
|
}
|
|
128451
|
-
return Math.floor(lastIndex);
|
|
128452
|
+
return Math.min(Math.floor(lastIndex), Number.MAX_SAFE_INTEGER);
|
|
128452
128453
|
}
|
|
128453
128454
|
function charactersEqual(left, right, ignoreCase) {
|
|
128454
128455
|
return left !== void 0 && foldCharacter(left, ignoreCase) === foldCharacter(right, ignoreCase);
|
|
@@ -128496,13 +128497,14 @@ function getRegexMember(target, property, budget) {
|
|
|
128496
128497
|
return budget === void 0 ? flags : budget.allocateString(flags);
|
|
128497
128498
|
}
|
|
128498
128499
|
if (property === "lastIndex") return target.lastIndex;
|
|
128500
|
+
if (Object.hasOwn(regexFlagProperties, property)) return target.flags.includes(regexFlagProperties[property]);
|
|
128499
128501
|
if (!isRegexMethodName(property)) {
|
|
128500
128502
|
return void 0;
|
|
128501
128503
|
}
|
|
128502
128504
|
return createSandboxClosure({
|
|
128503
128505
|
sandbox: true,
|
|
128504
128506
|
name: `RegExp#${property}`,
|
|
128505
|
-
call: (args) => callRegexMethod(
|
|
128507
|
+
call: (args, context) => callRegexMethod(context?.thisValue, property, args, budget, context)
|
|
128506
128508
|
});
|
|
128507
128509
|
}
|
|
128508
128510
|
function escapeRegexSource(source, budget) {
|
|
@@ -128530,15 +128532,41 @@ function setRegexMember(target, property, value) {
|
|
|
128530
128532
|
if (property !== "lastIndex") {
|
|
128531
128533
|
throw new TypeError(`RegExp#${String(property)} is not writable.`);
|
|
128532
128534
|
}
|
|
128533
|
-
target.lastIndex =
|
|
128535
|
+
target.lastIndex = value;
|
|
128534
128536
|
}
|
|
128535
|
-
function callRegexMethod(target, methodName, args) {
|
|
128536
|
-
|
|
128537
|
-
|
|
128537
|
+
async function callRegexMethod(target, methodName, args, budget, context) {
|
|
128538
|
+
if (target === null || typeof target !== "object" || methodName === "exec" && !isSandboxRegex(target)) {
|
|
128539
|
+
throw new TypeError(`RegExp#${methodName} requires ${methodName === "exec" ? "a regex" : "an object"} receiver.`);
|
|
128540
|
+
}
|
|
128541
|
+
const retained = {};
|
|
128542
|
+
let cursor2;
|
|
128543
|
+
let convertedInput;
|
|
128544
|
+
budget.setRetainedValues(retained, () => [target, ...args, cursor2, convertedInput]);
|
|
128545
|
+
try {
|
|
128546
|
+
const input = await sandboxString(args[0], budget, context);
|
|
128547
|
+
if (methodName === "test") {
|
|
128548
|
+
const exec2 = context?.getProperty === void 0 ? getSandboxDataProperty(target, "exec", budget) : context.getProperty(target, "exec");
|
|
128549
|
+
if (isSandboxClosure(exec2)) {
|
|
128550
|
+
const result = await invokeBuiltinClosure(exec2, [input], budget, context, target);
|
|
128551
|
+
if (result !== null && typeof result !== "object") {
|
|
128552
|
+
throw new TypeError("RegExp#test exec must return an object or null.");
|
|
128553
|
+
}
|
|
128554
|
+
return result !== null;
|
|
128555
|
+
}
|
|
128556
|
+
}
|
|
128557
|
+
if (!isSandboxRegex(target)) throw new TypeError("RegExp execution requires a regex receiver.");
|
|
128558
|
+
if (typeof args[0] !== "string") convertedInput = input;
|
|
128559
|
+
cursor2 = target.lastIndex;
|
|
128560
|
+
const lastIndex = await sandboxNumber(cursor2, budget, context);
|
|
128561
|
+
const match = executeRegex(target, input, lastIndex);
|
|
128562
|
+
return methodName === "test" ? match !== null : toMatchArray(match, input);
|
|
128563
|
+
} finally {
|
|
128564
|
+
budget.setRetainedValues(retained, void 0);
|
|
128565
|
+
}
|
|
128538
128566
|
}
|
|
128539
|
-
function executeRegex(target, input) {
|
|
128567
|
+
function executeRegex(target, input, lastIndex) {
|
|
128540
128568
|
const pattern = getSandboxRegexPattern(target);
|
|
128541
|
-
const match = matchRegex(pattern, input,
|
|
128569
|
+
const match = matchRegex(pattern, input, lastIndex);
|
|
128542
128570
|
if (pattern.flags.global) {
|
|
128543
128571
|
target.lastIndex = match === null ? 0 : match.index + match.text.length;
|
|
128544
128572
|
}
|
|
@@ -128552,13 +128580,26 @@ function toMatchArray(match, input) {
|
|
|
128552
128580
|
Object.assign(result, { index: match.index, input, groups: void 0 });
|
|
128553
128581
|
return result;
|
|
128554
128582
|
}
|
|
128555
|
-
var regexMethodNames;
|
|
128583
|
+
var regexMethodNames, regexFlagProperties;
|
|
128556
128584
|
var init_regex = __esm({
|
|
128557
128585
|
"packages/safe-js/src/interp/methods/regex.ts"() {
|
|
128558
128586
|
"use strict";
|
|
128559
128587
|
init_values();
|
|
128560
128588
|
init_engine2();
|
|
128589
|
+
init_builtin_call();
|
|
128590
|
+
init_object_model();
|
|
128591
|
+
init_string_coercion();
|
|
128561
128592
|
regexMethodNames = /* @__PURE__ */ new Set(["exec", "test"]);
|
|
128593
|
+
regexFlagProperties = {
|
|
128594
|
+
hasIndices: "d",
|
|
128595
|
+
global: "g",
|
|
128596
|
+
ignoreCase: "i",
|
|
128597
|
+
multiline: "m",
|
|
128598
|
+
dotAll: "s",
|
|
128599
|
+
unicode: "u",
|
|
128600
|
+
unicodeSets: "v",
|
|
128601
|
+
sticky: "y"
|
|
128602
|
+
};
|
|
128562
128603
|
}
|
|
128563
128604
|
});
|
|
128564
128605
|
|
|
@@ -130549,13 +130590,14 @@ function deepCopyToSandbox(value) {
|
|
|
130549
130590
|
seen: /* @__PURE__ */ new WeakMap()
|
|
130550
130591
|
});
|
|
130551
130592
|
}
|
|
130552
|
-
function cloneSandboxValue(value) {
|
|
130593
|
+
function cloneSandboxValue(value, options = {}) {
|
|
130553
130594
|
const initializeIterators = [];
|
|
130554
130595
|
const copy = copyToSandbox(
|
|
130555
130596
|
value,
|
|
130556
130597
|
{
|
|
130557
130598
|
seen: /* @__PURE__ */ new WeakMap(),
|
|
130558
|
-
initializeIterators
|
|
130599
|
+
initializeIterators,
|
|
130600
|
+
...options
|
|
130559
130601
|
},
|
|
130560
130602
|
"<root>",
|
|
130561
130603
|
true
|
|
@@ -130654,11 +130696,12 @@ function measureSandboxData(values, options = {}) {
|
|
|
130654
130696
|
}
|
|
130655
130697
|
if (isSandboxPromise(value)) return;
|
|
130656
130698
|
if (isSandboxRegex(value)) {
|
|
130657
|
-
const { source, flags } = captureRegexData(value);
|
|
130699
|
+
const { source, flags, lastIndex } = captureRegexData(value);
|
|
130658
130700
|
const compiled = regexCompiledData(getSandboxRegexPattern(value));
|
|
130659
130701
|
const staged = compiled.ticket === void 0 ? 0 : compiled.ticket.owner.budget.compileTicketUsage(compiled.ticket);
|
|
130660
130702
|
usage += Math.max(6 + source.length + flags.length + compiled.units, staged - 1);
|
|
130661
130703
|
if (compiled.ticket !== void 0) options.compileTickets?.add(compiled.ticket);
|
|
130704
|
+
visit(lastIndex, depth + 1);
|
|
130662
130705
|
return;
|
|
130663
130706
|
}
|
|
130664
130707
|
if (isSandboxArguments(value)) {
|
|
@@ -130739,7 +130782,16 @@ function copyToSandbox(value, state, path193 = "<root>", cloneSandboxCollections
|
|
|
130739
130782
|
return value;
|
|
130740
130783
|
}
|
|
130741
130784
|
if (isLiveCapability(value)) throw new TypeError("Live capabilities require their owning realm bridge.");
|
|
130742
|
-
if (
|
|
130785
|
+
if (isSandboxRegex(value)) {
|
|
130786
|
+
if (!cloneSandboxCollections) return value;
|
|
130787
|
+
const existing = state.seen.get(value);
|
|
130788
|
+
if (existing !== void 0) return existing;
|
|
130789
|
+
const copy = createSandboxRegex(value.source, value.flags, 0, state.compilation);
|
|
130790
|
+
state.seen.set(value, copy);
|
|
130791
|
+
if (!state.resetRegexLastIndex) copy.lastIndex = copyToSandbox(value.lastIndex, state, `${path193}.lastIndex`, true, depth + 1);
|
|
130792
|
+
return copy;
|
|
130793
|
+
}
|
|
130794
|
+
if (isSandboxClosure(value) || isSandboxGenerator(value) || isSandboxPromise(value)) {
|
|
130743
130795
|
return value;
|
|
130744
130796
|
}
|
|
130745
130797
|
if (isSandboxCollectionIterator(value)) {
|
|
@@ -130948,9 +131000,9 @@ function copyFromSandbox(value, state, path193 = "<root>", options, depth = 0) {
|
|
|
130948
131000
|
if (existing !== void 0) return existing;
|
|
130949
131001
|
guard.allocate(1 + source.length + flags.length);
|
|
130950
131002
|
const regex = new RegExp(source, flags);
|
|
130951
|
-
regex.lastIndex = lastIndex;
|
|
130952
|
-
guard.retainScratch();
|
|
130953
131003
|
state.seen.set(value, regex);
|
|
131004
|
+
Reflect.set(regex, "lastIndex", copyFromSandbox(lastIndex, state, `${path193}.lastIndex`, options, depth + 1));
|
|
131005
|
+
guard.retainScratch();
|
|
130954
131006
|
return regex;
|
|
130955
131007
|
} finally {
|
|
130956
131008
|
guard.close();
|
|
@@ -131832,7 +131884,7 @@ function validateTaggedValue(record2, path193, state) {
|
|
|
131832
131884
|
case "undefined":
|
|
131833
131885
|
return;
|
|
131834
131886
|
case "number":
|
|
131835
|
-
if (!["-Infinity", "Infinity", "NaN"].includes(String(record2.value))) {
|
|
131887
|
+
if (!["-Infinity", "Infinity", "NaN", "-0"].includes(String(record2.value))) {
|
|
131836
131888
|
fail2("invalidValue", `${path193}.value`, "unknown non-finite number value");
|
|
131837
131889
|
}
|
|
131838
131890
|
return;
|
|
@@ -131854,6 +131906,11 @@ function validateTaggedValue(record2, path193, state) {
|
|
|
131854
131906
|
requireString2(record2.flags, `${path193}.flags`, state.limits);
|
|
131855
131907
|
requireSafeInteger(record2.lastIndex, `${path193}.lastIndex`, 0);
|
|
131856
131908
|
return;
|
|
131909
|
+
case "regex-object":
|
|
131910
|
+
requireString2(record2.source, `${path193}.source`, state.limits);
|
|
131911
|
+
requireString2(record2.flags, `${path193}.flags`, state.limits);
|
|
131912
|
+
if (!Object.hasOwn(record2, "lastIndex")) fail2("invalidValue", `${path193}.lastIndex`, "missing regex cursor");
|
|
131913
|
+
return;
|
|
131857
131914
|
case "array":
|
|
131858
131915
|
case "arguments":
|
|
131859
131916
|
case "object":
|
|
@@ -145226,7 +145283,11 @@ function callStringMethod(value, methodName, args, budget, callClosure = async (
|
|
|
145226
145283
|
return budget.allocateString(result + value.slice(spanStart));
|
|
145227
145284
|
}
|
|
145228
145285
|
if (methodName === "replace" || methodName === "replaceAll") {
|
|
145229
|
-
return callReplaceLikeMethod(value, methodName, args, budget, callClosure);
|
|
145286
|
+
return callReplaceLikeMethod(value, methodName, args, budget, callClosure, context);
|
|
145287
|
+
}
|
|
145288
|
+
const regex = args[0];
|
|
145289
|
+
if (isSandboxRegex(regex) && regex.lastIndex !== null && typeof regex.lastIndex === "object" && (methodName === "match" && !regex.flags.includes("g") || methodName === "matchAll" && regex.flags.includes("g"))) {
|
|
145290
|
+
return callStringRegexCursor(value, methodName, regex, budget, parent, context);
|
|
145230
145291
|
}
|
|
145231
145292
|
if ((methodName === "match" || methodName === "matchAll" || methodName === "search") && !isSandboxRegex(args[0])) {
|
|
145232
145293
|
return callStringPattern(value, methodName, args[0], budget, parent, context);
|
|
@@ -145341,7 +145402,7 @@ function callStringMethod(value, methodName, args, budget, callClosure = async (
|
|
|
145341
145402
|
operation.release();
|
|
145342
145403
|
}
|
|
145343
145404
|
}
|
|
145344
|
-
function callReplaceLikeMethod(value, methodName, args, budget, callClosure) {
|
|
145405
|
+
function callReplaceLikeMethod(value, methodName, args, budget, callClosure, context) {
|
|
145345
145406
|
const search = args[0];
|
|
145346
145407
|
const replacement = args[1];
|
|
145347
145408
|
if (!isSandboxRegex(search) && typeof search !== "string" || typeof replacement !== "string" && !isSandboxClosure(replacement)) {
|
|
@@ -145359,7 +145420,8 @@ function callReplaceLikeMethod(value, methodName, args, budget, callClosure) {
|
|
|
145359
145420
|
replacement,
|
|
145360
145421
|
methodName === "replaceAll",
|
|
145361
145422
|
budget,
|
|
145362
|
-
callClosure
|
|
145423
|
+
callClosure,
|
|
145424
|
+
context
|
|
145363
145425
|
);
|
|
145364
145426
|
}
|
|
145365
145427
|
if (typeof replacement === "string") {
|
|
@@ -145376,20 +145438,28 @@ function callReplaceLikeMethod(value, methodName, args, budget, callClosure) {
|
|
|
145376
145438
|
callClosure
|
|
145377
145439
|
);
|
|
145378
145440
|
}
|
|
145379
|
-
async function replaceRegex(value, regex, replacement, replaceAll2, budget, callClosure) {
|
|
145441
|
+
async function replaceRegex(value, regex, replacement, replaceAll2, budget, callClosure, context) {
|
|
145380
145442
|
if (regex.flags.includes("g")) regex.lastIndex = 0;
|
|
145381
|
-
const
|
|
145382
|
-
|
|
145383
|
-
|
|
145384
|
-
|
|
145385
|
-
|
|
145386
|
-
|
|
145387
|
-
|
|
145388
|
-
|
|
145389
|
-
|
|
145443
|
+
const cursor2 = regex.lastIndex;
|
|
145444
|
+
const retained = {};
|
|
145445
|
+
budget.setRetainedValues(retained, () => [value, regex, cursor2, replacement]);
|
|
145446
|
+
try {
|
|
145447
|
+
const lastIndex = await sandboxNumber(cursor2, budget, context);
|
|
145448
|
+
const matches = collectRegexMatches(regex, value, replaceAll2 || regex.flags.includes("g"), void 0, lastIndex);
|
|
145449
|
+
let result = "";
|
|
145450
|
+
let copiedThrough = 0;
|
|
145451
|
+
for (const match of matches) {
|
|
145452
|
+
result += value.slice(copiedThrough, match.index);
|
|
145453
|
+
result += typeof replacement === "string" ? expandReplacement(replacement, match.text, match.captures, value, match.index) : String(
|
|
145454
|
+
await callClosure(replacement, [match.text, ...match.captures, match.index, value])
|
|
145455
|
+
);
|
|
145456
|
+
copiedThrough = match.index + match.text.length;
|
|
145457
|
+
}
|
|
145458
|
+
result += value.slice(copiedThrough);
|
|
145459
|
+
return budget.allocateString(result);
|
|
145460
|
+
} finally {
|
|
145461
|
+
budget.setRetainedValues(retained, void 0);
|
|
145390
145462
|
}
|
|
145391
|
-
result += value.slice(copiedThrough);
|
|
145392
|
-
return budget.allocateString(result);
|
|
145393
145463
|
}
|
|
145394
145464
|
function expandReplacement(replacement, match, captures, input, matchIndex) {
|
|
145395
145465
|
let result = "";
|
|
@@ -145505,7 +145575,7 @@ async function callStringPattern(value, methodName, pattern, budget, parent, con
|
|
|
145505
145575
|
const operation = budget.acquireCompileOwner(false, parent?.owner);
|
|
145506
145576
|
const compilation = new CompileScope(operation.owner);
|
|
145507
145577
|
const retainedPattern = {};
|
|
145508
|
-
budget.setRetainedValues(retainedPattern, () => [pattern]);
|
|
145578
|
+
budget.setRetainedValues(retainedPattern, () => [value, pattern]);
|
|
145509
145579
|
try {
|
|
145510
145580
|
const source = pattern === void 0 ? "" : await sandboxString(pattern, budget, context);
|
|
145511
145581
|
const regex = createSandboxRegex(source, methodName === "matchAll" ? "g" : "", 0, compilation);
|
|
@@ -145516,35 +145586,51 @@ async function callStringPattern(value, methodName, pattern, budget, parent, con
|
|
|
145516
145586
|
operation.release();
|
|
145517
145587
|
}
|
|
145518
145588
|
}
|
|
145519
|
-
function
|
|
145589
|
+
async function callStringRegexCursor(value, methodName, regex, budget, parent, context) {
|
|
145590
|
+
const operation = budget.acquireCompileOwner(false, parent?.owner);
|
|
145591
|
+
const compilation = new CompileScope(operation.owner);
|
|
145592
|
+
const cursor2 = regex.lastIndex;
|
|
145593
|
+
const retained = {};
|
|
145594
|
+
budget.setRetainedValues(retained, () => [value, regex, cursor2]);
|
|
145595
|
+
try {
|
|
145596
|
+
const lastIndex = await sandboxNumber(cursor2, budget, context);
|
|
145597
|
+
return callMatchLikeMethod(value, methodName, [regex], compilation, lastIndex);
|
|
145598
|
+
} finally {
|
|
145599
|
+
budget.setRetainedValues(retained, void 0);
|
|
145600
|
+
compilation.dispose();
|
|
145601
|
+
operation.release();
|
|
145602
|
+
}
|
|
145603
|
+
}
|
|
145604
|
+
function callMatchLikeMethod(value, methodName, args, compilation, lastIndex) {
|
|
145520
145605
|
const regex = args[0];
|
|
145521
145606
|
if (!isSandboxRegex(regex))
|
|
145522
145607
|
throw new TypeError(`String#${methodName} requires a regex argument.`);
|
|
145523
145608
|
if (methodName === "search") {
|
|
145524
|
-
const
|
|
145525
|
-
if (!Object.is(
|
|
145526
|
-
const match = executeRegex(regex, value);
|
|
145527
|
-
if (!Object.is(regex.lastIndex,
|
|
145609
|
+
const lastIndex2 = regex.lastIndex;
|
|
145610
|
+
if (!Object.is(lastIndex2, 0)) regex.lastIndex = 0;
|
|
145611
|
+
const match = executeRegex(regex, value, 0);
|
|
145612
|
+
if (!Object.is(regex.lastIndex, lastIndex2)) regex.lastIndex = lastIndex2;
|
|
145528
145613
|
return match?.index ?? -1;
|
|
145529
145614
|
}
|
|
145530
145615
|
if (methodName === "matchAll" && !regex.flags.includes("g"))
|
|
145531
145616
|
throw new TypeError("String#matchAll requires a global regex.");
|
|
145532
145617
|
if (methodName === "match" && !regex.flags.includes("g"))
|
|
145533
|
-
return toMatchArray(executeRegex(regex, value), value);
|
|
145618
|
+
return toMatchArray(executeRegex(regex, value, lastIndex ?? Number(regex.lastIndex)), value);
|
|
145534
145619
|
if (methodName === "match") regex.lastIndex = 0;
|
|
145535
|
-
const matcher = methodName === "matchAll" ? createSandboxRegex(regex.source, regex.flags, regex.lastIndex, compilation) : regex;
|
|
145536
|
-
const matches = collectRegexMatches(matcher, value, true, compilation.owner?.budget);
|
|
145620
|
+
const matcher = methodName === "matchAll" ? createSandboxRegex(regex.source, regex.flags, normalizeLastIndex(lastIndex ?? Number(regex.lastIndex)), compilation) : regex;
|
|
145621
|
+
const matches = collectRegexMatches(matcher, value, true, compilation.owner?.budget, Number(matcher.lastIndex));
|
|
145537
145622
|
if (methodName === "match" && matches.length === 0) return null;
|
|
145538
145623
|
return methodName === "match" ? matches.map((match) => match.text) : matches.map((match) => toMatchArray(match, value));
|
|
145539
145624
|
}
|
|
145540
|
-
function collectRegexMatches(regex, value, all, budget) {
|
|
145625
|
+
function collectRegexMatches(regex, value, all, budget, lastIndex = 0) {
|
|
145541
145626
|
const matches = [];
|
|
145542
145627
|
do {
|
|
145543
|
-
const match = executeRegex(regex, value);
|
|
145628
|
+
const match = executeRegex(regex, value, lastIndex);
|
|
145544
145629
|
if (match === null) break;
|
|
145545
145630
|
budget?.allocateArrayLength(matches.length + 1);
|
|
145546
145631
|
matches.push(match);
|
|
145547
|
-
|
|
145632
|
+
lastIndex = match.index + match.text.length;
|
|
145633
|
+
if (all && match.text.length === 0) regex.lastIndex = ++lastIndex;
|
|
145548
145634
|
} while (all);
|
|
145549
145635
|
return matches;
|
|
145550
145636
|
}
|
|
@@ -145567,6 +145653,7 @@ var init_string = __esm({
|
|
|
145567
145653
|
"use strict";
|
|
145568
145654
|
init_builtin_call();
|
|
145569
145655
|
init_compile_guard();
|
|
145656
|
+
init_engine2();
|
|
145570
145657
|
init_string_coercion();
|
|
145571
145658
|
init_values();
|
|
145572
145659
|
init_regex();
|
|
@@ -151088,7 +151175,7 @@ function createMiscGlobals(options) {
|
|
|
151088
151175
|
return {
|
|
151089
151176
|
structuredClone: createSandboxClosure({
|
|
151090
151177
|
sandbox: true,
|
|
151091
|
-
call: ([value]) => structuredCloneSandboxValue(value, options.budget),
|
|
151178
|
+
call: ([value], context) => structuredCloneSandboxValue(value, options.budget, context?.compilation),
|
|
151092
151179
|
name: "structuredClone"
|
|
151093
151180
|
}),
|
|
151094
151181
|
parseInt: createSandboxClosure({
|
|
@@ -151113,11 +151200,20 @@ function createMiscGlobals(options) {
|
|
|
151113
151200
|
})
|
|
151114
151201
|
};
|
|
151115
151202
|
}
|
|
151116
|
-
function structuredCloneSandboxValue(value, budget) {
|
|
151117
|
-
|
|
151118
|
-
const
|
|
151119
|
-
|
|
151120
|
-
|
|
151203
|
+
function structuredCloneSandboxValue(value, budget, parent) {
|
|
151204
|
+
const operation = budget.acquireCompileOwner(false, parent?.owner);
|
|
151205
|
+
const compilation = parent?.owner === operation.owner ? parent : new CompileScope(operation.owner);
|
|
151206
|
+
try {
|
|
151207
|
+
const clone = cloneSandboxValue(value, { compilation, resetRegexLastIndex: true });
|
|
151208
|
+
assertSandboxGraphDepth(clone);
|
|
151209
|
+
assertStructuredCloneable(clone, /* @__PURE__ */ new WeakSet());
|
|
151210
|
+
allocateProducedSandboxValue(clone, budget);
|
|
151211
|
+
if (compilation !== parent) reconcileCompiledValues(budget, [clone], compilation);
|
|
151212
|
+
return clone;
|
|
151213
|
+
} finally {
|
|
151214
|
+
if (compilation !== parent) compilation.dispose();
|
|
151215
|
+
operation.release();
|
|
151216
|
+
}
|
|
151121
151217
|
}
|
|
151122
151218
|
function assertStructuredCloneable(value, seen) {
|
|
151123
151219
|
if (isSandboxClosure(value) || isSandboxPromise(value) || isSandboxCollectionIterator(value)) {
|
|
@@ -151149,6 +151245,7 @@ var init_misc = __esm({
|
|
|
151149
151245
|
"use strict";
|
|
151150
151246
|
init_collection_iterator();
|
|
151151
151247
|
init_graph_depth();
|
|
151248
|
+
init_compile_guard();
|
|
151152
151249
|
init_values();
|
|
151153
151250
|
}
|
|
151154
151251
|
});
|