Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't mock accessors #409

Merged
merged 1 commit into from
Jun 19, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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