Skip to content

Commit

Permalink
rename the backing buffer property to "ref.buffer"
Browse files Browse the repository at this point in the history
The old prop name "buffer" was very likely to collide, as it's a common
struct property name in C. The new name "ref.buffer" is not a valid C struct
name, so it's very unlikely to every be a problem in the future.

/cc @tjfontaine
  • Loading branch information
TooTallNate committed Jan 25, 2013
1 parent 40b8fae commit aa33781
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/struct.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* The only verboten field names are "ref", which is used used on struct
* instances as a function to retrieve the backing Buffer instance of the
* struct, and "buffer" which contains the backing Buffer instance.
* struct, and "ref.buffer" which contains the backing Buffer instance.
*
*
* Example:
Expand Down Expand Up @@ -92,7 +92,7 @@ function Struct () {

// set the backing Buffer store
store.type = StructType
this.buffer = store
this['ref.buffer'] = store

if (arg) {
for (var key in arg) {
Expand Down Expand Up @@ -167,7 +167,7 @@ function set (buffer, offset, value) {
}
var isStruct = value instanceof this
if (isStruct) {
value.buffer.copy(buffer, offset, 0, this.size);
value['ref.buffer'].copy(buffer, offset, 0, this.size);
} else {
new this(buffer, value)
}
Expand Down Expand Up @@ -214,11 +214,11 @@ function defineProperty (name, type) {
var desc = { enumerable: true , configurable: true }
desc.get = function () {
debug('getting "%s" struct field (offset: %d)', name, field.offset)
return ref.get(this.buffer, field.offset, type)
return ref.get(this['ref.buffer'], field.offset, type)
}
desc.set = function (value) {
debug('setting "%s" struct field (offset: %d)', name, field.offset, value)
return ref.set(this.buffer, field.offset, value, type)
return ref.set(this['ref.buffer'], field.offset, value, type)
}

// calculate the new size and field offsets
Expand Down Expand Up @@ -301,7 +301,7 @@ var proto = {}
* throw an error if you try to define a struct field with the name "buffer".
*/

proto.buffer = ref.NULL
proto['ref.buffer'] = ref.NULL

/**
* Flattens the Struct instance into a regular JavaScript Object. This function
Expand Down Expand Up @@ -345,5 +345,5 @@ proto.inspect = function inspect () {
*/

proto.ref = function ref () {
return this.buffer
return this['ref.buffer']
}

0 comments on commit aa33781

Please sign in to comment.