jslike 1.8.1 → 1.8.2

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.
@@ -54,22 +54,48 @@ function getAvailableMethods(obj) {
54
54
 
55
55
  const methods = new Set();
56
56
 
57
- // Get own properties
58
- Object.getOwnPropertyNames(obj).forEach(name => {
59
- if (typeof obj[name] === 'function') {
60
- methods.add(name);
57
+ const addSafeMethods = (target, includeConstructor = true) => {
58
+ let names;
59
+ try {
60
+ names = Object.getOwnPropertyNames(target);
61
+ } catch {
62
+ return;
61
63
  }
62
- });
63
64
 
64
- // Get prototype methods
65
- let proto = Object.getPrototypeOf(obj);
66
- while (proto && proto !== Object.prototype) {
67
- Object.getOwnPropertyNames(proto).forEach(name => {
68
- if (typeof proto[name] === 'function' && name !== 'constructor') {
65
+ names.forEach(name => {
66
+ if (!includeConstructor && name === 'constructor') return;
67
+
68
+ let descriptor;
69
+ try {
70
+ descriptor = Object.getOwnPropertyDescriptor(target, name);
71
+ } catch {
72
+ return;
73
+ }
74
+
75
+ if (descriptor && 'value' in descriptor && typeof descriptor.value === 'function') {
69
76
  methods.add(name);
70
77
  }
71
78
  });
72
- proto = Object.getPrototypeOf(proto);
79
+ };
80
+
81
+ // Get own properties
82
+ addSafeMethods(obj);
83
+
84
+ // Get prototype methods
85
+ let proto;
86
+ try {
87
+ proto = Object.getPrototypeOf(obj);
88
+ } catch {
89
+ proto = null;
90
+ }
91
+
92
+ while (proto && proto !== Object.prototype) {
93
+ addSafeMethods(proto, false);
94
+ try {
95
+ proto = Object.getPrototypeOf(proto);
96
+ } catch {
97
+ proto = null;
98
+ }
73
99
  }
74
100
 
75
101
  return Array.from(methods).sort();
package/dist/index.cjs CHANGED
@@ -11425,19 +11425,40 @@ function findSimilar(target, candidates, maxDistance = 3) {
11425
11425
  function getAvailableMethods(obj) {
11426
11426
  if (obj === null || obj === void 0) return [];
11427
11427
  const methods = /* @__PURE__ */ new Set();
11428
- Object.getOwnPropertyNames(obj).forEach((name) => {
11429
- if (typeof obj[name] === "function") {
11430
- methods.add(name);
11428
+ const addSafeMethods = (target, includeConstructor = true) => {
11429
+ let names;
11430
+ try {
11431
+ names = Object.getOwnPropertyNames(target);
11432
+ } catch {
11433
+ return;
11431
11434
  }
11432
- });
11433
- let proto = Object.getPrototypeOf(obj);
11434
- while (proto && proto !== Object.prototype) {
11435
- Object.getOwnPropertyNames(proto).forEach((name) => {
11436
- if (typeof proto[name] === "function" && name !== "constructor") {
11435
+ names.forEach((name) => {
11436
+ if (!includeConstructor && name === "constructor") return;
11437
+ let descriptor;
11438
+ try {
11439
+ descriptor = Object.getOwnPropertyDescriptor(target, name);
11440
+ } catch {
11441
+ return;
11442
+ }
11443
+ if (descriptor && "value" in descriptor && typeof descriptor.value === "function") {
11437
11444
  methods.add(name);
11438
11445
  }
11439
11446
  });
11440
- proto = Object.getPrototypeOf(proto);
11447
+ };
11448
+ addSafeMethods(obj);
11449
+ let proto;
11450
+ try {
11451
+ proto = Object.getPrototypeOf(obj);
11452
+ } catch {
11453
+ proto = null;
11454
+ }
11455
+ while (proto && proto !== Object.prototype) {
11456
+ addSafeMethods(proto, false);
11457
+ try {
11458
+ proto = Object.getPrototypeOf(proto);
11459
+ } catch {
11460
+ proto = null;
11461
+ }
11441
11462
  }
11442
11463
  return Array.from(methods).sort();
11443
11464
  }
package/dist/index.d.cts CHANGED
@@ -12100,22 +12100,48 @@ function getAvailableMethods(obj) {
12100
12100
 
12101
12101
  const methods = new Set();
12102
12102
 
12103
- // Get own properties
12104
- Object.getOwnPropertyNames(obj).forEach(name => {
12105
- if (typeof obj[name] === 'function') {
12106
- methods.add(name);
12103
+ const addSafeMethods = (target, includeConstructor = true) => {
12104
+ let names;
12105
+ try {
12106
+ names = Object.getOwnPropertyNames(target);
12107
+ } catch {
12108
+ return;
12107
12109
  }
12108
- });
12109
12110
 
12110
- // Get prototype methods
12111
- let proto = Object.getPrototypeOf(obj);
12112
- while (proto && proto !== Object.prototype) {
12113
- Object.getOwnPropertyNames(proto).forEach(name => {
12114
- if (typeof proto[name] === 'function' && name !== 'constructor') {
12111
+ names.forEach(name => {
12112
+ if (!includeConstructor && name === 'constructor') return;
12113
+
12114
+ let descriptor;
12115
+ try {
12116
+ descriptor = Object.getOwnPropertyDescriptor(target, name);
12117
+ } catch {
12118
+ return;
12119
+ }
12120
+
12121
+ if (descriptor && 'value' in descriptor && typeof descriptor.value === 'function') {
12115
12122
  methods.add(name);
12116
12123
  }
12117
12124
  });
12118
- proto = Object.getPrototypeOf(proto);
12125
+ };
12126
+
12127
+ // Get own properties
12128
+ addSafeMethods(obj);
12129
+
12130
+ // Get prototype methods
12131
+ let proto;
12132
+ try {
12133
+ proto = Object.getPrototypeOf(obj);
12134
+ } catch {
12135
+ proto = null;
12136
+ }
12137
+
12138
+ while (proto && proto !== Object.prototype) {
12139
+ addSafeMethods(proto, false);
12140
+ try {
12141
+ proto = Object.getPrototypeOf(proto);
12142
+ } catch {
12143
+ proto = null;
12144
+ }
12119
12145
  }
12120
12146
 
12121
12147
  return Array.from(methods).sort();
package/dist/index.d.ts CHANGED
@@ -12100,22 +12100,48 @@ function getAvailableMethods(obj) {
12100
12100
 
12101
12101
  const methods = new Set();
12102
12102
 
12103
- // Get own properties
12104
- Object.getOwnPropertyNames(obj).forEach(name => {
12105
- if (typeof obj[name] === 'function') {
12106
- methods.add(name);
12103
+ const addSafeMethods = (target, includeConstructor = true) => {
12104
+ let names;
12105
+ try {
12106
+ names = Object.getOwnPropertyNames(target);
12107
+ } catch {
12108
+ return;
12107
12109
  }
12108
- });
12109
12110
 
12110
- // Get prototype methods
12111
- let proto = Object.getPrototypeOf(obj);
12112
- while (proto && proto !== Object.prototype) {
12113
- Object.getOwnPropertyNames(proto).forEach(name => {
12114
- if (typeof proto[name] === 'function' && name !== 'constructor') {
12111
+ names.forEach(name => {
12112
+ if (!includeConstructor && name === 'constructor') return;
12113
+
12114
+ let descriptor;
12115
+ try {
12116
+ descriptor = Object.getOwnPropertyDescriptor(target, name);
12117
+ } catch {
12118
+ return;
12119
+ }
12120
+
12121
+ if (descriptor && 'value' in descriptor && typeof descriptor.value === 'function') {
12115
12122
  methods.add(name);
12116
12123
  }
12117
12124
  });
12118
- proto = Object.getPrototypeOf(proto);
12125
+ };
12126
+
12127
+ // Get own properties
12128
+ addSafeMethods(obj);
12129
+
12130
+ // Get prototype methods
12131
+ let proto;
12132
+ try {
12133
+ proto = Object.getPrototypeOf(obj);
12134
+ } catch {
12135
+ proto = null;
12136
+ }
12137
+
12138
+ while (proto && proto !== Object.prototype) {
12139
+ addSafeMethods(proto, false);
12140
+ try {
12141
+ proto = Object.getPrototypeOf(proto);
12142
+ } catch {
12143
+ proto = null;
12144
+ }
12119
12145
  }
12120
12146
 
12121
12147
  return Array.from(methods).sort();
package/dist/index.js CHANGED
@@ -11391,19 +11391,40 @@ function findSimilar(target, candidates, maxDistance = 3) {
11391
11391
  function getAvailableMethods(obj) {
11392
11392
  if (obj === null || obj === void 0) return [];
11393
11393
  const methods = /* @__PURE__ */ new Set();
11394
- Object.getOwnPropertyNames(obj).forEach((name) => {
11395
- if (typeof obj[name] === "function") {
11396
- methods.add(name);
11394
+ const addSafeMethods = (target, includeConstructor = true) => {
11395
+ let names;
11396
+ try {
11397
+ names = Object.getOwnPropertyNames(target);
11398
+ } catch {
11399
+ return;
11397
11400
  }
11398
- });
11399
- let proto = Object.getPrototypeOf(obj);
11400
- while (proto && proto !== Object.prototype) {
11401
- Object.getOwnPropertyNames(proto).forEach((name) => {
11402
- if (typeof proto[name] === "function" && name !== "constructor") {
11401
+ names.forEach((name) => {
11402
+ if (!includeConstructor && name === "constructor") return;
11403
+ let descriptor;
11404
+ try {
11405
+ descriptor = Object.getOwnPropertyDescriptor(target, name);
11406
+ } catch {
11407
+ return;
11408
+ }
11409
+ if (descriptor && "value" in descriptor && typeof descriptor.value === "function") {
11403
11410
  methods.add(name);
11404
11411
  }
11405
11412
  });
11406
- proto = Object.getPrototypeOf(proto);
11413
+ };
11414
+ addSafeMethods(obj);
11415
+ let proto;
11416
+ try {
11417
+ proto = Object.getPrototypeOf(obj);
11418
+ } catch {
11419
+ proto = null;
11420
+ }
11421
+ while (proto && proto !== Object.prototype) {
11422
+ addSafeMethods(proto, false);
11423
+ try {
11424
+ proto = Object.getPrototypeOf(proto);
11425
+ } catch {
11426
+ proto = null;
11427
+ }
11407
11428
  }
11408
11429
  return Array.from(methods).sort();
11409
11430
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jslike",
3
- "version": "1.8.1",
3
+ "version": "1.8.2",
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",