- From: Jonas Sicking <jonas@sicking.cc>
- Date: Wed, 19 Feb 2014 12:11:36 -0800
- To: Boris Zbarsky <bzbarsky@mit.edu>
- Cc: "Mark S. Miller" <erights@google.com>, "public-script-coord@w3.org" <public-script-coord@w3.org>
On Wed, Feb 19, 2014 at 9:01 AM, Boris Zbarsky <bzbarsky@mit.edu> wrote:
> For the record, the full set of
> standards-track things (so excluding gecko-specific stuff) affected by that
> change in Gecko is:
>
> 1) DedicatedWorkerGlobalScope.postMessage. Right now it requires
> explicitly passing a message, but with the change you could pass undefined
> by passing no arguments.
> 2) IDBCursor.update.
I think there are two separate questions here: "what behavior do we
want" and "what WebIDL syntax should we use". I think agreement on the
first question is needed before we can usefully debate the second
question.
Right now various objects have a `obj.postMessage(x)` method. The
value of the first argument is what is sent as a message to the
receiver.
Do we want `obj.postMessage()` to send the value `undefined`? It seems
a bit surprising to me that that doesn't throw an exception.
The argument that we've used in the past for treating `undefined` as
not-passed is to avoid people having to write code like:
function func(optArg1, optArg2) {
if (optArg1 === undefined) {
otherFunc1();
}
else {
otherFunc1(optArg1);
}
if (optArg2 === undefined) {
otherFunc2();
}
else {
otherFunc2(optArg2);
}
}
and instead write
function func(optArg1, optArg2) {
otherFunc1(optArg1);
otherFunc2(optArg2);
}
However the same argument doesn't seem to argue that
`obj.postMessage()` should be treated as `obj.postMessage(undefined)`.
I.e. you could still write
function func(optArg1, optArg2) {
obj.postMessage(optArg1);
otherObj.postMessage(optArg2);
}
Also, I don't think we'll ever have the invariant that not-passed is
always equivalent to `undefined` given functions like
function func(args...) {
return args.length;
}
So is it really intuitive that `postMessage()` sends the value
`undefined`? Or that `cursor.update()` writes the value `undefined` to
the database?
All that said, if someone were to implement postMessage or
cursor.update in JS rather than C++ the code would likely look
something like
function postMessage(data, otherArg) {
verifyData(data);
var s = serialize(data, otherArg);
_receiver.acceptSerializedData(s);
}
which means that calling `postMessage()` would be equivalent to
`postMessage(undefined)`. I.e. you could definitely argue that
treating not-passed and `undefined` as equivalent would be more
"javascripty".
Interested in hearing others' thoughts.
/ Jonas
Received on Wednesday, 19 February 2014 20:12:34 UTC