Re: [indexedDB] OptionalParameter question on IDBDatabase.createObjectStore

Jonas Sicking:
> At least in the indexedDB case we need to enumerate the object anyway
> since we want to throw if it contains any properties that we don't
> understand. This is for forwards compatible reasons.
> 
> Hence we automatically limit ourselves to enumerable properties, so
> toString wouldn't be a problem.

The way I’ve specified dictionaries, there is no way to know what other
properties might exist on the JS object.  If you defined

  dictionary ObjectStoreCreationOptions {
    DOMString keyPath = "";
    boolean autoIncrement = false;
  };

then the (IDL level) dictionary value will only ever have a keyPath and
an autoIncrement entry.

I could add a flag to the dictionary that indicates whether “unexpected”
properties were on the (language level) object, so that IndexedDB can
act upon it by throwing an exception.  I’m just not sure that this is a
common usage pattern of options objects in JS.  To me, the simplest use
of the properties on the options object would be:

  function createObjectStore(name, optionalParameters) {
    optionalParameters = optionalParameters || { };
    var keyPath = optionalParameters.keyPath || "";
    var autoIncrement = optionalParameters.autoIncrement;
    ...
  }

Doing:

  function createObjectStore(name, optionalParameters) {
    optionalParameters = optionalParameters || { };
    var keyPath = optionalParameters.keyPath || "";
    var autoIncrement = optionalParameters.autoIncrement;
    for (var key in optionalParameters) {
      if (key != "keyPath" && key != "autoIncrement") {
        throw ...;
      }
    }
    ...
  }

feels kind of unnecessary.  Are you thinking that authors will feature
test for new options by doing something like the following?

  try {
    createObjectStore("test", { newOption: 123 });
  } catch (e) {
    if (e.code == IDBDatabaseException.NON_TRANSIENT_ERR) {
      // fall back to something else that does use newOption
    }
  }

-- 
Cameron McCormack ≝ http://mcc.id.au/

Received on Tuesday, 31 May 2011 22:09:40 UTC