diff --git a/lib/sinon/default-behaviors.js b/lib/sinon/default-behaviors.js index 96a4b416d..d7387f7a9 100644 --- a/lib/sinon/default-behaviors.js +++ b/lib/sinon/default-behaviors.js @@ -258,7 +258,7 @@ var defaultBehaviors = { Object.defineProperty(rootStub.rootObj, rootStub.propName, { value: newVal, enumerable: true, - configurable: isPropertyConfigurable(rootStub.rootObj, rootStub.propName) + configurable: rootStub.shadowsPropOnPrototype || isPropertyConfigurable(rootStub.rootObj, rootStub.propName) }); return fake; diff --git a/lib/sinon/stub.js b/lib/sinon/stub.js index 3ddca0a99..9dde8858e 100644 --- a/lib/sinon/stub.js +++ b/lib/sinon/stub.js @@ -94,11 +94,14 @@ function stub(object, property) { var func = typeof actualDescriptor.value === "function" ? actualDescriptor.value : null; var s = createStub(func); + var propIsOwn = Boolean(actualDescriptor.isOwn); + extend.nonEnum(s, { rootObj: object, propName: property, + shadowsPropOnPrototype: !propIsOwn, restore: function restore() { - if (actualDescriptor !== undefined) { + if (actualDescriptor !== undefined && propIsOwn) { Object.defineProperty(object, property, actualDescriptor); return; }