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

Side by Side Diff: lib/typedObjects/utils.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/references.js ('k') | test/tests/typedObjects.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
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 } 84 }
85 result.push(views[index]); 85 result.push(views[index]);
86 } 86 }
87 return result; 87 return result;
88 }; 88 };
89 89
90 /** 90 /**
91 * Defines properties with given name and type on an object. 91 * Defines properties with given name and type on an object.
92 * 92 *
93 * @param obj object to define properties on 93 * @param obj object to define properties on
94 * @param propList array of properties where each property is represented by 94 * @param properties object mapping property names to their respective types
95 * [name, type]
96 * @param viewTypes see getViewsForType() 95 * @param viewTypes see getViewsForType()
97 * @param views see getViewsForType() 96 * @param views see getViewsForType()
98 * @param [offset] byte array offset at which the properties should start 97 * @param [offset] byte array offset at which the properties should start
99 * @return new start offset for additional properties 98 * @return new start offset for additional properties
100 */ 99 */
101 exports.defineProperties = function defineProperties(obj, propList, viewTypes, v iews, offset) 100 exports.defineProperties = function defineProperties(obj, properties, viewTypes, views, offset)
102 { 101 {
103 offset = offset | 0; 102 offset = offset | 0;
104 103
104 let propList = [];
105 for (let name in properties)
106 propList.push([name, properties[name]]);
107
105 // Put larger properties first to make sure alignment requirements are met. 108 // Put larger properties first to make sure alignment requirements are met.
106 propList.sort(function(a, b) 109 propList.sort(function(a, b)
107 { 110 {
108 return b[1].referenceLength - a[1].referenceLength; 111 return b[1].referenceLength - a[1].referenceLength;
109 }); 112 });
110 113
111 // Generates getters and setters for each property. 114 // Generates getters and setters for each property.
112 let descriptors = {}; 115 let descriptors = {};
113 for (let i = 0, l = propList.length | 0; i < l; i++) 116 for (let i = 0, l = propList.length | 0; i < l; i++)
114 { 117 {
115 let [name, type] = propList[i]; 118 let [name, type] = propList[i];
116 119
117 let viewParams = getViewsForType(type, viewTypes, views); 120 let viewParams = getViewsForType(type, viewTypes, views);
118 descriptors[name] = { 121 descriptors[name] = {
119 get: type.createGetter.apply(type, [offset].concat(viewParams)), 122 get: type.createGetter.apply(type, [offset].concat(viewParams)),
120 set: type.createSetter.apply(type, [offset].concat(viewParams)), 123 set: type.createSetter.apply(type, [offset].concat(viewParams)),
121 configurable: false, 124 configurable: false,
122 enumerable: true 125 enumerable: true
123 }; 126 };
124 offset += type.referenceLength; 127 offset += type.referenceLength;
125 } 128 }
126 129
127 // Define properties 130 // Define properties
128 Object.defineProperties(obj, descriptors); 131 Object.defineProperties(obj, descriptors);
129 132
130 return offset; 133 return offset;
131 }; 134 };
OLDNEW
« no previous file with comments | « lib/typedObjects/references.js ('k') | test/tests/typedObjects.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld