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 27 matching lines...) Expand all Loading... |
38 * | 38 * |
39 * The first parameter to ObjectType defines object properties and methods. A | 39 * The first parameter to ObjectType defines object properties and methods. A |
40 * name can either be associted with a type (property) or function (method). | 40 * name can either be associted with a type (property) or function (method). |
41 * Numeric value types from the ECMAScript Harmony proposal are predefined as | 41 * Numeric value types from the ECMAScript Harmony proposal are predefined as |
42 * well as "boolean" which is an alias for uint8. In addition to that, already | 42 * well as "boolean" which is an alias for uint8. In addition to that, already |
43 * defined object types can be used. | 43 * defined object types can be used. |
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. | 48 * is created. Parameters supplied during object creation will be passed |
| 49 * to the constructor. |
| 50 * destructor: function that will be called when an object of the type is |
| 51 * freed. |
49 * 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 |
50 * buffer (by default 128). | 53 * buffer (by default 128). |
51 * | 54 * |
52 * Creating an object instance | 55 * Creating and releasing an object instance |
53 * --------------------------- | 56 * ----------------------------------------- |
54 * | 57 * |
55 * var point = Point2D(5, 10); | 58 * var point = Point2D(5, 10); |
56 * point.rotate(10); | 59 * point.rotate(10); |
57 * Console.log(point.x + ", " + point.y); | 60 * console.log(point.x + ", " + point.y); |
58 * | 61 * |
59 * The parameters 5 and 10 will be passed to the constructor function defined | 62 * The parameters 5 and 10 will be passed to the constructor function defined |
60 * for this type. | 63 * for this type. |
61 * | 64 * |
| 65 * Once the object instance is no longer needed it should be released: |
| 66 * |
| 67 * point.release(); |
| 68 * |
| 69 * This will not necessarily free the object but merely decrease its reference |
| 70 * count. The object will only be freed when its reference count reaches zero. |
| 71 * |
| 72 * If you need to hold on to an object that you didn't create (e.g. a function |
| 73 * parameter) you have to call object.retain() to increase its reference count. |
| 74 * Once the object is no longer needed you should call object.release(). |
| 75 * However, it is preferable to use references from other typed objects to hold |
| 76 * on to an object - the necessary reference count increases and decreases will |
| 77 * be performed automatically then. |
| 78 * |
62 * Type inheritance | 79 * Type inheritance |
63 * ---------------- | 80 * ---------------- |
64 * | 81 * |
65 * var Point3D = Point2D.extend({ | 82 * var Point3D = Point2D.extend({ |
66 * z: uint32 | 83 * z: uint32 |
67 * }, { | 84 * }, { |
68 * constructor: function(super_, x, y, z) | 85 * constructor: function(super_, x, y, z) |
69 * { | 86 * { |
70 * super_(x, y); | 87 * super_(x, y); |
71 * ... | 88 * ... |
(...skipping 24 matching lines...) Expand all Loading... |
96 | 113 |
97 function forwardExports(module) | 114 function forwardExports(module) |
98 { | 115 { |
99 let moduleExports = require(module); | 116 let moduleExports = require(module); |
100 for (let key in moduleExports) | 117 for (let key in moduleExports) |
101 exports[key] = moduleExports[key]; | 118 exports[key] = moduleExports[key]; |
102 } | 119 } |
103 | 120 |
104 forwardExports("typedObjects/primitiveTypes"); | 121 forwardExports("typedObjects/primitiveTypes"); |
105 forwardExports("typedObjects/objectTypes"); | 122 forwardExports("typedObjects/objectTypes"); |
OLD | NEW |