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

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

Issue 6253377650425856: WIP - Dictionary types implementation (Closed)
Patch Set: Created Jan. 9, 2015, 3:34 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/typedObjects/objectTypes.js ('k') | test/index.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 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 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 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/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 "use strict"; 18 "use strict";
19 19
20 let {ilog2} = require("typedObjects/utils"); 20 let {ilog2} = require("typedObjects/utils");
21 let {createArrayType} = require("typedObjects/arrayTypes"); 21 let {createArrayType} = require("typedObjects/arrayTypes");
22 let {createDictionaryType} = require("typedObjects/dictionaryTypes");
22 23
23 function createGetter(shift, offset, view) 24 function createGetter(shift, offset, view)
24 { 25 {
25 shift = shift | 0; 26 shift = shift | 0;
26 offset = offset | 0; 27 offset = offset | 0;
27 offset >>= shift; 28 offset >>= shift;
28 return function(bufferIndex, byteOffset) 29 return function(bufferIndex, byteOffset)
29 { 30 {
30 bufferIndex = bufferIndex | 0; 31 bufferIndex = bufferIndex | 0;
31 byteOffset = byteOffset | 0; 32 byteOffset = byteOffset | 0;
(...skipping 21 matching lines...) Expand all
53 result.byteLength = result.referenceLength = viewType.BYTES_PER_ELEMENT | 0; 54 result.byteLength = result.referenceLength = viewType.BYTES_PER_ELEMENT | 0;
54 55
55 let offsetShift = ilog2(result.byteLength) | 0; 56 let offsetShift = ilog2(result.byteLength) | 0;
56 result.createGetter = createGetter.bind(null, offsetShift); 57 result.createGetter = createGetter.bind(null, offsetShift);
57 result.createSetter = createSetter.bind(null, offsetShift); 58 result.createSetter = createSetter.bind(null, offsetShift);
58 // Note: this is a pretty inefficient way to zero out initial values. We 59 // Note: this is a pretty inefficient way to zero out initial values. We
59 // should consider using ArrayBuffer.fill(0) once it becomes available 60 // should consider using ArrayBuffer.fill(0) once it becomes available
60 // (https://bugzilla.mozilla.org/show_bug.cgi?id=730880). 61 // (https://bugzilla.mozilla.org/show_bug.cgi?id=730880).
61 result.initialValue = 0; 62 result.initialValue = 0;
62 result.Array = createArrayType.bind(null, result); 63 result.Array = createArrayType.bind(null, result);
64 result.Dictionary = createDictionaryType.bind(null, result);
63 Object.freeze(result); 65 Object.freeze(result);
64 return result; 66 return result;
65 } 67 }
66 68
67 exports.uint8 = exports.boolean = new PrimitiveType(Uint8Array); 69 exports.uint8 = exports.boolean = new PrimitiveType(Uint8Array);
68 exports.uint8clamped = new PrimitiveType(Uint8ClampedArray); 70 exports.uint8clamped = new PrimitiveType(Uint8ClampedArray);
69 exports.int8 = new PrimitiveType(Int8Array); 71 exports.int8 = new PrimitiveType(Int8Array);
70 exports.uint16 = new PrimitiveType(Uint16Array); 72 exports.uint16 = new PrimitiveType(Uint16Array);
71 exports.int16 = new PrimitiveType(Int16Array); 73 exports.int16 = new PrimitiveType(Int16Array);
72 exports.uint32 = new PrimitiveType(Uint32Array); 74 exports.uint32 = new PrimitiveType(Uint32Array);
73 exports.int32 = new PrimitiveType(Int32Array); 75 exports.int32 = new PrimitiveType(Int32Array);
74 exports.float32 = new PrimitiveType(Float32Array); 76 exports.float32 = new PrimitiveType(Float32Array);
75 exports.float64 = new PrimitiveType(Float64Array); 77 exports.float64 = new PrimitiveType(Float64Array);
OLDNEW
« no previous file with comments | « lib/typedObjects/objectTypes.js ('k') | test/index.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld