Skip to content
Browse files

Fix the null/last view thing

  • Loading branch information...
1 parent faa3cff commit 0d3c3455e7b3ee42a1c1a17043d70a03c98e6e7d @Trubbs Trubbs committed Apr 14, 2012
Showing with 4 additions and 0 deletions.
  1. +4 −0 view-buffer.js
View
4 view-buffer.js
@@ -207,6 +207,8 @@ ViewBuffer.prototype = {
// ### Proxy Handler ###
// #####################
+var views = new WeakMap;
+
var handler = {
names : function(fwd, target){
return numbers(target.length).concat(fwd());
@@ -241,12 +243,14 @@ var handler = {
if (isFinite(name)) {
target.set(name, val);
} else if (name === 'view') {
+ if (val === null) val = views.get(target);
val = val[0].toUpperCase() + val.slice(1).toLowerCase();
if (has(nameMap, val)) val = nameMap[val];
if (!has(types, val)) throw new Error('Unknown data type');
var bytesEach = types[val][0];
target.get = getters[val] || getters[val+target.endian];
target.set = setters[val] || setters[val+target.endian];
+ views.set(target, target.view);
target.view = val;
target.length = target.bytes / bytesEach | 0;
target.excess = target.bytes % bytesEach;

0 comments on commit 0d3c345

Please sign in to comment.
Something went wrong with that request. Please try again.