https://codereview.appspot.com/12801043/diff/70001/tests/com/google/caja/plugin/test-taming-inout-guest.js
File tests/com/google/caja/plugin/test-taming-inout-guest.js (right):

https://codereview.appspot.com/12801043/diff/70001/tests/com/google/caja/plugin/test-taming-inout-guest.js#newcode189
tests/com/google/caja/plugin/test-taming-inout-guest.js:189:
tamedApi.tamedHostPureFunction('assertEquals("2", 3, a.byteLength);',
buf);
On 2013/10/22 22:40:48, ihab.awad wrote:
Was the assertion label supposed to be "3"?

Sorry, those were placeholders to just be able to distinguish the
asserts. All will have mutable labels in the next snapshot (not now due
to unresolved design question below).

https://codereview.appspot.com/12801043/diff/70001/tests/com/google/caja/plugin/test-taming-inout-guest.js#newcode204
tests/com/google/caja/plugin/test-taming-inout-guest.js:204:
tamedApi.tamedHostPureFunction('assertEquals("not mutated", 1, b[0]);',
a, b);
On 2013/10/22 22:40:48, ihab.awad wrote:
I don't understand the invariant that the above 2 lines are trying to
maintain. I'm even confused that they work! :)

In line 201, we mutate a feral clone of "a". Then in line 203, we
assert that
a *distinct* feral clone of "a" -- created by a *distinct* pass
through
untame() -- still carries the mutation?

I misread the original taming membrane code. I thought that untame()
*always* entered the feral twins it constructs in the membrane (which is
why the behavior tested here occurs), but I missed that there is a
special case for Arrays. Should these be treated like Arrays and copied
anew each time?

For:
- Users think of them as arrays, so this would be consistent
- It's plausible that they might be mutated and re-passed (reuse of
allocated storage), in which case we want to make copies with fresh
contents

Against:
- Very large buffers might be passed and be slow to copy repeatedly;
e.g. consider a 'parsing' API which returns many small slices of a large
buffer
- Copying each time would destroy all sharing that might be expected by
the recipient; e.g. a buffer/array provided for the callee's use that's
passed repeatedly rather than closed over.

The main browser API that works with typed arrays is WebGL, and its uses
are all of the sort "please grab a snapshot of this array contents and
upload it to the GPU", so it contains no useful precedent for
mutability/sharing choices.

What do you think the membrane should do?

In line 204, we assert that yet another *distinct* feral clone, of "b"
this
time, is *not* mutated. But should (feral clones of) "a" and "b" not
behave
exactly the same, since they share a buffer?

They don't share, because copyBuiltin copies the buffer when the array
is copied. We could untame() the buffer and get the behavior you
propose, unless we decide to copy every time as discussed above.

https://codereview.appspot.com/12801043/

--

--- 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/groups/opt_out.

Reply via email to