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

Delta Between Two Patch Sets: lib/typedObjects/utils.js

Issue 5728072976302080: Issue 151 - [Typed objects] Implement dynamically-sized array types (Closed)
Left Patch Set: Created May 16, 2014, 12:44 p.m.
Right Patch Set: Created July 11, 2014, 7:26 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/typedObjects/primitiveTypes.js ('k') | test/index.html » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 126
127 /** 127 /**
128 * Defines properties with given name and type on an object. 128 * Defines properties with given name and type on an object.
129 * 129 *
130 * @param obj object to define properties on 130 * @param obj object to define properties on
131 * @param properties object mapping property names to their respective types 131 * @param properties object mapping property names to their respective types
132 * @param viewTypes see getViewsForType() 132 * @param viewTypes see getViewsForType()
133 * @param views see getViewsForType() 133 * @param views see getViewsForType()
134 * @param [offset] byte array offset at which the properties should start 134 * @param [offset] byte array offset at which the properties should start
135 * @param [watchers] map of watcher functions to be called when a particular pro perty is being set 135 * @param [watchers] map of watcher functions to be called when a particular pro perty is being set
136 * @param [cleanupValues] array of property/value combinations to be set when th e object is created or destroyed 136 * @param [initialValues] array of property/value combinations to be set when th e object is created or destroyed
137 * @return new start offset for additional properties 137 * @return new start offset for additional properties
138 */ 138 */
139 exports.defineProperties = function defineProperties(obj, properties, viewTypes, views, offset, watchers, cleanupValues) 139 exports.defineProperties = function defineProperties(obj, properties, viewTypes, views, offset, watchers, initialValues)
140 { 140 {
141 offset = offset | 0; 141 offset = offset | 0;
142 142
143 let propList = []; 143 let propList = [];
144 for (let name in properties) 144 for (let name in properties)
145 propList.push([name, properties[name]]); 145 propList.push([name, properties[name]]);
146 146
147 // Put larger properties first to make sure alignment requirements are met. 147 // Put larger properties first to make sure alignment requirements are met.
148 propList.sort(function(a, b) 148 propList.sort(function(a, b)
149 { 149 {
(...skipping 11 matching lines...) Expand all
161 get: wrapGetter(type.createGetter.apply(type, [offset].concat(viewParams)) ), 161 get: wrapGetter(type.createGetter.apply(type, [offset].concat(viewParams)) ),
162 set: wrapSetter(type.createSetter.apply(type, [offset].concat(viewParams)) ), 162 set: wrapSetter(type.createSetter.apply(type, [offset].concat(viewParams)) ),
163 configurable: false, 163 configurable: false,
164 enumerable: true 164 enumerable: true
165 }; 165 };
166 166
167 if (watchers && typeof watchers[name] == "function") 167 if (watchers && typeof watchers[name] == "function")
168 descriptors[name].set = watchSetter(descriptors[name].set, watchers[name]) ; 168 descriptors[name].set = watchSetter(descriptors[name].set, watchers[name]) ;
169 169
170 offset += type.referenceLength; 170 offset += type.referenceLength;
171 if (cleanupValues && typeof type.cleanupValue != "undefined") 171 if (initialValues && typeof type.initialValue != "undefined")
172 cleanupValues.push([name, type.cleanupValue]); 172 initialValues.push([name, type.initialValue]);
173 } 173 }
174 174
175 // Define properties 175 // Define properties
176 Object.defineProperties(obj, descriptors); 176 Object.defineProperties(obj, descriptors);
177 177
178 return offset; 178 return offset;
179 }; 179 };
180 180
181 /** 181 /**
182 * Creates a new array buffer and adds the necessary views. 182 * Creates a new array buffer and adds the necessary views.
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 exports.dealloc = function(firstFree, bufferIndex, byteOffset) 268 exports.dealloc = function(firstFree, bufferIndex, byteOffset)
269 { 269 {
270 let oldFreeBufferIndex = firstFree.bufferIndex | 0; 270 let oldFreeBufferIndex = firstFree.bufferIndex | 0;
271 let oldFreeByteOffset = firstFree.byteOffset | 0; 271 let oldFreeByteOffset = firstFree.byteOffset | 0;
272 272
273 firstFree.bufferIndex = bufferIndex | 0; 273 firstFree.bufferIndex = bufferIndex | 0;
274 firstFree.byteOffset = byteOffset | 0; 274 firstFree.byteOffset = byteOffset | 0;
275 firstFree.targetBufferIndex = oldFreeBufferIndex; 275 firstFree.targetBufferIndex = oldFreeBufferIndex;
276 firstFree.targetByteOffset = oldFreeByteOffset; 276 firstFree.targetByteOffset = oldFreeByteOffset;
277 } 277 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld