@poe-platform/safe-js 0.1.253 → 0.1.255
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-F46UKJYT.js → chunk-PRWJXI5K.js} +86 -3
- package/dist/safe-js/chunks/{chunk-F46UKJYT.js.map → chunk-PRWJXI5K.js.map} +4 -4
- package/dist/safe-js/chunks/{chunk-FTO62YAZ.js → chunk-X5HPFLQX.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-FTO62YAZ.js.map → chunk-X5HPFLQX.js.map} +0 -0
|
@@ -22103,6 +22103,76 @@ function defineDataProperty2(target, key, value) {
|
|
|
22103
22103
|
});
|
|
22104
22104
|
}
|
|
22105
22105
|
|
|
22106
|
+
// packages/safe-js/src/interp/globals/math-sum-precise.ts
|
|
22107
|
+
async function sumPrecise(source, budget, context) {
|
|
22108
|
+
let iterator;
|
|
22109
|
+
let current;
|
|
22110
|
+
let recordValue;
|
|
22111
|
+
let sum = 0n;
|
|
22112
|
+
let sumSize = 1;
|
|
22113
|
+
let special;
|
|
22114
|
+
let minusZero = true;
|
|
22115
|
+
let count = 0;
|
|
22116
|
+
const storage = new DataView(new ArrayBuffer(8));
|
|
22117
|
+
const checkData = createDataCheckpoint(budget, context);
|
|
22118
|
+
const release = retainValues(budget, () => [source, iterator?.retainedValue, recordValue, current, sum]);
|
|
22119
|
+
try {
|
|
22120
|
+
if (source === void 0 || source === null) throw new TypeError("Math.sumPrecise requires an iterable.");
|
|
22121
|
+
iterator = context === void 0 ? getSandboxIterator(source, budget) : await acquireSandboxIterator(source, budget, context);
|
|
22122
|
+
if (iterator === void 0) throw new TypeError("Math.sumPrecise requires an iterable.");
|
|
22123
|
+
checkData(source, 0, true);
|
|
22124
|
+
while (true) {
|
|
22125
|
+
budget.visitNode();
|
|
22126
|
+
const next = iterator.next();
|
|
22127
|
+
const result = iterator.asynchronous || iterator.generator ? await next : next;
|
|
22128
|
+
if (typeof result !== "object" && typeof result !== "function" || result === null)
|
|
22129
|
+
throw new TypeError("Iterator result must be an object.");
|
|
22130
|
+
recordValue = result;
|
|
22131
|
+
const record3 = result;
|
|
22132
|
+
if ((await readIteratorResult(iterator, record3, "done")).value) break;
|
|
22133
|
+
current = (await readIteratorResult(iterator, record3, "value")).value;
|
|
22134
|
+
if (count >= Number.MAX_SAFE_INTEGER || typeof current !== "number") {
|
|
22135
|
+
const error = count >= Number.MAX_SAFE_INTEGER ? new RangeError("Math.sumPrecise received too many elements.") : new TypeError("Math.sumPrecise requires number elements.");
|
|
22136
|
+
await closeIterator(iterator, true);
|
|
22137
|
+
throw error;
|
|
22138
|
+
}
|
|
22139
|
+
count++;
|
|
22140
|
+
if (!Object.is(current, -0)) minusZero = false;
|
|
22141
|
+
if (Number.isNaN(current)) special = NaN;
|
|
22142
|
+
else if (!Number.isFinite(current)) {
|
|
22143
|
+
special = special === void 0 || special === current ? current : NaN;
|
|
22144
|
+
} else if (special === void 0) {
|
|
22145
|
+
storage.setFloat64(0, current);
|
|
22146
|
+
const bits = storage.getBigUint64(0);
|
|
22147
|
+
const exponent = Number(bits >> 52n & 2047n);
|
|
22148
|
+
const fraction = bits & (1n << 52n) - 1n;
|
|
22149
|
+
const significand = exponent === 0 ? fraction : 1n << 52n | fraction;
|
|
22150
|
+
const units = significand << BigInt(Math.max(0, exponent - 1));
|
|
22151
|
+
sum += bits >> 63n ? -units : units;
|
|
22152
|
+
}
|
|
22153
|
+
current = void 0;
|
|
22154
|
+
recordValue = void 0;
|
|
22155
|
+
const size = sum.toString(16).length;
|
|
22156
|
+
checkData(source, Math.max(0, size - sumSize));
|
|
22157
|
+
sumSize = size;
|
|
22158
|
+
}
|
|
22159
|
+
if (special !== void 0) return special;
|
|
22160
|
+
if (minusZero) return -0;
|
|
22161
|
+
const sign = sum < 0n ? -1 : 1;
|
|
22162
|
+
if (sum < 0n) sum = -sum;
|
|
22163
|
+
const shift = Math.max(0, sum.toString(2).length - 53);
|
|
22164
|
+
let rounded = sum >> BigInt(shift);
|
|
22165
|
+
if (shift > 0) {
|
|
22166
|
+
const remainder = sum - (rounded << BigInt(shift));
|
|
22167
|
+
const half = 1n << BigInt(shift - 1);
|
|
22168
|
+
if (remainder > half || remainder === half && (rounded & 1n) === 1n) rounded++;
|
|
22169
|
+
}
|
|
22170
|
+
return sign * Number(rounded) * 2 ** (shift - 1074);
|
|
22171
|
+
} finally {
|
|
22172
|
+
release();
|
|
22173
|
+
}
|
|
22174
|
+
}
|
|
22175
|
+
|
|
22106
22176
|
// packages/safe-js/src/interp/globals/math.ts
|
|
22107
22177
|
var mathMethods = {
|
|
22108
22178
|
abs: Math.abs,
|
|
@@ -22174,12 +22244,21 @@ function createMathGlobals(options = {}) {
|
|
|
22174
22244
|
PI: Math.PI,
|
|
22175
22245
|
SQRT1_2: Math.SQRT1_2,
|
|
22176
22246
|
SQRT2: Math.SQRT2,
|
|
22177
|
-
random: createSandboxClosure({ sandbox: true, call: () => random(), name: "random" })
|
|
22247
|
+
random: createSandboxClosure({ sandbox: true, guest: true, call: () => random(), name: "random", length: 0 }),
|
|
22248
|
+
sumPrecise: createSandboxClosure({
|
|
22249
|
+
sandbox: true,
|
|
22250
|
+
guest: true,
|
|
22251
|
+
name: "sumPrecise",
|
|
22252
|
+
length: 1,
|
|
22253
|
+
call: ([source], context) => sumPrecise(source, budget, context)
|
|
22254
|
+
})
|
|
22178
22255
|
};
|
|
22179
22256
|
for (const [name, method] of Object.entries(mathMethods)) {
|
|
22180
22257
|
const variadic = method === Math.max || method === Math.min || method === Math.hypot;
|
|
22181
22258
|
mathObject[name] = createSandboxClosure({
|
|
22182
22259
|
sandbox: true,
|
|
22260
|
+
guest: true,
|
|
22261
|
+
length: method.length,
|
|
22183
22262
|
call: (args, context) => callNumericMethod(method, args, variadic, budget, context),
|
|
22184
22263
|
name
|
|
22185
22264
|
});
|
|
@@ -22193,6 +22272,11 @@ function createMathGlobals(options = {}) {
|
|
|
22193
22272
|
});
|
|
22194
22273
|
}
|
|
22195
22274
|
Object.defineProperty(mathObject, Symbol.toStringTag, { value: "Math", configurable: true });
|
|
22275
|
+
registerBuiltinIdentities(budget, { Math: mathObject });
|
|
22276
|
+
for (const descriptor of Object.values(Object.getOwnPropertyDescriptors(mathObject))) {
|
|
22277
|
+
if (isSandboxClosure(descriptor.value)) registerIntrinsicFunction(budget, descriptor.value);
|
|
22278
|
+
}
|
|
22279
|
+
registerIntrinsicObject(budget, mathObject);
|
|
22196
22280
|
return {
|
|
22197
22281
|
Infinity: Infinity,
|
|
22198
22282
|
Math: mathObject,
|
|
@@ -22897,7 +22981,6 @@ function createBuiltinBindings(options) {
|
|
|
22897
22981
|
...createRegexGlobals(options)
|
|
22898
22982
|
};
|
|
22899
22983
|
registerBuiltinIdentities(options.budget, bindings);
|
|
22900
|
-
registerIntrinsicObject(options.budget, bindings.Math);
|
|
22901
22984
|
return bindings;
|
|
22902
22985
|
}
|
|
22903
22986
|
|
|
@@ -39614,4 +39697,4 @@ export {
|
|
|
39614
39697
|
FileSnapshotBackend,
|
|
39615
39698
|
run
|
|
39616
39699
|
};
|
|
39617
|
-
//# sourceMappingURL=chunk-
|
|
39700
|
+
//# sourceMappingURL=chunk-PRWJXI5K.js.map
|