Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/typedObjects/primitiveTypes.js

Issue 5728072976302080: Issue 151 - [Typed objects] Implement dynamically-sized array types (Closed)
Patch Set: Use Uint8Array as constructor, not a function Created May 19, 2014, 7:57 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/typedObjects/objectTypes.js ('k') | lib/typedObjects/utils.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/typedObjects/primitiveTypes.js
===================================================================
--- a/lib/typedObjects/primitiveTypes.js
+++ b/lib/typedObjects/primitiveTypes.js
@@ -13,48 +13,58 @@
*
* You should have received a copy of the GNU General Public License
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
"use strict";
let {ilog2} = require("typedObjects/utils");
+let {createArrayType} = require("typedObjects/arrayTypes");
function createGetter(shift, offset, view)
{
shift = shift | 0;
offset = offset | 0;
offset >>= shift;
- return function()
+ return function(bufferIndex, byteOffset)
{
- return view[this.bufferIndex][((this.byteOffset | 0) >> shift) + offset];
+ bufferIndex = bufferIndex | 0;
+ byteOffset = byteOffset | 0;
+ return view[bufferIndex][(byteOffset >> shift) + offset];
};
}
function createSetter(shift, offset, view)
{
shift = shift | 0;
offset = offset | 0;
offset >>= shift;
- return function(value)
+ return function(bufferIndex, byteOffset, value)
{
- view[this.bufferIndex][((this.byteOffset | 0) >> shift) + offset] = value;
+ bufferIndex = bufferIndex | 0;
+ byteOffset = byteOffset | 0;
+ view[bufferIndex][(byteOffset >> shift) + offset] = value;
};
}
function PrimitiveType(viewType)
{
let result = Object.create(PrimitiveType.prototype);
result.viewTypes = [viewType];
result.byteLength = result.referenceLength = viewType.BYTES_PER_ELEMENT | 0;
let offsetShift = ilog2(result.byteLength) | 0;
result.createGetter = createGetter.bind(null, offsetShift);
result.createSetter = createSetter.bind(null, offsetShift);
+ // Note: this is a pretty inefficient way to zero out initial values. We
+ // should consider using ArrayBuffer.fill(0) once it becomes available
+ // (https://bugzilla.mozilla.org/show_bug.cgi?id=730880).
+ result.cleanupValue = 0;
+ result.Array = createArrayType.bind(null, result);
Object.freeze(result);
return result;
}
exports.uint8 = exports.boolean = new PrimitiveType(Uint8Array);
exports.uint8clamped = new PrimitiveType(Uint8ClampedArray);
exports.int8 = new PrimitiveType(Int8Array);
exports.uint16 = new PrimitiveType(Uint16Array);
« no previous file with comments | « lib/typedObjects/objectTypes.js ('k') | lib/typedObjects/utils.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld