Skip to content

Commit

Permalink
Add test case to cover non-enumerable keys made enumerable by a previ…
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Oct 6, 2015
1 parent 1c3ddff commit 5b53808
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"max-nested-callbacks": [2, 3],
"max-statements": [2, 12],
"new-cap": [2, { "capIsNewExceptions": ["RequireObjectCoercible"] }],
"no-invalid-this": [1]
"no-invalid-this": [1],
"no-restricted-syntax": [2, "BreakStatement", "ContinueStatement", "DebuggerStatement", "LabeledStatement", "WithStatement"]
}
}
1 change: 0 additions & 1 deletion .jscs.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

"disallowNodeTypes": [
"DebuggerStatement",
"ForInStatement",
"LabeledStatement",
"SwitchCase",
"SwitchStatement",
Expand Down
10 changes: 5 additions & 5 deletions implementation.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
'use strict';

var ES = require('es-abstract/es7');
var keys = require('object-keys');
var has = require('has');
var bind = require('function-bind');
var isEnumerable = bind.call(Function.call, Object.prototype.propertyIsEnumerable);

module.exports = function entries(O) {
var obj = ES.RequireObjectCoercible(O);
var objKeys = keys(obj);
var entrys = [];
for (var i = 0; i < objKeys.length; ++i) {
if (has(obj, objKeys[i])) {
entrys.push([objKeys[i], obj[objKeys[i]]]);
for (var key in obj) {
if (has(obj, key) && isEnumerable(obj, key)) {
entrys.push([key, obj[key]]);
}
}
return entrys;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"define-properties": "^1.1.1",
"es-abstract": "^1.3.2",
"has": "^1.0.1",
"object-keys": "^1.0.7"
"function-bind": "^1.0.2"
},
"devDependencies": {
"tape": "^4.2.1",
Expand Down
12 changes: 12 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,16 @@ module.exports = function (entries, t) {
st.deepEqual(entries(o), [['a', 1], ['c', 3]], 'when "b" is deleted prior to being visited, it should not show up');
st.end();
});

t.test('not-yet-visited keys made non-enumerable on [[Get]] must not show up in output', { skip: !define.supportsDescriptors }, function (st) {
var o = { a: 'A', b: 'B' };
Object.defineProperty(o, 'a', {
get: function () {
Object.defineProperty(o, 'b', { enumerable: false });
return 'A';
}
});
st.deepEqual(entries(o), [['a', 'A']], 'when "b" is made non-enumerable prior to being visited, it should not show up');
st.end();
});
};

0 comments on commit 5b53808

Please sign in to comment.