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