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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 | 104 |
105 function createSetter(typeId, offset) | 105 function createSetter(typeId, offset) |
106 { | 106 { |
107 typeId = typeId | 0; | 107 typeId = typeId | 0; |
108 offset = offset | 0; | 108 offset = offset | 0; |
109 | 109 |
110 let views = Array.prototype.slice.call(arguments, 2); | 110 let views = Array.prototype.slice.call(arguments, 2); |
111 let reference = new Reference(types, views); | 111 let reference = new Reference(types, views); |
112 return function(value) | 112 return function(value) |
113 { | 113 { |
114 if (value && !isinstance(typeId, value)) | 114 if (value && !isInstance(typeId, value)) |
115 throw new Error("Incompatible type"); | 115 throw new Error("Incompatible type"); |
116 | 116 |
117 reference.bufferIndex = this.bufferIndex | 0; | 117 reference.bufferIndex = this.bufferIndex | 0; |
118 reference.byteOffset = (this.byteOffset | 0) + offset; | 118 reference.byteOffset = (this.byteOffset | 0) + offset; |
119 if (value) | 119 if (value) |
120 { | 120 { |
121 reference.typeId = value.typeId; | 121 reference.typeId = value.typeId; |
122 reference.targetBufferIndex = value.bufferIndex; | 122 reference.targetBufferIndex = value.bufferIndex; |
123 reference.targetByteOffset = value.byteOffset; | 123 reference.targetByteOffset = value.byteOffset; |
124 } | 124 } |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
236 | 236 |
237 let result = create.bind(typeInfo); | 237 let result = create.bind(typeInfo); |
238 Object.defineProperties(result, { | 238 Object.defineProperties(result, { |
239 byteLength: fixedPropertyDescriptor(byteLength), | 239 byteLength: fixedPropertyDescriptor(byteLength), |
240 | 240 |
241 referenceLength: fixedPropertyDescriptor(Reference.byteLength), | 241 referenceLength: fixedPropertyDescriptor(Reference.byteLength), |
242 viewTypes: fixedPropertyDescriptor(Reference.viewTypes), | 242 viewTypes: fixedPropertyDescriptor(Reference.viewTypes), |
243 | 243 |
244 typeId: fixedPropertyDescriptor(typeId), | 244 typeId: fixedPropertyDescriptor(typeId), |
245 extend: fixedPropertyDescriptor(extend.bind(null, typeInfo)), | 245 extend: fixedPropertyDescriptor(extend.bind(null, typeInfo)), |
246 isinstance: fixedPropertyDescriptor(isinstance.bind(null, typeId)), | 246 isInstance: fixedPropertyDescriptor(isInstance.bind(null, typeId)), |
René Jeschke
2014/05/02 16:16:37
Just wondering, every other member name you use is
Wladimir Palant
2014/05/02 19:14:31
It's really because the JavaScript operator is cal
| |
247 | 247 |
248 createGetter: fixedPropertyDescriptor(createGetter), | 248 createGetter: fixedPropertyDescriptor(createGetter), |
249 createSetter: fixedPropertyDescriptor(createSetter.bind(null, typeId)) | 249 createSetter: fixedPropertyDescriptor(createSetter.bind(null, typeId)) |
250 }); | 250 }); |
251 types.push(typeInfo); | 251 types.push(typeInfo); |
252 return result; | 252 return result; |
253 } | 253 } |
254 | 254 |
255 function isinstance(typeId, obj) | 255 function isInstance(typeId, obj) |
256 { | 256 { |
257 typeId = typeId | 0; | 257 typeId = typeId | 0; |
258 | 258 |
259 // TODO: This could be optimized by compiling the list of all subclasses for | 259 // TODO: This could be optimized by compiling the list of all subclasses for |
260 // each type up front. Question is whether this is worth it. | 260 // each type up front. Question is whether this is worth it. |
261 let typeInfo = types[obj.typeId | 0]; | 261 let typeInfo = types[obj.typeId | 0]; |
262 while (typeInfo) | 262 while (typeInfo) |
263 { | 263 { |
264 if ((typeInfo.typeId | 0) == typeId) | 264 if ((typeInfo.typeId | 0) == typeId) |
265 return true; | 265 return true; |
266 typeInfo = typeInfo.parentTypeInfo; | 266 typeInfo = typeInfo.parentTypeInfo; |
267 } | 267 } |
268 return false; | 268 return false; |
269 } | 269 } |
270 | 270 |
271 let ObjectBase = exports.ObjectBase = extend(null, { | 271 let ObjectBase = exports.ObjectBase = extend(null, { |
272 equals: function(obj) | 272 equals: function(obj) |
273 { | 273 { |
274 if (!obj) | 274 if (!obj) |
275 return false; | 275 return false; |
276 return this.typeId == obj.typeId && this.bufferIndex == obj.bufferIndex && t his.byteOffset == obj.byteOffset; | 276 return this.typeId == obj.typeId && this.bufferIndex == obj.bufferIndex && t his.byteOffset == obj.byteOffset; |
277 } | 277 } |
278 }, null); | 278 }, null); |
279 | 279 |
280 exports.ObjectType = ObjectBase.extend; | 280 exports.ObjectType = ObjectBase.extend; |
LEFT | RIGHT |