Skip to content

Commit

Permalink
Use HTML's StructuredSerializeForStorage (Fixes #197 and #152)
Browse files Browse the repository at this point in the history
  • Loading branch information
inexorabletash authored May 2, 2017
1 parent f659e17 commit 2aef49f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
17 changes: 11 additions & 6 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ stored and retrieved by value rather than by reference; later changes
to a value have no effect on the record stored in the database.

Record [=/values=] are [=/Records=] output by the
<a abstract-op>StructuredSerialize</a> operation.
<a abstract-op>StructuredSerializeForStorage</a> operation.


<!-- ============================================================ -->
Expand Down Expand Up @@ -797,7 +797,7 @@ from a [=/value=]. A <dfn>valid key path</dfn> is one of:
</aside>

[=/Key path=] values can only be accessed from properties explicitly
copied by <a abstract-op>StructuredSerialize</a>, as well as the
copied by <a abstract-op>StructuredSerializeForStorage</a>, as well as the
following type-specific properties:

<table class=props>
Expand Down Expand Up @@ -5817,7 +5817,7 @@ the implementation must run the following steps:
To make a <dfn>clone</dfn> of |value| in |targetRealm|,
the implementation must run the following steps:

1. Let |serialized| be [=?=] <a abstract-op>StructuredSerialize</a>(|value|).
1. Let |serialized| be [=?=] <a abstract-op>StructuredSerializeForStorage</a>(|value|).

2. Let |clone| be [=?=] <a abstract-op>StructuredDeserialize</a>(|serialized|, |targetRealm|).

Expand All @@ -5839,7 +5839,7 @@ a request=].
Invocations of <a abstract-op>StructuredDeserialize</a>() in the operation
steps below can be asserted not to throw (as indicated by the [=!=] prefix)
because they operate only on previous output of
<a abstract-op>StructuredSerialize</a>().
<a abstract-op>StructuredSerializeForStorage</a>().
</aside>

<!-- ============================================================ -->
Expand Down Expand Up @@ -5881,7 +5881,7 @@ follows.
steps to [=delete records from an object store=].

4. Store a record in |store| containing |key| as its key and
[=!=] <a abstract-op>StructuredSerialize</a>(|value|)
[=!=] <a abstract-op>StructuredSerializeForStorage</a>(|value|)
as its value. The record is stored in the object store's
[=object-store/list of records=] such that the list is sorted
according to the key of the records in [=ascending=] order.
Expand Down Expand Up @@ -7022,7 +7022,7 @@ basic serialization concerns, serialized data could encode assumptions
which are not valid in newer versions of the user agent.

