poe-code 14.0.52 → 14.0.53
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 +164 -91
- package/dist/index.js.map +3 -3
- package/dist/metafile.json +1 -1
- package/package.json +1 -1
- package/packages/safe-bash/dist/browser.js +35 -15
- package/packages/safe-bash/dist/browser.js.map +3 -3
- package/packages/safe-bash/dist/shell/arrays/state.d.ts +2 -1
- package/packages/safe-bash/dist/shell/arrays/state.d.ts.map +1 -1
- package/packages/safe-bash/dist/shell/arrays/state.js +23 -5
- package/packages/safe-bash/dist/shell/arrays/state.js.map +1 -1
- package/packages/safe-bash/dist/shell/cleanup.d.ts.map +1 -1
- package/packages/safe-bash/dist/shell/cleanup.js +11 -5
- package/packages/safe-bash/dist/shell/cleanup.js.map +1 -1
- package/packages/safe-bash/dist/shell/runtime.js +5 -5
- package/packages/safe-bash/dist/shell/runtime.js.map +1 -1
- package/packages/safe-js/dist/chunks/{chunk-XIBH4BH2.js → chunk-4XYGVCOQ.js} +2 -2
- package/packages/safe-js/dist/chunks/{chunk-DVWTNFTV.js → chunk-VDFW3EKS.js} +161 -91
- package/packages/safe-js/dist/chunks/{chunk-DVWTNFTV.js.map → chunk-VDFW3EKS.js.map} +3 -3
- 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/interpreter.js +5 -1
- package/packages/safe-js/dist/interp/methods/array.d.ts +12 -3
- package/packages/safe-js/dist/interp/methods/array.js +164 -46
- package/packages/safe-js/dist/interp/methods/number.d.ts +2 -2
- package/packages/safe-js/dist/interp/methods/number.js +27 -46
- /package/packages/safe-js/dist/chunks/{chunk-XIBH4BH2.js.map → chunk-4XYGVCOQ.js.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -144043,7 +144043,7 @@ function getArrayMember(value, property, options) {
|
|
|
144043
144043
|
return createSandboxClosure({
|
|
144044
144044
|
sandbox: true,
|
|
144045
144045
|
name: `Array#${property}`,
|
|
144046
|
-
call: (args, context) => callArrayMethod(
|
|
144046
|
+
call: (args, context) => callArrayMethod(context?.thisValue, property, args, { ...options, context }, context?.stack ?? [])
|
|
144047
144047
|
});
|
|
144048
144048
|
}
|
|
144049
144049
|
return void 0;
|
|
@@ -144058,28 +144058,75 @@ function getArrayIndex(property) {
|
|
|
144058
144058
|
function isArrayMethodName(property) {
|
|
144059
144059
|
return typeof property === "string" && arrayMethodNames.has(property);
|
|
144060
144060
|
}
|
|
144061
|
-
async function callArrayMethod(
|
|
144062
|
-
if (
|
|
144063
|
-
|
|
144064
|
-
}
|
|
144065
|
-
|
|
144066
|
-
|
|
144067
|
-
|
|
144068
|
-
|
|
144069
|
-
|
|
144061
|
+
async function callArrayMethod(receiver, methodName, args, options, stack = []) {
|
|
144062
|
+
if (receiver === null || receiver === void 0) throw new TypeError("Array method requires a receiver.");
|
|
144063
|
+
if (typeof receiver !== "object") throw new TypeError("Object primitive boxing is not supported.");
|
|
144064
|
+
const retainedReceiver = {};
|
|
144065
|
+
options.budget.setRetainedValues(retainedReceiver, () => [receiver]);
|
|
144066
|
+
try {
|
|
144067
|
+
const value = Array.isArray(receiver) || methodName === "concat" ? receiver : await arrayLikeView(receiver, options);
|
|
144068
|
+
if (isMutatingArrayMethod(methodName)) {
|
|
144069
|
+
assertCollectionMutable(receiver);
|
|
144070
144070
|
}
|
|
144071
|
-
|
|
144072
|
-
|
|
144073
|
-
|
|
144074
|
-
|
|
144075
|
-
|
|
144076
|
-
|
|
144077
|
-
|
|
144078
|
-
|
|
144071
|
+
if (isCallbackArrayMethod(methodName)) {
|
|
144072
|
+
let callbackState = activeArrayCallbacks.get(receiver);
|
|
144073
|
+
if (callbackState === void 0) {
|
|
144074
|
+
callbackState = { depth: 0, leave: enterRunningState(receiver) };
|
|
144075
|
+
activeArrayCallbacks.set(receiver, callbackState);
|
|
144076
|
+
}
|
|
144077
|
+
callbackState.depth += 1;
|
|
144078
|
+
try {
|
|
144079
|
+
const result2 = await callArrayMethodUnlocked(value, methodName, args, options, stack);
|
|
144080
|
+
return result2 === value ? receiver : result2;
|
|
144081
|
+
} finally {
|
|
144082
|
+
callbackState.depth -= 1;
|
|
144083
|
+
if (callbackState.depth === 0) {
|
|
144084
|
+
activeArrayCallbacks.delete(receiver);
|
|
144085
|
+
callbackState.leave();
|
|
144086
|
+
}
|
|
144079
144087
|
}
|
|
144080
144088
|
}
|
|
144089
|
+
const result = await callArrayMethodUnlocked(value, methodName, args, options, stack);
|
|
144090
|
+
return result === value ? receiver : result;
|
|
144091
|
+
} finally {
|
|
144092
|
+
options.budget.setRetainedValues(retainedReceiver, void 0);
|
|
144081
144093
|
}
|
|
144082
|
-
|
|
144094
|
+
}
|
|
144095
|
+
async function arrayLikeView(receiver, options) {
|
|
144096
|
+
const rawLength = options.context?.getProperty !== void 0 ? options.context.getProperty(receiver, "length") : getSandboxDataProperty(receiver, "length", options.budget);
|
|
144097
|
+
const number = await sandboxNumber(rawLength, options.budget, options.context);
|
|
144098
|
+
const length = Number.isNaN(number) || number <= 0 ? 0 : Math.min(Math.trunc(number), Number.MAX_SAFE_INTEGER);
|
|
144099
|
+
const view = new Proxy(/* @__PURE__ */ Object.create(null), {
|
|
144100
|
+
get: (_target, key3) => {
|
|
144101
|
+
options.budget.visitNode();
|
|
144102
|
+
if (key3 === "length") return length;
|
|
144103
|
+
if (typeof key3 !== "string") return void 0;
|
|
144104
|
+
return options.context?.getProperty !== void 0 ? options.context.getProperty(receiver, key3) : getSandboxDataProperty(receiver, key3, options.budget);
|
|
144105
|
+
},
|
|
144106
|
+
has: (_target, key3) => {
|
|
144107
|
+
options.budget.visitNode();
|
|
144108
|
+
if (typeof key3 === "string" && options.hasProperty !== void 0) return options.hasProperty(receiver, key3);
|
|
144109
|
+
for (let current = receiver; current !== null; current = getSandboxPrototype(current, options.budget)) {
|
|
144110
|
+
options.budget.visitNode();
|
|
144111
|
+
if (Object.hasOwn(current, key3)) return true;
|
|
144112
|
+
}
|
|
144113
|
+
return false;
|
|
144114
|
+
},
|
|
144115
|
+
set: (_target, key3, entry) => {
|
|
144116
|
+
options.budget.visitNode();
|
|
144117
|
+
if (typeof key3 !== "string") throw new TypeError("Array indices must be string keys.");
|
|
144118
|
+
if (options.setProperty !== void 0) options.setProperty(receiver, key3, entry);
|
|
144119
|
+
else if (!Reflect.set(receiver, key3, entry)) throw new TypeError(`Cannot assign property '${key3}'.`);
|
|
144120
|
+
return true;
|
|
144121
|
+
},
|
|
144122
|
+
deleteProperty: (_target, key3) => {
|
|
144123
|
+
options.budget.visitNode();
|
|
144124
|
+
if (typeof key3 === "string" && options.deleteProperty !== void 0) return options.deleteProperty(receiver, key3);
|
|
144125
|
+
return Reflect.deleteProperty(receiver, key3);
|
|
144126
|
+
}
|
|
144127
|
+
});
|
|
144128
|
+
arrayLikeSources.set(view, receiver);
|
|
144129
|
+
return view;
|
|
144083
144130
|
}
|
|
144084
144131
|
async function callArrayMethodUnlocked(value, methodName, args, options, stack) {
|
|
144085
144132
|
switch (methodName) {
|
|
@@ -144192,11 +144239,21 @@ async function callArrayMethodUnlocked(value, methodName, args, options, stack)
|
|
|
144192
144239
|
return Reflect.apply(Array.prototype.lastIndexOf, value, [...args]);
|
|
144193
144240
|
case "join":
|
|
144194
144241
|
return options.budget.allocateString(Reflect.apply(Array.prototype.join, value, [...args]));
|
|
144195
|
-
case "slice":
|
|
144196
|
-
|
|
144197
|
-
|
|
144198
|
-
|
|
144199
|
-
);
|
|
144242
|
+
case "slice": {
|
|
144243
|
+
const length = value.length;
|
|
144244
|
+
const start = toIntegerOrInfinity(await sandboxNumber(args[0], options.budget, options.context));
|
|
144245
|
+
const end = args[1] === void 0 ? length : toIntegerOrInfinity(await sandboxNumber(args[1], options.budget, options.context));
|
|
144246
|
+
const first = start < 0 ? Math.max(length + start, 0) : Math.min(start, length);
|
|
144247
|
+
const final = end < 0 ? Math.max(length + end, 0) : Math.min(end, length);
|
|
144248
|
+
const count = Math.max(final - first, 0);
|
|
144249
|
+
options.budget.allocateArrayLength(count);
|
|
144250
|
+
const result = new Array(count);
|
|
144251
|
+
for (let index = 0; index < count; index += 1) {
|
|
144252
|
+
options.budget.visitNode();
|
|
144253
|
+
if (first + index in value) result[index] = value[first + index];
|
|
144254
|
+
}
|
|
144255
|
+
return budgetProducedValue(result, options.budget);
|
|
144256
|
+
}
|
|
144200
144257
|
case "concat":
|
|
144201
144258
|
return budgetProducedValue(
|
|
144202
144259
|
Reflect.apply(Array.prototype.concat, value, [...args]),
|
|
@@ -144223,7 +144280,7 @@ async function callArrayMethodUnlocked(value, methodName, args, options, stack)
|
|
|
144223
144280
|
);
|
|
144224
144281
|
case "sort":
|
|
144225
144282
|
if (args[0] === void 0) {
|
|
144226
|
-
|
|
144283
|
+
Reflect.apply(Array.prototype.sort, value, []);
|
|
144227
144284
|
budgetProducedValue(value, options.budget);
|
|
144228
144285
|
return value;
|
|
144229
144286
|
}
|
|
@@ -144231,11 +144288,17 @@ async function callArrayMethodUnlocked(value, methodName, args, options, stack)
|
|
|
144231
144288
|
budgetProducedValue(value, options.budget);
|
|
144232
144289
|
return value;
|
|
144233
144290
|
case "reverse":
|
|
144234
|
-
|
|
144291
|
+
Reflect.apply(Array.prototype.reverse, value, []);
|
|
144235
144292
|
budgetProducedValue(value, options.budget);
|
|
144236
144293
|
return value;
|
|
144237
144294
|
case "toSorted": {
|
|
144238
|
-
const
|
|
144295
|
+
const length = value.length;
|
|
144296
|
+
options.budget.allocateArrayLength(length);
|
|
144297
|
+
const result = new Array(length);
|
|
144298
|
+
for (let index = 0; index < length; index += 1) {
|
|
144299
|
+
options.budget.visitNode();
|
|
144300
|
+
result[index] = value[index];
|
|
144301
|
+
}
|
|
144239
144302
|
if (args[0] === void 0) {
|
|
144240
144303
|
result.sort();
|
|
144241
144304
|
} else {
|
|
@@ -144244,13 +144307,29 @@ async function callArrayMethodUnlocked(value, methodName, args, options, stack)
|
|
|
144244
144307
|
return budgetProducedValue(result, options.budget);
|
|
144245
144308
|
}
|
|
144246
144309
|
case "toReversed": {
|
|
144247
|
-
const
|
|
144248
|
-
|
|
144310
|
+
const length = value.length;
|
|
144311
|
+
options.budget.allocateArrayLength(length);
|
|
144312
|
+
const result = new Array(length);
|
|
144313
|
+
for (let index = 0; index < length; index += 1) {
|
|
144314
|
+
options.budget.visitNode();
|
|
144315
|
+
result[index] = value[length - index - 1];
|
|
144316
|
+
}
|
|
144249
144317
|
return budgetProducedValue(result, options.budget);
|
|
144250
144318
|
}
|
|
144251
144319
|
case "toSpliced": {
|
|
144252
|
-
const
|
|
144253
|
-
|
|
144320
|
+
const length = value.length;
|
|
144321
|
+
const start = toIntegerOrInfinity(await sandboxNumber(args[0], options.budget, options.context));
|
|
144322
|
+
const first = start < 0 ? Math.max(length + start, 0) : Math.min(start, length);
|
|
144323
|
+
const inserted = Math.max(args.length - 2, 0);
|
|
144324
|
+
const deleted = args.length === 0 ? 0 : args.length === 1 ? length - first : Math.min(Math.max(toIntegerOrInfinity(await sandboxNumber(args[1], options.budget, options.context)), 0), length - first);
|
|
144325
|
+
const resultLength = length + inserted - deleted;
|
|
144326
|
+
if (resultLength > Number.MAX_SAFE_INTEGER) throw new TypeError("Array-like length exceeds the safe integer limit.");
|
|
144327
|
+
options.budget.allocateArrayLength(resultLength);
|
|
144328
|
+
const result = new Array(resultLength);
|
|
144329
|
+
for (let index = 0; index < resultLength; index += 1) {
|
|
144330
|
+
options.budget.visitNode();
|
|
144331
|
+
result[index] = index < first ? value[index] : index < first + inserted ? args[index - first + 2] : value[index - inserted + deleted];
|
|
144332
|
+
}
|
|
144254
144333
|
return budgetProducedValue(result, options.budget);
|
|
144255
144334
|
}
|
|
144256
144335
|
case "with": {
|
|
@@ -144264,39 +144343,42 @@ async function callArrayMethodUnlocked(value, methodName, args, options, stack)
|
|
|
144264
144343
|
const result = [];
|
|
144265
144344
|
for (let position = 0; position < length; position += 1) {
|
|
144266
144345
|
options.budget.visitNode();
|
|
144267
|
-
result[position] = position === actualIndex ? args[1] : Object.hasOwn(value, position) ? value[position]
|
|
144346
|
+
result[position] = position === actualIndex ? args[1] : Array.isArray(value) && !Object.hasOwn(value, position) ? void 0 : value[position];
|
|
144268
144347
|
}
|
|
144269
144348
|
return budgetProducedValue(result, options.budget);
|
|
144270
144349
|
}
|
|
144271
144350
|
case "push": {
|
|
144272
|
-
appendArrayValues(value, args);
|
|
144273
|
-
const nextLength = value.length;
|
|
144351
|
+
const nextLength = appendArrayValues(value, args);
|
|
144274
144352
|
budgetProducedValue(value, options.budget);
|
|
144275
144353
|
return nextLength;
|
|
144276
144354
|
}
|
|
144277
144355
|
case "pop":
|
|
144278
|
-
return budgetProducedValue(
|
|
144356
|
+
return budgetProducedValue(Reflect.apply(Array.prototype.pop, value, []), options.budget);
|
|
144279
144357
|
case "shift":
|
|
144280
|
-
return budgetProducedValue(
|
|
144358
|
+
return budgetProducedValue(Reflect.apply(Array.prototype.shift, value, []), options.budget);
|
|
144281
144359
|
case "unshift": {
|
|
144282
|
-
prependArrayValues(value, args);
|
|
144283
|
-
const nextLength = value.length;
|
|
144360
|
+
const nextLength = prependArrayValues(value, args);
|
|
144284
144361
|
budgetProducedValue(value, options.budget);
|
|
144285
144362
|
return nextLength;
|
|
144286
144363
|
}
|
|
144287
144364
|
}
|
|
144288
144365
|
}
|
|
144289
144366
|
function appendArrayValues(target, values) {
|
|
144367
|
+
let length = target.length;
|
|
144368
|
+
if (length + values.length > Number.MAX_SAFE_INTEGER) throw new TypeError("Array-like length exceeds the safe integer limit.");
|
|
144290
144369
|
for (const value of values) {
|
|
144291
|
-
target
|
|
144370
|
+
target[length++] = value;
|
|
144292
144371
|
}
|
|
144372
|
+
target.length = length;
|
|
144373
|
+
return length;
|
|
144293
144374
|
}
|
|
144294
144375
|
function prependArrayValues(target, values) {
|
|
144295
144376
|
const originalLength = target.length;
|
|
144296
|
-
|
|
144297
|
-
|
|
144377
|
+
const length = originalLength + values.length;
|
|
144378
|
+
if (length > Number.MAX_SAFE_INTEGER) throw new TypeError("Array-like length exceeds the safe integer limit.");
|
|
144379
|
+
for (let index = values.length === 0 ? -1 : originalLength - 1; index >= 0; index -= 1) {
|
|
144298
144380
|
const targetIndex = index + values.length;
|
|
144299
|
-
if (
|
|
144381
|
+
if (index in target) {
|
|
144300
144382
|
target[targetIndex] = target[index];
|
|
144301
144383
|
} else {
|
|
144302
144384
|
delete target[targetIndex];
|
|
@@ -144305,6 +144387,8 @@ function prependArrayValues(target, values) {
|
|
|
144305
144387
|
for (let index = 0; index < values.length; index += 1) {
|
|
144306
144388
|
target[index] = values[index];
|
|
144307
144389
|
}
|
|
144390
|
+
target.length = length;
|
|
144391
|
+
return length;
|
|
144308
144392
|
}
|
|
144309
144393
|
function isCallbackArrayMethod(methodName) {
|
|
144310
144394
|
return methodName === "map" || methodName === "filter" || methodName === "find" || methodName === "findIndex" || methodName === "findLast" || methodName === "findLastIndex" || methodName === "some" || methodName === "every" || methodName === "reduce" || methodName === "reduceRight" || methodName === "forEach" || methodName === "flatMap" || methodName === "sort";
|
|
@@ -144320,6 +144404,7 @@ function getRequiredCallback(methodName, value) {
|
|
|
144320
144404
|
}
|
|
144321
144405
|
async function mapArray(value, callback, options, stack, thisValue) {
|
|
144322
144406
|
const length = value.length;
|
|
144407
|
+
options.budget.allocateArrayLength(length);
|
|
144323
144408
|
const result = new Array(length);
|
|
144324
144409
|
options.budget.setRetainedValues(result, () => [result]);
|
|
144325
144410
|
try {
|
|
@@ -144465,7 +144550,7 @@ async function reduceFromLeft(value, callback, accumulator, startIndex, length,
|
|
|
144465
144550
|
if (!(index in value)) {
|
|
144466
144551
|
continue;
|
|
144467
144552
|
}
|
|
144468
|
-
current = await options.callClosure(callback, [current, value[index], index, value], stack);
|
|
144553
|
+
current = await options.callClosure(callback, [current, value[index], index, arrayLikeSources.get(value) ?? value], stack);
|
|
144469
144554
|
}
|
|
144470
144555
|
return current;
|
|
144471
144556
|
} finally {
|
|
@@ -144482,7 +144567,7 @@ async function reduceFromRight(value, callback, accumulator, startIndex, length,
|
|
|
144482
144567
|
if (!(index in value)) {
|
|
144483
144568
|
continue;
|
|
144484
144569
|
}
|
|
144485
|
-
current = await options.callClosure(callback, [current, value[index], index, value], stack);
|
|
144570
|
+
current = await options.callClosure(callback, [current, value[index], index, arrayLikeSources.get(value) ?? value], stack);
|
|
144486
144571
|
}
|
|
144487
144572
|
return current;
|
|
144488
144573
|
} finally {
|
|
@@ -144605,7 +144690,7 @@ async function compareEntries(left, right, comparator, options, stack) {
|
|
|
144605
144690
|
return Number.isNaN(result) ? 0 : result;
|
|
144606
144691
|
}
|
|
144607
144692
|
async function callArrayCallback(callback, value, index, array, options, stack, thisValue) {
|
|
144608
|
-
return options.callClosure(callback, [value, index, array], stack, thisValue);
|
|
144693
|
+
return options.callClosure(callback, [value, index, arrayLikeSources.get(array) ?? array], stack, thisValue);
|
|
144609
144694
|
}
|
|
144610
144695
|
function findNextDefinedIndex(value, startIndex, direction, length, budget) {
|
|
144611
144696
|
for (let index = startIndex; direction > 0 ? index < length : index >= 0; index += direction) {
|
|
@@ -144617,6 +144702,7 @@ function findNextDefinedIndex(value, startIndex, direction, length, budget) {
|
|
|
144617
144702
|
return -1;
|
|
144618
144703
|
}
|
|
144619
144704
|
function budgetProducedValue(value, budget) {
|
|
144705
|
+
if (typeof value === "object" && value !== null) value = arrayLikeSources.get(value) ?? value;
|
|
144620
144706
|
allocateProducedValue(value, budget, /* @__PURE__ */ new WeakSet());
|
|
144621
144707
|
return value;
|
|
144622
144708
|
}
|
|
@@ -144680,12 +144766,15 @@ function toIntegerOrInfinity(value) {
|
|
|
144680
144766
|
}
|
|
144681
144767
|
return Math.trunc(number);
|
|
144682
144768
|
}
|
|
144683
|
-
var activeArrayCallbacks, arrayMethodNames;
|
|
144769
|
+
var arrayLikeSources, activeArrayCallbacks, arrayMethodNames;
|
|
144684
144770
|
var init_array = __esm({
|
|
144685
144771
|
"packages/safe-js/src/interp/methods/array.ts"() {
|
|
144686
144772
|
"use strict";
|
|
144687
144773
|
init_values();
|
|
144688
144774
|
init_running_state();
|
|
144775
|
+
init_object_model();
|
|
144776
|
+
init_string_coercion();
|
|
144777
|
+
arrayLikeSources = /* @__PURE__ */ new WeakMap();
|
|
144689
144778
|
activeArrayCallbacks = /* @__PURE__ */ new WeakMap();
|
|
144690
144779
|
arrayMethodNames = /* @__PURE__ */ new Set([
|
|
144691
144780
|
"map",
|
|
@@ -144967,68 +145056,48 @@ function getNumberMember(property, budget) {
|
|
|
144967
145056
|
return createSandboxClosure({
|
|
144968
145057
|
sandbox: true,
|
|
144969
145058
|
name: `Number#${property}`,
|
|
144970
|
-
call: (args, context) => callNumberMethod(context?.thisValue, property, args, budget)
|
|
145059
|
+
call: (args, context) => callNumberMethod(context?.thisValue, property, args, budget, context)
|
|
144971
145060
|
});
|
|
144972
145061
|
}
|
|
144973
145062
|
function isNumberMethodName(property) {
|
|
144974
145063
|
return typeof property === "string" && numberMethodNames.has(property);
|
|
144975
145064
|
}
|
|
144976
|
-
function callNumberMethod(value, methodName, args, budget) {
|
|
145065
|
+
function callNumberMethod(value, methodName, args, budget, context) {
|
|
144977
145066
|
if (typeof value !== "number") {
|
|
144978
145067
|
throw new TypeError(`Number#${methodName} requires a number receiver.`);
|
|
144979
145068
|
}
|
|
144980
|
-
|
|
144981
|
-
|
|
144982
|
-
|
|
144983
|
-
switch (methodName) {
|
|
144984
|
-
case "toString":
|
|
144985
|
-
return value.toString(asValidatedRadix(args[0]));
|
|
144986
|
-
case "toExponential":
|
|
144987
|
-
return args[0] === void 0 ? value.toExponential() : value.toExponential(asValidatedFractionDigits(args[0], methodName));
|
|
144988
|
-
case "toFixed":
|
|
144989
|
-
return value.toFixed(asValidatedFractionDigits(args[0], methodName));
|
|
144990
|
-
case "toPrecision":
|
|
144991
|
-
return args[0] === void 0 ? value.toPrecision() : value.toPrecision(asValidatedPrecision(args[0]));
|
|
145069
|
+
const argument = args[0];
|
|
145070
|
+
if (argument !== null && typeof argument === "object") {
|
|
145071
|
+
return formatObjectArgument(value, methodName, argument, budget, context);
|
|
144992
145072
|
}
|
|
145073
|
+
return formatNumber3(value, methodName, argument === void 0 ? void 0 : Number(argument), budget);
|
|
144993
145074
|
}
|
|
144994
|
-
function
|
|
144995
|
-
|
|
144996
|
-
|
|
144997
|
-
|
|
144998
|
-
|
|
144999
|
-
|
|
145000
|
-
|
|
145001
|
-
|
|
145002
|
-
return radix;
|
|
145003
|
-
}
|
|
145004
|
-
function asValidatedFractionDigits(value, methodName) {
|
|
145005
|
-
const digits = toIntegerOrInfinity2(value);
|
|
145006
|
-
if (digits < 0 || digits > 100) {
|
|
145007
|
-
throw new RangeError(`Number#${methodName} digits must be between 0 and 100.`);
|
|
145008
|
-
}
|
|
145009
|
-
return digits;
|
|
145010
|
-
}
|
|
145011
|
-
function asValidatedPrecision(value) {
|
|
145012
|
-
const precision = toIntegerOrInfinity2(value);
|
|
145013
|
-
if (precision < 1 || precision > 100) {
|
|
145014
|
-
throw new RangeError("Number#toPrecision precision must be between 1 and 100.");
|
|
145075
|
+
async function formatObjectArgument(value, methodName, argument, budget, context) {
|
|
145076
|
+
const retainedArgument = {};
|
|
145077
|
+
budget.setRetainedValues(retainedArgument, () => [argument]);
|
|
145078
|
+
try {
|
|
145079
|
+
const number = await sandboxNumber(argument, budget, context);
|
|
145080
|
+
return formatNumber3(value, methodName, number, budget);
|
|
145081
|
+
} finally {
|
|
145082
|
+
budget.setRetainedValues(retainedArgument, void 0);
|
|
145015
145083
|
}
|
|
145016
|
-
return precision;
|
|
145017
145084
|
}
|
|
145018
|
-
function
|
|
145019
|
-
|
|
145020
|
-
|
|
145021
|
-
|
|
145022
|
-
}
|
|
145023
|
-
|
|
145024
|
-
|
|
145085
|
+
function formatNumber3(value, methodName, argument, budget) {
|
|
145086
|
+
let result;
|
|
145087
|
+
try {
|
|
145088
|
+
result = value[methodName](argument);
|
|
145089
|
+
} catch (error3) {
|
|
145090
|
+
if (!(error3 instanceof RangeError)) throw error3;
|
|
145091
|
+
const detail = methodName === "toString" ? "radix must be between 2 and 36." : methodName === "toPrecision" ? "precision must be between 1 and 100." : "digits must be between 0 and 100.";
|
|
145092
|
+
throw new RangeError(`Number#${methodName} ${detail}`);
|
|
145025
145093
|
}
|
|
145026
|
-
return
|
|
145094
|
+
return budget.allocateString(result);
|
|
145027
145095
|
}
|
|
145028
145096
|
var numberMethodNames;
|
|
145029
145097
|
var init_number = __esm({
|
|
145030
145098
|
"packages/safe-js/src/interp/methods/number.ts"() {
|
|
145031
145099
|
"use strict";
|
|
145100
|
+
init_string_coercion();
|
|
145032
145101
|
init_values();
|
|
145033
145102
|
numberMethodNames = /* @__PURE__ */ new Set([
|
|
145034
145103
|
"toExponential",
|
|
@@ -148909,7 +148978,7 @@ async function evaluateNumberMethodCall(node, target, methodName, context) {
|
|
|
148909
148978
|
return {
|
|
148910
148979
|
kind: "normal",
|
|
148911
148980
|
hasValue: true,
|
|
148912
|
-
value: callNumberMethod(target, methodName, args.value, context.budget)
|
|
148981
|
+
value: await callNumberMethod(target, methodName, args.value, context.budget, createCoercionContext(context))
|
|
148913
148982
|
};
|
|
148914
148983
|
} catch (error3) {
|
|
148915
148984
|
if (isFatalSandboxError(error3)) {
|
|
@@ -148921,6 +148990,10 @@ async function evaluateNumberMethodCall(node, target, methodName, context) {
|
|
|
148921
148990
|
function createArrayMethodOptions(context) {
|
|
148922
148991
|
return {
|
|
148923
148992
|
budget: context.budget,
|
|
148993
|
+
context: createCoercionContext(context),
|
|
148994
|
+
hasProperty: (value, property) => hasSandboxProperty(value, property, context),
|
|
148995
|
+
setProperty: (value, property, entry) => setSandboxProperty(value, property, entry, context.budget),
|
|
148996
|
+
deleteProperty: deleteSandboxProperty,
|
|
148924
148997
|
callClosure: (closure, args, stack, thisValue) => invokeSandboxClosure(closure, args, context, stack, void 0, thisValue)
|
|
148925
148998
|
};
|
|
148926
148999
|
}
|