<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>15434</bug_id>
          
          <creation_ts>2012-01-05 21:44:12 +0000</creation_ts>
          <short_desc>[IndexedDB] Detail steps for assigning a key to a value</short_desc>
          <delta_ts>2012-02-29 17:47:55 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebAppsWG</product>
          <component>Indexed Database API</component>
          <version>unspecified</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>minor</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Joshua Bell">jsbell</reporter>
          <assigned_to name="Eliot Graff">eliotgra</assigned_to>
          <cc>eliotgra</cc>
    
    <cc>jonas</cc>
    
    <cc>mike</cc>
    
    <cc>public-webapps</cc>
          
          <qa_contact>public-webapps-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>62311</commentid>
    <comment_count>0</comment_count>
    <who name="Joshua Bell">jsbell</who>
    <bug_when>2012-01-05 21:44:12 +0000</bug_when>
    <thetext>In section 5.1 &quot;Object Store Storage Operation&quot;, step 2: when a key generator is used with store with in line keys, the spec says: &quot;set the property in value pointed to by store&apos;s key path to the new value for key&quot;

The &quot;steps for extracting a key from a value using a key path&quot; are called out explicitly under Algorithms in 4.7. Should the steps for assigning a key to a value using a key path be similarly documented? 

Cribbing from the spec, this could read as:

4.X Steps for assigning a key to a value using a key path

When taking the steps for assigning a key to a value using a key path, the implementation must run the following algorithm. The algorithm takes a key path named /keyPath/, a key named /key/, and a value named /value/ which may be modified by the steps of the algorithm.

1. If /keyPath/ is the empty string, skip the remaining steps and /value/ is not modified.
2. Let /remainingKeypath/ be /keyPath/ and /object/ be /value/.
3. If /remainingKeypath/ has a period in it, assign /remainingKeypath/ to be everything after the first period and assign /attribute/ to be everything before that first period. Otherwise, go to step 7.
4. If /object/ does not have an attribute named /attribute/, then skip the rest of these steps and /value/ is not modified.
5. Assign /object/ to be the /value/ of the attribute named /attribute/ on /object/.
6. Go to step 3.
7. NOTE: The steps leading here ensure that /remainingKeyPath/ is a single attribute name (i.e. string without periods) by this step.
8. Let /attribute/ be /remainingKeyPath/
9. If /object/ has an attribute named /attribute/ which is not modifiable, then skip the remaining steps and /value/ is not modified.
10. Set an attribute named /attribute/ on /object/ with the value /key/.

Notes: 

The above talks in terms of a mutable value. It could be amended to have an initial step which produces a clone of the value, which is later returned, but given how this algorithm is used the difference is not observable, since the value stored should already be a clone that doesn&apos;t have any other references.

Step 9 is present in case the key path refers to a &quot;special&quot; property, e.g. a String/Array length, Blob/File properties, etc.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>63090</commentid>
    <comment_count>1</comment_count>
    <who name="Jonas Sicking (Not reading bugmail)">jonas</who>
    <bug_when>2012-01-25 01:08:38 +0000</bug_when>
    <thetext>This is the set of steps people seemed to agree on after the thread in the mailing list:

1. Let /remainingKeypath/ be /keyPath/ and /object/ be /value/.
2. if /object/ is not an Object object or an Array object (see structured clone algorithm), then throw a DOMException of type DataError.
3. If /remainingKeypath/ has a period in it, assign /remainingKeypath/ to be everything after the first period and assign /attribute/ to be everything before that first period. Otherwise, go to step 7.
4. If /object/ does not have an attribute named /attribute/, then create the attribute and assign it an empty object.
5. Assign /object/ to be the value of the attribute named /attribute/ on /object/.
6. Go to step 2.
7. NOTE: The steps leading here ensure that /remainingKeyPath/ is a single attribute name (i.e. string without periods) by this step. They also ensure that /object/ is an Object or an Array, and not a Date, RegExp, Blob etc.
8. Let /attribute/ be /remainingKeyPath/
9. Set an attribute named /attribute/ on /object/ with the value /key/.

Note that the intent is that these steps are only executed if evaluating the keyPath did not yield a value. I.e. every time before we run these steps we evaluate the keyPath against /value/ and only if that does not yield a value (where &apos;undefined&apos; does count as a value) do we generate a key and use the above steps to modify /value/ to contain the generated key.

Because of this we know that at step 10 the object does not have an attribute with name /attribute/.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>64740</commentid>
    <comment_count>2</comment_count>
    <who name="Eliot Graff">eliotgra</who>
    <bug_when>2012-02-29 17:47:55 +0000</bug_when>
    <thetext>Changes live in the Editor&apos;s draft of 29 February.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>