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

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

Issue 5656302898380800: Issue 260 - [Typed objects] Implement type inheritance (Closed)
Patch Set: Renamed isinstance to isInstance Created May 2, 2014, 7:13 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') | lib/typedObjects/utils.js » ('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 {nextPow2, defineProperties} = require("typedObjects/utils"); 20 let {nextPow2, defineProperties} = require("typedObjects/utils");
21 let {uint16, int16, uint32} = require("typedObjects/primitiveTypes"); 21 let {uint16, int16, uint32} = require("typedObjects/primitiveTypes");
22 let {fixedPropertyDescriptor} = require("typedObjects/utils"); 22 let {fixedPropertyDescriptor} = require("typedObjects/utils");
23 23
24 function calculateSize(propList) 24 function calculateSize(properties)
25 { 25 {
26 let result = 0; 26 let result = 0;
27 for (let i = 0, l = propList.length | 0; i < l; i++) 27 for (let name in properties)
28 result += propList[i][1].referenceLength; 28 result += properties[name].referenceLength | 0;
29 return nextPow2(result); 29 return nextPow2(result) | 0;
30 } 30 }
31 31
32 function getViewTypes(propList) 32 function getViewTypes(properties)
33 { 33 {
34 let result = []; 34 let result = [];
35 for (let i = 0, l = propList.length | 0; i < l; i++) 35 for (let name in properties)
36 { 36 {
37 let requiredViews = propList[i][1].viewTypes; 37 let requiredViews = properties[name].viewTypes;
38 for (let j = 0, ll = requiredViews.length | 0; j < ll; j++) 38 for (let i = 0, l = requiredViews.length | 0; i < l; i++)
39 if (result.indexOf(requiredViews[j]) < 0) 39 if (result.indexOf(requiredViews[i]) < 0)
40 result.push(requiredViews[j]); 40 result.push(requiredViews[i]);
41 } 41 }
42 return result; 42 return result;
43 } 43 }
44 44
45 let TypedReference_properties = [ 45 let TypedReference_properties = {
46 ["targetBufferIndex", int16], 46 targetBufferIndex: int16,
47 ["targetByteOffset", uint32] 47 targetByteOffset: uint32
48 ]; 48 };
49 49
50 let Reference_properties = [ 50 let Reference_properties = {
51 ["typeId", int16] 51 __proto__: TypedReference_properties,
52 ].concat(TypedReference_properties); 52 typeId: int16
53 };
53 54
54 /** 55 /**
55 * Helper class to read/write properties referencing other objects. bufferIndex 56 * Helper class to read/write properties referencing other objects. bufferIndex
56 * and byteOffset properties of the reference need to be set in order to use it. 57 * and byteOffset properties of the reference need to be set in order to use it.
57 * 58 *
58 * @param types list of registered object types used to resolve typeId 59 * @param types list of registered object types used to resolve typeId
59 * @param views list of views corresponding to Reference.viewTypes 60 * @param views list of views corresponding to Reference.viewTypes
60 */ 61 */
61 function Reference(types, views) 62 function Reference(types, views)
62 { 63 {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 { 95 {
95 let result = Object.create(Reference.prototype, { 96 let result = Object.create(Reference.prototype, {
96 typeInfo: fixedPropertyDescriptor(typeInfo), 97 typeInfo: fixedPropertyDescriptor(typeInfo),
97 }); 98 });
98 defineProperties(result, TypedReference_properties, TypedReference.viewTypes, views, 0); 99 defineProperties(result, TypedReference_properties, TypedReference.viewTypes, views, 0);
99 return result; 100 return result;
100 } 101 }
101 TypedReference.byteLength = calculateSize(TypedReference_properties); 102 TypedReference.byteLength = calculateSize(TypedReference_properties);
102 TypedReference.viewTypes = Object.freeze(getViewTypes(TypedReference_properties) ); 103 TypedReference.viewTypes = Object.freeze(getViewTypes(TypedReference_properties) );
103 exports.TypedReference = TypedReference; 104 exports.TypedReference = TypedReference;
OLDNEW
« 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