poe-code 14.0.83 → 14.0.84
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 +588 -93
- package/dist/index.js.map +4 -4
- package/dist/metafile.json +1 -1
- package/package.json +1 -1
- package/packages/safe-js/dist/chunks/{chunk-37V6Q4K3.js → chunk-2EZQJQ2C.js} +2 -2
- package/packages/safe-js/dist/chunks/{chunk-PT7PBLVT.js → chunk-CYVI4ZUK.js} +536 -85
- package/packages/safe-js/dist/chunks/chunk-CYVI4ZUK.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/array-buffer.d.ts +12 -0
- package/packages/safe-js/dist/interp/array-buffer.js +33 -0
- package/packages/safe-js/dist/interp/float32.d.ts +6 -1
- package/packages/safe-js/dist/interp/float32.js +38 -10
- package/packages/safe-js/dist/interp/globals/array-buffer.d.ts +3 -0
- package/packages/safe-js/dist/interp/globals/array-buffer.js +112 -0
- package/packages/safe-js/dist/interp/globals/float32array.d.ts +1 -1
- package/packages/safe-js/dist/interp/globals/float32array.js +104 -15
- package/packages/safe-js/dist/interp/globals.d.ts +1 -0
- package/packages/safe-js/dist/interp/globals.js +2 -0
- package/packages/safe-js/dist/interp/host-bridge.d.ts +1 -0
- package/packages/safe-js/dist/interp/host-bridge.js +21 -0
- package/packages/safe-js/dist/interp/host-call.js +26 -2
- package/packages/safe-js/dist/interp/methods/array-iterator.js +1 -1
- package/packages/safe-js/dist/interp/object-model.js +6 -0
- package/packages/safe-js/dist/interp/values.d.ts +1 -1
- package/packages/safe-js/dist/interp/values.js +47 -5
- package/packages/safe-js/dist/lint/rules/known-globals.d.ts +1 -1
- package/packages/safe-js/dist/lint/rules/known-globals.js +1 -0
- package/packages/safe-js/dist/snapshot/array-buffer.d.ts +13 -0
- package/packages/safe-js/dist/snapshot/array-buffer.js +40 -0
- package/packages/safe-js/dist/snapshot/dump-format.js +25 -9
- package/packages/safe-js/dist/snapshot/float32array.d.ts +8 -1
- package/packages/safe-js/dist/snapshot/float32array.js +23 -5
- package/packages/safe-js/dist/snapshot/replay-data.d.ts +5 -0
- package/packages/safe-js/dist/snapshot/replay-data.js +35 -10
- package/packages/safe-js/dist/snapshot/restore.js +13 -1
- package/packages/safe-js/dist/snapshot/serialize.d.ts +5 -2
- package/packages/safe-js/dist/snapshot/serialize.js +20 -11
- package/packages/safe-js/dist/snapshot/validation.js +11 -1
- package/packages/safe-js/dist/chunks/chunk-PT7PBLVT.js.map +0 -7
- /package/packages/safe-js/dist/chunks/{chunk-37V6Q4K3.js.map → chunk-2EZQJQ2C.js.map} +0 -0
|
@@ -6843,26 +6843,83 @@ function readPendingHostCallPolicyModeValue(value) {
|
|
|
6843
6843
|
// packages/safe-js/src/interp/host-call.ts
|
|
6844
6844
|
import { createHash, randomUUID } from "node:crypto";
|
|
6845
6845
|
|
|
6846
|
+
// packages/safe-js/src/interp/array-buffer.ts
|
|
6847
|
+
import { types as types2 } from "node:util";
|
|
6848
|
+
var readLength = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength").get;
|
|
6849
|
+
var readResizable = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "resizable")?.get;
|
|
6850
|
+
var readMaxLength = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "maxByteLength")?.get;
|
|
6851
|
+
var arrayBufferPrototypes = /* @__PURE__ */ new WeakMap();
|
|
6852
|
+
function isSandboxArrayBuffer(value) {
|
|
6853
|
+
return types2.isArrayBuffer(value) && Object.getPrototypeOf(value) === ArrayBuffer.prototype;
|
|
6854
|
+
}
|
|
6855
|
+
function arrayBufferLength(value) {
|
|
6856
|
+
return Reflect.apply(readLength, value, []);
|
|
6857
|
+
}
|
|
6858
|
+
function arrayBufferOptions(value) {
|
|
6859
|
+
return readResizable !== void 0 && Reflect.apply(readResizable, value, []) ? { maxByteLength: Reflect.apply(readMaxLength, value, []) } : void 0;
|
|
6860
|
+
}
|
|
6861
|
+
function copyArrayBufferStorage(value, state) {
|
|
6862
|
+
state.float32Buffers ??= /* @__PURE__ */ new WeakMap();
|
|
6863
|
+
let copy = state.float32Buffers.get(value);
|
|
6864
|
+
if (copy === void 0) {
|
|
6865
|
+
copy = Reflect.construct(ArrayBuffer, [arrayBufferLength(value), arrayBufferOptions(value)]);
|
|
6866
|
+
new Uint8Array(copy).set(new Uint8Array(value));
|
|
6867
|
+
state.float32Buffers.set(value, copy);
|
|
6868
|
+
}
|
|
6869
|
+
return copy;
|
|
6870
|
+
}
|
|
6871
|
+
function arrayBufferDataProperties(value) {
|
|
6872
|
+
return Reflect.ownKeys(value).map((key) => {
|
|
6873
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
6874
|
+
if (!("value" in descriptor)) throw new TypeError("ArrayBuffer accessors cannot be copied as data.");
|
|
6875
|
+
return [key, descriptor];
|
|
6876
|
+
});
|
|
6877
|
+
}
|
|
6878
|
+
|
|
6846
6879
|
// packages/safe-js/src/interp/float32.ts
|
|
6847
6880
|
var typedArrayPrototype = Object.getPrototypeOf(Float32Array.prototype);
|
|
6848
|
-
var
|
|
6881
|
+
var readLength2 = Object.getOwnPropertyDescriptor(typedArrayPrototype, "length").get;
|
|
6849
6882
|
var readOffset = Object.getOwnPropertyDescriptor(typedArrayPrototype, "byteOffset").get;
|
|
6850
6883
|
var readBuffer = Object.getOwnPropertyDescriptor(typedArrayPrototype, "buffer").get;
|
|
6851
6884
|
var readTag = Object.getOwnPropertyDescriptor(typedArrayPrototype, Symbol.toStringTag).get;
|
|
6885
|
+
var createValuesIterator = Object.getOwnPropertyDescriptor(typedArrayPrototype, "values").value;
|
|
6852
6886
|
var bufferLength = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength").get;
|
|
6853
6887
|
var bufferResizable = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "resizable")?.get;
|
|
6888
|
+
var float32ViewLayouts = /* @__PURE__ */ new WeakMap();
|
|
6889
|
+
var resizeBuffer = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "resize").value;
|
|
6890
|
+
function restoreFloat32View(buffer, byteOffset, length, budget) {
|
|
6891
|
+
const originalLength = arrayBufferLength(buffer);
|
|
6892
|
+
const required = byteOffset + (length ?? 0) * 4;
|
|
6893
|
+
const options = arrayBufferOptions(buffer);
|
|
6894
|
+
const grow = required > originalLength;
|
|
6895
|
+
if (grow) {
|
|
6896
|
+
if (options === void 0 || required > options.maxByteLength)
|
|
6897
|
+
throw new RangeError("Float32Array layout exceeds backing capacity.");
|
|
6898
|
+
budget?.allocateArrayLength(Math.ceil(required / 4));
|
|
6899
|
+
budget?.provisionDataUsage(required - originalLength)();
|
|
6900
|
+
Reflect.apply(resizeBuffer, buffer, [required]);
|
|
6901
|
+
}
|
|
6902
|
+
try {
|
|
6903
|
+
const view = new Float32Array(buffer, byteOffset, length);
|
|
6904
|
+
if (options !== void 0) float32ViewLayouts.set(view, { byteOffset, ...length === void 0 ? {} : { length } });
|
|
6905
|
+
return view;
|
|
6906
|
+
} finally {
|
|
6907
|
+
if (grow) Reflect.apply(resizeBuffer, buffer, [originalLength]);
|
|
6908
|
+
}
|
|
6909
|
+
}
|
|
6854
6910
|
function isFloat32Array(value) {
|
|
6855
6911
|
return ArrayBuffer.isView(value) && Object.getPrototypeOf(value) === Float32Array.prototype && Reflect.apply(readTag, value, []) === "Float32Array";
|
|
6856
6912
|
}
|
|
6857
|
-
function float32Storage(value) {
|
|
6913
|
+
function float32Storage(value, requireInBounds = false) {
|
|
6914
|
+
if (requireInBounds) Reflect.apply(createValuesIterator, value, []);
|
|
6858
6915
|
const buffer = Reflect.apply(readBuffer, value, []);
|
|
6859
|
-
if (Object.getPrototypeOf(buffer) !== ArrayBuffer.prototype
|
|
6860
|
-
throw new TypeError("Float32Array requires a
|
|
6916
|
+
if (Object.getPrototypeOf(buffer) !== ArrayBuffer.prototype) {
|
|
6917
|
+
throw new TypeError("Float32Array requires a non-shared ArrayBuffer.");
|
|
6861
6918
|
}
|
|
6862
6919
|
return {
|
|
6863
6920
|
buffer,
|
|
6864
6921
|
byteOffset: Reflect.apply(readOffset, value, []),
|
|
6865
|
-
length: Reflect.apply(
|
|
6922
|
+
length: Reflect.apply(readLength2, value, []),
|
|
6866
6923
|
byteLength: Reflect.apply(bufferLength, buffer, [])
|
|
6867
6924
|
};
|
|
6868
6925
|
}
|
|
@@ -6903,18 +6960,17 @@ function checkFloat32Allocation(length, budget) {
|
|
|
6903
6960
|
}
|
|
6904
6961
|
function copyFloat32Storage(value, state) {
|
|
6905
6962
|
const storage = float32Storage(value);
|
|
6906
|
-
|
|
6907
|
-
|
|
6908
|
-
|
|
6909
|
-
|
|
6910
|
-
|
|
6911
|
-
state.float32Buffers.set(storage.buffer, buffer);
|
|
6963
|
+
const buffer = copyArrayBufferStorage(storage.buffer, state);
|
|
6964
|
+
if (bufferResizable !== void 0 && Reflect.apply(bufferResizable, storage.buffer, [])) {
|
|
6965
|
+
const layout = float32ViewLayouts.get(value);
|
|
6966
|
+
if (layout === void 0) throw new TypeError("Resizable Float32Array copies require known view layout.");
|
|
6967
|
+
return restoreFloat32View(buffer, layout.byteOffset, layout.length);
|
|
6912
6968
|
}
|
|
6913
6969
|
return new Float32Array(buffer, storage.byteOffset, storage.length);
|
|
6914
6970
|
}
|
|
6915
6971
|
|
|
6916
6972
|
// packages/safe-js/src/interp/date.ts
|
|
6917
|
-
import { types as
|
|
6973
|
+
import { types as types3 } from "node:util";
|
|
6918
6974
|
var NativeDate = Date;
|
|
6919
6975
|
var readTime = NativeDate.prototype.getTime;
|
|
6920
6976
|
var writeTime = NativeDate.prototype.setTime;
|
|
@@ -6931,7 +6987,7 @@ function dateTime(value) {
|
|
|
6931
6987
|
return Reflect.apply(readTime, value, []);
|
|
6932
6988
|
}
|
|
6933
6989
|
function copyNativeDate(value) {
|
|
6934
|
-
if (!
|
|
6990
|
+
if (!types3.isDate(value)) return void 0;
|
|
6935
6991
|
if (Object.getPrototypeOf(value) !== NativeDate.prototype)
|
|
6936
6992
|
throw new TypeError("Date subclasses are not supported.");
|
|
6937
6993
|
return createSandboxDate(dateTime(value));
|
|
@@ -7366,7 +7422,7 @@ function copySandboxArgumentProperties(source, target, copyValue) {
|
|
|
7366
7422
|
}
|
|
7367
7423
|
|
|
7368
7424
|
// packages/safe-js/src/interp/boxed.ts
|
|
7369
|
-
import { types as
|
|
7425
|
+
import { types as types4 } from "node:util";
|
|
7370
7426
|
var boxes = /* @__PURE__ */ new WeakSet();
|
|
7371
7427
|
var numberValue = Number.prototype.valueOf;
|
|
7372
7428
|
var stringValue = String.prototype.valueOf;
|
|
@@ -7374,11 +7430,11 @@ var booleanValue = Boolean.prototype.valueOf;
|
|
|
7374
7430
|
var symbolValue = Symbol.prototype.valueOf;
|
|
7375
7431
|
var bigintValue = BigInt.prototype.valueOf;
|
|
7376
7432
|
function nativeBoxedValue(value) {
|
|
7377
|
-
if (
|
|
7378
|
-
if (
|
|
7379
|
-
if (
|
|
7380
|
-
if (
|
|
7381
|
-
if (
|
|
7433
|
+
if (types4.isNumberObject(value)) return Reflect.apply(numberValue, value, []);
|
|
7434
|
+
if (types4.isStringObject(value)) return Reflect.apply(stringValue, value, []);
|
|
7435
|
+
if (types4.isBooleanObject(value)) return Reflect.apply(booleanValue, value, []);
|
|
7436
|
+
if (types4.isSymbolObject(value)) return Reflect.apply(symbolValue, value, []);
|
|
7437
|
+
if (types4.isBigIntObject(value)) return Reflect.apply(bigintValue, value, []);
|
|
7382
7438
|
return void 0;
|
|
7383
7439
|
}
|
|
7384
7440
|
function createSandboxBox(value) {
|
|
@@ -7557,7 +7613,7 @@ async function withRunResources(signal, execute) {
|
|
|
7557
7613
|
}
|
|
7558
7614
|
|
|
7559
7615
|
// packages/safe-js/src/interp/host-capabilities.ts
|
|
7560
|
-
import { types as
|
|
7616
|
+
import { types as types5 } from "node:util";
|
|
7561
7617
|
var MAX_INDEXED_LENGTH = 65536;
|
|
7562
7618
|
var MAX_NAMED_KEYS = 65536;
|
|
7563
7619
|
var MAX_NAMED_KEY_CODE_UNITS = 1048576;
|
|
@@ -7612,7 +7668,7 @@ function createLiveHostObject(definition, controller) {
|
|
|
7612
7668
|
for (const name of ["keys", "get", "set", "delete"]) {
|
|
7613
7669
|
const operation = data[name];
|
|
7614
7670
|
if (operation === void 0 && (name === "set" || name === "delete")) continue;
|
|
7615
|
-
if (typeof operation !== "function" ||
|
|
7671
|
+
if (typeof operation !== "function" || types5.isProxy(operation) || types5.isAsyncFunction(operation) || types5.isGeneratorFunction(operation))
|
|
7616
7672
|
throw new TypeError(`Named ${name} must be a synchronous non-generator function, not a proxy.`);
|
|
7617
7673
|
}
|
|
7618
7674
|
if (typeof data.maxKeys !== "number" || !Number.isInteger(data.maxKeys) || data.maxKeys < 1 || data.maxKeys > MAX_NAMED_KEYS)
|
|
@@ -7867,7 +7923,7 @@ function namedMutationKeys(state, key, create) {
|
|
|
7867
7923
|
function namedKeys(state) {
|
|
7868
7924
|
const named = state.named;
|
|
7869
7925
|
return state.controller.read(named.keys, (value) => {
|
|
7870
|
-
if (!Array.isArray(value) ||
|
|
7926
|
+
if (!Array.isArray(value) || types5.isProxy(value))
|
|
7871
7927
|
throw new TypeError("Named keys must be a dense own-data array of strings, not a proxy.");
|
|
7872
7928
|
const length = Object.getOwnPropertyDescriptor(value, "length").value;
|
|
7873
7929
|
if (length > named.maxKeys) throw new RangeError("Named keys exceed maxKeys.");
|
|
@@ -8132,11 +8188,13 @@ function releaseObjectPrototype(budget) {
|
|
|
8132
8188
|
generatorPrototypes.delete(budget);
|
|
8133
8189
|
errorPrototypes.delete(budget);
|
|
8134
8190
|
float32Prototypes.delete(budget);
|
|
8191
|
+
arrayBufferPrototypes.delete(budget);
|
|
8135
8192
|
initialRegexDescriptors.delete(budget);
|
|
8136
8193
|
intrinsicPrototypes.delete(budget);
|
|
8137
8194
|
}
|
|
8138
8195
|
function getSandboxPrototype(value, budget) {
|
|
8139
8196
|
if (prototypes.has(value)) return prototypes.get(value) ?? null;
|
|
8197
|
+
if (isSandboxArrayBuffer(value)) return budget === void 0 ? null : arrayBufferPrototypes.get(budget) ?? null;
|
|
8140
8198
|
if (isFloat32Array(value)) return budget === void 0 ? null : float32Prototypes.get(budget) ?? null;
|
|
8141
8199
|
const errorType = sandboxErrorTypes.get(value);
|
|
8142
8200
|
if (budget !== void 0 && errorType !== void 0) {
|
|
@@ -8247,6 +8305,7 @@ function setSandboxPrototype(value, prototype, budget) {
|
|
|
8247
8305
|
prototypes.set(value, prototype);
|
|
8248
8306
|
}
|
|
8249
8307
|
function isPrototypeRecord(value) {
|
|
8308
|
+
if (isSandboxArrayBuffer(value)) return true;
|
|
8250
8309
|
if (isFloat32Array(value)) return true;
|
|
8251
8310
|
if (isGuestClosure(value)) return true;
|
|
8252
8311
|
if (isGuestHostObject(value)) return false;
|
|
@@ -8511,7 +8570,7 @@ function restoreRegexProperties(value, data, decode) {
|
|
|
8511
8570
|
}
|
|
8512
8571
|
|
|
8513
8572
|
// packages/safe-js/src/snapshot/validation.ts
|
|
8514
|
-
import { types as
|
|
8573
|
+
import { types as types7 } from "node:util";
|
|
8515
8574
|
|
|
8516
8575
|
// packages/safe-js/src/interp/builtin-call.ts
|
|
8517
8576
|
async function invokeBuiltinClosure(closure, args, budget, context, thisValue, construct = false) {
|
|
@@ -10660,7 +10719,7 @@ async function nextArrayIterator(value, budget, context) {
|
|
|
10660
10719
|
const read = (key) => context?.getProperty !== void 0 ? context.getProperty(source, key) : readPropertyDescriptor((isFloat32Array(source) ? Object.getOwnPropertyDescriptor(source, key) : void 0) ?? getSandboxPropertyDescriptor(source, key, budget) ?? { value: void 0 }, source, context);
|
|
10661
10720
|
try {
|
|
10662
10721
|
budget.visitNode();
|
|
10663
|
-
const number = isFloat32Array(source) ? float32Storage(source).length : await sandboxNumber(await read("length"), budget, context);
|
|
10722
|
+
const number = isFloat32Array(source) ? float32Storage(source, true).length : await sandboxNumber(await read("length"), budget, context);
|
|
10664
10723
|
const length = Number.isNaN(number) || number <= 0 ? 0 : Math.min(Math.trunc(number), Number.MAX_SAFE_INTEGER);
|
|
10665
10724
|
if (index >= length) {
|
|
10666
10725
|
state.source = void 0;
|
|
@@ -10925,7 +10984,7 @@ function formatNumber(value, methodName, argument, budget) {
|
|
|
10925
10984
|
}
|
|
10926
10985
|
|
|
10927
10986
|
// packages/safe-js/src/interp/methods/string.ts
|
|
10928
|
-
import { types as
|
|
10987
|
+
import { types as types6 } from "node:util";
|
|
10929
10988
|
|
|
10930
10989
|
// packages/safe-js/src/interp/methods/string-locale.ts
|
|
10931
10990
|
var collatorOptions = [
|
|
@@ -11076,7 +11135,7 @@ function callStringMethod(value, methodName, args, budget, callClosure = async (
|
|
|
11076
11135
|
};
|
|
11077
11136
|
const symbol = methodName === "match" ? Symbol.match : methodName === "search" ? Symbol.search : methodName === "matchAll" ? Symbol.matchAll : methodName === "replace" || methodName === "replaceAll" ? Symbol.replace : methodName === "split" ? Symbol.split : void 0;
|
|
11078
11137
|
const pattern = args[0];
|
|
11079
|
-
if (symbol !== void 0 &&
|
|
11138
|
+
if (symbol !== void 0 && types6.isRegExp(pattern))
|
|
11080
11139
|
throw new TypeError(`String#${methodName} does not accept unbranded host RegExp values.`);
|
|
11081
11140
|
if (symbol === void 0 || pattern === null || pattern === void 0) return fallback();
|
|
11082
11141
|
const readProperty = (key) => context?.getProperty !== void 0 ? context.getProperty(pattern, key) : key === "flags" && isSandboxRegex(pattern) && getSandboxPropertyDescriptor(pattern, key, budget) === void 0 ? getRegexMember(pattern, key, budget, context) : getSandboxDataProperty(pattern, key, budget);
|
|
@@ -14557,6 +14616,31 @@ function createFloat32ArrayGlobal(budget, nativePrototype = false) {
|
|
|
14557
14616
|
const prototype = candidate !== null && typeof candidate === "object" ? candidate : float32Prototypes.get(budget);
|
|
14558
14617
|
const release = retainValues(budget, () => [prototype, ...args]);
|
|
14559
14618
|
try {
|
|
14619
|
+
if (isSandboxArrayBuffer(args[0])) {
|
|
14620
|
+
const buffer = args[0];
|
|
14621
|
+
const number = await sandboxNumber(args[1], budget, context);
|
|
14622
|
+
const offset = Number.isNaN(number) ? 0 : Math.trunc(number);
|
|
14623
|
+
if (!Number.isSafeInteger(offset) || offset < 0 || offset % 4 !== 0)
|
|
14624
|
+
throw new RangeError("Invalid Float32Array buffer offset.");
|
|
14625
|
+
const bytes = arrayBufferLength(buffer);
|
|
14626
|
+
let length;
|
|
14627
|
+
if (args[2] === void 0) {
|
|
14628
|
+
if (arrayBufferOptions(buffer) === void 0 && bytes % 4 !== 0 || offset > bytes)
|
|
14629
|
+
throw new RangeError("Invalid Float32Array buffer length.");
|
|
14630
|
+
length = Math.floor((bytes - offset) / 4);
|
|
14631
|
+
} else {
|
|
14632
|
+
const size = await sandboxNumber(args[2], budget, context);
|
|
14633
|
+
length = Number.isNaN(size) ? 0 : Math.trunc(size);
|
|
14634
|
+
if (!Number.isSafeInteger(length) || length < 0 || offset + length * 4 > arrayBufferLength(buffer))
|
|
14635
|
+
throw new RangeError("Invalid Float32Array view length.");
|
|
14636
|
+
}
|
|
14637
|
+
budget.allocateArrayLength(length);
|
|
14638
|
+
const result2 = new Float32Array(buffer, offset, args[2] === void 0 ? void 0 : length);
|
|
14639
|
+
if (arrayBufferOptions(buffer) !== void 0)
|
|
14640
|
+
float32ViewLayouts.set(result2, { byteOffset: offset, ...args[2] === void 0 ? {} : { length } });
|
|
14641
|
+
setSandboxPrototype(result2, prototype, budget);
|
|
14642
|
+
return result2;
|
|
14643
|
+
}
|
|
14560
14644
|
const result = args[0] !== null && typeof args[0] === "object" && !isFloat32Array(args[0]) ? await allocateFloat32Input(args[0], budget, context) : allocateFloat32Array(args[0], budget);
|
|
14561
14645
|
setSandboxPrototype(result, prototype, budget);
|
|
14562
14646
|
return result;
|
|
@@ -14771,7 +14855,19 @@ function createFloat32ArrayPrototypes(budget, constructor) {
|
|
|
14771
14855
|
setSandboxPrototype(prototype, shared);
|
|
14772
14856
|
setSandboxPrototype(shared, getSandboxPrototype(/* @__PURE__ */ Object.create(null), budget));
|
|
14773
14857
|
const getters = [];
|
|
14774
|
-
|
|
14858
|
+
const species = createSandboxClosure({
|
|
14859
|
+
guest: true,
|
|
14860
|
+
sandbox: true,
|
|
14861
|
+
name: "get [Symbol.species]",
|
|
14862
|
+
length: 0,
|
|
14863
|
+
call: (_args, context) => context?.thisValue
|
|
14864
|
+
});
|
|
14865
|
+
getters.push(species);
|
|
14866
|
+
Object.defineProperty(materializeFunctionProperties(typedArray), Symbol.species, {
|
|
14867
|
+
get: accessorAdapter(species, "get"),
|
|
14868
|
+
configurable: true
|
|
14869
|
+
});
|
|
14870
|
+
for (const key of ["length", "byteLength", "byteOffset", "buffer"]) {
|
|
14775
14871
|
const getter = createSandboxClosure({
|
|
14776
14872
|
guest: true,
|
|
14777
14873
|
sandbox: true,
|
|
@@ -14787,7 +14883,7 @@ function createFloat32ArrayPrototypes(budget, constructor) {
|
|
|
14787
14883
|
Object.defineProperty(shared, key, { get: accessorAdapter(getter, "get"), configurable: true });
|
|
14788
14884
|
}
|
|
14789
14885
|
for (const key of ["set", "slice", "subarray"])
|
|
14790
|
-
Object.defineProperty(shared, key, { value: getFloat32Member(new Float32Array(0), key, budget), writable: true, configurable: true });
|
|
14886
|
+
Object.defineProperty(shared, key, { value: getFloat32Member(new Float32Array(0), key, budget, constructor), writable: true, configurable: true });
|
|
14791
14887
|
const arrayPrototype = resolveIntrinsicIdentity(budget, '["Array","prototype"]');
|
|
14792
14888
|
Object.defineProperty(shared, "toString", { value: getSandboxDataProperty(arrayPrototype, "toString", budget), writable: true, configurable: true });
|
|
14793
14889
|
Object.defineProperty(shared, "join", {
|
|
@@ -14801,7 +14897,7 @@ function createFloat32ArrayPrototypes(budget, constructor) {
|
|
|
14801
14897
|
call: async (args, context) => {
|
|
14802
14898
|
if (!isFloat32Array(context?.thisValue)) throw new TypeError("TypedArray join requires a typed array receiver.");
|
|
14803
14899
|
const receiver = context.thisValue;
|
|
14804
|
-
const length = float32Storage(receiver).length;
|
|
14900
|
+
const length = float32Storage(receiver, true).length;
|
|
14805
14901
|
let separator = ",";
|
|
14806
14902
|
let text = "";
|
|
14807
14903
|
const release = retainValues(budget, () => [receiver, separator, text, ...args]);
|
|
@@ -14809,7 +14905,8 @@ function createFloat32ArrayPrototypes(budget, constructor) {
|
|
|
14809
14905
|
if (args[0] !== void 0) separator = await sandboxString(args[0], budget, context);
|
|
14810
14906
|
for (let index = 0; index < length; index++) {
|
|
14811
14907
|
budget.visitNode();
|
|
14812
|
-
|
|
14908
|
+
const value = receiver[index];
|
|
14909
|
+
text = budget.allocateString(text + (index === 0 ? "" : separator) + (value === void 0 ? "" : String(value)));
|
|
14813
14910
|
}
|
|
14814
14911
|
return text;
|
|
14815
14912
|
} finally {
|
|
@@ -14836,6 +14933,7 @@ function createFloat32ArrayPrototypes(budget, constructor) {
|
|
|
14836
14933
|
length: 0,
|
|
14837
14934
|
call: (args, context) => {
|
|
14838
14935
|
if (!isFloat32Array(context?.thisValue)) throw new TypeError(`TypedArray ${key} requires a typed array receiver.`);
|
|
14936
|
+
float32Storage(context.thisValue, true);
|
|
14839
14937
|
return invokeBuiltinClosure(method, args, budget, context, context.thisValue);
|
|
14840
14938
|
}
|
|
14841
14939
|
});
|
|
@@ -14853,7 +14951,7 @@ function createFloat32ArrayPrototypes(budget, constructor) {
|
|
|
14853
14951
|
function isFloat32ArrayConstructor(value) {
|
|
14854
14952
|
return typeof value === "object" && value !== null && constructors.has(value);
|
|
14855
14953
|
}
|
|
14856
|
-
function getFloat32Member(value, property, budget) {
|
|
14954
|
+
function getFloat32Member(value, property, budget, defaultConstructor) {
|
|
14857
14955
|
const key = String(property);
|
|
14858
14956
|
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
14859
14957
|
if (descriptor !== void 0) {
|
|
@@ -14876,7 +14974,7 @@ function getFloat32Member(value, property, budget) {
|
|
|
14876
14974
|
const receiver = context?.thisValue;
|
|
14877
14975
|
if (!isFloat32Array(receiver))
|
|
14878
14976
|
throw new TypeError(`Float32Array#${key} requires a Float32Array receiver.`);
|
|
14879
|
-
const storage2 = float32Storage(receiver);
|
|
14977
|
+
const storage2 = float32Storage(receiver, key === "slice");
|
|
14880
14978
|
const bridge = {
|
|
14881
14979
|
...context,
|
|
14882
14980
|
stack: context?.stack ?? [],
|
|
@@ -14897,16 +14995,17 @@ function getFloat32Member(value, property, budget) {
|
|
|
14897
14995
|
const number = await sandboxNumber(offsetValue, budget, bridge);
|
|
14898
14996
|
const offset = Number.isNaN(number) ? 0 : Math.trunc(number);
|
|
14899
14997
|
if (offset < 0) throw new RangeError("Float32Array#set offset is out of bounds.");
|
|
14998
|
+
const targetStorage = float32Storage(receiver, true);
|
|
14900
14999
|
if (source === null || source === void 0) throw new TypeError("Float32Array#set requires a non-null source.");
|
|
14901
15000
|
let length;
|
|
14902
|
-
if (isFloat32Array(source)) length = float32Storage(source).length;
|
|
15001
|
+
if (isFloat32Array(source)) length = float32Storage(source, true).length;
|
|
14903
15002
|
else {
|
|
14904
15003
|
sourceObject = typeof source === "object" ? source : createSandboxBox(source);
|
|
14905
15004
|
current = await bridge.getProperty(sourceObject, "length");
|
|
14906
15005
|
const size = await sandboxNumber(current, budget, bridge);
|
|
14907
15006
|
length = Number.isNaN(size) || size <= 0 ? 0 : Math.min(Math.trunc(size), Number.MAX_SAFE_INTEGER);
|
|
14908
15007
|
}
|
|
14909
|
-
if (offset + length >
|
|
15008
|
+
if (offset + length > targetStorage.length) throw new RangeError("Float32Array#set source is out of bounds.");
|
|
14910
15009
|
if (isFloat32Array(source)) Float32Array.prototype.set.call(receiver, source, offset);
|
|
14911
15010
|
else for (let index = 0; index < length; index++) {
|
|
14912
15011
|
budget.visitNode();
|
|
@@ -14920,18 +15019,62 @@ function getFloat32Member(value, property, budget) {
|
|
|
14920
15019
|
})();
|
|
14921
15020
|
}
|
|
14922
15021
|
return (async () => {
|
|
14923
|
-
|
|
15022
|
+
let candidate;
|
|
15023
|
+
let result;
|
|
15024
|
+
const release = retainValues(budget, () => [receiver, candidate, result, ...args]);
|
|
14924
15025
|
try {
|
|
14925
15026
|
const start = relativeIndex(await sandboxNumber(args[0], budget, bridge), storage2.length);
|
|
14926
15027
|
const end = args[1] === void 0 ? storage2.length : relativeIndex(await sandboxNumber(args[1], budget, bridge), storage2.length);
|
|
14927
15028
|
const length = Math.max(end - start, 0);
|
|
14928
|
-
|
|
14929
|
-
|
|
14930
|
-
|
|
14931
|
-
|
|
14932
|
-
|
|
14933
|
-
|
|
14934
|
-
|
|
15029
|
+
const layout = float32ViewLayouts.get(receiver);
|
|
15030
|
+
const offset = (layout?.byteOffset ?? storage2.byteOffset) + start * 4;
|
|
15031
|
+
const tracking = layout !== void 0 && layout.length === void 0 && args[1] === void 0;
|
|
15032
|
+
if (defaultConstructor !== void 0) {
|
|
15033
|
+
candidate = await bridge.getProperty(receiver, "constructor");
|
|
15034
|
+
if (candidate !== void 0) {
|
|
15035
|
+
if (candidate === null || typeof candidate !== "object")
|
|
15036
|
+
throw new TypeError("TypedArray constructor must be an object.");
|
|
15037
|
+
candidate = await bridge.getProperty(candidate, Symbol.species);
|
|
15038
|
+
if (candidate !== void 0 && candidate !== null && (!isSandboxClosure(candidate) || candidate.construct === void 0))
|
|
15039
|
+
throw new TypeError("TypedArray species must be a constructor.");
|
|
15040
|
+
}
|
|
15041
|
+
}
|
|
15042
|
+
if (candidate !== void 0 && candidate !== null && candidate !== defaultConstructor) {
|
|
15043
|
+
const values = key === "slice" ? [length] : [storage2.buffer, offset, tracking ? void 0 : length];
|
|
15044
|
+
result = await invokeBuiltinClosure(candidate, values, budget, bridge, void 0, true);
|
|
15045
|
+
if (!isFloat32Array(result)) throw new TypeError("TypedArray species must return typed storage.");
|
|
15046
|
+
const target = float32Storage(result, key === "slice");
|
|
15047
|
+
if (key === "slice" && target.length < length)
|
|
15048
|
+
throw new TypeError("TypedArray species returned insufficient storage.");
|
|
15049
|
+
}
|
|
15050
|
+
if (key === "subarray") {
|
|
15051
|
+
if (result === void 0) {
|
|
15052
|
+
result = new Float32Array(storage2.buffer, offset, tracking ? void 0 : length);
|
|
15053
|
+
if (arrayBufferOptions(storage2.buffer) !== void 0)
|
|
15054
|
+
float32ViewLayouts.set(result, { byteOffset: offset, ...tracking ? {} : { length } });
|
|
15055
|
+
}
|
|
15056
|
+
return result;
|
|
15057
|
+
}
|
|
15058
|
+
if (result === void 0) {
|
|
15059
|
+
checkFloat32Allocation(length, budget);
|
|
15060
|
+
result = new Float32Array(length);
|
|
15061
|
+
}
|
|
15062
|
+
if (!isFloat32Array(result)) throw new TypeError("TypedArray species must return typed storage.");
|
|
15063
|
+
if (length > 0) {
|
|
15064
|
+
const current = float32Storage(receiver, true);
|
|
15065
|
+
const target = float32Storage(result, true);
|
|
15066
|
+
const count = Math.min(length, Math.max(current.length - start, 0));
|
|
15067
|
+
if (count > 0) {
|
|
15068
|
+
const sourceBytes = new Uint8Array(current.buffer, current.byteOffset + start * 4, count * 4);
|
|
15069
|
+
const targetBytes = new Uint8Array(target.buffer, target.byteOffset, count * 4);
|
|
15070
|
+
if (current.buffer === target.buffer && targetBytes.byteOffset > sourceBytes.byteOffset && targetBytes.byteOffset < sourceBytes.byteOffset + sourceBytes.length) {
|
|
15071
|
+
for (let index = 0; index < sourceBytes.length; index++) {
|
|
15072
|
+
budget.visitNode();
|
|
15073
|
+
targetBytes[index] = sourceBytes[index];
|
|
15074
|
+
}
|
|
15075
|
+
} else targetBytes.set(sourceBytes);
|
|
15076
|
+
}
|
|
15077
|
+
}
|
|
14935
15078
|
return result;
|
|
14936
15079
|
} finally {
|
|
14937
15080
|
release();
|
|
@@ -21046,18 +21189,20 @@ function serializeArray(value, serializeValue) {
|
|
|
21046
21189
|
}
|
|
21047
21190
|
|
|
21048
21191
|
// packages/safe-js/src/snapshot/float32array.ts
|
|
21049
|
-
function
|
|
21192
|
+
function encodeFloat32Layout(value) {
|
|
21050
21193
|
const storage = float32Storage(value);
|
|
21051
|
-
|
|
21052
|
-
|
|
21194
|
+
if (arrayBufferOptions(storage.buffer) === void 0) return { byteOffset: storage.byteOffset, length: storage.length };
|
|
21195
|
+
const layout = float32ViewLayouts.get(value);
|
|
21196
|
+
if (layout === void 0) throw new TypeError("Resizable Float32Array snapshots require known view layout.");
|
|
21053
21197
|
return {
|
|
21054
|
-
|
|
21055
|
-
|
|
21056
|
-
length:
|
|
21057
|
-
...existing === void 0 ? { bytes: Array.from(new Uint8Array(storage.buffer)) } : { buffer: reference(existing) }
|
|
21198
|
+
byteOffset: layout.byteOffset,
|
|
21199
|
+
length: layout.length ?? 0,
|
|
21200
|
+
...layout.length === void 0 ? { lengthTracking: true } : {}
|
|
21058
21201
|
};
|
|
21059
21202
|
}
|
|
21060
21203
|
function validateFloat32Storage(value) {
|
|
21204
|
+
if (Object.hasOwn(value, "lengthTracking") && (value.lengthTracking !== true || value.length !== 0 || Object.hasOwn(value, "bytes")))
|
|
21205
|
+
throw new TypeError("Invalid Float32Array length-tracking layout.");
|
|
21061
21206
|
if (!Number.isSafeInteger(value.length) || Number(value.length) < 0 || !Number.isSafeInteger(value.byteOffset) || Number(value.byteOffset) < 0 || Number(value.byteOffset) % 4 !== 0)
|
|
21062
21207
|
throw new TypeError("Invalid Float32Array view dimensions.");
|
|
21063
21208
|
if (Object.hasOwn(value, "bytes") === Object.hasOwn(value, "buffer"))
|
|
@@ -21067,7 +21212,7 @@ function validateFloat32Storage(value) {
|
|
|
21067
21212
|
throw new TypeError("Invalid Float32Array backing bytes.");
|
|
21068
21213
|
}
|
|
21069
21214
|
}
|
|
21070
|
-
function decodeFloat32Storage(value, resolve) {
|
|
21215
|
+
function decodeFloat32Storage(value, resolve, budget) {
|
|
21071
21216
|
validateFloat32Storage(value);
|
|
21072
21217
|
let buffer;
|
|
21073
21218
|
if (Array.isArray(value.bytes)) {
|
|
@@ -21075,10 +21220,50 @@ function decodeFloat32Storage(value, resolve) {
|
|
|
21075
21220
|
new Uint8Array(buffer).set(value.bytes);
|
|
21076
21221
|
} else {
|
|
21077
21222
|
const referenced = resolve(value.buffer);
|
|
21078
|
-
if (
|
|
21079
|
-
buffer = float32Storage(referenced).buffer;
|
|
21223
|
+
if (isSandboxArrayBuffer(referenced)) buffer = referenced;
|
|
21224
|
+
else if (isFloat32Array(referenced)) buffer = float32Storage(referenced).buffer;
|
|
21225
|
+
else throw new TypeError("Invalid Float32Array backing reference.");
|
|
21226
|
+
}
|
|
21227
|
+
if (value.lengthTracking === true && arrayBufferOptions(buffer) === void 0)
|
|
21228
|
+
throw new TypeError("Length-tracking layout requires resizable backing storage.");
|
|
21229
|
+
return restoreFloat32View(buffer, Number(value.byteOffset), value.lengthTracking === true ? void 0 : Number(value.length), budget);
|
|
21230
|
+
}
|
|
21231
|
+
|
|
21232
|
+
// packages/safe-js/src/snapshot/array-buffer.ts
|
|
21233
|
+
function captureArrayBufferState(value, encode) {
|
|
21234
|
+
return {
|
|
21235
|
+
properties: serializePropertyDescriptors(value, encode),
|
|
21236
|
+
...hasExplicitSandboxPrototype(value) ? { prototype: encode(getSandboxPrototype(value)) } : {}
|
|
21237
|
+
};
|
|
21238
|
+
}
|
|
21239
|
+
function encodeArrayBufferStorage(value, id, buffers, reference) {
|
|
21240
|
+
arrayBufferLength(value);
|
|
21241
|
+
const existing = buffers.get(value);
|
|
21242
|
+
if (existing === void 0) buffers.set(value, id);
|
|
21243
|
+
return { kind: "arraybuffer", ...existing === void 0 ? { bytes: Array.from(new Uint8Array(value)), ...arrayBufferOptions(value) } : { buffer: reference(existing) } };
|
|
21244
|
+
}
|
|
21245
|
+
function validateArrayBufferStorage(value) {
|
|
21246
|
+
if (Object.hasOwn(value, "bytes") === Object.hasOwn(value, "buffer"))
|
|
21247
|
+
throw new TypeError("ArrayBuffer requires one backing storage description.");
|
|
21248
|
+
if (Object.hasOwn(value, "bytes") && (!Array.isArray(value.bytes) || value.bytes.some((byte) => !Number.isInteger(byte) || byte < 0 || byte > 255)))
|
|
21249
|
+
throw new TypeError("Invalid ArrayBuffer bytes.");
|
|
21250
|
+
if (Object.hasOwn(value, "maxByteLength") && (!Array.isArray(value.bytes) || !Number.isSafeInteger(value.maxByteLength) || Number(value.maxByteLength) < value.bytes.length))
|
|
21251
|
+
throw new TypeError("Invalid ArrayBuffer maximum length.");
|
|
21252
|
+
}
|
|
21253
|
+
function decodeArrayBufferStorage(value, resolve) {
|
|
21254
|
+
validateArrayBufferStorage(value);
|
|
21255
|
+
if (Array.isArray(value.bytes)) {
|
|
21256
|
+
const buffer = Reflect.construct(ArrayBuffer, [
|
|
21257
|
+
value.bytes.length,
|
|
21258
|
+
Object.hasOwn(value, "maxByteLength") ? { maxByteLength: value.maxByteLength } : void 0
|
|
21259
|
+
]);
|
|
21260
|
+
new Uint8Array(buffer).set(value.bytes);
|
|
21261
|
+
return buffer;
|
|
21080
21262
|
}
|
|
21081
|
-
|
|
21263
|
+
const referenced = resolve(value.buffer);
|
|
21264
|
+
if (isSandboxArrayBuffer(referenced)) return referenced;
|
|
21265
|
+
if (isFloat32Array(referenced)) return float32Storage(referenced).buffer;
|
|
21266
|
+
throw new TypeError("Invalid ArrayBuffer backing reference.");
|
|
21082
21267
|
}
|
|
21083
21268
|
|
|
21084
21269
|
// packages/safe-js/src/snapshot/date-properties.ts
|
|
@@ -21209,7 +21394,7 @@ function serializeDumpValue(value, path, state) {
|
|
|
21209
21394
|
if (hasGuestObjectState(value) && !(state.trustedRunReplay && (isSandboxDate(value) || isSandboxPromise(value) || isPromiseResolvingFunction(value)))) {
|
|
21210
21395
|
throw new TypeError("Guest function properties and prototype links cannot be serialized.");
|
|
21211
21396
|
}
|
|
21212
|
-
if (isSandboxRegExpIterator(value) || isSandboxRegex(value) && hasCustomRegexProperties(value) || isSandboxBox(value) || isSandboxDate(value) || isFloat32Array(value)) return serializeHeapReference(value, path, state);
|
|
21397
|
+
if (isSandboxArrayBuffer(value) || isSandboxRegExpIterator(value) || isSandboxRegex(value) && hasCustomRegexProperties(value) || isSandboxBox(value) || isSandboxDate(value) || isFloat32Array(value)) return serializeHeapReference(value, path, state);
|
|
21213
21398
|
if (Array.isArray(value)) {
|
|
21214
21399
|
const reference2 = serializeHeapReference(value, path, state);
|
|
21215
21400
|
if (reference2 !== void 0) {
|
|
@@ -21281,11 +21466,21 @@ function serializeHeapReference(value, path, state) {
|
|
|
21281
21466
|
const serialized = serializeDumpValue(entry, `${path}.<date-property>`, state);
|
|
21282
21467
|
return serialized === SKIP_VALUE ? { kind: "undefined" } : serialized;
|
|
21283
21468
|
});
|
|
21469
|
+
} else if (isSandboxArrayBuffer(value)) {
|
|
21470
|
+
state.heap[String(id)] = {
|
|
21471
|
+
...encodeArrayBufferStorage(value, id, state.float32Buffers, (id2) => ({ kind: "ref", id: id2 })),
|
|
21472
|
+
state: captureArrayBufferState(value, (entry) => {
|
|
21473
|
+
const serialized = serializeDumpValue(entry, `${path}.<buffer>`, state);
|
|
21474
|
+
return serialized === SKIP_VALUE ? { kind: "undefined" } : serialized;
|
|
21475
|
+
})
|
|
21476
|
+
};
|
|
21284
21477
|
} else if (isFloat32Array(value)) {
|
|
21285
|
-
const
|
|
21286
|
-
|
|
21287
|
-
|
|
21288
|
-
|
|
21478
|
+
const backing = float32Storage(value);
|
|
21479
|
+
const storage = {
|
|
21480
|
+
kind: "float32array",
|
|
21481
|
+
...encodeFloat32Layout(value),
|
|
21482
|
+
buffer: serializeHeapReference(backing.buffer, `${path}.buffer`, state)
|
|
21483
|
+
};
|
|
21289
21484
|
const entries = /* @__PURE__ */ Object.create(null);
|
|
21290
21485
|
state.heap[String(id)] = { ...storage, entries };
|
|
21291
21486
|
for (const [key, descriptor] of float32DataProperties(value)) {
|
|
@@ -21351,7 +21546,7 @@ function indexHeapContainers(snapshot) {
|
|
|
21351
21546
|
const heapIds = /* @__PURE__ */ new Map();
|
|
21352
21547
|
let nextId = 1;
|
|
21353
21548
|
for (const [value, stat2] of stats.entries()) {
|
|
21354
|
-
if (stat2.count > 1 || stat2.forceHeap === true || guestValues.has(value) || stat2.cyclic || hasNullObjectPrototype(value) || ownSerializableSymbolKeys(value).length > 0 || isSandboxBox(value) || isSandboxRegExpIterator(value) || isSandboxRegex(value) && hasCustomRegexProperties(value) || isSandboxDate(value) || isFloat32Array(value) || Array.isArray(value) && requiresArrayEntries(value) || isSandboxArguments(value) || sandboxErrorTypes.has(value)) {
|
|
21549
|
+
if (stat2.count > 1 || stat2.forceHeap === true || guestValues.has(value) || stat2.cyclic || hasNullObjectPrototype(value) || ownSerializableSymbolKeys(value).length > 0 || isSandboxBox(value) || isSandboxRegExpIterator(value) || isSandboxRegex(value) && hasCustomRegexProperties(value) || isSandboxDate(value) || isFloat32Array(value) || isSandboxArrayBuffer(value) || Array.isArray(value) && requiresArrayEntries(value) || isSandboxArguments(value) || sandboxErrorTypes.has(value)) {
|
|
21355
21550
|
heapIds.set(value, nextId);
|
|
21356
21551
|
nextId += 1;
|
|
21357
21552
|
}
|
|
@@ -21383,12 +21578,16 @@ function collectContainerStats(value, stats, ancestors, guestValues, depth = 0)
|
|
|
21383
21578
|
stat2.expanded = true;
|
|
21384
21579
|
ancestors.add(value);
|
|
21385
21580
|
const guestEntries = [];
|
|
21386
|
-
|
|
21581
|
+
if (isFloat32Array(value)) guestEntries.push(float32Storage(value).buffer);
|
|
21582
|
+
const guest = isSandboxArrayBuffer(value) ? { kind: "arraybuffer", state: captureArrayBufferState(value, (entry) => {
|
|
21583
|
+
guestEntries.push(entry);
|
|
21584
|
+
return null;
|
|
21585
|
+
}) } : captureGuestHeapNode(value, (entry) => {
|
|
21387
21586
|
guestEntries.push(entry);
|
|
21388
21587
|
return null;
|
|
21389
21588
|
});
|
|
21390
21589
|
if (guest !== void 0) {
|
|
21391
|
-
guestValues.add(value);
|
|
21590
|
+
if (!isSandboxArrayBuffer(value)) guestValues.add(value);
|
|
21392
21591
|
for (const entry of guestEntries) {
|
|
21393
21592
|
collectContainerStats(entry, stats, ancestors, guestValues, depth + 1);
|
|
21394
21593
|
if (entry !== null && typeof entry === "object") stats.get(entry).forceHeap = true;
|
|
@@ -21396,6 +21595,7 @@ function collectContainerStats(value, stats, ancestors, guestValues, depth = 0)
|
|
|
21396
21595
|
ancestors.delete(value);
|
|
21397
21596
|
return;
|
|
21398
21597
|
}
|
|
21598
|
+
for (const entry of guestEntries) collectContainerStats(entry, stats, ancestors, guestValues, depth + 1);
|
|
21399
21599
|
if (!Array.isArray(value) && !isPlainObject(value) && !isFloat32Array(value) && !isSandboxDate(value)) {
|
|
21400
21600
|
ancestors.delete(value);
|
|
21401
21601
|
return;
|
|
@@ -21715,11 +21915,24 @@ function encodeReplayData(value, options = {}) {
|
|
|
21715
21915
|
...symbolProperties.length === 0 ? {} : { symbolProperties },
|
|
21716
21916
|
...Object.isExtensible(entry) ? {} : { extensible: false }
|
|
21717
21917
|
};
|
|
21918
|
+
} else if (isSandboxArrayBuffer(entry)) {
|
|
21919
|
+
const storage = encodeArrayBufferStorage(entry, id, float32Buffers, (id2) => ({ tag: "ref", id: id2 }));
|
|
21920
|
+
const properties = /* @__PURE__ */ Object.create(null);
|
|
21921
|
+
for (const [key, descriptor] of arrayBufferDataProperties(entry)) {
|
|
21922
|
+
if (typeof key === "symbol") continue;
|
|
21923
|
+
properties[key] = {
|
|
21924
|
+
value: child(descriptor.value, key),
|
|
21925
|
+
configurable: descriptor.configurable === true,
|
|
21926
|
+
enumerable: descriptor.enumerable === true,
|
|
21927
|
+
writable: descriptor.writable === true
|
|
21928
|
+
};
|
|
21929
|
+
}
|
|
21930
|
+
let symbolIndex = 0;
|
|
21931
|
+
const symbolEntries = serializeSymbolProperties(entry, (value2) => encode(value2, depth + 1, [...path, { symbol: Math.floor(symbolIndex++ / 2) }]));
|
|
21932
|
+
nodes[id] = { ...storage, properties, extensible: Object.isExtensible(entry), symbolEntries };
|
|
21718
21933
|
} else if (isFloat32Array(entry)) {
|
|
21719
|
-
const
|
|
21720
|
-
|
|
21721
|
-
id: id2
|
|
21722
|
-
}));
|
|
21934
|
+
const backing = float32Storage(entry);
|
|
21935
|
+
const storage = { kind: "float32array", ...encodeFloat32Layout(entry), buffer: child(backing.buffer, "<buffer>") };
|
|
21723
21936
|
const properties = /* @__PURE__ */ Object.create(null);
|
|
21724
21937
|
for (const [key, descriptor] of float32DataProperties(entry)) {
|
|
21725
21938
|
properties[key] = {
|
|
@@ -21822,7 +22035,7 @@ function decodeReplayData(input, options = {}, parent) {
|
|
|
21822
22035
|
const graph = record2(input);
|
|
21823
22036
|
const nodes = list(own(graph, "nodes"));
|
|
21824
22037
|
const restored = /* @__PURE__ */ new Map();
|
|
21825
|
-
const
|
|
22038
|
+
const initializeValues = [];
|
|
21826
22039
|
const decode = (entry, depth = 0) => {
|
|
21827
22040
|
if (depth > MAX_DATA_DEPTH) throw new TypeError("Replay data exceeds the nesting limit.");
|
|
21828
22041
|
if (entry === null || typeof entry === "boolean" || typeof entry === "string") return entry;
|
|
@@ -21947,10 +22160,20 @@ function decodeReplayData(input, options = {}, parent) {
|
|
|
21947
22160
|
if (node.extensible === false) Object.preventExtensions(result3);
|
|
21948
22161
|
return result3;
|
|
21949
22162
|
}
|
|
22163
|
+
if (kind === "arraybuffer") {
|
|
22164
|
+
if (typeof node.extensible !== "boolean") throw new TypeError("Invalid ArrayBuffer extensibility.");
|
|
22165
|
+
const result3 = decodeArrayBufferStorage(node, child);
|
|
22166
|
+
restored.set(id, result3);
|
|
22167
|
+
initializeValues.push(() => {
|
|
22168
|
+
defineProperties(result3, record2(own(node, "properties")), child, node.symbolEntries);
|
|
22169
|
+
if (!node.extensible) Object.preventExtensions(result3);
|
|
22170
|
+
});
|
|
22171
|
+
return result3;
|
|
22172
|
+
}
|
|
21950
22173
|
if (kind === "float32array") {
|
|
21951
22174
|
if (typeof node.extensible !== "boolean")
|
|
21952
22175
|
throw new TypeError("Invalid Float32Array extensibility.");
|
|
21953
|
-
const result3 = decodeFloat32Storage(node, child);
|
|
22176
|
+
const result3 = decodeFloat32Storage(node, child, compilation.owner?.budget);
|
|
21954
22177
|
restored.set(id, result3);
|
|
21955
22178
|
defineProperties(result3, record2(own(node, "properties")), child);
|
|
21956
22179
|
if (!node.extensible) Object.preventExtensions(result3);
|
|
@@ -21986,7 +22209,7 @@ function decodeReplayData(input, options = {}, parent) {
|
|
|
21986
22209
|
restored.set(id, result3);
|
|
21987
22210
|
const collection = child(own(node, "collection"));
|
|
21988
22211
|
if (collection !== void 0 && !isSandboxMap(collection) && !isSandboxSet(collection)) throw new TypeError("Invalid replay collection iterator source.");
|
|
21989
|
-
|
|
22212
|
+
initializeValues.push(() => {
|
|
21990
22213
|
restoreSandboxCollectionIterator({ collection, collectionKind, method, index, exhausted }, result3);
|
|
21991
22214
|
});
|
|
21992
22215
|
defineProperties(result3, record2(own(node, "properties")), child);
|
|
@@ -22057,7 +22280,7 @@ function decodeReplayData(input, options = {}, parent) {
|
|
|
22057
22280
|
return result2;
|
|
22058
22281
|
};
|
|
22059
22282
|
const result = decode(own(graph, "root"));
|
|
22060
|
-
for (const initialize of
|
|
22283
|
+
for (const initialize of initializeValues) initialize();
|
|
22061
22284
|
if (parent !== void 0) compilation.forward(compilation.tickets, parent);
|
|
22062
22285
|
return result;
|
|
22063
22286
|
} finally {
|
|
@@ -22836,12 +23059,43 @@ function copyHostValueToSandbox(value, stackFrames, options, state, path) {
|
|
|
22836
23059
|
state.seen.set(value, date);
|
|
22837
23060
|
return date;
|
|
22838
23061
|
}
|
|
23062
|
+
if (isSandboxArrayBuffer(value)) {
|
|
23063
|
+
const existing = state.seen.get(value);
|
|
23064
|
+
if (existing !== void 0) return existing;
|
|
23065
|
+
const length = arrayBufferLength(value);
|
|
23066
|
+
budget.allocateArrayLength(length);
|
|
23067
|
+
budget.provisionDataUsage(length + 1)();
|
|
23068
|
+
const copy = copyArrayBufferStorage(value, state);
|
|
23069
|
+
state.seen.set(value, copy);
|
|
23070
|
+
for (const [key, descriptor] of arrayBufferDataProperties(value)) {
|
|
23071
|
+
if (typeof key === "symbol") throw new TypeError("Host ArrayBuffer symbol properties require an explicit capability path.");
|
|
23072
|
+
Object.defineProperty(copy, key, {
|
|
23073
|
+
...descriptor,
|
|
23074
|
+
value: copyHostValueToSandbox(
|
|
23075
|
+
descriptor.value,
|
|
23076
|
+
stackFrames,
|
|
23077
|
+
{ ...options, capabilityPath: [...options.capabilityPath ?? [], key] },
|
|
23078
|
+
state,
|
|
23079
|
+
joinPath(path, key)
|
|
23080
|
+
)
|
|
23081
|
+
});
|
|
23082
|
+
}
|
|
23083
|
+
if (!Object.isExtensible(value)) Object.preventExtensions(copy);
|
|
23084
|
+
return copy;
|
|
23085
|
+
}
|
|
22839
23086
|
if (isFloat32Array(value)) {
|
|
22840
23087
|
const existing = state.seen.get(value);
|
|
22841
23088
|
if (existing !== void 0) return existing;
|
|
22842
23089
|
checkFloat32Allocation(Math.ceil(float32Storage(value).byteLength / 4), budget);
|
|
22843
23090
|
const copy = copyFloat32Storage(value, state);
|
|
22844
23091
|
state.seen.set(value, copy);
|
|
23092
|
+
copyHostValueToSandbox(
|
|
23093
|
+
float32Storage(value).buffer,
|
|
23094
|
+
stackFrames,
|
|
23095
|
+
{ ...options, capabilityPath: [...options.capabilityPath ?? [], "buffer"] },
|
|
23096
|
+
state,
|
|
23097
|
+
`${path}.buffer`
|
|
23098
|
+
);
|
|
22845
23099
|
for (const [key, descriptor] of float32DataProperties(value)) {
|
|
22846
23100
|
Object.defineProperty(copy, key, {
|
|
22847
23101
|
...descriptor,
|
|
@@ -24867,6 +25121,128 @@ function createBigIntGlobal(budget) {
|
|
|
24867
25121
|
return constructor;
|
|
24868
25122
|
}
|
|
24869
25123
|
|
|
25124
|
+
// packages/safe-js/src/interp/globals/array-buffer.ts
|
|
25125
|
+
var resizeBuffer2 = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "resize").value;
|
|
25126
|
+
function createArrayBufferGlobal(budget) {
|
|
25127
|
+
const prototype = /* @__PURE__ */ Object.create(null);
|
|
25128
|
+
const constructor = createSandboxClosure({
|
|
25129
|
+
guest: true,
|
|
25130
|
+
sandbox: true,
|
|
25131
|
+
name: "ArrayBuffer",
|
|
25132
|
+
length: 1,
|
|
25133
|
+
call: () => {
|
|
25134
|
+
throw new TypeError("ArrayBuffer requires new.");
|
|
25135
|
+
},
|
|
25136
|
+
construct: async (args, context) => {
|
|
25137
|
+
let selected;
|
|
25138
|
+
let current;
|
|
25139
|
+
const bridge = {
|
|
25140
|
+
...context,
|
|
25141
|
+
stack: context?.stack ?? [],
|
|
25142
|
+
thisValue: void 0,
|
|
25143
|
+
getProperty: context?.getProperty ?? ((value, key) => {
|
|
25144
|
+
const descriptor = getSandboxPropertyDescriptor(value, key, budget);
|
|
25145
|
+
return descriptor === void 0 ? getSandboxDataProperty(value, key, budget) : readPropertyDescriptor(descriptor, value, bridge);
|
|
25146
|
+
}),
|
|
25147
|
+
invokeClosure: context?.invokeClosure ?? ((callee, values, receiver, construct) => invokeBuiltinClosure(callee, values, budget, context, receiver, construct))
|
|
25148
|
+
};
|
|
25149
|
+
const release = retainValues(budget, () => [selected, current, ...args]);
|
|
25150
|
+
try {
|
|
25151
|
+
const number = await sandboxNumber(args[0], budget, bridge);
|
|
25152
|
+
const length = Number.isNaN(number) ? 0 : Math.trunc(number);
|
|
25153
|
+
if (length < 0 || !Number.isSafeInteger(length)) throw new RangeError("Invalid ArrayBuffer length.");
|
|
25154
|
+
let maxByteLength;
|
|
25155
|
+
if (args[1] !== null && typeof args[1] === "object") {
|
|
25156
|
+
current = await bridge.getProperty(args[1], "maxByteLength");
|
|
25157
|
+
if (current !== void 0) {
|
|
25158
|
+
const maximum = await sandboxNumber(current, budget, bridge);
|
|
25159
|
+
maxByteLength = Number.isNaN(maximum) ? 0 : Math.trunc(maximum);
|
|
25160
|
+
if (!Number.isSafeInteger(maxByteLength) || maxByteLength < length)
|
|
25161
|
+
throw new RangeError("Invalid ArrayBuffer maximum length.");
|
|
25162
|
+
}
|
|
25163
|
+
}
|
|
25164
|
+
const target = context?.newTarget ?? constructor;
|
|
25165
|
+
selected = await bridge.getProperty(target, "prototype");
|
|
25166
|
+
budget.allocateArrayLength(maxByteLength ?? length);
|
|
25167
|
+
budget.provisionDataUsage(length + 1)();
|
|
25168
|
+
const result = Reflect.construct(ArrayBuffer, [length, maxByteLength === void 0 ? void 0 : { maxByteLength }]);
|
|
25169
|
+
setSandboxPrototype(result, selected !== null && typeof selected === "object" ? selected : prototype, budget);
|
|
25170
|
+
return result;
|
|
25171
|
+
} finally {
|
|
25172
|
+
release();
|
|
25173
|
+
}
|
|
25174
|
+
}
|
|
25175
|
+
});
|
|
25176
|
+
Object.defineProperty(materializeFunctionProperties(constructor), "prototype", { value: prototype, writable: false });
|
|
25177
|
+
Object.defineProperty(materializeFunctionProperties(constructor), "isView", {
|
|
25178
|
+
writable: true,
|
|
25179
|
+
configurable: true,
|
|
25180
|
+
value: createSandboxClosure({
|
|
25181
|
+
guest: true,
|
|
25182
|
+
sandbox: true,
|
|
25183
|
+
name: "isView",
|
|
25184
|
+
length: 1,
|
|
25185
|
+
call: (args) => ArrayBuffer.isView(args[0])
|
|
25186
|
+
})
|
|
25187
|
+
});
|
|
25188
|
+
Object.defineProperties(prototype, {
|
|
25189
|
+
constructor: { value: constructor, writable: true, configurable: true },
|
|
25190
|
+
[Symbol.toStringTag]: { value: "ArrayBuffer", configurable: true }
|
|
25191
|
+
});
|
|
25192
|
+
const getters = [];
|
|
25193
|
+
Object.defineProperty(prototype, "resize", {
|
|
25194
|
+
writable: true,
|
|
25195
|
+
configurable: true,
|
|
25196
|
+
value: createSandboxClosure({
|
|
25197
|
+
guest: true,
|
|
25198
|
+
sandbox: true,
|
|
25199
|
+
name: "resize",
|
|
25200
|
+
length: 1,
|
|
25201
|
+
call: async (args, context) => {
|
|
25202
|
+
const receiver = context?.thisValue;
|
|
25203
|
+
if (!isSandboxArrayBuffer(receiver) || arrayBufferOptions(receiver) === void 0)
|
|
25204
|
+
throw new TypeError("ArrayBuffer resize requires a resizable buffer receiver.");
|
|
25205
|
+
const release = retainValues(budget, () => [receiver, ...args]);
|
|
25206
|
+
try {
|
|
25207
|
+
const number = await sandboxNumber(args[0], budget, context);
|
|
25208
|
+
const length = Number.isNaN(number) ? 0 : Math.trunc(number);
|
|
25209
|
+
if (!Number.isSafeInteger(length) || length < 0 || length > arrayBufferOptions(receiver).maxByteLength)
|
|
25210
|
+
throw new RangeError("Invalid ArrayBuffer resize length.");
|
|
25211
|
+
budget.allocateArrayLength(length);
|
|
25212
|
+
budget.provisionDataUsage(Math.max(length - arrayBufferLength(receiver), 0))();
|
|
25213
|
+
Reflect.apply(resizeBuffer2, receiver, [length]);
|
|
25214
|
+
return void 0;
|
|
25215
|
+
} finally {
|
|
25216
|
+
release();
|
|
25217
|
+
}
|
|
25218
|
+
}
|
|
25219
|
+
})
|
|
25220
|
+
});
|
|
25221
|
+
for (const key of ["byteLength", "maxByteLength", "resizable"]) {
|
|
25222
|
+
const getter = createSandboxClosure({
|
|
25223
|
+
guest: true,
|
|
25224
|
+
sandbox: true,
|
|
25225
|
+
name: `get ${key}`,
|
|
25226
|
+
length: 0,
|
|
25227
|
+
call: (_args, context) => {
|
|
25228
|
+
if (!isSandboxArrayBuffer(context?.thisValue)) throw new TypeError(`ArrayBuffer ${key} requires a buffer receiver.`);
|
|
25229
|
+
if (key === "byteLength") return arrayBufferLength(context.thisValue);
|
|
25230
|
+
const options = arrayBufferOptions(context.thisValue);
|
|
25231
|
+
return key === "resizable" ? options !== void 0 : options?.maxByteLength ?? arrayBufferLength(context.thisValue);
|
|
25232
|
+
}
|
|
25233
|
+
});
|
|
25234
|
+
Object.defineProperty(prototype, key, { get: accessorAdapter(getter, "get"), configurable: true });
|
|
25235
|
+
getters.push(getter);
|
|
25236
|
+
}
|
|
25237
|
+
setSandboxPrototype(prototype, getSandboxPrototype(/* @__PURE__ */ Object.create(null), budget));
|
|
25238
|
+
arrayBufferPrototypes.set(budget, prototype);
|
|
25239
|
+
registerBuiltinIdentities(budget, { ArrayBuffer: constructor });
|
|
25240
|
+
registerIntrinsicFunction(budget, constructor);
|
|
25241
|
+
for (const getter of getters) registerIntrinsicFunction(budget, getter);
|
|
25242
|
+
registerIntrinsicObject(budget, prototype);
|
|
25243
|
+
return constructor;
|
|
25244
|
+
}
|
|
25245
|
+
|
|
24870
25246
|
// packages/safe-js/src/interp/globals.ts
|
|
24871
25247
|
function createBuiltinBindings(options) {
|
|
24872
25248
|
const bindings = {
|
|
@@ -24879,6 +25255,7 @@ function createBuiltinBindings(options) {
|
|
|
24879
25255
|
...createErrorGlobals({ ...options, errorPrototypes: options.errorPrototypes !== false }),
|
|
24880
25256
|
...createMathGlobals({ random: options.random, budget: options.budget }),
|
|
24881
25257
|
...createObjectArrayGlobals(options),
|
|
25258
|
+
ArrayBuffer: createArrayBufferGlobal(options.budget),
|
|
24882
25259
|
...createMiscGlobals(options),
|
|
24883
25260
|
...createUriGlobals(options.budget),
|
|
24884
25261
|
...createPromiseGlobals(options),
|
|
@@ -25615,6 +25992,11 @@ function validateDumpHeap(root, state) {
|
|
|
25615
25992
|
validateDateRecord(entry, path);
|
|
25616
25993
|
continue;
|
|
25617
25994
|
}
|
|
25995
|
+
if (entry.kind === "arraybuffer") {
|
|
25996
|
+
validateArrayBufferStorage(entry);
|
|
25997
|
+
validateGuestHeapNode({ kind: "guest-object", state: entry.state }, heap, state.limits.maxEntries);
|
|
25998
|
+
continue;
|
|
25999
|
+
}
|
|
25618
26000
|
if (entry.kind === "float32array") {
|
|
25619
26001
|
validateFloat32Storage(entry);
|
|
25620
26002
|
requireRecord(entry.entries, `${path}.entries`);
|
|
@@ -25838,7 +26220,7 @@ function validateHeapValue(value, path, state, heap) {
|
|
|
25838
26220
|
fail("invalidValue", path, String(error));
|
|
25839
26221
|
}
|
|
25840
26222
|
validateErrorType(record4, path);
|
|
25841
|
-
if (!["symbol", "arguments", "array", "object", "map", "set", "float32array", "date", "boxed", "collection-iterator", "regexp-iterator", "regex-object"].includes(String(record4.kind)))
|
|
26223
|
+
if (!["symbol", "arguments", "array", "object", "map", "set", "float32array", "arraybuffer", "date", "boxed", "collection-iterator", "regexp-iterator", "regex-object"].includes(String(record4.kind)))
|
|
25842
26224
|
fail("unknownTag", `${path}.kind`, "unknown heap tag");
|
|
25843
26225
|
validateValue(record4, path, 1, state);
|
|
25844
26226
|
if (record4.kind === "symbol") validateSymbolRecord(record4, path, state);
|
|
@@ -25847,6 +26229,10 @@ function validateHeapValue(value, path, state, heap) {
|
|
|
25847
26229
|
if (record4.kind === "object") requireRecord(record4.entries, `${path}.entries`);
|
|
25848
26230
|
if (record4.kind === "boxed") validateBoxedRecord(record4, path, heap);
|
|
25849
26231
|
if (record4.kind === "date") validateDateRecord(record4, path);
|
|
26232
|
+
if (record4.kind === "arraybuffer") {
|
|
26233
|
+
validateArrayBufferStorage(record4);
|
|
26234
|
+
validateGuestHeapNode({ kind: "guest-object", state: record4.state }, heap, state.limits.maxEntries);
|
|
26235
|
+
}
|
|
25850
26236
|
if (record4.kind === "float32array") {
|
|
25851
26237
|
validateFloat32Storage(record4);
|
|
25852
26238
|
requireRecord(record4.entries, `${path}.entries`);
|
|
@@ -26043,7 +26429,7 @@ function validateGenericValue(value, path, depth, state) {
|
|
|
26043
26429
|
if (typeof value === "object" && value !== null && hasGuestObjectState(value)) {
|
|
26044
26430
|
fail("invalidState", path, "guest function properties, prototype links and custom descriptors cannot be restored");
|
|
26045
26431
|
}
|
|
26046
|
-
if (state.dataPropertiesOnly &&
|
|
26432
|
+
if (state.dataPropertiesOnly && types7.isProxy(value)) {
|
|
26047
26433
|
fail("invalidType", path, "proxy objects are not snapshot data");
|
|
26048
26434
|
}
|
|
26049
26435
|
if (depth > state.limits.maxDepth)
|
|
@@ -26842,12 +27228,10 @@ function measureSandboxData(values, options = {}) {
|
|
|
26842
27228
|
}
|
|
26843
27229
|
const prototype = getSandboxPrototype(value);
|
|
26844
27230
|
if (prototype !== null) visit(prototype, depth + 1);
|
|
27231
|
+
if (isSandboxArrayBuffer(value)) usage += arrayBufferLength(value);
|
|
26845
27232
|
if (isFloat32Array(value)) {
|
|
26846
27233
|
const storage = float32Storage(value);
|
|
26847
|
-
|
|
26848
|
-
seen.add(storage.buffer);
|
|
26849
|
-
usage += storage.byteLength;
|
|
26850
|
-
}
|
|
27234
|
+
visit(storage.buffer, depth + 1);
|
|
26851
27235
|
for (const [key, descriptor] of float32Properties(value)) {
|
|
26852
27236
|
usage += 1;
|
|
26853
27237
|
if (typeof key === "string") usage += key.length;
|
|
@@ -26986,7 +27370,7 @@ function measureSandboxData(values, options = {}) {
|
|
|
26986
27370
|
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
26987
27371
|
if (descriptor !== void 0) descriptors2.push([key, descriptor]);
|
|
26988
27372
|
}
|
|
26989
|
-
const includeNonEnumerable = isSandboxDate(value) || sandboxErrorTypes.has(value) || hasManagedDescriptors(value);
|
|
27373
|
+
const includeNonEnumerable = isSandboxDate(value) || isSandboxArrayBuffer(value) || sandboxErrorTypes.has(value) || hasManagedDescriptors(value);
|
|
26990
27374
|
for (const [key, descriptor] of descriptors2) {
|
|
26991
27375
|
if (!descriptor.enumerable && !includeNonEnumerable) continue;
|
|
26992
27376
|
usage += 1 + key.length;
|
|
@@ -27182,6 +27566,20 @@ function copyToSandbox(value, state, path = "<root>", cloneSandboxCollections =
|
|
|
27182
27566
|
}
|
|
27183
27567
|
return sandboxPromise;
|
|
27184
27568
|
}
|
|
27569
|
+
if (isSandboxArrayBuffer(value)) {
|
|
27570
|
+
const existing = state.seen.get(value);
|
|
27571
|
+
if (existing !== void 0) return existing;
|
|
27572
|
+
const copy = copyArrayBufferStorage(value, state);
|
|
27573
|
+
state.seen.set(value, copy);
|
|
27574
|
+
for (const [key, descriptor] of arrayBufferDataProperties(value)) {
|
|
27575
|
+
Object.defineProperty(copy, key, {
|
|
27576
|
+
...descriptor,
|
|
27577
|
+
value: copyToSandbox(descriptor.value, state, joinPath2(path, key), cloneSandboxCollections, depth + 1)
|
|
27578
|
+
});
|
|
27579
|
+
}
|
|
27580
|
+
if (!Object.isExtensible(value)) Object.preventExtensions(copy);
|
|
27581
|
+
return copy;
|
|
27582
|
+
}
|
|
27185
27583
|
if (nodeTypes.isDate(value)) {
|
|
27186
27584
|
const existing = state.seen.get(value);
|
|
27187
27585
|
if (existing !== void 0) return existing;
|
|
@@ -27200,6 +27598,7 @@ function copyToSandbox(value, state, path = "<root>", cloneSandboxCollections =
|
|
|
27200
27598
|
if (existing !== void 0) return existing;
|
|
27201
27599
|
const copy = copyFloat32Storage(value, state);
|
|
27202
27600
|
state.seen.set(value, copy);
|
|
27601
|
+
copyToSandbox(float32Storage(value).buffer, state, `${path}.buffer`, cloneSandboxCollections, depth + 1);
|
|
27203
27602
|
for (const [key, descriptor] of float32DataProperties(value)) {
|
|
27204
27603
|
Object.defineProperty(copy, key, {
|
|
27205
27604
|
...descriptor,
|
|
@@ -27421,6 +27820,7 @@ function copyFromSandbox(value, state, path = "<root>", options, depth = 0) {
|
|
|
27421
27820
|
if (existing !== void 0) return existing;
|
|
27422
27821
|
const copy = copyFloat32Storage(value, state);
|
|
27423
27822
|
state.seen.set(value, copy);
|
|
27823
|
+
copyFromSandbox(float32Storage(value).buffer, state, `${path}.buffer`, options, depth + 1);
|
|
27424
27824
|
for (const [key, descriptor] of float32DataProperties(value)) {
|
|
27425
27825
|
Object.defineProperty(copy, key, {
|
|
27426
27826
|
...descriptor,
|
|
@@ -27430,6 +27830,20 @@ function copyFromSandbox(value, state, path = "<root>", options, depth = 0) {
|
|
|
27430
27830
|
if (!Object.isExtensible(value)) Object.preventExtensions(copy);
|
|
27431
27831
|
return copy;
|
|
27432
27832
|
}
|
|
27833
|
+
if (isSandboxArrayBuffer(value)) {
|
|
27834
|
+
const existing = state.seen.get(value);
|
|
27835
|
+
if (existing !== void 0) return existing;
|
|
27836
|
+
const copy = copyArrayBufferStorage(value, state);
|
|
27837
|
+
state.seen.set(value, copy);
|
|
27838
|
+
for (const [key, descriptor] of arrayBufferDataProperties(value)) {
|
|
27839
|
+
Object.defineProperty(copy, key, {
|
|
27840
|
+
...descriptor,
|
|
27841
|
+
value: copyFromSandbox(descriptor.value, state, joinPath2(path, key), options, depth + 1)
|
|
27842
|
+
});
|
|
27843
|
+
}
|
|
27844
|
+
if (!Object.isExtensible(value)) Object.preventExtensions(copy);
|
|
27845
|
+
return copy;
|
|
27846
|
+
}
|
|
27433
27847
|
if (isSandboxDate(value)) {
|
|
27434
27848
|
const existing = state.seen.get(value);
|
|
27435
27849
|
if (existing !== void 0) return existing;
|
|
@@ -27591,6 +28005,16 @@ function allocateSandboxValue2(value, budget, seen) {
|
|
|
27591
28005
|
budget.allocateString(value);
|
|
27592
28006
|
return;
|
|
27593
28007
|
}
|
|
28008
|
+
if (isSandboxArrayBuffer(value)) {
|
|
28009
|
+
if (seen.has(value)) return;
|
|
28010
|
+
seen.add(value);
|
|
28011
|
+
budget.allocateArrayLength(arrayBufferLength(value));
|
|
28012
|
+
for (const [key, descriptor] of arrayBufferDataProperties(value)) {
|
|
28013
|
+
if (typeof key === "string") budget.allocateString(key);
|
|
28014
|
+
allocateSandboxValue2(descriptor.value, budget, seen);
|
|
28015
|
+
}
|
|
28016
|
+
return;
|
|
28017
|
+
}
|
|
27594
28018
|
if (isSandboxBox(value)) {
|
|
27595
28019
|
if (seen.has(value)) return;
|
|
27596
28020
|
seen.add(value);
|
|
@@ -28336,8 +28760,29 @@ function normalize(value, seen) {
|
|
|
28336
28760
|
try {
|
|
28337
28761
|
const date = copyNativeDate(value);
|
|
28338
28762
|
if (date !== void 0) return Object.assign(/* @__PURE__ */ Object.create(null), { $type: "date", time: serializedDateTime(date) });
|
|
28763
|
+
if (isSandboxArrayBuffer(value)) {
|
|
28764
|
+
arrayBufferLength(value);
|
|
28765
|
+
const properties = /* @__PURE__ */ Object.create(null);
|
|
28766
|
+
const entries = [];
|
|
28767
|
+
for (const [key, descriptor] of arrayBufferDataProperties(value)) {
|
|
28768
|
+
if (typeof key === "symbol") throw new TypeError("ArrayBuffer symbol properties require an explicit host-call identity.");
|
|
28769
|
+
entries.push([key, descriptor]);
|
|
28770
|
+
}
|
|
28771
|
+
for (const [key, descriptor] of entries.sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0))
|
|
28772
|
+
defineOwnDataProperty(properties, key, normalize(descriptor.value, seen));
|
|
28773
|
+
return Object.assign(/* @__PURE__ */ Object.create(null), {
|
|
28774
|
+
$type: "arraybuffer",
|
|
28775
|
+
bytes: normalize(Array.from(new Uint8Array(value)), seen),
|
|
28776
|
+
...arrayBufferOptions(value),
|
|
28777
|
+
properties
|
|
28778
|
+
});
|
|
28779
|
+
}
|
|
28339
28780
|
if (isFloat32Array(value)) {
|
|
28340
28781
|
const storage = float32Storage(value);
|
|
28782
|
+
const resizable = arrayBufferOptions(storage.buffer) !== void 0;
|
|
28783
|
+
const layout = resizable ? float32ViewLayouts.get(value) : void 0;
|
|
28784
|
+
if (resizable && layout === void 0)
|
|
28785
|
+
throw new TypeError("Resizable Float32Array host-call identity requires known view layout.");
|
|
28341
28786
|
const properties = /* @__PURE__ */ Object.create(null);
|
|
28342
28787
|
for (const [key, descriptor] of float32DataProperties(value).sort(
|
|
28343
28788
|
([left], [right]) => left < right ? -1 : left > right ? 1 : 0
|
|
@@ -28349,7 +28794,12 @@ function normalize(value, seen) {
|
|
|
28349
28794
|
bytes: normalize(Array.from(new Uint8Array(storage.buffer)), seen),
|
|
28350
28795
|
byteOffset: storage.byteOffset,
|
|
28351
28796
|
length: storage.length,
|
|
28352
|
-
properties
|
|
28797
|
+
properties,
|
|
28798
|
+
...resizable || Reflect.ownKeys(storage.buffer).length > 0 ? { buffer: normalize(storage.buffer, seen) } : {},
|
|
28799
|
+
...layout === void 0 ? {} : { viewLayout: {
|
|
28800
|
+
byteOffset: layout.byteOffset,
|
|
28801
|
+
length: layout.length ?? null
|
|
28802
|
+
} }
|
|
28353
28803
|
});
|
|
28354
28804
|
}
|
|
28355
28805
|
if (Array.isArray(value)) {
|
|
@@ -29301,6 +29751,7 @@ function classDefinitionContains(node, expression) {
|
|
|
29301
29751
|
var KNOWN_RUNTIME_GLOBALS = [
|
|
29302
29752
|
"AggregateError",
|
|
29303
29753
|
"Array",
|
|
29754
|
+
"ArrayBuffer",
|
|
29304
29755
|
"Boolean",
|
|
29305
29756
|
"BigInt",
|
|
29306
29757
|
"Date",
|
|
@@ -39693,7 +40144,7 @@ function createReplayableRandom(options = {}) {
|
|
|
39693
40144
|
|
|
39694
40145
|
// packages/safe-js/src/realm.ts
|
|
39695
40146
|
import { AsyncLocalStorage as AsyncLocalStorage6 } from "node:async_hooks";
|
|
39696
|
-
import { types as
|
|
40147
|
+
import { types as types8 } from "node:util";
|
|
39697
40148
|
|
|
39698
40149
|
// packages/safe-js/src/modules/registry.ts
|
|
39699
40150
|
function createUnknownModuleMessage2(moduleName, moduleNames) {
|
|
@@ -39832,7 +40283,7 @@ var RealmState = class {
|
|
|
39832
40283
|
throw new TypeError("Realm limits must be positive safe integers with supported names.");
|
|
39833
40284
|
this.limits[name] = Number(value);
|
|
39834
40285
|
}
|
|
39835
|
-
if (options.extensions !== void 0 && (!Array.isArray(options.extensions) ||
|
|
40286
|
+
if (options.extensions !== void 0 && (!Array.isArray(options.extensions) || types8.isProxy(options.extensions)))
|
|
39836
40287
|
throw new TypeError("Extensions must be a registration array.");
|
|
39837
40288
|
const registrations = options.extensions ?? [];
|
|
39838
40289
|
const extensions = [];
|
|
@@ -40067,7 +40518,7 @@ var RealmState = class {
|
|
|
40067
40518
|
return this.phase.run(phase, () => {
|
|
40068
40519
|
try {
|
|
40069
40520
|
const result = call();
|
|
40070
|
-
if (
|
|
40521
|
+
if (types8.isPromise(result) || phase.pending.size > 0 || phase.failure !== void 0) {
|
|
40071
40522
|
return Promise.resolve(result).then(
|
|
40072
40523
|
async (value) => {
|
|
40073
40524
|
await Promise.allSettled(phase.pending);
|
|
@@ -40136,7 +40587,7 @@ var RealmState = class {
|
|
|
40136
40587
|
},
|
|
40137
40588
|
read: (operation, validate) => {
|
|
40138
40589
|
const value = this.invokeHost(operation, operation);
|
|
40139
|
-
if (
|
|
40590
|
+
if (types8.isPromise(value)) {
|
|
40140
40591
|
void Promise.resolve(value).catch(() => void 0);
|
|
40141
40592
|
throw new TypeError("Live property operations must be synchronous.");
|
|
40142
40593
|
}
|
|
@@ -40144,7 +40595,7 @@ var RealmState = class {
|
|
|
40144
40595
|
},
|
|
40145
40596
|
write: (operation, value) => {
|
|
40146
40597
|
const result = this.invokeHost(operation, () => operation(this.exportValue(value)));
|
|
40147
|
-
if (
|
|
40598
|
+
if (types8.isPromise(result)) {
|
|
40148
40599
|
void Promise.resolve(result).catch(() => void 0);
|
|
40149
40600
|
throw new TypeError("Live property setters must be synchronous.");
|
|
40150
40601
|
}
|
|
@@ -40353,7 +40804,7 @@ var RealmState = class {
|
|
|
40353
40804
|
}
|
|
40354
40805
|
});
|
|
40355
40806
|
const output = getExtensionSetup(extension)(context);
|
|
40356
|
-
if (
|
|
40807
|
+
if (types8.isPromise(output)) {
|
|
40357
40808
|
void Promise.resolve(output).catch(() => void 0);
|
|
40358
40809
|
throw new TypeError("Extension setup must be synchronous.");
|
|
40359
40810
|
}
|
|
@@ -40545,7 +40996,7 @@ var RealmState = class {
|
|
|
40545
40996
|
};
|
|
40546
40997
|
function readModules(input) {
|
|
40547
40998
|
const entries = (value, label) => {
|
|
40548
|
-
if (
|
|
40999
|
+
if (types8.isMap(value) && !types8.isProxy(value)) {
|
|
40549
41000
|
const result = [...Map.prototype.entries.call(value)];
|
|
40550
41001
|
if (result.length > 4096 || result.some(([key]) => typeof key !== "string" || key.length === 0))
|
|
40551
41002
|
throw new TypeError(`${label} requires bounded string keys.`);
|
|
@@ -41814,4 +42265,4 @@ export {
|
|
|
41814
42265
|
FileSnapshotBackend,
|
|
41815
42266
|
run
|
|
41816
42267
|
};
|
|
41817
|
-
//# sourceMappingURL=chunk-
|
|
42268
|
+
//# sourceMappingURL=chunk-CYVI4ZUK.js.map
|