Index: lib/typedObjects/utils.js |
=================================================================== |
--- a/lib/typedObjects/utils.js |
+++ b/lib/typedObjects/utils.js |
@@ -90,19 +90,20 @@ let getViewsForType = exports.getViewsFo |
/** |
* Defines properties with given name and type on an object. |
* |
* @param obj object to define properties on |
* @param properties object mapping property names to their respective types |
* @param viewTypes see getViewsForType() |
* @param views see getViewsForType() |
* @param [offset] byte array offset at which the properties should start |
+ * @param [cleanupValues] array of property/value combinations to be set when the object is created or destroyed |
* @return new start offset for additional properties |
*/ |
-exports.defineProperties = function defineProperties(obj, properties, viewTypes, views, offset) |
+exports.defineProperties = function defineProperties(obj, properties, viewTypes, views, offset, cleanupValues) |
{ |
offset = offset | 0; |
let propList = []; |
for (let name in properties) |
propList.push([name, properties[name]]); |
// Put larger properties first to make sure alignment requirements are met. |
@@ -120,15 +121,17 @@ exports.defineProperties = function defi |
let viewParams = getViewsForType(type, viewTypes, views); |
descriptors[name] = { |
get: type.createGetter.apply(type, [offset].concat(viewParams)), |
set: type.createSetter.apply(type, [offset].concat(viewParams)), |
configurable: false, |
enumerable: true |
}; |
offset += type.referenceLength; |
+ if (cleanupValues && typeof type.cleanupValue != "undefined") |
+ cleanupValues.push([name, type.cleanupValue]); |
} |
// Define properties |
Object.defineProperties(obj, descriptors); |
return offset; |
}; |