OLD | NEW |
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 * | 44 * |
45 * The optional second parameter sets type metadata: | 45 * The optional second parameter sets type metadata: |
46 * | 46 * |
47 * constructor: function that will be called whenever an object of the type | 47 * constructor: function that will be called whenever an object of the type |
48 * is created. Parameters supplied during object creation will be passed | 48 * is created. Parameters supplied during object creation will be passed |
49 * to the constructor. | 49 * to the constructor. |
50 * destructor: function that will be called when an object of the type is | 50 * destructor: function that will be called when an object of the type is |
51 * freed. | 51 * freed. |
52 * bufferSize: number of objects that should be placed into a single typed | 52 * bufferSize: number of objects that should be placed into a single typed |
53 * buffer (by default 128). | 53 * buffer (by default 128). |
| 54 * watch: a map assigning watcher functions to properties. These functions |
| 55 * are called with the new property value before the property is set. |
| 56 * They have to return the value that should actually be set for the |
| 57 * property, it doesn't necessarily have to be the original value. |
54 * | 58 * |
55 * Creating and releasing an object instance | 59 * Creating and releasing an object instance |
56 * ----------------------------------------- | 60 * ----------------------------------------- |
57 * | 61 * |
58 * var point = Point2D(5, 10); | 62 * var point = Point2D(5, 10); |
59 * point.rotate(10); | 63 * point.rotate(10); |
60 * console.log(point.x + ", " + point.y); | 64 * console.log(point.x + ", " + point.y); |
61 * | 65 * |
62 * The parameters 5 and 10 will be passed to the constructor function defined | 66 * The parameters 5 and 10 will be passed to the constructor function defined |
63 * for this type. | 67 * for this type. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 * All objects inherit from ObjectBase type implicitly and share its methods. | 106 * All objects inherit from ObjectBase type implicitly and share its methods. |
103 * In particular, object.equals() can be used to compare objects: | 107 * In particular, object.equals() can be used to compare objects: |
104 * | 108 * |
105 * var point1 = Point2D(5, 10); | 109 * var point1 = Point2D(5, 10); |
106 * var point2 = Point2D(6, 12); | 110 * var point2 = Point2D(6, 12); |
107 * console.log(point1.equals(point2)); // false | 111 * console.log(point1.equals(point2)); // false |
108 * console.log(point1.equals(point1)); // true | 112 * console.log(point1.equals(point1)); // true |
109 * | 113 * |
110 * Note that JavaScript comparison operators == and != won't always produce | 114 * Note that JavaScript comparison operators == and != won't always produce |
111 * correct results for typed objects. | 115 * correct results for typed objects. |
| 116 * |
| 117 * Array types |
| 118 * ----------- |
| 119 * |
| 120 * An array type can be created with any other type as element type: |
| 121 * |
| 122 * var uint8Array = uint8.Array(); |
| 123 * var array = uint8Array(); |
| 124 * array.length = 2; |
| 125 * array.set(0, 5); |
| 126 * array.set(1, 8); |
| 127 * |
| 128 * var Blob = ObjectType({ |
| 129 * name: uint8Array, |
| 130 * data: uint8Array |
| 131 * }); |
| 132 * var blob = Blob(); |
| 133 * blob.data = array; |
| 134 * array.release(); |
| 135 * |
| 136 * Array() function takes the same parameters as ObjectType(), meaning that an |
| 137 * array can have a constructor, destructor and custom properties or methods. |
| 138 * This also means that there can be multiple array types for each element type, |
| 139 * each Array() call will generate a new type that won't be compatible with |
| 140 * the other types. The metadata parameter for arrays can have the additional |
| 141 * arrayBufferSize property determining the number of array elements stored in |
| 142 * a single buffer (not the same as bufferSize property which applies to buffers |
| 143 * containing array metadata and custom array properties and determines the |
| 144 * number of arrays stored in these buffers). |
| 145 * |
| 146 * An array is an object meaning that it has the properties common for all |
| 147 * objects, in particular retain() and release() determining when the array is |
| 148 * garbage collected. In addition, it has the following properties and methods: |
| 149 * |
| 150 * get(index): retrieves the array element at specified index. |
| 151 * set(index, value): sets the array element at specified index. |
| 152 * length: number of elements in the array, by default 0. Increase the length |
| 153 * to match your data size. |
| 154 * size: size of the allocated buffer in array elements, will be at least |
| 155 * equal to length. Normally you won't need to set the size explicitly. |
| 156 * However, the size won't decrease automatically if the array gets |
| 157 * smaller so you might want to set it in order to shrink the array. |
112 */ | 158 */ |
113 | 159 |
114 function forwardExports(module) | 160 function forwardExports(module) |
115 { | 161 { |
116 let moduleExports = require(module); | 162 let moduleExports = require(module); |
117 for (let key in moduleExports) | 163 for (let key in moduleExports) |
118 exports[key] = moduleExports[key]; | 164 exports[key] = moduleExports[key]; |
119 } | 165 } |
120 | 166 |
121 forwardExports("typedObjects/primitiveTypes"); | 167 forwardExports("typedObjects/primitiveTypes"); |
122 forwardExports("typedObjects/objectTypes"); | 168 forwardExports("typedObjects/objectTypes"); |
OLD | NEW |