Skip to content

Commit

Permalink
Merge pull request #409 from facebook/mocker_no_accessors
Browse files Browse the repository at this point in the history
Don't mock accessors
  • Loading branch information
DmitrySoshnikov committed Jun 19, 2015
2 parents c229ed1 + 4ef9ae7 commit 3afa11b
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/lib/moduleMocker.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,24 @@ function getType(ref) {
* methods on ES6 classes are not enumerable, so they can't be found with a
* simple `for (var slot in ...) {` so that had to be replaced with getSlots()
*/
var forbiddenProps = Object.create(null, {
caller: {value: true},
callee: {value: true},
arguments: {value: true},
});

function getSlots(object) {
var slots = {};
if (!object) {
return [];
}
// Simply attempting to access any of these throws an error.
var forbiddenProps = [ 'caller', 'callee', 'arguments' ];
//
var collectProp = function(prop) {
if (prop in forbiddenProps) {
return;
}
var propDesc = Object.getOwnPropertyDescriptor(object, prop);
if (forbiddenProps.indexOf(prop) === -1 &&
// Include only enumerable accessors.
(propDesc.enumerable || !propDesc.get)) {
if (!propDesc.get) {
slots[prop] = true;
}
};
Expand Down

0 comments on commit 3afa11b

Please sign in to comment.