A practical example of this is the [=RegExp=] type. The <a
abstract-op>StructuredSerialize</a> operation allows serializing [=RegExp=]
abstract-op>StructuredSerializeForStorage</a> operation allows serializing [=RegExp=]
objects. A typical user agent will compile a regular expression into
native machine instructions, with assumptions about how the input data
is passed and results returned. If this internal state was serialized
Expand Down Expand Up @@ -7156,6 +7156,11 @@ document's Revision History</a>.
the [=asynchronously execute a request=] steps.
(<a href="https://github.com/w3c/IndexedDB/issues/192">issue #192</a>)

* Use [[HTML]]'s <a abstract-op>StructuredSerializeForStorage</a>
hook.
(<a href="https://github.com/w3c/IndexedDB/issues/197">issue #197</a>,
<a href="https://github.com/w3c/IndexedDB/issues/197">issue #152</a>)


<!-- ============================================================ -->
<h2 id=acknowledgements>Acknowledgements</h2>
Expand Down
22 changes: 13 additions & 9 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,7 @@
}
}
</style>
<meta content="Bikeshed version aa692b5bb18791d7660cd494994fd0ac2ec23132" name="generator">
<meta content="Bikeshed version 5bd73bb15eb04ad9f7d1a57f012e9ee6eca5a765" name="generator">
<link href="https://www.w3.org/TR/IndexedDB-2/" rel="canonical">
<link href="logo-db.png" rel="icon">
<style>
Expand Down Expand Up @@ -1459,7 +1459,7 @@
<div class="head">
<p data-fill-with="logo"><a class="logo" href="https://www.w3.org/"> <img alt="W3C" height="48" src="https://www.w3.org/StyleSheets/TR/2016/logos/W3C" width="72"> </a> </p>
<h1 class="p-name no-ref" id="title">Indexed Database API 2.0</h1>
<h2 class="no-num no-toc no-ref heading settled" id="subtitle"><span class="content">Editor’s Draft, <time class="dt-updated" datetime="2017-04-21">21 April 2017</time></span></h2>
<h2 class="no-num no-toc no-ref heading settled" id="subtitle"><span class="content">Editor’s Draft, <time class="dt-updated" datetime="2017-05-01">1 May 2017</time></span></h2>
<div data-fill-with="spec-metadata">
<dl>
<dt>This version:
Expand Down Expand Up @@ -1983,7 +1983,7 @@ <h3 class="heading settled" data-level="2.3" id="value-construct"><span class="s
such as <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-terms-and-definitions-string-type">String</a> primitive values and <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-date-objects">Date</a> objects as well as <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-object-objects">Object</a> and <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-array-objects">Array</a> instances, <code class="idl"><a data-link-type="idl" href="https://w3c.github.io/FileAPI/#dfn-file">File</a></code> objects, <code class="idl"><a data-link-type="idl" href="https://w3c.github.io/FileAPI/#dfn-Blob">Blob</a></code> objects, <code class="idl"><a data-link-type="idl" href="https://html.spec.whatwg.org/multipage/scripting.html#imagedata">ImageData</a></code> objects, and so on. Record <a data-link-type="dfn" href="#value" id="ref-for-value-3">values</a> are
stored and retrieved by value rather than by reference; later changes
to a value have no effect on the record stored in the database.</p>
<p>Record <a data-link-type="dfn" href="#value" id="ref-for-value-4">values</a> are <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-list-and-record-specification-type">Records</a> output by the <a data-link-type="abstract-op" href="https://html.spec.whatwg.org/multipage/infrastructure.html#structuredserialize">StructuredSerialize</a> operation.</p>
<p>Record <a data-link-type="dfn" href="#value" id="ref-for-value-4">values</a> are <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-list-and-record-specification-type">Records</a> output by the <a data-link-type="abstract-op" href="https://html.spec.whatwg.org/multipage/infrastructure.html#structuredserializeforstorage">StructuredSerializeForStorage</a> operation.</p>
<h3 class="heading settled" data-level="2.4" id="key-construct"><span class="secno">2.4. </span><span class="content">Keys</span><a class="self-link" href="#key-construct"></a></h3>
<p>In order to efficiently retrieve <a data-link-type="dfn" href="#object-store-record" id="ref-for-object-store-record-2">records</a> stored in an indexed
database, each <a data-link-type="dfn" href="#object-store-record" id="ref-for-object-store-record-3">record</a> is organized according to its <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="key">key</dfn>.</p>
Expand Down Expand Up @@ -2187,7 +2187,7 @@ <h3 class="heading settled" data-level="2.5" id="key-path-construct"><span class
</ul>
<aside class="note"> Spaces are not allowed within a key path. </aside>
<p><a data-link-type="dfn" href="#key-path" id="ref-for-key-path-1">Key path</a> values can only be accessed from properties explicitly
copied by <a data-link-type="abstract-op" href="https://html.spec.whatwg.org/multipage/infrastructure.html#structuredserialize">StructuredSerialize</a>, as well as the
copied by <a data-link-type="abstract-op" href="https://html.spec.whatwg.org/multipage/infrastructure.html#structuredserializeforstorage">StructuredSerializeForStorage</a>, as well as the
following type-specific properties:</p>
<table class="props">
<tbody>
Expand Down Expand Up @@ -5615,7 +5615,7 @@ <h3 class="heading settled" data-level="5.11" id="clone-value"><span class="secn
the implementation must run the following steps:</p>
<ol>
<li data-md="">
<p>Let <var>serialized</var> be <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-algorithm-conventions">?</a> <a data-link-type="abstract-op" href="https://html.spec.whatwg.org/multipage/infrastructure.html#structuredserialize">StructuredSerialize</a>(<var>value</var>).</p>
<p>Let <var>serialized</var> be <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-algorithm-conventions">?</a> <a data-link-type="abstract-op" href="https://html.spec.whatwg.org/multipage/infrastructure.html#structuredserializeforstorage">StructuredSerializeForStorage</a>(<var>value</var>).</p>
<li data-md="">
<p>Let <var>clone</var> be <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-algorithm-conventions">?</a> <a data-link-type="abstract-op" href="https://html.spec.whatwg.org/multipage/infrastructure.html#structureddeserialize">StructuredDeserialize</a>(<var>serialized</var>, <var>targetRealm</var>).</p>
<li data-md="">
Expand All @@ -5628,7 +5628,7 @@ <h2 class="heading settled" data-level="6" id="database-operations"><span class=
a request</a>.</p>
<aside class="note"> Invocations of <a data-link-type="abstract-op" href="https://html.spec.whatwg.org/multipage/infrastructure.html#structureddeserialize">StructuredDeserialize</a>() in the operation
steps below can be asserted not to throw (as indicated by the <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-algorithm-conventions">!</a> prefix)
because they operate only on previous output of <a data-link-type="abstract-op" href="https://html.spec.whatwg.org/multipage/infrastructure.html#structuredserialize">StructuredSerialize</a>(). </aside>
because they operate only on previous output of <a data-link-type="abstract-op" href="https://html.spec.whatwg.org/multipage/infrastructure.html#structuredserializeforstorage">StructuredSerializeForStorage</a>(). </aside>
<h3 class="heading settled" data-level="6.1" id="object-store-storage-operation"><span class="secno">6.1. </span><span class="content">Object Store Storage Operation</span><a class="self-link" href="#object-store-storage-operation"></a></h3>
<div class="algorithm">
<p>The steps to <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport="" id="store-a-record-into-an-object-store">store a record into an object store</dfn> with <var>store</var>, <var>value</var>, an optional <var>key</var>, and a <var>no-overwrite flag</var> are as
Expand Down Expand Up @@ -5663,7 +5663,7 @@ <h3 class="heading settled" data-level="6.1" id="object-store-storage-operation"
to</a> <var>key</var>, then remove the <a data-link-type="dfn" href="#object-store-record" id="ref-for-object-store-record-80">record</a> from <var>store</var> using the
steps to <a data-link-type="dfn" href="#delete-records-from-an-object-store" id="ref-for-delete-records-from-an-object-store-3">delete records from an object store</a>.</p>
<li data-md="">
<p>Store a record in <var>store</var> containing <var>key</var> as its key and <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-algorithm-conventions">!</a> <a data-link-type="abstract-op" href="https://html.spec.whatwg.org/multipage/infrastructure.html#structuredserialize">StructuredSerialize</a>(<var>value</var>)
<p>Store a record in <var>store</var> containing <var>key</var> as its key and <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-algorithm-conventions">!</a> <a data-link-type="abstract-op" href="https://html.spec.whatwg.org/multipage/infrastructure.html#structuredserializeforstorage">StructuredSerializeForStorage</a>(<var>value</var>)
as its value. The record is stored in the object store’s <a data-link-type="dfn" href="#object-store-list-of-records" id="ref-for-object-store-list-of-records-1">list of records</a> such that the list is sorted
according to the key of the records in <a data-link-type="dfn" href="#greater-than" id="ref-for-greater-than-9">ascending</a> order.</p>
<li data-md="">
Expand Down Expand Up @@ -6576,7 +6576,7 @@ <h3 class="heading settled" data-level="9.4" id="persistence-risks"><span class=
handling of older data can result in security issues. In addition to
basic serialization concerns, serialized data could encode assumptions
which are not valid in newer versions of the user agent.</p>
<p>A practical example of this is the <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-regexp-regular-expression-objects">RegExp</a> type. The <a data-link-type="abstract-op" href="https://html.spec.whatwg.org/multipage/infrastructure.html#structuredserialize">StructuredSerialize</a> operation allows serializing <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-regexp-regular-expression-objects">RegExp</a> objects. A typical user agent will compile a regular expression into
<p>A practical example of this is the <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-regexp-regular-expression-objects">RegExp</a> type. The <a data-link-type="abstract-op" href="https://html.spec.whatwg.org/multipage/infrastructure.html#structuredserializeforstorage">StructuredSerializeForStorage</a> operation allows serializing <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-regexp-regular-expression-objects">RegExp</a> objects. A typical user agent will compile a regular expression into
native machine instructions, with assumptions about how the input data
is passed and results returned. If this internal state was serialized
as part of the data stored to the database, various problems could
Expand Down Expand Up @@ -6686,6 +6686,9 @@ <h2 class="heading settled" data-level="10" id="revision-history"><span class="s
<p>Transaction-is-<a data-link-type="dfn" href="#transaction-active" id="ref-for-transaction-active-44">active</a> test can be an assertion in
the <a data-link-type="dfn" href="#asynchronously-execute-a-request" id="ref-for-asynchronously-execute-a-request-27">asynchronously execute a request</a> steps.
(<a href="https://github.com/w3c/IndexedDB/issues/192">issue #192</a>)</p>
<li data-md="">
<p>Use <a data-link-type="biblio" href="#biblio-html">[HTML]</a>'s <a data-link-type="abstract-op" href="https://html.spec.whatwg.org/multipage/infrastructure.html#structuredserializeforstorage">StructuredSerializeForStorage</a> hook.
(<a href="https://github.com/w3c/IndexedDB/issues/197">issue #197</a>, <a href="https://github.com/w3c/IndexedDB/issues/197">issue #152</a>)</p>
</ul>
<h2 class="heading settled" data-level="11" id="acknowledgements"><span class="secno">11. </span><span class="content">Acknowledgements</span><a class="self-link" href="#acknowledgements"></a></h2>
<p>Special thanks to Nikunj Mehta, the original author of the first
Expand Down Expand Up @@ -7322,6 +7325,7 @@ <h3 class="no-num no-ref heading settled" id="index-defined-elsewhere"><span cla
<li><a href="https://html.spec.whatwg.org/multipage/scripting.html#imagedata">ImageData</a>
<li><a href="https://html.spec.whatwg.org/multipage/infrastructure.html#structureddeserialize">StructuredDeserialize</a>
<li><a href="https://html.spec.whatwg.org/multipage/infrastructure.html#structuredserialize">StructuredSerialize</a>
<li><a href="https://html.spec.whatwg.org/multipage/infrastructure.html#structuredserializeforstorage">StructuredSerializeForStorage</a>
<li><a href="https://html.spec.whatwg.org/multipage/webappapis.html#windoworworkerglobalscope">WindowOrWorkerGlobalScope</a>
<li><a href="https://html.spec.whatwg.org/multipage/browsers.html#browsing-context">browsing context</a>
<li><a href="https://html.spec.whatwg.org/multipage/browsers.html#dom-document-domain">domain</a>
Expand Down Expand Up @@ -7392,7 +7396,7 @@ <h3 class="no-num no-ref heading settled" id="normative"><span class="content">N
<dt id="biblio-rfc2119">[RFC2119]
<dd>S. Bradner. <a href="https://tools.ietf.org/html/rfc2119">Key words for use in RFCs to Indicate Requirement Levels</a>. March 1997. Best Current Practice. URL: <a href="https://tools.ietf.org/html/rfc2119">https://tools.ietf.org/html/rfc2119</a>
<dt id="biblio-webidl">[WEBIDL]
<dd>Cameron McCormack; Boris Zbarsky; Tobie Langel. <a href="https://www.w3.org/TR/WebIDL-1/">Web IDL</a>. URL: <a href="https://www.w3.org/TR/WebIDL-1/">https://www.w3.org/TR/WebIDL-1/</a>
<dd>Cameron McCormack; Boris Zbarsky; Tobie Langel. <a href="https://heycam.github.io/webidl/">Web IDL</a>. URL: <a href="https://heycam.github.io/webidl/">https://heycam.github.io/webidl/</a>
</dl>
<h3 class="no-num no-ref heading settled" id="informative"><span class="content">Informative References</span><a class="self-link" href="#informative"></a></h3>
<dl>
Expand Down

0 comments on commit 2aef49f

Please sign in to comment.