@poe-platform/safe-js 0.1.363 → 0.1.365
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-ADA4LH5C.js → chunk-A7CQH53A.js} +2 -2
- package/dist/safe-js/chunks/{chunk-OTFEHCGJ.js → chunk-NLDDBHDH.js} +403 -83
- package/dist/safe-js/chunks/chunk-NLDDBHDH.js.map +7 -0
- 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/dist/safe-js/interp/values.d.ts +1 -1
- package/dist/safe-js/snapshot/data-view.d.ts +13 -0
- package/dist/safe-js/snapshot/replay-data.d.ts +5 -0
- package/package.json +2 -2
- package/dist/safe-js/chunks/chunk-OTFEHCGJ.js.map +0 -7
- /package/dist/safe-js/chunks/{chunk-ADA4LH5C.js.map → chunk-A7CQH53A.js.map} +0 -0
|
@@ -7001,8 +7001,67 @@ function requireUint8Array(value) {
|
|
|
7001
7001
|
return value;
|
|
7002
7002
|
}
|
|
7003
7003
|
|
|
7004
|
-
// packages/safe-js/src/interp/
|
|
7004
|
+
// packages/safe-js/src/interp/data-view.ts
|
|
7005
7005
|
import { types as types3 } from "node:util";
|
|
7006
|
+
var dataViewPrototypes = /* @__PURE__ */ new WeakMap();
|
|
7007
|
+
var dataViewLayouts = /* @__PURE__ */ new WeakMap();
|
|
7008
|
+
var dataViewGetters = Object.fromEntries(["buffer", "byteOffset", "byteLength"].map((key) => [key, Object.getOwnPropertyDescriptor(DataView.prototype, key).get]));
|
|
7009
|
+
var resize = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "resize")?.value;
|
|
7010
|
+
function isSandboxDataView(value) {
|
|
7011
|
+
return types3.isDataView(value) && Object.getPrototypeOf(value) === DataView.prototype;
|
|
7012
|
+
}
|
|
7013
|
+
function dataViewBuffer(value) {
|
|
7014
|
+
const buffer = Reflect.apply(dataViewGetters.buffer, value, []);
|
|
7015
|
+
if (!isSandboxArrayBuffer(buffer)) throw new TypeError("DataView requires a non-shared ArrayBuffer.");
|
|
7016
|
+
return buffer;
|
|
7017
|
+
}
|
|
7018
|
+
function dataViewLayout(value) {
|
|
7019
|
+
const buffer = dataViewBuffer(value);
|
|
7020
|
+
if (arrayBufferDetached(buffer)) return { byteOffset: 0, byteLength: 0 };
|
|
7021
|
+
if (arrayBufferOptions(buffer) !== void 0) {
|
|
7022
|
+
const layout = dataViewLayouts.get(value);
|
|
7023
|
+
if (layout === void 0) throw new TypeError("Resizable DataView persistence requires known view layout.");
|
|
7024
|
+
return layout;
|
|
7025
|
+
}
|
|
7026
|
+
return {
|
|
7027
|
+
byteOffset: Reflect.apply(dataViewGetters.byteOffset, value, []),
|
|
7028
|
+
byteLength: Reflect.apply(dataViewGetters.byteLength, value, [])
|
|
7029
|
+
};
|
|
7030
|
+
}
|
|
7031
|
+
function restoreDataView(buffer, byteOffset, byteLength, budget) {
|
|
7032
|
+
const originalLength = arrayBufferLength(buffer);
|
|
7033
|
+
const required = byteOffset + (byteLength ?? 0);
|
|
7034
|
+
const options = arrayBufferOptions(buffer);
|
|
7035
|
+
const grow = required > originalLength;
|
|
7036
|
+
if (grow) {
|
|
7037
|
+
if (resize === void 0 || options === void 0 || required > options.maxByteLength)
|
|
7038
|
+
throw new RangeError("DataView layout exceeds backing capacity.");
|
|
7039
|
+
budget?.allocateArrayLength(required);
|
|
7040
|
+
budget?.provisionDataUsage(required - originalLength)();
|
|
7041
|
+
Reflect.apply(resize, buffer, [required]);
|
|
7042
|
+
}
|
|
7043
|
+
try {
|
|
7044
|
+
const view = new DataView(buffer, byteOffset, byteLength);
|
|
7045
|
+
if (options !== void 0) dataViewLayouts.set(view, { byteOffset, ...byteLength === void 0 ? {} : { byteLength } });
|
|
7046
|
+
return view;
|
|
7047
|
+
} finally {
|
|
7048
|
+
if (grow) Reflect.apply(resize, buffer, [originalLength]);
|
|
7049
|
+
}
|
|
7050
|
+
}
|
|
7051
|
+
function copyDataViewStorage(value, state) {
|
|
7052
|
+
const layout = dataViewLayout(value);
|
|
7053
|
+
return restoreDataView(copyArrayBufferStorage(dataViewBuffer(value), state), layout.byteOffset, layout.byteLength);
|
|
7054
|
+
}
|
|
7055
|
+
function dataViewDataProperties(value) {
|
|
7056
|
+
return Reflect.ownKeys(value).map((key) => {
|
|
7057
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
7058
|
+
if (!("value" in descriptor)) throw new TypeError("DataView accessors cannot be copied as data.");
|
|
7059
|
+
return [key, descriptor];
|
|
7060
|
+
});
|
|
7061
|
+
}
|
|
7062
|
+
|
|
7063
|
+
// packages/safe-js/src/interp/date.ts
|
|
7064
|
+
import { types as types4 } from "node:util";
|
|
7006
7065
|
var NativeDate = Date;
|
|
7007
7066
|
var readTime = NativeDate.prototype.getTime;
|
|
7008
7067
|
var writeTime = NativeDate.prototype.setTime;
|
|
@@ -7019,7 +7078,7 @@ function dateTime(value) {
|
|
|
7019
7078
|
return Reflect.apply(readTime, value, []);
|
|
7020
7079
|
}
|
|
7021
7080
|
function copyNativeDate(value) {
|
|
7022
|
-
if (!
|
|
7081
|
+
if (!types4.isDate(value)) return void 0;
|
|
7023
7082
|
if (Object.getPrototypeOf(value) !== NativeDate.prototype)
|
|
7024
7083
|
throw new TypeError("Date subclasses are not supported.");
|
|
7025
7084
|
return createSandboxDate(dateTime(value));
|
|
@@ -7454,7 +7513,7 @@ function copySandboxArgumentProperties(source, target, copyValue) {
|
|
|
7454
7513
|
}
|
|
7455
7514
|
|
|
7456
7515
|
// packages/safe-js/src/interp/boxed.ts
|
|
7457
|
-
import { types as
|
|
7516
|
+
import { types as types5 } from "node:util";
|
|
7458
7517
|
var boxes = /* @__PURE__ */ new WeakSet();
|
|
7459
7518
|
var numberValue = Number.prototype.valueOf;
|
|
7460
7519
|
var stringValue = String.prototype.valueOf;
|
|
@@ -7462,11 +7521,11 @@ var booleanValue = Boolean.prototype.valueOf;
|
|
|
7462
7521
|
var symbolValue = Symbol.prototype.valueOf;
|
|
7463
7522
|
var bigintValue = BigInt.prototype.valueOf;
|
|
7464
7523
|
function nativeBoxedValue(value) {
|
|
7465
|
-
if (
|
|
7466
|
-
if (
|
|
7467
|
-
if (
|
|
7468
|
-
if (
|
|
7469
|
-
if (
|
|
7524
|
+
if (types5.isNumberObject(value)) return Reflect.apply(numberValue, value, []);
|
|
7525
|
+
if (types5.isStringObject(value)) return Reflect.apply(stringValue, value, []);
|
|
7526
|
+
if (types5.isBooleanObject(value)) return Reflect.apply(booleanValue, value, []);
|
|
7527
|
+
if (types5.isSymbolObject(value)) return Reflect.apply(symbolValue, value, []);
|
|
7528
|
+
if (types5.isBigIntObject(value)) return Reflect.apply(bigintValue, value, []);
|
|
7470
7529
|
return void 0;
|
|
7471
7530
|
}
|
|
7472
7531
|
function createSandboxBox(value) {
|
|
@@ -7645,7 +7704,7 @@ async function withRunResources(signal, execute) {
|
|
|
7645
7704
|
}
|
|
7646
7705
|
|
|
7647
7706
|
// packages/safe-js/src/interp/host-capabilities.ts
|
|
7648
|
-
import { types as
|
|
7707
|
+
import { types as types6 } from "node:util";
|
|
7649
7708
|
var MAX_INDEXED_LENGTH = 65536;
|
|
7650
7709
|
var MAX_NAMED_KEYS = 65536;
|
|
7651
7710
|
var MAX_NAMED_KEY_CODE_UNITS = 1048576;
|
|
@@ -7700,7 +7759,7 @@ function createLiveHostObject(definition, controller) {
|
|
|
7700
7759
|
for (const name of ["keys", "get", "set", "delete"]) {
|
|
7701
7760
|
const operation = data[name];
|
|
7702
7761
|
if (operation === void 0 && (name === "set" || name === "delete")) continue;
|
|
7703
|
-
if (typeof operation !== "function" ||
|
|
7762
|
+
if (typeof operation !== "function" || types6.isProxy(operation) || types6.isAsyncFunction(operation) || types6.isGeneratorFunction(operation))
|
|
7704
7763
|
throw new TypeError(`Named ${name} must be a synchronous non-generator function, not a proxy.`);
|
|
7705
7764
|
}
|
|
7706
7765
|
if (typeof data.maxKeys !== "number" || !Number.isInteger(data.maxKeys) || data.maxKeys < 1 || data.maxKeys > MAX_NAMED_KEYS)
|
|
@@ -7747,13 +7806,13 @@ function createLiveHostObject(definition, controller) {
|
|
|
7747
7806
|
controller.chargeWork(properties.size + Object.keys(operations).length + 1);
|
|
7748
7807
|
const host = Object.freeze(/* @__PURE__ */ Object.create(null));
|
|
7749
7808
|
const guest = Object.freeze(/* @__PURE__ */ Object.create(null));
|
|
7750
|
-
const
|
|
7809
|
+
const methods2 = new Map(
|
|
7751
7810
|
Object.entries(operations).map(([name, operation]) => [
|
|
7752
7811
|
name,
|
|
7753
7812
|
controller.method(operation)
|
|
7754
7813
|
])
|
|
7755
7814
|
);
|
|
7756
|
-
const state = { host, guest, controller, properties, methods, indexed, named };
|
|
7815
|
+
const state = { host, guest, controller, properties, methods: methods2, indexed, named };
|
|
7757
7816
|
hostObjects.set(host, state);
|
|
7758
7817
|
guestObjects.set(guest, state);
|
|
7759
7818
|
return host;
|
|
@@ -7955,7 +8014,7 @@ function namedMutationKeys(state, key, create) {
|
|
|
7955
8014
|
function namedKeys(state) {
|
|
7956
8015
|
const named = state.named;
|
|
7957
8016
|
return state.controller.read(named.keys, (value) => {
|
|
7958
|
-
if (!Array.isArray(value) ||
|
|
8017
|
+
if (!Array.isArray(value) || types6.isProxy(value))
|
|
7959
8018
|
throw new TypeError("Named keys must be a dense own-data array of strings, not a proxy.");
|
|
7960
8019
|
const length = Object.getOwnPropertyDescriptor(value, "length").value;
|
|
7961
8020
|
if (length > named.maxKeys) throw new RangeError("Named keys exceed maxKeys.");
|
|
@@ -8141,11 +8200,11 @@ function isIntrinsicFunction(value) {
|
|
|
8141
8200
|
function registerIntrinsicPrototype(budget, prototype, constructor) {
|
|
8142
8201
|
if (constructor.name === void 0) throw new TypeError("Intrinsic constructors require an installation name.");
|
|
8143
8202
|
registerBuiltinIdentities(budget, { [constructor.name]: constructor });
|
|
8144
|
-
const
|
|
8203
|
+
const methods2 = [prototype, materializeFunctionProperties(constructor)].flatMap((owner) => Reflect.ownKeys(owner).flatMap((key) => {
|
|
8145
8204
|
const descriptor = Object.getOwnPropertyDescriptor(owner, key);
|
|
8146
8205
|
return [descriptor.value, ...retainedAccessorClosures(descriptor)];
|
|
8147
8206
|
})).filter(isGuestClosure);
|
|
8148
|
-
trackIntrinsicState(budget, prototype, constructor, [prototype, constructor, ...
|
|
8207
|
+
trackIntrinsicState(budget, prototype, constructor, [prototype, constructor, ...methods2]);
|
|
8149
8208
|
}
|
|
8150
8209
|
function registerIntrinsicFunction(budget, closure) {
|
|
8151
8210
|
if (closure.name === void 0) throw new TypeError("Intrinsic functions require an installation name.");
|
|
@@ -8154,8 +8213,8 @@ function registerIntrinsicFunction(budget, closure) {
|
|
|
8154
8213
|
trackIntrinsicState(budget, closure, closure, [closure]);
|
|
8155
8214
|
}
|
|
8156
8215
|
function registerIntrinsicObject(budget, value) {
|
|
8157
|
-
const
|
|
8158
|
-
trackIntrinsicState(budget, value, value, [value, ...
|
|
8216
|
+
const methods2 = Object.values(Object.getOwnPropertyDescriptors(value)).map((descriptor) => descriptor.value).filter(isGuestClosure);
|
|
8217
|
+
trackIntrinsicState(budget, value, value, [value, ...methods2]);
|
|
8159
8218
|
}
|
|
8160
8219
|
function trackIntrinsicState(budget, root, owner, targets) {
|
|
8161
8220
|
let roots = intrinsicPrototypeRoots.get(budget);
|
|
@@ -8228,6 +8287,7 @@ function getSandboxPrototype(value, budget) {
|
|
|
8228
8287
|
if (prototypes.has(value)) return prototypes.get(value) ?? null;
|
|
8229
8288
|
if (budget === void 0) return null;
|
|
8230
8289
|
if (isSandboxArrayBuffer(value)) return budget === void 0 ? null : arrayBufferPrototypes.get(budget) ?? null;
|
|
8290
|
+
if (isSandboxDataView(value)) return dataViewPrototypes.get(budget) ?? null;
|
|
8231
8291
|
if (isNumericTypedArray(value)) return budget === void 0 ? null : typedArrayPrototypes.get(budget)?.get(typedArrayStorage(value).Native) ?? null;
|
|
8232
8292
|
const errorType = sandboxErrorTypes.get(value);
|
|
8233
8293
|
if (budget !== void 0 && errorType !== void 0) {
|
|
@@ -8338,6 +8398,7 @@ function setSandboxPrototype(value, prototype, budget) {
|
|
|
8338
8398
|
prototypes.set(value, prototype);
|
|
8339
8399
|
}
|
|
8340
8400
|
function isPrototypeRecord(value) {
|
|
8401
|
+
if (isSandboxDataView(value)) return true;
|
|
8341
8402
|
if (isSandboxArrayBuffer(value)) return true;
|
|
8342
8403
|
if (isNumericTypedArray(value)) return true;
|
|
8343
8404
|
if (isGuestClosure(value)) return true;
|
|
@@ -8603,7 +8664,7 @@ function restoreRegexProperties(value, data, decode) {
|
|
|
8603
8664
|
}
|
|
8604
8665
|
|
|
8605
8666
|
// packages/safe-js/src/snapshot/validation.ts
|
|
8606
|
-
import { types as
|
|
8667
|
+
import { types as types8 } from "node:util";
|
|
8607
8668
|
|
|
8608
8669
|
// packages/safe-js/src/interp/builtin-call.ts
|
|
8609
8670
|
async function invokeBuiltinClosure(closure, args, budget, context, thisValue, construct = false) {
|
|
@@ -11017,7 +11078,7 @@ function formatNumber(value, methodName, argument, budget) {
|
|
|
11017
11078
|
}
|
|
11018
11079
|
|
|
11019
11080
|
// packages/safe-js/src/interp/methods/string.ts
|
|
11020
|
-
import { types as
|
|
11081
|
+
import { types as types7 } from "node:util";
|
|
11021
11082
|
|
|
11022
11083
|
// packages/safe-js/src/interp/methods/string-locale.ts
|
|
11023
11084
|
var collatorOptions = [
|
|
@@ -11168,7 +11229,7 @@ function callStringMethod(value, methodName, args, budget, callClosure = async (
|
|
|
11168
11229
|
};
|
|
11169
11230
|
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;
|
|
11170
11231
|
const pattern = args[0];
|
|
11171
|
-
if (symbol !== void 0 &&
|
|
11232
|
+
if (symbol !== void 0 && types7.isRegExp(pattern))
|
|
11172
11233
|
throw new TypeError(`String#${methodName} does not accept unbranded host RegExp values.`);
|
|
11173
11234
|
if (symbol === void 0 || pattern === null || pattern === void 0) return fallback();
|
|
11174
11235
|
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);
|
|
@@ -11920,7 +11981,7 @@ function createPrimitiveConstructor(options, budget) {
|
|
|
11920
11981
|
writable: isSandboxClosure(value),
|
|
11921
11982
|
configurable: isSandboxClosure(value)
|
|
11922
11983
|
});
|
|
11923
|
-
const
|
|
11984
|
+
const methods2 = /* @__PURE__ */ new Map([
|
|
11924
11985
|
[
|
|
11925
11986
|
"valueOf",
|
|
11926
11987
|
createSandboxClosure({
|
|
@@ -11932,9 +11993,9 @@ function createPrimitiveConstructor(options, budget) {
|
|
|
11932
11993
|
]
|
|
11933
11994
|
]);
|
|
11934
11995
|
if (kind === "number") {
|
|
11935
|
-
for (const name of numberMethodNames)
|
|
11996
|
+
for (const name of numberMethodNames) methods2.set(name, getNumberMember(name, budget));
|
|
11936
11997
|
} else {
|
|
11937
|
-
|
|
11998
|
+
methods2.set(
|
|
11938
11999
|
"toString",
|
|
11939
12000
|
createSandboxClosure({
|
|
11940
12001
|
sandbox: true,
|
|
@@ -11944,9 +12005,9 @@ function createPrimitiveConstructor(options, budget) {
|
|
|
11944
12005
|
})
|
|
11945
12006
|
);
|
|
11946
12007
|
if (kind === "string")
|
|
11947
|
-
for (const name of stringMethodNames)
|
|
12008
|
+
for (const name of stringMethodNames) methods2.set(name, getStringMember("", name, budget));
|
|
11948
12009
|
}
|
|
11949
|
-
for (const [name, value] of
|
|
12010
|
+
for (const [name, value] of methods2)
|
|
11950
12011
|
Object.defineProperty(prototype, name, { value, writable: true, configurable: true });
|
|
11951
12012
|
installBoxedPrototype(budget, prototype, constructor);
|
|
11952
12013
|
return constructor;
|
|
@@ -19804,7 +19865,7 @@ function toPropertyKey(value, budget, context) {
|
|
|
19804
19865
|
}
|
|
19805
19866
|
|
|
19806
19867
|
// packages/safe-js/src/interp/globals/object.ts
|
|
19807
|
-
function createObjectGlobal(
|
|
19868
|
+
function createObjectGlobal(methods2, budget) {
|
|
19808
19869
|
const construct = ([value]) => {
|
|
19809
19870
|
if (value === null || value === void 0) {
|
|
19810
19871
|
budget.chargeDataUsage(1);
|
|
@@ -19839,7 +19900,7 @@ function createObjectGlobal(methods, budget) {
|
|
|
19839
19900
|
const properties = materializeFunctionProperties(constructor);
|
|
19840
19901
|
const prototype = properties.prototype;
|
|
19841
19902
|
Object.defineProperty(properties, "prototype", { writable: false });
|
|
19842
|
-
for (const [name, method] of Object.entries(
|
|
19903
|
+
for (const [name, method] of Object.entries(methods2)) {
|
|
19843
19904
|
Object.defineProperty(properties, name, { value: method, writable: true, configurable: true });
|
|
19844
19905
|
}
|
|
19845
19906
|
const prototypeMethods = {
|
|
@@ -21896,6 +21957,39 @@ function snapshotTypedArrayConstructor(value) {
|
|
|
21896
21957
|
return numericTypedArrayConstructors[value.arrayType];
|
|
21897
21958
|
}
|
|
21898
21959
|
|
|
21960
|
+
// packages/safe-js/src/snapshot/data-view.ts
|
|
21961
|
+
function encodeDataViewLayout(value) {
|
|
21962
|
+
const layout = dataViewLayout(value);
|
|
21963
|
+
return {
|
|
21964
|
+
kind: "dataview",
|
|
21965
|
+
byteOffset: layout.byteOffset,
|
|
21966
|
+
byteLength: layout.byteLength ?? 0,
|
|
21967
|
+
...layout.byteLength === void 0 ? { lengthTracking: true } : {}
|
|
21968
|
+
};
|
|
21969
|
+
}
|
|
21970
|
+
function captureDataViewState(value, encode) {
|
|
21971
|
+
return {
|
|
21972
|
+
properties: serializePropertyDescriptors(value, encode),
|
|
21973
|
+
...hasExplicitSandboxPrototype(value) ? { prototype: encode(getSandboxPrototype(value)) } : {}
|
|
21974
|
+
};
|
|
21975
|
+
}
|
|
21976
|
+
function validateDataViewStorage(value) {
|
|
21977
|
+
if (!Number.isSafeInteger(value.byteOffset) || Number(value.byteOffset) < 0 || !Number.isSafeInteger(value.byteLength) || Number(value.byteLength) < 0 || !Number.isSafeInteger(Number(value.byteOffset) + Number(value.byteLength)))
|
|
21978
|
+
throw new TypeError("Invalid DataView dimensions.");
|
|
21979
|
+
if (!Object.hasOwn(value, "buffer") || Object.hasOwn(value, "bytes")) throw new TypeError("DataView requires a backing buffer reference.");
|
|
21980
|
+
if (Object.hasOwn(value, "lengthTracking") && (value.lengthTracking !== true || value.byteLength !== 0))
|
|
21981
|
+
throw new TypeError("Invalid DataView length-tracking layout.");
|
|
21982
|
+
}
|
|
21983
|
+
function decodeDataViewStorage(value, resolve, budget) {
|
|
21984
|
+
validateDataViewStorage(value);
|
|
21985
|
+
const buffer = resolve(value.buffer);
|
|
21986
|
+
if (!isSandboxArrayBuffer(buffer)) throw new TypeError("Invalid DataView backing reference.");
|
|
21987
|
+
if (value.lengthTracking === true && arrayBufferOptions(buffer) === void 0)
|
|
21988
|
+
throw new TypeError("Length-tracking DataView requires resizable storage.");
|
|
21989
|
+
budget?.provisionDataUsage(1)();
|
|
21990
|
+
return restoreDataView(buffer, Number(value.byteOffset), value.lengthTracking === true ? void 0 : Number(value.byteLength), budget);
|
|
21991
|
+
}
|
|
21992
|
+
|
|
21899
21993
|
// packages/safe-js/src/snapshot/array-buffer.ts
|
|
21900
21994
|
function captureArrayBufferState(value, encode) {
|
|
21901
21995
|
return {
|
|
@@ -22077,10 +22171,10 @@ function serializeDumpValue(value, path, state) {
|
|
|
22077
22171
|
}
|
|
22078
22172
|
return { kind: "ref", id };
|
|
22079
22173
|
}
|
|
22080
|
-
if (hasGuestObjectState(value) && !(state.trustedRunReplay && (isSandboxDate(value) || isSandboxPromise(value) || isPromiseResolvingFunction(value)))) {
|
|
22174
|
+
if (hasGuestObjectState(value) && !isSandboxDataView(value) && !(state.trustedRunReplay && (isSandboxDate(value) || isSandboxPromise(value) || isPromiseResolvingFunction(value)))) {
|
|
22081
22175
|
throw new TypeError("Guest function properties and prototype links cannot be serialized.");
|
|
22082
22176
|
}
|
|
22083
|
-
if (isSandboxArrayBuffer(value) || isSandboxRegExpIterator(value) || isSandboxRegex(value) && hasCustomRegexProperties(value) || isSandboxBox(value) || isSandboxDate(value) || isNumericTypedArray(value)) return serializeHeapReference(value, path, state);
|
|
22177
|
+
if (isSandboxDataView(value) || isSandboxArrayBuffer(value) || isSandboxRegExpIterator(value) || isSandboxRegex(value) && hasCustomRegexProperties(value) || isSandboxBox(value) || isSandboxDate(value) || isNumericTypedArray(value)) return serializeHeapReference(value, path, state);
|
|
22084
22178
|
if (Array.isArray(value)) {
|
|
22085
22179
|
const reference2 = serializeHeapReference(value, path, state);
|
|
22086
22180
|
if (reference2 !== void 0) {
|
|
@@ -22152,6 +22246,18 @@ function serializeHeapReference(value, path, state) {
|
|
|
22152
22246
|
const serialized = serializeDumpValue(entry, `${path}.<date-property>`, state);
|
|
22153
22247
|
return serialized === SKIP_VALUE ? { kind: "undefined" } : serialized;
|
|
22154
22248
|
});
|
|
22249
|
+
} else if (isSandboxDataView(value)) {
|
|
22250
|
+
state.heap[String(id)] = {
|
|
22251
|
+
...encodeDataViewLayout(value),
|
|
22252
|
+
buffer: serializeHeapReference(dataViewBuffer(value), `${path}.buffer`, state),
|
|
22253
|
+
state: captureDataViewState(value, (entry) => {
|
|
22254
|
+
if (entry === void 0) return { kind: "undefined" };
|
|
22255
|
+
if (Object.is(entry, -0)) return { kind: "number", value: "-0" };
|
|
22256
|
+
const serialized = serializeDumpValue(entry, `${path}.<view>`, state);
|
|
22257
|
+
if (serialized === SKIP_VALUE) throw new TypeError("Unsupported DataView property in public dump.");
|
|
22258
|
+
return serialized;
|
|
22259
|
+
})
|
|
22260
|
+
};
|
|
22155
22261
|
} else if (isSandboxArrayBuffer(value)) {
|
|
22156
22262
|
state.heap[String(id)] = {
|
|
22157
22263
|
...encodeArrayBufferStorage(value, id, state.float32Buffers, (id2) => ({ kind: "ref", id: id2 })),
|
|
@@ -22231,7 +22337,7 @@ function indexHeapContainers(snapshot) {
|
|
|
22231
22337
|
const heapIds = /* @__PURE__ */ new Map();
|
|
22232
22338
|
let nextId = 1;
|
|
22233
22339
|
for (const [value, stat2] of stats.entries()) {
|
|
22234
|
-
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) || isNumericTypedArray(value) || isSandboxArrayBuffer(value) || Array.isArray(value) && requiresArrayEntries(value) || isSandboxArguments(value) || sandboxErrorTypes.has(value)) {
|
|
22340
|
+
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) || isNumericTypedArray(value) || isSandboxArrayBuffer(value) || isSandboxDataView(value) || Array.isArray(value) && requiresArrayEntries(value) || isSandboxArguments(value) || sandboxErrorTypes.has(value)) {
|
|
22235
22341
|
heapIds.set(value, nextId);
|
|
22236
22342
|
nextId += 1;
|
|
22237
22343
|
}
|
|
@@ -22263,8 +22369,12 @@ function collectContainerStats(value, stats, ancestors, guestValues, depth = 0)
|
|
|
22263
22369
|
stat2.expanded = true;
|
|
22264
22370
|
ancestors.add(value);
|
|
22265
22371
|
const guestEntries = [];
|
|
22372
|
+
if (isSandboxDataView(value)) guestEntries.push(dataViewBuffer(value));
|
|
22266
22373
|
if (isNumericTypedArray(value)) guestEntries.push(typedArrayStorage(value).buffer);
|
|
22267
|
-
const guest =
|
|
22374
|
+
const guest = isSandboxDataView(value) ? { kind: "dataview", state: captureDataViewState(value, (entry) => {
|
|
22375
|
+
guestEntries.push(entry);
|
|
22376
|
+
return null;
|
|
22377
|
+
}) } : isSandboxArrayBuffer(value) ? { kind: "arraybuffer", state: captureArrayBufferState(value, (entry) => {
|
|
22268
22378
|
guestEntries.push(entry);
|
|
22269
22379
|
return null;
|
|
22270
22380
|
}) } : captureGuestHeapNode(value, (entry) => {
|
|
@@ -22272,7 +22382,7 @@ function collectContainerStats(value, stats, ancestors, guestValues, depth = 0)
|
|
|
22272
22382
|
return null;
|
|
22273
22383
|
});
|
|
22274
22384
|
if (guest !== void 0) {
|
|
22275
|
-
if (!isSandboxArrayBuffer(value)) guestValues.add(value);
|
|
22385
|
+
if (!isSandboxArrayBuffer(value) && !isSandboxDataView(value)) guestValues.add(value);
|
|
22276
22386
|
for (const entry of guestEntries) {
|
|
22277
22387
|
collectContainerStats(entry, stats, ancestors, guestValues, depth + 1);
|
|
22278
22388
|
if (entry !== null && typeof entry === "object") stats.get(entry).forceHeap = true;
|
|
@@ -22600,10 +22710,10 @@ function encodeReplayData(value, options = {}) {
|
|
|
22600
22710
|
...symbolProperties.length === 0 ? {} : { symbolProperties },
|
|
22601
22711
|
...Object.isExtensible(entry) ? {} : { extensible: false }
|
|
22602
22712
|
};
|
|
22603
|
-
} else if (isSandboxArrayBuffer(entry)) {
|
|
22604
|
-
const storage = encodeArrayBufferStorage(entry, id, float32Buffers, (id2) => ({ tag: "ref", id: id2 }));
|
|
22713
|
+
} else if (isSandboxArrayBuffer(entry) || isSandboxDataView(entry)) {
|
|
22714
|
+
const storage = isSandboxDataView(entry) ? { ...encodeDataViewLayout(entry), buffer: child(dataViewBuffer(entry), "<buffer>") } : encodeArrayBufferStorage(entry, id, float32Buffers, (id2) => ({ tag: "ref", id: id2 }));
|
|
22605
22715
|
const properties = /* @__PURE__ */ Object.create(null);
|
|
22606
|
-
for (const [key, descriptor] of arrayBufferDataProperties(entry)) {
|
|
22716
|
+
for (const [key, descriptor] of isSandboxDataView(entry) ? dataViewDataProperties(entry) : arrayBufferDataProperties(entry)) {
|
|
22607
22717
|
if (typeof key === "symbol") continue;
|
|
22608
22718
|
properties[key] = {
|
|
22609
22719
|
value: child(descriptor.value, key),
|
|
@@ -22846,9 +22956,9 @@ function decodeReplayData(input, options = {}, parent) {
|
|
|
22846
22956
|
if (node.extensible === false) Object.preventExtensions(result3);
|
|
22847
22957
|
return result3;
|
|
22848
22958
|
}
|
|
22849
|
-
if (kind === "arraybuffer") {
|
|
22959
|
+
if (kind === "arraybuffer" || kind === "dataview") {
|
|
22850
22960
|
if (typeof node.extensible !== "boolean") throw new TypeError("Invalid ArrayBuffer extensibility.");
|
|
22851
|
-
const result3 = decodeArrayBufferStorage(node, child, compilation.owner?.budget, detachBuffers);
|
|
22961
|
+
const result3 = kind === "dataview" ? decodeDataViewStorage(node, child, compilation.owner?.budget) : decodeArrayBufferStorage(node, child, compilation.owner?.budget, detachBuffers);
|
|
22852
22962
|
restored.set(id, result3);
|
|
22853
22963
|
initializeValues.push(() => {
|
|
22854
22964
|
defineProperties(result3, record2(own(node, "properties")), child, node.symbolEntries);
|
|
@@ -23746,6 +23856,38 @@ function copyHostValueToSandbox(value, stackFrames, options, state, path) {
|
|
|
23746
23856
|
state.seen.set(value, date);
|
|
23747
23857
|
return date;
|
|
23748
23858
|
}
|
|
23859
|
+
if (isSandboxDataView(value)) {
|
|
23860
|
+
const existing = state.seen.get(value);
|
|
23861
|
+
if (existing !== void 0) return existing;
|
|
23862
|
+
const buffer = dataViewBuffer(value);
|
|
23863
|
+
const length = arrayBufferLength(buffer);
|
|
23864
|
+
budget.allocateArrayLength(arrayBufferOptions(buffer)?.maxByteLength ?? length);
|
|
23865
|
+
budget.provisionDataUsage(length + 2)();
|
|
23866
|
+
const copy = copyDataViewStorage(value, state);
|
|
23867
|
+
state.seen.set(value, copy);
|
|
23868
|
+
copyHostValueToSandbox(
|
|
23869
|
+
buffer,
|
|
23870
|
+
stackFrames,
|
|
23871
|
+
{ ...options, capabilityPath: [...options.capabilityPath ?? [], "buffer"] },
|
|
23872
|
+
state,
|
|
23873
|
+
`${path}.buffer`
|
|
23874
|
+
);
|
|
23875
|
+
for (const [key, descriptor] of dataViewDataProperties(value)) {
|
|
23876
|
+
if (typeof key !== "string") throw new TypeError("Host DataView symbol properties require an explicit capability path.");
|
|
23877
|
+
Object.defineProperty(copy, key, {
|
|
23878
|
+
...descriptor,
|
|
23879
|
+
value: copyHostValueToSandbox(
|
|
23880
|
+
descriptor.value,
|
|
23881
|
+
stackFrames,
|
|
23882
|
+
{ ...options, capabilityPath: [...options.capabilityPath ?? [], key] },
|
|
23883
|
+
state,
|
|
23884
|
+
joinPath(path, key)
|
|
23885
|
+
)
|
|
23886
|
+
});
|
|
23887
|
+
}
|
|
23888
|
+
if (!Object.isExtensible(value)) Object.preventExtensions(copy);
|
|
23889
|
+
return copy;
|
|
23890
|
+
}
|
|
23749
23891
|
if (isSandboxArrayBuffer(value)) {
|
|
23750
23892
|
const existing = state.seen.get(value);
|
|
23751
23893
|
if (existing !== void 0) return existing;
|
|
@@ -24135,9 +24277,9 @@ function createDateGlobal(options) {
|
|
|
24135
24277
|
call: (args, context) => coerceDateParts(args, true, options.budget, context)
|
|
24136
24278
|
})
|
|
24137
24279
|
};
|
|
24138
|
-
const
|
|
24280
|
+
const methods2 = /* @__PURE__ */ new Map();
|
|
24139
24281
|
for (const [name, method] of dateMethods)
|
|
24140
|
-
|
|
24282
|
+
methods2.set(
|
|
24141
24283
|
name,
|
|
24142
24284
|
createSandboxClosure({
|
|
24143
24285
|
guest: true,
|
|
@@ -24157,8 +24299,8 @@ function createDateGlobal(options) {
|
|
|
24157
24299
|
}
|
|
24158
24300
|
})
|
|
24159
24301
|
);
|
|
24160
|
-
|
|
24161
|
-
|
|
24302
|
+
methods2.set("toGMTString", methods2.get("toUTCString"));
|
|
24303
|
+
methods2.set(Symbol.toPrimitive, createSandboxClosure({
|
|
24162
24304
|
guest: true,
|
|
24163
24305
|
sandbox: true,
|
|
24164
24306
|
name: "[Symbol.toPrimitive]",
|
|
@@ -24174,7 +24316,7 @@ function createDateGlobal(options) {
|
|
|
24174
24316
|
for (const [key, value] of Object.entries(staticProperties))
|
|
24175
24317
|
Object.defineProperty(properties, key, { value, writable: key !== "prototype", configurable: key !== "prototype" });
|
|
24176
24318
|
Object.defineProperty(prototype, "constructor", { value: constructor, writable: true, configurable: true });
|
|
24177
|
-
for (const [key, value] of
|
|
24319
|
+
for (const [key, value] of methods2)
|
|
24178
24320
|
Object.defineProperty(prototype, key, { value, writable: key !== Symbol.toPrimitive, configurable: true });
|
|
24179
24321
|
installDatePrototype(options.budget, prototype, constructor);
|
|
24180
24322
|
return constructor;
|
|
@@ -24626,7 +24768,7 @@ function installCollectionPrototypes(budget, mapConstructor, setConstructor) {
|
|
|
24626
24768
|
return context.thisValue.values.size;
|
|
24627
24769
|
}
|
|
24628
24770
|
});
|
|
24629
|
-
for (const { name, constructor, methods, size, iterator } of [
|
|
24771
|
+
for (const { name, constructor, methods: methods2, size, iterator } of [
|
|
24630
24772
|
{ name: "Map", constructor: mapConstructor, methods: mapMethods, size: mapSize, iterator: mapMethods.entries },
|
|
24631
24773
|
{ name: "Set", constructor: setConstructor, methods: setMethods, size: setSize, iterator: setMethods.values }
|
|
24632
24774
|
]) {
|
|
@@ -24641,13 +24783,13 @@ function installCollectionPrototypes(budget, mapConstructor, setConstructor) {
|
|
|
24641
24783
|
Object.defineProperty(materializeFunctionProperties(constructor), "prototype", { value: prototype, writable: false });
|
|
24642
24784
|
Object.defineProperty(materializeFunctionProperties(constructor), Symbol.species, { get: accessorAdapter(species, "get"), configurable: true });
|
|
24643
24785
|
Object.defineProperty(prototype, "constructor", { value: constructor, writable: true, configurable: true });
|
|
24644
|
-
for (const [key, method] of Object.entries(
|
|
24786
|
+
for (const [key, method] of Object.entries(methods2))
|
|
24645
24787
|
Object.defineProperty(prototype, key, { value: method, writable: true, configurable: true });
|
|
24646
24788
|
Object.defineProperty(prototype, "size", { get: accessorAdapter(size, "get"), configurable: true });
|
|
24647
24789
|
Object.defineProperty(prototype, Symbol.toStringTag, { value: name, configurable: true });
|
|
24648
24790
|
Object.defineProperty(prototype, Symbol.iterator, { value: iterator, writable: true, configurable: true });
|
|
24649
24791
|
installCollectionPrototype(budget, name, prototype, constructor);
|
|
24650
|
-
for (const method of /* @__PURE__ */ new Set([...Object.values(
|
|
24792
|
+
for (const method of /* @__PURE__ */ new Set([...Object.values(methods2), size, species])) registerIntrinsicFunction(budget, method);
|
|
24651
24793
|
}
|
|
24652
24794
|
}
|
|
24653
24795
|
|
|
@@ -25665,7 +25807,7 @@ function createSymbolGlobal(budget) {
|
|
|
25665
25807
|
});
|
|
25666
25808
|
const properties = materializeFunctionProperties(constructor);
|
|
25667
25809
|
Object.defineProperty(properties, "prototype", { value: prototype });
|
|
25668
|
-
const
|
|
25810
|
+
const methods2 = {
|
|
25669
25811
|
for: createSandboxClosure({
|
|
25670
25812
|
sandbox: true,
|
|
25671
25813
|
name: "for",
|
|
@@ -25691,7 +25833,7 @@ function createSymbolGlobal(budget) {
|
|
|
25691
25833
|
}
|
|
25692
25834
|
})
|
|
25693
25835
|
};
|
|
25694
|
-
for (const [name, method] of Object.entries(
|
|
25836
|
+
for (const [name, method] of Object.entries(methods2)) {
|
|
25695
25837
|
Object.defineProperty(properties, name, { value: method, writable: true, configurable: true });
|
|
25696
25838
|
}
|
|
25697
25839
|
for (const [name, value] of Object.entries(wellKnownSymbols)) {
|
|
@@ -25707,28 +25849,28 @@ function createSymbolGlobal(budget) {
|
|
|
25707
25849
|
}
|
|
25708
25850
|
|
|
25709
25851
|
// packages/safe-js/src/interp/globals/bigint.ts
|
|
25852
|
+
async function sandboxBigInt(value, budget, context, allowNumber = false) {
|
|
25853
|
+
const primitive = value !== null && typeof value === "object" ? await objectToPrimitive(value, budget, context, /* @__PURE__ */ new Set(), "number") : value;
|
|
25854
|
+
if (typeof primitive === "bigint") return primitive;
|
|
25855
|
+
if (typeof primitive !== "string" && typeof primitive !== "boolean" && !(allowNumber && typeof primitive === "number"))
|
|
25856
|
+
throw new TypeError("Cannot convert value to BigInt.");
|
|
25857
|
+
const size = typeof primitive === "string" ? primitive.length : 256;
|
|
25858
|
+
budget.visitNode(size);
|
|
25859
|
+
const allocation = {};
|
|
25860
|
+
budget.setRetainedDataUsage(allocation, size);
|
|
25861
|
+
try {
|
|
25862
|
+
return BigInt(primitive);
|
|
25863
|
+
} finally {
|
|
25864
|
+
budget.setRetainedDataUsage(allocation, 0);
|
|
25865
|
+
}
|
|
25866
|
+
}
|
|
25710
25867
|
function createBigIntGlobal(budget) {
|
|
25711
|
-
const convert = async (value, context, allowNumber = false) => {
|
|
25712
|
-
const primitive = value !== null && typeof value === "object" ? await objectToPrimitive(value, budget, context, /* @__PURE__ */ new Set(), "number") : value;
|
|
25713
|
-
if (typeof primitive === "bigint") return primitive;
|
|
25714
|
-
if (typeof primitive !== "string" && typeof primitive !== "boolean" && !(allowNumber && typeof primitive === "number"))
|
|
25715
|
-
throw new TypeError("Cannot convert value to BigInt.");
|
|
25716
|
-
const size = typeof primitive === "string" ? primitive.length : 256;
|
|
25717
|
-
budget.visitNode(size);
|
|
25718
|
-
const allocation = {};
|
|
25719
|
-
budget.setRetainedDataUsage(allocation, size);
|
|
25720
|
-
try {
|
|
25721
|
-
return BigInt(primitive);
|
|
25722
|
-
} finally {
|
|
25723
|
-
budget.setRetainedDataUsage(allocation, 0);
|
|
25724
|
-
}
|
|
25725
|
-
};
|
|
25726
25868
|
const constructor = createSandboxClosure({
|
|
25727
25869
|
guest: true,
|
|
25728
25870
|
sandbox: true,
|
|
25729
25871
|
name: "BigInt",
|
|
25730
25872
|
length: 1,
|
|
25731
|
-
call: ([value], context) =>
|
|
25873
|
+
call: ([value], context) => sandboxBigInt(value, budget, context, true)
|
|
25732
25874
|
});
|
|
25733
25875
|
const prototype = /* @__PURE__ */ Object.create(null);
|
|
25734
25876
|
Object.defineProperties(prototype, {
|
|
@@ -25792,7 +25934,7 @@ function createBigIntGlobal(budget) {
|
|
|
25792
25934
|
const number = await sandboxNumber(bits, budget, context);
|
|
25793
25935
|
const width = Number.isNaN(number) ? 0 : Math.trunc(number);
|
|
25794
25936
|
if (width < 0 || !Number.isSafeInteger(width)) throw new RangeError("Invalid BigInt width.");
|
|
25795
|
-
const value = await
|
|
25937
|
+
const value = await sandboxBigInt(input, budget, context);
|
|
25796
25938
|
const size = value.toString(16).length;
|
|
25797
25939
|
budget.visitNode(size);
|
|
25798
25940
|
if (width >= size * 4 + 1 && (name === "asIntN" || value >= 0n)) return value;
|
|
@@ -26056,6 +26198,129 @@ function createArrayBufferGlobal(budget) {
|
|
|
26056
26198
|
return constructor;
|
|
26057
26199
|
}
|
|
26058
26200
|
|
|
26201
|
+
// packages/safe-js/src/interp/globals/data-view.ts
|
|
26202
|
+
var methods = Object.fromEntries(["Int8", "Uint8", "Int16", "Uint16", "Int32", "Uint32", "Float32", "Float64", "BigInt64", "BigUint64"].flatMap((type) => ["get", "set"].map((operation) => [operation + type, Object.getOwnPropertyDescriptor(DataView.prototype, operation + type).value])));
|
|
26203
|
+
var readUint16 = DataView.prototype.getUint16;
|
|
26204
|
+
var writeUint16 = DataView.prototype.setUint16;
|
|
26205
|
+
methods.getFloat16 = function(...args) {
|
|
26206
|
+
const bits = Reflect.apply(readUint16, this, args);
|
|
26207
|
+
const sign = bits & 32768 ? -1 : 1;
|
|
26208
|
+
const exponent = bits >> 10 & 31, fraction = bits & 1023;
|
|
26209
|
+
if (exponent === 31) return fraction === 0 ? sign * Infinity : NaN;
|
|
26210
|
+
return sign * (exponent === 0 ? fraction * 2 ** -24 : (1 + fraction / 1024) * 2 ** (exponent - 15));
|
|
26211
|
+
};
|
|
26212
|
+
methods.setFloat16 = function(...args) {
|
|
26213
|
+
const rounded = f16round(args[1]);
|
|
26214
|
+
const sign = rounded < 0 || Object.is(rounded, -0) ? 32768 : 0;
|
|
26215
|
+
const magnitude = Math.abs(rounded);
|
|
26216
|
+
let bits;
|
|
26217
|
+
if (Number.isNaN(magnitude)) bits = 32256;
|
|
26218
|
+
else if (magnitude === Infinity) bits = 31744;
|
|
26219
|
+
else if (magnitude < 2 ** -14) bits = magnitude * 2 ** 24;
|
|
26220
|
+
else {
|
|
26221
|
+
const exponent = Math.floor(Math.log2(magnitude));
|
|
26222
|
+
bits = exponent + 15 << 10 | (magnitude / 2 ** exponent - 1) * 1024;
|
|
26223
|
+
}
|
|
26224
|
+
return Reflect.apply(writeUint16, this, [args[0], sign | bits, args[2]]);
|
|
26225
|
+
};
|
|
26226
|
+
function createDataViewGlobal(budget) {
|
|
26227
|
+
const prototype = /* @__PURE__ */ Object.create(null);
|
|
26228
|
+
const constructor = createSandboxClosure({
|
|
26229
|
+
guest: true,
|
|
26230
|
+
sandbox: true,
|
|
26231
|
+
name: "DataView",
|
|
26232
|
+
length: 1,
|
|
26233
|
+
call: () => {
|
|
26234
|
+
throw new TypeError("DataView requires new.");
|
|
26235
|
+
},
|
|
26236
|
+
construct: async (args, context) => {
|
|
26237
|
+
const buffer = args[0];
|
|
26238
|
+
if (!isSandboxArrayBuffer(buffer)) throw new TypeError("DataView requires an ArrayBuffer.");
|
|
26239
|
+
let selected;
|
|
26240
|
+
const release = retainValues(budget, () => [...args, selected]);
|
|
26241
|
+
try {
|
|
26242
|
+
const offset = await dataViewIndex(args[1], budget, context);
|
|
26243
|
+
if (arrayBufferDetached(buffer)) throw new TypeError("Cannot view a detached buffer.");
|
|
26244
|
+
const length = arrayBufferLength(buffer);
|
|
26245
|
+
if (offset > length) throw new RangeError("DataView offset exceeds buffer length.");
|
|
26246
|
+
const size = args[2] === void 0 ? void 0 : await dataViewIndex(args[2], budget, context);
|
|
26247
|
+
if (size !== void 0 && offset + size > length) throw new RangeError("DataView length exceeds buffer length.");
|
|
26248
|
+
const target = context?.newTarget ?? constructor;
|
|
26249
|
+
if (context?.getProperty !== void 0) selected = await context.getProperty(target, "prototype");
|
|
26250
|
+
else {
|
|
26251
|
+
const descriptor = getSandboxPropertyDescriptor(target, "prototype", budget);
|
|
26252
|
+
selected = descriptor === void 0 ? void 0 : await readPropertyDescriptor(descriptor, target, context);
|
|
26253
|
+
}
|
|
26254
|
+
budget.provisionDataUsage(1)();
|
|
26255
|
+
const value = new DataView(buffer, offset, size);
|
|
26256
|
+
if (arrayBufferOptions(buffer) !== void 0) dataViewLayouts.set(value, { byteOffset: offset, ...size === void 0 ? {} : { byteLength: size } });
|
|
26257
|
+
setSandboxPrototype(value, selected !== null && typeof selected === "object" ? selected : prototype, budget);
|
|
26258
|
+
return value;
|
|
26259
|
+
} finally {
|
|
26260
|
+
release();
|
|
26261
|
+
}
|
|
26262
|
+
}
|
|
26263
|
+
});
|
|
26264
|
+
Object.defineProperty(materializeFunctionProperties(constructor), "prototype", { value: prototype });
|
|
26265
|
+
Object.defineProperties(prototype, {
|
|
26266
|
+
constructor: { value: constructor, writable: true, configurable: true },
|
|
26267
|
+
[Symbol.toStringTag]: { value: "DataView", configurable: true }
|
|
26268
|
+
});
|
|
26269
|
+
const getters = [];
|
|
26270
|
+
for (const [name, getter] of Object.entries(dataViewGetters)) {
|
|
26271
|
+
const closure = createSandboxClosure({
|
|
26272
|
+
guest: true,
|
|
26273
|
+
sandbox: true,
|
|
26274
|
+
name: `get ${name}`,
|
|
26275
|
+
length: 0,
|
|
26276
|
+
call: (_args, context) => {
|
|
26277
|
+
if (!isSandboxDataView(context?.thisValue)) throw new TypeError("DataView getter requires a DataView receiver.");
|
|
26278
|
+
return Reflect.apply(getter, context.thisValue, []);
|
|
26279
|
+
}
|
|
26280
|
+
});
|
|
26281
|
+
Object.defineProperty(prototype, name, { get: accessorAdapter(closure, "get"), configurable: true });
|
|
26282
|
+
getters.push(closure);
|
|
26283
|
+
}
|
|
26284
|
+
for (const [name, method] of Object.entries(methods)) {
|
|
26285
|
+
const setter = name.startsWith("set");
|
|
26286
|
+
Object.defineProperty(prototype, name, {
|
|
26287
|
+
writable: true,
|
|
26288
|
+
configurable: true,
|
|
26289
|
+
value: createSandboxClosure({
|
|
26290
|
+
guest: true,
|
|
26291
|
+
sandbox: true,
|
|
26292
|
+
name,
|
|
26293
|
+
length: setter ? 2 : 1,
|
|
26294
|
+
call: async (args, context) => {
|
|
26295
|
+
const receiver = context?.thisValue;
|
|
26296
|
+
if (!isSandboxDataView(receiver)) throw new TypeError("DataView method requires a DataView receiver.");
|
|
26297
|
+
const release = retainValues(budget, () => [receiver, ...args]);
|
|
26298
|
+
try {
|
|
26299
|
+
const offset = await dataViewIndex(args[0], budget, context);
|
|
26300
|
+
const value = setter ? name.startsWith("setBig") ? await sandboxBigInt(args[1], budget, context) : await sandboxNumber(args[1], budget, context) : void 0;
|
|
26301
|
+
return Reflect.apply(method, receiver, setter ? [offset, value, Boolean(args[2])] : [offset, Boolean(args[1])]);
|
|
26302
|
+
} finally {
|
|
26303
|
+
release();
|
|
26304
|
+
}
|
|
26305
|
+
}
|
|
26306
|
+
})
|
|
26307
|
+
});
|
|
26308
|
+
}
|
|
26309
|
+
setSandboxPrototype(prototype, getSandboxPrototype(/* @__PURE__ */ Object.create(null), budget));
|
|
26310
|
+
dataViewPrototypes.set(budget, prototype);
|
|
26311
|
+
registerBuiltinIdentities(budget, { DataView: constructor });
|
|
26312
|
+
registerIntrinsicFunction(budget, constructor);
|
|
26313
|
+
for (const getter of getters) registerIntrinsicFunction(budget, getter);
|
|
26314
|
+
registerIntrinsicObject(budget, prototype);
|
|
26315
|
+
return constructor;
|
|
26316
|
+
}
|
|
26317
|
+
async function dataViewIndex(value, budget, context) {
|
|
26318
|
+
const number = await sandboxNumber(value, budget, context);
|
|
26319
|
+
const index = Number.isNaN(number) ? 0 : Math.trunc(number);
|
|
26320
|
+
if (!Number.isSafeInteger(index) || index < 0) throw new RangeError("Invalid DataView index.");
|
|
26321
|
+
return index;
|
|
26322
|
+
}
|
|
26323
|
+
|
|
26059
26324
|
// packages/safe-js/src/interp/globals.ts
|
|
26060
26325
|
function createBuiltinBindings(options) {
|
|
26061
26326
|
const bindings = {
|
|
@@ -26069,6 +26334,7 @@ function createBuiltinBindings(options) {
|
|
|
26069
26334
|
...createMathGlobals({ random: options.random, budget: options.budget }),
|
|
26070
26335
|
...createObjectArrayGlobals(options),
|
|
26071
26336
|
ArrayBuffer: createArrayBufferGlobal(options.budget),
|
|
26337
|
+
DataView: createDataViewGlobal(options.budget),
|
|
26072
26338
|
...createMiscGlobals(options),
|
|
26073
26339
|
...createUriGlobals(options.budget),
|
|
26074
26340
|
...createPromiseGlobals(options),
|
|
@@ -26805,8 +27071,9 @@ function validateDumpHeap(root, state) {
|
|
|
26805
27071
|
validateDateRecord(entry, path);
|
|
26806
27072
|
continue;
|
|
26807
27073
|
}
|
|
26808
|
-
if (entry.kind === "arraybuffer") {
|
|
26809
|
-
|
|
27074
|
+
if (entry.kind === "arraybuffer" || entry.kind === "dataview") {
|
|
27075
|
+
if (entry.kind === "dataview") validateDataViewStorage(entry);
|
|
27076
|
+
else validateArrayBufferStorage(entry);
|
|
26810
27077
|
validateGuestHeapNode({ kind: "guest-object", state: entry.state }, heap, state.limits.maxEntries);
|
|
26811
27078
|
continue;
|
|
26812
27079
|
}
|
|
@@ -27033,7 +27300,7 @@ function validateHeapValue(value, path, state, heap) {
|
|
|
27033
27300
|
fail("invalidValue", path, String(error));
|
|
27034
27301
|
}
|
|
27035
27302
|
validateErrorType(record4, path);
|
|
27036
|
-
if (!["symbol", "arguments", "array", "object", "map", "set", "float32array", "typedarray", "arraybuffer", "date", "boxed", "collection-iterator", "regexp-iterator", "regex-object"].includes(String(record4.kind)))
|
|
27303
|
+
if (!["symbol", "arguments", "array", "object", "map", "set", "float32array", "typedarray", "arraybuffer", "dataview", "date", "boxed", "collection-iterator", "regexp-iterator", "regex-object"].includes(String(record4.kind)))
|
|
27037
27304
|
fail("unknownTag", `${path}.kind`, "unknown heap tag");
|
|
27038
27305
|
validateValue(record4, path, 1, state);
|
|
27039
27306
|
if (record4.kind === "symbol") validateSymbolRecord(record4, path, state);
|
|
@@ -27042,8 +27309,9 @@ function validateHeapValue(value, path, state, heap) {
|
|
|
27042
27309
|
if (record4.kind === "object") requireRecord(record4.entries, `${path}.entries`);
|
|
27043
27310
|
if (record4.kind === "boxed") validateBoxedRecord(record4, path, heap);
|
|
27044
27311
|
if (record4.kind === "date") validateDateRecord(record4, path);
|
|
27045
|
-
if (record4.kind === "arraybuffer") {
|
|
27046
|
-
|
|
27312
|
+
if (record4.kind === "arraybuffer" || record4.kind === "dataview") {
|
|
27313
|
+
if (record4.kind === "dataview") validateDataViewStorage(record4);
|
|
27314
|
+
else validateArrayBufferStorage(record4);
|
|
27047
27315
|
validateGuestHeapNode({ kind: "guest-object", state: record4.state }, heap, state.limits.maxEntries);
|
|
27048
27316
|
}
|
|
27049
27317
|
if (record4.kind === "float32array" || record4.kind === "typedarray") {
|
|
@@ -27242,7 +27510,7 @@ function validateGenericValue(value, path, depth, state) {
|
|
|
27242
27510
|
if (typeof value === "object" && value !== null && hasGuestObjectState(value)) {
|
|
27243
27511
|
fail("invalidState", path, "guest function properties, prototype links and custom descriptors cannot be restored");
|
|
27244
27512
|
}
|
|
27245
|
-
if (state.dataPropertiesOnly &&
|
|
27513
|
+
if (state.dataPropertiesOnly && types8.isProxy(value)) {
|
|
27246
27514
|
fail("invalidType", path, "proxy objects are not snapshot data");
|
|
27247
27515
|
}
|
|
27248
27516
|
if (depth > state.limits.maxDepth)
|
|
@@ -28042,6 +28310,7 @@ function measureSandboxData(values, options = {}) {
|
|
|
28042
28310
|
const prototype = getSandboxPrototype(value);
|
|
28043
28311
|
if (prototype !== null) visit(prototype, depth + 1);
|
|
28044
28312
|
if (isSandboxArrayBuffer(value)) usage += arrayBufferLength(value);
|
|
28313
|
+
if (isSandboxDataView(value)) visit(dataViewBuffer(value), depth + 1);
|
|
28045
28314
|
if (isNumericTypedArray(value)) {
|
|
28046
28315
|
const storage = typedArrayStorage(value);
|
|
28047
28316
|
visit(storage.buffer, depth + 1);
|
|
@@ -28187,7 +28456,7 @@ function measureSandboxData(values, options = {}) {
|
|
|
28187
28456
|
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
28188
28457
|
if (descriptor !== void 0) descriptors2.push([key, descriptor]);
|
|
28189
28458
|
}
|
|
28190
|
-
const includeNonEnumerable = isSandboxDate(value) || isSandboxArrayBuffer(value) || sandboxErrorTypes.has(value) || hasManagedDescriptors(value);
|
|
28459
|
+
const includeNonEnumerable = isSandboxDate(value) || isSandboxArrayBuffer(value) || isSandboxDataView(value) || sandboxErrorTypes.has(value) || hasManagedDescriptors(value);
|
|
28191
28460
|
for (const [key, descriptor] of descriptors2) {
|
|
28192
28461
|
if (!descriptor.enumerable && !includeNonEnumerable) continue;
|
|
28193
28462
|
usage += 1 + key.length;
|
|
@@ -28319,7 +28588,7 @@ function copyToSandbox(value, state, path = "<root>", cloneSandboxCollections =
|
|
|
28319
28588
|
}
|
|
28320
28589
|
return copy;
|
|
28321
28590
|
}
|
|
28322
|
-
if (typeof value === "object" && value !== null && hasGuestObjectState(value) && !(state.structuredClone && (isSandboxDate(value) || isSandboxArrayBuffer(value) || isNumericTypedArray(value)))) {
|
|
28591
|
+
if (typeof value === "object" && value !== null && hasGuestObjectState(value) && !(state.structuredClone && (isSandboxDate(value) || isSandboxArrayBuffer(value) || isSandboxDataView(value) || isNumericTypedArray(value)))) {
|
|
28323
28592
|
throw new TypeError("Guest prototype links and custom descriptors cannot be copied as data.");
|
|
28324
28593
|
}
|
|
28325
28594
|
const primitive = nativeBoxedValue(value);
|
|
@@ -28411,6 +28680,30 @@ function copyToSandbox(value, state, path = "<root>", cloneSandboxCollections =
|
|
|
28411
28680
|
if (!state.structuredClone && !Object.isExtensible(value)) Object.preventExtensions(copy);
|
|
28412
28681
|
return copy;
|
|
28413
28682
|
}
|
|
28683
|
+
if (isSandboxDataView(value)) {
|
|
28684
|
+
const existing = state.seen.get(value);
|
|
28685
|
+
if (existing !== void 0) return existing;
|
|
28686
|
+
if (state.structuredClone) {
|
|
28687
|
+
try {
|
|
28688
|
+
Reflect.apply(dataViewGetters.byteLength, value, []);
|
|
28689
|
+
} catch (error) {
|
|
28690
|
+
if (!(error instanceof TypeError)) throw error;
|
|
28691
|
+
throw new DOMException("Cannot clone an out-of-bounds DataView.", "DataCloneError");
|
|
28692
|
+
}
|
|
28693
|
+
}
|
|
28694
|
+
const copy = copyDataViewStorage(value, state);
|
|
28695
|
+
state.seen.set(value, copy);
|
|
28696
|
+
if (state.structuredClone) return copy;
|
|
28697
|
+
copyToSandbox(dataViewBuffer(value), state, `${path}.buffer`, cloneSandboxCollections, depth + 1);
|
|
28698
|
+
for (const [key, descriptor] of dataViewDataProperties(value)) {
|
|
28699
|
+
Object.defineProperty(copy, key, {
|
|
28700
|
+
...descriptor,
|
|
28701
|
+
value: copyToSandbox(descriptor.value, state, joinPath2(path, key), cloneSandboxCollections, depth + 1)
|
|
28702
|
+
});
|
|
28703
|
+
}
|
|
28704
|
+
if (!Object.isExtensible(value)) Object.preventExtensions(copy);
|
|
28705
|
+
return copy;
|
|
28706
|
+
}
|
|
28414
28707
|
if (isNumericTypedArray(value)) {
|
|
28415
28708
|
const existing = state.seen.get(value);
|
|
28416
28709
|
if (existing !== void 0) return existing;
|
|
@@ -28657,12 +28950,13 @@ function copyFromSandbox(value, state, path = "<root>", options, depth = 0) {
|
|
|
28657
28950
|
if (!Object.isExtensible(value)) Object.preventExtensions(copy);
|
|
28658
28951
|
return copy;
|
|
28659
28952
|
}
|
|
28660
|
-
if (isSandboxArrayBuffer(value)) {
|
|
28953
|
+
if (isSandboxArrayBuffer(value) || isSandboxDataView(value)) {
|
|
28661
28954
|
const existing = state.seen.get(value);
|
|
28662
28955
|
if (existing !== void 0) return existing;
|
|
28663
|
-
const copy = copyArrayBufferStorage(value, state);
|
|
28956
|
+
const copy = isSandboxDataView(value) ? copyDataViewStorage(value, state) : copyArrayBufferStorage(value, state);
|
|
28664
28957
|
state.seen.set(value, copy);
|
|
28665
|
-
|
|
28958
|
+
if (isSandboxDataView(value)) copyFromSandbox(dataViewBuffer(value), state, `${path}.buffer`, options, depth + 1);
|
|
28959
|
+
for (const [key, descriptor] of isSandboxDataView(value) ? dataViewDataProperties(value) : arrayBufferDataProperties(value)) {
|
|
28666
28960
|
Object.defineProperty(copy, key, {
|
|
28667
28961
|
...descriptor,
|
|
28668
28962
|
value: copyFromSandbox(descriptor.value, state, joinPath2(path, key), options, depth + 1)
|
|
@@ -28832,6 +29126,16 @@ function allocateSandboxValue2(value, budget, seen) {
|
|
|
28832
29126
|
budget.allocateString(value);
|
|
28833
29127
|
return;
|
|
28834
29128
|
}
|
|
29129
|
+
if (isSandboxDataView(value)) {
|
|
29130
|
+
if (seen.has(value)) return;
|
|
29131
|
+
seen.add(value);
|
|
29132
|
+
allocateSandboxValue2(dataViewBuffer(value), budget, seen);
|
|
29133
|
+
for (const [key, descriptor] of dataViewDataProperties(value)) {
|
|
29134
|
+
if (typeof key === "string") budget.allocateString(key);
|
|
29135
|
+
allocateSandboxValue2(descriptor.value, budget, seen);
|
|
29136
|
+
}
|
|
29137
|
+
return;
|
|
29138
|
+
}
|
|
28835
29139
|
if (isSandboxArrayBuffer(value)) {
|
|
28836
29140
|
if (seen.has(value)) return;
|
|
28837
29141
|
seen.add(value);
|
|
@@ -29590,6 +29894,21 @@ function normalize(value, seen) {
|
|
|
29590
29894
|
try {
|
|
29591
29895
|
const date = copyNativeDate(value);
|
|
29592
29896
|
if (date !== void 0) return Object.assign(/* @__PURE__ */ Object.create(null), { $type: "date", time: serializedDateTime(date) });
|
|
29897
|
+
if (isSandboxDataView(value)) {
|
|
29898
|
+
const properties = /* @__PURE__ */ Object.create(null);
|
|
29899
|
+
const entries = dataViewDataProperties(value);
|
|
29900
|
+
if (entries.some(([key]) => typeof key !== "string")) throw new TypeError("DataView symbol properties require an explicit host-call identity.");
|
|
29901
|
+
for (const [key, descriptor] of entries.sort(([left], [right]) => String(left) < String(right) ? -1 : String(left) > String(right) ? 1 : 0))
|
|
29902
|
+
defineOwnDataProperty(properties, String(key), normalize(descriptor.value, seen));
|
|
29903
|
+
const layout = dataViewLayout(value);
|
|
29904
|
+
return Object.assign(/* @__PURE__ */ Object.create(null), {
|
|
29905
|
+
$type: "dataview",
|
|
29906
|
+
byteOffset: layout.byteOffset,
|
|
29907
|
+
byteLength: layout.byteLength ?? null,
|
|
29908
|
+
buffer: normalize(dataViewBuffer(value), seen),
|
|
29909
|
+
properties
|
|
29910
|
+
});
|
|
29911
|
+
}
|
|
29593
29912
|
if (isSandboxArrayBuffer(value)) {
|
|
29594
29913
|
arrayBufferLength(value);
|
|
29595
29914
|
const properties = /* @__PURE__ */ Object.create(null);
|
|
@@ -30582,6 +30901,7 @@ var KNOWN_RUNTIME_GLOBALS = [
|
|
|
30582
30901
|
"AggregateError",
|
|
30583
30902
|
"Array",
|
|
30584
30903
|
"ArrayBuffer",
|
|
30904
|
+
"DataView",
|
|
30585
30905
|
"Boolean",
|
|
30586
30906
|
"BigInt",
|
|
30587
30907
|
"Date",
|
|
@@ -40982,7 +41302,7 @@ function createReplayableRandom(options = {}) {
|
|
|
40982
41302
|
|
|
40983
41303
|
// packages/safe-js/src/realm.ts
|
|
40984
41304
|
import { AsyncLocalStorage as AsyncLocalStorage6 } from "node:async_hooks";
|
|
40985
|
-
import { types as
|
|
41305
|
+
import { types as types9 } from "node:util";
|
|
40986
41306
|
|
|
40987
41307
|
// packages/safe-js/src/modules/registry.ts
|
|
40988
41308
|
function createUnknownModuleMessage2(moduleName, moduleNames) {
|
|
@@ -41121,7 +41441,7 @@ var RealmState = class {
|
|
|
41121
41441
|
throw new TypeError("Realm limits must be positive safe integers with supported names.");
|
|
41122
41442
|
this.limits[name] = Number(value);
|
|
41123
41443
|
}
|
|
41124
|
-
if (options.extensions !== void 0 && (!Array.isArray(options.extensions) ||
|
|
41444
|
+
if (options.extensions !== void 0 && (!Array.isArray(options.extensions) || types9.isProxy(options.extensions)))
|
|
41125
41445
|
throw new TypeError("Extensions must be a registration array.");
|
|
41126
41446
|
const registrations = options.extensions ?? [];
|
|
41127
41447
|
const extensions = [];
|
|
@@ -41356,7 +41676,7 @@ var RealmState = class {
|
|
|
41356
41676
|
return this.phase.run(phase, () => {
|
|
41357
41677
|
try {
|
|
41358
41678
|
const result = call();
|
|
41359
|
-
if (
|
|
41679
|
+
if (types9.isPromise(result) || phase.pending.size > 0 || phase.failure !== void 0) {
|
|
41360
41680
|
return Promise.resolve(result).then(
|
|
41361
41681
|
async (value) => {
|
|
41362
41682
|
await Promise.allSettled(phase.pending);
|
|
@@ -41425,7 +41745,7 @@ var RealmState = class {
|
|
|
41425
41745
|
},
|
|
41426
41746
|
read: (operation, validate) => {
|
|
41427
41747
|
const value = this.invokeHost(operation, operation);
|
|
41428
|
-
if (
|
|
41748
|
+
if (types9.isPromise(value)) {
|
|
41429
41749
|
void Promise.resolve(value).catch(() => void 0);
|
|
41430
41750
|
throw new TypeError("Live property operations must be synchronous.");
|
|
41431
41751
|
}
|
|
@@ -41433,7 +41753,7 @@ var RealmState = class {
|
|
|
41433
41753
|
},
|
|
41434
41754
|
write: (operation, value) => {
|
|
41435
41755
|
const result = this.invokeHost(operation, () => operation(this.exportValue(value)));
|
|
41436
|
-
if (
|
|
41756
|
+
if (types9.isPromise(result)) {
|
|
41437
41757
|
void Promise.resolve(result).catch(() => void 0);
|
|
41438
41758
|
throw new TypeError("Live property setters must be synchronous.");
|
|
41439
41759
|
}
|
|
@@ -41642,7 +41962,7 @@ var RealmState = class {
|
|
|
41642
41962
|
}
|
|
41643
41963
|
});
|
|
41644
41964
|
const output = getExtensionSetup(extension)(context);
|
|
41645
|
-
if (
|
|
41965
|
+
if (types9.isPromise(output)) {
|
|
41646
41966
|
void Promise.resolve(output).catch(() => void 0);
|
|
41647
41967
|
throw new TypeError("Extension setup must be synchronous.");
|
|
41648
41968
|
}
|
|
@@ -41834,7 +42154,7 @@ var RealmState = class {
|
|
|
41834
42154
|
};
|
|
41835
42155
|
function readModules(input) {
|
|
41836
42156
|
const entries = (value, label) => {
|
|
41837
|
-
if (
|
|
42157
|
+
if (types9.isMap(value) && !types9.isProxy(value)) {
|
|
41838
42158
|
const result = [...Map.prototype.entries.call(value)];
|
|
41839
42159
|
if (result.length > 4096 || result.some(([key]) => typeof key !== "string" || key.length === 0))
|
|
41840
42160
|
throw new TypeError(`${label} requires bounded string keys.`);
|
|
@@ -43103,4 +43423,4 @@ export {
|
|
|
43103
43423
|
FileSnapshotBackend,
|
|
43104
43424
|
run
|
|
43105
43425
|
};
|
|
43106
|
-
//# sourceMappingURL=chunk-
|
|
43426
|
+
//# sourceMappingURL=chunk-NLDDBHDH.js.map
|