Skip to content

Commit

Permalink
Make internal ObjectIterator properties non-enumerable.
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Aug 11, 2015
1 parent 630e897 commit 8a00fc9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
8 changes: 5 additions & 3 deletions es6-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -843,9 +843,11 @@
addIterator(ArrayIterator.prototype);

var ObjectIterator = function (object, kind) {
this.object = object;
this.array = getAllKeys(object);
this.kind = kind;
defineProperties(this, {
object: object,
array: getAllKeys(object),
kind: kind
});
};

var getAllKeys = function getAllKeys(object) {
Expand Down
21 changes: 21 additions & 0 deletions test/reflect.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,27 @@ describe('Reflect', function () {
expect(iter.next()).to.deep.equal({ value: undefined, done: true });
});
});

describe('enumeration order', function () {
it('enumerates own keys before prototype keys', function () {
var Foo = function Foo(arg) {
this.b = arg;
this[2] = arg;
};
Foo.prototype.a = 'bar';
Foo.prototype.c = 'bar';
Foo.prototype[1] = 'bar';
var foo = new Foo(42);

var iter = Reflect.enumerate(foo);
expect(iter.next()).to.deep.equal({ value: '2', done: false });
expect(iter.next()).to.deep.equal({ value: 'b', done: false });
expect(iter.next()).to.deep.equal({ value: '1', done: false });
expect(iter.next()).to.deep.equal({ value: 'a', done: false });
expect(iter.next()).to.deep.equal({ value: 'c', done: false });
expect(iter.next()).to.deep.equal({ value: undefined, done: true });
});
});
});

describeIfES5('.get()', function () {
Expand Down

0 comments on commit 8a00fc9

Please sign in to comment.