Skip to content

Commit

Permalink
make contract function name a true property, not a derived property
Browse files Browse the repository at this point in the history
in response to sinonjs/sinon#2203
  • Loading branch information
jandockx committed Jun 1, 2020
1 parent 351c5c2 commit 2c63d7d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
16 changes: 10 additions & 6 deletions lib/IV/AbstractContract.js
Expand Up @@ -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)
})
}
}

Expand Down
9 changes: 8 additions & 1 deletion test/02.IV/02.2.AbstractContractTest.js
Expand Up @@ -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)
})
})

Expand Down

0 comments on commit 2c63d7d

Please sign in to comment.