On Mon, Jul 28, 2014 at 7:00 PM, Tim Shnaider <[email protected]> wrote:
> If event = [], I can not call any methods such as push:
>
> function timerFired(event) {
> event.push(1);
> }
>
> => TypeError: Can't add property 0, object is not extensible
>
> Do I need to provide special wrappers for Arrays that have marked
> methods/properties?
>
> Essentially I want to pass a regular array back and forth between host and
> guest, that can be manipulated by either, and retains standard Array
> functionality.
>
Unfortunately, the taming membrane's design prohibits what you want to do
here. Arrays and plain objects are always _copied_, and changes on one side
will not be reflected on the other. (The error you are seeing is not
because the 'push' method is unavailable, but because the array you get
from the membrane has been made unmodifiable.) This was done because with
the current baseline of browser functionality it is essentially impossible
to reliably mirror an array across the membrane (since it has an unbounded
set of property names).
In order to share something modifiable between the two sides of the
membrane, make an object with methods (which can have internal state which
is an array, if you want — it doesn't matter to the membrane). If you do
this on the host side you'll need to mark its methods; on the guest side it
should automatically work when accessed from the host.
--
---
You received this message because you are subscribed to the Google Groups
"Google Caja Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.