Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

into test passes

  • Loading branch information...
commit 4aaf296567618302aeaf6ef9388a2ffe2b7e5377 1 parent 5e7cdc0
James Halliday authored
Showing with 21 additions and 14 deletions.
  1. +21 −14 lib/binary.js
35 lib/binary.js
View
@@ -180,8 +180,8 @@ function Binary(buffer) {
};
// assign immediately
- function assign () {
- var args = [].concat.apply([],arguments);
+ function assign (self) {
+ var args = [].slice.call(arguments,1);
// flatten :into so .getX(['foo','bar','baz'])
// and .getX('foo','bar','baz') both work
@@ -194,7 +194,7 @@ function Binary(buffer) {
var value = args.slice(-1)[0];
// assign into key hierarchy with the into array
- var obj = this.vars;
+ var obj = self.vars;
keys.slice(0,-1).forEach(function (k) {
if (!obj[k]) obj[k] = {};
obj = obj[k];
@@ -228,20 +228,29 @@ function Binary(buffer) {
var fv = args.slice(-1)[0];
return this.tap(function (vars) {
- if (fv instanceof Function) {
+ if (typeof fv == 'function') {
+ var topVars = this.vars;
+ this.vars = {};
fv.call(this, this.vars);
- assign.call(binary, keys, this.vars);
+ this.pushAction({
+ ready : true,
+ action : function () {
+ var localVars = this.vars;
+ this.vars = topVars;
+ assign(this, keys, localVars);
+ }
+ });
}
- else if (typeof(fv) == 'string') {
- assign.call(binary, keys, lookup.call(this,fv));
+ else if (typeof fv == 'string') {
+ assign(this, keys, lookup.call(this,fv));
}
- else if (typeof(fv) == 'number') {
- assign.call(binary, keys, fv);
+ else if (typeof fv == 'number') {
+ assign(this, keys, fv);
}
else {
throw TypeError(
'Last argument to .into must be a string, number, '
- + 'or a function, not a "' + typeof(fv) + '".'
+ + 'or a function, not a "' + typeof fv + '".'
+ 'Value supplied: ' + sys.inspect(fv)
);
}
@@ -262,9 +271,7 @@ function Binary(buffer) {
this.offset += opts.bytes;
var decodeLittleEndian = opts.signed ? decodeLEs : decodeLE;
var decodeBigEndian = opts.signed ? decodeBEs : decodeBE;
- assign.call(
- this,
- into,
+ assign(this, into,
opts.endian && opts.endian == 'little'
? decodeLittleEndian(data)
: decodeBigEndian(data)
@@ -398,7 +405,7 @@ function Binary(buffer) {
var s = lengthF.call(this,this.vars);
var data = buffer.join(this.offset, this.offset + s);
this.offset += s;
- assign.call(this,into,data);
+ assign(this, into, data);
},
});
return this;
Please sign in to comment.
Something went wrong with that request. Please try again.