@poe-platform/safe-js 0.1.295 → 0.1.296
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/safe-js/chunks/{chunk-CL6E5SM7.js → chunk-2Y6SJCIT.js} +74 -36
- package/dist/safe-js/chunks/chunk-2Y6SJCIT.js.map +7 -0
- package/dist/safe-js/chunks/{chunk-JXRBLOIP.js → chunk-BXVBZMIN.js} +2 -2
- package/dist/safe-js/cli.js +2 -2
- package/dist/safe-js/core.js +1 -1
- package/dist/safe-js/index.js +2 -2
- package/package.json +2 -2
- package/dist/safe-js/chunks/chunk-CL6E5SM7.js.map +0 -7
- /package/dist/safe-js/chunks/{chunk-JXRBLOIP.js.map → chunk-BXVBZMIN.js.map} +0 -0
|
@@ -11608,6 +11608,30 @@ function createPrimitiveConstructor(options, budget) {
|
|
|
11608
11608
|
}
|
|
11609
11609
|
|
|
11610
11610
|
// packages/safe-js/src/interp/methods/array.ts
|
|
11611
|
+
async function arraySpeciesCreate(value, length, options) {
|
|
11612
|
+
const receiver = arrayLikeSources.get(value) ?? value;
|
|
11613
|
+
const read = (target, key) => options.context?.getProperty !== void 0 ? options.context.getProperty(target, key) : readPropertyDescriptor(getSandboxPropertyDescriptor(target, key, options.budget) ?? { value: void 0 }, target, options.context);
|
|
11614
|
+
let constructor;
|
|
11615
|
+
if (Array.isArray(receiver)) {
|
|
11616
|
+
constructor = await read(receiver, "constructor");
|
|
11617
|
+
if (typeof constructor === "object" && constructor !== null) {
|
|
11618
|
+
constructor = await read(constructor, Symbol.species);
|
|
11619
|
+
if (constructor === null) constructor = void 0;
|
|
11620
|
+
}
|
|
11621
|
+
if (constructor !== void 0) {
|
|
11622
|
+
if (!isSandboxClosure(constructor) || constructor.construct === void 0)
|
|
11623
|
+
throw new TypeError("Array species must be a constructor.");
|
|
11624
|
+
return await invokeBuiltinClosure(constructor, [length], options.budget, options.context, void 0, true);
|
|
11625
|
+
}
|
|
11626
|
+
}
|
|
11627
|
+
options.budget.allocateArrayLength(length);
|
|
11628
|
+
return new Array(length);
|
|
11629
|
+
}
|
|
11630
|
+
function defineArrayResult(result, index, value, options) {
|
|
11631
|
+
if (index >= Number.MAX_SAFE_INTEGER) throw new TypeError("Array result exceeds the safe integer limit.");
|
|
11632
|
+
if (Array.isArray(result)) options.budget.allocateArrayLength(index + 1);
|
|
11633
|
+
defineOwnDataProperty(objectProperties(result, true), String(index), value);
|
|
11634
|
+
}
|
|
11611
11635
|
var arrayLikeSources = /* @__PURE__ */ new WeakMap();
|
|
11612
11636
|
var activeArrayCallbacks = /* @__PURE__ */ new WeakMap();
|
|
11613
11637
|
var localeArrays = /* @__PURE__ */ new WeakSet();
|
|
@@ -11887,15 +11911,18 @@ async function callArrayMethodUnlocked(value, methodName, args, options, stack)
|
|
|
11887
11911
|
),
|
|
11888
11912
|
options.budget
|
|
11889
11913
|
);
|
|
11890
|
-
case "flat":
|
|
11914
|
+
case "flat": {
|
|
11915
|
+
const length = value.length;
|
|
11891
11916
|
return budgetProducedValue(
|
|
11892
11917
|
await flattenArray(
|
|
11893
11918
|
value,
|
|
11894
11919
|
args[0] === void 0 ? 1 : toIntegerOrInfinity(await sandboxNumber(args[0], options.budget, options.context)),
|
|
11895
|
-
options
|
|
11920
|
+
options,
|
|
11921
|
+
length
|
|
11896
11922
|
),
|
|
11897
11923
|
options.budget
|
|
11898
11924
|
);
|
|
11925
|
+
}
|
|
11899
11926
|
case "includes":
|
|
11900
11927
|
case "indexOf":
|
|
11901
11928
|
case "lastIndexOf": {
|
|
@@ -11933,22 +11960,23 @@ async function callArrayMethodUnlocked(value, methodName, args, options, stack)
|
|
|
11933
11960
|
const first = start < 0 ? Math.max(length + start, 0) : Math.min(start, length);
|
|
11934
11961
|
const final = end < 0 ? Math.max(length + end, 0) : Math.min(end, length);
|
|
11935
11962
|
const count = Math.max(final - first, 0);
|
|
11936
|
-
|
|
11937
|
-
const result = new Array(count);
|
|
11963
|
+
const result = await arraySpeciesCreate(value, count, options);
|
|
11938
11964
|
const release = retainValues(options.budget, () => [result]);
|
|
11939
11965
|
try {
|
|
11940
11966
|
for (let index = 0; index < count; index += 1) {
|
|
11941
11967
|
options.budget.visitNode();
|
|
11942
11968
|
if (first + index in value)
|
|
11943
|
-
result
|
|
11969
|
+
defineArrayResult(result, index, await readArrayElement(value, first + index, options), options);
|
|
11944
11970
|
}
|
|
11971
|
+
await setSandboxProperty(result, "length", count, options.budget, true, options.context);
|
|
11945
11972
|
return budgetProducedValue(result, options.budget);
|
|
11946
11973
|
} finally {
|
|
11947
11974
|
release();
|
|
11948
11975
|
}
|
|
11949
11976
|
}
|
|
11950
11977
|
case "concat": {
|
|
11951
|
-
const result =
|
|
11978
|
+
const result = await arraySpeciesCreate(value, 0, options);
|
|
11979
|
+
let targetIndex = 0;
|
|
11952
11980
|
const retained = {};
|
|
11953
11981
|
options.budget.setRetainedValues(retained, () => [result]);
|
|
11954
11982
|
try {
|
|
@@ -11959,21 +11987,22 @@ async function callArrayMethodUnlocked(value, methodName, args, options, stack)
|
|
|
11959
11987
|
spread = flag === void 0 ? Array.isArray(entry) : Boolean(flag);
|
|
11960
11988
|
}
|
|
11961
11989
|
if (!spread) {
|
|
11962
|
-
|
|
11963
|
-
result.push(entry);
|
|
11990
|
+
defineArrayResult(result, targetIndex++, entry, options);
|
|
11964
11991
|
continue;
|
|
11965
11992
|
}
|
|
11966
|
-
const start =
|
|
11993
|
+
const start = targetIndex;
|
|
11967
11994
|
const source = await arrayLikeView(entry, options);
|
|
11968
11995
|
const length = source.length;
|
|
11969
|
-
|
|
11970
|
-
result.
|
|
11996
|
+
if (start + length > Number.MAX_SAFE_INTEGER) throw new TypeError("Array result exceeds the safe integer limit.");
|
|
11997
|
+
if (Array.isArray(result)) options.budget.allocateArrayLength(start + length);
|
|
11998
|
+
targetIndex += length;
|
|
11971
11999
|
for (let index = 0; index < length; index++) {
|
|
11972
12000
|
options.budget.visitNode();
|
|
11973
12001
|
if (index in source)
|
|
11974
|
-
result
|
|
12002
|
+
defineArrayResult(result, start + index, await readArrayElement(source, index, options), options);
|
|
11975
12003
|
}
|
|
11976
12004
|
}
|
|
12005
|
+
await setSandboxProperty(result, "length", targetIndex, options.budget, true, options.context);
|
|
11977
12006
|
return budgetProducedValue(result, options.budget);
|
|
11978
12007
|
} finally {
|
|
11979
12008
|
options.budget.setRetainedValues(retained, void 0);
|
|
@@ -11998,16 +12027,16 @@ async function callArrayMethodUnlocked(value, methodName, args, options, stack)
|
|
|
11998
12027
|
const nextLength = length + inserted - deleted;
|
|
11999
12028
|
if (nextLength > Number.MAX_SAFE_INTEGER)
|
|
12000
12029
|
throw new TypeError("Array-like length exceeds the safe integer limit.");
|
|
12001
|
-
|
|
12002
|
-
const removed = new Array(deleted);
|
|
12030
|
+
const removed = await arraySpeciesCreate(value, deleted, options);
|
|
12003
12031
|
const retained = {};
|
|
12004
12032
|
options.budget.setRetainedValues(retained, () => [removed]);
|
|
12005
12033
|
try {
|
|
12006
12034
|
for (let index = 0; index < deleted; index++) {
|
|
12007
12035
|
options.budget.visitNode();
|
|
12008
12036
|
if (first + index in value)
|
|
12009
|
-
removed
|
|
12037
|
+
defineArrayResult(removed, index, await readArrayElement(value, first + index, options), options);
|
|
12010
12038
|
}
|
|
12039
|
+
await setSandboxProperty(removed, "length", deleted, options.budget, true, options.context);
|
|
12011
12040
|
if (inserted < deleted) {
|
|
12012
12041
|
for (let index = first; index < length - deleted; index++)
|
|
12013
12042
|
await moveArrayElement(value, index + deleted, index + inserted, options);
|
|
@@ -12303,8 +12332,7 @@ async function moveArrayElement(value, from, to, options) {
|
|
|
12303
12332
|
}
|
|
12304
12333
|
async function mapArray(value, callback, options, stack, thisValue) {
|
|
12305
12334
|
const length = value.length;
|
|
12306
|
-
|
|
12307
|
-
const result = new Array(length);
|
|
12335
|
+
const result = await arraySpeciesCreate(value, length, options);
|
|
12308
12336
|
options.budget.setRetainedValues(result, () => [result]);
|
|
12309
12337
|
try {
|
|
12310
12338
|
for (let index = 0; index < length; index += 1) {
|
|
@@ -12312,7 +12340,7 @@ async function mapArray(value, callback, options, stack, thisValue) {
|
|
|
12312
12340
|
if (!(index in value)) {
|
|
12313
12341
|
continue;
|
|
12314
12342
|
}
|
|
12315
|
-
result
|
|
12343
|
+
defineArrayResult(result, index, await callArrayCallback(
|
|
12316
12344
|
callback,
|
|
12317
12345
|
await readArrayElement(value, index, options),
|
|
12318
12346
|
index,
|
|
@@ -12320,7 +12348,7 @@ async function mapArray(value, callback, options, stack, thisValue) {
|
|
|
12320
12348
|
options,
|
|
12321
12349
|
stack,
|
|
12322
12350
|
thisValue
|
|
12323
|
-
);
|
|
12351
|
+
), options);
|
|
12324
12352
|
}
|
|
12325
12353
|
return result;
|
|
12326
12354
|
} finally {
|
|
@@ -12329,7 +12357,8 @@ async function mapArray(value, callback, options, stack, thisValue) {
|
|
|
12329
12357
|
}
|
|
12330
12358
|
async function filterArray(value, callback, options, stack, thisValue) {
|
|
12331
12359
|
const length = value.length;
|
|
12332
|
-
const result =
|
|
12360
|
+
const result = await arraySpeciesCreate(value, 0, options);
|
|
12361
|
+
let targetIndex = 0;
|
|
12333
12362
|
options.budget.setRetainedValues(result, () => [result]);
|
|
12334
12363
|
try {
|
|
12335
12364
|
for (let index = 0; index < length; index += 1) {
|
|
@@ -12339,7 +12368,7 @@ async function filterArray(value, callback, options, stack, thisValue) {
|
|
|
12339
12368
|
}
|
|
12340
12369
|
const entry = await readArrayElement(value, index, options);
|
|
12341
12370
|
if (await callArrayCallback(callback, entry, index, value, options, stack, thisValue)) {
|
|
12342
|
-
result
|
|
12371
|
+
defineArrayResult(result, targetIndex++, entry, options);
|
|
12343
12372
|
}
|
|
12344
12373
|
}
|
|
12345
12374
|
return result;
|
|
@@ -12543,7 +12572,8 @@ async function forEachArray(value, callback, options, stack, thisValue) {
|
|
|
12543
12572
|
}
|
|
12544
12573
|
async function flatMapArray(value, callback, options, stack, thisValue) {
|
|
12545
12574
|
const length = value.length;
|
|
12546
|
-
const result =
|
|
12575
|
+
const result = await arraySpeciesCreate(value, 0, options);
|
|
12576
|
+
let targetIndex = 0;
|
|
12547
12577
|
options.budget.setRetainedValues(result, () => [result]);
|
|
12548
12578
|
try {
|
|
12549
12579
|
for (let index = 0; index < length; index += 1) {
|
|
@@ -12561,37 +12591,35 @@ async function flatMapArray(value, callback, options, stack, thisValue) {
|
|
|
12561
12591
|
thisValue
|
|
12562
12592
|
);
|
|
12563
12593
|
if (Array.isArray(mapped)) {
|
|
12564
|
-
|
|
12594
|
+
const mappedLength = mapped.length;
|
|
12595
|
+
for (let mappedIndex = 0; mappedIndex < mappedLength; mappedIndex += 1) {
|
|
12565
12596
|
options.budget.visitNode();
|
|
12566
12597
|
if (!(mappedIndex in mapped)) {
|
|
12567
12598
|
continue;
|
|
12568
12599
|
}
|
|
12569
|
-
result
|
|
12570
|
-
options.budget.allocateArrayLength(result.length);
|
|
12600
|
+
defineArrayResult(result, targetIndex++, await readArrayElement(mapped, mappedIndex, options), options);
|
|
12571
12601
|
}
|
|
12572
12602
|
continue;
|
|
12573
12603
|
}
|
|
12574
|
-
result
|
|
12575
|
-
options.budget.allocateArrayLength(result.length);
|
|
12604
|
+
defineArrayResult(result, targetIndex++, mapped, options);
|
|
12576
12605
|
}
|
|
12577
12606
|
return result;
|
|
12578
12607
|
} finally {
|
|
12579
12608
|
options.budget.setRetainedValues(result, void 0);
|
|
12580
12609
|
}
|
|
12581
12610
|
}
|
|
12582
|
-
async function flattenArray(value, depth, options) {
|
|
12583
|
-
const result =
|
|
12611
|
+
async function flattenArray(value, depth, options, length) {
|
|
12612
|
+
const result = await arraySpeciesCreate(value, 0, options);
|
|
12584
12613
|
const retained = {};
|
|
12585
12614
|
options.budget.setRetainedValues(retained, () => [result]);
|
|
12586
12615
|
try {
|
|
12587
|
-
await appendFlattenedEntries(value, depth, result, options);
|
|
12616
|
+
await appendFlattenedEntries(value, depth, result, options, 0, length);
|
|
12588
12617
|
return result;
|
|
12589
12618
|
} finally {
|
|
12590
12619
|
options.budget.setRetainedValues(retained, void 0);
|
|
12591
12620
|
}
|
|
12592
12621
|
}
|
|
12593
|
-
async function appendFlattenedEntries(value, depth, result, options) {
|
|
12594
|
-
const length = value.length;
|
|
12622
|
+
async function appendFlattenedEntries(value, depth, result, options, targetIndex, length = value.length) {
|
|
12595
12623
|
for (let index = 0; index < length; index += 1) {
|
|
12596
12624
|
options.budget.visitNode();
|
|
12597
12625
|
if (!(index in value)) {
|
|
@@ -12599,12 +12627,12 @@ async function appendFlattenedEntries(value, depth, result, options) {
|
|
|
12599
12627
|
}
|
|
12600
12628
|
const entry = await readArrayElement(value, index, options);
|
|
12601
12629
|
if (depth > 0 && Array.isArray(entry)) {
|
|
12602
|
-
await appendFlattenedEntries(entry, depth - 1, result, options);
|
|
12630
|
+
targetIndex = await appendFlattenedEntries(entry, depth - 1, result, options, targetIndex);
|
|
12603
12631
|
continue;
|
|
12604
12632
|
}
|
|
12605
|
-
result
|
|
12606
|
-
options.budget.allocateArrayLength(result.length);
|
|
12633
|
+
defineArrayResult(result, targetIndex++, entry, options);
|
|
12607
12634
|
}
|
|
12635
|
+
return targetIndex;
|
|
12608
12636
|
}
|
|
12609
12637
|
async function sortArray(value, comparator, options, stack) {
|
|
12610
12638
|
const length = value.length;
|
|
@@ -13076,6 +13104,16 @@ function createArrayGlobal(budget) {
|
|
|
13076
13104
|
});
|
|
13077
13105
|
const properties = materializeFunctionProperties(constructor);
|
|
13078
13106
|
Object.defineProperty(properties, "prototype", { value: prototype, writable: false });
|
|
13107
|
+
Object.defineProperty(properties, Symbol.species, {
|
|
13108
|
+
get: accessorAdapter(createSandboxClosure({
|
|
13109
|
+
guest: true,
|
|
13110
|
+
sandbox: true,
|
|
13111
|
+
name: "get [Symbol.species]",
|
|
13112
|
+
length: 0,
|
|
13113
|
+
call: (_args, context) => context?.thisValue
|
|
13114
|
+
}), "get"),
|
|
13115
|
+
configurable: true
|
|
13116
|
+
});
|
|
13079
13117
|
Object.defineProperty(prototype, "constructor", { value: constructor, writable: true, configurable: true });
|
|
13080
13118
|
for (const name of arrayMethodNames) {
|
|
13081
13119
|
const method = createSandboxClosure({
|
|
@@ -40765,4 +40803,4 @@ export {
|
|
|
40765
40803
|
FileSnapshotBackend,
|
|
40766
40804
|
run
|
|
40767
40805
|
};
|
|
40768
|
-
//# sourceMappingURL=chunk-
|
|
40806
|
+
//# sourceMappingURL=chunk-2Y6SJCIT.js.map
|