@ruby/wasm-wasi 2.3.0-2023-12-04-a → 2.3.0-2023-12-05-a

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.
@@ -3101,8 +3101,27 @@
3101
3101
  class RbExceptionFormatter {
3102
3102
  constructor() {
3103
3103
  this.literalsCache = null;
3104
+ this.isFormmatting = false;
3104
3105
  }
3105
3106
  format(error, vm, privateObject) {
3107
+ // All Ruby exceptions raised during formatting exception message should
3108
+ // be caught and return a fallback message.
3109
+ // Therefore, we don't need to worry about infinite recursion here ideally
3110
+ // but checking re-entrancy just in case.
3111
+ class RbExceptionFormatterError extends Error {
3112
+ }
3113
+ if (this.isFormmatting) {
3114
+ throw new RbExceptionFormatterError("Unexpected exception occurred during formatting exception message");
3115
+ }
3116
+ this.isFormmatting = true;
3117
+ try {
3118
+ return this._format(error, vm, privateObject);
3119
+ }
3120
+ finally {
3121
+ this.isFormmatting = false;
3122
+ }
3123
+ }
3124
+ _format(error, vm, privateObject) {
3106
3125
  const [zeroLiteral, oneLiteral, newLineLiteral] = (() => {
3107
3126
  if (this.literalsCache == null) {
3108
3127
  const zeroOneNewLine = [
@@ -3117,18 +3136,43 @@
3117
3136
  return this.literalsCache;
3118
3137
  }
3119
3138
  })();
3120
- const backtrace = error.call("backtrace");
3139
+ let className;
3140
+ let backtrace;
3141
+ let message;
3142
+ try {
3143
+ className = error.call("class").toString();
3144
+ }
3145
+ catch (e) {
3146
+ className = "unknown";
3147
+ }
3148
+ try {
3149
+ message = error.toString();
3150
+ }
3151
+ catch (e) {
3152
+ message = "unknown";
3153
+ }
3154
+ try {
3155
+ backtrace = error.call("backtrace");
3156
+ }
3157
+ catch (e) {
3158
+ return this.formatString(className, message);
3159
+ }
3121
3160
  if (backtrace.call("nil?").toString() === "true") {
3122
- return this.formatString(error.call("class").toString(), error.toString());
3161
+ return this.formatString(className, message);
3162
+ }
3163
+ try {
3164
+ const firstLine = backtrace.call("at", zeroLiteral);
3165
+ const restLines = backtrace
3166
+ .call("drop", oneLiteral)
3167
+ .call("join", newLineLiteral);
3168
+ return this.formatString(className, message, [
3169
+ firstLine.toString(),
3170
+ restLines.toString(),
3171
+ ]);
3172
+ }
3173
+ catch (e) {
3174
+ return this.formatString(className, message);
3123
3175
  }
3124
- const firstLine = backtrace.call("at", zeroLiteral);
3125
- const restLines = backtrace
3126
- .call("drop", oneLiteral)
3127
- .call("join", newLineLiteral);
3128
- return this.formatString(error.call("class").toString(), error.toString(), [
3129
- firstLine.toString(),
3130
- restLines.toString(),
3131
- ]);
3132
3176
  }
3133
3177
  formatString(klass, message, backtrace) {
3134
3178
  if (backtrace) {
@@ -3059,8 +3059,27 @@
3059
3059
  class RbExceptionFormatter {
3060
3060
  constructor() {
3061
3061
  this.literalsCache = null;
3062
+ this.isFormmatting = false;
3062
3063
  }
3063
3064
  format(error, vm, privateObject) {
3065
+ // All Ruby exceptions raised during formatting exception message should
3066
+ // be caught and return a fallback message.
3067
+ // Therefore, we don't need to worry about infinite recursion here ideally
3068
+ // but checking re-entrancy just in case.
3069
+ class RbExceptionFormatterError extends Error {
3070
+ }
3071
+ if (this.isFormmatting) {
3072
+ throw new RbExceptionFormatterError("Unexpected exception occurred during formatting exception message");
3073
+ }
3074
+ this.isFormmatting = true;
3075
+ try {
3076
+ return this._format(error, vm, privateObject);
3077
+ }
3078
+ finally {
3079
+ this.isFormmatting = false;
3080
+ }
3081
+ }
3082
+ _format(error, vm, privateObject) {
3064
3083
  const [zeroLiteral, oneLiteral, newLineLiteral] = (() => {
3065
3084
  if (this.literalsCache == null) {
3066
3085
  const zeroOneNewLine = [
@@ -3075,18 +3094,43 @@
3075
3094
  return this.literalsCache;
3076
3095
  }
3077
3096
  })();
3078
- const backtrace = error.call("backtrace");
3097
+ let className;
3098
+ let backtrace;
3099
+ let message;
3100
+ try {
3101
+ className = error.call("class").toString();
3102
+ }
3103
+ catch (e) {
3104
+ className = "unknown";
3105
+ }
3106
+ try {
3107
+ message = error.toString();
3108
+ }
3109
+ catch (e) {
3110
+ message = "unknown";
3111
+ }
3112
+ try {
3113
+ backtrace = error.call("backtrace");
3114
+ }
3115
+ catch (e) {
3116
+ return this.formatString(className, message);
3117
+ }
3079
3118
  if (backtrace.call("nil?").toString() === "true") {
3080
- return this.formatString(error.call("class").toString(), error.toString());
3119
+ return this.formatString(className, message);
3120
+ }
3121
+ try {
3122
+ const firstLine = backtrace.call("at", zeroLiteral);
3123
+ const restLines = backtrace
3124
+ .call("drop", oneLiteral)
3125
+ .call("join", newLineLiteral);
3126
+ return this.formatString(className, message, [
3127
+ firstLine.toString(),
3128
+ restLines.toString(),
3129
+ ]);
3130
+ }
3131
+ catch (e) {
3132
+ return this.formatString(className, message);
3081
3133
  }
3082
- const firstLine = backtrace.call("at", zeroLiteral);
3083
- const restLines = backtrace
3084
- .call("drop", oneLiteral)
3085
- .call("join", newLineLiteral);
3086
- return this.formatString(error.call("class").toString(), error.toString(), [
3087
- firstLine.toString(),
3088
- restLines.toString(),
3089
- ]);
3090
3134
  }
3091
3135
  formatString(klass, message, backtrace) {
3092
3136
  if (backtrace) {
@@ -169,7 +169,9 @@ type RubyVMPrivate = {
169
169
  };
170
170
  declare class RbExceptionFormatter {
171
171
  private literalsCache;
172
+ private isFormmatting;
172
173
  format(error: RbValue, vm: RubyVM, privateObject: RubyVMPrivate): string;
174
+ private _format;
173
175
  formatString(klass: string, message: string, backtrace?: [string, string]): string;
174
176
  }
175
177
  /**
package/dist/cjs/index.js CHANGED
@@ -470,8 +470,27 @@ var ruby_tag_type;
470
470
  class RbExceptionFormatter {
471
471
  constructor() {
472
472
  this.literalsCache = null;
473
+ this.isFormmatting = false;
473
474
  }
474
475
  format(error, vm, privateObject) {
476
+ // All Ruby exceptions raised during formatting exception message should
477
+ // be caught and return a fallback message.
478
+ // Therefore, we don't need to worry about infinite recursion here ideally
479
+ // but checking re-entrancy just in case.
480
+ class RbExceptionFormatterError extends Error {
481
+ }
482
+ if (this.isFormmatting) {
483
+ throw new RbExceptionFormatterError("Unexpected exception occurred during formatting exception message");
484
+ }
485
+ this.isFormmatting = true;
486
+ try {
487
+ return this._format(error, vm, privateObject);
488
+ }
489
+ finally {
490
+ this.isFormmatting = false;
491
+ }
492
+ }
493
+ _format(error, vm, privateObject) {
475
494
  const [zeroLiteral, oneLiteral, newLineLiteral] = (() => {
476
495
  if (this.literalsCache == null) {
477
496
  const zeroOneNewLine = [
@@ -486,18 +505,43 @@ class RbExceptionFormatter {
486
505
  return this.literalsCache;
487
506
  }
488
507
  })();
489
- const backtrace = error.call("backtrace");
508
+ let className;
509
+ let backtrace;
510
+ let message;
511
+ try {
512
+ className = error.call("class").toString();
513
+ }
514
+ catch (e) {
515
+ className = "unknown";
516
+ }
517
+ try {
518
+ message = error.toString();
519
+ }
520
+ catch (e) {
521
+ message = "unknown";
522
+ }
523
+ try {
524
+ backtrace = error.call("backtrace");
525
+ }
526
+ catch (e) {
527
+ return this.formatString(className, message);
528
+ }
490
529
  if (backtrace.call("nil?").toString() === "true") {
491
- return this.formatString(error.call("class").toString(), error.toString());
530
+ return this.formatString(className, message);
531
+ }
532
+ try {
533
+ const firstLine = backtrace.call("at", zeroLiteral);
534
+ const restLines = backtrace
535
+ .call("drop", oneLiteral)
536
+ .call("join", newLineLiteral);
537
+ return this.formatString(className, message, [
538
+ firstLine.toString(),
539
+ restLines.toString(),
540
+ ]);
541
+ }
542
+ catch (e) {
543
+ return this.formatString(className, message);
492
544
  }
493
- const firstLine = backtrace.call("at", zeroLiteral);
494
- const restLines = backtrace
495
- .call("drop", oneLiteral)
496
- .call("join", newLineLiteral);
497
- return this.formatString(error.call("class").toString(), error.toString(), [
498
- firstLine.toString(),
499
- restLines.toString(),
500
- ]);
501
545
  }
502
546
  formatString(klass, message, backtrace) {
503
547
  if (backtrace) {
@@ -169,7 +169,9 @@ type RubyVMPrivate = {
169
169
  };
170
170
  declare class RbExceptionFormatter {
171
171
  private literalsCache;
172
+ private isFormmatting;
172
173
  format(error: RbValue, vm: RubyVM, privateObject: RubyVMPrivate): string;
174
+ private _format;
173
175
  formatString(klass: string, message: string, backtrace?: [string, string]): string;
174
176
  }
175
177
  /**
package/dist/esm/index.js CHANGED
@@ -464,8 +464,27 @@ var ruby_tag_type;
464
464
  class RbExceptionFormatter {
465
465
  constructor() {
466
466
  this.literalsCache = null;
467
+ this.isFormmatting = false;
467
468
  }
468
469
  format(error, vm, privateObject) {
470
+ // All Ruby exceptions raised during formatting exception message should
471
+ // be caught and return a fallback message.
472
+ // Therefore, we don't need to worry about infinite recursion here ideally
473
+ // but checking re-entrancy just in case.
474
+ class RbExceptionFormatterError extends Error {
475
+ }
476
+ if (this.isFormmatting) {
477
+ throw new RbExceptionFormatterError("Unexpected exception occurred during formatting exception message");
478
+ }
479
+ this.isFormmatting = true;
480
+ try {
481
+ return this._format(error, vm, privateObject);
482
+ }
483
+ finally {
484
+ this.isFormmatting = false;
485
+ }
486
+ }
487
+ _format(error, vm, privateObject) {
469
488
  const [zeroLiteral, oneLiteral, newLineLiteral] = (() => {
470
489
  if (this.literalsCache == null) {
471
490
  const zeroOneNewLine = [
@@ -480,18 +499,43 @@ class RbExceptionFormatter {
480
499
  return this.literalsCache;
481
500
  }
482
501
  })();
483
- const backtrace = error.call("backtrace");
502
+ let className;
503
+ let backtrace;
504
+ let message;
505
+ try {
506
+ className = error.call("class").toString();
507
+ }
508
+ catch (e) {
509
+ className = "unknown";
510
+ }
511
+ try {
512
+ message = error.toString();
513
+ }
514
+ catch (e) {
515
+ message = "unknown";
516
+ }
517
+ try {
518
+ backtrace = error.call("backtrace");
519
+ }
520
+ catch (e) {
521
+ return this.formatString(className, message);
522
+ }
484
523
  if (backtrace.call("nil?").toString() === "true") {
485
- return this.formatString(error.call("class").toString(), error.toString());
524
+ return this.formatString(className, message);
525
+ }
526
+ try {
527
+ const firstLine = backtrace.call("at", zeroLiteral);
528
+ const restLines = backtrace
529
+ .call("drop", oneLiteral)
530
+ .call("join", newLineLiteral);
531
+ return this.formatString(className, message, [
532
+ firstLine.toString(),
533
+ restLines.toString(),
534
+ ]);
535
+ }
536
+ catch (e) {
537
+ return this.formatString(className, message);
486
538
  }
487
- const firstLine = backtrace.call("at", zeroLiteral);
488
- const restLines = backtrace
489
- .call("drop", oneLiteral)
490
- .call("join", newLineLiteral);
491
- return this.formatString(error.call("class").toString(), error.toString(), [
492
- firstLine.toString(),
493
- restLines.toString(),
494
- ]);
495
539
  }
496
540
  formatString(klass, message, backtrace) {
497
541
  if (backtrace) {
package/dist/index.umd.js CHANGED
@@ -1065,8 +1065,27 @@
1065
1065
  class RbExceptionFormatter {
1066
1066
  constructor() {
1067
1067
  this.literalsCache = null;
1068
+ this.isFormmatting = false;
1068
1069
  }
1069
1070
  format(error, vm, privateObject) {
1071
+ // All Ruby exceptions raised during formatting exception message should
1072
+ // be caught and return a fallback message.
1073
+ // Therefore, we don't need to worry about infinite recursion here ideally
1074
+ // but checking re-entrancy just in case.
1075
+ class RbExceptionFormatterError extends Error {
1076
+ }
1077
+ if (this.isFormmatting) {
1078
+ throw new RbExceptionFormatterError("Unexpected exception occurred during formatting exception message");
1079
+ }
1080
+ this.isFormmatting = true;
1081
+ try {
1082
+ return this._format(error, vm, privateObject);
1083
+ }
1084
+ finally {
1085
+ this.isFormmatting = false;
1086
+ }
1087
+ }
1088
+ _format(error, vm, privateObject) {
1070
1089
  const [zeroLiteral, oneLiteral, newLineLiteral] = (() => {
1071
1090
  if (this.literalsCache == null) {
1072
1091
  const zeroOneNewLine = [
@@ -1081,18 +1100,43 @@
1081
1100
  return this.literalsCache;
1082
1101
  }
1083
1102
  })();
1084
- const backtrace = error.call("backtrace");
1103
+ let className;
1104
+ let backtrace;
1105
+ let message;
1106
+ try {
1107
+ className = error.call("class").toString();
1108
+ }
1109
+ catch (e) {
1110
+ className = "unknown";
1111
+ }
1112
+ try {
1113
+ message = error.toString();
1114
+ }
1115
+ catch (e) {
1116
+ message = "unknown";
1117
+ }
1118
+ try {
1119
+ backtrace = error.call("backtrace");
1120
+ }
1121
+ catch (e) {
1122
+ return this.formatString(className, message);
1123
+ }
1085
1124
  if (backtrace.call("nil?").toString() === "true") {
1086
- return this.formatString(error.call("class").toString(), error.toString());
1125
+ return this.formatString(className, message);
1126
+ }
1127
+ try {
1128
+ const firstLine = backtrace.call("at", zeroLiteral);
1129
+ const restLines = backtrace
1130
+ .call("drop", oneLiteral)
1131
+ .call("join", newLineLiteral);
1132
+ return this.formatString(className, message, [
1133
+ firstLine.toString(),
1134
+ restLines.toString(),
1135
+ ]);
1136
+ }
1137
+ catch (e) {
1138
+ return this.formatString(className, message);
1087
1139
  }
1088
- const firstLine = backtrace.call("at", zeroLiteral);
1089
- const restLines = backtrace
1090
- .call("drop", oneLiteral)
1091
- .call("join", newLineLiteral);
1092
- return this.formatString(error.call("class").toString(), error.toString(), [
1093
- firstLine.toString(),
1094
- restLines.toString(),
1095
- ]);
1096
1140
  }
1097
1141
  formatString(klass, message, backtrace) {
1098
1142
  if (backtrace) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruby/wasm-wasi",
3
- "version": "2.3.0-2023-12-04-a",
3
+ "version": "2.3.0-2023-12-05-a",
4
4
  "description": "WebAssembly port of CRuby with WASI",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",