@poe-platform/safe-js 0.1.448 → 0.1.449

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.
@@ -12376,8 +12376,12 @@ function formatNumber(value, methodName, argument, budget) {
12376
12376
  // packages/safe-js/src/interp/methods/string.ts
12377
12377
  import { types as types7 } from "node:util";
12378
12378
 
12379
- // packages/safe-js/src/interp/methods/string-locale.ts
12380
- var collatorOptions = [
12379
+ // packages/safe-js/src/interp/intl-collator.ts
12380
+ var NativeCollator = Intl.Collator;
12381
+ var nativeResolvedOptions = NativeCollator.prototype.resolvedOptions;
12382
+ var nativeCompare = Object.getOwnPropertyDescriptor(NativeCollator.prototype, "compare").get;
12383
+ var states5 = /* @__PURE__ */ new WeakMap();
12384
+ var optionTypes = [
12381
12385
  ["usage", ["sort", "search"]],
12382
12386
  ["localeMatcher", ["lookup", "best fit"]],
12383
12387
  ["collation", "unicodeType"],
@@ -12386,6 +12390,50 @@ var collatorOptions = [
12386
12390
  ["sensitivity", ["base", "accent", "case", "variant"]],
12387
12391
  ["ignorePunctuation", "boolean"]
12388
12392
  ];
12393
+ async function readCollatorOptions(input, budget, context, invalid) {
12394
+ const source = intlOptionsObject(input, budget);
12395
+ const options = /* @__PURE__ */ Object.create(null);
12396
+ const release = retainValues(budget, () => [source, options]);
12397
+ try {
12398
+ for (const [key, type] of optionTypes) {
12399
+ const value = await readIntlProperty(source, key, budget, context);
12400
+ if (value !== void 0) options[key] = await convertIntlOption(
12401
+ value,
12402
+ key,
12403
+ type,
12404
+ budget,
12405
+ context,
12406
+ (text) => {
12407
+ invalid?.(key, text);
12408
+ new NativeCollator([], { [key]: text });
12409
+ }
12410
+ );
12411
+ }
12412
+ return options;
12413
+ } finally {
12414
+ release();
12415
+ }
12416
+ }
12417
+ function createSandboxCollator(locales2, options) {
12418
+ const native = new NativeCollator(locales2, options);
12419
+ const value = /* @__PURE__ */ Object.create(null);
12420
+ states5.set(value, { native, options: Reflect.apply(nativeResolvedOptions, native, []) });
12421
+ return value;
12422
+ }
12423
+ function isSandboxCollator(value) {
12424
+ return typeof value === "object" && value !== null && states5.has(value);
12425
+ }
12426
+ function collatorState(value) {
12427
+ if (!isSandboxCollator(value)) throw new TypeError("Intl.Collator requires a Collator receiver.");
12428
+ return states5.get(value);
12429
+ }
12430
+ function compareCollatorStrings(value, first, second) {
12431
+ const state = collatorState(value);
12432
+ const compare = Reflect.apply(nativeCompare, state.native, []);
12433
+ return Reflect.apply(compare, void 0, [first, second]);
12434
+ }
12435
+
12436
+ // packages/safe-js/src/interp/methods/string-locale.ts
12389
12437
  async function changeStringLocaleCase(value, method, args, budget, context) {
12390
12438
  let locales2 = [];
12391
12439
  const release = retainValues(budget, () => [value, locales2]);
@@ -12400,19 +12448,15 @@ async function changeStringLocaleCase(value, method, args, budget, context) {
12400
12448
  async function compareStringLocale(value, args, budget, context) {
12401
12449
  let comparison = "";
12402
12450
  let locales2 = [];
12403
- const options = /* @__PURE__ */ Object.create(null);
12451
+ let options = /* @__PURE__ */ Object.create(null);
12404
12452
  const release = retainValues(budget, () => [value, comparison, locales2, options]);
12405
12453
  try {
12406
12454
  comparison = await sandboxString(args[0], budget, context);
12407
12455
  locales2 = await canonicalizeGuestLocales(args[1], budget, context);
12408
12456
  if (args[2] === null) return Reflect.apply(String.prototype.localeCompare, value, [comparison, locales2, null]);
12409
- const inputOptions = intlOptionsObject(args[2], budget);
12410
- for (const [key, type] of collatorOptions) {
12411
- const option = await readIntlProperty(inputOptions, key, budget, context);
12412
- if (option !== void 0) options[key] = await convertIntlOption(option, key, type, budget, context, (text) => {
12413
- Reflect.apply(String.prototype.localeCompare, "", ["", [], { [key]: text }]);
12414
- });
12415
- }
12457
+ options = await readCollatorOptions(args[2], budget, context, (key, text) => {
12458
+ Reflect.apply(String.prototype.localeCompare, "", ["", [], { [key]: text }]);
12459
+ });
12416
12460
  budget.visitNode(value.length + comparison.length);
12417
12461
  return Reflect.apply(String.prototype.localeCompare, value, [comparison, locales2, options]);
12418
12462
  } finally {
@@ -21172,7 +21216,7 @@ async function buildLocaleTag(input, optionsInput, budget, context) {
21172
21216
  }
21173
21217
  const updated = Object.values(base).filter((value) => value !== void 0).join("-") + canonical.slice(native.baseName.length);
21174
21218
  const extension = unicodeKeywords(updated);
21175
- const optionTypes = [
21219
+ const optionTypes2 = [
21176
21220
  ["calendar", "ca", "unicodeType"],
21177
21221
  ["collation", "co", "unicodeType"],
21178
21222
  ["firstDayOfWeek", "fw", "unicodeType"],
@@ -21181,7 +21225,7 @@ async function buildLocaleTag(input, optionsInput, budget, context) {
21181
21225
  ["numeric", "kn", "boolean"],
21182
21226
  ["numberingSystem", "nu", "unicodeType"]
21183
21227
  ];
21184
- for (const [key, extensionKey, type] of optionTypes) {
21228
+ for (const [key, extensionKey, type] of optionTypes2) {
21185
21229
  let value = await readIntlProperty(options, key, budget, context);
21186
21230
  if (value === void 0) continue;
21187
21231
  if (key === "firstDayOfWeek") {
@@ -21540,6 +21584,10 @@ function captureGuestHeapNode(value, encode) {
21540
21584
  return void 0;
21541
21585
  }
21542
21586
  if (isSandboxLocale(value)) return { kind: "guest-locale", tag: localeTag(value), state: captureObjectState(value, encode) };
21587
+ if (isSandboxCollator(value)) {
21588
+ const { options, compare } = collatorState(value);
21589
+ return { kind: "guest-collator", options: { ...options }, ...compare === void 0 ? {} : { compare: encode(compare) }, state: captureObjectState(value, encode) };
21590
+ }
21543
21591
  if (hasGuestObjectState(value) || privateElements.has(value)) {
21544
21592
  if (isSandboxRegex(value)) return { kind: "guest-regex", source: value.source, flags: value.flags, state: captureObjectState(value, encode) };
21545
21593
  if (isSandboxBox(value)) return { kind: "guest-boxed", value: encode(boxedValue(value)), state: captureObjectState(value, encode) };
@@ -25742,6 +25790,107 @@ function createLocaleConstructor(budget) {
25742
25790
  return constructor;
25743
25791
  }
25744
25792
 
25793
+ // packages/safe-js/src/interp/globals/intl-collator.ts
25794
+ var supportedLocalesOf = Intl.Collator.supportedLocalesOf;
25795
+ function createCollatorConstructor(budget) {
25796
+ const prototype = createIntrinsicObject();
25797
+ const compareTarget = createSandboxClosure({
25798
+ guest: true,
25799
+ sandbox: true,
25800
+ name: "",
25801
+ length: 2,
25802
+ call: async ([first, second], context) => {
25803
+ let left = "";
25804
+ const release = retainValues(budget, () => [context?.thisValue, left]);
25805
+ try {
25806
+ left = await sandboxString(first, budget, context);
25807
+ const right = await sandboxString(second, budget, context);
25808
+ budget.visitNode(left.length + right.length);
25809
+ return compareCollatorStrings(context?.thisValue, left, right);
25810
+ } finally {
25811
+ release();
25812
+ }
25813
+ }
25814
+ });
25815
+ registerBuiltinIdentities(budget, { "%CollatorCompare%": compareTarget });
25816
+ registerIntrinsicFunction(budget, compareTarget);
25817
+ const initialize = async ([input, options], context) => {
25818
+ const target = context?.newTarget;
25819
+ const selected = target === void 0 || target === constructor ? prototype : context?.getProperty !== void 0 ? await context.getProperty(target, "prototype") : await readPropertyDescriptor(getSandboxPropertyDescriptor(target, "prototype", budget) ?? { value: void 0 }, target, context);
25820
+ let locales2 = [];
25821
+ const release = retainValues(budget, () => [selected, locales2]);
25822
+ try {
25823
+ locales2 = await canonicalizeGuestLocales(input, budget, context);
25824
+ const converted = await readCollatorOptions(options, budget, context);
25825
+ const value = createSandboxCollator(locales2, converted);
25826
+ setSandboxPrototype(value, typeof selected === "object" && selected !== null ? selected : prototype, budget);
25827
+ return allocateProducedSandboxValue(value, budget);
25828
+ } finally {
25829
+ release();
25830
+ }
25831
+ };
25832
+ const constructor = createSandboxClosure({
25833
+ guest: true,
25834
+ sandbox: true,
25835
+ name: "Collator",
25836
+ length: 0,
25837
+ construct: initialize,
25838
+ call: (args, context) => initialize(args, { ...context, stack: context?.stack ?? [], thisValue: context?.thisValue, newTarget: void 0 })
25839
+ });
25840
+ const properties = materializeFunctionProperties(constructor);
25841
+ Object.defineProperty(properties, "prototype", { value: prototype, writable: false, configurable: false });
25842
+ Object.defineProperty(properties, "supportedLocalesOf", { value: createSandboxClosure({
25843
+ guest: true,
25844
+ sandbox: true,
25845
+ name: "supportedLocalesOf",
25846
+ length: 1,
25847
+ call: async ([input, options], context) => {
25848
+ const locales2 = await canonicalizeGuestLocales(input, budget, context);
25849
+ const release = retainValues(budget, () => [locales2]);
25850
+ try {
25851
+ const source = intlOptionsObject(options, budget);
25852
+ const option = await readIntlProperty(source, "localeMatcher", budget, context);
25853
+ const matcher = option === void 0 ? void 0 : await convertIntlOption(option, "localeMatcher", ["lookup", "best fit"], budget, context);
25854
+ return allocateProducedSandboxValue(supportedLocalesOf(locales2, { localeMatcher: matcher }), budget);
25855
+ } finally {
25856
+ release();
25857
+ }
25858
+ }
25859
+ }), writable: true, configurable: true });
25860
+ Object.defineProperties(prototype, {
25861
+ constructor: { value: constructor, writable: true, configurable: true },
25862
+ [Symbol.toStringTag]: { value: "Intl.Collator", configurable: true },
25863
+ resolvedOptions: { value: createSandboxClosure({
25864
+ guest: true,
25865
+ sandbox: true,
25866
+ name: "resolvedOptions",
25867
+ length: 0,
25868
+ call: (_args, context) => allocateProducedSandboxValue({ ...collatorState(context?.thisValue).options }, budget)
25869
+ }), writable: true, configurable: true },
25870
+ compare: { get: accessorAdapter(createSandboxClosure({
25871
+ guest: true,
25872
+ sandbox: true,
25873
+ name: "get compare",
25874
+ length: 0,
25875
+ call: (_args, context) => {
25876
+ const receiver = context?.thisValue;
25877
+ const state = collatorState(receiver);
25878
+ if (state.compare === void 0) {
25879
+ state.compare = createBoundFunction(
25880
+ { target: compareTarget, thisValue: receiver, args: [] },
25881
+ "",
25882
+ 2,
25883
+ (target, args, stack, thisValue) => invokeBuiltinClosure(target, args, budget, { stack, thisValue }, thisValue)
25884
+ );
25885
+ allocateProducedSandboxValue(state.compare, budget);
25886
+ }
25887
+ return state.compare;
25888
+ }
25889
+ }), "get"), configurable: true }
25890
+ });
25891
+ return constructor;
25892
+ }
25893
+
25745
25894
  // packages/safe-js/src/interp/globals/intl.ts
25746
25895
  var supportedValuesOf = Intl.supportedValuesOf;
25747
25896
  function createIntlGlobal(budget) {
@@ -25755,18 +25904,23 @@ function createIntlGlobal(budget) {
25755
25904
  };
25756
25905
  const intl = createIntrinsicObject();
25757
25906
  const locale = createLocaleConstructor(budget);
25907
+ const collator = createCollatorConstructor(budget);
25758
25908
  Object.defineProperty(intl, "Locale", { value: locale, writable: true, configurable: true });
25909
+ Object.defineProperty(intl, "Collator", { value: collator, writable: true, configurable: true });
25759
25910
  for (const [name, call] of Object.entries(methods2)) {
25760
25911
  const closure = createSandboxClosure({ guest: true, sandbox: true, name, length: 1, call });
25761
25912
  Object.defineProperty(intl, name, { value: closure, writable: true, configurable: true });
25762
25913
  }
25763
25914
  Object.defineProperty(intl, Symbol.toStringTag, { value: "Intl", configurable: true });
25764
25915
  registerBuiltinIdentities(budget, { Intl: intl });
25765
- const prototype = locale.properties.prototype;
25766
- for (const descriptor of Object.values(Object.getOwnPropertyDescriptors(prototype)))
25767
- for (const closure of [descriptor.value, ...retainedAccessorClosures(descriptor)])
25768
- if (isSandboxClosure(closure)) registerIntrinsicFunction(budget, closure);
25769
- registerIntrinsicObject(budget, prototype);
25916
+ for (const constructor of [locale, collator]) {
25917
+ const prototype = constructor.properties.prototype;
25918
+ for (const owner of [prototype, constructor.properties])
25919
+ for (const descriptor of Object.values(Object.getOwnPropertyDescriptors(owner)))
25920
+ for (const closure of [descriptor.value, ...retainedAccessorClosures(descriptor)])
25921
+ if (isSandboxClosure(closure)) registerIntrinsicFunction(budget, closure);
25922
+ registerIntrinsicObject(budget, prototype);
25923
+ }
25770
25924
  for (const name of Object.keys(methods2)) registerIntrinsicFunction(budget, intl[name]);
25771
25925
  registerIntrinsicObject(budget, intl);
25772
25926
  return intl;
@@ -25876,7 +26030,7 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
25876
26030
  createRawJson(node.text);
25877
26031
  return true;
25878
26032
  }
25879
- if (!["module-function", "async-generator-driver", "async-generator-handler", "async-function-driver", "async-function-handler", "thenable-state", "thenable-resolver", "construction-environment", "capability-executor", "promise-aggregate", "aggregate-entry", "aggregate-handler", "intrinsic", "bound-function", "promise-resolver", "pending-promise", "promise-reaction", "promise-adoption", "adoption-resolver", "guest-function", "guest-class", "guest-generator", "scope-frame", "guest-object", "guest-array", "guest-boxed", "guest-date", "guest-locale", "guest-regex", "guest-promise", "array-iterator", "string-iterator", "async-disposable-stack", "async-cleanup", "async-cleanup-handler", "disposable-stack", "iterator-wrapper", "iterator-helper", "guest-collection-iterator", "guest-regexp-iterator", "map", "set"].includes(String(node.kind))) return false;
26033
+ if (!["module-function", "async-generator-driver", "async-generator-handler", "async-function-driver", "async-function-handler", "thenable-state", "thenable-resolver", "construction-environment", "capability-executor", "promise-aggregate", "aggregate-entry", "aggregate-handler", "intrinsic", "bound-function", "promise-resolver", "pending-promise", "promise-reaction", "promise-adoption", "adoption-resolver", "guest-function", "guest-class", "guest-generator", "scope-frame", "guest-object", "guest-array", "guest-boxed", "guest-date", "guest-locale", "guest-collator", "guest-regex", "guest-promise", "array-iterator", "string-iterator", "async-disposable-stack", "async-cleanup", "async-cleanup-handler", "disposable-stack", "iterator-wrapper", "iterator-helper", "guest-collection-iterator", "guest-regexp-iterator", "map", "set"].includes(String(node.kind))) return false;
25880
26034
  const reference = (value, kinds) => {
25881
26035
  const ref = record2(value);
25882
26036
  fields(ref, ["kind", "id"]);
@@ -26145,6 +26299,23 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
26145
26299
  fields(node, ["kind", "source", "flags", "state"]);
26146
26300
  if (typeof node.source !== "string" || typeof node.flags !== "string") throw new TypeError("Invalid guest RegExp payload.");
26147
26301
  state(node.state);
26302
+ } else if (node.kind === "guest-collator") {
26303
+ fields(node, ["kind", "options", "state"], ["compare"]);
26304
+ const options = record2(node.options);
26305
+ const names = ["locale", "usage", "sensitivity", "ignorePunctuation", "collation", "numeric", "caseFirst"];
26306
+ fields(options, names);
26307
+ for (const key of names)
26308
+ if (typeof options[key] !== (key === "numeric" || key === "ignorePunctuation" ? "boolean" : "string"))
26309
+ throw new TypeError("Invalid Collator option type.");
26310
+ const restored = collatorState(createSandboxCollator(options.locale, options)).options;
26311
+ for (const key of names)
26312
+ if (options[key] !== restored[key]) throw new TypeError("Invalid resolved Collator options.");
26313
+ if (node.compare !== void 0) {
26314
+ const compare = reference(node.compare, ["bound-function"]);
26315
+ if (reference(compare.thisValue) !== node || array(compare.args).length !== 0 || compare.name !== "" || compare.length !== 2 || reference(compare.target, ["intrinsic"]).id !== '["%CollatorCompare%"]')
26316
+ throw new TypeError("Invalid cached Collator comparison.");
26317
+ }
26318
+ state(node.state);
26148
26319
  } else if (node.kind === "guest-locale") {
26149
26320
  fields(node, ["kind", "tag", "state"]);
26150
26321
  if (typeof node.tag !== "string" || localeTag(createSandboxLocale(node.tag)) !== node.tag)
@@ -29883,6 +30054,11 @@ function measureSandboxData(values, options = {}) {
29883
30054
  }
29884
30055
  if (isSandboxDate(value)) usage += 8;
29885
30056
  if (isSandboxLocale(value)) usage += localeTag(value).length;
30057
+ if (isSandboxCollator(value)) {
30058
+ const state = collatorState(value);
30059
+ visit(state.options, depth + 1);
30060
+ visit(state.compare, depth + 1);
30061
+ }
29886
30062
  if (isGuestHostObject(value)) {
29887
30063
  usage += measureHostObjectData(value);
29888
30064
  return;
@@ -47846,4 +48022,4 @@ export {
47846
48022
  FileSnapshotBackend,
47847
48023
  run
47848
48024
  };
47849
- //# sourceMappingURL=chunk-D32JKK5K.js.map
48025
+ //# sourceMappingURL=chunk-264RHYEA.js.map