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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 let [bufferIndex, byteOffset] = alloc(this.firstFree, this.byteLength, | 51 let [bufferIndex, byteOffset] = alloc(this.firstFree, this.byteLength, |
52 this.bufferSize, this.buffers, this.viewTypes, this.views); | 52 this.bufferSize, this.buffers, this.viewTypes, this.views); |
53 | 53 |
54 let result = Object.create(this.proto, { | 54 let result = Object.create(this.proto, { |
55 typeId: fixedPropertyDescriptor(this.typeId), | 55 typeId: fixedPropertyDescriptor(this.typeId), |
56 bufferIndex: fixedPropertyDescriptor(bufferIndex), | 56 bufferIndex: fixedPropertyDescriptor(bufferIndex), |
57 byteOffset: fixedPropertyDescriptor(byteOffset) | 57 byteOffset: fixedPropertyDescriptor(byteOffset) |
58 }); | 58 }); |
59 | 59 |
60 result._state = STATE_UNINITIALIZED; | 60 result._state = STATE_UNINITIALIZED; |
61 for (let [prop, value] of this.cleanupValues) | 61 for (let [prop, value] of this.initialValues) |
62 result[prop] = value; | 62 result[prop] = value; |
63 result._state = STATE_CREATED; | 63 result._state = STATE_CREATED; |
64 result._refCount = 1; | 64 result._refCount = 1; |
65 | 65 |
66 if (this.constructor) | 66 if (this.constructor) |
67 this.constructor.apply(result, arguments); | 67 this.constructor.apply(result, arguments); |
68 return result; | 68 return result; |
69 } | 69 } |
70 | 70 |
71 function free(obj) | 71 function free(obj) |
72 { | 72 { |
73 try | 73 try |
74 { | 74 { |
75 if (this.destructor) | 75 if (this.destructor) |
76 { | 76 { |
77 this.destructor.call(obj); | 77 this.destructor.call(obj); |
78 if (obj._refCount | 0) | 78 if (obj._refCount | 0) |
79 throw new Error("Reference count is no longer zero after calling the des
tructor"); | 79 throw new Error("Reference count is no longer zero after calling the des
tructor"); |
80 } | 80 } |
81 } | 81 } |
82 finally | 82 finally |
83 { | 83 { |
84 for (let [prop, value] of this.cleanupValues) | 84 for (let [prop, value] of this.initialValues) |
85 obj[prop] = value; | 85 obj[prop] = value; |
86 | 86 |
87 dealloc(this.firstFree, obj.bufferIndex, obj.byteOffset); | 87 dealloc(this.firstFree, obj.bufferIndex, obj.byteOffset); |
88 } | 88 } |
89 } | 89 } |
90 | 90 |
91 function createGetter(offset) | 91 function createGetter(offset) |
92 { | 92 { |
93 offset = offset | 0; | 93 offset = offset | 0; |
94 | 94 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 { | 209 { |
210 watchers = Object.create(watchers); | 210 watchers = Object.create(watchers); |
211 for (let key in meta.watch) | 211 for (let key in meta.watch) |
212 watchers[key] = meta.watch[key]; | 212 watchers[key] = meta.watch[key]; |
213 } | 213 } |
214 | 214 |
215 let proto = {}; | 215 let proto = {}; |
216 let buffers = []; | 216 let buffers = []; |
217 let viewTypes = []; | 217 let viewTypes = []; |
218 let views = []; | 218 let views = []; |
219 let cleanupValues = []; | 219 let initialValues = []; |
220 let byteLength = defineProperties(proto, properties, viewTypes, views, 0, watc
hers, cleanupValues); | 220 let byteLength = defineProperties(proto, properties, viewTypes, views, 0, watc
hers, initialValues); |
221 Object.defineProperties(proto, methods); | 221 Object.defineProperties(proto, methods); |
222 | 222 |
223 // Round up to be a multiple of the maximal property size | 223 // Round up to be a multiple of the maximal property size |
224 byteLength = ((byteLength - 1) | (maxReferenceLength - 1)) + 1; | 224 byteLength = ((byteLength - 1) | (maxReferenceLength - 1)) + 1; |
225 | 225 |
226 // We need to be able to store a typed reference in the object's buffer | 226 // We need to be able to store a typed reference in the object's buffer |
227 byteLength = Math.max(byteLength, TypedReference.byteLength) | 0; | 227 byteLength = Math.max(byteLength, TypedReference.byteLength) | 0; |
228 let typedReferenceViews = getViewsForType(TypedReference, viewTypes, views); | 228 let typedReferenceViews = getViewsForType(TypedReference, viewTypes, views); |
229 | 229 |
230 // Take constructor and destructor from meta parameters, allow calling | 230 // Take constructor and destructor from meta parameters, allow calling |
(...skipping 21 matching lines...) Expand all Loading... |
252 byteLength: byteLength, | 252 byteLength: byteLength, |
253 bufferSize: "bufferSize" in meta ? Math.max(meta.bufferSize | 0, 2) : 128, | 253 bufferSize: "bufferSize" in meta ? Math.max(meta.bufferSize | 0, 2) : 128, |
254 firstFree: new TypedReference(typeId, typedReferenceViews), | 254 firstFree: new TypedReference(typeId, typedReferenceViews), |
255 proto: proto, | 255 proto: proto, |
256 properties: properties, | 256 properties: properties, |
257 methods: methods, | 257 methods: methods, |
258 watchers: watchers, | 258 watchers: watchers, |
259 buffers: buffers, | 259 buffers: buffers, |
260 viewTypes: viewTypes, | 260 viewTypes: viewTypes, |
261 views: views, | 261 views: views, |
262 cleanupValues: cleanupValues, | 262 initialValues: initialValues, |
263 typeId: typeId, | 263 typeId: typeId, |
264 parentTypeInfo: parentTypeInfo, | 264 parentTypeInfo: parentTypeInfo, |
265 constructor: constructor, | 265 constructor: constructor, |
266 destructor: destructor | 266 destructor: destructor |
267 }; | 267 }; |
268 | 268 |
269 let result = create.bind(typeInfo); | 269 let result = create.bind(typeInfo); |
270 Object.defineProperties(result, { | 270 Object.defineProperties(result, { |
271 byteLength: fixedPropertyDescriptor(byteLength), | 271 byteLength: fixedPropertyDescriptor(byteLength), |
272 | 272 |
273 referenceLength: fixedPropertyDescriptor(Reference.byteLength), | 273 referenceLength: fixedPropertyDescriptor(Reference.byteLength), |
274 viewTypes: fixedPropertyDescriptor(Reference.viewTypes), | 274 viewTypes: fixedPropertyDescriptor(Reference.viewTypes), |
275 cleanupValue: fixedPropertyDescriptor(null), | 275 initialValue: fixedPropertyDescriptor(null), |
276 | 276 |
277 typeId: fixedPropertyDescriptor(typeId), | 277 typeId: fixedPropertyDescriptor(typeId), |
278 extend: fixedPropertyDescriptor(extend.bind(null, typeInfo)), | 278 extend: fixedPropertyDescriptor(extend.bind(null, typeInfo)), |
279 isInstance: fixedPropertyDescriptor(isInstance.bind(null, typeId)), | 279 isInstance: fixedPropertyDescriptor(isInstance.bind(null, typeId)), |
280 Array: fixedPropertyDescriptor(createArrayType.bind(null, result)), | 280 Array: fixedPropertyDescriptor(createArrayType.bind(null, result)), |
281 | 281 |
282 createGetter: fixedPropertyDescriptor(createGetter), | 282 createGetter: fixedPropertyDescriptor(createGetter), |
283 createSetter: fixedPropertyDescriptor(createSetter.bind(null, typeId)) | 283 createSetter: fixedPropertyDescriptor(createSetter.bind(null, typeId)) |
284 }); | 284 }); |
285 types.push(typeInfo); | 285 types.push(typeInfo); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 this._refCount--; | 323 this._refCount--; |
324 if (this._refCount == 0 && this._state < STATE_RELEASING) | 324 if (this._refCount == 0 && this._state < STATE_RELEASING) |
325 { | 325 { |
326 this._state = STATE_RELEASING; | 326 this._state = STATE_RELEASING; |
327 free.call(types[this.typeId | 0], this); | 327 free.call(types[this.typeId | 0], this); |
328 } | 328 } |
329 } | 329 } |
330 }, null); | 330 }, null); |
331 | 331 |
332 exports.ObjectType = ObjectBase.extend; | 332 exports.ObjectType = ObjectBase.extend; |
LEFT | RIGHT |