[widgets] Storage keys and ECMAScript incompatibility?
We've come across an issue with storage keys in Widget preferences; namely that the Web Storage spec [1] states that: Keys are strings. Any string (including the empty string) is a valid key. Values can be any data type supported by the structured clone algorithm. However, common guidance on JavaScript states that: Variable names must begin with a letter or the underscore character ECMAScript[3] follows the Unicode identifier syntax[4], which defines variable names as starting with: Characters having the Unicode General_Category of uppercase letters (Lu), lowercase letters (Ll), titlecase letters (Lt), modifier letters (Lm), other letters (Lo), letter numbers (Nl), minus Pattern_Syntax and Pattern_White_Space code points, plus stability extensions So we get into problems using keys that begin with digits, which are allowed as far as I can tell in WebStorage and Widgets, but not in ECMAScript, and things like widgets.preferences.12345=xyz throw exceptions. [1] http://www.w3.org/TR/webstorage/ [2] http://www.w3schools.com/js/js_variables.asp [3] http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf [4] http://unicode.org/reports/tr31/ smime.p7s Description: S/MIME cryptographic signature
Re: [widgets] Storage keys and ECMAScript incompatibility?
On Wed, Dec 15, 2010 at 3:29 PM, Scott Wilson scott.bradley.wil...@gmail.com wrote: things like widgets.preferences.12345=xyz throw exceptions. widgets.preferences[12345]=xyz probably works...
Re: [widgets] Storage keys and ECMAScript incompatibility?
On Wed, Dec 15, 2010 at 5:29 AM, Scott Wilson scott.bradley.wil...@gmail.com wrote: We've come across an issue with storage keys in Widget preferences; namely that the Web Storage spec [1] states that: Keys are strings. Any string (including the empty string) is a valid key. Values can be any data type supported by the structured clone algorithm. However, common guidance on JavaScript states that: Variable names must begin with a letter or the underscore character ECMAScript[3] follows the Unicode identifier syntax[4], which defines variable names as starting with: Characters having the Unicode General_Category of uppercase letters (Lu), lowercase letters (Ll), titlecase letters (Lt), modifier letters (Lm), other letters (Lo), letter numbers (Nl), minus Pattern_Syntax and Pattern_White_Space code points, plus stability extensions So we get into problems using keys that begin with digits, which are allowed as far as I can tell in WebStorage and Widgets, but not in ECMAScript, and things like widgets.preferences.12345=xyz throw exceptions. timeless got it. Only a subset of possible keys can be used in the dot syntax. Everything else can be used in the array notation instead. This is perfectly fine. ~TJ
Re: [widgets] Storage keys and ECMAScript incompatibility?
On 15 Dec 2010, at 15:50, Tab Atkins Jr. wrote: On Wed, Dec 15, 2010 at 5:29 AM, Scott Wilson scott.bradley.wil...@gmail.com wrote: We've come across an issue with storage keys in Widget preferences; namely that the Web Storage spec [1] states that: Keys are strings. Any string (including the empty string) is a valid key. Values can be any data type supported by the structured clone algorithm. However, common guidance on JavaScript states that: Variable names must begin with a letter or the underscore character ECMAScript[3] follows the Unicode identifier syntax[4], which defines variable names as starting with: Characters having the Unicode General_Category of uppercase letters (Lu), lowercase letters (Ll), titlecase letters (Lt), modifier letters (Lm), other letters (Lo), letter numbers (Nl), minus Pattern_Syntax and Pattern_White_Space code points, plus stability extensions So we get into problems using keys that begin with digits, which are allowed as far as I can tell in WebStorage and Widgets, but not in ECMAScript, and things like widgets.preferences.12345=xyz throw exceptions. timeless got it. Only a subset of possible keys can be used in the dot syntax. Everything else can be used in the array notation instead. This is perfectly fine. ~TJ OK, we'll implement using array notation instead. Thanks! smime.p7s Description: S/MIME cryptographic signature
Re: [widgets] Storage keys and ECMAScript incompatibility?
note that i should have said: widgets.preferences[12345]=xyz probably works... since other reserved words don't work well unquoted... and obviously if your identifier includes , ', or \, you may need to quote it or escape it appropriately...