jslike 1.8.6 → 1.8.7

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.
@@ -2846,6 +2846,14 @@ export class Interpreter {
2846
2846
  for (const [name, method] of Object.entries(methods)) {
2847
2847
  classConstructor.prototype[name] = function(...args) {
2848
2848
  const result = interpreter.callMethodFunction(method, this, args, env, superClass);
2849
+ if (result && typeof result.then === 'function') {
2850
+ return result.then(resolved => {
2851
+ if (resolved && resolved.__explicitReturn) {
2852
+ return resolved.value;
2853
+ }
2854
+ return resolved;
2855
+ });
2856
+ }
2849
2857
  // Unwrap explicit return marker
2850
2858
  if (result && result.__explicitReturn) {
2851
2859
  return result.value;
@@ -2858,6 +2866,14 @@ export class Interpreter {
2858
2866
  for (const [name, method] of Object.entries(staticMethods)) {
2859
2867
  classConstructor[name] = function(...args) {
2860
2868
  const result = interpreter.callMethodFunction(method, classConstructor, args, env);
2869
+ if (result && typeof result.then === 'function') {
2870
+ return result.then(resolved => {
2871
+ if (resolved && resolved.__explicitReturn) {
2872
+ return resolved.value;
2873
+ }
2874
+ return resolved;
2875
+ });
2876
+ }
2861
2877
  // Unwrap explicit return marker
2862
2878
  if (result && result.__explicitReturn) {
2863
2879
  return result.value;
@@ -2974,7 +2990,8 @@ export class Interpreter {
2974
2990
  __params: funcNode.params,
2975
2991
  __body: funcNode.body,
2976
2992
  __env: env,
2977
- __className: className
2993
+ __className: className,
2994
+ __async: funcNode.async || false
2978
2995
  };
2979
2996
  return func;
2980
2997
  }
@@ -2992,6 +3009,22 @@ export class Interpreter {
2992
3009
 
2993
3010
  this.bindFunctionParameters(methodFunc.__params, args, funcEnv, thisContext);
2994
3011
 
3012
+ if (methodFunc.__async) {
3013
+ return (async () => {
3014
+ const result = await this.evaluateAsync(methodFunc.__body, funcEnv);
3015
+
3016
+ if (result instanceof ReturnValue) {
3017
+ return { __explicitReturn: true, value: result.value };
3018
+ }
3019
+
3020
+ if (result instanceof ThrowSignal) {
3021
+ throw result.value;
3022
+ }
3023
+
3024
+ return result;
3025
+ })();
3026
+ }
3027
+
2995
3028
  const result = this.evaluate(methodFunc.__body, funcEnv);
2996
3029
 
2997
3030
  if (result instanceof ReturnValue) {
package/dist/index.cjs CHANGED
@@ -13721,6 +13721,14 @@ var Interpreter = class _Interpreter {
13721
13721
  for (const [name, method] of Object.entries(methods)) {
13722
13722
  classConstructor.prototype[name] = function(...args) {
13723
13723
  const result = interpreter.callMethodFunction(method, this, args, env, superClass);
13724
+ if (result && typeof result.then === "function") {
13725
+ return result.then((resolved) => {
13726
+ if (resolved && resolved.__explicitReturn) {
13727
+ return resolved.value;
13728
+ }
13729
+ return resolved;
13730
+ });
13731
+ }
13724
13732
  if (result && result.__explicitReturn) {
13725
13733
  return result.value;
13726
13734
  }
@@ -13730,6 +13738,14 @@ var Interpreter = class _Interpreter {
13730
13738
  for (const [name, method] of Object.entries(staticMethods)) {
13731
13739
  classConstructor[name] = function(...args) {
13732
13740
  const result = interpreter.callMethodFunction(method, classConstructor, args, env);
13741
+ if (result && typeof result.then === "function") {
13742
+ return result.then((resolved) => {
13743
+ if (resolved && resolved.__explicitReturn) {
13744
+ return resolved.value;
13745
+ }
13746
+ return resolved;
13747
+ });
13748
+ }
13733
13749
  if (result && result.__explicitReturn) {
13734
13750
  return result.value;
13735
13751
  }
@@ -13828,7 +13844,8 @@ var Interpreter = class _Interpreter {
13828
13844
  __params: funcNode.params,
13829
13845
  __body: funcNode.body,
13830
13846
  __env: env,
13831
- __className: className
13847
+ __className: className,
13848
+ __async: funcNode.async || false
13832
13849
  };
13833
13850
  return func;
13834
13851
  }
@@ -13839,6 +13856,18 @@ var Interpreter = class _Interpreter {
13839
13856
  funcEnv.define("super", this.createSuperBinding(superClass, thisContext, true, afterSuper));
13840
13857
  }
13841
13858
  this.bindFunctionParameters(methodFunc.__params, args, funcEnv, thisContext);
13859
+ if (methodFunc.__async) {
13860
+ return (async () => {
13861
+ const result2 = await this.evaluateAsync(methodFunc.__body, funcEnv);
13862
+ if (result2 instanceof ReturnValue) {
13863
+ return { __explicitReturn: true, value: result2.value };
13864
+ }
13865
+ if (result2 instanceof ThrowSignal) {
13866
+ throw result2.value;
13867
+ }
13868
+ return result2;
13869
+ })();
13870
+ }
13842
13871
  const result = this.evaluate(methodFunc.__body, funcEnv);
13843
13872
  if (result instanceof ReturnValue) {
13844
13873
  return { __explicitReturn: true, value: result.value };
package/dist/index.d.cts CHANGED
@@ -15039,6 +15039,14 @@ class Interpreter {
15039
15039
  for (const [name, method] of Object.entries(methods)) {
15040
15040
  classConstructor.prototype[name] = function(...args) {
15041
15041
  const result = interpreter.callMethodFunction(method, this, args, env, superClass);
15042
+ if (result && typeof result.then === 'function') {
15043
+ return result.then(resolved => {
15044
+ if (resolved && resolved.__explicitReturn) {
15045
+ return resolved.value;
15046
+ }
15047
+ return resolved;
15048
+ });
15049
+ }
15042
15050
  // Unwrap explicit return marker
15043
15051
  if (result && result.__explicitReturn) {
15044
15052
  return result.value;
@@ -15051,6 +15059,14 @@ class Interpreter {
15051
15059
  for (const [name, method] of Object.entries(staticMethods)) {
15052
15060
  classConstructor[name] = function(...args) {
15053
15061
  const result = interpreter.callMethodFunction(method, classConstructor, args, env);
15062
+ if (result && typeof result.then === 'function') {
15063
+ return result.then(resolved => {
15064
+ if (resolved && resolved.__explicitReturn) {
15065
+ return resolved.value;
15066
+ }
15067
+ return resolved;
15068
+ });
15069
+ }
15054
15070
  // Unwrap explicit return marker
15055
15071
  if (result && result.__explicitReturn) {
15056
15072
  return result.value;
@@ -15167,7 +15183,8 @@ class Interpreter {
15167
15183
  __params: funcNode.params,
15168
15184
  __body: funcNode.body,
15169
15185
  __env: env,
15170
- __className: className
15186
+ __className: className,
15187
+ __async: funcNode.async || false
15171
15188
  };
15172
15189
  return func;
15173
15190
  }
@@ -15185,6 +15202,22 @@ class Interpreter {
15185
15202
 
15186
15203
  this.bindFunctionParameters(methodFunc.__params, args, funcEnv, thisContext);
15187
15204
 
15205
+ if (methodFunc.__async) {
15206
+ return (async () => {
15207
+ const result = await this.evaluateAsync(methodFunc.__body, funcEnv);
15208
+
15209
+ if (result instanceof ReturnValue) {
15210
+ return { __explicitReturn: true, value: result.value };
15211
+ }
15212
+
15213
+ if (result instanceof ThrowSignal) {
15214
+ throw result.value;
15215
+ }
15216
+
15217
+ return result;
15218
+ })();
15219
+ }
15220
+
15188
15221
  const result = this.evaluate(methodFunc.__body, funcEnv);
15189
15222
 
15190
15223
  if (result instanceof ReturnValue) {
package/dist/index.d.ts CHANGED
@@ -15039,6 +15039,14 @@ class Interpreter {
15039
15039
  for (const [name, method] of Object.entries(methods)) {
15040
15040
  classConstructor.prototype[name] = function(...args) {
15041
15041
  const result = interpreter.callMethodFunction(method, this, args, env, superClass);
15042
+ if (result && typeof result.then === 'function') {
15043
+ return result.then(resolved => {
15044
+ if (resolved && resolved.__explicitReturn) {
15045
+ return resolved.value;
15046
+ }
15047
+ return resolved;
15048
+ });
15049
+ }
15042
15050
  // Unwrap explicit return marker
15043
15051
  if (result && result.__explicitReturn) {
15044
15052
  return result.value;
@@ -15051,6 +15059,14 @@ class Interpreter {
15051
15059
  for (const [name, method] of Object.entries(staticMethods)) {
15052
15060
  classConstructor[name] = function(...args) {
15053
15061
  const result = interpreter.callMethodFunction(method, classConstructor, args, env);
15062
+ if (result && typeof result.then === 'function') {
15063
+ return result.then(resolved => {
15064
+ if (resolved && resolved.__explicitReturn) {
15065
+ return resolved.value;
15066
+ }
15067
+ return resolved;
15068
+ });
15069
+ }
15054
15070
  // Unwrap explicit return marker
15055
15071
  if (result && result.__explicitReturn) {
15056
15072
  return result.value;
@@ -15167,7 +15183,8 @@ class Interpreter {
15167
15183
  __params: funcNode.params,
15168
15184
  __body: funcNode.body,
15169
15185
  __env: env,
15170
- __className: className
15186
+ __className: className,
15187
+ __async: funcNode.async || false
15171
15188
  };
15172
15189
  return func;
15173
15190
  }
@@ -15185,6 +15202,22 @@ class Interpreter {
15185
15202
 
15186
15203
  this.bindFunctionParameters(methodFunc.__params, args, funcEnv, thisContext);
15187
15204
 
15205
+ if (methodFunc.__async) {
15206
+ return (async () => {
15207
+ const result = await this.evaluateAsync(methodFunc.__body, funcEnv);
15208
+
15209
+ if (result instanceof ReturnValue) {
15210
+ return { __explicitReturn: true, value: result.value };
15211
+ }
15212
+
15213
+ if (result instanceof ThrowSignal) {
15214
+ throw result.value;
15215
+ }
15216
+
15217
+ return result;
15218
+ })();
15219
+ }
15220
+
15188
15221
  const result = this.evaluate(methodFunc.__body, funcEnv);
15189
15222
 
15190
15223
  if (result instanceof ReturnValue) {
package/dist/index.js CHANGED
@@ -13687,6 +13687,14 @@ var Interpreter = class _Interpreter {
13687
13687
  for (const [name, method] of Object.entries(methods)) {
13688
13688
  classConstructor.prototype[name] = function(...args) {
13689
13689
  const result = interpreter.callMethodFunction(method, this, args, env, superClass);
13690
+ if (result && typeof result.then === "function") {
13691
+ return result.then((resolved) => {
13692
+ if (resolved && resolved.__explicitReturn) {
13693
+ return resolved.value;
13694
+ }
13695
+ return resolved;
13696
+ });
13697
+ }
13690
13698
  if (result && result.__explicitReturn) {
13691
13699
  return result.value;
13692
13700
  }
@@ -13696,6 +13704,14 @@ var Interpreter = class _Interpreter {
13696
13704
  for (const [name, method] of Object.entries(staticMethods)) {
13697
13705
  classConstructor[name] = function(...args) {
13698
13706
  const result = interpreter.callMethodFunction(method, classConstructor, args, env);
13707
+ if (result && typeof result.then === "function") {
13708
+ return result.then((resolved) => {
13709
+ if (resolved && resolved.__explicitReturn) {
13710
+ return resolved.value;
13711
+ }
13712
+ return resolved;
13713
+ });
13714
+ }
13699
13715
  if (result && result.__explicitReturn) {
13700
13716
  return result.value;
13701
13717
  }
@@ -13794,7 +13810,8 @@ var Interpreter = class _Interpreter {
13794
13810
  __params: funcNode.params,
13795
13811
  __body: funcNode.body,
13796
13812
  __env: env,
13797
- __className: className
13813
+ __className: className,
13814
+ __async: funcNode.async || false
13798
13815
  };
13799
13816
  return func;
13800
13817
  }
@@ -13805,6 +13822,18 @@ var Interpreter = class _Interpreter {
13805
13822
  funcEnv.define("super", this.createSuperBinding(superClass, thisContext, true, afterSuper));
13806
13823
  }
13807
13824
  this.bindFunctionParameters(methodFunc.__params, args, funcEnv, thisContext);
13825
+ if (methodFunc.__async) {
13826
+ return (async () => {
13827
+ const result2 = await this.evaluateAsync(methodFunc.__body, funcEnv);
13828
+ if (result2 instanceof ReturnValue) {
13829
+ return { __explicitReturn: true, value: result2.value };
13830
+ }
13831
+ if (result2 instanceof ThrowSignal) {
13832
+ throw result2.value;
13833
+ }
13834
+ return result2;
13835
+ })();
13836
+ }
13808
13837
  const result = this.evaluate(methodFunc.__body, funcEnv);
13809
13838
  if (result instanceof ReturnValue) {
13810
13839
  return { __explicitReturn: true, value: result.value };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jslike",
3
- "version": "1.8.6",
3
+ "version": "1.8.7",
4
4
  "description": "Production-ready JavaScript interpreter with full ES6+ support using Acorn parser",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",