@poe-platform/safe-js 0.1.160 → 0.1.162

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.
@@ -16497,10 +16497,12 @@ async function evaluateSpreadElement(node, context) {
16497
16497
  if (typeof next !== "object" || next === null) {
16498
16498
  throw new TypeError("Iterator result must be an object.");
16499
16499
  }
16500
- if ((await readIteratorResult(iterator, next, "done")).value) {
16500
+ const done = iterator.readResultProperty === void 0 ? next.done : (await readIteratorResult(iterator, next, "done")).value;
16501
+ if (done) {
16501
16502
  break;
16502
16503
  }
16503
- spreadValues.push((await readIteratorResult(iterator, next, "value")).value);
16504
+ const item = iterator.readResultProperty === void 0 ? next.value : (await readIteratorResult(iterator, next, "value")).value;
16505
+ spreadValues.push(item);
16504
16506
  context.budget.allocateArrayLength(spreadValues.length);
16505
16507
  }
16506
16508
  return {
@@ -18639,7 +18641,18 @@ function createObjectGlobal(methods, budget) {
18639
18641
  sandbox: true,
18640
18642
  name: "toString",
18641
18643
  length: 0,
18642
- call: (_args, context) => budget.allocateString(`[object ${typeTag(context?.thisValue)}]`)
18644
+ call: (_args, context) => {
18645
+ const receiver = context?.thisValue;
18646
+ if (receiver === void 0 || receiver === null)
18647
+ return budget.allocateString(`[object ${typeTag(receiver)}]`);
18648
+ const object = construct([receiver]);
18649
+ const descriptor = isGuestHostObject(object) ? void 0 : getSandboxPropertyDescriptor(object, Symbol.toStringTag, budget);
18650
+ const fallback = typeTag(object, descriptor !== void 0 || hasExplicitSandboxPrototype(object));
18651
+ const finish = (tag2) => budget.allocateString(`[object ${typeof tag2 === "string" ? tag2 : fallback}]`);
18652
+ if (descriptor === void 0) return finish(void 0);
18653
+ const tag = readPropertyDescriptor(descriptor, object, context, true);
18654
+ return tag instanceof Promise ? tag.then(finish) : finish(tag);
18655
+ }
18643
18656
  }),
18644
18657
  valueOf: createSandboxClosure({
18645
18658
  sandbox: true,
@@ -18714,14 +18727,16 @@ function hasOwnSandboxProperty(value, key, enumerable) {
18714
18727
  const descriptor = Object.getOwnPropertyDescriptor(properties, key);
18715
18728
  return descriptor !== void 0 && (!enumerable || descriptor.enumerable === true);
18716
18729
  }
18717
- function typeTag(value) {
18730
+ function typeTag(value, builtinOnly = false) {
18718
18731
  if (isSandboxBox(value)) value = boxedValue(value);
18719
18732
  if (value === void 0) return "Undefined";
18720
18733
  if (value === null) return "Null";
18721
18734
  if (typeof value === "string") return "String";
18722
18735
  if (typeof value === "number") return "Number";
18723
18736
  if (typeof value === "boolean") return "Boolean";
18737
+ if (isSandboxArguments(value)) return "Arguments";
18724
18738
  if (isSandboxClosure(value)) {
18739
+ if (builtinOnly) return "Function";
18725
18740
  while (value.boundTarget !== void 0) value = value.boundTarget;
18726
18741
  return value.generator ? "GeneratorFunction" : value.async ? "AsyncFunction" : "Function";
18727
18742
  }
@@ -18729,6 +18744,7 @@ function typeTag(value) {
18729
18744
  if (isSandboxDate(value)) return "Date";
18730
18745
  if (isSandboxErrorConstructorInstance(value, "Error")) return "Error";
18731
18746
  if (isSandboxRegex(value)) return "RegExp";
18747
+ if (builtinOnly) return "Object";
18732
18748
  if (isSandboxMap(value)) return "Map";
18733
18749
  if (isSandboxSet(value)) return "Set";
18734
18750
  if (isSandboxCollectionIterator(value)) return collectionIteratorState(value).collectionKind === "map" ? "Map Iterator" : "Set Iterator";
@@ -25395,351 +25411,6 @@ var AS010Scanner = class {
25395
25411
  }
25396
25412
  };
25397
25413
 
25398
- // packages/safe-js/src/lint/rules/AS011.ts
25399
- var FORBIDDEN_PROPERTY_NAMES = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
25400
- var MESSAGE2 = "Property access to '__proto__', 'prototype', and 'constructor' is not allowed.";
25401
- function AS011(source, options = {}) {
25402
- return new AS011Scanner(options.filename ?? "<input>").scan(source);
25403
- }
25404
- var AS011Scanner = class {
25405
- constructor(filename) {
25406
- this.filename = filename;
25407
- }
25408
- filename;
25409
- diagnostics = [];
25410
- scan(source) {
25411
- this.visitModule(parseModule(source, this.filename));
25412
- return this.diagnostics;
25413
- }
25414
- visitModule(node) {
25415
- for (const statement of node.body) {
25416
- this.visitStatement(statement);
25417
- }
25418
- }
25419
- visitStatement(node) {
25420
- if (node.type === "ClassDeclaration") {
25421
- visitClassElements(node, (expression) => this.visitExpression(expression), (statement) => this.visitStatement(statement));
25422
- return;
25423
- }
25424
- switch (node.type) {
25425
- case "FunctionDeclaration":
25426
- this.visitArrowFunction(node);
25427
- return;
25428
- case "BlockStatement":
25429
- for (const statement of node.body) {
25430
- this.visitStatement(statement);
25431
- }
25432
- return;
25433
- case "ExpressionStatement":
25434
- this.visitExpression(node.expression);
25435
- return;
25436
- case "IfStatement":
25437
- this.visitIfStatement(node);
25438
- return;
25439
- case "ForStatement":
25440
- this.visitForStatement(node);
25441
- return;
25442
- case "ForInStatement":
25443
- case "ForOfStatement":
25444
- this.visitForOfStatement(node);
25445
- return;
25446
- case "WhileStatement":
25447
- case "DoWhileStatement":
25448
- this.visitExpression(node.test);
25449
- this.visitStatement(node.body);
25450
- return;
25451
- case "TryStatement":
25452
- this.visitTryStatement(node);
25453
- return;
25454
- case "VariableDeclaration":
25455
- this.visitVariableDeclaration(node);
25456
- return;
25457
- case "ReturnStatement":
25458
- this.visitReturnStatement(node);
25459
- return;
25460
- case "ThrowStatement":
25461
- this.visitThrowStatement(node);
25462
- return;
25463
- case "ExportNamedDeclaration":
25464
- this.visitVariableDeclaration(node.declaration);
25465
- return;
25466
- case "ExportDefaultDeclaration":
25467
- if (node.declaration.type === "ClassDeclaration" || node.declaration.type === "FunctionDeclaration") this.visitStatement(node.declaration);
25468
- else this.visitExpression(node.declaration);
25469
- return;
25470
- case "ImportDeclaration":
25471
- case "BreakStatement":
25472
- case "ContinueStatement":
25473
- return;
25474
- }
25475
- }
25476
- visitIfStatement(node) {
25477
- this.visitExpression(node.test);
25478
- this.visitStatement(node.consequent);
25479
- if (node.alternate !== void 0) {
25480
- this.visitStatement(node.alternate);
25481
- }
25482
- }
25483
- visitForStatement(node) {
25484
- if (node.init !== void 0) {
25485
- if (node.init.type === "VariableDeclaration") {
25486
- this.visitVariableDeclaration(node.init);
25487
- } else {
25488
- this.visitExpression(node.init);
25489
- }
25490
- }
25491
- if (node.test !== void 0) {
25492
- this.visitExpression(node.test);
25493
- }
25494
- if (node.update !== void 0) {
25495
- this.visitExpression(node.update);
25496
- }
25497
- this.visitStatement(node.body);
25498
- }
25499
- visitForOfStatement(node) {
25500
- if (node.left.type === "VariableDeclaration") {
25501
- this.visitVariableDeclaration(node.left);
25502
- } else {
25503
- this.visitAssignmentTarget(node.left);
25504
- }
25505
- this.visitExpression(node.right);
25506
- this.visitStatement(node.body);
25507
- }
25508
- visitTryStatement(node) {
25509
- this.visitStatement(node.block);
25510
- if (node.handler !== void 0) {
25511
- this.visitCatchClause(node.handler);
25512
- }
25513
- if (node.finalizer !== void 0) {
25514
- this.visitStatement(node.finalizer);
25515
- }
25516
- }
25517
- visitCatchClause(node) {
25518
- if (node.param !== void 0) {
25519
- this.visitAssignmentTarget(node.param);
25520
- }
25521
- this.visitStatement(node.body);
25522
- }
25523
- visitVariableDeclaration(node) {
25524
- for (const declarator of node.declarations) {
25525
- this.visitVariableDeclarator(declarator);
25526
- }
25527
- }
25528
- visitVariableDeclarator(node) {
25529
- this.visitBindingTarget(node.id);
25530
- if (node.init !== void 0) {
25531
- this.visitExpression(node.init);
25532
- }
25533
- }
25534
- visitReturnStatement(node) {
25535
- if (node.argument !== void 0) {
25536
- this.visitExpression(node.argument);
25537
- }
25538
- }
25539
- visitThrowStatement(node) {
25540
- this.visitExpression(node.argument);
25541
- }
25542
- visitExpression(node) {
25543
- if (node.type === "ClassExpression") {
25544
- visitClassElements(node, (expression) => this.visitExpression(expression), (statement) => this.visitStatement(statement));
25545
- return;
25546
- }
25547
- switch (node.type) {
25548
- case "YieldExpression":
25549
- if (node.argument !== void 0) {
25550
- this.visitExpression(node.argument);
25551
- }
25552
- return;
25553
- case "FunctionExpression":
25554
- case "ArrowFunctionExpression":
25555
- this.visitArrowFunction(node);
25556
- return;
25557
- case "AwaitExpression":
25558
- this.visitExpression(node.argument);
25559
- return;
25560
- case "ArrayExpression":
25561
- this.visitArrayExpression(node);
25562
- return;
25563
- case "ObjectExpression":
25564
- this.visitObjectExpression(node);
25565
- return;
25566
- case "UnaryExpression":
25567
- this.visitUnaryExpression(node);
25568
- return;
25569
- case "BinaryExpression":
25570
- case "LogicalExpression":
25571
- this.visitBinaryLikeExpression(node);
25572
- return;
25573
- case "ConditionalExpression":
25574
- this.visitConditionalExpression(node);
25575
- return;
25576
- case "MemberExpression":
25577
- this.visitMemberExpression(node);
25578
- return;
25579
- case "AssignmentExpression":
25580
- this.visitAssignmentExpression(node);
25581
- return;
25582
- case "CallExpression":
25583
- this.visitCallExpression(node);
25584
- return;
25585
- case "TemplateLiteral":
25586
- this.visitTemplateLiteral(node);
25587
- return;
25588
- case "Identifier":
25589
- case "BooleanLiteral":
25590
- case "NullLiteral":
25591
- case "NumericLiteral":
25592
- case "StringLiteral":
25593
- case "UndefinedLiteral":
25594
- return;
25595
- }
25596
- }
25597
- visitArrowFunction(node) {
25598
- for (const parameter of node.params) {
25599
- this.visitBindingTarget(parameter);
25600
- }
25601
- if (node.body.type === "BlockStatement") {
25602
- for (const statement of node.body.body) {
25603
- this.visitStatement(statement);
25604
- }
25605
- return;
25606
- }
25607
- this.visitExpression(node.body);
25608
- }
25609
- visitArrayExpression(node) {
25610
- for (const element of node.elements) {
25611
- if (element === null) {
25612
- continue;
25613
- }
25614
- if (element.type === "SpreadElement") {
25615
- this.visitExpression(element.argument);
25616
- continue;
25617
- }
25618
- this.visitExpression(element);
25619
- }
25620
- }
25621
- visitObjectExpression(node) {
25622
- for (const property of node.properties) {
25623
- if (property.type === "SpreadElement") {
25624
- this.visitExpression(property.argument);
25625
- continue;
25626
- }
25627
- this.visitProperty(property);
25628
- }
25629
- }
25630
- visitProperty(node) {
25631
- if (node.computed) {
25632
- this.visitExpression(node.key);
25633
- }
25634
- this.visitExpression(node.value);
25635
- }
25636
- visitUnaryExpression(node) {
25637
- this.visitExpression(node.argument);
25638
- }
25639
- visitBinaryLikeExpression(node) {
25640
- this.visitExpression(node.left);
25641
- this.visitExpression(node.right);
25642
- }
25643
- visitConditionalExpression(node) {
25644
- this.visitExpression(node.test);
25645
- this.visitExpression(node.consequent);
25646
- this.visitExpression(node.alternate);
25647
- }
25648
- visitMemberExpression(node) {
25649
- this.visitExpression(node.object);
25650
- if (this.isForbiddenMemberProperty(node)) {
25651
- this.report(node.property.span);
25652
- }
25653
- this.visitExpression(node.property);
25654
- }
25655
- visitAssignmentExpression(node) {
25656
- this.visitAssignmentTarget(node.left);
25657
- this.visitExpression(node.right);
25658
- }
25659
- visitCallExpression(node) {
25660
- this.visitExpression(node.callee);
25661
- for (const argument of node.arguments) {
25662
- if (argument.type === "SpreadElement") {
25663
- this.visitExpression(argument.argument);
25664
- continue;
25665
- }
25666
- this.visitExpression(argument);
25667
- }
25668
- }
25669
- visitTemplateLiteral(node) {
25670
- for (const expression of node.expressions) {
25671
- this.visitExpression(expression);
25672
- }
25673
- }
25674
- visitAssignmentTarget(node) {
25675
- switch (node.type) {
25676
- case "Identifier":
25677
- case "MetaProperty":
25678
- return;
25679
- case "MemberExpression":
25680
- this.visitMemberExpression(node);
25681
- return;
25682
- case "AssignmentPattern":
25683
- this.visitAssignmentTarget(node.left);
25684
- this.visitExpression(node.right);
25685
- return;
25686
- case "RestElement":
25687
- this.visitAssignmentTarget(node.argument);
25688
- return;
25689
- case "ArrayPattern":
25690
- for (const element of node.elements) {
25691
- if (element !== null) {
25692
- this.visitAssignmentTarget(element);
25693
- }
25694
- }
25695
- return;
25696
- case "ObjectPattern":
25697
- for (const property of node.properties) {
25698
- if (property.type === "RestElement") {
25699
- this.visitAssignmentTarget(property.argument);
25700
- continue;
25701
- }
25702
- if (property.computed) {
25703
- this.visitExpression(property.key);
25704
- }
25705
- this.visitAssignmentTarget(property.value);
25706
- }
25707
- return;
25708
- }
25709
- }
25710
- visitBindingTarget(node) {
25711
- switch (node.type) {
25712
- case "AssignmentPattern":
25713
- this.visitBindingTarget(node.left);
25714
- this.visitExpression(node.right);
25715
- return;
25716
- case "RestElement":
25717
- this.visitBindingTarget(node.argument);
25718
- return;
25719
- default:
25720
- this.visitAssignmentTarget(node);
25721
- return;
25722
- }
25723
- }
25724
- isForbiddenMemberProperty(node) {
25725
- if (!node.computed) {
25726
- return node.property.type === "Identifier" && FORBIDDEN_PROPERTY_NAMES.has(node.property.name);
25727
- }
25728
- return node.property.type === "StringLiteral" && FORBIDDEN_PROPERTY_NAMES.has(node.property.value);
25729
- }
25730
- report(span) {
25731
- this.diagnostics.push({
25732
- code: "AS011",
25733
- severity: "error",
25734
- message: MESSAGE2,
25735
- filename: this.filename,
25736
- line: span.start.line,
25737
- column: span.start.column,
25738
- span
25739
- });
25740
- }
25741
- };
25742
-
25743
25414
  // packages/safe-js/src/lint/rules/AS013.ts
25744
25415
  function AS013(source, options = {}) {
25745
25416
  const filename = options.filename ?? "<input>";
@@ -26712,7 +26383,7 @@ function patternTargetContainsAwait(node) {
26712
26383
  }
26713
26384
 
26714
26385
  // packages/safe-js/src/lint/rules/AS-destructure-null-default.ts
26715
- var MESSAGE3 = "Destructuring default values only apply to undefined, not null.";
26386
+ var MESSAGE2 = "Destructuring default values only apply to undefined, not null.";
26716
26387
  var HINT = "Handle null explicitly before destructuring or use ?? after binding.";
26717
26388
  function AS_DESTRUCTURE_NULL_DEFAULT(source, options = {}) {
26718
26389
  return new ASDestructureNullDefaultScanner(options.filename ?? "<input>").scan(source);
@@ -27116,7 +26787,7 @@ var ASDestructureNullDefaultScanner = class {
27116
26787
  this.diagnostics.push({
27117
26788
  code: "AS-DESTRUCTURE-NULL-DEFAULT",
27118
26789
  severity: "warning",
27119
- message: MESSAGE3,
26790
+ message: MESSAGE2,
27120
26791
  filename: this.filename,
27121
26792
  line: span.start.line,
27122
26793
  column: span.start.column,
@@ -31732,7 +31403,7 @@ var ASShadowGlobalScanner = class {
31732
31403
  };
31733
31404
 
31734
31405
  // packages/safe-js/src/lint/rules/AS-unbounded-loop.ts
31735
- var MESSAGE4 = "Unbounded loop or generator source has no static exit with break, return, or throw.";
31406
+ var MESSAGE3 = "Unbounded loop or generator source has no static exit with break, return, or throw.";
31736
31407
  function AS_UNBOUNDED_LOOP(source, options = {}) {
31737
31408
  return new ASUnboundedLoopScanner(options.filename ?? "<input>").scan(source);
31738
31409
  }
@@ -32042,7 +31713,7 @@ var ASUnboundedLoopScanner = class {
32042
31713
  this.diagnostics.push({
32043
31714
  code: "AS-UNBOUNDED-LOOP",
32044
31715
  severity: "warning",
32045
- message: MESSAGE4,
31716
+ message: MESSAGE3,
32046
31717
  filename: this.filename,
32047
31718
  line: node.span.start.line,
32048
31719
  column: node.span.start.column,
@@ -33048,7 +32719,6 @@ var RULES = [
33048
32719
  AS_MISSING_ASYNC,
33049
32720
  AS009,
33050
32721
  AS010,
33051
- AS011,
33052
32722
  AS013,
33053
32723
  AS015,
33054
32724
  AS_IMPORT_CYCLE,
@@ -36212,4 +35882,4 @@ export {
36212
35882
  FileSnapshotBackend,
36213
35883
  run
36214
35884
  };
36215
- //# sourceMappingURL=chunk-56X2TO4E.js.map
35885
+ //# sourceMappingURL=chunk-56XYHJCY.js.map