Skip to content

Commit

Permalink
always use defineProperty() for name
Browse files Browse the repository at this point in the history
  • Loading branch information
TooTallNate committed Jan 27, 2017
1 parent 786b739 commit 55716fd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
12 changes: 6 additions & 6 deletions lib/ref.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,12 +306,12 @@ exports.refType = function refType (type) {
var rtn = Object.create(_type)
rtn.indirection++
if (_type.name) {
var props = Object.getOwnPropertyDescriptor(_type, "name")
if (props && props.writable === false) {
props.writable = true
Object.defineProperty(rtn, "name", props)
}
rtn.name = _type.name + '*'
Object.defineProperty(rtn, 'name', {
value: _type.name + '*',
configurable: true,
enumerable: true,
writable: true
})
}
return rtn
}
Expand Down
13 changes: 9 additions & 4 deletions test/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,19 @@ describe('types', function () {
StructType.indirection = 0

// read-only name property
var oldProp = Object.getOwnPropertyDescriptor(StructType, "name")
assert.equal(oldProp.writable, false)
assert.equal(StructType.name, 'StructType')
try {
StructType.name = 'foo'
} catch (err) {
// ignore
}
assert.equal(StructType.name, 'StructType')

// name property should be writable and updated
var newObj = ref.refType(StructType)
var newProp = Object.getOwnPropertyDescriptor(newObj, "name")
var newProp = Object.getOwnPropertyDescriptor(newObj, 'name')
assert.equal(newProp.writable, true)
assert.equal(newObj.name, "StructType*")
assert.equal(newObj.name, 'StructType*')
})
})

Expand Down

0 comments on commit 55716fd

Please sign in to comment.