Skip to content

Commit

Permalink
Define JavaScript string and scalar value string
Browse files Browse the repository at this point in the history
And also surrogate code point, code unit, and cast (for strings). Fixes
#1.
  • Loading branch information
annevk committed Mar 17, 2017
1 parent f4d2de2 commit 9ad07c9
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions infra.bs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Boilerplate: omit conformance, omit feedback-header, omit idl-index
<pre class="anchors">
urlPrefix: https://tc39.github.io/ecma262/; spec: ECMA-262; type: dfn
text: List; url: sec-list-and-record-specification-type
text: The String Type; url: sec-ecmascript-language-types-string-type
</pre>


Expand Down Expand Up @@ -216,8 +217,11 @@ in parentheses. [[!UNICODE]]

<p>In certain contexts <a>code points</a> are prefixed with "0x" instead of "U+".

<p>A <dfn export>scalar value</dfn> is a <a>code point</a> that is not in the range
U+D800 to U+DFFF, inclusive.
<p>A <dfn export>surrogate code point</dfn> is a <a>code point</a> that is in the range U+D800 to
U+DFFF, inclusive.

<p>A <dfn export>scalar value</dfn> is a <a>code point</a> that is not a
<a>surrogate code point</a>.

<p>An <dfn export>ASCII code point</dfn> is a <a>code point</a> in the range U+0000 to U+007F,
inclusive.
Expand Down Expand Up @@ -258,11 +262,31 @@ inclusive.

<h3 id=strings>Strings</h3>

<p>A <dfn export>string</dfn> is a sequence of <a>code points</a>. Strings are denoted by double
quotes and monospace font.
<p>A <dfn export>JavaScript string</dfn> is a sequence of unsigned 16-bit integers, also known as
<dfn export lt="code unit">code units</dfn>. A <a>JavaScript string</a> can also be interpreted as
containing <a>code points</a>, per the conversion defined in <a>The String Type</a> section of the
JavaScript specification. [[!ECMA-262]]

<p>A <dfn export>scalar value string</dfn> is a sequence of <a>scalar values</a>. These
<a>scalar values</a> can also be addressed as <a>code points</a>.

<p class=note>A <a>scalar value string</a> is useful for any kind of I/O or other kind of operation
where <a>UTF-8 encode</a> comes into play.
<!-- It's also useful if you can imagine the subsystem to be implemented in Rust -->

<p><dfn export lt=string>String</dfn> can be used to refer to either a <a>JavaScript string</a> or
<a>scalar value string</a>, when it is clear from the context which is meant or when the distinction
is immaterial. <a>Strings</a> are denoted by double quotes and monospace font.

<p class=example id=example-string-notation>"<code>Hello, world!</code>" is a string.

<p>To <dfn export for=string>cast</dfn> a <a>JavaScript string</a> into a
<a>scalar value string</a>, replace any <a>surrogate code points</a> with U+FFFD.
<!-- Obviates need for https://heycam.github.io/webidl/#dfn-obtain-unicode -->

<p class=note><a for=string>Casting</a> a <a>scalar value string</a> into a <a>JavaScript string</a>
happens implicitly as desired as it is a lossless operation.

<p>An <dfn export>ASCII string</dfn> is a <a>string</a> whose <a>code points</a> are all
<a>ASCII code points</a>.

Expand Down

0 comments on commit 9ad07c9

Please sign in to comment.