domita.js has the following:

    defProperty(
        TameInputElement, 'value',
        false, function (x) { return x == null ? null : String(x); },
        false, function (x) { return x == null ? '' : '' + x; });
    defProperty(
        TameInputElement, 'defaultValue',
        false, function (x) { return x == null ? null : String(x); },
        false, function (x) { return x == null ? '' : '' + x; });

The functions passed to defProperty are used to transform the value from the 
real DOM before passing it to the sandboxed code on a property read, and to 
transform the value passed by sandbox code on a property write, respectively.

1. Why does this preserve null as null on read, but transform it to the empty 
string on write?

2. I have learned that the difference between String(x) and '' + x is that '' + 
x passes on the result of x.valueOf() rather than producing x.toString(), and 
it could be the case that it is desirable to let valueOf() happen for sandboxed 
code but not allow sandboxed code to get its hands on a non-string from outside 
the sandbox, but if this is so, why do several other places in Domita have 
defProperty(..., String), i.e. using String as the write transformer, so not 
permitting this?

-- 
Kevin Reid                                  <http://switchb.org/kpreid/>

Reply via email to