greybel-interpreter 5.1.1 → 5.1.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.
@@ -0,0 +1,3 @@
1
+ export declare function hasIterator<T extends {
2
+ [Symbol.iterator]?: Function;
3
+ }>(obj: T): boolean;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasIterator = void 0;
4
+ function hasIterator(obj) {
5
+ return typeof obj[Symbol.iterator] === 'function';
6
+ }
7
+ exports.hasIterator = hasIterator;
package/dist/vm.js CHANGED
@@ -31,6 +31,7 @@ const events_1 = __importDefault(require("events"));
31
31
  const object_value_1 = require("./utils/object-value");
32
32
  const call_1 = require("./vm/call");
33
33
  const limited_stack_1 = require("./utils/limited-stack");
34
+ const has_iterator_1 = require("./utils/has-iterator");
34
35
  class Debugger {
35
36
  constructor() {
36
37
  this.breakpoint = false;
@@ -431,6 +432,9 @@ class VM {
431
432
  }
432
433
  case instruction_1.OpCode.PUSH_ITERATOR: {
433
434
  const value = this.popStack();
435
+ if (!(0, has_iterator_1.hasIterator)(value)) {
436
+ throw new error_1.RuntimeError(`"${value.getCustomType()}" does not have an iterator.`, this);
437
+ }
434
438
  const iterator = value[Symbol.iterator]();
435
439
  frame.iterators.push(iterator);
436
440
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "greybel-interpreter",
3
- "version": "5.1.1",
3
+ "version": "5.1.2",
4
4
  "description": "Interpreter",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index",