poe-code 14.0.39 → 14.0.41

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 CHANGED
@@ -122866,10 +122866,7 @@ function rebasePosition(position, base) {
122866
122866
  };
122867
122867
  }
122868
122868
  function isLiteralPropertyKey(token) {
122869
- if (token.type === "numeric" || token.type === "string") {
122870
- return true;
122871
- }
122872
- return token.type === "keyword" && (token.value === "true" || token.value === "false" || token.value === "null" || token.value === "undefined");
122869
+ return token.type === "numeric" || token.type === "string";
122873
122870
  }
122874
122871
  function isIdentifierLikeToken(token) {
122875
122872
  return token.type === "identifier" || token.type === "keyword" && token.value === "async";
@@ -123992,9 +123989,9 @@ var init_parser3 = __esm({
123992
123989
  };
123993
123990
  }
123994
123991
  const token = this.currentToken();
123995
- if (token.type === "identifier") {
123992
+ if (token.type === "identifier" || token.type === "keyword") {
123996
123993
  this.index += 1;
123997
- const key3 = createIdentifier2(token);
123994
+ const key3 = createIdentifierName(token);
123998
123995
  if (this.consumePunctuator(":") !== void 0) {
123999
123996
  const value2 = this.parseBindingElement();
124000
123997
  if (value2.type === "RestElement") {
@@ -124009,6 +124006,7 @@ var init_parser3 = __esm({
124009
124006
  span: createSpan2(key3.span.start, value2.span.end)
124010
124007
  };
124011
124008
  }
124009
+ if (!isIdentifierLikeToken(token)) throw unexpectedTokenError(token);
124012
124010
  let value = key3;
124013
124011
  if (this.consumePunctuator("=") !== void 0) {
124014
124012
  const right = this.parseExpression().node;
@@ -124221,9 +124219,9 @@ var init_parser3 = __esm({
124221
124219
  };
124222
124220
  }
124223
124221
  const token = this.currentToken();
124224
- if (token.type === "identifier") {
124222
+ if (token.type === "identifier" || token.type === "keyword") {
124225
124223
  this.index += 1;
124226
- const key3 = createIdentifier2(token);
124224
+ const key3 = createIdentifierName(token);
124227
124225
  if (this.consumePunctuator(":") !== void 0) {
124228
124226
  const value2 = this.parseAssignmentPatternElement();
124229
124227
  if (value2.type === "RestElement") {
@@ -124238,6 +124236,7 @@ var init_parser3 = __esm({
124238
124236
  span: createSpan2(key3.span.start, value2.span.end)
124239
124237
  };
124240
124238
  }
124239
+ if (!isIdentifierLikeToken(token)) throw unexpectedTokenError(token);
124241
124240
  let value = key3;
124242
124241
  if (this.consumePunctuator("=") !== void 0) {
124243
124242
  const right = this.parseAssignmentExpression().node;
@@ -124886,9 +124885,9 @@ var init_parser3 = __esm({
124886
124885
  };
124887
124886
  }
124888
124887
  const token = this.currentToken();
124889
- if (isIdentifierLikeToken(token) || token.type === "keyword" && this.peekToken(1).type === "punctuator" && this.peekToken(1).value === "(") {
124888
+ if (token.type === "identifier" || token.type === "keyword") {
124890
124889
  this.index += 1;
124891
- const key3 = createIdentifier2(token);
124890
+ const key3 = createIdentifierName(token);
124892
124891
  if (this.currentToken().type === "punctuator" && this.currentToken().value === "(") {
124893
124892
  const value2 = this.parseObjectMethod(asyncToken, key3.span.start);
124894
124893
  return {
@@ -124901,6 +124900,7 @@ var init_parser3 = __esm({
124901
124900
  };
124902
124901
  }
124903
124902
  if (this.consumePunctuator(":") === void 0) {
124903
+ if (!isIdentifierLikeToken(token)) throw unexpectedTokenError(token);
124904
124904
  assertAllowedIdentifierReference(token);
124905
124905
  return {
124906
124906
  type: "Property",
@@ -145253,6 +145253,147 @@ var init_error = __esm({
145253
145253
  }
145254
145254
  });
145255
145255
 
145256
+ // packages/safe-js/src/interp/globals/object.ts
145257
+ function createObjectGlobal(methods, budget) {
145258
+ const construct = ([value]) => {
145259
+ if (value === null || value === void 0) {
145260
+ budget.chargeDataUsage(1);
145261
+ return /* @__PURE__ */ Object.create(null);
145262
+ }
145263
+ if (typeof value !== "object") throw new TypeError("Object primitive boxing is not supported.");
145264
+ return value;
145265
+ };
145266
+ const constructor = createSandboxClosure({
145267
+ guest: true,
145268
+ sandbox: true,
145269
+ name: "Object",
145270
+ length: 1,
145271
+ call: construct,
145272
+ construct
145273
+ });
145274
+ const properties = materializeFunctionProperties(constructor);
145275
+ const prototype = properties.prototype;
145276
+ Object.defineProperty(properties, "prototype", { writable: false });
145277
+ for (const [name, method] of Object.entries(methods)) {
145278
+ Object.defineProperty(properties, name, { value: method, writable: true, configurable: true });
145279
+ }
145280
+ const prototypeMethods = {
145281
+ toString: createSandboxClosure({
145282
+ sandbox: true,
145283
+ name: "toString",
145284
+ length: 0,
145285
+ call: (_args, context) => budget.allocateString(`[object ${typeTag(context?.thisValue)}]`)
145286
+ }),
145287
+ valueOf: createSandboxClosure({
145288
+ sandbox: true,
145289
+ name: "valueOf",
145290
+ length: 0,
145291
+ call: (_args, context) => {
145292
+ const value = requireReceiver(context?.thisValue);
145293
+ if (typeof value !== "object")
145294
+ throw new TypeError("Object primitive boxing is not supported.");
145295
+ return value;
145296
+ }
145297
+ }),
145298
+ hasOwnProperty: createSandboxClosure({
145299
+ sandbox: true,
145300
+ name: "hasOwnProperty",
145301
+ length: 1,
145302
+ call: async ([key3], context) => hasOwnSandboxProperty(
145303
+ requireReceiver(context?.thisValue),
145304
+ await sandboxString(key3, budget, context),
145305
+ false
145306
+ )
145307
+ }),
145308
+ propertyIsEnumerable: createSandboxClosure({
145309
+ sandbox: true,
145310
+ name: "propertyIsEnumerable",
145311
+ length: 1,
145312
+ call: async ([key3], context) => hasOwnSandboxProperty(
145313
+ requireReceiver(context?.thisValue),
145314
+ await sandboxString(key3, budget, context),
145315
+ true
145316
+ )
145317
+ }),
145318
+ isPrototypeOf: createSandboxClosure({
145319
+ sandbox: true,
145320
+ name: "isPrototypeOf",
145321
+ length: 1,
145322
+ call: ([value], context) => {
145323
+ if (typeof value !== "object" || value === null) return false;
145324
+ const receiver = requireReceiver(context?.thisValue);
145325
+ let depth = 0;
145326
+ for (let current = getSandboxPrototype(value, budget); current !== null; current = getSandboxPrototype(current, budget)) {
145327
+ budget.visitNode();
145328
+ assertSandboxDataDepth(depth++);
145329
+ if (current === receiver) return true;
145330
+ }
145331
+ return false;
145332
+ }
145333
+ })
145334
+ };
145335
+ for (const [name, method] of Object.entries(prototypeMethods)) {
145336
+ Object.defineProperty(prototype, name, { value: method, writable: true, configurable: true });
145337
+ }
145338
+ markDescriptorObject(prototype);
145339
+ installObjectPrototype(budget, prototype, constructor);
145340
+ return constructor;
145341
+ }
145342
+ function requireReceiver(value) {
145343
+ if (value === null || value === void 0)
145344
+ throw new TypeError("Object method requires a non-null receiver.");
145345
+ return value;
145346
+ }
145347
+ function hasOwnSandboxProperty(value, key3, enumerable) {
145348
+ requireReceiver(value);
145349
+ if (isGuestHostObject(value)) return hasHostObjectMember(value, key3, enumerable);
145350
+ let properties;
145351
+ if (isGuestClosure(value)) properties = materializeFunctionProperties(value);
145352
+ else if (isSandboxClosure(value)) {
145353
+ if (key3 === "length" || key3 === "name") return !enumerable;
145354
+ properties = value.properties ?? /* @__PURE__ */ Object.create(null);
145355
+ } else if (isSandboxMap(value) || isSandboxSet(value) || isSandboxPromise(value) || isSandboxGenerator(value))
145356
+ return false;
145357
+ else if (isSandboxRegex(value)) return key3 === "lastIndex" && !enumerable;
145358
+ else properties = Object(value);
145359
+ const descriptor = Object.getOwnPropertyDescriptor(properties, key3);
145360
+ return descriptor !== void 0 && (!enumerable || descriptor.enumerable === true);
145361
+ }
145362
+ function typeTag(value) {
145363
+ if (value === void 0) return "Undefined";
145364
+ if (value === null) return "Null";
145365
+ if (typeof value === "string") return "String";
145366
+ if (typeof value === "number") return "Number";
145367
+ if (typeof value === "boolean") return "Boolean";
145368
+ if (isSandboxClosure(value)) {
145369
+ while (value.boundTarget !== void 0) value = value.boundTarget;
145370
+ return value.generator ? "GeneratorFunction" : value.async ? "AsyncFunction" : "Function";
145371
+ }
145372
+ if (Array.isArray(value)) return "Array";
145373
+ if (isSandboxDate(value)) return "Date";
145374
+ if (isSandboxErrorConstructorInstance(value, "Error")) return "Error";
145375
+ if (isSandboxRegex(value)) return "RegExp";
145376
+ if (isSandboxMap(value)) return "Map";
145377
+ if (isSandboxSet(value)) return "Set";
145378
+ if (isSandboxPromise(value)) return "Promise";
145379
+ if (isSandboxGenerator(value)) return "Generator";
145380
+ if (isFloat32Array(value)) return "Float32Array";
145381
+ return "Object";
145382
+ }
145383
+ var init_object2 = __esm({
145384
+ "packages/safe-js/src/interp/globals/object.ts"() {
145385
+ "use strict";
145386
+ init_graph_depth();
145387
+ init_date();
145388
+ init_exceptions();
145389
+ init_float32();
145390
+ init_host_capabilities();
145391
+ init_object_model();
145392
+ init_string_coercion();
145393
+ init_values();
145394
+ }
145395
+ });
145396
+
145256
145397
  // packages/safe-js/src/interp/globals/collections.ts
145257
145398
  function createCollectionGlobals(options) {
145258
145399
  const mapConstructor = createSandboxClosure({
@@ -145866,6 +146007,7 @@ async function interpret(node, options = {}) {
145866
146007
  budget,
145867
146008
  callStack: [],
145868
146009
  onYield: options.onYield,
146010
+ onSuspend: options.onSuspend,
145869
146011
  captureReplayState: options.captureReplayState,
145870
146012
  rootNode: node,
145871
146013
  scope,
@@ -146237,11 +146379,14 @@ async function evaluateBinaryExpression(node, context) {
146237
146379
  if (right.kind !== "normal") {
146238
146380
  return right;
146239
146381
  }
146240
- const value = node.operator === "in" && isGuestHostObject(right.value) ? hasHostObjectMember(right.value, await sandboxString(left.value, context.budget, {
146241
- stack: context.callStack,
146242
- thisValue: void 0,
146243
- invokeClosure: (closure, args, thisValue) => invokeSandboxClosure(closure, args, context, context.callStack, void 0, thisValue)
146244
- })) : applyBinaryOperator(node, left.value, right.value, context);
146382
+ let leftValue = left.value;
146383
+ if (node.operator === "in") {
146384
+ if (typeof right.value !== "object" || right.value === null) {
146385
+ throw new TypeError("Right-hand side of 'in' must be an object.");
146386
+ }
146387
+ leftValue = await toPropertyKey(leftValue, context);
146388
+ }
146389
+ const value = applyBinaryOperator(node, leftValue, right.value, context);
146245
146390
  return {
146246
146391
  kind: "normal",
146247
146392
  hasValue: true,
@@ -147949,9 +148094,44 @@ function applyBinaryOperator(node, left, right, context) {
147949
148094
  }
147950
148095
  return false;
147951
148096
  case "in":
147952
- throw createError("UNSUPPORTED_NODE", node, "Binary operator 'in' is not supported.");
148097
+ return hasSandboxProperty(right, left, context);
147953
148098
  }
147954
148099
  }
148100
+ async function toPropertyKey(value, context) {
148101
+ if (isPlainSandboxObject(value) && !isSandboxDate(value) && !isFloat32Array(value) && !isSandboxGenerator(value) && !isGuestHostObject(value)) {
148102
+ for (const name of ["toString", "valueOf"]) {
148103
+ const method = getMemberValue(value, name, context);
148104
+ if (!isSandboxClosure(method)) continue;
148105
+ const primitive = await invokeSandboxClosure(method, [], context, context.callStack, void 0, value);
148106
+ if (primitive === null || typeof primitive !== "object") {
148107
+ return context.budget.allocateString(String(primitive));
148108
+ }
148109
+ }
148110
+ throw new TypeError("Cannot convert object to primitive value.");
148111
+ }
148112
+ return sandboxString(value, context.budget, {
148113
+ stack: context.callStack,
148114
+ thisValue: void 0,
148115
+ invokeClosure: (closure, args, thisValue) => invokeSandboxClosure(closure, args, context, context.callStack, void 0, thisValue)
148116
+ });
148117
+ }
148118
+ function hasSandboxProperty(value, key3, context) {
148119
+ let current = value;
148120
+ let depth = 0;
148121
+ while (typeof current === "object" && current !== null) {
148122
+ if (isGuestHostObject(current)) return hasHostObjectMember(current, key3);
148123
+ if (hasOwnSandboxProperty(current, key3, false)) return true;
148124
+ if (Array.isArray(current) || !isPlainSandboxObject(current) || isSandboxDate(current) || isFloat32Array(current) || isSandboxGenerator(current)) {
148125
+ return getPropertyValue(current, key3, context) !== void 0;
148126
+ }
148127
+ current = getSandboxPrototype(current, context.budget);
148128
+ if (current !== null) {
148129
+ context.budget.visitNode();
148130
+ assertSandboxDataDepth(++depth);
148131
+ }
148132
+ }
148133
+ return false;
148134
+ }
147955
148135
  async function applyCompoundAssignmentOperator(operator, left, right, context) {
147956
148136
  left = await toNumericPrimitive(left, context);
147957
148137
  right = await toNumericPrimitive(right, context);
@@ -148507,6 +148687,7 @@ var init_interpreter = __esm({
148507
148687
  init_string();
148508
148688
  init_set();
148509
148689
  init_error();
148690
+ init_object2();
148510
148691
  init_collections();
148511
148692
  init_float32array2();
148512
148693
  init_float32();
@@ -148638,44 +148819,51 @@ function createInterpretedClosure(node, context, evaluateNode3) {
148638
148819
  };
148639
148820
  if (!node.async)
148640
148821
  return executeClosure(node, args, callContext?.thisValue, invocationContext, evaluateNode3);
148641
- let completePrefix;
148642
- const synchronousPrefix = new Promise((resolve16) => {
148643
- completePrefix = resolve16;
148644
- });
148645
- const promise = new Promise((resolve16, reject) => {
148646
- runAsyncPrefix(async () => {
148647
- try {
148648
- const value = await executeClosure(
148649
- node,
148650
- args,
148651
- callContext?.thisValue,
148652
- { ...invocationContext, onSuspend: completePrefix },
148653
- evaluateNode3
148654
- );
148655
- resolve16(
148656
- isSandboxPromise(value) || getThenable(value) !== void 0 ? awaitSandboxValue(
148657
- createSandboxPromise(resolveSandboxValue(value, { budget: context.budget }), {
148658
- trackReplay: false
148659
- }),
148660
- context.signal,
148661
- context.budget
148662
- ) : allocateProducedSandboxValue(value, context.budget)
148663
- );
148664
- } catch (error3) {
148665
- reject(error3);
148666
- } finally {
148667
- completePrefix();
148668
- }
148669
- }).catch((error3) => {
148670
- reject(error3);
148671
- completePrefix();
148672
- });
148673
- });
148674
- return createSandboxPromise(promise, { synchronousPrefix });
148822
+ return executeAsyncFunction(
148823
+ (onSuspend) => executeClosure(
148824
+ node,
148825
+ args,
148826
+ callContext?.thisValue,
148827
+ { ...invocationContext, onSuspend },
148828
+ evaluateNode3
148829
+ ),
148830
+ context.budget,
148831
+ context.signal
148832
+ );
148675
148833
  }
148676
148834
  });
148677
148835
  return closure;
148678
148836
  }
148837
+ function executeAsyncFunction(execute2, budget, signal) {
148838
+ let completePrefix;
148839
+ const synchronousPrefix = new Promise((resolve16) => {
148840
+ completePrefix = resolve16;
148841
+ });
148842
+ const promise = new Promise((resolve16, reject) => {
148843
+ runAsyncPrefix(async () => {
148844
+ try {
148845
+ const value = await execute2(completePrefix);
148846
+ resolve16(
148847
+ isSandboxPromise(value) || getThenable(value) !== void 0 ? awaitSandboxValue(
148848
+ createSandboxPromise(resolveSandboxValue(value, { budget }), {
148849
+ trackReplay: false
148850
+ }),
148851
+ signal,
148852
+ budget
148853
+ ) : allocateProducedSandboxValue(value, budget)
148854
+ );
148855
+ } catch (error3) {
148856
+ reject(error3);
148857
+ } finally {
148858
+ completePrefix();
148859
+ }
148860
+ }).catch((error3) => {
148861
+ reject(error3);
148862
+ completePrefix();
148863
+ });
148864
+ });
148865
+ return createSandboxPromise(promise, { synchronousPrefix });
148866
+ }
148679
148867
  function createGeneratorClosure(node, context, evaluateNode3) {
148680
148868
  return createSandboxClosure({
148681
148869
  guest: true,
@@ -150388,147 +150576,6 @@ var init_misc = __esm({
150388
150576
  }
150389
150577
  });
150390
150578
 
150391
- // packages/safe-js/src/interp/globals/object.ts
150392
- function createObjectGlobal(methods, budget) {
150393
- const construct = ([value]) => {
150394
- if (value === null || value === void 0) {
150395
- budget.chargeDataUsage(1);
150396
- return /* @__PURE__ */ Object.create(null);
150397
- }
150398
- if (typeof value !== "object") throw new TypeError("Object primitive boxing is not supported.");
150399
- return value;
150400
- };
150401
- const constructor = createSandboxClosure({
150402
- guest: true,
150403
- sandbox: true,
150404
- name: "Object",
150405
- length: 1,
150406
- call: construct,
150407
- construct
150408
- });
150409
- const properties = materializeFunctionProperties(constructor);
150410
- const prototype = properties.prototype;
150411
- Object.defineProperty(properties, "prototype", { writable: false });
150412
- for (const [name, method] of Object.entries(methods)) {
150413
- Object.defineProperty(properties, name, { value: method, writable: true, configurable: true });
150414
- }
150415
- const prototypeMethods = {
150416
- toString: createSandboxClosure({
150417
- sandbox: true,
150418
- name: "toString",
150419
- length: 0,
150420
- call: (_args, context) => budget.allocateString(`[object ${typeTag(context?.thisValue)}]`)
150421
- }),
150422
- valueOf: createSandboxClosure({
150423
- sandbox: true,
150424
- name: "valueOf",
150425
- length: 0,
150426
- call: (_args, context) => {
150427
- const value = requireReceiver(context?.thisValue);
150428
- if (typeof value !== "object")
150429
- throw new TypeError("Object primitive boxing is not supported.");
150430
- return value;
150431
- }
150432
- }),
150433
- hasOwnProperty: createSandboxClosure({
150434
- sandbox: true,
150435
- name: "hasOwnProperty",
150436
- length: 1,
150437
- call: async ([key3], context) => hasOwnSandboxProperty(
150438
- requireReceiver(context?.thisValue),
150439
- await sandboxString(key3, budget, context),
150440
- false
150441
- )
150442
- }),
150443
- propertyIsEnumerable: createSandboxClosure({
150444
- sandbox: true,
150445
- name: "propertyIsEnumerable",
150446
- length: 1,
150447
- call: async ([key3], context) => hasOwnSandboxProperty(
150448
- requireReceiver(context?.thisValue),
150449
- await sandboxString(key3, budget, context),
150450
- true
150451
- )
150452
- }),
150453
- isPrototypeOf: createSandboxClosure({
150454
- sandbox: true,
150455
- name: "isPrototypeOf",
150456
- length: 1,
150457
- call: ([value], context) => {
150458
- if (typeof value !== "object" || value === null) return false;
150459
- const receiver = requireReceiver(context?.thisValue);
150460
- let depth = 0;
150461
- for (let current = getSandboxPrototype(value, budget); current !== null; current = getSandboxPrototype(current, budget)) {
150462
- budget.visitNode();
150463
- assertSandboxDataDepth(depth++);
150464
- if (current === receiver) return true;
150465
- }
150466
- return false;
150467
- }
150468
- })
150469
- };
150470
- for (const [name, method] of Object.entries(prototypeMethods)) {
150471
- Object.defineProperty(prototype, name, { value: method, writable: true, configurable: true });
150472
- }
150473
- markDescriptorObject(prototype);
150474
- installObjectPrototype(budget, prototype, constructor);
150475
- return constructor;
150476
- }
150477
- function requireReceiver(value) {
150478
- if (value === null || value === void 0)
150479
- throw new TypeError("Object method requires a non-null receiver.");
150480
- return value;
150481
- }
150482
- function hasOwnSandboxProperty(value, key3, enumerable) {
150483
- requireReceiver(value);
150484
- if (isGuestHostObject(value)) return hasHostObjectMember(value, key3, enumerable);
150485
- let properties;
150486
- if (isGuestClosure(value)) properties = materializeFunctionProperties(value);
150487
- else if (isSandboxClosure(value)) {
150488
- if (key3 === "length" || key3 === "name") return !enumerable;
150489
- properties = value.properties ?? /* @__PURE__ */ Object.create(null);
150490
- } else if (isSandboxMap(value) || isSandboxSet(value) || isSandboxPromise(value) || isSandboxGenerator(value))
150491
- return false;
150492
- else if (isSandboxRegex(value)) return key3 === "lastIndex" && !enumerable;
150493
- else properties = Object(value);
150494
- const descriptor = Object.getOwnPropertyDescriptor(properties, key3);
150495
- return descriptor !== void 0 && (!enumerable || descriptor.enumerable === true);
150496
- }
150497
- function typeTag(value) {
150498
- if (value === void 0) return "Undefined";
150499
- if (value === null) return "Null";
150500
- if (typeof value === "string") return "String";
150501
- if (typeof value === "number") return "Number";
150502
- if (typeof value === "boolean") return "Boolean";
150503
- if (isSandboxClosure(value)) {
150504
- while (value.boundTarget !== void 0) value = value.boundTarget;
150505
- return value.generator ? "GeneratorFunction" : value.async ? "AsyncFunction" : "Function";
150506
- }
150507
- if (Array.isArray(value)) return "Array";
150508
- if (isSandboxDate(value)) return "Date";
150509
- if (isSandboxErrorConstructorInstance(value, "Error")) return "Error";
150510
- if (isSandboxRegex(value)) return "RegExp";
150511
- if (isSandboxMap(value)) return "Map";
150512
- if (isSandboxSet(value)) return "Set";
150513
- if (isSandboxPromise(value)) return "Promise";
150514
- if (isSandboxGenerator(value)) return "Generator";
150515
- if (isFloat32Array(value)) return "Float32Array";
150516
- return "Object";
150517
- }
150518
- var init_object2 = __esm({
150519
- "packages/safe-js/src/interp/globals/object.ts"() {
150520
- "use strict";
150521
- init_graph_depth();
150522
- init_date();
150523
- init_exceptions();
150524
- init_float32();
150525
- init_host_capabilities();
150526
- init_object_model();
150527
- init_string_coercion();
150528
- init_values();
150529
- }
150530
- });
150531
-
150532
150579
  // packages/safe-js/src/interp/globals/object-array.ts
150533
150580
  function createObjectArrayGlobals(options) {
150534
150581
  return {