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

Side by Side Diff: lib/typedObjects/primitiveTypes.js

Issue 4827963358969856: Issue 147 - [Typed objects] Implement object types (Closed)
Patch Set: Created April 4, 2014, 10:28 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH
4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 "use strict";
19
20 let {log2} = require("typedObjects/utils");
21
22 function createGetter(shift, offset, view)
23 {
24 shift = shift | 0;
25 offset = offset | 0;
26 offset >>= shift;
27 return function()
28 {
29 return view[this.bufferIndex][((this.byteOffset | 0) >> shift) + offset];
30 };
31 }
32
33 function createSetter(shift, offset, view)
34 {
35 shift = shift | 0;
36 offset = offset | 0;
37 offset >>= shift;
38 return function(value)
39 {
40 view[this.bufferIndex][((this.byteOffset | 0) >> shift) + offset] = value;
41 };
42 }
43
44 function PrimitiveType(viewType)
45 {
46 let result = Object.create(PrimitiveType.prototype);
47 result.viewTypes = [viewType];
48 result.byteLength = result.referenceLength = viewType.BYTES_PER_ELEMENT | 0;
49
50 let offsetShift = log2(result.byteLength) | 0;
51 result.createGetter = createGetter.bind(null, offsetShift);
52 result.createSetter = createSetter.bind(null, offsetShift);
53 Object.freeze(result);
54 return result;
55 }
56
57 exports.uint8 = exports.boolean = new PrimitiveType(Uint8Array);
58 exports.uint8clamped = new PrimitiveType(Uint8ClampedArray);
59 exports.int8 = new PrimitiveType(Int8Array);
60 exports.uint16 = new PrimitiveType(Uint16Array);
61 exports.int16 = new PrimitiveType(Int16Array);
62 exports.uint32 = new PrimitiveType(Uint32Array);
63 exports.int32 = new PrimitiveType(Int32Array);
64 exports.float32 = new PrimitiveType(Float32Array);
65 exports.float64 = new PrimitiveType(Float64Array);
OLDNEW

Powered by Google App Engine
This is Rietveld