Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 24 matching lines...) Expand all Loading... | |
35 bufferIndex: fixedPropertyDescriptor(reference.targetBufferIndex), | 35 bufferIndex: fixedPropertyDescriptor(reference.targetBufferIndex), |
36 byteOffset: fixedPropertyDescriptor(reference.targetByteOffset) | 36 byteOffset: fixedPropertyDescriptor(reference.targetByteOffset) |
37 }); | 37 }); |
38 } | 38 } |
39 else | 39 else |
40 return null; | 40 return null; |
41 } | 41 } |
42 | 42 |
43 function create() | 43 function create() |
44 { | 44 { |
45 let views = this.views; | |
46 let {bufferIndex, byteOffset} = this.firstFree; | 45 let {bufferIndex, byteOffset} = this.firstFree; |
47 if (bufferIndex >= 0) | 46 if (bufferIndex >= 0) |
48 { | 47 { |
49 // There is still a free spot, simply move on firstFree reference | 48 // There is still a free spot, simply move on firstFree reference |
50 [this.firstFree.bufferIndex, this.firstFree.byteOffset] = | 49 [this.firstFree.bufferIndex, this.firstFree.byteOffset] = |
51 [this.firstFree.targetBufferIndex, this.firstFree.targetByteOffset]; | 50 [this.firstFree.targetBufferIndex, this.firstFree.targetByteOffset]; |
René Jeschke
2014/04/21 17:24:12
Do we gain anything from [a, b] = [c, d] instead o
Wladimir Palant
2014/04/22 15:25:05
reference.bufferIndex = reference.targetBufferInde
René Jeschke
2014/04/22 15:40:34
Right, using temporaries also will look ugly. So:
| |
52 } | 51 } |
53 else | 52 else |
54 { | 53 { |
55 let viewTypes = this.viewTypes; | 54 let viewTypes = this.viewTypes; |
55 let views = this.views; | |
56 let byteLength = this.byteLength | 0; | 56 let byteLength = this.byteLength | 0; |
57 let bufferSize = this.bufferSize | 0; | 57 let bufferSize = this.bufferSize | 0; |
58 | 58 |
59 // Create new buffer and use the first element of it | 59 // Create new buffer and use the first element of it |
60 let buffer = new ArrayBuffer(byteLength * bufferSize); | 60 let buffer = new ArrayBuffer(byteLength * bufferSize); |
61 bufferIndex = (this.buffers.push(buffer) | 0) - 1; | 61 bufferIndex = (this.buffers.push(buffer) | 0) - 1; |
62 byteOffset = 0; | 62 byteOffset = 0; |
63 for (let i = 0, l = viewTypes.length | 0; i < l; i++) | 63 for (let i = 0, l = viewTypes.length | 0; i < l; i++) |
64 views[i].push(new viewTypes[i](buffer)); | 64 views[i].push(new viewTypes[i](buffer)); |
65 | 65 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 else | 155 else |
156 throw new Error("Unrecognized type " + type + " given for property " + nam e); | 156 throw new Error("Unrecognized type " + type + " given for property " + nam e); |
157 } | 157 } |
158 | 158 |
159 let buffers = []; | 159 let buffers = []; |
160 let viewTypes = []; | 160 let viewTypes = []; |
161 let views = []; | 161 let views = []; |
162 let byteLength = defineProperties(proto, propList, viewTypes, views, 0); | 162 let byteLength = defineProperties(proto, propList, viewTypes, views, 0); |
163 | 163 |
164 // Round up to be a multiple of the maximal property size | 164 // Round up to be a multiple of the maximal property size |
165 byteLength = ((byteLength - 1) | (maxReferenceLength - 1)) + 1; | 165 byteLength = ((byteLength - 1) | (maxReferenceLength - 1)) + 1; |
René Jeschke
2014/04/21 17:24:12
This only works correctly if either 'byteLength' o
Wladimir Palant
2014/04/22 15:25:05
No, maxReferenceLength has to be a power of two -
René Jeschke
2014/04/22 15:40:34
Okay then.
| |
166 | 166 |
167 // We need to be able to store a typed reference in the object's buffer | 167 // We need to be able to store a typed reference in the object's buffer |
168 byteLength = Math.max(byteLength, TypedReference.byteLength) | 0; | 168 byteLength = Math.max(byteLength, TypedReference.byteLength) | 0; |
169 let typedReferenceViews = getViewsForType(TypedReference, viewTypes, views); | 169 let typedReferenceViews = getViewsForType(TypedReference, viewTypes, views); |
170 | 170 |
171 let typeId = types.length | 0; | 171 let typeId = types.length | 0; |
172 let typeInfo = { | 172 let typeInfo = { |
173 byteLength: byteLength, | 173 byteLength: byteLength, |
174 bufferSize: "bufferSize" in meta ? Math.max(meta.bufferSize | 0, 2) : 128, | 174 bufferSize: "bufferSize" in meta ? Math.max(meta.bufferSize | 0, 2) : 128, |
175 firstFree: new TypedReference(typeId, typedReferenceViews), | 175 firstFree: new TypedReference(typeId, typedReferenceViews), |
176 proto: proto, | 176 proto: proto, |
177 buffers: buffers, | 177 buffers: buffers, |
178 viewTypes: viewTypes, | 178 viewTypes: viewTypes, |
179 views: views, | 179 views: views, |
180 typeId: typeId, | 180 typeId: typeId, |
181 constructor: (typeof meta.constructor == "function" ? meta.constructor : nul l) | 181 constructor: (meta.hasOwnProperty("constructor") && typeof meta.constructor == "function" ? meta.constructor : null) |
Wladimir Palant
2014/04/22 15:25:05
This was a bug - each JavaScript object has a cons
René Jeschke
2014/04/22 15:40:34
Didn't know that, now I do. Finally a good use cas
| |
182 }; | 182 }; |
183 | 183 |
184 let result = create.bind(typeInfo); | 184 let result = create.bind(typeInfo); |
185 Object.defineProperties(result, { | 185 Object.defineProperties(result, { |
186 byteLength: fixedPropertyDescriptor(byteLength), | 186 byteLength: fixedPropertyDescriptor(byteLength), |
187 | 187 |
188 referenceLength: fixedPropertyDescriptor(Reference.byteLength), | 188 referenceLength: fixedPropertyDescriptor(Reference.byteLength), |
189 viewTypes: fixedPropertyDescriptor(Reference.viewTypes), | 189 viewTypes: fixedPropertyDescriptor(Reference.viewTypes), |
190 | 190 |
191 typeId: fixedPropertyDescriptor(typeId), | 191 typeId: fixedPropertyDescriptor(typeId), |
192 | 192 |
193 createGetter: fixedPropertyDescriptor(createGetter), | 193 createGetter: fixedPropertyDescriptor(createGetter), |
194 createSetter: fixedPropertyDescriptor(createSetter.bind(null, typeId)) | 194 createSetter: fixedPropertyDescriptor(createSetter.bind(null, typeId)) |
195 }); | 195 }); |
196 types.push(typeInfo); | 196 types.push(typeInfo); |
197 return result; | 197 return result; |
198 } | 198 } |
199 exports.ObjectType = ObjectType; | 199 exports.ObjectType = ObjectType; |
LEFT | RIGHT |