diff --git a/lib/IV/AbstractContract.js b/lib/IV/AbstractContract.js index 829bf435..87424106 100644 --- a/lib/IV/AbstractContract.js +++ b/lib/IV/AbstractContract.js @@ -275,13 +275,17 @@ AbstractContract.bless = function bless (contractFunction, contract, implFunctio we reach the 'syntactic position' (a.k.a, we assign the contract function to a variable or property with a name), it will already have the name `contractFunction` we need internally. Therefor, we will explicitly set the name, based on the name of implementation function. - The Firefox feature `displayName` will not be used. */ + The Firefox feature `displayName` will not be used. + This is a real property, and not a derived property. Earlier, it was, but this was changed in response to + https://github.com/sinonjs/sinon/issues/2203 */ // IDEA we might also add a name property to a Contract, and combine it with that - property.frozenDerived( - contractFunction, - 'name', - report.conciseCondition.bind(null, report.namePrefix, implFunction) - ) + const implNamePropertyDescriptor = Object.getOwnPropertyDescriptor(implFunction, 'name') + Object.defineProperty(contractFunction, 'name', { + configurable: implNamePropertyDescriptor.configurable, + enumerable: implNamePropertyDescriptor.enumerable, + writable: implNamePropertyDescriptor.writable, + value: report.conciseCondition(report.namePrefix, implFunction) + }) } } diff --git a/test/02.IV/02.2.AbstractContractTest.js b/test/02.IV/02.2.AbstractContractTest.js index 20395287..1466f0d8 100644 --- a/test/02.IV/02.2.AbstractContractTest.js +++ b/test/02.IV/02.2.AbstractContractTest.js @@ -127,11 +127,18 @@ describe('IV/AbstractContract', function () { contractFunction.location.should.equal(location) testUtil.expectOwnFrozenProperty(contractFunction, 'bind') contractFunction.bind.should.equal(AbstractContract.bindContractFunction) - testUtil.expectFrozenDerivedPropertyOnAPrototype(contractFunction, 'name') contractFunction.should.have.ownProperty('name') contractFunction.name.should.equal( report.conciseCondition(AbstractContract.namePrefix, contractFunction.implementation) ) + const implFunctionNamePropDesc = Object.getOwnPropertyDescriptor(implFunction, 'name') + delete implFunctionNamePropDesc.value + const contractFunctionNamePropDesc = Object.getOwnPropertyDescriptor(contractFunction, 'name') + contractFunctionNamePropDesc.value.should.equal( + report.conciseCondition(AbstractContract.namePrefix, contractFunction.implementation) + ) + delete contractFunctionNamePropDesc.value + contractFunctionNamePropDesc.should.deepEqual(implFunctionNamePropDesc) }) })