poe-code 14.0.72 → 14.0.73
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 +850 -638
- 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-VYUHL33E.js → chunk-I2Z37MKZ.js} +2 -2
- package/packages/safe-js/dist/chunks/{chunk-6UY4Z7WY.js → chunk-XKCTB5FR.js} +351 -158
- package/packages/safe-js/dist/chunks/chunk-XKCTB5FR.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/graph-depth.js +7 -0
- package/packages/safe-js/dist/index.js +2 -2
- package/packages/safe-js/dist/interp/globals/object-array.js +9 -7
- package/packages/safe-js/dist/interp/globals/object.js +2 -2
- package/packages/safe-js/dist/interp/interpreter.js +7 -7
- package/packages/safe-js/dist/interp/methods/regex.d.ts +1 -1
- package/packages/safe-js/dist/interp/methods/regex.js +6 -3
- package/packages/safe-js/dist/interp/methods/string.js +57 -18
- package/packages/safe-js/dist/interp/object-model.js +6 -3
- package/packages/safe-js/dist/interp/regexp-properties.d.ts +3 -0
- package/packages/safe-js/dist/interp/regexp-properties.js +7 -0
- package/packages/safe-js/dist/interp/values.d.ts +1 -0
- package/packages/safe-js/dist/interp/values.js +76 -2
- package/packages/safe-js/dist/snapshot/dump-format.js +27 -9
- package/packages/safe-js/dist/snapshot/regexp-properties.d.ts +18 -0
- package/packages/safe-js/dist/snapshot/regexp-properties.js +58 -0
- package/packages/safe-js/dist/snapshot/replay-data.d.ts +3 -2
- package/packages/safe-js/dist/snapshot/replay-data.js +4 -1
- package/packages/safe-js/dist/snapshot/restore.js +2 -0
- package/packages/safe-js/dist/snapshot/serialize.d.ts +3 -2
- package/packages/safe-js/dist/snapshot/serialize.js +23 -16
- package/packages/safe-js/dist/snapshot/validation.js +12 -1
- package/packages/safe-js/dist/chunks/chunk-6UY4Z7WY.js.map +0 -7
- /package/packages/safe-js/dist/chunks/{chunk-VYUHL33E.js.map → chunk-I2Z37MKZ.js.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -50271,8 +50271,8 @@ function assertNonNegativeInteger3(value, keyword) {
|
|
|
50271
50271
|
}
|
|
50272
50272
|
function validateSchemaObject(schema, dialect) {
|
|
50273
50273
|
if (schema.type !== void 0) {
|
|
50274
|
-
const
|
|
50275
|
-
if (
|
|
50274
|
+
const types8 = Array.isArray(schema.type) ? schema.type : [schema.type];
|
|
50275
|
+
if (types8.length === 0 || !types8.every((type) => typeof type === "string" && draftTypeSet.has(type)) || new Set(types8).size !== types8.length) {
|
|
50276
50276
|
throw new Error("type must be a JSON Schema type or a unique array of JSON Schema types.");
|
|
50277
50277
|
}
|
|
50278
50278
|
}
|
|
@@ -50991,9 +50991,9 @@ function evaluateValidationKeywords(node, schema, value, path193) {
|
|
|
50991
50991
|
if (schema.nullable === true && value === null) {
|
|
50992
50992
|
return results;
|
|
50993
50993
|
}
|
|
50994
|
-
const
|
|
50995
|
-
if (
|
|
50996
|
-
results.push(invalidResult(issue(path193,
|
|
50994
|
+
const types8 = typeof schema.type === "string" ? [schema.type] : Array.isArray(schema.type) ? schema.type : [];
|
|
50995
|
+
if (types8.length > 0 && !types8.some((type) => typeof type === "string" && typeMatches(type, value))) {
|
|
50996
|
+
results.push(invalidResult(issue(path193, types8.join(","), value, `must be ${types8.join(",")}`)));
|
|
50997
50997
|
return results;
|
|
50998
50998
|
}
|
|
50999
50999
|
if (schema.const !== void 0 && !deepEqual(schema.const, value)) {
|
|
@@ -125962,26 +125962,96 @@ var init_hash = __esm({
|
|
|
125962
125962
|
}
|
|
125963
125963
|
});
|
|
125964
125964
|
|
|
125965
|
-
// packages/safe-js/src/
|
|
125966
|
-
|
|
125967
|
-
|
|
125968
|
-
|
|
125965
|
+
// packages/safe-js/src/observability/otel.ts
|
|
125966
|
+
function bindOtelSpan(value, span) {
|
|
125967
|
+
spanByAsyncValue.set(value, span);
|
|
125968
|
+
}
|
|
125969
|
+
function getBoundOtelSpan(value) {
|
|
125970
|
+
return typeof value === "object" && value !== null ? spanByAsyncValue.get(value) : void 0;
|
|
125971
|
+
}
|
|
125972
|
+
function activateOtelSpan(span) {
|
|
125973
|
+
activeSpans.push(span);
|
|
125974
|
+
return () => {
|
|
125975
|
+
const index = activeSpans.lastIndexOf(span);
|
|
125976
|
+
if (index !== -1) {
|
|
125977
|
+
activeSpans.splice(index, 1);
|
|
125978
|
+
}
|
|
125979
|
+
};
|
|
125980
|
+
}
|
|
125981
|
+
function getActiveOtelSpan() {
|
|
125982
|
+
return activeSpans.at(-1);
|
|
125983
|
+
}
|
|
125984
|
+
function activateOtelSink(sink) {
|
|
125985
|
+
if (sink === void 0) {
|
|
125986
|
+
return () => void 0;
|
|
125987
|
+
}
|
|
125988
|
+
activeSinks.push(sink);
|
|
125989
|
+
return () => {
|
|
125990
|
+
const index = activeSinks.lastIndexOf(sink);
|
|
125991
|
+
if (index !== -1) {
|
|
125992
|
+
activeSinks.splice(index, 1);
|
|
125993
|
+
}
|
|
125994
|
+
};
|
|
125995
|
+
}
|
|
125996
|
+
function getActiveOtelSink() {
|
|
125997
|
+
return activeSinks.at(-1);
|
|
125998
|
+
}
|
|
125999
|
+
function safeStartSpan2(sink, name, attrs) {
|
|
126000
|
+
if (sink === void 0) {
|
|
126001
|
+
return noopOtelSpan2;
|
|
126002
|
+
}
|
|
126003
|
+
try {
|
|
126004
|
+
return sink.startSpan(name, attrs);
|
|
126005
|
+
} catch (error3) {
|
|
126006
|
+
warnOtelSinkFailure2("startSpan", error3);
|
|
126007
|
+
return noopOtelSpan2;
|
|
126008
|
+
}
|
|
126009
|
+
}
|
|
126010
|
+
function safeAddEvent2(span, name, attrs) {
|
|
126011
|
+
if (span === void 0) {
|
|
126012
|
+
return;
|
|
126013
|
+
}
|
|
126014
|
+
try {
|
|
126015
|
+
span.addEvent(name, attrs ?? {});
|
|
126016
|
+
} catch (error3) {
|
|
126017
|
+
warnOtelSinkFailure2("addEvent", error3);
|
|
126018
|
+
}
|
|
126019
|
+
}
|
|
126020
|
+
function safeRecordException2(sink, span, error3) {
|
|
126021
|
+
if (sink === void 0) {
|
|
126022
|
+
return;
|
|
126023
|
+
}
|
|
126024
|
+
try {
|
|
126025
|
+
sink.recordException(span, error3);
|
|
126026
|
+
} catch (recordError) {
|
|
126027
|
+
warnOtelSinkFailure2("recordException", recordError);
|
|
126028
|
+
}
|
|
126029
|
+
}
|
|
126030
|
+
function safeEndSpan2(span) {
|
|
126031
|
+
try {
|
|
126032
|
+
span.end();
|
|
126033
|
+
} catch (error3) {
|
|
126034
|
+
warnOtelSinkFailure2("end", error3);
|
|
126035
|
+
}
|
|
126036
|
+
}
|
|
126037
|
+
function warnOtelSinkFailure2(method, error3) {
|
|
126038
|
+
console.warn(`OpenTelemetry sink ${method} failed: ${readErrorMessage3(error3)}`);
|
|
126039
|
+
}
|
|
126040
|
+
function readErrorMessage3(error3) {
|
|
126041
|
+
return error3 instanceof Error ? error3.message : String(error3);
|
|
126042
|
+
}
|
|
126043
|
+
var noopOtelSpan2, spanByAsyncValue, activeSpans, activeSinks;
|
|
126044
|
+
var init_otel2 = __esm({
|
|
126045
|
+
"packages/safe-js/src/observability/otel.ts"() {
|
|
125969
126046
|
"use strict";
|
|
125970
|
-
|
|
125971
|
-
|
|
125972
|
-
|
|
125973
|
-
|
|
125974
|
-
|
|
125975
|
-
|
|
125976
|
-
|
|
125977
|
-
|
|
125978
|
-
search: Symbol.search,
|
|
125979
|
-
species: Symbol.species,
|
|
125980
|
-
split: Symbol.split,
|
|
125981
|
-
toPrimitive: Symbol.toPrimitive,
|
|
125982
|
-
toStringTag: Symbol.toStringTag,
|
|
125983
|
-
unscopables: Symbol.unscopables
|
|
125984
|
-
});
|
|
126047
|
+
noopOtelSpan2 = {
|
|
126048
|
+
setAttribute: () => void 0,
|
|
126049
|
+
addEvent: () => void 0,
|
|
126050
|
+
end: () => void 0
|
|
126051
|
+
};
|
|
126052
|
+
spanByAsyncValue = /* @__PURE__ */ new WeakMap();
|
|
126053
|
+
activeSpans = [];
|
|
126054
|
+
activeSinks = [];
|
|
125985
126055
|
}
|
|
125986
126056
|
});
|
|
125987
126057
|
|
|
@@ -125994,56 +126064,100 @@ var init_internal_symbols = __esm({
|
|
|
125994
126064
|
}
|
|
125995
126065
|
});
|
|
125996
126066
|
|
|
125997
|
-
// packages/safe-js/src/interp/
|
|
125998
|
-
function
|
|
125999
|
-
const
|
|
126000
|
-
|
|
126001
|
-
|
|
126002
|
-
for (let index = 0; index < values.length; index += 1) {
|
|
126003
|
-
result[index] = values[index];
|
|
126004
|
-
}
|
|
126005
|
-
result.length = values.length;
|
|
126006
|
-
Object.defineProperty(result, sandboxArgumentsBrand, { value: true });
|
|
126007
|
-
return result;
|
|
126067
|
+
// packages/safe-js/src/interp/regexp-properties.ts
|
|
126068
|
+
function getRegexProperties(value) {
|
|
126069
|
+
const properties = regexGuestProperties.get(value);
|
|
126070
|
+
if (properties === void 0) throw new TypeError("Invalid sandbox RegExp storage.");
|
|
126071
|
+
return properties;
|
|
126008
126072
|
}
|
|
126009
|
-
|
|
126010
|
-
|
|
126073
|
+
var regexGuestProperties;
|
|
126074
|
+
var init_regexp_properties = __esm({
|
|
126075
|
+
"packages/safe-js/src/interp/regexp-properties.ts"() {
|
|
126076
|
+
"use strict";
|
|
126077
|
+
regexGuestProperties = /* @__PURE__ */ new WeakMap();
|
|
126078
|
+
}
|
|
126079
|
+
});
|
|
126080
|
+
|
|
126081
|
+
// packages/safe-js/src/interp/accessors.ts
|
|
126082
|
+
function accessorAdapter(closure, kind) {
|
|
126083
|
+
if (kind === "get") {
|
|
126084
|
+
let adapter2 = getterAdapters.get(closure);
|
|
126085
|
+
if (adapter2 === void 0) {
|
|
126086
|
+
adapter2 = () => void 0;
|
|
126087
|
+
getterAdapters.set(closure, adapter2);
|
|
126088
|
+
accessorClosures.set(adapter2, closure);
|
|
126089
|
+
}
|
|
126090
|
+
return adapter2;
|
|
126091
|
+
}
|
|
126092
|
+
let adapter = setterAdapters.get(closure);
|
|
126093
|
+
if (adapter === void 0) {
|
|
126094
|
+
adapter = () => {
|
|
126095
|
+
throw new TypeError("Accessor writes require sandbox execution.");
|
|
126096
|
+
};
|
|
126097
|
+
setterAdapters.set(closure, adapter);
|
|
126098
|
+
accessorClosures.set(adapter, closure);
|
|
126099
|
+
}
|
|
126100
|
+
return adapter;
|
|
126011
126101
|
}
|
|
126012
|
-
function
|
|
126013
|
-
|
|
126014
|
-
|
|
126015
|
-
);
|
|
126102
|
+
function accessorClosure(adapter) {
|
|
126103
|
+
if (adapter === void 0) return void 0;
|
|
126104
|
+
const closure = accessorClosures.get(adapter);
|
|
126105
|
+
if (closure === void 0) throw new TypeError("Native accessors cannot execute in the sandbox.");
|
|
126106
|
+
return closure;
|
|
126016
126107
|
}
|
|
126017
|
-
function
|
|
126018
|
-
const
|
|
126019
|
-
|
|
126020
|
-
|
|
126108
|
+
function retainedAccessorClosures(descriptor) {
|
|
126109
|
+
const closures = [];
|
|
126110
|
+
for (const adapter of [descriptor.get, descriptor.set]) {
|
|
126111
|
+
const closure = adapter === void 0 ? void 0 : accessorClosures.get(adapter);
|
|
126112
|
+
if (closure !== void 0) closures.push(closure);
|
|
126021
126113
|
}
|
|
126022
|
-
|
|
126023
|
-
|
|
126024
|
-
|
|
126025
|
-
|
|
126026
|
-
|
|
126027
|
-
|
|
126114
|
+
return closures;
|
|
126115
|
+
}
|
|
126116
|
+
function readPropertyDescriptor(descriptor, receiver, context, allowNativeGetter = false) {
|
|
126117
|
+
if ("value" in descriptor) return descriptor.value;
|
|
126118
|
+
if (descriptor.get === void 0) return void 0;
|
|
126119
|
+
const getter = accessorClosures.get(descriptor.get);
|
|
126120
|
+
if (getter === void 0) {
|
|
126121
|
+
if (!allowNativeGetter) throw new TypeError("Native accessors cannot execute in the sandbox.");
|
|
126122
|
+
return Reflect.apply(descriptor.get, receiver, []);
|
|
126028
126123
|
}
|
|
126029
|
-
|
|
126030
|
-
|
|
126031
|
-
|
|
126032
|
-
|
|
126033
|
-
|
|
126034
|
-
|
|
126035
|
-
|
|
126036
|
-
|
|
126124
|
+
if (context?.invokeClosure === void 0)
|
|
126125
|
+
throw new TypeError("Accessor reads require sandbox execution.");
|
|
126126
|
+
return context.invokeClosure(getter, [], receiver);
|
|
126127
|
+
}
|
|
126128
|
+
function writePropertyDescriptor(descriptor, receiver, value, context) {
|
|
126129
|
+
const setter = accessorClosure(descriptor.set);
|
|
126130
|
+
if (setter === void 0) throw new TypeError("Cannot assign to a getter-only property.");
|
|
126131
|
+
if (context?.invokeClosure === void 0)
|
|
126132
|
+
throw new TypeError("Accessor writes require sandbox execution.");
|
|
126133
|
+
return context.invokeClosure(setter, [value], receiver).then(() => void 0);
|
|
126134
|
+
}
|
|
126135
|
+
var accessorClosures, getterAdapters, setterAdapters;
|
|
126136
|
+
var init_accessors = __esm({
|
|
126137
|
+
"packages/safe-js/src/interp/accessors.ts"() {
|
|
126138
|
+
"use strict";
|
|
126139
|
+
accessorClosures = /* @__PURE__ */ new WeakMap();
|
|
126140
|
+
getterAdapters = /* @__PURE__ */ new WeakMap();
|
|
126141
|
+
setterAdapters = /* @__PURE__ */ new WeakMap();
|
|
126037
126142
|
}
|
|
126038
|
-
|
|
126143
|
+
});
|
|
126144
|
+
|
|
126145
|
+
// packages/safe-js/src/interp/collection-brands.ts
|
|
126146
|
+
function isSandboxMap(value) {
|
|
126147
|
+
return typeof value === "object" && value !== null && sandboxMapBrand in value;
|
|
126039
126148
|
}
|
|
126040
|
-
|
|
126041
|
-
|
|
126042
|
-
|
|
126149
|
+
function isSandboxSet(value) {
|
|
126150
|
+
return typeof value === "object" && value !== null && sandboxSetBrand in value;
|
|
126151
|
+
}
|
|
126152
|
+
var sandboxMapBrand, sandboxSetBrand;
|
|
126153
|
+
var init_collection_brands = __esm({
|
|
126154
|
+
"packages/safe-js/src/interp/collection-brands.ts"() {
|
|
126043
126155
|
"use strict";
|
|
126044
126156
|
init_internal_symbols();
|
|
126045
|
-
|
|
126046
|
-
|
|
126157
|
+
sandboxMapBrand = /* @__PURE__ */ Symbol("SandboxMap");
|
|
126158
|
+
sandboxSetBrand = /* @__PURE__ */ Symbol("SandboxSet");
|
|
126159
|
+
internalSymbols.add(sandboxMapBrand);
|
|
126160
|
+
internalSymbols.add(sandboxSetBrand);
|
|
126047
126161
|
}
|
|
126048
126162
|
});
|
|
126049
126163
|
|
|
@@ -126109,175 +126223,8 @@ var init_collection_iterator = __esm({
|
|
|
126109
126223
|
}
|
|
126110
126224
|
});
|
|
126111
126225
|
|
|
126112
|
-
// packages/safe-js/src/interp/collection-brands.ts
|
|
126113
|
-
function isSandboxMap(value) {
|
|
126114
|
-
return typeof value === "object" && value !== null && sandboxMapBrand in value;
|
|
126115
|
-
}
|
|
126116
|
-
function isSandboxSet(value) {
|
|
126117
|
-
return typeof value === "object" && value !== null && sandboxSetBrand in value;
|
|
126118
|
-
}
|
|
126119
|
-
var sandboxMapBrand, sandboxSetBrand;
|
|
126120
|
-
var init_collection_brands = __esm({
|
|
126121
|
-
"packages/safe-js/src/interp/collection-brands.ts"() {
|
|
126122
|
-
"use strict";
|
|
126123
|
-
init_internal_symbols();
|
|
126124
|
-
sandboxMapBrand = /* @__PURE__ */ Symbol("SandboxMap");
|
|
126125
|
-
sandboxSetBrand = /* @__PURE__ */ Symbol("SandboxSet");
|
|
126126
|
-
internalSymbols.add(sandboxMapBrand);
|
|
126127
|
-
internalSymbols.add(sandboxSetBrand);
|
|
126128
|
-
}
|
|
126129
|
-
});
|
|
126130
|
-
|
|
126131
|
-
// packages/safe-js/src/interp/boxed.ts
|
|
126132
|
-
import { types } from "node:util";
|
|
126133
|
-
function nativeBoxedValue(value) {
|
|
126134
|
-
if (types.isNumberObject(value)) return Reflect.apply(numberValue2, value, []);
|
|
126135
|
-
if (types.isStringObject(value)) return Reflect.apply(stringValue2, value, []);
|
|
126136
|
-
if (types.isBooleanObject(value)) return Reflect.apply(booleanValue, value, []);
|
|
126137
|
-
if (types.isSymbolObject(value)) return Reflect.apply(symbolValue, value, []);
|
|
126138
|
-
return void 0;
|
|
126139
|
-
}
|
|
126140
|
-
function createSandboxBox(value) {
|
|
126141
|
-
if (typeof value !== "number" && typeof value !== "string" && typeof value !== "boolean" && typeof value !== "symbol")
|
|
126142
|
-
throw new TypeError("Invalid boxed primitive payload.");
|
|
126143
|
-
const box = Object(value);
|
|
126144
|
-
Object.setPrototypeOf(box, null);
|
|
126145
|
-
boxes.add(box);
|
|
126146
|
-
return box;
|
|
126147
|
-
}
|
|
126148
|
-
function isSandboxBox(value) {
|
|
126149
|
-
return typeof value === "object" && value !== null && boxes.has(value);
|
|
126150
|
-
}
|
|
126151
|
-
function boxedValue(value) {
|
|
126152
|
-
if (!boxes.has(value)) throw new TypeError("Expected a sandbox boxed primitive.");
|
|
126153
|
-
return nativeBoxedValue(value);
|
|
126154
|
-
}
|
|
126155
|
-
function primitiveReceiver(value, kind) {
|
|
126156
|
-
const primitive = isSandboxBox(value) ? boxedValue(value) : value;
|
|
126157
|
-
if (typeof primitive !== kind) throw new TypeError(`${kind} method requires a ${kind} receiver.`);
|
|
126158
|
-
return primitive;
|
|
126159
|
-
}
|
|
126160
|
-
function boxedDataProperties(value, includeSymbols = false) {
|
|
126161
|
-
const primitive = nativeBoxedValue(value);
|
|
126162
|
-
const descriptors = Object.getOwnPropertyDescriptors(value);
|
|
126163
|
-
const keys = includeSymbols ? Reflect.ownKeys(descriptors) : Object.keys(descriptors);
|
|
126164
|
-
return keys.map((key3) => [key3, Object.getOwnPropertyDescriptor(descriptors, key3).value]).filter(([key3]) => {
|
|
126165
|
-
if (typeof key3 === "symbol") return true;
|
|
126166
|
-
if (typeof primitive !== "string") return true;
|
|
126167
|
-
if (key3 === "length") return false;
|
|
126168
|
-
const index = Number(key3);
|
|
126169
|
-
return !(Number.isInteger(index) && index >= 0 && index < primitive.length && String(index) === key3);
|
|
126170
|
-
});
|
|
126171
|
-
}
|
|
126172
|
-
var boxes, numberValue2, stringValue2, booleanValue, symbolValue;
|
|
126173
|
-
var init_boxed = __esm({
|
|
126174
|
-
"packages/safe-js/src/interp/boxed.ts"() {
|
|
126175
|
-
"use strict";
|
|
126176
|
-
boxes = /* @__PURE__ */ new WeakSet();
|
|
126177
|
-
numberValue2 = Number.prototype.valueOf;
|
|
126178
|
-
stringValue2 = String.prototype.valueOf;
|
|
126179
|
-
booleanValue = Boolean.prototype.valueOf;
|
|
126180
|
-
symbolValue = Symbol.prototype.valueOf;
|
|
126181
|
-
}
|
|
126182
|
-
});
|
|
126183
|
-
|
|
126184
|
-
// packages/safe-js/src/graph-depth.ts
|
|
126185
|
-
function assertSandboxDataDepth(depth) {
|
|
126186
|
-
if (depth > MAX_DATA_DEPTH) {
|
|
126187
|
-
throw new SandboxError({ budget: "dataDepth", current: depth, limit: MAX_DATA_DEPTH });
|
|
126188
|
-
}
|
|
126189
|
-
}
|
|
126190
|
-
function assertSnapshotDataDepth(depth, path193) {
|
|
126191
|
-
if (depth > MAX_DATA_DEPTH) throw new SnapshotBudgetError(path193, depth);
|
|
126192
|
-
}
|
|
126193
|
-
function assertSnapshotGraphDepth(value, rootPath = "$") {
|
|
126194
|
-
walkGraphDepth(value, rootPath, (depth, path193) => assertSnapshotDataDepth(depth, path193));
|
|
126195
|
-
}
|
|
126196
|
-
function assertSandboxGraphDepth(value) {
|
|
126197
|
-
walkGraphDepth(value, "<root>", (depth) => assertSandboxDataDepth(depth));
|
|
126198
|
-
}
|
|
126199
|
-
function walkGraphDepth(root, rootPath, assertDepth) {
|
|
126200
|
-
const ancestors = /* @__PURE__ */ new WeakSet();
|
|
126201
|
-
const stack = [{ value: root, path: rootPath, depth: 0, exiting: false }];
|
|
126202
|
-
while (stack.length > 0) {
|
|
126203
|
-
const frame = stack.pop();
|
|
126204
|
-
if (typeof frame.value !== "object" || frame.value === null) continue;
|
|
126205
|
-
if (frame.exiting) {
|
|
126206
|
-
ancestors.delete(frame.value);
|
|
126207
|
-
continue;
|
|
126208
|
-
}
|
|
126209
|
-
assertDepth(frame.depth, frame.path);
|
|
126210
|
-
if (ancestors.has(frame.value)) continue;
|
|
126211
|
-
ancestors.add(frame.value);
|
|
126212
|
-
stack.push({ ...frame, exiting: true });
|
|
126213
|
-
const entries = graphEntries(frame.value);
|
|
126214
|
-
for (let index = entries.length - 1; index >= 0; index -= 1) {
|
|
126215
|
-
const [key3, entry] = entries[index];
|
|
126216
|
-
stack.push({
|
|
126217
|
-
value: entry,
|
|
126218
|
-
path: `${frame.path}${key3}`,
|
|
126219
|
-
depth: frame.depth + 1,
|
|
126220
|
-
exiting: false
|
|
126221
|
-
});
|
|
126222
|
-
}
|
|
126223
|
-
}
|
|
126224
|
-
}
|
|
126225
|
-
function graphEntries(value) {
|
|
126226
|
-
if (isSandboxBox(value)) return boxedDataProperties(value).map(([key3, descriptor]) => [`.${key3}`, descriptor.value]);
|
|
126227
|
-
if (isSandboxArguments(value)) {
|
|
126228
|
-
return getSandboxArgumentEntries(value).map(([key3, entry]) => [`.${key3}`, entry]);
|
|
126229
|
-
}
|
|
126230
|
-
const map = isSandboxMap(value) ? value.entries : value instanceof Map ? value : void 0;
|
|
126231
|
-
if (map !== void 0) {
|
|
126232
|
-
return [...map.entries()].flatMap(([key3, entry], index) => [
|
|
126233
|
-
[`.<map>[${index}].key`, key3],
|
|
126234
|
-
[`.<map>[${index}].value`, entry]
|
|
126235
|
-
]);
|
|
126236
|
-
}
|
|
126237
|
-
const set = isSandboxSet(value) ? value.values : value instanceof Set ? value : void 0;
|
|
126238
|
-
if (set !== void 0) {
|
|
126239
|
-
return [...set.values()].map((entry, index) => [`.<set>[${index}]`, entry]);
|
|
126240
|
-
}
|
|
126241
|
-
const entries = [];
|
|
126242
|
-
if (isSandboxCollectionIterator(value)) entries.push([".<collection>", collectionIteratorState(value).collection]);
|
|
126243
|
-
for (const key3 of Object.keys(value)) {
|
|
126244
|
-
const descriptor = Object.getOwnPropertyDescriptor(value, key3);
|
|
126245
|
-
if (descriptor !== void 0 && "value" in descriptor)
|
|
126246
|
-
entries.push([Array.isArray(value) ? `[${key3}]` : `.${key3}`, descriptor.value]);
|
|
126247
|
-
}
|
|
126248
|
-
return entries;
|
|
126249
|
-
}
|
|
126250
|
-
var MAX_DATA_DEPTH, SnapshotBudgetError;
|
|
126251
|
-
var init_graph_depth = __esm({
|
|
126252
|
-
"packages/safe-js/src/graph-depth.ts"() {
|
|
126253
|
-
"use strict";
|
|
126254
|
-
init_shape();
|
|
126255
|
-
init_budget2();
|
|
126256
|
-
init_arguments();
|
|
126257
|
-
init_collection_iterator();
|
|
126258
|
-
init_collection_brands();
|
|
126259
|
-
init_boxed();
|
|
126260
|
-
MAX_DATA_DEPTH = 1024;
|
|
126261
|
-
SnapshotBudgetError = class extends Error {
|
|
126262
|
-
code = "budgetExceeded";
|
|
126263
|
-
budget = "dataDepth";
|
|
126264
|
-
current;
|
|
126265
|
-
limit;
|
|
126266
|
-
path;
|
|
126267
|
-
constructor(path193, current, limit = MAX_DATA_DEPTH) {
|
|
126268
|
-
super(`Snapshot budget exceeded for dataDepth at ${path193}: ${current} > ${limit}.`);
|
|
126269
|
-
this.name = "SnapshotBudgetError";
|
|
126270
|
-
this.current = current;
|
|
126271
|
-
this.limit = limit;
|
|
126272
|
-
this.path = path193;
|
|
126273
|
-
replaceErrorStack(this);
|
|
126274
|
-
}
|
|
126275
|
-
};
|
|
126276
|
-
}
|
|
126277
|
-
});
|
|
126278
|
-
|
|
126279
126226
|
// packages/safe-js/src/interp/date.ts
|
|
126280
|
-
import { types
|
|
126227
|
+
import { types } from "node:util";
|
|
126281
126228
|
function isSandboxDate(value) {
|
|
126282
126229
|
return typeof value === "object" && value !== null && dates.has(value);
|
|
126283
126230
|
}
|
|
@@ -126290,7 +126237,7 @@ function dateTime(value) {
|
|
|
126290
126237
|
return Reflect.apply(readTime, value, []);
|
|
126291
126238
|
}
|
|
126292
126239
|
function copyNativeDate(value) {
|
|
126293
|
-
if (!
|
|
126240
|
+
if (!types.isDate(value)) return void 0;
|
|
126294
126241
|
if (Object.getPrototypeOf(value) !== NativeDate.prototype)
|
|
126295
126242
|
throw new TypeError("Date subclasses are not supported.");
|
|
126296
126243
|
return createSandboxDate(dateTime(value));
|
|
@@ -126412,67 +126359,56 @@ var init_date = __esm({
|
|
|
126412
126359
|
}
|
|
126413
126360
|
});
|
|
126414
126361
|
|
|
126415
|
-
// packages/safe-js/src/interp/
|
|
126416
|
-
|
|
126417
|
-
|
|
126418
|
-
|
|
126419
|
-
|
|
126420
|
-
|
|
126421
|
-
|
|
126422
|
-
|
|
126423
|
-
}
|
|
126424
|
-
return adapter2;
|
|
126425
|
-
}
|
|
126426
|
-
let adapter = setterAdapters.get(closure);
|
|
126427
|
-
if (adapter === void 0) {
|
|
126428
|
-
adapter = () => {
|
|
126429
|
-
throw new TypeError("Accessor writes require sandbox execution.");
|
|
126430
|
-
};
|
|
126431
|
-
setterAdapters.set(closure, adapter);
|
|
126432
|
-
accessorClosures.set(adapter, closure);
|
|
126433
|
-
}
|
|
126434
|
-
return adapter;
|
|
126362
|
+
// packages/safe-js/src/interp/boxed.ts
|
|
126363
|
+
import { types as types2 } from "node:util";
|
|
126364
|
+
function nativeBoxedValue(value) {
|
|
126365
|
+
if (types2.isNumberObject(value)) return Reflect.apply(numberValue2, value, []);
|
|
126366
|
+
if (types2.isStringObject(value)) return Reflect.apply(stringValue2, value, []);
|
|
126367
|
+
if (types2.isBooleanObject(value)) return Reflect.apply(booleanValue, value, []);
|
|
126368
|
+
if (types2.isSymbolObject(value)) return Reflect.apply(symbolValue, value, []);
|
|
126369
|
+
return void 0;
|
|
126435
126370
|
}
|
|
126436
|
-
function
|
|
126437
|
-
if (
|
|
126438
|
-
|
|
126439
|
-
|
|
126440
|
-
|
|
126371
|
+
function createSandboxBox(value) {
|
|
126372
|
+
if (typeof value !== "number" && typeof value !== "string" && typeof value !== "boolean" && typeof value !== "symbol")
|
|
126373
|
+
throw new TypeError("Invalid boxed primitive payload.");
|
|
126374
|
+
const box = Object(value);
|
|
126375
|
+
Object.setPrototypeOf(box, null);
|
|
126376
|
+
boxes.add(box);
|
|
126377
|
+
return box;
|
|
126441
126378
|
}
|
|
126442
|
-
function
|
|
126443
|
-
|
|
126444
|
-
for (const adapter of [descriptor.get, descriptor.set]) {
|
|
126445
|
-
const closure = adapter === void 0 ? void 0 : accessorClosures.get(adapter);
|
|
126446
|
-
if (closure !== void 0) closures.push(closure);
|
|
126447
|
-
}
|
|
126448
|
-
return closures;
|
|
126379
|
+
function isSandboxBox(value) {
|
|
126380
|
+
return typeof value === "object" && value !== null && boxes.has(value);
|
|
126449
126381
|
}
|
|
126450
|
-
function
|
|
126451
|
-
if (
|
|
126452
|
-
|
|
126453
|
-
const getter = accessorClosures.get(descriptor.get);
|
|
126454
|
-
if (getter === void 0) {
|
|
126455
|
-
if (!allowNativeGetter) throw new TypeError("Native accessors cannot execute in the sandbox.");
|
|
126456
|
-
return Reflect.apply(descriptor.get, receiver, []);
|
|
126457
|
-
}
|
|
126458
|
-
if (context?.invokeClosure === void 0)
|
|
126459
|
-
throw new TypeError("Accessor reads require sandbox execution.");
|
|
126460
|
-
return context.invokeClosure(getter, [], receiver);
|
|
126382
|
+
function boxedValue(value) {
|
|
126383
|
+
if (!boxes.has(value)) throw new TypeError("Expected a sandbox boxed primitive.");
|
|
126384
|
+
return nativeBoxedValue(value);
|
|
126461
126385
|
}
|
|
126462
|
-
function
|
|
126463
|
-
const
|
|
126464
|
-
if (
|
|
126465
|
-
|
|
126466
|
-
throw new TypeError("Accessor writes require sandbox execution.");
|
|
126467
|
-
return context.invokeClosure(setter, [value], receiver).then(() => void 0);
|
|
126386
|
+
function primitiveReceiver(value, kind) {
|
|
126387
|
+
const primitive = isSandboxBox(value) ? boxedValue(value) : value;
|
|
126388
|
+
if (typeof primitive !== kind) throw new TypeError(`${kind} method requires a ${kind} receiver.`);
|
|
126389
|
+
return primitive;
|
|
126468
126390
|
}
|
|
126469
|
-
|
|
126470
|
-
|
|
126471
|
-
|
|
126391
|
+
function boxedDataProperties(value, includeSymbols = false) {
|
|
126392
|
+
const primitive = nativeBoxedValue(value);
|
|
126393
|
+
const descriptors = Object.getOwnPropertyDescriptors(value);
|
|
126394
|
+
const keys = includeSymbols ? Reflect.ownKeys(descriptors) : Object.keys(descriptors);
|
|
126395
|
+
return keys.map((key3) => [key3, Object.getOwnPropertyDescriptor(descriptors, key3).value]).filter(([key3]) => {
|
|
126396
|
+
if (typeof key3 === "symbol") return true;
|
|
126397
|
+
if (typeof primitive !== "string") return true;
|
|
126398
|
+
if (key3 === "length") return false;
|
|
126399
|
+
const index = Number(key3);
|
|
126400
|
+
return !(Number.isInteger(index) && index >= 0 && index < primitive.length && String(index) === key3);
|
|
126401
|
+
});
|
|
126402
|
+
}
|
|
126403
|
+
var boxes, numberValue2, stringValue2, booleanValue, symbolValue;
|
|
126404
|
+
var init_boxed = __esm({
|
|
126405
|
+
"packages/safe-js/src/interp/boxed.ts"() {
|
|
126472
126406
|
"use strict";
|
|
126473
|
-
|
|
126474
|
-
|
|
126475
|
-
|
|
126407
|
+
boxes = /* @__PURE__ */ new WeakSet();
|
|
126408
|
+
numberValue2 = Number.prototype.valueOf;
|
|
126409
|
+
stringValue2 = String.prototype.valueOf;
|
|
126410
|
+
booleanValue = Boolean.prototype.valueOf;
|
|
126411
|
+
symbolValue = Symbol.prototype.valueOf;
|
|
126476
126412
|
}
|
|
126477
126413
|
});
|
|
126478
126414
|
|
|
@@ -126880,99 +126816,6 @@ var init_host_capabilities = __esm({
|
|
|
126880
126816
|
}
|
|
126881
126817
|
});
|
|
126882
126818
|
|
|
126883
|
-
// packages/safe-js/src/observability/otel.ts
|
|
126884
|
-
function bindOtelSpan(value, span) {
|
|
126885
|
-
spanByAsyncValue.set(value, span);
|
|
126886
|
-
}
|
|
126887
|
-
function getBoundOtelSpan(value) {
|
|
126888
|
-
return typeof value === "object" && value !== null ? spanByAsyncValue.get(value) : void 0;
|
|
126889
|
-
}
|
|
126890
|
-
function activateOtelSpan(span) {
|
|
126891
|
-
activeSpans.push(span);
|
|
126892
|
-
return () => {
|
|
126893
|
-
const index = activeSpans.lastIndexOf(span);
|
|
126894
|
-
if (index !== -1) {
|
|
126895
|
-
activeSpans.splice(index, 1);
|
|
126896
|
-
}
|
|
126897
|
-
};
|
|
126898
|
-
}
|
|
126899
|
-
function getActiveOtelSpan() {
|
|
126900
|
-
return activeSpans.at(-1);
|
|
126901
|
-
}
|
|
126902
|
-
function activateOtelSink(sink) {
|
|
126903
|
-
if (sink === void 0) {
|
|
126904
|
-
return () => void 0;
|
|
126905
|
-
}
|
|
126906
|
-
activeSinks.push(sink);
|
|
126907
|
-
return () => {
|
|
126908
|
-
const index = activeSinks.lastIndexOf(sink);
|
|
126909
|
-
if (index !== -1) {
|
|
126910
|
-
activeSinks.splice(index, 1);
|
|
126911
|
-
}
|
|
126912
|
-
};
|
|
126913
|
-
}
|
|
126914
|
-
function getActiveOtelSink() {
|
|
126915
|
-
return activeSinks.at(-1);
|
|
126916
|
-
}
|
|
126917
|
-
function safeStartSpan2(sink, name, attrs) {
|
|
126918
|
-
if (sink === void 0) {
|
|
126919
|
-
return noopOtelSpan2;
|
|
126920
|
-
}
|
|
126921
|
-
try {
|
|
126922
|
-
return sink.startSpan(name, attrs);
|
|
126923
|
-
} catch (error3) {
|
|
126924
|
-
warnOtelSinkFailure2("startSpan", error3);
|
|
126925
|
-
return noopOtelSpan2;
|
|
126926
|
-
}
|
|
126927
|
-
}
|
|
126928
|
-
function safeAddEvent2(span, name, attrs) {
|
|
126929
|
-
if (span === void 0) {
|
|
126930
|
-
return;
|
|
126931
|
-
}
|
|
126932
|
-
try {
|
|
126933
|
-
span.addEvent(name, attrs ?? {});
|
|
126934
|
-
} catch (error3) {
|
|
126935
|
-
warnOtelSinkFailure2("addEvent", error3);
|
|
126936
|
-
}
|
|
126937
|
-
}
|
|
126938
|
-
function safeRecordException2(sink, span, error3) {
|
|
126939
|
-
if (sink === void 0) {
|
|
126940
|
-
return;
|
|
126941
|
-
}
|
|
126942
|
-
try {
|
|
126943
|
-
sink.recordException(span, error3);
|
|
126944
|
-
} catch (recordError) {
|
|
126945
|
-
warnOtelSinkFailure2("recordException", recordError);
|
|
126946
|
-
}
|
|
126947
|
-
}
|
|
126948
|
-
function safeEndSpan2(span) {
|
|
126949
|
-
try {
|
|
126950
|
-
span.end();
|
|
126951
|
-
} catch (error3) {
|
|
126952
|
-
warnOtelSinkFailure2("end", error3);
|
|
126953
|
-
}
|
|
126954
|
-
}
|
|
126955
|
-
function warnOtelSinkFailure2(method, error3) {
|
|
126956
|
-
console.warn(`OpenTelemetry sink ${method} failed: ${readErrorMessage3(error3)}`);
|
|
126957
|
-
}
|
|
126958
|
-
function readErrorMessage3(error3) {
|
|
126959
|
-
return error3 instanceof Error ? error3.message : String(error3);
|
|
126960
|
-
}
|
|
126961
|
-
var noopOtelSpan2, spanByAsyncValue, activeSpans, activeSinks;
|
|
126962
|
-
var init_otel2 = __esm({
|
|
126963
|
-
"packages/safe-js/src/observability/otel.ts"() {
|
|
126964
|
-
"use strict";
|
|
126965
|
-
noopOtelSpan2 = {
|
|
126966
|
-
setAttribute: () => void 0,
|
|
126967
|
-
addEvent: () => void 0,
|
|
126968
|
-
end: () => void 0
|
|
126969
|
-
};
|
|
126970
|
-
spanByAsyncValue = /* @__PURE__ */ new WeakMap();
|
|
126971
|
-
activeSpans = [];
|
|
126972
|
-
activeSinks = [];
|
|
126973
|
-
}
|
|
126974
|
-
});
|
|
126975
|
-
|
|
126976
126819
|
// packages/safe-js/src/interp/float32.ts
|
|
126977
126820
|
function isFloat32Array(value) {
|
|
126978
126821
|
return ArrayBuffer.isView(value) && Object.getPrototypeOf(value) === Float32Array.prototype && Reflect.apply(readTag, value, []) === "Float32Array";
|
|
@@ -127515,6 +127358,406 @@ var init_promise_replay = __esm({
|
|
|
127515
127358
|
}
|
|
127516
127359
|
});
|
|
127517
127360
|
|
|
127361
|
+
// packages/safe-js/src/interp/arguments.ts
|
|
127362
|
+
function createSandboxArguments(values) {
|
|
127363
|
+
const result = /* @__PURE__ */ (function() {
|
|
127364
|
+
return arguments;
|
|
127365
|
+
})();
|
|
127366
|
+
for (let index = 0; index < values.length; index += 1) {
|
|
127367
|
+
result[index] = values[index];
|
|
127368
|
+
}
|
|
127369
|
+
result.length = values.length;
|
|
127370
|
+
Object.defineProperty(result, sandboxArgumentsBrand, { value: true });
|
|
127371
|
+
return result;
|
|
127372
|
+
}
|
|
127373
|
+
function isSandboxArguments(value) {
|
|
127374
|
+
return typeof value === "object" && value !== null && Object.hasOwn(value, sandboxArgumentsBrand);
|
|
127375
|
+
}
|
|
127376
|
+
function getSandboxArgumentEntries(value) {
|
|
127377
|
+
return Object.entries(Object.getOwnPropertyDescriptors(value)).flatMap(
|
|
127378
|
+
([key3, descriptor]) => "value" in descriptor ? [[key3, descriptor.value]] : []
|
|
127379
|
+
);
|
|
127380
|
+
}
|
|
127381
|
+
function copySandboxArgumentProperties(source, target, copyValue) {
|
|
127382
|
+
const names = Object.getOwnPropertyNames(source);
|
|
127383
|
+
if (!names.includes("length") || names.indexOf("length") > names.indexOf("callee")) {
|
|
127384
|
+
Reflect.deleteProperty(target, "length");
|
|
127385
|
+
}
|
|
127386
|
+
for (const [key3, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(source))) {
|
|
127387
|
+
if (!("value" in descriptor)) {
|
|
127388
|
+
if (key3 !== "callee") throw new TypeError(`Cannot copy arguments accessor '${key3}'.`);
|
|
127389
|
+
continue;
|
|
127390
|
+
}
|
|
127391
|
+
Object.defineProperty(target, key3, { ...descriptor, value: copyValue(descriptor.value, key3) });
|
|
127392
|
+
}
|
|
127393
|
+
const iterator = Object.getOwnPropertyDescriptor(source, Symbol.iterator);
|
|
127394
|
+
if (iterator === void 0) {
|
|
127395
|
+
Reflect.deleteProperty(target, Symbol.iterator);
|
|
127396
|
+
} else {
|
|
127397
|
+
if (iterator.value !== Array.prototype.values) {
|
|
127398
|
+
throw new TypeError("Cannot copy a replaced arguments iterator.");
|
|
127399
|
+
}
|
|
127400
|
+
Object.defineProperty(target, Symbol.iterator, iterator);
|
|
127401
|
+
}
|
|
127402
|
+
if (!Object.isExtensible(source)) Object.preventExtensions(target);
|
|
127403
|
+
}
|
|
127404
|
+
var sandboxArgumentsBrand;
|
|
127405
|
+
var init_arguments = __esm({
|
|
127406
|
+
"packages/safe-js/src/interp/arguments.ts"() {
|
|
127407
|
+
"use strict";
|
|
127408
|
+
init_internal_symbols();
|
|
127409
|
+
sandboxArgumentsBrand = /* @__PURE__ */ Symbol("SandboxArguments");
|
|
127410
|
+
internalSymbols.add(sandboxArgumentsBrand);
|
|
127411
|
+
}
|
|
127412
|
+
});
|
|
127413
|
+
|
|
127414
|
+
// packages/safe-js/src/graph-depth.ts
|
|
127415
|
+
function assertSandboxDataDepth(depth) {
|
|
127416
|
+
if (depth > MAX_DATA_DEPTH) {
|
|
127417
|
+
throw new SandboxError({ budget: "dataDepth", current: depth, limit: MAX_DATA_DEPTH });
|
|
127418
|
+
}
|
|
127419
|
+
}
|
|
127420
|
+
function assertSnapshotDataDepth(depth, path193) {
|
|
127421
|
+
if (depth > MAX_DATA_DEPTH) throw new SnapshotBudgetError(path193, depth);
|
|
127422
|
+
}
|
|
127423
|
+
function assertSnapshotGraphDepth(value, rootPath = "$") {
|
|
127424
|
+
walkGraphDepth(value, rootPath, (depth, path193) => assertSnapshotDataDepth(depth, path193));
|
|
127425
|
+
}
|
|
127426
|
+
function assertSandboxGraphDepth(value) {
|
|
127427
|
+
walkGraphDepth(value, "<root>", (depth) => assertSandboxDataDepth(depth));
|
|
127428
|
+
}
|
|
127429
|
+
function walkGraphDepth(root, rootPath, assertDepth) {
|
|
127430
|
+
const ancestors = /* @__PURE__ */ new WeakSet();
|
|
127431
|
+
const stack = [{ value: root, path: rootPath, depth: 0, exiting: false }];
|
|
127432
|
+
while (stack.length > 0) {
|
|
127433
|
+
const frame = stack.pop();
|
|
127434
|
+
if (typeof frame.value !== "object" || frame.value === null) continue;
|
|
127435
|
+
if (frame.exiting) {
|
|
127436
|
+
ancestors.delete(frame.value);
|
|
127437
|
+
continue;
|
|
127438
|
+
}
|
|
127439
|
+
assertDepth(frame.depth, frame.path);
|
|
127440
|
+
if (ancestors.has(frame.value)) continue;
|
|
127441
|
+
ancestors.add(frame.value);
|
|
127442
|
+
stack.push({ ...frame, exiting: true });
|
|
127443
|
+
const entries = graphEntries(frame.value);
|
|
127444
|
+
for (let index = entries.length - 1; index >= 0; index -= 1) {
|
|
127445
|
+
const [key3, entry] = entries[index];
|
|
127446
|
+
stack.push({
|
|
127447
|
+
value: entry,
|
|
127448
|
+
path: `${frame.path}${key3}`,
|
|
127449
|
+
depth: frame.depth + 1,
|
|
127450
|
+
exiting: false
|
|
127451
|
+
});
|
|
127452
|
+
}
|
|
127453
|
+
}
|
|
127454
|
+
}
|
|
127455
|
+
function graphEntries(value) {
|
|
127456
|
+
const properties = regexGuestProperties.get(value);
|
|
127457
|
+
if (properties !== void 0) return Reflect.ownKeys(properties).flatMap((key3) => {
|
|
127458
|
+
const descriptor = Object.getOwnPropertyDescriptor(properties, key3);
|
|
127459
|
+
return "value" in descriptor ? [[`.${String(key3)}`, descriptor.value]] : [];
|
|
127460
|
+
});
|
|
127461
|
+
if (isSandboxBox(value)) return boxedDataProperties(value).map(([key3, descriptor]) => [`.${key3}`, descriptor.value]);
|
|
127462
|
+
if (isSandboxArguments(value)) {
|
|
127463
|
+
return getSandboxArgumentEntries(value).map(([key3, entry]) => [`.${key3}`, entry]);
|
|
127464
|
+
}
|
|
127465
|
+
const map = isSandboxMap(value) ? value.entries : value instanceof Map ? value : void 0;
|
|
127466
|
+
if (map !== void 0) {
|
|
127467
|
+
return [...map.entries()].flatMap(([key3, entry], index) => [
|
|
127468
|
+
[`.<map>[${index}].key`, key3],
|
|
127469
|
+
[`.<map>[${index}].value`, entry]
|
|
127470
|
+
]);
|
|
127471
|
+
}
|
|
127472
|
+
const set = isSandboxSet(value) ? value.values : value instanceof Set ? value : void 0;
|
|
127473
|
+
if (set !== void 0) {
|
|
127474
|
+
return [...set.values()].map((entry, index) => [`.<set>[${index}]`, entry]);
|
|
127475
|
+
}
|
|
127476
|
+
const entries = [];
|
|
127477
|
+
if (isSandboxCollectionIterator(value)) entries.push([".<collection>", collectionIteratorState(value).collection]);
|
|
127478
|
+
for (const key3 of Object.keys(value)) {
|
|
127479
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key3);
|
|
127480
|
+
if (descriptor !== void 0 && "value" in descriptor)
|
|
127481
|
+
entries.push([Array.isArray(value) ? `[${key3}]` : `.${key3}`, descriptor.value]);
|
|
127482
|
+
}
|
|
127483
|
+
return entries;
|
|
127484
|
+
}
|
|
127485
|
+
var MAX_DATA_DEPTH, SnapshotBudgetError;
|
|
127486
|
+
var init_graph_depth = __esm({
|
|
127487
|
+
"packages/safe-js/src/graph-depth.ts"() {
|
|
127488
|
+
"use strict";
|
|
127489
|
+
init_shape();
|
|
127490
|
+
init_budget2();
|
|
127491
|
+
init_arguments();
|
|
127492
|
+
init_collection_iterator();
|
|
127493
|
+
init_collection_brands();
|
|
127494
|
+
init_boxed();
|
|
127495
|
+
init_regexp_properties();
|
|
127496
|
+
MAX_DATA_DEPTH = 1024;
|
|
127497
|
+
SnapshotBudgetError = class extends Error {
|
|
127498
|
+
code = "budgetExceeded";
|
|
127499
|
+
budget = "dataDepth";
|
|
127500
|
+
current;
|
|
127501
|
+
limit;
|
|
127502
|
+
path;
|
|
127503
|
+
constructor(path193, current, limit = MAX_DATA_DEPTH) {
|
|
127504
|
+
super(`Snapshot budget exceeded for dataDepth at ${path193}: ${current} > ${limit}.`);
|
|
127505
|
+
this.name = "SnapshotBudgetError";
|
|
127506
|
+
this.current = current;
|
|
127507
|
+
this.limit = limit;
|
|
127508
|
+
this.path = path193;
|
|
127509
|
+
replaceErrorStack(this);
|
|
127510
|
+
}
|
|
127511
|
+
};
|
|
127512
|
+
}
|
|
127513
|
+
});
|
|
127514
|
+
|
|
127515
|
+
// packages/safe-js/src/interp/object-model.ts
|
|
127516
|
+
function registerGuestClosure(closure) {
|
|
127517
|
+
guestClosures.add(closure);
|
|
127518
|
+
}
|
|
127519
|
+
function isGuestClosure(value) {
|
|
127520
|
+
return typeof value === "object" && value !== null && guestClosures.has(value);
|
|
127521
|
+
}
|
|
127522
|
+
function getGuestFunctionProperties(closure) {
|
|
127523
|
+
return functionProperties.get(closure);
|
|
127524
|
+
}
|
|
127525
|
+
function materializeFunctionProperties(closure) {
|
|
127526
|
+
if (!isGuestClosure(closure)) throw new TypeError("Host function properties are read only.");
|
|
127527
|
+
const existing = functionProperties.get(closure);
|
|
127528
|
+
if (existing !== void 0) return existing;
|
|
127529
|
+
const properties = /* @__PURE__ */ Object.create(null);
|
|
127530
|
+
Object.defineProperties(properties, {
|
|
127531
|
+
length: { value: closure.length ?? 0, configurable: true },
|
|
127532
|
+
name: { value: closure.name ?? "", configurable: true }
|
|
127533
|
+
});
|
|
127534
|
+
if (closure.construct !== void 0 && closure.boundTarget === void 0) {
|
|
127535
|
+
const prototype = /* @__PURE__ */ Object.create(null);
|
|
127536
|
+
Object.defineProperty(prototype, "constructor", {
|
|
127537
|
+
value: closure,
|
|
127538
|
+
writable: true,
|
|
127539
|
+
configurable: true
|
|
127540
|
+
});
|
|
127541
|
+
descriptorObjects.add(prototype);
|
|
127542
|
+
Object.defineProperty(properties, "prototype", { value: prototype, writable: true });
|
|
127543
|
+
}
|
|
127544
|
+
descriptorObjects.add(properties);
|
|
127545
|
+
functionProperties.set(closure, properties);
|
|
127546
|
+
return properties;
|
|
127547
|
+
}
|
|
127548
|
+
function getGuestFunctionProperty(closure, key3) {
|
|
127549
|
+
let properties = functionProperties.get(closure);
|
|
127550
|
+
if (properties === void 0) {
|
|
127551
|
+
if (key3 === "length") return closure.length ?? 0;
|
|
127552
|
+
if (key3 === "name") return closure.name ?? "";
|
|
127553
|
+
if (key3 === "prototype" && closure.construct !== void 0 && closure.boundTarget === void 0) {
|
|
127554
|
+
properties = materializeFunctionProperties(closure);
|
|
127555
|
+
}
|
|
127556
|
+
}
|
|
127557
|
+
return properties === void 0 ? void 0 : Object.getOwnPropertyDescriptor(properties, key3)?.value;
|
|
127558
|
+
}
|
|
127559
|
+
function installObjectPrototype(budget, prototype, constructor) {
|
|
127560
|
+
prototypes.set(prototype, null);
|
|
127561
|
+
intrinsicPrototypes.set(budget, prototype);
|
|
127562
|
+
registerIntrinsicPrototype(budget, prototype, constructor);
|
|
127563
|
+
}
|
|
127564
|
+
function installBoxedPrototype(budget, prototype, constructor, kind = typeof boxedValue(prototype)) {
|
|
127565
|
+
let state = boxedPrototypes.get(budget);
|
|
127566
|
+
if (state === void 0) boxedPrototypes.set(budget, state = /* @__PURE__ */ new Map());
|
|
127567
|
+
state.set(kind, prototype);
|
|
127568
|
+
initialBoxedMethods.set(prototype, new Map(Object.entries(Object.getOwnPropertyDescriptors(prototype)).map(([key3, descriptor]) => [key3, descriptor.value])));
|
|
127569
|
+
registerIntrinsicPrototype(budget, prototype, constructor);
|
|
127570
|
+
}
|
|
127571
|
+
function getBoxedPrototype(value, budget) {
|
|
127572
|
+
return boxedPrototypes.get(budget)?.get(typeof value);
|
|
127573
|
+
}
|
|
127574
|
+
function isDefaultBoxedMethod(value, key3, budget) {
|
|
127575
|
+
const prototype = getBoxedPrototype(value, budget);
|
|
127576
|
+
return prototype !== void 0 && initialBoxedMethods.get(prototype)?.has(key3) === true && Object.getOwnPropertyDescriptor(prototype, key3)?.value === initialBoxedMethods.get(prototype)?.get(key3);
|
|
127577
|
+
}
|
|
127578
|
+
function isIntrinsicConstructor(value) {
|
|
127579
|
+
return intrinsicConstructors.has(value);
|
|
127580
|
+
}
|
|
127581
|
+
function registerIntrinsicPrototype(budget, prototype, constructor) {
|
|
127582
|
+
let roots = intrinsicPrototypeRoots.get(budget);
|
|
127583
|
+
if (roots === void 0) intrinsicPrototypeRoots.set(budget, roots = /* @__PURE__ */ new Set());
|
|
127584
|
+
roots.add(prototype);
|
|
127585
|
+
const records = [prototype, constructor].map((target) => ({
|
|
127586
|
+
target,
|
|
127587
|
+
value: isGuestClosure(target) ? materializeFunctionProperties(target) : target,
|
|
127588
|
+
prototype: getSandboxPrototype(target),
|
|
127589
|
+
explicit: hasExplicitSandboxPrototype(target)
|
|
127590
|
+
})).map((record2) => ({
|
|
127591
|
+
...record2,
|
|
127592
|
+
descriptors: new Map(Object.entries(Object.getOwnPropertyDescriptors(record2.value)))
|
|
127593
|
+
}));
|
|
127594
|
+
const unchanged = (before, after) => before !== void 0 && after !== void 0 && Object.is(before.value, after.value) && before.get === after.get && before.set === after.set && before.writable === after.writable && before.configurable === after.configurable && before.enumerable === after.enumerable;
|
|
127595
|
+
intrinsicConstructors.set(
|
|
127596
|
+
constructor,
|
|
127597
|
+
() => records.every(({ target, value, descriptors, prototype: parent, explicit }) => {
|
|
127598
|
+
const current = Object.getOwnPropertyDescriptors(value);
|
|
127599
|
+
return getSandboxPrototype(target) === parent && hasExplicitSandboxPrototype(target) === explicit && Object.keys(current).length === descriptors.size && Object.keys(current).every((key3) => unchanged(descriptors.get(key3), current[key3]));
|
|
127600
|
+
})
|
|
127601
|
+
);
|
|
127602
|
+
budget.setRetainedValues(
|
|
127603
|
+
prototype,
|
|
127604
|
+
() => records.flatMap(({ target, value, descriptors, prototype: parent }) => [
|
|
127605
|
+
...getSandboxPrototype(target) === parent ? [] : [getSandboxPrototype(target)],
|
|
127606
|
+
...Object.entries(Object.getOwnPropertyDescriptors(value)).flatMap(
|
|
127607
|
+
([key3, descriptor]) => unchanged(descriptors.get(key3), descriptor) ? [] : [key3, descriptor.value, ...retainedAccessorClosures(descriptor)]
|
|
127608
|
+
)
|
|
127609
|
+
])
|
|
127610
|
+
);
|
|
127611
|
+
}
|
|
127612
|
+
function releaseObjectPrototype(budget) {
|
|
127613
|
+
for (const prototype of intrinsicPrototypeRoots.get(budget) ?? []) budget.setRetainedValues(prototype, void 0);
|
|
127614
|
+
intrinsicPrototypeRoots.delete(budget);
|
|
127615
|
+
boxedPrototypes.delete(budget);
|
|
127616
|
+
intrinsicPrototypes.delete(budget);
|
|
127617
|
+
}
|
|
127618
|
+
function getSandboxPrototype(value, budget) {
|
|
127619
|
+
if (prototypes.has(value)) return prototypes.get(value) ?? null;
|
|
127620
|
+
if (budget !== void 0 && isSandboxBox(value)) {
|
|
127621
|
+
const prototype = getBoxedPrototype(boxedValue(value), budget);
|
|
127622
|
+
if (prototype !== void 0 && prototype !== value) return prototype;
|
|
127623
|
+
}
|
|
127624
|
+
return budget !== void 0 && !isSandboxClosure(value) && isPrototypeRecord(value) ? intrinsicPrototypes.get(budget) ?? null : null;
|
|
127625
|
+
}
|
|
127626
|
+
function hasExplicitSandboxPrototype(value) {
|
|
127627
|
+
return prototypes.has(value);
|
|
127628
|
+
}
|
|
127629
|
+
function getSandboxPropertyDescriptor(value, key3, budget) {
|
|
127630
|
+
const hostProperties = isSandboxClosure(value) ? value.properties : void 0;
|
|
127631
|
+
if (isSandboxClosure(value) && !isGuestClosure(value))
|
|
127632
|
+
return hostProperties === void 0 ? void 0 : Object.getOwnPropertyDescriptor(hostProperties, key3);
|
|
127633
|
+
let current = value;
|
|
127634
|
+
let depth = 0;
|
|
127635
|
+
while (typeof current === "object" && current !== null && (Array.isArray(current) || isSandboxDate(current) || isSandboxRegex(current) || isPrototypeRecord(current))) {
|
|
127636
|
+
const properties = isGuestClosure(current) ? getGuestFunctionProperties(current) : isSandboxRegex(current) ? getRegexProperties(current) : current;
|
|
127637
|
+
const descriptor = properties === void 0 ? void 0 : Object.getOwnPropertyDescriptor(properties, key3);
|
|
127638
|
+
if (descriptor !== void 0) return descriptor;
|
|
127639
|
+
current = getSandboxPrototype(current, budget);
|
|
127640
|
+
if (current !== null) {
|
|
127641
|
+
budget?.visitNode();
|
|
127642
|
+
assertSandboxDataDepth(++depth);
|
|
127643
|
+
}
|
|
127644
|
+
}
|
|
127645
|
+
return void 0;
|
|
127646
|
+
}
|
|
127647
|
+
function getSandboxDataProperty(value, key3, budget) {
|
|
127648
|
+
let current = value;
|
|
127649
|
+
let depth = 0;
|
|
127650
|
+
while (typeof current === "object" && current !== null) {
|
|
127651
|
+
if (isGuestHostObject(current)) return typeof key3 === "symbol" ? void 0 : getHostObjectMember(current, String(key3));
|
|
127652
|
+
if (isSandboxRegex(current)) return Object.getOwnPropertyDescriptor(getRegexProperties(current), key3)?.value;
|
|
127653
|
+
if (isGuestClosure(current)) {
|
|
127654
|
+
const entry = getGuestFunctionProperty(current, key3);
|
|
127655
|
+
if (entry !== void 0 || Object.hasOwn(current.properties ?? {}, key3)) return entry;
|
|
127656
|
+
} else if (isSandboxClosure(current)) {
|
|
127657
|
+
const properties = current.properties;
|
|
127658
|
+
return properties !== void 0 && Object.hasOwn(properties, key3) ? properties[key3] : void 0;
|
|
127659
|
+
}
|
|
127660
|
+
if (isSandboxMap(current) || isSandboxSet(current) || isSandboxPromise(current) || isSandboxRegex(current) || isSandboxGenerator(current))
|
|
127661
|
+
return void 0;
|
|
127662
|
+
if (!isSandboxClosure(current) && Object.hasOwn(current, key3)) return current[key3];
|
|
127663
|
+
current = getSandboxPrototype(current, budget);
|
|
127664
|
+
if (current !== null) {
|
|
127665
|
+
budget?.visitNode();
|
|
127666
|
+
assertSandboxDataDepth(++depth);
|
|
127667
|
+
}
|
|
127668
|
+
}
|
|
127669
|
+
return void 0;
|
|
127670
|
+
}
|
|
127671
|
+
function setSandboxPrototype(value, prototype, budget) {
|
|
127672
|
+
if (budget !== void 0 && intrinsicPrototypes.get(budget) === value && prototype !== null) {
|
|
127673
|
+
throw new TypeError("Object.prototype has an immutable null prototype.");
|
|
127674
|
+
}
|
|
127675
|
+
if (!Array.isArray(value) && !isPrototypeRecord(value) || prototype !== null && !Array.isArray(prototype) && !isPrototypeRecord(prototype)) {
|
|
127676
|
+
throw new TypeError(
|
|
127677
|
+
"Prototype links require ordinary sandbox objects, arrays, or guest functions."
|
|
127678
|
+
);
|
|
127679
|
+
}
|
|
127680
|
+
if (prototypes.has(value) && getSandboxPrototype(value, budget) === prototype) return;
|
|
127681
|
+
if (!Object.isExtensible(isGuestClosure(value) ? materializeFunctionProperties(value) : value)) {
|
|
127682
|
+
throw new TypeError("Cannot change the prototype of a non-extensible object.");
|
|
127683
|
+
}
|
|
127684
|
+
let depth = 0;
|
|
127685
|
+
for (let current = prototype; current !== null; current = getSandboxPrototype(current, budget)) {
|
|
127686
|
+
budget?.visitNode();
|
|
127687
|
+
assertSandboxDataDepth(depth++);
|
|
127688
|
+
if (current === value) throw new TypeError("Cyclic prototype value.");
|
|
127689
|
+
}
|
|
127690
|
+
prototypes.set(value, prototype);
|
|
127691
|
+
}
|
|
127692
|
+
function isPrototypeRecord(value) {
|
|
127693
|
+
if (isGuestClosure(value)) return true;
|
|
127694
|
+
if (isGuestHostObject(value)) return false;
|
|
127695
|
+
if (isSandboxClosure(value) || isSandboxGenerator(value) || isSandboxMap(value) || isSandboxPromise(value) || isSandboxRegex(value) || isSandboxSet(value))
|
|
127696
|
+
return false;
|
|
127697
|
+
const prototype = Object.getPrototypeOf(value);
|
|
127698
|
+
return prototype === null || prototype === Object.prototype;
|
|
127699
|
+
}
|
|
127700
|
+
function markDescriptorObject(value) {
|
|
127701
|
+
descriptorObjects.add(value);
|
|
127702
|
+
}
|
|
127703
|
+
function hasManagedDescriptors(value) {
|
|
127704
|
+
return descriptorObjects.has(value);
|
|
127705
|
+
}
|
|
127706
|
+
function hasGuestObjectState(value) {
|
|
127707
|
+
const intrinsicUnchanged = intrinsicConstructors.get(value);
|
|
127708
|
+
if (intrinsicUnchanged !== void 0) return !intrinsicUnchanged();
|
|
127709
|
+
if (isLiveCapability(value)) return true;
|
|
127710
|
+
if (functionProperties.has(value) || prototypes.has(value)) return true;
|
|
127711
|
+
if (isSandboxBox(value) || isSandboxDate(value)) return false;
|
|
127712
|
+
return descriptorObjects.has(value) && Object.values(Object.getOwnPropertyDescriptors(value)).some(
|
|
127713
|
+
(descriptor) => !descriptor.enumerable || !descriptor.configurable || !descriptor.writable
|
|
127714
|
+
);
|
|
127715
|
+
}
|
|
127716
|
+
var guestClosures, functionProperties, prototypes, intrinsicPrototypes, boxedPrototypes, intrinsicPrototypeRoots, intrinsicConstructors, initialBoxedMethods, descriptorObjects;
|
|
127717
|
+
var init_object_model = __esm({
|
|
127718
|
+
"packages/safe-js/src/interp/object-model.ts"() {
|
|
127719
|
+
"use strict";
|
|
127720
|
+
init_graph_depth();
|
|
127721
|
+
init_date();
|
|
127722
|
+
init_accessors();
|
|
127723
|
+
init_host_capabilities();
|
|
127724
|
+
init_boxed();
|
|
127725
|
+
init_values();
|
|
127726
|
+
guestClosures = /* @__PURE__ */ new WeakSet();
|
|
127727
|
+
functionProperties = /* @__PURE__ */ new WeakMap();
|
|
127728
|
+
prototypes = /* @__PURE__ */ new WeakMap();
|
|
127729
|
+
intrinsicPrototypes = /* @__PURE__ */ new WeakMap();
|
|
127730
|
+
boxedPrototypes = /* @__PURE__ */ new WeakMap();
|
|
127731
|
+
intrinsicPrototypeRoots = /* @__PURE__ */ new WeakMap();
|
|
127732
|
+
intrinsicConstructors = /* @__PURE__ */ new WeakMap();
|
|
127733
|
+
initialBoxedMethods = /* @__PURE__ */ new WeakMap();
|
|
127734
|
+
descriptorObjects = /* @__PURE__ */ new WeakSet();
|
|
127735
|
+
}
|
|
127736
|
+
});
|
|
127737
|
+
|
|
127738
|
+
// packages/safe-js/src/interp/symbols.ts
|
|
127739
|
+
var wellKnownSymbols;
|
|
127740
|
+
var init_symbols2 = __esm({
|
|
127741
|
+
"packages/safe-js/src/interp/symbols.ts"() {
|
|
127742
|
+
"use strict";
|
|
127743
|
+
wellKnownSymbols = Object.freeze({
|
|
127744
|
+
iterator: Symbol.iterator,
|
|
127745
|
+
asyncIterator: Symbol.asyncIterator,
|
|
127746
|
+
hasInstance: Symbol.hasInstance,
|
|
127747
|
+
isConcatSpreadable: Symbol.isConcatSpreadable,
|
|
127748
|
+
match: Symbol.match,
|
|
127749
|
+
matchAll: Symbol.matchAll,
|
|
127750
|
+
replace: Symbol.replace,
|
|
127751
|
+
search: Symbol.search,
|
|
127752
|
+
species: Symbol.species,
|
|
127753
|
+
split: Symbol.split,
|
|
127754
|
+
toPrimitive: Symbol.toPrimitive,
|
|
127755
|
+
toStringTag: Symbol.toStringTag,
|
|
127756
|
+
unscopables: Symbol.unscopables
|
|
127757
|
+
});
|
|
127758
|
+
}
|
|
127759
|
+
});
|
|
127760
|
+
|
|
127518
127761
|
// packages/safe-js/src/snapshot/symbols.ts
|
|
127519
127762
|
function symbolData(value) {
|
|
127520
127763
|
const wellKnown = Object.keys(wellKnownSymbols).find((key3) => wellKnownSymbols[key3] === value);
|
|
@@ -127542,6 +127785,13 @@ function serializeSymbolProperties(value, encode) {
|
|
|
127542
127785
|
return [encode(key3), { value: encode(descriptor.value), enumerable: descriptor.enumerable === true, writable: descriptor.writable === true, configurable: descriptor.configurable === true }];
|
|
127543
127786
|
});
|
|
127544
127787
|
}
|
|
127788
|
+
function restoreSymbolProperties(target, entries, decode) {
|
|
127789
|
+
for (const [key3, descriptor] of entries ?? []) {
|
|
127790
|
+
const symbol2 = decode(key3);
|
|
127791
|
+
if (typeof symbol2 !== "symbol") throw new TypeError("Expected a symbol property key");
|
|
127792
|
+
Object.defineProperty(target, symbol2, { ...descriptor, value: decode(descriptor.value) });
|
|
127793
|
+
}
|
|
127794
|
+
}
|
|
127545
127795
|
var init_symbols3 = __esm({
|
|
127546
127796
|
"packages/safe-js/src/snapshot/symbols.ts"() {
|
|
127547
127797
|
"use strict";
|
|
@@ -127790,7 +128040,8 @@ function encodeReplayData(value, options = {}) {
|
|
|
127790
128040
|
kind: "regex",
|
|
127791
128041
|
source: entry.source,
|
|
127792
128042
|
flags: entry.flags,
|
|
127793
|
-
lastIndex: child(entry.lastIndex, "lastIndex")
|
|
128043
|
+
lastIndex: child(entry.lastIndex, "lastIndex"),
|
|
128044
|
+
...serializeRegexProperties(entry, (value2) => child(value2, "<regex-property>"))
|
|
127794
128045
|
};
|
|
127795
128046
|
} else if (isSandboxArguments(entry)) {
|
|
127796
128047
|
nodes[id] = { kind: "arguments", data: serializeArguments(entry, child) };
|
|
@@ -127993,6 +128244,7 @@ function decodeReplayData(input, options = {}, parent) {
|
|
|
127993
128244
|
const result3 = createSandboxRegex(node.source, node.flags, 0, compilation);
|
|
127994
128245
|
restored.set(id, result3);
|
|
127995
128246
|
result3.lastIndex = child(own(node, "lastIndex"));
|
|
128247
|
+
restoreRegexProperties(result3, node, child);
|
|
127996
128248
|
return result3;
|
|
127997
128249
|
}
|
|
127998
128250
|
if (kind === "arguments") {
|
|
@@ -128082,6 +128334,7 @@ var init_replay_data = __esm({
|
|
|
128082
128334
|
"packages/safe-js/src/snapshot/replay-data.ts"() {
|
|
128083
128335
|
"use strict";
|
|
128084
128336
|
init_graph_depth();
|
|
128337
|
+
init_regexp_properties2();
|
|
128085
128338
|
init_symbols2();
|
|
128086
128339
|
init_symbols3();
|
|
128087
128340
|
init_collection_iterator();
|
|
@@ -130135,10 +130388,11 @@ function escapeRegexSource(source, budget) {
|
|
|
130135
130388
|
return budget === void 0 ? text5 : budget.allocateString(text5);
|
|
130136
130389
|
}
|
|
130137
130390
|
function setRegexMember(target, property, value) {
|
|
130138
|
-
|
|
130391
|
+
const properties = getRegexProperties(target);
|
|
130392
|
+
if (!Object.hasOwn(properties, property) && (property === "source" || property === "flags" || Object.hasOwn(regexFlagProperties, property))) {
|
|
130139
130393
|
throw new TypeError(`RegExp#${String(property)} is not writable.`);
|
|
130140
130394
|
}
|
|
130141
|
-
|
|
130395
|
+
if (!Reflect.set(properties, property, value)) throw new TypeError(`RegExp#${String(property)} is not writable.`);
|
|
130142
130396
|
}
|
|
130143
130397
|
async function callRegexMethod(target, methodName, args, budget, context) {
|
|
130144
130398
|
if (target === null || typeof target !== "object" || methodName === "exec" && !isSandboxRegex(target)) {
|
|
@@ -130210,6 +130464,7 @@ var init_regex = __esm({
|
|
|
130210
130464
|
});
|
|
130211
130465
|
|
|
130212
130466
|
// packages/safe-js/src/interp/methods/string.ts
|
|
130467
|
+
import { types as types5 } from "node:util";
|
|
130213
130468
|
function getStringMember(value, property, budget) {
|
|
130214
130469
|
const index = getStringIndex(property);
|
|
130215
130470
|
if (index !== void 0) {
|
|
@@ -130265,15 +130520,39 @@ function callStringMethod(value, methodName, args, budget, callClosure = async (
|
|
|
130265
130520
|
if (value === null || value === void 0)
|
|
130266
130521
|
throw new TypeError(`String#${methodName} requires a non-null receiver.`);
|
|
130267
130522
|
const fallback = () => typeof value === "string" ? callStringMethodBody(value, methodName, args, budget, callClosure, parent, context) : Promise.resolve(sandboxString(value, budget, context)).then((string) => callStringMethodBody(string, methodName, args, budget, callClosure, parent, context));
|
|
130268
|
-
const symbol2 = methodName === "match" ? Symbol.match : methodName === "search" ? Symbol.search : methodName === "split" ? Symbol.split : void 0;
|
|
130523
|
+
const symbol2 = methodName === "match" ? Symbol.match : methodName === "search" ? Symbol.search : methodName === "matchAll" ? Symbol.matchAll : methodName === "replace" || methodName === "replaceAll" ? Symbol.replace : methodName === "split" ? Symbol.split : void 0;
|
|
130269
130524
|
const pattern = args[0];
|
|
130525
|
+
if (symbol2 !== void 0 && types5.isRegExp(pattern))
|
|
130526
|
+
throw new TypeError(`String#${methodName} does not accept unbranded host RegExp values.`);
|
|
130270
130527
|
if (symbol2 === void 0 || pattern === null || pattern === void 0) return fallback();
|
|
130271
130528
|
const applyHook = (hook) => {
|
|
130272
130529
|
if (hook === null || hook === void 0) return fallback();
|
|
130273
130530
|
if (!isSandboxClosure(hook)) throw new TypeError(`String#${methodName} symbol hook must be callable.`);
|
|
130274
|
-
return invokeBuiltinClosure(hook,
|
|
130275
|
-
};
|
|
130276
|
-
|
|
130531
|
+
return invokeBuiltinClosure(hook, symbol2 === Symbol.split || symbol2 === Symbol.replace ? [value, args[1]] : [value], budget, context, pattern);
|
|
130532
|
+
};
|
|
130533
|
+
const readProperty = (key3) => context?.getProperty !== void 0 ? context.getProperty(pattern, key3) : key3 === "flags" && isSandboxRegex(pattern) && getSandboxPropertyDescriptor(pattern, key3, budget) === void 0 ? pattern.flags : getSandboxDataProperty(pattern, key3, budget);
|
|
130534
|
+
const dispatch = () => {
|
|
130535
|
+
const hook = readProperty(symbol2);
|
|
130536
|
+
return hook instanceof Promise ? hook.then(applyHook) : applyHook(hook);
|
|
130537
|
+
};
|
|
130538
|
+
if ((methodName === "replaceAll" || methodName === "matchAll") && (typeof pattern === "object" || typeof pattern === "function")) {
|
|
130539
|
+
const checkFlags = (flags) => {
|
|
130540
|
+
const checkText = (text6) => {
|
|
130541
|
+
if (!text6.includes("g")) throw new TypeError(`String#${methodName} requires a global regex.`);
|
|
130542
|
+
return dispatch();
|
|
130543
|
+
};
|
|
130544
|
+
const text5 = sandboxString(flags, budget, context);
|
|
130545
|
+
return typeof text5 === "string" ? checkText(text5) : text5.then(checkText);
|
|
130546
|
+
};
|
|
130547
|
+
const checkMatch = (match2) => {
|
|
130548
|
+
if (!(match2 === void 0 ? isSandboxRegex(pattern) : Boolean(match2))) return dispatch();
|
|
130549
|
+
const flags = readProperty("flags");
|
|
130550
|
+
return flags instanceof Promise ? flags.then(checkFlags) : checkFlags(flags);
|
|
130551
|
+
};
|
|
130552
|
+
const match = readProperty(Symbol.match);
|
|
130553
|
+
return match instanceof Promise ? match.then(checkMatch) : checkMatch(match);
|
|
130554
|
+
}
|
|
130555
|
+
return dispatch();
|
|
130277
130556
|
}
|
|
130278
130557
|
function callStringMethodBody(value, methodName, args, budget, callClosure = async (closure, closureArgs) => await closure.call(closureArgs), parent, context) {
|
|
130279
130558
|
if (methodName === "concat" && args.some((argument) => argument !== null && typeof argument === "object")) {
|
|
@@ -130318,7 +130597,7 @@ function callStringMethodBody(value, methodName, args, budget, callClosure = asy
|
|
|
130318
130597
|
return callReplaceLikeMethod(value, methodName, args, budget, callClosure, context);
|
|
130319
130598
|
}
|
|
130320
130599
|
const regex = args[0];
|
|
130321
|
-
if (isSandboxRegex(regex) && regex.lastIndex !== null && typeof regex.lastIndex === "object" && (methodName === "match" && !regex.flags.includes("g") || methodName === "matchAll"
|
|
130600
|
+
if (isSandboxRegex(regex) && regex.lastIndex !== null && typeof regex.lastIndex === "object" && (methodName === "match" && !regex.flags.includes("g") || methodName === "matchAll")) {
|
|
130322
130601
|
return callStringRegexCursor(value, methodName, regex, budget, parent, context);
|
|
130323
130602
|
}
|
|
130324
130603
|
if ((methodName === "match" || methodName === "matchAll" || methodName === "search") && !isSandboxRegex(args[0])) {
|
|
@@ -130450,20 +130729,26 @@ async function callConcat(value, args, budget, context) {
|
|
|
130450
130729
|
function callReplaceLikeMethod(value, methodName, args, budget, callClosure, context) {
|
|
130451
130730
|
const search = args[0];
|
|
130452
130731
|
const replacement = args[1];
|
|
130453
|
-
|
|
130454
|
-
|
|
130455
|
-
|
|
130456
|
-
|
|
130732
|
+
const useRegex = isSandboxRegex(search) && getSandboxPropertyDescriptor(search, Symbol.replace, budget) === void 0;
|
|
130733
|
+
if (!useRegex && typeof search !== "string" || typeof replacement !== "string" && !isSandboxClosure(replacement)) {
|
|
130734
|
+
return (async () => {
|
|
130735
|
+
let normalizedSearch;
|
|
130736
|
+
let normalizedReplacement;
|
|
130737
|
+
const release2 = retainValues(budget, () => [normalizedSearch, normalizedReplacement]);
|
|
130738
|
+
try {
|
|
130739
|
+
normalizedSearch = useRegex ? search : await sandboxString(search, budget, context);
|
|
130740
|
+
normalizedReplacement = isSandboxClosure(replacement) ? replacement : await sandboxString(replacement, budget, context);
|
|
130741
|
+
return await callReplaceLikeMethod(value, methodName, [normalizedSearch, normalizedReplacement], budget, callClosure, context);
|
|
130742
|
+
} finally {
|
|
130743
|
+
release2();
|
|
130744
|
+
}
|
|
130745
|
+
})();
|
|
130457
130746
|
}
|
|
130458
130747
|
if (isSandboxRegex(search)) {
|
|
130459
|
-
if (methodName === "replaceAll" && !search.flags.includes("g")) {
|
|
130460
|
-
throw new TypeError("String#replaceAll requires a global regex.");
|
|
130461
|
-
}
|
|
130462
130748
|
return replaceRegex(
|
|
130463
130749
|
value,
|
|
130464
130750
|
search,
|
|
130465
130751
|
replacement,
|
|
130466
|
-
methodName === "replaceAll",
|
|
130467
130752
|
budget,
|
|
130468
130753
|
callClosure,
|
|
130469
130754
|
context
|
|
@@ -130483,14 +130768,14 @@ function callReplaceLikeMethod(value, methodName, args, budget, callClosure, con
|
|
|
130483
130768
|
callClosure
|
|
130484
130769
|
);
|
|
130485
130770
|
}
|
|
130486
|
-
async function replaceRegex(value, regex, replacement,
|
|
130771
|
+
async function replaceRegex(value, regex, replacement, budget, callClosure, context) {
|
|
130487
130772
|
if (regex.flags.includes("g")) regex.lastIndex = 0;
|
|
130488
130773
|
const cursor2 = regex.lastIndex;
|
|
130489
130774
|
const retained = {};
|
|
130490
130775
|
budget.setRetainedValues(retained, () => [value, regex, cursor2, replacement]);
|
|
130491
130776
|
try {
|
|
130492
130777
|
const lastIndex = await sandboxNumber(cursor2, budget, context);
|
|
130493
|
-
const matches = collectRegexMatches(regex, value,
|
|
130778
|
+
const matches = collectRegexMatches(regex, value, regex.flags.includes("g"), void 0, lastIndex);
|
|
130494
130779
|
let result = "";
|
|
130495
130780
|
let copiedThrough = 0;
|
|
130496
130781
|
for (const match of matches) {
|
|
@@ -130657,13 +130942,11 @@ function callMatchLikeMethod(value, methodName, args, compilation, lastIndex) {
|
|
|
130657
130942
|
if (!Object.is(regex.lastIndex, lastIndex2)) regex.lastIndex = lastIndex2;
|
|
130658
130943
|
return match?.index ?? -1;
|
|
130659
130944
|
}
|
|
130660
|
-
if (methodName === "matchAll" && !regex.flags.includes("g"))
|
|
130661
|
-
throw new TypeError("String#matchAll requires a global regex.");
|
|
130662
130945
|
if (methodName === "match" && !regex.flags.includes("g"))
|
|
130663
130946
|
return toMatchArray(executeRegex(regex, value, lastIndex ?? Number(regex.lastIndex)), value);
|
|
130664
130947
|
if (methodName === "match") regex.lastIndex = 0;
|
|
130665
130948
|
const matcher = methodName === "matchAll" ? createSandboxRegex(regex.source, regex.flags, normalizeLastIndex(lastIndex ?? Number(regex.lastIndex)), compilation) : regex;
|
|
130666
|
-
const matches = collectRegexMatches(matcher, value,
|
|
130949
|
+
const matches = collectRegexMatches(matcher, value, matcher.flags.includes("g"), compilation.owner?.budget, Number(matcher.lastIndex));
|
|
130667
130950
|
if (methodName === "match" && matches.length === 0) return null;
|
|
130668
130951
|
return methodName === "match" ? matches.map((match) => match.text) : matches.map((match) => toMatchArray(match, value));
|
|
130669
130952
|
}
|
|
@@ -130996,14 +131279,14 @@ function createObjectArrayGlobals(options) {
|
|
|
130996
131279
|
call: ([value]) => {
|
|
130997
131280
|
if (isGuestHostObject(value))
|
|
130998
131281
|
throw new TypeError("Live host objects cannot be made non-extensible.");
|
|
130999
|
-
Object.preventExtensions(isGuestClosure(value) ? materializeFunctionProperties(value) : value);
|
|
131282
|
+
Object.preventExtensions(isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : value);
|
|
131000
131283
|
return value;
|
|
131001
131284
|
},
|
|
131002
131285
|
name: "preventExtensions"
|
|
131003
131286
|
}),
|
|
131004
131287
|
isExtensible: createSandboxClosure({
|
|
131005
131288
|
sandbox: true,
|
|
131006
|
-
call: ([value]) => Object.isExtensible(isGuestClosure(value) ? materializeFunctionProperties(value) : value),
|
|
131289
|
+
call: ([value]) => Object.isExtensible(isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : value),
|
|
131007
131290
|
name: "isExtensible"
|
|
131008
131291
|
}),
|
|
131009
131292
|
seal: createSandboxClosure({
|
|
@@ -131011,14 +131294,14 @@ function createObjectArrayGlobals(options) {
|
|
|
131011
131294
|
call: ([value]) => {
|
|
131012
131295
|
if (isGuestHostObject(value))
|
|
131013
131296
|
throw new TypeError("Live host objects cannot be sealed.");
|
|
131014
|
-
Object.seal(isGuestClosure(value) ? materializeFunctionProperties(value) : value);
|
|
131297
|
+
Object.seal(isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : value);
|
|
131015
131298
|
return value;
|
|
131016
131299
|
},
|
|
131017
131300
|
name: "seal"
|
|
131018
131301
|
}),
|
|
131019
131302
|
isSealed: createSandboxClosure({
|
|
131020
131303
|
sandbox: true,
|
|
131021
|
-
call: ([value]) => Object.isSealed(isGuestClosure(value) ? materializeFunctionProperties(value) : value),
|
|
131304
|
+
call: ([value]) => Object.isSealed(isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : value),
|
|
131022
131305
|
name: "isSealed"
|
|
131023
131306
|
}),
|
|
131024
131307
|
freeze: createSandboxClosure({
|
|
@@ -131027,7 +131310,7 @@ function createObjectArrayGlobals(options) {
|
|
|
131027
131310
|
if (isGuestHostObject(value))
|
|
131028
131311
|
throw new TypeError("Live host objects cannot be frozen.");
|
|
131029
131312
|
if (typeof value === "object" && value !== null) {
|
|
131030
|
-
Object.freeze(isGuestClosure(value) ? materializeFunctionProperties(value) : value);
|
|
131313
|
+
Object.freeze(isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : value);
|
|
131031
131314
|
}
|
|
131032
131315
|
return value;
|
|
131033
131316
|
},
|
|
@@ -131035,7 +131318,7 @@ function createObjectArrayGlobals(options) {
|
|
|
131035
131318
|
}),
|
|
131036
131319
|
isFrozen: createSandboxClosure({
|
|
131037
131320
|
sandbox: true,
|
|
131038
|
-
call: ([value]) => Object.isFrozen(isGuestClosure(value) ? materializeFunctionProperties(value) : value),
|
|
131321
|
+
call: ([value]) => Object.isFrozen(isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : value),
|
|
131039
131322
|
name: "isFrozen"
|
|
131040
131323
|
}),
|
|
131041
131324
|
assign: createSandboxClosure({
|
|
@@ -131239,6 +131522,7 @@ function assignSandboxValues(target, sources, budget, context) {
|
|
|
131239
131522
|
})();
|
|
131240
131523
|
}
|
|
131241
131524
|
function objectProperties(value, mutable = false) {
|
|
131525
|
+
if (isSandboxRegex(value)) return getRegexProperties(value);
|
|
131242
131526
|
if (isSandboxDate(value)) {
|
|
131243
131527
|
return value;
|
|
131244
131528
|
}
|
|
@@ -135596,7 +135880,7 @@ async function evaluateDeleteExpression(node, context) {
|
|
|
135596
135880
|
}
|
|
135597
135881
|
throw new TypeError("Cannot delete properties of null or undefined.");
|
|
135598
135882
|
}
|
|
135599
|
-
if (!isIndexableSandboxValue(member.object)) {
|
|
135883
|
+
if (!isIndexableSandboxValue(member.object) && !isSandboxRegex(member.object)) {
|
|
135600
135884
|
throw new TypeError("Unary operator 'delete' requires a sandbox object property.");
|
|
135601
135885
|
}
|
|
135602
135886
|
const property = await toPropertyKey(member.property, context.budget, createCoercionContext(context));
|
|
@@ -135999,10 +136283,10 @@ async function evaluateMemberCallExpression(node, context) {
|
|
|
135999
136283
|
member.object
|
|
136000
136284
|
);
|
|
136001
136285
|
}
|
|
136002
|
-
if (isSandboxRegex(member.object)
|
|
136286
|
+
if (isSandboxRegex(member.object)) {
|
|
136003
136287
|
return evaluateResolvedCallExpression(
|
|
136004
136288
|
node,
|
|
136005
|
-
|
|
136289
|
+
await getPropertyValue(member.object, member.property, context),
|
|
136006
136290
|
context,
|
|
136007
136291
|
member.object
|
|
136008
136292
|
);
|
|
@@ -136503,7 +136787,6 @@ function setSandboxProperty(target, property, value, budget, checkInherited = tr
|
|
|
136503
136787
|
return;
|
|
136504
136788
|
}
|
|
136505
136789
|
if (isSandboxRegex(target)) {
|
|
136506
|
-
if (typeof property === "symbol") throw new TypeError("RegExp symbol properties are not yet supported.");
|
|
136507
136790
|
setRegexMember(target, property, value);
|
|
136508
136791
|
return;
|
|
136509
136792
|
}
|
|
@@ -136565,6 +136848,7 @@ function setSuperProperty(base, receiver, key3, value, context) {
|
|
|
136565
136848
|
function deleteSandboxProperty(target, property) {
|
|
136566
136849
|
if (isGuestHostObject(target)) return deleteHostObjectMember(target, String(property));
|
|
136567
136850
|
if (isGuestClosure(target)) target = materializeFunctionProperties(target);
|
|
136851
|
+
if (isSandboxRegex(target)) target = getRegexProperties(target);
|
|
136568
136852
|
if (Array.isArray(target)) {
|
|
136569
136853
|
assertCollectionMutable(target);
|
|
136570
136854
|
}
|
|
@@ -138735,7 +139019,7 @@ function hasOwnSandboxProperty(value, key3, enumerable) {
|
|
|
138735
139019
|
properties = value.properties ?? /* @__PURE__ */ Object.create(null);
|
|
138736
139020
|
} else if (isSandboxMap(value) || isSandboxSet(value) || isSandboxPromise(value) || isSandboxGenerator(value))
|
|
138737
139021
|
return false;
|
|
138738
|
-
else if (isSandboxRegex(value))
|
|
139022
|
+
else if (isSandboxRegex(value)) properties = getRegexProperties(value);
|
|
138739
139023
|
else properties = Object(value);
|
|
138740
139024
|
const descriptor = Object.getOwnPropertyDescriptor(properties, key3);
|
|
138741
139025
|
return descriptor !== void 0 && (!enumerable || descriptor.enumerable === true);
|
|
@@ -140338,6 +140622,7 @@ function ownEnumerableSandboxEntries(value, excludedKeys) {
|
|
|
140338
140622
|
if (value === null || value === void 0) throw new TypeError("Cannot convert undefined or null to object.");
|
|
140339
140623
|
let entries;
|
|
140340
140624
|
if (isGuestClosure(value)) entries = Object.entries(value.properties ?? {});
|
|
140625
|
+
else if (isSandboxRegex(value)) entries = Object.entries(getRegexProperties(value));
|
|
140341
140626
|
else if (isSandboxClosure(value) || isSandboxGenerator(value) || isSandboxMap(value) || isSandboxSet(value) || isSandboxPromise(value) || isSandboxRegex(value)) return [];
|
|
140342
140627
|
else entries = Object.entries(Object(value));
|
|
140343
140628
|
return excludedKeys === void 0 ? entries : entries.filter(([key3]) => !excludedKeys.has(key3));
|
|
@@ -140346,17 +140631,19 @@ function ownSandboxSymbolKeys(value) {
|
|
|
140346
140631
|
if (value === null || value === void 0) throw new TypeError("Cannot convert undefined or null to object.");
|
|
140347
140632
|
if (isGuestHostObject(value)) return [];
|
|
140348
140633
|
if (isSandboxClosure(value)) value = value.properties ?? {};
|
|
140634
|
+
else if (isSandboxRegex(value)) value = getRegexProperties(value);
|
|
140349
140635
|
else if (isSandboxGenerator(value) || isSandboxMap(value) || isSandboxSet(value) || isSandboxPromise(value) || isSandboxRegex(value)) return [];
|
|
140350
140636
|
return Object.getOwnPropertySymbols(Object(value)).filter((key3) => !internalSymbols.has(key3));
|
|
140351
140637
|
}
|
|
140352
140638
|
function ownEnumerableSandboxKeys(value, includeSymbols = false) {
|
|
140353
140639
|
if (includeSymbols) {
|
|
140354
|
-
const properties = isSandboxClosure(value) ? value.properties ?? {} : Object(value);
|
|
140640
|
+
const properties = isSandboxClosure(value) ? value.properties ?? {} : isSandboxRegex(value) ? getRegexProperties(value) : Object(value);
|
|
140355
140641
|
return [...ownEnumerableSandboxKeys(value), ...ownSandboxSymbolKeys(value).filter((key3) => Object.getOwnPropertyDescriptor(properties, key3)?.enumerable === true)];
|
|
140356
140642
|
}
|
|
140357
140643
|
if (isGuestHostObject(value)) return getHostObjectKeys(value);
|
|
140358
140644
|
if (value === null || value === void 0) throw new TypeError("Cannot convert undefined or null to object.");
|
|
140359
140645
|
if (isGuestClosure(value)) return Object.keys(value.properties ?? {});
|
|
140646
|
+
if (isSandboxRegex(value)) return Object.keys(getRegexProperties(value));
|
|
140360
140647
|
if (isSandboxClosure(value) || isSandboxGenerator(value) || isSandboxMap(value) || isSandboxSet(value) || isSandboxPromise(value) || isSandboxRegex(value)) return [];
|
|
140361
140648
|
return Object.keys(Object(value));
|
|
140362
140649
|
}
|
|
@@ -140448,6 +140735,28 @@ function createSandboxRegex(source, flags = "", lastIndex = 0, compilation) {
|
|
|
140448
140735
|
}
|
|
140449
140736
|
const pattern = parseRegex(source, flags, compilation, 7 + source.length + flags.length);
|
|
140450
140737
|
const regex = { kind: "regex", source, flags, lastIndex };
|
|
140738
|
+
const storage2 = /* @__PURE__ */ Object.create(null);
|
|
140739
|
+
Object.defineProperty(storage2, "lastIndex", { value: lastIndex, writable: true });
|
|
140740
|
+
const syncCursor = () => {
|
|
140741
|
+
const descriptor = Object.getOwnPropertyDescriptor(regex, "lastIndex");
|
|
140742
|
+
Object.defineProperty(storage2, "lastIndex", { value: descriptor.value, writable: descriptor.writable });
|
|
140743
|
+
};
|
|
140744
|
+
const properties = new Proxy(storage2, {
|
|
140745
|
+
get: (target, key3, receiver) => key3 === "lastIndex" ? regex.lastIndex : Reflect.get(target, key3, receiver),
|
|
140746
|
+
set: (target, key3, value, receiver) => key3 === "lastIndex" ? Reflect.set(regex, key3, value) : Reflect.set(target, key3, value, receiver),
|
|
140747
|
+
getOwnPropertyDescriptor(target, key3) {
|
|
140748
|
+
if (key3 === "lastIndex") syncCursor();
|
|
140749
|
+
return Object.getOwnPropertyDescriptor(target, key3);
|
|
140750
|
+
},
|
|
140751
|
+
defineProperty(target, key3, descriptor) {
|
|
140752
|
+
if (key3 !== "lastIndex") return Reflect.defineProperty(target, key3, descriptor);
|
|
140753
|
+
syncCursor();
|
|
140754
|
+
if (!Reflect.defineProperty(target, key3, descriptor)) return false;
|
|
140755
|
+
const cursor2 = Object.getOwnPropertyDescriptor(target, key3);
|
|
140756
|
+
return Reflect.defineProperty(regex, key3, { value: cursor2.value, writable: cursor2.writable });
|
|
140757
|
+
}
|
|
140758
|
+
});
|
|
140759
|
+
regexGuestProperties.set(regex, properties);
|
|
140451
140760
|
Object.defineProperties(regex, {
|
|
140452
140761
|
[sandboxRegexBrand]: { value: true },
|
|
140453
140762
|
[sandboxRegexPattern]: { value: pattern }
|
|
@@ -140623,6 +140932,14 @@ function measureSandboxData(values, options = {}) {
|
|
|
140623
140932
|
usage += Math.max(6 + source.length + flags.length + compiled.units, staged - 1);
|
|
140624
140933
|
if (compiled.ticket !== void 0) options.compileTickets?.add(compiled.ticket);
|
|
140625
140934
|
visit(lastIndex, depth + 1);
|
|
140935
|
+
for (const key3 of Reflect.ownKeys(getRegexProperties(value))) {
|
|
140936
|
+
if (key3 === "lastIndex") continue;
|
|
140937
|
+
const descriptor = Object.getOwnPropertyDescriptor(getRegexProperties(value), key3);
|
|
140938
|
+
usage += 1 + (typeof key3 === "string" ? key3.length : 0);
|
|
140939
|
+
if (typeof key3 === "symbol") visit(key3, depth + 1);
|
|
140940
|
+
if ("value" in descriptor) visit(descriptor.value, depth + 1);
|
|
140941
|
+
else for (const closure of retainedAccessorClosures(descriptor)) visit(closure, depth + 1);
|
|
140942
|
+
}
|
|
140626
140943
|
return;
|
|
140627
140944
|
}
|
|
140628
140945
|
if (isSandboxArguments(value)) {
|
|
@@ -140683,7 +141000,7 @@ function captureRegexData(value) {
|
|
|
140683
141000
|
"Invalid sandbox RegExp source or flags: expected own string data properties."
|
|
140684
141001
|
);
|
|
140685
141002
|
}
|
|
140686
|
-
const cursor2 = Object.getOwnPropertyDescriptor(value, "lastIndex");
|
|
141003
|
+
const cursor2 = Object.getOwnPropertyDescriptor(regexGuestProperties.get(value) ?? value, "lastIndex");
|
|
140687
141004
|
if (cursor2 === void 0 || !("value" in cursor2)) {
|
|
140688
141005
|
throw new TypeError("Invalid sandbox RegExp lastIndex: expected an own data property.");
|
|
140689
141006
|
}
|
|
@@ -140712,6 +141029,18 @@ function copyToSandbox(value, state, path193 = "<root>", cloneSandboxCollections
|
|
|
140712
141029
|
const copy = createSandboxRegex(value.source, value.flags, 0, state.compilation);
|
|
140713
141030
|
state.seen.set(value, copy);
|
|
140714
141031
|
if (!state.resetRegexLastIndex) copy.lastIndex = copyToSandbox(value.lastIndex, state, `${path193}.lastIndex`, true, depth + 1);
|
|
141032
|
+
if (!state.structuredClone) {
|
|
141033
|
+
const properties = getRegexProperties(value);
|
|
141034
|
+
for (const key3 of Reflect.ownKeys(properties)) {
|
|
141035
|
+
const descriptor = Object.getOwnPropertyDescriptor(properties, key3);
|
|
141036
|
+
if (!("value" in descriptor)) throw new TypeError("RegExp accessor properties cannot be copied as data.");
|
|
141037
|
+
Object.defineProperty(getRegexProperties(copy), key3, {
|
|
141038
|
+
...descriptor,
|
|
141039
|
+
value: key3 === "lastIndex" && state.resetRegexLastIndex ? 0 : copyToSandbox(descriptor.value, state, `${path193}.${String(key3)}`, true, depth + 1)
|
|
141040
|
+
});
|
|
141041
|
+
}
|
|
141042
|
+
if (!Object.isExtensible(properties)) Object.preventExtensions(getRegexProperties(copy));
|
|
141043
|
+
}
|
|
140715
141044
|
return copy;
|
|
140716
141045
|
}
|
|
140717
141046
|
if (isSandboxClosure(value) || isSandboxGenerator(value) || isSandboxPromise(value)) {
|
|
@@ -140960,6 +141289,18 @@ function copyFromSandbox(value, state, path193 = "<root>", options, depth = 0) {
|
|
|
140960
141289
|
const regex = new RegExp(source, flags);
|
|
140961
141290
|
state.seen.set(value, regex);
|
|
140962
141291
|
Reflect.set(regex, "lastIndex", copyFromSandbox(lastIndex, state, `${path193}.lastIndex`, options, depth + 1));
|
|
141292
|
+
const properties = regexGuestProperties.get(value);
|
|
141293
|
+
if (properties !== void 0) {
|
|
141294
|
+
for (const key3 of Reflect.ownKeys(properties)) {
|
|
141295
|
+
const descriptor = Object.getOwnPropertyDescriptor(properties, key3);
|
|
141296
|
+
if (!("value" in descriptor)) throw new TypeError("RegExp accessor properties cannot be copied as data.");
|
|
141297
|
+
Object.defineProperty(regex, key3, {
|
|
141298
|
+
...descriptor,
|
|
141299
|
+
value: copyFromSandbox(descriptor.value, state, `${path193}.${String(key3)}`, options, depth + 1)
|
|
141300
|
+
});
|
|
141301
|
+
}
|
|
141302
|
+
if (!Object.isExtensible(properties)) Object.preventExtensions(regex);
|
|
141303
|
+
}
|
|
140963
141304
|
guard.retainScratch();
|
|
140964
141305
|
return regex;
|
|
140965
141306
|
} finally {
|
|
@@ -141279,6 +141620,8 @@ var init_values = __esm({
|
|
|
141279
141620
|
"use strict";
|
|
141280
141621
|
init_otel2();
|
|
141281
141622
|
init_internal_symbols();
|
|
141623
|
+
init_regexp_properties();
|
|
141624
|
+
init_regexp_properties();
|
|
141282
141625
|
init_accessors();
|
|
141283
141626
|
init_collection_brands();
|
|
141284
141627
|
init_collection_iterator();
|
|
@@ -141308,225 +141651,65 @@ var init_values = __esm({
|
|
|
141308
141651
|
}
|
|
141309
141652
|
});
|
|
141310
141653
|
|
|
141311
|
-
// packages/safe-js/src/
|
|
141312
|
-
function
|
|
141313
|
-
|
|
141654
|
+
// packages/safe-js/src/snapshot/regexp-properties.ts
|
|
141655
|
+
function hasCustomRegexProperties(value) {
|
|
141656
|
+
const properties = getRegexProperties(value);
|
|
141657
|
+
return Reflect.ownKeys(properties).length !== 1 || !Object.isExtensible(properties) || Object.getOwnPropertyDescriptor(properties, "lastIndex")?.writable !== true;
|
|
141314
141658
|
}
|
|
141315
|
-
function
|
|
141316
|
-
|
|
141317
|
-
|
|
141318
|
-
function getGuestFunctionProperties(closure) {
|
|
141319
|
-
return functionProperties.get(closure);
|
|
141320
|
-
}
|
|
141321
|
-
function materializeFunctionProperties(closure) {
|
|
141322
|
-
if (!isGuestClosure(closure)) throw new TypeError("Host function properties are read only.");
|
|
141323
|
-
const existing = functionProperties.get(closure);
|
|
141324
|
-
if (existing !== void 0) return existing;
|
|
141659
|
+
function serializeRegexProperties(value, encode) {
|
|
141660
|
+
if (!hasCustomRegexProperties(value)) return {};
|
|
141661
|
+
const source = getRegexProperties(value);
|
|
141325
141662
|
const properties = /* @__PURE__ */ Object.create(null);
|
|
141326
|
-
Object.
|
|
141327
|
-
|
|
141328
|
-
|
|
141329
|
-
|
|
141330
|
-
|
|
141331
|
-
|
|
141332
|
-
|
|
141333
|
-
|
|
141334
|
-
|
|
141335
|
-
configurable: true
|
|
141336
|
-
});
|
|
141337
|
-
descriptorObjects.add(prototype);
|
|
141338
|
-
Object.defineProperty(properties, "prototype", { value: prototype, writable: true });
|
|
141339
|
-
}
|
|
141340
|
-
descriptorObjects.add(properties);
|
|
141341
|
-
functionProperties.set(closure, properties);
|
|
141342
|
-
return properties;
|
|
141343
|
-
}
|
|
141344
|
-
function getGuestFunctionProperty(closure, key3) {
|
|
141345
|
-
let properties = functionProperties.get(closure);
|
|
141346
|
-
if (properties === void 0) {
|
|
141347
|
-
if (key3 === "length") return closure.length ?? 0;
|
|
141348
|
-
if (key3 === "name") return closure.name ?? "";
|
|
141349
|
-
if (key3 === "prototype" && closure.construct !== void 0 && closure.boundTarget === void 0) {
|
|
141350
|
-
properties = materializeFunctionProperties(closure);
|
|
141351
|
-
}
|
|
141352
|
-
}
|
|
141353
|
-
return properties === void 0 ? void 0 : Object.getOwnPropertyDescriptor(properties, key3)?.value;
|
|
141354
|
-
}
|
|
141355
|
-
function installObjectPrototype(budget, prototype, constructor) {
|
|
141356
|
-
prototypes.set(prototype, null);
|
|
141357
|
-
intrinsicPrototypes.set(budget, prototype);
|
|
141358
|
-
registerIntrinsicPrototype(budget, prototype, constructor);
|
|
141359
|
-
}
|
|
141360
|
-
function installBoxedPrototype(budget, prototype, constructor, kind = typeof boxedValue(prototype)) {
|
|
141361
|
-
let state = boxedPrototypes.get(budget);
|
|
141362
|
-
if (state === void 0) boxedPrototypes.set(budget, state = /* @__PURE__ */ new Map());
|
|
141363
|
-
state.set(kind, prototype);
|
|
141364
|
-
initialBoxedMethods.set(prototype, new Map(Object.entries(Object.getOwnPropertyDescriptors(prototype)).map(([key3, descriptor]) => [key3, descriptor.value])));
|
|
141365
|
-
registerIntrinsicPrototype(budget, prototype, constructor);
|
|
141366
|
-
}
|
|
141367
|
-
function getBoxedPrototype(value, budget) {
|
|
141368
|
-
return boxedPrototypes.get(budget)?.get(typeof value);
|
|
141369
|
-
}
|
|
141370
|
-
function isDefaultBoxedMethod(value, key3, budget) {
|
|
141371
|
-
const prototype = getBoxedPrototype(value, budget);
|
|
141372
|
-
return prototype !== void 0 && initialBoxedMethods.get(prototype)?.has(key3) === true && Object.getOwnPropertyDescriptor(prototype, key3)?.value === initialBoxedMethods.get(prototype)?.get(key3);
|
|
141373
|
-
}
|
|
141374
|
-
function isIntrinsicConstructor(value) {
|
|
141375
|
-
return intrinsicConstructors.has(value);
|
|
141376
|
-
}
|
|
141377
|
-
function registerIntrinsicPrototype(budget, prototype, constructor) {
|
|
141378
|
-
let roots = intrinsicPrototypeRoots.get(budget);
|
|
141379
|
-
if (roots === void 0) intrinsicPrototypeRoots.set(budget, roots = /* @__PURE__ */ new Set());
|
|
141380
|
-
roots.add(prototype);
|
|
141381
|
-
const records = [prototype, constructor].map((target) => ({
|
|
141382
|
-
target,
|
|
141383
|
-
value: isGuestClosure(target) ? materializeFunctionProperties(target) : target,
|
|
141384
|
-
prototype: getSandboxPrototype(target),
|
|
141385
|
-
explicit: hasExplicitSandboxPrototype(target)
|
|
141386
|
-
})).map((record2) => ({
|
|
141387
|
-
...record2,
|
|
141388
|
-
descriptors: new Map(Object.entries(Object.getOwnPropertyDescriptors(record2.value)))
|
|
141389
|
-
}));
|
|
141390
|
-
const unchanged = (before, after) => before !== void 0 && after !== void 0 && Object.is(before.value, after.value) && before.get === after.get && before.set === after.set && before.writable === after.writable && before.configurable === after.configurable && before.enumerable === after.enumerable;
|
|
141391
|
-
intrinsicConstructors.set(
|
|
141392
|
-
constructor,
|
|
141393
|
-
() => records.every(({ target, value, descriptors, prototype: parent, explicit }) => {
|
|
141394
|
-
const current = Object.getOwnPropertyDescriptors(value);
|
|
141395
|
-
return getSandboxPrototype(target) === parent && hasExplicitSandboxPrototype(target) === explicit && Object.keys(current).length === descriptors.size && Object.keys(current).every((key3) => unchanged(descriptors.get(key3), current[key3]));
|
|
141396
|
-
})
|
|
141397
|
-
);
|
|
141398
|
-
budget.setRetainedValues(
|
|
141399
|
-
prototype,
|
|
141400
|
-
() => records.flatMap(({ target, value, descriptors, prototype: parent }) => [
|
|
141401
|
-
...getSandboxPrototype(target) === parent ? [] : [getSandboxPrototype(target)],
|
|
141402
|
-
...Object.entries(Object.getOwnPropertyDescriptors(value)).flatMap(
|
|
141403
|
-
([key3, descriptor]) => unchanged(descriptors.get(key3), descriptor) ? [] : [key3, descriptor.value, ...retainedAccessorClosures(descriptor)]
|
|
141404
|
-
)
|
|
141405
|
-
])
|
|
141406
|
-
);
|
|
141407
|
-
}
|
|
141408
|
-
function releaseObjectPrototype(budget) {
|
|
141409
|
-
for (const prototype of intrinsicPrototypeRoots.get(budget) ?? []) budget.setRetainedValues(prototype, void 0);
|
|
141410
|
-
intrinsicPrototypeRoots.delete(budget);
|
|
141411
|
-
boxedPrototypes.delete(budget);
|
|
141412
|
-
intrinsicPrototypes.delete(budget);
|
|
141413
|
-
}
|
|
141414
|
-
function getSandboxPrototype(value, budget) {
|
|
141415
|
-
if (prototypes.has(value)) return prototypes.get(value) ?? null;
|
|
141416
|
-
if (budget !== void 0 && isSandboxBox(value)) {
|
|
141417
|
-
const prototype = getBoxedPrototype(boxedValue(value), budget);
|
|
141418
|
-
if (prototype !== void 0 && prototype !== value) return prototype;
|
|
141663
|
+
for (const key3 of Object.getOwnPropertyNames(source)) {
|
|
141664
|
+
const descriptor = Object.getOwnPropertyDescriptor(source, key3);
|
|
141665
|
+
if (!("value" in descriptor)) throw new TypeError("RegExp accessor properties cannot be serialized as data.");
|
|
141666
|
+
properties[key3] = {
|
|
141667
|
+
value: encode(descriptor.value),
|
|
141668
|
+
enumerable: descriptor.enumerable === true,
|
|
141669
|
+
configurable: descriptor.configurable === true,
|
|
141670
|
+
writable: descriptor.writable === true
|
|
141671
|
+
};
|
|
141419
141672
|
}
|
|
141420
|
-
|
|
141421
|
-
|
|
141422
|
-
|
|
141423
|
-
|
|
141673
|
+
const symbolEntries = serializeSymbolProperties(source, encode);
|
|
141674
|
+
return {
|
|
141675
|
+
properties,
|
|
141676
|
+
...symbolEntries.length === 0 ? {} : { symbolEntries },
|
|
141677
|
+
...Object.isExtensible(source) ? {} : { extensible: false }
|
|
141678
|
+
};
|
|
141424
141679
|
}
|
|
141425
|
-
function
|
|
141426
|
-
const
|
|
141427
|
-
|
|
141428
|
-
|
|
141429
|
-
|
|
141430
|
-
|
|
141431
|
-
|
|
141432
|
-
|
|
141433
|
-
|
|
141434
|
-
|
|
141435
|
-
|
|
141436
|
-
if (current !== null) {
|
|
141437
|
-
budget?.visitNode();
|
|
141438
|
-
assertSandboxDataDepth(++depth);
|
|
141439
|
-
}
|
|
141680
|
+
function validateRegexProperties(data) {
|
|
141681
|
+
const descriptor = (value) => {
|
|
141682
|
+
if (typeof value !== "object" || value === null || Array.isArray(value) || !Object.hasOwn(value, "value") || !["enumerable", "configurable", "writable"].every((key3) => Object.hasOwn(value, key3) && typeof value[key3] === "boolean") || Object.keys(value).some((key3) => !["value", "enumerable", "configurable", "writable"].includes(key3)))
|
|
141683
|
+
throw new TypeError("Invalid RegExp data property descriptor.");
|
|
141684
|
+
};
|
|
141685
|
+
if (data.extensible !== void 0 && typeof data.extensible !== "boolean")
|
|
141686
|
+
throw new TypeError("Invalid RegExp extensibility.");
|
|
141687
|
+
if (data.properties !== void 0) {
|
|
141688
|
+
if (typeof data.properties !== "object" || data.properties === null || Array.isArray(data.properties))
|
|
141689
|
+
throw new TypeError("Invalid RegExp property data.");
|
|
141690
|
+
for (const entry of Object.values(data.properties)) descriptor(entry);
|
|
141440
141691
|
}
|
|
141441
|
-
|
|
141442
|
-
|
|
141443
|
-
|
|
141444
|
-
|
|
141445
|
-
|
|
141446
|
-
while (typeof current === "object" && current !== null) {
|
|
141447
|
-
if (isGuestHostObject(current)) return typeof key3 === "symbol" ? void 0 : getHostObjectMember(current, String(key3));
|
|
141448
|
-
if (isGuestClosure(current)) {
|
|
141449
|
-
const entry = getGuestFunctionProperty(current, key3);
|
|
141450
|
-
if (entry !== void 0 || Object.hasOwn(current.properties ?? {}, key3)) return entry;
|
|
141451
|
-
} else if (isSandboxClosure(current)) {
|
|
141452
|
-
const properties = current.properties;
|
|
141453
|
-
return properties !== void 0 && Object.hasOwn(properties, key3) ? properties[key3] : void 0;
|
|
141454
|
-
}
|
|
141455
|
-
if (isSandboxMap(current) || isSandboxSet(current) || isSandboxPromise(current) || isSandboxRegex(current) || isSandboxGenerator(current))
|
|
141456
|
-
return void 0;
|
|
141457
|
-
if (!isSandboxClosure(current) && Object.hasOwn(current, key3)) return current[key3];
|
|
141458
|
-
current = getSandboxPrototype(current, budget);
|
|
141459
|
-
if (current !== null) {
|
|
141460
|
-
budget?.visitNode();
|
|
141461
|
-
assertSandboxDataDepth(++depth);
|
|
141692
|
+
if (data.symbolEntries !== void 0) {
|
|
141693
|
+
if (!Array.isArray(data.symbolEntries)) throw new TypeError("Invalid RegExp symbol properties.");
|
|
141694
|
+
for (const entry of data.symbolEntries) {
|
|
141695
|
+
if (!Array.isArray(entry) || entry.length !== 2) throw new TypeError("Invalid RegExp symbol property.");
|
|
141696
|
+
descriptor(entry[1]);
|
|
141462
141697
|
}
|
|
141463
141698
|
}
|
|
141464
|
-
return void 0;
|
|
141465
|
-
}
|
|
141466
|
-
function setSandboxPrototype(value, prototype, budget) {
|
|
141467
|
-
if (budget !== void 0 && intrinsicPrototypes.get(budget) === value && prototype !== null) {
|
|
141468
|
-
throw new TypeError("Object.prototype has an immutable null prototype.");
|
|
141469
|
-
}
|
|
141470
|
-
if (!Array.isArray(value) && !isPrototypeRecord(value) || prototype !== null && !Array.isArray(prototype) && !isPrototypeRecord(prototype)) {
|
|
141471
|
-
throw new TypeError(
|
|
141472
|
-
"Prototype links require ordinary sandbox objects, arrays, or guest functions."
|
|
141473
|
-
);
|
|
141474
|
-
}
|
|
141475
|
-
if (prototypes.has(value) && getSandboxPrototype(value, budget) === prototype) return;
|
|
141476
|
-
if (!Object.isExtensible(isGuestClosure(value) ? materializeFunctionProperties(value) : value)) {
|
|
141477
|
-
throw new TypeError("Cannot change the prototype of a non-extensible object.");
|
|
141478
|
-
}
|
|
141479
|
-
let depth = 0;
|
|
141480
|
-
for (let current = prototype; current !== null; current = getSandboxPrototype(current, budget)) {
|
|
141481
|
-
budget?.visitNode();
|
|
141482
|
-
assertSandboxDataDepth(depth++);
|
|
141483
|
-
if (current === value) throw new TypeError("Cyclic prototype value.");
|
|
141484
|
-
}
|
|
141485
|
-
prototypes.set(value, prototype);
|
|
141486
141699
|
}
|
|
141487
|
-
function
|
|
141488
|
-
|
|
141489
|
-
|
|
141490
|
-
|
|
141491
|
-
|
|
141492
|
-
|
|
141493
|
-
|
|
141494
|
-
}
|
|
141495
|
-
function markDescriptorObject(value) {
|
|
141496
|
-
descriptorObjects.add(value);
|
|
141700
|
+
function restoreRegexProperties(value, data, decode) {
|
|
141701
|
+
validateRegexProperties(data);
|
|
141702
|
+
const properties = getRegexProperties(value);
|
|
141703
|
+
for (const [key3, descriptor] of Object.entries(data.properties ?? {}))
|
|
141704
|
+
Object.defineProperty(properties, key3, { ...descriptor, value: decode(descriptor.value) });
|
|
141705
|
+
restoreSymbolProperties(properties, data.symbolEntries, decode);
|
|
141706
|
+
if (data.extensible === false) Object.preventExtensions(properties);
|
|
141497
141707
|
}
|
|
141498
|
-
|
|
141499
|
-
|
|
141500
|
-
}
|
|
141501
|
-
function hasGuestObjectState(value) {
|
|
141502
|
-
const intrinsicUnchanged = intrinsicConstructors.get(value);
|
|
141503
|
-
if (intrinsicUnchanged !== void 0) return !intrinsicUnchanged();
|
|
141504
|
-
if (isLiveCapability(value)) return true;
|
|
141505
|
-
if (functionProperties.has(value) || prototypes.has(value)) return true;
|
|
141506
|
-
if (isSandboxBox(value) || isSandboxDate(value)) return false;
|
|
141507
|
-
return descriptorObjects.has(value) && Object.values(Object.getOwnPropertyDescriptors(value)).some(
|
|
141508
|
-
(descriptor) => !descriptor.enumerable || !descriptor.configurable || !descriptor.writable
|
|
141509
|
-
);
|
|
141510
|
-
}
|
|
141511
|
-
var guestClosures, functionProperties, prototypes, intrinsicPrototypes, boxedPrototypes, intrinsicPrototypeRoots, intrinsicConstructors, initialBoxedMethods, descriptorObjects;
|
|
141512
|
-
var init_object_model = __esm({
|
|
141513
|
-
"packages/safe-js/src/interp/object-model.ts"() {
|
|
141708
|
+
var init_regexp_properties2 = __esm({
|
|
141709
|
+
"packages/safe-js/src/snapshot/regexp-properties.ts"() {
|
|
141514
141710
|
"use strict";
|
|
141515
|
-
init_graph_depth();
|
|
141516
|
-
init_date();
|
|
141517
|
-
init_accessors();
|
|
141518
|
-
init_host_capabilities();
|
|
141519
|
-
init_boxed();
|
|
141520
141711
|
init_values();
|
|
141521
|
-
|
|
141522
|
-
functionProperties = /* @__PURE__ */ new WeakMap();
|
|
141523
|
-
prototypes = /* @__PURE__ */ new WeakMap();
|
|
141524
|
-
intrinsicPrototypes = /* @__PURE__ */ new WeakMap();
|
|
141525
|
-
boxedPrototypes = /* @__PURE__ */ new WeakMap();
|
|
141526
|
-
intrinsicPrototypeRoots = /* @__PURE__ */ new WeakMap();
|
|
141527
|
-
intrinsicConstructors = /* @__PURE__ */ new WeakMap();
|
|
141528
|
-
initialBoxedMethods = /* @__PURE__ */ new WeakMap();
|
|
141529
|
-
descriptorObjects = /* @__PURE__ */ new WeakSet();
|
|
141712
|
+
init_symbols3();
|
|
141530
141713
|
}
|
|
141531
141714
|
});
|
|
141532
141715
|
|
|
@@ -141647,7 +141830,7 @@ function serializeDumpValue(value, path193, state) {
|
|
|
141647
141830
|
if (hasGuestObjectState(value)) {
|
|
141648
141831
|
throw new TypeError("Guest function properties and prototype links cannot be serialized.");
|
|
141649
141832
|
}
|
|
141650
|
-
if (isSandboxBox(value) || isSandboxDate(value) || isFloat32Array(value)) return serializeHeapReference(value, path193, state);
|
|
141833
|
+
if (isSandboxRegex(value) && hasCustomRegexProperties(value) || isSandboxBox(value) || isSandboxDate(value) || isFloat32Array(value)) return serializeHeapReference(value, path193, state);
|
|
141651
141834
|
if (Array.isArray(value)) {
|
|
141652
141835
|
const reference2 = serializeHeapReference(value, path193, state);
|
|
141653
141836
|
if (reference2 !== void 0) {
|
|
@@ -141671,7 +141854,20 @@ function serializeHeapReference(value, path193, state) {
|
|
|
141671
141854
|
}
|
|
141672
141855
|
if (!state.serializedHeapIds.has(id)) {
|
|
141673
141856
|
state.serializedHeapIds.add(id);
|
|
141674
|
-
if (
|
|
141857
|
+
if (isSandboxRegex(value) && hasCustomRegexProperties(value)) {
|
|
141858
|
+
const encode = (entry) => {
|
|
141859
|
+
const serialized = serializeDumpValue(entry, `${path193}.<regex-property>`, state);
|
|
141860
|
+
if (serialized === SKIP_VALUE) throw new TypeError("Unsupported RegExp property in public dump.");
|
|
141861
|
+
return serialized;
|
|
141862
|
+
};
|
|
141863
|
+
state.heap[String(id)] = {
|
|
141864
|
+
kind: "regex-object",
|
|
141865
|
+
source: value.source,
|
|
141866
|
+
flags: value.flags,
|
|
141867
|
+
lastIndex: encode(value.lastIndex),
|
|
141868
|
+
...serializeRegexProperties(value, encode)
|
|
141869
|
+
};
|
|
141870
|
+
} else if (isSandboxBox(value)) {
|
|
141675
141871
|
state.heap[String(id)] = encodeBoxedData(value, (entry, key3) => {
|
|
141676
141872
|
if (Object.is(entry, -0)) return { kind: "number", value: "-0" };
|
|
141677
141873
|
const serialized = serializeDumpValue(entry, `${path193}.${key3}`, state);
|
|
@@ -141750,7 +141946,7 @@ function indexHeapContainers(snapshot2) {
|
|
|
141750
141946
|
const heapIds = /* @__PURE__ */ new Map();
|
|
141751
141947
|
let nextId = 1;
|
|
141752
141948
|
for (const [value, stat35] of stats2.entries()) {
|
|
141753
|
-
if (stat35.count > 1 || stat35.cyclic || ownSerializableSymbolKeys(value).length > 0 || isSandboxBox(value) || isSandboxDate(value) || isFloat32Array(value) || Array.isArray(value) && requiresArrayEntries(value) || isSandboxArguments(value) || sandboxErrorTypes.has(value)) {
|
|
141949
|
+
if (stat35.count > 1 || stat35.cyclic || ownSerializableSymbolKeys(value).length > 0 || isSandboxBox(value) || isSandboxRegex(value) && hasCustomRegexProperties(value) || isSandboxDate(value) || isFloat32Array(value) || Array.isArray(value) && requiresArrayEntries(value) || isSandboxArguments(value) || sandboxErrorTypes.has(value)) {
|
|
141754
141950
|
heapIds.set(value, nextId);
|
|
141755
141951
|
nextId += 1;
|
|
141756
141952
|
}
|
|
@@ -141783,7 +141979,10 @@ function collectContainerStats(value, stats2, ancestors) {
|
|
|
141783
141979
|
}
|
|
141784
141980
|
stat35.expanded = true;
|
|
141785
141981
|
ancestors.add(value);
|
|
141786
|
-
const entries =
|
|
141982
|
+
const entries = isSandboxRegex(value) ? Reflect.ownKeys(getRegexProperties(value)).flatMap((key3) => {
|
|
141983
|
+
const descriptor = Object.getOwnPropertyDescriptor(getRegexProperties(value), key3);
|
|
141984
|
+
return "value" in descriptor ? [descriptor.value] : [];
|
|
141985
|
+
}) : isSandboxDate(value) ? dateDataProperties(value).flatMap(([key3, descriptor]) => typeof key3 === "string" ? [descriptor.value] : []) : isSandboxBox(value) ? boxedDataProperties(value).map(([, descriptor]) => descriptor.value) : isSandboxArguments(value) ? getSandboxArgumentEntries(value).map(([, entry]) => entry) : getEnumerableDataValues(value);
|
|
141787
141986
|
for (const entry of entries) {
|
|
141788
141987
|
collectContainerStats(entry, stats2, ancestors);
|
|
141789
141988
|
}
|
|
@@ -141829,6 +142028,8 @@ var DUMP_FORMAT_VERSION, EXECUTION_SEMANTICS, SKIP_VALUE;
|
|
|
141829
142028
|
var init_dump_format = __esm({
|
|
141830
142029
|
"packages/safe-js/src/snapshot/dump-format.ts"() {
|
|
141831
142030
|
"use strict";
|
|
142031
|
+
init_values();
|
|
142032
|
+
init_regexp_properties2();
|
|
141832
142033
|
init_graph_depth();
|
|
141833
142034
|
init_object_model();
|
|
141834
142035
|
init_shape();
|
|
@@ -141849,7 +142050,7 @@ var init_dump_format = __esm({
|
|
|
141849
142050
|
});
|
|
141850
142051
|
|
|
141851
142052
|
// packages/safe-js/src/snapshot/validation.ts
|
|
141852
|
-
import { types as
|
|
142053
|
+
import { types as types6 } from "node:util";
|
|
141853
142054
|
function validateSnapshotData(value) {
|
|
141854
142055
|
validateGenericValue(value, "$", 0, {
|
|
141855
142056
|
allowFunctions: false,
|
|
@@ -141896,6 +142097,10 @@ function validateDumpHeap(root, state) {
|
|
|
141896
142097
|
const entry = requireRecord3(value, path193);
|
|
141897
142098
|
validateErrorType(entry, path193);
|
|
141898
142099
|
validateSymbolEntries(entry, path193, state, heap);
|
|
142100
|
+
if (entry.kind === "regex-object") {
|
|
142101
|
+
validateTaggedValue(entry, path193, state);
|
|
142102
|
+
continue;
|
|
142103
|
+
}
|
|
141899
142104
|
if (entry.kind === "boxed") {
|
|
141900
142105
|
validateBoxedRecord(entry, path193, heap);
|
|
141901
142106
|
continue;
|
|
@@ -142027,6 +142232,11 @@ function validateTaggedValue(record2, path193, state) {
|
|
|
142027
142232
|
requireString2(record2.source, `${path193}.source`, state.limits);
|
|
142028
142233
|
requireString2(record2.flags, `${path193}.flags`, state.limits);
|
|
142029
142234
|
if (!Object.hasOwn(record2, "lastIndex")) fail2("invalidValue", `${path193}.lastIndex`, "missing regex cursor");
|
|
142235
|
+
try {
|
|
142236
|
+
validateRegexProperties(record2);
|
|
142237
|
+
} catch {
|
|
142238
|
+
fail2("invalidValue", path193, "invalid RegExp property data");
|
|
142239
|
+
}
|
|
142030
142240
|
return;
|
|
142031
142241
|
case "array":
|
|
142032
142242
|
case "arguments":
|
|
@@ -142076,7 +142286,7 @@ function validateGeneratorShape(record2, path193, state) {
|
|
|
142076
142286
|
}
|
|
142077
142287
|
function validateSymbolEntries(record2, path193, state, heap) {
|
|
142078
142288
|
if (record2.symbolEntries === void 0) return;
|
|
142079
|
-
if (record2.kind !== "object" && record2.kind !== "array" && record2.kind !== "date" && record2.kind !== "boxed")
|
|
142289
|
+
if (record2.kind !== "object" && record2.kind !== "array" && record2.kind !== "date" && record2.kind !== "boxed" && record2.kind !== "regex-object")
|
|
142080
142290
|
fail2("invalidValue", `${path193}.symbolEntries`, "symbol properties are unsupported for this heap kind");
|
|
142081
142291
|
const entries = requireArray(record2.symbolEntries, `${path193}.symbolEntries`, state);
|
|
142082
142292
|
const keys = /* @__PURE__ */ new Set();
|
|
@@ -142229,7 +142439,7 @@ function validateGenericValue(value, path193, depth, state) {
|
|
|
142229
142439
|
if (typeof value === "object" && value !== null && hasGuestObjectState(value)) {
|
|
142230
142440
|
fail2("invalidState", path193, "guest function properties, prototype links and custom descriptors cannot be restored");
|
|
142231
142441
|
}
|
|
142232
|
-
if (state.dataPropertiesOnly &&
|
|
142442
|
+
if (state.dataPropertiesOnly && types6.isProxy(value)) {
|
|
142233
142443
|
fail2("invalidType", path193, "proxy objects are not snapshot data");
|
|
142234
142444
|
}
|
|
142235
142445
|
if (depth > state.limits.maxDepth)
|
|
@@ -142360,6 +142570,7 @@ var init_validation = __esm({
|
|
|
142360
142570
|
"packages/safe-js/src/snapshot/validation.ts"() {
|
|
142361
142571
|
"use strict";
|
|
142362
142572
|
init_shape();
|
|
142573
|
+
init_regexp_properties2();
|
|
142363
142574
|
init_symbols2();
|
|
142364
142575
|
init_dump_format();
|
|
142365
142576
|
init_graph_depth();
|
|
@@ -154718,10 +154929,10 @@ var init_random = __esm({
|
|
|
154718
154929
|
|
|
154719
154930
|
// packages/safe-js/src/realm.ts
|
|
154720
154931
|
import { AsyncLocalStorage as AsyncLocalStorage9 } from "node:async_hooks";
|
|
154721
|
-
import { types as
|
|
154932
|
+
import { types as types7 } from "node:util";
|
|
154722
154933
|
function readModules(input) {
|
|
154723
154934
|
const entries = (value, label) => {
|
|
154724
|
-
if (
|
|
154935
|
+
if (types7.isMap(value) && !types7.isProxy(value)) {
|
|
154725
154936
|
const result = [...Map.prototype.entries.call(value)];
|
|
154726
154937
|
if (result.length > 4096 || result.some(([key3]) => typeof key3 !== "string" || key3.length === 0))
|
|
154727
154938
|
throw new TypeError(`${label} requires bounded string keys.`);
|
|
@@ -154835,7 +155046,7 @@ var init_realm = __esm({
|
|
|
154835
155046
|
throw new TypeError("Realm limits must be positive safe integers with supported names.");
|
|
154836
155047
|
this.limits[name] = Number(value);
|
|
154837
155048
|
}
|
|
154838
|
-
if (options.extensions !== void 0 && (!Array.isArray(options.extensions) ||
|
|
155049
|
+
if (options.extensions !== void 0 && (!Array.isArray(options.extensions) || types7.isProxy(options.extensions)))
|
|
154839
155050
|
throw new TypeError("Extensions must be a registration array.");
|
|
154840
155051
|
const registrations = options.extensions ?? [];
|
|
154841
155052
|
const extensions = [];
|
|
@@ -155070,7 +155281,7 @@ var init_realm = __esm({
|
|
|
155070
155281
|
return this.phase.run(phase, () => {
|
|
155071
155282
|
try {
|
|
155072
155283
|
const result = call();
|
|
155073
|
-
if (
|
|
155284
|
+
if (types7.isPromise(result) || phase.pending.size > 0 || phase.failure !== void 0) {
|
|
155074
155285
|
return Promise.resolve(result).then(
|
|
155075
155286
|
async (value) => {
|
|
155076
155287
|
await Promise.allSettled(phase.pending);
|
|
@@ -155139,7 +155350,7 @@ var init_realm = __esm({
|
|
|
155139
155350
|
},
|
|
155140
155351
|
read: (operation, validate2) => {
|
|
155141
155352
|
const value = this.invokeHost(operation, operation);
|
|
155142
|
-
if (
|
|
155353
|
+
if (types7.isPromise(value)) {
|
|
155143
155354
|
void Promise.resolve(value).catch(() => void 0);
|
|
155144
155355
|
throw new TypeError("Live property operations must be synchronous.");
|
|
155145
155356
|
}
|
|
@@ -155147,7 +155358,7 @@ var init_realm = __esm({
|
|
|
155147
155358
|
},
|
|
155148
155359
|
write: (operation, value) => {
|
|
155149
155360
|
const result = this.invokeHost(operation, () => operation(this.exportValue(value)));
|
|
155150
|
-
if (
|
|
155361
|
+
if (types7.isPromise(result)) {
|
|
155151
155362
|
void Promise.resolve(result).catch(() => void 0);
|
|
155152
155363
|
throw new TypeError("Live property setters must be synchronous.");
|
|
155153
155364
|
}
|
|
@@ -155356,7 +155567,7 @@ var init_realm = __esm({
|
|
|
155356
155567
|
}
|
|
155357
155568
|
});
|
|
155358
155569
|
const output = getExtensionSetup(extension)(context);
|
|
155359
|
-
if (
|
|
155570
|
+
if (types7.isPromise(output)) {
|
|
155360
155571
|
void Promise.resolve(output).catch(() => void 0);
|
|
155361
155572
|
throw new TypeError("Extension setup must be synchronous.");
|
|
155362
155573
|
}
|
|
@@ -155976,6 +156187,7 @@ var init_serialize = __esm({
|
|
|
155976
156187
|
"packages/safe-js/src/snapshot/serialize.ts"() {
|
|
155977
156188
|
"use strict";
|
|
155978
156189
|
init_hash();
|
|
156190
|
+
init_regexp_properties2();
|
|
155979
156191
|
init_symbols3();
|
|
155980
156192
|
init_collection_iterator();
|
|
155981
156193
|
init_object_model();
|