Wrapper objects have a prototype of Object.prototype. This is especially unfortunate when attempting to wrap arrays.
Suggested behaviour
Wrapper objects should have a prototype which is a proxy for the prototype of the object being wrapped.
The prototype proxy should output observations when the prototype is accessed or changed, etc.
These should be stored under a top-level "prototype" key in the observation data format described in the wiki
I don't think it is desirable to recursively wrap the prototype chains of objects in most cases. However, wrapper code should accept a parameter indicating the depth to which the prototype chain of the object should be wrapped.
-1 = Recursively wrap prototypes, stopping when encountering a prototype which is a built-in object.
Storing a list of built-in objects may introduce problems in the future (as JavaScript continues to evolve)
0 = Observe the prototype as though it is a primitive property (default)
1 = Fully wrap the prototype (wrapping its properties when they are accessed, for instance), but treat its prototype as a primitive property.
2 = Fully wrap the prototype and its prototype
and so forth.
Arrays
The library should be able to wrap arrays, such that all array methods are available from the wrapper object (due to the wrapper having a reference to Array.prototype).
Check if the length property of an array is handled properly
I think it is a good idea to report manual changes to length performed by the client code.
Make sure that length still changes automatically when the wrapper array object is modified by methods like push(). In these cases, there should not be additional observation events output reporting changes to length, as such events can be inferred from the other changes to the array.
Current behaviour
Object.prototype
. This is especially unfortunate when attempting to wrap arrays.Suggested behaviour
-1
= Recursively wrap prototypes, stopping when encountering a prototype which is a built-in object.0
= Observe the prototype as though it is a primitive property (default)1
= Fully wrap the prototype (wrapping its properties when they are accessed, for instance), but treat its prototype as a primitive property.2
= Fully wrap the prototype and its prototypeArrays
Array.prototype
).length
property of an array is handled properlylength
performed by the client code.length
still changes automatically when the wrapper array object is modified by methods likepush()
. In these cases, there should not be additional observation events output reporting changes tolength
, as such events can be inferred from the other changes to the array.