- From: Maciej Stachowiak <mjs@apple.com>
- Date: Thu, 19 Nov 2009 14:35:31 -0800
- To: Joćo Eiras <joaoe@opera.com>
- Cc: "public-webapps@w3.org" <public-webapps@w3.org>
On Nov 19, 2009, at 2:12 PM, Joćo Eiras wrote:
>
> Hi everyone.
>
> Neither the web database specification, nor the IDL, specify the
> fine grained handling that implementation must do of the several
> possible values that can be passed in the 2nd argument to
> executeSql, considering that those ecmascript values need to be
> handled by the SQL engine, and therefore converted into a database
> compatible value.
>
> The only reference to the arguments is the paragraph that tell that
> the arguments should be replaced, but I've already asked that
> paragraph language to be reviewed in
> http://lists.w3.org/Archives/Public/public-webapps/2009JulSep/
> 1329.html
>
> Handling of ecmascript to database types could be done the following
> way:
> - numerical values would be converted to REAL
> - strings would be converted to TEXT, including the empty string
> - booleans would be converted to lowercase TEXT "false" or "true"
> - null and undefined would be handled as NULL
> - functions would be converted to TEXT
>
> Objects, which do not fit the primitive types about, can be handled
> in two ways.
>
> 1) The quick cheap way, which was already hinted, would be to
> convert them to string.
> However, that's not very helpful, if the object is a native type
> wrapper like:
> new String("aa");
> new Number(1);
> new Boolean(true)
>
> 2) We can define, in the Web IDL, how an object can be converted to
> a primitive type.
> Specifically, in an ecmascript binding we can do the following
> (note: returns means to stop the steps):
> - if object is null, return null
> - if object has a member function called valueOf, invoke valueOf in
> the context of object
> - if the returned value is a primitive type, return the value,
> - if object has a member function called toString, invoke toString
> in the context of object
> - if the returned value is a primitive type, return the value,
> - return Object.prototype.toString.call(object), so we get "[object
> Class]"
ECMAScript defines a ToPrimitive conversion (Section 9.1 of ECMA-262
5th edition). I think the right thing to do would be for some spec to
point to those steps. Probably it has to be Web Database, because in
many cases where a Web IDL method takes an "any" type, it's not
appropriate to do ToPrimitive conversion.
Regards,
Maciej
Received on Thursday, 19 November 2009 22:36:12 UTC