[WebIDL] Converting non-objects to Dictionaries.

Consider the following WebIDL:

dictionary FooOptions {
 boolean reverse = false;
 unsigned long limit;
};

interface Foo {
  void someFunc(in DOMString name, optional in FooOptions options);
};


This creates an API that is intended to be called like:

myfoo.someFunc("name", { reverse: true });

however, as currently defined, you can call it with:

myfoo.someFunc("name", 4);

The dictionary algorithm will convert the '4' to an object and then
attempt to read properties off that object. However since the object
won't have any properties, all properties in the dictionary will get
their default value. In other words, the above is equivalent to

myfoo.someFunc("name", {});
and
myfoo.someFunc("name");

It seems to very likely that if someone passes in a non-object, they
have a bug in their code and we would do them a bigger service by
throwing an exception than silently ignoring their argument.

This does leave the question what to do for something like:

myfoo.someFunc("name", null);
and
myfoo.someFunc("name", undefined);

It seems useful to me to allow both these and use the default values
in both cases. For example for code that looks like:

function myDoStuffFunc(name, options) {
  getFooObj().someFunc(name, options);
}

/ Jonas

Received on Thursday, 21 July 2011 19:23:11 UTC