--- /dev/null
+<html><head><link rel="stylesheet" type="text/css" href="css/book.css"/><link rel="stylesheet" type="text/css" href="css/highlight.css"/><link rel="stylesheet" type="text/css" href="css/console.css"/><link rel="stylesheet" type="text/css" href="css/codemirror.css"/><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><title>Print Version -- Eloquent JavaScript</title></head><body><div class="content"><h1><span class="number">Chapter 1: </span>Introduction</h1><div class="block"><p><a class="paragraph" href="#p791f9bee86072a50" name="p791f9bee86072a50"> </a>When personal computers were first introduced, most of them came
+equipped with a simple programming language, usually a variant of
+<a name="key1"></a>BASIC. Interacting with the computer was closely integrated with
+this language, and thus every computer-user, whether he wanted to or
+not, would get a taste of it. Now that computers have become plentiful
+and cheap, typical users don't get much further than clicking things
+with a mouse. For most people, this works very well. But for those of
+us with a natural inclination towards technological tinkering, the
+removal of programming from every-day computer use presents something
+of a barrier.</p><p><a class="paragraph" href="#p4adc934200807fbb" name="p4adc934200807fbb"> </a>Fortunately, as an effect of developments in the World Wide Web, it so
+happens that every computer equipped with a modern web-browser also
+has an environment for programming JavaScript. In today's spirit of
+not bothering the user with technical details, it is kept well hidden,
+but a web-page can make it accessible, and use it as a platform for
+learning to program.</p><p><a class="paragraph" href="#pe15267081702eb5" name="pe15267081702eb5"> </a>That is what this (hyper-)book tries to do.</p></div><hr/><div class="block"><blockquote>I do not enlighten those who are not eager to learn, nor arouse those
+who are not anxious to give an explanation themselves. If I have
+presented one corner of the square and they cannot come back to me
+with the other three, I should not go over the points again.<br/><br/>― Confucius</blockquote><p><a class="paragraph" href="#p7168e82dd605bf59" name="p7168e82dd605bf59"> ¶ </a>Besides explaining JavaScript, this book tries to be an introduction
+to the basic principles of programming. Programming, it turns out, is
+hard. The fundamental rules are, most of the time, simple and clear.
+But programs, while built on top of these basic rules, tend to become
+complex enough to introduce their own rules, their own complexity.
+Because of this, programming is rarely simple or predictable. As
+Donald Knuth, who is something of a founding father of the field,
+says, it is an <em>art</em>.</p><p><a class="paragraph" href="#p2849f125de87d3b5" name="p2849f125de87d3b5"> </a>To get something out of this book, more than just passive reading is
+required. Try to stay sharp, make an effort to solve the exercises,
+and only continue on when you are reasonably sure you understand the
+material that came before.</p></div><hr/><div class="block"><blockquote>The computer programmer is a creator of universes for which he alone
+is responsible. Universes of virtually unlimited complexity can be
+created in the form of computer programs.<br/><br/>― Joseph Weizenbaum, <em>Computer Power and Human Reason</em></blockquote><p><a class="paragraph" href="#p6fd53be181d82388" name="p6fd53be181d82388"> ¶ </a>A program is many things. It is a piece of text typed by a programmer,
+it is the directing force that makes the computer do what it does, it
+is data in the computer's memory, yet it controls the actions
+performed on this same memory. Analogies that try to compare programs
+to objects we are familiar with tend to fall short, but a
+superficially fitting one is that of a machine. The gears of a
+mechanical watch fit together ingeniously, and if the watchmaker was
+any good, it will accurately show the time for many years. The
+elements of a program fit together in a similar way, and if the
+programmer knows what he is doing, the program will run without
+crashing.</p><p><a class="paragraph" href="#p48ff3e75bab11884" name="p48ff3e75bab11884"> </a>A computer is a machine built to act as a host for these immaterial
+machines. Computers themselves can only do stupidly straightforward
+things. The reason they are so useful is that they do these things at
+an incredibly high speed. A program can, by ingeniously combining many
+of these simple actions, do very complicated things.</p><p><a class="paragraph" href="#p1ff6d46adeaed61b" name="p1ff6d46adeaed61b"> </a>To some of us, writing computer programs is a fascinating game. A
+program is a building of thought. It is costless to build, weightless,
+growing easily under our typing hands. If we get carried away, its
+size and complexity will grow out of control, confusing even the one
+who created it. This is the main problem of programming. It is why so
+much of today's software tends to crash, fail, screw up.</p><p><a class="paragraph" href="#p5a4281d62a20af99" name="p5a4281d62a20af99"> </a>When a program works, it is beautiful. The art of programming is the
+skill of controlling complexity. The great program is subdued, made
+simple in its complexity.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p4e3bc648db1c061d" name="p4e3bc648db1c061d"> </a>Today, many programmers believe that this complexity is best managed
+by using only a small set of well-understood techniques in their
+programs. They have composed strict rules about the form programs
+should have, and the more zealous among them will denounce those who
+break these rules as <em>bad</em> programmers.</p><p><a class="paragraph" href="#pb85bd0b48cb88dd" name="pb85bd0b48cb88dd"> </a>What hostility to the richness of programming! To try to reduce it to
+something straightforward and predictable, to place a taboo on all the
+weird and beautiful programs. The landscape of programming techniques
+is enormous, fascinating in its diversity, still largely unexplored.
+It is certainly littered with traps and snares, luring the
+inexperienced programmer into all kinds of horrible mistakes, but that
+only means you should proceed with caution, keep your wits about you.
+As you learn, there will always be new challenges, new territory to
+explore. The programmer who refuses to keep exploring will surely
+stagnate, forget his joy, lose the will to program (and become a
+manager).</p><p><a class="paragraph" href="#p6c59c7812ba8b9bb" name="p6c59c7812ba8b9bb"> </a>As far as I am concerned, the definite criterion for a program is
+whether it is correct. Efficiency, clarity, and size are also
+important, but how to balance these against each other is always a
+matter of judgement, a judgement that each programmer must make for
+himself. Rules of thumb are useful, but one should never be afraid to
+break them.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p6e133d7403fcf291" name="p6e133d7403fcf291"> </a>In the beginning, at the birth of computing, there were no programming
+languages. Programs looked something like this:</p><pre class="preformatted">00110001 00000000 00000000
+00110001 00000001 00000001
+00110011 00000001 00000010
+01010001 00001011 00000010
+00100010 00000010 00001000
+01000011 00000001 00000000
+01000001 00000001 00000001
+00010000 00000010 00000000
+01100010 00000000 00000000</pre><p><a class="paragraph" href="#p3be310f42eba4016" name="p3be310f42eba4016"> </a>That is a program to add the numbers from one to ten together, and
+print out the result (1 + 2 + ... + 10 = 55). It could run on a very
+simple kind of computer. To program early computers, it was necessary
+to set large arrays of switches in the right position, or punch holes
+in strips of cardboard and feed them to the computer. You can imagine
+how this was a tedious, error-prone procedure. Even the writing of
+simple programs required much cleverness and discipline, complex ones
+were nearly inconceivable.</p><p><a class="paragraph" href="#p4bd5ecf3f5dbb2e3" name="p4bd5ecf3f5dbb2e3"> </a>Of course, manually entering these arcane patterns of bits (which is
+what the 1s and 0s above are generally called) did give the programmer
+a profound sense of being a mighty wizard. And that has to be worth
+something, in terms of job satisfaction.</p><p><a class="paragraph" href="#p99870ffbdcd77f1" name="p99870ffbdcd77f1"> </a>Each line of the program contains a single instruction. It could be
+written in English like this:</p><ol><li>Store the number 0 in memory location 0</li><li>Store the number 1 in memory location 1</li><li>Store the value of memory location 1 in memory location 2</li><li>Decrement the value in memory location 2 by the number 11</li><li>If the value in memory location 2 is the number 0, continue with instruction 9</li><li>Increment the value in memory location 0 by the value in memory location 1</li><li>Increment the value in memory location 1 by the number 1</li><li>Continue with instruction 3</li><li>Output the value of memory location 0</li></ol><p><a class="paragraph" href="#p28087410c8942294" name="p28087410c8942294"> </a>While that is more readable than the binary soup, it is still rather
+unpleasant. It might help to use names instead of numbers for the
+instructions and memory locations:</p><pre class="preformatted"> Set 'total' to 0
+ Set 'count' to 1
+[loop]
+ Set 'compare' to 'count'
+ Subtract 11 from 'compare'
+ If 'compare' is zero, continue at [end]
+ Add 'count' to 'total'
+ Add 1 to 'count'
+ Continue at [loop]
+[end]
+ Output 'total'</pre><p><a class="paragraph" href="#p742448e76c15459b" name="p742448e76c15459b"> </a>At this point it is not too hard to see how the program works. Can
+you? The first two lines give two memory locations their starting
+values: <code>total</code> will be used to build up the result of the program,
+and <code>count</code> keeps track of the number that we are currently looking
+at. The lines using <code>compare</code> are probably the weirdest ones. What the
+program wants to do is see if <code>count</code> is equal to 11, in order to
+decide whether it can stop yet. Because the machine is so primitive,
+it can only test whether a number is zero, and make a decision (jump)
+based on that. So it uses the memory location labelled <code>compare</code> to
+compute the value of <code>count - 11</code>, and makes a decision based on that
+value. The next two lines add the value of <code>count</code> to the result, and
+increment <code>count</code> by one every time the program has decided that it is
+not 11 yet.</p><p><a class="paragraph" href="#p485d88d71ab25ae7" name="p485d88d71ab25ae7"> </a>Here is the same program in JavaScript:</p><pre class="code"><span class="keyword">var</span> <span class="variable">total</span> = <span class="atom">0</span>, <span class="variable">count</span> = <span class="atom">1</span>;
+<span class="keyword">while</span> (<span class="variable">count</span> <= <span class="atom">10</span>) {
+ <span class="variable">total</span> += <span class="variable">count</span>;
+ <span class="variable">count</span> += <span class="atom">1</span>;
+}
+<span class="variable">print</span>(<span class="variable">total</span>);</pre><p><a class="paragraph" href="#p500d53fd9ae8deba" name="p500d53fd9ae8deba"> </a>This gives us a few more improvements. Most importantly, there is no
+need to specify the way we want the program to jump back and forth
+anymore. The magic word <code>while</code> takes care of that. It continues
+executing the lines below it as long as the condition it was given
+holds: <code>count <= 10</code>, which means '<code>count</code> is less than or equal
+to <code>10</code>'. Apparently, there is no need anymore to create a temporary
+value and compare that to zero. This was a stupid little detail, and
+the power of programming languages is that they take care of stupid
+little details for us.</p><p><a class="paragraph" href="#p71e06cf06ceceb6e" name="p71e06cf06ceceb6e"> </a>Finally, here is what the program could look like if we happened to
+have the convenient operations <code>range</code> and <code>sum</code> available, which
+respectively create a collection of numbers within a range and compute
+the sum of a collection of numbers:</p><pre class="code"><span class="variable">print</span>(<span class="variable">sum</span>(<span class="variable">range</span>(<span class="atom">1</span>, <span class="atom">10</span>)));</pre><p><a class="paragraph" href="#p5748f0480052ee2d" name="p5748f0480052ee2d"> </a>The moral of this story, then, is that the same program can be
+expressed in long and short, unreadable and readable ways. The first
+version of the program was extremely obscure, while this last one is
+almost English: <code>print</code> the <code>sum</code> of the <code>range</code> of numbers from <code>1</code>
+to <code>10</code>. (We will see in later chapters how to build things like <code>sum</code>
+and <code>range</code>.)</p><p><a class="paragraph" href="#pf3fe04d4c3f6ccc" name="pf3fe04d4c3f6ccc"> </a>A good programming language helps the programmer by providing a more
+abstract way to express himself. It hides uninteresting details,
+provides convenient building blocks (such as the <code>while</code> construct),
+and, most of the time, allows the programmer to add building blocks
+himself (such as the <code>sum</code> and <code>range</code> operations).</p></div><hr/><div class="block"><p><a class="paragraph" href="#p3ec4f0fa1d7306d6" name="p3ec4f0fa1d7306d6"> </a>JavaScript is the language that is, at the moment, mostly being used
+to do all kinds of clever and horrible things with pages on the World
+Wide Web. Some <a href="http://steve-yegge.blogspot.com/2007/02/next-big-language.html">people</a> claim
+that the next version of JavaScript will become an important language
+for other tasks too. I am unsure whether that will happen, but if you
+are interested in programming, JavaScript is definitely a useful
+language to learn. Even if you do not end up doing much
+web programming, the mind-bending programs I will show you in this
+book will always stay with you, haunt you, and influence the programs
+you write in other languages.</p><p><a class="paragraph" href="#p6ffc7e890b848901" name="p6ffc7e890b848901"> </a>There are those who will say <em>terrible</em> things about JavaScript. Many
+of these things are true. When I was for the first time required to
+write something in JavaScript, I quickly came to despise the language.
+It would accept almost anything I typed, but interpret it in a way
+that was completely different from what I meant. This had a lot to do
+with the fact that I did not have a clue what I was doing, but there
+is also a real issue here: JavaScript is ridiculously liberal in what
+it allows. The idea behind this design was that it would make
+programming in JavaScript easier for beginners. In actuality, it
+mostly makes finding problems in your programs harder, because the
+system will not point them out to you.</p><p><a class="paragraph" href="#p6403e6cf1d6fd4ed" name="p6403e6cf1d6fd4ed"> </a>However, the flexibility of the language is also an advantage. It
+leaves space for a lot of techniques that are impossible in more rigid
+languages, and it can be used to overcome some of JavaScript's
+shortcomings. After learning it properly, and working with it for a
+while, I have really learned to <em>like</em> this language.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p5d372a74466674a7" name="p5d372a74466674a7"> </a>Contrary to what the name suggests, JavaScript has very little to do
+with the programming language named Java. The similar name was
+inspired by marketing considerations, rather than good judgement. In
+1995, when JavaScript was introduced by Netscape, the Java language
+was being heavily marketed and gaining in popularity. Apparently,
+someone thought it a good idea to try and ride along on this
+marketing. Now we are stuck with the name.</p><p><a class="paragraph" href="#p20bc2e21c259965b" name="p20bc2e21c259965b"> </a>Related to JavaScript is a thing called ECMAScript. When browsers
+other than Netscape started to support JavaScript, or something that
+looked like it, a document was written to describe precisely how the
+language should work. The language described in this document is
+called ECMAScript, after the organisation that standardised it.</p><p><a class="paragraph" href="#p223e1f11afa03b89" name="p223e1f11afa03b89"> </a>ECMAScript describes a general-purpose programming language, and does
+not say anything about the integration of this language in an Internet
+browser. JavaScript is ECMAScript plus extra tools for dealing with
+Internet pages and browser windows.</p><p><a class="paragraph" href="#p680aa5a209e425af" name="p680aa5a209e425af"> </a>A few other pieces of software use the language described in the
+ECMAScript document. Most importantly, the ActionScript language used
+by Flash is based on ECMAScript (though it does not precisely follow
+the standard). Flash is a system for adding things that move and make
+lots of noise to web-pages. Knowing JavaScript won't hurt if you ever
+find yourself learning to build Flash movies.</p><p><a class="paragraph" href="#p23572bf9c21cdf90" name="p23572bf9c21cdf90"> </a>JavaScript is still evolving. Since this book came out, ECMAScript 5
+has been released, which is compatible with the version described
+here, but adds some of the functionality we will be writing ourselves
+as built-in methods. The newest generation of browsers provides this
+expanded version of JavaScript. As of 2011, 'ECMAScript harmony', a
+more radical extension of the language, is in the process of being
+standardised. You should not worry too much about these new versions
+making the things you learn from this book obsolete. For one thing,
+they will be an extension of the language we have now, so almost
+everything written in this book will still hold.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p7f13eda01aab2232" name="p7f13eda01aab2232"> </a>Most chapters in this book contain quite a lot of code<a class="footref" href="#footnote1">1</a>. In my
+experience, reading and writing code is an important part of learning
+to program. Try to not just glance over these examples, but read them
+attentively and understand them. This can be slow and confusing at
+first, but you will quickly get the hang of it. The same goes for the
+exercises. Don't assume you understand them until you've actually
+written a working solution.</p><p><a class="paragraph" href="#p4eb8d1b48b2bb37b" name="p4eb8d1b48b2bb37b"> </a>Because of the way the web works, it is always possible to look at the
+JavaScript programs that people put in their web-pages. This can be a
+good way to learn how some things are done. Because most web
+programmers are not 'professional' programmers, or consider JavaScript
+programming so uninteresting that they never properly learned it, a
+lot of the code you can find like this is of a <em>very</em> bad quality.
+When learning from ugly or incorrect code, the ugliness and confusion
+will propagate into your own code, so be careful who you learn from.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p42b9dbbc2906fda8" name="p42b9dbbc2906fda8"> </a>To allow you to try out programs, both the examples and the code you
+write yourself, this book makes use of something called a <a name="key2"></a>console.
+If you are using a modern graphical browser (Internet Explorer version
+6 or higher, Firefox 1.5 or higher, Opera 9 or higher, Safari 3 or
+higher, Chrome), the pages in this book will show a blueish bar at the
+bottom of your screen. You can open the console by clicking on the
+little arrow on the far right of this bar. (Note that I am not talking
+about your browser's built-in console.)</p><p><a class="paragraph" href="#p5e7747de8cfc0946" name="p5e7747de8cfc0946"> </a>The console contains three important elements. There is the output
+window, which is used to show error messages and things that programs
+print out. Below that, there is a line where you can type in a piece
+of JavaScript. Try typing in a number, and pressing the enter key to
+run what you typed. If the text you typed produced something
+meaningful, it will be shown in the output window. Now try typing
+<code>wrong!</code>, and press enter again. The output window will show an error
+message. You can use the arrow-up and arrow-down keys to go back to
+previous commands that you typed.</p><p><a class="paragraph" href="#p52d9e86c513e6d64" name="p52d9e86c513e6d64"> </a>For bigger pieces of code, those that span multiple lines and which
+you want to keep around for a while, the field on the right can be
+used. The 'Run' button is used to execute programs written in this
+field. It is possible to have multiple programs open at the same time.
+Use the 'New' button to open a new, empty buffer. When there is more
+than one open buffer, the menu next to the 'Run' button can be used to
+choose which one is being shown. The 'Close' button, as you might
+expect, closes a buffer.</p><p><a class="paragraph" href="#p590905737fc41d6e" name="p590905737fc41d6e"> </a>Example programs in this book always have a small button with an arrow
+in their top-right corner, which can be used to run them. The example
+we saw earlier looked like this:</p><pre class="code"><span class="keyword">var</span> <span class="variable">total</span> = <span class="atom">0</span>, <span class="variable">count</span> = <span class="atom">1</span>;
+<span class="keyword">while</span> (<span class="variable">count</span> <= <span class="atom">10</span>) {
+ <span class="variable">total</span> += <span class="variable">count</span>;
+ <span class="variable">count</span> += <span class="atom">1</span>;
+}
+<span class="variable">print</span>(<span class="variable">total</span>);</pre><p><a class="paragraph" href="#p2a1912d818d21579" name="p2a1912d818d21579"> </a>Run it by clicking the arrow. There is also another button, which is
+used to load the program into the console. Do not hesitate to modify
+it and try out the result. The worst that could happen is that you
+create an endless loop. An endless loop is what you get when the
+condition of the <code>while</code> never becomes false, for example if you
+choose to add <code>0</code> instead of <code>1</code> to the count variable. Now the
+program will run forever.</p><p><a class="paragraph" href="#p11cb94429bfcd757" name="p11cb94429bfcd757"> </a>Fortunately, browsers keep an eye on the programs running inside them.
+Whenever one of them is taking suspiciously long to finish, they will
+ask you if you want to cut it off.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p320258aea4902e52" name="p320258aea4902e52"> </a>In some later chapters, we will build example programs that consist of
+many blocks of code. Often, you have to run every one of them for the
+program to work. As you may have noticed, the arrow in a block of code
+turns purple after the block has been run. When reading a chapter, try
+to run every block of code you come across, especially those that
+'define' something new (you will see what that means in the next
+chapter).</p><p><a class="paragraph" href="#p4dfd5650784d1b5a" name="p4dfd5650784d1b5a"> </a>It is, of course, possible that you can not read a chapter in one
+sitting. This means you will have to start halfway when you continue
+reading, but if you don't run all the code starting from the top of
+the chapter, some things might not work. By holding the shift key
+while pressing the 'run' arrow on a block of code, all blocks before
+that one will be run as well, so when you start in the middle of a
+chapter, hold shift the first time you run a piece of code, and
+everything should work as expected.</p></div><ol class="footnotes"><li><a name="footnote1"></a>'Code' is the substance that programs are made of. Every piece of a
+program, whether it is a single line or the whole thing, can be
+referred to as 'code'.</li></ol><h1><span class="number">Chapter 2: </span>Basic JavaScript: values, variables, and control flow</h1><div class="block"><p><a class="paragraph" href="#p61b1af7cf0e95900" name="p61b1af7cf0e95900"> </a>Inside the computer's world, there is only data. That which is not
+data, does not exist. Although all data is in essence just a sequence
+of bits<a class="footref" href="#footnote1">1</a>, and is thus fundamentally alike, every piece of data plays
+its own role. In JavaScript's system, most of this data is neatly
+separated into things called <a name="key1"></a>values. Every value has a type, which
+determines the kind of role it can play. There are six basic types of
+values: Numbers, strings, booleans, objects, functions, and undefined
+values.</p><p><a class="paragraph" href="#p50fb86c9d3e2ba37" name="p50fb86c9d3e2ba37"> </a>To create a value, one must merely invoke its name. This is very
+convenient. You don't have to gather building material for your
+values, or pay for them, you just call for one and <em>woosh</em>, you have
+it. They are not created from thin air, of course. Every value has to
+be stored somewhere, and if you want to use a gigantic number of them
+at the same time you might run out of computer memory. Fortunately,
+this is only a problem if you need them all simultaneously. As soon as
+you no longer use a value, it will dissipate, leaving behind only a
+few bits. These bits are recycled to make the next generation of
+values.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p50a3479ce6a9dffd" name="p50a3479ce6a9dffd"> </a>Values of the type <a name="key2"></a>number are, as you might have deduced, numeric
+values. They are written the way numbers are usually written:</p><pre class="code expression"><span class="atom">144</span></pre><p><a class="paragraph" href="#p32ae9753e0ad5f5b" name="p32ae9753e0ad5f5b"> </a>Enter that in the console, and the same thing is printed in the output
+window. The text you typed in gave rise to a number value, and the
+console took this number and wrote it out to the screen again. In a
+case like this, that was a rather pointless exercise, but soon we will
+be producing values in less straightforward ways, and it can be useful
+to 'try them out' on the console to see what they produce.</p><p><a class="paragraph" href="#p6b6235b9080cb806" name="p6b6235b9080cb806"> </a>This is what <code>144</code> looks like in bits<a class="footref" href="#footnote2">2</a>:</p><pre class="preformatted">0100000001100010000000000000000000000000000000000000000000000000</pre><p><a class="paragraph" href="#p259261911b9e3d68" name="p259261911b9e3d68"> </a>The number above has 64 bits. Numbers in JavaScript always do. This
+has one important repercussion: There is a limited amount of different
+numbers that can be expressed. With three decimal digits, only the
+numbers 0 to 999 can be written, which is 10<sup>3</sup> = 1000 different
+numbers. With 64 binary digits, 2<sup>64</sup> different numbers can be written.
+This is a lot, more than 10<sup>19</sup> (a one with nineteen zeroes).</p><p><a class="paragraph" href="#p6587537572d2d6de" name="p6587537572d2d6de"> </a>Not all whole numbers below 10<sup>19</sup> fit in a JavaScript number though.
+For one, there are also negative numbers, so one of the bits has to be
+used to store the sign of the number. A bigger issue is that non-whole
+numbers must also be represented. To do this, 11 bits are used to
+store the position of the fractional dot within the number.</p><p><a class="paragraph" href="#p7e2d0b7b96040227" name="p7e2d0b7b96040227"> </a>That leaves 52 bits<a class="footref" href="#footnote3">3</a>. Any whole number less than 2<sup>52</sup> (which is more
+than 10<sup>15</sup>) will safely fit in a JavaScript number. In most cases, the
+numbers we are using stay well below that, so we do not have to
+concern ourselves with bits at all. Which is good. I have nothing in
+particular against bits, but you <em>do</em> need a terrible lot of them to
+get anything done. When at all possible, it is more pleasant to deal
+with bigger things.</p><p><a class="paragraph" href="#p2daf3430c67921cb" name="p2daf3430c67921cb"> </a>Fractional numbers are written by using a dot.</p><pre class="code expression"><span class="atom">9.81</span></pre><p><a class="paragraph" href="#p63af9617f4b5c93a" name="p63af9617f4b5c93a"> </a>For very big or very small numbers, one can also use 'scientific'
+notation by adding an <code>e</code>, followed by the exponent of the number:</p><pre class="code expression"><span class="atom">2.998e8</span></pre><p><a class="paragraph" href="#p13d16265cebf1ff9" name="p13d16265cebf1ff9"> </a>Which is 2.998 * 10<sup>8</sup> = 299800000.</p><p><a class="paragraph" href="#p71dbd3c1f4974e33" name="p71dbd3c1f4974e33"> </a>Calculations with whole numbers (also called integers) that fit in 52
+bits are guaranteed to always be precise. Unfortunately, calculations
+with fractional numbers are generally not. The same way that π (pi) can not be
+precisely expressed by a finite amount of decimal digits, many numbers
+lose some precision when only 64 bits are available to store them.
+This is a shame, but it only causes practical problems in very
+specific situations. The important thing is to be aware of it, and
+treat fractional digital numbers as approximations, not as precise
+values.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p5e9cbe6e355f31b3" name="p5e9cbe6e355f31b3"> </a>The main thing to do with numbers is arithmetic. Arithmetic operations
+such as addition or multiplication take two number values and produce
+a new number from them. Here is what they look like in JavaScript:</p><pre class="code expression"><span class="atom">100</span> + <span class="atom">4</span> * <span class="atom">11</span></pre><p><a class="paragraph" href="#p42661e965df9439a" name="p42661e965df9439a"> </a>The <a name="key3"></a><code>+</code> and <a name="key4"></a><code>*</code> symbols are called operators. The first stands for
+addition, and the second for multiplication. Putting an operator
+between two values will <a name="key5"></a>apply it to those values, and
+produce a new value.</p><p><a class="paragraph" href="#p56a1ea0fbf26a539" name="p56a1ea0fbf26a539"> </a>Does the example mean 'add 4 and 100, and multiply the result by 11',
+or is the multiplication done before the adding? As you might have
+guessed, the multiplication happens first. But, as in mathematics,
+this can be changed by wrapping the addition in parentheses<a name="key6"></a>:</p><pre class="code expression">(<span class="atom">100</span> + <span class="atom">4</span>) * <span class="atom">11</span></pre><p><a class="paragraph" href="#p50440df750d8329c" name="p50440df750d8329c"> </a>For subtraction, there is the <a name="key7"></a><code>-</code> operator, and division can be done
+with <a name="key8"></a><code>/</code>. When operators appear together without parentheses, the
+order in which they are applied is determined by the <a name="key9"></a>precedence of
+the operators. The first example shows that multiplication has a
+higher precedence than addition. Division and multiplication always
+come before subtraction and addition. When multiple operators with the
+same precedence appear next to each other (<code>1 - 1 + 1</code>) they are
+applied left-to-right.</p><p><a class="paragraph" href="#p5ece5e641cb7a91" name="p5ece5e641cb7a91"> </a>Try to figure out what value this produces, and then run it to see if
+you were correct...</p><pre class="code expression"><span class="atom">115</span> * <span class="atom">4</span> - <span class="atom">4</span> + <span class="atom">88</span> / <span class="atom">2</span></pre><p><a class="paragraph" href="#p1f2a225f25c63f52" name="p1f2a225f25c63f52"> </a>These rules of precedence are not something you should worry about.
+When in doubt, just add parentheses.</p><p><a class="paragraph" href="#p37f2f79789db8719" name="p37f2f79789db8719"> </a>There is one more arithmetic operator which is probably less familiar
+to you. The <a name="key10"></a><code>%</code> symbol is used to represent the <a name="key11"></a>remainder operation.
+<code>X % Y</code> is the remainder of dividing <code>X</code> by <code>Y</code>. For example
+<code>314 % 100</code> is <code>14</code>, <code>10 % 3</code> is <code>1</code>, and <code>144 % 12</code> is <code>0</code>. Remainder
+has the same precedence as multiplication and division.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p60f72964a3424f8" name="p60f72964a3424f8"> </a>The next data type is the <a name="key12"></a>string. Its use is not as evident from its
+name as with numbers, but it also fulfills a very basic role. Strings
+are used to represent text, the name supposedly derives from the fact
+that it strings together a bunch of characters. Strings are written by
+enclosing their content in quotes:</p><pre class="code expression"><span class="string">"Patch my boat with chewing gum."</span></pre><p><a class="paragraph" href="#p4b2c38f3da872ec1" name="p4b2c38f3da872ec1"> </a>Almost anything can be put between double quotes, and JavaScript will
+make a string value out of it. But a few characters are tricky. You
+can imagine how putting quotes between quotes might be hard. Newlines,
+<a name="key13"></a>the things you get when you press enter, can also not be put
+between quotes, the string has to stay on a single line.</p><p><a class="paragraph" href="#p66a7f6315b134df3" name="p66a7f6315b134df3"> </a>To be able to have such characters in a string, the following trick is
+used: Whenever a backslash ('<code>\</code>') is found inside quoted text, it
+indicates that the character after it has a special meaning. A quote
+that is preceded by a backslash will not end the string, but be part
+of it. When an '<code>n</code>' character occurs after a backslash, it is
+interpreted as a newline. Similarly, a '<code>t</code>' after a backslash means a
+tab character<a class="footref" href="#footnote4">4</a>.</p><pre class="code expression"><span class="string">"This is the first line\nAnd this is the second"</span></pre><p><a class="paragraph" href="#p5251dd2fc75a326" name="p5251dd2fc75a326"> </a>Note that if you type this into the console, it'll display it back in
+'source' form, with the quotes and backslash escapes. To see only the
+actual text, you can type <code>print("a\nb")</code>. What that does precisely
+will be clarified a little further on.</p><p><a class="paragraph" href="#p3381259269b5ec55" name="p3381259269b5ec55"> </a>There are of course situations where you want a backslash in a string
+to be just a backslash, not a special code. If two backslashes follow
+each other, they will collapse right into each other, and only one
+will be left in the resulting string value:</p><pre class="code expression"><span class="string">"A newline character is written like \"\\n\"."</span></pre></div><hr/><div class="block"><p><a class="paragraph" href="#pe7768638750d804" name="pe7768638750d804"> </a>Strings can not be divided, multiplied, or subtracted. The <a name="key14"></a><code>+</code>
+operator <em>can</em> be used on them. It does not add, but it concatenates,
+it glues two strings together.</p><pre class="code expression"><span class="string">"con"</span> + <span class="string">"cat"</span> + <span class="string">"e"</span> + <span class="string">"nate"</span></pre><p><a class="paragraph" href="#p2bf2c03f52eb7d44" name="p2bf2c03f52eb7d44"> </a>There are more ways of manipulating strings, but these are discussed
+later.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p617d018066e362e9" name="p617d018066e362e9"> </a>Not all operators are symbols, some are written as words. For example,
+the <a name="key15"></a><code>typeof</code> operator, which produces a string value naming the type
+of the value you give it.</p><pre class="code expression">typeof <span class="atom">4.5</span></pre><p><a class="paragraph" href="#p4665f4ba1393153f" name="p4665f4ba1393153f"> </a>The other operators we saw all operated on two values, <code>typeof</code> takes
+only one. Operators that use two values are called <a name="key16"></a>binary operators,
+while those that take one are called <a name="key17"></a>unary operators. The
+<a name="key18"></a>minus operator can be used both as a binary and a unary
+operator:</p><pre class="code expression">- (<span class="atom">10</span> - <span class="atom">2</span>)</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p77bf1b47e2d73c8b" name="p77bf1b47e2d73c8b"> </a>Then there are values of the <a name="key19"></a>boolean type. There are only two of
+these: <a name="key20"></a><code>true</code> and <a name="key21"></a><code>false</code>. Here is one way to produce a <code>true</code>
+value:</p><pre class="code expression"><span class="atom">3</span> > <span class="atom">2</span></pre><p><a class="paragraph" href="#p797832a59bded7cc" name="p797832a59bded7cc"> </a>And <code>false</code> can be produced like this:</p><pre class="code expression"><span class="atom">3</span> < <span class="atom">2</span></pre><p><a class="paragraph" href="#p3a024c1cc18c61bc" name="p3a024c1cc18c61bc"> </a>I hope you have seen the <a name="key22"></a><code>></code> and <a name="key23"></a><code><</code> signs before. They mean,
+respectively, 'is greater than' and 'is less than'. They are binary
+operators, and the result of applying them is a boolean value that
+indicates whether they hold in this case.</p><p><a class="paragraph" href="#p1b70e329d23af1ff" name="p1b70e329d23af1ff"> </a>Strings can be compared in the same way:</p><pre class="code expression"><span class="string">"Aardvark"</span> < <span class="string">"Zoroaster"</span></pre><p><a class="paragraph" href="#p1bc6374d7e3e4694" name="p1bc6374d7e3e4694"> </a>The way strings are ordered is more or less alphabetic. More or
+less... Uppercase letters are always 'less' than lowercase ones, so
+<code>"Z" < "a"</code> (upper-case Z, lower-case a) is <code>true</code>, and non-alphabetic
+characters ('<code>!</code>', '<code>@</code>', etc) are also included in the ordering. The
+actual way in which the comparison is done is based on the <a name="key24"></a>Unicode
+standard. This standard assigns a number to virtually every character
+one would ever need, including characters from Greek, Arabic,
+Japanese, Tamil, and so on. Having such numbers is practical for
+storing strings inside a computer ― you can represent them as a list
+of numbers. When comparing strings, JavaScript just compares the
+numbers of the characters inside the string, from left to right.</p><p><a class="paragraph" href="#p1159736b16c0de67" name="p1159736b16c0de67"> </a>Other similar operators are <a name="key25"></a><code>>=</code> ('is greater than or equal to'),
+<a name="key26"></a><code><=</code> (is less than or equal to), <a name="key27"></a><code>==</code> ('is equal to'), and <a name="key28"></a><code>!=</code>
+('is not equal to').</p><pre class="code expression"><span class="string">"Itchy"</span> != <span class="string">"Scratchy"</span></pre><pre class="code expression"><span class="atom">5e2</span> == <span class="atom">500</span></pre></div><hr/><div class="block"><p><a class="paragraph" href="#p7cf9494fff734302" name="p7cf9494fff734302"> </a>There are also some useful operations that can be applied to boolean
+values themselves. JavaScript supports three logical operators: <em>and</em>,
+<em>or</em>, and <em>not</em>. These can be used to 'reason' about booleans.</p><p><a class="paragraph" href="#p7eb1852ca8c4b6f4" name="p7eb1852ca8c4b6f4"> </a>The <a name="key29"></a><code>&&</code> operator represents logical <em>and</em>. It is a binary operator,
+and its result is only <code>true</code> if both of the values given to it are
+<code>true</code>.</p><pre class="code expression"><span class="atom">true</span> && <span class="atom">false</span></pre><p><a class="paragraph" href="#p2bea27b8212b9b68" name="p2bea27b8212b9b68"> </a><a name="key30"></a><code>||</code> is the logical <em>or</em>, it is <code>true</code> if either of the values given
+to it is <code>true</code>:</p><pre class="code expression"><span class="atom">true</span> || <span class="atom">false</span></pre><p><a class="paragraph" href="#p7442bf68e97118f" name="p7442bf68e97118f"> </a><em>Not</em> is written as an exclamation mark, <a name="key31"></a><code>!</code>, it is a unary operator
+that flips the value given to it, <code>!true</code> is <code>false</code>, and <code>!false</code> is
+<code>true</code>.</p></div><hr/><div class="block"><a name="exercise1"></a><div class="exercisenum">Ex. 2.1</div><div class="exercise"><pre class="code expression">((<span class="atom">4</span> >= <span class="atom">6</span>) || (<span class="string">"grass"</span> != <span class="string">"green"</span>)) &&
+ !(((<span class="atom">12</span> * <span class="atom">2</span>) == <span class="atom">144</span>) && <span class="atom">true</span>)</pre><p><a class="paragraph" href="#p5c4d1693fe971953" name="p5c4d1693fe971953"> </a>Is this true? For readability, there are a lot of unnecessary
+parentheses in there. This simple version means the same thing:</p><pre class="code expression">(<span class="atom">4</span> >= <span class="atom">6</span> || <span class="string">"grass"</span> != <span class="string">"green"</span>) &&
+ !(<span class="atom">12</span> * <span class="atom">2</span> == <span class="atom">144</span> && <span class="atom">true</span>)</pre></div><div class="solution"><p><a class="paragraph" href="#p5c3cd3f27888dd02" name="p5c3cd3f27888dd02"> </a>Yes, it is <code>true</code>. You can reduce it step by step like this:</p><pre class="code expression">(<span class="atom">false</span> || <span class="atom">true</span>) && !(<span class="atom">false</span> && <span class="atom">true</span>)</pre><pre class="code expression"><span class="atom">true</span> && !<span class="atom">false</span></pre><pre class="code expression"><span class="atom">true</span></pre><p><a class="paragraph" href="#p17cfd06bf8f94976" name="p17cfd06bf8f94976"> </a>I hope you noticed that <code>"grass" != "green"</code> is <code>true</code>. Grass may be
+green, but it is not equal to green.</p></div></div><hr/><div class="block"><p><a class="paragraph" href="#p13f5cf334222453" name="p13f5cf334222453"> </a>It is not always obvious when parentheses are needed. In practice, one
+can usually get by with knowing that of the operators we have seen so
+far, <code>||</code> has the lowest precedence, then comes <code>&&</code>, then the
+comparison operators (<code>></code>, <code>==</code>, etcetera), and then the rest. This
+has been chosen in such a way that, in simple cases, as few
+parentheses as possible are necessary.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p107cf27965af5913" name="p107cf27965af5913"> </a>All the examples so far have used the language like you would use a
+pocket calculator. Make some values and apply operators to them to get
+new values. Creating values like this is an essential part of every
+JavaScript program, but it is only a part. A piece of code that
+produces a value is called an <a name="key32"></a>expression. Every value that is
+written directly (such as <code>22</code> or <code>"psychoanalysis"</code>) is an
+expression. An expression between parentheses is also an expression.
+And a binary operator applied to two expressions, or a unary operator
+applied to one, is also an expression.</p><p><a class="paragraph" href="#p65fc46bd5b67046e" name="p65fc46bd5b67046e"> </a>There are a few more ways of building expressions, which will be
+revealed when the time is ripe.</p><p><a class="paragraph" href="#p6efb23219d3caa3e" name="p6efb23219d3caa3e"> </a>There exists a unit that is bigger than an expression. It is called a
+<a name="key33"></a>statement. A program is built as a list of statements. Most
+statements end with a <a name="key34"></a>semicolon (<code>;</code>). The simplest kind of
+statement is an expression with a semicolon after it. This is a
+program:</p><pre class="code"><span class="atom">1</span>;
+!<span class="atom">false</span>;</pre><p><a class="paragraph" href="#p28351e9a29a7e8db" name="p28351e9a29a7e8db"> </a>It is a useless program. An expression can be content to just produce
+a value, but a statement only amounts to something if it somehow
+changes the world. It could print something to the screen ― that
+counts as changing the world ― or it could change the internal state
+of the program in a way that will affect the statements that come
+after it. These changes are called '<a name="key35"></a>side effects'. The statements in
+the example above just produce the values <code>1</code> and <code>true</code>, and then
+immediately throw them into the bit bucket<a class="footref" href="#footnote5">5</a>. This leaves no
+impression on the world at all, and is not a side effect.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p5fb0b52a65170986" name="p5fb0b52a65170986"> </a>How does a program keep an internal state? How does it remember
+things? We have seen how to produce new values from old values, but
+this does not change the old values, and the new value has to be
+immediately used or it will dissipate again. To catch and hold values,
+JavaScript provides a thing called a <a name="key36"></a>variable.</p><pre class="code"><span class="keyword">var</span> <span class="variable">caught</span> = <span class="atom">5</span> * <span class="atom">5</span>;</pre><p><a class="paragraph" href="#p58b88cf3405a34f5" name="p58b88cf3405a34f5"> </a>A variable always has a name, and it can point at a value, holding on
+to it. The statement above creates a variable called <code>caught</code> and uses
+it to grab hold of the number that is produced by multiplying <code>5</code> by
+<code>5</code>.</p><p><a class="paragraph" href="#p2c8171c6a3bce68" name="p2c8171c6a3bce68"> </a>After running the above program, you can type the word <code>caught</code> into
+the console, and it will retrieve the value <code>25</code> for you. The name of
+a variable is used to fetch its value. <code>caught + 1</code> also works. A
+variable name can be used as an expression, and thus can be part of
+bigger expressions.</p><p><a class="paragraph" href="#p62259c9d47e8e505" name="p62259c9d47e8e505"> </a>The word <a name="key37"></a><code>var</code> is used to create a new variable. After <code>var</code>, the
+name of the variable follows. Variable names can be almost every word,
+but they may not include spaces. Digits can be part of variable names,
+<code>catch22</code> is a valid name, but the name must not start with a digit. The
+characters '<code>$</code>' and '<code>_</code>' can be used in names as if they were
+letters, so <code>$_$</code> is a correct variable name.</p><p><a class="paragraph" href="#p17ec5282ddc9bc52" name="p17ec5282ddc9bc52"> </a>If you want the new variable to immediately capture a value, which is
+often the case, the <a name="key38"></a><code>=</code> operator can be used to give it the value of
+some expression.</p><p><a class="paragraph" href="#p5c44155d666db7fe" name="p5c44155d666db7fe"> </a>When a variable points at a value, that does not mean it is tied to
+that value forever. At any time, the <code>=</code> operator can be used on
+existing variables to yank them away from their current value and make
+them point to a new one.</p><pre class="code"><span class="variable">caught</span> = <span class="atom">4</span> * <span class="atom">4</span>;</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p1d46b0ecd273d88c" name="p1d46b0ecd273d88c"> </a>You should imagine variables as tentacles, rather than boxes. They do
+not <em>contain</em> values, they <em>grasp</em> them ― two variables can refer to
+the same value. Only the values that the program still has a hold on
+can be accessed by it. When you need to remember something, you grow a
+tentacle to hold on to it, or re-attach one of your existing tentacles
+to a new value: To remember the amount of dollars that Luigi still
+owes you, you could do...</p><pre class="code"><span class="keyword">var</span> <span class="variable">luigiDebt</span> = <span class="atom">140</span>;</pre><p><a class="paragraph" href="#p25ff31a51d72168c" name="p25ff31a51d72168c"> </a>Then, every time Luigi pays something back, this amount can be
+decremented by giving the variable a new number:</p><pre class="code"><span class="variable">luigiDebt</span> = <span class="variable">luigiDebt</span> - <span class="atom">35</span>;</pre><p><a class="paragraph" href="#p7e8cd0bb233236e8" name="p7e8cd0bb233236e8"> </a>The collection of variables and their values that exist at a given
+time is called the <a name="key39"></a>environment. When a program starts up, this
+environment is not empty. It always contains a number of standard
+variables. When your browser loads a page, it creates a new
+environment and attaches these standard values to it. The variables
+created and modified by programs on that page survive until the
+browser goes to a new page.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p7a2d22ee22a73bc5" name="p7a2d22ee22a73bc5"> </a>A lot of the values provided by the standard environment have the type
+'<a name="key40"></a>function'. A function is a piece of program wrapped in a value.
+Generally, this piece of program does something useful, which can be
+invoked using the function value that contains it. In a browser
+environment, the variable <a name="key41"></a><code>alert</code> holds a function that shows a
+little dialog window with a message. It is used like this:</p><pre class="code"><span class="variable">alert</span>(<span class="string">"Avocados"</span>);</pre><p><a class="paragraph" href="#p676ecb7ed3921d48" name="p676ecb7ed3921d48"> </a><a name="key42"></a>Executing the code in a function is called <a name="key43"></a>invoking, calling,
+or <a name="key44"></a>applying it. The notation for doing this uses parentheses. Every
+expression that produces a function value can be invoked by putting
+parentheses after it. In the example, the value <code>"Avocados"</code> is given
+to the function, which uses it as the text to show in the dialog
+window. Values given to functions are called <a name="key45"></a>parameters or
+<a name="key46"></a>arguments. <code>alert</code> needs only one of them, but other functions might
+need a different number.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p7b3fd95c590dcad3" name="p7b3fd95c590dcad3"> </a>Showing a dialog window is a side effect. A lot of functions are
+useful because of the side effects they produce. It is also possible
+for a function to produce a value, in which case it does not need to
+have a side effect to be useful. For example, there is a function
+<a name="key47"></a><code>Math.max</code>, which takes any number of numeric arguments and gives
+back the greatest:</p><pre class="code"><span class="variable">alert</span>(<span class="variable">Math</span>.<span class="property">max</span>(<span class="atom">2</span>, <span class="atom">4</span>));</pre><p><a class="paragraph" href="#p86f6c2b80c0e6fc" name="p86f6c2b80c0e6fc"> </a><a name="key48"></a>When a function produces a value, it is said to <a name="key49"></a>return
+it. Because things that produce values are always expressions in
+JavaScript, function calls can be used as a part of bigger
+expressions:</p><pre class="code"><span class="variable">alert</span>(<span class="variable">Math</span>.<span class="property">min</span>(<span class="atom">2</span>, <span class="atom">4</span>) + <span class="atom">100</span>);</pre><p><a class="paragraph" href="#p1f0771d62babec3e" name="p1f0771d62babec3e"> </a><a href="chapter3.html">Chapter 3</a> discusses writing your own functions.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p71ef6330c6776122" name="p71ef6330c6776122"> </a>As the previous examples show, <code>alert</code> can be useful for showing the
+result of some expression. Clicking away all those little windows can
+get on one's nerves though, so from now on we will prefer to use a
+similar function, called <a name="key50"></a><code>print</code>, which does not pop up a window,
+but just writes a value to the output area of the console. <code>print</code> is
+not a standard JavaScript function, browsers do not provide it for
+you, but it is made available by this book, so you can use it on these
+pages.</p><pre class="code"><span class="variable">print</span>(<span class="string">"N"</span>);</pre><p><a class="paragraph" href="#p2b7155906dde07b4" name="p2b7155906dde07b4"> </a>A similar function, also provided on these pages, is <code>show</code>. While
+<code>print</code> will display its argument as flat text, <a name="key51"></a><code>show</code> tries to
+display it the way it would look in a program, which can give more
+information about the type of the value. For example, string values
+keep their quotes when given to <code>show</code>:</p><pre class="code"><span class="variable">show</span>(<span class="string">"N"</span>);</pre><p><a class="paragraph" href="#p3738004b5758ea97" name="p3738004b5758ea97"> </a>The standard environment provided by browsers contains a few more
+functions for popping up windows. You can ask the user an OK/Cancel
+question using <a name="key52"></a><code>confirm</code>. This returns a boolean, <code>true</code> if the user
+presses 'OK', and <code>false</code> if he presses 'Cancel'.</p><pre class="code"><span class="variable">show</span>(<span class="variable">confirm</span>(<span class="string">"Shall we, then?"</span>));</pre><p><a class="paragraph" href="#p42ad8c1ef96a706b" name="p42ad8c1ef96a706b"> </a><a name="key53"></a><code>prompt</code> can be used to ask an 'open' question. The first argument
+is the question, the second one is the text that the user starts with.
+A line of text can be typed into the window, and the function will
+return this as a string.</p><pre class="code"><span class="variable">show</span>(<span class="variable">prompt</span>(<span class="string">"Tell us everything you know."</span>, <span class="string">"..."</span>));</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p228519d506327a1f" name="p228519d506327a1f"> </a>It is possible to give almost every variable in the environment a new
+value. This can be useful, but also dangerous. If you give <code>print</code> the
+value <code>8</code>, you won't be able to print things anymore. Fortunately,
+there is a big 'Reset' button on the console, which will reset the
+environment to its original state.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p4f28c3e2c3307f10" name="p4f28c3e2c3307f10"> </a>One-line programs are not very interesting. When you put more than one
+statement into a program, the statements are, predictably, executed
+one at a time, from top to bottom.</p><pre class="code"><span class="keyword">var</span> <span class="variable">theNumber</span> = <span class="variable">Number</span>(<span class="variable">prompt</span>(<span class="string">"Pick a number"</span>, <span class="string">""</span>));
+<span class="variable">print</span>(<span class="string">"Your number is the square root of "</span> +
+ (<span class="variable">theNumber</span> * <span class="variable">theNumber</span>));</pre><p><a class="paragraph" href="#p399942c25b700f68" name="p399942c25b700f68"> </a>The function <a name="key54"></a><code>Number</code> converts a value to a number, which is needed
+in this case because the result of <code>prompt</code> is a string value. There
+are similar functions called <a name="key55"></a><code>String</code> and <a name="key56"></a><code>Boolean</code> which convert
+values to those types.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p191d6f33e07ac9fd" name="p191d6f33e07ac9fd"> </a>Consider a program that prints out all even numbers from 0 to 12. One
+way to write this is:</p><pre class="code"><span class="variable">print</span>(<span class="atom">0</span>);
+<span class="variable">print</span>(<span class="atom">2</span>);
+<span class="variable">print</span>(<span class="atom">4</span>);
+<span class="variable">print</span>(<span class="atom">6</span>);
+<span class="variable">print</span>(<span class="atom">8</span>);
+<span class="variable">print</span>(<span class="atom">10</span>);
+<span class="variable">print</span>(<span class="atom">12</span>);</pre><p><a class="paragraph" href="#p7f8805a6587f2118" name="p7f8805a6587f2118"> </a>That works, but the idea of writing a program is to make something
+<em>less</em> work, not more. If we needed all even numbers below 1000, the
+above would be unworkable. What we need is a way to automatically
+repeat some code.</p><pre class="code"><span class="keyword">var</span> <span class="variable">currentNumber</span> = <span class="atom">0</span>;
+<span class="keyword">while</span> (<span class="variable">currentNumber</span> <= <span class="atom">12</span>) {
+ <span class="variable">print</span>(<span class="variable">currentNumber</span>);
+ <span class="variable">currentNumber</span> = <span class="variable">currentNumber</span> + <span class="atom">2</span>;
+}</pre><p><a class="paragraph" href="#p49e5e5b54090b34b" name="p49e5e5b54090b34b"> </a>You may have seen <a name="key57"></a><code>while</code> in the introduction chapter. A statement
+starting with the word <code>while</code> creates a <a name="key58"></a>loop. A loop is a
+disturbance in the sequence of statements ― it may cause the program to
+repeat some statements multiple times. In this case, the word <code>while</code>
+is followed by an expression in parentheses (the parentheses are
+compulsory here), which is used to determine whether the loop will
+loop or finish. As long as the boolean value produced by this
+expression is <code>true</code>, the code in the loop is repeated. As soon as it
+is false, the program goes to the bottom of the loop and continues as
+normal.</p><p><a class="paragraph" href="#p12de169b6ad2f5e2" name="p12de169b6ad2f5e2"> </a>The variable <code>currentNumber</code> demonstrates the way a variable can track
+the progress of a program. Every time the loop repeats, it is
+incremented by <code>2</code>, and at the beginning of every repetition, it is
+compared with the number <code>12</code> to decide whether to keep on looping.</p><p><a class="paragraph" href="#p4c3faa857b49a0e7" name="p4c3faa857b49a0e7"> </a>The third part of a <code>while</code> statement is another statement. This is
+the <a name="key59"></a>body of the loop, the action or actions that must take place
+multiple times. If we did not have to print the numbers, the program
+could have been:</p><pre class="code"><span class="keyword">var</span> <span class="variable">currentNumber</span> = <span class="atom">0</span>;
+<span class="keyword">while</span> (<span class="variable">currentNumber</span> <= <span class="atom">12</span>)
+ <span class="variable">currentNumber</span> = <span class="variable">currentNumber</span> + <span class="atom">2</span>;</pre><p><a class="paragraph" href="#p28e18a0a9ae6fa64" name="p28e18a0a9ae6fa64"> </a>Here, <code>currentNumber = currentNumber + 2;</code> is the statement that forms
+the body of the loop. We must also print the number, though, so the
+loop statement must consist of more than one statement. <a name="key60"></a>Braces
+(<code>{</code> and <code>}</code>) are used to group statements into <a name="key61"></a>blocks. To the world
+outside the block, a block counts as a single statement. In the earlier
+example, this is used to include in the loop both the call to <code>print</code>
+and the statement that updates <code>currentNumber</code>.</p></div><hr/><div class="block"><a name="exercise2"></a><div class="exercisenum">Ex. 2.2</div><div class="exercise"><p><a class="paragraph" href="#p5442ca2a9bc50c8e" name="p5442ca2a9bc50c8e"> </a>Use the techniques shown so far to write a program that calculates and
+shows the value of 2<sup>10</sup> (2 to the 10th power). You are, obviously, not
+allowed to use a cheap trick like just writing <code>2 * 2 * ...</code>.</p><p><a class="paragraph" href="#p1810f758d84ce7c9" name="p1810f758d84ce7c9"> </a>If you are having trouble with this, try to see it in terms of the
+even-numbers example. The program must perform an action a certain
+amount of times. A counter variable with a <code>while</code> loop can be used
+for that. Instead of printing the counter, the program must multiply
+something by 2. This something should be another variable, in which
+the result value is built up.</p><p><a class="paragraph" href="#p635c5eccaae1407e" name="p635c5eccaae1407e"> </a>Don't worry if you don't quite see how this would work yet. Even if
+you perfectly understand all the techniques this chapter covers, it
+can be hard to apply them to a specific problem. Reading and writing
+code will help develop a feeling for this, so study the solution, and
+try the next exercise.</p></div><div class="solution"><pre class="code"><span class="keyword">var</span> <span class="variable">result</span> = <span class="atom">1</span>;
+<span class="keyword">var</span> <span class="variable">counter</span> = <span class="atom">0</span>;
+<span class="keyword">while</span> (<span class="variable">counter</span> < <span class="atom">10</span>) {
+ <span class="variable">result</span> = <span class="variable">result</span> * <span class="atom">2</span>;
+ <span class="variable">counter</span> = <span class="variable">counter</span> + <span class="atom">1</span>;
+}
+<span class="variable">show</span>(<span class="variable">result</span>);</pre><p><a class="paragraph" href="#p34e01f8922444a64" name="p34e01f8922444a64"> </a>The counter could also start at <code>1</code> and check for <code><= 10</code>, but, for
+reasons that will become apparent later on, it is a good idea to get
+used to counting from 0.</p><p><a class="paragraph" href="#p48198b9ba530af8c" name="p48198b9ba530af8c"> </a>Obviously, your own solutions aren't required to be precisely the same
+as mine. They should work. And if they are very different, make sure
+you also understand my solution.</p></div></div><hr/><div class="block"><a name="exercise3"></a><div class="exercisenum">Ex. 2.3</div><div class="exercise"><p><a class="paragraph" href="#p641bbdee500f68ef" name="p641bbdee500f68ef"> </a>With some slight modifications, the solution to the previous exercise
+can be made to draw a triangle. And when I say 'draw a triangle' I
+mean 'print out some text that almost looks like a triangle when you
+squint'.</p><p><a class="paragraph" href="#p2f5c07093e5097db" name="p2f5c07093e5097db"> </a>Print out ten lines. On the first line there is one '#' character. On
+the second there are two. And so on.</p><p><a class="paragraph" href="#p5db823f0ebb01541" name="p5db823f0ebb01541"> </a>How does one get a string with X '#' characters in it? One way is to
+build it every time it is needed with an 'inner loop' ― a loop inside
+a loop. A simpler way is to reuse the string that the previous
+iteration of the loop used, and add one character to it.</p></div><div class="solution"><pre class="code"><span class="keyword">var</span> <span class="variable">line</span> = <span class="string">""</span>;
+<span class="keyword">var</span> <span class="variable">counter</span> = <span class="atom">0</span>;
+<span class="keyword">while</span> (<span class="variable">counter</span> < <span class="atom">10</span>) {
+ <span class="variable">line</span> = <span class="variable">line</span> + <span class="string">"#"</span>;
+ <span class="variable">print</span>(<span class="variable">line</span>);
+ <span class="variable">counter</span> = <span class="variable">counter</span> + <span class="atom">1</span>;
+}</pre></div></div><hr/><div class="block"><p><a class="paragraph" href="#p2cbd44fa16ea3e42" name="p2cbd44fa16ea3e42"> </a>You will have noticed the spaces I put in front of some statements.
+These are not required: The computer will accept the program just fine
+without them. In fact, even the line breaks in programs are optional.
+You could write them as a single long line if you felt like it. The
+role of the <a name="key62"></a>indentation inside blocks is to make the structure of
+the code clearer to a reader. Because new blocks can be opened inside
+other blocks, it can become hard to see where one block ends and
+another begins in a complex piece of code. When lines are indented,
+the visual shape of a program corresponds to the shape of the blocks
+inside it. I like to use two spaces for every open block, but tastes
+differ.</p><p><a class="paragraph" href="#p4a14ae9b87cb1618" name="p4a14ae9b87cb1618"> </a>The field in the console where you can type programs will help you by
+automatically adding these spaces. This may seem annoying at first,
+but when you write a lot of code it becomes a huge time-saver.
+Pressing shift+tab will re-indent the line your cursor is currently
+on.</p><p><a class="paragraph" href="#p4560113d751953db" name="p4560113d751953db"> </a>In some cases, JavaScript allows you to omit the semicolon at the end
+of a statement. In other cases, it has to be there or strange things
+will happen. The rules for when it can be safely omitted are complex
+and weird. In this book, I won't leave out any semicolons, and I
+strongly urge you to do the same in your own programs.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p18c9a1b55326c0b7" name="p18c9a1b55326c0b7"> </a>The uses of <code>while</code> we have seen so far all show the same pattern.
+First, a 'counter' variable is created. This variable tracks the
+progress of the loop. The <code>while</code> itself contains a check, usually to
+see whether the counter has reached some boundary yet. Then, at the
+end of the loop body, the counter is updated.</p><p><a class="paragraph" href="#p7669ecc2de8963e6" name="p7669ecc2de8963e6"> </a>A lot of loops fall into this pattern. For this reason, JavaScript,
+and similar languages, also provide a slightly shorter and more
+comprehensive form:</p><pre class="code"><span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">number</span> = <span class="atom">0</span>; <span class="variable">number</span> <= <span class="atom">12</span>; <span class="variable">number</span> = <span class="variable">number</span> + <span class="atom">2</span>)
+ <span class="variable">show</span>(<span class="variable">number</span>);</pre><p><a class="paragraph" href="#p33ad2075537c4259" name="p33ad2075537c4259"> </a>This program is exactly equivalent to the earlier even-number-printing
+example. The only change is that all the statements that are related
+to the 'state' of the loop are now on one line. The parentheses after
+the <a name="key63"></a><code>for</code> should contain two semicolons. The part before the first
+semicolon <em>initialises</em> the loop, usually by defining a variable. The
+second part is the expression that <em>checks</em> whether the loop must
+still continue. The final part <em>updates</em> the state of the loop. In
+most cases this is shorter and clearer than a <code>while</code> construction.</p></div><hr/><div class="block"><p><a class="paragraph" href="#pcbce05838d54058" name="pcbce05838d54058"> </a>I have been using some rather odd <a name="key64"></a>capitalisation in some variable
+names. Because you can not have spaces in these names ― the computer
+would read them as two separate variables ― your choices for a name
+that is made of several words are more or less limited to the
+following: <code>fuzzylittleturtle</code>, <code>fuzzy_little_turtle</code>,
+<code>FuzzyLittleTurtle</code>, or <code>fuzzyLittleTurtle</code>. The first one is hard to
+read. Personally, I like the one with the underscores, though it is a
+little painful to type. However, the standard JavaScript functions,
+and most JavaScript programmers, follow the last one. It is not hard
+to get used to little things like that, so I will just follow the
+crowd and capitalise the first letter of every word after the first.</p><p><a class="paragraph" href="#p52f29cd4dde6b1f" name="p52f29cd4dde6b1f"> </a>In a few cases, such as the <code>Number</code> function, the first letter of a
+variable is also capitalised. This was done to mark this function as a
+constructor. What a constructor is will become clear in <a href="chapter8.html">chapter 8</a>. For
+now, the important thing is not to be bothered by this apparent lack
+of consistency.</p><p><a class="paragraph" href="#p4fcc7ad59bacc742" name="p4fcc7ad59bacc742"> </a>Note that names that have a special meaning, such as <code>var</code>, <code>while</code>,
+and <code>for</code> may not be used as variable names. These are called
+<a name="key65"></a>keywords. There are also a number of <a name="key66"></a>words which
+are 'reserved for use' in future versions of JavaScript. These are
+also officially not allowed to be used as variable names, though some
+browsers do allow them. The full list is rather long:</p><pre class="preformatted">abstract boolean break byte case catch char class const continue
+debugger default delete do double else enum export extends false
+final finally float for function goto if implements import in
+instanceof int interface long native new null package private
+protected public return short static super switch synchronized
+this throw throws transient true try typeof var void volatile
+while with</pre><p><a class="paragraph" href="#p9adbe16f2e24759" name="p9adbe16f2e24759"> </a>Don't worry about memorising these for now, but remember that this
+might be the problem when something does not work as expected. In my
+experience, <code>char</code> (to store a one-character string) and <a name="key67"></a><code>class</code> are
+the most common names to accidentally use.</p></div><hr/><div class="block"><a name="exercise4"></a><div class="exercisenum">Ex. 2.4</div><div class="exercise"><p><a class="paragraph" href="#p64b3e1eae7316320" name="p64b3e1eae7316320"> </a>Rewrite the solutions of the previous two exercises to use <code>for</code>
+instead of <code>while</code>.</p></div><div class="solution"><pre class="code"><span class="keyword">var</span> <span class="variable">result</span> = <span class="atom">1</span>;
+<span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">counter</span> = <span class="atom">0</span>; <span class="variable">counter</span> < <span class="atom">10</span>; <span class="variable">counter</span> = <span class="variable">counter</span> + <span class="atom">1</span>)
+ <span class="variable">result</span> = <span class="variable">result</span> * <span class="atom">2</span>;
+<span class="variable">show</span>(<span class="variable">result</span>);</pre><p><a class="paragraph" href="#p7d53270d94954ca6" name="p7d53270d94954ca6"> </a>Note that even if no block is opened with a '<code>{</code>', the statement in
+the loop is still indented two spaces to make it clear that it
+'belongs' to the line above it.</p><pre class="code"><span class="keyword">var</span> <span class="variable">line</span> = <span class="string">""</span>;
+<span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">counter</span> = <span class="atom">0</span>; <span class="variable">counter</span> < <span class="atom">10</span>; <span class="variable">counter</span> = <span class="variable">counter</span> + <span class="atom">1</span>) {
+ <span class="variable">line</span> = <span class="variable">line</span> + <span class="string">"#"</span>;
+ <span class="variable">print</span>(<span class="variable">line</span>);
+}</pre></div></div><hr/><div class="block"><p><a class="paragraph" href="#p3fd3bf55c1bd6483" name="p3fd3bf55c1bd6483"> </a><a name="key68"></a><a name="key69"></a><a name="key70"></a><a name="key71"></a>A program often needs to 'update' a
+variable with a value that is based on its previous value. For example
+<code>counter = counter + 1</code>. JavaScript provides a shortcut for this:
+<code>counter += 1</code>. This also works for many other operators, for example
+<code>result *= 2</code> to double the value of <code>result</code>, or <code>counter -= 1</code> to
+count downwards.</p><p><a class="paragraph" href="#p2600126f4acc14ef" name="p2600126f4acc14ef"> </a><a name="key72"></a><a name="key73"></a>For <code>counter += 1</code> and <code>counter -= 1</code> there are even
+shorter versions: <code>counter++</code> and <code>counter--</code>.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p4b80d7d05f3c7e54" name="p4b80d7d05f3c7e54"> </a>Loops are said to affect the <a name="key74"></a>control flow of a program. They change
+the order in which statements are executed. In many cases, another
+kind of flow is useful: skipping statements.</p><p><a class="paragraph" href="#p677b8a85393a1809" name="p677b8a85393a1809"> </a>We want to show all numbers below 20 which are divisible both by 3 and
+by 4.</p><pre class="code"><span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">counter</span> = <span class="atom">0</span>; <span class="variable">counter</span> < <span class="atom">20</span>; <span class="variable">counter</span>++) {
+ <span class="keyword">if</span> (<span class="variable">counter</span> % <span class="atom">3</span> == <span class="atom">0</span> && <span class="variable">counter</span> % <span class="atom">4</span> == <span class="atom">0</span>)
+ <span class="variable">show</span>(<span class="variable">counter</span>);
+}</pre><p><a class="paragraph" href="#p579ad0ae40d2b6b6" name="p579ad0ae40d2b6b6"> </a>The keyword <a name="key75"></a><code>if</code> is not too different from the keyword <code>while</code>: It
+checks the condition it is given (between parentheses), and executes
+the statement after it based on this condition. But it does this only
+once, so that the statement is executed zero or one time.</p><p><a class="paragraph" href="#p12100a1e5918d8f7" name="p12100a1e5918d8f7"> </a>The trick with the remainder (<a name="key76"></a><code>%</code>) operator is an easy way to test
+whether a number is divisible by another number. If it is, the
+remainder of their division, which is what remainder gives you, is zero.</p><p><a class="paragraph" href="#p406399b46620cc88" name="p406399b46620cc88"> </a>If we wanted to print all numbers below 20, but put
+parentheses around the ones that are not divisible by 4, we can do it
+like this:</p><pre class="code"><span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">counter</span> = <span class="atom">0</span>; <span class="variable">counter</span> < <span class="atom">20</span>; <span class="variable">counter</span>++) {
+ <span class="keyword">if</span> (<span class="variable">counter</span> % <span class="atom">4</span> == <span class="atom">0</span>)
+ <span class="variable">print</span>(<span class="variable">counter</span>);
+ <span class="keyword">if</span> (<span class="variable">counter</span> % <span class="atom">4</span> != <span class="atom">0</span>)
+ <span class="variable">print</span>(<span class="string">"("</span> + <span class="variable">counter</span> + <span class="string">")"</span>);
+}</pre><p><a class="paragraph" href="#pb00f039a340e1f1" name="pb00f039a340e1f1"> </a>But now the program has to determine whether <code>counter</code> is divisible by
+<code>4</code> two times. The same effect can be obtained by appending an <code>else</code>
+part after an <code>if</code> statement. The <a name="key77"></a><code>else</code> statement is executed only
+when the <code>if</code>'s condition is false.</p><pre class="code"><span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">counter</span> = <span class="atom">0</span>; <span class="variable">counter</span> < <span class="atom">20</span>; <span class="variable">counter</span>++) {
+ <span class="keyword">if</span> (<span class="variable">counter</span> % <span class="atom">4</span> == <span class="atom">0</span>)
+ <span class="variable">print</span>(<span class="variable">counter</span>);
+ <span class="keyword">else</span>
+ <span class="variable">print</span>(<span class="string">"("</span> + <span class="variable">counter</span> + <span class="string">")"</span>);
+}</pre><p><a class="paragraph" href="#p44c5da1f0b1e4e71" name="p44c5da1f0b1e4e71"> </a>To stretch this trivial example a bit further, we now want to print
+these same numbers, but add two stars after them when they are greater
+than 15, one star when they are greater than 10 (but not greater than
+15), and no stars otherwise.</p><pre class="code"><span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">counter</span> = <span class="atom">0</span>; <span class="variable">counter</span> < <span class="atom">20</span>; <span class="variable">counter</span>++) {
+ <span class="keyword">if</span> (<span class="variable">counter</span> > <span class="atom">15</span>)
+ <span class="variable">print</span>(<span class="variable">counter</span> + <span class="string">"**"</span>);
+ <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">counter</span> > <span class="atom">10</span>)
+ <span class="variable">print</span>(<span class="variable">counter</span> + <span class="string">"*"</span>);
+ <span class="keyword">else</span>
+ <span class="variable">print</span>(<span class="variable">counter</span>);
+}</pre><p><a class="paragraph" href="#p10bbb4606536644" name="p10bbb4606536644"> </a>This demonstrates that you can chain <code>if</code> statements together. In this
+case, the program first looks if <code>counter</code> is greater than <code>15</code>. If it
+is, the two stars are printed and the other tests are skipped. If it
+is not, we continue to check if <code>counter</code> is greater than <code>10</code>. Only
+if <code>counter</code> is also not greater than <code>10</code> does it arrive at the last
+<code>print</code> statement.</p></div><hr/><div class="block"><a name="exercise5"></a><div class="exercisenum">Ex. 2.5</div><div class="exercise"><p><a class="paragraph" href="#p3d2dfd849f445bb0" name="p3d2dfd849f445bb0"> </a>Write a program to ask yourself, using <code>prompt</code>, what the value of 2 +
+2 is. If the answer is "4", use <code>alert</code> to say something praising. If
+it is "3" or "5", say "Almost!". In other cases, say something mean.</p></div><div class="solution"><pre class="code"><span class="keyword">var</span> <span class="variable">answer</span> = <span class="variable">prompt</span>(<span class="string">"You! What is the value of 2 + 2?"</span>, <span class="string">""</span>);
+<span class="keyword">if</span> (<span class="variable">answer</span> == <span class="string">"4"</span>)
+ <span class="variable">alert</span>(<span class="string">"You must be a genius or something."</span>);
+<span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">answer</span> == <span class="string">"3"</span> || <span class="variable">answer</span> == <span class="string">"5"</span>)
+ <span class="variable">alert</span>(<span class="string">"Almost!"</span>);
+<span class="keyword">else</span>
+ <span class="variable">alert</span>(<span class="string">"You're an embarrassment."</span>);</pre></div></div><hr/><div class="block"><p><a class="paragraph" href="#p6f4a538a0fca3f13" name="p6f4a538a0fca3f13"> </a>When a loop does not always have to go all the way through to its end,
+the <a name="key78"></a><code>break</code> keyword can be useful. It immediately jumps out of the
+current loop, continuing after it. This program finds the first number
+that is greater than or equal to 20 and divisible by 7:</p><pre class="code"><span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">current</span> = <span class="atom">20</span>; ; <span class="variable">current</span>++) {
+ <span class="keyword">if</span> (<span class="variable">current</span> % <span class="atom">7</span> == <span class="atom">0</span>)
+ <span class="keyword">break</span>;
+}
+<span class="variable">print</span>(<span class="variable">current</span>);</pre><p><a class="paragraph" href="#p22724963e529c807" name="p22724963e529c807"> </a>The <code>for</code> construct shown above does not have a part that checks for
+the end of the loop. This means that it is dependent on the <code>break</code>
+statement inside it to ever stop. The same program could also have
+been written as simply...</p><pre class="code"><span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">current</span> = <span class="atom">20</span>; <span class="variable">current</span> % <span class="atom">7</span> != <span class="atom">0</span>; <span class="variable">current</span>++)
+ ;
+<span class="variable">print</span>(<span class="variable">current</span>);</pre><p><a class="paragraph" href="#p404799311561aa83" name="p404799311561aa83"> </a>In this case, the body of the loop is empty. A lone semicolon can be
+used to produce an empty statement. Here, the only effect of the loop
+is to increment the variable <code>current</code> to its desired value. But I
+needed an example that uses <code>break</code>, so pay attention to the first
+version too.</p></div><hr/><div class="block"><a name="exercise6"></a><div class="exercisenum">Ex. 2.6</div><div class="exercise"><p><a class="paragraph" href="#p7fdea634b22eece5" name="p7fdea634b22eece5"> </a>Add a <code>while</code> and optionally a <code>break</code> to your solution for the
+previous exercise, so that it keeps repeating the question until a
+correct answer is given.</p><p><a class="paragraph" href="#p165e246df3370008" name="p165e246df3370008"> </a>Note that <code>while (true) ...</code> can be used to create a loop that does
+not end on its own account. This is a bit silly, you ask the program
+to loop as long as <code>true</code> is <code>true</code>, but it is a useful trick.</p></div><div class="solution"><pre class="code"><span class="keyword">var</span> <span class="variable">answer</span>;
+<span class="keyword">while</span> (<span class="atom">true</span>) {
+ <span class="variable">answer</span> = <span class="variable">prompt</span>(<span class="string">"You! What is the value of 2 + 2?"</span>, <span class="string">""</span>);
+ <span class="keyword">if</span> (<span class="variable">answer</span> == <span class="string">"4"</span>) {
+ <span class="variable">alert</span>(<span class="string">"You must be a genius or something."</span>);
+ <span class="keyword">break</span>;
+ }
+ <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">answer</span> == <span class="string">"3"</span> || <span class="variable">answer</span> == <span class="string">"5"</span>) {
+ <span class="variable">alert</span>(<span class="string">"Almost!"</span>);
+ }
+ <span class="keyword">else</span> {
+ <span class="variable">alert</span>(<span class="string">"You're an embarrassment."</span>);
+ }
+}</pre><p><a class="paragraph" href="#p71ee6870077747b6" name="p71ee6870077747b6"> </a>Because the first <code>if</code>'s body now has two statements, I added braces
+around all the bodies. This is a matter of taste. Having an
+<code>if</code>/<code>else</code> chain where some of the bodies are blocks and others are
+single statements looks a bit lopsided to me, but you can make up your
+own mind about that.</p><p><a class="paragraph" href="#paf1d0463f490564" name="paf1d0463f490564"> </a>Another solution, arguably nicer, but without <code>break</code>:</p><pre class="code"><span class="keyword">var</span> <span class="variable">value</span> = <span class="atom">null</span>;
+<span class="keyword">while</span> (<span class="variable">value</span> != <span class="string">"4"</span>) {
+ <span class="variable">value</span> = <span class="variable">prompt</span>(<span class="string">"You! What is the value of 2 + 2?"</span>, <span class="string">""</span>);
+ <span class="keyword">if</span> (<span class="variable">value</span> == <span class="string">"4"</span>)
+ <span class="variable">alert</span>(<span class="string">"You must be a genius or something."</span>);
+ <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">value</span> == <span class="string">"3"</span> || <span class="variable">value</span> == <span class="string">"5"</span>)
+ <span class="variable">alert</span>(<span class="string">"Almost!"</span>);
+ <span class="keyword">else</span>
+ <span class="variable">alert</span>(<span class="string">"You're an embarrassment."</span>);
+}</pre></div></div><hr/><div class="block"><p><a class="paragraph" href="#p26084c692e69b3e7" name="p26084c692e69b3e7"> </a>In the solution to the previous exercise there is a statement <code>var
+answer;</code>. This creates a variable named <code>answer</code>, but does not give it
+a value. What happens when you take the value of this variable?</p><pre class="code"><span class="keyword">var</span> <span class="variable">mysteryVariable</span>;
+<span class="variable">show</span>(<span class="variable">mysteryVariable</span>);</pre><p><a class="paragraph" href="#p60044b005bb576ee" name="p60044b005bb576ee"> </a>In terms of tentacles, this variable ends in thin air, it has nothing
+to grasp. When you ask for the value of an empty place, you get a
+special value named <a name="key79"></a><code>undefined</code>. Functions which do not return an
+interesting value, such as <code>print</code> and <code>alert</code>, also return an
+<code>undefined</code> value.</p><pre class="code"><span class="variable">show</span>(<span class="variable">alert</span>(<span class="string">"I am a side effect."</span>));</pre><p><a class="paragraph" href="#p697d039f6b8b3ea" name="p697d039f6b8b3ea"> </a>There is also a similar value, <a name="key80"></a><code>null</code>, whose meaning is 'this
+variable is defined, but it does not have a value'. The difference in
+meaning between <code>undefined</code> and <code>null</code> is mostly academic, and usually
+not very interesting. In practical programs, it is often necessary to
+check whether something 'has a value'. In these cases, the expression
+<code>something == undefined</code> may be used, because, even though they are
+not exactly the same value, <code>null == undefined</code> will produce <code>true</code>.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p6fa1962abd3e4a44" name="p6fa1962abd3e4a44"> </a>Which brings us to another tricky subject...</p><pre class="code"><span class="variable">show</span>(<span class="atom">false</span> == <span class="atom">0</span>);
+<span class="variable">show</span>(<span class="string">""</span> == <span class="atom">0</span>);
+<span class="variable">show</span>(<span class="string">"5"</span> == <span class="atom">5</span>);</pre><p><a class="paragraph" href="#p1e190ad10128d250" name="p1e190ad10128d250"> </a><a name="key81"></a>All these give the value <code>true</code>. When comparing
+values that have different types, JavaScript uses a complicated and
+confusing set of rules. I am not going to try to explain them
+precisely, but in most cases it just tries to convert one of the
+values to the type of the other value. However, when <code>null</code> or
+<code>undefined</code> occur, it only produces <code>true</code> if both sides are <code>null</code> or
+<code>undefined</code>.</p><p><a class="paragraph" href="#p24a1cdeb125eebb1" name="p24a1cdeb125eebb1"> </a>What if you want to test whether a variable refers to the value
+<code>false</code>? The rules for converting strings and numbers to boolean
+values state that <code>0</code> and the empty string count as <code>false</code>, while all
+the other values count as <code>true</code>. Because of this, the expression
+<code>variable == false</code> is also <code>true</code> when <code>variable</code> refers to <code>0</code> or
+<code>""</code>. For cases like this, where you do <em>not</em> want any automatic type
+conversions to happen, there are two extra operators: <a name="key82"></a><code>===</code> and
+<a name="key83"></a><code>!==</code>. The first tests whether a value is precisely equal to the
+other, and the second tests whether it is not precisely equal.</p><pre class="code"><span class="variable">show</span>(<span class="atom">null</span> === <span class="atom">undefined</span>);
+<span class="variable">show</span>(<span class="atom">false</span> === <span class="atom">0</span>);
+<span class="variable">show</span>(<span class="string">""</span> === <span class="atom">0</span>);
+<span class="variable">show</span>(<span class="string">"5"</span> === <span class="atom">5</span>);</pre><p><a class="paragraph" href="#p24c6f6ff2ef5a755" name="p24c6f6ff2ef5a755"> </a>All these are <code>false</code>.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p6b0cbd256d266d" name="p6b0cbd256d266d"> </a>Values given as the condition in an <code>if</code>, <code>while</code>, or <code>for</code> statement
+do not have to be booleans. They will be automatically converted to
+booleans before they are checked. This means that the number <code>0</code>, the
+empty string <code>""</code>, <code>null</code>, <code>undefined</code>, and of course <code>false</code>, will
+all count as false.</p><p><a class="paragraph" href="#p9b525f85d56aa6e" name="p9b525f85d56aa6e"> </a>The fact that all other values are converted to <code>true</code> in this case
+makes it possible to leave out explicit comparisons in many
+situations. If a variable is known to contain either a string or
+<code>null</code>, one could check for this very simply...</p><pre class="code"><span class="keyword">var</span> <span class="variable">maybeNull</span> = <span class="atom">null</span>;
+<span class="comment">// ... mystery code that might put a string into maybeNull ...</span>
+<span class="keyword">if</span> (<span class="variable">maybeNull</span>)
+ <span class="variable">print</span>(<span class="string">"maybeNull has a value"</span>);</pre><p><a class="paragraph" href="#p5a78f60b263ff17d" name="p5a78f60b263ff17d"> </a>... except in the case where the mystery code gives <code>maybeNull</code> the
+value <code>""</code>. An empty string is false, so nothing is printed. Depending
+on what you are trying to do, this might be <em>wrong</em>. It is often a
+good idea to add an explicit <code>=== null</code> or <code>=== false</code> in cases like
+this to prevent subtle mistakes. The same occurs with number values
+that might be <code>0</code>.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p679c07c88ec62790" name="p679c07c88ec62790"> </a>The line that talks about 'mystery code' in the previous example might
+have looked a bit suspicious to you. It is often useful to include
+extra text in a program. The most common use for this is adding some
+explanations in human language to a program.</p><pre class="code"><span class="comment">// The variable counter, which is about to be defined, is going</span>
+<span class="comment">// to start with a value of 0, which is zero.</span>
+<span class="keyword">var</span> <span class="variable">counter</span> = <span class="atom">0</span>;
+<span class="comment">// Now, we are going to loop, hold on to your hat.</span>
+<span class="keyword">while</span> (<span class="variable">counter</span> < <span class="atom">100</span> <span class="comment">/* counter is less than one hundred */</span>)
+<span class="comment">/* Every time we loop, we INCREMENT the value of counter,
+ Seriously, we just add one to it. */</span>
+ <span class="variable">counter</span>++;
+<span class="comment">// And then, we are done.</span></pre><p><a class="paragraph" href="#p6314c8d46b2c537a" name="p6314c8d46b2c537a"> </a>This kind of text is called a <a name="key84"></a>comment. The rules are like this:
+'<code>/*</code>' starts a comment that goes on until a '<code>*/</code>' is found. '<code>//</code>'
+starts another kind of comment, which goes on until the end of the
+line.</p><p><a class="paragraph" href="#p1c8efde0fed0bf98" name="p1c8efde0fed0bf98"> </a>As you can see, even the simplest programs can be made to look big,
+ugly, and complicated by simply adding a lot of comments to them.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p6c1556cf0eda8c15" name="p6c1556cf0eda8c15"> </a>There are some other situations that cause automatic <a name="key85"></a>type
+conversions to happen. If you add a non-string value to a string, the
+value is automatically converted to a string before it is
+concatenated. If you multiply a number and a string, JavaScript tries
+to make a number out of the string.</p><pre class="code"><span class="variable">show</span>(<span class="string">"Apollo"</span> + <span class="atom">5</span>);
+<span class="variable">show</span>(<span class="atom">null</span> + <span class="string">"ify"</span>);
+<span class="variable">show</span>(<span class="string">"5"</span> * <span class="atom">5</span>);
+<span class="variable">show</span>(<span class="string">"strawberry"</span> * <span class="atom">5</span>);</pre><p><a class="paragraph" href="#p182041e0447d25bd" name="p182041e0447d25bd"> </a>The last statement prints <a name="key86"></a><code>NaN</code>, which is a special value. It stands
+for 'not a number', and is of type number (which might sound a little
+contradictory). In this case, it refers to the fact that a strawberry
+is not a number. All arithmetic operations on the value <code>NaN</code> result
+in <code>NaN</code>, which is why multiplying it by <code>5</code>, as in the example, still
+gives a <code>NaN</code> value. Also, and this can be disorienting at times, <code>NaN
+== NaN</code> equals <code>false</code>, checking whether a value is <code>NaN</code> can be done
+with the <a name="key87"></a><code>isNaN</code> function. <code>NaN</code> is another (the last) value that
+counts as <code>false</code> when converted to a boolean.</p><p><a class="paragraph" href="#p36148be46ecef1b3" name="p36148be46ecef1b3"> </a>These automatic conversions can be very convenient, but they are also
+rather weird and error prone. Even though <code>+</code> and <code>*</code> are both
+arithmetic operators, they behave completely different in the example.
+In my own code, I use <code>+</code> to combine strings and non-strings a lot,
+but make it a point not to use <code>*</code> and the other numeric operators on
+string values. Converting a number to a string is always possible and
+straightforward, but converting a string to a number may not even work
+(as in the last line of the example). We can use <code>Number</code> to
+explicitly convert the string to a number, making it clear that we
+might run the risk of getting a <code>NaN</code> value.</p><pre class="code"><span class="variable">show</span>(<span class="variable">Number</span>(<span class="string">"5"</span>) * <span class="atom">5</span>);</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p558c67182a2437b2" name="p558c67182a2437b2"> </a>When we discussed the boolean operators <code>&&</code> and <code>||</code> earlier, I
+claimed they produced boolean values. This turns out to be a bit of an
+oversimplification. If you apply them to boolean values, they will
+indeed return booleans. But they can also be applied to other kinds of
+values, in which case they will return one of their arguments.</p><p><a class="paragraph" href="#p3e7102c343c2cac3" name="p3e7102c343c2cac3"> </a>What <a name="key88"></a><code>||</code> really does is this: It looks at the value to the left of
+it first. If converting this value to a boolean would produce <code>true</code>,
+it returns this left value, otherwise it returns the one on its
+right. Check for yourself that this does the correct thing when the
+arguments are booleans. Why does it work like that? It turns out this
+is very practical. Consider this example:</p><pre class="code"><span class="keyword">var</span> <span class="variable">input</span> = <span class="variable">prompt</span>(<span class="string">"What is your name?"</span>, <span class="string">"Kilgore Trout"</span>);
+<span class="variable">print</span>(<span class="string">"Well hello "</span> + (<span class="variable">input</span> || <span class="string">"dear"</span>));</pre><p><a class="paragraph" href="#p1d27bd58eb76bd59" name="p1d27bd58eb76bd59"> </a>If the user presses 'Cancel' or closes the <code>prompt</code> dialog in some
+other way without giving a name, the variable <code>input</code> will hold the
+value <code>null</code> or <code>""</code>. Both of these would give <code>false</code> when converted
+to a boolean. The expression <code>input || "dear"</code> can in this case be
+read as 'the value of the variable <code>input</code>, or else the string
+<code>"dear"</code>'. It is an easy way to provide a 'fallback' value.</p><p><a class="paragraph" href="#p2c9d338cf8ef8b92" name="p2c9d338cf8ef8b92"> </a>The <a name="key89"></a><code>&&</code> operator works similarly, but the other way around. When
+the value to its left is something that would give <code>false</code> when
+converted to a boolean, it returns that value, otherwise it returns
+the value on its right.</p><p><a class="paragraph" href="#p375b61ed74770a64" name="p375b61ed74770a64"> </a>Another property of these two operators is that the expression to
+their right is only evaluated when necessary. In the case of <code>true ||
+X</code>, no matter what <code>X</code> is, the result will be <code>true</code>, so <code>X</code> is never
+evaluated, and if it has side effects they never happen. The same goes
+for <code>false && X</code>.</p><pre class="code"><span class="atom">false</span> || <span class="variable">alert</span>(<span class="string">"I'm happening!"</span>);
+<span class="atom">true</span> || <span class="variable">alert</span>(<span class="string">"Not me."</span>);</pre></div><ol class="footnotes"><li><a name="footnote1"></a>Bits are any kinds of two-valued things, usually described as <code>0</code>s
+and <code>1</code>s. Inside the computer, they take forms like a high or low
+electrical charge, a strong or weak signal, a shiny or dull spot on
+the surface of a CD.</li><li><a name="footnote2"></a>If you were expecting something like <code>10010000</code> here ― good call,
+but read on. JavaScript's numbers are not stored as integers.</li><li><a name="footnote3"></a>Actually, 53, because of a trick that can be used to get one bit
+for free. Look up the 'IEEE 754' format if you are curious about the
+details.</li><li><a name="footnote4"></a>When you type string values at the console, you'll notice that they
+will come back with the quotes and backslashes the way you typed them.
+To get special characters to show properly, you can do <code>print("a\nb")</code>
+― why this works, we will see in a moment.</li><li><a name="footnote5"></a>The bit bucket is supposedly the place where old bits are kept. On
+some systems, the programmer has to manually empty it now and then.
+Fortunately, JavaScript comes with a fully-automatic bit-recycling
+system.</li></ol><h1><span class="number">Chapter 3: </span>Functions</h1><div class="block"><p><a class="paragraph" href="#p1ab13025e2cb1812" name="p1ab13025e2cb1812"> </a>A program often needs to do the same thing in different places.
+Repeating all the necessary statements every time is tedious and
+error-prone. It would be better to put them in one place, and have the
+program take a detour through there whenever necessary. This is what
+<a name="key1"></a>functions were invented for: They are canned code that a program can
+go through whenever it wants. Putting a string on the screen requires
+quite a few statements, but when we have a <code>print</code> function we can
+just write <code>print("Aleph")</code> and be done with it.</p><p><a class="paragraph" href="#p54c8e7a89febfb72" name="p54c8e7a89febfb72"> </a>To view functions merely as canned chunks of code doesn't do them
+justice though. When needed, they can play the role of pure functions,
+algorithms, indirections, abstractions, decisions, modules,
+continuations, data structures, and more. Being able to effectively
+use functions is a necessary skill for any kind of serious
+programming. This chapter provides an introduction into the subject,
+<a href="chapter6.html">chapter 6</a> discusses the subtleties of functions in more depth.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p7a12e37bc40802a0" name="p7a12e37bc40802a0"> </a><a name="key2"></a>Pure functions, for a start, are the things that were
+called functions in the mathematics classes that I hope you have been
+subjected to at some point in your life. Taking the cosine or the
+absolute value of a number is a pure function of one argument.
+Addition is a pure function of two arguments.</p><p><a class="paragraph" href="#p522f322a2c4f7492" name="p522f322a2c4f7492"> </a>The defining properties of pure functions are that they always return
+the same value when given the same arguments, and never have side
+effects. They take some arguments, return a value based on these
+arguments, and do not monkey around with anything else.</p><p><a class="paragraph" href="#p40b7ab0395b26dd5" name="p40b7ab0395b26dd5"> </a>In JavaScript, addition is an operator, but it could be wrapped in a
+function like this (and as pointless as this looks, we will come
+across situations where it is actually useful):</p><pre class="code"><span class="keyword">function</span> <span class="variable">add</span>(<span class="variabledef">a</span>, <span class="variabledef">b</span>) {
+ <span class="keyword">return</span> <span class="localvariable">a</span> + <span class="localvariable">b</span>;
+}
+
+<span class="variable">show</span>(<span class="variable">add</span>(<span class="atom">2</span>, <span class="atom">2</span>));</pre><p><a class="paragraph" href="#p759819d221350eb" name="p759819d221350eb"> </a><code>add</code> is the name of the function. <code>a</code> and <code>b</code> are the names of the
+two arguments. <code>return a + b;</code> is the body of the function.</p><p><a class="paragraph" href="#p6d3341a7ad2c86b6" name="p6d3341a7ad2c86b6"> </a>The keyword <a name="key3"></a><code>function</code> is always used when creating a new function.
+When it is followed by a variable name, the resulting function will be
+stored under this name. After the name comes a list of <a name="key4"></a>argument
+names, and then finally the <a name="key5"></a>body of the function. Unlike those
+around the body of <code>while</code> loops or <code>if</code> statements, the braces around
+a function body are obligatory<a class="footref" href="#footnote1">1</a>.</p><p><a class="paragraph" href="#p3734bedf153a1c6c" name="p3734bedf153a1c6c"> </a>The keyword <a name="key6"></a><code>return</code>, followed by an expression, is used to
+determine the value the function returns. When control comes across a
+<code>return</code> statement, it immediately jumps out of the current function
+and gives the returned value to the code that called the function. A
+<code>return</code> statement without an expression after it will cause the
+function to return <code>undefined</code>.</p><p><a class="paragraph" href="#p226693db801b5db6" name="p226693db801b5db6"> </a>A body can, of course, have more than one statement in it. Here is a
+function for computing powers (with positive, integer exponents):</p><pre class="code"><span class="keyword">function</span> <span class="variable">power</span>(<span class="variabledef">base</span>, <span class="variabledef">exponent</span>) {
+ <span class="keyword">var</span> <span class="variabledef">result</span> = <span class="atom">1</span>;
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variabledef">count</span> = <span class="atom">0</span>; <span class="localvariable">count</span> < <span class="localvariable">exponent</span>; <span class="localvariable">count</span>++)
+ <span class="localvariable">result</span> *= <span class="localvariable">base</span>;
+ <span class="keyword">return</span> <span class="localvariable">result</span>;
+}
+
+<span class="variable">show</span>(<span class="variable">power</span>(<span class="atom">2</span>, <span class="atom">10</span>));</pre><p><a class="paragraph" href="#p19cfe95b03c8e65a" name="p19cfe95b03c8e65a"> </a>If you solved <a href="chapter2.html#exercise2">exercise 2.2</a>, this technique for computing a power should
+look familiar.</p><p><a class="paragraph" href="#p1dcbee6b83ab5ea0" name="p1dcbee6b83ab5ea0"> </a>Creating a variable (<code>result</code>) and updating it are side effects.
+Didn't I just say pure functions had no side effects?</p><p><a class="paragraph" href="#p6c03fbcaffeb52" name="p6c03fbcaffeb52"> </a>A variable created inside a function exists only inside the function.
+This is fortunate, or a programmer would have to come up with a
+different name for every variable he needs throughout a program.
+Because <code>result</code> only exists inside <code>power</code>, the changes to it only
+last until the function returns, and from the perspective of code that
+calls it there are no side effects.</p></div><hr/><div class="block"><a name="exercise1"></a><div class="exercisenum">Ex. 3.1</div><div class="exercise"><p><a class="paragraph" href="#pf048437a44d112e" name="pf048437a44d112e"> </a>Write a function called <code>absolute</code>, which returns the absolute value
+of the number it is given as its argument. The absolute value of a
+negative number is the positive version of that same number, and the
+absolute value of a positive number (or zero) is that number itself.</p></div><div class="solution"><pre class="code"><span class="keyword">function</span> <span class="variable">absolute</span>(<span class="variabledef">number</span>) {
+ <span class="keyword">if</span> (<span class="localvariable">number</span> < <span class="atom">0</span>)
+ <span class="keyword">return</span> -<span class="localvariable">number</span>;
+ <span class="keyword">else</span>
+ <span class="keyword">return</span> <span class="localvariable">number</span>;
+}
+
+<span class="variable">show</span>(<span class="variable">absolute</span>(-<span class="atom">144</span>));</pre></div></div><hr/><div class="block"><p><a class="paragraph" href="#p3ab0c3f84a641284" name="p3ab0c3f84a641284"> </a>Pure functions have two very nice properties. They are easy to think
+about, and they are easy to re-use.</p><p><a class="paragraph" href="#p68a342c634d718df" name="p68a342c634d718df"> </a>If a function is pure, a call to it can be seen as a thing in itself.
+When you are not sure that it is working correctly, you can test it by
+calling it directly from the console, which is simple because it does
+not depend on any context<a class="footref" href="#footnote2">2</a>. It is easy to make these tests automatic
+― to write a program that tests a specific function. Non-pure
+functions might return different values based on all kinds of factors,
+and have side effects that might be hard to test and think about.</p><p><a class="paragraph" href="#p9a097a88dff1354" name="p9a097a88dff1354"> </a>Because pure functions are self-sufficient, they are likely to be
+useful and relevant in a wider range of situations than non-pure ones.
+Take <code>show</code>, for example. This function's usefulness depends on the
+presence of a special place on the screen for printing output. If that
+place is not there, the function is useless. We can imagine a related
+function, let's call it <code>format</code>, that takes a value as an argument
+and returns a string that represents this value. This function is
+useful in more situations than <code>show</code>.</p><p><a class="paragraph" href="#p49c26f53b5129803" name="p49c26f53b5129803"> </a>Of course, <code>format</code> does not solve the same problem as <code>show</code>, and no
+pure function is going to be able to solve that problem, because it
+requires a side effect. In many cases, non-pure functions are
+precisely what you need. In other cases, a problem can be solved with
+a pure function but the non-pure variant is much more convenient or
+efficient.</p><p><a class="paragraph" href="#p7e26f30e06605ddf" name="p7e26f30e06605ddf"> </a>Thus, when something can easily be expressed as a pure function, write
+it that way. But never feel dirty for writing non-pure functions.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p7e4f5f8e5d70151c" name="p7e4f5f8e5d70151c"> </a>Functions with side effects do not have to contain a <code>return</code>
+statement. If no <code>return</code> statement is encountered, the function
+returns <code>undefined</code>.</p><pre class="code"><span class="keyword">function</span> <span class="variable">yell</span>(<span class="variabledef">message</span>) {
+ <span class="variable">alert</span>(<span class="localvariable">message</span> + <span class="string">"!!"</span>);
+}
+
+<span class="variable">yell</span>(<span class="string">"Yow"</span>);</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p468c043e14dd0d54" name="p468c043e14dd0d54"> </a>The names of the arguments of a function are available as variables
+inside it. They will refer to the values of the arguments the function
+is being called with, and like normal variables created inside a
+function, they do not exist outside it. Aside from the <a name="key7"></a>top-level
+environment, there are smaller, <a name="key8"></a>local environments created by
+function calls. When looking up a variable inside a function, the
+local environment is checked first, and only if the variable does not
+exist there is it looked up in the top-level environment. This makes
+it possible for variables inside a function to '<a name="key9"></a>shadow' top-level
+variables that have the same name.</p><pre class="code"><span class="keyword">function</span> <span class="variable">alertIsPrint</span>(<span class="variabledef">value</span>) {
+ <span class="keyword">var</span> <span class="variabledef">alert</span> = <span class="variable">print</span>;
+ <span class="localvariable">alert</span>(<span class="localvariable">value</span>);
+}
+
+<span class="variable">alertIsPrint</span>(<span class="string">"Troglodites"</span>);</pre><p><a class="paragraph" href="#pbd8c4daf6299d2b" name="pbd8c4daf6299d2b"> </a>The variables in this local environment are only visible to the code
+inside the function. If this function calls another function, the
+newly called function does not see the variables inside the first
+function:</p><pre class="code"><span class="keyword">var</span> <span class="variable">variable</span> = <span class="string">"top-level"</span>;
+
+<span class="keyword">function</span> <span class="variable">printVariable</span>() {
+ <span class="variable">print</span>(<span class="string">"inside printVariable, the variable holds '"</span> +
+ <span class="variable">variable</span> + <span class="string">"'."</span>);
+}
+
+<span class="keyword">function</span> <span class="variable">test</span>() {
+ <span class="keyword">var</span> <span class="variabledef">variable</span> = <span class="string">"local"</span>;
+ <span class="variable">print</span>(<span class="string">"inside test, the variable holds '"</span> + <span class="localvariable">variable</span> + <span class="string">"'."</span>);
+ <span class="variable">printVariable</span>();
+}
+
+<span class="variable">test</span>();</pre><p><a class="paragraph" href="#p6aca90948e3a3b37" name="p6aca90948e3a3b37"> </a>However, and this is a subtle but extremely useful phenomenon, when a
+function is defined <em>inside</em> another function, its local environment
+will be based on the local environment that surrounds it instead of
+the top-level environment.</p><pre class="code"><span class="keyword">var</span> <span class="variable">variable</span> = <span class="string">"top-level"</span>;
+<span class="keyword">function</span> <span class="variable">parentFunction</span>() {
+ <span class="keyword">var</span> <span class="variabledef">variable</span> = <span class="string">"local"</span>;
+ <span class="keyword">function</span> <span class="variabledef">childFunction</span>() {
+ <span class="variable">print</span>(<span class="localvariable">variable</span>);
+ }
+ <span class="localvariable">childFunction</span>();
+}
+<span class="variable">parentFunction</span>();</pre><p><a class="paragraph" href="#pad6394b3204c0b3" name="pad6394b3204c0b3"> </a>What this comes down to is that which variables are visible inside a
+function is determined by the place of that function in the program
+text. All variables that were defined 'above' a function's definition
+are visible, which means both those in function bodies that enclose
+it, and those at the top-level of the program. This approach to
+variable visibility is called <a name="key10"></a>lexical scoping.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p56a7c524c38519f7" name="p56a7c524c38519f7"> </a>People who have experience with other programming languages might
+expect that a <a name="key11"></a>block of code (between braces) also produces a new
+local environment. Not in JavaScript. Functions are the only things
+that create a new scope. You are allowed to use free-standing blocks
+like this...</p><pre class="code"><span class="keyword">var</span> <span class="variable">something</span> = <span class="atom">1</span>;
+{
+ <span class="keyword">var</span> <span class="variable">something</span> = <span class="atom">2</span>;
+ <span class="variable">print</span>(<span class="string">"Inside: "</span> + <span class="variable">something</span>);
+}
+<span class="variable">print</span>(<span class="string">"Outside: "</span> + <span class="variable">something</span>);</pre><p><a class="paragraph" href="#p34bdadb90acc781" name="p34bdadb90acc781"> </a>... but the <code>something</code> inside the block refers to the same variable
+as the one outside the block. In fact, although blocks like this are
+allowed, they are utterly pointless. Most people agree that this is a
+bit of a design blunder by the designers of JavaScript, and ECMAScript
+Harmony will add some way to define variables that stay inside blocks
+(the <code>let</code> keyword).</p></div><hr/><div class="block"><p><a class="paragraph" href="#p51e4eea024ff2593" name="p51e4eea024ff2593"> </a>Here is a case that might surprise you:</p><pre class="code"><span class="keyword">var</span> <span class="variable">variable</span> = <span class="string">"top-level"</span>;
+<span class="keyword">function</span> <span class="variable">parentFunction</span>() {
+ <span class="keyword">var</span> <span class="variabledef">variable</span> = <span class="string">"local"</span>;
+ <span class="keyword">function</span> <span class="variabledef">childFunction</span>() {
+ <span class="variable">print</span>(<span class="localvariable">variable</span>);
+ }
+ <span class="keyword">return</span> <span class="localvariable">childFunction</span>;
+}
+
+<span class="keyword">var</span> <span class="variable">child</span> = <span class="variable">parentFunction</span>();
+<span class="variable">child</span>();</pre><p><a class="paragraph" href="#p5653f0ae129fabc0" name="p5653f0ae129fabc0"> </a><code>parentFunction</code> <em>returns</em> its internal function, and the code at the
+bottom calls this function. Even though <code>parentFunction</code> has finished
+executing at this point, the local environment where <code>variable</code> has
+the value <code>"local"</code> still exists, and <code>childFunction</code> still uses it.
+This phenomenon is called <a name="key12"></a>closure.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p428f678f2eb13e2b" name="p428f678f2eb13e2b"> </a>Apart from making it very easy to quickly see in which part of a
+program a variable will be available by looking at the shape of the
+program text, lexical scoping also allows us to 'synthesise'
+functions. By using some of the variables from an enclosing function,
+an inner function can be made to do different things. Imagine we need
+a few different but similar functions, one that adds 2 to its
+argument, one that adds 5, and so on.</p><pre class="code"><span class="keyword">function</span> <span class="variable">makeAddFunction</span>(<span class="variabledef">amount</span>) {
+ <span class="keyword">function</span> <span class="variabledef">add</span>(<span class="variabledef">number</span>) {
+ <span class="keyword">return</span> <span class="localvariable">number</span> + <span class="localvariable">amount</span>;
+ }
+ <span class="keyword">return</span> <span class="localvariable">add</span>;
+}
+
+<span class="keyword">var</span> <span class="variable">addTwo</span> = <span class="variable">makeAddFunction</span>(<span class="atom">2</span>);
+<span class="keyword">var</span> <span class="variable">addFive</span> = <span class="variable">makeAddFunction</span>(<span class="atom">5</span>);
+<span class="variable">show</span>(<span class="variable">addTwo</span>(<span class="atom">1</span>) + <span class="variable">addFive</span>(<span class="atom">1</span>));</pre><p><a class="paragraph" href="#p1ab06c166100fc1" name="p1ab06c166100fc1"> </a>To wrap your head around this, you should consider functions to not
+just package up a computation, but also an environment. Top-level
+functions simply execute in the top-level environment, that much is
+obvious. But a function defined inside another function retains access
+to the environment that existed in that function at the point when it
+was defined.</p><p><a class="paragraph" href="#p1db9285e19fa7905" name="p1db9285e19fa7905"> </a>Thus, the <code>add</code> function in the above example, which is created when
+<code>makeAddFunction</code> is called, captures an environment in which <code>amount</code>
+has a certain value. It packages this environment, together with the
+computation <code>return number + amount</code>, into a value, which is then
+returned from the outer function.</p><p><a class="paragraph" href="#p1f062bceb7c6e565" name="p1f062bceb7c6e565"> </a>When this returned function (<code>addTwo</code> or <code>addFive</code>) is called, a new
+environment―-in which the variable <code>number</code> has a value―-is created,
+as a sub-environment of the captured environment (in which <code>amount</code>
+has a value). These two values are then added, and the result is
+returned.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p666d720f386c0ed5" name="p666d720f386c0ed5"> </a>On top of the fact that different functions can contain variables of
+the same name without getting tangled up, these scoping rules also
+allow functions to call <em>themselves</em> without running into problems. A
+function that calls itself is called recursive. <a name="key13"></a>Recursion
+allows for some interesting definitions. Look at this implementation
+of <code>power</code>:</p><pre class="code"><span class="keyword">function</span> <span class="variable">power</span>(<span class="variabledef">base</span>, <span class="variabledef">exponent</span>) {
+ <span class="keyword">if</span> (<span class="localvariable">exponent</span> == <span class="atom">0</span>)
+ <span class="keyword">return</span> <span class="atom">1</span>;
+ <span class="keyword">else</span>
+ <span class="keyword">return</span> <span class="localvariable">base</span> * <span class="variable">power</span>(<span class="localvariable">base</span>, <span class="localvariable">exponent</span> - <span class="atom">1</span>);
+}</pre><p><a class="paragraph" href="#pa41bf3c2429d4ce" name="pa41bf3c2429d4ce"> </a>This is rather close to the way mathematicians define exponentiation,
+and to me it looks a lot nicer than the earlier version. It sort of
+loops, but there is no <code>while</code>, <code>for</code>, or even a local side effect to
+be seen. By calling itself, the function produces the same effect.</p><p><a class="paragraph" href="#p713cfc3161eda8a4" name="p713cfc3161eda8a4"> </a>There is one important problem though: In most browsers, this second
+version is about ten times slower than the first one. In JavaScript,
+running through a simple loop is a lot cheaper than calling a
+function multiple times.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p504e6707edebe21" name="p504e6707edebe21"> </a><a name="key14"></a>The dilemma of speed versus <a name="key15"></a>elegance is an interesting
+one. It not only occurs when deciding for or against recursion. In
+many situations, an elegant, intuitive, and often short solution can
+be replaced by a more convoluted but faster solution.</p><p><a class="paragraph" href="#p18281cd06ea544c4" name="p18281cd06ea544c4"> </a>In the case of the <code>power</code> function above the un-elegant version is
+still sufficiently simple and easy to read. It doesn't make very much
+sense to replace it with the recursive version. Often, though, the
+concepts a program is dealing with get so complex that giving up some
+efficiency in order to make the program more straightforward becomes
+an attractive choice.</p><p><a class="paragraph" href="#p41ace6ff96589ec2" name="p41ace6ff96589ec2"> </a>The basic rule, which has been repeated by many programmers and with
+which I wholeheartedly agree, is to not worry about efficiency until
+your program is provably too slow. When it is, find out which parts
+are too slow, and start exchanging elegance for efficiency in those
+parts.</p><p><a class="paragraph" href="#p4a09cae140ae6451" name="p4a09cae140ae6451"> </a>Of course, the above rule doesn't mean one should start ignoring
+performance altogether. In many cases, like the <code>power</code> function, not
+much simplicity is gained by the 'elegant' approach. In other cases,
+an experienced programmer can see right away that a simple approach is
+never going to be fast enough.</p><p><a class="paragraph" href="#p32fee7de3a4a76e7" name="p32fee7de3a4a76e7"> </a>The reason I am making a big deal out of this is that surprisingly
+many programmers focus fanatically on efficiency, even in the smallest
+details. The result is bigger, more complicated, and often less
+correct programs, which take longer to write than their more
+straightforward equivalents and often run only marginally faster.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p567ecca0115e09ef" name="p567ecca0115e09ef"> </a>But I was talking about recursion. A concept closely related to
+recursion is a thing called the <a name="key16"></a>stack. When a function is called,
+control is given to the body of that function. When that body returns,
+the code that called the function is resumed. While the body is
+running, the computer must remember the context from which the
+function was called, so that it knows where to continue afterwards.
+The place where this context is stored is called the stack.</p><p><a class="paragraph" href="#p2a20f62a6ceb5021" name="p2a20f62a6ceb5021"> </a>The fact that it is called 'stack' has to do with the fact that, as we
+saw, a function body can again call a function. Every time a function
+is called, another context has to be stored. One can visualise this as
+a stack of contexts. Every time a function is called, the current
+context is thrown on top of the stack. When a function returns, the
+context on top is taken off the stack and resumed.</p><p><a class="paragraph" href="#p66d5d68566b1c951" name="p66d5d68566b1c951"> </a>This stack requires space in the computer's memory to be stored. When
+the stack grows too big, the computer will give up with a message like
+"out of stack space" or "too much recursion". This is something that
+has to be kept in mind when writing recursive functions.</p><pre class="code invalid"><span class="keyword">function</span> <span class="variable">chicken</span>() {
+ <span class="keyword">return</span> <span class="variable">egg</span>();
+}
+<span class="keyword">function</span> <span class="variable">egg</span>() {
+ <span class="keyword">return</span> <span class="variable">chicken</span>();
+}
+<span class="variable">print</span>(<span class="variable">chicken</span>() + <span class="string">" came first."</span>);</pre><p><a class="paragraph" href="#p2236504013f7bcc1" name="p2236504013f7bcc1"> </a>In addition to demonstrating a very interesting way of writing a
+broken program, this example shows that a function does not have to
+call itself directly to be recursive. If it calls another function
+which (directly or indirectly) calls the first function again, it is
+still recursive.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p55d89141e13b97c5" name="p55d89141e13b97c5"> </a>Recursion is not always just a less-efficient alternative to looping.
+Some problems are much easier to solve with recursion than with loops.
+Most often these are problems that require exploring or processing
+several 'branches', each of which might branch out again into more
+branches.</p><p><a class="paragraph" href="#p305d5143d39f07b5" name="p305d5143d39f07b5"> </a>Consider this puzzle: By starting from the number 1 and repeatedly
+either adding 5 or multiplying by 3, an infinite amount of new numbers
+can be produced. How would you write a function that, given a number,
+tries to find a sequence of additions and multiplications that produce
+that number?</p><p><a class="paragraph" href="#p736964418741c593" name="p736964418741c593"> </a>For example, the number 13 could be reached by first multiplying 1 by
+3, and then adding 5 twice. The number 15 can not be reached at all.</p><p><a class="paragraph" href="#p39723b92f9615a1a" name="p39723b92f9615a1a"> </a>Here is the solution:</p><pre class="code"><span class="keyword">function</span> <span class="variable">findSequence</span>(<span class="variabledef">goal</span>) {
+ <span class="keyword">function</span> <span class="variabledef">find</span>(<span class="variabledef">start</span>, <span class="variabledef">history</span>) {
+ <span class="keyword">if</span> (<span class="localvariable">start</span> == <span class="localvariable">goal</span>)
+ <span class="keyword">return</span> <span class="localvariable">history</span>;
+ <span class="keyword">else</span> <span class="keyword">if</span> (<span class="localvariable">start</span> > <span class="localvariable">goal</span>)
+ <span class="keyword">return</span> <span class="atom">null</span>;
+ <span class="keyword">else</span>
+ <span class="keyword">return</span> <span class="localvariable">find</span>(<span class="localvariable">start</span> + <span class="atom">5</span>, <span class="string">"("</span> + <span class="localvariable">history</span> + <span class="string">" + 5)"</span>) ||
+ <span class="localvariable">find</span>(<span class="localvariable">start</span> * <span class="atom">3</span>, <span class="string">"("</span> + <span class="localvariable">history</span> + <span class="string">" * 3)"</span>);
+ }
+ <span class="keyword">return</span> <span class="localvariable">find</span>(<span class="atom">1</span>, <span class="string">"1"</span>);
+}
+
+<span class="variable">print</span>(<span class="variable">findSequence</span>(<span class="atom">24</span>));</pre><p><a class="paragraph" href="#p31974c4e7a3d4a5" name="p31974c4e7a3d4a5"> </a>Note that it doesn't necessarily find the <em>shortest</em> sequence of
+operations, it is satisfied when it finds any sequence at all.</p><p><a class="paragraph" href="#p6bcdfa28934ac18b" name="p6bcdfa28934ac18b"> </a>The inner <code>find</code> function, by calling itself in two different ways,
+explores both the possibility of adding 5 to the current number and of
+multiplying it by 3. When it finds the number, it returns the
+<code>history</code> string, which is used to record all the operators that were
+performed to get to this number. It also checks whether the current
+number is bigger than <code>goal</code>, because if it is, we should stop
+exploring this branch, it is not going to give us our number.</p><p><a class="paragraph" href="#p7a8b0e0dffcbe80c" name="p7a8b0e0dffcbe80c"> </a>The use of the <code>||</code> operator in the example can be read as 'return the
+solution found by adding 5 to <code>start</code>, and if that fails, return the
+solution found by multiplying <code>start</code> by 3'. It could also have been
+written in a more wordy way like this:</p><pre class="preformatted">else {
+ var found = find(start + 5, "(" + history + " + 5)");
+ if (found == null)
+ found = find(start * 3, "(" + history + " * 3)");
+ return found;
+}</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p3d589d4d45947faa" name="p3d589d4d45947faa"> </a>Even though function definitions occur as statements between the rest
+of the program, they are not part of the same time-line:</p><pre class="code"><span class="variable">print</span>(<span class="string">"The future says: "</span>, <span class="variable">future</span>());
+
+<span class="keyword">function</span> <span class="variable">future</span>() {
+ <span class="keyword">return</span> <span class="string">"We STILL have no flying cars."</span>;
+}</pre><p><a class="paragraph" href="#p4e79d3c9d40230fe" name="p4e79d3c9d40230fe"> </a>What is happening is that the computer looks up all function
+definitions, and stores the associated functions, <em>before</em> it starts
+executing the rest of the program. The same happens with functions
+that are defined inside other functions. When the outer function is
+called, the first thing that happens is that all inner functions are
+added to the new environment.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p1daddade62c5d8a" name="p1daddade62c5d8a"> </a>There is another way to define function values, which more closely
+resembles the way other values are created. When the <code>function</code>
+keyword is used in a place where an expression is expected, it is
+treated as an expression producing a function value. Functions created
+in this way do not have to be given a name (though it is allowed to
+give them one).</p><pre class="code"><span class="keyword">var</span> <span class="variable">add</span> = <span class="keyword">function</span>(<span class="variabledef">a</span>, <span class="variabledef">b</span>) {
+ <span class="keyword">return</span> <span class="localvariable">a</span> + <span class="localvariable">b</span>;
+};
+<span class="variable">show</span>(<span class="variable">add</span>(<span class="atom">5</span>, <span class="atom">5</span>));</pre><p><a class="paragraph" href="#p1ff0501f8151fde7" name="p1ff0501f8151fde7"> </a>Note the semicolon after the definition of <code>add</code>. Normal function
+definitions do not need these, but this statement has the same general
+structure as <code>var add = 22;</code>, and thus requires the semicolon.</p><p><a class="paragraph" href="#p294c5a0ff8452901" name="p294c5a0ff8452901"> </a>This kind of function value is called an <a name="key17"></a>anonymous function, because
+it does not have a name. Sometimes it is useless to give a function a
+name, like in the <code>makeAddFunction</code> example we saw earlier:</p><pre class="code"><span class="keyword">function</span> <span class="variable">makeAddFunction</span>(<span class="variabledef">amount</span>) {
+ <span class="keyword">return</span> <span class="keyword">function</span> (<span class="variabledef">number</span>) {
+ <span class="keyword">return</span> <span class="localvariable">number</span> + <span class="localvariable">amount</span>;
+ };
+}</pre><p><a class="paragraph" href="#p3942ecf8918012ea" name="p3942ecf8918012ea"> </a>Since the function named <code>add</code> in the first version of
+<code>makeAddFunction</code> was referred to only once, the name does not serve
+any purpose and we might as well directly return the function value.</p></div><hr/><div class="block"><a name="exercise2"></a><div class="exercisenum">Ex. 3.2</div><div class="exercise"><p><a class="paragraph" href="#p39ef6ece83c48ffd" name="p39ef6ece83c48ffd"> </a>Write a function <code>greaterThan</code>, which takes one argument, a number,
+and returns a function that represents a test. When this returned
+function is called with a single number as argument, it returns a
+boolean: <code>true</code> if the given number is greater than the number that
+was used to create the test function, and <code>false</code> otherwise.</p></div><div class="solution"><pre class="code"><span class="keyword">function</span> <span class="variable">greaterThan</span>(<span class="variabledef">x</span>) {
+ <span class="keyword">return</span> <span class="keyword">function</span>(<span class="variabledef">y</span>) {
+ <span class="keyword">return</span> <span class="localvariable">y</span> > <span class="localvariable">x</span>;
+ };
+}
+
+<span class="keyword">var</span> <span class="variable">greaterThanTen</span> = <span class="variable">greaterThan</span>(<span class="atom">10</span>);
+<span class="variable">show</span>(<span class="variable">greaterThanTen</span>(<span class="atom">9</span>));</pre></div></div><hr/><div class="block"><p><a class="paragraph" href="#p229f158aa3834c6d" name="p229f158aa3834c6d"> </a>Try the following:</p><pre class="code"><span class="variable">alert</span>(<span class="string">"Hello"</span>, <span class="string">"Good Evening"</span>, <span class="string">"How do you do?"</span>, <span class="string">"Goodbye"</span>);</pre><p><a class="paragraph" href="#p77166a1bf06b3798" name="p77166a1bf06b3798"> </a>The function <code>alert</code> officially only accepts one argument. Yet when
+you call it like this, the computer does not complain at all, but just
+ignores the other arguments.</p><pre class="code"><span class="variable">show</span>();</pre><p><a class="paragraph" href="#p1985bd9435f81fe3" name="p1985bd9435f81fe3"> </a>You can, apparently, even get away with passing too few arguments.
+When an argument is not passed, its value inside the function is
+<code>undefined</code>.</p><p><a class="paragraph" href="#p3e4bab204c00a239" name="p3e4bab204c00a239"> </a>In the next chapter, we will see a way in which a function body can
+get at the exact list of arguments that were passed to it. This can be
+useful, as it makes it possible to have a function accept any number
+of arguments. <code>print</code> makes use of this:</p><pre class="code"><span class="variable">print</span>(<span class="string">"R"</span>, <span class="atom">2</span>, <span class="string">"D"</span>, <span class="atom">2</span>);</pre><p><a class="paragraph" href="#p2626cadb33f5c110" name="p2626cadb33f5c110"> </a>Of course, the downside of this is that it is also possible to
+accidentally pass the wrong number of arguments to functions that
+expect a fixed amount of them, like <code>alert</code>, and never be told about
+it.</p></div><ol class="footnotes"><li><a name="footnote1"></a>Technically, this wouldn't have been necessary, but I suppose the
+designers of JavaScript felt it would clarify things if function
+bodies always had braces.</li><li><a name="footnote2"></a>Technically, a pure function can not use the value of any external
+variables. These values might change, and this could make the function
+return a different value for the same arguments. In practice, the
+programmer may consider some variables 'constant' ― they are not
+expected to change ― and consider functions that use only constant
+variables pure. Variables that contain a function value are often good
+examples of constant variables.</li></ol><h1><span class="number">Chapter 4: </span>Data structures: Objects and Arrays</h1><div class="block"><p><a class="paragraph" href="#p3dad71ee8f395a59" name="p3dad71ee8f395a59"> </a>This chapter will be devoted to solving a few simple problems. In the
+process, we will discuss two new types of values, arrays and objects,
+and look at some techniques related to them.</p><p><a class="paragraph" href="#p564e8d1b4b91712a" name="p564e8d1b4b91712a"> </a>Consider the following situation: Your crazy aunt Emily, who is
+rumoured to have over fifty cats living with her (you never managed to
+count them), regularly sends you e-mails to keep you up to date on her
+exploits. They usually look like this:</p><blockquote>Dear nephew,<br/><br/>Your mother told me you have taken up skydiving. Is this true? You
+watch yourself, young man! Remember what happened to my husband? And
+that was only from the second floor!<br/><br/>Anyway, things are very exciting here. I have spent all week trying to
+get the attention of Mr. Drake, the nice gentleman who moved in next
+door, but I think he is afraid of cats. Or allergic to them? I am
+going to try putting Fat Igor on his shoulder next time I see him,
+very curious what will happen.<br/><br/>Also, the scam I told you about is going better than expected. I have
+already gotten back five 'payments', and only one complaint. It is
+starting to make me feel a bit bad though. And you are right that it
+is probably illegal in some way.<br/><br/>(... etc ...)<br/><br/>Much love,
+Aunt Emily<br/><br/>died 27/04/2006: Black Leclre<br/><br/>born 05/04/2006 (mother Lady Penelope): Red Lion, Doctor Hobbles the
+3rd, Little Iroquois</blockquote><p><a class="paragraph" href="#p301a6a2df4db3245" name="p301a6a2df4db3245"> </a>To humour the old dear, you would like to keep track of the genealogy
+of her cats, so you can add things like "P.S. I hope Doctor Hobbles
+the 2nd enjoyed his birthday this Saturday!", or "How is old Lady
+Penelope doing? She's five years old now, isn't she?", preferably
+without accidentally asking about dead cats. You are in the possession
+of a large quantity of old e-mails from your aunt, and fortunately she
+is very consistent in always putting information about the cats'
+births and deaths at the end of her mails in precisely the same
+format.</p><p><a class="paragraph" href="#p15cf28da1188e7aa" name="p15cf28da1188e7aa"> </a>You are hardly inclined to go through all those mails by hand.
+Fortunately, we were just in need of an example problem, so we will
+try to work out a program that does the work for us. For a start, we
+write a program that gives us a list of cats that are still alive
+after the last e-mail.</p><p><a class="paragraph" href="#p3ee0a4d551384142" name="p3ee0a4d551384142"> </a>Before you ask, at the start of the correspondence, aunt Emily had
+only a single cat: Spot. (She was still rather conventional in those
+days.)</p></div><hr/><div class="block"><div class="picture"><img src="img/eyes.png"/></div></div><hr/><div class="block"><p><a class="paragraph" href="#p1d776b34e90a830e" name="p1d776b34e90a830e"> </a>It usually pays to have some kind of clue what one's program is going
+to do before starting to type. Here's a plan:</p><ol><li>Start with a set of cat names that has only "Spot" in it.</li><li>Go over every e-mail in our archive, in chronological order.</li><li>Look for paragraphs that start with "born" or "died".</li><li>Add the names from paragraphs that start with "born" to our set of names.</li><li>Remove the names from paragraphs that start with "died" from our set.</li></ol><p><a class="paragraph" href="#p22f6a88dc6385bae" name="p22f6a88dc6385bae"> </a>Where taking the names from a paragraph goes like this:</p><ol><li>Find the colon in the paragraph.</li><li>Take the part after this colon.</li><li>Split this part into separate names by looking for commas.</li></ol><p><a class="paragraph" href="#p31ed7fa7e0fb7b15" name="p31ed7fa7e0fb7b15"> </a>It may require some suspension of disbelief to accept that aunt Emily
+always used this exact format, and that she never forgot or misspelled
+a name, but that is just how your aunt is.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p381d38ad2a5f03fb" name="p381d38ad2a5f03fb"> </a>First, let me tell you about <a name="key1"></a>properties. A lot of JavaScript values
+have other values associated with them. These associations are called
+properties. Every string has a property called <a name="key2"></a><code>length</code>, which refers
+to a number, the amount of characters in that string.</p><p><a class="paragraph" href="#p48e9e703da61d7cb" name="p48e9e703da61d7cb"> </a><a name="key3"></a>Properties can be accessed in two ways:</p><pre class="code"><span class="keyword">var</span> <span class="variable">text</span> = <span class="string">"purple haze"</span>;
+<span class="variable">show</span>(<span class="variable">text</span>[<span class="string">"length"</span>]);
+<span class="variable">show</span>(<span class="variable">text</span>.<span class="property">length</span>);</pre><p><a class="paragraph" href="#p2c4a983bace7fd1e" name="p2c4a983bace7fd1e"> </a>The second way is a shorthand for the first, and it only works when
+the name of the property would be a valid variable name ― when it
+doesn't have any spaces or symbols in it and does not start with a
+digit character.</p><p><a class="paragraph" href="#p618918d23b0e51d1" name="p618918d23b0e51d1"> </a>The values <code>null</code> and <code>undefined</code> do not have any properties. Trying
+to read properties from such a value produces an error. Try the
+following code, if only to get an idea about the kind of error-message
+your browser produces in such a case (which, for some browsers, can be
+rather cryptic).</p><pre class="code invalid"><span class="keyword">var</span> <span class="variable">nothing</span> = <span class="atom">null</span>;
+<span class="variable">show</span>(<span class="variable">nothing</span>.<span class="property">length</span>);</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p3a782c2198acba80" name="p3a782c2198acba80"> </a>The properties of a string value can not be changed. There are quite a
+few more than just <code>length</code>, as we will see, but you are not allowed
+to add or remove any.</p><p><a class="paragraph" href="#p16941343cc6e526c" name="p16941343cc6e526c"> </a>This is different with values of the type <a name="key4"></a>object. Their main role is
+to hold other values. They have, you could say, their own set of
+tentacles in the form of properties. You are free to modify these,
+remove them, or add new ones.</p><p><a class="paragraph" href="#p40b069744fe1b3f6" name="p40b069744fe1b3f6"> </a><a name="key5"></a>An object can be written like this:</p><pre class="code"><span class="keyword">var</span> <span class="variable">cat</span> = {<span class="property">colour</span>: <span class="string">"grey"</span>, <span class="property">name</span>: <span class="string">"Spot"</span>, <span class="property">size</span>: <span class="atom">46</span>};
+<span class="variable">cat</span>.<span class="property">size</span> = <span class="atom">47</span>;
+<span class="variable">show</span>(<span class="variable">cat</span>.<span class="property">size</span>);
+<span class="keyword">delete</span> <span class="variable">cat</span>.<span class="property">size</span>;
+<span class="variable">show</span>(<span class="variable">cat</span>.<span class="property">size</span>);
+<span class="variable">show</span>(<span class="variable">cat</span>);</pre><p><a class="paragraph" href="#p13bcd81d1795ba64" name="p13bcd81d1795ba64"> </a>Like variables, each property attached to an object is labelled by a
+string. The first statement creates an object in which the property
+<code>"colour"</code> holds the string <code>"grey"</code>, the property <code>"name"</code> is attached
+to the string <code>"Spot"</code>, and the property <code>"size"</code> refers to the number
+<code>46</code>. The second statement gives the property named <code>size</code> a new
+value, which is done in the same way as modifying a variable.</p><p><a class="paragraph" href="#p4a08c86f5895f714" name="p4a08c86f5895f714"> </a>The keyword <a name="key6"></a><code>delete</code> cuts off properties. Trying to read a
+non-existent property gives the value <code>undefined</code>.</p><p><a class="paragraph" href="#p20597691898398b" name="p20597691898398b"> </a>If a property that does not yet exist is set with the <a name="key7"></a><code>=</code> operator,
+it is added to the object.</p><pre class="code"><span class="keyword">var</span> <span class="variable">empty</span> = {};
+<span class="variable">empty</span>.<span class="property">notReally</span> = <span class="atom">1000</span>;
+<span class="variable">show</span>(<span class="variable">empty</span>.<span class="property">notReally</span>);</pre><p><a class="paragraph" href="#p205e668d2c45ec08" name="p205e668d2c45ec08"> </a>Properties whose names are not valid variable names have to be quoted
+when creating the object, and approached using brackets:</p><pre class="code"><span class="keyword">var</span> <span class="variable">thing</span> = {<span class="string">"gabba gabba"</span>: <span class="string">"hey"</span>, <span class="string">"5"</span>: <span class="atom">10</span>};
+<span class="variable">show</span>(<span class="variable">thing</span>[<span class="string">"5"</span>]);
+<span class="variable">thing</span>[<span class="string">"5"</span>] = <span class="atom">20</span>;
+<span class="variable">show</span>(<span class="variable">thing</span>[<span class="atom">2</span> + <span class="atom">3</span>]);
+<span class="keyword">delete</span> <span class="variable">thing</span>[<span class="string">"gabba gabba"</span>];</pre><p><a class="paragraph" href="#p7d28b3bf47e572d8" name="p7d28b3bf47e572d8"> </a>As you can see, the part between the brackets can be any expression.
+It is converted to a string to determine the property name it refers
+to. One can even use variables to name properties:</p><pre class="code"><span class="keyword">var</span> <span class="variable">propertyName</span> = <span class="string">"length"</span>;
+<span class="keyword">var</span> <span class="variable">text</span> = <span class="string">"mainline"</span>;
+<span class="variable">show</span>(<span class="variable">text</span>[<span class="variable">propertyName</span>]);</pre><p><a class="paragraph" href="#p48975384feabef2b" name="p48975384feabef2b"> </a>The operator <a name="key8"></a><code>in</code> can be used to test whether an object has a
+certain property. It produces a boolean.</p><pre class="code"><span class="keyword">var</span> <span class="variable">chineseBox</span> = {};
+<span class="variable">chineseBox</span>.<span class="property">content</span> = <span class="variable">chineseBox</span>;
+<span class="variable">show</span>(<span class="string">"content"</span> in <span class="variable">chineseBox</span>);
+<span class="variable">show</span>(<span class="string">"content"</span> in <span class="variable">chineseBox</span>.<span class="property">content</span>);</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p75f93b43a15f6b97" name="p75f93b43a15f6b97"> </a>When object values are shown on the console, they can be clicked to
+inspect their properties. This changes the output window to an
+'inspect' window. The little 'x' at the top-right can be used to
+return to the output window, and the left-arrow can be used to go back
+to the properties of the previously inspected object.</p><pre class="code"><span class="variable">show</span>(<span class="variable">chineseBox</span>);</pre></div><hr/><div class="block"><a name="exercise1"></a><div class="exercisenum">Ex. 4.1</div><div class="exercise"><p><a class="paragraph" href="#p27ecd9cf2dacfc4f" name="p27ecd9cf2dacfc4f"> </a>The solution for the cat problem talks about a 'set' of names. A <a name="key9"></a>set
+is a collection of values in which no value may occur more than once.
+If names are strings, can you think of a way to use an object to
+represent a set of names?</p><p><a class="paragraph" href="#p43887c2aefc059e4" name="p43887c2aefc059e4"> </a>Show how a name can be added to this set, how one can be removed, and
+how you can check whether a name occurs in it.</p></div><div class="solution"><p><a class="paragraph" href="#p24ea5ce9465c6b97" name="p24ea5ce9465c6b97"> </a>This can be done by storing the content of the set as the properties
+of an object. Adding a name is done by setting a property by that name
+to a value, any value. Removing a name is done by deleting this
+property. The <code>in</code> operator can be used to determine whether a certain
+name is part of the set<a class="footref" href="#footnote1">1</a>.</p><pre class="code"><span class="keyword">var</span> <span class="variable">set</span> = {<span class="string">"Spot"</span>: <span class="atom">true</span>};
+<span class="comment">// Add "White Fang" to the set</span>
+<span class="variable">set</span>[<span class="string">"White Fang"</span>] = <span class="atom">true</span>;
+<span class="comment">// Remove "Spot"</span>
+<span class="keyword">delete</span> <span class="variable">set</span>[<span class="string">"Spot"</span>];
+<span class="comment">// See if "Asoka" is in the set</span>
+<span class="variable">show</span>(<span class="string">"Asoka"</span> in <span class="variable">set</span>);</pre></div></div><hr/><div class="block"><p><a class="paragraph" href="#p374d5585e1413051" name="p374d5585e1413051"> </a><a name="key10"></a>Object values, apparently, can change. The types of
+values discussed in <a href="chapter2.html">chapter 2</a> are all immutable, it is impossible to
+change an existing value of those types. You can combine them and
+derive new values from them, but when you take a specific string
+value, the text inside it can not change. With objects, on the other
+hand, the content of a value can be modified by changing its
+properties.</p><p><a class="paragraph" href="#p304f40f25d1c0387" name="p304f40f25d1c0387"> </a>When we have two numbers, <code>120</code> and <code>120</code>, they can for all practical
+purposes be considered the precise same number. With objects, there is
+a difference between having two references to the same object and
+having two different objects that contain the same properties.
+Consider the following code:</p><pre class="code"><span class="keyword">var</span> <span class="variable">object1</span> = {<span class="property">value</span>: <span class="atom">10</span>};
+<span class="keyword">var</span> <span class="variable">object2</span> = <span class="variable">object1</span>;
+<span class="keyword">var</span> <span class="variable">object3</span> = {<span class="property">value</span>: <span class="atom">10</span>};
+
+<span class="variable">show</span>(<span class="variable">object1</span> == <span class="variable">object2</span>);
+<span class="variable">show</span>(<span class="variable">object1</span> == <span class="variable">object3</span>);
+
+<span class="variable">object1</span>.<span class="property">value</span> = <span class="atom">15</span>;
+<span class="variable">show</span>(<span class="variable">object2</span>.<span class="property">value</span>);
+<span class="variable">show</span>(<span class="variable">object3</span>.<span class="property">value</span>);</pre><p><a class="paragraph" href="#p33251549b1ce2fd4" name="p33251549b1ce2fd4"> </a><code>object1</code> and <code>object2</code> are two variables grasping the <em>same</em> value.
+There is only one actual object, which is why changing <code>object1</code> also
+changes the value of <code>object2</code>. The variable <code>object3</code> points to
+another object, which initially contains the same properties as
+<code>object1</code>, but lives a separate life.</p><p><a class="paragraph" href="#p586f09a0de2c9531" name="p586f09a0de2c9531"> </a>JavaScript's <a name="key11"></a><code>==</code> operator, when comparing objects, will only return
+<code>true</code> if both values given to it are the precise same value.
+Comparing different objects with identical contents will give <code>false</code>.
+This is useful in some situations, but impractical in others.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p545a9c43b75af0cd" name="p545a9c43b75af0cd"> </a>Object values can play a lot of different roles. Behaving like a set
+is only one of those. We will see a few other roles in this chapter,
+and <a href="chapter8.html">chapter 8</a> shows another important way of using objects.</p><p><a class="paragraph" href="#p706ccf569a6428ed" name="p706ccf569a6428ed"> ¶ </a>In the plan for the cat problem ― in fact, call it an <em>algorithm</em>,
+not a plan, that makes it sound like we know what we are talking about
+― in the algorithm, it talks about going over all the e-mails in an
+archive. What does this archive look like? And where does it come
+from?</p><p><a class="paragraph" href="#p2e21e98d83db57ad" name="p2e21e98d83db57ad"> </a>Do not worry about the second question for now. <a href="chapter14.html">Chapter 14</a> talks about
+some ways to import data into your programs, but for now you will find
+that the e-mails are just magically there. Some magic is really easy,
+inside computers.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p2a379b494a92b2d4" name="p2a379b494a92b2d4"> </a>The way in which the archive is stored is still an interesting
+question. It contains a number of e-mails. An e-mail can be a string,
+that should be obvious. The whole archive could be put into one huge
+string, but that is hardly practical. What we want is a collection of
+separate strings.</p><p><a class="paragraph" href="#p69666f13ed683e93" name="p69666f13ed683e93"> </a>Collections of things are what objects are used for. One could make an
+object like this:</p><pre class="code"><span class="keyword">var</span> <span class="variable">mailArchive</span> = {<span class="string">"the first e-mail"</span>: <span class="string">"Dear nephew, ..."</span>,
+ <span class="string">"the second e-mail"</span>: <span class="string">"..."</span>
+ <span class="comment">/* and so on ... */</span>};</pre><p><a class="paragraph" href="#p1aba2b421ecbd9f3" name="p1aba2b421ecbd9f3"> ¶ </a>But that makes it hard to go over the e-mails from start to end ― how
+does the program guess the name of these properties? This can be
+solved by more predictable property names:</p><pre class="code"><span class="keyword">var</span> <span class="variable">mailArchive</span> = {<span class="atom">0</span>: <span class="string">"Dear nephew, ... (mail number 1)"</span>,
+ <span class="atom">1</span>: <span class="string">"(mail number 2)"</span>,
+ <span class="atom">2</span>: <span class="string">"(mail number 3)"</span>};
+
+<span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">current</span> = <span class="atom">0</span>; <span class="variable">current</span> in <span class="variable">mailArchive</span>; <span class="variable">current</span>++)
+ <span class="variable">print</span>(<span class="string">"Processing e-mail #"</span>, <span class="variable">current</span>, <span class="string">": "</span>, <span class="variable">mailArchive</span>[<span class="variable">current</span>]);</pre><p><a class="paragraph" href="#p5d88f1adde4f9e20" name="p5d88f1adde4f9e20"> </a>Luck has it that there is a special kind of objects specifically for
+this kind of use. They are called <a name="key12"></a>arrays, and they provide some
+conveniences, such as a <a name="key13"></a><code>length</code> property that contains the amount
+of values in the array, and a number of operations useful for this
+kind of collection.</p><p><a class="paragraph" href="#p66a8f15bc365329f" name="p66a8f15bc365329f"> </a><a name="key14"></a>New arrays can be created using brackets (<code>[</code> and <code>]</code>):</p><pre class="code"><span class="keyword">var</span> <span class="variable">mailArchive</span> = [<span class="string">"mail one"</span>, <span class="string">"mail two"</span>, <span class="string">"mail three"</span>];
+
+<span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">current</span> = <span class="atom">0</span>; <span class="variable">current</span> < <span class="variable">mailArchive</span>.<span class="property">length</span>; <span class="variable">current</span>++)
+ <span class="variable">print</span>(<span class="string">"Processing e-mail #"</span>, <span class="variable">current</span>, <span class="string">": "</span>, <span class="variable">mailArchive</span>[<span class="variable">current</span>]);</pre><p><a class="paragraph" href="#p208a5481ace28737" name="p208a5481ace28737"> </a>In this example, the numbers of the elements are not specified
+explicitly anymore. The first one automatically gets the number 0, the
+second the number 1, and so on.</p><p><a class="paragraph" href="#p63946de7837cdea6" name="p63946de7837cdea6"> </a>Why start at 0? People tend to start counting from 1. As unintuitive
+as it seems, numbering the elements in a collection from 0 is often
+more practical. Just go with it for now, it will grow on you.</p><p><a class="paragraph" href="#p6b60b0919e690668" name="p6b60b0919e690668"> </a>Starting at element 0 also means that in a collection with <code>X</code>
+elements, the last element can be found at position <code>X - 1</code>. This is
+why the <code>for</code> loop in the example checks for <code>current <
+mailArchive.length</code>. There is no element at position
+<code>mailArchive.length</code>, so as soon as <code>current</code> has that value, we stop
+looping.</p></div><hr/><div class="block"><a name="exercise2"></a><div class="exercisenum">Ex. 4.2</div><div class="exercise"><p><a class="paragraph" href="#p5bb2a834279b6896" name="p5bb2a834279b6896"> </a>Write a function <code>range</code> that takes one argument, a positive number,
+and returns an array containing all numbers from 0 up to and including
+the given number.</p><p><a class="paragraph" href="#p2d6da830cab7863d" name="p2d6da830cab7863d"> </a>An empty array can be created by simply typing <code>[]</code>. Also remember
+that adding properties to an object, and thus also to an array, can be
+done by assigning them a value with the <code>=</code> operator. The <code>length</code>
+property is automatically updated when elements are added.</p></div><div class="solution"><pre class="code"><span class="keyword">function</span> <span class="variable">range</span>(<span class="variabledef">upto</span>) {
+ <span class="keyword">var</span> <span class="variabledef">result</span> = [];
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variabledef">i</span> = <span class="atom">0</span>; <span class="localvariable">i</span> <= <span class="localvariable">upto</span>; <span class="localvariable">i</span>++)
+ <span class="localvariable">result</span>[<span class="localvariable">i</span>] = <span class="localvariable">i</span>;
+ <span class="keyword">return</span> <span class="localvariable">result</span>;
+}
+<span class="variable">show</span>(<span class="variable">range</span>(<span class="atom">4</span>));</pre><p><a class="paragraph" href="#p691dda347a9c0f9b" name="p691dda347a9c0f9b"> </a>Instead of naming the loop variable <code>counter</code> or <code>current</code>, as I have
+been doing so far, it is now called simply <code>i</code>. Using single letters,
+usually <code>i</code>, <code>j</code>, or <code>k</code> for loop variables is a widely spread habit
+among programmers. It has its origin mostly in laziness: We'd rather
+type one character than seven, and names like <code>counter</code> and <code>current</code>
+do not really clarify the meaning of the variable much.</p><p><a class="paragraph" href="#p41226ce7fea00811" name="p41226ce7fea00811"> </a>If a program uses too many meaningless single-letter variables, it can
+become unbelievably confusing. In my own programs, I try to only do
+this in a few common cases. Small loops are one of these cases. If the
+loop contains another loop, and that one also uses a variable named
+<code>i</code>, the inner loop will modify the variable that the outer loop is
+using, and everything will break. One could use <code>j</code> for the inner
+loop, but in general, when the body of a loop is big, you should come
+up with a variable name that has some clear meaning.</p></div></div><hr/><div class="block"><p><a class="paragraph" href="#p63f311670d53896a" name="p63f311670d53896a"> </a>Both string and array objects contain, in addition to the <code>length</code>
+property, a number of properties that refer to function values.</p><pre class="code"><span class="keyword">var</span> <span class="variable">doh</span> = <span class="string">"Doh"</span>;
+<span class="variable">print</span>(typeof <span class="variable">doh</span>.<span class="property">toUpperCase</span>);
+<span class="variable">print</span>(<span class="variable">doh</span>.<span class="property">toUpperCase</span>());</pre><p><a class="paragraph" href="#p172dc5b33324ebd" name="p172dc5b33324ebd"> </a>Every string has a <a name="key15"></a><code>toUpperCase</code> property. When called, it will
+return a copy of the string, in which all letters have been converted
+to uppercase. There is also <a name="key16"></a><code>toLowerCase</code>. Guess what that does.</p><p><a class="paragraph" href="#p70ebdb3340519977" name="p70ebdb3340519977"> </a>Notice that, even though the call to <code>toUpperCase</code> does not pass any
+arguments, the function does somehow have access to the string
+<code>"Doh"</code>, the value of which it is a property. How this works precisely
+is described in <a href="chapter8.html">chapter 8</a>.</p><p><a class="paragraph" href="#p43a78e4cbfe94f0f" name="p43a78e4cbfe94f0f"> </a>Properties that contain functions are generally called <a name="key17"></a>methods, as
+in '<code>toUpperCase</code> is a method of a string object'.</p><pre class="code"><span class="keyword">var</span> <span class="variable">mack</span> = [];
+<span class="variable">mack</span>.<span class="property">push</span>(<span class="string">"Mack"</span>);
+<span class="variable">mack</span>.<span class="property">push</span>(<span class="string">"the"</span>);
+<span class="variable">mack</span>.<span class="property">push</span>(<span class="string">"Knife"</span>);
+<span class="variable">show</span>(<span class="variable">mack</span>.<span class="property">join</span>(<span class="string">" "</span>));
+<span class="variable">show</span>(<span class="variable">mack</span>.<span class="property">pop</span>());
+<span class="variable">show</span>(<span class="variable">mack</span>);</pre><p><a class="paragraph" href="#p78f9e8a5e60b4ac4" name="p78f9e8a5e60b4ac4"> </a>The method <a name="key18"></a><code>push</code>, which is associated with arrays, can be used to
+add values to it. It could have been used in the last exercise, as an
+alternative to <code>result[i] = i</code>. Then there is <a name="key19"></a><code>pop</code>, the opposite of
+<code>push</code>: it takes off and returns the last value in the array. <a name="key20"></a><code>join</code>
+builds a single big string from an array of strings. The parameter it
+is given is pasted between the values in the array.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p3e9601168069b19b" name="p3e9601168069b19b"> </a>Coming back to those cats, we now know that an array would be a good
+way to store the archive of e-mails. On this page, the function
+<code>retrieveMails</code> can be used to (magically) get hold of this array.
+Going over them to process them one after another is not rocket science
+anymore either:</p><pre class="code"><span class="keyword">var</span> <span class="variable">mailArchive</span> = <span class="variable">retrieveMails</span>();
+
+<span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">i</span> = <span class="atom">0</span>; <span class="variable">i</span> < <span class="variable">mailArchive</span>.<span class="property">length</span>; <span class="variable">i</span>++) {
+ <span class="keyword">var</span> <span class="variable">email</span> = <span class="variable">mailArchive</span>[<span class="variable">i</span>];
+ <span class="variable">print</span>(<span class="string">"Processing e-mail #"</span>, <span class="variable">i</span>);
+ <span class="comment">// Do more things...</span>
+}</pre><p><a class="paragraph" href="#p217d5ce915c57420" name="p217d5ce915c57420"> </a>We have also decided on a way to represent the set of cats that are
+alive. The next problem, then, is to find the paragraphs in an e-mail
+that start with <code>"born"</code> or <code>"died"</code>.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p71e3cb0ed700e41a" name="p71e3cb0ed700e41a"> </a>The first question that comes up is what exactly a paragraph is. In
+this case, the string value itself can't help us much: JavaScript's
+concept of text does not go any deeper than the 'sequence of
+characters' idea, so we must define paragraphs in those terms.</p><p><a class="paragraph" href="#p67017c07e4cdab3b" name="p67017c07e4cdab3b"> </a>Earlier, we saw that there is such a thing as a newline character.
+These are what most people use to split paragraphs. We consider a
+paragraph, then, to be a part of an e-mail that starts at a newline
+character or at the start of the content, and ends at the next newline
+character or at the end of the content.</p><p><a class="paragraph" href="#p6f0a818766388399" name="p6f0a818766388399"> </a>And we don't even have to write the algorithm for splitting a string
+into paragraphs ourselves. Strings already have a method named
+<a name="key21"></a><code>split</code>, which is (almost) the opposite of the <code>join</code> method of
+arrays. It splits a string into an array, using the string given as
+its argument to determine in which places to cut.</p><pre class="code"><span class="keyword">var</span> <span class="variable">words</span> = <span class="string">"Cities of the Interior"</span>;
+<span class="variable">show</span>(<span class="variable">words</span>.<span class="property">split</span>(<span class="string">" "</span>));</pre><p><a class="paragraph" href="#p75504e71133f9c11" name="p75504e71133f9c11"> </a>Thus, cutting on newlines (<code>"\n"</code>), can be used to split an e-mail
+into paragraphs.</p></div><hr/><div class="block"><a name="exercise3"></a><div class="exercisenum">Ex. 4.3</div><div class="exercise"><p><a class="paragraph" href="#p4049fe84b8fbac8c" name="p4049fe84b8fbac8c"> </a><code>split</code> and <code>join</code> are not precisely each other's inverse.
+<code>string.split(x).join(x)</code> always produces the original value, but
+<code>array.join(x).split(x)</code> does not. Can you give an example of an array
+where <code>.join(" ").split(" ")</code> produces a different value?</p></div><div class="solution"><pre class="code"><span class="keyword">var</span> <span class="variable">array</span> = [<span class="string">"a"</span>, <span class="string">"b"</span>, <span class="string">"c d"</span>];
+<span class="variable">show</span>(<span class="variable">array</span>.<span class="property">join</span>(<span class="string">" "</span>).<span class="property">split</span>(<span class="string">" "</span>));</pre></div></div><hr/><div class="block"><p><a class="paragraph" href="#p59d1a3239c60a7e6" name="p59d1a3239c60a7e6"> </a>Paragraphs that do not start with either "born" or "died" can be
+ignored by the program. How do we test whether a string starts with a
+certain word? The method <a name="key22"></a><code>charAt</code> can be used to get a specific
+character from a string. <code>x.charAt(0)</code> gives the first character, <code>1</code>
+is the second one, and so on. One way to check whether a string starts
+with "born" is:</p><pre class="code"><span class="keyword">var</span> <span class="variable">paragraph</span> = <span class="string">"born 15-11-2003 (mother Spot): White Fang"</span>;
+<span class="variable">show</span>(<span class="variable">paragraph</span>.<span class="property">charAt</span>(<span class="atom">0</span>) == <span class="string">"b"</span> && <span class="variable">paragraph</span>.<span class="property">charAt</span>(<span class="atom">1</span>) == <span class="string">"o"</span> &&
+ <span class="variable">paragraph</span>.<span class="property">charAt</span>(<span class="atom">2</span>) == <span class="string">"r"</span> && <span class="variable">paragraph</span>.<span class="property">charAt</span>(<span class="atom">3</span>) == <span class="string">"n"</span>);</pre><p><a class="paragraph" href="#p222f704190a769ff" name="p222f704190a769ff"> ¶ </a>But that gets a bit clumsy ― imagine checking for a word of ten
+characters. There is something to be learned here though: when a line
+gets ridiculously long, it can be spread over multiple lines. The
+result can be made easier to read by lining up the start of the new
+line with the first element on the original line that plays a similar
+role.</p><p><a class="paragraph" href="#p463b2febd9dcb0ff" name="p463b2febd9dcb0ff"> </a>Strings also have a method called <a name="key23"></a><code>slice</code>. It copies out a piece of
+the string, starting from the character at the position given by the
+first argument, and ending before (not including) the character at the
+position given by the second one. This allows the check to be written
+in a shorter way.</p><pre class="code"><span class="variable">show</span>(<span class="variable">paragraph</span>.<span class="property">slice</span>(<span class="atom">0</span>, <span class="atom">4</span>) == <span class="string">"born"</span>);</pre></div><hr/><div class="block"><a name="exercise4"></a><div class="exercisenum">Ex. 4.4</div><div class="exercise"><p><a class="paragraph" href="#p44eb0c2117451fa5" name="p44eb0c2117451fa5"> </a>Write a function called <code>startsWith</code> that takes two arguments, both
+strings. It returns <code>true</code> when the first argument starts with the
+characters in the second argument, and <code>false</code> otherwise.</p></div><div class="solution"><pre class="code"><span class="keyword">function</span> <span class="variable">startsWith</span>(<span class="variabledef">string</span>, <span class="variabledef">pattern</span>) {
+ <span class="keyword">return</span> <span class="localvariable">string</span>.<span class="property">slice</span>(<span class="atom">0</span>, <span class="localvariable">pattern</span>.<span class="property">length</span>) == <span class="localvariable">pattern</span>;
+}
+
+<span class="variable">show</span>(<span class="variable">startsWith</span>(<span class="string">"rotation"</span>, <span class="string">"rot"</span>));</pre></div></div><hr/><div class="block"><p><a class="paragraph" href="#p7a960e3d6b231017" name="p7a960e3d6b231017"> </a>What happens when <code>charAt</code> or <code>slice</code> are used to take a piece of a
+string that does not exist? Will the <code>startsWith</code> I showed still work
+when the pattern is longer than the string it is matched against?</p><pre class="code"><span class="variable">show</span>(<span class="string">"Pip"</span>.<span class="property">charAt</span>(<span class="atom">250</span>));
+<span class="variable">show</span>(<span class="string">"Nop"</span>.<span class="property">slice</span>(<span class="atom">1</span>, <span class="atom">10</span>));</pre><p><a class="paragraph" href="#p4efb4e9aa94c9fb3" name="p4efb4e9aa94c9fb3"> </a><code>charAt</code> will return <code>""</code> when there is no character at the given
+position, and <code>slice</code> will simply leave out the part of the new
+string that does not exist.</p><p><a class="paragraph" href="#p6b24782e0b53201d" name="p6b24782e0b53201d"> </a>So yes, that version of <code>startsWith</code> works. When <code>startsWith("Idiots",
+"Most honoured colleagues")</code> is called, the call to <code>slice</code> will,
+because <code>string</code> does not have enough characters, always return a
+string that is shorter than <code>pattern</code>. Because of that, the comparison
+with <code>==</code> will return <code>false</code>, which is correct.</p><p><a class="paragraph" href="#p6ca9d35fb6e0cf1c" name="p6ca9d35fb6e0cf1c"> </a>It helps to always take a moment to consider abnormal (but valid)
+inputs for a program. These are usually called <a name="key24"></a>corner cases, and it
+is very common for programs that work perfectly on all the 'normal'
+inputs to screw up on corner cases.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p6f5e0704b3198e32" name="p6f5e0704b3198e32"> </a>The only part of the cat-problem that is still unsolved is the
+extraction of names from a paragraph. The algorithm was this:</p><ol><li>Find the colon in the paragraph.</li><li>Take the part after this colon.</li><li>Split this part into separate names by looking for commas.</li></ol><p><a class="paragraph" href="#p13747a447dcf78d9" name="p13747a447dcf78d9"> </a>This has to happen both for paragraphs that start with <code>"died"</code>, and
+paragraphs that start with <code>"born"</code>. It would be a good idea to put it
+into a function, so that the two pieces of code that handle these
+different kinds of paragraphs can both use it.</p></div><hr/><div class="block"><a name="exercise5"></a><div class="exercisenum">Ex. 4.5</div><div class="exercise"><p><a class="paragraph" href="#p582574767c781ba1" name="p582574767c781ba1"> </a>Can you write a function <code>catNames</code> that takes a paragraph as an
+argument and returns an array of names?</p><p><a class="paragraph" href="#p3d70e965f76e0906" name="p3d70e965f76e0906"> </a>Strings have an <a name="key25"></a><code>indexOf</code> method that can be used to find the
+(first) position of a character or sub-string within that string. Also,
+when <code>slice</code> is given only one argument, it will return the part of
+the string from the given position all the way to the end.</p><p><a class="paragraph" href="#pb782cd8caeb5db8" name="pb782cd8caeb5db8"> </a>It can be helpful to use the console to 'explore' functions. For
+example, type <code>"foo: bar".indexOf(":")</code> and see what you get.</p></div><div class="solution"><pre class="code"><span class="keyword">function</span> <span class="variable">catNames</span>(<span class="variabledef">paragraph</span>) {
+ <span class="keyword">var</span> <span class="variabledef">colon</span> = <span class="localvariable">paragraph</span>.<span class="property">indexOf</span>(<span class="string">":"</span>);
+ <span class="keyword">return</span> <span class="localvariable">paragraph</span>.<span class="property">slice</span>(<span class="localvariable">colon</span> + <span class="atom">2</span>).<span class="property">split</span>(<span class="string">", "</span>);
+}
+
+<span class="variable">show</span>(<span class="variable">catNames</span>(<span class="string">"born 20/09/2004 (mother Yellow Bess): "</span> +
+ <span class="string">"Doctor Hobbles the 2nd, Noog"</span>));</pre><p><a class="paragraph" href="#p200fca11a3ac1241" name="p200fca11a3ac1241"> </a>The tricky part, which the original description of the algorithm
+ignored, is dealing with spaces after the colon and the commas.
+The <code>+ 2</code> used when slicing the string is needed to leave out the
+colon itself and the space after it. The argument to <code>split</code> contains
+both a comma and a space, because that is what the names are really
+separated by, rather than just a comma.</p><p><a class="paragraph" href="#p4c75b2280949cdf6" name="p4c75b2280949cdf6"> </a>This function does not do any checking for problems. We assume, in
+this case, that the input is always correct.</p></div></div><hr/><div class="block"><p><a class="paragraph" href="#p6d6a82a0b28a0847" name="p6d6a82a0b28a0847"> </a>All that remains now is putting the pieces together. One way to do
+that looks like this:</p><pre class="code"><span class="keyword">var</span> <span class="variable">mailArchive</span> = <span class="variable">retrieveMails</span>();
+<span class="keyword">var</span> <span class="variable">livingCats</span> = {<span class="string">"Spot"</span>: <span class="atom">true</span>};
+
+<span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">mail</span> = <span class="atom">0</span>; <span class="variable">mail</span> < <span class="variable">mailArchive</span>.<span class="property">length</span>; <span class="variable">mail</span>++) {
+ <span class="keyword">var</span> <span class="variable">paragraphs</span> = <span class="variable">mailArchive</span>[<span class="variable">mail</span>].<span class="property">split</span>(<span class="string">"\n"</span>);
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">paragraph</span> = <span class="atom">0</span>;
+ <span class="variable">paragraph</span> < <span class="variable">paragraphs</span>.<span class="property">length</span>;
+ <span class="variable">paragraph</span>++) {
+ <span class="keyword">if</span> (<span class="variable">startsWith</span>(<span class="variable">paragraphs</span>[<span class="variable">paragraph</span>], <span class="string">"born"</span>)) {
+ <span class="keyword">var</span> <span class="variable">names</span> = <span class="variable">catNames</span>(<span class="variable">paragraphs</span>[<span class="variable">paragraph</span>]);
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">name</span> = <span class="atom">0</span>; <span class="variable">name</span> < <span class="variable">names</span>.<span class="property">length</span>; <span class="variable">name</span>++)
+ <span class="variable">livingCats</span>[<span class="variable">names</span>[<span class="variable">name</span>]] = <span class="atom">true</span>;
+ }
+ <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">startsWith</span>(<span class="variable">paragraphs</span>[<span class="variable">paragraph</span>], <span class="string">"died"</span>)) {
+ <span class="keyword">var</span> <span class="variable">names</span> = <span class="variable">catNames</span>(<span class="variable">paragraphs</span>[<span class="variable">paragraph</span>]);
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">name</span> = <span class="atom">0</span>; <span class="variable">name</span> < <span class="variable">names</span>.<span class="property">length</span>; <span class="variable">name</span>++)
+ <span class="keyword">delete</span> <span class="variable">livingCats</span>[<span class="variable">names</span>[<span class="variable">name</span>]];
+ }
+ }
+}
+
+<span class="variable">show</span>(<span class="variable">livingCats</span>);</pre><p><a class="paragraph" href="#p4d35b993acbc1dd8" name="p4d35b993acbc1dd8"> </a>That is quite a big dense chunk of code. We'll look into making it a
+bit lighter in a moment. But first let us look at our results. We know
+how to check whether a specific cat survives:</p><pre class="code"><span class="keyword">if</span> (<span class="string">"Spot"</span> in <span class="variable">livingCats</span>)
+ <span class="variable">print</span>(<span class="string">"Spot lives!"</span>);
+<span class="keyword">else</span>
+ <span class="variable">print</span>(<span class="string">"Good old Spot, may she rest in peace."</span>);</pre><p><a class="paragraph" href="#p4453cb8513584d0d" name="p4453cb8513584d0d"> </a>But how do we list all the cats that are alive? The <a name="key26"></a><code>in</code> keyword has
+a somewhat different meaning when it is used together with <code>for</code>:</p><pre class="code"><span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">cat</span> <span class="keyword">in</span> <span class="variable">livingCats</span>)
+ <span class="variable">print</span>(<span class="variable">cat</span>);</pre><p><a class="paragraph" href="#p2c5cb96013184931" name="p2c5cb96013184931"> </a>A loop like that will go over the names of the properties in an
+object, which allows us to enumerate all the names in our set.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p3a76bee6b1c1b27c" name="p3a76bee6b1c1b27c"> </a>Some pieces of code look like an impenetrable jungle. The example
+solution to the cat problem suffers from this. One way to make some
+light shine through it is to just add some strategic blank lines. This
+makes it look better, but doesn't really solve the problem.</p><p><a class="paragraph" href="#p79acc3d63f2626f6" name="p79acc3d63f2626f6"> </a>What is needed here is to break the code up. We already wrote two
+helper functions, <code>startsWith</code> and <code>catNames</code>, which both take care of
+a small, understandable part of the problem. Let us continue doing
+this.</p><pre class="code"><span class="keyword">function</span> <span class="variable">addToSet</span>(<span class="variabledef">set</span>, <span class="variabledef">values</span>) {
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variabledef">i</span> = <span class="atom">0</span>; <span class="localvariable">i</span> < <span class="localvariable">values</span>.<span class="property">length</span>; <span class="localvariable">i</span>++)
+ <span class="localvariable">set</span>[<span class="localvariable">values</span>[<span class="localvariable">i</span>]] = <span class="atom">true</span>;
+}
+
+<span class="keyword">function</span> <span class="variable">removeFromSet</span>(<span class="variabledef">set</span>, <span class="variabledef">values</span>) {
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variabledef">i</span> = <span class="atom">0</span>; <span class="localvariable">i</span> < <span class="localvariable">values</span>.<span class="property">length</span>; <span class="localvariable">i</span>++)
+ <span class="keyword">delete</span> <span class="localvariable">set</span>[<span class="localvariable">values</span>[<span class="localvariable">i</span>]];
+}</pre><p><a class="paragraph" href="#p4954367c9f5eda1a" name="p4954367c9f5eda1a"> </a>These two functions take care of the adding and removing of names from
+the set. That already cuts out the two most inner loops from the
+solution:</p><pre class="code"><span class="keyword">var</span> <span class="variable">livingCats</span> = {<span class="property">Spot</span>: <span class="atom">true</span>};
+
+<span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">mail</span> = <span class="atom">0</span>; <span class="variable">mail</span> < <span class="variable">mailArchive</span>.<span class="property">length</span>; <span class="variable">mail</span>++) {
+ <span class="keyword">var</span> <span class="variable">paragraphs</span> = <span class="variable">mailArchive</span>[<span class="variable">mail</span>].<span class="property">split</span>(<span class="string">"\n"</span>);
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">paragraph</span> = <span class="atom">0</span>;
+ <span class="variable">paragraph</span> < <span class="variable">paragraphs</span>.<span class="property">length</span>;
+ <span class="variable">paragraph</span>++) {
+ <span class="keyword">if</span> (<span class="variable">startsWith</span>(<span class="variable">paragraphs</span>[<span class="variable">paragraph</span>], <span class="string">"born"</span>))
+ <span class="variable">addToSet</span>(<span class="variable">livingCats</span>, <span class="variable">catNames</span>(<span class="variable">paragraphs</span>[<span class="variable">paragraph</span>]));
+ <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">startsWith</span>(<span class="variable">paragraphs</span>[<span class="variable">paragraph</span>], <span class="string">"died"</span>))
+ <span class="variable">removeFromSet</span>(<span class="variable">livingCats</span>, <span class="variable">catNames</span>(<span class="variable">paragraphs</span>[<span class="variable">paragraph</span>]));
+ }
+}</pre><p><a class="paragraph" href="#p707956d48832422b" name="p707956d48832422b"> </a>Quite an improvement, if I may say so myself.</p><p><a class="paragraph" href="#p79b79974ad51c8ae" name="p79b79974ad51c8ae"> </a>Why do <code>addToSet</code> and <code>removeFromSet</code> take the set as an argument?
+They could use the variable <code>livingCats</code> directly, if they wanted to.
+The reason is that this way they are not completely tied to our
+current problem. If <code>addToSet</code> directly changed <code>livingCats</code>, it would
+have to be called <code>addCatsToCatSet</code>, or something similar. The way it
+is now, it is a more generally useful tool.</p><p><a class="paragraph" href="#pcf887f065caa752" name="pcf887f065caa752"> </a>Even if we are never going to use these functions for anything else,
+which is quite probable, it is useful to write them like this. Because
+they are 'self sufficient', they can be read and understood on their
+own, without needing to know about some external variable called
+<code>livingCats</code>.</p><p><a class="paragraph" href="#p7f96a36fb45208f7" name="p7f96a36fb45208f7"> </a>The functions are not pure: They change the object passed as their
+<code>set</code> argument. This makes them slightly trickier than real pure
+functions, but still a lot less confusing than functions that run amok
+and change any value or variable they please.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p4215ba8a538a2c0b" name="p4215ba8a538a2c0b"> </a>We continue breaking the algorithm into pieces:</p><pre class="code"><span class="keyword">function</span> <span class="variable">findLivingCats</span>() {
+ <span class="keyword">var</span> <span class="variabledef">mailArchive</span> = <span class="variable">retrieveMails</span>();
+ <span class="keyword">var</span> <span class="variabledef">livingCats</span> = {<span class="string">"Spot"</span>: <span class="atom">true</span>};
+
+ <span class="keyword">function</span> <span class="variabledef">handleParagraph</span>(<span class="variabledef">paragraph</span>) {
+ <span class="keyword">if</span> (<span class="variable">startsWith</span>(<span class="localvariable">paragraph</span>, <span class="string">"born"</span>))
+ <span class="variable">addToSet</span>(<span class="localvariable">livingCats</span>, <span class="variable">catNames</span>(<span class="localvariable">paragraph</span>));
+ <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">startsWith</span>(<span class="localvariable">paragraph</span>, <span class="string">"died"</span>))
+ <span class="variable">removeFromSet</span>(<span class="localvariable">livingCats</span>, <span class="variable">catNames</span>(<span class="localvariable">paragraph</span>));
+ }
+
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variabledef">mail</span> = <span class="atom">0</span>; <span class="localvariable">mail</span> < <span class="localvariable">mailArchive</span>.<span class="property">length</span>; <span class="localvariable">mail</span>++) {
+ <span class="keyword">var</span> <span class="variabledef">paragraphs</span> = <span class="localvariable">mailArchive</span>[<span class="localvariable">mail</span>].<span class="property">split</span>(<span class="string">"\n"</span>);
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variabledef">i</span> = <span class="atom">0</span>; <span class="localvariable">i</span> < <span class="localvariable">paragraphs</span>.<span class="property">length</span>; <span class="localvariable">i</span>++)
+ <span class="localvariable">handleParagraph</span>(<span class="localvariable">paragraphs</span>[<span class="localvariable">i</span>]);
+ }
+ <span class="keyword">return</span> <span class="localvariable">livingCats</span>;
+}
+
+<span class="keyword">var</span> <span class="variable">howMany</span> = <span class="atom">0</span>;
+<span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">cat</span> <span class="keyword">in</span> <span class="variable">findLivingCats</span>())
+ <span class="variable">howMany</span>++;
+<span class="variable">print</span>(<span class="string">"There are "</span>, <span class="variable">howMany</span>, <span class="string">" cats."</span>);</pre><p><a class="paragraph" href="#p3dae279b6f62cc0f" name="p3dae279b6f62cc0f"> </a>The whole algorithm is now encapsulated by a function. This means that
+it does not leave a mess after it runs: <code>livingCats</code> is now a local
+variable in the function, instead of a top-level one, so it only
+exists while the function runs. The code that needs this set can call
+<code>findLivingCats</code> and use the value it returns.</p><p><a class="paragraph" href="#p68353a56b1f8d562" name="p68353a56b1f8d562"> </a>It seemed to me that making <code>handleParagraph</code> a separate function also
+cleared things up. But this one is so closely tied to the
+cat-algorithm that it is meaningless in any other situation. On top of
+that, it needs access to the <code>livingCats</code> variable. Thus, it is a
+perfect candidate to be a function-inside-a-function. When it lives
+inside <code>findLivingCats</code>, it is clear that it is only relevant there,
+and it has access to the variables of its parent function.</p><p><a class="paragraph" href="#p6c1eba78ad0b2665" name="p6c1eba78ad0b2665"> </a>This solution is actually <em>bigger</em> than the previous one. Still, it is
+tidier and I hope you'll agree that it is easier to read.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p28893aeb55b4a635" name="p28893aeb55b4a635"> </a>The program still ignores a lot of the information that is contained
+in the e-mails. There are birth-dates, dates of death, and the names
+of mothers in there.</p><p><a class="paragraph" href="#p72f03ac49aec1af" name="p72f03ac49aec1af"> </a>To start with the dates: What would be a good way to store a date? We
+could make an object with three properties, <code>year</code>, <code>month</code>, and
+<code>day</code>, and store numbers in them.</p><pre class="code"><span class="keyword">var</span> <span class="variable">when</span> = {<span class="property">year</span>: <span class="atom">1980</span>, <span class="property">month</span>: <span class="atom">2</span>, <span class="property">day</span>: <span class="atom">1</span>};</pre><p><a class="paragraph" href="#p589c2140a9195d5d" name="p589c2140a9195d5d"> </a>But JavaScript already provides a kind of object for this purpose.
+Such an object can be created by using the keyword <a name="key27"></a><code>new</code>:</p><pre class="code"><span class="keyword">var</span> <span class="variable">when</span> = <span class="keyword">new</span> <span class="variable">Date</span>(<span class="atom">1980</span>, <span class="atom">1</span>, <span class="atom">1</span>);
+<span class="variable">show</span>(<span class="variable">when</span>);</pre><p><a class="paragraph" href="#p63649032fd757eea" name="p63649032fd757eea"> </a>Just like the notation with braces and colons we have already
+seen, <code>new</code> is a way to create object values. Instead of specifying
+all the property names and values, a function is used to build up the
+object. This makes it possible to define a kind of standard procedure
+for creating objects. Functions like this are called <a name="key28"></a>constructors,
+and in <a href="chapter8.html">chapter 8</a> we will see how to write them.</p><p><a class="paragraph" href="#pd46a19fe682dcf9" name="pd46a19fe682dcf9"> </a>The <a name="key29"></a><code>Date</code> constructor can be used in different ways.</p><pre class="code"><span class="variable">show</span>(<span class="keyword">new</span> <span class="variable">Date</span>());
+<span class="variable">show</span>(<span class="keyword">new</span> <span class="variable">Date</span>(<span class="atom">1980</span>, <span class="atom">1</span>, <span class="atom">1</span>));
+<span class="variable">show</span>(<span class="keyword">new</span> <span class="variable">Date</span>(<span class="atom">2007</span>, <span class="atom">2</span>, <span class="atom">30</span>, <span class="atom">8</span>, <span class="atom">20</span>, <span class="atom">30</span>));</pre><p><a class="paragraph" href="#p4ecedb91cc67fbd2" name="p4ecedb91cc67fbd2"> </a>As you can see, these objects can store a time of day as well as a
+date. When not given any arguments, an object representing the current
+time and date is created. Arguments can be given to ask for a specific
+date and time. The order of the arguments is year, month, day, hour,
+minute, second, milliseconds. These last four are optional, they
+become 0 when not given.</p><p><a class="paragraph" href="#p7616478b4c1deb97" name="p7616478b4c1deb97"> </a>The month numbers these objects use go from 0 to 11, which can be
+confusing. Especially since day numbers <em>do</em> start from 1.</p></div><hr/><div class="block"><p><a class="paragraph" href="#pd9326f8cf70c31c" name="pd9326f8cf70c31c"> </a>The content of a <code>Date</code> object can be inspected with a number of
+<code>get...</code> methods.</p><pre class="code"><span class="keyword">var</span> <span class="variable">today</span> = <span class="keyword">new</span> <span class="variable">Date</span>();
+<span class="variable">print</span>(<span class="string">"Year: "</span>, <span class="variable">today</span>.<span class="property">getFullYear</span>(), <span class="string">", month: "</span>,
+ <span class="variable">today</span>.<span class="property">getMonth</span>(), <span class="string">", day: "</span>, <span class="variable">today</span>.<span class="property">getDate</span>());
+<span class="variable">print</span>(<span class="string">"Hour: "</span>, <span class="variable">today</span>.<span class="property">getHours</span>(), <span class="string">", minutes: "</span>,
+ <span class="variable">today</span>.<span class="property">getMinutes</span>(), <span class="string">", seconds: "</span>, <span class="variable">today</span>.<span class="property">getSeconds</span>());
+<span class="variable">print</span>(<span class="string">"Day of week: "</span>, <span class="variable">today</span>.<span class="property">getDay</span>());</pre><p><a class="paragraph" href="#p6247902a24924a7" name="p6247902a24924a7"> </a>All of these, except for <code>getDay</code>, also have a <code>set...</code> variant that
+can be used to change the value of the date object.</p><p><a class="paragraph" href="#p592bddf4ad4a7dd5" name="p592bddf4ad4a7dd5"> </a>Inside the object, a date is represented by the amount of milliseconds
+it is away from January 1st 1970. You can imagine this is quite a
+large number.</p><pre class="code"><span class="keyword">var</span> <span class="variable">today</span> = <span class="keyword">new</span> <span class="variable">Date</span>();
+<span class="variable">show</span>(<span class="variable">today</span>.<span class="property">getTime</span>());</pre><p><a class="paragraph" href="#p2bbd7e384781286e" name="p2bbd7e384781286e"> </a>A very useful thing to do with dates is comparing them.</p><pre class="code"><span class="keyword">var</span> <span class="variable">wallFall</span> = <span class="keyword">new</span> <span class="variable">Date</span>(<span class="atom">1989</span>, <span class="atom">10</span>, <span class="atom">9</span>);
+<span class="keyword">var</span> <span class="variable">gulfWarOne</span> = <span class="keyword">new</span> <span class="variable">Date</span>(<span class="atom">1990</span>, <span class="atom">6</span>, <span class="atom">2</span>);
+<span class="variable">show</span>(<span class="variable">wallFall</span> < <span class="variable">gulfWarOne</span>);
+<span class="variable">show</span>(<span class="variable">wallFall</span> == <span class="variable">wallFall</span>);
+<span class="comment">// but</span>
+<span class="variable">show</span>(<span class="variable">wallFall</span> == <span class="keyword">new</span> <span class="variable">Date</span>(<span class="atom">1989</span>, <span class="atom">10</span>, <span class="atom">9</span>));</pre><p><a class="paragraph" href="#p19255137ba410999" name="p19255137ba410999"> </a>Comparing dates with <code><</code>, <code>></code>, <code><=</code>, and <code>>=</code> does exactly what you
+would expect. When a date object is compared to itself with <code>==</code> the
+result is <code>true</code>, which is also good. But when <a name="key30"></a><code>==</code> is used to
+compare a date object to a different, equal date object, we get
+<code>false</code>. Huh?</p><p><a class="paragraph" href="#p3948ccce640dd7f8" name="p3948ccce640dd7f8"> </a>As mentioned earlier, <code>==</code> will return <code>false</code> when comparing two
+different objects, even if they contain the same properties. This is a
+bit clumsy and error-prone here, since one would expect <code>>=</code> and <code>==</code>
+to behave in a more or less similar way. Testing whether two dates are
+equal can be done like this:</p><pre class="code"><span class="keyword">var</span> <span class="variable">wallFall1</span> = <span class="keyword">new</span> <span class="variable">Date</span>(<span class="atom">1989</span>, <span class="atom">10</span>, <span class="atom">9</span>),
+ <span class="variable">wallFall2</span> = <span class="keyword">new</span> <span class="variable">Date</span>(<span class="atom">1989</span>, <span class="atom">10</span>, <span class="atom">9</span>);
+<span class="variable">show</span>(<span class="variable">wallFall1</span>.<span class="property">getTime</span>() == <span class="variable">wallFall2</span>.<span class="property">getTime</span>());</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p1f17c7dc7bee5aeb" name="p1f17c7dc7bee5aeb"> </a>In addition to a date and time, <code>Date</code> objects also contain
+information about a <a name="key31"></a>timezone. When it is one o'clock in Amsterdam,
+it can, depending on the time of year, be noon in London, and seven in
+the morning in New York. Such times can only be compared when you take
+their time zones into account. The <a name="key32"></a><code>getTimezoneOffset</code> function of a
+<code>Date</code> can be used to find out how many minutes it differs from GMT
+(Greenwich Mean Time).</p><pre class="code"><span class="keyword">var</span> <span class="variable">now</span> = <span class="keyword">new</span> <span class="variable">Date</span>();
+<span class="variable">print</span>(<span class="variable">now</span>.<span class="property">getTimezoneOffset</span>());</pre></div><hr/><div class="block"><a name="exercise6"></a><div class="exercisenum">Ex. 4.6</div><div class="exercise"><pre class="preformatted">"died 27/04/2006: Black Leclre"</pre><p><a class="paragraph" href="#pb1d0ff442ec8e6f" name="pb1d0ff442ec8e6f"> </a>The date part is always in the exact same place of a paragraph. How
+convenient. Write a function <code>extractDate</code> that takes such a paragraph
+as its argument, extracts the date, and returns it as a date object.</p></div><div class="solution"><pre class="code"><span class="keyword">function</span> <span class="variable">extractDate</span>(<span class="variabledef">paragraph</span>) {
+ <span class="keyword">function</span> <span class="variabledef">numberAt</span>(<span class="variabledef">start</span>, <span class="variabledef">length</span>) {
+ <span class="keyword">return</span> <span class="variable">Number</span>(<span class="localvariable">paragraph</span>.<span class="property">slice</span>(<span class="localvariable">start</span>, <span class="localvariable">start</span> + <span class="localvariable">length</span>));
+ }
+ <span class="keyword">return</span> <span class="keyword">new</span> <span class="variable">Date</span>(<span class="localvariable">numberAt</span>(<span class="atom">11</span>, <span class="atom">4</span>), <span class="localvariable">numberAt</span>(<span class="atom">8</span>, <span class="atom">2</span>) - <span class="atom">1</span>,
+ <span class="localvariable">numberAt</span>(<span class="atom">5</span>, <span class="atom">2</span>));
+}
+
+<span class="variable">show</span>(<span class="variable">extractDate</span>(<span class="string">"died 27-04-2006: Black Leclre"</span>));</pre><p><a class="paragraph" href="#p69f81ed7e3e5af4b" name="p69f81ed7e3e5af4b"> </a>It would work without the calls to <code>Number</code>, but as mentioned earlier,
+I prefer not to use strings as if they are numbers. The inner function
+was introduced to prevent having to repeat the <code>Number</code> and <code>slice</code>
+part three times.</p><p><a class="paragraph" href="#p17a75abbb24156d6" name="p17a75abbb24156d6"> </a>Note the <code>- 1</code> for the month number. Like most people, Aunt Emily
+counts her months from 1, so we have to adjust the value before giving
+it to the <code>Date</code> constructor. (The day number does not have this
+problem, since <code>Date</code> objects count days in the usual human way.)</p><p><a class="paragraph" href="#p78edee83ce3ee883" name="p78edee83ce3ee883"> </a>In <a href="chapter10.html">chapter 10</a> we will see a more practical and robust way of extracting
+pieces from strings that have a fixed structure.</p></div></div><hr/><div class="block"><p><a class="paragraph" href="#p6231188669290e08" name="p6231188669290e08"> </a>Storing cats will work differently from now on. Instead of just
+putting the value <code>true</code> into the set, we store an object with
+information about the cat. When a cat dies, we do not remove it from
+the set, we just add a property <code>death</code> to the object to store the
+date on which the creature died.</p><p><a class="paragraph" href="#p5e80cffb16b8822b" name="p5e80cffb16b8822b"> </a>This means our <code>addToSet</code> and <code>removeFromSet</code> functions have become
+useless. Something similar is needed, but it must also store
+birth-dates and, later, the mother's name.</p><pre class="code"><span class="keyword">function</span> <span class="variable">catRecord</span>(<span class="variabledef">name</span>, <span class="variabledef">birthdate</span>, <span class="variabledef">mother</span>) {
+ <span class="keyword">return</span> {<span class="property">name</span>: <span class="localvariable">name</span>, <span class="property">birth</span>: <span class="localvariable">birthdate</span>, <span class="property">mother</span>: <span class="localvariable">mother</span>};
+}
+
+<span class="keyword">function</span> <span class="variable">addCats</span>(<span class="variabledef">set</span>, <span class="variabledef">names</span>, <span class="variabledef">birthdate</span>, <span class="variabledef">mother</span>) {
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variabledef">i</span> = <span class="atom">0</span>; <span class="localvariable">i</span> < <span class="localvariable">names</span>.<span class="property">length</span>; <span class="localvariable">i</span>++)
+ <span class="localvariable">set</span>[<span class="localvariable">names</span>[<span class="localvariable">i</span>]] = <span class="variable">catRecord</span>(<span class="localvariable">names</span>[<span class="localvariable">i</span>], <span class="localvariable">birthdate</span>, <span class="localvariable">mother</span>);
+}
+<span class="keyword">function</span> <span class="variable">deadCats</span>(<span class="variabledef">set</span>, <span class="variabledef">names</span>, <span class="variabledef">deathdate</span>) {
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variabledef">i</span> = <span class="atom">0</span>; <span class="localvariable">i</span> < <span class="localvariable">names</span>.<span class="property">length</span>; <span class="localvariable">i</span>++)
+ <span class="localvariable">set</span>[<span class="localvariable">names</span>[<span class="localvariable">i</span>]].<span class="property">death</span> = <span class="localvariable">deathdate</span>;
+}</pre><p><a class="paragraph" href="#p6faa980ecfae9cd0" name="p6faa980ecfae9cd0"> </a><code>catRecord</code> is a separate function for creating these storage objects.
+It might be useful in other situations, such as creating the object
+for Spot. 'Record' is a term often used for objects like this, which
+are used to group a limited number of values.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p8813bf1acd966d7" name="p8813bf1acd966d7"> </a>So let us try to extract the names of the mother cats from the
+paragraphs.</p><pre class="preformatted">"born 15/11/2003 (mother Spot): White Fang"</pre><p><a class="paragraph" href="#p7d8bd57ae8eb1851" name="p7d8bd57ae8eb1851"> </a>One way to do this would be...</p><pre class="code"><span class="keyword">function</span> <span class="variable">extractMother</span>(<span class="variabledef">paragraph</span>) {
+ <span class="keyword">var</span> <span class="variabledef">start</span> = <span class="localvariable">paragraph</span>.<span class="property">indexOf</span>(<span class="string">"(mother "</span>) + <span class="string">"(mother "</span>.<span class="property">length</span>;
+ <span class="keyword">var</span> <span class="variabledef">end</span> = <span class="localvariable">paragraph</span>.<span class="property">indexOf</span>(<span class="string">")"</span>);
+ <span class="keyword">return</span> <span class="localvariable">paragraph</span>.<span class="property">slice</span>(<span class="localvariable">start</span>, <span class="localvariable">end</span>);
+}
+
+<span class="variable">show</span>(<span class="variable">extractMother</span>(<span class="string">"born 15/11/2003 (mother Spot): White Fang"</span>));</pre><p><a class="paragraph" href="#p5e1cda67dde3c884" name="p5e1cda67dde3c884"> </a>Notice how the start position has to be adjusted for the length of
+<code>"(mother "</code>, because <code>indexOf</code> returns the position of the start of
+the pattern, not its end.</p></div><hr/><div class="block"><a name="exercise7"></a><div class="exercisenum">Ex. 4.7</div><div class="exercise"><p><a class="paragraph" href="#pd8b2deab1823547" name="pd8b2deab1823547"> </a>The thing that <code>extractMother</code> does can be expressed in a more general
+way. Write a function <code>between</code> that takes three arguments, all of
+which are strings. It will return the part of the first argument that
+occurs between the patterns given by the second and the third
+arguments.</p><p><a class="paragraph" href="#p10683394354b9d86" name="p10683394354b9d86"> </a>So <code>between("born 15/11/2003 (mother Spot): White Fang", "(mother ",
+")")</code> gives <code>"Spot"</code>.</p><p><a class="paragraph" href="#p2b71a5af1756297e" name="p2b71a5af1756297e"> </a><code>between("bu ] boo [ bah ] gzz", "[ ", " ]")</code> returns <code>"bah"</code>.</p><p><a class="paragraph" href="#p51f662968c8adaa7" name="p51f662968c8adaa7"> </a>To make that second test work, it can be useful to know that <code>indexOf</code>
+can be given a second, optional parameter that specifies at which
+point it should start searching.</p></div><div class="solution"><pre class="code"><span class="keyword">function</span> <span class="variable">between</span>(<span class="variabledef">string</span>, <span class="variabledef">start</span>, <span class="variabledef">end</span>) {
+ <span class="keyword">var</span> <span class="variabledef">startAt</span> = <span class="localvariable">string</span>.<span class="property">indexOf</span>(<span class="localvariable">start</span>) + <span class="localvariable">start</span>.<span class="property">length</span>;
+ <span class="keyword">var</span> <span class="variabledef">endAt</span> = <span class="localvariable">string</span>.<span class="property">indexOf</span>(<span class="localvariable">end</span>, <span class="localvariable">startAt</span>);
+ <span class="keyword">return</span> <span class="localvariable">string</span>.<span class="property">slice</span>(<span class="localvariable">startAt</span>, <span class="localvariable">endAt</span>);
+}
+<span class="variable">show</span>(<span class="variable">between</span>(<span class="string">"bu ] boo [ bah ] gzz"</span>, <span class="string">"[ "</span>, <span class="string">" ]"</span>));</pre></div></div><hr/><div class="block"><p><a class="paragraph" href="#p4064448f6a557c9c" name="p4064448f6a557c9c"> </a>Having <code>between</code> makes it possible to express extractMother in a
+simpler way:</p><pre class="code"><span class="keyword">function</span> <span class="variable">extractMother</span>(<span class="variabledef">paragraph</span>) {
+ <span class="keyword">return</span> <span class="variable">between</span>(<span class="localvariable">paragraph</span>, <span class="string">"(mother "</span>, <span class="string">")"</span>);
+}</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p50633f100de91e0" name="p50633f100de91e0"> </a>The new, improved cat-algorithm looks like this:</p><pre class="code"><span class="keyword">function</span> <span class="variable">findCats</span>() {
+ <span class="keyword">var</span> <span class="variabledef">mailArchive</span> = <span class="variable">retrieveMails</span>();
+ <span class="keyword">var</span> <span class="variabledef">cats</span> = {<span class="string">"Spot"</span>: <span class="variable">catRecord</span>(<span class="string">"Spot"</span>, <span class="keyword">new</span> <span class="variable">Date</span>(<span class="atom">1997</span>, <span class="atom">2</span>, <span class="atom">5</span>),
+ <span class="string">"unknown"</span>)};
+
+ <span class="keyword">function</span> <span class="variabledef">handleParagraph</span>(<span class="variabledef">paragraph</span>) {
+ <span class="keyword">if</span> (<span class="variable">startsWith</span>(<span class="localvariable">paragraph</span>, <span class="string">"born"</span>))
+ <span class="variable">addCats</span>(<span class="localvariable">cats</span>, <span class="variable">catNames</span>(<span class="localvariable">paragraph</span>), <span class="variable">extractDate</span>(<span class="localvariable">paragraph</span>),
+ <span class="variable">extractMother</span>(<span class="localvariable">paragraph</span>));
+ <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">startsWith</span>(<span class="localvariable">paragraph</span>, <span class="string">"died"</span>))
+ <span class="variable">deadCats</span>(<span class="localvariable">cats</span>, <span class="variable">catNames</span>(<span class="localvariable">paragraph</span>), <span class="variable">extractDate</span>(<span class="localvariable">paragraph</span>));
+ }
+
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variabledef">mail</span> = <span class="atom">0</span>; <span class="localvariable">mail</span> < <span class="localvariable">mailArchive</span>.<span class="property">length</span>; <span class="localvariable">mail</span>++) {
+ <span class="keyword">var</span> <span class="variabledef">paragraphs</span> = <span class="localvariable">mailArchive</span>[<span class="localvariable">mail</span>].<span class="property">split</span>(<span class="string">"\n"</span>);
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variabledef">i</span> = <span class="atom">0</span>; <span class="localvariable">i</span> < <span class="localvariable">paragraphs</span>.<span class="property">length</span>; <span class="localvariable">i</span>++)
+ <span class="localvariable">handleParagraph</span>(<span class="localvariable">paragraphs</span>[<span class="localvariable">i</span>]);
+ }
+ <span class="keyword">return</span> <span class="localvariable">cats</span>;
+}
+
+<span class="keyword">var</span> <span class="variable">catData</span> = <span class="variable">findCats</span>();</pre><p><a class="paragraph" href="#p64c74e3df6edee0b" name="p64c74e3df6edee0b"> </a>Having that extra data allows us to finally have a clue about the cats
+aunt Emily talks about. A function like this could be useful:</p><pre class="code"><span class="keyword">function</span> <span class="variable">formatDate</span>(<span class="variabledef">date</span>) {
+ <span class="keyword">return</span> <span class="localvariable">date</span>.<span class="property">getDate</span>() + <span class="string">"/"</span> + (<span class="localvariable">date</span>.<span class="property">getMonth</span>() + <span class="atom">1</span>) +
+ <span class="string">"/"</span> + <span class="localvariable">date</span>.<span class="property">getFullYear</span>();
+}
+
+<span class="keyword">function</span> <span class="variable">catInfo</span>(<span class="variabledef">data</span>, <span class="variabledef">name</span>) {
+ <span class="keyword">if</span> (!(<span class="localvariable">name</span> in <span class="localvariable">data</span>))
+ <span class="keyword">return</span> <span class="string">"No cat by the name of "</span> + <span class="localvariable">name</span> + <span class="string">" is known."</span>;
+
+ <span class="keyword">var</span> <span class="variabledef">cat</span> = <span class="localvariable">data</span>[<span class="localvariable">name</span>];
+ <span class="keyword">var</span> <span class="variabledef">message</span> = <span class="localvariable">name</span> + <span class="string">", born "</span> + <span class="variable">formatDate</span>(<span class="localvariable">cat</span>.<span class="property">birth</span>) +
+ <span class="string">" from mother "</span> + <span class="localvariable">cat</span>.<span class="property">mother</span>;
+ <span class="keyword">if</span> (<span class="string">"death"</span> in <span class="localvariable">cat</span>)
+ <span class="localvariable">message</span> += <span class="string">", died "</span> + <span class="variable">formatDate</span>(<span class="localvariable">cat</span>.<span class="property">death</span>);
+ <span class="keyword">return</span> <span class="localvariable">message</span> + <span class="string">"."</span>;
+}
+
+<span class="variable">print</span>(<span class="variable">catInfo</span>(<span class="variable">catData</span>, <span class="string">"Fat Igor"</span>));</pre><p><a class="paragraph" href="#p744754e286e636d9" name="p744754e286e636d9"> </a>The first <code>return</code> statement in <code>catInfo</code> is used as an escape hatch.
+If there is no data about the given cat, the rest of the function is
+meaningless, so we immediately return a value, which prevents the rest
+of the code from running.</p><p><a class="paragraph" href="#p65a8337e1b1950af" name="p65a8337e1b1950af"> </a>In the past, certain groups of programmers considered functions that
+contain multiple <code>return</code> statements sinful. The idea was that this
+made it hard to see which code was executed and which code was not.
+Other techniques, which will be discussed in <a href="chapter5.html">chapter 5</a>, have made the
+reasons behind this idea more or less obsolete, but you might still
+occasionally come across someone who will criticise the use of
+'shortcut' return statements.</p></div><hr/><div class="block"><a name="exercise8"></a><div class="exercisenum">Ex. 4.8</div><div class="exercise"><p><a class="paragraph" href="#p4a0ed3bb5d1716e3" name="p4a0ed3bb5d1716e3"> </a>The <code>formatDate</code> function used by <code>catInfo</code> does not add a zero before
+the month and the day part when these are only one digit long. Write a
+new version that does this.</p></div><div class="solution"><pre class="code"><span class="keyword">function</span> <span class="variable">formatDate</span>(<span class="variabledef">date</span>) {
+ <span class="keyword">function</span> <span class="variabledef">pad</span>(<span class="variabledef">number</span>) {
+ <span class="keyword">if</span> (<span class="localvariable">number</span> < <span class="atom">10</span>)
+ <span class="keyword">return</span> <span class="string">"0"</span> + <span class="localvariable">number</span>;
+ <span class="keyword">else</span>
+ <span class="keyword">return</span> <span class="localvariable">number</span>;
+ }
+ <span class="keyword">return</span> <span class="localvariable">pad</span>(<span class="localvariable">date</span>.<span class="property">getDate</span>()) + <span class="string">"/"</span> + <span class="localvariable">pad</span>(<span class="localvariable">date</span>.<span class="property">getMonth</span>() + <span class="atom">1</span>) +
+ <span class="string">"/"</span> + <span class="localvariable">date</span>.<span class="property">getFullYear</span>();
+}
+<span class="variable">print</span>(<span class="variable">formatDate</span>(<span class="keyword">new</span> <span class="variable">Date</span>(<span class="atom">2000</span>, <span class="atom">0</span>, <span class="atom">1</span>)));</pre></div></div><hr/><div class="block"><a name="exercise9"></a><div class="exercisenum">Ex. 4.9</div><div class="exercise"><p><a class="paragraph" href="#pb4c5eaeeba870f0" name="pb4c5eaeeba870f0"> </a>Write a function <code>oldestCat</code> which, given an object containing cats as
+its argument, returns the name of the oldest living cat.</p></div><div class="solution"><pre class="code"><span class="keyword">function</span> <span class="variable">oldestCat</span>(<span class="variabledef">data</span>) {
+ <span class="keyword">var</span> <span class="variabledef">oldest</span> = <span class="atom">null</span>;
+
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variabledef">name</span> <span class="keyword">in</span> <span class="localvariable">data</span>) {
+ <span class="keyword">var</span> <span class="variabledef">cat</span> = <span class="localvariable">data</span>[<span class="localvariable">name</span>];
+ <span class="keyword">if</span> (!(<span class="string">"death"</span> in <span class="localvariable">cat</span>) &&
+ (<span class="localvariable">oldest</span> == <span class="atom">null</span> || <span class="localvariable">oldest</span>.<span class="property">birth</span> > <span class="localvariable">cat</span>.<span class="property">birth</span>))
+ <span class="localvariable">oldest</span> = <span class="localvariable">cat</span>;
+ }
+
+ <span class="keyword">if</span> (<span class="localvariable">oldest</span> == <span class="atom">null</span>)
+ <span class="keyword">return</span> <span class="atom">null</span>;
+ <span class="keyword">else</span>
+ <span class="keyword">return</span> <span class="localvariable">oldest</span>.<span class="property">name</span>;
+}
+
+<span class="variable">print</span>(<span class="variable">oldestCat</span>(<span class="variable">catData</span>));</pre><p><a class="paragraph" href="#p285408cd2c93c127" name="p285408cd2c93c127"> </a>The condition in the <code>if</code> statement might seem a little intimidating.
+It can be read as 'only store the current cat in the variable <code>oldest</code>
+if it is not dead, and <code>oldest</code> is either <code>null</code> or a cat that was
+born after the current cat'.</p><p><a class="paragraph" href="#p4feaed58fe9460c6" name="p4feaed58fe9460c6"> </a>Note that this function returns <code>null</code> when there are no living cats
+in <code>data</code>. What does your solution do in that case?</p></div></div><hr/><div class="block"><p><a class="paragraph" href="#p4d7165898045f99" name="p4d7165898045f99"> </a>Now that we are familiar with arrays, I can show you something
+related. Whenever a function is called, a special variable named
+<a name="key33"></a><code>arguments</code> is added to the environment in which the function body
+runs. This variable refers to an object that resembles an array. It
+has a property <code>0</code> for the first argument, <code>1</code> for the second, and so
+on for every argument the function was given. It also has a <a name="key34"></a><code>length</code>
+property.</p><p><a class="paragraph" href="#p5d6f061498f2c6ec" name="p5d6f061498f2c6ec"> </a>This object is not a real array though, it does not have methods like
+<code>push</code>, and it does not automatically update its <code>length</code> property
+when you add something to it. Why not, I never really found out, but
+this is something one needs to be aware of.</p><pre class="code"><span class="keyword">function</span> <span class="variable">argumentCounter</span>() {
+ <span class="variable">print</span>(<span class="string">"You gave me "</span>, <span class="localvariable">arguments</span>.<span class="property">length</span>, <span class="string">" arguments."</span>);
+}
+<span class="variable">argumentCounter</span>(<span class="string">"Death"</span>, <span class="string">"Famine"</span>, <span class="string">"Pestilence"</span>);</pre><p><a class="paragraph" href="#pe2ca89d1a2931ea" name="pe2ca89d1a2931ea"> </a>Some functions can take any number of arguments, like <code>print</code> does.
+These typically loop over the values in the <code>arguments</code> object to do
+something with them. Others can take optional arguments which, when
+not given by the caller, get some sensible default value.</p><pre class="code"><span class="keyword">function</span> <span class="variable">add</span>(<span class="variabledef">number</span>, <span class="variabledef">howmuch</span>) {
+ <span class="keyword">if</span> (<span class="localvariable">arguments</span>.<span class="property">length</span> < <span class="atom">2</span>)
+ <span class="localvariable">howmuch</span> = <span class="atom">1</span>;
+ <span class="keyword">return</span> <span class="localvariable">number</span> + <span class="localvariable">howmuch</span>;
+}
+
+<span class="variable">show</span>(<span class="variable">add</span>(<span class="atom">6</span>));
+<span class="variable">show</span>(<span class="variable">add</span>(<span class="atom">6</span>, <span class="atom">4</span>));</pre></div><hr/><div class="block"><a name="exercise10"></a><div class="exercisenum">Ex. 4.10</div><div class="exercise"><p><a class="paragraph" href="#p20228267b5983b13" name="p20228267b5983b13"> </a>Extend the <code>range</code> function from <a href="chapter4.html#exercise2">exercise 4.2</a> to take a second, optional
+argument. If only one argument is given, it behaves as earlier and
+produces a range from 0 to the given number. If two arguments are
+given, the first indicates the start of the range, the second the end.</p></div><div class="solution"><pre class="code"><span class="keyword">function</span> <span class="variable">range</span>(<span class="variabledef">start</span>, <span class="variabledef">end</span>) {
+ <span class="keyword">if</span> (<span class="localvariable">arguments</span>.<span class="property">length</span> < <span class="atom">2</span>) {
+ <span class="localvariable">end</span> = <span class="localvariable">start</span>;
+ <span class="localvariable">start</span> = <span class="atom">0</span>;
+ }
+ <span class="keyword">var</span> <span class="variabledef">result</span> = [];
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variabledef">i</span> = <span class="localvariable">start</span>; <span class="localvariable">i</span> <= <span class="localvariable">end</span>; <span class="localvariable">i</span>++)
+ <span class="localvariable">result</span>.<span class="property">push</span>(<span class="localvariable">i</span>);
+ <span class="keyword">return</span> <span class="localvariable">result</span>;
+}
+
+<span class="variable">show</span>(<span class="variable">range</span>(<span class="atom">4</span>));
+<span class="variable">show</span>(<span class="variable">range</span>(<span class="atom">2</span>, <span class="atom">4</span>));</pre><p><a class="paragraph" href="#p41212ba9134d0970" name="p41212ba9134d0970"> </a>The optional argument does not work precisely like the one in the
+<code>add</code> example above. When it is not given, the first argument takes
+the role of <code>end</code>, and <code>start</code> becomes <code>0</code>.</p></div></div><hr/><div class="block"><a name="exercise11"></a><div class="exercisenum">Ex. 4.11</div><div class="exercise"><p><a class="paragraph" href="#p7e9a60fc2a17f3d8" name="p7e9a60fc2a17f3d8"> </a>You may remember this line of code from the introduction:</p><pre class="code invalid"><span class="variable">print</span>(<span class="variable">sum</span>(<span class="variable">range</span>(<span class="atom">1</span>, <span class="atom">10</span>)));</pre><p><a class="paragraph" href="#p717ee2c2365c357f" name="p717ee2c2365c357f"> </a>We have <code>range</code> now. All we need to make this line work is a <code>sum</code>
+function. This function takes an array of numbers, and returns their
+sum. Write it, it should be easy.</p></div><div class="solution"><pre class="code"><span class="keyword">function</span> <span class="variable">sum</span>(<span class="variabledef">numbers</span>) {
+ <span class="keyword">var</span> <span class="variabledef">total</span> = <span class="atom">0</span>;
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variabledef">i</span> = <span class="atom">0</span>; <span class="localvariable">i</span> < <span class="localvariable">numbers</span>.<span class="property">length</span>; <span class="localvariable">i</span>++)
+ <span class="localvariable">total</span> += <span class="localvariable">numbers</span>[<span class="localvariable">i</span>];
+ <span class="keyword">return</span> <span class="localvariable">total</span>;
+}
+
+<span class="variable">print</span>(<span class="variable">sum</span>(<span class="variable">range</span>(<span class="atom">1</span>, <span class="atom">10</span>)));</pre></div></div><hr/><div class="block"><p><a class="paragraph" href="#p12ff9c0aced56748" name="p12ff9c0aced56748"> </a><a href="chapter2.html">Chapter 2</a> mentioned the functions <code>Math.max</code> and <code>Math.min</code>.
+With what you know now, you will notice that these are really the
+properties <code>max</code> and <code>min</code> of the object stored under the name
+<a name="key35"></a><code>Math</code>. This is another role that objects can play: A warehouse
+holding a number of related values.</p><p><a class="paragraph" href="#p43b6d0895389b0ba" name="p43b6d0895389b0ba"> </a>There are quite a lot of values inside <code>Math</code>, if they would all have
+been placed directly into the global environment they would, as it is
+called, pollute it. The more names have been taken, the more likely
+one is to accidentally overwrite the value of some variable. For
+example, it is not a far shot to want to name something <code>max</code>.</p><p><a class="paragraph" href="#p169966adcd36c941" name="p169966adcd36c941"> </a>Most languages will stop you, or at least warn you, when you are
+defining a variable with a name that is already taken. Not JavaScript.</p><p><a class="paragraph" href="#p6c55460a225e2a59" name="p6c55460a225e2a59"> </a>In any case, one can find a whole outfit of mathematical functions and
+constants inside <code>Math</code>. All the trigonometric functions are there ―
+<code>cos</code>, <code>sin</code>, <code>tan</code>, <code>acos</code>, <code>asin</code>, <code>atan</code>. π and e, which are
+written with all capital letters (<code>PI</code> and <code>E</code>), which was, at one
+time, a fashionable way to indicate something is a constant. <code>pow</code> is
+a good replacement for the <code>power</code> functions we have been writing, it
+also accepts negative and fractional exponents. <code>sqrt</code> takes square
+roots. <code>max</code> and <code>min</code> can give the maximum or minimum of two values.
+<a name="key36"></a><a name="key37"></a><a name="key38"></a><code>round</code>, <code>floor</code>, and
+<code>ceil</code> will round numbers to the closest whole number, the whole
+number below it, and the whole number above it respectively.</p><p><a class="paragraph" href="#p372cb886b60de3b5" name="p372cb886b60de3b5"> </a>There are a number of other values in <code>Math</code>, but this text is an
+introduction, not a <a name="key39"></a>reference. References are what you look at when
+you suspect something exists in the language, but need to find out
+what it is called or how it works exactly. Unfortunately, there is no
+one comprehensive complete reference for JavaScript. This is mostly
+because its current form is the result of a chaotic process of
+different browsers adding different extensions at different times. The
+ECMA standard document that was mentioned in the introduction provides
+a solid documentation of the basic language, but is more or less
+unreadable. For most things, your best bet is the <a href="https://developer.mozilla.org/en/JavaScript/Reference/">Mozilla Developer
+Network</a>.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p13075c1e2cf024c1" name="p13075c1e2cf024c1"> </a>Maybe you already thought of a way to find out what is available in
+the <code>Math</code> object:</p><pre class="code"><span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">name</span> <span class="keyword">in</span> <span class="variable">Math</span>)
+ <span class="variable">print</span>(<span class="variable">name</span>);</pre><p><a class="paragraph" href="#p75f3933a7434183f" name="p75f3933a7434183f"> </a>But alas, nothing appears. Similarly, when you do this:</p><pre class="code"><span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">name</span> <span class="keyword">in</span> [<span class="string">"Huey"</span>, <span class="string">"Dewey"</span>, <span class="string">"Loui"</span>])
+ <span class="variable">print</span>(<span class="variable">name</span>);</pre><p><a class="paragraph" href="#p4b432c2f1e6f0ac5" name="p4b432c2f1e6f0ac5"> </a>You only see <code>0</code>, <code>1</code>, and <code>2</code>, not <code>length</code>, or <code>push</code>, or <code>join</code>,
+which are definitely also in there. Apparently, some properties of
+objects are hidden<a name="key40"></a>. There is a good reason for
+this: All objects have a few methods, for example <a name="key41"></a><code>toString</code>, which
+converts the object into some kind of relevant string, and you do not
+want to see those when you are, for example, looking for the cats that
+you stored in the object.</p><p><a class="paragraph" href="#p24f5b457aa728472" name="p24f5b457aa728472"> </a>Why the properties of <code>Math</code> are hidden is unclear to me. Someone
+probably wanted it to be a mysterious kind of object.</p><p><a class="paragraph" href="#p1bb9785463d8ae0c" name="p1bb9785463d8ae0c"> </a>All properties your programs add to objects are visible. There is no
+way to make them hidden, which is unfortunate because, as we will see
+in <a href="chapter8.html">chapter 8</a>, it would be nice to be able to add methods to objects
+without having them show up in our <code>for</code>/<code>in</code> loops.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p32975b9cc4433e91" name="p32975b9cc4433e91"> </a><a name="key42"></a>Some properties are read-only, you can get
+their value but not change it. For example, the properties of a string
+value are all read-only.</p><p><a class="paragraph" href="#p15ce1d78b184077e" name="p15ce1d78b184077e"> </a>Other properties can be 'active'. Changing them
+causes <em>things</em> to happen. For example, lowering the length of an
+array causes excess elements to be discarded:</p><pre class="code"><span class="keyword">var</span> <span class="variable">array</span> = [<span class="string">"Heaven"</span>, <span class="string">"Earth"</span>, <span class="string">"Man"</span>];
+<span class="variable">array</span>.<span class="property">length</span> = <span class="atom">2</span>;
+<span class="variable">show</span>(<span class="variable">array</span>);</pre></div><ol class="footnotes"><li><a name="footnote1"></a>There are a few subtle problems with this approach, which will be
+discussed and solved in <a href="chapter8.html">chapter 8</a>. For this chapter, it works well enough.</li></ol><h1><span class="number">Chapter 5: </span>Error Handling</h1><div class="block"><p><a class="paragraph" href="#p23415e96aafc7a8d" name="p23415e96aafc7a8d"> </a>Writing programs that work when everything goes as expected is a good
+start. Making your programs behave properly when encountering
+unexpected conditions is where it really gets challenging.</p><p><a class="paragraph" href="#p1139aa50a5371761" name="p1139aa50a5371761"> </a>The problematic situations that a program can encounter fall into two
+categories: Programmer mistakes and genuine problems. If someone
+forgets to pass a required argument to a function, that is an example
+of the first kind of problem. On the other hand, if a program asks the
+user to enter a name and it gets back an empty string, that is
+something the programmer can not prevent.</p><p><a class="paragraph" href="#p20ee0eeaf72d4de1" name="p20ee0eeaf72d4de1"> </a>In general, one deals with programmer errors by finding and fixing
+them, and with genuine errors by having the code check for them and
+perform some suitable action to remedy them (for example, asking for
+the name again), or at least fail in a well-defined and clean way.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p265cd385d7c63b7f" name="p265cd385d7c63b7f"> </a>It is important to decide into which of these categories a certain
+problem falls. For example, consider our old <code>power</code> function:</p><pre class="code"><span class="keyword">function</span> <span class="variable">power</span>(<span class="variabledef">base</span>, <span class="variabledef">exponent</span>) {
+ <span class="keyword">var</span> <span class="variabledef">result</span> = <span class="atom">1</span>;
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variabledef">count</span> = <span class="atom">0</span>; <span class="localvariable">count</span> < <span class="localvariable">exponent</span>; <span class="localvariable">count</span>++)
+ <span class="localvariable">result</span> *= <span class="localvariable">base</span>;
+ <span class="keyword">return</span> <span class="localvariable">result</span>;
+}</pre><p><a class="paragraph" href="#p76fc78f5e4d27491" name="p76fc78f5e4d27491"> </a>When some geek tries to call <code>power("Rabbit", 4)</code>, that is quite
+obviously a programmer error, but how about <code>power(9, 0.5)</code>? The
+function can not handle fractional exponents, but, mathematically
+speaking, raising a number to the halfth power is perfectly reasonable
+(<a name="key1"></a><code>Math.pow</code> can handle it). In situations where it is not entirely
+clear what kind of input a function accepts, it is often a good idea
+to explicitly state the kind of arguments that are acceptable in a
+comment.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p603873105d7487a4" name="p603873105d7487a4"> </a>If a function encounters a problem that it can not solve itself, what
+should it do? In <a href="chapter4.html">chapter 4</a> we wrote the function <code>between</code>:</p><pre class="code"><span class="keyword">function</span> <span class="variable">between</span>(<span class="variabledef">string</span>, <span class="variabledef">start</span>, <span class="variabledef">end</span>) {
+ <span class="keyword">var</span> <span class="variabledef">startAt</span> = <span class="localvariable">string</span>.<span class="property">indexOf</span>(<span class="localvariable">start</span>) + <span class="localvariable">start</span>.<span class="property">length</span>;
+ <span class="keyword">var</span> <span class="variabledef">endAt</span> = <span class="localvariable">string</span>.<span class="property">indexOf</span>(<span class="localvariable">end</span>, <span class="localvariable">startAt</span>);
+ <span class="keyword">return</span> <span class="localvariable">string</span>.<span class="property">slice</span>(<span class="localvariable">startAt</span>, <span class="localvariable">endAt</span>);
+}</pre><p><a class="paragraph" href="#p3f610153f264b3d7" name="p3f610153f264b3d7"> </a>If the given <code>start</code> and <code>end</code> do not occur in the string, <code>indexOf</code>
+will return <code>-1</code> and this version of <code>between</code> will return a lot of
+nonsense: <code>between("Your mother!", "{-", "-}")</code> returns <code>"our mother"</code>.</p><p><a class="paragraph" href="#p499735628bc535b3" name="p499735628bc535b3"> </a>When the program is running, and the function is called like that, the
+code that called it will get a string value, as it expected, and
+happily continue doing something with it. But the value is wrong, so
+whatever it ends up doing with it will also be wrong. And if you are
+unlucky, this wrongness only causes a problem after having passed
+through twenty other functions. In cases like that, it is extremely
+hard to find out where the problem started.</p><p><a class="paragraph" href="#p3b2ec371666f4e1a" name="p3b2ec371666f4e1a"> </a>In some cases, you will be so unconcerned about these problems that
+you don't mind the function misbehaving when given incorrect input.
+For example, if you know for sure the function will only be called
+from a few places, and you can prove that these places give it decent
+input, it is generally not worth the trouble to make the function
+bigger and uglier so that it can handle problematic cases.</p><p><a class="paragraph" href="#p487f962e97db245e" name="p487f962e97db245e"> </a>But most of the time, functions that fail 'silently' are hard to use,
+and even dangerous. What if the code calling <code>between</code> wants to know
+whether everything went well? At the moment, it can not tell, except
+by re-doing all the work that <code>between</code> did and checking the result of
+<code>between</code> with its own result. That is bad. One solution is to make
+<code>between</code> return a special value, such as <code>false</code> or <code>undefined</code>, when
+it fails.</p><pre class="code"><span class="keyword">function</span> <span class="variable">between</span>(<span class="variabledef">string</span>, <span class="variabledef">start</span>, <span class="variabledef">end</span>) {
+ <span class="keyword">var</span> <span class="variabledef">startAt</span> = <span class="localvariable">string</span>.<span class="property">indexOf</span>(<span class="localvariable">start</span>);
+ <span class="keyword">if</span> (<span class="localvariable">startAt</span> == -<span class="atom">1</span>)
+ <span class="keyword">return</span> <span class="atom">undefined</span>;
+ <span class="localvariable">startAt</span> += <span class="localvariable">start</span>.<span class="property">length</span>;
+ <span class="keyword">var</span> <span class="variabledef">endAt</span> = <span class="localvariable">string</span>.<span class="property">indexOf</span>(<span class="localvariable">end</span>, <span class="localvariable">startAt</span>);
+ <span class="keyword">if</span> (<span class="localvariable">endAt</span> == -<span class="atom">1</span>)
+ <span class="keyword">return</span> <span class="atom">undefined</span>;
+
+ <span class="keyword">return</span> <span class="localvariable">string</span>.<span class="property">slice</span>(<span class="localvariable">startAt</span>, <span class="localvariable">endAt</span>);
+}</pre><p><a class="paragraph" href="#p3fa9a1283c5c0ee6" name="p3fa9a1283c5c0ee6"> </a>You can see that error checking does not generally make functions
+prettier. But now code that calls <code>between</code> can do something like:</p><pre class="code"><span class="keyword">var</span> <span class="variable">input</span> = <span class="variable">prompt</span>(<span class="string">"Tell me something"</span>, <span class="string">""</span>);
+<span class="keyword">var</span> <span class="variable">parenthesized</span> = <span class="variable">between</span>(<span class="variable">input</span>, <span class="string">"("</span>, <span class="string">")"</span>);
+<span class="keyword">if</span> (<span class="variable">parenthesized</span> != <span class="atom">undefined</span>)
+ <span class="variable">print</span>(<span class="string">"You parenthesized '"</span>, <span class="variable">parenthesized</span>, <span class="string">"'."</span>);</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p60066c2098aade00" name="p60066c2098aade00"> </a>In many cases returning a special value is a perfectly fine way to
+indicate an error. It does, however, have its downsides. Firstly, what
+if the function can already return every possible kind of value? For
+example, consider this function that gets the last element from an
+array:</p><pre class="code"><span class="keyword">function</span> <span class="variable">lastElement</span>(<span class="variabledef">array</span>) {
+ <span class="keyword">if</span> (<span class="localvariable">array</span>.<span class="property">length</span> > <span class="atom">0</span>)
+ <span class="keyword">return</span> <span class="localvariable">array</span>[<span class="localvariable">array</span>.<span class="property">length</span> - <span class="atom">1</span>];
+ <span class="keyword">else</span>
+ <span class="keyword">return</span> <span class="atom">undefined</span>;
+}
+
+<span class="variable">show</span>(<span class="variable">lastElement</span>([<span class="atom">1</span>, <span class="atom">2</span>, <span class="atom">undefined</span>]));</pre><p><a class="paragraph" href="#p25b05ae4df778f0e" name="p25b05ae4df778f0e"> </a>So did the array have a last element? Looking at the value
+<code>lastElement</code> returns, it is impossible to say.</p><p><a class="paragraph" href="#p59d5d030b1223110" name="p59d5d030b1223110"> </a>The second issue with returning special values is that it can
+sometimes lead to a whole lot of clutter. If a piece of code calls
+<code>between</code> ten times, it has to check ten times whether <code>undefined</code> was
+returned. Also, if a function calls <code>between</code> but does not have a
+strategy to recover from a failure, it will have to check the return
+value of <code>between</code>, and if it is <code>undefined</code>, this function can then
+return <code>undefined</code> or some other special value to its caller, who in
+turn also checks for this value.</p><p><a class="paragraph" href="#p2d4a742116a20f7" name="p2d4a742116a20f7"> </a>Sometimes, when something strange occurs, it would be practical to
+just stop doing what we are doing and immediately jump back to a place
+that knows how to handle the problem.</p><p><a class="paragraph" href="#p75820b4abd417475" name="p75820b4abd417475"> </a>Well, we are in luck, a lot of programming languages provide such a
+thing. Usually, it is called <a name="key2"></a>exception handling.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p48d4032291a4063d" name="p48d4032291a4063d"> </a>The theory behind exception handling goes like this: It is possible
+for code to <a name="key3"></a>raise (or <a name="key4"></a>throw) an <a name="key5"></a>exception, which is a value.
+Raising an exception somewhat resembles a super-charged return from a
+function ― it does not just jump out of the current function, but
+also out of its callers, all the way up to the top-level call that
+started the current execution. This is called <a name="key6"></a>unwinding the stack.
+You may remember the <a name="key7"></a>stack of function calls that was mentioned in
+<a href="chapter3.html">chapter 3</a>. An exception zooms down this stack, throwing away all
+the call contexts it encounters.</p><p><a class="paragraph" href="#p577e309ea04ff91d" name="p577e309ea04ff91d"> </a>If they always zoomed right down to the base of the stack, exceptions
+would not be of much use, they would just provide a novel way to blow
+up your program. Fortunately, it is possible to set obstacles for
+exceptions along the stack. These '<a name="key8"></a>catch' the exception as it is
+zooming down, and can do something with it, after which the program
+continues running at the point where the exception was caught.</p><p><a class="paragraph" href="#pd35fda8d169697d" name="pd35fda8d169697d"> </a>An example:</p><pre class="code"><span class="keyword">function</span> <span class="variable">lastElement</span>(<span class="variabledef">array</span>) {
+ <span class="keyword">if</span> (<span class="localvariable">array</span>.<span class="property">length</span> > <span class="atom">0</span>)
+ <span class="keyword">return</span> <span class="localvariable">array</span>[<span class="localvariable">array</span>.<span class="property">length</span> - <span class="atom">1</span>];
+ <span class="keyword">else</span>
+ <span class="keyword">throw</span> <span class="string">"Can not take the last element of an empty array."</span>;
+}
+
+<span class="keyword">function</span> <span class="variable">lastElementPlusTen</span>(<span class="variabledef">array</span>) {
+ <span class="keyword">return</span> <span class="variable">lastElement</span>(<span class="localvariable">array</span>) + <span class="atom">10</span>;
+}
+
+<span class="keyword">try</span> {
+ <span class="variable">print</span>(<span class="variable">lastElementPlusTen</span>([]));
+}
+<span class="keyword">catch</span> (<span class="variabledef">error</span>) {
+ <span class="variable">print</span>(<span class="string">"Something went wrong: "</span>, <span class="localvariable">error</span>);
+}</pre><p><a class="paragraph" href="#p56436d45f8fad659" name="p56436d45f8fad659"> </a><a name="key9"></a><code>throw</code> is the keyword that is used to raise an exception. The
+keyword <a name="key10"></a><code>try</code> sets up an obstacle for exceptions: When the code in
+the block after it raises an exception, the <a name="key11"></a><code>catch</code> block will be
+executed. The variable named in parentheses after the word <code>catch</code> is
+the name given to the exception value inside this block.</p><p><a class="paragraph" href="#p2b53d4284ce191bf" name="p2b53d4284ce191bf"> </a>Note that the function <code>lastElementPlusTen</code> completely ignores the
+possibility that <code>lastElement</code> might go wrong. This is the big
+advantage of exceptions ― error-handling code is only necessary at
+the point where the error occurs, and the point where it is handled.
+The functions in between can forget all about it.</p><p><a class="paragraph" href="#p66b04af462386c28" name="p66b04af462386c28"> </a>Well, almost.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p593204985074522e" name="p593204985074522e"> </a>Consider the following: A function <code>processThing</code> wants to set a
+top-level variable <code>currentThing</code> to point to a specific thing while
+its body executes, so that other functions can have access to that
+thing too. Normally you would of course just pass the thing as an
+argument, but assume for a moment that that is not practical. When the
+function finishes, <code>currentThing</code> should be set back to <code>null</code>.</p><pre class="code"><span class="keyword">var</span> <span class="variable">currentThing</span> = <span class="atom">null</span>;
+
+<span class="keyword">function</span> <span class="variable">processThing</span>(<span class="variabledef">thing</span>) {
+ <span class="keyword">if</span> (<span class="variable">currentThing</span> != <span class="atom">null</span>)
+ <span class="keyword">throw</span> <span class="string">"Oh no! We are already processing a thing!"</span>;
+
+ <span class="variable">currentThing</span> = <span class="localvariable">thing</span>;
+ <span class="comment">/* do complicated processing... */</span>
+ <span class="variable">currentThing</span> = <span class="atom">null</span>;
+}</pre><p><a class="paragraph" href="#p61e6f0e964bfa434" name="p61e6f0e964bfa434"> </a>But what if the complicated processing raises an exception? In that
+case the call to <code>processThing</code> will be thrown off the stack by the
+exception, and <code>currentThing</code> will never be reset to <code>null</code>.</p><p><a class="paragraph" href="#p16204fe3ccdbe7d3" name="p16204fe3ccdbe7d3"> </a><code>try</code> statements can also be followed by a <a name="key12"></a><code>finally</code> keyword, which
+means 'no matter <em>what</em> happens, run this code after trying to run the
+code in the <code>try</code> block'. If a function has to clean something up, the
+cleanup code should usually be put into a <code>finally</code> block:</p><pre class="code"><span class="keyword">function</span> <span class="variable">processThing</span>(<span class="variabledef">thing</span>) {
+ <span class="keyword">if</span> (<span class="variable">currentThing</span> != <span class="atom">null</span>)
+ <span class="keyword">throw</span> <span class="string">"Oh no! We are already processing a thing!"</span>;
+
+ <span class="variable">currentThing</span> = <span class="localvariable">thing</span>;
+ <span class="keyword">try</span> {
+ <span class="comment">/* do complicated processing... */</span>
+ }
+ <span class="keyword">finally</span> {
+ <span class="variable">currentThing</span> = <span class="atom">null</span>;
+ }
+}</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p61c863902bde0b98" name="p61c863902bde0b98"> </a>A lot of errors in programs cause the JavaScript environment to raise
+an exception. For example:</p><pre class="code"><span class="keyword">try</span> {
+ <span class="variable">print</span>(<span class="variable">Sasquatch</span>);
+}
+<span class="keyword">catch</span> (<span class="variabledef">error</span>) {
+ <span class="variable">print</span>(<span class="string">"Caught: "</span> + <span class="localvariable">error</span>.<span class="property">message</span>);
+}</pre><p><a class="paragraph" href="#p2fc14e19e1879089" name="p2fc14e19e1879089"> </a>In cases like this, special error objects are raised. These always
+have a <code>message</code> property containing a description of the problem. You
+can raise similar objects using the <code>new</code> keyword and the <a name="key13"></a><code>Error</code>
+constructor:</p><pre class="code"><span class="keyword">throw</span> <span class="keyword">new</span> <span class="variable">Error</span>(<span class="string">"Fire!"</span>);</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p663e29c2fc3163a1" name="p663e29c2fc3163a1"> </a>When an exception goes all the way to the bottom of the stack without
+being caught, it gets handled by the environment. What this means
+differs between the different browsers, sometimes a description of the
+error is written to some kind of log, sometimes a window pops up
+describing the error.</p><p><a class="paragraph" href="#p79ca4f9b2f4c2a81" name="p79ca4f9b2f4c2a81"> </a>The errors produced by entering code in the console on this page are
+always caught by the console, and displayed among the other output.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p6f4a56186561ecaa" name="p6f4a56186561ecaa"> </a>Most programmers consider exceptions purely an error-handling
+mechanism. In essence, though, they are just another way of
+influencing the control flow of a program. For example, they can be
+used as a kind of <code>break</code> statement in a recursive function. Here is a
+slightly strange function which determines whether an object, and the
+objects stored inside it, contain at least seven <code>true</code> values:</p><pre class="code"><span class="keyword">var</span> <span class="variable">FoundSeven</span> = {};
+
+<span class="keyword">function</span> <span class="variable">hasSevenTruths</span>(<span class="variabledef">object</span>) {
+ <span class="keyword">var</span> <span class="variabledef">counted</span> = <span class="atom">0</span>;
+
+ <span class="keyword">function</span> <span class="variabledef">count</span>(<span class="variabledef">object</span>) {
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variabledef">name</span> <span class="keyword">in</span> <span class="localvariable">object</span>) {
+ <span class="keyword">if</span> (<span class="localvariable">object</span>[<span class="localvariable">name</span>] === <span class="atom">true</span>) {
+ <span class="localvariable">counted</span>++;
+ <span class="keyword">if</span> (<span class="localvariable">counted</span> == <span class="atom">7</span>)
+ <span class="keyword">throw</span> <span class="variable">FoundSeven</span>;
+ }
+ <span class="keyword">else</span> <span class="keyword">if</span> (typeof <span class="localvariable">object</span>[<span class="localvariable">name</span>] == <span class="string">"object"</span>) {
+ <span class="localvariable">count</span>(<span class="localvariable">object</span>[<span class="localvariable">name</span>]);
+ }
+ }
+ }
+
+ <span class="keyword">try</span> {
+ <span class="localvariable">count</span>(<span class="localvariable">object</span>);
+ <span class="keyword">return</span> <span class="atom">false</span>;
+ }
+ <span class="keyword">catch</span> (<span class="variabledef">exception</span>) {
+ <span class="keyword">if</span> (<span class="localvariable">exception</span> != <span class="variable">FoundSeven</span>)
+ <span class="keyword">throw</span> <span class="localvariable">exception</span>;
+ <span class="keyword">return</span> <span class="atom">true</span>;
+ }
+}</pre><p><a class="paragraph" href="#p478fb7ee5eac6383" name="p478fb7ee5eac6383"> </a>The inner function <code>count</code> is recursively called for every object that
+is part of the argument. When the variable <code>counted</code> reaches seven,
+there is no point in continuing to count, but just returning from the
+current call to <code>count</code> will not necessarily stop the counting, since
+there might be more calls below it. So what we do is just throw a
+value, which will cause the control to jump right out of any calls to
+<code>count</code>, and land at the <code>catch</code> block.</p><p><a class="paragraph" href="#p770a470bd00d3706" name="p770a470bd00d3706"> </a>But just returning <code>true</code> in case of an exception is not correct.
+Something else might be going wrong, so we first check whether the
+exception is the object <code>FoundSeven</code>, created specifically for this
+purpose. If it is not, this <code>catch</code> block does not know how to handle
+it, so it raises it again.</p><p><a class="paragraph" href="#p1040256860b43e79" name="p1040256860b43e79"> </a>This is a pattern that is also common when dealing with error
+conditions ― you have to make sure that your <code>catch</code> block only
+handles exceptions that it knows how to handle. Throwing string
+values, as some of the examples in this chapter do, is rarely a good
+idea, because it makes it hard to recognise the type of the exception.
+A better idea is to use unique values, such as the <code>FoundSeven</code>
+object, or to introduce a new type of objects, as described in <a href="chapter8.html">chapter 8</a>.</p></div><h1><span class="number">Chapter 6: </span>Functional Programming</h1><div class="block"><p><a class="paragraph" href="#p406bc0550dba7201" name="p406bc0550dba7201"> </a>As programs get bigger, they also become more complex and harder to
+understand. We all think ourselves pretty clever, of course, but we
+are mere human beings, and even a moderate amount of chaos tends to
+baffle us. And then it all goes downhill. Working on something you do
+not really understand is a bit like cutting random wires on those
+time-activated bombs they always have in movies. If you are lucky, you
+might get the right one ― especially if you are the hero of the movie
+and strike a suitably dramatic pose ― but there is always the
+possibility of blowing everything up.</p><p><a class="paragraph" href="#p61d9c58b7ccd55b" name="p61d9c58b7ccd55b"> </a>Admittedly, in most cases, breaking a program does not cause any large
+explosions. But when a program, by someone's ignorant tinkering, has
+degenerated into a ramshackle mass of errors, reshaping it into
+something sensible is a terrible labour ― sometimes you might just as
+well start over.</p><p><a class="paragraph" href="#pe323e5622f00be3" name="pe323e5622f00be3"> </a><a name="key1"></a>Thus, the programmer is always looking for ways to keep
+the complexity of his programs as low as possible. An important way to
+do this is to try and make code more abstract. When writing a program,
+it is easy to get sidetracked into small details at every point. You
+come across some little issue, and you deal with it, and then proceed
+to the next little problem, and so on. This makes the code read like a
+grandmother's tale.</p><blockquote>Yes, dear, to make pea soup you will need split peas, the dry kind.
+And you have to soak them at least for a night, or you will have to
+cook them for hours and hours. I remember one time, when my dull son
+tried to make pea soup. Would you believe he hadn't soaked the peas?
+We almost broke our teeth, all of us. Anyway, when you have soaked
+the peas, and you'll want about a cup of them per person, and pay
+attention because they will expand a bit while they are soaking, so
+if you aren't careful they will spill out of whatever you use to
+hold them, so also use plenty water to soak in, but as I said, about
+a cup of them, when they are dry, and after they are soaked you cook
+them in four cups of water per cup of dry peas. Let it simmer for
+two hours, which means you cover it and keep it barely cooking, and
+then add some diced onions, sliced celery stalk, and maybe a carrot
+or two and some ham. Let it all cook for a few minutes more, and it
+is ready to eat.</blockquote><p><a class="paragraph" href="#p2f9bf5e014dcdc06" name="p2f9bf5e014dcdc06"> </a>Another way to describe this recipe:</p><blockquote>Per person: one cup dried split peas, half a chopped onion, half a
+carrot, a celery stalk, and optionally ham.<br/><br/>Soak peas overnight, simmer them for two hours in four cups of water
+(per person), add vegetables and ham, and cook for ten more minutes.</blockquote><p><a class="paragraph" href="#p4abdc642ee7bc293" name="p4abdc642ee7bc293"> </a>This is shorter, but if you don't know how to soak peas you'll surely
+screw up and put them in too little water. But how to soak peas can be
+looked up, and that is the trick. If you assume a certain basic
+knowledge in the audience, you can talk in a language that deals with
+bigger concepts, and express things in a much shorter and clearer way.
+This, more or less, is what abstraction is.</p><p><a class="paragraph" href="#p2bfd98498baedead" name="p2bfd98498baedead"> </a>How is this far-fetched recipe story relevant to programming? Well,
+obviously, the recipe is the program. Furthermore, the basic knowledge
+that the cook is supposed to have corresponds to the functions and
+other constructs that are available to the programmer. If you remember
+the introduction of this book, things like <code>while</code> make it easier to
+build loops, and in <a href="chapter4.html">chapter 4</a> we wrote some simple functions in order to
+make other functions shorter and more straightforward. Such tools,
+some of them made available by the language itself, others built by
+the programmer, are used to reduce the amount of uninteresting details
+in the rest of the program, and thus make that program easier to work
+with.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p1029fd844bd24fc8" name="p1029fd844bd24fc8"> </a><a name="key2"></a>Functional programming, which is the subject
+of this chapter, produces abstraction through clever ways of combining
+functions. A programmer armed with a repertoire of fundamental
+functions and, more importantly, the knowledge on how to use them, is
+much more effective than one who starts from scratch. Unfortunately, a
+standard JavaScript environment comes with deplorably few essential
+functions, so we have to write them ourselves or, which is often
+preferable, make use of somebody else's code (more on that in
+<a href="chapter9.html">chapter 9</a>).</p><p><a class="paragraph" href="#p5b2b16eeb6c201d1" name="p5b2b16eeb6c201d1"> </a>There are other popular approaches to abstraction, most notably
+object-oriented programming, the subject of <a href="chapter8.html">chapter 8</a>.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p755f4be241af5b12" name="p755f4be241af5b12"> </a>One ugly detail that, if you have any good taste at all, must be
+starting to bother you is the endlessly repeated <code>for</code> loop going over
+an array: <code>for (var i = 0; i < something.length; i++) ...</code>. Can this
+be abstracted?</p><p><a class="paragraph" href="#p6dce7810233c1f28" name="p6dce7810233c1f28"> </a>The problem is that, whereas most functions just take some values,
+combine them, and return something, such a loop contains a piece of
+code that it must execute. It is easy to write a function that goes
+over an array and prints out every element:</p><pre class="code"><span class="keyword">function</span> <span class="variable">printArray</span>(<span class="variabledef">array</span>) {
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variabledef">i</span> = <span class="atom">0</span>; <span class="localvariable">i</span> < <span class="localvariable">array</span>.<span class="property">length</span>; <span class="localvariable">i</span>++)
+ <span class="variable">print</span>(<span class="localvariable">array</span>[<span class="localvariable">i</span>]);
+}</pre><p><a class="paragraph" href="#p5e43c3fda6edbd78" name="p5e43c3fda6edbd78"> </a>But what if we want to do something else than print? Since 'doing
+something' can be represented as a function, and functions are also
+values, we can pass our action as a function value:</p><pre class="code"><span class="keyword">function</span> <span class="variable">forEach</span>(<span class="variabledef">array</span>, <span class="variabledef">action</span>) {
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variabledef">i</span> = <span class="atom">0</span>; <span class="localvariable">i</span> < <span class="localvariable">array</span>.<span class="property">length</span>; <span class="localvariable">i</span>++)
+ <span class="localvariable">action</span>(<span class="localvariable">array</span>[<span class="localvariable">i</span>]);
+}
+
+<span class="variable">forEach</span>([<span class="string">"Wampeter"</span>, <span class="string">"Foma"</span>, <span class="string">"Granfalloon"</span>], <span class="variable">print</span>);</pre><p><a class="paragraph" href="#p5c6ce2b695bd142d" name="p5c6ce2b695bd142d"> </a>And by making use of an anonymous function, something just like a
+<code>for</code> loop can be written with less useless details:</p><pre class="code"><span class="keyword">function</span> <span class="variable">sum</span>(<span class="variabledef">numbers</span>) {
+ <span class="keyword">var</span> <span class="variabledef">total</span> = <span class="atom">0</span>;
+ <span class="variable">forEach</span>(<span class="localvariable">numbers</span>, <span class="keyword">function</span> (<span class="variabledef">number</span>) {
+ <span class="localvariable">total</span> += <span class="localvariable">number</span>;
+ });
+ <span class="keyword">return</span> <span class="localvariable">total</span>;
+}
+<span class="variable">show</span>(<span class="variable">sum</span>([<span class="atom">1</span>, <span class="atom">10</span>, <span class="atom">100</span>]));</pre><p><a class="paragraph" href="#p22480fe89f06c197" name="p22480fe89f06c197"> </a>Note that the variable <code>total</code> is visible inside the anonymous
+function because of the lexical scoping rules. Also note that this
+version is hardly shorter than the <code>for</code> loop and requires a rather
+clunky <code>});</code> at its end ― the brace closes the body of the anonymous
+function, the parenthesis closes the function call to <a name="key3"></a><code>forEach</code>, and
+the semicolon is needed because this call is a statement.</p><p><a class="paragraph" href="#p58553fdda22a0049" name="p58553fdda22a0049"> </a>You do get a variable bound to the current element in the array,
+<code>number</code>, so there is no need to use <code>numbers[i]</code> anymore, and when
+this array is created by evaluating some expression, there is no need
+to store it in a variable, because it can be passed to <code>forEach</code>
+directly.</p><p><a class="paragraph" href="#p551f69c843687e97" name="p551f69c843687e97"> </a>The cat-code in <a href="chapter4.html">chapter 4</a> contains a piece like this:</p><pre class="preformatted">var paragraphs = mailArchive[mail].split("\n");
+for (var i = 0; i < paragraphs.length; i++)
+ handleParagraph(paragraphs[i]);</pre><p><a class="paragraph" href="#pffb217033b4c9e0" name="pffb217033b4c9e0"> </a>This can now be written as...</p><pre class="preformatted">forEach(mailArchive[mail].split("\n"), handleParagraph);</pre><p><a class="paragraph" href="#p75cea5d2d73e38c4" name="p75cea5d2d73e38c4"> </a>On the whole, using more abstract (or 'higher level') constructs
+results in more information and less noise: The code in <code>sum</code> reads
+'<em>for each number in numbers add that number to the total</em>', instead
+of... '<em>there is this variable that starts at zero, and it counts
+upward to the length of the array called numbers, and for every value
+of this variable we look up the corresponding element in the array and
+add this to the total</em>'.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p177cb39381c8ab4" name="p177cb39381c8ab4"> </a>What <code>forEach</code> does is take an algorithm, in this case 'going over an
+array', and abstract it. The 'gaps' in the algorithm, in this case,
+what to do for each of these elements, are filled by functions which
+are passed to the algorithm function.</p><p><a class="paragraph" href="#p3d4f511f55eb429c" name="p3d4f511f55eb429c"> </a>Functions that operate on other functions are called <a name="key4"></a>higher-order
+functions. By operating on functions, they can talk about actions on
+a whole new level. The <code>makeAddFunction</code> function from <a href="chapter3.html">chapter 3</a> is
+also a higher-order function. Instead of taking a function value as an
+argument, it produces a new function.</p><p><a class="paragraph" href="#p95f3cd5d57a5d96" name="p95f3cd5d57a5d96"> </a>Higher-order functions can be used to generalise many algorithms that
+regular functions can not easily describe. When you have a repertoire
+of these functions at your disposal, it can help you think about your
+code in a clearer way: Instead of a messy set of variables and loops,
+you can decompose algorithms into a combination of a few fundamental
+algorithms, which are invoked by name, and do not have to be typed out
+again and again.</p><p><a class="paragraph" href="#p5541a4757333b993" name="p5541a4757333b993"> </a>Being able to write <em>what</em> we want to do instead of <em>how</em> we do it
+means we are working at a higher level of abstraction. In practice,
+this means shorter, clearer, and more pleasant code.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p59860b27992bc7e4" name="p59860b27992bc7e4"> </a>Another useful type of higher-order function <em>modifies</em> the function
+value it is given:</p><pre class="code"><span class="keyword">function</span> <span class="variable">negate</span>(<span class="variabledef">func</span>) {
+ <span class="keyword">return</span> <span class="keyword">function</span>(<span class="variabledef">x</span>) {
+ <span class="keyword">return</span> !<span class="localvariable">func</span>(<span class="localvariable">x</span>);
+ };
+}
+<span class="keyword">var</span> <span class="variable">isNotNaN</span> = <span class="variable">negate</span>(<span class="variable">isNaN</span>);
+<span class="variable">show</span>(<span class="variable">isNotNaN</span>(<span class="atom">NaN</span>));</pre><p><a class="paragraph" href="#p6604314a4be645ae" name="p6604314a4be645ae"> </a>The function returned by <code>negate</code> feeds the argument it is given to
+the original function <code>func</code>, and then negates the result. But what if
+the function you want to negate takes more than one argument? You can
+get access to any arguments passed to a function with the <code>arguments</code>
+array, but how do you call a function when you do not know how many
+arguments you have?</p><p><a class="paragraph" href="#p254e0cc081a6d7df" name="p254e0cc081a6d7df"> </a>Functions have a method called <a name="key5"></a><code>apply</code>, which is used for situations
+like this. It takes two arguments. The role of the first argument will
+be discussed in <a href="chapter8.html">chapter 8</a>, for now we just use <code>null</code> there. The second
+argument is an array containing the arguments that the function must
+be applied to.</p><pre class="code"><span class="variable">show</span>(<span class="variable">Math</span>.<span class="property">min</span>.<span class="property">apply</span>(<span class="atom">null</span>, [<span class="atom">5</span>, <span class="atom">6</span>]));
+
+<span class="keyword">function</span> <span class="variable">negate</span>(<span class="variabledef">func</span>) {
+ <span class="keyword">return</span> <span class="keyword">function</span>() {
+ <span class="keyword">return</span> !<span class="localvariable">func</span>.<span class="property">apply</span>(<span class="atom">null</span>, <span class="localvariable">arguments</span>);
+ };
+}</pre><p><a class="paragraph" href="#p4cbc103f8e1c6a70" name="p4cbc103f8e1c6a70"> </a>Unfortunately, on the Internet Explorer browser a lot of built-in
+functions, such as <code>alert</code>, are not <em>really</em> functions... or
+something. They report their type as <code>"object"</code> when given to the
+<code>typeof</code> operator, and they do not have an <code>apply</code> method. Your own
+functions do not suffer from this, they are always real functions.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p43bea35b65e9846c" name="p43bea35b65e9846c"> </a>Let us look at a few more basic algorithms related to arrays. The
+<code>sum</code> function is really a variant of an algorithm which is usually
+called <a name="key6"></a><code>reduce</code> or <code>fold</code>:</p><pre class="code"><span class="keyword">function</span> <span class="variable">reduce</span>(<span class="variabledef">combine</span>, <span class="variabledef">base</span>, <span class="variabledef">array</span>) {
+ <span class="variable">forEach</span>(<span class="localvariable">array</span>, <span class="keyword">function</span> (<span class="variabledef">element</span>) {
+ <span class="localvariable">base</span> = <span class="localvariable">combine</span>(<span class="localvariable">base</span>, <span class="localvariable">element</span>);
+ });
+ <span class="keyword">return</span> <span class="localvariable">base</span>;
+}
+
+<span class="keyword">function</span> <span class="variable">add</span>(<span class="variabledef">a</span>, <span class="variabledef">b</span>) {
+ <span class="keyword">return</span> <span class="localvariable">a</span> + <span class="localvariable">b</span>;
+}
+
+<span class="keyword">function</span> <span class="variable">sum</span>(<span class="variabledef">numbers</span>) {
+ <span class="keyword">return</span> <span class="variable">reduce</span>(<span class="variable">add</span>, <span class="atom">0</span>, <span class="localvariable">numbers</span>);
+}</pre><p><a class="paragraph" href="#p3a26d72d5d539372" name="p3a26d72d5d539372"> </a><code>reduce</code> combines an array into a single value by repeatedly using a
+function that combines an element of the array with a base value. This
+is exactly what <code>sum</code> did, so it can be made shorter by using
+<code>reduce</code>... except that addition is an operator and not a function in
+JavaScript, so we first had to put it into a function.</p><p><a class="paragraph" href="#p1e327ea6dfd8d5a9" name="p1e327ea6dfd8d5a9"> </a>The reason <code>reduce</code> takes the function as its first argument instead
+of its last, as in <code>forEach</code>, is partly that this is tradition ―
+other languages do it like that ― and partly that this allows us to
+use a particular trick, which will be discussed at the end of this
+chapter. It does mean that, when calling <code>reduce</code>, writing the
+reducing function as an anonymous function looks a bit weirder,
+because now the other arguments follow after the function, and the
+resemblance to a normal <code>for</code> block is lost entirely.</p></div><hr/><div class="block"><a name="exercise1"></a><div class="exercisenum">Ex. 6.1</div><div class="exercise"><p><a class="paragraph" href="#p60c55bb8b0ec0f52" name="p60c55bb8b0ec0f52"> </a>Write a function <code>countZeroes</code>, which takes an array of numbers as its
+argument and returns the amount of zeroes that occur in it. Use
+<code>reduce</code>.</p><p><a class="paragraph" href="#pc668a5d771065b3" name="pc668a5d771065b3"> </a>Then, write the higher-order function <code>count</code>, which takes an array
+and a test function as arguments, and returns the amount of elements
+in the array for which the test function returned <code>true</code>. Re-implement
+<code>countZeroes</code> using this function.</p></div><div class="solution"><pre class="code"><span class="keyword">function</span> <span class="variable">countZeroes</span>(<span class="variabledef">array</span>) {
+ <span class="keyword">function</span> <span class="variabledef">counter</span>(<span class="variabledef">total</span>, <span class="variabledef">element</span>) {
+ <span class="keyword">return</span> <span class="localvariable">total</span> + (<span class="localvariable">element</span> === <span class="atom">0</span> ? <span class="atom">1</span> : <span class="atom">0</span>);
+ }
+ <span class="keyword">return</span> <span class="variable">reduce</span>(<span class="localvariable">counter</span>, <span class="atom">0</span>, <span class="localvariable">array</span>);
+}</pre><p><a class="paragraph" href="#p543f21adae0dab0c" name="p543f21adae0dab0c"> </a><a name="key7"></a>The weird part, with the question mark and the colon, uses a
+new operator. In <a href="chapter2.html">chapter 2</a> we have seen unary and binary operators.
+This one is ternary ― it acts on three values. Its effect resembles
+that of <code>if</code>/<code>else</code>, except that, where <code>if</code> conditionally executes
+statements, this one conditionally chooses expressions. The first
+part, before the question mark, is the condition. If this condition is
+<code>true</code>, the expression after the question mark is chosen, <code>1</code> in this
+case. If it is <code>false</code>, the part after the colon, <code>0</code> in this case, is
+chosen.</p><p><a class="paragraph" href="#p588c930c925024a1" name="p588c930c925024a1"> </a>Use of this operator can make some pieces of code much shorter. When
+the expressions inside it get very big, or you have to make more
+decisions inside the conditional parts, just using plain <code>if</code> and
+<code>else</code> is usually more readable.</p><p><a class="paragraph" href="#p29cfd0dde807fe3b" name="p29cfd0dde807fe3b"> </a>Here is the solution that uses a <code>count</code> function, with a function
+that produces equality-testers included to make the final
+<code>countZeroes</code> function even shorter:</p><pre class="code"><span class="keyword">function</span> <span class="variable">count</span>(<span class="variabledef">test</span>, <span class="variabledef">array</span>) {
+ <span class="keyword">return</span> <span class="variable">reduce</span>(<span class="keyword">function</span>(<span class="variabledef">total</span>, <span class="variabledef">element</span>) {
+ <span class="keyword">return</span> <span class="localvariable">total</span> + (<span class="localvariable">test</span>(<span class="localvariable">element</span>) ? <span class="atom">1</span> : <span class="atom">0</span>);
+ }, <span class="atom">0</span>, <span class="localvariable">array</span>);
+}
+
+<span class="keyword">function</span> <span class="variable">equals</span>(<span class="variabledef">x</span>) {
+ <span class="keyword">return</span> <span class="keyword">function</span>(<span class="variabledef">element</span>) {<span class="keyword">return</span> <span class="localvariable">x</span> === <span class="localvariable">element</span>;};
+}
+
+<span class="keyword">function</span> <span class="variable">countZeroes</span>(<span class="variabledef">array</span>) {
+ <span class="keyword">return</span> <span class="variable">count</span>(<span class="variable">equals</span>(<span class="atom">0</span>), <span class="localvariable">array</span>);
+}</pre></div></div><hr/><div class="block"><p><a class="paragraph" href="#p487fc5acce55439c" name="p487fc5acce55439c"> </a>One other generally useful 'fundamental algorithm' related to arrays
+is called <a name="key8"></a><code>map</code>. It goes over an array, applying a function to every
+element, just like <code>forEach</code>. But instead of discarding the values
+returned by function, it builds up a new array from these values.</p><pre class="code"><span class="keyword">function</span> <span class="variable">map</span>(<span class="variabledef">func</span>, <span class="variabledef">array</span>) {
+ <span class="keyword">var</span> <span class="variabledef">result</span> = [];
+ <span class="variable">forEach</span>(<span class="localvariable">array</span>, <span class="keyword">function</span> (<span class="variabledef">element</span>) {
+ <span class="localvariable">result</span>.<span class="property">push</span>(<span class="localvariable">func</span>(<span class="localvariable">element</span>));
+ });
+ <span class="keyword">return</span> <span class="localvariable">result</span>;
+}
+
+<span class="variable">show</span>(<span class="variable">map</span>(<span class="variable">Math</span>.<span class="property">round</span>, [<span class="atom">0.01</span>, <span class="atom">2</span>, <span class="atom">9.89</span>, <span class="variable">Math</span>.<span class="property">PI</span>]));</pre><p><a class="paragraph" href="#pfbaec59a02a1d15" name="pfbaec59a02a1d15"> </a>Note that the first argument is called <code>func</code>, not <code>function</code>, this
+is because <code>function</code> is a keyword and thus not a valid variable name.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p72845d53f6f05268" name="p72845d53f6f05268"> </a>There once was, living in the deep mountain forests of Transylvania, a
+recluse. Most of the time, he just wandered around his mountain,
+talking to trees and laughing with birds. But now and then, when the
+pouring rain trapped him in his little hut, and the howling wind made
+him feel unbearably small, the recluse felt an urge to write
+something, wanted to pour some thoughts out onto paper, where they
+could maybe grow bigger than he himself was.</p><p><a class="paragraph" href="#p518bcf1e2791bb49" name="p518bcf1e2791bb49"> </a>After failing miserably at poetry, fiction, and philosophy, the
+recluse finally decided to write a technical book. In his youth, he
+had done some computer programming, and he figured that if he could
+just write a good book about that, fame and recognition would surely
+follow.</p><p><a class="paragraph" href="#p4838ad8fb26c0acd" name="p4838ad8fb26c0acd"> </a>So he wrote. At first he used fragments of tree bark, but that turned
+out not to be very practical. He went down to the nearest village and
+bought himself a laptop computer. After a few chapters, he realised he
+wanted to put the book in HTML format, in order to put it on his
+web-page...</p></div><hr/><div class="block"><p><a class="paragraph" href="#p6f89de8af6edd388" name="p6f89de8af6edd388"> </a>Are you familiar with HTML? It is the method used to add mark-up to
+pages on the web, and we will be using it a few times in this book, so
+it would be nice if you know how it works, at least generally. If you
+are a good student, you could go search the web for a good
+introduction to HTML now, and come back here when you have read it.
+Most of you probably are lousy students, so I will just give a short
+explanation and hope it is enough.</p><p><a class="paragraph" href="#p5595eff2a86b5d87" name="p5595eff2a86b5d87"> </a><a name="key9"></a>HTML stands for 'HyperText Mark-up Language'. An HTML document is
+all text. Because it must be able to express the structure of this
+text, information about which text is a heading, which text is purple,
+and so on, a few characters have a special meaning, somewhat like
+backslashes in JavaScript strings. The 'less than' and 'greater than'
+characters are used to create '<a name="key10"></a>tags'. A tag gives extra information
+about the text in the document. It can stand on its own, for example
+to mark the place where a picture should appear in the page, or it can
+contain text and other tags, for example when it marks the start and
+end of a paragraph.</p><p><a class="paragraph" href="#p28225fb69550a84c" name="p28225fb69550a84c"> </a>Some tags are compulsory, a whole HTML document must always be
+contained in between <code>html</code> tags. Here is an example of an HTML
+document:</p><pre class="preformatted"><html>
+ <head>
+ <title>A quote</title>
+ </head>
+ <body>
+ <h1>A quote</h1>
+ <blockquote>
+ <p>The connection between the language in which we
+ think/program and the problems and solutions we can imagine
+ is very close. For this reason restricting language
+ features with the intent of eliminating programmer errors is
+ at best dangerous.</p>
+ <p>-- Bjarne Stroustrup</p>
+ </blockquote>
+ <p>Mr. Stroustrup is the inventor of the C++ programming
+ language, but quite an insightful person nevertheless.</p>
+ <p>Also, here is a picture of an ostrich:</p>
+ <img src="img/ostrich.png"/>
+ </body>
+</html></pre><p><a class="paragraph" href="#p23bb63064e929324" name="p23bb63064e929324"> </a>Elements that contain text or other tags are first opened with
+<code><tagname></code>, and afterwards finished with <code></tagname></code>. The <code>html</code>
+element always contains two children: <code>head</code> and <code>body</code>. The first
+contains information <em>about</em> the document, the second contains the
+actual document.</p><p><a class="paragraph" href="#p6e09739d3bcd5a53" name="p6e09739d3bcd5a53"> </a>Most tag names are cryptic abbreviations. <code>h1</code> stands for 'heading 1',
+the biggest kind of heading. There are also <code>h2</code> to <code>h6</code> for
+successively smaller headings. <code>p</code> means 'paragraph', and <code>img</code> stands
+for 'image'. The <code>img</code> element does not contain any text or other
+tags, but it does have some extra information,
+<code>src="img/ostrich.png"</code>, which is called an '<a name="key11"></a>attribute'. In this
+case, it contains information about the image file that should be
+shown here.</p><p><a class="paragraph" href="#p61592ab96ad6b347" name="p61592ab96ad6b347"> </a>Because <code><</code> and <code>></code> have a special meaning in HTML documents, they can
+not be written directly in the text of the document. If you want to
+say '<code>5 < 10</code>' in an HTML document, you have to write '<code>5 &lt; 10</code>',
+where '<code>lt</code>' stands for 'less than'. '<code>&gt;</code>' is used for '<code>></code>', and
+because these codes also give the ampersand character a special
+meaning, a plain '<code>&</code>' is written as '<code>&amp;</code>'.</p><p><a class="paragraph" href="#p62a06dc7ccbbe1d4" name="p62a06dc7ccbbe1d4"> </a>Now, those are only the bare basics of HTML, but they should be enough
+to make it through this chapter, and later chapters that deal with
+HTML documents, without getting entirely confused.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p18cbb1fe1ccd441e" name="p18cbb1fe1ccd441e"> </a>The JavaScript console has a function <code>viewHTML</code> that can be used to
+look at HTML documents. I stored the example document above in the
+variable <code>stroustrupQuote</code>, so you can view it by executing the
+following code:</p><pre class="code"><span class="variable">viewHTML</span>(<span class="variable">stroustrupQuote</span>);</pre><p><a class="paragraph" href="#p44328054845e46ab" name="p44328054845e46ab"> </a>If you have some kind of pop-up blocker installed or integrated in
+your browser, it will probably interfere with <code>viewHTML</code>, which tries
+to show the HTML document in a new window or tab. Try to configure the
+blocker to allow pop-ups from this site.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p15c5e14addbc1388" name="p15c5e14addbc1388"> </a>So, picking up the story again, the recluse wanted to have his book in
+HTML format. At first he just wrote all the tags directly into his
+manuscript, but typing all those less-than and greater-than signs made
+his fingers hurt, and he constantly forgot to write <code>&amp;</code> when he
+needed an <code>&</code>. This gave him a headache. Next, he tried to write the
+book in Microsoft Word, and then save it as HTML. But the HTML that
+came out of that was fifteen times bigger and more complicated than it
+had to be. And besides, Microsoft Word gave him a headache.</p><p><a class="paragraph" href="#p1156d30627166a36" name="p1156d30627166a36"> </a>The solution that he eventually came up with was this: He would write
+the book as plain text, following some simple rules about the way
+paragraphs were separated and the way headings looked. Then, he would
+write a program to convert this text into precisely the HTML that he
+wanted.</p><p><a class="paragraph" href="#p231e5049ecd8f592" name="p231e5049ecd8f592"> </a>The rules are this:</p><ol><li>Paragraphs are separated by blank lines.</li><li>A paragraph that starts with a '%' symbol is a header. The more '%' symbols, the smaller the header.</li><li>Inside paragraphs, pieces of text can be emphasised by putting them between asterisks.</li><li>Footnotes are written between braces.</li></ol></div><hr/><div class="block"><p><a class="paragraph" href="#p7427e734fe433eef" name="p7427e734fe433eef"> </a>After he had struggled painfully with his book for six months, the
+recluse had still only finished a few paragraphs. At this point, his
+hut was struck by lightning, killing him, and forever putting his
+writing ambitions to rest. From the charred remains of his laptop, I
+could recover the following file:</p><pre class="preformatted">% The Book of Programming
+
+%% The Two Aspects
+
+Below the surface of the machine, the program moves. Without effort,
+it expands and contracts. In great harmony, electrons scatter and
+regroup. The forms on the monitor are but ripples on the water. The
+essence stays invisibly below.
+
+When the creators built the machine, they put in the processor and the
+memory. From these arise the two aspects of the program.
+
+The aspect of the processor is the active substance. It is called
+Control. The aspect of the memory is the passive substance. It is
+called Data.
+
+Data is made of merely bits, yet it takes complex forms. Control
+consists only of simple instructions, yet it performs difficult
+tasks. From the small and trivial, the large and complex arise.
+
+The program source is Data. Control arises from it. The Control
+proceeds to create new Data. The one is born from the other, the
+other is useless without the one. This is the harmonious cycle of
+Data and Control.
+
+Of themselves, Data and Control are without structure. The programmers
+of old moulded their programs out of this raw substance. Over time,
+the amorphous Data has crystallised into data types, and the chaotic
+Control was restricted into control structures and functions.
+
+%% Short Sayings
+
+When a student asked Fu-Tzu about the nature of the cycle of Data and
+Control, Fu-Tzu replied 'Think of a compiler, compiling itself.'
+
+A student asked 'The programmers of old used only simple machines and
+no programming languages, yet they made beautiful programs. Why do we
+use complicated machines and programming languages?'. Fu-Tzu replied
+'The builders of old used only sticks and clay, yet they made
+beautiful huts.'
+
+A hermit spent ten years writing a program. 'My program can compute
+the motion of the stars on a 286-computer running MS DOS', he proudly
+announced. 'Nobody owns a 286-computer or uses MS DOS anymore.',
+Fu-Tzu responded.
+
+Fu-Tzu had written a small program that was full of global state and
+dubious shortcuts. Reading it, a student asked 'You warned us against
+these techniques, yet I find them in your program. How can this be?'
+Fu-Tzu said 'There is no need to fetch a water hose when the house is
+not on fire.'{This is not to be read as an encouragement of sloppy
+programming, but rather as a warning against neurotic adherence to
+rules of thumb.}
+
+%% Wisdom
+
+A student was complaining about digital numbers. 'When I take the root
+of two and then square it again, the result is already inaccurate!'.
+Overhearing him, Fu-Tzu laughed. 'Here is a sheet of paper. Write down
+the precise value of the square root of two for me.'
+
+Fu-Tzu said 'When you cut against the grain of the wood, much strength
+is needed. When you program against the grain of a problem, much code
+is needed.'
+
+Tzu-li and Tzu-ssu were boasting about the size of their latest
+programs. 'Two-hundred thousand lines', said Tzu-li, 'not counting
+comments!'. 'Psah', said Tzu-ssu, 'mine is almost a *million* lines
+already.' Fu-Tzu said 'My best program has five hundred lines.'
+Hearing this, Tzu-li and Tzu-ssu were enlightened.
+
+A student had been sitting motionless behind his computer for hours,
+frowning darkly. He was trying to write a beautiful solution to a
+difficult problem, but could not find the right approach. Fu-Tzu hit
+him on the back of his head and shouted '*Type something!*' The student
+started writing an ugly solution. After he had finished, he suddenly
+understood the beautiful solution.
+
+%% Progression
+
+A beginning programmer writes his programs like an ant builds her
+hill, one piece at a time, without thought for the bigger structure.
+His programs will be like loose sand. They may stand for a while, but
+growing too big they fall apart{Referring to the danger of internal
+inconsistency and duplicated structure in unorganised code.}.
+
+Realising this problem, the programmer will start to spend a lot of
+time thinking about structure. His programs will be rigidly
+structured, like rock sculptures. They are solid, but when they must
+change, violence must be done to them{Referring to the fact that
+structure tends to put restrictions on the evolution of a program.}.
+
+The master programmer knows when to apply structure and when to leave
+things in their simple form. His programs are like clay, solid yet
+malleable.
+
+%% Language
+
+When a programming language is created, it is given syntax and
+semantics. The syntax describes the form of the program, the semantics
+describe the function. When the syntax is beautiful and the semantics
+are clear, the program will be like a stately tree. When the syntax is
+clumsy and the semantics confusing, the program will be like a bramble
+bush.
+
+Tzu-ssu was asked to write a program in the language called Java,
+which takes a very primitive approach to functions. Every morning, as
+he sat down in front of his computer, he started complaining. All day
+he cursed, blaming the language for all that went wrong. Fu-Tzu
+listened for a while, and then reproached him, saying 'Every language
+has its own way. Follow its form, do not try to program as if you
+were using another language.'</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p897b23e06210d6e" name="p897b23e06210d6e"> </a>To honour the memory of our good recluse, I would like to finish his
+HTML-generating program for him. A good approach to this problem goes
+like this:</p><ol><li>Split the file into paragraphs by cutting it at every empty line.</li><li>Remove the '%' characters from header paragraphs and mark them as headers.</li><li>Process the text of the paragraphs themselves, splitting them into normal parts, emphasised parts, and footnotes.</li><li>Move all the footnotes to the bottom of the document, leaving numbers<a class="footref" href="#footnote1">1</a> in their place.</li><li>Wrap each piece into the correct HTML tags.</li><li>Combine everything into a single HTML document.</li></ol><p><a class="paragraph" href="#p3639dfda43aa90ef" name="p3639dfda43aa90ef"> </a>This approach does not allow footnotes inside emphasised text, or vice
+versa. This is kind of arbitrary, but helps keep the example code
+simple. If, at the end of the chapter, you feel like an extra
+challenge, you can try to revise the program to support 'nested'
+mark-up.</p><p><a class="paragraph" href="#pa5c8ea56e8f40" name="pa5c8ea56e8f40"> </a>The whole manuscript, as a string value, is available on this page
+by calling <code>recluseFile</code> function.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p3ea6f2079f69683b" name="p3ea6f2079f69683b"> </a>Step 1 of the algorithm is trivial. A blank line is what you get when
+you have two newlines in a row, and if you remember the <code>split</code> method
+that strings have, which we saw in <a href="chapter4.html">chapter 4</a>, you will realise that this
+will do the trick:</p><pre class="code"><span class="keyword">var</span> <span class="variable">paragraphs</span> = <span class="variable">recluseFile</span>().<span class="property">split</span>(<span class="string">"\n\n"</span>);
+<span class="variable">print</span>(<span class="string">"Found "</span>, <span class="variable">paragraphs</span>.<span class="property">length</span>, <span class="string">" paragraphs."</span>);</pre></div><hr/><div class="block"><a name="exercise2"></a><div class="exercisenum">Ex. 6.2</div><div class="exercise"><p><a class="paragraph" href="#p7a03749a314f5c0e" name="p7a03749a314f5c0e"> </a>Write a function <code>processParagraph</code> that, when given a paragraph
+string as its argument, checks whether this paragraph is a header. If
+it is, it strips off the '%' characters and counts their number. Then,
+it returns an object with two properties, <code>content</code>, which contains
+the text inside the paragraph, and <code>type</code>, which contains the tag that
+this paragraph must be wrapped in, <code>"p"</code> for regular paragraphs,
+<code>"h1"</code> for headers with one '%', and <code>"hX"</code> for headers with <code>X</code> '%'
+characters.</p><p><a class="paragraph" href="#p43476b9b9ff201a7" name="p43476b9b9ff201a7"> </a>Remember that strings have a <code>charAt</code> method that can be used to look
+at a specific character inside them.</p></div><div class="solution"><pre class="code"><span class="keyword">function</span> <span class="variable">processParagraph</span>(<span class="variabledef">paragraph</span>) {
+ <span class="keyword">var</span> <span class="variabledef">header</span> = <span class="atom">0</span>;
+ <span class="keyword">while</span> (<span class="localvariable">paragraph</span>.<span class="property">charAt</span>(<span class="atom">0</span>) == <span class="string">"%"</span>) {
+ <span class="localvariable">paragraph</span> = <span class="localvariable">paragraph</span>.<span class="property">slice</span>(<span class="atom">1</span>);
+ <span class="localvariable">header</span>++;
+ }
+
+ <span class="keyword">return</span> {<span class="property">type</span>: (<span class="localvariable">header</span> == <span class="atom">0</span> ? <span class="string">"p"</span> : <span class="string">"h"</span> + <span class="localvariable">header</span>),
+ <span class="property">content</span>: <span class="localvariable">paragraph</span>};
+}
+
+<span class="variable">show</span>(<span class="variable">processParagraph</span>(<span class="variable">paragraphs</span>[<span class="atom">0</span>]));</pre></div></div><hr/><div class="block"><p><a class="paragraph" href="#pa7f3dc1b71f0aa4" name="pa7f3dc1b71f0aa4"> </a>This is where we can try out the <code>map</code> function we saw earlier.</p><pre class="code"><span class="keyword">var</span> <span class="variable">paragraphs</span> = <span class="variable">map</span>(<span class="variable">processParagraph</span>,
+ <span class="variable">recluseFile</span>().<span class="property">split</span>(<span class="string">"\n\n"</span>));</pre><p><a class="paragraph" href="#p12974fd2c85f79a" name="p12974fd2c85f79a"> </a>And <em>bang</em>, we have an array of nicely categorised paragraph objects.
+We are getting ahead of ourselves though, we forgot step 3 of the
+algorithm:</p><blockquote>Process the text of the paragraphs themselves, splitting them into
+normal parts, emphasised parts, and footnotes.</blockquote><p><a class="paragraph" href="#p37365c2089df721d" name="p37365c2089df721d"> </a>Which can be decomposed into:</p><ol><li>If the paragraph starts with an asterisk, take off the emphasised part and store it.</li><li>If the paragraph starts with an opening brace, take off the footnote and store it.</li><li>Otherwise, take off the part until the first emphasised part or footnote, or until the end of the string, and store it as normal text.</li><li>If there is anything left in the paragraph, start at 1 again.</li></ol></div><hr/><div class="block"><a name="exercise3"></a><div class="exercisenum">Ex. 6.3</div><div class="exercise"><p><a class="paragraph" href="#p71cc2e8ae802b37f" name="p71cc2e8ae802b37f"> </a>Build a function <code>splitParagraph</code> which, given a paragraph string,
+returns an array of paragraph fragments. Think of a good way to
+represent the fragments.</p><p><a class="paragraph" href="#p69e4f58fb69971b5" name="p69e4f58fb69971b5"> </a>The method <code>indexOf</code>, which searches for a character or sub-string in
+a string and returns its position, or <code>-1</code> if not found, will probably
+be useful in some way here.</p><p><a class="paragraph" href="#p3ee6676215ac600b" name="p3ee6676215ac600b"> </a>This is a tricky algorithm, and there are many not-quite-correct or
+way-too-long ways to describe it. If you run into problems, just think
+about it for a minute. Try to write inner functions that perform the
+smaller actions that make up the algorithm.</p></div><div class="solution"><p><a class="paragraph" href="#pbb40d1f6f95d6da" name="pbb40d1f6f95d6da"> </a>Here is one possible solution:</p><pre class="code"><span class="keyword">function</span> <span class="variable">splitParagraph</span>(<span class="variabledef">text</span>) {
+ <span class="keyword">function</span> <span class="variabledef">indexOrEnd</span>(<span class="variabledef">character</span>) {
+ <span class="keyword">var</span> <span class="variabledef">index</span> = <span class="localvariable">text</span>.<span class="property">indexOf</span>(<span class="localvariable">character</span>);
+ <span class="keyword">return</span> <span class="localvariable">index</span> == -<span class="atom">1</span> ? <span class="localvariable">text</span>.<span class="property">length</span> : <span class="localvariable">index</span>;
+ }
+
+ <span class="keyword">function</span> <span class="variabledef">takeNormal</span>() {
+ <span class="keyword">var</span> <span class="variabledef">end</span> = <span class="variable">reduce</span>(<span class="variable">Math</span>.<span class="property">min</span>, <span class="localvariable">text</span>.<span class="property">length</span>,
+ <span class="variable">map</span>(<span class="localvariable">indexOrEnd</span>, [<span class="string">"*"</span>, <span class="string">"{"</span>]));
+ <span class="keyword">var</span> <span class="variabledef">part</span> = <span class="localvariable">text</span>.<span class="property">slice</span>(<span class="atom">0</span>, <span class="localvariable">end</span>);
+ <span class="localvariable">text</span> = <span class="localvariable">text</span>.<span class="property">slice</span>(<span class="localvariable">end</span>);
+ <span class="keyword">return</span> <span class="localvariable">part</span>;
+ }
+
+ <span class="keyword">function</span> <span class="variabledef">takeUpTo</span>(<span class="variabledef">character</span>) {
+ <span class="keyword">var</span> <span class="variabledef">end</span> = <span class="localvariable">text</span>.<span class="property">indexOf</span>(<span class="localvariable">character</span>, <span class="atom">1</span>);
+ <span class="keyword">if</span> (<span class="localvariable">end</span> == -<span class="atom">1</span>)
+ <span class="keyword">throw</span> <span class="keyword">new</span> <span class="variable">Error</span>(<span class="string">"Missing closing '"</span> + <span class="localvariable">character</span> + <span class="string">"'"</span>);
+ <span class="keyword">var</span> <span class="variabledef">part</span> = <span class="localvariable">text</span>.<span class="property">slice</span>(<span class="atom">1</span>, <span class="localvariable">end</span>);
+ <span class="localvariable">text</span> = <span class="localvariable">text</span>.<span class="property">slice</span>(<span class="localvariable">end</span> + <span class="atom">1</span>);
+ <span class="keyword">return</span> <span class="localvariable">part</span>;
+ }
+
+ <span class="keyword">var</span> <span class="variabledef">fragments</span> = [];
+
+ <span class="keyword">while</span> (<span class="localvariable">text</span> != <span class="string">""</span>) {
+ <span class="keyword">if</span> (<span class="localvariable">text</span>.<span class="property">charAt</span>(<span class="atom">0</span>) == <span class="string">"*"</span>)
+ <span class="localvariable">fragments</span>.<span class="property">push</span>({<span class="property">type</span>: <span class="string">"emphasised"</span>,
+ <span class="property">content</span>: <span class="localvariable">takeUpTo</span>(<span class="string">"*"</span>)});
+ <span class="keyword">else</span> <span class="keyword">if</span> (<span class="localvariable">text</span>.<span class="property">charAt</span>(<span class="atom">0</span>) == <span class="string">"{"</span>)
+ <span class="localvariable">fragments</span>.<span class="property">push</span>({<span class="property">type</span>: <span class="string">"footnote"</span>,
+ <span class="property">content</span>: <span class="localvariable">takeUpTo</span>(<span class="string">"}"</span>)});
+ <span class="keyword">else</span>
+ <span class="localvariable">fragments</span>.<span class="property">push</span>({<span class="property">type</span>: <span class="string">"normal"</span>,
+ <span class="property">content</span>: <span class="localvariable">takeNormal</span>()});
+ }
+ <span class="keyword">return</span> <span class="localvariable">fragments</span>;
+}</pre><p><a class="paragraph" href="#p345940589e670c12" name="p345940589e670c12"> </a>Note the over-eager use of <code>map</code> and <code>reduce</code> in the <code>takeNormal</code>
+function. This is a chapter about functional programming, so program
+functionally we will! Can you see how this works? The <code>map</code> produces
+an array of positions where the given characters were found, or the
+end of the string if they were not found, and the <code>reduce</code> takes the
+minimum of them, which is the next point in the string that we have to
+look at.</p><p><a class="paragraph" href="#p69d4e54010e82198" name="p69d4e54010e82198"> </a>If you'd write that out without mapping and reducing you'd get
+something like this:</p><pre class="preformatted">var nextAsterisk = text.indexOf("*");
+var nextBrace = text.indexOf("{");
+var end = text.length;
+if (nextAsterisk != -1)
+ end = nextAsterisk;
+if (nextBrace != -1 && nextBrace < end)
+ end = nextBrace;</pre><p><a class="paragraph" href="#p8c0367fd215c195" name="p8c0367fd215c195"> </a>Which is even more hideous. Most of the time, when a decision has to
+be made based on a series of things, even if there are only two of
+them, writing it as array operations is nicer than handling every
+value in a separate <code>if</code> statement. (Fortunately, <a href="chapter10.html">chapter 10</a> describes
+an easier way to ask for the first occurrence of 'this or that
+character' in a string.)</p><p><a class="paragraph" href="#p3bc46f0ef5a06a22" name="p3bc46f0ef5a06a22"> </a>If you wrote a <code>splitParagraph</code> that stored fragments in a different
+way than the solution above, you might want to adjust it, because the
+functions in the rest of the chapter assume that fragments are objects
+with <code>type</code> and <code>content</code> properties.</p></div></div><hr/><div class="block"><p><a class="paragraph" href="#p8d8dfc9fda5e96b" name="p8d8dfc9fda5e96b"> </a>We can now wire <code>processParagraph</code> to also split the text inside the
+paragraphs, my version can be modified like this:</p><pre class="code"><span class="keyword">function</span> <span class="variable">processParagraph</span>(<span class="variabledef">paragraph</span>) {
+ <span class="keyword">var</span> <span class="variabledef">header</span> = <span class="atom">0</span>;
+ <span class="keyword">while</span> (<span class="localvariable">paragraph</span>.<span class="property">charAt</span>(<span class="atom">0</span>) == <span class="string">"%"</span>) {
+ <span class="localvariable">paragraph</span> = <span class="localvariable">paragraph</span>.<span class="property">slice</span>(<span class="atom">1</span>);
+ <span class="localvariable">header</span>++;
+ }
+
+ <span class="keyword">return</span> {<span class="property">type</span>: (<span class="localvariable">header</span> == <span class="atom">0</span> ? <span class="string">"p"</span> : <span class="string">"h"</span> + <span class="localvariable">header</span>),
+ <span class="property">content</span>: <span class="variable">splitParagraph</span>(<span class="localvariable">paragraph</span>)};
+}</pre><p><a class="paragraph" href="#p1dc03c0bced024ba" name="p1dc03c0bced024ba"> </a>Mapping that over the array of paragraphs gives us an array of
+paragraph objects, which in turn contain arrays of fragment objects.
+The next thing to do is to take out the footnotes, and put references
+to them in their place. Something like this:</p><pre class="code"><span class="keyword">function</span> <span class="variable">extractFootnotes</span>(<span class="variabledef">paragraphs</span>) {
+ <span class="keyword">var</span> <span class="variabledef">footnotes</span> = [];
+ <span class="keyword">var</span> <span class="variabledef">currentNote</span> = <span class="atom">0</span>;
+
+ <span class="keyword">function</span> <span class="variabledef">replaceFootnote</span>(<span class="variabledef">fragment</span>) {
+ <span class="keyword">if</span> (<span class="localvariable">fragment</span>.<span class="property">type</span> == <span class="string">"footnote"</span>) {
+ <span class="localvariable">currentNote</span>++;
+ <span class="localvariable">footnotes</span>.<span class="property">push</span>(<span class="localvariable">fragment</span>);
+ <span class="localvariable">fragment</span>.<span class="property">number</span> = <span class="localvariable">currentNote</span>;
+ <span class="keyword">return</span> {<span class="property">type</span>: <span class="string">"reference"</span>, <span class="property">number</span>: <span class="localvariable">currentNote</span>};
+ }
+ <span class="keyword">else</span> {
+ <span class="keyword">return</span> <span class="localvariable">fragment</span>;
+ }
+ }
+
+ <span class="variable">forEach</span>(<span class="localvariable">paragraphs</span>, <span class="keyword">function</span>(<span class="variabledef">paragraph</span>) {
+ <span class="localvariable">paragraph</span>.<span class="property">content</span> = <span class="variable">map</span>(<span class="localvariable">replaceFootnote</span>,
+ <span class="localvariable">paragraph</span>.<span class="property">content</span>);
+ });
+
+ <span class="keyword">return</span> <span class="localvariable">footnotes</span>;
+} </pre><p><a class="paragraph" href="#p1945e2a9469001e7" name="p1945e2a9469001e7"> </a>The <code>replaceFootnote</code> function is called on every fragment. When it
+gets a fragment that should stay where it is, it just returns it, but
+when it gets a footnote, it stores this footnote in the <code>footnotes</code>
+array, and returns a reference to it instead. In the process, every
+footnote and reference is also numbered.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p17175caf68cc7e1d" name="p17175caf68cc7e1d"> </a>That gives us enough tools to extract the information we need from the
+file. All that is left now is generating the correct HTML.</p><p><a class="paragraph" href="#p749d0d61d6a10c1c" name="p749d0d61d6a10c1c"> </a>A lot of people think that concatenating strings is a great way to
+produce HTML. When they need a link to, for example, a site where you
+can play the game of Go, they will do:</p><pre class="code"><span class="keyword">var</span> <span class="variable">url</span> = <span class="string">"http://www.gokgs.com/"</span>;
+<span class="keyword">var</span> <span class="variable">text</span> = <span class="string">"Play Go!"</span>;
+<span class="keyword">var</span> <span class="variable">linkText</span> = <span class="string">"<a href=\""</span> + <span class="variable">url</span> + <span class="string">"\">"</span> + <span class="variable">text</span> + <span class="string">"</a>"</span>;
+<span class="variable">print</span>(<span class="variable">linkText</span>);</pre><p><a class="paragraph" href="#p747f2492516f6ec8" name="p747f2492516f6ec8"> </a>(Where <code>a</code> is the tag used to create links in HTML documents.) ... Not
+only is this clumsy, but when the string <code>text</code> happens to include an
+angular bracket or an ampersand, it is also wrong. Weird things will
+happen on your website, and you will look embarrassingly amateurish.
+We wouldn't want that to happen. A few simple HTML-generating
+functions are easy to write. So let us write them.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p6fa1925fa79b3a64" name="p6fa1925fa79b3a64"> </a>The secret to successful HTML generation is to treat your HTML
+document as a data structure instead of a flat piece of text.
+JavaScript's objects provide a very easy way to model this:</p><pre class="code"><span class="keyword">var</span> <span class="variable">linkObject</span> = {<span class="property">name</span>: <span class="string">"a"</span>,
+ <span class="property">attributes</span>: {<span class="property">href</span>: <span class="string">"http://www.gokgs.com/"</span>},
+ <span class="property">content</span>: [<span class="string">"Play Go!"</span>]};</pre><p><a class="paragraph" href="#p556c15128bc138bf" name="p556c15128bc138bf"> </a>Each HTML element contains a <code>name</code> property, giving the name of the
+tag it represents. When it has attributes, it also contains an
+<code>attributes</code> property, which contains an object in which the
+attributes are stored. When it has content, there is a <code>content</code>
+property, containing an array of other elements contained in this
+element. Strings play the role of pieces of text in our HTML document,
+so the array <code>["Play Go!"]</code> means that this link has only one element
+inside it, which is a simple piece of text.</p><p><a class="paragraph" href="#p436b8a0933ca40c3" name="p436b8a0933ca40c3"> </a>Typing in these objects directly is clumsy, but we don't have to do
+that. We provide a shortcut function to do this for us:</p><pre class="code"><span class="keyword">function</span> <span class="variable">tag</span>(<span class="variabledef">name</span>, <span class="variabledef">content</span>, <span class="variabledef">attributes</span>) {
+ <span class="keyword">return</span> {<span class="property">name</span>: <span class="localvariable">name</span>, <span class="property">attributes</span>: <span class="localvariable">attributes</span>, <span class="property">content</span>: <span class="localvariable">content</span>};
+}</pre><p><a class="paragraph" href="#p1ecda8e342d6e46b" name="p1ecda8e342d6e46b"> </a>Note that, since we allow the <code>attributes</code> and <code>content</code> of an element
+to be undefined if they are not applicable, the second and third
+argument to this function can be left off when they are not needed.</p><p><a class="paragraph" href="#p4cba4588483f2724" name="p4cba4588483f2724"> </a><code>tag</code> is still rather primitive, so we write shortcuts for common
+types of elements, such as links, or the outer structure of a simple
+document:</p><pre class="code"><span class="keyword">function</span> <span class="variable">link</span>(<span class="variabledef">target</span>, <span class="variabledef">text</span>) {
+ <span class="keyword">return</span> <span class="variable">tag</span>(<span class="string">"a"</span>, [<span class="localvariable">text</span>], {<span class="property">href</span>: <span class="localvariable">target</span>});
+}
+
+<span class="keyword">function</span> <span class="variable">htmlDoc</span>(<span class="variabledef">title</span>, <span class="variabledef">bodyContent</span>) {
+ <span class="keyword">return</span> <span class="variable">tag</span>(<span class="string">"html"</span>, [<span class="variable">tag</span>(<span class="string">"head"</span>, [<span class="variable">tag</span>(<span class="string">"title"</span>, [<span class="localvariable">title</span>])]),
+ <span class="variable">tag</span>(<span class="string">"body"</span>, <span class="localvariable">bodyContent</span>)]);
+}</pre></div><hr/><div class="block"><a name="exercise4"></a><div class="exercisenum">Ex. 6.4</div><div class="exercise"><p><a class="paragraph" href="#p55aadeef2bce3455" name="p55aadeef2bce3455"> </a>Looking back at the example HTML document if necessary, write an
+<code>image</code> function which, when given the location of an image file, will
+create an <code>img</code> HTML element.</p></div><div class="solution"><pre class="code"><span class="keyword">function</span> <span class="variable">image</span>(<span class="variabledef">src</span>) {
+ <span class="keyword">return</span> <span class="variable">tag</span>(<span class="string">"img"</span>, [], {<span class="property">src</span>: <span class="localvariable">src</span>});
+}</pre></div></div><hr/><div class="block"><p><a class="paragraph" href="#p6f2629dff438f71e" name="p6f2629dff438f71e"> </a>When we have created a document, it will have to be reduced to a
+string. But building this string from the data structures we have been
+producing is very straightforward. The important thing is to remember
+to transform the special characters in the text of our document...</p><pre class="code"><span class="keyword">function</span> <span class="variable">escapeHTML</span>(<span class="variabledef">text</span>) {
+ <span class="keyword">var</span> <span class="variabledef">replacements</span> = [[<span class="string">/&/g</span>, <span class="string">"&amp;"</span>], [<span class="string">/"/g</span>, <span class="string">"&quot;"</span>],
+ [<span class="string">/</g</span>, <span class="string">"&lt;"</span>], [<span class="string">/>/g</span>, <span class="string">"&gt;"</span>]];
+ <span class="variable">forEach</span>(<span class="localvariable">replacements</span>, <span class="keyword">function</span>(<span class="variabledef">replace</span>) {
+ <span class="localvariable">text</span> = <span class="localvariable">text</span>.<span class="property">replace</span>(<span class="localvariable">replace</span>[<span class="atom">0</span>], <span class="localvariable">replace</span>[<span class="atom">1</span>]);
+ });
+ <span class="keyword">return</span> <span class="localvariable">text</span>;
+}</pre><p><a class="paragraph" href="#p20c7007a4d92929f" name="p20c7007a4d92929f"> </a>The <code>replace</code> method of strings creates a new string in which all
+occurrences of the pattern in the first argument are replaced by the
+second argument, so <code>"Borobudur".replace(/r/g, "k")</code> gives
+<code>"Bokobuduk"</code>. Don't worry about the pattern syntax here ― we'll get
+to that in <a href="chapter10.html">chapter 10</a>. The <code>escapeHTML</code> function puts the different
+replacements that have to be made into an array, so that it can loop
+over them and apply them to the argument one by one.</p><p><a class="paragraph" href="#p3c2403698fee1561" name="p3c2403698fee1561"> </a>Double quotes are also replaced, because we will also be using this
+function for the text inside the attributes of HTML tags. Those will
+be surrounded by double quotes, and thus must not have any double
+quotes inside of them.</p><p><a class="paragraph" href="#p76723fc7e0f72bae" name="p76723fc7e0f72bae"> </a>Calling replace four times means the computer has to go over the whole
+string four times to check and replace its content. This is not very
+efficient. If we cared enough, we could write a more complex version
+of this function, something that resembles the <code>splitParagraph</code>
+function we saw earlier, to go over it only once. For now, we are too
+lazy for this. Again, <a href="chapter10.html">chapter 10</a> shows a much better way to do this.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p597f66cdb5f3e27e" name="p597f66cdb5f3e27e"> </a>To turn an HTML element object into a string, we can use a recursive
+function like this:</p><pre class="code"><span class="keyword">function</span> <span class="variable">renderHTML</span>(<span class="variabledef">element</span>) {
+ <span class="keyword">var</span> <span class="variabledef">pieces</span> = [];
+
+ <span class="keyword">function</span> <span class="variabledef">renderAttributes</span>(<span class="variabledef">attributes</span>) {
+ <span class="keyword">var</span> <span class="variabledef">result</span> = [];
+ <span class="keyword">if</span> (<span class="localvariable">attributes</span>) {
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variabledef">name</span> <span class="keyword">in</span> <span class="localvariable">attributes</span>)
+ <span class="localvariable">result</span>.<span class="property">push</span>(<span class="string">" "</span> + <span class="localvariable">name</span> + <span class="string">"=\""</span> +
+ <span class="variable">escapeHTML</span>(<span class="localvariable">attributes</span>[<span class="localvariable">name</span>]) + <span class="string">"\""</span>);
+ }
+ <span class="keyword">return</span> <span class="localvariable">result</span>.<span class="property">join</span>(<span class="string">""</span>);
+ }
+
+ <span class="keyword">function</span> <span class="variabledef">render</span>(<span class="variabledef">element</span>) {
+ <span class="comment">// Text node</span>
+ <span class="keyword">if</span> (typeof <span class="localvariable">element</span> == <span class="string">"string"</span>) {
+ <span class="localvariable">pieces</span>.<span class="property">push</span>(<span class="variable">escapeHTML</span>(<span class="localvariable">element</span>));
+ }
+ <span class="comment">// Empty tag</span>
+ <span class="keyword">else</span> <span class="keyword">if</span> (!<span class="localvariable">element</span>.<span class="property">content</span> || <span class="localvariable">element</span>.<span class="property">content</span>.<span class="property">length</span> == <span class="atom">0</span>) {
+ <span class="localvariable">pieces</span>.<span class="property">push</span>(<span class="string">"<"</span> + <span class="localvariable">element</span>.<span class="property">name</span> +
+ <span class="localvariable">renderAttributes</span>(<span class="localvariable">element</span>.<span class="property">attributes</span>) + <span class="string">"/>"</span>);
+ }
+ <span class="comment">// Tag with content</span>
+ <span class="keyword">else</span> {
+ <span class="localvariable">pieces</span>.<span class="property">push</span>(<span class="string">"<"</span> + <span class="localvariable">element</span>.<span class="property">name</span> +
+ <span class="localvariable">renderAttributes</span>(<span class="localvariable">element</span>.<span class="property">attributes</span>) + <span class="string">">"</span>);
+ <span class="variable">forEach</span>(<span class="localvariable">element</span>.<span class="property">content</span>, <span class="localvariable">render</span>);
+ <span class="localvariable">pieces</span>.<span class="property">push</span>(<span class="string">"</"</span> + <span class="localvariable">element</span>.<span class="property">name</span> + <span class="string">">"</span>);
+ }
+ }
+
+ <span class="localvariable">render</span>(<span class="localvariable">element</span>);
+ <span class="keyword">return</span> <span class="localvariable">pieces</span>.<span class="property">join</span>(<span class="string">""</span>);
+}</pre><p><a class="paragraph" href="#p2dbe0143b8e2e574" name="p2dbe0143b8e2e574"> </a>Note the <code>in</code> loop that extracts the properties from a JavaScript
+object in order to make HTML tag attributes out of them. Also note
+that in two places, arrays are being used to accumulate strings, which
+are then joined into a single result string. Why didn't I just start
+with an empty string and then add the content to it with the <code>+=</code>
+operator?</p><p><a class="paragraph" href="#p4c819786485d39b0" name="p4c819786485d39b0"> </a>It turns out that creating new strings, especially big strings, is
+quite a lot of work. Remember that JavaScript string values never
+change. If you concatenate something to them, a new string is created,
+the old ones stay intact. If we build up a big string by concatenating
+lots of little strings, new strings have to be created at every step,
+only to be thrown away when the next piece is concatenated to them.
+If, on the other hand, we store all the little strings in an array and
+then join them, only <em>one</em> big string has to be created.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p4e3b2805efaaea64" name="p4e3b2805efaaea64"> </a>So, let us try out this HTML generating system...</p><pre class="code"><span class="variable">print</span>(<span class="variable">renderHTML</span>(<span class="variable">link</span>(<span class="string">"http://www.nedroid.com"</span>, <span class="string">"Drawings!"</span>)));</pre><p><a class="paragraph" href="#p506d9a82709880b0" name="p506d9a82709880b0"> </a>That seems to work.</p><pre class="code"><span class="keyword">var</span> <span class="variable">body</span> = [<span class="variable">tag</span>(<span class="string">"h1"</span>, [<span class="string">"The Test"</span>]),
+ <span class="variable">tag</span>(<span class="string">"p"</span>, [<span class="string">"Here is a paragraph, and an image..."</span>]),
+ <span class="variable">image</span>(<span class="string">"img/sheep.png"</span>)];
+<span class="keyword">var</span> <span class="variable">doc</span> = <span class="variable">htmlDoc</span>(<span class="string">"The Test"</span>, <span class="variable">body</span>);
+<span class="variable">viewHTML</span>(<span class="variable">renderHTML</span>(<span class="variable">doc</span>));</pre><p><a class="paragraph" href="#p3276b3e80a052310" name="p3276b3e80a052310"> </a>Now, I should probably warn you that this approach is not perfect.
+What it actually renders is <a name="key12"></a>XML, which is similar to HTML, but more
+structured. In simple cases, such as the above, this does not cause
+any problems. However, there are some things, which are correct XML,
+but not proper HTML, and these might confuse a browser that is trying
+to show the documents we create. For example, if you have an empty
+<code>script</code> tag (used to put JavaScript into a page) in your document,
+browsers will not realise that it is empty and think that everything
+after it is JavaScript. (In this case, the problem can be fixed by
+putting a single space inside of the tag, so that it is no longer
+empty, and gets a proper closing tag.)</p></div><hr/><div class="block"><a name="exercise5"></a><div class="exercisenum">Ex. 6.5</div><div class="exercise"><p><a class="paragraph" href="#p1e0ef833450fc1f3" name="p1e0ef833450fc1f3"> </a>Write a function <code>renderFragment</code>, and use that to implement another
+function <code>renderParagraph</code>, which takes a paragraph object (with the
+footnotes already filtered out), and produces the correct HTML element
+(which might be a paragraph or a header, depending on the <code>type</code>
+property of the paragraph object).</p><p><a class="paragraph" href="#p1f0861c7ed9d1bfa" name="p1f0861c7ed9d1bfa"> </a>This function might come in useful for rendering the footnote
+references:</p><pre class="code"><span class="keyword">function</span> <span class="variable">footnote</span>(<span class="variabledef">number</span>) {
+ <span class="keyword">return</span> <span class="variable">tag</span>(<span class="string">"sup"</span>, [<span class="variable">link</span>(<span class="string">"#footnote"</span> + <span class="localvariable">number</span>,
+ <span class="variable">String</span>(<span class="localvariable">number</span>))]);
+}</pre><p><a class="paragraph" href="#p794dcad4550f2084" name="p794dcad4550f2084"> </a>A <code>sup</code> tag will show its content as 'superscript', which means it
+will be smaller and a little higher than other text. The target of the
+link will be something like <code>"#footnote1"</code>. Links that contain a '#'
+character refer to 'anchors' within a page, and in this case we will
+use them to make it so that clicking on the footnote link will take
+the reader to the bottom of the page, where the footnotes live.</p><p><a class="paragraph" href="#p72966e0371d3b74" name="p72966e0371d3b74"> </a>The tag to render emphasised fragments with is <code>em</code>, and normal text
+can be rendered without any extra tags.</p></div><div class="solution"><pre class="code"><span class="keyword">function</span> <span class="variable">renderParagraph</span>(<span class="variabledef">paragraph</span>) {
+ <span class="keyword">return</span> <span class="variable">tag</span>(<span class="localvariable">paragraph</span>.<span class="property">type</span>, <span class="variable">map</span>(<span class="variable">renderFragment</span>,
+ <span class="localvariable">paragraph</span>.<span class="property">content</span>));
+}
+
+<span class="keyword">function</span> <span class="variable">renderFragment</span>(<span class="variabledef">fragment</span>) {
+ <span class="keyword">if</span> (<span class="localvariable">fragment</span>.<span class="property">type</span> == <span class="string">"reference"</span>)
+ <span class="keyword">return</span> <span class="variable">footnote</span>(<span class="localvariable">fragment</span>.<span class="property">number</span>);
+ <span class="keyword">else</span> <span class="keyword">if</span> (<span class="localvariable">fragment</span>.<span class="property">type</span> == <span class="string">"emphasised"</span>)
+ <span class="keyword">return</span> <span class="variable">tag</span>(<span class="string">"em"</span>, [<span class="localvariable">fragment</span>.<span class="property">content</span>]);
+ <span class="keyword">else</span> <span class="keyword">if</span> (<span class="localvariable">fragment</span>.<span class="property">type</span> == <span class="string">"normal"</span>)
+ <span class="keyword">return</span> <span class="localvariable">fragment</span>.<span class="property">content</span>;
+}</pre></div></div><hr/><div class="block"><p><a class="paragraph" href="#p260d6cceac205754" name="p260d6cceac205754"> </a>We are almost finished. The only thing that we do not have a rendering
+function for yet are the footnotes. To make the <code>"#footnote1"</code> links
+work, an anchor must be included with every footnote. In HTML, an
+anchor is specified with an <code>a</code> element, which is also used for links.
+In this case, it needs a <code>name</code> attribute, instead of an <code>href</code>.</p><pre class="code"><span class="keyword">function</span> <span class="variable">renderFootnote</span>(<span class="variabledef">footnote</span>) {
+ <span class="keyword">var</span> <span class="variabledef">number</span> = <span class="string">"["</span> + <span class="localvariable">footnote</span>.<span class="property">number</span> + <span class="string">"] "</span>;
+ <span class="keyword">var</span> <span class="variabledef">anchor</span> = <span class="variable">tag</span>(<span class="string">"a"</span>, [<span class="localvariable">number</span>], {<span class="property">name</span>: <span class="string">"footnote"</span> + <span class="localvariable">footnote</span>.<span class="property">number</span>});
+ <span class="keyword">return</span> <span class="variable">tag</span>(<span class="string">"p"</span>, [<span class="variable">tag</span>(<span class="string">"small"</span>, [<span class="localvariable">anchor</span>, <span class="localvariable">footnote</span>.<span class="property">content</span>])]);
+}</pre><p><a class="paragraph" href="#p15ce2e41d5804dbd" name="p15ce2e41d5804dbd"> </a>Here, then, is the function which, when given a file in the correct
+format and a document title, returns an HTML document:</p><pre class="code"><span class="keyword">function</span> <span class="variable">renderFile</span>(<span class="variabledef">file</span>, <span class="variabledef">title</span>) {
+ <span class="keyword">var</span> <span class="variabledef">paragraphs</span> = <span class="variable">map</span>(<span class="variable">processParagraph</span>, <span class="localvariable">file</span>.<span class="property">split</span>(<span class="string">"\n\n"</span>));
+ <span class="keyword">var</span> <span class="variabledef">footnotes</span> = <span class="variable">map</span>(<span class="variable">renderFootnote</span>,
+ <span class="variable">extractFootnotes</span>(<span class="localvariable">paragraphs</span>));
+ <span class="keyword">var</span> <span class="variabledef">body</span> = <span class="variable">map</span>(<span class="variable">renderParagraph</span>, <span class="localvariable">paragraphs</span>).<span class="property">concat</span>(<span class="localvariable">footnotes</span>);
+ <span class="keyword">return</span> <span class="variable">renderHTML</span>(<span class="variable">htmlDoc</span>(<span class="localvariable">title</span>, <span class="localvariable">body</span>));
+}
+
+<span class="variable">viewHTML</span>(<span class="variable">renderFile</span>(<span class="variable">recluseFile</span>(), <span class="string">"The Book of Programming"</span>));</pre><p><a class="paragraph" href="#p44b9e2a4b2c6f4ee" name="p44b9e2a4b2c6f4ee"> </a>The <a name="key13"></a><code>concat</code> method of an array can be used to concatenate another
+array to it, similar to what the <code>+</code> operator does with strings.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p38be59fe5e85639c" name="p38be59fe5e85639c"> </a>In the chapters after this one, elementary higher-order functions like
+<code>map</code> and <code>reduce</code> will always be available and will be used by code
+examples. Now and then, a new useful tool is added to this. In
+<a href="chapter9.html">chapter 9</a>, we develop a more structured approach to this set of
+'basic' functions.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p56acbb13d5ed03ef" name="p56acbb13d5ed03ef"> </a>When using higher-order functions, it is often annoying that operators
+are not functions in JavaScript. We have needed <code>add</code> or <code>equals</code>
+functions at several points. Rewriting these every time, you will
+agree, is a pain. From now on, we will assume the existence of an
+object called <code>op</code>, which contains these functions:</p><pre class="code"><span class="keyword">var</span> <span class="variable">op</span> = {
+ <span class="string">"+"</span>: <span class="keyword">function</span>(<span class="variabledef">a</span>, <span class="variabledef">b</span>){<span class="keyword">return</span> <span class="localvariable">a</span> + <span class="localvariable">b</span>;},
+ <span class="string">"=="</span>: <span class="keyword">function</span>(<span class="variabledef">a</span>, <span class="variabledef">b</span>){<span class="keyword">return</span> <span class="localvariable">a</span> == <span class="localvariable">b</span>;},
+ <span class="string">"==="</span>: <span class="keyword">function</span>(<span class="variabledef">a</span>, <span class="variabledef">b</span>){<span class="keyword">return</span> <span class="localvariable">a</span> === <span class="localvariable">b</span>;},
+ <span class="string">"!"</span>: <span class="keyword">function</span>(<span class="variabledef">a</span>){<span class="keyword">return</span> !<span class="localvariable">a</span>;}
+ <span class="comment">/* and so on */</span>
+};</pre><p><a class="paragraph" href="#pfeabae2909dca1b" name="pfeabae2909dca1b"> </a>So we can write <code>reduce(op["+"], 0, [1, 2, 3, 4, 5])</code> to sum an array.
+But what if we need something like <code>equals</code> or <code>makeAddFunction</code>, in
+which one of the arguments already has a value? In that case we are
+back to writing a new function again.</p><p><a class="paragraph" href="#p7748cd15a29a68dd" name="p7748cd15a29a68dd"> </a>For cases like that, something called '<a name="key14"></a>partial application' is
+useful. You want to create a new function that already knows some of
+its arguments, and treats any additional arguments it is passed as
+coming after these fixed arguments. This can be done by making
+creative use of the <code>apply</code> method of a function:</p><pre class="code"><span class="keyword">function</span> <span class="variable">asArray</span>(<span class="variabledef">quasiArray</span>, <span class="variabledef">start</span>) {
+ <span class="keyword">var</span> <span class="variabledef">result</span> = [];
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variabledef">i</span> = (<span class="localvariable">start</span> || <span class="atom">0</span>); <span class="localvariable">i</span> < <span class="localvariable">quasiArray</span>.<span class="property">length</span>; <span class="localvariable">i</span>++)
+ <span class="localvariable">result</span>.<span class="property">push</span>(<span class="localvariable">quasiArray</span>[<span class="localvariable">i</span>]);
+ <span class="keyword">return</span> <span class="localvariable">result</span>;
+}
+
+<span class="keyword">function</span> <span class="variable">partial</span>(<span class="variabledef">func</span>) {
+ <span class="keyword">var</span> <span class="variabledef">fixedArgs</span> = <span class="variable">asArray</span>(<span class="localvariable">arguments</span>, <span class="atom">1</span>);
+ <span class="keyword">return</span> <span class="keyword">function</span>(){
+ <span class="keyword">return</span> <span class="localvariable">func</span>.<span class="property">apply</span>(<span class="atom">null</span>, <span class="localvariable">fixedArgs</span>.<span class="property">concat</span>(<span class="variable">asArray</span>(<span class="localvariable">arguments</span>)));
+ };
+}</pre><p><a class="paragraph" href="#pe9b122460ca0eee" name="pe9b122460ca0eee"> </a>We want to allow binding multiple arguments at the same time, so the
+<code>asArray</code> function is necessary to make normal arrays out of the
+<code>arguments</code> objects. It copies their content into a real array, so
+that the <code>concat</code> method can be used on it. It also takes an optional
+second argument, which can be used to leave out some arguments at the
+start.</p><p><a class="paragraph" href="#p342f5837255ffd22" name="p342f5837255ffd22"> </a>Also note that it is necessary to store the <code>arguments</code> of the outer
+function (<code>partial</code>) into a variable with another name, because
+otherwise the inner function can not see them ― it has its own
+<code>arguments</code> variable, which shadows the one of the outer function.</p><p><a class="paragraph" href="#p78f7fd1997c68fae" name="p78f7fd1997c68fae"> </a>Now <code>equals(10)</code> could be written as <code>partial(op["=="], 10)</code>, without
+the need for a specialized <code>equals</code> function. And you can do things
+like this:</p><pre class="code"><span class="variable">show</span>(<span class="variable">map</span>(<span class="variable">partial</span>(<span class="variable">op</span>[<span class="string">"+"</span>], <span class="atom">1</span>), [<span class="atom">0</span>, <span class="atom">2</span>, <span class="atom">4</span>, <span class="atom">6</span>, <span class="atom">8</span>, <span class="atom">10</span>]));</pre><p><a class="paragraph" href="#p53b9ce7b99d38fa4" name="p53b9ce7b99d38fa4"> </a>The reason <code>map</code> takes its function argument before its array argument
+is that it is often useful to partially apply map by giving it a
+function. This 'lifts' the function from operating on a single value
+to operating on an array of values. For example, if you have an array
+of arrays of numbers, and you want to square them all, you do this:</p><pre class="code"><span class="keyword">function</span> <span class="variable">square</span>(<span class="variabledef">x</span>) {<span class="keyword">return</span> <span class="localvariable">x</span> * <span class="localvariable">x</span>;}
+
+<span class="variable">show</span>(<span class="variable">map</span>(<span class="variable">partial</span>(<span class="variable">map</span>, <span class="variable">square</span>), [[<span class="atom">10</span>, <span class="atom">100</span>], [<span class="atom">12</span>, <span class="atom">16</span>], [<span class="atom">0</span>, <span class="atom">1</span>]]));</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p185552a7e4f5ee01" name="p185552a7e4f5ee01"> </a>One last trick that can be useful when you want to combine functions
+is <a name="key15"></a>function composition. At the start of this chapter I showed a
+function <code>negate</code>, which applies the boolean <em>not</em> operator to the
+result of calling a function:</p><pre class="code"><span class="keyword">function</span> <span class="variable">negate</span>(<span class="variabledef">func</span>) {
+ <span class="keyword">return</span> <span class="keyword">function</span>() {
+ <span class="keyword">return</span> !<span class="localvariable">func</span>.<span class="property">apply</span>(<span class="atom">null</span>, <span class="localvariable">arguments</span>);
+ };
+}</pre><p><a class="paragraph" href="#p63a12d097069c39a" name="p63a12d097069c39a"> </a>This is a special case of a general pattern: call function A, and then
+apply function B to the result. Composition is a common concept in
+mathematics. <a name="key16"></a>It can be caught in a higher-order function
+like this:</p><pre class="code"><span class="keyword">function</span> <span class="variable">compose</span>(<span class="variabledef">func1</span>, <span class="variabledef">func2</span>) {
+ <span class="keyword">return</span> <span class="keyword">function</span>() {
+ <span class="keyword">return</span> <span class="localvariable">func1</span>(<span class="localvariable">func2</span>.<span class="property">apply</span>(<span class="atom">null</span>, <span class="localvariable">arguments</span>));
+ };
+}
+
+<span class="keyword">var</span> <span class="variable">isUndefined</span> = <span class="variable">partial</span>(<span class="variable">op</span>[<span class="string">"==="</span>], <span class="atom">undefined</span>);
+<span class="keyword">var</span> <span class="variable">isDefined</span> = <span class="variable">compose</span>(<span class="variable">op</span>[<span class="string">"!"</span>], <span class="variable">isUndefined</span>);
+<span class="variable">show</span>(<span class="variable">isDefined</span>(<span class="variable">Math</span>.<span class="property">PI</span>));
+<span class="variable">show</span>(<span class="variable">isDefined</span>(<span class="variable">Math</span>.<span class="property">PIE</span>));</pre><p><a class="paragraph" href="#p6fe822fa5221ce46" name="p6fe822fa5221ce46"> </a>Here we are defining new functions without using the <code>function</code>
+keyword at all. This can be useful when you need to create a simple
+function to give to, for example, <code>map</code> or <code>reduce</code>. However, when a
+function becomes more complex than these examples, it is usually
+shorter (not to mention more efficient) to just write it out with
+<code>function</code>.</p></div><ol class="footnotes"><li><a name="footnote1"></a>Like this...</li></ol><h1><span class="number">Chapter 7: </span>Searching</h1><div class="block"><p><a class="paragraph" href="#p52ee64062049491e" name="p52ee64062049491e"> </a>This chapter does not introduce any new JavaScript-specific concepts.
+Instead, we will go through the solution to two problems, discussing
+some interesting algorithms and techniques along the way. If this does
+not sound interesting to you, it is safe to skip to the next chapter.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p14264f955a1c38a8" name="p14264f955a1c38a8"> </a>Let me introduce our first problem. Take a look at this map. It shows
+Hiva Oa, a small tropical island in the Pacific Ocean.</p><div class="illustration"><img src="img/Hiva Oa.png"/></div><p><a class="paragraph" href="#p4f3e199a5c919c9f" name="p4f3e199a5c919c9f"> </a>The grey lines are roads, and the numbers next to them are the lengths
+of these roads. Imagine we need a program that finds the shortest
+route between two points on Hiva Oa. How could we approach that? Think
+about this for a moment.</p><p><a class="paragraph" href="#p863b223f0b945eb" name="p863b223f0b945eb"> </a>No really. Don't just steamroll on to the next paragraph. Try to
+seriously think of some ways you could do this, and consider the
+issues you would come up against. When reading a technical book, it is
+way too easy to just zoom over the text, nod solemnly, and promptly
+forget what you have read. If you make a sincere effort to solve a
+problem, it becomes <em>your</em> problem, and its solution will be more
+meaningful.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p10cd40c44817971" name="p10cd40c44817971"> </a>The first aspect of this problem is, again, representing our data. The
+information in the picture does not mean much to our computer. We
+could try writing a program that looks at the map and extracts the
+information in it... but that can get complicated. If we had
+twenty-thousand maps to interpret, this would be a good idea, in this
+case we will do the interpretation ourself and transcribe the map into
+a more computer-friendly format.</p><p><a class="paragraph" href="#p60b43058c8cb0bbe" name="p60b43058c8cb0bbe"> </a>What does our program need to know? It has to be able to look up which
+locations are connected, and how long the roads between them are. The
+places and roads on the island form a <a name="key1"></a>graph, as mathematicians call
+it. There are many ways to store graphs. A simple possibility is to
+just store an array of road objects, each of which contains properties
+naming its two endpoints and its length...</p><pre class="code"><span class="keyword">var</span> <span class="variable">roads</span> = [{<span class="property">point1</span>: <span class="string">"Point Kiukiu"</span>, <span class="property">point2</span>: <span class="string">"Hanaiapa"</span>, <span class="property">length</span>: <span class="atom">19</span>},
+ {<span class="property">point1</span>: <span class="string">"Point Kiukiu"</span>, <span class="property">point2</span>: <span class="string">"Mt Feani"</span>, <span class="property">length</span>: <span class="atom">15</span>}
+ <span class="comment">/* and so on */</span>];</pre><p><a class="paragraph" href="#p4427d7bd1c17ee6a" name="p4427d7bd1c17ee6a"> </a>However, it turns out that the program, as it is working out a route,
+will very often need to get a list of all the roads that start at a
+certain location, like a person standing on a crossroads will look at
+a signpost and read "Hanaiapa: 19km, Mount Feani: 15km". It would be
+nice if this was easy (and quick) to do.</p><p><a class="paragraph" href="#p469cbb764dda878c" name="p469cbb764dda878c"> </a>With the representation given above, we have to sift through the whole
+list of roads, picking out the relevant ones, every time we want this
+signpost list. A better approach would be to store this list directly.
+For example, use an object that associates place-names with signpost
+lists:</p><pre class="code"><span class="keyword">var</span> <span class="variable">roads</span> = {<span class="string">"Point Kiukiu"</span>: [{<span class="property">to</span>: <span class="string">"Hanaiapa"</span>, <span class="property">distance</span>: <span class="atom">19</span>},
+ {<span class="property">to</span>: <span class="string">"Mt Feani"</span>, <span class="property">distance</span>: <span class="atom">15</span>},
+ {<span class="property">to</span>: <span class="string">"Taaoa"</span>, <span class="property">distance</span>: <span class="atom">15</span>}],
+ <span class="string">"Taaoa"</span>: [<span class="comment">/* et cetera */</span>]};</pre><p><a class="paragraph" href="#p6a0a21645ee7ef1d" name="p6a0a21645ee7ef1d"> </a>When we have this object, getting the roads that leave from Point
+Kiukiu is just a matter of looking at <code>roads["Point Kiukiu"]</code>.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p18358b5e37d6e44d" name="p18358b5e37d6e44d"> </a>However, this new representation does contain duplicate information:
+The road between A and B is listed both under A and under B. The first
+representation was already a lot of work to type in, this one is even
+worse.</p><p><a class="paragraph" href="#p32b789b4141e2041" name="p32b789b4141e2041"> </a>Fortunately, we have at our command the computer's talent for
+repetitive work. We can specify the roads once, and have the correct
+data structure be generated by the computer. First, initialise an
+empty object called <code>roads</code>, and write a function <code>makeRoad</code>:</p><pre class="code"><span class="keyword">var</span> <span class="variable">roads</span> = {};
+<span class="keyword">function</span> <span class="variable">makeRoad</span>(<span class="variabledef">from</span>, <span class="variabledef">to</span>, <span class="variabledef">length</span>) {
+ <span class="keyword">function</span> <span class="variabledef">addRoad</span>(<span class="variabledef">from</span>, <span class="variabledef">to</span>) {
+ <span class="keyword">if</span> (!(<span class="localvariable">from</span> in <span class="variable">roads</span>))
+ <span class="variable">roads</span>[<span class="localvariable">from</span>] = [];
+ <span class="variable">roads</span>[<span class="localvariable">from</span>].<span class="property">push</span>({<span class="property">to</span>: <span class="localvariable">to</span>, <span class="property">distance</span>: <span class="localvariable">length</span>});
+ }
+ <span class="localvariable">addRoad</span>(<span class="localvariable">from</span>, <span class="localvariable">to</span>);
+ <span class="localvariable">addRoad</span>(<span class="localvariable">to</span>, <span class="localvariable">from</span>);
+}</pre><p><a class="paragraph" href="#pf154c92fa6839c4" name="pf154c92fa6839c4"> </a>Nice, huh? Notice how the inner function, <code>addRoad</code>, uses the same
+names (<code>from</code>, <code>to</code>) for its parameters as the outer function. These
+will not interfere: inside <code>addRoad</code> they refer to <code>addRoad</code>'s
+parameters, and outside it they refer to <code>makeRoad</code>'s parameters.</p><p><a class="paragraph" href="#p398ae48177d16e36" name="p398ae48177d16e36"> </a>The <code>if</code> statement in <code>addRoad</code> makes sure that there is an array of
+destinations associated with the location named by <code>from</code>, if there
+isn't already one it puts in an empty array. This way, the next line
+can assume there is such an array and safely push the new road onto
+it.</p><p><a class="paragraph" href="#p480e2c025d9e925c" name="p480e2c025d9e925c"> </a>Now the map information looks like this:</p><pre class="code"><span class="variable">makeRoad</span>(<span class="string">"Point Kiukiu"</span>, <span class="string">"Hanaiapa"</span>, <span class="atom">19</span>);
+<span class="variable">makeRoad</span>(<span class="string">"Point Kiukiu"</span>, <span class="string">"Mt Feani"</span>, <span class="atom">15</span>);
+<span class="variable">makeRoad</span>(<span class="string">"Point Kiukiu"</span>, <span class="string">"Taaoa"</span>, <span class="atom">15</span>);
+<span class="comment">// ...</span></pre></div><hr/><div class="block"><a name="exercise1"></a><div class="exercisenum">Ex. 7.1</div><div class="exercise"><p><a class="paragraph" href="#p7164d49e80109cfc" name="p7164d49e80109cfc"> </a>In the above description, the string <code>"Point Kiukiu"</code> still occurs
+three times in a row. We could make our description even more succinct
+by allowing multiple roads to be specified in one line.</p><p><a class="paragraph" href="#p34c12b1ed0610689" name="p34c12b1ed0610689"> </a>Write a function <code>makeRoads</code> that takes any uneven number of
+arguments. The first argument is always the starting point of the
+roads, and every pair of arguments after that gives an ending point
+and a distance.</p><p><a class="paragraph" href="#p57e725f47ce6a1c3" name="p57e725f47ce6a1c3"> </a>Do not duplicate the functionality of <code>makeRoad</code>, but have <code>makeRoads</code>
+call <code>makeRoad</code> to do the actual road-making.</p></div><div class="solution"><pre class="code"><span class="keyword">function</span> <span class="variable">makeRoads</span>(<span class="variabledef">start</span>) {
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variabledef">i</span> = <span class="atom">1</span>; <span class="localvariable">i</span> < <span class="localvariable">arguments</span>.<span class="property">length</span>; <span class="localvariable">i</span> += <span class="atom">2</span>)
+ <span class="variable">makeRoad</span>(<span class="localvariable">start</span>, <span class="localvariable">arguments</span>[<span class="localvariable">i</span>], <span class="localvariable">arguments</span>[<span class="localvariable">i</span> + <span class="atom">1</span>]);
+}</pre><p><a class="paragraph" href="#p739a02fa780d1691" name="p739a02fa780d1691"> </a>This function uses one named parameter, <code>start</code>, and gets the other
+parameters from the <code>arguments</code> (quasi-) array. <code>i</code> starts at <code>1</code>
+because it has to skip this first parameter. <code>i += 2</code> is short for <code>i
+= i + 2</code>, as you might recall.</p><pre class="code"><span class="keyword">var</span> <span class="variable">roads</span> = {};
+<span class="variable">makeRoads</span>(<span class="string">"Point Kiukiu"</span>, <span class="string">"Hanaiapa"</span>, <span class="atom">19</span>,
+ <span class="string">"Mt Feani"</span>, <span class="atom">15</span>, <span class="string">"Taaoa"</span>, <span class="atom">15</span>);
+<span class="variable">makeRoads</span>(<span class="string">"Airport"</span>, <span class="string">"Hanaiapa"</span>, <span class="atom">6</span>, <span class="string">"Mt Feani"</span>, <span class="atom">5</span>,
+ <span class="string">"Atuona"</span>, <span class="atom">4</span>, <span class="string">"Mt Ootua"</span>, <span class="atom">11</span>);
+<span class="variable">makeRoads</span>(<span class="string">"Mt Temetiu"</span>, <span class="string">"Mt Feani"</span>, <span class="atom">8</span>, <span class="string">"Taaoa"</span>, <span class="atom">4</span>);
+<span class="variable">makeRoads</span>(<span class="string">"Atuona"</span>, <span class="string">"Taaoa"</span>, <span class="atom">3</span>, <span class="string">"Hanakee pearl lodge"</span>, <span class="atom">1</span>);
+<span class="variable">makeRoads</span>(<span class="string">"Cemetery"</span>, <span class="string">"Hanakee pearl lodge"</span>, <span class="atom">6</span>, <span class="string">"Mt Ootua"</span>, <span class="atom">5</span>);
+<span class="variable">makeRoads</span>(<span class="string">"Hanapaoa"</span>, <span class="string">"Mt Ootua"</span>, <span class="atom">3</span>);
+<span class="variable">makeRoads</span>(<span class="string">"Puamua"</span>, <span class="string">"Mt Ootua"</span>, <span class="atom">13</span>, <span class="string">"Point Teohotepapapa"</span>, <span class="atom">14</span>);
+
+<span class="variable">show</span>(<span class="variable">roads</span>[<span class="string">"Airport"</span>]);</pre></div></div><hr/><div class="block"><p><a class="paragraph" href="#p5722f0720bebfc58" name="p5722f0720bebfc58"> </a>We managed to considerably shorten our description of the
+road-information by defining some convenient operations. You could say
+we expressed the information more succinctly by expanding our
+vocabulary. <a name="key2"></a>Defining a 'little language'
+like this is often a very powerful technique ― when, at any time, you
+find yourself writing repetitive or redundant code, stop and try to
+come up with a vocabulary that makes it shorter and denser.</p><p><a class="paragraph" href="#p5bcecb670274fb56" name="p5bcecb670274fb56"> </a>Redundant code is not only a bore to write, it is also error-prone,
+people pay less attention when doing something that doesn't require
+them to think. On top of that, repetitive code is hard to change,
+because structure that is repeated a hundred times has to be changed a
+hundred times when it turns out to be incorrect or suboptimal.</p></div><hr/><div class="block"><p><a class="paragraph" href="#pb859cf5c2d6f2fd" name="pb859cf5c2d6f2fd"> </a>If you ran all the pieces of code above, you should now have a
+variable named <code>roads</code> that contains all the roads on the island. When
+we need the roads starting from a certain place, we could just do
+<code>roads[place]</code>. But then, when someone makes a typo in a place name,
+which is not unlikely with these names, he will get <code>undefined</code>
+instead of the array he expects, and strange errors will follow.
+Instead, we will use a function that retrieves the road arrays, and
+yells at us when we give it an unknown place name:</p><pre class="code"><span class="keyword">function</span> <span class="variable">roadsFrom</span>(<span class="variabledef">place</span>) {
+ <span class="keyword">var</span> <span class="variabledef">found</span> = <span class="variable">roads</span>[<span class="localvariable">place</span>];
+ <span class="keyword">if</span> (<span class="localvariable">found</span> == <span class="atom">undefined</span>)
+ <span class="keyword">throw</span> <span class="keyword">new</span> <span class="variable">Error</span>(<span class="string">"No place named '"</span> + <span class="localvariable">place</span> + <span class="string">"' found."</span>);
+ <span class="keyword">else</span>
+ <span class="keyword">return</span> <span class="localvariable">found</span>;
+}
+
+<span class="variable">show</span>(<span class="variable">roadsFrom</span>(<span class="string">"Puamua"</span>));</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p1e5bca09b5aefa17" name="p1e5bca09b5aefa17"> </a>Here is a first stab at a path-finding algorithm, the gambler's method:</p><pre class="code"><span class="keyword">function</span> <span class="variable">gamblerPath</span>(<span class="variabledef">from</span>, <span class="variabledef">to</span>) {
+ <span class="keyword">function</span> <span class="variabledef">randomInteger</span>(<span class="variabledef">below</span>) {
+ <span class="keyword">return</span> <span class="variable">Math</span>.<span class="property">floor</span>(<span class="variable">Math</span>.<span class="property">random</span>() * <span class="localvariable">below</span>);
+ }
+ <span class="keyword">function</span> <span class="variabledef">randomDirection</span>(<span class="variabledef">from</span>) {
+ <span class="keyword">var</span> <span class="variabledef">options</span> = <span class="variable">roadsFrom</span>(<span class="localvariable">from</span>);
+ <span class="keyword">return</span> <span class="localvariable">options</span>[<span class="localvariable">randomInteger</span>(<span class="localvariable">options</span>.<span class="property">length</span>)].<span class="property">to</span>;
+ }
+
+ <span class="keyword">var</span> <span class="variabledef">path</span> = [];
+ <span class="keyword">while</span> (<span class="atom">true</span>) {
+ <span class="localvariable">path</span>.<span class="property">push</span>(<span class="localvariable">from</span>);
+ <span class="keyword">if</span> (<span class="localvariable">from</span> == <span class="localvariable">to</span>)
+ <span class="keyword">break</span>;
+ <span class="localvariable">from</span> = <span class="localvariable">randomDirection</span>(<span class="localvariable">from</span>);
+ }
+ <span class="keyword">return</span> <span class="localvariable">path</span>;
+}
+
+<span class="variable">show</span>(<span class="variable">gamblerPath</span>(<span class="string">"Hanaiapa"</span>, <span class="string">"Mt Feani"</span>));</pre><p><a class="paragraph" href="#p4d05527b8c74ee0d" name="p4d05527b8c74ee0d"> </a>At every split in the road, the gambler rolls his dice to decide which
+road he shall take. If the dice sends him back the way he came, so be
+it. Sooner or later, he will arrive at his destination, since all
+places on the island are connected by roads.</p><p><a class="paragraph" href="#p3f973913a349c411" name="p3f973913a349c411"> </a>The most confusing line is probably the one containing
+<a name="key3"></a><code>Math.random</code>. This function returns a pseudo-random<a class="footref" href="#footnote1">1</a> number
+between 0 and 1. Try calling it a few times from the console, it will
+(most likely) give you a different number every time. The function
+<code>randomInteger</code> multiplies this number by the argument it is given,
+and rounds the result down with <code>Math.floor</code>. Thus, for example,
+<code>randomInteger(3)</code> will produce the number <code>0</code>, <code>1</code>, or <code>2</code>.</p></div><hr/><div class="block"><p><a class="paragraph" href="#pe69ef526948e099" name="pe69ef526948e099"> </a>The gambler's method is the way to go for those who abhor structure
+and planning, who desperately search for adventure. We set out to
+write a program that could find the <em>shortest</em> route between places
+though, so something else will be needed.</p><p><a class="paragraph" href="#p44756e2f577b7a69" name="p44756e2f577b7a69"> </a>A very straightforward approach to solving such a problem is called
+'<a name="key4"></a>generate and test'. It goes like this:</p><ol><li>Generate all possible routes.</li><li>In this set, find the shortest one that actually connects the start point to the end point.</li></ol><p><a class="paragraph" href="#p74f159b15463fb19" name="p74f159b15463fb19"> </a>Step two is not hard. Step one is a little problematic. If you allow
+routes with circles in them, there is an infinite amount of routes. Of
+course, routes with circles in them are unlikely to be the shortest
+route to anywhere, and routes that do not start at the start point do
+not have to be considered either. For a small graph like Hiva Oa, it
+should be possible to generate all non-cyclic (circle-free) routes
+starting from a certain point.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p145242a550d748c8" name="p145242a550d748c8"> </a>But first, we will need some new tools. The first is a function named
+<code>member</code>, which is used to determine whether an element is found
+within an array. The route will be kept as an array of names, and when
+arriving at a new place, the algorithm calls <code>member</code> to check whether
+we have been at that place already. It could look like this:</p><pre class="code"><span class="keyword">function</span> <span class="variable">member</span>(<span class="variabledef">array</span>, <span class="variabledef">value</span>) {
+ <span class="keyword">var</span> <span class="variabledef">found</span> = <span class="atom">false</span>;
+ <span class="variable">forEach</span>(<span class="localvariable">array</span>, <span class="keyword">function</span>(<span class="variabledef">element</span>) {
+ <span class="keyword">if</span> (<span class="localvariable">element</span> === <span class="localvariable">value</span>)
+ <span class="localvariable">found</span> = <span class="atom">true</span>;
+ });
+ <span class="keyword">return</span> <span class="localvariable">found</span>;
+}
+
+<span class="variable">print</span>(<span class="variable">member</span>([<span class="atom">6</span>, <span class="atom">7</span>, <span class="string">"Bordeaux"</span>], <span class="atom">7</span>));</pre><p><a class="paragraph" href="#p49342b38f17b6aca" name="p49342b38f17b6aca"> </a>However, this will go over the whole array, even if the value is found
+immediately at the first position. What wastefulness. When using a
+<code>for</code> loop, you can use the <code>break</code> statement to jump out of it, but
+in a <code>forEach</code> construct this will not work, because the body of the
+loop is a function, and <code>break</code> statements do not jump out of
+functions. One solution could be to adjust <code>forEach</code> to recognise a
+certain kind of exceptions as signalling a break.</p><pre class="code"><span class="keyword">var</span> <span class="variable">Break</span> = {<span class="property">toString</span>: <span class="keyword">function</span>() {<span class="keyword">return</span> <span class="string">"Break"</span>;}};
+
+<span class="keyword">function</span> <span class="variable">forEach</span>(<span class="variabledef">array</span>, <span class="variabledef">action</span>) {
+ <span class="keyword">try</span> {
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variabledef">i</span> = <span class="atom">0</span>; <span class="localvariable">i</span> < <span class="localvariable">array</span>.<span class="property">length</span>; <span class="localvariable">i</span>++)
+ <span class="localvariable">action</span>(<span class="localvariable">array</span>[<span class="localvariable">i</span>]);
+ }
+ <span class="keyword">catch</span> (<span class="variabledef">exception</span>) {
+ <span class="keyword">if</span> (<span class="localvariable">exception</span> != <span class="variable">Break</span>)
+ <span class="keyword">throw</span> <span class="localvariable">exception</span>;
+ }
+}</pre><p><a class="paragraph" href="#p3074f95998f948d0" name="p3074f95998f948d0"> </a>Now, if the <code>action</code> function throws <code>Break</code>, <code>forEach</code> will absorb
+the exception and stop looping. The object stored in the variable
+<code>Break</code> is used purely as a thing to compare with. The only reason I
+gave it a <code>toString</code> property is that this might be useful to figure
+out what kind of strange value you are dealing with if you somehow end
+up with a <code>Break</code> exception outside of a <code>forEach</code>.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p33f341c6a34dd74f" name="p33f341c6a34dd74f"> </a>Having a way to break out of <code>forEach</code> loops can be very useful, but
+in the case of the <code>member</code> function the result is still rather ugly,
+because you need to specifically store the result and later return it.
+We could add yet another kind of exception, <code>Return</code>, which can be
+given a <code>value</code> property, and have <code>forEach</code> return this value when
+such an exception is thrown, but this would be terribly ad-hoc and
+messy. What we really need is a whole new higher-order function,
+called <a name="key5"></a><code>any</code> (or sometimes <code>some</code>). It looks like this:</p><pre class="code"><span class="keyword">function</span> <span class="variable">any</span>(<span class="variabledef">test</span>, <span class="variabledef">array</span>) {
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variabledef">i</span> = <span class="atom">0</span>; <span class="localvariable">i</span> < <span class="localvariable">array</span>.<span class="property">length</span>; <span class="localvariable">i</span>++) {
+ <span class="keyword">var</span> <span class="variabledef">found</span> = <span class="localvariable">test</span>(<span class="localvariable">array</span>[<span class="localvariable">i</span>]);
+ <span class="keyword">if</span> (<span class="localvariable">found</span>)
+ <span class="keyword">return</span> <span class="localvariable">found</span>;
+ }
+ <span class="keyword">return</span> <span class="atom">false</span>;
+}
+
+<span class="keyword">function</span> <span class="variable">member</span>(<span class="variabledef">array</span>, <span class="variabledef">value</span>) {
+ <span class="keyword">return</span> <span class="variable">any</span>(<span class="variable">partial</span>(<span class="variable">op</span>[<span class="string">"==="</span>], <span class="localvariable">value</span>), <span class="localvariable">array</span>);
+}
+
+<span class="variable">print</span>(<span class="variable">member</span>([<span class="string">"Fear"</span>, <span class="string">"Loathing"</span>], <span class="string">"Denial"</span>));</pre><p><a class="paragraph" href="#p4bf8bb60fb252f3e" name="p4bf8bb60fb252f3e"> </a><code>any</code> goes over the elements in an array, from left to right, and
+applies the test function to them. The first time this returns a
+true-ish value, it returns that value. If no true-ish value is found,
+<code>false</code> is returned. Calling <code>any(test, array)</code> is more or less
+equivalent to doing <code>test(array[0]) || test(array[1]) || ...</code>
+etcetera.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p634754d27023742a" name="p634754d27023742a"> </a>Just like <code>&&</code> is the companion of <code>||</code>, <code>any</code> has a companion called
+<a name="key6"></a><code>every</code>:</p><pre class="code"><span class="keyword">function</span> <span class="variable">every</span>(<span class="variabledef">test</span>, <span class="variabledef">array</span>) {
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variabledef">i</span> = <span class="atom">0</span>; <span class="localvariable">i</span> < <span class="localvariable">array</span>.<span class="property">length</span>; <span class="localvariable">i</span>++) {
+ <span class="keyword">var</span> <span class="variabledef">found</span> = <span class="localvariable">test</span>(<span class="localvariable">array</span>[<span class="localvariable">i</span>]);
+ <span class="keyword">if</span> (!<span class="localvariable">found</span>)
+ <span class="keyword">return</span> <span class="localvariable">found</span>;
+ }
+ <span class="keyword">return</span> <span class="atom">true</span>;
+}
+
+<span class="variable">show</span>(<span class="variable">every</span>(<span class="variable">partial</span>(<span class="variable">op</span>[<span class="string">"!="</span>], <span class="atom">0</span>), [<span class="atom">1</span>, <span class="atom">2</span>, -<span class="atom">1</span>]));</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p25577b9a2fefc6bd" name="p25577b9a2fefc6bd"> </a>Another function we will need is <code>flatten</code>. This function takes an
+array of arrays, and puts the elements of the arrays together in one
+big array.</p><pre class="code"> <span class="keyword">function</span> <span class="variable">flatten</span>(<span class="variabledef">arrays</span>) {
+ <span class="keyword">var</span> <span class="variabledef">result</span> = [];
+ <span class="variable">forEach</span>(<span class="localvariable">arrays</span>, <span class="keyword">function</span> (<span class="variabledef">array</span>) {
+ <span class="variable">forEach</span>(<span class="localvariable">array</span>, <span class="keyword">function</span> (<span class="variabledef">element</span>){<span class="localvariable">result</span>.<span class="property">push</span>(<span class="localvariable">element</span>);});
+ });
+ <span class="keyword">return</span> <span class="localvariable">result</span>;
+ }</pre><p><a class="paragraph" href="#p420e7218c62b54aa" name="p420e7218c62b54aa"> </a>The same could have been done using the <code>concat</code> method and some kind
+of <code>reduce</code>, but this would be less efficient. Just like repeatedly
+concatenating strings together is slower than putting them into an
+array and then calling <code>join</code>, repeatedly concatenating arrays
+produces a lot of unnecessary intermediary array values.</p></div><hr/><div class="block"><a name="exercise2"></a><div class="exercisenum">Ex. 7.2</div><div class="exercise"><p><a class="paragraph" href="#p4195e954f55beb3a" name="p4195e954f55beb3a"> </a>Before starting to generate routes, we need one more higher-order
+function. This one is called <a name="key7"></a><code>filter</code>. Like <code>map</code>, it takes a
+function and an array as arguments, and produces a new array, but
+instead of putting the results of calling the function in the new
+array, it produces an array with only those values from the old array
+for which the given function returns a true-like value. Write this
+function.</p></div><div class="solution"><pre class="code"><span class="keyword">function</span> <span class="variable">filter</span>(<span class="variabledef">test</span>, <span class="variabledef">array</span>) {
+ <span class="keyword">var</span> <span class="variabledef">result</span> = [];
+ <span class="variable">forEach</span>(<span class="localvariable">array</span>, <span class="keyword">function</span> (<span class="variabledef">element</span>) {
+ <span class="keyword">if</span> (<span class="localvariable">test</span>(<span class="localvariable">element</span>))
+ <span class="localvariable">result</span>.<span class="property">push</span>(<span class="localvariable">element</span>);
+ });
+ <span class="keyword">return</span> <span class="localvariable">result</span>;
+}
+
+<span class="variable">show</span>(<span class="variable">filter</span>(<span class="variable">partial</span>(<span class="variable">op</span>[<span class="string">">"</span>], <span class="atom">5</span>), [<span class="atom">0</span>, <span class="atom">4</span>, <span class="atom">8</span>, <span class="atom">12</span>]));</pre><p><a class="paragraph" href="#p600d990341cb6b99" name="p600d990341cb6b99"> </a>(If the result of that application of <code>filter</code> surprises you, remember
+that the argument given to <code>partial</code> is used as the <em>first</em> argument
+of the function, so it ends up to the left of the <code>></code>.)</p></div></div><hr/><div class="block"><p><a class="paragraph" href="#p62dacdece974027c" name="p62dacdece974027c"> ¶ </a>Imagine what an algorithm to generate routes would look like ― it
+starts at the starting location, and starts to generate a route for
+every road leaving there. At the end of each of these roads it
+continues to generate more routes. It doesn't run along one road, it
+branches out. Because of this, <a name="key8"></a>recursion is a natural way to model
+it.</p><pre class="code"><span class="keyword">function</span> <span class="variable">possibleRoutes</span>(<span class="variabledef">from</span>, <span class="variabledef">to</span>) {
+ <span class="keyword">function</span> <span class="variabledef">findRoutes</span>(<span class="variabledef">route</span>) {
+ <span class="keyword">function</span> <span class="variabledef">notVisited</span>(<span class="variabledef">road</span>) {
+ <span class="keyword">return</span> !<span class="variable">member</span>(<span class="localvariable">route</span>.<span class="property">places</span>, <span class="localvariable">road</span>.<span class="property">to</span>);
+ }
+ <span class="keyword">function</span> <span class="variabledef">continueRoute</span>(<span class="variabledef">road</span>) {
+ <span class="keyword">return</span> <span class="localvariable">findRoutes</span>({<span class="property">places</span>: <span class="localvariable">route</span>.<span class="property">places</span>.<span class="property">concat</span>([<span class="localvariable">road</span>.<span class="property">to</span>]),
+ <span class="property">length</span>: <span class="localvariable">route</span>.<span class="property">length</span> + <span class="localvariable">road</span>.<span class="property">distance</span>});
+ }
+
+ <span class="keyword">var</span> <span class="variabledef">end</span> = <span class="localvariable">route</span>.<span class="property">places</span>[<span class="localvariable">route</span>.<span class="property">places</span>.<span class="property">length</span> - <span class="atom">1</span>];
+ <span class="keyword">if</span> (<span class="localvariable">end</span> == <span class="localvariable">to</span>)
+ <span class="keyword">return</span> [<span class="localvariable">route</span>];
+ <span class="keyword">else</span>
+ <span class="keyword">return</span> <span class="variable">flatten</span>(<span class="variable">map</span>(<span class="localvariable">continueRoute</span>, <span class="variable">filter</span>(<span class="localvariable">notVisited</span>,
+ <span class="variable">roadsFrom</span>(<span class="localvariable">end</span>))));
+ }
+ <span class="keyword">return</span> <span class="localvariable">findRoutes</span>({<span class="property">places</span>: [<span class="localvariable">from</span>], <span class="property">length</span>: <span class="atom">0</span>});
+}
+
+<span class="variable">show</span>(<span class="variable">possibleRoutes</span>(<span class="string">"Point Teohotepapapa"</span>, <span class="string">"Point Kiukiu"</span>).<span class="property">length</span>);
+<span class="variable">show</span>(<span class="variable">possibleRoutes</span>(<span class="string">"Hanapaoa"</span>, <span class="string">"Mt Ootua"</span>));</pre><p><a class="paragraph" href="#p387f53b9b4c55332" name="p387f53b9b4c55332"> </a>The function returns an array of route objects, each of which contains
+an array of places that the route passes, and a length. <code>findRoutes</code>
+recursively continues a route, returning an array with every possible
+extension of that route. When the end of a route is the place where we
+want to go, it just returns that route, since continuing past that
+place would be pointless. If it is another place, we must go on. The
+<code>flatten</code>/<code>map</code>/<code>filter</code> line is probably the hardest to read. This is
+what it says: 'Take all the roads going from the current location,
+discard the ones that go to places that this route has already
+visited. Continue each of these roads, which will give an array of
+finished routes for each of them, then put all these routes into a
+single big array that we return.'</p><p><a class="paragraph" href="#p60218e4263e58450" name="p60218e4263e58450"> </a>That line does a lot. This is why good abstractions help: They allow
+you to say complicated things without typing screenfulls of code.</p><p><a class="paragraph" href="#p162cf311167c8212" name="p162cf311167c8212"> </a>Doesn't this recurse forever, seeing how it keeps calling itself (via
+<code>continueRoute</code>)? No, at some point, all outgoing roads will go to
+places that a route has already passed, and the result of <code>filter</code>
+will be an empty array. Mapping over an empty array produces an empty
+array, and flattening that still gives an empty array. So calling
+<code>findRoutes</code> on a dead end produces an empty array, meaning 'there are
+no ways to continue this route'.</p><p><a class="paragraph" href="#p11bdf742e1ec64d1" name="p11bdf742e1ec64d1"> </a>Notice that places are appended to routes by using <a name="key9"></a><code>concat</code>, not
+<a name="key10"></a><code>push</code>. The <code>concat</code> method creates a new array, while <code>push</code>
+modifies the existing array. Because the function might branch off
+several routes from a single partial route, we must not modify the
+array that represents the original route, because it must be used
+several times.</p></div><hr/><div class="block"><a name="exercise3"></a><div class="exercisenum">Ex. 7.3</div><div class="exercise"><p><a class="paragraph" href="#p113c68095cc0f450" name="p113c68095cc0f450"> </a>Now that we have all possible routes, let us try to find the shortest
+one. Write a function <code>shortestRoute</code> that, like <code>possibleRoutes</code>,
+takes the names of a starting and ending location as arguments. It
+returns a single route object, of the type that <code>possibleRoutes</code>
+produces.</p></div><div class="solution"><pre class="code"><span class="keyword">function</span> <span class="variable">shortestRoute</span>(<span class="variabledef">from</span>, <span class="variabledef">to</span>) {
+ <span class="keyword">var</span> <span class="variabledef">currentShortest</span> = <span class="atom">null</span>;
+ <span class="variable">forEach</span>(<span class="variable">possibleRoutes</span>(<span class="localvariable">from</span>, <span class="localvariable">to</span>), <span class="keyword">function</span>(<span class="variabledef">route</span>) {
+ <span class="keyword">if</span> (!<span class="localvariable">currentShortest</span> || <span class="localvariable">currentShortest</span>.<span class="property">length</span> > <span class="localvariable">route</span>.<span class="property">length</span>)
+ <span class="localvariable">currentShortest</span> = <span class="localvariable">route</span>;
+ });
+ <span class="keyword">return</span> <span class="localvariable">currentShortest</span>;
+}</pre><p><a class="paragraph" href="#p6bd1ea7e4e1efe76" name="p6bd1ea7e4e1efe76"> </a>The tricky thing in 'minimising' or 'maximising' algorithms is to not
+screw up when given an empty array. In this case, we happen to know
+that there is at least one road between every two places, so we could
+just ignore it. But that would be a bit lame. What if the road from
+Puamua to Mount Ootua, which is steep and muddy, is washed away by a
+rainstorm? It would be a shame if this caused our function to break as
+well, so it takes care to return <code>null</code> when no routes are found.</p><p><a class="paragraph" href="#p30fff685a845eab9" name="p30fff685a845eab9"> </a>Then, the very functional, abstract-everything-we-can approach:</p><pre class="code"><span class="keyword">function</span> <span class="variable">minimise</span>(<span class="variabledef">func</span>, <span class="variabledef">array</span>) {
+ <span class="keyword">var</span> <span class="variabledef">minScore</span> = <span class="atom">null</span>;
+ <span class="keyword">var</span> <span class="variabledef">found</span> = <span class="atom">null</span>;
+ <span class="variable">forEach</span>(<span class="localvariable">array</span>, <span class="keyword">function</span>(<span class="variabledef">element</span>) {
+ <span class="keyword">var</span> <span class="variabledef">score</span> = <span class="localvariable">func</span>(<span class="localvariable">element</span>);
+ <span class="keyword">if</span> (<span class="localvariable">minScore</span> == <span class="atom">null</span> || <span class="localvariable">score</span> < <span class="localvariable">minScore</span>) {
+ <span class="localvariable">minScore</span> = <span class="localvariable">score</span>;
+ <span class="localvariable">found</span> = <span class="localvariable">element</span>;
+ }
+ });
+ <span class="keyword">return</span> <span class="localvariable">found</span>;
+}
+
+<span class="keyword">function</span> <span class="variable">getProperty</span>(<span class="variabledef">propName</span>) {
+ <span class="keyword">return</span> <span class="keyword">function</span>(<span class="variabledef">object</span>) {
+ <span class="keyword">return</span> <span class="localvariable">object</span>[<span class="localvariable">propName</span>];
+ };
+}
+
+<span class="keyword">function</span> <span class="variable">shortestRoute</span>(<span class="variabledef">from</span>, <span class="variabledef">to</span>) {
+ <span class="keyword">return</span> <span class="variable">minimise</span>(<span class="variable">getProperty</span>(<span class="string">"length"</span>), <span class="variable">possibleRoutes</span>(<span class="localvariable">from</span>, <span class="localvariable">to</span>));
+}</pre><p><a class="paragraph" href="#p7d170cb50c40bf1c" name="p7d170cb50c40bf1c"> </a>Unfortunately, it is three times longer than the other version. In
+programs where you need to minimise several things it might be a good
+idea to write the generic algorithm like this, so you can re-use it.
+In most cases the first version is probably good enough.</p><p><a class="paragraph" href="#p3d296aaee3135ce5" name="p3d296aaee3135ce5"> </a>Note the <a name="key11"></a><code>getProperty</code> function though, it is often useful when
+doing functional programming with objects.</p></div></div><hr/><div class="block"><p><a class="paragraph" href="#p6cd3134a22b4e870" name="p6cd3134a22b4e870"> </a>Let us see what route our algorithm comes up with between Point Kiukiu
+and Point Teohotepapapa...</p><pre class="code"><span class="variable">show</span>(<span class="variable">shortestRoute</span>(<span class="string">"Point Kiukiu"</span>, <span class="string">"Point Teohotepapapa"</span>).<span class="property">places</span>);</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p3c100fea3e9f3555" name="p3c100fea3e9f3555"> </a>On a small island like Hiva Oa, it is not too much work to generate
+all possible routes. If you try to do that on a reasonably detailed
+map of, say, Belgium, it is going to take an absurdly long time, not
+to mention an absurd amount of memory. Still, you have probably seen
+those online route-planners. These give you a more or less optimal
+route through a gigantic maze of roads in just a few seconds. How do
+they do it?</p><p><a class="paragraph" href="#p1ec650eca82bbdbf" name="p1ec650eca82bbdbf"> </a>If you are paying attention, you may have noticed that it is not
+necessary to generate all routes all the way to the end. If we start
+comparing routes <em>while</em> we are building them, we can avoid building
+this big set of routes, and, as soon as we have found a single route
+to our destination, we can stop extending routes that are already
+longer than that route.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p1b8d136b82118e91" name="p1b8d136b82118e91"> </a>To try this out, we will use a 20 by 20 grid as our map:</p><div class="illustration"><img src="img/height.png"/></div><p><a class="paragraph" href="#p179740b3947d7bde" name="p179740b3947d7bde"> </a>What you see here is an elevation map of a mountain landscape. The
+yellow spots are the peaks, and the blue spots the valleys. The area
+is divided into squares with a size of a hundred meters. We have at
+our disposal a function <code>heightAt</code>, which can give us the height, in
+meters, of any square on that map, where squares are represented by
+objects with <code>x</code> and <code>y</code> properties.</p><pre class="code"><span class="variable">print</span>(<span class="variable">heightAt</span>({<span class="property">x</span>: <span class="atom">0</span>, <span class="property">y</span>: <span class="atom">0</span>}));
+<span class="variable">print</span>(<span class="variable">heightAt</span>({<span class="property">x</span>: <span class="atom">11</span>, <span class="property">y</span>: <span class="atom">18</span>}));</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p646f6b1177112caf" name="p646f6b1177112caf"> </a>We want to cross this landscape, on foot, from the top left to the
+bottom right. A grid can be approached like a graph. Every square is a
+node, which is connected to the squares around it.</p><p><a class="paragraph" href="#p20bce21c7475a861" name="p20bce21c7475a861"> </a>We do not like wasting energy, so we would prefer to take the easiest
+route possible. Going uphill is heavier than going downhill, and going
+downhill is heavier than going level<a class="footref" href="#footnote2">2</a>. This function calculates the
+amount of 'weighted meters', between two adjacent squares, which
+represents how tired you get from walking (or climbing) between them.
+Going uphill is counted as twice as heavy as going downhill.</p><pre class="code"><span class="keyword">function</span> <span class="variable">weightedDistance</span>(<span class="variabledef">pointA</span>, <span class="variabledef">pointB</span>) {
+ <span class="keyword">var</span> <span class="variabledef">heightDifference</span> = <span class="variable">heightAt</span>(<span class="localvariable">pointB</span>) - <span class="variable">heightAt</span>(<span class="localvariable">pointA</span>);
+ <span class="keyword">var</span> <span class="variabledef">climbFactor</span> = (<span class="localvariable">heightDifference</span> < <span class="atom">0</span> ? <span class="atom">1</span> : <span class="atom">2</span>);
+ <span class="keyword">var</span> <span class="variabledef">flatDistance</span> = (<span class="localvariable">pointA</span>.<span class="property">x</span> == <span class="localvariable">pointB</span>.<span class="property">x</span> || <span class="localvariable">pointA</span>.<span class="property">y</span> == <span class="localvariable">pointB</span>.<span class="property">y</span> ? <span class="atom">100</span> : <span class="atom">141</span>);
+ <span class="keyword">return</span> <span class="localvariable">flatDistance</span> + <span class="localvariable">climbFactor</span> * <span class="variable">Math</span>.<span class="property">abs</span>(<span class="localvariable">heightDifference</span>);
+}</pre><p><a class="paragraph" href="#p42069c51328e70b" name="p42069c51328e70b"> </a>Note the <code>flatDistance</code> calculation. If the two points are on the same
+row or column, they are right next to each other, and the distance
+between them is a hundred meters. Otherwise, they are assumed to
+be diagonally adjacent, and the diagonal distance between two
+squares of this size is a hundred times the square root of two, which
+is approximately <code>141</code>. One is not allowed to call this function for
+squares that are further than one step apart. (It could double-check
+this... but it is too lazy.)</p></div><hr/><div class="block"><p><a class="paragraph" href="#p7e47d79c78483ec4" name="p7e47d79c78483ec4"> </a>Points on the map are represented by objects containing <code>x</code> and <code>y</code>
+properties. These three functions are useful when working with such
+objects:</p><pre class="code"><span class="keyword">function</span> <span class="variable">point</span>(<span class="variabledef">x</span>, <span class="variabledef">y</span>) {
+ <span class="keyword">return</span> {<span class="property">x</span>: <span class="localvariable">x</span>, <span class="property">y</span>: <span class="localvariable">y</span>};
+}
+
+<span class="keyword">function</span> <span class="variable">addPoints</span>(<span class="variabledef">a</span>, <span class="variabledef">b</span>) {
+ <span class="keyword">return</span> <span class="variable">point</span>(<span class="localvariable">a</span>.<span class="property">x</span> + <span class="localvariable">b</span>.<span class="property">x</span>, <span class="localvariable">a</span>.<span class="property">y</span> + <span class="localvariable">b</span>.<span class="property">y</span>);
+}
+
+<span class="keyword">function</span> <span class="variable">samePoint</span>(<span class="variabledef">a</span>, <span class="variabledef">b</span>) {
+ <span class="keyword">return</span> <span class="localvariable">a</span>.<span class="property">x</span> == <span class="localvariable">b</span>.<span class="property">x</span> && <span class="localvariable">a</span>.<span class="property">y</span> == <span class="localvariable">b</span>.<span class="property">y</span>;
+}
+
+<span class="variable">show</span>(<span class="variable">samePoint</span>(<span class="variable">addPoints</span>(<span class="variable">point</span>(<span class="atom">10</span>, <span class="atom">10</span>), <span class="variable">point</span>(<span class="atom">4</span>, -<span class="atom">2</span>)),
+ <span class="variable">point</span>(<span class="atom">14</span>, <span class="atom">8</span>)));</pre></div><hr/><div class="block"><a name="exercise4"></a><div class="exercisenum">Ex. 7.4</div><div class="exercise"><p><a class="paragraph" href="#p49859a249a4b2656" name="p49859a249a4b2656"> </a>If we are going to find routes through this map, we will again need a
+function to create 'signposts', lists of directions that can be taken
+from a given point. Write a function <code>possibleDirections</code>, which takes
+a point object as argument and returns an array of nearby points. We
+can only move to adjacent points, both straight and diagonally, so
+squares have a maximum of eight neighbours. Take care not to return
+squares that lie outside of the map. For all we know the edge of the
+map might be the edge of the world.</p></div><div class="solution"><pre class="code"><span class="keyword">function</span> <span class="variable">possibleDirections</span>(<span class="variabledef">from</span>) {
+ <span class="keyword">var</span> <span class="variabledef">mapSize</span> = <span class="atom">20</span>;
+ <span class="keyword">function</span> <span class="variabledef">insideMap</span>(<span class="variabledef">point</span>) {
+ <span class="keyword">return</span> <span class="localvariable">point</span>.<span class="property">x</span> >= <span class="atom">0</span> && <span class="localvariable">point</span>.<span class="property">x</span> < <span class="localvariable">mapSize</span> &&
+ <span class="localvariable">point</span>.<span class="property">y</span> >= <span class="atom">0</span> && <span class="localvariable">point</span>.<span class="property">y</span> < <span class="localvariable">mapSize</span>;
+ }
+
+ <span class="keyword">var</span> <span class="variabledef">directions</span> = [<span class="variable">point</span>(-<span class="atom">1</span>, <span class="atom">0</span>), <span class="variable">point</span>(<span class="atom">1</span>, <span class="atom">0</span>), <span class="variable">point</span>(<span class="atom">0</span>, -<span class="atom">1</span>),
+ <span class="variable">point</span>(<span class="atom">0</span>, <span class="atom">1</span>), <span class="variable">point</span>(-<span class="atom">1</span>, -<span class="atom">1</span>), <span class="variable">point</span>(-<span class="atom">1</span>, <span class="atom">1</span>),
+ <span class="variable">point</span>(<span class="atom">1</span>, <span class="atom">1</span>), <span class="variable">point</span>(<span class="atom">1</span>, -<span class="atom">1</span>)];
+ <span class="keyword">return</span> <span class="variable">filter</span>(<span class="localvariable">insideMap</span>, <span class="variable">map</span>(<span class="variable">partial</span>(<span class="variable">addPoints</span>, <span class="localvariable">from</span>),
+ <span class="localvariable">directions</span>));
+}
+
+<span class="variable">show</span>(<span class="variable">possibleDirections</span>(<span class="variable">point</span>(<span class="atom">0</span>, <span class="atom">0</span>)));</pre><p><a class="paragraph" href="#p7c1a3e8412416bc8" name="p7c1a3e8412416bc8"> </a>I created a variable <code>mapSize</code>, for the sole purpose of not having to
+write <code>20</code> two times. If, at some other time, we want to use this same
+function for another map, it would be clumsy if the code was full of
+<code>20</code>s, which all have to be changed. We could even go as far as making
+the <code>mapSize</code> an argument to <code>possibleDirections</code>, so we can use the
+function for different maps without changing it. I judged that that
+was not necessary in this case though, such things can always be
+changed when the need arises.</p><p><a class="paragraph" href="#p5d2c9b5e70e2749d" name="p5d2c9b5e70e2749d"> </a>Then why didn't I also add a variable to hold the <code>0</code>, which also
+occurs two times? I assumed that maps always start at <code>0</code>, so this one
+is unlikely to ever change, and using a variable for it only adds
+noise.</p></div></div><hr/><div class="block"><p><a class="paragraph" href="#p70789a0cfb7a7a6a" name="p70789a0cfb7a7a6a"> </a>To find a route on this map without having our browser cut off the
+program because it takes too long to finish, we have to stop our
+amateurish attempts and implement a serious algorithm. A lot of work
+has gone into problems like this in the past, and many solutions have
+been designed (some brilliant, others useless). A very popular and
+efficient one is called <a name="key12"></a>A* (pronounced A-star). We will spend the
+rest of the chapter implementing an A* route-finding function for our
+map.</p><p><a class="paragraph" href="#p3f39b88a3fe7ae6c" name="p3f39b88a3fe7ae6c"> </a>Before I get to the algorithm itself, let me tell you a bit more about
+the problem it solves. The trouble with searching routes through
+graphs is that, in big graphs, there are an awful lot of them. Our
+Hiva Oa path-finder showed that, when the graph is small, all we needed
+to do was to make sure our paths didn't revisit points they had
+already passed. On our new map, this is not enough anymore.</p><p><a class="paragraph" href="#p52128e90b57b21e9" name="p52128e90b57b21e9"> </a>The fundamental problem is that there is too much room for going in
+the wrong direction. Unless we somehow manage to steer our exploration
+of paths towards the goal, a choice we make for continuing a given
+path is more likely to go in the wrong direction than in the right
+direction. If you keep generating paths like that, you end up with an
+enormous amount of paths, and even if one of them accidentally reaches
+the end point, you do not know whether that is the shortest path.</p><p><a class="paragraph" href="#p19b4c229e6854121" name="p19b4c229e6854121"> </a>So what you want to do is explore directions that are likely to get
+you to the end point first. On a grid like our map, you can get a
+rough estimate of how good a path is by checking how long it is and
+how close its end is to the end point. By adding path length and an
+estimate of the distance it still has to go, you can get a rough idea
+of which paths are promising. If you extend promising paths first, you
+are less likely to waste time on useless ones.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p605aef04ef4aade7" name="p605aef04ef4aade7"> </a>But that still is not enough. If our map was of a perfectly flat
+plane, the path that looked promising would almost always be the best
+one, and we could use the above method to walk right to our goal. But
+we have valleys and hillsides blocking our paths, so it is hard to
+tell in advance which direction will be the most efficient path.
+Because of this, we still end up having to explore way too many paths.</p><p><a class="paragraph" href="#p7e13f30083397647" name="p7e13f30083397647"> </a>To correct this, we can make clever use of the fact that we are
+constantly exploring the most promising path first. Once we have
+determined that path A is the best way to get to point X, we can
+remember that. When, later on, path B also gets to point X, we know
+that it is not the best route, so we do not have to explore it
+further. This can prevent our program from building a lot of pointless
+paths.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p4933e09f45bed7ec" name="p4933e09f45bed7ec"> </a>The algorithm, then, goes something like this...</p><p><a class="paragraph" href="#p7429b315086105d4" name="p7429b315086105d4"> </a>There are two pieces of data to keep track of. The first one is called
+the open list, it contains the partial routes that must still be
+explored. Each route has a score, which is calculated by adding its
+length to its estimated distance from the goal. This estimate must
+always be optimistic, it should never overestimate the distance. The
+second is a set of nodes that we have seen, together with the shortest
+partial route that got us there. This one we will call the reached
+list. We start by adding a route that contains only the starting node
+to the open list, and recording it in the reached list.</p><p><a class="paragraph" href="#p54f2f4829fa45297" name="p54f2f4829fa45297"> </a>Then, as long as there are any nodes in the open list, we take out the
+one that has the lowest (best) score, and find the ways in which it
+can be continued (by calling <code>possibleDirections</code>). For each of the
+nodes this returns, we create a new route by appending it to our
+original route, and adjusting the length of the route using
+<code>weightedDistance</code>. The endpoint of each of these new routes is then
+looked up in the reached list.</p><p><a class="paragraph" href="#p225b77195287d4ca" name="p225b77195287d4ca"> </a>If the node is not in the reached list yet, it means we have not seen
+it before, and we add the new route to the open list and record it in
+the reached list. If we <em>had</em> seen it before, we compare the score of
+the new route to the score of the route in the reached list. If the
+new route is shorter, we replace the existing route with the new one.
+Otherwise, we discard the new route, since we have already seen a
+better way to get to that point.</p><p><a class="paragraph" href="#p15f21832c000f5e4" name="p15f21832c000f5e4"> </a>We continue doing this until the route we fetch from the open list
+ends at the goal node, in which case we have found our route, or until
+the open list is empty, in which case we have found out that there is
+no route. In our case the map contains no unsurmountable obstacles, so
+there is always a route.</p><p><a class="paragraph" href="#p6e3b0a4bdd0b7c01" name="p6e3b0a4bdd0b7c01"> </a>How do we know that the first full route that we get from the open
+list is also the shortest one? This is a result of the fact that we
+only look at a route when it has the lowest score. The score of a
+route is its actual length plus an <em>optimistic</em> estimate of the
+remaining length. This means that if a route has the lowest score in
+the open list, it is always the best route to its current endpoint ―
+it is impossible for another route to later find a better way to that
+point, because if it were better, its score would have been lower.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p14edd10217b17d31" name="p14edd10217b17d31"> </a>Try not to get frustrated when the fine points of why this works are
+still eluding you. When thinking about algorithms like this, having
+seen 'something like it' before helps a lot, it gives you a point of
+reference to compare the approach to. Beginning programmers have to do
+without such a point of reference, which makes it rather easy to get
+lost. Just realise that this is advanced stuff, globally read over the
+rest of the chapter, and come back to it later when you feel like a
+challenge.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p3adb16bcddeec555" name="p3adb16bcddeec555"> </a>I am afraid that, for one aspect of the algorithm, I'm going to have
+to invoke magic again. The open list needs to be able to hold a large
+amount of routes, and to quickly find the route with the lowest score
+among them. Storing them in a normal array, and searching through this
+array every time, is way too slow, so I give you a data structure
+called a <a name="key13"></a>binary heap. You create them with <code>new</code>, just like <code>Date</code>
+objects, giving them a function that is used to 'score' its elements
+as argument. The resulting object has the methods <code>push</code> and <code>pop</code>,
+just like an array, but <code>pop</code> always gives you the element with the
+lowest score, instead of the one that was <code>push</code>ed last.</p><pre class="code"><span class="keyword">function</span> <span class="variable">identity</span>(<span class="variabledef">x</span>) {
+ <span class="keyword">return</span> <span class="localvariable">x</span>;
+}
+
+<span class="keyword">var</span> <span class="variable">heap</span> = <span class="keyword">new</span> <span class="variable">BinaryHeap</span>(<span class="variable">identity</span>);
+<span class="variable">forEach</span>([<span class="atom">2</span>, <span class="atom">4</span>, <span class="atom">5</span>, <span class="atom">1</span>, <span class="atom">6</span>, <span class="atom">3</span>], <span class="keyword">function</span>(<span class="variabledef">number</span>) {
+ <span class="variable">heap</span>.<span class="property">push</span>(<span class="localvariable">number</span>);
+});
+<span class="keyword">while</span> (<span class="variable">heap</span>.<span class="property">size</span>() > <span class="atom">0</span>)
+ <span class="variable">show</span>(<span class="variable">heap</span>.<span class="property">pop</span>());</pre><p><a class="paragraph" href="#p5fbbf2e6f17b02f1" name="p5fbbf2e6f17b02f1"> </a><a href="appendix2.html">Appendix 2</a> discusses the implementation of this data structure,
+which is quite interesting. After you have read <a href="chapter8.html">chapter 8</a>, you might want
+to take a look at it.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p65e5c2761132d409" name="p65e5c2761132d409"> </a>The need to squeeze out as much efficiency as we can has another
+effect. The Hiva Oa algorithm used arrays of locations to store
+routes, and copied them with the <code>concat</code> method when it extended
+them. This time, we can not afford to copy arrays, since we will be
+exploring lots and lots of routes. Instead, we use a 'chain' of
+objects to store a route. Every object in the chain has some
+properties, such as a point on the map, and the length of the route so
+far, and it also has a property that points at the previous object in
+the chain. Something like this:</p><div class="illustration"><img src="img/objectchain.png"/></div><p><a class="paragraph" href="#p2c8aee6703ed2618" name="p2c8aee6703ed2618"> </a>Where the cyan circles are the relevant objects, and the lines
+represent properties ― the end with the dot points at the value of
+the property. Object <code>A</code> is the start of a route here. Object <code>B</code> is
+used to build a new route, which continues from <code>A</code>. It has a
+property, which we will call <code>from</code>, pointing at the route it is based
+on. When we need to reconstruct a route later, we can follow these
+properties to find all the points that the route passed. Note that
+object <code>B</code> is part of two routes, one that ends in <code>D</code> and one that
+ends in <code>E</code>. When there are a lot of routes, this can save us much
+storage space ― every new route only needs one new object for itself,
+the rest is shared with other routes that started the same way.</p></div><hr/><div class="block"><a name="exercise5"></a><div class="exercisenum">Ex. 7.5</div><div class="exercise"><p><a class="paragraph" href="#p7a25220698e3520" name="p7a25220698e3520"> </a>Write a function <code>estimatedDistance</code> that gives an optimistic estimate
+of the distance between two points. It does not have to look at the
+height data, but can assume a flat map. Remember that we are only
+travelling straight and diagonally, and that we are counting the
+diagonal distance between two squares as <code>141</code>.</p></div><div class="solution"><pre class="code"><span class="keyword">function</span> <span class="variable">estimatedDistance</span>(<span class="variabledef">pointA</span>, <span class="variabledef">pointB</span>) {
+ <span class="keyword">var</span> <span class="variabledef">dx</span> = <span class="variable">Math</span>.<span class="property">abs</span>(<span class="localvariable">pointA</span>.<span class="property">x</span> - <span class="localvariable">pointB</span>.<span class="property">x</span>),
+ <span class="variabledef">dy</span> = <span class="variable">Math</span>.<span class="property">abs</span>(<span class="localvariable">pointA</span>.<span class="property">y</span> - <span class="localvariable">pointB</span>.<span class="property">y</span>);
+ <span class="keyword">if</span> (<span class="localvariable">dx</span> > <span class="localvariable">dy</span>)
+ <span class="keyword">return</span> (<span class="localvariable">dx</span> - <span class="localvariable">dy</span>) * <span class="atom">100</span> + <span class="localvariable">dy</span> * <span class="atom">141</span>;
+ <span class="keyword">else</span>
+ <span class="keyword">return</span> (<span class="localvariable">dy</span> - <span class="localvariable">dx</span>) * <span class="atom">100</span> + <span class="localvariable">dx</span> * <span class="atom">141</span>;
+}</pre><p><a class="paragraph" href="#p20a1cd2bad40a101" name="p20a1cd2bad40a101"> </a>The strange formulae are used to decompose the path into a straight
+and a diagonal part. If you have a path like this...</p><div class="illustration"><img src="img/diagonalpath.png"/></div><p><a class="paragraph" href="#p426979e25aaa7f4a" name="p426979e25aaa7f4a"> </a>... the path is <code>6</code> squares wide and <code>3</code> high, so you get <code>6 - 3 = 3</code>
+straight moves, and <code>3</code> diagonal ones.</p><p><a class="paragraph" href="#p1440313db1fcdc3a" name="p1440313db1fcdc3a"> </a>If you wrote a function that just computes the straight 'Pythagorean'
+distance between the points, that would also work. What we need is an
+optimistic estimate, and assuming you can go straight to the goal is
+certainly optimistic. However, the closer the estimate is to the real
+distance, the less useless paths our program has to try out.</p></div></div><hr/><div class="block"><a name="exercise6"></a><div class="exercisenum">Ex. 7.6</div><div class="exercise"><p><a class="paragraph" href="#p32380721aaad37bb" name="p32380721aaad37bb"> </a>We will use a binary heap for the open list. What would be a good data
+structure for the reached list? This one will be used to look up
+routes, given a pair of <code>x</code>, <code>y</code> coordinates. Preferably in a way that
+is fast. Write three functions, <code>makeReachedList</code>, <code>storeReached</code>, and
+<code>findReached</code>. The first one creates your data structure, the second
+one, given a reached list, a point, and a route, stores a route in it,
+and the last one, given a reached list and point, retrieves a route or
+returns <code>undefined</code> to indicate that no route was found for that
+point.</p></div><div class="solution"><p><a class="paragraph" href="#p1ce74e87516850c1" name="p1ce74e87516850c1"> </a>One reasonable idea would be to use an object with objects in it. One
+of the coordinates in the points, say <code>x</code>, is used as a property name
+for the outer object, and the other, <code>y</code>, for the inner object. This
+does require some bookkeeping to handle the fact that, sometimes, the
+inner object we are looking for is not there (yet).</p><pre class="code"><span class="keyword">function</span> <span class="variable">makeReachedList</span>() {
+ <span class="keyword">return</span> {};
+}
+
+<span class="keyword">function</span> <span class="variable">storeReached</span>(<span class="variabledef">list</span>, <span class="variabledef">point</span>, <span class="variabledef">route</span>) {
+ <span class="keyword">var</span> <span class="variabledef">inner</span> = <span class="localvariable">list</span>[<span class="localvariable">point</span>.<span class="property">x</span>];
+ <span class="keyword">if</span> (<span class="localvariable">inner</span> == <span class="atom">undefined</span>) {
+ <span class="localvariable">inner</span> = {};
+ <span class="localvariable">list</span>[<span class="localvariable">point</span>.<span class="property">x</span>] = <span class="localvariable">inner</span>;
+ }
+ <span class="localvariable">inner</span>[<span class="localvariable">point</span>.<span class="property">y</span>] = <span class="localvariable">route</span>;
+}
+
+<span class="keyword">function</span> <span class="variable">findReached</span>(<span class="variabledef">list</span>, <span class="variabledef">point</span>) {
+ <span class="keyword">var</span> <span class="variabledef">inner</span> = <span class="localvariable">list</span>[<span class="localvariable">point</span>.<span class="property">x</span>];
+ <span class="keyword">if</span> (<span class="localvariable">inner</span> == <span class="atom">undefined</span>)
+ <span class="keyword">return</span> <span class="atom">undefined</span>;
+ <span class="keyword">else</span>
+ <span class="keyword">return</span> <span class="localvariable">inner</span>[<span class="localvariable">point</span>.<span class="property">y</span>];
+}</pre><p><a class="paragraph" href="#p2f0ec4286f7e1d1f" name="p2f0ec4286f7e1d1f"> </a>Another possibility is to merge the <code>x</code> and <code>y</code> of the point into a
+single property name, and use that to store routes in a single object.</p><pre class="code"><span class="keyword">function</span> <span class="variable">pointID</span>(<span class="variabledef">point</span>) {
+ <span class="keyword">return</span> <span class="localvariable">point</span>.<span class="property">x</span> + <span class="string">"-"</span> + <span class="localvariable">point</span>.<span class="property">y</span>;
+}
+
+<span class="keyword">function</span> <span class="variable">makeReachedList</span>() {
+ <span class="keyword">return</span> {};
+}
+
+<span class="keyword">function</span> <span class="variable">storeReached</span>(<span class="variabledef">list</span>, <span class="variabledef">point</span>, <span class="variabledef">route</span>) {
+ <span class="localvariable">list</span>[<span class="variable">pointID</span>(<span class="localvariable">point</span>)] = <span class="localvariable">route</span>;
+}
+
+<span class="keyword">function</span> <span class="variable">findReached</span>(<span class="variabledef">list</span>, <span class="variabledef">point</span>) {
+ <span class="keyword">return</span> <span class="localvariable">list</span>[<span class="variable">pointID</span>(<span class="localvariable">point</span>)];
+}</pre></div></div><hr/><div class="block"><p><a class="paragraph" href="#p170f0ddac20707cd" name="p170f0ddac20707cd"> </a><a name="key14"></a>Defining a type of data structure by providing a set
+of functions to create and manipulate such structures is a useful
+technique. It makes it possible to 'isolate' the code that makes use
+of the structure from the details of the structure itself. Note that,
+no matter which of the above two implementations is used, code that
+needs a reached list works in exactly the same way. It doesn't care
+what kind of objects are used, as long as it gets the results it
+expected.</p><p><a class="paragraph" href="#p11b5dca2b0171fd4" name="p11b5dca2b0171fd4"> </a>This will be discussed in much more detail in <a href="chapter8.html">chapter 8</a>, where we will
+learn to make object types like <code>BinaryHeap</code>, which are created using
+<code>new</code> and have methods to manipulate them.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p5eae67a2437a9721" name="p5eae67a2437a9721"> </a>Here we finally have the actual path-finding function:</p><pre class="code"><span class="keyword">function</span> <span class="variable">findRoute</span>(<span class="variabledef">from</span>, <span class="variabledef">to</span>) {
+ <span class="keyword">var</span> <span class="variabledef">open</span> = <span class="keyword">new</span> <span class="variable">BinaryHeap</span>(<span class="variable">routeScore</span>);
+ <span class="keyword">var</span> <span class="variabledef">reached</span> = <span class="variable">makeReachedList</span>();
+
+ <span class="keyword">function</span> <span class="variabledef">routeScore</span>(<span class="variabledef">route</span>) {
+ <span class="keyword">if</span> (<span class="localvariable">route</span>.<span class="property">score</span> == <span class="atom">undefined</span>)
+ <span class="localvariable">route</span>.<span class="property">score</span> = <span class="variable">estimatedDistance</span>(<span class="localvariable">route</span>.<span class="property">point</span>, <span class="localvariable">to</span>) +
+ <span class="localvariable">route</span>.<span class="property">length</span>;
+ <span class="keyword">return</span> <span class="localvariable">route</span>.<span class="property">score</span>;
+ }
+ <span class="keyword">function</span> <span class="variabledef">addOpenRoute</span>(<span class="variabledef">route</span>) {
+ <span class="localvariable">open</span>.<span class="property">push</span>(<span class="localvariable">route</span>);
+ <span class="variable">storeReached</span>(<span class="localvariable">reached</span>, <span class="localvariable">route</span>.<span class="property">point</span>, <span class="localvariable">route</span>);
+ }
+ <span class="localvariable">addOpenRoute</span>({<span class="property">point</span>: <span class="localvariable">from</span>, <span class="property">length</span>: <span class="atom">0</span>});
+
+ <span class="keyword">while</span> (<span class="localvariable">open</span>.<span class="property">size</span>() > <span class="atom">0</span>) {
+ <span class="keyword">var</span> <span class="variabledef">route</span> = <span class="localvariable">open</span>.<span class="property">pop</span>();
+ <span class="keyword">if</span> (<span class="variable">samePoint</span>(<span class="localvariable">route</span>.<span class="property">point</span>, <span class="localvariable">to</span>))
+ <span class="keyword">return</span> <span class="localvariable">route</span>;
+
+ <span class="variable">forEach</span>(<span class="variable">possibleDirections</span>(<span class="localvariable">route</span>.<span class="property">point</span>), <span class="keyword">function</span>(<span class="variabledef">direction</span>) {
+ <span class="keyword">var</span> <span class="variabledef">known</span> = <span class="variable">findReached</span>(<span class="localvariable">reached</span>, <span class="localvariable">direction</span>);
+ <span class="keyword">var</span> <span class="variabledef">newLength</span> = <span class="localvariable">route</span>.<span class="property">length</span> +
+ <span class="variable">weightedDistance</span>(<span class="localvariable">route</span>.<span class="property">point</span>, <span class="localvariable">direction</span>);
+ <span class="keyword">if</span> (!<span class="localvariable">known</span> || <span class="localvariable">known</span>.<span class="property">length</span> > <span class="localvariable">newLength</span>){
+ <span class="keyword">if</span> (<span class="localvariable">known</span>)
+ <span class="localvariable">open</span>.<span class="property">remove</span>(<span class="localvariable">known</span>);
+ <span class="localvariable">addOpenRoute</span>({<span class="property">point</span>: <span class="localvariable">direction</span>,
+ <span class="property">from</span>: <span class="localvariable">route</span>,
+ <span class="property">length</span>: <span class="localvariable">newLength</span>});
+ }
+ });
+ }
+ <span class="keyword">return</span> <span class="atom">null</span>;
+}</pre><p><a class="paragraph" href="#p627d0478bf5050f1" name="p627d0478bf5050f1"> </a>First, it creates the data structures it needs, one open list and one
+reached list. <code>routeScore</code> is the scoring function given to the binary
+heap. Note how it stores its result in the route object, to prevent
+having to re-calculate it multiple times.</p><p><a class="paragraph" href="#p6dc66f08bbae1c5" name="p6dc66f08bbae1c5"> </a><code>addOpenRoute</code> is a convenience function that adds a new route to both
+the open list and the reached list. It is immediately used to add the
+start of the route. Note that route objects always have the properties
+<code>point</code>, which holds the point at the end of the route, and <code>length</code>,
+which holds the current length of the route. Routes which are more
+than one square long also have a <code>from</code> property, which points at
+their predecessors.</p><p><a class="paragraph" href="#p2b065241401e6e48" name="p2b065241401e6e48"> </a>The <code>while</code> loop, as was described in the algorithm, keeps taking the
+lowest-scoring route from the open list and checks whether this gets
+us to the goal point. If it does not, we must continue by expanding
+it. This is what the <code>forEach</code> takes care of. It looks up this new
+point in the reached list. If it is not found there, or the node found
+has a longer length than the new route, a new route object is created
+and added to the open list and reached list, and the existing route
+(if any) is removed from the open list.</p><p><a class="paragraph" href="#p3f08d59ab6d9538c" name="p3f08d59ab6d9538c"> </a>What if the route in <code>known</code> is not on the open list? It has to be,
+because routes are only removed from the open list when they have been
+found to be the most optimal route to their endpoint. If we try to
+remove a value from a binary heap that is not on it, it will throw an
+exception, so if my reasoning is wrong, we will probably see an
+exception when running the function.</p><p><a class="paragraph" href="#p2b2d7e407500c88d" name="p2b2d7e407500c88d"> </a>When code gets complex enough to make you doubt certain things about
+it, it is a good idea to add some checks that raise exceptions when
+something goes wrong. That way, you know that there are no weird
+things happening 'silently', and when you break something, you
+immediately see what you broke.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p6a9bab4da8fa0eed" name="p6a9bab4da8fa0eed"> </a>Note that this algorithm does not use recursion, but still manages to
+explore all those branches. The open list more or less takes over the
+role that the function call stack played in the recursive solution to
+the Hiva Oa problem ― it keeps track of the paths that still have to
+be explored. Every recursive algorithm can be rewritten in a
+non-recursive way by using a data structure to store the 'things that
+must still be done'.</p></div><hr/><div class="block"><p><a class="paragraph" href="#pad930b309189a46" name="pad930b309189a46"> </a>Well, let us try our path-finder:</p><pre class="code"><span class="keyword">var</span> <span class="variable">route</span> = <span class="variable">findRoute</span>(<span class="variable">point</span>(<span class="atom">0</span>, <span class="atom">0</span>), <span class="variable">point</span>(<span class="atom">19</span>, <span class="atom">19</span>));</pre><p><a class="paragraph" href="#p1bf3e5c89fce62b6" name="p1bf3e5c89fce62b6"> </a>If you ran all the code above, and did not introduce any errors, that
+call, though it might take a few seconds to run, should give us a
+route object. This object is rather hard to read. That can be helped
+by using the <code>showRoute</code> function which, if your console is big
+enough, will show a route on a map.</p><pre class="code"><span class="variable">showRoute</span>(<span class="variable">route</span>);</pre><p><a class="paragraph" href="#p225576595e8e0774" name="p225576595e8e0774"> </a>You can also pass multiple routes to <code>showRoute</code>, which can be useful
+when you are, for example, trying to plan a scenic route, which must
+include the beautiful viewpoint at <code>11</code>, <code>17</code>.</p><pre class="code"><span class="variable">showRoute</span>(<span class="variable">findRoute</span>(<span class="variable">point</span>(<span class="atom">0</span>, <span class="atom">0</span>), <span class="variable">point</span>(<span class="atom">11</span>, <span class="atom">17</span>)),
+ <span class="variable">findRoute</span>(<span class="variable">point</span>(<span class="atom">11</span>, <span class="atom">17</span>), <span class="variable">point</span>(<span class="atom">19</span>, <span class="atom">19</span>)));</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p3396aee2bad97996" name="p3396aee2bad97996"> </a>Variations on the theme of <a name="key15"></a>searching an optimal route through a
+graph can be applied to many problems, many of which are not at all
+related to finding a physical path. For example, a program that needs
+to solve a puzzle of fitting a number of blocks into a limited space
+could do this by exploring the various 'paths' it gets by trying to
+put a certain block in a certain place. The paths that ends up with
+insufficient room for the last blocks are dead ends, and the path that
+manages to fit in all blocks is the solution.</p></div><ol class="footnotes"><li><a name="footnote1"></a>Computers are deterministic machines: They always react in the same
+way to the input they receive, so they can not produce truly random
+values. Therefore, we have to make do with series of numbers that look
+random, but are in fact the result of some complicated deterministic
+computation.</li><li><a name="footnote2"></a>No really, it is.</li></ol><h1><span class="number">Chapter 8: </span>Object-oriented Programming</h1><div class="block"><p><a class="paragraph" href="#p18e03940ba942b6f" name="p18e03940ba942b6f"> </a>In the early nineties, a thing called <a name="key1"></a>object-oriented programming
+stirred up the software industry. Most of the ideas behind it were not
+really new at the time, but they had finally gained enough momentum to
+start rolling, to become fashionable. Books were being written,
+courses given, programming languages developed. All of a sudden,
+everybody was extolling the virtues of object-orientation,
+enthusiastically applying it to every problem, convincing themselves
+they had finally found the <em>right way to write programs</em>.</p><p><a class="paragraph" href="#p4a5356a6d996e9b9" name="p4a5356a6d996e9b9"> </a>These things happen a lot. When a process is hard and confusing,
+people are always on the lookout for a magic solution. When something
+looking like such a solution presents itself, they are prepared to
+become devoted followers. For many programmers, even today,
+object-orientation (or their view of it) is the gospel. When a program
+is not 'truly object-oriented', whatever that means, it is considered
+decidedly inferior.</p><p><a class="paragraph" href="#p4a5e752e289a65b1" name="p4a5e752e289a65b1"> </a>Few fads have managed to stay popular for as long as this one, though.
+Object-orientation's longevity can largely be explained by the fact
+that the ideas at its core are very solid and useful. In this chapter,
+we will discuss these ideas, along with JavaScript's (rather
+eccentric) take on them. The above paragraphs are by no means meant to
+discredit these ideas. What I want to do is warn the reader against
+developing an unhealthy attachment to them.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p5d07c4f5109e7992" name="p5d07c4f5109e7992"> </a>As the name suggests, object-oriented programming is related to
+objects. So far, we have used objects as loose aggregations of values,
+adding and altering their properties whenever we saw fit. In an
+object-oriented approach, objects are viewed as little worlds of their
+own, and the outside world may touch them only through a limited and
+well-defined <a name="key2"></a>interface, a number of specific methods and properties.
+The 'reached list' we used at the end of <a href="chapter7.html">chapter 7</a> is an example of
+this: We used only three functions, <code>makeReachedList</code>, <code>storeReached</code>,
+and <code>findReached</code> to interact with it. These three functions form an
+interface for such objects.</p><p><a class="paragraph" href="#p2e1bbb92823ad3b1" name="p2e1bbb92823ad3b1"> </a>The <code>Date</code>, <code>Error</code>, and <code>BinaryHeap</code> objects we have seen also work
+like this. Instead of providing regular functions for working with the
+objects, they provide a way to create such objects, using the <code>new</code>
+keyword, and a number of methods and properties that provide the rest
+of the interface.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p13af050db602907b" name="p13af050db602907b"> </a>One way to give an object methods is to simply attach function values
+to it.</p><pre class="code"><span class="keyword">var</span> <span class="variable">rabbit</span> = {};
+<span class="variable">rabbit</span>.<span class="property">speak</span> = <span class="keyword">function</span>(<span class="variabledef">line</span>) {
+ <span class="variable">print</span>(<span class="string">"The rabbit says '"</span>, <span class="localvariable">line</span>, <span class="string">"'"</span>);
+};
+
+<span class="variable">rabbit</span>.<span class="property">speak</span>(<span class="string">"Well, now you're asking me."</span>);</pre><p><a class="paragraph" href="#p12798fc3dfebc5cd" name="p12798fc3dfebc5cd"> </a>In most cases, the method will need to know <em>who</em> it should act on.
+For example, if there are different rabbits, the <code>speak</code> method must
+indicate which rabbit is speaking. For this purpose, there is a
+special variable called <a name="key3"></a><code>this</code>, which is always present when a
+function is called, and which points at the relevant object when the
+function is called as a method. A function is called as a method when
+it is looked up as a property, and immediately called, as in
+<code>object.method()</code>.</p><pre class="code"><span class="keyword">function</span> <span class="variable">speak</span>(<span class="variabledef">line</span>) {
+ <span class="variable">print</span>(<span class="string">"The "</span>, <span class="localvariable">this</span>.<span class="property">adjective</span>, <span class="string">" rabbit says '"</span>, <span class="localvariable">line</span>, <span class="string">"'"</span>);
+}
+<span class="keyword">var</span> <span class="variable">whiteRabbit</span> = {<span class="property">adjective</span>: <span class="string">"white"</span>, <span class="property">speak</span>: <span class="variable">speak</span>};
+<span class="keyword">var</span> <span class="variable">fatRabbit</span> = {<span class="property">adjective</span>: <span class="string">"fat"</span>, <span class="property">speak</span>: <span class="variable">speak</span>};
+
+<span class="variable">whiteRabbit</span>.<span class="property">speak</span>(<span class="string">"Oh my ears and whiskers, how late it's getting!"</span>);
+<span class="variable">fatRabbit</span>.<span class="property">speak</span>(<span class="string">"I could sure use a carrot right now."</span>);</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p4ca40bb0e8fc17d7" name="p4ca40bb0e8fc17d7"> </a>I can now clarify the mysterious first argument to the <a name="key4"></a><code>apply</code>
+method, for which we always used <code>null</code> in <a href="chapter6.html">chapter 6</a>. This argument can be
+used to specify the object that the function must be applied to. For
+non-method functions, this is irrelevant, hence the <code>null</code>.</p><pre class="code"><span class="variable">speak</span>.<span class="property">apply</span>(<span class="variable">fatRabbit</span>, [<span class="string">"Yum."</span>]);</pre><p><a class="paragraph" href="#p2f2d7cb0d84dd000" name="p2f2d7cb0d84dd000"> </a>Functions also have a <a name="key5"></a><code>call</code> method, which is similar to <code>apply</code>,
+but you can give the arguments for the function separately instead of
+as an array:</p><pre class="code"><span class="variable">speak</span>.<span class="property">call</span>(<span class="variable">fatRabbit</span>, <span class="string">"Burp."</span>);</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p37d65271d19568f2" name="p37d65271d19568f2"> </a>The <a name="key6"></a><code>new</code> keyword provides a convenient way of creating new objects.
+When a function is called with the word <code>new</code> in front of it, its
+<a name="key7"></a><code>this</code> variable will point at a <em>new</em> object, which it will
+automatically return (unless it explicitly returns something else).
+Functions used to create new objects like this are called
+<a name="key8"></a>constructors. Here is a constructor for rabbits:</p><pre class="code"><span class="keyword">function</span> <span class="variable">Rabbit</span>(<span class="variabledef">adjective</span>) {
+ <span class="localvariable">this</span>.<span class="property">adjective</span> = <span class="localvariable">adjective</span>;
+ <span class="localvariable">this</span>.<span class="property">speak</span> = <span class="keyword">function</span>(<span class="variabledef">line</span>) {
+ <span class="variable">print</span>(<span class="string">"The "</span>, <span class="localvariable">this</span>.<span class="property">adjective</span>, <span class="string">" rabbit says '"</span>, <span class="localvariable">line</span>, <span class="string">"'"</span>);
+ };
+}
+
+<span class="keyword">var</span> <span class="variable">killerRabbit</span> = <span class="keyword">new</span> <span class="variable">Rabbit</span>(<span class="string">"killer"</span>);
+<span class="variable">killerRabbit</span>.<span class="property">speak</span>(<span class="string">"GRAAAAAAAAAH!"</span>);</pre><p><a class="paragraph" href="#p11c69c27ded2fabf" name="p11c69c27ded2fabf"> </a>It is a convention, among JavaScript programmers, to start the names
+of constructors with a capital letter. This makes it easy to
+distinguish them from other functions.</p><p><a class="paragraph" href="#p592ac456b8eebbb3" name="p592ac456b8eebbb3"> </a>Why is the <code>new</code> keyword even necessary? After all, we could have
+simply written this:</p><pre class="code"><span class="keyword">function</span> <span class="variable">makeRabbit</span>(<span class="variabledef">adjective</span>) {
+ <span class="keyword">return</span> {
+ <span class="property">adjective</span>: <span class="localvariable">adjective</span>,
+ <span class="property">speak</span>: <span class="keyword">function</span>(<span class="variabledef">line</span>) {<span class="comment">/*etc*/</span>}
+ };
+}
+
+<span class="keyword">var</span> <span class="variable">blackRabbit</span> = <span class="variable">makeRabbit</span>(<span class="string">"black"</span>);</pre><p><a class="paragraph" href="#p16717b36f8642b81" name="p16717b36f8642b81"> </a>But that is not entirely the same. <code>new</code> does a few things behind the
+scenes. For one thing, our <code>killerRabbit</code> has a property called
+<a name="key9"></a><code>constructor</code>, which points at the <code>Rabbit</code> function that created
+it. <code>blackRabbit</code> also has such a property, but it points at the
+<a name="key10"></a><code>Object</code> function.</p><pre class="code"><span class="variable">show</span>(<span class="variable">killerRabbit</span>.<span class="property">constructor</span>);
+<span class="variable">show</span>(<span class="variable">blackRabbit</span>.<span class="property">constructor</span>);</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p65aceab6b4c1ffdd" name="p65aceab6b4c1ffdd"> </a>Where did the <code>constructor</code> property come from? It is part of the
+<a name="key11"></a>prototype of a rabbit. Prototypes are a powerful, if somewhat
+confusing, part of the way JavaScript objects work. Every object is
+based on a prototype, which gives it a set of inherent properties. The
+simple objects we have used so far are based on the most basic
+prototype, which is associated with the <code>Object</code> constructor. In fact,
+typing <code>{}</code> is equivalent to typing <code>new Object()</code>.</p><pre class="code"><span class="keyword">var</span> <span class="variable">simpleObject</span> = {};
+<span class="variable">show</span>(<span class="variable">simpleObject</span>.<span class="property">constructor</span>);
+<span class="variable">show</span>(<span class="variable">simpleObject</span>.<span class="property">toString</span>);</pre><p><a class="paragraph" href="#p531e35cf3e01867e" name="p531e35cf3e01867e"> </a><a name="key12"></a><code>toString</code> is a method that is part of the <code>Object</code> prototype. This
+means that all simple objects have a <code>toString</code> method, which converts
+them to a string. Our rabbit objects are based on the prototype
+associated with the <code>Rabbit</code> constructor. You can use a constructor's
+<code>prototype</code> property to get access to, well, their prototype:</p><pre class="code"><span class="variable">show</span>(<span class="variable">Rabbit</span>.<span class="property">prototype</span>);
+<span class="variable">show</span>(<span class="variable">Rabbit</span>.<span class="property">prototype</span>.<span class="property">constructor</span>);</pre><p><a class="paragraph" href="#p5dfb614a8bba419d" name="p5dfb614a8bba419d"> </a>Every function automatically gets a <code>prototype</code> property, whose
+<code>constructor</code> property points back at the function. Because the rabbit
+prototype is itself an object, it is based on the <code>Object</code> prototype,
+and shares its <code>toString</code> method.</p><pre class="code"><span class="variable">show</span>(<span class="variable">killerRabbit</span>.<span class="property">toString</span> == <span class="variable">simpleObject</span>.<span class="property">toString</span>);</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p6359c8d3085d6d12" name="p6359c8d3085d6d12"> </a>Even though objects seem to share the properties of their prototype,
+this sharing is one-way. The properties of the prototype influence the
+object based on it, but the properties of this object never change the
+prototype.</p><p><a class="paragraph" href="#p3e4f8a85a38cfc7" name="p3e4f8a85a38cfc7"> </a>The precise rules are this: When looking up the value of a property,
+JavaScript first looks at the properties that the object <em>itself</em> has.
+If there is a property that has the name we are looking for, that is
+the value we get. If there is no such property, it continues searching
+the prototype of the object, and then the prototype of the prototype,
+and so on. If no property is found, the value <code>undefined</code> is given. On
+the other hand, when <em>setting</em> the value of a property, JavaScript
+never goes to the prototype, but always sets the property in the
+object itself.</p><pre class="code"><span class="variable">Rabbit</span>.<span class="property">prototype</span>.<span class="property">teeth</span> = <span class="string">"small"</span>;
+<span class="variable">show</span>(<span class="variable">killerRabbit</span>.<span class="property">teeth</span>);
+<span class="variable">killerRabbit</span>.<span class="property">teeth</span> = <span class="string">"long, sharp, and bloody"</span>;
+<span class="variable">show</span>(<span class="variable">killerRabbit</span>.<span class="property">teeth</span>);
+<span class="variable">show</span>(<span class="variable">Rabbit</span>.<span class="property">prototype</span>.<span class="property">teeth</span>);</pre><p><a class="paragraph" href="#p5450ae7ffc2e9fb8" name="p5450ae7ffc2e9fb8"> </a>This does mean that the prototype can be used at any time to add
+new properties and methods to all objects based on it. For example, it
+might become necessary for our rabbits to dance.</p><pre class="code"><span class="variable">Rabbit</span>.<span class="property">prototype</span>.<span class="property">dance</span> = <span class="keyword">function</span>() {
+ <span class="variable">print</span>(<span class="string">"The "</span>, <span class="localvariable">this</span>.<span class="property">adjective</span>, <span class="string">" rabbit dances a jig."</span>);
+};
+
+<span class="variable">killerRabbit</span>.<span class="property">dance</span>();</pre><p><a class="paragraph" href="#p6384880cdbf6db23" name="p6384880cdbf6db23"> </a>And, as you might have guessed, the prototypical rabbit is the perfect
+place for values that all rabbits have in common, such as the <code>speak</code>
+method. Here is a new approach to the <code>Rabbit</code> constructor:</p><pre class="code"><span class="keyword">function</span> <span class="variable">Rabbit</span>(<span class="variabledef">adjective</span>) {
+ <span class="localvariable">this</span>.<span class="property">adjective</span> = <span class="localvariable">adjective</span>;
+}
+<span class="variable">Rabbit</span>.<span class="property">prototype</span>.<span class="property">speak</span> = <span class="keyword">function</span>(<span class="variabledef">line</span>) {
+ <span class="variable">print</span>(<span class="string">"The "</span>, <span class="localvariable">this</span>.<span class="property">adjective</span>, <span class="string">" rabbit says '"</span>, <span class="localvariable">line</span>, <span class="string">"'"</span>);
+};
+
+<span class="keyword">var</span> <span class="variable">hazelRabbit</span> = <span class="keyword">new</span> <span class="variable">Rabbit</span>(<span class="string">"hazel"</span>);
+<span class="variable">hazelRabbit</span>.<span class="property">speak</span>(<span class="string">"Good Frith!"</span>);</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p3c4ac238702c7ecc" name="p3c4ac238702c7ecc"> </a>The fact that all objects have a prototype and receive some properties
+from this prototype can be tricky. It means that using an object to
+store a set of things, such as the cats from <a href="chapter4.html">chapter 4</a>, can go wrong.
+If, for example, we wondered whether there is a cat called
+<code>"constructor"</code>, we would have checked it like this:</p><pre class="code"><span class="keyword">var</span> <span class="variable">noCatsAtAll</span> = {};
+<span class="keyword">if</span> (<span class="string">"constructor"</span> in <span class="variable">noCatsAtAll</span>)
+ <span class="variable">print</span>(<span class="string">"Yes, there definitely is a cat called 'constructor'."</span>);</pre><p><a class="paragraph" href="#p429d248add331700" name="p429d248add331700"> </a>This is problematic. A related problem is that it can often be
+practical to extend the prototypes of standard constructors such as
+<code>Object</code> and <code>Array</code> with new useful functions. For example, we could
+give all objects a method called <code>properties</code>, which returns an array
+with the names of the (non-hidden) properties that the object has:</p><pre class="code"><span class="variable">Object</span>.<span class="property">prototype</span>.<span class="property">properties</span> = <span class="keyword">function</span>() {
+ <span class="keyword">var</span> <span class="variabledef">result</span> = [];
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variabledef">property</span> <span class="keyword">in</span> <span class="localvariable">this</span>)
+ <span class="localvariable">result</span>.<span class="property">push</span>(<span class="localvariable">property</span>);
+ <span class="keyword">return</span> <span class="localvariable">result</span>;
+};
+
+<span class="keyword">var</span> <span class="variable">test</span> = {<span class="property">x</span>: <span class="atom">10</span>, <span class="property">y</span>: <span class="atom">3</span>};
+<span class="variable">show</span>(<span class="variable">test</span>.<span class="property">properties</span>());</pre><p><a class="paragraph" href="#p4cfd7a8a8a68e368" name="p4cfd7a8a8a68e368"> </a>And that immediately shows the problem. Now that the <code>Object</code>
+prototype has a property called <code>properties</code>, looping over the
+properties of any object, using <code>for</code> and <a name="key13"></a><code>in</code>, will also give us
+that shared property, which is generally not what we want. We are
+interested only in the properties that the object itself has.</p><p><a class="paragraph" href="#p15d222d107370bb2" name="p15d222d107370bb2"> </a>Fortunately, there is a way to find out whether a property belongs to
+the object itself or to one of its prototypes. Unfortunately, it does
+make looping over the properties of an object a bit clumsier. Every
+object has a method called <a name="key14"></a><code>hasOwnProperty</code>, which tells us whether
+the object has a property with a given name. Using this, we could
+rewrite our <code>properties</code> method like this:</p><pre class="code"><span class="variable">Object</span>.<span class="property">prototype</span>.<span class="property">properties</span> = <span class="keyword">function</span>() {
+ <span class="keyword">var</span> <span class="variabledef">result</span> = [];
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variabledef">property</span> <span class="keyword">in</span> <span class="localvariable">this</span>) {
+ <span class="keyword">if</span> (<span class="localvariable">this</span>.<span class="property">hasOwnProperty</span>(<span class="localvariable">property</span>))
+ <span class="localvariable">result</span>.<span class="property">push</span>(<span class="localvariable">property</span>);
+ }
+ <span class="keyword">return</span> <span class="localvariable">result</span>;
+};
+
+<span class="keyword">var</span> <span class="variable">test</span> = {<span class="string">"Fat Igor"</span>: <span class="atom">true</span>, <span class="string">"Fireball"</span>: <span class="atom">true</span>};
+<span class="variable">show</span>(<span class="variable">test</span>.<span class="property">properties</span>());</pre><p><a class="paragraph" href="#p5a1185bce6f9b589" name="p5a1185bce6f9b589"> </a><a name="key15"></a>And of course, we can abstract that into a higher-order
+function. Note that the <code>action</code> function is called with both the name
+of the property and the value it has in the object.</p><pre class="code"><span class="keyword">function</span> <span class="variable">forEachIn</span>(<span class="variabledef">object</span>, <span class="variabledef">action</span>) {
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variabledef">property</span> <span class="keyword">in</span> <span class="localvariable">object</span>) {
+ <span class="keyword">if</span> (<span class="localvariable">object</span>.<span class="property">hasOwnProperty</span>(<span class="localvariable">property</span>))
+ <span class="localvariable">action</span>(<span class="localvariable">property</span>, <span class="localvariable">object</span>[<span class="localvariable">property</span>]);
+ }
+}
+
+<span class="keyword">var</span> <span class="variable">chimera</span> = {<span class="property">head</span>: <span class="string">"lion"</span>, <span class="property">body</span>: <span class="string">"goat"</span>, <span class="property">tail</span>: <span class="string">"snake"</span>};
+<span class="variable">forEachIn</span>(<span class="variable">chimera</span>, <span class="keyword">function</span>(<span class="variabledef">name</span>, <span class="variabledef">value</span>) {
+ <span class="variable">print</span>(<span class="string">"The "</span>, <span class="localvariable">name</span>, <span class="string">" of a "</span>, <span class="localvariable">value</span>, <span class="string">"."</span>);
+});</pre><p><a class="paragraph" href="#p2420ca9a47b21ef8" name="p2420ca9a47b21ef8"> </a>But, what if we find a cat named <code>hasOwnProperty</code>? (You never know.)
+It will be stored in the object, and the next time we want to go over
+the collection of cats, calling <code>object.hasOwnProperty</code> will fail,
+because that property no longer points at a function value. This can
+be solved by doing something even uglier:</p><pre class="code"><span class="keyword">function</span> <span class="variable">forEachIn</span>(<span class="variabledef">object</span>, <span class="variabledef">action</span>) {
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variabledef">property</span> <span class="keyword">in</span> <span class="localvariable">object</span>) {
+ <span class="keyword">if</span> (<span class="variable">Object</span>.<span class="property">prototype</span>.<span class="property">hasOwnProperty</span>.<span class="property">call</span>(<span class="localvariable">object</span>, <span class="localvariable">property</span>))
+ <span class="localvariable">action</span>(<span class="localvariable">property</span>, <span class="localvariable">object</span>[<span class="localvariable">property</span>]);
+ }
+}
+
+<span class="keyword">var</span> <span class="variable">test</span> = {<span class="property">name</span>: <span class="string">"Mordecai"</span>, <span class="property">hasOwnProperty</span>: <span class="string">"Uh-oh"</span>};
+<span class="variable">forEachIn</span>(<span class="variable">test</span>, <span class="keyword">function</span>(<span class="variabledef">name</span>, <span class="variabledef">value</span>) {
+ <span class="variable">print</span>(<span class="string">"Property "</span>, <span class="localvariable">name</span>, <span class="string">" = "</span>, <span class="localvariable">value</span>);
+});</pre><p><a class="paragraph" href="#p3abba784f5ae2cab" name="p3abba784f5ae2cab"> </a>(Note: This example does not currently work correctly in Internet
+Explorer 8, which apparently has some problems with overriding
+built-in prototype properties.)</p><p><a class="paragraph" href="#p1ffca6e85480c92a" name="p1ffca6e85480c92a"> </a>Here, instead of using the method found in the object itself, we get
+the method from the <code>Object</code> prototype, and then use <code>call</code> to apply
+it to the right object. Unless someone actually messes with the method
+in <code>Object.prototype</code> (don't do that), this should work correctly.</p></div><hr/><div class="block"><p><a class="paragraph" href="#pbe9c467ae3a4c79" name="pbe9c467ae3a4c79"> </a><code>hasOwnProperty</code> can also be used in those situations where we have
+been using the <a name="key16"></a><code>in</code> operator to see whether an object has a specific
+property. There is one more catch, however. We saw in <a href="chapter4.html">chapter 4</a> that
+some properties, such as <code>toString</code>, are 'hidden', and do not show up
+when going over properties with <code>for</code>/<code>in</code>. It turns out that browsers
+in the Gecko family (Firefox, most importantly) give every object a
+hidden property named <code>__proto__</code>, which points to the prototype of
+that object. <code>hasOwnProperty</code> will return <code>true</code> for this one, even
+though the program did not explicitly add it. Having access to the
+prototype of an object can be very convenient, but making it a
+property like that was not a very good idea. Still, Firefox is a
+widely used browser, so when you write a program for the web you have
+to be careful with this. There is a method <a name="key17"></a><code>propertyIsEnumerable</code>,
+which returns <code>false</code> for hidden properties, and which can be used to
+filter out strange things like <code>__proto__</code>. An expression such as this
+one can be used to reliably work around this:</p><pre class="code"><span class="keyword">var</span> <span class="variable">object</span> = {<span class="property">foo</span>: <span class="string">"bar"</span>};
+<span class="variable">show</span>(<span class="variable">Object</span>.<span class="property">prototype</span>.<span class="property">hasOwnProperty</span>.<span class="property">call</span>(<span class="variable">object</span>, <span class="string">"foo"</span>) &&
+ <span class="variable">Object</span>.<span class="property">prototype</span>.<span class="property">propertyIsEnumerable</span>.<span class="property">call</span>(<span class="variable">object</span>, <span class="string">"foo"</span>));</pre><p><a class="paragraph" href="#p1eaec3a4d259aa40" name="p1eaec3a4d259aa40"> </a>Nice and simple, no? This is one of the not-so-well-designed aspects
+of JavaScript. Objects play both the role of 'values with methods',
+for which prototypes work great, and 'sets of properties', for which
+prototypes only get in the way.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p5392d7ffbb63c4f3" name="p5392d7ffbb63c4f3"> </a>Writing the above expression every time you need to check whether a
+property is present in an object is unworkable. We could put it into a
+function, but an even better approach is to write a constructor and a
+prototype specifically for situations like this, where we want to
+approach an object as just a set of properties. Because you can use it
+to look things up by name, we will call it a <a name="key18"></a><code>Dictionary</code>.</p><pre class="code"><span class="keyword">function</span> <span class="variable">Dictionary</span>(<span class="variabledef">startValues</span>) {
+ <span class="localvariable">this</span>.<span class="property">values</span> = <span class="localvariable">startValues</span> || {};
+}
+<span class="variable">Dictionary</span>.<span class="property">prototype</span>.<span class="property">store</span> = <span class="keyword">function</span>(<span class="variabledef">name</span>, <span class="variabledef">value</span>) {
+ <span class="localvariable">this</span>.<span class="property">values</span>[<span class="localvariable">name</span>] = <span class="localvariable">value</span>;
+};
+<span class="variable">Dictionary</span>.<span class="property">prototype</span>.<span class="property">lookup</span> = <span class="keyword">function</span>(<span class="variabledef">name</span>) {
+ <span class="keyword">return</span> <span class="localvariable">this</span>.<span class="property">values</span>[<span class="localvariable">name</span>];
+};
+<span class="variable">Dictionary</span>.<span class="property">prototype</span>.<span class="property">contains</span> = <span class="keyword">function</span>(<span class="variabledef">name</span>) {
+ <span class="keyword">return</span> <span class="variable">Object</span>.<span class="property">prototype</span>.<span class="property">hasOwnProperty</span>.<span class="property">call</span>(<span class="localvariable">this</span>.<span class="property">values</span>, <span class="localvariable">name</span>) &&
+ <span class="variable">Object</span>.<span class="property">prototype</span>.<span class="property">propertyIsEnumerable</span>.<span class="property">call</span>(<span class="localvariable">this</span>.<span class="property">values</span>, <span class="localvariable">name</span>);
+};
+<span class="variable">Dictionary</span>.<span class="property">prototype</span>.<span class="property">each</span> = <span class="keyword">function</span>(<span class="variabledef">action</span>) {
+ <span class="variable">forEachIn</span>(<span class="localvariable">this</span>.<span class="property">values</span>, <span class="localvariable">action</span>);
+};
+
+<span class="keyword">var</span> <span class="variable">colours</span> = <span class="keyword">new</span> <span class="variable">Dictionary</span>({<span class="property">Grover</span>: <span class="string">"blue"</span>,
+ <span class="property">Elmo</span>: <span class="string">"orange"</span>,
+ <span class="property">Bert</span>: <span class="string">"yellow"</span>});
+<span class="variable">show</span>(<span class="variable">colours</span>.<span class="property">contains</span>(<span class="string">"Grover"</span>));
+<span class="variable">show</span>(<span class="variable">colours</span>.<span class="property">contains</span>(<span class="string">"constructor"</span>));
+<span class="variable">colours</span>.<span class="property">each</span>(<span class="keyword">function</span>(<span class="variabledef">name</span>, <span class="variabledef">colour</span>) {
+ <span class="variable">print</span>(<span class="localvariable">name</span>, <span class="string">" is "</span>, <span class="localvariable">colour</span>);
+});</pre><p><a class="paragraph" href="#p2921a27cd935902b" name="p2921a27cd935902b"> </a>Now the whole mess related to approaching objects as plain sets of
+properties has been 'encapsulated' in a convenient interface: one
+constructor and four methods. Note that the <code>values</code> property of a
+<code>Dictionary</code> object is not part of this interface, it is an internal
+detail, and when you are using <code>Dictionary</code> objects you do not need to
+directly use it.</p><p><a class="paragraph" href="#p54a4aa38e7a80eab" name="p54a4aa38e7a80eab"> </a>Whenever you write an interface, it is a good idea to add a comment
+with a quick sketch of what it does and how it should be used. This
+way, when someone, possibly yourself three months after you wrote it,
+wants to work with the interface, they can quickly see how to use it,
+and do not have to study the whole program.</p><p><a class="paragraph" href="#p2aaba1b065516c82" name="p2aaba1b065516c82"> </a>Most of the time, when you are designing an interface, you will soon
+find some limitations and problems in whatever you came up with, and
+change it. To prevent wasting your time, it is advisable to document
+your interfaces only <em>after</em> they have been used in a few real
+situations and proven themselves to be practical. ― Of course, this
+might make it tempting to forget about documentation altogether.
+Personally, I treat writing documentation as a 'finishing touch' to
+add to a system. When it feels ready, it is time to write something
+about it, and to see if it sounds as good in English (or whatever
+language) as it does in JavaScript (or whatever programming language).</p></div><hr/><div class="block"><p><a class="paragraph" href="#p588adda0b0472459" name="p588adda0b0472459"> </a>The distinction between the external interface of an object and its
+internal details is important for two reasons. Firstly, having a
+small, clearly described interface makes an object easier to use. You
+only have to keep the interface in mind, and do not have to worry
+about the rest unless you are changing the object itself.</p><p><a class="paragraph" href="#p56d8406fdc34ca54" name="p56d8406fdc34ca54"> </a>Secondly, it often turns out to be necessary or practical to change
+something about the internal implementation of an object type<a class="footref" href="#footnote1">1</a>, to
+make it more efficient, for example, or to fix some problem. When
+outside code is accessing every single property and detail in the
+object, you can not change any of them without also updating a lot of
+other code. If outside code only uses a small interface, you can do
+what you want, as long as you do not change the interface.</p><p><a class="paragraph" href="#p639a46444303f2d0" name="p639a46444303f2d0"> </a>Some people go very far in this. They will, for example, never include
+properties in the interface of object, only methods ― if their object
+type has a length, it will be accessible with the <code>getLength</code> method,
+not the <code>length</code> property. This way, if they ever want to change their
+object in such a way that it no longer has a <code>length</code> property, for
+example because it now has some internal array whose length it must
+return, they can update the function without changing the interface.</p><p><a class="paragraph" href="#p44dc075d8a2b8573" name="p44dc075d8a2b8573"> </a>My own take is that in most cases this is not worth it. Adding a
+<code>getLength</code> method which only contains <code>return this.length;</code> mostly
+just adds meaningless code, and, in most situations, I consider
+meaningless code a bigger problem than the risk of having to
+occasionally change the interface to my objects.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p5e2f0cee5f85da20" name="p5e2f0cee5f85da20"> </a>Adding new methods to existing prototypes can be very convenient.
+Especially the <code>Array</code> and <code>String</code> prototypes in JavaScript could use
+a few more basic methods. We could, for example, replace <code>forEach</code> and
+<code>map</code> with methods on arrays, and make the <code>startsWith</code> function we
+wrote in <a href="chapter4.html">chapter 4</a> a method on strings.</p><p><a class="paragraph" href="#p584b92a939af8ba8" name="p584b92a939af8ba8"> </a>However, if your program has to run on the same web-page as another
+program (either written by you or by someone else) which uses
+<code>for</code>/<code>in</code> naively ― the way we have been using it so far ― then
+adding things to prototypes, especially the <code>Object</code> and <code>Array</code>
+prototype, will definitely break something, because these loops will
+suddenly start seeing those new properties. For this reason, some
+people prefer not to touch these prototypes at all. Of course, if you
+are careful, and you do not expect your code to have to coexist with
+badly-written code, adding methods to standard prototypes is a
+perfectly good technique.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p3e80b90220c891b9" name="p3e80b90220c891b9"> </a>In this chapter we are going to build a virtual terrarium, a tank with
+insects moving around in it. There will be some objects involved (this
+is, after all, the chapter on object-oriented programming). We will
+take a rather simple approach, and make the terrarium a
+two-dimensional grid, like the second map in <a href="chapter7.html">chapter 7</a>. On this grid
+there are a number of bugs. When the terrarium is active, all the bugs
+get a chance to take an action, such as moving, every half second.</p><p><a class="paragraph" href="#p2ac546ad345b5e63" name="p2ac546ad345b5e63"> ¶ </a>Thus, we chop both time and space into units with a fixed size ―
+squares for space, half seconds for time. This usually makes things
+easier to model in a program, but of course has the drawback of being
+wildly inaccurate. Fortunately, this terrarium-simulator is not
+required to be accurate in any way, so we can get away with it.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p31d95b135879263b" name="p31d95b135879263b"> </a>A terrarium can be defined with a 'plan', which is an array of
+strings. We could have used a single string, but because JavaScript
+strings must stay on a single line it would have been a lot harder to
+type.</p><pre class="code"><span class="keyword">var</span> <span class="variable">thePlan</span> =
+ [<span class="string">"############################"</span>,
+ <span class="string">"# # # o ##"</span>,
+ <span class="string">"# #"</span>,
+ <span class="string">"# ##### #"</span>,
+ <span class="string">"## # # ## #"</span>,
+ <span class="string">"### ## # #"</span>,
+ <span class="string">"# ### # #"</span>,
+ <span class="string">"# #### #"</span>,
+ <span class="string">"# ## o #"</span>,
+ <span class="string">"# o # o ### #"</span>,
+ <span class="string">"# # #"</span>,
+ <span class="string">"############################"</span>];</pre><p><a class="paragraph" href="#p2aad21964803d546" name="p2aad21964803d546"> </a>The <code>"#"</code> characters are used to represent the walls of the terrarium
+(and the ornamental rocks lying in it), the <code>"o"</code>s represent bugs, and
+the spaces are, as you might have guessed, empty space.</p><p><a class="paragraph" href="#p740e6749d33ce2f9" name="p740e6749d33ce2f9"> </a>Such a plan-array can be used to create a terrarium-object. This
+object keeps track of the shape and content of the terrarium, and lets
+the bugs inside move. It has four methods: Firstly <code>toString</code>, which
+converts the terrarium back to a string similar to the plan it was
+based on, so that you can see what is going on inside it. Then there
+is <code>step</code>, which allows all the bugs in the terrarium to move one
+step, if they so desire. And finally, there are <code>start</code> and <code>stop</code>,
+which control whether the terrarium is 'running'. When it is running,
+<code>step</code> is automatically called every half second, so the bugs keep
+moving.</p></div><hr/><div class="block"><a name="exercise1"></a><div class="exercisenum">Ex. 8.1</div><div class="exercise"><p><a class="paragraph" href="#p6a3a9ecbec6a2f09" name="p6a3a9ecbec6a2f09"> </a><a name="key19"></a>The points on the grid will be represented by objects again.
+In <a href="chapter7.html">chapter 7</a> we used three functions, <code>point</code>, <code>addPoints</code>, and
+<code>samePoint</code> to work with points. This time, we will use a constructor
+and two methods. Write the constructor <code>Point</code>, which takes two
+arguments, the x and y coordinates of the point, and produces an
+object with <code>x</code> and <code>y</code> properties. Give the prototype of this
+constructor a method <code>add</code>, which takes another point as argument and
+returns a <em>new</em> point whose <code>x</code> and <code>y</code> are the sum of the <code>x</code> and <code>y</code>
+of the two given points. Also add a method <code>isEqualTo</code>, which takes a
+point and returns a boolean indicating whether the <code>this</code> point refers
+to the same coordinates as the given point.</p><p><a class="paragraph" href="#p6470113307af5b6f" name="p6470113307af5b6f"> </a>Apart from the two methods, the <code>x</code> and <code>y</code> properties are also part
+of the interface of this type of objects: Code which uses point
+objects may freely retrieve and modify <code>x</code> and <code>y</code>.</p></div><div class="solution"><pre class="code"><span class="keyword">function</span> <span class="variable">Point</span>(<span class="variabledef">x</span>, <span class="variabledef">y</span>) {
+ <span class="localvariable">this</span>.<span class="property">x</span> = <span class="localvariable">x</span>;
+ <span class="localvariable">this</span>.<span class="property">y</span> = <span class="localvariable">y</span>;
+}
+<span class="variable">Point</span>.<span class="property">prototype</span>.<span class="property">add</span> = <span class="keyword">function</span>(<span class="variabledef">other</span>) {
+ <span class="keyword">return</span> <span class="keyword">new</span> <span class="variable">Point</span>(<span class="localvariable">this</span>.<span class="property">x</span> + <span class="localvariable">other</span>.<span class="property">x</span>, <span class="localvariable">this</span>.<span class="property">y</span> + <span class="localvariable">other</span>.<span class="property">y</span>);
+};
+<span class="variable">Point</span>.<span class="property">prototype</span>.<span class="property">isEqualTo</span> = <span class="keyword">function</span>(<span class="variabledef">other</span>) {
+ <span class="keyword">return</span> <span class="localvariable">this</span>.<span class="property">x</span> == <span class="localvariable">other</span>.<span class="property">x</span> && <span class="localvariable">this</span>.<span class="property">y</span> == <span class="localvariable">other</span>.<span class="property">y</span>;
+};
+
+<span class="variable">show</span>((<span class="keyword">new</span> <span class="variable">Point</span>(<span class="atom">3</span>, <span class="atom">1</span>)).<span class="property">add</span>(<span class="keyword">new</span> <span class="variable">Point</span>(<span class="atom">2</span>, <span class="atom">4</span>)));</pre><p><a class="paragraph" href="#pb18a786ec7d72cd" name="pb18a786ec7d72cd"> </a>Make sure your version of <code>add</code> leaves the <code>this</code> point intact and
+produces a new point object. A method which changes the current point
+instead would be similar to the <code>+=</code> operator, whereas this one is
+like the <code>+</code> operator.</p></div></div><hr/><div class="block"><p><a class="paragraph" href="#p4a6b18b171398590" name="p4a6b18b171398590"> </a>When writing objects to implement a certain program, it is not always
+very clear which functionality goes where. Some things are best
+written as methods of your objects, other things are better expressed
+as separate functions, and some things are best implemented by adding
+a new type of object. To keep things clear and organised, it is
+important to keep the amount of methods and responsibilities that an
+object type has as small as possible. When an object does too much, it
+becomes a big mess of functionality, and a formidable source of
+confusion.</p><p><a class="paragraph" href="#p672169de2a03529" name="p672169de2a03529"> </a>I said above that the terrarium object will be responsible for storing
+its contents and for letting the bugs inside it move. Firstly, note
+that it <em>lets</em> them move, it doesn't <em>make</em> them move. The bugs
+themselves will also be objects, and these objects are responsible for
+deciding what they want to do. The terrarium merely provides the
+infrastructure that asks them what to do every half second, and if
+they decide to move, it makes sure this happens.</p><p><a class="paragraph" href="#pbafe28cb7b5f0f7" name="pbafe28cb7b5f0f7"> </a>Storing the grid on which the content of the terrarium is kept can get
+quite complex. It has to define some kind of representation, ways to
+access this representation, a way to initialise the grid from a 'plan'
+array, a way to write the content of the grid to a string for the
+<code>toString</code> method, and the movement of the bugs on the grid. It would
+be nice if part of this could be moved into another object, so that
+the terrarium object itself doesn't get too big and complex.</p></div><hr/><div class="block"><p><a class="paragraph" href="#pbd9c6f6076dd1a7" name="pbd9c6f6076dd1a7"> </a>Whenever you find yourself about to mix data representation and
+problem-specific code in one object, it is a good idea to try and put
+the data representation code into a separate type of object. In this
+case, we need to represent a grid of values, so I wrote a <code>Grid</code> type,
+which supports the operations that the terrarium will need.</p><p><a class="paragraph" href="#p6f1d3ff563ace594" name="p6f1d3ff563ace594"> </a>To store the values on the grid, there are two options. One can use an
+array of arrays, like this:</p><pre class="code"><span class="keyword">var</span> <span class="variable">grid</span> = [[<span class="string">"0,0"</span>, <span class="string">"1,0"</span>, <span class="string">"2,0"</span>],
+ [<span class="string">"0,1"</span>, <span class="string">"1,1"</span>, <span class="string">"2,1"</span>]];
+<span class="variable">show</span>(<span class="variable">grid</span>[<span class="atom">1</span>][<span class="atom">2</span>]);</pre><p><a class="paragraph" href="#p6ed2e51aa687f5bb" name="p6ed2e51aa687f5bb"> </a>Or the values can all be put into a single array. In this case, the
+element at <code>x</code>,<code>y</code> can be found by getting the element at position <code>x
++ y * width</code> in the array, where <code>width</code> is the width of the grid.</p><pre class="code"><span class="keyword">var</span> <span class="variable">grid</span> = [<span class="string">"0,0"</span>, <span class="string">"1,0"</span>, <span class="string">"2,0"</span>,
+ <span class="string">"0,1"</span>, <span class="string">"1,1"</span>, <span class="string">"2,1"</span>];
+<span class="variable">show</span>(<span class="variable">grid</span>[<span class="atom">2</span> + <span class="atom">1</span> * <span class="atom">3</span>]);</pre><p><a class="paragraph" href="#p707a25be90bfffe" name="p707a25be90bfffe"> </a><a name="key20"></a>I chose the second representation, because it makes it much
+easier to initialise the array. <code>new Array(x)</code> produces a new array of
+length <code>x</code>, filled with <code>undefined</code> values.</p><pre class="code"><span class="keyword">function</span> <span class="variable">Grid</span>(<span class="variabledef">width</span>, <span class="variabledef">height</span>) {
+ <span class="localvariable">this</span>.<span class="property">width</span> = <span class="localvariable">width</span>;
+ <span class="localvariable">this</span>.<span class="property">height</span> = <span class="localvariable">height</span>;
+ <span class="localvariable">this</span>.<span class="property">cells</span> = <span class="keyword">new</span> <span class="variable">Array</span>(<span class="localvariable">width</span> * <span class="localvariable">height</span>);
+}
+<span class="variable">Grid</span>.<span class="property">prototype</span>.<span class="property">valueAt</span> = <span class="keyword">function</span>(<span class="variabledef">point</span>) {
+ <span class="keyword">return</span> <span class="localvariable">this</span>.<span class="property">cells</span>[<span class="localvariable">point</span>.<span class="property">y</span> * <span class="localvariable">this</span>.<span class="property">width</span> + <span class="localvariable">point</span>.<span class="property">x</span>];
+};
+<span class="variable">Grid</span>.<span class="property">prototype</span>.<span class="property">setValueAt</span> = <span class="keyword">function</span>(<span class="variabledef">point</span>, <span class="variabledef">value</span>) {
+ <span class="localvariable">this</span>.<span class="property">cells</span>[<span class="localvariable">point</span>.<span class="property">y</span> * <span class="localvariable">this</span>.<span class="property">width</span> + <span class="localvariable">point</span>.<span class="property">x</span>] = <span class="localvariable">value</span>;
+};
+<span class="variable">Grid</span>.<span class="property">prototype</span>.<span class="property">isInside</span> = <span class="keyword">function</span>(<span class="variabledef">point</span>) {
+ <span class="keyword">return</span> <span class="localvariable">point</span>.<span class="property">x</span> >= <span class="atom">0</span> && <span class="localvariable">point</span>.<span class="property">y</span> >= <span class="atom">0</span> &&
+ <span class="localvariable">point</span>.<span class="property">x</span> < <span class="localvariable">this</span>.<span class="property">width</span> && <span class="localvariable">point</span>.<span class="property">y</span> < <span class="localvariable">this</span>.<span class="property">height</span>;
+};
+<span class="variable">Grid</span>.<span class="property">prototype</span>.<span class="property">moveValue</span> = <span class="keyword">function</span>(<span class="variabledef">from</span>, <span class="variabledef">to</span>) {
+ <span class="localvariable">this</span>.<span class="property">setValueAt</span>(<span class="localvariable">to</span>, <span class="localvariable">this</span>.<span class="property">valueAt</span>(<span class="localvariable">from</span>));
+ <span class="localvariable">this</span>.<span class="property">setValueAt</span>(<span class="localvariable">from</span>, <span class="atom">undefined</span>);
+};</pre></div><hr/><div class="block"><a name="exercise2"></a><div class="exercisenum">Ex. 8.2</div><div class="exercise"><p><a class="paragraph" href="#p40a4c6abd51cb533" name="p40a4c6abd51cb533"> </a>We will also need to go over all the elements of the grid, to find the
+bugs we need to move, or to convert the whole thing to a string. To
+make this easy, we can use a higher-order function that takes an
+action as its argument. Add the method <code>each</code> to the prototype of
+<code>Grid</code>, which takes a function of two arguments as its argument. It
+calls this function for every point on the grid, giving it the point
+object for that point as its first argument, and the value that is on
+the grid at that point as second argument.</p><p><a class="paragraph" href="#p3481d8529fd5bb73" name="p3481d8529fd5bb73"> </a>Go over the points starting at <code>0</code>,<code>0</code>, one row at a time, so that
+<code>1</code>,<code>0</code> is handled before <code>0</code>,<code>1</code>. This will make it easier to write
+the <code>toString</code> function of the terrarium later. (Hint: Put a <code>for</code>
+loop for the <code>x</code> coordinate inside a loop for the <code>y</code> coordinate.)</p><p><a class="paragraph" href="#p42d988cd4825b7e4" name="p42d988cd4825b7e4"> </a>It is advisable not to muck about in the <code>cells</code> property of the grid
+object directly, but use <code>valueAt</code> to get at the values. This way, if
+we decide (for some reason) to use a different method for storing the
+values, we only have to rewrite <code>valueAt</code> and <code>setValueAt</code>, and the
+other methods can stay untouched.</p></div><div class="solution"><pre class="code"><span class="variable">Grid</span>.<span class="property">prototype</span>.<span class="property">each</span> = <span class="keyword">function</span>(<span class="variabledef">action</span>) {
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variabledef">y</span> = <span class="atom">0</span>; <span class="localvariable">y</span> < <span class="localvariable">this</span>.<span class="property">height</span>; <span class="localvariable">y</span>++) {
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variabledef">x</span> = <span class="atom">0</span>; <span class="localvariable">x</span> < <span class="localvariable">this</span>.<span class="property">width</span>; <span class="localvariable">x</span>++) {
+ <span class="keyword">var</span> <span class="variabledef">point</span> = <span class="keyword">new</span> <span class="variable">Point</span>(<span class="localvariable">x</span>, <span class="localvariable">y</span>);
+ <span class="localvariable">action</span>(<span class="localvariable">point</span>, <span class="localvariable">this</span>.<span class="property">valueAt</span>(<span class="localvariable">point</span>));
+ }
+ }
+};</pre></div></div><hr/><div class="block"><p><a class="paragraph" href="#p137d4c10de0b3623" name="p137d4c10de0b3623"> </a>Finally, to test the grid:</p><pre class="code"><span class="keyword">var</span> <span class="variable">testGrid</span> = <span class="keyword">new</span> <span class="variable">Grid</span>(<span class="atom">3</span>, <span class="atom">2</span>);
+<span class="variable">testGrid</span>.<span class="property">setValueAt</span>(<span class="keyword">new</span> <span class="variable">Point</span>(<span class="atom">1</span>, <span class="atom">0</span>), <span class="string">"#"</span>);
+<span class="variable">testGrid</span>.<span class="property">setValueAt</span>(<span class="keyword">new</span> <span class="variable">Point</span>(<span class="atom">1</span>, <span class="atom">1</span>), <span class="string">"o"</span>);
+<span class="variable">testGrid</span>.<span class="property">each</span>(<span class="keyword">function</span>(<span class="variabledef">point</span>, <span class="variabledef">value</span>) {
+ <span class="variable">print</span>(<span class="localvariable">point</span>.<span class="property">x</span>, <span class="string">","</span>, <span class="localvariable">point</span>.<span class="property">y</span>, <span class="string">": "</span>, <span class="localvariable">value</span>);
+});</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p46446fffa7849114" name="p46446fffa7849114"> </a>Before we can start to write a <code>Terrarium</code> constructor, we will have
+to get a bit more specific about these 'bug objects' that will be
+living inside it. Earlier, I mentioned that the terrarium will ask the
+bugs what action they want to take. This will work as follows: Each
+bug object has an <code>act</code> method which, when called, returns an
+'action'. An action is an object with a <code>type</code> property, which names
+the type of action the bug wants to take, for example <code>"move"</code>. For
+most actions, the action also contains extra information, such as the
+direction the bug wants to go.</p><p><a class="paragraph" href="#p47cc4df13607024f" name="p47cc4df13607024f"> </a>Bugs are terribly myopic, they can only see the squares directly
+around them on the grid. But these they can use to base their action
+on. When the <code>act</code> method is called, it is given an object with
+information about the surroundings of the bug in question. For each of
+the eight directions, it contains a property. The property indicating
+what is above the bug is called <code>"n"</code>, for North, the one
+indicating what is above and to the right <code>"ne"</code>, for North-East, and
+so on. To look up the direction these names refer to, the following
+dictionary object is useful:</p><pre class="code"><span class="keyword">var</span> <span class="variable">directions</span> = <span class="keyword">new</span> <span class="variable">Dictionary</span>(
+ {<span class="string">"n"</span>: <span class="keyword">new</span> <span class="variable">Point</span>( <span class="atom">0</span>, -<span class="atom">1</span>),
+ <span class="string">"ne"</span>: <span class="keyword">new</span> <span class="variable">Point</span>( <span class="atom">1</span>, -<span class="atom">1</span>),
+ <span class="string">"e"</span>: <span class="keyword">new</span> <span class="variable">Point</span>( <span class="atom">1</span>, <span class="atom">0</span>),
+ <span class="string">"se"</span>: <span class="keyword">new</span> <span class="variable">Point</span>( <span class="atom">1</span>, <span class="atom">1</span>),
+ <span class="string">"s"</span>: <span class="keyword">new</span> <span class="variable">Point</span>( <span class="atom">0</span>, <span class="atom">1</span>),
+ <span class="string">"sw"</span>: <span class="keyword">new</span> <span class="variable">Point</span>(-<span class="atom">1</span>, <span class="atom">1</span>),
+ <span class="string">"w"</span>: <span class="keyword">new</span> <span class="variable">Point</span>(-<span class="atom">1</span>, <span class="atom">0</span>),
+ <span class="string">"nw"</span>: <span class="keyword">new</span> <span class="variable">Point</span>(-<span class="atom">1</span>, -<span class="atom">1</span>)});
+
+<span class="variable">show</span>(<span class="keyword">new</span> <span class="variable">Point</span>(<span class="atom">4</span>, <span class="atom">4</span>).<span class="property">add</span>(<span class="variable">directions</span>.<span class="property">lookup</span>(<span class="string">"se"</span>)));</pre><p><a class="paragraph" href="#p201f637041e299ba" name="p201f637041e299ba"> </a>When a bug decides to move, he indicates in which direction he wants
+to go by giving the resulting action object a <code>direction</code> property
+that names one of these directions. We can make a simple, stupid bug
+that always just goes south, 'towards the light', like this:</p><pre class="code"><span class="keyword">function</span> <span class="variable">StupidBug</span>() {};
+<span class="variable">StupidBug</span>.<span class="property">prototype</span>.<span class="property">act</span> = <span class="keyword">function</span>(<span class="variabledef">surroundings</span>) {
+ <span class="keyword">return</span> {<span class="property">type</span>: <span class="string">"move"</span>, <span class="property">direction</span>: <span class="string">"s"</span>};
+};</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p12783aa99e1b1f2e" name="p12783aa99e1b1f2e"> </a>Now we can start on the <code>Terrarium</code> object type itself. First, its
+constructor, which takes a plan (an array of strings) as argument, and
+initialises its grid.</p><pre class="code"><span class="keyword">var</span> <span class="variable">wall</span> = {};
+
+<span class="keyword">function</span> <span class="variable">Terrarium</span>(<span class="variabledef">plan</span>) {
+ <span class="keyword">var</span> <span class="variabledef">grid</span> = <span class="keyword">new</span> <span class="variable">Grid</span>(<span class="localvariable">plan</span>[<span class="atom">0</span>].<span class="property">length</span>, <span class="localvariable">plan</span>.<span class="property">length</span>);
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variabledef">y</span> = <span class="atom">0</span>; <span class="localvariable">y</span> < <span class="localvariable">plan</span>.<span class="property">length</span>; <span class="localvariable">y</span>++) {
+ <span class="keyword">var</span> <span class="variabledef">line</span> = <span class="localvariable">plan</span>[<span class="localvariable">y</span>];
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variabledef">x</span> = <span class="atom">0</span>; <span class="localvariable">x</span> < <span class="localvariable">line</span>.<span class="property">length</span>; <span class="localvariable">x</span>++) {
+ <span class="localvariable">grid</span>.<span class="property">setValueAt</span>(<span class="keyword">new</span> <span class="variable">Point</span>(<span class="localvariable">x</span>, <span class="localvariable">y</span>),
+ <span class="variable">elementFromCharacter</span>(<span class="localvariable">line</span>.<span class="property">charAt</span>(<span class="localvariable">x</span>)));
+ }
+ }
+ <span class="localvariable">this</span>.<span class="property">grid</span> = <span class="localvariable">grid</span>;
+}
+
+<span class="keyword">function</span> <span class="variable">elementFromCharacter</span>(<span class="variabledef">character</span>) {
+ <span class="keyword">if</span> (<span class="localvariable">character</span> == <span class="string">" "</span>)
+ <span class="keyword">return</span> <span class="atom">undefined</span>;
+ <span class="keyword">else</span> <span class="keyword">if</span> (<span class="localvariable">character</span> == <span class="string">"#"</span>)
+ <span class="keyword">return</span> <span class="variable">wall</span>;
+ <span class="keyword">else</span> <span class="keyword">if</span> (<span class="localvariable">character</span> == <span class="string">"o"</span>)
+ <span class="keyword">return</span> <span class="keyword">new</span> <span class="variable">StupidBug</span>();
+}</pre><p><a class="paragraph" href="#p265091ec9b2588c2" name="p265091ec9b2588c2"> </a><code>wall</code> is an object that is used to mark the location of walls on the
+grid. Like a real wall, it doesn't do much, it just sits there and
+takes up space.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p139280591b6b0e8" name="p139280591b6b0e8"> </a>The most straightforward method of a terrarium object is <code>toString</code>,
+which transforms a terrarium into a string. To make this easier, we
+mark both the <code>wall</code> and the prototype of the <code>StupidBug</code> with a
+property <code>character</code>, which holds the character that represents them.</p><pre class="code"><span class="variable">wall</span>.<span class="property">character</span> = <span class="string">"#"</span>;
+<span class="variable">StupidBug</span>.<span class="property">prototype</span>.<span class="property">character</span> = <span class="string">"o"</span>;
+
+<span class="keyword">function</span> <span class="variable">characterFromElement</span>(<span class="variabledef">element</span>) {
+ <span class="keyword">if</span> (<span class="localvariable">element</span> == <span class="atom">undefined</span>)
+ <span class="keyword">return</span> <span class="string">" "</span>;
+ <span class="keyword">else</span>
+ <span class="keyword">return</span> <span class="localvariable">element</span>.<span class="property">character</span>;
+}
+
+<span class="variable">show</span>(<span class="variable">characterFromElement</span>(<span class="variable">wall</span>));</pre></div><hr/><div class="block"><a name="exercise3"></a><div class="exercisenum">Ex. 8.3</div><div class="exercise"><p><a class="paragraph" href="#p5692c3b1fe7182a5" name="p5692c3b1fe7182a5"> </a>Now we can use the <code>each</code> method of the <code>Grid</code> object to build up a
+string. But to make the result readable, it would be nice to have a
+newline at the end of every row. The <code>x</code> coordinate of the positions
+on the grid can be used to determine when the end of a line is
+reached. Add a method <code>toString</code> to the <code>Terrarium</code> prototype, which
+takes no arguments and returns a string that, when given to <code>print</code>,
+shows a nice two-dimensional view of the terrarium.</p></div><div class="solution"><pre class="code"><span class="variable">Terrarium</span>.<span class="property">prototype</span>.<span class="property">toString</span> = <span class="keyword">function</span>() {
+ <span class="keyword">var</span> <span class="variabledef">characters</span> = [];
+ <span class="keyword">var</span> <span class="variabledef">endOfLine</span> = <span class="localvariable">this</span>.<span class="property">grid</span>.<span class="property">width</span> - <span class="atom">1</span>;
+ <span class="localvariable">this</span>.<span class="property">grid</span>.<span class="property">each</span>(<span class="keyword">function</span>(<span class="variabledef">point</span>, <span class="variabledef">value</span>) {
+ <span class="localvariable">characters</span>.<span class="property">push</span>(<span class="variable">characterFromElement</span>(<span class="localvariable">value</span>));
+ <span class="keyword">if</span> (<span class="localvariable">point</span>.<span class="property">x</span> == <span class="localvariable">endOfLine</span>)
+ <span class="localvariable">characters</span>.<span class="property">push</span>(<span class="string">"\n"</span>);
+ });
+ <span class="keyword">return</span> <span class="localvariable">characters</span>.<span class="property">join</span>(<span class="string">""</span>);
+};</pre><p><a class="paragraph" href="#p6d6fe7f48ed236e" name="p6d6fe7f48ed236e"> </a>And to try it out...</p><pre class="code"><span class="keyword">var</span> <span class="variable">terrarium</span> = <span class="keyword">new</span> <span class="variable">Terrarium</span>(<span class="variable">thePlan</span>);
+<span class="variable">print</span>(<span class="variable">terrarium</span>.<span class="property">toString</span>());</pre></div></div><hr/><div class="block"><p><a class="paragraph" href="#pdab3c0c48b40f87" name="pdab3c0c48b40f87"> </a>It is possible that, when trying to solve the above exercise, you have
+tried to access <code>this.grid</code> inside the function that you pass as an
+argument to the grid's <code>each</code> method. This will not work. Calling a
+function always results in a new <code>this</code> being defined inside that
+function, even when it is not used as a method. Thus, any <code>this</code>
+variable outside of the function will not be visible.</p><p><a class="paragraph" href="#p6fceb2e91589da6a" name="p6fceb2e91589da6a"> </a>Sometimes it is straightforward to work around this by storing the
+information you need in a variable, like <code>endOfLine</code>, which <em>is</em>
+visible in the inner function. If you need access to the whole <code>this</code>
+object, you can store that in a variable too. The name <code>self</code> (or
+<code>that</code>) is often used for such a variable.</p><p><a class="paragraph" href="#pa47ded0a2ea1bbb" name="pa47ded0a2ea1bbb"> </a>But all these extra variables can get messy. Another good solution is
+to use a function similar to <code>partial</code> from <a href="chapter6.html">chapter 6</a>. Instead of adding
+arguments to a function, this one adds a <code>this</code> object, using the
+first argument to the function's <code>apply</code> method:</p><pre class="code"><span class="keyword">function</span> <span class="variable">bind</span>(<span class="variabledef">func</span>, <span class="variabledef">object</span>) {
+ <span class="keyword">return</span> <span class="keyword">function</span>(){
+ <span class="keyword">return</span> <span class="localvariable">func</span>.<span class="property">apply</span>(<span class="localvariable">object</span>, <span class="localvariable">arguments</span>);
+ };
+}
+
+<span class="keyword">var</span> <span class="variable">testArray</span> = [];
+<span class="keyword">var</span> <span class="variable">pushTest</span> = <span class="variable">bind</span>(<span class="variable">testArray</span>.<span class="property">push</span>, <span class="variable">testArray</span>);
+<span class="variable">pushTest</span>(<span class="string">"A"</span>);
+<span class="variable">pushTest</span>(<span class="string">"B"</span>);
+<span class="variable">show</span>(<span class="variable">testArray</span>);</pre><p><a class="paragraph" href="#p5fca76321e7b900a" name="p5fca76321e7b900a"> </a>This way, you can <code>bind</code> an inner function to <code>this</code>, and it will have
+the same <code>this</code> as the outer function.</p></div><hr/><div class="block"><a name="exercise4"></a><div class="exercisenum">Ex. 8.4</div><div class="exercise"><p><a class="paragraph" href="#p2f6a2baf6a6ea0a0" name="p2f6a2baf6a6ea0a0"> </a>In the expression <code>bind(testArray.push, testArray)</code> the name
+<code>testArray</code> still occurs twice. Can you design a function <a name="key21"></a><code>method</code>,
+which allows you to bind an object to one of its methods <em>without</em>
+naming the object twice?</p></div><div class="solution"><p><a class="paragraph" href="#p120fbfe1bd84d26" name="p120fbfe1bd84d26"> </a>It is possible to give the name of the method as a string. This way, the
+<code>method</code> function can look up the correct function value for itself.</p><pre class="code"><span class="keyword">function</span> <span class="variable">method</span>(<span class="variabledef">object</span>, <span class="variabledef">name</span>) {
+ <span class="keyword">return</span> <span class="keyword">function</span>() {
+ <span class="keyword">return</span> <span class="localvariable">object</span>[<span class="localvariable">name</span>].<span class="property">apply</span>(<span class="localvariable">object</span>, <span class="localvariable">arguments</span>);
+ };
+}
+
+<span class="keyword">var</span> <span class="variable">pushTest</span> = <span class="variable">method</span>(<span class="variable">testArray</span>, <span class="string">"push"</span>);</pre></div></div><hr/><div class="block"><p><a class="paragraph" href="#p7a810d1a779f7817" name="p7a810d1a779f7817"> </a>We will need <code>bind</code> (or <code>method</code>) when implementing the <code>step</code> method
+of a terrarium. This method has to go over all the bugs on the grid,
+ask them for an action, and execute the given action. You might be
+tempted to use <code>each</code> on the grid, and just handle the bugs we come
+across. But then, when a bug moves South or East, we will come across
+it again in the same turn, and allow it to move again.</p><p><a class="paragraph" href="#p5e7251b804191f66" name="p5e7251b804191f66"> </a>Instead, we first gather all the bugs into an array, and then process
+them. This method gathers bugs, or other things that have an <code>act</code>
+method, and stores them in objects that also contain their current
+position:</p><pre class="code"><span class="variable">Terrarium</span>.<span class="property">prototype</span>.<span class="property">listActingCreatures</span> = <span class="keyword">function</span>() {
+ <span class="keyword">var</span> <span class="variabledef">found</span> = [];
+ <span class="localvariable">this</span>.<span class="property">grid</span>.<span class="property">each</span>(<span class="keyword">function</span>(<span class="variabledef">point</span>, <span class="variabledef">value</span>) {
+ <span class="keyword">if</span> (<span class="localvariable">value</span> != <span class="atom">undefined</span> && <span class="localvariable">value</span>.<span class="property">act</span>)
+ <span class="localvariable">found</span>.<span class="property">push</span>({<span class="property">object</span>: <span class="localvariable">value</span>, <span class="property">point</span>: <span class="localvariable">point</span>});
+ });
+ <span class="keyword">return</span> <span class="localvariable">found</span>;
+};</pre></div><hr/><div class="block"><a name="exercise5"></a><div class="exercisenum">Ex. 8.5</div><div class="exercise"><p><a class="paragraph" href="#p40072543c02b30aa" name="p40072543c02b30aa"> </a>When asking a bug to act, we must pass it an object with information
+about its current surroundings. This object will use the direction
+names we saw earlier (<code>"n"</code>, <code>"ne"</code>, etcetera) as property names. Each
+property holds a string of one character, as returned by
+<code>characterFromElement</code>, indicating what the bug can see in that
+direction.</p><p><a class="paragraph" href="#p4d6a26d8b927c395" name="p4d6a26d8b927c395"> </a>Add a method <code>listSurroundings</code> to the <code>Terrarium</code> prototype. It takes
+one argument, the point at which the bug is currently standing, and
+returns an object with information about the surroundings of that
+point. When the point is at the edge of the grid, use <code>"#"</code> for the
+directions that go outside of the grid, so the bug will not try to
+move there.</p><p><a class="paragraph" href="#p17dec5980cfd5fb6" name="p17dec5980cfd5fb6"> </a>Hint: Do not write out all the directions, use the <code>each</code> method on
+the <code>directions</code> dictionary.</p></div><div class="solution"><pre class="code"><span class="variable">Terrarium</span>.<span class="property">prototype</span>.<span class="property">listSurroundings</span> = <span class="keyword">function</span>(<span class="variabledef">center</span>) {
+ <span class="keyword">var</span> <span class="variabledef">result</span> = {};
+ <span class="keyword">var</span> <span class="variabledef">grid</span> = <span class="localvariable">this</span>.<span class="property">grid</span>;
+ <span class="variable">directions</span>.<span class="property">each</span>(<span class="keyword">function</span>(<span class="variabledef">name</span>, <span class="variabledef">direction</span>) {
+ <span class="keyword">var</span> <span class="variabledef">place</span> = <span class="localvariable">center</span>.<span class="property">add</span>(<span class="localvariable">direction</span>);
+ <span class="keyword">if</span> (<span class="localvariable">grid</span>.<span class="property">isInside</span>(<span class="localvariable">place</span>))
+ <span class="localvariable">result</span>[<span class="localvariable">name</span>] = <span class="variable">characterFromElement</span>(<span class="localvariable">grid</span>.<span class="property">valueAt</span>(<span class="localvariable">place</span>));
+ <span class="keyword">else</span>
+ <span class="localvariable">result</span>[<span class="localvariable">name</span>] = <span class="string">"#"</span>;
+ });
+ <span class="keyword">return</span> <span class="localvariable">result</span>;
+};</pre><p><a class="paragraph" href="#p413cebbd56aad079" name="p413cebbd56aad079"> </a>Note the use of the <code>grid</code> variable to work around the <code>this</code> problem.</p></div></div><hr/><div class="block"><p><a class="paragraph" href="#p6297bb18dc0fb882" name="p6297bb18dc0fb882"> </a>Both above methods are not part of the external interface of a
+<code>Terrarium</code> object, they are internal details. Some languages provide
+ways to explicitly declare certain methods and properties 'private',
+and make it an error to use them from outside the object. JavaScript
+does not, so you will have to rely on comments to describe the
+interface to an object. Sometimes it can be useful to use some kind of
+naming scheme to distinguish between external and internal properties,
+for example by prefixing all internal ones with an underscore ('<code>_</code>').
+This will make accidental uses of properties that are not part of an
+object's interface easier to spot.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p5c3903e78df76607" name="p5c3903e78df76607"> </a>Next is one more internal method, the one that will ask a bug for an
+action and carry it out. It takes an object with <code>object</code> and <code>point</code>
+properties, as returned by <code>listActingCreatures</code>, as argument. For now,
+it only knows about the <code>"move"</code> action:</p><pre class="code"><span class="variable">Terrarium</span>.<span class="property">prototype</span>.<span class="property">processCreature</span> = <span class="keyword">function</span>(<span class="variabledef">creature</span>) {
+ <span class="keyword">var</span> <span class="variabledef">surroundings</span> = <span class="localvariable">this</span>.<span class="property">listSurroundings</span>(<span class="localvariable">creature</span>.<span class="property">point</span>);
+ <span class="keyword">var</span> <span class="variabledef">action</span> = <span class="localvariable">creature</span>.<span class="property">object</span>.<span class="property">act</span>(<span class="localvariable">surroundings</span>);
+ <span class="keyword">if</span> (<span class="localvariable">action</span>.<span class="property">type</span> == <span class="string">"move"</span> && <span class="variable">directions</span>.<span class="property">contains</span>(<span class="localvariable">action</span>.<span class="property">direction</span>)) {
+ <span class="keyword">var</span> <span class="variabledef">to</span> = <span class="localvariable">creature</span>.<span class="property">point</span>.<span class="property">add</span>(<span class="variable">directions</span>.<span class="property">lookup</span>(<span class="localvariable">action</span>.<span class="property">direction</span>));
+ <span class="keyword">if</span> (<span class="localvariable">this</span>.<span class="property">grid</span>.<span class="property">isInside</span>(<span class="localvariable">to</span>) && <span class="localvariable">this</span>.<span class="property">grid</span>.<span class="property">valueAt</span>(<span class="localvariable">to</span>) == <span class="atom">undefined</span>)
+ <span class="localvariable">this</span>.<span class="property">grid</span>.<span class="property">moveValue</span>(<span class="localvariable">creature</span>.<span class="property">point</span>, <span class="localvariable">to</span>);
+ }
+ <span class="keyword">else</span> {
+ <span class="keyword">throw</span> <span class="keyword">new</span> <span class="variable">Error</span>(<span class="string">"Unsupported action: "</span> + <span class="localvariable">action</span>.<span class="property">type</span>);
+ }
+};</pre><p><a class="paragraph" href="#p20fba0575128ec62" name="p20fba0575128ec62"> </a>Note that it checks whether the chosen direction is inside of the grid
+and empty, and ignores it otherwise. This way, the bugs can ask for
+any action they like ― the action will only be carried out if it is
+actually possible. This acts as a layer of insulation between the bugs
+and the terrarium, and allows us to be less precise when writing the
+bugs' <code>act</code> methods ― for example the <code>StupidBug</code> just always travels
+South, regardless of any walls that might stand in its way.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p6d41bfbdb15a2e59" name="p6d41bfbdb15a2e59"> </a>These three internal methods then finally allow us to write the <code>step</code>
+method, which gives all bugs a chance to do something (all elements
+with an <code>act</code> method ― we could also give the <code>wall</code> object one if we
+so desired, and make the walls walk).</p><pre class="code"><span class="variable">Terrarium</span>.<span class="property">prototype</span>.<span class="property">step</span> = <span class="keyword">function</span>() {
+ <span class="variable">forEach</span>(<span class="localvariable">this</span>.<span class="property">listActingCreatures</span>(),
+ <span class="variable">bind</span>(<span class="localvariable">this</span>.<span class="property">processCreature</span>, <span class="localvariable">this</span>));
+};</pre><p><a class="paragraph" href="#p4a17101cbea56a43" name="p4a17101cbea56a43"> </a>Now, let us make a terrarium and see whether the bugs move...</p><pre class="code"><span class="keyword">var</span> <span class="variable">terrarium</span> = <span class="keyword">new</span> <span class="variable">Terrarium</span>(<span class="variable">thePlan</span>);
+<span class="variable">print</span>(<span class="variable">terrarium</span>);
+<span class="variable">terrarium</span>.<span class="property">step</span>();
+<span class="variable">print</span>(<span class="variable">terrarium</span>);</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p3bef263cc0ca4203" name="p3bef263cc0ca4203"> </a>Wait, how come the above calls <code>print(terrarium)</code> and ends up
+displaying the output of our <a name="key22"></a><code>toString</code> method? <code>print</code> turns its
+arguments to strings using the <code>String</code> function. Objects are turned
+to strings by calling their <code>toString</code> method, so giving your own
+object types a meaningful <code>toString</code> is a good way to make them
+readable when printed out.</p><pre class="code"><span class="variable">Point</span>.<span class="property">prototype</span>.<span class="property">toString</span> = <span class="keyword">function</span>() {
+ <span class="keyword">return</span> <span class="string">"("</span> + <span class="localvariable">this</span>.<span class="property">x</span> + <span class="string">","</span> + <span class="localvariable">this</span>.<span class="property">y</span> + <span class="string">")"</span>;
+};
+<span class="variable">print</span>(<span class="keyword">new</span> <span class="variable">Point</span>(<span class="atom">5</span>, <span class="atom">5</span>));</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p66525715fa3ed4fe" name="p66525715fa3ed4fe"> </a>As promised, <code>Terrarium</code> objects also get <code>start</code> and <code>stop</code> methods
+to start or stop their simulation. For this, we will use two functions
+provided by the browser, called <a name="key23"></a><code>setInterval</code> and <a name="key24"></a><code>clearInterval</code>.
+The first is used to cause its first argument (a function, or a string
+containing JavaScript code) to be executed periodically. Its second
+argument gives the amount of milliseconds (1/1000 second) between
+invocations. It returns a value that can be given to <code>clearInterval</code>
+to stop its effect.</p><pre class="code"><span class="keyword">var</span> <span class="variable">annoy</span> = <span class="variable">setInterval</span>(<span class="keyword">function</span>() {<span class="variable">print</span>(<span class="string">"What?"</span>);}, <span class="atom">400</span>);</pre><p><a class="paragraph" href="#p5a9b2d6a5" name="p5a9b2d6a5"> </a>And...</p><pre class="code"><span class="variable">clearInterval</span>(<span class="variable">annoy</span>);</pre><p><a class="paragraph" href="#p65c6552ce64152a2" name="p65c6552ce64152a2"> </a>There are similar functions for one-shot time-based actions.
+<a name="key25"></a><code>setTimeout</code> causes a function or string to be executed after a
+given amount of milliseconds, and <a name="key26"></a><code>clearTimeout</code> cancels such an
+action.</p></div><hr/><div class="block"><pre class="code"><span class="variable">Terrarium</span>.<span class="property">prototype</span>.<span class="property">start</span> = <span class="keyword">function</span>() {
+ <span class="keyword">if</span> (!<span class="localvariable">this</span>.<span class="property">running</span>)
+ <span class="localvariable">this</span>.<span class="property">running</span> = <span class="variable">setInterval</span>(<span class="variable">bind</span>(<span class="localvariable">this</span>.<span class="property">step</span>, <span class="localvariable">this</span>), <span class="atom">500</span>);
+};
+
+<span class="variable">Terrarium</span>.<span class="property">prototype</span>.<span class="property">stop</span> = <span class="keyword">function</span>() {
+ <span class="keyword">if</span> (<span class="localvariable">this</span>.<span class="property">running</span>) {
+ <span class="variable">clearInterval</span>(<span class="localvariable">this</span>.<span class="property">running</span>);
+ <span class="localvariable">this</span>.<span class="property">running</span> = <span class="atom">null</span>;
+ }
+};</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p56dee92e9e45266d" name="p56dee92e9e45266d"> </a>Now we have a terrarium with some simple-minded bugs, and we can run
+it. But to see what is going on, we have to repeatedly do
+<code>print(terrarium)</code>, or we won't see what is going on. That is not very
+practical. It would be nicer if it would print automatically. It would
+also look better if, instead of printing a thousand terraria below
+each other, we could update a single printout of the terrarium. For
+that second problem, this page conveniently provides a function called
+<code>inPlacePrinter</code>. It returns a function like <code>print</code> which, instead of
+adding to the output, replaces its previous output.</p><pre class="code"><span class="keyword">var</span> <span class="variable">printHere</span> = <span class="variable">inPlacePrinter</span>();
+<span class="variable">printHere</span>(<span class="string">"Now you see it."</span>);
+<span class="variable">setTimeout</span>(<span class="variable">partial</span>(<span class="variable">printHere</span>, <span class="string">"Now you don't."</span>), <span class="atom">1000</span>);</pre><p><a class="paragraph" href="#p709059f44d4e6a50" name="p709059f44d4e6a50"> </a>To cause the terrarium to be re-printed every time it changes, we can
+modify the <code>step</code> method as follows:</p><pre class="code"><span class="variable">Terrarium</span>.<span class="property">prototype</span>.<span class="property">step</span> = <span class="keyword">function</span>() {
+ <span class="variable">forEach</span>(<span class="localvariable">this</span>.<span class="property">listActingCreatures</span>(),
+ <span class="variable">bind</span>(<span class="localvariable">this</span>.<span class="property">processCreature</span>, <span class="localvariable">this</span>));
+ <span class="keyword">if</span> (<span class="localvariable">this</span>.<span class="property">onStep</span>)
+ <span class="localvariable">this</span>.<span class="property">onStep</span>();
+};</pre><p><a class="paragraph" href="#p4290eaad2c2db8ab" name="p4290eaad2c2db8ab"> </a>Now, when an <code>onStep</code> property has been added to a terrarium, it will
+be called on every step.</p><pre class="code"><span class="keyword">var</span> <span class="variable">terrarium</span> = <span class="keyword">new</span> <span class="variable">Terrarium</span>(<span class="variable">thePlan</span>);
+<span class="variable">terrarium</span>.<span class="property">onStep</span> = <span class="variable">partial</span>(<span class="variable">inPlacePrinter</span>(), <span class="variable">terrarium</span>);
+<span class="variable">terrarium</span>.<span class="property">start</span>();</pre><p><a class="paragraph" href="#p2d0605452e8bd940" name="p2d0605452e8bd940"> ¶ </a>Note the use of <code>partial</code> ― it produces an in-place printer applied
+to the terrarium. Such a printer only takes one argument, so after
+partially applying it there are no arguments left, and it becomes a
+function of zero arguments. That is exactly what we need for the
+<code>onStep</code> property.</p><p><a class="paragraph" href="#p6373da70db3ecd6d" name="p6373da70db3ecd6d"> </a>Don't forget to stop the terrarium when it is no longer interesting
+(which should be pretty soon), so that it does not keep wasting your
+computer's resources:</p><pre class="code"><span class="variable">terrarium</span>.<span class="property">stop</span>();</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p473ec2ade63fa198" name="p473ec2ade63fa198"> </a>But who wants a terrarium with just one kind of bug, and a stupid bug
+at that? Not me. It would be nice if we could add different kinds of
+bugs. Fortunately, all we have to do is to make the
+<code>elementFromCharacter</code> function more general. Right now it contains
+three cases which are typed in directly, or 'hard-coded':</p><pre class="code"><span class="keyword">function</span> <span class="variable">elementFromCharacter</span>(<span class="variabledef">character</span>) {
+ <span class="keyword">if</span> (<span class="localvariable">character</span> == <span class="string">" "</span>)
+ <span class="keyword">return</span> <span class="atom">undefined</span>;
+ <span class="keyword">else</span> <span class="keyword">if</span> (<span class="localvariable">character</span> == <span class="string">"#"</span>)
+ <span class="keyword">return</span> <span class="variable">wall</span>;
+ <span class="keyword">else</span> <span class="keyword">if</span> (<span class="localvariable">character</span> == <span class="string">"o"</span>)
+ <span class="keyword">return</span> <span class="keyword">new</span> <span class="variable">StupidBug</span>();
+}</pre><p><a class="paragraph" href="#p1d99a6fa022e107" name="p1d99a6fa022e107"> </a>The first two cases we can leave intact, but the last one is way too
+specific. A better approach would be to store the characters and the
+corresponding bug-constructors in a dictionary, and look for them
+there:</p><pre class="code"><span class="keyword">var</span> <span class="variable">creatureTypes</span> = <span class="keyword">new</span> <span class="variable">Dictionary</span>();
+<span class="variable">creatureTypes</span>.<span class="property">register</span> = <span class="keyword">function</span>(<span class="variabledef">constructor</span>) {
+ <span class="localvariable">this</span>.<span class="property">store</span>(<span class="localvariable">constructor</span>.<span class="property">prototype</span>.<span class="property">character</span>, <span class="localvariable">constructor</span>);
+};
+
+<span class="keyword">function</span> <span class="variable">elementFromCharacter</span>(<span class="variabledef">character</span>) {
+ <span class="keyword">if</span> (<span class="localvariable">character</span> == <span class="string">" "</span>)
+ <span class="keyword">return</span> <span class="atom">undefined</span>;
+ <span class="keyword">else</span> <span class="keyword">if</span> (<span class="localvariable">character</span> == <span class="string">"#"</span>)
+ <span class="keyword">return</span> <span class="variable">wall</span>;
+ <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">creatureTypes</span>.<span class="property">contains</span>(<span class="localvariable">character</span>))
+ <span class="keyword">return</span> <span class="keyword">new</span> (<span class="variable">creatureTypes</span>.<span class="property">lookup</span>(<span class="localvariable">character</span>))();
+ <span class="keyword">else</span>
+ <span class="keyword">throw</span> <span class="keyword">new</span> <span class="variable">Error</span>(<span class="string">"Unknown character: "</span> + <span class="localvariable">character</span>);
+}</pre><p><a class="paragraph" href="#p24b496fddbe1c1a" name="p24b496fddbe1c1a"> ¶ </a>Note how the <code>register</code> method is added to <code>creatureTypes</code> ― this is
+a dictionary object, but there is no reason why it shouldn't support
+an additional method. This method looks up the character associated
+with a constructor, and stores it in the dictionary. It should only be
+called on constructors whose prototype does actually have a
+<code>character</code> property.</p><p><a class="paragraph" href="#p2577d0539c0a27ad" name="p2577d0539c0a27ad"> </a><code>elementFromCharacter</code> now looks up the character it is given in
+<code>creatureTypes</code>, and raises an exception when it comes across an
+unknown character.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p7dc5495832c0814d" name="p7dc5495832c0814d"> </a>Here is a new bug type, and the call to register its character in
+<code>creatureTypes</code>:</p><pre class="code"><span class="keyword">function</span> <span class="variable">BouncingBug</span>() {
+ <span class="localvariable">this</span>.<span class="property">direction</span> = <span class="string">"ne"</span>;
+}
+<span class="variable">BouncingBug</span>.<span class="property">prototype</span>.<span class="property">act</span> = <span class="keyword">function</span>(<span class="variabledef">surroundings</span>) {
+ <span class="keyword">if</span> (<span class="localvariable">surroundings</span>[<span class="localvariable">this</span>.<span class="property">direction</span>] != <span class="string">" "</span>)
+ <span class="localvariable">this</span>.<span class="property">direction</span> = (<span class="localvariable">this</span>.<span class="property">direction</span> == <span class="string">"ne"</span> ? <span class="string">"sw"</span> : <span class="string">"ne"</span>);
+ <span class="keyword">return</span> {<span class="property">type</span>: <span class="string">"move"</span>, <span class="property">direction</span>: <span class="localvariable">this</span>.<span class="property">direction</span>};
+};
+<span class="variable">BouncingBug</span>.<span class="property">prototype</span>.<span class="property">character</span> = <span class="string">"%"</span>;
+
+<span class="variable">creatureTypes</span>.<span class="property">register</span>(<span class="variable">BouncingBug</span>);</pre><p><a class="paragraph" href="#p2a96bb089be30662" name="p2a96bb089be30662"> </a>Can you figure out what it does?</p></div><hr/><div class="block"><a name="exercise6"></a><div class="exercisenum">Ex. 8.6</div><div class="exercise"><p><a class="paragraph" href="#p18ddd7e93c010002" name="p18ddd7e93c010002"> </a>Create a bug type called <code>DrunkBug</code> which tries to move in a random
+direction every turn, never mind whether there is a wall there.
+Remember the <code>Math.random</code> trick from <a href="chapter7.html">chapter 7</a>.</p></div><div class="solution"><p><a class="paragraph" href="#p63e8265c4f32da15" name="p63e8265c4f32da15"> </a>To pick a random direction, we will need an array of direction names.
+We could of course just type <code>["n", "ne", ...]</code>, but that duplicates
+information, and duplicated information makes me nervous. We could
+also use the <code>each</code> method in <code>directions</code> to build the array, which
+is better already.</p><p><a class="paragraph" href="#pfa2dff0e314562b" name="pfa2dff0e314562b"> </a>But there is clearly a generality to be discovered here. Getting a
+list of the property names in a dictionary sounds like a useful tool
+to have, so we add it to the <code>Dictionary</code> prototype.</p><pre class="code"><span class="variable">Dictionary</span>.<span class="property">prototype</span>.<span class="property">names</span> = <span class="keyword">function</span>() {
+ <span class="keyword">var</span> <span class="variabledef">names</span> = [];
+ <span class="localvariable">this</span>.<span class="property">each</span>(<span class="keyword">function</span>(<span class="variabledef">name</span>, <span class="variabledef">value</span>) {<span class="localvariable">names</span>.<span class="property">push</span>(<span class="localvariable">name</span>);});
+ <span class="keyword">return</span> <span class="localvariable">names</span>;
+};
+
+<span class="variable">show</span>(<span class="variable">directions</span>.<span class="property">names</span>());</pre><p><a class="paragraph" href="#p7cf14ca4dffbc4a9" name="p7cf14ca4dffbc4a9"> </a>A real neurotic programmer would immediately restore symmetry by also
+adding a <code>values</code> method, which returns a list of the values stored in
+the dictionary. But I guess that can wait until we <a href="http://www.c2.com/cgi/wiki?YouArentGonnaNeedIt">need it</a>.</p><p><a class="paragraph" href="#pc02c2c5583dbd50" name="pc02c2c5583dbd50"> </a>Here is a way to take a random element from an array:</p><pre class="code"><span class="keyword">function</span> <span class="variable">randomElement</span>(<span class="variabledef">array</span>) {
+ <span class="keyword">if</span> (<span class="localvariable">array</span>.<span class="property">length</span> == <span class="atom">0</span>)
+ <span class="keyword">throw</span> <span class="keyword">new</span> <span class="variable">Error</span>(<span class="string">"The array is empty."</span>);
+ <span class="keyword">return</span> <span class="localvariable">array</span>[<span class="variable">Math</span>.<span class="property">floor</span>(<span class="variable">Math</span>.<span class="property">random</span>() * <span class="localvariable">array</span>.<span class="property">length</span>)];
+}
+
+<span class="variable">show</span>(<span class="variable">randomElement</span>([<span class="string">"heads"</span>, <span class="string">"tails"</span>]));</pre><p><a class="paragraph" href="#p3f063625cdeea8e7" name="p3f063625cdeea8e7"> </a>And the bug itself:</p><pre class="code"><span class="keyword">function</span> <span class="variable">DrunkBug</span>() {};
+<span class="variable">DrunkBug</span>.<span class="property">prototype</span>.<span class="property">act</span> = <span class="keyword">function</span>(<span class="variabledef">surroundings</span>) {
+ <span class="keyword">return</span> {<span class="property">type</span>: <span class="string">"move"</span>,
+ <span class="property">direction</span>: <span class="variable">randomElement</span>(<span class="variable">directions</span>.<span class="property">names</span>())};
+};
+<span class="variable">DrunkBug</span>.<span class="property">prototype</span>.<span class="property">character</span> = <span class="string">"~"</span>;
+
+<span class="variable">creatureTypes</span>.<span class="property">register</span>(<span class="variable">DrunkBug</span>);</pre></div></div><hr/><div class="block"><p><a class="paragraph" href="#p6c2121e5aefe5ffe" name="p6c2121e5aefe5ffe"> </a>So, let us test out our new bugs:</p><pre class="code"><span class="keyword">var</span> <span class="variable">newPlan</span> =
+ [<span class="string">"############################"</span>,
+ <span class="string">"# #####"</span>,
+ <span class="string">"# ## ####"</span>,
+ <span class="string">"# #### ~ ~ ##"</span>,
+ <span class="string">"# ## ~ #"</span>,
+ <span class="string">"# #"</span>,
+ <span class="string">"# ### #"</span>,
+ <span class="string">"# ##### #"</span>,
+ <span class="string">"# ### #"</span>,
+ <span class="string">"# % ### % #"</span>,
+ <span class="string">"# ####### #"</span>,
+ <span class="string">"############################"</span>];
+
+<span class="keyword">var</span> <span class="variable">terrarium</span> = <span class="keyword">new</span> <span class="variable">Terrarium</span>(<span class="variable">newPlan</span>);
+<span class="variable">terrarium</span>.<span class="property">onStep</span> = <span class="variable">partial</span>(<span class="variable">inPlacePrinter</span>(), <span class="variable">terrarium</span>);
+<span class="variable">terrarium</span>.<span class="property">start</span>();</pre><p><a class="paragraph" href="#p248478d6c6accb5f" name="p248478d6c6accb5f"> </a>Notice the bouncing bugs bouncing off the drunk ones? Pure drama.
+Anyway, when you are done watching this fascinating show, shut it
+down:</p><pre class="code"><span class="variable">terrarium</span>.<span class="property">stop</span>();</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p79f13bf15c758a3b" name="p79f13bf15c758a3b"> </a>We now have two kinds of objects that both have an <code>act</code> method and a
+<code>character</code> property. Because they share these traits, the terrarium
+can approach them in the same way. This allows us to have all kinds of
+bugs, without changing anything about the terrarium code. This
+technique is called <a name="key27"></a>polymorphism, and it is arguably the most
+powerful aspect of object-oriented programming.</p><p><a class="paragraph" href="#p4ba9a1a3fa44f56b" name="p4ba9a1a3fa44f56b"> </a>The basic idea of polymorphism is that when a piece of code is written
+to work with objects that have a certain interface, any kind of object
+that happens to support this interface can be plugged into the code,
+and it will just work. We already saw simple examples of this, like
+the <code>toString</code> method on objects. All objects that have a meaningful
+<code>toString</code> method can be given to <code>print</code> and other functions that
+need to convert values to strings, and the correct string will be
+produced, no matter how their <code>toString</code> method chooses to build this
+string.</p><p><a class="paragraph" href="#p1fc9c932dbf032c2" name="p1fc9c932dbf032c2"> </a>Similarly, <code>forEach</code> works on both real arrays and the pseudo-arrays
+found in the <code>arguments</code> variable, because all it needs is a <code>length</code>
+property and properties called <code>0</code>, <code>1</code>, and so on, for the elements
+of the array.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p758d80d940318015" name="p758d80d940318015"> </a>To make life in the terrarium more life-like, we will add to it the
+concepts of food and reproduction. Each living thing in the terrarium
+gets a new property, <code>energy</code>, which is reduced by performing actions,
+and increased by eating things. When it has enough energy, a thing can
+reproduce<a class="footref" href="#footnote2">2</a>, generating a new creature of the same kind.</p><p><a class="paragraph" href="#p42c42d12dc3c248" name="p42c42d12dc3c248"> </a>If there are only bugs, wasting energy by moving around and eating
+each other, a terrarium will soon succumb to the forces of entropy,
+run out of energy, and become a lifeless wasteland. To prevent this
+from happening (too quickly, at least), we add lichen to the
+terrarium. Lichen do not move, they just use photo-synthesis to
+gather energy, and reproduce.</p><p><a class="paragraph" href="#p67d47ddc7a971734" name="p67d47ddc7a971734"> </a>To make this work, we will need a terrarium with a different
+<code>processCreature</code> method. We could just replace the method of to the
+<code>Terrarium</code> prototype, but we have become very attached to the
+simulation of the bouncing and drunk bugs, and we would hate to break
+our old terrarium.</p><p><a class="paragraph" href="#p65909203631b5139" name="p65909203631b5139"> </a>What we can do is create a new constructor, <code>LifeLikeTerrarium</code>, whose
+prototype is based on the <code>Terrarium</code> prototype, but which has a
+different <code>processCreature</code> method.</p></div><hr/><div class="block"><p><a class="paragraph" href="#pf522d85fca0a3c8" name="pf522d85fca0a3c8"> </a>There are a few ways to do this. We could go over the properties of
+<code>Terrarium.prototype</code>, and add them one by one to
+<code>LifeLikeTerrarium.prototype</code>. This is easy to do, and in some cases
+it is the best solution, but in this case there is a cleaner way. If
+we make the old prototype object the prototype of the new prototype
+object (you may have to re-read that a few times), it will
+automatically have all its properties.</p><p><a class="paragraph" href="#pd6a518d7928ff39" name="pd6a518d7928ff39"> </a><a name="key28"></a>Unfortunately, JavaScript does not have a straightforward
+way to create an object whose prototype is a certain other object. It
+is possible to write a function that does this, though, by using the
+following trick:</p><pre class="code"><span class="keyword">function</span> <span class="variable">clone</span>(<span class="variabledef">object</span>) {
+ <span class="keyword">function</span> <span class="variabledef">OneShotConstructor</span>(){}
+ <span class="localvariable">OneShotConstructor</span>.<span class="property">prototype</span> = <span class="localvariable">object</span>;
+ <span class="keyword">return</span> <span class="keyword">new</span> <span class="localvariable">OneShotConstructor</span>();
+}</pre><p><a class="paragraph" href="#p33ecaf21fae6c51d" name="p33ecaf21fae6c51d"> </a>This function uses an empty one-shot constructor, whose prototype is
+the given object. When using <code>new</code> on this constructor, it will create
+a new object based on the given object.</p><pre class="code"><span class="keyword">function</span> <span class="variable">LifeLikeTerrarium</span>(<span class="variabledef">plan</span>) {
+ <span class="variable">Terrarium</span>.<span class="property">call</span>(<span class="localvariable">this</span>, <span class="localvariable">plan</span>);
+}
+<span class="variable">LifeLikeTerrarium</span>.<span class="property">prototype</span> = <span class="variable">clone</span>(<span class="variable">Terrarium</span>.<span class="property">prototype</span>);
+<span class="variable">LifeLikeTerrarium</span>.<span class="property">prototype</span>.<span class="property">constructor</span> = <span class="variable">LifeLikeTerrarium</span>;</pre><p><a class="paragraph" href="#p2ba39a102e7bc" name="p2ba39a102e7bc"> </a>The new constructor doesn't need to do anything different from the old
+one, so it just calls the old one on the <code>this</code> object. We also have
+to restore the <code>constructor</code> property in the new prototype, or it
+would claim its constructor is <code>Terrarium</code> (which, of course, is only
+really a problem when we make use of this property, which we don't).</p></div><hr/><div class="block"><p><a class="paragraph" href="#p150b93ea584ba68d" name="p150b93ea584ba68d"> </a>It is now possible to replace some of the methods of the
+<code>LifeLikeTerrarium</code> object, or add new ones. We have based a new
+object type on an old one, which saved us the work of re-writing all
+the methods which are the same in <code>Terrarium</code> and <code>LifeLikeTerrarium</code>.
+This technique is called '<a name="key29"></a>inheritance'. The new type inherits the
+properties of the old type. In most cases, this means the new type
+will still support the interface of the old type, though it might also
+support a few methods that the old type does not have. This way,
+objects of the new type can be (polymorphically) used in all the
+places where objects of the old type could be used.</p><p><a class="paragraph" href="#p3cd64c42173d9d1b" name="p3cd64c42173d9d1b"> </a>In most programming languages with explicit support for
+object-oriented programming, inheritance is a very straightforward
+thing. In JavaScript, the language doesn't really specify a simple way
+to do it. Because of this, JavaScript programmers have invented many
+different approaches to inheritance. Unfortunately, none of them is
+quite perfect. Fortunately, such a broad range of approaches allows a
+programmer to choose the most suitable one for the problem he is
+solving, and allows certain tricks that would be utterly impossible in
+other languages.</p><p><a class="paragraph" href="#p463807b9df8e8556" name="p463807b9df8e8556"> </a>At the end of this chapter, I will show a few other ways to do
+inheritance, and the issues they have.</p></div><hr/><div class="block"><p><a class="paragraph" href="#pdf62a47811257c7" name="pdf62a47811257c7"> </a>Here is the new <code>processCreature</code> method. It is big.</p><pre class="code"><span class="variable">LifeLikeTerrarium</span>.<span class="property">prototype</span>.<span class="property">processCreature</span> = <span class="keyword">function</span>(<span class="variabledef">creature</span>) {
+ <span class="keyword">if</span> (<span class="localvariable">creature</span>.<span class="property">object</span>.<span class="property">energy</span> <= <span class="atom">0</span>) <span class="keyword">return</span>;
+ <span class="keyword">var</span> <span class="variabledef">surroundings</span> = <span class="localvariable">this</span>.<span class="property">listSurroundings</span>(<span class="localvariable">creature</span>.<span class="property">point</span>);
+ <span class="keyword">var</span> <span class="variabledef">action</span> = <span class="localvariable">creature</span>.<span class="property">object</span>.<span class="property">act</span>(<span class="localvariable">surroundings</span>);
+
+ <span class="keyword">var</span> <span class="variabledef">target</span> = <span class="atom">undefined</span>;
+ <span class="keyword">var</span> <span class="variabledef">valueAtTarget</span> = <span class="atom">undefined</span>;
+ <span class="keyword">if</span> (<span class="localvariable">action</span>.<span class="property">direction</span> && <span class="variable">directions</span>.<span class="property">contains</span>(<span class="localvariable">action</span>.<span class="property">direction</span>)) {
+ <span class="keyword">var</span> <span class="variabledef">direction</span> = <span class="variable">directions</span>.<span class="property">lookup</span>(<span class="localvariable">action</span>.<span class="property">direction</span>);
+ <span class="keyword">var</span> <span class="variabledef">maybe</span> = <span class="localvariable">creature</span>.<span class="property">point</span>.<span class="property">add</span>(<span class="localvariable">direction</span>);
+ <span class="keyword">if</span> (<span class="localvariable">this</span>.<span class="property">grid</span>.<span class="property">isInside</span>(<span class="localvariable">maybe</span>)) {
+ <span class="localvariable">target</span> = <span class="localvariable">maybe</span>;
+ <span class="localvariable">valueAtTarget</span> = <span class="localvariable">this</span>.<span class="property">grid</span>.<span class="property">valueAt</span>(<span class="localvariable">target</span>);
+ }
+ }
+
+ <span class="keyword">if</span> (<span class="localvariable">action</span>.<span class="property">type</span> == <span class="string">"move"</span>) {
+ <span class="keyword">if</span> (<span class="localvariable">target</span> && !<span class="localvariable">valueAtTarget</span>) {
+ <span class="localvariable">this</span>.<span class="property">grid</span>.<span class="property">moveValue</span>(<span class="localvariable">creature</span>.<span class="property">point</span>, <span class="localvariable">target</span>);
+ <span class="localvariable">creature</span>.<span class="property">point</span> = <span class="localvariable">target</span>;
+ <span class="localvariable">creature</span>.<span class="property">object</span>.<span class="property">energy</span> -= <span class="atom">1</span>;
+ }
+ }
+ <span class="keyword">else</span> <span class="keyword">if</span> (<span class="localvariable">action</span>.<span class="property">type</span> == <span class="string">"eat"</span>) {
+ <span class="keyword">if</span> (<span class="localvariable">valueAtTarget</span> && <span class="localvariable">valueAtTarget</span>.<span class="property">energy</span>) {
+ <span class="localvariable">this</span>.<span class="property">grid</span>.<span class="property">setValueAt</span>(<span class="localvariable">target</span>, <span class="atom">undefined</span>);
+ <span class="localvariable">creature</span>.<span class="property">object</span>.<span class="property">energy</span> += <span class="localvariable">valueAtTarget</span>.<span class="property">energy</span>;
+ <span class="localvariable">valueAtTarget</span>.<span class="property">energy</span> = <span class="atom">0</span>;
+ }
+ }
+ <span class="keyword">else</span> <span class="keyword">if</span> (<span class="localvariable">action</span>.<span class="property">type</span> == <span class="string">"photosynthese"</span>) {
+ <span class="localvariable">creature</span>.<span class="property">object</span>.<span class="property">energy</span> += <span class="atom">1</span>;
+ }
+ <span class="keyword">else</span> <span class="keyword">if</span> (<span class="localvariable">action</span>.<span class="property">type</span> == <span class="string">"reproduce"</span>) {
+ <span class="keyword">if</span> (<span class="localvariable">target</span> && !<span class="localvariable">valueAtTarget</span>) {
+ <span class="keyword">var</span> <span class="variabledef">species</span> = <span class="variable">characterFromElement</span>(<span class="localvariable">creature</span>.<span class="property">object</span>);
+ <span class="keyword">var</span> <span class="variabledef">baby</span> = <span class="variable">elementFromCharacter</span>(<span class="localvariable">species</span>);
+ <span class="localvariable">creature</span>.<span class="property">object</span>.<span class="property">energy</span> -= <span class="localvariable">baby</span>.<span class="property">energy</span> * <span class="atom">2</span>;
+ <span class="keyword">if</span> (<span class="localvariable">creature</span>.<span class="property">object</span>.<span class="property">energy</span> > <span class="atom">0</span>)
+ <span class="localvariable">this</span>.<span class="property">grid</span>.<span class="property">setValueAt</span>(<span class="localvariable">target</span>, <span class="localvariable">baby</span>);
+ }
+ }
+ <span class="keyword">else</span> <span class="keyword">if</span> (<span class="localvariable">action</span>.<span class="property">type</span> == <span class="string">"wait"</span>) {
+ <span class="localvariable">creature</span>.<span class="property">object</span>.<span class="property">energy</span> -= <span class="atom">0.2</span>;
+ }
+ <span class="keyword">else</span> {
+ <span class="keyword">throw</span> <span class="keyword">new</span> <span class="variable">Error</span>(<span class="string">"Unsupported action: "</span> + <span class="localvariable">action</span>.<span class="property">type</span>);
+ }
+
+ <span class="keyword">if</span> (<span class="localvariable">creature</span>.<span class="property">object</span>.<span class="property">energy</span> <= <span class="atom">0</span>)
+ <span class="localvariable">this</span>.<span class="property">grid</span>.<span class="property">setValueAt</span>(<span class="localvariable">creature</span>.<span class="property">point</span>, <span class="atom">undefined</span>);
+};</pre><p><a class="paragraph" href="#p2eb9628b144539c6" name="p2eb9628b144539c6"> </a>The function still starts by asking the creature for an action,
+provided it isn't out of energy (dead). Then, if the action has a
+<code>direction</code> property, it immediately computes which point on the grid
+this direction points to and which value is currently sitting there.
+Three of the five supported actions need to know this, and the code
+would be even uglier if they all computed it separately. If there is
+no <code>direction</code> property, or an invalid one, it leaves the variables
+<code>target</code> and <code>valueAtTarget</code> undefined.</p><p><a class="paragraph" href="#p678c8f5612aa7344" name="p678c8f5612aa7344"> </a>After this, it goes over all the actions. Some actions require
+additional checking before they are executed, this is done with a
+separate <code>if</code> so that if a creature, for example, tries to walk
+through a wall, we do not generate an <code>"Unsupported action"</code>
+exception.</p><p><a class="paragraph" href="#p3b24dea4a496986b" name="p3b24dea4a496986b"> </a>Note that, in the <code>"reproduce"</code> action, the parent creature loses
+twice the energy that the newborn creature gets (childbearing is not
+easy), and the new creature is only placed on the grid if the parent
+had enough energy to produce it.</p><p><a class="paragraph" href="#p35cba7057ce1e0ef" name="p35cba7057ce1e0ef"> </a>After the action has been performed, we check whether the creature is
+out of energy. If it is, it dies, and we remove it.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p2f7f93b8a136a25b" name="p2f7f93b8a136a25b"> </a>Lichen is not a very complex organism. We will use the character <code>"*"</code>
+to represent it. Make sure you have defined the <code>randomElement</code>
+function from <a href="chapter8.html#exercise6">exercise 8.6</a>, because it is used again here.</p><pre class="code"><span class="keyword">function</span> <span class="variable">Lichen</span>() {
+ <span class="localvariable">this</span>.<span class="property">energy</span> = <span class="atom">5</span>;
+}
+<span class="variable">Lichen</span>.<span class="property">prototype</span>.<span class="property">act</span> = <span class="keyword">function</span>(<span class="variabledef">surroundings</span>) {
+ <span class="keyword">var</span> <span class="variabledef">emptySpace</span> = <span class="variable">findDirections</span>(<span class="localvariable">surroundings</span>, <span class="string">" "</span>);
+ <span class="keyword">if</span> (<span class="localvariable">this</span>.<span class="property">energy</span> >= <span class="atom">13</span> && <span class="localvariable">emptySpace</span>.<span class="property">length</span> > <span class="atom">0</span>)
+ <span class="keyword">return</span> {<span class="property">type</span>: <span class="string">"reproduce"</span>, <span class="property">direction</span>: <span class="variable">randomElement</span>(<span class="localvariable">emptySpace</span>)};
+ <span class="keyword">else</span> <span class="keyword">if</span> (<span class="localvariable">this</span>.<span class="property">energy</span> < <span class="atom">20</span>)
+ <span class="keyword">return</span> {<span class="property">type</span>: <span class="string">"photosynthese"</span>};
+ <span class="keyword">else</span>
+ <span class="keyword">return</span> {<span class="property">type</span>: <span class="string">"wait"</span>};
+};
+<span class="variable">Lichen</span>.<span class="property">prototype</span>.<span class="property">character</span> = <span class="string">"*"</span>;
+
+<span class="variable">creatureTypes</span>.<span class="property">register</span>(<span class="variable">Lichen</span>);
+
+<span class="keyword">function</span> <span class="variable">findDirections</span>(<span class="variabledef">surroundings</span>, <span class="variabledef">wanted</span>) {
+ <span class="keyword">var</span> <span class="variabledef">found</span> = [];
+ <span class="variable">directions</span>.<span class="property">each</span>(<span class="keyword">function</span>(<span class="variabledef">name</span>) {
+ <span class="keyword">if</span> (<span class="localvariable">surroundings</span>[<span class="localvariable">name</span>] == <span class="localvariable">wanted</span>)
+ <span class="localvariable">found</span>.<span class="property">push</span>(<span class="localvariable">name</span>);
+ });
+ <span class="keyword">return</span> <span class="localvariable">found</span>;
+}</pre><p><a class="paragraph" href="#p6b321b75a17e9afc" name="p6b321b75a17e9afc"> </a>Lichen do not grow bigger than 20 energy, or they would get <em>huge</em>
+when they are surrounded by other lichen and have no room to
+reproduce.</p></div><hr/><div class="block"><a name="exercise7"></a><div class="exercisenum">Ex. 8.7</div><div class="exercise"><p><a class="paragraph" href="#p7a952902fe987f86" name="p7a952902fe987f86"> </a>Create a <code>LichenEater</code> creature. It starts with an energy of <code>10</code>, and
+behaves in the following way:</p><ul><li>When it has an energy of 30 or more, and there is room near it, it reproduces.</li><li>Otherwise, if there are lichen nearby, it eats a random one.</li><li>Otherwise, if there is space to move, it moves into a random nearby empty square.</li><li>Otherwise, it waits.</li></ul><p><a class="paragraph" href="#p362b1713f878db19" name="p362b1713f878db19"> </a>Use <code>findDirections</code> and <code>randomElement</code> to check the surroundings and
+to pick directions. Give the lichen-eater <code>"c"</code> as its character
+(pac-man).</p></div><div class="solution"><pre class="code"><span class="keyword">function</span> <span class="variable">LichenEater</span>() {
+ <span class="localvariable">this</span>.<span class="property">energy</span> = <span class="atom">10</span>;
+}
+<span class="variable">LichenEater</span>.<span class="property">prototype</span>.<span class="property">act</span> = <span class="keyword">function</span>(<span class="variabledef">surroundings</span>) {
+ <span class="keyword">var</span> <span class="variabledef">emptySpace</span> = <span class="variable">findDirections</span>(<span class="localvariable">surroundings</span>, <span class="string">" "</span>);
+ <span class="keyword">var</span> <span class="variabledef">lichen</span> = <span class="variable">findDirections</span>(<span class="localvariable">surroundings</span>, <span class="string">"*"</span>);
+
+ <span class="keyword">if</span> (<span class="localvariable">this</span>.<span class="property">energy</span> >= <span class="atom">30</span> && <span class="localvariable">emptySpace</span>.<span class="property">length</span> > <span class="atom">0</span>)
+ <span class="keyword">return</span> {<span class="property">type</span>: <span class="string">"reproduce"</span>, <span class="property">direction</span>: <span class="variable">randomElement</span>(<span class="localvariable">emptySpace</span>)};
+ <span class="keyword">else</span> <span class="keyword">if</span> (<span class="localvariable">lichen</span>.<span class="property">length</span> > <span class="atom">0</span>)
+ <span class="keyword">return</span> {<span class="property">type</span>: <span class="string">"eat"</span>, <span class="property">direction</span>: <span class="variable">randomElement</span>(<span class="localvariable">lichen</span>)};
+ <span class="keyword">else</span> <span class="keyword">if</span> (<span class="localvariable">emptySpace</span>.<span class="property">length</span> > <span class="atom">0</span>)
+ <span class="keyword">return</span> {<span class="property">type</span>: <span class="string">"move"</span>, <span class="property">direction</span>: <span class="variable">randomElement</span>(<span class="localvariable">emptySpace</span>)};
+ <span class="keyword">else</span>
+ <span class="keyword">return</span> {<span class="property">type</span>: <span class="string">"wait"</span>};
+};
+<span class="variable">LichenEater</span>.<span class="property">prototype</span>.<span class="property">character</span> = <span class="string">"c"</span>;
+
+<span class="variable">creatureTypes</span>.<span class="property">register</span>(<span class="variable">LichenEater</span>);</pre></div></div><hr/><div class="block"><p><a class="paragraph" href="#p3eb90111f0a15929" name="p3eb90111f0a15929"> </a>And try it out.</p><pre class="code"><span class="keyword">var</span> <span class="variable">lichenPlan</span> =
+ [<span class="string">"############################"</span>,
+ <span class="string">"# ######"</span>,
+ <span class="string">"# *** **##"</span>,
+ <span class="string">"# *##** ** c *##"</span>,
+ <span class="string">"# *** c ##** *#"</span>,
+ <span class="string">"# c ##*** *#"</span>,
+ <span class="string">"# ##** *#"</span>,
+ <span class="string">"# c #* *#"</span>,
+ <span class="string">"#* #** c *#"</span>,
+ <span class="string">"#*** ##** c **#"</span>,
+ <span class="string">"#***** ###*** *###"</span>,
+ <span class="string">"############################"</span>];
+
+<span class="keyword">var</span> <span class="variable">terrarium</span> = <span class="keyword">new</span> <span class="variable">LifeLikeTerrarium</span>(<span class="variable">lichenPlan</span>);
+<span class="variable">terrarium</span>.<span class="property">onStep</span> = <span class="variable">partial</span>(<span class="variable">inPlacePrinter</span>(), <span class="variable">terrarium</span>);
+<span class="variable">terrarium</span>.<span class="property">start</span>();</pre><p><a class="paragraph" href="#p32f60535b0258d2c" name="p32f60535b0258d2c"> </a>Most likely, you will see the lichen quickly over-grow a large part of
+the terrarium, after which the abundance of food makes the eaters so
+numerous that they wipe out all the lichen, and thus themselves. Ah,
+tragedy of nature.</p><pre class="code"><span class="variable">terrarium</span>.<span class="property">stop</span>();</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p2ce28a6e767ca8f3" name="p2ce28a6e767ca8f3"> </a>Having the inhabitants of your terrarium go extinct after a few
+minutes is kind of depressing. To deal with this, we have to teach our
+lichen-eaters about long-term sustainable farming. By making them only
+eat if they see at least two lichen nearby, no matter how hungry they
+are, they will never exterminate the lichen. This requires some
+discipline, but the result is a biotope that does not destroy itself.
+Here is a new <code>act</code> method ― the only change is that it now only eats
+when <code>lichen.length</code> is at least two.</p><pre class="code"><span class="variable">LichenEater</span>.<span class="property">prototype</span>.<span class="property">act</span> = <span class="keyword">function</span>(<span class="variabledef">surroundings</span>) {
+ <span class="keyword">var</span> <span class="variabledef">emptySpace</span> = <span class="variable">findDirections</span>(<span class="localvariable">surroundings</span>, <span class="string">" "</span>);
+ <span class="keyword">var</span> <span class="variabledef">lichen</span> = <span class="variable">findDirections</span>(<span class="localvariable">surroundings</span>, <span class="string">"*"</span>);
+
+ <span class="keyword">if</span> (<span class="localvariable">this</span>.<span class="property">energy</span> >= <span class="atom">30</span> && <span class="localvariable">emptySpace</span>.<span class="property">length</span> > <span class="atom">0</span>)
+ <span class="keyword">return</span> {<span class="property">type</span>: <span class="string">"reproduce"</span>, <span class="property">direction</span>: <span class="variable">randomElement</span>(<span class="localvariable">emptySpace</span>)};
+ <span class="keyword">else</span> <span class="keyword">if</span> (<span class="localvariable">lichen</span>.<span class="property">length</span> > <span class="atom">1</span>)
+ <span class="keyword">return</span> {<span class="property">type</span>: <span class="string">"eat"</span>, <span class="property">direction</span>: <span class="variable">randomElement</span>(<span class="localvariable">lichen</span>)};
+ <span class="keyword">else</span> <span class="keyword">if</span> (<span class="localvariable">emptySpace</span>.<span class="property">length</span> > <span class="atom">0</span>)
+ <span class="keyword">return</span> {<span class="property">type</span>: <span class="string">"move"</span>, <span class="property">direction</span>: <span class="variable">randomElement</span>(<span class="localvariable">emptySpace</span>)};
+ <span class="keyword">else</span>
+ <span class="keyword">return</span> {<span class="property">type</span>: <span class="string">"wait"</span>};
+};</pre><p><a class="paragraph" href="#p20678085b14d6a43" name="p20678085b14d6a43"> </a>Run the above <code>lichenPlan</code> terrarium again, and see how it goes.
+Unless you are very lucky, the lichen-eaters will probably still go
+extinct after a while, because, in a time of mass starvation, they
+crawl aimlessly back and forth through empty space, instead of finding
+the lichen that is sitting just around the corner.</p></div><hr/><div class="block"><a name="exercise8"></a><div class="exercisenum">Ex. 8.8</div><div class="exercise"><p><a class="paragraph" href="#p579343bcf39d474e" name="p579343bcf39d474e"> </a>Find a way to modify the <code>LichenEater</code> to be more likely to survive.
+Do not cheat ― <code>this.energy += 100</code> is cheating. If you rewrite the
+constructor, do not forget to re-register it in the <code>creatureTypes</code>
+dictionary, or the terrarium will continue to use the old constructor.</p></div><div class="solution"><p><a class="paragraph" href="#p75ffb12656cb10eb" name="p75ffb12656cb10eb"> </a>One approach would be to reduce the randomness of its movement. By
+always picking a random direction, it will often move back and forth
+without getting anywhere. By remembering the last direction it went,
+and preferring that direction, the eater will waste less time, and
+find food faster.</p><pre class="code"><span class="keyword">function</span> <span class="variable">CleverLichenEater</span>() {
+ <span class="localvariable">this</span>.<span class="property">energy</span> = <span class="atom">10</span>;
+ <span class="localvariable">this</span>.<span class="property">direction</span> = <span class="string">"ne"</span>;
+}
+<span class="variable">CleverLichenEater</span>.<span class="property">prototype</span>.<span class="property">act</span> = <span class="keyword">function</span>(<span class="variabledef">surroundings</span>) {
+ <span class="keyword">var</span> <span class="variabledef">emptySpace</span> = <span class="variable">findDirections</span>(<span class="localvariable">surroundings</span>, <span class="string">" "</span>);
+ <span class="keyword">var</span> <span class="variabledef">lichen</span> = <span class="variable">findDirections</span>(<span class="localvariable">surroundings</span>, <span class="string">"*"</span>);
+
+ <span class="keyword">if</span> (<span class="localvariable">this</span>.<span class="property">energy</span> >= <span class="atom">30</span> && <span class="localvariable">emptySpace</span>.<span class="property">length</span> > <span class="atom">0</span>) {
+ <span class="keyword">return</span> {<span class="property">type</span>: <span class="string">"reproduce"</span>,
+ <span class="property">direction</span>: <span class="variable">randomElement</span>(<span class="localvariable">emptySpace</span>)};
+ }
+ <span class="keyword">else</span> <span class="keyword">if</span> (<span class="localvariable">lichen</span>.<span class="property">length</span> > <span class="atom">1</span>) {
+ <span class="keyword">return</span> {<span class="property">type</span>: <span class="string">"eat"</span>,
+ <span class="property">direction</span>: <span class="variable">randomElement</span>(<span class="localvariable">lichen</span>)};
+ }
+ <span class="keyword">else</span> <span class="keyword">if</span> (<span class="localvariable">emptySpace</span>.<span class="property">length</span> > <span class="atom">0</span>) {
+ <span class="keyword">if</span> (<span class="localvariable">surroundings</span>[<span class="localvariable">this</span>.<span class="property">direction</span>] != <span class="string">" "</span>)
+ <span class="localvariable">this</span>.<span class="property">direction</span> = <span class="variable">randomElement</span>(<span class="localvariable">emptySpace</span>);
+ <span class="keyword">return</span> {<span class="property">type</span>: <span class="string">"move"</span>,
+ <span class="property">direction</span>: <span class="localvariable">this</span>.<span class="property">direction</span>};
+ }
+ <span class="keyword">else</span> {
+ <span class="keyword">return</span> {<span class="property">type</span>: <span class="string">"wait"</span>};
+ }
+};
+<span class="variable">CleverLichenEater</span>.<span class="property">prototype</span>.<span class="property">character</span> = <span class="string">"c"</span>;
+
+<span class="variable">creatureTypes</span>.<span class="property">register</span>(<span class="variable">CleverLichenEater</span>);</pre><p><a class="paragraph" href="#p4437e880cacc64e1" name="p4437e880cacc64e1"> </a>Try it out using the previous terrarium-plan.</p></div></div><hr/><div class="block"><a name="exercise9"></a><div class="exercisenum">Ex. 8.9</div><div class="exercise"><p><a class="paragraph" href="#pfec1523c677c149" name="pfec1523c677c149"> </a>A one-link food chain is still a bit rudimentary. Can you write a new
+creature, <code>LichenEaterEater</code> (character <code>"@"</code>), which survives by
+eating lichen-eaters? Try to find a way to make it fit in the
+ecosystem without dying out too quickly. Modify the <code>lichenPlan</code> array
+to include a few of these, and try them out.</p></div><div class="solution"><p><a class="paragraph" href="#p23994d0645459645" name="p23994d0645459645"> </a>You are on your own here. I failed to find a really good way to
+prevent these creatures from either going extinct right away or
+gobbling up all lichen-eaters and then going extinct. The trick of
+only eating when it spots two pieces of food doesn't work very well
+for them, because their food moves around so much it is rare to find
+two in one place. What does seem to help is making the eater-eater
+really fat (high energy), so that it can survive times when
+lichen-eaters are scarce, and only reproduces slowly, which prevents
+it from exterminating its food source too quickly.</p><p><a class="paragraph" href="#p446e3604a8766308" name="p446e3604a8766308"> ¶ </a>The lichen and eaters go through a periodic movement ― sometimes
+lichen are abundant, which causes a lot of eaters to be born, which
+causes the lichen to become scarce, which causes the eaters to starve,
+which causes the lichen to become abundant, and so on. You could try
+to make the lichen-eater-eaters 'hibernate' (use the <code>"wait"</code> action
+for a while), when they fail to find food for a few turns. If you
+choose the right amount of turns for this hibernation, or have them
+wake up automatically when they smell lots of food, this could be a
+good strategy.</p></div></div><hr/><div class="block"><p><a class="paragraph" href="#p436c3a722d3cad23" name="p436c3a722d3cad23"> </a>That concludes our discussion of terraria. The rest of the chapter is
+devoted to a more in-depth look at inheritance, and the problems
+related to inheritance in JavaScript.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p3830370304b66488" name="p3830370304b66488"> </a>First, some theory. Students of object-oriented programming can often
+be heard having lengthy, subtle discussions about correct and
+incorrect uses of inheritance. It is important to bear in mind that
+inheritance, in the end, is just a trick that allows lazy<a class="footref" href="#footnote3">3</a>
+programmers to write less code. Thus, the question of whether
+inheritance is being used correctly boils down to the question of
+whether the resulting code works correctly and avoids useless
+repetitions. Still, the principles used by these students provide a
+good way to start thinking about inheritance.</p><p><a class="paragraph" href="#p32881e0715c30db" name="p32881e0715c30db"> </a>Inheritance is the creation of a new type of objects, the
+'<a name="key30"></a>sub-type', based on an existing type, the '<a name="key31"></a>super-type'. The
+sub-type starts with all the properties and methods of the super-type,
+it inherits them, and then modifies a few of these, and optionally
+adds new ones. Inheritance is best used when the thing modelled by the
+sub-type can be said to <em>be</em> an object of the super-type.</p><p><a class="paragraph" href="#p1dec7ccc2bddffe4" name="p1dec7ccc2bddffe4"> </a>Thus, a <code>Piano</code> type could be a sub-type of an <code>Instrument</code> type,
+because a piano <em>is</em> an instrument. Because a piano has a whole array
+of keys, one might be tempted to make <code>Piano</code> a sub-type of <code>Array</code>,
+but a piano <em>is</em> no array, and implementing it like that is bound to
+lead to all kinds of silliness. For example, a piano also has pedals.
+Why would <code>piano[0]</code> give me the first key, and not the first pedal?
+The situation is, of course, that a piano <em>has</em> keys, so it would be
+better to give it a property <code>keys</code>, and possibly another property
+<code>pedals</code>, both holding arrays.</p><p><a class="paragraph" href="#p6a1c7c2b75c953a7" name="p6a1c7c2b75c953a7"> </a>It is possible for a sub-type to be the super-type of yet another
+sub-type. Some problems are best solved by building a complex family
+tree of types. You have to take care not to get too inheritance-happy,
+though. Overuse of inheritance is a great way to make a program into a
+big ugly mess.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p644bfcb5a2a20d3e" name="p644bfcb5a2a20d3e"> </a>The working of the <code>new</code> keyword and the <code>prototype</code> property of
+constructors suggest a certain way of using objects. For simple
+objects, such as the terrarium-creatures, this way works rather well.
+Unfortunately, when a program starts to make serious use of
+inheritance, this approach to objects quickly becomes clumsy. Adding
+some functions to take care of common operations can make things a
+little smoother. Many people define, for example, <code>inherit</code> and
+<code>method</code> methods on objects.</p><pre class="code"><span class="variable">Object</span>.<span class="property">prototype</span>.<span class="property">inherit</span> = <span class="keyword">function</span>(<span class="variabledef">baseConstructor</span>) {
+ <span class="localvariable">this</span>.<span class="property">prototype</span> = <span class="variable">clone</span>(<span class="localvariable">baseConstructor</span>.<span class="property">prototype</span>);
+ <span class="localvariable">this</span>.<span class="property">prototype</span>.<span class="property">constructor</span> = <span class="localvariable">this</span>;
+};
+<span class="variable">Object</span>.<span class="property">prototype</span>.<span class="property">method</span> = <span class="keyword">function</span>(<span class="variabledef">name</span>, <span class="variabledef">func</span>) {
+ <span class="localvariable">this</span>.<span class="property">prototype</span>[<span class="localvariable">name</span>] = <span class="localvariable">func</span>;
+};
+
+<span class="keyword">function</span> <span class="variable">StrangeArray</span>(){}
+<span class="variable">StrangeArray</span>.<span class="property">inherit</span>(<span class="variable">Array</span>);
+<span class="variable">StrangeArray</span>.<span class="property">method</span>(<span class="string">"push"</span>, <span class="keyword">function</span>(<span class="variabledef">value</span>) {
+ <span class="variable">Array</span>.<span class="property">prototype</span>.<span class="property">push</span>.<span class="property">call</span>(<span class="localvariable">this</span>, <span class="localvariable">value</span>);
+ <span class="variable">Array</span>.<span class="property">prototype</span>.<span class="property">push</span>.<span class="property">call</span>(<span class="localvariable">this</span>, <span class="localvariable">value</span>);
+});
+
+<span class="keyword">var</span> <span class="variable">strange</span> = <span class="keyword">new</span> <span class="variable">StrangeArray</span>();
+<span class="variable">strange</span>.<span class="property">push</span>(<span class="atom">4</span>);
+<span class="variable">show</span>(<span class="variable">strange</span>);</pre><p><a class="paragraph" href="#p27152a799564fcf9" name="p27152a799564fcf9"> </a>If you search the web for the words 'JavaScript' and 'inheritance',
+you will come across scores of different variations on this, some of
+them quite a lot more complex and clever than the above.</p><p><a class="paragraph" href="#p5e8a5e0394d81eb" name="p5e8a5e0394d81eb"> </a>Note how the <code>push</code> method written here uses the <code>push</code> method from
+the prototype of its parent type. This is something that is done often
+when using inheritance ― a method in the sub-type internally uses a
+method of the super-type, but extends it somehow.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p6a4f3dddfa85055c" name="p6a4f3dddfa85055c"> </a>The biggest problem with this basic approach is the duality between
+constructors and prototypes. Constructors take a very central role,
+they are the things that give an object type its name, and when you
+need to get at a prototype, you have to go to the constructor and take
+its <code>prototype</code> property.</p><p><a class="paragraph" href="#p2e0cd0294f8f916b" name="p2e0cd0294f8f916b"> </a>Not only does this lead to a <em>lot</em> of typing (<code>"prototype"</code> is 9
+letters), it is also confusing. We had to write an empty, useless
+constructor for <code>StrangeArray</code> in the example above. Quite a few
+times, I have found myself accidentally adding methods to a
+constructor instead of its prototype, or trying to call <code>Array.slice</code>
+when I really meant <code>Array.prototype.slice</code>. As far as I am concerned,
+the prototype itself is the most important aspect of an object type,
+and the constructor is just an extension of that, a special kind of
+method.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p7e0e1720d924931f" name="p7e0e1720d924931f"> </a>With a few simple helper methods added to <code>Object.prototype</code>, it is
+possible to create an alternative approach to objects and inheritance.
+In this approach, a type is represented by its prototype, and we will
+use capitalised variables to store these prototypes. When it needs to
+do any 'constructing' work, this is done by a method called
+<code>construct</code>. We add a method called <code>create</code> to the <code>Object</code>
+prototype, which is used in place of the <code>new</code> keyword. It clones the
+object, and calls its <code>construct</code> method, if there is such a method,
+giving it the arguments that were passed to <code>create</code>.</p><pre class="code"><span class="variable">Object</span>.<span class="property">prototype</span>.<span class="property">create</span> = <span class="keyword">function</span>() {
+ <span class="keyword">var</span> <span class="variabledef">object</span> = <span class="variable">clone</span>(<span class="localvariable">this</span>);
+ <span class="keyword">if</span> (typeof <span class="localvariable">object</span>.<span class="property">construct</span> == <span class="string">"function"</span>)
+ <span class="localvariable">object</span>.<span class="property">construct</span>.<span class="property">apply</span>(<span class="localvariable">object</span>, <span class="localvariable">arguments</span>);
+ <span class="keyword">return</span> <span class="localvariable">object</span>;
+};</pre><p><a class="paragraph" href="#p37e6ddc63c91c187" name="p37e6ddc63c91c187"> </a>Inheritance can be done by cloning a prototype object and adding or
+replacing some of its properties. We also provide a convenient
+shorthand for this, an <code>extend</code> method, which clones the object it is
+applied to and adds to this clone the properties in the object that it
+is given as an argument.</p><pre class="code"><span class="variable">Object</span>.<span class="property">prototype</span>.<span class="property">extend</span> = <span class="keyword">function</span>(<span class="variabledef">properties</span>) {
+ <span class="keyword">var</span> <span class="variabledef">result</span> = <span class="variable">clone</span>(<span class="localvariable">this</span>);
+ <span class="variable">forEachIn</span>(<span class="localvariable">properties</span>, <span class="keyword">function</span>(<span class="variabledef">name</span>, <span class="variabledef">value</span>) {
+ <span class="localvariable">result</span>[<span class="localvariable">name</span>] = <span class="localvariable">value</span>;
+ });
+ <span class="keyword">return</span> <span class="localvariable">result</span>;
+};</pre><p><a class="paragraph" href="#p74d7be1ca42471c" name="p74d7be1ca42471c"> </a>In a case where it is not safe to mess with the <code>Object</code> prototype,
+these can of course be implemented as regular (non-method) functions.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p4b11691c21a7a212" name="p4b11691c21a7a212"> </a>An example. If you are old enough, you may at one time have played a
+'text adventure' game, where you move through a virtual world by
+typing commands, and get textual descriptions of the things around you
+and the actions you perform. Now those were games!</p><p><a class="paragraph" href="#p78217bb27e83fcae" name="p78217bb27e83fcae"> </a>We could write the prototype for an item in such a game like this.</p><pre class="code"><span class="keyword">var</span> <span class="variable">Item</span> = {
+ <span class="property">construct</span>: <span class="keyword">function</span>(<span class="variabledef">name</span>) {
+ <span class="localvariable">this</span>.<span class="property">name</span> = <span class="localvariable">name</span>;
+ },
+ <span class="property">inspect</span>: <span class="keyword">function</span>() {
+ <span class="variable">print</span>(<span class="string">"it is "</span>, <span class="localvariable">this</span>.<span class="property">name</span>, <span class="string">"."</span>);
+ },
+ <span class="property">kick</span>: <span class="keyword">function</span>() {
+ <span class="variable">print</span>(<span class="string">"klunk!"</span>);
+ },
+ <span class="property">take</span>: <span class="keyword">function</span>() {
+ <span class="variable">print</span>(<span class="string">"you can not lift "</span>, <span class="localvariable">this</span>.<span class="property">name</span>, <span class="string">"."</span>);
+ }
+};
+
+<span class="keyword">var</span> <span class="variable">lantern</span> = <span class="variable">Item</span>.<span class="property">create</span>(<span class="string">"the brass lantern"</span>);
+<span class="variable">lantern</span>.<span class="property">kick</span>();</pre><p><a class="paragraph" href="#pdef19b06a873573" name="pdef19b06a873573"> </a>Inherit from it like this...</p><pre class="code"><span class="keyword">var</span> <span class="variable">DetailedItem</span> = <span class="variable">Item</span>.<span class="property">extend</span>({
+ <span class="property">construct</span>: <span class="keyword">function</span>(<span class="variabledef">name</span>, <span class="variabledef">details</span>) {
+ <span class="variable">Item</span>.<span class="property">construct</span>.<span class="property">call</span>(<span class="localvariable">this</span>, <span class="localvariable">name</span>);
+ <span class="localvariable">this</span>.<span class="property">details</span> = <span class="localvariable">details</span>;
+ },
+ <span class="property">inspect</span>: <span class="keyword">function</span>() {
+ <span class="variable">print</span>(<span class="string">"you see "</span>, <span class="localvariable">this</span>.<span class="property">name</span>, <span class="string">", "</span>, <span class="localvariable">this</span>.<span class="property">details</span>, <span class="string">"."</span>);
+ }
+});
+
+<span class="keyword">var</span> <span class="variable">giantSloth</span> = <span class="variable">DetailedItem</span>.<span class="property">create</span>(
+ <span class="string">"the giant sloth"</span>,
+ <span class="string">"it is quietly hanging from a tree, munching leaves"</span>);
+<span class="variable">giantSloth</span>.<span class="property">inspect</span>();</pre><p><a class="paragraph" href="#p3a393a9c25c0d4b4" name="p3a393a9c25c0d4b4"> </a>Leaving out the compulsory <code>prototype</code> part makes things like calling
+<code>Item.construct</code> from <code>DetailedItem</code>'s constructor slightly simpler.
+Note that it would be a bad idea to just do <code>this.name = name</code> in
+<code>DetailedItem.construct</code>. This duplicates a line. Sure, duplicating
+the line is shorter than calling the <code>Item.construct</code> function, but if
+we end up adding something to this constructor later, we have to add
+it in two places.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p6f1156c2057a9871" name="p6f1156c2057a9871"> </a>Most of the time, a sub-type's constructor should start by calling the
+constructor of the super-type. This way, it starts with a valid object
+of the super-type, which it can then extend. In this new approach to
+prototypes, types that need no constructor can leave it out. They will
+automatically inherit the constructor of their super-type.</p><pre class="code"><span class="keyword">var</span> <span class="variable">SmallItem</span> = <span class="variable">Item</span>.<span class="property">extend</span>({
+ <span class="property">kick</span>: <span class="keyword">function</span>() {
+ <span class="variable">print</span>(<span class="localvariable">this</span>.<span class="property">name</span>, <span class="string">" flies across the room."</span>);
+ },
+ <span class="property">take</span>: <span class="keyword">function</span>() {
+ <span class="comment">// (imagine some code that moves the item to your pocket here)</span>
+ <span class="variable">print</span>(<span class="string">"you take "</span>, <span class="localvariable">this</span>.<span class="property">name</span>, <span class="string">"."</span>);
+ }
+});
+
+<span class="keyword">var</span> <span class="variable">pencil</span> = <span class="variable">SmallItem</span>.<span class="property">create</span>(<span class="string">"the red pencil"</span>);
+<span class="variable">pencil</span>.<span class="property">take</span>();</pre><p><a class="paragraph" href="#p177ec83e58f32995" name="p177ec83e58f32995"> </a>Even though <code>SmallItem</code> does not define its own constructor, creating
+it with a <code>name</code> argument works, because it inherited the constructor
+from the <code>Item</code> prototype.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p184c126e4d8eb12d" name="p184c126e4d8eb12d"> </a>JavaScript has an operator called <a name="key32"></a><code>instanceof</code>, which can be used to
+determine whether an object is based on a certain prototype. You give
+it the object on the left hand side, and a constructor on the right
+hand side, and it returns a boolean, <code>true</code> if the constructor's
+<code>prototype</code> property is the direct or indirect prototype of the
+object, and <code>false</code> otherwise.</p><p><a class="paragraph" href="#pbaadbbd2abbbf87" name="pbaadbbd2abbbf87"> </a>When you are not using regular constructors, using this operator
+becomes rather clumsy ― it expects a constructor function as its
+second argument, but we only have prototypes. A trick similar to the
+<code>clone</code> function can be used to get around it: We use a 'fake
+constructor', and apply <code>instanceof</code> to it.</p><pre class="code"><span class="variable">Object</span>.<span class="property">prototype</span>.<span class="property">hasPrototype</span> = <span class="keyword">function</span>(<span class="variabledef">prototype</span>) {
+ <span class="keyword">function</span> <span class="variabledef">DummyConstructor</span>() {}
+ <span class="localvariable">DummyConstructor</span>.<span class="property">prototype</span> = <span class="localvariable">prototype</span>;
+ <span class="keyword">return</span> <span class="localvariable">this</span> instanceof <span class="localvariable">DummyConstructor</span>;
+};
+
+<span class="variable">show</span>(<span class="variable">pencil</span>.<span class="property">hasPrototype</span>(<span class="variable">Item</span>));
+<span class="variable">show</span>(<span class="variable">pencil</span>.<span class="property">hasPrototype</span>(<span class="variable">DetailedItem</span>));</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p1d25ab62feead1a3" name="p1d25ab62feead1a3"> </a>Next, we want to make a small item that has a detailed description. It
+seems like this item would have to inherit both from <code>DetailedItem</code>
+and <code>SmallItem</code>. JavaScript does not allow an object to have multiple
+prototypes, and even if it did, the problem would not be quite that
+easy to solve. For example, if <code>SmallItem</code> would, for some reason,
+also define an <code>inspect</code> method, which <code>inspect</code> method should the new
+prototype use?</p><p><a class="paragraph" href="#p48915eba7a651e30" name="p48915eba7a651e30"> </a>Deriving an object type from more than one parent type is called
+<a name="key33"></a>multiple inheritance. Some languages chicken out and forbid it
+altogether, others define complicated schemes for making it work in a
+well-defined and practical way. It is possible to implement a decent
+multiple-inheritance framework in JavaScript. In fact there are, as
+usual, multiple good approaches to this. But they all are too complex
+to be discussed here. Instead, I will show a very simple approach
+which suffices in most cases.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p16400015b22a7338" name="p16400015b22a7338"> </a>A <a name="key34"></a>mix-in is a specific kind of prototype which can be 'mixed into'
+other prototypes. <code>SmallItem</code> can be seen as such a prototype. By
+copying its <code>kick</code> and <code>take</code> methods into another prototype, we mix
+smallness into this prototype.</p><pre class="code"><span class="keyword">function</span> <span class="variable">mixInto</span>(<span class="variabledef">object</span>, <span class="variabledef">mixIn</span>) {
+ <span class="variable">forEachIn</span>(<span class="localvariable">mixIn</span>, <span class="keyword">function</span>(<span class="variabledef">name</span>, <span class="variabledef">value</span>) {
+ <span class="localvariable">object</span>[<span class="localvariable">name</span>] = <span class="localvariable">value</span>;
+ });
+};
+
+<span class="keyword">var</span> <span class="variable">SmallDetailedItem</span> = <span class="variable">clone</span>(<span class="variable">DetailedItem</span>);
+<span class="variable">mixInto</span>(<span class="variable">SmallDetailedItem</span>, <span class="variable">SmallItem</span>);
+
+<span class="keyword">var</span> <span class="variable">deadMouse</span> = <span class="variable">SmallDetailedItem</span>.<span class="property">create</span>(
+ <span class="string">"Fred the mouse"</span>,
+ <span class="string">"he is dead"</span>);
+<span class="variable">deadMouse</span>.<span class="property">inspect</span>();
+<span class="variable">deadMouse</span>.<span class="property">kick</span>();</pre><p><a class="paragraph" href="#p21dd81048149cd05" name="p21dd81048149cd05"> </a>Remember that <code>forEachIn</code> only goes over the object's <em>own</em>
+properties, so it will copy <code>kick</code> and <code>take</code>, but not the constructor
+that <code>SmallItem</code> inherited from <code>Item</code>.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p75d5ae0a2088df83" name="p75d5ae0a2088df83"> </a>Mixing prototypes gets more complex when the mix-in has a constructor,
+or when some of its methods 'clash' with methods in the prototype that
+it is mixed into. Sometimes, it is workable to do a 'manual mix-in'.
+Say we have a prototype <code>Monster</code>, which has its own constructor, and
+we want to mix that with <code>DetailedItem</code>.</p><pre class="code"><span class="keyword">var</span> <span class="variable">Monster</span> = <span class="variable">Item</span>.<span class="property">extend</span>({
+ <span class="property">construct</span>: <span class="keyword">function</span>(<span class="variabledef">name</span>, <span class="variabledef">dangerous</span>) {
+ <span class="variable">Item</span>.<span class="property">construct</span>.<span class="property">call</span>(<span class="localvariable">this</span>, <span class="localvariable">name</span>);
+ <span class="localvariable">this</span>.<span class="property">dangerous</span> = <span class="localvariable">dangerous</span>;
+ },
+ <span class="property">kick</span>: <span class="keyword">function</span>() {
+ <span class="keyword">if</span> (<span class="localvariable">this</span>.<span class="property">dangerous</span>)
+ <span class="variable">print</span>(<span class="localvariable">this</span>.<span class="property">name</span>, <span class="string">" bites your head off."</span>);
+ <span class="keyword">else</span>
+ <span class="variable">print</span>(<span class="localvariable">this</span>.<span class="property">name</span>, <span class="string">" runs away, weeping."</span>);
+ }
+});
+
+<span class="keyword">var</span> <span class="variable">DetailedMonster</span> = <span class="variable">DetailedItem</span>.<span class="property">extend</span>({
+ <span class="property">construct</span>: <span class="keyword">function</span>(<span class="variabledef">name</span>, <span class="variabledef">description</span>, <span class="variabledef">dangerous</span>) {
+ <span class="variable">DetailedItem</span>.<span class="property">construct</span>.<span class="property">call</span>(<span class="localvariable">this</span>, <span class="localvariable">name</span>, <span class="localvariable">description</span>);
+ <span class="variable">Monster</span>.<span class="property">construct</span>.<span class="property">call</span>(<span class="localvariable">this</span>, <span class="localvariable">name</span>, <span class="localvariable">dangerous</span>);
+ },
+ <span class="property">kick</span>: <span class="variable">Monster</span>.<span class="property">kick</span>
+});
+
+<span class="keyword">var</span> <span class="variable">giantSloth</span> = <span class="variable">DetailedMonster</span>.<span class="property">create</span>(
+ <span class="string">"the giant sloth"</span>,
+ <span class="string">"it is quietly hanging from a tree, munching leaves"</span>,
+ <span class="atom">true</span>);
+<span class="variable">giantSloth</span>.<span class="property">kick</span>();</pre><p><a class="paragraph" href="#p28df0d4d34a24925" name="p28df0d4d34a24925"> </a>But note that this causes <code>Item</code> constructor to be called twice when
+creating a <code>DetailedMonster</code> ― once through the <code>DetailedItem</code>
+constructor, and once through the <code>Monster</code> constructor. In this case
+there is not much harm done, but there are situations where this would
+cause a problem.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p5530c4df57764453" name="p5530c4df57764453"> </a>But don't let those complications discourage you from making use of
+inheritance. Multiple inheritance, though extremely useful in some
+situations, can be safely ignored most of the time. This is why
+languages like Java get away with forbidding multiple inheritance. And
+if, at some point, you find that you really need it, you can search
+the web, do some research, and figure out an approach that works for
+your situation.</p><p><a class="paragraph" href="#p759d3a7b43780a89" name="p759d3a7b43780a89"> </a>Now that I think about it, JavaScript would probably be a great
+environment for building a text adventure. The ability to change the
+behaviour of objects at will, which is what prototypical inheritance
+gives us, is very well suited for this. If you have an object
+<code>hedgehog</code>, which has the unique habit of rolling up when it is
+kicked, you can just change its <code>kick</code> method.</p><p><a class="paragraph" href="#p11b363307c0a7f67" name="p11b363307c0a7f67"> </a>Unfortunately, the text adventure went the way of the vinyl record
+and, while once very popular, is nowadays only played by a small
+population of <a href="http://groups.google.com/group/rec.arts.int-fiction/topics">enthusiasts</a>.</p></div><ol class="footnotes"><li><a name="footnote1"></a>Such types are usually called 'classes' in other programming
+languages.</li><li><a name="footnote2"></a>To keep things reasonably simple, the creatures in our terrarium
+reproduce asexually, all by themselves.</li><li><a name="footnote3"></a>Laziness, for a programmer, is not necessarily a sin. The kind of
+people who will industriously do the same thing over and over again
+tend to make great assembly-line workers and lousy programmers.</li></ol><h1><span class="number">Chapter 9: </span>Modularity</h1><div class="block"><p><a class="paragraph" href="#p462e143585b2bd04" name="p462e143585b2bd04"> </a>This chapter deals with the process of organising programs. In small
+programs, organisation rarely becomes a problem. As a program grows,
+however, it can reach a size where its structure and interpretation
+become hard to keep track of. Easily enough, such a program starts to
+look like a bowl of spaghetti, an amorphous mass in which everything
+seems to be connected to everything else.</p><p><a class="paragraph" href="#p6dbca427e076a788" name="p6dbca427e076a788"> </a>When structuring a program, we do two things. We separate it into
+smaller parts, called <a name="key1"></a>modules, each of which has a specific role,
+and we specify the relations between these parts.</p><p><a class="paragraph" href="#p3895697c7cef4aaf" name="p3895697c7cef4aaf"> </a>In <a href="chapter8.html">chapter 8</a>, while developing a terrarium, we made use of a number of
+functions described in <a href="chapter6.html">chapter 6</a>. The chapter also defined a few new
+concepts that had nothing in particular to do with terraria, such as
+<code>clone</code> and the <code>Dictionary</code> type. All these things were haphazardly
+added to the environment. One way to split this program into modules
+would be:</p><ul><li>A module <code>FunctionalTools</code>, which contains the functions from <a href="chapter6.html">chapter 6</a>, and depends on nothing.</li><li>Then <code>ObjectTools</code>, which contains things like <code>clone</code> and <code>create</code>, and depends on <code>FunctionalTools</code>.</li><li><code>Dictionary</code>, containing the dictionary type, and depending on <code>FunctionalTools</code>.</li><li>And finally the <code>Terrarium</code> module, which depends on <code>ObjectTools</code> and <code>Dictionary</code>.</li></ul><p><a class="paragraph" href="#p2e1b410733dba78" name="p2e1b410733dba78"> </a>When a module <a name="key2"></a>depends on another module, it uses functions or
+variables from that module, and will only work when this module is
+loaded.</p><p><a class="paragraph" href="#p3903f3609e775868" name="p3903f3609e775868"> </a>It is a good idea to make sure dependencies never form a circle. Not
+only do circular dependencies create a practical problem (if module
+<code>A</code> and <code>B</code> depend on each other, which one should be loaded first?),
+it also makes the relation between the modules less straightforward,
+and can result in a modularised version of the spaghetti I mentioned
+earlier.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p5ada2c7b5f4cd057" name="p5ada2c7b5f4cd057"> </a>Most modern programming languages have some kind of module system
+built in. Not JavaScript. Once again, we have to invent something
+ourselves. The most obvious way to start is to put every module in a
+different file. This makes it clear which code belongs to which
+module.</p><p><a class="paragraph" href="#p278741f16f40e062" name="p278741f16f40e062"> </a><a name="key3"></a>Browsers load JavaScript files when they find a <code><script></code>
+tag with an <code>src</code> attribute in the HTML of the web-page. The extension
+<code>.js</code> is usually used for files containing JavaScript code. On the
+console, a shortcut for loading files is provided by the <code>load</code>
+function.</p><pre class="code"><span class="variable">load</span>(<span class="string">"FunctionalTools.js"</span>);</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p3612a370b3fd2685" name="p3612a370b3fd2685"> </a>In some cases, giving load commands in the wrong order will result in
+errors. If a module tries to create a <code>Dictionary</code> object, but the
+<code>Dictionary</code> module has not been loaded yet, it will be unable to find
+the constructor, and will fail.</p><p><a class="paragraph" href="#pda0515a72640aa2" name="pda0515a72640aa2"> </a>One would imagine this to be easy to solve. Just put some calls to
+<code>load</code> at the top of the file for a module, to load all the modules it
+depends on. Unfortunately, because of the way browsers work, calling
+<code>load</code> does not immediately cause the given file to be loaded. The
+file will be loaded <em>after</em> the current file has finished executing.
+Which is too late, usually.</p><p><a class="paragraph" href="#p60c820cc1f0bb29a" name="p60c820cc1f0bb29a"> </a>In most cases, the practical solution is to just manage dependencies
+by hand: Put the <code>script</code> tags in your HTML documents in the right
+order.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p7ae6777e79353629" name="p7ae6777e79353629"> </a>There are two ways to (partially) automate dependency management. The
+first is to keep a separate file with information about the
+dependencies between modules. This can be loaded first, and used to
+determine the order in which to load the files. The second way is to
+not use a <code>script</code> tag (<code>load</code> internally creates and adds such a
+tag), but to fetch the content of the file directly (see <a href="chapter14.html">chapter 14</a>), and
+then use the <code>eval</code> function to execute it. This makes script loading
+instantaneous, and thus easier to deal with.</p><p><a class="paragraph" href="#p64d1d3a066b53092" name="p64d1d3a066b53092"> </a><a name="key4"></a><code>eval</code>, short for 'evaluate', is an interesting function. You give
+it a string value, and it will execute the content of the string as
+JavaScript code.</p><pre class="code"><span class="variable">eval</span>(<span class="string">"print(\"I am a string inside a string!\");"</span>);</pre><p><a class="paragraph" href="#p2f7c4d375c787d44" name="p2f7c4d375c787d44"> </a>You can imagine that <code>eval</code> can be used to do some interesting things.
+Code can build new code, and run it. In most cases, however, problems
+that can be solved with creative uses of <code>eval</code> can also be solved
+with creative uses of anonymous functions, and the latter is less
+likely to cause strange problems.</p><p><a class="paragraph" href="#p3c7c1279aa2c552a" name="p3c7c1279aa2c552a"> </a>When <code>eval</code> is called inside a function, all new variables will become
+local to that function. Thus, when a variation of the <code>load</code> would use
+<code>eval</code> internally, loading the <code>Dictionary</code> module would create a
+<code>Dictionary</code> constructor inside of the <code>load</code> function, which would be
+lost as soon as the function returned. There are ways to work around
+this, but they are rather clumsy.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p1760fa0cdd48ac47" name="p1760fa0cdd48ac47"> </a>Let us quickly go over the first variant of dependency management. It
+requires a special file for dependency information, which could look
+something like this:</p><pre class="code"><span class="keyword">var</span> <span class="variable">dependencies</span> =
+ {<span class="string">"ObjectTools.js"</span>: [<span class="string">"FunctionalTools.js"</span>],
+ <span class="string">"Dictionary.js"</span>: [<span class="string">"ObjectTools.js"</span>],
+ <span class="string">"TestModule.js"</span>: [<span class="string">"FunctionalTools.js"</span>, <span class="string">"Dictionary.js"</span>]};</pre><p><a class="paragraph" href="#p36868c584900b459" name="p36868c584900b459"> </a>The <code>dependencies</code> object contains a property for each file that
+depends on other files. The values of the properties are arrays of
+file names. Note that we could not use a <code>Dictionary</code> object here,
+because we can not be sure that the <code>Dictionary</code> module has been
+loaded yet. Because all the properties in this object will end in
+<code>".js"</code>, they are unlikely to interfere with hidden properties like
+<code>__proto__</code> or <code>hasOwnProperty</code>, and a regular object will work fine.</p><p><a class="paragraph" href="#p67921e1675ae1581" name="p67921e1675ae1581"> </a>The dependency manager must do two things. Firstly it must make sure
+that files are loaded in the correct order, by loading a file's
+dependencies before the file itself. And secondly, it must make sure
+that no file is loaded twice. Loading the same file twice might cause
+problems, and is definitely a waste of time.</p><pre class="code"><span class="keyword">var</span> <span class="variable">loadedFiles</span> = {};
+
+<span class="keyword">function</span> <span class="variable">require</span>(<span class="variabledef">file</span>) {
+ <span class="keyword">if</span> (<span class="variable">dependencies</span>[<span class="localvariable">file</span>]) {
+ <span class="keyword">var</span> <span class="variabledef">files</span> = <span class="variable">dependencies</span>[<span class="localvariable">file</span>];
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variabledef">i</span> = <span class="atom">0</span>; <span class="localvariable">i</span> < <span class="localvariable">files</span>.<span class="property">length</span>; <span class="localvariable">i</span>++)
+ <span class="variable">require</span>(<span class="localvariable">files</span>[<span class="localvariable">i</span>]);
+ }
+ <span class="keyword">if</span> (!<span class="variable">loadedFiles</span>[<span class="localvariable">file</span>]) {
+ <span class="variable">loadedFiles</span>[<span class="localvariable">file</span>] = <span class="atom">true</span>;
+ <span class="variable">load</span>(<span class="localvariable">file</span>);
+ }
+}</pre><p><a class="paragraph" href="#p4b0482a846ce5463" name="p4b0482a846ce5463"> </a>The <a name="key5"></a><code>require</code> function can now be used to load a file and all its
+dependencies. Note how it recursively calls itself to take care of
+dependencies (and possible dependencies of that dependency).</p><pre class="code"><span class="variable">require</span>(<span class="string">"TestModule.js"</span>);</pre><pre class="code"><span class="variable">test</span>();</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p5f8fdc39c48e9f72" name="p5f8fdc39c48e9f72"> </a>Building a program as a set of nice, small modules often means the
+program will use a lot of different files. When programming for the
+web, having lots of small JavaScript files on a page tends to make the
+page slower to load. This does not have to be a problem though. You
+can write and test your program as a number of small files, and put
+them all into a single big file when 'publishing' the program to the
+web.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p511fd1a470b62a91" name="p511fd1a470b62a91"> </a>Just like an object type, a module has an interface. In simple
+collection-of-functions modules such as <code>FunctionalTools</code>, the
+interface usually consists of all the functions that are defined in
+the module. In other cases, the interface of the module is only a
+small part of the functions defined inside it. For example, our
+manuscript-to-HTML system from <a href="chapter6.html">chapter 6</a> only needs an interface of a
+single function, <code>renderFile</code>. (The sub-system for building HTML would
+be a separate module.)</p><p><a class="paragraph" href="#p263f60798e0d5774" name="p263f60798e0d5774"> </a>For modules which only define a single type of object, such as
+<code>Dictionary</code>, the object's interface is the same as the module's
+interface.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p3c747e5c1f737d59" name="p3c747e5c1f737d59"> </a>In JavaScript, 'top-level' variables all live together in a single
+place. In browsers, this place is an object that can be found under
+the name <code>window</code>. The name is somewhat odd, <code>environment</code> or <code>top</code>
+would have made more sense, but since browsers associate a JavaScript
+environment with a window (or 'frame'), someone decided that <code>window</code>
+was a logical name.</p><pre class="code"><span class="variable">show</span>(<span class="variable">window</span>);
+<span class="variable">show</span>(<span class="variable">window</span>.<span class="property">print</span> == <span class="variable">print</span>);
+<span class="variable">show</span>(<span class="variable">window</span>.<span class="property">window</span>.<span class="property">window</span>.<span class="property">window</span>.<span class="property">window</span>);</pre><p><a class="paragraph" href="#p352ca08c4808e061" name="p352ca08c4808e061"> </a>As the third line shows, the name <code>window</code> is merely a property of
+this environment object, pointing at itself.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p418c55cafaf82578" name="p418c55cafaf82578"> </a>When much code is loaded into an environment, it will use many
+top-level variable names. Once there is more code than you can really
+keep track of, it becomes very easy to accidentally use a name that
+was already used for something else. This will break the code that
+used the original value. The proliferation of top-level variables is
+called <a name="key6"></a>name-space pollution, and it can be a rather severe problem
+in JavaScript ― the language will not warn you when you redefine an
+existing variable.</p><p><a class="paragraph" href="#p3aca3d89a64057bd" name="p3aca3d89a64057bd"> </a>There is no way to get rid of this problem entirely, but it can be
+greatly reduced by taking care to cause as little pollution as
+possible. For one thing, modules should not use top-level variables
+for values that are not part of their external interface.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p1829408f56380633" name="p1829408f56380633"> </a>Not being able to define any internal functions and variables at all
+in your modules is, of course, not very practical. Fortunately, there
+is a trick to get around this. We write all the code for the module
+inside a function, and then finally add the variables that are part of
+the module's interface to the <code>window</code> object. Because they were
+created in the same parent function, all the functions of the module
+can see each other, but code outside of the module can not.</p><pre class="code"><span class="keyword">function</span> <span class="variable">buildMonthNameModule</span>() {
+ <span class="keyword">var</span> <span class="variabledef">names</span> = [<span class="string">"January"</span>, <span class="string">"February"</span>, <span class="string">"March"</span>, <span class="string">"April"</span>,
+ <span class="string">"May"</span>, <span class="string">"June"</span>, <span class="string">"July"</span>, <span class="string">"August"</span>, <span class="string">"September"</span>,
+ <span class="string">"October"</span>, <span class="string">"November"</span>, <span class="string">"December"</span>];
+ <span class="keyword">function</span> <span class="variabledef">getMonthName</span>(<span class="variabledef">number</span>) {
+ <span class="keyword">return</span> <span class="localvariable">names</span>[<span class="localvariable">number</span>];
+ }
+ <span class="keyword">function</span> <span class="variabledef">getMonthNumber</span>(<span class="variabledef">name</span>) {
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variabledef">number</span> = <span class="atom">0</span>; <span class="localvariable">number</span> < <span class="localvariable">names</span>.<span class="property">length</span>; <span class="localvariable">number</span>++) {
+ <span class="keyword">if</span> (<span class="localvariable">names</span>[<span class="localvariable">number</span>] == <span class="localvariable">name</span>)
+ <span class="keyword">return</span> <span class="localvariable">number</span>;
+ }
+ }
+
+ <span class="variable">window</span>.<span class="property">getMonthName</span> = <span class="localvariable">getMonthName</span>;
+ <span class="variable">window</span>.<span class="property">getMonthNumber</span> = <span class="localvariable">getMonthNumber</span>;
+}
+<span class="variable">buildMonthNameModule</span>();
+
+<span class="variable">show</span>(<span class="variable">getMonthName</span>(<span class="atom">11</span>));</pre><p><a class="paragraph" href="#p6abed197dfcfd02e" name="p6abed197dfcfd02e"> </a>This builds a very simple module for translating between month names
+and their number (as used by <code>Date</code>, where January is <code>0</code>). But note
+that <code>buildMonthNameModule</code> is still a top-level variable that is not
+part of the module's interface. Also, we have to repeat the names of
+the interface functions three times. Ugh.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p3d1691c937faa6f7" name="p3d1691c937faa6f7"> </a>The first problem can be solved by making the module function
+anonymous, and calling it directly. To do this, we have to add a pair
+of parentheses around the function value, or JavaScript will think it
+is a normal function definition, which can not be called directly.</p><p><a class="paragraph" href="#p7057309ec1009bce" name="p7057309ec1009bce"> </a>The second problem can be solved with a helper function, <code>provide</code>,
+which can be given an object containing the values that must be
+exported into the <code>window</code> object.</p><pre class="code"><span class="keyword">function</span> <span class="variable">provide</span>(<span class="variabledef">values</span>) {
+ <span class="variable">forEachIn</span>(<span class="localvariable">values</span>, <span class="keyword">function</span>(<span class="variabledef">name</span>, <span class="variabledef">value</span>) {
+ <span class="variable">window</span>[<span class="localvariable">name</span>] = <span class="localvariable">value</span>;
+ });
+}</pre><p><a class="paragraph" href="#pd61147f170d5ca3" name="pd61147f170d5ca3"> </a>Using this, we can write a module like this:</p><pre class="code">(<span class="keyword">function</span>() {
+ <span class="keyword">var</span> <span class="variabledef">names</span> = [<span class="string">"Sunday"</span>, <span class="string">"Monday"</span>, <span class="string">"Tuesday"</span>, <span class="string">"Wednesday"</span>,
+ <span class="string">"Thursday"</span>, <span class="string">"Friday"</span>, <span class="string">"Saturday"</span>];
+ <span class="variable">provide</span>({
+ <span class="property">getDayName</span>: <span class="keyword">function</span>(<span class="variabledef">number</span>) {
+ <span class="keyword">return</span> <span class="localvariable">names</span>[<span class="localvariable">number</span>];
+ },
+ <span class="property">getDayNumber</span>: <span class="keyword">function</span>(<span class="variabledef">name</span>) {
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variabledef">number</span> = <span class="atom">0</span>; <span class="localvariable">number</span> < <span class="localvariable">names</span>.<span class="property">length</span>; <span class="localvariable">number</span>++) {
+ <span class="keyword">if</span> (<span class="localvariable">names</span>[<span class="localvariable">number</span>] == <span class="localvariable">name</span>)
+ <span class="keyword">return</span> <span class="localvariable">number</span>;
+ }
+ }
+ });
+})();
+
+<span class="variable">show</span>(<span class="variable">getDayNumber</span>(<span class="string">"Wednesday"</span>));</pre><p><a class="paragraph" href="#p3d8d0684a25dbc3a" name="p3d8d0684a25dbc3a"> </a>I do not recommend writing modules like this right from the start.
+While you are still working on a piece of code, it is easier to just
+use the simple approach we have used so far, and put everything at top
+level. That way, you can inspect the module's internal values in your
+browser, and test them out. Once a module is more or less finished, it
+is not difficult to wrap it in a function.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p727ed06b4989266d" name="p727ed06b4989266d"> </a>There are cases where a module will export so many variables that it
+is a bad idea to put them all into the top-level environment. In cases
+like this, you can do what the standard <code>Math</code> object does, and
+represent the module as a single object whose properties are the
+functions and values it exports. For example...</p><pre class="code"><span class="keyword">var</span> <span class="variable">HTML</span> = {
+ <span class="property">tag</span>: <span class="keyword">function</span>(<span class="variabledef">name</span>, <span class="variabledef">content</span>, <span class="variabledef">properties</span>) {
+ <span class="keyword">return</span> {<span class="property">name</span>: <span class="localvariable">name</span>, <span class="property">properties</span>: <span class="localvariable">properties</span>, <span class="property">content</span>: <span class="localvariable">content</span>};
+ },
+ <span class="property">link</span>: <span class="keyword">function</span>(<span class="variabledef">target</span>, <span class="variabledef">text</span>) {
+ <span class="keyword">return</span> <span class="variable">HTML</span>.<span class="property">tag</span>(<span class="string">"a"</span>, [<span class="localvariable">text</span>], {<span class="property">href</span>: <span class="localvariable">target</span>});
+ }
+ <span class="comment">/* ... many more HTML-producing functions ... */</span>
+};</pre><p><a class="paragraph" href="#p17970bf58fef9476" name="p17970bf58fef9476"> </a>When you need the content of such a module so often that it becomes
+cumbersome to constantly type <code>HTML</code>, you can always move it into the
+top-level environment using <code>provide</code>.</p><pre class="code"><span class="variable">provide</span>(<span class="variable">HTML</span>);
+<span class="variable">show</span>(<span class="variable">link</span>(<span class="string">"http://download.oracle.com/docs/cd/E19957-01/816-6408-10/object.htm"</span>,
+ <span class="string">"This is how objects work."</span>));</pre><p><a class="paragraph" href="#p631548b0275f6ddb" name="p631548b0275f6ddb"> </a>You can even combine the function and object approaches, by putting
+the internal variables of the module inside a function, and having
+this function return an object containing its external interface.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p7cca580a8acbd620" name="p7cca580a8acbd620"> </a>When adding methods to standard prototypes, such as those of <code>Array</code>
+and <code>Object</code> a similar problem to name-space pollution occurs. If two
+modules decide to add a <code>map</code> method to <code>Array.prototype</code>, you might
+have a problem. If these two versions of <code>map</code> have the precise same
+effect, things will continue to work, but only by sheer luck.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p19934344570563ca" name="p19934344570563ca"> </a>Designing an interface for a module or an object type is one of the
+subtler aspects of programming. On the one hand, you do not want to
+expose too many details. They will only get in the way when using the
+module. On the other hand, you do not want to be <em>too</em> simple and
+general, because that might make it impossible to use the module in
+complex or specialised situations.</p><p><a class="paragraph" href="#p1559f2055beb9a4" name="p1559f2055beb9a4"> </a>Sometimes the solution is to provide two interfaces, a detailed
+'low-level' one for complicated things, and a simple 'high-level' one
+for straightforward situations. The second one can usually be built
+very easily using the tools provided by the first one.</p><p><a class="paragraph" href="#p3e0782b573cdc399" name="p3e0782b573cdc399"> </a>In other cases, you just have to find the right idea around which to
+base your interface. Compare this to the various approaches to
+inheritance we saw in <a href="chapter8.html">chapter 8</a>. By making prototypes the central concept,
+rather than constructors, we managed to make some things considerably
+more straightforward.</p><p><a class="paragraph" href="#p1330ba7fba73a6b2" name="p1330ba7fba73a6b2"> </a>The best way to learn the value of good interface design is,
+unfortunately, to use bad interfaces. Once you get fed up with them,
+you'll figure out a way to improve them, and learn a lot in the
+process. Try not to assume that a lousy interface is 'just the way it
+is'. Fix it, or wrap it in a new interface that is better (we will see
+an example of this in <a href="chapter12.html">chapter 12</a>).</p></div><hr/><div class="block"><p><a class="paragraph" href="#p2855dfc6cedc9e10" name="p2855dfc6cedc9e10"> </a>There are functions which require a lot of arguments. Sometimes this
+means they are just badly designed, and can easily be remedied by
+splitting them into a few more modest functions. But in other cases,
+there is no way around it. Typically, some of these arguments have a
+sensible 'default' value. We could, for example, write yet another
+extended version of <code>range</code>.</p><pre class="code"><span class="keyword">function</span> <span class="variable">range</span>(<span class="variabledef">start</span>, <span class="variabledef">end</span>, <span class="variabledef">stepSize</span>, <span class="variabledef">length</span>) {
+ <span class="keyword">if</span> (<span class="localvariable">stepSize</span> == <span class="atom">undefined</span>)
+ <span class="localvariable">stepSize</span> = <span class="atom">1</span>;
+ <span class="keyword">if</span> (<span class="localvariable">end</span> == <span class="atom">undefined</span>)
+ <span class="localvariable">end</span> = <span class="localvariable">start</span> + <span class="localvariable">stepSize</span> * (<span class="localvariable">length</span> - <span class="atom">1</span>);
+
+ <span class="keyword">var</span> <span class="variabledef">result</span> = [];
+ <span class="keyword">for</span> (; <span class="localvariable">start</span> <= <span class="localvariable">end</span>; <span class="localvariable">start</span> += <span class="localvariable">stepSize</span>)
+ <span class="localvariable">result</span>.<span class="property">push</span>(<span class="localvariable">start</span>);
+ <span class="keyword">return</span> <span class="localvariable">result</span>;
+}
+
+<span class="variable">show</span>(<span class="variable">range</span>(<span class="atom">0</span>, <span class="atom">undefined</span>, <span class="atom">4</span>, <span class="atom">5</span>));</pre><p><a class="paragraph" href="#p553dbd9c534b0740" name="p553dbd9c534b0740"> </a>It can get hard to remember which argument goes where, not to mention
+the annoyance of having to pass <code>undefined</code> as a second argument when
+a <code>length</code> argument is used. We can make passing arguments to this
+function more comprehensive by wrapping them in an object.</p><pre class="code"><span class="keyword">function</span> <span class="variable">defaultTo</span>(<span class="variabledef">object</span>, <span class="variabledef">values</span>) {
+ <span class="variable">forEachIn</span>(<span class="localvariable">values</span>, <span class="keyword">function</span>(<span class="variabledef">name</span>, <span class="variabledef">value</span>) {
+ <span class="keyword">if</span> (!<span class="localvariable">object</span>.<span class="property">hasOwnProperty</span>(<span class="localvariable">name</span>))
+ <span class="localvariable">object</span>[<span class="localvariable">name</span>] = <span class="localvariable">value</span>;
+ });
+}
+
+<span class="keyword">function</span> <span class="variable">range</span>(<span class="variabledef">args</span>) {
+ <span class="variable">defaultTo</span>(<span class="localvariable">args</span>, {<span class="property">start</span>: <span class="atom">0</span>, <span class="property">stepSize</span>: <span class="atom">1</span>});
+ <span class="keyword">if</span> (<span class="localvariable">args</span>.<span class="property">end</span> == <span class="atom">undefined</span>)
+ <span class="localvariable">args</span>.<span class="property">end</span> = <span class="localvariable">args</span>.<span class="property">start</span> + <span class="localvariable">args</span>.<span class="property">stepSize</span> * (<span class="localvariable">args</span>.<span class="property">length</span> - <span class="atom">1</span>);
+
+ <span class="keyword">var</span> <span class="variabledef">result</span> = [];
+ <span class="keyword">for</span> (; <span class="localvariable">args</span>.<span class="property">start</span> <= <span class="localvariable">args</span>.<span class="property">end</span>; <span class="localvariable">args</span>.<span class="property">start</span> += <span class="localvariable">args</span>.<span class="property">stepSize</span>)
+ <span class="localvariable">result</span>.<span class="property">push</span>(<span class="localvariable">args</span>.<span class="property">start</span>);
+ <span class="keyword">return</span> <span class="localvariable">result</span>;
+}
+
+<span class="variable">show</span>(<span class="variable">range</span>({<span class="property">stepSize</span>: <span class="atom">4</span>, <span class="property">length</span>: <span class="atom">5</span>}));</pre><p><a class="paragraph" href="#p209935cf6c50e97b" name="p209935cf6c50e97b"> </a>The <code>defaultTo</code> function is useful for adding default values to an
+object. It copies the properties of its second argument into its first
+argument, skipping those that already have a value.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p1a7878ac38fce032" name="p1a7878ac38fce032"> </a>A module or group of modules that can be useful in more than one
+program is usually called a <a name="key7"></a>library. For many programming languages,
+there is a huge set of quality libraries available. This means
+programmers do not have to start from scratch all the time, which can
+make them a lot more productive. For JavaScript, unfortunately, the
+amount of available libraries is not very large.</p><p><a class="paragraph" href="#p28730aa17f362171" name="p28730aa17f362171"> </a>But recently this seems to be improving. There are a number of good
+libraries with 'basic' tools, things like <code>map</code> and <code>clone</code>. Other
+languages tend to provide such obviously useful things as built-in
+standard features, but with JavaScript you'll have to either build a
+collection of them for yourself or use a library. Using a library is
+recommended: It is less work, and the code in a library has usually
+been tested more thoroughly than the things you wrote yourself.</p><p><a class="paragraph" href="#p40fe3f5a106dc4ec" name="p40fe3f5a106dc4ec"> </a>Covering these basics, there are (among others) the 'lightweight'
+libraries <a href="http://www.prototypejs.org/">prototype</a>, <a href="http://mootools.net">mootools</a>, <a href="http://jquery.com">jQuery</a>, and <a href="http://mochikit.com">MochiKit</a>. There are also some larger 'frameworks'
+available, which do a lot more than just provide a set of basic tools.
+<a href="http://developer.yahoo.com/yui/">YUI</a> (by Yahoo), and <a href="http://dojotoolkit.org/">Dojo</a> seem to be the most popular ones in that
+genre. All of these can be downloaded and used free of charge. My
+personal favourite is MochiKit, but this is mostly a matter of taste.
+When you get serious about JavaScript programming, it is a good idea
+to quickly glance through the documentation of each of these, to get a
+general idea about the way they work and the things they provide.</p><p><a class="paragraph" href="#p46d01329ecc618f" name="p46d01329ecc618f"> </a>The fact that a basic toolkit is almost indispensable for any
+non-trivial JavaScript programs, combined with the fact that there are
+so many different toolkits, causes a bit of a dilemma for library
+writers. You either have to make your library depend on one of the
+toolkits, or write the basic tools yourself and include them with the
+library. The first option makes the library hard to use for people who
+are using a different toolkit, and the second option adds a lot of
+non-essential code to the library. This dilemma might be one of the
+reasons why there are relatively few good, widely used JavaScript
+libraries. It is possible that, in the future, new versions of
+ECMAScript and changes in browsers will make toolkits less necessary,
+and thus (partially) solve this problem.</p></div><h1><span class="number">Chapter 10: </span>Regular Expressions</h1><div class="block"><p><a class="paragraph" href="#p64ff0b30104c964c" name="p64ff0b30104c964c"> </a>At various points in the previous chapters, we had to look for
+patterns in string values. In <a href="chapter4.html">chapter 4</a> we extracted date values from
+strings by writing out the precise positions at which the numbers that
+were part of the date could be found. Later, in <a href="chapter6.html">chapter 6</a>, we saw some
+particularly ugly pieces of code for finding certain types of
+characters in a string, for example the characters that had to be
+escaped in HTML output.</p><p><a class="paragraph" href="#p4907100ef57e381c" name="p4907100ef57e381c"> </a><a name="key1"></a>Regular expressions are a language for describing
+patterns in strings. They form a small, separate language, which is
+embedded inside JavaScript (and in various other programming
+languages, in one way or another). It is not a very readable language
+― big regular expressions tend to be completely unreadable. But, it
+is a useful tool, and can really simplify string-processing programs.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p213ad6cd9cbc5562" name="p213ad6cd9cbc5562"> </a>Just like strings get written between quotes, regular expression
+patterns get written between slashes (<a name="key2"></a><code>/</code>). This means that slashes
+inside the expression have to be escaped.</p><pre class="code"><span class="keyword">var</span> <span class="variable">slash</span> = <span class="string">/\//</span>;
+<span class="variable">show</span>(<span class="string">"AC/DC"</span>.<span class="property">search</span>(<span class="variable">slash</span>));</pre><p><a class="paragraph" href="#p1101481f3b05a5ca" name="p1101481f3b05a5ca"> </a>The <a name="key3"></a><code>search</code> method resembles <code>indexOf</code>, but it searches for a
+regular expression instead of a string. Patterns specified by regular
+expressions can do a few things that strings can not do. For a start,
+they allow some of their elements to match more than a single
+character. In <a href="chapter6.html">chapter 6</a>, when extracting mark-up from a document, we
+needed to find the first asterisk or opening brace in a string. That
+could be done like this:</p><pre class="code"><span class="keyword">var</span> <span class="variable">asteriskOrBrace</span> = <span class="string">/[\{\*]/</span>;
+<span class="keyword">var</span> <span class="variable">story</span> =
+ <span class="string">"We noticed the *giant sloth*, hanging from a giant branch."</span>;
+<span class="variable">show</span>(<span class="variable">story</span>.<span class="property">search</span>(<span class="variable">asteriskOrBrace</span>));</pre><p><a class="paragraph" href="#p5233b3c75c1b3d93" name="p5233b3c75c1b3d93"> </a>The <code>[</code> and <code>]</code> characters have a special meaning inside a regular
+expression. They can enclose a set of characters, and they mean 'any
+of these characters'. Most non-alphanumeric characters have some
+special meaning inside a regular expression, so it is a good idea to
+always escape them with a backslash<a class="footref" href="#footnote1">1</a> when you use them to refer to
+the actual characters.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p10dd6e1797cc70f4" name="p10dd6e1797cc70f4"> </a>There are a few shortcuts for sets of characters that are needed
+often. The dot (<code>.</code>) can be used to mean 'any character that is not a
+newline', an escaped 'd' (<code>\d</code>) means 'any digit', an escaped 'w'
+(<code>\w</code>) matches any alphanumeric character (including underscores, for
+some reason), and an escaped 's' (<code>\s</code>) matches any white-space (tab,
+newline, space) character.</p><pre class="code"><span class="keyword">var</span> <span class="variable">digitSurroundedBySpace</span> = <span class="string">/\s\d\s/</span>;
+<span class="variable">show</span>(<span class="string">"1a 2 3d"</span>.<span class="property">search</span>(<span class="variable">digitSurroundedBySpace</span>));</pre><p><a class="paragraph" href="#p6e04fda25e1e13c5" name="p6e04fda25e1e13c5"> </a>The escaped 'd', 'w', and 's' can be replaced by their capital letter
+to mean their opposite. For example, <code>\S</code> matches any character that
+is <em>not</em> white-space. When using <code>[</code> and <code>]</code>, a pattern can be
+inverted by starting with a <code>^</code> character:</p><pre class="code"><span class="keyword">var</span> <span class="variable">notABC</span> = <span class="string">/[^ABC]/</span>;
+<span class="variable">show</span>(<span class="string">"ABCBACCBBADABC"</span>.<span class="property">search</span>(<span class="variable">notABC</span>));</pre><p><a class="paragraph" href="#p2684c39c7b00c483" name="p2684c39c7b00c483"> </a>As you can see, the way regular expressions use characters to express
+patterns makes them A) very short, and B) very hard to read.</p></div><hr/><div class="block"><a name="exercise1"></a><div class="exercisenum">Ex. 10.1</div><div class="exercise"><p><a class="paragraph" href="#p7ff8b44542842a86" name="p7ff8b44542842a86"> </a>Write a regular expression that matches a date in the format
+<code>"XX/XX/XXXX"</code>, where the <code>X</code>s are digits. Test it against the string
+<code>"born 15/11/2003 (mother Spot): White Fang"</code>.</p></div><div class="solution"><pre class="code"><span class="keyword">var</span> <span class="variable">datePattern</span> = <span class="string">/\d\d\/\d\d\/\d\d\d\d/</span>;
+<span class="variable">show</span>(<span class="string">"born 15/11/2003 (mother Spot): White Fang"</span>.<span class="property">search</span>(<span class="variable">datePattern</span>));</pre></div></div><hr/><div class="block"><p><a class="paragraph" href="#p44f51a2cf46d4125" name="p44f51a2cf46d4125"> </a>Sometimes you need to make sure a pattern starts at the beginning of a
+string, or ends at its end. For this, the special characters <code>^</code> and
+<code>$</code> can be used. The first matches the start of the string, the second
+the end.</p><pre class="code"><span class="variable">show</span>(<span class="string">/a+/</span>.<span class="property">test</span>(<span class="string">"blah"</span>));
+<span class="variable">show</span>(<span class="string">/^a+$/</span>.<span class="property">test</span>(<span class="string">"blah"</span>));</pre><p><a class="paragraph" href="#p2699070e35a42354" name="p2699070e35a42354"> </a>The first regular expression matches any string that contains an <code>a</code>
+character, the second only those strings that consist entirely of <code>a</code>
+characters.</p><p><a class="paragraph" href="#p15e04302f56cd0d8" name="p15e04302f56cd0d8"> </a>Note that regular expressions are objects, and have methods. Their
+<a name="key4"></a><code>test</code> method returns a boolean indicating whether the given string
+matches the expression.</p><p><a class="paragraph" href="#p22062b94cbeb2c8f" name="p22062b94cbeb2c8f"> </a>The code <code>\b</code> matches a 'word boundary', which can be punctuation,
+white-space, or the start or end of the string.</p><pre class="code"><span class="variable">show</span>(<span class="string">/cat/</span>.<span class="property">test</span>(<span class="string">"concatenate"</span>));
+<span class="variable">show</span>(<span class="string">/\bcat\b/</span>.<span class="property">test</span>(<span class="string">"concatenate"</span>));</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p68f6323f6df2f848" name="p68f6323f6df2f848"> </a>Parts of a pattern can be allowed to be repeated a number of times.
+Putting an asterisk (<code>*</code>) after an element allows it to be repeated
+any number of times, including zero. A plus (<code>+</code>) does the same, but
+requires the pattern to occur at least one time. A question mark (<code>?</code>)
+makes an element 'optional' ― it can occur zero or one times.</p><pre class="code"><span class="keyword">var</span> <span class="variable">parenthesizedText</span> = <span class="string">/\(.*\)/</span>;
+<span class="variable">show</span>(<span class="string">"Its (the sloth's) claws were gigantic!"</span>.<span class="property">search</span>(<span class="variable">parenthesizedText</span>));</pre><p><a class="paragraph" href="#p12db0944e3d8f760" name="p12db0944e3d8f760"> </a>When necessary, braces can be used to be more precise about the amount
+of times an element may occur. A number between braces (<code>{4}</code>) gives
+the exact amount of times it must occur. Two numbers with a comma
+between them (<code>{3,10}</code>) indicate that the pattern must occur at least
+as often as the first number, and at most as often as the second one.
+Similarly, <code>{2,}</code> means two or more occurrences, while <code>{,4}</code> means
+four or less.</p><pre class="code"><span class="keyword">var</span> <span class="variable">datePattern</span> = <span class="string">/\d{1,2}\/\d\d?\/\d{4}/</span>;
+<span class="variable">show</span>(<span class="string">"born 15/11/2003 (mother Spot): White Fang"</span>.<span class="property">search</span>(<span class="variable">datePattern</span>));</pre><p><a class="paragraph" href="#p3892407e1b16f81" name="p3892407e1b16f81"> </a>The pieces <code>/\d{1,2}/</code> and <code>/\d\d?/</code> both express 'one or two digits'.</p></div><hr/><div class="block"><a name="exercise2"></a><div class="exercisenum">Ex. 10.2</div><div class="exercise"><p><a class="paragraph" href="#p61c72523f73c013f" name="p61c72523f73c013f"> </a>Write a pattern that matches e-mail addresses. For simplicity, assume
+that the parts before and after the <code>@</code> can contain only alphanumeric
+characters and the characters <code>.</code> and <code>-</code> (dot and dash), while the
+last part of the address, the country code after the last dot, may
+only contain alphanumeric characters, and must be two or three
+characters long.</p></div><div class="solution"><pre class="code"><span class="keyword">var</span> <span class="variable">mailAddress</span> = <span class="string">/\b[\w\.-]+@[\w\.-]+\.\w{2,3}\b/</span>;
+
+<span class="variable">show</span>(<span class="variable">mailAddress</span>.<span class="property">test</span>(<span class="string">"kenny@test.net"</span>));
+<span class="variable">show</span>(<span class="variable">mailAddress</span>.<span class="property">test</span>(<span class="string">"I mailt kenny@tets.nets, but it didn wrok!"</span>));
+<span class="variable">show</span>(<span class="variable">mailAddress</span>.<span class="property">test</span>(<span class="string">"the_giant_sloth@gmail.com"</span>));</pre><p><a class="paragraph" href="#p25a7a57651dc6d43" name="p25a7a57651dc6d43"> </a>The <code>\b</code>s at the start and end of the pattern make sure that the
+second string does not match.</p></div></div><hr/><div class="block"><p><a class="paragraph" href="#p2ed36c90566186ab" name="p2ed36c90566186ab"> </a>Part of a regular expression can be grouped together with parentheses.
+This allows us to use <code>*</code> and such on more than one character. For
+example:</p><pre class="code"><span class="keyword">var</span> <span class="variable">cartoonCrying</span> = <span class="string">/boo(hoo+)+/i</span>;
+<span class="variable">show</span>(<span class="string">"Then, he exclaimed 'Boohoooohoohooo'"</span>.<span class="property">search</span>(<span class="variable">cartoonCrying</span>));</pre><p><a class="paragraph" href="#pb6974678990c6d9" name="pb6974678990c6d9"> </a>Where did the <code>i</code> at the end of that regular expression come from?
+After the closing slash, 'options' may be added to a regular
+expression. An <code>i</code>, here, means the expression is case-insensitive,
+which allows the lower-case B in the pattern to match the upper-case
+one in the string.</p><p><a class="paragraph" href="#p7dea2fbd0d4c23ca" name="p7dea2fbd0d4c23ca"> </a>A pipe character (<code>|</code>) is used to allow a pattern to make a choice
+between two elements. For example:</p><pre class="code"><span class="keyword">var</span> <span class="variable">holyCow</span> = <span class="string">/(sacred|holy) (cow|bovine|bull|taurus)/i</span>;
+<span class="variable">show</span>(<span class="variable">holyCow</span>.<span class="property">test</span>(<span class="string">"Sacred bovine!"</span>));</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p4be8972ea05685cb" name="p4be8972ea05685cb"> </a>Often, looking for a pattern is just a first step in extracting
+something from a string. In previous chapters, this extraction was
+done by calling a string's <code>indexOf</code> and <code>slice</code> methods a lot. Now
+that we are aware of the existence of regular expressions, we can use
+the <code>match</code> method instead. When a string is matched against a regular
+expression, the result will be <code>null</code> if the match failed, or an array
+of matched strings if it succeeded.</p><pre class="code"><span class="variable">show</span>(<span class="string">"No"</span>.<span class="property">match</span>(<span class="string">/Yes/</span>));
+<span class="variable">show</span>(<span class="string">"... yes"</span>.<span class="property">match</span>(<span class="string">/yes/</span>));
+<span class="variable">show</span>(<span class="string">"Giant Ape"</span>.<span class="property">match</span>(<span class="string">/giant (\w+)/i</span>));</pre><p><a class="paragraph" href="#p4cb37024e57160d3" name="p4cb37024e57160d3"> </a>The first element in the returned array is always the part of the
+string that matched the pattern. As the last example shows, when there
+are parenthesized parts in the pattern, the parts they match are also
+added to the array. Often, this makes extracting pieces of string very
+easy.</p><pre class="code"><span class="keyword">var</span> <span class="variable">parenthesized</span> = <span class="variable">prompt</span>(<span class="string">"Tell me something"</span>, <span class="string">""</span>).<span class="property">match</span>(<span class="string">/\((.*)\)/</span>);
+<span class="keyword">if</span> (<span class="variable">parenthesized</span> != <span class="atom">null</span>)
+ <span class="variable">print</span>(<span class="string">"You parenthesized '"</span>, <span class="variable">parenthesized</span>[<span class="atom">1</span>], <span class="string">"'"</span>);</pre></div><hr/><div class="block"><a name="exercise3"></a><div class="exercisenum">Ex. 10.3</div><div class="exercise"><p><a class="paragraph" href="#p4ef170c78fad7bcf" name="p4ef170c78fad7bcf"> </a>Re-write the function <code>extractDate</code> that we wrote in <a href="chapter4.html">chapter 4</a>. When
+given a string, this function looks for something that follows the
+date format we saw earlier. If it can find such a date, it puts the
+values into a <code>Date</code> object. Otherwise, it throws an exception. Make
+it accept dates in which the day or month are written with only one
+digit.</p></div><div class="solution"><pre class="code"><span class="keyword">function</span> <span class="variable">extractDate</span>(<span class="variabledef">string</span>) {
+ <span class="keyword">var</span> <span class="variabledef">found</span> = <span class="localvariable">string</span>.<span class="property">match</span>(<span class="string">/(\d\d?)\/(\d\d?)\/(\d{4})/</span>);
+ <span class="keyword">if</span> (<span class="localvariable">found</span> == <span class="atom">null</span>)
+ <span class="keyword">throw</span> <span class="keyword">new</span> <span class="variable">Error</span>(<span class="string">"No date found in '"</span> + <span class="localvariable">string</span> + <span class="string">"'."</span>);
+ <span class="keyword">return</span> <span class="keyword">new</span> <span class="variable">Date</span>(<span class="variable">Number</span>(<span class="localvariable">found</span>[<span class="atom">3</span>]), <span class="variable">Number</span>(<span class="localvariable">found</span>[<span class="atom">2</span>]) - <span class="atom">1</span>,
+ <span class="variable">Number</span>(<span class="localvariable">found</span>[<span class="atom">1</span>]));
+}
+
+<span class="variable">show</span>(<span class="variable">extractDate</span>(<span class="string">"born 5/2/2007 (mother Noog): Long-ear Johnson"</span>));</pre><p><a class="paragraph" href="#p158086303fcfd023" name="p158086303fcfd023"> </a>This version is slightly longer than the previous one, but it has the
+advantage of actually checking what it is doing, and shouting out when
+it is given nonsensical input. This was a lot harder without regular
+expressions ― it would have taken a lot of calls to <code>indexOf</code> to find
+out whether the numbers had one or two digits, and whether the dashes
+were in the right places.</p></div></div><hr/><div class="block"><p><a class="paragraph" href="#p7b062f2259df786b" name="p7b062f2259df786b"> </a>The <a name="key5"></a><code>replace</code> method of string values, which we saw in <a href="chapter6.html">chapter 6</a>, can be
+given a regular expression as its first argument.</p><pre class="code"><span class="variable">print</span>(<span class="string">"Borobudur"</span>.<span class="property">replace</span>(<span class="string">/[ou]/g</span>, <span class="string">"a"</span>));</pre><p><a class="paragraph" href="#p15713a2f0b98670b" name="p15713a2f0b98670b"> </a>Notice the <code>g</code> character after the regular expression. It stands for
+'global', and means that every part of the string that matches the
+pattern should be replaced. When this <code>g</code> is omitted, only the first
+<code>"o"</code> would be replaced.</p><p><a class="paragraph" href="#p378eee313c8f0c76" name="p378eee313c8f0c76"> </a>Sometimes it is necessary to keep parts of the replaced strings. For
+example, we have a big string containing the names of people, one name
+per line, in the format "Lastname, Firstname". We want to swap these
+names, and remove the comma, to get a simple "Firstname Lastname"
+format.</p><pre class="code"><span class="keyword">var</span> <span class="variable">names</span> = <span class="string">"Picasso, Pablo\nGauguin, Paul\nVan Gogh, Vincent"</span>;
+<span class="variable">print</span>(<span class="variable">names</span>.<span class="property">replace</span>(<span class="string">/([\w ]+), ([\w ]+)/g</span>, <span class="string">"$2 $1"</span>));</pre><p><a class="paragraph" href="#p31d9c967337f9be2" name="p31d9c967337f9be2"> </a>The <code>$1</code> and <code>$2</code> the replacement string refer to the parenthesized
+parts in the pattern. <code>$1</code> is replaced by the text that matched
+against the first pair of parentheses, <code>$2</code> by the second, and so on,
+up to <code>$9</code>.</p><p><a class="paragraph" href="#p57faab01a0e0b3de" name="p57faab01a0e0b3de"> </a>If you have more than 9 parentheses parts in your pattern, this will
+no longer work. But there is one more way to replace pieces of a
+string, which can also be useful in some other tricky situations. When
+the second argument given to the <code>replace</code> method is a function value
+instead of a string, this function is called every time a match is
+found, and the matched text is replaced by whatever the function
+returns. The arguments given to the function are the matched elements,
+similar to the values found in the arrays returned by <code>match</code>: The
+first one is the whole match, and after that comes one argument for
+every parenthesized part of the pattern.</p><pre class="code"><span class="keyword">function</span> <span class="variable">eatOne</span>(<span class="variabledef">match</span>, <span class="variabledef">amount</span>, <span class="variabledef">unit</span>) {
+ <span class="localvariable">amount</span> = <span class="variable">Number</span>(<span class="localvariable">amount</span>) - <span class="atom">1</span>;
+ <span class="keyword">if</span> (<span class="localvariable">amount</span> == <span class="atom">1</span>) {
+ <span class="localvariable">unit</span> = <span class="localvariable">unit</span>.<span class="property">slice</span>(<span class="atom">0</span>, <span class="localvariable">unit</span>.<span class="property">length</span> - <span class="atom">1</span>);
+ }
+ <span class="keyword">else</span> <span class="keyword">if</span> (<span class="localvariable">amount</span> == <span class="atom">0</span>) {
+ <span class="localvariable">unit</span> = <span class="localvariable">unit</span> + <span class="string">"s"</span>;
+ <span class="localvariable">amount</span> = <span class="string">"no"</span>;
+ }
+ <span class="keyword">return</span> <span class="localvariable">amount</span> + <span class="string">" "</span> + <span class="localvariable">unit</span>;
+}
+
+<span class="keyword">var</span> <span class="variable">stock</span> = <span class="string">"1 lemon, 2 cabbages, and 101 eggs"</span>;
+<span class="variable">stock</span> = <span class="variable">stock</span>.<span class="property">replace</span>(<span class="string">/(\d+) (\w+)/g</span>, <span class="variable">eatOne</span>);
+
+<span class="variable">print</span>(<span class="variable">stock</span>);</pre></div><hr/><div class="block"><a name="exercise4"></a><div class="exercisenum">Ex. 10.4</div><div class="exercise"><p><a class="paragraph" href="#p3b6fcf5074d34c37" name="p3b6fcf5074d34c37"> </a>That last trick can be used to make the HTML-escaper from <a href="chapter6.html">chapter 6</a> more
+efficient. You may remember that it looked like this: </p><pre class="code"><span class="keyword">function</span> <span class="variable">escapeHTML</span>(<span class="variabledef">text</span>) {
+ <span class="keyword">var</span> <span class="variabledef">replacements</span> = [[<span class="string">"&"</span>, <span class="string">"&amp;"</span>], [<span class="string">"\""</span>, <span class="string">"&quot;"</span>],
+ [<span class="string">"<"</span>, <span class="string">"&lt;"</span>], [<span class="string">">"</span>, <span class="string">"&gt;"</span>]];
+ <span class="variable">forEach</span>(<span class="localvariable">replacements</span>, <span class="keyword">function</span>(<span class="variabledef">replace</span>) {
+ <span class="localvariable">text</span> = <span class="localvariable">text</span>.<span class="property">replace</span>(<span class="localvariable">replace</span>[<span class="atom">0</span>], <span class="localvariable">replace</span>[<span class="atom">1</span>]);
+ });
+ <span class="keyword">return</span> <span class="localvariable">text</span>;
+}</pre><p><a class="paragraph" href="#p38ca038b2155aa38" name="p38ca038b2155aa38"> </a>Write a new function <code>escapeHTML</code>, which does the same thing, but only
+calls <code>replace</code> once.</p></div><div class="solution"><pre class="code"><span class="keyword">function</span> <span class="variable">escapeHTML</span>(<span class="variabledef">text</span>) {
+ <span class="keyword">var</span> <span class="variabledef">replacements</span> = {<span class="string">"<"</span>: <span class="string">"&lt;"</span>, <span class="string">">"</span>: <span class="string">"&gt;"</span>,
+ <span class="string">"&"</span>: <span class="string">"&amp;"</span>, <span class="string">"\""</span>: <span class="string">"&quot;"</span>};
+ <span class="keyword">return</span> <span class="localvariable">text</span>.<span class="property">replace</span>(<span class="string">/[<>&"]/g</span>, <span class="keyword">function</span>(<span class="variabledef">character</span>) {
+ <span class="keyword">return</span> <span class="localvariable">replacements</span>[<span class="localvariable">character</span>];
+ });
+}
+
+<span class="variable">print</span>(<span class="variable">escapeHTML</span>(<span class="string">"The 'pre-formatted' tag is written \"<pre>\"."</span>));</pre><p><a class="paragraph" href="#p3c989769e16ba17d" name="p3c989769e16ba17d"> </a>The <code>replacements</code> object is a quick way to associate each character
+with its escaped version. Using it like this is safe (i.e. no
+<code>Dictionary</code> object is needed), because the only properties that will
+be used are those matched by the <code>/[<>&"]/</code> expression.</p></div></div><hr/><div class="block"><p><a class="paragraph" href="#p5753b7e96196f238" name="p5753b7e96196f238"> </a>There are cases where the pattern you need to match against is not
+known while you are writing the code. Say we are writing a (very
+simple-minded) obscenity filter for a message board. We only want to
+allow messages that do not contain obscene words. The administrator of
+the board can specify a list of words that he or she considers
+unacceptable.</p><p><a class="paragraph" href="#p277ed728ec39bfd4" name="p277ed728ec39bfd4"> </a>The most efficient way to check a piece of text for a set of words is
+to use a regular expression. If we have our word list as an array, we
+can build the regular expression like this:</p><pre class="code"><span class="keyword">var</span> <span class="variable">badWords</span> = [<span class="string">"ape"</span>, <span class="string">"monkey"</span>, <span class="string">"simian"</span>, <span class="string">"gorilla"</span>, <span class="string">"evolution"</span>];
+<span class="keyword">var</span> <span class="variable">pattern</span> = <span class="keyword">new</span> <span class="variable">RegExp</span>(<span class="variable">badWords</span>.<span class="property">join</span>(<span class="string">"|"</span>), <span class="string">"i"</span>);
+<span class="keyword">function</span> <span class="variable">isAcceptable</span>(<span class="variabledef">text</span>) {
+ <span class="keyword">return</span> !<span class="variable">pattern</span>.<span class="property">test</span>(<span class="localvariable">text</span>);
+}
+
+<span class="variable">show</span>(<span class="variable">isAcceptable</span>(<span class="string">"Mmmm, grapes."</span>));
+<span class="variable">show</span>(<span class="variable">isAcceptable</span>(<span class="string">"No more of that monkeybusiness, now."</span>));</pre><p><a class="paragraph" href="#p715e5fe8a3c62495" name="p715e5fe8a3c62495"> </a>We could add <code>\b</code> patterns around the words, so that the thing about
+grapes would not be classified as unacceptable. That would also make
+the second one acceptable, though, which is probably not correct.
+Obscenity filters are hard to get right (and usually way too annoying
+to be a good idea).</p><p><a class="paragraph" href="#p47b71fdfc0954b56" name="p47b71fdfc0954b56"> </a>The first argument to the <a name="key6"></a><code>RegExp</code> constructor is a string
+containing the pattern, the second argument can be used to add
+case-insensitivity or globalness. When building a string to hold the
+pattern, you have to be careful with backslashes. Because, normally,
+backslashes are removed when a string is interpreted, any backslashes
+that must end up in the regular expression itself have to be escaped:</p><pre class="code"><span class="keyword">var</span> <span class="variable">digits</span> = <span class="keyword">new</span> <span class="variable">RegExp</span>(<span class="string">"\\d+"</span>);
+<span class="variable">show</span>(<span class="variable">digits</span>.<span class="property">test</span>(<span class="string">"101"</span>));</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p67ee28b47e95b263" name="p67ee28b47e95b263"> </a>The most important thing to know about regular expressions is that
+they exist, and can greatly enhance the power of your string-mangling
+code. They are so cryptic that you'll probably have to look up the
+details on them the first ten times you want to make use of them.
+Persevere, and you will soon be off-handedly writing expressions that
+look like occult gibberish</p><div class="illustration"><img src="img/xkcd_regular_expressions.png"/></div><p><a class="paragraph" href="#p57032844af1f87bf" name="p57032844af1f87bf"> </a>(Comic by <a href="http://xkcd.com">Randall Munroe</a>.)</p></div><ol class="footnotes"><li><a name="footnote1"></a>In this case, the backslashes were not really necessary, because
+the characters occur between <code>[</code> and <code>]</code>, but it is easier to just
+escape them anyway, so you won't have to think about it.</li></ol><h1><span class="number">Chapter 11: </span>Web programming: A crash course</h1><div class="block"><p><a class="paragraph" href="#p215a94a837046f1e" name="p215a94a837046f1e"> </a>You are probably reading this in a web browser, so you are likely to
+be at least a little familiar with the World Wide Web. This
+chapter contains a quick, superficial introduction to the various
+elements that make the web work, and the way they relate to
+JavaScript. The three after this one are more practical, and show some
+of the ways JavaScript can be used to inspect and change a web-page.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p974cad8a7797534" name="p974cad8a7797534"> </a>The Internet is, basically, just a computer network spanning most of
+the world. Computer networks make it possible for computers to send
+each other messages. The techniques that underlie networking are an
+interesting subject, but not the subject of this book. All you have to
+know is that, typically, one computer, which we will call the
+<a name="key1"></a>server, is waiting for other computers to start talking to it. Once
+another computer, the <a name="key2"></a>client, opens communications with this server,
+they will exchange whatever it is that needs to be exchanged using
+some specific language, a <a name="key3"></a>protocol.</p><p><a class="paragraph" href="#p37853189e1adc3cf" name="p37853189e1adc3cf"> </a>The Internet is used to carry messages for <em>many</em> different protocols.
+There are protocols for chatting, protocols for file sharing,
+protocols used by malicious software to control the computer of the
+poor schmuck who installed it, and so on. The protocol that is of
+interest to us is that used by the World Wide Web. It is called
+<a name="key4"></a>HTTP, which stands for Hyper Text Transfer Protocol, and is used to
+retrieve web-pages and the files associated with them.</p><p><a class="paragraph" href="#p2902c9e4e783994d" name="p2902c9e4e783994d"> </a>In HTTP communication, the server is the computer on which the
+web-page is stored. The client is the computer, such as yours, which
+asks the server for a page, so that it can display it. Asking for a
+page like this is called an '<a name="key5"></a>HTTP request'.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p1338349ab05e601b" name="p1338349ab05e601b"> </a>Web-pages and other files that are accessible through the Internet are
+identified by <a name="key6"></a>URLs, which is an abbreviation of Universal Resource
+Locators. A URL looks like this:</p><pre class="preformatted">http://acc6.its.brooklyn.cuny.edu/~phalsall/texts/taote-v3.html</pre><p><a class="paragraph" href="#p4d943105a436c077" name="p4d943105a436c077"> </a>It is composed of three parts. The start, <code>http://</code>, indicates that
+this URL uses the HTTP protocol. There are some other protocols, such
+as FTP (File Transfer Protocol), which also make use of URLs. The next
+part, <code>acc6.its.brooklyn.cuny.edu</code>, names the server on which this
+page can be found. The end of the URL,
+<code>/~phalsal/texts/taote-v3.html</code>, names a specific file on this server.</p><p><a class="paragraph" href="#p21770142dde6d5af" name="p21770142dde6d5af"> </a>Most of the time, the World Wide Web is accessed using a browser.
+After typing a URL or clicking a link, the browser makes the
+appropriate HTTP request to the appropriate server. If all goes well,
+the server responds by sending a file back to the browser, who shows
+it to the user in one way or another.</p><p><a class="paragraph" href="#p647f98273ef611ea" name="p647f98273ef611ea"> </a>When, as in the example, the retrieved file is an <a name="key7"></a>HTML document, it
+will be displayed as a web-page. We briefly discussed HTML in <a href="chapter6.html">chapter 6</a>,
+where we saw that it could refer to image files. In <a href="chapter9.html">chapter 9</a>, we
+found that HTML pages can also contain <code><script></code> tags to load files
+of JavaScript code. When showing an HTML document, a browser will
+fetch all these extra files from their servers, so it can add them to
+the document.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p1b80e87a36e47799" name="p1b80e87a36e47799"> </a>Although a URL is supposed to point at a file, it is possible for a
+web-server to do something more complicated than just looking up a
+file and sending it to the client. ― It can process this file in some
+way first, or maybe there is no file at all, but only a program that,
+given a URL, has some way of generating the relevant document for it.</p><p><a class="paragraph" href="#p4a034a06d0f4a6e4" name="p4a034a06d0f4a6e4"> </a>Programs that transform or generate documents on a server are a
+popular way to make web-pages less static. When a file is just a file,
+it is always the same, but when there is a program that builds it
+every time it is requested, it could be made to look different for
+each person, based on things like whether this person has logged in or
+specified certain preferences. This can also make managing the content
+of web-pages much easier ― instead of adding a new HTML file whenever
+something new is put on a website, a new document is added to some
+central storage, and the program knows where to find it and how to
+show it to clients.</p><p><a class="paragraph" href="#p5427df345f8f4442" name="p5427df345f8f4442"> </a>This kind of web programming is called <a name="key8"></a>server-side programming. It
+affects the document before it is sent to the user. In some cases, it
+is also practical to have a program that runs <em>after</em> the page has
+been sent, when the user is looking at it. This is called <a name="key9"></a>client-side
+programming, because the program runs on the client computer.
+Client-side web programming is what JavaScript was invented for.</p></div><hr/><div class="block"><p><a class="paragraph" href="#pb5d4950c3451eeb" name="pb5d4950c3451eeb"> </a>Running programs client-side has an inherent problem. You can never
+really know in advance what kinds of programs the page you are
+visiting is going to run. If it can send information from your
+computer to others, damage something, or infiltrate your system,
+surfing the web would be a rather hazardous activity.</p><p><a class="paragraph" href="#p2ca07b9de2aadd9b" name="p2ca07b9de2aadd9b"> </a>To solve this dilemma, browsers severely limit the things a JavaScript
+program may do. It is not allowed to look at your files, or to modify
+anything not related to the web-page it came with. Isolating a
+programming environment like this is called <a name="key10"></a>sand-boxing. Allowing
+the programs enough room to be useful, and at the same time
+restricting them enough to prevent them from doing harm is not an easy
+thing to do. Every few months, some JavaScript programmer comes up
+with a new way to circumvent the limitations and do something harmful
+or privacy-invading. The people responsible for the browsers respond
+by modifying their programs to make this trick impossible, and all is
+well again ― until the next problem is discovered.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p75491f3ca449564a" name="p75491f3ca449564a"> ¶ </a>One of the first JavaScript tricks that became widely used is the
+<a name="key11"></a><a name="key12"></a><code>open</code> method of the <code>window</code> object. It takes a URL
+as an argument, and will open a new window showing that URL.</p><pre class="code"><span class="keyword">var</span> <span class="variable">perry</span> = <span class="variable">window</span>.<span class="property">open</span>(<span class="string">"http://www.pbfcomics.com"</span>);</pre><p><a class="paragraph" href="#p66fb209b064e4e6a" name="p66fb209b064e4e6a"> </a>Unless you turned off pop-up blocking in <a href="chapter6.html">chapter 6</a>, there's a chance that
+this new window is blocked. There is a good reason pop-up blockers
+exist. Web-programmers, especially those trying to get people to pay
+attention to advertisements, have abused the poor <code>window.open</code> method
+so much that by now, most users hate it with a passion. It has its
+place though, and in this book we will be using it to show some
+example pages. As a general rule, your scripts should not open any new
+windows unless the user asked for them.</p><p><a class="paragraph" href="#p21aa8dc65094ea6a" name="p21aa8dc65094ea6a"> </a>Note that, because <code>open</code> (just like <code>setTimeout</code> and company) is a
+method on the <code>window</code> object, the <code>window.</code> part can be left off.
+When a function is called 'normally', it is called as a method on the
+top-level object, which is what <code>window</code> is. Personally, I think
+<code>open</code> sounds a bit generic, so I'll usually type <code>window.open</code>, which
+makes it clear that it is a window that is being opened.</p><p><a class="paragraph" href="#p7f5e5857b8aa51fc" name="p7f5e5857b8aa51fc"> </a>The value returned by <code>window.open</code> is a new window. This is the
+global object for the script running in that window, and contains all
+the standard things like the <code>Object</code> constructor and the <code>Math</code>
+object. But if you try to look at them, most browsers will (probably)
+not let you...</p><pre class="code invalid"><span class="variable">show</span>(<span class="variable">perry</span>.<span class="property">Math</span>);</pre><p><a class="paragraph" href="#p4d7cf06c6a768e11" name="p4d7cf06c6a768e11"> </a>This is part of the sand-boxing that I mentioned earlier. Pages opened
+by your browser might show information that is meant only for you, for
+example on sites where you logged in, and thus it would be bad if any
+random script could go and read them. The exception to this rule is
+pages opened on the same domain: When a script running on a page from
+<code>eloquentjavascript.net</code> opens another page on that same domain, it
+can do everything it wants to this page.</p><p><a class="paragraph" href="#p5be60148df827603" name="p5be60148df827603"> </a>An opened window can be closed with its <a name="key13"></a><a name="key14"></a><code>close</code>
+method. If you didn't already close it yourself...</p><pre class="code"><span class="variable">perry</span>.<span class="property">close</span>();</pre><p><a class="paragraph" href="#p7604215231778930" name="p7604215231778930"> </a>Other kinds of sub-documents, such as frames
+(documents-within-a-document), are also windows from the perspective
+of a JavaScript program, and have their own JavaScript environment. In
+fact, the environment that you have access to in the console belongs
+to a small invisible frame hidden somewhere on this page ― this way,
+it is slightly harder for you to accidentally mess up the whole page.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p610a3520542c16c7" name="p610a3520542c16c7"> </a>Every window object has a <a name="key15"></a><code>document</code> property, which contains an
+object representing the document shown in that window. This object
+contains, for example, a property <a name="key16"></a><code>location</code>,
+with information about the URL of the document.</p><pre class="code"><span class="variable">show</span>(<span class="variable">document</span>.<span class="property">location</span>.<span class="property">href</span>);</pre><p><a class="paragraph" href="#p11f7166b478901" name="p11f7166b478901"> </a>Setting <code>document.location.href</code> to a new URL can be used to make the
+browser load another document. Another application of the <code>document</code>
+object is its <a name="key17"></a><code>write</code> method. This method, when
+given a string argument, writes some HTML to the document. When it is
+used on a fully loaded document, it will replace the whole document by
+the given HTML, which is usually not what you want. The idea is to
+have a script call it while the document is being loaded, in which
+case the written HTML will be inserted into the document at the place
+of the <code>script</code> tag that triggered it. This is a simple way to add
+some dynamic elements to a page. For example, here is a trivially
+simple document showing the current time.</p><pre class="code"><span class="variable">print</span>(<span class="variable">timeWriter</span>);
+<span class="keyword">var</span> <span class="variable">time</span> = <span class="variable">viewHTML</span>(<span class="variable">timeWriter</span>);</pre><pre class="code"><span class="variable">time</span>.<span class="property">close</span>();</pre><p><a class="paragraph" href="#p23deb3f634989fa0" name="p23deb3f634989fa0"> </a>Often, the techniques shown in <a href="chapter12.html">chapter 12</a> provide a cleaner and more
+versatile way to modify the document, but occasionally,
+<code>document.write</code> is the nicest, simplest way to do something.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p1af46a916e59d79c" name="p1af46a916e59d79c"> </a>Another popular application of JavaScript in web pages centers around
+<a name="key18"></a>forms. In case you are not quite sure what the role of 'forms' is,
+let me give a quick summary.</p><p><a class="paragraph" href="#p74a67e1a3687d6ea" name="p74a67e1a3687d6ea"> </a>A basic HTTP request is a simple request for a file. When this file is
+not really a passive file, but a server-side program, it can become
+useful to include information other than a filename in the request.
+For this purpose, HTTP requests are allowed to contain additional
+'parameters'. Here is an example:</p><pre class="preformatted">http://www.google.com/search?q=aztec%20empire</pre><p><a class="paragraph" href="#p59ad99259d080c28" name="p59ad99259d080c28"> </a>After the filename (<code>/search</code>), the URL continues with a question
+mark, after which the parameters follow. This request has one
+parameter, called <code>q</code> (for 'query', presumably), whose value is <code>aztec
+empire</code>. The <code>%20</code> part corresponds to a space. There are a number of
+characters that can not occur in these values, such as spaces,
+ampersands, or question marks. These are 'escaped' by replacing them
+with a <code>%</code> followed by their numerical value<a class="footref" href="#footnote1">1</a>, which serves the same
+purpose as the backslashes used in strings and regular expressions,
+but is even more unreadable.</p><p><a class="paragraph" href="#p7651937b8b7b5402" name="p7651937b8b7b5402"> </a>JavaScript provides functions <a name="key19"></a><code>encodeURIComponent</code> and
+<a name="key20"></a><code>decodeURIComponent</code> to add these codes to strings and remove them
+again.</p><pre class="code"><span class="keyword">var</span> <span class="variable">encoded</span> = <span class="variable">encodeURIComponent</span>(<span class="string">"aztec empire"</span>);
+<span class="variable">show</span>(<span class="variable">encoded</span>);
+<span class="variable">show</span>(<span class="variable">decodeURIComponent</span>(<span class="variable">encoded</span>));</pre><p><a class="paragraph" href="#p10bc7a0212b6ce51" name="p10bc7a0212b6ce51"> </a>When a request contains more than one parameter, they are separated by
+ampersands, as in...</p><pre class="preformatted">http://www.google.com/search?q=aztec%20empire&lang=nl</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p1d1ef60489c3c769" name="p1d1ef60489c3c769"> </a>A form, basically, is a way to make it easy for browser-users to
+create such parameterised URLs. It contains a number of fields, such
+as input boxes for text, checkboxes that can be 'checked' and
+'unchecked', or thingies that allow you to choose from a given set of
+values. It also usually contains a 'submit' button and, invisible to
+the user, an 'action' URL to which it should be sent. When the submit
+button is clicked, or enter is pressed, the information that was
+entered in the fields is added to this action URL as parameters, and
+the browser will request this URL.</p><p><a class="paragraph" href="#p406cdbfa9fce1fdc" name="p406cdbfa9fce1fdc"> </a>Here is the HTML for a simple form:</p><pre class="preformatted"><form name="userinfo" method="get" action="info.html">
+ <p>Please give us your information, so that we can send
+ you spam.</p>
+ <p>Name: <input type="text" name="name"/></p>
+ <p>E-Mail: <input type="text" name="email"/></p>
+ <p>Sex: <select name="sex">
+ <option>Male</option>
+ <option>Female</option>
+ <option>Other</option>
+ </select></p>
+ <p><input name="send" type="submit" value="Send!"/></p>
+</form></pre><p><a class="paragraph" href="#p538fdc14f7677e92" name="p538fdc14f7677e92"> </a>The name of the form can be used to access it with JavaScript, as we
+shall see in a moment. The names of the fields determine the names of
+the HTTP parameters that are used to store their values. Sending this
+form might produce a URL like this:</p><pre class="preformatted">http://planetspam.com/info.html?name=Ted&email=ted@zork.com&sex=Male</pre><p><a class="paragraph" href="#p219ea7957ff322a8" name="p219ea7957ff322a8"> </a>There are quite a few other tags and properties that can be used in
+forms, but in this book we will stick with simple ones, so that we can
+concentrate on JavaScript.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p6c177da4e31618eb" name="p6c177da4e31618eb"> </a>The <code>method="get"</code> property of the example form shown above indicates
+that this form should encode the values it is given as URL parameters,
+as shown before. There is an alternative method for sending
+parameters, which is called <code>post</code>. An HTTP request using the <code>post</code>
+method contains, in addition to a URL, a block of data. A form using
+the <code>post</code> method puts the values of its parameters in this data block
+instead of in the URL.</p><p><a class="paragraph" href="#p1bd7ebeede29316a" name="p1bd7ebeede29316a"> </a>When sending big chunks of data, the <code>get</code> method will result in URLs
+that are a mile wide, so <code>post</code> is usually more convenient. But the
+difference between the two methods is not just a question of
+convenience. Traditionally, <code>get</code> requests are used for requests that
+just ask the server for some document, while <code>post</code> requests are used
+to take an action that changes something on the server. For example,
+getting a list of recent messages on an Internet forum would be a
+<code>get</code> request, while adding a new message would be a <code>post</code> request.
+There is a good reason why most pages follow this distinction ―
+programs that automatically explore the web, such as those used by
+search engines, will generally only make <code>get</code> requests. If changes to
+a site can be made by <code>get</code> requests, these well-meaning 'crawlers'
+could do all kinds of damage.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p2fd2ddc325c801be" name="p2fd2ddc325c801be"> </a>When the browser is displaying a page containing a form, JavaScript
+programs can inspect and modify the values that are entered in the
+form's fields. This opens up possibilities for all kinds of tricks,
+such as checking values before they are sent to the server, or
+automatically filling in certain fields.</p><p><a class="paragraph" href="#pb9141e4c88552c7" name="pb9141e4c88552c7"> </a>The form shown above can be found in the file <code>example_getinfo.html</code>.
+Open it.</p><pre class="code"><span class="keyword">var</span> <span class="variable">form</span> = <span class="variable">window</span>.<span class="property">open</span>(<span class="string">"example_getinfo.html"</span>);</pre><p><a class="paragraph" href="#p121632dec93e9a8b" name="p121632dec93e9a8b"> </a>When a URL does not contain a server name, it is called a <a name="key21"></a>relative URL.
+Relative URLs are interpreted by the browser to refer to files on the
+same server as the current document. Unless they start with a slash,
+the path (or directory) of the current document is also retained, and
+the given path is appended to it.</p><p><a class="paragraph" href="#p12c860a567b9d97c" name="p12c860a567b9d97c"> </a>We will be adding a validity check to the form, so that it only
+submits if the name field is not left empty and the e-mail field
+contains something that looks like a valid e-mail address. Because we
+no longer want the form to submit immediately when the 'Send!' button
+is pressed, its <code>type</code> property has been changed from <code>"submit"</code> to
+<code>"button"</code>, which turns it into a regular button with no effect. ―
+<a href="chapter13.html">Chapter 13</a> will show a <em>much</em> better way of doing this, but for now, we
+use the naive method.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p3ed6cce4bd3d7fc4" name="p3ed6cce4bd3d7fc4"> </a><a name="key22"></a>To be able to work with the newly opened window (if you
+closed it, re-open it first), we 'attach' the console to it, like
+this:</p><pre class="code"><span class="variable">attach</span>(<span class="variable">form</span>);</pre><p><a class="paragraph" href="#p7fa72de0dcd38820" name="p7fa72de0dcd38820"> </a>After doing this, the code run from the console will be run in the
+given window. To verify that we are indeed working with the correct
+window, we can look at the document's <code>location</code> and <code>title</code>
+properties.</p><pre class="code"><span class="variable">print</span>(<span class="variable">document</span>.<span class="property">location</span>.<span class="property">href</span>);
+<span class="variable">print</span>(<span class="variable">document</span>.<span class="property">title</span>);</pre><p><a class="paragraph" href="#p9206f8b81681121" name="p9206f8b81681121"> </a>Because we have entered a new environment, previously defined
+variables, such as <code>form</code>, are no longer present.</p><pre class="code invalid"><span class="variable">show</span>(<span class="variable">form</span>);</pre><p><a class="paragraph" href="#p4e3dbc0688b0eebe" name="p4e3dbc0688b0eebe"> </a><a name="key23"></a>To get back to our starting environment, we can use the
+<code>detach</code> function (without arguments). But first, we have to add that
+validation system to the form.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p3d9b7dfe0cab7c5" name="p3d9b7dfe0cab7c5"> </a>Every HTML tag shown in a document has a JavaScript object associated
+with it. These objects can be used to inspect and manipulate almost
+every aspect of the document. In this chapter, we will work with the
+objects for forms and form fields, <a href="chapter12.html">chapter 12</a> talks about these objects in
+more detail.</p><p><a class="paragraph" href="#p77591c41cc2c3d3e" name="p77591c41cc2c3d3e"> </a><a name="key24"></a>The <code>document</code> object has a property named <code>forms</code>,
+which contains links to all the forms in the document, by name. Our
+form has a property <code>name="userinfo"</code>, so it can be found under the
+property <code>userinfo</code>.</p><pre class="code"><span class="keyword">var</span> <span class="variable">userForm</span> = <span class="variable">document</span>.<span class="property">forms</span>.<span class="property">userinfo</span>;
+<span class="variable">print</span>(<span class="variable">userForm</span>.<span class="property">method</span>);
+<span class="variable">print</span>(<span class="variable">userForm</span>.<span class="property">action</span>);</pre><p><a class="paragraph" href="#p3ae64296ade58117" name="p3ae64296ade58117"> </a>In this case, the properties <code>method</code> and <code>action</code> that were given to
+the HTML <code>form</code> tag are also present as properties of the JavaScript
+object. This is often the case, but not always: Some HTML properties
+are spelled differently in JavaScript, others are not present at all.
+<a href="chapter12.html">Chapter 12</a> will show a way to get at all properties.</p><p><a class="paragraph" href="#p3927f9f68734c04c" name="p3927f9f68734c04c"> </a>The object for the <code>form</code> tag has a property <code>elements</code>, which refers
+to an object containing the fields of the form, by name.</p><pre class="code"><span class="keyword">var</span> <span class="variable">nameField</span> = <span class="variable">userForm</span>.<span class="property">elements</span>.<span class="property">name</span>;
+<span class="variable">nameField</span>.<span class="property">value</span> = <span class="string">"Eugne"</span>;</pre><p><a class="paragraph" href="#p1c7de725744a371d" name="p1c7de725744a371d"> </a>Text-input objects have a <code>value</code> property, which can be used to read
+and change their content. If you look at the form window after running
+the above code, you'll see that the name has been filled in.</p></div><hr/><div class="block"><a name="exercise1"></a><div class="exercisenum">Ex. 11.1</div><div class="exercise"><p><a class="paragraph" href="#p541dacbcab2766eb" name="p541dacbcab2766eb"> </a>Being able to read the values of the form fields makes it possible to
+write a function <code>validInfo</code>, which takes a form object as its
+argument and returns a boolean value: <code>true</code> when the <code>name</code> field is
+not empty and the <code>email</code> field contains something that looks like an
+e-mail address, <code>false</code> otherwise. Write this function.</p></div><div class="solution"><pre class="code"><span class="keyword">function</span> <span class="variable">validInfo</span>(<span class="variabledef">form</span>) {
+ <span class="keyword">return</span> <span class="localvariable">form</span>.<span class="property">elements</span>.<span class="property">name</span>.<span class="property">value</span> != <span class="string">""</span> &&
+ <span class="string">/^.+@.+\.\w{2,3}$/</span>.<span class="property">test</span>(<span class="localvariable">form</span>.<span class="property">elements</span>.<span class="property">email</span>.<span class="property">value</span>);
+}
+
+<span class="variable">show</span>(<span class="variable">validInfo</span>(<span class="variable">document</span>.<span class="property">forms</span>.<span class="property">userinfo</span>));</pre><p><a class="paragraph" href="#p1bb27b4bf43ed6e0" name="p1bb27b4bf43ed6e0"> </a>You did think to use a regular expression for the e-mail check, didn't
+you?</p></div></div><hr/><div class="block"><p><a class="paragraph" href="#p53d234c1e595089d" name="p53d234c1e595089d"> </a>All we have to do now is determine what happens when people click the
+'Send!' button. At the moment, it does not do anything at all. This
+can be remedied by setting its <code>onclick</code> property.</p><pre class="code"><span class="variable">userForm</span>.<span class="property">elements</span>.<span class="property">send</span>.<span class="property">onclick</span> = <span class="keyword">function</span>() {
+ <span class="variable">alert</span>(<span class="string">"Click."</span>);
+};</pre><p><a class="paragraph" href="#p6aad7774d60be20b" name="p6aad7774d60be20b"> </a>Just like the actions given to <code>setInterval</code> and <code>setTimeout</code> (<a href="chapter8.html">chapter 8</a>),
+the value stored in an <a name="key25"></a><code>onclick</code> (or similar) property can be either
+a function or a string of JavaScript code. In this case, we give it a
+function that opens an alert window. Try clicking it.</p></div><hr/><div class="block"><a name="exercise2"></a><div class="exercisenum">Ex. 11.2</div><div class="exercise"><p><a class="paragraph" href="#p555067bbc9761c91" name="p555067bbc9761c91"> </a>Finish the form validator by giving the button's <code>onclick</code> property a
+new value ― a function that checks the form, submits when it is
+valid, or pops up a warning message when it is not. It will be useful
+to know that form objects have a <a name="key26"></a><code>submit</code> method that takes no
+parameters and submits the form.</p></div><div class="solution"><pre class="code"><span class="variable">userForm</span>.<span class="property">elements</span>.<span class="property">send</span>.<span class="property">onclick</span> = <span class="keyword">function</span>() {
+ <span class="keyword">if</span> (<span class="variable">validInfo</span>(<span class="variable">userForm</span>))
+ <span class="variable">userForm</span>.<span class="property">submit</span>();
+ <span class="keyword">else</span>
+ <span class="variable">alert</span>(<span class="string">"Give us a name and a valid e-mail address!"</span>);
+};</pre></div></div><hr/><div class="block"><p><a class="paragraph" href="#p1a69d33802ce26f1" name="p1a69d33802ce26f1"> </a>Another trick related to form inputs, as well as other things that can
+be 'selected', such as buttons and links, is the <a name="key27"></a><code>focus</code> method.
+When you know for sure that a user will want to start typing in a
+certain text field as soon as he enters the page, you can have your
+script start by placing the cursor in it, so he won't have to click it
+or select it in some other way.</p><pre class="code"><span class="variable">userForm</span>.<span class="property">elements</span>.<span class="property">name</span>.<span class="property">focus</span>();</pre><p><a class="paragraph" href="#p19e00e933fd2043f" name="p19e00e933fd2043f"> </a>Because the form sits in another window, it may not be obvious that
+something was selected, depending on the browser you are using. Some
+pages also automatically make the cursor jump to the next field when
+it looks like you finished filling in one field ― for example, when
+you type a zip code. This should not be overdone ― it makes the page
+behave in a way the user does not expect. If he is used to pressing
+tab to move the cursor manually, or mistyped the last character and
+wants to remove it, such magic cursor-jumping is very annoying.</p></div><hr/><div class="block"><pre class="code"><span class="variable">detach</span>();</pre><p><a class="paragraph" href="#p6fdc646aead27089" name="p6fdc646aead27089"> </a>Test the validator. When you enter valid information and click the
+button, the form should submit. If the console was still attached to
+it, this will cause it to detach itself, because the page reloads and
+the JavaScript environment is replaced by a new one.</p><p><a class="paragraph" href="#p7945865eb0cacf1d" name="p7945865eb0cacf1d"> </a>If you haven't closed the form window yet, this will close it.</p><pre class="code"><span class="variable">form</span>.<span class="property">close</span>();</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p1d059983b3caec5" name="p1d059983b3caec5"> </a>The above may look easy, but let me assure you, client-side
+web programming is no walk in the park. It can, at times, be a very
+painful ordeal. Why? Because programs that are supposed to run on the
+client computer generally have to work for all popular browsers. Each
+of these browsers tends to work slightly different. To make things
+worse, each of them contains a unique set of problems. Do not assume
+that a program is bug-free just because it was made by a multi-billion
+dollar company. So it is up to us, the web-programmer, to rigorously
+test our programs, figure out what goes wrong, and find ways to work
+around it.</p><p><a class="paragraph" href="#p1b88caf4f7052db" name="p1b88caf4f7052db"> </a>Some of you might think "I will just report any problems/<a name="key28"></a>bugs I find
+to the browser manufacturers, and they will certainly solve fix them
+immediately". These people are in for a major disappointment. The most
+recent version of Internet Explorer, the browser that is still used by
+some seventy percent of web-surfers (and that every web-developer
+likes to rag on) still contains bugs that have been known for over
+five years. Serious bugs, too.</p><p><a class="paragraph" href="#p21f1b49e9fa83773" name="p21f1b49e9fa83773"> </a>But do not let that discourage you. With the right kind of
+obsessive-compulsive mindset, such problems provide wonderful
+challenges. And for those of us who do not like wasting our time,
+being careful and avoiding the obscure corners of the browser's
+functionality will generally prevent you from running into too much
+trouble.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p58bddd3ddb98c58a" name="p58bddd3ddb98c58a"> </a>Bugs aside, the by-design differences in interface between browsers
+still make for an interesting challenge. The current situation looks
+something like this: On the one hand, there are all the 'small'
+browsers: Firefox, Safari, and Opera are the most important ones, but
+there are more. These browsers all make a reasonable effort to adhere
+to a set of standards that have been developed, or are being
+developed, by the W3C, an organisation that tries to make the Web a
+less confusing place by defining standard interfaces for things like
+this. On the other hand, there is Internet Explorer, Microsoft's
+browser, which rose to dominance in a time when many of these
+standards did not really exist yet, and hasn't made much effort to
+adjust itself to what other people are doing.</p><p><a class="paragraph" href="#p68cd52aa0c7f1c75" name="p68cd52aa0c7f1c75"> </a>In some areas, such as the way the content of an HTML document can be
+approached from JavaScript (<a href="chapter12.html">chapter 12</a>), the standards are based on the
+method that Internet Explorer invented, and things work more or less
+the same on all browsers. In other areas, such as the way events
+(mouse-clicks, key-presses, and such) are handled (<a href="chapter13.html">chapter 13</a>), Internet
+Explorer works radically different from other browsers.</p><p><a class="paragraph" href="#p1f02739b0b86908b" name="p1f02739b0b86908b"> </a>For a long time, owing partially to the cluelessness of the average
+JavaScript developer, and partially to the fact that browser
+incompatibilities were much worse when browsers like Internet Explorer
+version 4 or 5 and old versions of Netscape were still common, the
+usual way to deal with such differences was to detect which browser
+the user was running, and litter code with alternate solutions for
+each browser ― if this is Internet Explorer, do this, if this is
+Netscape, do that, and if this is other browser that we didn't think
+of, just hope for the best. You can imagine how hideous, confusing,
+and long such programs were.</p><p><a class="paragraph" href="#p79c0429cd5e756e7" name="p79c0429cd5e756e7"> </a>Many sites would also just refuse to load when opened in a browser
+that was 'not supported'. This caused a few of the minor browsers to
+swallow their pride and pretend they were Internet Explorer, just so
+they would be allowed to load such pages. The properties of the
+<a name="key29"></a><code>navigator</code> object contain information about the browser that a page
+was loaded in, but because of such lying this information is not
+particularly reliable. See what yours says<a class="footref" href="#footnote2">2</a>:</p><pre class="code"><span class="variable">forEachIn</span>(<span class="variable">navigator</span>, <span class="keyword">function</span>(<span class="variabledef">name</span>, <span class="variabledef">value</span>) {
+ <span class="variable">print</span>(<span class="localvariable">name</span>, <span class="string">" = "</span>, <span class="localvariable">value</span>);
+});</pre><p><a class="paragraph" href="#p4a14a9ef8ee4464d" name="p4a14a9ef8ee4464d"> </a>A better approach is to try and 'isolate' our programs from
+differences in browsers. If you need, for example, to find out more
+about an event, such as the clicks we handled by setting the <code>onclick</code>
+property of our send button, you have to look at the top-level object
+called <code>event</code> on Internet Explorer, but you have to use the first
+argument passed to the event-handling function on other browsers. To
+handle this, and a number of other differences related to events, one
+can write a helper function for attaching events to things, which
+takes care of all the plumbing and allows the event-handling functions
+themselves to be the same for all browsers. In <a href="chapter13.html">chapter 13</a> we will write
+such a function.</p><p><a class="paragraph" href="#p1e19541a30477d05" name="p1e19541a30477d05"> </a>(Note: The browser quirks mentioned in the following chapters refer to
+the state of affairs in early 2007, and might no longer be accurate on
+some points.)</p></div><hr/><div class="block"><p><a class="paragraph" href="#p8d68d5265638803" name="p8d68d5265638803"> </a>These chapters will only give a somewhat superficial introduction to
+the subject of browser interfaces. They are not the main subject of
+this book, and they are complex enough to fill a thick book on their
+own. When you understand the basics of these interfaces (and
+understand something about HTML), it is not too hard to look for
+specific information online. The interface documentation for the
+<a href="https://developer.mozilla.org/en/Gecko_DOM_Reference">Firefox</a>
+and <a href="http://msdn2.microsoft.com/library/yek4tbz0.aspx">Internet Explorer</a> browsers are a good
+place to start.</p><p><a class="paragraph" href="#p1756b90f8bdb0b41" name="p1756b90f8bdb0b41"> </a>The information in the next chapters will not deal with the quirks of
+'previous-generation' browsers. They deal with Internet Explorer 6,
+Firefox 1.5, Opera 9, Safari 3, or any more recent versions of the
+same browsers. Most of it will also probably be relevant to modern but
+obscure browsers such as Konqueror, but this has not been extensively
+checked. Fortunately, these previous-generation browsers have pretty
+much died out, and are hardly used anymore.</p><p><a class="paragraph" href="#p35a7fa9a8037d35e" name="p35a7fa9a8037d35e"> </a>There is, however, a group of web-users that will still use a browser
+without JavaScript. A large part of this group consists of people
+using a regular graphical browser, but with JavaScript disabled for
+security reasons. Then there are people using textual browsers, or
+browsers for blind people. When working on a 'serious' site, it is
+often a good idea to start with a plain HTML system that works, and
+then add non-essential tricks and conveniences with JavaScript.</p></div><ol class="footnotes"><li><a name="footnote1"></a>The value a character gets is decided by the ASCII standard, which
+assigns the numbers 0 to 127 to a set of letters and symbols used by
+the Latin alphabet. This standard is a precursor of the Unicode
+standard mentioned in <a href="chapter2.html">chapter 2</a>.</li><li><a name="footnote2"></a>Some browsers seem to hide the properties of the <code>navigator</code>
+object, in which case this will print nothing.</li></ol><h1><span class="number">Chapter 12: </span>The Document-Object Model</h1><div class="block"><p><a class="paragraph" href="#p2371f3184ab2f93d" name="p2371f3184ab2f93d"> </a>In <a href="chapter11.html">chapter 11</a> we saw JavaScript objects referring to <code>form</code> and <code>input</code>
+tags from the HTML document. Such objects are part of a structure
+called the <a name="key1"></a>Document-Object Model (<a name="key2"></a>DOM). Every tag of the document
+is represented in this model, and can be looked up and interacted
+with.</p><p><a class="paragraph" href="#p1a6b4b2b5e0c57b6" name="p1a6b4b2b5e0c57b6"> </a>HTML documents have what is called a hierarchical structure. Each
+element (or tag) except the top <code><html></code> tag is contained in another
+element, its parent. This element can in turn contain child elements.
+You can visualise this as a kind of family tree:</p><div class="illustration"><img src="img/html.png"/></div><p><a class="paragraph" href="#p2b836579b7a3eb89" name="p2b836579b7a3eb89"> </a>The document-object model is based on such a view of the document.
+Note that the tree contains two types of elements: Nodes, which are
+shown as blue boxes, and pieces of simple text. The pieces of text, as
+we will see, work somewhat different than the other elements. For one
+thing, they never have children.</p><p><a class="paragraph" href="#p45c17045586e9c9d" name="p45c17045586e9c9d"> </a>Open the file <code>example_alchemy.html</code>, which contains the document
+shown in the picture, and attach the console to it.</p><pre class="code"><span class="variable">attach</span>(<span class="variable">window</span>.<span class="property">open</span>(<span class="string">"example_alchemy.html"</span>));</pre><p><a class="paragraph" href="#p7892409b26883ab8" name="p7892409b26883ab8"> </a><a name="key3"></a>The object for the root of the document
+tree, the <code>html</code> node, can be reached through the <code>documentElement</code>
+property of the <code>document</code> object. Most of the time, we need access to
+the <code>body</code> part of the document instead, which is at
+<a name="key4"></a><code>document.body</code>.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p86956d8230219f9" name="p86956d8230219f9"> </a>The links between these nodes are available as properties of the node
+objects. Every DOM object has a <a name="key5"></a><code>parentNode</code> property, which refers
+to the object in which it is contained, if any. These parents also
+have links pointing back to their children, but because there can be
+more than one child, these are stored in a pseudo-array called
+<a name="key6"></a><code>childNodes</code>.</p><pre class="code"><span class="variable">show</span>(<span class="variable">document</span>.<span class="property">body</span>);
+<span class="variable">show</span>(<span class="variable">document</span>.<span class="property">body</span>.<span class="property">parentNode</span>);
+<span class="variable">show</span>(<span class="variable">document</span>.<span class="property">body</span>.<span class="property">childNodes</span>.<span class="property">length</span>);</pre><p><a class="paragraph" href="#p440f8233a2072614" name="p440f8233a2072614"> </a>For convenience, there are also links called <a name="key7"></a><code>firstChild</code> and
+<a name="key8"></a><code>lastChild</code>, pointing at the first and last child inside a node, or
+<code>null</code> when there are no children.</p><pre class="code"><span class="variable">show</span>(<span class="variable">document</span>.<span class="property">documentElement</span>.<span class="property">firstChild</span>);
+<span class="variable">show</span>(<span class="variable">document</span>.<span class="property">documentElement</span>.<span class="property">lastChild</span>);</pre><p><a class="paragraph" href="#p60f59a4c0b48d0fa" name="p60f59a4c0b48d0fa"> </a>Finally, there are properties called <a name="key9"></a><code>nextSibling</code> and
+<a name="key10"></a><code>previousSibling</code>, which point at the nodes sitting 'next' to a node
+― nodes that are children of the same parent, coming before or after
+the current node. Again, when there is no such sibling, the value of
+these properties is <code>null</code>.</p><pre class="code"><span class="variable">show</span>(<span class="variable">document</span>.<span class="property">body</span>.<span class="property">previousSibling</span>);
+<span class="variable">show</span>(<span class="variable">document</span>.<span class="property">body</span>.<span class="property">nextSibling</span>);</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p3ccb233a77d94d5d" name="p3ccb233a77d94d5d"> </a>To find out whether a node represents a simple piece of text or an
+actual HTML node, we can look at its <a name="key11"></a><code>nodeType</code> property. This
+contains a number, <code>1</code> for regular nodes and <code>3</code> for text nodes. There
+are actually other kinds of objects with a <code>nodeType</code>, such as the
+<code>document</code> object, which has <code>9</code>, but the most common use for this
+property is distinguishing between text nodes and other nodes.</p><pre class="code"><span class="keyword">function</span> <span class="variable">isTextNode</span>(<span class="variabledef">node</span>) {
+ <span class="keyword">return</span> <span class="localvariable">node</span>.<span class="property">nodeType</span> == <span class="atom">3</span>;
+}
+
+<span class="variable">show</span>(<span class="variable">isTextNode</span>(<span class="variable">document</span>.<span class="property">body</span>));
+<span class="variable">show</span>(<span class="variable">isTextNode</span>(<span class="variable">document</span>.<span class="property">body</span>.<span class="property">firstChild</span>.<span class="property">firstChild</span>));</pre><p><a class="paragraph" href="#p2be6a8ba1286bc38" name="p2be6a8ba1286bc38"> </a>Regular nodes have a property called <a name="key12"></a><code>nodeName</code>, indicating the type
+of HTML tag that they represent. Text nodes, on the other hand, have a
+<a name="key13"></a><code>nodeValue</code>, containing their text content.</p><pre class="code"><span class="variable">show</span>(<span class="variable">document</span>.<span class="property">body</span>.<span class="property">firstChild</span>.<span class="property">nodeName</span>);
+<span class="variable">show</span>(<span class="variable">document</span>.<span class="property">body</span>.<span class="property">firstChild</span>.<span class="property">firstChild</span>.<span class="property">nodeValue</span>);</pre><p><a class="paragraph" href="#p39f0c2b86ed51ac1" name="p39f0c2b86ed51ac1"> </a>The <code>nodeName</code>s are always capitalised, which is something you need to
+take into account if you ever want to compare them to something.</p><pre class="code"><span class="keyword">function</span> <span class="variable">isImage</span>(<span class="variabledef">node</span>) {
+ <span class="keyword">return</span> !<span class="variable">isTextNode</span>(<span class="localvariable">node</span>) && <span class="localvariable">node</span>.<span class="property">nodeName</span> == <span class="string">"IMG"</span>;
+}
+
+<span class="variable">show</span>(<span class="variable">isImage</span>(<span class="variable">document</span>.<span class="property">body</span>.<span class="property">lastChild</span>));</pre></div><hr/><div class="block"><a name="exercise1"></a><div class="exercisenum">Ex. 12.1</div><div class="exercise"><p><a class="paragraph" href="#p693bc40cd9f0664f" name="p693bc40cd9f0664f"> </a>Write a function <code>asHTML</code> which, when given a DOM node, produces a
+string representing the HTML text for that node and its children. You
+may ignore attributes, just show nodes as <code><nodename></code>. The
+<code>escapeHTML</code> function from <a href="chapter10.html">chapter 10</a> is available to properly escape
+the content of text nodes.</p><p><a class="paragraph" href="#p44eacebd36aa1758" name="p44eacebd36aa1758"> </a>Hint: Recursion!</p></div><div class="solution"><pre class="code"><span class="keyword">function</span> <span class="variable">asHTML</span>(<span class="variabledef">node</span>) {
+ <span class="keyword">if</span> (<span class="variable">isTextNode</span>(<span class="localvariable">node</span>))
+ <span class="keyword">return</span> <span class="variable">escapeHTML</span>(<span class="localvariable">node</span>.<span class="property">nodeValue</span>);
+ <span class="keyword">else</span> <span class="keyword">if</span> (<span class="localvariable">node</span>.<span class="property">childNodes</span>.<span class="property">length</span> == <span class="atom">0</span>)
+ <span class="keyword">return</span> <span class="string">"<"</span> + <span class="localvariable">node</span>.<span class="property">nodeName</span> + <span class="string">"/>"</span>;
+ <span class="keyword">else</span>
+ <span class="keyword">return</span> <span class="string">"<"</span> + <span class="localvariable">node</span>.<span class="property">nodeName</span> + <span class="string">">"</span> +
+ <span class="variable">map</span>(<span class="variable">asHTML</span>, <span class="localvariable">node</span>.<span class="property">childNodes</span>).<span class="property">join</span>(<span class="string">""</span>) +
+ <span class="string">"</"</span> + <span class="localvariable">node</span>.<span class="property">nodeName</span> + <span class="string">">"</span>;
+}
+
+<span class="variable">print</span>(<span class="variable">asHTML</span>(<span class="variable">document</span>.<span class="property">body</span>));</pre></div></div><hr/><div class="block"><p><a class="paragraph" href="#p6227576459690f7b" name="p6227576459690f7b"> </a>Nodes, in fact, already have something similar to <code>asHTML</code>. Their
+<a name="key14"></a><code>innerHTML</code> property can be used to retrieve the HTML text <em>inside</em>
+of the node, without the tags for the node itself. Some browsers also
+support <code>outerHTML</code>, which does include the node itself, but not all
+of them.</p><pre class="code"><span class="variable">print</span>(<span class="variable">document</span>.<span class="property">body</span>.<span class="property">innerHTML</span>);</pre><p><a class="paragraph" href="#p20b19c3c14fb6cf8" name="p20b19c3c14fb6cf8"> </a>Some of these properties can also be modified. Setting the <code>innerHTML</code>
+of a node or the <code>nodeValue</code> of a text-node will change its content.
+Note that, in the first case, the given string is interpreted as HTML,
+while in the second case it is interpreted as plain text.</p><pre class="code"><span class="variable">document</span>.<span class="property">body</span>.<span class="property">firstChild</span>.<span class="property">firstChild</span>.<span class="property">nodeValue</span> =
+ <span class="string">"Chapter 1: The deep significance of the bottle"</span>;</pre><p><a class="paragraph" href="#p5d1497533" name="p5d1497533"> </a>Or ...</p><pre class="code"><span class="variable">document</span>.<span class="property">body</span>.<span class="property">firstChild</span>.<span class="property">innerHTML</span> =
+ <span class="string">"Did you know the 'blink' tag yet? <blink>Joy!</blink>"</span>;</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p25697a36a698583f" name="p25697a36a698583f"> </a>We have been accessing nodes by going through a series of <code>firstChild</code>
+and <code>lastChild</code> properties. This can work, but it is verbose and easy
+to break ― if we add another node at the start of our document,
+<code>document.body.firstChild</code> no longer refers to the <code>h1</code> element, and
+code which assumes it does will go wrong. On top of that, some
+browsers will add text-nodes for things like spaces and newlines
+between tags, while others do not, so that the exact layout of the DOM
+tree can vary.</p><p><a class="paragraph" href="#p301690f60581a24" name="p301690f60581a24"> </a>An alternative to this is to give elements that you need to have
+access to an <code>id</code> attribute. In the example page, the picture has an
+id <code>"picture"</code>, and we can use this to look it up.</p><pre class="code"><span class="keyword">var</span> <span class="variable">picture</span> = <span class="variable">document</span>.<span class="property">getElementById</span>(<span class="string">"picture"</span>);
+<span class="variable">show</span>(<span class="variable">picture</span>.<span class="property">src</span>);
+<span class="variable">picture</span>.<span class="property">src</span> = <span class="string">"img/ostrich.png"</span>;</pre><p><a class="paragraph" href="#p64c511c6d47a97a4" name="p64c511c6d47a97a4"> </a><a name="key15"></a>When typing <code>getElementById</code>, note that
+the last letter is lowercase. Also, when typing it a lot, beware of
+carpal-tunnel syndrome. Because <code>document.getElementById</code> is a
+ridiculously long name for a very common operation, it has become a
+convention among JavaScript programmers to aggressively abbreviate it
+to <a name="key16"></a><code>$</code>. <code>$</code>, as you might remember, is considered a letter by
+JavaScript, and is thus a valid variable name.</p><pre class="code"><span class="keyword">function</span> <span class="variable">$</span>(<span class="variabledef">id</span>) {
+ <span class="keyword">return</span> <span class="variable">document</span>.<span class="property">getElementById</span>(<span class="localvariable">id</span>);
+}
+<span class="variable">show</span>(<span class="variable">$</span>(<span class="string">"picture"</span>));</pre><p><a class="paragraph" href="#p318d9b39b51b7152" name="p318d9b39b51b7152"> </a>DOM nodes also have a method <a name="key17"></a><code>getElementsByTagName</code> (another nice,
+short name), which, when given a tag name, returns an array of all
+nodes of that type contained in the node it was called on.</p><pre class="code"><span class="variable">show</span>(<span class="variable">document</span>.<span class="property">body</span>.<span class="property">getElementsByTagName</span>(<span class="string">"BLINK"</span>)[<span class="atom">0</span>]);</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p2e898bcad4486cb3" name="p2e898bcad4486cb3"> </a>Another thing we can do with these DOM nodes is creating new ones
+ourselves. This makes it possible to add pieces to a document at will,
+which can be used to create some interesting effects. Unfortunately,
+the interface for doing this is extremely clumsy. But that can be
+remedied with some helper functions.</p><p><a class="paragraph" href="#p4d363d7f0d3ce5" name="p4d363d7f0d3ce5"> </a><a name="key18"></a><a name="key19"></a>The <code>document</code>
+object has <code>createElement</code> and <code>createTextNode</code> methods. The first is
+used to create regular nodes, the second, as the name suggests,
+creates text nodes.</p><pre class="code"><span class="keyword">var</span> <span class="variable">secondHeader</span> = <span class="variable">document</span>.<span class="property">createElement</span>(<span class="string">"H1"</span>);
+<span class="keyword">var</span> <span class="variable">secondTitle</span> = <span class="variable">document</span>.<span class="property">createTextNode</span>(<span class="string">"Chapter 2: Deep magic"</span>);</pre><p><a class="paragraph" href="#p681a6d5bd714cad5" name="p681a6d5bd714cad5"> </a>Next, we'll want to put the title name into the <code>h1</code> element, and then
+add the element to the document. The simplest way to do this is the
+<a name="key20"></a><code>appendChild</code> method, which can be called on every (non-text) node.</p><pre class="code"><span class="variable">secondHeader</span>.<span class="property">appendChild</span>(<span class="variable">secondTitle</span>);
+<span class="variable">document</span>.<span class="property">body</span>.<span class="property">appendChild</span>(<span class="variable">secondHeader</span>);</pre><p><a class="paragraph" href="#p2f9841d88b9f3000" name="p2f9841d88b9f3000"> </a>Often, you will also want to give these new nodes some attributes. For
+example, an <code>img</code> (image) tag is rather useless without an <code>src</code>
+property telling the browser which image it should show. Most
+attributes can be approached directly as properties of the DOM nodes,
+but there are also methods <a name="key21"></a><code>setAttribute</code> and <a name="key22"></a><code>getAttribute</code>,
+which are used to access attributes in a more general way:</p><pre class="code"><span class="keyword">var</span> <span class="variable">newImage</span> = <span class="variable">document</span>.<span class="property">createElement</span>(<span class="string">"IMG"</span>);
+<span class="variable">newImage</span>.<span class="property">setAttribute</span>(<span class="string">"src"</span>, <span class="string">"img/Hiva Oa.png"</span>);
+<span class="variable">document</span>.<span class="property">body</span>.<span class="property">appendChild</span>(<span class="variable">newImage</span>);
+<span class="variable">show</span>(<span class="variable">newImage</span>.<span class="property">getAttribute</span>(<span class="string">"src"</span>));</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p70aeeb1819ce2ccf" name="p70aeeb1819ce2ccf"> </a>But, when we want to build more than a few simple nodes, it gets very
+tiresome to create every single node with a call to
+<code>document.createElement</code> or <code>document.createTextNode</code>, and then add
+its attributes and child nodes one by one. Fortunately, it is not hard
+to write a function to do most of the work for us. Before we do so,
+there is one little detail to take care of ― the <code>setAttribute</code>
+method, while working fine on most browsers, does not always work on
+Internet Explorer. The names of a few HTML attributes already have a
+special meaning in JavaScript, and thus the corresponding object
+properties got an adjusted name. Specifically, the <code>class</code> attribute
+becomes <a name="key23"></a><code>className</code>, <code>for</code> becomes <code>htmlFor</code>, and <code>checked</code> is
+renamed to <code>defaultChecked</code>. On Internet Explorer, <code>setAttribute</code> and
+<code>getAttribute</code> also work with these adjusted names, instead of the
+original HTML names, which can be confusing. On top of that the
+<a name="key24"></a><code>style</code> attribute, which, along with <code>class</code>, will be discussed
+later in this chapter, can not be set with <code>setAttribute</code> on that
+browser.</p><p><a class="paragraph" href="#p791e905afd14653e" name="p791e905afd14653e"> </a>A workaround would look something like this:</p><pre class="code"><span class="keyword">function</span> <span class="variable">setNodeAttribute</span>(<span class="variabledef">node</span>, <span class="variabledef">attribute</span>, <span class="variabledef">value</span>) {
+ <span class="keyword">if</span> (<span class="localvariable">attribute</span> == <span class="string">"class"</span>)
+ <span class="localvariable">node</span>.<span class="property">className</span> = <span class="localvariable">value</span>;
+ <span class="keyword">else</span> <span class="keyword">if</span> (<span class="localvariable">attribute</span> == <span class="string">"checked"</span>)
+ <span class="localvariable">node</span>.<span class="property">defaultChecked</span> = <span class="localvariable">value</span>;
+ <span class="keyword">else</span> <span class="keyword">if</span> (<span class="localvariable">attribute</span> == <span class="string">"for"</span>)
+ <span class="localvariable">node</span>.<span class="property">htmlFor</span> = <span class="localvariable">value</span>;
+ <span class="keyword">else</span> <span class="keyword">if</span> (<span class="localvariable">attribute</span> == <span class="string">"style"</span>)
+ <span class="localvariable">node</span>.<span class="property">style</span>.<span class="property">cssText</span> = <span class="localvariable">value</span>;
+ <span class="keyword">else</span>
+ <span class="localvariable">node</span>.<span class="property">setAttribute</span>(<span class="localvariable">attribute</span>, <span class="localvariable">value</span>);
+}</pre><p><a class="paragraph" href="#p376e25cb4a452da4" name="p376e25cb4a452da4"> </a>For every case where Internet Explorer deviates from other browsers,
+it does something that works in all cases. Don't worry about the
+details ― this is the kind of ugly trick that we'd rather not need,
+but which non-conforming browsers force us to write. Having this, it
+is possible to write a simple function for building DOM elements.</p><pre class="code"><span class="keyword">function</span> <span class="variable">dom</span>(<span class="variabledef">name</span>, <span class="variabledef">attributes</span>) {
+ <span class="keyword">var</span> <span class="variabledef">node</span> = <span class="variable">document</span>.<span class="property">createElement</span>(<span class="localvariable">name</span>);
+ <span class="keyword">if</span> (<span class="localvariable">attributes</span>) {
+ <span class="variable">forEachIn</span>(<span class="localvariable">attributes</span>, <span class="keyword">function</span>(<span class="variabledef">name</span>, <span class="variabledef">value</span>) {
+ <span class="variable">setNodeAttribute</span>(<span class="localvariable">node</span>, <span class="localvariable">name</span>, <span class="localvariable">value</span>);
+ });
+ }
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variabledef">i</span> = <span class="atom">2</span>; <span class="localvariable">i</span> < <span class="localvariable">arguments</span>.<span class="property">length</span>; <span class="localvariable">i</span>++) {
+ <span class="keyword">var</span> <span class="variabledef">child</span> = <span class="localvariable">arguments</span>[<span class="localvariable">i</span>];
+ <span class="keyword">if</span> (typeof <span class="localvariable">child</span> == <span class="string">"string"</span>)
+ <span class="localvariable">child</span> = <span class="variable">document</span>.<span class="property">createTextNode</span>(<span class="localvariable">child</span>);
+ <span class="localvariable">node</span>.<span class="property">appendChild</span>(<span class="localvariable">child</span>);
+ }
+ <span class="keyword">return</span> <span class="localvariable">node</span>;
+}
+
+<span class="keyword">var</span> <span class="variable">newParagraph</span> =
+ <span class="variable">dom</span>(<span class="string">"P"</span>, <span class="atom">null</span>, <span class="string">"A paragraph with a "</span>,
+ <span class="variable">dom</span>(<span class="string">"A"</span>, {<span class="property">href</span>: <span class="string">"http://en.wikipedia.org/wiki/Alchemy"</span>},
+ <span class="string">"link"</span>),
+ <span class="string">" inside of it."</span>);
+<span class="variable">document</span>.<span class="property">body</span>.<span class="property">appendChild</span>(<span class="variable">newParagraph</span>);</pre><p><a class="paragraph" href="#p162c21af52c74199" name="p162c21af52c74199"> </a>The <a name="key25"></a><code>dom</code> function creates a DOM node. Its first argument gives the
+tag name of the node, its second argument is an object containing the
+attributes of the node, or <code>null</code> when no attributes are needed. After
+that, any amount of arguments may follow, and these are added to the
+node as child nodes. When strings appear here, they are first put into
+a text node.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p39e473097619d796" name="p39e473097619d796"> </a><code>appendChild</code> is not the only way nodes can be inserted into another
+node. When the new node should not appear at the end of its parent,
+the <a name="key26"></a><code>insertBefore</code> method can be used to place it in front of
+another child node. It takes the new node as a first argument, and the
+existing child as second argument.</p><pre class="code"><span class="keyword">var</span> <span class="variable">link</span> = <span class="variable">newParagraph</span>.<span class="property">childNodes</span>[<span class="atom">1</span>];
+<span class="variable">newParagraph</span>.<span class="property">insertBefore</span>(<span class="variable">dom</span>(<span class="string">"STRONG"</span>, <span class="atom">null</span>, <span class="string">"great "</span>), <span class="variable">link</span>);</pre><p><a class="paragraph" href="#p11f16a6744ae4dcd" name="p11f16a6744ae4dcd"> </a>If a node that already has a <code>parentNode</code> is placed somewhere, it is
+automatically removed from its current position ― nodes can not exist
+in the document in more than one place.</p><p><a class="paragraph" href="#p579ea6f7e446ae9d" name="p579ea6f7e446ae9d"> </a>When a node must be replaced by another one, use the <a name="key27"></a><code>replaceChild</code>
+method, which again takes the new node as first argument and the
+existing one as second argument.</p><pre class="code"><span class="variable">newParagraph</span>.<span class="property">replaceChild</span>(<span class="variable">document</span>.<span class="property">createTextNode</span>(<span class="string">"lousy "</span>),
+ <span class="variable">newParagraph</span>.<span class="property">childNodes</span>[<span class="atom">1</span>]);</pre><p><a class="paragraph" href="#p4482097c05237c2a" name="p4482097c05237c2a"> </a>And, finally, there is <a name="key28"></a><code>removeChild</code> to remove a child node. Note
+that this is called on the <em>parent</em> of the node to be removed, giving
+the child as argument.</p><pre class="code"><span class="variable">newParagraph</span>.<span class="property">removeChild</span>(<span class="variable">newParagraph</span>.<span class="property">childNodes</span>[<span class="atom">1</span>]);</pre></div><hr/><div class="block"><a name="exercise2"></a><div class="exercisenum">Ex. 12.2</div><div class="exercise"><p><a class="paragraph" href="#p7de372f354824f06" name="p7de372f354824f06"> </a>Write the convenient function <a name="key29"></a><code>removeElement</code> which removes the DOM
+node it is given as an argument from its parent node.</p></div><div class="solution"><pre class="code"><span class="keyword">function</span> <span class="variable">removeElement</span>(<span class="variabledef">node</span>) {
+ <span class="keyword">if</span> (<span class="localvariable">node</span>.<span class="property">parentNode</span>)
+ <span class="localvariable">node</span>.<span class="property">parentNode</span>.<span class="property">removeChild</span>(<span class="localvariable">node</span>);
+}
+
+<span class="variable">removeElement</span>(<span class="variable">newParagraph</span>);</pre></div></div><hr/><div class="block"><p><a class="paragraph" href="#p343dadd85c8f719b" name="p343dadd85c8f719b"> </a>When creating new nodes and moving nodes around it is necessary to be
+aware of the following rule: Nodes are not allowed to be inserted into
+another document from the one in which they were created. This means
+that if you have extra frames or windows open, you can not take a
+piece of the document from one and move it to another, and nodes
+created with methods on one <code>document</code> object must stay in that
+document. Some browsers, notably Firefox, do not enforce this
+restriction, and thus a program which violates it will work fine in
+those browsers but break on others.</p></div><hr/><div class="block"><p><a class="paragraph" href="#pf55e5ba81e9c1c7" name="pf55e5ba81e9c1c7"> </a>An example of something useful that can be done with this <code>dom</code>
+function is a program that takes JavaScript objects and summarises
+them in a <a name="key30"></a>table. Tables, in HTML, are created with a set of tags
+starting with <code>t</code>s, something like this:</p><pre class="preformatted"><table>
+ <tbody>
+ <tr> <th>Tree </th> <th>Flowers</th> </tr>
+ <tr> <td>Apple</td> <td>White </td> </tr>
+ <tr> <td>Coral</td> <td>Red </td> </tr>
+ <tr> <td>Pine </td> <td>None </td> </tr>
+ </tbody>
+</table></pre><p><a class="paragraph" href="#p4678f201e3f69cd2" name="p4678f201e3f69cd2"> </a>Each <code>tr</code> element is a row of the table. <code>th</code> and <code>td</code> elements are
+the cells of the table, <code>td</code>s are normal data cells, <code>th</code> cells are
+'header' cells, which will be displayed in a slightly more prominent
+way. The <code>tbody</code> (table body) tag does not have to be included when a
+table is written as HTML, but when building a table from DOM nodes it
+should be added, because Internet Explorer refuses to display tables
+created without a <code>tbody</code>.</p></div><hr/><div class="block"><a name="exercise3"></a><div class="exercisenum">Ex. 12.3</div><div class="exercise"><p><a class="paragraph" href="#p1f7399e46ec01044" name="p1f7399e46ec01044"> </a>The function <code>makeTable</code> takes two arrays as arguments. The first
+contains the JavaScript objects that it should summarise, and the
+second contains strings, which name the columns of the table and the
+properties of the objects that should be shown in these columns. For
+example, the following will produce the table above:</p><pre class="code invalid"><span class="variable">makeTable</span>([{<span class="property">Tree</span>: <span class="string">"Apple"</span>, <span class="property">Flowers</span>: <span class="string">"White"</span>},
+ {<span class="property">Tree</span>: <span class="string">"Coral"</span>, <span class="property">Flowers</span>: <span class="string">"Red"</span>},
+ {<span class="property">Tree</span>: <span class="string">"Pine"</span>, <span class="property">Flowers</span>: <span class="string">"None"</span>}],
+ [<span class="string">"Tree"</span>, <span class="string">"Flowers"</span>]);</pre><p><a class="paragraph" href="#p699a821489361909" name="p699a821489361909"> </a>Write this function.</p></div><div class="solution"><pre class="code"><span class="keyword">function</span> <span class="variable">makeTable</span>(<span class="variabledef">data</span>, <span class="variabledef">columns</span>) {
+ <span class="keyword">var</span> <span class="variabledef">headRow</span> = <span class="variable">dom</span>(<span class="string">"TR"</span>);
+ <span class="variable">forEach</span>(<span class="localvariable">columns</span>, <span class="keyword">function</span>(<span class="variabledef">name</span>) {
+ <span class="localvariable">headRow</span>.<span class="property">appendChild</span>(<span class="variable">dom</span>(<span class="string">"TH"</span>, <span class="atom">null</span>, <span class="localvariable">name</span>));
+ });
+
+ <span class="keyword">var</span> <span class="variabledef">body</span> = <span class="variable">dom</span>(<span class="string">"TBODY"</span>, <span class="atom">null</span>, <span class="localvariable">headRow</span>);
+ <span class="variable">forEach</span>(<span class="localvariable">data</span>, <span class="keyword">function</span>(<span class="variabledef">object</span>) {
+ <span class="keyword">var</span> <span class="variabledef">row</span> = <span class="variable">dom</span>(<span class="string">"TR"</span>);
+ <span class="variable">forEach</span>(<span class="localvariable">columns</span>, <span class="keyword">function</span>(<span class="variabledef">name</span>) {
+ <span class="localvariable">row</span>.<span class="property">appendChild</span>(<span class="variable">dom</span>(<span class="string">"TD"</span>, <span class="atom">null</span>, <span class="variable">String</span>(<span class="localvariable">object</span>[<span class="localvariable">name</span>])));
+ });
+ <span class="localvariable">body</span>.<span class="property">appendChild</span>(<span class="localvariable">row</span>);
+ });
+
+ <span class="keyword">return</span> <span class="variable">dom</span>(<span class="string">"TABLE"</span>, <span class="atom">null</span>, <span class="localvariable">body</span>);
+}
+
+<span class="keyword">var</span> <span class="variable">table</span> = <span class="variable">makeTable</span>(<span class="variable">document</span>.<span class="property">body</span>.<span class="property">childNodes</span>,
+ [<span class="string">"nodeType"</span>, <span class="string">"tagName"</span>]);
+<span class="variable">document</span>.<span class="property">body</span>.<span class="property">appendChild</span>(<span class="variable">table</span>);</pre><p><a class="paragraph" href="#p4e2188b5a2b3aa36" name="p4e2188b5a2b3aa36"> </a>Do not forget to convert the values from the objects to strings before
+adding them to the table ― our <code>dom</code> function only understands
+strings and DOM nodes.</p></div></div><hr/><div class="block"><p><a class="paragraph" href="#p7b5d594f0e4b3062" name="p7b5d594f0e4b3062"> </a>Closely tied to HTML and the document-object model is the topic of
+<a name="key31"></a>style-sheets. It is a big topic, and I will not discuss it entirely,
+but some understanding of style-sheets is necessary for a lot of
+interesting JavaScript techniques, so we will go over the basics.</p><p><a class="paragraph" href="#p64f6941be56bc96a" name="p64f6941be56bc96a"> </a>In old-fashioned HTML, the only way to change the appearance of
+elements in a document was to give them extra attributes or to wrap
+them in extra tags, such as <code>center</code> to center them horizontally, or
+<code>font</code> to change the font style or colour. Most of the time, this meant
+that if you wanted the paragraphs or the tables in your document to
+look a certain way, you had to add a bunch of attributes and tags to
+<em>every single one of them</em>. This quickly adds a lot of noise to such
+documents, and makes them very painful to write or change by hand.</p><p><a class="paragraph" href="#p72fca0bf4e2a8dd2" name="p72fca0bf4e2a8dd2"> </a>Of course, people being the inventive monkeys they are, someone came
+up with a solution. Style-sheets are a way to make statements like 'in
+this document, all paragraphs use the Comic Sans font, and are purple,
+and all tables have a thick green border'. You specify them once, at
+the top of the document or in a separate file, and they affect the
+whole document. Here, for example, is a style-sheet to make headers 22
+points big and centered, and make paragraphs use the font and colour
+mentioned earlier, when they are of the 'ugly' class.</p><pre class="preformatted"><style type="text/css">
+ h1 {
+ font-size: 22pt;
+ text-align: center;
+ }
+
+ p.ugly {
+ font-family: Comic Sans MS;
+ color: purple;
+ }
+</style></pre><p><a class="paragraph" href="#p349dc099954e894" name="p349dc099954e894"> </a>Classes are a concept related to styles. If you have different kinds
+of paragraphs, ugly ones and nice ones for example, setting the style
+for all <code>p</code> elements is not what you want, so <a name="key32"></a>classes can be used to
+distinguish between them. The above style will only be applied to
+paragraphs like this:</p><pre class="preformatted"><p class="ugly">Mirror, mirror...</p></pre><p><a class="paragraph" href="#p6c51025c01391032" name="p6c51025c01391032"> </a>And this is also the meaning of the <a name="key33"></a><code>className</code> property which was
+briefly mentioned for the <code>setNodeAttribute</code> function. The <a name="key34"></a><code>style</code>
+attribute can be used to add a piece of style directly to an element.
+For example, this gives our image a solid border 4 pixels ('px') wide.</p><pre class="code"><span class="variable">setNodeAttribute</span>(<span class="variable">$</span>(<span class="string">"picture"</span>), <span class="string">"style"</span>,
+ <span class="string">"border-width: 4px; border-style: solid;"</span>);</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p3af4cf5019ec289a" name="p3af4cf5019ec289a"> </a>There is much more to styles: Some styles are inherited by child nodes
+from parent nodes, and interfere with each other in complex and
+interesting ways, but for the purpose of DOM programming, the most
+important thing to know is that each DOM node has a <code>style</code> property,
+which can be used to manipulate the style of that node, and that there
+are a few kinds of styles that can be used to make nodes do
+extraordinary things.</p><p><a class="paragraph" href="#p38583625c73749a5" name="p38583625c73749a5"> </a>This <code>style</code> property refers to an object, which has properties for
+all the possible elements of the style. We can, for example, make the
+picture's border green.</p><pre class="code"><span class="variable">$</span>(<span class="string">"picture"</span>).<span class="property">style</span>.<span class="property">borderColor</span> = <span class="string">"green"</span>;
+<span class="variable">show</span>(<span class="variable">$</span>(<span class="string">"picture"</span>).<span class="property">style</span>.<span class="property">borderColor</span>);</pre><p><a class="paragraph" href="#p6143d9936b617114" name="p6143d9936b617114"> </a>Note that in style-sheets, the words are separated by hyphens, as in
+<code>border-color</code>, while in JavaScript, capital letters are used to mark
+the different words, as in <code>borderColor</code>.</p><p><a class="paragraph" href="#p6f36589d568674e8" name="p6f36589d568674e8"> </a>A very practical kind of style is <code>display: none</code>. This can be used to
+temporarily hide a node: When <a name="key35"></a><code>style.display</code> is <code>"none"</code>, the element
+does not appear at all to the viewer of the document, even though it
+does exist. Later, <code>display</code> can be set to the empty string, and the
+element will re-appear.</p><pre class="code"><span class="variable">$</span>(<span class="string">"picture"</span>).<span class="property">style</span>.<span class="property">display</span> = <span class="string">"none"</span>;</pre><p><a class="paragraph" href="#p25f13b7a27de58c1" name="p25f13b7a27de58c1"> </a>And, to get our picture back:</p><pre class="code"><span class="variable">$</span>(<span class="string">"picture"</span>).<span class="property">style</span>.<span class="property">display</span> = <span class="string">""</span>;</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p48aaace071bc7c1e" name="p48aaace071bc7c1e"> </a>Another set of style types that can be abused in interesting ways are
+those related to positioning. In a simple HTML document, the browser
+takes care of determining the screen positions of all the elements ―
+each element is put next to or below the elements that come before it,
+and nodes (generally) do not overlap.</p><p><a class="paragraph" href="#p1adb29643a45055d" name="p1adb29643a45055d"> </a><a name="key36"></a>When its <code>position</code> style is set to <code>"absolute"</code>, a
+node is taken out of the normal document 'flow'. It no longer takes up
+room in the document, but sort of floats above it. The <code>left</code> and
+<code>top</code> styles can then be used to influence its position. This can be
+used for various purposes, from making a node obnoxiously follow the
+mouse cursor to making 'windows' open on top of the rest of the
+document.</p><pre class="code"><span class="variable">$</span>(<span class="string">"picture"</span>).<span class="property">style</span>.<span class="property">position</span> = <span class="string">"absolute"</span>;
+<span class="keyword">var</span> <span class="variable">angle</span> = <span class="atom">0</span>;
+<span class="keyword">var</span> <span class="variable">spin</span> = <span class="variable">setInterval</span>(<span class="keyword">function</span>() {
+ <span class="variable">angle</span> += <span class="atom">0.1</span>;
+ <span class="variable">$</span>(<span class="string">"picture"</span>).<span class="property">style</span>.<span class="property">left</span> = (<span class="atom">100</span> + <span class="atom">100</span> * <span class="variable">Math</span>.<span class="property">cos</span>(<span class="variable">angle</span>)) + <span class="string">"px"</span>;
+ <span class="variable">$</span>(<span class="string">"picture"</span>).<span class="property">style</span>.<span class="property">top</span> = (<span class="atom">100</span> + <span class="atom">100</span> * <span class="variable">Math</span>.<span class="property">sin</span>(<span class="variable">angle</span>)) + <span class="string">"px"</span>;
+}, <span class="atom">100</span>);</pre><p><a class="paragraph" href="#p5dc64c194a44c865" name="p5dc64c194a44c865"> </a>If you aren't familiar with trigonometry, just believe me when I tell
+you that the cosine and sine stuff is used to build coordinates lying
+on the outline of a circle. Ten times per second, the angle at which
+we place the picture is changed, and new coordinates are computed. It
+is a common error, when setting styles like this, to forget to append
+<code>"px"</code> to your value. In most cases, setting a style to a number
+without a unit does not work, so you must add <code>"px"</code> for pixels, <code>"%"</code>
+for percent, <code>"em"</code> for 'ems' (the width of an <code>M</code> character), or
+<code>"pt"</code> for points.</p><p><a class="paragraph" href="#p439de65d084f14a3" name="p439de65d084f14a3"> </a>(Now put the image to rest again...)</p><pre class="code"><span class="variable">clearInterval</span>(<span class="variable">spin</span>);</pre><p><a class="paragraph" href="#p7b2d891f7bbe9c6c" name="p7b2d891f7bbe9c6c"> </a>The place that is treated as 0,0 for the purpose of these positions
+depends on the place of the node in the document. When it is placed
+inside another node that has <code>position: absolute</code> or <code>position:
+relative</code>, the top left of this node is used. Otherwise, you get the
+top left corner of the document.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p328f153ff3a314e3" name="p328f153ff3a314e3"> </a><a name="key37"></a><a name="key38"></a>One last aspect of DOM nodes that is
+fun to play with is their size. There are style types called <code>width</code>
+and <code>height</code>, which can be used to set the absolute size of an
+element.</p><pre class="code"><span class="variable">$</span>(<span class="string">"picture"</span>).<span class="property">style</span>.<span class="property">width</span> = <span class="string">"400px"</span>;
+<span class="variable">$</span>(<span class="string">"picture"</span>).<span class="property">style</span>.<span class="property">height</span> = <span class="string">"200px"</span>;</pre><p><a class="paragraph" href="#pcb511fd107a693c" name="pcb511fd107a693c"> </a>But, when you need to accurately set the size of an element, there is
+an tricky problem to take into account. Some browsers, in some
+circumstances, take these sizes to mean the outside size of the
+object, including any border and internal padding. Other browsers, in
+other circumstances, use the size of the space inside of the object
+instead, and do not count the width of borders and padding. Thus, if
+you set the size of an object that has a border or a padding, it will
+not always appear the same size.</p><p><a class="paragraph" href="#p772ec2613c5bed6e" name="p772ec2613c5bed6e"> </a>Fortunately, you can inspect the inner and outer size of a node,
+which, when you really need to accurately size something, can be used
+to compensate for browser behaviour. The <a name="key39"></a><code>offsetWidth</code> and
+<a name="key40"></a><code>offsetHeight</code> properties give you the outer size of your element
+(the space it takes up in the document), while the <a name="key41"></a><code>clientWidth</code> and
+<a name="key42"></a><code>clientHeight</code> properties give the space inside of it, if any.</p><pre class="code"><span class="variable">print</span>(<span class="string">"Outer size: "</span>, <span class="variable">$</span>(<span class="string">"picture"</span>).<span class="property">offsetWidth</span>,
+ <span class="string">" by "</span>, <span class="variable">$</span>(<span class="string">"picture"</span>).<span class="property">offsetHeight</span>, <span class="string">" pixels."</span>);
+<span class="variable">print</span>(<span class="string">"Inner size: "</span>, <span class="variable">$</span>(<span class="string">"picture"</span>).<span class="property">clientWidth</span>,
+ <span class="string">" by "</span>, <span class="variable">$</span>(<span class="string">"picture"</span>).<span class="property">clientHeight</span>, <span class="string">" pixels."</span>);</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p35b6eeb810806c1d" name="p35b6eeb810806c1d"> </a>If you've followed through with all the examples in this chapter, and
+maybe did a few extra things by yourself, you will have completely
+mutilated the poor little document that we started with. Now let me
+moralise for a moment and tell you that you do not want to do this to
+real pages. The temptation to add all kinds of moving bling-bling will
+at times be strong. Resist it, or your pages shall surely become
+unreadable or even, if you go far enough, induce the occasional
+seizure.</p></div><h1><span class="number">Chapter 13: </span>Browser Events</h1><div class="block"><p><a class="paragraph" href="#p516abb9a2e865690" name="p516abb9a2e865690"> </a>To add interesting functionality to a web-page, just being able to
+inspect or modify the document is generally not enough. We also need
+to be able to detect what the user is doing, and respond to it. For
+this, we will use a thing called <a name="key1"></a>event handlers. Pressed keys are
+events, mouse clicks are events, even mouse motion can be seen as a
+series of events. In <a href="chapter11.html">chapter 11</a>, we added an <code>onclick</code> property to a
+button, in order to do something when it was pressed. This is a simple
+event handler.</p><p><a class="paragraph" href="#p36415ead7203e803" name="p36415ead7203e803"> </a>The way browser events work is, fundamentally, very simple. It is
+possible to register handlers for specific event types and specific
+DOM nodes. Whenever an <a name="key2"></a>event occurs, the handler for that event, if
+any, is called. For some events, such as key presses, knowing just
+that the event occurred is not good enough, you also want to know
+which key was pressed. To store such information, every event creates
+an <a name="key3"></a>event object, which the handler can look at.</p><p><a class="paragraph" href="#p4052c5cacc6778f2" name="p4052c5cacc6778f2"> </a>It is important to realise that, even though events can fire at any
+time, no two handlers ever run at the same moment. If other JavaScript
+code is still running, the browser waits until it finishes before it
+calls the next handler. This also holds for code that is triggered in
+other ways, such as with <code>setTimeout</code>. In programmer jargon, browser
+JavaScript is <a name="key4"></a>single-threaded, there are never two '<a name="key5"></a>threads'
+running at the same time. This is, in most cases, a good thing. It is
+very easy to get strange results when multiple things happen at the
+same time.</p><p><a class="paragraph" href="#p720d0712e7504cad" name="p720d0712e7504cad"> </a>An event, when not handled, can 'bubble' through the DOM tree. What
+this means is that if you click on, for example, a link in a
+paragraph, any handlers associated with the link are called first. If
+there are no such handlers, or these handlers do not indicate that
+they have finished handling the event, the handlers for the paragraph,
+which is the parent of the link, are tried. After that, the handlers
+for <code>document.body</code> get a turn. Finally, if no JavaScript handlers
+have taken care of the event, the browser handles it. When clicking a
+link, this means that the link will be followed.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p435a5bc9218ad643" name="p435a5bc9218ad643"> </a>So, as you see, events are easy. The only hard thing about them is
+that browsers, while all supporting more or less the same
+functionality, support this functionality through different
+interfaces. As usual, the most incompatible browser is Internet
+Explorer, which ignores the standard that most other browsers follow.
+After that, there is Opera, which does not properly support some
+useful events, such as the <code>onunload</code> event which fires when leaving a
+page, and sometimes gives confusing information about keyboard events.</p><p><a class="paragraph" href="#p1ad840eebb96a094" name="p1ad840eebb96a094"> </a>There are four event-related actions one might want to take.</p><ul><li>Registering an event handler.</li><li>Getting the event object.</li><li>Extracting information from this object.</li><li>Signalling that an event has been handled.</li></ul><p><a class="paragraph" href="#p14d4e49cdd6c8701" name="p14d4e49cdd6c8701"> </a>None of them work the same across all major browsers.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p29f2f582b585c7f3" name="p29f2f582b585c7f3"> </a>As a practice field for our event-handling, we open a document with a
+button and a text field. Keep this window open (and attached) for the
+rest of the chapter.</p><pre class="code"><span class="variable">attach</span>(<span class="variable">window</span>.<span class="property">open</span>(<span class="string">"example_events.html"</span>));</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p4b8ef4f4dff9fe01" name="p4b8ef4f4dff9fe01"> </a>The first action, registering a handler, can be done by setting an
+element's <code>onclick</code> (or <code>onkeypress</code>, and so on) property. This does
+in fact work across browsers, but it has an important drawback ― you
+can only attach one handler to an element. Most of the time, one is
+enough, but there are cases, especially when a program has to be able
+to work together with other programs (which might also be adding
+handlers), that this is annoying.</p><p><a class="paragraph" href="#p53ab4448a79192fe" name="p53ab4448a79192fe"> </a><a name="key6"></a>In Internet Explorer, one can add a click handler to a
+button like this:</p><pre class="code invalid"><span class="variable">$</span>(<span class="string">"button"</span>).<span class="property">attachEvent</span>(<span class="string">"onclick"</span>, <span class="keyword">function</span>(){<span class="variable">print</span>(<span class="string">"Click!"</span>);});</pre><p><a class="paragraph" href="#p1a1c706bf5e7dd9" name="p1a1c706bf5e7dd9"> </a><a name="key7"></a>On the other browsers, it goes like this:</p><pre class="code invalid"><span class="variable">$</span>(<span class="string">"button"</span>).<span class="property">addEventListener</span>(<span class="string">"click"</span>, <span class="keyword">function</span>(){<span class="variable">print</span>(<span class="string">"Click!"</span>);},
+ <span class="atom">false</span>);</pre><p><a class="paragraph" href="#p6a1dc47cf5217450" name="p6a1dc47cf5217450"> </a>Note how <code>"on"</code> is left off in the second case. The third argument
+to <code>addEventListener</code>, <code>false</code>, indicates that the event should
+'bubble' through the DOM tree as normal. Giving <code>true</code> instead can be
+used to give this handler priority over the handlers 'beneath' it, but
+since Internet Explorer does not support such a thing, this is rarely
+useful.</p></div><hr/><div class="block"><a name="exercise1"></a><div class="exercisenum">Ex. 13.1</div><div class="exercise"><p><a class="paragraph" href="#p4f929b97df1c21e8" name="p4f929b97df1c21e8"> </a>Write a function called <code>registerEventHandler</code> to wrap the
+incompatibilities of these two models. It takes three arguments: first
+a DOM node that the handler should be attached to, then the name of
+the event type, such as <code>"click"</code> or <code>"keypress"</code>, and finally the
+handler function.</p><p><a class="paragraph" href="#p4955486507b38739" name="p4955486507b38739"> </a>To determine which method should be called, look for the methods
+themselves ― if the DOM node has a method called <code>attachEvent</code>, you
+may assume that this is the correct method. Note that this is much
+preferable to directly checking whether the browser is Internet
+Explorer. If a new browser arrives which uses Internet Explorer's
+model, or Internet Explorer suddenly switches to the standard model,
+the code will still work. Both are rather unlikely, of course, but
+doing something in a smart way never hurts.</p></div><div class="solution"><pre class="code"><span class="keyword">function</span> <span class="variable">registerEventHandler</span>(<span class="variabledef">node</span>, <span class="variabledef">event</span>, <span class="variabledef">handler</span>) {
+ <span class="keyword">if</span> (typeof <span class="localvariable">node</span>.<span class="property">addEventListener</span> == <span class="string">"function"</span>)
+ <span class="localvariable">node</span>.<span class="property">addEventListener</span>(<span class="localvariable">event</span>, <span class="localvariable">handler</span>, <span class="atom">false</span>);
+ <span class="keyword">else</span>
+ <span class="localvariable">node</span>.<span class="property">attachEvent</span>(<span class="string">"on"</span> + <span class="localvariable">event</span>, <span class="localvariable">handler</span>);
+}
+
+<span class="variable">registerEventHandler</span>(<span class="variable">$</span>(<span class="string">"button"</span>), <span class="string">"click"</span>,
+ <span class="keyword">function</span>(){<span class="variable">print</span>(<span class="string">"Click (2)"</span>);});</pre><p><a class="paragraph" href="#p15573e9bf4a50775" name="p15573e9bf4a50775"> </a>Don't fret about the long, clumsy name. Later on, we will have to add
+an extra wrapper to wrap this wrapper, and it will have a shorter
+name.</p><p><a class="paragraph" href="#p78adb8f0dce1437b" name="p78adb8f0dce1437b"> </a>It is also possible to do this check only once, and define
+<code>registerEventHandler</code> to hold a different function depending on the
+browser. This is more efficient, but a little strange.</p><pre class="code"><span class="keyword">if</span> (typeof <span class="variable">document</span>.<span class="property">addEventListener</span> == <span class="string">"function"</span>)
+ <span class="keyword">var</span> <span class="variable">registerEventHandler</span> = <span class="keyword">function</span>(<span class="variabledef">node</span>, <span class="variabledef">event</span>, <span class="variabledef">handler</span>) {
+ <span class="localvariable">node</span>.<span class="property">addEventListener</span>(<span class="localvariable">event</span>, <span class="localvariable">handler</span>, <span class="atom">false</span>);
+ };
+<span class="keyword">else</span>
+ <span class="keyword">var</span> <span class="variable">registerEventHandler</span> = <span class="keyword">function</span>(<span class="variabledef">node</span>, <span class="variabledef">event</span>, <span class="variabledef">handler</span>) {
+ <span class="localvariable">node</span>.<span class="property">attachEvent</span>(<span class="string">"on"</span> + <span class="localvariable">event</span>, <span class="localvariable">handler</span>);
+ };</pre></div></div><hr/><div class="block"><p><a class="paragraph" href="#p643d3dda1cb19245" name="p643d3dda1cb19245"> </a>Removing events works very much like adding them, but this time the
+methods <a name="key8"></a><code>detachEvent</code> and <a name="key9"></a><code>removeEventListener</code> are used. Note
+that, to remove a handler, you need to have access to the function you
+attached to it.</p><pre class="code"><span class="keyword">function</span> <span class="variable">unregisterEventHandler</span>(<span class="variabledef">node</span>, <span class="variabledef">event</span>, <span class="variabledef">handler</span>) {
+ <span class="keyword">if</span> (typeof <span class="localvariable">node</span>.<span class="property">removeEventListener</span> == <span class="string">"function"</span>)
+ <span class="localvariable">node</span>.<span class="property">removeEventListener</span>(<span class="localvariable">event</span>, <span class="localvariable">handler</span>, <span class="atom">false</span>);
+ <span class="keyword">else</span>
+ <span class="localvariable">node</span>.<span class="property">detachEvent</span>(<span class="string">"on"</span> + <span class="localvariable">event</span>, <span class="localvariable">handler</span>);
+}</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p79feb4226ccdc648" name="p79feb4226ccdc648"> </a>Exceptions produced by event handlers can, because of technical
+limitations, not be caught by the console. Thus, they are handled by
+the browser, which might mean they get hidden in some kind of 'error
+console' somewhere, or cause a message to pop up. When you write an
+event handler and it does not seem to work, it might be silently
+aborting because it causes some kind of error.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p3fc97834f2fb9c39" name="p3fc97834f2fb9c39"> </a><a name="key10"></a>Most browsers pass the <a name="key11"></a>event object as an argument to the
+handler. Internet Explorer stores it in the top-level variable called
+<code>event</code>. When looking at JavaScript code, you will often come across
+something like <code>event || window.event</code>, which takes the local variable
+<code>event</code> or, if that is undefined, the top-level variable by that same
+name.</p><pre class="code"><span class="keyword">function</span> <span class="variable">showEvent</span>(<span class="variabledef">event</span>) {
+ <span class="variable">show</span>(<span class="localvariable">event</span> || <span class="variable">window</span>.<span class="property">event</span>);
+}
+
+<span class="variable">registerEventHandler</span>(<span class="variable">$</span>(<span class="string">"textfield"</span>), <span class="string">"keypress"</span>, <span class="variable">showEvent</span>);</pre><p><a class="paragraph" href="#p1e85731019f5211" name="p1e85731019f5211"> </a>Type a few characters in the field, look at the objects, and shut it
+up again:</p><pre class="code"><span class="variable">unregisterEventHandler</span>(<span class="variable">$</span>(<span class="string">"textfield"</span>), <span class="string">"keypress"</span>, <span class="variable">showEvent</span>);</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p4b98195aa6c52a84" name="p4b98195aa6c52a84"> </a><a name="key12"></a><a name="key13"></a><a name="key14"></a><a name="key15"></a>When the user
+clicks his mouse, three events are generated. First <a name="key16"></a><code>mousedown</code>, at
+the moment the mouse button is pressed. Then, <a name="key17"></a><code>mouseup</code>, at the
+moment it is released. And finally, <a name="key18"></a><code>click</code>, to indicate something
+was clicked. When this happens two times in quick succession, a
+<a name="key19"></a><code>dblclick</code> (double-click) event is also generated. Note that it is
+possible for the <code>mousedown</code> and <code>mouseup</code> events to happen some time
+apart ― when the mouse button is held for a while.</p><p><a class="paragraph" href="#p6f732069cb906b8" name="p6f732069cb906b8"> ¶ </a>When you attach an event handler to, for example, a button, the fact
+that it has been clicked is often all you need to know. When the
+handler, on the other hand, is attached to a node that has children,
+clicks from the children will 'bubble' up to it, and you will want to
+find out which child has been clicked. For this purpose, event objects
+have a property called <a name="key20"></a><code>target</code>... or <code>srcElement</code>, depending on the
+browser.</p><p><a class="paragraph" href="#pc23ad6b90cac8aa" name="pc23ad6b90cac8aa"> </a><a name="key21"></a><a name="key22"></a>Another interesting piece of information
+are the precise coordinates at which the click occurred. Event objects
+related to the mouse contain <a name="key23"></a><code>clientX</code> and <a name="key24"></a><code>clientY</code> properties,
+which give the <code>x</code> and <code>y</code> coordinates of the mouse, in pixels, on the
+screen. Documents can scroll, though, so often these coordinates do
+not tell us much about the part of the document that the mouse is
+over. Some browsers provide <a name="key25"></a><code>pageX</code> and <a name="key26"></a><code>pageY</code> properties for
+this purpose, but others (guess which) do not. Fortunately, the
+information about the amount of pixels the document has been scrolled
+can be found in <code>document.body.scrollLeft</code> and
+<code>document.body.scrollTop</code>.</p><p><a class="paragraph" href="#p62cd9eb170cc7708" name="p62cd9eb170cc7708"> </a>This handler, attached to the whole document, intercepts all mouse
+clicks, and prints some information about them.</p><pre class="code"><span class="keyword">function</span> <span class="variable">reportClick</span>(<span class="variabledef">event</span>) {
+ <span class="localvariable">event</span> = <span class="localvariable">event</span> || <span class="variable">window</span>.<span class="property">event</span>;
+ <span class="keyword">var</span> <span class="variabledef">target</span> = <span class="localvariable">event</span>.<span class="property">target</span> || <span class="localvariable">event</span>.<span class="property">srcElement</span>;
+ <span class="keyword">var</span> <span class="variabledef">pageX</span> = <span class="localvariable">event</span>.<span class="property">pageX</span>, <span class="variabledef">pageY</span> = <span class="localvariable">event</span>.<span class="property">pageY</span>;
+ <span class="keyword">if</span> (<span class="localvariable">pageX</span> == <span class="atom">undefined</span>) {
+ <span class="localvariable">pageX</span> = <span class="localvariable">event</span>.<span class="property">clientX</span> + <span class="variable">document</span>.<span class="property">body</span>.<span class="property">scrollLeft</span>;
+ <span class="localvariable">pageY</span> = <span class="localvariable">event</span>.<span class="property">clientY</span> + <span class="variable">document</span>.<span class="property">body</span>.<span class="property">scrollTop</span>;
+ }
+
+ <span class="variable">print</span>(<span class="string">"Mouse clicked at "</span>, <span class="localvariable">pageX</span>, <span class="string">", "</span>, <span class="localvariable">pageY</span>,
+ <span class="string">". Inside element:"</span>);
+ <span class="variable">show</span>(<span class="localvariable">target</span>);
+}
+<span class="variable">registerEventHandler</span>(<span class="variable">document</span>, <span class="string">"click"</span>, <span class="variable">reportClick</span>);</pre><p><a class="paragraph" href="#p2177351b46809e6c" name="p2177351b46809e6c"> </a>And get rid of it again:</p><pre class="code"><span class="variable">unregisterEventHandler</span>(<span class="variable">document</span>, <span class="string">"click"</span>, <span class="variable">reportClick</span>);</pre><p><a class="paragraph" href="#p283f8f76889606e0" name="p283f8f76889606e0"> </a>Obviously, writing all these checks and workarounds is not something
+you want to do in every single event handler. In a moment, after we
+have gotten acquainted with a few more incompatibilities, we will
+write a function to 'normalise' event objects to work the same across
+browsers.</p><p><a class="paragraph" href="#p4adb1a1ccca12b17" name="p4adb1a1ccca12b17"> </a>It is also sometimes possible to find out which mouse button was
+pressed, using the <a name="key27"></a><code>which</code> and <a name="key28"></a><code>button</code> properties of event
+objects. Unfortunately, this is very unreliable ― some browsers
+pretend mouses have only one button, others report right-clicks as
+clicks during which the control key was held down, and so on.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p66c3fec7a30a209f" name="p66c3fec7a30a209f"> </a><a name="key29"></a><a name="key30"></a><a name="key31"></a>Apart from clicks, we
+might also be interested in the movement of the mouse. The
+<a name="key32"></a><code>mousemove</code> event of a DOM node is fired whenever the mouse moves
+while it is over that element. There are also <a name="key33"></a><code>mouseover</code> and
+<a name="key34"></a><code>mouseout</code>, which are fired only when the mouse enters or leaves a
+node. For events of this last type, the <code>target</code> (or <code>srcElement</code>)
+property points at the node that the event is fired for, while the
+<a name="key35"></a><code>relatedTarget</code> (or <code>toElement</code>, or <code>fromElement</code>) property gives
+the node that the mouse came from (for <code>mouseover</code>) or left to (for
+<code>mouseout</code>).</p><p><a class="paragraph" href="#p56a60965be9b927d" name="p56a60965be9b927d"> </a><code>mouseover</code> and <code>mouseout</code> can be tricky when they are registered on
+an element that has child nodes. Events fired for the child nodes will
+bubble up to the parent element, so you will also see a <code>mouseover</code>
+event when the mouse enters one of the child nodes. The <code>target</code> and
+<code>relatedTarget</code> properties can be used to detect (and ignore) such
+events.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p22a094298f9e2915" name="p22a094298f9e2915"> </a><a name="key36"></a><a name="key37"></a><a name="key38"></a>For every key that the user
+presses, three events are generated: <a name="key39"></a><code>keydown</code>, <a name="key40"></a><code>keyup</code>, and
+<a name="key41"></a><code>keypress</code>. In general, you should use the first two in cases where
+you really want to know which key was pressed, for example when you
+want to do something when the arrow keys are pressed. <code>keypress</code>, on
+the other hand, is to be used when you are interested in the character
+that is being typed. The reason for this is that there is often no
+character information in <code>keyup</code> and <code>keydown</code> events, and Internet
+Explorer does not generate a <code>keypress</code> event at all for special keys
+such as the arrow keys.</p><p><a class="paragraph" href="#p40cc1d688c4f47e9" name="p40cc1d688c4f47e9"> </a>Finding out which key was pressed can be quite a challenge by itself.
+For <code>keydown</code> and <code>keyup</code> events, the event object will have a
+<a name="key42"></a><code>keyCode</code> property, which contains a number. Most of the time, these
+codes can be used to identify keys in a reasonably browser-independent
+way. Finding out which code corresponds to which key can be done by
+simple experiments...</p><pre class="code"><span class="keyword">function</span> <span class="variable">printKeyCode</span>(<span class="variabledef">event</span>) {
+ <span class="localvariable">event</span> = <span class="localvariable">event</span> || <span class="variable">window</span>.<span class="property">event</span>;
+ <span class="variable">print</span>(<span class="string">"Key "</span>, <span class="localvariable">event</span>.<span class="property">keyCode</span>, <span class="string">" was pressed."</span>);
+}
+
+<span class="variable">registerEventHandler</span>(<span class="variable">$</span>(<span class="string">"textfield"</span>), <span class="string">"keydown"</span>, <span class="variable">printKeyCode</span>);</pre><pre class="code"><span class="variable">unregisterEventHandler</span>(<span class="variable">$</span>(<span class="string">"textfield"</span>), <span class="string">"keydown"</span>, <span class="variable">printKeyCode</span>);</pre><p><a class="paragraph" href="#p7350f32959d12e73" name="p7350f32959d12e73"> </a>In most browsers, a single key code corresponds to a single <em>physical</em>
+key on your keyboard. The Opera browser, however, will generate
+different key codes for some keys depending on whether shift is
+pressed or not. Even worse, some of these shift-is-pressed codes are
+the same codes that are also used for other keys ― shift-9, which on
+most keyboards is used to type a parenthesis, gets the same code as
+the down arrow, and as such is hard to distinguish from it. When this
+threatens to sabotage your programs, you can usually resolve it by
+ignoring key events that have shift pressed.</p><p><a class="paragraph" href="#p7156fdbb9be9c4ab" name="p7156fdbb9be9c4ab"> </a>To find out whether the shift, control, or alt key was held during a
+key or mouse event, you can look at the <a name="key43"></a><code>shiftKey</code>, <a name="key44"></a><code>ctrlKey</code>, and
+<a name="key45"></a><code>altKey</code> properties of the event object.</p><p><a class="paragraph" href="#p40895e8835cd0c5d" name="p40895e8835cd0c5d"> </a>For <code>keypress</code> events, you will want to know which character was
+typed. The event object will have a <a name="key46"></a><code>charCode</code> property, which, if
+you are lucky, contains the <a name="key47"></a>Unicode number corresponding to the
+character that was typed, which can be converted to a 1-character
+string by using <a name="key48"></a><code>String.fromCharCode</code>. Unfortunately, some browsers
+do not define this property, or define it as <code>0</code>, and store the
+character code in the <a name="key49"></a><code>keyCode</code> property instead.</p><pre class="code"><span class="keyword">function</span> <span class="variable">printCharacter</span>(<span class="variabledef">event</span>) {
+ <span class="localvariable">event</span> = <span class="localvariable">event</span> || <span class="variable">window</span>.<span class="property">event</span>;
+ <span class="keyword">var</span> <span class="variabledef">charCode</span> = <span class="localvariable">event</span>.<span class="property">charCode</span>;
+ <span class="keyword">if</span> (<span class="localvariable">charCode</span> == <span class="atom">undefined</span> || <span class="localvariable">charCode</span> === <span class="atom">0</span>)
+ <span class="localvariable">charCode</span> = <span class="localvariable">event</span>.<span class="property">keyCode</span>;
+ <span class="variable">print</span>(<span class="string">"Character '"</span>, <span class="variable">String</span>.<span class="property">fromCharCode</span>(<span class="localvariable">charCode</span>), <span class="string">"'"</span>);
+}
+
+<span class="variable">registerEventHandler</span>(<span class="variable">$</span>(<span class="string">"textfield"</span>), <span class="string">"keypress"</span>, <span class="variable">printCharacter</span>);</pre><pre class="code"><span class="variable">unregisterEventHandler</span>(<span class="variable">$</span>(<span class="string">"textfield"</span>), <span class="string">"keypress"</span>, <span class="variable">printCharacter</span>);</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p5ac14b0f042b3dc0" name="p5ac14b0f042b3dc0"> </a>An event handler can 'stop' the event it is handling. There are two
+different ways to do this. You can prevent the event from bubbling up
+to parent nodes and the handlers defined on those, and you can prevent
+the browser from taking the standard action associated with such an
+event. It should be noted that browsers do not always follow this ―
+preventing the default behaviour for the pressing of certain 'hotkeys'
+will, on many browsers, not actually keep the browser from executing
+the normal effect of these keys.</p><p><a class="paragraph" href="#p380482a2b001f697" name="p380482a2b001f697"> </a>On most browsers, stopping event bubbling is done with the
+<a name="key50"></a><code>stopPropagation</code> method of the event object, and preventing default
+behaviour is done with the <a name="key51"></a><code>preventDefault</code> method. For Internet
+Explorer, this is done by setting the <a name="key52"></a><code>cancelBubble</code> property of
+this object to <code>true</code>, and the <a name="key53"></a><code>returnValue</code> property to <code>false</code>,
+respectively.</p><p><a class="paragraph" href="#pb67f76098fd7410" name="pb67f76098fd7410"> </a>And that was the last of the long list of incompatibilities that we
+will discuss in this chapter. Which means that we can finally write
+the event normaliser function and move on to more interesting things.</p><pre class="code"><span class="keyword">function</span> <span class="variable">normaliseEvent</span>(<span class="variabledef">event</span>) {
+ <span class="keyword">if</span> (!<span class="localvariable">event</span>.<span class="property">stopPropagation</span>) {
+ <span class="localvariable">event</span>.<span class="property">stopPropagation</span> = <span class="keyword">function</span>() {<span class="localvariable">this</span>.<span class="property">cancelBubble</span> = <span class="atom">true</span>;};
+ <span class="localvariable">event</span>.<span class="property">preventDefault</span> = <span class="keyword">function</span>() {<span class="localvariable">this</span>.<span class="property">returnValue</span> = <span class="atom">false</span>;};
+ }
+ <span class="keyword">if</span> (!<span class="localvariable">event</span>.<span class="property">stop</span>) {
+ <span class="localvariable">event</span>.<span class="property">stop</span> = <span class="keyword">function</span>() {
+ <span class="localvariable">this</span>.<span class="property">stopPropagation</span>();
+ <span class="localvariable">this</span>.<span class="property">preventDefault</span>();
+ };
+ }
+
+ <span class="keyword">if</span> (<span class="localvariable">event</span>.<span class="property">srcElement</span> && !<span class="localvariable">event</span>.<span class="property">target</span>)
+ <span class="localvariable">event</span>.<span class="property">target</span> = <span class="localvariable">event</span>.<span class="property">srcElement</span>;
+ <span class="keyword">if</span> ((<span class="localvariable">event</span>.<span class="property">toElement</span> || <span class="localvariable">event</span>.<span class="property">fromElement</span>) && !<span class="localvariable">event</span>.<span class="property">relatedTarget</span>)
+ <span class="localvariable">event</span>.<span class="property">relatedTarget</span> = <span class="localvariable">event</span>.<span class="property">toElement</span> || <span class="localvariable">event</span>.<span class="property">fromElement</span>;
+ <span class="keyword">if</span> (<span class="localvariable">event</span>.<span class="property">clientX</span> != <span class="atom">undefined</span> && <span class="localvariable">event</span>.<span class="property">pageX</span> == <span class="atom">undefined</span>) {
+ <span class="localvariable">event</span>.<span class="property">pageX</span> = <span class="localvariable">event</span>.<span class="property">clientX</span> + <span class="variable">document</span>.<span class="property">body</span>.<span class="property">scrollLeft</span>;
+ <span class="localvariable">event</span>.<span class="property">pageY</span> = <span class="localvariable">event</span>.<span class="property">clientY</span> + <span class="variable">document</span>.<span class="property">body</span>.<span class="property">scrollTop</span>;
+ }
+ <span class="keyword">if</span> (<span class="localvariable">event</span>.<span class="property">type</span> == <span class="string">"keypress"</span>) {
+ <span class="keyword">if</span> (<span class="localvariable">event</span>.<span class="property">charCode</span> === <span class="atom">0</span> || <span class="localvariable">event</span>.<span class="property">charCode</span> == <span class="atom">undefined</span>)
+ <span class="localvariable">event</span>.<span class="property">character</span> = <span class="variable">String</span>.<span class="property">fromCharCode</span>(<span class="localvariable">event</span>.<span class="property">keyCode</span>);
+ <span class="keyword">else</span>
+ <span class="localvariable">event</span>.<span class="property">character</span> = <span class="variable">String</span>.<span class="property">fromCharCode</span>(<span class="localvariable">event</span>.<span class="property">charCode</span>);
+ }
+
+ <span class="keyword">return</span> <span class="localvariable">event</span>;
+}</pre><p><a class="paragraph" href="#p40286c84b5d3f72b" name="p40286c84b5d3f72b"> </a>A <a name="key54"></a><code>stop</code> method is added, which cancels both the bubbling and
+the default action of the event. Some browsers already provide this,
+in which case we leave it as it is.</p><p><a class="paragraph" href="#p5fb19f529da455d6" name="p5fb19f529da455d6"> </a>Next we can write convenient wrappers for <code>registerEventHandler</code> and
+<code>unregisterEventHandler</code>:</p><pre class="code"><span class="keyword">function</span> <span class="variable">addHandler</span>(<span class="variabledef">node</span>, <span class="variabledef">type</span>, <span class="variabledef">handler</span>) {
+ <span class="keyword">function</span> <span class="variabledef">wrapHandler</span>(<span class="variabledef">event</span>) {
+ <span class="localvariable">handler</span>(<span class="variable">normaliseEvent</span>(<span class="localvariable">event</span> || <span class="variable">window</span>.<span class="property">event</span>));
+ }
+ <span class="variable">registerEventHandler</span>(<span class="localvariable">node</span>, <span class="localvariable">type</span>, <span class="localvariable">wrapHandler</span>);
+ <span class="keyword">return</span> {<span class="property">node</span>: <span class="localvariable">node</span>, <span class="property">type</span>: <span class="localvariable">type</span>, <span class="property">handler</span>: <span class="localvariable">wrapHandler</span>};
+}
+
+<span class="keyword">function</span> <span class="variable">removeHandler</span>(<span class="variabledef">object</span>) {
+ <span class="variable">unregisterEventHandler</span>(<span class="localvariable">object</span>.<span class="property">node</span>, <span class="localvariable">object</span>.<span class="property">type</span>, <span class="localvariable">object</span>.<span class="property">handler</span>);
+}
+
+<span class="keyword">var</span> <span class="variable">blockQ</span> = <span class="variable">addHandler</span>(<span class="variable">$</span>(<span class="string">"textfield"</span>), <span class="string">"keypress"</span>, <span class="keyword">function</span>(<span class="variabledef">event</span>) {
+ <span class="keyword">if</span> (<span class="localvariable">event</span>.<span class="property">character</span>.<span class="property">toLowerCase</span>() == <span class="string">"q"</span>)
+ <span class="localvariable">event</span>.<span class="property">stop</span>();
+});</pre><p><a class="paragraph" href="#p10b06183662315ec" name="p10b06183662315ec"> </a>The new <code>addHandler</code> function wraps the handler function it is given
+in a new function, so it can take care of normalising the event
+objects. It returns an object that can be given to <code>removeHandler</code>
+when we want to remove this specific handler. Try typing a '<code>q</code>' in
+the text field.</p><pre class="code"><span class="variable">removeHandler</span>(<span class="variable">blockQ</span>);</pre></div><hr/><div class="block"><p><a class="paragraph" href="#pee867787a173854" name="pee867787a173854"> </a>Armed with <code>addHandler</code> and the <code>dom</code> function from the last chapter,
+we are ready for more challenging feats of document-manipulation. As
+an exercise, we will implement the game known as <a name="key55"></a>Sokoban. This is
+something of a classic, but you may not have seen it before. The rules
+are this: There is a grid, made up of walls, empty space, and one or
+more 'exits'. On this grid, there are a number of crates or stones,
+and a little dude that the player controls. This dude can be moved
+horizontally and vertically into empty squares, and can push the
+boulders around, provided that there is empty space behind them. The
+goal of the game is to move a given number of boulders into the exits.</p><p><a class="paragraph" href="#p234fe283b2505365" name="p234fe283b2505365"> </a>Just like the terraria from <a href="chapter8.html">chapter 8</a>, a Sokoban level can be represented
+as text. The variable <code>sokobanLevels</code>, in the <code>example_events.html</code>
+window, contains an array of level objects. Each level has a property
+<code>field</code>, containing a textual representation of the level, and a
+property <code>boulders</code>, indicating the amount of boulders that must be
+expelled to finish the level.</p><pre class="code"><span class="variable">show</span>(<span class="variable">sokobanLevels</span>.<span class="property">length</span>);
+<span class="variable">show</span>(<span class="variable">sokobanLevels</span>[<span class="atom">1</span>].<span class="property">boulders</span>);
+<span class="variable">forEach</span>(<span class="variable">sokobanLevels</span>[<span class="atom">1</span>].<span class="property">field</span>, <span class="variable">print</span>);</pre><p><a class="paragraph" href="#p24d3da5c0f84c174" name="p24d3da5c0f84c174"> </a>In such a level, the <code>#</code> characters are walls, spaces are empty
+squares, <code>0</code> characters are used for for boulders, an <code>@</code> for the
+starting location of the player, and a <code>*</code> for the exit.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p47ecdfa2370825d1" name="p47ecdfa2370825d1"> </a>But, when playing the game, we do not want to be looking at this
+textual representation. Instead, we will put a <a name="key56"></a>table into the
+document. I made small <a name="key57"></a>style-sheet (<a href="css/sokoban.css">sokoban.css</a>,
+if you are curious what it looks like) to give the cells of this table
+a fixed square size, and added it to the example document. Each of the
+cells in this table will get a background image, representing the type
+of the square (empty, wall, or exit). To show the location of the
+player and the boulders, images are added to these table cells, and
+moved to different cells as appropriate.</p><p><a class="paragraph" href="#p35344ca902c88e34" name="p35344ca902c88e34"> </a>It would be possible to use this table as the main representation of
+our data ― when we want to look whether there is a wall in a given
+square, we just inspect the background of the appropriate table cell,
+and to find the player, we just search for the image node with the
+correct <code>src</code> property. In some cases, this approach is practical, but
+for this program I chose to keep a separate data structure for the
+grid, because it makes things much more straightforward.</p><p><a class="paragraph" href="#p44bf042ee9cbbcb6" name="p44bf042ee9cbbcb6"> </a>This data structure is a two-dimensional grid of objects, representing
+the squares of the playing field. Each of the objects must store the
+type of background it has and whether there is a boulder or player
+present in that cell. It should also contain a reference to the table
+cell that is used to display it in the document, to make it easy to
+move images in and out of this table cell.</p><p><a class="paragraph" href="#p7ae97e5f7cf79a44" name="p7ae97e5f7cf79a44"> ¶ </a>That gives us two kinds of objects ― one to hold the grid of the
+playing field, and one to represent the individual cells in this grid.
+If we want the game to also do things like moving the next level at
+the appropriate moment, and being able to reset the current level when
+you mess up, we will also need a 'controller' object, which creates or
+removes the field objects at the appropriate moment. For convenience,
+we will be using the prototype approach outlined at the end of <a href="chapter8.html">chapter 8</a>,
+so object types are just prototypes, and the <code>create</code> method, rather
+than the <code>new</code> operator, is used to make new objects.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p5e757dc49c1d8b9e" name="p5e757dc49c1d8b9e"> </a>Let us start with the objects representing the squares of the game's
+field. They are responsible for setting the background of their cells
+correctly, and adding images as appropriate. The <code>img/sokoban/</code>
+directory contains a set of images, based on another ancient game,
+which will be used to visualise the game. For a start, the <code>Square</code>
+prototype could look like this.</p><pre class="code"><span class="keyword">var</span> <span class="variable">Square</span> = {
+ <span class="property">construct</span>: <span class="keyword">function</span>(<span class="variabledef">character</span>, <span class="variabledef">tableCell</span>) {
+ <span class="localvariable">this</span>.<span class="property">background</span> = <span class="string">"empty"</span>;
+ <span class="keyword">if</span> (<span class="localvariable">character</span> == <span class="string">"#"</span>)
+ <span class="localvariable">this</span>.<span class="property">background</span> = <span class="string">"wall"</span>;
+ <span class="keyword">else</span> <span class="keyword">if</span> (<span class="localvariable">character</span> == <span class="string">"*"</span>)
+ <span class="localvariable">this</span>.<span class="property">background</span> = <span class="string">"exit"</span>;
+
+ <span class="localvariable">this</span>.<span class="property">tableCell</span> = <span class="localvariable">tableCell</span>;
+ <span class="localvariable">this</span>.<span class="property">tableCell</span>.<span class="property">className</span> = <span class="localvariable">this</span>.<span class="property">background</span>;
+
+ <span class="localvariable">this</span>.<span class="property">content</span> = <span class="atom">null</span>;
+ <span class="keyword">if</span> (<span class="localvariable">character</span> == <span class="string">"0"</span>)
+ <span class="localvariable">this</span>.<span class="property">content</span> = <span class="string">"boulder"</span>;
+ <span class="keyword">else</span> <span class="keyword">if</span> (<span class="localvariable">character</span> == <span class="string">"@"</span>)
+ <span class="localvariable">this</span>.<span class="property">content</span> = <span class="string">"player"</span>;
+
+ <span class="keyword">if</span> (<span class="localvariable">this</span>.<span class="property">content</span> != <span class="atom">null</span>) {
+ <span class="keyword">var</span> <span class="variabledef">image</span> = <span class="variable">dom</span>(<span class="string">"IMG"</span>, {<span class="property">src</span>: <span class="string">"img/sokoban/"</span> +
+ <span class="localvariable">this</span>.<span class="property">content</span> + <span class="string">".gif"</span>});
+ <span class="localvariable">this</span>.<span class="property">tableCell</span>.<span class="property">appendChild</span>(<span class="localvariable">image</span>);
+ }
+ },
+
+ <span class="property">hasPlayer</span>: <span class="keyword">function</span>() {
+ <span class="keyword">return</span> <span class="localvariable">this</span>.<span class="property">content</span> == <span class="string">"player"</span>;
+ },
+ <span class="property">hasBoulder</span>: <span class="keyword">function</span>() {
+ <span class="keyword">return</span> <span class="localvariable">this</span>.<span class="property">content</span> == <span class="string">"boulder"</span>;
+ },
+ <span class="property">isEmpty</span>: <span class="keyword">function</span>() {
+ <span class="keyword">return</span> <span class="localvariable">this</span>.<span class="property">content</span> == <span class="atom">null</span> && <span class="localvariable">this</span>.<span class="property">background</span> == <span class="string">"empty"</span>;
+ },
+ <span class="property">isExit</span>: <span class="keyword">function</span>() {
+ <span class="keyword">return</span> <span class="localvariable">this</span>.<span class="property">background</span> == <span class="string">"exit"</span>;
+ }
+};
+
+<span class="keyword">var</span> <span class="variable">testSquare</span> = <span class="variable">Square</span>.<span class="property">create</span>(<span class="string">"@"</span>, <span class="variable">dom</span>(<span class="string">"TD"</span>));
+<span class="variable">show</span>(<span class="variable">testSquare</span>.<span class="property">hasPlayer</span>());</pre><p><a class="paragraph" href="#p707dcafe258fa48" name="p707dcafe258fa48"> </a>The <code>character</code> argument to the constructor will be used to transform
+characters from the level blueprints into actual <code>Square</code> objects. To
+set the background of the cells, style-sheet classes are used (defined
+in <a href="css/sokoban.css">sokoban.css</a>), which are assigned to the <code>td</code>
+elements' <code>className</code> property.</p><p><a class="paragraph" href="#p2a57901f2f328f59" name="p2a57901f2f328f59"> </a>The methods like <code>hasPlayer</code> and <code>isEmpty</code> are a way to 'isolate' the
+code that uses objects of this type from the internals of the objects.
+They are not strictly necessary in this case, but they will make the
+other code look better.</p></div><hr/><div class="block"><a name="exercise2"></a><div class="exercisenum">Ex. 13.2</div><div class="exercise"><p><a class="paragraph" href="#p58996516543d0e5f" name="p58996516543d0e5f"> </a>Add methods <code>moveContent</code> and <code>clearContent</code> to the <code>Square</code>
+prototype. The first one takes another <code>Square</code> object as an argument,
+and moves the content of the <code>this</code> square into the argument by
+updating the <code>content</code> properties and moving the image node associated
+with this content. This will be used to move boulders and players
+around the grid. It may assume the square is not currently empty.
+<code>clearContent</code> removes the content from the square without moving it
+anywhere. Note that the <code>content</code> property for empty squares contains
+<code>null</code>.</p><p><a class="paragraph" href="#p9bc948783f82b2c" name="p9bc948783f82b2c"> </a>The <code>removeElement</code> function we defined in <a href="chapter12.html">chapter 12</a> is available in this
+chapter too, for your node-removing convenience. You may assume that
+the images are the only child nodes of the table cells, and can thus
+be reached through, for example, <code>this.tableCell.lastChild</code>.</p></div><div class="solution"><pre class="code"><span class="variable">Square</span>.<span class="property">moveContent</span> = <span class="keyword">function</span>(<span class="variabledef">target</span>) {
+ <span class="localvariable">target</span>.<span class="property">content</span> = <span class="localvariable">this</span>.<span class="property">content</span>;
+ <span class="localvariable">this</span>.<span class="property">content</span> = <span class="atom">null</span>;
+ <span class="localvariable">target</span>.<span class="property">tableCell</span>.<span class="property">appendChild</span>(<span class="localvariable">this</span>.<span class="property">tableCell</span>.<span class="property">lastChild</span>);
+};
+<span class="variable">Square</span>.<span class="property">clearContent</span> = <span class="keyword">function</span>() {
+ <span class="localvariable">this</span>.<span class="property">content</span> = <span class="atom">null</span>;
+ <span class="variable">removeElement</span>(<span class="localvariable">this</span>.<span class="property">tableCell</span>.<span class="property">lastChild</span>);
+};</pre></div></div><hr/><div class="block"><p><a class="paragraph" href="#p1773b9d99848aef3" name="p1773b9d99848aef3"> </a>The next object type will be called <code>SokobanField</code>. Its constructor is
+given an object from the <code>sokobanLevels</code> array, and is responsible for
+building both a table of DOM nodes and a grid of <code>Square</code> objects.
+This object will also take care of the details of moving the player
+and boulders around, through a <code>move</code> method that is given an argument
+indicating which way the player wants to move.</p><p><a class="paragraph" href="#p70f3c7243a2d101e" name="p70f3c7243a2d101e"> </a>To identify the individual squares, and to indicate directions, we
+will again use the <code>Point</code> object type from <a href="chapter8.html">chapter 8</a>, which, as you might
+remember, has an <code>add</code> method.</p><p><a class="paragraph" href="#p796a6f5325ce8f2d" name="p796a6f5325ce8f2d"> </a>The base of the field prototype looks like this:</p><pre class="code"><span class="keyword">var</span> <span class="variable">SokobanField</span> = {
+ <span class="property">construct</span>: <span class="keyword">function</span>(<span class="variabledef">level</span>) {
+ <span class="keyword">var</span> <span class="variabledef">tbody</span> = <span class="variable">dom</span>(<span class="string">"TBODY"</span>);
+ <span class="localvariable">this</span>.<span class="property">squares</span> = [];
+ <span class="localvariable">this</span>.<span class="property">bouldersToGo</span> = <span class="localvariable">level</span>.<span class="property">boulders</span>;
+
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variabledef">y</span> = <span class="atom">0</span>; <span class="localvariable">y</span> < <span class="localvariable">level</span>.<span class="property">field</span>.<span class="property">length</span>; <span class="localvariable">y</span>++) {
+ <span class="keyword">var</span> <span class="variabledef">line</span> = <span class="localvariable">level</span>.<span class="property">field</span>[<span class="localvariable">y</span>];
+ <span class="keyword">var</span> <span class="variabledef">tableRow</span> = <span class="variable">dom</span>(<span class="string">"TR"</span>);
+ <span class="keyword">var</span> <span class="variabledef">squareRow</span> = [];
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variabledef">x</span> = <span class="atom">0</span>; <span class="localvariable">x</span> < <span class="localvariable">line</span>.<span class="property">length</span>; <span class="localvariable">x</span>++) {
+ <span class="keyword">var</span> <span class="variabledef">tableCell</span> = <span class="variable">dom</span>(<span class="string">"TD"</span>);
+ <span class="localvariable">tableRow</span>.<span class="property">appendChild</span>(<span class="localvariable">tableCell</span>);
+ <span class="keyword">var</span> <span class="variabledef">square</span> = <span class="variable">Square</span>.<span class="property">create</span>(<span class="localvariable">line</span>.<span class="property">charAt</span>(<span class="localvariable">x</span>), <span class="localvariable">tableCell</span>);
+ <span class="localvariable">squareRow</span>.<span class="property">push</span>(<span class="localvariable">square</span>);
+ <span class="keyword">if</span> (<span class="localvariable">square</span>.<span class="property">hasPlayer</span>())
+ <span class="localvariable">this</span>.<span class="property">playerPos</span> = <span class="keyword">new</span> <span class="variable">Point</span>(<span class="localvariable">x</span>, <span class="localvariable">y</span>);
+ }
+ <span class="localvariable">tbody</span>.<span class="property">appendChild</span>(<span class="localvariable">tableRow</span>);
+ <span class="localvariable">this</span>.<span class="property">squares</span>.<span class="property">push</span>(<span class="localvariable">squareRow</span>);
+ }
+
+ <span class="localvariable">this</span>.<span class="property">table</span> = <span class="variable">dom</span>(<span class="string">"TABLE"</span>, {<span class="string">"class"</span>: <span class="string">"sokoban"</span>}, <span class="localvariable">tbody</span>);
+ <span class="localvariable">this</span>.<span class="property">score</span> = <span class="variable">dom</span>(<span class="string">"DIV"</span>, <span class="atom">null</span>, <span class="string">"..."</span>);
+ <span class="localvariable">this</span>.<span class="property">updateScore</span>();
+ },
+
+ <span class="property">getSquare</span>: <span class="keyword">function</span>(<span class="variabledef">position</span>) {
+ <span class="keyword">return</span> <span class="localvariable">this</span>.<span class="property">squares</span>[<span class="localvariable">position</span>.<span class="property">y</span>][<span class="localvariable">position</span>.<span class="property">x</span>];
+ },
+ <span class="property">updateScore</span>: <span class="keyword">function</span>() {
+ <span class="localvariable">this</span>.<span class="property">score</span>.<span class="property">firstChild</span>.<span class="property">nodeValue</span> = <span class="localvariable">this</span>.<span class="property">bouldersToGo</span> +
+ <span class="string">" boulders to go."</span>;
+ },
+ <span class="property">won</span>: <span class="keyword">function</span>() {
+ <span class="keyword">return</span> <span class="localvariable">this</span>.<span class="property">bouldersToGo</span> <= <span class="atom">0</span>;
+ }
+};
+
+<span class="keyword">var</span> <span class="variable">testField</span> = <span class="variable">SokobanField</span>.<span class="property">create</span>(<span class="variable">sokobanLevels</span>[<span class="atom">0</span>]);
+<span class="variable">show</span>(<span class="variable">testField</span>.<span class="property">getSquare</span>(<span class="keyword">new</span> <span class="variable">Point</span>(<span class="atom">10</span>, <span class="atom">2</span>)).<span class="property">content</span>);</pre><p><a class="paragraph" href="#p2c2b54280aa123b2" name="p2c2b54280aa123b2"> </a>The constructor goes over the lines and characters in the level, and
+stores the <code>Square</code> objects in the <code>squares</code> property. When it
+encounters the square with the player, it saves this position as
+<code>playerPos</code>, so that we can easily find the square with the player
+later on. <code>getSquare</code> is used to find a <code>Square</code> object corresponding
+to a certain <code>x,y</code> position on the field. Note that it doesn't take
+the edges of the field into account ― to avoid writing some boring
+code, we assume that the field is properly walled off, making it
+impossible to walk out of it.</p><p><a class="paragraph" href="#p455575a17764e02d" name="p455575a17764e02d"> </a>The word <code>"class"</code> in the <code>dom</code> call that makes the <code>table</code> node is
+quoted as a string. This is necessary because <a name="key58"></a><code>class</code> is a 'reserved
+word' in JavaScript, and may not be used as a variable or property
+name.</p><p><a class="paragraph" href="#p573c956db8c8002f" name="p573c956db8c8002f"> </a>The amount of boulders that have to be cleared to win the level (this
+may be less than the total amount of boulders on the level) is stored
+in <code>bouldersToGo</code>. Whenever a boulder is brought to the exit, we can
+subtract 1 from this, and see whether the game is won yet. To show the
+player how he is doing, we will have to show this amount somehow. For
+this purpose, a <code>div</code> element with text is used. <code>div</code> nodes are
+containers without inherent markup. The score text can be updated with
+the <code>updateScore</code> method. The <code>won</code> method will be used by the
+controller object to determine when the game is over, so the player
+can move on to the next level.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p77c7622b4009788c" name="p77c7622b4009788c"> </a>If we want to actually see the playing field and the score, we will
+have to insert them into the document somehow. That is what the
+<code>place</code> method is for. We'll also add a <code>remove</code> method to make it
+easy to remove a field when we are done with it.</p><pre class="code"><span class="variable">SokobanField</span>.<span class="property">place</span> = <span class="keyword">function</span>(<span class="variabledef">where</span>) {
+ <span class="localvariable">where</span>.<span class="property">appendChild</span>(<span class="localvariable">this</span>.<span class="property">score</span>);
+ <span class="localvariable">where</span>.<span class="property">appendChild</span>(<span class="localvariable">this</span>.<span class="property">table</span>);
+};
+<span class="variable">SokobanField</span>.<span class="property">remove</span> = <span class="keyword">function</span>() {
+ <span class="variable">removeElement</span>(<span class="localvariable">this</span>.<span class="property">score</span>);
+ <span class="variable">removeElement</span>(<span class="localvariable">this</span>.<span class="property">table</span>);
+};
+
+<span class="variable">testField</span>.<span class="property">place</span>(<span class="variable">document</span>.<span class="property">body</span>);</pre><p><a class="paragraph" href="#p5487ca31a17d9d6f" name="p5487ca31a17d9d6f"> </a>If all went well, you should see a Sokoban field now.</p></div><hr/><div class="block"><a name="exercise3"></a><div class="exercisenum">Ex. 13.3</div><div class="exercise"><p><a class="paragraph" href="#p748eef9d06aedd00" name="p748eef9d06aedd00"> </a>But this field doesn't do very much yet. Add a method called <code>move</code>.
+It takes a <code>Point</code> object specifying the move as argument (for example
+<code>-1,0</code> to move left), and takes care of moving the game elements in
+the correct way.</p><p><a class="paragraph" href="#p3d38e80ddde25283" name="p3d38e80ddde25283"> </a>The correct way is this: The <code>playerPos</code> property can be used to
+determine where the player is trying to move. If there is a boulder
+here, look at the square behind this boulder. When there is an exit
+there, remove the boulder and update the score. When there is empty
+space there, move the boulder into it. Next, try to move the player.
+If the square he is trying to move into is not empty, ignore the move.</p></div><div class="solution"><pre class="code"><span class="variable">SokobanField</span>.<span class="property">move</span> = <span class="keyword">function</span>(<span class="variabledef">direction</span>) {
+ <span class="keyword">var</span> <span class="variabledef">playerSquare</span> = <span class="localvariable">this</span>.<span class="property">getSquare</span>(<span class="localvariable">this</span>.<span class="property">playerPos</span>);
+ <span class="keyword">var</span> <span class="variabledef">targetPos</span> = <span class="localvariable">this</span>.<span class="property">playerPos</span>.<span class="property">add</span>(<span class="localvariable">direction</span>);
+ <span class="keyword">var</span> <span class="variabledef">targetSquare</span> = <span class="localvariable">this</span>.<span class="property">getSquare</span>(<span class="localvariable">targetPos</span>);
+
+ <span class="comment">// Possibly pushing a boulder</span>
+ <span class="keyword">if</span> (<span class="localvariable">targetSquare</span>.<span class="property">hasBoulder</span>()) {
+ <span class="keyword">var</span> <span class="variabledef">pushTarget</span> = <span class="localvariable">this</span>.<span class="property">getSquare</span>(<span class="localvariable">targetPos</span>.<span class="property">add</span>(<span class="localvariable">direction</span>));
+ <span class="keyword">if</span> (<span class="localvariable">pushTarget</span>.<span class="property">isEmpty</span>()) {
+ <span class="localvariable">targetSquare</span>.<span class="property">moveContent</span>(<span class="localvariable">pushTarget</span>);
+ }
+ <span class="keyword">else</span> <span class="keyword">if</span> (<span class="localvariable">pushTarget</span>.<span class="property">isExit</span>()) {
+ <span class="localvariable">targetSquare</span>.<span class="property">moveContent</span>(<span class="localvariable">pushTarget</span>);
+ <span class="localvariable">pushTarget</span>.<span class="property">clearContent</span>();
+ <span class="localvariable">this</span>.<span class="property">bouldersToGo</span>--;
+ <span class="localvariable">this</span>.<span class="property">updateScore</span>();
+ }
+ }
+ <span class="comment">// Moving the player</span>
+ <span class="keyword">if</span> (<span class="localvariable">targetSquare</span>.<span class="property">isEmpty</span>()) {
+ <span class="localvariable">playerSquare</span>.<span class="property">moveContent</span>(<span class="localvariable">targetSquare</span>);
+ <span class="localvariable">this</span>.<span class="property">playerPos</span> = <span class="localvariable">targetPos</span>;
+ }
+};</pre><p><a class="paragraph" href="#p538b98bc3fc959ad" name="p538b98bc3fc959ad"> </a>By taking care of boulders first, the move code can work the same way
+when the player is moving normally and when he is pushing a boulder.
+Note how the square behind the boulder is found by adding the
+<code>direction</code> to the <code>playerPos</code> twice. Test it by moving left two
+squares:</p><pre class="code"><span class="variable">testField</span>.<span class="property">move</span>(<span class="keyword">new</span> <span class="variable">Point</span>(-<span class="atom">1</span>, <span class="atom">0</span>));
+<span class="variable">testField</span>.<span class="property">move</span>(<span class="keyword">new</span> <span class="variable">Point</span>(-<span class="atom">1</span>, <span class="atom">0</span>));</pre><p><a class="paragraph" href="#p3c642348ee437a1c" name="p3c642348ee437a1c"> </a>If that worked, we moved a boulder into a place from which we can't
+get it out anymore, so we'd better throw this field away.</p><pre class="code"><span class="variable">testField</span>.<span class="property">remove</span>();</pre></div></div><hr/><div class="block"><p><a class="paragraph" href="#p5b308c76a573480" name="p5b308c76a573480"> </a>All the 'game logic' has been taken care of now, and we just need a
+controller to make it playable. The controller will be an object type
+called <code>SokobanGame</code>, which is responsible for the following things:</p><ul><li>Preparing a place where the game field can be placed.</li><li>Building and removing <code>SokobanField</code> objects.</li><li>Capturing key events and calling the <code>move</code> method on current field with the correct argument.</li><li>Keeping track of the current level number and moving to the next level when a level is won.</li><li>Adding buttons to reset the current level or the whole game (back to level 0).</li></ul><p><a class="paragraph" href="#p45ad3b18e78810ca" name="p45ad3b18e78810ca"> </a>We start again with an unfinished prototype.</p><pre class="code"><span class="keyword">var</span> <span class="variable">SokobanGame</span> = {
+ <span class="property">construct</span>: <span class="keyword">function</span>(<span class="variabledef">place</span>) {
+ <span class="localvariable">this</span>.<span class="property">level</span> = <span class="atom">null</span>;
+ <span class="localvariable">this</span>.<span class="property">field</span> = <span class="atom">null</span>;
+
+ <span class="keyword">var</span> <span class="variabledef">newGame</span> = <span class="variable">dom</span>(<span class="string">"BUTTON"</span>, <span class="atom">null</span>, <span class="string">"New game"</span>);
+ <span class="variable">addHandler</span>(<span class="localvariable">newGame</span>, <span class="string">"click"</span>, <span class="variable">method</span>(<span class="localvariable">this</span>, <span class="string">"newGame"</span>));
+ <span class="keyword">var</span> <span class="variabledef">reset</span> = <span class="variable">dom</span>(<span class="string">"BUTTON"</span>, <span class="atom">null</span>, <span class="string">"Reset level"</span>);
+ <span class="variable">addHandler</span>(<span class="localvariable">reset</span>, <span class="string">"click"</span>, <span class="variable">method</span>(<span class="localvariable">this</span>, <span class="string">"reset"</span>));
+ <span class="localvariable">this</span>.<span class="property">container</span> = <span class="variable">dom</span>(<span class="string">"DIV"</span>, <span class="atom">null</span>,
+ <span class="variable">dom</span>(<span class="string">"H1"</span>, <span class="atom">null</span>, <span class="string">"Sokoban"</span>),
+ <span class="variable">dom</span>(<span class="string">"DIV"</span>, <span class="atom">null</span>, <span class="localvariable">newGame</span>, <span class="string">" "</span>, <span class="localvariable">reset</span>));
+ <span class="localvariable">place</span>.<span class="property">appendChild</span>(<span class="localvariable">this</span>.<span class="property">container</span>);
+
+ <span class="variable">addHandler</span>(<span class="variable">document</span>, <span class="string">"keydown"</span>, <span class="variable">method</span>(<span class="localvariable">this</span>, <span class="string">"keyDown"</span>));
+ <span class="localvariable">this</span>.<span class="property">newGame</span>();
+ },
+
+ <span class="property">newGame</span>: <span class="keyword">function</span>() {
+ <span class="localvariable">this</span>.<span class="property">level</span> = <span class="atom">0</span>;
+ <span class="localvariable">this</span>.<span class="property">reset</span>();
+ },
+ <span class="property">reset</span>: <span class="keyword">function</span>() {
+ <span class="keyword">if</span> (<span class="localvariable">this</span>.<span class="property">field</span>)
+ <span class="localvariable">this</span>.<span class="property">field</span>.<span class="property">remove</span>();
+ <span class="localvariable">this</span>.<span class="property">field</span> = <span class="variable">SokobanField</span>.<span class="property">create</span>(<span class="variable">sokobanLevels</span>[<span class="localvariable">this</span>.<span class="property">level</span>]);
+ <span class="localvariable">this</span>.<span class="property">field</span>.<span class="property">place</span>(<span class="localvariable">this</span>.<span class="property">container</span>);
+ },
+
+ <span class="property">keyDown</span>: <span class="keyword">function</span>(<span class="variabledef">event</span>) {
+ <span class="comment">// To be filled in</span>
+ }
+};</pre><p><a class="paragraph" href="#p35d377ee1e3f49a8" name="p35d377ee1e3f49a8"> </a>The constructor builds a <code>div</code> element to hold the field, along with
+two buttons and a title. Note how <code>method</code> is used to attach methods
+on the <code>this</code> object to events.</p><p><a class="paragraph" href="#p42d09a84b15ae999" name="p42d09a84b15ae999"> </a>We can put a Sokoban game into our document like this:</p><pre class="code"><span class="keyword">var</span> <span class="variable">sokoban</span> = <span class="variable">SokobanGame</span>.<span class="property">create</span>(<span class="variable">document</span>.<span class="property">body</span>);</pre></div><hr/><div class="block"><a name="exercise4"></a><div class="exercisenum">Ex. 13.4</div><div class="exercise"><p><a class="paragraph" href="#p53a2f6f5fc9bf0e8" name="p53a2f6f5fc9bf0e8"> </a>All that is left to do now is filling in the key event handler.
+Replace the <code>keyDown</code> method of the prototype with one that detects
+presses of the arrow keys and, when it finds them, moves the player in
+the correct direction. The following <code>Dictionary</code> will probably come
+in handy:</p><pre class="code"><span class="keyword">var</span> <span class="variable">arrowKeyCodes</span> = <span class="keyword">new</span> <span class="variable">Dictionary</span>({
+ <span class="atom">37</span>: <span class="keyword">new</span> <span class="variable">Point</span>(-<span class="atom">1</span>, <span class="atom">0</span>), <span class="comment">// left</span>
+ <span class="atom">38</span>: <span class="keyword">new</span> <span class="variable">Point</span>(<span class="atom">0</span>, -<span class="atom">1</span>), <span class="comment">// up</span>
+ <span class="atom">39</span>: <span class="keyword">new</span> <span class="variable">Point</span>(<span class="atom">1</span>, <span class="atom">0</span>), <span class="comment">// right</span>
+ <span class="atom">40</span>: <span class="keyword">new</span> <span class="variable">Point</span>(<span class="atom">0</span>, <span class="atom">1</span>) <span class="comment">// down</span>
+});</pre><p><a class="paragraph" href="#pcb1472f81f00f3b" name="pcb1472f81f00f3b"> </a>After an arrow key has been handled, check <code>this.field.won()</code> to find
+out if that was the winning move. If the player won, use <code>alert</code> to
+show a message, and go to the next level. If there is no next level
+(check <code>sokobanLevels.length</code>), restart the game instead.</p><p><a class="paragraph" href="#p3d967959c7cdf6ce" name="p3d967959c7cdf6ce"> </a>It is probably wise to stop the events for key presses after handling
+them, otherwise pressing arrow-up and arrow-down will scroll your
+window, which is rather annoying.</p></div><div class="solution"><pre class="code"><span class="variable">SokobanGame</span>.<span class="property">keyDown</span> = <span class="keyword">function</span>(<span class="variabledef">event</span>) {
+ <span class="keyword">if</span> (<span class="variable">arrowKeyCodes</span>.<span class="property">contains</span>(<span class="localvariable">event</span>.<span class="property">keyCode</span>)) {
+ <span class="localvariable">event</span>.<span class="property">stop</span>();
+ <span class="localvariable">this</span>.<span class="property">field</span>.<span class="property">move</span>(<span class="variable">arrowKeyCodes</span>.<span class="property">lookup</span>(<span class="localvariable">event</span>.<span class="property">keyCode</span>));
+ <span class="keyword">if</span> (<span class="localvariable">this</span>.<span class="property">field</span>.<span class="property">won</span>()) {
+ <span class="keyword">if</span> (<span class="localvariable">this</span>.<span class="property">level</span> < <span class="variable">sokobanLevels</span>.<span class="property">length</span> - <span class="atom">1</span>) {
+ <span class="variable">alert</span>(<span class="string">"Excellent! Going to the next level."</span>);
+ <span class="localvariable">this</span>.<span class="property">level</span>++;
+ <span class="localvariable">this</span>.<span class="property">reset</span>();
+ }
+ <span class="keyword">else</span> {
+ <span class="variable">alert</span>(<span class="string">"You win! Game over."</span>);
+ <span class="localvariable">this</span>.<span class="property">newGame</span>();
+ }
+ }
+ }
+};</pre><p><a class="paragraph" href="#p1b830e985c329e93" name="p1b830e985c329e93"> ¶ </a>It has to be noted that capturing keys like this ― adding a handler
+to the <code>document</code> and stopping the events that you are looking for ―
+is not very nice when there are other elements in the document. For
+example, try moving the cursor around in the text field at the top of
+the document. ― It won't work, you'll only move the little man in the
+Sokoban game. If a game like this were to be used in a real site, it
+is probably best to put it in a frame or window of its own, so that it
+only grabs events aimed at its own window.</p></div></div><hr/><div class="block"><a name="exercise5"></a><div class="exercisenum">Ex. 13.5</div><div class="exercise"><p><a class="paragraph" href="#p239cf757b63a655d" name="p239cf757b63a655d"> </a>When brought to the exit, the boulders vanish rather abruptly. By
+modifying the <code>Square.clearContent</code> method, try to show a 'falling'
+animation for boulders that are about to be removed. Make them grow
+smaller for a moment before, and then disappear. You can use
+<code>style.width = "50%"</code>, and similarly for <code>style.height</code>, to make an
+image appear, for example, half as big as it usually is.</p></div><div class="solution"><p><a class="paragraph" href="#p59c8b255e3854cba" name="p59c8b255e3854cba"> </a>We can use <code>setInterval</code> to handle the timing of the animation. Note
+that the method makes sure to clear the interval after it is done. If
+you don't do that, it will continue wasting your computer's time until
+the page is closed.</p><pre class="code"><span class="variable">Square</span>.<span class="property">clearContent</span> = <span class="keyword">function</span>() {
+ <span class="variable">self</span>.<span class="property">content</span> = <span class="atom">null</span>;
+ <span class="keyword">var</span> <span class="variabledef">image</span> = <span class="localvariable">this</span>.<span class="property">tableCell</span>.<span class="property">lastChild</span>;
+ <span class="keyword">var</span> <span class="variabledef">size</span> = <span class="atom">100</span>;
+
+ <span class="keyword">var</span> <span class="variabledef">animate</span> = <span class="variable">setInterval</span>(<span class="keyword">function</span>() {
+ <span class="localvariable">size</span> -= <span class="atom">10</span>;
+ <span class="localvariable">image</span>.<span class="property">style</span>.<span class="property">width</span> = <span class="localvariable">size</span> + <span class="string">"%"</span>;
+ <span class="localvariable">image</span>.<span class="property">style</span>.<span class="property">height</span> = <span class="localvariable">size</span> + <span class="string">"%"</span>;
+
+ <span class="keyword">if</span> (<span class="localvariable">size</span> < <span class="atom">60</span>) {
+ <span class="variable">clearInterval</span>(<span class="localvariable">animate</span>);
+ <span class="variable">removeElement</span>(<span class="localvariable">image</span>);
+ }
+ }, <span class="atom">70</span>);
+};</pre><p><a class="paragraph" href="#p2883f0d262b85871" name="p2883f0d262b85871"> </a>Now, if you have a few hours to waste, try finishing all levels.</p></div></div><hr/><div class="block"><p><a class="paragraph" href="#p6f93696fe70dfa4e" name="p6f93696fe70dfa4e"> </a><a name="key59"></a><a name="key60"></a>Other event types that can be useful are
+<a name="key61"></a><code>focus</code> and <a name="key62"></a><code>blur</code>, which are fired on elements that can be
+'focused', such as form inputs. <code>focus</code>, obviously, happens when you
+put the focus on the element, for example by clicking on it. <code>blur</code> is
+JavaScript-speak for 'unfocus', and is fired when the focus leaves the
+element.</p><pre class="code"><span class="variable">addHandler</span>(<span class="variable">$</span>(<span class="string">"textfield"</span>), <span class="string">"focus"</span>, <span class="keyword">function</span>(<span class="variabledef">event</span>) {
+ <span class="localvariable">event</span>.<span class="property">target</span>.<span class="property">style</span>.<span class="property">backgroundColor</span> = <span class="string">"yellow"</span>;
+});
+<span class="variable">addHandler</span>(<span class="variable">$</span>(<span class="string">"textfield"</span>), <span class="string">"blur"</span>, <span class="keyword">function</span>(<span class="variabledef">event</span>) {
+ <span class="localvariable">event</span>.<span class="property">target</span>.<span class="property">style</span>.<span class="property">backgroundColor</span> = <span class="string">""</span>;
+});</pre><p><a class="paragraph" href="#p118c69cf1c7aa223" name="p118c69cf1c7aa223"> </a><a name="key63"></a>Another event related to form inputs is <a name="key64"></a><code>change</code>. This
+is fired when the content of the input has changed... except that for
+some inputs, such as text inputs, it does not fire until the element
+is unfocused.</p><pre class="code"><span class="variable">addHandler</span>(<span class="variable">$</span>(<span class="string">"textfield"</span>), <span class="string">"change"</span>, <span class="keyword">function</span>(<span class="variabledef">event</span>) {
+ <span class="variable">print</span>(<span class="string">"Content of text field changed to '"</span>,
+ <span class="localvariable">event</span>.<span class="property">target</span>.<span class="property">value</span>, <span class="string">"'."</span>);
+});</pre><p><a class="paragraph" href="#p7db698c4342d25e3" name="p7db698c4342d25e3"> </a>You can type all you want, the event will only fire when you click
+outside of the input, press tab, or unfocus it in some other way.</p><p><a class="paragraph" href="#p61e8f958414e8cfc" name="p61e8f958414e8cfc"> </a><a name="key65"></a>Forms also have a <a name="key66"></a><code>submit</code> event, which is fired when
+they submit. It can be stopped to prevent the submit from taking
+place. This gives us a <em>much</em> better way to do the form validation we
+saw in the previous chapter. You just register a <code>submit</code> handler,
+which stops the event when the content of the form is not valid. That
+way, when the user does not have JavaScript enabled, the form will
+still work, it just won't have instant validation.</p><p><a class="paragraph" href="#p1337214030928c91" name="p1337214030928c91"> </a><a name="key67"></a><a name="key68"></a>Window objects have a <a name="key69"></a><code>load</code> event that fires
+when the document is fully loaded, which can be useful if your script
+needs to do some kind of initialisation that has to wait until the
+whole document is present. For example, the scripts on the pages for
+this book go over the current chapter to hide solutions to exercises.
+You can't do that when the exercises are not loaded yet. There is also
+an <a name="key70"></a><code>unload</code> event, firing when the user leaves the document, but
+this is not properly supported by all browsers.</p><p><a class="paragraph" href="#p62706f6f952b7d27" name="p62706f6f952b7d27"> </a><a name="key71"></a>Most of the time it is best to leave the laying out of a
+document to the browser, but there are effects that can only be
+produced by having a piece of JavaScript set the exact sizes of some
+nodes in a document. When you do this, make sure you also listen for
+<a name="key72"></a><code>resize</code> events on the window, and re-calculate the sizes of your
+element every time the window is resized.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p1576d7eeb23c322" name="p1576d7eeb23c322"> </a>Finally, I have to tell you something about event handlers that you
+would rather not know. The Internet Explorer browser (which means, at
+the time of writing, the browser used by a majority of web-surfers)
+has a bug that causes values to not be cleaned up as normal: Even when
+they are no longer used, they stay in the machine's memory. This is
+known as a <a name="key73"></a>memory leak, and, once enough memory has been leaked,
+will seriously slow down a computer.</p><p><a class="paragraph" href="#p22f24bf084d74d4e" name="p22f24bf084d74d4e"> </a>When does this leaking occur? Due to a deficiency in Internet
+Explorer's <a name="key74"></a>garbage collector, the system whose purpose it is to
+reclaim unused values, when you have a DOM node that, through one of
+its properties or in a more indirect way, refers to a normal
+JavaScript object, and this object, in turn, refers back to that DOM
+node, both objects will not be collected. This has something to do
+with the fact that DOM nodes and other JavaScript objects are
+collected by different systems ― the system that cleans up DOM nodes
+will take care to leave any nodes that are still referenced by
+JavaScript objects, and vice versa for the system that collects normal
+JavaScript values.</p><p><a class="paragraph" href="#p560d289a24cd2757" name="p560d289a24cd2757"> </a>As the above description shows, the problem is not specifically
+related to event handlers. This code, for example, creates a bit of
+un-collectable memory:</p><pre class="code invalid"><span class="keyword">var</span> <span class="variable">jsObject</span> = {<span class="property">link</span>: <span class="variable">document</span>.<span class="property">body</span>};
+<span class="variable">document</span>.<span class="property">body</span>.<span class="property">linkBack</span> = <span class="variable">jsObject</span>;</pre><p><a class="paragraph" href="#p3dd3e899a4484a02" name="p3dd3e899a4484a02"> </a>Even after such an Internet Explorer browser goes to a different page,
+it will still hold on to the <code>document.body</code> shown here. The reason
+this bug is often associated with event handlers is that it is
+extremely easy to make such circular links when registering a handler.
+The DOM node keeps references to its handlers, and the handler, most
+of the time, has a reference to the DOM node. Even when this reference
+is not intentionally made, JavaScript's scoping rules tend to add it
+implicitly. Consider this function:</p><pre class="code invalid"><span class="keyword">function</span> <span class="variable">addAlerter</span>(<span class="variabledef">element</span>) {
+ <span class="variable">addHandler</span>(<span class="localvariable">element</span>, <span class="string">"click"</span>, <span class="keyword">function</span>() {
+ <span class="variable">alert</span>(<span class="string">"Alert! ALERT!"</span>);
+ });
+}</pre><p><a class="paragraph" href="#p3b0788945ca0cdd9" name="p3b0788945ca0cdd9"> </a>The anonymous function that is created by the <code>addAlerter</code> function
+can 'see' the <code>element</code> variable. It doesn't use it, but that does not
+matter ― just because it can see it, it will have a reference to it.
+By registering this function as an event handler on that same
+<code>element</code> object, we have created a circle.</p><p><a class="paragraph" href="#p274f002fddd7971a" name="p274f002fddd7971a"> </a>There are three ways to deal with this problem. The first approach, a
+very popular one, is to ignore it. Most scripts will only leak a
+little bit, so it takes a long time and a lot of pages before the
+problems become noticeable. And, when the problems are so subtle,
+who's going to hold <em>you</em> responsible? Programmers given to this
+approach will often searingly denounce Microsoft for their shoddy
+programming, and state that the problem is not their fault, so <em>they</em>
+shouldn't be fixing it.</p><p><a class="paragraph" href="#p425aad248cff4045" name="p425aad248cff4045"> </a>Such reasoning is not entirely without merit, of course. But when half
+your users are having problems with the web-pages you make, it is hard
+to deny that there is a practical problem. Which is why people working
+on 'serious' sites usually make an attempt not to leak any memory.
+Which brings us to the second approach: Painstakingly making sure that
+no circular references between DOM objects and regular objects are
+created. This means, for example, rewriting the above handler like
+this:</p><pre class="code"><span class="keyword">function</span> <span class="variable">addAlerter</span>(<span class="variabledef">element</span>) {
+ <span class="variable">addHandler</span>(<span class="localvariable">element</span>, <span class="string">"click"</span>, <span class="keyword">function</span>() {
+ <span class="variable">alert</span>(<span class="string">"Alert! ALERT!"</span>);
+ });
+ <span class="localvariable">element</span> = <span class="atom">null</span>;
+}</pre><p><a class="paragraph" href="#p9dd7c644334aca3" name="p9dd7c644334aca3"> </a>Now the <code>element</code> variable no longer points at the DOM node, and the
+handler will not leak. This approach is viable, but requires the
+programmer to <em>really</em> pay attention.</p><p><a class="paragraph" href="#p1f42dbaeb6e8d65b" name="p1f42dbaeb6e8d65b"> </a>The third solution, finally, is to not worry too much about creating
+leaky structures, but to make sure to clean them up when you are done
+with them. This means unregistering any event handlers when they are
+no longer needed, and registering an <code>onunload</code> event to unregister
+the handlers that are needed until the page is unloaded. It is
+possible to extend an event-registering system, like our <code>addHandler</code>
+function, to automatically do this. When taking this approach, you
+must keep in mind that event handlers are not the only possible source
+of memory leaks ― adding properties to DOM node objects can cause
+similar problems.</p></div><h1><span class="number">Chapter 14: </span>HTTP requests</h1><div class="block"><p><a class="paragraph" href="#p743a85de1fe93747" name="p743a85de1fe93747"> </a>As mentioned in <a href="chapter11.html">chapter 11</a>, communication on the World Wide Web happens
+over the <a name="key1"></a>HTTP protocol. A simple <a name="key2"></a>request might look
+like this:</p><pre class="preformatted">GET /files/fruit.txt HTTP/1.1
+Host: eloquentjavascript.net
+User-Agent: The Imaginary Browser</pre><p><a class="paragraph" href="#p3ea737b5aacb10f" name="p3ea737b5aacb10f"> </a>Which asks for the file <code>files/fruit.txt</code> from the server at
+<code>eloquentjavascript.net</code>. In addition, it specifies that this request
+uses version 1.1 of the HTTP protocol ― version 1.0 is also still in
+use, and works slightly differently. The <code>Host</code> and <code>User-Agent</code> lines
+follow a pattern: They start with a word that identifies the
+information they contain, followed by a colon and the actual
+information. These are called '<a name="key3"></a>headers'. The <code>User-Agent</code> header
+tells the server which browser (or other kind of program) is being
+used to make the request. Other kinds of headers are often sent along,
+for example to state the types of documents that the client can
+understand, or the language that it prefers.</p><p><a class="paragraph" href="#p1b275f378f382ad8" name="p1b275f378f382ad8"> </a>When given the above request, the server might send the following
+<a name="key4"></a>response:</p><pre class="preformatted">HTTP/1.1 200 OK
+Last-Modified: Mon, 23 Jul 2007 08:41:56 GMT
+Content-Length: 24
+Content-Type: text/plain
+
+apples, oranges, bananas</pre><p><a class="paragraph" href="#p13683b7c6cac54c" name="p13683b7c6cac54c"> </a>The first line indicates again the version of the HTTP protocol,
+followed by the status of the request. In this case the status code is
+<code>200</code>, meaning 'OK, nothing out of the ordinary happened, I am sending
+you the file'. This is followed by a few headers, indicating (in this
+case) the last time the file was modified, its length, and its type
+(plain text). After the headers you get a blank line, followed by the
+file itself.</p><p><a class="paragraph" href="#p2417c911b4676d0d" name="p2417c911b4676d0d"> </a>Apart from requests starting with <code>GET</code>, which indicates the client
+just wants to fetch a document, the word <code>POST</code> can also be used to
+indicate some information will be sent along with the request, which
+the server is expected to process in some way.<a class="footref" href="#footnote1">1</a></p></div><hr/><div class="block"><p><a class="paragraph" href="#p314f77f0ec94eb7a" name="p314f77f0ec94eb7a"> </a>When you click a link, submit a form, or in some other way encourage
+your browser to go to a new page, it will do an HTTP request and
+immediately unload the old page to show the newly loaded document. In
+typical situations, this is just what you want ― it is how the web
+traditionally works. Sometimes, however, a JavaScript program wants to
+communicate with the server without re-loading the page. The 'Load'
+button in the console, for example, can load files without leaving the
+page.</p><p><a class="paragraph" href="#p2963d0bd02e1e35d" name="p2963d0bd02e1e35d"> </a>To be able to do things like that, the JavaScript program must make
+the HTTP request itself. Contemporary browsers provide an interface
+for this. As with opening new windows, this interface is subject to
+some restrictions. To prevent a script from doing anything scary, it
+is only allowed to make HTTP requests to the domain that the current
+page came from.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p6c40c04f1a4e9c8e" name="p6c40c04f1a4e9c8e"> </a><a name="key5"></a>An object used to make an HTTP request can, on most
+browsers, be created by doing <code>new XMLHttpRequest()</code>. Older versions
+of Internet Explorer, which originally invented these objects, require
+you to do <code>new ActiveXObject("Msxml2.XMLHTTP")</code> or, on even older
+versions, <code>new ActiveXObject("Microsoft.XMLHTTP")</code>. <a name="key6"></a><code>ActiveXObject</code>
+is Internet Explorer's interface to various kinds of browser add-ons.
+We are already used to writing incompatibility-wrappers by now, so let
+us do so again:</p><pre class="code"><span class="keyword">function</span> <span class="variable">makeHttpObject</span>() {
+ <span class="keyword">try</span> {<span class="keyword">return</span> <span class="keyword">new</span> <span class="variable">XMLHttpRequest</span>();}
+ <span class="keyword">catch</span> (<span class="variabledef">error</span>) {}
+ <span class="keyword">try</span> {<span class="keyword">return</span> <span class="keyword">new</span> <span class="variable">ActiveXObject</span>(<span class="string">"Msxml2.XMLHTTP"</span>);}
+ <span class="keyword">catch</span> (<span class="variabledef">error</span>) {}
+ <span class="keyword">try</span> {<span class="keyword">return</span> <span class="keyword">new</span> <span class="variable">ActiveXObject</span>(<span class="string">"Microsoft.XMLHTTP"</span>);}
+ <span class="keyword">catch</span> (<span class="variabledef">error</span>) {}
+
+ <span class="keyword">throw</span> <span class="keyword">new</span> <span class="variable">Error</span>(<span class="string">"Could not create HTTP request object."</span>);
+}
+
+<span class="variable">show</span>(typeof(<span class="variable">makeHttpObject</span>()));</pre><p><a class="paragraph" href="#p47399bf3cf9b1d8a" name="p47399bf3cf9b1d8a"> </a>The wrapper tries to create the object in all three ways, using <code>try</code>
+and <code>catch</code> to detect which ones fail. If none of the ways work, which
+might be the case on older browsers or browsers with strict security
+settings, it raises an error.</p><p><a class="paragraph" href="#p1cf32e97597c0e1" name="p1cf32e97597c0e1"> </a>Now why is this object called an <em>XML</em> HTTP request? This is a bit of
+a misleading name. <a name="key7"></a>XML is a way to store textual data. It uses tags
+and attributes like HTML, but is more structured and flexible ― to
+store your own kinds of data, you may define your own types of XML
+tags. These HTTP request objects have some built-in functionality for
+dealing with retrieved XML documents, which is why they have XML in
+their name. They can also handle other types of documents, though, and
+in my experience they are used just as often for non-XML requests.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p349618433b643891" name="p349618433b643891"> </a>Now that we have our HTTP object, we can use it to make a request
+similar the example shown above.</p><pre class="code"><span class="keyword">var</span> <span class="variable">request</span> = <span class="variable">makeHttpObject</span>();
+<span class="variable">request</span>.<span class="property">open</span>(<span class="string">"GET"</span>, <span class="string">"files/fruit.txt"</span>, <span class="atom">false</span>);
+<span class="variable">request</span>.<span class="property">send</span>(<span class="atom">null</span>);
+<span class="variable">print</span>(<span class="variable">request</span>.<span class="property">responseText</span>);</pre><p><a class="paragraph" href="#p568fd5163d41f6f7" name="p568fd5163d41f6f7"> </a>The <a name="key8"></a><code>open</code> method is used to configure a request. In this case we
+choose to make a <code>GET</code> request for our <code>fruit.txt</code> file. The <a name="key9"></a>URL
+given here is relative, it does not contain the <code>http://</code> part or a
+server name, which means it will look for the file on the server that
+the current document came from. The third parameter, <code>false</code>, will be
+discussed in a moment. After <code>open</code> has been called, the actual
+request can be made with the <a name="key10"></a><code>send</code> method. When the request is a
+<code>POST</code> request, the data to be sent to the server (as a string) can be
+passed to this method. For <code>GET</code> requests, one should just pass
+<code>null</code>.</p><p><a class="paragraph" href="#p17b3563d8f0ae54f" name="p17b3563d8f0ae54f"> </a>After the request has been made, the <a name="key11"></a><code>responseText</code> property of the
+request object contains the content of the retrieved document. The
+headers that the server sent back can be inspected with the
+<a name="key12"></a><code>getResponseHeader</code> and <a name="key13"></a><code>getAllResponseHeaders</code> functions. The
+first looks up a specific header, the second gives us a string
+containing all the headers. These can occasionally be useful to get
+some extra information about the document.</p><pre class="code"><span class="variable">print</span>(<span class="variable">request</span>.<span class="property">getAllResponseHeaders</span>());
+<span class="variable">show</span>(<span class="variable">request</span>.<span class="property">getResponseHeader</span>(<span class="string">"Last-Modified"</span>));</pre><p><a class="paragraph" href="#p26d4d4b30a20b42e" name="p26d4d4b30a20b42e"> </a>If, for some reason, you want to add headers to the request that is
+sent to the server, you can do so with the <a name="key14"></a><code>setRequestHeader</code>
+method. This takes two strings as arguments, the name and the value of
+the header.</p><p><a class="paragraph" href="#p38a8852f3e0dac14" name="p38a8852f3e0dac14"> </a>The response code, which was <code>200</code> in the example, can be found under
+the <a name="key15"></a><code>status</code> property. When something went wrong, this cryptic code
+will indicate it. For example, <code>404</code> means the file you asked for did
+not exist. The <a name="key16"></a><code>statusText</code> contains a slightly less cryptic
+description of the status.</p><pre class="code"><span class="variable">show</span>(<span class="variable">request</span>.<span class="property">status</span>);
+<span class="variable">show</span>(<span class="variable">request</span>.<span class="property">statusText</span>);</pre><p><a class="paragraph" href="#p2224c3891b47d53e" name="p2224c3891b47d53e"> </a>When you want to check whether a request succeeded, comparing the
+<code>status</code> to <code>200</code> is usually enough. In theory, the server might in
+some situations return the code <code>304</code> to indicate that the older
+version of the document, which the browser has stored in its
+'<a name="key17"></a>cache', is still up to date. But it seems that browsers shield you
+from this by setting the <code>status</code> to <code>200</code> even when it is <code>304</code>.
+Also, if you are doing a request over a non-HTTP protocol<a class="footref" href="#footnote2">2</a>, such as
+FTP, the <code>status</code> will not be usable because the protocol does not
+use HTTP status codes.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p499e386f31f6e47f" name="p499e386f31f6e47f"> </a>When a request is done as in the example above, the call to the <code>send</code>
+method does not return until the request is finished. This is
+convenient, because it means the <code>responseText</code> is available after the
+call to <code>send</code>, and we can start using it immediately. There is a
+problem, though. When the server is slow, or the file is big, doing a
+request might take quite a while. As long as this is happening, the
+program is waiting, which causes the whole browser to wait. Until the
+program finishes, the user can not do anything, not even scroll the
+page. Pages that run on a local network, which is fast and reliable,
+might get away with doing requests like this. Pages on the big great
+unreliable Internet, on the other hand, should not.</p><p><a class="paragraph" href="#p291f7223fcad270d" name="p291f7223fcad270d"> </a>When the third argument to <code>open</code> is <code>true</code>, the request is set to be
+'<a name="key18"></a>asynchronous'. This means that <code>send</code> will return right away, while
+the request happens in the background.</p><pre class="code"><span class="variable">request</span>.<span class="property">open</span>(<span class="string">"GET"</span>, <span class="string">"files/fruit.xml"</span>, <span class="atom">true</span>);
+<span class="variable">request</span>.<span class="property">send</span>(<span class="atom">null</span>);
+<span class="variable">show</span>(<span class="variable">request</span>.<span class="property">responseText</span>);</pre><p><a class="paragraph" href="#p6471230dbf8844b0" name="p6471230dbf8844b0"> </a>But wait a moment, and...</p><pre class="code"><span class="variable">print</span>(<span class="variable">request</span>.<span class="property">responseText</span>);</pre><p><a class="paragraph" href="#peae7ba1f220ae20" name="peae7ba1f220ae20"> </a>'Waiting a moment' could be implemented with <code>setTimeout</code> or something
+like that, but there is a better way. A request object has a
+<a name="key19"></a><code>readyState</code> property, indicating the state it is in. This will
+become <code>4</code> when the document has been fully loaded, and have a smaller
+value before that<a class="footref" href="#footnote3">3</a>. To react to changes in this status, you can set
+the <a name="key20"></a><code>onreadystatechange</code> property of the object to a function. This
+function will be called every time the state changes.</p><pre class="code"><span class="variable">request</span>.<span class="property">open</span>(<span class="string">"GET"</span>, <span class="string">"files/fruit.xml"</span>, <span class="atom">true</span>);
+<span class="variable">request</span>.<span class="property">send</span>(<span class="atom">null</span>);
+<span class="variable">request</span>.<span class="property">onreadystatechange</span> = <span class="keyword">function</span>() {
+ <span class="keyword">if</span> (<span class="variable">request</span>.<span class="property">readyState</span> == <span class="atom">4</span>)
+ <span class="variable">show</span>(<span class="variable">request</span>.<span class="property">responseText</span>.<span class="property">length</span>);
+};</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p1ca7f490fba0e18a" name="p1ca7f490fba0e18a"> </a>When the file retrieved by the request object is an XML document, the
+request's <a name="key21"></a><code>responseXML</code> property will hold a representation of this
+document. This representation works like the DOM objects discussed in
+<a href="chapter12.html">chapter 12</a>, except that it doesn't have HTML-specific functionality, such
+as <code>style</code> or <code>innerHTML</code>. <code>responseXML</code> gives us a document object,
+whose <code>documentElement</code> property refers to the outer tag of the XML
+document.</p><pre class="code"><span class="keyword">var</span> <span class="variable">catalog</span> = <span class="variable">request</span>.<span class="property">responseXML</span>.<span class="property">documentElement</span>;
+<span class="variable">show</span>(<span class="variable">catalog</span>.<span class="property">childNodes</span>.<span class="property">length</span>);</pre><p><a class="paragraph" href="#p1d65f6711ea2c673" name="p1d65f6711ea2c673"> </a>Such XML documents can be used to exchange structured information with
+the server. Their form ― tags contained inside other tags ― is often
+very suitable to store things that would be tricky to represent as
+simple flat text. The DOM interface is rather clumsy for extracting
+information though, and XML documents are notoriously wordy: The
+<code>fruit.xml</code> document looks like a lot, but all it says is 'apples are
+red, oranges are orange, and bananas are yellow'.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p1b952415eee0ffca" name="p1b952415eee0ffca"> </a><a name="key22"></a>As an alternative to XML, JavaScript programmers have come up
+with something called <a href="http://www.json.org">JSON</a>. This uses the
+basic notation of JavaScript values to represent 'hierarchical'
+information in a more minimalist way. A JSON document is a file
+containing a single JavaScript object or array, which in turn contains
+any number of other objects, arrays, strings, numbers, booleans, or
+<code>null</code> values. For an example, look at <code>fruit.json</code>:</p><pre class="code"><span class="variable">request</span>.<span class="property">open</span>(<span class="string">"GET"</span>, <span class="string">"files/fruit.json"</span>, <span class="atom">true</span>);
+<span class="variable">request</span>.<span class="property">send</span>(<span class="atom">null</span>);
+<span class="variable">request</span>.<span class="property">onreadystatechange</span> = <span class="keyword">function</span>() {
+ <span class="keyword">if</span> (<span class="variable">request</span>.<span class="property">readyState</span> == <span class="atom">4</span>)
+ <span class="variable">print</span>(<span class="variable">request</span>.<span class="property">responseText</span>);
+};</pre><p><a class="paragraph" href="#p3ce2b18ba499c2f7" name="p3ce2b18ba499c2f7"> </a>Such a piece of text can be converted to a normal JavaScript value by
+using the <a name="key23"></a><code>eval</code> function. Parentheses should be added around it
+before calling <code>eval</code>, because otherwise JavaScript might interpret an
+object (enclosed by braces) as a block of code, and produce an error.</p><pre class="code"><span class="keyword">function</span> <span class="variable">evalJSON</span>(<span class="variabledef">json</span>) {
+ <span class="keyword">return</span> <span class="variable">eval</span>(<span class="string">"("</span> + <span class="localvariable">json</span> + <span class="string">")"</span>);
+}
+<span class="keyword">var</span> <span class="variable">fruit</span> = <span class="variable">evalJSON</span>(<span class="variable">request</span>.<span class="property">responseText</span>);
+<span class="variable">show</span>(<span class="variable">fruit</span>);</pre><p><a class="paragraph" href="#p7df8d1d76c10288e" name="p7df8d1d76c10288e"> </a>When running <code>eval</code> on a piece of text, you have to keep in mind that
+this means you let the piece of text run whichever code it wants.
+Since JavaScript only allows us to make requests to our own domain,
+you will usually know exactly what kind of text you are getting, and
+this is not a problem. In other situations, it might be unsafe.</p></div><hr/><div class="block"><a name="exercise1"></a><div class="exercisenum">Ex. 14.1</div><div class="exercise"><p><a class="paragraph" href="#p61a3f689edac52d6" name="p61a3f689edac52d6"> </a>Write a function called <code>serializeJSON</code> which, when given a JavaScript
+value, produces a string with the value's JSON representation. Simple
+values like numbers and booleans can be simply given to the <code>String</code>
+function to convert them to a string. Objects and arrays can be
+handled by recursion.</p><p><a class="paragraph" href="#p509523e8ecb763b7" name="p509523e8ecb763b7"> </a>Recognizing arrays can be tricky, since its type is <code>"object"</code>. You
+can use <code>instanceof Array</code>, but that only works for arrays that were
+created in your own window ― others will use the <code>Array</code> prototype
+from other windows, and <code>instanceof</code> will return <code>false</code>. A cheap
+trick is to convert the <code>constructor</code> property to a string, and see
+whether that contains <code>"function Array"</code>.</p><p><a class="paragraph" href="#p416d7e20add6f798" name="p416d7e20add6f798"> </a>When converting a string, you have to take care to escape special
+characters inside it. If you use double-quotes around the string, the
+characters to escape are <code>\"</code>, <code>\\</code>, <code>\f</code>, <code>\b</code>, <code>\n</code>, <code>\t</code>, <code>\r</code>, and
+<code>\v</code><a class="footref" href="#footnote4">4</a>.</p></div><div class="solution"><pre class="code"><span class="keyword">function</span> <span class="variable">serializeJSON</span>(<span class="variabledef">value</span>) {
+ <span class="keyword">function</span> <span class="variabledef">isArray</span>(<span class="variabledef">value</span>) {
+ <span class="keyword">return</span> <span class="string">/^\s*function Array/</span>.<span class="property">test</span>(<span class="variable">String</span>(<span class="localvariable">value</span>.<span class="property">constructor</span>));
+ }
+
+ <span class="keyword">function</span> <span class="variabledef">serializeArray</span>(<span class="variabledef">value</span>) {
+ <span class="keyword">return</span> <span class="string">"["</span> + <span class="variable">map</span>(<span class="variable">serializeJSON</span>, <span class="localvariable">value</span>).<span class="property">join</span>(<span class="string">", "</span>) + <span class="string">"]"</span>;
+ }
+ <span class="keyword">function</span> <span class="variabledef">serializeObject</span>(<span class="variabledef">value</span>) {
+ <span class="keyword">var</span> <span class="variabledef">properties</span> = [];
+ <span class="variable">forEachIn</span>(<span class="localvariable">value</span>, <span class="keyword">function</span>(<span class="variabledef">name</span>, <span class="variabledef">value</span>) {
+ <span class="localvariable">properties</span>.<span class="property">push</span>(<span class="variable">serializeString</span>(<span class="localvariable">name</span>) + <span class="string">": "</span> +
+ <span class="variable">serializeJSON</span>(<span class="localvariable">value</span>));
+ });
+ <span class="keyword">return</span> <span class="string">"{"</span> + <span class="localvariable">properties</span>.<span class="property">join</span>(<span class="string">", "</span>) + <span class="string">"}"</span>;
+ }
+ <span class="keyword">function</span> <span class="variabledef">serializeString</span>(<span class="variabledef">value</span>) {
+ <span class="keyword">var</span> <span class="variabledef">special</span> =
+ {<span class="string">"\""</span>: <span class="string">"\\\""</span>, <span class="string">"\\"</span>: <span class="string">"\\\\"</span>, <span class="string">"\f"</span>: <span class="string">"\\f"</span>, <span class="string">"\b"</span>: <span class="string">"\\b"</span>,
+ <span class="string">"\n"</span>: <span class="string">"\\n"</span>, <span class="string">"\t"</span>: <span class="string">"\\t"</span>, <span class="string">"\r"</span>: <span class="string">"\\r"</span>, <span class="string">"\v"</span>: <span class="string">"\\v"</span>};
+ <span class="keyword">var</span> <span class="variabledef">escaped</span> = <span class="localvariable">value</span>.<span class="property">replace</span>(<span class="string">/[\"\\\f\b\n\t\r\v]/g</span>,
+ <span class="keyword">function</span>(<span class="variabledef">c</span>) {<span class="keyword">return</span> <span class="localvariable">special</span>[<span class="localvariable">c</span>];});
+ <span class="keyword">return</span> <span class="string">"\""</span> + <span class="localvariable">escaped</span> + <span class="string">"\""</span>;
+ }
+
+ <span class="keyword">var</span> <span class="variabledef">type</span> = typeof <span class="localvariable">value</span>;
+ <span class="keyword">if</span> (<span class="localvariable">type</span> == <span class="string">"object"</span> && <span class="localvariable">isArray</span>(<span class="localvariable">value</span>))
+ <span class="keyword">return</span> <span class="localvariable">serializeArray</span>(<span class="localvariable">value</span>);
+ <span class="keyword">else</span> <span class="keyword">if</span> (<span class="localvariable">type</span> == <span class="string">"object"</span>)
+ <span class="keyword">return</span> <span class="localvariable">serializeObject</span>(<span class="localvariable">value</span>);
+ <span class="keyword">else</span> <span class="keyword">if</span> (<span class="localvariable">type</span> == <span class="string">"string"</span>)
+ <span class="keyword">return</span> <span class="localvariable">serializeString</span>(<span class="localvariable">value</span>);
+ <span class="keyword">else</span>
+ <span class="keyword">return</span> <span class="variable">String</span>(<span class="localvariable">value</span>);
+}
+
+<span class="variable">print</span>(<span class="variable">serializeJSON</span>(<span class="variable">fruit</span>));</pre><p><a class="paragraph" href="#p788f4c1b7638b9f6" name="p788f4c1b7638b9f6"> </a>The trick used in <code>serializeString</code> is similar to what we saw in the
+<code>escapeHTML</code> function in <a href="chapter10.html">chapter 10</a>. It uses an object to look up the
+correct replacements for each of the characters. Some of them, such as
+<code>"\\\\"</code>, look quite weird because of the need to put two backslashes
+for every backslash in the resulting string.</p><p><a class="paragraph" href="#p23459ab246be96c" name="p23459ab246be96c"> </a>Also note that the names of properties are quoted as strings. For some
+of them, this is not necessary, but for property names with spaces and
+other strange things in them it is, so the code just takes the easy
+way out and quotes everything.</p></div></div><hr/><div class="block"><p><a class="paragraph" href="#p1f6ce3dfed84a60f" name="p1f6ce3dfed84a60f"> </a>When making lots of requests, we do, of course, not want to repeat the
+whole <code>open</code>, <code>send</code>, <code>onreadystatechange</code> ritual every time. A very
+simple wrapper could look like this:</p><pre class="code"><span class="keyword">function</span> <span class="variable">simpleHttpRequest</span>(<span class="variabledef">url</span>, <span class="variabledef">success</span>, <span class="variabledef">failure</span>) {
+ <span class="keyword">var</span> <span class="variabledef">request</span> = <span class="variable">makeHttpObject</span>();
+ <span class="localvariable">request</span>.<span class="property">open</span>(<span class="string">"GET"</span>, <span class="localvariable">url</span>, <span class="atom">true</span>);
+ <span class="localvariable">request</span>.<span class="property">send</span>(<span class="atom">null</span>);
+ <span class="localvariable">request</span>.<span class="property">onreadystatechange</span> = <span class="keyword">function</span>() {
+ <span class="keyword">if</span> (<span class="localvariable">request</span>.<span class="property">readyState</span> == <span class="atom">4</span>) {
+ <span class="keyword">if</span> (<span class="localvariable">request</span>.<span class="property">status</span> == <span class="atom">200</span>)
+ <span class="localvariable">success</span>(<span class="localvariable">request</span>.<span class="property">responseText</span>);
+ <span class="keyword">else</span> <span class="keyword">if</span> (<span class="localvariable">failure</span>)
+ <span class="localvariable">failure</span>(<span class="localvariable">request</span>.<span class="property">status</span>, <span class="localvariable">request</span>.<span class="property">statusText</span>);
+ }
+ };
+}
+
+<span class="variable">simpleHttpRequest</span>(<span class="string">"files/fruit.txt"</span>, <span class="variable">print</span>);</pre><p><a class="paragraph" href="#p38f2c042d53afec1" name="p38f2c042d53afec1"> </a>The function retrieves the url it is given, and calls the function it
+is given as a second argument with the content. When a third argument
+is given, this is used to indicate failure ― a non-<code>200</code> status code.</p><p><a class="paragraph" href="#p2724ce19ae53a641" name="p2724ce19ae53a641"> ¶ </a>To be able to do more complex requests, the function could be made to
+accept extra parameters to specify the method (<code>GET</code> or <code>POST</code>), an
+optional string to post as data, a way to add extra headers, and so
+on. When you have so many arguments, you'd probably want to pass them
+as an arguments-object as seen in <a href="chapter9.html">chapter 9</a>.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p3ab80399325e0221" name="p3ab80399325e0221"> </a>Some websites make use of intensive communication between the programs
+running on the client and the programs running on the server. For such
+systems, it can be practical to think of some HTTP requests as calls
+to functions that run on the server. The client makes request to URLs
+that identify the functions, giving the arguments as URL parameters or
+<code>POST</code> data. The server then calls the function, and puts the result
+into JSON or XML document that it sends back. If you write a few
+convenient support functions, this can make calling server-side
+functions almost as easy as calling client-side ones... except, of
+course, that you do not get their results instantly.</p></div><ol class="footnotes"><li><a name="footnote1"></a>These are not the only types of requests. There is also <code>HEAD</code>, to
+request just the headers for a document, not its content, <code>PUT</code>, to
+add a document to a server, and <code>DELETE</code>, to delete a document. These
+are not used by browsers, and often not supported by web-servers, but
+― if you add server-side programs to support them ― they can be
+useful.</li><li><a name="footnote2"></a>Not only the 'XML' part of the <code>XMLHttpRequest</code> name is misleading
+― the object can also be used for request over protocols other than
+HTTP, so <code>Request</code> is the only meaningful part we have left.</li><li><a name="footnote3"></a><code>0</code> ('uninitialized') is the state of the object before <code>open</code> is
+called on it. Calling <code>open</code> moves it to <code>1</code> ('open'). Calling <code>send</code>
+makes it proceed to <code>2</code> ('sent'). When the server responds, it goes to
+<code>3</code> ('receiving'). Finally, <code>4</code> means 'loaded'.</li><li><a name="footnote4"></a>We already saw <code>\n</code>, which is a newline. <code>\t</code> is a tab character,
+<code>\r</code> a 'carriage return', which some systems use before or instead of
+a newline to indicate the end of a line. <code>\b</code> (backspace), <code>\v</code>
+(vertical tab), and <code>\f</code> (form feed) are useful when working with old
+printers, but less so when dealing with Internet browsers.</li></ol><h1><span class="number">Appendix 1: </span>More (obscure) control structures</h1><div class="block"><p><a class="paragraph" href="#p317185e14fa160d2" name="p317185e14fa160d2"> </a>In <a href="chapter2.html">chapter 2</a>, a number of control statements were introduced, such as
+<code>while</code>, <code>for</code>, and <code>break</code>. To keep things simple, I left out some
+others, which, in my experience, are a lot less useful. This appendix
+briefly describes these missing control statements.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p7e8d95a2e61cb3be" name="p7e8d95a2e61cb3be"> </a>First, there is <a name="key1"></a><code>do</code>. <code>do</code> works like <code>while</code>, but instead of
+executing the loop body zero or more times, it executes it one or more
+times. A <code>do</code> loop looks like this:</p><pre class="code"><span class="keyword">do</span> {
+ <span class="keyword">var</span> <span class="variable">answer</span> = <span class="variable">prompt</span>(<span class="string">"Say 'moo'."</span>, <span class="string">""</span>);
+ <span class="variable">print</span>(<span class="string">"You said '"</span>, <span class="variable">answer</span>, <span class="string">"'."</span>);
+} <span class="keyword">while</span> (<span class="variable">answer</span> != <span class="string">"moo"</span>);</pre><p><a class="paragraph" href="#p5a5805128b83f50d" name="p5a5805128b83f50d"> </a>To emphasise the fact that the condition is only checked <em>after</em> the
+loop has run once, it is written at the end of the loop's body.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p50a14029a5eb8c80" name="p50a14029a5eb8c80"> </a>Next, there is <a name="key2"></a><code>continue</code>. This one is closely related to <code>break</code>,
+and can be used in the same places. While <code>break</code> jumps <em>out</em> of a
+loop and causes the program to proceed after the loop, <code>continue</code>
+jumps to the next iteration of the loop.</p><pre class="code"><span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">i</span> = <span class="atom">0</span>; <span class="variable">i</span> < <span class="atom">10</span>; <span class="variable">i</span>++) {
+ <span class="keyword">if</span> (<span class="variable">i</span> % <span class="atom">3</span> != <span class="atom">0</span>)
+ <span class="keyword">continue</span>;
+ <span class="variable">print</span>(<span class="variable">i</span>, <span class="string">" is divisible by three."</span>);
+}</pre><p><a class="paragraph" href="#p1c12755797c60807" name="p1c12755797c60807"> </a>A similar effect can usually be produced using just <code>if</code>, but there
+are cases where <code>continue</code> looks nicer.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p1888c5ed0ed59323" name="p1888c5ed0ed59323"> </a>When there is a loop sitting inside another loop, a <code>break</code> or
+<code>continue</code> statement will affect only the inner loop. Sometimes you
+want to jump out of the <em>outer</em> loop. To be able to refer to a
+specific loop, loop statements can be <a name="key3"></a>labelled. A label is a name
+(any valid variable name will do), followed by a colon (<code>:</code>).</p><pre class="code"><span class="property">outer</span>: <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">sideA</span> = <span class="atom">1</span>; <span class="variable">sideA</span> < <span class="atom">10</span>; <span class="variable">sideA</span>++) {
+ <span class="property">inner</span>: <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">sideB</span> = <span class="atom">1</span>; <span class="variable">sideB</span> < <span class="atom">10</span>; <span class="variable">sideB</span>++) {
+ <span class="keyword">var</span> <span class="variable">hypotenuse</span> = <span class="variable">Math</span>.<span class="property">sqrt</span>(<span class="variable">sideA</span> * <span class="variable">sideA</span> + <span class="variable">sideB</span> * <span class="variable">sideB</span>);
+ <span class="keyword">if</span> (<span class="variable">hypotenuse</span> % <span class="atom">1</span> == <span class="atom">0</span>) {
+ <span class="variable">print</span>(<span class="string">"A right triangle with straight sides of length "</span>,
+ <span class="variable">sideA</span>, <span class="string">" and "</span>, <span class="variable">sideB</span>, <span class="string">" has a hypotenuse of "</span>,
+ <span class="variable">hypotenuse</span>, <span class="string">"."</span>);
+ <span class="keyword">break</span> <span class="variable">outer</span>;
+ }
+ }
+}</pre></div><hr/><div class="block"><p><a class="paragraph" href="#p32873086b52cd02b" name="p32873086b52cd02b"> </a>Next, there is a construct called <a name="key4"></a><code>switch</code> which can be used to
+choose which code to execute based on some value. This is a very
+useful thing to do, but the syntax JavaScript uses for this (which it
+took from the C programming language) is so clumsy and ugly that I
+usually prefer to use a chain of <code>if</code> statements instead.</p><pre class="code"><span class="keyword">function</span> <span class="variable">weatherAdvice</span>(<span class="variabledef">weather</span>) {
+ <span class="keyword">switch</span>(<span class="localvariable">weather</span>) {
+ <span class="keyword">case</span> <span class="string">"rainy"</span>:
+ <span class="variable">print</span>(<span class="string">"Remember to bring an umbrella."</span>);
+ <span class="keyword">break</span>;
+ <span class="keyword">case</span> <span class="string">"sunny"</span>:
+ <span class="variable">print</span>(<span class="string">"Dress lightly."</span>);
+ <span class="keyword">case</span> <span class="string">"cloudy"</span>:
+ <span class="variable">print</span>(<span class="string">"Go outside."</span>);
+ <span class="keyword">break</span>;
+ <span class="property">default</span>:
+ <span class="variable">print</span>(<span class="string">"Unknown weather type: "</span>, <span class="localvariable">weather</span>);
+ <span class="keyword">break</span>;
+ }
+}
+
+<span class="variable">weatherAdvice</span>(<span class="string">"sunny"</span>);</pre><p><a class="paragraph" href="#p5bc54c4dd14212f3" name="p5bc54c4dd14212f3"> </a>Inside the block opened by <code>switch</code>, you can write a number of <code>case</code>
+labels. The program will jump to the label that corresponds to the
+value that <code>switch</code> was given (comparing the values with an equivalent
+of <code>===</code>, so without automatic type conversion), or to <code>default</code> if no
+matching value is found. Then it start executing statements there, and
+<em>continues</em> past other labels, until it reaches a <code>break</code> statement.
+In some cases, such as the <code>"sunny"</code> case in the example, this can be
+used to share some code between cases (it recommends going outside for
+both sunny and cloudy weather). Most of the time, this just adds a lot
+of ugly <code>break</code> statements, or causes problems when you forget to add
+one.</p><p><a class="paragraph" href="#p7d48e03d02d681a3" name="p7d48e03d02d681a3"> </a>Like loops, <code>switch</code> statements can be given a label.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p684cc333a8c52df1" name="p684cc333a8c52df1"> </a>Finally, there is a keyword named <a name="key5"></a><code>with</code>. I've never actually <em>used</em>
+this in a real program, but I have seen other people use it, so it is
+useful to know what it is. Code using <code>with</code> looks like this:</p><pre class="code"><span class="keyword">var</span> <span class="variable">scope</span> = <span class="string">"outside"</span>;
+<span class="keyword">var</span> <span class="variable">object</span> = {<span class="property">name</span>: <span class="string">"Ignatius"</span>, <span class="property">scope</span>: <span class="string">"inside"</span>};
+<span class="keyword">with</span>(<span class="variable">object</span>) {
+ <span class="variable">print</span>(<span class="string">"Name == "</span>, <span class="variable">name</span>, <span class="string">", scope == "</span>, <span class="variable">scope</span>);
+ <span class="variable">name</span> = <span class="string">"Raoul"</span>;
+ <span class="keyword">var</span> <span class="variable">newVariable</span> = <span class="atom">49</span>;
+}
+<span class="variable">show</span>(<span class="variable">object</span>.<span class="property">name</span>);
+<span class="variable">show</span>(<span class="variable">newVariable</span>);</pre><p><a class="paragraph" href="#p63b8a153093e63a" name="p63b8a153093e63a"> </a>Inside the block, the properties of the object given to <code>with</code> act as
+variables. Newly introduced variables are <em>not</em> added as properties to
+this object though. I assume the idea behind this construct was that
+it could be useful in methods that make lots of use of the properties
+of their object. You could start such a method with <code>with(this)
+{...}</code>, and not have to write <code>this</code> all the time after that.</p></div><h1><span class="number">Appendix 2: </span>Binary Heaps</h1><div class="block"><p><a class="paragraph" href="#p3ad51e69b1d4637a" name="p3ad51e69b1d4637a"> </a>In <a href="chapter7.html">chapter 7</a>, the <a name="key1"></a>binary heap was introduced as a method to store a
+collection of objects in such a way that the smallest element can be
+quickly found. As promised, this appendix will explain the details
+behind this data structure.</p><p><a class="paragraph" href="#p16c209ac0cec8fab" name="p16c209ac0cec8fab"> </a>Consider again the problem we needed to solve. The A* algorithm
+created large amounts of small objects, and had to keep these in an
+'open list'. It was also constantly removing the smallest element from
+this list. The simplest approach would be to just keep all the objects
+in an array, and search for the smallest one when we need it. But,
+unless we have a <em>lot</em> of time, this will not do. Finding the smallest
+element in an unsorted array requires going over the whole array, and
+checking each element.</p><p><a class="paragraph" href="#p572276834a90ce58" name="p572276834a90ce58"> </a>The next solution would be, of course, to sort our array. JavaScript
+arrays have a wonderful <a name="key2"></a><code>sort</code> method, which can be used to do the
+heavy work. Unfortunately, re-sorting a whole array every time an
+element is added is more work than searching for a minimum value in
+an unsorted array. Some tricks can be used, such as, instead of
+re-sorting the whole array, just making sure new values are inserted
+in the right place so that the array, which was sorted before, stays
+sorted. This is coming closer to the approach a binary heap uses
+already, but inserting a value in the middle of an array requires
+moving all the elements after it one place up, which is still just too
+slow.</p><p><a class="paragraph" href="#p133087e88d1a67df" name="p133087e88d1a67df"> </a>Another approach is to not use an array at all, but to store the
+values in a set of interconnected objects. A simple form of this is to
+have every object hold one value and two (or less) links to other
+objects. There is one root object, holding the smallest value, which
+is used to access all the other objects. Links always point to objects
+holding greater values, so the whole structure looks something like
+this:</p><div class="illustration"><img src="img/tree.png"/></div><p><a class="paragraph" href="#p27ce575d43ee567" name="p27ce575d43ee567"> </a>Such structures are usually called <a name="key3"></a>trees, because of the way they
+branch. Now, when you need the smallest element, you just take off the
+top element and rearrange the tree so that one of the top element's
+children ― the one with the lowest value ― becomes the new top. When
+inserting new elements, you 'descend' the tree until you find an
+element less than the new element, and insert it there. This takes a
+lot less searching than a sorted array does, but it has the
+disadvantage of creating a lot of objects, which also slows things
+down.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p7859b5b1b88ff0df" name="p7859b5b1b88ff0df"> </a>A binary heap, then, does make use of a sorted array, but it is only
+partially sorted, much like the tree above. Instead of objects, the
+positions in the array are used to form a tree, as this picture tries
+to show:</p><div class="illustration"><img src="img/heap.png"/></div><p><a class="paragraph" href="#p7867b77b4b2c7639" name="p7867b77b4b2c7639"> </a>Array element <code>1</code> is the root of the tree, array element <code>2</code> and <code>3</code>
+are its children, and in general array element <code>X</code> has children <code>X *
+2</code> and <code>X * 2 + 1</code>. You can see why this structure is called a 'heap'.
+Note that this array starts at <code>1</code>, while JavaScript arrays start at
+<code>0</code>. The heap will always keep the smallest element in position <code>1</code>,
+and make sure that for every element in the array at position <code>X</code>, the
+element at <code>X / 2</code> (round down) is smaller.</p><p><a class="paragraph" href="#p306dfd56ae39b23a" name="p306dfd56ae39b23a"> </a>Finding the smallest element is now a matter of taking the element at
+position <code>1</code>. But when this element is removed, the heap must make
+sure that there are no holes left in the array. To do this, it takes
+the last element in the array and moves it to the start, and then
+compares it to its child elements at position <code>2</code> and <code>3</code>. It is
+likely to be greater, so it is exchanged with one of them, and the
+process of comparing it with its children is repeated for the new
+position, and so on, until it comes to a position where its children
+are greater, or a position where it has no children.</p><pre class="preformatted">[2, 3, 5, 4, 8, 7, 6]
+Take out 2, move 6 to the front.
+[6, 3, 5, 4, 8, 7]
+6 is greater than its first child 3, so swap them.
+[3, 6, 5, 4, 8, 7]
+Now 6 has children 4 and 8 (position 4 and 5). It is greater than
+4, so we swap again.
+[3, 4, 5, 6, 8, 7]
+6 is in position 4, and has no more children. The heap is in order
+again.</pre><p><a class="paragraph" href="#p4e546a29c19b6c57" name="p4e546a29c19b6c57"> </a>Similarly, when an element has to be added to the heap, it is put at
+the end of the array and allowed to 'bubble' up by repeatedly
+exchanging it with its parent, until we find a parent that is less
+than the new node.</p><pre class="preformatted">[3, 4, 5, 6, 8, 7]
+Element 2 gets added again, it starts at the back.
+[3, 4, 5, 6, 8, 7, 2]
+2 is in position 7, its parent is at 3, which is a 5. 5 is greater
+than 2, so we swap.
+[3, 4, 2, 6, 8, 7, 5]
+The parent of position 3 is position 1. Again, we swap.
+[2, 4, 3, 6, 8, 7, 5]
+The element can not go further than position 1, so we are done.</pre><p><a class="paragraph" href="#p32a5a6cbb1fc90f1" name="p32a5a6cbb1fc90f1"> </a>Note how adding or inserting an element does not require it to be
+compared with every element in the array. In fact, because the jumps
+between parents and children get bigger as the array gets bigger, this
+advantage is especially large when we have a lot of elements<a class="footref" href="#footnote1">1</a>.</p></div><hr/><div class="block"><p><a class="paragraph" href="#p75d2422111be5673" name="p75d2422111be5673"> </a>Here is the full code of a binary heap implementation. Two things to
+note are that, instead of directly comparing the elements put into the
+heap, a function (<code>scoreFunction</code>) is first applied to them, so that
+it becomes possible to store objects that can not be directly
+compared.</p><p><a class="paragraph" href="#p1ece19e94713954c" name="p1ece19e94713954c"> </a>Also, because JavaScript arrays start at <code>0</code>, and the parent/child
+calculations use a system that starts at <code>1</code>, there are a few strange
+calculations to compensate.</p><pre class="code"><span class="keyword">function</span> <span class="variable">BinaryHeap</span>(<span class="variabledef">scoreFunction</span>){
+ <span class="localvariable">this</span>.<span class="property">content</span> = [];
+ <span class="localvariable">this</span>.<span class="property">scoreFunction</span> = <span class="localvariable">scoreFunction</span>;
+}
+
+<span class="variable">BinaryHeap</span>.<span class="property">prototype</span> = {
+ <span class="property">push</span>: <span class="keyword">function</span>(<span class="variabledef">element</span>) {
+ <span class="comment">// Add the new element to the end of the array.</span>
+ <span class="localvariable">this</span>.<span class="property">content</span>.<span class="property">push</span>(<span class="localvariable">element</span>);
+ <span class="comment">// Allow it to bubble up.</span>
+ <span class="localvariable">this</span>.<span class="property">bubbleUp</span>(<span class="localvariable">this</span>.<span class="property">content</span>.<span class="property">length</span> - <span class="atom">1</span>);
+ },
+
+ <span class="property">pop</span>: <span class="keyword">function</span>() {
+ <span class="comment">// Store the first element so we can return it later.</span>
+ <span class="keyword">var</span> <span class="variabledef">result</span> = <span class="localvariable">this</span>.<span class="property">content</span>[<span class="atom">0</span>];
+ <span class="comment">// Get the element at the end of the array.</span>
+ <span class="keyword">var</span> <span class="variabledef">end</span> = <span class="localvariable">this</span>.<span class="property">content</span>.<span class="property">pop</span>();
+ <span class="comment">// If there are any elements left, put the end element at the</span>
+ <span class="comment">// start, and let it sink down.</span>
+ <span class="keyword">if</span> (<span class="localvariable">this</span>.<span class="property">content</span>.<span class="property">length</span> > <span class="atom">0</span>) {
+ <span class="localvariable">this</span>.<span class="property">content</span>[<span class="atom">0</span>] = <span class="localvariable">end</span>;
+ <span class="localvariable">this</span>.<span class="property">sinkDown</span>(<span class="atom">0</span>);
+ }
+ <span class="keyword">return</span> <span class="localvariable">result</span>;
+ },
+
+ <span class="property">remove</span>: <span class="keyword">function</span>(<span class="variabledef">node</span>) {
+ <span class="keyword">var</span> <span class="variabledef">length</span> = <span class="localvariable">this</span>.<span class="property">content</span>.<span class="property">length</span>;
+ <span class="comment">// To remove a value, we must search through the array to find</span>
+ <span class="comment">// it.</span>
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variabledef">i</span> = <span class="atom">0</span>; <span class="localvariable">i</span> < <span class="localvariable">length</span>; <span class="localvariable">i</span>++) {
+ <span class="keyword">if</span> (<span class="localvariable">this</span>.<span class="property">content</span>[<span class="localvariable">i</span>] != <span class="localvariable">node</span>) <span class="keyword">continue</span>;
+ <span class="comment">// When it is found, the process seen in 'pop' is repeated</span>
+ <span class="comment">// to fill up the hole.</span>
+ <span class="keyword">var</span> <span class="variabledef">end</span> = <span class="localvariable">this</span>.<span class="property">content</span>.<span class="property">pop</span>();
+ <span class="comment">// If the element we popped was the one we needed to remove,</span>
+ <span class="comment">// we're done.</span>
+ <span class="keyword">if</span> (<span class="localvariable">i</span> == <span class="localvariable">length</span> - <span class="atom">1</span>) <span class="keyword">break</span>;
+ <span class="comment">// Otherwise, we replace the removed element with the popped</span>
+ <span class="comment">// one, and allow it to float up or sink down as appropriate.</span>
+ <span class="localvariable">this</span>.<span class="property">content</span>[<span class="localvariable">i</span>] = <span class="localvariable">end</span>;
+ <span class="localvariable">this</span>.<span class="property">bubbleUp</span>(<span class="localvariable">i</span>);
+ <span class="localvariable">this</span>.<span class="property">sinkDown</span>(<span class="localvariable">i</span>);
+ <span class="keyword">break</span>;
+ }
+ },
+
+ <span class="property">size</span>: <span class="keyword">function</span>() {
+ <span class="keyword">return</span> <span class="localvariable">this</span>.<span class="property">content</span>.<span class="property">length</span>;
+ },
+
+ <span class="property">bubbleUp</span>: <span class="keyword">function</span>(<span class="variabledef">n</span>) {
+ <span class="comment">// Fetch the element that has to be moved.</span>
+ <span class="keyword">var</span> <span class="variabledef">element</span> = <span class="localvariable">this</span>.<span class="property">content</span>[<span class="localvariable">n</span>], <span class="variabledef">score</span> = <span class="localvariable">this</span>.<span class="property">scoreFunction</span>(<span class="localvariable">element</span>);
+ <span class="comment">// When at 0, an element can not go up any further.</span>
+ <span class="keyword">while</span> (<span class="localvariable">n</span> > <span class="atom">0</span>) {
+ <span class="comment">// Compute the parent element's index, and fetch it.</span>
+ <span class="keyword">var</span> <span class="variabledef">parentN</span> = <span class="variable">Math</span>.<span class="property">floor</span>((<span class="localvariable">n</span> + <span class="atom">1</span>) / <span class="atom">2</span>) - <span class="atom">1</span>,
+ <span class="variabledef">parent</span> = <span class="localvariable">this</span>.<span class="property">content</span>[<span class="localvariable">parentN</span>];
+ <span class="comment">// If the parent has a lesser score, things are in order and we</span>
+ <span class="comment">// are done.</span>
+ <span class="keyword">if</span> (<span class="localvariable">score</span> >= <span class="localvariable">this</span>.<span class="property">scoreFunction</span>(<span class="localvariable">parent</span>))
+ <span class="keyword">break</span>;
+
+ <span class="comment">// Otherwise, swap the parent with the current element and</span>
+ <span class="comment">// continue.</span>
+ <span class="localvariable">this</span>.<span class="property">content</span>[<span class="localvariable">parentN</span>] = <span class="localvariable">element</span>;
+ <span class="localvariable">this</span>.<span class="property">content</span>[<span class="localvariable">n</span>] = <span class="localvariable">parent</span>;
+ <span class="localvariable">n</span> = <span class="localvariable">parentN</span>;
+ }
+ },
+
+ <span class="property">sinkDown</span>: <span class="keyword">function</span>(<span class="variabledef">n</span>) {
+ <span class="comment">// Look up the target element and its score.</span>
+ <span class="keyword">var</span> <span class="variabledef">length</span> = <span class="localvariable">this</span>.<span class="property">content</span>.<span class="property">length</span>,
+ <span class="variabledef">element</span> = <span class="localvariable">this</span>.<span class="property">content</span>[<span class="localvariable">n</span>],
+ <span class="variabledef">elemScore</span> = <span class="localvariable">this</span>.<span class="property">scoreFunction</span>(<span class="localvariable">element</span>);
+
+ <span class="keyword">while</span>(<span class="atom">true</span>) {
+ <span class="comment">// Compute the indices of the child elements.</span>
+ <span class="keyword">var</span> <span class="variabledef">child2N</span> = (<span class="localvariable">n</span> + <span class="atom">1</span>) * <span class="atom">2</span>, <span class="variabledef">child1N</span> = <span class="localvariable">child2N</span> - <span class="atom">1</span>;
+ <span class="comment">// This is used to store the new position of the element,</span>
+ <span class="comment">// if any.</span>
+ <span class="keyword">var</span> <span class="variabledef">swap</span> = <span class="atom">null</span>;
+ <span class="comment">// If the first child exists (is inside the array)...</span>
+ <span class="keyword">if</span> (<span class="localvariable">child1N</span> < <span class="localvariable">length</span>) {
+ <span class="comment">// Look it up and compute its score.</span>
+ <span class="keyword">var</span> <span class="variabledef">child1</span> = <span class="localvariable">this</span>.<span class="property">content</span>[<span class="localvariable">child1N</span>],
+ <span class="variabledef">child1Score</span> = <span class="localvariable">this</span>.<span class="property">scoreFunction</span>(<span class="localvariable">child1</span>);
+ <span class="comment">// If the score is less than our element's, we need to swap.</span>
+ <span class="keyword">if</span> (<span class="localvariable">child1Score</span> < <span class="localvariable">elemScore</span>)
+ <span class="localvariable">swap</span> = <span class="localvariable">child1N</span>;
+ }
+ <span class="comment">// Do the same checks for the other child.</span>
+ <span class="keyword">if</span> (<span class="localvariable">child2N</span> < <span class="localvariable">length</span>) {
+ <span class="keyword">var</span> <span class="variabledef">child2</span> = <span class="localvariable">this</span>.<span class="property">content</span>[<span class="localvariable">child2N</span>],
+ <span class="variabledef">child2Score</span> = <span class="localvariable">this</span>.<span class="property">scoreFunction</span>(<span class="localvariable">child2</span>);
+ <span class="keyword">if</span> (<span class="localvariable">child2Score</span> < (<span class="localvariable">swap</span> == <span class="atom">null</span> ? <span class="localvariable">elemScore</span> : <span class="localvariable">child1Score</span>))
+ <span class="localvariable">swap</span> = <span class="localvariable">child2N</span>;
+ }
+
+ <span class="comment">// No need to swap further, we are done.</span>
+ <span class="keyword">if</span> (<span class="localvariable">swap</span> == <span class="atom">null</span>) <span class="keyword">break</span>;
+
+ <span class="comment">// Otherwise, swap and continue.</span>
+ <span class="localvariable">this</span>.<span class="property">content</span>[<span class="localvariable">n</span>] = <span class="localvariable">this</span>.<span class="property">content</span>[<span class="localvariable">swap</span>];
+ <span class="localvariable">this</span>.<span class="property">content</span>[<span class="localvariable">swap</span>] = <span class="localvariable">element</span>;
+ <span class="localvariable">n</span> = <span class="localvariable">swap</span>;
+ }
+ }
+};</pre><p><a class="paragraph" href="#p52526691c872a7c" name="p52526691c872a7c"> </a>And a simple test...</p><pre class="code"><span class="keyword">var</span> <span class="variable">heap</span> = <span class="keyword">new</span> <span class="variable">BinaryHeap</span>(<span class="keyword">function</span>(<span class="variabledef">x</span>){<span class="keyword">return</span> <span class="localvariable">x</span>;});
+<span class="variable">forEach</span>([<span class="atom">10</span>, <span class="atom">3</span>, <span class="atom">4</span>, <span class="atom">8</span>, <span class="atom">2</span>, <span class="atom">9</span>, <span class="atom">7</span>, <span class="atom">1</span>, <span class="atom">2</span>, <span class="atom">6</span>, <span class="atom">5</span>],
+ <span class="variable">method</span>(<span class="variable">heap</span>, <span class="string">"push"</span>));
+
+<span class="variable">heap</span>.<span class="property">remove</span>(<span class="atom">2</span>);
+<span class="keyword">while</span> (<span class="variable">heap</span>.<span class="property">size</span>() > <span class="atom">0</span>)
+ <span class="variable">print</span>(<span class="variable">heap</span>.<span class="property">pop</span>());
+</pre></div><ol class="footnotes"><li><a name="footnote1"></a>The amount of comparisons and swaps that are needed ― in the worst
+case ― can be approached by taking the logarithm (base 2) of the
+amount of elements in the heap.</li></ol></div><div class="footer"> <a href="mailto:marijnh@gmail.com">Marijn Haverbeke</a> (<a href="http://creativecommons.org/licenses/by/3.0/">license</a>), written March to July 2007, last modified on November 28 2013.</div></body></html>
--- /dev/null
+<!doctype html>
+<html lang="en-GB">
+<head>
+ <meta charset="utf-8">
+ <title>ECMAScript Language Specification ECMA-262 6th Edition – DRAFT</title>
+ <link href="es6-draft.css" rel="stylesheet">
+ <script src="es6-draft-sections.js"></script>
+</head>
+<body>
+<div id="unofficial">
+ <p><strong>This is <em>not</em> the official ECMAScript Language Specification.</strong></p>
+
+ <p>This is a draft of the next edition of the standard. See also:</p>
+
+ <ul>
+ <li><a href="http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf">ECMAScript Language Specification,
+ Edition 5.1 (PDF)</a>, the most recent official, final standard.</li>
+ <li><a href="http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts">The ES specification drafts archive</a> for
+ PDF and Word versions of this document, and older drafts.</li>
+ <li><a href="https://github.com/jorendorff/es-spec-html">The script that produced this web page</a>, and especially the <a
+ href="https://github.com/jorendorff/es-spec-html/issues?state=open">issue tracker — please file bugs when you find
+ them</a>. Patches are welcome too.</li>
+ </ul>
+
+ <p>For copyright information, see Ecma International’s legal disclaimer in the document itself.</p>
+</div>
+
+<hgroup>
+ <h1>ECMA-262</h1>
+ <h1>6<sup>th</sup> Edition / Draft May 22, 2014</h1>
+ <h1>Draft</h1>
+</hgroup>
+<hgroup>
+ <h1>ECMAScript Language Specification</h1>
+
+ <p>Draft</p>
+
+ <p>Report Errors and Issues at: https://bugs.ecmascript.org</p>
+
+ <p>Product: Draft for 6th Edition</p>
+
+ <p>Component: choose an appropriate one</p>
+
+ <p>Version: Rev 25, May 22, 2014 Draft</p>
+
+ <h1>Ecma/TC39/2014/0xx</h1>
+</hgroup>
+
+<section id="contents">
+ <h1>Contents</h1>
+ <ol class="toc">
+ <li>Introduction</li>
+ <li><span class="secnum"><a href="#sec-scope">1</a></span> Scope</li>
+ <li><span class="secnum"><a href="#sec-conformance">2</a></span> Conformance</li>
+ <li><span class="secnum"><a href="#sec-normative-references">3</a></span> Normative references</li>
+ <li><span class="secnum"><a href="#sec-overview">4</a></span> Overview
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-web-scripting">4.1</a></span> Web Scripting</li>
+ <li><span class="secnum"><a href="#sec-ecmascript-overview">4.2</a></span> ECMAScript Overview
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-objects">4.2.1</a></span> Objects</li>
+ <li><span class="secnum"><a href="#sec-strict-variant-of-ecmascript">4.2.2</a></span> The Strict Variant of
+ ECMAScript</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-terms-and-definitions">4.3</a></span> Terms and definitions
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-type">4.3.1</a></span> type</li>
+ <li><span class="secnum"><a href="#sec-primitive-value">4.3.2</a></span> primitive value</li>
+ <li><span class="secnum"><a href="#sec-terms-and-definitions-object">4.3.3</a></span> object</li>
+ <li><span class="secnum"><a href="#sec-constructor">4.3.4</a></span> constructor</li>
+ <li><span class="secnum"><a href="#sec-terms-and-definitions-prototype">4.3.5</a></span> prototype</li>
+ <li><span class="secnum"><a href="#sec-ordinary-object">4.3.6</a></span> ordinary object</li>
+ <li><span class="secnum"><a href="#sec-exotic-object">4.3.7</a></span> exotic object</li>
+ <li><span class="secnum"><a href="#sec-standard-object">4.3.8</a></span> standard object</li>
+ <li><span class="secnum"><a href="#sec-built-in-object">4.3.9</a></span> built-in object</li>
+ <li><span class="secnum"><a href="#sec-undefined-value">4.3.10</a></span> undefined value</li>
+ <li><span class="secnum"><a href="#sec-terms-and-definitions-undefined-type">4.3.11</a></span> Undefined type</li>
+ <li><span class="secnum"><a href="#sec-null-value">4.3.12</a></span> null value</li>
+ <li><span class="secnum"><a href="#sec-terms-and-definitions-null-type">4.3.13</a></span> Null type</li>
+ <li><span class="secnum"><a href="#sec-terms-and-definitions-boolean-value">4.3.14</a></span> Boolean value</li>
+ <li><span class="secnum"><a href="#sec-terms-and-definitions-boolean-type">4.3.15</a></span> Boolean type</li>
+ <li><span class="secnum"><a href="#sec-boolean-object">4.3.16</a></span> Boolean object</li>
+ <li><span class="secnum"><a href="#sec-terms-and-definitions-string-value">4.3.17</a></span> String value</li>
+ <li><span class="secnum"><a href="#sec-terms-and-definitions-string-type">4.3.18</a></span> String type</li>
+ <li><span class="secnum"><a href="#sec-string-object">4.3.19</a></span> String object</li>
+ <li><span class="secnum"><a href="#sec-terms-and-definitions-number-value">4.3.20</a></span> Number value</li>
+ <li><span class="secnum"><a href="#sec-terms-and-definitions-number-type">4.3.21</a></span> Number type</li>
+ <li><span class="secnum"><a href="#sec-number-object">4.3.22</a></span> Number object</li>
+ <li><span class="secnum"><a href="#sec-terms-and-definitions-infinity">4.3.23</a></span> Infinity</li>
+ <li><span class="secnum"><a href="#sec-terms-and-definitions-nan">4.3.24</a></span> NaN</li>
+ <li><span class="secnum"><a href="#sec-symbol-value">4.3.25</a></span> Symbol value</li>
+ <li><span class="secnum"><a href="#sec-terms-and-definitions-symbol-type">4.3.26</a></span> Symbol type</li>
+ <li><span class="secnum"><a href="#sec-symbol-object">4.3.27</a></span> Symbol object</li>
+ <li><span class="secnum"><a href="#sec-terms-and-definitions-function">4.3.28</a></span> function</li>
+ <li><span class="secnum"><a href="#sec-built-in-function">4.3.29</a></span> built-in function</li>
+ <li><span class="secnum"><a href="#sec-property">4.3.30</a></span> property</li>
+ <li><span class="secnum"><a href="#sec-method">4.3.31</a></span> method</li>
+ <li><span class="secnum"><a href="#sec-built-in-method">4.3.32</a></span> built-in method</li>
+ <li><span class="secnum"><a href="#sec-attribute">4.3.33</a></span> attribute</li>
+ <li><span class="secnum"><a href="#sec-own-property">4.3.34</a></span> own property</li>
+ <li><span class="secnum"><a href="#sec-inherited-property">4.3.35</a></span> inherited property</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-organization-of-this-specification">4.4</a></span> Organization of This
+ Specification</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-notational-conventions">5</a></span> Notational Conventions
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-syntactic-and-lexical-grammars">5.1</a></span> Syntactic and Lexical Grammars
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-context-free-grammars">5.1.1</a></span> Context-Free Grammars</li>
+ <li><span class="secnum"><a href="#sec-lexical-and-regexp-grammars">5.1.2</a></span> The Lexical and RegExp
+ Grammars</li>
+ <li><span class="secnum"><a href="#sec-numeric-string-grammar">5.1.3</a></span> The Numeric String Grammar</li>
+ <li><span class="secnum"><a href="#sec-syntactic-grammar">5.1.4</a></span> The Syntactic Grammar</li>
+ <li><span class="secnum"><a href="#sec-grammar-notation">5.1.5</a></span> Grammar Notation</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-algorithm-conventions">5.2</a></span> Algorithm Conventions</li>
+ <li><span class="secnum"><a href="#sec-static-semantic-rules">5.3</a></span> Static Semantic Rules</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-ecmascript-data-types-and-values">6</a></span> ECMAScript Data Types and Values
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-ecmascript-language-types">6.1</a></span> ECMAScript Language Types
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-ecmascript-language-types-undefined-type">6.1.1</a></span> The Undefined
+ Type</li>
+ <li><span class="secnum"><a href="#sec-ecmascript-language-types-null-type">6.1.2</a></span> The Null Type</li>
+ <li><span class="secnum"><a href="#sec-ecmascript-language-types-boolean-type">6.1.3</a></span> The Boolean Type</li>
+ <li><span class="secnum"><a href="#sec-ecmascript-language-types-string-type">6.1.4</a></span> The String Type</li>
+ <li><span class="secnum"><a href="#sec-ecmascript-language-types-symbol-type">6.1.5</a></span> The Symbol Type</li>
+ <li><span class="secnum"><a href="#sec-ecmascript-language-types-number-type">6.1.6</a></span> The Number Type</li>
+ <li><span class="secnum"><a href="#sec-object-type">6.1.7</a></span> The Object Type</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-ecmascript-specification-types">6.2</a></span> ECMAScript Specification Types
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-list-and-record-specification-type">6.2.1</a></span> The List and Record
+ Specification Type</li>
+ <li><span class="secnum"><a href="#sec-completion-record-specification-type">6.2.2</a></span> The Completion Record
+ Specification Type</li>
+ <li><span class="secnum"><a href="#sec-reference-specification-type">6.2.3</a></span> The Reference Specification
+ Type</li>
+ <li><span class="secnum"><a href="#sec-property-descriptor-specification-type">6.2.4</a></span> The Property
+ Descriptor Specification Type</li>
+ <li><span class="secnum"><a
+ href="#sec-lexical-environment-and-environment-record-specification-types">6.2.5</a></span> The Lexical
+ Environment and Environment Record Specification Types</li>
+ <li><span class="secnum"><a href="#sec-data-blocks">6.2.6</a></span> Data Blocks</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-abstract-operations">7</a></span> Abstract Operations
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-type-conversion-and-testing">7.1</a></span> Type Conversion and Testing
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-toprimitive">7.1.1</a></span> ToPrimitive</li>
+ <li><span class="secnum"><a href="#sec-toboolean">7.1.2</a></span> ToBoolean</li>
+ <li><span class="secnum"><a href="#sec-tonumber">7.1.3</a></span> ToNumber</li>
+ <li><span class="secnum"><a href="#sec-tointeger">7.1.4</a></span> ToInteger</li>
+ <li><span class="secnum"><a href="#sec-toint32">7.1.5</a></span> ToInt32: (Signed 32 Bit Integer)</li>
+ <li><span class="secnum"><a href="#sec-touint32">7.1.6</a></span> ToUint32: (Unsigned 32 Bit Integer)</li>
+ <li><span class="secnum"><a href="#sec-toint16">7.1.7</a></span> ToInt16: (Signed 16 Bit Integer)</li>
+ <li><span class="secnum"><a href="#sec-touint16">7.1.8</a></span> ToUint16: (Unsigned 16 Bit Integer)</li>
+ <li><span class="secnum"><a href="#sec-toint8">7.1.9</a></span> ToInt8: (Signed 8 Bit Integer)</li>
+ <li><span class="secnum"><a href="#sec-touint8">7.1.10</a></span> ToUint8: (Unsigned 8 Bit Integer)</li>
+ <li><span class="secnum"><a href="#sec-touint8clamp">7.1.11</a></span> ToUint8Clamp: (Unsigned 8 Bit Integer,
+ Clamped)</li>
+ <li><span class="secnum"><a href="#sec-tostring">7.1.12</a></span> ToString</li>
+ <li><span class="secnum"><a href="#sec-toobject">7.1.13</a></span> ToObject</li>
+ <li><span class="secnum"><a href="#sec-topropertykey">7.1.14</a></span> ToPropertyKey</li>
+ <li><span class="secnum"><a href="#sec-tolength">7.1.15</a></span> ToLength</li>
+ <li><span class="secnum"><a href="#sec-canonicalnumericindexstring">7.1.16</a></span>
+ CanonicalNumericIndexString(argument)</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-testing-and-comparison-operations">7.2</a></span> Testing and Comparison Operations
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-checkobjectcoercible">7.2.1</a></span> CheckObjectCoercible ( argument )</li>
+ <li><span class="secnum"><a href="#sec-iscallable">7.2.2</a></span> IsCallable ( argument )</li>
+ <li><span class="secnum"><a href="#sec-samevalue">7.2.3</a></span> SameValue(x, y)</li>
+ <li><span class="secnum"><a href="#sec-samevaluezero">7.2.4</a></span> SameValueZero(x, y)</li>
+ <li><span class="secnum"><a href="#sec-isconstructor">7.2.5</a></span> IsConstructor ( argument )</li>
+ <li><span class="secnum"><a href="#sec-ispropertykey">7.2.6</a></span> IsPropertyKey ( argument )</li>
+ <li><span class="secnum"><a href="#sec-isextensible-o">7.2.7</a></span> IsExtensible (O)</li>
+ <li><span class="secnum"><a href="#sec-isinteger">7.2.8</a></span> IsInteger ( argument )</li>
+ <li><span class="secnum"><a href="#sec-abstract-relational-comparison">7.2.9</a></span> Abstract Relational
+ Comparison</li>
+ <li><span class="secnum"><a href="#sec-abstract-equality-comparison">7.2.10</a></span> Abstract Equality
+ Comparison</li>
+ <li><span class="secnum"><a href="#sec-strict-equality-comparison">7.2.11</a></span> Strict Equality Comparison</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-operations-on-objects">7.3</a></span> Operations on Objects
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-get-o-p">7.3.1</a></span> Get (O, P)</li>
+ <li><span class="secnum"><a href="#sec-put-o-p-v-throw">7.3.2</a></span> Put (O, P, V, Throw)</li>
+ <li><span class="secnum"><a href="#sec-createdataproperty">7.3.3</a></span> CreateDataProperty (O, P, V)</li>
+ <li><span class="secnum"><a href="#sec-createdatapropertyorthrow">7.3.4</a></span> CreateDataPropertyOrThrow (O, P,
+ V)</li>
+ <li><span class="secnum"><a href="#sec-definepropertyorthrow">7.3.5</a></span> DefinePropertyOrThrow (O, P, desc)</li>
+ <li><span class="secnum"><a href="#sec-deletepropertyorthrow">7.3.6</a></span> DeletePropertyOrThrow (O, P)</li>
+ <li><span class="secnum"><a href="#sec-getmethod">7.3.7</a></span> GetMethod (O, P)</li>
+ <li><span class="secnum"><a href="#sec-hasproperty">7.3.8</a></span> HasProperty (O, P)</li>
+ <li><span class="secnum"><a href="#sec-hasownproperty">7.3.9</a></span> HasOwnProperty (O, P)</li>
+ <li><span class="secnum"><a href="#sec-invoke">7.3.10</a></span> Invoke(O,P, [args])</li>
+ <li><span class="secnum"><a href="#sec-setintegritylevel">7.3.11</a></span> SetIntegrityLevel (O, level)</li>
+ <li><span class="secnum"><a href="#sec-testintegritylevel">7.3.12</a></span> TestIntegrityLevel (O, level)</li>
+ <li><span class="secnum"><a href="#sec-createarrayfromlist">7.3.13</a></span> CreateArrayFromList (elements)</li>
+ <li><span class="secnum"><a href="#sec-createlistfromarraylike">7.3.14</a></span> CreateListFromArrayLike (obj)</li>
+ <li><span class="secnum"><a href="#sec-ordinaryhasinstance">7.3.15</a></span> OrdinaryHasInstance (C, O)</li>
+ <li><span class="secnum"><a href="#sec-getprototypefromconstructor">7.3.16</a></span> GetPrototypeFromConstructor (
+ constructor, intrinsicDefaultProto )</li>
+ <li><span class="secnum"><a href="#sec-createfromconstructor">7.3.17</a></span> CreateFromConstructor (F)</li>
+ <li><span class="secnum"><a href="#sec-construct-f-argumentslist">7.3.18</a></span> Construct (F, argumentsList)</li>
+ <li><span class="secnum"><a href="#sec-getoption">7.3.19</a></span> GetOption (options, P)</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-operations-on-iterator-objects">7.4</a></span> Operations on Iterator Objects
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-checkiterable">7.4.1</a></span> CheckIterable ( obj )</li>
+ <li><span class="secnum"><a href="#sec-getiterator">7.4.2</a></span> GetIterator ( obj, method )</li>
+ <li><span class="secnum"><a href="#sec-iteratornext">7.4.3</a></span> IteratorNext ( iterator, value )</li>
+ <li><span class="secnum"><a href="#sec-iteratorcomplete">7.4.4</a></span> IteratorComplete ( iterResult )</li>
+ <li><span class="secnum"><a href="#sec-iteratorvalue">7.4.5</a></span> IteratorValue ( iterResult )</li>
+ <li><span class="secnum"><a href="#sec-iteratorstep">7.4.6</a></span> IteratorStep ( iterator )</li>
+ <li><span class="secnum"><a href="#sec-createiterresultobject">7.4.7</a></span> CreateIterResultObject (value,
+ done)</li>
+ <li><span class="secnum"><a href="#sec-createlistiterator">7.4.8</a></span> CreateListIterator (list)</li>
+ <li><span class="secnum"><a href="#sec-createemptyiterator">7.4.9</a></span> CreateEmptyIterator ( )</li>
+ <li><span class="secnum"><a href="#sec-createcompounditerator">7.4.10</a></span> CreateCompoundIterator ( iterator1,
+ iterator2 )</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-operations-on-promise-objects">7.5</a></span> Operations on Promise Objects
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-promisenew">7.5.1</a></span> PromiseNew ( executor ) Abstract Operation</li>
+ <li><span class="secnum"><a href="#sec-promisebuiltincapability">7.5.2</a></span> PromiseBuiltinCapability () Abstract
+ Operation</li>
+ <li><span class="secnum"><a href="#sec-promiseof">7.5.3</a></span> PromiseOf (value) Abstract Operation</li>
+ <li><span class="secnum"><a href="#sec-promiseall">7.5.4</a></span> PromiseAll (promiseList) Abstract Operation</li>
+ <li><span class="secnum"><a href="#sec-promisecatch">7.5.5</a></span> PromiseCatch (promise, rejectedAction) Abstract
+ Operation</li>
+ <li><span class="secnum"><a href="#sec-promisethen">7.5.6</a></span> PromiseThen (promise, resolvedAction,
+ rejectedAction) Abstract Operation</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-executable-code-and-execution-contexts">8</a></span> Executable Code and Execution
+ Contexts
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-lexical-environments">8.1</a></span> Lexical Environments
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-environment-records">8.1.1</a></span> Environment Records</li>
+ <li><span class="secnum"><a href="#sec-lexical-environment-operations">8.1.2</a></span> Lexical Environment
+ Operations</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-code-realms">8.2</a></span> Code Realms
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-createrealm">8.2.1</a></span> CreateRealm ( ) Abstract Operation</li>
+ <li><span class="secnum"><a href="#sec-createintrinsics">8.2.2</a></span> CreateIntrinsics ( realmRec ) Abstract
+ Operation</li>
+ <li><span class="secnum"><a href="#sec-setrealmglobalobj">8.2.3</a></span> SetRealmGlobalObj ( realmRec, globalObj )
+ Abstract Operation</li>
+ <li><span class="secnum"><a href="#sec-setdefaultglobalbindings">8.2.4</a></span> SetDefaultGlobalBindings ( realmRec
+ ) Abstract Operation</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-execution-contexts">8.3</a></span> Execution Contexts
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-resolvebinding">8.3.1</a></span> ResolveBinding ( name ) Abstract
+ Operation</li>
+ <li><span class="secnum"><a href="#sec-getthisenvironment">8.3.2</a></span> GetThisEnvironment ( ) Abstract
+ Operation</li>
+ <li><span class="secnum"><a href="#sec-resolvethisbinding">8.3.3</a></span> ResolveThisBinding ( ) Abstract
+ Operation</li>
+ <li><span class="secnum"><a href="#sec-getglobalobject">8.3.4</a></span> GetGlobalObject ( ) Abstract Operation</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-tasks-and-task-queues">8.4</a></span> Tasks and Task Queues
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-enqueuetask">8.4.1</a></span> EnqueueTask ( queueName, task, arguments)
+ Abstract Operation</li>
+ <li><span class="secnum"><a href="#sec-nexttask-result">8.4.2</a></span> NextTask result</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-initialization">8.5</a></span> Initialization
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-initializefirstrealm">8.5.1</a></span> InitializeFirstRealm ( realm ) Abstract
+ Operation</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-ordinary-and-exotic-objects-behaviours">9</a></span> Ordinary and Exotic Objects
+ Behaviours
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-ordinary-object-internal-methods-and-internal-slots">9.1</a></span> Ordinary Object
+ Internal Methods and Internal Slots
+ <ol class="toc">
+ <li><span class="secnum"><a
+ href="#sec-ordinary-object-internal-methods-and-internal-slots-getprototypeof">9.1.1</a></span> [[GetPrototypeOf]]
+ ( )</li>
+ <li><span class="secnum"><a
+ href="#sec-ordinary-object-internal-methods-and-internal-slots-setprototypeof-v">9.1.2</a></span>
+ [[SetPrototypeOf]] (V)</li>
+ <li><span class="secnum"><a
+ href="#sec-ordinary-object-internal-methods-and-internal-slots-isextensible">9.1.3</a></span> [[IsExtensible]] (
+ )</li>
+ <li><span class="secnum"><a
+ href="#sec-ordinary-object-internal-methods-and-internal-slots-preventextensions">9.1.4</a></span>
+ [[PreventExtensions]] ( )</li>
+ <li><span class="secnum"><a
+ href="#sec-ordinary-object-internal-methods-and-internal-slots-getownproperty-p">9.1.5</a></span>
+ [[GetOwnProperty]] (P)</li>
+ <li><span class="secnum"><a
+ href="#sec-ordinary-object-internal-methods-and-internal-slots-defineownproperty-p-desc">9.1.6</a></span>
+ [[DefineOwnProperty]] (P, Desc)</li>
+ <li><span class="secnum"><a
+ href="#sec-ordinary-object-internal-methods-and-internal-slots-hasproperty-p">9.1.7</a></span>
+ [[HasProperty]](P)</li>
+ <li><span class="secnum"><a
+ href="#sec-ordinary-object-internal-methods-and-internal-slots-get-p-receiver">9.1.8</a></span> [[Get]] (P,
+ Receiver)</li>
+ <li><span class="secnum"><a
+ href="#sec-ordinary-object-internal-methods-and-internal-slots-set-p-v-receiver">9.1.9</a></span> [[Set]] ( P, V,
+ Receiver)</li>
+ <li><span class="secnum"><a href="#sec-ordinary-object-internal-methods-and-internal-slots-delete-p">9.1.10</a></span>
+ [[Delete]] (P)</li>
+ <li><span class="secnum"><a
+ href="#sec-ordinary-object-internal-methods-and-internal-slots-enumerate">9.1.11</a></span> [[Enumerate]] ()</li>
+ <li><span class="secnum"><a
+ href="#sec-ordinary-object-internal-methods-and-internal-slots-ownpropertykeys">9.1.12</a></span>
+ [[OwnPropertyKeys]] ( )</li>
+ <li><span class="secnum"><a href="#sec-objectcreate">9.1.13</a></span> ObjectCreate(proto, internalSlotsList) Abstract
+ Operation</li>
+ <li><span class="secnum"><a href="#sec-ordinarycreatefromconstructor">9.1.14</a></span> OrdinaryCreateFromConstructor
+ ( constructor, intrinsicDefaultProto, internalSlotsList )</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-ecmascript-function-objects">9.2</a></span> ECMAScript Function Objects
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-ecmascript-function-objects-getownproperty-p">9.2.1</a></span>
+ [[GetOwnProperty]] (P)</li>
+ <li><span class="secnum"><a href="#sec-ecmascript-function-objects-call-thisargument-argumentslist">9.2.2</a></span>
+ [[Call]] ( thisArgument, argumentsList)</li>
+ <li><span class="secnum"><a href="#sec-construct-argumentslist">9.2.3</a></span> [[Construct]] ( argumentsList)</li>
+ <li><span class="secnum"><a href="#sec-functionallocate">9.2.4</a></span> FunctionAllocate (functionPrototype, strict)
+ Abstract Operation</li>
+ <li><span class="secnum"><a href="#sec-functioninitialize">9.2.5</a></span> FunctionInitialize (F, kind, Strict,
+ ParameterList, Body, Scope) Abstract Operation</li>
+ <li><span class="secnum"><a href="#sec-functioncreate">9.2.6</a></span> FunctionCreate (kind, ParameterList, Body,
+ Scope, Strict) Abstract Operation</li>
+ <li><span class="secnum"><a href="#sec-generatorfunctioncreate">9.2.7</a></span> GeneratorFunctionCreate (kind,
+ ParameterList, Body, Scope, Strict) Abstract Operation</li>
+ <li><span class="secnum"><a href="#sec-addrestrictedfunctionproperties">9.2.8</a></span>
+ AddRestrictedFunctionProperties ( F, realm ) Abstract Operation</li>
+ <li><span class="secnum"><a href="#sec-makeconstructor">9.2.9</a></span> MakeConstructor (F, writablePrototype,
+ prototype) Abstract Operation</li>
+ <li><span class="secnum"><a href="#sec-makemethod">9.2.10</a></span> MakeMethod ( F, methodName, homeObject) Abstract
+ Operation</li>
+ <li><span class="secnum"><a href="#sec-setfunctionname">9.2.11</a></span> SetFunctionName (F, name, prefix) Abstract
+ Operation</li>
+ <li><span class="secnum"><a href="#sec-clonemethod">9.2.12</a></span> CloneMethod(function, newHome, newName) Abstract
+ Operation</li>
+ <li><span class="secnum"><a href="#sec-functiondeclarationinstantiation">9.2.13</a></span>
+ FunctionDeclarationInstantiation(func, argumentsList, env ) Abstract Operation</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-built-in-function-objects">9.3</a></span> Built-in Function Objects
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-built-in-function-objects-call-thisargument-argumentslist">9.3.1</a></span>
+ [[Call]] ( thisArgument, argumentsList)</li>
+ <li><span class="secnum"><a href="#sec-createbuiltinfunction">9.3.2</a></span> CreateBuiltinFunction(realm, steps,
+ prototype, internalSlotsList) Abstract Operation</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-built-in-exotic-object-internal-methods-and-data-fields">9.4</a></span> Built-in
+ Exotic Object Internal Methods and Data Fields
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-bound-function-exotic-objects">9.4.1</a></span> Bound Function Exotic
+ Objects</li>
+ <li><span class="secnum"><a href="#sec-array-exotic-objects">9.4.2</a></span> Array Exotic Objects</li>
+ <li><span class="secnum"><a href="#sec-string-exotic-objects">9.4.3</a></span> String Exotic Objects</li>
+ <li><span class="secnum"><a href="#sec-arguments-exotic-objects">9.4.4</a></span> Arguments Exotic Objects</li>
+ <li><span class="secnum"><a href="#sec-integer-indexed-exotic-objects">9.4.5</a></span> Integer Indexed Exotic
+ Objects</li>
+ <li><span class="secnum"><a href="#sec-module-exotic-objects">9.4.6</a></span> Module Exotic Objects</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-proxy-object-internal-methods-and-internal-slots">9.5</a></span> Proxy Object
+ Internal Methods and Internal Slots
+ <ol class="toc">
+ <li><span class="secnum"><a
+ href="#sec-proxy-object-internal-methods-and-internal-slots-getprototypeof">9.5.1</a></span> [[GetPrototypeOf]] (
+ )</li>
+ <li><span class="secnum"><a
+ href="#sec-proxy-object-internal-methods-and-internal-slots-setprototypeof-v">9.5.2</a></span> [[SetPrototypeOf]]
+ (V)</li>
+ <li><span class="secnum"><a href="#sec-proxy-object-internal-methods-and-internal-slots-isextensible">9.5.3</a></span>
+ [[IsExtensible]] ( )</li>
+ <li><span class="secnum"><a
+ href="#sec-proxy-object-internal-methods-and-internal-slots-preventextensions">9.5.4</a></span>
+ [[PreventExtensions]] ( )</li>
+ <li><span class="secnum"><a
+ href="#sec-proxy-object-internal-methods-and-internal-slots-getownproperty-p">9.5.5</a></span> [[GetOwnProperty]]
+ (P)</li>
+ <li><span class="secnum"><a
+ href="#sec-proxy-object-internal-methods-and-internal-slots-defineownproperty-p-desc">9.5.6</a></span>
+ [[DefineOwnProperty]] (P, Desc)</li>
+ <li><span class="secnum"><a
+ href="#sec-proxy-object-internal-methods-and-internal-slots-hasproperty-p">9.5.7</a></span> [[HasProperty]]
+ (P)</li>
+ <li><span class="secnum"><a
+ href="#sec-proxy-object-internal-methods-and-internal-slots-get-p-receiver">9.5.8</a></span> [[Get]] (P,
+ Receiver)</li>
+ <li><span class="secnum"><a
+ href="#sec-proxy-object-internal-methods-and-internal-slots-set-p-v-receiver">9.5.9</a></span> [[Set]] ( P, V,
+ Receiver)</li>
+ <li><span class="secnum"><a href="#sec-proxy-object-internal-methods-and-internal-slots-delete-p">9.5.10</a></span>
+ [[Delete]] (P)</li>
+ <li><span class="secnum"><a href="#sec-proxy-object-internal-methods-and-internal-slots-enumerate">9.5.11</a></span>
+ [[Enumerate]] ()</li>
+ <li><span class="secnum"><a
+ href="#sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys">9.5.12</a></span> [[OwnPropertyKeys]]
+ ( )</li>
+ <li><span class="secnum"><a
+ href="#sec-proxy-object-internal-methods-and-internal-slots-call-thisargument-argumentslist">9.5.13</a></span>
+ [[Call]] (thisArgument, argumentsList)</li>
+ <li><span class="secnum"><a href="#sec-construct-internal-method">9.5.14</a></span> [[Construct]] Internal Method</li>
+ <li><span class="secnum"><a href="#sec-proxycreate">9.5.15</a></span> ProxyCreate(target, handler) Abstract
+ Operation</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-ecmascript-language-source-code">10</a></span> ECMAScript Language: Source Code
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-source-text">10.1</a></span> Source Text
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-static-semantics-utf-16encoding">10.1.1</a></span> Static Semantics:
+ <i>UTF-16Encoding</i></li>
+ <li><span class="secnum"><a href="#sec-utf16decode">10.1.2</a></span> Static Semantics: UTF16Decode(lead, trail)</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-types-of-source-code">10.2</a></span> Types of Source Code
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-strict-mode-code">10.2.1</a></span> Strict Mode Code</li>
+ <li><span class="secnum"><a href="#sec-non-ecmascript-functions">10.2.2</a></span> Non-ECMAScript Functions</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-ecmascript-language-lexical-grammar">11</a></span> ECMAScript Language: Lexical Grammar
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-unicode-format-control-characters">11.1</a></span> Unicode Format-Control
+ Characters</li>
+ <li><span class="secnum"><a href="#sec-white-space">11.2</a></span> White Space</li>
+ <li><span class="secnum"><a href="#sec-line-terminators">11.3</a></span> Line Terminators</li>
+ <li><span class="secnum"><a href="#sec-comments">11.4</a></span> Comments</li>
+ <li><span class="secnum"><a href="#sec-tokens">11.5</a></span> Tokens</li>
+ <li><span class="secnum"><a href="#sec-names-and-keywords">11.6</a></span> Names and Keywords
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-identifier-names">11.6.1</a></span> Identifier Names</li>
+ <li><span class="secnum"><a href="#sec-reserved-words">11.6.2</a></span> Reserved Words</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-punctuators">11.7</a></span> Punctuators</li>
+ <li><span class="secnum"><a href="#sec-ecmascript-language-lexical-grammar-literals">11.8</a></span> Literals
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-null-literals">11.8.1</a></span> Null Literals</li>
+ <li><span class="secnum"><a href="#sec-boolean-literals">11.8.2</a></span> Boolean Literals</li>
+ <li><span class="secnum"><a href="#sec-literals-numeric-literals">11.8.3</a></span> Numeric Literals</li>
+ <li><span class="secnum"><a href="#sec-literals-string-literals">11.8.4</a></span> String Literals</li>
+ <li><span class="secnum"><a href="#sec-literals-regular-expression-literals">11.8.5</a></span> Regular Expression
+ Literals</li>
+ <li><span class="secnum"><a href="#sec-template-literal-lexical-components">11.8.6</a></span> Template Literal Lexical
+ Components</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-automatic-semicolon-insertion">11.9</a></span> Automatic Semicolon Insertion
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-rules-of-automatic-semicolon-insertion">11.9.1</a></span> Rules of Automatic
+ Semicolon Insertion</li>
+ <li><span class="secnum"><a href="#sec-examples-of-automatic-semicolon-insertion">11.9.2</a></span> Examples of
+ Automatic Semicolon Insertion</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-ecmascript-language-expressions">12</a></span> ECMAScript Language: Expressions
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-identifiers">12.1</a></span> Identifiers
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-identifiers-static-semantics-early-errors">12.1.1</a></span> Static Semantics:
+ Early Errors</li>
+ <li><span class="secnum"><a href="#sec-identifiers-static-semantics-boundnames">12.1.2</a></span> Static Semantics:
+ BoundNames</li>
+ <li><span class="secnum"><a href="#sec-identifiers-static-semantics-stringvalue">12.1.3</a></span> Static
+ Semantics<span style="font-family: sans-serif">:</span> <i>StringValue</i></li>
+ <li><span class="secnum"><a href="#sec-identifiers-runtime-semantics-bindinginitialization">12.1.4</a></span> Runtime
+ Semantics: BindingInitialization</li>
+ <li><span class="secnum"><a href="#sec-identifiers-runtime-semantics-evaluation">12.1.5</a></span> Runtime Semantics:
+ Evaluation</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-primary-expression">12.2</a></span> Primary Expression
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-primary-expression-semantics">12.2.0</a></span> Semantics</li>
+ <li><span class="secnum"><a href="#sec-this-keyword">12.2.1</a></span> The <code>this</code> Keyword</li>
+ <li><span class="secnum"><a href="#sec-identifier-reference">12.2.2</a></span> Identifier Reference</li>
+ <li><span class="secnum"><a href="#sec-primary-expression-literals">12.2.3</a></span> Literals</li>
+ <li><span class="secnum"><a href="#sec-array-initializer">12.2.4</a></span> Array Initializer</li>
+ <li><span class="secnum"><a href="#sec-object-initializer">12.2.5</a></span> Object Initializer</li>
+ <li><span class="secnum"><a href="#sec-function-defining-expressions">12.2.6</a></span> Function Defining
+ Expressions</li>
+ <li><span class="secnum"><a href="#sec-generator-comprehensions">12.2.7</a></span> Generator Comprehensions</li>
+ <li><span class="secnum"><a href="#sec-primary-expression-regular-expression-literals">12.2.8</a></span> Regular
+ Expression Literals</li>
+ <li><span class="secnum"><a href="#sec-template-literals">12.2.9</a></span> Template Literals</li>
+ <li><span class="secnum"><a href="#sec-grouping-operator">12.2.10</a></span> The Grouping Operator</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-left-hand-side-expressions">12.3</a></span> Left-Hand-Side Expressions
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-left-hand-side-expressions-static-semantics">12.3.1</a></span> Static
+ Semantics</li>
+ <li><span class="secnum"><a href="#sec-property-accessors">12.3.2</a></span> Property Accessors</li>
+ <li><span class="secnum"><a href="#sec-new-operator">12.3.3</a></span> The <code>new</code> Operator</li>
+ <li><span class="secnum"><a href="#sec-function-calls">12.3.4</a></span> Function Calls</li>
+ <li><span class="secnum"><a href="#sec-super-keyword">12.3.5</a></span> The <code>super</code> Keyword</li>
+ <li><span class="secnum"><a href="#sec-argument-lists">12.3.6</a></span> Argument Lists</li>
+ <li><span class="secnum"><a href="#sec-tagged-templates">12.3.7</a></span> Tagged Templates</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-postfix-expressions">12.4</a></span> Postfix Expressions
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-postfix-expressions-static-semantics-early-errors">12.4.1</a></span> Static
+ Semantics: Early Errors</li>
+ <li><span class="secnum"><a href="#sec-postfix-expressions-static-semantics-isfunctiondefinition">12.4.2</a></span>
+ Static Semantics: IsFunctionDefinition</li>
+ <li><span class="secnum"><a
+ href="#sec-postfix-expressions-static-semantics-isvalidsimpleassignmenttarget">12.4.3</a></span> Static Semantics:
+ IsValidSimpleAssignmentTarget</li>
+ <li><span class="secnum"><a href="#sec-postfix-increment-operator">12.4.4</a></span> Postfix Increment Operator</li>
+ <li><span class="secnum"><a href="#sec-postfix-decrement-operator">12.4.5</a></span> Postfix Decrement Operator</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-unary-operators">12.5</a></span> Unary Operators
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-unary-operators-static-semantics-early-errors">12.5.1</a></span> Static
+ Semantics: Early Errors</li>
+ <li><span class="secnum"><a href="#sec-unary-operators-static-semantics-isfunctiondefinition">12.5.2</a></span> Static
+ Semantics: IsFunctionDefinition</li>
+ <li><span class="secnum"><a
+ href="#sec-unary-operators-static-semantics-isvalidsimpleassignmenttarget">12.5.3</a></span> Static Semantics:
+ IsValidSimpleAssignmentTarget</li>
+ <li><span class="secnum"><a href="#sec-delete-operator">12.5.4</a></span> The <code>delete</code> Operator</li>
+ <li><span class="secnum"><a href="#sec-void-operator">12.5.5</a></span> The <code>void</code> Operator</li>
+ <li><span class="secnum"><a href="#sec-typeof-operator">12.5.6</a></span> The <code>typeof</code> Operator</li>
+ <li><span class="secnum"><a href="#sec-prefix-increment-operator">12.5.7</a></span> Prefix Increment Operator</li>
+ <li><span class="secnum"><a href="#sec-prefix-decrement-operator">12.5.8</a></span> Prefix Decrement Operator</li>
+ <li><span class="secnum"><a href="#sec-unary-plus-operator">12.5.9</a></span> Unary <code>+</code> Operator</li>
+ <li><span class="secnum"><a href="#sec-unary-minus-operator">12.5.10</a></span> Unary <code>-</code> Operator</li>
+ <li><span class="secnum"><a href="#sec-bitwise-not-operator">12.5.11</a></span> Bitwise NOT Operator ( <code>~</code>
+ )</li>
+ <li><span class="secnum"><a href="#sec-logical-not-operator">12.5.12</a></span> Logical NOT Operator ( <code>!</code>
+ )</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-multiplicative-operators">12.6</a></span> Multiplicative Operators
+ <ol class="toc">
+ <li><span class="secnum"><a
+ href="#sec-multiplicative-operators-static-semantics-isfunctiondefinition">12.6.1</a></span> Static Semantics:
+ IsFunctionDefinition</li>
+ <li><span class="secnum"><a
+ href="#sec-multiplicative-operators-static-semantics-isvalidsimpleassignmenttarget">12.6.2</a></span> Static
+ Semantics: IsValidSimpleAssignmentTarget</li>
+ <li><span class="secnum"><a href="#sec-multiplicative-operators-runtime-semantics-evaluation">12.6.3</a></span>
+ Runtime Semantics: Evaluation</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-additive-operators">12.7</a></span> Additive Operators
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-additive-operators-static-semantics-isfunctiondefinition">12.7.1</a></span>
+ Static Semantics: IsFunctionDefinition</li>
+ <li><span class="secnum"><a
+ href="#sec-additive-operators-static-semantics-isvalidsimpleassignmenttarget">12.7.2</a></span> Static Semantics:
+ IsValidSimpleAssignmentTarget</li>
+ <li><span class="secnum"><a href="#sec-addition-operator-plus">12.7.3</a></span> The Addition operator (
+ <code>+</code> )</li>
+ <li><span class="secnum"><a href="#sec-subtraction-operator-minus">12.7.4</a></span> The Subtraction Operator (
+ <code>-</code> )</li>
+ <li><span class="secnum"><a href="#sec-applying-the-additive-operators-to-numbers">12.7.5</a></span> Applying the
+ Additive Operators to Numbers</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-bitwise-shift-operators">12.8</a></span> Bitwise Shift Operators
+ <ol class="toc">
+ <li><span class="secnum"><a
+ href="#sec-bitwise-shift-operators-static-semantics-isfunctiondefinition">12.8.1</a></span> Static Semantics:
+ IsFunctionDefinition</li>
+ <li><span class="secnum"><a
+ href="#sec-bitwise-shift-operators-static-semantics-isvalidsimpleassignmenttarget">12.8.2</a></span> Static
+ Semantics: IsValidSimpleAssignmentTarget</li>
+ <li><span class="secnum"><a href="#sec-left-shift-operator">12.8.3</a></span> The Left Shift Operator (
+ <code><<</code> )</li>
+ <li><span class="secnum"><a href="#sec-signed-right-shift-operator">12.8.4</a></span> The Signed Right Shift Operator
+ ( <code>>></code> )</li>
+ <li><span class="secnum"><a href="#sec-unsigned-right-shift-operator">12.8.5</a></span> The Unsigned Right Shift
+ Operator ( <code>>>></code> )</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-relational-operators">12.9</a></span> Relational Operators
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-relational-operators-static-semantics-isfunctiondefinition">12.9.1</a></span>
+ Static Semantics: IsFunctionDefinition</li>
+ <li><span class="secnum"><a
+ href="#sec-relational-operators-static-semantics-isvalidsimpleassignmenttarget">12.9.2</a></span> Static
+ Semantics: IsValidSimpleAssignmentTarget</li>
+ <li><span class="secnum"><a href="#sec-relational-operators-runtime-semantics-evaluation">12.9.3</a></span> Runtime
+ Semantics: Evaluation</li>
+ <li><span class="secnum"><a href="#sec-instanceofoperator">12.9.4</a></span> Runtime Semantics: InstanceofOperator(O,
+ C)</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-equality-operators">12.10</a></span> Equality Operators
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-equality-operators-static-semantics-isfunctiondefinition">12.10.1</a></span>
+ Static Semantics: IsFunctionDefinition</li>
+ <li><span class="secnum"><a
+ href="#sec-equality-operators-static-semantics-isvalidsimpleassignmenttarget">12.10.2</a></span> Static Semantics:
+ IsValidSimpleAssignmentTarget</li>
+ <li><span class="secnum"><a href="#sec-equality-operators-runtime-semantics-evaluation">12.10.3</a></span> Runtime
+ Semantics: Evaluation</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-binary-bitwise-operators">12.11</a></span> Binary Bitwise Operators
+ <ol class="toc">
+ <li><span class="secnum"><a
+ href="#sec-binary-bitwise-operators-static-semantics-isfunctiondefinition">12.11.1</a></span> Static Semantics:
+ IsFunctionDefinition</li>
+ <li><span class="secnum"><a
+ href="#sec-binary-bitwise-operators-static-semantics-isvalidsimpleassignmenttarget">12.11.2</a></span> Static
+ Semantics: IsValidSimpleAssignmentTarget</li>
+ <li><span class="secnum"><a href="#sec-binary-bitwise-operators-runtime-semantics-evaluation">12.11.3</a></span>
+ Runtime Semantics: Evaluation</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-binary-logical-operators">12.12</a></span> Binary Logical Operators
+ <ol class="toc">
+ <li><span class="secnum"><a
+ href="#sec-binary-logical-operators-static-semantics-isfunctiondefinition">12.12.1</a></span> Static Semantics:
+ IsFunctionDefinition</li>
+ <li><span class="secnum"><a
+ href="#sec-binary-logical-operators-static-semantics-isvalidsimpleassignmenttarget">12.12.2</a></span> Static
+ Semantics: IsValidSimpleAssignmentTarget</li>
+ <li><span class="secnum"><a href="#sec-binary-logical-operators-runtime-semantics-evaluation">12.12.3</a></span>
+ Runtime Semantics: Evaluation</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-conditional-operator">12.13</a></span> Conditional Operator ( <code>? : )</code>
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-conditional-operator-static-semantics-isfunctiondefinition">12.13.1</a></span>
+ Static Semantics: IsFunctionDefinition</li>
+ <li><span class="secnum"><a
+ href="#sec-conditional-operator-static-semantics-isvalidsimpleassignmenttarget">12.13.2</a></span> Static
+ Semantics: IsValidSimpleAssignmentTarget</li>
+ <li><span class="secnum"><a href="#sec-conditional-operator-runtime-semantics-evaluation">12.13.3</a></span> Runtime
+ Semantics: Evaluation</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-assignment-operators">12.14</a></span> Assignment Operators
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-assignment-operators-static-semantics-early-errors">12.14.1</a></span> Static
+ Semantics: Early Errors</li>
+ <li><span class="secnum"><a href="#sec-assignment-operators-static-semantics-isfunctiondefinition">12.14.2</a></span>
+ Static Semantics: IsFunctionDefinition</li>
+ <li><span class="secnum"><a
+ href="#sec-assignment-operators-static-semantics-isvalidsimpleassignmenttarget">12.14.3</a></span> Static
+ Semantics: IsValidSimpleAssignmentTarget</li>
+ <li><span class="secnum"><a href="#sec-assignment-operators-runtime-semantics-evaluation">12.14.4</a></span> Runtime
+ Semantics: Evaluation</li>
+ <li><span class="secnum"><a href="#sec-destructuring-assignment">12.14.5</a></span> Destructuring Assignment</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-comma-operator">12.15</a></span> Comma Operator ( <code>, )</code>
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-comma-operator-static-semantics-isfunctiondefinition">12.15.1</a></span> Static
+ Semantics: IsFunctionDefinition</li>
+ <li><span class="secnum"><a
+ href="#sec-comma-operator-static-semantics-isvalidsimpleassignmenttarget">12.15.2</a></span> Static Semantics:
+ IsValidSimpleAssignmentTarget</li>
+ <li><span class="secnum"><a href="#sec-comma-operator-runtime-semantics-evaluation">12.15.3</a></span> Runtime
+ Semantics: Evaluation</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-ecmascript-language-statements-and-declarations">13</a></span> ECMAScript Language:
+ Statements and Declarations
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-statement-semantics">13.0</a></span> Statement Semantics
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-statement-semantics-static-semantics-vardeclarednames">13.0.1</a></span> Static
+ Semantics: VarDeclaredNames</li>
+ <li><span class="secnum"><a href="#sec-statement-semantics-static-semantics-varscopeddeclarations">13.0.2</a></span>
+ Static Semantics: VarScopedDeclarations</li>
+ <li><span class="secnum"><a href="#sec-statement-semantics-runtime-semantics-labelledevaluation">13.0.3</a></span>
+ Runtime Semantics: LabelledEvaluation</li>
+ <li><span class="secnum"><a href="#sec-statement-semantics-runtime-semantics-evaluation">13.0.4</a></span> Runtime
+ Semantics: Evaluation</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-block">13.1</a></span> Block
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-block-static-semantics-early-errors">13.1.1</a></span> Static Semantics: Early
+ Errors</li>
+ <li><span class="secnum"><a href="#sec-block-static-semantics-lexicallyscopeddeclarations">13.1.2</a></span> Static
+ Semantics: LexicallyScopedDeclarations</li>
+ <li><span class="secnum"><a href="#sec-block-static-semantics-lexicallydeclarednames">13.1.3</a></span> Static
+ Semantics: LexicallyDeclaredNames</li>
+ <li><span class="secnum"><a href="#sec-static-semantics-toplevellexicallydeclarednames">13.1.4</a></span> Static
+ Semantics: TopLevelLexicallyDeclaredNames</li>
+ <li><span class="secnum"><a href="#sec-static-semantics-toplevellexicallyscopeddeclarations">13.1.5</a></span> Static
+ Semantics: TopLevelLexicallyScopedDeclarations</li>
+ <li><span class="secnum"><a href="#sec-static-semantics-toplevelvardeclarednames">13.1.6</a></span> Static Semantics:
+ TopLevelVarDeclaredNames</li>
+ <li><span class="secnum"><a href="#sec-static-semantics-toplevelvarscopeddeclarations">13.1.7</a></span> Static
+ Semantics: TopLevelVarScopedDeclarations</li>
+ <li><span class="secnum"><a href="#sec-block-static-semantics-vardeclarednames">13.1.8</a></span> Static Semantics:
+ VarDeclaredNames</li>
+ <li><span class="secnum"><a href="#sec-block-static-semantics-varscopeddeclarations">13.1.9</a></span> Static
+ Semantics: VarScopedDeclarations</li>
+ <li><span class="secnum"><a href="#sec-block-runtime-semantics-evaluation">13.1.10</a></span> Runtime Semantics:
+ Evaluation</li>
+ <li><span class="secnum"><a href="#sec-blockdeclarationinstantiation">13.1.11</a></span> Runtime Semantics:
+ BlockDeclarationInstantiation( code, env )</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-declarations-and-the-variable-statement">13.2</a></span> Declarations and the
+ Variable Statement
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-let-and-const-declarations">13.2.1</a></span> Let and Const Declarations</li>
+ <li><span class="secnum"><a href="#sec-variable-statement">13.2.2</a></span> Variable Statement</li>
+ <li><span class="secnum"><a href="#sec-destructuring-binding-patterns">13.2.3</a></span> Destructuring Binding
+ Patterns</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-empty-statement">13.3</a></span> Empty Statement
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-empty-statement-runtime-semantics-evaluation">13.3.1</a></span> Runtime
+ Semantics: Evaluation</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-expression-statement">13.4</a></span> Expression Statement
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-expression-statement-runtime-semantics-evaluation">13.4.1</a></span> Runtime
+ Semantics: Evaluation</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-if-statement">13.5</a></span> The <code>if</code> Statement
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-if-statement-static-semantics-vardeclarednames">13.5.1</a></span> Static
+ Semantics: VarDeclaredNames</li>
+ <li><span class="secnum"><a href="#sec-if-statement-static-semantics-varscopeddeclarations">13.5.2</a></span> Static
+ Semantics: VarScopedDeclarations</li>
+ <li><span class="secnum"><a href="#sec-if-statement-runtime-semantics-evaluation">13.5.3</a></span> Runtime Semantics:
+ Evaluation</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-iteration-statements">13.6</a></span> Iteration Statements
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-iteration-statements-semantics">13.6.0</a></span> Semantics</li>
+ <li><span class="secnum"><a href="#sec-do-while-statement">13.6.1</a></span> The <code>do</code>-<code>while</code>
+ Statement</li>
+ <li><span class="secnum"><a href="#sec-while-statement">13.6.2</a></span> The <code>while</code> Statement</li>
+ <li><span class="secnum"><a href="#sec-for-statement">13.6.3</a></span> The <code>for</code> Statement</li>
+ <li><span class="secnum"><a href="#sec-for-in-and-for-of-statements">13.6.4</a></span> The
+ <code>for</code>-<code>in</code> and <code>for</code>-<code>of</code> Statements</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-continue-statement">13.7</a></span> The <code>continue</code> Statement
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-continue-statement-static-semantics-early-errors">13.7.1</a></span> Static
+ Semantics: Early Errors</li>
+ <li><span class="secnum"><a href="#sec-continue-statement-runtime-semantics-evaluation">13.7.2</a></span> Runtime
+ Semantics: Evaluation</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-break-statement">13.8</a></span> The <code>break</code> Statement
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-break-statement-static-semantics-early-errors">13.8.1</a></span> Static
+ Semantics: Early Errors</li>
+ <li><span class="secnum"><a href="#sec-break-statement-runtime-semantics-evaluation">13.8.2</a></span> Runtime
+ Semantics: Evaluation</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-return-statement">13.9</a></span> The <code>return</code> Statement
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-return-statement-runtime-semantics-evaluation">13.9.1</a></span> Runtime
+ Semantics: Evaluation</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-with-statement">13.10</a></span> The <code>with</code> Statement
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-with-statement-static-semantics-early-errors">13.10.1</a></span> Static
+ Semantics: Early Errors</li>
+ <li><span class="secnum"><a href="#sec-with-statement-static-semantics-vardeclarednames">13.10.2</a></span> Static
+ Semantics: VarDeclaredNames</li>
+ <li><span class="secnum"><a href="#sec-with-statement-static-semantics-varscopeddeclarations">13.10.3</a></span>
+ Static Semantics: VarScopedDeclarations</li>
+ <li><span class="secnum"><a href="#sec-with-statement-runtime-semantics-evaluation">13.10.4</a></span> Runtime
+ Semantics: Evaluation</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-switch-statement">13.11</a></span> The <code>switch</code> Statement
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-switch-statement-static-semantics-early-errors">13.11.1</a></span> Static
+ Semantics: Early Errors</li>
+ <li><span class="secnum"><a
+ href="#sec-switch-statement-static-semantics-lexicallyscopeddeclarations">13.11.2</a></span> Static Semantics:
+ LexicallyScopedDeclarations</li>
+ <li><span class="secnum"><a href="#sec-switch-statement-static-semantics-lexicallydeclarednames">13.11.3</a></span>
+ Static Semantics: LexicallyDeclaredNames</li>
+ <li><span class="secnum"><a href="#sec-switch-statement-static-semantics-vardeclarednames">13.11.4</a></span> Static
+ Semantics: VarDeclaredNames</li>
+ <li><span class="secnum"><a href="#sec-switch-statement-static-semantics-varscopeddeclarations">13.11.5</a></span>
+ Static Semantics: VarScopedDeclarations</li>
+ <li><span class="secnum"><a href="#sec-runtime-semantics-caseblockevaluation">13.11.6</a></span> Runtime Semantics:
+ CaseBlockEvaluation</li>
+ <li><span class="secnum"><a href="#sec-runtime-semantics-caseselectorevaluation">13.11.7</a></span> Runtime Semantics:
+ CaseSelectorEvaluation</li>
+ <li><span class="secnum"><a href="#sec-switch-statement-runtime-semantics-evaluation">13.11.8</a></span> Runtime
+ Semantics: Evaluation</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-labelled-statements">13.12</a></span> Labelled Statements
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-labelled-statements-static-semantics-early-errors">13.12.1</a></span> Static
+ Semantics: Early Errors</li>
+ <li><span class="secnum"><a href="#sec-static-semantics-currentlabelset">13.12.2</a></span> Static Semantics:
+ CurrentLabelSet</li>
+ <li><span class="secnum"><a href="#sec-labelled-statements-static-semantics-vardeclarednames">13.12.3</a></span>
+ Static Semantics: VarDeclaredNames</li>
+ <li><span class="secnum"><a href="#sec-labelled-statements-static-semantics-varscopeddeclarations">13.12.4</a></span>
+ Static Semantics: VarScopedDeclarations</li>
+ <li><span class="secnum"><a href="#sec-labelled-statements-runtime-semantics-labelledevaluation">13.12.5</a></span>
+ Runtime Semantics: LabelledEvaluation</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-throw-statement">13.13</a></span> The <code>throw</code> Statement
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-throw-statement-runtime-semantics-evaluation">13.13.1</a></span> Runtime
+ Semantics: Evaluation</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-try-statement">13.14</a></span> The <code>try</code> Statement
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-try-statement-static-semantics-early-errors">13.14.1</a></span> Static
+ Semantics: Early Errors</li>
+ <li><span class="secnum"><a href="#sec-try-statement-static-semantics-vardeclarednames">13.14.2</a></span> Static
+ Semantics: VarDeclaredNames</li>
+ <li><span class="secnum"><a href="#sec-try-statement-static-semantics-varscopeddeclarations">13.14.3</a></span> Static
+ Semantics: VarScopedDeclarations</li>
+ <li><span class="secnum"><a href="#sec-try-statement-runtime-semantics-bindinginitialization">13.14.4</a></span>
+ Runtime Semantics: BindingInitialization</li>
+ <li><span class="secnum"><a href="#sec-runtime-semantics-catchclauseevaluation">13.14.5</a></span> Runtime Semantics:
+ CatchClauseEvaluation</li>
+ <li><span class="secnum"><a href="#sec-try-statement-runtime-semantics-evaluation">13.14.6</a></span> Runtime
+ Semantics: Evaluation</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-debugger-statement">13.15</a></span> The <code>debugger</code> statement
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-debugger-statement-runtime-semantics-evaluation">13.15.1</a></span> Runtime
+ Semantics: Evaluation</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-ecmascript-language-functions-and-classes">14</a></span> ECMAScript Language: Functions
+ and Classes
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-function-definitions">14.1</a></span> Function Definitions
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-directive-prologues-and-the-use-strict-directive">14.1.1</a></span> Directive
+ Prologues and the Use Strict Directive</li>
+ <li><span class="secnum"><a href="#sec-function-definitions-static-semantics-early-errors">14.1.2</a></span> Static
+ Semantics: Early Errors</li>
+ <li><span class="secnum"><a href="#sec-function-definitions-static-semantics-boundnames">14.1.3</a></span> Static
+ Semantics: BoundNames</li>
+ <li><span class="secnum"><a href="#sec-function-definitions-static-semantics-contains">14.1.4</a></span> Static
+ Semantics: Contains</li>
+ <li><span class="secnum"><a href="#sec-function-definitions-static-semantics-containsexpression">14.1.5</a></span>
+ Static Semantics: ContainsExpression</li>
+ <li><span class="secnum"><a href="#sec-function-definitions-static-semantics-expectedargumentcount">14.1.6</a></span>
+ Static Semantics: ExpectedArgumentCount</li>
+ <li><span class="secnum"><a href="#sec-function-definitions-static-semantics-hasinitializer">14.1.7</a></span> Static
+ Semantics: HasInitializer</li>
+ <li><span class="secnum"><a href="#sec-function-definitions-static-semantics-hasname">14.1.8</a></span> Static
+ Semantics: HasName</li>
+ <li><span class="secnum"><a href="#sec-isanonymousfunctiondefinition">14.1.9</a></span> Static Semantics:
+ IsAnonymousFunctionDefinition ( production) Abstract Operation</li>
+ <li><span class="secnum"><a href="#sec-function-definitions-static-semantics-isconstantdeclaration">14.1.10</a></span>
+ Static Semantics: IsConstantDeclaration</li>
+ <li><span class="secnum"><a href="#sec-function-definitions-static-semantics-isfunctiondefinition">14.1.11</a></span>
+ Static Semantics: IsFunctionDefinition</li>
+ <li><span class="secnum"><a href="#sec-function-definitions-static-semantics-issimpleparameterlist">14.1.12</a></span>
+ Static Semantics: IsSimpleParameterList</li>
+ <li><span class="secnum"><a href="#sec-function-definitions-static-semantics-isstrict">14.1.13</a></span> Static
+ Semantics: IsStrict</li>
+ <li><span class="secnum"><a
+ href="#sec-function-definitions-static-semantics-lexicallyscopeddeclarations">14.1.14</a></span> Static Semantics:
+ LexicallyScopedDeclarations</li>
+ <li><span class="secnum"><a
+ href="#sec-function-definitions-static-semantics-lexicallydeclarednames">14.1.15</a></span> Static Semantics:
+ LexicallyDeclaredNames</li>
+ <li><span class="secnum"><a href="#sec-function-definitions-static-semantics-referencessuper">14.1.16</a></span>
+ Static Semantics: ReferencesSuper</li>
+ <li><span class="secnum"><a href="#sec-function-definitions-static-semantics-vardeclarednames">14.1.17</a></span>
+ Static Semantics: VarDeclaredNames</li>
+ <li><span class="secnum"><a href="#sec-function-definitions-static-semantics-varscopeddeclarations">14.1.18</a></span>
+ Static Semantics: VarScopedDeclarations</li>
+ <li><span class="secnum"><a href="#sec-function-definitions-runtime-semantics-evaluatebody">14.1.19</a></span> Runtime
+ Semantics: EvaluateBody</li>
+ <li><span class="secnum"><a
+ href="#sec-function-definitions-runtime-semantics-iteratorbindinginitialization">14.1.20</a></span> Runtime
+ Semantics: IteratorBindingInitialization</li>
+ <li><span class="secnum"><a
+ href="#sec-function-definitions-runtime-semantics-instantiatefunctionobject">14.1.21</a></span> Runtime Semantics:
+ InstantiateFunctionObject</li>
+ <li><span class="secnum"><a href="#sec-function-definitions-runtime-semantics-evaluation">14.1.22</a></span> Runtime
+ Semantics: Evaluation</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-arrow-function-definitions">14.2</a></span> Arrow Function Definitions
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-arrow-function-definitions-static-semantics-early-errors">14.2.1</a></span>
+ Static Semantics: Early Errors</li>
+ <li><span class="secnum"><a href="#sec-arrow-function-definitions-static-semantics-boundnames">14.2.2</a></span>
+ Static Semantics: BoundNames</li>
+ <li><span class="secnum"><a href="#sec-arrow-function-definitions-static-semantics-contains">14.2.3</a></span> Static
+ Semantics: Contains</li>
+ <li><span class="secnum"><a
+ href="#sec-arrow-function-definitions-static-semantics-containsexpression">14.2.4</a></span> Static Semantics:
+ ContainsExpression</li>
+ <li><span class="secnum"><a href="#sec-static-semantics-coveredformalslist">14.2.5</a></span> Static Semantics:
+ CoveredFormalsList</li>
+ <li><span class="secnum"><a
+ href="#sec-arrow-function-definitions-static-semantics-expectedargumentcount">14.2.6</a></span> Static Semantics:
+ ExpectedArgumentCount</li>
+ <li><span class="secnum"><a href="#sec-arrow-function-definitions-static-semantics-hasinitializer">14.2.7</a></span>
+ Static Semantics: HasInitializer</li>
+ <li><span class="secnum"><a href="#sec-arrow-function-definitions-static-semantics-hasname">14.2.8</a></span> Static
+ Semantics: HasName</li>
+ <li><span class="secnum"><a
+ href="#sec-arrow-function-definitions-static-semantics-issimpleparameterlist">14.2.9</a></span> Static Semantics:
+ IsSimpleParameterList</li>
+ <li><span class="secnum"><a
+ href="#sec-arrow-function-definitions-static-semantics-lexicallyscopeddeclarations">14.2.10</a></span> Static
+ Semantics: LexicallyScopedDeclarations</li>
+ <li><span class="secnum"><a
+ href="#sec-arrow-function-definitions-static-semantics-lexicallydeclarednames">14.2.11</a></span> Static
+ Semantics: LexicallyDeclaredNames</li>
+ <li><span class="secnum"><a href="#sec-arrow-function-definitions-static-semantics-referencessuper">14.2.12</a></span>
+ Static Semantics: ReferencesSuper</li>
+ <li><span class="secnum"><a
+ href="#sec-arrow-function-definitions-static-semantics-vardeclarednames">14.2.13</a></span> Static Semantics:
+ VarDeclaredNames</li>
+ <li><span class="secnum"><a
+ href="#sec-arrow-function-definitions-static-semantics-varscopeddeclarations">14.2.14</a></span> Static Semantics:
+ VarScopedDeclarations</li>
+ <li><span class="secnum"><a
+ href="#sec-arrow-function-definitions-runtime-semantics-iteratorbindinginitialization">14.2.15</a></span> Runtime
+ Semantics: IteratorBindingInitialization</li>
+ <li><span class="secnum"><a href="#sec-arrow-function-definitions-runtime-semantics-evaluatebody">14.2.16</a></span>
+ Runtime Semantics: EvaluateBody</li>
+ <li><span class="secnum"><a href="#sec-arrow-function-definitions-runtime-semantics-evaluation">14.2.17</a></span>
+ Runtime Semantics: Evaluation</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-method-definitions">14.3</a></span> Method Definitions
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-method-definitions-static-semantics-early-errors">14.3.1</a></span> Static
+ Semantics: Early Errors</li>
+ <li><span class="secnum"><a href="#sec-method-definitions-static-semantics-computedpropertycontains">14.3.2</a></span>
+ Static Semantics: ComputedPropertyContains</li>
+ <li><span class="secnum"><a href="#sec-method-definitions-static-semantics-expectedargumentcount">14.3.3</a></span>
+ Static Semantics: ExpectedArgumentCount</li>
+ <li><span class="secnum"><a href="#sec-method-definitions-static-semantics-hascomputedpropertykey">14.3.4</a></span>
+ Static Semantics: HasComputedPropertyKey</li>
+ <li><span class="secnum"><a href="#sec-method-definitions-static-semantics-propname">14.3.5</a></span> Static
+ Semantics: PropName</li>
+ <li><span class="secnum"><a href="#sec-method-definitions-static-semantics-referencessuper">14.3.6</a></span> Static
+ Semantics: ReferencesSuper</li>
+ <li><span class="secnum"><a href="#sec-static-semantics-specialmethod">14.3.7</a></span> Static Semantics:
+ SpecialMethod</li>
+ <li><span class="secnum"><a href="#sec-runtime-semantics-definemethod">14.3.8</a></span> Runtime Semantics:
+ DefineMethod</li>
+ <li><span class="secnum"><a
+ href="#sec-method-definitions-runtime-semantics-propertydefinitionevaluation">14.3.9</a></span> Runtime Semantics:
+ PropertyDefinitionEvaluation</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-generator-function-definitions">14.4</a></span> Generator Function Definitions
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-generator-function-definitions-static-semantics-early-errors">14.4.1</a></span>
+ Static Semantics: Early Errors</li>
+ <li><span class="secnum"><a href="#sec-generator-function-definitions-static-semantics-boundnames">14.4.2</a></span>
+ Static Semantics: BoundNames</li>
+ <li><span class="secnum"><a
+ href="#sec-generator-function-definitions-static-semantics-computedpropertycontains">14.4.3</a></span> Static
+ Semantics: ComputedPropertyContains</li>
+ <li><span class="secnum"><a href="#sec-generator-function-definitions-static-semantics-contains">14.4.4</a></span>
+ Static Semantics: Contains</li>
+ <li><span class="secnum"><a
+ href="#sec-generator-function-definitions-static-semantics-hascomputedpropertykey">14.4.5</a></span> Static
+ Semantics: HasComputedPropertyKey</li>
+ <li><span class="secnum"><a href="#sec-generator-function-definitions-static-semantics-hasname">14.4.6</a></span>
+ Static Semantics: HasName</li>
+ <li><span class="secnum"><a
+ href="#sec-generator-function-definitions-static-semantics-isconstantdeclaration">14.4.7</a></span> Static
+ Semantics: IsConstantDeclaration</li>
+ <li><span class="secnum"><a
+ href="#sec-generator-function-definitions-static-semantics-isfunctiondefinition">14.4.8</a></span> Static
+ Semantics: IsFunctionDefinition</li>
+ <li><span class="secnum"><a
+ href="#sec-generator-function-definitions-static-semantics-lexicallydeclarednames">14.4.9</a></span> Static
+ Semantics: LexicallyDeclaredNames</li>
+ <li><span class="secnum"><a href="#sec-generator-function-definitions-static-semantics-propname">14.4.10</a></span>
+ Static Semantics: PropName</li>
+ <li><span class="secnum"><a
+ href="#sec-generator-function-definitions-static-semantics-referencessuper">14.4.11</a></span> Static Semantics:
+ ReferencesSuper</li>
+ <li><span class="secnum"><a
+ href="#sec-generator-function-definitions-static-semantics-vardeclarednames">14.4.12</a></span> Static Semantics:
+ VarDeclaredNames</li>
+ <li><span class="secnum"><a
+ href="#sec-generator-function-definitions-static-semantics-varscopeddeclarations">14.4.13</a></span> Static
+ Semantics: VarScopedDeclarations</li>
+ <li><span class="secnum"><a
+ href="#sec-generator-function-definitions-runtime-semantics-evaluatebody">14.4.14</a></span> Runtime Semantics:
+ EvaluateBody</li>
+ <li><span class="secnum"><a
+ href="#sec-generator-function-definitions-runtime-semantics-instantiatefunctionobject">14.4.15</a></span> Runtime
+ Semantics: InstantiateFunctionObject</li>
+ <li><span class="secnum"><a
+ href="#sec-generator-function-definitions-runtime-semantics-propertydefinitionevaluation">14.4.16</a></span>
+ Runtime Semantics: PropertyDefinitionEvaluation</li>
+ <li><span class="secnum"><a href="#sec-generator-function-definitions-runtime-semantics-evaluation">14.4.17</a></span>
+ Runtime Semantics: Evaluation</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-class-definitions">14.5</a></span> Class Definitions
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-class-definitions-static-semantics-early-errors">14.5.1</a></span> Static
+ Semantics: Early Errors</li>
+ <li><span class="secnum"><a href="#sec-class-definitions-static-semantics-boundnames">14.5.2</a></span> Static
+ Semantics: BoundNames</li>
+ <li><span class="secnum"><a href="#sec-static-semantics-constructormethod">14.5.3</a></span> Static Semantics:
+ ConstructorMethod</li>
+ <li><span class="secnum"><a href="#sec-class-definitions-static-semantics-contains">14.5.4</a></span> Static
+ Semantics: Contains</li>
+ <li><span class="secnum"><a href="#sec-class-definitions-static-semantics-computedpropertycontains">14.5.5</a></span>
+ Static Semantics: ComputedPropertyContains</li>
+ <li><span class="secnum"><a href="#sec-class-definitions-static-semantics-hasname">14.5.6</a></span> Static Semantics:
+ HasName</li>
+ <li><span class="secnum"><a href="#sec-class-definitions-static-semantics-isconstantdeclaration">14.5.7</a></span>
+ Static Semantics: IsConstantDeclaration</li>
+ <li><span class="secnum"><a href="#sec-class-definitions-static-semantics-isfunctiondefinition">14.5.8</a></span>
+ Static Semantics: IsFunctionDefinition</li>
+ <li><span class="secnum"><a href="#sec-static-semantics-isstatic">14.5.9</a></span> Static Semantics: IsStatic</li>
+ <li><span class="secnum"><a href="#sec-class-definitions-static-semantics-lexicallydeclarednames">14.5.10</a></span>
+ Static Semantics: LexicallyDeclaredNames</li>
+ <li><span class="secnum"><a href="#sec-static-semantics-nonconstructormethoddefinitions">14.5.11</a></span> Static
+ Semantics: NonConstructorMethodDefinitions</li>
+ <li><span class="secnum"><a href="#sec-static-semantics-prototypepropertynamelist">14.5.12</a></span> Static
+ Semantics: PrototypePropertyNameList</li>
+ <li><span class="secnum"><a href="#sec-class-definitions-static-semantics-propname">14.5.13</a></span> Static
+ Semantics: PropName</li>
+ <li><span class="secnum"><a href="#sec-static-semantics-staticpropertynamelist">14.5.14</a></span> Static Semantics:
+ StaticPropertyNameList</li>
+ <li><span class="secnum"><a href="#sec-class-definitions-static-semantics-vardeclarednames">14.5.15</a></span> Static
+ Semantics: VarDeclaredNames</li>
+ <li><span class="secnum"><a href="#sec-runtime-semantics-classdefinitionevaluation">14.5.16</a></span> Runtime
+ Semantics: ClassDefinitionEvaluation</li>
+ <li><span class="secnum"><a href="#sec-class-definitions-runtime-semantics-evaluation">14.5.17</a></span> Runtime
+ Semantics: Evaluation</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-tail-position-calls">14.6</a></span> Tail Position Calls
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-isintailposition">14.6.1</a></span> Static Semantics:
+ IsInTailPosition(nonterminal) Abstract Operation</li>
+ <li><span class="secnum"><a href="#sec-static-semantics-hasproductionintailposition">14.6.2</a></span> Static
+ Semantics: HasProductionInTailPosition</li>
+ <li><span class="secnum"><a href="#sec-preparefortailcall">14.6.3</a></span> Runtime Semantics: PrepareForTailCall (
+ )</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-ecmascript-language-scripts-and-modules">15</a></span> ECMAScript Language: Scripts and
+ Modules
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-scripts">15.1</a></span> Scripts
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-scripts-static-semantics-early-errors">15.1.1</a></span> Static Semantics:
+ Early Errors</li>
+ <li><span class="secnum"><a href="#sec-scripts-static-semantics-isstrict">15.1.2</a></span> Static Semantics:
+ IsStrict</li>
+ <li><span class="secnum"><a href="#sec-scripts-static-semantics-lexicallydeclarednames">15.1.3</a></span> Static
+ Semantics: LexicallyDeclaredNames</li>
+ <li><span class="secnum"><a href="#sec-scripts-static-semantics-lexicallyscopeddeclarations">15.1.4</a></span> Static
+ Semantics: LexicallyScopedDeclarations</li>
+ <li><span class="secnum"><a href="#sec-scripts-static-semantics-vardeclarednames">15.1.5</a></span> Static Semantics:
+ VarDeclaredNames</li>
+ <li><span class="secnum"><a href="#sec-scripts-static-semantics-varscopeddeclarations">15.1.6</a></span> Static
+ Semantics: VarScopedDeclarations</li>
+ <li><span class="secnum"><a href="#sec-runtime-semantics-scriptevaluation">15.1.7</a></span> Runtime Semantics:
+ ScriptEvaluation</li>
+ <li><span class="secnum"><a href="#sec-runtime-semantics-globaldeclarationinstantiation">15.1.8</a></span> Runtime
+ Semantics: GlobalDeclarationInstantiation</li>
+ <li><span class="secnum"><a href="#sec-scriptevaluationtask">15.1.9</a></span> Runtime Semantics: ScriptEvaluationTask
+ ( source )</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-modules">15.2</a></span> Modules
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-module-static-semantics">15.2.0</a></span> Module Static Semantics</li>
+ <li><span class="secnum"><a href="#sec-imports">15.2.1</a></span> Imports</li>
+ <li><span class="secnum"><a href="#sec-exports">15.2.2</a></span> Exports</li>
+ <li><span class="secnum"><a href="#sec-runtime-semantics-loader-state">15.2.3</a></span> Runtime Semantics: Loader
+ State</li>
+ <li><span class="secnum"><a href="#sec-runtime-semantics-module-loading">15.2.4</a></span> Runtime Semantics: Module
+ Loading</li>
+ <li><span class="secnum"><a href="#sec-runtime-semantics-module-linking">15.2.5</a></span> Runtime Semantics: Module
+ Linking</li>
+ <li><span class="secnum"><a href="#sec-runtime-semantics-module-evaluation">15.2.6</a></span> Runtime Semantics:
+ Module Evaluation</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-error-handling-and-language-extensions">16</a></span> Error Handling and Language
+ Extensions</li>
+ <li><span class="secnum"><a href="#sec-ecmascript-standard-built-in-objects">17</a></span> ECMAScript Standard Built-in
+ Objects</li>
+ <li><span class="secnum"><a href="#sec-global-object">18</a></span> The Global Object
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-value-properties-of-the-global-object">18.1</a></span> Value Properties of the
+ Global Object
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-value-properties-of-the-global-object-infinity">18.1.1</a></span> Infinity</li>
+ <li><span class="secnum"><a href="#sec-value-properties-of-the-global-object-nan">18.1.2</a></span> NaN</li>
+ <li><span class="secnum"><a href="#sec-undefined">18.1.3</a></span> undefined</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-function-properties-of-the-global-object">18.2</a></span> Function Properties of
+ the Global Object
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-eval-x">18.2.1</a></span> eval (x)</li>
+ <li><span class="secnum"><a href="#sec-isfinite-number">18.2.2</a></span> isFinite (number)</li>
+ <li><span class="secnum"><a href="#sec-isnan-number">18.2.3</a></span> isNaN (number)</li>
+ <li><span class="secnum"><a href="#sec-parsefloat-string">18.2.4</a></span> parseFloat (string)</li>
+ <li><span class="secnum"><a href="#sec-parseint-string-radix">18.2.5</a></span> parseInt (string , radix)</li>
+ <li><span class="secnum"><a href="#sec-uri-handling-functions">18.2.6</a></span> URI Handling Functions</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-constructor-properties-of-the-global-object">18.3</a></span> Constructor Properties
+ of the Global Object
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-constructor-properties-of-the-global-object-array">18.3.1</a></span> Array ( .
+ . . )</li>
+ <li><span class="secnum"><a href="#sec-constructor-properties-of-the-global-object-arraybuffer">18.3.2</a></span>
+ ArrayBuffer ( . . . )</li>
+ <li><span class="secnum"><a href="#sec-constructor-properties-of-the-global-object-boolean">18.3.3</a></span> Boolean
+ ( . . . )</li>
+ <li><span class="secnum"><a href="#sec-constructor-properties-of-the-global-object-dataview">18.3.4</a></span>
+ DataView ( . . . )</li>
+ <li><span class="secnum"><a href="#sec-constructor-properties-of-the-global-object-date">18.3.5</a></span> Date ( . .
+ . )</li>
+ <li><span class="secnum"><a href="#sec-constructor-properties-of-the-global-object-error">18.3.6</a></span> Error ( .
+ . . )</li>
+ <li><span class="secnum"><a href="#sec-constructor-properties-of-the-global-object-evalerror">18.3.7</a></span>
+ EvalError ( . . . )</li>
+ <li><span class="secnum"><a href="#sec-float32array">18.3.8</a></span> Float32Array ( . . . )</li>
+ <li><span class="secnum"><a href="#sec-float64array">18.3.9</a></span> Float64Array ( . . . )</li>
+ <li><span class="secnum"><a href="#sec-constructor-properties-of-the-global-object-function">18.3.10</a></span>
+ Function ( . . . )</li>
+ <li><span class="secnum"><a href="#sec-int8array">18.3.11</a></span> Int8Array ( . . . )</li>
+ <li><span class="secnum"><a href="#sec-int16array">18.3.12</a></span> Int16Array ( . . . )</li>
+ <li><span class="secnum"><a href="#sec-int32array">18.3.13</a></span> Int32Array ( . . . )</li>
+ <li><span class="secnum"><a href="#sec-map">18.3.14</a></span> Map ( . . . )</li>
+ <li><span class="secnum"><a href="#sec-constructor-properties-of-the-global-object-number">18.3.15</a></span> Number (
+ . . . )</li>
+ <li><span class="secnum"><a href="#sec-constructor-properties-of-the-global-object-object">18.3.16</a></span> Object (
+ . . . )</li>
+ <li><span class="secnum"><a href="#sec-constructor-properties-of-the-global-object-rangeerror">18.3.17</a></span>
+ RangeError ( . . . )</li>
+ <li><span class="secnum"><a href="#sec-constructor-properties-of-the-global-object-referenceerror">18.3.18</a></span>
+ ReferenceError ( . . . )</li>
+ <li><span class="secnum"><a href="#sec-constructor-properties-of-the-global-object-regexp">18.3.19</a></span> RegExp (
+ . . . )</li>
+ <li><span class="secnum"><a href="#sec-set">18.3.20</a></span> Set ( . . . )</li>
+ <li><span class="secnum"><a href="#sec-constructor-properties-of-the-global-object-string">18.3.21</a></span> String (
+ . . . )</li>
+ <li><span class="secnum"><a href="#sec-constructor-properties-of-the-global-object-symbol">18.3.22</a></span> Symbol (
+ . . . )</li>
+ <li><span class="secnum"><a href="#sec-constructor-properties-of-the-global-object-syntaxerror">18.3.23</a></span>
+ SyntaxError ( . . . )</li>
+ <li><span class="secnum"><a href="#sec-constructor-properties-of-the-global-object-typeerror">18.3.24</a></span>
+ TypeError ( . . . )</li>
+ <li><span class="secnum"><a href="#sec-uint8array">18.3.25</a></span> Uint8Array ( . . . )</li>
+ <li><span class="secnum"><a href="#sec-uint8clampedarray">18.3.26</a></span> Uint8ClampedArray ( . . . )</li>
+ <li><span class="secnum"><a href="#sec-uint16array">18.3.27</a></span> Uint16Array ( . . . )</li>
+ <li><span class="secnum"><a href="#sec-uint32array">18.3.28</a></span> Uint32Array ( . . . )</li>
+ <li><span class="secnum"><a href="#sec-constructor-properties-of-the-global-object-urierror">18.3.29</a></span>
+ URIError ( . . . )</li>
+ <li><span class="secnum"><a href="#sec-constructor-properties-of-the-global-object-weakmap">18.3.30</a></span> WeakMap
+ ( . . . )</li>
+ <li><span class="secnum"><a href="#sec-constructor-properties-of-the-global-object-weakset">18.3.31</a></span> WeakSet
+ ( . . . )</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-other-properties-of-the-global-object">18.4</a></span> Other Properties of the
+ Global Object
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-json">18.4.1</a></span> JSON</li>
+ <li><span class="secnum"><a href="#sec-math">18.4.2</a></span> Math</li>
+ <li><span class="secnum"><a href="#sec-other-properties-of-the-global-object-proxy">18.4.3</a></span> Proxy ( . . .
+ )</li>
+ <li><span class="secnum"><a href="#sec-reflect">18.4.4</a></span> Reflect</li>
+ <li><span class="secnum"><a href="#sec-system">18.4.5</a></span> System</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-fundamental-objects">19</a></span> Fundamental Objects
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-object-objects">19.1</a></span> Object Objects
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-object-constructor">19.1.1</a></span> The Object Constructor</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-object-constructor">19.1.2</a></span> Properties of the
+ Object Constructor</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-object-prototype-object">19.1.3</a></span> Properties of the
+ Object Prototype Object</li>
+ <li><span class="secnum"><a href="#sec-properties-of-object-instances">19.1.4</a></span> Properties of Object
+ Instances</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-function-objects">19.2</a></span> Function Objects
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-function-constructor">19.2.1</a></span> The Function Constructor</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-function-constructor">19.2.2</a></span> Properties of the
+ Function Constructor</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-function-prototype-object">19.2.3</a></span> Properties of
+ the Function Prototype Object</li>
+ <li><span class="secnum"><a href="#sec-function-instances">19.2.4</a></span> Function Instances</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-boolean-objects">19.3</a></span> Boolean Objects
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-boolean-constructor">19.3.1</a></span> The Boolean Constructor</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-boolean-constructor">19.3.2</a></span> Properties of the
+ Boolean Constructor</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-boolean-prototype-object">19.3.3</a></span> Properties of the
+ Boolean Prototype Object</li>
+ <li><span class="secnum"><a href="#sec-properties-of-boolean-instances">19.3.4</a></span> Properties of Boolean
+ Instances</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-symbol-objects">19.4</a></span> Symbol Objects
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-symbol-constructor">19.4.1</a></span> The Symbol Constructor</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-symbol-constructor">19.4.2</a></span> Properties of the
+ Symbol Constructor</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-symbol-prototype-object">19.4.3</a></span> Properties of the
+ Symbol Prototype Object</li>
+ <li><span class="secnum"><a href="#sec-properties-of-symbol-instances">19.4.4</a></span> Properties of Symbol
+ Instances</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-error-objects">19.5</a></span> Error Objects
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-error-constructor">19.5.1</a></span> The Error Constructor</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-error-constructor">19.5.2</a></span> Properties of the Error
+ Constructor</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-error-prototype-object">19.5.3</a></span> Properties of the
+ Error Prototype Object</li>
+ <li><span class="secnum"><a href="#sec-properties-of-error-instances">19.5.4</a></span> Properties of Error
+ Instances</li>
+ <li><span class="secnum"><a href="#sec-native-error-types-used-in-this-standard">19.5.5</a></span> Native Error Types
+ Used in This Standard</li>
+ <li><span class="secnum"><a href="#sec-nativeerror-object-structure">19.5.6</a></span> <i>NativeError</i> Object
+ Structure</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-numbers-and-dates">20</a></span> Numbers and Dates
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-number-objects">20.1</a></span> Number Objects
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-number-constructor">20.1.1</a></span> The Number Constructor</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-number-constructor">20.1.2</a></span> Properties of the
+ Number Constructor</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-number-prototype-object">20.1.3</a></span> Properties of the
+ Number Prototype Object</li>
+ <li><span class="secnum"><a href="#sec-properties-of-number-instances">20.1.4</a></span> Properties of Number
+ Instances</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-math-object">20.2</a></span> The Math Object
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-value-properties-of-the-math-object">20.2.1</a></span> Value Properties of the
+ Math Object</li>
+ <li><span class="secnum"><a href="#sec-function-properties-of-the-math-object">20.2.2</a></span> Function Properties
+ of the Math Object</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-date-objects">20.3</a></span> Date Objects
+ <ol class="toc">
+ <li><span class="secnum"><a
+ href="#sec-overview-of-date-objects-and-definitions-of-abstract-operations">20.3.1</a></span> Overview of Date
+ Objects and Definitions of Abstract Operations</li>
+ <li><span class="secnum"><a href="#sec-date-constructor">20.3.2</a></span> The Date Constructor</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-date-constructor">20.3.3</a></span> Properties of the Date
+ Constructor</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-date-prototype-object">20.3.4</a></span> Properties of the
+ Date Prototype Object</li>
+ <li><span class="secnum"><a href="#sec-properties-of-date-instances">20.3.5</a></span> Properties of Date
+ Instances</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-text-processing">21</a></span> Text Processing
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-string-objects">21.1</a></span> String Objects
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-string-constructor">21.1.1</a></span> The String Constructor</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-string-constructor">21.1.2</a></span> Properties of the
+ String Constructor</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-string-prototype-object">21.1.3</a></span> Properties of the
+ String Prototype Object</li>
+ <li><span class="secnum"><a href="#sec-properties-of-string-instances">21.1.4</a></span> Properties of String
+ Instances</li>
+ <li><span class="secnum"><a href="#sec-string-iterator-objects">21.1.5</a></span> String Iterator Objects</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-regexp-regular-expression-objects">21.2</a></span> RegExp (Regular Expression)
+ Objects
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-patterns">21.2.1</a></span> Patterns</li>
+ <li><span class="secnum"><a href="#sec-pattern-semantics">21.2.2</a></span> Pattern Semantics</li>
+ <li><span class="secnum"><a href="#sec-regexp-constructor">21.2.3</a></span> The RegExp Constructor</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-regexp-constructor">21.2.4</a></span> Properties of the
+ RegExp Constructor</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-regexp-prototype-object">21.2.5</a></span> Properties of the
+ RegExp Prototype Object</li>
+ <li><span class="secnum"><a href="#sec-properties-of-regexp-instances">21.2.6</a></span> Properties of RegExp
+ Instances</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-indexed-collections">22</a></span> Indexed Collections
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-array-objects">22.1</a></span> Array Objects
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-array-constructor">22.1.1</a></span> The Array Constructor</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-array-constructor">22.1.2</a></span> Properties of the Array
+ Constructor</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-array-prototype-object">22.1.3</a></span> Properties of the
+ Array Prototype Object</li>
+ <li><span class="secnum"><a href="#sec-properties-of-array-instances">22.1.4</a></span> Properties of Array
+ Instances</li>
+ <li><span class="secnum"><a href="#sec-array-iterator-objects">22.1.5</a></span> Array Iterator Objects</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-typedarray-objects">22.2</a></span> <i>TypedArray</i> Objects
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-%typedarray%-intrinsic-object">22.2.1</a></span> The %TypedArray% Intrinsic
+ Object</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-%typedarray%-intrinsic-object">22.2.2</a></span> Properties
+ of the %TypedArray% Intrinsic Object</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-%typedarrayprototype%-object">22.2.3</a></span> Properties of
+ the %TypedArrayPrototype% Object</li>
+ <li><span class="secnum"><a href="#sec-typedarray-constructors">22.2.4</a></span> The <i>TypedArray</i>
+ Constructors</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-typedarray-constructors">22.2.5</a></span> Properties of the
+ <i>TypedArray</i> Constructors</li>
+ <li><span class="secnum"><a href="#sec-properties-of-typedarray-prototype-objects">22.2.6</a></span> Properties of
+ <i>TypedArray</i> Prototype Objects</li>
+ <li><span class="secnum"><a href="#sec-properties-of-typedarray-instances">22.2.7</a></span> Properties of
+ <i>TypedArray</i> Instances</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-keyed-collection">23</a></span> Keyed Collection
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-map-objects">23.1</a></span> Map Objects
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-map-constructor">23.1.1</a></span> The Map Constructor</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-map-constructor">23.1.2</a></span> Properties of the Map
+ Constructor</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-map-prototype-object">23.1.3</a></span> Properties of the Map
+ Prototype Object</li>
+ <li><span class="secnum"><a href="#sec-properties-of-map-instances">23.1.4</a></span> Properties of Map Instances</li>
+ <li><span class="secnum"><a href="#sec-map-iterator-objects">23.1.5</a></span> Map Iterator Objects</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-set-objects">23.2</a></span> Set Objects
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-set-constructor">23.2.1</a></span> The Set Constructor</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-set-constructor">23.2.2</a></span> Properties of the Set
+ Constructor</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-set-prototype-object">23.2.3</a></span> Properties of the Set
+ Prototype Object</li>
+ <li><span class="secnum"><a href="#sec-properties-of-set-instances">23.2.4</a></span> Properties of Set Instances</li>
+ <li><span class="secnum"><a href="#sec-set-iterator-objects">23.2.5</a></span> Set Iterator Objects</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-weakmap-objects">23.3</a></span> WeakMap Objects
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-weakmap-constructor">23.3.1</a></span> The WeakMap Constructor</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-weakmap-constructor">23.3.2</a></span> Properties of the
+ WeakMap Constructor</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-weakmap-prototype-object">23.3.3</a></span> Properties of the
+ WeakMap Prototype Object</li>
+ <li><span class="secnum"><a href="#sec-properties-of-weakmap-instances">23.3.4</a></span> Properties of WeakMap
+ Instances</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-weakset-objects">23.4</a></span> WeakSet Objects
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-weakset-constructor">23.4.1</a></span> The WeakSet Constructor</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-weakset-constructor">23.4.2</a></span> Properties of the
+ WeakSet Constructor</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-weakset-prototype-object">23.4.3</a></span> Properties of the
+ WeakSet Prototype Object</li>
+ <li><span class="secnum"><a href="#sec-properties-of-weakset-instances">23.4.4</a></span> Properties of WeakSet
+ Instances</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-structured-data">24</a></span> Structured Data
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-arraybuffer-objects">24.1</a></span> ArrayBuffer Objects
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-abstract-operations-for-arraybuffer-objects">24.1.1</a></span> Abstract
+ Operations For ArrayBuffer Objects</li>
+ <li><span class="secnum"><a href="#sec-arraybuffer-constructor">24.1.2</a></span> The ArrayBuffer Constructor</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-arraybuffer-constructor">24.1.3</a></span> Properties of the
+ ArrayBuffer Constructor</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-arraybuffer-prototype-object">24.1.4</a></span> Properties of
+ the ArrayBuffer Prototype Object</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-arraybuffer-instances">24.1.5</a></span> Properties of the
+ ArrayBuffer Instances</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-dataview-objects">24.2</a></span> DataView Objects
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-abstract-operations-for-dataview-objects">24.2.1</a></span> Abstract Operations
+ For DataView Objects</li>
+ <li><span class="secnum"><a href="#sec-dataview-constructor">24.2.2</a></span> The DataView Constructor</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-dataview-constructor">24.2.3</a></span> Properties of the
+ DataView Constructor</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-dataview-prototype-object">24.2.4</a></span> Properties of
+ the DataView Prototype Object</li>
+ <li><span class="secnum"><a href="#sec-properties-of-dataview-instances">24.2.5</a></span> Properties of DataView
+ Instances</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-json-object">24.3</a></span> The JSON Object
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-json.parse">24.3.1</a></span> JSON.parse ( text [ , reviver ] )</li>
+ <li><span class="secnum"><a href="#sec-json.stringify">24.3.2</a></span> JSON.stringify ( value [ , replacer [ , space
+ ] ] )</li>
+ <li><span class="secnum"><a href="#sec-json-@@tostringtag">24.3.3</a></span> JSON [ @@toStringTag ]</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-control-abstraction-objects">25</a></span> Control Abstraction Objects
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-common-iteration-interfaces">25.1</a></span> Common Iteration Interfaces
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-iterable-interface">25.1.1</a></span> The <i>Iterable</i> Interface</li>
+ <li><span class="secnum"><a href="#sec-iterator-interface">25.1.2</a></span> The <i>Iterator</i> Interface</li>
+ <li><span class="secnum"><a href="#sec-iteratorresult-interface">25.1.3</a></span> The <i>IteratorResult</i>
+ Interface</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-generatorfunction-objects">25.2</a></span> GeneratorFunction Objects
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-generatorfunction-constructor">25.2.1</a></span> The GeneratorFunction
+ Constructor</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-generatorfunction-constructor">25.2.2</a></span> Properties
+ of the GeneratorFunction Constructor</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-generatorfunction-prototype-object">25.2.3</a></span>
+ Properties of the GeneratorFunction Prototype Object</li>
+ <li><span class="secnum"><a href="#sec-generatorfunction-instances">25.2.4</a></span> GeneratorFunction Instances</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-generator-objects">25.3</a></span> Generator Objects
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-properties-of-generator-prototype">25.3.1</a></span> Properties of Generator
+ Prototype</li>
+ <li><span class="secnum"><a href="#sec-properties-of-generator-instances">25.3.2</a></span> Properties of Generator
+ Instances</li>
+ <li><span class="secnum"><a href="#sec-generator-abstract-operations">25.3.3</a></span> Generator Abstract
+ Operations</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-promise-objects">25.4</a></span> Promise Objects
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-promise-abstract-operations">25.4.1</a></span> Promise Abstract Operations</li>
+ <li><span class="secnum"><a href="#sec-promise-tasks">25.4.2</a></span> Promise Tasks</li>
+ <li><span class="secnum"><a href="#sec-promise-constructor">25.4.3</a></span> The Promise Constructor</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-promise-constructor">25.4.4</a></span> Properties of the
+ Promise Constructor</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-promise-prototype-object">25.4.5</a></span> Properties of the
+ Promise Prototype Object</li>
+ <li><span class="secnum"><a href="#sec-properties-of-promise-instances">25.4.6</a></span> Properties of Promise
+ Instances</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-reflection">26</a></span> Reflection
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-reflect-object">26.1</a></span> The Reflect Object
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-reflect.apply">26.1.1</a></span> Reflect.apply ( target, thisArgument,
+ argumentsList )</li>
+ <li><span class="secnum"><a href="#sec-reflect.construct">26.1.2</a></span> Reflect.construct ( target, argumentsList
+ )</li>
+ <li><span class="secnum"><a href="#sec-reflect.defineproperty">26.1.3</a></span> Reflect.defineProperty ( target,
+ propertyKey, attributes )</li>
+ <li><span class="secnum"><a href="#sec-reflect.deleteproperty">26.1.4</a></span> Reflect.deleteProperty ( target,
+ propertyKey )</li>
+ <li><span class="secnum"><a href="#sec-reflect.enumerate">26.1.5</a></span> Reflect.enumerate ( target )</li>
+ <li><span class="secnum"><a href="#sec-reflect.get">26.1.6</a></span> Reflect.get ( target, propertyKey [ , receiver
+ ])</li>
+ <li><span class="secnum"><a href="#sec-reflect.getownpropertydescriptor">26.1.7</a></span>
+ Reflect.getOwnPropertyDescriptor ( target, propertyKey )</li>
+ <li><span class="secnum"><a href="#sec-reflect.getprototypeof">26.1.8</a></span> Reflect.getPrototypeOf ( target
+ )</li>
+ <li><span class="secnum"><a href="#sec-reflect.has">26.1.9</a></span> Reflect.has ( target, propertyKey )</li>
+ <li><span class="secnum"><a href="#sec-reflect.isextensible">26.1.10</a></span> Reflect.isExtensible (target)</li>
+ <li><span class="secnum"><a href="#sec-reflect.ownkeys">26.1.11</a></span> Reflect.ownKeys ( target )</li>
+ <li><span class="secnum"><a href="#sec-reflect.preventextensions">26.1.12</a></span> Reflect.preventExtensions (
+ target )</li>
+ <li><span class="secnum"><a href="#sec-reflect.set">26.1.13</a></span> Reflect.set ( target, propertyKey, V [ ,
+ receiver ] )</li>
+ <li><span class="secnum"><a href="#sec-reflect.setprototypeof">26.1.14</a></span> Reflect.setPrototypeOf ( target,
+ proto )</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-realm-objects">26.2</a></span> Realm Objects
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-reflect.realm-constructor">26.2.1</a></span> The Reflect.Realm Constructor</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-reflect.realm-constructor">26.2.2</a></span> Properties of
+ the Reflect.Realm Constructor</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-reflect.realm-prototype-object">26.2.3</a></span> Properties
+ of the Reflect.Realm Prototype Object</li>
+ <li><span class="secnum"><a href="#sec-properties-of-reflect.realm-instances">26.2.4</a></span> Properties of
+ Reflect.Realm Instances</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-loader-objects">26.3</a></span> Loader Objects
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-reflect.loader-constructor">26.3.1</a></span> The Reflect.Loader
+ Constructor</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-loader-constructor">26.3.2</a></span> Properties of the
+ Loader Constructor</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-reflect.loader-prototype-object">26.3.3</a></span> Properties
+ of the Reflect.Loader Prototype Object</li>
+ <li><span class="secnum"><a href="#sec-properties-of-reflect.loader-instances">26.3.4</a></span> Properties of
+ Reflect.Loader Instances</li>
+ <li><span class="secnum"><a href="#sec-loader-iterator-objects">26.3.5</a></span> Loader Iterator Objects</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-system-object">26.4</a></span> The System Object</li>
+ <li><span class="secnum"><a href="#sec-proxy-objects">26.5</a></span> Proxy Objects
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-proxy-constructor-function">26.5.1</a></span> The Proxy Constructor
+ Function</li>
+ <li><span class="secnum"><a href="#sec-properties-of-the-proxy-constructor-function">26.5.2</a></span> Properties of
+ the Proxy Constructor Function</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-grammar-summary">Annex A</a></span> <span
+ class="section-status">(informative)</span> Grammar Summary
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-lexical-grammar">A.1</a></span> Lexical Grammar
+ <ol class="toc">
+ <li>Expressions</li>
+ <li>Statements</li>
+ <li>Functions and Scripts</li>
+ <li>Number Conversions</li>
+ <li>Universal Resource Identifier Character Classes</li>
+ <li>Regular Expressions</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-additional-ecmascript-features-for-web-browsers">Annex B</a></span> <span
+ class="section-status">(normative)</span> Additional ECMAScript Features for Web Browsers
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-additional-syntax">B.1</a></span> Additional Syntax
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-additional-syntax-numeric-literals">B.1.1</a></span> Numeric Literals</li>
+ <li><span class="secnum"><a href="#sec-additional-syntax-string-literals">B.1.2</a></span> String Literals</li>
+ <li><span class="secnum"><a href="#sec-html-like-comments">B.1.3</a></span> HTML-like Comments</li>
+ <li><span class="secnum"><a href="#sec-regular-expressions-patterns">B.1.4</a></span> Regular Expressions
+ Patterns</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-additional-built-in-properties">B.2</a></span> Additional Built-in Properties
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-additional-properties-of-the-global-object">B.2.1</a></span> Additional
+ Properties of the Global Object</li>
+ <li><span class="secnum"><a href="#sec-additional-properties-of-the-object.prototype-object">B.2.2</a></span>
+ Additional Properties of the Object.prototype Object</li>
+ <li><span class="secnum"><a href="#sec-additional-properties-of-the-string.prototype-object">B.2.3</a></span>
+ Additional Properties of the String.prototype Object</li>
+ <li><span class="secnum"><a href="#sec-additional-properties-of-the-date.prototype-object">B.2.4</a></span> Additional
+ Properties of the Date.prototype Object</li>
+ <li><span class="secnum"><a href="#sec-additional-properties-of-the-regexp.prototype-object">B.2.5</a></span>
+ Additional Properties of the RegExp.prototype Object</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-other-additional-features">B.3</a></span> Other Additional Features
+ <ol class="toc">
+ <li><span class="secnum"><a href="#sec-__proto__-property-names-in-object-initializers">B.3.1</a></span> __proto__
+ Property Names in Object Initializers</li>
+ <li><span class="secnum"><a
+ href="#sec-web-legacy-compatibility-for-block-level-function-declarations">B.3.2</a></span> Web Legacy
+ Compatibility for Block-Level Function Declarations</li>
+ <li><span class="secnum"><a href="#sec-variablestatements-in-catch-blocks">B.3.3</a></span> VariableStatements in
+ Catch blocks</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a href="#sec-strict-mode-of-ecmascript">Annex C</a></span> <span
+ class="section-status">(informative)</span> The Strict Mode of ECMAScript</li>
+ <li><span class="secnum"><a
+ href="#sec-corrections-and-clarifications-that-may-introduce-incompatibilities-with-prior-editions">Annex D</a></span>
+ <span class="section-status">(informative)</span> Corrections and Clarifications That May Introduce Incompatibilities with
+ Prior Editions
+ <ol class="toc">
+ <li><span class="secnum"><a
+ href="#sec-corrections-and-clarifications-that-may-introduce-incompatibilities-with-prior-editions-in-the-6th-edition">D.1</a></span>
+ In the 6<sup>th</sup> Edition</li>
+ <li><span class="secnum"><a
+ href="#sec-corrections-and-clarifications-that-may-introduce-incompatibilities-with-prior-editions-in-the-5th-edition">D.2</a></span>
+ In the 5<sup>th</sup> Edition</li>
+ </ol>
+ </li>
+ <li><span class="secnum"><a
+ href="#sec-additions-and-changes-that-introduce-incompatibilities-with-prior-editions">Annex E</a></span> <span
+ class="section-status">(informative)</span> Additions and Changes that Introduce Incompatibilities with Prior Editions
+ <ol class="toc">
+ <li><span class="secnum"><a
+ href="#sec-additions-and-changes-that-introduce-incompatibilities-with-prior-editions-in-the-6th-edition">E.1</a></span>
+ In the 6<sup>th</sup> Edition</li>
+ <li><span class="secnum"><a
+ href="#sec-additions-and-changes-that-introduce-incompatibilities-with-prior-editions-in-the-5th-edition">E.2</a></span>
+ In the 5<sup>th</sup> Edition</li>
+ </ol>
+ </li>
+ <li>Bibliography</li>
+ </ol>
+</section>
+
+<section>
+ <h1>Introduction</h1>
+
+ <p>This Ecma Standard is based on several originating technologies, the most well known being JavaScript (Netscape) and JScript
+ (Microsoft). The language was invented by Brendan Eich at Netscape and first appeared in that company’s Navigator 2.0
+ browser. It has appeared in all subsequent browsers from Netscape and in all browsers from Microsoft starting with Internet
+ Explorer 3.0.</p>
+
+ <p>The development of this Standard started in November 1996. The first edition of this Ecma Standard was adopted by the Ecma
+ General Assembly of June 1997.</p>
+
+ <p>That Ecma Standard was submitted to ISO/IEC JTC 1 for adoption under the fast-track procedure, and approved as international
+ standard ISO/IEC 16262, in April 1998. The Ecma General Assembly of June 1998 approved the second edition of ECMA-262 to keep it
+ fully aligned with ISO/IEC 16262. Changes between the first and the second edition are editorial in nature.</p>
+
+ <p>The third edition of the Standard introduced powerful regular expressions, better string handling, new control statements,
+ try/catch exception handling, tighter definition of errors, formatting for numeric output and minor changes in anticipation of
+ forthcoming internationalisation facilities and future language growth. The third edition of the ECMAScript standard was adopted
+ by the Ecma General Assembly of December 1999 and published as ISO/IEC 16262:2002 in June 2002.</p>
+
+ <p>After publication of the third edition, ECMAScript achieved massive adoption in conjunction with the World Wide Web where it
+ has become the programming language that is supported by essentially all web browsers. Significant work was done to develop a
+ fourth edition of ECMAScript. Although that work was not completed and not published as the fourth edition of ECMAScript, it
+ informs continuing evolution of the language. The fifth edition of ECMAScript (published as ECMA-262 5<sup>th</sup> edition)
+ codified de facto interpretations of the language specification that have become common among browser implementations and added
+ support for new features that had emerged since the publication of the third edition. Such features include accessor properties,
+ reflective creation and inspection of objects, program control of property attributes, additional array manipulation functions,
+ support for the JSON object encoding format, and a strict mode that provides enhanced error checking and program security.</p>
+
+ <p>The edition 5.1 of the ECMAScript Standard is fully aligned with the third edition of the international standard ISO/IEC
+ 16262:2011.</p>
+
+ <p>This present sixth edition of the Standard………</p>
+
+ <p>ECMAScript is a vibrant language and the evolution of the language is not complete. Significant technical enhancement will
+ continue with future editions of this specification.</p>
+
+ <p>This Ecma Standard has been adopted by the General Assembly of <month> <year>.</p>
+
+ <p><i>"DISCLAIMER</i></p>
+
+ <p><i>This draft document may be copied and furnished to others, and derivative works that comment on or otherwise explain it or
+ assist in its implementation may be prepared, copied, published, and distributed, in whole or in part, without restriction of
+ any kind, provided that the above copyright notice and this section are included on all such copies and derivative works.
+ However, this document itself may not be modified in any way, including by removing the copyright notice or references to Ecma
+ International, except as needed for the purpose of developing any document or deliverable produced by Ecma
+ International.</i></p>
+
+ <p><i>This disclaimer is valid only prior to final version of this document. After approval all rights on the standard are
+ reserved by Ecma International.</i></p>
+
+ <p><i>The limited permissions are granted through the standardization phase and will not be revoked by Ecma International or its
+ successors or assigns during this time.</i></p>
+
+ <p><i>This document and the information contained herein is provided on an "AS IS" basis and ECMA INTERNATIONAL DISCLAIMS ALL
+ WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL NOT
+ INFRINGE ANY OWNERSHIP RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE."</i></p>
+</section>
+
+<div class="inner-title">ECMAScript Language Specification</div>
+
+<section id="sec-scope">
+ <h1><span class="secnum" id="sec-1"><a href="#sec-scope" title="link to this section">1</a></span> Scope</h1>
+
+ <p>This Standard defines the ECMAScript scripting language.</p>
+</section>
+
+<section id="sec-conformance">
+ <h1><span class="secnum" id="sec-2"><a href="#sec-conformance" title="link to this section">2</a></span> Conformance</h1>
+
+ <p>A conforming implementation of ECMAScript must provide and support all the types, values, objects, properties, functions, and
+ program syntax and semantics described in this specification.</p>
+
+ <p>A conforming implementation of ECMAScript must interpret characters in conformance with the Unicode Standard, Version 5.1.0
+ or later and ISO/IEC 10646. If the adopted ISO/IEC 10646-1 subset is not otherwise specified, it is presumed to be the Unicode
+ set, collection 10646.</p>
+
+ <p>A conforming implementation of ECMAScript that provides an application programming interface that supports programs that need
+ to adapt to the linguistic and cultural conventions used by different human languages and countries must implement the interface
+ defined by the most recent edition of ECMA-402 that is compatible with this specification.</p>
+
+ <p>A conforming implementation of ECMAScript may provide additional types, values, objects, properties, and functions beyond
+ those described in this specification. In particular, a conforming implementation of ECMAScript may provide properties not
+ described in this specification, and values for those properties, for objects that are described in this specification.</p>
+
+ <p>A conforming implementation of ECMAScript may support program and regular expression syntax not described in this
+ specification. In particular, a conforming implementation of ECMAScript may support program syntax that makes use of the
+ “future reserved words” listed in <a href="#sec-future-reserved-words">subclause 11.6.2.2</a> of this
+ specification.</p>
+</section>
+
+<section id="sec-normative-references">
+ <h1><span class="secnum" id="sec-3"><a href="#sec-normative-references" title="link to this section">3</a></span> Normative
+ references</h1>
+
+ <p>The following referenced documents are indispensable for the application of this document. For dated references, only the
+ edition cited applies. For undated references, the latest edition of the referenced document (including any amendments)
+ applies.</p>
+
+ <p class="formal-reference">IEEE Std 754-2008: <i>IEEE Standard for Floating-Point Arithmetic</i>. Institute of Electrical and
+ Electronic Engineers, New York (2008)</p>
+
+ <p class="formal-reference">ISO/IEC 10646:2003: <i>Information Technology – Universal Multiple-Octet Coded Character Set
+ (UCS) plus Amendment 1:2005, Amendment 2:2006, Amendment 3:2008, and Amendment 4:2008</i>, plus additional amendments and
+ corrigenda, or successor</p>
+
+ <p class="formal-reference"><i>The Unicode Standard, Version 5.0</i>, as amended by Unicode 5.1.0, or successor</p>
+
+ <p class="formal-reference"><i>Unicode Standard Annex #15, Unicode Normalization Forms, version Unicode 5.1.0</i>, or
+ successor</p>
+
+ <p class="formal-reference"><i>Unicode Standard Annex #31, Unicode Identifiers and Pattern Syntax, version Unicode 5.1.0</i>, or
+ successor.</p>
+
+ <p>ECMA-402, <i>ECMAScript Internationalization API Specification</i>.<br><a
+ href="http://www.ecma-international.org/publications/standards/Ecma-402.htm">http://www.ecma-international.org/publications/standards/Ecma-402.htm</a></p>
+
+ <p>ECMA-404, <i>The JSON Data Interchange Format</i>.<br><a
+ href="http://www.ecma-international.org/publications/standards/Ecma-404.htm">http://www.ecma-international.org/publications/standards/Ecma-404.htm</a></p>
+</section>
+
+<section id="sec-overview">
+ <div class="front">
+ <h1><span class="secnum" id="sec-4"><a href="#sec-overview" title="link to this section">4</a></span> Overview</h1>
+
+ <p>This section contains a non-normative overview of the ECMAScript language.</p>
+
+ <p>ECMAScript is an object-oriented programming language for performing computations and manipulating computational objects
+ within a host environment. ECMAScript as defined here is not intended to be computationally self-sufficient; indeed, there are
+ no provisions in this specification for input of external data or output of computed results. Instead, it is expected that the
+ computational environment of an ECMAScript program will provide not only the objects and other facilities described in this
+ specification but also certain environment-specific objects, whose description and behaviour are beyond the scope of this
+ specification except to indicate that they may provide certain properties that can be accessed and certain functions that can
+ be called from an ECMAScript program.</p>
+
+ <p>A <b><i>scripting language</i></b> is a programming language that is used to manipulate, customize, and automate the
+ facilities of an existing system. In such systems, useful functionality is already available through a user interface, and the
+ scripting language is a mechanism for exposing that functionality to program control. In this way, the existing system is said
+ to provide a host environment of objects and facilities, which completes the capabilities of the scripting language. A
+ scripting language is intended for use by both professional and non-professional programmers. ECMAScript was originally
+ designed to be used as a scripting language, but has become widely used as a general purpose programming language.</p>
+
+ <p>ECMAScript was originally designed to be a <b><i>Web scripting language</i></b>, providing a mechanism to enliven Web pages
+ in browsers and to perform server computation as part of a Web-based client-server architecture. ECMAScript is now used both
+ as a general propose programming language and to provide core scripting capabilities for a variety of host environments.
+ Therefore the core language is specified in this document apart from any particular host environment.</p>
+
+ <p>Some of the facilities of ECMAScript are similar to those used in other programming languages; in particular C,
+ Java™, Self, and Scheme as described in:</p>
+
+ <p>ISO/IEC 9899:1996, Programming Languages – C.</p>
+
+ <p class="formal-reference">Gosling, James, Bill Joy and Guy Steele. <span class="book-title">The Java™ Language
+ Specification</span>. Addison Wesley Publishing Co., 1996.</p>
+
+ <p class="formal-reference">Ungar, David, and Smith, Randall B. <span class="book-title">Self: The Power of Simplicity</span>.
+ OOPSLA '87 Conference Proceedings, pp. 227–241, Orlando, FL, October 1987.</p>
+
+ <p class="formal-reference"><span class="book-title">IEEE Standard for the Scheme Programming Language</span>. IEEE Std
+ 1178-1990.</p>
+ </div>
+
+ <section id="sec-web-scripting">
+ <h1><span class="secnum" id="sec-4.1"><a href="#sec-web-scripting" title="link to this section">4.1</a></span> Web
+ Scripting</h1>
+
+ <p>A web browser provides an ECMAScript host environment for client-side computation including, for instance, objects that
+ represent windows, menus, pop-ups, dialog boxes, text areas, anchors, frames, history, cookies, and input/output. Further, the
+ host environment provides a means to attach scripting code to events such as change of focus, page and image loading,
+ unloading, error and abort, selection, form submission, and mouse actions. Scripting code appears within the HTML and the
+ displayed page is a combination of user interface elements and fixed and computed text and images. The scripting code is
+ reactive to user interaction and there is no need for a main program.</p>
+
+ <p>A web server provides a different host environment for server-side computation including objects representing requests,
+ clients, and files; and mechanisms to lock and share data. By using browser-side and server-side scripting together, it is
+ possible to distribute computation between the client and server while providing a customized user interface for a Web-based
+ application.</p>
+
+ <p>Each Web browser and server that supports ECMAScript supplies its own host environment, completing the ECMAScript execution
+ environment.</p>
+ </section>
+
+ <section id="sec-ecmascript-overview">
+ <div class="front">
+ <h1><span class="secnum" id="sec-4.2"><a href="#sec-ecmascript-overview" title="link to this section">4.2</a></span>
+ ECMAScript Overview</h1>
+
+ <p>The following is an informal overview of ECMAScript—not all parts of the language are described. This overview is
+ not part of the standard proper.</p>
+
+ <p>ECMAScript is object-based: basic language and host facilities are provided by objects, and an ECMAScript program is a
+ cluster of communicating objects. In ECMAScript, an <b><i>object</i></b> is a collection of <b><i>properties</i></b> each
+ with zero or more <b><i>attributes</i></b> that determine how each property can be used—for example, when the Writable
+ attribute for a property is set to <b>false</b>, any attempt by executed ECMAScript code to change the value of the property
+ fails. Properties are containers that hold other objects, <b><i>primitive values</i></b>, or <b><i>functions</i></b>. A
+ primitive value is a member of one of the following built-in types: <b>Undefined</b>, <b>Null</b>, <b>Boolean</b>,
+ <b>Number</b>, <b>Symbol</b> and <b>String</b>; an object is a member of the remaining built-in type <b>Object</b>; and a
+ function is a callable object. A function that is associated with an object via a property is a <b><i>method</i></b>.</p>
+
+ <p>ECMAScript defines a collection of <b><i>built-in objects</i></b> that round out the definition of ECMAScript entities.
+ These built-in objects include the global object, the <b>Object</b> object, the <b>Function</b> object, the <b>Array</b>
+ object, the <b>String</b> object, the <b>Boolean</b> object, the <b>Number</b> object, the <b>Math</b> object, the
+ <b>Date</b> object, the <b>RegExp</b> object, the <b>JSON</b> object, and the Error objects <b>Error, EvalError</b>,
+ <b>RangeError, ReferenceError, SyntaxError, TypeError</b> and <b><a
+ href="#sec-constructor-properties-of-the-global-object-urierror">URIError</a></b>.</p>
+
+ <p>ECMAScript also defines a set of built-in <b><i>operators</i></b>. ECMAScript operators include various unary operations,
+ multiplicative operators, additive operators, bitwise shift operators, relational operators, equality operators, binary
+ bitwise operators, binary logical operators, assignment operators, and the comma operator.</p>
+
+ <p>ECMAScript syntax intentionally resembles Java syntax. ECMAScript syntax is relaxed to enable it to serve as an
+ easy-to-use scripting language. For example, a variable is not required to have its type declared nor are types associated
+ with properties, and defined functions are not required to have their declarations appear textually before calls to
+ them.</p>
+ </div>
+
+ <section id="sec-objects">
+ <h1><span class="secnum" id="sec-4.2.1"><a href="#sec-objects" title="link to this section">4.2.1</a></span> Objects</h1>
+
+ <p>ECMAScript objects are not fundamentally class-based such as those in C++, Smalltalk, or Java. Instead objects may be
+ created in various ways including via a literal notation or via <b><i>constructors</i></b> which create objects and then
+ execute code that initializes all or part of them by assigning initial values to their properties. Each constructor is a
+ function that has a property named “<code>prototype</code>” that is used to implement <b><i>prototype-based
+ inheritance</i></b> and <b><i>shared properties</i></b>. Objects are created by using constructors in <b>new</b>
+ expressions; for example, <code>new Date(2009,11)</code> creates a new Date object. Invoking a constructor without using
+ <b>new</b> has consequences that depend on the constructor. For example, <code>Date()</code> produces a string
+ representation of the current date and time rather than an object.</p>
+
+ <p>Every object created by a constructor has an implicit reference (called the object’s <i>prototype</i>) to the value
+ of its constructor’s “<code>prototype</code>” property. Furthermore, a prototype may have a non-null
+ implicit reference to its prototype, and so on; this is called the <i>prototype chain</i>. When a reference is made to a
+ property in an object, that reference is to the property of that name in the first object in the prototype chain that
+ contains a property of that name. In other words, first the object mentioned directly is examined for such a property; if
+ that object contains the named property, that is the property to which the reference refers; if that object does not contain
+ the named property, the prototype for that object is examined next; and so on.</p>
+
+ <figure>
+ <object data="figure-1.svg" height="354" type="image/svg+xml" width="719">
+ <img alt="An image of lots of boxes and arrows." height="354" src="figure-1.png" width="719">
+ </object>
+ <figcaption>Figure 1 — Object/Prototype Relationships</figcaption>
+ </figure>
+
+ <p>In a class-based object-oriented language, in general, state is carried by instances, methods are carried by classes, and
+ inheritance is only of structure and behaviour. In ECMAScript, the state and methods are carried by objects, while
+ structure, behaviour, and state are all inherited.</p>
+
+ <p>All objects that do not directly contain a particular property that their prototype contains share that property and its
+ value. Figure 1 illustrates this:</p>
+
+ <p><b>CF</b> is a constructor (and also an object). Five objects have been created by using <code>new</code> expressions:
+ <b>cf<sub>1</sub></b>, <b>cf<sub>2</sub></b>, <b>cf<sub>3</sub></b>, <b>cf<sub>4</sub></b>, and <b>cf<sub>5</sub></b>. Each
+ of these objects contains properties named <code>q1</code> and <code>q2</code>. The dashed lines represent the implicit
+ prototype relationship; so, for example, <b>cf<sub>3</sub></b>’s prototype is <b>CF<sub>p</sub></b>. The constructor,
+ <b>CF</b>, has two properties itself, named <code>P1</code> and <code>P2</code>, which are not visible to
+ <b>CF<sub>p</sub></b>, <b>cf<sub>1</sub></b>, <b>cf<sub>2</sub></b>, <b>cf<sub>3</sub></b>, <b>cf<sub>4</sub></b>, or
+ <b>cf<sub>5</sub></b>. The property named <code>CFP1</code> in <b>CF<sub>p</sub></b> is shared by <b>cf<sub>1</sub></b>,
+ <b>cf<sub>2</sub></b>, <b>cf<sub>3</sub></b>, <b>cf<sub>4</sub></b>, and <b>cf<sub>5</sub></b> (but not by <b>CF</b>), as
+ are any properties found in <b>CF<sub>p</sub></b>’s implicit prototype chain that are not named <code>q1</code>,
+ <code>q2</code>, or <code>CFP1</code>. Notice that there is no implicit prototype link between <b>CF</b> and
+ <b>CF<sub>p</sub></b>.</p>
+
+ <p>Unlike most class-based object languages, properties can be added to objects dynamically by assigning values to them.
+ That is, constructors are not required to name or assign values to all or any of the constructed object’s properties.
+ In the above diagram, one could add a new shared property for <b>cf<sub>1</sub></b>, <b>cf<sub>2</sub></b>,
+ <b>cf<sub>3</sub></b>, <b>cf<sub>4</sub></b>, and <b>cf<sub>5</sub></b> by assigning a new value to the property in
+ <b>CF<sub>p</sub></b>.</p>
+
+ <p>Although ECMAScript objects are not inherently class-based, it is often convenient to define class-like abstractions
+ based upon a common pattern of constructor functions, prototype objects, and methods. The ECMAScript built-in object
+ themselves follow such a class-like pattern. The ECMAScript language includes syntatic class definitions that permit
+ programmers to concisely define objects that conform to the same class-like abstraction pattern used by the built-in
+ objects.</p>
+ </section>
+
+ <section id="sec-strict-variant-of-ecmascript">
+ <h1><span class="secnum" id="sec-4.2.2"><a href="#sec-strict-variant-of-ecmascript"
+ title="link to this section">4.2.2</a></span> The Strict Variant of ECMAScript</h1>
+
+ <p>The ECMAScript Language recognizes the possibility that some users of the language may wish to restrict their usage of
+ some features available in the language. They might do so in the interests of security, to avoid what they consider to be
+ error-prone features, to get enhanced error checking, or for other reasons of their choosing. In support of this
+ possibility, ECMAScript defines a strict variant of the language. The strict variant of the language excludes some specific
+ syntactic and semantic features of the regular ECMAScript language and modifies the detailed semantics of some features. The
+ strict variant also specifies additional error conditions that must be reported by throwing error exceptions in situations
+ that are not specified as errors by the non-strict form of the language.</p>
+
+ <p>The strict variant of ECMAScript is commonly referred to as the <i>strict mode</i> of the language. Strict mode selection
+ and use of the strict mode syntax and semantics of ECMAScript is explicitly made at the level of individual ECMAScript code
+ units. Because strict mode is selected at the level of a syntactic code unit, strict mode only imposes restrictions that
+ have local effect within such a code unit. Strict mode does not restrict or modify any aspect of the ECMAScript semantics
+ that must operate consistently across multiple code units. A complete ECMAScript program may be composed for both strict
+ mode and non-strict mode ECMAScript code units. In this case, strict mode only applies when actually executing code that is
+ defined within a <a href="#sec-strict-mode-code">strict mode code</a> unit.</p>
+
+ <p>In order to conform to this specification, an ECMAScript implementation must implement both the full unrestricted
+ ECMAScript language and the strict mode variant of the ECMAScript language as defined by this specification. In addition, an
+ implementation must support the combination of unrestricted and <a href="#sec-strict-mode-code">strict mode code</a> units
+ into a single composite program.</p>
+ </section>
+ </section>
+
+ <section id="sec-terms-and-definitions">
+ <div class="front">
+ <h1><span class="secnum" id="sec-4.3"><a href="#sec-terms-and-definitions" title="link to this section">4.3</a></span> Terms
+ and definitions</h1>
+
+ <p>For the purposes of this document, the following terms and definitions apply.</p>
+ </div>
+
+ <section id="sec-type">
+ <h1><span class="secnum" id="sec-4.3.1"><a href="#sec-type" title="link to this section">4.3.1</a></span> type</h1>
+
+ <p>set of data values as defined in <a href="#sec-ecmascript-data-types-and-values">clause 6</a> of this specification</p>
+ </section>
+
+ <section id="sec-primitive-value">
+ <h1><span class="secnum" id="sec-4.3.2"><a href="#sec-primitive-value" title="link to this section">4.3.2</a></span>
+ primitive value</h1>
+
+ <p>member of one of the types Undefined, Null, Boolean, Number, Symbol, or String as defined in <a
+ href="#sec-ecmascript-data-types-and-values">clause 6</a></p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> A primitive value is a datum that is represented directly at the lowest level of the
+ language implementation.</p>
+ </div>
+ </section>
+
+ <section id="sec-terms-and-definitions-object">
+ <h1><span class="secnum" id="sec-4.3.3"><a href="#sec-terms-and-definitions-object"
+ title="link to this section">4.3.3</a></span> object</h1>
+
+ <p>member of the type Object</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> An object is a collection of properties and has a single prototype object. The prototype
+ may be the null value.</p>
+ </div>
+ </section>
+
+ <section id="sec-constructor">
+ <h1><span class="secnum" id="sec-4.3.4"><a href="#sec-constructor" title="link to this section">4.3.4</a></span>
+ constructor</h1>
+
+ <p>function object that creates and initializes objects</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The value of a constructor’s “<code>prototype</code>” property is a
+ prototype object that is used to implement inheritance and shared properties.</p>
+ </div>
+ </section>
+
+ <section id="sec-terms-and-definitions-prototype">
+ <h1><span class="secnum" id="sec-4.3.5"><a href="#sec-terms-and-definitions-prototype"
+ title="link to this section">4.3.5</a></span> prototype</h1>
+
+ <p>object that provides shared properties for other objects</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> When a constructor creates an object, that object implicitly references the
+ constructor’s “<code>prototype</code>” property for the purpose of resolving property references. The
+ constructor’s “<code>prototype</code>” property can be referenced by the program expression
+ <code><i>constructor</i><b>.prototype</b></code>, and properties added to an object’s prototype are shared, through
+ inheritance, by all objects sharing the prototype. Alternatively, a new object may be created with an explicitly specified
+ prototype by using the <code><a href="#sec-object.create">Object.create</a></code> built-in function.</p>
+ </div>
+ </section>
+
+ <section id="sec-ordinary-object">
+ <h1><span class="secnum" id="sec-4.3.6"><a href="#sec-ordinary-object" title="link to this section">4.3.6</a></span>
+ ordinary object</h1>
+
+ <p>object that has the default behaviour for the essential internal methods that must be supported by all objects.</p>
+ </section>
+
+ <section id="sec-exotic-object">
+ <h1><span class="secnum" id="sec-4.3.7"><a href="#sec-exotic-object" title="link to this section">4.3.7</a></span> exotic
+ object</h1>
+
+ <p>object that has some alternative behaviour for one or more of the essential internal methods that must be supported by
+ all objects.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Any object that is not an ordinary object is an exotic object.</p>
+ </div>
+ </section>
+
+ <section id="sec-standard-object">
+ <h1><span class="secnum" id="sec-4.3.8"><a href="#sec-standard-object" title="link to this section">4.3.8</a></span>
+ standard object</h1>
+
+ <p>object whose semantics are defined by this specification.</p>
+ </section>
+
+ <section id="sec-built-in-object">
+ <h1><span class="secnum" id="sec-4.3.9"><a href="#sec-built-in-object" title="link to this section">4.3.9</a></span>
+ built-in object</h1>
+
+ <p>object supplied by an ECMAScript implementation, independent of the host environment, that is present at the start of the
+ execution of an ECMAScript program</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Standard built-in objects are defined in this specification, and an ECMAScript
+ implementation may specify and define others. A <i>built-in constructor</i> is a built-in object that is also a
+ constructor.</p>
+ </div>
+ </section>
+
+ <section id="sec-undefined-value">
+ <h1><span class="secnum" id="sec-4.3.10"><a href="#sec-undefined-value" title="link to this section">4.3.10</a></span>
+ undefined value</h1>
+
+ <p>primitive value used when a variable has not been assigned a value</p>
+ </section>
+
+ <section id="sec-terms-and-definitions-undefined-type">
+ <h1><span class="secnum" id="sec-4.3.11"><a href="#sec-terms-and-definitions-undefined-type"
+ title="link to this section">4.3.11</a></span> Undefined type</h1>
+
+ <p>type whose sole value is the <b>undefined</b> value</p>
+ </section>
+
+ <section id="sec-null-value">
+ <h1><span class="secnum" id="sec-4.3.12"><a href="#sec-null-value" title="link to this section">4.3.12</a></span> null
+ value</h1>
+
+ <p>primitive value that represents the intentional absence of any object value</p>
+ </section>
+
+ <section id="sec-terms-and-definitions-null-type">
+ <h1><span class="secnum" id="sec-4.3.13"><a href="#sec-terms-and-definitions-null-type"
+ title="link to this section">4.3.13</a></span> Null type</h1>
+
+ <p>type whose sole value is the null value</p>
+ </section>
+
+ <section id="sec-terms-and-definitions-boolean-value">
+ <h1><span class="secnum" id="sec-4.3.14"><a href="#sec-terms-and-definitions-boolean-value"
+ title="link to this section">4.3.14</a></span> Boolean value</h1>
+
+ <p>member of the Boolean type</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> There are only two Boolean values, <b>true</b> and <b>false</b>.</p>
+ </div>
+ </section>
+
+ <section id="sec-terms-and-definitions-boolean-type">
+ <h1><span class="secnum" id="sec-4.3.15"><a href="#sec-terms-and-definitions-boolean-type"
+ title="link to this section">4.3.15</a></span> Boolean type</h1>
+
+ <p>type consisting of the primitive values <b>true</b> and <b>false</b></p>
+ </section>
+
+ <section id="sec-boolean-object">
+ <h1><span class="secnum" id="sec-4.3.16"><a href="#sec-boolean-object" title="link to this section">4.3.16</a></span>
+ Boolean object</h1>
+
+ <p>member of the Object type that is an instance of the standard built-in <code>Boolean</code> constructor</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> A Boolean object is created by using the <code>Boolean</code> constructor in a
+ <code>new</code> expression, supplying a Boolean value as an argument. The resulting object has an <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> whose value is the Boolean value. A Boolean
+ object can be coerced to a Boolean value.</p>
+ </div>
+ </section>
+
+ <section id="sec-terms-and-definitions-string-value">
+ <h1><span class="secnum" id="sec-4.3.17"><a href="#sec-terms-and-definitions-string-value"
+ title="link to this section">4.3.17</a></span> String value</h1>
+
+ <p>primitive value that is a finite ordered sequence of zero or more 16-bit unsigned integer</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> A String value is a member of the String type. Each integer value in the sequence usually
+ represents a single 16-bit unit of UTF-16 text. However, ECMAScript does not place any restrictions or requirements on the
+ values except that they must be 16-bit unsigned integers.</p>
+ </div>
+ </section>
+
+ <section id="sec-terms-and-definitions-string-type">
+ <h1><span class="secnum" id="sec-4.3.18"><a href="#sec-terms-and-definitions-string-type"
+ title="link to this section">4.3.18</a></span> String type</h1>
+
+ <p>set of all possible String values</p>
+ </section>
+
+ <section id="sec-string-object">
+ <h1><span class="secnum" id="sec-4.3.19"><a href="#sec-string-object" title="link to this section">4.3.19</a></span> String
+ object</h1>
+
+ <p>member of the Object type that is an instance of the standard built-in <code>String</code> constructor</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> A String object is created by using the <code>String</code> constructor in a
+ <code>new</code> expression, supplying a String value as an argument. The resulting object has an <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> whose value is the String value. A String object
+ can be coerced to a String value by calling the <code>String</code> constructor as a function (<a
+ href="#sec-string-constructor-string-value">21.1.1.1</a>).</p>
+ </div>
+ </section>
+
+ <section id="sec-terms-and-definitions-number-value">
+ <h1><span class="secnum" id="sec-4.3.20"><a href="#sec-terms-and-definitions-number-value"
+ title="link to this section">4.3.20</a></span> Number value</h1>
+
+ <p>primitive value corresponding to a double-precision 64-bit binary format IEEE 754 value</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> A Number value is a member of the Number type and is a direct representation of a
+ number.</p>
+ </div>
+ </section>
+
+ <section id="sec-terms-and-definitions-number-type">
+ <h1><span class="secnum" id="sec-4.3.21"><a href="#sec-terms-and-definitions-number-type"
+ title="link to this section">4.3.21</a></span> Number type</h1>
+
+ <p>set of all possible Number values including the special “Not-a-Number” (NaN) value, positive infinity, and
+ negative infinity</p>
+ </section>
+
+ <section id="sec-number-object">
+ <h1><span class="secnum" id="sec-4.3.22"><a href="#sec-number-object" title="link to this section">4.3.22</a></span> Number
+ object</h1>
+
+ <p>member of the Object type that is an instance of the standard built-in <code>Number</code> constructor</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> A Number object is created by using the <code>Number</code> constructor in a
+ <code>new</code> expression, supplying a Number value as an argument. The resulting object has an <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> whose value is the Number value. A Number object
+ can be coerced to a Number value by calling the <code>Number</code> constructor as a function (<a
+ href="#sec-number-constructor-number-value">20.1.1.1</a>).</p>
+ </div>
+ </section>
+
+ <section id="sec-terms-and-definitions-infinity">
+ <h1><span class="secnum" id="sec-4.3.23"><a href="#sec-terms-and-definitions-infinity"
+ title="link to this section">4.3.23</a></span> Infinity</h1>
+
+ <p>number value that is the positive infinite Number value</p>
+ </section>
+
+ <section id="sec-terms-and-definitions-nan">
+ <h1><span class="secnum" id="sec-4.3.24"><a href="#sec-terms-and-definitions-nan"
+ title="link to this section">4.3.24</a></span> NaN</h1>
+
+ <p>number value that is an IEEE 754 “Not-a-Number” value</p>
+ </section>
+
+ <section id="sec-symbol-value">
+ <h1><span class="secnum" id="sec-4.3.25"><a href="#sec-symbol-value" title="link to this section">4.3.25</a></span> Symbol
+ value</h1>
+
+ <p>primitive value that represents a unique, non-String Object <a href="#sec-object-type">property key</a>.</p>
+ </section>
+
+ <section id="sec-terms-and-definitions-symbol-type">
+ <h1><span class="secnum" id="sec-4.3.26"><a href="#sec-terms-and-definitions-symbol-type"
+ title="link to this section">4.3.26</a></span> Symbol type</h1>
+
+ <p>set of all possible Symbol values</p>
+ </section>
+
+ <section id="sec-symbol-object">
+ <h1><span class="secnum" id="sec-4.3.27"><a href="#sec-symbol-object" title="link to this section">4.3.27</a></span> Symbol
+ object</h1>
+
+ <p>member of the Object type that is an instance of the standard built-in <code>Symbol</code> constructor</p>
+ </section>
+
+ <section id="sec-terms-and-definitions-function">
+ <h1><span class="secnum" id="sec-4.3.28"><a href="#sec-terms-and-definitions-function"
+ title="link to this section">4.3.28</a></span> function</h1>
+
+ <p>member of the Object type that may be invoked as a subroutine</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> In addition to its properties, a function contains executable code and state that
+ determine how it behaves when invoked. A function’s code may or may not be written in ECMAScript.</p>
+ </div>
+ </section>
+
+ <section id="sec-built-in-function">
+ <h1><span class="secnum" id="sec-4.3.29"><a href="#sec-built-in-function" title="link to this section">4.3.29</a></span>
+ built-in function</h1>
+
+ <p>built-in object that is a function</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Examples of built-in functions include <code>parseInt</code> and <code><a
+ href="#sec-math.exp">Math.exp</a></code>. An implementation may provide implementation-dependent built-in functions that
+ are not described in this specification.</p>
+ </div>
+ </section>
+
+ <section id="sec-property">
+ <h1><span class="secnum" id="sec-4.3.30"><a href="#sec-property" title="link to this section">4.3.30</a></span>
+ property</h1>
+
+ <p>association between a key and a value that is a part of an object. The key be either a String value or a Symbol
+ value.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Depending upon the form of the property the value may be represented either directly as a
+ data value (a primitive value, an object, or a function object) or indirectly by a pair of accessor functions.</p>
+ </div>
+ </section>
+
+ <section id="sec-method">
+ <h1><span class="secnum" id="sec-4.3.31"><a href="#sec-method" title="link to this section">4.3.31</a></span> method</h1>
+
+ <p>function that is the value of a property</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> When a function is called as a method of an object, the object is passed to the function
+ as its <b>this</b> value.</p>
+ </div>
+ </section>
+
+ <section id="sec-built-in-method">
+ <h1><span class="secnum" id="sec-4.3.32"><a href="#sec-built-in-method" title="link to this section">4.3.32</a></span>
+ built-in method</h1>
+
+ <p>method that is a built-in function</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Standard built-in methods are defined in this specification, and an ECMAScript
+ implementation may specify and provide other additional built-in methods.</p>
+ </div>
+ </section>
+
+ <section id="sec-attribute">
+ <h1><span class="secnum" id="sec-4.3.33"><a href="#sec-attribute" title="link to this section">4.3.33</a></span>
+ attribute</h1>
+
+ <p>internal value that defines some characteristic of a property</p>
+ </section>
+
+ <section id="sec-own-property">
+ <h1><span class="secnum" id="sec-4.3.34"><a href="#sec-own-property" title="link to this section">4.3.34</a></span> own
+ property</h1>
+
+ <p>property that is directly contained by its object</p>
+ </section>
+
+ <section id="sec-inherited-property">
+ <h1><span class="secnum" id="sec-4.3.35"><a href="#sec-inherited-property" title="link to this section">4.3.35</a></span>
+ inherited property</h1>
+
+ <p>property of an object that is not an own property but is a property (either own or inherited) of the object’s
+ prototype</p>
+ </section>
+ </section>
+
+ <section id="sec-organization-of-this-specification">
+ <h1><span class="secnum" id="sec-4.4"><a href="#sec-organization-of-this-specification"
+ title="link to this section">4.4</a></span> Organization of This Specification</h1>
+
+ <p>The remainder of this specification is organized as follows:</p>
+
+ <p>Clause 5 defines the notational conventions used throughout the specification.</p>
+
+ <p>Clauses 6−<a href="#sec-initializefirstrealm">8.5.1</a> define the execution environment within which ECMAScript
+ programs operate.</p>
+
+ <p>Clauses 10−16 define the actual ECMAScript programming language includings its syntactic encoding and the execution
+ semantics of all language features.</p>
+
+ <p>Clauses 17−26 define the ECMAScript standard library. It includes the definitions of all of the standard objects that
+ are available for use by ECMAScript programs as they execute.</p>
+ </section>
+</section>
+
+<section id="sec-notational-conventions">
+ <div class="front">
+ <h1><span class="secnum" id="sec-5"><a href="#sec-notational-conventions" title="link to this section">5</a></span> Notational
+ Conventions</h1>
+ </div>
+
+ <section id="sec-syntactic-and-lexical-grammars">
+ <div class="front">
+ <h1><span class="secnum" id="sec-5.1"><a href="#sec-syntactic-and-lexical-grammars"
+ title="link to this section">5.1</a></span> Syntactic and Lexical Grammars</h1>
+ </div>
+
+ <section id="sec-context-free-grammars">
+ <h1><span class="secnum" id="sec-5.1.1"><a href="#sec-context-free-grammars" title="link to this section">5.1.1</a></span>
+ Context-Free Grammars</h1>
+
+ <p>A <i>context-free grammar</i> consists of a number of <i>productions</i>. Each production has an abstract symbol called a
+ <i>nonterminal</i> as its <i>left-hand side</i>, and a sequence of zero or more nonterminal and <i>terminal</i> symbols as
+ its <i>right-hand side</i>. For each grammar, the terminal symbols are drawn from a specified alphabet.</p>
+
+ <p>A <i>chain production</i> is a production that has exactly one nonterminal symbol on its right-hand side along with zero
+ or more terminal symbols.</p>
+
+ <p>Starting from a sentence consisting of a single distinguished nonterminal, called the <i>goal symbol</i>, a given
+ context-free grammar specifies a <i>language</i>, namely, the (perhaps infinite) set of possible sequences of terminal
+ symbols that can result from repeatedly replacing any nonterminal in the sequence with a right-hand side of a production for
+ which the nonterminal is the left-hand side.</p>
+ </section>
+
+ <section id="sec-lexical-and-regexp-grammars">
+ <h1><span class="secnum" id="sec-5.1.2"><a href="#sec-lexical-and-regexp-grammars"
+ title="link to this section">5.1.2</a></span> The Lexical and RegExp Grammars</h1>
+
+ <p>A <i>lexical grammar</i> for ECMAScript is given in <a href="#sec-ecmascript-language-lexical-grammar">clause 11</a>.
+ This grammar has as its terminal symbols characters (Unicode code points) that conform to the rules for <span
+ class="nt">SourceCharacter</span> defined in <a href="#sec-source-text">10.1</a>. It defines a set of productions, starting
+ from the goal symbol <span class="nt">InputElementDiv</span> or <span class="nt">InputElementRegExp</span>, that describe
+ how sequences of such characters are translated into a sequence of input elements.</p>
+
+ <p>Input elements other than white space and comments form the terminal symbols for the syntactic grammar for ECMAScript and
+ are called ECMAScript <i>tokens</i>. These tokens are the reserved words, identifiers, literals, and punctuators of the
+ ECMAScript language. Moreover, line terminators, although not considered to be tokens, also become part of the stream of
+ input elements and guide the process of <a href="#sec-automatic-semicolon-insertion">automatic semicolon insertion</a> (<a
+ href="#sec-automatic-semicolon-insertion">11.9</a>). Simple white space and single-line comments are discarded and do not
+ appear in the stream of input elements for the syntactic grammar. A <span class="nt">MultiLineComment</span> (that is, a
+ comment of the form “<code>/*</code>…<code>*/</code>” regardless of whether it spans more than one line)
+ is likewise simply discarded if it contains no line terminator; but if a <span class="nt">MultiLineComment</span> contains
+ one or more line terminators, then it is replaced by a single line terminator, which becomes part of the stream of input
+ elements for the syntactic grammar.</p>
+
+ <p>A <i>RegExp grammar</i> for ECMAScript is given in <a href="#sec-patterns">21.2.1</a>. This grammar also has as its
+ terminal symbols the characters as defined by <span class="nt">SourceCharacter</span>. It defines a set of productions,
+ starting from the goal symbol <span class="nt">Pattern</span>, that describe how sequences of characters are translated into
+ regular expression patterns.</p>
+
+ <p>Productions of the lexical and RegExp grammars are distinguished by having two colons “<b>::</b>” as
+ separating punctuation. The lexical and RegExp grammars share some productions.</p>
+ </section>
+
+ <section id="sec-numeric-string-grammar">
+ <h1><span class="secnum" id="sec-5.1.3"><a href="#sec-numeric-string-grammar" title="link to this section">5.1.3</a></span>
+ The Numeric String Grammar</h1>
+
+ <p>Another grammar is used for translating Strings into numeric values. This grammar is similar to the part of the lexical
+ grammar having to do with numeric literals and has as its terminal symbols <span class="nt">SourceCharacter</span>. This
+ grammar appears in <a href="#sec-tonumber-applied-to-the-string-type">7.1.3.1</a>.</p>
+
+ <p>Productions of the numeric string grammar are distinguished by having three colons “<b>:::</b>” as
+ punctuation.</p>
+ </section>
+
+ <section id="sec-syntactic-grammar">
+ <h1><span class="secnum" id="sec-5.1.4"><a href="#sec-syntactic-grammar" title="link to this section">5.1.4</a></span> The
+ Syntactic Grammar</h1>
+
+ <p>The <i>syntactic grammar</i> for ECMAScript is given in clauses 11, 12, 13, 14, and 15. This grammar has ECMAScript
+ tokens defined by the lexical grammar as its terminal symbols (<a href="#sec-lexical-and-regexp-grammars">5.1.2</a>). It
+ defines a set of productions, starting from the goal symbol <span class="nt">Script</span>, that describe how sequences of
+ tokens can form syntactically correct independent components of an ECMAScript programs.</p>
+
+ <p>When a stream of characters is to be parsed as an ECMAScript script, it is first converted to a stream of input elements
+ by repeated application of the lexical grammar; this stream of input elements is then parsed by a single application of the
+ syntactic grammar. The script is syntactically in error if the tokens in the stream of input elements cannot be parsed as a
+ single instance of the goal nonterminal <span class="nt">Script</span>, with no tokens left over.</p>
+
+ <p>Productions of the syntactic grammar are distinguished by having just one colon “<b>:</b>” as
+ punctuation.</p>
+
+ <p>The syntactic grammar as presented in clauses 12, 13, 14 and 15 is actually not a complete account of which token
+ sequences are accepted as correct ECMAScript scripts. Certain additional token sequences are also accepted, namely, those
+ that would be described by the grammar if only semicolons were added to the sequence in certain places (such as before line
+ terminator characters). Furthermore, certain token sequences that are described by the grammar are not considered acceptable
+ if a terminator character appears in certain “awkward” places.</p>
+
+ <p>In certain cases in order to avoid ambiguities the syntactic grammar uses generalized productions that permit token
+ sequences that are not valid ECMAScript scripts. For example, this technique is used for object literals and object
+ destructuring patterns. In such cases a more restrictive <i>supplemental grammar</i> is provided that further restricts the
+ acceptable token sequences. In certain contexts, when explicitly specific, the input elements corresponding to such a
+ production are parsed again using a goal symbol of a supplemental grammar. The script is syntactically in error if the
+ tokens in the stream of input elements cannot be parsed as a single instance of the supplemental goal symbol, with no tokens
+ left over.</p>
+ </section>
+
+ <section id="sec-grammar-notation">
+ <h1><span class="secnum" id="sec-5.1.5"><a href="#sec-grammar-notation" title="link to this section">5.1.5</a></span>
+ Grammar Notation</h1>
+
+ <p>Terminal symbols of the lexical, RegExp, and numeric string grammars, and some of the terminal symbols of the other
+ grammars, are shown in <code>fixed width</code> font, both in the productions of the grammars and throughout this
+ specification whenever the text directly refers to such a terminal symbol. These are to appear in a script exactly as
+ written. All terminal symbol characters specified in this way are to be understood as the appropriate Unicode code points
+ from the Basic Latin range, as opposed to any similar-looking characters from other Unicode ranges.</p>
+
+ <p>Nonterminal symbols are shown in <var>italic</var> type. The definition of a nonterminal (also called a
+ “production”) is introduced by the name of the nonterminal being defined followed by one or more colons. (The
+ number of colons indicates to which grammar the production belongs.) One or more alternative right-hand sides for the
+ nonterminal then follow on succeeding lines. For example, the syntactic definition:</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">WhileStatement</span> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">while</code> <code class="t">(</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ </div>
+
+ <p>states that the nonterminal <span class="nt">WhileStatement</span> represents the token <code>while</code>, followed by a
+ left parenthesis token, followed by an <span class="nt">Expression</span>, followed by a right parenthesis token, followed
+ by a <span class="nt">Statement</span>. The occurrences of <span class="nt">Expression</span> and <span
+ class="nt">Statement</span> are themselves nonterminals. As another example, the syntactic definition:</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ArgumentList</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">AssignmentExpression</span></div>
+ <div class="rhs"><span class="nt">ArgumentList</span> <code class="t">,</code> <span class="nt">AssignmentExpression</span></div>
+ </div>
+
+ <p>states that an <span class="nt">ArgumentList</span> may represent either a single <span
+ class="nt">AssignmentExpression</span> or an <span class="nt">ArgumentList</span>, followed by a comma, followed by an <span
+ class="nt">AssignmentExpression</span>. This definition of <span class="nt">ArgumentList</span> is recursive, that is, it is
+ defined in terms of itself. The result is that an <span class="nt">ArgumentList</span> may contain any positive number of
+ arguments, separated by commas, where each argument expression is an <span class="nt">AssignmentExpression</span>. Such
+ recursive definitions of nonterminals are common.</p>
+
+ <p>The subscripted suffix “<sub>opt</sub>”, which may appear after a terminal or nonterminal, indicates an
+ optional symbol. The alternative containing the optional symbol actually specifies two right-hand sides, one that omits the
+ optional element and one that includes it. This means that:</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">VariableDeclaration</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">BindingIdentifier</span> <span class="nt">Initializer</span><sub>opt</sub></div>
+ </div>
+
+ <p>is a convenient abbreviation for:</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">VariableDeclaration</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">BindingIdentifier</span></div>
+ <div class="rhs"><span class="nt">BindingIdentifier</span> <span class="nt">Initializer</span></div>
+ </div>
+
+ <p>and that:</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">IterationStatement</span> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">for</code> <code class="t">(</code> <span class="nt">LexicalDeclaration</span> <span class="nt">Expression</span><sub>opt</sub> <code class="t">;</code> <span class="nt">Expression</span><sub>opt</sub> <code class="t">)</code> <span class="nt">Statement</span></div>
+ </div>
+
+ <p>is a convenient abbreviation for:</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">IterationStatement</span> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">for</code> <code class="t">(</code> <span class="nt">LexicalDeclaration</span> <span class="nt">Expression</span><sub>opt</sub> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <div class="rhs"><code class="t">for</code> <code class="t">(</code> <span class="nt">LexicalDeclaration</span> <span class="nt">Expression</span> <code class="t">;</code> <span class="nt">Expression</span><sub>opt</sub> <code class="t">)</code> <span class="nt">Statement</span></div>
+ </div>
+
+ <p>which in turn is an abbreviation for:</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">IterationStatement</span> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">for</code> <code class="t">(</code> <span class="nt">LexicalDeclaration</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <div class="rhs"><code class="t">for</code> <code class="t">(</code> <span class="nt">LexicalDeclaration</span> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <div class="rhs"><code class="t">for</code> <code class="t">(</code> <span class="nt">LexicalDeclaration</span> <span class="nt">Expression</span> <code class="t">;</code> <code class="t">;)</code> <span class="nt">Statement</span></div>
+ <div class="rhs"><code class="t">for</code> <code class="t">(</code> <span class="nt">LexicalDeclaration</span> <span class="nt">Expression</span> <code class="t">;</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ </div>
+
+ <p>so, in this example, the nonterminal <span class="nt">IterationStatement</span> actually has four alternative right-hand
+ sides.</p>
+
+ <p>A production may be parameterized by a subscripted annotation of the form “<sub>[parameters]</sub>”, which
+ may appear as a suffix to the nonterminal symbol defined by the production. “<sub>parameters</sub>” may be
+ either a single name or a comma separated list of names. A parameterized production is shorthand for a set of productions
+ defining all combinations of the parameter names, preceeded by an underscore, appended to the parameterized nonterminal
+ symbol. This means that:</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">StatementList</span><sub>[Return]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">ReturnStatement</span></div>
+ <div class="rhs"><span class="nt">ExpressionStatement</span></div>
+ </div>
+
+ <p>is a convenient abbreviation for:</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">StatementList</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">ReturnStatement</span></div>
+ <div class="rhs"><span class="nt">ExpressionStatement</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">StatementList_Return</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">ReturnStatement</span></div>
+ <div class="rhs"><span class="nt">ExpressionStatement</span></div>
+ </div>
+
+ <p>and that:</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">StatementList</span><sub>[Return, In]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">ReturnStatement</span></div>
+ <div class="rhs"><span class="nt">ExpressionStatement</span></div>
+ </div>
+
+ <p>is an abbreviation for:</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">StatementList</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">ReturnStatement</span></div>
+ <div class="rhs"><span class="nt">ExpressionStatement</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">StatementList_Return</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">ReturnStatement</span></div>
+ <div class="rhs"><span class="nt">ExpressionStatement</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">StatementList_In</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">ReturnStatement</span></div>
+ <div class="rhs"><span class="nt">ExpressionStatement</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">StatementList_Return_In</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">ReturnStatement</span></div>
+ <div class="rhs"><span class="nt">ExpressionStatement</span></div>
+ </div>
+
+ <p>Multiple parameters produce a combinatory number of productions, not all of which are necessarily referenced in a
+ complete grammar.</p>
+
+ <p>References to nonterminals on the right hand side of a production can also be parameterized. For example:</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">StatementList</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">ReturnStatement</span></div>
+ <div class="rhs"><span class="nt">ExpressionStatement</span><sub>[In]</sub></div>
+ </div>
+
+ <p>is equivalent to saying:</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">StatementList</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">ReturnStatement</span></div>
+ <div class="rhs"><span class="nt">ExpressionStatement_In</span></div>
+ </div>
+
+ <p>A nonterminal reference may have both a parameter list and an “<sub>opt</sub>” suffix. For example:</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">VariableDeclaration</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">BindingIdentifier</span> <span class="nt">Initializer</span><sub>[In]</sub><sub>opt</sub></div>
+ </div>
+
+ <p>is an abbreviation for:</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">VariableDeclaration</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">BindingIdentifier</span></div>
+ <div class="rhs"><span class="nt">BindingIdentifier</span> <span class="nt">Initializer_In</span></div>
+ </div>
+
+ <p>Prefixing a parameter name with “<sub>?</sub>” on a right hand side nonterminal reference makes that
+ parameter value dependent upon the occurrence of the parameter name on the reference to the current production’s left
+ hand side symbol. For example:</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">VariableDeclaration</span><sub>[In]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">BindingIdentifier</span> <span class="nt">Initializer</span><sub>[?In]</sub></div>
+ </div>
+
+ <p>is an abbreviation for:</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">VariableDeclaration</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">BindingIdentifier</span> <span class="nt">Initializer</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">VariableDeclaration_In</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">BindingIdentifier</span> <span class="nt">Initializer_In</span></div>
+ </div>
+
+ <p>If a right hand side alternative is prefixed with “[+parameter]” that alternative is only available if the
+ named parameter was used in referencing the production’s nonterminal symbol. If a right hand side alternative is
+ prefixed with “[~parameter]” that alternative is only available if the named parameter was <i>not</i> used in
+ referencing the production’s nonterminal symbol. This means that:</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">StatementList</span><sub>[Return]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="grhsannot">[+Return]</span> <span class="nt">ReturnStatement</span></div>
+ <div class="rhs"><span class="nt">ExpressionStatement</span></div>
+ </div>
+
+ <p>is an abbreviation for:</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">StatementList</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">ExpressionStatement</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">StatementList_Return</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">ReturnStatement</span></div>
+ <div class="rhs"><span class="nt">ExpressionStatement</span></div>
+ </div>
+
+ <p>and that</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">StatementList</span><sub>[Return]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="grhsannot">[~Return]</span> <span class="nt">ReturnStatement</span></div>
+ <div class="rhs"><span class="nt">ExpressionStatement</span></div>
+ </div>
+
+ <p>is an abbreviation for:</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">StatementList</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">ReturnStatement</span></div>
+ <div class="rhs"><span class="nt">ExpressionStatement</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">StatementList_Return</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">ExpressionStatement</span></div>
+ </div>
+
+ <p>When the words “<b>one of</b>” follow the colon(s) in a grammar definition, they signify that each of the
+ terminal symbols on the following line or lines is an alternative definition. For example, the lexical grammar for
+ ECMAScript contains the production:</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">NonZeroDigit</span> <span class="geq">::</span> <span class="grhsmod">one of</span></div>
+ <div class="rhs"><code class="t">1</code> <code class="t">2</code> <code class="t">3</code> <code class="t">4</code> <code class="t">5</code> <code class="t">6</code> <code class="t">7</code> <code class="t">8</code> <code class="t">9</code></div>
+ </div>
+
+ <p>which is merely a convenient abbreviation for:</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">NonZeroDigit</span> <span class="geq">::</span></div>
+ <div class="rhs"><code class="t">1</code></div>
+ <div class="rhs"><code class="t">2</code></div>
+ <div class="rhs"><code class="t">3</code></div>
+ <div class="rhs"><code class="t">4</code></div>
+ <div class="rhs"><code class="t">5</code></div>
+ <div class="rhs"><code class="t">6</code></div>
+ <div class="rhs"><code class="t">7</code></div>
+ <div class="rhs"><code class="t">8</code></div>
+ <div class="rhs"><code class="t">9</code></div>
+ </div>
+
+ <p>If the phrase “[empty]” appears as the right-hand side of a production, it indicates that the production's
+ right-hand side contains no terminals or nonterminals.</p>
+
+ <p>If the phrase “[lookahead ∉ <var>set</var>]” appears in the right-hand side of a production, it
+ indicates that the production may not be used if the immediately following input token is a member of the given
+ <var>set</var>. The <var>set</var> can be written as a list of terminals enclosed in curly braces. For convenience, the set
+ can also be written as a nonterminal, in which case it represents the set of all terminals to which that nonterminal could
+ expand. If the <var>set</var> consists of a single terminal the pharse “[lookahead ≠ <var>terminal</var>]” by
+ be used.</p>
+
+ <p>For example, given the definitions</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">DecimalDigit</span> <span class="geq">::</span> <span class="grhsmod">one of</span></div>
+ <div class="rhs"><code class="t">0</code> <code class="t">1</code> <code class="t">2</code> <code class="t">3</code> <code class="t">4</code> <code class="t">5</code> <code class="t">6</code> <code class="t">7</code> <code class="t">8</code> <code class="t">9</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">DecimalDigits</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">DecimalDigit</span></div>
+ <div class="rhs"><span class="nt">DecimalDigits</span> <span class="nt">DecimalDigit</span></div>
+ </div>
+
+ <p>the definition</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">LookaheadExample</span> <span class="geq">::</span></div>
+ <div class="rhs"><code class="t">n</code> <span class="grhsannot">[lookahead ∉ {<code class="t">1</code>, <code class="t">3</code>, <code class="t">5</code>, <code class="t">7</code>, <code class="t">9</code>}]</span> <span class="nt">DecimalDigits</span></div>
+ <div class="rhs"><span class="nt">DecimalDigit</span> <span class="grhsannot">[lookahead ∉ <span class="nt">DecimalDigit</span>]</span></div>
+ </div>
+
+ <p>matches either the letter <code>n</code> followed by one or more decimal digits the first of which is even, or a decimal
+ digit not followed by another decimal digit.</p>
+
+ <p>If the phrase “[no <span class="nt">LineTerminator</span> here]” appears in the right-hand side of a
+ production of the syntactic grammar, it indicates that the production is <i>a restricted production</i>: it may not be used
+ if a <span class="nt">LineTerminator</span> occurs in the input stream at the indicated position. For example, the
+ production:</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ThrowStatement</span> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">throw</code> <span class="grhsannot">[no <span class="nt">LineTerminator</span> here]</span> <span class="nt">Expression</span> <code class="t">;</code></div>
+ </div>
+
+ <p>indicates that the production may not be used if a <span class="nt">LineTerminator</span> occurs in the script between
+ the <code>throw</code> token and the <span class="nt">Expression</span>.</p>
+
+ <p>Unless the presence of a <span class="nt">LineTerminator</span> is forbidden by a restricted production, any number of
+ occurrences of <span class="nt">LineTerminator</span> may appear between any two consecutive tokens in the stream of input
+ elements without affecting the syntactic acceptability of the script.</p>
+
+ <p>The lexical grammar has multiple goal symbols and the appropriate goal symbol to use depends upon the syntactic grammar
+ context. If a phrase of the form “[Lexical goal <span class="nt">LexicalGoalSymbol</span>]” appears on the
+ right-hand-side of a syntactic production then the next token must be lexically recognized using the indicated goal symbol.
+ In the absence of such a phrase the default lexical goal symbol is used.</p>
+
+ <p>When an alternative in a production of the lexical grammar or the numeric string grammar appears to be a multi-character
+ token, it represents the sequence of characters that would make up such a token.</p>
+
+ <p>The right-hand side of a production may specify that certain expansions are not permitted by using the phrase
+ “<b>but not</b>” and then indicating the expansions to be excluded. For example, the production:</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">Identifier</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">IdentifierName</span> <span class="grhsmod">but not</span> <span class="nt">ReservedWord</span></div>
+ </div>
+
+ <p>means that the nonterminal <span class="nt">Identifier</span> may be replaced by any sequence of characters that could
+ replace <span class="nt">IdentifierName</span> provided that the same sequence of characters could not replace <span
+ class="nt">ReservedWord</span>.</p>
+
+ <p>Finally, a few nonterminal symbols are described by a descriptive phrase in sans-serif type in cases where it would be
+ impractical to list all the alternatives:</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">SourceCharacter</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="gprose">any Unicode code point</span></div>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-algorithm-conventions">
+ <h1><span class="secnum" id="sec-5.2"><a href="#sec-algorithm-conventions" title="link to this section">5.2</a></span>
+ Algorithm Conventions</h1>
+
+ <p>The specification often uses a numbered list to specify steps in an algorithm. These algorithms are used to precisely
+ specify the required semantics of ECMAScript language constructs. The algorithms are not intended to imply the use of any
+ specific implementation technique. In practice, there may be more efficient algorithms available to implement a given
+ feature.</p>
+
+ <p>Algorithms may be explicitly parameterized, in which case the names and usage of the parameters must be provided as part of
+ the algorithm’s definition. In order to facilitate their use in multiple parts of this specification, some algorithms,
+ called <i>abstract</i> <i>operations</i>, are named and written in parameterized functional form so that they may be
+ referenced by name from within other algorithms.</p>
+
+ <p>Algorithms may be associated with productions of one of the ECMAScript grammars. A production that has multiple
+ alternative definitions will typically have a distinct algorithm for each alternative. When an algorithm is associated with a
+ grammar production, it may reference the terminal and nonterminal symbols of the production alternative as if they were
+ parameters of the algorithm. When used in this manner, nonterminal symbols refer to the actual alternative definition that is
+ matched when parsing the script souce code.</p>
+
+ <p>When an algorithm is associated with a production alternative, the alternative is typically shown without any “[
+ ]” grammar annotations. Such annotations should only affect the syntactic recognition of the alternative and have no
+ effect on the associated semantics for the alternative.</p>
+
+ <p>Unless explicitly specified otherwise, all <a href="#sec-context-free-grammars">chain productions</a> have an implicit
+ associated definition for every algorithm that might be applied to that production’s left-hand side nonterminal. The
+ implicit definition simply reapplies the same algorithm name with the same parameters, if any, to the <a
+ href="#sec-context-free-grammars">chain production</a>’s sole right-hand side nonterminal and then result. For example,
+ assume there is a production:</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">Block</span> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">{</code> <span class="nt">StatementList</span> <code class="t">}</code></div>
+ </div>
+
+ <p>but there is no corresponding Evaluation algorithm that is explicitly specified for that production. If in some algorithm
+ there is a statement of the form: “<span style="font-family: Times New Roman">Return the result of evaluating
+ <i>Block</i></span>” it is implicit that an Evaluation algorithm exists of the form:</p>
+
+ <p><b>Runtime Semantics: Evaluation</b></p>
+
+ <div class="gp prod"><span class="nt">Block</span> <span class="geq">:</span> <code class="t">{</code> <span class="nt">StatementList</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return the result of evaluating <i>StatementList</i>.</li>
+ </ol>
+
+ <p>For clarity of expression, algorithm steps may be subdivided into sequential substeps. Substeps are indented and may
+ themselves be further divided into indented substeps. Outline numbering conventions are used to identify substeps with the
+ first level of substeps labelled with lower case alphabetic characters and the second level of substeps labelled with lower
+ case roman numerals. If more than three levels are required these rules repeat with the fourth level using numeric labels. For
+ example:</p>
+
+ <ol class="proc">
+ <li>Top-level step
+ <ol class="block">
+ <li>Substep.</li>
+ <li>Substep.
+ <ol class="block">
+ <li>Subsubstep.
+ <ol class="block">
+ <li>Subsubsubstep
+ <ol class="block">
+ <li>Subsubsubsubstep
+ <ol class="block">
+ <li>Subsubsubsubsubstep</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+
+ <p>A step or substep may be written as an “if” predicate that conditions its substeps. In this case, the substeps
+ are only applied if the predicate is true. If a step or substep begins with the word “else”, it is a predicate
+ that is the negation of the preceding “if” predicate step at the same level.</p>
+
+ <p>A step may specify the iterative application of its substeps.</p>
+
+ <p>A step may assert an invariant condition of its algorithm. Such assertions are used to make explicit algorithmic invariants
+ that would otherwise be implicit. Such assertions add no additional semantic requirements and hence need not be checked by an
+ implementation. They are used simply to clarify algorithms.</p>
+
+ <p>Mathematical operations such as addition, subtraction, negation, multiplication, division, and the mathematical functions
+ defined later in this clause should always be understood as computing exact mathematical results on mathematical real numbers,
+ which do not include infinities and do not include a negative zero that is distinguished from positive zero. Algorithms in
+ this standard that model floating-point arithmetic include explicit steps, where necessary, to handle infinities and signed
+ zero and to perform rounding. If a mathematical operation or function is applied to a floating-point number, it should be
+ understood as being applied to the exact mathematical value represented by that floating-point number; such a floating-point
+ number must be finite, and if it is <span class="value">+0</span> or <span class="value">−0</span> then the
+ corresponding mathematical value is simply <span class="value">0</span>.</p>
+
+ <p>The mathematical function <span style="font-family: Times New Roman">abs(<i>x</i>)</span> produces the absolute value of
+ <var>x</var>, which is <span style="font-family: Times New Roman">−<i>x</i></span> if <var>x</var> is negative (less
+ than zero) and otherwise is <var>x</var> itself.</p>
+
+ <p>The mathematical function <span style="font-family: Times New Roman">sign(<i>x</i>)</span> produces <span
+ style="font-family: Times New Roman">1</span> if <var>x</var> is positive and <span style="font-family: Times New
+ Roman">−1</span> if <var>x</var> is negative. The sign function is not used in this standard for cases when <var>x</var>
+ is zero.</p>
+
+ <p>The mathematical function <span style="font-family: Times New Roman">min(<i>x</i><sub>1</sub>,</span> <span
+ style="font-family: Times New Roman"><i>x</i><sub>2</sub>, ..., <i>x</i><sub>n</sub>)</span> produces the mathematically
+ smallest of <span style="font-family: Times New Roman"><i>x</i><sub>1</sub></span> through <span style="font-family: Times New
+ Roman"><i>x</i><sub>n</sub></span>.</p>
+
+ <p>The notation “<span style="font-family: Times New Roman"><i>x</i> modulo <i>y</i></span>” (<var>y</var> must be
+ finite and nonzero) computes a value <var>k</var> of the same sign as <var>y</var> (or zero) such that <span
+ style="font-family: Times New Roman">abs(<i>k</i>) < abs(<i>y</i>) and <i>x</i>−<i>k</i> = <i>q</i></span> <span
+ style="font-family: Times New Roman">×</span> <var>y</var> for some integer <var>q</var>.</p>
+
+ <p>The mathematical function <span style="font-family: Times New Roman">floor(<i>x</i>)</span> produces the largest integer
+ (closest to positive infinity) that is not larger than <var>x</var>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> floor(<i>x</i>) = <i>x</i>−(<i>x</i> modulo 1).</p>
+ </div>
+ </section>
+
+ <section id="sec-static-semantic-rules">
+ <h1><span class="secnum" id="sec-5.3"><a href="#sec-static-semantic-rules" title="link to this section">5.3</a></span> Static
+ Semantic Rules</h1>
+
+ <p>Context-free grammars are not sufficiently powerful to express all the rules that define whether a stream of input elements
+ form a valid ECMAScript script that may be evaluated. In some situations additional rules are needed that may be expressed
+ using either ECMAScript algorithm conventions or prose requirements. Such rules are always associated with a production of a
+ grammar and are called the <i>static semantics</i> of the production.</p>
+
+ <p>Static Semantic Rules have names and typically are defined using an algorithm. Named Static Semantic Rules are associated
+ with grammar productions and a production that has multiple alternative definitions will typically have for each alternative a
+ distinct algorithm for each applicable named static semantic rule.</p>
+
+ <p>Unless otherwise specified every grammar production alternative in this specification implicitly has a definition for a
+ static semantic rule named <span style="font-family: Times New Roman">Contains</span> which takes an argument named
+ <var>symbol</var> whose value is a terminal or nonterminal of the grammar that includes the associated production. The default
+ definition of <span style="font-family: Times New Roman">Contains</span> is:</p>
+
+ <ol class="proc">
+ <li>For each terminal and nonterminal grammar symbol, <i>sym</i>, in the definition of this production do
+ <ol class="block">
+ <li>If <i>sym</i> is the same grammar symbol as <i>symbol</i>, return <b>true</b>.</li>
+ <li>If <i>sym</i> is a nonterminal, then
+ <ol class="block">
+ <li>Let <i>contained</i> be the result of <i>sym</i> Contains <i>symbol</i>.</li>
+ <li>If <i>contained</i> is <b>true</b>, return <b>true</b>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+
+ <p>The above definition is explicitly over-ridden for specific productions.</p>
+
+ <p>A special kind of static semantic rule is an Early Error Rule. Early error rules define early error conditions (see <a
+ href="#sec-error-handling-and-language-extensions">clause 16</a>) that are associated with specific grammar productions.
+ Evaluation of most early error rules are not explicitly invoked within the algorithms of this specification. A conforming
+ implementation must, prior to the first evaluation of a <span class="nt">Script</span>, validate all of the early error rules
+ of the productions used to parse that <span class="nt">Script</span>. If any of the early error rules are violated the <span
+ class="nt">Script</span> is invalid and cannot be evaluated.</p>
+ </section>
+</section>
+
+<section id="sec-ecmascript-data-types-and-values">
+ <div class="front">
+ <h1><span class="secnum" id="sec-6"><a href="#sec-ecmascript-data-types-and-values" title="link to this section">6</a></span>
+ ECMAScript Data Types and Values</h1>
+
+ <p>Algorithms within this specification manipulate values each of which has an associated type. The possible value types are
+ exactly those defined in this clause. Types are further subclassified into ECMAScript language types and specification
+ types.</p>
+
+ <p>Within this specification, the notation “<span style="font-family: Times New Roman">Type(<i>x</i>)</span>” is
+ used as shorthand for “<span style="font-family: Times New Roman">the type of <i>x</i></span>” where “<span
+ style="font-family: Times New Roman">type</span>” refers to the ECMAScript language and specification types defined in
+ this clause.</p>
+ </div>
+
+ <section id="sec-ecmascript-language-types">
+ <div class="front">
+ <h1><span class="secnum" id="sec-6.1"><a href="#sec-ecmascript-language-types" title="link to this section">6.1</a></span>
+ ECMAScript Language Types</h1>
+
+ <p>An ECMAScript language type corresponds to values that are directly manipulated by an ECMAScript programmer using the
+ ECMAScript language. The ECMAScript language types are Undefined, Null, Boolean, String, Symbol, Number, and Object. An
+ ECMAScript language value is a value that is characterized by an ECMAScript language type.</p>
+ </div>
+
+ <section id="sec-ecmascript-language-types-undefined-type">
+ <h1><span class="secnum" id="sec-6.1.1"><a href="#sec-ecmascript-language-types-undefined-type"
+ title="link to this section">6.1.1</a></span> The Undefined Type</h1>
+
+ <p>The Undefined type has exactly one value, called <b>undefined</b>. Any variable that has not been assigned a value has
+ the value <b>undefined</b>.</p>
+ </section>
+
+ <section id="sec-ecmascript-language-types-null-type">
+ <h1><span class="secnum" id="sec-6.1.2"><a href="#sec-ecmascript-language-types-null-type"
+ title="link to this section">6.1.2</a></span> The Null Type</h1>
+
+ <p>The Null type has exactly one value, called <b>null</b>.</p>
+ </section>
+
+ <section id="sec-ecmascript-language-types-boolean-type">
+ <h1><span class="secnum" id="sec-6.1.3"><a href="#sec-ecmascript-language-types-boolean-type"
+ title="link to this section">6.1.3</a></span> The Boolean Type</h1>
+
+ <p>The Boolean type represents a logical entity having two values, called <b>true</b> and <b>false</b>.</p>
+ </section>
+
+ <section id="sec-ecmascript-language-types-string-type">
+ <h1><span class="secnum" id="sec-6.1.4"><a href="#sec-ecmascript-language-types-string-type"
+ title="link to this section">6.1.4</a></span> The String Type</h1>
+
+ <p>The String type is the set of all finite ordered sequences of zero or more 16-bit unsigned integer values
+ (“elements”). The String type is generally used to represent textual data in a running ECMAScript program, in
+ which case each element in the String is treated as a UTF-16 code unit value. Each element is regarded as occupying a
+ position within the sequence. These positions are indexed with nonnegative integers. The first element (if any) is at index
+ 0, the next element (if any) at index 1, and so on. The length of a String is the number of elements (i.e., 16-bit values)
+ within it. The empty String has length zero and therefore contains no elements.</p>
+
+ <p>Where ECMAScript operations interpret String values, each element is interpreted as a single UTF-16 code unit. However,
+ ECMAScript does not place any restrictions or requirements on the sequence of code units in a String value, so they may be
+ ill-formed when interpreted as UTF-16 code unit sequences. Operations that do not interpret String contents treat them as
+ sequences of undifferentiated 16-bit unsigned integers. No operations ensure that Strings are in a normalized form. Only
+ operations that are explicitly specified to be language or locale sensitive produce language-sensitive results</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The rationale behind this design was to keep the implementation of Strings as simple and
+ high-performing as possible. If ECMAScript source code is in Normalized Form C, string literals are guaranteed to also be
+ normalized, as long as they do not contain any Unicode escape sequences.</p>
+ </div>
+
+ <p>Some operations interpret String contents as UTF-16 encoded Unicode code points. In that case the interpretation is:</p>
+
+ <ul>
+ <li>
+ <p>A code unit in the range <span style="font-family: Times New Roman">0</span> to <span style="font-family: Times New
+ Roman">0xD7FF</span> or in the range <span style="font-family: Times New Roman">0xE000</span> to <span
+ style="font-family: Times New Roman">0xFFFF</span> is interpreted as a code point with the same value.</p>
+ </li>
+
+ <li>
+ <p>A sequence of two code units, where the first code unit <var>c1</var> is in the range <span style="font-family: Times
+ New Roman">0xD800</span> to <span style="font-family: Times New Roman">0xDBFF</span> and the second code unit
+ <var>c2</var> is in the range <span style="font-family: Times New Roman">0xDC00</span> to <span style="font-family:
+ Times New Roman">0xDFFF</span>, is a surrogate pair and is interpreted as a code point with the value (<var>c1</var> -
+ <span style="font-family: Times New Roman">0xD800</span>) × <span style="font-family: Times New
+ Roman">0x400</span> + (<var>c2</var> – <span style="font-family: Times New Roman">0xDC00</span>) + <span
+ style="font-family: Times New Roman">0x10000</span>.</p>
+ </li>
+
+ <li>
+ <p>A code unit that is in the range <span style="font-family: Times New Roman">0xD800</span> to <span
+ style="font-family: Times New Roman">0xDFFF</span>, but is not part of a surrogate pair, is interpreted as a code point
+ with the same value.</p>
+ </li>
+ </ul>
+ </section>
+
+ <section id="sec-ecmascript-language-types-symbol-type">
+ <div class="front">
+ <h1><span class="secnum" id="sec-6.1.5"><a href="#sec-ecmascript-language-types-symbol-type"
+ title="link to this section">6.1.5</a></span> The Symbol Type</h1>
+
+ <p>The Symbol type is the set of all non-String values that may be used as the key of an Object property (<a
+ href="#sec-object-type">6.1.7</a>).</p>
+
+ <p>Each possible Symbol values is unique and immutable.</p>
+
+ <p>Each Symbol value immutably holds an associated value called [[Description]] that is either <span
+ class="value">undefined</span> or a String value.</p>
+ </div>
+
+ <section id="sec-well-known-symbols">
+ <h1><span class="secnum" id="sec-6.1.5.1"><a href="#sec-well-known-symbols"
+ title="link to this section">6.1.5.1</a></span> Well-Known Symbols</h1>
+
+ <p>Well-known symbols are built-in Symbol values that are explicitly referenced by algorithms of this specification. They
+ are typically used as the keys of properties whose values serve as extension points of a specification algorithm. Unless
+ otherwise specified, well-known symbols values are shared by all Code Realms (<a
+ href="#sec-newglobalenvironment">8.1.2.5</a>).</p>
+
+ <p>Within this specification a well-known symbol is referred to by using a notation of the form @@name, where
+ “name” is one of the values listed in <a href="#table-1">Table 1</a>.</p>
+
+ <figure>
+ <figcaption><span id="table-1">Table 1</span>— Well-known Symbols</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 0px solid black; border-top: 2px solid #000000">Specification Name</th>
+ <th style="border-bottom: 1px solid #000000; border-right: 0px solid black; border-top: 2px solid #000000">[[Description]]</th>
+ <th style="border-bottom: 1px solid #000000; border-left: 0px solid black; border-right: 1px solid #000000; border-top: 2px solid #000000">Value and Purpose</th>
+ </tr>
+ <tr>
+ <td>@@create</td>
+ <td><code>"Symbol.create"</code></td>
+ <td>A method used to allocate an object. Called from the [[Construct]] internal method.</td>
+ </tr>
+ <tr>
+ <td>@@hasInstance</td>
+ <td><code>"Symbol.hasInstance"</code></td>
+ <td>A method that determines if a constructor object recognizes an object as one of the constructor’s instances. Called by the semantics of the <code>instanceof</code> operator.</td>
+ </tr>
+ <tr>
+ <td>@@isConcatSpreadable</td>
+ <td><code>"Symbol.isConcatSpreadable"</code></td>
+ <td>A Boolean value that if true indicates that an object should be flatten to its array elements by <a href="#sec-array.prototype.concat">Array.prototype.concat</a>.</td>
+ </tr>
+ <tr>
+ <td>@@isRegExp</td>
+ <td><code>"Symbol.isRegExp"</code></td>
+ <td>A Boolean value that if true indicates that an object may be used as a regular expression.</td>
+ </tr>
+ <tr>
+ <td>@@iterator</td>
+ <td><code>"Symbol.iterator"</code></td>
+ <td>A method that returns the default iterator for an object. Called by the semantics of the for-of statement.</td>
+ </tr>
+ <tr>
+ <td>@@toPrimitive</td>
+ <td><code>"Symbol.toPrimitive"</code></td>
+ <td>A method that converts an object to a corresponding primitive value. Called by the <a href="#sec-toprimitive">ToPrimitive</a> abstract operation.</td>
+ </tr>
+ <tr>
+ <td>@@toStringTag</td>
+ <td><code>"Symbol.toStringTag"</code></td>
+ <td>A string value that is used in the creation of the default string description of an object. Called by the built-in method <a href="#sec-object.prototype.tostring">Object.prototype.toString</a>.</td>
+ </tr>
+ <tr>
+ <td>@@unscopables</td>
+ <td><code>"Symbol.unscopables"</code></td>
+ <td>An Array of string values that are property names that are excluded from the with environment bindings of the associated objects.</td>
+ </tr>
+ </table>
+ </figure>
+ </section>
+ </section>
+
+ <section id="sec-ecmascript-language-types-number-type">
+ <h1><span class="secnum" id="sec-6.1.6"><a href="#sec-ecmascript-language-types-number-type"
+ title="link to this section">6.1.6</a></span> The Number Type</h1>
+
+ <p>The Number type has exactly <span style="font-family: Times New Roman">18437736874454810627</span> (that is, <span
+ style="font-family: Times New Roman">2<sup>64</sup>−2<sup>53</sup>+3</span>) values, representing the double-precision
+ 64-bit format IEEE 754 values as specified in the IEEE Standard for Binary Floating-Point Arithmetic, except that the <span
+ style="font-family: Times New Roman">9007199254740990</span> (that is, <span style="font-family: Times New
+ Roman">2<sup>53</sup>−2</span>) distinct “Not-a-Number” values of the IEEE Standard are represented in
+ ECMAScript as a single special <b>NaN</b> value. (Note that the <b>NaN</b> value is produced by the program expression
+ <code>NaN</code>.) In some implementations, external code might be able to detect a difference between various Not-a-Number
+ values, but such behaviour is implementation-dependent; to ECMAScript code, all NaN values are indistinguishable from each
+ other.</p>
+
+ <p>There are two other special values, called <b>positive Infinity</b> and <b>negative Infinity</b>. For brevity, these
+ values are also referred to for expository purposes by the symbols <span class="value">+∞</span> and <span
+ class="value">−∞</span>, respectively. (Note that these two infinite Number values are produced by the program
+ expressions <code>+Infinity</code> (or simply <code>Infinity</code>) and <code>-Infinity</code>.)</p>
+
+ <p>The other <span style="font-family: Times New Roman">18437736874454810624</span> (that is, <span style="font-family:
+ Times New Roman">2<sup>64</sup>−2<sup>53</sup></span>) values are called the finite numbers. Half of these are
+ positive numbers and half are negative numbers; for every finite positive Number value there is a corresponding negative
+ value having the same magnitude.</p>
+
+ <p>Note that there is both a <b>positive zero</b> and a <b>negative zero</b>. For brevity, these values are also referred to
+ for expository purposes by the symbols <span class="value">+0</span> and <span class="value">−0</span>, respectively.
+ (Note that these two different zero Number values are produced by the program expressions <code>+0</code> (or simply
+ <code>0</code>) and <code>-0</code>.)</p>
+
+ <p>The <span style="font-family: Times New Roman">18437736874454810622</span> (that is, <span style="font-family: Times New
+ Roman">2<sup>64</sup>−2<sup>53</sup>−2</span>) finite nonzero values are of two kinds:</p>
+
+ <p><span style="font-family: Times New Roman">18428729675200069632</span> (that is, <span style="font-family: Times New
+ Roman">2<sup>64</sup>−2<sup>54</sup></span>) of them are normalized, having the form</p>
+
+ <div class="math-display"><i>s</i> × <i>m</i> × 2<sup><i>e</i></sup></div>
+
+ <p>where <var>s</var> is <span style="font-family: Times New Roman">+1</span> or <span style="font-family: Times New
+ Roman">−1</span>, <var>m</var> is a positive integer less than <span style="font-family: Times New
+ Roman">2<sup>53</sup></span> but not less than <span style="font-family: Times New Roman">2<sup>52</sup></span>, and
+ <var>e</var> is an integer ranging from <span style="font-family: Times New Roman">−1074</span> to <span
+ style="font-family: Times New Roman">971</span>, inclusive.</p>
+
+ <p>The remaining <span style="font-family: Times New Roman">9007199254740990</span> (that is, <span style="font-family:
+ Times New Roman">2<sup>53</sup>−2</span>) values are denormalized, having the form</p>
+
+ <div class="math-display"><i>s</i> × <i>m</i> × 2<sup><i>e</i></sup></div>
+
+ <p>where <var>s</var> is <span style="font-family: Times New Roman">+1</span> or <span style="font-family: Times New
+ Roman">−1</span>, <var>m</var> is a positive integer less than <span style="font-family: Times New
+ Roman">2<sup>52</sup></span>, and <var>e</var> is <span style="font-family: Times New Roman">−1074</span>.</p>
+
+ <p>Note that all the positive and negative integers whose magnitude is no greater than <span style="font-family: Times New
+ Roman">2<sup>53</sup></span> are representable in the Number type (indeed, the integer <span style="font-family: Times New
+ Roman">0</span> has two representations, <code>+0</code> and <code>-0</code>).</p>
+
+ <p>A finite number has an <i>odd significand</i> if it is nonzero and the integer <var>m</var> used to express it (in one of
+ the two forms shown above) is odd. Otherwise, it has an <i>even significand</i>.</p>
+
+ <p>In this specification, the phrase “<span style="font-family: Times New Roman">the Number value for
+ <i>x</i></span>” where <var>x</var> represents an exact nonzero real mathematical quantity (which might even be an
+ irrational number such as <span style="font-family: Times New Roman">π</span>) means a Number value chosen in the
+ following manner. Consider the set of all finite values of the Number type, with <span class="value">−0</span> removed
+ and with two additional values added to it that are not representable in the Number type, namely <span style="font-family:
+ Times New Roman">2<sup>1024</sup></span> (which is <span style="font-family: Times New Roman">+1 ×
+ 2<sup>53</sup></span> <span style="font-family: Times New Roman">× 2<sup>971</sup></span>) and <span
+ style="font-family: Times New Roman">−2<sup>1024</sup></span> (which is <span style="font-family: Times New
+ Roman">−1 × 2<sup>53</sup></span> <span style="font-family: Times New Roman">× 2<sup>971</sup></span>).
+ Choose the member of this set that is closest in value to <var>x</var>. If two values of the set are equally close, then the
+ one with an even significand is chosen; for this purpose, the two extra values <span style="font-family: Times New
+ Roman">2<sup>1024</sup></span> and <span style="font-family: Times New Roman">−2<sup>1024</sup></span> are considered
+ to have even significands. Finally, if <span style="font-family: Times New Roman">2<sup>1024</sup></span> was chosen,
+ replace it with <span class="value">+∞</span>; if <span style="font-family: Times New
+ Roman">−2<sup>1024</sup></span> was chosen, replace it with <span class="value">−∞</span>; if <span
+ class="value">+0</span> was chosen, replace it with <span class="value">−0</span> if and only if <var>x</var> is less
+ than zero; any other chosen value is used unchanged. The result is the Number value for <var>x</var>. (This procedure
+ corresponds exactly to the behaviour of the IEEE 754 “round to nearest” mode.)</p>
+
+ <p>Some ECMAScript operators deal only with integers in the range <span style="font-family: Times New
+ Roman">−2<sup>31</sup></span> through <span style="font-family: Times New Roman">2<sup>31</sup>−1</span>,
+ inclusive, or in the range <span style="font-family: Times New Roman">0</span> through <span style="font-family: Times New
+ Roman">2<sup>32</sup>−1</span>, inclusive. These operators accept any value of the Number type but first convert each
+ such value to one of <span style="font-family: Times New Roman">2<sup>32</sup></span> integer values. See the descriptions
+ of the <a href="#sec-toint32">ToInt32</a> and <a href="#sec-touint32">ToUint32</a> operators in <a
+ href="#sec-toint32">7.1.5</a> and <a href="#sec-touint32">7.1.6</a>, respectively.</p>
+ </section>
+
+ <section id="sec-object-type">
+ <div class="front">
+ <h1><span class="secnum" id="sec-6.1.7"><a href="#sec-object-type" title="link to this section">6.1.7</a></span> The
+ Object Type</h1>
+
+ <p>An Object is logically a collection of properties. Each property is either a data property, or an accessor
+ property:</p>
+
+ <ul>
+ <li>
+ <p>A <i>data property</i> associates a key value with an <a href="#sec-ecmascript-language-types">ECMAScript language
+ value</a> and a set of Boolean attributes.</p>
+ </li>
+
+ <li>
+ <p>An <i>accessor property</i> associates a key value with one or two accessor functions, and a set of Boolean
+ attributes. The accessor functions are used to store or retrieve an <a
+ href="#sec-ecmascript-language-types">ECMAScript language value</a> that is associated with the property.</p>
+ </li>
+ </ul>
+
+ <p>Properties are identified using key values. A key value is either an ECMAScript String value or a Symbol value. All
+ String and Symbol values, including the empty string, are valid as property keys.</p>
+
+ <p>An <i>integer index</i> is a String-valued property key that is a canonical numeric String (<a
+ href="#sec-canonicalnumericindexstring">see 7.1.16</a>) and whose numeric value is either <span style="font-family: Times
+ New Roman">+0</span> or a positive integer. An <i>array index</i> is an integer index whose numeric value <var>i</var> is
+ in the range <span style="font-family: Times New Roman">0 ≤ <i>i</i></span> <span style="font-family: Times New
+ Roman">< 2<sup>32</sup>−1</span> and <var>i</var> <span style="font-family: Times New Roman">≠</span> <span
+ style="font-family: Times New Roman">−0.</span></p>
+
+ <p>Property keys are used to access properties and their values. There are two kinds of access for properties: <i>get</i>
+ and <i>set</i>, corresponding to value retrieval and assignment, respectively. The properties accessible via get and set
+ access includes both <i>own properties</i> that are a direct part of an object and <i>inherited properties</i> which are
+ provided by another associated object via a property inheritance relationship. Inherited properties may be either own or
+ inherited properties of the associated object. Each own properties of an object must each have a key value that is
+ distinct from the key values of the other own properties of that object.</p>
+
+ <p>All objects are logically collections of properties, but there are multiple forms of objects that differ in their
+ semantics for accessing and manipulating their properties. O<i>rdinary objects</i> are the most common form of objects
+ and have the default object semantics. An <i>exotic object</i> is any form of object whose property semantics differ in
+ any way from the default semantics.</p>
+ </div>
+
+ <section id="sec-property-attributes">
+ <h1><span class="secnum" id="sec-6.1.7.1"><a href="#sec-property-attributes"
+ title="link to this section">6.1.7.1</a></span> Property Attributes</h1>
+
+ <p>Attributes are used in this specification to define and explain the state of Object properties. A data property
+ associates a key value with the attributes listed in <a href="#table-2">Table 2</a>.</p>
+
+ <figure>
+ <figcaption><span id="table-2">Table 2</span> — Attributes of a Data Property</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid #000000; border-top: 1px solid black">Attribute Name</th>
+ <th style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid #000000; border-top: 1px solid black">Value Domain</th>
+ <th style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid #000000; border-top: 1px solid black">Description</th>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black">[[Value]]</td>
+ <td style="border-bottom: 1px solid black; border-right: 1px solid black">Any <a href="#sec-ecmascript-language-types">ECMAScript language type</a></td>
+ <td style="border-bottom: 1px solid black; border-right: 1px solid black">The value retrieved by a get access of the property.</td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black">[[Writable]]</td>
+ <td style="border-bottom: 1px solid black; border-right: 1px solid black">Boolean</td>
+ <td style="border-bottom: 1px solid black; border-right: 1px solid black">If <b>false</b>, attempts by ECMAScript code to change the property’s [[Value]] attribute using [[Set]] will not succeed.</td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black">[[Enumerable]]</td>
+ <td style="border-bottom: 1px solid black; border-right: 1px solid black">Boolean</td>
+ <td style="border-bottom: 1px solid black; border-right: 1px solid black">If <b>true</b>, the property will be enumerated by a for-in enumeration (<a href="#sec-runtime-semantics-createperiterationenvironment">see 13.6.3.5</a>). Otherwise, the property is said to be non-enumerable.</td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black">[[Configurable]]</td>
+ <td style="border-bottom: 1px solid black; border-right: 1px solid black">Boolean</td>
+ <td style="border-bottom: 1px solid black; border-right: 1px solid black">If <b>false</b>, attempts to delete the property, change the property to be an accessor property, or change its attributes (other than [[Value]], or changing [[Writable]] to <b>false</b>) will fail.</td>
+ </tr>
+ </table>
+ </figure>
+
+ <p>An accessor property associates a key value with the attributes listed in <a href="#table-3">Table 3</a>.</p>
+
+ <figure>
+ <figcaption><span id="table-3">Table 3</span> — Attributes of an Accessor Property</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid #000000; border-top: 1px solid black">Attribute Name</th>
+ <th style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid #000000; border-top: 1px solid black">Value Domain</th>
+ <th style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid #000000; border-top: 1px solid black">Description</th>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid #000000">[[Get]]</td>
+ <td style="border-bottom: 1px solid black; border-right: 1px solid black">Object <i>or</i> Undefined</td>
+ <td style="border-bottom: 1px solid black; border-right: 1px solid black">If the value is an Object it must be a function Object. The function’s [[Call]] internal method (<a href="#table-6">Table 6</a>) is called with an empty arguments list to retrieve the property value each time a get access of the property is performed.</td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid #000000; border-top: 1px solid black">[[Set]]</td>
+ <td style="border-bottom: 1px solid black; border-right: 1px solid black">Object <i>or</i> Undefined</td>
+ <td style="border-bottom: 1px solid black; border-right: 1px solid black">If the value is an Object it must be a function Object. The function’s [[Call]] internal method (<a href="#table-6">Table 6</a>) is called with an arguments list containing the assigned value as its sole argument each time a set access of the property is performed. The effect of a property's [[Set]] internal method may, but is not required to, have an effect on the value returned by subsequent calls to the property's [[Get]] internal method.</td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid #000000; border-top: 1px solid black">[[Enumerable]]</td>
+ <td style="border-bottom: 1px solid black; border-right: 1px solid black">Boolean</td>
+ <td style="border-bottom: 1px solid black; border-right: 1px solid black">If <b>true</b>, the property is to be enumerated by a for-in enumeration (<a href="#sec-runtime-semantics-createperiterationenvironment">see 13.6.3.5</a>). Otherwise, the property is said to be non-enumerable.</td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid #000000; border-top: 1px solid black">[[Configurable]]</td>
+ <td style="border-bottom: 1px solid black; border-right: 1px solid black">Boolean</td>
+ <td style="border-bottom: 1px solid black; border-right: 1px solid black">If <b>false</b>, attempts to delete the property, change the property to be a data property, or change its attributes will fail.</td>
+ </tr>
+ </table>
+ </figure>
+
+ <p>If the initial values of a property’s attributes are not explicitly specified by this specification, the default
+ value defined in <a href="#table-4">Table 4</a> is used.</p>
+
+ <figure>
+ <figcaption><span id="table-4">Table 4</span> — Default Attribute Values</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid #000000; border-top: 1px solid black">Attribute Name</th>
+ <th style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid #000000; border-top: 1px solid black">Default Value</th>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid #000000; border-top: 1px solid black">[[Value]]</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid #000000; border-top: 1px solid black"><b>undefined</b></td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid #000000">[[Get]]</td>
+ <td style="border-bottom: 1px solid black; border-right: 1px solid black"><b>undefined</b></td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid #000000; border-top: 1px solid black">[[Set]]</td>
+ <td style="border-bottom: 1px solid black; border-right: 1px solid black"><b>undefined</b></td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid #000000; border-top: 1px solid black">[[Writable]]</td>
+ <td style="border-bottom: 1px solid black; border-right: 1px solid black"><b>false</b></td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid #000000; border-top: 1px solid black">[[Enumerable]]</td>
+ <td style="border-bottom: 1px solid black; border-right: 1px solid black"><b>false</b></td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid #000000; border-top: 1px solid black">[[Configurable]]</td>
+ <td style="border-bottom: 1px solid black; border-right: 1px solid black"><b>false</b></td>
+ </tr>
+ </table>
+ </figure>
+ </section>
+
+ <section id="sec-object-internal-methods-and-internal-slots">
+ <h1><span class="secnum" id="sec-6.1.7.2"><a href="#sec-object-internal-methods-and-internal-slots"
+ title="link to this section">6.1.7.2</a></span> Object Internal Methods and Internal Slots</h1>
+
+ <p>The actual semantics of objects, in ECMAScript, are specified via algorithms called <i>internal methods</i>. Each
+ object in an ECMAScript engine is associated with a set of internal methods that defines its runtime behaviour. These
+ internal methods are not part of the ECMAScript language. They are defined by this specification purely for expository
+ purposes. However, each object within an implementation of ECMAScript must behave as specified by the internal methods
+ associated with it. The exact manner in which this is accomplished is determined by the implementation.</p>
+
+ <p>Internal method names are polymorphic. This means that different object values may perform different algorithms when a
+ common internal method name is invoked upon them. If, at runtime, the implementation of an algorithm attempts to use an
+ internal method of an object that the object does not support, a <b>TypeError</b> exception is thrown.</p>
+
+ <p>Internal slots correspond to internal state that is associated with objects and used by various ECMAScript
+ specification algorithms. Internal slots are not object properties and they are not inherited. Depending upon the specific
+ internal slot specification, such state may consist of values of any <a href="#sec-ecmascript-language-types">ECMAScript
+ language type</a> or of specific ECMA specification type values. Unless explicitly specified otherwise, internal slots are
+ allocated as part of the process of creating an object and may not be dynamically added to an object. Unless specified
+ otherwise, the initial value of an internal slot is the value <span class="value">undefined</span>. Various algorithms
+ within this specification create objects that have internal slots. However, the ECMAScript language provides no direct way
+ to associate internal slots with an object.</p>
+
+ <p>Internal methods and internal slots are identified within this specification using names enclosed in double square
+ brackets [[ ]].</p>
+
+ <p><a href="#table-5">Table 5</a> summarizes the <i>essential internal methods</i> used by this specification that are
+ applicable to all objects created or manipulated by ECMAScript code. Every object must have algorithms for all of the
+ essential internal methods. However, all objects do not necessarily use the same algorithms for those methods.</p>
+
+ <p>The “Signature” column of <a href="#table-5">Table 5</a> and other similar tables describes the invocation
+ pattern for each internal method. The invocation pattern always includes a parenthesized list of descriptive parameter
+ names. If a parameter name is the same as an ECMAScript type name then the name describes the required type of the
+ parameter value. If an internal method explicitly returns a value, its parameter list is followed by the symbol
+ “→” and the type name of the returned value. The type names used in signatures refer to the types defined
+ in <a href="#sec-ecmascript-data-types-and-values">clause 6</a> augmented by the following additional names.
+ “<i>any</i>” means the value may be any <a href="#sec-ecmascript-language-types">ECMAScript language type</a>.
+ An internal method implicitly returns a <a href="#sec-completion-record-specification-type">Completion Record</a> as
+ described in <a href="#sec-completion-record-specification-type">6.2.2</a>. In addition to its parameters, an internal
+ method always has access to the object upon which it is invoked as a method.</p>
+
+ <figure>
+ <figcaption><span id="table-5">Table 5</span> — Essential Internal Methods</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-top: 2px solid #000000">Internal Method</th>
+ <th style="border-bottom: 1px solid #000000; border-top: 2px solid #000000">Signature</th>
+ <th style="border-bottom: 1px solid #000000; border-right: 1px solid #000000; border-top: 2px solid #000000">Description</th>
+ </tr>
+ <tr>
+ <td>[[GetPrototypeOf]]</td>
+ <td>()<b><i>→</i></b>Object or Null</td>
+ <td>Determine the object that provides inherited properties for this object. A <b>null</b> value indicates that there are no inherited properties.</td>
+ </tr>
+ <tr>
+ <td>[[SetPrototypeOf]]</td>
+ <td>(<i>Object</i> or Null)<b><i>→</i></b>Boolean</td>
+ <td>Associate with an object another object that provides inherited properties. Passing <b>null</b> indicates that there are no inherited properties. Returns <b>true</b> indicating that the operation was completed successfully or <b>false</b> indicating that the operation was not successful.</td>
+ </tr>
+ <tr>
+ <td>[[IsExtensible]]</td>
+ <td>( )<b><i>→</i></b>Boolean</td>
+ <td>Determine whether it is permitted to add additional properties to an object.</td>
+ </tr>
+ <tr>
+ <td>[[PreventExtensions]]</td>
+ <td>( )<b><i>→</i></b>Boolean</td>
+ <td>Control whether new properties may be added to an object. Returns <b>true</b> indicating that the operation was completed successfully or <b>false</b> indicating that the operation was not successful.</td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid #808080; border-left: 1px solid #808080; border-right: 1px solid #808080; border-top: 1px solid #808080">[[GetOwnProperty]]</td>
+
+ <td style="border-bottom: 1px solid #808080; border-left: 1px solid #808080; border-right: 1px solid #808080; border-top: 1px solid #808080">
+ <p>(<i>propertyKey</i>) →</p>
+
+ <p>Undefined or <a href="#sec-property-descriptor-specification-type">Property Descriptor</a></p>
+ </td>
+
+ <td style="border-bottom: 1px solid #808080; border-left: 1px solid #808080; border-right: 1px solid #808080; border-top: 1px solid #808080">Returns a <a href="#sec-property-descriptor-specification-type">Property Descriptor</a> for the own property of this object whose key is <i>propertyKey</i>, or <b>undefined</b> if no such property exists.</td>
+ </tr>
+ <tr>
+ <td>[[HasProperty]]</td>
+ <td>(<i>propertyKey</i>) <b><i>→</i></b> Boolean</td>
+ <td>Returns a Boolean value indicating whether the object already has either an own or inherited property whose key is <i>propertyKey</i>.</td>
+ </tr>
+ <tr>
+ <td>[[Get]]</td>
+ <td>(<i>propertyKey</i>, <i>Receiver</i>) <i><b>→</b> any</i></td>
+ <td>Retrieve the value of an object’s property using the <i>propertyKey</i> parameter. If any ECMAScript code must be executed to retrieve the property value, <i>Receiver</i> is used as the <b>this</b> value when evaluating the code.</td>
+ </tr>
+ <tr>
+ <td>[[Set]]</td>
+ <td>(<i>propertyKey</i>,<i>value</i>, <i>Receiver</i>) <i><b>→</b> Boolean</i></td>
+ <td>Try to set the value of an object’s property indentified by <i>propertyKey</i> to <i>value</i>. If any ECMAScript code must be executed to set the property value, <i>Receiver</i> is used as the <b>this</b> value when evaluating the code. Returns <b>true</b> indicating that the property value was set or <b>false</b> indicating that it could not be set.</td>
+ </tr>
+ <tr>
+ <td>[[Delete]]</td>
+ <td>(<i>propertyKey</i>) <b><i>→</i></b> Boolean</td>
+ <td>Removes the own property indentified by the <i>propertyKey</i> parameter from the object. Return <span class="value">false</span> if the property was not deleted and is still present. Return <span class="value">true</span> if the property was deleted or was not present.</td>
+ </tr>
+ <tr>
+ <td>[[DefineOwnProperty]]</td>
+ <td>(<i>propertyKey, PropertyDescriptor</i>) <b><i>→</i></b> Boolean</td>
+ <td>Creates or alters the named own property to have the state described by a <a href="#sec-property-descriptor-specification-type">Property Descriptor</a>. Returns <span class="value">true</span> indicating that the property was successfully created/updated or <b>false</b> indicating that the property could not be created or updated.</td>
+ </tr>
+ <tr>
+ <td>[[Enumerate]]</td>
+ <td>()<b><i>→</i></b>Object</td>
+ <td>Returns an iterator object over the string values of the keys of the enumerable properties of the object.</td>
+ </tr>
+ <tr>
+ <td>[[OwnPropertyKeys]]</td>
+ <td>()<b><i>→</i></b>Array of propertyKey</td>
+ <td>Returns an Array object whose elements are all of the own property keys for the object.</td>
+ </tr>
+ </table>
+ </figure>
+
+ <p><a href="#table-6">Table 6</a> summarizes additional essential internal methods that are supported by objects that may
+ be called as functions.</p>
+
+ <figure>
+ <figcaption><span id="table-6">Table 6</span> — Additional Essential Internal Methods of Function Objects</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-top: 2px solid #000000">Internal Method</th>
+ <th style="border-bottom: 1px solid #000000; border-top: 2px solid #000000">Signature</th>
+ <th style="border-bottom: 1px solid #000000; border-right: 1px solid #000000; border-top: 2px solid #000000">Description</th>
+ </tr>
+ <tr>
+ <td>[[Call]]</td>
+ <td>(<i>any</i>, a <a href="#sec-list-and-record-specification-type">List</a> of <i>any</i>) <span style="font-family: Times New Roman"><b><i>→</i></b></span> <i>any</i></td>
+ <td>Executes code associated with the object. Invoked via a function call expression. The arguments to the internal method are a <b>this</b> value and a list containing the arguments passed to the function by a call expression. Objects that implement this internal method are <i>callable</i>.</td>
+ </tr>
+ <tr>
+ <td>[[Construct]]</td>
+ <td>(a <a href="#sec-list-and-record-specification-type">List</a> of <i>any</i>) <span style="font-family: Times New Roman"><b><i>→</i></b></span> Object</td>
+ <td>Creates an object. Invoked via the <code>new</code> operator. The arguments to the internal method are the arguments passed to the <b>new</b> operator. Objects that implement this internal method are called <i>constructors</i>. A Function object is not necessarily a constructor and such non-constructor Function objects do not have a [[Construct]] internal method.</td>
+ </tr>
+ </table>
+ </figure>
+
+ <p>The semantics of the essential internal method for ordinary objects and standard exotic objects are specified in <a
+ href="#sec-initializefirstrealm">clause 8.5.1</a>. If any specified use of an exotic object's internal methods is not
+ supported by an implementation, that usage must throw a <b>TypeError</b> exception when attempted.</p>
+ </section>
+
+ <section id="sec-invariants-of-the-essential-internal-methods">
+ <h1><span class="secnum" id="sec-6.1.7.3"><a href="#sec-invariants-of-the-essential-internal-methods"
+ title="link to this section">6.1.7.3</a></span> Invariants of the Essential Internal Methods</h1>
+
+ <p>The Internal Methods of Objects of an ECMAScript engine must conform to the list of invariants specified below.
+ Ordinary ECMAScript Objects as well as all standard exotic objects in this specification maintain these invariants.
+ ECMAScript Proxy objects maintain these invariants by means of runtime checks on the result of traps invoked on the
+ [[ProxyHandler]] object.</p>
+
+ <p>Any implementation provided exotic objects must also maintain these invariants for those objects. Violation of these
+ invariants may cause ECMAScript code to have unpredictable behaviour and create security issues. However, violation of
+ these invariants must never compromise the memory safety of an implementation.</p>
+
+ <p>Definitions:</p>
+
+ <p>● The <i>target</i> of an internal method is the object the internal method is called upon.</p>
+
+ <p>● A target is <i>non-extensible</i> if it has been observed to return false from its [[IsExtensible]]
+ internal method, or true from its [[PreventExtensions]] internal method.</p>
+
+ <p>● A <i>non-existent</i> property is a property that does not exist as an own property on a non-extensible
+ target.</p>
+
+ <p>● All references to <i><a href="#sec-samevalue">SameValue</a></i> are according to the definition of <a
+ href="#sec-samevalue">SameValue</a> algorithm specified in <a href="#sec-samevalue">7.2.3</a>.</p>
+
+ <p><b>[[GetPrototypeOf]] ( )</b></p>
+
+ <p>● The Type of the return value must be either Object or Null.</p>
+
+ <p>● If target is non-extensible, and [[GetPrototypeOf]] returns a value v, then any future calls to
+ [[GetPrototypeOf]] should return the <a href="#sec-samevalue">SameValue</a> as v.</p>
+
+ <p>● An object’s prototype chain must have finite length (that is, starting from any object, recursively
+ applying the [[GetPrototypeOf]] internal method to its result must eventually lead to the value null.</p>
+
+ <p><b>[[SetPrototypeOf]] (V)</b></p>
+
+ <p>● The Type of the return value must be Boolean.</p>
+
+ <p>● If target is non-extensible, [[SetPrototypeOf]] must return false, unless V is the <a
+ href="#sec-samevalue">SameValue</a> as the target’s observed [[GetPrototypeOf]] value.</p>
+
+ <p><b>[[PreventExtensions]] ( )</b></p>
+
+ <p>● The Type of the return value must be Boolean.</p>
+
+ <p>● If [[PreventExtensions]] returns true, all future calls to [[IsExtensible]] on the target must return
+ false and the target is now considered non-extensible.</p>
+
+ <p><b>[[GetOwnProperty]] (P)</b></p>
+
+ <p>● The Type of the return value must be either Object or Undefined.</p>
+
+ <p>● If the Type of the return value is Object, that object must be a complete property descriptor (<a
+ href="#sec-completepropertydescriptor">see 6.2.4.6</a>).</p>
+
+ <p>● If a property is described as a data property and it may return different values over time, then either
+ or both of the Desc.[[Writable]] and Desc.[[Configurable]] attributes must be true even if no mechanism to change the
+ value is exposed via the other internal methods.</p>
+
+ <p>● If a property P is described as a data property with Desc.[[Value]] equal to v and Desc.[[Writable]] and
+ Desc.[[Configurable]] are both false, then the <a href="#sec-samevalue">SameValue</a> must be returned for the
+ Desc.[[Value]] attribute of the property on all future calls to [[GetOwnProperty]] ( P ).</p>
+
+ <p>● If P’s attributes other than [[Writable]] may change over time or if the property might disappear,
+ then P’s [[Configurable]] attribute must be true.</p>
+
+ <p>● If the [[Writable]] attribute may change from false to true, then the [[Configurable]] attribute must be
+ true.</p>
+
+ <p>● If the target is non-extensible and P is non-existent, then all future calls to [[GetOwnProperty]] (P)
+ on the target must describe P as non-existent (i.e. [[GetOwnProperty]] (P) must return undefined)</p>
+
+ <p><b>[[DefineOwnProperty]] (P, Desc)</b></p>
+
+ <p>● The Type of the return value must be Boolean.</p>
+
+ <p>● [[DefineOwnProperty]] must return false if P has previously been observed as a non-configurable own
+ property of the target, unless either:</p>
+
+ <p>1.	P is a non-configurable writable own data property. A non-configurable writable data property can be changed
+ into a non-configurable non-writable data property.</p>
+
+ <p>2.	All attributes in Desc are the <a href="#sec-samevalue">SameValue</a> as P’s attributes.</p>
+
+ <p>● [[DefineOwnProperty]] (P, Desc) must return false if target is non-extensible and P is a non-existent own
+ property. That is, a non-extensible target object cannot be extended with new properties.</p>
+
+ <p><b>[[HasProperty]] ( P )</b></p>
+
+ <p>● The Type of the return value must be Boolean.</p>
+
+ <p>● If P was previously observed as a non-configurable data or accessor own property of the target,
+ [[HasProperty]] must return true.</p>
+
+ <p><b>[[Get]] (P, Receiver)</b></p>
+
+ <p>● If P was previously observed as a non-configurable, non-writable own data property of the target with
+ value v, then [[Get]] must return the <a href="#sec-samevalue">SameValue</a>.</p>
+
+ <p>● If P was previously observed as a non-configurable own accessor property of the target whose [[Get]]
+ attribute is undefined, the [[Get]] operation must return undefined.</p>
+
+ <p><b>[[Set]] ( P, V, Receiver)</b></p>
+
+ <p>● The Type of the return value must be Boolean.</p>
+
+ <p>● If P was previously observed as a non-configurable, non-writable own data property of the target, then
+ [[Set]] must return false unless V is the <a href="#sec-samevalue">SameValue</a> as P’s [[Value]] attribute.</p>
+
+ <p>● If P was previously observed as a non-configurable own accessor property of the target whose [[Set]]
+ attribute is undefined, the [[Set]] operation must return false.</p>
+
+ <p><b>[[Delete]] ( P )</b></p>
+
+ <p>● The Type of the return value must be Boolean.</p>
+
+ <p>● If P was previously observed to be a non-configurable own data or accessor property of the target,
+ [[Delete]] must return false.</p>
+
+ <p><b>[[Enumerate]] ( )</b></p>
+
+ <p>● The Type of the return value must be Object.</p>
+
+ <p><b>[[OwnPropertyKeys]] ( )</b></p>
+
+ <p>● The Type of the return value must be Object.</p>
+
+ <p>● The return value must be an exotic Array object.</p>
+
+ <p>● The returned array must contain at least the string and symbol-valued names of all own properties of the
+ target that have previously been observed as non-configurable.</p>
+
+ <p>● If the target is non-extensible, it may not claim to have any own properties not observed by
+ [[OwnPropertyNames]].</p>
+
+ <p><b>[[Construct]] ( )</b></p>
+
+ <p>● The Type of the return value must be Object.</p>
+ </section>
+
+ <section id="sec-well-known-intrinsic-objects">
+ <h1><span class="secnum" id="sec-6.1.7.4"><a href="#sec-well-known-intrinsic-objects"
+ title="link to this section">6.1.7.4</a></span> Well-Known Intrinsic Objects</h1>
+
+ <p>Well-known intrinsics are built-in objects that are explicitly referenced by the algorithms of this specification and
+ which usually have <a href="#sec-code-realms">Realm</a> specific identities. Unless otherwise specified each intrinsic
+ object actually corresponds to a set of similar objects, one per <a href="#sec-code-realms">Realm</a>.</p>
+
+ <p>Within this specification a reference such as %name% means the intrinsic object, associated with <a
+ href="#sec-execution-contexts">the current Realm</a>, corresponding to the name. Determination of <a
+ href="#sec-execution-contexts">the current Realm</a> and its intrinsics is described in <a
+ href="#sec-newglobalenvironment">8.1.2.5</a>. The well-known intrinsics are listed in <a href="#table-7">Table 7</a>.</p>
+
+ <figure>
+ <figcaption><span id="table-7">Table 7</span> — Well-known Intrinsic Objects</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 0px solid black; border-top: 2px solid #000000">Intrinsic Name</th>
+ <th style="border-bottom: 1px solid #000000; border-top: 2px solid #000000">Global Name</th>
+ <th style="border-bottom: 1px solid #000000; border-right: 1px solid #000000; border-top: 2px solid #000000">ECMAScript Language Association</th>
+ </tr>
+ <tr>
+ <td>%ObjectPrototype%</td>
+ <td></td>
+ <td>The initial value of the <code>"prototype"</code> data property of the intrinsic <span style="font-family: Times New Roman">%Object%</span>. (<a href="#sec-properties-of-the-object-prototype-object">19.1.3</a>)</td>
+ </tr>
+ <tr>
+ <td><a href="#sec-%throwtypeerror%">%ThrowTypeError%</a></td>
+ <td></td>
+ <td>A function that, when called, throws a TypeError exception.</td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">%FunctionPrototype%</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black"></td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">The initial value of the "prototype" data property of the intrinsic %<span style="font-family: Times New Roman">Function</span>%.</td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">%Object%</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">"Object"</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">The Object constructor (<a href="#sec-object-constructor">19.1.1</a>)</td>
+ </tr>
+ <tr>
+ <td>%ObjProto_toString%</td>
+ <td></td>
+ <td>The initial value of the <code>"toString"</code> data property of the intrinsic <span style="font-family: Times New Roman">%ObjectPrototype%</span>. (<a href="#sec-object.prototype.tostring">19.1.3.6</a>)</td>
+ </tr>
+ <tr>
+ <td>%Function%</td>
+ <td><code>"Function"</code></td>
+ <td>The <code>Function</code> constructor (<a href="#sec-function-constructor">19.2.1</a>)</td>
+ </tr>
+ <tr>
+ <td>%Array%</td>
+ <td><code>"Array"</code></td>
+ <td>The <code>Array</code> constructor (<a href="#sec-array-constructor">22.1.1</a>)</td>
+ </tr>
+ <tr>
+ <td>%ArrayPrototype%</td>
+ <td></td>
+ <td>The initial value of the <code>"prototype"</code> data property of the intrinsic <span style="font-family: Times New Roman">%Array%.</span></td>
+ </tr>
+ <tr>
+ <td>%ArrayProto_values%</td>
+ <td></td>
+ <td>The initial value of the <code>"values"</code> data property of the intrinsic <span style="font-family: Times New Roman">%ArrayPrototype%</span>. (<a href="#sec-array.prototype.values">22.1.3.29</a>)</td>
+ </tr>
+ <tr>
+ <td>%ArrayIteratorPrototype%</td>
+ <td></td>
+ <td>The prototype object used for<br>Iterator objects created by the <a href="#sec-createarrayiterator">CreateArrayIterator</a> abstract operation.</td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">%String%</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black"><code>"String"</code></td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">The <code>String</code> constructor (<a href="#sec-string-constructor">21.1.1</a>)</td>
+ </tr>
+ <tr>
+ <td>%StringPrototype%</td>
+ <td></td>
+ <td>The initial value of the <code>"prototype"</code> data property of the intrinsic <span style="font-family: Times New Roman">%String%.</span></td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">%StringIteratorPrototype%</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black"></td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">The prototype object used for<br>Iterator objects created by the <a href="#sec-createstringiterator">CreateStringIterator</a> abstract operation</td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">%Boolean%</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black"><code>"Boolean"</code></td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">The initial value of the global object property named "<code>Boolean</code>".</td>
+ </tr>
+ <tr>
+ <td>%BooleanPrototype%</td>
+ <td></td>
+ <td>The initial value of the <code>"prototype"</code> data property of the intrinsic <span style="font-family: Times New Roman">%Boolean%.</span></td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">%Number%</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black"><code>"Number"</code></td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">The initial value of the global object property named "<code>Number</code>".</td>
+ </tr>
+ <tr>
+ <td>%NumberPrototype%</td>
+ <td></td>
+ <td>The initial value of the <code>"prototype"</code> data property of the intrinsic <span style="font-family: Times New Roman">%Number%.</span></td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">%Date%</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black"><code>"Date"</code></td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">The initial value of the global object property named "<code>Date</code>".</td>
+ </tr>
+ <tr>
+ <td>%DatePrototype%</td>
+ <td></td>
+ <td>The initial value of the <code>"prototype"</code> data property of the intrinsic <span style="font-family: Times New Roman">%Date%.</span></td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">%RegExp%</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black"><code>"RegExp"</code></td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">The initial value of the global object property named "<code>RegExp</code>".</td>
+ </tr>
+ <tr>
+ <td>%RegExpPrototype%</td>
+ <td></td>
+ <td>The initial value of the <code>"prototype"</code> data property of the intrinsic <span style="font-family: Times New Roman">%RegExp%.</span></td>
+ </tr>
+ <tr>
+ <td>%Map%</td>
+ <td><code>"Map"</code></td>
+ <td>The initial value of the global object property named <code>"Map"</code>.</td>
+ </tr>
+ <tr>
+ <td>%MapPrototype%</td>
+ <td></td>
+ <td>The initial value of the <code>"prototype"</code> data property of the intrinsic <span style="font-family: Times New Roman">%Map%.</span></td>
+ </tr>
+ <tr>
+ <td>%MapIteratorPrototype%</td>
+ <td></td>
+ <td>The prototype object used for<br>Iterator objects created by the <a href="#sec-createmapiterator">CreateMapIterator</a> abstract operation</td>
+ </tr>
+ <tr>
+ <td>%WeakMap%</td>
+ <td><code>"WeakMap"</code></td>
+ <td>The initial value of the global object property named <code>"WeakMap"</code>.</td>
+ </tr>
+ <tr>
+ <td>%WeakMapPrototype%</td>
+ <td></td>
+ <td>The initial value of the <code>"prototype"</code> data property of the intrinsic <span style="font-family: Times New Roman">%WeakMap%.</span></td>
+ </tr>
+ <tr>
+ <td>%Set%</td>
+ <td><code>"Set"</code></td>
+ <td>The initial value of the global object property named <code>"Set"</code>.</td>
+ </tr>
+ <tr>
+ <td>%SetPrototype%</td>
+ <td></td>
+ <td>The initial value of the <code>"prototype"</code> data property of the intrinsic <span style="font-family: Times New Roman">%Set%.</span></td>
+ </tr>
+ <tr>
+ <td>%WeakSet%</td>
+ <td><code>"WeakSet"</code></td>
+ <td>The initial value of the global object property named <code>"WeakSet"</code>.</td>
+ </tr>
+ <tr>
+ <td>%WeakSetPrototype%</td>
+ <td></td>
+ <td>The initial value of the <code>"prototype"</code> data property of the intrinsic <span style="font-family: Times New Roman">%WeakSet%.</span></td>
+ </tr>
+ <tr>
+ <td>%SetIteratorPrototype%</td>
+ <td></td>
+ <td>The prototype object used for<br>Iterator objects created by the <a href="#sec-createsetiterator">CreateSetIterator</a> abstract operation</td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">%GeneratorFunction%</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black"></td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">The constructor of generator functions.</td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">%Generator%</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black"></td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">The initial value of the <code>prototype</code> property of the %GeneratorFunction intrinsic</td>
+ </tr>
+ <tr>
+ <td>%GeneratorPrototype%</td>
+ <td></td>
+ <td>The initial value of the <code>prototype</code> property of the %Generator% intrinsic</td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">%Error%</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black"></td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black"></td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">%EvalError%</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black"></td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black"></td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">%RangeError%</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black"></td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black"></td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">%ReferenceError%</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black"></td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black"></td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">%SyntaxError%</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black"></td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black"></td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">%TypeError%</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black"></td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black"></td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">%URIError%</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black"></td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black"></td>
+ </tr>
+ <tr>
+ <td>%ErrorPrototype%</td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>%EvalErrorPrototype%</td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>%RangeErrorPrototype%</td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>%ReferenceErrorPrototype%</td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>%SyntaxErrorPrototype%</td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>%TypeErrorPrototype%</td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>%URIErrorPrototype%</td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>%ArrayBuffer%</td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>%ArrayBufferPrototype%</td>
+ <td></td>
+ <td>The initial value of the <code>"prototype"</code> data property of the intrinsic <span style="font-family: Times New Roman">%ArrayBuffer%.</span></td>
+ </tr>
+ <tr>
+ <td>%TypedArray%</td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>%TypedArrayPrototype%</td>
+ <td></td>
+ <td>The initial value of the <code>"prototype"</code> data property of the intrinsic <span style="font-family: Times New Roman">%TypedArray%.</span></td>
+ </tr>
+ <tr>
+ <td>%Int8Array%</td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>%Int8ArrayPrototype%</td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>%DataView%</td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>%DataViewPrototype%</td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td><a href="#sec-%throwtypeerror%">%ThrowTypeError%</a></td>
+ <td></td>
+ <td>A function object that unconditionally throws a new instance of %TypeError%.</td>
+ </tr>
+ <tr>
+ <td>%Realm%</td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>%RealmPrototype%</td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>%Promise%</td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>%PromisePrototype%</td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>%Loader%</td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>%LoaderPrototype%</td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>%LoaderIteratorPrototype%</td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>%ReturnUndefined%</td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>%Symbol%</td>
+ <td></td>
+ <td></td>
+ </tr>
+ </table>
+ </figure>
+ </section>
+ </section>
+ </section>
+
+ <section id="sec-ecmascript-specification-types">
+ <div class="front">
+ <h1><span class="secnum" id="sec-6.2"><a href="#sec-ecmascript-specification-types"
+ title="link to this section">6.2</a></span> ECMAScript Specification Types</h1>
+
+ <p>A specification type corresponds to meta-values that are used within algorithms to describe the semantics of ECMAScript
+ language constructs and ECMAScript language types. The specification types are <a
+ href="#sec-reference-specification-type">Reference</a>, <a href="#sec-list-and-record-specification-type">List</a>, <a
+ href="#sec-completion-record-specification-type">Completion</a>, <a
+ href="#sec-property-descriptor-specification-type">Property Descriptor</a>, <a href="#sec-lexical-environments">Lexical
+ Environment</a>, <a href="#sec-environment-records">Environment Record</a>, and <a href="#sec-data-blocks">Data Block</a>.
+ Specification type values are specification artefacts that do not necessarily correspond to any specific entity within an
+ ECMAScript implementation. Specification type values may be used to describe intermediate results of ECMAScript expression
+ evaluation but such values cannot be stored as properties of objects or values of ECMAScript language variables.</p>
+ </div>
+
+ <section id="sec-list-and-record-specification-type">
+ <h1><span class="secnum" id="sec-6.2.1"><a href="#sec-list-and-record-specification-type"
+ title="link to this section">6.2.1</a></span> The List and Record Specification Type</h1>
+
+ <p>The List type is used to explain the evaluation of argument lists (<a href="#sec-argument-lists">see 12.3.6</a>) in
+ <code>new</code> expressions, in function calls, and in other algorithms where a simple ordered list of values is needed.
+ Values of the List type are simply ordered sequences of list elements containing the individual values. These sequences may
+ be of any length. The elements of a list may be randomly accessed using 0-origin indices. For notational convience an
+ array-like syntax can be used to access List elements. For example, <i>arguments</i>[2] is shorthand for saying the
+ 3<sup>rd</sup> element of the List <i>arguments</i>.</p>
+
+ <p>The Record type is used to describe data aggregations within the algorithms of this specification. A Record type value
+ consists of one or more named fields. The value of each field is either an ECMAScript value or an abstract value
+ represented by a name associated with the Record type. Field names are always enclosed in double brackets, for example
+ [[value]]</p>
+
+ <p>For notational convenience within this specification, an object literal-like syntax can be used to express a Record
+ value. For example, {[[field1]]: 42, [[field2]]: <b>false</b>, [[field3]]: <b>empty</b>} defines a Record value that has
+ three fields each of which is initialized to a specific value. Field name order is not significant. Any fields that are not
+ explicitly listed are considered to be absent.</p>
+
+ <p>In specification text and algorithms, dot notation may be used to refer to a specific field of a Record value. For
+ example, if R is the record shown in the previous paragraph then R.[[field2]] is shorthand for “the field of R named
+ [[field2]]”.</p>
+
+ <p>Schema for commonly used Record field combinations may be named, and that name may be used as a prefix to a literal
+ Record value to identify the specific kind of aggregations that is being described. For example:
+ PropertyDescriptor{[[Value]]: 42, [[Writable]]: <b>false</b>, [[Configurable]]: <b>true</b>}.</p>
+ </section>
+
+ <section id="sec-completion-record-specification-type">
+ <div class="front">
+ <h1><span class="secnum" id="sec-6.2.2"><a href="#sec-completion-record-specification-type"
+ title="link to this section">6.2.2</a></span> The Completion Record Specification Type</h1>
+
+ <p>The Completion type is a Record used to explain the runtime propagation of values and control flow such as the
+ behaviour of statements (<code>break</code>, <code>continue</code>, <code>return</code> and <code>throw</code>) that
+ perform nonlocal transfers of control.</p>
+
+ <p>Values of the Completion type are Record values whole fields are defined as by <a href="#table-8">Table 8</a>.</p>
+
+ <figure>
+ <figcaption><span id="table-8">Table 8</span> — Completion Record Fields</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 0px solid black; border-top: 2px solid #000000">Field Name</th>
+ <th style="border-bottom: 1px solid #000000; border-left: 0px solid black; border-right: 1px solid #000000; border-top: 2px solid #000000">Value</th>
+ <th style="border-bottom: 1px solid #000000; border-right: 1px solid #000000; border-top: 2px solid #000000">Meaning</th>
+ </tr>
+ <tr>
+ <td>[[type]]</td>
+ <td>One of <b>normal</b>, <b>break</b>, <b>continue</b>, <b>return</b>, or <b>throw</b></td>
+ <td>The type of completion that occurred.</td>
+ </tr>
+ <tr>
+ <td>[[value]]</td>
+ <td>any <a href="#sec-ecmascript-language-types">ECMAScript language value</a> or <b>empty</b></td>
+ <td>The value that was produced.</td>
+ </tr>
+ <tr>
+ <td>[[target]]</td>
+ <td>any ECMAScript string or <b>empty</b></td>
+ <td>The target label for directed control transfers.</td>
+ </tr>
+ </table>
+ </figure>
+
+ <p>The term “abrupt completion” refers to any completion with a <span style="font-family: Times New
+ Roman">[[type]]</span> value other than <b>normal</b>.</p>
+ </div>
+
+ <section id="sec-normalcompletion">
+ <h1><span class="secnum" id="sec-6.2.2.1"><a href="#sec-normalcompletion" title="link to this section">6.2.2.1</a></span>
+ NormalCompletion</h1>
+
+ <p>The abstract operation NormalCompletion with a single <i>argument</i>, such as:</p>
+
+ <ol class="proc">
+ <li>Return NormalCompletion(<i>argument</i>).</li>
+ </ol>
+
+ <p>Is a shorthand that is defined as follows:</p>
+
+ <ol class="proc">
+ <li>Return <a href="#sec-completion-record-specification-type">Completion</a>{[[type]]: <span style="font-family:
+ sans-serif">normal</span>, [[value]]: <i>argument</i>, [[target]]:<span style="font-family:
+ sans-serif">empty</span>}.</li>
+ </ol>
+ </section>
+
+ <section id="sec-implicit-completion-values">
+ <h1><span class="secnum" id="sec-6.2.2.2"><a href="#sec-implicit-completion-values"
+ title="link to this section">6.2.2.2</a></span> Implicit Completion Values</h1>
+
+ <p>The algorithms of this specification often implicitly return <a
+ href="#sec-completion-record-specification-type">Completion</a> Records whose [[type]] is <b>normal</b>. Unless it is
+ otherwise obvious from the context, an algorithm statement that returns a value that is not a <a
+ href="#sec-completion-record-specification-type">Completion Record</a>, such as:</p>
+
+ <ol class="proc">
+ <li>Return "Infinity".</li>
+ </ol>
+
+ <p>Generally means the same thing as:</p>
+
+ <ol class="proc">
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<code>"Infinity"</code>).</li>
+ </ol>
+
+ <p>A “<span style="font-family: Times New Roman">return</span>” statement without a value in an algorithm step
+ means the same thing as:</p>
+
+ <ol class="proc">
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<b>undefined</b>).</li>
+ </ol>
+
+ <p>Similarly, any reference to a <a href="#sec-completion-record-specification-type">Completion Record</a> value that is
+ in a context that does not explicitly require a complete <a href="#sec-completion-record-specification-type">Completion
+ Record</a> value is equivalent to an explicit reference to the [[value]] field of the <a
+ href="#sec-completion-record-specification-type">Completion Record</a> value unless the <a
+ href="#sec-completion-record-specification-type">Completion Record</a> is an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a>.</p>
+ </section>
+
+ <section id="sec-throw-an-exception">
+ <h1><span class="secnum" id="sec-6.2.2.3"><a href="#sec-throw-an-exception"
+ title="link to this section">6.2.2.3</a></span> Throw an Exception</h1>
+
+ <p>Algorithms steps that say to throw an exception, such as</p>
+
+ <ol class="proc">
+ <li>Throw a <b>TypeError</b> exception.</li>
+ </ol>
+
+ <p>mean the same things as:</p>
+
+ <ol class="proc">
+ <li>Return <a href="#sec-completion-record-specification-type">Completion</a>{[[type]]: <span style="font-family:
+ sans-serif">throw</span>, [[value]]: a newly created <b>TypeError</b> object, [[target]]:<span style="font-family:
+ sans-serif">empty</span>}.</li>
+ </ol>
+ </section>
+
+ <section id="sec-returnifabrupt">
+ <h1><span class="secnum" id="sec-6.2.2.4"><a href="#sec-returnifabrupt" title="link to this section">6.2.2.4</a></span>
+ ReturnIfAbrupt</h1>
+
+ <p>Algorithms steps that say</p>
+
+ <ol class="proc">
+ <li>ReturnIfAbrupt(<i>argument</i>).</li>
+ </ol>
+
+ <p>mean the same thing as:</p>
+
+ <ol class="proc">
+ <li>If <i>argument</i> is an <a href="#sec-completion-record-specification-type">abrupt completion</a>, then return
+ <i>argument</i>.</li>
+ <li>Else if <i>argument</i> is a <a href="#sec-completion-record-specification-type">Completion Record</a>, then let
+ <i>argument</i> be <i>argument</i>.[[value]].</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-reference-specification-type">
+ <div class="front">
+ <h1><span class="secnum" id="sec-6.2.3"><a href="#sec-reference-specification-type"
+ title="link to this section">6.2.3</a></span> The Reference Specification Type</h1>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The Reference type is used to explain the behaviour of such operators as
+ <code>delete</code>, <code>typeof</code>, the assignment operators, the <code>super</code> keyword and other language
+ features. For example, the left-hand operand of an assignment is expected to produce a reference.</p>
+ </div>
+
+ <p>A <b>Reference</b> is a resolved name or property binding. A Reference consists of three components, the
+ <var>base</var> value, the <var>referenced name</var> and the Boolean valued <var>strict reference</var> flag. The
+ <var>base</var> value is either <b>undefined</b>, an Object, a Boolean, a String, a Symbol, a Number, or an environment
+ record (<a href="#sec-environment-records">8.1.1</a>). A <var>base</var> value of <b>undefined</b> indicates that the
+ Reference could not be resolved to a binding. The <var>referenced name</var> is a String or Symbol value.</p>
+
+ <p>A Super Reference is a Reference that is used to represents a name binding that was expressed using the super keyword.
+ A Super Reference has an additional <var>thisValue</var> component and its <var>base</var> value will never be an
+ environment record.</p>
+
+ <p>The following abstract operations are used in this specification to access the components of references:</p>
+
+ <ul>
+ <li>
+ <p>GetBase(V). Returns the <i>base</i> value component of the reference V.</p>
+ </li>
+
+ <li>
+ <p>GetReferencedName(V). Returns the <i>referenced name</i> component of the reference V.</p>
+ </li>
+
+ <li>
+ <p>IsStrictReference(V). Returns the <i>strict reference</i> flag component of the reference V.</p>
+ </li>
+
+ <li>
+ <p>HasPrimitiveBase(V). Returns <b>true</b> if <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>base</i>)
+ is a Boolean, String, Symbol, or Number.</p>
+ </li>
+
+ <li>
+ <p>IsPropertyReference(V). Returns <b>true</b> if either the <i>base</i> value is an object or HasPrimitiveBase(V) is
+ <b>true</b>; otherwise returns <b>false</b>.</p>
+ </li>
+
+ <li>
+ <p>IsUnresolvableReference(V). Returns <b>true</b> if the <i>base</i> value is <b>undefined</b> and <b>false</b>
+ otherwise.</p>
+ </li>
+
+ <li>
+ <p>IsSuperReference(V). Returns <b>true</b> if this reference has a <i>thisValue</i> component.</p>
+ </li>
+ </ul>
+
+ <p>The following abstract operations are used in this specification to operate on references:</p>
+ </div>
+
+ <section id="sec-getvalue">
+ <h1><span class="secnum" id="sec-6.2.3.1"><a href="#sec-getvalue" title="link to this section">6.2.3.1</a></span> GetValue
+ (V)</h1>
+ <ol class="proc">
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>V</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>V</i>) is not <a
+ href="#sec-reference-specification-type">Reference</a>, return <i>V</i>.</li>
+ <li>Let <i>base</i> be <a href="#sec-reference-specification-type">GetBase</a>(<i>V</i>).</li>
+ <li>If <a href="#sec-reference-specification-type">IsUnresolvableReference</a>(<i>V</i>), throw a <b>ReferenceError</b>
+ exception.</li>
+ <li>If <a href="#sec-reference-specification-type">IsPropertyReference</a>(<i>V</i>), then
+ <ol class="block">
+ <li>If <a href="#sec-reference-specification-type">HasPrimitiveBase</a>(<i>V</i>) is <b>true</b>, then
+ <ol class="block">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: In this case, <i>base</i> will never be <b>null</b> or
+ <b>undefined</b>.</li>
+ <li>Let <i>base</i> be <a href="#sec-toobject">ToObject</a>(<i>base</i>).</li>
+ </ol>
+ </li>
+ <li>Return the result of calling the [[Get]] internal method of <i>base</i> passing <a
+ href="#sec-reference-specification-type">GetReferencedName</a>(<i>V</i>) and <a
+ href="#sec-getthisvalue">GetThisValue</a>(<i>V</i>) as the arguments.</li>
+ </ol>
+ </li>
+ <li>Else <i>base</i> must be an environment record,
+ <ol class="block">
+ <li>Return the result of calling the GetBindingValue (<a href="#sec-environment-records">see 8.1.1</a>) concrete
+ method of <i>base</i> passing <a href="#sec-reference-specification-type">GetReferencedName</a>(<i>V</i>) and <a
+ href="#sec-reference-specification-type">IsStrictReference</a>(<i>V</i>) as arguments.</li>
+ </ol>
+ </li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The object that may be created in step 5.a.ii is not accessible outside of the above
+ abstract operation and the ordinary object [[Get]] internal method. An implementation might choose to avoid the actual
+ creation of the object.</p>
+ </div>
+ </section>
+
+ <section id="sec-putvalue">
+ <h1><span class="secnum" id="sec-6.2.3.2"><a href="#sec-putvalue" title="link to this section">6.2.3.2</a></span> PutValue
+ (V, W)</h1>
+ <ol class="proc">
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>V</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>W</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>V</i>) is not <a
+ href="#sec-reference-specification-type">Reference</a>, throw a <b>ReferenceError</b> exception.</li>
+ <li>Let <i>base</i> be <a href="#sec-reference-specification-type">GetBase</a>(<i>V</i>).</li>
+ <li>If <a href="#sec-reference-specification-type">IsUnresolvableReference</a>(<i>V</i>), then
+ <ol class="block">
+ <li>If <a href="#sec-reference-specification-type">IsStrictReference</a>(<i>V</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>Throw <b>ReferenceError</b> exception.</li>
+ </ol>
+ </li>
+ <li>Let <i>globalObj</i> be the result of the abstract operation <a
+ href="#sec-getglobalobject">GetGlobalObject</a>.</li>
+ <li>Return <a href="#sec-put-o-p-v-throw">Put</a>(<i>globalObj</i>,<a
+ href="#sec-reference-specification-type">GetReferencedName</a>(<i>V</i>), <i>W</i>, <b>false</b>).</li>
+ </ol>
+ </li>
+ <li>Else if <a href="#sec-reference-specification-type">IsPropertyReference</a>(<i>V</i>), then
+ <ol class="block">
+ <li>If <a href="#sec-reference-specification-type">HasPrimitiveBase</a>(<i>V</i>) is <b>true</b>, then
+ <ol class="block">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: In this case, <i>base</i> will never be <b>null</b> or
+ <b>undefined</b>.</li>
+ <li>Set <i>base</i> to <a href="#sec-toobject">ToObject</a>(<i>base</i>).</li>
+ </ol>
+ </li>
+ <li>Let <i>succeeded</i> be the result of calling the [[Set]] internal method of <i>base</i> passing <a
+ href="#sec-reference-specification-type">GetReferencedName</a>(<i>V</i>), <i>W</i>, and <a
+ href="#sec-getthisvalue">GetThisValue</a>(<i>V</i>) as arguments.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>succeeded</i>).</li>
+ <li>If <i>succeeded</i> is <b>false</b> and <a
+ href="#sec-reference-specification-type">IsStrictReference</a>(<i>V</i>) is <b>true</b>, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>Return.</li>
+ </ol>
+ </li>
+ <li>Else <i>base</i> must be a <a href="#sec-reference-specification-type">Reference</a> whose base is an environment
+ record.
+ <ol class="block">
+ <li>Return the result of calling the SetMutableBinding (<a href="#sec-environment-records">8.1.1</a>) concrete
+ method of <i>base</i>, passing <a href="#sec-reference-specification-type">GetReferencedName</a>(<i>V</i>),
+ <i>W</i>, and <a href="#sec-reference-specification-type">IsStrictReference</a>(<i>V</i>) as arguments.</li>
+ </ol>
+ </li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The object that may be created in step 6.a.ii is not accessible outside of the above
+ algorithm and the ordinary object [[Set]] internal method. An implementation might choose to avoid the actual creation
+ of that object.</p>
+ </div>
+ </section>
+
+ <section id="sec-getthisvalue">
+ <h1><span class="secnum" id="sec-6.2.3.3"><a href="#sec-getthisvalue" title="link to this section">6.2.3.3</a></span>
+ GetThisValue (V)</h1>
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a
+ href="#sec-reference-specification-type">IsPropertyReference</a>(<i>V</i>) is <b>true</b>.</li>
+ <li>If <a href="#sec-reference-specification-type">IsSuperReference</a>(<i>V</i>), then
+ <ol class="block">
+ <li>Return the value of the <i>thisValue</i> component of the reference <i>V</i>.</li>
+ </ol>
+ </li>
+ <li>Return <a href="#sec-reference-specification-type">GetBase</a>(<i>V</i>).</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-property-descriptor-specification-type">
+ <div class="front">
+ <h1><span class="secnum" id="sec-6.2.4"><a href="#sec-property-descriptor-specification-type"
+ title="link to this section">6.2.4</a></span> The Property Descriptor Specification Type</h1>
+
+ <p>The Property Descriptor type is used to explain the manipulation and reification of Object property attributes. Values
+ of the Property Descriptor type are Records. Except for the optional [[Origin]] field, each field’s name is an
+ attribute name and its value is a corresponding attribute value as specified in <a
+ href="#sec-property-attributes">6.1.7.1</a>. In addition, any field may be present or absent. The schema name used within
+ this specification to tag literal descriptions of Property Descriptor records is “PropertyDescriptor”.</p>
+
+ <p>Property Descriptor values may be further classified as data Property Descriptors and accessor Property Descriptors
+ based upon the existence or use of certain fields. A data Property Descriptor is one that includes any fields named either
+ [[Value]] or [[Writable]]. An accessor Property Descriptor is one that includes any fields named either [[Get]] or
+ [[Set]]. Any Property Descriptor may have fields named [[Enumerable]] and [[Configurable]]. A Property Descriptor value
+ may not be both a data Property Descriptor and an accessor Property Descriptor; however, it may be neither. A generic
+ Property Descriptor is a Property Descriptor value that is neither a data Property Descriptor nor an accessor Property
+ Descriptor. A fully populated Property Descriptor is one that is either an accessor Property Descriptor or a data Property
+ Descriptor and that has all of the fields that correspond to the property attributes defined in either <a
+ href="#table-2">Table 2</a> or <a href="#table-3">Table 3</a>.</p>
+
+ <p>A Property Descriptor may be derived from an object that has properties that directly correspond to the fields of a
+ Property Descriptor. Such a derived Property Descriptor has an additional field named [[Origin]] whose value is the object
+ from which the Property Descriptor was derived.</p>
+
+ <p>The following abstract operations are used in this specification to operate upon Property Descriptor values:</p>
+ </div>
+
+ <section id="sec-isaccessordescriptor">
+ <h1><span class="secnum" id="sec-6.2.4.1"><a href="#sec-isaccessordescriptor"
+ title="link to this section">6.2.4.1</a></span> IsAccessorDescriptor ( Desc )</h1>
+
+ <p>When the abstract operation IsAccessorDescriptor is called with <a
+ href="#sec-property-descriptor-specification-type">Property Descriptor</a> <span class="nt">Desc</span>, the following
+ steps are taken:</p>
+
+ <ol class="proc">
+ <li>If <i>Desc</i> is <b>undefined</b>, then return <b>false</b>.</li>
+ <li>If both <i>Desc</i>.[[Get]] and <i>Desc</i>.[[Set]] are absent, then return <b>false</b>.</li>
+ <li>Return <b>true</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-isdatadescriptor">
+ <h1><span class="secnum" id="sec-6.2.4.2"><a href="#sec-isdatadescriptor" title="link to this section">6.2.4.2</a></span>
+ IsDataDescriptor ( Desc )</h1>
+
+ <p>When the abstract operation IsDataDescriptor is called with <a
+ href="#sec-property-descriptor-specification-type">Property Descriptor</a> <span class="nt">Desc</span>, the following
+ steps are taken:</p>
+
+ <ol class="proc">
+ <li>If <i>Desc</i> is <b>undefined</b>, then return <b>false</b>.</li>
+ <li>If both <i>Desc</i>.[[Value]] and <i>Desc</i>.[[Writable]] are absent, then return <b>false</b>.</li>
+ <li>Return <b>true</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-isgenericdescriptor">
+ <h1><span class="secnum" id="sec-6.2.4.3"><a href="#sec-isgenericdescriptor"
+ title="link to this section">6.2.4.3</a></span> IsGenericDescriptor ( Desc )</h1>
+
+ <p>When the abstract operation IsGenericDescriptor is called with <a
+ href="#sec-property-descriptor-specification-type">Property Descriptor</a> <span class="nt">Desc</span>, the following
+ steps are taken:</p>
+
+ <ol class="proc">
+ <li>If <i>Desc</i> is <b>undefined</b>, then return <b>false</b>.</li>
+ <li>If <a href="#sec-isaccessordescriptor">IsAccessorDescriptor</a>(<i>Desc</i>) and <a
+ href="#sec-isdatadescriptor">IsDataDescriptor</a>(<i>Desc</i>) are both <b>false</b>, then return <b>true</b>.</li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-frompropertydescriptor">
+ <h1><span class="secnum" id="sec-6.2.4.4"><a href="#sec-frompropertydescriptor"
+ title="link to this section">6.2.4.4</a></span> FromPropertyDescriptor ( Desc )</h1>
+
+ <p>When the abstract operation FromPropertyDescriptor is called with <a
+ href="#sec-property-descriptor-specification-type">Property Descriptor</a> <span class="nt">Desc</span>, the following
+ steps are taken:</p>
+
+ <ol class="proc">
+ <li>If <i>Desc</i> is <b>undefined</b>, then return <b>undefined</b>.</li>
+ <li>If <i>Desc</i> has an [[Origin]] field, then return <i>Desc</i>.[[Origin]].</li>
+ <li>Let <i>obj</i> be <a href="#sec-objectcreate">ObjectCreate</a>(<span style="font-family:
+ sans-serif">%ObjectPrototype%</span>).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>obj</i> is an extensible ordinary object with no own
+ properties.</li>
+ <li>If <i>Desc</i> has a [[Value]] field, then
+ <ol class="block">
+ <li>Call <a href="#sec-ordinarydefineownproperty">OrdinaryDefineOwnProperty</a> with arguments <i>obj</i>,
+ "<b><code>value</code>"</b>, and PropertyDescriptor{[[Value]]: <i>Desc</i>.[[Value]], [[Writable]]: <b>true</b>,
+ [[Enumerable]]: <b>true</b>, [[Configurable]]: <b>true</b>}</li>
+ </ol>
+ </li>
+ <li>If <i>Desc</i> has a [[Writable]] field, then
+ <ol class="block">
+ <li>Call <a href="#sec-ordinarydefineownproperty">OrdinaryDefineOwnProperty</a> with arguments <i>obj</i>,
+ "<code>writable</code>", and PropertyDescriptor{[[Value]]: <i>Desc</i>.[[Writable]], [[Writable]]: <b>true</b>,
+ [[Enumerable]]: <b>true</b>, [[Configurable]]: <b>true</b>}.</li>
+ </ol>
+ </li>
+ <li>If <i>Desc</i> has a [[Get]] field, then
+ <ol class="block">
+ <li>Call <a href="#sec-ordinarydefineownproperty">OrdinaryDefineOwnProperty</a> with arguments <i>obj</i>,
+ "<code>get",</code> and PropertyDescriptor{[[Value]]: <i>Desc</i>.[[Get]], [[Writable]]: <b>true</b>,
+ [[Enumerable]]: <b>true</b>, [[Configurable]]: <b>true</b>}.</li>
+ </ol>
+ </li>
+ <li>If <i>Desc</i> has a [[Set]] field, then
+ <ol class="block">
+ <li>Call <a href="#sec-ordinarydefineownproperty">OrdinaryDefineOwnProperty</a> with arguments <i>obj</i>,
+ "<code>set</code>", and PropertyDescriptor{[[Value]]: <i>Desc</i>.[[Set]], [[Writable]]: <b>true</b>,
+ [[Enumerable]]: <b>true</b>, [[Configurable]]: <b>true</b>}.</li>
+ </ol>
+ </li>
+ <li>If <i>Desc</i> has an [[Enumerable]] field, then
+ <ol class="block">
+ <li>Call <a href="#sec-ordinarydefineownproperty">OrdinaryDefineOwnProperty</a> with arguments <i>obj</i>,
+ "<code>enumerable</code>", and PropertyDescriptor{[[Value]]: <i>Desc</i>.[[Enumerable]], [[Writable]]:
+ <b>true</b>, [[Enumerable]]: <b>true</b>, [[Configurable]]: <b>true</b>}.</li>
+ </ol>
+ </li>
+ <li>If <i>Desc</i> has a [[Configurable]] field, then
+ <ol class="block">
+ <li>Call <a href="#sec-ordinarydefineownproperty">OrdinaryDefineOwnProperty</a> with arguments <i>obj</i> ,
+ "<code>configurable</code>", and PropertyDescriptor{[[Value]]: <i>Desc</i>.[[Configurable]], [[Writable]]:
+ <b>true</b>, [[Enumerable]]: <b>true</b>, [[Configurable]]: <b>true</b>}.</li>
+ </ol>
+ </li>
+ <li>Return <i>obj</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-topropertydescriptor">
+ <h1><span class="secnum" id="sec-6.2.4.5"><a href="#sec-topropertydescriptor"
+ title="link to this section">6.2.4.5</a></span> ToPropertyDescriptor ( Obj )</h1>
+
+ <p>When the abstract operation ToPropertyDescriptor is called with object <span class="nt">Obj</span>, the following steps
+ are taken:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>Obj</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>Obj</i>) is not Object throw a <b>TypeError</b>
+ exception.</li>
+ <li>Let <i>desc</i> be a new <a href="#sec-property-descriptor-specification-type">Property Descriptor</a> that
+ initially has no fields.</li>
+ <li>If <a href="#sec-hasproperty">HasProperty</a>(<i>Obj</i>, "<code>enumerable</code>") is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>enum</i> be <a href="#sec-get-o-p">Get</a>(<i>Obj</i>, "<code>enumerable</code>").</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>enum</i>).</li>
+ <li>Set the [[Enumerable]] field of <i>desc</i> to <a href="#sec-toboolean">ToBoolean</a>(<i>enum</i>).</li>
+ </ol>
+ </li>
+ <li>If <a href="#sec-hasproperty">HasProperty</a>(<i>Obj</i>, "<code>configurable</code>") is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>conf</i> be <a href="#sec-get-o-p">Get</a>(<i>Obj</i>, "<code>configurable</code>").</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>conf</i>).</li>
+ <li>Set the [[Configurable]] field of <i>desc</i> to <a href="#sec-toboolean">ToBoolean</a>(<i>conf</i>).</li>
+ </ol>
+ </li>
+ <li>If <a href="#sec-hasproperty">HasProperty</a>(<i>Obj</i>, "<code>value</code>") is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>value</i> be <a href="#sec-get-o-p">Get</a>(<i>Obj</i>, "<code>value</code>").</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>value</i>).</li>
+ <li>Set the [[Value]] field of <i>desc</i> to <i>value</i>.</li>
+ </ol>
+ </li>
+ <li>If <a href="#sec-hasproperty">HasProperty</a>(<i>Obj</i>, "<code>writable</code>") is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>writable</i> be <a href="#sec-get-o-p">Get</a>(<i>Obj</i>, "<code>writable</code>").</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>writable</i>).</li>
+ <li>Set the [[Writable]] field of <i>desc</i> to <a href="#sec-toboolean">ToBoolean</a>(<i>writable</i>).</li>
+ </ol>
+ </li>
+ <li>If <a href="#sec-hasproperty">HasProperty</a>(<i>Obj</i>, "<code>get</code>") is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>getter</i> be <a href="#sec-get-o-p">Get</a>(<i>Obj</i>, "<code>get</code>").</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>getter</i>).</li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>getter</i>) is <b>false</b> and <i>getter</i> is not
+ <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Set the [[Get]] field of <i>desc</i> to <i>getter</i>.</li>
+ </ol>
+ </li>
+ <li>If <a href="#sec-hasproperty">HasProperty</a>(<i>Obj</i>, "<code>set</code>") is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>setter</i> be <a href="#sec-get-o-p">Get</a>(<i>Obj</i>, "<code>set</code>").</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>setter</i>).</li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>setter</i>) is <b>false</b> and <i>setter</i> is not
+ <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Set the [[Set]] field of <i>desc</i> to <i>setter</i>.</li>
+ </ol>
+ </li>
+ <li>If either <i>desc</i>.[[Get]] or <i>desc</i>.[[Set]] are present, then
+ <ol class="block">
+ <li>If either <i>desc</i>.[[Value]] or <i>desc</i>.[[Writable]] are present, then throw a <b>TypeError</b>
+ exception.</li>
+ </ol>
+ </li>
+ <li>Set the [[Origin]] field of <i>desc</i> to <i>Obj</i>.</li>
+ <li>Return <i>desc</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-completepropertydescriptor">
+ <h1><span class="secnum" id="sec-6.2.4.6"><a href="#sec-completepropertydescriptor"
+ title="link to this section">6.2.4.6</a></span> CompletePropertyDescriptor ( Desc, LikeDesc )</h1>
+
+ <p>When the abstract operation CompletePropertyDescriptor is called with Property Descriptors <span class="nt">Desc</span>
+ and <span class="nt">LikeDesc</span> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>LikeDesc</i> is either a <a
+ href="#sec-property-descriptor-specification-type">Property Descriptor</a> or <b>undefined</b>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>Desc</i>).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>Desc</i> is a <a
+ href="#sec-property-descriptor-specification-type">Property Descriptor</a></li>
+ <li>If <i>LikeDesc</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>like</i> be Record{[[Value]]: <b>undefined</b>, [[Writable]]: <b>false</b>, [[Get]]: <b>undefined</b>,
+ [[Set]]: <b>undefined</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]: <b>false</b>}.</li>
+ </ol>
+ </li>
+ <li>else,
+ <ol class="block">
+ <li>Let <i>like</i> be a new <a href="#sec-property-descriptor-specification-type">Property Descriptor</a> that is a
+ copy of <i>LikeDesc</i>.</li>
+ <li>Perform CompletePropertyDescriptor(<i>like</i>, <b>undefined</b>).</li>
+ </ol>
+ </li>
+ <li>If either <a href="#sec-isgenericdescriptor">IsGenericDescriptor</a>(<i>Desc</i>) or <a
+ href="#sec-isdatadescriptor">IsDataDescriptor</a>(<i>Desc</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>If <i>Desc</i> does not have a [[Value]] field, then set <i>Desc</i>.[[Value]] to <i>like</i>.[[Value]].</li>
+ <li>If <i>Desc</i> does not have a [[Writable]] field, then set <i>Desc</i>.[[Writable]] to
+ <i>like</i>.[[Writable]].</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>If <i>Desc</i> does not have a [[Get]] field, then set <i>Desc</i>.[[Get]] to <i>like</i>.[[Get]].</li>
+ <li>If <i>Desc</i> does not have a [[Set]] field, then set <i>Desc</i>.[[Set]] to <i>like</i>.[[Set]].</li>
+ </ol>
+ </li>
+ <li>If <i>Desc</i> does not have an [[Enumerable]] field, then set <i>Desc</i>.[[Enumerable]] to
+ <i>like</i>.[[Enumerable]].</li>
+ <li>If <i>Desc</i> does not have a [[Configurable]] field, then set <i>Desc</i>.[[Configurable]] to
+ <i>like</i>.[[Configurable]].</li>
+ <li>Return <i>Desc</i>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-lexical-environment-and-environment-record-specification-types">
+ <h1><span class="secnum" id="sec-6.2.5"><a href="#sec-lexical-environment-and-environment-record-specification-types"
+ title="link to this section">6.2.5</a></span> The Lexical Environment and Environment Record Specification Types</h1>
+
+ <p>The <a href="#sec-lexical-environments">Lexical Environment</a> and <a href="#sec-environment-records">Environment
+ Record</a> types are used to explain the behaviour of name resolution in nested functions and blocks. These types and the
+ operations upon them are defined in <a href="#sec-lexical-environments">8.1</a>.</p>
+ </section>
+
+ <section id="sec-data-blocks">
+ <div class="front">
+ <h1><span class="secnum" id="sec-6.2.6"><a href="#sec-data-blocks" title="link to this section">6.2.6</a></span> Data
+ Blocks</h1>
+
+ <p>The Data Block specification type is used to describe a distinct and mutable sequence of byte-sized (8 bit) numeric
+ values. A Data Block value is created with a fixed number of bytes that each have the initial value 0.</p>
+
+ <p>For notational convenience within this specification, an array-like syntax can be used to express to the individual
+ bytes of a Data Block value. This notation presents a Data Block value as a 0-origined integer indexed sequence of bytes.
+ For example, if <var>db</var> is a 5 byte Data Block value then <var>db</var>[2] can be used to express access to its
+ 3<sup>rd</sup> byte.</p>
+
+ <p>The following abstract operations are used in this specification to operate upon Data Block values:</p>
+ </div>
+
+ <section id="sec-createbytedatablock">
+ <h1><span class="secnum" id="sec-6.2.6.1"><a href="#sec-createbytedatablock"
+ title="link to this section">6.2.6.1</a></span> CreateByteDataBlock(size)</h1>
+
+ <p>When the abstract operation CreateByteDataBlock is called with integer argument <var>size</var>, the following steps
+ are taken:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>size</i>≥0.</li>
+ <li>Let <i>db</i> be a new <a href="#sec-data-blocks">Data Block</a> value consisting of <i>size</i> bytes. If it is
+ impossible to create such a <a href="#sec-data-blocks">Data Block</a>, then throw a <b>RangeError</b>
+ exception.</li>
+ <li>Set all of the bytes of <i>db</i> to 0.</li>
+ <li>Return <i>db</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-copydatablockbytes">
+ <h1><span class="secnum" id="sec-6.2.6.2"><a href="#sec-copydatablockbytes"
+ title="link to this section">6.2.6.2</a></span> CopyDataBlockBytes(toBlock, toIndex, fromBlock, fromIndex, count)</h1>
+
+ <p>When the abstract operation CopyDataBlockBytes is called the following steps are taken:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>fromBlock</i> and <i>toBlock</i> are distinct <a
+ href="#sec-data-blocks">Data Block</a> values.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>fromIndex</i>, <i>toIndex</i>, and <i>count</i> are positive
+ integer values.</li>
+ <li>Let <i>fromSize</i> be the number of bytes in <i>fromBlock</i>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>fromIndex</i>+<i>count</i> ≤ <i>fromSize</i>.</li>
+ <li>Let <i>toSize</i> be the number of bytes in <i>toBlock</i>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>toIndex</i>+<i>count</i> ≤ <i>toSize</i>.</li>
+ <li>Repeat, while <i>count</i>>0
+ <ol class="block">
+ <li>Set <i>toBlock</i>[<i>toIndex</i>] to the value of <i>fromBlock</i>[<i>fromIndex</i>].</li>
+ <li>Increment <i>toIndex</i> and <i>fromIndex</i> each by 1.</li>
+ <li>Decrement <i>count</i> by 1.</li>
+ </ol>
+ </li>
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<span style="font-family: sans-serif">empty</span>)</li>
+ </ol>
+ </section>
+ </section>
+ </section>
+</section>
+
+<section id="sec-abstract-operations">
+ <div class="front">
+ <h1><span class="secnum" id="sec-7"><a href="#sec-abstract-operations" title="link to this section">7</a></span> Abstract
+ Operations</h1>
+
+ <p>These operations are not a part of the ECMAScript language; they are defined here to solely to aid the specification of the
+ semantics of the ECMAScript language. Other, more specialized abstract operations are defined throughout this
+ specification.</p>
+ </div>
+
+ <section id="sec-type-conversion-and-testing">
+ <div class="front">
+ <h1><span class="secnum" id="sec-7.1"><a href="#sec-type-conversion-and-testing" title="link to this section">7.1</a></span>
+ Type Conversion and Testing</h1>
+
+ <p>The ECMAScript language implicitly performs automatic type conversion as needed. To clarify the semantics of certain
+ constructs it is useful to define a set of conversion abstract operations. The conversion abstract operations are
+ polymorphic; they can accept a value of any <a href="#sec-ecmascript-language-types">ECMAScript language type</a> or of a <a
+ href="#sec-completion-record-specification-type">Completion Record</a> value. But no other specification types are used
+ with these operations.</p>
+ </div>
+
+ <section id="sec-toprimitive">
+ <h1><span class="secnum" id="sec-7.1.1"><a href="#sec-toprimitive" title="link to this section">7.1.1</a></span>
+ ToPrimitive</h1>
+
+ <p>The abstract operation ToPrimitive takes an <var>input</var> argument and an optional argument <span
+ class="nt">PreferredType</span>. The abstract operation ToPrimitive converts its <var>input</var> argument to a non-Object
+ type. If an object is capable of converting to more than one primitive type, it may use the optional hint <span
+ class="nt">PreferredType</span> to favour that type. Conversion occurs according to <a href="#table-9">Table 9</a>:</p>
+
+ <figure>
+ <figcaption><span id="table-9">Table 9</span> — ToPrimitive Conversions</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-top: 2px solid #000000">Input Type</th>
+ <th style="border-bottom: 1px solid #000000; border-right: 1px solid #000000; border-top: 2px solid #000000">Result</th>
+ </tr>
+ <tr>
+ <td><a href="#sec-completion-record-specification-type">Completion Record</a></td>
+ <td>If <var>input</var> is an <a href="#sec-completion-record-specification-type">abrupt completion</a>, return <var>input</var>. Otherwise return ToPrimitive(<var>input</var>.[[value]]) also passing the optional hint <span class="nt">PreferredType</span>.</td>
+ </tr>
+ <tr>
+ <td>Undefined</td>
+ <td>Return <var>input</var> (no conversion).</td>
+ </tr>
+ <tr>
+ <td>Null</td>
+ <td>Return <var>input</var> (no conversion).</td>
+ </tr>
+ <tr>
+ <td>Boolean</td>
+ <td>Return <var>input</var> (no conversion).</td>
+ </tr>
+ <tr>
+ <td>Number</td>
+ <td>Return <var>input</var> (no conversion).</td>
+ </tr>
+ <tr>
+ <td>String</td>
+ <td>Return <var>input</var> (no conversion).</td>
+ </tr>
+ <tr>
+ <td>Symbol</td>
+ <td>Return <var>input</var> (no conversion).</td>
+ </tr>
+ <tr>
+ <td>Object</td>
+ <td>Perform the steps following this table.</td>
+ </tr>
+ </table>
+ </figure>
+
+ <p>When <span style="font-family: Times New Roman"><a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>input</i>)</span> is Object, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>If <i>PreferredType</i> was not passed, let <i>hint</i> be "<code>default</code>".</li>
+ <li>Else if <i>PreferredType</i> is hint String, let <i>hint</i> be "<code>string</code>".</li>
+ <li>Else <i>PreferredType</i> is hint Number, let <i>hint</i> be "<code>number</code>".</li>
+ <li>Let <i>exoticToPrim</i> be <a href="#sec-getmethod">GetMethod</a>(<i>input</i>, @@toPrimitive).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>exoticToPrim</i>).</li>
+ <li>If <i>exoticToPrim</i> is not <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>result</i> be the result of calling the [[Call]] internal method of <i>exoticToPrim</i>, with <i>input</i>
+ as <i>thisArgument</i> and (<i>hint</i>) as <i>argumentsList</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>result</i>).</li>
+ <li>If <i>result</i> is an <a href="#sec-ecmascript-language-types">ECMAScript language value</a> and <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>result</i>) is not Object, then return
+ <i>result</i>.</li>
+ <li>Else, throw a <b>TypeError</b> exception.</li>
+ </ol>
+ </li>
+ <li>If <i>hint</i> is "<code>default</code>" then, let <i>hint</i> be "<code>number</code>".</li>
+ <li>Return OrdinaryToPrimitive(<i>input,hint</i>).</li>
+ </ol>
+
+ <p>When the abstract operation OrdinaryToPrimitive is called with arguments <var>O</var> and <var>hint</var>, the following
+ steps are taken:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is
+ Object</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>hint</i>)
+ is String and its value is either "<code>string</code>" or "<code>number</code>".</li>
+ <li>If <i>hint</i> is "<code>string</code>", then
+ <ol class="block">
+ <li>Let <i>methodNames</i> be the <a href="#sec-list-and-record-specification-type">List</a> (
+ "<code>toString</code>", "<code>valueOf</code>").</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>methodNames</i> be the <a href="#sec-list-and-record-specification-type">List</a> ( "<code>valueOf</code>",
+ "<code>toString</code>").</li>
+ </ol>
+ </li>
+ <li>For each <i>name</i> in <i>methodNames</i> in <a href="#sec-list-and-record-specification-type">List</a> order, do
+ <ol class="block">
+ <li>Let <i>method</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <i>name</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>method</i>).</li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>method)</i> is <b>true</b> then,
+ <ol class="block">
+ <li>Let <i>result</i> be the result of calling the [[Call]] internal method of <i>method</i>, with <i>O</i> as
+ <i>thisArgument</i> and an empty <a href="#sec-list-and-record-specification-type">List</a> as
+ <i>argumentsList</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>result</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>result</i>) is not Object, then return
+ <i>result</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Throw a <b>TypeError</b> exception.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> When ToPrimitive is called with no hint, then it generally behaves as if the hint were
+ Number. However, objects may over-ride this behaviour by defining a @@toPrimitive method. Of the objects defined in this
+ specification only Date objects (<a href="#sec-date-objects">see 20.3</a>) and Symbol objects (<a
+ href="#sec-symbol.prototype-@@toprimitive">see 19.4.3.4</a>) over-ride the default ToPrimitive behaviour. Date objects
+ treat no hint as if the hint were String.</p>
+ </div>
+ </section>
+
+ <section id="sec-toboolean">
+ <h1><span class="secnum" id="sec-7.1.2"><a href="#sec-toboolean" title="link to this section">7.1.2</a></span>
+ ToBoolean</h1>
+
+ <p>The abstract operation ToBoolean converts its <i>argument</i> to a value of type Boolean according to <a
+ href="#table-10">Table 10</a>:</p>
+
+ <figure>
+ <figcaption><span id="table-10">Table 10</span> — ToBoolean Conversions</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-top: 2px solid #000000">Argument Type</th>
+ <th style="border-bottom: 1px solid #000000; border-right: 1px solid #000000; border-top: 2px solid #000000">Result</th>
+ </tr>
+ <tr>
+ <td><a href="#sec-completion-record-specification-type">Completion Record</a></td>
+ <td>If <i>argument</i> is an <a href="#sec-completion-record-specification-type">abrupt completion</a>, return the argument. Otherwise return ToBoolean(<i>argument</i>.[[value]])</td>
+ </tr>
+ <tr>
+ <td>Undefined</td>
+ <td>Return <b>false</b></td>
+ </tr>
+ <tr>
+ <td>Null</td>
+ <td>Return <b>false</b></td>
+ </tr>
+ <tr>
+ <td>Boolean</td>
+ <td>Return the input argument (no conversion).</td>
+ </tr>
+ <tr>
+ <td>Number</td>
+ <td>Return <b>false</b> if the argument is <b>+0</b>, <b>−0</b>, or <b>NaN</b>; otherwise return <b>true</b>.</td>
+ </tr>
+ <tr>
+ <td>String</td>
+ <td>Return <b>false</b> if the argument is the empty String (its length is zero); otherwise return <b>true</b>.</td>
+ </tr>
+ <tr>
+ <td>Symbol</td>
+ <td>Return <b>true</b></td>
+ </tr>
+ <tr>
+ <td>Object</td>
+ <td>Return <b>true</b></td>
+ </tr>
+ </table>
+ </figure>
+ </section>
+
+ <section id="sec-tonumber">
+ <div class="front">
+ <h1><span class="secnum" id="sec-7.1.3"><a href="#sec-tonumber" title="link to this section">7.1.3</a></span>
+ ToNumber</h1>
+
+ <p>The abstract operation ToNumber converts its <i>argument</i> to a value of type Number according to <a
+ href="#table-11">Table 11</a>:</p>
+
+ <figure>
+ <figcaption><span id="table-11">Table 11</span> — ToNumber Conversions</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-top: 2px solid #000000">Argument Type</th>
+ <th style="border-bottom: 1px solid #000000; border-right: 1px solid #000000; border-top: 2px solid #000000">Result</th>
+ </tr>
+ <tr>
+ <td><a href="#sec-completion-record-specification-type">Completion Record</a></td>
+ <td>If <i>argument</i> is an <a href="#sec-completion-record-specification-type">abrupt completion</a>, return <i>argument</i>. Otherwise return ToNumber(<i>argument</i>.[[value]])</td>
+ </tr>
+ <tr>
+ <td>Undefined</td>
+ <td>Return <b>NaN</b></td>
+ </tr>
+ <tr>
+ <td>Null</td>
+ <td>Return <b>+0</b></td>
+ </tr>
+ <tr>
+ <td>Boolean</td>
+ <td>Return <b>1</b> if <i>argument</i> is <b>true</b>. Return <b>+0</b> if <i>argument</i> is <b>false</b>.</td>
+ </tr>
+ <tr>
+ <td>Number</td>
+ <td>Return <i>argument</i> (no conversion).</td>
+ </tr>
+ <tr>
+ <td>String</td>
+ <td>See grammar and conversion algorithm below.</td>
+ </tr>
+ <tr>
+ <td>Symbol</td>
+ <td>Return <b>NaN</b></td>
+ </tr>
+ <tr>
+ <td>Object</td>
+
+ <td>
+ <p>Apply the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>primValue</i> be <a href="#sec-toprimitive">ToPrimitive</a>(<i>argument</i>, hint Number).</li>
+ <li>Return ToNumber(<i>primValue</i>).</li>
+ </ol>
+ </td>
+ </tr>
+ </table>
+ </figure>
+ </div>
+
+ <section id="sec-tonumber-applied-to-the-string-type">
+ <div class="front">
+ <h1><span class="secnum" id="sec-7.1.3.1"><a href="#sec-tonumber-applied-to-the-string-type"
+ title="link to this section">7.1.3.1</a></span> ToNumber Applied to the String Type</h1>
+
+ <p><a href="#sec-tonumber">ToNumber</a> applied to Strings applies the following grammar to the input String. If the
+ grammar cannot interpret the String as an expansion of <span class="nt">StringNumericLiteral</span>, then the result of
+ <a href="#sec-tonumber">ToNumber</a> is <b>NaN</b>.</p>
+
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">StringNumericLiteral</span> <span class="geq">:::</span></div>
+ <div class="rhs"><span class="nt">StrWhiteSpace</span><sub>opt</sub></div>
+ <div class="rhs"><span class="nt">StrWhiteSpace</span><sub>opt</sub> <span class="nt">StrNumericLiteral</span> <span class="nt">StrWhiteSpace</span><sub>opt</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">StrWhiteSpace</span> <span class="geq">:::</span></div>
+ <div class="rhs"><span class="nt">StrWhiteSpaceChar</span> <span class="nt">StrWhiteSpace</span><sub>opt</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">StrWhiteSpaceChar</span> <span class="geq">:::</span></div>
+ <div class="rhs"><span class="nt">WhiteSpace</span></div>
+ <div class="rhs"><span class="nt">LineTerminator</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">StrNumericLiteral</span> <span class="geq">:::</span></div>
+ <div class="rhs"><span class="nt">StrDecimalLiteral</span></div>
+ <div class="rhs"><span class="nt">HexIntegerLiteral</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">StrDecimalLiteral</span> <span class="geq">:::</span></div>
+ <div class="rhs"><span class="nt">StrUnsignedDecimalLiteral</span></div>
+ <div class="rhs"><code class="t">+</code> <span class="nt">StrUnsignedDecimalLiteral</span></div>
+ <div class="rhs"><code class="t">-</code> <span class="nt">StrUnsignedDecimalLiteral</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">StrUnsignedDecimalLiteral</span> <span class="geq">:::</span></div>
+ <div class="rhs"><span class="nt">Infinity</span></div>
+ <div class="rhs"><span class="nt">DecimalDigits</span> <code class="t">.</code> <span class="nt">DecimalDigits</span><sub>opt</sub> <span class="nt">ExponentPart</span><sub>opt</sub></div>
+ <div class="rhs"><code class="t">.</code> <span class="nt">DecimalDigits</span> <span class="nt">ExponentPart</span><sub>opt</sub></div>
+ <div class="rhs"><span class="nt">DecimalDigits</span> <span class="nt">ExponentPart</span><sub>opt</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">DecimalDigits</span> <span class="geq">:::</span></div>
+ <div class="rhs"><span class="nt">DecimalDigit</span></div>
+ <div class="rhs"><span class="nt">DecimalDigits</span> <span class="nt">DecimalDigit</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">DecimalDigit</span> <span class="geq">:::</span> <span class="grhsmod">one of</span></div>
+ <div class="rhs"><code class="t">0</code> <code class="t">1</code> <code class="t">2</code> <code class="t">3</code> <code class="t">4</code> <code class="t">5</code> <code class="t">6</code> <code class="t">7</code> <code class="t">8</code> <code class="t">9</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ExponentPart</span> <span class="geq">:::</span></div>
+ <div class="rhs"><span class="nt">ExponentIndicator</span> <span class="nt">SignedInteger</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ExponentIndicator</span> <span class="geq">:::</span> <span class="grhsmod">one of</span></div>
+ <div class="rhs"><code class="t">e</code> <code class="t">E</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">SignedInteger</span> <span class="geq">:::</span></div>
+ <div class="rhs"><span class="nt">DecimalDigits</span></div>
+ <div class="rhs"><code class="t">+</code> <span class="nt">DecimalDigits</span></div>
+ <div class="rhs"><code class="t">-</code> <span class="nt">DecimalDigits</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">HexIntegerLiteral</span> <span class="geq">:::</span></div>
+ <div class="rhs"><code class="t">0x</code> <span class="nt">HexDigit</span></div>
+ <div class="rhs"><code class="t">0X</code> <span class="nt">HexDigit</span></div>
+ <div class="rhs"><span class="nt">HexIntegerLiteral</span> <span class="nt">HexDigit</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">HexDigit</span> <span class="geq">:::</span> <span class="grhsmod">one of</span></div>
+ <div class="rhs"><code class="t">0</code> <code class="t">1</code> <code class="t">2</code> <code class="t">3</code> <code class="t">4</code> <code class="t">5</code> <code class="t">6</code> <code class="t">7</code> <code class="t">8</code> <code class="t">9</code> <code class="t">a</code> <code class="t">b</code> <code class="t">c</code> <code class="t">d</code> <code class="t">e</code> <code class="t">f</code> <code class="t">A</code> <code class="t">B</code> <code class="t">C</code> <code class="t">D</code> <code class="t">E</code> <code class="t">F</code></div>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Some differences should be noted between the syntax of a <i>StringNumericLiteral</i>
+ and a <i>NumericLiteral</i> (<a href="#sec-literals-numeric-literals">see 11.8.3</a>):</p>
+
+ <ul>
+ <li>
+ <p>A <i>StringNumericLiteral</i> may include leading and/or trailing white space and/or line terminators.</p>
+ </li>
+
+ <li>
+ <p>A <i>StringNumericLiteral</i> that is decimal may have any number of leading <code>0</code> digits.</p>
+ </li>
+
+ <li>
+ <p>A <i>StringNumericLiteral</i> that is decimal may include a <code>+</code> or <code>-</code> to indicate its
+ sign.</p>
+ </li>
+
+ <li>
+ <p>A <i>StringNumericLiteral</i> that is empty or contains only white space is converted to <b>+0</b>.</p>
+ </li>
+
+ <li>
+ <p><code>Infinity</code> <code>and –Infinity</code> are recognized as a <i>StringNumericLiteral</i> but not
+ as a <i>NumericLiteral</i>.</p>
+ </li>
+ </ul>
+ </div>
+ </div>
+
+ <section id="sec-runtime-semantics-mv-s">
+ <h1><span class="secnum" id="sec-7.1.3.1.1"><a href="#sec-runtime-semantics-mv-s"
+ title="link to this section">7.1.3.1.1</a></span> Runtime Semantics: MV’s</h1>
+
+ <p>The conversion of a String to a Number value is similar overall to the determination of the Number value for a
+ numeric literal (<a href="#sec-literals-numeric-literals">see 11.8.3</a>), but some of the details are different, so the
+ process for converting a String numeric literal to a value of Number type is given here in full. This value is
+ determined in two steps: first, a mathematical value (MV) is derived from the String numeric literal; second, this
+ mathematical value is rounded as described below.</p>
+
+ <ul>
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">StringNumericLiteral</span> <span class="geq">:::</span> <span
+ class="grhsannot">[empty]</span></span> is 0.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">StringNumericLiteral</span> <span class="geq">:::</span> <span
+ class="nt">StrWhiteSpace</span></span> is 0.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">StringNumericLiteral</span> <span class="geq">:::</span> <span
+ class="nt">StrWhiteSpace</span><sub>opt</sub> <span class="nt">StrNumericLiteral</span> <span
+ class="nt">StrWhiteSpace</span><sub>opt</sub></span> is the MV of <span class="nt">StrNumericLiteral</span>, no
+ matter whether white space is present or not.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">StrNumericLiteral</span> <span class="geq">:::</span> <span
+ class="nt">StrDecimalLiteral</span></span> is the MV of <span class="nt">StrDecimalLiteral</span>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">StrNumericLiteral</span> <span class="geq">:::</span> <span
+ class="nt">HexIntegerLiteral</span></span> is the MV of <span class="nt">HexIntegerLiteral</span>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">StrDecimalLiteral</span> <span class="geq">:::</span> <span
+ class="nt">StrUnsignedDecimalLiteral</span></span> is the MV of <span
+ class="nt">StrUnsignedDecimalLiteral</span>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">StrDecimalLiteral</span> <span class="geq">:::</span> <code
+ class="t">+</code> <span class="nt">StrUnsignedDecimalLiteral</span></span> is the MV of <span
+ class="nt">StrUnsignedDecimalLiteral</span>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">StrDecimalLiteral</span> <span class="geq">:::</span> <code
+ class="t">-</code> <span class="nt">StrUnsignedDecimalLiteral</span></span> is the negative of the MV of <span
+ class="nt">StrUnsignedDecimalLiteral</span>. (Note that if the MV of <span
+ class="nt">StrUnsignedDecimalLiteral</span> is 0, the negative of this MV is also 0. The rounding rule described
+ below handles the conversion of this signless mathematical zero to a floating-point <b>+0</b> or <b>−0</b> as
+ appropriate.)</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">StrUnsignedDecimalLiteral</span> <span class="geq">:::</span> <span
+ class="nt">Infinity</span></span> is <span style="font-family: Times New Roman">10<sup>10000</sup></span> (a value
+ so large that it will round to <b>+∞</b>).</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">StrUnsignedDecimalLiteral</span> <span class="geq">:::</span> <span
+ class="nt">DecimalDigits</span> <code class="t">.</code></span> is the MV of <span
+ class="nt">DecimalDigits</span>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">StrUnsignedDecimalLiteral</span> <span class="geq">:::</span> <span
+ class="nt">DecimalDigits</span> <code class="t">.</code> <span class="nt">DecimalDigits</span></span> is the MV of
+ the first <span class="nt">DecimalDigits</span> plus (the MV of the second <span class="nt">DecimalDigits</span>
+ times <span style="font-family: Times New Roman">10<sup>−<i>n</i></sup></span>), where <var>n</var> is the
+ number of characters in the second <span class="nt">DecimalDigits</span>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">StrUnsignedDecimalLiteral</span> <span class="geq">:::</span> <span
+ class="nt">DecimalDigits</span> <code class="t">.</code> <span class="nt">ExponentPart</span></span> is the MV of
+ <i>DecimalDigits</i> times 10<sup><i>e</i></sup>, where <i>e</i> is the MV of <i>ExponentPart</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">StrUnsignedDecimalLiteral</span> <span class="geq">:::</span> <span
+ class="nt">DecimalDigits</span> <code class="t">.</code> <span class="nt">DecimalDigits</span> <span
+ class="nt">ExponentPart</span></span> is (the MV of the first <i>DecimalDigits</i> plus (the MV of the second
+ <i>DecimalDigits</i> times 10<sup>−<i>n</i></sup>)) times 10<sup><i>e</i></sup>, where <i>n</i> is the number
+ of characters in the second <i>DecimalDigits</i> and <i>e</i> is the MV of <i>ExponentPart</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">StrUnsignedDecimalLiteral</span> <span class="geq">:::</span> <code
+ class="t">.</code> <span class="nt">DecimalDigits</span></span> is the MV of <i>DecimalDigits</i> times
+ 10<sup>−<i>n</i></sup>, where <i>n</i> is the number of characters in <i>DecimalDigits</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">StrUnsignedDecimalLiteral</span> <span class="geq">:::</span> <code
+ class="t">.</code> <span class="nt">DecimalDigits</span> <span class="nt">ExponentPart</span></span> is the MV of
+ <i>DecimalDigits</i> times 10<sup><i>e</i>−<i>n</i></sup>, where <i>n</i> is the number of characters in
+ <i>DecimalDigits</i> and <i>e</i> is the MV of <i>ExponentPart</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">StrUnsignedDecimalLiteral</span> <span class="geq">:::</span> <span
+ class="nt">DecimalDigits</span></span> is the MV of <i>DecimalDigits</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">StrUnsignedDecimalLiteral</span> <span class="geq">:::</span> <span
+ class="nt">DecimalDigits</span> <span class="nt">ExponentPart</span></span> is the MV of <i>DecimalDigits</i> times
+ 10<sup><i>e</i></sup>, where <i>e</i> is the MV of <i>ExponentPart</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">DecimalDigits</span> <span class="geq">:::</span> <span
+ class="nt">DecimalDigit</span></span> is the MV of <i>DecimalDigit</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">DecimalDigits</span> <span class="geq">:::</span> <span
+ class="nt">DecimalDigits</span> <span class="nt">DecimalDigit</span></span> is (the MV of <i>DecimalDigits</i> times
+ 10) plus the MV of <i>DecimalDigit</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">ExponentPart</span> <span class="geq">:::</span> <span
+ class="nt">ExponentIndicator</span> <span class="nt">SignedInteger</span></span> is the MV of
+ <i>SignedInteger</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">SignedInteger</span> <span class="geq">:::</span> <span
+ class="nt">DecimalDigits</span></span> is the MV of <i>DecimalDigits</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">SignedInteger</span> <span class="geq">:::</span> <code
+ class="t">+</code> <span class="nt">DecimalDigits</span></span> is the MV of <i>DecimalDigits</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">SignedInteger</span> <span class="geq">:::</span> <code
+ class="t">-</code> <span class="nt">DecimalDigits</span></span> is the negative of the MV of
+ <i>DecimalDigits</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">DecimalDigit</span> <span class="geq">:::</span> <code
+ class="t">0</code></span> or of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">:::</span>
+ <code class="t">0</code></span> is 0.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">DecimalDigit</span> <span class="geq">:::</span> <code
+ class="t">1</code></span> or of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">:::</span>
+ <code class="t">1</code></span> is 1.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">DecimalDigit</span> <span class="geq">:::</span> <code
+ class="t">2</code></span> or of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">:::</span>
+ <code class="t">2</code></span> is 2.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">DecimalDigit</span> <span class="geq">:::</span> <code
+ class="t">3</code></span> or of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">:::</span>
+ <code class="t">3</code></span> is 3.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">DecimalDigit</span> <span class="geq">:::</span> <code
+ class="t">4</code></span> or of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">:::</span>
+ <code class="t">4</code></span> is 4.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">DecimalDigit</span> <span class="geq">:::</span> <code
+ class="t">5</code></span> or of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">:::</span>
+ <code class="t">5</code></span> is 5.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">DecimalDigit</span> <span class="geq">:::</span> <code
+ class="t">6</code></span> or of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">:::</span>
+ <code class="t">6</code></span> is 6.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">DecimalDigit</span> <span class="geq">:::</span> <code
+ class="t">7</code></span> or of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">:::</span>
+ <code class="t">7</code></span> is 7.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">DecimalDigit</span> <span class="geq">:::</span> <code
+ class="t">8</code></span> or of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">:::</span>
+ <code class="t">8</code></span> is 8.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">DecimalDigit</span> <span class="geq">:::</span> <code
+ class="t">9</code></span> or of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">:::</span>
+ <code class="t">9</code></span> is 9.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">:::</span> <code
+ class="t">a</code></span> or of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">:::</span>
+ <code class="t">A</code></span> is 10.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">:::</span> <code
+ class="t">b</code></span> or of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">:::</span>
+ <code class="t">B</code></span> is 11.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">:::</span> <code
+ class="t">c</code></span> or of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">:::</span>
+ <code class="t">C</code></span> is 12.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">:::</span> <code
+ class="t">d</code></span> or of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">:::</span>
+ <code class="t">D</code></span> is 13.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">:::</span> <code
+ class="t">e</code></span> or of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">:::</span>
+ <code class="t">E</code></span> is 14.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">:::</span> <code
+ class="t">f</code></span> or of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">:::</span>
+ <code class="t">F</code></span> is 15.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">HexIntegerLiteral</span> <span class="geq">:::</span> <code
+ class="t">0x</code> <span class="nt">HexDigit</span></span> is the MV of <i>HexDigit</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">HexIntegerLiteral</span> <span class="geq">:::</span> <code
+ class="t">0X</code> <span class="nt">HexDigit</span></span> is the MV of <i>HexDigit</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">HexIntegerLiteral</span> <span class="geq">:::</span> <span
+ class="nt">HexIntegerLiteral</span> <span class="nt">HexDigit</span></span> is (the MV of <i>HexIntegerLiteral</i>
+ times 16) plus the MV of <i>HexDigit</i>.</p>
+ </li>
+ </ul>
+
+ <p>Once the exact MV for a String numeric literal has been determined, it is then rounded to a value of the Number type.
+ If the MV is 0, then the rounded value is +0 unless the first non white space character in the String numeric literal is
+ ‘<code>-</code>’, in which case the rounded value is −0. Otherwise, the rounded value must be the
+ Number value for the MV (in the sense defined in <a href="#sec-ecmascript-language-types-number-type">6.1.6</a>), unless
+ the literal includes a <span class="nt">StrUnsignedDecimalLiteral</span> and the literal has more than 20 significant
+ digits, in which case the Number value may be either the Number value for the MV of a literal produced by replacing each
+ significant digit after the 20th with a 0 digit or the Number value for the MV of a literal produced by replacing each
+ significant digit after the 20th with a 0 digit and then incrementing the literal at the 20th digit position. A digit is
+ <i>significant</i> if it is not part of an <span class="nt">ExponentPart</span> and</p>
+
+ <ul>
+ <li>it is not <b>0</b>; or</li>
+ <li>there is a nonzero digit to its left and there is a nonzero digit, not in the <span
+ class="nt">ExponentPart</span>, to its right.</li>
+ </ul>
+ </section>
+ </section>
+ </section>
+
+ <section id="sec-tointeger">
+ <h1><span class="secnum" id="sec-7.1.4"><a href="#sec-tointeger" title="link to this section">7.1.4</a></span>
+ ToInteger</h1>
+
+ <p>The abstract operation ToInteger converts its <var>argument</var> to an integral numeric value. This abstract operation
+ functions as follows:</p>
+
+ <ol class="proc">
+ <li>Let <i>number</i> be <a href="#sec-tonumber">ToNumber</a>(<i>argument</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>number</i>).</li>
+ <li>If <i>number</i> is <b>NaN</b>, return <b>+0</b>.</li>
+ <li>If <i>number</i> is <b>+0</b>, <b>−0</b>, <b>+∞,</b> or <b>−∞</b>, return <i>number</i>.</li>
+ <li>Return the result of computing <a href="#sec-algorithm-conventions">sign</a>(<i>number</i>) × <a
+ href="#sec-algorithm-conventions">floor</a>(<a href="#sec-algorithm-conventions">abs</a>(<i>number</i>)).</li>
+ </ol>
+ </section>
+
+ <section id="sec-toint32">
+ <h1><span class="secnum" id="sec-7.1.5"><a href="#sec-toint32" title="link to this section">7.1.5</a></span> ToInt32:
+ (Signed 32 Bit Integer)</h1>
+
+ <p>The abstract operation ToInt32 converts its <var>argument</var> to one of <span style="font-family: Times New
+ Roman">2<sup>32</sup></span> integer values in the range <span style="font-family: Times New
+ Roman">−2<sup>31</sup></span> through <span style="font-family: Times New Roman">2<sup>31</sup>−1</span>,
+ inclusive. This abstract operation functions as follows:</p>
+
+ <ol class="proc">
+ <li>Let <i>number</i> be <a href="#sec-tonumber">ToNumber</a>(<i>argument</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>number</i>).</li>
+ <li>If <i>number</i> is <b>NaN</b>, <b>+0</b>, <b>−0</b>, <b>+∞</b>, or <b>−∞</b>, return
+ <b>+0</b>.</li>
+ <li>Let <i>int</i> be <a href="#sec-algorithm-conventions">sign</a>(<i>number</i>) × <a
+ href="#sec-algorithm-conventions">floor</a>(<a href="#sec-algorithm-conventions">abs</a>(<i>number</i>)).</li>
+ <li>Let <i>int32bit</i> be <i>int</i> <a href="#sec-algorithm-conventions">modulo</a> 2<sup>32</sup>.</li>
+ <li>If <i>int32bit</i> ≥ 2<sup>31</sup>, return <i>int32bit</i> − 2<sup>32</sup>, otherwise return
+ <i>int32bit</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Given the above definition of ToInt32:</p>
+
+ <ul>
+ <li>
+ <p>The ToInt32 abstract operation is idempotent: if applied to a result that it produced, the second application
+ leaves that value unchanged.</p>
+ </li>
+
+ <li>
+ <p><i>ToInt32(<a href="#sec-touint32">ToUint32</a>(x))</i> is equal to ToInt32(<i>x</i>) for all values of <i>x</i>.
+ (It is to preserve this latter property that +<b>∞</b> and −<b>∞</b> are mapped to <b>+0</b>.)</p>
+ </li>
+
+ <li>
+ <p>ToInt32 maps <b>−0</b> to <b>+0</b>.</p>
+ </li>
+ </ul>
+ </div>
+ </section>
+
+ <section id="sec-touint32">
+ <h1><span class="secnum" id="sec-7.1.6"><a href="#sec-touint32" title="link to this section">7.1.6</a></span> ToUint32:
+ (Unsigned 32 Bit Integer)</h1>
+
+ <p>The abstract operation ToUint32 converts its <var>argument</var> to one of <span style="font-family: Times New
+ Roman">2<sup>32</sup></span> integer values in the range <span style="font-family: Times New Roman">0</span> through <span
+ style="font-family: Times New Roman">2<sup>32</sup>−1</span>, inclusive. This abstract operation functions as
+ follows:</p>
+
+ <ol class="proc">
+ <li>Let <i>number</i> be <a href="#sec-tonumber">ToNumber</a>(<i>argument</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>number</i>).</li>
+ <li>If <i>number</i> is <b>NaN</b>, +0, −0, +<b>∞</b>, or −<b>∞</b>, return <b>+0</b>.</li>
+ <li>Let <i>int</i> be <a href="#sec-algorithm-conventions">sign</a>(<i>number</i>) × <a
+ href="#sec-algorithm-conventions">floor</a>(<a href="#sec-algorithm-conventions">abs</a>(<i>number</i>)).</li>
+ <li>Let <i>int32bit</i> be <i>int</i> <a href="#sec-algorithm-conventions">modulo</a> 2<sup>32</sup>.</li>
+ <li>Return <i>int32bit</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Given the above definition of ToUint32:</p>
+
+ <ul>
+ <li>
+ <p>Step 6 is the only difference between ToUint32 and <a href="#sec-toint32">ToInt32</a>.</p>
+ </li>
+
+ <li>
+ <p>The ToUint32 abstract operation is idempotent: if applied to a result that it produced, the second application
+ leaves that value unchanged.</p>
+ </li>
+
+ <li>
+ <p>ToUint32(<a href="#sec-toint32">ToInt32</a>(<i>x</i>)) is equal to ToUint32(<i>x</i>) for all values of <i>x</i>.
+ (It is to preserve this latter property that <b>+∞</b> and <b>−∞</b> are mapped to <b>+0</b>.)</p>
+ </li>
+
+ <li>
+ <p>ToUint32 maps <b>−0</b> to <b>+0</b>.</p>
+ </li>
+ </ul>
+ </div>
+ </section>
+
+ <section id="sec-toint16">
+ <h1><span class="secnum" id="sec-7.1.7"><a href="#sec-toint16" title="link to this section">7.1.7</a></span> ToInt16:
+ (Signed 16 Bit Integer)</h1>
+
+ <p>The abstract operation ToInt16 converts its <var>argument</var> to one of <span style="font-family: Times New
+ Roman">2<sup>16</sup></span> integer values in the range <span style="font-family: Times New Roman">−32768</span>
+ through <span style="font-family: Times New Roman">32767</span>, inclusive. This abstract operation functions as
+ follows:</p>
+
+ <ol class="proc">
+ <li>Let <i>number</i> be <a href="#sec-tonumber">ToNumber</a>(<i>argument</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>number</i>).</li>
+ <li>If <i>number</i> is <b>NaN</b>, <b>+0</b>, <b>−0</b>, <b>+∞</b>, or <b>−∞</b>, return
+ <b>+0</b>.</li>
+ <li>Let <i>int</i> be <a href="#sec-algorithm-conventions">sign</a>(<i>number</i>) × <a
+ href="#sec-algorithm-conventions">floor</a>(<a href="#sec-algorithm-conventions">abs</a>(<i>number</i>)).</li>
+ <li>Let <i>int16bit</i> be <i>int</i> <a href="#sec-algorithm-conventions">modulo</a> 2<sup>16</sup>.</li>
+ <li>If <i>int16bit</i> ≥ 2<sup>15</sup>, return <i>int16bit</i> − 2<sup>16</sup>, otherwise return
+ <i>int16bit</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-touint16">
+ <h1><span class="secnum" id="sec-7.1.8"><a href="#sec-touint16" title="link to this section">7.1.8</a></span> ToUint16:
+ (Unsigned 16 Bit Integer)</h1>
+
+ <p>The abstract operation ToUint16 converts its <var>argument</var> to one of <span style="font-family: Times New
+ Roman">2<sup>16</sup></span> integer values in the range <span style="font-family: Times New Roman">0</span> through <span
+ style="font-family: Times New Roman">2<sup>16</sup>−1</span>, inclusive. This abstract operation functions as
+ follows:</p>
+
+ <ol class="proc">
+ <li>Let <i>number</i> be <a href="#sec-tonumber">ToNumber</a>(<i>argument</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>number</i>).</li>
+ <li>If <i>number</i> is <b>NaN</b>, +0, −0, +<b>∞</b>, or −<b>∞</b>, return <b>+0</b>.</li>
+ <li>Let <i>int</i> be <a href="#sec-algorithm-conventions">sign</a>(<i>number</i>) × <a
+ href="#sec-algorithm-conventions">floor</a>(<a href="#sec-algorithm-conventions">abs</a>(<i>number</i>)).</li>
+ <li>Let <i>int16bit</i> be <i>int</i> <a href="#sec-algorithm-conventions">modulo</a> 2<sup>16</sup>.</li>
+ <li>Return <i>int16bit</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Given the above definition of ToUint16:</p>
+
+ <ul>
+ <li>The substitution of 2<sup>16</sup> for 2<sup>32</sup> in step 5 is the only difference between <a
+ href="#sec-touint32">ToUint32</a> and ToUint16.</li>
+ <li>ToUint16 maps <b>−0</b> to <span style="font-family: sans-serif"><b>+0</b></span>.</li>
+ </ul>
+ </div>
+ </section>
+
+ <section id="sec-toint8">
+ <h1><span class="secnum" id="sec-7.1.9"><a href="#sec-toint8" title="link to this section">7.1.9</a></span> ToInt8: (Signed
+ 8 Bit Integer)</h1>
+
+ <p>The abstract operation ToInt8 converts its <var>argument</var> to one of <span style="font-family: Times New
+ Roman">2<sup>8</sup></span> integer values in the range <span style="font-family: Times New Roman">−128</span> through
+ <span style="font-family: Times New Roman">127</span>, inclusive. This abstract operation functions as follows:</p>
+
+ <ol class="proc">
+ <li>Let <i>number</i> be <a href="#sec-tonumber">ToNumber</a>(<i>argument</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>number</i>).</li>
+ <li>If <i>number</i> is <b>NaN</b>, <b>+0</b>, <b>−0</b>, <b>+∞</b>, or <b>−∞</b>, return
+ <b>+0</b>.</li>
+ <li>Let <i>int</i> be <a href="#sec-algorithm-conventions">sign</a>(<i>number</i>) × <a
+ href="#sec-algorithm-conventions">floor</a>(<a href="#sec-algorithm-conventions">abs</a>(<i>number</i>)).</li>
+ <li>Let <i>int8bit</i> be <i>int</i> <a href="#sec-algorithm-conventions">modulo</a> 2<sup>8</sup>.</li>
+ <li>If <i>int8bit</i> ≥ 2<sup>7</sup>, return <i>int8bit</i> − 2<sup>8</sup>, otherwise return
+ <i>int8bit</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-touint8">
+ <h1><span class="secnum" id="sec-7.1.10"><a href="#sec-touint8" title="link to this section">7.1.10</a></span> ToUint8:
+ (Unsigned 8 Bit Integer)</h1>
+
+ <p>The abstract operation ToUint8 converts its <var>argument</var> to one of <span style="font-family: Times New
+ Roman">2<sup>8</sup></span> integer values in the range <span style="font-family: Times New Roman">0</span> through <span
+ style="font-family: Times New Roman">255</span>, inclusive. This abstract operation functions as follows:</p>
+
+ <ol class="proc">
+ <li>Let <i>number</i> be <a href="#sec-tonumber">ToNumber</a>(<i>argument</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>number</i>).</li>
+ <li>If <i>number</i> is <b>NaN</b>, +0, −0, +<b>∞</b>, or −<b>∞</b>, return <b>+0</b>.</li>
+ <li>Let <i>int</i> be <a href="#sec-algorithm-conventions">sign</a>(<i>number</i>) × <a
+ href="#sec-algorithm-conventions">floor</a>(<a href="#sec-algorithm-conventions">abs</a>(<i>number</i>)).</li>
+ <li>Let <i>int8bit</i> be <i>int</i> <a href="#sec-algorithm-conventions">modulo</a> 2<sup>8</sup>.</li>
+ <li>Return <i>int8bit</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-touint8clamp">
+ <h1><span class="secnum" id="sec-7.1.11"><a href="#sec-touint8clamp" title="link to this section">7.1.11</a></span>
+ ToUint8Clamp: (Unsigned 8 Bit Integer, Clamped)</h1>
+
+ <p>The abstract operation ToUint8Clamp converts its <var>argument</var> to one of <span style="font-family: Times New
+ Roman">2<sup>8</sup></span> integer values in the range <span style="font-family: Times New Roman">0</span> through <span
+ style="font-family: Times New Roman">255</span>, inclusive. This abstract operation functions as follows:</p>
+
+ <ol class="proc">
+ <li>Let <i>number</i> be <a href="#sec-tonumber">ToNumber</a>(<i>argument</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>number</i>).</li>
+ <li>If <i>number</i> is <b>NaN</b>, return <b>+0</b>.</li>
+ <li>If <i>number</i> ≤ 0, return <b>+0</b>.</li>
+ <li>If <i>number</i> ≥ 255, return 255.</li>
+ <li>Let <i>f</i> be <a href="#sec-algorithm-conventions">floor</a>(<i>number</i>).</li>
+ <li>If <i>f</i> <i>+</i> 0.5 < <i>number</i>, then return <i>f</i> + 1.</li>
+ <li>If <i>number</i> < <i>f +</i> 0.5, then return <i>f</i>.</li>
+ <li>If <i>f</i> is odd, then return <i>f</i> + 1.</li>
+ <li>Return <i>f</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Note that unlike the other ECMAScript integer conversion abstract operation, ToUint8Clamp
+ rounds rather than truncates non-integer values and does not convert +<b>∞</b> to 0. ToUint8Clamp does “round
+ half to even” tie-breaking. This differs from <code><a href="#sec-math.round">Math.round</a></code> which does
+ “round half up” tie-breaking.</p>
+ </div>
+ </section>
+
+ <section id="sec-tostring">
+ <div class="front">
+ <h1><span class="secnum" id="sec-7.1.12"><a href="#sec-tostring" title="link to this section">7.1.12</a></span>
+ ToString</h1>
+
+ <p>The abstract operation ToString converts its <i>argument</i> to a value of type String according to <a
+ href="#table-12">Table 12</a>:</p>
+
+ <figure>
+ <figcaption><span id="table-12">Table 12</span> — ToString Conversions</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-top: 2px solid #000000">Argument Type</th>
+ <th style="border-bottom: 1px solid #000000; border-right: 1px solid #000000; border-top: 2px solid #000000">Result</th>
+ </tr>
+ <tr>
+ <td><a href="#sec-completion-record-specification-type">Completion Record</a></td>
+ <td>If <i>argument</i> is an <a href="#sec-completion-record-specification-type">abrupt completion</a>, return <i>argument</i>. Otherwise return ToString(<i>argument</i>.[[value]])</td>
+ </tr>
+ <tr>
+ <td>Undefined</td>
+ <td><code>"undefined"</code></td>
+ </tr>
+ <tr>
+ <td>Null</td>
+ <td><code>"null"</code></td>
+ </tr>
+ <tr>
+ <td>Boolean</td>
+
+ <td>
+ <p>If <i>argument</i> is <b>true</b>, then return <code>"true"</code>.</p>
+
+ <p>If <i>argument</i> is <b>false</b>, then return <b><code>"false"</code>.</b></p>
+ </td>
+ </tr>
+ <tr>
+ <td>Number</td>
+ <td>See <a href="#sec-tostring-applied-to-the-number-type">7.1.12.1</a>.</td>
+ </tr>
+ <tr>
+ <td>String</td>
+ <td>Return <i>argument</i> (no conversion)</td>
+ </tr>
+ <tr>
+ <td>Symbol</td>
+ <td>Throw a <b>TypeError</b> exception.</td>
+ </tr>
+ <tr>
+ <td>Object</td>
+
+ <td>
+ <p>Apply the following steps:</p>
+
+ <p>1. Let <i>primValue</i> be <a href="#sec-toprimitive">ToPrimitive</a>(<i>argument</i>, hint String).</p>
+
+ <p>2. Return ToString(<i>primValue</i>).</p>
+ </td>
+ </tr>
+ </table>
+ </figure>
+ </div>
+
+ <section id="sec-tostring-applied-to-the-number-type">
+ <h1><span class="secnum" id="sec-7.1.12.1"><a href="#sec-tostring-applied-to-the-number-type"
+ title="link to this section">7.1.12.1</a></span> ToString Applied to the Number Type</h1>
+
+ <p>The abstract operation <a href="#sec-tostring">ToString</a> converts a Number <var>m</var> to String format as
+ follows:</p>
+
+ <ol class="proc">
+ <li>If <i>m</i> is <b>NaN</b>, return the String <code>"NaN"</code>.</li>
+ <li>If <i>m</i> is <b>+0</b> or <b>−0</b>, return the String <code>"0"</code>.</li>
+ <li>If <i>m</i> is less than zero, return the String concatenation of the String <code>"-"</code> and <a
+ href="#sec-tostring">ToString</a>(−<i>m</i>).</li>
+ <li>If <i>m</i> is +∞, return the String <code>"Infinity"</code>.</li>
+ <li>Otherwise, let <i>n</i>, <i>k</i>, and <i>s</i> be integers such that <i>k</i> ≥ 1, 10<sup><i>k</i>−1</sup>
+ ≤ <i>s</i> < 10<sup><i>k</i></sup>, the Number value for <i>s</i> × 10<sup><i>n−k</i></sup> is
+ <i>m</i>, and <i>k</i> is as small as possible. Note that <i>k</i> is the number of digits in the decimal
+ representation of <i>s</i>, that <i>s</i> is not divisible by 10, and that the least significant digit of <i>s</i>
+ is not necessarily uniquely determined by these criteria.</li>
+ <li>If <i>k</i> ≤ <i>n</i> ≤ 21, return the String consisting of the <i>k</i> digits of the decimal representation
+ of <i>s</i> (in order, with no leading zeroes), followed by <i>n−k</i> occurrences of the character
+ ‘<code>0</code>’.</li>
+ <li>If 0 < <i>n</i> ≤ 21, return the String consisting of the most significant <i>n</i> digits of the decimal
+ representation of <i>s</i>, followed by a decimal point ‘<code>.</code>’, followed by the remaining
+ <i>k−n</i> digits of the decimal representation of <i>s</i>.</li>
+ <li>If −6 < <i>n</i> ≤ 0, return the String consisting of the character ‘<code>0</code>’,
+ followed by a decimal point ‘<code>.</code>’, followed by −<i>n</i> occurrences of the character
+ ‘<code>0</code>’, followed by the <i>k</i> digits of the decimal representation of <i>s</i>.</li>
+ <li>Otherwise, if <i>k</i> = 1, return the String consisting of the single digit of <i>s</i>, followed by lowercase
+ character ‘<code>e</code>’, followed by a plus sign ‘<code>+</code>’ or minus sign
+ ‘<code>−</code>’ according to whether <i>n</i>−1 is positive or negative, followed by the
+ decimal representation of the integer <a href="#sec-algorithm-conventions">abs</a>(<i>n</i>−1) (with no
+ leading zeroes).</li>
+ <li>Return the String consisting of the most significant digit of the decimal representation of <i>s</i>, followed by a
+ decimal point ‘.’, followed by the remaining <i>k</i>−1 digits of the decimal representation of
+ <i>s</i>, followed by the lowercase character ‘<code>e</code>’, followed by a plus sign
+ ‘<code>+</code>’ or minus sign ‘<code>−</code>’ according to whether <i>n</i>−1
+ is positive or negative, followed by the decimal representation of the integer <a
+ href="#sec-algorithm-conventions">abs</a>(<i>n</i>−1) (with no leading zeroes).</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> The following observations may be useful as guidelines for implementations, but are
+ not part of the normative requirements of this Standard:</p>
+
+ <ul>
+ <li>
+ <p>If x is any Number value other than <b>−0</b>, then <a href="#sec-tonumber">ToNumber</a>(<a
+ href="#sec-tostring">ToString</a>(x)) is exactly the same Number value as x.</p>
+ </li>
+
+ <li>
+ <p>The least significant digit of s is not always uniquely determined by the requirements listed in step 5.</p>
+ </li>
+ </ul>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 2</span> For implementations that provide more accurate conversions than required by the rules
+ above, it is recommended that the following alternative version of step 5 be used as a guideline:</p>
+
+ <p>Otherwise, let <i>n</i>, <i>k</i>, and <i>s</i> be integers such that <i>k</i> ≥ 1, 10<sup><i>k</i>−1</sup>
+ ≤ <i>s</i> < 10<sup><i>k</i></sup>, the Number value for <i>s</i> × 10<sup><i>n</i>−<i>k</i></sup> is
+ <i>m</i>, and <i>k</i> is as small as possible. If there are multiple possibilities for <i>s</i>, choose the value of
+ <i>s</i> for which <i>s</i> × 10<sup><i>n</i>−<i>k</i></sup> is closest in value to <i>m</i>. If there are
+ two such possible values of <i>s</i>, choose the one that is even. Note that <i>k</i> is the number of digits in the
+ decimal representation of <i>s</i> and that <i>s</i> is not divisible by 10.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 3</span> Implementers of ECMAScript may find useful the paper and code written by David M. Gay
+ for binary-to-decimal conversion of floating-point numbers:</p>
+
+ <p>Gay, David M. Correctly Rounded Binary-Decimal and Decimal-Binary Conversions. Numerical Analysis, Manuscript 90-10.
+ AT&T Bell Laboratories (Murray Hill, New Jersey). November 30, 1990. Available as<br><span style="font-family:
+ sans-serif"><a
+ href="http://cm.bell-labs.com/cm/cs/doc/90/4-10.ps.gz">http://cm.bell-labs.com/cm/cs/doc/90/4-10.ps.gz</a></span>.
+ Associated code available as<br><span style="font-family: sans-serif"><a
+ href="http://netlib.sandia.gov/fp/dtoa.c">http://netlib.sandia.gov/fp/dtoa.c</a></span> and as<br><span
+ style="font-family: sans-serif"><a
+ href="http://netlib.sandia.gov/fp/g_fmt.c">http://netlib.sandia.gov/fp/g_fmt.c</a></span> and may also be found at the
+ various <code>netlib</code> mirror sites.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-toobject">
+ <h1><span class="secnum" id="sec-7.1.13"><a href="#sec-toobject" title="link to this section">7.1.13</a></span>
+ ToObject</h1>
+
+ <p>The abstract operation ToObject converts its <i>argument</i> to a value of type Object according to <a
+ href="#table-13">Table 13</a>:</p>
+
+ <figure>
+ <figcaption><span id="table-13">Table 13</span> — ToObject Conversions</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-top: 2px solid #000000">Argument Type</th>
+ <th style="border-bottom: 1px solid #000000; border-right: 1px solid #000000; border-top: 2px solid #000000">Result</th>
+ </tr>
+ <tr>
+ <td><a href="#sec-completion-record-specification-type">Completion Record</a></td>
+ <td>If <i>argument</i> is an <a href="#sec-completion-record-specification-type">abrupt completion</a>, return <i>argument</i>. Otherwise return ToObject(<i>argument</i>.[[value]])</td>
+ </tr>
+ <tr>
+ <td>Undefined</td>
+ <td>Throw a <b>TypeError</b> exception.</td>
+ </tr>
+ <tr>
+ <td>Null</td>
+ <td>Throw a <b>TypeError</b> exception.</td>
+ </tr>
+ <tr>
+ <td>Boolean</td>
+ <td>Return a new Boolean object whose [[BooleanData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is set to the value of <i>argument</i>. See <a href="#sec-boolean-objects">19.3</a> for a description of Boolean objects.</td>
+ </tr>
+ <tr>
+ <td>Number</td>
+ <td>Return a new Number object whose [[NumberData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is set to the value of <i>argument</i>. See <a href="#sec-number-objects">20.1</a> for a description of Number objects.</td>
+ </tr>
+ <tr>
+ <td>String</td>
+ <td>Return a new String object whose [[StringData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is set to the value of <i>argument</i>. See <a href="#sec-string-objects">21.1</a> for a description of String objects.</td>
+ </tr>
+ <tr>
+ <td>Symbol</td>
+ <td>Return a new Symbol object whose [[SymbolData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is set to the value of <i>argument</i>. See <a href="#sec-symbol-objects">19.4</a> for a description of Symbol objects.</td>
+ </tr>
+ <tr>
+ <td>Object</td>
+ <td>Return <i>argument</i> (no conversion).</td>
+ </tr>
+ </table>
+ </figure>
+ </section>
+
+ <section id="sec-topropertykey">
+ <h1><span class="secnum" id="sec-7.1.14"><a href="#sec-topropertykey" title="link to this section">7.1.14</a></span>
+ ToPropertyKey</h1>
+
+ <p>The abstract operation ToPropertyKey converts its <var>argument</var> to a value that can be used as a <a
+ href="#sec-object-type">property key</a> by performing the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>argument</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>argument</i>) is Symbol, then
+ <ol class="block">
+ <li>Return <i>argument</i>.</li>
+ </ol>
+ </li>
+ <li>Return <a href="#sec-tostring">ToString</a>(<i>argument</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-tolength">
+ <h1><span class="secnum" id="sec-7.1.15"><a href="#sec-tolength" title="link to this section">7.1.15</a></span>
+ ToLength</h1>
+
+ <p>The abstract operation ToLength converts its <var>argument</var> to an integer suitable for use as the length of an
+ array-like object. It performs the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>argument</i>).</li>
+ <li>Let <i>len</i> be <a href="#sec-tointeger">ToInteger</a>(<i>argument</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>len</i>).</li>
+ <li>If <i>len</i> ≤ +0, then return +0.</li>
+ <li>Return min(<i>len</i>, 2<sup>53</sup>-1).</li>
+ </ol>
+ </section>
+
+ <section id="sec-canonicalnumericindexstring">
+ <h1><span class="secnum" id="sec-7.1.16"><a href="#sec-canonicalnumericindexstring"
+ title="link to this section">7.1.16</a></span> CanonicalNumericIndexString(argument)</h1>
+
+ <p>The abstract operation CanonicalNumericIndexString returns its <var>argument</var> converted to a numeric value if it is
+ a String representation of a Number that would be produced by <a href="#sec-tostring">ToString</a>, or the string
+ <code>"-0"</code>. Otherwise, it returns <span class="value">undefined.</span> This abstract operation functions as
+ follows:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>argument</i>) is String.</li>
+ <li>If <i>argument</i> is <code>"-0"</code>, then return −0.</li>
+ <li>Let <i>n</i> be <a href="#sec-tonumber">ToNumber</a>(<i>argument</i>).</li>
+ <li>If <a href="#sec-samevalue">SameValue</a>(<a href="#sec-tostring">ToString</a>(<i>n</i>), <i>argument</i>) is
+ <b>false</b>, then return <b>undefined</b>.</li>
+ <li>Return <i>n</i>.</li>
+ </ol>
+
+ <p>A <i>canonical numeric string</i> is any String value for which the CanonicalNumericIndexString abstraction operation
+ does not return <span class="value">undefined</span>.</p>
+ </section>
+ </section>
+
+ <section id="sec-testing-and-comparison-operations">
+ <div class="front">
+ <h1><span class="secnum" id="sec-7.2"><a href="#sec-testing-and-comparison-operations"
+ title="link to this section">7.2</a></span> Testing and Comparison Operations</h1>
+ </div>
+
+ <section id="sec-checkobjectcoercible">
+ <h1><span class="secnum" id="sec-7.2.1"><a href="#sec-checkobjectcoercible" title="link to this section">7.2.1</a></span>
+ CheckObjectCoercible ( argument )</h1>
+
+ <p>The abstract operation CheckObjectCoercible throws an error if its <var>argument</var> is a value that cannot be
+ converted to an Object using <a href="#sec-toobject">ToObject</a>. It is defined by <a href="#table-14">Table 14</a>:</p>
+
+ <figure>
+ <figcaption><span id="table-14">Table 14</span> — CheckObjectCoercible Results</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-top: 2px solid #000000"><span style="background-color: #C0C0C0; font-family: Times New Roman"><b><i>argument</i></b></span> <span style="background-color: #C0C0C0"><b><i>Type</i></b></span></th>
+ <th style="border-bottom: 1px solid #000000; border-right: 1px solid #000000; border-top: 2px solid #000000">Result</th>
+ </tr>
+ <tr>
+ <td><a href="#sec-completion-record-specification-type">Completion Record</a></td>
+ <td>If <var>argument</var> is an <a href="#sec-completion-record-specification-type">abrupt completion</a>, return <var>argument</var>. Otherwise return CheckObjectCoercible(<var>argument</var>.[[value]])</td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black">Undefined</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black">Throw a <b>TypeError</b> exception.</td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">Null</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">Throw a <b>TypeError</b> exception.</td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">Boolean</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">Return <var>argument</var></td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">Number</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">Return <var>argument</var></td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">String</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">Return <var>argument</var></td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">Symbol</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">Return <var>argument</var></td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">Object</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">Return <var>argument</var></td>
+ </tr>
+ </table>
+ </figure>
+ </section>
+
+ <section id="sec-iscallable">
+ <h1><span class="secnum" id="sec-7.2.2"><a href="#sec-iscallable" title="link to this section">7.2.2</a></span> IsCallable (
+ argument )</h1>
+
+ <p>The abstract operation IsCallable determines if its <var>argument</var>, which must be an <a
+ href="#sec-ecmascript-language-types">ECMAScript language value</a> or a <a
+ href="#sec-completion-record-specification-type">Completion Record</a>, is a callable function Object according to <a
+ href="#table-15">Table 15</a>:</p>
+
+ <figure>
+ <figcaption><span id="table-15">Table 15</span> — IsCallable Results</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-top: 2px solid #000000">Argument Type</th>
+ <th style="border-bottom: 1px solid #000000; border-right: 1px solid #000000; border-top: 2px solid #000000">Result</th>
+ </tr>
+ <tr>
+ <td><a href="#sec-completion-record-specification-type">Completion Record</a></td>
+ <td>If <var>argument</var> is an <a href="#sec-completion-record-specification-type">abrupt completion</a>, return <var>argument</var>. Otherwise return IsCallable(<var>argument</var>.[[value]])</td>
+ </tr>
+ <tr>
+ <td>Undefined</td>
+ <td>Return <b>false</b>.</td>
+ </tr>
+ <tr>
+ <td>Null</td>
+ <td>Return <b>false</b>.</td>
+ </tr>
+ <tr>
+ <td>Boolean</td>
+ <td>Return <b>false</b>.</td>
+ </tr>
+ <tr>
+ <td>Number</td>
+ <td>Return <b>false</b>.</td>
+ </tr>
+ <tr>
+ <td>String</td>
+ <td>Return <b>false</b>.</td>
+ </tr>
+ <tr>
+ <td>Symbol</td>
+ <td>Return <b>false</b>.</td>
+ </tr>
+ <tr>
+ <td>Object</td>
+ <td>If <var>argument</var> has a [[Call]] internal method, then return <b>true</b>, otherwise return <b>false</b>.</td>
+ </tr>
+ </table>
+ </figure>
+ </section>
+
+ <section id="sec-samevalue">
+ <h1><span class="secnum" id="sec-7.2.3"><a href="#sec-samevalue" title="link to this section">7.2.3</a></span> SameValue(x,
+ y)</h1>
+
+ <p>The internal comparison abstract operation SameValue(<var>x</var>, <var>y</var>), where <var>x</var> and <var>y</var> are
+ <a href="#sec-ecmascript-language-types">ECMAScript language values</a>, produces <b>true</b> or <b>false</b>. Such a
+ comparison is performed as follows:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>x</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>y</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>x</i>) is different from <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>y</i>), return <b>false</b>.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>x</i>) is Undefined, return <b>true</b>.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>x</i>) is Null, return <b>true</b>.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>x</i>) is Number, then
+ <ol class="block">
+ <li>If <i>x</i> is NaN and <i>y</i> is NaN, return <b>true</b>.</li>
+ <li>If <i>x</i> is +0 and <i>y</i> is -0, return <b>false</b>.</li>
+ <li>If <i>x</i> is -0 and <i>y</i> is +0, return <b>false</b>.</li>
+ <li>If <i>x</i> is the same Number value as <i>y</i>, return <b>true</b>.</li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>x</i>) is String, then
+ <ol class="block">
+ <li>If <i>x</i> and <i>y</i> are exactly the same sequence of code units (same length and same code units in
+ corresponding positions) return <b>true</b>; otherwise, return <b>false</b>.</li>
+ </ol>
+ </li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>x</i>) is Boolean, then
+ <ol class="block">
+ <li>If <i>x</i> and <i>y</i> are both <b>true</b> or both <b>false</b>, then return <b>true</b>; otherwise, return
+ <b>false</b>.</li>
+ </ol>
+ </li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>x</i>) is Symbol, then
+ <ol class="block">
+ <li>If <i>x</i> and <i>y</i> are both the same Symbol value, then return <b>true</b>; otherwise, return
+ <b>false</b>.</li>
+ </ol>
+ </li>
+ <li>Return <b>true</b> if <i>x</i> and <i>y</i> are the same Object value. Otherwise, return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-samevaluezero">
+ <h1><span class="secnum" id="sec-7.2.4"><a href="#sec-samevaluezero" title="link to this section">7.2.4</a></span>
+ SameValueZero(x, y)</h1>
+
+ <p>The internal comparison abstract operation SameValueZero(<var>x</var>, <var>y</var>), where <var>x</var> and <var>y</var>
+ are <a href="#sec-ecmascript-language-types">ECMAScript language values</a>, produces <b>true</b> or <b>false</b>. Such a
+ comparison is performed as follows:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>x</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>y</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>x</i>) is different from <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>y</i>), return <b>false</b>.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>x</i>) is Undefined, return <b>true</b>.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>x</i>) is Null, return <b>true</b>.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>x</i>) is Number, then
+ <ol class="block">
+ <li>If <i>x</i> is NaN and <i>y</i> is NaN, return <b>true</b>.</li>
+ <li>If <i>x</i> is +0 and <i>y</i> is -0, return <b>true</b>.</li>
+ <li>If <i>x</i> is -0 and <i>y</i> is +0, return <b>true</b>.</li>
+ <li>If <i>x</i> is the same Number value as <i>y</i>, return <b>true</b>.</li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>x</i>) is String, then
+ <ol class="block">
+ <li>If <i>x</i> and <i>y</i> are exactly the same sequence of code units (same length and same code units in
+ corresponding positions) return <b>true</b>; otherwise, return <b>false</b>.</li>
+ </ol>
+ </li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>x</i>) is Boolean, then
+ <ol class="block">
+ <li>If <i>x</i> and <i>y</i> are both <b>true</b> or both <b>false</b>, then return <b>true</b>; otherwise, return
+ <b>false</b>.</li>
+ </ol>
+ </li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>x</i>) is Symbol, then
+ <ol class="block">
+ <li>If <i>x</i> and <i>y</i> are both the same Symbol value, then return <b>true</b>; otherwise, return
+ <b>false</b>.</li>
+ </ol>
+ </li>
+ <li>Return <b>true</b> if <i>x</i> and <i>y</i> are the same Object value. Otherwise, return <b>false</b>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> SameValueZero differs from SameValue only in its treatment of +0 and -0.</p>
+ </div>
+ </section>
+
+ <section id="sec-isconstructor">
+ <h1><span class="secnum" id="sec-7.2.5"><a href="#sec-isconstructor" title="link to this section">7.2.5</a></span>
+ IsConstructor ( argument )</h1>
+
+ <p>The abstract operation IsConstructor determines if its <var>argument</var>, which must be an <a
+ href="#sec-ecmascript-language-types">ECMAScript language value</a> or a <a
+ href="#sec-completion-record-specification-type">Completion Record</a>, is a function object with a [[Construct]] internal
+ method.</p>
+
+ <ol class="proc">
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>argument</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>argument</i>) is not Object, return <b>false</b>.</li>
+ <li>If <i>argument</i> has a [[Construct]] internal method, return <b>true</b>.</li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-ispropertykey">
+ <h1><span class="secnum" id="sec-7.2.6"><a href="#sec-ispropertykey" title="link to this section">7.2.6</a></span>
+ IsPropertyKey ( argument )</h1>
+
+ <p>The abstract operation IsPropertyKey determines if its <var>argument</var>, which must be an <a
+ href="#sec-ecmascript-language-types">ECMAScript language value</a> or a <a
+ href="#sec-completion-record-specification-type">Completion Record</a>, is a value that may be used as a <a
+ href="#sec-object-type">property key</a>.</p>
+
+ <ol class="proc">
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>argument</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>argument</i>) is String, return <b>true</b>.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>argument</i>) is Symbol, return <b>true</b>.</li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-isextensible-o">
+ <h1><span class="secnum" id="sec-7.2.7"><a href="#sec-isextensible-o" title="link to this section">7.2.7</a></span>
+ IsExtensible (O)</h1>
+
+ <p>The abstract operation <span style="font-family: Times New Roman">IsExtensible</span> is used to determine whether
+ additional properties can be added to the object that is <var>O</var>. A Boolean value is returned. This abstract operation
+ performs the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is
+ Object.</li>
+ <li>Return the result of calling the [[IsExtensible]] internal method of <i>O</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-isinteger">
+ <h1><span class="secnum" id="sec-7.2.8"><a href="#sec-isinteger" title="link to this section">7.2.8</a></span> IsInteger (
+ argument )</h1>
+
+ <p>The abstract operation IsInteger determines if its <var>argument</var> is a finite integer numeric value.</p>
+
+ <ol class="proc">
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>argument</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>argument</i>) is not Number, return <b>false</b>.</li>
+ <li>If <i>argument</i> is <b>NaN</b>, <b>+∞</b>, or <b>−∞</b>, return <b>false</b>.</li>
+ <li>If <a href="#sec-algorithm-conventions">floor</a>(<a href="#sec-algorithm-conventions">abs</a>(<i>argument</i>)) ≠
+ <a href="#sec-algorithm-conventions">abs</a>(<i>argument</i>), then return <b>false</b>.</li>
+ <li>Return <b>true</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-abstract-relational-comparison">
+ <h1><span class="secnum" id="sec-7.2.9"><a href="#sec-abstract-relational-comparison"
+ title="link to this section">7.2.9</a></span> Abstract Relational Comparison</h1>
+
+ <p>The comparison <var>x</var> < <var>y</var>, where <var>x</var> and <var>y</var> are values, produces <b>true</b>,
+ <b>false</b>, or <b>undefined</b> (which indicates that at least one operand is <b>NaN</b>). In addition to <var>x</var> and
+ <var>y</var> the algorithm takes a Boolean flag named <span class="nt">LeftFirst</span> as a parameter. The flag is used to
+ control the order in which operations with potentially visible side-effects are performed upon <var>x</var> and
+ <var>y</var>. It is necessary because ECMAScript specifies left to right evaluation of expressions. The default value of
+ <span class="nt">LeftFirst</span> is <b>true</b> and indicates that the <var>x</var> parameter corresponds to an expression
+ that occurs to the left of the <var>y</var> parameter’s corresponding expression. If <span class="nt">LeftFirst</span>
+ is <b>false</b>, the reverse is the case and operations must be performed upon <var>y</var> before <var>x</var>. Such a
+ comparison is performed as follows:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>x</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>y</i>).</li>
+ <li>If the <i>LeftFirst</i> flag is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>px</i> be <a href="#sec-toprimitive">ToPrimitive</a>(<i>x</i>, hint Number).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>px</i>).</li>
+ <li>Let <i>py</i> be <a href="#sec-toprimitive">ToPrimitive</a>(<i>y</i>, hint Number).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>py</i>).</li>
+ </ol>
+ </li>
+ <li>Else the order of evaluation needs to be reversed to preserve left to right evaluation
+ <ol class="block">
+ <li>Let <i>py</i> be <a href="#sec-toprimitive">ToPrimitive</a>(<i>y</i>, hint Number).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>py</i>).</li>
+ <li>Let <i>px</i> be <a href="#sec-toprimitive">ToPrimitive</a>(<i>x</i>, hint Number).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>px</i>).</li>
+ </ol>
+ </li>
+ <li>If both <i>px</i> and <i>py</i> are Strings, then
+ <ol class="block">
+ <li>If <i>py</i> is a prefix of <i>px</i>, return <b>false</b>. (A String value <i>p</i> is a prefix of String value
+ <i>q</i> if <i>q</i> can be the result of concatenating <i>p</i> and some other String <i>r</i>. Note that any
+ String is a prefix of itself, because <i>r</i> may be the empty String.)</li>
+ <li>If <i>px</i> is a prefix of <i>py</i>, return <b>true</b>.</li>
+ <li>Let <i>k</i> be the smallest nonnegative integer such that the character at position <i>k</i> within <i>px</i> is
+ different from the character at position <i>k</i> within <i>py</i>. (There must be such a <i>k</i>, for neither
+ String is a prefix of the other.)</li>
+ <li>Let <i>m</i> be the integer that is the code unit value for the character at position <i>k</i> within
+ <i>px</i>.</li>
+ <li>Let <i>n</i> be the integer that is the code unit value for the character at position <i>k</i> within
+ <i>py</i>.</li>
+ <li>If <i>m</i> < <i>n</i>, return <b>true</b>. Otherwise, return <b>false</b>.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>nx</i> be <a href="#sec-tonumber">ToNumber</a>(<i>px</i>). Because <i>px</i> and <i>py</i> are primitive
+ values evaluation order is not important.</li>
+ <li>Let <i>ny</i> be <a href="#sec-tonumber">ToNumber</a>(<i>py</i>).</li>
+ <li>If <i>nx</i> is <b>NaN</b>, return <b>undefined</b>.</li>
+ <li>If <i>ny</i> is <b>NaN</b>, return <b>undefined</b>.</li>
+ <li>If <i>nx</i> and <i>ny</i> are the same Number value, return <b>false</b>.</li>
+ <li>If <i>nx</i> is <b>+0</b> and <i>ny</i> is <b>−0</b>, return <b>false</b>.</li>
+ <li>If <i>nx</i> is <b>−0</b> and <i>ny</i> is <b>+0</b>, return <b>false</b>.</li>
+ <li>If <i>nx</i> is <b>+∞</b>, return <b>false</b>.</li>
+ <li>If <i>ny</i> is <b>+∞</b>, return <b>true</b>.</li>
+ <li>If <i>ny</i> is <b>−∞</b>, return <b>false</b>.</li>
+ <li>If <i>nx</i> is <b>−∞</b>, return <b>true</b>.</li>
+ <li>If the mathematical value of <i>nx</i> is less than the mathematical value of <i>ny</i> —note that these
+ mathematical values are both finite and not both zero—return <b>true</b>. Otherwise, return
+ <b>false</b>.</li>
+ </ol>
+ </li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> Step 5 differs from step 11 in the algorithm for the addition operator <code>+</code>
+ (<a href="#sec-addition-operator-plus">12.7.3</a>) in using “and” instead of “or”.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 2</span> The comparison of Strings uses a simple lexicographic ordering on sequences of code unit
+ values. There is no attempt to use the more complex, semantically oriented definitions of character or string equality and
+ collating order defined in the Unicode specification. Therefore String values that are canonically equal according to the
+ Unicode standard could test as unequal. In effect this algorithm assumes that both Strings are already in normalized form.
+ Also, note that for strings containing supplementary characters, lexicographic ordering on sequences of UTF-16 code unit
+ values differs from that on sequences of code point values.</p>
+ </div>
+ </section>
+
+ <section id="sec-abstract-equality-comparison">
+ <h1><span class="secnum" id="sec-7.2.10"><a href="#sec-abstract-equality-comparison"
+ title="link to this section">7.2.10</a></span> Abstract Equality Comparison</h1>
+
+ <p>The comparison <var>x</var> == <var>y</var>, where <var>x</var> and <var>y</var> are values, produces <b>true</b> or
+ <b>false</b>. Such a comparison is performed as follows:</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>x</i>) is the same as <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>y</i>), then
+ <ol class="block">
+ <li>Return the result of performing Strict Equality Comparison <i>x</i> === <i>y</i>.</li>
+ </ol>
+ </li>
+ <li>If <i>x</i> is <b>null</b> and <i>y</i> is <b>undefined</b>, return <b>true</b>.</li>
+ <li>If <i>x</i> is <b>undefined</b> and <i>y</i> is <b>null</b>, return <b>true</b>.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>x</i>) is Number and <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>y</i>) is String,<br>return the result of the comparison
+ <i>x</i> == <a href="#sec-tonumber">ToNumber</a>(<i>y</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>x</i>) is String and <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>y</i>) is Number,<br>return the result of the comparison <a
+ href="#sec-tonumber">ToNumber</a>(<i>x</i>) == <i>y</i>.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>x</i>) is Boolean, return the result of the comparison
+ <a href="#sec-tonumber">ToNumber</a>(<i>x</i>) == <i>y</i>.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>y</i>) is Boolean, return the result of the comparison
+ <i>x</i> == <a href="#sec-tonumber">ToNumber</a>(<i>y</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>x</i>) is either String or Number and <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>y</i>) is Object,<br>return the result of the comparison
+ <i>x</i> == <a href="#sec-toprimitive">ToPrimitive</a>(<i>y</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>x</i>) is Object and <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>y</i>) is either String or Number,<br>return the result of
+ the comparison <a href="#sec-toprimitive">ToPrimitive</a>(<i>x</i>) == <i>y</i>.</li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-strict-equality-comparison">
+ <h1><span class="secnum" id="sec-7.2.11"><a href="#sec-strict-equality-comparison"
+ title="link to this section">7.2.11</a></span> Strict Equality Comparison</h1>
+
+ <p>The comparison <var>x</var> === <var>y</var>, where <var>x</var> and <var>y</var> are values, produces <b>true</b> or
+ <b>false</b>. Such a comparison is performed as follows:</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>x</i>) is different from <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>y</i>), return <b>false</b>.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>x</i>) is Undefined, return <b>true</b>.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>x</i>) is Null, return <b>true</b>.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>x</i>) is Number, then
+ <ol class="block">
+ <li>If <i>x</i> is <b>NaN</b>, return <b>false</b>.</li>
+ <li>If <i>y</i> is <b>NaN</b>, return <b>false</b>.</li>
+ <li>If <i>x</i> is the same Number value as <i>y</i>, return <b>true</b>.</li>
+ <li>If <i>x</i> is <b>+0</b> and <i>y</i> is <b>−0</b>, return <b>true</b>.</li>
+ <li>If <i>x</i> is <b>−0</b> and <i>y</i> is <b>+0</b>, return <b>true</b>.</li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>x</i>) is String, then
+ <ol class="block">
+ <li>If <i>x</i> and <i>y</i> are exactly the same sequence of characters (same length and same characters in
+ corresponding positions), return <b>true</b>.</li>
+ <li>Else, return <b>false</b>.</li>
+ </ol>
+ </li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>x</i>) is Boolean, then
+ <ol class="block">
+ <li>If <i>x</i> and <i>y</i> are both <b>true</b> or both <b>false</b>, return <b>true</b>.</li>
+ <li>Else, return <b>false</b>.</li>
+ </ol>
+ </li>
+ <li>If <i>x</i> and <i>y</i> are the same Symbol value, return <b>true</b>.</li>
+ <li>If <i>x</i> and <i>y</i> are the same Object value, return <b>true</b>.</li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> This algorithm differs from <a href="#sec-samevalue">the SameValue Algorithm</a> (<a
+ href="#sec-samevalue">7.2.3</a>) in its treatment of signed zeroes and NaNs.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-operations-on-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-7.3"><a href="#sec-operations-on-objects" title="link to this section">7.3</a></span>
+ Operations on Objects</h1>
+ </div>
+
+ <section id="sec-get-o-p">
+ <h1><span class="secnum" id="sec-7.3.1"><a href="#sec-get-o-p" title="link to this section">7.3.1</a></span> Get (O, P)</h1>
+
+ <p>The abstract operation <span style="font-family: Times New Roman">Get</span> is used to retrieve the value of a specific
+ property of an object. The operation is called with arguments <var>O</var> and <var>P</var> where <var>O</var> is the
+ object and <var>P</var> is the <a href="#sec-object-type">property key</a>. This abstract operation performs the following
+ steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is
+ Object.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ispropertykey">IsPropertyKey</a>(<i>P</i>) is
+ <b>true</b>.</li>
+ <li>Return the result of calling the [[Get]] internal method of <i>O</i> passing <i>P</i> and <i>O</i> as the
+ arguments.</li>
+ </ol>
+ </section>
+
+ <section id="sec-put-o-p-v-throw">
+ <h1><span class="secnum" id="sec-7.3.2"><a href="#sec-put-o-p-v-throw" title="link to this section">7.3.2</a></span> Put (O,
+ P, V, Throw)</h1>
+
+ <p>The abstract operation <span style="font-family: Times New Roman">Put</span> is used to set the value of a specific
+ property of an object. The operation is called with arguments <var>O</var>, <var>P</var>, <var>V</var>, and <span
+ class="nt">Throw</span> where <var>O</var> is the object, <var>P</var> is the <a href="#sec-object-type">property key</a>,
+ <var>V</var> is the new value for the property and <span class="nt">Throw</span> is a Boolean flag. This abstract operation
+ performs the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is
+ Object.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ispropertykey">IsPropertyKey</a>(<i>P</i>) is
+ <b>true</b>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>Throw</i>) is Boolean.</li>
+ <li>Let <i>success</i> be the result of calling the [[Set]] internal method of <i>O</i> passing <i>P</i>, <i>V</i>, and
+ <i>O</i> as the arguments.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>success</i>).</li>
+ <li>If <i>success</i> is <b>false</b> and <i>Throw</i> is <b>true</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Return <i>success</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-createdataproperty">
+ <h1><span class="secnum" id="sec-7.3.3"><a href="#sec-createdataproperty" title="link to this section">7.3.3</a></span>
+ CreateDataProperty (O, P, V)</h1>
+
+ <p>The abstract operation <span style="font-family: Times New Roman">CreateDataProperty</span> is used to create a new own
+ property of an object. The operation is called with arguments <var>O</var>, <var>P</var>, and <var>V</var> where
+ <var>O</var> is the object, <var>P</var> is the <a href="#sec-object-type">property key</a>, and <var>V</var> is the value
+ for the property. This abstract operation performs the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is
+ Object.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ispropertykey">IsPropertyKey</a>(<i>P</i>) is
+ <b>true</b>.</li>
+ <li>Let <i>newDesc</i> be the PropertyDescriptor{[[Value]]: <i>V</i>, [[Writable]]: <b>true</b>, [[Enumerable]]:
+ <b>true</b>, [[Configurable]]: <b>true</b>}.</li>
+ <li>Return the result of calling the [[DefineOwnProperty]] internal method of <i>O</i> passing <i>P</i> and <i>newDesc</i>
+ as arguments.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> This abstract operation creates a property whose attributes are set to the same defaults
+ used for properties created by the ECMAScript language assignment operator. Normally, the property will not already exist.
+ If it does exist and is not configurable or <b>O</b> is not extensible [[DefineOwnProperty]] will return <b>false</b>.</p>
+ </div>
+ </section>
+
+ <section id="sec-createdatapropertyorthrow">
+ <h1><span class="secnum" id="sec-7.3.4"><a href="#sec-createdatapropertyorthrow"
+ title="link to this section">7.3.4</a></span> CreateDataPropertyOrThrow (O, P, V)</h1>
+
+ <p>The abstract operation <span style="font-family: Times New Roman">CreateDataPropertyOrThrow</span> is used to create a
+ new own property of an object. It throws a <span class="value">TypeError</span> exception if the requested property update
+ cannot be performed. The operation is called with arguments <var>O</var>, <var>P</var>, and <var>V</var> where <var>O</var>
+ is the object, <var>P</var> is the <a href="#sec-object-type">property key</a>, and <var>V</var> is the value for the
+ property. This abstract operation performs the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is
+ Object.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ispropertykey">IsPropertyKey</a>(<i>P</i>) is
+ <b>true</b>.</li>
+ <li>Let <i>success</i> be <a href="#sec-createdataproperty">CreateDataProperty</a>(<i>O</i>, <i>P</i>, <i>V</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>success</i>).</li>
+ <li>If <i>success</i> is <b>false</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Return <i>success</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> This abstract operation creates a property whose attributes are set to the same defaults
+ used for properties created by the ECMAScript language assignment operator. Normally, the property will not already exist.
+ If it does exist and is not configurable or <b>O</b> is not extensible [[DefineOwnProperty]] will return <b>false</b>
+ <span style="font-family: sans-serif">causing this operation to throw a</span> <b>TypeError</b> <span style="font-family:
+ sans-serif">exception</span>.</p>
+ </div>
+ </section>
+
+ <section id="sec-definepropertyorthrow">
+ <h1><span class="secnum" id="sec-7.3.5"><a href="#sec-definepropertyorthrow" title="link to this section">7.3.5</a></span>
+ DefinePropertyOrThrow (O, P, desc)</h1>
+
+ <p>The abstract operation <span style="font-family: Times New Roman">DefinePropertyOrThrow</span> is used to call the
+ [[DefineOwnProperty]] internal method of an object in a manner that will throw a <b>TypeError</b> exception if the requested
+ property update cannot be performed. The operation is called with arguments <var>O</var>, <var>P</var>, and
+ <var>desc</var> where <var>O</var> is the object, <var>P</var> is the <a href="#sec-object-type">property key</a>, and
+ <var>desc</var> is the <a href="#sec-property-descriptor-specification-type">Property Descriptor</a> for the property. This
+ abstract operation performs the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is
+ Object.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ispropertykey">IsPropertyKey</a>(<i>P</i>) is
+ <b>true</b>.</li>
+ <li>Let <i>success</i> be the result of calling the [[DefineOwnProperty]] internal method of <i>O</i> passing <i>P</i>
+ and <i>desc</i> as arguments.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>success</i>).</li>
+ <li>If <i>success</i> is <b>false</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Return <i>success</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-deletepropertyorthrow">
+ <h1><span class="secnum" id="sec-7.3.6"><a href="#sec-deletepropertyorthrow" title="link to this section">7.3.6</a></span>
+ DeletePropertyOrThrow (O, P)</h1>
+
+ <p>The abstract operation DeletePropertyOrThrow is used to remove a specific own property of an object. It throws an
+ exception if the property is not configurable. The operation is called with arguments <var>O</var> and <var>P</var> where
+ <var>O</var> is the object and <var>P</var> is the <a href="#sec-object-type">property key</a>. This abstract operation
+ performs the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is
+ Object.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ispropertykey">IsPropertyKey</a>(<i>P</i>) is
+ <b>true</b>.</li>
+ <li>Let <i>success</i> be the result of calling the [[Delete]] internal method of <i>O</i> passing <i>P</i> as the
+ argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>success</i>).</li>
+ <li>If <i>success</i> is <b>false</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Return <i>success</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-getmethod">
+ <h1><span class="secnum" id="sec-7.3.7"><a href="#sec-getmethod" title="link to this section">7.3.7</a></span> GetMethod (O,
+ P)</h1>
+
+ <p>The abstract operation GetMethod is used to get the value of a specific property of an object when the value of the
+ property is expected to be a function. The operation is called with arguments <var>O</var> and <var>P</var> where
+ <var>O</var> is the object, <var>P</var> is the <a href="#sec-object-type">property key</a>. This abstract operation
+ performs the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is
+ Object.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ispropertykey">IsPropertyKey</a>(<i>P</i>) is
+ <b>true</b>.</li>
+ <li>Let <i>func</i> be the result of calling the [[Get]] internal method of <i>O</i> passing <i>P</i> and <i>O</i> as the
+ arguments.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>func</i>).</li>
+ <li>If <i>func</i> is <b>undefined</b>, then return <b>undefined</b>.</li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>func</i>) is <b>false</b>, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>Return <i>func</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-hasproperty">
+ <h1><span class="secnum" id="sec-7.3.8"><a href="#sec-hasproperty" title="link to this section">7.3.8</a></span> HasProperty
+ (O, P)</h1>
+
+ <p>The abstract operation HasProperty is used to determine whether an object has a property with the specified <a
+ href="#sec-object-type">property key</a>. The property may be either an own or inherited. A Boolean value is returned. The
+ operation is called with arguments <var>O</var> and <var>P</var> where <var>O</var> is the object and <var>P</var> is the
+ <a href="#sec-object-type">property key</a>. This abstract operation performs the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is
+ Object.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ispropertykey">IsPropertyKey</a>(<i>P</i>) is
+ <b>true</b>.</li>
+ <li>Return the result of calling the [[HasProperty]] internal method of <i>O</i> with argument <i>P</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-hasownproperty">
+ <h1><span class="secnum" id="sec-7.3.9"><a href="#sec-hasownproperty" title="link to this section">7.3.9</a></span>
+ HasOwnProperty (O, P)</h1>
+
+ <p>The abstract operation HasOwnProperty is used to determine whether an object has an own property with the specified <a
+ href="#sec-object-type">property key</a>. A Boolean value is returned. The operation is called with arguments <var>O</var>
+ and <var>P</var> where <var>O</var> is the object and <var>P</var> is the <a href="#sec-object-type">property key</a>. This
+ abstract operation performs the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is
+ Object.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ispropertykey">IsPropertyKey</a>(<i>P</i>) is
+ <b>true</b>.</li>
+ <li>Let <i>desc</i> be the result of calling the [[GetOwnProperty]] internal method of <i>O</i> passing <i>P</i> as the
+ argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>desc</i>).</li>
+ <li>If <i>desc</i> is <b>undefined</b>, return <b>false</b>.</li>
+ <li>Return <b>true</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-invoke">
+ <h1><span class="secnum" id="sec-7.3.10"><a href="#sec-invoke" title="link to this section">7.3.10</a></span> Invoke(O,P,
+ [args])</h1>
+
+ <p>The abstract operation <span style="font-family: Times New Roman">Invoke</span> is used to call a method property of an
+ object. The operation is called with arguments <var>O</var>, <var>P</var> , and optionally <var>args</var> where
+ <var>O</var> serves as both the lookup point for the property and the <b>this</b> value of the call, <var>P</var> is the <a
+ href="#sec-object-type">property key</a>, and <var>args</var> is the list of arguments values passed to the method. If
+ <var>args</var> is not present, an empty <a href="#sec-list-and-record-specification-type">List</a> is used as its value.
+ This abstract operation performs the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>P</i> is a valid <a href="#sec-object-type">property key</a>.</li>
+ <li>If <i>args</i> was not passed, then let <i>args</i> be a new empty <a
+ href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Let <i>obj</i> be <a href="#sec-toobject">ToObject</a>(<i>O</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>obj</i>).</li>
+ <li>Let <i>func</i> be the result of calling the [[Get]] internal method of <i>obj</i> passing <i>P</i> and <i>O</i> as
+ the arguments.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>func</i>).</li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>func</i>) is <b>false</b>, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>Return the result of calling the [[Call]] internal method of <i>func</i> passing <i>O</i> as <i>thisArgument</i> and
+ <i>args</i> as <i>argumentsList</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-setintegritylevel">
+ <h1><span class="secnum" id="sec-7.3.11"><a href="#sec-setintegritylevel" title="link to this section">7.3.11</a></span>
+ SetIntegrityLevel (O, level)</h1>
+
+ <p>The abstract operation <span style="font-family: Times New Roman">SetIntegrityLevel</span> is used to fix the set of own
+ properties of an object. This abstract operation performs the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is
+ Object.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>level</i> is either "<code>sealed</code>" or
+ "<code>frozen</code>".</li>
+ <li>Let <i>keysArray</i> be the result of calling the [[OwnPropertyKeys]] internal method of <i>O</i>.</li>
+ <li>Let <i>keys</i> be <a href="#sec-createlistfromarraylike">CreateListFromArrayLike</a>(<i>keysArray</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>keys</i>).</li>
+ <li>Let <i>pendingException</i> be <b>undefined</b>.</li>
+ <li>If <i>level</i> is "<code>sealed</code>", then
+ <ol class="block">
+ <li>Repeat for each element <i>k</i> of <i>keys</i>,
+ <ol class="block">
+ <li>Let <i>status</i> be <a href="#sec-definepropertyorthrow">DefinePropertyOrThrow</a>(<i>O</i>, <i>k</i>,
+ PropertyDescriptor{ [[Configurable]]: <b>false</b>}).</li>
+ <li>If <i>status</i> is an <a href="#sec-completion-record-specification-type">abrupt completion</a>, then
+ <ol class="block">
+ <li>If <i>pendingException</i> is <b>undefined</b>, then set <i>pendingException</i> to <i>status</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Else <i>level</i> is "<code>frozen</code>",
+ <ol class="block">
+ <li>Repeat for each element <i>k</i> of <i>keys</i>,
+ <ol class="block">
+ <li>Let <i>status</i> be the result of calling the [[GetOwnProperty]] internal method of <i>O</i> with
+ <i>k</i>.</li>
+ <li>If <i>status</i> is an <a href="#sec-completion-record-specification-type">abrupt completion</a>, then
+ <ol class="block">
+ <li>If <i>pendingException</i> is <b>undefined</b>, then set <i>pendingException</i> to <i>status</i>.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>currentDesc</i> be <i>status</i>.[[value]].</li>
+ <li>If <i>currentDesc</i> is not <b>undefined</b>, then
+ <ol class="block">
+ <li>If <a href="#sec-isaccessordescriptor">IsAccessorDescriptor</a>(<i>currentDesc</i>) is <b>true</b>,
+ then
+ <ol class="block">
+ <li>Let <i>desc</i> be the PropertyDescriptor{[[Configurable]]: <b>false</b>}.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>desc</i> be the PropertyDescriptor { [[Configurable]]: <b>false</b>, [[Writable]]:
+ <b>false</b> }.</li>
+ </ol>
+ </li>
+ <li>Let <i>status</i> be <a href="#sec-definepropertyorthrow">DefinePropertyOrThrow</a>(<i>O</i>,
+ <i>k</i>, <i>desc</i>).</li>
+ <li>If <i>status</i> is an <a href="#sec-completion-record-specification-type">abrupt completion</a>, then
+ <ol class="block">
+ <li>If <i>pendingException</i> is <b>undefined</b>, then set <i>pendingException</i> to
+ <i>status</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>If <i>pendingException</i> is not <b>undefined</b>, then return <i>pendingException</i>.</li>
+ <li>Return the result of calling the [[PreventExtensions]] internal method of <i>O</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-testintegritylevel">
+ <h1><span class="secnum" id="sec-7.3.12"><a href="#sec-testintegritylevel" title="link to this section">7.3.12</a></span>
+ TestIntegrityLevel (O, level)</h1>
+
+ <p>The abstract operation <span style="font-family: Times New Roman">TestIntegrityLevel</span> is used to determine if the
+ set of own properties of an object are fixed. This abstract operation performs the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is
+ Object.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>level</i> is either "<code>sealed</code>" or
+ "<code>frozen</code>".</li>
+ <li>Let <i>status</i> be <a href="#sec-isextensible-o">IsExtensible</a>(<i>O</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>If <i>status</i> is <b>true</b>, then return <b>false</b></li>
+ <li>NOTE If the object is extensible, none of its properties are examined.</li>
+ <li>Let <i>keysArray</i> be the result of calling the [[OwnPropertyKeys]] internal method of <i>O</i>.</li>
+ <li>Let <i>keys</i> be <a href="#sec-createlistfromarraylike">CreateListFromArrayLike</a>(<i>keysArray</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>keys</i>).</li>
+ <li>Let <i>pendingException</i> be <b>undefined</b>.</li>
+ <li>Let <i>configurable</i> be <b>false</b>.</li>
+ <li>Let <i>writable</i> be <b>false</b>.</li>
+ <li>Repeat for each element <i>k</i> of <i>keys</i>,
+ <ol class="block">
+ <li>Let <i>status</i> be the result of calling the [[GetOwnProperty]] internal method of <i>O</i> with <i>k</i>.</li>
+ <li>If <i>status</i> is an <a href="#sec-completion-record-specification-type">abrupt completion</a>, then
+ <ol class="block">
+ <li>If <i>pendingException</i> is <b>undefined</b>, then set <i>pendingException</i> to <i>status</i>.</li>
+ <li>Let <i>configurable</i> be <b>true</b>.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>currentDesc</i> be <i>status</i>.[[value]].</li>
+ <li>If <i>currentDesc</i> is not <b>undefined</b>, then
+ <ol class="block">
+ <li>Set <i>configurable</i> to <i>configurable</i> logically ored with
+ <i>currentDesc</i>.[[Configurable]].</li>
+ <li>If <a href="#sec-isdatadescriptor">IsDataDescriptor</a>(<i>currentDesc</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>Set <i>writable</i> to <i>writable</i> logically ored with <i>currentDesc</i>.[[Writable]].</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>If <i>pendingException</i> is not <b>undefined</b>, then return <i>pendingException</i>.</li>
+ <li>If <i>level</i> is "<code>frozen</code>" and <i>writable</i> is <b>true</b>, then return <b>false</b>.</li>
+ <li>If <i>configurable</i> is <b>true</b>, then return <b>false</b>.</li>
+ <li>Return <b>true</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-createarrayfromlist">
+ <h1><span class="secnum" id="sec-7.3.13"><a href="#sec-createarrayfromlist" title="link to this section">7.3.13</a></span>
+ CreateArrayFromList (elements)</h1>
+
+ <p>The abstract operation <span style="font-family: Times New Roman">CreateArrayFromList</span> is used to create an Array
+ object whose elements are provided by a <a href="#sec-list-and-record-specification-type">List</a>. This abstract operation
+ performs the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>elements</i> is a <a
+ href="#sec-list-and-record-specification-type">List</a> whose elements are all <a
+ href="#sec-ecmascript-language-types">ECMAScript language values</a>.</li>
+ <li>Let <i>array</i> be <a href="#sec-arraycreate">ArrayCreate</a>(0) (<a href="#sec-arraycreate">see 9.4.2.2</a>).</li>
+ <li>Let <i>n</i> be 0.</li>
+ <li>For each element <i>e</i> of <i>elements</i>
+ <ol class="block">
+ <li>Let <i>status</i> be the result of <a href="#sec-createdataproperty">CreateDataProperty</a>(<i>array</i>, <a
+ href="#sec-tostring">ToString</a>(<i>n</i>), <i>e</i>).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>status</i> is <b>true</b>.</li>
+ <li>Increment <i>n</i> by 1.</li>
+ </ol>
+ </li>
+ <li>Return <i>array</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-createlistfromarraylike">
+ <h1><span class="secnum" id="sec-7.3.14"><a href="#sec-createlistfromarraylike"
+ title="link to this section">7.3.14</a></span> CreateListFromArrayLike (obj)</h1>
+
+ <p>The abstract operation <span style="font-family: Times New Roman">CreateListFromArrayLike</span> is used to create a <a
+ href="#sec-list-and-record-specification-type">List</a> value whose elements are provided by the indexed properties of an
+ array-like object. This abstract operation performs the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>obj</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>obj</i>) is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>Let <i>len</i> be <a href="#sec-get-o-p">Get</a>(<i>obj</i>, <code>"length"</code>).</li>
+ <li>Let <i>n</i> be <a href="#sec-tolength">ToLength</a>(<i>len</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>n</i>).</li>
+ <li>Let <i>list</i> be an empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Let <i>index</i> be 0.</li>
+ <li>Repeat while <i>index</i> < <i>n</i>
+ <ol class="block">
+ <li>Let <i>indexName</i> be <a href="#sec-tostring">ToString</a>(<i>index</i>).</li>
+ <li>Let <i>next</i> be <a href="#sec-get-o-p">Get</a>(<i>obj</i>, <i>indexName</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>next</i>).</li>
+ <li>Append <i>next</i> as the last element of <i>list</i>.</li>
+ <li>Set <i>index</i> to <i>index</i> + 1.</li>
+ </ol>
+ </li>
+ <li>Return <i>list</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-ordinaryhasinstance">
+ <h1><span class="secnum" id="sec-7.3.15"><a href="#sec-ordinaryhasinstance" title="link to this section">7.3.15</a></span>
+ OrdinaryHasInstance (C, O)</h1>
+
+ <p>The abstract operation <span style="font-family: Times New Roman">OrdinaryHasInstance</span> implements the default
+ algorithm for determining if an object <var>O</var> inherits from the instance object inheritance path provided by
+ constructor <var>C</var>. This abstract operation performs the following steps:</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>C</i>) is <b>false</b>, return <b>false</b>.</li>
+ <li>If <i>C</i> has a <a href="#sec-bound-function-exotic-objects">[[BoundTargetFunction]]</a> <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, then
+ <ol class="block">
+ <li>Let <i>BC</i> be the value of <i>C’s</i> <a
+ href="#sec-bound-function-exotic-objects">[[BoundTargetFunction]]</a> <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Return <a href="#sec-instanceofoperator">InstanceofOperator</a>(<i>O</i>,<i>BC</i>) (<a
+ href="#sec-instanceofoperator">see 12.9.4</a>).</li>
+ </ol>
+ </li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object, return <b>false</b>.</li>
+ <li>Let <i>P</i> be <a href="#sec-get-o-p">Get</a>(<i>C</i>, <code>"prototype"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>P</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>P</i>) is not Object, throw a <b>TypeError</b>
+ exception.</li>
+ <li>Repeat
+ <ol class="block">
+ <li>Set <i>O</i> to the result of calling the [[GetPrototypeOf]] internal method of <i>O</i> with no arguments.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>O</i>).</li>
+ <li>If <i>O</i> is <code>null</code>, return <b>false</b>.</li>
+ <li>If <a href="#sec-samevalue">SameValue</a>(<i>P</i>, <i>O</i>) is <b>true</b>, return <b>true</b>.</li>
+ </ol>
+ </li>
+ </ol>
+ </section>
+
+ <section id="sec-getprototypefromconstructor">
+ <h1><span class="secnum" id="sec-7.3.16"><a href="#sec-getprototypefromconstructor"
+ title="link to this section">7.3.16</a></span> GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )</h1>
+
+ <p>The abstract operation <span style="font-family: Times New Roman">GetPrototypeFromConstructor</span> determines the
+ [[Prototype]] value that should be used to create an object corresponding to a specific constructor. The value is retrieved
+ from the constructor’s <code>prototype</code> property, if it exists. Otherwise the supplied default is used for
+ [[Prototype]]. This abstract operation performs the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>intrinsicDefaultProto</i> is a string value that is this
+ specification’s name of an intrinsic object. The corresponding object must be an intrinsic that is intended to
+ be used as the [[Prototype]] value of an object.</li>
+ <li>If <a href="#sec-isconstructor">IsConstructor</a> (<i>constructor</i>) is <b>false</b>, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>Let <i>proto</i> be <a href="#sec-get-o-p">Get</a>(<i>constructor</i>, <code>"prototype"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>proto</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>proto</i>) is not Object, then
+ <ol class="block">
+ <li>If <i>constructor</i> has a [[Realm]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>,
+ let <i>realm</i> be <i>constructor’s</i> [[Realm]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>ctx</i> be <a href="#sec-execution-contexts">the running execution context</a>.</li>
+ <li>Let <i>realm</i> be <i>ctx’s</i> <a href="#sec-code-realms">Realm</a>.</li>
+ </ol>
+ </li>
+ <li>Let <i>proto</i> be <i>realm’s</i> intrinsic object named <i>intrinsicDefaultProto</i>.</li>
+ </ol>
+ </li>
+ <li>Return <i>proto</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> If <i>constructor</i> does not supply a [[Prototype]] value, the default value that is
+ used is obtained from the <a href="#sec-code-realms">Code Realm</a> of the <i>constructor</i> function rather than from <a
+ href="#sec-execution-contexts">the running execution context</a>. This accounts for the possibility that a built-in
+ @@create method from a different <a href="#sec-code-realms">Code Realm</a> might be installed on <i>constructor</i>.</p>
+ </div>
+ </section>
+
+ <section id="sec-createfromconstructor">
+ <h1><span class="secnum" id="sec-7.3.17"><a href="#sec-createfromconstructor" title="link to this section">7.3.17</a></span>
+ CreateFromConstructor (F)</h1>
+
+ <p>When the abstract operation CreateFromConstructor is called with Object <var>F</var> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>creator</i> be <a href="#sec-getmethod">GetMethod</a> (<i>F</i>, @@create).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>creator</i>).</li>
+ <li>If <i>creator</i> is <b>undefined</b>, then return <b>undefined</b>.</li>
+ <li>Let <i>obj</i> be the result of calling the [[Call]] internal method of <i>creator</i> with arguments <i>F</i> and an
+ empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>obj</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>obj</i>) is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>Return <i>obj</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> This operation is equivalent to: <code>F[Symbol.create]()</code><span style="font-family:
+ sans-serif">followed by an error check.</span></p>
+ </div>
+ </section>
+
+ <section id="sec-construct-f-argumentslist">
+ <h1><span class="secnum" id="sec-7.3.18"><a href="#sec-construct-f-argumentslist"
+ title="link to this section">7.3.18</a></span> Construct (F, argumentsList)</h1>
+
+ <p>When the abstract operation Construct is called with Object <var>F</var> and <a
+ href="#sec-list-and-record-specification-type">List</a> <var>argumentsList</var> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>F</i>) is
+ Object.</li>
+ <li>Let <i>obj</i> be <a href="#sec-createfromconstructor">CreateFromConstructor</a>(<i>F</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>obj</i>).</li>
+ <li>If <i>obj</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>obj</i> be <a href="#sec-ordinarycreatefromconstructor">OrdinaryCreateFromConstructor</a>(<i>F</i>,
+ <code>"%ObjectPrototype%"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>obj</i>).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>obj</i>) is Object.</li>
+ </ol>
+ </li>
+ <li>Let <i>result</i> be the result of calling the [[Call]] internal method of <i>F</i>, providing <i>obj</i> and
+ <i>argumentsList</i> as the arguments.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>result</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>result</i>) is Object then return <i>result</i>.</li>
+ <li>Return <i>obj</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> This operation is equivalent to: <code>new F(...argumentsList)</code></p>
+ </div>
+ </section>
+
+ <section id="sec-getoption">
+ <h1><span class="secnum" id="sec-7.3.19"><a href="#sec-getoption" title="link to this section">7.3.19</a></span> GetOption
+ (options, P)</h1>
+
+ <p>The abstract operation <span style="font-family: Times New Roman">GetOption</span> is used to retrieve the value of a
+ specific property of an object in situation where the object may not be present. The operation is called with arguments
+ <var>options</var> and <var>P</var> where <var>options</var> is the object and <var>P</var> is the <a
+ href="#sec-object-type">property key</a>. This abstract operation performs the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ispropertykey">IsPropertyKey</a>(<i>P</i>) is
+ <b>true</b>.</li>
+ <li>If <i>options</i> is <b>undefined</b>, then return <b>undefined</b>.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>options</i>) is not Object, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>Return the result of calling the [[Get]] internal method of <i>options</i> passing <i>P</i> and <i>options</i> as the
+ arguments.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-operations-on-iterator-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-7.4"><a href="#sec-operations-on-iterator-objects"
+ title="link to this section">7.4</a></span> Operations on Iterator Objects</h1>
+
+ <p>See Commmon Iteration Interfaces (<a href="#sec-common-iteration-interfaces">25.1</a>).</p>
+ </div>
+
+ <section id="sec-checkiterable">
+ <h1><span class="secnum" id="sec-7.4.1"><a href="#sec-checkiterable" title="link to this section">7.4.1</a></span>
+ CheckIterable ( obj )</h1>
+
+ <p>The abstract operation CheckIterable with argument <var>obj</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>obj</i>) is not Object, then return
+ <b>undefined</b>.</li>
+ <li>Let <i>iteratorGetter</i> be <a href="#sec-get-o-p">Get</a>(<i>obj</i>, @@iterator).</li>
+ <li>Return <i>iteratorGetter</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-getiterator">
+ <h1><span class="secnum" id="sec-7.4.2"><a href="#sec-getiterator" title="link to this section">7.4.2</a></span> GetIterator
+ ( obj, method )</h1>
+
+ <p>The abstract operation GetIterator with argument <span style="font-family: Times New Roman"><i>obj</i> and</span>
+ optional argument <var>method</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>If <i>method</i> was not passed, then
+ <ol class="block">
+ <li>Let <i>method</i> be <a href="#sec-checkiterable">CheckIterable</a>(<i>obj</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>method</i>).</li>
+ </ol>
+ </li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>method</i>) is <b>false</b>, then throw a <b>TypeError</b>
+ exception<i>.</i></li>
+ <li>Let <i>iterator</i> be the result of calling the [[Call]] internal method of <i>method</i> with <i>obj</i> as
+ <i>thisArgument</i> and an empty <a href="#sec-list-and-record-specification-type">List</a> as
+ <i>argumentsList</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>iterator</i>)<i>.</i></li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>iterator</i>) is not Object, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>Return <i>iterator</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-iteratornext">
+ <h1><span class="secnum" id="sec-7.4.3"><a href="#sec-iteratornext" title="link to this section">7.4.3</a></span>
+ IteratorNext ( iterator, value )</h1>
+
+ <p>The abstract operation IteratorNext with argument <var>iterator</var> and optional argument <var>value</var> performs the
+ following steps:</p>
+
+ <ol class="proc">
+ <li>If <i>value</i> was not passed,
+ <ol class="block">
+ <li>Let <i>result</i> be <a href="#sec-invoke">Invoke</a>(<i>iterator</i>, <code>"next"</code>, ( )).</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>result</i> be <a href="#sec-invoke">Invoke</a>(<i>iterator</i>, <code>"next"</code>, (<i>value</i>)).</li>
+ </ol>
+ </li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>result</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>result</i>) is not Object, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>Return <i>result</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-iteratorcomplete">
+ <h1><span class="secnum" id="sec-7.4.4"><a href="#sec-iteratorcomplete" title="link to this section">7.4.4</a></span>
+ IteratorComplete ( iterResult )</h1>
+
+ <p>The abstract operation IteratorComplete with argument <var>iterResult</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>iterResult</i>) is Object.</li>
+ <li>Let <i>done</i> be <a href="#sec-get-o-p">Get</a>(<i>iterResult</i>, <code>"done"</code>).</li>
+ <li>Return <a href="#sec-toboolean">ToBoolean</a>(<i>done</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-iteratorvalue">
+ <h1><span class="secnum" id="sec-7.4.5"><a href="#sec-iteratorvalue" title="link to this section">7.4.5</a></span>
+ IteratorValue ( iterResult )</h1>
+
+ <p>The abstract operation IteratorValue with argument <var>iterResult</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>iterResult</i>) is Object.</li>
+ <li>Return <a href="#sec-get-o-p">Get</a>(<i>iterResult</i>, <code>"value"</code>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-iteratorstep">
+ <h1><span class="secnum" id="sec-7.4.6"><a href="#sec-iteratorstep" title="link to this section">7.4.6</a></span>
+ IteratorStep ( iterator )</h1>
+
+ <p>The abstract operation IteratorStep with argument <var>iterator</var> requests the next value from <var>iterator</var>
+ and returns either <span class="value">false</span> indicating that the iterator has reached its end or the IteratorResult
+ object if a next value is available. IteratorStep performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>result</i> be <a href="#sec-iteratornext">IteratorNext</a>(<i>iterator</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>result</i>).</li>
+ <li>Let <i>done</i> be <a href="#sec-iteratorcomplete">IteratorComplete</a>(<i>result</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>done</i>).</li>
+ <li>If <i>done</i> is <b>true</b>, then return <b>false</b>.</li>
+ <li>Return <i>result</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-createiterresultobject">
+ <h1><span class="secnum" id="sec-7.4.7"><a href="#sec-createiterresultobject" title="link to this section">7.4.7</a></span>
+ CreateIterResultObject (value, done)</h1>
+
+ <p>The abstract operation CreateIterResultObject with arguments <var>value</var> and <var>done</var> creates an object that
+ supports the IteratorResult interface by performing the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>done</i>)
+ is Boolean.</li>
+ <li>Let <i>obj</i> be <a href="#sec-objectcreate">ObjectCreate</a>(<span style="font-family:
+ sans-serif">%ObjectPrototype%</span>).</li>
+ <li>Perform <a href="#sec-createdataproperty">CreateDataProperty</a>(<i>obj</i>, <code>"value"</code>, <i>value</i>).</li>
+ <li>Perform <a href="#sec-createdataproperty">CreateDataProperty</a>(<i>obj</i>, <code>"done"</code>, <i>done</i>).</li>
+ <li>Return <i>obj</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-createlistiterator">
+ <div class="front">
+ <h1><span class="secnum" id="sec-7.4.8"><a href="#sec-createlistiterator" title="link to this section">7.4.8</a></span>
+ CreateListIterator (list)</h1>
+
+ <p>The abstract operation CreateListIterator with argument <var>list</var> creates an Iterator (<a
+ href="#sec-iterator-interface">25.1.2</a>) object whose next method returns the successive elements of <var>list</var>. It
+ performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>iterator</i> be <a href="#sec-objectcreate">ObjectCreate</a>(%ObjectPrototype%, ([[IteratedList]],
+ [[ListIteratorNextIndex]])).</li>
+ <li>Set <i>iterator’s</i> [[IteratedList]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> to <i>list</i>.</li>
+ <li>Set <i>iterator’s</i> [[ListIteratorNextIndex]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to 0.</li>
+ <li>Define ListIterator <code>next</code> (<a href="#sec-listiterator-next">7.4.8.1</a>) as an own property of
+ <i>iterator</i>.</li>
+ <li>Return <i>iterator</i>.</li>
+ </ol>
+ </div>
+
+ <section id="sec-listiterator-next">
+ <h1><span class="secnum" id="sec-7.4.8.1"><a href="#sec-listiterator-next" title="link to this section">7.4.8.1</a></span>
+ ListIterator next( )</h1>
+
+ <p>The ListIterator <code>next</code> method is a standard built-in function object (<a
+ href="#sec-ecmascript-standard-built-in-objects">clause 17</a>) that performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>If <i>O</i> does not have a [[IteratedList]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>list</i> be the value of the [[IteratedList]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>Let <i>index</i> be the value of the [[ListIteratorNextIndex]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>Let <i>len</i> be the number of elements of <i>list</i>.</li>
+ <li>If <i>index</i> ≥ <i>len</i>, then
+ <ol class="block">
+ <li>Return <a href="#sec-createiterresultobject">CreateIterResultObject</a>(<b>undefined</b>, <b>true</b>).</li>
+ </ol>
+ </li>
+ <li>Set the value of the [[ListIteratorNextIndex]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> of <i>O</i> to <i>index</i>+1.</li>
+ <li>Return <a href="#sec-createiterresultobject">CreateIterResultObject</a>(<i>list</i>[<i>index</i>],
+ <b>false</b>).</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-createemptyiterator">
+ <h1><span class="secnum" id="sec-7.4.9"><a href="#sec-createemptyiterator" title="link to this section">7.4.9</a></span>
+ CreateEmptyIterator ( )</h1>
+
+ <p>The abstract operation CreateEmptyIterator with no arguments creates an Iterator object whose next method always reports
+ that the iterator is done. It performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>empty</i> be a <a href="#sec-list-and-record-specification-type">List</a> with no elements.</li>
+ <li>Return <a href="#sec-createlistiterator">CreateListIterator</a>(<i>empty</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-createcompounditerator">
+ <div class="front">
+ <h1><span class="secnum" id="sec-7.4.10"><a href="#sec-createcompounditerator"
+ title="link to this section">7.4.10</a></span> CreateCompoundIterator ( iterator1, iterator2 )</h1>
+
+ <p>The abstract operation CreateCompoundIterator with arguments <var>iterator1</var> and <var>iterator2</var> creates an
+ Iterator (<a href="#sec-iterator-interface">25.1.2</a>) object whose next method returns the successive elements of
+ <var>iterator1</var> followed by the successive elements of <var>iterator2</var>. It performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>iterator</i> be <a href="#sec-objectcreate">ObjectCreate</a>(%ObjectPrototype%, ([[Iterator1]],
+ [[Iterator2]], [[State]])).</li>
+ <li>Set <i>iterator’s</i> [[Iterator1]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> to <i>iterator1</i>.</li>
+ <li>Set <i>iterator’s</i> [[Iterator2]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> to <i>iterator2</i>.</li>
+ <li>Set <i>iterator’s</i> [[State]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to
+ 1.</li>
+ <li>Define CompundIterator <code>next</code> (<a href="#sec-compounditerator-next">7.4.10.1</a>) as an own property of
+ <i>iterator</i>.</li>
+ <li>Return <i>iterator</i>.</li>
+ </ol>
+ </div>
+
+ <section id="sec-compounditerator-next">
+ <h1><span class="secnum" id="sec-7.4.10.1"><a href="#sec-compounditerator-next"
+ title="link to this section">7.4.10.1</a></span> CompoundIterator next( )</h1>
+
+ <p>The CompoundIterator <code>next</code> method is a standard built-in function object that performs the following
+ steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>If <i>O</i> does not have a [[Iterator1]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a>, then throw a <b>TypeError</b> exception.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>O</i> is an object created and initialized by <a
+ href="#sec-createcompounditerator">CreateCompoundIterator</a>.</li>
+ <li>Let <i>state</i> be the value of <i>O’s</i> [[State] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>state</i> = 1, then
+ <ol class="block">
+ <li>Let <i>iterator1</i> be the value of <i>O’s</i> [[Iterator1] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>result1</i> be <a href="#sec-iteratorstep">IteratorStep</a>(<i>iterator1</i>).</li>
+ <li>If <i>result1</i> is not <b>false</b>, then,
+ <ol class="block">
+ <li>Return <i>result1.</i></li>
+ </ol>
+ </li>
+ <li>Set <i>O’s</i> [[State] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to
+ 2.</li>
+ </ol>
+ </li>
+ <li>Let <i>iterator2</i> be the value of <i>O’s</i> [[Iterator2] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Return <a href="#sec-iteratornext">IteratorNext</a>(<i>iterator2</i>).</li>
+ </ol>
+ </section>
+ </section>
+ </section>
+
+ <section id="sec-operations-on-promise-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-7.5"><a href="#sec-operations-on-promise-objects"
+ title="link to this section">7.5</a></span> Operations on Promise Objects</h1>
+
+ <p>Promise Objects (<a href="#sec-promise-objects">25.4</a>) serve as a placeholder for the eventual result of a deferred
+ (and possibly asynchronous) computation.</p>
+
+ <p>Within this specification the adjective “eventual” mean a value or a Promise object that will ultimately
+ resolves to the value. For example, “Returns an eventual String” is equivalent to “Returns either a
+ String or a Promise object that will eventually resolves to a String”. A “resolved value” is the final
+ value of an “eventual value”.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The Promise related abstract operations defined in this subclause are used by
+ specification algorithms when they perform or respond to asynchronous operations. They ensure that the actual built-in
+ Promise operations are used by the algorithms, even if ECMAScript code has modified the properties of %Promise% or
+ %PromisePrototype%.</p>
+ </div>
+ </div>
+
+ <section id="sec-promisenew">
+ <h1><span class="secnum" id="sec-7.5.1"><a href="#sec-promisenew" title="link to this section">7.5.1</a></span> PromiseNew (
+ executor ) Abstract Operation</h1>
+
+ <p>The abstract operation PromiseNew allocates and initializes a new <var>promise</var> object for use by specification
+ algorithm. The <var>executor</var> argument initiates the deferred computation.</p>
+
+ <ol class="proc">
+ <li>Let <i>promise</i> be <a href="#sec-allocatepromise">AllocatePromise</a>(%Promise%).</li>
+ <li>Return <a href="#sec-initializepromise">InitializePromise</a>(<i>promise</i>, <i>executor</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-promisebuiltincapability">
+ <h1><span class="secnum" id="sec-7.5.2"><a href="#sec-promisebuiltincapability"
+ title="link to this section">7.5.2</a></span> PromiseBuiltinCapability () Abstract Operation</h1>
+
+ <p>The abstract operation PromiseBuiltinCapability allocates a PromiseCapability record (<a
+ href="#sec-promisecapability-records">25.4.1.1</a>) for a builtin <var>promise</var> object for use by specification
+ algorithm.</p>
+
+ <ol class="proc">
+ <li>Let <i>promise</i> be <a href="#sec-allocatepromise">AllocatePromise</a>(%Promise%).</li>
+ <li>Return <a href="#sec-createpromisecapabilityrecord">CreatePromiseCapabilityRecord</a>(<i>promise</i>, %Promise%).</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> This abstract operation is the same as the default built-in behaviour of <a
+ href="#sec-newpromisecapability">NewPromiseCapability</a> abstract operation (<a
+ href="#sec-fulfillpromise">25.4.1.5</a>).</p>
+ </div>
+ </section>
+
+ <section id="sec-promiseof">
+ <h1><span class="secnum" id="sec-7.5.3"><a href="#sec-promiseof" title="link to this section">7.5.3</a></span> PromiseOf
+ (value) Abstract Operation</h1>
+
+ <p>The abstract operation PromiseOf returns a new Promise that resolves to the argument <var>value</var>.</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ispromise">IsPromise</a>(<i>value</i>) is
+ <b>false</b>.</li>
+ <li>Let <i>capability</i> be <a href="#sec-promisebuiltincapability">PromiseBuiltinCapability</a>( ).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>capability</i>).</li>
+ <li>Let <i>resolveResult</i> be the result of calling the [[Call]] internal method of <i>capability</i>.[[Resolve]] with
+ <b>undefined</b> as <i>thisArgument</i> and (<i>value</i>) as <i>argumentsList</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>resolveResult</i>).</li>
+ <li>Return <i>capability</i>.[[Promise]].</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> This abstract operation is the same as the default built-in behaviour of the <a
+ href="#sec-promise.resolve">Promise.resolve</a> method (<a href="#sec-promise.resolve">25.4.4.5</a>). However, PromiseOf
+ does not accept a Promise is its argument.</p>
+ </div>
+ </section>
+
+ <section id="sec-promiseall">
+ <h1><span class="secnum" id="sec-7.5.4"><a href="#sec-promiseall" title="link to this section">7.5.4</a></span> PromiseAll
+ (promiseList) Abstract Operation</h1>
+ </section>
+
+ <section id="sec-promisecatch">
+ <h1><span class="secnum" id="sec-7.5.5"><a href="#sec-promisecatch" title="link to this section">7.5.5</a></span>
+ PromiseCatch (promise, rejectedAction) Abstract Operation</h1>
+ </section>
+
+ <section id="sec-promisethen">
+ <h1><span class="secnum" id="sec-7.5.6"><a href="#sec-promisethen" title="link to this section">7.5.6</a></span> PromiseThen
+ (promise, resolvedAction, rejectedAction) Abstract Operation</h1>
+ </section>
+ </section>
+</section>
+
+<section id="sec-executable-code-and-execution-contexts">
+ <div class="front">
+ <h1><span class="secnum" id="sec-8"><a href="#sec-executable-code-and-execution-contexts"
+ title="link to this section">8</a></span> Executable Code and Execution Contexts</h1>
+ </div>
+
+ <section id="sec-lexical-environments">
+ <div class="front">
+ <h1><span class="secnum" id="sec-8.1"><a href="#sec-lexical-environments" title="link to this section">8.1</a></span>
+ Lexical Environments</h1>
+
+ <p>A <i>Lexical Environment</i> is a specification type used to define the association of <span
+ class="nt">Identifiers</span> to specific variables and functions based upon the lexical nesting structure of ECMAScript
+ code. A Lexical Environment consists of an <a href="#sec-environment-records">Environment Record</a> and a possibly null
+ reference to an <i>outer</i> Lexical Environment. Usually a Lexical Environment is associated with some specific syntactic
+ structure of ECMAScript code such as a <span class="nt">FunctionDeclaration</span>, a <span
+ class="nt">BlockStatement</span>, or a <span class="nt">Catch</span> clause of a <span class="nt">TryStatement</span> and a
+ new Lexical Environment is created each time such code is evaluated.</p>
+
+ <p>An <i><a href="#sec-environment-records">Environment Record</a></i> records the identifier bindings that are created
+ within the scope of its associated Lexical Environment.</p>
+
+ <p>The outer environment reference is used to model the logical nesting of Lexical Environment values. The outer reference
+ of a (inner) Lexical Environment is a reference to the Lexical Environment that logically surrounds the inner Lexical
+ Environment. An outer Lexical Environment may, of course, have its own outer Lexical Environment. A Lexical Environment may
+ serve as the outer environment for multiple inner Lexical Environments. For example, if a <span
+ class="nt">FunctionDeclaration</span> contains two nested <span class="nt">FunctionDeclarations</span> then the Lexical
+ Environments of each of the nested functions will have as their outer Lexical Environment the Lexical Environment of the
+ current evaluation of the surrounding function.</p>
+
+ <p>A <i>global environment</i> is a Lexical Environment which does not have an outer environment. The global
+ environment’s outer environment reference is <b>null</b>. A global environment’s environment record may be
+ prepopulated with identifier bindings and includes an associated <i>global object</i> whose properties provide some of <a
+ href="#sec-global-environment-records">the global environment</a>’s identifier bindings. This global object is the
+ value of a global environment’s <code>this</code> binding. As ECMAScript code is executed, additional properties may
+ be added to the global object and the initial properties may be modified.</p>
+
+ <p>A method environment is a Lexical Environment that corresponds to the invocation of an <a
+ href="#sec-ecmascript-function-objects">ECMAScript function object</a> that establishes a new <code>this</code> binding. A
+ method environment also captures the state necessary to support <code>super</code> method invocations.</p>
+
+ <p>Lexical Environments and <a href="#sec-environment-records">Environment Record</a> values are purely specification
+ mechanisms and need not correspond to any specific artefact of an ECMAScript implementation. It is impossible for an
+ ECMAScript program to directly access or manipulate such values.</p>
+ </div>
+
+ <section id="sec-environment-records">
+ <div class="front">
+ <h1><span class="secnum" id="sec-8.1.1"><a href="#sec-environment-records" title="link to this section">8.1.1</a></span>
+ Environment Records</h1>
+
+ <p>There are two primary kinds of Environment Record values used in this specification: <i>declarative environment
+ records</i> and <i>object environment records</i>. Declarative environment records are used to define the effect of
+ ECMAScript language syntactic elements such as <span class="nt">FunctionDeclarations</span>, <span
+ class="nt">VariableDeclarations</span>, and <span class="nt">Catch</span> clauses that directly associate identifier
+ bindings with <a href="#sec-ecmascript-language-types">ECMAScript language values</a>. Object environment records are used
+ to define the effect of ECMAScript elements such as <span class="nt">WithStatement</span> that associate identifier
+ bindings with the properties of some object. <a href="#sec-global-environment-records">Global Environment Records</a> and
+ <a href="#sec-function-environment-records">Function Environment Records</a> are specializations that are used for
+ specifically for <span class="nt">Script</span> global declarations and for top-level declarations within functions.</p>
+
+ <p>For specification purposes Environment Record values can be thought of as existing in a simple object-oriented
+ hierarchy where Environment Record is an abstract class with three concrete subclasses, <a
+ href="#sec-declarative-environment-records">declarative environment record</a>, <a
+ href="#sec-object-environment-records">object environment record</a>, and <a href="#sec-global-environment-records">global
+ environment record</a>. Function environment records are a subclass of <a
+ href="#sec-declarative-environment-records">declarative environment record</a>. The abstract class includes the abstract
+ specification methods defined in <a href="#table-16">Table 16</a>. These abstract methods have distinct concrete
+ algorithms for each of the concrete subclasses.</p>
+
+ <figure>
+ <figcaption><span id="table-16">Table 16</span> — Abstract Methods of Environment Records</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-top: 2px solid #000000">Method</th>
+ <th style="border-bottom: 1px solid #000000; border-right: 1px solid #000000; border-top: 2px solid #000000">Purpose</th>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black">HasBinding(N)</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black">Determine if an environment record has a binding for an identifier. Return <b>true</b> if it does and <b>false</b> if it does not. The String value <var>N</var> is the text of the identifier.</td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">CreateMutableBinding(N, D)</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">Create a new but uninitialized mutable binding in an environment record. The String value <var>N</var> is the text of the bound name. If the optional Boolean argument <var>D</var> is <b>true</b> the binding is may be subsequently deleted.</td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">CreateImmutableBinding(N)</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">Create a new but uninitialized immutable binding in an environment record. The String value N is the text of the bound name.</td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">InitializeBinding(N,V)</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">Set the value of an already existing but uninitialized binding in an environment record. The String value N is the text of the bound name. V is the value for the binding and is a value of any <a href="#sec-ecmascript-language-types">ECMAScript language type</a>.</td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">SetMutableBinding(N,V, S)</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">Set the value of an already existing mutable binding in an environment record. The String value <var>N</var> is the text of the bound name. <var>V</var> is the value for the binding and may be a value of any <a href="#sec-ecmascript-language-types">ECMAScript language type</a>. <var>S</var> is a Boolean flag. If <var>S</var> is <b>true</b> and the binding cannot be set throw a <b>TypeError</b> exception. <var>S</var> is used to identify strict mode references.</td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">GetBindingValue(N,S)</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">Returns the value of an already existing binding from an environment record. The String value <var>N</var> is the text of the bound name. <var>S</var> is used to identify strict mode references. If <var>S</var> is <b>true</b> and the binding does not exist throw a <b>ReferenceError</b> exception. If the binding exists but is uninitialized a <b>ReferenceError</b> is thrown, regardless of the value of <i><span style="font-family: Times New Roman">S</span>.</i></td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">DeleteBinding(N)</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">Delete a binding from an environment record. The String value <var>N</var> is the text of the bound name If a binding for <var>N</var> exists, remove the binding and return <b>true</b>. If the binding exists but cannot be removed return <b>false</b>. If the binding does not exist return <b>true</b>.</td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">HasThisBinding()</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">Determine if an environment record establishes a <code>this</code> binding. Return <b>true</b> if it does and <b>false</b> if it does not.</td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">HasSuperBinding()</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">Determine if an environment record establishes a <code>super</code> method binding. Return <b>true</b> if it does and <b>false</b> if it does not.</td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">WithBaseObject ()</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">If this environment record is associated with a <code>with</code> statement, return the with object. Otherwise, return <span class="value">undefined</span>.</td>
+ </tr>
+ </table>
+ </figure>
+ </div>
+
+ <section id="sec-declarative-environment-records">
+ <div class="front">
+ <h1><span class="secnum" id="sec-8.1.1.1"><a href="#sec-declarative-environment-records"
+ title="link to this section">8.1.1.1</a></span> Declarative Environment Records</h1>
+
+ <p>Each declarative environment record is associated with an ECMAScript program scope containing variable, constant,
+ let, class, module, import, and/or function declarations. A declarative environment record binds the set of identifiers
+ defined by the declarations contained within its scope.</p>
+
+ <p>The behaviour of the concrete specification methods for Declarative Environment Records is defined by the following
+ algorithms.</p>
+ </div>
+
+ <section id="sec-declarative-environment-records-hasbinding-n">
+ <h1><span class="secnum" id="sec-8.1.1.1.1"><a href="#sec-declarative-environment-records-hasbinding-n"
+ title="link to this section">8.1.1.1.1</a></span> HasBinding(N)</h1>
+
+ <p>The concrete environment record method HasBinding for declarative environment records simply determines if the
+ argument identifier is one of the identifiers bound by the record:</p>
+
+ <ol class="proc">
+ <li>Let <i>envRec</i> be the <a href="#sec-declarative-environment-records">declarative environment record</a> for
+ which the method was invoked.</li>
+ <li>If <i>envRec</i> has a binding for the name that is the value of <i>N</i>, return <b>true</b>.</li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-declarative-environment-records-createmutablebinding-n-d">
+ <h1><span class="secnum" id="sec-8.1.1.1.2"><a href="#sec-declarative-environment-records-createmutablebinding-n-d"
+ title="link to this section">8.1.1.1.2</a></span> CreateMutableBinding (N, D)</h1>
+
+ <p>The concrete <a href="#sec-environment-records">Environment Record</a> method CreateMutableBinding for declarative
+ environment records creates a new mutable binding for the name <var>N</var> that is uninitialized. A binding must not
+ already exist in this <a href="#sec-environment-records">Environment Record</a> for <var>N</var>. If Boolean argument
+ <var>D</var> is provided and has the value <b>true</b> the new binding is marked as being subject to deletion.</p>
+
+ <ol class="proc">
+ <li>Let <i>envRec</i> be the <a href="#sec-declarative-environment-records">declarative environment record</a> for
+ which the method was invoked.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>envRec</i> does not already have a binding for <i>N</i>.</li>
+ <li>Create a mutable binding in <i>envRec</i> for <i>N</i> and record that it is uninitialized. If <i>D</i> is
+ <b>true</b> record that the newly created binding may be deleted by a subsequent DeleteBinding call.</li>
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<span style="font-family:
+ sans-serif">empty</span>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-declarative-environment-records-createimmutablebinding-n">
+ <h1><span class="secnum" id="sec-8.1.1.1.3"><a href="#sec-declarative-environment-records-createimmutablebinding-n"
+ title="link to this section">8.1.1.1.3</a></span> CreateImmutableBinding (N)</h1>
+
+ <p>The concrete <a href="#sec-environment-records">Environment Record</a> method CreateImmutableBinding for declarative
+ environment records creates a new immutable binding for the name <var>N</var> that is uninitialized. A binding must not
+ already exist in this environment record for <var>N</var>.</p>
+
+ <ol class="proc">
+ <li>Let <i>envRec</i> be the <a href="#sec-declarative-environment-records">declarative environment record</a> for
+ which the method was invoked.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>envRec</i> does not already have a binding for <i>N</i>.</li>
+ <li>Create an immutable binding in <i>envRec</i> for <i>N</i> and record that it is uninitialized.</li>
+ </ol>
+ </section>
+
+ <section id="sec-declarative-environment-records-initializebinding-n-v">
+ <h1><span class="secnum" id="sec-8.1.1.1.4"><a href="#sec-declarative-environment-records-initializebinding-n-v"
+ title="link to this section">8.1.1.1.4</a></span> InitializeBinding (N,V)</h1>
+
+ <p>The concrete <a href="#sec-environment-records">Environment Record</a> method InitializeBinding for declarative
+ environment records is used to set the bound value of the current binding of the identifier whose name is the value of
+ the argument <var>N</var> to the value of argument <var>V</var>. An uninitialized binding for <var>N</var> must already
+ exist.</p>
+
+ <ol class="proc">
+ <li>Let <i>envRec</i> be the <a href="#sec-declarative-environment-records">declarative environment record</a> for
+ which the method was invoked.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>envRec</i> must have an uninitialized binding for
+ <i>N</i>.</li>
+ <li>Set the bound value for <i>N</i> in <i>envRec</i> to <i>V</i>.</li>
+ <li>Record that the binding for <i>N</i> in <i>envRec</i> has been initialized.</li>
+ </ol>
+ </section>
+
+ <section id="sec-declarative-environment-records-setmutablebinding-n-v-s">
+ <h1><span class="secnum" id="sec-8.1.1.1.5"><a href="#sec-declarative-environment-records-setmutablebinding-n-v-s"
+ title="link to this section">8.1.1.1.5</a></span> SetMutableBinding (N,V,S)</h1>
+
+ <p>The concrete <a href="#sec-environment-records">Environment Record</a> method SetMutableBinding for declarative
+ environment records attempts to change the bound value of the current binding of the identifier whose name is the value
+ of the argument <var>N</var> to the value of argument <var>V</var>. A binding for <var>N</var> must already exist. If
+ the binding is an immutable binding, a <b>TypeError</b> is thrown if <span style="font-family: Times New Roman">S</span>
+ is <span class="value">true</span>.</p>
+
+ <ol class="proc">
+ <li>Let <i>envRec</i> be the <a href="#sec-declarative-environment-records">declarative environment record</a> for
+ which the method was invoked.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>envRec</i> must have a binding for <i>N</i>.</li>
+ <li>If the binding for <i>N</i> in <i>envRec</i> has not yet been initialized throw a <b>ReferenceError</b>
+ exception.</li>
+ <li>Else if the binding for <i>N</i> in <i>envRec</i> is a mutable binding, change its bound value to <i>V</i>.</li>
+ <li>Else this must be an attempt to change the value of an immutable binding so if <i>S</i> is <b>true</b> throw a
+ <b>TypeError</b> exception.</li>
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<span style="font-family:
+ sans-serif">empty</span>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-declarative-environment-records-getbindingvalue-n-s">
+ <h1><span class="secnum" id="sec-8.1.1.1.6"><a href="#sec-declarative-environment-records-getbindingvalue-n-s"
+ title="link to this section">8.1.1.1.6</a></span> GetBindingValue(N,S)</h1>
+
+ <p>The concrete <a href="#sec-environment-records">Environment Record</a> method GetBindingValue for declarative
+ environment records simply returns the value of its bound identifier whose name is the value of the argument
+ <var>N</var>. If the binding exists but is uninitialized a <b>ReferenceError</b> is thrown, regardless of the value of
+ <i><span style="font-family: Times New Roman">S</span>.</i></p>
+
+ <ol class="proc">
+ <li>Let <i>envRec</i> be the <a href="#sec-declarative-environment-records">declarative environment record</a> for
+ which the method was invoked.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>envRec</i> has a binding for <i>N</i>.</li>
+ <li>If the binding for <i>N</i> in <i>envRec</i> is an uninitialized binding, then throw a <b>ReferenceError</b>
+ exception.</li>
+ <li>Return the value currently bound to <i>N</i> in <i>envRec</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-declarative-environment-records-deletebinding-n">
+ <h1><span class="secnum" id="sec-8.1.1.1.7"><a href="#sec-declarative-environment-records-deletebinding-n"
+ title="link to this section">8.1.1.1.7</a></span> DeleteBinding (N)</h1>
+
+ <p>The concrete <a href="#sec-environment-records">Environment Record</a> method DeleteBinding for declarative
+ environment records can only delete bindings that have been explicitly designated as being subject to deletion.</p>
+
+ <ol class="proc">
+ <li>Let <i>envRec</i> be the <a href="#sec-declarative-environment-records">declarative environment record</a> for
+ which the method was invoked.</li>
+ <li>If <i>envRec</i> does not have a binding for the name that is the value of <i>N</i>, return <b>true</b>.</li>
+ <li>If the binding for <i>N</i> in <i>envRec</i> cannot be deleted, return <b>false</b>.</li>
+ <li>Remove the binding for <i>N</i> from <i>envRec</i>.</li>
+ <li>Return <b>true</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-declarative-environment-records-hasthisbinding">
+ <h1><span class="secnum" id="sec-8.1.1.1.8"><a href="#sec-declarative-environment-records-hasthisbinding"
+ title="link to this section">8.1.1.1.8</a></span> HasThisBinding ()</h1>
+
+ <p>Regular Declarative Environment Records do not provide a <code>this</code> binding.</p>
+
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-declarative-environment-records-hassuperbinding">
+ <h1><span class="secnum" id="sec-8.1.1.1.9"><a href="#sec-declarative-environment-records-hassuperbinding"
+ title="link to this section">8.1.1.1.9</a></span> HasSuperBinding ()</h1>
+
+ <p>Regular Declarative Environment Records do not provide a <code>super</code> binding.</p>
+
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-declarative-environment-records-withbaseobject">
+ <h1><span class="secnum" id="sec-8.1.1.1.10"><a href="#sec-declarative-environment-records-withbaseobject"
+ title="link to this section">8.1.1.1.10</a></span> WithBaseObject()</h1>
+
+ <p>Declarative Environment Records always return <b>undefined</b> as their WithBaseObject.</p>
+
+ <ol class="proc">
+ <li>Return <b>undefined</b>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-object-environment-records">
+ <div class="front">
+ <h1><span class="secnum" id="sec-8.1.1.2"><a href="#sec-object-environment-records"
+ title="link to this section">8.1.1.2</a></span> Object Environment Records</h1>
+
+ <p>Each object environment record is associated with an object called its <i>binding object</i>. An object environment
+ record binds the set of string identifier names that directly correspond to the property names of its binding object.
+ Property keys that are not strings in the form of an <span class="nt">IdentifierName</span> are not included in the set
+ of bound identifiers. Both own and inherited properties are included in the set regardless of the setting of their
+ [[Enumerable]] attribute. Because properties can be dynamically added and deleted from objects, the set of identifiers
+ bound by an object environment record may potentially change as a side-effect of any operation that adds or deletes
+ properties. Any bindings that are created as a result of such a side-effect are considered to be a mutable binding even
+ if the Writable attribute of the corresponding property has the value <b>false</b>. Immutable bindings do not exist for
+ object environment records.</p>
+
+ <p>Object environment records also have a possibly empty <a href="#sec-list-and-record-specification-type">List</a> of
+ strings called <var>unscopables</var>. The strings in this <a href="#sec-list-and-record-specification-type">List</a>
+ are excluded from the environment records set of bound names, regardless of whether or not they exist as property keys
+ of its binding object.</p>
+
+ <p>Object environment records created for <code>with</code> statements (<a href="#sec-with-statement">13.10</a>) can
+ provide their binding object as an implicit this value for use in function calls. The capability is controlled by a
+ <var>withEnvironment</var> Boolean value that is associated with each object environment record. By default, the value
+ of <var>withEnvironment</var> is <b>false</b> for any object environment record.</p>
+
+ <p>The behaviour of the concrete specification methods for Object Environment Records is defined by the following
+ algorithms.</p>
+ </div>
+
+ <section id="sec-object-environment-records-hasbinding-n">
+ <h1><span class="secnum" id="sec-8.1.1.2.1"><a href="#sec-object-environment-records-hasbinding-n"
+ title="link to this section">8.1.1.2.1</a></span> HasBinding(N)</h1>
+
+ <p>The concrete <a href="#sec-environment-records">Environment Record</a> method HasBinding for object environment
+ records determines if its associated binding object has a property whose name is the value of the argument
+ <var>N</var>:</p>
+
+ <ol class="proc">
+ <li>Let <i>envRec</i> be the <a href="#sec-object-environment-records">object environment record</a> for which the
+ method was invoked.</li>
+ <li>If <i>N</i> is an element of <i>envRec’s unscopables</i>, then return <b>false</b>.</li>
+ <li>Let <i>bindings</i> be the binding object for <i>envRec</i>.</li>
+ <li>Return the result of <a href="#sec-hasproperty">HasProperty</a>(<i>bindings</i>, <i>N</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-object-environment-records-createmutablebinding-n-d">
+ <h1><span class="secnum" id="sec-8.1.1.2.2"><a href="#sec-object-environment-records-createmutablebinding-n-d"
+ title="link to this section">8.1.1.2.2</a></span> CreateMutableBinding (N, D)</h1>
+
+ <p>The concrete <a href="#sec-environment-records">Environment Record</a> method CreateMutableBinding for object
+ environment records creates in an environment record’s associated binding object a property whose name is the
+ String value and initializes it to the value <b>undefined</b>. If Boolean argument <var>D</var> is provided and has the
+ value <b>true</b> the new property’s [[Configurable]] attribute is set to <b>true</b>, otherwise it is set to
+ <b>false</b>.</p>
+
+ <ol class="proc">
+ <li>Let <i>envRec</i> be the <a href="#sec-object-environment-records">object environment record</a> for which the
+ method was invoked.</li>
+ <li>Let <i>bindings</i> be the binding object for <i>envRec</i>.</li>
+ <li>If <i>D</i> is <b>true</b> then let <i>configValue</i> be <b>true</b> otherwise let <i>configValue</i> be
+ <b>false</b>.</li>
+ <li>Return <a href="#sec-definepropertyorthrow">DefinePropertyOrThrow</a>(<i>bindings</i>, <i>N</i>,
+ PropertyDescriptor{[[Value]]:<b>undefined</b>, [[Writable]]: <b>true</b>, [[Enumerable]]: <b>true</b> ,
+ [[Configurable]]: <i>configValue</i>}).</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Normally <i>envRec</i> will not have a binding for <i>N</i> but if it does, the
+ semantics of <a href="#sec-definepropertyorthrow">DefinePropertyOrThrow</a> may result in an existing binding being
+ replaced or shadowed or cause an <a href="#sec-completion-record-specification-type">abrupt completion</a> to be
+ returned.</p>
+ </div>
+ </section>
+
+ <section id="sec-object-environment-records-createimmutablebinding-n">
+ <h1><span class="secnum" id="sec-8.1.1.2.3"><a href="#sec-object-environment-records-createimmutablebinding-n"
+ title="link to this section">8.1.1.2.3</a></span> CreateImmutableBinding (N)</h1>
+
+ <p>The concrete <a href="#sec-environment-records">Environment Record</a> method CreateImmutableBinding is never used
+ within this specification in association with Object environment records.</p>
+ </section>
+
+ <section id="sec-object-environment-records-initializebinding-n-v">
+ <h1><span class="secnum" id="sec-8.1.1.2.4"><a href="#sec-object-environment-records-initializebinding-n-v"
+ title="link to this section">8.1.1.2.4</a></span> InitializeBinding (N,V)</h1>
+
+ <p>The concrete <a href="#sec-environment-records">Environment Record</a> method InitializeBinding for object
+ environment records is used to set the bound value of the current binding of the identifier whose name is the value of
+ the argument <var>N</var> to the value of argument <var>V</var>. An uninitialized binding for <var>N</var> must already
+ exist.</p>
+
+ <ol class="proc">
+ <li>Let <i>envRec</i> be the <a href="#sec-object-environment-records">object environment record</a> for which the
+ method was invoked.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>envRec</i> must have an uninitialized binding for
+ <i>N</i>.</li>
+ <li>Record that the binding for <i>N</i> in <i>envRec</i> has been initialized.</li>
+ <li>Return the result of calling the SetMutableBinding concrete method of <i>envRec</i> with <i>N</i>, <i>V</i>, and
+ <b>false</b> as arguments.</li>
+ </ol>
+ </section>
+
+ <section id="sec-object-environment-records-setmutablebinding-n-v-s">
+ <h1><span class="secnum" id="sec-8.1.1.2.5"><a href="#sec-object-environment-records-setmutablebinding-n-v-s"
+ title="link to this section">8.1.1.2.5</a></span> SetMutableBinding (N,V,S)</h1>
+
+ <p>The concrete <a href="#sec-environment-records">Environment Record</a> method SetMutableBinding for object
+ environment records attempts to set the value of the environment record’s associated binding object’s
+ property whose name is the value of the argument <var>N</var> to the value of argument <var>V</var>. A property named
+ <var>N</var> normally already exists but if it does not or is not currently writable, error handling is determined by
+ the value of the Boolean argument <var>S</var>.</p>
+
+ <ol class="proc">
+ <li>Let <i>envRec</i> be the <a href="#sec-object-environment-records">object environment record</a> for which the
+ method was invoked.</li>
+ <li>Let <i>bindings</i> be the binding object for <i>envRec</i>.</li>
+ <li>Return <a href="#sec-put-o-p-v-throw">Put</a>(<i>bindings</i>, <i>N</i>, <i>V</i>, and <i>S</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-object-environment-records-getbindingvalue-n-s">
+ <h1><span class="secnum" id="sec-8.1.1.2.6"><a href="#sec-object-environment-records-getbindingvalue-n-s"
+ title="link to this section">8.1.1.2.6</a></span> GetBindingValue(N,S)</h1>
+
+ <p>The concrete <a href="#sec-environment-records">Environment Record</a> method GetBindingValue for object environment
+ records returns the value of its associated binding object’s property whose name is the String value of the
+ argument identifier <var>N</var>. The property should already exist but if it does not the result depends upon the value
+ of the <var>S</var> argument:</p>
+
+ <ol class="proc">
+ <li>Let <i>envRec</i> be the <a href="#sec-object-environment-records">object environment record</a> for which the
+ method was invoked.</li>
+ <li>Let <i>bindings</i> be the binding object for <i>envRec</i>.</li>
+ <li>Let <i>value</i> be <a href="#sec-hasproperty">HasProperty</a>(<i>bindings</i>, <i>N</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>value</i>).</li>
+ <li>If <i>value</i> is <b>false</b>, then
+ <ol class="block">
+ <li>If <i>S</i> is <b>false</b>, return the value <b>undefined</b>, otherwise throw a <b>ReferenceError</b>
+ exception.</li>
+ </ol>
+ </li>
+ <li>Return <a href="#sec-get-o-p">Get</a>(<i>bindings</i>, <i>N</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-object-environment-records-deletebinding-n">
+ <h1><span class="secnum" id="sec-8.1.1.2.7"><a href="#sec-object-environment-records-deletebinding-n"
+ title="link to this section">8.1.1.2.7</a></span> DeleteBinding (N)</h1>
+
+ <p>The concrete <a href="#sec-environment-records">Environment Record</a> method DeleteBinding for object environment
+ records can only delete bindings that correspond to properties of the environment object whose [[Configurable]]
+ attribute have the value <b>true</b>.</p>
+
+ <ol class="proc">
+ <li>Let <i>envRec</i> be the <a href="#sec-object-environment-records">object environment record</a> for which the
+ method was invoked.</li>
+ <li>Let <i>bindings</i> be the binding object for <i>envRec</i>.</li>
+ <li>Return the result of calling the [[Delete]] internal method of <i>bindings</i> passing <i>N</i> as the
+ argument.</li>
+ </ol>
+ </section>
+
+ <section id="sec-object-environment-records-hasthisbinding">
+ <h1><span class="secnum" id="sec-8.1.1.2.8"><a href="#sec-object-environment-records-hasthisbinding"
+ title="link to this section">8.1.1.2.8</a></span> HasThisBinding ()</h1>
+
+ <p>Regular Object Environment Records do not provide a <code>this</code> binding.</p>
+
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-object-environment-records-hassuperbinding">
+ <h1><span class="secnum" id="sec-8.1.1.2.9"><a href="#sec-object-environment-records-hassuperbinding"
+ title="link to this section">8.1.1.2.9</a></span> HasSuperBinding ()</h1>
+
+ <p>Regular Object Environment Records do not provide a <code>super</code> binding.</p>
+
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-object-environment-records-withbaseobject">
+ <h1><span class="secnum" id="sec-8.1.1.2.10"><a href="#sec-object-environment-records-withbaseobject"
+ title="link to this section">8.1.1.2.10</a></span> WithBaseObject()</h1>
+
+ <p>Object Environment Records return <b>undefined</b> as their WithBaseObject unless their <var>withEnvironment</var>
+ flag is <b>true</b>.</p>
+
+ <ol class="proc">
+ <li>Let <i>envRec</i> be the <a href="#sec-object-environment-records">object environment record</a> for which the
+ method was invoked.</li>
+ <li>If the <i>withEnvironment</i> flag of <i>envRec</i> is <b>true</b>, return the binding object for
+ <i>envRec</i>.</li>
+ <li>Otherwise, return <b>undefined</b>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-function-environment-records">
+ <div class="front">
+ <h1><span class="secnum" id="sec-8.1.1.3"><a href="#sec-function-environment-records"
+ title="link to this section">8.1.1.3</a></span> Function Environment Records</h1>
+
+ <p>A function environment record is a <a href="#sec-declarative-environment-records">declarative environment record</a>
+ that is used to represent the outer most scope of a function that provides a <code>this</code> binding. In addition to
+ its identifier bindings, a function environment record contains the <b>this</b> value used within its scope. If such a
+ function references <code>super</code>, its function environment record also contains the state that is used to perform
+ <code>super</code> method invocations from within the function.</p>
+
+ <p>Function environment records store their <code>this</code> binding as the value of their <var>thisValue</var>. If the
+ associated function references <code>super</code>, the environment record stores in <span class="nt">HomeObject</span>
+ the object that the function is bound to as a method and in <span class="nt">MethodName</span> the <a
+ href="#sec-object-type">property key</a> used for unqualified super invocations from within the function. The default
+ value for <span class="nt">HomeObject</span> and <span class="nt">MethodName</span> is <span
+ class="value">undefined</span>.</p>
+
+ <p>Methods environment records support all of <a href="#sec-declarative-environment-records">Declarative Environment
+ Record</a> methods listed in <a href="#table-16">Table 16</a> and share the same specifications for all of those methods
+ except for HasThisBinding and HasSuperBinding. In addition, declarative environment records support the methods listed
+ in <a href="#table-17">Table 17</a>:</p>
+
+ <figure>
+ <figcaption><span id="table-17">Table 17</span> — Additional Methods of Function Environment Records</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-top: 2px solid #000000">Method</th>
+ <th style="border-bottom: 1px solid #000000; border-right: 1px solid #000000; border-top: 2px solid #000000">Purpose</th>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">GetThisBinding()</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">Return the value of this environment record’s <code>this</code> binding.</td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black"><a href="#sec-getsuperbase">GetSuperBase</a>()</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">Return the object that is the base for <code>super</code> property accesses bound in this environment record. The object is derived from this environment record’s <span style="font-family: Times New Roman">HomeObject</span> binding. If the value is Empty, return <span class="value">undefined</span>.</td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black"><a href="#sec-getmethodname">GetMethodName</a>()</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">Return the value of this environment record’s <span style="font-family: Times New Roman">MethodName</span> binding.</td>
+ </tr>
+ </table>
+ </figure>
+
+ <p>The behaviour of the additional concrete specification methods for Function Environment Records is defined by the
+ following algorithms:</p>
+ </div>
+
+ <section id="sec-function-environment-records-hasthisbinding">
+ <h1><span class="secnum" id="sec-8.1.1.3.1"><a href="#sec-function-environment-records-hasthisbinding"
+ title="link to this section">8.1.1.3.1</a></span> HasThisBinding ()</h1>
+
+ <p><a href="#sec-function-environment-records">Function Environment Records</a> always provide a <code>this</code>
+ binding.</p>
+
+ <ol class="proc">
+ <li>Return <b>true</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-function-environment-records-hassuperbinding">
+ <h1><span class="secnum" id="sec-8.1.1.3.2"><a href="#sec-function-environment-records-hassuperbinding"
+ title="link to this section">8.1.1.3.2</a></span> HasSuperBinding ()</h1>
+ <ol class="proc">
+ <li>If this environment record’s <i>HomeObject</i> has the value <span style="font-family:
+ sans-serif">Empty</span>, then return <b>false</b>. Otherwise, return <b>true</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-function-environment-records-getthisbinding">
+ <h1><span class="secnum" id="sec-8.1.1.3.3"><a href="#sec-function-environment-records-getthisbinding"
+ title="link to this section">8.1.1.3.3</a></span> GetThisBinding ()</h1>
+ <ol class="proc">
+ <li>Return the value of this environment record’s <i>thisValue</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-getsuperbase">
+ <h1><span class="secnum" id="sec-8.1.1.3.4"><a href="#sec-getsuperbase"
+ title="link to this section">8.1.1.3.4</a></span> GetSuperBase ()</h1>
+ <ol class="proc">
+ <li>Let <i>home</i> be the value of this environment record’s <i>HomeObject</i>.</li>
+ <li>If <i>home</i> has the value <span style="font-family: sans-serif">Empty</span>, then return
+ <b>undefined</b>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>home</i>) is Object.</li>
+ <li>Return the result of calling <i>home’s</i> [[GetPrototypeOf]] internal method.</li>
+ </ol>
+ </section>
+
+ <section id="sec-getmethodname">
+ <h1><span class="secnum" id="sec-8.1.1.3.5"><a href="#sec-getmethodname"
+ title="link to this section">8.1.1.3.5</a></span> GetMethodName ()</h1>
+ <ol class="proc">
+ <li>Return the value of this environment record’s <i>MethodName</i>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-global-environment-records">
+ <div class="front">
+ <h1><span class="secnum" id="sec-8.1.1.4"><a href="#sec-global-environment-records"
+ title="link to this section">8.1.1.4</a></span> Global Environment Records</h1>
+
+ <p>A global environment record is used to represent the outer most scope that is shared by all of the ECMAScript <span
+ class="nt">Script</span> elements that are processed in a common <a href="#sec-code-realms">Realm</a> (<a
+ href="#sec-newglobalenvironment">8.1.2.5</a>). A global environment record provides the bindings for built-in globals
+ (<a href="#sec-global-object">clause 18</a>), properties of the global object, and for all declarations that are not
+ function code and that occur within <span class="nt">Script</span> productions.</p>
+
+ <p>A global environment record is logically a single record but it is specified as a composite encapsulating an <a
+ href="#sec-object-environment-records">object environment record</a> and a <a
+ href="#sec-declarative-environment-records">declarative environment record</a>. The <a
+ href="#sec-object-environment-records">object environment record</a> has as its base object the global object of the
+ associated <a href="#sec-code-realms">Realm</a>. This global object is also the value of the global environment
+ record’s <var>thisValue</var>. The <a href="#sec-object-environment-records">object environment record</a>
+ component of a global environment record contains the bindings for all built-in globals (<a
+ href="#sec-global-object">clause 18</a>) and all bindings introduced by a <span style="font-family: Times New
+ Roman"><i>FunctionDeclaration</i>, <i>GeneratorDeclaration</i></span>, or <span class="nt">VariableStatement</span>
+ contained in global code. The bindings for all other ECMAScript declarations in global code are contained in the <a
+ href="#sec-declarative-environment-records">declarative environment record</a> component of the global environment
+ record.</p>
+
+ <p>Properties may be created directly on a global object. Hence, the <a href="#sec-object-environment-records">object
+ environment record</a> component of a global environment record may contain both bindings created explicitly by <span
+ style="font-family: Times New Roman"><i>FunctionDeclaration</i>, <i>GeneratorDeclaration</i></span>, or <span
+ class="nt">VariableDeclaration</span> declarations and binding created implicitly as properties of the global object. In
+ order to identify which bindings were explicitly created using declarations, a global environment record maintains a
+ list of the names bound using its CreateGlobalVarBindings and CreateGlobalFunctionBindings concrete methods.</p>
+
+ <p>Global environment records have the additional state components listed in <a href="#table-18">Table 18</a> and the
+ additional methods listed in <a href="#table-19">Table 19</a>.</p>
+
+ <figure>
+ <figcaption><span id="table-18">Table 18</span> — Components of Global Environment Records</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-top: 2px solid #000000">Component</th>
+ <th style="border-bottom: 1px solid #000000; border-right: 1px solid #000000; border-top: 2px solid #000000">Purpose</th>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black">ObjectRecord</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black">An <a href="#sec-object-environment-records">Object Environment Record</a> whose base object is the global object. It contains global built-in bindings as well as <span style="font-family: Times New Roman"><i>FunctionDeclaration</i>, <i>GeneratorDeclaration</i></span>, and <span class="nt">VariableDeclaration</span> bindings in global code for the associated <a href="#sec-code-realms">Realm</a>.</td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">DeclarativeRecord</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">A <a href="#sec-declarative-environment-records">Declarative Environment Record</a> that contains bindings for all declarations in global code for the associated <a href="#sec-code-realms">Realm</a> code except for <span style="font-family: Times New Roman"><i>FunctionDeclaration</i>, <i>GeneratorDeclaration</i></span>, and <span class="nt">VariableDeclaration</span> <var>bindings</var>.</td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">VarNames</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">A <a href="#sec-list-and-record-specification-type">List</a> containing the string names bound by <span style="font-family: Times New Roman"><i>FunctionDeclaration</i>, <i>GeneratorDeclaration</i></span>, and <span class="nt">VariableDeclaration</span> declarations in global code for the associated <a href="#sec-code-realms">Realm</a>.</td>
+ </tr>
+ </table>
+ </figure>
+
+ <figure>
+ <figcaption><span id="table-19">Table 19</span> — Additional Methods of Global Environment Records</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-top: 2px solid #000000">Method</th>
+ <th style="border-bottom: 1px solid #000000; border-right: 1px solid #000000; border-top: 2px solid #000000">Purpose</th>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">GetThisBinding()</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">Return the value of this environment record’s <code>this</code> binding.</td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black"><a href="#sec-hasvardeclaration">HasVarDeclaration</a> (N)</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">Determines if the argument identifier has a binding in this environment record that was created using a <span style="font-family: Times New Roman"><i>VariableDeclaration</i>,</span> <span class="nt">FunctionDeclaration</span>, or <span style="font-family: Times New Roman"><i>GeneratorDeclaration</i>.</span></td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black"><a href="#sec-haslexicaldeclaration">HasLexicalDeclaration</a> (N)</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">Determines if the argument identifier has a binding in this environment record that was created using a lexical declaration such as a <span class="nt">LexicalDeclaration</span> or a <span class="nt">ClassDeclaration</span>.</td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black"><a href="#sec-candeclareglobalvar">CanDeclareGlobalVar</a> (N)</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">Determines if a corresponding <a href="#sec-createglobalvarbinding">CreateGlobalVarBinding</a> call would succeed if called for the same argument <var>N</var>.</td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black"><a href="#sec-candeclareglobalfunction">CanDeclareGlobalFunction</a> (N)</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">Determines if a corresponding <a href="#sec-createglobalfunctionbinding">CreateGlobalFunctionBinding</a> call would succeed if called for the same argument <var>N</var>.</td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black"><a href="#sec-createglobalvarbinding">CreateGlobalVarBinding</a>(N, D)</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">Used to create global <code>var</code> bindings in the ObjectRecord component of a global environment record. The binding will be a mutable binding. The corresponding global object property will have attribute values approate for a <code>var</code>. The String value <var>N</var> is the text of the bound name. <i>V</i> is the initial value of the binding If the optional Boolean argument <var>D</var> is <b>true</b> the binding is may be subsequently deleted. This is logically equivalent to CreateMutableBinding but it allows var declarations to receive special treatment.</td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black"><a href="#sec-createglobalfunctionbinding">CreateGlobalFunctionBinding</a>(N, V, D)</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">Used to create and initialize global <code>function</code> bindings in the ObjectRecord component of a global environment record. The binding will be a mutable binding. The corresponding global object property will have attribute values approate for a <code>function</code>.The String value <var>N</var> is the text of the bound name. If the optional Boolean argument <var>D</var> is <b>true</b> the binding is may be subsequently deleted. This is logically equivalent to CreateMutableBinding followed by a SetMutableBinding but it allows function declarations to receive special treatment.</td>
+ </tr>
+ </table>
+ </figure>
+
+ <p>The behaviour of the concrete specification methods for Global Environment Records is defined by the following
+ algorithms.</p>
+ </div>
+
+ <section id="sec-global-environment-records-hasbinding-n">
+ <h1><span class="secnum" id="sec-8.1.1.4.1"><a href="#sec-global-environment-records-hasbinding-n"
+ title="link to this section">8.1.1.4.1</a></span> HasBinding(N)</h1>
+
+ <p>The concrete environment record method HasBinding for global environment records simply determines if the argument
+ identifier is one of the identifiers bound by the record:</p>
+
+ <ol class="proc">
+ <li>Let <i>envRec</i> be <a href="#sec-global-environment-records">the global environment record</a> for which the
+ method was invoked.</li>
+ <li>Let <i>DclRec</i> be <i>envRec’s</i> DeclarativeRecord.</li>
+ <li>If the result of calling <i>DclRec’s</i> HasBinding concrete method with argument <i>N</i> is <b>true</b>,
+ return <b>true</b>.</li>
+ <li>Let <i>ObjRec</i> be <i>envRec’s</i> ObjectRecord.</li>
+ <li>Return the result of calling <i>ObjRec’s</i> HasBinding concrete method with argument <i>N</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-global-environment-records-createmutablebinding-n-d">
+ <h1><span class="secnum" id="sec-8.1.1.4.2"><a href="#sec-global-environment-records-createmutablebinding-n-d"
+ title="link to this section">8.1.1.4.2</a></span> CreateMutableBinding (N, D)</h1>
+
+ <p>The concrete environment record method CreateMutableBinding for global environment records creates a new mutable
+ binding for the name <var>N</var> that is uninitialized. The binding is created in the associated DeclarativeRecord. A
+ binding for <var>N</var> must not already exist in the DeclarativeRecord. If Boolean argument <var>D</var> is provided
+ and has the value <b>true</b> the new binding is marked as being subject to deletion.</p>
+
+ <ol class="proc">
+ <li>Let <i>envRec</i> be <a href="#sec-global-environment-records">the global environment record</a> for which the
+ method was invoked.</li>
+ <li>Let <i>DclRec</i> be <i>envRec’s</i> DeclarativeRecord.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>DclRec</i> does not already have a binding for <i>N</i>.</li>
+ <li>Return the result of calling the CreateMutableBinding concrete method of <i>DclRec</i> with arguments <i>N</i> and
+ <i>D</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-global-environment-records-createimmutablebinding-n">
+ <h1><span class="secnum" id="sec-8.1.1.4.3"><a href="#sec-global-environment-records-createimmutablebinding-n"
+ title="link to this section">8.1.1.4.3</a></span> CreateImmutableBinding (N)</h1>
+
+ <p>The concrete <a href="#sec-environment-records">Environment Record</a> method CreateImmutableBinding for global
+ environment records creates a new immutable binding for the name <var>N</var> that is uninitialized. A binding must not
+ already exist in this environment record for <var>N</var>.</p>
+
+ <ol class="proc">
+ <li>Let <i>envRec</i> be <a href="#sec-global-environment-records">the global environment record</a> for which the
+ method was invoked.</li>
+ <li>Let <i>DclRec</i> be <i>envRec’s</i> DeclarativeRecord.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>DclRec</i> does not already have a binding for <i>N</i>.</li>
+ <li>Return the result of calling the CreateImmutableBinding concrete method of <i>DclRec</i> with argument
+ <i>N</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-global-environment-records-initializebinding-n-v">
+ <h1><span class="secnum" id="sec-8.1.1.4.4"><a href="#sec-global-environment-records-initializebinding-n-v"
+ title="link to this section">8.1.1.4.4</a></span> InitializeBinding (N,V)</h1>
+
+ <p>The concrete <a href="#sec-environment-records">Environment Record</a> method InitializeBinding for global
+ environment records is used to set the bound value of the current binding of the identifier whose name is the value of
+ the argument <var>N</var> to the value of argument <var>V</var>. An uninitialized binding for <var>N</var> must already
+ exist.</p>
+
+ <ol class="proc">
+ <li>Let <i>envRec</i> be <a href="#sec-global-environment-records">the global environment record</a> for which the
+ method was invoked.</li>
+ <li>Let <i>DclRec</i> be <i>envRec’s</i> DeclarativeRecord.</li>
+ <li>If the result of calling <i>DclRec’s</i> HasBinding concrete method with argument <i>N</i> is <b>true</b>,
+ then
+ <ol class="block">
+ <li>Return the result of calling <i>DclRec’s</i> InitializeBinding concrete method with arguments <i>N</i>
+ and <i>V</i>.</li>
+ </ol>
+ </li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: If the binding exists it must be in the <a
+ href="#sec-object-environment-records">object environment record</a>.</li>
+ <li>Let <i>ObjRec</i> be <i>envRec’s</i> ObjectRecord.</li>
+ <li>Return the result of calling <i>ObjRec’s</i> InitializeBinding concrete method with arguments <i>N</i> and
+ <i>V</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-global-environment-records-setmutablebinding-n-v-s">
+ <h1><span class="secnum" id="sec-8.1.1.4.5"><a href="#sec-global-environment-records-setmutablebinding-n-v-s"
+ title="link to this section">8.1.1.4.5</a></span> SetMutableBinding (N,V,S)</h1>
+
+ <p>The concrete <a href="#sec-environment-records">Environment Record</a> method SetMutableBinding for global
+ environment records attempts to change the bound value of the current binding of the identifier whose name is the value
+ of the argument <var>N</var> to the value of argument <var>V</var>. If the binding is an immutable binding, a
+ <b>TypeError</b> is thrown if <span style="font-family: Times New Roman">S</span> is <span class="value">true</span>. A
+ property named <var>N</var> normally already exists but if it does not or is not currently writable, error handling is
+ determined by the value of the Boolean argument <var>S</var>.</p>
+
+ <ol class="proc">
+ <li>Let <i>envRec</i> be <a href="#sec-global-environment-records">the global environment record</a> for which the
+ method was invoked.</li>
+ <li>Let <i>DclRec</i> be <i>envRec’s</i> DeclarativeRecord.</li>
+ <li>If the result of calling <i>DclRec’s</i> HasBinding concrete method with argument <i>N</i> is <b>true</b>,
+ then
+ <ol class="block">
+ <li>Return the result of calling the SetMutableBinding concrete method of <i>DclRec</i> with arguments <i>N</i>,
+ <i>V</i>, and <i>S</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>ObjRec</i> be <i>envRec’s</i> ObjectRecord.</li>
+ <li>Return the result of calling the SetMutableBinding concrete method of <i>ObjRec</i> with arguments <i>N</i>,
+ <i>V</i>, and <i>S</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-global-environment-records-getbindingvalue-n-s">
+ <h1><span class="secnum" id="sec-8.1.1.4.6"><a href="#sec-global-environment-records-getbindingvalue-n-s"
+ title="link to this section">8.1.1.4.6</a></span> GetBindingValue(N,S)</h1>
+
+ <p>The concrete <a href="#sec-environment-records">Environment Record</a> method GetBindingValue for global environment
+ records simply returns the value of its bound identifier whose name is the value of the argument <var>N</var>. If the
+ binding is an uninitialized binding throw a <b>ReferenceError</b> exception. A property named <var>N</var> normally
+ already exists but if it does not or is not currently writable, error handling is determined by the value of the Boolean
+ argument <var>S</var>.</p>
+
+ <ol class="proc">
+ <li>Let <i>envRec</i> be <a href="#sec-global-environment-records">the global environment record</a> for which the
+ method was invoked.</li>
+ <li>Let <i>DclRec</i> be <i>envRec’s</i> DeclarativeRecord.</li>
+ <li>If the result of calling <i>DclRec’s</i> HasBinding concrete method with argument <i>N</i> is <b>true</b>,
+ then
+ <ol class="block">
+ <li>Return the result of calling the GetBindingValue concrete method of <i>DclRec</i> with arguments <i>N</i> and
+ <i>S</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>ObjRec</i> be <i>envRec’s</i> ObjectRecord.</li>
+ <li>Return the result of calling the GetBindingValue concrete method of <i>ObjRec</i> with arguments <i>N</i>, and
+ <i>S</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-global-environment-records-deletebinding-n">
+ <h1><span class="secnum" id="sec-8.1.1.4.7"><a href="#sec-global-environment-records-deletebinding-n"
+ title="link to this section">8.1.1.4.7</a></span> DeleteBinding (N)</h1>
+
+ <p>The concrete <a href="#sec-environment-records">Environment Record</a> method DeleteBinding for global environment
+ records can only delete bindings that have been explicitly designated as being subject to deletion.</p>
+
+ <ol class="proc">
+ <li>Let <i>envRec</i> be <a href="#sec-global-environment-records">the global environment record</a> for which the
+ method was invoked.</li>
+ <li>Let <i>DclRec</i> be <i>envRec’s</i> DeclarativeRecord.</li>
+ <li>If the result of calling <i>DclRec’s</i> HasBinding concrete method with argument <i>N</i> is <b>true</b>,
+ then
+ <ol class="block">
+ <li>Return the result of calling the DeleteBinding concrete method of <i>DclRec</i> with argument <i>N</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>ObjRec</i> be <i>envRec’s</i> ObjectRecord.</li>
+ <li>If the result of calling <i>ObjRec’s</i> HasBinding concrete method with argument <i>N</i> is <b>true</b>,
+ then
+ <ol class="block">
+ <li>Let <i>status</i> be the result of calling the DeleteBinding concrete method of <i>ObjRec</i> with argument
+ <i>N</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>If <i>status</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>varNames</i> be <i>envRec’s</i> VarNames <a
+ href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>If <i>N</i> is an element of <i>varNames</i>, then remove that element from the <i>varNames</i>.</li>
+ </ol>
+ </li>
+ <li>Return <i>status</i>.</li>
+ </ol>
+ </li>
+ <li>Return <b>true</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-global-environment-records-hasthisbinding">
+ <h1><span class="secnum" id="sec-8.1.1.4.8"><a href="#sec-global-environment-records-hasthisbinding"
+ title="link to this section">8.1.1.4.8</a></span> HasThisBinding ()</h1>
+
+ <p><a href="#sec-global-environment-records">Global Environment Records</a> always provide a <code>this</code> binding
+ whose value is the associated global object.</p>
+
+ <ol class="proc">
+ <li>Return <b>true</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-global-environment-records-hassuperbinding">
+ <h1><span class="secnum" id="sec-8.1.1.4.9"><a href="#sec-global-environment-records-hassuperbinding"
+ title="link to this section">8.1.1.4.9</a></span> HasSuperBinding ()</h1>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-global-environment-records-withbaseobject">
+ <h1><span class="secnum" id="sec-8.1.1.4.10"><a href="#sec-global-environment-records-withbaseobject"
+ title="link to this section">8.1.1.4.10</a></span> WithBaseObject()</h1>
+
+ <p><a href="#sec-global-environment-records">Global Environment Records</a> always return <b>undefined</b> as their
+ WithBaseObject.</p>
+
+ <ol class="proc">
+ <li>Return <b>undefined</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-global-environment-records-getthisbinding">
+ <h1><span class="secnum" id="sec-8.1.1.4.11"><a href="#sec-global-environment-records-getthisbinding"
+ title="link to this section">8.1.1.4.11</a></span> GetThisBinding ()</h1>
+ <ol class="proc">
+ <li>Let <i>envRec</i> be <a href="#sec-global-environment-records">the global environment record</a> for which the
+ method was invoked.</li>
+ <li>Let <i>ObjRec</i> be <i>envRec’s</i> ObjectRecord.</li>
+ <li>Let <i>bindings</i> be the binding object for <i>ObjRec</i>.</li>
+ <li>Return <i>bindings</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-hasvardeclaration">
+ <h1><span class="secnum" id="sec-8.1.1.4.12"><a href="#sec-hasvardeclaration"
+ title="link to this section">8.1.1.4.12</a></span> HasVarDeclaration (N)</h1>
+
+ <p>The concrete environment record method HasVarDeclaration for global environment records determines if the argument
+ identifier has a binding in this record that was created using a <span class="nt">VariableStatement</span> or a <span
+ class="prod"><span class="nt">FunctionDeclaration</span> <span class="geq">:</span></span></p>
+
+ <ol class="proc">
+ <li>Let <i>envRec</i> be <a href="#sec-global-environment-records">the global environment record</a> for which the
+ method was invoked.</li>
+ <li>Let <i>varDeclaredNames</i> be <i>envRec’s</i> VarNames <a
+ href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>If <i>varDeclaredNames</i> contains the value of <i>N</i>, return <b>true</b>.</li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-haslexicaldeclaration">
+ <h1><span class="secnum" id="sec-8.1.1.4.13"><a href="#sec-haslexicaldeclaration"
+ title="link to this section">8.1.1.4.13</a></span> HasLexicalDeclaration (N)</h1>
+
+ <p>The concrete environment record method HasLexicalDeclaration for global environment records determines if the
+ argument identifier has a binding in this record that was created using a lexical declaration such as a <span
+ class="nt">LexicalDeclaration</span> or a <span class="prod"><span class="nt">ClassDeclaration</span> <span
+ class="geq">:</span></span></p>
+
+ <ol class="proc">
+ <li>Let <i>envRec</i> be <a href="#sec-global-environment-records">the global environment record</a> for which the
+ method was invoked.</li>
+ <li>Let <i>DclRec</i> be <i>envRec’s</i> DeclarativeRecord.</li>
+ <li>Return the result of calling <i>DclRec’s</i> HasBinding concrete method with argument <i>N</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-candeclareglobalvar">
+ <h1><span class="secnum" id="sec-8.1.1.4.14"><a href="#sec-candeclareglobalvar"
+ title="link to this section">8.1.1.4.14</a></span> CanDeclareGlobalVar (N)</h1>
+
+ <p>The concrete environment record method CanDeclareGlobalVar for global environment records determines if a
+ corresponding <a href="#sec-createglobalvarbinding">CreateGlobalVarBinding</a> call would succeed if called for the same
+ argument <var>N</var>. Redundent var declarations and var declarations for pre-existing global object properties are
+ allowed.</p>
+
+ <ol class="proc">
+ <li>Let <i>envRec</i> be <a href="#sec-global-environment-records">the global environment record</a> for which the
+ method was invoked.</li>
+ <li>Let <i>ObjRec</i> be <i>envRec’s</i> ObjectRecord.</li>
+ <li>If the result of calling <i>ObjRec’s</i> HasBinding concrete method with argument <i>N</i> is <b>true</b>,
+ return <b>true</b>.</li>
+ <li>Let <i>bindings</i> be the binding object for <i>ObjRec</i>.</li>
+ <li>Let <i>extensible</i> be <a href="#sec-isextensible-o">IsExtensible</a>(<i>bindings</i>).</li>
+ <li>Return <i>extensible</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-candeclareglobalfunction">
+ <h1><span class="secnum" id="sec-8.1.1.4.15"><a href="#sec-candeclareglobalfunction"
+ title="link to this section">8.1.1.4.15</a></span> CanDeclareGlobalFunction (N)</h1>
+
+ <p>The concrete environment record method CanDeclareGlobalFunction for global environment records determines if a
+ corresponding <a href="#sec-createglobalfunctionbinding">CreateGlobalFunctionBinding</a> call would succeed if called
+ for the same argument <var>N</var>.</p>
+
+ <ol class="proc">
+ <li>Let <i>envRec</i> be <a href="#sec-global-environment-records">the global environment record</a> for which the
+ method was invoked.</li>
+ <li>Let <i>ObjRec</i> be <i>envRec’s</i> ObjectRecord.</li>
+ <li>Let <i>globalObject</i> be the binding object for <i>ObjRec</i>.</li>
+ <li>Let <i>extensible</i> be <a href="#sec-isextensible-o">IsExtensible</a>(<i>globalObject</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>extensible</i>).</li>
+ <li>If the result of calling <i>ObjRec’s</i> HasBinding concrete method with argument <i>N</i> is <b>false</b>,
+ then return <i>extensible</i>.</li>
+ <li>Let <i>existingProp</i> be the result of calling the [[GetOwnProperty]] internal method of <i>globalObject</i>
+ with argument <i>N</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>existingProp</i>).</li>
+ <li>If <i>existingProp</i> is <b>undefined</b>, then return <i>extensible</i>.</li>
+ <li>If <i>existingProp</i>.[[Configurable]] is <b>true</b>, then return <b>true</b>.</li>
+ <li>If <a href="#sec-isdatadescriptor">IsDataDescriptor</a>(<i>existingProp</i>) is <b>true</b> and
+ <i>existingProp</i> has attribute values {[[Writable]]: <b>true</b>, [[Enumerable]]: <b>true</b>}, then return
+ <b>true</b>.</li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-createglobalvarbinding">
+ <h1><span class="secnum" id="sec-8.1.1.4.16"><a href="#sec-createglobalvarbinding"
+ title="link to this section">8.1.1.4.16</a></span> CreateGlobalVarBinding (N, D)</h1>
+
+ <p>The concrete <a href="#sec-environment-records">Environment Record</a> method CreateGlobalVarBinding for global
+ environment records creates a mutable binding in the associated <a href="#sec-object-environment-records">object
+ environment record</a> and records the bound name in the associated VarNames <a
+ href="#sec-list-and-record-specification-type">List</a>. If a binding already exists, it is reused.</p>
+
+ <ol class="proc">
+ <li>Let <i>envRec</i> be <a href="#sec-global-environment-records">the global environment record</a> for which the
+ method was invoked.</li>
+ <li>Let <i>ObjRec</i> be <i>envRec’s</i> ObjectRecord.</li>
+ <li>If the result of calling <i>ObjRec’s</i> HasBinding concrete method with argument <i>N</i> is <b>false</b>,
+ then
+ <ol class="block">
+ <li>Let <i>status</i> be the result of calling the CreateMutableBinding concrete method of <i>ObjRec</i> with
+ arguments <i>N</i> and <i>D</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ </ol>
+ </li>
+ <li>Let <i>varDeclaredNames</i> be <i>envRec’s</i> VarNames <a
+ href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>If <i>varDeclaredNames</i> does not contain the value of <i>N</i>, then
+ <ol class="block">
+ <li>Append <i>N</i> to <i>varDeclaredNames</i>.</li>
+ </ol>
+ </li>
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<span style="font-family:
+ sans-serif">empty</span>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-createglobalfunctionbinding">
+ <h1><span class="secnum" id="sec-8.1.1.4.17"><a href="#sec-createglobalfunctionbinding"
+ title="link to this section">8.1.1.4.17</a></span> CreateGlobalFunctionBinding (N, V, D)</h1>
+
+ <p>The concrete <a href="#sec-environment-records">Environment Record</a> method CreateGlobalFunctionBinding for global
+ environment records creates a mutable binding in the associated <a href="#sec-object-environment-records">object
+ environment record</a> and records the bound name in the associated VarNames <a
+ href="#sec-list-and-record-specification-type">List</a>. If a binding already exists, it is replaced.</p>
+
+ <ol class="proc">
+ <li>Let <i>envRec</i> be <a href="#sec-global-environment-records">the global environment record</a> for which the
+ method was invoked.</li>
+ <li>Let <i>ObjRec</i> be <i>envRec’s</i> ObjectRecord.</li>
+ <li>Let <i>globalObject</i> be the binding object for <i>ObjRec</i>.</li>
+ <li>Let <i>existingProp</i> be the result of calling the [[GetOwnProperty]] internal method of <i>globalObject</i>
+ with argument <i>N</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>existingProp</i>).</li>
+ <li>If <i>existingProp</i> is <b>undefined</b> or <i>existingProp</i>.[[Configurable]] is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>desc</i> be the PropertyDescriptor{[[Value]]:<i>V</i>, [[Writable]]: <b>true</b>, [[Enumerable]]:
+ <b>true</b> , [[Configurable]]: <i>D</i>}.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>desc</i> be the PropertyDescriptor{[[Value]]:<i>V</i> }.</li>
+ </ol>
+ </li>
+ <li>Let <i>status</i> be <a href="#sec-definepropertyorthrow">DefinePropertyOrThrow</a>(<i>globalObject</i>, <i>N</i>,
+ <i>desc</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Let <i>varDeclaredNames</i> be <i>envRec’s</i> VarNames <a
+ href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>If <i>varDeclaredNames</i> does not contain the value of <i>N</i>, then
+ <ol class="block">
+ <li>Append <i>N</i> to <i>varDeclaredNames</i>.</li>
+ </ol>
+ </li>
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<span style="font-family:
+ sans-serif">empty</span>).</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Global function declarations are always represented as own properties of the global
+ object. If possible, an existing own property is reconfigured to have a standard set of attribute values.</p>
+ </div>
+ </section>
+ </section>
+ </section>
+
+ <section id="sec-lexical-environment-operations">
+ <div class="front">
+ <h1><span class="secnum" id="sec-8.1.2"><a href="#sec-lexical-environment-operations"
+ title="link to this section">8.1.2</a></span> Lexical Environment Operations</h1>
+
+ <p>The following abstract operations are used in this specification to operate upon lexical environments:</p>
+ </div>
+
+ <section id="sec-getidentifierreference">
+ <h1><span class="secnum" id="sec-8.1.2.1"><a href="#sec-getidentifierreference"
+ title="link to this section">8.1.2.1</a></span> GetIdentifierReference (lex, name, strict) Abstract Operation</h1>
+
+ <p>The abstract operation GetIdentifierReference is called with a <a href="#sec-lexical-environments">Lexical
+ Environment</a> <var>lex</var>, a String <var>name</var>, and a Boolean flag <var>strict.</var> The value of
+ <var>lex</var> may be <b>null</b>. When called, the following steps are performed:</p>
+
+ <ol class="proc">
+ <li>If <i>lex</i> is the value <b>null</b>, then
+ <ol class="block">
+ <li>Return a value of type <a href="#sec-reference-specification-type">Reference</a> whose base value is
+ <b>undefined</b>, whose referenced name is <i>name</i>, and whose strict reference flag is <i>strict</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>envRec</i> be <i>lex</i>’s environment record.</li>
+ <li>Let <i>exists</i> be the result of calling the HasBinding concrete method of <i>envRec</i> passing <i>name</i> as
+ the argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>exists</i>).</li>
+ <li>If <i>exists</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Return a value of type <a href="#sec-reference-specification-type">Reference</a> whose base value is
+ <i>envRec</i>, whose referenced name is <i>name</i>, and whose strict reference flag is <i>strict.</i></li>
+ </ol>
+ </li>
+ <li>Else
+ <ol class="block">
+ <li>Let <i>outer</i> be the value of <i>lex’s</i> <a href="#sec-lexical-environments">outer environment
+ reference</a>.</li>
+ <li>Return GetIdentifierReference(<i>outer</i>, <i>name</i>, <i>strict</i>).</li>
+ </ol>
+ </li>
+ </ol>
+ </section>
+
+ <section id="sec-newdeclarativeenvironment">
+ <h1><span class="secnum" id="sec-8.1.2.2"><a href="#sec-newdeclarativeenvironment"
+ title="link to this section">8.1.2.2</a></span> NewDeclarativeEnvironment (E) Abstract Operation</h1>
+
+ <p>When the abstract operation NewDeclarativeEnvironment is called with either a <a
+ href="#sec-lexical-environments">Lexical Environment</a> or <b>null</b> as argument <var>E</var> the following steps are
+ performed:</p>
+
+ <ol class="proc">
+ <li>Let <i>env</i> be a new <a href="#sec-lexical-environments">Lexical Environment</a>.</li>
+ <li>Let <i>envRec</i> be a new <a href="#sec-declarative-environment-records">declarative environment record</a>
+ containing no bindings.</li>
+ <li>Set <i>env’s</i> environment record to be <i>envRec</i>.</li>
+ <li>Set the <a href="#sec-lexical-environments">outer lexical environment reference</a> of <i>env</i> to <i>E</i>.</li>
+ <li>Return <i>env</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-newobjectenvironment">
+ <h1><span class="secnum" id="sec-8.1.2.3"><a href="#sec-newobjectenvironment"
+ title="link to this section">8.1.2.3</a></span> NewObjectEnvironment (O, E) Abstract Operation</h1>
+
+ <p>When the abstract operation NewObjectEnvironment is called with an Object <var>O</var> and a <a
+ href="#sec-lexical-environments">Lexical Environment</a> <var>E</var> (or <b>null)</b> as arguments, the following steps
+ are performed:</p>
+
+ <ol class="proc">
+ <li>Let <i>env</i> be a new <a href="#sec-lexical-environments">Lexical Environment</a>.</li>
+ <li>Let <i>envRec</i> be a new <a href="#sec-object-environment-records">object environment record</a> containing
+ <i>O</i> as the binding object.</li>
+ <li>Set <i>envRec’s</i> <i>unscopables</i> to an empty <a
+ href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Set <i>env’s</i> environment record to <i>envRec</i>.</li>
+ <li>Set the <a href="#sec-lexical-environments">outer lexical environment reference</a> of <i>env</i> to <i>E</i>.</li>
+ <li>Return <i>env</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-newfunctionenvironment">
+ <h1><span class="secnum" id="sec-8.1.2.4"><a href="#sec-newfunctionenvironment"
+ title="link to this section">8.1.2.4</a></span> NewFunctionEnvironment (F, T) Abstract Operation</h1>
+
+ <p>When the abstract operation NewFunctionEnvironment is called with an ECMAScript function Object <var>F</var> and an
+ ECMAScript value <var>T</var> as arguments, the following steps are performed:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: The value of <i>F’s</i> [[ThisMode]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is not <span style="font-family:
+ sans-serif">lexical</span>.</li>
+ <li>Let <i>env</i> be a new <a href="#sec-lexical-environments">Lexical Environment</a>.</li>
+ <li>Let <i>envRec</i> be a new <a href="#sec-function-environment-records">Function environment record</a> containing
+ containing no bindings.</li>
+ <li>Set <i>envRec’s</i> <i>thisValue</i> to <i>T</i>.</li>
+ <li>If <i>F</i>’s [[NeedsSuper]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is
+ <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>home</i> be the value of <i>F’s</i> [[HomeObject]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>home</i> is <b>undefined</b>, then throw a <b>ReferenceError</b> exception.</li>
+ <li>Set <i>envRec’s</i> <i>HomeObject</i> to <i>home</i>.</li>
+ <li>Set <i>envRec’s</i> <i>MethodName</i> to the value of <i>F’s</i> [[MethodName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Set <i>envRec’s</i> <i>HomeObject</i> to <span style="font-family: sans-serif">Empty</span>.</li>
+ </ol>
+ </li>
+ <li>Set <i>env’s</i> environment record to be <i>envRec</i>.</li>
+ <li>Set the <a href="#sec-lexical-environments">outer lexical environment reference</a> of <i>env</i> to the value of
+ <i>F’s</i> [[Environment]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Return <i>env</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-newglobalenvironment">
+ <h1><span class="secnum" id="sec-8.1.2.5"><a href="#sec-newglobalenvironment"
+ title="link to this section">8.1.2.5</a></span> NewGlobalEnvironment ( G ) Abstract Operation</h1>
+
+ <p>When the abstract operation NewGlobalEnvironment is called with an ECMAScript Object <var>G</var> as its argument, the
+ following steps are performed:</p>
+
+ <ol class="proc">
+ <li>Let <i>env</i> be a new <a href="#sec-lexical-environments">Lexical Environment</a>.</li>
+ <li>Let <i>objRec</i> be a new <a href="#sec-object-environment-records">object environment record</a> containing
+ <i>G</i> as the binding object.</li>
+ <li>Set <i>objRec’s</i> <i>unscopables</i> to an empty <a
+ href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Let <i>dclRec</i> be a new <a href="#sec-declarative-environment-records">declarative environment record</a>
+ containing no bindings.</li>
+ <li>Let <i>globalRec</i> be a new <a href="#sec-global-environment-records">global environment record</a>.</li>
+ <li>Set <i>globalRec’s</i> ObjectRecord to <i>objRec</i>.</li>
+ <li>Set <i>globalRec’s</i> DeclarativeRecord to <i>dclRec</i>.</li>
+ <li>Set <i>globalRec’s</i> VarNames to a new empty <a
+ href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Set <i>env’s</i> environment record to <i>globalRec</i>.</li>
+ <li>Set the <a href="#sec-lexical-environments">outer lexical environment reference</a> of <i>env</i> to
+ <b>null</b></li>
+ <li>Return <i>env</i>.</li>
+ </ol>
+ </section>
+ </section>
+ </section>
+
+ <section id="sec-code-realms">
+ <div class="front">
+ <h1><span class="secnum" id="sec-8.2"><a href="#sec-code-realms" title="link to this section">8.2</a></span> Code
+ Realms</h1>
+
+ <p>Before it is evaluated, all ECMAScript code must be associated with a <i>Realm</i>. Conceptually, a realm consists of a
+ set of intrinsic objects, an ECMAScript global environment, all of the ECMAScript code that is loaded within the scope of
+ that global environment, a Loader object that can associate new ECMAScript code with the realm, and other associated state
+ and resources.</p>
+
+ <p>A Realm is specified as a Record with the fields specified in <a href="#table-20">Table 20</a>:</p>
+
+ <figure>
+ <figcaption><span id="table-20">Table 20</span> — Realm Record Fields</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 0px solid black; border-top: 2px solid #000000">Field Name</th>
+ <th style="border-bottom: 1px solid #000000; border-left: 0px solid black; border-right: 1px solid #000000; border-top: 2px solid #000000">Value</th>
+ <th style="border-bottom: 1px solid #000000; border-right: 1px solid #000000; border-top: 2px solid #000000">Meaning</th>
+ </tr>
+ <tr>
+ <td>[[intrinsics]]</td>
+ <td>A record whose field names are intrinsic keys and whose values are objects</td>
+ <td>These are the intrinsic values used by code associated with this Realm</td>
+ </tr>
+ <tr>
+ <td>[[globalThis]]</td>
+ <td>An object</td>
+ <td>The global object for this Realm</td>
+ </tr>
+ <tr>
+ <td>[[globalEnv]]</td>
+ <td>An ECMAScript environment</td>
+ <td>The global environment for this Realm</td>
+ </tr>
+ <tr>
+ <td>[[directEvalTranslate]]</td>
+ <td><b>undefined</b> or an object that is callable as a function.</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>[[nonEvalFallback]]</td>
+ <td><b>undefined</b> or an object that is callable as a function.</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>[[indirectEval]]</td>
+ <td><b>undefined</b> or an object that is callable as a function.</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>[[loader]]</td>
+ <td>any ECMAScript identifier or <b>empty</b></td>
+ <td>The Loader object that can associate ECMAScript code with this Realm</td>
+ </tr>
+ </table>
+ </figure>
+ </div>
+
+ <section id="sec-createrealm">
+ <h1><span class="secnum" id="sec-8.2.1"><a href="#sec-createrealm" title="link to this section">8.2.1</a></span> CreateRealm
+ ( ) Abstract Operation</h1>
+
+ <p>The abstract operation CreateRealm with no arguments performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>realmRec</i> be a new Record.</li>
+ <li>Let <i>intrinsics</i> be <a href="#sec-createintrinsics">CreateIntrinsics</a>(<i>realmRec</i>).</li>
+ <li>Set <i>realmRec</i>.[[globalThis]] to <b>undefined</b>.</li>
+ <li>Set <i>realmRec</i>.[[globalEnv]] to <b>undefined</b>.</li>
+ <li>Set each of <i>realmRec</i>.[[directEvalTranslate]], <i>realmRec</i>.[[nonEvalFallback]], and
+ <i>realmRec</i>.[[indirectEval]] to <b>undefined</b>.</li>
+ <li>Return <i>realmRec</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-createintrinsics">
+ <h1><span class="secnum" id="sec-8.2.2"><a href="#sec-createintrinsics" title="link to this section">8.2.2</a></span>
+ CreateIntrinsics ( realmRec ) Abstract Operation</h1>
+
+ <p>When the abstract operation CreateIntrinsics with argument <var>realmRec</var> performs the following:</p>
+
+ <ol class="proc">
+ <li>Let <i>intrinsics</i> be a new Record.</li>
+ <li>Set <i>realmRec</i>.[[intrinsics]] to <i>intrinsics</i>.</li>
+ <li>Let <i>objProto</i> be <a href="#sec-objectcreate">ObjectCreate</a>(<b>null</b>).</li>
+ <li>Set <i>intrinsics</i>.[[%ObjectPrototype%]] to <i>objProto</i>.</li>
+ <li>Let <i>throwerSteps</i> be the algorithm steps of the <a href="#sec-%throwtypeerror%">%ThrowTypeError%</a> function
+ (<a href="#sec-%throwtypeerror%">9.2.8.1</a>).</li>
+ <li>Let <i>thrower</i> be a new built-in function object that when called performs the action described by
+ <i>steps</i>.</li>
+ <li>Call the [[SetPrototypeOf]] internal method of <i>thrower</i> with argument <b>undefined</b>.</li>
+ <li>Set the [[Realm]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>thrower</i> to
+ <i>realmRec</i>.</li>
+ <li>Perform <a href="#sec-definepropertyorthrow">DefinePropertyOrThrow</a>(<i>thrower</i>, <code>"caller"</code>,
+ PropertyDescriptor {[[Get]]: <i>thrower</i>, [[Set]]: <i>thrower</i>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b>}).</li>
+ <li>Perform <a href="#sec-definepropertyorthrow">DefinePropertyOrThrow</a>(<i>thrower</i> , <code>"arguments"</code>,
+ PropertyDescriptor {[[Get]]: <i>thrower</i>, [[Set]]: <i>thrower</i>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b>}).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: Defining the above two properties will not result in an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a>.</li>
+ <li>Set <i>intrinsics</i>.[[<span style="font-family: sans-serif"><a
+ href="#sec-%throwtypeerror%">%ThrowTypeError%</a></span>]] to <i>thrower</i>.</li>
+ <li>Let <i>noStep</i> be an empty sequence of algorithm steps.</li>
+ <li>Let <i>funcProto</i> be the CreateBuildinFunction(<i>realmRec</i>, <i>noSteps</i>, <i>objProto</i>).</li>
+ <li>Set <i>intrinsics</i>.[[%FunctionPrototype%]] to <i>funcProto</i>.</li>
+ <li>Call the [[SetPrototypeOf]] internal method of <i>thrower</i> with argument <i>funcProto</i>.</li>
+ <li>Set fields of <i>intrinsics</i> with the values listed in <a href="#table-7">Table 7</a> that have not already been
+ handled above. The field names are the names listed in column one of the table. The value of each field is a new
+ object value fully and recursively populated with property values as defined by the specification of each object in
+ clauses 18-26. All object property values are newly created object values. All values that are built-in function
+ objects are created by performing <a href="#sec-createbuiltinfunction">CreateBuiltinFunction</a>(<i>realmRec</i>,
+ <steps>, <prototype>, <slots>) where <steps> is the definition of that function provided by
+ this specification, <prototype> is the specified value of the function’s [[Prototype]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> and <slots> is a list of the names, if
+ any, of the functions specified internal slots. The create of the intrinsics and their properties must be ordered to
+ avoid any dependencies upon objects that have not yet been created.</li>
+ <li>Return <i>intrinsics</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-setrealmglobalobj">
+ <h1><span class="secnum" id="sec-8.2.3"><a href="#sec-setrealmglobalobj" title="link to this section">8.2.3</a></span>
+ SetRealmGlobalObj ( realmRec, globalObj ) Abstract Operation</h1>
+
+ <p>The abstract operation SetRealmGlobalObj with arguments <var>realmRec</var> and <var>globalObj</var> performs the
+ following steps:</p>
+
+ <ol class="proc">
+ <li>If <i>globalObj</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>globalObj</i> be <a
+ href="#sec-objectcreate">ObjectCreate</a>(<i>realmRec</i>.[[instrinsics]].[[%ObjectPrototype%]]).</li>
+ </ol>
+ </li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>globalObj</i>) is Object.</li>
+ <li>Set <i>realmRec</i>.[[globalThis]] be <i>newGlobal</i>.</li>
+ <li>Let <i>newGlobalEnv</i> be <a href="#sec-newglobalenvironment">NewGlobalEnvironment</a>(<i>newGlobal</i>).</li>
+ <li>Set <i>realmRec</i>.[[globalEnv]] be <i>newGlobalEnv</i>.</li>
+ <li>Return <i>realmRec</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-setdefaultglobalbindings">
+ <h1><span class="secnum" id="sec-8.2.4"><a href="#sec-setdefaultglobalbindings"
+ title="link to this section">8.2.4</a></span> SetDefaultGlobalBindings ( realmRec ) Abstract Operation</h1>
+
+ <p>The abstract operation SetDefaultGlobalBindings with argument <var>realmRec</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>global</i> be <i>realmRec</i>.[[globalThis]].</li>
+ <li>For each property of the Global Object specified in <a href="#sec-global-object">clause 18</a>, do
+ <ol class="block">
+ <li>Let <i>name</i> be the string value of the property name.</li>
+ <li>Let <i>desc</i> be the fully populated data property descriptor for the property containing the specified
+ attributes for the property. For properties whose values are functions, the value of the [[Value]] attribute is
+ the corresponding intrinsic function object from <i>realmRec</i>.</li>
+ <li>Let <i>status</i> be <a href="#sec-definepropertyorthrow">DefinePropertyOrThrow</a>(<i>global</i>, <i>name</i>,
+ <i>desc</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ </ol>
+ </li>
+ <li>Return <i>global</i>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-execution-contexts">
+ <div class="front">
+ <h1><span class="secnum" id="sec-8.3"><a href="#sec-execution-contexts" title="link to this section">8.3</a></span>
+ Execution Contexts</h1>
+
+ <p>An <i>execution context</i> is a specification device that is used to track the runtime evaluation of code by an
+ ECMAScript implementation. At any point in time, there is at most one execution context that is actually executing code.
+ This is known as the <i>running</i> execution context. A stack is used to track execution contexts. The running execution
+ context is always the top element of this stack. A new execution context is created whenever control is transferred from the
+ executable code associated with the currently running execution context to executable code that is not associated with that
+ execution context. The newly created execution context is pushed onto the stack and becomes the running execution
+ context.</p>
+
+ <p>An execution context contains whatever implementation specific state is necessary to track the execution progress of its
+ associated code. Each execution context has at least the state components listed in <a href="#table-21">Table 21</a>.</p>
+
+ <figure>
+ <figcaption><span id="table-21">Table 21</span> —State Components for All Execution Contexts</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-top: 2px solid #000000">Component</th>
+ <th style="border-bottom: 1px solid #000000; border-right: 1px solid #000000; border-top: 2px solid #000000">Purpose</th>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black">code evaluation state</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black">Any state needed to perform, suspend, and resume evaluation of the code associated with this execution context.</td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black"><a href="#sec-code-realms">Realm</a></td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black">The <a href="#sec-code-realms">Realm</a> from which associated code accesses ECMAScript resources.</td>
+ </tr>
+ </table>
+ </figure>
+
+ <p>Evaluation of code by the running execution context may be suspended at various points defined within this specification.
+ Once the running execution context has been suspended a different execution context may become the running execution context
+ and commence evaluating its code. At some later time a suspended execution context may again become the running execution
+ context and continue evaluating its code at the point where it had previously been suspended. Transition of the running
+ execution context status among execution contexts usually occurs in stack-like last-in/first-out manner. However, some
+ ECMAScript features require non-LIFO transitions of the running execution context.</p>
+
+ <p>The value of the <a href="#sec-code-realms">Realm</a> component of the running execution context is also called the
+ <i>current <a href="#sec-code-realms">Realm</a></i>.</p>
+
+ <p>Execution contexts for ECMAScript code have the additional state components listed in <a href="#table-22">Table
+ 22</a>.</p>
+
+ <figure>
+ <figcaption><span id="table-22">Table 22</span> — Additional State Components for ECMAScript Code Execution Contexts</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-top: 2px solid #000000">Component</th>
+ <th style="border-bottom: 1px solid #000000; border-right: 1px solid #000000; border-top: 2px solid #000000">Purpose</th>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black">LexicalEnvironment</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black">Identifies the <a href="#sec-lexical-environments">Lexical Environment</a> used to resolve identifier references made by code within this execution context.</td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">VariableEnvironment</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">Identifies the <a href="#sec-lexical-environments">Lexical Environment</a> whose environment record holds bindings created by <span class="nt">VariableStatements</span> within this execution context.</td>
+ </tr>
+ </table>
+ </figure>
+
+ <p>The LexicalEnvironment and VariableEnvironment components of an execution context are always Lexical Environments. When
+ an execution context is created its LexicalEnvironment and VariableEnvironment components initially have the same value. The
+ value of the VariableEnvironment component never changes while the value of the LexicalEnvironment component may change
+ during execution of code within an execution context.</p>
+
+ <p>Execution contexts representing the evaluation of generator objects have the additional state components listed in <a
+ href="#table-23">Table 23</a>.</p>
+
+ <figure>
+ <figcaption><span id="table-23">Table 23</span> — Additional State Components for Generator Execution Contexts</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-top: 2px solid #000000">Component</th>
+ <th style="border-bottom: 1px solid #000000; border-right: 1px solid #000000; border-top: 2px solid #000000">Purpose</th>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black">Generator</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black">The GeneratorObject that this execution context is evaluating.</td>
+ </tr>
+ </table>
+ </figure>
+
+ <p>In most situations only the running execution context (the top of the execution context stack) is directly manipulated by
+ algorithms within this specification. Hence when the terms “LexicalEnvironment”, and
+ “VariableEnvironment” are used without qualification they are in reference to those components of the running
+ execution context.</p>
+
+ <p>An execution context is purely a specification mechanism and need not correspond to any particular artefact of an
+ ECMAScript implementation. It is impossible for ECMAScript code to directly access or observe an execution context.</p>
+ </div>
+
+ <section id="sec-resolvebinding">
+ <h1><span class="secnum" id="sec-8.3.1"><a href="#sec-resolvebinding" title="link to this section">8.3.1</a></span>
+ ResolveBinding ( name ) Abstract Operation</h1>
+
+ <p>The ResolveBinding abstract operation is used to determine the binding of <var>name</var> passed as a string value using
+ the <a href="#sec-execution-contexts">LexicalEnvironment</a> of <a href="#sec-execution-contexts">the running execution
+ context</a>. During execution of ECMAScript code, ResolveBinding is performed using the following algorithm:</p>
+
+ <ol class="proc">
+ <li>Let <i>env</i> be <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-execution-contexts">LexicalEnvironment</a>.</li>
+ <li>If the syntactic production that is being evaluated is contained in <a href="#sec-strict-mode-code">strict mode
+ code</a>, then let <i>strict</i> be <b>true</b>, else let <i>strict</i> be <b>false</b>.</li>
+ <li>Return <a href="#sec-getidentifierreference">GetIdentifierReference</a>(<i>env</i>, <i>name</i>, <i>strict</i> ).</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The result of ResolveBinding is always a <a
+ href="#sec-reference-specification-type">Reference</a> value with its referenced name component equal to the <i>name</i>
+ argument.</p>
+ </div>
+ </section>
+
+ <section id="sec-getthisenvironment">
+ <h1><span class="secnum" id="sec-8.3.2"><a href="#sec-getthisenvironment" title="link to this section">8.3.2</a></span>
+ GetThisEnvironment ( ) Abstract Operation</h1>
+
+ <p>The abstract operation <span style="font-family: Times New Roman">GetThisEnvironment</span> finds the <a
+ href="#sec-lexical-environments">lexical environment</a> that currently supplies the binding of the keyword
+ <code>this</code>. <span style="font-family: Times New Roman">GetThisEnvironment</span> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>lex</i> be <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-execution-contexts">LexicalEnvironment</a>.</li>
+ <li>Repeat
+ <ol class="block">
+ <li>Let <i>envRec</i> be <i>lex</i>’s environment record.</li>
+ <li>Let <i>exists</i> be the result of calling the HasThisBinding concrete method of <i>envRec</i>.</li>
+ <li>If <i>exists</i> is <b>true</b>, then return <i>envRec</i>.</li>
+ <li>Let <i>outer</i> be the value of <i>lex’s</i> <a href="#sec-lexical-environments">outer environment
+ reference</a>.</li>
+ <li>Let <i>lex</i> be <i>outer</i>.</li>
+ </ol>
+ </li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The loop in step 2 will always terminate because the llst of environments always ends with
+ <a href="#sec-global-environment-records">the global environment</a> which has a <code>this</code> binding.</p>
+ </div>
+ </section>
+
+ <section id="sec-resolvethisbinding">
+ <h1><span class="secnum" id="sec-8.3.3"><a href="#sec-resolvethisbinding" title="link to this section">8.3.3</a></span>
+ ResolveThisBinding ( ) Abstract Operation</h1>
+
+ <p>The abstract operation ResolveThisBinding determines the binding of the keyword <code>this</code> using the <a
+ href="#sec-execution-contexts">LexicalEnvironment</a> of <a href="#sec-execution-contexts">the running execution
+ context</a>. ResolveThisBinding performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>env</i> be <a href="#sec-getthisenvironment">GetThisEnvironment</a>( ).</li>
+ <li>Return the result of calling the GetThisBinding concrete method of <i>env</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-getglobalobject">
+ <h1><span class="secnum" id="sec-8.3.4"><a href="#sec-getglobalobject" title="link to this section">8.3.4</a></span>
+ GetGlobalObject ( ) Abstract Operation</h1>
+
+ <p>The abstract operation <span style="font-family: Times New Roman">GetGlobalObject</span> returns the global object used
+ by <a href="#sec-execution-contexts">the currently running execution context</a>. <span style="font-family: Times New
+ Roman">GetGlobalObject</span> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>ctx</i> be <a href="#sec-execution-contexts">the running execution context</a>.</li>
+ <li>Let <i>currentRealm</i> be <i>ctx’s</i> <a href="#sec-code-realms">Realm</a>.</li>
+ <li>Return <i>currentRealm</i>.[[globalThis]].</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-tasks-and-task-queues">
+ <div class="front">
+ <h1><span class="secnum" id="sec-8.4"><a href="#sec-tasks-and-task-queues" title="link to this section">8.4</a></span> Tasks
+ and Task Queues</h1>
+
+ <p>A Task is an abstract operation that initiates an ECAMScript computation when no other ECMAScript computation is
+ currently in progress. A Task abstract operation may be defined to accept an arbitrary set of task parameters.</p>
+
+ <p>Execution of a Task can be initiated only when there is no running <a href="#sec-execution-contexts">execution
+ context</a> and <a href="#sec-execution-contexts">the execution context stack</a> is empty. A PendingTask is a request for
+ the future execution of a Task. A PendingTask is an internal Record whose fields are specified in <a href="#table-24">Table
+ 24</a>.</p>
+
+ <figure>
+ <figcaption><span id="table-24">Table 24</span> — PendingTask Record Fields</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 0px solid black; border-top: 2px solid #000000">Field Name</th>
+ <th style="border-bottom: 1px solid #000000; border-left: 0px solid black; border-right: 1px solid #000000; border-top: 2px solid #000000">Value</th>
+ <th style="border-bottom: 1px solid #000000; border-right: 1px solid #000000; border-top: 2px solid #000000">Meaning</th>
+ </tr>
+ <tr>
+ <td>[[Task]]</td>
+ <td>The name of a Task abstract operation</td>
+ <td>This is the abstract operation that is performed when execution of this PendingTask is initiated. Tasks are abstract operations that use NextTask rather than Return to indicate that they have completed.</td>
+ </tr>
+ <tr>
+ <td>[[Arguments]]</td>
+ <td>A <a href="#sec-list-and-record-specification-type">List</a>.</td>
+ <td>The <a href="#sec-list-and-record-specification-type">List</a> of argument values that are to be passed to [[Task]] when it is activated.</td>
+ </tr>
+ <tr>
+ <td>[[Realm]]</td>
+ <td>A <a href="#sec-code-realms">Realm</a> Record</td>
+ <td>The <a href="#sec-code-realms">Realm</a> for the initial <a href="#sec-execution-contexts">execution context</a> when this Pending Task is initiated.</td>
+ </tr>
+ <tr>
+ <td>[[HostDefined]]</td>
+ <td>Any, default value is <span class="value">undefined</span>.</td>
+ <td>Field reserved for use by host environment that need to associate additional information with a pending Task</td>
+ </tr>
+ </table>
+ </figure>
+
+ <p>A Task Queue is a FIFO queue of PendingTask records. Each Task Queue has a name and the full set of available Task Queues
+ are defined by an ECMAScript implementation. Every ECMAScript implementation has at least the task queues defined in <a
+ href="#table-25">Table 25</a>.</p>
+
+ <figure>
+ <figcaption><span id="table-25">Table 25</span> — Required Task Queues</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-top: 2px solid #000000">Name</th>
+ <th style="border-bottom: 1px solid #000000; border-right: 1px solid #000000; border-top: 2px solid #000000">Purpose</th>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black">ScriptTasks</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black">Tasks that validate and evaluate ECMAScript <span class="nt">Script</span> and <span class="nt">Module</span> code units. See clauses 10 and 15.</td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">PromiseTasks</td>
+ <td style="border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black">Tasks that are responses to the settlement of a Promise (<a href="#sec-promise-objects">see 25.4</a>).</td>
+ </tr>
+ </table>
+ </figure>
+
+ <p>A request for the future execution of a Task is made by enqueueing, on a Task Queue, a PendingTask record that includes a
+ Task abstract operation name and any necessary argument values. When there is no running <a
+ href="#sec-execution-contexts">execution context</a> and <a href="#sec-execution-contexts">the execution context stack</a>
+ is empty, the ECMAScript implementation removes the first PendingTask from a Task Queue and uses the information contained
+ in it to create an <a href="#sec-execution-contexts">execution context</a> and starts execution of the associated Task
+ abstract operation.</p>
+
+ <p>The PendingTask records from a single Task Queue are always initiated in FIFO order. This specification does not define
+ the order in which multiple Task Queues are serviced. An ECMAScript implementation may interweave the FIFO evaluation of the
+ PendingTask records of a Task Queue with the evaluation of the PendingTask records of one or more other Task Queues. An
+ implementation must define what occurs when there are no running <a href="#sec-execution-contexts">execution context</a> and
+ all Task Queues are empty.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Typically an ECMAScript implementation will have its Task Queues are pre-initialized with
+ at least one PendingTask and one of those Tasks will be the first to be executed. An implementation might choose to free
+ all resources and terminate if the current Task completes and all Task Queues are empty. Alternatively, it might choose to
+ wait for a some implementation specific agent or mechanism to enqueue new PendingTask requests.</p>
+ </div>
+
+ <p>The following abstract operations are used to create and manage Tasks and Task Queues:</p>
+ </div>
+
+ <section id="sec-enqueuetask">
+ <h1><span class="secnum" id="sec-8.4.1"><a href="#sec-enqueuetask" title="link to this section">8.4.1</a></span> EnqueueTask
+ ( queueName, task, arguments) Abstract Operation</h1>
+
+ <p>The abstract operation requires three arguments: <var>queueName</var>, <var>task</var>, and <var>arguments</var>. It
+ performs the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>queueName</i>) is String and its value is the name of a Task
+ Queue recognized by this implementation.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>task</i> is the name of a Task.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>arguments</i> is a <a
+ href="#sec-list-and-record-specification-type">List</a> that has the same number of elements as the number of
+ parameters required by <i>task</i>.</li>
+ <li>Let <i>callerContext</i> be <a href="#sec-execution-contexts">the running execution context</a>.</li>
+ <li>Let <i>callerRealm</i> be <i>callerContext’s</i> <a href="#sec-code-realms">Realm</a>.</li>
+ <li>Let <i>pending</i> be PendingTask{ [[Task]]: <i>task</i>, [[Arguments]]: <i>arguments</i>, [[Realm]]:
+ <i>callerRealm</i>, [[HostDefined]]: <b>undefined</b> }.</li>
+ <li>Perform any implementation or host environment defined processing of <i>pending</i>. This may including modify the
+ [[HostDefined]] field or any other field of <i>pending</i>.</li>
+ <li>Add <i>pending</i> at the back of the Task Queue named by <i>queueName</i>.</li>
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<span style="font-family: sans-serif">empty</span>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-nexttask-result">
+ <h1><span class="secnum" id="sec-8.4.2"><a href="#sec-nexttask-result" title="link to this section">8.4.2</a></span>
+ NextTask result</h1>
+
+ <p>An algorithm step such as:</p>
+
+ <ol class="proc">
+ <li>NextTask <i>result</i>.</li>
+ </ol>
+
+ <p>is used in Task abstract operations in place of:</p>
+
+ <ol class="proc">
+ <li>Return <i>result</i>.</li>
+ </ol>
+
+ <p>Task abstract operations must not contain a Return step or a <a href="#sec-returnifabrupt">ReturnIfAbrupt</a> step. The
+ NextTask <var>result</var> operation is equivalent to the following steps:</p>
+
+ <ol class="proc">
+ <li>If <i>result</i> is an <a href="#sec-completion-record-specification-type">abrupt completion</a>, then perform
+ implementation defined unhandled exception processing.</li>
+ <li><a href="#sec-execution-contexts">Suspend</a> <a href="#sec-execution-contexts">the running execution
+ context</a>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: The <a href="#sec-execution-contexts">execution context stack</a> is
+ now empty.</li>
+ <li>Let <i>nextQueue</i> be a non-empty Task Queue chosen in an implementation defined manner. If all Task Queues are
+ empty, the result is implementation defined.</li>
+ <li>Let <i>nextPending</i> be the PendingTask record at the front of <i>nextQueue</i>. Remove that record from
+ <i>nextQueue</i>.</li>
+ <li>Let <i>newContext</i> be a new <a href="#sec-execution-contexts">execution context</a>.</li>
+ <li>Set <i>newContext</i>’s <a href="#sec-code-realms">Realm</a> to <i>nextPending</i>.[[Realm]].</li>
+ <li>Push <i>newContext</i> onto <a href="#sec-execution-contexts">the execution context stack</a>; <i>newContext</i> is
+ now <a href="#sec-execution-contexts">the running execution context</a>.</li>
+ <li>Perform any implementation or host environment defined task initialization using <i>nextPending</i>.</li>
+ <li>Perform the abstract operation named by <i>nextPending</i>.[[Task]] using the elements of
+ <i>nextPending</i>.[[Arguments]] as its arguments.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-initialization">
+ <div class="front">
+ <h1><span class="secnum" id="sec-8.5"><a href="#sec-initialization" title="link to this section">8.5</a></span>
+ Initialization</h1>
+
+ <p>An ECMAScript implementation performs the following steps prior to the execution of any Tasks or the evaluation of any
+ ECMAScript code:</p>
+
+ <ol class="proc">
+ <li>Let <i>realm</i> be <a href="#sec-createrealm">CreateRealm</a>().</li>
+ <li>Let <i>newContext</i> be a new exeution context.</li>
+ <li>Set <i>newContext</i>’s <a href="#sec-code-realms">Realm</a> to <i>realm</i>.</li>
+ <li>Push <i>newContext</i> onto <a href="#sec-execution-contexts">the execution context stack</a>; <i>newContext</i> is
+ now <a href="#sec-execution-contexts">the running execution context</a>.</li>
+ <li>Let <i>status</i> be <a href="#sec-initializefirstrealm">InitializeFirstRealm</a>(<i>realm</i>).</li>
+ <li>If <i>status</i> is an <a href="#sec-completion-record-specification-type">abrupt completion</a>, then
+ <ol class="block">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: The first realm could not be created.</li>
+ <li>Terminate ECMAScript execution.</li>
+ </ol>
+ </li>
+ <li>In an implementation dependent manner, obtain the <i>SourceCharacter</i> sequence (see 10) for one or more ECMAScript
+ scripts. For each such sequence <i>source</i> do,
+ <ol class="block">
+ <li><a href="#sec-enqueuetask">EnqueueTask</a>(<code>"ScriptTasks"</code>, <a
+ href="#sec-scriptevaluationtask">ScriptEvaluationTask</a>, (<i>source</i>)).</li>
+ </ol>
+ </li>
+ <li>NextTask <a href="#sec-normalcompletion">NormalCompletion</a>(<b>undefined</b>).</li>
+ </ol>
+ </div>
+
+ <section id="sec-initializefirstrealm">
+ <h1><span class="secnum" id="sec-8.5.1"><a href="#sec-initializefirstrealm" title="link to this section">8.5.1</a></span>
+ InitializeFirstRealm ( realm ) Abstract Operation</h1>
+
+ <p>The abstract operation InitializeFirstRealm with parameter <var>realm</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>intrinsics</i> be <a href="#sec-createintrinsics">CreateIntrinsics</a>(<i>realm</i>).</li>
+ <li>If this implementation requires use of an exotic object object to serve as <i>realm</i>’s global object, then
+ let <i>global</i> be such an object created in an implementation defined manner. Otherwise, let <i>global</i> be
+ <b>undefined</b> indicating that an ordinary object should be created as the global object.</li>
+ <li>Perfrom SetRealmGlobalObject(<i>realm</i>, <i>global</i>).</li>
+ <li>Let <i>globalObj</i> be <a href="#sec-setdefaultglobalbindings">SetDefaultGlobalBindings</a>(<i>realm</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>globalObj</i>).</li>
+ <li>Create any implementation defined global object properties on <i>globalObj</i>.</li>
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<b>undefined</b>).</li>
+ </ol>
+ </section>
+ </section>
+</section>
+
+<section id="sec-ordinary-and-exotic-objects-behaviours">
+ <div class="front">
+ <h1><span class="secnum" id="sec-9"><a href="#sec-ordinary-and-exotic-objects-behaviours"
+ title="link to this section">9</a></span> Ordinary and Exotic Objects Behaviours</h1>
+ </div>
+
+ <section id="sec-ordinary-object-internal-methods-and-internal-slots">
+ <div class="front">
+ <h1><span class="secnum" id="sec-9.1"><a href="#sec-ordinary-object-internal-methods-and-internal-slots"
+ title="link to this section">9.1</a></span> Ordinary Object Internal Methods and Internal Slots</h1>
+
+ <p>All ordinary objects have an <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> called
+ [[Prototype]]. The value of this <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is either
+ <b>null</b> or an object and is used for implementing inheritance. Data properties of the [[Prototype]] object are inherited
+ (are visible as properties of the child object) for the purposes of get access, but not for set access. Accessor properties
+ are inherited for both get access and set access.</p>
+
+ <p>Every ordinary object has a Boolean-valued [[Extensible]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> that controls whether or not properties may be
+ added to the object. If the value of the [[Extensible]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> is <b>false</b> then additional properties may not be added to the object. In addition, if [[Extensible]] is
+ <b>false</b> the value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of
+ the object may not be modified. Once the value of an object’s [[Extensible]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> has been set to <b>false</b> it may not be
+ subsequently changed to <b>true</b>.</p>
+
+ <p>In the following algorithm descriptions, assume <var>O</var> is an ordinary object, <var>P</var> is a <a
+ href="#sec-object-type">property key value</a>, <var>V</var> is any <a href="#sec-ecmascript-language-types">ECMAScript
+ language value</a>, and <span class="nt">Desc</span> is a <a href="#sec-property-descriptor-specification-type">Property
+ Descriptor</a> record.</p>
+ </div>
+
+ <section id="sec-ordinary-object-internal-methods-and-internal-slots-getprototypeof">
+ <h1><span class="secnum" id="sec-9.1.1"><a href="#sec-ordinary-object-internal-methods-and-internal-slots-getprototypeof"
+ title="link to this section">9.1.1</a></span> [[GetPrototypeOf]] ( )</h1>
+
+ <p>When the [[GetPrototypeOf]] internal method of <var>O</var> is called the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Return the value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of
+ <i>O</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-ordinary-object-internal-methods-and-internal-slots-setprototypeof-v">
+ <h1><span class="secnum" id="sec-9.1.2"><a href="#sec-ordinary-object-internal-methods-and-internal-slots-setprototypeof-v"
+ title="link to this section">9.1.2</a></span> [[SetPrototypeOf]] (V)</h1>
+
+ <p>When the [[SetPrototypeOf]] internal method of <var>O</var> is called with argument <var>V</var> the following steps are
+ taken:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: Either <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>V</i>) is Object or <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>V</i>) is Null.</li>
+ <li>Let <i>extensible</i> be the value of the [[Extensible]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>Let <i>current</i> be the value of the [[Prototype]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>If <a href="#sec-samevalue">SameValue</a>(<i>V</i>, <i>current</i>), then return <b>true.</b></li>
+ <li>If <i>extensible</i> is <b>false</b>, then return <b>false</b>.</li>
+ <li>If <i>V</i> is not <b>null</b>, then
+ <ol class="block">
+ <li>Let <i>p</i> be <i>V</i>.</li>
+ <li>Repeat, while <i>p</i> is not <b>null</b>
+ <ol class="block">
+ <li>If <a href="#sec-samevalue">SameValue</a>(<i>p</i>, <i>O</i>) is <b>true</b>, then return <b>false</b>.</li>
+ <li>Let <i>nextp</i> be the result of calling the [[GetPrototypeOf]] internal method of <i>p</i> with no
+ arguments.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>nextp</i>).</li>
+ <li>Let <i>p</i> be <i>nextp</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Let <i>extensible</i> be the value of the [[Extensible]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>If <i>extensible</i> is <b>false</b>, then
+ <ol class="block">
+ <li>Let <i>current2</i> be the value of the [[Prototype]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>If <a href="#sec-samevalue">SameValue</a>(<i>V</i>, <i>current2</i>) is <b>true</b>, then return <b>true.</b></li>
+ <li>Return <b>false.</b></li>
+ </ol>
+ </li>
+ <li>Set the value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of
+ <i>O</i> to <i>V</i>.</li>
+ <li>Return <b>true</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-ordinary-object-internal-methods-and-internal-slots-isextensible">
+ <h1><span class="secnum" id="sec-9.1.3"><a href="#sec-ordinary-object-internal-methods-and-internal-slots-isextensible"
+ title="link to this section">9.1.3</a></span> [[IsExtensible]] ( )</h1>
+
+ <p>When the [[IsExtensible]] internal method of <var>O</var> is called the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Return the value of the [[Extensible]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of
+ <i>O</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-ordinary-object-internal-methods-and-internal-slots-preventextensions">
+ <h1><span class="secnum" id="sec-9.1.4"><a href="#sec-ordinary-object-internal-methods-and-internal-slots-preventextensions"
+ title="link to this section">9.1.4</a></span> [[PreventExtensions]] ( )</h1>
+
+ <p>When the [[PreventExtensions]] internal method of <var>O</var> is called the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Set the value of the [[Extensible]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of
+ <i>O</i> to <b>false</b>.</li>
+ <li>Return <b>true.</b></li>
+ </ol>
+ </section>
+
+ <section id="sec-ordinary-object-internal-methods-and-internal-slots-getownproperty-p">
+ <div class="front">
+ <h1><span class="secnum" id="sec-9.1.5"><a
+ href="#sec-ordinary-object-internal-methods-and-internal-slots-getownproperty-p"
+ title="link to this section">9.1.5</a></span> [[GetOwnProperty]] (P)</h1>
+
+ <p>When the [[GetOwnProperty]] internal method of <var>O</var> is called with <a href="#sec-object-type">property key</a>
+ <var>P</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Return <a href="#sec-ordinarygetownproperty">OrdinaryGetOwnProperty</a>(<i>O</i>, <i>P</i>).</li>
+ </ol>
+ </div>
+
+ <section id="sec-ordinarygetownproperty">
+ <h1><span class="secnum" id="sec-9.1.5.1"><a href="#sec-ordinarygetownproperty"
+ title="link to this section">9.1.5.1</a></span> OrdinaryGetOwnProperty (O, P)</h1>
+
+ <p>When the abstract operation OrdinaryGetOwnProperty is called with Object <var>O</var> and with <a
+ href="#sec-object-type">property key</a> <var>P</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ispropertykey">IsPropertyKey</a>(<i>P</i>) is
+ <b>true</b>.</li>
+ <li>If <i>O</i> does not have an own property with key <i>P</i>, return <b>undefined</b>.</li>
+ <li>Let <i>D</i> be a newly created <a href="#sec-property-descriptor-specification-type">Property Descriptor</a> with
+ no fields.</li>
+ <li>Let <i>X</i> be <i>O</i>’s own property whose key is <i>P</i>.</li>
+ <li>If <i>X</i> is a data property, then
+ <ol class="block">
+ <li>Set <i>D</i>.[[Value]] to the value of <i>X</i>’s [[Value]] attribute.</li>
+ <li>Set <i>D</i>.[[Writable]] to the value of <i>X</i>’s [[Writable]] attribute</li>
+ </ol>
+ </li>
+ <li>Else <i>X</i> is an accessor property, so
+ <ol class="block">
+ <li>Set <i>D</i>.[[Get]] to the value of <i>X</i>’s [[Get]] attribute.</li>
+ <li>Set <i>D</i>.[[Set]] to the value of <i>X</i>’s [[Set]] attribute.</li>
+ </ol>
+ </li>
+ <li>Set <i>D</i>.[[Enumerable]] to the value of <i>X</i>’s [[Enumerable]] attribute.</li>
+ <li>Set <i>D</i>.[[Configurable]] to the value of <i>X</i>’s [[Configurable]] attribute.</li>
+ <li>Return <i>D</i>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-ordinary-object-internal-methods-and-internal-slots-defineownproperty-p-desc">
+ <div class="front">
+ <h1><span class="secnum" id="sec-9.1.6"><a
+ href="#sec-ordinary-object-internal-methods-and-internal-slots-defineownproperty-p-desc"
+ title="link to this section">9.1.6</a></span> [[DefineOwnProperty]] (P, Desc)</h1>
+
+ <p>When the [[DefineOwnProperty]] internal method of <var>O</var> is called with <a href="#sec-object-type">property
+ key</a> <var>P</var> and <a href="#sec-property-descriptor-specification-type">Property Descriptor</a> <span
+ class="nt">Desc</span>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Return <a href="#sec-ordinarydefineownproperty">OrdinaryDefineOwnProperty</a>(<i>O</i>, <i>P</i>, <i>Desc</i>).</li>
+ </ol>
+ </div>
+
+ <section id="sec-ordinarydefineownproperty">
+ <h1><span class="secnum" id="sec-9.1.6.1"><a href="#sec-ordinarydefineownproperty"
+ title="link to this section">9.1.6.1</a></span> OrdinaryDefineOwnProperty (O, P, Desc)</h1>
+
+ <p>When the abstract operation <span style="font-family: Times New Roman">OrdinaryDefineOwnProperty</span> is called with
+ Object <var>O</var>, <a href="#sec-object-type">property key</a> <span style="font-family: Times New
+ Roman"><i>P</i>,</span> and <a href="#sec-property-descriptor-specification-type">Property Descriptor</a> <span
+ class="nt">Desc</span> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>current</i> be the result of calling the [[GetOwnProperty]] internal method of <i>O</i> with argument
+ <i>P</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>current</i>).</li>
+ <li>Let <i>extensible</i> be the value of the [[Extensible]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>Return <a href="#sec-validateandapplypropertydescriptor">ValidateAndApplyPropertyDescriptor</a>(<i>O</i>, <i>P</i>,
+ <i>extensible</i>, <i>Desc</i>, <i>current</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-iscompatiblepropertydescriptor">
+ <h1><span class="secnum" id="sec-9.1.6.2"><a href="#sec-iscompatiblepropertydescriptor"
+ title="link to this section">9.1.6.2</a></span> IsCompatiblePropertyDescriptor (Extensible, Desc, Current)</h1>
+
+ <p>When the abstract operation <span style="font-family: Times New Roman">IsCompatiblePropertyDescriptor</span> is called
+ with Boolean value <span class="nt">Extensible</span>, and Property Descriptors <span class="nt">Desc</span>, and <span
+ class="nt">Current</span> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Return <a href="#sec-validateandapplypropertydescriptor">ValidateAndApplyPropertyDescriptor</a>(<b>undefined</b>,
+ <b>undefined</b>, <i>Extensible</i>, <i>Desc</i>, <i>Current</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-validateandapplypropertydescriptor">
+ <h1><span class="secnum" id="sec-9.1.6.3"><a href="#sec-validateandapplypropertydescriptor"
+ title="link to this section">9.1.6.3</a></span> ValidateAndApplyPropertyDescriptor (O, P, extensible, Desc,
+ current)</h1>
+
+ <p>When the abstract operation <span style="font-family: Times New Roman">ValidateAndApplyPropertyDescriptor</span> is
+ called with Object <var>O</var>, <a href="#sec-object-type">property key</a> <span style="font-family: Times New
+ Roman"><i>P</i>,</span> Boolean value <var>extensible</var>, and Property Descriptors <span class="nt">Desc</span>, and
+ <var>current</var> the following steps are taken:</p>
+
+ <p>This algorithm contains steps that test various fields of the <a
+ href="#sec-property-descriptor-specification-type">Property Descriptor</a> <span class="nt">Desc</span> for specific
+ values. The fields that are tested in this manner need not actually exist in <span class="nt">Desc</span>. If a field is
+ absent then its value is considered to be <b>false</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> If <b>undefined</b> is passed as the <i>O</i> argument only validation is performed and
+ no object updates are performed.</p>
+ </div>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: If <i>O</i> is not <b>undefined</b> then <i>P</i> is a valid <a
+ href="#sec-object-type">property key</a>.</li>
+ <li>If <i>current</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>If <i>extensible</i> is <b>false</b>, then return <b>false</b>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>extensible</i> is <b>true</b>.</li>
+ <li>If <a href="#sec-isgenericdescriptor">IsGenericDescriptor</a>(<i>Desc</i>) or <a
+ href="#sec-isdatadescriptor">IsDataDescriptor</a>(<i>Desc</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>If <i>O</i> is not <b>undefined</b>, then create an own data property named <i>P</i> of object <i>O</i>
+ whose [[Value]], [[Writable]], [[Enumerable]] and [[Configurable]] attribute values are described by
+ <i>Desc</i>. If the value of an attribute field of <i>Desc</i> is absent, the attribute of the newly created
+ property is set to its default value.</li>
+ </ol>
+ </li>
+ <li>Else <i>Desc</i> must be an accessor <a href="#sec-property-descriptor-specification-type">Property
+ Descriptor</a>,
+ <ol class="block">
+ <li>If <i>O</i> is not <b>undefined</b>, then create an own accessor property named <i>P</i> of object <i>O</i>
+ whose [[Get]], [[Set]], [[Enumerable]] and [[Configurable]] attribute values are described by <i>Desc</i>.
+ If the value of an attribute field of <i>Desc</i> is absent, the attribute of the newly created property is
+ set to its default value.</li>
+ </ol>
+ </li>
+ <li>Return <b>true</b>.</li>
+ </ol>
+ </li>
+ <li>Return <b>true</b>, if every field in <i>Desc</i> is absent.</li>
+ <li>Return <b>true</b>, if every field in <i>Desc</i> also occurs in <i>current</i> and the value of every field in
+ <i>Desc</i> is the same value as the corresponding field in <i>current</i> when compared using <a
+ href="#sec-samevalue">the SameValue algorithm</a>.</li>
+ <li>If the [[Configurable]] field of <i>current</i> is <b>false</b> then
+ <ol class="block">
+ <li>Return <b>false</b>, if the [[Configurable]] field of <i>Desc</i> is <b>true</b>.</li>
+ <li>Return <b>false</b>, if the [[Enumerable]] field of <i>Desc</i> is present and the [[Enumerable]] fields of
+ <i>current</i> and <i>Desc</i> are the Boolean negation of each other.</li>
+ </ol>
+ </li>
+ <li>If <a href="#sec-isgenericdescriptor">IsGenericDescriptor</a>(<i>Desc</i>) is <b>true</b>, then no further
+ validation is required.</li>
+ <li>Else if <a href="#sec-isdatadescriptor">IsDataDescriptor</a>(<i>current</i>) and <a
+ href="#sec-isdatadescriptor">IsDataDescriptor</a>(<i>Desc</i>) have different results, then
+ <ol class="block">
+ <li>Return <b>false</b>, if the [[Configurable]] field of <i>current</i> is <b>false</b>.</li>
+ <li>If <a href="#sec-isdatadescriptor">IsDataDescriptor</a>(<i>current</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>If <i>O</i> is not <b>undefined</b>, then convert the property named <i>P</i> of object <i>O</i> from a data
+ property to an accessor property. Preserve the existing values of the converted property’s
+ [[Configurable]] and [[Enumerable]] attributes and set the rest of the property’s attributes to their
+ default values.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>If <i>O</i> is not <b>undefined</b>, then convert the property named <i>P</i> of object <i>O</i> from an
+ accessor property to a data property. Preserve the existing values of the converted property’s
+ [[Configurable]] and [[Enumerable]] attributes and set the rest of the property’s attributes to their
+ default values.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Else if <a href="#sec-isdatadescriptor">IsDataDescriptor</a>(<i>current</i>) and <a
+ href="#sec-isdatadescriptor">IsDataDescriptor</a>(<i>Desc</i>) are both <b>true</b>, then
+ <ol class="block">
+ <li>If the [[Configurable]] field of <i>current</i> is <b>false</b>, then
+ <ol class="block">
+ <li>Return <b>false</b>, if the [[Writable]] field of <i>current</i> is <b>false</b> and the [[Writable]] field
+ of <i>Desc</i> is <b>true</b>.</li>
+ <li>If the [[Writable]] field of <i>current</i> is <b>false</b>, then
+ <ol class="block">
+ <li>Return <b>false</b>, if the [[Value]] field of <i>Desc</i> is present and <a
+ href="#sec-samevalue">SameValue</a>(<i>Desc</i>.[[Value]], <i>current</i>.[[Value]]) is
+ <b>false</b>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Else the [[Configurable]] field of <i>current</i> is <b>true</b>, so any change is acceptable.</li>
+ </ol>
+ </li>
+ <li>Else <a href="#sec-isaccessordescriptor">IsAccessorDescriptor</a>(<i>current</i>) and <a
+ href="#sec-isaccessordescriptor">IsAccessorDescriptor</a>(<i>Desc</i>) are both <b>true</b>,
+ <ol class="block">
+ <li>If the [[Configurable]] field of <i>current</i> is <b>false</b>, then
+ <ol class="block">
+ <li>Return <b>false</b>, if the [[Set]] field of <i>Desc</i> is present and <a
+ href="#sec-samevalue">SameValue</a>(<i>Desc</i>.[[Set]], <i>current</i>.[[Set]]) is <b>false</b>.</li>
+ <li>Return <b>false</b>, if the [[Get]] field of <i>Desc</i> is present and <a
+ href="#sec-samevalue">SameValue</a>(<i>Desc</i>.[[Get]], <i>current</i>.[[Get]]) is <b>false</b>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>If <i>O</i> is not <b>undefined</b>, then
+ <ol class="block">
+ <li>For each field of <i>Desc</i> that is present, set the corresponding attribute of the property named <i>P</i> of
+ object <i>O</i> to the value of the field. The [[Origin]] field, if present, is ignored.</li>
+ </ol>
+ </li>
+ <li>Return <b>true</b>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Step 8.b allows any field of Desc to be different from the corresponding field of
+ current if current’s [[Configurable]] field is <b>true</b>. This even permits changing the [[Value]] of a property
+ whose [[Writable]] attribute is <b>false</b>. This is allowed because a <b>true</b> [[Configurable]] attribute would
+ permit an equivalent sequence of calls where [[Writable]] is first set to <b>true</b>, a new [[Value]] is set, and then
+ [[Writable]] is set to <b>false</b>.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-ordinary-object-internal-methods-and-internal-slots-hasproperty-p">
+ <h1><span class="secnum" id="sec-9.1.7"><a href="#sec-ordinary-object-internal-methods-and-internal-slots-hasproperty-p"
+ title="link to this section">9.1.7</a></span> [[HasProperty]](P)</h1>
+
+ <p>When the [[HasProperty]] internal method of <var>O</var> is called with <a href="#sec-object-type">property key</a>
+ <var>P</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ispropertykey">IsPropertyKey</a>(<i>P</i>) is
+ <b>true</b>.</li>
+ <li>Let <i>hasOwn</i> be the result of calling the [[GetOwnProperty]] internal method of <i>O</i> with argument
+ <i>P</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>hasOwn</i>).</li>
+ <li>If <i>hasOwn</i> is not <b>undefined</b>, then return <b>true</b>.</li>
+ <li>Let <i>parent</i> be the result of calling the [[GetPrototypeOf]] internal method of <i>O</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>parent</i>).</li>
+ <li>If <i>parent</i> is not <b>null</b>, then
+ <ol class="block">
+ <li>Return the result of calling the [[HasProperty]] internal method of <i>parent</i> with argument <i>P</i>.</li>
+ </ol>
+ </li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-ordinary-object-internal-methods-and-internal-slots-get-p-receiver">
+ <h1><span class="secnum" id="sec-9.1.8"><a href="#sec-ordinary-object-internal-methods-and-internal-slots-get-p-receiver"
+ title="link to this section">9.1.8</a></span> [[Get]] (P, Receiver)</h1>
+
+ <p>When the [[Get]] internal method of <var>O</var> is called with <a href="#sec-object-type">property key</a> <var>P</var>
+ and <a href="#sec-ecmascript-language-types">ECMAScript language value</a> <span class="nt">Receiver</span> the following
+ steps are taken:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ispropertykey">IsPropertyKey</a>(<i>P</i>) is
+ <b>true</b>.</li>
+ <li>Let <i>desc</i> be the result of calling the [[GetOwnProperty]] internal method of <i>O</i> with argument
+ <i>P</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>desc</i>).</li>
+ <li>If <i>desc</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>parent</i> be the result of calling the [[GetPrototypeOf]] internal method of <i>O</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>parent</i>).</li>
+ <li>If <i>parent</i> is <b>null</b>, then return <b>undefined.</b></li>
+ <li>Return the result of calling the [[Get]] internal method of <i>parent</i> with arguments <i>P</i> and
+ <i>Receiver</i>.</li>
+ </ol>
+ </li>
+ <li>If <a href="#sec-isdatadescriptor">IsDataDescriptor</a>(<i>desc</i>) is <b>true</b>, return
+ <i>desc</i>.[[Value]].</li>
+ <li>Otherwise, <a href="#sec-isaccessordescriptor">IsAccessorDescriptor</a>(<i>desc</i>) must be <b>true</b> so, let
+ <i>getter</i> be <i>desc</i>.[[Get]].</li>
+ <li>If <i>getter</i> is <b>undefined</b>, return <b>undefined</b>.</li>
+ <li>Return the result of calling the [[Call]] internal method of <i>getter</i> with <i>Receiver</i> as the
+ <i>thisArgument</i> and an empty <a href="#sec-list-and-record-specification-type">List</a> as
+ <i>argumentsList</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-ordinary-object-internal-methods-and-internal-slots-set-p-v-receiver">
+ <h1><span class="secnum" id="sec-9.1.9"><a href="#sec-ordinary-object-internal-methods-and-internal-slots-set-p-v-receiver"
+ title="link to this section">9.1.9</a></span> [[Set]] ( P, V, Receiver)</h1>
+
+ <p>When the [[Set]] internal method of <var>O</var> is called with <a href="#sec-object-type">property key</a> <var>P</var>,
+ value <var>V</var>, and <a href="#sec-ecmascript-language-types">ECMAScript language value</a> <span
+ class="nt">Receiver</span>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ispropertykey">IsPropertyKey</a>(<i>P</i>) is
+ <b>true</b>.</li>
+ <li>Let <i>ownDesc</i> be the result of calling the [[GetOwnProperty]] internal method of <i>O</i> with argument
+ <i>P</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>ownDesc</i>).</li>
+ <li>If <i>ownDesc</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>parent</i> be the result of calling the [[GetPrototypeOf]] internal method of <i>O</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>parent</i>).</li>
+ <li>If <i>parent</i> is not <b>null</b>, then
+ <ol class="block">
+ <li>Return the result of calling the [[Set]] internal method of <i>parent</i> with arguments <i>P</i>, <i>V</i>,
+ and <i>Receiver</i>.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>ownDesc</i> be the PropertyDescriptor{[[Value]]: <b>undefined</b>, [[Writable]]: <b>true</b>,
+ [[Enumerable]]: <b>true</b>, [[Configurable]]: <b>true</b>}.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>If <a href="#sec-isdatadescriptor">IsDataDescriptor</a>(<i>ownDesc</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>If <i>ownDesc</i>.[[Writable]] is <b>false</b>, return <b>false</b>.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>Receiver</i>) is not Object, return
+ <b>false</b>.</li>
+ <li>Let <i>existingDescriptor</i> be the result of calling the [[GetOwnProperty]] internal method of <i>Receiver</i>
+ with argument <i>P</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>existingDescriptor</i>).</li>
+ <li>If <i>existingDescriptor</i> is not <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>valueDesc</i> be the PropertyDescriptor{[[Value]]: <i>V</i>}.</li>
+ <li>Return the result of calling the [[DefineOwnProperty]] internal method of <i>Receiver</i> with arguments
+ <i>P</i> and <i>valueDesc</i>.</li>
+ </ol>
+ </li>
+ <li>Else <i>Receiver</i> does not currently have a property <i>P</i>,
+ <ol class="block">
+ <li>Return <a href="#sec-createdataproperty">CreateDataProperty</a>(<i>Receiver</i>, <i>P</i>, <i>V</i>).</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>If <a href="#sec-isaccessordescriptor">IsAccessorDescriptor</a>(<i>ownDesc</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>setter</i> be <i>ownDesc</i>.[[Set]].</li>
+ <li>If <i>setter</i> is <b>undefined</b>, return <b>false</b>.</li>
+ <li>Let <i>setterResult</i> be the result of calling the [[Call]] internal method of <i>setter</i> providing
+ <i>Receiver</i> as <i>thisArgument</i> and a new <a href="#sec-list-and-record-specification-type">List</a>
+ containing <i>V</i> as <i>argumentsList</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>setterResult</i>).</li>
+ <li>Return <b>true</b>.</li>
+ </ol>
+ </li>
+ </ol>
+ </section>
+
+ <section id="sec-ordinary-object-internal-methods-and-internal-slots-delete-p">
+ <h1><span class="secnum" id="sec-9.1.10"><a href="#sec-ordinary-object-internal-methods-and-internal-slots-delete-p"
+ title="link to this section">9.1.10</a></span> [[Delete]] (P)</h1>
+
+ <p>When the [[Delete]] internal method of <var>O</var> is called with <a href="#sec-object-type">property key</a>
+ <var>P</var> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ispropertykey">IsPropertyKey</a>(<i>P</i>) is
+ <b>true</b>.</li>
+ <li>Let <i>desc</i> be the result of calling the [[GetOwnProperty]] internal method of <i>O</i> with argument
+ <i>P</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>desc</i>).</li>
+ <li>If <i>desc</i> is <b>undefined</b>, then return <b>true</b>.</li>
+ <li>If <i>desc</i>.[[Configurable]] is <b>true</b>, then
+ <ol class="block">
+ <li>Remove the own property with name <i>P</i> from <i>O</i>.</li>
+ <li>Return <b>true</b>.</li>
+ </ol>
+ </li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-ordinary-object-internal-methods-and-internal-slots-enumerate">
+ <h1><span class="secnum" id="sec-9.1.11"><a href="#sec-ordinary-object-internal-methods-and-internal-slots-enumerate"
+ title="link to this section">9.1.11</a></span> [[Enumerate]] ()</h1>
+
+ <p>When the [[Enumerate]] internal method of <var>O</var> is called the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Return an Iterator object (<a href="#sec-iterator-interface">25.1.2</a>) whose next method iterates over all the
+ String-valued keys of enumerable properties of <i>O</i>. The mechanics and order of enumerating the properties is not
+ specified but must conform to the rules specified below.</li>
+ </ol>
+
+ <p>Enumerated properties do not include properties whose <a href="#sec-object-type">property key</a> is a Symbol. Properties
+ of the object being enumerated may be deleted during enumeration. If a property that has not yet been visited during
+ enumeration is deleted, then it will not be visited. If new properties are added to the object being enumerated during
+ enumeration, the newly added properties are not guaranteed to be visited in the active enumeration. A property name must not
+ be visited more than once in any enumeration.</p>
+
+ <p>Enumerating the properties of an object includes enumerating properties of its prototype, and the prototype of the
+ prototype, and so on, recursively; but a property of a prototype is not enumerated if it is “shadowed” because
+ some previous object in the prototype chain has a property with the same name. The values of [[Enumerable]] attributes are
+ not considered when determining if a property of a prototype object is shadowed by a previous object on the prototype
+ chain.</p>
+
+ <p>The following is an informative algorithm that conforms to these rules</p>
+
+ <ol class="proc">
+ <li>Let <i>proto</i> be the result of calling the [[GetPrototypeOf]] internal method of <i>O</i> with no arguments.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>proto</i>).</li>
+ <li>If <i>proto</i> is the value <b>null</b>, then
+ <ol class="block">
+ <li>Let <i>propList</i> be a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ </li>
+ <li>Else
+ <ol class="block">
+ <li>Let <i>propList</i> be the result of calling the [[Enumerate]] internal method of <i>proto</i>.</li>
+ </ol>
+ </li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>propList</i>).</li>
+ <li>For each <i>name</i> that is the <a href="#sec-object-type">property key</a> of an own property of <i>O</i>
+ <ol class="block">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>name</i>) is String, then
+ <ol class="block">
+ <li>Let <i>desc</i> be the result of calling the [[GetOwnProperty]] internal method of <i>O</i> with argument
+ <i>name</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>desc</i>).</li>
+ <li>If <i>name</i> is an element of <i>propList</i>, then remove <i>name</i> as an element of
+ <i>propList</i>.</li>
+ <li>If <i>desc</i>.[[Enumerable]] is <b>true</b>, then add <i>name</i> as an element of <i>propList</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Order the elements of <i>propList</i> in an implementation defined order.</li>
+ <li>Return <i>propList</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-ordinary-object-internal-methods-and-internal-slots-ownpropertykeys">
+ <h1><span class="secnum" id="sec-9.1.12"><a href="#sec-ordinary-object-internal-methods-and-internal-slots-ownpropertykeys"
+ title="link to this section">9.1.12</a></span> [[OwnPropertyKeys]] ( )</h1>
+
+ <p>When the [[OwnPropertyKeys]] internal method of <var>O</var> is called the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>keys</i> be a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>For each own <a href="#sec-object-type">property key</a> <i>P</i> of <i>O</i> that is an integer index, in ascending
+ numeric index order
+ <ol class="block">
+ <li>Add <i>P</i> as the last element of <i>keys</i>.</li>
+ </ol>
+ </li>
+ <li>For each own <a href="#sec-object-type">property key</a> <i>P</i> of <i>O</i> that is a String but is not an integer
+ index, in property creation order
+ <ol class="block">
+ <li>Add <i>P</i> as the last element of <i>keys</i>.</li>
+ </ol>
+ </li>
+ <li>For each own <a href="#sec-object-type">property key</a> <i>P</i> of <i>O</i> that is a Symbol, in property creation
+ order
+ <ol class="block">
+ <li>Add <i>P</i> as the last element of <i>keys</i>.</li>
+ </ol>
+ </li>
+ <li>Return <a href="#sec-createarrayfromlist">CreateArrayFromList</a>(<i>keys</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-objectcreate">
+ <h1><span class="secnum" id="sec-9.1.13"><a href="#sec-objectcreate" title="link to this section">9.1.13</a></span>
+ ObjectCreate(proto, internalSlotsList) Abstract Operation</h1>
+
+ <p>The abstract operation ObjectCreate with argument <i>proto</i> (an object or null) is used to specify the runtime
+ creation of new ordinary objects. The optional argument <var>internalSlotsList</var> is a <a
+ href="#sec-list-and-record-specification-type">List</a> of the names of additional internal slots that must be defined as
+ part of the object. If the list is not provided, an empty <a href="#sec-list-and-record-specification-type">List</a> is
+ used. This abstract operation performs the following steps:</p>
+
+ <ol class="proc">
+ <li>If <i>internalSlotsList</i> was not provided, let <i>internalSlotsList</i> be an empty <a
+ href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Let <i>obj</i> be a newly created object with an <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> for each name in <i>internalSlotsList</i>.</li>
+ <li>Set <i>obj</i>’s essential internal methods to the default ordinary object definitions specified in <a
+ href="#sec-ordinary-object-internal-methods-and-internal-slots">9.1</a>.</li>
+ <li>Set the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>obj</i> to
+ <i>proto</i>.</li>
+ <li>Set the [[Extensible]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>obj</i> to
+ <b>true</b>.</li>
+ <li>Return <i>obj</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-ordinarycreatefromconstructor">
+ <h1><span class="secnum" id="sec-9.1.14"><a href="#sec-ordinarycreatefromconstructor"
+ title="link to this section">9.1.14</a></span> OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto,
+ internalSlotsList )</h1>
+
+ <p>The abstract operation OrdinaryCreateFromConstructor creates an ordinary object whose [[Prototype]] value is retrieved
+ from a constructor’s <code>prototype</code> property, if it exists. Otherwise the supplied default is used for
+ [[Prototype]]. The optional <var>internalSlotsList</var> is a <a href="#sec-list-and-record-specification-type">List</a> of
+ the names of additional internal slots that must be defined as part of the object. If the list is not provided, an empty <a
+ href="#sec-list-and-record-specification-type">List</a> is used. This abstract operation performs the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>intrinsicDefaultProto</i> is a string value that is this
+ specification’s name of an intrinsic object. The corresponding object must be an intrinsic that is intended to
+ be used as the [[Prototype]] value of an object.</li>
+ <li>Let <i>proto</i> be <a href="#sec-getprototypefromconstructor">GetPrototypeFromConstructor</a>(<i>constructor</i>,
+ <i>intrinsicDefaultProto</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>proto</i>).</li>
+ <li>Return <a href="#sec-objectcreate">ObjectCreate</a>(<i>proto</i>, <i>internalSlotsList</i>).</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-ecmascript-function-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-9.2"><a href="#sec-ecmascript-function-objects" title="link to this section">9.2</a></span>
+ ECMAScript Function Objects</h1>
+
+ <p>ECMAScript function objects encapsulate parameterized ECMAScript code closed over a <a
+ href="#sec-lexical-environments">lexical environment</a> and support the dynamic evaluation of that code. An ECMAScript
+ function object is an ordinary object and has the same internal slots and (except as noted below) and the same internal
+ methods as other ordinary objects. The code of an ECMAScript function object may be either <a
+ href="#sec-strict-mode-code">strict mode code</a> (<a href="#sec-strict-mode-code">10.2.1</a>) or non-<a
+ href="#sec-strict-mode-code">strict mode code</a>.</p>
+
+ <p>ECMAScript function objects have the additional internal slots listed in <a href="#table-26">Table 26</a>.</p>
+
+ <p>ECMAScript function objects whose code is not <a href="#sec-strict-mode-code">strict mode code</a> (<a
+ href="#sec-strict-mode-code">10.2.1</a>) provide an alternative definition for the [[GetOwnProperty]] internal method. This
+ alternative prevents the value of strict mode function from being revealed as the value of a function object property named
+ "<code>caller</code>". The alternative definition exist solely to preclude a non-standard legacy feature of some ECMAScript
+ implementations from revealing information about strict mode callers. If an implementation does not provide such a feature,
+ it need not implement this alternative internal method for ECMAScript function objects. ECMAScript function objects are
+ considered to be ordinary objects even though they may use the alternative definition of [[GetOwnProperty]].</p>
+
+ <figure>
+ <figcaption><span id="table-26">Table 26</span> — Internal Slots of ECMAScript Function Objects</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-top: 2px solid #000000">Internal Slot</th>
+ <th style="border-bottom: 1px solid #000000; border-top: 2px solid #000000">Type</th>
+ <th style="border-bottom: 1px solid #000000; border-right: 1px solid #000000; border-top: 2px solid #000000">Description</th>
+ </tr>
+ <tr>
+ <td>[[Environment]]</td>
+ <td><a href="#sec-lexical-environments">Lexical Environment</a></td>
+ <td>The <a href="#sec-lexical-environments">Lexical Environment</a> that the function was closed over. Used as the outer environment when evaluating the code of the function.</td>
+ </tr>
+ <tr>
+ <td>[[FormalParameters]]</td>
+ <td>Parse Node</td>
+ <td>The root parse node of the source code that defines the function’s formal parameter list.</td>
+ </tr>
+ <tr>
+ <td>[[FunctionKind]]</td>
+ <td>String</td>
+ <td>Either "<code>normal</code>" or "<code>generator</code>".</td>
+ </tr>
+ <tr>
+ <td>[[Code]]</td>
+ <td>Parse Node</td>
+ <td>The root parse node of the source code that defines the function’s body.</td>
+ </tr>
+ <tr>
+ <td>[[Realm]]</td>
+ <td><a href="#sec-code-realms">Realm</a> Record</td>
+ <td>The <a href="#sec-code-realms">Code Realm</a> in which the function was created and which provides any intrinsic objects that are accessed when evaluating the function.</td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid #808080; border-left: 1px solid #808080; border-right: 1px solid #808080; border-top: 1px solid #808080">[[ThisMode]]</td>
+ <td style="border-bottom: 1px solid #808080; border-left: 1px solid #808080; border-right: 1px solid #808080; border-top: 1px solid #808080">(lexical, strict, global)</td>
+ <td style="border-bottom: 1px solid #808080; border-left: 1px solid #808080; border-right: 1px solid #808080; border-top: 1px solid #808080">Defines how <code>this</code> references are interpreted within the formal parameters and code body of the function. <b>lexical</b> means that <code>this</code> refers to the <b>this</b> value of a lexically enclosing function. <b>strict</b> means that the <b>this</b> value is used exactly as provided by an invocation of the function. <b>global</b> means that a <b>this</b> value of <span class="value">undefined</span> is interpreted as a reference to the global object.</td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 1px solid #808080; border-left: 1px solid #808080; border-right: 1px solid #808080; border-top: 1px solid #808080">[[Strict]]</td>
+ <td style="border-bottom: 1px solid #808080; border-left: 1px solid #808080; border-right: 1px solid #808080; border-top: 1px solid #808080">Boolean</td>
+ <td style="border-bottom: 1px solid #808080; border-left: 1px solid #808080; border-right: 1px solid #808080; border-top: 1px solid #808080"><span class="value">true</span> if this is a strict mode function, <span class="value">false</span> if this is not a strict mode function.</td>
+ </tr>
+ <tr>
+ <td>[[NeedsSuper]]</td>
+ <td>Boolean</td>
+ <td><span class="value">true</span> if this function uses <code>super</code>.</td>
+ </tr>
+ <tr>
+ <td>[[HomeObject]]</td>
+ <td>Object</td>
+ <td>If the function uses <code>super</code>, this is the object whose [[GetPrototypeOf]] provides the object where <code>super</code> property lookups begin.</td>
+ </tr>
+ <tr>
+ <td>[[MethodName]]</td>
+ <td>String or Symbol</td>
+ <td>If the function uses <code>super</code>, this is the <a href="#sec-object-type">property key</a> that is used for unqualified references to <code>super</code>.</td>
+ </tr>
+ </table>
+ </figure>
+
+ <p>All ECMAScript function objects have the [[Call]] internal method defined here. ECMAScript functions that are also
+ constructors in addition have the [[Construct]] internal method. ECMAScript function objects whose code is not <a
+ href="#sec-strict-mode-code">strict mode code</a> have the [[Get]] and [[GetOwnProperty]] internal methods defined here.</p>
+ </div>
+
+ <section id="sec-ecmascript-function-objects-getownproperty-p">
+ <h1><span class="secnum" id="sec-9.2.1"><a href="#sec-ecmascript-function-objects-getownproperty-p"
+ title="link to this section">9.2.1</a></span> [[GetOwnProperty]] (P)</h1>
+
+ <p>When the [[GetOwnProperty]] internal method of non-strict <a href="#sec-ecmascript-function-objects">ECMAScript function
+ object</a> <var>F</var> is called with <a href="#sec-object-type">property key</a> <var>P</var>, the following steps are
+ taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>v</i> be <a href="#sec-ordinarygetownproperty">OrdinaryGetOwnProperty</a>(<i>F</i>, <i>P</i>).</li>
+ <li>If <a href="#sec-isdatadescriptor">IsDataDescriptor</a>(<i>v</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>If <i>P</i> is <code>"caller"</code> then,
+ <ol class="block">
+ <li>Let <i>callerValue</i> be <i>v</i>.[[Value]].</li>
+ <li>If <i>callerValue</i> is an <a href="#sec-ecmascript-function-objects">ECMAScript Function object</a>, then
+ <ol class="block">
+ <li>If <i>callerValue</i>’s [[Strict]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is <b>true</b>, then set
+ <i>v</i>.[[Value]] to <b>null</b>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Return <i>v</i>.</li>
+ </ol>
+
+ <p>If an implementation does not provide a built-in <code>caller</code> property for non-strict ECMAScript function objects
+ then it must not use this definition. Instead the ordinary object [[GetOwnProperty]] internal method is used.</p>
+ </section>
+
+ <section id="sec-ecmascript-function-objects-call-thisargument-argumentslist">
+ <h1><span class="secnum" id="sec-9.2.2"><a href="#sec-ecmascript-function-objects-call-thisargument-argumentslist"
+ title="link to this section">9.2.2</a></span> [[Call]] ( thisArgument, argumentsList)</h1>
+
+ <p>The [[Call]] internal method for an <a href="#sec-ecmascript-function-objects">ECMAScript function object</a>
+ <var>F</var> is called with parameters <var>thisArgument</var> and <var>argumentsList</var>, a <a
+ href="#sec-list-and-record-specification-type">List</a> of <a href="#sec-ecmascript-language-types">ECMAScript language
+ values</a>. The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>If <i>F</i>’s [[Code]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> has the value
+ <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>callerContext</i> be <a href="#sec-execution-contexts">the running execution context</a>.</li>
+ <li>If <i>callerContext</i> is not already <a href="#sec-execution-contexts">suspended</a>, then <a
+ href="#sec-execution-contexts">Suspend</a> <i>callerContext</i>.</li>
+ <li>Let <i>calleeContext</i> be a new <a href="#sec-execution-contexts">ECMAScript Code execution context</a>.</li>
+ <li>Let <i>calleeRealm</i> be the value of <i>F’s</i> [[Realm]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Set <i>calleeContext’s</i> <a href="#sec-code-realms">Realm</a> to <i>calleeRealm</i>.</li>
+ <li>Let <i>thisMode</i> be the value of <i>F</i>’s [[ThisMode]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>needsThisWrapper</i> be <b>false.</b></li>
+ <li>If <i>thisMode</i> is <span style="font-family: sans-serif">lexical</span>, then
+ <ol class="block">
+ <li>Let <i>localEnv</i> be the result of calling <a
+ href="#sec-newdeclarativeenvironment">NewDeclarativeEnvironment</a> passing the value of the [[Environment]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>F</i> as the argument.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>If <i>thisMode</i> is <span style="font-family: sans-serif">strict</span>, then let <i>thisValue</i> be
+ <i>thisArgument</i>.</li>
+ <li>Else
+ <ol class="block">
+ <li>if <i>thisArgument</i> is <b>null</b> or <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>thisValue</i> be <i>calleeRealm</i>.[[globalThis]].</li>
+ </ol>
+ </li>
+ <li>Else
+ <ol class="block">
+ <li>if <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>thisArgument</i>) is not Object, then let
+ <i>needsThisWrapper</i> be <b>true.</b></li>
+ <li>Let <i>thisValue</i> be <i>thisArgument</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Let <i>localEnv</i> be <a href="#sec-newfunctionenvironment">NewFunctionEnvironment</a>(<i>F</i>,
+ <i>thisValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>localEnv</i>).</li>
+ <li><span style="font-family: sans-serif">NOTE Any exception objects produced by <a
+ href="#sec-newfunctionenvironment">NewFunctionEnvironment</a> are associated with</span> <i>callerReam</i>.</li>
+ </ol>
+ </li>
+ <li>Set the <a href="#sec-execution-contexts">LexicalEnvironment</a> of <i>calleeContext</i> to <i>localEnv</i>.</li>
+ <li>Set the <a href="#sec-execution-contexts">VariableEnvironment</a> of <i>calleeContext</i> to <i>localEnv</i>.</li>
+ <li>Push <i>calleeContext</i> onto <a href="#sec-execution-contexts">the execution context stack</a>; <i>calleeContext</i>
+ is now <a href="#sec-execution-contexts">the running execution context</a>.</li>
+ <li>If <i>needsThisWrapper</i> is <b>true</b> then,
+ <ol class="block">
+ <li>Let <i>wrapperedThis</i> be <a href="#sec-toobject">ToObject</a>(<i>thisArgument</i>).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>wrapperedThis</i> is not an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a>.</li>
+ <li><span style="font-family: sans-serif">NOTE Wrappering deferred until</span> <i>calleeContext</i> <span
+ style="font-family: sans-serif">is running so that <a href="#sec-toobject">ToObject</a> produces objects
+ using</span> <i>calleeRealm</i>.</li>
+ <li>Let <i>functionEnv</i> be <i>localEnv</i>’s environment record.</li>
+ <li>Set <i>functionEnv</i>’s <i>thisValue</i> to <i>wrapperedThis</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>status</i> be the result of performing <a
+ href="#sec-functiondeclarationinstantiation">FunctionDeclarationInstantiation</a> using the function <i>F</i>,
+ <i>argumentsList</i> , and <i>localEnv</i> as described in <a
+ href="#sec-functiondeclarationinstantiation">9.2.13</a>.</li>
+ <li>If <i>status</i> is an <a href="#sec-completion-record-specification-type">abrupt completion</a>, then
+ <ol class="block">
+ <li>Remove <i>calleeContext</i> from <a href="#sec-execution-contexts">the execution context stack</a> and restore
+ <i>callerContext</i> as <a href="#sec-execution-contexts">the running execution context</a>.</li>
+ <li>Return <i>status</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>result</i> be the result of EvaluateBody of the production that is the value of <i>F</i>'s [[Code]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> passing <i>F</i> as the argument.</li>
+ <li>Remove <i>calleeContext</i> from <a href="#sec-execution-contexts">the execution context stack</a> and restore
+ <i>callerContext</i> as <a href="#sec-execution-contexts">the running execution context</a>.</li>
+ <li>Return <i>result</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> Most ECMAScript functions use a <a href="#sec-function-environment-records">Function
+ Environment Record</a> as their <a href="#sec-execution-contexts">LexicalEnvironment</a>. ECMAScript functions that are
+ arrow functions use a <a href="#sec-declarative-environment-records">Declarative Environment Record</a> as their <a
+ href="#sec-execution-contexts">LexicalEnvironment</a>.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 2</span> When <i>calleeContext</i> is removed from <a href="#sec-execution-contexts">the
+ execution context stack</a> it must not be destroyed because it may have been <a
+ href="#sec-execution-contexts">suspended</a> and retained by a generator object for later resumption<i>.</i></p>
+ </div>
+ </section>
+
+ <section id="sec-construct-argumentslist">
+ <h1><span class="secnum" id="sec-9.2.3"><a href="#sec-construct-argumentslist" title="link to this section">9.2.3</a></span>
+ [[Construct]] ( argumentsList)</h1>
+
+ <p>The [[Construct]] internal method for an <a href="#sec-ecmascript-function-objects">ECMAScript Function object</a>
+ <var>F</var> is called with a single parameter <var>argumentsList</var> which is a possibly empty <a
+ href="#sec-list-and-record-specification-type">List</a> of <a href="#sec-ecmascript-language-types">ECMAScript language
+ values</a>. The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Return <a href="#sec-construct-f-argumentslist">Construct</a>(<i>F</i>, <i>argumentsList</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-functionallocate">
+ <h1><span class="secnum" id="sec-9.2.4"><a href="#sec-functionallocate" title="link to this section">9.2.4</a></span>
+ FunctionAllocate (functionPrototype, strict) Abstract Operation</h1>
+
+ <p>The abstract operation FunctionAllocate requires the two arguments <span style="font-family: Times New
+ Roman"><i>functionPrototype</i> and <i>strict</i>.</span> It also accepts one optional argument, <var>functionKind</var>.
+ FunctionAllocate performs the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>functionPrototype</i>) is Object.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: If <i>functionKind</i> is present, its value is either
+ "<code>normal</code>" or "<code>generator</code>".</li>
+ <li>If <i>functionKind</i> is not present, then let <i>functionKind</i> be "<code>normal</code>".</li>
+ <li>Let <i>F</i> be a newly created <a href="#sec-ecmascript-function-objects">ECMAScript function object</a> with the
+ internal slots listed in <a href="#table-26">Table 26</a>. All of those internal slots are initialized to
+ <b>undefined</b>.</li>
+ <li>Set <i>F</i>’s essential internal methods except for [[GetOwnProperty]] to the default ordinary object
+ definitions specified in <a href="#sec-ordinary-object-internal-methods-and-internal-slots">9.1</a>.</li>
+ <li>If <i>strict</i> is <b>true</b>, set <i>F</i>’s [[GetOwnProperty]] internal method to the default ordinary
+ object definitions specified in <a href="#sec-ordinary-object-internal-methods-and-internal-slots">9.1</a>.</li>
+ <li>Else, set <i>F</i>’s [[GetOwnProperty]] internal method to the definitions specified in <b>Error! <a
+ href="#sec-reference-specification-type">Reference</a> source not found.</b>.</li>
+ <li>Set <i>F</i>’s [[Call]] internal method to the definition specified in <a
+ href="#sec-ecmascript-function-objects-getownproperty-p">9.2.1</a>.</li>
+ <li>Set the [[Strict]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>F</i> to
+ <i>strict</i>.</li>
+ <li>Set the [[FunctionKind]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>F</i> to
+ <i>functionKind</i>.</li>
+ <li>Set the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>F</i> to
+ <i>functionPrototype</i>.</li>
+ <li>Set the [[Extensible]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>F</i> to
+ <b>true</b>.</li>
+ <li>Set the [[Realm]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>F</i> to <a
+ href="#sec-execution-contexts">the running execution context</a>’s <a href="#sec-code-realms">Realm</a>.</li>
+ <li>Return <i>F</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-functioninitialize">
+ <h1><span class="secnum" id="sec-9.2.5"><a href="#sec-functioninitialize" title="link to this section">9.2.5</a></span>
+ FunctionInitialize (F, kind, Strict, ParameterList, Body, Scope) Abstract Operation</h1>
+
+ <p>The abstract operation FunctionInitialize requires the arguments: a function object <var>F</var>, <var>kind</var> which
+ is one of (Normal, Method, Arrow), a Boolean <span class="nt">Strict</span>, a parameter list production specified by <span
+ class="nt">ParameterList</span>, a body production specified by <span class="nt">Body</span>, a <a
+ href="#sec-lexical-environments">Lexical Environment</a> specified by <span style="font-family: Times New
+ Roman"><i>Scope</i>.</span> FunctionInitialize performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>len</i> be the ExpectedArgumentCount of <i>ParameterList</i>.</li>
+ <li>Let <i>realm</i> be the value of <i>F’s</i> [[Realm]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>status</i> be <a href="#sec-definepropertyorthrow">DefinePropertyOrThrow</a>(<i>F</i>, <code>"length"</code>,
+ PropertyDescriptor{[[Value]]: <i>len</i>, [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>true</b>}).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>If <i>Strict</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>status</i> be <a href="#sec-addrestrictedfunctionproperties">AddRestrictedFunctionProperties</a>(<i>F</i>,
+ <i>realm</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ </ol>
+ </li>
+ <li>Set the [[Strict]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>F</i> to
+ <i>Strict</i>.</li>
+ <li>Set the [[Environment]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>F</i> to the
+ value of <i>Scope</i>.</li>
+ <li>Set the [[FormalParameters]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>F</i>
+ to <i>ParameterList</i> .</li>
+ <li>Set the [[Code]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>F</i> to
+ <i>Body</i>.</li>
+ <li>If <i>kind</i> is <span style="font-family: sans-serif">Arrow</span>, then set the [[ThisMode]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>F</i> to <span style="font-family:
+ sans-serif">lexical</span>.</li>
+ <li>Else if <i>Strict</i> is <b>true</b>, then set the [[ThisMode]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>F</i> to <span style="font-family:
+ sans-serif">strict</span>.</li>
+ <li>Else set the [[ThisMode]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>F</i> to
+ <span style="font-family: sans-serif">global</span>.</li>
+ <li>Return <i>F</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-functioncreate">
+ <h1><span class="secnum" id="sec-9.2.6"><a href="#sec-functioncreate" title="link to this section">9.2.6</a></span>
+ FunctionCreate (kind, ParameterList, Body, Scope, Strict) Abstract Operation</h1>
+
+ <p>The abstract operation FunctionCreate requires the arguments: <var>kind</var> which is one of (Normal, Method, Arrow), a
+ parameter list production specified by <span class="nt">ParameterList</span>, a body production specified by <span
+ class="nt">Body</span>, a <a href="#sec-lexical-environments">Lexical Environment</a> specified by <span
+ class="nt">Scope</span>, a Boolean flag <span class="nt">Strict</span>, and optionally, an object <span style="font-family:
+ Times New Roman"><i>functionPrototype</i>.</span> FunctionCreate performs the following steps:</p>
+
+ <ol class="proc">
+ <li>If the <i>functionPrototype</i> argument was not passed, then
+ <ol class="block">
+ <li>Let <i>functionPrototype</i> be the intrinsic object %FunctionPrototype%.</li>
+ </ol>
+ </li>
+ <li>Let <i>F</i> be <a href="#sec-functionallocate">FunctionAllocate</a>(<i>functionPrototype</i>, <i>Strict</i>).</li>
+ <li>Return <a href="#sec-functioninitialize">FunctionInitialize</a>(<i>F</i>, <i>kind</i>, <i>Strict</i>,
+ <i>ParameterList</i>, <i>Body</i>, <i>Scope</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-generatorfunctioncreate">
+ <h1><span class="secnum" id="sec-9.2.7"><a href="#sec-generatorfunctioncreate" title="link to this section">9.2.7</a></span>
+ GeneratorFunctionCreate (kind, ParameterList, Body, Scope, Strict) Abstract Operation</h1>
+
+ <p>The abstract operation GeneratorFunctionCreate requires the arguments: <var>kind</var> which is one of (Normal, Method,
+ Arrow), a parameter list production specified by <span class="nt">ParameterList</span>, a body production specified by <span
+ class="nt">Body</span>, a <a href="#sec-lexical-environments">Lexical Environment</a> specified by <span
+ class="nt">Scope</span>, and a Boolean flag <span class="nt">Strict</span>. GeneratorFunctionCreate performs the following
+ steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>functionPrototype</i> be the intrinsic object %Generator%.</li>
+ <li>Let <i>F</i> be <a href="#sec-functionallocate">FunctionAllocate</a>(<i>functionPrototype</i>, <i>Strict</i>,
+ <code>"generator"</code>).</li>
+ <li>Return <a href="#sec-functioninitialize">FunctionInitialize</a>(<i>F</i>, <i>kind</i>, <i>Strict</i>,
+ <i>ParameterList</i>, <i>Body</i>, <i>Scope</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-addrestrictedfunctionproperties">
+ <div class="front">
+ <h1><span class="secnum" id="sec-9.2.8"><a href="#sec-addrestrictedfunctionproperties"
+ title="link to this section">9.2.8</a></span> AddRestrictedFunctionProperties ( F, realm ) Abstract Operation</h1>
+
+ <p>The abstract operation AddRestrictedFunctionProperties is called with a function object <var>F</var> and <a
+ href="#sec-code-realms">Realm</a> Record <var>realm</var> as its argument. It performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>thrower</i> be <i>realmRec</i>.[[intrinsics]].[[<span style="font-family:
+ sans-serif">%ThrowTypeError%]]</span></li>
+ <li>Let <i>status</i> be <a href="#sec-definepropertyorthrow">DefinePropertyOrThrow</a>(<i>F</i>, <code>"caller"</code>,
+ PropertyDescriptor {[[Get]]: <i>thrower</i>, [[Set]]: <i>thrower</i>, [[Enumerable]]: <b>false</b>,
+ [[Configurable]]: <b>false</b>}).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Return <a href="#sec-definepropertyorthrow">DefinePropertyOrThrow</a>(<i>F</i> , <code>"arguments"</code>,
+ PropertyDescriptor {[[Get]]: <i>thrower</i>, [[Set]]: <i>thrower</i>, [[Enumerable]]: <b>false</b>,
+ [[Configurable]]: <b>false</b>}).</li>
+ </ol>
+ </div>
+
+ <section id="sec-%throwtypeerror%">
+ <h1><span class="secnum" id="sec-9.2.8.1"><a href="#sec-%throwtypeerror%" title="link to this section">9.2.8.1</a></span>
+ %ThrowTypeError% ( )</h1>
+
+ <p>The %ThrowTypeError% intrinsic is an anonymous built-in function object that is defined once for each <a
+ href="#sec-code-realms">Realm</a>. When %ThrowTypeError% is called it performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Throw a <b>TypeError</b> exception.</li>
+ </ol>
+
+ <p>The value of the [[Extensible]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of a
+ %ThrowTypeError% function is <span class="value">false</span>.</p>
+ </section>
+ </section>
+
+ <section id="sec-makeconstructor">
+ <h1><span class="secnum" id="sec-9.2.9"><a href="#sec-makeconstructor" title="link to this section">9.2.9</a></span>
+ MakeConstructor (F, writablePrototype, prototype) Abstract Operation</h1>
+
+ <p>The abstract operation MakeConstructor requires a Function argument <var>F</var> and optionally, a Boolean
+ <var>writablePrototype</var> and an object <var>prototype</var>. If <var>prototype</var> is provided it is assumed to
+ already contain, if needed, a <code>"constructor"</code> property whose value is <var>F</var>. This operation converts
+ <var>F</var> into a constructor by performing the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>F</i> is an <a href="#sec-ecmascript-function-objects">ECMAScript
+ function object</a>.</li>
+ <li>Let <i>installNeeded</i> be <b>false</b>.</li>
+ <li>If the <i>prototype</i> argument was not provided, then
+ <ol class="block">
+ <li>Let <i>installNeeded</i> be <b>true</b>.</li>
+ <li>Let <i>prototype</i> be <a href="#sec-objectcreate">ObjectCreate</a>(<span style="font-family:
+ sans-serif">%ObjectPrototype%</span>).</li>
+ </ol>
+ </li>
+ <li>If the <i>writablePrototype</i> argument was not provided, then
+ <ol class="block">
+ <li>Let <i>writablePrototype</i> be <b>true</b>.</li>
+ </ol>
+ </li>
+ <li>Set <i>F</i>’s essential internal method [[Construct]] to the definition specified in <a
+ href="#sec-construct-argumentslist">9.2.3</a>.</li>
+ <li>If <i>installNeeded</i>, then
+ <ol class="block">
+ <li>Let <i>status</i> be <a href="#sec-definepropertyorthrow">DefinePropertyOrThrow</a>(<i>prototype</i>,
+ <code>"constructor"</code>, PropertyDescriptor{[[Value]]: <i>F</i>, [[Writable]]: <i>writablePrototype</i>,
+ [[Enumerable]]: <b>false</b>, [[Configurable]]: <i>writablePrototype</i> }).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ </ol>
+ </li>
+ <li>Let <i>status</i> be <a href="#sec-definepropertyorthrow">DefinePropertyOrThrow</a>(<i>F</i>,
+ <code>"prototype"</code>, PropertyDescriptor{[[Value]]: <i>prototype</i>, [[Writable]]: <i>writablePrototype</i>,
+ [[Enumerable]]: <b>false</b>, [[Configurable]]: <b>false</b>}).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<b>undefined</b>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-makemethod">
+ <h1><span class="secnum" id="sec-9.2.10"><a href="#sec-makemethod" title="link to this section">9.2.10</a></span> MakeMethod
+ ( F, methodName, homeObject) Abstract Operation</h1>
+
+ <p>The abstract operation MakeMethod with arguments <var>F</var>, <var>methodName</var> and <var>homeObject</var> configures
+ <var>F</var> as a method by performing the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>F</i> is an <a href="#sec-ecmascript-function-objects">ECMAScript
+ function object</a>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>methodName</i> is either <b>undefined</b> or a <a
+ href="#sec-object-type">property key</a>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>homeObject</i> ) is either Undefined or Object.</li>
+ <li>Set the [[NeedsSuper]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>F</i> to
+ <b>true</b>.</li>
+ <li>Set the [[HomeObject]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>F</i> to
+ <i>homeObject</i>.</li>
+ <li>Set the [[MethodName]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>F</i> to
+ <i>methodName</i>.</li>
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<b>undefined</b>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-setfunctionname">
+ <h1><span class="secnum" id="sec-9.2.11"><a href="#sec-setfunctionname" title="link to this section">9.2.11</a></span>
+ SetFunctionName (F, name, prefix) Abstract Operation</h1>
+
+ <p>The abstract operation SetFunctionName requires a Function argument <var>F</var>, a String or Symbol argument
+ <var>name</var> and optionally a String argument <var>prefix</var>. This operation adds a <code>name</code> property to
+ <var>F</var> by performing the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>F</i> is an extensible <a
+ href="#sec-ecmascript-function-objects">ECMAScript function object</a> that does not have a <code>name</code> own
+ property.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>name</i>)
+ is either Symbol or String.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>name</i>) is Symbol, then
+ <ol class="block">
+ <li>Let <i>description</i> be <i>name</i>’s [[Description]] value.</li>
+ <li>If <i>description</i> is <b>undefined</b>, then let <i>name</i> be the empty String.</li>
+ <li>Else, let <i>name</i> be the concatenation of <code>"["</code>, <i>description</i>, and <code>"]"</code>.</li>
+ </ol>
+ </li>
+ <li>If <i>name</i> is not the empty string and <i>prefix</i> was passed, then let <i>name</i> be the concatenation of
+ <i>prefix</i>, Unicode code point U+0020 (Space) , and <i>name</i>.</li>
+ <li>Call the [[DefineOwnProperty]] internal method of <i>F</i> with arguments <code>"name"</code> and
+ PropertyDescriptor{[[Value]]: <i>name</i>, [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>true</b>}.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: Defining the <code>name</code> property will always succeed.</li>
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<b>undefined</b>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-clonemethod">
+ <h1><span class="secnum" id="sec-9.2.12"><a href="#sec-clonemethod" title="link to this section">9.2.12</a></span>
+ CloneMethod(function, newHome, newName) Abstract Operation</h1>
+
+ <p>The abstract operation Clone is called with a function object <var>function</var>, an object <var>newHome</var>, and a <a
+ href="#sec-object-type">property key</a> <var>newName</var> as its argument. It performs the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>function</i> is an <a
+ href="#sec-ecmascript-function-objects">ECMAScript function object</a> or an exotic Built-in function object.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>newHome</i>) is Object.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>newName</i>) one of Undefined, String, or Symbol.</li>
+ <li>If <i>function</i> is an ECMAScript function, then
+ <ol class="block">
+ <li>Let <i>new</i> be a new <a href="#sec-ecmascript-function-objects">ECMAScript function object</a> that has all of
+ the same internal methods and internal slots as <i>function</i>.</li>
+ </ol>
+ </li>
+ <li>Else
+ <ol class="block">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>function</i> is an exotic Built-in function object.</li>
+ <li>Let <i>new</i> be a new exotic Built-in function object that has all of the same internal methods and internal
+ slots as <i>function</i>.</li>
+ </ol>
+ </li>
+ <li>Set the value of each of <i>new’s</i> internal slots, except for [[Extensible]], [[HomeObject]] and
+ [[MethodName]] to the value of <i>function’s</i> corresponding <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Set <i>new</i>’s [[Extensible]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to
+ <b>true</b>.</li>
+ <li>If the value of <i>function</i>’s [[NeedsSuper]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is <b>true</b>, then
+ <ol class="block">
+ <li>Set the value of <i>new’s</i> [[HomeObject]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to <i>newHome</i>.</li>
+ <li>If <i>newName</i> is not <b>undefined</b>, then
+ <ol class="block">
+ <li>Set the value of <i>new’s</i> [[MethodName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to <i>newName</i>.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Set the value of <i>new’s</i> [[MethodName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to the value of
+ <i>function’s</i> [[MethodName]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>If <i>function</i> is an exotic Built-in function object or if <i>function</i>’s [[Strict]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>realm</i> be <i>new</i>’s [[Realm]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>status</i> be <a
+ href="#sec-addrestrictedfunctionproperties">AddRestrictedFunctionProperties</a>(<i>new</i>, <i>realm</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ </ol>
+ </li>
+ <li>Return <i>new</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The purpose of this abstract operation is to create a new function object that is
+ identical to the argument object in all always except for its identity and the value of its [[HomeObject]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>. However, properties of the function object,
+ except for the restricted function properties, are not created or copied.</p>
+ </div>
+ </section>
+
+ <section id="sec-functiondeclarationinstantiation">
+ <h1><span class="secnum" id="sec-9.2.13"><a href="#sec-functiondeclarationinstantiation"
+ title="link to this section">9.2.13</a></span> FunctionDeclarationInstantiation(func, argumentsList, env ) Abstract
+ Operation</h1>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> When an <a href="#sec-execution-contexts">execution context</a> is established for
+ evaluating an ECMAScript function a new <a href="#sec-declarative-environment-records">Declarative Environment Record</a>
+ is created and bindings for each formal parameter are instantiated in that environment record. Each declaration in the
+ function body is also instantiated. If the function’s formal parameters do not include any default value
+ initializers then the body declarations are instantiated in the same environment record as the parameters. If default
+ value parameter initializers exist, a second environment record is created for the body declarations. Formal parameters
+ and functions are initialized as part of FunctionDeclarationInstantiation. All other bindings are initialized during
+ evaluation of the function body.</p>
+ </div>
+
+ <p>FunctionDeclarationInstantiation is performed as follows using arguments <var>func,</var> <var>argumentsList</var>, and
+ <var>env</var>. <var>func</var> is the function object that for which the <a href="#sec-execution-contexts">execution
+ context</a> is being established. <var>env</var> is the <a href="#sec-declarative-environment-records">declarative
+ environment record</a> in which formal parameter bindings are to be created.</p>
+
+ <ol class="proc">
+ <li>Let <i>code</i> be the value of the [[Code]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> of <i>func</i>.</li>
+ <li>Let <i>strict</i> be the value of the [[Strict]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> of <i>func</i>.</li>
+ <li>Let <i>formals</i> be the value of the [[FormalParameters]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>func</i>.</li>
+ <li>Let <i>parameterNames</i> be the BoundNames of <i>formals</i>.</li>
+ <li>If <i>parameterNames</i> has any duplicate entries, let <i>hasDuplicates</i> be <b>true</b>. Otherwise, let
+ <i>hasDuplicates</i> be <b>false</b>.</li>
+ <li>Let <i>needsParameterEnvironment</i> be ContainsExpression of <i>formals</i>.</li>
+ <li>Let <i>simpleParameterList</i> be IsSimpleParameterList of <i>formals</i>.</li>
+ <li>Let <i>varNames</i> be the VarDeclaredNames of <i>code</i>.</li>
+ <li>Let <i>varDeclarations</i> be the VarScopedDeclarations of <i>code</i>.</li>
+ <li>Let <i>lexicalNames</i> be the LexicallyDeclaredNames of <i>code</i>.</li>
+ <li>Let <i>functionNames</i> be an empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Let <i>functionsToInitialize</i> be an empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>For each <i>d</i> in <i>varDeclarations</i>, in reverse list order do
+ <ol class="block">
+ <li>If <i>d</i> is neither a <i>VariableDeclaration</i> or a <i>ForBinding</i>, then
+ <ol class="block">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>d</i> is either a <i>FunctionDeclaration</i> or a
+ <i>GeneratorDeclaration</i>.</li>
+ <li>Let <i>fn</i> be the sole element of the BoundNames of <i>d.</i></li>
+ <li>If <i>fn</i> is not an element of <i>functionNames</i>, then
+ <ol class="block">
+ <li>Insert <i>fn</i> as the first element of <i>functionNames</i>.</li>
+ <li>NOTE If there are multiple <span style="font-family: Times New Roman"><i>FunctionDeclarations</i> or
+ <i>GeneratorDeclarations</i></span> for the same name, the last declaration is used.</li>
+ <li>Insert <i>d</i> as the first element of <i>functionsToInitialize</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Let <i>needsSpecialArgumentsBinding</i> be <b>true</b>.</li>
+ <li>Let <i>argumentsObjectNeeded</i> be <b>true</b>.</li>
+ <li>If the value of the [[ThisMode]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of
+ <i>func</i> is <span style="font-family: sans-serif">lexical</span>, then
+ <ol class="block">
+ <li>NOTE Arrow functions never have an arguments objects.</li>
+ <li>Let <i>needsSpecialArgumentsBinding</i> be <b>false</b>.</li>
+ <li>Let <i>argumentsObjectNeeded</i> be <b>false</b>.</li>
+ </ol>
+ </li>
+ <li>Else if "<code>arguments</code>" is an element of <i>parameterNames</i>, then
+ <ol class="block">
+ <li>Let <i>needsSpecialArgumentsBinding</i> be <b>false</b>.</li>
+ <li>Let <i>argumentsObjectNeeded</i> be <b>false</b>.</li>
+ </ol>
+ </li>
+ <li>Else
+ <ol class="block">
+ <li>If "<code>arguments</code>" is an element of <i>functionNames</i>, then let <i>argumentsObjectNeeded</i> be
+ <b>false</b>.</li>
+ <li>Else if "<code>arguments</code>" is an element of <i>lexicalNames</i>, then let <i>argumentsObjectNeeded</i> be
+ <b>false</b>.</li>
+ </ol>
+ </li>
+ <li>If <i>argumentsObjectNeeded</i> is <b>false</b>, then let <i>ao</i> be <b>undefined</b>.</li>
+ <li>Else,
+ <ol class="block">
+ <li>If <i>strict</i> is <b>true</b> or if <i>simpleParameterList</i> is <b>false</b>, then
+ <ol class="block">
+ <li>Let <i>ao</i> be <a
+ href="#sec-createunmappedargumentsobject">CreateUnmappedArgumentsObject</a>(<i>argumentsList</i>)<i>.</i></li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>ao</i> be <a href="#sec-createmappedargumentsobject">CreateMappedArgumentsObject</a>(<i>func</i>,
+ <i>formals</i>, <i>argumentsList</i>, <i>env</i>).</li>
+ </ol>
+ </li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>ao</i>).</li>
+ </ol>
+ </li>
+ <li>For each String <i>paramName</i> in <i>parameterNames</i>, do
+ <ol class="block">
+ <li>Let <i>alreadyDeclared</i> be the result of calling <i>env’s</i> HasBinding concrete method passing
+ <i>paramName</i> as the argument.</li>
+ <li>NOTE Early errors ensure that duplicate parameter names can only occur in non-strict functions that do not have
+ parameter default values or rest parameters.</li>
+ <li>If <i>alreadyDeclared</i> is <b>false</b>, then
+ <ol class="block">
+ <li>Let <i>status</i> be the result of calling <i>env’s</i> CreateMutableBinding concrete method passing
+ <i>paramName</i> as the argument.</li>
+ <li>If <i>hasDuplicates</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>status</i> be the result of calling <i>env’s</i> InitializeBinding concrete method passing
+ <i>paramName</i> and <b>undefined</b> as the argument.</li>
+ </ol>
+ </li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>status</i> is never an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a> for either of the above
+ operations.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Let <i>instantiatedVarNames</i> be a copy of the <a href="#sec-list-and-record-specification-type">List</a>
+ <i>parameterNames</i>.</li>
+ <li>If <i>needsSpecialArgumentsBinding</i> is <b>true</b>, then
+ <ol class="block">
+ <li>If <i>strict</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>status</i> be the result of calling <i>env’s</i> CreateImmutableBinding concrete method passing
+ "<code>arguments</code>" as the argument.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>status</i> be the result of calling <i>env’s</i> CreateMutableBinding concrete method passing
+ "<code>arguments</code>" as the argument.</li>
+ </ol>
+ </li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>status</i> is never an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a></li>
+ <li>If <i>argumentsObjectNeeded</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Call <i>env</i>’s InitializeBinding concrete method passing "<code>arguments</code>" and <i>ao</i> as
+ arguments.</li>
+ </ol>
+ </li>
+ <li>Append "<code>arguments</code>" to <i>instantiatedVarNames</i>.</li>
+ </ol>
+ </li>
+ <li>If <i>hasDuplicates</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>formalStatus</i> be the result of performing IteratorBindingInitialization for <i>formals</i> with <a
+ href="#sec-createlistiterator">CreateListIterator</a>(<i>argumentsList</i>) and <b>undefined</b> as
+ arguments.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>formalStatus</i> be the result of performing IteratorBindingInitialization for <i>formals</i> with <a
+ href="#sec-createlistiterator">CreateListIterator</a>(<i>argumentsList</i>) and <i>env</i> as arguments.</li>
+ </ol>
+ </li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>formalStatus</i>).</li>
+ <li>If <i>needsSpecialArgumentsBinding</i> is <b>true</b> and <i>argumentsObjectNeeded</i> is <b>false</b>, then
+ <ol class="block">
+ <li>Call <i>env</i>’s InitializeBinding concrete method passing "<code>arguments</code>" and <b>undefined</b> as
+ arguments.</li>
+ </ol>
+ </li>
+ <li>If <i>needsParameterEnvironment</i> is <b>true</b>, then
+ <ol class="block">
+ <li>NOTE	A separate enviornment record is needed to ensure that closures created by parameter default value
+ expressions do not have visibility of declarations in the function body.</li>
+ <li>Let <i>env</i> be <a href="#sec-newdeclarativeenvironment">NewDeclarativeEnvironment</a>(<i>env</i>).</li>
+ <li>Let <i>calleeContext</i> be <a href="#sec-execution-contexts">the running execution context</a>.</li>
+ <li>Set the <a href="#sec-execution-contexts">LexicalEnvironment</a> of <i>calleeContext</i> to <i>env</i>.</li>
+ <li>Set the <a href="#sec-execution-contexts">VariableEnvironment</a> of <i>calleeContext</i> to <i>env</i>.</li>
+ </ol>
+ </li>
+ <li>For each <i>n</i> in <i>varNames</i>, do
+ <ol class="block">
+ <li>If <i>n</i> is not an element of <i>instantiatedVarNames</i>, then
+ <ol class="block">
+ <li>Append <i>n</i> to <i>instantiatedVarNames</i>.</li>
+ <li>Let <i>status</i> be the result of calling <i>env’s</i> CreateMutableBinding concrete method passing
+ <i>n</i> as the argument.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>status</i> is never an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a>.</li>
+ <li>Call <i>env</i>’s InitializeBinding concrete method passing <i>n</i> and <b>undefined</b> as
+ arguments.</li>
+ <li>NOTE	vars and functions whose names are the same as a formal parameter, use the same binding element as
+ the parameter.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Let <i>lexDeclarations</i> be the LexicallyScopedDeclarations of <i>code</i>.</li>
+ <li>For each element <i>d</i> in <i>lexDeclarations</i> do
+ <ol class="block">
+ <li>NOTE	A lexically declared name cannot be the same as a function/generator declaration, formal parameter, or a
+ var name. Lexically declared names are only instantiated here but not initialized.</li>
+ <li>For each element <i>dn</i> of the BoundNames of <i>d</i> do
+ <ol class="block">
+ <li>If IsConstantDeclaration of <i>d</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>status</i> be the result of calling <i>env</i>’s CreateImmutableBinding concrete method
+ passing <i>dn</i> as the argument.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>status</i> be the result of calling <i>env</i>’s CreateMutableBinding concrete method passing
+ <i>dn</i> and <b>false</b> as the arguments.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>status</i> is never an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a>.</li>
+ </ol>
+ </li>
+ <li>For each production <i>f</i> in <i>functionsToInitialize</i>, do
+ <ol class="block">
+ <li>Let <i>fn</i> be the sole element of the BoundNames of <i>f.</i></li>
+ <li>Let <i>fo</i> be the result of performing InstantiateFunctionObject for <i>f</i> with argument <i>env</i>.</li>
+ <li>Let <i>fref</i> be <a href="#sec-resolvebinding">ResolveBinding</a>(<i>fn</i>).</li>
+ <li>Let <i>status</i> be <a href="#sec-putvalue">PutValue</a>(<i>fref</i>, <i>fo</i>).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>status</i> is never an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a>.</li>
+ </ol>
+ </li>
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<span style="font-family: sans-serif">empty</span>).</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> <a href="#sec-web-legacy-compatibility-for-block-level-function-declarations">B.3.2</a>
+ provides an extension to the above algorithm that is necessary for backwards compatability with web browser
+ implementations of ECAMScript that predate the sixth edition of ECMA-262.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-built-in-function-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-9.3"><a href="#sec-built-in-function-objects" title="link to this section">9.3</a></span>
+ Built-in Function Objects</h1>
+
+ <p>The built-in function objects defined in this specification may be implemented as either ECMAScript function objects (<a
+ href="#sec-ecmascript-function-objects">9.2</a>) whose behaviour is provided using ECMAScript code or as implementation
+ provided exotic function objects whose behaviour is provided in some other manner. In either case, the effect of calling
+ such functions must conform to their specifications.</p>
+
+ <p>If a built-in function object is implemented as an exotic object it must have the ordinary object behaviour specified in
+ <a href="#sec-ordinary-object-internal-methods-and-internal-slots">9.1</a> except [[GetOwnProperty]] which must be as
+ specified in <a href="#sec-ecmascript-function-objects-getownproperty-p">9.2.1</a>. All such exotic function objects also
+ have [[Prototype]] and [[Extensible]] internal slots.</p>
+
+ <p>Unless otherwise specified every built-in function object initially has the %FunctionPrototype% object (<a
+ href="#sec-properties-of-the-function-prototype-object">19.2.3</a>) as the initial value of its [[Prototype]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</p>
+
+ <p>The behaviour specified for each built-in function via algorithm steps or other means is the specification of the
+ [[Call]] behaviour for that function with the [[Call]] <var>thisArgument</var> providing the <span class="value">this</span>
+ value and the [[Call]] <var>argumentsList</var> providing the named parameters for each built-in function. If the built-in
+ function is implemented as an <a href="#sec-ecmascript-function-objects">ECMAScript function object</a> then this specified
+ behaviour must be implemented by the ECMAScript code that is the body of the function. Built-in functions that are
+ ECMAScript function objects must be strict mode functions.</p>
+
+ <p>Built-in function objects that are not identified as constructors do not implement the [[Construct]] internal method
+ unless otherwise specified in the description of a particular function. When a built-in constructor is called as part of a
+ <code>new</code> expression the <var>argumentsList</var> parameter of the invoked [[Construct]] internal method provides the
+ values for the built-in constructor’s named parameters.</p>
+
+ <p>Built-in functions that are not constructors do not have a <code>prototype</code> property unless otherwise specified in
+ the description of a particular function.</p>
+
+ <p>If a built-in function object is not implemented as an ECMAScript function it must have a [[Realm]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>. It must also have a [[Call]] internal method that
+ conforms to the following definition:</p>
+ </div>
+
+ <section id="sec-built-in-function-objects-call-thisargument-argumentslist">
+ <h1><span class="secnum" id="sec-9.3.1"><a href="#sec-built-in-function-objects-call-thisargument-argumentslist"
+ title="link to this section">9.3.1</a></span> [[Call]] ( thisArgument, argumentsList)</h1>
+
+ <p>The [[Call]] internal method for a built-in function object <var>F</var> is called with parameters
+ <var>thisArgument</var> and <var>argumentsList</var>, a <a href="#sec-list-and-record-specification-type">List</a> of <a
+ href="#sec-ecmascript-language-types">ECMAScript language values</a>. The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>callerContext</i> be <a href="#sec-execution-contexts">the running execution context</a>.</li>
+ <li>If <i>callerContext</i> is not already <a href="#sec-execution-contexts">suspended</a>, then <a
+ href="#sec-execution-contexts">Suspend</a> <i>callerContext</i>.</li>
+ <li>Let <i>calleeContext</i> be a new <a href="#sec-execution-contexts">execution context</a>.</li>
+ <li>Let <i>calleeRealm</i> be the value of <i>F’s</i> [[Realm]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Set <i>calleeContext’s</i> <a href="#sec-code-realms">Realm</a> to <i>calleeRealm</i>.</li>
+ <li>Perform any necessary implementation defined initialization of <i>calleeContext</i>.</li>
+ <li>Push <i>calleeContext</i> onto <a href="#sec-execution-contexts">the execution context stack</a>; <i>calleeContext</i>
+ is now <a href="#sec-execution-contexts">the running execution context</a>.</li>
+ <li>Let <i>result</i> be the <a href="#sec-completion-record-specification-type">Completion Record</a> that is the result
+ of evaluating <i>F</i> in an implementation defined manner that conforms to this specification of <i>F</i>.</li>
+ <li>Remove <i>calleeContext</i> from <a href="#sec-execution-contexts">the execution context stack</a> and restore
+ <i>callerContext</i> as <a href="#sec-execution-contexts">the running execution context</a>.</li>
+ <li>Return <i>result</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> When <i>calleeContext</i> is removed from <a href="#sec-execution-contexts">the
+ execution context stack</a> it must not be destroyed because it may have been <a
+ href="#sec-execution-contexts">suspended</a> and retained by a generator object for later resumption<i>.</i></p>
+ </div>
+ </section>
+
+ <section id="sec-createbuiltinfunction">
+ <h1><span class="secnum" id="sec-9.3.2"><a href="#sec-createbuiltinfunction" title="link to this section">9.3.2</a></span>
+ CreateBuiltinFunction(realm, steps, prototype, internalSlotsList) Abstract Operation</h1>
+
+ <p>The abstract operation CreateBuiltinFunction takes arguments <span style="font-family: Times New Roman"><i>realm</i>,
+ <i>prototype</i>,</span> and <var>steps</var>. The optional argument <var>internalSlotsList</var> is a <a
+ href="#sec-list-and-record-specification-type">List</a> of the names of additional <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> that must be defined as part of the object. If the
+ list is not provided, an empty <a href="#sec-list-and-record-specification-type">List</a> is used. CreateBuiltinFunction
+ returns a built-in function object created by the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>realm</i> is a <a href="#sec-code-realms">Realm</a> Record.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>steps</i> is either a set of algorithm steps or other definition
+ of a functions behaviour provided in this specification.</li>
+ <li>Let <i>func</i> be a new built-in function object that when called performs the action described by <i>steps</i>. The
+ new function object has internal slots whose names are the elements of <i>internalSlotsList</i>. The initial value of
+ each of those internal slots is <b>undefined<i>.</i></b></li>
+ <li>Set the [[Realm]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>func</i> to
+ <i>realm</i>.</li>
+ <li>Call the [[SetPrototypeOf]] internal method of <i>func</i> with argument <i>prototype</i>.</li>
+ <li>Perform the <a href="#sec-addrestrictedfunctionproperties">AddRestrictedFunctionProperties</a>(<i>func</i>,
+ <i>realm</i>).</li>
+ <li>Return <i>func</i>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-built-in-exotic-object-internal-methods-and-data-fields">
+ <div class="front">
+ <h1><span class="secnum" id="sec-9.4"><a href="#sec-built-in-exotic-object-internal-methods-and-data-fields"
+ title="link to this section">9.4</a></span> Built-in Exotic Object Internal Methods and Data Fields</h1>
+
+ <p>This specification defines several kinds of built-in exotic objects. These objects generally behave similar to ordinary
+ objects except for a few specific situations. The following exotic objects use the ordinary object internal methods except
+ where it is explicitly specified otherwise below:</p>
+ </div>
+
+ <section id="sec-bound-function-exotic-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-9.4.1"><a href="#sec-bound-function-exotic-objects"
+ title="link to this section">9.4.1</a></span> Bound Function Exotic Objects</h1>
+
+ <p>A <i>bound function</i> is an exotic object that wrappers another function object. A bound function is callable (it has
+ a [[Call]] internal method and may have a [[Construct]] internal method). Calling a bound function generally results in a
+ call of its wrapped function.</p>
+
+ <p>Bound function objects do not have the internal slots of ECMAScript function objects defined in <a
+ href="#table-26">Table 26</a>. Instead they have the internal slots defined in <a href="#table-27">Table 27</a>.</p>
+
+ <figure>
+ <figcaption><span id="table-27">Table 27</span> — Internal Slots of Exotic Bound Function Objects</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-top: 2px solid #000000">Internal Slot</th>
+ <th style="border-bottom: 1px solid #000000; border-top: 2px solid #000000">Type</th>
+ <th style="border-bottom: 1px solid #000000; border-right: 1px solid #000000; border-top: 2px solid #000000">Description</th>
+ </tr>
+ <tr>
+ <td>[[BoundTargetFunction]]</td>
+ <td>Callable Object</td>
+ <td>The wrappered function object.</td>
+ </tr>
+ <tr>
+ <td>[[BoundThis]]</td>
+ <td>Any</td>
+ <td>The value that is always passed as the <b>this</b> value when calling the wrappered function.</td>
+ </tr>
+ <tr>
+ <td>[[BoundArguments]]</td>
+ <td><a href="#sec-list-and-record-specification-type">List</a> of Any</td>
+ <td>A list of values that whose elements are used as the first arguments to any call to the wrappered function.</td>
+ </tr>
+ </table>
+ </figure>
+
+ <p>Unlike ECMAScript function objects, bound function objects do not use alternative definitions of the [[Get]] and
+ [[GetOwnProperty]] internal methods. Bound function objects provide all of the essential internal methods as specified in
+ <a href="#sec-ordinary-object-internal-methods-and-internal-slots">9.1</a>. However, they use the following definitions
+ for the essential internal methods of function objects.</p>
+ </div>
+
+ <section id="sec-call">
+ <h1><span class="secnum" id="sec-9.4.1.1"><a href="#sec-call" title="link to this section">9.4.1.1</a></span>
+ [[Call]]</h1>
+
+ <p>When the [[Call]] internal method of an exotic <a href="#sec-bound-function-exotic-objects">bound function</a> object,
+ <var>F</var>, which was created using the bind function is called with parameters <var>thisArgument</var> and
+ <var>argumentsList</var>, a <a href="#sec-list-and-record-specification-type">List</a> of <a
+ href="#sec-ecmascript-language-types">ECMAScript language values</a>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>boundArgs</i> be the value of <i>F’s</i> <a
+ href="#sec-bound-function-exotic-objects">[[BoundArguments]]</a> <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>boundThis</i> be the value of <i>F’s</i> <a href="#sec-bound-function-exotic-objects">[[BoundThis]]</a>
+ <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>target</i> be the value of <i>F’s</i> <a
+ href="#sec-bound-function-exotic-objects">[[BoundTargetFunction]]</a> <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>args</i> be a new list containing the same values as the list <i>boundArgs</i> in the same order followed by
+ the same values as the list <i>argumentsList</i> in the same order.</li>
+ <li>Return the result of calling the [[Call]] internal method of <i>target</i> providing <i>boundThis</i> as
+ <i>thisArgument</i> and providing <i>args</i> as <i>argumentsList</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-bound-function-exotic-objects-construct">
+ <h1><span class="secnum" id="sec-9.4.1.2"><a href="#sec-bound-function-exotic-objects-construct"
+ title="link to this section">9.4.1.2</a></span> [[Construct]]</h1>
+
+ <p>When the [[Construct]] internal method of an exotic <a href="#sec-bound-function-exotic-objects">bound function</a>
+ object, <var>F</var> that was created using the bind function is called with a list of arguments <span
+ class="nt">ExtraArgs</span>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>target</i> be the value of <i>F’s</i> <a
+ href="#sec-bound-function-exotic-objects">[[BoundTargetFunction]]</a> <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>target</i> has a [[Construct]] internal method.</li>
+ <li>Let <i>boundArgs</i> be the value of <i>F’s</i> <a
+ href="#sec-bound-function-exotic-objects">[[BoundArguments]]</a> <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>args</i> be a new list containing the same values as the list <i>boundArgs</i> in the same order followed by
+ the same values as the list <i>ExtraArgs</i> in the same order.</li>
+ <li>Return the result of calling the [[Construct]] internal method of <i>target</i> providing <i>args</i> as the
+ arguments.</li>
+ </ol>
+ </section>
+
+ <section id="sec-boundfunctioncreate">
+ <h1><span class="secnum" id="sec-9.4.1.3"><a href="#sec-boundfunctioncreate"
+ title="link to this section">9.4.1.3</a></span> BoundFunctionCreate (targetFunction, boundThis, boundArgs) Abstract
+ Operation</h1>
+
+ <p>The abstract operation BoundFunctionCreate with arguments <var>targetFunction</var>, <var>boundThis</var> and
+ <var>boundArgs</var> is used to specify the creation of new <a href="#sec-bound-function-exotic-objects">Bound
+ Function</a> exotic objects. It performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>proto</i> be the intrinsic <span style="font-family: sans-serif">%FunctionPrototype%</span>.</li>
+ <li>Let <i>obj</i> be a newly created object.</li>
+ <li>Set <i>obj</i>’s essential internal methods to the default ordinary object definitions specified in <a
+ href="#sec-ordinary-object-internal-methods-and-internal-slots">9.1</a>.</li>
+ <li>Set the [[Call]] internal method of <i>obj</i> as described in <a href="#sec-call">9.4.1.1</a>.</li>
+ <li>If <i>targetFunction</i> has a [[Construct]] internal method, then
+ <ol class="block">
+ <li>Set the [[Construct]] internal method of <i>obj</i> as described in <a
+ href="#sec-bound-function-exotic-objects-construct">9.4.1.2</a>.</li>
+ </ol>
+ </li>
+ <li>Set the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>obj</i> to
+ <i>proto</i>.</li>
+ <li>Set the [[Extensible]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>obj</i> to
+ <b>true</b>.</li>
+ <li>Set the <a href="#sec-bound-function-exotic-objects">[[BoundTargetFunction]]</a> <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>obj</i> to
+ <i>targetFunction</i>.</li>
+ <li>Set the <a href="#sec-bound-function-exotic-objects">[[BoundThis]]</a> <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>obj</i> to the value of
+ <i>boundThis</i>.</li>
+ <li>Set the <a href="#sec-bound-function-exotic-objects">[[BoundArguments]]</a> <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>obj</i> to <i>boundArgs</i>.</li>
+ <li>Return <i>obj</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-boundfunctionclone">
+ <h1><span class="secnum" id="sec-9.4.1.4"><a href="#sec-boundfunctionclone"
+ title="link to this section">9.4.1.4</a></span> BoundFunctionClone ( function ) Abstract Operation</h1>
+
+ <p>The abstract operation BoundFunctionClone is called with argujment <var>function</var> it performs the following
+ steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>function</i> is a <a
+ href="#sec-bound-function-exotic-objects">Bound Function</a> exotic object.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>newHome</i>) is Object.</li>
+ <li>Let <i>new</i> be a new <a href="#sec-bound-function-exotic-objects">Bound Function</a> exotic object that has all
+ of the same internal methods and internal slots as <i>function</i>.</li>
+ <li>Set the value of each of <i>new’s</i> internal slots, except for [[Extensible]] to the value of
+ <i>function’s</i> corresponding <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a>.</li>
+ <li>Set <i>new</i>’s [[Extensible]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to
+ <b>true</b>.</li>
+ <li>Let <i>realm</i> be <a href="#sec-boundfunctiontargetrealm">BoundFunctionTargetRealm</a>(<i>new</i>).</li>
+ <li>Let <i>status</i> be <a href="#sec-addrestrictedfunctionproperties">AddRestrictedFunctionProperties</a>(<i>new</i>,
+ <i>realm</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Return <i>new</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-boundfunctiontargetrealm">
+ <h1><span class="secnum" id="sec-9.4.1.5"><a href="#sec-boundfunctiontargetrealm"
+ title="link to this section">9.4.1.5</a></span> BoundFunctionTargetRealm ( bound ) Abstract Operation</h1>
+
+ <p>The abstract operation BoundFunctionTargetRealm with argument <var>bound</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>bound</i> is a <a
+ href="#sec-bound-function-exotic-objects">Bound Function</a> exotic object.</li>
+ <li>Let <i>target</i> be <i>bound</i>’s <a href="#sec-bound-function-exotic-objects">[[BoundTargetFunction]]</a>
+ <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>target</i> is a <a href="#sec-bound-function-exotic-objects">Bound Function</a> exotic object, then
+ <ol class="block">
+ <li>Return BoundFunctionTargetRealm(<i>target</i>).</li>
+ </ol>
+ </li>
+ <li>If <i>target</i> has a [[Realm]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, then
+ <ol class="block">
+ <li>Return <i>target</i>’s [[Realm]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a>.</li>
+ </ol>
+ </li>
+ <li>Return <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-code-realms">Realm</a>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Step 5 will only be reached if <i>target</i> is a non-standard exotic function object
+ that does not have a [[Realm]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-array-exotic-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-9.4.2"><a href="#sec-array-exotic-objects" title="link to this section">9.4.2</a></span>
+ Array Exotic Objects</h1>
+
+ <p>An <i>Array object</i> is an exotic object that gives special treatment to array index property keys (<a
+ href="#sec-object-type">see 6.1.7</a>). A property whose property name is an array index is also called an <i>element</i>.
+ Every Array object has a <code>length</code> property whose value is always a nonnegative integer less than <span
+ style="font-family: Times New Roman">2<sup>32</sup></span>. The value of the <code>length</code> property is numerically
+ greater than the name of every property whose name is an array index; whenever a property of an Array object is created or
+ changed, other properties are adjusted as necessary to maintain this invariant. Specifically, whenever a property is added
+ whose name is an array index, the <code>length</code> property is changed, if necessary, to be one more than the numeric
+ value of that array index; and whenever the <code>length</code> property is changed, every property whose name is an array
+ index whose value is not smaller than the new length is automatically deleted. This constraint applies only to own
+ properties of an Array object and is unaffected by <code>length</code> or array index properties that may be inherited
+ from its prototypes.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> A String property name <i>P</i> is an <i>array index</i> if and only if <a
+ href="#sec-tostring">ToString</a>(<a href="#sec-touint32">ToUint32</a>(<i>P</i>)) is equal to <i>P</i> and <a
+ href="#sec-touint32">ToUint32</a>(<i>P</i>) is not equal to 2<sup>32</sup>−1.</p>
+ </div>
+
+ <p>Exotic Array objects have the same internal slots as ordinary objects. They also have an [[ArrayInitializationState]]
+ internal slot.</p>
+
+ <p>Exotic Array objects always have a non-configurable property named <b>"<code>length</code>"</b>.</p>
+
+ <p>Exotic Array objects provide an alternative definition for the [[DefineOwnProperty]] internal method. Except for that
+ internal method, exotic Array objects provide all of the other essential internal methods as specified in <a
+ href="#sec-ordinary-object-internal-methods-and-internal-slots">9.1</a>.</p>
+ </div>
+
+ <section id="sec-array-exotic-objects-defineownproperty-p-desc">
+ <h1><span class="secnum" id="sec-9.4.2.1"><a href="#sec-array-exotic-objects-defineownproperty-p-desc"
+ title="link to this section">9.4.2.1</a></span> [[DefineOwnProperty]] ( P, Desc)</h1>
+
+ <p>When the [[DefineOwnProperty]] internal method of an exotic Array object <var>A</var> is called with <a
+ href="#sec-object-type">property key</a> <var>P</var>, and <a href="#sec-property-descriptor-specification-type">Property
+ Descriptor</a> <span class="nt">Desc</span> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ispropertykey">IsPropertyKey</a>(<i>P</i>) is
+ <b>true</b>.</li>
+ <li>If <i>P</i> is <code>"length"</code>, then
+ <ol class="block">
+ <li>Return <a href="#sec-arraysetlength">ArraySetLength</a>(<i>A</i>, <i>Desc</i>).</li>
+ </ol>
+ </li>
+ <li>Else if <i>P</i> is an array index, then
+ <ol class="block">
+ <li>Let <i>oldLenDesc</i> be <a href="#sec-ordinarygetownproperty">OrdinaryGetOwnProperty</a>(<i>A</i>,
+ <i>P</i>).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>oldLenDesc</i> will never be <b>undefined</b> or an accessor
+ descriptor because Array objects are created with a length data property that cannot be deleted or
+ reconfigured.</li>
+ <li>Let <i>oldLen</i> be <i>oldLenDesc</i>.[[Value]].</li>
+ <li>Let <i>index</i> be <a href="#sec-touint32">ToUint32</a>(<i>P</i>).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>index</i> will never be an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a>.</li>
+ <li>If <i>index</i> ≥ <i>oldLen</i> and <i>oldLenDesc</i>.[[Writable]] is <b>false</b>, then return
+ <b>false</b>.</li>
+ <li>Let <i>succeeded</i> be the result of calling <a
+ href="#sec-ordinarydefineownproperty">OrdinaryDefineOwnProperty</a> passing <i>A</i>, <i>P</i>, and <i>Desc</i>
+ as arguments.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>succeeded</i>).</li>
+ <li>If <i>succeeded</i> is <b>false</b>, then return <b>false</b>.</li>
+ <li>If <i>index</i> ≥ <i>oldLen</i>
+ <ol class="block">
+ <li>Set <i>oldLenDesc</i>.[[Value]] to <i>index</i> + 1.</li>
+ <li>Let <i>succeeded</i> be <a href="#sec-ordinarydefineownproperty">OrdinaryDefineOwnProperty</a>(<i>A</i>,
+ <b>"<code>length</code>"</b>, <i>oldLenDesc</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>succeeded</i>).</li>
+ </ol>
+ </li>
+ <li>Return <b>true</b>.</li>
+ </ol>
+ </li>
+ <li>Return <a href="#sec-ordinarydefineownproperty">OrdinaryDefineOwnProperty</a>(<i>A</i>, <i>P</i>, <i>Desc</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-arraycreate">
+ <h1><span class="secnum" id="sec-9.4.2.2"><a href="#sec-arraycreate" title="link to this section">9.4.2.2</a></span>
+ ArrayCreate(length, proto) Abstract Operation</h1>
+
+ <p>The abstract operation ArrayCreate with argument <var>length</var> (a positive integer or <span
+ class="value">undefined</span>) and optional argument <var>proto</var> is used to specify the creation of new exotic Array
+ objects. It performs the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>length</i> is either <b>undefined</b> or a integer Number ≥
+ 0.</li>
+ <li>If <i>length</i> is −0, then let <i>length</i> be +0.</li>
+ <li>If the <i>proto</i> argument was not passed, then let <i>proto</i> be the intrinsic object <span style="font-family:
+ sans-serif">%ArrayPrototype%</span>.</li>
+ <li>Let <i>A</i> be a newly created <a href="#sec-array-exotic-objects">Array exotic object</a>.</li>
+ <li>Set <i>A</i>’s essential internal methods except for [[DefineOwnProperty]] to the default ordinary object
+ definitions specified in <a href="#sec-ordinary-object-internal-methods-and-internal-slots">9.1</a>.</li>
+ <li>Set the [[DefineOwnProperty]] internal method of <i>A</i> as specified in <a
+ href="#sec-array-exotic-objects-defineownproperty-p-desc">9.4.2.1</a>.</li>
+ <li>Set the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>A</i> to
+ <i>proto</i>.</li>
+ <li>Set the [[Extensible]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>A</i> to
+ <b>true</b>.</li>
+ <li>If <i>length</i> is not <b>undefined</b>, then
+ <ol class="block">
+ <li>Set the [[ArrayInitializationState]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>
+ of <i>A</i> to <b>true</b>.</li>
+ </ol>
+ </li>
+ <li>Else
+ <ol class="block">
+ <li>Set the [[ArrayInitializationState]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>
+ of <i>A</i> to <b>false</b>.</li>
+ <li>Let <i>length</i> be +0.</li>
+ </ol>
+ </li>
+ <li>If <i>length</i>>2<sup>32</sup>-1, then throw a <b>RangeError</b> exception.</li>
+ <li>Call <a href="#sec-ordinarydefineownproperty">OrdinaryDefineOwnProperty</a> with arguments <i>A</i>,
+ <code>"length"</code> and PropertyDescriptor{[[Value]]: <i>length</i>, [[Writable]]: <b>true</b>, [[Enumerable]]:
+ <b>false</b>, [[Configurable]]: <b>false</b>}.</li>
+ <li>Return <i>A</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-arraysetlength">
+ <h1><span class="secnum" id="sec-9.4.2.3"><a href="#sec-arraysetlength" title="link to this section">9.4.2.3</a></span>
+ ArraySetLength(A, Desc) Abstract Operation</h1>
+
+ <p>When the abstract operation ArraySetLength is called with an exotic Array object <span style="font-family: Times New
+ Roman"><i>A</i>,</span> and <a href="#sec-property-descriptor-specification-type">Property Descriptor</a> <span
+ class="nt">Desc</span> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>If the [[Value]] field of <i>Desc</i> is absent, then
+ <ol class="block">
+ <li>Return <a href="#sec-ordinarydefineownproperty">OrdinaryDefineOwnProperty</a>(<i>A</i>,
+ <b>"<code>length</code>"</b>, <i>Desc</i>).</li>
+ </ol>
+ </li>
+ <li>Let <i>newLenDesc</i> be a copy of <i>Desc</i>.</li>
+ <li>Let <i>newLen</i> be <a href="#sec-touint32">ToUint32</a>(<i>Desc</i>.[[Value]]).</li>
+ <li>If <i>newLen</i> is not equal to <a href="#sec-tonumber">ToNumber</a>( <i>Desc</i>.[[Value]]), throw a
+ <b>RangeError</b> exception.</li>
+ <li>Set <i>newLenDesc</i>.[[Value]] to <i>newLen</i>.</li>
+ <li>Let <i>oldLenDesc</i> be the result of calling the [[GetOwnProperty]] internal method of <i>A</i> passing
+ <b>"<code>length</code>"</b> as the argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>oldLenDesc</i>).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>oldLenDesc</i> will never be <b>undefined</b> or an accessor
+ descriptor because Array objects are created with a length data property that cannot be deleted or
+ reconfigured.</li>
+ <li>Let <i>oldLen</i> be <i>oldLenDesc</i>.[[Value]].</li>
+ <li>If <i>newLen</i> ≥<i>oldLen</i>, then
+ <ol class="block">
+ <li>Return <a href="#sec-ordinarydefineownproperty">OrdinaryDefineOwnProperty</a>(<i>A</i>,
+ <b>"<code>length</code>"</b>, <i>newLenDesc</i>).</li>
+ </ol>
+ </li>
+ <li>If <i>oldLenDesc</i>.[[Writable]] is <b>false</b>, then return <b>false</b>.</li>
+ <li>If <i>newLenDesc</i>.[[Writable]] is absent or has the value <b>true</b>, let <i>newWritable</i> be
+ <b>true</b>.</li>
+ <li>Else,
+ <ol class="block">
+ <li>Need to defer setting the [[Writable]] attribute to <b>false</b> in case any elements cannot be deleted.</li>
+ <li>Let <i>newWritable</i> be <b>false</b>.</li>
+ <li>Set <i>newLenDesc</i>.[[Writable]] to <b>true</b>.</li>
+ </ol>
+ </li>
+ <li>Let <i>succeeded</i> be <a href="#sec-ordinarydefineownproperty">OrdinaryDefineOwnProperty</a>(<i>A</i>,
+ <b>"<code>length</code>"</b>, <i>newLenDesc</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>succeeded</i>).</li>
+ <li>If <i>succeeded</i> is <b>false</b>, return <b>false</b>.</li>
+ <li>While <i>newLen</i> < <i>oldLen</i> repeat,
+ <ol class="block">
+ <li>Set <i>oldLen</i> to <i>oldLen</i> – 1.</li>
+ <li>Let <i>deleteSucceeded</i> be the result of calling the [[Delete]] internal method of <i>A</i> passing <a
+ href="#sec-tostring">ToString</a>(<i>oldLen</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>succeeded</i>).</li>
+ <li>If <i>deleteSucceeded</i> is <b>false</b>, then
+ <ol class="block">
+ <li>Set <i>newLenDesc</i>.[[Value]] to <i>oldLen+1</i>.</li>
+ <li>If <i>newWritable</i> is <b>false</b>, set <i>newLenDesc</i>.[[Writable]] to <b>false</b>.</li>
+ <li>Let <i>succeeded</i> be <a href="#sec-ordinarydefineownproperty">OrdinaryDefineOwnProperty</a>(<i>A</i>,
+ <b>"<code>length</code>"</b>, <i>newLenDesc</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>succeeded</i>).</li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>If <i>newWritable</i> is <b>false</b>, then
+ <ol class="block">
+ <li>Call <a href="#sec-ordinarydefineownproperty">OrdinaryDefineOwnProperty</a> passing <i>A</i>,
+ <b>"<code>length</code>"</b>, and PropertyDescriptor{[[Writable]]: <b>false</b>} as arguments. This call will
+ always return <b>true</b>.</li>
+ </ol>
+ </li>
+ <li>Return <b>true</b>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> In steps 3 and 4, if <i>Desc</i>.[[Value]] is an object then its <code>valueOf</code>
+ method is called twice. This is legacy behaviour that was specified with this effect starting with the 2<sup>nd</sup>
+ Edition of this specification.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-string-exotic-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-9.4.3"><a href="#sec-string-exotic-objects" title="link to this section">9.4.3</a></span>
+ String Exotic Objects</h1>
+
+ <p>A <i>String object</i> is an exotic object that encapsulates a String value and exposes virtual integer indexed data
+ properties corresponding to the individual code unit elements of the string value. Exotic String objects always have a
+ data property named <b>"<code>length</code>"</b> whose value is the number of code unit elements in the encapsulated
+ String value. Both the code unit data properties and the <b>"<code>length</code>"</b> property are non-writable and
+ non-configurable.</p>
+
+ <p>Exotic String objects have the same internal slots as ordinary objects. They also have a [[StringData]] internal
+ slot.</p>
+
+ <p>Exotic String objects provide alternative definitions for the following internal methods. All of the other exotic
+ String object essential internal methods that are not defined below are as specified in <a
+ href="#sec-ordinary-object-internal-methods-and-internal-slots">9.1</a>.</p>
+ </div>
+
+ <section id="sec-string-exotic-objects-getownproperty-p">
+ <h1><span class="secnum" id="sec-9.4.3.1"><a href="#sec-string-exotic-objects-getownproperty-p"
+ title="link to this section">9.4.3.1</a></span> [[GetOwnProperty]] ( P )</h1>
+
+ <p>When the [[GetOwnProperty]] internal method of an exotic String object <var>S</var> is called with <a
+ href="#sec-object-type">property key</a> <var>P</var> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ispropertykey">IsPropertyKey</a>(<i>P</i>) is
+ <b>true</b>.</li>
+ <li>Let <i>desc</i> be <a href="#sec-ordinarygetownproperty">OrdinaryGetOwnProperty</a>(<i>S</i>, <i>P</i>).</li>
+ <li>If <i>desc</i> is not <b>undefined</b> return <i>desc</i>.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>P</i>) is not String, then return
+ <b>undefined</b>.</li>
+ <li>Let <i>index</i> be <a href="#sec-canonicalnumericindexstring">CanonicalNumericIndexString</a> (<i>P</i>).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>index</i> is not an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a>.</li>
+ <li>If <i>index</i> is <b>undefined</b>, then return <b>undefined</b>.</li>
+ <li>If <a href="#sec-isinteger">IsInteger</a>(<i>index</i>) is <b>false</b>, then return <b>undefined</b>.</li>
+ <li>If <i>index</i> = −0, then return <b>undefined</b>.</li>
+ <li>Let <i>str</i> be the String value of the [[StringData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>S</i>, if the value of [[StringData]]
+ is <b>undefined</b> the empty string is used as its value.</li>
+ <li>Let <i>len</i> be the number of elements in <i>str</i>.</li>
+ <li>If <i>index</i> < 0 or <i>len</i> ≤ <i>index</i>, return <b>undefined</b>.</li>
+ <li>Let <i>resultStr</i> be a String value of length 1, containing one code unit from <i>str</i>, specifically the code
+ unit at position <i>index</i>, where the first (leftmost) element in <i>str</i> is considered to be at position 0,
+ the next one at position 1, and so on.</li>
+ <li>Return a PropertyDescriptor{ [[Value]]: <i>resultStr</i>, [[Enumerable]]: <b>true</b>, [[Writable]]: <b>false</b>,
+ [[Configurable]]: <b>false</b> }.</li>
+ </ol>
+ </section>
+
+ <section id="sec-string-exotic-objects-enumerate">
+ <h1><span class="secnum" id="sec-9.4.3.2"><a href="#sec-string-exotic-objects-enumerate"
+ title="link to this section">9.4.3.2</a></span> [[Enumerate]] ()</h1>
+
+ <p>When the [[Enumerate]] internal method of an exotic String object <var>O</var> is called the following steps are
+ taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>indexKeys</i> be a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Let <i>str</i> be the String value of the [[StringData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>, if the value of [[StringData]]
+ is <b>undefined</b> the empty string is used as its value.</li>
+ <li>Let <i>len</i> be the number of elements in <i>str</i>.</li>
+ <li>For each integer <i>i</i> starting with 0 such that <i>i</i> < <i>len</i>, in ascending order,
+ <ol class="block">
+ <li>Add <a href="#sec-tostring">ToString</a>(<i>i</i>) as the last element of <i>indexKeys</i></li>
+ </ol>
+ </li>
+ <li>Let <i>ordinary</i> be the result of calling the default ordinary object [[Enumerate]] internal method (<a
+ href="#sec-ordinary-object-internal-methods-and-internal-slots-enumerate">9.1.11</a>) on <i>O</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>ordinary</i>).</li>
+ <li>Return <a href="#sec-createcompounditerator">CreateCompoundIterator</a>(<a
+ href="#sec-createlistiterator">CreateListIterator</a>(<i>indexKeys</i>), <i>ordinary</i>)<i>.</i></li>
+ </ol>
+ </section>
+
+ <section id="sec-string-exotic-objects-ownpropertykeys">
+ <h1><span class="secnum" id="sec-9.4.3.3"><a href="#sec-string-exotic-objects-ownpropertykeys"
+ title="link to this section">9.4.3.3</a></span> [[OwnPropertyKeys]] ( )</h1>
+
+ <p>When the [[OwnPropertyKeys]] internal method of a <a href="#sec-string-exotic-objects">String exotic object</a>
+ <var>O</var> is called the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>keys</i> be a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Let <i>str</i> be the String value of the [[StringData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>, if the value of [[StringData]]
+ is <b>undefined</b> the empty string is used as its value.</li>
+ <li>Let <i>len</i> be the number of elements in <i>str</i>.</li>
+ <li>For each integer <i>i</i> starting with 0 such that <i>i</i> < <i>len</i>. in ascending order,
+ <ol class="block">
+ <li>Add <a href="#sec-tostring">ToString</a>(<i>i</i>) as the last element of <i>keys</i></li>
+ </ol>
+ </li>
+ <li>For each own <a href="#sec-object-type">property key</a> <i>P</i> of <i>O</i> such that <i>P</i> is an integer index
+ and <a href="#sec-tointeger">ToInteger</a>(<i>P</i>) ≥ <i>len</i>, in ascending numeric index order,
+ <ol class="block">
+ <li>Add <i>P</i> as the last element of <i>keys</i>.</li>
+ </ol>
+ </li>
+ <li>For each own <a href="#sec-object-type">property key</a> <i>P</i> of <i>O</i> such that <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>P</i>) is String and <i>P</i> is not an integer index, in
+ property creation order,
+ <ol class="block">
+ <li>Add <i>P</i> as the last element of <i>keys</i>.</li>
+ </ol>
+ </li>
+ <li>For each own <a href="#sec-object-type">property key</a> <i>P</i> of <i>O</i> such that <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>P</i>) is Symbol, in property creation order,
+ <ol class="block">
+ <li>Add <i>P</i> as the last element of <i>keys</i>.</li>
+ </ol>
+ </li>
+ <li>Return <a href="#sec-createarrayfromlist">CreateArrayFromList</a>(<i>keys</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-stringcreate">
+ <h1><span class="secnum" id="sec-9.4.3.4"><a href="#sec-stringcreate" title="link to this section">9.4.3.4</a></span>
+ StringCreate Abstract Operation</h1>
+
+ <p>The abstract operation StringCreate with argument <var>prototype</var> is used to specify the creation of new exotic
+ String objects. It performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>A</i> be a newly created <a href="#sec-string-exotic-objects">String exotic object</a>.</li>
+ <li>Set <i>A</i>’s essential internal methods to the default ordinary object definitions specified in <a
+ href="#sec-ordinary-object-internal-methods-and-internal-slots">9.1</a>.</li>
+ <li>Set the [[GetOwnProperty]] internal method of <i>A</i> as specified in <a
+ href="#sec-string-exotic-objects-getownproperty-p">9.4.3.1</a>.</li>
+ <li>Set the [[Enumerate]] internal method of <i>A</i> as specified in <a
+ href="#sec-string-exotic-objects-enumerate">9.4.3.2</a>.</li>
+ <li>Set the [[OwnPropertyKeys]] internal method of <i>A</i> as specified in <a
+ href="#sec-string-exotic-objects-ownpropertykeys">9.4.3.3</a>.</li>
+ <li>Set the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>A</i> to
+ <i>prototype</i>.</li>
+ <li>Set the [[Extensible]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>A</i> to
+ <b>true</b>.</li>
+ <li>Return <i>A</i>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-arguments-exotic-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-9.4.4"><a href="#sec-arguments-exotic-objects"
+ title="link to this section">9.4.4</a></span> Arguments Exotic Objects</h1>
+
+ <p>Most ECMAScript functions make an arguments objects available to their code. Depending upon the characteristics of the
+ function definition, its argument object is either an ordinary object or an <i>arguments exotic object</i>. An aguments
+ exotic object is an exotic object whose array index properties map to the formal parameters bindings of an invocation of
+ its associated ECMAScript function.</p>
+
+ <p>Arguments exotic objects have the same internal slots as ordinary objects. They also have a [[ParameterMap]] internal
+ slot. Ordanary arguments objects also have a [[ParameterMap]] internal slot whose value is always undefined. For ordany
+ argument objects the [[ParameterMap]] internal slot is only used by <code><a
+ href="#sec-object.prototype.tostring">Object.prototype.toString</a></code> (<a
+ href="#sec-object.prototype.tostring">19.1.3.6</a>) to identify them as such.</p>
+
+ <p>Arguments exotic objects provide alternative definitions for the following internal methods. All of the other exotic
+ arguments object essential internal methods that are not defined below are as specified in <a
+ href="#sec-ordinary-object-internal-methods-and-internal-slots">9.1</a></p>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> For non-strict mode functions the integer indexed data properties of an arguments
+ object whose numeric name values are less than the number of formal parameters of the corresponding function object
+ initially share their values with the corresponding argument bindings in the function’s <a
+ href="#sec-execution-contexts">execution context</a>. This means that changing the property changes the corresponding
+ value of the argument binding and vice-versa. This correspondence is broken if such a property is deleted and then
+ redefined or if the property is changed into an accessor property. For strict mode functions, the values of the
+ arguments object’s properties are simply a copy of the arguments passed to the function and there is no dynamic
+ linkage between the property values and the formal parameter values.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 2</span> The ParameterMap object and its property values are used as a device for specifying
+ the arguments object correspondence to argument bindings. The ParameterMap object and the objects that are the values of
+ its properties are not directly observable from ECMAScript code. An ECMAScript implementation does not need to actually
+ create or use such objects to implement the specified semantics.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 3</span> Arguments objects for strict mode functions define non-configurable accessor
+ properties named "<code>caller</code>" and "<code>callee</code>" which throw a <b>TypeError</b> exception on access. The
+ "<code>callee</code>" property has a more specific meaning for non-strict mode functions and a "<code>caller</code>"
+ property has historically been provided as an implementation-defined extension by some ECMAScript implementations. The
+ strict mode definition of these properties exists to ensure that neither of them is defined in any other manner by
+ conforming ECMAScript implementations.</p>
+ </div>
+ </div>
+
+ <section id="sec-arguments-exotic-objects-getownproperty-p">
+ <h1><span class="secnum" id="sec-9.4.4.1"><a href="#sec-arguments-exotic-objects-getownproperty-p"
+ title="link to this section">9.4.4.1</a></span> [[GetOwnProperty]] (P)</h1>
+
+ <p>The [[GetOwnProperty]] internal method of an arguments exotic object when called with a property name <var>P</var>
+ performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>args</i> be the arguments object.</li>
+ <li>Let <i>desc</i> be <a href="#sec-ordinarygetownproperty">OrdinaryGetOwnProperty</a>(<i>args</i>, <i>P</i>).</li>
+ <li>If <i>desc</i> is <b>undefined</b> then return <i>desc</i>.</li>
+ <li>Let <i>map</i> be the value of the [[ParameterMap]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the arguments object.</li>
+ <li>Let <i>isMapped</i> be the result of calling the [[GetOwnProperty]] internal method of <i>map</i> passing <i>P</i>
+ as the argument.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>isMapped</i> is never an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a>.</li>
+ <li>If the value of <i>isMapped</i> is not <b>undefined</b>, then
+ <ol class="block">
+ <li>Set <i>desc</i>.[[Value]] to <a href="#sec-get-o-p">Get</a>(<i>map</i>, <i>P</i>).</li>
+ </ol>
+ </li>
+ <li>If <a href="#sec-isdatadescriptor">IsDataDescriptor</a>(<i>desc</i>) is <b>true</b> and <i>P</i> is
+ <code>"caller"</code> and <i>desc</i>.[[Value]] is a strict mode Function object, throw a <b>TypeError</b>
+ exception.</li>
+ <li>Return <i>desc</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-arguments-exotic-objects-defineownproperty-p-desc">
+ <h1><span class="secnum" id="sec-9.4.4.2"><a href="#sec-arguments-exotic-objects-defineownproperty-p-desc"
+ title="link to this section">9.4.4.2</a></span> [[DefineOwnProperty]] (P, Desc)</h1>
+
+ <p>The [[DefineOwnProperty]] internal method of an arguments exotic object when called with a property name <var>P</var>
+ and <a href="#sec-property-descriptor-specification-type">Property Descriptor</a> <span class="nt">Desc</span> performs
+ the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>args</i> be the arguments object.</li>
+ <li>Let <i>map</i> be the value of the [[ParameterMap]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the arguments object.</li>
+ <li>Let <i>isMapped</i> be <a href="#sec-hasownproperty">HasOwnProperty</a>(<i>map</i>, <i>P</i>).</li>
+ <li>Let <i>allowed</i> be <a href="#sec-ordinarydefineownproperty">OrdinaryDefineOwnProperty</a>(<i>args</i>, <i>P</i>,
+ <i>Desc</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>allowed</i>).</li>
+ <li>If <i>allowed</i> is <b>false</b>, then return <b>false</b>.</li>
+ <li>If the value of <i>isMapped</i> is not <b>undefined</b>, then
+ <ol class="block">
+ <li>If <a href="#sec-isaccessordescriptor">IsAccessorDescriptor</a>(<i>Desc</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>Call the [[Delete]] internal method of <i>map</i> passing <i>P</i> as the argument.</li>
+ </ol>
+ </li>
+ <li>Else
+ <ol class="block">
+ <li>If <i>Desc</i>.[[Value]] is present, then
+ <ol class="block">
+ <li>Let <i>putStatus</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>map</i>, <i>P</i>,
+ <i>Desc</i>.[[Value]], <b>false</b>).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>putStatus</i> is <b>true</b> because formal
+ parameters mapped by argument objects are always writable.</li>
+ </ol>
+ </li>
+ <li>If <i>Desc</i>.[[Writable]] is present and its value is <b>false</b>, then
+ <ol class="block">
+ <li>Call the [[Delete]] internal method of <i>map</i> passing <i>P</i> as the argument.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Return <b>true</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-arguments-exotic-objects-get-p-receiver">
+ <h1><span class="secnum" id="sec-9.4.4.3"><a href="#sec-arguments-exotic-objects-get-p-receiver"
+ title="link to this section">9.4.4.3</a></span> [[Get]] (P, Receiver)</h1>
+
+ <p>The [[Get]] internal method of an arguments exotic object when called with a property name <var>P</var> and <a
+ href="#sec-ecmascript-language-types">ECMAScript language value</a> <span class="nt">Receiver</span> performs the
+ following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>args</i> be the arguments object.</li>
+ <li>Let <i>map</i> be the value of the [[ParameterMap]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the arguments object.</li>
+ <li>Let <i>isMapped</i> be <a href="#sec-hasownproperty">HasOwnProperty</a>(<i>map</i>, <i>P</i>).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>isMapped</i> is not an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a>.</li>
+ <li>If the value of <i>isMapped</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>v</i> be the result of calling the default ordinary object [[Get]] internal method (<a
+ href="#sec-ordinary-object-internal-methods-and-internal-slots-get-p-receiver">9.1.8</a>) on <i>args</i> passing
+ <i>P</i> and <i>Receiver</i> as the arguments.</li>
+ </ol>
+ </li>
+ <li>Else <i>map</i> contains a formal parameter mapping for <i>P</i>,
+ <ol class="block">
+ <li>Let <i>v</i> be <a href="#sec-get-o-p">Get</a>(<i>map</i>, <i>P</i>).</li>
+ </ol>
+ </li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>v</i>).</li>
+ <li>If <i>P</i> is <code>"caller"</code> and <i>v</i> is a strict mode Function object, throw a <b>TypeError</b>
+ exception.</li>
+ <li>Return <i>v</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-arguments-exotic-objects-set-p-v-receiver">
+ <h1><span class="secnum" id="sec-9.4.4.4"><a href="#sec-arguments-exotic-objects-set-p-v-receiver"
+ title="link to this section">9.4.4.4</a></span> [[Set]] ( P, V, Receiver)</h1>
+
+ <p>The [[Set]] internal method of an arguments exotic object when called with <a href="#sec-object-type">property key</a>
+ <var>P</var>, value <var>V</var>, and <a href="#sec-ecmascript-language-types">ECMAScript language value</a> <span
+ class="nt">Receiver</span> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>args</i> be the arguments object.</li>
+ <li>If <a href="#sec-samevalue">SameValue</a>(<i>args</i>, <i>Receiver</i>) is <b>false</b>, then
+ <ol class="block">
+ <li>Let <i>isMapped</i> be <b>undefined</b>.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>map</i> be the value of the [[ParameterMap]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the arguments object.</li>
+ <li>Let <i>isMapped</i> be <a href="#sec-hasownproperty">HasOwnProperty</a>(<i>map</i>, <i>P</i>).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>isMapped</i> is not an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a>.</li>
+ </ol>
+ </li>
+ <li>If the value of <i>isMapped</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>Return the result of calling the default ordinary object [[Set]] internal method (<a
+ href="#sec-ordinary-object-internal-methods-and-internal-slots-get-p-receiver">9.1.8</a>) on <i>args</i> passing
+ <i>P</i>, <i>V</i> and <i>Receiver</i> as the arguments.</li>
+ </ol>
+ </li>
+ <li>Else <i>map</i> contains a formal parameter mapping for <i>P</i>,
+ <ol class="block">
+ <li>Return <a href="#sec-put-o-p-v-throw">Put</a>(<i>map</i>, <i>P</i>, <i>V</i>, <b>false</b>).</li>
+ </ol>
+ </li>
+ </ol>
+ </section>
+
+ <section id="sec-arguments-exotic-objects-delete-p">
+ <h1><span class="secnum" id="sec-9.4.4.5"><a href="#sec-arguments-exotic-objects-delete-p"
+ title="link to this section">9.4.4.5</a></span> [[Delete]] (P)</h1>
+
+ <p>The [[Delete]] internal method of an arguments exotic object when called with a <a href="#sec-object-type">property
+ key</a> <var>P</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>map</i> be the value of the [[ParameterMap]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the arguments object.</li>
+ <li>Let <i>isMapped</i> be <a href="#sec-hasownproperty">HasOwnProperty</a>(<i>map</i>, <i>P</i>).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>isMapped</i> is not an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a>.</li>
+ <li>Let <i>result</i> be the result of calling the default [[Delete]] internal method for ordinary objects (<a
+ href="#sec-ordinary-object-internal-methods-and-internal-slots-delete-p">9.1.10</a>) on the arguments object passing
+ <i>P</i> as the argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>result</i>).</li>
+ <li>If <i>result</i> is <b>true</b> and the value of <i>isMapped</i> is not <b>undefined</b>, then
+ <ol class="block">
+ <li>Call the [[Delete]] internal method of <i>map</i> passing <i>P</i> as the argument.</li>
+ </ol>
+ </li>
+ <li>Return <i>result</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> For non-strict mode functions with simple parameter lists, those integer indexed data
+ properties of an arguments object whose numeric name values are less than the number of formal parameters of the
+ function initially share their values with the corresponding argument bindings in the function’s <a
+ href="#sec-execution-contexts">execution context</a>. This means that changing the property changes the corresponding
+ value of the argument binding and vice-versa. This correspondence is broken if such a property is deleted and then
+ redefined or if the property is changed into an accessor property. For strict mode functions, the values of the
+ arguments object’s properties are simply a copy of the arguments passed to the function and there is no dynamic
+ linkage between the property values and the formal parameter values.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 2</span> The ParameterMap object and its property values are used as a device for specifying
+ the arguments object correspondence to argument bindings. The ParameterMap object and the objects that are the values of
+ its properties are not directly accessible from ECMAScript code. An ECMAScript implementation does not need to actually
+ create or use such objects to implement the specified semantics.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 3</span> Arguments objects for strict mode functions define non-configurable accessor
+ properties named "<code>caller</code>" and "<code>callee</code>" which throw a <b>TypeError</b> exception on access. The
+ "<code>callee</code>" property has a more specific meaning for non-strict mode functions and a "<code>caller</code>"
+ property has historically been provided as an implementation-defined extension by some ECMAScript implementations. The
+ strict mode definition of these properties exists to ensure that neither of them is defined in any other manner by
+ conforming ECMAScript implementations.</p>
+ </div>
+ </section>
+
+ <section id="sec-createunmappedargumentsobject">
+ <h1><span class="secnum" id="sec-9.4.4.6"><a href="#sec-createunmappedargumentsobject"
+ title="link to this section">9.4.4.6</a></span> CreateUnmappedArgumentsObject(argumentsList) Abstract Operation</h1>
+
+ <p>The abstract operation <span style="font-family: Times New Roman">CreateUnmappedArgumentsObject</span> called with an
+ argument <var>argumentsList</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>len</i> be the number of elements in <i>argumentsList</i>.</li>
+ <li>Let <i>obj</i> be <a href="#sec-objectcreate">ObjectCreate</a>(%ObjectPrototype%, ([[ParameterMap]])).</li>
+ <li>Set <i>obj</i>’s [[ParameterMap]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>
+ to <b>undefined</b>.</li>
+ <li>Perform <a href="#sec-definepropertyorthrow">DefinePropertyOrThrow</a>(<i>obj</i>, <b>"<code>length</code>"</b>,
+ PropertyDescriptor{[[Value]]: <i>len</i>, [[Writable]]: <b>true</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>true</b>}).</li>
+ <li>Let <i>index</i> be 0.</li>
+ <li>Repeat while <i>index</i> < <i>len</i>,
+ <ol class="block">
+ <li>Let <i>val</i> be the element of <i>argumentsList</i> at 0-origined list position <i>index</i>.</li>
+ <li>Perform <a href="#sec-createdataproperty">CreateDataProperty</a>(<i>obj</i>, <a
+ href="#sec-tostring">ToString</a>(<i>index</i>), <i>val</i>).</li>
+ <li>Let <i>index</i> be <i>index</i> + 1</li>
+ </ol>
+ </li>
+ <li>Perform <a href="#sec-definepropertyorthrow">DefinePropertyOrThrow</a>(<i>obj</i>, @@iterator, PropertyDescriptor
+ {[[Value]]:%ArrayProto_values%, [[Writable]]: <b>true</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>true</b>}).</li>
+ <li>Perform <a href="#sec-definepropertyorthrow">DefinePropertyOrThrow</a>(<i>obj</i>, <code>"caller"</code>,
+ PropertyDescriptor {[[Get]]: <a href="#sec-%throwtypeerror%">%ThrowTypeError%</a>, [[Set]]: <a
+ href="#sec-%throwtypeerror%">%ThrowTypeError%</a>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b>}).</li>
+ <li>Perform <a href="#sec-definepropertyorthrow">DefinePropertyOrThrow</a>(<i>obj</i>, <code>"callee"</code>,
+ PropertyDescriptor {[[Get]]: <a href="#sec-%throwtypeerror%">%ThrowTypeError%</a>, [[Set]]: <a
+ href="#sec-%throwtypeerror%">%ThrowTypeError%</a>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b>}).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: the above property definitions will not produce an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a>.</li>
+ <li>Return <i>obj</i></li>
+ </ol>
+ </section>
+
+ <section id="sec-createmappedargumentsobject">
+ <div class="front">
+ <h1><span class="secnum" id="sec-9.4.4.7"><a href="#sec-createmappedargumentsobject"
+ title="link to this section">9.4.4.7</a></span> CreateMappedArgumentsObject ( func, formals, argumentsList, env )
+ Abstract Operation</h1>
+
+ <p>The abstract operation <span style="font-family: Times New Roman">CreateMappedArgumentsObject</span> is called with
+ object <var>func</var>, grammar production <var>formals</var>, <a
+ href="#sec-list-and-record-specification-type">List</a> <var>argumentsList</var>, and environment record <span
+ style="font-family: Times New Roman"><i>env</i>.</span> The following steps are performed:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>formals</i> does not contain a rest parameter, any binding
+ patterns, or any initializers. It may contain duplicate identifiers.</li>
+ <li>Let <i>len</i> be the number of elements in <i>argumentsList</i>.</li>
+ <li>Let <i>obj</i> be a newly created arguments exotic object with a [[ParameterMap]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Set the [[GetOwnProperty]] internal method of <i>obj</i> as specified in <a
+ href="#sec-arguments-exotic-objects-getownproperty-p">9.4.4.1</a>.</li>
+ <li>Set the [[DefineOwnProperty]] internal method of <i>obj</i> as specified in <a
+ href="#sec-arguments-exotic-objects-defineownproperty-p-desc">9.4.4.2</a>.</li>
+ <li>Set the [[Get]] internal method of <i>obj</i> as specified in <a
+ href="#sec-arguments-exotic-objects-get-p-receiver">9.4.4.3</a>.</li>
+ <li>Set the [[Set]] internal method of <i>obj</i> as specified in <a
+ href="#sec-arguments-exotic-objects-set-p-v-receiver">9.4.4.4</a>.</li>
+ <li>Set the [[Delete]] internal method of <i>obj</i> as specified in <a
+ href="#sec-arguments-exotic-objects-delete-p">9.4.4.5</a>.</li>
+ <li>Set the remainder of <i>obj</i>’s essential internal methods to the default ordinary object definitions
+ specified in <a href="#sec-ordinary-object-internal-methods-and-internal-slots">9.1</a>.</li>
+ <li>Set the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>obj</i> to
+ %ObjectPrototype%.</li>
+ <li>Set the [[Extensible]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>obj</i>
+ to <b>true</b>.</li>
+ <li>Let <i>parameterNames</i> be the BoundNames of <i>formals</i>.</li>
+ <li>Let <i>numberOfParameters</i> be the number of elements in <i>parameterNames</i></li>
+ <li>Let <i>index</i> be 0.</li>
+ <li>Repeat while <i>index</i> < <i>len</i> ,
+ <ol class="block">
+ <li>Let <i>val</i> be the element of <i>argumentsList</i> at 0-origined list position <i>index</i>.</li>
+ <li>Perform <a href="#sec-createdataproperty">CreateDataProperty</a>(<i>obj</i>, <a
+ href="#sec-tostring">ToString</a>(<i>index</i>), <i>val</i>).</li>
+ <li>Let <i>index</i> be <i>index</i> + 1</li>
+ </ol>
+ </li>
+ <li>Perform <a href="#sec-definepropertyorthrow">DefinePropertyOrThrow</a>(<i>obj</i>, <b>"<code>length</code>"</b>,
+ PropertyDescriptor{[[Value]]: <i>len</i>, [[Writable]]: <b>true</b>, [[Enumerable]]: <b>false</b>,
+ [[Configurable]]: <b>true</b>}).</li>
+ <li>Let <i>map</i> be <a href="#sec-objectcreate">ObjectCreate</a>(<b>null</b>).</li>
+ <li>Let <i>mappedNames</i> be an empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Let <i>index</i> be <i>numberOfParameters</i> − 1.</li>
+ <li>Repeat while <i>index</i> ≥ 0 ,
+ <ol class="block">
+ <li>Let <i>name</i> be the element of <i>parameterNames</i> at 0-origined list position <i>index</i>.</li>
+ <li>If <i>name</i> is not an element of <i>mappedNames</i>, then
+ <ol class="block">
+ <li>Add <i>name</i> as an element of the list <i>mappedNames</i>.</li>
+ <li>If <i>index</i> < <i>len</i>, then
+ <ol class="block">
+ <li>Let <i>g</i> be <a href="#sec-makearggetter">MakeArgGetter</a>(<i>name</i>, <i>env</i>).</li>
+ <li>Let <i>p</i> be <a href="#sec-makeargsetter">MakeArgSetter</a>(<i>name</i>, <i>env</i>).</li>
+ <li>Call the [[DefineOwnProperty]] internal method of <i>map</i> passing <a
+ href="#sec-tostring">ToString</a>(<i>index</i>) and the PropertyDescriptor{[[Set]]: <i>p</i>, [[Get]]:
+ <i>g,</i>[[Enumerable]]: <b>false</b>, [[Configurable]]: <b>true</b>} as arguments.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Let <i>index</i> be <i>index</i> − 1</li>
+ </ol>
+ </li>
+ <li>Set the [[ParameterMap]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>obj</i>
+ to <i>map</i>.</li>
+ <li>Perform <a href="#sec-definepropertyorthrow">DefinePropertyOrThrow</a>(<i>obj</i>, @@iterator, PropertyDescriptor
+ {[[Value]]:%ArrayProto_values%, [[Writable]]: <b>true</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>true</b>}).</li>
+ <li>Perform <a href="#sec-definepropertyorthrow">DefinePropertyOrThrow</a>(<i>obj</i>, <code>"callee"</code>,
+ PropertyDescriptor {[[Value]]: <i>func</i>, [[Writable]]: <b>true</b>, [[Enumerable]]: <b>false</b>,
+ [[Configurable]]: <b>true</b>}).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: the above property definitions will not produce an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a>.</li>
+ <li>Return <i>obj</i></li>
+ </ol>
+ </div>
+
+ <section id="sec-makearggetter">
+ <h1><span class="secnum" id="sec-9.4.4.7.1"><a href="#sec-makearggetter"
+ title="link to this section">9.4.4.7.1</a></span> MakeArgGetter ( name, env) Abstract Operation</h1>
+
+ <p>The abstract operation <span style="font-family: Times New Roman">MakeArgGetter</span> called with String
+ <var>name</var> and environment record <var>env</var> creates a built-in function object that when executed returns the
+ value bound for <var>name</var> in <var>env</var>. It performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>realm</i> be <a href="#sec-execution-contexts">the current Realm</a>.</li>
+ <li>Let <i>steps</i> be the steps of a ArgGetter function as specified below.</li>
+ <li>Let <i>getter</i> be <a href="#sec-createbuiltinfunction">CreateBuiltinFunction</a>(<i>realm</i>, <i>steps</i>,
+ %FunctionPrototype%, ([[name]], [[env]]) ).</li>
+ <li>Set <i>getter’s</i> [[name]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to
+ <i>name</i>.</li>
+ <li>Set <i>getter’s</i> [[env]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to
+ <i>env</i>.</li>
+ <li>Return <i>getter</i>.</li>
+ </ol>
+
+ <p>An ArgGetter function is an anonymous built-in function with [[name]] and [[env]] internal slots. When an ArgGetter
+ function <var>f</var> that expects no arguments is called it performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>name</i> be the value of <i>f’s</i> [[name]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>env</i> be the value of <i>f’s</i> [[env]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a></li>
+ <li>Return the result of calling the GetBindingValue concrete method of <i>env</i> with arguments <i>name</i> and
+ <b>false</b>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> ArgGetter functions are never directly accessible to ECMAScript code.</p>
+ </div>
+ </section>
+
+ <section id="sec-makeargsetter">
+ <h1><span class="secnum" id="sec-9.4.4.7.2"><a href="#sec-makeargsetter"
+ title="link to this section">9.4.4.7.2</a></span> MakeArgSetter ( name, env) Abstract Operation</h1>
+
+ <p>The abstract operation <span style="font-family: Times New Roman">MakeArgSetter</span> called with String
+ <var>name</var> and environment record <var>env</var> creates a built-in function object that when executed sets the
+ value bound for <var>name</var> in <var>env</var>. It performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>realm</i> be <a href="#sec-execution-contexts">the current Realm</a>.</li>
+ <li>Let <i>steps</i> be the steps of a ArgSetter function as specified below.</li>
+ <li>Let <i>setter</i> be <a href="#sec-createbuiltinfunction">CreateBuiltinFunction</a>(<i>realm</i>, <i>steps</i>,
+ %FunctionPrototype%, ([[name]], [[env]]) ).</li>
+ <li>Set <i>setter’s</i> [[name]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to
+ <i>name</i>.</li>
+ <li>Set <i>setter’s</i> [[env]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to
+ <i>env</i>.</li>
+ <li>Return <i>setter</i>.</li>
+ </ol>
+
+ <p>An ArgSetter function is an anonymous built-in function with [[name]] and [[env]] internal slots. When an ArgSetter
+ function <var>f</var> is called with argument <var>value</var> it performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>name</i> be the value of <i>f’s</i> [[name]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>env</i> be the value of <i>f’s</i> [[env]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a></li>
+ <li>Return the result of calling the SetMutableBinding concrete method of <i>env</i> with arguments <i>name</i>,
+ <i>value</i>, and <b>false</b>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> ArgSetter functions are never directly accessible to ECMAScript code.</p>
+ </div>
+ </section>
+ </section>
+ </section>
+
+ <section id="sec-integer-indexed-exotic-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-9.4.5"><a href="#sec-integer-indexed-exotic-objects"
+ title="link to this section">9.4.5</a></span> Integer Indexed Exotic Objects</h1>
+
+ <p>An <i>Integer Indexed object</i> is an exotic object that performs special handling of integer index property keys.</p>
+
+ <p>Integer Indexed exotic objects have the same internal slots as ordinary objects additionally [[ViewedArrayBuffer]],
+ [[ArrayLength]], [[ByteOffset]], and [[TypedArrayName]] internal slots.</p>
+
+ <p>Integer Indexed Exotic objects provide alternative definitions for the following internal methods. All of the other
+ Integer Indexed exotic object essential internal methods that are not defined below are as specified in <a
+ href="#sec-ordinary-object-internal-methods-and-internal-slots">9.1</a>.</p>
+ </div>
+
+ <section id="sec-integer-indexed-exotic-objects-getownproperty-p">
+ <h1><span class="secnum" id="sec-9.4.5.1"><a href="#sec-integer-indexed-exotic-objects-getownproperty-p"
+ title="link to this section">9.4.5.1</a></span> [[GetOwnProperty]] ( P )</h1>
+
+ <p>When the [[GetOwnProperty]] internal method of an Integer Indexed exotic object <var>O</var> is called with <a
+ href="#sec-object-type">property key</a> <var>P</var> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ispropertykey">IsPropertyKey</a>(<i>P</i>) is
+ <b>true</b>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>O</i> is an Object that has a [[ViewedArrayBuffer]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>P</i>) is String, then
+ <ol class="block">
+ <li>Let <i>numericIndex</i> be <a
+ href="#sec-canonicalnumericindexstring">CanonicalNumericIndexString</a>(<i>P</i>).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>numericIndex</i> is not an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a>.</li>
+ <li>If <i>numericIndex</i> is not <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>value</i> be <a href="#sec-integerindexedelementget">IntegerIndexedElementGet</a> (<i>O</i>,
+ <i>numericIndex</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>value</i>).</li>
+ <li>If <i>value</i> is <b>undefined</b>, then return <b>undefined</b>.</li>
+ <li>Return a PropertyDescriptor{ [[Value]]: <i>value</i>, [[Enumerable]]: <b>true</b>, [[Writable]]:
+ <b>true</b>, [[Configurable]]: <b>false</b> }.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Return <a href="#sec-ordinarygetownproperty">OrdinaryGetOwnProperty</a>(<i>O</i>, <i>P</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-integer-indexed-exotic-objects-defineownproperty-p-desc">
+ <h1><span class="secnum" id="sec-9.4.5.2"><a href="#sec-integer-indexed-exotic-objects-defineownproperty-p-desc"
+ title="link to this section">9.4.5.2</a></span> [[DefineOwnProperty]] ( P, Desc)</h1>
+
+ <p>When the [[DefineOwnProperty]] internal method of an Integer Indexed exotic object <var>O</var> is called with <a
+ href="#sec-object-type">property key</a> <var>P</var>, and <a href="#sec-property-descriptor-specification-type">Property
+ Descriptor</a> <span class="nt">Desc</span> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ispropertykey">IsPropertyKey</a>(<i>P</i>) is
+ <b>true</b>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>O</i> is an Object that has a [[ViewedArrayBuffer]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>P</i>) is String, then
+ <ol class="block">
+ <li>If the value of <i>O</i>’s [[ViewedArrayBuffer]] is <b>undefined</b>, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>Let <i>numericIndex</i> be <a href="#sec-canonicalnumericindexstring">CanonicalNumericIndexString</a>
+ (<i>P</i>).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>numericIndex</i> is not an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a>.</li>
+ <li>If <i>numericIndex</i> is not <b>undefined</b>, then
+ <ol class="block">
+ <li>If <a href="#sec-isinteger">IsInteger</a>(<i>numericIndex</i>) is <b>false</b> then return <b>false</b></li>
+ <li>Let <i>intIndex</i> be <i>numericIndex</i>.</li>
+ <li>If <i>intIndex</i> = −0, then return <b>false</b>.</li>
+ <li>If <i>intIndex</i> < 0, then return <b>false</b>.</li>
+ <li>Let <i>length</i> be the value of <i>O</i>’s [[ArrayLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>intIndex</i> ≥ <i>length</i>, then return <b>false</b>.</li>
+ <li>If <a href="#sec-isaccessordescriptor">IsAccessorDescriptor</a>(<i>Desc</i>) is <b>true</b>, then return
+ <b>false.</b></li>
+ <li>If <i>Desc</i> has a [[Configurable]] field and if <i>Desc</i>.[[Configurable]] is <b>true</b>, then return
+ <b>false<i>.</i></b></li>
+ <li>If <i>Desc</i> has an [[Enumerable]] field and if <i>Desc</i>.[[Enumerable]] is <b>false</b>, then return
+ <b>false<i>.</i></b></li>
+ <li>If <i>Desc</i> has a [[Writable]] field and if <i>Desc</i>.[[Writable]] is <b>false</b>, then return
+ <b>false</b>.</li>
+ <li>If <i>Desc</i> has a [[Value]] field, then
+ <ol class="block">
+ <li>Let <i>value</i> be <i>Desc</i>.[[Value]].</li>
+ <li>Let <i>status</i> be <a href="#sec-integerindexedelementset">IntegerIndexedElementSet</a> (<i>O</i>,
+ <i>intIndex</i>, <i>value</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ </ol>
+ </li>
+ <li>Return <b>true</b>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Return <a href="#sec-ordinarydefineownproperty">OrdinaryDefineOwnProperty</a>(<i>O</i>, <i>P, Desc</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-integer-indexed-exotic-objects-get-p-receiver">
+ <h1><span class="secnum" id="sec-9.4.5.3"><a href="#sec-integer-indexed-exotic-objects-get-p-receiver"
+ title="link to this section">9.4.5.3</a></span> [[Get]] (P, Receiver)</h1>
+
+ <p>When the [[Get]] internal method of an Integer Indexed exotic object <var>O</var> is called with <a
+ href="#sec-object-type">property key</a> <var>P</var> and <a href="#sec-ecmascript-language-types">ECMAScript language
+ value</a> <span class="nt">Receiver</span> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ispropertykey">IsPropertyKey</a>(<i>P</i>) is
+ <b>true</b>.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>P</i>) is String and if <a
+ href="#sec-samevalue">SameValue</a>(<i>O</i>, <i>Receiver</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>numericIndex</i> be <a href="#sec-canonicalnumericindexstring">CanonicalNumericIndexString</a>
+ (<i>P</i>).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>numericIndex</i> is not an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a>.</li>
+ <li>If <i>numericIndex</i> is not <b>undefined</b>, then
+ <ol class="block">
+ <li>Return <a href="#sec-integerindexedelementget">IntegerIndexedElementGet</a> (<i>O</i>,
+ <i>numericIndex</i>).</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Return the result of calling the default ordinary object [[Get]] internal method (<a
+ href="#sec-ordinary-object-internal-methods-and-internal-slots-get-p-receiver">9.1.8</a>) on <i>O</i> passing
+ <i>P</i> and <i>Receiver</i> as arguments.</li>
+ </ol>
+ </section>
+
+ <section id="sec-integer-indexed-exotic-objects-set-p-v-receiver">
+ <h1><span class="secnum" id="sec-9.4.5.4"><a href="#sec-integer-indexed-exotic-objects-set-p-v-receiver"
+ title="link to this section">9.4.5.4</a></span> [[Set]] ( P, V, Receiver)</h1>
+
+ <p>When the [[Set]] internal method of an Integer Indexed exotic object <var>O</var> is called with <a
+ href="#sec-object-type">property key</a> <var>P</var>, value <var>V</var>, and <a
+ href="#sec-ecmascript-language-types">ECMAScript language value</a> <span class="nt">Receiver</span>, the following steps
+ are taken:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ispropertykey">IsPropertyKey</a>(<i>P</i>) is
+ <b>true</b>.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>P</i>) is String and if <a
+ href="#sec-samevalue">SameValue</a>(<i>O</i>, <i>Receiver</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>numericIndex</i> be <a href="#sec-canonicalnumericindexstring">CanonicalNumericIndexString</a>
+ (<i>P</i>).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>numericIndex</i> is not an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a>.</li>
+ <li>If <i>numericIndex</i> is not <b>undefined</b>, then
+ <ol class="block">
+ <li>Return <a href="#sec-toboolean">ToBoolean</a>(<a
+ href="#sec-integerindexedelementset">IntegerIndexedElementSet</a> (<i>O</i>, <i>numericIndex</i>,
+ <i>V</i>)).</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Return the result of calling the default ordinary object [[Set]] internal method (<a
+ href="#sec-ordinary-object-internal-methods-and-internal-slots-get-p-receiver">9.1.8</a>) on <i>O</i> passing
+ <i>P</i>, <i>V</i>, and <i>Receiver</i> as arguments.</li>
+ </ol>
+ </section>
+
+ <section id="sec-integer-indexed-exotic-objects-enumerate">
+ <h1><span class="secnum" id="sec-9.4.5.5"><a href="#sec-integer-indexed-exotic-objects-enumerate"
+ title="link to this section">9.4.5.5</a></span> [[Enumerate]] ()</h1>
+
+ <p>When the [[Enumerate]] internal method of an Integer Indexed exotic object <var>O</var> is called the following steps
+ are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>indexKeys</i> be a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>O</i> is an Object that has [[ViewedArrayBuffer]],
+ [[ArrayLength]], [[ByteOffset]], and [[TypedArrayName]] internal slots.</li>
+ <li>If the value of <i>O</i>’s [[ViewedArrayBuffer]] is <b>undefined</b>, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>Let <i>len</i> be the value of <i>O</i>’s [[ArrayLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>For each integer <i>i</i> starting with 0 such that <i>i</i> < <i>len</i>, in ascending order,
+ <ol class="block">
+ <li>Add <a href="#sec-tostring">ToString</a>(<i>i</i>) as the last element of <i>indexKeys</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>ordinary</i> be the result of calling the default ordinary object [[Enumerate]] internal method (<a
+ href="#sec-ordinary-object-internal-methods-and-internal-slots-enumerate">9.1.11</a>) on <i>O</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>ordinary</i>).</li>
+ <li>Return <a href="#sec-createcompounditerator">CreateCompoundIterator</a>(<a
+ href="#sec-createlistiterator">CreateListIterator</a>(<i>indexKeys</i>), <i>ordinary</i>)<i>.</i></li>
+ </ol>
+ </section>
+
+ <section id="sec-integer-indexed-exotic-objects-ownpropertykeys">
+ <h1><span class="secnum" id="sec-9.4.5.6"><a href="#sec-integer-indexed-exotic-objects-ownpropertykeys"
+ title="link to this section">9.4.5.6</a></span> [[OwnPropertyKeys]] ()</h1>
+
+ <p>When the [[OwnPropertyKeys]] internal method of an Integer Indexed exotic object <var>O</var> is called the following
+ steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>keys</i> be a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>O</i> is an Object that has [[ViewedArrayBuffer]],
+ [[ArrayLength]], [[ByteOffset]], and [[TypedArrayName]] internal slots.</li>
+ <li>If the value of <i>O</i>’s [[ViewedArrayBuffer]] is <b>undefined</b>, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>Let <i>len</i> be the value of <i>O</i>’s [[ArrayLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>For each integer <i>i</i> starting with 0 such that <i>i</i> < <i>len</i>, in ascending order,
+ <ol class="block">
+ <li>Add <a href="#sec-tostring">ToString</a>(<i>i</i>) as the last element of <i>keys</i>.</li>
+ </ol>
+ </li>
+ <li>For each own <a href="#sec-object-type">property key</a> <i>P</i> of <i>O</i> such that <i>P</i> is an integer index
+ and <a href="#sec-tointeger">ToInteger</a>(<i>P</i>) ≥ <i>len</i>, in ascending numeric index order
+ <ol class="block">
+ <li>Add <i>P</i> as the last element of <i>keys</i>.</li>
+ </ol>
+ </li>
+ <li>For each own <a href="#sec-object-type">property key</a> <i>P</i> of <i>O</i> such that <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>P</i>) is String and <i>P</i> is not an integer index, in
+ property creation order
+ <ol class="block">
+ <li>Add <i>P</i> as the last element of <i>keys</i>.</li>
+ </ol>
+ </li>
+ <li>For each own <a href="#sec-object-type">property key</a> <i>P</i> of <i>O</i> such that <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>P</i>) is Symbol, in property creation order
+ <ol class="block">
+ <li>Add <i>P</i> as the last element of <i>keys</i>.</li>
+ </ol>
+ </li>
+ <li>Return <a href="#sec-createarrayfromlist">CreateArrayFromList</a>(<i>keys</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-integerindexedobjectcreate">
+ <h1><span class="secnum" id="sec-9.4.5.7"><a href="#sec-integerindexedobjectcreate"
+ title="link to this section">9.4.5.7</a></span> IntegerIndexedObjectCreate Abstract Operation</h1>
+
+ <p>The abstract operation IntegerIndexedObjectCreate with argument <var>prototype</var> is used to specify the creation of
+ new Integer Indexed exotic objects. It performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>A</i> be a newly created object.</li>
+ <li>Set <i>A</i>’s essential internal methods to the default ordinary object definitions specified in <a
+ href="#sec-ordinary-object-internal-methods-and-internal-slots">9.1</a>.</li>
+ <li>Set the [[GetOwnProperty]] internal method of <i>A</i> as specified in <a
+ href="#sec-integer-indexed-exotic-objects-getownproperty-p">9.4.5.1</a>.</li>
+ <li>Set the [[DefineOwnProperty]] internal method of <i>A</i> as specified in <a
+ href="#sec-integer-indexed-exotic-objects-defineownproperty-p-desc">9.4.5.2</a>.</li>
+ <li>Set the [[Get]] internal method of <i>A</i> as specified in <a
+ href="#sec-integer-indexed-exotic-objects-get-p-receiver">9.4.5.3</a>.</li>
+ <li>Set the [[Set]] internal method of <i>A</i> as specified in <a
+ href="#sec-integer-indexed-exotic-objects-set-p-v-receiver">9.4.5.4</a>.</li>
+ <li>Set the [[Enumerate]] internal method of <i>A</i> as specified in <a
+ href="#sec-integer-indexed-exotic-objects-enumerate">9.4.5.5</a>.</li>
+ <li>Set the [[OwnPropertyKeys]] internal method of <i>A</i> as specified in <a
+ href="#sec-integer-indexed-exotic-objects-ownpropertykeys">9.4.5.6</a>.</li>
+ <li>Set the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>A</i> to
+ <i>prototype</i>.</li>
+ <li>Set the [[Extensible]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>A</i> to
+ <b>true</b>.</li>
+ <li>Return <i>A</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-integerindexedelementget">
+ <h1><span class="secnum" id="sec-9.4.5.8"><a href="#sec-integerindexedelementget"
+ title="link to this section">9.4.5.8</a></span> IntegerIndexedElementGet ( O, index ) Abstract Operation</h1>
+
+ <p>The abstract operation IntegerIndexedElementGet with arguments <var>O</var> and <var>index</var> performs the following
+ steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>index</i>) is Number.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>O</i> is an Object that has [[ViewedArrayBuffer]],
+ [[ArrayLength]], [[ByteOffset]], and [[TypedArrayName]] internal slots.</li>
+ <li>Let <i>buffer</i> be the value of <i>O</i>’s [[ViewedArrayBuffer]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>buffer</i> is <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>If <a href="#sec-isinteger">IsInteger</a>(<i>index</i>) is <b>false</b> then return <b>undefined</b></li>
+ <li>If <i>index</i> = −0, then return <b>undefined</b>.</li>
+ <li>Let <i>length</i> be the value of <i>O</i>’s [[ArrayLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>index</i> < 0 or <i>index</i> ≥ <i>length</i>, then return <b>undefined</b>.</li>
+ <li>Let <i>offset</i> be the value of <i>O</i>’s [[ByteOffset]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>arrayTypeName</i> be the string value of <i>O</i>’s [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>elementSize</i> be the Number value of the Element Size value specified in <a href="#table-44">Table 44</a>
+ for <i>arrayTypeName</i>.</li>
+ <li>Let <i>indexedPosition</i> = (<i>index</i> × <i>elementSize</i>) + <i>offset</i>.</li>
+ <li>Let <i>elementType</i> be the string value of the Element Type value in <a href="#table-44">Table 44</a> for
+ <i>arrayTypeName</i>.</li>
+ <li>Return <a href="#sec-getvaluefrombuffer">GetValueFromBuffer</a>(<i>buffer</i>, <i>indexedPosition</i>,
+ <i>elementType</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-integerindexedelementset">
+ <h1><span class="secnum" id="sec-9.4.5.9"><a href="#sec-integerindexedelementset"
+ title="link to this section">9.4.5.9</a></span> IntegerIndexedElementSet ( O, index, value ) Abstract Operation</h1>
+
+ <p>The abstract operation IntegerIndexedElementSet with arguments <var>O</var>, <var>index</var>, and <var>value</var>
+ performs the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>index</i>) is Number.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>O</i> is an Object that has [[ViewedArrayBuffer]],
+ [[ArrayLength]], [[ByteOffset]], and [[TypedArrayName]] internal slots.</li>
+ <li>Let <i>buffer</i> be the value of <i>O</i>’s [[ViewedArrayBuffer]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>buffer</i> is <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>If <a href="#sec-isinteger">IsInteger</a>(<i>index</i>) is <b>false</b> then return <b>false</b></li>
+ <li>If <i>index</i> = −0, then return <b>undefined</b>.</li>
+ <li>Let <i>length</i> be the value of <i>O</i>’s [[ArrayLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>numValue</i> be <a href="#sec-tonumber">ToNumber</a>(<i>value)</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>numValue</i>).</li>
+ <li>If <i>index</i> < 0 or <i>index</i> ≥ <i>length</i>, then return <b>false</b>.</li>
+ <li>Let <i>offset</i> be the value of <i>O</i>’s [[ByteOffset]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>arrayTypeName</i> be the string value of <i>O</i>’s [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>elementSize</i> be the Number value of the Element Size value specified in <a href="#table-44">Table 44</a>
+ for <i>arrayTypeName</i>.</li>
+ <li>Let <i>indexedPosition</i> = (<i>index</i> × <i>elementSize</i>) + <i>offset</i>.</li>
+ <li>Let <i>elementType</i> be the string value of the Element Type value in <a href="#table-44">Table 44</a> for
+ <i>arrayTypeName</i>.</li>
+ <li>Let <i>status</i> be <a href="#sec-setvalueinbuffer">SetValueInBuffer</a>(<i>buffer</i>, <i>indexedPosition</i>,
+ <i>elementType</i>, <i>numValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Return <b>true</b>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-module-exotic-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-9.4.6"><a href="#sec-module-exotic-objects" title="link to this section">9.4.6</a></span>
+ Module Exotic Objects</h1>
+
+ <p>A <i>module object</i> is an exotic object that exposes the bindings exported from an ECMAScript <span
+ class="nt">Module</span> <var>(See <a href="#sec-scriptevaluationtask">15.1.9</a>)</var>. There is a one-to-one
+ correspondence between the own properties of a module exotic object and the ExportedBindings of the <span
+ class="nt">Module</span>. Each own property name is the StringValue of the corresponding exported binding. These are the
+ only properties of a module exotic object. Each such property has the attributes {[[Configurable]]: <span
+ class="value">false</span>, [[Enumerable]]: <span class="value">true</span>}. Module objects are not extensible.</p>
+
+ <p>Module objects have the internal slots defined in <a href="#table-28">Table 28</a>.</p>
+
+ <figure>
+ <figcaption><span id="table-28">Table 28</span> — Internal Slots of Module Exotic Objects</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-top: 2px solid #000000">Internal Slot</th>
+ <th style="border-bottom: 1px solid #000000; border-top: 2px solid #000000">Type</th>
+ <th style="border-bottom: 1px solid #000000; border-right: 1px solid #000000; border-top: 2px solid #000000">Description</th>
+ </tr>
+ <tr>
+ <td>[[ModuleEnvironment]]</td>
+ <td>Environment</td>
+ <td>The <a href="#sec-declarative-environment-records">Declarative Environment Record</a> that contains all of the declared top-level bindings for the corresponding module.</td>
+ </tr>
+ <tr>
+ <td>[[Exports]]</td>
+ <td><a href="#sec-list-and-record-specification-type">List</a> of String</td>
+ <td>A <a href="#sec-list-and-record-specification-type">List</a> containing the bound names exposed as own properties of this object. The list is ordered as if an Array of the same values had been sorted using <code><a href="#sec-array.prototype.sort">Array.prototype.sort</a></code> using <a href="#sec-sortcompare">SortCompare</a> as <i><span style="font-family: Times New Roman">comparefn</span>.</i></td>
+ </tr>
+ </table>
+ </figure>
+
+ <p>Module exotic objects provide alternative definitions for all of the internal methods.</p>
+ </div>
+
+ <section id="sec-module-exotic-objects-getprototypeof">
+ <h1><span class="secnum" id="sec-9.4.6.1"><a href="#sec-module-exotic-objects-getprototypeof"
+ title="link to this section">9.4.6.1</a></span> [[GetPrototypeOf]] ( )</h1>
+
+ <p>When the [[GetPrototypeOf]] internal method of a module exotic object <var>O</var> is called the following steps are
+ taken:</p>
+
+ <ol class="proc">
+ <li>Return <b>null</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-module-exotic-objects-setprototypeof-v">
+ <h1><span class="secnum" id="sec-9.4.6.2"><a href="#sec-module-exotic-objects-setprototypeof-v"
+ title="link to this section">9.4.6.2</a></span> [[SetPrototypeOf]] (V)</h1>
+
+ <p>When the [[SetPrototypeOf]] internal method of a module exotic object <var>O</var> is called with argument <i>V</i> the
+ following steps are taken:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: Either <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>V</i>) is Object or <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>V</i>) is Null.</li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-module-exotic-objects-isextensible">
+ <h1><span class="secnum" id="sec-9.4.6.3"><a href="#sec-module-exotic-objects-isextensible"
+ title="link to this section">9.4.6.3</a></span> [[IsExtensible]] ( )</h1>
+
+ <p>When the [[IsExtensible]] internal method of a module exotic object <var>O</var> is called the following steps are
+ taken:</p>
+
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-module-exotic-objects-preventextensions">
+ <h1><span class="secnum" id="sec-9.4.6.4"><a href="#sec-module-exotic-objects-preventextensions"
+ title="link to this section">9.4.6.4</a></span> [[PreventExtensions]] ( )</h1>
+
+ <p>When the [[PreventExtensions]] internal method of a module exotic object <var>O</var> is called the following steps are
+ taken:</p>
+
+ <ol class="proc">
+ <li>Return <b>true</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-module-exotic-objects-getownproperty-p">
+ <h1><span class="secnum" id="sec-9.4.6.5"><a href="#sec-module-exotic-objects-getownproperty-p"
+ title="link to this section">9.4.6.5</a></span> [[GetOwnProperty]] (P)</h1>
+
+ <p>When the [[GetOwnProperty]] internal method of a module exotic object <var>O</var> is called with <a
+ href="#sec-object-type">property key</a> <var>P</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Throw a <b>TypeError</b> exception.</li>
+ </ol>
+ </section>
+
+ <section id="sec-module-exotic-objects-defineownproperty-p-desc">
+ <h1><span class="secnum" id="sec-9.4.6.6"><a href="#sec-module-exotic-objects-defineownproperty-p-desc"
+ title="link to this section">9.4.6.6</a></span> [[DefineOwnProperty]] (P, Desc)</h1>
+
+ <p>When the [[DefineOwnProperty]] internal method of a module exotic object <var>O</var> is called with <a
+ href="#sec-object-type">property key</a> <var>P</var> and <a href="#sec-property-descriptor-specification-type">Property
+ Descriptor</a> <span class="nt">Desc</span>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-module-exotic-objects-hasproperty-p">
+ <h1><span class="secnum" id="sec-9.4.6.7"><a href="#sec-module-exotic-objects-hasproperty-p"
+ title="link to this section">9.4.6.7</a></span> [[HasProperty]] (P)</h1>
+
+ <p>When the [[HasProperty]] internal method of a module exotic object <var>O</var> is called with <a
+ href="#sec-object-type">property key</a> <var>P</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>exports</i> be the value of <i>O</i>’s [[Exports]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>P</i> is an element of <i>exports</i>, then return <b>true</b>.</li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-module-exotic-objects-get-p-receiver">
+ <h1><span class="secnum" id="sec-9.4.6.8"><a href="#sec-module-exotic-objects-get-p-receiver"
+ title="link to this section">9.4.6.8</a></span> [[Get]] (P, Receiver)</h1>
+
+ <p>When the [[Get]] internal method of a module exotic object <var>O</var> is called with <a
+ href="#sec-object-type">property key</a> <var>P</var> and <a href="#sec-ecmascript-language-types">ECMAScript language
+ value</a> <span class="nt">Receiver</span> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ispropertykey">IsPropertyKey</a>(<i>P</i>) is
+ <b>true</b>.</li>
+ <li>Let <i>exports</i> be the value of <i>O</i>’s [[Exports]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>P</i> is not an element of <i>exports</i>, then return <b>undefined</b>.</li>
+ <li>Let <i>env</i> be the value of <i>O</i>’s [[ModuleEnvironment]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Return the result of calling the GetBindingValue concrete method of <i>env</i> with arguments <i>P</i> and
+ <b>true</b>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Attempting to [[Get]] the value of a module export that has not yet been initialized
+ will throw a ReferenceError exception.</p>
+ </div>
+ </section>
+
+ <section id="sec-module-exotic-objects-set-p-v-receiver">
+ <h1><span class="secnum" id="sec-9.4.6.9"><a href="#sec-module-exotic-objects-set-p-v-receiver"
+ title="link to this section">9.4.6.9</a></span> [[Set]] ( P, V, Receiver)</h1>
+
+ <p>When the [[Set]] internal method of <span style="font-family: Times New Roman">a</span> module exotic object
+ <var>O</var> is called with <a href="#sec-object-type">property key</a> <var>P</var>, value <var>V</var>, and <a
+ href="#sec-ecmascript-language-types">ECMAScript language value</a> <span class="nt">Receiver</span>, the following steps
+ are taken:</p>
+
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-module-exotic-objects-delete-p">
+ <h1><span class="secnum" id="sec-9.4.6.10"><a href="#sec-module-exotic-objects-delete-p"
+ title="link to this section">9.4.6.10</a></span> [[Delete]] (P)</h1>
+
+ <p>When the [[Delete]] internal method of a module exotic object <var>O</var> is called with <a
+ href="#sec-object-type">property key</a> <var>P</var> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ispropertykey">IsPropertyKey</a>(<i>P</i>) is
+ <b>true</b>.</li>
+ <li>Let <i>exports</i> be the value of <i>O</i>’s [[Exports]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>P</i> is an element of <i>exports</i>, then return <b>false</b>.</li>
+ <li>Return <b>true</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-module-exotic-objects-enumerate">
+ <h1><span class="secnum" id="sec-9.4.6.11"><a href="#sec-module-exotic-objects-enumerate"
+ title="link to this section">9.4.6.11</a></span> [[Enumerate]] ()</h1>
+
+ <p>When the [[Enumerate]] internal method of a module exotic object <var>O</var> is called the following steps are
+ taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>exports</i> be the value of <i>O</i>’s [[Exports]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Return <a href="#sec-createlistiterator">CreateListIterator</a>(<i>exports</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-module-exotic-objects-ownpropertykeys">
+ <h1><span class="secnum" id="sec-9.4.6.12"><a href="#sec-module-exotic-objects-ownpropertykeys"
+ title="link to this section">9.4.6.12</a></span> [[OwnPropertyKeys]] ( )</h1>
+
+ <p>When the [[OwnPropertyKeys]] internal method of a module exotic object <var>O</var> is called the following steps are
+ taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>exports</i> be the value of <i>O</i>’s [[Exports]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Return <a href="#sec-createarrayfromlist">CreateArrayFromList</a> (<i>exports</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-moduleobjectcreate">
+ <h1><span class="secnum" id="sec-9.4.6.13"><a href="#sec-moduleobjectcreate"
+ title="link to this section">9.4.6.13</a></span> ModuleObjectCreate (environment, exports)</h1>
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>environment</i> is a <a
+ href="#sec-declarative-environment-records">Declarative Environment Record</a>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>exports</i> is a <a
+ href="#sec-list-and-record-specification-type">List</a> of string values.</li>
+ <li>Let <i>M</i> be a newly created object.</li>
+ <li>Set <i>M</i>’s essential internal methods to the definitions specified in <a
+ href="#sec-module-exotic-objects">9.4.6</a>.</li>
+ <li>Set <i>M</i>’s [[ModuleEnvironment]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> to <i>environment</i>.</li>
+ <li>Set <i>M</i>’s [[Exports]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to
+ <i>exports</i>.</li>
+ <li>Return <i>M</i>.</li>
+ </ol>
+ </section>
+ </section>
+ </section>
+
+ <section id="sec-proxy-object-internal-methods-and-internal-slots">
+ <div class="front">
+ <h1><span class="secnum" id="sec-9.5"><a href="#sec-proxy-object-internal-methods-and-internal-slots"
+ title="link to this section">9.5</a></span> Proxy Object Internal Methods and Internal Slots</h1>
+
+ <p>A proxy object is an exotic object whose essential internal methods are partially implemented using ECMAScript code.
+ Every proxy objects has an <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> called
+ [[ProxyHandler]]. The value of [[ProxyHandler]] is always an object, called the proxy’s <i>handler object</i>.
+ Methods of a handler object may be used to augment the implementation for one or more of the proxy object’s internal
+ methods. Every proxy object also has an <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> called
+ [[ProxyTarget]] whose value is either an object or the <b>null</b> value. This object is called the proxy’s <i>target
+ object</i>.</p>
+
+ <p>When a handler method is called to provide the implementation of a proxy object internal method, the handler method is
+ passed the proxy’s target object as a parameter. A proxy’s handler object does not necessarily have a method
+ corresponding to every essential internal method. Invoking an internal method on the proxy results in the invocation of the
+ corresponding internal method on the proxy’s target object if the handler object does not have a method corresponding
+ to the internal trap.</p>
+
+ <p>The [[ProxyHandler]] and [[ProxyTarget]] internal slots of a proxy object are always initialized when the object is
+ created and typically may not be modified. Some proxy objects are created in a manner that permits them to be subsequently
+ <i>revoked</i>. When a proxy is revoked, its [[ProxyHander]] and [[ProxyTarget]] internal slots are set to <b>null</b>
+ causing subsequent invocations of internal methods on that proxy obeject to throw a <span class="value">TypeError</span>
+ exception.</p>
+
+ <p>Because proxy permit arbitrary ECMAScript code to be used to in the implementation of internal methods, it is possible to
+ define a proxy object whose handler methods violates the invariants defined in <a
+ href="#sec-invariants-of-the-essential-internal-methods">6.1.7.3</a>. Some of the internal method invariants defined in <a
+ href="#sec-invariants-of-the-essential-internal-methods">6.1.7.3</a> are essential integrity invariants. These invariants
+ are explicitly enforced by the proxy internal methods specified in this section. An ECMAScript implementation must be robust
+ in the presence of all possible invariant violations.</p>
+
+ <p>In the following algorithm descriptions, assume <var>O</var> is an ECMAScript proxy object, <var>P</var> is a <a
+ href="#sec-object-type">property key value</a>, <var>V</var> is any <a href="#sec-ecmascript-language-types">ECMAScript
+ language value</a>, <span style="font-family: Times New Roman">Desc</span> is a <a
+ href="#sec-property-descriptor-specification-type">Property Descriptor</a> record, and <var>B</var> is a Boolean flag.</p>
+ </div>
+
+ <section id="sec-proxy-object-internal-methods-and-internal-slots-getprototypeof">
+ <h1><span class="secnum" id="sec-9.5.1"><a href="#sec-proxy-object-internal-methods-and-internal-slots-getprototypeof"
+ title="link to this section">9.5.1</a></span> [[GetPrototypeOf]] ( )</h1>
+
+ <p>When the [[GetPrototypeOf]] internal method of an exotic Proxy object <var>O</var> is called the following steps are
+ taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>handler</i> be the value of the [[ProxyHandler]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>If <i>handler</i> is <b>null</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>target</i> be the value of the [[ProxyTarget]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>Let <i>trap</i> be <a href="#sec-getmethod">GetMethod</a>(<i>handler</i>, "<code>getPrototypeOf</code>").</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>trap</i>).</li>
+ <li>If <i>trap</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>Return the result of calling the [[GetPrototypeOf]] internal method of <i>target</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>handlerProto</i> be the result of calling the [[Call]] internal method of <i>trap</i> with <i>handler</i> as
+ the <b>this</b> value and a new <a href="#sec-list-and-record-specification-type">List</a> containing
+ <i>target</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>handlerProto</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>handlerProto</i>) is neither Object nor Null, then
+ throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>extensibleTarget</i> be <a href="#sec-isextensible-o">IsExtensible</a>(<i>target</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>extensibleTarget</i>).</li>
+ <li>If <i>extensibleTarget</i> is <b>true</b>, then return <i>handlerProto</i>.</li>
+ <li>Let <i>targetProto</i> be the result of calling the [[GetPrototypeOf]] internal method of <i>target</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>targetProto</i>).</li>
+ <li>If <a href="#sec-samevalue">SameValue</a>(<i>handlerProto</i>, <i>targetProto</i>) is <b>false</b>, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>Return <i>handlerProto</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> [[GetPrototypeOf]] for proxy objects enforces the following invariant:</p>
+
+ <ul>
+ <li>
+ <p>The result of [[GetPrototypeOf]] must be either an Object or <b>null</b>.</p>
+ </li>
+
+ <li>
+ <p>If the target object is not extensible, [[GetPrototypeOf]] applied to the proxy object must return the same value
+ as [[GetPrototypeOf] applied to the proxy object’s target object.</p>
+ </li>
+ </ul>
+ </div>
+ </section>
+
+ <section id="sec-proxy-object-internal-methods-and-internal-slots-setprototypeof-v">
+ <h1><span class="secnum" id="sec-9.5.2"><a href="#sec-proxy-object-internal-methods-and-internal-slots-setprototypeof-v"
+ title="link to this section">9.5.2</a></span> [[SetPrototypeOf]] (V)</h1>
+
+ <p>When the [[SetPrototypeOf]] internal method of an exotic Proxy object <var>O</var> is called with argument <i>V</i> the
+ following steps are taken:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: Either <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>V</i>) is Object or <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>V</i>) is Null.</li>
+ <li>Let <i>handler</i> be the value of the [[ProxyHandler]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>If <i>handler</i> is <b>null</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>target</i> be the value of the [[ProxyTarget]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>Let <i>trap</i> be <a href="#sec-getmethod">GetMethod</a>(<i>handler</i>, "<code>setPrototypeOf</code>").</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>trap</i>).</li>
+ <li>If <i>trap</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>Return the result of calling the [[SetPrototypeOf]] internal method of <i>target</i> with argument <i>V</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>trapResult</i> be the result of calling the [[Call]] internal method of <i>trap</i> with <i>handler</i> as the
+ <b>this</b> value and a new <a href="#sec-list-and-record-specification-type">List</a> containing <i>target</i> and
+ <i>V</i>.</li>
+ <li>Let <i>booleanTrapResult</i> be <a href="#sec-toboolean">ToBoolean</a>(<i>trapResult</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>booleanTrapResult</i>).</li>
+ <li>Let <i>extensibleTarget</i> be <a href="#sec-isextensible-o">IsExtensible</a>(<i>target</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>extensibleTarget</i>).</li>
+ <li>If <i>extensibleTarget</i> is <b>true</b>, then return <i>booleanTrapResult</i>.</li>
+ <li>Let <i>targetProto</i> be the result of calling the [[GetPrototypeOf]] internal method of <i>target</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>targetProto</i>).</li>
+ <li>If <i>booleanTrapResult</i> is <b>true</b> and <a href="#sec-samevalue">SameValue</a>(<i>V</i>, <i>targetProto</i>) is
+ <b>false</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Return <i>booleanTrapResult</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> [[SetPrototypeOf]] for proxy objects enforces the following invariant:</p>
+
+ <ul>
+ <li>
+ <p>If the target object is not extensible, the argument value must be the same as the result of [[GetPrototypeOf]]
+ applied to target object.</p>
+ </li>
+ </ul>
+ </div>
+ </section>
+
+ <section id="sec-proxy-object-internal-methods-and-internal-slots-isextensible">
+ <h1><span class="secnum" id="sec-9.5.3"><a href="#sec-proxy-object-internal-methods-and-internal-slots-isextensible"
+ title="link to this section">9.5.3</a></span> [[IsExtensible]] ( )</h1>
+
+ <p>When the [[IsExtensible]] internal method of an exotic Proxy object <var>O</var> is called the following steps are
+ taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>handler</i> be the value of the [[ProxyHandler]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>If <i>handler</i> is <b>null</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>target</i> be the value of the [[ProxyTarget]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>Let <i>trap</i> be <a href="#sec-getmethod">GetMethod</a>(<i>handler</i>, "<code>isExtensible</code>").</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>trap</i>).</li>
+ <li>If <i>trap</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>Return the result of calling the [[IsExtensible]] internal method of <i>target</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>trapResult</i> be the result of calling the [[Call]] internal method of <i>trap</i> with <i>handler</i> as the
+ <b>this</b> value and a new <a href="#sec-list-and-record-specification-type">List</a> containing <i>target</i>.</li>
+ <li>Let <i>booleanTrapResult</i> be <a href="#sec-toboolean">ToBoolean</a>(<i>trapResult</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>booleanTrapResult</i>).</li>
+ <li>Let <i>targetResult</i> be the result of calling the [[IsExtensible]] internal method of <i>target</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>targetResult</i>).</li>
+ <li>If <a href="#sec-samevalue">SameValue</a>(<i>booleanTrapResult</i>, <i>targetResult</i>) is <b>false</b>, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>Return <i>booleanTrapResult</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> [[IsExtensible]] for proxy objects enforces the following invariant:</p>
+
+ <ul>
+ <li>
+ <p>[[IsExtensible]] applied to the proxy object must return the same value as [[IsExtensible]] applied to the proxy
+ object’s target object with the same argument.</p>
+ </li>
+ </ul>
+ </div>
+ </section>
+
+ <section id="sec-proxy-object-internal-methods-and-internal-slots-preventextensions">
+ <h1><span class="secnum" id="sec-9.5.4"><a href="#sec-proxy-object-internal-methods-and-internal-slots-preventextensions"
+ title="link to this section">9.5.4</a></span> [[PreventExtensions]] ( )</h1>
+
+ <p>When the [[PreventExtensions]] internal method of an exotic Proxy object <var>O</var> is called the following steps are
+ taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>handler</i> be the value of the [[ProxyHandler]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>If <i>handler</i> is <b>null</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>target</i> be the value of the [[ProxyTarget]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>Let <i>trap</i> be <a href="#sec-getmethod">GetMethod</a>(<i>handler</i>, "<code>preventExtensions</code>").</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>trap</i>).</li>
+ <li>If <i>trap</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>Return the result of calling the [[PreventExtensions]] internal method of <i>target</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>trapResult</i> be the result of calling the [[Call]] internal method of <i>trap</i> with <i>handler</i> as the
+ <b>this</b> value and a new <a href="#sec-list-and-record-specification-type">List</a> containing <i>target</i>.</li>
+ <li>Let <i>booleanTrapResult</i> be <a href="#sec-toboolean">ToBoolean</a>(<i>trapResult</i>)</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>booleanTrapResult</i>).</li>
+ <li>If <i>booleanTrapResult</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>targetIsExtensible</i> be the result of calling the [[IsExtensible]] internal method of <i>target</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>targetIsExtensible</i>).</li>
+ <li>If <i>targetIsExtensible</i> is <b>true</b>, then throw a <b>TypeError</b> exception.</li>
+ </ol>
+ </li>
+ <li>Return <i>booleanTrapResult</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> [[PreventExtensions]] for proxy objects enforces the following invariant:</p>
+
+ <ul>
+ <li>
+ <p>[[PreventExtensions]] applied to the proxy object only returns <b>true</b> if [[IsExtensible]] applied to the proxy
+ object’s target object is <b>false</b>.</p>
+ </li>
+ </ul>
+ </div>
+ </section>
+
+ <section id="sec-proxy-object-internal-methods-and-internal-slots-getownproperty-p">
+ <h1><span class="secnum" id="sec-9.5.5"><a href="#sec-proxy-object-internal-methods-and-internal-slots-getownproperty-p"
+ title="link to this section">9.5.5</a></span> [[GetOwnProperty]] (P)</h1>
+
+ <p>When the [[GetOwnProperty]] internal method of an exotic Proxy object <var>O</var> is called with <a
+ href="#sec-object-type">property key</a> <var>P</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ispropertykey">IsPropertyKey</a>(<i>P</i>) is
+ <b>true</b>.</li>
+ <li>Let <i>handler</i> be the value of the [[ProxyHandler]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>If <i>handler</i> is <b>null</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>target</i> be the value of the [[ProxyTarget]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>Let <i>trap</i> be <a href="#sec-getmethod">GetMethod</a>(<i>handler</i>,
+ "<code>getOwnPropertyDescriptor</code>").</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>trap</i>).</li>
+ <li>If <i>trap</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>Return the result of calling the [[GetOwnProperty]] internal method of <i>target</i> with argument <i>P</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>trapResultObj</i> be the result of calling the [[Call]] internal method of <i>trap</i> with <i>handler</i> as
+ the <b>this</b> value and a new <a href="#sec-list-and-record-specification-type">List</a> containing <i>target</i>
+ and <i>P</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>trapResultObj</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>trapResultObj</i>) is neither Object nor Undefined,
+ then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>targetDesc</i> be the result of calling the [[GetOwnProperty]] internal method of <i>target</i> with argument
+ <i>P</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>targetDesc</i>).</li>
+ <li>If <i>trapResultObj</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>If <i>targetDesc</i> is <b>undefined</b>, then return <b>undefined</b>.</li>
+ <li>If <i>targetDesc</i>.[[Configurable]] is <b>false</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>extensibleTarget</i> be <a href="#sec-isextensible-o">IsExtensible</a>(<i>target</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>extensibleTarget</i>).</li>
+ <li>If <a href="#sec-toboolean">ToBoolean</a>(<i>extensibleTarget</i>) is <b>false</b>, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>Return <b>undefined</b>.</li>
+ </ol>
+ </li>
+ <li>Let <i>extensibleTarget</i> be <a href="#sec-isextensible-o">IsExtensible</a>(<i>target</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>extensibleTarget</i>).</li>
+ <li>Let <i>resultDesc</i> be <a href="#sec-topropertydescriptor">ToPropertyDescriptor</a>(<i>trapResultObj</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>resultDesc</i>).</li>
+ <li>Call <a href="#sec-completepropertydescriptor">CompletePropertyDescriptor</a>(<i>resultDesc</i>,
+ <b>undefined</b>).</li>
+ <li>Let <i>valid</i> be <a href="#sec-iscompatiblepropertydescriptor">IsCompatiblePropertyDescriptor</a>
+ (<i>extensibleTarget</i>, <i>resultDesc</i>, <i>targetDesc</i>).</li>
+ <li>If <i>valid</i> is <b>false</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>If <i>resultDesc</i>.[[Configurable]] is <b>false</b>, then
+ <ol class="block">
+ <li>If <i>targetDesc</i> is <b>undefined</b> or <i>targetDesc</i>.[[Configurable]] is <b>true</b><i>,</i> then
+ <ol class="block">
+ <li>Throw a <b>TypeError</b> exception.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Return <i>resultDesc</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> [[GetOwnProperty]] for proxy objects enforces the following invariants:</p>
+
+ <ul>
+ <li>
+ <p>The result of [[GetOwnProperty]] must be either an Object or <b>undefined</b>.</p>
+ </li>
+
+ <li>
+ <p>A property cannot be reported as non-existent, if it exists as a non-configurable own property of the target
+ object.</p>
+ </li>
+
+ <li>
+ <p>A property cannot be reported as non-existent, if it exists as an own property of the target object and the target
+ object is not extensible.</p>
+ </li>
+
+ <li>
+ <p>A property cannot be reported as existent, if it does not exists as an own property of the target object and the
+ target object is not extensible.</p>
+ </li>
+
+ <li>
+ <p>A property cannot be reported as non-configurable, if it does not exists as an own property of the target object or
+ if it exists as a configurable own property of the target object.</p>
+ </li>
+
+ <li>
+ <p>The result of [[GetOwnProperty]] can be applied to the target object using [[DefineOwnProperty]] and will not throw
+ an exception.</p>
+ </li>
+ </ul>
+ </div>
+ </section>
+
+ <section id="sec-proxy-object-internal-methods-and-internal-slots-defineownproperty-p-desc">
+ <h1><span class="secnum" id="sec-9.5.6"><a
+ href="#sec-proxy-object-internal-methods-and-internal-slots-defineownproperty-p-desc"
+ title="link to this section">9.5.6</a></span> [[DefineOwnProperty]] (P, Desc)</h1>
+
+ <p>When the [[DefineOwnProperty]] internal method of an exotic Proxy object <var>O</var> is called with <a
+ href="#sec-object-type">property key</a> <var>P</var> and <a href="#sec-property-descriptor-specification-type">Property
+ Descriptor</a> <span class="nt">Desc</span>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ispropertykey">IsPropertyKey</a>(<i>P</i>) is
+ <b>true</b>.</li>
+ <li>Let <i>handler</i> be the value of the [[ProxyHandler]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>If <i>handler</i> is <b>null</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>target</i> be the value of the [[ProxyTarget]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>Let <i>trap</i> be <a href="#sec-getmethod">GetMethod</a>(<i>handler</i>, "<code>defineProperty</code>").</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>trap</i>).</li>
+ <li>If <i>trap</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>Return the result of calling the [[DefineOwnProperty]] internal method of <i>target</i> with arguments <i>P</i>
+ and <i>Desc</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>descObj</i> be <a href="#sec-frompropertydescriptor">FromPropertyDescriptor</a>(<i>Desc</i>).</li>
+ <li>NOTE If <span class="nt">Desc</span> was originally generated from an object using <a
+ href="#sec-topropertydescriptor">ToPropertyDescriptor</a>, then <var>descObj</var> will be that original object.</li>
+ <li>Let <i>trapResult</i> be the result of calling the [[Call]] internal method of <i>trap</i> with <i>handler</i> as the
+ <b>this</b> value and a new <a href="#sec-list-and-record-specification-type">List</a> containing <i>target</i>,
+ <i>P</i>, and <i>descObj</i>.</li>
+ <li>Let <i>booleanTrapResult</i> be <a href="#sec-toboolean">ToBoolean</a>(<i>trapResult</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>booleanTrapResult</i>).</li>
+ <li>If <i>booleanTrapResult</i> is <b>false</b>, then return <b>false</b>.</li>
+ <li>Let <i>targetDesc</i> be the result of calling the [[GetOwnProperty]] internal method of <i>target</i> with argument
+ <i>P</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>targetDesc</i>).</li>
+ <li>Let <i>extensibleTarget</i> be <a href="#sec-isextensible-o">IsExtensible</a>(<i>target</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>extensibleTarget</i>).</li>
+ <li>If <i>Desc</i> has a [[Configurable]] field and if <i>Desc</i>.[[Configurable]] is <b>false,</b> then
+ <ol class="block">
+ <li>Let <i>settingConfigFalse</i> be <b>true</b>.</li>
+ </ol>
+ </li>
+ <li>Else let <i>settingConfigFalse</i> be <b>false</b>.</li>
+ <li>If <i>targetDesc</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>If <i>extensibleTarget</i> is <b>false</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>If <i>settingConfigFalse</i> is <b>true</b>, then throw a <b>TypeError</b> exception.</li>
+ </ol>
+ </li>
+ <li>Else <i>targetDesc</i> is not <b>undefined<i>,</i></b>
+ <ol class="block">
+ <li>If <a href="#sec-iscompatiblepropertydescriptor">IsCompatiblePropertyDescriptor</a>(<i>extensibleTarget</i>,
+ <i>Desc</i> , <i>targetDesc</i>) is <b>false</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>If <i>settingConfigFalse</i> is <b>true</b> and <i>targetDesc</i>.[[Configurable]] is <b>true</b>, then throw a
+ <b>TypeError</b> exception.</li>
+ </ol>
+ </li>
+ <li>Return <b>true</b>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> [[DefineOwnProperty]] for proxy objects enforces the following invariants:</p>
+
+ <ul>
+ <li>
+ <p>A property cannot be added, if the target object is not extensible.</p>
+ </li>
+
+ <li>
+ <p>A property cannot be added as or modified to be non-configurable, if it does not exists as a non-configurable own
+ property of the target object.</p>
+ </li>
+
+ <li>
+ <p>A property may not be non-configurable, if is corresponding configurable property of the target object exists.</p>
+ </li>
+
+ <li>
+ <p>If a property has a corresponding target object property then apply the <a
+ href="#sec-property-descriptor-specification-type">Property Descriptor</a> of the property to the target object using
+ [[DefineOwnProperty]] will not throw an exception.</p>
+ </li>
+ </ul>
+ </div>
+ </section>
+
+ <section id="sec-proxy-object-internal-methods-and-internal-slots-hasproperty-p">
+ <h1><span class="secnum" id="sec-9.5.7"><a href="#sec-proxy-object-internal-methods-and-internal-slots-hasproperty-p"
+ title="link to this section">9.5.7</a></span> [[HasProperty]] (P)</h1>
+
+ <p>When the [[HasProperty]] internal method of an exotic Proxy object <var>O</var> is called with <a
+ href="#sec-object-type">property key</a> <var>P</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ispropertykey">IsPropertyKey</a>(<i>P</i>) is
+ <b>true</b>.</li>
+ <li>Let <i>handler</i> be the value of the [[ProxyHandler]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>If <i>handler</i> is <b>null</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>target</i> be the value of the [[ProxyTarget]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>Let <i>trap</i> be <a href="#sec-getmethod">GetMethod</a>(<i>handler</i>, "<code>has</code>").</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>trap</i>).</li>
+ <li>If <i>trap</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>Return the result of calling the [[HasProperty]] internal method of <i>target</i> with argument <i>P</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>trapResult</i> be the result of calling the [[Call]] internal method of <i>trap</i> with <i>handler</i> as the
+ <b>this</b> value and a new <a href="#sec-list-and-record-specification-type">List</a> containing <i>target</i> and
+ <i>P</i>.</li>
+ <li>Let <i>booleanTrapResult</i> be <a href="#sec-toboolean">ToBoolean</a>(<i>trapResult</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>booleanTrapResult</i>).</li>
+ <li>If <i>booleanTrapResult</i> is <b>false</b>, then
+ <ol class="block">
+ <li>Let <i>targetDesc</i> be the result of calling the [[GetOwnProperty]] internal method of <i>target</i> with
+ argument <i>P</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>targetDesc</i>).</li>
+ <li>If <i>targetDesc</i> is not <b>undefined</b>, then
+ <ol class="block">
+ <li>If <i>targetDesc</i>.[[Configurable]] is <b>false</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>extensibleTarget</i> be <a href="#sec-isextensible-o">IsExtensible</a>(<i>target</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>extensibleTarget</i>).</li>
+ <li>If <i>extensibleTarget</i> is <b>false</b>, then throw a <b>TypeError</b> exception.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Return <i>booleanTrapResult</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> [[HasProperty]] for proxy objects enforces the following invariants:</p>
+
+ <ul>
+ <li>
+ <p>A property cannot be reported as non-existent, if it exists as a non-configurable own property of the target
+ object.</p>
+ </li>
+
+ <li>
+ <p>A property cannot be reported as non-existent, if it exists as an own property of the target object and the target
+ object is not extensible.</p>
+ </li>
+ </ul>
+ </div>
+ </section>
+
+ <section id="sec-proxy-object-internal-methods-and-internal-slots-get-p-receiver">
+ <h1><span class="secnum" id="sec-9.5.8"><a href="#sec-proxy-object-internal-methods-and-internal-slots-get-p-receiver"
+ title="link to this section">9.5.8</a></span> [[Get]] (P, Receiver)</h1>
+
+ <p>When the [[Get]] internal method of an exotic Proxy object <var>O</var> is called with <a
+ href="#sec-object-type">property key</a> <var>P</var> and <a href="#sec-ecmascript-language-types">ECMAScript language
+ value</a> <span class="nt">Receiver</span> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ispropertykey">IsPropertyKey</a>(<i>P</i>) is
+ <b>true</b>.</li>
+ <li>Let <i>handler</i> be the value of the [[ProxyHandler]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>If <i>handler</i> is <b>null</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>target</i> be the value of the [[ProxyTarget]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>Let <i>trap</i> be <a href="#sec-getmethod">GetMethod</a>(<i>handler</i>, "<code>get</code>").</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>trap</i>).</li>
+ <li>If <i>trap</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>Return the result of calling the [[Get]] internal method of <i>target</i> with arguments <i>P</i> and
+ <i>Receiver</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>trapResult</i> be the result of calling the [[Call]] internal method of <i>trap</i> with <i>handler</i> as the
+ <b>this</b> value and a new <a href="#sec-list-and-record-specification-type">List</a> containing <i>target</i>,
+ <i>P</i>, and <i>Receiver</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>trapResult</i>).</li>
+ <li>Let <i>targetDesc</i> be the result of calling the [[GetOwnProperty]] internal method of <i>target</i> with argument
+ <i>P</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>targetDesc</i>).</li>
+ <li>If <i>targetDesc</i> is not <b>undefined</b>, then
+ <ol class="block">
+ <li>If <a href="#sec-isdatadescriptor">IsDataDescriptor</a>(<i>targetDesc</i>) and <i>targetDesc</i>.[[Configurable]]
+ is <b>false</b> and <i>targetDesc</i>.[[Writable]] is <b>false</b>, then
+ <ol class="block">
+ <li>If <a href="#sec-samevalue">SameValue</a>(<i>trapResult</i>, <i>targetDesc</i>.[[Value]]) is <b>false</b>,
+ then throw a <b>TypeError</b> exception.</li>
+ </ol>
+ </li>
+ <li>If <a href="#sec-isaccessordescriptor">IsAccessorDescriptor</a>(<i>targetDesc</i>) and
+ <i>targetDesc</i>.[[Configurable]] is <b>false</b> and <i>targetDesc</i>.[[Get]] is <b>undefined</b>, then
+ <ol class="block">
+ <li>If <i>trapResult</i> is not <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Return <i>trapResult</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> [[Get]] for proxy objects enforces the following invariants:</p>
+
+ <ul>
+ <li>
+ <p>The value reported for a property must be the same as the value of the corresponding target object property if the
+ target object property is a non-writable, non-configurable data property.</p>
+ </li>
+
+ <li>
+ <p>The value reported for a property must be <b>undefined</b> if the corresponding corresponding target object
+ property is non-configurable accessor property that has <b>undefined</b> as its [[Get]] attribute.</p>
+ </li>
+ </ul>
+ </div>
+ </section>
+
+ <section id="sec-proxy-object-internal-methods-and-internal-slots-set-p-v-receiver">
+ <h1><span class="secnum" id="sec-9.5.9"><a href="#sec-proxy-object-internal-methods-and-internal-slots-set-p-v-receiver"
+ title="link to this section">9.5.9</a></span> [[Set]] ( P, V, Receiver)</h1>
+
+ <p>When the [[Set]] internal method of an exotic Proxy object <var>O</var> is called with <a
+ href="#sec-object-type">property key</a> <var>P</var>, value <var>V</var>, and <a
+ href="#sec-ecmascript-language-types">ECMAScript language value</a> <span class="nt">Receiver</span>, the following steps
+ are taken:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ispropertykey">IsPropertyKey</a>(<i>P</i>) is
+ <b>true</b>.</li>
+ <li>Let <i>handler</i> be the value of the [[ProxyHandler]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>If <i>handler</i> is <b>null</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>target</i> be the value of the [[ProxyTarget]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>Let <i>trap</i> be <a href="#sec-getmethod">GetMethod</a>(<i>handler</i>, "<code>set</code>").</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>trap</i>).</li>
+ <li>If <i>trap</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>Return the result of calling the [[Set]] internal method of <i>target</i> with arguments <i>P</i>, <i>V</i>, and
+ <i>Receiver</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>trapResult</i> be the result of calling the [[Call]] internal method of <i>trap</i> with <i>handler</i> as the
+ <b>this</b> value and a new <a href="#sec-list-and-record-specification-type">List</a> containing <i>target</i>,
+ <i>P</i>, <i>V</i>, and <i>Receiver</i>.</li>
+ <li>Let <i>booleanTrapResult</i> be <a href="#sec-toboolean">ToBoolean</a>(<i>trapResult</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>booleanTrapResult</i>).</li>
+ <li>If <i>booleanTrapResult</i> is <b>false</b>, then return <b>false</b>.</li>
+ <li>Let <i>targetDesc</i> be the result of calling the [[GetOwnProperty]] internal method of <i>target</i> with argument
+ <i>P</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>targetDesc</i>).</li>
+ <li>If <i>targetDesc</i> is not <b>undefined</b>, then
+ <ol class="block">
+ <li>If <a href="#sec-isdatadescriptor">IsDataDescriptor</a>(<i>targetDesc</i>) and <i>targetDesc</i>.[[Configurable]]
+ is <b>false</b> and <i>targetDesc</i>.[[Writable]] is <b>false</b>, then
+ <ol class="block">
+ <li>If <a href="#sec-samevalue">SameValue</a>(<i>V</i>, <i>targetDesc</i>.[[Value]]) is <b>false</b>, then throw a
+ <b>TypeError</b> exception.</li>
+ </ol>
+ </li>
+ <li>If <a href="#sec-isaccessordescriptor">IsAccessorDescriptor</a>(<i>targetDesc</i>) and
+ <i>targetDesc</i>.[[Configurable]] is <b>false</b>, then
+ <ol class="block">
+ <li>If <i>targetDesc</i>.[[Set]] is <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Return <b>true</b>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> [[Set]] for proxy objects enforces the following invariants:</p>
+
+ <ul>
+ <li>
+ <p>Cannnot change the value of a property to be different from the value of the corresponding target object property
+ if the corresponding target object property is a non-writable, non-configurable data property.</p>
+ </li>
+
+ <li>
+ <p>Cannot set the value of a property if the corresponding corresponding target object property is a non-configurable
+ accessor property that has <b>undefined</b> as its [[Set]] attribute.</p>
+ </li>
+ </ul>
+ </div>
+ </section>
+
+ <section id="sec-proxy-object-internal-methods-and-internal-slots-delete-p">
+ <h1><span class="secnum" id="sec-9.5.10"><a href="#sec-proxy-object-internal-methods-and-internal-slots-delete-p"
+ title="link to this section">9.5.10</a></span> [[Delete]] (P)</h1>
+
+ <p>When the [[Delete]] internal method of an exotic Proxy object <var>O</var> is called with property name <var>P</var> the
+ following steps are taken:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ispropertykey">IsPropertyKey</a>(<i>P</i>) is
+ <b>true</b>.</li>
+ <li>Let <i>handler</i> be the value of the [[ProxyHandler]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>If <i>handler</i> is <b>null</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>target</i> be the value of the [[ProxyTarget]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>Let <i>trap</i> be <a href="#sec-getmethod">GetMethod</a>(<i>handler</i>, "<code>deleteProperty</code>").</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>trap</i>).</li>
+ <li>If <i>trap</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>Return the result of calling the [[Delete]] internal method of <i>target</i> with argument <i>P</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>trapResult</i> be the result of calling the [[Call]] internal method of <i>trap</i> with <i>handler</i> as the
+ <b>this</b> value and a new <a href="#sec-list-and-record-specification-type">List</a> containing <i>target</i> and
+ <i>P</i>.</li>
+ <li>Let <i>booleanTrapResult</i> be <a href="#sec-toboolean">ToBoolean</a>(<i>trapResult</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>booleanTrapResult</i>).</li>
+ <li>If <i>booleanTrapResult</i> is <b>false</b>, then return <b>false</b>.</li>
+ <li>Let <i>targetDesc</i> be the result of calling the [[GetOwnProperty]] internal method of <i>target</i> with argument
+ <i>P</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>targetDesc</i>).</li>
+ <li>If <i>targetDesc</i> is <b>undefined</b>, then return <b>true</b>.</li>
+ <li>If <i>targetDesc</i>.[[Configurable]] is <b>false</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Return <b>true</b>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> [[Delete]] for proxy objects enforces the following invariant:</p>
+
+ <ul>
+ <li>
+ <p>A property cannot be deleted, if it exists as a non-configurable own property of the target object.</p>
+ </li>
+ </ul>
+ </div>
+ </section>
+
+ <section id="sec-proxy-object-internal-methods-and-internal-slots-enumerate">
+ <h1><span class="secnum" id="sec-9.5.11"><a href="#sec-proxy-object-internal-methods-and-internal-slots-enumerate"
+ title="link to this section">9.5.11</a></span> [[Enumerate]] ()</h1>
+
+ <p>When the [[Enumerate]] internal method of an exotic Proxy object <var>O</var> is called the following steps are
+ taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>handler</i> be the value of the [[ProxyHandler]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>If <i>handler</i> is <b>null</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>target</i> be the value of the [[ProxyTarget]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>Let <i>trap</i> be <a href="#sec-getmethod">GetMethod</a>(<i>handler</i>, "<code>enumerate</code>").</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>trap</i>).</li>
+ <li>If <i>trap</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>Return the result of calling the [[Enumerate]] internal method of <i>target</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>trapResult</i> be the result of calling the [[Call]] internal method of <i>trap</i> with <i>handler</i> as the
+ <b>this</b> value and a new <a href="#sec-list-and-record-specification-type">List</a> containing <i>target</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>trapResult</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>trapResult</i>) is not Object, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>Return <i>trapResult</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> [[Enumerate]] for proxy objects enforces the following invariants:</p>
+
+ <ul>
+ <li>The result of [[Enumerate]] must be an Object.</li>
+ </ul>
+ </div>
+ </section>
+
+ <section id="sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys">
+ <h1><span class="secnum" id="sec-9.5.12"><a href="#sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys"
+ title="link to this section">9.5.12</a></span> [[OwnPropertyKeys]] ( )</h1>
+
+ <p>When the [[OwnPropertyKeys]] internal method of an exotic Proxy object <var>O</var> is called the following steps are
+ taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>handler</i> be the value of the [[ProxyHandler]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>If <i>handler</i> is <b>null</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>target</i> be the value of the [[ProxyTarget]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>Let <i>trap</i> be <a href="#sec-getmethod">GetMethod</a>(<i>handler</i>, "<code>ownKeys</code>").</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>trap</i>).</li>
+ <li>If <i>trap</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>Return the result of calling the [[OwnPropertyKeys]] internal method of <i>target</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>trapResult</i> be the result of calling the [[Call]] internal method of <i>trap</i> with <i>handler</i> as the
+ <b>this</b> value and a new <a href="#sec-list-and-record-specification-type">List</a> containing <i>target</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>trapResult</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>trapResult</i>) is not Object, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>TODO: we may need to add a lot of additional invariant checking here according to the wiki spec. But maybe it really
+ isn’t necessary</li>
+ <li>Return <i>trapResult</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> [[OwnPropertyKeys]] for proxy objects enforces the following invariants:</p>
+
+ <ul>
+ <li>The result of [[OwnPropertyKeys]] must be an Object.</li>
+ </ul>
+ </div>
+ </section>
+
+ <section id="sec-proxy-object-internal-methods-and-internal-slots-call-thisargument-argumentslist">
+ <h1><span class="secnum" id="sec-9.5.13"><a
+ href="#sec-proxy-object-internal-methods-and-internal-slots-call-thisargument-argumentslist"
+ title="link to this section">9.5.13</a></span> [[Call]] (thisArgument, argumentsList)</h1>
+
+ <p>The [[Call]] internal method of an exotic Proxy object <var>O</var> is called with parameters <var>thisArgument</var> and
+ <var>argumentsList</var>, a <a href="#sec-list-and-record-specification-type">List</a> of <a
+ href="#sec-ecmascript-language-types">ECMAScript language values</a>. The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>handler</i> be the value of the [[ProxyHandler]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>If <i>handler</i> is <b>null</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>target</i> be the value of the [[ProxyTarget]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>Let <i>trap</i> be <a href="#sec-getmethod">GetMethod</a>(<i>handler</i>, "<code>apply</code>").</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>trap</i>).</li>
+ <li>If <i>trap</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>Return the result of calling the [[Call]] internal method of <i>target</i> with arguments <i>thisArgument</i> and
+ <i>argumentsList</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>argArray</i> be <a href="#sec-createarrayfromlist">CreateArrayFromList</a>(<i>argumentsList</i>).</li>
+ <li>Return the result of calling the [[Call]] internal method of <i>trap</i> with <i>handler</i> as the <b>this</b> value
+ and a new <a href="#sec-list-and-record-specification-type">List</a> containing <i>target</i>, <i>thisArgument</i>,
+ and <i>argArray</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> A Proxy exotic object only has a [[Call]] internal method if the initial value of its
+ [[ProxyTarget]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is an object that has a
+ [[Call]] internal method.</p>
+ </div>
+ </section>
+
+ <section id="sec-construct-internal-method">
+ <h1><span class="secnum" id="sec-9.5.14"><a href="#sec-construct-internal-method"
+ title="link to this section">9.5.14</a></span> [[Construct]] Internal Method</h1>
+
+ <p>The [[Construct]] internal method of an exotic Proxy object <var>O</var> is called with a single parameter
+ <var>argumentsList</var> which is a possibly empty <a href="#sec-list-and-record-specification-type">List</a> of <a
+ href="#sec-ecmascript-language-types">ECMAScript language values</a>. The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>handler</i> be the value of the [[ProxyHandler]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>If <i>handler</i> is <b>null</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>target</i> be the value of the [[ProxyTarget]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>Let <i>trap</i> be <a href="#sec-getmethod">GetMethod</a>(<i>handler</i>, "<code>construct</code>").</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>trap</i>).</li>
+ <li>If <i>trap</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>If <i>target</i> does not have a [[Construct]] internal method, then throw a <b>TypeError</b> exception.</li>
+ <li>Return the result of calling the [[Construct]] internal method of <i>target</i> with argument
+ <i>argumentsList</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>argArray</i> be <a href="#sec-createarrayfromlist">CreateArrayFromList</a>(<i>argumentsList</i>).</li>
+ <li>Let <i>newObj</i> be the result of calling <i>trap</i> with <i>handler</i> as the <b>this</b> value and a new <a
+ href="#sec-list-and-record-specification-type">List</a> containing <i>target</i> and <i>argArray</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>newObj</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>newObj</i>) is not Object, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>Return <i>newObj</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> A Proxy exotic object only has a [[Construct]] internal method if the initial value of
+ its [[ProxyTarget]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is an object that has a
+ [[Construct]] internal method.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 2</span> [[Construct]]] for proxy objects enforces the following invariants:</p>
+
+ <ul>
+ <li>The result of [[Construct]] must be an Object.</li>
+ </ul>
+ </div>
+ </section>
+
+ <section id="sec-proxycreate">
+ <h1><span class="secnum" id="sec-9.5.15"><a href="#sec-proxycreate" title="link to this section">9.5.15</a></span>
+ ProxyCreate(target, handler) Abstract Operation</h1>
+
+ <p>The abstract operation ProxyCreate with arguments <var>target</var> and <var>handler</var> is used to specify the
+ creation of new Proxy exotic objects. It performs the following steps:</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>target</i>) is not Object, throw a <b>TypeError</b>
+ Exception.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>handler</i>) is not Object, throw a <b>TypeError</b>
+ Exception.</li>
+ <li>Let <i>P</i> be a newly created object.</li>
+ <li>Set <i>P</i>’s essential internal methods to the definitions specified in <a
+ href="#sec-proxy-object-internal-methods-and-internal-slots">9.5</a>.</li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>target</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>Set the [[Call]] internal method of <i>P</i> as specified in <a
+ href="#sec-proxy-object-internal-methods-and-internal-slots-call-thisargument-argumentslist">9.5.13</a>.</li>
+ <li>If <i>target</i> has a [[Construct]] internal method, then
+ <ol class="block">
+ <li>Set the [[Construct]] internal method of <i>P</i> as specified in <a
+ href="#sec-construct-internal-method">9.5.14</a>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Set the [[ProxyTarget]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>P</i> to
+ <i>target</i>.</li>
+ <li>Set the [[ProxyHandler]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>P</i> to
+ <i>handler</i>.</li>
+ <li>Return <i>P</i>.</li>
+ </ol>
+ </section>
+ </section>
+</section>
+
+<section id="sec-ecmascript-language-source-code">
+ <div class="front">
+ <h1><span class="secnum" id="sec-10"><a href="#sec-ecmascript-language-source-code" title="link to this section">10</a></span>
+ ECMAScript Language: Source Code</h1>
+ </div>
+
+ <section id="sec-source-text">
+ <div class="front">
+ <h1><span class="secnum" id="sec-10.1"><a href="#sec-source-text" title="link to this section">10.1</a></span> Source
+ Text</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">SourceCharacter</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="gprose">any Unicode code point</span></div>
+ </div>
+
+ <p>The ECMAScript code is expressed using Unicode, version 5.1 or later. ECMAScript source text is a sequence of code
+ points. All Unicode code point values from U+0000 to U+10FFFF, including surrogate code points, may occur in source text
+ where permitted by the ECMAScript grammars. The actual encodings used to store and interchange ECMAScript source text is not
+ relevant to this specification. Regardless of the external source text encoding, a conforming ECMAScript implementation
+ processes the source text as if it was an equivalent sequence of <span class="nt">SourceCharacter</span> values. Each <span
+ class="nt">SourceCharacter</span> being a Unicode code point. Conforming ECMAScript implementations are not required to
+ perform any normalisation of text, or behave as though they were performing normalisation of text.</p>
+
+ <p>The components of a combining character sequence are treated as individual Unicode code points even though a user might
+ think of the whole sequence as a single character.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> In string literals, regular expression literals, template literals and identifiers, any
+ Unicode code point may also be expressed using Unicode escape sequences that explicitly express a code point’s
+ numeric value. Within a comment, such an escape sequence is effectively ignored as part of the comment.</p>
+
+ <p>ECMAScript differs from the Java programming language in the behaviour of Unicode escape sequences. In a Java program,
+ if the Unicode escape sequence <code>\u000A</code>, for example, occurs within a single-line comment, it is interpreted as
+ a line terminator (Unicode character <code>000A</code> is line feed) and therefore the next character is not part of the
+ comment. Similarly, if the Unicode escape sequence <code>\u000A</code> occurs within a string literal in a Java program,
+ it is likewise interpreted as a line terminator, which is not allowed within a string literal—one must write
+ <code>\n</code> instead of <code>\u000A</code> to cause a line feed to be part of the string value of a string literal. In
+ an ECMAScript program, a Unicode escape sequence occurring within a comment is never interpreted and therefore cannot
+ contribute to termination of the comment. Similarly, a Unicode escape sequence occurring within a string literal in an
+ ECMAScript program always contributes a Unicode code unit or code point (depending upon the first of the escape) to the
+ literal and is never interpreted as a line terminator or as a quote mark that might terminate the string literal.</p>
+ </div>
+ </div>
+
+ <section id="sec-static-semantics-utf-16encoding">
+ <h1><span class="secnum" id="sec-10.1.1"><a href="#sec-static-semantics-utf-16encoding"
+ title="link to this section">10.1.1</a></span> Static Semantics: <i>UTF-16Encoding</i></h1>
+
+ <p>The UTF-16Encoding of a numeric code point value, <var>cp</var>, is determined as follows:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: 0 ≤ <i>cp</i> ≤ 0x10FFFF.</li>
+ <li>If <i>cp</i> ≤ 65535, then return <i>cp</i>.</li>
+ <li>Let <i>cu1</i> be <a href="#sec-algorithm-conventions">floor</a>((<i>cp</i> – 65536) / 1024) + 0xD800.</li>
+ <li>Let <i>cu2</i> be ((<i>cp</i> – 65536) <a href="#sec-algorithm-conventions">modulo</a> 1024) + 0xDC00.</li>
+ <li>Return the code unit sequence consisting of <i>cu1</i> followed by <i>cu2</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-utf16decode">
+ <h1><span class="secnum" id="sec-10.1.2"><a href="#sec-utf16decode" title="link to this section">10.1.2</a></span> Static
+ Semantics: UTF16Decode(lead, trail)</h1>
+
+ <p>Two code units, <var>lead</var> and <var>trail</var>, that form a UTF-16 surrogate pair are converted to a code point by
+ performing the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: 0xD800 ≤ <i>lead</i> ≤ 0xDBFF and 0xDC00 ≤ <i>trail</i> ≤
+ 0xDFFF.</li>
+ <li>Let <i>cp</i> be (<i>lead</i>–0xD800)×1024+( <i>trail</i>–0xDC00)+0x10000..</li>
+ <li>Return the code point <i>cp</i>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-types-of-source-code">
+ <div class="front">
+ <h1><span class="secnum" id="sec-10.2"><a href="#sec-types-of-source-code" title="link to this section">10.2</a></span>
+ Types of Source Code</h1>
+
+ <p>There are four types of ECMAScript code:</p>
+
+ <ul>
+ <li>
+ <p><i>Global code</i> is source text that is treated as an ECMAScript <i>Script</i>. The global code of a particular
+ <i>Script</i> does not include any source text that is parsed as part of a <i>FunctionBody</i>, <i>GeneratorBody</i>,
+ <i>ConciseBody</i>, <i>ClassBody</i>, or <i>ModuleBody</i>.</p>
+ </li>
+
+ <li>
+ <p><i>Eval code</i> is the source text supplied to the built-in <code>eval</code> function. More precisely, if the
+ parameter to the built-in <code>eval</code> function is a String, it is treated as an ECMAScript <i>Script</i>. The eval
+ code for a particular invocation of <code>eval</code> is the global code portion of that <i>Script</i>.</p>
+ </li>
+
+ <li>
+ <p><i>Function code</i> is source text that is parsed to supply the value of the [[Code]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> (<a
+ href="#sec-ordinarycreatefromconstructor">see 9.1.14</a>) of function and generator objects. It includes the code that
+ defines and initializes the formal parameters of the function. The <i>function code</i> of a particular function or
+ generator does not include any source text that is parsed as the function code of a nested <i>FunctionBody</i>,
+ <i>GeneratorBody</i>, <i>ConciseBody</i>, or <i>ClassBody</i>.</p>
+ </li>
+
+ <li>
+ <p><i>Module code</i> is source text that is code that is provided as a <i>ModuleBody</i>. It is the code that is
+ directly evaluated when a module is initialized. The module code of a particular module does not include any source text
+ that is parsed as part of a nested <i>FunctionBody</i>, <i>GeneratorBody</i>, <i>ConciseBody</i>, <i>ClassBody</i>, or
+ <i>ModuleBody</i>.</p>
+ </li>
+ </ul>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Function code is generally provided as the bodies of Function Definitions (<a
+ href="#sec-function-definitions">14.1</a>), Arrow Function Definitions (<a
+ href="#sec-arrow-function-definitions">14.2</a>), Method Definitions (<a href="#sec-method-definitions">14.3</a>) and
+ Generator Definitions (<a href="#sec-generator-function-definitions">14.4</a>). Function code is also derived from the
+ last argument to the Function constructor (<a href="#sec-function-p1-p2-pn-body">19.2.1.1</a>) and the GeneratorFunction
+ constructor (<a href="#sec-generatorfunction">25.2.1.1</a>).</p>
+ </div>
+ </div>
+
+ <section id="sec-strict-mode-code">
+ <h1><span class="secnum" id="sec-10.2.1"><a href="#sec-strict-mode-code" title="link to this section">10.2.1</a></span>
+ Strict Mode Code</h1>
+
+ <p>An ECMAScript <span class="nt">Script</span> syntactic unit may be processed using either unrestricted or strict mode
+ syntax and semantics. When processed using strict mode the four types of ECMAScript code are referred to as module code,
+ strict global code, strict eval code, and strict function code. Code is interpreted as strict mode code in the following
+ situations:</p>
+
+ <ul>
+ <li>
+ <p>Global code is strict global code if it begins with a <a
+ href="#sec-directive-prologues-and-the-use-strict-directive">Directive Prologue</a> that contains a <a
+ href="#sec-directive-prologues-and-the-use-strict-directive">Use Strict Directive</a> (<a
+ href="#sec-directive-prologues-and-the-use-strict-directive">see 14.1.1</a>).</p>
+ </li>
+
+ <li>
+ <p>Module code is always strict code.</p>
+ </li>
+
+ <li>
+ <p>All parts of a <span class="nt">ClassDeclaration</span> or a <span class="nt">ClassExpression</span> are strict
+ code.</p>
+ </li>
+
+ <li>
+ <p>Eval code is strict eval code if it begins with a <a
+ href="#sec-directive-prologues-and-the-use-strict-directive">Directive Prologue</a> that contains a <a
+ href="#sec-directive-prologues-and-the-use-strict-directive">Use Strict Directive</a> or if the call to eval is a direct
+ call (<a href="#sec-direct-call-to-eval">see 18.2.1.1</a>) to the eval function that is contained in strict mode
+ code.</p>
+ </li>
+
+ <li>
+ <p>Function code that is part of a <span class="nt">FunctionDeclaration</span>, <span
+ class="nt">FunctionExpression</span>, <span class="nt">GeneratorDeclaration</span>, <span
+ class="nt">GeneratorExpression</span>, <span class="nt">MethodDefinition</span>, or <span
+ class="nt">ArrowFunction</span> is strict function code if its <span class="nt">GeneratorDeclaration</span>, <span
+ class="nt">GeneratorExpression</span>, <span class="nt">MethodDefinition</span>, or <span
+ class="nt">ArrowFunction</span> is contained in strict mode code or if its <span class="nt">FunctionBody</span> begins
+ with a <a href="#sec-directive-prologues-and-the-use-strict-directive">Directive Prologue</a> that contains a <a
+ href="#sec-directive-prologues-and-the-use-strict-directive">Use Strict Directive</a>.</p>
+ </li>
+
+ <li>
+ <p>Function code that is supplied as the last argument to the built-in Function constructor is strict function code if
+ the last argument is a String that when processed as a <span class="nt">FunctionBody</span> begins with a <a
+ href="#sec-directive-prologues-and-the-use-strict-directive">Directive Prologue</a> that contains a <a
+ href="#sec-directive-prologues-and-the-use-strict-directive">Use Strict Directive</a>.</p>
+ </li>
+ </ul>
+ </section>
+
+ <section id="sec-non-ecmascript-functions">
+ <h1><span class="secnum" id="sec-10.2.2"><a href="#sec-non-ecmascript-functions"
+ title="link to this section">10.2.2</a></span> Non-ECMAScript Functions</h1>
+
+ <p>An ECMAScript implementation may support the evaluation of exotic function objects whose evaluative behaviour is
+ expressed in some implementation defined form of executable code other than via ECMAScript code. Whether a function object
+ is an ECMAScript code function or a non-ECMAScript function is not semantically observable from the perspective of an
+ ECMAScript code function that calls or is called by such a non-ECMAScript function.</p>
+ </section>
+ </section>
+</section>
+
+<section id="sec-ecmascript-language-lexical-grammar">
+ <div class="front">
+ <h1><span class="secnum" id="sec-11"><a href="#sec-ecmascript-language-lexical-grammar"
+ title="link to this section">11</a></span> ECMAScript Language: Lexical Grammar</h1>
+
+ <p>The source text of an ECMAScript script is first converted into a sequence of input elements, which are tokens, line
+ terminators, comments, or white space. The source text is scanned from left to right, repeatedly taking the longest possible
+ sequence of characters as the next input element.</p>
+
+ <p>There are several situations where the identification of lexical input elements is sensitive to the syntactic grammar
+ context that is consuming the input elements. This requires multiple goal symbols for the lexical grammar. The <span
+ class="nt">InputElementDiv</span> goal symbol is the default goal symbol and is used in those syntactic grammar contexts where
+ a leading division (<code>/</code>) or division-assignment (<code>/=</code>) operator is permitted. The <span
+ class="nt">InputElementRegExp</span> goal symbol is used in all syntactic grammar contexts where a <span
+ class="nt">RegularExpressionLiteral</span> is permitted. The <span class="nt">InputElementTemplateTail</span> goal is used in
+ syntactic grammar contexts where a <span class="nt">TemplateLiteral</span> logically continues after a substitution
+ element.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> There are no syntactic grammar contexts where both a leading division or
+ division-assignment, and a leading <i>RegularExpressionLiteral</i> are permitted. This is not affected by semicolon
+ insertion (<a href="#sec-automatic-semicolon-insertion">see 11.9</a>); in examples such as the following:</p>
+
+ <pre>a = b<br>/hi/g.exec(c).map(d);</pre>
+
+ <p>where the first non-whitespace, non-comment character after a <i>LineTerminator</i> is slash (<code>/</code>) and the
+ syntactic context allows division or division-assignment, no semicolon is inserted at the <i>LineTerminator</i>. That is,
+ the above example is interpreted in the same way as:</p>
+
+ <pre>a = b / hi / g.exec(c).map(d);</pre>
+ </div>
+
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">InputElementDiv</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">WhiteSpace</span></div>
+ <div class="rhs"><span class="nt">LineTerminator</span></div>
+ <div class="rhs"><span class="nt">Comment</span></div>
+ <div class="rhs"><span class="nt">Token</span></div>
+ <div class="rhs"><span class="nt">DivPunctuator</span></div>
+ <div class="rhs"><span class="nt">RightBracePunctuator</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">InputElementRegExp</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">WhiteSpace</span></div>
+ <div class="rhs"><span class="nt">LineTerminator</span></div>
+ <div class="rhs"><span class="nt">Comment</span></div>
+ <div class="rhs"><span class="nt">Token</span></div>
+ <div class="rhs"><span class="nt">RightBracePunctuator</span></div>
+ <div class="rhs"><span class="nt">RegularExpressionLiteral</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">InputElementTemplateTail</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">WhiteSpace</span></div>
+ <div class="rhs"><span class="nt">LineTerminator</span></div>
+ <div class="rhs"><span class="nt">Comment</span></div>
+ <div class="rhs"><span class="nt">Token</span></div>
+ <div class="rhs"><span class="nt">DivPunctuator</span></div>
+ <div class="rhs"><span class="nt">TemplateSubstitutionTail</span></div>
+ </div>
+ </div>
+
+ <section id="sec-unicode-format-control-characters">
+ <h1><span class="secnum" id="sec-11.1"><a href="#sec-unicode-format-control-characters"
+ title="link to this section">11.1</a></span> Unicode Format-Control Characters</h1>
+
+ <p>The Unicode format-control characters (i.e., the characters in category “Cf” in the Unicode Character Database
+ such as left-to-right mark or right-to-left mark) are control codes used to control the formatting of a range of text in the
+ absence of higher-level protocols for this (such as mark-up languages).</p>
+
+ <p>It is useful to allow format-control characters in source text to facilitate editing and display. All format control
+ characters may be used within comments, and within string literals, template literals, and regular expression literals.</p>
+
+ <p>U+200C <span style="font-family: Times New Roman">(</span>Zero width non-joiner<span style="font-family: Times New
+ Roman">)</span> and U+200D <span style="font-family: Times New Roman">(</span>Zero width joiner<span style="font-family: Times
+ New Roman">)</span> are format-control characters that are used to make necessary distinctions when forming words or phrases
+ in certain languages. In ECMAScript source text, <span style="font-family: Times New Roman"><ZWNJ></span> and <span
+ style="font-family: Times New Roman"><ZWJ></span> may also be used in an identifier after the first character.</p>
+
+ <p>U+FEFF <span style="font-family: Times New Roman">(</span>Byte Order Mark<span style="font-family: Times New
+ Roman">)</span> is a format-control character used primarily at the start of a text to mark it as Unicode and to allow
+ detection of the text's encoding and byte order. <span style="font-family: Times New Roman"><BOM></span> characters
+ intended for this purpose can sometimes also appear after the start of a text, for example as a result of concatenating files.
+ <BOM> characters are treated as white space characters (see 0).</p>
+
+ <p>The special treatment of certain format-control characters outside of comments, string literals, and regular expression
+ literals is summarized in <a href="#table-29">Table 29</a>.</p>
+
+ <figure>
+ <figcaption><span id="table-29">Table 29</span> — Format-Control Character Usage</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-top: 2px solid #000000">Code Point</th>
+ <th style="border-bottom: 1px solid #000000; border-top: 2px solid #000000">Name</th>
+ <th style="border-bottom: 1px solid #000000; border-top: 2px solid #000000">Abbreviation</th>
+ <th style="border-bottom: 1px solid #000000; border-right: 1px solid #000000; border-top: 2px solid #000000">Usage</th>
+ </tr>
+ <tr>
+ <td style="border-left: 1px solid #000000"><code>U+200C</code></td>
+ <td>Zero width non-joiner</td>
+ <td><ZWNJ></td>
+ <td style="border-right: 1px solid #000000"><i>IdentifierPart</i></td>
+ </tr>
+ <tr>
+ <td style="border-left: 1px solid #000000"><code>U+200D</code></td>
+ <td>Zero width joiner</td>
+ <td><ZWJ></td>
+ <td style="border-right: 1px solid #000000"><i>IdentifierPart</i></td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 2px solid #000000; border-left: 1px solid #000000"><code>U+FEFF</code></td>
+ <td style="border-bottom: 2px solid #000000">Byte Order Mark</td>
+ <td style="border-bottom: 2px solid #000000"><BOM></td>
+ <td style="border-bottom: 2px solid #000000; border-right: 1px solid #000000"><i>Whitespace</i></td>
+ </tr>
+ </table>
+ </figure>
+ </section>
+
+ <section id="sec-white-space">
+ <h1><span class="secnum" id="sec-11.2"><a href="#sec-white-space" title="link to this section">11.2</a></span> White
+ Space</h1>
+
+ <p>White space characters are used to improve source text readability and to separate tokens (indivisible lexical units) from
+ each other, but are otherwise insignificant. White space characters may occur between any two tokens and at the start or end
+ of input. White space characters may occur within a <span class="nt">StringLiteral</span>, a <span
+ class="nt">RegularExpressionLiteral</span>, a <span class="nt">Template</span>, or a <span
+ class="nt">TemplateSubstitutionTail</span> where they are considered significant characters forming part of a literal value.
+ They may also occur within a <span class="nt">Comment</span>, but cannot appear within any other kind of token.</p>
+
+ <p>The ECMAScript white space characters are listed in <a href="#table-30">Table 30</a>.</p>
+
+ <figure>
+ <figcaption><span id="table-30">Table 30</span> — Whitespace Characters</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-top: 2px solid #000000">Code Point</th>
+ <th style="border-bottom: 1px solid #000000; border-top: 2px solid #000000">Name</th>
+ <th style="border-bottom: 1px solid #000000; border-right: 1px solid #000000; border-top: 2px solid #000000">Abbreviation</th>
+ </tr>
+ <tr>
+ <td style="border-left: 1px solid #000000"><code>U+0009</code></td>
+ <td>Character Tabulation</td>
+ <td style="border-right: 1px solid #000000"><TAB></td>
+ </tr>
+ <tr>
+ <td style="border-left: 1px solid #000000"><code>U+000B</code></td>
+ <td>LINE TABULATION</td>
+ <td style="border-right: 1px solid #000000"><VT></td>
+ </tr>
+ <tr>
+ <td style="border-left: 1px solid #000000"><code>U+000C</code></td>
+ <td>Form Feed</td>
+ <td style="border-right: 1px solid #000000"><FF></td>
+ </tr>
+ <tr>
+ <td style="border-left: 1px solid #000000"><code>U+0020</code></td>
+ <td>Space</td>
+ <td style="border-right: 1px solid #000000"><SP></td>
+ </tr>
+ <tr>
+ <td style="border-left: 1px solid #000000"><code>U+00A0</code></td>
+ <td>No-break space</td>
+ <td style="border-right: 1px solid #000000"><NBSP></td>
+ </tr>
+ <tr>
+ <td style="border-left: 1px solid #000000"><code>U+FEFF</code></td>
+ <td>Byte Order Mark</td>
+ <td style="border-right: 1px solid #000000"><BOM></td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 2px solid #000000; border-left: 1px solid #000000">Other category “Zs”</td>
+ <td style="border-bottom: 2px solid #000000">Any other Unicode “Separator, Space” code point</td>
+ <td style="border-bottom: 2px solid #000000; border-right: 1px solid #000000"><USP></td>
+ </tr>
+ </table>
+ </figure>
+
+ <p>ECMAScript implementations must recognize as <span class="nt">Whitespace</span> code points listed in the “Separator
+ Space” (Zs) category by Unicode 5.1. ECMAScript implementations may also recognize as <span class="nt">Whitespace</span>
+ additional category Zs code points from subsequent editions of the Unicode Standard.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Other than for the code points listed in <a href="#table-30">Table 30</a>, ECMAScript
+ <i>Whitespace</i> intentionally excludes all code points that have the Unicode “White_Space” property but which
+ are not classified in category “Zs”.</p>
+ </div>
+
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">WhiteSpace</span> <span class="geq">::</span></div>
+ <div class="rhs"><TAB></div>
+ <div class="rhs"><VT></div>
+ <div class="rhs"><FF></div>
+ <div class="rhs"><SP></div>
+ <div class="rhs"><NBSP></div>
+ <div class="rhs"><BOM></div>
+ <div class="rhs"><USP></div>
+ </div>
+ </section>
+
+ <section id="sec-line-terminators">
+ <h1><span class="secnum" id="sec-11.3"><a href="#sec-line-terminators" title="link to this section">11.3</a></span> Line
+ Terminators</h1>
+
+ <p>Like white space characters, line terminator characters are used to improve source text readability and to separate tokens
+ (indivisible lexical units) from each other. However, unlike white space characters, line terminators have some influence over
+ the behaviour of the syntactic grammar. In general, line terminators may occur between any two tokens, but there are a few
+ places where they are forbidden by the syntactic grammar. Line terminators also affect the process of <a
+ href="#sec-automatic-semicolon-insertion">automatic semicolon insertion</a> (<a
+ href="#sec-automatic-semicolon-insertion">11.9</a>). A line terminator cannot occur within any token except a <span
+ class="nt">StringLiteral</span>, <span class="nt">Template</span>, or <span class="nt">TemplateSubstitutionTail</span>. Line
+ terminators may only occur within a <span class="nt">StringLiteral</span> token as part of a <span
+ class="nt">LineContinuation</span>.</p>
+
+ <p>A line terminator can occur within a <span class="nt">MultiLineComment</span> (<a href="#sec-comments">11.4</a>) but cannot
+ occur within a <span class="nt">SingleLineComment</span>.</p>
+
+ <p>Line terminators are included in the set of white space characters that are matched by the <code>\s</code> class in regular
+ expressions.</p>
+
+ <p>The ECMAScript line terminator characters are listed in <a href="#table-31">Table 31</a>.</p>
+
+ <figure>
+ <figcaption><span id="table-31">Table 31</span> — Line Terminator Characters</figcaption>
+ <table class="real-table">
+ <tr>
+ <th>Code Point</th>
+ <th>Name</th>
+ <th>Abbreviation</th>
+ </tr>
+ <tr>
+ <td><code>U+000A</code></td>
+ <td>Line Feed</td>
+ <td><LF></td>
+ </tr>
+ <tr>
+ <td><code>U+000D</code></td>
+ <td>Carriage Return</td>
+ <td><CR></td>
+ </tr>
+ <tr>
+ <td><code>U+2028</code></td>
+ <td>Line separator</td>
+ <td><LS></td>
+ </tr>
+ <tr>
+ <td><code>U+2029</code></td>
+ <td>Paragraph separator</td>
+ <td><PS></td>
+ </tr>
+ </table>
+ </figure>
+
+ <p>Only the Unicode code points in <a href="#table-31">Table 31</a> are treated as line terminators. Other new line or line
+ breaking Unicode code points are not treated as line terminators but are treated as white space if they meet the requirements
+ listed in <a href="#table-30">Table 30</a>. The sequence <CR><LF> is commonly used as a line terminator. It should
+ be considered a single <span class="nt">SourceCharacter</span> for the purpose of reporting line numbers.</p>
+
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">LineTerminator</span> <span class="geq">::</span></div>
+ <div class="rhs"><LF></div>
+ <div class="rhs"><CR></div>
+ <div class="rhs"><LS></div>
+ <div class="rhs"><PS></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">LineTerminatorSequence</span> <span class="geq">::</span></div>
+ <div class="rhs"><LF></div>
+ <div class="rhs"><CR> <span class="grhsannot">[lookahead ∉ <LF> ]</span></div>
+ <div class="rhs"><LS></div>
+ <div class="rhs"><PS></div>
+ <div class="rhs"><CR> <LF></div>
+ </div>
+ </section>
+
+ <section id="sec-comments">
+ <h1><span class="secnum" id="sec-11.4"><a href="#sec-comments" title="link to this section">11.4</a></span> Comments</h1>
+
+ <p>Comments can be either single or multi-line. Multi-line comments cannot nest.</p>
+
+ <p>Because a single-line comment can contain any Unicode code point except a <span class="nt">LineTerminator</span> character,
+ and because of the general rule that a token is always as long as possible, a single-line comment always consists of all
+ characters from the <code>//</code> marker to the end of the line. However, the <span class="nt">LineTerminator</span> at the
+ end of the line is not considered to be part of the single-line comment; it is recognized separately by the lexical grammar
+ and becomes part of the stream of input elements for the syntactic grammar. This point is very important, because it implies
+ that the presence or absence of single-line comments does not affect the process of <a
+ href="#sec-automatic-semicolon-insertion">automatic semicolon insertion</a> (<a href="#sec-automatic-semicolon-insertion">see
+ 11.9</a>).</p>
+
+ <p>Comments behave like white space and are discarded except that, if a <span class="nt">MultiLineComment</span> contains a
+ line terminator character, then the entire comment is considered to be a <span class="nt">LineTerminator</span> for purposes
+ of parsing by the syntactic grammar.</p>
+
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">Comment</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">MultiLineComment</span></div>
+ <div class="rhs"><span class="nt">SingleLineComment</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">MultiLineComment</span> <span class="geq">::</span></div>
+ <div class="rhs"><code class="t">/*</code> <span class="nt">MultiLineCommentChars</span><sub>opt</sub> <code class="t">*/</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">MultiLineCommentChars</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">MultiLineNotAsteriskChar</span> <span class="nt">MultiLineCommentChars</span><sub>opt</sub></div>
+ <div class="rhs"><code class="t">*</code> <span class="nt">PostAsteriskCommentChars</span><sub>opt</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">PostAsteriskCommentChars</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">MultiLineNotForwardSlashOrAsteriskChar</span> <span class="nt">MultiLineCommentChars</span><sub>opt</sub></div>
+ <div class="rhs"><code class="t">*</code> <span class="nt">PostAsteriskCommentChars</span><sub>opt</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">MultiLineNotAsteriskChar</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">SourceCharacter</span> <span class="grhsmod">but not</span> <code class="t">*</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">MultiLineNotForwardSlashOrAsteriskChar</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">SourceCharacter</span> <span class="grhsmod">but not one of</span> <code class="t">/</code> <span class="grhsmod">or</span> <code class="t">*</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">SingleLineComment</span> <span class="geq">::</span></div>
+ <div class="rhs"><code class="t">//</code> <span class="nt">SingleLineCommentChars</span><sub>opt</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">SingleLineCommentChars</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">SingleLineCommentChar</span> <span class="nt">SingleLineCommentChars</span><sub>opt</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">SingleLineCommentChar</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">SourceCharacter</span> <span class="grhsmod">but not</span> <span class="nt">LineTerminator</span></div>
+ </div>
+ </section>
+
+ <section id="sec-tokens">
+ <h1><span class="secnum" id="sec-11.5"><a href="#sec-tokens" title="link to this section">11.5</a></span> Tokens</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">Token</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">IdentifierName</span></div>
+ <div class="rhs"><span class="nt">Punctuator</span></div>
+ <div class="rhs"><span class="nt">NumericLiteral</span></div>
+ <div class="rhs"><span class="nt">StringLiteral</span></div>
+ <div class="rhs"><span class="nt">Template</span></div>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <i>DivPunctuator</i>, <i>RegularExpressionLiteral</i>, <i>RightBracePunctuator,</i> and
+ <i>TemplateSubstitutionTail</i> productions define tokens, but are not included in the <i>Token</i> production.</p>
+ </div>
+ </section>
+
+ <section id="sec-names-and-keywords">
+ <div class="front">
+ <h1><span class="secnum" id="sec-11.6"><a href="#sec-names-and-keywords" title="link to this section">11.6</a></span> Names
+ and Keywords</h1>
+
+ <p><span class="nt">IdentifierName</span> and <span class="nt">ReservedWord</span> are tokens that are interpreted according
+ to the Default Identifier Syntax given in Unicode Standard Annex #31, Identifier and Pattern Syntax, with some small
+ modifications. <span class="nt">ReservedWord</span> is an enumerated subset of <span style="font-family: Times New
+ Roman"><i>IdentifierName</i>.</span> The syntactic grammer defines <span class="nt">Identifier</span> as an <span
+ class="nt">IdentifierName</span> that is not a <span class="nt">ReservedWord</span> (<a href="#sec-reserved-words">see
+ 11.6.2</a>). The Unicode identifier grammar is based on character properties specified by the Unicode Standard. The Unicode
+ code points in the specified categories in version 5.1.0 of the Unicode standard must be treated as in those categories by
+ all conforming ECMAScript implementations. ECMAScript implementations may recognise identifier characters defined in later
+ editions of the Unicode Standard.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> This standard specifies specific character additions: The dollar sign
+ (<code>U+0024</code>) and the underscore (<code>U+005f</code>) are permitted anywhere in an <i>IdentifierName</i><span
+ style="font-family: sans-serif">, and the characters zero width non-joiner (U+200C) and zero width joiner (U+200D) are
+ permitted anywhere after the first character of an</span> <i>IdentifierName</i>.</p>
+ </div>
+
+ <p>Unicode escape sequences are permitted in an <span class="nt">IdentifierName</span>, where they contribute a single
+ Unicode code point to the <span class="nt">IdentifierName</span>. The code point is expressed by the <span
+ class="nt">HexDigits</span> of the <span class="nt">UnicodeEscapeSequence</span> (<a
+ href="#sec-literals-string-literals">see 11.8.4</a>). The <code>\</code> preceding the <span
+ class="nt">UnicodeEscapeSequence</span> and the <code>u</code> and <code>{ }</code> characters, if they appear, do not
+ contribute code points to the <span class="nt">IdentifierName</span>. A <span class="nt">UnicodeEscapeSequence</span> cannot
+ be used to put a code point into an <span class="nt">IdentifierName</span> that would otherwise be illegal. In other words,
+ if a <code>\</code> <span class="nt">UnicodeEscapeSequence</span> sequence were replaced by the <span
+ class="nt">SourceCharacter</span> it contributes, the result must still be a valid <span class="nt">IdentifierName</span>
+ that has the exact same sequence of <span class="nt">SourceCharacter</span> elements as the original <span
+ class="nt">IdentifierName</span>. All interpretations of <span class="nt">IdentifierName</span> within this specification
+ are based upon their actual code points regardless of whether or not an escape sequence was used to contribute any
+ particular characters.</p>
+
+ <p>Two <span class="nt">IdentifierName</span> that are canonically equivalent according to the Unicode standard are
+ <i>not</i> equal unless they are represented by the exact same sequence of code points (in other words, conforming
+ ECMAScript implementations are only required to do bitwise comparison on <span class="nt">IdentifierName</span> values).</p>
+
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">IdentifierName</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">IdentifierStart</span></div>
+ <div class="rhs"><span class="nt">IdentifierName</span> <span class="nt">IdentifierPart</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">IdentifierStart</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">UnicodeIDStart</span></div>
+ <div class="rhs"><code class="t">$</code></div>
+ <div class="rhs"><code class="t">_</code></div>
+ <div class="rhs"><code class="t">\</code> <span class="nt">UnicodeEscapeSequence</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">IdentifierPart</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">UnicodeIDContinue</span></div>
+ <div class="rhs"><code class="t">$</code></div>
+ <div class="rhs"><code class="t">_</code></div>
+ <div class="rhs"><code class="t">\</code> <span class="nt">UnicodeEscapeSequence</span></div>
+ <div class="rhs"><ZWNJ></div>
+ <div class="rhs"><ZWJ></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">UnicodeIDStart</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="gprose">any Unicode code point with the Unicode property “ID_Start”</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">UnicodeIDContinue</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="gprose">any Unicode code point with the Unicode property “ID_Continue”</span></div>
+ </div>
+
+ <p>The definitions of the nonterminal <span class="nt">UnicodeEscapeSequence</span> is given in <a
+ href="#sec-literals-string-literals">11.8.4</a>.</p>
+ </div>
+
+ <section id="sec-identifier-names">
+ <div class="front">
+ <h1><span class="secnum" id="sec-11.6.1"><a href="#sec-identifier-names" title="link to this section">11.6.1</a></span>
+ Identifier Names</h1>
+ </div>
+
+ <section id="sec-identifier-names-static-semantics-early-errors">
+ <h1><span class="secnum" id="sec-11.6.1.1"><a href="#sec-identifier-names-static-semantics-early-errors"
+ title="link to this section">11.6.1.1</a></span> Static Semantics: Early Errors</h1>
+ <div class="gp prod"><span class="nt">IdentifierStart</span> <span class="geq">::</span> <code class="t">\</code> <span class="nt">UnicodeEscapeSequence</span></div>
+ <ul>
+ <li>
+ <p>It is a Syntax Error if <span style="font-family: Times New Roman">SV(<i>UnicodeEscapeSequence</i>)</span> is
+ neither the <a href="#sec-static-semantics-utf-16encoding">UTF-16Encoding</a> (<a
+ href="#sec-static-semantics-utf-16encoding">10.1.1</a>) of a single Unicode code point with the Unicode property
+ “ID_Start” nor <code>"$″</code> or <code>"_″</code>.</p>
+ </li>
+ </ul>
+ <div class="gp prod"><span class="nt">IdentifierPart</span> <span class="geq">::</span> <code class="t">\</code> <span class="nt">UnicodeEscapeSequence</span></div>
+ <ul>
+ <li>
+ <p>It is a Syntax Error if <span style="font-family: Times New Roman">SV(<i>UnicodeEscapeSequence</i>)</span> is
+ neither the <a href="#sec-static-semantics-utf-16encoding">UTF-16Encoding</a> (<a
+ href="#sec-static-semantics-utf-16encoding">10.1.1</a>) of a single Unicode code point with the Unicode property
+ “ID_Continue” nor <code>"$″</code> or <code>"_″</code> nor the <a
+ href="#sec-static-semantics-utf-16encoding">UTF-16Encoding</a> of either <ZWNJ> or <ZAJ>.</p>
+ </li>
+ </ul>
+ </section>
+
+ <section id="sec-identifier-names-static-semantics-stringvalue">
+ <h1><span class="secnum" id="sec-11.6.1.2"><a href="#sec-identifier-names-static-semantics-stringvalue"
+ title="link to this section">11.6.1.2</a></span> Static Semantics<span style="font-family: sans-serif">:</span>
+ <i>StringValue</i></h1>
+
+ <p>See also: <a href="#sec-string-literals-static-semantics-stringvalue">11.8.4.2</a>, <a
+ href="#sec-identifiers-static-semantics-stringvalue">12.1.3</a>.</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">IdentifierName</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">IdentifierStart</span></div>
+ <div class="rhs"><span class="nt">IdentifierName</span> <span class="nt">IdentifierPart</span></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return the String value consisting of the sequence of code units corresponding to <i>IdentifierName</i>. In
+ determining the sequence any occurrences of <code>\</code> <i>UnicodeEscapeSequence</i> are first replaced with the
+ code point represented by the <i>UnicodeEscapeSequence</i> and then the code points of the entire
+ <i>IdentifierName</i> are converted to code units by <a
+ href="#sec-static-semantics-utf-16encoding">UTF-16Encoding</a> (<a
+ href="#sec-static-semantics-utf-16encoding">10.1.1</a>) each code point.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-reserved-words">
+ <div class="front">
+ <h1><span class="secnum" id="sec-11.6.2"><a href="#sec-reserved-words" title="link to this section">11.6.2</a></span>
+ Reserved Words</h1>
+
+ <p>A reserved word is an <span class="nt">IdentifierName</span> that cannot be used as an <span
+ class="nt">Identifier</span>.</p>
+
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ReservedWord</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">Keyword</span></div>
+ <div class="rhs"><span class="nt">FutureReservedWord</span></div>
+ <div class="rhs"><span class="nt">NullLiteral</span></div>
+ <div class="rhs"><span class="nt">BooleanLiteral</span></div>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <i>ReservedWord</i> definitions are specified as literal sequences of specific
+ <i>SourceCharacter</i> elements. A code point in a <i>ReservedWord</i> cannot be expressed by a <code>\</code>
+ <i>UnicodeEscapeSequence</i>.</p>
+ </div>
+ </div>
+
+ <section id="sec-keywords">
+ <h1><span class="secnum" id="sec-11.6.2.1"><a href="#sec-keywords" title="link to this section">11.6.2.1</a></span>
+ Keywords</h1>
+
+ <p>The following tokens are ECMAScript keywords and may not be used as <span class="nt">Identifiers</span> in ECMAScript
+ programs.</p>
+
+ <h2>Syntax</h2>
+ <div class="gp prod"><span class="nt">Keyword</span> <span class="geq">::</span> <span class="grhsmod">one of</span></div>
+
+ <figure>
+ <table class="lightweight-table">
+ <tr>
+ <td><code>break</code></td>
+ <td><code>do</code></td>
+ <td><code>in</code></td>
+ <td><code>typeof</code></td>
+ </tr>
+ <tr>
+ <td><code>case</code></td>
+ <td><code>else</code></td>
+ <td><code>instanceof</code></td>
+ <td><code>var</code></td>
+ </tr>
+ <tr>
+ <td><code>catch</code></td>
+ <td><code>export</code></td>
+ <td><code>new</code></td>
+ <td><code>void</code></td>
+ </tr>
+ <tr>
+ <td><code>class</code></td>
+ <td><code>extends</code></td>
+ <td><code>return</code></td>
+ <td><code>while</code></td>
+ </tr>
+ <tr>
+ <td><code>const</code></td>
+ <td><code>finally</code></td>
+ <td><code>super</code></td>
+ <td><code>with</code></td>
+ </tr>
+ <tr>
+ <td><code>continue</code></td>
+ <td><code>for</code></td>
+ <td><code>switch</code></td>
+ <td><code>yield</code></td>
+ </tr>
+ <tr>
+ <td><code>debugger</code></td>
+ <td><code>function</code></td>
+ <td><code>this</code></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td><code>default</code></td>
+ <td><code>if</code></td>
+ <td><code>throw</code></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td><code>delete</code></td>
+ <td><code>import</code></td>
+ <td><code>try</code></td>
+ <td></td>
+ </tr>
+ </table>
+ </figure>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> In some contexts <code>yield</code> is given the semantics of an <i>Identifier</i>. See
+ <a href="#sec-identifiers-static-semantics-early-errors">12.1.1</a>. In <a href="#sec-strict-mode-code">strict mode
+ code</a>, <code>let</code> is treated as a keyword through static semantic restrictions (see <a
+ href="#sec-identifiers-static-semantics-early-errors">12.1.1</a>, <a
+ href="#sec-array-comprehension-static-semantics-early-errors">12.2.4.2.1</a>, <a
+ href="#sec-let-and-const-declarations-static-semantics-early-errors">13.2.1.1</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-early-errors">13.6.4.1</a>, and <a
+ href="#sec-class-definitions-static-semantics-early-errors">14.5.1</a>) rather than the lexical grammar.</p>
+ </div>
+ </section>
+
+ <section id="sec-future-reserved-words">
+ <h1><span class="secnum" id="sec-11.6.2.2"><a href="#sec-future-reserved-words"
+ title="link to this section">11.6.2.2</a></span> Future Reserved Words</h1>
+
+ <p>The following words are used as keywords in proposed extensions and are therefore reserved to allow for the possibility
+ of future adoption of those extensions.</p>
+
+ <h2>Syntax</h2>
+ <div class="gp prod"><span class="nt">FutureReservedWord</span> <span class="geq">::</span></div>
+
+ <figure>
+ <table class="lightweight-table">
+ <tr>
+ <td><code>enum</code></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ </tr>
+ </table>
+ </figure>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Use of the following tokens within <a href="#sec-strict-mode-code">strict mode code</a>
+ (<a href="#sec-strict-mode-code">see 10.2.1</a>) is also reserved. That usage is restricted using static semantic
+ restrictions (<a href="#sec-identifiers-static-semantics-early-errors">see 12.1.1</a>) rather than the lexical
+ grammar:</p>
+ </div>
+
+ <figure>
+ <table class="lightweight-table">
+ <tr>
+ <td><code>implements</code></td>
+ <td><code>package</code></td>
+ <td><code>protected</code></td>
+ <td><code>static</code></td>
+ </tr>
+ <tr>
+ <td><code>interface</code></td>
+ <td><code>private</code></td>
+ <td><code>public</code></td>
+ <td></td>
+ </tr>
+ </table>
+ </figure>
+ </section>
+ </section>
+ </section>
+
+ <section id="sec-punctuators">
+ <h1><span class="secnum" id="sec-11.7"><a href="#sec-punctuators" title="link to this section">11.7</a></span>
+ Punctuators</h1>
+ <h2>Syntax</h2>
+ <div class="gp prod"><span class="nt">Punctuator</span> <span class="geq">::</span> <span class="grhsmod">one of</span></div>
+
+ <figure>
+ <table class="lightweight-table">
+ <tr>
+ <td><code>{</code></td>
+ <td><code>(</code></td>
+ <td><code>)</code></td>
+ <td><code>[</code></td>
+ <td><code>]</code></td>
+ <td><code>.</code></td>
+ </tr>
+ <tr>
+ <td><code>...</code></td>
+ <td><code>;</code></td>
+ <td><code>,</code></td>
+ <td><code><</code></td>
+ <td><code>></code></td>
+ <td><code><=</code></td>
+ </tr>
+ <tr>
+ <td><code>>=</code></td>
+ <td><code>==</code></td>
+ <td><code>!=</code></td>
+ <td><code>===</code></td>
+ <td><code>!==</code></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td><code>+</code></td>
+ <td><code>-</code></td>
+ <td><code>*</code></td>
+ <td><code>%</code></td>
+ <td><code>++</code></td>
+ <td><code>--</code></td>
+ </tr>
+ <tr>
+ <td><code><<</code></td>
+ <td><code>>></code></td>
+ <td><code>>>></code></td>
+ <td><code>&</code></td>
+ <td><code>|</code></td>
+ <td><code>^</code></td>
+ </tr>
+ <tr>
+ <td><code>!</code></td>
+ <td><code>~</code></td>
+ <td><code>&&</code></td>
+ <td><code>||</code></td>
+ <td><code>?</code></td>
+ <td><code>:</code></td>
+ </tr>
+ <tr>
+ <td><code>=</code></td>
+ <td><code>+=</code></td>
+ <td><code>-=</code></td>
+ <td><code>*=</code></td>
+ <td><code>%=</code></td>
+ <td><code><<=</code></td>
+ </tr>
+ <tr>
+ <td><code>>>=</code></td>
+ <td><code>>>>=</code></td>
+ <td><code>&=</code></td>
+ <td><code>|=</code></td>
+ <td><code>^=</code></td>
+ <td><code>=></code></td>
+ </tr>
+ </table>
+ </figure>
+
+ <div class="gp prod"><span class="nt">DivPunctuator</span> <span class="geq">::</span> <span class="grhsmod">one of</span></div>
+
+ <figure>
+ <table class="lightweight-table">
+ <tr>
+ <td><code>/</code></td>
+ <td><code>/=</code></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ </tr>
+ </table>
+ </figure>
+
+ <div class="gp prod"><span class="nt">RightBracePunctuator</span> <span class="geq">::</span></div>
+
+ <figure>
+ <table class="lightweight-table">
+ <tr>
+ <td><code>}</code></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ </tr>
+ </table>
+ </figure>
+ </section>
+
+ <section id="sec-ecmascript-language-lexical-grammar-literals">
+ <div class="front">
+ <h1><span class="secnum" id="sec-11.8"><a href="#sec-ecmascript-language-lexical-grammar-literals"
+ title="link to this section">11.8</a></span> Literals</h1>
+ </div>
+
+ <section id="sec-null-literals">
+ <h1><span class="secnum" id="sec-11.8.1"><a href="#sec-null-literals" title="link to this section">11.8.1</a></span> Null
+ Literals</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">NullLiteral</span> <span class="geq">::</span></div>
+ <div class="rhs"><code class="t">null</code></div>
+ </div>
+ </section>
+
+ <section id="sec-boolean-literals">
+ <h1><span class="secnum" id="sec-11.8.2"><a href="#sec-boolean-literals" title="link to this section">11.8.2</a></span>
+ Boolean Literals</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">BooleanLiteral</span> <span class="geq">::</span></div>
+ <div class="rhs"><code class="t">true</code></div>
+ <div class="rhs"><code class="t">false</code></div>
+ </div>
+ </section>
+
+ <section id="sec-literals-numeric-literals">
+ <div class="front">
+ <h1><span class="secnum" id="sec-11.8.3"><a href="#sec-literals-numeric-literals"
+ title="link to this section">11.8.3</a></span> Numeric Literals</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">NumericLiteral</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">DecimalLiteral</span></div>
+ <div class="rhs"><span class="nt">BinaryIntegerLiteral</span></div>
+ <div class="rhs"><span class="nt">OctalIntegerLiteral</span></div>
+ <div class="rhs"><span class="nt">HexIntegerLiteral</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">DecimalLiteral</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">DecimalIntegerLiteral</span> <code class="t">.</code> <span class="nt">DecimalDigits</span><sub>opt</sub> <span class="nt">ExponentPart</span><sub>opt</sub></div>
+ <div class="rhs"><code class="t">.</code> <span class="nt">DecimalDigits</span> <span class="nt">ExponentPart</span><sub>opt</sub></div>
+ <div class="rhs"><span class="nt">DecimalIntegerLiteral</span> <span class="nt">ExponentPart</span><sub>opt</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">DecimalIntegerLiteral</span> <span class="geq">::</span></div>
+ <div class="rhs"><code class="t">0</code></div>
+ <div class="rhs"><span class="nt">NonZeroDigit</span> <span class="nt">DecimalDigits</span><sub>opt</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">DecimalDigits</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">DecimalDigit</span></div>
+ <div class="rhs"><span class="nt">DecimalDigits</span> <span class="nt">DecimalDigit</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">DecimalDigit</span> <span class="geq">::</span> <span class="grhsmod">one of</span></div>
+ <div class="rhs"><code class="t">0</code> <code class="t">1</code> <code class="t">2</code> <code class="t">3</code> <code class="t">4</code> <code class="t">5</code> <code class="t">6</code> <code class="t">7</code> <code class="t">8</code> <code class="t">9</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">NonZeroDigit</span> <span class="geq">::</span> <span class="grhsmod">one of</span></div>
+ <div class="rhs"><code class="t">1</code> <code class="t">2</code> <code class="t">3</code> <code class="t">4</code> <code class="t">5</code> <code class="t">6</code> <code class="t">7</code> <code class="t">8</code> <code class="t">9</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ExponentPart</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">ExponentIndicator</span> <span class="nt">SignedInteger</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ExponentIndicator</span> <span class="geq">::</span> <span class="grhsmod">one of</span></div>
+ <div class="rhs"><code class="t">e</code> <code class="t">E</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">SignedInteger</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">DecimalDigits</span></div>
+ <div class="rhs"><code class="t">+</code> <span class="nt">DecimalDigits</span></div>
+ <div class="rhs"><code class="t">-</code> <span class="nt">DecimalDigits</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">BinaryIntegerLiteral</span> <span class="geq">::</span></div>
+ <div class="rhs"><code class="t">0b</code> <span class="nt">BinaryDigits</span></div>
+ <div class="rhs"><code class="t">0B</code> <span class="nt">BinaryDigits</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">BinaryDigits</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">BinaryDigit</span></div>
+ <div class="rhs"><span class="nt">BinaryDigits</span> <span class="nt">BinaryDigit</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">BinaryDigit</span> <span class="geq">::</span> <span class="grhsmod">one of</span></div>
+ <div class="rhs"><code class="t">0</code> <code class="t">1</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">OctalIntegerLiteral</span> <span class="geq">::</span></div>
+ <div class="rhs"><code class="t">0o</code> <span class="nt">OctalDigits</span></div>
+ <div class="rhs"><code class="t">0O</code> <span class="nt">OctalDigits</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">OctalDigits</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">OctalDigit</span></div>
+ <div class="rhs"><span class="nt">OctalDigits</span> <span class="nt">OctalDigit</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">OctalDigit</span> <span class="geq">::</span> <span class="grhsmod">one of</span></div>
+ <div class="rhs"><code class="t">0</code> <code class="t">1</code> <code class="t">2</code> <code class="t">3</code> <code class="t">4</code> <code class="t">5</code> <code class="t">6</code> <code class="t">7</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">HexIntegerLiteral</span> <span class="geq">::</span></div>
+ <div class="rhs"><code class="t">0x</code> <span class="nt">HexDigits</span></div>
+ <div class="rhs"><code class="t">0X</code> <span class="nt">HexDigits</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">HexDigits</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">HexDigit</span></div>
+ <div class="rhs"><span class="nt">HexDigits</span> <span class="nt">HexDigit</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">HexDigit</span> <span class="geq">::</span> <span class="grhsmod">one of</span></div>
+ <div class="rhs"><code class="t">0</code> <code class="t">1</code> <code class="t">2</code> <code class="t">3</code> <code class="t">4</code> <code class="t">5</code> <code class="t">6</code> <code class="t">7</code> <code class="t">8</code> <code class="t">9</code> <code class="t">a</code> <code class="t">b</code> <code class="t">c</code> <code class="t">d</code> <code class="t">e</code> <code class="t">f</code> <code class="t">A</code> <code class="t">B</code> <code class="t">C</code> <code class="t">D</code> <code class="t">E</code> <code class="t">F</code></div>
+ </div>
+
+ <p>The <span class="nt">SourceCharacter</span> immediately following a <span class="nt">NumericLiteral</span> must not be
+ an <span class="nt">IdentifierStart</span> or <span class="nt">DecimalDigit</span>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> For example:</p>
+
+ <pre>3in</pre>
+
+ <p>is an error and not the two input elements <code>3</code> and <code>in</code>.</p>
+ </div>
+
+ <p>A conforming implementation, when processing <a href="#sec-strict-mode-code">strict mode code</a> (<a
+ href="#sec-strict-mode-code">see 10.2.1</a>), must not extend the syntax of <span class="nt">NumericLiteral</span> to
+ include <i>Legacy<span style="font-family: Times New Roman">OctalIntegerLiteral</span></i> as described in <a
+ href="#sec-additional-syntax-numeric-literals">B.1.1</a>.</p>
+ </div>
+
+ <section id="sec-static-semantics-mv-s">
+ <h1><span class="secnum" id="sec-11.8.3.1"><a href="#sec-static-semantics-mv-s"
+ title="link to this section">11.8.3.1</a></span> Static Semantics: MV’s</h1>
+
+ <p>A numeric literal stands for a value of the Number type. This value is determined in two steps: first, a mathematical
+ value (MV) is derived from the literal; second, this mathematical value is rounded as described below.</p>
+
+ <ul>
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">NumericLiteral</span> <span class="geq">::</span> <span
+ class="nt">DecimalLiteral</span></span> is the MV of <i>DecimalLiteral</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">NumericLiteral</span> <span class="geq">::</span> <span
+ class="nt">BinaryIntegerLiteral</span></span> is the MV of <i>BinaryIntegerLiteral</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">NumericLiteral</span> <span class="geq">::</span> <span
+ class="nt">OctalIntegerLiteral</span></span> is the MV of <i>OctalIntegerLiteral</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">NumericLiteral</span> <span class="geq">::</span> <span
+ class="nt">HexIntegerLiteral</span></span> is the MV of <i>HexIntegerLiteral</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">DecimalLiteral</span> <span class="geq">::</span> <span
+ class="nt">DecimalIntegerLiteral</span> <code class="t">.</code></span> is the MV of <i>DecimalIntegerLiteral</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">DecimalLiteral</span> <span class="geq">::</span> <span
+ class="nt">DecimalIntegerLiteral</span> <code class="t">.</code> <span class="nt">DecimalDigits</span></span> is the
+ MV of <i>DecimalIntegerLiteral</i> plus (the MV of <i>DecimalDigits</i> × 10<sup>–<i>n</i></sup>), where
+ <i>n</i> is the number of characters in <i>DecimalDigits</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">DecimalLiteral</span> <span class="geq">::</span> <span
+ class="nt">DecimalIntegerLiteral</span> <code class="t">.</code> <span class="nt">ExponentPart</span></span> is the MV
+ of <i>DecimalIntegerLiteral</i> × 10<sup><i>e</i></sup>, where <i>e</i> is the MV of <i>ExponentPart</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">DecimalLiteral</span> <span class="geq">::</span> <span
+ class="nt">DecimalIntegerLiteral</span> <code class="t">.</code> <span class="nt">DecimalDigits</span> <span
+ class="nt">ExponentPart</span></span> is (the MV of <i>DecimalIntegerLiteral</i> plus (the MV of <i>DecimalDigits</i>
+ × 10<sup>–<i>n</i></sup>)) × 10<sup><i>e</i></sup>, where <i>n</i> is the number of characters in
+ <i>DecimalDigits</i> and <i>e</i> is the MV of <i>ExponentPart</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">DecimalLiteral</span> <span class="geq">::</span> <code
+ class="t">.</code> <span class="nt">DecimalDigits</span></span> is the MV of <i>DecimalDigits</i> ×
+ 10<sup>–<i>n</i></sup>, where <i>n</i> is the number of characters in <i>DecimalDigits</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">DecimalLiteral</span> <span class="geq">::</span> <code
+ class="t">.</code> <span class="nt">DecimalDigits</span> <span class="nt">ExponentPart</span></span> is the MV of
+ <i>DecimalDigits</i> × 10<sup><i>e</i>–<i>n</i></sup>, where <i>n</i> is the number of characters in
+ <i>DecimalDigits</i> and <i>e</i> is the MV of <i>ExponentPart</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">DecimalLiteral</span> <span class="geq">::</span> <span
+ class="nt">DecimalIntegerLiteral</span></span> is the MV of <i>DecimalIntegerLiteral</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">DecimalLiteral</span> <span class="geq">::</span> <span
+ class="nt">DecimalIntegerLiteral</span> <span class="nt">ExponentPart</span></span> is the MV of
+ <i>DecimalIntegerLiteral</i> × 10<sup><i>e</i></sup>, where <i>e</i> is the MV of <i>ExponentPart</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">DecimalIntegerLiteral</span> <span class="geq">::</span> <code
+ class="t">0</code></span> is 0.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">DecimalIntegerLiteral</span> <span class="geq">::</span> <span
+ class="nt">NonZeroDigit</span></span> is the MV of <i>NonZeroDigit.</i></p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">DecimalIntegerLiteral</span> <span class="geq">::</span> <span
+ class="nt">NonZeroDigit</span> <span class="nt">DecimalDigits</span></span> is (the MV of <i>NonZeroDigit</i> ×
+ 10<sup><i>n</i></sup>) plus the MV of <i>DecimalDigits</i>, where <i>n</i> is the number of characters in
+ <i>DecimalDigits</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">DecimalDigits</span> <span class="geq">::</span> <span
+ class="nt">DecimalDigit</span></span> is the MV of <i>DecimalDigit</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">DecimalDigits</span> <span class="geq">::</span> <span
+ class="nt">DecimalDigits</span> <span class="nt">DecimalDigit</span></span> is (the MV of <i>DecimalDigits</i> ×
+ 10) plus the MV of <i>DecimalDigit</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">ExponentPart</span> <span class="geq">::</span> <span
+ class="nt">ExponentIndicator</span> <span class="nt">SignedInteger</span></span> is the MV of
+ <i>SignedInteger</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">SignedInteger</span> <span class="geq">::</span> <span
+ class="nt">DecimalDigits</span></span> is the MV of <i>DecimalDigits</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">SignedInteger</span> <span class="geq">::</span> <code
+ class="t">+</code> <span class="nt">DecimalDigits</span></span> is the MV of <i>DecimalDigits</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">SignedInteger</span> <span class="geq">::</span> <code
+ class="t">-</code> <span class="nt">DecimalDigits</span></span> is the negative of the MV of <i>DecimalDigits</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">DecimalDigit</span> <span class="geq">::</span> <code
+ class="t">0</code></span> or of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">::</span> <code
+ class="t">0</code></span> or of <span class="prod"><span class="nt">OctalDigit</span> <span class="geq">::</span>
+ <code class="t">0</code></span> or of <span class="prod"><span class="nt">BinaryDigit</span> <span
+ class="geq">::</span> <code class="t">0</code></span> is 0.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">DecimalDigit</span> <span class="geq">::</span> <code
+ class="t">1</code></span> or of <span class="prod"><span class="nt">NonZeroDigit</span> <span class="geq">::</span>
+ <code class="t">1</code></span> or of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">::</span>
+ <code class="t">1</code></span> or of <span class="prod"><span class="nt">OctalDigit</span> <span
+ class="geq">::</span> <code class="t">1</code></span> or<br>of <span class="prod"><span class="nt">BinaryDigit</span>
+ <span class="geq">::</span> <code class="t">1</code></span> is 1.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">DecimalDigit</span> <span class="geq">::</span> <code
+ class="t">2</code></span> or of <span class="prod"><span class="nt">NonZeroDigit</span> <span class="geq">::</span>
+ <code class="t">2</code></span> or of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">::</span>
+ <code class="t">2</code></span> or of <span class="prod"><span class="nt">OctalDigit</span> <span
+ class="geq">::</span> <code class="t">2</code></span> is 2.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">DecimalDigit</span> <span class="geq">::</span> <code
+ class="t">3</code></span> or of <span class="prod"><span class="nt">NonZeroDigit</span> <span class="geq">::</span>
+ <code class="t">3</code></span> or of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">::</span>
+ <code class="t">3</code></span> or of <span class="prod"><span class="nt">OctalDigit</span> <span
+ class="geq">::</span> <code class="t">3</code></span> is 3.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">DecimalDigit</span> <span class="geq">::</span> <code
+ class="t">4</code></span> or of <span class="prod"><span class="nt">NonZeroDigit</span> <span class="geq">::</span>
+ <code class="t">4</code></span> or of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">::</span>
+ <code class="t">4</code></span> or of <span class="prod"><span class="nt">OctalDigit</span> <span
+ class="geq">::</span> <code class="t">4</code></span> is 4.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">DecimalDigit</span> <span class="geq">::</span> <code
+ class="t">5</code></span> or of <span class="prod"><span class="nt">NonZeroDigit</span> <span class="geq">::</span>
+ <code class="t">5</code></span> or of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">::</span>
+ <code class="t">5</code></span> or of <span class="prod"><span class="nt">OctalDigit</span> <span
+ class="geq">::</span> <code class="t">5</code></span> is 5.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">DecimalDigit</span> <span class="geq">::</span> <code
+ class="t">6</code></span> or of <span class="prod"><span class="nt">NonZeroDigit</span> <span class="geq">::</span>
+ <code class="t">6</code></span> or of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">::</span>
+ <code class="t">6</code></span> or of <span class="prod"><span class="nt">OctalDigit</span> <span
+ class="geq">::</span> <code class="t">6</code></span> is 6.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">DecimalDigit</span> <span class="geq">::</span> <code
+ class="t">7</code></span> or of <span class="prod"><span class="nt">NonZeroDigit</span> <span class="geq">::</span>
+ <code class="t">7</code></span> or of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">::</span>
+ <code class="t">7</code></span> or of <span class="prod"><span class="nt">OctalDigit</span> <span
+ class="geq">::</span> <code class="t">7</code></span> is 7.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">DecimalDigit</span> <span class="geq">::</span> <code
+ class="t">8</code></span> or of <span class="prod"><span class="nt">NonZeroDigit</span> <span class="geq">::</span>
+ <code class="t">8</code></span> or of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">::</span>
+ <code class="t">8</code></span> is 8.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">DecimalDigit</span> <span class="geq">::</span> <code
+ class="t">9</code></span> or of <span class="prod"><span class="nt">NonZeroDigit</span> <span class="geq">::</span>
+ <code class="t">9</code></span> or of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">::</span>
+ <code class="t">9</code></span> is 9.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">::</span> <code
+ class="t">a</code></span> or of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">::</span> <code
+ class="t">A</code></span> is 10.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">::</span> <code
+ class="t">b</code></span> or of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">::</span> <code
+ class="t">B</code></span> is 11.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">::</span> <code
+ class="t">c</code></span> or of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">::</span> <code
+ class="t">C</code></span> is 12.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">::</span> <code
+ class="t">d</code></span> or of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">::</span> <code
+ class="t">D</code></span> is 13.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">::</span> <code
+ class="t">e</code></span> or of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">::</span> <code
+ class="t">E</code></span> is 14.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">::</span> <code
+ class="t">f</code></span> or of <span class="prod"><span class="nt">HexDigit</span> <span class="geq">::</span> <code
+ class="t">F</code></span> is 15.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">BinaryIntegerLiteral</span> <span class="geq">::</span> <code
+ class="t">0b</code> <span class="nt">BinaryDigits</span></span> is the MV of <i>BinaryDigits</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">BinaryIntegerLiteral</span> <span class="geq">::</span> <code
+ class="t">0B</code> <span class="nt">BinaryDigits</span></span> is the MV of <i>BinaryDigits</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">BinaryDigits</span> <span class="geq">::</span> <span
+ class="nt">BinaryDigit</span></span> is the MV of <i>BinaryDigit</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">BinaryDigits</span> <span class="geq">::</span> <span
+ class="nt">BinaryDigits</span> <span class="nt">BinaryDigit</span></span> is (the MV of <i>BinaryDigits</i> × 2)
+ plus the MV of <i>BinaryDigit</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">OctalIntegerLiteral</span> <span class="geq">::</span> <code
+ class="t">0o</code> <span class="nt">OctalDigits</span></span> is the MV of <i>OctalDigits</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">OctalIntegerLiteral</span> <span class="geq">::</span> <code
+ class="t">0O</code> <span class="nt">OctalDigits</span></span> is the MV of <i>OctalDigits</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">OctalDigits</span> <span class="geq">::</span> <span
+ class="nt">OctalDigit</span></span> is the MV of <i>OctalDigit</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">OctalDigits</span> <span class="geq">::</span> <span
+ class="nt">OctalDigits</span> <span class="nt">OctalDigit</span></span> is (the MV of <i>OctalDigits</i> × 8)
+ plus the MV of <i>OctalDigit</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">HexIntegerLiteral</span> <span class="geq">::</span> <code
+ class="t">0x</code> <span class="nt">HexDigits</span></span> is the MV of <i>HexDigits</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">HexIntegerLiteral</span> <span class="geq">::</span> <code
+ class="t">0X</code> <span class="nt">HexDigits</span></span> is the MV of <i>HexDigits</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">HexDigits</span> <span class="geq">::</span> <span
+ class="nt">HexDigit</span></span> is the MV of <i>HexDigit</i>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">HexDigits</span> <span class="geq">::</span> <span
+ class="nt">HexDigits</span> <span class="nt">HexDigit</span></span> is (the MV of <i>HexDigits</i> × 16) plus
+ the MV of <i>HexDigit</i>.</p>
+ </li>
+ </ul>
+
+ <p>Once the exact MV for a numeric literal has been determined, it is then rounded to a value of the Number type. If the
+ MV is 0, then the rounded value is <span class="value">+0</span>; otherwise, the rounded value must be the Number value
+ for the MV (as specified in <a href="#sec-ecmascript-language-types-number-type">6.1.6</a>), unless the literal is a <span
+ class="nt">DecimalLiteral</span> and the literal has more than 20 significant digits, in which case the Number value may
+ be either the Number value for the MV of a literal produced by replacing each significant digit after the 20th with a
+ <code>0</code> digit or the Number value for the MV of a literal produced by replacing each significant digit after the
+ 20th with a <code>0</code> digit and then incrementing the literal at the 20th significant digit position. A digit is
+ <i>significant</i> if it is not part of an <span class="nt">ExponentPart</span> and</p>
+
+ <ul>
+ <li>it is not <code>0</code>; or</li>
+ <li>there is a nonzero digit to its left and there is a nonzero digit, not in the <i>ExponentPart</i>, to its
+ right.</li>
+ </ul>
+ </section>
+ </section>
+
+ <section id="sec-literals-string-literals">
+ <div class="front">
+ <h1><span class="secnum" id="sec-11.8.4"><a href="#sec-literals-string-literals"
+ title="link to this section">11.8.4</a></span> String Literals</h1>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> A string literal is zero or more Unicode code points enclosed in single or double
+ quotes. Unicode code points may also be represented by an escape sequence. All characters may appear literally in a
+ string literal except for the closing quote character, backslash, carriage return, line separator, paragraph separator,
+ and line feed. Any character may appear in the form of an escape sequence. String literals evaluate to ECAMScript String
+ values. When generating these string values Unicode code points are UTF-16 encoded as defined in <a
+ href="#sec-static-semantics-utf-16encoding">10.1.1</a>. Code points belonging to Basic Multilingual Plane are encoded as
+ a single code unit element of the string. All other code points are encoded as two code unit elements of the
+ string.</p>
+ </div>
+
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">StringLiteral</span> <span class="geq">::</span></div>
+ <div class="rhs"><code class="t">"</code> <span class="nt">DoubleStringCharacters</span><sub>opt</sub> <code class="t">"</code></div>
+ <div class="rhs"><code class="t">'</code> <span class="nt">SingleStringCharacters</span><sub>opt</sub> <code class="t">'</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">DoubleStringCharacters</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">DoubleStringCharacter</span> <span class="nt">DoubleStringCharacters</span><sub>opt</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">SingleStringCharacters</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">SingleStringCharacter</span> <span class="nt">SingleStringCharacters</span><sub>opt</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">DoubleStringCharacter</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">SourceCharacter</span> <span class="grhsmod">but not one of</span> <code class="t">"</code> <span class="grhsmod">or</span> <code class="t">\</code> <span class="grhsmod">or</span> <span class="nt">LineTerminator</span></div>
+ <div class="rhs"><code class="t">\</code> <span class="nt">EscapeSequence</span></div>
+ <div class="rhs"><span class="nt">LineContinuation</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">SingleStringCharacter</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">SourceCharacter</span> <span class="grhsmod">but not one of</span> <code class="t">'</code> <span class="grhsmod">or</span> <code class="t">\</code> <span class="grhsmod">or</span> <span class="nt">LineTerminator</span></div>
+ <div class="rhs"><code class="t">\</code> <span class="nt">EscapeSequence</span></div>
+ <div class="rhs"><span class="nt">LineContinuation</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">LineContinuation</span> <span class="geq">::</span></div>
+ <div class="rhs"><code class="t">\</code> <span class="nt">LineTerminatorSequence</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">EscapeSequence</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">CharacterEscapeSequence</span></div>
+ <div class="rhs"><code class="t">0</code> <span class="grhsannot">[lookahead ∉ <span class="nt">DecimalDigit</span>]</span></div>
+ <div class="rhs"><span class="nt">HexEscapeSequence</span></div>
+ <div class="rhs"><span class="nt">UnicodeEscapeSequence</span></div>
+ </div>
+
+ <p>A conforming implementation, when processing <a href="#sec-strict-mode-code">strict mode code</a> (<a
+ href="#sec-strict-mode-code">see 10.2.1</a>), must not extend the syntax of <span class="nt">EscapeSequence</span> to
+ include <i>Legacy<span style="font-family: Times New Roman">OctalEscapeSequence</span></i> as described in <a
+ href="#sec-additional-syntax-numeric-literals">B.1.1</a>.</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">CharacterEscapeSequence</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">SingleEscapeCharacter</span></div>
+ <div class="rhs"><span class="nt">NonEscapeCharacter</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">SingleEscapeCharacter</span> <span class="geq">::</span> <span class="grhsmod">one of</span></div>
+ <div class="rhs"><code class="t">'</code> <code class="t">"</code> <code class="t">\</code> <code class="t">b</code> <code class="t">f</code> <code class="t">n</code> <code class="t">r</code> <code class="t">t</code> <code class="t">v</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">NonEscapeCharacter</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">SourceCharacter</span> <span class="grhsmod">but not one of</span> <span class="nt">EscapeCharacter</span> <span class="grhsmod">or</span> <span class="nt">LineTerminator</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">EscapeCharacter</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">SingleEscapeCharacter</span></div>
+ <div class="rhs"><span class="nt">DecimalDigit</span></div>
+ <div class="rhs"><code class="t">x</code></div>
+ <div class="rhs"><code class="t">u</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">HexEscapeSequence</span> <span class="geq">::</span></div>
+ <div class="rhs"><code class="t">x</code> <span class="nt">HexDigit</span> <span class="nt">HexDigit</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">UnicodeEscapeSequence</span> <span class="geq">::</span></div>
+ <div class="rhs"><code class="t">u</code> <span class="nt">Hex4Digits</span></div>
+ <div class="rhs"><code class="t">u{</code> <span class="nt">HexDigits</span> <code class="t">}</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">Hex4Digits</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">HexDigit</span> <span class="nt">HexDigit</span> <span class="nt">HexDigit</span> <span class="nt">HexDigit</span></div>
+ </div>
+
+ <p>The definition of the nonterminal <span class="nt">HexDigit</span> is given in <a
+ href="#sec-literals-numeric-literals">11.8.3</a>. <span class="nt">SourceCharacter</span> is defined in <a
+ href="#sec-source-text">10.1</a>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> A line terminator character cannot appear in a string literal, except as part of a
+ <i>LineContinuation</i> to produce the empty character sequence. The correct way to cause a line terminator character to
+ be part of the String value of a string literal is to use an escape sequence such as <code>\n</code> or
+ <code>\u000A</code>.</p>
+ </div>
+ </div>
+
+ <section id="sec-string-literals-static-semantics-early-errors">
+ <h1><span class="secnum" id="sec-11.8.4.1"><a href="#sec-string-literals-static-semantics-early-errors"
+ title="link to this section">11.8.4.1</a></span> Static Semantics: Early Errors</h1>
+ <div class="gp prod"><span class="nt">UnicodeEscapeSequence</span> <span class="geq">::</span> <code class="t">u{</code> <span class="nt">HexDigits</span> <code class="t">}</code></div>
+ <ul>
+ <li>It is a Syntax Error if the MV of <span class="nt">HexDigits</span> > <span style="font-family: Times New
+ Roman">1114111<i>.</i></span></li>
+ </ul>
+ </section>
+
+ <section id="sec-string-literals-static-semantics-stringvalue">
+ <h1><span class="secnum" id="sec-11.8.4.2"><a href="#sec-string-literals-static-semantics-stringvalue"
+ title="link to this section">11.8.4.2</a></span> Static Semantics<span style="font-family: sans-serif">:</span>
+ <i>StringValue</i></h1>
+
+ <p>See also: <a href="#sec-identifier-names-static-semantics-stringvalue">11.6.1.2</a>, <a
+ href="#sec-identifiers-static-semantics-stringvalue">12.1.3</a>.</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">StringLiteral</span> <span class="geq">::</span></div>
+ <div class="rhs"><code class="t">"</code> <span class="nt">DoubleStringCharacters</span><sub>opt</sub> <code class="t">"</code></div>
+ <div class="rhs"><code class="t">'</code> <span class="nt">SingleStringCharacters</span><sub>opt</sub> <code class="t">'</code></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return the String value whose elements are the SV of this <i>StringLiteral</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-static-semantics-sv-s-and-cv-s">
+ <h1><span class="secnum" id="sec-11.8.4.3"><a href="#sec-static-semantics-sv-s-and-cv-s"
+ title="link to this section">11.8.4.3</a></span> Static Semantics: <i>SV’s</i> <i>and CV’s</i></h1>
+
+ <p>A string literal stands for a value of the String type. The String value (SV) of the literal is described in terms of
+ code unit values (CV) contributed by the various parts of the string literal. As part of this process, some Unicode code
+ points within the string literal are interpreted as having a mathematical value (MV), as described below or in <a
+ href="#sec-literals-numeric-literals">11.8.3</a>.</p>
+
+ <ul>
+ <li>
+ <p>The SV of <span class="prod"><span class="nt">StringLiteral</span> <span class="geq">::</span> <code
+ class="t">""</code></span> is the empty code unit sequence.</p>
+ </li>
+
+ <li>
+ <p>The SV of <span class="prod"><span class="nt">StringLiteral</span> <span class="geq">::</span> <code
+ class="t">''</code></span> is the empty code unit sequence.</p>
+ </li>
+
+ <li>
+ <p>The SV of <span class="prod"><span class="nt">StringLiteral</span> <span class="geq">::</span> <code
+ class="t">"</code> <span class="nt">DoubleStringCharacters</span> <code class="t">"</code></span> is the SV of
+ <i>DoubleStringCharacters</i>.</p>
+ </li>
+
+ <li>
+ <p>The SV of <span class="prod"><span class="nt">StringLiteral</span> <span class="geq">::</span> <code
+ class="t">'</code> <span class="nt">SingleStringCharacters</span> <code class="t">'</code></span> is the SV of
+ <i>SingleStringCharacters</i>.</p>
+ </li>
+
+ <li>
+ <p>The SV of <span class="prod"><span class="nt">DoubleStringCharacters</span> <span class="geq">::</span> <span
+ class="nt">DoubleStringCharacter</span></span> is a sequence of one or two code units that is the CV of
+ <i>DoubleStringCharacter</i>.</p>
+ </li>
+
+ <li>
+ <p>The SV of <span class="prod"><span class="nt">DoubleStringCharacters</span> <span class="geq">::</span> <span
+ class="nt">DoubleStringCharacter</span> <span class="nt">DoubleStringCharacters</span></span> is a sequence of one or
+ two code units that is the CV of <i>DoubleStringCharacter</i> followed by all the code units in the SV of
+ <i>DoubleStringCharacters</i> in order.</p>
+ </li>
+
+ <li>
+ <p>The SV of <span class="prod"><span class="nt">SingleStringCharacters</span> <span class="geq">::</span> <span
+ class="nt">SingleStringCharacter</span></span> is a sequence of one or two code units that is the CV of
+ <i>SingleStringCharacter</i>.</p>
+ </li>
+
+ <li>
+ <p>The SV of <span class="prod"><span class="nt">SingleStringCharacters</span> <span class="geq">::</span> <span
+ class="nt">SingleStringCharacter</span> <span class="nt">SingleStringCharacters</span></span> is a sequence of one or
+ two code units that is the CV of <i>SingleStringCharacter</i> followed by all the code units in the SV of
+ <i>SingleStringCharacters</i> in order.</p>
+ </li>
+
+ <li>
+ <p>The CV of <span class="prod"><span class="nt">DoubleStringCharacter</span> <span class="geq">::</span> <span
+ class="nt">SourceCharacter</span> <span class="grhsmod">but not one of</span> <code class="t">"</code> <span
+ class="grhsmod">or</span> <code class="t">\</code> <span class="grhsmod">or</span> <span
+ class="nt">LineTerminator</span></span> is the <a href="#sec-static-semantics-utf-16encoding">UTF-16Encoding</a> (<a
+ href="#sec-static-semantics-utf-16encoding">10.1.1</a>) of the code point value of <i>SourceCharacter</i>.</p>
+ </li>
+
+ <li>
+ <p>The CV of <span class="prod"><span class="nt">DoubleStringCharacter</span> <span class="geq">::</span> <code
+ class="t">\</code> <span class="nt">EscapeSequence</span></span> is the CV of the <i>EscapeSequence</i>.</p>
+ </li>
+
+ <li>
+ <p>The CV of <span class="prod"><span class="nt">DoubleStringCharacter</span> <span class="geq">::</span> <span
+ class="nt">LineContinuation</span></span> is the empty character sequence.</p>
+ </li>
+
+ <li>
+ <p>The CV of <span class="prod"><span class="nt">SingleStringCharacter</span> <span class="geq">::</span> <span
+ class="nt">SourceCharacter</span> <span class="grhsmod">but not one of</span> <code class="t">'</code> <span
+ class="grhsmod">or</span> <code class="t">\</code> <span class="grhsmod">or</span> <span
+ class="nt">LineTerminator</span></span> is the <a href="#sec-static-semantics-utf-16encoding">UTF-16Encoding</a> (<a
+ href="#sec-static-semantics-utf-16encoding">10.1.1</a>) of the code point value of <i>SourceCharacter</i> .</p>
+ </li>
+
+ <li>
+ <p>The CV of <span class="prod"><span class="nt">SingleStringCharacter</span> <span class="geq">::</span> <code
+ class="t">\</code> <span class="nt">EscapeSequence</span></span> is the CV of the <i>EscapeSequence</i>.</p>
+ </li>
+
+ <li>
+ <p>The CV of <span class="prod"><span class="nt">SingleStringCharacter</span> <span class="geq">::</span> <span
+ class="nt">LineContinuation</span></span> is the empty character sequence.</p>
+ </li>
+
+ <li>
+ <p>The CV of <span class="prod"><span class="nt">EscapeSequence</span> <span class="geq">::</span> <span
+ class="nt">CharacterEscapeSequence</span></span> is the CV of the <i>CharacterEscapeSequence</i>.</p>
+ </li>
+
+ <li>
+ <p>The CV of <span class="prod"><span class="nt">EscapeSequence</span> <span class="geq">::</span> <code
+ class="t">0</code></span> is the code unit value 0.</p>
+ </li>
+
+ <li>
+ <p>The CV of <span class="prod"><span class="nt">EscapeSequence</span> <span class="geq">::</span> <span
+ class="nt">HexEscapeSequence</span></span> is the CV of the <i>HexEscapeSequence</i>.</p>
+ </li>
+
+ <li>
+ <p>The CV of <span class="prod"><span class="nt">EscapeSequence</span> <span class="geq">::</span> <span
+ class="nt">UnicodeEscapeSequence</span></span> is the CV of the <i>UnicodeEscapeSequence</i>.</p>
+ </li>
+
+ <li>
+ <p>The CV of <span class="prod"><span class="nt">CharacterEscapeSequence</span> <span class="geq">::</span> <span
+ class="nt">SingleEscapeCharacter</span></span> is the character whose code unit value is determined by the
+ <i>SingleEscapeCharacter</i> according to <a href="#table-32">Table 32</a>.</p>
+ </li>
+ </ul>
+
+ <figure>
+ <figcaption><span id="table-32">Table 32</span> — String Single Character Escape Sequences</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-top: 2px solid #000000">Escape Sequence</th>
+ <th style="border-bottom: 1px solid #000000; border-top: 2px solid #000000">Code Unit Value</th>
+ <th style="border-bottom: 1px solid #000000; border-top: 2px solid #000000">Name</th>
+ <th style="border-bottom: 1px solid #000000; border-right: 1px solid #000000; border-top: 2px solid #000000">Symbol</th>
+ </tr>
+ <tr>
+ <td style="border-left: 1px solid #000000"><code>\b</code></td>
+ <td><code>0x0008</code></td>
+ <td>backspace</td>
+ <td style="border-right: 1px solid #000000"><BS></td>
+ </tr>
+ <tr>
+ <td style="border-left: 1px solid #000000"><code>\t</code></td>
+ <td><code>0x0009</code></td>
+ <td>horizontal tab</td>
+ <td style="border-right: 1px solid #000000"><HT></td>
+ </tr>
+ <tr>
+ <td style="border-left: 1px solid #000000"><code>\n</code></td>
+ <td><code>0x000A</code></td>
+ <td>line feed (new line)</td>
+ <td style="border-right: 1px solid #000000"><LF></td>
+ </tr>
+ <tr>
+ <td style="border-left: 1px solid #000000"><code>\v</code></td>
+ <td><code>0x000B</code></td>
+ <td>vertical tab</td>
+ <td style="border-right: 1px solid #000000"><VT></td>
+ </tr>
+ <tr>
+ <td style="border-left: 1px solid #000000"><code>\f</code></td>
+ <td><code>0x000C</code></td>
+ <td>form feed</td>
+ <td style="border-right: 1px solid #000000"><FF></td>
+ </tr>
+ <tr>
+ <td style="border-left: 1px solid #000000"><code>\r</code></td>
+ <td><code>0x000D</code></td>
+ <td>carriage return</td>
+ <td style="border-right: 1px solid #000000"><CR></td>
+ </tr>
+ <tr>
+ <td style="border-left: 1px solid #000000"><code>\"</code></td>
+ <td><code>0x0022</code></td>
+ <td>double quote</td>
+ <td style="border-right: 1px solid #000000"><code>"</code></td>
+ </tr>
+ <tr>
+ <td style="border-left: 1px solid #000000"><code>\'</code></td>
+ <td><code>0x0027</code></td>
+ <td>single quote</td>
+ <td style="border-right: 1px solid #000000"><code>'</code></td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 2px solid #000000; border-left: 1px solid #000000"><code>\\</code></td>
+ <td style="border-bottom: 2px solid #000000"><code>0x005C</code></td>
+ <td style="border-bottom: 2px solid #000000">backslash</td>
+ <td style="border-bottom: 2px solid #000000; border-right: 1px solid #000000"><code>\</code></td>
+ </tr>
+ </table>
+ </figure>
+
+ <ul>
+ <li>
+ <p>The CV of <span class="prod"><span class="nt">CharacterEscapeSequence</span> <span class="geq">::</span> <span
+ class="nt">NonEscapeCharacter</span></span> is the CV of the <i>NonEscapeCharacter</i>.</p>
+ </li>
+
+ <li>
+ <p>The CV of <span class="prod"><span class="nt">NonEscapeCharacter</span> <span class="geq">::</span> <span
+ class="nt">SourceCharacter</span> <span class="grhsmod">but not one of</span> <span class="nt">EscapeCharacter</span>
+ <span class="grhsmod">or</span> <span class="nt">LineTerminator</span></span> is the <a
+ href="#sec-static-semantics-utf-16encoding">UTF-16Encoding</a> (<a
+ href="#sec-static-semantics-utf-16encoding">10.1.1</a>) of the code point value of <i>SourceCharacter</i> .</p>
+ </li>
+
+ <li>
+ <p>The CV of <span class="prod"><span class="nt">HexEscapeSequence</span> <span class="geq">::</span> <code
+ class="t">x</code> <span class="nt">HexDigit</span> <span class="nt">HexDigit</span></span> is the code unit value
+ that is (16 times the MV of the first <i>HexDigit</i>) plus the MV of the second <i>HexDigit</i>.</p>
+ </li>
+
+ <li>
+ <p>The CV of <span class="prod"><span class="nt">UnicodeEscapeSequence</span> <span class="geq">::</span> <code
+ class="t">u</code> <span class="nt">Hex4Digits</span></span> is the CV of <span class="nt">Hex4Digits</span></p>
+ </li>
+
+ <li>
+ <p>The CV of <span class="prod"><span class="nt">Hex4Digits</span> <span class="geq">::</span> <span
+ class="nt">HexDigit</span> <span class="nt">HexDigit</span> <span class="nt">HexDigit</span> <span
+ class="nt">HexDigit</span></span> is the code unit value that is (4096 times the MV of the first <i>HexDigit</i>) plus
+ (256 times the MV of the second <i>HexDigit</i>) plus (16 times the MV of the third <i>HexDigit</i>) plus the MV of
+ the fourth <i>HexDigit</i>.</p>
+ </li>
+
+ <li>
+ <p>The CV of <span class="prod"><span class="nt">UnicodeEscapeSequence</span> <span class="geq">::</span> <code
+ class="t">u{</code> <span class="nt">HexDigits</span> <code class="t">}</code></span> is the <a
+ href="#sec-static-semantics-utf-16encoding">UTF-16Encoding</a> (<a
+ href="#sec-static-semantics-utf-16encoding">10.1.1</a>) of the MV of <i>HexDigits</i>.</p>
+ </li>
+ </ul>
+ </section>
+ </section>
+
+ <section id="sec-literals-regular-expression-literals">
+ <div class="front">
+ <h1><span class="secnum" id="sec-11.8.5"><a href="#sec-literals-regular-expression-literals"
+ title="link to this section">11.8.5</a></span> Regular Expression Literals</h1>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> A regular expression literal is an input element that is converted to a RegExp object
+ (<a href="#sec-string-iterator-objects">see 21.1.5</a>) each time the literal is evaluated. Two regular expression
+ literals in a program evaluate to regular expression objects that never compare as <code>===</code> to each other even
+ if the two literals' contents are identical. A RegExp object may also be created at runtime by <code>new RegExp</code>
+ (<a href="#sec-new-regexp-argumentslist">see 21.2.3.2</a>) or calling the <code>RegExp</code> constructor as a function
+ (<a href="#sec-regexp-pattern-flags">21.2.3.1</a>).</p>
+ </div>
+
+ <p>The productions below describe the syntax for a regular expression literal and are used by the input element scanner to
+ find the end of the regular expression literal. The source code comprising the <span
+ class="nt">RegularExpressionBody</span> and the <span class="nt">RegularExpressionFlags</span> are subsequently parsed
+ using the more stringent ECMAScript Regular Expression grammar (<a href="#sec-patterns">21.2.1</a>).</p>
+
+ <p>An implementation may extend the ECMAScript Regular Expression grammar defined in <a href="#sec-patterns">21.2.1</a>,
+ but it must not extend the <span class="nt">RegularExpressionBody</span> and <span
+ class="nt">RegularExpressionFlags</span> productions defined below or the productions used by these productions.</p>
+
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">RegularExpressionLiteral</span> <span class="geq">::</span></div>
+ <div class="rhs"><code class="t">/</code> <span class="nt">RegularExpressionBody</span> <code class="t">/</code> <span class="nt">RegularExpressionFlags</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">RegularExpressionBody</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">RegularExpressionFirstChar</span> <span class="nt">RegularExpressionChars</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">RegularExpressionChars</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="grhsannot">[empty]</span></div>
+ <div class="rhs"><span class="nt">RegularExpressionChars</span> <span class="nt">RegularExpressionChar</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">RegularExpressionFirstChar</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">RegularExpressionNonTerminator</span> <span class="grhsmod">but not one of</span> <code class="t">*</code> <span class="grhsmod">or</span> <code class="t">\</code> <span class="grhsmod">or</span> <code class="t">/</code> <span class="grhsmod">or</span> <code class="t">[</code></div>
+ <div class="rhs"><span class="nt">RegularExpressionBackslashSequence</span></div>
+ <div class="rhs"><span class="nt">RegularExpressionClass</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">RegularExpressionChar</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">RegularExpressionNonTerminator</span> <span class="grhsmod">but not one of</span> <code class="t">\</code> <span class="grhsmod">or</span> <code class="t">/</code> <span class="grhsmod">or</span> <code class="t">[</code></div>
+ <div class="rhs"><span class="nt">RegularExpressionBackslashSequence</span></div>
+ <div class="rhs"><span class="nt">RegularExpressionClass</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">RegularExpressionBackslashSequence</span> <span class="geq">::</span></div>
+ <div class="rhs"><code class="t">\</code> <span class="nt">RegularExpressionNonTerminator</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">RegularExpressionNonTerminator</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">SourceCharacter</span> <span class="grhsmod">but not</span> <span class="nt">LineTerminator</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">RegularExpressionClass</span> <span class="geq">::</span></div>
+ <div class="rhs"><code class="t">[</code> <span class="nt">RegularExpressionClassChars</span> <code class="t">]</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">RegularExpressionClassChars</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="grhsannot">[empty]</span></div>
+ <div class="rhs"><span class="nt">RegularExpressionClassChars</span> <span class="nt">RegularExpressionClassChar</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">RegularExpressionClassChar</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">RegularExpressionNonTerminator</span> <span class="grhsmod">but not one of</span> <code class="t">]</code> <span class="grhsmod">or</span> <code class="t">\</code></div>
+ <div class="rhs"><span class="nt">RegularExpressionBackslashSequence</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">RegularExpressionFlags</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="grhsannot">[empty]</span></div>
+ <div class="rhs"><span class="nt">RegularExpressionFlags</span> <span class="nt">IdentifierPart</span></div>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Regular expression literals may not be empty; instead of representing an empty regular
+ expression literal, the characters <code>//</code> start a single-line comment. To specify an empty regular expression,
+ use: <code>/(?:)/</code>.</p>
+ </div>
+ </div>
+
+ <section id="sec-literals-regular-expression-literals-static-semantics-early-errors">
+ <h1><span class="secnum" id="sec-11.8.5.1"><a
+ href="#sec-literals-regular-expression-literals-static-semantics-early-errors"
+ title="link to this section">11.8.5.1</a></span> Static Semantics: Early Errors</h1>
+ <div class="gp prod"><span class="nt">RegularExpressionFlags</span> <span class="geq">::</span> <span class="nt">RegularExpressionFlags</span> <span class="nt">IdentifierPart</span></div>
+ <ul>
+ <li>It is a Syntax Error if <span class="nt">IdentifierPart</span> contains a Unicode escape sequence<var>.</var></li>
+ </ul>
+ </section>
+
+ <section id="sec-static-semantics-bodytext">
+ <h1><span class="secnum" id="sec-11.8.5.2"><a href="#sec-static-semantics-bodytext"
+ title="link to this section">11.8.5.2</a></span> Static Semantics: <i>BodyText</i></h1>
+ <div class="gp prod"><span class="nt">RegularExpressionLiteral</span> <span class="geq">::</span> <code class="t">/</code> <span class="nt">RegularExpressionBody</span> <code class="t">/</code> <span class="nt">RegularExpressionFlags</span></div>
+ <ol class="proc">
+ <li>Return the source code that was recognized as <i>RegularExpressionBody</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-static-semantics-flagtext">
+ <h1><span class="secnum" id="sec-11.8.5.3"><a href="#sec-static-semantics-flagtext"
+ title="link to this section">11.8.5.3</a></span> Static Semantics: <i>FlagText</i></h1>
+ <div class="gp prod"><span class="nt">RegularExpressionLiteral</span> <span class="geq">::</span> <code class="t">/</code> <span class="nt">RegularExpressionBody</span> <code class="t">/</code> <span class="nt">RegularExpressionFlags</span></div>
+ <ol class="proc">
+ <li>Return the source code that was recognized as <i>RegularExpressionFlags</i>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-template-literal-lexical-components">
+ <div class="front">
+ <h1><span class="secnum" id="sec-11.8.6"><a href="#sec-template-literal-lexical-components"
+ title="link to this section">11.8.6</a></span> Template Literal Lexical Components</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">Template</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">NoSubstitutionTemplate</span></div>
+ <div class="rhs"><span class="nt">TemplateHead</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">NoSubstitutionTemplate</span> <span class="geq">::</span></div>
+ <div class="rhs"><code class="t">`</code> <span class="nt">TemplateCharacters</span><sub>opt</sub> <code class="t">`</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">TemplateHead</span> <span class="geq">::</span></div>
+ <div class="rhs"><code class="t">`</code> <span class="nt">TemplateCharacters</span><sub>opt</sub> <code class="t">${</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">TemplateSubstitutionTail</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">TemplateMiddle</span></div>
+ <div class="rhs"><span class="nt">TemplateTail</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">TemplateMiddle</span> <span class="geq">::</span></div>
+ <div class="rhs"><code class="t">}</code> <span class="nt">TemplateCharacters</span><sub>opt</sub> <code class="t">${</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">TemplateTail</span> <span class="geq">::</span></div>
+ <div class="rhs"><code class="t">}</code> <span class="nt">TemplateCharacters</span><sub>opt</sub> <code class="t">`</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">TemplateCharacters</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">TemplateCharacter</span> <span class="nt">TemplateCharacters</span><sub>opt</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">TemplateCharacter</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">SourceCharacter</span> <span class="grhsmod">but not one of</span> <code class="t">`</code> <span class="grhsmod">or</span> <code class="t">\</code> <span class="grhsmod">or</span> <code class="t">$</code> <span class="grhsmod">or</span> <span class="nt">LineTerminatorSequence</span></div>
+ <div class="rhs"><code class="t">$</code> <span class="grhsannot">[lookahead ≠ { ]</span></div>
+ <div class="rhs"><code class="t">\</code> <span class="nt">EscapeSequence</span></div>
+ <div class="rhs"><span class="nt">LineContinuation</span></div>
+ <div class="rhs"><span class="nt">LineTerminatorSequence</span></div>
+ </div>
+
+ <p>A conforming implementation must not use the extended definition of <span class="nt">EscapeSequence</span> described in
+ <a href="#sec-additional-syntax-string-literals">B.1.2</a> when parsing a <span class="nt">TemplateCharacter</span>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> <i>TemplateSubstitutionTail</i> is used by the <i>InputElementTemplateTail</i>
+ alternative lexical goal.</p>
+ </div>
+ </div>
+
+ <section id="sec-static-semantics-tv-s-and-trv-s">
+ <h1><span class="secnum" id="sec-11.8.6.1"><a href="#sec-static-semantics-tv-s-and-trv-s"
+ title="link to this section">11.8.6.1</a></span> Static Semantics: <i>TV’s and TRV’s</i></h1>
+
+ <p>A template literal component is interpreted as a sequence of Unicode code points. The Template Value (TV) of a literal
+ component is described in terms of code unit values (CV, <a href="#sec-literals-string-literals">11.8.4</a>) contributed
+ by the various parts of the template literal component. As part of this process, some Unicode code points within the
+ template component are interpreted as having a mathematical value (MV, <a
+ href="#sec-literals-numeric-literals">11.8.3</a>). In determining a TV, escape sequences are replaced by the UTF-16 code
+ unit(s) of the Unicode code point represented by the escape sequence. The Template Raw Value (TRV) is similar to a
+ Template Value with the difference that in TRVs escape sequences are interpreted literally.</p>
+
+ <ul>
+ <li>
+ <p>The TV and TRV of <span class="prod"><span class="nt">NoSubstitutionTemplate</span> <span class="geq">::</span>
+ <code class="t">``</code></span> is the empty code unit sequence.</p>
+ </li>
+
+ <li>
+ <p>The TV and TRV of <span class="prod"><span class="nt">TemplateHead</span> <span class="geq">::</span> <code
+ class="t">`${</code></span> is the empty code unit sequence.</p>
+ </li>
+
+ <li>
+ <p>The TV and TRV of <span class="prod"><span class="nt">TemplateMiddle</span> <span class="geq">::</span> <code
+ class="t">}${</code></span> is the empty code unit sequence.</p>
+ </li>
+
+ <li>
+ <p>The TV and TRV of <span class="prod"><span class="nt">TemplateTail</span> <span class="geq">::</span> <code
+ class="t">}`</code></span> is the empty code unit sequence.</p>
+ </li>
+
+ <li>
+ <p>The TV of <span class="prod"><span class="nt">NoSubstitutionTemplate</span> <span class="geq">::</span> <code
+ class="t">`</code> <span class="nt">TemplateCharacters</span> <code class="t">`</code></span> is the TV of
+ <i>TemplateCharacters</i>.</p>
+ </li>
+
+ <li>
+ <p>The TV of <span class="prod"><span class="nt">TemplateHead</span> <span class="geq">::</span> <code
+ class="t">`</code> <span class="nt">TemplateCharacters</span> <code class="t">${</code></span> is the TV of
+ <i>TemplateCharacters</i>.</p>
+ </li>
+
+ <li>
+ <p>The TV of <span class="prod"><span class="nt">TemplateMiddle</span> <span class="geq">::</span> <code
+ class="t">}</code> <span class="nt">TemplateCharacters</span> <code class="t">${</code></span> is the TV of
+ <i>TemplateCharacters</i>.</p>
+ </li>
+
+ <li>
+ <p>The TV of <span class="prod"><span class="nt">TemplateTail</span> <span class="geq">::</span> <code
+ class="t">}</code> <span class="nt">TemplateCharacters</span> <code class="t">`</code></span> is the TV of
+ <i>TemplateCharacters</i>.</p>
+ </li>
+
+ <li>
+ <p>The TV of <span class="prod"><span class="nt">TemplateCharacters</span> <span class="geq">::</span> <span
+ class="nt">TemplateCharacter</span></span> is the TV of <i>TemplateCharacter</i>.</p>
+ </li>
+
+ <li>
+ <p>The TV of <span class="prod"><span class="nt">TemplateCharacters</span> <span class="geq">::</span> <span
+ class="nt">TemplateCharacter</span> <span class="nt">TemplateCharacters</span></span> is a sequence consisting of the
+ code units in the TV of <i>TemplateCharacter</i> followed by all the code units in the TV of <i>TemplateCharacters</i>
+ in order.</p>
+ </li>
+
+ <li>
+ <p>The TV of <span class="prod"><span class="nt">TemplateCharacter</span> <span class="geq">::</span> <span
+ class="nt">SourceCharacter</span> <span class="grhsmod">but not one of</span> <code class="t">`</code> <span
+ class="grhsmod">or</span> <code class="t">\</code> <span class="grhsmod">or</span> <code class="t">$</code> <span
+ class="grhsmod">or</span> <span class="nt">LineTerminatorSequence</span></span> is the <a
+ href="#sec-static-semantics-utf-16encoding">UTF-16Encoding</a> (<a
+ href="#sec-static-semantics-utf-16encoding">10.1.1</a>) of the code point value of <i>SourceCharacter</i>.</p>
+ </li>
+
+ <li>
+ <p>The TV of <span class="prod"><span class="nt">TemplateCharacter</span> <span class="geq">::</span> <code
+ class="t">$</code></span> is the code unit value 0x0024.</p>
+ </li>
+
+ <li>
+ <p>The TV of <span class="prod"><span class="nt">TemplateCharacter</span> <span class="geq">::</span> <code
+ class="t">\</code> <span class="nt">EscapeSequence</span></span> is the CV of <i>EscapeSequence</i>.</p>
+ </li>
+
+ <li>
+ <p>The TV of <span class="prod"><span class="nt">TemplateCharacter</span> <span class="geq">::</span> <span
+ class="nt">LineContinuation</span></span> is the TV of <i>LineContinuation</i>.</p>
+ </li>
+
+ <li>
+ <p>The TV of <span class="prod"><span class="nt">TemplateCharacter</span> <span class="geq">::</span> <span
+ class="nt">LineTerminatorSequence</span></span> is the TRV of <i>LineTerminatorSequence</i>.</p>
+ </li>
+
+ <li>
+ <p>The TV of <span class="prod"><span class="nt">LineContinuation</span> <span class="geq">::</span> <code
+ class="t">\</code> <span class="nt">LineTerminatorSequence</span></span> is the empty code unit sequence.</p>
+ </li>
+
+ <li>
+ <p>The TRV of <span class="prod"><span class="nt">NoSubstitutionTemplate</span> <span class="geq">::</span> <code
+ class="t">`</code> <span class="nt">TemplateCharacters</span> <code class="t">`</code></span> is the TRV of
+ <i>TemplateCharacters</i>.</p>
+ </li>
+
+ <li>
+ <p>The TRV of <span class="prod"><span class="nt">TemplateHead</span> <span class="geq">::</span> <code
+ class="t">`</code> <span class="nt">TemplateCharacters</span> <code class="t">${</code></span> is the TRV of
+ <i>TemplateCharacters</i>.</p>
+ </li>
+
+ <li>
+ <p>The TRV of <span class="prod"><span class="nt">TemplateMiddle</span> <span class="geq">::</span> <code
+ class="t">}</code> <span class="nt">TemplateCharacters</span> <code class="t">${</code></span> is the TRV of
+ <i>TemplateCharacters</i>.</p>
+ </li>
+
+ <li>
+ <p>The TRV of <span class="prod"><span class="nt">TemplateTail</span> <span class="geq">::</span> <code
+ class="t">}</code> <span class="nt">TemplateCharacters</span> <code class="t">`</code></span> is the TRV of
+ <i>TemplateCharacters</i>.</p>
+ </li>
+
+ <li>
+ <p>The TRV of <span class="prod"><span class="nt">TemplateCharacters</span> <span class="geq">::</span> <span
+ class="nt">TemplateCharacter</span></span> is the TRV of <i>TemplateCharacter</i>.</p>
+ </li>
+
+ <li>
+ <p>The TRV of <span class="prod"><span class="nt">TemplateCharacters</span> <span class="geq">::</span> <span
+ class="nt">TemplateCharacter</span> <span class="nt">TemplateCharacters</span></span> is a sequence consisting of the
+ code units in the TRV of <i>TemplateCharacter</i> followed by all the code units in the TRV of
+ <i>TemplateCharacters,</i> in order.</p>
+ </li>
+
+ <li>
+ <p>The TRV of <span class="prod"><span class="nt">TemplateCharacter</span> <span class="geq">::</span> <span
+ class="nt">SourceCharacter</span> <span class="grhsmod">but not one of</span> <code class="t">`</code> <span
+ class="grhsmod">or</span> <code class="t">\</code> <span class="grhsmod">or</span> <code class="t">$</code> <span
+ class="grhsmod">or</span> <span class="nt">LineTerminatorSequence</span></span> is the <a
+ href="#sec-static-semantics-utf-16encoding">UTF-16Encoding</a> (<a
+ href="#sec-static-semantics-utf-16encoding">10.1.1</a>) of the code point value of <i>SourceCharacter</i>.</p>
+ </li>
+
+ <li>
+ <p>The TRV of <span class="prod"><span class="nt">TemplateCharacter</span> <span class="geq">::</span> <code
+ class="t">$</code></span> is the code unit value 0x0024.</p>
+ </li>
+
+ <li>
+ <p>The TRV of <span class="prod"><span class="nt">TemplateCharacter</span> <span class="geq">::</span> <code
+ class="t">\</code> <span class="nt">EscapeSequence</span></span> is the sequence consisting of the code unit value
+ 0x005C followed by the code units of TRV of <i>EscapeSequence</i>.</p>
+ </li>
+
+ <li>
+ <p>The TRV of <span class="prod"><span class="nt">TemplateCharacter</span> <span class="geq">::</span> <span
+ class="nt">LineContinuation</span></span> is the TRV of <i>LineContinuation</i>.</p>
+ </li>
+
+ <li>
+ <p>The TRV of <span class="prod"><span class="nt">TemplateCharacter</span> <span class="geq">::</span> <span
+ class="nt">LineTerminatorSequence</span></span> is the TRV of <i>LineTerminatorSequence</i>.</p>
+ </li>
+
+ <li>
+ <p>The TRV of <span class="prod"><span class="nt">EscapeSequence</span> <span class="geq">::</span> <span
+ class="nt">CharacterEscapeSequence</span></span> is the TRV of the <i>CharacterEscapeSequence</i>.</p>
+ </li>
+
+ <li>
+ <p>The TRV of <span class="prod"><span class="nt">EscapeSequence</span> <span class="geq">::</span> <code
+ class="t">0</code></span> is the code unit value 0x0030.</p>
+ </li>
+
+ <li>
+ <p>The TRV of <span class="prod"><span class="nt">EscapeSequence</span> <span class="geq">::</span> <span
+ class="nt">HexEscapeSequence</span></span> is the TRV of the <i>HexEscapeSequence</i>.</p>
+ </li>
+
+ <li>
+ <p>The TRV of <span class="prod"><span class="nt">EscapeSequence</span> <span class="geq">::</span> <span
+ class="nt">UnicodeEscapeSequence</span></span> is the TRV of the <i>UnicodeEscapeSequence</i>.</p>
+ </li>
+
+ <li>
+ <p>The TRV of <span class="prod"><span class="nt">CharacterEscapeSequence</span> <span class="geq">::</span> <span
+ class="nt">SingleEscapeCharacter</span></span> is the TRV of the <i>SingleEscapeCharacter</i>.</p>
+ </li>
+
+ <li>
+ <p>The TRV of <span class="prod"><span class="nt">CharacterEscapeSequence</span> <span class="geq">::</span> <span
+ class="nt">NonEscapeCharacter</span></span> is the CV of the <i>NonEscapeCharacter</i>.</p>
+ </li>
+
+ <li>
+ <p>The TRV of <span class="prod"><span class="nt">SingleEscapeCharacter</span> <span class="geq">::</span> <span
+ class="grhsmod">one of</span> <code class="t">'</code> <code class="t">"</code> <code class="t">\</code> <code
+ class="t">b</code> <code class="t">f</code> <code class="t">n</code> <code class="t">r</code> <code class="t">t</code>
+ <code class="t">v</code></span> is the CV of the <i>SourceCharacter</i> that is that single character.</p>
+ </li>
+
+ <li>
+ <p>The TRV of <span class="prod"><span class="nt">HexEscapeSequence</span> <span class="geq">::</span> <code
+ class="t">x</code> <span class="nt">HexDigit</span> <span class="nt">HexDigit</span></span> is the sequence
+ consisting of code unit value 0x0078 followed by TRV of the first <i>HexDigit</i> followed by the TRV of the second
+ <i>HexDigit</i>.</p>
+ </li>
+
+ <li>
+ <p>The TRV of <span class="prod"><span class="nt">UnicodeEscapeSequence</span> <span class="geq">::</span> <code
+ class="t">u</code> <span class="nt">Hex4Digits</span></span> is the sequence consisting of code unit value 0x0075
+ followed by TRV of <span class="nt">Hex4Digits</span>.</p>
+ </li>
+
+ <li>
+ <p>The TRV of <span class="prod"><span class="nt">UnicodeEscapeSequence</span> <span class="geq">::</span> <code
+ class="t">u{</code> <span class="nt">HexDigits</span> <code class="t">}</code></span> is the sequence consisting of
+ code unit value 0x0075 followed by code unit value 0x007B followed by TRV of <i>HexDigits</i> followed by code unit
+ value 0x007D.</p>
+ </li>
+
+ <li>
+ <p>The TRV of <span class="prod"><span class="nt">Hex4Digits</span> <span class="geq">::</span> <span
+ class="nt">HexDigit</span> <span class="nt">HexDigit</span> <span class="nt">HexDigit</span> <span
+ class="nt">HexDigit</span></span> is the sequence consisting of the TRV of the first <i>HexDigit</i> followed by the
+ TRV of the second <i>HexDigit</i> followed by the TRV of the third <i>HexDigit</i> followed by the TRV of the fourth
+ <span class="nt">HexDigits</span>.</p>
+ </li>
+
+ <li>
+ <p>The TRV of <span class="prod"><span class="nt">HexDigits</span> <span class="geq">::</span> <span
+ class="nt">HexDigit</span></span> is the TRV of <i>HexDigit</i>.</p>
+ </li>
+
+ <li>
+ <p>The TRV of <span class="prod"><span class="nt">HexDigits</span> <span class="geq">::</span> <span
+ class="nt">HexDigits</span> <span class="nt">HexDigit</span></span> is the sequence consisting of TRV of
+ <i>HexDigits</i> followed by TRV of <i>HexDigit</i>.</p>
+ </li>
+
+ <li>
+ <p>The TRV of a <i>HexDigit</i> is the CV of the <i>SourceCharacter</i> that is that <i>HexDigit</i>.</p>
+ </li>
+
+ <li>
+ <p>The TRV of <span class="prod"><span class="nt">LineContinuation</span> <span class="geq">::</span> <code
+ class="t">\</code> <span class="nt">LineTerminatorSequence</span></span> is the sequence consisting of the code unit
+ value 0x005C followed by the code units of TRV of <i>LineTerminatorSequence</i>.</p>
+ </li>
+
+ <li>
+ <p>The TRV of <span class="prod"><span class="nt">LineTerminatorSequence</span> <span class="geq">::</span></span>
+ <LF> is the code unit value 0x000A.</p>
+ </li>
+
+ <li>
+ <p>The TRV of <span class="prod"><span class="nt">LineTerminatorSequence</span> <span class="geq">::</span></span>
+ <CR> is the code unit value 0x000A.</p>
+ </li>
+
+ <li>
+ <p>The TRV of <span class="prod"><span class="nt">LineTerminatorSequence</span> <span class="geq">::</span></span>
+ <LS> is the code unit value 0x2028.</p>
+ </li>
+
+ <li>
+ <p>The TRV of <span class="prod"><span class="nt">LineTerminatorSequence</span> <span class="geq">::</span></span>
+ <PS> is the code unit value 0x2029.</p>
+ </li>
+
+ <li>
+ <p>The TRV of <span class="prod"><span class="nt">LineTerminatorSequence</span> <span class="geq">::</span></span>
+ <CR><LF> is the sequence consisting of the code unit value 0x000A.</p>
+ </li>
+ </ul>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> TV excludes the code units of <i>LineContinuation</i> while TRV includes them.
+ <CR><LF> and <CR> <i>LineTerminatorSequences</i> are normalized to <LF> for both TV and TRV. An
+ explicit <i>EscapeSequence</i> is needed to include a <CR> or <CR><LF> sequence.</p>
+ </div>
+ </section>
+ </section>
+ </section>
+
+ <section id="sec-automatic-semicolon-insertion">
+ <div class="front">
+ <h1><span class="secnum" id="sec-11.9"><a href="#sec-automatic-semicolon-insertion"
+ title="link to this section">11.9</a></span> Automatic Semicolon Insertion</h1>
+
+ <p>Certain ECMAScript statements (empty statement, <code>let</code>, <code>const</code>, <code>import</code>,
+ <code>export</code>, <code>and module</code> declarations, variable statement, expression statement, <code>debugger</code>
+ statement, <code>continue</code> statement, <code>break</code> statement, <code>return</code> statement, and
+ <code>throw</code> statement) must be terminated with semicolons. Such semicolons may always appear explicitly in the source
+ text. For convenience, however, such semicolons may be omitted from the source text in certain situations. These situations
+ are described by saying that semicolons are automatically inserted into the source code token stream in those
+ situations.</p>
+ </div>
+
+ <section id="sec-rules-of-automatic-semicolon-insertion">
+ <h1><span class="secnum" id="sec-11.9.1"><a href="#sec-rules-of-automatic-semicolon-insertion"
+ title="link to this section">11.9.1</a></span> Rules of Automatic Semicolon Insertion</h1>
+
+ <p>There are three basic rules of semicolon insertion:</p>
+
+ <ol class="proc">
+ <li>When, as the script is parsed from left to right, a token (called the <i>offending token</i>) is encountered that is
+ not allowed by any production of the grammar, then a semicolon is automatically inserted before the offending token if
+ one or more of the following conditions is true:
+ <ul>
+ <li>The offending token is separated from the previous token by at least one <i>LineTerminator</i>.</li>
+ <li>The offending token is <code>}</code>.</li>
+ </ul>
+ </li>
+ <li>When, as the script is parsed from left to right, the end of the input stream of tokens is encountered and the parser
+ is unable to parse the input token stream as a single complete ECMAScript <var>script</var>, then a semicolon is
+ automatically inserted at the end of the input stream.</li>
+ <li>When, as the script is parsed from left to right, a token is encountered that is allowed by some production of the
+ grammar, but the production is a <i>restricted production</i> and the token would be the first token for a terminal or
+ nonterminal immediately following the annotation <span style="font-family: Times New Roman">“</span>[no <span
+ style="font-family: Times New Roman"><i>LineTerminator</i></span> here]<span style="font-family: Times New
+ Roman">”</span> within the restricted production (and therefore such a token is called a restricted token), and
+ the restricted token is separated from the previous token by at least one <span class="nt">LineTerminator</span>, then
+ a semicolon is automatically inserted before the restricted token.</li>
+ </ol>
+
+ <p>However, there is an additional overriding condition on the preceding rules: a semicolon is never inserted automatically
+ if the semicolon would then be parsed as an empty statement or if that semicolon would become one of the two semicolons in
+ the header of a <code>for</code> statement (<a href="#sec-for-statement">see 13.6.3</a>).</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The following are the only restricted productions in the grammar:</p>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">PostfixExpression</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">LeftHandSideExpression</span><sub>[?Yield]</sub> <span class="grhsannot">[no <span class="nt">LineTerminator</span> here]</span> <code class="t">++</code></div>
+ <div class="rhs"><span class="nt">LeftHandSideExpression</span><sub>[?Yield]</sub> <span class="grhsannot">[no <span class="nt">LineTerminator</span> here]</span> <code class="t">--</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ContinueStatement</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">continue;</code></div>
+ <div class="rhs"><code class="t">continue</code> <span class="grhsannot">[no <span class="nt">LineTerminator</span> here]</span> <span class="nt">LabelIdentifier</span><sub>[?Yield]</sub> <code class="t">;</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">BreakStatement</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">break</code> <code class="t">;</code></div>
+ <div class="rhs"><code class="t">break</code> <span class="grhsannot">[no <span class="nt">LineTerminator</span> here]</span> <span class="nt">LabelIdentifier</span><sub>[?Yield]</sub> <code class="t">;</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ReturnStatement</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">return</code> <span class="grhsannot">[no <span class="nt">LineTerminator</span> here]</span> <span class="nt">Expression</span> <code class="t">;</code></div>
+ <div class="rhs"><code class="t">return</code> <span class="grhsannot">[no <span class="nt">LineTerminator</span> here]</span> <span class="nt">Expression</span><sub>[In, ?Yield]</sub> <code class="t">;</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ThrowStatement</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">throw</code> <span class="grhsannot">[no <span class="nt">LineTerminator</span> here]</span> <span class="nt">Expression</span><sub>[In, ?Yield]</sub> <code class="t">;</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ArrowFunction</span><sub>[In, Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">ArrowParameters</span><sub>[?Yield]</sub> <span class="grhsannot">[no <span class="nt">LineTerminator</span> here]</span> <code class="t">=></code> <span class="nt">ConciseBody</span><sub>[?In]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">YieldExpression</span><sub>[In]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">yield</code> <span class="grhsannot">[no <span class="nt">LineTerminator</span> here]</span> <code class="t">*</code> <span class="grhsannot">[Lexical goal <span class="nt">InputElementRegExp</span>]</span> <span class="nt">AssignmentExpression</span><sub>[?In, Yield]</sub></div>
+ <div class="rhs"><code class="t">yield</code> <span class="grhsannot">[no <span class="nt">LineTerminator</span> here]</span> <span class="grhsannot">[Lexical goal <span class="nt">InputElementRegExp</span>]</span> <span class="nt">AssignmentExpression</span><sub>[?In, Yield]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ModuleImport</span> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">module</code> <span class="grhsannot">[no <span class="nt">LineTerminator</span> here]</span> <span class="nt">ImportedBinding</span> <span class="nt">FromClause</span> <code class="t">;</code></div>
+ </div>
+
+ <p>The practical effect of these restricted productions is as follows:</p>
+
+ <p>When a <code>++</code> or <code>--</code> token is encountered where the parser would treat it as a postfix operator, and
+ at least one <span class="nt">LineTerminator</span> occurred between the preceding token and the <code>++</code> or
+ <code>--</code> token, then a semicolon is automatically inserted before the <code>++</code> or <code>--</code> token.</p>
+
+ <p>When a <code>continue</code>, <code>break</code>, <code>return</code>, <code>throw</code>, or <code>yield</code> token is
+ encountered and a <span class="nt">LineTerminator</span> is encountered before the next token, a semicolon is automatically
+ inserted after the <code>continue</code>, <code>break</code>, <code>return</code>, <code>throw</code>, or <code>yield</code>
+ token.</p>
+
+ <p>The resulting practical advice to ECMAScript programmers is:</p>
+
+ <p>A postfix <code>++</code> or <code>--</code> operator should appear on the same line as its operand.</p>
+
+ <p>An <span class="nt">Expression</span> in a <code>return</code> or <code>throw</code> statement or an <span
+ class="nt">AssignmentExpression</span> in a <code>yield</code> expression should start on the same line as the
+ <code>return</code>, <code>throw</code>, or <code>yield</code> token.</p>
+
+ <p>An <span class="nt">IdentifierReference</span> in a <code>break</code> or <code>continue</code> statement should be on
+ the same line as the <code>break</code> or <code>continue</code> token.</p>
+ </section>
+
+ <section id="sec-examples-of-automatic-semicolon-insertion">
+ <h1><span class="secnum" id="sec-11.9.2"><a href="#sec-examples-of-automatic-semicolon-insertion"
+ title="link to this section">11.9.2</a></span> Examples of Automatic Semicolon Insertion</h1>
+
+ <p>The source</p>
+
+ <pre>{ 1 2 } 3</pre>
+
+ <p>is not a valid sentence in the ECMAScript grammar, even with the <a href="#sec-automatic-semicolon-insertion">automatic
+ semicolon insertion</a> rules. In contrast, the source</p>
+
+ <pre>{ 1<br>2 } 3</pre>
+
+ <p>is also not a valid ECMAScript sentence, but is transformed by <a href="#sec-automatic-semicolon-insertion">automatic
+ semicolon insertion</a> into the following:</p>
+
+ <pre>{ 1<br>;2 ;} 3;</pre>
+
+ <p>which is a valid ECMAScript sentence.</p>
+
+ <p>The source</p>
+
+ <pre>for (a; b<br>)</pre>
+
+ <p>is not a valid ECMAScript sentence and is not altered by <a href="#sec-automatic-semicolon-insertion">automatic semicolon
+ insertion</a> because the semicolon is needed for the header of a <code>for</code> statement. Automatic semicolon insertion
+ never inserts one of the two semicolons in the header of a <code>for</code> statement.</p>
+
+ <p>The source</p>
+
+ <pre>return<br>a + b</pre>
+
+ <p>is transformed by <a href="#sec-automatic-semicolon-insertion">automatic semicolon insertion</a> into the following:</p>
+
+ <pre>return;<br>a + b;</pre>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The expression <code>a + b</code> is not treated as a value to be returned by the
+ <code>return</code> statement, because a <i>LineTerminator</i> separates it from the token <code>return</code>.</p>
+ </div>
+
+ <p>The source</p>
+
+ <pre>a = b<br>++c</pre>
+
+ <p>is transformed by <a href="#sec-automatic-semicolon-insertion">automatic semicolon insertion</a> into the following:</p>
+
+ <pre>a = b;<br>++c;</pre>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The token <code>++</code> is not treated as a postfix operator applying to the variable
+ <code>b</code>, because a <i>LineTerminator</i> occurs between <code>b</code> and <code>++</code>.</p>
+ </div>
+
+ <p>The source</p>
+
+ <pre>if (a > b)<br>else c = d</pre>
+
+ <p>is not a valid ECMAScript sentence and is not altered by <a href="#sec-automatic-semicolon-insertion">automatic semicolon
+ insertion</a> before the <code>else</code> token, even though no production of the grammar applies at that point, because an
+ automatically inserted semicolon would then be parsed as an empty statement.</p>
+
+ <p>The source</p>
+
+ <pre>a = b + c<br>(d + e).print()</pre>
+
+ <p>is <i>not</i> transformed by <a href="#sec-automatic-semicolon-insertion">automatic semicolon insertion</a>, because the
+ parenthesized expression that begins the second line can be interpreted as an argument list for a function call:</p>
+
+ <pre>a = b + c(d + e).print()</pre>
+
+ <p>In the circumstance that an assignment statement must begin with a left parenthesis, it is a good idea for the programmer
+ to provide an explicit semicolon at the end of the preceding statement rather than to rely on <a
+ href="#sec-automatic-semicolon-insertion">automatic semicolon insertion</a>.</p>
+ </section>
+ </section>
+</section>
+
+<section id="sec-ecmascript-language-expressions">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12"><a href="#sec-ecmascript-language-expressions" title="link to this section">12</a></span>
+ ECMAScript Language: Expressions</h1>
+ </div>
+
+ <section id="sec-identifiers">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.1"><a href="#sec-identifiers" title="link to this section">12.1</a></span>
+ Identifiers</h1>
+
+ <p><b>Syntax</b></p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">IdentifierReference</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">Identifier</span></div>
+ <div class="rhs"><span class="grhsannot">[~Yield]</span> <code class="t">yield</code></div>
+ </div>
+
+ <p><i>BindingIdentifier</i><span style="font-family: sans-serif"><sub>[Default, Yield]</sub></span> <b>:</b></p>
+
+ <p>[+Default] <code>default</code><br>[~Yield] <code>yield</code><span style="font-family: Times New
+ Roman"><i><br>Identifier</i></span></p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">LabelIdentifier</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">Identifier</span></div>
+ <div class="rhs"><span class="grhsannot">[~Yield]</span> <code class="t">yield</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">Identifier</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">IdentifierName</span> <span class="grhsmod">but not</span> <span class="nt">ReservedWord</span></div>
+ </div>
+ </div>
+
+ <section id="sec-identifiers-static-semantics-early-errors">
+ <h1><span class="secnum" id="sec-12.1.1"><a href="#sec-identifiers-static-semantics-early-errors"
+ title="link to this section">12.1.1</a></span> Static Semantics: Early Errors</h1>
+ <div class="gp prod"><span class="nt">BindingIdentifier</span> <span class="geq">:</span> <span class="nt">Identifier</span></div>
+ <ul>
+ <li>
+ <p>It is a Syntax Error if this production is contained in <a href="#sec-strict-mode-code">strict code</a> and the
+ StringValue of <span class="nt">Identifier</span> is <code>"arguments"</code> or <code>"eval"</code>.</p>
+ </li>
+ </ul>
+
+ <p><i>IdentifierReference</i><span style="font-family: sans-serif"><sub>[Yield]</sub> <b>:</b></span> <i>Identifier</i></p>
+
+ <p><i>BindingIdentifier</i><span style="font-family: sans-serif"><sub>[Default, Yield]</sub> <b>:</b></span>
+ <i>Identifier</i></p>
+
+ <p><i>LabelIdentifier</i> <span style="font-family: sans-serif"><sub>[Yield]</sub></span> <code>:</code>
+ <i>Identifier</i></p>
+
+ <ul>
+ <li>
+ <p>It is a Syntax Error if this production has a <sub>[Yield]</sub> parameter and the StringValue of <span
+ class="nt">Identifier</span> is <code>"yield"</code><span style="font-family: Times New Roman">.</span></p>
+ </li>
+ </ul>
+
+ <p><span class="prod"><span class="nt">IdentifierReference</span> <span class="geq">:</span> <code
+ class="t">yield</code></span></p>
+
+ <p><span class="prod"><span class="nt">BindingIdentifier</span> <span class="geq">:</span> <code
+ class="t">yield</code></span></p>
+
+ <div class="gp prod"><span class="nt">LabelIdentifier</span> <span class="geq">:</span> <code class="t">yield</code></div>
+ <ul>
+ <li>
+ <p>It is a Syntax Error if this production is contained in <a href="#sec-strict-mode-code">strict
+ code</a><var>.</var></p>
+ </li>
+
+ <li>
+ <p>It is a Syntax Error if this production is within the <span class="nt">FunctionBody</span> of a <i><span
+ style="font-family: Times New Roman">GeneratorMethod</span>, <span style="font-family: Times New
+ Roman">GeneratorDeclaration</span>,</i> or <span class="nt">GeneratorExpression</span>.</p>
+ </li>
+ </ul>
+ <div class="gp prod"><span class="nt">Identifier</span> <span class="geq">::</span> <span class="nt">IdentifierName</span> <span class="grhsmod">but not</span> <span class="nt">ReservedWord</span></div>
+ <ul>
+ <li>
+ <p>It is a Syntax Error if this production is contained in <a href="#sec-strict-mode-code">strict code</a> and the
+ StringValue of <span class="nt">IdentifierName</span> is: <code>"implements"</code>, <code>"interface"</code>,
+ <code>"let"</code>, <code>"package"</code>, <code>"private"</code>, <code>"protected"</code>, <code>"public"</code>, or
+ <code>"static"</code>.</p>
+ </li>
+
+ <li>
+ <p>It is a Syntax Error if this production is contained in <a href="#sec-strict-mode-code">strict code</a> and the
+ StringValue of <span class="nt">IdentifierName</span> is <code>"yield"</code>.</p>
+ </li>
+
+ <li>
+ <p>It is a Syntax Error if StringValue of <span class="nt">IdentifierName</span> is the same string value as the
+ StringValue of any <span class="nt">ReservedWord</span> except for <code>yield</code>.</p>
+ </li>
+ </ul>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> <span style="font-family: sans-serif">StringValue of</span> <i>IdentifierName</i>
+ normalizes any Unicode escape sequences in <i>IdentifierName</i> hence such escapes cannot be used to write an
+ <i>Identifier</i> whose code point sequence is the same as a <i>ReservedWord</i>.</p>
+ </div>
+ </section>
+
+ <section id="sec-identifiers-static-semantics-boundnames">
+ <h1><span class="secnum" id="sec-12.1.2"><a href="#sec-identifiers-static-semantics-boundnames"
+ title="link to this section">12.1.2</a></span> Static Semantics: BoundNames</h1>
+
+ <p>See also: <a href="#sec-let-and-const-declarations-static-semantics-boundnames">13.2.1.2</a>, <a
+ href="#sec-variable-statement-static-semantics-boundnames">13.2.2.1</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-boundnames">13.6.4.2</a>, <a
+ href="#sec-function-definitions-static-semantics-boundnames">14.1.3</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-boundnames">14.2.2</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-boundnames">14.4.2</a>, <a
+ href="#sec-class-definitions-static-semantics-boundnames">14.5.2</a>, <a
+ href="#sec-imports-static-semantics-boundnames">15.2.1.2</a>, <a
+ href="#sec-exports-static-semantics-boundnames">15.2.2.1</a>.</p>
+
+ <div class="gp prod"><span class="nt">BindingIdentifier</span> <span class="geq">:</span> <span class="nt">Identifier</span></div>
+ <ol class="proc">
+ <li>Return a new <a href="#sec-list-and-record-specification-type">List</a> containing the StringValue of
+ <i>Identifier</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">BindingIdentifier</span> <span class="geq">:</span> <code class="t">yield</code></div>
+ <ol class="proc">
+ <li>Return a new <a href="#sec-list-and-record-specification-type">List</a> containing <code>"yield"</code>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">BindingIdentifier</span> <span class="geq">:</span> <code class="t">default</code></div>
+ <ol class="proc">
+ <li>Return a new <a href="#sec-list-and-record-specification-type">List</a> containing <code>"default"</code>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-identifiers-static-semantics-stringvalue">
+ <h1><span class="secnum" id="sec-12.1.3"><a href="#sec-identifiers-static-semantics-stringvalue"
+ title="link to this section">12.1.3</a></span> Static Semantics<span style="font-family: sans-serif">:</span>
+ <i>StringValue</i></h1>
+
+ <p>See also: <a href="#sec-identifier-names-static-semantics-stringvalue">11.6.1.2</a>, <a
+ href="#sec-string-literals-static-semantics-stringvalue">11.8.4.2</a>.</p>
+
+ <p><span class="prod"><span class="nt">IdentifierReference</span> <span class="geq">:</span> <code
+ class="t">yield</code></span></p>
+
+ <p><span class="prod"><span class="nt">BindingIdentifier</span> <span class="geq">:</span> <code
+ class="t">yield</code></span></p>
+
+ <div class="gp prod"><span class="nt">LabelIdentifier</span> <span class="geq">:</span> <code class="t">yield</code></div>
+ <ol class="proc">
+ <li>Return <code>"yield"</code>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">BindingIdentifier</span> <span class="geq">:</span> <code class="t">default</code></div>
+ <ol class="proc">
+ <li>Return <code>"default"</code>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">Identifier</span> <span class="geq">:</span> <span class="nt">IdentifierName</span> <span class="grhsmod">but not</span> <span class="nt">ReservedWord</span></div>
+ <ol class="proc">
+ <li>Return the StringValue of <i>IdentifierName</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-identifiers-runtime-semantics-bindinginitialization">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.1.4"><a href="#sec-identifiers-runtime-semantics-bindinginitialization"
+ title="link to this section">12.1.4</a></span> Runtime Semantics: BindingInitialization</h1>
+
+ <p>With arguments <var>value</var> and <var>environment</var>.</p>
+
+ <p>See also: <a href="#sec-array-comprehension-runtime-semantics-bindinginitialization">12.2.4.2.2</a>, <a
+ href="#sec-variable-statement-static-semantics-vardeclarednames">13.2.2.2</a>, <a
+ href="#sec-destructuring-binding-patterns-static-semantics-issimpleparameterlist">13.2.3.4</a>, <a
+ href="#sec-try-statement-static-semantics-varscopeddeclarations">13.14.3</a>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> <b>undefined</b> is passed for <var>environment</var> to indicate that a <a
+ href="#sec-putvalue">PutValue</a> operation should be used to assign the initialization value. This is the case for
+ <code>var</code> statements formal parameter lists of non-strict functions. In those cases a lexical binding is hosted
+ and preinitialized prior to evaluation of its initializer.</p>
+ </div>
+
+ <div class="gp prod"><span class="nt">BindingIdentifier</span> <span class="geq">:</span> <span class="nt">Identifier</span></div>
+ <ol class="proc">
+ <li>Let <i>name</i> be StringValue of <i>Identifier</i>.</li>
+ <li>Return <a href="#sec-initializeboundname">InitializeBoundName</a>( <i>name</i>, <i>value</i>,
+ <i>environment</i>).</li>
+ </ol>
+ <div class="gp prod"><span class="nt">BindingIdentifier</span> <span class="geq">:</span> <code class="t">default</code></div>
+ <ol class="proc">
+ <li>Return <a href="#sec-initializeboundname">InitializeBoundName</a>(<code>"default"</code>, <i>value</i>,
+ <i>environment</i>).</li>
+ </ol>
+ <div class="gp prod"><span class="nt">BindingIdentifier</span> <span class="geq">:</span> <code class="t">yield</code></div>
+ <ol class="proc">
+ <li>Return <a href="#sec-initializeboundname">InitializeBoundName</a>(<code>"yield"</code>, <i>value</i>,
+ <i>environment</i>).</li>
+ </ol>
+ </div>
+
+ <section id="sec-initializeboundname">
+ <h1><span class="secnum" id="sec-12.1.4.1"><a href="#sec-initializeboundname"
+ title="link to this section">12.1.4.1</a></span> Runtime Semantics: InitializeBoundName(name, value, environment)</h1>
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>name</i>) is String.</li>
+ <li>If <i>environment</i> is not <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>env</i> be the environment record component of <i>environment</i>.</li>
+ <li>Call the InitializeBinding concrete method of <i>env</i> passing <i>name</i> and <i>value</i> as the
+ arguments.</li>
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<b>undefined</b>).</li>
+ </ol>
+ </li>
+ <li>Else
+ <ol class="block">
+ <li>Let <i>lhs</i> be <a href="#sec-resolvebinding">ResolveBinding</a>(<i>name</i>).</li>
+ <li>Return <a href="#sec-putvalue">PutValue</a>(<i>lhs</i>, <i>value</i>).</li>
+ </ol>
+ </li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-identifiers-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-12.1.5"><a href="#sec-identifiers-runtime-semantics-evaluation"
+ title="link to this section">12.1.5</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">IdentifierReference</span> <span class="geq">:</span> <span class="nt">Identifier</span></div>
+ <ol class="proc">
+ <li>Return <a href="#sec-resolvebinding">ResolveBinding</a>(StringValue(<i>Identifier</i>)).</li>
+ </ol>
+ <div class="gp prod"><span class="nt">IdentifierReference</span> <span class="geq">:</span> <code class="t">yield</code></div>
+ <ol class="proc">
+ <li>Return <a href="#sec-resolvebinding">ResolveBinding</a>(<code>″yield″</code>).</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1:</span> The result of evaluating an <i>IdentifierReference</i> is always a value of type <a
+ href="#sec-reference-specification-type">Reference</a>.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 2:</span> In non-<a href="#sec-strict-mode-code">strict code</a>, the keyword <code>yield</code>
+ may be used as an identifier. Evaluating the <i>IdentifierReference</i> production resolves the binding of
+ <code>yield</code> as if it was an <i>Identifier</i>. Early Error restriction ensures that such an evaluation only can
+ occur for non-<a href="#sec-strict-mode-code">strict code</a>. See <a href="#sec-let-and-const-declarations">13.2.1</a>
+ for the handling of <code>yield</code> in binding creation contexts.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-primary-expression">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.2"><a href="#sec-primary-expression" title="link to this section">12.2</a></span>
+ Primary Expression</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">PrimaryExpression</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">this</code></div>
+ <div class="rhs"><span class="nt">IdentifierReference</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="nt">Literal</span></div>
+ <div class="rhs"><span class="nt">ArrayInitializer</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="nt">ObjectLiteral</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="nt">FunctionExpression</span></div>
+ <div class="rhs"><span class="nt">ClassExpression</span></div>
+ <div class="rhs"><span class="nt">GeneratorExpression</span></div>
+ <div class="rhs"><span class="nt">GeneratorComprehension</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="nt">RegularExpressionLiteral</span></div>
+ <div class="rhs"><span class="nt">TemplateLiteral</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="nt">CoverParenthesizedExpressionAndArrowParameterList</span><sub>[?Yield]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">CoverParenthesizedExpressionAndArrowParameterList</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">(</code> <span class="nt">Expression</span><sub>[In, ?Yield]</sub> <code class="t">)</code></div>
+ <div class="rhs"><code class="t">(</code> <code class="t">)</code></div>
+ <div class="rhs"><code class="t">(</code> <code class="t">...</code> <span class="nt">BindingIdentifier</span><sub>[?Yield]</sub> <code class="t">)</code></div>
+ <div class="rhs"><code class="t">(</code> <span class="nt">Expression</span><sub>[In, ?Yield]</sub> <code class="t">,</code> <code class="t">...</code> <span class="nt">BindingIdentifier</span><sub>[?Yield]</sub> <code class="t">)</code></div>
+ </div>
+
+ <h2>Supplemental Syntax</h2>
+
+ <p>When processing the production</p>
+
+ <p><span class="nt">PrimaryExpression</span><sub>[Yield]</sub> <b>:</b> <span
+ class="nt">CoverParenthesizedExpressionAndArrowParameterList</span><sub>[?Yield]</sub><span style="font-family: Times New
+ Roman"><i><br></i></span>the interpretation of <span class="nt">CoverParenthesizedExpressionAndArrowParameterList</span> is
+ refined using the following grammar:</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ParenthesizedExpression</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">(</code> <span class="nt">Expression</span><sub>[In, ?Yield]</sub> <code class="t">)</code></div>
+ </div>
+ </div>
+
+ <section id="sec-primary-expression-semantics">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.2.0"><a href="#sec-primary-expression-semantics"
+ title="link to this section">12.2.0</a></span> Semantics</h1>
+ </div>
+
+ <section id="sec-static-semantics-coveredparenthesizedexpression">
+ <h1><span class="secnum" id="sec-12.2.0.1"><a href="#sec-static-semantics-coveredparenthesizedexpression"
+ title="link to this section">12.2.0.1</a></span> Static Semantics: CoveredParenthesizedExpression</h1>
+ <div class="gp prod"><span class="nt">CoverParenthesizedExpressionAndArrowParameterList</span><sub>[Yield]</sub> <span class="geq">:</span> <code class="t">(</code> <span class="nt">Expression</span><sub>[In, ?Yield]</sub> <code class="t">)</code></div>
+ <ol class="proc">
+ <li>Return the result of parsing the lexical token stream matched by
+ <i>CoverParenthesizedExpressionAndArrowParameterList</i><sub>[Yield]</sub> using either
+ <i>ParenthesizedExpression</i> or <i>ParenthesizedExpression</i><sub>[Yield]</sub> as the goal symbol depending upon
+ whether the <sub>[Yield]</sub> grammar parameter was present when
+ <i>CoverParenthesizedExpressionAndArrowParameterList was matched.</i></li>
+ </ol>
+ </section>
+
+ <section id="sec-semantics-static-semantics-isfunctiondefinition">
+ <h1><span class="secnum" id="sec-12.2.0.2"><a href="#sec-semantics-static-semantics-isfunctiondefinition"
+ title="link to this section">12.2.0.2</a></span> Static Semantics: IsFunctionDefinition</h1>
+
+ <p>See also: <a href="#sec-grouping-operator-static-semantics-isfunctiondefinition">12.2.10.2</a>, <a
+ href="#sec-static-semantics-static-semantics-isfunctiondefinition">12.3.1.2</a>, <a
+ href="#sec-postfix-expressions-static-semantics-isfunctiondefinition">12.4.2</a>, <a
+ href="#sec-unary-operators-static-semantics-isfunctiondefinition">12.5.2</a>, <a
+ href="#sec-multiplicative-operators-static-semantics-isfunctiondefinition">12.6.1</a>, <a
+ href="#sec-additive-operators-static-semantics-isfunctiondefinition">12.7.1</a>, <a
+ href="#sec-bitwise-shift-operators-static-semantics-isfunctiondefinition">12.8.1</a>, <a
+ href="#sec-relational-operators-static-semantics-isfunctiondefinition">12.9.1</a>, <a
+ href="#sec-equality-operators-static-semantics-isfunctiondefinition">12.10.1</a>, <a
+ href="#sec-binary-bitwise-operators-static-semantics-isfunctiondefinition">12.11.1</a>, <a
+ href="#sec-binary-logical-operators-static-semantics-isfunctiondefinition">12.12.1</a>, <a
+ href="#sec-conditional-operator-static-semantics-isfunctiondefinition">12.13.1</a>, <a
+ href="#sec-assignment-operators-static-semantics-isfunctiondefinition">12.14.2</a>, <a
+ href="#sec-comma-operator-static-semantics-isfunctiondefinition">12.15.1</a>, <a
+ href="#sec-function-definitions-static-semantics-isfunctiondefinition">14.1.11</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-isfunctiondefinition">14.4.8</a>, <a
+ href="#sec-class-definitions-static-semantics-isfunctiondefinition">14.5.8</a>.</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">PrimaryExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">this</code></div>
+ <div class="rhs"><span class="nt">IdentifierReference</span></div>
+ <div class="rhs"><span class="nt">Literal</span></div>
+ <div class="rhs"><span class="nt">ArrayInitializer</span></div>
+ <div class="rhs"><span class="nt">ObjectLiteral</span></div>
+ <div class="rhs"><span class="nt">GeneratorComprehension</span></div>
+ <div class="rhs"><span class="nt">RegularExpressionLiteral</span></div>
+ <div class="rhs"><span class="nt">TemplateLiteral</span></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">PrimaryExpression</span> <span class="geq">:</span> <span class="nt">CoverParenthesizedExpressionAndArrowParameterList</span></div>
+ <ol class="proc">
+ <li>Let <i>expr</i> be CoveredParenthesizedExpression of <i>CoverParenthesizedExpressionAndArrowParameterList</i>.</li>
+ <li>Return IsFunctionDefinition of <i>expr</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-semantics-static-semantics-isidentifierref">
+ <h1><span class="secnum" id="sec-12.2.0.3"><a href="#sec-semantics-static-semantics-isidentifierref"
+ title="link to this section">12.2.0.3</a></span> Static Semantics: IsIdentifierRef</h1>
+
+ <p>See also: <a href="#sec-static-semantics-static-semantics-isidentifierref">12.3.1.3</a>.</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">PrimaryExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">IdentifierReference</span></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return <b>true</b>.</li>
+ </ol>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">PrimaryExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">this</code></div>
+ <div class="rhs"><span class="nt">Literal</span></div>
+ <div class="rhs"><span class="nt">ArrayInitializer</span></div>
+ <div class="rhs"><span class="nt">ObjectLiteral</span></div>
+ <div class="rhs"><span class="nt">FunctionExpression</span></div>
+ <div class="rhs"><span class="nt">ClassExpression</span></div>
+ <div class="rhs"><span class="nt">GeneratorExpression</span></div>
+ <div class="rhs"><span class="nt">GeneratorComprehension</span></div>
+ <div class="rhs"><span class="nt">RegularExpressionLiteral</span></div>
+ <div class="rhs"><span class="nt">TemplateLiteral</span></div>
+ <div class="rhs"><span class="nt">CoverParenthesizedExpressionAndArrowParameterList</span></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-semantics-static-semantics-isvalidsimpleassignmenttarget">
+ <h1><span class="secnum" id="sec-12.2.0.4"><a href="#sec-semantics-static-semantics-isvalidsimpleassignmenttarget"
+ title="link to this section">12.2.0.4</a></span> Static Semantics: IsValidSimpleAssignmentTarget</h1>
+
+ <p>See also: <a href="#sec-grouping-operator-static-semantics-isvalidsimpleassignmenttarget">12.2.10.3</a>, <a
+ href="#sec-static-semantics-static-semantics-isidentifierref">12.3.1.3</a>, <a
+ href="#sec-postfix-expressions-static-semantics-isvalidsimpleassignmenttarget">12.4.3</a>, <a
+ href="#sec-unary-operators-static-semantics-isvalidsimpleassignmenttarget">12.5.3</a>, <a
+ href="#sec-multiplicative-operators-static-semantics-isvalidsimpleassignmenttarget">12.6.2</a>, <a
+ href="#sec-additive-operators-static-semantics-isvalidsimpleassignmenttarget">12.7.2</a>, <a
+ href="#sec-bitwise-shift-operators-static-semantics-isvalidsimpleassignmenttarget">12.8.2</a>, <a
+ href="#sec-relational-operators-static-semantics-isvalidsimpleassignmenttarget">12.9.2</a>, <a
+ href="#sec-equality-operators-static-semantics-isvalidsimpleassignmenttarget">12.10.2</a>, <a
+ href="#sec-binary-bitwise-operators-static-semantics-isvalidsimpleassignmenttarget">12.11.2</a>, <a
+ href="#sec-binary-logical-operators-static-semantics-isvalidsimpleassignmenttarget">12.12.2</a>, <a
+ href="#sec-conditional-operator-static-semantics-isvalidsimpleassignmenttarget">12.13.2</a>, <a
+ href="#sec-assignment-operators-static-semantics-isvalidsimpleassignmenttarget">12.14.3</a>, <a
+ href="#sec-comma-operator-static-semantics-isvalidsimpleassignmenttarget">12.15.2</a>.</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">PrimaryExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">this</code></div>
+ <div class="rhs"><span class="nt">Literal</span></div>
+ <div class="rhs"><span class="nt">ArrayInitializer</span></div>
+ <div class="rhs"><span class="nt">ObjectLiteral</span></div>
+ <div class="rhs"><span class="nt">FunctionExpression</span></div>
+ <div class="rhs"><span class="nt">ClassExpression</span></div>
+ <div class="rhs"><span class="nt">GeneratorExpression</span></div>
+ <div class="rhs"><span class="nt">GeneratorComprehension</span></div>
+ <div class="rhs"><span class="nt">RegularExpressionLiteral</span></div>
+ <div class="rhs"><span class="nt">TemplateLiteral</span></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">PrimaryExpression</span> <span class="geq">:</span> <span class="nt">IdentifierReference</span></div>
+ <ol class="proc">
+ <li>If this <i>PrimaryExpression</i> is contained in <a href="#sec-strict-mode-code">strict code</a> and StringValue of
+ <i>IdentifierReference</i> is <code>"eval"</code> or <code>"arguments"</code>, then return <b>false</b>.</li>
+ <li>Return <b>true</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">PrimaryExpression</span> <span class="geq">:</span> <span class="nt">CoverParenthesizedExpressionAndArrowParameterList</span></div>
+ <ol class="proc">
+ <li>Let <i>expr</i> be CoveredParenthesizedExpression of <i>CoverParenthesizedExpressionAndArrowParameterList</i>.</li>
+ <li>Return IsValidSimpleAssignmentTarget of <i>expr</i>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-this-keyword">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.2.1"><a href="#sec-this-keyword" title="link to this section">12.2.1</a></span> The
+ <code>this</code> Keyword</h1>
+ </div>
+
+ <section id="sec-this-keyword-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-12.2.1.1"><a href="#sec-this-keyword-runtime-semantics-evaluation"
+ title="link to this section">12.2.1.1</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">PrimaryExpression</span> <span class="geq">:</span> <code class="t">this</code></div>
+ <ol class="proc">
+ <li>Return <a href="#sec-resolvethisbinding">ResolveThisBinding</a>( ) .</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-identifier-reference">
+ <h1><span class="secnum" id="sec-12.2.2"><a href="#sec-identifier-reference" title="link to this section">12.2.2</a></span>
+ Identifier Reference</h1>
+
+ <p>See <a href="#sec-identifiers">12.1</a> for <span class="prod"><span class="nt">PrimaryExpression</span> <span
+ class="geq">:</span> <span class="nt">IdentifierReference</span></span> .</p>
+ </section>
+
+ <section id="sec-primary-expression-literals">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.2.3"><a href="#sec-primary-expression-literals"
+ title="link to this section">12.2.3</a></span> Literals</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">Literal</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">NullLiteral</span></div>
+ <div class="rhs"><span class="nt">ValueLiteral</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ValueLiteral</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">BooleanLiteral</span></div>
+ <div class="rhs"><span class="nt">NumericLiteral</span></div>
+ <div class="rhs"><span class="nt">StringLiteral</span></div>
+ </div>
+ </div>
+
+ <section id="sec-literals-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-12.2.3.1"><a href="#sec-literals-runtime-semantics-evaluation"
+ title="link to this section">12.2.3.1</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">Literal</span> <span class="geq">:</span> <span class="nt">NullLiteral</span></div>
+ <ol class="proc">
+ <li>Return <b>null</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ValueLiteral</span> <span class="geq">:</span> <span class="nt">BooleanLiteral</span></div>
+ <ol class="proc">
+ <li>Return <b>false</b> if <i>BooleanLiteral</i> is the token <code>false</code>.</li>
+ <li>Return <b>true</b> if <i>BooleanLiteral</i> is the token <code>true</code>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ValueLiteral</span> <span class="geq">:</span> <span class="nt">NumericLiteral</span></div>
+ <ol class="proc">
+ <li>Return the number whose value is MV of <i>NumericLiteral</i> as defined in <a
+ href="#sec-literals-numeric-literals">11.8.3</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ValueLiteral</span> <span class="geq">:</span> <span class="nt">StringLiteral</span></div>
+ <ol class="proc">
+ <li>Return the StringValue of <i>StringLiteral</i> as defined in <a
+ href="#sec-string-literals-static-semantics-stringvalue">11.8.4.2</a>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-array-initializer">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.2.4"><a href="#sec-array-initializer" title="link to this section">12.2.4</a></span>
+ Array Initializer</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ArrayInitializer</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">ArrayLiteral</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="nt">ArrayComprehension</span><sub>[?Yield]</sub></div>
+ </div>
+ </div>
+
+ <section id="sec-array-literal">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.2.4.1"><a href="#sec-array-literal" title="link to this section">12.2.4.1</a></span>
+ Array Literal</h1>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> An <i>ArrayLiteral</i> is an expression describing the initialization of an Array
+ object, using a list, of zero or more expressions each of which represents an array element, enclosed in square
+ brackets. The elements need not be literals; they are evaluated each time the array initializer is evaluated.</p>
+ </div>
+
+ <p>Array elements may be elided at the beginning, middle or end of the element list. Whenever a comma in the element
+ list is not preceded by an <span class="nt">AssignmentExpression</span> (i.e., a comma at the beginning or after another
+ comma), the missing array element contributes to the length of the Array and increases the index of subsequent elements.
+ Elided array elements are not defined. If an element is elided at the end of an array, that element does not contribute
+ to the length of the Array.</p>
+
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ArrayLiteral</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">[</code> <span class="nt">Elision</span><sub>opt</sub> <code class="t">]</code></div>
+ <div class="rhs"><code class="t">[</code> <span class="nt">ElementList</span><sub>[?Yield]</sub> <code class="t">]</code></div>
+ <div class="rhs"><code class="t">[</code> <span class="nt">ElementList</span><sub>[?Yield]</sub> <code class="t">,</code> <span class="nt">Elision</span><sub>opt</sub> <code class="t">]</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ElementList</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">Elision</span><sub>opt</sub> <span class="nt">AssignmentExpression</span><sub>[In, ?Yield]</sub></div>
+ <div class="rhs"><span class="nt">Elision</span><sub>opt</sub> <span class="nt">SpreadElement</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="nt">ElementList</span><sub>[?Yield]</sub> <code class="t">,</code> <span class="nt">Elision</span><sub>opt</sub> <span class="nt">AssignmentExpression</span><sub>[In, ?Yield]</sub></div>
+ <div class="rhs"><span class="nt">ElementList</span><sub>[?Yield]</sub> <code class="t">,</code> <span class="nt">Elision</span><sub>opt</sub> <span class="nt">SpreadElement</span><sub>[?Yield]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">Elision</span> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">,</code></div>
+ <div class="rhs"><span class="nt">Elision</span> <code class="t">,</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">SpreadElement</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">...</code> <span class="nt">AssignmentExpression</span><sub>[In, ?Yield]</sub></div>
+ </div>
+ </div>
+
+ <section id="sec-static-semantics-elisionwidth">
+ <h1><span class="secnum" id="sec-12.2.4.1.1"><a href="#sec-static-semantics-elisionwidth"
+ title="link to this section">12.2.4.1.1</a></span> Static Semantics: ElisionWidth</h1>
+ <div class="gp prod"><span class="nt">Elision</span> <span class="geq">:</span> <code class="t">,</code></div>
+ <ol class="proc">
+ <li>Return the numeric value 1.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">Elision</span> <span class="geq">:</span> <span class="nt">Elision</span> <code class="t">,</code></div>
+ <ol class="proc">
+ <li>Let <i>preceding</i> be the ElisionWidth of <i>Elision</i>.</li>
+ <li>Return <i>preceding</i>+1.</li>
+ </ol>
+ </section>
+
+ <section id="sec-runtime-semantics-arrayaccumulation">
+ <h1><span class="secnum" id="sec-12.2.4.1.2"><a href="#sec-runtime-semantics-arrayaccumulation"
+ title="link to this section">12.2.4.1.2</a></span> Runtime Semantics: ArrayAccumulation</h1>
+
+ <p>With parameters <var>array</var> and <var>nextIndex</var>.</p>
+
+ <div class="gp prod"><span class="nt">ElementList</span> <span class="geq">:</span> <span class="nt">Elision</span><sub>opt</sub> <span class="nt">AssignmentExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>padding</i> be the ElisionWidth of <i>Elision</i>; if <i>Elision</i> is not present, use the numeric value
+ zero.</li>
+ <li>Let <i>initResult</i> be the result of evaluating <i>AssignmentExpression</i>.</li>
+ <li>Let <i>initValue</i> be <a href="#sec-getvalue">GetValue</a>(<i>initResult</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>initValue</i>).</li>
+ <li>Let <i>created</i> be the result of calling the [[DefineOwnProperty]] internal method of <i>array</i> with
+ arguments <a href="#sec-tostring">ToString</a>(<a href="#sec-touint32">ToUint32</a>(<i>nextIndex+padding</i>)) and
+ the PropertyDescriptor{ [[Value]]: <i>initValue</i>, [[Writable]]: <b>true</b>, [[Enumerable]]: <b>true</b>,
+ [[Configurable]]: <b>true</b>}.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>created</i> is <b>true</b><i>.</i></li>
+ <li>Return <i>nextIndex+padding+</i>1.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ElementList</span> <span class="geq">:</span> <span class="nt">Elision</span><sub>opt</sub> <span class="nt">SpreadElement</span></div>
+ <ol class="proc">
+ <li>Let <i>padding</i> be the ElisionWidth of <i>Elision</i>; if <i>Elision</i> is not present, use the numeric value
+ zero.</li>
+ <li>Return the result of performing ArrayAccumulation for <i>SpreadElement</i> with arguments <i>array</i> and
+ <i>nextIndex</i>+<i>padding</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ElementList</span> <span class="geq">:</span> <span class="nt">ElementList</span> <code class="t">,</code> <span class="nt">Elision</span><sub>opt</sub> <span class="nt">AssignmentExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>postIndex</i> be the result of performing ArrayAccumulation for <i>ElementList</i> with arguments
+ <i>array</i> and <i>nextIndex</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>postIndex</i>).</li>
+ <li>Let <i>padding</i> be the ElisionWidth of <i>Elision</i>; if <i>Elision</i> is not present, use the numeric value
+ zero.</li>
+ <li>Let <i>initResult</i> be the result of evaluating <i>AssignmentExpression</i>.</li>
+ <li>Let <i>initValue</i> be <a href="#sec-getvalue">GetValue</a>(<i>initResult</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>initValue</i>).</li>
+ <li>Let <i>created</i> be the result of calling the [[DefineOwnProperty]] internal method of <i>array</i> with
+ arguments <a href="#sec-tostring">ToString</a>(<a
+ href="#sec-touint32">ToUint32</a>(<i>postIndex</i>+<i>padding</i>)) and the PropertyDescriptor{ [[Value]]:
+ <i>initValue</i>, [[Writable]]: <b>true</b>, [[Enumerable]]: <b>true</b>, [[Configurable]]: <b>true</b>}.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>created</i> is <b>true</b>.</li>
+ <li>Return <i>postIndex</i>+<i>padding+</i>1.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ElementList</span> <span class="geq">:</span> <span class="nt">ElementList</span> <code class="t">,</code> <span class="nt">Elision</span><sub>opt</sub> <span class="nt">SpreadElement</span></div>
+ <ol class="proc">
+ <li>Let <i>postIndex</i> be the result of performing ArrayAccumulation for <i>ElementList</i> with arguments
+ <i>array</i> and <i>nextIndex</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>postIndex</i>).</li>
+ <li>Let <i>padding</i> be the ElisionWidth of <i>Elision</i>; if <i>Elision</i> is not present, use the numeric value
+ zero.</li>
+ <li>Return the result of performing ArrayAccumulation for <i>SpreadElement</i> with arguments <i>array</i> and
+ <i>postIndex</i>+<i>padding</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">SpreadElement</span> <span class="geq">:</span> <code class="t">...</code> <span class="nt">AssignmentExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>spreadRef</i> be the result of evaluating <i>AssignmentExpression</i>.</li>
+ <li>Let <i>spreadObj</i> be <a href="#sec-getvalue">GetValue</a>(<i>spreadRef</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>spreadObj</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>spreadObj</i>) is not Object, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>Let <i>iterator</i> be <a href="#sec-getiterator">GetIterator</a>(<i>spreadObj</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>iterator</i>).</li>
+ <li>Repeat
+ <ol class="block">
+ <li>Let <i>next</i> be <a href="#sec-iteratorstep">IteratorStep</a>(<i>iterator</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>next</i>).</li>
+ <li>If <i>next</i> is <b>false</b>, then return <i>nextIndex</i>.</li>
+ <li>Let <i>nextValue</i> be <a href="#sec-iteratorvalue">IteratorValue</a>(<i>next</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>nextValue</i>).</li>
+ <li>Let <i>defineStatus</i> be <a
+ href="#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a>(<i>array</i>, <a
+ href="#sec-tostring">ToString</a>(<a href="#sec-touint32">ToUint32</a>(<i>nextIndex</i>)),
+ <i>nextValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>defineStatus</i>).</li>
+ <li>Let <i>nextIndex</i> be <i>nextIndex</i> + 1.</li>
+ </ol>
+ </li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> [[DefineOwnProperty]] is used to ensure that own properties are defined for the array
+ even if the standard built-in Array prototype object has been modified in a manner that would preclude the creation of
+ new own properties using [[Set]].</p>
+ </div>
+ </section>
+
+ <section id="sec-array-literal-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-12.2.4.1.3"><a href="#sec-array-literal-runtime-semantics-evaluation"
+ title="link to this section">12.2.4.1.3</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">ArrayLiteral</span> <span class="geq">:</span> <code class="t">[</code> <span class="nt">Elision</span><sub>opt</sub> <code class="t">]</code></div>
+ <ol class="proc">
+ <li>Let <i>array</i> be <a href="#sec-arraycreate">ArrayCreate</a>(0).</li>
+ <li>Let <i>pad</i> be the ElisionWidth of <i>Elision</i>; if <i>Elision</i> is not present, use the numeric value
+ zero.</li>
+ <li>Perform <a href="#sec-put-o-p-v-throw">Put</a>(<i>array</i>, <code>"length"</code>, <i>pad</i>,
+ <b>false</b>).</li>
+ <li>Return <i>array</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ArrayLiteral</span> <span class="geq">:</span> <code class="t">[</code> <span class="nt">ElementList</span> <code class="t">]</code></div>
+ <ol class="proc">
+ <li>Let <i>array</i> be <a href="#sec-arraycreate">ArrayCreate</a>(0).</li>
+ <li>Let <i>len</i> be the result of performing ArrayAccumulation for <i>ElementList</i> with arguments <i>array</i>
+ and 0.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>len</i>).</li>
+ <li>Perform <a href="#sec-put-o-p-v-throw">Put</a>(<i>array</i>, <code>"length"</code>, <i>len</i>,
+ <b>false</b>).</li>
+ <li>Return <i>array</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ArrayLiteral</span> <span class="geq">:</span> <code class="t">[</code> <span class="nt">ElementList</span> <code class="t">,</code> <span class="nt">Elision</span><sub>opt</sub> <code class="t">]</code></div>
+ <ol class="proc">
+ <li>Let <i>array</i> be <a href="#sec-arraycreate">ArrayCreate</a>(0).</li>
+ <li>Let <i>len</i> be the result of performing ArrayAccumulation for <i>ElementList</i> with arguments <i>array</i>
+ and 0.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>len</i>).</li>
+ <li>Let <i>padding</i> be the ElisionWidth of <i>Elision</i>; if <i>Elision</i> is not present, use the numeric value
+ zero.</li>
+ <li>Perform <a href="#sec-put-o-p-v-throw">Put</a>(<i>array</i>, <code>"length"</code>, <a
+ href="#sec-touint32">ToUint32</a>(<i>padding</i>+<i>len</i>), <b>false</b>).</li>
+ <li>Return <i>array</i>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-array-comprehension">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.2.4.2"><a href="#sec-array-comprehension"
+ title="link to this section">12.2.4.2</a></span> Array Comprehension</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ArrayComprehension</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">[</code> <span class="nt">Comprehension</span><sub>[?Yield]</sub> <code class="t">]</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">Comprehension</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">ComprehensionFor</span><sub>[?Yield]</sub> <span class="nt">ComprehensionTail</span><sub>[?Yield]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ComprehensionTail</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">AssignmentExpression</span><sub>[In, ?Yield]</sub></div>
+ <div class="rhs"><span class="nt">ComprehensionFor</span><sub>[?Yield]</sub> <span class="nt">ComprehensionTail</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="nt">ComprehensionIf</span><sub>[?Yield]</sub> <span class="nt">ComprehensionTail</span><sub>[?Yield]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ComprehensionFor</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">for</code> <code class="t">(</code> <span class="nt">ForBinding</span><sub>[?Yield]</sub> <code class="t">of</code> <span class="nt">AssignmentExpression</span><sub>[In, ?Yield]</sub> <code class="t">)</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ComprehensionIf</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">if</code> <code class="t">(</code> <span class="nt">AssignmentExpression</span><sub>[In, ?Yield]</sub> <code class="t">)</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ForBinding</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">BindingIdentifier</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="nt">BindingPattern</span><sub>[?Yield]</sub></div>
+ </div>
+ </div>
+
+ <section id="sec-array-comprehension-static-semantics-early-errors">
+ <h1><span class="secnum" id="sec-12.2.4.2.1"><a href="#sec-array-comprehension-static-semantics-early-errors"
+ title="link to this section">12.2.4.2.1</a></span> Static Semantics: Early Errors</h1>
+ <div class="gp prod"><span class="nt">ComprehensionFor</span> <span class="geq">:</span> <code class="t">for</code> <code class="t">(</code> <span class="nt">ForBinding</span> <code class="t">of</code> <span class="nt">AssignmentExpression</span> <code class="t">)</code></div>
+ <ul>
+ <li>It is a Syntax Error if the BoundNames of <span class="nt">ForBinding</span> contains <code>"let"</code>.</li>
+ <li>It is a Syntax Error if the BoundNames of <span class="nt">ForBinding</span> contains any duplicate entries.</li>
+ </ul>
+ </section>
+
+ <section id="sec-array-comprehension-runtime-semantics-bindinginitialization">
+ <h1><span class="secnum" id="sec-12.2.4.2.2"><a href="#sec-array-comprehension-runtime-semantics-bindinginitialization"
+ title="link to this section">12.2.4.2.2</a></span> Runtime Semantics: BindingInitialization</h1>
+
+ <p>With arguments <var>value</var> and <var>environment</var>.</p>
+
+ <p>See also: <b>Error! <a href="#sec-reference-specification-type">Reference</a> source not found.</b>, <a
+ href="#sec-variable-statement-static-semantics-vardeclarednames">13.2.2.2</a>, <a
+ href="#sec-destructuring-binding-patterns-static-semantics-issimpleparameterlist">13.2.3.4</a>, <a
+ href="#sec-try-statement-static-semantics-varscopeddeclarations">13.14.3</a>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> <b>undefined</b> is passed for <i>environment</i> to indicate that a <a
+ href="#sec-putvalue">PutValue</a> operation should be used to assign the initialization value. This is the case for
+ <code>var</code> statements formal parameter lists of non-strict functions. In those cases a lexical binding is hosted
+ and preinitialized prior to evaluation of its initializer.</p>
+ </div>
+
+ <div class="gp prod"><span class="nt">ForBinding</span> <span class="geq">:</span> <span class="nt">BindingPattern</span></div>
+ <ol class="proc">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>value</i>) is not Object, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>Return the result of performing BindingInitialization for <i>BindingPattern</i> passing <i>value</i> and
+ <i>environment</i> as the arguments.</li>
+ </ol>
+ </section>
+
+ <section id="sec-runtime-semantics-comprehensionevaluation">
+ <h1><span class="secnum" id="sec-12.2.4.2.3"><a href="#sec-runtime-semantics-comprehensionevaluation"
+ title="link to this section">12.2.4.2.3</a></span> Runtime Semantics: ComprehensionEvaluation</h1>
+
+ <p>With argument <var>accumulator</var>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> <b>undefined</b> is passed for <i>accumulator</i> to indicate that a comprehension
+ component is being evaluated as part of a generator comprehension. Otherwise, the value of <i>accumulator</i> is the
+ array object into which the elements of an array comprehension are to be accumulated.</p>
+ </div>
+
+ <div class="gp prod"><span class="nt">Comprehension</span> <span class="geq">:</span> <span class="nt">ComprehensionFor</span> <span class="nt">ComprehensionTail</span></div>
+ <ol class="proc">
+ <li>Return the result of performing ComprehensionComponentEvaluation for <i>ComprehensionFor</i> with arguments
+ <i>ComprehensionTail</i> and <i>accumulator</i>.</li>
+ </ol>
+
+ <p><span class="prod"><span class="nt">ComprehensionTail</span> <span class="geq">:</span> <span
+ class="nt">ComprehensionFor</span> <span class="nt">ComprehensionTail</span></span></p>
+
+ <ol class="proc">
+ <li>Return the result of performing ComprehensionComponentEvaluation for <i>ComprehensionFor</i> with arguments
+ <i>ComprehensionTail</i> and <i>accumulator</i>.</li>
+ </ol>
+
+ <p><span class="prod"><span class="nt">ComprehensionTail</span> <span class="geq">:</span> <span
+ class="nt">ComprehensionIf</span> <span class="nt">ComprehensionTail</span></span></p>
+
+ <ol class="proc">
+ <li>Return the result of performing ComprehensionComponentEvaluation for <i>ComprehensionIf</i> with arguments
+ <i>ComprehensionTail</i> and <i>accumulator</i>.</li>
+ </ol>
+
+ <p><span class="prod"><span class="nt">ComprehensionTail</span> <span class="geq">:</span> <span
+ class="nt">AssignmentExpression</span></span></p>
+
+ <ol class="proc">
+ <li>Let <i>valueRef</i> be the result of evaluating <i>AssignmentExpression</i>.</li>
+ <li>Let <i>value</i> be <a href="#sec-getvalue">GetValue</a>(<i>valueRef</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>value</i>).</li>
+ <li>If <i>accumulator</i> is not <b>undefined</b>, then
+ <ol class="block">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: this is part of an array comprehension.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>accumulator</i> is an exotic array object so access to its
+ <code>length</code> property should never fail.</li>
+ <li>Let <i>len</i> be <a href="#sec-get-o-p">Get</a>(<i>accumulator</i>, <code>"length"</code>).</li>
+ <li>If <i>len</i>≥2<sup>32</sup>-1, then throw a <b>RangeError</b> exception.</li>
+ <li>Let <i>putStatus</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>accumulator</i>, <a
+ href="#sec-tostring">ToString</a>(<i>len</i>), <i>value</i>, <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>putStatus</i>).</li>
+ <li>Increase <i>len</i> by 1.</li>
+ <li>Let <i>putStatus</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>accumulator</i>, <code>"length"</code>,
+ <i>len</i>, <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>putStatus</i>).</li>
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<b>undefined</b>).</li>
+ </ol>
+ </li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>accumulator</i> is <b>undefined</b>, so this is part of a
+ generator comprehension.</li>
+ <li>Let <i>yieldStatus</i> be <a href="#sec-generatoryield">GeneratorYield</a>(<a
+ href="#sec-createiterresultobject">CreateIterResultObject</a>(<i>value</i>, <b>false</b>)).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>yieldStatus</i>).</li>
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<b>undefined</b>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-runtime-semantics-comprehensioncomponentevaluation">
+ <h1><span class="secnum" id="sec-12.2.4.2.4"><a href="#sec-runtime-semantics-comprehensioncomponentevaluation"
+ title="link to this section">12.2.4.2.4</a></span> Runtime Semantics: ComprehensionComponentEvaluation</h1>
+
+ <p>With arguments <var>tail</var> and <var>accumulator</var>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> <b>undefined</b> is passed for <i>accumulator</i> to indicate that a comprehension
+ component is being evaluated as part of a generator comprehension. Otherwise, the value of <i>accumulator</i> is the
+ array object into which the elements of an array comprehension are to be accumulated.</p>
+ </div>
+
+ <div class="gp prod"><span class="nt">ComprehensionFor</span> <span class="geq">:</span> <code class="t">for</code> <code class="t">(</code> <span class="nt">ForBinding</span> <code class="t">of</code> <span class="nt">AssignmentExpression</span> <code class="t">)</code></div>
+ <ol class="proc">
+ <li>Let <i>exprRef</i> be the result of evaluating <i>AssignmentExpression</i>.</li>
+ <li>Let <i>exprValue</i> be <a href="#sec-getvalue">GetValue</a>(<i>exprRef</i>).</li>
+ <li>if <i>exprValue</i> is <b>null</b> or <b>undefined</b>, then return <a
+ href="#sec-normalcompletion">NormalCompletion</a>(<b>undefined</b>).</li>
+ <li>Let <i>obj</i> be <a href="#sec-toobject">ToObject</a>(<i>exprValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>obj</i>).</li>
+ <li>Let <i>keys</i> be <a href="#sec-getiterator">GetIterator</a>(<i>obj</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>keys</i>).</li>
+ <li>Let <i>oldEnv</i> be <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-execution-contexts">LexicalEnvironment</a>.</li>
+ <li>Repeat
+ <ol class="block">
+ <li>Let <i>nextResult</i> be <a href="#sec-iteratorstep">IteratorStep</a>(<i>keys</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>nextResult</i>).</li>
+ <li>If <i>nextResult</i> is <b>false</b>, then return <a
+ href="#sec-normalcompletion">NormalCompletion</a>(<b>undefined</b>).</li>
+ <li>Let <i>nextValue</i> be <a href="#sec-iteratorvalue">IteratorValue</a>(<i>nextResult</i>);</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>nextValue</i>).</li>
+ <li>Let <i>forEnv</i> be <a
+ href="#sec-newdeclarativeenvironment">NewDeclarativeEnvironment</a>(<i>oldEnv</i>).</li>
+ <li>For each element <i>name</i> of the BoundNames of <i>ForBinding</i> do
+ <ol class="block">
+ <li>Call <i>forEnv</i>’s CreateMutableBinding concrete method with argument <i>name</i>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: The above call to CreateMutableBinding will never return
+ an <a href="#sec-completion-record-specification-type">abrupt completion</a>.</li>
+ </ol>
+ </li>
+ <li>Let <i>status</i> be the result of performing BindingInitialization for <i>ForBinding</i> passing
+ <i>nextValue</i> and <i>forEnv</i> as the arguments.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Set <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-execution-contexts">LexicalEnvironment</a> to <i>forEnv</i>.</li>
+ <li>Let <i>continue</i> be the result of performing ComprehensionEvaluation for <i>tail</i> with argument
+ <i>accumulator</i>.</li>
+ <li>Set <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-execution-contexts">LexicalEnvironment</a> to <i>oldEnv</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>continue</i>).</li>
+ </ol>
+ </li>
+ </ol>
+ <div class="gp prod"><span class="nt">ComprehensionIf</span> <span class="geq">:</span> <code class="t">if</code> <code class="t">(</code> <span class="nt">AssignmentExpression</span> <code class="t">)</code></div>
+ <ol class="proc">
+ <li>Let <i>valueRef</i> be the result of evaluating <i>AssignmentExpression</i>.</li>
+ <li>Let <i>value</i> be <a href="#sec-getvalue">GetValue</a>(<i>valueRef</i>).</li>
+ <li>Let <i>boolValue</i> be <a href="#sec-toboolean">ToBoolean</a>(<i>value</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>boolValue</i>).</li>
+ <li>If <i>boolValue</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Return the result of performing ComprehensionEvaluation for <i>tail</i> with argument <i>accumulator</i>.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<b>undefined</b>).</li>
+ </ol>
+ </li>
+ </ol>
+ </section>
+
+ <section id="sec-array-comprehension-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-12.2.4.2.5"><a href="#sec-array-comprehension-runtime-semantics-evaluation"
+ title="link to this section">12.2.4.2.5</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">ArrayComprehension</span> <span class="geq">:</span> <code class="t">[</code> <span class="nt">Comprehension</span> <code class="t">]</code></div>
+ <ol class="proc">
+ <li>Let <i>array</i> be <a href="#sec-arraycreate">ArrayCreate</a>(0).</li>
+ <li>Let <i>status</i> be the result of performing ComprehensionEvaluation for <i>Comprehension</i> with argument
+ <i>array</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Return <i>array</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">Comprehension</span> <span class="geq">:</span> <span class="nt">ComprehensionFor</span> <span class="nt">ComprehensionTail</span></div>
+ <ol class="proc">
+ <li>Return the result of performing ComprehensionEvaluation for this <i>Comprehension</i> with argument
+ <b>undefined</b>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> This action is only invoked for a <i>Comprehension</i> that is part of a
+ <i>GeneratorComprehension</i>.</p>
+ </div>
+ </section>
+ </section>
+ </section>
+
+ <section id="sec-object-initializer">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.2.5"><a href="#sec-object-initializer" title="link to this section">12.2.5</a></span>
+ Object Initializer</h1>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> An object initializer is an expression describing the initialization of an Object,
+ written in a form resembling a literal. It is a list of zero or more pairs of property names and associated values,
+ enclosed in curly braces. The values need not be literals; they are evaluated each time the object initializer is
+ evaluated.</p>
+ </div>
+
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ObjectLiteral</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">{</code> <code class="t">}</code></div>
+ <div class="rhs"><code class="t">{</code> <span class="nt">PropertyDefinitionList</span><sub>[?Yield]</sub> <code class="t">}</code></div>
+ <div class="rhs"><code class="t">{</code> <span class="nt">PropertyDefinitionList</span><sub>[?Yield]</sub> <code class="t">,</code> <code class="t">}</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">PropertyDefinitionList</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">PropertyDefinition</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="nt">PropertyDefinitionList</span><sub>[?Yield]</sub> <code class="t">,</code> <span class="nt">PropertyDefinition</span><sub>[?Yield]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">PropertyDefinition</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">IdentifierReference</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="nt">CoverInitializedName</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="nt">PropertyName</span><sub>[?Yield]</sub> <code class="t">:</code> <span class="nt">AssignmentExpression</span><sub>[In, ?Yield]</sub></div>
+ <div class="rhs"><span class="nt">MethodDefinition</span><sub>[?Yield]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">PropertyName</span><sub>[Yield,GeneratorParameter]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">LiteralPropertyName</span></div>
+ <div class="rhs"><span class="grhsannot">[+GeneratorParameter]</span> <span class="nt">ComputedPropertyName</span></div>
+ <div class="rhs"><span class="grhsannot">[~GeneratorParameter]</span> <span class="nt">ComputedPropertyName</span><sub>[?Yield]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">LiteralPropertyName</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">IdentifierName</span></div>
+ <div class="rhs"><span class="nt">StringLiteral</span></div>
+ <div class="rhs"><span class="nt">NumericLiteral</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ComputedPropertyName</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">[</code> <span class="nt">AssignmentExpression</span><sub>[In, ?Yield]</sub> <code class="t">]</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">CoverInitializedName</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">IdentifierReference</span><sub>[?Yield]</sub> <span class="nt">Initializer</span><sub>[In, ?Yield]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">Initializer</span><sub>[In, Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">=</code> <span class="nt">AssignmentExpression</span><sub>[?In, ?Yield]</sub></div>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 2</span> <i>MethodDefinition</i> is defined in <a href="#sec-method-definitions">14.3</a>.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 3</span> In certain contexts, <i>ObjectLiteral</i> is used as a cover grammar for a more
+ restricted secondary grammar. The <i>CoverInitializedName</i> production is necessary to fully cover these secondary
+ grammars. However, use of this production results in an early Syntax Error in normal contexts where an actual
+ <i>ObjectLiteral</i> is expected.</p>
+ </div>
+ </div>
+
+ <section id="sec-object-initializer-static-semantics-early-errors">
+ <h1><span class="secnum" id="sec-12.2.5.1"><a href="#sec-object-initializer-static-semantics-early-errors"
+ title="link to this section">12.2.5.1</a></span> Static Semantics: Early Errors</h1>
+
+ <p>In addition to describing an actual object initializer the <span class="nt">ObjectLiteral</span> productions are also
+ used as a cover grammar for <span class="nt">ObjectAssignmentPattern</span> (<a
+ href="#sec-destructuring-assignment">12.14.5</a>). and may be recognized as part of a <span
+ class="nt">CoverParenthesizedExpressionAndArrowParameterList</span>. When <span class="nt">ObjectLiteral</span> appears in
+ a context where <span class="nt">ObjectAssignmentPattern</span> is required the following Early Error rules are <b>not</b>
+ applied. In addition, they are not applied when initially parsing a
+ <var>CoverParenthesizedExpressionAndArrowParameterList.</var></p>
+
+ <div class="gp prod"><span class="nt">ObjectLiteral</span> <span class="geq">:</span> <code class="t">{</code> <span class="nt">PropertyDefinitionList</span> <code class="t">}</code></div>
+
+ <p>and</p>
+
+ <div class="gp prod"><span class="nt">ObjectLiteral</span> <span class="geq">:</span> <code class="t">{</code> <span class="nt">PropertyDefinitionList</span> <code class="t">,</code> <code class="t">}</code></div>
+ <ul>
+ <li>
+ <p>It is a Syntax Error if <span style="font-family: Times New Roman">PropertyNameList</span> of <span
+ class="nt">PropertyDefinitionList</span> contains any duplicate entries, unless one of the following conditions are
+ true for each duplicate entry: </p>
+
+ <ol class="proc">
+ <li>The source code corresponding to <span class="nt">PropertyDefinitionList</span> is not <a
+ href="#sec-strict-mode-code">strict code</a> and all occurrences in the list of the duplicated entry were
+ obtained from productions of the form <span class="prod"><span class="nt">PropertyDefinition</span> <span
+ class="geq">:</span> <span class="nt">PropertyName</span> <code class="t">:</code> <span
+ class="nt">AssignmentExpression</span></span> .</li>
+ <li>The duplicated entry occurs exactly twice in the list and one occurrence was obtained from a <code>get</code>
+ accessor <span class="nt">MethodDefinition</span> and the other occurrence was obtained from a <code>set</code>
+ accessor <span class="nt">MethodDefinition</span>.</li>
+ </ol>
+ </li>
+ </ul>
+ <div class="gp prod"><span class="nt">PropertyDefinition</span> <span class="geq">:</span> <span class="nt">CoverInitializedName</span></div>
+ <ul>
+ <li>Always throw a Syntax Error if <span style="font-family: Times New Roman">this production is present</span></li>
+ </ul>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> This production exists so that <i>ObjectLiteral</i> can serve as a cover grammar for
+ <i>ObjectAssignmentPattern</i> (<a href="#sec-destructuring-assignment">12.14.5</a>). It cannot occur in an actual
+ object initializer.</p>
+ </div>
+ </section>
+
+ <section id="sec-object-initializer-static-semantics-computedpropertycontains">
+ <h1><span class="secnum" id="sec-12.2.5.2"><a href="#sec-object-initializer-static-semantics-computedpropertycontains"
+ title="link to this section">12.2.5.2</a></span> Static Semantics: ComputedPropertyContains</h1>
+
+ <p>With parameter <var>symbol</var>.</p>
+
+ <p>See also: <a href="#sec-method-definitions-static-semantics-computedpropertycontains">14.3.2</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-computedpropertycontains">14.4.3</a>, <a
+ href="#sec-class-definitions-static-semantics-computedpropertycontains">14.5.5</a>.</p>
+
+ <div class="gp prod"><span class="nt">PropertyName</span> <span class="geq">:</span> <span class="nt">LiteralPropertyName</span></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">PropertyName</span> <span class="geq">:</span> <span class="nt">ComputedPropertyName</span></div>
+ <ol class="proc">
+ <li>Return the result of <i>ComputedPropertyName</i> Contains <i>symbol</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-object-initializer-static-semantics-contains">
+ <h1><span class="secnum" id="sec-12.2.5.3"><a href="#sec-object-initializer-static-semantics-contains"
+ title="link to this section">12.2.5.3</a></span> Static Semantics: Contains</h1>
+
+ <p>With parameter <var>symbol</var>.</p>
+
+ <p>See also: <a href="#sec-static-semantic-rules">5.3</a>, <a
+ href="#sec-static-semantics-static-semantics-contains">12.3.1.1</a>, <a
+ href="#sec-function-definitions-static-semantics-contains">14.1.4</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-contains">14.2.3</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-computedpropertycontains">14.4.3</a>, <a
+ href="#sec-class-definitions-static-semantics-contains">14.5.4</a></p>
+
+ <div class="gp prod"><span class="nt">PropertyDefinition</span> <span class="geq">:</span> <span class="nt">MethodDefinition</span></div>
+ <ol class="proc">
+ <li>If <i>symbol</i> is <i>MethodDefinition</i>, return <b>true</b>.</li>
+ <li>Return the result of ComputedPropertyContains for <i>MethodDefinition</i> with argument <i>symbol</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Static semantic rules that depend upon substructure generally do not look into function
+ definitions.</p>
+ </div>
+
+ <div class="gp prod"><span class="nt">LiteralPropertyName</span> <span class="geq">:</span> <span class="nt">IdentifierName</span></div>
+ <ol class="proc">
+ <li>If <i>symbol</i> is a <i>ReservedWord</i>, return <b>false</b>.</li>
+ <li>If <i>symbol</i> is an <i>Identifier</i> and StringValue of <i>symbol</i> is the same value as the StringValue of
+ <i>IdentifierName</i>, return <b>true</b>;</li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-object-initializer-static-semantics-hascomputedpropertykey">
+ <h1><span class="secnum" id="sec-12.2.5.4"><a href="#sec-object-initializer-static-semantics-hascomputedpropertykey"
+ title="link to this section">12.2.5.4</a></span> Static Semantics: HasComputedPropertyKey</h1>
+
+ <p>See also: <a href="#sec-method-definitions-static-semantics-hascomputedpropertykey">14.3.4</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-hascomputedpropertykey">14.4.5</a></p>
+
+ <div class="gp prod"><span class="nt">PropertyDefinitionList</span> <span class="geq">:</span> <span class="nt">PropertyDefinitionList</span> <code class="t">,</code> <span class="nt">PropertyDefinition</span></div>
+ <ol class="proc">
+ <li>If HasComputedPropertyKey of <i>PropertyDefinitionList</i> is <b>true</b>, then return <b>true</b>.</li>
+ <li>Return HasComputedPropertyKey of <i>PropertyDefinition</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">PropertyDefinition</span> <span class="geq">:</span> <span class="nt">IdentifierReference</span></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">PropertyDefinition</span> <span class="geq">:</span> <span class="nt">PropertyName</span> <code class="t">:</code> <span class="nt">AssignmentExpression</span></div>
+ <ol class="proc">
+ <li>Return IsComputedPropertyKey of <i>PropertyName</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-static-semantics-iscomputedpropertykey">
+ <h1><span class="secnum" id="sec-12.2.5.5"><a href="#sec-static-semantics-iscomputedpropertykey"
+ title="link to this section">12.2.5.5</a></span> Static Semantics: IsComputedPropertyKey</h1>
+ <div class="gp prod"><span class="nt">PropertyName</span> <span class="geq">:</span> <span class="nt">LiteralPropertyName</span></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">PropertyName</span> <span class="geq">:</span> <span class="nt">ComputedPropertyName</span></div>
+ <ol class="proc">
+ <li>Return <b>true</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-object-initializer-static-semantics-propname">
+ <h1><span class="secnum" id="sec-12.2.5.6"><a href="#sec-object-initializer-static-semantics-propname"
+ title="link to this section">12.2.5.6</a></span> Static Semantics: <i>PropName</i></h1>
+
+ <p>See also: <a href="#sec-method-definitions-static-semantics-propname">14.3.5</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-propname">14.4.10</a>, <a
+ href="#sec-class-definitions-static-semantics-propname">14.5.13</a></p>
+
+ <div class="gp prod"><span class="nt">PropertyDefinition</span> <span class="geq">:</span> <span class="nt">IdentifierReference</span></div>
+ <ol class="proc">
+ <li>Return StringValue of <i>IdentifierReference</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">PropertyDefinition</span> <span class="geq">:</span> <span class="nt">PropertyName</span> <code class="t">:</code> <span class="nt">AssignmentExpression</span></div>
+ <ol class="proc">
+ <li>Return PropName of <i>PropertyName</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">LiteralPropertyName</span> <span class="geq">:</span> <span class="nt">IdentifierName</span></div>
+ <ol class="proc">
+ <li>Return StringValue of <i>IdentifierName</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">LiteralPropertyName</span> <span class="geq">:</span> <span class="nt">StringLiteral</span></div>
+ <ol class="proc">
+ <li>Return a String value whose characters are the SV of the <i>StringLiteral</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">LiteralPropertyName</span> <span class="geq">:</span> <span class="nt">NumericLiteral</span></div>
+ <ol class="proc">
+ <li>Let <i>nbr</i> be the result of forming the value of the <i>NumericLiteral</i>.</li>
+ <li>Return <a href="#sec-tostring">ToString</a>(<i>nbr</i>).</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ComputedPropertyName</span> <span class="geq">:</span> <code class="t">[</code> <span class="nt">AssignmentExpression</span> <code class="t">]</code></div>
+ <ol class="proc">
+ <li>Return <span style="font-family: sans-serif">empty</span>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-static-semantics-propertynamelist">
+ <h1><span class="secnum" id="sec-12.2.5.7"><a href="#sec-static-semantics-propertynamelist"
+ title="link to this section">12.2.5.7</a></span> Static Semantics: PropertyNameList</h1>
+ <div class="gp prod"><span class="nt">PropertyDefinitionList</span> <span class="geq">:</span> <span class="nt">PropertyDefinition</span></div>
+ <ol class="proc">
+ <li>If PropName of <i>PropertyDefinition</i> is <span style="font-family: sans-serif">empty</span>, return a new empty
+ <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Return a new <a href="#sec-list-and-record-specification-type">List</a> containing PropName of
+ <i>PropertyDefinition</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">PropertyDefinitionList</span> <span class="geq">:</span> <span class="nt">PropertyDefinitionList</span> <code class="t">,</code> <span class="nt">PropertyDefinition</span></div>
+ <ol class="proc">
+ <li>Let <i>list</i> be PropertyNameList of <i>PropertyDefinitionList.</i></li>
+ <li>If PropName of <i>PropertyDefinition</i> is <span style="font-family: sans-serif">empty</span>, return
+ <i>list</i>.</li>
+ <li>Append PropName of <i>PropertyDefinition</i> to the end of <i>list</i>.</li>
+ <li>Return <i>list</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-object-initializer-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-12.2.5.8"><a href="#sec-object-initializer-runtime-semantics-evaluation"
+ title="link to this section">12.2.5.8</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">ObjectLiteral</span> <span class="geq">:</span> <code class="t">{</code> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return <a href="#sec-objectcreate">ObjectCreate</a>(<span style="font-family:
+ sans-serif">%ObjectPrototype%</span>).</li>
+ </ol>
+
+ <p><span class="prod"><span class="nt">ObjectLiteral</span> <span class="geq">:</span></span><br>	<code>{</code> <span
+ class="nt">PropertyDefinitionList</span> <code>}</code><span style="font-family: Times New
+ Roman"><i><br></i></span>	<code>{</code> <span class="nt">PropertyDefinitionList</span> <code>,</code>
+ <code>}</code></p>
+
+ <ol class="proc">
+ <li>Let <i>obj</i> be <a href="#sec-objectcreate">ObjectCreate</a>(%ObjectPrototype%).</li>
+ <li>Let <i>status</i> be the result of performing PropertyDefinitionEvaluation of <i>PropertyDefinitionList</i> with
+ argument <i>obj</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Return <i>obj</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">LiteralPropertyName</span> <span class="geq">:</span> <span class="nt">IdentifierName</span></div>
+ <ol class="proc">
+ <li>Return StringValue of <i>IdentifierName</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">LiteralPropertyName</span> <span class="geq">:</span> <span class="nt">StringLiteral</span></div>
+ <ol class="proc">
+ <li>Return a String value whose characters are the SV of the <i>StringLiteral</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">LiteralPropertyName</span> <span class="geq">:</span> <span class="nt">NumericLiteral</span></div>
+ <ol class="proc">
+ <li>Let <i>nbr</i> be the result of forming the value of the <i>NumericLiteral</i>.</li>
+ <li>Return <a href="#sec-tostring">ToString</a>(<i>nbr</i>).</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ComputedPropertyName</span> <span class="geq">:</span> <code class="t">[</code> <span class="nt">AssignmentExpression</span> <code class="t">]</code></div>
+ <ol class="proc">
+ <li>Let <i>exprValue</i> be the result of evaluating <i>AssignmentExpression</i>.</li>
+ <li>Let <i>propName</i> be <a href="#sec-getvalue">GetValue</a>(<i>exprValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>propName</i>).</li>
+ <li>Return <a href="#sec-topropertykey">ToPropertyKey</a>(<i>propName</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-object-initializer-runtime-semantics-propertydefinitionevaluation">
+ <h1><span class="secnum" id="sec-12.2.5.9"><a
+ href="#sec-object-initializer-runtime-semantics-propertydefinitionevaluation"
+ title="link to this section">12.2.5.9</a></span> Runtime Semantics: PropertyDefinitionEvaluation</h1>
+
+ <p>With parameter <span style="font-family: Times New Roman"><i>object</i>.</span></p>
+
+ <p>See also: <a href="#sec-method-definitions-runtime-semantics-propertydefinitionevaluation">14.3.9</a>, <a
+ href="#sec-generator-function-definitions-runtime-semantics-propertydefinitionevaluation">14.4.16</a>, B.3.1</p>
+
+ <div class="gp prod"><span class="nt">PropertyDefinitionList</span> <span class="geq">:</span> <span class="nt">PropertyDefinitionList</span> <code class="t">,</code> <span class="nt">PropertyDefinition</span></div>
+ <ol class="proc">
+ <li>Let <i>status</i> be the result of performing PropertyDefinitionEvaluation of <i>PropertyDefinitionList</i> with
+ argument <i>object</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Return the result of performing PropertyDefinitionEvaluation of <i>PropertyDefinition</i> with argument
+ <i>object</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">PropertyDefinition</span> <span class="geq">:</span> <span class="nt">IdentifierReference</span></div>
+ <ol class="proc">
+ <li>Let <i>propName</i> be StringValue of <i>IdentifierReference</i>.</li>
+ <li>Let <i>exprValue</i> be the result of evaluating <i>IdentifierReference</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>exprValue</i>).</li>
+ <li>Let <i>propValue</i> be <a href="#sec-getvalue">GetValue</a>(<i>exprValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>propValue</i>).</li>
+ <li>Let <i>desc</i> be the <a href="#sec-property-descriptor-specification-type">Property Descriptor</a>{[[Value]]:
+ <i>propValue</i>, [[Writable]]: <b>true</b>, [[Enumerable]]: <b>true</b>, [[Configurable]]: <b>true</b>}</li>
+ <li>Return <a href="#sec-definepropertyorthrow">DefinePropertyOrThrow</a>(<i>object</i>, <i>propName</i>,
+ <i>desc</i>).</li>
+ </ol>
+ <div class="gp prod"><span class="nt">PropertyDefinition</span> <span class="geq">:</span> <span class="nt">PropertyName</span> <code class="t">:</code> <span class="nt">AssignmentExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>propKey</i> be the result of evaluating <i>PropertyName</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>propKey</i>).</li>
+ <li>Let <i>exprValue</i> be the result of evaluating <i>AssignmentExpression</i>.</li>
+ <li>Let <i>propValue</i> be <a href="#sec-getvalue">GetValue</a>(<i>exprValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>propValue</i>).</li>
+ <li>If IsFunctionDefinition of <i>AssignmentExpression</i> is <b>true</b>, then
+ <ol class="block">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>propValue</i> is an <a
+ href="#sec-ecmascript-function-objects">ECMAScript function object</a>.</li>
+ <li>Let <i>referencesSuper</i> be the value of <i>propValue</i>’s [[NeedsSuper]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>thisMode</i> be the value of <i>propValue</i>’s [[ThisMode]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>thisMode</i> is not <span style="font-family: sans-serif">lexical</span> and <i>referencesSuper</i> is
+ <b>true</b>, then
+ <ol class="block">
+ <li>If <i>propValue</i>’s [[HomeObject]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is <b>undefined</b>, then
+ <ol class="block">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>AssignmentExpression</i> is not a class definition
+ whose constructor references <code>super</code>.</li>
+ <li>Set <i>propValue</i>’s [[HomeObject]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to <i>object</i>.</li>
+ <li>Set <i>propValue</i>’s [[MethodName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to <i>propKey</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>If <a href="#sec-isanonymousfunctiondefinition">IsAnonymousFunctionDefinition</a>(<i>AssignmentExpression)</i>
+ is <b>true</b>, then
+ <ol class="block">
+ <li><a href="#sec-setfunctionname">SetFunctionName</a>(<i>propValue</i>, <i>propKey</i>).</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Let <i>desc</i> be the <a href="#sec-property-descriptor-specification-type">Property Descriptor</a>{[[Value]]:
+ <i>propValue</i>, [[Writable]]: <b>true</b>, [[Enumerable]]: <b>true</b>, [[Configurable]]: <b>true</b>}</li>
+ <li>Return <a href="#sec-definepropertyorthrow">DefinePropertyOrThrow</a>(<i>object</i>, <i>propKey</i>,
+ <i>desc</i>).</li>
+ </ol>
+
+ <p class="Note"><i>NOTE	An alternative semantics for this production is given in <a
+ href="#sec-__proto__-property-names-in-object-initializers">B.3.1</a>.</i></p>
+ </section>
+ </section>
+
+ <section id="sec-function-defining-expressions">
+ <h1><span class="secnum" id="sec-12.2.6"><a href="#sec-function-defining-expressions"
+ title="link to this section">12.2.6</a></span> Function Defining Expressions</h1>
+
+ <p>See <a href="#sec-function-definitions">14.1</a> for <span class="prod"><span class="nt">PrimaryExpression</span> <span
+ class="geq">:</span> <span class="nt">FunctionExpression</span></span> .</p>
+
+ <p>See <a href="#sec-generator-function-definitions">14.4</a> for <span class="prod"><span
+ class="nt">PrimaryExpression</span> <span class="geq">:</span> <span class="nt">GeneratorExpression</span></span> .</p>
+
+ <p>See <a href="#sec-class-definitions">14.5</a> for <span class="prod"><span class="nt">PrimaryExpression</span> <span
+ class="geq">:</span> <span class="nt">ClassExpression</span></span> .</p>
+ </section>
+
+ <section id="sec-generator-comprehensions">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.2.7"><a href="#sec-generator-comprehensions"
+ title="link to this section">12.2.7</a></span> Generator Comprehensions</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">GeneratorComprehension</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">(</code> <span class="nt">Comprehension</span><sub>[?Yield]</sub> <code class="t">)</code></div>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The keyword <code>yield</code> may be used in <i>IdentifierReference</i> contexts within
+ a <i>GeneratorComprehension</i> contained in non-<a href="#sec-strict-mode-code">strict code</a>. The following early
+ error rule ensures that a <i>GeneratorComprehension</i> never contains a <i>YieldExpression</i>.</p>
+ </div>
+ </div>
+
+ <section id="sec-generator-comprehensions-static-semantics-early-errors">
+ <h1><span class="secnum" id="sec-12.2.7.1"><a href="#sec-generator-comprehensions-static-semantics-early-errors"
+ title="link to this section">12.2.7.1</a></span> Static Semantics: Early Errors</h1>
+ <div class="gp prod"><span class="nt">GeneratorComprehension</span> <span class="geq">:</span> <code class="t">(</code> <span class="nt">Comprehension</span> <code class="t">)</code></div>
+ <ul>
+ <li>It is a Syntax Error if <span style="font-family: Times New Roman"><i>Comprehension</i> Contains
+ <i>YieldExpression</i> is <b>true</b></span>.</li>
+ </ul>
+ </section>
+
+ <section id="sec-generator-comprehensions-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-12.2.7.2"><a href="#sec-generator-comprehensions-runtime-semantics-evaluation"
+ title="link to this section">12.2.7.2</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">GeneratorComprehension</span> <span class="geq">:</span> <code class="t">(</code> <span class="nt">Comprehension</span> <code class="t">)</code></div>
+ <ol class="proc">
+ <li>If <i>GeneratorComprehension</i> is contained in <a href="#sec-strict-mode-code">strict mode code</a>, then let
+ <i>strict</i> be <b>true</b>; otherwise let <i>strict</i> be <b>false</b>.</li>
+ <li>Let <i>scope</i> be the <a href="#sec-execution-contexts">LexicalEnvironment</a> of <a
+ href="#sec-execution-contexts">the running execution context</a>.</li>
+ <li>Let <i>parameters</i> be the production: <span class="prod"><span class="nt">FormalParameters</span> <span
+ class="geq">:</span> <span class="grhsannot">[empty]</span></span> .</li>
+ <li>Using <i>Comprehension</i> from the production that is being evaluated, let <i>body</i> be the supplemental
+ syntactic grammar production: <span class="prod"><span class="nt">GeneratorBody</span> <span class="geq">:</span>
+ <span class="nt">Comprehension</span></span> .</li>
+ <li>Let <i>closure</i> be <a href="#sec-generatorfunctioncreate">GeneratorFunctionCreate</a>(<span style="font-family:
+ sans-serif">Arrow</span>, <i>parameters</i>, <i>body, scope</i>, <i>strict</i>).</li>
+ <li>Let <i>prototype</i> be <a href="#sec-objectcreate">ObjectCreate</a>(<span style="font-family:
+ sans-serif">%GeneratorPrototype%</span>).</li>
+ <li>Perform <a href="#sec-makeconstructor">MakeConstructor</a>(<i>closure</i>, <b>true</b>, and <i>prototype</i>).</li>
+ <li>Let <i>iterator</i> be the result of calling the [[Call]] internal method of <i>closure</i> with <b>undefined</b> as
+ <i>thisArgument</i> and an empty <a href="#sec-list-and-record-specification-type">List</a> as
+ <i>argumentsList</i>.</li>
+ <li>Return <i>iterator</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The GeneratorFunction object created in step 5 is not observable from ECMAScript code so
+ an implementation may choose to avoid its allocation and initialization. In that case, other semantically equivalent
+ means must be used to allocate and initialize the <i>iterator</i> object in step 8. In either case, the <i>prototype</i>
+ object created in step 6 must be created because it is potentially observable as the value of the <i>iterator</i>
+ object’s [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>. If
+ <i>strict</i> is <b>false</b> and the <i>Comprehesion</i> contains any direct eval calls then any VarScopedDeclaration
+ bindings created by the evals are created in the VariableEnviornment of the function called in step 8.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-primary-expression-regular-expression-literals">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.2.8"><a href="#sec-primary-expression-regular-expression-literals"
+ title="link to this section">12.2.8</a></span> Regular Expression Literals</h1>
+ <h2>Syntax</h2>
+
+ <p>See <a href="#sec-literals-string-literals">11.8.4</a>.</p>
+ </div>
+
+ <section id="sec-primary-expression-regular-expression-literals-static-semantics-early-errors">
+ <h1><span class="secnum" id="sec-12.2.8.1"><a
+ href="#sec-primary-expression-regular-expression-literals-static-semantics-early-errors"
+ title="link to this section">12.2.8.1</a></span> Static Semantics: Early Errors</h1>
+ <div class="gp prod"><span class="nt">PrimaryExpression</span> <span class="geq">:</span> <span class="nt">RegularExpressionLiteral</span></div>
+ <ul>
+ <li>
+ <p>It is a Syntax Error if <span style="font-family: Times New Roman">BodyText</span> of <span
+ class="nt">RegularExpressionLiteral</span> cannot be recognized using the goal symbol <span class="nt">Pattern</span>
+ of the ECMAScript RegExp grammar specified in <a href="#sec-patterns">21.2.1</a><var>.</var></p>
+ </li>
+
+ <li>
+ <p>It is a Syntax Error if <span style="font-family: Times New Roman">FlagText</span> of <span
+ class="nt">RegularExpressionLiteral</span> contains any character other than <code>"g"</code>, <code>"i"</code>,
+ <code>"m"</code>, <code>"u"</code>, or <code>"y"</code>, or if it contains the same character more than once.</p>
+ </li>
+ </ul>
+ </section>
+
+ <section id="sec-regular-expression-literals-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-12.2.8.2"><a href="#sec-regular-expression-literals-runtime-semantics-evaluation"
+ title="link to this section">12.2.8.2</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">PrimaryExpression</span> <span class="geq">:</span> <span class="nt">RegularExpressionLiteral</span></div>
+ <ol class="proc">
+ <li>Let <i>pattern</i> be the string value consisting of the <a
+ href="#sec-static-semantics-utf-16encoding">UTF-16Encoding</a> of each code point of BodyText of
+ <i>RegularExpressionLiteral</i>.</li>
+ <li>Let <i>flags</i> be the string value consisting of the <a
+ href="#sec-static-semantics-utf-16encoding">UTF-16Encoding</a> of each code point of FlagText of
+ <i>RegularExpressionLiteral</i>.</li>
+ <li>Return <a href="#sec-regexpcreate">RegExpCreate</a>(<i>pattern</i>, <i>flags</i>).</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-template-literals">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.2.9"><a href="#sec-template-literals" title="link to this section">12.2.9</a></span>
+ Template Literals</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">TemplateLiteral</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">NoSubstitutionTemplate</span></div>
+ <div class="rhs"><span class="nt">TemplateHead</span> <span class="nt">Expression</span><sub>[In, ?Yield]</sub> <span class="grhsannot">[Lexical goal <span class="nt">InputElementTemplateTail</span>]</span> <span class="nt">TemplateSpans</span><sub>[?Yield]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">TemplateSpans</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">TemplateTail</span></div>
+ <div class="rhs"><span class="nt">TemplateMiddleList</span><sub>[?Yield]</sub> <span class="grhsannot">[Lexical goal <span class="nt">InputElementTemplateTail</span>]</span> <span class="nt">TemplateTail</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">TemplateMiddleList</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">TemplateMiddle</span> <span class="nt">Expression</span><sub>[In, ?Yield]</sub></div>
+ <div class="rhs"><span class="nt">TemplateMiddleList</span><sub>[?Yield]</sub> <span class="grhsannot">[Lexical goal <span class="nt">InputElementTemplateTail</span>]</span> <span class="nt">TemplateMiddle</span> <span class="nt">Expression</span><sub>[In, ?Yield]</sub></div>
+ </div>
+ </div>
+
+ <section id="sec-template-literals-static-semantics">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.2.9.1"><a href="#sec-template-literals-static-semantics"
+ title="link to this section">12.2.9.1</a></span> Static Semantics</h1>
+ </div>
+
+ <section id="sec-static-semantics-templatestrings">
+ <h1><span class="secnum" id="sec-12.2.9.1.1"><a href="#sec-static-semantics-templatestrings"
+ title="link to this section">12.2.9.1.1</a></span> Static Semantics: TemplateStrings</h1>
+
+ <p>With parameter <var>raw</var>.</p>
+
+ <div class="gp prod"><span class="nt">TemplateLiteral</span> <span class="geq">:</span> <span class="nt">NoSubstitutionTemplate</span></div>
+ <ol class="proc">
+ <li>If <i>raw</i> is <b>false</b>, then
+ <ol class="block">
+ <li>Let <i>string</i> be the TV of <i>NoSubstitutionTemplate</i>.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>string</i> be the TRV of <i>NoSubstitutionTemplate</i>.</li>
+ </ol>
+ </li>
+ <li>Return a <a href="#sec-list-and-record-specification-type">List</a> containing the single element,
+ <i>string</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">TemplateLiteral</span> <span class="geq">:</span> <span class="nt">TemplateHead</span> <span class="nt">Expression</span> <span class="nt">TemplateSpans</span></div>
+ <ol class="proc">
+ <li>If <i>raw</i> is <b>false</b>, then
+ <ol class="block">
+ <li>Let <i>head</i> be the TV of <i>TemplateHead</i>.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>head</i> be the TRV of <i>TemplateHead</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>tail</i> be TemplateStrings of <i>TemplateSpans</i> with argument <i>raw</i>.</li>
+ <li>Return a <a href="#sec-list-and-record-specification-type">List</a> containing <i>head</i> followed by the
+ element, in order of <i>tail</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">TemplateSpans</span> <span class="geq">:</span> <span class="nt">TemplateTail</span></div>
+ <ol class="proc">
+ <li>If <i>raw</i> is <b>false</b>, then
+ <ol class="block">
+ <li>Let <i>tail</i> be the TV of <i>TemplateTail</i>.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>tail</i> be the TRV of <i>TemplateTail</i>.</li>
+ </ol>
+ </li>
+ <li>Return a <a href="#sec-list-and-record-specification-type">List</a> containing the single element,
+ <i>tail</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">TemplateSpans</span> <span class="geq">:</span> <span class="nt">TemplateMiddleList</span> <span class="nt">TemplateTail</span></div>
+ <ol class="proc">
+ <li>Let <i>middle</i> be TemplateStrings of <i>TemplateMiddleList</i> with argument <i>raw</i>.</li>
+ <li>If <i>raw</i> is <b>false</b>, then
+ <ol class="block">
+ <li>Let <i>tail</i> be the TV of <i>TemplateTail</i>.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>tail</i> be the TRV of <i>TemplateTail</i>.</li>
+ </ol>
+ </li>
+ <li>Return a <a href="#sec-list-and-record-specification-type">List</a> containing the elements, in order, of
+ <i>middle</i> followed by <i>tail</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">TemplateMiddleList</span> <span class="geq">:</span> <span class="nt">TemplateMiddle</span> <span class="nt">Expression</span></div>
+ <ol class="proc">
+ <li>If <i>raw</i> is <b>false</b>, then
+ <ol class="block">
+ <li>Let <i>string</i> be the TV of <i>TemplateMiddle</i>.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>string</i> be the TRV of <i>TemplateMiddle</i>.</li>
+ </ol>
+ </li>
+ <li>Return a <a href="#sec-list-and-record-specification-type">List</a> containing the single element,
+ <i>string</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">TemplateMiddleList</span> <span class="geq">:</span> <span class="nt">TemplateMiddleList</span> <span class="nt">TemplateMiddle</span> <span class="nt">Expression</span></div>
+ <ol class="proc">
+ <li>Let <i>front</i> be TemplateStrings of <i>TemplateMiddleList</i> with argument <i>raw</i>.</li>
+ <li>If <i>raw</i> is <b>false</b>, then
+ <ol class="block">
+ <li>Let <i>last</i> be the TV of <i>TemplateMiddle</i>.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>last</i> be the TRV of <i>TemplateMiddle</i>.</li>
+ </ol>
+ </li>
+ <li>Append <i>last</i> as the last element of the <a href="#sec-list-and-record-specification-type">List</a>
+ <i>front</i>.</li>
+ <li>Return <i>front</i>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-runtime-semantics">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.2.9.2"><a href="#sec-runtime-semantics"
+ title="link to this section">12.2.9.2</a></span> Runtime Semantics</h1>
+ </div>
+
+ <section id="sec-runtime-semantics-runtime-semantics-argumentlistevaluation">
+ <h1><span class="secnum" id="sec-12.2.9.2.1"><a href="#sec-runtime-semantics-runtime-semantics-argumentlistevaluation"
+ title="link to this section">12.2.9.2.1</a></span> <span style="font-family: sans-serif">Runtime Semantics:</span>
+ ArgumentListEvaluation</h1>
+
+ <p>See also: <a href="#sec-argument-lists-runtime-semantics-argumentlistevaluation">12.3.6.1</a></p>
+
+ <div class="gp prod"><span class="nt">TemplateLiteral</span> <span class="geq">:</span> <span class="nt">NoSubstitutionTemplate</span></div>
+ <ol class="proc">
+ <li>Let <i>siteObj</i> be the result of the abstract operation GetTemplateCallSite passing this <i>TemplateLiteral</i>
+ production as the argument.</li>
+ <li>Return a <a href="#sec-list-and-record-specification-type">List</a> containing the one element which is
+ <i>siteObj</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">TemplateLiteral</span> <span class="geq">:</span> <span class="nt">TemplateHead</span> <span class="nt">Expression</span> <span class="nt">TemplateSpans</span></div>
+ <ol class="proc">
+ <li>Let <i>siteObj</i> be the result of the abstract operation GetTemplateCallSite passing this <i>TemplateLiteral</i>
+ production as the argument.</li>
+ <li>Let <i>firstSub</i> be the result of evaluating <i>Expression</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>firstSub</i>).</li>
+ <li>Let <i>restSub</i> be SubstitutionEvaluation of <i>TemplateSpans</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>restSub</i>).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>restSub</i> is a <a
+ href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Return a <a href="#sec-list-and-record-specification-type">List</a> whose first element is <i>siteObj</i>, whose
+ second elements is <i>firstSub</i>, and whose subsequent elements are the elements of <i>restSub</i>, in order.
+ <i>restSub</i> may contain no elements.</li>
+ </ol>
+ </section>
+
+ <section id="sec-runtime-semantics-gettemplatecallsite">
+ <h1><span class="secnum" id="sec-12.2.9.2.2"><a href="#sec-runtime-semantics-gettemplatecallsite"
+ title="link to this section">12.2.9.2.2</a></span> Runtime Semantics: GetTemplateCallSite</h1>
+
+ <p>The abstract operation <span style="font-family: Times New Roman">GetTemplateCallSite</span> is called with a grammar
+ production, <var>templateLiteral</var>, as an argument. It performs the following steps:</p>
+
+ <ol class="proc">
+ <li>If a call site object for the source code corresponding to <i>templateLiteral</i> has already been created by a
+ previous call to this abstract operation, then
+ <ol class="block">
+ <li>Return that call site object.</li>
+ </ol>
+ </li>
+ <li>Let <i>cookedStrings</i> be TemplateStrings of <i>templateLiteral</i> with argument <b>false</b>.</li>
+ <li>Let <i>rawStrings</i> be TemplateStrings of <i>templateLiteral</i> with argument <b>true</b>.</li>
+ <li>Let <i>count</i> be the number of elements in the <a href="#sec-list-and-record-specification-type">List</a>
+ <i>cookedStrings</i>.</li>
+ <li>Let <i>siteObj</i> be <a href="#sec-arraycreate">ArrayCreate</a>(<i>count</i>).</li>
+ <li>Let <i>rawObj</i> be <a href="#sec-arraycreate">ArrayCreate</a>(<i>count</i>).</li>
+ <li>Let <i>index</i> be 0.</li>
+ <li>Repeat while <i>index</i> < <i>count</i>
+ <ol class="block">
+ <li>Let <i>prop</i> be <a href="#sec-tostring">ToString</a>(<i>index</i>).</li>
+ <li>Let <i>cookedValue</i> be the string value at 0-based position <i>index</i> of the <a
+ href="#sec-list-and-record-specification-type">List</a> <i>cookedStrings</i>.</li>
+ <li>Call the [[DefineOwnProperty]] internal method of <i>siteObj</i> with arguments <i>prop</i> and
+ PropertyDescriptor{[[Value]]: <i>cookedValue</i>, [[Enumerable]]: <b>true</b>, [[Writable]]: <b>false</b>,
+ [[Configurable]]: <b>false</b>}<i>.</i></li>
+ <li>Let <i>rawValue</i> be the string value at 0-based position <i>index</i> of the <a
+ href="#sec-list-and-record-specification-type">List</a> <i>rawStrings</i>.</li>
+ <li>Call the [[DefineOwnProperty]] internal method of <i>rawObj</i> with arguments <i>prop</i> and
+ PropertyDescriptor{[[Value]]: <i>rawValue</i>, [[Enumerable]]: <b>true</b>, [[Writable]]: <b>false</b>,
+ [[Configurable]]: <b>false</b>}<i>.</i></li>
+ <li>Let <i>index</i> be <i>index</i>+1.</li>
+ </ol>
+ </li>
+ <li>Perform <a href="#sec-setintegritylevel">SetIntegrityLevel</a>(<i>rawObj</i>, "<code>frozen</code>").</li>
+ <li>Call the [[DefineOwnProperty]] internal method of <i>siteObj</i> with arguments <b>"<code>raw</code>"</b> and
+ PropertyDescriptor{[[Value]]: <i>rawObj</i>, [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>,
+ [[Configurable]]: <b>false</b>}<i>.</i></li>
+ <li>Perform <a href="#sec-setintegritylevel">SetIntegrityLevel</a>(<i>siteObj</i>, "<code>frozen</code>").</li>
+ <li>Remember an association between the source code corresponding to <i>templateLiteral</i> and <i>siteObj</i> such
+ that <i>siteObj</i> can be retrieve in subsequent calls to this abstract operation.</li>
+ <li>Return <i>siteObj</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> The creation of a call site object cannot result in an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a>.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 2</span> Each <i>TemplateLiteral</i> in the program code is associated with a unique Template
+ call site object that is used in the evaluation of tagged Templates (<a
+ href="#sec-runtime-semantics-runtime-semantics-evaluation">12.2.9.2.4</a>). The same call site object is used each
+ time a specific tagged Template is evaluated. Whether call site objects are created lazily upon first evaluation of
+ the <i>TemplateLiteral</i> or eagerly prior to first evaluation is an implementation choice that is not observable to
+ ECMAScript code.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 3</span> Future editions of this specification may define additional non-enumerable
+ properties of call site objects.</p>
+ </div>
+ </section>
+
+ <section id="sec-runtime-semantics-substitutionevaluation">
+ <h1><span class="secnum" id="sec-12.2.9.2.3"><a href="#sec-runtime-semantics-substitutionevaluation"
+ title="link to this section">12.2.9.2.3</a></span> Runtime Semantics: SubstitutionEvaluation</h1>
+ <div class="gp prod"><span class="nt">TemplateSpans</span> <span class="geq">:</span> <span class="nt">TemplateTail</span></div>
+ <ol class="proc">
+ <li>Return an empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">TemplateSpans</span> <span class="geq">:</span> <span class="nt">TemplateMiddleList</span> <span class="nt">TemplateTail</span></div>
+ <ol class="proc">
+ <li>Return the result of SubstitutionEvaluation of <i>TemplateMiddleList</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">TemplateMiddleList</span> <span class="geq">:</span> <span class="nt">TemplateMiddle</span> <span class="nt">Expression</span></div>
+ <ol class="proc">
+ <li>Let <i>sub</i> be the result of evaluating <i>Expression</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>sub</i>).</li>
+ <li>Return a <a href="#sec-list-and-record-specification-type">List</a> containing only <i>sub</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">TemplateMiddleList</span> <span class="geq">:</span> <span class="nt">TemplateMiddleList</span> <span class="nt">TemplateMiddle</span> <span class="nt">Expression</span></div>
+ <ol class="proc">
+ <li>Let <i>preceeding</i> be the result of SubstitutionEvaluation of <i>TemplateMiddleList</i> .</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>preceeding</i>).</li>
+ <li>Let <i>next</i> be the result of evaluating <i>Expression</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>next</i>).</li>
+ <li>Append <i>next</i> as the last element of the <a href="#sec-list-and-record-specification-type">List</a>
+ <i>preceeding</i>.</li>
+ <li>Return <i>preceeding</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-runtime-semantics-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-12.2.9.2.4"><a href="#sec-runtime-semantics-runtime-semantics-evaluation"
+ title="link to this section">12.2.9.2.4</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">TemplateLiteral</span> <span class="geq">:</span> <span class="nt">NoSubstitutionTemplate</span></div>
+ <ol class="proc">
+ <li>Return the string value whose elements are the TV of <i>NoSubstitutionTemplate</i> as defined in <a
+ href="#sec-template-literal-lexical-components">11.8.6</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">TemplateLiteral</span> <span class="geq">:</span> <span class="nt">TemplateHead</span> <span class="nt">Expression</span> <span class="nt">TemplateSpans</span></div>
+ <ol class="proc">
+ <li>Let <i>head</i> be the TV of <i>TemplateHead</i> as defined in <a
+ href="#sec-template-literal-lexical-components">11.8.6</a>.</li>
+ <li>Let <i>sub</i> be the result of evaluating <i>Expression</i>.</li>
+ <li>Let <i>middle</i> be <a href="#sec-tostring">ToString</a>(<i>sub</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>middle</i>).</li>
+ <li>Let <i>tail</i> be the result of evaluating <i>TemplateSpans</i> .</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>tail</i>).</li>
+ <li>Return the string value whose elements are the code units of <i>head</i> followed by the code units of
+ <i>tail</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The string conversion semantics applied to the <i>Expression</i> value are like
+ <code><a href="#sec-string.prototype.concat">String.prototype.concat</a></code> rather than the <code>+</code>
+ operator.</p>
+ </div>
+
+ <div class="gp prod"><span class="nt">TemplateSpans</span> <span class="geq">:</span> <span class="nt">TemplateTail</span></div>
+ <ol class="proc">
+ <li>Let <i>tail</i> be the TV of <i>TemplateTail</i> as defined in <a
+ href="#sec-template-literal-lexical-components">11.8.6</a>.</li>
+ <li>Return the string whose elements are the code units of <i>tail</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">TemplateSpans</span> <span class="geq">:</span> <span class="nt">TemplateMiddleList</span> <span class="nt">TemplateTail</span></div>
+ <ol class="proc">
+ <li>Let <i>head</i> be the result of evaluating <i>TemplateMiddleList</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>head</i>).</li>
+ <li>Let <i>tail</i> be the TV of <i>TemplateTail</i> as defined in <a
+ href="#sec-template-literal-lexical-components">11.8.6</a>.</li>
+ <li>Return the string whose elements are the elements of <i>head</i> followed by the elements of <i>tail</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">TemplateMiddleList</span> <span class="geq">:</span> <span class="nt">TemplateMiddle</span> <span class="nt">Expression</span></div>
+ <ol class="proc">
+ <li>Let <i>head</i> be the TV of <i>TemplateMiddle</i> as defined in <a
+ href="#sec-template-literal-lexical-components">11.8.6</a>.</li>
+ <li>Let <i>sub</i> be the result of evaluating <i>Expression</i>.</li>
+ <li>Let <i>middle</i> be <a href="#sec-tostring">ToString</a>(<i>sub</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>middle</i>).</li>
+ <li>Return the sequence of characters consisting of the code units of <i>head</i> followed by the elements of
+ <i>middle</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The string conversion semantics applied to the <i>Expression</i> value are like
+ <code><a href="#sec-string.prototype.concat">String.prototype.concat</a></code> rather than the <code>+</code>
+ operator.</p>
+ </div>
+
+ <div class="gp prod"><span class="nt">TemplateMiddleList</span> <span class="geq">:</span> <span class="nt">TemplateMiddleList</span> <span class="nt">TemplateMiddle</span> <span class="nt">Expression</span></div>
+ <ol class="proc">
+ <li>Let <i>rest</i> be the result of evaluating <i>TemplateMiddleList</i> .</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>rest</i>).</li>
+ <li>Let <i>middle</i> be the TV of <i>TemplateMiddle</i> as defined in <a
+ href="#sec-template-literal-lexical-components">11.8.6</a>.</li>
+ <li>Let <i>sub</i> be the result of evaluating <i>Expression</i>.</li>
+ <li>Let <i>last</i> be <a href="#sec-tostring">ToString</a>(<i>sub</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>last</i>).</li>
+ <li>Return the sequence of characters consisting of the elements of <i>rest</i> followed by the code units of
+ <i>middle</i> followed by the elements of <i>last</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The string conversion semantics applied to the <i>Expression</i> value are like
+ <code><a href="#sec-string.prototype.concat">String.prototype.concat</a></code> rather than the <code>+</code>
+ operator.</p>
+ </div>
+ </section>
+ </section>
+ </section>
+
+ <section id="sec-grouping-operator">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.2.10"><a href="#sec-grouping-operator" title="link to this section">12.2.10</a></span>
+ The Grouping Operator</h1>
+ </div>
+
+ <section id="sec-grouping-operator-static-semantics-early-errors">
+ <h1><span class="secnum" id="sec-12.2.10.1"><a href="#sec-grouping-operator-static-semantics-early-errors"
+ title="link to this section">12.2.10.1</a></span> Static Semantics: Early Errors</h1>
+ <div class="gp prod"><span class="nt">PrimaryExpression</span> <span class="geq">:</span> <span class="nt">CoverParenthesizedExpressionAndArrowParameterList</span></div>
+ <ul>
+ <li>
+ <p>It is a Syntax Error if the lexical token sequence matched by <span
+ class="nt">CoverParenthesizedExpressionAndArrowParameterList</span> cannot be parsed with no tokens left over using
+ <span class="nt">ParenthesizedExpression</span> as the goal symbol.</p>
+ </li>
+
+ <li>
+ <p>All Early Errors rules for <span class="nt">ParenthesizedExpression</span> and its derived productions also apply
+ to the <span style="font-family: Times New Roman">CoveredParenthesizedExpression</span> of <span
+ class="nt">CoverParenthesizedExpressionAndArrowParameterList</span>.</p>
+ </li>
+ </ul>
+ </section>
+
+ <section id="sec-grouping-operator-static-semantics-isfunctiondefinition">
+ <h1><span class="secnum" id="sec-12.2.10.2"><a href="#sec-grouping-operator-static-semantics-isfunctiondefinition"
+ title="link to this section">12.2.10.2</a></span> Static Semantics: IsFunctionDefinition</h1>
+
+ <p>See also: <a href="#sec-semantics-static-semantics-isfunctiondefinition">12.2.0.2</a>, <a
+ href="#sec-static-semantics-static-semantics-isfunctiondefinition">12.3.1.2</a>, <a
+ href="#sec-postfix-expressions-static-semantics-isfunctiondefinition">12.4.2</a>, <a
+ href="#sec-unary-operators-static-semantics-isfunctiondefinition">12.5.2</a>, <a
+ href="#sec-multiplicative-operators-static-semantics-isfunctiondefinition">12.6.1</a>, <a
+ href="#sec-additive-operators-static-semantics-isfunctiondefinition">12.7.1</a>, <a
+ href="#sec-bitwise-shift-operators-static-semantics-isfunctiondefinition">12.8.1</a>, <a
+ href="#sec-relational-operators-static-semantics-isfunctiondefinition">12.9.1</a>, <a
+ href="#sec-equality-operators-static-semantics-isfunctiondefinition">12.10.1</a>, <a
+ href="#sec-binary-bitwise-operators-static-semantics-isfunctiondefinition">12.11.1</a>, <a
+ href="#sec-binary-logical-operators-static-semantics-isfunctiondefinition">12.12.1</a>, <a
+ href="#sec-conditional-operator-static-semantics-isfunctiondefinition">12.13.1</a>, <a
+ href="#sec-assignment-operators-static-semantics-isfunctiondefinition">12.14.2</a>, <a
+ href="#sec-comma-operator-static-semantics-isfunctiondefinition">12.15.1</a>, <a
+ href="#sec-function-definitions-static-semantics-isfunctiondefinition">14.1.11</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-isfunctiondefinition">14.4.8</a>, <a
+ href="#sec-class-definitions-static-semantics-isfunctiondefinition">14.5.8</a>.</p>
+
+ <div class="gp prod"><span class="nt">ParenthesizedExpression</span> <span class="geq">:</span> <code class="t">(</code> <span class="nt">Expression</span> <code class="t">)</code></div>
+ <ol class="proc">
+ <li>Return IsFunctionDefinition of <i>Expression</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-grouping-operator-static-semantics-isvalidsimpleassignmenttarget">
+ <h1><span class="secnum" id="sec-12.2.10.3"><a
+ href="#sec-grouping-operator-static-semantics-isvalidsimpleassignmenttarget"
+ title="link to this section">12.2.10.3</a></span> Static Semantics: IsValidSimpleAssignmentTarget</h1>
+
+ <p>See also: <a href="#sec-semantics-static-semantics-isidentifierref">12.2.0.3</a>, <a
+ href="#sec-static-semantics-static-semantics-isidentifierref">12.3.1.3</a>, <a
+ href="#sec-postfix-expressions-static-semantics-isvalidsimpleassignmenttarget">12.4.3</a>, <a
+ href="#sec-unary-operators-static-semantics-isvalidsimpleassignmenttarget">12.5.3</a>, <a
+ href="#sec-multiplicative-operators-static-semantics-isvalidsimpleassignmenttarget">12.6.2</a>, <a
+ href="#sec-additive-operators-static-semantics-isvalidsimpleassignmenttarget">12.7.2</a>, <a
+ href="#sec-bitwise-shift-operators-static-semantics-isvalidsimpleassignmenttarget">12.8.2</a>, <a
+ href="#sec-relational-operators-static-semantics-isvalidsimpleassignmenttarget">12.9.2</a>, <a
+ href="#sec-equality-operators-static-semantics-isvalidsimpleassignmenttarget">12.10.2</a>, <a
+ href="#sec-binary-bitwise-operators-static-semantics-isvalidsimpleassignmenttarget">12.11.2</a>, <a
+ href="#sec-binary-logical-operators-static-semantics-isvalidsimpleassignmenttarget">12.12.2</a>, <a
+ href="#sec-conditional-operator-static-semantics-isvalidsimpleassignmenttarget">12.13.2</a>, <a
+ href="#sec-assignment-operators-static-semantics-isvalidsimpleassignmenttarget">12.14.3</a>, <a
+ href="#sec-comma-operator-static-semantics-isvalidsimpleassignmenttarget">12.15.2</a>.</p>
+
+ <div class="gp prod"><span class="nt">ParenthesizedExpression</span> <span class="geq">:</span> <code class="t">(</code> <span class="nt">Expression</span> <code class="t">)</code></div>
+ <ol class="proc">
+ <li>Return IsValidSimpleAssignmentTarget of <i>Expression</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-grouping-operator-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-12.2.10.4"><a href="#sec-grouping-operator-runtime-semantics-evaluation"
+ title="link to this section">12.2.10.4</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">PrimaryExpression</span> <span class="geq">:</span> <span class="nt">CoverParenthesizedExpressionAndArrowParameterList</span></div>
+ <ol class="proc">
+ <li>Let <i>expr</i> be CoveredParenthesizedExpression of <i>CoverParenthesizedExpressionAndArrowParameterList</i>.</li>
+ <li>Return the result of evaluating <i>expr</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ParenthesizedExpression</span> <span class="geq">:</span> <code class="t">(</code> <span class="nt">Expression</span> <code class="t">)</code></div>
+ <ol class="proc">
+ <li>Return the result of evaluating <i>Expression</i>. This may be of type <a
+ href="#sec-reference-specification-type">Reference</a>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> This algorithm does not apply <a href="#sec-getvalue">GetValue</a> to the result of
+ evaluating <i>Expression</i>. The principal motivation for this is so that operators such as <code>delete</code> and
+ <code>typeof</code> may be applied to parenthesized expressions.</p>
+ </div>
+ </section>
+ </section>
+ </section>
+
+ <section id="sec-left-hand-side-expressions">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.3"><a href="#sec-left-hand-side-expressions"
+ title="link to this section">12.3</a></span> Left-Hand-Side Expressions</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">MemberExpression</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="grhsannot">[Lexical goal <span class="nt">InputElementRegExp</span>]</span> <span class="nt">PrimaryExpression</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="nt">MemberExpression</span><sub>[?Yield]</sub> <code class="t">[</code> <span class="nt">Expression</span><sub>[In, ?Yield]</sub> <code class="t">]</code></div>
+ <div class="rhs"><span class="nt">MemberExpression</span><sub>[?Yield]</sub> <code class="t">.</code> <span class="nt">IdentifierName</span></div>
+ <div class="rhs"><span class="nt">MemberExpression</span><sub>[?Yield]</sub> <span class="nt">TemplateLiteral</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><code class="t">super</code> <code class="t">[</code> <span class="nt">Expression</span><sub>[In, ?Yield]</sub> <code class="t">]</code></div>
+ <div class="rhs"><code class="t">super</code> <code class="t">.</code> <span class="nt">IdentifierName</span></div>
+ <div class="rhs"><code class="t">new</code> <code class="t">super</code> <span class="nt">Arguments</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><code class="t">new</code> <span class="nt">MemberExpression</span><sub>[?Yield]</sub> <span class="nt">Arguments</span><sub>[?Yield]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">NewExpression</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">MemberExpression</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><code class="t">new</code> <span class="nt">NewExpression</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><code class="t">new</code> <code class="t">super</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">CallExpression</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">MemberExpression</span><sub>[?Yield]</sub> <span class="nt">Arguments</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><code class="t">super</code> <span class="nt">Arguments</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="nt">CallExpression</span><sub>[?Yield]</sub> <span class="nt">Arguments</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="nt">CallExpression</span><sub>[?Yield]</sub> <code class="t">[</code> <span class="nt">Expression</span><sub>[In, ?Yield]</sub> <code class="t">]</code></div>
+ <div class="rhs"><span class="nt">CallExpression</span><sub>[?Yield]</sub> <code class="t">.</code> <span class="nt">IdentifierName</span></div>
+ <div class="rhs"><span class="nt">CallExpression</span><sub>[?Yield]</sub> <span class="nt">TemplateLiteral</span><sub>[?Yield]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">Arguments</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">(</code> <code class="t">)</code></div>
+ <div class="rhs"><code class="t">(</code> <span class="nt">ArgumentList</span><sub>[?Yield]</sub> <code class="t">)</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ArgumentList</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">AssignmentExpression</span><sub>[In, ?Yield]</sub></div>
+ <div class="rhs"><code class="t">...</code> <span class="nt">AssignmentExpression</span><sub>[In, ?Yield]</sub></div>
+ <div class="rhs"><span class="nt">ArgumentList</span><sub>[?Yield]</sub> <code class="t">,</code> <span class="nt">AssignmentExpression</span><sub>[In, ?Yield]</sub></div>
+ <div class="rhs"><span class="nt">ArgumentList</span><sub>[?Yield]</sub> <code class="t">,</code> <code class="t">...</code> <span class="nt">AssignmentExpression</span><sub>[In, ?Yield]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">LeftHandSideExpression</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">NewExpression</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="nt">CallExpression</span><sub>[?Yield]</sub></div>
+ </div>
+ </div>
+
+ <section id="sec-left-hand-side-expressions-static-semantics">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.3.1"><a href="#sec-left-hand-side-expressions-static-semantics"
+ title="link to this section">12.3.1</a></span> Static Semantics</h1>
+ </div>
+
+ <section id="sec-static-semantics-static-semantics-contains">
+ <h1><span class="secnum" id="sec-12.3.1.1"><a href="#sec-static-semantics-static-semantics-contains"
+ title="link to this section">12.3.1.1</a></span> Static Semantics: Contains</h1>
+
+ <p>With parameter <var>symbol</var>.</p>
+
+ <p>See also: <a href="#sec-static-semantic-rules">5.3</a>, <a
+ href="#sec-object-initializer-static-semantics-computedpropertycontains">12.2.5.2</a>, <a
+ href="#sec-function-definitions-static-semantics-contains">14.1.4</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-contains">14.2.3</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-computedpropertycontains">14.4.3</a>, <a
+ href="#sec-class-definitions-static-semantics-contains">14.5.4</a></p>
+
+ <div class="gp prod"><span class="nt">MemberExpression</span> <span class="geq">:</span> <span class="nt">MemberExpression</span> <code class="t">.</code> <span class="nt">IdentifierName</span></div>
+ <ol class="proc">
+ <li>If <i>MemberExpression</i> Contains <i>symbol</i> is <b>true</b>, return <b>true</b>.</li>
+ <li>If <i>symbol</i> is a <i>ReservedWord</i>, return <b>false</b>.</li>
+ <li>If <i>symbol</i> is an <i>Identifier</i> and StringValue of <i>symbol</i> is the same value as the StringValue of
+ <i>IdentifierName</i>, return <b>true</b>;</li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">MemberExpression</span> <span class="geq">:</span> <code class="t">super</code> <code class="t">.</code> <span class="nt">IdentifierName</span></div>
+ <ol class="proc">
+ <li>If <i>symbol</i> is the <i>ReservedWord</i> <code>super</code>, return <b>true</b>.</li>
+ <li>If <i>symbol</i> is a <i>ReservedWord</i>, return <b>false</b>.</li>
+ <li>If <i>symbol</i> is an <i>Identifier</i> and StringValue of <i>symbol</i> is the same value as the StringValue of
+ <i>IdentifierName</i>, return <b>true</b>;</li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">CallExpression</span> <span class="geq">:</span> <span class="nt">CallExpression</span> <code class="t">.</code> <span class="nt">IdentifierName</span></div>
+ <ol class="proc">
+ <li>If <i>CallExpression</i> Contains <i>symbol</i> is <b>true</b>, return <b>true</b>.</li>
+ <li>If <i>symbol</i> is a <i>ReservedWord</i>, return <b>false</b>.</li>
+ <li>If <i>symbol</i> is an <i>Identifier</i> and StringValue of <i>symbol</i> is the same value as the StringValue of
+ <i>IdentifierName</i>, return <b>true</b>;</li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-static-semantics-static-semantics-isfunctiondefinition">
+ <h1><span class="secnum" id="sec-12.3.1.2"><a href="#sec-static-semantics-static-semantics-isfunctiondefinition"
+ title="link to this section">12.3.1.2</a></span> Static Semantics: IsFunctionDefinition</h1>
+
+ <p>See also: <a href="#sec-semantics-static-semantics-isfunctiondefinition">12.2.0.2</a>, <a
+ href="#sec-grouping-operator-static-semantics-isfunctiondefinition">12.2.10.2</a>, <a
+ href="#sec-postfix-expressions-static-semantics-isfunctiondefinition">12.4.2</a>, <a
+ href="#sec-unary-operators-static-semantics-isfunctiondefinition">12.5.2</a>, <a
+ href="#sec-multiplicative-operators-static-semantics-isfunctiondefinition">12.6.1</a>, <a
+ href="#sec-additive-operators-static-semantics-isfunctiondefinition">12.7.1</a>, <a
+ href="#sec-bitwise-shift-operators-static-semantics-isfunctiondefinition">12.8.1</a>, <a
+ href="#sec-relational-operators-static-semantics-isfunctiondefinition">12.9.1</a>, <a
+ href="#sec-equality-operators-static-semantics-isfunctiondefinition">12.10.1</a>, <a
+ href="#sec-binary-bitwise-operators-static-semantics-isfunctiondefinition">12.11.1</a>, <a
+ href="#sec-binary-logical-operators-static-semantics-isfunctiondefinition">12.12.1</a>, <a
+ href="#sec-conditional-operator-static-semantics-isfunctiondefinition">12.13.1</a>, <a
+ href="#sec-assignment-operators-static-semantics-isfunctiondefinition">12.14.2</a>, <a
+ href="#sec-comma-operator-static-semantics-isfunctiondefinition">12.15.1</a>, <a
+ href="#sec-function-definitions-static-semantics-isfunctiondefinition">14.1.11</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-isfunctiondefinition">14.4.8</a>, <a
+ href="#sec-class-definitions-static-semantics-isfunctiondefinition">14.5.8</a>.</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">MemberExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">MemberExpression</span> <code class="t">[</code> <span class="nt">Expression</span> <code class="t">]</code></div>
+ <div class="rhs"><span class="nt">MemberExpression</span> <code class="t">.</code> <span class="nt">IdentifierName</span></div>
+ <div class="rhs"><span class="nt">MemberExpression</span> <span class="nt">TemplateLiteral</span></div>
+ <div class="rhs"><code class="t">super</code> <code class="t">[</code> <span class="nt">Expression</span> <code class="t">]</code></div>
+ <div class="rhs"><code class="t">super</code> <code class="t">.</code> <span class="nt">IdentifierName</span></div>
+ <div class="rhs"><code class="t">new</code> <code class="t">super</code> <span class="nt">Arguments</span></div>
+ <div class="rhs"><code class="t">new</code> <span class="nt">MemberExpression</span> <span class="nt">Arguments</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">NewExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">new</code> <span class="nt">NewExpression</span></div>
+ <div class="rhs"><code class="t">new</code> <code class="t">super</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">CallExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">MemberExpression</span> <span class="nt">Arguments</span></div>
+ <div class="rhs"><code class="t">super</code> <span class="nt">Arguments</span></div>
+ <div class="rhs"><span class="nt">CallExpression</span> <span class="nt">Arguments</span></div>
+ <div class="rhs"><span class="nt">CallExpression</span> <code class="t">[</code> <span class="nt">Expression</span> <code class="t">]</code></div>
+ <div class="rhs"><span class="nt">CallExpression</span> <code class="t">.</code> <span class="nt">IdentifierName</span></div>
+ <div class="rhs"><span class="nt">CallExpression</span> <span class="nt">TemplateLiteral</span></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-static-semantics-static-semantics-isidentifierref">
+ <h1><span class="secnum" id="sec-12.3.1.3"><a href="#sec-static-semantics-static-semantics-isidentifierref"
+ title="link to this section">12.3.1.3</a></span> Static Semantics: IsIdentifierRef</h1>
+
+ <p>See also: <a href="#sec-semantics-static-semantics-isidentifierref">12.2.0.3</a>.</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">LeftHandSideExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">CallExpression</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">MemberExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">MemberExpression</span> <code class="t">[</code> <span class="nt">Expression</span> <code class="t">]</code></div>
+ <div class="rhs"><span class="nt">MemberExpression</span> <code class="t">.</code> <span class="nt">IdentifierName</span></div>
+ <div class="rhs"><span class="nt">MemberExpression</span> <span class="nt">TemplateLiteral</span></div>
+ <div class="rhs"><code class="t">super</code> <code class="t">[</code> <span class="nt">Expression</span> <code class="t">]</code></div>
+ <div class="rhs"><code class="t">super</code> <code class="t">.</code> <span class="nt">IdentifierName</span></div>
+ <div class="rhs"><code class="t">new</code> <code class="t">super</code> <span class="nt">Arguments</span></div>
+ <div class="rhs"><code class="t">new</code> <span class="nt">MemberExpression</span> <span class="nt">Arguments</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">NewExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">new</code> <span class="nt">NewExpression</span></div>
+ <div class="rhs"><code class="t">new</code> <code class="t">super</code></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-static-semantics-static-semantics-isvalidsimpleassignmenttarget">
+ <h1><span class="secnum" id="sec-12.3.1.4"><a href="#sec-static-semantics-static-semantics-isvalidsimpleassignmenttarget"
+ title="link to this section">12.3.1.4</a></span> Static Semantics: IsValidSimpleAssignmentTarget</h1>
+
+ <p>See also: <a href="#sec-semantics-static-semantics-isidentifierref">12.2.0.3</a>, <a
+ href="#sec-grouping-operator-static-semantics-isvalidsimpleassignmenttarget">12.2.10.3</a>, <a
+ href="#sec-postfix-expressions-static-semantics-isvalidsimpleassignmenttarget">12.4.3</a>, <a
+ href="#sec-unary-operators-static-semantics-isvalidsimpleassignmenttarget">12.5.3</a>, <a
+ href="#sec-multiplicative-operators-static-semantics-isvalidsimpleassignmenttarget">12.6.2</a>, <a
+ href="#sec-additive-operators-static-semantics-isvalidsimpleassignmenttarget">12.7.2</a>, <a
+ href="#sec-bitwise-shift-operators-static-semantics-isvalidsimpleassignmenttarget">12.8.2</a>, <a
+ href="#sec-relational-operators-static-semantics-isvalidsimpleassignmenttarget">12.9.2</a>, <a
+ href="#sec-equality-operators-static-semantics-isvalidsimpleassignmenttarget">12.10.2</a>, <a
+ href="#sec-binary-bitwise-operators-static-semantics-isvalidsimpleassignmenttarget">12.11.2</a>, <a
+ href="#sec-binary-logical-operators-static-semantics-isvalidsimpleassignmenttarget">12.12.2</a>, <a
+ href="#sec-conditional-operator-static-semantics-isvalidsimpleassignmenttarget">12.13.2</a>, <a
+ href="#sec-assignment-operators-static-semantics-isvalidsimpleassignmenttarget">12.14.3</a>, <a
+ href="#sec-comma-operator-static-semantics-isvalidsimpleassignmenttarget">12.15.2</a>.</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">CallExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">CallExpression</span> <code class="t">[</code> <span class="nt">Expression</span> <code class="t">]</code></div>
+ <div class="rhs"><span class="nt">CallExpression</span> <code class="t">.</code> <span class="nt">IdentifierName</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">MemberExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">MemberExpression</span> <code class="t">[</code> <span class="nt">Expression</span> <code class="t">]</code></div>
+ <div class="rhs"><span class="nt">MemberExpression</span> <code class="t">.</code> <span class="nt">IdentifierName</span></div>
+ <div class="rhs"><code class="t">super</code> <code class="t">[</code> <span class="nt">Expression</span> <code class="t">]</code></div>
+ <div class="rhs"><code class="t">super</code> <code class="t">.</code> <span class="nt">IdentifierName</span></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return <b>true</b>.</li>
+ </ol>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">CallExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">MemberExpression</span> <span class="nt">Arguments</span></div>
+ <div class="rhs"><code class="t">super</code> <span class="nt">Arguments</span></div>
+ <div class="rhs"><span class="nt">CallExpression</span> <span class="nt">Arguments</span></div>
+ <div class="rhs"><span class="nt">CallExpression</span> <span class="nt">TemplateLiteral</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">NewExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">new</code> <span class="nt">NewExpression</span></div>
+ <div class="rhs"><code class="t">new</code> <code class="t">super</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">MemberExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">MemberExpression</span> <span class="nt">TemplateLiteral</span></div>
+ <div class="rhs"><code class="t">new</code> <code class="t">super</code> <span class="nt">Arguments</span></div>
+ <div class="rhs"><code class="t">new</code> <span class="nt">MemberExpression</span> <span class="nt">Arguments</span></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-property-accessors">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.3.2"><a href="#sec-property-accessors" title="link to this section">12.3.2</a></span>
+ Property Accessors</h1>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Properties are accessed by name, using either the dot notation:</p>
+ </div>
+
+ <div class="lhs">MemberExpression <code>.</code> IdentifierName<br>CallExpression <code>.</code> IdentifierName</div>
+
+ <p>or the bracket notation:</p>
+
+ <div class="lhs">MemberExpression <code>[</code> Expression <code>]</code><br>CallExpression <code>[</code> Expression <code>]</code></div>
+
+ <p>The dot notation is explained by the following syntactic conversion:</p>
+
+ <div class="lhs">MemberExpression <code>.</code> IdentifierName</div>
+
+ <p>is identical in its behaviour to</p>
+
+ <div class="lhs">MemberExpression <code>[</code> <identifier-name-string> <code>]</code></div>
+
+ <p>and similarly</p>
+
+ <div class="lhs">CallExpression <code>.</code> IdentifierName</div>
+
+ <p>is identical in its behaviour to</p>
+
+ <div class="lhs">CallExpression <code>[</code> <identifier-name-string> <code>]</code></div>
+
+ <p>where <var><identifier-name-string></var> is a string literal containing the same sequence of characters after
+ processing of Unicode escape sequences as the <span class="nt">IdentifierName</span>.</p>
+ </div>
+
+ <section id="sec-property-accessors-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-12.3.2.1"><a href="#sec-property-accessors-runtime-semantics-evaluation"
+ title="link to this section">12.3.2.1</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">MemberExpression</span> <span class="geq">:</span> <span class="nt">MemberExpression</span> <code class="t">[</code> <span class="nt">Expression</span> <code class="t">]</code></div>
+ <ol class="proc">
+ <li>Let <i>baseReference</i> be the result of evaluating <i>MemberExpression</i>.</li>
+ <li>Let <i>baseValue</i> be <a href="#sec-getvalue">GetValue</a>(<i>baseReference</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>baseValue</i>).</li>
+ <li>Let <i>propertyNameReference</i> be the result of evaluating <i>Expression</i>.</li>
+ <li>Let <i>propertyNameValue</i> be <a href="#sec-getvalue">GetValue</a>(<i>propertyNameReference</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>propertyNameValue</i>).</li>
+ <li>Let <i>bv</i> be <a href="#sec-checkobjectcoercible">CheckObjectCoercible</a>(<i>baseValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>bv</i>).</li>
+ <li>Let <i>propertyNameString</i> be <a href="#sec-tostring">ToString</a>(<i>propertyNameValue</i>).</li>
+ <li>If the code matched by the syntactic production that is being evaluated is <a href="#sec-strict-mode-code">strict
+ mode code</a>, let <i>strict</i> be <b>true</b>, else let <i>strict</i> be <b>false</b>.</li>
+ <li>Return a value of type <a href="#sec-reference-specification-type">Reference</a> whose base value is <i>bv</i> and
+ whose referenced name is <i>propertyNameString</i>, and whose strict reference flag is <i>strict</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">CallExpression</span> <span class="geq">:</span> <span class="nt">CallExpression</span> <code class="t">[</code> <span class="nt">Expression</span> <code class="t">]</code></div>
+
+ <p>Is evaluated in exactly the same manner as <span class="prod"><span class="nt">MemberExpression</span> <span
+ class="geq">:</span> <span class="nt">MemberExpression</span> <code class="t">[</code> <span class="nt">Expression</span>
+ <code class="t">]</code></span> except that the contained <span class="nt">CallExpression</span> is evaluated in step
+ 1.</p>
+ </section>
+ </section>
+
+ <section id="sec-new-operator">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.3.3"><a href="#sec-new-operator" title="link to this section">12.3.3</a></span> The
+ <code>new</code> Operator</h1>
+ </div>
+
+ <section id="sec-new-operator-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-12.3.3.1"><a href="#sec-new-operator-runtime-semantics-evaluation"
+ title="link to this section">12.3.3.1</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">NewExpression</span> <span class="geq">:</span> <code class="t">new</code> <span class="nt">NewExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>ref</i> be the result of evaluating <i>NewExpression</i>.</li>
+ <li>Let <i>constructor</i> be <a href="#sec-getvalue">GetValue</a>(<i>ref</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>constructor</i>).</li>
+ <li>If <a href="#sec-isconstructor">IsConstructor</a>(<i>constructor</i>) is <b>false</b>, throw a <b>TypeError</b>
+ exception.</li>
+ <li>Let <i>thisCall</i> be this <i>NewExpression</i>.</li>
+ <li>Let <i>tailCall</i> be <a href="#sec-isintailposition">IsInTailPosition</a>(<i>thisCall</i>). (See <a
+ href="#sec-isintailposition">14.6.1</a>)</li>
+ <li>If <i>tailCall</i> is <b>true</b>, then perform the <a href="#sec-preparefortailcall">PrepareForTailCall</a>
+ abstract operation.</li>
+ <li>Let <i>result</i> be the result of calling the [[Construct]] internal method on <i>constructor</i> with an empty <a
+ href="#sec-list-and-record-specification-type">List</a> as the argument.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: If <i>tailCall</i> is <b>true</b>, the above call of [[Construct]]
+ will not return here, but instead evaluation will continue as if the following return has already occurred.</li>
+ <li>Return <i>result</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">MemberExpression</span> <span class="geq">:</span> <code class="t">new</code> <span class="nt">MemberExpression</span> <span class="nt">Arguments</span></div>
+ <ol class="proc">
+ <li>Let <i>ref</i> be the result of evaluating <i>MemberExpression</i>.</li>
+ <li>Let <i>constructor</i> be <a href="#sec-getvalue">GetValue</a>(<i>ref</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>constructor</i>).</li>
+ <li>Let <i>argList</i> be the result of evaluating <i>Arguments</i>, producing a <a
+ href="#sec-list-and-record-specification-type">List</a> of argument values (<a
+ href="#sec-argument-lists">12.3.6</a>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>argList</i>).</li>
+ <li>If <a href="#sec-isconstructor">IsConstructor</a> (<i>constructor</i>) is <b>false</b>, throw a <b>TypeError</b>
+ exception.</li>
+ <li>Let <i>thisCall</i> be this <i>MemberExpression</i>.</li>
+ <li>Let <i>tailCall</i> be <a href="#sec-isintailposition">IsInTailPosition</a>(<i>thisCall</i>). (See <a
+ href="#sec-isintailposition">14.6.1</a>)</li>
+ <li>If <i>tailCall</i> is <b>true</b>, then perform the <a href="#sec-preparefortailcall">PrepareForTailCall</a>
+ abstract operation.</li>
+ <li>Let <i>result</i> be the result of calling the [[Construct]] internal method on <i>constructor</i>, passing
+ <i>argList</i> as the argument.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: If <i>tailCall</i> is <b>true</b>, the above call of [[Construct]]
+ will not return here, but instead evaluation will continue as if the following return has already occurred.</li>
+ <li>Return <i>result</i>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-function-calls">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.3.4"><a href="#sec-function-calls" title="link to this section">12.3.4</a></span>
+ Function Calls</h1>
+ </div>
+
+ <section id="sec-function-calls-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-12.3.4.1"><a href="#sec-function-calls-runtime-semantics-evaluation"
+ title="link to this section">12.3.4.1</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">CallExpression</span> <span class="geq">:</span> <span class="nt">MemberExpression</span> <span class="nt">Arguments</span></div>
+ <ol class="proc">
+ <li>Let <i>ref</i> be the result of evaluating <i>MemberExpression</i>.</li>
+ <li>If <i>MemberExpression</i> consists solely of the <i>IdentifierName</i> <code>eval</code>, then
+ <ol class="block">
+ <li><span style="background-color: #FFC000">check if direct eval</span></li>
+ <li>Return EvaluateCall(<i>ref</i>, <i>Arguments</i>, <b>false</b>).</li>
+ </ol>
+ </li>
+ <li>Let <i>thisCall</i> be this <i>CallExpression</i>.</li>
+ <li>Let <i>tailCall</i> be <a href="#sec-isintailposition">IsInTailPosition</a>(<i>thisCall</i>). (See <a
+ href="#sec-isintailposition">14.6.1</a>)</li>
+ <li>Return EvaluateCall(<i>ref</i>, <i>Arguments</i>, <i>tailCall</i>).</li>
+ </ol>
+ <div class="gp prod"><span class="nt">CallExpression</span> <span class="geq">:</span> <span class="nt">CallExpression</span> <span class="nt">Arguments</span></div>
+ <ol class="proc">
+ <li>Let <i>ref</i> be the result of evaluating <i>CallExpression</i>.</li>
+ <li>Let <i>thisCall</i> be this <i>CallExpression</i></li>
+ <li>Let <i>tailCall</i> be <a href="#sec-isintailposition">IsInTailPosition</a>(<i>thisCall</i>). (See <a
+ href="#sec-isintailposition">14.6.1</a>)</li>
+ <li>Return EvaluateCall(<i>ref</i>, <i>Arguments</i>, <i>tailCall</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-runtime-semantics-evaluatecall">
+ <h1><span class="secnum" id="sec-12.3.4.2"><a href="#sec-runtime-semantics-evaluatecall"
+ title="link to this section">12.3.4.2</a></span> Runtime Semantics: EvaluateCall</h1>
+
+ <p>The abstract operation EvaluateCall takes as arguments a value <i>ref</i>, and a syntactic grammar production
+ <i>arguments</i>, and a Boolean argument <i>tailPosition</i>. It performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>func</i> be <a href="#sec-getvalue">GetValue</a>(<i>ref</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>func</i>).</li>
+ <li>Let <i>argList</i> be ArgumentListEvaluation(<i>arguments</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>argList</i>).</li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>func</i>) is <b>false</b>, throw a <b>TypeError</b> exception.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>ref</i>) is <a
+ href="#sec-reference-specification-type">Reference</a>, then
+ <ol class="block">
+ <li>If <a href="#sec-reference-specification-type">IsPropertyReference</a>(<i>ref</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>thisValue</i> be <a href="#sec-getthisvalue">GetThisValue</a>(<i>ref</i>).</li>
+ </ol>
+ </li>
+ <li>Else, the base of <i>ref</i> is an <a href="#sec-environment-records">Environment Record</a>
+ <ol class="block">
+ <li>Let <i>thisValue</i> be the result of calling the WithBaseObject concrete method of <a
+ href="#sec-reference-specification-type">GetBase</a>(<i>ref</i>).</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Else <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>ref</i>) is not <a
+ href="#sec-reference-specification-type">Reference</a>,
+ <ol class="block">
+ <li>Let <i>thisValue</i> be <b>undefined</b>.</li>
+ </ol>
+ </li>
+ <li>If <i>tailPosition</i> is <b>true</b>, then perform the <a href="#sec-preparefortailcall">PrepareForTailCall</a>
+ abstract operation.</li>
+ <li>Let <i>result</i> be the result of calling the [[Call]] internal method on <i>func</i>, passing <i>thisValue</i> as
+ the <i>thisArgument</i> and <i>argList</i> as the <i>argumentsList</i>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: If <i>tailPosition</i> is <b>true</b>, the above call will not
+ return here, but instead evaluation will continue as if the following return has already occurred.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: If <i>result</i> is not an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a> then <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>result</i>) is an <a
+ href="#sec-ecmascript-language-types">ECMAScript language type</a></li>
+ <li>Return <i>result</i>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-super-keyword">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.3.5"><a href="#sec-super-keyword" title="link to this section">12.3.5</a></span> The
+ <code>super</code> Keyword</h1>
+ </div>
+
+ <section id="sec-super-keyword-static-semantics-early-errors">
+ <h1><span class="secnum" id="sec-12.3.5.1"><a href="#sec-super-keyword-static-semantics-early-errors"
+ title="link to this section">12.3.5.1</a></span> Static Semantics: Early Errors</h1>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">MemberExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">super</code> <code class="t">[</code> <span class="nt">Expression</span> <code class="t">]</code></div>
+ <div class="rhs"><code class="t">super</code> <code class="t">.</code> <span class="nt">IdentifierName</span></div>
+ <div class="rhs"><code class="t">new</code> <code class="t">super</code> <span class="nt">Arguments</span></div>
+ <div class="rhs"><span class="nt">NewExpression</span> <code class="t">:</code> <code class="t">new</code> <code class="t">super</code></div>
+ <div class="rhs"><span class="nt">CallExpression</span> <code class="t">:</code> <code class="t">super</code> <span class="nt">Arguments</span></div>
+ </div>
+
+ <ul>
+ <li>
+ <p>It is a Syntax Error if the source code parsed with this production is global code that is not eval code.</p>
+ </li>
+
+ <li>
+ <p>It is a Syntax Error if the source code parsed with this production is eval code and the source code is not being
+ processed by a direct call to eval that is contained in function code.</p>
+ </li>
+ </ul>
+ </section>
+
+ <section id="sec-super-keyword-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-12.3.5.2"><a href="#sec-super-keyword-runtime-semantics-evaluation"
+ title="link to this section">12.3.5.2</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">MemberExpression</span> <span class="geq">:</span> <code class="t">super</code> <code class="t">[</code> <span class="nt">Expression</span> <code class="t">]</code></div>
+ <ol class="proc">
+ <li>Let <i>propertyNameReference</i> be the result of evaluating <i>Expression</i>.</li>
+ <li>Let <i>propertyNameValue</i> be <a href="#sec-getvalue">GetValue</a>(<i>propertyNameReference</i>).</li>
+ <li>Let <i>propertyKey</i> be <a href="#sec-topropertykey">ToPropertyKey</a>(<i>propertyNameValue</i>).</li>
+ <li>If the code matched by the syntactic production that is being evaluated is <a href="#sec-strict-mode-code">strict
+ mode code</a>, let <i>strict</i> be <b>true</b>, else let <i>strict</i> be <b>false</b>.</li>
+ <li>Return <a href="#sec-makesuperreference">MakeSuperReference</a>(<i>propertyKey</i>, <i>strict</i>).</li>
+ </ol>
+ <div class="gp prod"><span class="nt">MemberExpression</span> <span class="geq">:</span> <code class="t">super</code> <code class="t">.</code> <span class="nt">IdentifierName</span></div>
+ <ol class="proc">
+ <li>Let <i>propertyKey</i> be StringValue of <i>IdentifierName</i>.</li>
+ <li>If the code matched by the syntactic production that is being evaluated is <a href="#sec-strict-mode-code">strict
+ mode code</a>, let <i>strict</i> be <b>true</b>, else let <i>strict</i> be <b>false</b>.</li>
+ <li>Return <a href="#sec-makesuperreference">MakeSuperReference</a>(<i>propertyKey</i>, <i>strict</i>).</li>
+ </ol>
+ <div class="gp prod"><span class="nt">MemberExpression</span> <span class="geq">:</span> <code class="t">new</code> <code class="t">super</code> <span class="nt">Arguments</span></div>
+ <ol class="proc">
+ <li>If the code matched by the syntactic production that is being evaluated is <a href="#sec-strict-mode-code">strict
+ mode code</a>, let <i>strict</i> be <b>true</b>, else let <i>strict</i> be <b>false</b>.</li>
+ <li>Let <i>ref</i> be <a href="#sec-makesuperreference">MakeSuperReference</a>(<b>undefined</b>, <i>strict</i>).</li>
+ <li>Let <i>constructor</i> be <a href="#sec-getvalue">GetValue</a>(<i>ref</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>constructor</i>).</li>
+ <li>Let <i>argList</i> be the result of evaluating <i>Arguments</i>, producing a <a
+ href="#sec-list-and-record-specification-type">List</a> of argument values (<a
+ href="#sec-argument-lists">12.3.6</a>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>argList</i>).</li>
+ <li>If <a href="#sec-isconstructor">IsConstructor</a> (<i>constructor</i>) is <b>false</b>, throw a <b>TypeError</b>
+ exception.</li>
+ <li>Let <i>thisCall</i> be this <i>MemberExpression</i>.</li>
+ <li>Let <i>tailCall</i> be <a href="#sec-isintailposition">IsInTailPosition</a>(<i>thisCall</i>). (See <a
+ href="#sec-isintailposition">14.6.1</a>)</li>
+ <li>If <i>tailCall</i> is <b>true</b>, then perform the <a href="#sec-preparefortailcall">PrepareForTailCall</a>
+ abstract operation.</li>
+ <li>Let <i>result</i> be the result of calling the [[Construct]] internal method on <i>constructor</i>, passing
+ <i>argList</i> as the argument.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: If <i>tailCall</i> is <b>true</b>, the above call of [[Construct]]
+ will not return here, but instead evaluation will continue as if the following return has already occurred.</li>
+ <li>Return <i>result</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">NewExpression</span> <span class="geq">:</span> <code class="t">new</code> <code class="t">super</code></div>
+ <ol class="proc">
+ <li>If the code matched by the syntactic production that is being evaluated is <a href="#sec-strict-mode-code">strict
+ mode code</a>, let <i>strict</i> be <b>true</b>, else let <i>strict</i> be <b>false</b>.</li>
+ <li>Let <i>ref</i> be <a href="#sec-makesuperreference">MakeSuperReference</a>(<b>undefined</b>, <i>strict</i>).</li>
+ <li>Let <i>constructor</i> be <a href="#sec-getvalue">GetValue</a>(<i>ref</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>constructor</i>).</li>
+ <li>Let <i>argList</i> be a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>argList</i>).</li>
+ <li>If <a href="#sec-isconstructor">IsConstructor</a> (<i>constructor</i>) is <b>false</b>, throw a <b>TypeError</b>
+ exception.</li>
+ <li>Let <i>thisCall</i> be this <i>NewExpression</i>.</li>
+ <li>Let <i>tailCall</i> be <a href="#sec-isintailposition">IsInTailPosition</a>(<i>thisCall</i>). (See <a
+ href="#sec-isintailposition">14.6.1</a>)</li>
+ <li>If <i>tailCall</i> is <b>true</b>, then perform the <a href="#sec-preparefortailcall">PrepareForTailCall</a>
+ abstract operation.</li>
+ <li>Let <i>result</i> be the result of calling the [[Construct]] internal method on <i>constructor</i>, passing
+ <i>argList</i> as the argument.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: If <i>tailCall</i> is <b>true</b>, the above call of [[Construct]]
+ will not return here, but instead evaluation will continue as if the following return has already occurred.</li>
+ <li>Return <i>result</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">CallExpression</span> <span class="geq">:</span> <code class="t">super</code> <span class="nt">Arguments</span></div>
+ <ol class="proc">
+ <li>If the code matched by the syntactic production that is being evaluated is <a href="#sec-strict-mode-code">strict
+ mode code</a>, let <i>strict</i> be <b>true</b>, else let <i>strict</i> be <b>false</b>.</li>
+ <li>Let <i>ref</i> be <a href="#sec-makesuperreference">MakeSuperReference</a>(<b>undefined</b>, <i>strict</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>ref</i>).</li>
+ <li>Let <i>thisCall</i> be this <i>CallExpression</i>.</li>
+ <li>Let <i>tailCall</i> be <a href="#sec-isintailposition">IsInTailPosition</a>(<i>thisCall</i>). (See <a
+ href="#sec-isintailposition">14.6.1</a>)</li>
+ <li>Return EvaluateCall(<i>ref</i>, <i>Arguments</i>, <i>tailCall</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-makesuperreference">
+ <h1><span class="secnum" id="sec-12.3.5.3"><a href="#sec-makesuperreference"
+ title="link to this section">12.3.5.3</a></span> Runtime Semantics: MakeSuperReference(propertyKey, strict)</h1>
+
+ <p>The abstract operation MakeSuperReference with arguments <var>propertyKey</var> and <var>strict</var> performs the
+ following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>env</i> be <a href="#sec-getthisenvironment">GetThisEnvironment</a>( ).</li>
+ <li>If the result of calling the HasSuperBinding concrete method of <i>env</i> is <b>false</b>, then throw a
+ <b>ReferenceError</b> exception.</li>
+ <li>Let <i>actualThis</i> be the result of calling the GetThisBinding concrete method of <i>env</i>.</li>
+ <li>Let <i>baseValue</i> be the result of calling the <a href="#sec-getsuperbase">GetSuperBase</a> concrete method of
+ <i>env</i>.</li>
+ <li>Let <i>bv</i> be <a href="#sec-checkobjectcoercible">CheckObjectCoercible</a>(<i>baseValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>bv</i>).</li>
+ <li>If <i>propertyKey</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>propertyKey</i> be the result of calling the <a href="#sec-getmethodname">GetMethodName</a> concrete
+ method of <i>env</i>.</li>
+ <li>If <i>propertyKey</i> is <b>undefined</b>, then throw a <b>ReferenceError</b> exception.</li>
+ </ol>
+ </li>
+ <li>Return a value of type <a href="#sec-reference-specification-type">Reference</a> that is a Super <a
+ href="#sec-reference-specification-type">Reference</a> whose base value is <i>bv</i>, whose referenced name is
+ <i>propertyKey</i>, whose thisValue is <i>actualThis</i>, and whose strict reference flag is <i>strict</i>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-argument-lists">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.3.6"><a href="#sec-argument-lists" title="link to this section">12.3.6</a></span>
+ Argument Lists</h1>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The evaluation of an argument list produces a <a
+ href="#sec-list-and-record-specification-type">List</a> of values (<a href="#sec-list-and-record-specification-type">see
+ 6.2.1</a>).</p>
+ </div>
+ </div>
+
+ <section id="sec-argument-lists-runtime-semantics-argumentlistevaluation">
+ <h1><span class="secnum" id="sec-12.3.6.1"><a href="#sec-argument-lists-runtime-semantics-argumentlistevaluation"
+ title="link to this section">12.3.6.1</a></span> <span style="font-family: sans-serif">Runtime Semantics:</span>
+ ArgumentListEvaluation</h1>
+
+ <p>See also: <a href="#sec-runtime-semantics-runtime-semantics-argumentlistevaluation">12.2.9.2.1</a></p>
+
+ <div class="gp prod"><span class="nt">Arguments</span> <span class="geq">:</span> <code class="t">(</code> <code class="t">)</code></div>
+ <ol class="proc">
+ <li>Return an empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ArgumentList</span> <span class="geq">:</span> <span class="nt">AssignmentExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>ref</i> be the result of evaluating <i>AssignmentExpression</i>.</li>
+ <li>Let <i>arg</i> be <a href="#sec-getvalue">GetValue</a>(<i>ref</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>arg</i>).</li>
+ <li>Return a <a href="#sec-list-and-record-specification-type">List</a> whose sole item is <i>arg</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ArgumentList</span> <span class="geq">:</span> <code class="t">...</code> <span class="nt">AssignmentExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>list</i> be an empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Let <i>spreadRef</i> be the result of evaluating <i>AssignmentExpression</i>.</li>
+ <li>Let <i>spreadObj</i> be <a href="#sec-getvalue">GetValue</a>(<i>spreadRef</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>spreadObj</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>spreadObj</i>) is not Object, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>Let <i>iterator</i> be <a href="#sec-getiterator">GetIterator</a>(<i>spreadObj</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>iterator</i>).</li>
+ <li>Repeat
+ <ol class="block">
+ <li>Let <i>next</i> be <a href="#sec-iteratorstep">IteratorStep</a>(<i>iterator</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>next</i>).</li>
+ <li>If <i>next</i> is <b>false</b>, then return <i>list</i>.</li>
+ <li>Let <i>nextArg</i> be <a href="#sec-iteratorvalue">IteratorValue</a>(<i>next</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>nextArg</i>).</li>
+ <li>Append <i>nextArg</i> as the last element of <i>list</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ <div class="gp prod"><span class="nt">ArgumentList</span> <span class="geq">:</span> <span class="nt">ArgumentList</span> <code class="t">,</code> <span class="nt">AssignmentExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>precedingArgs</i> be the result of evaluating <i>ArgumentList</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>precedingArgs</i>).</li>
+ <li>Let <i>ref</i> be the result of evaluating <i>AssignmentExpression</i>.</li>
+ <li>Let <i>arg</i> be <a href="#sec-getvalue">GetValue</a>(<i>ref</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>arg</i>).</li>
+ <li>Return a <a href="#sec-list-and-record-specification-type">List</a> whose length is one greater than the length of
+ <i>precedingArgs</i> and whose items are the items of <i>precedingArgs</i>, in order, followed at the end by
+ <i>arg</i> which is the last item of the new list.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ArgumentList</span> <span class="geq">:</span> <span class="nt">ArgumentList</span> <code class="t">,</code> <code class="t">...</code> <span class="nt">AssignmentExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>precedingArgs</i> be the result of evaluating <i>ArgumentList</i>.</li>
+ <li>Let <i>spreadRef</i> be the result of evaluating <i>AssignmentExpression</i>.</li>
+ <li>Let <i>spreadObj</i> be <a href="#sec-getvalue">GetValue</a>(<i>spreadRef</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>spreadObj</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>spreadObj</i>) is not Object, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>Let <i>iterator</i> be <a href="#sec-getiterator">GetIterator</a>(<i>spreadObj</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>iterator</i>).</li>
+ <li>Repeat
+ <ol class="block">
+ <li>Let <i>next</i> be <a href="#sec-iteratorstep">IteratorStep</a>(<i>iterator</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>next</i>).</li>
+ <li>If <i>next</i> is <b>false</b>, then return <i>precedingArgs</i>.</li>
+ <li>Let <i>nextArg</i> be <a href="#sec-iteratorvalue">IteratorValue</a>(<i>next</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>nextArg</i>).</li>
+ <li>Append <i>nextArg</i> as the last element of <i>precedingArgs</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-tagged-templates">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.3.7"><a href="#sec-tagged-templates" title="link to this section">12.3.7</a></span>
+ Tagged Templates</h1>
+ </div>
+
+ <section id="sec-tagged-templates-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-12.3.7.1"><a href="#sec-tagged-templates-runtime-semantics-evaluation"
+ title="link to this section">12.3.7.1</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">MemberExpression</span> <span class="geq">:</span> <span class="nt">MemberExpression</span> <span class="nt">TemplateLiteral</span></div>
+ <ol class="proc">
+ <li>Let <i>tagRef</i> be the result of evaluating <i>MemberExpression</i>.</li>
+ <li>Let <i>thisCall</i> be this <i>MemberExpression</i>.</li>
+ <li>Let <i>tailCall</i> be <a href="#sec-isintailposition">IsInTailPosition</a>(<i>thisCall</i>). (See <a
+ href="#sec-isintailposition">14.6.1</a>)</li>
+ <li>Return EvaluateCall(<i>tagRef</i>, <i>TemplateLiteral</i>, <i>tailCall</i>).</li>
+ </ol>
+ <div class="gp prod"><span class="nt">CallExpression</span> <span class="geq">:</span> <span class="nt">CallExpression</span> <span class="nt">TemplateLiteral</span></div>
+ <ol class="proc">
+ <li>Let <i>tagRef</i> be the result of evaluating <i>CallExpression</i>.</li>
+ <li>Let <i>thisCall</i> be this <i>CallExpression</i>.</li>
+ <li>Let <i>tailCall</i> be <a href="#sec-isintailposition">IsInTailPosition</a>(<i>thisCall</i>). (See <a
+ href="#sec-isintailposition">14.6.1</a>)</li>
+ <li>Return EvaluateCall(<i>tagRef</i>, <i>TemplateLiteral</i>, <i>tailCall</i>).</li>
+ </ol>
+ </section>
+ </section>
+ </section>
+
+ <section id="sec-postfix-expressions">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.4"><a href="#sec-postfix-expressions" title="link to this section">12.4</a></span>
+ Postfix Expressions</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">PostfixExpression</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">LeftHandSideExpression</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="nt">LeftHandSideExpression</span><sub>[?Yield]</sub> <span class="grhsannot">[no <span class="nt">LineTerminator</span> here]</span> <code class="t">++</code></div>
+ <div class="rhs"><span class="nt">LeftHandSideExpression</span><sub>[?Yield]</sub> <span class="grhsannot">[no <span class="nt">LineTerminator</span> here]</span> <code class="t">--</code></div>
+ </div>
+ </div>
+
+ <section id="sec-postfix-expressions-static-semantics-early-errors">
+ <h1><span class="secnum" id="sec-12.4.1"><a href="#sec-postfix-expressions-static-semantics-early-errors"
+ title="link to this section">12.4.1</a></span> Static Semantics: Early Errors</h1>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">PostfixExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">LeftHandSideExpression</span> <code class="t">++</code></div>
+ <div class="rhs"><span class="nt">LeftHandSideExpression</span> <code class="t">--</code></div>
+ </div>
+
+ <ul>
+ <li>
+ <p>It is an early <a href="#sec-reference-specification-type">Reference</a> Error if <span style="font-family: Times New
+ Roman">IsValidSimpleAssignmentTarget</span> of <span class="nt">LeftHandSideExpression</span> is <span
+ class="value">false</span>.</p>
+ </li>
+ </ul>
+ </section>
+
+ <section id="sec-postfix-expressions-static-semantics-isfunctiondefinition">
+ <h1><span class="secnum" id="sec-12.4.2"><a href="#sec-postfix-expressions-static-semantics-isfunctiondefinition"
+ title="link to this section">12.4.2</a></span> Static Semantics: IsFunctionDefinition</h1>
+
+ <p>See also: <a href="#sec-semantics-static-semantics-isfunctiondefinition">12.2.0.2</a>, <a
+ href="#sec-grouping-operator-static-semantics-isfunctiondefinition">12.2.10.2</a>, <a
+ href="#sec-static-semantics-static-semantics-isfunctiondefinition">12.3.1.2</a>, <a
+ href="#sec-unary-operators-static-semantics-isfunctiondefinition">12.5.2</a>, <a
+ href="#sec-multiplicative-operators-static-semantics-isfunctiondefinition">12.6.1</a>, <a
+ href="#sec-additive-operators-static-semantics-isfunctiondefinition">12.7.1</a>, <a
+ href="#sec-bitwise-shift-operators-static-semantics-isfunctiondefinition">12.8.1</a>, <a
+ href="#sec-relational-operators-static-semantics-isfunctiondefinition">12.9.1</a>, <a
+ href="#sec-equality-operators-static-semantics-isfunctiondefinition">12.10.1</a>, <a
+ href="#sec-binary-bitwise-operators-static-semantics-isfunctiondefinition">12.11.1</a>, <a
+ href="#sec-binary-logical-operators-static-semantics-isfunctiondefinition">12.12.1</a>, <a
+ href="#sec-conditional-operator-static-semantics-isfunctiondefinition">12.13.1</a>, <a
+ href="#sec-assignment-operators-static-semantics-isfunctiondefinition">12.14.2</a>, <a
+ href="#sec-comma-operator-static-semantics-isfunctiondefinition">12.15.1</a>, <a
+ href="#sec-function-definitions-static-semantics-isfunctiondefinition">14.1.11</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-isfunctiondefinition">14.4.8</a>, <a
+ href="#sec-class-definitions-static-semantics-isfunctiondefinition">14.5.8</a></p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">PostfixExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">LeftHandSideExpression</span> <code class="t">++</code></div>
+ <div class="rhs"><span class="nt">LeftHandSideExpression</span> <code class="t">--</code></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-postfix-expressions-static-semantics-isvalidsimpleassignmenttarget">
+ <h1><span class="secnum" id="sec-12.4.3"><a href="#sec-postfix-expressions-static-semantics-isvalidsimpleassignmenttarget"
+ title="link to this section">12.4.3</a></span> Static Semantics: IsValidSimpleAssignmentTarget</h1>
+
+ <p>See also: <a href="#sec-semantics-static-semantics-isidentifierref">12.2.0.3</a>, <a
+ href="#sec-grouping-operator-static-semantics-isvalidsimpleassignmenttarget">12.2.10.3</a>, <a
+ href="#sec-static-semantics-static-semantics-isidentifierref">12.3.1.3</a>, <a
+ href="#sec-unary-operators-static-semantics-isvalidsimpleassignmenttarget">12.5.3</a>, <a
+ href="#sec-multiplicative-operators-static-semantics-isvalidsimpleassignmenttarget">12.6.2</a>, <a
+ href="#sec-additive-operators-static-semantics-isvalidsimpleassignmenttarget">12.7.2</a>, <a
+ href="#sec-bitwise-shift-operators-static-semantics-isvalidsimpleassignmenttarget">12.8.2</a>, <a
+ href="#sec-relational-operators-static-semantics-isvalidsimpleassignmenttarget">12.9.2</a>, <a
+ href="#sec-equality-operators-static-semantics-isvalidsimpleassignmenttarget">12.10.2</a>, <a
+ href="#sec-binary-bitwise-operators-static-semantics-isvalidsimpleassignmenttarget">12.11.2</a>, <a
+ href="#sec-binary-logical-operators-static-semantics-isvalidsimpleassignmenttarget">12.12.2</a>, <a
+ href="#sec-conditional-operator-static-semantics-isvalidsimpleassignmenttarget">12.13.2</a>, <a
+ href="#sec-assignment-operators-static-semantics-isvalidsimpleassignmenttarget">12.14.3</a>, <a
+ href="#sec-comma-operator-static-semantics-isvalidsimpleassignmenttarget">12.15.2</a>.</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">PostfixExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">LeftHandSideExpression</span> <code class="t">++</code></div>
+ <div class="rhs"><span class="nt">LeftHandSideExpression</span> <code class="t">--</code></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-postfix-increment-operator">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.4.4"><a href="#sec-postfix-increment-operator"
+ title="link to this section">12.4.4</a></span> Postfix Increment Operator</h1>
+ </div>
+
+ <section id="sec-postfix-increment-operator-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-12.4.4.1"><a href="#sec-postfix-increment-operator-runtime-semantics-evaluation"
+ title="link to this section">12.4.4.1</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">PostfixExpression</span> <span class="geq">:</span> <span class="nt">LeftHandSideExpression</span> <code class="t">++</code></div>
+ <ol class="proc">
+ <li>Let <i>lhs</i> be the result of evaluating <i>LeftHandSideExpression</i>.</li>
+ <li>Let <i>oldValue</i> be <a href="#sec-tonumber">ToNumber</a>(<a href="#sec-getvalue">GetValue</a>(<i>lhs</i>)).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>oldValue</i>).</li>
+ <li>Let <i>newValue</i> be the result of adding the value <code>1</code> to <i>oldValue</i>, using the same rules as for
+ the <code>+</code> operator (<a href="#sec-applying-the-additive-operators-to-numbers">see 12.7.5</a>).</li>
+ <li>Let <i>status</i> be <a href="#sec-putvalue">PutValue</a>(<i>lhs</i>, <i>newValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Return <i>oldValue</i>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-postfix-decrement-operator">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.4.5"><a href="#sec-postfix-decrement-operator"
+ title="link to this section">12.4.5</a></span> Postfix Decrement Operator</h1>
+ </div>
+
+ <section id="sec-postfix-decrement-operator-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-12.4.5.1"><a href="#sec-postfix-decrement-operator-runtime-semantics-evaluation"
+ title="link to this section">12.4.5.1</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">PostfixExpression</span> <span class="geq">:</span> <span class="nt">LeftHandSideExpression</span> <code class="t">--</code></div>
+ <ol class="proc">
+ <li>Let <i>lhs</i> be the result of evaluating <i>LeftHandSideExpression</i>.</li>
+ <li>Let <i>oldValue</i> be <a href="#sec-tonumber">ToNumber</a>(<a href="#sec-getvalue">GetValue</a>(<i>lhs</i>)).</li>
+ <li>Let <i>newValue</i> be the result of subtracting the value <code>1</code> from <i>oldValue</i>, using the same rules
+ as for the <code>-</code> operator (<a href="#sec-applying-the-additive-operators-to-numbers">12.7.5</a>).</li>
+ <li>Let <i>status</i> be <a href="#sec-putvalue">PutValue</a>(<i>lhs</i>, <i>newValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Return <i>oldValue</i>.</li>
+ </ol>
+ </section>
+ </section>
+ </section>
+
+ <section id="sec-unary-operators">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.5"><a href="#sec-unary-operators" title="link to this section">12.5</a></span> Unary
+ Operators</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">UnaryExpression</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">PostfixExpression</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><code class="t">delete</code> <span class="nt">UnaryExpression</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><code class="t">void</code> <span class="nt">UnaryExpression</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><code class="t">typeof</code> <span class="nt">UnaryExpression</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><code class="t">++</code> <span class="nt">UnaryExpression</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><code class="t">--</code> <span class="nt">UnaryExpression</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><code class="t">+</code> <span class="nt">UnaryExpression</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><code class="t">-</code> <span class="nt">UnaryExpression</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><code class="t">~</code> <span class="nt">UnaryExpression</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><code class="t">!</code> <span class="nt">UnaryExpression</span><sub>[?Yield]</sub></div>
+ </div>
+ </div>
+
+ <section id="sec-unary-operators-static-semantics-early-errors">
+ <h1><span class="secnum" id="sec-12.5.1"><a href="#sec-unary-operators-static-semantics-early-errors"
+ title="link to this section">12.5.1</a></span> Static Semantics: Early Errors</h1>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">UnaryExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">++</code> <span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><code class="t">--</code> <span class="nt">UnaryExpression</span></div>
+ </div>
+
+ <ul>
+ <li>
+ <p>It is an early <a href="#sec-reference-specification-type">Reference</a> Error if <span style="font-family: Times New
+ Roman">IsValidSimpleAssignmentTarget</span> of <span class="nt">UnaryExpression</span> is <span
+ class="value">false</span>.</p>
+ </li>
+ </ul>
+ </section>
+
+ <section id="sec-unary-operators-static-semantics-isfunctiondefinition">
+ <h1><span class="secnum" id="sec-12.5.2"><a href="#sec-unary-operators-static-semantics-isfunctiondefinition"
+ title="link to this section">12.5.2</a></span> Static Semantics: IsFunctionDefinition</h1>
+
+ <p>See also: <a href="#sec-semantics-static-semantics-isfunctiondefinition">12.2.0.2</a>, <a
+ href="#sec-grouping-operator-static-semantics-isfunctiondefinition">12.2.10.2</a>, <a
+ href="#sec-static-semantics-static-semantics-isfunctiondefinition">12.3.1.2</a>, <a
+ href="#sec-postfix-expressions-static-semantics-isfunctiondefinition">12.4.2</a>, <a
+ href="#sec-multiplicative-operators-static-semantics-isfunctiondefinition">12.6.1</a>, <a
+ href="#sec-additive-operators-static-semantics-isfunctiondefinition">12.7.1</a>, <a
+ href="#sec-bitwise-shift-operators-static-semantics-isfunctiondefinition">12.8.1</a>, <a
+ href="#sec-relational-operators-static-semantics-isfunctiondefinition">12.9.1</a>, <a
+ href="#sec-equality-operators-static-semantics-isfunctiondefinition">12.10.1</a>, <a
+ href="#sec-binary-bitwise-operators-static-semantics-isfunctiondefinition">12.11.1</a>, <a
+ href="#sec-binary-logical-operators-static-semantics-isfunctiondefinition">12.12.1</a>, <a
+ href="#sec-conditional-operator-static-semantics-isfunctiondefinition">12.13.1</a>, <a
+ href="#sec-assignment-operators-static-semantics-isfunctiondefinition">12.14.2</a>, <a
+ href="#sec-comma-operator-static-semantics-isfunctiondefinition">12.15.1</a>, <a
+ href="#sec-function-definitions-static-semantics-isfunctiondefinition">14.1.11</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-isfunctiondefinition">14.4.8</a>, <a
+ href="#sec-class-definitions-static-semantics-isfunctiondefinition">14.5.8</a>.</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">UnaryExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">delete</code> <span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><code class="t">void</code> <span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><code class="t">typeof</code> <span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><code class="t">++</code> <span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><code class="t">--</code> <span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><code class="t">+</code> <span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><code class="t">-</code> <span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><code class="t">~</code> <span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><code class="t">!</code> <span class="nt">UnaryExpression</span></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-unary-operators-static-semantics-isvalidsimpleassignmenttarget">
+ <h1><span class="secnum" id="sec-12.5.3"><a href="#sec-unary-operators-static-semantics-isvalidsimpleassignmenttarget"
+ title="link to this section">12.5.3</a></span> Static Semantics: IsValidSimpleAssignmentTarget</h1>
+
+ <p>See also: <a href="#sec-semantics-static-semantics-isidentifierref">12.2.0.3</a>, <a
+ href="#sec-grouping-operator-static-semantics-isvalidsimpleassignmenttarget">12.2.10.3</a>, <a
+ href="#sec-static-semantics-static-semantics-isidentifierref">12.3.1.3</a>, <a
+ href="#sec-postfix-expressions-static-semantics-isvalidsimpleassignmenttarget">12.4.3</a>, <a
+ href="#sec-multiplicative-operators-static-semantics-isvalidsimpleassignmenttarget">12.6.2</a>, <a
+ href="#sec-additive-operators-static-semantics-isvalidsimpleassignmenttarget">12.7.2</a>, <a
+ href="#sec-bitwise-shift-operators-static-semantics-isvalidsimpleassignmenttarget">12.8.2</a>, <a
+ href="#sec-relational-operators-static-semantics-isvalidsimpleassignmenttarget">12.9.2</a>, <a
+ href="#sec-equality-operators-static-semantics-isvalidsimpleassignmenttarget">12.10.2</a>, <a
+ href="#sec-binary-bitwise-operators-static-semantics-isvalidsimpleassignmenttarget">12.11.2</a>, <a
+ href="#sec-binary-logical-operators-static-semantics-isvalidsimpleassignmenttarget">12.12.2</a>, <a
+ href="#sec-conditional-operator-static-semantics-isvalidsimpleassignmenttarget">12.13.2</a>, <a
+ href="#sec-assignment-operators-static-semantics-isvalidsimpleassignmenttarget">12.14.3</a>, <a
+ href="#sec-comma-operator-static-semantics-isvalidsimpleassignmenttarget">12.15.2</a>.</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">UnaryExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">delete</code> <span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><code class="t">void</code> <span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><code class="t">typeof</code> <span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><code class="t">++</code> <span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><code class="t">--</code> <span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><code class="t">+</code> <span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><code class="t">-</code> <span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><code class="t">~</code> <span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><code class="t">!</code> <span class="nt">UnaryExpression</span></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-delete-operator">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.5.4"><a href="#sec-delete-operator" title="link to this section">12.5.4</a></span> The
+ <code>delete</code> Operator</h1>
+ </div>
+
+ <section id="sec-delete-operator-static-semantics-early-errors">
+ <h1><span class="secnum" id="sec-12.5.4.1"><a href="#sec-delete-operator-static-semantics-early-errors"
+ title="link to this section">12.5.4.1</a></span> Static Semantics: Early Errors</h1>
+ <div class="gp prod"><span class="nt">UnaryExpression</span> <span class="geq">:</span> <code class="t">delete</code> <span class="nt">UnaryExpression</span></div>
+ <ul>
+ <li>
+ <p>It is a Syntax Error if the <span class="nt">UnaryExpression</span> is contained in <a
+ href="#sec-strict-mode-code">strict code</a> and the derived <span class="nt">UnaryExpression</span> is <span
+ class="prod"><span class="nt">PrimaryExpression</span> <span class="geq">:</span></span>
+ <var>IdentifierReference.</var></p>
+ </li>
+
+ <li>
+ <p>It is a Syntax Error if the derived <span class="nt">UnaryExpression</span> is<br> <span style="font-family:
+ Times New Roman"><i>PrimaryExpression : CoverParenthesizedExpressionAndArrowParameterList<br></i></span>and derives a
+ production that, if used in place of <var>UnaryExpression,</var> would produce a Syntax Error according to these
+ rules. This rule is recursively applied.</p>
+ </li>
+ </ul>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The last rule means that expressions such as<br> <code>delete
+ (((foo)))</code><br>produce early errors because of recursive application of the first rule.</p>
+ </div>
+ </section>
+
+ <section id="sec-delete-operator-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-12.5.4.2"><a href="#sec-delete-operator-runtime-semantics-evaluation"
+ title="link to this section">12.5.4.2</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">UnaryExpression</span> <span class="geq">:</span> <code class="t">delete</code> <span class="nt">UnaryExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>ref</i> be the result of evaluating <i>UnaryExpression</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>ref</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>ref</i>) is not <a
+ href="#sec-reference-specification-type">Reference</a>, return <b>true</b>.</li>
+ <li>If <a href="#sec-reference-specification-type">IsUnresolvableReference</a>(<i>ref</i>) is <b>true</b>, then,
+ <ol class="block">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a
+ href="#sec-reference-specification-type">IsStrictReference</a>(<i>ref</i>) is <b>false</b>.</li>
+ <li>Return <b>true</b>.</li>
+ </ol>
+ </li>
+ <li>If <a href="#sec-reference-specification-type">IsPropertyReference</a>(<i>ref</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>If <a href="#sec-reference-specification-type">IsSuperReference</a>(<i>ref</i>), then throw a
+ <b>ReferenceError</b> exception.</li>
+ <li>Let <i>deleteStatus</i> be the result of calling the [[Delete]] internal method on <a
+ href="#sec-toobject">ToObject</a>(<a href="#sec-reference-specification-type">GetBase</a>(<i>ref)</i>),
+ providing <a href="#sec-reference-specification-type">GetReferencedName</a>(<i>ref</i>) as the argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>deleteStatus</i>).</li>
+ <li>If <i>deleteStatus</i> is <b>false</b> and <a
+ href="#sec-reference-specification-type">IsStrictReference</a>(<i>ref</i>) is <b>true</b>, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>Return <i>deleteStatus</i>.</li>
+ </ol>
+ </li>
+ <li>Else <i>ref</i> is a <a href="#sec-reference-specification-type">Reference</a> to an <a
+ href="#sec-environment-records">Environment Record</a> binding,
+ <ol class="block">
+ <li>Let <i>bindings</i> be <a href="#sec-reference-specification-type">GetBase</a>(<i>ref</i>).</li>
+ <li>Return the result of calling the DeleteBinding concrete method of <i>bindings</i>, providing <a
+ href="#sec-reference-specification-type">GetReferencedName</a>(<i>ref</i>) as the argument.</li>
+ </ol>
+ </li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> When a <code>delete</code> operator occurs within <a href="#sec-strict-mode-code">strict
+ mode code</a>, a <b>SyntaxError</b> exception is thrown if its <i>UnaryExpression</i> is a direct reference to a
+ variable, function argument, or function name. In addition, if a <code>delete</code> operator occurs within <a
+ href="#sec-strict-mode-code">strict mode code</a> and the property to be deleted has the attribute { [[Configurable]]:
+ <b>false</b> }, a <b>TypeError</b> exception is thrown.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-void-operator">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.5.5"><a href="#sec-void-operator" title="link to this section">12.5.5</a></span> The
+ <code>void</code> Operator</h1>
+ </div>
+
+ <section id="sec-void-operator-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-12.5.5.1"><a href="#sec-void-operator-runtime-semantics-evaluation"
+ title="link to this section">12.5.5.1</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">UnaryExpression</span> <span class="geq">:</span> <code class="t">void</code> <span class="nt">UnaryExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>expr</i> be the result of evaluating <i>UnaryExpression</i>.</li>
+ <li>Let <i>status</i> be <a href="#sec-getvalue">GetValue</a>(<i>expr</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Return <b>undefined</b>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> <a href="#sec-getvalue">GetValue</a> must be called even though its value is not used
+ because it may have observable side-effects.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-typeof-operator">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.5.6"><a href="#sec-typeof-operator" title="link to this section">12.5.6</a></span> The
+ <code>typeof</code> Operator</h1>
+ </div>
+
+ <section id="sec-typeof-operator-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-12.5.6.1"><a href="#sec-typeof-operator-runtime-semantics-evaluation"
+ title="link to this section">12.5.6.1</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">UnaryExpression</span> <span class="geq">:</span> <code class="t">typeof</code> <span class="nt">UnaryExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>val</i> be the result of evaluating <i>UnaryExpression</i>.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>val</i>) is <a
+ href="#sec-reference-specification-type">Reference</a>, then
+ <ol class="block">
+ <li>If <a href="#sec-reference-specification-type">IsUnresolvableReference</a>(<i>val</i>) is <b>true</b>, return
+ <code>"undefined"</code>.</li>
+ <li>Let <i>val</i> be <a href="#sec-getvalue">GetValue</a>(<i>val</i>).</li>
+ </ol>
+ </li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>val</i>).</li>
+ <li>Return a String according to <a href="#table-33">Table 33</a>.</li>
+ </ol>
+
+ <figure>
+ <figcaption><span id="table-33">Table 33</span> — typeof Operator Results</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-top: 2px solid #000000"><b>Type of</b> <span style="font-family: Times New Roman">val</span></th>
+ <th style="border-bottom: 1px solid #000000; border-right: 1px solid #000000; border-top: 2px solid #000000">Result</th>
+ </tr>
+ <tr>
+ <td>Undefined</td>
+ <td><code>"undefined"</code></td>
+ </tr>
+ <tr>
+ <td>Null</td>
+ <td><code>"object"</code></td>
+ </tr>
+ <tr>
+ <td>Boolean</td>
+ <td><code>"boolean"</code></td>
+ </tr>
+ <tr>
+ <td>Number</td>
+ <td><code>"number"</code></td>
+ </tr>
+ <tr>
+ <td>String</td>
+ <td><code>"string"</code></td>
+ </tr>
+ <tr>
+ <td>Symbol</td>
+ <td><code>"symbol"</code></td>
+ </tr>
+ <tr>
+ <td>Object (ordinary and does not implement [[Call]])</td>
+ <td><code>"object"</code></td>
+ </tr>
+ <tr>
+ <td>Object (standard exotic and does not implement [[Call]])</td>
+ <td><code>"object"</code></td>
+ </tr>
+ <tr>
+ <td>Object (implements [[Call]])</td>
+ <td><code>"function"</code></td>
+ </tr>
+ <tr>
+ <td>Object (non-standard exotic and does not implement [[Call]])</td>
+ <td>Implementation-defined. Must not be <code>"undefined"</code>, <code>"boolean"</code>, <code>"number</code>", <code>"symbol"</code>, or <code>"string".</code></td>
+ </tr>
+ </table>
+ </figure>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Implementations are discouraged from defining new <code>typeof</code> result values for
+ non-standard exotic objects. If possible <code>"object"</code>should be used for such objects.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-prefix-increment-operator">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.5.7"><a href="#sec-prefix-increment-operator"
+ title="link to this section">12.5.7</a></span> Prefix Increment Operator</h1>
+ </div>
+
+ <section id="sec-prefix-increment-operator-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-12.5.7.1"><a href="#sec-prefix-increment-operator-runtime-semantics-evaluation"
+ title="link to this section">12.5.7.1</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">UnaryExpression</span> <span class="geq">:</span> <code class="t">++</code> <span class="nt">UnaryExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>expr</i> be the result of evaluating <i>UnaryExpression</i>.</li>
+ <li>Let <i>oldValue</i> be <a href="#sec-tonumber">ToNumber</a>(<a href="#sec-getvalue">GetValue</a>(<i>expr</i>)).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>oldValue</i>).</li>
+ <li>Let <i>newValue</i> be the result of adding the value <code>1</code> to <i>oldValue</i>, using the same rules as for
+ the <code>+</code> operator (<a href="#sec-applying-the-additive-operators-to-numbers">see 12.7.5</a>).</li>
+ <li>Let <i>status</i> be <a href="#sec-putvalue">PutValue</a>(<i>expr</i>, <i>newValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Return <i>newValue</i>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-prefix-decrement-operator">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.5.8"><a href="#sec-prefix-decrement-operator"
+ title="link to this section">12.5.8</a></span> Prefix Decrement Operator</h1>
+ </div>
+
+ <section id="sec-prefix-decrement-operator-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-12.5.8.1"><a href="#sec-prefix-decrement-operator-runtime-semantics-evaluation"
+ title="link to this section">12.5.8.1</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">UnaryExpression</span> <span class="geq">:</span> <code class="t">--</code> <span class="nt">UnaryExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>expr</i> be the result of evaluating <i>UnaryExpression</i>.</li>
+ <li>Let <i>oldValue</i> be <a href="#sec-tonumber">ToNumber</a>(<a href="#sec-getvalue">GetValue</a>(<i>expr</i>)).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>oldValue</i>).</li>
+ <li>Let <i>newValue</i> be the result of subtracting the value <code>1</code> from <i>oldValue</i>, using the same
+ rules as for the <code>-</code> operator (<a href="#sec-applying-the-additive-operators-to-numbers">see
+ 12.7.5</a>).</li>
+ <li>Let <i>status</i> be <a href="#sec-putvalue">PutValue</a>(<i>expr</i>, <i>newValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Return <i>newValue</i>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-unary-plus-operator">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.5.9"><a href="#sec-unary-plus-operator" title="link to this section">12.5.9</a></span>
+ Unary <code>+</code> Operator</h1>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The unary + operator converts its operand to Number type.</p>
+ </div>
+ </div>
+
+ <section id="sec-unary-plus-operator-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-12.5.9.1"><a href="#sec-unary-plus-operator-runtime-semantics-evaluation"
+ title="link to this section">12.5.9.1</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">UnaryExpression</span> <span class="geq">:</span> <code class="t">+</code> <span class="nt">UnaryExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>expr</i> be the result of evaluating <i>UnaryExpression</i>.</li>
+ <li>Return <a href="#sec-tonumber">ToNumber</a>(<a href="#sec-getvalue">GetValue</a>(<i>expr</i>)).</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-unary-minus-operator">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.5.10"><a href="#sec-unary-minus-operator"
+ title="link to this section">12.5.10</a></span> Unary <code>-</code> Operator</h1>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The unary <code>-</code> operator converts its operand to Number type and then negates
+ it. Negating <b>+0</b> produces <b>−0</b>, and negating <b>−0</b> produces <b>+0</b>.</p>
+ </div>
+ </div>
+
+ <section id="sec-unary-minus-operator-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-12.5.10.1"><a href="#sec-unary-minus-operator-runtime-semantics-evaluation"
+ title="link to this section">12.5.10.1</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">UnaryExpression</span> <span class="geq">:</span> <code class="t">-</code> <span class="nt">UnaryExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>expr</i> be the result of evaluating <i>UnaryExpression</i>.</li>
+ <li>Let <i>oldValue</i> be <a href="#sec-tonumber">ToNumber</a>(<a href="#sec-getvalue">GetValue</a>(<i>expr</i>)).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>oldValue</i>).</li>
+ <li>If <i>oldValue</i> is <b>NaN</b>, return <b>NaN</b>.</li>
+ <li>Return the result of negating <i>oldValue</i>; that is, compute a Number with the same magnitude but opposite
+ sign.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-bitwise-not-operator">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.5.11"><a href="#sec-bitwise-not-operator"
+ title="link to this section">12.5.11</a></span> Bitwise NOT Operator ( <code>~</code> )</h1>
+ </div>
+
+ <section id="sec-bitwise-not-operator-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-12.5.11.1"><a href="#sec-bitwise-not-operator-runtime-semantics-evaluation"
+ title="link to this section">12.5.11.1</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">UnaryExpression</span> <span class="geq">:</span> <code class="t">~</code> <span class="nt">UnaryExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>expr</i> be the result of evaluating <i>UnaryExpression</i>.</li>
+ <li>Let <i>oldValue</i> be <a href="#sec-toint32">ToInt32</a>(<a href="#sec-getvalue">GetValue</a>(<i>expr</i>)).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>oldValue</i>).</li>
+ <li>Return the result of applying bitwise complement to <i>oldValue</i>. The result is a signed 32-bit integer.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-logical-not-operator">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.5.12"><a href="#sec-logical-not-operator"
+ title="link to this section">12.5.12</a></span> Logical NOT Operator ( <code>!</code> )</h1>
+ </div>
+
+ <section id="sec-logical-not-operator-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-12.5.12.1"><a href="#sec-logical-not-operator-runtime-semantics-evaluation"
+ title="link to this section">12.5.12.1</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">UnaryExpression</span> <span class="geq">:</span> <code class="t">!</code> <span class="nt">UnaryExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>expr</i> be the result of evaluating <i>UnaryExpression</i>.</li>
+ <li>Let <i>oldValue</i> be <a href="#sec-toboolean">ToBoolean</a>(<a
+ href="#sec-getvalue">GetValue</a>(<i>expr</i>)).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>oldValue</i>).</li>
+ <li>If <i>oldValue</i> is <b>true</b>, return <b>false</b>.</li>
+ <li>Return <b>true</b>.</li>
+ </ol>
+ </section>
+ </section>
+ </section>
+
+ <section id="sec-multiplicative-operators">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.6"><a href="#sec-multiplicative-operators" title="link to this section">12.6</a></span>
+ Multiplicative Operators</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">MultiplicativeExpression</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">UnaryExpression</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="nt">MultiplicativeExpression</span><sub>[?Yield]</sub> <code class="t">*</code> <span class="nt">UnaryExpression</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="nt">MultiplicativeExpression</span><sub>[?Yield]</sub> <code class="t">/</code> <span class="nt">UnaryExpression</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="nt">MultiplicativeExpression</span><sub>[?Yield]</sub> <code class="t">%</code> <span class="nt">UnaryExpression</span><sub>[?Yield]</sub></div>
+ </div>
+ </div>
+
+ <section id="sec-multiplicative-operators-static-semantics-isfunctiondefinition">
+ <h1><span class="secnum" id="sec-12.6.1"><a href="#sec-multiplicative-operators-static-semantics-isfunctiondefinition"
+ title="link to this section">12.6.1</a></span> Static Semantics: IsFunctionDefinition</h1>
+
+ <p>See also: <a href="#sec-semantics-static-semantics-isfunctiondefinition">12.2.0.2</a>, <a
+ href="#sec-grouping-operator-static-semantics-isfunctiondefinition">12.2.10.2</a>, <a
+ href="#sec-static-semantics-static-semantics-isfunctiondefinition">12.3.1.2</a>, <a
+ href="#sec-postfix-expressions-static-semantics-isfunctiondefinition">12.4.2</a>, <a
+ href="#sec-unary-operators-static-semantics-isfunctiondefinition">12.5.2</a>, <a
+ href="#sec-additive-operators-static-semantics-isfunctiondefinition">12.7.1</a>, <a
+ href="#sec-bitwise-shift-operators-static-semantics-isfunctiondefinition">12.8.1</a>, <a
+ href="#sec-relational-operators-static-semantics-isfunctiondefinition">12.9.1</a>, <a
+ href="#sec-equality-operators-static-semantics-isfunctiondefinition">12.10.1</a>, <a
+ href="#sec-binary-bitwise-operators-static-semantics-isfunctiondefinition">12.11.1</a>, <a
+ href="#sec-binary-logical-operators-static-semantics-isfunctiondefinition">12.12.1</a>, <a
+ href="#sec-conditional-operator-static-semantics-isfunctiondefinition">12.13.1</a>, <a
+ href="#sec-assignment-operators-static-semantics-isfunctiondefinition">12.14.2</a>, <a
+ href="#sec-comma-operator-static-semantics-isfunctiondefinition">12.15.1</a>, <a
+ href="#sec-function-definitions-static-semantics-isfunctiondefinition">14.1.11</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-isfunctiondefinition">14.4.8</a>, <a
+ href="#sec-class-definitions-static-semantics-isfunctiondefinition">14.5.8</a>.</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">MultiplicativeExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">MultiplicativeExpression</span> <code class="t">*</code> <span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><span class="nt">MultiplicativeExpression</span> <code class="t">/</code> <span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><span class="nt">MultiplicativeExpression</span> <code class="t">%</code> <span class="nt">UnaryExpression</span></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-multiplicative-operators-static-semantics-isvalidsimpleassignmenttarget">
+ <h1><span class="secnum" id="sec-12.6.2"><a
+ href="#sec-multiplicative-operators-static-semantics-isvalidsimpleassignmenttarget"
+ title="link to this section">12.6.2</a></span> Static Semantics: IsValidSimpleAssignmentTarget</h1>
+
+ <p>See also: <a href="#sec-semantics-static-semantics-isidentifierref">12.2.0.3</a>, <a
+ href="#sec-grouping-operator-static-semantics-isvalidsimpleassignmenttarget">12.2.10.3</a>, <a
+ href="#sec-static-semantics-static-semantics-isidentifierref">12.3.1.3</a>, <a
+ href="#sec-postfix-expressions-static-semantics-isvalidsimpleassignmenttarget">12.4.3</a>, <a
+ href="#sec-unary-operators-static-semantics-isvalidsimpleassignmenttarget">12.5.3</a>, <a
+ href="#sec-additive-operators-static-semantics-isvalidsimpleassignmenttarget">12.7.2</a>, <a
+ href="#sec-bitwise-shift-operators-static-semantics-isvalidsimpleassignmenttarget">12.8.2</a>, <a
+ href="#sec-relational-operators-static-semantics-isvalidsimpleassignmenttarget">12.9.2</a>, <a
+ href="#sec-equality-operators-static-semantics-isvalidsimpleassignmenttarget">12.10.2</a>, <a
+ href="#sec-binary-bitwise-operators-static-semantics-isvalidsimpleassignmenttarget">12.11.2</a>, <a
+ href="#sec-binary-logical-operators-static-semantics-isvalidsimpleassignmenttarget">12.12.2</a>, <a
+ href="#sec-conditional-operator-static-semantics-isvalidsimpleassignmenttarget">12.13.2</a>, <a
+ href="#sec-assignment-operators-static-semantics-isvalidsimpleassignmenttarget">12.14.3</a>, <a
+ href="#sec-comma-operator-static-semantics-isvalidsimpleassignmenttarget">12.15.2</a>.</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">MultiplicativeExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">MultiplicativeExpression</span> <code class="t">*</code> <span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><span class="nt">MultiplicativeExpression</span> <code class="t">/</code> <span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><span class="nt">MultiplicativeExpression</span> <code class="t">%</code> <span class="nt">UnaryExpression</span></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-multiplicative-operators-runtime-semantics-evaluation">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.6.3"><a href="#sec-multiplicative-operators-runtime-semantics-evaluation"
+ title="link to this section">12.6.3</a></span> Runtime Semantics: Evaluation</h1>
+
+ <p>The production <span class="prod"><span class="nt">MultiplicativeExpression</span> <span class="geq">:</span> <span
+ class="nt">MultiplicativeExpression</span> <code class="t">@</code> <span class="nt">UnaryExpression</span></span> , where
+ @ stands for one of the operators in the above definitions, is evaluated as follows:</p>
+
+ <ol class="proc">
+ <li>Let <i>left</i> be the result of evaluating <i>MultiplicativeExpression</i>.</li>
+ <li>Let <i>leftValue</i> be <a href="#sec-getvalue">GetValue</a>(<i>left</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>leftValue</i>).</li>
+ <li>Let <i>right</i> be the result of evaluating <i>UnaryExpression</i>.</li>
+ <li>Let <i>rightValue</i> be <a href="#sec-getvalue">GetValue</a>(<i>right</i>).</li>
+ <li>Let <i>lnum</i> be <a href="#sec-tonumber">ToNumber</a>(<i>leftValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>lnum</i>).</li>
+ <li>Let <i>rnum</i> be <a href="#sec-tonumber">ToNumber</a>(<i>rightValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>rnum</i>).</li>
+ <li>Return the result of applying the specified operation (*, /, or %) to <i>lnum</i> and <i>rnum</i>. See the Notes
+ below <a href="#sec-applying-the-mul-operator">12.6.3.1</a>, <a href="#sec-applying-the-div-operator">12.6.3.2</a>,
+ <a href="#sec-applying-the-mod-operator">12.6.3.3</a>.</li>
+ </ol>
+ </div>
+
+ <section id="sec-applying-the-mul-operator">
+ <h1><span class="secnum" id="sec-12.6.3.1"><a href="#sec-applying-the-mul-operator"
+ title="link to this section">12.6.3.1</a></span> Applying the <code>*</code> Operator</h1>
+
+ <p>The <code>*</code> operator performs multiplication, producing the product of its operands. Multiplication is
+ commutative. Multiplication is not always associative in ECMAScript, because of finite precision.</p>
+
+ <p>The result of a floating-point multiplication is governed by the rules of IEEE 754 binary double-precision
+ arithmetic:</p>
+
+ <ul>
+ <li>
+ <p>If either operand is <b>NaN</b>, the result is <b>NaN</b>.</p>
+ </li>
+
+ <li>
+ <p>The sign of the result is positive if both operands have the same sign, negative if the operands have different
+ signs.</p>
+ </li>
+
+ <li>
+ <p>Multiplication of an infinity by a zero results in <b>NaN</b>.</p>
+ </li>
+
+ <li>
+ <p>Multiplication of an infinity by an infinity results in an infinity. The sign is determined by the rule already
+ stated above.</p>
+ </li>
+
+ <li>
+ <p>Multiplication of an infinity by a finite nonzero value results in a signed infinity. The sign is determined by the
+ rule already stated above.</p>
+ </li>
+
+ <li>
+ <p>In the remaining cases, where neither an infinity nor NaN is involved, the product is computed and rounded to the
+ nearest representable value using IEEE 754 round-to-nearest mode. If the magnitude is too large to represent, the
+ result is then an infinity of appropriate sign. If the magnitude is too small to represent, the result is then a zero
+ of appropriate sign. The ECMAScript language requires support of gradual underflow as defined by IEEE 754.</p>
+ </li>
+ </ul>
+ </section>
+
+ <section id="sec-applying-the-div-operator">
+ <h1><span class="secnum" id="sec-12.6.3.2"><a href="#sec-applying-the-div-operator"
+ title="link to this section">12.6.3.2</a></span> Applying the <code>/</code> Operator</h1>
+
+ <p>The <code>/</code> operator performs division, producing the quotient of its operands. The left operand is the dividend
+ and the right operand is the divisor. ECMAScript does not perform integer division. The operands and result of all
+ division operations are double-precision floating-point numbers. The result of division is determined by the specification
+ of IEEE 754 arithmetic:</p>
+
+ <ul>
+ <li>
+ <p>If either operand is <b>NaN</b>, the result is <b>NaN</b>.</p>
+ </li>
+
+ <li>
+ <p>The sign of the result is positive if both operands have the same sign, negative if the operands have different
+ signs.</p>
+ </li>
+
+ <li>
+ <p>Division of an infinity by an infinity results in <b>NaN</b>.</p>
+ </li>
+
+ <li>
+ <p>Division of an infinity by a zero results in an infinity. The sign is determined by the rule already stated
+ above.</p>
+ </li>
+
+ <li>
+ <p>Division of an infinity by a nonzero finite value results in a signed infinity. The sign is determined by the rule
+ already stated above.</p>
+ </li>
+
+ <li>
+ <p>Division of a finite value by an infinity results in zero. The sign is determined by the rule already stated
+ above.</p>
+ </li>
+
+ <li>
+ <p>Division of a zero by a zero results in <b>NaN</b>; division of zero by any other finite value results in zero,
+ with the sign determined by the rule already stated above.</p>
+ </li>
+
+ <li>
+ <p>Division of a nonzero finite value by a zero results in a signed infinity. The sign is determined by the rule
+ already stated above.</p>
+ </li>
+
+ <li>
+ <p>In the remaining cases, where neither an infinity, nor a zero, nor <b>NaN</b> is involved, the quotient is computed
+ and rounded to the nearest representable value using IEEE 754 round-to-nearest mode. If the magnitude is too large to
+ represent, the operation overflows; the result is then an infinity of appropriate sign. If the magnitude is too small
+ to represent, the operation underflows and the result is a zero of the appropriate sign. The ECMAScript language
+ requires support of gradual underflow as defined by IEEE 754.</p>
+ </li>
+ </ul>
+ </section>
+
+ <section id="sec-applying-the-mod-operator">
+ <h1><span class="secnum" id="sec-12.6.3.3"><a href="#sec-applying-the-mod-operator"
+ title="link to this section">12.6.3.3</a></span> Applying the <code>%</code> Operator</h1>
+
+ <p>The <code>%</code> operator yields the remainder of its operands from an implied division; the left operand is the
+ dividend and the right operand is the divisor.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> In C and C++, the remainder operator accepts only integral operands; in ECMAScript, it
+ also accepts floating-point operands.</p>
+ </div>
+
+ <p>The result of a floating-point remainder operation as computed by the <code>%</code> operator is not the same as the
+ “remainder” operation defined by IEEE 754. The IEEE 754 “remainder” operation computes the
+ remainder from a rounding division, not a truncating division, and so its behaviour is not analogous to that of the usual
+ integer remainder operator. Instead the ECMAScript language defines <code>%</code> on floating-point operations to behave
+ in a manner analogous to that of the Java integer remainder operator; this may be compared with the C library function
+ fmod.</p>
+
+ <p>The result of an ECMAScript floating-point remainder operation is determined by the rules of IEEE arithmetic:</p>
+
+ <ul>
+ <li>
+ <p>If either operand is <b>NaN</b>, the result is <b>NaN</b>.</p>
+ </li>
+
+ <li>
+ <p>The sign of the result equals the sign of the dividend.</p>
+ </li>
+
+ <li>
+ <p>If the dividend is an infinity, or the divisor is a zero, or both, the result is <b>NaN</b>.</p>
+ </li>
+
+ <li>
+ <p>If the dividend is finite and the divisor is an infinity, the result equals the dividend.</p>
+ </li>
+
+ <li>
+ <p>If the dividend is a zero and the divisor is nonzero and finite, the result is the same as the dividend.</p>
+ </li>
+
+ <li>
+ <p>In the remaining cases, where neither an infinity, nor a zero, nor <b>NaN</b> is involved, the floating-point
+ remainder r from a dividend n and a divisor d is defined by the mathematical relation r = n − (d × q)
+ where q is an integer that is negative only if n/d is negative and positive only if n/d is positive, and whose
+ magnitude is as large as possible without exceeding the magnitude of the true mathematical quotient of n and d. r is
+ computed and rounded to the nearest representable value using IEEE 754 round-to-nearest mode.</p>
+ </li>
+ </ul>
+ </section>
+ </section>
+ </section>
+
+ <section id="sec-additive-operators">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.7"><a href="#sec-additive-operators" title="link to this section">12.7</a></span>
+ Additive Operators</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">AdditiveExpression</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">MultiplicativeExpression</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="nt">AdditiveExpression</span><sub>[?Yield]</sub> <code class="t">+</code> <span class="nt">MultiplicativeExpression</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="nt">AdditiveExpression</span><sub>[?Yield]</sub> <code class="t">-</code> <span class="nt">MultiplicativeExpression</span><sub>[?Yield]</sub></div>
+ </div>
+ </div>
+
+ <section id="sec-additive-operators-static-semantics-isfunctiondefinition">
+ <h1><span class="secnum" id="sec-12.7.1"><a href="#sec-additive-operators-static-semantics-isfunctiondefinition"
+ title="link to this section">12.7.1</a></span> Static Semantics: IsFunctionDefinition</h1>
+
+ <p>See also: <a href="#sec-semantics-static-semantics-isfunctiondefinition">12.2.0.2</a>, <a
+ href="#sec-grouping-operator-static-semantics-isfunctiondefinition">12.2.10.2</a>, <a
+ href="#sec-static-semantics-static-semantics-isfunctiondefinition">12.3.1.2</a>, <a
+ href="#sec-postfix-expressions-static-semantics-isfunctiondefinition">12.4.2</a>, <a
+ href="#sec-unary-operators-static-semantics-isfunctiondefinition">12.5.2</a>, <a
+ href="#sec-multiplicative-operators-static-semantics-isfunctiondefinition">12.6.1</a>, <a
+ href="#sec-bitwise-shift-operators-static-semantics-isfunctiondefinition">12.8.1</a>, <a
+ href="#sec-relational-operators-static-semantics-isfunctiondefinition">12.9.1</a>, <a
+ href="#sec-equality-operators-static-semantics-isfunctiondefinition">12.10.1</a>, <a
+ href="#sec-binary-bitwise-operators-static-semantics-isfunctiondefinition">12.11.1</a>, <a
+ href="#sec-binary-logical-operators-static-semantics-isfunctiondefinition">12.12.1</a>, <a
+ href="#sec-conditional-operator-static-semantics-isfunctiondefinition">12.13.1</a>, <a
+ href="#sec-assignment-operators-static-semantics-isfunctiondefinition">12.14.2</a>, <a
+ href="#sec-comma-operator-static-semantics-isfunctiondefinition">12.15.1</a>, <a
+ href="#sec-function-definitions-static-semantics-isfunctiondefinition">14.1.11</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-isfunctiondefinition">14.4.8</a>, <a
+ href="#sec-class-definitions-static-semantics-isfunctiondefinition">14.5.8</a>.</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">AdditiveExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">AdditiveExpression</span> <code class="t">+</code> <span class="nt">MultiplicativeExpression</span></div>
+ <div class="rhs"><span class="nt">AdditiveExpression</span> <code class="t">-</code> <span class="nt">MultiplicativeExpression</span></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-additive-operators-static-semantics-isvalidsimpleassignmenttarget">
+ <h1><span class="secnum" id="sec-12.7.2"><a href="#sec-additive-operators-static-semantics-isvalidsimpleassignmenttarget"
+ title="link to this section">12.7.2</a></span> Static Semantics: IsValidSimpleAssignmentTarget</h1>
+
+ <p>See also: <a href="#sec-semantics-static-semantics-isidentifierref">12.2.0.3</a>, <a
+ href="#sec-grouping-operator-static-semantics-isvalidsimpleassignmenttarget">12.2.10.3</a>, <a
+ href="#sec-static-semantics-static-semantics-isidentifierref">12.3.1.3</a>, <a
+ href="#sec-postfix-expressions-static-semantics-isvalidsimpleassignmenttarget">12.4.3</a>, <a
+ href="#sec-unary-operators-static-semantics-isvalidsimpleassignmenttarget">12.5.3</a>, <a
+ href="#sec-multiplicative-operators-static-semantics-isvalidsimpleassignmenttarget">12.6.2</a>, <a
+ href="#sec-bitwise-shift-operators-static-semantics-isvalidsimpleassignmenttarget">12.8.2</a>, <a
+ href="#sec-relational-operators-static-semantics-isvalidsimpleassignmenttarget">12.9.2</a>, <a
+ href="#sec-equality-operators-static-semantics-isvalidsimpleassignmenttarget">12.10.2</a>, <a
+ href="#sec-binary-bitwise-operators-static-semantics-isvalidsimpleassignmenttarget">12.11.2</a>, <a
+ href="#sec-binary-logical-operators-static-semantics-isvalidsimpleassignmenttarget">12.12.2</a>, <a
+ href="#sec-conditional-operator-static-semantics-isvalidsimpleassignmenttarget">12.13.2</a>, <a
+ href="#sec-assignment-operators-static-semantics-isvalidsimpleassignmenttarget">12.14.3</a>, <a
+ href="#sec-comma-operator-static-semantics-isvalidsimpleassignmenttarget">12.15.2</a>.</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">AdditiveExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">AdditiveExpression</span> <code class="t">+</code> <span class="nt">MultiplicativeExpression</span></div>
+ <div class="rhs"><span class="nt">AdditiveExpression</span> <code class="t">-</code> <span class="nt">MultiplicativeExpression</span></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-addition-operator-plus">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.7.3"><a href="#sec-addition-operator-plus"
+ title="link to this section">12.7.3</a></span> The Addition operator ( <code>+</code> )</h1>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The addition operator either performs string concatenation or numeric addition.</p>
+ </div>
+ </div>
+
+ <section id="sec-addition-operator-plus-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-12.7.3.1"><a href="#sec-addition-operator-plus-runtime-semantics-evaluation"
+ title="link to this section">12.7.3.1</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">AdditiveExpression</span> <span class="geq">:</span> <span class="nt">AdditiveExpression</span> <code class="t">+</code> <span class="nt">MultiplicativeExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>lref</i> be the result of evaluating <i>AdditiveExpression</i>.</li>
+ <li>Let <i>lval</i> be <a href="#sec-getvalue">GetValue</a>(<i>lref</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>lval</i>).</li>
+ <li>Let <i>rref</i> be the result of evaluating <i>MultiplicativeExpression</i>.</li>
+ <li>Let <i>rval</i> be <a href="#sec-getvalue">GetValue</a>(<i>rref</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>rval</i>).</li>
+ <li>Let <i>lprim</i> be <a href="#sec-toprimitive">ToPrimitive</a>(<i>lval</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>lprim</i>).</li>
+ <li>Let <i>rprim</i> be <a href="#sec-toprimitive">ToPrimitive</a>(<i>rval</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>rprim</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>lprim</i>) is String or <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>rprim</i>) is String, then
+ <ol class="block">
+ <li>Return the String that is the result of concatenating <a href="#sec-tostring">ToString</a>(<i>lprim</i>)
+ followed by <a href="#sec-tostring">ToString</a>(<i>rprim</i>)</li>
+ </ol>
+ </li>
+ <li>Return the result of applying the addition operation to <a href="#sec-tonumber">ToNumber</a>(<i>lprim</i>) and <a
+ href="#sec-tonumber">ToNumber</a>(<i>rprim</i>). See the Note below <a
+ href="#sec-applying-the-additive-operators-to-numbers">12.7.5</a>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> No hint is provided in the calls to <a href="#sec-toprimitive">ToPrimitive</a> in
+ steps 7 and 9. All standard objects except Date objects handle the absence of a hint as if the hint Number were given;
+ Date objects handle the absence of a hint as if the hint String were given. Exotic objects may handle the absence of a
+ hint in some other manner.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 2</span> Step 11 differs from step 5 of the Abstract Relational Comparison algorithm (<a
+ href="#sec-isinteger">7.2.8</a>), by using the logical-or operation instead of the logical-and operation.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-subtraction-operator-minus">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.7.4"><a href="#sec-subtraction-operator-minus"
+ title="link to this section">12.7.4</a></span> The Subtraction Operator ( <code>-</code> )</h1>
+ </div>
+
+ <section id="sec-subtraction-operator-minus-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-12.7.4.1"><a href="#sec-subtraction-operator-minus-runtime-semantics-evaluation"
+ title="link to this section">12.7.4.1</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">AdditiveExpression</span> <span class="geq">:</span> <span class="nt">AdditiveExpression</span> <code class="t">-</code> <span class="nt">MultiplicativeExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>lref</i> be the result of evaluating <i>AdditiveExpression</i>.</li>
+ <li>Let <i>lval</i> be <a href="#sec-getvalue">GetValue</a>(<i>lref</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>lval</i>).</li>
+ <li>Let <i>rref</i> be the result of evaluating <i>MultiplicativeExpression</i>.</li>
+ <li>Let <i>rval</i> be <a href="#sec-getvalue">GetValue</a>(<i>rref</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>rval</i>).</li>
+ <li>Let <i>lnum</i> be <a href="#sec-tonumber">ToNumber</a>(<i>lval</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>lnum</i>).</li>
+ <li>Let <i>rnum</i> be <a href="#sec-tonumber">ToNumber</a>(<i>rval</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>rnum</i>).</li>
+ <li>Return the result of applying the subtraction operation to <i>lnum</i> and <i>rnum</i>. See the note below <a
+ href="#sec-applying-the-additive-operators-to-numbers">12.7.5</a>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-applying-the-additive-operators-to-numbers">
+ <h1><span class="secnum" id="sec-12.7.5"><a href="#sec-applying-the-additive-operators-to-numbers"
+ title="link to this section">12.7.5</a></span> Applying the Additive Operators to Numbers</h1>
+
+ <p>The <code>+</code> operator performs addition when applied to two operands of numeric type, producing the sum of the
+ operands. The <code>-</code> operator performs subtraction, producing the difference of two numeric operands.</p>
+
+ <p>Addition is a commutative operation, but not always associative.</p>
+
+ <p>The result of an addition is determined using the rules of IEEE 754 binary double-precision arithmetic:</p>
+
+ <ul>
+ <li>
+ <p>If either operand is <b>NaN</b>, the result is <b>NaN</b>.</p>
+ </li>
+
+ <li>
+ <p>The sum of two infinities of opposite sign is <b>NaN</b>.</p>
+ </li>
+
+ <li>
+ <p>The sum of two infinities of the same sign is the infinity of that sign.</p>
+ </li>
+
+ <li>
+ <p>The sum of an infinity and a finite value is equal to the infinite operand.</p>
+ </li>
+
+ <li>
+ <p>The sum of two negative zeroes is <b>−0</b>. The sum of two positive zeroes, or of two zeroes of opposite sign,
+ is <b>+0</b>.</p>
+ </li>
+
+ <li>
+ <p>The sum of a zero and a nonzero finite value is equal to the nonzero operand.</p>
+ </li>
+
+ <li>
+ <p>The sum of two nonzero finite values of the same magnitude and opposite sign is <b>+0</b>.</p>
+ </li>
+
+ <li>
+ <p>In the remaining cases, where neither an infinity, nor a zero, nor NaN is involved, and the operands have the same
+ sign or have different magnitudes, the sum is computed and rounded to the nearest representable value using IEEE 754
+ round-to-nearest mode. If the magnitude is too large to represent, the operation overflows and the result is then an
+ infinity of appropriate sign. The ECMAScript language requires support of gradual underflow as defined by IEEE 754.</p>
+ </li>
+ </ul>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>-</code> operator performs subtraction when applied to two operands of numeric
+ type, producing the difference of its operands; the left operand is the minuend and the right operand is the subtrahend.
+ Given numeric operands <i>a</i> and <i>b</i>, it is always the case that <i>a<code>–</code>b</i> produces the same
+ result as <i>a <code>+(–</code>b<code>)</code></i>.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-bitwise-shift-operators">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.8"><a href="#sec-bitwise-shift-operators" title="link to this section">12.8</a></span>
+ Bitwise Shift Operators</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ShiftExpression</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">AdditiveExpression</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="nt">ShiftExpression</span><sub>[?Yield]</sub> <code class="t"><<</code> <span class="nt">AdditiveExpression</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="nt">ShiftExpression</span><sub>[?Yield]</sub> <code class="t">>></code> <span class="nt">AdditiveExpression</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="nt">ShiftExpression</span><sub>[?Yield]</sub> <code class="t">>>></code> <span class="nt">AdditiveExpression</span><sub>[?Yield]</sub></div>
+ </div>
+ </div>
+
+ <section id="sec-bitwise-shift-operators-static-semantics-isfunctiondefinition">
+ <h1><span class="secnum" id="sec-12.8.1"><a href="#sec-bitwise-shift-operators-static-semantics-isfunctiondefinition"
+ title="link to this section">12.8.1</a></span> Static Semantics: IsFunctionDefinition</h1>
+
+ <p>See also: <a href="#sec-semantics-static-semantics-isfunctiondefinition">12.2.0.2</a>, <a
+ href="#sec-grouping-operator-static-semantics-isfunctiondefinition">12.2.10.2</a>, <a
+ href="#sec-static-semantics-static-semantics-isfunctiondefinition">12.3.1.2</a>, <a
+ href="#sec-postfix-expressions-static-semantics-isfunctiondefinition">12.4.2</a>, <a
+ href="#sec-unary-operators-static-semantics-isfunctiondefinition">12.5.2</a>, <a
+ href="#sec-multiplicative-operators-static-semantics-isfunctiondefinition">12.6.1</a>, <a
+ href="#sec-additive-operators-static-semantics-isfunctiondefinition">12.7.1</a>, <a
+ href="#sec-relational-operators-static-semantics-isfunctiondefinition">12.9.1</a>, <a
+ href="#sec-equality-operators-static-semantics-isfunctiondefinition">12.10.1</a>, <a
+ href="#sec-binary-bitwise-operators-static-semantics-isfunctiondefinition">12.11.1</a>, <a
+ href="#sec-binary-logical-operators-static-semantics-isfunctiondefinition">12.12.1</a>, <a
+ href="#sec-conditional-operator-static-semantics-isfunctiondefinition">12.13.1</a>, <a
+ href="#sec-assignment-operators-static-semantics-isfunctiondefinition">12.14.2</a>, <a
+ href="#sec-comma-operator-static-semantics-isfunctiondefinition">12.15.1</a>, <a
+ href="#sec-function-definitions-static-semantics-isfunctiondefinition">14.1.11</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-isfunctiondefinition">14.4.8</a>, <a
+ href="#sec-class-definitions-static-semantics-isfunctiondefinition">14.5.8</a>.</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ShiftExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">ShiftExpression</span> <code class="t"><<</code> <span class="nt">AdditiveExpression</span></div>
+ <div class="rhs"><span class="nt">ShiftExpression</span> <code class="t">>></code> <span class="nt">AdditiveExpression</span></div>
+ <div class="rhs"><span class="nt">ShiftExpression</span> <code class="t">>>></code> <span class="nt">AdditiveExpression</span></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-bitwise-shift-operators-static-semantics-isvalidsimpleassignmenttarget">
+ <h1><span class="secnum" id="sec-12.8.2"><a
+ href="#sec-bitwise-shift-operators-static-semantics-isvalidsimpleassignmenttarget"
+ title="link to this section">12.8.2</a></span> Static Semantics: IsValidSimpleAssignmentTarget</h1>
+
+ <p>See also: <a href="#sec-semantics-static-semantics-isidentifierref">12.2.0.3</a>, <a
+ href="#sec-grouping-operator-static-semantics-isvalidsimpleassignmenttarget">12.2.10.3</a>, <a
+ href="#sec-static-semantics-static-semantics-isidentifierref">12.3.1.3</a>, <a
+ href="#sec-postfix-expressions-static-semantics-isvalidsimpleassignmenttarget">12.4.3</a>, <a
+ href="#sec-unary-operators-static-semantics-isvalidsimpleassignmenttarget">12.5.3</a>, <a
+ href="#sec-multiplicative-operators-static-semantics-isvalidsimpleassignmenttarget">12.6.2</a>, <a
+ href="#sec-additive-operators-static-semantics-isvalidsimpleassignmenttarget">12.7.2</a>, <a
+ href="#sec-relational-operators-static-semantics-isvalidsimpleassignmenttarget">12.9.2</a>, <a
+ href="#sec-equality-operators-static-semantics-isvalidsimpleassignmenttarget">12.10.2</a>, <a
+ href="#sec-binary-bitwise-operators-static-semantics-isvalidsimpleassignmenttarget">12.11.2</a>, <a
+ href="#sec-binary-logical-operators-static-semantics-isvalidsimpleassignmenttarget">12.12.2</a>, <a
+ href="#sec-conditional-operator-static-semantics-isvalidsimpleassignmenttarget">12.13.2</a>, <a
+ href="#sec-assignment-operators-static-semantics-isvalidsimpleassignmenttarget">12.14.3</a>, <a
+ href="#sec-comma-operator-static-semantics-isvalidsimpleassignmenttarget">12.15.2</a>.</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ShiftExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">ShiftExpression</span> <code class="t"><<</code> <span class="nt">AdditiveExpression</span></div>
+ <div class="rhs"><span class="nt">ShiftExpression</span> <code class="t">>></code> <span class="nt">AdditiveExpression</span></div>
+ <div class="rhs"><span class="nt">ShiftExpression</span> <code class="t">>>></code> <span class="nt">AdditiveExpression</span></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-left-shift-operator">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.8.3"><a href="#sec-left-shift-operator" title="link to this section">12.8.3</a></span>
+ The Left Shift Operator ( <code><<</code> )</h1>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Performs a bitwise left shift operation on the left operand by the amount specified by
+ the right operand.</p>
+ </div>
+ </div>
+
+ <section id="sec-left-shift-operator-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-12.8.3.1"><a href="#sec-left-shift-operator-runtime-semantics-evaluation"
+ title="link to this section">12.8.3.1</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">ShiftExpression</span> <span class="geq">:</span> <span class="nt">ShiftExpression</span> <code class="t"><<</code> <span class="nt">AdditiveExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>lref</i> be the result of evaluating <i>ShiftExpression</i>.</li>
+ <li>Let <i>lval</i> be <a href="#sec-getvalue">GetValue</a>(<i>lref</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>lval</i>).</li>
+ <li>Let <i>rref</i> be the result of evaluating <i>AdditiveExpression</i>.</li>
+ <li>Let <i>rval</i> be <a href="#sec-getvalue">GetValue</a>(<i>rref</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>rval</i>).</li>
+ <li>Let <i>lnum</i> be <a href="#sec-toint32">ToInt32</a>(<i>lval</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>lnum</i>).</li>
+ <li>Let <i>rnum</i> be <a href="#sec-touint32">ToUint32</a>(<i>rval</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>rnum</i>).</li>
+ <li>Let <i>shiftCount</i> be the result of masking out all but the least significant 5 bits of <i>rnum</i>, that is,
+ compute <i>rnum</i> & 0x1F.</li>
+ <li>Return the result of left shifting <i>lnum</i> by <i>shiftCount</i> bits. The result is a signed 32-bit
+ integer.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-signed-right-shift-operator">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.8.4"><a href="#sec-signed-right-shift-operator"
+ title="link to this section">12.8.4</a></span> The Signed Right Shift Operator ( <code>>></code> )</h1>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Performs a sign-filling bitwise right shift operation on the left operand by the amount
+ specified by the right operand.</p>
+ </div>
+ </div>
+
+ <section id="sec-signed-right-shift-operator-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-12.8.4.1"><a href="#sec-signed-right-shift-operator-runtime-semantics-evaluation"
+ title="link to this section">12.8.4.1</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">ShiftExpression</span> <span class="geq">:</span> <span class="nt">ShiftExpression</span> <code class="t">>></code> <span class="nt">AdditiveExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>lref</i> be the result of evaluating <i>ShiftExpression</i>.</li>
+ <li>Let <i>lval</i> be <a href="#sec-getvalue">GetValue</a>(<i>lref</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>lval</i>).</li>
+ <li>Let <i>rref</i> be the result of evaluating <i>AdditiveExpression</i>.</li>
+ <li>Let <i>rval</i> be <a href="#sec-getvalue">GetValue</a>(<i>rref</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>rval</i>).</li>
+ <li>Let <i>lnum</i> be <a href="#sec-toint32">ToInt32</a>(<i>lval</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>lnum</i>).</li>
+ <li>Let <i>rnum</i> be <a href="#sec-touint32">ToUint32</a>(<i>rval</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>rnum</i>).</li>
+ <li>Let <i>shiftCount</i> be the result of masking out all but the least significant 5 bits of <i>rnum</i>, that is,
+ compute <i>rnum</i> & 0x1F.</li>
+ <li>Return the result of performing a sign-extending right shift of <i>lnum</i> by <i>shiftCount</i> bits. The most
+ significant bit is propagated. The result is a signed 32-bit integer.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-unsigned-right-shift-operator">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.8.5"><a href="#sec-unsigned-right-shift-operator"
+ title="link to this section">12.8.5</a></span> The Unsigned Right Shift Operator ( <code>>>></code> )</h1>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Performs a zero-filling bitwise right shift operation on the left operand by the amount
+ specified by the right operand.</p>
+ </div>
+ </div>
+
+ <section id="sec-unsigned-right-shift-operator-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-12.8.5.1"><a href="#sec-unsigned-right-shift-operator-runtime-semantics-evaluation"
+ title="link to this section">12.8.5.1</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">ShiftExpression</span> <span class="geq">:</span> <span class="nt">ShiftExpression</span> <code class="t">>>></code> <span class="nt">AdditiveExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>lref</i> be the result of evaluating <i>ShiftExpression</i>.</li>
+ <li>Let <i>lval</i> be <a href="#sec-getvalue">GetValue</a>(<i>lref</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>lval</i>).</li>
+ <li>Let <i>rref</i> be the result of evaluating <i>AdditiveExpression</i>.</li>
+ <li>Let <i>rval</i> be <a href="#sec-getvalue">GetValue</a>(<i>rref</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>rval</i>).</li>
+ <li>Let <i>lnum</i> be <a href="#sec-touint32">ToUint32</a>(<i>lval</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>lnum</i>).</li>
+ <li>Let <i>rnum</i> be <a href="#sec-touint32">ToUint32</a>(<i>rval</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>rnum</i>).</li>
+ <li>Let <i>shiftCount</i> be the result of masking out all but the least significant 5 bits of <i>rnum</i>, that is,
+ compute <i>rnum</i> & 0x1F.</li>
+ <li>Return the result of performing a zero-filling right shift of <i>lnum</i> by <i>shiftCount</i> bits. Vacated bits
+ are filled with zero. The result is an unsigned 32-bit integer.</li>
+ </ol>
+ </section>
+ </section>
+ </section>
+
+ <section id="sec-relational-operators">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.9"><a href="#sec-relational-operators" title="link to this section">12.9</a></span>
+ Relational Operators</h1>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The result of evaluating a relational operator is always of type Boolean, reflecting
+ whether the relationship named by the operator holds between its two operands.</p>
+ </div>
+
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">RelationalExpression</span><sub>[In, Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">ShiftExpression</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="nt">RelationalExpression</span><sub>[?In, ?Yield]</sub> <code class="t"><</code> <span class="nt">ShiftExpression</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="nt">RelationalExpression</span><sub>[?In, ?Yield]</sub> <code class="t">></code> <span class="nt">ShiftExpression</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="nt">RelationalExpression</span><sub>[?In, ?Yield]</sub> <code class="t"><=</code> <span class="nt">ShiftExpression</span><sub>[? Yield]</sub></div>
+ <div class="rhs"><span class="nt">RelationalExpression</span><sub>[?In, ?Yield]</sub> <code class="t">>=</code> <span class="nt">ShiftExpression</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="nt">RelationalExpression</span><sub>[?In, ?Yield]</sub> <code class="t">instanceof</code> <span class="nt">ShiftExpression</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="grhsannot">[+In]</span> <span class="nt">RelationalExpression</span><sub>[In, ?Yield]</sub> <code class="t">in</code> <span class="nt">ShiftExpression</span><sub>[?Yield]</sub></div>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The [In] grammar parameter is needed to avoid confusing the <code>in</code> operator in a
+ relational expression with the <code>in</code> operator in a <code>for</code> statement.</p>
+ </div>
+ </div>
+
+ <section id="sec-relational-operators-static-semantics-isfunctiondefinition">
+ <h1><span class="secnum" id="sec-12.9.1"><a href="#sec-relational-operators-static-semantics-isfunctiondefinition"
+ title="link to this section">12.9.1</a></span> Static Semantics: IsFunctionDefinition</h1>
+
+ <p>See also: <a href="#sec-semantics-static-semantics-isfunctiondefinition">12.2.0.2</a>, <a
+ href="#sec-grouping-operator-static-semantics-isfunctiondefinition">12.2.10.2</a>, <a
+ href="#sec-static-semantics-static-semantics-isfunctiondefinition">12.3.1.2</a>, <a
+ href="#sec-postfix-expressions-static-semantics-isfunctiondefinition">12.4.2</a>, <a
+ href="#sec-unary-operators-static-semantics-isfunctiondefinition">12.5.2</a>, <a
+ href="#sec-multiplicative-operators-static-semantics-isfunctiondefinition">12.6.1</a>, <a
+ href="#sec-additive-operators-static-semantics-isfunctiondefinition">12.7.1</a>, <a
+ href="#sec-bitwise-shift-operators-static-semantics-isfunctiondefinition">12.8.1</a>, <a
+ href="#sec-equality-operators-static-semantics-isfunctiondefinition">12.10.1</a>, <a
+ href="#sec-binary-bitwise-operators-static-semantics-isfunctiondefinition">12.11.1</a>, <a
+ href="#sec-binary-logical-operators-static-semantics-isfunctiondefinition">12.12.1</a>, <a
+ href="#sec-conditional-operator-static-semantics-isfunctiondefinition">12.13.1</a>, <a
+ href="#sec-assignment-operators-static-semantics-isfunctiondefinition">12.14.2</a>, <a
+ href="#sec-comma-operator-static-semantics-isfunctiondefinition">12.15.1</a>, <a
+ href="#sec-function-definitions-static-semantics-isfunctiondefinition">14.1.11</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-isfunctiondefinition">14.4.8</a>, <a
+ href="#sec-class-definitions-static-semantics-isfunctiondefinition">14.5.8</a>.</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">RelationalExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">RelationalExpression</span> <code class="t"><</code> <span class="nt">ShiftExpression</span></div>
+ <div class="rhs"><span class="nt">RelationalExpression</span> <code class="t">></code> <span class="nt">ShiftExpression</span></div>
+ <div class="rhs"><span class="nt">RelationalExpression</span> <code class="t"><=</code> <span class="nt">ShiftExpression</span></div>
+ <div class="rhs"><span class="nt">RelationalExpression</span> <code class="t">>=</code> <span class="nt">ShiftExpression</span></div>
+ <div class="rhs"><span class="nt">RelationalExpression</span> <code class="t">instanceof</code> <span class="nt">ShiftExpression</span></div>
+ <div class="rhs"><span class="nt">RelationalExpression</span> <code class="t">in</code> <span class="nt">ShiftExpression</span></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-relational-operators-static-semantics-isvalidsimpleassignmenttarget">
+ <h1><span class="secnum" id="sec-12.9.2"><a href="#sec-relational-operators-static-semantics-isvalidsimpleassignmenttarget"
+ title="link to this section">12.9.2</a></span> Static Semantics: IsValidSimpleAssignmentTarget</h1>
+
+ <p>See also: <a href="#sec-semantics-static-semantics-isidentifierref">12.2.0.3</a>, <a
+ href="#sec-grouping-operator-static-semantics-isvalidsimpleassignmenttarget">12.2.10.3</a>, <a
+ href="#sec-static-semantics-static-semantics-isidentifierref">12.3.1.3</a>, <a
+ href="#sec-postfix-expressions-static-semantics-isvalidsimpleassignmenttarget">12.4.3</a>, <a
+ href="#sec-unary-operators-static-semantics-isvalidsimpleassignmenttarget">12.5.3</a>, <a
+ href="#sec-multiplicative-operators-static-semantics-isvalidsimpleassignmenttarget">12.6.2</a>, <a
+ href="#sec-additive-operators-static-semantics-isvalidsimpleassignmenttarget">12.7.2</a>, <a
+ href="#sec-bitwise-shift-operators-static-semantics-isvalidsimpleassignmenttarget">12.8.2</a>, <a
+ href="#sec-equality-operators-static-semantics-isvalidsimpleassignmenttarget">12.10.2</a>, <a
+ href="#sec-binary-bitwise-operators-static-semantics-isvalidsimpleassignmenttarget">12.11.2</a>, <a
+ href="#sec-binary-logical-operators-static-semantics-isvalidsimpleassignmenttarget">12.12.2</a>, <a
+ href="#sec-conditional-operator-static-semantics-isvalidsimpleassignmenttarget">12.13.2</a>, <a
+ href="#sec-assignment-operators-static-semantics-isvalidsimpleassignmenttarget">12.14.3</a>, <a
+ href="#sec-comma-operator-static-semantics-isvalidsimpleassignmenttarget">12.15.2</a>.</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">RelationalExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">RelationalExpression</span> <code class="t"><</code> <span class="nt">ShiftExpression</span></div>
+ <div class="rhs"><span class="nt">RelationalExpression</span> <code class="t">></code> <span class="nt">ShiftExpression</span></div>
+ <div class="rhs"><span class="nt">RelationalExpression</span> <code class="t"><=</code> <span class="nt">ShiftExpression</span></div>
+ <div class="rhs"><span class="nt">RelationalExpression</span> <code class="t">>=</code> <span class="nt">ShiftExpression</span></div>
+ <div class="rhs"><span class="nt">RelationalExpression</span> <code class="t">instanceof</code> <span class="nt">ShiftExpression</span></div>
+ <div class="rhs"><span class="nt">RelationalExpression</span> <code class="t">in</code> <span class="nt">ShiftExpression</span></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-relational-operators-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-12.9.3"><a href="#sec-relational-operators-runtime-semantics-evaluation"
+ title="link to this section">12.9.3</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">RelationalExpression</span> <span class="geq">:</span> <span class="nt">RelationalExpression</span> <code class="t"><</code> <span class="nt">ShiftExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>lref</i> be the result of evaluating <i>RelationalExpression</i>.</li>
+ <li>Let <i>lval</i> be <a href="#sec-getvalue">GetValue</a>(<i>lref</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>lval</i>).</li>
+ <li>Let <i>rref</i> be the result of evaluating <i>ShiftExpression</i>.</li>
+ <li>Let <i>rval</i> be <a href="#sec-getvalue">GetValue</a>(<i>rref</i>).</li>
+ <li>Let <i>r</i> be the result of performing Abstract Relational Comparison <i>lval</i> < <i>rval</i>. (<a
+ href="#sec-isinteger">see 7.2.8</a>)</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>r</i>).</li>
+ <li>If <i>r</i> is <b>undefined</b>, return <b>false</b>. Otherwise, return <i>r</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">RelationalExpression</span> <span class="geq">:</span> <span class="nt">RelationalExpression</span> <code class="t">></code> <span class="nt">ShiftExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>lref</i> be the result of evaluating <i>RelationalExpression</i>.</li>
+ <li>Let <i>lval</i> be <a href="#sec-getvalue">GetValue</a>(<i>lref</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>lval</i>).</li>
+ <li>Let <i>rref</i> be the result of evaluating <i>ShiftExpression</i>.</li>
+ <li>Let <i>rval</i> be <a href="#sec-getvalue">GetValue</a>(<i>rref</i>).</li>
+ <li>Let <i>r</i> be the result of performing Abstract Relational Comparison <i>rval</i> < <i>lval</i> with
+ <i>LeftFirst</i> equal to <b>false</b>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>r</i>).</li>
+ <li>If <i>r</i> is <b>undefined</b>, return <b>false</b>. Otherwise, return <i>r</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">RelationalExpression</span> <span class="geq">:</span> <span class="nt">RelationalExpression</span> <code class="t"><=</code> <span class="nt">ShiftExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>lref</i> be the result of evaluating <i>RelationalExpression</i>.</li>
+ <li>Let <i>lval</i> be <a href="#sec-getvalue">GetValue</a>(<i>lref</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>lval</i>).</li>
+ <li>Let <i>rref</i> be the result of evaluating <i>ShiftExpression</i>.</li>
+ <li>Let <i>rval</i> be <a href="#sec-getvalue">GetValue</a>(<i>rref</i>).</li>
+ <li>Let <i>r</i> be the result of performing Abstract Relational Comparison <i>rval</i> < <i>lval</i> with
+ <i>LeftFirst</i> equal to <b>false</b>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>r</i>).</li>
+ <li>If <i>r</i> is <b>true</b> or <b>undefined</b>, return <b>false</b>. Otherwise, return <b>true</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">RelationalExpression</span> <span class="geq">:</span> <span class="nt">RelationalExpression</span> <code class="t">>=</code> <span class="nt">ShiftExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>lref</i> be the result of evaluating <i>RelationalExpression</i>.</li>
+ <li>Let <i>lval</i> be <a href="#sec-getvalue">GetValue</a>(<i>lref</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>lval</i>).</li>
+ <li>Let <i>rref</i> be the result of evaluating <i>ShiftExpression</i>.</li>
+ <li>Let <i>rval</i> be <a href="#sec-getvalue">GetValue</a>(<i>rref</i>).</li>
+ <li>Let <i>r</i> be the result of performing Abstract Relational Comparison <i>lval</i> < <i>rval</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>r</i>).</li>
+ <li>If <i>r</i> is <b>true</b> or <b>undefined</b>, return <b>false</b>. Otherwise, return <b>true</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">RelationalExpression</span> <span class="geq">:</span> <span class="nt">RelationalExpression</span> <code class="t">instanceof</code> <span class="nt">ShiftExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>lref</i> be the result of evaluating <i>RelationalExpression</i>.</li>
+ <li>Let <i>lval</i> be <a href="#sec-getvalue">GetValue</a>(<i>lref</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>lval</i>).</li>
+ <li>Let <i>rref</i> be the result of evaluating <i>ShiftExpression</i>.</li>
+ <li>Let <i>rval</i> be <a href="#sec-getvalue">GetValue</a>(<i>rref</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>rval</i>).</li>
+ <li>Return <a href="#sec-instanceofoperator">InstanceofOperator</a>(<i>lval</i>, <i>rval</i>).</li>
+ </ol>
+ <div class="gp prod"><span class="nt">RelationalExpression</span> <span class="geq">:</span> <span class="nt">RelationalExpression</span> <code class="t">in</code> <span class="nt">ShiftExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>lref</i> be the result of evaluating <i>RelationalExpression</i>.</li>
+ <li>Let <i>lval</i> be <a href="#sec-getvalue">GetValue</a>(<i>lref</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>lval</i>).</li>
+ <li>Let <i>rref</i> be the result of evaluating <i>ShiftExpression</i>.</li>
+ <li>Let <i>rval</i> be <a href="#sec-getvalue">GetValue</a>(<i>rref</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>rval</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>rval</i>) is not Object, throw a <b>TypeError</b>
+ exception.</li>
+ <li>Return <a href="#sec-hasproperty">HasProperty</a>(<i>rval</i>, <a
+ href="#sec-topropertykey">ToPropertyKey</a>(<i>lval</i>)).</li>
+ </ol>
+ </section>
+
+ <section id="sec-instanceofoperator">
+ <h1><span class="secnum" id="sec-12.9.4"><a href="#sec-instanceofoperator" title="link to this section">12.9.4</a></span>
+ Runtime Semantics: InstanceofOperator(O, C)</h1>
+
+ <p>The abstract operation <span style="font-family: Times New Roman">InstanceofOperator(<i>O</i>, <i>C</i>)</span>
+ implements the generic algorithm for determining if an object <var>O</var> inherits from the inheritance path defined by
+ constructor <var>C</var>. This abstract operation performs the following steps:</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>C</i>) is not Object, throw a <b>TypeError</b>
+ exception.</li>
+ <li>Let <i>instOfHandler</i> be <a href="#sec-getmethod">GetMethod</a>(<i>C</i>,@@hasInstance).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>instOfHandler</i>).</li>
+ <li>If <i>instOfHandler</i> is not <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>result</i> be the result of calling the [[Call]] internal method of <i>instOfHandler</i> passing <i>C</i>
+ as <i>thisArgument</i> and a new <a href="#sec-list-and-record-specification-type">List</a> containing <i>O</i> as
+ <i>argumentsList</i>.</li>
+ <li>Return <a href="#sec-toboolean">ToBoolean</a>(<i>result</i>).</li>
+ </ol>
+ </li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>C</i>) is <b>false</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Return <a href="#sec-ordinaryhasinstance">OrdinaryHasInstance</a>(<i>C</i>, <i>O</i>).</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Steps 5 and 6 provide compatibility with previous editions of ECMAScript that did not use
+ a @@hasInstance method to define the <code>instanceof</code> operator semantics. If a function object does not define or
+ inherit @@hasInstance it uses the default <code>instanceof</code> semantics.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-equality-operators">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.10"><a href="#sec-equality-operators" title="link to this section">12.10</a></span>
+ Equality Operators</h1>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The result of evaluating an equality operator is always of type Boolean, reflecting
+ whether the relationship named by the operator holds between its two operands.</p>
+ </div>
+
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">EqualityExpression</span><sub>[In, Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">RelationalExpression</span><sub>[?In, ?Yield]</sub></div>
+ <div class="rhs"><span class="nt">EqualityExpression</span><sub>[?In, ?Yield]</sub> <code class="t">==</code> <span class="nt">RelationalExpression</span><sub>[?In, ?Yield]</sub></div>
+ <div class="rhs"><span class="nt">EqualityExpression</span><sub>[?In, ?Yield]</sub> <code class="t">!=</code> <span class="nt">RelationalExpression</span><sub>[?In, ?Yield]</sub></div>
+ <div class="rhs"><span class="nt">EqualityExpression</span><sub>[?In, ?Yield]</sub> <code class="t">===</code> <span class="nt">RelationalExpression</span><sub>[?In, ?Yield]</sub></div>
+ <div class="rhs"><span class="nt">EqualityExpression</span><sub>[?In, ?Yield]</sub> <code class="t">!==</code> <span class="nt">RelationalExpression</span><sub>[?In, ?Yield]</sub></div>
+ </div>
+ </div>
+
+ <section id="sec-equality-operators-static-semantics-isfunctiondefinition">
+ <h1><span class="secnum" id="sec-12.10.1"><a href="#sec-equality-operators-static-semantics-isfunctiondefinition"
+ title="link to this section">12.10.1</a></span> Static Semantics: IsFunctionDefinition</h1>
+
+ <p>See also: <a href="#sec-semantics-static-semantics-isfunctiondefinition">12.2.0.2</a>, <a
+ href="#sec-grouping-operator-static-semantics-isfunctiondefinition">12.2.10.2</a>, <a
+ href="#sec-static-semantics-static-semantics-isfunctiondefinition">12.3.1.2</a>, <a
+ href="#sec-postfix-expressions-static-semantics-isfunctiondefinition">12.4.2</a>, <a
+ href="#sec-unary-operators-static-semantics-isfunctiondefinition">12.5.2</a>, <a
+ href="#sec-multiplicative-operators-static-semantics-isfunctiondefinition">12.6.1</a>, <a
+ href="#sec-additive-operators-static-semantics-isfunctiondefinition">12.7.1</a>, <a
+ href="#sec-bitwise-shift-operators-static-semantics-isfunctiondefinition">12.8.1</a>, <a
+ href="#sec-relational-operators-static-semantics-isfunctiondefinition">12.9.1</a>, <a
+ href="#sec-binary-bitwise-operators-static-semantics-isfunctiondefinition">12.11.1</a>, <a
+ href="#sec-binary-logical-operators-static-semantics-isfunctiondefinition">12.12.1</a>, <a
+ href="#sec-conditional-operator-static-semantics-isfunctiondefinition">12.13.1</a>, <a
+ href="#sec-assignment-operators-static-semantics-isfunctiondefinition">12.14.2</a>, <a
+ href="#sec-comma-operator-static-semantics-isfunctiondefinition">12.15.1</a>, <a
+ href="#sec-function-definitions-static-semantics-isfunctiondefinition">14.1.11</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-isfunctiondefinition">14.4.8</a>, <a
+ href="#sec-class-definitions-static-semantics-isfunctiondefinition">14.5.8</a>.</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">EqualityExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">EqualityExpression</span> <code class="t">==</code> <span class="nt">RelationalExpression</span></div>
+ <div class="rhs"><span class="nt">EqualityExpression</span> <code class="t">!=</code> <span class="nt">RelationalExpression</span></div>
+ <div class="rhs"><span class="nt">EqualityExpression</span> <code class="t">===</code> <span class="nt">RelationalExpression</span></div>
+ <div class="rhs"><span class="nt">EqualityExpression</span> <code class="t">!==</code> <span class="nt">RelationalExpression</span></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-equality-operators-static-semantics-isvalidsimpleassignmenttarget">
+ <h1><span class="secnum" id="sec-12.10.2"><a href="#sec-equality-operators-static-semantics-isvalidsimpleassignmenttarget"
+ title="link to this section">12.10.2</a></span> Static Semantics: IsValidSimpleAssignmentTarget</h1>
+
+ <p>See also: <a href="#sec-semantics-static-semantics-isidentifierref">12.2.0.3</a>, <a
+ href="#sec-grouping-operator-static-semantics-isvalidsimpleassignmenttarget">12.2.10.3</a>, <a
+ href="#sec-static-semantics-static-semantics-isidentifierref">12.3.1.3</a>, <a
+ href="#sec-postfix-expressions-static-semantics-isvalidsimpleassignmenttarget">12.4.3</a>, <a
+ href="#sec-unary-operators-static-semantics-isvalidsimpleassignmenttarget">12.5.3</a>, <a
+ href="#sec-multiplicative-operators-static-semantics-isvalidsimpleassignmenttarget">12.6.2</a>, <a
+ href="#sec-additive-operators-static-semantics-isvalidsimpleassignmenttarget">12.7.2</a>, <a
+ href="#sec-bitwise-shift-operators-static-semantics-isvalidsimpleassignmenttarget">12.8.2</a>, <a
+ href="#sec-relational-operators-static-semantics-isvalidsimpleassignmenttarget">12.9.2</a>, <a
+ href="#sec-binary-bitwise-operators-static-semantics-isvalidsimpleassignmenttarget">12.11.2</a>, <a
+ href="#sec-binary-logical-operators-static-semantics-isvalidsimpleassignmenttarget">12.12.2</a>, <a
+ href="#sec-conditional-operator-static-semantics-isvalidsimpleassignmenttarget">12.13.2</a>, <a
+ href="#sec-assignment-operators-static-semantics-isvalidsimpleassignmenttarget">12.14.3</a>, <a
+ href="#sec-comma-operator-static-semantics-isvalidsimpleassignmenttarget">12.15.2</a>.</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">EqualityExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">EqualityExpression</span> <code class="t">==</code> <span class="nt">RelationalExpression</span></div>
+ <div class="rhs"><span class="nt">EqualityExpression</span> <code class="t">!=</code> <span class="nt">RelationalExpression</span></div>
+ <div class="rhs"><span class="nt">EqualityExpression</span> <code class="t">===</code> <span class="nt">RelationalExpression</span></div>
+ <div class="rhs"><span class="nt">EqualityExpression</span> <code class="t">!==</code> <span class="nt">RelationalExpression</span></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-equality-operators-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-12.10.3"><a href="#sec-equality-operators-runtime-semantics-evaluation"
+ title="link to this section">12.10.3</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">EqualityExpression</span> <span class="geq">:</span> <span class="nt">EqualityExpression</span> <code class="t">==</code> <span class="nt">RelationalExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>lref</i> be the result of evaluating <i>EqualityExpression</i>.</li>
+ <li>Let <i>lval</i> be <a href="#sec-getvalue">GetValue</a>(<i>lref</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>lval</i>).</li>
+ <li>Let <i>rref</i> be the result of evaluating <i>RelationalExpression</i>.</li>
+ <li>Let <i>rval</i> be <a href="#sec-getvalue">GetValue</a>(<i>rref</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>rval</i>).</li>
+ <li>Return the result of performing Abstract Equality Comparison <i>rval</i> == <i>lval</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">EqualityExpression</span> <span class="geq">:</span> <span class="nt">EqualityExpression</span> <code class="t">!=</code> <span class="nt">RelationalExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>lref</i> be the result of evaluating <i>EqualityExpression</i>.</li>
+ <li>Let <i>lval</i> be <a href="#sec-getvalue">GetValue</a>(<i>lref</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>lval</i>).</li>
+ <li>Let <i>rref</i> be the result of evaluating <i>RelationalExpression</i>.</li>
+ <li>Let <i>rval</i> be <a href="#sec-getvalue">GetValue</a>(<i>rref</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>rval</i>).</li>
+ <li>Let <i>r</i> be the result of performing Abstract Equality Comparison <i>rval</i> == <i>lval</i>.</li>
+ <li>If <i>r</i> is <b>true</b>, return <b>false</b>. Otherwise, return <b>true</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">EqualityExpression</span> <span class="geq">:</span> <span class="nt">EqualityExpression</span> <code class="t">===</code> <span class="nt">RelationalExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>lref</i> be the result of evaluating <i>EqualityExpression</i>.</li>
+ <li>Let <i>lval</i> be <a href="#sec-getvalue">GetValue</a>(<i>lref</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>lval</i>)</li>
+ <li>Let <i>rref</i> be the result of evaluating <i>RelationalExpression</i>.</li>
+ <li>Let <i>rval</i> be <a href="#sec-getvalue">GetValue</a>(<i>rref</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>rval</i>).</li>
+ <li>Return the result of performing Strict Equality Comparison <i>rval</i> === <i>lval</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">EqualityExpression</span> <span class="geq">:</span> <span class="nt">EqualityExpression</span> <code class="t">!==</code> <span class="nt">RelationalExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>lref</i> be the result of evaluating <i>EqualityExpression</i>.</li>
+ <li>Let <i>lval</i> be <a href="#sec-getvalue">GetValue</a>(<i>lref</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>lval</i>).</li>
+ <li>Let <i>rref</i> be the result of evaluating <i>RelationalExpression</i>.</li>
+ <li>Let <i>rval</i> be <a href="#sec-getvalue">GetValue</a>(<i>rref</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>rval</i>).</li>
+ <li>Let <i>r</i> be the result of performing Strict Equality Comparison <i>rval</i> === <i>lval</i>.</li>
+ <li>If <i>r</i> is <b>true</b>, return <b>false</b>. Otherwise, return <b>true</b>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> Given the above definition of equality:</p>
+
+ <ul>
+ <li>String comparison can be forced by: <code>"" + a == "" + b</code>.</li>
+ <li>Numeric comparison can be forced by: <code>+a == +b</code>.</li>
+ <li>Boolean comparison can be forced by: <code>!a == !b</code>.</li>
+ </ul>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 2</span> The equality operators maintain the following invariants:</p>
+
+ <ul>
+ <li><code>A</code> <code>!=</code> <code>B</code> is equivalent to <code>!(A</code> <code>==</code>
+ <code>B)</code>.</li>
+ <li><code>A</code> <code>==</code> <code>B</code> is equivalent to <code>B</code> <code>==</code> <code>A</code>, except
+ in the order of evaluation of <code>A</code> and <code>B</code>.</li>
+ </ul>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 3</span> The equality operator is not always transitive. For example, there might be two distinct
+ String objects, each representing the same String value; each String object would be considered equal to the String value
+ by the <code>==</code> operator, but the two String objects would not be equal to each other. For Example:</p>
+
+ <ul>
+ <li><code>new String("a")</code> <code>==</code> <code>"a"</code> and <code>"a"</code> <code>==</code> <code>new
+ String("a")</code>are both <b>true</b>.</li>
+ <li><code>new String("a")</code> <code>==</code> <code>new String("a")</code> is <b>false</b>.</li>
+ </ul>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 4</span> Comparison of Strings uses a simple equality test on sequences of code unit values.
+ There is no attempt to use the more complex, semantically oriented definitions of character or string equality and
+ collating order defined in the Unicode specification. Therefore Strings values that are canonically equal according to the
+ Unicode standard could test as unequal. In effect this algorithm assumes that both Strings are already in normalized
+ form.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-binary-bitwise-operators">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.11"><a href="#sec-binary-bitwise-operators"
+ title="link to this section">12.11</a></span> Binary Bitwise Operators</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">BitwiseANDExpression</span><sub>[In, Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">EqualityExpression</span><sub>[?In, ?Yield]</sub></div>
+ <div class="rhs"><span class="nt">BitwiseANDExpression</span><sub>[?In, ?Yield]</sub> <code class="t">&</code> <span class="nt">EqualityExpression</span><sub>[?In, ?Yield]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">BitwiseXORExpression</span><sub>[In, Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">BitwiseANDExpression</span><sub>[?In, ?Yield]</sub></div>
+ <div class="rhs"><span class="nt">BitwiseXORExpression</span><sub>[?In, ?Yield]</sub> <code class="t">^</code> <span class="nt">BitwiseANDExpression</span><sub>[?In, ?Yield]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">BitwiseORExpression</span><sub>[In, Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">BitwiseXORExpression</span><sub>[?In, ?Yield]</sub></div>
+ <div class="rhs"><span class="nt">BitwiseORExpression</span><sub>[?In, ?Yield]</sub> <code class="t">|</code> <span class="nt">BitwiseXORExpression</span><sub>[?In, ?Yield]</sub></div>
+ </div>
+ </div>
+
+ <section id="sec-binary-bitwise-operators-static-semantics-isfunctiondefinition">
+ <h1><span class="secnum" id="sec-12.11.1"><a href="#sec-binary-bitwise-operators-static-semantics-isfunctiondefinition"
+ title="link to this section">12.11.1</a></span> Static Semantics: IsFunctionDefinition</h1>
+
+ <p>See also: <a href="#sec-semantics-static-semantics-isfunctiondefinition">12.2.0.2</a>, <a
+ href="#sec-grouping-operator-static-semantics-isfunctiondefinition">12.2.10.2</a>, <a
+ href="#sec-static-semantics-static-semantics-isfunctiondefinition">12.3.1.2</a>, <a
+ href="#sec-postfix-expressions-static-semantics-isfunctiondefinition">12.4.2</a>, <a
+ href="#sec-unary-operators-static-semantics-isfunctiondefinition">12.5.2</a>, <a
+ href="#sec-multiplicative-operators-static-semantics-isfunctiondefinition">12.6.1</a>, <a
+ href="#sec-additive-operators-static-semantics-isfunctiondefinition">12.7.1</a>, <a
+ href="#sec-bitwise-shift-operators-static-semantics-isfunctiondefinition">12.8.1</a>, <a
+ href="#sec-relational-operators-static-semantics-isfunctiondefinition">12.9.1</a>, <a
+ href="#sec-equality-operators-static-semantics-isfunctiondefinition">12.10.1</a>, <a
+ href="#sec-binary-logical-operators-static-semantics-isfunctiondefinition">12.12.1</a>, <a
+ href="#sec-conditional-operator-static-semantics-isfunctiondefinition">12.13.1</a>, <a
+ href="#sec-assignment-operators-static-semantics-isfunctiondefinition">12.14.2</a>, <a
+ href="#sec-comma-operator-static-semantics-isfunctiondefinition">12.15.1</a>, <a
+ href="#sec-function-definitions-static-semantics-isfunctiondefinition">14.1.11</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-isfunctiondefinition">14.4.8</a>, <a
+ href="#sec-class-definitions-static-semantics-isfunctiondefinition">14.5.8</a>.</p>
+
+ <p><span class="prod"><span class="nt">BitwiseANDExpression</span> <span class="geq">:</span> <span
+ class="nt">BitwiseANDExpression</span> <code class="t">&</code> <span class="nt">EqualityExpression</span></span></p>
+
+ <p><span class="prod"><span class="nt">BitwiseXORExpression</span> <span class="geq">:</span> <span
+ class="nt">BitwiseXORExpression</span> <code class="t">^</code> <span class="nt">BitwiseANDExpression</span></span></p>
+
+ <div class="gp prod"><span class="nt">BitwiseORExpression</span> <span class="geq">:</span> <span class="nt">BitwiseORExpression</span> <code class="t">|</code> <span class="nt">BitwiseXORExpression</span></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-binary-bitwise-operators-static-semantics-isvalidsimpleassignmenttarget">
+ <h1><span class="secnum" id="sec-12.11.2"><a
+ href="#sec-binary-bitwise-operators-static-semantics-isvalidsimpleassignmenttarget"
+ title="link to this section">12.11.2</a></span> Static Semantics: IsValidSimpleAssignmentTarget</h1>
+
+ <p>See also: <a href="#sec-semantics-static-semantics-isidentifierref">12.2.0.3</a>, <a
+ href="#sec-grouping-operator-static-semantics-isvalidsimpleassignmenttarget">12.2.10.3</a>, <a
+ href="#sec-static-semantics-static-semantics-isidentifierref">12.3.1.3</a>, <a
+ href="#sec-postfix-expressions-static-semantics-isvalidsimpleassignmenttarget">12.4.3</a>, <a
+ href="#sec-unary-operators-static-semantics-isvalidsimpleassignmenttarget">12.5.3</a>, <a
+ href="#sec-multiplicative-operators-static-semantics-isvalidsimpleassignmenttarget">12.6.2</a>, <a
+ href="#sec-additive-operators-static-semantics-isvalidsimpleassignmenttarget">12.7.2</a>, <a
+ href="#sec-bitwise-shift-operators-static-semantics-isvalidsimpleassignmenttarget">12.8.2</a>, <a
+ href="#sec-relational-operators-static-semantics-isvalidsimpleassignmenttarget">12.9.2</a>, <a
+ href="#sec-equality-operators-static-semantics-isvalidsimpleassignmenttarget">12.10.2</a>, <a
+ href="#sec-binary-logical-operators-static-semantics-isvalidsimpleassignmenttarget">12.12.2</a>, <a
+ href="#sec-conditional-operator-static-semantics-isvalidsimpleassignmenttarget">12.13.2</a>, <a
+ href="#sec-assignment-operators-static-semantics-isvalidsimpleassignmenttarget">12.14.3</a>, <a
+ href="#sec-comma-operator-static-semantics-isvalidsimpleassignmenttarget">12.15.2</a>.</p>
+
+ <p><span class="prod"><span class="nt">BitwiseANDExpression</span> <span class="geq">:</span> <span
+ class="nt">BitwiseANDExpression</span> <code class="t">&</code> <span class="nt">EqualityExpression</span></span></p>
+
+ <p><span class="prod"><span class="nt">BitwiseXORExpression</span> <span class="geq">:</span> <span
+ class="nt">BitwiseXORExpression</span> <code class="t">^</code> <span class="nt">BitwiseANDExpression</span></span></p>
+
+ <div class="gp prod"><span class="nt">BitwiseORExpression</span> <span class="geq">:</span> <span class="nt">BitwiseORExpression</span> <code class="t">|</code> <span class="nt">BitwiseXORExpression</span></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-binary-bitwise-operators-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-12.11.3"><a href="#sec-binary-bitwise-operators-runtime-semantics-evaluation"
+ title="link to this section">12.11.3</a></span> Runtime Semantics: Evaluation</h1>
+
+ <p>The production <var>A</var> <b>:</b> <i><span style="font-family: Times New Roman">A</span> @ <span style="font-family:
+ Times New Roman">B</span></i>, where @ is one of the bitwise operators in the productions above, is evaluated as
+ follows:</p>
+
+ <ol class="proc">
+ <li>Let <i>lref</i> be the result of evaluating <i>A</i>.</li>
+ <li>Let <i>lval</i> be <a href="#sec-getvalue">GetValue</a>(<i>lref</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>lval</i>).</li>
+ <li>Let <i>rref</i> be the result of evaluating <i>B</i>.</li>
+ <li>Let <i>rval</i> be <a href="#sec-getvalue">GetValue</a>(<i>rref</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>rval</i>).</li>
+ <li>Let <i>lnum</i> be <a href="#sec-toint32">ToInt32</a>(<i>lval</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>lnum</i>).</li>
+ <li>Let <i>rnum</i> be <a href="#sec-toint32">ToInt32</a>(<i>rval</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>rnum</i>).</li>
+ <li>Return the result of applying the bitwise operator @ to <i>lnum</i> and <i>rnum</i>. The result is a signed 32 bit
+ integer.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-binary-logical-operators">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.12"><a href="#sec-binary-logical-operators"
+ title="link to this section">12.12</a></span> Binary Logical Operators</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">LogicalANDExpression</span><sub>[In, Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">BitwiseORExpression</span><sub>[?In, ?Yield]</sub></div>
+ <div class="rhs"><span class="nt">LogicalANDExpression</span><sub>[?In, ?Yield]</sub> <code class="t">&&</code> <span class="nt">BitwiseORExpression</span><sub>[?In, ?Yield]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">LogicalORExpression</span><sub>[In, Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">LogicalANDExpression</span><sub>[?In, ?Yield]</sub></div>
+ <div class="rhs"><span class="nt">LogicalORExpression</span><sub>[?In, ?Yield]</sub> <code class="t">||</code> <span class="nt">LogicalANDExpression</span><sub>[?In, ?Yield]</sub></div>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The value produced by a <code>&&</code> or <code>||</code> operator is not
+ necessarily of type Boolean. The value produced will always be the value of one of the two operand expressions.</p>
+ </div>
+ </div>
+
+ <section id="sec-binary-logical-operators-static-semantics-isfunctiondefinition">
+ <h1><span class="secnum" id="sec-12.12.1"><a href="#sec-binary-logical-operators-static-semantics-isfunctiondefinition"
+ title="link to this section">12.12.1</a></span> Static Semantics: IsFunctionDefinition</h1>
+
+ <p>See also: <a href="#sec-semantics-static-semantics-isfunctiondefinition">12.2.0.2</a>, <a
+ href="#sec-grouping-operator-static-semantics-isfunctiondefinition">12.2.10.2</a>, <a
+ href="#sec-static-semantics-static-semantics-isfunctiondefinition">12.3.1.2</a>, <a
+ href="#sec-postfix-expressions-static-semantics-isfunctiondefinition">12.4.2</a>, <a
+ href="#sec-unary-operators-static-semantics-isfunctiondefinition">12.5.2</a>, <a
+ href="#sec-multiplicative-operators-static-semantics-isfunctiondefinition">12.6.1</a>, <a
+ href="#sec-additive-operators-static-semantics-isfunctiondefinition">12.7.1</a>, <a
+ href="#sec-bitwise-shift-operators-static-semantics-isfunctiondefinition">12.8.1</a>, <a
+ href="#sec-relational-operators-static-semantics-isfunctiondefinition">12.9.1</a>, <a
+ href="#sec-equality-operators-static-semantics-isfunctiondefinition">12.10.1</a>, <a
+ href="#sec-binary-bitwise-operators-static-semantics-isfunctiondefinition">12.11.1</a>, <a
+ href="#sec-conditional-operator-static-semantics-isfunctiondefinition">12.13.1</a>, <a
+ href="#sec-assignment-operators-static-semantics-isfunctiondefinition">12.14.2</a>, <a
+ href="#sec-comma-operator-static-semantics-isfunctiondefinition">12.15.1</a>, <a
+ href="#sec-function-definitions-static-semantics-isfunctiondefinition">14.1.11</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-isfunctiondefinition">14.4.8</a>, <a
+ href="#sec-class-definitions-static-semantics-isfunctiondefinition">14.5.8</a>.</p>
+
+ <p><span class="prod"><span class="nt">LogicalANDExpression</span> <span class="geq">:</span> <span
+ class="nt">LogicalANDExpression</span> <code class="t">&&</code> <span
+ class="nt">BitwiseORExpression</span></span></p>
+
+ <div class="gp prod"><span class="nt">LogicalORExpression</span> <span class="geq">:</span> <span class="nt">LogicalORExpression</span> <code class="t">||</code> <span class="nt">LogicalANDExpression</span></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-binary-logical-operators-static-semantics-isvalidsimpleassignmenttarget">
+ <h1><span class="secnum" id="sec-12.12.2"><a
+ href="#sec-binary-logical-operators-static-semantics-isvalidsimpleassignmenttarget"
+ title="link to this section">12.12.2</a></span> Static Semantics: IsValidSimpleAssignmentTarget</h1>
+
+ <p>See also: <a href="#sec-semantics-static-semantics-isidentifierref">12.2.0.3</a>, <a
+ href="#sec-grouping-operator-static-semantics-isvalidsimpleassignmenttarget">12.2.10.3</a>, <a
+ href="#sec-static-semantics-static-semantics-isidentifierref">12.3.1.3</a>, <a
+ href="#sec-postfix-expressions-static-semantics-isvalidsimpleassignmenttarget">12.4.3</a>, <a
+ href="#sec-unary-operators-static-semantics-isvalidsimpleassignmenttarget">12.5.3</a>, <a
+ href="#sec-multiplicative-operators-static-semantics-isvalidsimpleassignmenttarget">12.6.2</a>, <a
+ href="#sec-additive-operators-static-semantics-isvalidsimpleassignmenttarget">12.7.2</a>, <a
+ href="#sec-bitwise-shift-operators-static-semantics-isvalidsimpleassignmenttarget">12.8.2</a>, <a
+ href="#sec-relational-operators-static-semantics-isvalidsimpleassignmenttarget">12.9.2</a>, <a
+ href="#sec-equality-operators-static-semantics-isvalidsimpleassignmenttarget">12.10.2</a>, <a
+ href="#sec-binary-bitwise-operators-static-semantics-isvalidsimpleassignmenttarget">12.11.2</a>, <a
+ href="#sec-conditional-operator-static-semantics-isvalidsimpleassignmenttarget">12.13.2</a>, <a
+ href="#sec-assignment-operators-static-semantics-isvalidsimpleassignmenttarget">12.14.3</a>, <a
+ href="#sec-comma-operator-static-semantics-isvalidsimpleassignmenttarget">12.15.2</a>.</p>
+
+ <p><span class="prod"><span class="nt">LogicalANDExpression</span> <span class="geq">:</span> <span
+ class="nt">LogicalANDExpression</span> <code class="t">&&</code> <span
+ class="nt">BitwiseORExpression</span></span></p>
+
+ <div class="gp prod"><span class="nt">LogicalORExpression</span> <span class="geq">:</span> <span class="nt">LogicalORExpression</span> <code class="t">||</code> <span class="nt">LogicalANDExpression</span></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-binary-logical-operators-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-12.12.3"><a href="#sec-binary-logical-operators-runtime-semantics-evaluation"
+ title="link to this section">12.12.3</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">LogicalANDExpression</span> <span class="geq">:</span> <span class="nt">LogicalANDExpression</span> <code class="t">&&</code> <span class="nt">BitwiseORExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>lref</i> be the result of evaluating <i>LogicalANDExpression</i>.</li>
+ <li>Let <i>lval</i> be <a href="#sec-getvalue">GetValue</a>(<i>lref</i>).</li>
+ <li>Let <i>lbool</i> be <a href="#sec-toboolean">ToBoolean</a>(<i>lval</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>lbool</i>).</li>
+ <li>If <i>lbool</i> is <b>false</b>, return <i>lval</i>.</li>
+ <li>Let <i>rref</i> be the result of evaluating <i>BitwiseORExpression</i>.</li>
+ <li>Return <a href="#sec-getvalue">GetValue</a>(<i>rref</i>).</li>
+ </ol>
+ <div class="gp prod"><span class="nt">LogicalORExpression</span> <span class="geq">:</span> <span class="nt">LogicalORExpression</span> <code class="t">||</code> <span class="nt">LogicalANDExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>lref</i> be the result of evaluating <i>LogicalORExpression</i>.</li>
+ <li>Let <i>lval</i> be <a href="#sec-getvalue">GetValue</a>(<i>lref</i>).</li>
+ <li>Let <i>lbool</i> be <a href="#sec-toboolean">ToBoolean</a>(<i>lval</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>lbool</i>).</li>
+ <li>If <i>lbool</i> is <b>true</b>, return <i>lval</i>.</li>
+ <li>Let <i>rref</i> be the result of evaluating <i>LogicalANDExpression</i>.</li>
+ <li>Return <a href="#sec-getvalue">GetValue</a>(<i>rref</i>).</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-conditional-operator">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.13"><a href="#sec-conditional-operator" title="link to this section">12.13</a></span>
+ Conditional Operator ( <code>? : )</code></h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ConditionalExpression</span><sub>[In, Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">LogicalORExpression</span><sub>[?In, ?Yield]</sub></div>
+ <div class="rhs"><span class="nt">LogicalORExpression</span><sub>[?In,?Yield]</sub> <code class="t">?</code> <span class="nt">AssignmentExpression</span><sub>[In, ?Yield]</sub> <code class="t">:</code> <span class="nt">AssignmentExpression</span><sub>[?In, ?Yield]</sub></div>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The grammar for a <i>ConditionalExpression</i> in ECMAScript is slightly different from
+ that in C and Java, which each allow the second subexpression to be an <i>Expression</i> but restrict the third expression
+ to be a <i>ConditionalExpression</i>. The motivation for this difference in ECMAScript is to allow an assignment
+ expression to be governed by either arm of a conditional and to eliminate the confusing and fairly useless case of a comma
+ expression as the centre expression.</p>
+ </div>
+ </div>
+
+ <section id="sec-conditional-operator-static-semantics-isfunctiondefinition">
+ <h1><span class="secnum" id="sec-12.13.1"><a href="#sec-conditional-operator-static-semantics-isfunctiondefinition"
+ title="link to this section">12.13.1</a></span> Static Semantics: IsFunctionDefinition</h1>
+
+ <p>See also: <a href="#sec-semantics-static-semantics-isfunctiondefinition">12.2.0.2</a>, <a
+ href="#sec-grouping-operator-static-semantics-isfunctiondefinition">12.2.10.2</a>, <a
+ href="#sec-static-semantics-static-semantics-isfunctiondefinition">12.3.1.2</a>, <a
+ href="#sec-postfix-expressions-static-semantics-isfunctiondefinition">12.4.2</a>, <a
+ href="#sec-unary-operators-static-semantics-isfunctiondefinition">12.5.2</a>, <a
+ href="#sec-multiplicative-operators-static-semantics-isfunctiondefinition">12.6.1</a>, <a
+ href="#sec-additive-operators-static-semantics-isfunctiondefinition">12.7.1</a>, <a
+ href="#sec-bitwise-shift-operators-static-semantics-isfunctiondefinition">12.8.1</a>, <a
+ href="#sec-relational-operators-static-semantics-isfunctiondefinition">12.9.1</a>, <a
+ href="#sec-equality-operators-static-semantics-isfunctiondefinition">12.10.1</a>, <a
+ href="#sec-binary-bitwise-operators-static-semantics-isfunctiondefinition">12.11.1</a>, <a
+ href="#sec-binary-logical-operators-static-semantics-isfunctiondefinition">12.12.1</a>, <a
+ href="#sec-assignment-operators-static-semantics-isfunctiondefinition">12.14.2</a>, <a
+ href="#sec-comma-operator-static-semantics-isfunctiondefinition">12.15.1</a>, <a
+ href="#sec-function-definitions-static-semantics-isfunctiondefinition">14.1.11</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-isfunctiondefinition">14.4.8</a>, <a
+ href="#sec-class-definitions-static-semantics-isfunctiondefinition">14.5.8</a>.</p>
+
+ <div class="gp prod"><span class="nt">ConditionalExpression</span> <span class="geq">:</span> <span class="nt">LogicalORExpression</span> <code class="t">?</code> <span class="nt">AssignmentExpression</span> <code class="t">:</code> <span class="nt">AssignmentExpression</span></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-conditional-operator-static-semantics-isvalidsimpleassignmenttarget">
+ <h1><span class="secnum" id="sec-12.13.2"><a href="#sec-conditional-operator-static-semantics-isvalidsimpleassignmenttarget"
+ title="link to this section">12.13.2</a></span> Static Semantics: IsValidSimpleAssignmentTarget</h1>
+
+ <p>See also: <a href="#sec-semantics-static-semantics-isidentifierref">12.2.0.3</a>, <a
+ href="#sec-grouping-operator-static-semantics-isvalidsimpleassignmenttarget">12.2.10.3</a>, <a
+ href="#sec-static-semantics-static-semantics-isidentifierref">12.3.1.3</a>, <a
+ href="#sec-postfix-expressions-static-semantics-isvalidsimpleassignmenttarget">12.4.3</a>, <a
+ href="#sec-unary-operators-static-semantics-isvalidsimpleassignmenttarget">12.5.3</a>, <a
+ href="#sec-multiplicative-operators-static-semantics-isvalidsimpleassignmenttarget">12.6.2</a>, <a
+ href="#sec-additive-operators-static-semantics-isvalidsimpleassignmenttarget">12.7.2</a>, <a
+ href="#sec-bitwise-shift-operators-static-semantics-isvalidsimpleassignmenttarget">12.8.2</a>, <a
+ href="#sec-relational-operators-static-semantics-isvalidsimpleassignmenttarget">12.9.2</a>, <a
+ href="#sec-equality-operators-static-semantics-isvalidsimpleassignmenttarget">12.10.2</a>, <a
+ href="#sec-binary-bitwise-operators-static-semantics-isvalidsimpleassignmenttarget">12.11.2</a>, <a
+ href="#sec-binary-logical-operators-static-semantics-isvalidsimpleassignmenttarget">12.12.2</a>, <a
+ href="#sec-assignment-operators-static-semantics-isvalidsimpleassignmenttarget">12.14.3</a>, <a
+ href="#sec-comma-operator-static-semantics-isvalidsimpleassignmenttarget">12.15.2</a>.</p>
+
+ <div class="gp prod"><span class="nt">ConditionalExpression</span> <span class="geq">:</span> <span class="nt">LogicalORExpression</span> <code class="t">?</code> <span class="nt">AssignmentExpression</span> <code class="t">:</code> <span class="nt">AssignmentExpression</span></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-conditional-operator-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-12.13.3"><a href="#sec-conditional-operator-runtime-semantics-evaluation"
+ title="link to this section">12.13.3</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">ConditionalExpression</span> <span class="geq">:</span> <span class="nt">LogicalORExpression</span> <code class="t">?</code> <span class="nt">AssignmentExpression</span> <code class="t">:</code> <span class="nt">AssignmentExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>lref</i> be the result of evaluating <i>LogicalORExpression</i>.</li>
+ <li>Let <i>lval</i> be <a href="#sec-toboolean">ToBoolean</a>(<a href="#sec-getvalue">GetValue</a>(<i>lref</i>)).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>lval</i>).</li>
+ <li>If <i>lval</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>trueRef</i> be the result of evaluating the first <i>AssignmentExpression</i>.</li>
+ <li>Return <a href="#sec-getvalue">GetValue</a>(<i>trueRef</i>).</li>
+ </ol>
+ </li>
+ <li>Else
+ <ol class="block">
+ <li>Let <i>falseRef</i> be the result of evaluating the second <i>AssignmentExpression</i>.</li>
+ <li>Return <a href="#sec-getvalue">GetValue</a>(<i>falseRef</i>).</li>
+ </ol>
+ </li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-assignment-operators">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.14"><a href="#sec-assignment-operators" title="link to this section">12.14</a></span>
+ Assignment Operators</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">AssignmentExpression</span><sub>[In, Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">ConditionalExpression</span><sub>[?In, ?Yield]</sub></div>
+ <div class="rhs"><span class="grhsannot">[+Yield]</span> <span class="nt">YieldExpression</span><sub>[?In]</sub></div>
+ <div class="rhs"><span class="nt">ArrowFunction</span><sub>[?In, ?Yield]</sub></div>
+ <div class="rhs"><span class="nt">LeftHandSideExpression</span><sub>[?Yield]</sub> <code class="t">=</code> <span class="nt">AssignmentExpression</span><sub>[?In, ?Yield]</sub></div>
+ <div class="rhs"><span class="nt">LeftHandSideExpression</span><sub>[?Yield]</sub> <span class="nt">AssignmentOperator</span> <span class="nt">AssignmentExpression</span><sub>[?In, ?Yield]</sub></div>
+ </div>
+
+ <div class="gp prod"><span class="nt">AssignmentOperator</span> <span class="geq">:</span> <span class="grhsmod">one of</span></div>
+
+ <figure>
+ <table class="lightweight-table">
+ <tr>
+ <td><code>*=</code></td>
+ <td><code>/=</code></td>
+ <td><code>%=</code></td>
+ <td><code>+=</code></td>
+ <td><code>-=</code></td>
+ <td><code><<=</code></td>
+ <td><code>>>=</code></td>
+ <td><code>>>>=</code></td>
+ <td><code>&=</code></td>
+ <td><code>^=</code></td>
+ <td><code>|=</code></td>
+ </tr>
+ </table>
+ </figure>
+ </div>
+
+ <section id="sec-assignment-operators-static-semantics-early-errors">
+ <h1><span class="secnum" id="sec-12.14.1"><a href="#sec-assignment-operators-static-semantics-early-errors"
+ title="link to this section">12.14.1</a></span> Static Semantics: Early Errors</h1>
+ <div class="gp prod"><span class="nt">AssignmentExpression</span> <span class="geq">:</span> <span class="nt">LeftHandSideExpression</span> <code class="t">=</code> <span class="nt">AssignmentExpression</span></div>
+ <ul>
+ <li>
+ <p>It is a Syntax Error if <span class="nt">LeftHandSideExpression</span> is either an <span
+ class="nt">ObjectLiteral</span> or an <span class="nt">ArrayLiteral</span> and the lexical token sequence matched by
+ <span class="nt">LeftHandSideExpression</span> cannot be parsed with no tokens left over using <span
+ class="nt">AssignmentPattern</span> as the goal symbol.</p>
+ </li>
+
+ <li>
+ <p>If <span class="nt">LeftHandSideExpression</span> is either an <span class="nt">ObjectLiteral</span> or an <span
+ class="nt">ArrayLiteral</span> and if the lexical token sequence matched by <span
+ class="nt">LeftHandSideExpression</span> can be parsed with no tokens left over using <span
+ class="nt">AssignmentPattern</span> as the goal symbol then the following rules are not applied. Instead, the Early
+ Error rules for <span class="nt">AssignmentPattern</span> are used.</p>
+ </li>
+
+ <li>
+ <p>It is a Syntax Error if <span class="nt">LeftHandSideExpression</span> is an <span
+ class="nt">IdentifierReference</span> that can be statically determined to always resolve to a <a
+ href="#sec-declarative-environment-records">declarative environment record</a> binding and the resolved binding is an
+ immutable binding.</p>
+ </li>
+
+ <li>
+ <p>It is an early <a href="#sec-reference-specification-type">Reference</a> Error if <span
+ class="nt">LeftHandSideExpression</span> is neither an <span class="nt">ObjectLiteral</span> nor an <span
+ class="nt">ArrayLiteral</span> and <span style="font-family: Times New Roman">IsValidSimpleAssignmentTarget</span> of
+ <span class="nt">LeftHandSideExpression</span> is <span class="value">false</span>.</p>
+ </li>
+ </ul>
+ <div class="gp prod"><span class="nt">AssignmentExpression</span> <span class="geq">:</span> <span class="nt">LeftHandSideExpression</span> <span class="nt">AssignmentOperator</span> <span class="nt">AssignmentExpression</span></div>
+ <ul>
+ <li>
+ <p>It is a Syntax Error if the <span class="nt">LeftHandSideExpression</span> is an <span
+ class="nt">IdentifierReference</span> that can be statically determined to always resolve to a <a
+ href="#sec-declarative-environment-records">declarative environment record</a> binding and the resolved binding is an
+ immutable binding.</p>
+ </li>
+
+ <li>
+ <p>It is an early <a href="#sec-reference-specification-type">Reference</a> Error if <span style="font-family: Times New
+ Roman">IsValidSimpleAssignmentTarget</span> of <span class="nt">LeftHandSideExpression</span> is <span
+ class="value">false</span>.</p>
+ </li>
+ </ul>
+ </section>
+
+ <section id="sec-assignment-operators-static-semantics-isfunctiondefinition">
+ <h1><span class="secnum" id="sec-12.14.2"><a href="#sec-assignment-operators-static-semantics-isfunctiondefinition"
+ title="link to this section">12.14.2</a></span> Static Semantics: IsFunctionDefinition</h1>
+
+ <p>See also: <a href="#sec-semantics-static-semantics-isfunctiondefinition">12.2.0.2</a>, <a
+ href="#sec-grouping-operator-static-semantics-isfunctiondefinition">12.2.10.2</a>, <a
+ href="#sec-static-semantics-static-semantics-isfunctiondefinition">12.3.1.2</a>, <a
+ href="#sec-postfix-expressions-static-semantics-isfunctiondefinition">12.4.2</a>, <a
+ href="#sec-unary-operators-static-semantics-isfunctiondefinition">12.5.2</a>, <a
+ href="#sec-multiplicative-operators-static-semantics-isfunctiondefinition">12.6.1</a>, <a
+ href="#sec-additive-operators-static-semantics-isfunctiondefinition">12.7.1</a>, <a
+ href="#sec-bitwise-shift-operators-static-semantics-isfunctiondefinition">12.8.1</a>, <a
+ href="#sec-relational-operators-static-semantics-isfunctiondefinition">12.9.1</a>, <a
+ href="#sec-equality-operators-static-semantics-isfunctiondefinition">12.10.1</a>, <a
+ href="#sec-binary-bitwise-operators-static-semantics-isfunctiondefinition">12.11.1</a>, <a
+ href="#sec-binary-logical-operators-static-semantics-isfunctiondefinition">12.12.1</a>, <a
+ href="#sec-conditional-operator-static-semantics-isfunctiondefinition">12.13.1</a>, <a
+ href="#sec-comma-operator-static-semantics-isfunctiondefinition">12.15.1</a>, <a
+ href="#sec-function-definitions-static-semantics-isfunctiondefinition">14.1.11</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-isfunctiondefinition">14.4.8</a>, <a
+ href="#sec-class-definitions-static-semantics-isfunctiondefinition">14.5.8</a>.</p>
+
+ <div class="gp prod"><span class="nt">AssignmentExpression</span> <span class="geq">:</span> <span class="nt">ArrowFunction</span></div>
+ <ol class="proc">
+ <li>Return <b>true</b>.</li>
+ </ol>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">AssignmentExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">YieldExpression</span></div>
+ <div class="rhs"><span class="nt">LeftHandSideExpression</span> <code class="t">=</code> <span class="nt">AssignmentExpression</span></div>
+ <div class="rhs"><span class="nt">LeftHandSideExpression</span> <span class="nt">AssignmentOperator</span> <span class="nt">AssignmentExpression</span></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-assignment-operators-static-semantics-isvalidsimpleassignmenttarget">
+ <h1><span class="secnum" id="sec-12.14.3"><a href="#sec-assignment-operators-static-semantics-isvalidsimpleassignmenttarget"
+ title="link to this section">12.14.3</a></span> Static Semantics: IsValidSimpleAssignmentTarget</h1>
+
+ <p>See also: <a href="#sec-semantics-static-semantics-isidentifierref">12.2.0.3</a>, <a
+ href="#sec-grouping-operator-static-semantics-isvalidsimpleassignmenttarget">12.2.10.3</a>, <a
+ href="#sec-static-semantics-static-semantics-isidentifierref">12.3.1.3</a>, <a
+ href="#sec-postfix-expressions-static-semantics-isvalidsimpleassignmenttarget">12.4.3</a>, <a
+ href="#sec-unary-operators-static-semantics-isvalidsimpleassignmenttarget">12.5.3</a>, <a
+ href="#sec-multiplicative-operators-static-semantics-isvalidsimpleassignmenttarget">12.6.2</a>, <a
+ href="#sec-additive-operators-static-semantics-isvalidsimpleassignmenttarget">12.7.2</a>, <a
+ href="#sec-bitwise-shift-operators-static-semantics-isvalidsimpleassignmenttarget">12.8.2</a>, <a
+ href="#sec-relational-operators-static-semantics-isvalidsimpleassignmenttarget">12.9.2</a>, <a
+ href="#sec-equality-operators-static-semantics-isvalidsimpleassignmenttarget">12.10.2</a>, <a
+ href="#sec-binary-bitwise-operators-static-semantics-isvalidsimpleassignmenttarget">12.11.2</a>, <a
+ href="#sec-binary-logical-operators-static-semantics-isvalidsimpleassignmenttarget">12.12.2</a>, <a
+ href="#sec-conditional-operator-static-semantics-isvalidsimpleassignmenttarget">12.13.2</a>, <a
+ href="#sec-comma-operator-static-semantics-isvalidsimpleassignmenttarget">12.15.2</a>.</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">AssignmentExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">YieldExpression</span></div>
+ <div class="rhs"><span class="nt">ArrowFunction</span></div>
+ <div class="rhs"><span class="nt">LeftHandSideExpression</span> <code class="t">=</code> <span class="nt">AssignmentExpression</span></div>
+ <div class="rhs"><span class="nt">LeftHandSideExpression</span> <span class="nt">AssignmentOperator</span> <span class="nt">AssignmentExpression</span></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-assignment-operators-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-12.14.4"><a href="#sec-assignment-operators-runtime-semantics-evaluation"
+ title="link to this section">12.14.4</a></span> Runtime Semantics: Evaluation</h1>
+
+ <p><span class="nt">AssignmentExpression</span><sub>[In, Yield]</sub> <b>:</b> <span
+ class="nt">LeftHandSideExpression</span><sub>[?Yield]</sub> <code>=</code> <span
+ class="nt">AssignmentExpression</span><sub>[?In, ?Yield]</sub></p>
+
+ <ol class="proc">
+ <li>If <i>LeftHandSideExpression</i> is neither an <i>ObjectLiteral</i> nor an <i>ArrayLiteral</i> then
+ <ol class="block">
+ <li>Let <i>lref</i> be the result of evaluating <i>LeftHandSideExpression</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>lref</i>).</li>
+ <li>Let <i>rref</i> be the result of evaluating <i>AssignmentExpression</i>.</li>
+ <li>Let <i>rval</i> be <a href="#sec-getvalue">GetValue</a>(<i>rref</i>).</li>
+ <li>If <a href="#sec-isanonymousfunctiondefinition">IsAnonymousFunctionDefinition</a>(<i>AssignmentExpression)</i> and
+ IsIdentifierRef of <i>LeftHandSideExpression</i> are both <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>hasNameProperty</i> be <a href="#sec-hasownproperty">HasOwnProperty</a>(<i>rval</i>,
+ <code>"name"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>hasNameProperty</i>).</li>
+ <li>If <i>hasNameProperty</i> is <b>false</b>, then
+ <ol class="block">
+ <li><a href="#sec-setfunctionname">SetFunctionName</a>(<i>rval</i>, <a
+ href="#sec-reference-specification-type">GetReferencedName</a>(<i>lref</i>)).</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Let <i>status</i> be <a href="#sec-putvalue">PutValue</a>(<i>lref</i>, <i>rval</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Return <i>rval</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>AssignmentPattern</i> be the parse of the source code corresponding to <i>LeftHandSideExpression</i> using
+ <i>AssignmentPattern</i><sub>[?Yield]</sub> as the goal symbol.</li>
+ <li>Let <i>rref</i> be the result of evaluating <i>AssignmentExpression</i>.</li>
+ <li>Let <i>rval</i> be <a href="#sec-getvalue">GetValue</a>(<i>rref</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>rval</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>rval</i>) is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>Let <i>status</i> be the result of performing DestructuringAssignmentEvaluation of <i>AssignmentPattern</i> using
+ <i>rval</i> as the argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Return <i>rval</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">AssignmentExpression</span> <span class="geq">:</span> <span class="nt">LeftHandSideExpression</span> <span class="nt">AssignmentOperator</span> <span class="nt">AssignmentExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>lref</i> be the result of evaluating <i>LeftHandSideExpression</i>.</li>
+ <li>Let <i>lval</i> be <a href="#sec-getvalue">GetValue</a>(<i>lref</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>lval</i>).</li>
+ <li>Let <i>rref</i> be the result of evaluating <i>AssignmentExpression</i>.</li>
+ <li>Let <i>rval</i> be <a href="#sec-getvalue">GetValue</a>(<i>rref</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>rval</i>).</li>
+ <li>Let <i>operator</i> be the <code>@</code> where <i>AssignmentOperator</i> is <code>@=</code></li>
+ <li>Let <i>r</i> be the result of applying operator @ to <i>lval</i> and <i>rval</i>.</li>
+ <li>Let <i>status</i> be <a href="#sec-putvalue">PutValue</a>(<i>lref</i>, <i>r</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Return <i>r</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> When an assignment occurs within <a href="#sec-strict-mode-code">strict mode code</a>, it
+ is an runtime error if <i>lref</i> in step 1.f.of the first algorithm or step 9 of the second algorithm it is an
+ unresolvable reference. If it is, a <b>ReferenceError</b> exception is thrown. The <i>LeftHandSide</i> also may not be a
+ reference to a data property with the attribute value {[[Writable]]:<b>false</b>}, to an accessor property with the
+ attribute value {[[Set]]:<b>undefined</b>}, nor to a non-existent property of an object for which the <a
+ href="#sec-isextensible-o">IsExtensible</a> predicate returns the value <b>false</b>. In these cases a <b>TypeError</b>
+ exception is thrown.</p>
+ </div>
+ </section>
+
+ <section id="sec-destructuring-assignment">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.14.5"><a href="#sec-destructuring-assignment"
+ title="link to this section">12.14.5</a></span> Destructuring Assignment</h1>
+ <h2>Supplemental Syntax</h2>
+
+ <p>In certain circumstances when processing the production <span class="prod"><span class="nt">AssignmentExpression</span>
+ <span class="geq">:</span> <span class="nt">LeftHandSideExpression</span> <code class="t">=</code> <span
+ class="nt">AssignmentExpression</span></span> the following grammar is used to refine the interpretation of <span
+ class="nt">LeftHandSideExpression</span>.</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">AssignmentPattern</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">ObjectAssignmentPattern</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="nt">ArrayAssignmentPattern</span><sub>[?Yield]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ObjectAssignmentPattern</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">{</code> <code class="t">}</code></div>
+ <div class="rhs"><code class="t">{</code> <span class="nt">AssignmentPropertyList</span><sub>[?Yield]</sub> <code class="t">}</code></div>
+ <div class="rhs"><code class="t">{</code> <span class="nt">AssignmentPropertyList</span><sub>[?Yield]</sub> <code class="t">,</code> <code class="t">}</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ArrayAssignmentPattern</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">[</code> <span class="nt">Elision</span><sub>opt</sub> <span class="nt">AssignmentRestElement</span><sub>[?Yield]</sub><sub>opt</sub> <code class="t">]</code></div>
+ <div class="rhs"><code class="t">[</code> <span class="nt">AssignmentElementList</span><sub>[?Yield]</sub> <code class="t">]</code></div>
+ <div class="rhs"><code class="t">[</code> <span class="nt">AssignmentElementList</span><sub>[?Yield]</sub> <code class="t">,</code> <span class="nt">Elision</span><sub>opt</sub> <span class="nt">AssignmentRestElement</span><sub>[?Yield]</sub><sub>opt</sub> <code class="t">]</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">AssignmentPropertyList</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">AssignmentProperty</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="nt">AssignmentPropertyList</span><sub>[?Yield]</sub> <code class="t">,</code> <span class="nt">AssignmentProperty</span><sub>[?Yield]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">AssignmentElementList</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">AssignmentElisionElement</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="nt">AssignmentElementList</span><sub>[?Yield]</sub> <code class="t">,</code> <span class="nt">AssignmentElisionElement</span><sub>[?Yield]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">AssignmentElisionElement</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">Elision</span><sub>opt</sub> <span class="nt">AssignmentElement</span><sub>[?Yield]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">AssignmentProperty</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">IdentifierReference</span><sub>[?Yield]</sub> <span class="nt">Initializer</span><sub>[In,?Yield]</sub><sub>opt</sub></div>
+ <div class="rhs"><span class="nt">PropertyName</span> <code class="t">:</code> <span class="nt">AssignmentElement</span><sub>[?Yield]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">AssignmentElement</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">DestructuringAssignmentTarget</span><sub>[?Yield]</sub> <span class="nt">Initializer</span><sub>[In,?Yield]</sub><sub>opt</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">AssignmentRestElement</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">...</code> <span class="nt">DestructuringAssignmentTarget</span><sub>[?Yield]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">DestructuringAssignmentTarget</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">LeftHandSideExpression</span><sub>[?Yield]</sub></div>
+ </div>
+ </div>
+
+ <section id="sec-destructuring-assignment-static-semantics-early-errors">
+ <h1><span class="secnum" id="sec-12.14.5.1"><a href="#sec-destructuring-assignment-static-semantics-early-errors"
+ title="link to this section">12.14.5.1</a></span> Static Semantics: Early Errors</h1>
+ <div class="gp prod"><span class="nt">AssignmentProperty</span> <span class="geq">:</span> <span class="nt">IdentifierReference</span> <span class="nt">Initializer</span><sub>opt</sub></div>
+ <ul>
+ <li>
+ <p>It is a Syntax Error if IsValidSimpleAssignment of <span class="nt">IdentifierReference</span> is <span
+ class="value">false</span>.</p>
+ </li>
+
+ <li>
+ <p>It is a Syntax Error if <span class="nt">IdentifierReference</span> statically resolves to a immutable
+ binding<i>.</i></p>
+ </li>
+ </ul>
+ <div class="gp prod"><span class="nt">AssignmentRestElement</span> <span class="geq">:</span> <code class="t">...</code> <span class="nt">DestructuringAssignmentTarget</span></div>
+ <ul>
+ <li>
+ <p>It is a Syntax Error if <span style="font-family: Times New Roman">IsValidSimpleAssignmentTarget</span> of <span
+ class="nt">DestructuringAssignmentTarget</span> is <span style="font-family: Times New
+ Roman"><b>false</b><i>.</i></span></p>
+ </li>
+ </ul>
+ <div class="gp prod"><span class="nt">DestructuringAssignmentTarget</span> <span class="geq">:</span> <span class="nt">LeftHandSideExpression</span></div>
+ <ul>
+ <li>
+ <p>It is a Syntax Error if <span class="nt">LeftHandSideExpression</span> is either an <span
+ class="nt">ObjectLiteral</span> or an <span class="nt">ArrayLiteral</span> and if the lexical token sequence matched
+ by <span class="nt">LeftHandSideExpression</span> cannot be parsed with no tokens left over using <span
+ class="nt">AssignmentPattern</span> as the goal symbol.</p>
+ </li>
+
+ <li>
+ <p>It is a Syntax Error if <span class="nt">LeftHandSideExpression</span> is neither an <span
+ class="nt">ObjectLiteral</span> nor an <span class="nt">ArrayLiteral</span> and <span style="font-family: Times New
+ Roman">IsValidSimpleAssignmentTarget</span>(<span class="nt">LeftHandSideExpression</span>) is <span
+ class="value">false</span>.</p>
+ </li>
+
+ <li>
+ <p>It is a Syntax Error if <span class="nt">LeftHandSideExpression</span> is an <span
+ class="nt">IdentifierReference</span> that can be statically determined to always resolve to a <a
+ href="#sec-declarative-environment-records">declarative environment record</a> binding and the resolved binding is an
+ immutable binding.</p>
+ </li>
+
+ <li>
+ <p>It is a Syntax Error if <span class="nt">LeftHandSideExpression</span> is <span
+ class="prod"><span class="nt">CoverParenthesizedExpressionAndArrowParameterList</span> <span class="geq">:</span>
+ <code class="t">(</code> <span class="nt">Expression</span> <code class="t">)</code></span> and <span
+ class="nt">Expression</span> derives a production that would produce a Syntax Error according to these rules if that
+ production is substituted for <span class="nt">LeftHandSideExpression</span>. This rule is recursively applied.</p>
+ </li>
+ </ul>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The last rule means that the other rules are applied even if multiple levels of nested
+ parentheses surround <i>Expression</i>.</p>
+ </div>
+ </section>
+
+ <section id="sec-runtime-semantics-destructuringassignmentevaluation">
+ <h1><span class="secnum" id="sec-12.14.5.2"><a href="#sec-runtime-semantics-destructuringassignmentevaluation"
+ title="link to this section">12.14.5.2</a></span> Runtime Semantics: DestructuringAssignmentEvaluation</h1>
+
+ <p>with parameter <var>obj</var></p>
+
+ <div class="gp prod"><span class="nt">ObjectAssignmentPattern</span> <span class="geq">:</span> <code class="t">{</code> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<span style="font-family:
+ sans-serif">empty</span>).</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ArrayAssignmentPattern</span> <span class="geq">:</span> <code class="t">[</code> <code class="t">]</code></div>
+ <ol class="proc">
+ <li>Let <i>iterator</i> be <a href="#sec-getiterator">GetIterator</a>(<i>obj</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>iterator</i>).</li>
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<span style="font-family:
+ sans-serif">empty</span>).</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ArrayAssignmentPattern</span> <span class="geq">:</span> <code class="t">[</code> <span class="nt">Elision</span> <code class="t">]</code></div>
+ <ol class="proc">
+ <li>Let <i>iterator</i> be <a href="#sec-getiterator">GetIterator</a>(<i>obj</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>iterator</i>).</li>
+ <li>Return the result of performing IteratorDestructuringAssignmentEvaluation of <i>Elision</i> with <i>iterator</i> as
+ the argument.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ArrayAssignmentPattern</span> <span class="geq">:</span> <code class="t">[</code> <span class="nt">Elision</span><sub>opt</sub> <span class="nt">AssignmentRestElement</span> <code class="t">]</code></div>
+ <ol class="proc">
+ <li>Let <i>iterator</i> be <a href="#sec-getiterator">GetIterator</a>(<i>obj</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>iterator</i>).</li>
+ <li>If <i>Elision</i> is present, then
+ <ol class="block">
+ <li>Let <i>status</i> be the result of performing IteratorDestructuringAssignmentEvaluation of <i>Elision</i> with
+ <i>iterator</i> as the argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ </ol>
+ </li>
+ <li>Return the result of performing IteratorDestructuringAssignmentEvaluation of <i>AssignmentRestElement</i> with
+ <i>iterator</i> as the argument.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ArrayAssignmentPattern</span> <span class="geq">:</span> <code class="t">[</code> <span class="nt">AssignmentElementList</span> <code class="t">]</code></div>
+ <ol class="proc">
+ <li>Let <i>iterator</i> be <a href="#sec-getiterator">GetIterator</a>(<i>obj</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>iterator</i>).</li>
+ <li>Return the result of performing IteratorDestructuringAssignmentEvaluation of <i>AssignmentElementList</i> using
+ <i>iterator</i> as the argument.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ArrayAssignmentPattern</span> <span class="geq">:</span> <code class="t">[</code> <span class="nt">AssignmentElementList</span> <code class="t">,</code> <span class="nt">Elision</span><sub>opt</sub> <span class="nt">AssignmentRestElement</span><sub>opt</sub> <code class="t">]</code></div>
+ <ol class="proc">
+ <li>Let <i>iterator</i> be <a href="#sec-getiterator">GetIterator</a>(<i>obj</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>iterator</i>).</li>
+ <li>Let <i>status</i> be the result of performing IteratorDestructuringAssignmentEvaluation of
+ <i>AssignmentElementList</i> using <i>iterator</i> as the argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>If <i>Elision</i> is present, then
+ <ol class="block">
+ <li>Let <i>status</i> be the result of performing IteratorDestructuringAssignmentEvaluation of <i>Elision</i> with
+ <i>iterator</i> as the argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ </ol>
+ </li>
+ <li>If <i>AssignmentRestElement</i> is not present, then return <i>status</i>.</li>
+ <li>Return the result of performing IteratorDestructuringAssignmentEvaluation of <i>AssignmentRestElement</i> with
+ <i>iterator</i> as the argument.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">AssignmentPropertyList</span> <span class="geq">:</span> <span class="nt">AssignmentPropertyList</span> <code class="t">,</code> <span class="nt">AssignmentProperty</span></div>
+ <ol class="proc">
+ <li>Let <i>status</i> be the result of performing DestructuringAssignmentEvaluation for <i>AssignmentPropertyList</i>
+ using <i>obj</i> as the argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Return the result of performing DestructuringAssignmentEvaluation for <i>AssignmentProperty</i> using <i>obj</i> as
+ the argument.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">AssignmentProperty</span> <span class="geq">:</span> <span class="nt">IdentifierReference</span> <span class="nt">Initializer</span><sub>opt</sub></div>
+ <ol class="proc">
+ <li>Let <i>P</i> be StringValue of <i>IdentifierReference</i>.</li>
+ <li>Let <i>v</i> be <a href="#sec-get-o-p">Get</a>(<i>obj</i>, <i>P</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>v</i>).</li>
+ <li>If <i>Initializer</i><sub>opt</sub> is present and <i>v</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>defaultValue</i> be the result of evaluating <i>Initializer</i>.</li>
+ <li>Let <i>v</i> be <a href="#sec-getvalue">GetValue</a>(<i>defaultValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>v</i>).</li>
+ </ol>
+ </li>
+ <li>Let <i>lref</i> be <a href="#sec-resolvebinding">ResolveBinding</a>(<i>P)</i>.</li>
+ <li>Return <a href="#sec-putvalue">PutValue</a>(<i>lref</i>,<i>v</i>).</li>
+ </ol>
+ <div class="gp prod"><span class="nt">AssignmentProperty</span> <span class="geq">:</span> <span class="nt">PropertyName</span> <code class="t">:</code> <span class="nt">AssignmentElement</span></div>
+ <ol class="proc">
+ <li>Let <i>name</i> be the result of evaluating <i>PropertyName</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>name</i>).</li>
+ <li>Return the result of performing KeyedDestructuringAssignmentEvaluation of <i>AssignmentElement</i> with <i>obj</i>
+ and <i>name</i> as the arguments.</li>
+ </ol>
+ </section>
+
+ <section id="sec-runtime-semantics-iteratordestructuringassignmentevaluation">
+ <h1><span class="secnum" id="sec-12.14.5.3"><a href="#sec-runtime-semantics-iteratordestructuringassignmentevaluation"
+ title="link to this section">12.14.5.3</a></span> Runtime Semantics: IteratorDestructuringAssignmentEvaluation</h1>
+
+ <p>with parameters <var>iterator</var></p>
+
+ <div class="gp prod"><span class="nt">AssignmentElementList</span> <span class="geq">:</span> <span class="nt">AssignmentElisionElement</span></div>
+ <ol class="proc">
+ <li>Return the result of performing IteratorDestructuringAssignmentEvaluation of <i>AssignmentElisionElement</i> using
+ <i>iterator</i> as the <i>argument</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">AssignmentElementList</span> <span class="geq">:</span> <span class="nt">AssignmentElementList</span> <code class="t">,</code> <span class="nt">AssignmentElisionElement</span></div>
+ <ol class="proc">
+ <li>Let <i>status</i> be the result of performing IteratorDestructuringAssignmentEvaluation of
+ <i>AssignmentElementList</i> using <i>iterator</i> as the <i>argument.</i></li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Return the result of performing IteratorDestructuringAssignmentEvaluation of <i>AssignmentElisionElement</i> using
+ <i>iterator</i> as the <i>argument</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">AssignmentElisionElement</span> <span class="geq">:</span> <span class="nt">AssignmentElement</span></div>
+ <ol class="proc">
+ <li><i>R</i>eturn the result of performing IteratorDestructuringAssignmentEvaluation of <i>AssignmentElement</i> with
+ <i>iterator</i> as the argument.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">AssignmentElisionElement</span> <span class="geq">:</span> <span class="nt">Elision</span> <span class="nt">AssignmentElement</span></div>
+ <ol class="proc">
+ <li>Let <i>status</i> be the result of performing IteratorDestructuringAssignmentEvaluation of <i>Elision</i> with
+ <i>iterator</i> as the argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Return the result of performing IteratorDestructuringAssignmentEvaluation of <i>AssignmentElement</i> with
+ <i>iterator</i> as the argument.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">Elision</span> <span class="geq">:</span> <code class="t">,</code></div>
+ <ol class="proc">
+ <li>Return <a href="#sec-iteratorstep">IteratorStep</a>(<i>iterator</i>).</li>
+ </ol>
+ <div class="gp prod"><span class="nt">Elision</span> <span class="geq">:</span> <span class="nt">Elision</span> <code class="t">,</code></div>
+ <ol class="proc">
+ <li>Let <i>status</i> be the result of performing IteratorDestructuringAssignmentEvaluation of <i>Elision</i> with
+ <i>iterator</i> as the argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Return <a href="#sec-iteratorstep">IteratorStep</a>(<i>iterator</i>).</li>
+ </ol>
+
+ <p><span class="nt">AssignmentElement</span><sub>[Yield]</sub> <b>:</b> <span
+ class="nt">DestructuringAssignmentTarget</span> <span class="nt">Initializer</span><sub>opt</sub></p>
+
+ <ol class="proc">
+ <li>If <i>DestructuringAssignmentTarget</i> is neither an <i>ObjectLiteral</i> nor an <i>ArrayLiteral</i> then
+ <ol class="block">
+ <li>Let <i>lref</i> be the result of evaluating <i>DestructuringAssignmentTarget</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>lref</i>).</li>
+ </ol>
+ </li>
+ <li>Let <i>next</i> be <a href="#sec-iteratorstep">IteratorStep</a>(<i>iterator</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>next</i>).</li>
+ <li>If <i>next</i> is <b>false</b>, then let <i>v</i> be <b>undefined</b></li>
+ <li>Else
+ <ol class="block">
+ <li>Let <i>v</i> be <a href="#sec-iteratorvalue">IteratorValue</a>(<i>next</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>v</i>).</li>
+ </ol>
+ </li>
+ <li>If <i>Initializer</i> is present and <i>v</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>defaultValue</i> be the result of evaluating <i>Initializer</i>.</li>
+ <li>Let <i>v</i> be <a href="#sec-getvalue">GetValue</a>(<i>defaultValue</i>)</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>v</i>).</li>
+ </ol>
+ </li>
+ <li>If <i>DestructuringAssignmentTarget</i> is an <i>ObjectLiteral or an ArrayLiteral</i> then
+ <ol class="block">
+ <li>Let <i>nestedAssignmentPattern</i> be the parse of the source code corresponding to
+ <i>DestructuringAssignmentTarget</i> using either <i>AssignmentPattern</i> or
+ <i>AssignmentPattern</i><sub>[Yield]</sub> as the goal symbol depending upon whether this
+ <i>AssignmentElement</i> has the <span style="font-family: sans-serif"><sub>Yield</sub></span> parameter.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>v</i>) is not Object, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>Return the result of performing DestructuringAssignmentEvaluation of <i>nestedAssignmentPattern</i> with
+ <i>v</i> as the argument.</li>
+ </ol>
+ </li>
+ <li>Return <a href="#sec-putvalue">PutValue</a>(<i>lref</i>,<i>v</i>).</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Left to right evaluation order is maintained by evaluating a
+ <i>DestructuringAssignmentTarget</i> that is not a destructuring pattern prior to accessing the iterator or evaluating
+ the <i>Initializer</i>.</p>
+ </div>
+
+ <div class="gp prod"><span class="nt">AssignmentRestElement</span> <span class="geq">:</span> <code class="t">...</code> <span class="nt">DestructuringAssignmentTarget</span></div>
+ <ol class="proc">
+ <li>Let <i>lref</i> be the result of evaluating <i>DestructuringAssignmentTarget</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>lref</i>).</li>
+ <li>Let <i>A</i> be <a href="#sec-arraycreate">ArrayCreate</a>(0).</li>
+ <li>Let <i>n</i>=0;</li>
+ <li>Repeat
+ <ol class="block">
+ <li>Let <i>next</i> be <a href="#sec-iteratorstep">IteratorStep</a>(<i>iterator</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>next</i>).</li>
+ <li>If <i>next</i> is <b>false</b>, then
+ <ol class="block">
+ <li>Return <a href="#sec-putvalue">PutValue</a>(<i>lref</i>, <i>A</i>).</li>
+ </ol>
+ </li>
+ <li>Let <i>nextValue</i> be <a href="#sec-iteratorvalue">IteratorValue</a>(<i>next</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>nextValue</i>).</li>
+ <li>Let <i>defineStatus</i> be <a href="#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a>(<i>A</i>, <a
+ href="#sec-tostring">ToString</a>(<a href="#sec-touint32">ToUint32</a>(<i>n)</i>), <i>nextValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>defineStatus</i>).</li>
+ <li>Increment <i>n</i> by 1.</li>
+ </ol>
+ </li>
+ </ol>
+ </section>
+
+ <section id="sec-runtime-semantics-keyeddestructuringassignmentevaluation">
+ <h1><span class="secnum" id="sec-12.14.5.4"><a href="#sec-runtime-semantics-keyeddestructuringassignmentevaluation"
+ title="link to this section">12.14.5.4</a></span> Runtime Semantics: KeyedDestructuringAssignmentEvaluation</h1>
+
+ <p>with parameters <var>obj</var> and <var>propertyName</var></p>
+
+ <p><span class="nt">AssignmentElement</span> <span style="font-family: Times New Roman"><sub><i>[Yield]</i></sub></span>
+ <b>:</b> <span class="nt">DestructuringAssignmentTarget</span> <span class="nt">Initializer</span><sub>opt</sub></p>
+
+ <ol class="proc">
+ <li>Let <i>v</i> be <a href="#sec-get-o-p">Get</a>(<i>obj</i>, <i>propertyName</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>v</i>).</li>
+ <li>If <i>Initializer</i> is present and <i>v</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>defaultValue</i> be the result of evaluating <i>Initializer</i>.</li>
+ <li>Let <i>v</i> be <a href="#sec-getvalue">GetValue</a>(<i>defaultValue</i>)</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>v</i>).</li>
+ </ol>
+ </li>
+ <li>If <i>DestructuringAssignmentTarget</i> is an <i>ObjectLiteral or an ArrayLiteral</i> then
+ <ol class="block">
+ <li>Let <i>AssignmentPattern</i> be the parse of the source code corresponding to
+ <i>DestructuringAssignmentTarget</i> using either <i>AssignmentPattern</i> or
+ <i>AssignmentPattern</i><sub>[Yield]</sub> as the goal symbol depending upon whether this
+ <i>AssignmentElement</i> has the <span style="font-family: sans-serif"><sub>Yield</sub></span> parameter.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>v</i>) is not Object, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>Return the result of performing DestructuringAssignmentEvaluation of <i>AssignmentPattern</i> with <i>v</i> as
+ the argument.</li>
+ </ol>
+ </li>
+ <li>Let <i>lref</i> be the result of evaluating <i>DestructuringAssignmentTarget</i>.</li>
+ <li>Return <a href="#sec-putvalue">PutValue</a>(<i>lref</i>,<i>v</i>).</li>
+ </ol>
+ </section>
+ </section>
+ </section>
+
+ <section id="sec-comma-operator">
+ <div class="front">
+ <h1><span class="secnum" id="sec-12.15"><a href="#sec-comma-operator" title="link to this section">12.15</a></span> Comma
+ Operator ( <code>, )</code></h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">Expression</span><sub>[In, Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">AssignmentExpression</span><sub>[?In, ?Yield]</sub></div>
+ <div class="rhs"><span class="nt">Expression</span><sub>[?In, ?Yield]</sub> <code class="t">,</code> <span class="nt">AssignmentExpression</span><sub>[?In, ?Yield]</sub></div>
+ </div>
+ </div>
+
+ <section id="sec-comma-operator-static-semantics-isfunctiondefinition">
+ <h1><span class="secnum" id="sec-12.15.1"><a href="#sec-comma-operator-static-semantics-isfunctiondefinition"
+ title="link to this section">12.15.1</a></span> Static Semantics: IsFunctionDefinition</h1>
+
+ <p>See also: <a href="#sec-semantics-static-semantics-isfunctiondefinition">12.2.0.2</a>, <a
+ href="#sec-grouping-operator-static-semantics-isfunctiondefinition">12.2.10.2</a>, <a
+ href="#sec-static-semantics-static-semantics-isfunctiondefinition">12.3.1.2</a>, <a
+ href="#sec-postfix-expressions-static-semantics-isfunctiondefinition">12.4.2</a>, <a
+ href="#sec-unary-operators-static-semantics-isfunctiondefinition">12.5.2</a>, <a
+ href="#sec-multiplicative-operators-static-semantics-isfunctiondefinition">12.6.1</a>, <a
+ href="#sec-additive-operators-static-semantics-isfunctiondefinition">12.7.1</a>, <a
+ href="#sec-bitwise-shift-operators-static-semantics-isfunctiondefinition">12.8.1</a>, <a
+ href="#sec-relational-operators-static-semantics-isfunctiondefinition">12.9.1</a>, <a
+ href="#sec-equality-operators-static-semantics-isfunctiondefinition">12.10.1</a>, <a
+ href="#sec-binary-bitwise-operators-static-semantics-isfunctiondefinition">12.11.1</a>, <a
+ href="#sec-binary-logical-operators-static-semantics-isfunctiondefinition">12.12.1</a>, <a
+ href="#sec-conditional-operator-static-semantics-isfunctiondefinition">12.13.1</a>, <a
+ href="#sec-assignment-operators-static-semantics-isfunctiondefinition">12.14.2</a>, <a
+ href="#sec-function-definitions-static-semantics-isfunctiondefinition">14.1.11</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-isfunctiondefinition">14.4.8</a>, <a
+ href="#sec-class-definitions-static-semantics-isfunctiondefinition">14.5.8</a>.</p>
+
+ <div class="gp prod"><span class="nt">Expression</span> <span class="geq">:</span> <span class="nt">Expression</span> <code class="t">,</code> <span class="nt">AssignmentExpression</span></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-comma-operator-static-semantics-isvalidsimpleassignmenttarget">
+ <h1><span class="secnum" id="sec-12.15.2"><a href="#sec-comma-operator-static-semantics-isvalidsimpleassignmenttarget"
+ title="link to this section">12.15.2</a></span> Static Semantics: IsValidSimpleAssignmentTarget</h1>
+
+ <p>See also: <a href="#sec-semantics-static-semantics-isidentifierref">12.2.0.3</a>, <a
+ href="#sec-grouping-operator-static-semantics-isvalidsimpleassignmenttarget">12.2.10.3</a>, <a
+ href="#sec-static-semantics-static-semantics-isidentifierref">12.3.1.3</a>, <a
+ href="#sec-postfix-expressions-static-semantics-isvalidsimpleassignmenttarget">12.4.3</a>, <a
+ href="#sec-unary-operators-static-semantics-isvalidsimpleassignmenttarget">12.5.3</a>, <a
+ href="#sec-multiplicative-operators-static-semantics-isvalidsimpleassignmenttarget">12.6.2</a>, <a
+ href="#sec-additive-operators-static-semantics-isvalidsimpleassignmenttarget">12.7.2</a>, <a
+ href="#sec-bitwise-shift-operators-static-semantics-isvalidsimpleassignmenttarget">12.8.2</a>, <a
+ href="#sec-relational-operators-static-semantics-isvalidsimpleassignmenttarget">12.9.2</a>, <a
+ href="#sec-equality-operators-static-semantics-isvalidsimpleassignmenttarget">12.10.2</a>, <a
+ href="#sec-binary-bitwise-operators-static-semantics-isvalidsimpleassignmenttarget">12.11.2</a>, <a
+ href="#sec-binary-logical-operators-static-semantics-isvalidsimpleassignmenttarget">12.12.2</a>, <a
+ href="#sec-conditional-operator-static-semantics-isvalidsimpleassignmenttarget">12.13.2</a>, <a
+ href="#sec-assignment-operators-static-semantics-isvalidsimpleassignmenttarget">12.14.3</a>.</p>
+
+ <div class="gp prod"><span class="nt">Expression</span> <span class="geq">:</span> <span class="nt">Expression</span> <code class="t">,</code> <span class="nt">AssignmentExpression</span></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-comma-operator-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-12.15.3"><a href="#sec-comma-operator-runtime-semantics-evaluation"
+ title="link to this section">12.15.3</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">Expression</span> <span class="geq">:</span> <span class="nt">Expression</span> <code class="t">,</code> <span class="nt">AssignmentExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>lref</i> be the result of evaluating <i>Expression</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<a href="#sec-getvalue">GetValue</a>(<i>lref</i>))</li>
+ <li>Let <i>rref</i> be the result of evaluating <i>AssignmentExpression</i>.</li>
+ <li>Return <a href="#sec-getvalue">GetValue</a>(<i>rref</i>).</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> <a href="#sec-getvalue">GetValue</a> must be called even though its value is not used
+ because it may have observable side-effects.</p>
+ </div>
+ </section>
+ </section>
+</section>
+
+<section id="sec-ecmascript-language-statements-and-declarations">
+ <div class="front">
+ <h1><span class="secnum" id="sec-13"><a href="#sec-ecmascript-language-statements-and-declarations"
+ title="link to this section">13</a></span> ECMAScript Language: Statements and Declarations</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">Statement</span><sub>[Yield, Return]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">BlockStatement</span><sub>[?Yield, ?Return]</sub></div>
+ <div class="rhs"><span class="nt">VariableStatement</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="nt">EmptyStatement</span></div>
+ <div class="rhs"><span class="nt">ExpressionStatement</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="nt">IfStatement</span><sub>[?Yield, ?Return]</sub></div>
+ <div class="rhs"><span class="nt">BreakableStatement</span><sub>[?Yield, ?Return]</sub></div>
+ <div class="rhs"><span class="nt">ContinueStatement</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="nt">BreakStatement</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="grhsannot">[+Return]</span> <span class="nt">ReturnStatement</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="nt">WithStatement</span><sub>[?Yield, ?Return]</sub></div>
+ <div class="rhs"><span class="nt">LabelledStatement</span><sub>[?Yield, ?Return]</sub></div>
+ <div class="rhs"><span class="nt">ThrowStatement</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="nt">TryStatement</span><sub>[?Yield, ?Return]</sub></div>
+ <div class="rhs"><span class="nt">DebuggerStatement</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">Declaration</span><sub>[Yield, Default]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">FunctionDeclaration</span><sub>[?Yield,?Default]</sub></div>
+ <div class="rhs"><span class="nt">GeneratorDeclaration</span><sub>[?Yield, ?Default]</sub></div>
+ <div class="rhs"><span class="nt">ClassDeclaration</span><sub>[?Yield,?Default]</sub></div>
+ <div class="rhs"><span class="nt">LexicalDeclaration</span><sub>[In, ?Yield]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">BreakableStatement</span><sub>[Yield, Return]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">IterationStatement</span><sub>[?Yield, ?Return]</sub></div>
+ <div class="rhs"><span class="nt">SwitchStatement</span><sub>[?Yield, ?Return]</sub></div>
+ </div>
+ </div>
+
+ <section id="sec-statement-semantics">
+ <div class="front">
+ <h1><span class="secnum" id="sec-13.0"><a href="#sec-statement-semantics" title="link to this section">13.0</a></span>
+ Statement Semantics</h1>
+ </div>
+
+ <section id="sec-statement-semantics-static-semantics-vardeclarednames">
+ <h1><span class="secnum" id="sec-13.0.1"><a href="#sec-statement-semantics-static-semantics-vardeclarednames"
+ title="link to this section">13.0.1</a></span> Static Semantics: VarDeclaredNames</h1>
+
+ <p>See also: <a href="#sec-block-static-semantics-vardeclarednames">13.1.8</a>, <a
+ href="#sec-variable-statement-static-semantics-vardeclarednames">13.2.2.2</a>, <a
+ href="#sec-if-statement-static-semantics-vardeclarednames">13.5.1</a>, <a
+ href="#sec-do-while-statement-static-semantics-vardeclarednames">13.6.1.1</a>, <a
+ href="#sec-while-statement-static-semantics-vardeclarednames">13.6.2.1</a>, <a
+ href="#sec-for-statement-static-semantics-vardeclarednames">13.6.3.1</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-vardeclarednames">13.6.4.3</a>, <a
+ href="#sec-with-statement-static-semantics-vardeclarednames">13.10.2</a>, <a
+ href="#sec-switch-statement-static-semantics-vardeclarednames">13.11.4</a>, <a
+ href="#sec-static-semantics-currentlabelset">13.12.2</a>, 0, <a
+ href="#sec-function-definitions-static-semantics-referencessuper">14.1.16</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-vardeclarednames">14.4.12</a>, <a
+ href="#sec-class-definitions-static-semantics-vardeclarednames">14.5.15</a>, <a
+ href="#sec-scripts-static-semantics-vardeclarednames">15.1.5</a>, <a
+ href="#sec-module-static-semantics-static-semantics-vardeclarednames">15.2.0.13</a>.</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">Statement</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">EmptyStatement</span></div>
+ <div class="rhs"><span class="nt">ExpressionStatement</span></div>
+ <div class="rhs"><span class="nt">ContinueStatement</span></div>
+ <div class="rhs"><span class="nt">BreakStatement</span></div>
+ <div class="rhs"><span class="nt">ReturnStatement</span></div>
+ <div class="rhs"><span class="nt">ThrowStatement</span></div>
+ <div class="rhs"><span class="nt">DebuggerStatement</span></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-statement-semantics-static-semantics-varscopeddeclarations">
+ <h1><span class="secnum" id="sec-13.0.2"><a href="#sec-statement-semantics-static-semantics-varscopeddeclarations"
+ title="link to this section">13.0.2</a></span> Static Semantics: VarScopedDeclarations</h1>
+
+ <p>See also: <a href="#sec-block-static-semantics-varscopeddeclarations">13.1.9</a>, <a
+ href="#sec-variable-statement-static-semantics-varscopeddeclarations">13.2.2.3</a>, <a
+ href="#sec-if-statement-static-semantics-varscopeddeclarations">13.5.2</a>, <a
+ href="#sec-do-while-statement-static-semantics-varscopeddeclarations">13.6.1.2</a>, <a
+ href="#sec-while-statement-static-semantics-varscopeddeclarations">13.6.2.2</a>, <a
+ href="#sec-for-statement-static-semantics-varscopeddeclarations">13.6.3.2</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-varscopeddeclarations">13.6.4.4</a>, <a
+ href="#sec-with-statement-static-semantics-varscopeddeclarations">13.10.3</a>, <a
+ href="#sec-switch-statement-static-semantics-varscopeddeclarations">13.11.5</a>, <a
+ href="#sec-labelled-statements-static-semantics-varscopeddeclarations">13.12.4</a>, <a
+ href="#sec-try-statement-static-semantics-varscopeddeclarations">13.14.3</a>, <a
+ href="#sec-function-definitions-static-semantics-varscopeddeclarations">14.1.18</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-varscopeddeclarations">14.2.14</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-varscopeddeclarations">14.4.13</a>, <a
+ href="#sec-scripts-static-semantics-varscopeddeclarations">15.1.6</a>, <a
+ href="#sec-module-static-semantics-static-semantics-varscopeddeclarations">15.2.0.14</a>.</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">Statement</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">EmptyStatement</span></div>
+ <div class="rhs"><span class="nt">ExpressionStatement</span></div>
+ <div class="rhs"><span class="nt">ContinueStatement</span></div>
+ <div class="rhs"><span class="nt">BreakStatement</span></div>
+ <div class="rhs"><span class="nt">ReturnStatement</span></div>
+ <div class="rhs"><span class="nt">ThrowStatement</span></div>
+ <div class="rhs"><span class="nt">DebuggerStatement</span></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-statement-semantics-runtime-semantics-labelledevaluation">
+ <h1><span class="secnum" id="sec-13.0.3"><a href="#sec-statement-semantics-runtime-semantics-labelledevaluation"
+ title="link to this section">13.0.3</a></span> Runtime Semantics: LabelledEvaluation</h1>
+
+ <p>With argument <var>labelSet</var>.</p>
+
+ <p>See also: <a href="#sec-do-while-statement-static-semantics-varscopeddeclarations">13.6.1.2</a>, <a
+ href="#sec-while-statement-static-semantics-varscopeddeclarations">13.6.2.2</a>, <a
+ href="#sec-for-statement-static-semantics-varscopeddeclarations">13.6.3.2</a>, <a
+ href="#sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation">13.6.4.6</a>, <a
+ href="#sec-labelled-statements-static-semantics-varscopeddeclarations">13.12.4</a>.</p>
+
+ <div class="gp prod"><span class="nt">BreakableStatement</span> <span class="geq">:</span> <span class="nt">IterationStatement</span></div>
+ <ol class="proc">
+ <li>Let <i>stmtResult</i> be the result of performing LabelledEvaluation of <i>IterationStatement</i> with argument
+ <i>labelSet</i>.</li>
+ <li>If <i>stmtResult</i>.[[type]] is <span style="font-family: sans-serif">break</span> and <i>stmtResult</i>.[[target]]
+ is <span style="font-family: sans-serif">empty</span>, then
+ <ol class="block">
+ <li>If <i>stmtResult</i>.[[value]] is <span style="font-family: sans-serif">empty</span>, then let <i>stmtResult</i>
+ be <a href="#sec-normalcompletion">NormalCompletion</a>(<b>undefined</b>).</li>
+ <li>Else, let <i>stmtResult</i> be <a
+ href="#sec-normalcompletion">NormalCompletion</a>(<i>stmtResult</i>.[[value]])</li>
+ </ol>
+ </li>
+ <li>Return <i>stmtResult</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">BreakableStatement</span> <span class="geq">:</span> <span class="nt">SwitchStatement</span></div>
+ <ol class="proc">
+ <li>Let <i>stmtResult</i> be the result of evaluating <i>SwitchStatement</i>.</li>
+ <li>If <i>stmtResult</i>.[[type]] is <span style="font-family: sans-serif">break</span> and <i>stmtResult</i>.[[target]]
+ is <span style="font-family: sans-serif">empty</span>, then
+ <ol class="block">
+ <li>If <i>stmtResult</i>.[[value]] is <span style="font-family: sans-serif">empty</span>, then let <i>stmtResult</i>
+ be <a href="#sec-normalcompletion">NormalCompletion</a>(<b>undefined</b>).</li>
+ <li>Else, let <i>stmtResult</i> be <a
+ href="#sec-normalcompletion">NormalCompletion</a>(<i>stmtResult</i>.[[value]])</li>
+ </ol>
+ </li>
+ <li>Return <i>stmtResult</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> A <i>BreakableStatement</i> is one that can be exited via an unlabelled
+ <i>BreakStatement.</i></p>
+ </div>
+ </section>
+
+ <section id="sec-statement-semantics-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-13.0.4"><a href="#sec-statement-semantics-runtime-semantics-evaluation"
+ title="link to this section">13.0.4</a></span> Runtime Semantics: Evaluation</h1>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">BreakableStatement</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">IterationStatement</span></div>
+ <div class="rhs"><span class="nt">SwitchStatement</span></div>
+ </div>
+
+ <ol class="proc">
+ <li>Let <i>newLabelSet</i> be a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Return the result of performing LabelledEvaluation of this <i>BreakableStatement</i> with argument
+ <i>newLabelSet</i>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-block">
+ <div class="front">
+ <h1><span class="secnum" id="sec-13.1"><a href="#sec-block" title="link to this section">13.1</a></span> Block</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">BlockStatement</span><sub>[Yield, Return]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">Block</span><sub>[?Yield, ?Return]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">Block</span><sub>[Yield, Return]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">{</code> <span class="nt">StatementList</span><sub>[?Yield, ?Return]</sub><sub>opt</sub> <code class="t">}</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">StatementList</span><sub>[Yield, Return]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">StatementListItem</span><sub>[?Yield, ?Return]</sub></div>
+ <div class="rhs"><span class="nt">StatementList</span><sub>[?Yield, ?Return]</sub> <span class="nt">StatementListItem</span><sub>[?Yield, ?Return]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">StatementListItem</span><sub>[Yield, Return]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">Statement</span><sub>[?Yield, ?Return]</sub></div>
+ <div class="rhs"><span class="nt">Declaration</span><sub>[?Yield]</sub></div>
+ </div>
+ </div>
+
+ <section id="sec-block-static-semantics-early-errors">
+ <h1><span class="secnum" id="sec-13.1.1"><a href="#sec-block-static-semantics-early-errors"
+ title="link to this section">13.1.1</a></span> Static Semantics: Early Errors</h1>
+ <div class="gp prod"><span class="nt">Block</span> <span class="geq">:</span> <code class="t">{</code> <span class="nt">StatementList</span> <code class="t">}</code></div>
+ <ul>
+ <li>
+ <p>It is a Syntax Error if the LexicallyDeclaredNames of <span class="nt">StatementList</span> contains any duplicate
+ entries.</p>
+ </li>
+
+ <li>
+ <p>It is a Syntax Error if any element of the LexicallyDeclaredNames of <span class="nt">StatementList</span> also
+ occurs in the VarDeclaredNames of <span class="nt">StatementList</span>.</p>
+ </li>
+ </ul>
+ </section>
+
+ <section id="sec-block-static-semantics-lexicallyscopeddeclarations">
+ <h1><span class="secnum" id="sec-13.1.2"><a href="#sec-block-static-semantics-lexicallyscopeddeclarations"
+ title="link to this section">13.1.2</a></span> Static Semantics: LexicallyScopedDeclarations</h1>
+
+ <p>See also: <a href="#sec-switch-statement-static-semantics-lexicallyscopeddeclarations">13.11.2</a>, <a
+ href="#sec-module-static-semantics-static-semantics-lexicallyscopeddeclarations">15.2.0.11</a>.</p>
+
+ <div class="gp prod"><span class="nt">StatementList</span> <span class="geq">:</span> <span class="nt">StatementList</span> <span class="nt">StatementListItem</span></div>
+ <ol class="proc">
+ <li>Let <i>declarations</i> be LexicallyScopedDeclarations of <i>StatementList</i>.</li>
+ <li>Append to <i>declarations</i> the elements of the LexicallyScopedDeclarations of <i>StatementListItem.</i></li>
+ <li>Return <i>declarations</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">StatementListItem</span> <span class="geq">:</span> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">StatementListItem</span> <span class="geq">:</span> <span class="nt">Declaration</span></div>
+ <ol class="proc">
+ <li>Return a new <a href="#sec-list-and-record-specification-type">List</a> containing <i>Declaration</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-block-static-semantics-lexicallydeclarednames">
+ <h1><span class="secnum" id="sec-13.1.3"><a href="#sec-block-static-semantics-lexicallydeclarednames"
+ title="link to this section">13.1.3</a></span> Static Semantics: LexicallyDeclaredNames</h1>
+
+ <p>See also: <a href="#sec-switch-statement-static-semantics-lexicallydeclarednames">13.11.3</a>, <a
+ href="#sec-function-definitions-static-semantics-lexicallyscopeddeclarations">14.1.14</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-lexicallyscopeddeclarations">14.2.10</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-isfunctiondefinition">14.4.8</a>, <a
+ href="#sec-class-definitions-static-semantics-lexicallydeclarednames">14.5.10</a>, <a
+ href="#sec-scripts-static-semantics-lexicallydeclarednames">15.1.3</a>, <a
+ href="#sec-module-static-semantics-static-semantics-lexicallydeclarednames">15.2.0.10</a>.</p>
+
+ <div class="gp prod"><span class="nt">Block</span> <span class="geq">:</span> <code class="t">{</code> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">StatementList</span> <span class="geq">:</span> <span class="nt">StatementList</span> <span class="nt">StatementListItem</span></div>
+ <ol class="proc">
+ <li>Let <i>names</i> be LexicallyDeclaredNames of <i>StatementList</i>.</li>
+ <li>Append to <i>names</i> the elements of the LexicallyDeclaredNames of <i>StatementListItem.</i></li>
+ <li>Return <i>names</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">StatementListItem</span> <span class="geq">:</span> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">StatementListItem</span> <span class="geq">:</span> <span class="nt">Declaration</span></div>
+ <ol class="proc">
+ <li>Return the BoundNames of <i>Declaration</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-static-semantics-toplevellexicallydeclarednames">
+ <h1><span class="secnum" id="sec-13.1.4"><a href="#sec-static-semantics-toplevellexicallydeclarednames"
+ title="link to this section">13.1.4</a></span> Static Semantics: TopLevelLexicallyDeclaredNames</h1>
+ <div class="gp prod"><span class="nt">StatementList</span> <span class="geq">:</span> <span class="nt">StatementList</span> <span class="nt">StatementListItem</span></div>
+ <ol class="proc">
+ <li>Let <i>names</i> be TopLevelLexicallyDeclaredNames of <i>StatementList</i>.</li>
+ <li>Append to <i>names</i> the elements of the TopLevelLexicallyDeclaredNames of <i>StatementListItem.</i></li>
+ <li>Return <i>names</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">StatementListItem</span> <span class="geq">:</span> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">StatementListItem</span> <span class="geq">:</span> <span class="nt">Declaration</span></div>
+ <ol class="proc">
+ <li>If <i>Declaration</i> is <span class="prod"><span class="nt">Declaration</span> <span class="geq">:</span> <span
+ class="nt">FunctionDeclaration</span></span> , then return a new empty <a
+ href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>If <i>Declaration</i> is <span class="prod"><span class="nt">Declaration</span> <span class="geq">:</span> <span
+ class="nt">GeneratorDeclaration</span></span> , then return a new empty <a
+ href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Return the BoundNames of <i>Declaration</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> At the top level of a function, or script, function declarations are treated like var
+ declarations rather than like lexical declarations.</p>
+ </div>
+ </section>
+
+ <section id="sec-static-semantics-toplevellexicallyscopeddeclarations">
+ <h1><span class="secnum" id="sec-13.1.5"><a href="#sec-static-semantics-toplevellexicallyscopeddeclarations"
+ title="link to this section">13.1.5</a></span> Static Semantics: TopLevelLexicallyScopedDeclarations</h1>
+ <div class="gp prod"><span class="nt">Block</span> <span class="geq">:</span> <code class="t">{</code> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">StatementList</span> <span class="geq">:</span> <span class="nt">StatementList</span> <span class="nt">StatementListItem</span></div>
+ <ol class="proc">
+ <li>Let <i>declarations</i> be TopLevelLexicallyScopedDeclarations of <i>StatementList</i>.</li>
+ <li>Append to <i>declarations</i> the elements of the TopLevelLexicallyScopedDeclarations of
+ <i>StatementListItem.</i></li>
+ <li>Return <i>declarations</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">StatementListItem</span> <span class="geq">:</span> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">StatementListItem</span> <span class="geq">:</span> <span class="nt">Declaration</span></div>
+ <ol class="proc">
+ <li>If <i>Declaration</i> is <span class="prod"><span class="nt">Declaration</span> <span class="geq">:</span> <span
+ class="nt">FunctionDeclaration</span></span> , then return a new empty <a
+ href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>If <i>Declaration</i> is <span class="prod"><span class="nt">Declaration</span> <span class="geq">:</span> <span
+ class="nt">GeneratorDeclaration</span></span> , then return a new empty <a
+ href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Return a new <a href="#sec-list-and-record-specification-type">List</a> containing <i>Declaration</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-static-semantics-toplevelvardeclarednames">
+ <h1><span class="secnum" id="sec-13.1.6"><a href="#sec-static-semantics-toplevelvardeclarednames"
+ title="link to this section">13.1.6</a></span> Static Semantics: TopLevelVarDeclaredNames</h1>
+ <div class="gp prod"><span class="nt">Block</span> <span class="geq">:</span> <code class="t">{</code> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">StatementList</span> <span class="geq">:</span> <span class="nt">StatementList</span> <span class="nt">StatementListItem</span></div>
+ <ol class="proc">
+ <li>Let <i>names</i> be TopLevelVarDeclaredNames of <i>StatementList</i>.</li>
+ <li>Append to <i>names</i> the elements of the TopLevelVarDeclaredNames of <i>StatementListItem.</i></li>
+ <li>Return <i>names</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">StatementListItem</span> <span class="geq">:</span> <span class="nt">Declaration</span></div>
+ <ol class="proc">
+ <li>If <i>Declaration</i> is <span class="prod"><span class="nt">Declaration</span> <span class="geq">:</span> <span
+ class="nt">FunctionDeclaration</span></span> , then return the LexicallyDeclaredNames of <i>Declaration</i>.</li>
+ <li>If <i>Declaration</i> is <span class="prod"><span class="nt">Declaration</span> <span class="geq">:</span> <span
+ class="nt">GeneratorDeclaration</span></span> , then return the LexicallyDeclaredNames of <i>Declaration</i>.</li>
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">StatementListItem</span> <span class="geq">:</span> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Return VarDeclaredNames of <i>Statement</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> At the top level of a function or script, inner function declarations are treated like var
+ declarations.</p>
+ </div>
+ </section>
+
+ <section id="sec-static-semantics-toplevelvarscopeddeclarations">
+ <h1><span class="secnum" id="sec-13.1.7"><a href="#sec-static-semantics-toplevelvarscopeddeclarations"
+ title="link to this section">13.1.7</a></span> Static Semantics: TopLevelVarScopedDeclarations</h1>
+ <div class="gp prod"><span class="nt">Block</span> <span class="geq">:</span> <code class="t">{</code> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">StatementList</span> <span class="geq">:</span> <span class="nt">StatementList</span> <span class="nt">StatementListItem</span></div>
+ <ol class="proc">
+ <li>Let <i>declarations</i> be TopLevelVarScopedDeclarations of <i>StatementList</i>.</li>
+ <li>Append to <i>declarations</i> the elements of the TopLevelVarScopedDeclarations of <i>StatementListItem.</i></li>
+ <li>Return <i>declarations</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">StatementListItem</span> <span class="geq">:</span> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Return VarScopedDeclarations of <i>Statement</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">StatementListItem</span> <span class="geq">:</span> <span class="nt">Declaration</span></div>
+ <ol class="proc">
+ <li>If <i>Declaration</i> is <span class="prod"><span class="nt">Declaration</span> <span class="geq">:</span> <span
+ class="nt">FunctionDeclaration</span></span> , then return a new <a
+ href="#sec-list-and-record-specification-type">List</a> containing <i>FunctionDeclaration</i>.</li>
+ <li>If <i>Declaration</i> is <span class="prod"><span class="nt">Declaration</span> <span class="geq">:</span> <span
+ class="nt">GeneratorDeclaration</span></span> , then return a new <a
+ href="#sec-list-and-record-specification-type">List</a> containing <i>GeneratorDeclaration</i>.</li>
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-block-static-semantics-vardeclarednames">
+ <h1><span class="secnum" id="sec-13.1.8"><a href="#sec-block-static-semantics-vardeclarednames"
+ title="link to this section">13.1.8</a></span> Static Semantics: VarDeclaredNames</h1>
+
+ <p>See also: <a href="#sec-statement-semantics-static-semantics-vardeclarednames">13.0.1</a>, <a
+ href="#sec-variable-statement-static-semantics-vardeclarednames">13.2.2.2</a>, <a
+ href="#sec-if-statement-static-semantics-vardeclarednames">13.5.1</a>, <a
+ href="#sec-do-while-statement-static-semantics-vardeclarednames">13.6.1.1</a>, <a
+ href="#sec-while-statement-static-semantics-vardeclarednames">13.6.2.1</a>, <a
+ href="#sec-for-statement-static-semantics-vardeclarednames">13.6.3.1</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-vardeclarednames">13.6.4.3</a>, <a
+ href="#sec-with-statement-static-semantics-vardeclarednames">13.10.2</a>, <a
+ href="#sec-switch-statement-static-semantics-vardeclarednames">13.11.4</a>, <a
+ href="#sec-static-semantics-currentlabelset">13.12.2</a>, 0, <a
+ href="#sec-function-definitions-static-semantics-referencessuper">14.1.16</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-vardeclarednames">14.4.12</a>, <a
+ href="#sec-class-definitions-static-semantics-vardeclarednames">14.5.15</a>, <a
+ href="#sec-scripts-static-semantics-vardeclarednames">15.1.5</a>, <a
+ href="#sec-module-static-semantics-static-semantics-vardeclarednames">15.2.0.13</a>.</p>
+
+ <div class="gp prod"><span class="nt">Block</span> <span class="geq">:</span> <code class="t">{</code> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">StatementList</span> <span class="geq">:</span> <span class="nt">StatementList</span> <span class="nt">StatementListItem</span></div>
+ <ol class="proc">
+ <li>Let <i>names</i> be VarDeclaredNames of <i>StatementList</i>.</li>
+ <li>Append to <i>names</i> the elements of the VarDeclaredNames of <i>StatementListItem.</i></li>
+ <li>Return <i>names</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">StatementListItem</span> <span class="geq">:</span> <span class="nt">Declaration</span></div>
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-block-static-semantics-varscopeddeclarations">
+ <h1><span class="secnum" id="sec-13.1.9"><a href="#sec-block-static-semantics-varscopeddeclarations"
+ title="link to this section">13.1.9</a></span> Static Semantics: VarScopedDeclarations</h1>
+
+ <p>See also: <a href="#sec-statement-semantics-static-semantics-varscopeddeclarations">13.0.2</a>, <a
+ href="#sec-variable-statement-static-semantics-varscopeddeclarations">13.2.2.3</a>, <a
+ href="#sec-if-statement-static-semantics-varscopeddeclarations">13.5.2</a>, <a
+ href="#sec-do-while-statement-static-semantics-varscopeddeclarations">13.6.1.2</a>, <a
+ href="#sec-while-statement-static-semantics-varscopeddeclarations">13.6.2.2</a>, <a
+ href="#sec-for-statement-static-semantics-varscopeddeclarations">13.6.3.2</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-varscopeddeclarations">13.6.4.4</a>, <a
+ href="#sec-with-statement-static-semantics-varscopeddeclarations">13.10.3</a>, <a
+ href="#sec-switch-statement-static-semantics-varscopeddeclarations">13.11.5</a>, <a
+ href="#sec-labelled-statements-static-semantics-varscopeddeclarations">13.12.4</a>, <a
+ href="#sec-try-statement-static-semantics-varscopeddeclarations">13.14.3</a>, <a
+ href="#sec-function-definitions-static-semantics-varscopeddeclarations">14.1.18</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-varscopeddeclarations">14.2.14</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-varscopeddeclarations">14.4.13</a>, <a
+ href="#sec-scripts-static-semantics-varscopeddeclarations">15.1.6</a>, <a
+ href="#sec-module-static-semantics-static-semantics-varscopeddeclarations">15.2.0.14</a>.</p>
+
+ <div class="gp prod"><span class="nt">Block</span> <span class="geq">:</span> <code class="t">{</code> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">StatementList</span> <span class="geq">:</span> <span class="nt">StatementList</span> <span class="nt">StatementListItem</span></div>
+ <ol class="proc">
+ <li>Let <i>declarations</i> be VarScopedDeclarations of <i>StatementList</i>.</li>
+ <li>Append to <i>declarations</i> the elements of the VarScopedDeclarations of <i>StatementListItem.</i></li>
+ <li>Return <i>declarations</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">StatementListItem</span> <span class="geq">:</span> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Return VarScopedDeclarations of <i>Statement</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">StatementListItem</span> <span class="geq">:</span> <span class="nt">Declaration</span></div>
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-block-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-13.1.10"><a href="#sec-block-runtime-semantics-evaluation"
+ title="link to this section">13.1.10</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">Block</span> <span class="geq">:</span> <code class="t">{</code> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<b>undefined</b>).</li>
+ </ol>
+ <div class="gp prod"><span class="nt">Block</span> <span class="geq">:</span> <code class="t">{</code> <span class="nt">StatementList</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Let <i>oldEnv</i> be <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-execution-contexts">LexicalEnvironment</a>.</li>
+ <li>Let <i>blockEnv</i> be <a href="#sec-newdeclarativeenvironment">NewDeclarativeEnvironment</a>(<i>oldEnv</i>).</li>
+ <li>Perform <a href="#sec-blockdeclarationinstantiation">BlockDeclarationInstantiation</a>(<i>StatementList,</i>
+ <i>blockEnv</i>).</li>
+ <li>Set <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-execution-contexts">LexicalEnvironment</a> to <i>blockEnv</i>.</li>
+ <li>Let <i>blockValue</i> be the result of evaluating <i>StatementList</i>.</li>
+ <li>Set <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-execution-contexts">LexicalEnvironment</a> to <i>oldEnv</i>.</li>
+ <li>If <i>blockValue</i>.[[type]] is <span style="font-family: sans-serif">normal</span> and <i>blockValue</i>.[[value]]
+ is <span style="font-family: sans-serif">empty</span>, then
+ <ol class="block">
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<b>undefined</b>).</li>
+ </ol>
+ </li>
+ <li>Return <i>blockValue</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> No matter how control leaves the <i>Block</i> the <a
+ href="#sec-execution-contexts">LexicalEnvironment</a> is always restored to its former state.</p>
+ </div>
+
+ <div class="gp prod"><span class="nt">StatementList</span> <span class="geq">:</span> <span class="nt">StatementList</span> <span class="nt">StatementListItem</span></div>
+ <ol class="proc">
+ <li>Let <i>sl</i> be the result of evaluating <i>StatementList</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>sl</i>).</li>
+ <li>Let <i>s</i> be the result of evaluating <i>StatementListItem</i>.</li>
+ <li>If <i>s</i>.[[type]] is <span style="font-family: sans-serif">throw</span>, return <i>s</i>.</li>
+ <li>If <i>s</i>.[[value]] is <span style="font-family: sans-serif">empty</span>, let <i>V</i> = <i>sl</i>.[[value]],
+ otherwise let <i>V</i> = <i>s</i>.[[value]].</li>
+ <li>Return <a href="#sec-completion-record-specification-type">Completion</a>{[[type]]: <i>s</i>.[[type]], [[value]]:
+ <i>V</i>, [[target]]: <i>s</i>.[[target]]}.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Steps 5 and 6 of the above algorithm ensure that the value of a <i>StatementList</i> is
+ the value of the last value producing <i>Statement</i> in the <i>StatementList</i>. For example, the following calls to
+ the <code>eval</code> function all return the value 1:</p>
+
+ <pre>eval("1;;;;;")</pre>
+ <pre>eval("1;{}")</pre>
+ <pre>eval("1;var a;")</pre>
+ </div>
+ </section>
+
+ <section id="sec-blockdeclarationinstantiation">
+ <h1><span class="secnum" id="sec-13.1.11"><a href="#sec-blockdeclarationinstantiation"
+ title="link to this section">13.1.11</a></span> Runtime Semantics: BlockDeclarationInstantiation( code, env )</h1>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> When a <span class="nt">Block</span> or <span class="nt">CaseBlock</span> production is
+ evaluated a new <a href="#sec-declarative-environment-records">Declarative Environment Record</a> is created and bindings
+ for each block scoped variable, constant, or function declarated in the block are instantiated in the environment
+ record.</p>
+ </div>
+
+ <p>BlockDeclarationInstantiation is performed as follows using arguments <var>code</var> and <var>env</var>. <var>code</var>
+ is the grammar production corresponding to the body of the block. <var>env</var> is the <a
+ href="#sec-declarative-environment-records">declarative environment record</a> in which bindings are to be created.</p>
+
+ <ol class="proc">
+ <li>Let <i>declarations</i> be the LexicallyScopedDeclarations of <i>code</i>.</li>
+ <li>Let <i>functionsToInitialize</i> be an empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>For each element <i>d</i> in <i>declarations</i> do
+ <ol class="block">
+ <li>For each element <i>dn</i> of the BoundNames of <i>d</i> do
+ <ol class="block">
+ <li>If IsConstantDeclaration of <i>d</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Call <i>env</i>’s CreateImmutableBinding concrete method passing <i>dn</i> as the argument.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>status</i> be the result of calling <i>env</i>’s CreateMutableBinding concrete method passing
+ <i>dn</i> and <b>false</b> as the arguments.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>status</i> is never an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>If <i>d</i> is a <i>GeneratorDeclaration</i> production or a <i>FunctionDeclaration</i> production, then
+ <ol class="block">
+ <li>Append <i>d</i> to <i>functionsToInitialize</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>For each production <i>f</i> in <i>functionsToInitialize</i>, in list order do
+ <ol class="block">
+ <li>Let <i>fn</i> be the sole element of the BoundNames of <i>f.</i></li>
+ <li>Let <i>fo</i> be the result of performing InstantiateFunctionObject for <i>f</i> with argument <i>env</i>.</li>
+ <li>Call <i>env</i>’s InitializeBinding concrete method passing <i>fn</i>, and <i>fo</i> as the arguments.</li>
+ </ol>
+ </li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-declarations-and-the-variable-statement">
+ <div class="front">
+ <h1><span class="secnum" id="sec-13.2"><a href="#sec-declarations-and-the-variable-statement"
+ title="link to this section">13.2</a></span> Declarations and the Variable Statement</h1>
+ </div>
+
+ <section id="sec-let-and-const-declarations">
+ <div class="front">
+ <h1><span class="secnum" id="sec-13.2.1"><a href="#sec-let-and-const-declarations"
+ title="link to this section">13.2.1</a></span> Let and Const Declarations</h1>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> A <code>let</code> and <code>const</code> declarations define variables that are scoped
+ to <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-execution-contexts">LexicalEnvironment</a>. The variables are created when their containing <a
+ href="#sec-lexical-environments">Lexical Environment</a> is instantiated but may not be accessed in any way until the
+ variable’s <span class="nt">LexicalBinding</span> is evaluated. A variable defined by a <span
+ class="nt">LexicalBinding</span> with an <span class="nt">Initializer</span> is assigned the value of its <span
+ style="font-family: Times New Roman"><i>Initializer</i>’s</span> <span class="nt">AssignmentExpression</span> when
+ the <span class="nt">LexicalBinding</span> is evaluated, not when the variable is created. If a <span
+ class="nt">LexicalBinding</span> in a <code>let</code> declaration does not have an <span class="nt">Initializer</span>
+ the variable is assigned the value <b>undefined</b> when the <span class="nt">LexicalBinding</span> is evaluated.</p>
+ </div>
+
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">LexicalDeclaration</span><sub>[In, Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">LetOrConst</span> <span class="nt">BindingList</span><sub>[?In, ?Yield]</sub> <code class="t">;</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">LetOrConst</span> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">let</code></div>
+ <div class="rhs"><code class="t">const</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">BindingList</span><sub>[In, Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">LexicalBinding</span><sub>[?In, ?Yield]</sub></div>
+ <div class="rhs"><span class="nt">BindingList</span><sub>[?In, ?Yield]</sub> <code class="t">,</code> <span class="nt">LexicalBinding</span><sub>[?In, ?Yield]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">LexicalBinding</span><sub>[In, Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">BindingIdentifier</span><sub>[?Yield]</sub> <span class="nt">Initializer</span><sub>[?In, ?Yield]</sub><sub>opt</sub></div>
+ <div class="rhs"><span class="nt">BindingPattern</span><sub>[?Yield]</sub> <span class="nt">Initializer</span><sub>[?In, ?Yield]</sub></div>
+ </div>
+ </div>
+
+ <section id="sec-let-and-const-declarations-static-semantics-early-errors">
+ <h1><span class="secnum" id="sec-13.2.1.1"><a href="#sec-let-and-const-declarations-static-semantics-early-errors"
+ title="link to this section">13.2.1.1</a></span> Static Semantics: Early Errors</h1>
+ <div class="gp prod"><span class="nt">LexicalDeclaration</span> <span class="geq">:</span> <span class="nt">LetOrConst</span> <span class="nt">BindingList</span> <code class="t">;</code></div>
+ <ul>
+ <li>It is a Syntax Error if the BoundNames of <span class="nt">BindingList</span> contains <code>"let"</code>.</li>
+ <li>It is a Syntax Error if the BoundNames of <span class="nt">BindingList</span> contains any duplicate entries.</li>
+ </ul>
+ <div class="gp prod"><span class="nt">LexicalBinding</span> <span class="geq">:</span> <span class="nt">BindingIdentifier</span> <span class="nt">Initializer</span><sub>opt</sub></div>
+ <ul>
+ <li>
+ <p>It is a Syntax Error if <span class="nt">Initializer</span> is not present and IsConstantDeclaration of the <span
+ class="nt">LexicalDeclaration</span> containing this production is <span class="value">true</span>.</p>
+ </li>
+ </ul>
+ </section>
+
+ <section id="sec-let-and-const-declarations-static-semantics-boundnames">
+ <h1><span class="secnum" id="sec-13.2.1.2"><a href="#sec-let-and-const-declarations-static-semantics-boundnames"
+ title="link to this section">13.2.1.2</a></span> Static Semantics: BoundNames</h1>
+
+ <p>See also:, <a href="#sec-identifiers-static-semantics-boundnames">12.1.2</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-boundnames">13.6.4.2</a>, <a
+ href="#sec-function-definitions-static-semantics-boundnames">14.1.3</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-boundnames">14.2.2</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-boundnames">14.4.2</a>, <a
+ href="#sec-class-definitions-static-semantics-boundnames">14.5.2</a>, <a
+ href="#sec-imports-static-semantics-boundnames">15.2.1.2</a>, <a
+ href="#sec-exports-static-semantics-boundnames">15.2.2.1</a>.</p>
+
+ <div class="gp prod"><span class="nt">LexicalDeclaration</span> <span class="geq">:</span> <span class="nt">LetOrConst</span> <span class="nt">BindingList</span> <code class="t">;</code></div>
+ <ol class="proc">
+ <li>Return the BoundNames of <i>BindingList</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">BindingList</span> <span class="geq">:</span> <span class="nt">BindingList</span> <code class="t">,</code> <span class="nt">LexicalBinding</span></div>
+ <ol class="proc">
+ <li>Let <i>names</i> be the BoundNames of <i>BindingList</i>.</li>
+ <li>Append to <i>names</i> the elements of the BoundNames of <i>LexicalBinding.</i></li>
+ <li>Return <i>names</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">LexicalBinding</span> <span class="geq">:</span> <span class="nt">BindingIdentifier</span> <span class="nt">Initializer</span><sub>opt</sub></div>
+ <ol class="proc">
+ <li>Return the BoundNames of <i>BindingIdentifier</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">LexicalBinding</span> <span class="geq">:</span> <span class="nt">BindingPattern</span> <span class="nt">Initializer</span></div>
+ <ol class="proc">
+ <li>Return the BoundNames of <i>BindingPattern</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-let-and-const-declarations-static-semantics-isconstantdeclaration">
+ <h1><span class="secnum" id="sec-13.2.1.3"><a
+ href="#sec-let-and-const-declarations-static-semantics-isconstantdeclaration"
+ title="link to this section">13.2.1.3</a></span> Static Semantics: IsConstantDeclaration</h1>
+
+ <p>See also: <a href="#sec-function-definitions-static-semantics-hasname">14.1.8</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-hascomputedpropertykey">14.4.5</a>, <a
+ href="#sec-class-definitions-static-semantics-computedpropertycontains">14.5.5</a>.</p>
+
+ <div class="gp prod"><span class="nt">LexicalDeclaration</span> <span class="geq">:</span> <span class="nt">LetOrConst</span> <span class="nt">BindingList</span> <code class="t">;</code></div>
+ <ol class="proc">
+ <li>Return IsConstantDeclaration of <i>LetOrConst</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">LetOrConst</span> <span class="geq">:</span> <code class="t">let</code></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">LetOrConst</span> <span class="geq">:</span> <code class="t">const</code></div>
+ <ol class="proc">
+ <li>Return <b>true</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-let-and-const-declarations-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-13.2.1.4"><a href="#sec-let-and-const-declarations-runtime-semantics-evaluation"
+ title="link to this section">13.2.1.4</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">LexicalDeclaration</span> <span class="geq">:</span> <span class="nt">LetOrConst</span> <span class="nt">BindingList</span> <code class="t">;</code></div>
+ <ol class="proc">
+ <li>Let <i>next</i> be the result of evaluating <i>BindingList</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>next</i>).</li>
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<span style="font-family:
+ sans-serif">empty</span>).</li>
+ </ol>
+ <div class="gp prod"><span class="nt">BindingList</span> <span class="geq">:</span> <span class="nt">BindingList</span> <code class="t">,</code> <span class="nt">LexicalBinding</span></div>
+ <ol class="proc">
+ <li>Let <i>next</i> be the result of evaluating <i>BindingList</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>next</i>).</li>
+ <li>Return the result of evaluating <i>LexicalBinding</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">LexicalBinding</span> <span class="geq">:</span> <span class="nt">BindingIdentifier</span></div>
+ <ol class="proc">
+ <li>Let <i>env</i> be <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-execution-contexts">LexicalEnvironment</a>.</li>
+ <li>Return the result of performing BindingInitialization for <i>BindingIdentifier</i> passing <b>undefined</b> and
+ <i>env</i> as the arguments.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> A static semantics rule ensures that this form of <span class="nt">LexicalBinding</span>
+ never occurs in a <code>const</code> declaration.</p>
+ </div>
+
+ <div class="gp prod"><span class="nt">LexicalBinding</span> <span class="geq">:</span> <span class="nt">BindingIdentifier</span> <span class="nt">Initializer</span></div>
+ <ol class="proc">
+ <li>Let <i>rhs</i> be the result of evaluating <i>Initializer</i>.</li>
+ <li>Let <i>value</i> be <a href="#sec-getvalue">GetValue</a>(<i>rhs</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>value</i>).</li>
+ <li>If <a href="#sec-isanonymousfunctiondefinition">IsAnonymousFunctionDefinition</a>(<i>Initializer)</i> is
+ <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>hasNameProperty</i> be <a href="#sec-hasownproperty">HasOwnProperty</a>(<i>value</i>,
+ <code>"name"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>hasNameProperty</i>).</li>
+ <li>If <i>hasNameProperty</i> is <b>false</b>, then
+ <ol class="block">
+ <li><a href="#sec-setfunctionname">SetFunctionName</a>(<i>value</i>,
+ StringValue(<i>BindingIdentifier</i>)).</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Let <i>env</i> be <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-execution-contexts">LexicalEnvironment</a>.</li>
+ <li>Return the result of performing BindingInitialization for <i>BindingIdentifier</i> passing <i>value</i> and
+ <i>env</i> as the arguments.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">LexicalBinding</span> <span class="geq">:</span> <span class="nt">BindingPattern</span> <span class="nt">Initializer</span></div>
+ <ol class="proc">
+ <li>Let <i>rhs</i> be the result of evaluating <i>Initializer</i>.</li>
+ <li>Let <i>value</i> be <a href="#sec-getvalue">GetValue</a>(<i>rhs</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>value</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>value</i>) is not Object, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>Let <i>env</i> be <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-execution-contexts">LexicalEnvironment</a>.</li>
+ <li>Return the result of performing BindingInitialization for <i>BindingPattern</i> using <i>value</i> and <i>env</i> as
+ the <i>arguments</i>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-variable-statement">
+ <div class="front">
+ <h1><span class="secnum" id="sec-13.2.2"><a href="#sec-variable-statement" title="link to this section">13.2.2</a></span>
+ Variable Statement</h1>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> A <code>var</code> statement declares variables that are scoped to <a
+ href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-execution-contexts">VariableEnvironment</a>. Var variables are created when their containing <a
+ href="#sec-lexical-environments">Lexical Environment</a> is instantiated and are initialized to <b>undefined</b> when
+ created. Within the scope of any VariableEnvironemnt a common <span class="nt">Identifier</span> may appear in more than
+ one <span class="nt">VariableDeclaration</span> but those declarations collective define only one variable. A variable
+ defined by a <span class="nt">VariableDeclaration</span> with an <span class="nt">Initializer</span> is assigned the
+ value of its <span style="font-family: Times New Roman"><i>Initializer</i>’s</span> <span
+ class="nt">AssignmentExpression</span> when the <span class="nt">VariableDeclaration</span> is executed, not when the
+ variable is created.</p>
+ </div>
+
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">VariableStatement</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">var</code> <span class="nt">VariableDeclarationList</span><sub>[In, ?Yield]</sub> <code class="t">;</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">VariableDeclarationList</span><sub>[In, Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">VariableDeclaration</span><sub>[?In, ?Yield]</sub></div>
+ <div class="rhs"><span class="nt">VariableDeclarationList</span><sub>[?In, ?Yield]</sub> <code class="t">,</code> <span class="nt">VariableDeclaration</span><sub>[?In, ?Yield]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">VariableDeclaration</span><sub>[In, Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">BindingIdentifier</span><sub>[?Yield]</sub> <span class="nt">Initializer</span><sub>[?In, ?Yield]</sub><sub>opt</sub></div>
+ <div class="rhs"><span class="nt">BindingPattern</span><sub>[Yield]</sub> <span class="nt">Initializer</span><sub>[?In, ?Yield]</sub></div>
+ </div>
+ </div>
+
+ <section id="sec-variable-statement-static-semantics-boundnames">
+ <h1><span class="secnum" id="sec-13.2.2.1"><a href="#sec-variable-statement-static-semantics-boundnames"
+ title="link to this section">13.2.2.1</a></span> Static Semantics: BoundNames</h1>
+
+ <p>See also: <a href="#sec-let-and-const-declarations-static-semantics-boundnames">13.2.1.2</a>, <a
+ href="#sec-identifiers-static-semantics-boundnames">12.1.2</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-boundnames">13.6.4.2</a>, <a
+ href="#sec-function-definitions-static-semantics-boundnames">14.1.3</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-boundnames">14.2.2</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-boundnames">14.4.2</a>, <a
+ href="#sec-class-definitions-static-semantics-boundnames">14.5.2</a>, <a
+ href="#sec-imports-static-semantics-boundnames">15.2.1.2</a>, <a
+ href="#sec-exports-static-semantics-boundnames">15.2.2.1</a>.</p>
+
+ <div class="gp prod"><span class="nt">VariableDeclarationList</span> <span class="geq">:</span> <span class="nt">VariableDeclarationList</span> <code class="t">,</code> <span class="nt">VariableDeclaration</span></div>
+ <ol class="proc">
+ <li>Let <i>names</i> be BoundNames of <i>VariableDeclarationList</i>.</li>
+ <li>Append to <i>names</i> the elements of BoundNames of <i>VariableDeclaration.</i></li>
+ <li>Return <i>names</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">VariableDeclaration</span> <span class="geq">:</span> <span class="nt">BindingIdentifier</span> <span class="nt">Initializer</span><sub>opt</sub></div>
+ <ol class="proc">
+ <li>Return the BoundNames of <i>BindingIdentifier</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">VariableDeclaration</span> <span class="geq">:</span> <span class="nt">BindingPattern</span> <span class="nt">Initializer</span></div>
+ <ol class="proc">
+ <li>Return the BoundNames of <i>BindingPattern</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-variable-statement-static-semantics-vardeclarednames">
+ <h1><span class="secnum" id="sec-13.2.2.2"><a href="#sec-variable-statement-static-semantics-vardeclarednames"
+ title="link to this section">13.2.2.2</a></span> Static Semantics: VarDeclaredNames</h1>
+
+ <p>See also: <a href="#sec-statement-semantics-static-semantics-vardeclarednames">13.0.1</a>, <a
+ href="#sec-if-statement-static-semantics-vardeclarednames">13.5.1</a>, <a
+ href="#sec-do-while-statement-static-semantics-vardeclarednames">13.6.1.1</a>, <a
+ href="#sec-while-statement-static-semantics-vardeclarednames">13.6.2.1</a>, <a
+ href="#sec-for-statement-static-semantics-vardeclarednames">13.6.3.1</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-vardeclarednames">13.6.4.3</a>, <a
+ href="#sec-with-statement-static-semantics-vardeclarednames">13.10.2</a>, <a
+ href="#sec-switch-statement-static-semantics-vardeclarednames">13.11.4</a>, <a
+ href="#sec-static-semantics-currentlabelset">13.12.2</a>, 0, <a
+ href="#sec-function-definitions-static-semantics-referencessuper">14.1.16</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-vardeclarednames">14.4.12</a>, <a
+ href="#sec-class-definitions-static-semantics-vardeclarednames">14.5.15</a>, <a
+ href="#sec-scripts-static-semantics-vardeclarednames">15.1.5</a>, <a
+ href="#sec-module-static-semantics-static-semantics-vardeclarednames">15.2.0.13</a>.</p>
+
+ <div class="gp prod"><span class="nt">VariableStatement</span> <span class="geq">:</span> <code class="t">var</code> <span class="nt">VariableDeclarationList</span></div>
+ <ol class="proc">
+ <li>Return BoundNames of <i>VariableDeclarationList.</i></li>
+ </ol>
+ </section>
+
+ <section id="sec-variable-statement-static-semantics-varscopeddeclarations">
+ <h1><span class="secnum" id="sec-13.2.2.3"><a href="#sec-variable-statement-static-semantics-varscopeddeclarations"
+ title="link to this section">13.2.2.3</a></span> Static Semantics: VarScopedDeclarations</h1>
+
+ <p>See also: <a href="#sec-statement-semantics-static-semantics-varscopeddeclarations">13.0.2</a>, <a
+ href="#sec-block-static-semantics-varscopeddeclarations">13.1.9</a>, <a
+ href="#sec-if-statement-static-semantics-varscopeddeclarations">13.5.2</a>, <a
+ href="#sec-do-while-statement-static-semantics-varscopeddeclarations">13.6.1.2</a>, <a
+ href="#sec-while-statement-static-semantics-varscopeddeclarations">13.6.2.2</a>, <a
+ href="#sec-for-statement-static-semantics-varscopeddeclarations">13.6.3.2</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-varscopeddeclarations">13.6.4.4</a>, <a
+ href="#sec-with-statement-static-semantics-varscopeddeclarations">13.10.3</a>, <a
+ href="#sec-switch-statement-static-semantics-varscopeddeclarations">13.11.5</a>, <a
+ href="#sec-labelled-statements-static-semantics-varscopeddeclarations">13.12.4</a>, <a
+ href="#sec-try-statement-static-semantics-varscopeddeclarations">13.14.3</a>, <a
+ href="#sec-function-definitions-static-semantics-varscopeddeclarations">14.1.18</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-varscopeddeclarations">14.2.14</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-varscopeddeclarations">14.4.13</a>, <a
+ href="#sec-scripts-static-semantics-varscopeddeclarations">15.1.6</a>, <a
+ href="#sec-module-static-semantics-static-semantics-varscopeddeclarations">15.2.0.14</a>.</p>
+
+ <div class="gp prod"><span class="nt">VariableDeclarationList</span> <span class="geq">:</span> <span class="nt">VariableDeclaration</span></div>
+ <ol class="proc">
+ <li>Return a new <a href="#sec-list-and-record-specification-type">List</a> containing <i>VariableDeclaration.</i></li>
+ </ol>
+ <div class="gp prod"><span class="nt">VariableDeclarationList</span> <span class="geq">:</span> <span class="nt">VariableDeclarationList</span> <code class="t">,</code> <span class="nt">VariableDeclaration</span></div>
+ <ol class="proc">
+ <li>Let <i>declarations</i> be VarScopedDeclarations of <i>VariableDeclarationList</i>.</li>
+ <li>Append <i>VariableDeclaration</i> to <i>declarations.</i></li>
+ <li>Return <i>declarations</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-variable-statement-runtime-semantics-bindinginitialization">
+ <h1><span class="secnum" id="sec-13.2.2.4"><a href="#sec-variable-statement-runtime-semantics-bindinginitialization"
+ title="link to this section">13.2.2.4</a></span> Runtime Semantics: BindingInitialization</h1>
+
+ <p>With arguments <var>value</var> and <var>environment</var>.</p>
+
+ <p>See also: <a href="#sec-array-comprehension-runtime-semantics-bindinginitialization">12.2.4.2.2</a>, <b>Error! <a
+ href="#sec-reference-specification-type">Reference</a> source not found.</b>, <a
+ href="#sec-destructuring-binding-patterns-static-semantics-issimpleparameterlist">13.2.3.4</a>, <a
+ href="#sec-try-statement-static-semantics-varscopeddeclarations">13.14.3</a>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> <b>undefined</b> is passed for <var>environment</var> to indicate that a <a
+ href="#sec-putvalue">PutValue</a> operation should be used to assign the initialization value. This is the case for
+ <code>var</code> statements formal parameter lists of non-strict functions. In those cases a lexical binding is hosted
+ and preinitialized prior to evaluation of its initializer.</p>
+ </div>
+
+ <div class="gp prod"><span class="nt">VariableDeclaration</span> <span class="geq">:</span> <span class="nt">BindingIdentifier</span></div>
+ <ol class="proc">
+ <li>Return the result of performing BindingInitialization for <i>BindingIdentifier</i> passing <i>value</i> and
+ <b>undefined</b> as the arguments.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">VariableDeclaration</span> <span class="geq">:</span> <span class="nt">BindingIdentifier</span> <span class="nt">Initializer</span></div>
+ <ol class="proc">
+ <li>Return the result of performing BindingInitialization for <i>BindingIdentifier</i> passing <i>value</i> and
+ <b>undefined</b> as the arguments.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">VariableDeclaration</span> <span class="geq">:</span> <span class="nt">BindingPattern</span> <span class="nt">Initializer</span></div>
+ <ol class="proc">
+ <li>Return the result of performing BindingInitialization for <i>BindingPattern</i> passing <i>value</i> and
+ <b>undefined</b> as the arguments.</li>
+ </ol>
+ </section>
+
+ <section id="sec-variable-statement-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-13.2.2.5"><a href="#sec-variable-statement-runtime-semantics-evaluation"
+ title="link to this section">13.2.2.5</a></span> <span style="font-family: sans-serif">Runtime</span> Semantics:
+ Evaluation</h1>
+ <div class="gp prod"><span class="nt">VariableStatement</span> <span class="geq">:</span> <code class="t">var</code> <span class="nt">VariableDeclarationList</span> <code class="t">;</code></div>
+ <ol class="proc">
+ <li>Let <i>next</i> be the result of evaluating <i>VariableDeclarationList</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>next</i>).</li>
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>( <span style="font-family:
+ sans-serif">empty</span>).</li>
+ </ol>
+ <div class="gp prod"><span class="nt">VariableDeclarationList</span> <span class="geq">:</span> <span class="nt">VariableDeclarationList</span> <code class="t">,</code> <span class="nt">VariableDeclaration</span></div>
+ <ol class="proc">
+ <li>Let <i>next</i> be the result of evaluating <i>VariableDeclarationList</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>next</i>).</li>
+ <li>Return the result of evaluating <i>VariableDeclaration</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">VariableDeclaration</span> <span class="geq">:</span> <span class="nt">BindingIdentifier</span></div>
+ <ol class="proc">
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<span style="font-family:
+ sans-serif">empty</span>).</li>
+ </ol>
+ <div class="gp prod"><span class="nt">VariableDeclaration</span> <span class="geq">:</span> <span class="nt">BindingIdentifier</span> <span class="nt">Initializer</span></div>
+ <ol class="proc">
+ <li>Let <i>rhs</i> be the result of evaluating <i>Initializer</i>.</li>
+ <li>Let <i>value</i> be <a href="#sec-getvalue">GetValue</a>(<i>rhs</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>value</i>).</li>
+ <li>If <a href="#sec-isanonymousfunctiondefinition">IsAnonymousFunctionDefinition</a>(<i>Initializer)</i> is
+ <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>hasNameProperty</i> be <a href="#sec-hasownproperty">HasOwnProperty</a>(<i>value</i>,
+ <code>"name"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>hasNameProperty</i>).</li>
+ <li>If <i>hasNameProperty</i> is <b>false</b>, then
+ <ol class="block">
+ <li>Perform <a href="#sec-setfunctionname">SetFunctionName</a>(<i>value</i>,
+ StringValue(<i>BindingIdentifier</i>)).</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Return the result of performing BindingInitialization for <i>BindingIdentifier</i> passing <i>value</i> and
+ <b>undefined</b> as the arguments.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE </span> If a <i>VariableDeclaration</i> is nested within a with statement and the
+ <i>Identifier</i> in the <i>VariableDeclaration</i> is the same as a property name of the binding object of the with
+ statement’s <a href="#sec-object-environment-records">object environment record</a>, then step 3 will assign value
+ to the property instead of assigning to the <a href="#sec-execution-contexts">VariableEnvironment</a> binding of the
+ <i>Identifier</i>.</p>
+ </div>
+
+ <div class="gp prod"><span class="nt">VariableDeclaration</span> <span class="geq">:</span> <span class="nt">BindingPattern</span> <span class="nt">Initializer</span></div>
+ <ol class="proc">
+ <li>Let <i>rhs</i> be the result of evaluating <i>Initializer</i>.</li>
+ <li>Let <i>rval</i> be <a href="#sec-getvalue">GetValue</a>(<i>rhs</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>rval</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>rval</i>) is not Object, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>Return the result of performing BindingInitialization for <i>BindingPattern</i> passing <i>rval</i> and
+ <b>undefined</b> as arguments.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-destructuring-binding-patterns">
+ <div class="front">
+ <h1><span class="secnum" id="sec-13.2.3"><a href="#sec-destructuring-binding-patterns"
+ title="link to this section">13.2.3</a></span> Destructuring Binding Patterns</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">BindingPattern</span><sub>[Yield,GeneratorParameter]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">ObjectBindingPattern</span><sub>[?Yield,?GeneratorParameter]</sub></div>
+ <div class="rhs"><span class="nt">ArrayBindingPattern</span><sub>[?Yield,?GeneratorParameter]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ObjectBindingPattern</span><sub>[Yield,GeneratorParameter]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">{</code> <code class="t">}</code></div>
+ <div class="rhs"><code class="t">{</code> <span class="nt">BindingPropertyList</span><sub>[?Yield,?GeneratorParameter]</sub> <code class="t">}</code></div>
+ <div class="rhs"><code class="t">{</code> <span class="nt">BindingPropertyList</span><sub>[?Yield,?GeneratorParameter]</sub> <code class="t">,</code> <code class="t">}</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ArrayBindingPattern</span><sub>[Yield,GeneratorParameter]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">[</code> <span class="nt">Elision</span><sub>opt</sub> <span class="nt">BindingRestElement</span><sub>[?Yield, ?GeneratorParameter]</sub><sub>opt</sub> <code class="t">]</code></div>
+ <div class="rhs"><code class="t">[</code> <span class="nt">BindingElementList</span><sub>[?Yield, ?GeneratorParameter]</sub> <code class="t">]</code></div>
+ <div class="rhs"><code class="t">[</code> <span class="nt">BindingElementList</span><sub>[?Yield, ?GeneratorParameter]</sub> <code class="t">,</code> <span class="nt">Elision</span><sub>opt</sub> <span class="nt">BindingRestElement</span><sub>[?Yield, ?GeneratorParameter]</sub><sub>opt</sub> <code class="t">]</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">BindingPropertyList</span><sub>[Yield,GeneratorParameter]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">BindingProperty</span><sub>[?Yield, ?GeneratorParameter]</sub></div>
+ <div class="rhs"><span class="nt">BindingPropertyList</span><sub>[?Yield, ?GeneratorParameter]</sub> <code class="t">,</code> <span class="nt">BindingProperty</span><sub>[?Yield, ?GeneratorParameter]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">BindingElementList</span><sub>[Yield,GeneratorParameter]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">BindingElisionElement</span><sub>[?Yield, ?GeneratorParameter]</sub></div>
+ <div class="rhs"><span class="nt">BindingElementList</span><sub>[?Yield, ?GeneratorParameter]</sub> <code class="t">,</code> <span class="nt">BindingElisionElement</span><sub>[?Yield, ?GeneratorParameter]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">BindingElisionElement</span><sub>[Yield,GeneratorParameter]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">Elision</span><sub>opt</sub> <span class="nt">BindingElement</span><sub>[?Yield, ?GeneratorParameter]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">BindingProperty</span><sub>[Yield,GeneratorParameter]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">SingleNameBinding</span><sub>[?Yield, ?GeneratorParameter]</sub></div>
+ <div class="rhs"><span class="nt">PropertyName</span><sub>[?Yield, ?GeneratorParameter]</sub> <code class="t">:</code> <span class="nt">BindingElement</span><sub>[?Yield, ?GeneratorParameter]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">BindingElement</span><sub>[Yield,GeneratorParameter]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">SingleNameBinding</span><sub>[?Yield, ?GeneratorParameter]</sub></div>
+ <div class="rhs"><span class="grhsannot">[+GeneratorParameter]</span> <span class="nt">BindingPattern</span><sub>[?Yield,GeneratorParameter]</sub> <span class="nt">Initializer</span><sub>[In]</sub><sub>opt</sub></div>
+ <div class="rhs"><span class="grhsannot">[~GeneratorParameter]</span> <span class="nt">BindingPattern</span><sub>[?Yield]</sub> <span class="nt">Initializer</span><sub>[In, ?Yield]</sub><sub>opt</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">SingleNameBinding</span><sub>[Yield,GeneratorParameter]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="grhsannot">[+GeneratorParameter]</span> <span class="nt">BindingIdentifier</span><sub>[Yield]</sub> <span class="nt">Initializer</span><sub>[In]</sub><sub>opt</sub></div>
+ <div class="rhs"><span class="grhsannot">[~GeneratorParameter]</span> <span class="nt">BindingIdentifier</span><sub>[?Yield]</sub> <span class="nt">Initializer</span><sub>[In, ?Yield]</sub><sub>opt</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">BindingRestElement</span><sub>[Yield, GeneratorParameter]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="grhsannot">[+GeneratorParameter]</span> <code class="t">...</code> <span class="nt">BindingIdentifier</span><sub>[Yield]</sub></div>
+ <div class="rhs"><span class="grhsannot">[~GeneratorParameter]</span> <code class="t">...</code> <span class="nt">BindingIdentifier</span><sub>[?Yield]</sub></div>
+ </div>
+ </div>
+
+ <section id="sec-destructuring-binding-patterns-static-semantics-boundnames">
+ <h1><span class="secnum" id="sec-13.2.3.1"><a href="#sec-destructuring-binding-patterns-static-semantics-boundnames"
+ title="link to this section">13.2.3.1</a></span> Static Semantics: BoundNames</h1>
+
+ <p>See also: <a href="#sec-let-and-const-declarations-static-semantics-boundnames">13.2.1.2</a>, <a
+ href="#sec-variable-statement-static-semantics-boundnames">13.2.2.1</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-boundnames">13.6.4.2</a>, <a
+ href="#sec-function-definitions-static-semantics-boundnames">14.1.3</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-boundnames">14.2.2</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-boundnames">14.4.2</a>, <a
+ href="#sec-class-definitions-static-semantics-boundnames">14.5.2</a>, <a
+ href="#sec-imports-static-semantics-boundnames">15.2.1.2</a>, <a
+ href="#sec-exports-static-semantics-boundnames">15.2.2.1</a>.</p>
+
+ <div class="gp prod"><span class="nt">ObjectBindingPattern</span> <span class="geq">:</span> <code class="t">{</code> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return an empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ArrayBindingPattern</span> <span class="geq">:</span> <code class="t">[</code> <span class="nt">Elision</span><sub>opt</sub> <code class="t">]</code></div>
+ <ol class="proc">
+ <li>Return an empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ArrayBindingPattern</span> <span class="geq">:</span> <code class="t">[</code> <span class="nt">Elision</span><sub>opt</sub> <span class="nt">BindingRestElement</span> <code class="t">]</code></div>
+ <ol class="proc">
+ <li>Return the BoundNames of <i>BindingRestElement</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ArrayBindingPattern</span> <span class="geq">:</span> <code class="t">[</code> <span class="nt">BindingElementList</span> <code class="t">,</code> <span class="nt">Elision</span><sub>opt</sub> <code class="t">]</code></div>
+ <ol class="proc">
+ <li>Return the BoundNames of <i>BindingElementList</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ArrayBindingPattern</span> <span class="geq">:</span> <code class="t">[</code> <span class="nt">BindingElementList</span> <code class="t">,</code> <span class="nt">Elision</span><sub>opt</sub> <span class="nt">BindingRestElement</span> <code class="t">]</code></div>
+ <ol class="proc">
+ <li>Let <i>names</i> be BoundNames of <i>BindingElementList</i>.</li>
+ <li>Append to <i>names</i> the elements of BoundNames of <i>BindingRestElement.</i></li>
+ <li>Return <i>names</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">BindingPropertyList</span> <span class="geq">:</span> <span class="nt">BindingPropertyList</span> <code class="t">,</code> <span class="nt">BindingProperty</span></div>
+ <ol class="proc">
+ <li>Let <i>names</i> be BoundNames of <i>BindingPropertyList</i>.</li>
+ <li>Append to <i>names</i> the elements of BoundNames of <i>BindingProperty.</i></li>
+ <li>Return <i>names</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">BindingElementList</span> <span class="geq">:</span> <span class="nt">BindingElementList</span> <code class="t">,</code> <span class="nt">BindingElisionElement</span></div>
+ <ol class="proc">
+ <li>Let <i>names</i> be BoundNames of <i>BindingElementList</i>.</li>
+ <li>Append to <i>names</i> the elements of BoundNames of <i>BindingElisionElement.</i></li>
+ <li>Return <i>names</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">BindingElisionElement</span> <span class="geq">:</span> <span class="nt">Elision</span><sub>opt</sub> <span class="nt">BindingElement</span></div>
+ <ol class="proc">
+ <li>Return BoundNames of <i>BindingElement</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">BindingProperty</span> <span class="geq">:</span> <span class="nt">PropertyName</span> <code class="t">:</code> <span class="nt">BindingElement</span></div>
+ <ol class="proc">
+ <li>Return the BoundNames of <i>BindingElement</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">SingleNameBinding</span> <span class="geq">:</span> <span class="nt">BindingIdentifier</span> <span class="nt">Initializer</span><sub>opt</sub></div>
+ <ol class="proc">
+ <li>Return the BoundNames of <i>BindingIdentifier</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">BindingElement</span> <span class="geq">:</span> <span class="nt">BindingPattern</span> <span class="nt">Initializer</span><sub>opt</sub></div>
+ <ol class="proc">
+ <li>Return the BoundNames of <i>BindingPattern</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-destructuring-binding-patterns-static-semantics-containsexpression">
+ <h1><span class="secnum" id="sec-13.2.3.2"><a
+ href="#sec-destructuring-binding-patterns-static-semantics-containsexpression"
+ title="link to this section">13.2.3.2</a></span> Static Semantics: ContainsExpression</h1>
+
+ <p>See also: <a href="#sec-function-definitions-static-semantics-containsexpression">14.1.5</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-containsexpression">14.2.4</a>.</p>
+
+ <div class="gp prod"><span class="nt">ObjectBindingPattern</span> <span class="geq">:</span> <code class="t">{</code> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ArrayBindingPattern</span> <span class="geq">:</span> <code class="t">[</code> <span class="nt">Elision</span><sub>opt</sub> <code class="t">]</code></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ArrayBindingPattern</span> <span class="geq">:</span> <code class="t">[</code> <span class="nt">Elision</span><sub>opt</sub> <span class="nt">BindingRestElement</span> <code class="t">]</code></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ArrayBindingPattern</span> <span class="geq">:</span> <code class="t">[</code> <span class="nt">BindingElementList</span> <code class="t">,</code> <span class="nt">Elision</span><sub>opt</sub> <code class="t">]</code></div>
+ <ol class="proc">
+ <li>Return ContainsExpression of <i>BindingElementList</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ArrayBindingPattern</span> <span class="geq">:</span> <code class="t">[</code> <span class="nt">BindingElementList</span> <code class="t">,</code> <span class="nt">Elision</span><sub>opt</sub> <span class="nt">BindingRestElement</span> <code class="t">]</code></div>
+ <ol class="proc">
+ <li>Return ContainsExpression of <i>BindingElementList</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">BindingPropertyList</span> <span class="geq">:</span> <span class="nt">BindingPropertyList</span> <code class="t">,</code> <span class="nt">BindingProperty</span></div>
+ <ol class="proc">
+ <li>Let <i>has</i> be ContainsExpression of <i>BindingPropertyList</i>.</li>
+ <li>If <i>has</i> is <b>true</b>, return <b>true</b><i>.</i></li>
+ <li>Return ContainsExpression of <i>BindingProperty</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">BindingElementList</span> <span class="geq">:</span> <span class="nt">BindingElementList</span> <code class="t">,</code> <span class="nt">BindingElisionElement</span></div>
+ <ol class="proc">
+ <li>Let <i>has</i> be ContainsExpression of <i>BindingElementList</i>.</li>
+ <li>If <i>has</i> is <b>true</b>, return <b>true</b><i>.</i></li>
+ <li>Return ContainsExpression of <i>BindingElisionElement</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">BindingElisionElement</span> <span class="geq">:</span> <span class="nt">Elision</span><sub>opt</sub> <span class="nt">BindingElement</span></div>
+ <ol class="proc">
+ <li>Return ContainsExpression of <i>BindingElement</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">BindingProperty</span> <span class="geq">:</span> <span class="nt">PropertyName</span> <code class="t">:</code> <span class="nt">BindingElement</span></div>
+ <ol class="proc">
+ <li>Let <i>has</i> be IsComputedPropertyKey of <i>PropertyName</i>.</li>
+ <li>If <i>has</i> is <b>true</b>, return <b>true</b><i>.</i></li>
+ <li>Return the ContainsExpression of <i>BindingElement</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">BindingElement</span> <span class="geq">:</span> <span class="nt">BindingPattern</span> <span class="nt">Initializer</span></div>
+ <ol class="proc">
+ <li>Return <b>true</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">SingleNameBinding</span> <span class="geq">:</span> <span class="nt">BindingIdentifier</span></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">SingleNameBinding</span> <span class="geq">:</span> <span class="nt">BindingIdentifier</span> <span class="nt">Initializer</span></div>
+ <ol class="proc">
+ <li>Return <b>true</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-destructuring-binding-patterns-static-semantics-hasinitializer">
+ <h1><span class="secnum" id="sec-13.2.3.3"><a href="#sec-destructuring-binding-patterns-static-semantics-hasinitializer"
+ title="link to this section">13.2.3.3</a></span> Static Semantics: HasInitializer</h1>
+
+ <p>See also: <a href="#sec-destructuring-binding-patterns-static-semantics-hasinitializer">13.2.3.3</a>, <a
+ href="#sec-function-definitions-static-semantics-hasinitializer">14.1.7</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-hasinitializer">14.2.7</a>.</p>
+
+ <div class="gp prod"><span class="nt">BindingElement</span> <span class="geq">:</span> <span class="nt">BindingPattern</span></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">BindingElement</span> <span class="geq">:</span> <span class="nt">BindingPattern</span> <span class="nt">Initializer</span></div>
+ <ol class="proc">
+ <li>Return <b>true</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">SingleNameBinding</span> <span class="geq">:</span> <span class="nt">BindingIdentifier</span></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">SingleNameBinding</span> <span class="geq">:</span> <span class="nt">BindingIdentifier</span> <span class="nt">Initializer</span></div>
+ <ol class="proc">
+ <li>Return <b>true</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-destructuring-binding-patterns-static-semantics-issimpleparameterlist">
+ <h1><span class="secnum" id="sec-13.2.3.4"><a
+ href="#sec-destructuring-binding-patterns-static-semantics-issimpleparameterlist"
+ title="link to this section">13.2.3.4</a></span> Static Semantics: IsSimpleParameterList</h1>
+
+ <p>See also: <a href="#sec-function-definitions-static-semantics-isfunctiondefinition">14.1.11</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-hasname">14.2.8</a>.</p>
+
+ <div class="gp prod"><span class="nt">BindingElement</span> <span class="geq">:</span> <span class="nt">BindingPattern</span></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">BindingElement</span> <span class="geq">:</span> <span class="nt">BindingPattern</span> <span class="nt">Initializer</span></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">SingleNameBinding</span> <span class="geq">:</span> <span class="nt">BindingIdentifier</span></div>
+ <ol class="proc">
+ <li>Return <b>true</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">SingleNameBinding</span> <span class="geq">:</span> <span class="nt">BindingIdentifier</span> <span class="nt">Initializer</span></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-destructuring-binding-patterns-runtime-semantics-bindinginitialization">
+ <h1><span class="secnum" id="sec-13.2.3.5"><a
+ href="#sec-destructuring-binding-patterns-runtime-semantics-bindinginitialization"
+ title="link to this section">13.2.3.5</a></span> Runtime Semantics: BindingInitialization</h1>
+
+ <p>With parameters <var>value</var> and <var>environment</var>.</p>
+
+ <p>See also: <a href="#sec-array-comprehension-runtime-semantics-bindinginitialization">12.2.4.2.2</a>, <b>Error! <a
+ href="#sec-reference-specification-type">Reference</a> source not found.</b>, <a
+ href="#sec-variable-statement-static-semantics-vardeclarednames">13.2.2.2</a>, <a
+ href="#sec-try-statement-static-semantics-varscopeddeclarations">13.14.3</a>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> When <b>undefined</b> is passed for <var>environment</var> it indicates that a <a
+ href="#sec-putvalue">PutValue</a> operation should be used to assign the initialization value. This is the case for
+ formal parameter lists of non-strict functions. In that case the formal parameter bindings are preinitialized in order
+ to deal with the possibility of multiple parameters with the same name.</p>
+ </div>
+
+ <div class="gp prod"><span class="nt">BindingPattern</span> <span class="geq">:</span> <span class="nt">ObjectBindingPattern</span></div>
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>value</i>) is Object</li>
+ <li>Return the result of performing BindingInitialization for <i>ObjectBindingPattern</i> using <i>value</i> and
+ <i>environment</i> as arguments.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">BindingPattern</span> <span class="geq">:</span> <span class="nt">ArrayBindingPattern</span></div>
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>value</i>) is Object</li>
+ <li>Let <i>iterator</i> be <a href="#sec-getiterator">GetIterator</a>(<i>value</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>iterator</i>).</li>
+ <li>Return the result of performing IteratorBindingInitialization for <i>ArrayBindingPattern</i> using <i>iterator</i>,
+ and <i>environment</i> as arguments.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ObjectBindingPattern</span> <span class="geq">:</span> <code class="t">{</code> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<span style="font-family:
+ sans-serif">empty</span>).</li>
+ </ol>
+ <div class="gp prod"><span class="nt">BindingPropertyList</span> <span class="geq">:</span> <span class="nt">BindingPropertyList</span> <code class="t">,</code> <span class="nt">BindingProperty</span></div>
+ <ol class="proc">
+ <li>Let <i>status</i> be the result of performing BindingInitialization for <i>BindingPropertyList</i> using
+ <i>value</i> and <i>environment</i> as arguments.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Return the result of performing BindingInitialization for <i>BindingProperty</i> using <i>value</i> and
+ <i>environment</i> as arguments.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">BindingProperty</span> <span class="geq">:</span> <span class="nt">SingleNameBinding</span></div>
+ <ol class="proc">
+ <li>Let <i>name</i> be the string that is the only element of BoundNames of <i>SingleNameBinding</i>.</li>
+ <li>Return the result of performing KeyedBindingInitialization for <i>SingleNameBinding</i> using <i>value</i>,
+ <i>environment</i>, and <i>name</i> as the arguments.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">BindingProperty</span> <span class="geq">:</span> <span class="nt">PropertyName</span> <code class="t">:</code> <span class="nt">BindingElement</span></div>
+ <ol class="proc">
+ <li>Let <i>P</i> be the result of evaluating <i>PropertyName</i></li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>P</i>).</li>
+ <li>Return the result of performing KeyedBindingInitialization for <i>BindingElement</i> using <i>value</i>,
+ <i>environment</i>, and <i>P</i> as arguments.</li>
+ </ol>
+ </section>
+
+ <section id="sec-destructuring-binding-patterns-runtime-semantics-iteratorbindinginitialization">
+ <h1><span class="secnum" id="sec-13.2.3.6"><a
+ href="#sec-destructuring-binding-patterns-runtime-semantics-iteratorbindinginitialization"
+ title="link to this section">13.2.3.6</a></span> Runtime Semantics: IteratorBindingInitialization</h1>
+
+ <p>With parameters <var>iterator,</var> and <var>environment</var>.</p>
+
+ <p>See also: <a href="#sec-function-definitions-runtime-semantics-iteratorbindinginitialization">14.1.20</a>, .</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> When <b>undefined</b> is passed for <var>environment</var> it indicates that a <a
+ href="#sec-putvalue">PutValue</a> operation should be used to assign the initialization value. This is the case for
+ formal parameter lists of non-strict functions. In that case the formal parameter bindings are preinitialized in order
+ to deal with the possibility of multiple parameters with the same name.</p>
+ </div>
+
+ <div class="gp prod"><span class="nt">ArrayBindingPattern</span> <span class="geq">:</span> <code class="t">[</code> <code class="t">]</code></div>
+ <ol class="proc">
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<span style="font-family:
+ sans-serif">empty</span>).</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ArrayBindingPattern</span> <span class="geq">:</span> <code class="t">[</code> <span class="nt">Elision</span> <code class="t">]</code></div>
+ <ol class="proc">
+ <li>Return the result of performing IteratorDestructuringAssignmentEvaluation of <i>Elision</i> with <i>iterator</i> as
+ the argument.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ArrayBindingPattern</span> <span class="geq">:</span> <code class="t">[</code> <span class="nt">Elision</span><sub>opt</sub> <span class="nt">BindingRestElement</span> <code class="t">]</code></div>
+ <ol class="proc">
+ <li>If <i>Elision</i> is present, then
+ <ol class="block">
+ <li>Let <i>status</i> be the result of performing IteratorDestructuringAssignmentEvaluation of <i>Elision</i> with
+ <i>iterator</i> as the argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ </ol>
+ </li>
+ <li>Return the result of performing IteratorBindingInitialization for <i>BindingRestElement</i> using <i>iterator</i>
+ and <i>environment</i> as arguments.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ArrayBindingPattern</span> <span class="geq">:</span> <code class="t">[</code> <span class="nt">BindingElementList</span> <code class="t">]</code></div>
+ <ol class="proc">
+ <li>Return the result of performing IteratorBindingInitialization for <i>BindingElementList</i> using <i>iterator</i>
+ and <i>environment</i> as arguments.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ArrayBindingPattern</span> <span class="geq">:</span> <code class="t">[</code> <span class="nt">BindingElementList</span> <code class="t">,</code> <code class="t">]</code></div>
+ <ol class="proc">
+ <li>Return the result of performing IteratorBindingInitialization for <i>BindingElementList</i> using <i>iterator</i>
+ and <i>environment</i> as arguments.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ArrayBindingPattern</span> <span class="geq">:</span> <code class="t">[</code> <span class="nt">BindingElementList</span> <code class="t">,</code> <span class="nt">Elision</span> <code class="t">]</code></div>
+ <ol class="proc">
+ <li>Let <i>status</i> be the result of performing IteratorBindingInitialization for <i>BindingElementList</i> using
+ <i>iterator</i> and <i>environment</i> as arguments.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Return the result of performing IteratorDestructuringAssignmentEvaluation of <i>Elision</i> with <i>iterator</i> as
+ the argument.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ArrayBindingPattern</span> <span class="geq">:</span> <code class="t">[</code> <span class="nt">BindingElementList</span> <code class="t">,</code> <span class="nt">Elision</span><sub>opt</sub> <span class="nt">BindingRestElement</span> <code class="t">]</code></div>
+ <ol class="proc">
+ <li>Let <i>status</i> be the result of performing IteratorBindingInitialization for <i>BindingElementList</i> using
+ <i>iterator</i> and <i>environment</i> as arguments.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>If <i>Elision</i> is present, then
+ <ol class="block">
+ <li>Let <i>status</i> be the result of performing IteratorDestructuringAssignmentEvaluation of <i>Elision</i> with
+ <i>iterator</i> as the argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ </ol>
+ </li>
+ <li>Return the result of performing IteratorBindingInitialization for <i>BindingRestElement</i> using <i>iterator</i>
+ and <i>environment</i> as arguments.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">BindingElementList</span> <span class="geq">:</span> <span class="nt">BindingElisionElement</span></div>
+ <ol class="proc">
+ <li>Return the result of performing IteratorBindingInitialization for <i>BindingElisionElement</i> using
+ <i>iterator</i> and <i>environment</i> as arguments.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">BindingElementList</span> <span class="geq">:</span> <span class="nt">BindingElementList</span> <code class="t">,</code> <span class="nt">BindingElisionElement</span></div>
+ <ol class="proc">
+ <li>Let <i>status</i> be the result of performing IteratorBindingInitialization for <i>BindingElementList</i> iterator
+ and <i>environment</i> as arguments.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Return the result of performing IteratorBindingInitialization for <i>BindingElisionElement</i> using <i>iterator</i>
+ and <i>environment</i> as arguments.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">BindingElisionElement</span> <span class="geq">:</span> <span class="nt">BindingElement</span></div>
+ <ol class="proc">
+ <li>Return the result of performing IteratorBindingInitialization of <i>BindingElement</i> with <i>iterator</i> and
+ <i>environment</i> as the arguments.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">BindingElisionElement</span> <span class="geq">:</span> <span class="nt">Elision</span> <span class="nt">BindingElement</span></div>
+ <ol class="proc">
+ <li>Let <i>status</i> be the result of performing IteratorDestructuringAssignmentEvaluation of <i>Elision</i> with
+ <i>iterator</i> as the argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Return the result of performing IteratorBindingInitialization of <i>BindingElement</i> with <i>iterator</i> and
+ <i>environment</i> as the arguments.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">BindingElement</span> <span class="geq">:</span> <span class="nt">SingleNameBinding</span></div>
+ <ol class="proc">
+ <li>Return the result of performing IteratorBindingInitialization for <i>SingleNameBinding</i> using <i>iterator
+ and</i> <i>environment</i> as the arguments.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">SingleNameBinding</span> <span class="geq">:</span> <span class="nt">BindingIdentifier</span> <span class="nt">Initializer</span><sub>opt</sub></div>
+ <ol class="proc">
+ <li>Let <i>next</i> be <a href="#sec-iteratorstep">IteratorStep</a>(<i>iterator</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>next</i>).</li>
+ <li>If <i>next</i> is <b>false</b>, then let <i>v</i> be <b>undefined</b></li>
+ <li>Else
+ <ol class="block">
+ <li>Let <i>v</i> be <a href="#sec-iteratorvalue">IteratorValue</a>(<i>next</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>v</i>).</li>
+ </ol>
+ </li>
+ <li>If <i>Initializer</i> is present and <i>v</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>defaultValue</i> be the result of evaluating <i>Initializer</i>.</li>
+ <li>Let <i>v</i> be <a href="#sec-getvalue">GetValue</a>(<i>defaultValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>v</i>).</li>
+ <li>If <a href="#sec-isanonymousfunctiondefinition">IsAnonymousFunctionDefinition</a>(<i>Initializer)</i> is
+ <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>hasNameProperty</i> be <a href="#sec-hasownproperty">HasOwnProperty</a>(<i>v</i>,
+ <code>"name"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>hasNameProperty</i>).</li>
+ <li>If <i>hasNameProperty</i> is <b>false</b>, then
+ <ol class="block">
+ <li><a href="#sec-setfunctionname">SetFunctionName</a>(<i>v</i>,
+ StringValue(<i>BindingIdentifier</i>)).</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Return the result of performing BindingInitialization for <i>BindingIdentifier</i> passing <i>v</i> and
+ <i>environment</i> as arguments.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">BindingElement</span> <span class="geq">:</span> <span class="nt">BindingPattern</span> <span class="nt">Initializer</span><sub>opt</sub></div>
+ <ol class="proc">
+ <li>Let <i>next</i> be <a href="#sec-iteratorstep">IteratorStep</a>(<i>iterator</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>next</i>).</li>
+ <li>If <i>next</i> is <b>false</b>, then let <i>v</i> be <b>undefined</b></li>
+ <li>Else
+ <ol class="block">
+ <li>Let <i>v</i> be <a href="#sec-iteratorvalue">IteratorValue</a>(<i>next</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>v</i>).</li>
+ </ol>
+ </li>
+ <li>If <i>Initializer</i> is present and <i>v</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>defaultValue</i> be the result of evaluating <i>Initializer</i>.</li>
+ <li>Let <i>v</i> be <a href="#sec-getvalue">GetValue</a>(<i>defaultValue</i>)</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>v</i>).</li>
+ </ol>
+ </li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>v</i>) is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>Return the result of performing BindingInitialization of <i>BindingPattern</i> with <i>v</i> and <i>environment</i>
+ as the arguments.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">BindingRestElement</span> <span class="geq">:</span> <code class="t">...</code> <span class="nt">BindingIdentifier</span></div>
+ <ol class="proc">
+ <li>Let <i>A</i> be <a href="#sec-arraycreate">ArrayCreate</a>(0).</li>
+ <li>Let <i>n</i>=0.</li>
+ <li>Repeat,
+ <ol class="block">
+ <li>Let <i>next</i> be <a href="#sec-iteratorstep">IteratorStep</a>(<i>iterator</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>next</i>).</li>
+ <li>If <i>next</i> is <b>false</b>, then
+ <ol class="block">
+ <li>Return the result of performing BindingInitialization for <i>BindingIdentifier</i> using <i>A</i> and
+ <i>environment</i> as arguments.</li>
+ </ol>
+ </li>
+ <li>Let <i>nextValue</i> be <a href="#sec-iteratorvalue">IteratorValue</a>(<i>next</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>nextValue</i>).</li>
+ <li>Let <i>defineStatus</i> be <a href="#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a>(<i>A</i>, <a
+ href="#sec-tostring">ToString</a>(<a href="#sec-touint32">ToUint32</a>(<i>n)</i>), <i>nextValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>defineStatus</i>).</li>
+ <li>Increment <i>n</i> by 1.</li>
+ </ol>
+ </li>
+ </ol>
+ </section>
+
+ <section id="sec-runtime-semantics-keyedbindinginitialization">
+ <h1><span class="secnum" id="sec-13.2.3.7"><a href="#sec-runtime-semantics-keyedbindinginitialization"
+ title="link to this section">13.2.3.7</a></span> Runtime Semantics: KeyedBindingInitialization</h1>
+
+ <p>With parameters <var>obj</var>, <var>environment,</var> and <var>propertyName</var>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> When <b>undefined</b> is passed for <var>environment</var> it indicates that a <a
+ href="#sec-putvalue">PutValue</a> operation should be used to assign the initialization value. This is the case for
+ formal parameter lists of non-strict functions. In that case the formal parameter bindings are preinitialized in order
+ to deal with the possibility of multiple parameters with the same name.</p>
+ </div>
+
+ <div class="gp prod"><span class="nt">BindingElement</span> <span class="geq">:</span> <span class="nt">BindingPattern</span> <span class="nt">Initializer</span><sub>opt</sub></div>
+ <ol class="proc">
+ <li>Let <i>v</i> be <a href="#sec-get-o-p">Get</a>(<i>obj</i>, <i>propertyName</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>v</i>).</li>
+ <li>If <i>Initializer</i> is present and <i>v</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>defaultValue</i> be the result of evaluating <i>Initializer</i>.</li>
+ <li>Let <i>v</i> be <a href="#sec-getvalue">GetValue</a>(<i>defaultValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>v</i>).</li>
+ </ol>
+ </li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>v</i>) is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>Return the result of performing BindingInitialization for <i>BindingPattern</i> passing <i>v</i> and
+ <i>environment</i> as arguments.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">SingleNameBinding</span> <span class="geq">:</span> <span class="nt">BindingIdentifier</span> <span class="nt">Initializer</span><sub>opt</sub></div>
+ <ol class="proc">
+ <li>Let <i>v</i> be <a href="#sec-get-o-p">Get</a>(<i>obj</i>, <i>propertyName</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>v</i>).</li>
+ <li>If <i>Initializer</i> is present and <i>v</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>defaultValue</i> be the result of evaluating <i>Initializer</i>.</li>
+ <li>Let <i>v</i> be <a href="#sec-getvalue">GetValue</a>(<i>defaultValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>v</i>).</li>
+ <li>If <a href="#sec-isanonymousfunctiondefinition">IsAnonymousFunctionDefinition</a>(<i>Initializer</i>) is
+ <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>hasNameProperty</i> be <a href="#sec-hasownproperty">HasOwnProperty</a>(<i>v</i>,
+ <code>"name"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>hasNameProperty</i>).</li>
+ <li>If <i>hasNameProperty</i> is <b>false</b>, then
+ <ol class="block">
+ <li><a href="#sec-setfunctionname">SetFunctionName</a>(<i>v</i>,
+ StringValue(<i>BindingIdentifier</i>)).</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Return the result of performing BindingInitialization for <i>BindingIdentifier</i> passing <i>v</i> and
+ <i>environment</i> as arguments.</li>
+ </ol>
+ </section>
+ </section>
+ </section>
+
+ <section id="sec-empty-statement">
+ <div class="front">
+ <h1><span class="secnum" id="sec-13.3"><a href="#sec-empty-statement" title="link to this section">13.3</a></span> Empty
+ Statement</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">EmptyStatement</span> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">;</code></div>
+ </div>
+ </div>
+
+ <section id="sec-empty-statement-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-13.3.1"><a href="#sec-empty-statement-runtime-semantics-evaluation"
+ title="link to this section">13.3.1</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">EmptyStatement</span> <span class="geq">:</span> <code class="t">;</code></div>
+ <ol class="proc">
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<span style="font-family: sans-serif">empty</span>)<span
+ style="font-family: sans-serif">.</span></li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-expression-statement">
+ <div class="front">
+ <h1><span class="secnum" id="sec-13.4"><a href="#sec-expression-statement" title="link to this section">13.4</a></span>
+ Expression Statement</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ExpressionStatement</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="grhsannot">[lookahead ∉ {<code class="t">{</code>, <code class="t">function</code>, <code class="t">class</code>, <code class="t">let [</code>}]</span> <span class="nt">Expression</span><sub>[In, ?Yield]</sub> <code class="t">;</code></div>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> An <i>ExpressionStatement</i> cannot start with an opening curly brace because that might
+ make it ambiguous with a <i>Block</i>. Also, an <i>ExpressionStatement</i> cannot start with the <code>function</code> or
+ <code>class</code> keywords because that would make it ambiguous with a <i>FunctionDeclaration</i>, a
+ <i>GeneratorDeclaration</i>, or a <i>ClassDeclaration</i>. An <i>ExpressionStatement</i> cannot start with the two token
+ sequence <code>let [</code> because that would make it ambiguous with a <code>let</code> <i>LexicalDeclaration</i> whose
+ first <i>LexicalBinding</i> was an <i>ArrayBindingPattern</i>.</p>
+ </div>
+ </div>
+
+ <section id="sec-expression-statement-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-13.4.1"><a href="#sec-expression-statement-runtime-semantics-evaluation"
+ title="link to this section">13.4.1</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">ExpressionStatement</span> <span class="geq">:</span> <span class="nt">Expression</span> <code class="t">;</code></div>
+ <ol class="proc">
+ <li>Let <i>exprRef</i> be the result of evaluating <i>Expression</i>.</li>
+ <li>Let <i>value</i> be <a href="#sec-getvalue">GetValue</a>(<i>exprRef</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>value</i>).</li>
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<i>value</i>).</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-if-statement">
+ <div class="front">
+ <h1><span class="secnum" id="sec-13.5"><a href="#sec-if-statement" title="link to this section">13.5</a></span> The
+ <code>if</code> Statement</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">IfStatement</span><sub>[Yield, Return]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">if</code> <code class="t">(</code> <span class="nt">Expression</span><sub>[In, ?Yield]</sub> <code class="t">)</code> <span class="nt">Statement</span><sub>[?Yield, ?Return]</sub> <code class="t">else</code> <span class="nt">Statement</span><sub>[?Yield, ?Return]</sub></div>
+ <div class="rhs"><code class="t">if</code> <code class="t">(</code> <span class="nt">Expression</span><sub>[In, ?Yield]</sub> <code class="t">)</code> <span class="nt">Statement</span><sub>[?Yield, ?Return]</sub></div>
+ </div>
+
+ <p>Each <code>else</code> for which the choice of associated <code>if</code> is ambiguous shall be associated with the
+ nearest possible <b>if</b> that would otherwise have no corresponding <code>else</code>.</p>
+ </div>
+
+ <section id="sec-if-statement-static-semantics-vardeclarednames">
+ <h1><span class="secnum" id="sec-13.5.1"><a href="#sec-if-statement-static-semantics-vardeclarednames"
+ title="link to this section">13.5.1</a></span> Static Semantics: VarDeclaredNames</h1>
+
+ <p>See also: <a href="#sec-statement-semantics-static-semantics-vardeclarednames">13.0.1</a>, <a
+ href="#sec-block-static-semantics-vardeclarednames">13.1.8</a>, <a
+ href="#sec-variable-statement-static-semantics-vardeclarednames">13.2.2.2</a>, <a
+ href="#sec-do-while-statement-static-semantics-vardeclarednames">13.6.1.1</a>, <a
+ href="#sec-while-statement-static-semantics-vardeclarednames">13.6.2.1</a>, <a
+ href="#sec-for-statement-static-semantics-vardeclarednames">13.6.3.1</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-vardeclarednames">13.6.4.3</a>, <a
+ href="#sec-with-statement-static-semantics-vardeclarednames">13.10.2</a>, <a
+ href="#sec-switch-statement-static-semantics-vardeclarednames">13.11.4</a>, <a
+ href="#sec-static-semantics-currentlabelset">13.12.2</a>, 0, <a
+ href="#sec-function-definitions-static-semantics-referencessuper">14.1.16</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-vardeclarednames">14.4.12</a>, <a
+ href="#sec-class-definitions-static-semantics-vardeclarednames">14.5.15</a>, <a
+ href="#sec-scripts-static-semantics-vardeclarednames">15.1.5</a>, <a
+ href="#sec-module-static-semantics-static-semantics-vardeclarednames">15.2.0.13</a>.</p>
+
+ <div class="gp prod"><span class="nt">IfStatement</span> <span class="geq">:</span> <code class="t">if</code> <code class="t">(</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">Statement</span> <code class="t">else</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Let <i>names</i> be VarDeclaredNames of the first <i>Statement</i>.</li>
+ <li>Append to <i>names</i> the elements of the VarDeclaredNames of the second <i>Statement.</i></li>
+ <li>Return <i>names</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">IfStatement</span> <span class="geq">:</span> <code class="t">if</code> <code class="t">(</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Return the VarDeclaredNames of <i>Statement</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-if-statement-static-semantics-varscopeddeclarations">
+ <h1><span class="secnum" id="sec-13.5.2"><a href="#sec-if-statement-static-semantics-varscopeddeclarations"
+ title="link to this section">13.5.2</a></span> Static Semantics: VarScopedDeclarations</h1>
+
+ <p>See also: <a href="#sec-statement-semantics-static-semantics-varscopeddeclarations">13.0.2</a>, <a
+ href="#sec-block-static-semantics-varscopeddeclarations">13.1.9</a>, <a
+ href="#sec-variable-statement-static-semantics-varscopeddeclarations">13.2.2.3</a>, <a
+ href="#sec-do-while-statement-static-semantics-varscopeddeclarations">13.6.1.2</a>, <a
+ href="#sec-while-statement-static-semantics-varscopeddeclarations">13.6.2.2</a>, <a
+ href="#sec-for-statement-static-semantics-varscopeddeclarations">13.6.3.2</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-varscopeddeclarations">13.6.4.4</a>, <a
+ href="#sec-with-statement-static-semantics-varscopeddeclarations">13.10.3</a>, <a
+ href="#sec-switch-statement-static-semantics-varscopeddeclarations">13.11.5</a>, <a
+ href="#sec-labelled-statements-static-semantics-varscopeddeclarations">13.12.4</a>, <a
+ href="#sec-try-statement-static-semantics-varscopeddeclarations">13.14.3</a>, <a
+ href="#sec-function-definitions-static-semantics-varscopeddeclarations">14.1.18</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-varscopeddeclarations">14.2.14</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-varscopeddeclarations">14.4.13</a>, <a
+ href="#sec-scripts-static-semantics-varscopeddeclarations">15.1.6</a>, <a
+ href="#sec-module-static-semantics-static-semantics-varscopeddeclarations">15.2.0.14</a>.</p>
+
+ <div class="gp prod"><span class="nt">IfStatement</span> <span class="geq">:</span> <code class="t">if</code> <code class="t">(</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">Statement</span> <code class="t">else</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Let <i>declarations</i> be VarScopedDeclarations of the first <i>Statement</i>.</li>
+ <li>Append to <i>declarations</i> the elements of the VarScopedDeclarations of the second <i>Statement.</i></li>
+ <li>Return <i>declarations</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">IfStatement</span> <span class="geq">:</span> <code class="t">if</code> <code class="t">(</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Return the VarDeclaredNames of <i>Statement</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-if-statement-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-13.5.3"><a href="#sec-if-statement-runtime-semantics-evaluation"
+ title="link to this section">13.5.3</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">IfStatement</span> <span class="geq">:</span> <code class="t">if</code> <code class="t">(</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">Statement</span> <code class="t">else</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Let <i>exprRef</i> be the result of evaluating <i>Expression</i>.</li>
+ <li>Let <i>exprValue</i> be <a href="#sec-toboolean">ToBoolean</a>(<a
+ href="#sec-getvalue">GetValue</a>(<i>exprRef</i>)).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>exprValue</i>).</li>
+ <li>If <i>exprValue</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>stmtValue</i> be the result of evaluating the first <i>Statement</i>.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>stmtValue</i> be the result of evaluating the second <i>Statement</i>.</li>
+ </ol>
+ </li>
+ <li>If <i>stmtValue</i>.[[type]] is <span style="font-family: sans-serif">normal</span> and <i>stmtValue</i>.[[value]] is
+ <span style="font-family: sans-serif">empty</span>, then
+ <ol class="block">
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<b>undefined</b>).</li>
+ </ol>
+ </li>
+ <li>Return <i>stmtValue</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">IfStatement</span> <span class="geq">:</span> <code class="t">if</code> <code class="t">(</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Let <i>exprRef</i> be the result of evaluating <i>Expression</i>.</li>
+ <li>Let <i>exprValue</i> be <a href="#sec-toboolean">ToBoolean</a>(<a
+ href="#sec-getvalue">GetValue</a>(<i>exprRef</i>)).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>exprValue</i>).</li>
+ <li>If <i>exprValue</i> is <b>false</b>, then
+ <ol class="block">
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<b>undefined</b>).</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>stmtValue</i> be the result of evaluating <i>Statement</i>.</li>
+ </ol>
+ </li>
+ <li>If <i>stmtValue</i>.[[type]] is <span style="font-family: sans-serif">normal</span> and <i>stmtValue</i>.[[value]] is
+ <span style="font-family: sans-serif">empty</span>, then
+ <ol class="block">
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<b>undefined</b>).</li>
+ </ol>
+ </li>
+ <li>Return <i>stmtValue</i>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-iteration-statements">
+ <div class="front">
+ <h1><span class="secnum" id="sec-13.6"><a href="#sec-iteration-statements" title="link to this section">13.6</a></span>
+ Iteration Statements</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">IterationStatement</span><sub>[Yield, Return]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">do</code> <span class="nt">Statement</span><sub>[?Yield, ?Return]</sub> <code class="t">while</code> <code class="t">(</code> <span class="nt">Expression</span><sub>[In, ?Yield]</sub> <code class="t">)</code> <code class="t">;</code><sub>opt</sub></div>
+ <div class="rhs"><code class="t">while</code> <code class="t">(</code> <span class="nt">Expression</span><sub>[In, ?Yield]</sub> <code class="t">)</code> <span class="nt">Statement</span><sub>[?Yield, ?Return]</sub></div>
+ <div class="rhs"><code class="t">for</code> <code class="t">(</code> <span class="grhsannot">[lookahead ∉ {<code class="t">let [</code>}]</span> <span class="nt">Expression</span><sub>[?Yield]</sub><sub>opt</sub> <code class="t">;</code> <span class="nt">Expression</span><sub>[In, ?Yield]</sub><sub>opt</sub> <code class="t">;</code> <span class="nt">Expression</span><sub>[In, ?Yield]</sub><sub>opt</sub> <code class="t">)</code> <span class="nt">Statement</span><sub>[?Yield, ?Return]</sub></div>
+ <div class="rhs"><code class="t">for</code> <code class="t">(</code> <code class="t">var</code> <span class="nt">VariableDeclarationList</span><sub>[?Yield]</sub> <code class="t">;</code> <span class="nt">Expression</span><sub>[In, ?Yield]</sub><sub>opt</sub> <code class="t">;</code> <span class="nt">Expression</span><sub>[In, ?Yield]</sub><sub>opt</sub> <code class="t">)</code> <span class="nt">Statement</span><sub>[?Yield, ?Return]</sub></div>
+ <div class="rhs"><code class="t">for</code> <code class="t">(</code> <span class="nt">LexicalDeclaration</span><sub>[?Yield]</sub> <span class="nt">Expression</span><sub>[In, ?Yield]</sub><sub>opt</sub> <code class="t">;</code> <span class="nt">Expression</span><sub>[In, ?Yield]</sub><sub>opt</sub> <code class="t">)</code> <span class="nt">Statement</span><sub>[?Yield, ?Return]</sub></div>
+ <div class="rhs"><code class="t">for</code> <code class="t">(</code> <span class="grhsannot">[lookahead ∉ {<code class="t">let [</code>}]</span> <span class="nt">LeftHandSideExpression</span><sub>[?Yield]</sub> <code class="t">in</code> <span class="nt">Expression</span><sub>[In, ?Yield]</sub> <code class="t">)</code> <span class="nt">Statement</span><sub>[?Yield, ?Return]</sub></div>
+ <div class="rhs"><code class="t">for</code> <code class="t">(</code> <code class="t">var</code> <span class="nt">ForBinding</span><sub>[?Yield]</sub> <code class="t">in</code> <span class="nt">Expression</span><sub>[In, ?Yield]</sub> <code class="t">)</code> <span class="nt">Statement</span><sub>[?Yield, ?Return]</sub></div>
+ <div class="rhs"><code class="t">for</code> <code class="t">(</code> <span class="nt">ForDeclaration</span><sub>[?Yield]</sub> <code class="t">in</code> <span class="nt">Expression</span><sub>[In, ?Yield]</sub> <code class="t">)</code> <span class="nt">Statement</span><sub>[?Yield, ?Return]</sub></div>
+ <div class="rhs"><code class="t">for</code> <code class="t">(</code> <span class="grhsannot">[lookahead ≠ let ]</span> <span class="nt">LeftHandSideExpression</span><sub>[?Yield]</sub> <code class="t">of</code> <span class="nt">AssignmentExpression</span><sub>[In, ?Yield]</sub> <code class="t">)</code> <span class="nt">Statement</span> <span class="grhsannot">[?Yield, ?Return]</span></div>
+ <div class="rhs"><code class="t">for</code> <code class="t">(</code> <code class="t">var</code> <span class="nt">ForBinding</span><sub>[?Yield]</sub> <code class="t">of</code> <span class="nt">AssignmentExpression</span><sub>[In, ?Yield]</sub> <code class="t">)</code> <span class="nt">Statement</span><sub>[?Yield, ?Return]</sub></div>
+ <div class="rhs"><code class="t">for</code> <code class="t">(</code> <span class="nt">ForDeclaration</span><sub>[?Yield]</sub> <code class="t">of</code> <span class="nt">AssignmentExpression</span><sub>[In, ?Yield]</sub> <code class="t">)</code> <span class="nt">Statement</span><sub>[?Yield, ?Return]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ForDeclaration</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">LetOrConst</span> <span class="nt">ForBinding</span><sub>[?Yield]</sub></div>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> <i>ForBinding</i> is defined in <a href="#sec-array-comprehension">12.2.4.2</a>.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 2</span> A semicolon is not required after a <code>do-while</code> statement.</p>
+ </div>
+ </div>
+
+ <section id="sec-iteration-statements-semantics">
+ <div class="front">
+ <h1><span class="secnum" id="sec-13.6.0"><a href="#sec-iteration-statements-semantics"
+ title="link to this section">13.6.0</a></span> Semantics</h1>
+ </div>
+
+ <section id="sec-loopcontinues">
+ <h1><span class="secnum" id="sec-13.6.0.1"><a href="#sec-loopcontinues" title="link to this section">13.6.0.1</a></span>
+ Runtime Semantics: LoopContinues(completion, labelSet)</h1>
+
+ <p>The abstract operation <span style="font-family: Times New Roman">LoopContinues</span> with arguments
+ <var>completion</var> and <var>labelSet</var> is defined by the following step:</p>
+
+ <ol class="proc">
+ <li>If <i>completion</i>.[[type]] is <span style="font-family: sans-serif">normal</span>, then return <b>true</b>.</li>
+ <li>If <i>completion</i>.[[type]] is not <span style="font-family: sans-serif">continue</span>, then return
+ <b>false</b>.</li>
+ <li>If <i>completion</i>.[[target]] is <span style="font-family: sans-serif">empty</span>, then return <b>true</b>.</li>
+ <li>If <i>completion</i>.[[target]] is an element of <i>labelSet</i>, then return <b>true</b>.</li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Within the <i>Statement</i> part of an <i>IterationStatement</i> a
+ <i>ContinueStatement</i> may be used to begin a new iteration.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-do-while-statement">
+ <div class="front">
+ <h1><span class="secnum" id="sec-13.6.1"><a href="#sec-do-while-statement" title="link to this section">13.6.1</a></span>
+ The <code>do</code>-<code>while</code> Statement</h1>
+ </div>
+
+ <section id="sec-do-while-statement-static-semantics-vardeclarednames">
+ <h1><span class="secnum" id="sec-13.6.1.1"><a href="#sec-do-while-statement-static-semantics-vardeclarednames"
+ title="link to this section">13.6.1.1</a></span> Static Semantics: VarDeclaredNames</h1>
+
+ <p>See also: <a href="#sec-statement-semantics-static-semantics-vardeclarednames">13.0.1</a>, <a
+ href="#sec-block-static-semantics-vardeclarednames">13.1.8</a>, <a
+ href="#sec-variable-statement-static-semantics-vardeclarednames">13.2.2.2</a>, <a
+ href="#sec-if-statement-static-semantics-vardeclarednames">13.5.1</a>, <a
+ href="#sec-while-statement-static-semantics-vardeclarednames">13.6.2.1</a>, <a
+ href="#sec-for-statement-static-semantics-vardeclarednames">13.6.3.1</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-vardeclarednames">13.6.4.3</a>, <a
+ href="#sec-with-statement-static-semantics-vardeclarednames">13.10.2</a>, <a
+ href="#sec-switch-statement-static-semantics-vardeclarednames">13.11.4</a>, <a
+ href="#sec-static-semantics-currentlabelset">13.12.2</a>, 0, <a
+ href="#sec-function-definitions-static-semantics-referencessuper">14.1.16</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-vardeclarednames">14.4.12</a>, <a
+ href="#sec-class-definitions-static-semantics-vardeclarednames">14.5.15</a>, <a
+ href="#sec-scripts-static-semantics-vardeclarednames">15.1.5</a>, <a
+ href="#sec-module-static-semantics-static-semantics-vardeclarednames">15.2.0.13</a>.</p>
+
+ <div class="gp prod"><span class="nt">IterationStatement</span> <span class="geq">:</span> <code class="t">do</code> <span class="nt">Statement</span> <code class="t">while</code> <code class="t">(</code> <span class="nt">Expression</span> <code class="t">)</code> <code class="t">;</code><sub>opt</sub></div>
+ <ol class="proc">
+ <li>Return the VarDeclaredNames of <i>Statement</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-do-while-statement-static-semantics-varscopeddeclarations">
+ <h1><span class="secnum" id="sec-13.6.1.2"><a href="#sec-do-while-statement-static-semantics-varscopeddeclarations"
+ title="link to this section">13.6.1.2</a></span> Static Semantics: VarScopedDeclarations</h1>
+
+ <p>See also: <a href="#sec-statement-semantics-static-semantics-varscopeddeclarations">13.0.2</a>, <a
+ href="#sec-block-static-semantics-varscopeddeclarations">13.1.9</a>, <a
+ href="#sec-variable-statement-static-semantics-varscopeddeclarations">13.2.2.3</a>, <a
+ href="#sec-if-statement-static-semantics-varscopeddeclarations">13.5.2</a>, <a
+ href="#sec-while-statement-static-semantics-varscopeddeclarations">13.6.2.2</a>, <a
+ href="#sec-for-statement-static-semantics-varscopeddeclarations">13.6.3.2</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-varscopeddeclarations">13.6.4.4</a>, <a
+ href="#sec-with-statement-static-semantics-varscopeddeclarations">13.10.3</a>, <a
+ href="#sec-switch-statement-static-semantics-varscopeddeclarations">13.11.5</a>, <a
+ href="#sec-labelled-statements-static-semantics-varscopeddeclarations">13.12.4</a>, <a
+ href="#sec-try-statement-static-semantics-varscopeddeclarations">13.14.3</a>, <a
+ href="#sec-function-definitions-static-semantics-varscopeddeclarations">14.1.18</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-varscopeddeclarations">14.2.14</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-varscopeddeclarations">14.4.13</a>, <a
+ href="#sec-scripts-static-semantics-varscopeddeclarations">15.1.6</a>, <a
+ href="#sec-module-static-semantics-static-semantics-varscopeddeclarations">15.2.0.14</a>.</p>
+
+ <div class="gp prod"><span class="nt">IterationStatement</span> <span class="geq">:</span> <code class="t">do</code> <span class="nt">Statement</span> <code class="t">while</code> <code class="t">(</code> <span class="nt">Expression</span> <code class="t">)</code> <code class="t">;</code><sub>opt</sub></div>
+ <ol class="proc">
+ <li>Return the VarScopedDeclarations of <i>Statement</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-do-while-statement-runtime-semantics-labelledevaluation">
+ <h1><span class="secnum" id="sec-13.6.1.3"><a href="#sec-do-while-statement-runtime-semantics-labelledevaluation"
+ title="link to this section">13.6.1.3</a></span> Runtime Semantics: LabelledEvaluation</h1>
+
+ <p>With argument <var>labelSet</var>.</p>
+
+ <p>See also: <a href="#sec-statement-semantics-static-semantics-varscopeddeclarations">13.0.2</a>, <a
+ href="#sec-while-statement-static-semantics-varscopeddeclarations">13.6.2.2</a>, <a
+ href="#sec-for-statement-static-semantics-varscopeddeclarations">13.6.3.2</a>, <a
+ href="#sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation">13.6.4.6</a>, <a
+ href="#sec-labelled-statements-static-semantics-varscopeddeclarations">13.12.4</a>.</p>
+
+ <div class="gp prod"><span class="nt">IterationStatement</span> <span class="geq">:</span> <code class="t">do</code> <span class="nt">Statement</span> <code class="t">while</code> <code class="t">(</code> <span class="nt">Expression</span> <code class="t">)</code> <code class="t">;</code><sub>opt</sub></div>
+ <ol class="proc">
+ <li>Let <i>V</i> = <b>undefined</b>.</li>
+ <li>Repeat
+ <ol class="block">
+ <li>Let <i>stmt</i> be the result of evaluating <i>Statement</i>.</li>
+ <li>If <i>stmt</i>.[[value]] is not <span style="font-family: sans-serif">empty</span>, let <i>V</i> =
+ <i>stmt</i>.[[value]]<i>.</i></li>
+ <li>If <a href="#sec-loopcontinues">LoopContinues</a> (<i>stmt</i>,<i>labelSet</i>) is <b>false</b>, return
+ <i>stmt</i>.</li>
+ <li>Let <i>exprRef</i> be the result of evaluating <i>Expression</i>.</li>
+ <li>Let <i>exprValue</i> be <a href="#sec-toboolean">ToBoolean</a>(<a
+ href="#sec-getvalue">GetValue</a>(<i>exprRef</i>)).</li>
+ <li>If <i>exprValue</i> is <b>false</b>, Return <a href="#sec-normalcompletion">NormalCompletion</a>(<i>V</i>).</li>
+ <li>Else if <i>exprValue</i> is not <b>true</b>, then
+ <ol class="block">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>exprValue</i> is an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a>.</li>
+ <li>If <a href="#sec-loopcontinues">LoopContinues</a> (<i>exprValue</i>,<i>labelSet</i>) is <b>false</b>,
+ return <i>exprValue.</i></li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-while-statement">
+ <div class="front">
+ <h1><span class="secnum" id="sec-13.6.2"><a href="#sec-while-statement" title="link to this section">13.6.2</a></span> The
+ <code>while</code> Statement</h1>
+ </div>
+
+ <section id="sec-while-statement-static-semantics-vardeclarednames">
+ <h1><span class="secnum" id="sec-13.6.2.1"><a href="#sec-while-statement-static-semantics-vardeclarednames"
+ title="link to this section">13.6.2.1</a></span> Static Semantics: VarDeclaredNames</h1>
+
+ <p>See also: <a href="#sec-statement-semantics-static-semantics-vardeclarednames">13.0.1</a>, <a
+ href="#sec-block-static-semantics-vardeclarednames">13.1.8</a>, <a
+ href="#sec-if-statement-static-semantics-vardeclarednames">13.5.1</a>, <a
+ href="#sec-do-while-statement-static-semantics-vardeclarednames">13.6.1.1</a>, <a
+ href="#sec-for-statement-static-semantics-vardeclarednames">13.6.3.1</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-vardeclarednames">13.6.4.3</a>, <a
+ href="#sec-with-statement-static-semantics-vardeclarednames">13.10.2</a>, <a
+ href="#sec-switch-statement-static-semantics-vardeclarednames">13.11.4</a>, <a
+ href="#sec-static-semantics-currentlabelset">13.12.2</a>, <a
+ href="#sec-try-statement-static-semantics-vardeclarednames">13.14.2</a>, <a
+ href="#sec-function-definitions-static-semantics-referencessuper">14.1.16</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-vardeclarednames">14.4.12</a>, <a
+ href="#sec-class-definitions-static-semantics-vardeclarednames">14.5.15</a>, <a
+ href="#sec-scripts-static-semantics-vardeclarednames">15.1.5</a>, <a
+ href="#sec-module-static-semantics-static-semantics-vardeclarednames">15.2.0.13</a>.</p>
+
+ <div class="gp prod"><span class="nt">IterationStatement</span> <span class="geq">:</span> <code class="t">while</code> <code class="t">(</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Return the VarDeclaredNames of <i>Statement</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-while-statement-static-semantics-varscopeddeclarations">
+ <h1><span class="secnum" id="sec-13.6.2.2"><a href="#sec-while-statement-static-semantics-varscopeddeclarations"
+ title="link to this section">13.6.2.2</a></span> Static Semantics: VarScopedDeclarations</h1>
+
+ <p>See also: <a href="#sec-statement-semantics-static-semantics-varscopeddeclarations">13.0.2</a>, <a
+ href="#sec-block-static-semantics-varscopeddeclarations">13.1.9</a>, <a
+ href="#sec-variable-statement-static-semantics-varscopeddeclarations">13.2.2.3</a>, <a
+ href="#sec-if-statement-static-semantics-varscopeddeclarations">13.5.2</a>, <a
+ href="#sec-do-while-statement-static-semantics-varscopeddeclarations">13.6.1.2</a>, <a
+ href="#sec-while-statement-static-semantics-varscopeddeclarations">13.6.2.2</a>, <a
+ href="#sec-scripts-static-semantics-varscopeddeclarations">15.1.6</a>, <a
+ href="#sec-module-static-semantics-static-semantics-varscopeddeclarations">15.2.0.14</a>.</p>
+
+ <div class="gp prod"><span class="nt">IterationStatement</span> <span class="geq">:</span> <code class="t">while</code> <code class="t">(</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Return the VarScopedDeclarations of <i>Statement</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-while-statement-runtime-semantics-labelledevaluation">
+ <h1><span class="secnum" id="sec-13.6.2.3"><a href="#sec-while-statement-runtime-semantics-labelledevaluation"
+ title="link to this section">13.6.2.3</a></span> Runtime Semantics: LabelledEvaluation</h1>
+
+ <p>With argument <var>labelSet</var>.</p>
+
+ <p>See also: <a href="#sec-statement-semantics-static-semantics-varscopeddeclarations">13.0.2</a>, <a
+ href="#sec-do-while-statement-static-semantics-varscopeddeclarations">13.6.1.2</a>, <a
+ href="#sec-for-statement-static-semantics-varscopeddeclarations">13.6.3.2</a>, <a
+ href="#sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation">13.6.4.6</a>, <a
+ href="#sec-labelled-statements-static-semantics-varscopeddeclarations">13.12.4</a>.</p>
+
+ <div class="gp prod"><span class="nt">IterationStatement</span> <span class="geq">:</span> <code class="t">while</code> <code class="t">(</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Let <i>V</i> = <b>undefined</b>.</li>
+ <li>Repeat
+ <ol class="block">
+ <li>Let <i>exprRef</i> be the result of evaluating <i>Expression</i>.</li>
+ <li>Let <i>exprValue</i> be <a href="#sec-toboolean">ToBoolean</a>(<a
+ href="#sec-getvalue">GetValue</a>(<i>exprRef</i>)).</li>
+ <li>If <i>exprValue</i> is <b>false</b>, return <a href="#sec-normalcompletion">NormalCompletion</a>(<i>V</i>).</li>
+ <li>If <i>exprValue</i> is not <b>true</b>, then
+ <ol class="block">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>exprValue</i> is an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a>.</li>
+ <li>If <a href="#sec-loopcontinues">LoopContinues</a> (<i>exprValue</i>,<i>labelSet</i>) is <b>false</b>,
+ return <i>exprValue.</i></li>
+ </ol>
+ </li>
+ <li>Let <i>stmt</i> be the result of evaluating <i>Statement</i>.</li>
+ <li>If <i>stmt</i>.[[value]] is not <span style="font-family: sans-serif">empty</span>, let <i>V</i> =
+ <i>stmt</i>.[[value]].</li>
+ <li>If <a href="#sec-loopcontinues">LoopContinues</a> (<i>stmt</i>,<i>labelSet</i>) is <b>false</b>, return
+ <i>stmt</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-for-statement">
+ <div class="front">
+ <h1><span class="secnum" id="sec-13.6.3"><a href="#sec-for-statement" title="link to this section">13.6.3</a></span> The
+ <code>for</code> Statement</h1>
+ </div>
+
+ <section id="sec-for-statement-static-semantics-vardeclarednames">
+ <h1><span class="secnum" id="sec-13.6.3.1"><a href="#sec-for-statement-static-semantics-vardeclarednames"
+ title="link to this section">13.6.3.1</a></span> Static Semantics: VarDeclaredNames</h1>
+
+ <p>See also: <a href="#sec-statement-semantics-static-semantics-vardeclarednames">13.0.1</a>, <a
+ href="#sec-block-static-semantics-vardeclarednames">13.1.8</a>, <a
+ href="#sec-variable-statement-static-semantics-vardeclarednames">13.2.2.2</a>, <a
+ href="#sec-if-statement-static-semantics-vardeclarednames">13.5.1</a>, <a
+ href="#sec-do-while-statement-static-semantics-vardeclarednames">13.6.1.1</a>, <a
+ href="#sec-while-statement-static-semantics-vardeclarednames">13.6.2.1</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-vardeclarednames">13.6.4.3</a>, <a
+ href="#sec-with-statement-static-semantics-vardeclarednames">13.10.2</a>, <a
+ href="#sec-switch-statement-static-semantics-vardeclarednames">13.11.4</a>, <a
+ href="#sec-static-semantics-currentlabelset">13.12.2</a>, <a
+ href="#sec-try-statement-static-semantics-vardeclarednames">13.14.2</a>, <a
+ href="#sec-function-definitions-static-semantics-referencessuper">14.1.16</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-vardeclarednames">14.4.12</a>, <a
+ href="#sec-class-definitions-static-semantics-vardeclarednames">14.5.15</a>, <a
+ href="#sec-scripts-static-semantics-vardeclarednames">15.1.5</a>, <a
+ href="#sec-module-static-semantics-static-semantics-vardeclarednames">15.2.0.13</a>.</p>
+
+ <div class="gp prod"><span class="nt">IterationStatement</span> <span class="geq">:</span> <code class="t">for</code> <code class="t">(</code> <span class="nt">Expression</span><sub>opt</sub> <code class="t">;</code> <span class="nt">Expression</span><sub>opt</sub> <code class="t">;</code> <span class="nt">Expression</span><sub>opt</sub> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Return the VarDeclaredNames of <i>Statement</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">IterationStatement</span> <span class="geq">:</span> <code class="t">for</code> <code class="t">(</code> <code class="t">var</code> <span class="nt">VariableDeclarationList</span> <code class="t">;</code> <span class="nt">Expression</span><sub>opt</sub> <code class="t">;</code> <span class="nt">Expression</span><sub>opt</sub> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Let <i>names</i> be BoundNames of <i>VariableDeclarationList</i>.</li>
+ <li>Append to <i>names</i> the elements of the VarDeclaredNames of <i>Statement.</i></li>
+ <li>Return <i>names</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">IterationStatement</span> <span class="geq">:</span> <code class="t">for</code> <code class="t">(</code> <span class="nt">LexicalDeclaration</span> <span class="nt">Expression</span><sub>opt</sub> <code class="t">;</code> <span class="nt">Expression</span><sub>opt</sub> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Return the VarDeclaredNames of <i>Statement</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-for-statement-static-semantics-varscopeddeclarations">
+ <h1><span class="secnum" id="sec-13.6.3.2"><a href="#sec-for-statement-static-semantics-varscopeddeclarations"
+ title="link to this section">13.6.3.2</a></span> Static Semantics: VarScopedDeclarations</h1>
+
+ <p>See also: <a href="#sec-statement-semantics-static-semantics-varscopeddeclarations">13.0.2</a>, <a
+ href="#sec-block-static-semantics-varscopeddeclarations">13.1.9</a>, <a
+ href="#sec-variable-statement-static-semantics-varscopeddeclarations">13.2.2.3</a>, <a
+ href="#sec-if-statement-static-semantics-varscopeddeclarations">13.5.2</a>, <a
+ href="#sec-do-while-statement-static-semantics-varscopeddeclarations">13.6.1.2</a>, <a
+ href="#sec-while-statement-static-semantics-varscopeddeclarations">13.6.2.2</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-varscopeddeclarations">13.6.4.4</a>, <a
+ href="#sec-with-statement-static-semantics-varscopeddeclarations">13.10.3</a>, <a
+ href="#sec-switch-statement-static-semantics-varscopeddeclarations">13.11.5</a>, <a
+ href="#sec-labelled-statements-static-semantics-varscopeddeclarations">13.12.4</a>, <a
+ href="#sec-try-statement-static-semantics-varscopeddeclarations">13.14.3</a>, <a
+ href="#sec-function-definitions-static-semantics-varscopeddeclarations">14.1.18</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-varscopeddeclarations">14.2.14</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-varscopeddeclarations">14.4.13</a>, <a
+ href="#sec-scripts-static-semantics-varscopeddeclarations">15.1.6</a>, <a
+ href="#sec-module-static-semantics-static-semantics-varscopeddeclarations">15.2.0.14</a>.</p>
+
+ <div class="gp prod"><span class="nt">IterationStatement</span> <span class="geq">:</span> <code class="t">for</code> <code class="t">(</code> <span class="nt">Expression</span><sub>opt</sub> <code class="t">;</code> <span class="nt">Expression</span><sub>opt</sub> <code class="t">;</code> <span class="nt">Expression</span><sub>opt</sub> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Return the VarScopedDeclarations of <i>Statement</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">IterationStatement</span> <span class="geq">:</span> <code class="t">for</code> <code class="t">(</code> <code class="t">var</code> <span class="nt">VariableDeclarationList</span> <code class="t">;</code> <span class="nt">Expression</span><sub>opt</sub> <code class="t">;</code> <span class="nt">Expression</span><sub>opt</sub> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Let <i>declarations</i> be VarScopedDeclarations of <i>VariableDeclarationList</i>.</li>
+ <li>Append to <i>declarations</i> the elements of the VarScopedDeclarations of <i>Statement.</i></li>
+ <li>Return <i>declarations</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">IterationStatement</span> <span class="geq">:</span> <code class="t">for</code> <code class="t">(</code> <span class="nt">LexicalDeclaration</span> <span class="nt">Expression</span><sub>opt</sub> <code class="t">;</code> <span class="nt">Expression</span><sub>opt</sub> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Return the VarScopedDeclarations of <i>Statement</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-for-statement-runtime-semantics-labelledevaluation">
+ <h1><span class="secnum" id="sec-13.6.3.3"><a href="#sec-for-statement-runtime-semantics-labelledevaluation"
+ title="link to this section">13.6.3.3</a></span> Runtime Semantics: LabelledEvaluation</h1>
+
+ <p>With argument <var>labelSet</var>.</p>
+
+ <p>See also: <a href="#sec-statement-semantics-static-semantics-varscopeddeclarations">13.0.2</a>, <a
+ href="#sec-do-while-statement-static-semantics-varscopeddeclarations">13.6.1.2</a>, <a
+ href="#sec-while-statement-static-semantics-varscopeddeclarations">13.6.2.2</a>, <a
+ href="#sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation">13.6.4.6</a>, <a
+ href="#sec-labelled-statements-static-semantics-varscopeddeclarations">13.12.4</a>.</p>
+
+ <div class="gp prod"><span class="nt">IterationStatement</span> <span class="geq">:</span> <code class="t">for</code> <code class="t">(</code> <span class="nt">Expression</span><sub>opt</sub> <code class="t">;</code> <span class="nt">Expression</span><sub>opt</sub> <code class="t">;</code> <span class="nt">Expression</span><sub>opt</sub> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>If the first <i>Expression</i> is present, then
+ <ol class="block">
+ <li>Let <i>exprRef</i> be the result of evaluating the first <i>Expression</i>.</li>
+ <li>Let <i>exprValue</i> be <a href="#sec-getvalue">GetValue</a>(<i>exprRef</i>).</li>
+ <li>If <a href="#sec-loopcontinues">LoopContinues</a>(<i>exprValue</i>,<i>labelSet</i>) is <b>false</b>, return
+ <i>exprValue.</i></li>
+ </ol>
+ </li>
+ <li>Return the result of performing ForBodyEvaluation with the first <i>Expression</i> as the <i>testExpr</i> argument,
+ the second <i>Expression</i> as the <i>incrementExpr</i> argument, <i>Statement</i> as the <i>stmt</i> argument, ()
+ as the <i>perIterationBindings</i>, and with <i>labelSet</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">IterationStatement</span> <span class="geq">:</span> <code class="t">for</code> <code class="t">(</code> <code class="t">var</code> <span class="nt">VariableDeclarationList</span> <code class="t">;</code> <span class="nt">Expression</span><sub>opt</sub> <code class="t">;</code> <span class="nt">Expression</span><sub>opt</sub> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Let <i>varDcl</i> be the result of evaluating <i>VariableDeclarationList</i>.</li>
+ <li>If <a href="#sec-loopcontinues">LoopContinues</a>(<i>varDcl</i>,<i>labelSet</i>) is <b>false</b>, return
+ <i>varDcl</i>.</li>
+ <li>Return the result of performing ForBodyEvaluation with the first <i>Expression</i> as the <i>testExpr</i> argument,
+ the second <i>Expression</i> as the <i>incrementExpr</i> argument, <i>Statement</i> as the <i>stmt</i> argument, ()
+ as the <i>perIterationBindings</i>, and with <i>labelSet</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">IterationStatement</span> <span class="geq">:</span> <code class="t">for</code> <code class="t">(</code> <span class="nt">LexicalDeclaration</span> <span class="nt">Expression</span><sub>opt</sub> <code class="t">;</code> <span class="nt">Expression</span><sub>opt</sub> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Let <i>oldEnv</i> be <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-execution-contexts">LexicalEnvironment</a>.</li>
+ <li>Let <i>loopEnv</i> be <a href="#sec-newdeclarativeenvironment">NewDeclarativeEnvironment</a>(<i>oldEnv</i>).</li>
+ <li>Let <i>isConst</i> be the result of performing IsConstantDeclaration of <i>LexicalDeclaration</i>.</li>
+ <li>Let <i>boundNames</i> be the BoundNames of <i>LexicalDeclaration</i>.</li>
+ <li>For each element <i>dn</i> of <i>boundNames</i> do
+ <ol class="block">
+ <li>If <i>isConst</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Call <i>loopEnv</i>’s CreateImmutableBinding concrete method passing <i>dn</i> as the argument.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Call <i>loopEnv</i>’s CreateMutableBinding concrete method passing <i>dn</i> and <b>false</b> as the
+ arguments.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: The above call to CreateMutableBinding will never return an
+ <a href="#sec-completion-record-specification-type">abrupt completion</a>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Set <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-execution-contexts">LexicalEnvironment</a> to <i>loopEnv</i>.</li>
+ <li>Let <i>forDcl</i> be the result of evaluating <i>LexicalDeclaration</i>.</li>
+ <li>If <a href="#sec-loopcontinues">LoopContinues</a>(<i>forDcl</i>,<i>labelSet</i>) is <b>false</b>, then
+ <ol class="block">
+ <li>Set <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-execution-contexts">LexicalEnvironment</a> to <i>oldEnv</i>.</li>
+ <li>Return <i>forDcl</i>.</li>
+ </ol>
+ </li>
+ <li>If <i>isConst</i> is <b>false</b>, let <i>perIterationLets</i> be <i>boundNames</i> otherwise let
+ <i>perIterationLets</i> be ( ).</li>
+ <li>Let <i>bodyResult</i> be the result of performing ForBodyEvaluation with the first <i>Expression</i> as the
+ <i>testExpr</i> argument, the second <i>Expression</i> as the <i>incrementExpr</i> argument, <i>Statement</i> as the
+ <i>stmt</i> argument, <i>perIterationLets</i> as the <i>perIterationBindings</i>, and with <i>labelSet</i>.</li>
+ <li>Set <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-execution-contexts">LexicalEnvironment</a> to <i>oldEnv</i>.</li>
+ <li>Return <i>bodyResult</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-runtime-semantics-forbodyevaluation">
+ <h1><span class="secnum" id="sec-13.6.3.4"><a href="#sec-runtime-semantics-forbodyevaluation"
+ title="link to this section">13.6.3.4</a></span> Runtime Semantics: ForBodyEvaluation</h1>
+
+ <p>The abstract operation ForBodyEvaluation with arguments <var>testExpr</var>, <var>incrementExpr</var>, <var>stmt</var>,
+ <var>perIterationBindings</var>, and <var>labelSet</var> is performed as follows:</p>
+
+ <ol class="proc">
+ <li>Let <i>V</i> = <b>undefined</b>.</li>
+ <li>Let <i>status</i> be CreatePerIterationEnvironment(<i>perIterationBindings</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Repeat
+ <ol class="block">
+ <li>If <i>testExpr</i> is not <span style="font-family: sans-serif">[empty</span>], then
+ <ol class="block">
+ <li>Let <i>testExprRef</i> be the result of evaluating <i>testExpr</i>.</li>
+ <li>Let <i>testExprValue</i> be <a href="#sec-toboolean">ToBoolean</a>(<a
+ href="#sec-getvalue">GetValue</a>(<i>testExprRef</i>))</li>
+ <li>If <i>testExprValue</i> is <b>false</b>, return <a
+ href="#sec-normalcompletion">NormalCompletion</a>(<i>V</i>).</li>
+ <li>Else if <a href="#sec-loopcontinues">LoopContinues</a> (<i>testExprValue</i>,<i>labelSet</i>) is
+ <b>false</b>, return <i>testExprValue.</i></li>
+ </ol>
+ </li>
+ <li>Let <i>result</i> be the result of evaluating <i>stmt</i>.</li>
+ <li>If <i>result</i>.[[value]] is not <span style="font-family: sans-serif">empty</span>, let <i>V</i> =
+ <i>result</i>.[[value]].</li>
+ <li>If <a href="#sec-loopcontinues">LoopContinues</a> (<i>result</i>,<i>labelSet</i>) is <b>false</b>, return
+ <i>result</i>.</li>
+ <li>Let <i>status</i> be CreatePerIterationEnvironment(<i>perIterationBindings</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>If <i>incrementExpr</i> is not <span style="font-family: sans-serif">[empty]</span>, then
+ <ol class="block">
+ <li>Let <i>incExprRef</i> be the result of evaluating <i>incrementExpr</i>.</li>
+ <li>Let <i>incExprValue</i> be <a href="#sec-getvalue">GetValue</a>(<i>incExprRef</i>).</li>
+ <li>If <a href="#sec-loopcontinues">LoopContinues</a>(<i>incExprValue</i>,<i>labelSet</i>) is <b>false</b>,
+ return <i>incExprValue.</i></li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </section>
+
+ <section id="sec-runtime-semantics-createperiterationenvironment">
+ <h1><span class="secnum" id="sec-13.6.3.5"><a href="#sec-runtime-semantics-createperiterationenvironment"
+ title="link to this section">13.6.3.5</a></span> Runtime Semantics: CreatePerIterationEnvironment</h1>
+
+ <p>The abstract operation CreatePerIterationEnvironment with argument <var>perIterationBindings</var> is performed as
+ follows:</p>
+
+ <ol class="proc">
+ <li>If <i>perIterationBindings</i> has any elements, then
+ <ol class="block">
+ <li>Let <i>lastIterationEnv</i> be <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-execution-contexts">LexicalEnvironment</a>.</li>
+ <li>Let <i>outer</i> be <i>lastIterationEnv</i>’s <a href="#sec-lexical-environments">outer environment
+ reference</a>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>outer</i> is not <b>null</b>.</li>
+ <li>Let <i>thisIterationEnv</i> be <a
+ href="#sec-newdeclarativeenvironment">NewDeclarativeEnvironment</a>(<i>outer</i>).</li>
+ <li>For each element <i>bn</i> of <i>perIterationBindings</i> do,
+ <ol class="block">
+ <li>Let <i>status</i> be the result of calling <i>thisIterationEnv</i>’s CreateMutableBinding concrete
+ method passing <i>bn</i> and <b>false</b> as the arguments.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>status</i> is never an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a>.</li>
+ <li>Let <i>lastValue</i> be the result of calling <i>lastIterationEnv</i>’s GetBindingValue concrete
+ method passing <i>bn</i> and <b>true</b> as the arguments.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>lastValue</i>).</li>
+ <li>Call the InitializeBinding concrete method of <i>thisIterationEnv</i> passing <i>bn</i> and <i>lastValue</i>
+ as the arguments.</li>
+ </ol>
+ </li>
+ <li>Set <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-execution-contexts">LexicalEnvironment</a> to <i>thisIterationEnv.</i></li>
+ </ol>
+ </li>
+ <li>Return <b>undefined</b></li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-for-in-and-for-of-statements">
+ <div class="front">
+ <h1><span class="secnum" id="sec-13.6.4"><a href="#sec-for-in-and-for-of-statements"
+ title="link to this section">13.6.4</a></span> The <code>for</code>-<code>in</code> and
+ <code>for</code>-<code>of</code> Statements</h1>
+ </div>
+
+ <section id="sec-for-in-and-for-of-statements-static-semantics-early-errors">
+ <h1><span class="secnum" id="sec-13.6.4.1"><a href="#sec-for-in-and-for-of-statements-static-semantics-early-errors"
+ title="link to this section">13.6.4.1</a></span> Static Semantics: Early Errors</h1>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">IterationStatement</span> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">for</code> <code class="t">(</code> <span class="nt">LeftHandSideExpression</span> <code class="t">in</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <div class="rhs"><code class="t">for</code> <code class="t">(</code> <span class="nt">LeftHandSideExpression</span> <code class="t">of</code> <span class="nt">AssignmentExpression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ </div>
+
+ <ul>
+ <li>
+ <p>It is a Syntax Error if <span class="nt">LeftHandSideExpression</span> is either an <span
+ class="nt">ObjectLiteral</span> or an <span class="nt">ArrayLiteral</span> and if the lexical token sequence matched
+ by <span class="nt">LeftHandSideExpression</span> cannot be parsed with no tokens left over using <span
+ class="nt">AssignmentPattern</span> as the goal symbol.</p>
+ </li>
+
+ <li>
+ <p>If <span class="nt">LeftHandSideExpression</span> is either an <span class="nt">ObjectLiteral</span> or an <span
+ class="nt">ArrayLiteral</span> and if the lexical token sequence matched by <span
+ class="nt">LeftHandSideExpression</span> can be parsed with no tokens left over using <span
+ class="nt">AssignmentPattern</span> as the goal symbol then the following rules are not applied. Instead, the Early
+ Error rules for <span class="nt">AssignmentPattern</span> are used.</p>
+ </li>
+
+ <li>
+ <p>It is a Syntax Error if <span class="nt">LeftHandSideExpression</span> is a <span
+ class="nt">IdentifierReference</span> that can be statically determined to always resolve to a <a
+ href="#sec-declarative-environment-records">declarative environment record</a> binding and the resolved binding is an
+ immutable binding.</p>
+ </li>
+
+ <li>
+ <p>It is a Syntax Error if <span class="nt">LeftHandSideExpression</span> is neither an <span
+ class="nt">ObjectLiteral</span> nor an <span class="nt">ArrayLiteral</span> and <span style="font-family: Times New
+ Roman">IsValidSimpleAssignmentTarget</span> of <span class="nt">LeftHandSideExpression</span> is <span
+ class="value">false</span>.</p>
+ </li>
+
+ <li>
+ <p>It is a Syntax Error if the <span class="nt">LeftHandSideExpression</span> is <span
+ class="prod"><span class="nt">CoverParenthesizedExpressionAndArrowParameterList</span> <span class="geq">:</span>
+ <code class="t">(</code> <span class="nt">Expression</span> <code class="t">)</code></span> and <span
+ class="nt">Expression</span> derives a production that would produce a Syntax Error according to these rules if that
+ production is substituted for <span class="nt">LeftHandSideExpression</span>. This rule is recursively applied.</p>
+ </li>
+ </ul>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The last rule means that the other rules are applied even if parentheses surround
+ <i>Expression</i>.</p>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">IterationStatement</span> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">for</code> <code class="t">(</code> <span class="nt">ForDeclaration</span> <code class="t">in</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <div class="rhs"><code class="t">for</code> <code class="t">(</code> <span class="nt">ForDeclaration</span> <code class="t">of</code> <span class="nt">AssignmentExpression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ </div>
+
+ <ul>
+ <li>
+ <p>It is a Syntax Error if the BoundNames of <span class="nt">ForDeclaration</span> contains <code>"let"</code>.</p>
+ </li>
+
+ <li>
+ <p>It is a Syntax Error if any element of the BoundNames of <span class="nt">ForDeclaration</span> also occurs in the
+ VarDeclaredNames of <span class="nt">Statement</span>.</p>
+ </li>
+ </ul>
+ </section>
+
+ <section id="sec-for-in-and-for-of-statements-static-semantics-boundnames">
+ <h1><span class="secnum" id="sec-13.6.4.2"><a href="#sec-for-in-and-for-of-statements-static-semantics-boundnames"
+ title="link to this section">13.6.4.2</a></span> Static Semantics: BoundNames</h1>
+
+ <p>See also: <a href="#sec-let-and-const-declarations-static-semantics-boundnames">13.2.1.2</a>, <a
+ href="#sec-variable-statement-static-semantics-boundnames">13.2.2.1</a>, <a
+ href="#sec-identifiers-static-semantics-boundnames">12.1.2</a>, <a
+ href="#sec-function-definitions-static-semantics-boundnames">14.1.3</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-boundnames">14.2.2</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-boundnames">14.4.2</a>, <a
+ href="#sec-class-definitions-static-semantics-boundnames">14.5.2</a>, <a
+ href="#sec-imports-static-semantics-boundnames">15.2.1.2</a>, <a
+ href="#sec-exports-static-semantics-boundnames">15.2.2.1</a>.</p>
+
+ <div class="gp prod"><span class="nt">ForDeclaration</span> <span class="geq">:</span> <span class="nt">LetOrConst</span> <span class="nt">ForBinding</span></div>
+ <ol class="proc">
+ <li>Return the BoundNames of <i>ForBinding</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-for-in-and-for-of-statements-static-semantics-vardeclarednames">
+ <h1><span class="secnum" id="sec-13.6.4.3"><a href="#sec-for-in-and-for-of-statements-static-semantics-vardeclarednames"
+ title="link to this section">13.6.4.3</a></span> Static Semantics: VarDeclaredNames</h1>
+
+ <p>See also: <a href="#sec-statement-semantics-static-semantics-vardeclarednames">13.0.1</a>, <a
+ href="#sec-block-static-semantics-vardeclarednames">13.1.8</a>, <a
+ href="#sec-variable-statement-static-semantics-vardeclarednames">13.2.2.2</a>, <a
+ href="#sec-if-statement-static-semantics-vardeclarednames">13.5.1</a>, <a
+ href="#sec-do-while-statement-static-semantics-vardeclarednames">13.6.1.1</a>, <a
+ href="#sec-while-statement-static-semantics-vardeclarednames">13.6.2.1</a>, <a
+ href="#sec-for-statement-static-semantics-vardeclarednames">13.6.3.1</a>, <a
+ href="#sec-with-statement-static-semantics-vardeclarednames">13.10.2</a>, <a
+ href="#sec-switch-statement-static-semantics-vardeclarednames">13.11.4</a>, <a
+ href="#sec-static-semantics-currentlabelset">13.12.2</a>, <a
+ href="#sec-try-statement-static-semantics-vardeclarednames">13.14.2</a>, <a
+ href="#sec-function-definitions-static-semantics-referencessuper">14.1.16</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-vardeclarednames">14.4.12</a>, <a
+ href="#sec-class-definitions-static-semantics-vardeclarednames">14.5.15</a>, <a
+ href="#sec-scripts-static-semantics-vardeclarednames">15.1.5</a>, <a
+ href="#sec-module-static-semantics-static-semantics-vardeclarednames">15.2.0.13</a>.</p>
+
+ <div class="gp prod"><span class="nt">IterationStatement</span> <span class="geq">:</span> <code class="t">for</code> <code class="t">(</code> <span class="nt">LeftHandSideExpression</span> <code class="t">in</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Return the VarDeclaredNames of <i>Statement</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">IterationStatement</span> <span class="geq">:</span> <code class="t">for</code> <code class="t">(</code> <code class="t">var</code> <span class="nt">ForBinding</span> <code class="t">in</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Let <i>names</i> be the BoundNames of <i>ForBinding</i>.</li>
+ <li>Append to <i>names</i> the elements of the VarDeclaredNames of <i>Statement.</i></li>
+ <li>Return <i>names.</i></li>
+ </ol>
+ <div class="gp prod"><span class="nt">IterationStatement</span> <span class="geq">:</span> <code class="t">for</code> <code class="t">(</code> <span class="nt">ForDeclaration</span> <code class="t">in</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Return the VarDeclaredNames of <i>Statement</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">IterationStatement</span> <span class="geq">:</span> <code class="t">for</code> <code class="t">(</code> <span class="nt">LeftHandSideExpression</span> <code class="t">of</code> <span class="nt">AssignmentExpression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Return the VarDeclaredNames of <i>Statement</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">IterationStatement</span> <span class="geq">:</span> <code class="t">for</code> <code class="t">(</code> <code class="t">var</code> <span class="nt">ForBinding</span> <code class="t">of</code> <span class="nt">AssignmentExpression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Let <i>names</i> be the BoundNames of <i>ForBinding</i>.</li>
+ <li>Append to <i>names</i> the elements of the VarDeclaredNames of <i>Statement.</i></li>
+ <li>Return <i>names.</i></li>
+ </ol>
+ <div class="gp prod"><span class="nt">IterationStatement</span> <span class="geq">:</span> <code class="t">for</code> <code class="t">(</code> <span class="nt">ForDeclaration</span> <code class="t">of</code> <span class="nt">AssignmentExpression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Return the VarDeclaredNames of <i>Statement</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-for-in-and-for-of-statements-static-semantics-varscopeddeclarations">
+ <h1><span class="secnum" id="sec-13.6.4.4"><a
+ href="#sec-for-in-and-for-of-statements-static-semantics-varscopeddeclarations"
+ title="link to this section">13.6.4.4</a></span> Static Semantics: VarScopedDeclarations</h1>
+
+ <p>See also: <a href="#sec-statement-semantics-static-semantics-varscopeddeclarations">13.0.2</a>, <a
+ href="#sec-block-static-semantics-varscopeddeclarations">13.1.9</a>, <a
+ href="#sec-variable-statement-static-semantics-varscopeddeclarations">13.2.2.3</a>, <a
+ href="#sec-if-statement-static-semantics-varscopeddeclarations">13.5.2</a>, <a
+ href="#sec-do-while-statement-static-semantics-varscopeddeclarations">13.6.1.2</a>, <a
+ href="#sec-while-statement-static-semantics-varscopeddeclarations">13.6.2.2</a>, <a
+ href="#sec-for-statement-static-semantics-varscopeddeclarations">13.6.3.2</a>, <a
+ href="#sec-with-statement-static-semantics-varscopeddeclarations">13.10.3</a>, <a
+ href="#sec-switch-statement-static-semantics-varscopeddeclarations">13.11.5</a>, <a
+ href="#sec-labelled-statements-static-semantics-varscopeddeclarations">13.12.4</a>, <a
+ href="#sec-try-statement-static-semantics-varscopeddeclarations">13.14.3</a>, <a
+ href="#sec-function-definitions-static-semantics-varscopeddeclarations">14.1.18</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-varscopeddeclarations">14.2.14</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-varscopeddeclarations">14.4.13</a>, <a
+ href="#sec-scripts-static-semantics-varscopeddeclarations">15.1.6</a>, <a
+ href="#sec-module-static-semantics-static-semantics-varscopeddeclarations">15.2.0.14</a>.</p>
+
+ <div class="gp prod"><span class="nt">IterationStatement</span> <span class="geq">:</span> <code class="t">for</code> <code class="t">(</code> <span class="nt">LeftHandSideExpression</span> <code class="t">in</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Return the VarScopedDeclarations of <i>Statement</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">IterationStatement</span> <span class="geq">:</span> <code class="t">for</code> <code class="t">(</code> <code class="t">var</code> <span class="nt">ForBinding</span> <code class="t">in</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Let <i>declarations</i> be a <a href="#sec-list-and-record-specification-type">List</a> containing
+ <i>ForBinding</i>.</li>
+ <li>Append to <i>declarations</i> the elements of the VarScopedDeclarations of <i>Statement.</i></li>
+ <li>Return <i>declarations.</i></li>
+ </ol>
+ <div class="gp prod"><span class="nt">IterationStatement</span> <span class="geq">:</span> <code class="t">for</code> <code class="t">(</code> <span class="nt">ForDeclaration</span> <code class="t">in</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Return the VarScopedDeclarations of <i>Statement</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">IterationStatement</span> <span class="geq">:</span> <code class="t">for</code> <code class="t">(</code> <span class="nt">LeftHandSideExpression</span> <code class="t">of</code> <span class="nt">AssignmentExpression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Return the VarScopedDeclarations of <i>Statement</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">IterationStatement</span> <span class="geq">:</span> <code class="t">for</code> <code class="t">(</code> <code class="t">var</code> <span class="nt">ForBinding</span> <code class="t">of</code> <span class="nt">AssignmentExpression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Let <i>declarations</i> be a <a href="#sec-list-and-record-specification-type">List</a> containing
+ <i>ForBinding</i>.</li>
+ <li>Append to <i>declarations</i> the elements of the VarScopedDeclarations of <i>Statement.</i></li>
+ <li>Return <i>declarations.</i></li>
+ </ol>
+ <div class="gp prod"><span class="nt">IterationStatement</span> <span class="geq">:</span> <code class="t">for</code> <code class="t">(</code> <span class="nt">ForDeclaration</span> <code class="t">of</code> <span class="nt">AssignmentExpression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Return the VarScopedDeclarations of <i>Statement</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-runtime-semantics-bindinginstantiation">
+ <h1><span class="secnum" id="sec-13.6.4.5"><a href="#sec-runtime-semantics-bindinginstantiation"
+ title="link to this section">13.6.4.5</a></span> Runtime Semantics: BindingInstantiation</h1>
+
+ <p>With arguments <var>value</var> and <var>environment</var>.</p>
+
+ <p>See also: <a href="#sec-statement-semantics-static-semantics-varscopeddeclarations">13.0.2</a>, <a
+ href="#sec-do-while-statement-static-semantics-varscopeddeclarations">13.6.1.2</a>, <a
+ href="#sec-while-statement-static-semantics-varscopeddeclarations">13.6.2.2</a>, <a
+ href="#sec-for-statement-static-semantics-varscopeddeclarations">13.6.3.2</a>, <a
+ href="#sec-labelled-statements-static-semantics-varscopeddeclarations">13.12.4</a>.</p>
+
+ <div class="gp prod"><span class="nt">ForDeclaration</span> <span class="geq">:</span> <span class="nt">LetOrConst</span> <span class="nt">ForBinding</span></div>
+ <ol class="proc">
+ <li>For each element <i>name</i> of the BoundNames of <i>ForBinding</i> do
+ <ol class="block">
+ <li>If IsConstantDeclaration of <i>LetOrConst</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Call <i>environment</i>’s CreateImmutableBinding concrete method with argument <i>name</i>.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Call <i>environment</i>’s CreateMutableBinding concrete method with argument <i>name</i>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: The above call to CreateMutableBinding will never return an
+ <a href="#sec-completion-record-specification-type">abrupt completion</a>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Return the result of performing BindingInitialization for <i>ForBinding</i> passing <i>value</i> and
+ <i>environment</i> as the arguments.</li>
+ </ol>
+ </section>
+
+ <section id="sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation">
+ <h1><span class="secnum" id="sec-13.6.4.6"><a
+ href="#sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation"
+ title="link to this section">13.6.4.6</a></span> Runtime Semantics: LabelledEvaluation</h1>
+
+ <p>With argument <var>labelSet</var>.</p>
+
+ <p>See also: <a href="#sec-statement-semantics-static-semantics-varscopeddeclarations">13.0.2</a>, <a
+ href="#sec-do-while-statement-static-semantics-varscopeddeclarations">13.6.1.2</a>, <a
+ href="#sec-while-statement-static-semantics-varscopeddeclarations">13.6.2.2</a>, <a
+ href="#sec-for-statement-static-semantics-varscopeddeclarations">13.6.3.2</a>, <a
+ href="#sec-labelled-statements-static-semantics-varscopeddeclarations">13.12.4</a>.</p>
+
+ <div class="gp prod"><span class="nt">IterationStatement</span> <span class="geq">:</span> <code class="t">for</code> <code class="t">(</code> <span class="nt">LeftHandSideExpression</span> <code class="t">in</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Let <i>keyResult</i> be ForIn/OfExpressionEvaluation( ( ), <i>Expression</i>, <span style="font-family:
+ sans-serif">enumerate</span>, <i>labelSet</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>keyResult</i>).</li>
+ <li>Return the result of performing ForIn/OfBodyEvaluation with <i>LeftHandSideExpression</i>, <i>Statement</i>,
+ <i>keyResult</i>, <span style="font-family: sans-serif">assignment</span>, and <i>labelSet</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">IterationStatement</span> <span class="geq">:</span> <code class="t">for</code> <code class="t">(</code> <code class="t">var</code> <span class="nt">ForBinding</span> <code class="t">in</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Let <i>keyResult</i> be ForIn/OfExpressionEvaluation( ( ), <i>Expression</i>, <span style="font-family:
+ sans-serif">enumerate</span>, <i>labelSet</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>keyResult</i>).</li>
+ <li>Return the result of performing ForIn/OfBodyEvaluation with <i>ForBinding</i>, <i>Statement</i>, <i>keyResult</i>,
+ <span style="font-family: sans-serif">varBinding</span>, and <i>labelSet</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">IterationStatement</span> <span class="geq">:</span> <code class="t">for</code> <code class="t">(</code> <span class="nt">ForDeclaration</span> <code class="t">in</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Let <i>keyResult</i> be the result of performing ForIn/OfExpressionEvaluation(BoundNames of <i>ForDeclaration,</i>
+ <i>Expression</i>, <span style="font-family: sans-serif">enumerate</span>, <i>labelSet</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>keyResult</i>).</li>
+ <li>Return the result of performing ForIn/OfBodyEvaluation with <i>ForDeclaration</i>, <i>Statement</i>,
+ <i>keyResult</i>, <span style="font-family: sans-serif">lexicalBinding</span>, and <i>labelSet</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">IterationStatement</span> <span class="geq">:</span> <code class="t">for</code> <code class="t">(</code> <span class="nt">LeftHandSideExpression</span> <code class="t">of</code> <span class="nt">AssignmentExpression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Let <i>keyResult</i> be the result of performing ForIn/OfExpressionEvaluation( ( ), <i>AssignmentExpression</i>,
+ <span style="font-family: sans-serif">iterate</span>, <i>labelSet</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>keyResult</i>).</li>
+ <li>Return the result of performing ForIn/OfBodyEvaluation with <i>LeftHandSideExpression</i>, <i>Statement</i>,
+ <i>keyResult</i>, <span style="font-family: sans-serif">assignment</span>, and <i>labelSet</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">IterationStatement</span> <span class="geq">:</span> <code class="t">for</code> <code class="t">(</code> <code class="t">var</code> <span class="nt">ForBinding</span> <code class="t">of</code> <span class="nt">AssignmentExpression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Let <i>keyResult</i> be the result of performing ForIn/OfExpressionEvaluation( ( ), <i>AssignmentExpression</i>,
+ <span style="font-family: sans-serif">iterate</span>, <i>labelSet</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>keyResult</i>).</li>
+ <li>Return the result of performing ForIn/OfBodyEvaluation with <i>ForBinding</i>, <i>Statement</i>, <i>keyResult</i>,
+ <span style="font-family: sans-serif">varBinding</span>, and <i>labelSet</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">IterationStatement</span> <span class="geq">:</span> <code class="t">for</code> <code class="t">(</code> <span class="nt">ForDeclaration</span> <code class="t">of</code> <span class="nt">AssignmentExpression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Let <i>keyResult</i> be the result of performing ForIn/OfExpressionEvaluation( BoundNames of <i>ForDeclaration</i>,
+ <i>AssignmentExpression</i>, <span style="font-family: sans-serif">iterate</span>, <i>labelSet</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>keyResult</i>).</li>
+ <li>Return the result of performing ForIn/OfBodyEvaluation with <i>ForDeclaration</i>, <i>Statement</i>,
+ <i>keyResult</i>, <span style="font-family: sans-serif">lexicalBinding</span>, and <i>labelSet</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-runtime-semantics-forin-div-ofexpressionevaluation-abstract-operation">
+ <h1><span class="secnum" id="sec-13.6.4.7"><a
+ href="#sec-runtime-semantics-forin-div-ofexpressionevaluation-abstract-operation"
+ title="link to this section">13.6.4.7</a></span> Runtime Semantics: ForIn/OfExpressionEvaluation Abstract
+ Operation</h1>
+
+ <p>The abstract operation ForIn/OfExpressionEvaluation is called with arguments <span class="nt">TDZnames</span>,
+ <var>expr</var>, <var>iterationKind</var>, and <span style="font-family: Times New Roman"><i>labelSet</i>.</span> The
+ value of <var>iterationKind</var> is either <b>enumerate</b> or <b>iterate</b>.</p>
+
+ <ol class="proc">
+ <li>Let <i>oldEnv</i> be <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-execution-contexts">LexicalEnvironment</a>.</li>
+ <li>If <i>TDZnames</i> is not an empty <a href="#sec-list-and-record-specification-type">List</a>, then
+ <ol class="block">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>TDZnames</i> has no duplicate entries.</li>
+ <li>Let <i>TDZ</i> be <a href="#sec-newdeclarativeenvironment">NewDeclarativeEnvironment</a>(<i>oldEnv</i>).</li>
+ <li>For each string <i>name</i> in <i>TDZnames</i>, do
+ <ol class="block">
+ <li>Let <i>status</i> be the result of calling <i>TDZ</i>’s CreateMutableBinding concrete method passing
+ <i>name</i> and <b>false</b> as the arguments.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>status</i> is never an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a>.</li>
+ </ol>
+ </li>
+ <li>Set <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-execution-contexts">LexicalEnvironment</a> to <i>TDZ</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>exprRef</i> be the result of evaluating the production that is <i>expr</i>.</li>
+ <li>Set <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-execution-contexts">LexicalEnvironment</a> to <i>oldEnv</i>.</li>
+ <li>Let <i>exprValue</i> be <a href="#sec-getvalue">GetValue</a>(<i>exprRef</i>).</li>
+ <li>If <i>exprValue</i> is an <a href="#sec-completion-record-specification-type">abrupt completion</a>,
+ <ol class="block">
+ <li>If <a href="#sec-loopcontinues">LoopContinues</a>(<i>exprValue</i>,<i>labelSet</i>) is <b>false</b>, then return
+ <i>exprValue</i>.</li>
+ <li>Else, return <a href="#sec-completion-record-specification-type">Completion</a>{[[type]]: <span
+ style="font-family: sans-serif">break</span>, [[value]]: <span style="font-family: sans-serif">empty,</span>
+ [[target]]: <span style="font-family: sans-serif">empty</span>}.</li>
+ </ol>
+ </li>
+ <li>If <i>exprValue</i>.[[value]] is <b>null</b> or <b>undefined</b>, then
+ <ol class="block">
+ <li>Return <a href="#sec-completion-record-specification-type">Completion</a>{[[type]]: <span style="font-family:
+ sans-serif">break</span>, [[value]]: <span style="font-family: sans-serif">empty,</span> [[target]]: <span
+ style="font-family: sans-serif">empty</span>}.</li>
+ </ol>
+ </li>
+ <li>Let <i>obj</i> be <a href="#sec-toobject">ToObject</a>(<i>exprValue</i>).</li>
+ <li>If <i>iterationKind</i> is <span style="font-family: sans-serif">enumerate</span>, then
+ <ol class="block">
+ <li>Let <i>keys</i> be the result of calling the [[Enumerate]] internal method of <i>obj</i> with no arguments.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>iterationKind</i> is <span style="font-family:
+ sans-serif">iterate</span>.</li>
+ <li>Let <i>keys</i> be <a href="#sec-getiterator">GetIterator</a>(<i>obj</i>).</li>
+ </ol>
+ </li>
+ <li>If <i>keys</i> is an <a href="#sec-completion-record-specification-type">abrupt completion</a>, then
+ <ol class="block">
+ <li>If <a href="#sec-loopcontinues">LoopContinues</a>(<i>keys</i>,<i>labelSet</i>) is <b>false</b>, then return
+ <i>keys</i>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>keys</i>.[[type]] is <span style="font-family:
+ sans-serif">continue</span></li>
+ <li>Return <a href="#sec-completion-record-specification-type">Completion</a>{[[type]]: <span style="font-family:
+ sans-serif">break</span>, [[value]]: <span style="font-family: sans-serif">empty</span>, [[target]]: <span
+ style="font-family: sans-serif">empty</span>}.</li>
+ </ol>
+ </li>
+ <li>Return <i>keys</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-runtime-semantics-forin-div-ofbodyevaluation">
+ <h1><span class="secnum" id="sec-13.6.4.8"><a href="#sec-runtime-semantics-forin-div-ofbodyevaluation"
+ title="link to this section">13.6.4.8</a></span> Runtime Semantics: ForIn/OfBodyEvaluation</h1>
+
+ <p>The abstract operation ForIn/OfBodyEvaluation is called with arguments <var>lhs</var>, <var>stmt, keys,</var>
+ <var>lhsKind</var>, and <var>labelSet.</var> The value of <var>lhsKind</var> is either <b>assignment</b>,
+ <b>varBinding</b> or <b>lexicalBinding</b>.</p>
+
+ <ol class="proc">
+ <li>Let <i>oldEnv</i> be <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-execution-contexts">LexicalEnvironment</a>.</li>
+ <li>Let <i>V</i> = <b>undefined</b> .</li>
+ <li>Repeat
+ <ol class="block">
+ <li>Let <i>nextResult</i> be <a href="#sec-iteratorstep">IteratorStep</a>(<i>keys</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>nextResult</i>).</li>
+ <li>If <i>nextResult</i> is <b>false</b>, then return <a
+ href="#sec-normalcompletion">NormalCompletion</a>(<i>V</i>).</li>
+ <li>Let <i>nextValue</i> be <a href="#sec-iteratorvalue">IteratorValue</a>(<i>nextResult</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>nextValue</i>).</li>
+ <li>If <i>lhsKind</i> is <span style="font-family: sans-serif">assignment</span>, then
+ <ol class="block">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>lhs</i> is a <i>LeftHandSideExpression</i>.</li>
+ <li>If <i>lhs</i> is neither an <i>ObjectLiteral</i> nor an <i>ArrayLiteral</i> then
+ <ol class="block">
+ <li>Let <i>lhsRef</i> be the result of evaluating <i>lhs</i> ( it may be evaluated repeatedly).</li>
+ <li>Let <i>status</i> be <a href="#sec-putvalue">PutValue</a>(<i>lhsRef</i>, <i>nextValue</i>).</li>
+ </ol>
+ </li>
+ <li>Else
+ <ol class="block">
+ <li>Let <i>assignmentPattern</i> be the parse of the source code corresponding to <i>lhs</i> using
+ <i>AssignmentPattern</i> as the goal symbol.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>nextValue</i>) is not Object, then throw
+ a <b>TypeError</b> exception.</li>
+ <li>Let <i>status</i> be the result of performing DestructuringAssignmentEvaluation of
+ <i>AssignmentPattern</i> using <i>nextValue</i> as the argument.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Else if <i>lhsKind</i> is <span style="font-family: sans-serif">varBinding</span>, then
+ <ol class="block">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>lhs</i> is a <i>ForBinding</i>.</li>
+ <li>Let <i>status</i> be the result of performing BindingInitialization for <i>lhs</i> passing <i>nextValue</i>
+ and <b>undefined</b> as the arguments.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>lhsKind</i> is <span style="font-family:
+ sans-serif">lexicalBinding</span>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>lhs</i> is a <i>ForDeclaration</i>.</li>
+ <li>Let <i>iterationEnv</i> be <a
+ href="#sec-newdeclarativeenvironment">NewDeclarativeEnvironment</a>(<i>oldEnv</i>).</li>
+ <li>Let <i>status</i> be the result of performing BindingInstantiation for <i>lhs</i> passing <i>nextValue</i>
+ and <i>iterationEnv</i> as arguments.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>status</i> is not an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a>.</li>
+ <li>Set <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-execution-contexts">LexicalEnvironment</a> to <i>iterationEnv</i>.</li>
+ </ol>
+ </li>
+ <li>If <i>status</i>.[[type]] is <span style="font-family: sans-serif">normal</span>, then
+ <ol class="block">
+ <li>Let <i>status</i> be the result of evaluating <i>stmt</i>.</li>
+ <li>If <i>status</i>.[[type]] is <span style="font-family: sans-serif">normal</span> and <i>status</i>.[[value]]
+ is not <span style="font-family: sans-serif">empty</span>, then
+ <ol class="block">
+ <li>Let <i>V</i> = <i>status</i>.[[value]].</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Set <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-execution-contexts">LexicalEnvironment</a> to <i>oldEnv</i>.</li>
+ <li>If <i>status</i> is an <a href="#sec-completion-record-specification-type">abrupt completion</a> and <a
+ href="#sec-loopcontinues">LoopContinues</a>(<i>status</i>,<i>labelSet</i>) is <b>false</b>, then return
+ <i>status</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </section>
+ </section>
+ </section>
+
+ <section id="sec-continue-statement">
+ <div class="front">
+ <h1><span class="secnum" id="sec-13.7"><a href="#sec-continue-statement" title="link to this section">13.7</a></span> The
+ <code>continue</code> Statement</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ContinueStatement</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">continue</code> <code class="t">;</code></div>
+ <div class="rhs"><code class="t">continue</code> <span class="grhsannot">[no <span class="nt">LineTerminator</span> here]</span> <span class="nt">LabelIdentifier</span><sub>[?Yield]</sub> <code class="t">;</code></div>
+ </div>
+ </div>
+
+ <section id="sec-continue-statement-static-semantics-early-errors">
+ <h1><span class="secnum" id="sec-13.7.1"><a href="#sec-continue-statement-static-semantics-early-errors"
+ title="link to this section">13.7.1</a></span> Static Semantics: Early Errors</h1>
+ <div class="gp prod"><span class="nt">ContinueStatement</span> <span class="geq">:</span> <code class="t">continue</code> <code class="t">;</code></div>
+ <ul>
+ <li>
+ <p>It is a Syntax Error if this production is not nested, directly or indirectly (but not crossing function boundaries),
+ within an <span class="nt">IterationStatement</span>.</p>
+ </li>
+ </ul>
+ <div class="gp prod"><span class="nt">ContinueStatement</span> <span class="geq">:</span> <code class="t">continue</code> <span class="nt">LabelIdentifier</span> <code class="t">;</code></div>
+ <ul>
+ <li>
+ <p>It is a Syntax Error if this production is not nested, directly or indirectly (but not crossing function boundaries),
+ within an <span class="nt">IterationStatement</span>.</p>
+ </li>
+
+ <li>
+ <p>It is a Syntax Error if StringValue(<span class="nt">LabelIdentifier</span>) does not appear in the enclosing
+ IterationLabelSet of this <span class="nt">ContinueStatement</span>.</p>
+ </li>
+ </ul>
+ </section>
+
+ <section id="sec-continue-statement-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-13.7.2"><a href="#sec-continue-statement-runtime-semantics-evaluation"
+ title="link to this section">13.7.2</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">ContinueStatement</span> <span class="geq">:</span> <code class="t">continue</code> <code class="t">;</code></div>
+ <ol class="proc">
+ <li>Return <a href="#sec-completion-record-specification-type">Completion</a>{[[type]]: <span style="font-family:
+ sans-serif">continue</span>, [[value]]: <span style="font-family: sans-serif">empty</span>, [[target]]: <span
+ style="font-family: sans-serif">empty</span>}.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ContinueStatement</span> <span class="geq">:</span> <code class="t">continue</code> <span class="nt">LabelIdentifier</span> <code class="t">;</code></div>
+ <ol class="proc">
+ <li>Let <i>label</i> be the StringValue of <i>LabelIdentifier</i>.</li>
+ <li>Return <a href="#sec-completion-record-specification-type">Completion</a>{[[type]]: <span style="font-family:
+ sans-serif">continue</span>, [[value]]: <span style="font-family: sans-serif">empty</span>, [[target]]: <i>label</i>
+ }.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-break-statement">
+ <div class="front">
+ <h1><span class="secnum" id="sec-13.8"><a href="#sec-break-statement" title="link to this section">13.8</a></span> The
+ <code>break</code> Statement</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">BreakStatement</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">break</code> <code class="t">;</code></div>
+ <div class="rhs"><code class="t">break</code> <span class="grhsannot">[no <span class="nt">LineTerminator</span> here]</span> <span class="nt">LabelIdentifier</span><sub>[?Yield]</sub> <code class="t">;</code></div>
+ </div>
+ </div>
+
+ <section id="sec-break-statement-static-semantics-early-errors">
+ <h1><span class="secnum" id="sec-13.8.1"><a href="#sec-break-statement-static-semantics-early-errors"
+ title="link to this section">13.8.1</a></span> Static Semantics: Early Errors</h1>
+ <div class="gp prod"><span class="nt">BreakStatement</span> <span class="geq">:</span> <code class="t">break</code> <code class="t">;</code></div>
+ <ul>
+ <li>
+ <p>It is a Syntax Error if this production is not nested, directly or indirectly (but not crossing function boundaries),
+ within an <span class="nt">IterationStatement</span> or a <span class="nt">SwitchStatement</span>.</p>
+ </li>
+ </ul>
+ <div class="gp prod"><span class="nt">BreakStatement</span> <span class="geq">:</span> <code class="t">break</code> <span class="nt">LabelIdentifier</span> <code class="t">;</code></div>
+ <ul>
+ <li>
+ <p>It is a Syntax Error if StringValue(<span class="nt">LabelIdentifier</span>) does not appear in the enclosing
+ CurrentLabelSet of this <span class="nt">BreakStatement</span>.</p>
+ </li>
+ </ul>
+ </section>
+
+ <section id="sec-break-statement-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-13.8.2"><a href="#sec-break-statement-runtime-semantics-evaluation"
+ title="link to this section">13.8.2</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">BreakStatement</span> <span class="geq">:</span> <code class="t">break</code> <code class="t">;</code></div>
+ <ol class="proc">
+ <li>Return <a href="#sec-completion-record-specification-type">Completion</a>{[[type]]: <span style="font-family:
+ sans-serif">break</span>, [[value]]: <span style="font-family: sans-serif">empty</span>, [[target]]: <span
+ style="font-family: sans-serif">empty</span>}.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">BreakStatement</span> <span class="geq">:</span> <code class="t">break</code> <span class="nt">LabelIdentifier</span> <code class="t">;</code></div>
+ <ol class="proc">
+ <li>Let <i>label</i> be the StringValue of <i>LabelIdentifier</i>.</li>
+ <li>Return <a href="#sec-completion-record-specification-type">Completion</a>{[[type]]: <span style="font-family:
+ sans-serif">break</span>, [[value]]: <span style="font-family: sans-serif">empty</span>, [[target]]: <i>label</i>
+ }.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-return-statement">
+ <div class="front">
+ <h1><span class="secnum" id="sec-13.9"><a href="#sec-return-statement" title="link to this section">13.9</a></span> The
+ <code>return</code> Statement</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ReturnStatement</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">return</code> <code class="t">;</code></div>
+ <div class="rhs"><code class="t">return</code> <span class="grhsannot">[no <span class="nt">LineTerminator</span> here]</span> <span class="nt">Expression</span><sub>[In, ?Yield]</sub> <code class="t">;</code></div>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> A <code>return</code> statement causes a function to cease execution and return a value to
+ the caller. If <span class="nt">Expression</span> is omitted, the return value is <b>undefined</b>. Otherwise, the return
+ value is the value of <span class="nt">Expression</span>.</p>
+ </div>
+ </div>
+
+ <section id="sec-return-statement-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-13.9.1"><a href="#sec-return-statement-runtime-semantics-evaluation"
+ title="link to this section">13.9.1</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">ReturnStatement</span> <span class="geq">:</span> <code class="t">return</code> <code class="t">;</code></div>
+ <ol class="proc">
+ <li>Return <a href="#sec-completion-record-specification-type">Completion</a>{[[type]]: <span style="font-family:
+ sans-serif">return</span>, [[value]]: <b>undefined</b>, [[target]]: <span style="font-family:
+ sans-serif">empty</span>}.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ReturnStatement</span> <span class="geq">:</span> <code class="t">return</code> <span class="nt">Expression</span> <code class="t">;</code></div>
+ <ol class="proc">
+ <li>Let <i>exprRef</i> be the result of evaluating <i>Expression</i>.</li>
+ <li>Let <i>exprValue</i> be <a href="#sec-getvalue">GetValue</a>(<i>exprRef</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>exprValue</i>).</li>
+ <li>Return <a href="#sec-completion-record-specification-type">Completion</a>{[[type]]: <span style="font-family:
+ sans-serif">return</span>, [[value]]: <i>exprValue</i>, [[target]]: <span style="font-family:
+ sans-serif">empty</span>}.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-with-statement">
+ <div class="front">
+ <h1><span class="secnum" id="sec-13.10"><a href="#sec-with-statement" title="link to this section">13.10</a></span> The
+ <code>with</code> Statement</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">WithStatement</span><sub>[Yield, Return]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">with</code> <code class="t">(</code> <span class="nt">Expression</span><sub>[In, ?Yield]</sub> <code class="t">)</code> <span class="nt">Statement</span><sub>[?Yield, ?Return]</sub></div>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>with</code> statement adds an <a href="#sec-object-environment-records">object
+ environment record</a> for a computed object to the <a href="#sec-lexical-environments">lexical environment</a> of <a
+ href="#sec-execution-contexts">the running execution context</a>. It then executes a statement using this augmented <a
+ href="#sec-lexical-environments">lexical environment</a>. Finally, it restores the original <a
+ href="#sec-lexical-environments">lexical environment</a>.</p>
+ </div>
+ </div>
+
+ <section id="sec-with-statement-static-semantics-early-errors">
+ <h1><span class="secnum" id="sec-13.10.1"><a href="#sec-with-statement-static-semantics-early-errors"
+ title="link to this section">13.10.1</a></span> Static Semantics: Early Errors</h1>
+ <div class="gp prod"><span class="nt">WithStatement</span> <span class="geq">:</span> <code class="t">with</code> <code class="t">(</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <ul>
+ <li>
+ <p>It is a Syntax Error if the code that matches this production is contained in <a href="#sec-strict-mode-code">strict
+ code</a>.</p>
+ </li>
+ </ul>
+ </section>
+
+ <section id="sec-with-statement-static-semantics-vardeclarednames">
+ <h1><span class="secnum" id="sec-13.10.2"><a href="#sec-with-statement-static-semantics-vardeclarednames"
+ title="link to this section">13.10.2</a></span> Static Semantics: VarDeclaredNames</h1>
+
+ <p>See also: <a href="#sec-statement-semantics-static-semantics-vardeclarednames">13.0.1</a>, <a
+ href="#sec-block-static-semantics-vardeclarednames">13.1.8</a>, <a
+ href="#sec-variable-statement-static-semantics-vardeclarednames">13.2.2.2</a>, <a
+ href="#sec-if-statement-static-semantics-vardeclarednames">13.5.1</a>, <a
+ href="#sec-do-while-statement-static-semantics-vardeclarednames">13.6.1.1</a>, <a
+ href="#sec-while-statement-static-semantics-vardeclarednames">13.6.2.1</a>, <a
+ href="#sec-for-statement-static-semantics-vardeclarednames">13.6.3.1</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-vardeclarednames">13.6.4.3</a>, <a
+ href="#sec-switch-statement-static-semantics-vardeclarednames">13.11.4</a>, <a
+ href="#sec-static-semantics-currentlabelset">13.12.2</a>, <a
+ href="#sec-try-statement-static-semantics-vardeclarednames">13.14.2</a>, <a
+ href="#sec-function-definitions-static-semantics-referencessuper">14.1.16</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-vardeclarednames">14.4.12</a>, <a
+ href="#sec-class-definitions-static-semantics-vardeclarednames">14.5.15</a>, <a
+ href="#sec-scripts-static-semantics-vardeclarednames">15.1.5</a>, <a
+ href="#sec-module-static-semantics-static-semantics-vardeclarednames">15.2.0.13</a>.</p>
+
+ <div class="gp prod"><span class="nt">WithStatement</span> <span class="geq">:</span> <code class="t">with</code> <code class="t">(</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Return the VarDeclaredNames of <i>Statement</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-with-statement-static-semantics-varscopeddeclarations">
+ <h1><span class="secnum" id="sec-13.10.3"><a href="#sec-with-statement-static-semantics-varscopeddeclarations"
+ title="link to this section">13.10.3</a></span> Static Semantics: VarScopedDeclarations</h1>
+
+ <p>See also: <a href="#sec-statement-semantics-static-semantics-varscopeddeclarations">13.0.2</a>, <a
+ href="#sec-block-static-semantics-varscopeddeclarations">13.1.9</a>, <a
+ href="#sec-variable-statement-static-semantics-varscopeddeclarations">13.2.2.3</a>, <a
+ href="#sec-if-statement-static-semantics-varscopeddeclarations">13.5.2</a>, <a
+ href="#sec-do-while-statement-static-semantics-varscopeddeclarations">13.6.1.2</a>, <a
+ href="#sec-while-statement-static-semantics-varscopeddeclarations">13.6.2.2</a>, <a
+ href="#sec-for-statement-static-semantics-varscopeddeclarations">13.6.3.2</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-varscopeddeclarations">13.6.4.4</a>, <a
+ href="#sec-switch-statement-static-semantics-varscopeddeclarations">13.11.5</a>, <a
+ href="#sec-labelled-statements-static-semantics-varscopeddeclarations">13.12.4</a>, <a
+ href="#sec-try-statement-static-semantics-varscopeddeclarations">13.14.3</a>, <a
+ href="#sec-function-definitions-static-semantics-varscopeddeclarations">14.1.18</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-varscopeddeclarations">14.2.14</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-varscopeddeclarations">14.4.13</a>, <a
+ href="#sec-scripts-static-semantics-varscopeddeclarations">15.1.6</a>, <a
+ href="#sec-module-static-semantics-static-semantics-varscopeddeclarations">15.2.0.14</a>.</p>
+
+ <div class="gp prod"><span class="nt">WithStatement</span> <span class="geq">:</span> <code class="t">with</code> <code class="t">(</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Return the VarScopedDeclarations of <i>Statement</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-with-statement-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-13.10.4"><a href="#sec-with-statement-runtime-semantics-evaluation"
+ title="link to this section">13.10.4</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">WithStatement</span> <span class="geq">:</span> <code class="t">with</code> <code class="t">(</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Let <i>val</i> be the result of evaluating <i>Expression</i>.</li>
+ <li>Let <i>obj</i> be <a href="#sec-toobject">ToObject</a>(<a href="#sec-getvalue">GetValue</a>(<i>val</i>)).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>obj</i>).</li>
+ <li>Let <i>oldEnv</i> be <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-execution-contexts">LexicalEnvironment</a>.</li>
+ <li>Let <i>newEnv</i> be <a href="#sec-newobjectenvironment">NewObjectEnvironment</a>(<i>obj</i>, <i>oldEnv</i>).</li>
+ <li>Set the <i>withEnvironment</i> flag of <i>newEnv’s</i> environment record to <b>true</b>.</li>
+ <li>Set <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-execution-contexts">LexicalEnvironment</a> to <i>newEnv</i>.</li>
+ <li>Let <i>C</i> be the result of evaluating <i>Statement</i>.</li>
+ <li>Set <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-lexical-environments">Lexical Environment</a> to <i>oldEnv</i>.</li>
+ <li>Return <i>C</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> No matter how control leaves the embedded <i>Statement</i>, whether normally or by some
+ form of <a href="#sec-completion-record-specification-type">abrupt completion</a> or exception, the <a
+ href="#sec-execution-contexts">LexicalEnvironment</a> is always restored to its former state.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-switch-statement">
+ <div class="front">
+ <h1><span class="secnum" id="sec-13.11"><a href="#sec-switch-statement" title="link to this section">13.11</a></span> The
+ <code>switch</code> Statement</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">SwitchStatement</span><sub>[Yield, Return]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">switch</code> <code class="t">(</code> <span class="nt">Expression</span><sub>[In, ?Yield]</sub> <code class="t">)</code> <span class="nt">CaseBlock</span><sub>[?Yield, ?Return]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">CaseBlock</span><sub>[Yield, Return]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">{</code> <span class="nt">CaseClauses</span><sub>[?Yield, ?Return]</sub><sub>opt</sub> <code class="t">}</code></div>
+ <div class="rhs"><code class="t">{</code> <span class="nt">CaseClauses</span><sub>[?Yield, ?Return]</sub><sub>opt</sub> <span class="nt">DefaultClause</span><sub>[?Yield, ?Return]</sub> <span class="nt">CaseClauses</span><sub>[?Yield, ?Return]</sub><sub>opt</sub> <code class="t">}</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">CaseClauses</span><sub>[Yield, Return]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">CaseClause</span><sub>[?Yield, ?Return]</sub></div>
+ <div class="rhs"><span class="nt">CaseClauses</span><sub>[?Yield, ?Return]</sub> <span class="nt">CaseClause</span><sub>[?Yield, ?Return]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">CaseClause</span><sub>[Yield, Return]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">case</code> <span class="nt">Expression</span><sub>[In, ?Yield]</sub> <code class="t">:</code> <span class="nt">StatementList</span><sub>[?Yield, ?Return]</sub><sub>opt</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">DefaultClause</span><sub>[Yield, Return]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">default</code> <code class="t">:</code> <span class="nt">StatementList</span><sub>[?Yield, ?Return]</sub><sub>opt</sub></div>
+ </div>
+ </div>
+
+ <section id="sec-switch-statement-static-semantics-early-errors">
+ <h1><span class="secnum" id="sec-13.11.1"><a href="#sec-switch-statement-static-semantics-early-errors"
+ title="link to this section">13.11.1</a></span> Static Semantics: Early Errors</h1>
+ <div class="gp prod"><span class="nt">CaseBlock</span> <span class="geq">:</span> <code class="t">{</code> <span class="nt">CaseClauses</span> <code class="t">}</code></div>
+ <ul>
+ <li>
+ <p>It is a Syntax Error if the LexicallyDeclaredNames of <span class="nt">CaseClauses</span> contains any duplicate
+ entries.</p>
+ </li>
+
+ <li>
+ <p>It is a Syntax Error if any element of the LexicallyDeclaredNames of <span class="nt">CaseClauses</span> also occurs
+ in the VarDeclaredNames of <span class="nt">CaseClauses</span>.</p>
+ </li>
+ </ul>
+ </section>
+
+ <section id="sec-switch-statement-static-semantics-lexicallyscopeddeclarations">
+ <h1><span class="secnum" id="sec-13.11.2"><a href="#sec-switch-statement-static-semantics-lexicallyscopeddeclarations"
+ title="link to this section">13.11.2</a></span> Static Semantics: LexicallyScopedDeclarations</h1>
+
+ <p>See also: <a href="#sec-block-static-semantics-lexicallyscopeddeclarations">13.1.2</a>, <a
+ href="#sec-module-static-semantics-static-semantics-lexicallyscopeddeclarations">15.2.0.11</a>.</p>
+
+ <div class="gp prod"><span class="nt">CaseBlock</span> <span class="geq">:</span> <code class="t">{</code> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">CaseBlock</span> <span class="geq">:</span> <code class="t">{</code> <span class="nt">CaseClauses</span><sub>opt</sub> <span class="nt">DefaultClause</span> <span class="nt">CaseClauses</span><sub>opt</sub> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>If the first <i>CaseClauses</i> is present, let <i>declarations</i> be the LexicallyScopedDeclarations of the first
+ <i>CaseClauses</i>.</li>
+ <li>Else let <i>declarations</i> be a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Append to <i>declarations</i> the elements of the LexicallyScopedDeclarations of the <i>DefaultClause.</i></li>
+ <li>If the second <i>CaseClauses</i> is not present, return <i>declarations</i>.</li>
+ <li>Else return the result of appending to <i>declarations</i> the elements of the LexicallyScopedDeclarations of the
+ second <i>CaseClauses</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">CaseClauses</span> <span class="geq">:</span> <span class="nt">CaseClauses</span> <span class="nt">CaseClause</span></div>
+ <ol class="proc">
+ <li>Let <i>declarations</i> be LexicallyScopedDeclarations of <i>CaseClauses</i>.</li>
+ <li>Append to <i>declarations</i> the elements of the LexicallyScopedDeclarations of <i>CaseClause.</i></li>
+ <li>Return <i>declarations</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">CaseClause</span> <span class="geq">:</span> <code class="t">case</code> <span class="nt">Expression</span> <code class="t">:</code> <span class="nt">StatementList</span><sub>opt</sub></div>
+ <ol class="proc">
+ <li>If the <i>StatementList</i> is present, return the LexicallyScopedDeclarations of <i>StatementList</i>.</li>
+ <li>Else return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">DefaultClause</span> <span class="geq">:</span> <code class="t">default</code> <code class="t">:</code> <span class="nt">StatementList</span><sub>opt</sub></div>
+ <ol class="proc">
+ <li>If the <i>StatementList</i> is present, return the LexicallyScopedDeclarations of <i>StatementList</i>.</li>
+ <li>Else return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-switch-statement-static-semantics-lexicallydeclarednames">
+ <h1><span class="secnum" id="sec-13.11.3"><a href="#sec-switch-statement-static-semantics-lexicallydeclarednames"
+ title="link to this section">13.11.3</a></span> Static Semantics: LexicallyDeclaredNames</h1>
+
+ <p>See also: <a href="#sec-block-static-semantics-lexicallydeclarednames">13.1.3</a>, <a
+ href="#sec-function-definitions-static-semantics-lexicallyscopeddeclarations">14.1.14</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-lexicallyscopeddeclarations">14.2.10</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-isfunctiondefinition">14.4.8</a>, <a
+ href="#sec-class-definitions-static-semantics-lexicallydeclarednames">14.5.10</a>, <a
+ href="#sec-scripts-static-semantics-lexicallydeclarednames">15.1.3</a>, <a
+ href="#sec-module-static-semantics-static-semantics-lexicallydeclarednames">15.2.0.10</a>.</p>
+
+ <div class="gp prod"><span class="nt">CaseBlock</span> <span class="geq">:</span> <code class="t">{</code> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">CaseBlock</span> <span class="geq">:</span> <code class="t">{</code> <span class="nt">CaseClauses</span><sub>opt</sub> <span class="nt">DefaultClause</span> <span class="nt">CaseClauses</span><sub>opt</sub> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>If the first <i>CaseClauses</i> is present, let <i>names</i> be the LexicallyDeclaredNames of the first
+ <i>CaseClauses</i>.</li>
+ <li>Else let <i>names</i> be a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Append to <i>names</i> the elements of the LexicallyDeclaredNames of the <i>DefaultClause.</i></li>
+ <li>If the second <i>CaseClauses</i> is not present, return <i>names</i>.</li>
+ <li>Else return the result of appending to <i>names</i> the elements of the LexicallyDeclaredNames of the second
+ <i>CaseClauses</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">CaseClauses</span> <span class="geq">:</span> <span class="nt">CaseClauses</span> <span class="nt">CaseClause</span></div>
+ <ol class="proc">
+ <li>Let <i>names</i> be LexicallyDeclaredNames of <i>CaseClauses</i>.</li>
+ <li>Append to <i>names</i> the elements of the LexicallyDeclaredNames of <i>CaseClause.</i></li>
+ <li>Return <i>names</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">CaseClause</span> <span class="geq">:</span> <code class="t">case</code> <span class="nt">Expression</span> <code class="t">:</code> <span class="nt">StatementList</span><sub>opt</sub></div>
+ <ol class="proc">
+ <li>If the <i>StatementList</i> is present, return the LexicallyDeclaredNames of <i>StatementList</i>.</li>
+ <li>Else return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">DefaultClause</span> <span class="geq">:</span> <code class="t">default</code> <code class="t">:</code> <span class="nt">StatementList</span><sub>opt</sub></div>
+ <ol class="proc">
+ <li>If the <i>StatementList</i> is present, return the LexicallyDeclaredNames of <i>StatementList</i>.</li>
+ <li>Else return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-switch-statement-static-semantics-vardeclarednames">
+ <h1><span class="secnum" id="sec-13.11.4"><a href="#sec-switch-statement-static-semantics-vardeclarednames"
+ title="link to this section">13.11.4</a></span> Static Semantics: VarDeclaredNames</h1>
+
+ <p>See also: <a href="#sec-statement-semantics-static-semantics-vardeclarednames">13.0.1</a>, <a
+ href="#sec-block-static-semantics-vardeclarednames">13.1.8</a>, <a
+ href="#sec-variable-statement-static-semantics-vardeclarednames">13.2.2.2</a>, <a
+ href="#sec-if-statement-static-semantics-vardeclarednames">13.5.1</a>, <a
+ href="#sec-do-while-statement-static-semantics-vardeclarednames">13.6.1.1</a>, <a
+ href="#sec-while-statement-static-semantics-vardeclarednames">13.6.2.1</a>, <a
+ href="#sec-for-statement-static-semantics-vardeclarednames">13.6.3.1</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-vardeclarednames">13.6.4.3</a>, <a
+ href="#sec-with-statement-static-semantics-vardeclarednames">13.10.2</a>, <a
+ href="#sec-static-semantics-currentlabelset">13.12.2</a>, <a
+ href="#sec-try-statement-static-semantics-vardeclarednames">13.14.2</a>, <a
+ href="#sec-function-definitions-static-semantics-referencessuper">14.1.16</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-vardeclarednames">14.4.12</a>, <a
+ href="#sec-class-definitions-static-semantics-vardeclarednames">14.5.15</a>, <a
+ href="#sec-scripts-static-semantics-vardeclarednames">15.1.5</a>, <a
+ href="#sec-module-static-semantics-static-semantics-vardeclarednames">15.2.0.13</a>.</p>
+
+ <div class="gp prod"><span class="nt">SwitchStatement</span> <span class="geq">:</span> <code class="t">switch</code> <code class="t">(</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">CaseBlock</span></div>
+ <ol class="proc">
+ <li>Return the VarDeclaredNames of <i>CaseBlock</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">CaseBlock</span> <span class="geq">:</span> <code class="t">{</code> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">CaseBlock</span> <span class="geq">:</span> <code class="t">{</code> <span class="nt">CaseClauses</span><sub>opt</sub> <span class="nt">DefaultClause</span> <span class="nt">CaseClauses</span><sub>opt</sub> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>If the first <i>CaseClauses</i> is present, let <i>names</i> be the VarDeclaredNames of the first
+ <i>CaseClauses</i>.</li>
+ <li>Else let <i>names</i> be a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Append to <i>names</i> the elements of the VarDeclaredNames of the <i>DefaultClause.</i></li>
+ <li>If the second <i>CaseClauses</i> is not present, return <i>names</i>.</li>
+ <li>Else return the result of appending to <i>names</i> the elements of the VarDeclaredNames of the second
+ <i>CaseClauses</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">CaseClauses</span> <span class="geq">:</span> <span class="nt">CaseClauses</span> <span class="nt">CaseClause</span></div>
+ <ol class="proc">
+ <li>Let <i>names</i> be VarDeclaredNames of <i>CaseClauses</i>.</li>
+ <li>Append to <i>names</i> the elements of the VarDeclaredNames of <i>CaseClause.</i></li>
+ <li>Return <i>names</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">CaseClause</span> <span class="geq">:</span> <code class="t">case</code> <span class="nt">Expression</span> <code class="t">:</code> <span class="nt">StatementList</span><sub>opt</sub></div>
+ <ol class="proc">
+ <li>If the <i>StatementList</i> is present, return the VarDeclaredNames of <i>StatementList</i>.</li>
+ <li>Else return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">DefaultClause</span> <span class="geq">:</span> <code class="t">default</code> <code class="t">:</code> <span class="nt">StatementList</span><sub>opt</sub></div>
+ <ol class="proc">
+ <li>If the <i>StatementList</i> is present, return the VarDeclaredNames of <i>StatementList</i>.</li>
+ <li>Else return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-switch-statement-static-semantics-varscopeddeclarations">
+ <h1><span class="secnum" id="sec-13.11.5"><a href="#sec-switch-statement-static-semantics-varscopeddeclarations"
+ title="link to this section">13.11.5</a></span> Static Semantics: VarScopedDeclarations</h1>
+
+ <p>See also: <a href="#sec-statement-semantics-static-semantics-varscopeddeclarations">13.0.2</a>, <a
+ href="#sec-block-static-semantics-varscopeddeclarations">13.1.9</a>, <a
+ href="#sec-variable-statement-static-semantics-varscopeddeclarations">13.2.2.3</a>, <a
+ href="#sec-if-statement-static-semantics-varscopeddeclarations">13.5.2</a>, <a
+ href="#sec-do-while-statement-static-semantics-varscopeddeclarations">13.6.1.2</a>, <a
+ href="#sec-while-statement-static-semantics-varscopeddeclarations">13.6.2.2</a>, <a
+ href="#sec-for-statement-static-semantics-varscopeddeclarations">13.6.3.2</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-varscopeddeclarations">13.6.4.4</a>, <a
+ href="#sec-with-statement-static-semantics-varscopeddeclarations">13.10.3</a>, <a
+ href="#sec-labelled-statements-static-semantics-varscopeddeclarations">13.12.4</a>, <a
+ href="#sec-try-statement-static-semantics-varscopeddeclarations">13.14.3</a>, <a
+ href="#sec-function-definitions-static-semantics-varscopeddeclarations">14.1.18</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-varscopeddeclarations">14.2.14</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-varscopeddeclarations">14.4.13</a>, <a
+ href="#sec-scripts-static-semantics-varscopeddeclarations">15.1.6</a>, <a
+ href="#sec-module-static-semantics-static-semantics-varscopeddeclarations">15.2.0.14</a>.</p>
+
+ <div class="gp prod"><span class="nt">SwitchStatement</span> <span class="geq">:</span> <code class="t">switch</code> <code class="t">(</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">CaseBlock</span></div>
+ <ol class="proc">
+ <li>Return the VarScopedDeclarations of <i>CaseBlock</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">CaseBlock</span> <span class="geq">:</span> <code class="t">{</code> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">CaseBlock</span> <span class="geq">:</span> <code class="t">{</code> <span class="nt">CaseClauses</span><sub>opt</sub> <span class="nt">DefaultClause</span> <span class="nt">CaseClauses</span><sub>opt</sub> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>If the first <i>CaseClauses</i> is present, let <i>declarations</i> be the VarScopedDeclarations of the first
+ <i>CaseClauses</i>.</li>
+ <li>Else let <i>declarations</i> be a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Append to <i>declarations</i> the elements of the VarScopedDeclarations of the <i>DefaultClause.</i></li>
+ <li>If the second <i>CaseClauses</i> is not present, return <i>declarations</i>.</li>
+ <li>Else return the result of appending to <i>declarations</i> the elements of the VarScopedDeclarations of the second
+ <i>CaseClauses</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">CaseClauses</span> <span class="geq">:</span> <span class="nt">CaseClauses</span> <span class="nt">CaseClause</span></div>
+ <ol class="proc">
+ <li>Let <i>declarations</i> be VarScopedDeclarations of <i>CaseClauses</i>.</li>
+ <li>Append to <i>declarations</i> the elements of the VarScopedDeclarations of <i>CaseClause.</i></li>
+ <li>Return <i>declarations</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">CaseClause</span> <span class="geq">:</span> <code class="t">case</code> <span class="nt">Expression</span> <code class="t">:</code> <span class="nt">StatementList</span><sub>opt</sub></div>
+ <ol class="proc">
+ <li>If the <i>StatementList</i> is present, return the VarScopedDeclarations of <i>StatementList</i>.</li>
+ <li>Else return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">DefaultClause</span> <span class="geq">:</span> <code class="t">default</code> <code class="t">:</code> <span class="nt">StatementList</span><sub>opt</sub></div>
+ <ol class="proc">
+ <li>If the <i>StatementList</i> is present, return the VarScopedDeclarations of <i>StatementList</i>.</li>
+ <li>Else return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-runtime-semantics-caseblockevaluation">
+ <h1><span class="secnum" id="sec-13.11.6"><a href="#sec-runtime-semantics-caseblockevaluation"
+ title="link to this section">13.11.6</a></span> Runtime Semantics: CaseBlockEvaluation</h1>
+
+ <p>With argument <var>input</var>.</p>
+
+ <div class="gp prod"><span class="nt">CaseBlock</span> <span class="geq">:</span> <code class="t">{</code> <span class="nt">CaseClauses</span><sub>opt</sub> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Let <i>V</i> = <b>undefined</b>.</li>
+ <li>Let <i>A</i> be the list of <i>CaseClause</i> items in source text order.</li>
+ <li>Let <i>searching</i> be <b>true</b>.</li>
+ <li>Repeat, for each <i>CaseClause</i>, <i>C</i>, in <i>A</i>
+ <ol class="block">
+ <li>If <i>searching</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>clauseSelector</i> be the result of CaseSelectorEvaluation of <i>C</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>clauseSelector</i>).</li>
+ <li>Let <i>matched</i> be the result of performing Strict Equality Comparison <i>input</i> ===
+ <i>clauseSelector</i>.</li>
+ <li>If <i>matched</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Set <i>searching</i> to <b>false</b>.</li>
+ <li>If <i>C</i> has a <i>StatementList</i>, then
+ <ol class="block">
+ <li>Let <i>V</i> be the result of evaluating <i>C</i>’s <i>StatementList</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>V</i>).</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Else <i>searching</i> is <b>false</b>,
+ <ol class="block">
+ <li>If <i>C</i> has a <i>StatementList</i>, then
+ <ol class="block">
+ <li>Let <i>R</i> be the result of evaluating <i>C</i>’s <i>StatementList</i>.</li>
+ <li>If <i>R</i>.[[value]] is not <span style="font-family: sans-serif">empty</span>, then let <i>V</i> =
+ <i>R</i>.[[value]].</li>
+ <li>If <i>R</i> is an <a href="#sec-completion-record-specification-type">abrupt completion</a>, then return
+ <a href="#sec-completion-record-specification-type">Completion</a>{[[type]]: <i>R</i>.[[type]], [[value]]:
+ <i>V</i>, [[target]]: <i>R</i>.[[target]]}.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<i>V</i>).</li>
+ </ol>
+ <div class="gp prod"><span class="nt">CaseBlock</span> <span class="geq">:</span> <code class="t">{</code> <span class="nt">CaseClauses</span><sub>opt</sub> <span class="nt">DefaultClause</span> <span class="nt">CaseClauses</span><sub>opt</sub> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Let <i>V</i> = <b>undefined</b>.</li>
+ <li>Let <i>A</i> be the list of <i>CaseClause</i> items in the first <i>CaseClauses</i>, in source text order.</li>
+ <li>Let <i>found</i> be <b>false</b>.</li>
+ <li>Repeat letting <i>C</i> be in order each <i>CaseClause</i> in <i>A</i>
+ <ol class="block">
+ <li>If <i>found</i> is <b>false</b>, then
+ <ol class="block">
+ <li>Let <i>clauseSelector</i> be the result of CaseSelectorEvaluation of <i>C</i>.</li>
+ <li>If <i>clauseSelector</i> is an <a href="#sec-completion-record-specification-type">abrupt completion</a>, then
+ <ol class="block">
+ <li>If <i>clauseSelector</i>.[[value]] is <span style="font-family: sans-serif">empty</span>, then return <a
+ href="#sec-completion-record-specification-type">Completion</a>{[[type]]: <i>clauseSelector</i>.[[type]],
+ [[value]]: <b>undefined</b>, [[target]]: <i>clauseSelector</i>.[[target]]}.</li>
+ <li>Else, return <i>clauseSelector</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>found</i> be the result of performing Strict Equality Comparison <i>input</i> ===
+ <i>clauseSelector</i>.</li>
+ </ol>
+ </li>
+ <li>If <i>found</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>R</i> be the result of evaluating <i>CaseClause</i> <i>C</i>.</li>
+ <li>If <i>R</i>.[[value]] is not <span style="font-family: sans-serif">empty</span>, then let <i>V</i> =
+ <i>R</i>.[[value]].</li>
+ <li>If <i>R</i> is an <a href="#sec-completion-record-specification-type">abrupt completion</a>, then return <a
+ href="#sec-completion-record-specification-type">Completion</a>{[[type]]: <i>R</i>.[[type]], [[value]]:
+ <i>V</i>, [[target]]: <i>R</i>.[[target]]}.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Let <i>foundInB</i> be <b>false</b>.</li>
+ <li>If <i>found</i> is <b>false</b>, then
+ <ol class="block">
+ <li>Let <i>B</i> be a new <a href="#sec-list-and-record-specification-type">List</a> containing the <i>CaseClause</i>
+ items in the second <i>CaseClauses</i>, in source text order.</li>
+ <li>Repeat, letting <i>C</i> be in order each <i>CaseClause</i> in <i>B</i>
+ <ol class="block">
+ <li>If <i>foundInB</i> is <b>false</b>, then
+ <ol class="block">
+ <li>Let <i>clauseSelector</i> be the result of CaseSelectorEvaluation of <i>C</i>.</li>
+ <li>If <i>clauseSelector</i> is an <a href="#sec-completion-record-specification-type">abrupt completion</a>,
+ then
+ <ol class="block">
+ <li>If <i>clauseSelector</i>.[[value]] is <span style="font-family: sans-serif">empty</span>, then return
+ <a href="#sec-completion-record-specification-type">Completion</a>{[[type]]:
+ <i>clauseSelector</i>.[[type]], [[value]]: <b>undefined</b>, [[target]]:
+ <i>clauseSelector</i>.[[target]]}.</li>
+ <li>Else, return <i>clauseSelector</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>foundInB</i> be the result of performing Strict Equality Comparison <i>input</i> ===
+ <i>clauseSelector</i>.</li>
+ </ol>
+ </li>
+ <li>If <i>foundInB</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>R</i> be the result of evaluating <i>CaseClause C</i>.</li>
+ <li>If <i>R</i>.[[value]] is not <span style="font-family: sans-serif">empty</span>, then let <i>V</i> =
+ <i>R</i>.[[value]].</li>
+ <li>If <i>R</i> is an <a href="#sec-completion-record-specification-type">abrupt completion</a>, then return
+ <a href="#sec-completion-record-specification-type">Completion</a>{[[type]]: <i>R</i>.[[type]], [[value]]:
+ <i>V</i>, [[target]]: <i>R</i>.[[target]]}.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>If <i>foundInB</i> is <b>true</b>, then return <a href="#sec-normalcompletion">NormalCompletion</a>(<i>V</i>).</li>
+ <li>Let <i>R</i> be the result of evaluating <i>DefaultClause</i>.</li>
+ <li>If <i>R</i>.[[value]] is not <span style="font-family: sans-serif">empty</span>, then let <i>V</i> =
+ <i>R</i>.[[value]].</li>
+ <li>If <i>R</i> is an <a href="#sec-completion-record-specification-type">abrupt completion</a>, then return <a
+ href="#sec-completion-record-specification-type">Completion</a>{[[type]]: <i>R</i>.[[type]], [[value]]: <i>V</i>,
+ [[target]]: <i>R</i>.[[target]]}.</li>
+ <li>Let <i>B</i> be a new <a href="#sec-list-and-record-specification-type">List</a> containing the <i>CaseClause</i>
+ items in the second <i>CaseClauses</i>, in source text order.</li>
+ <li>Repeat, letting <i>C</i> be in order each <i>CaseClause</i> in <i>B</i> (NOTE this is another complete iteration of
+ the second <i>CaseClauses</i>)
+ <ol class="block">
+ <li>Let <i>R</i> be the result of evaluating <i>CaseClause</i> <i>C</i>.</li>
+ <li>If <i>R</i>.[[value]] is not <span style="font-family: sans-serif">empty</span>, then let <i>V</i> =
+ <i>R</i>.[[value]].</li>
+ <li>If <i>R</i> is an <a href="#sec-completion-record-specification-type">abrupt completion</a>, then return <a
+ href="#sec-completion-record-specification-type">Completion</a>{[[type]]: <i>R</i>.[[type]], [[value]]: <i>V</i>,
+ [[target]]: <i>R</i>.[[target]]}.</li>
+ </ol>
+ </li>
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<i>V</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-runtime-semantics-caseselectorevaluation">
+ <h1><span class="secnum" id="sec-13.11.7"><a href="#sec-runtime-semantics-caseselectorevaluation"
+ title="link to this section">13.11.7</a></span> Runtime Semantics: CaseSelectorEvaluation</h1>
+ <div class="gp prod"><span class="nt">CaseClause</span> <span class="geq">:</span> <code class="t">case</code> <span class="nt">Expression</span> <code class="t">:</code> <span class="nt">StatementList</span><sub>opt</sub></div>
+ <ol class="proc">
+ <li>Let <i>exprRef</i> be the result of evaluating <i>Expression</i>.</li>
+ <li>Return <a href="#sec-getvalue">GetValue</a>(<i>exprRef</i>).</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> CaseSelectorEvaluation does not execute the associated <i>StatementList</i>. It simply
+ evaluates the <i>Expression</i> and returns the value, which the <i>CaseBlock</i> algorithm uses to determine which
+ <i>StatementList</i> to start executing.</p>
+ </div>
+ </section>
+
+ <section id="sec-switch-statement-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-13.11.8"><a href="#sec-switch-statement-runtime-semantics-evaluation"
+ title="link to this section">13.11.8</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">SwitchStatement</span> <span class="geq">:</span> <code class="t">switch</code> <code class="t">(</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">CaseBlock</span></div>
+ <ol class="proc">
+ <li>Let <i>exprRef</i> be the result of evaluating <i>Expression</i>.</li>
+ <li>Let <i>switchValue</i> be <a href="#sec-getvalue">GetValue</a>(<i>exprRef</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>switchValue</i>).</li>
+ <li>Let <i>oldEnv</i> be <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-execution-contexts">LexicalEnvironment</a>.</li>
+ <li>Let <i>blockEnv</i> be <a href="#sec-newdeclarativeenvironment">NewDeclarativeEnvironment</a>(<i>oldEnv</i>).</li>
+ <li>Perform <a href="#sec-blockdeclarationinstantiation">BlockDeclarationInstantiation</a>(<i>CaseBlock,</i>
+ <i>blockEnv</i>).</li>
+ <li>Let <i>R</i> be the result of performing CaseBlockEvaluation of <i>CaseBlock</i> with argument
+ <i>switchValue</i>.</li>
+ <li>Set <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-execution-contexts">LexicalEnvironment</a> to <i>oldEnv</i>.</li>
+ <li>Return <i>R</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> No matter how control leaves the <i>SwitchStatement</i> the <a
+ href="#sec-execution-contexts">LexicalEnvironment</a> is always restored to its former state.</p>
+ </div>
+
+ <div class="gp prod"><span class="nt">CaseClause</span> <span class="geq">:</span> <code class="t">case</code> <span class="nt">Expression</span> <code class="t">:</code></div>
+ <ol class="proc">
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<span style="font-family: sans-serif">empty</span>).</li>
+ </ol>
+ <div class="gp prod"><span class="nt">CaseClause</span> <span class="geq">:</span> <code class="t">case</code> <span class="nt">Expression</span> <code class="t">:</code> <span class="nt">StatementList</span></div>
+ <ol class="proc">
+ <li>Return the result of evaluating <i>StatementList</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">DefaultClause</span> <span class="geq">:</span> <code class="t">default</code> <code class="t">:</code></div>
+ <ol class="proc">
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<span style="font-family: sans-serif">empty</span>).</li>
+ </ol>
+ <div class="gp prod"><span class="nt">DefaultClause</span> <span class="geq">:</span> <code class="t">default</code> <code class="t">:</code> <span class="nt">StatementList</span></div>
+ <ol class="proc">
+ <li>Return the result of evaluating <i>StatementList</i>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-labelled-statements">
+ <div class="front">
+ <h1><span class="secnum" id="sec-13.12"><a href="#sec-labelled-statements" title="link to this section">13.12</a></span>
+ Labelled Statements</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">LabelledStatement</span><sub>[Yield, Return]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">LabelIdentifier</span><sub>[?Yield]</sub> <code class="t">:</code> <span class="nt">Statement</span><sub>[?Yield, ?Return]</sub></div>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> A <span class="nt">Statement</span> may be prefixed by a label. Labelled statements are
+ only used in conjunction with labelled <code>break</code> and <code>continue</code> statements. ECMAScript has no
+ <code>goto</code> statement. A <span class="nt">Statement</span> can be part of a <span
+ class="nt">LabelledStatement</span>, which itself can be part of a <span class="nt">LabelledStatement</span>, and so on.
+ The labels introduced this way are collectively referred to as the “current label set” when describing the
+ semantics of individual statements. A <span class="nt">LabelledStatement</span> has no semantic meaning other than the
+ introduction of a label to a <i>label set</i>.</p>
+ </div>
+ </div>
+
+ <section id="sec-labelled-statements-static-semantics-early-errors">
+ <h1><span class="secnum" id="sec-13.12.1"><a href="#sec-labelled-statements-static-semantics-early-errors"
+ title="link to this section">13.12.1</a></span> Static Semantics: Early Errors</h1>
+ <div class="gp prod"><span class="nt">LabelledStatement</span> <span class="geq">:</span> <span class="nt">LabelIdentifier</span> <code class="t">:</code> <span class="nt">Statement</span></div>
+ <ul>
+ <li>
+ <p>It is a Syntax Error if the immediately enclosing CurrentLabelSet contains the StringValue of <span
+ class="nt">LabelIdentifier</span>.</p>
+ </li>
+ </ul>
+ </section>
+
+ <section id="sec-static-semantics-currentlabelset">
+ <h1><span class="secnum" id="sec-13.12.2"><a href="#sec-static-semantics-currentlabelset"
+ title="link to this section">13.12.2</a></span> Static Semantics: CurrentLabelSet</h1>
+ <div class="gp prod"><span class="nt">LabelledStatement</span> <span class="geq">:</span> <span class="nt">LabelIdentifier</span> <code class="t">:</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>The CurrentLabelSet of this <i>LabelledStatement</i> is a <a href="#sec-list-and-record-specification-type">List</a>
+ that includes the StringValue of <i>LabelIdentifier</i> <i>and</i> all elements of the immediately enclosing
+ CurrentLabelSet.</li>
+ </ol>
+ </section>
+
+ <section id="sec-labelled-statements-static-semantics-vardeclarednames">
+ <h1><span class="secnum" id="sec-13.12.3"><a href="#sec-labelled-statements-static-semantics-vardeclarednames"
+ title="link to this section">13.12.3</a></span> Static Semantics: VarDeclaredNames</h1>
+
+ <p>See also: <a href="#sec-statement-semantics-static-semantics-vardeclarednames">13.0.1</a>, <a
+ href="#sec-block-static-semantics-vardeclarednames">13.1.8</a>, <a
+ href="#sec-variable-statement-static-semantics-vardeclarednames">13.2.2.2</a>, <a
+ href="#sec-if-statement-static-semantics-vardeclarednames">13.5.1</a>, <a
+ href="#sec-do-while-statement-static-semantics-vardeclarednames">13.6.1.1</a>, <a
+ href="#sec-while-statement-static-semantics-vardeclarednames">13.6.2.1</a>, <a
+ href="#sec-for-statement-static-semantics-vardeclarednames">13.6.3.1</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-vardeclarednames">13.6.4.3</a>, <a
+ href="#sec-with-statement-static-semantics-vardeclarednames">13.10.2</a>, <a
+ href="#sec-switch-statement-static-semantics-vardeclarednames">13.11.4</a>, <a
+ href="#sec-try-statement-static-semantics-vardeclarednames">13.14.2</a>, <a
+ href="#sec-function-definitions-static-semantics-referencessuper">14.1.16</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-vardeclarednames">14.4.12</a>, <a
+ href="#sec-class-definitions-static-semantics-vardeclarednames">14.5.15</a>, <a
+ href="#sec-scripts-static-semantics-vardeclarednames">15.1.5</a>, <a
+ href="#sec-module-static-semantics-static-semantics-vardeclarednames">15.2.0.13</a>.</p>
+
+ <div class="gp prod"><span class="nt">LabelledStatement</span> <span class="geq">:</span> <span class="nt">LabelIdentifier</span> <code class="t">:</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Return the VarDeclaredNames of <i>Statement</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-labelled-statements-static-semantics-varscopeddeclarations">
+ <h1><span class="secnum" id="sec-13.12.4"><a href="#sec-labelled-statements-static-semantics-varscopeddeclarations"
+ title="link to this section">13.12.4</a></span> Static Semantics: VarScopedDeclarations</h1>
+
+ <p>See also: <a href="#sec-statement-semantics-static-semantics-varscopeddeclarations">13.0.2</a>, <a
+ href="#sec-block-static-semantics-varscopeddeclarations">13.1.9</a>, <a
+ href="#sec-variable-statement-static-semantics-varscopeddeclarations">13.2.2.3</a>, <a
+ href="#sec-if-statement-static-semantics-varscopeddeclarations">13.5.2</a>, <a
+ href="#sec-do-while-statement-static-semantics-varscopeddeclarations">13.6.1.2</a>, <a
+ href="#sec-while-statement-static-semantics-varscopeddeclarations">13.6.2.2</a>, <a
+ href="#sec-for-statement-static-semantics-varscopeddeclarations">13.6.3.2</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-varscopeddeclarations">13.6.4.4</a>, <a
+ href="#sec-with-statement-static-semantics-varscopeddeclarations">13.10.3</a>, <a
+ href="#sec-switch-statement-static-semantics-varscopeddeclarations">13.11.5</a>, <a
+ href="#sec-try-statement-static-semantics-varscopeddeclarations">13.14.3</a>, <a
+ href="#sec-function-definitions-static-semantics-varscopeddeclarations">14.1.18</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-varscopeddeclarations">14.2.14</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-varscopeddeclarations">14.4.13</a>, <a
+ href="#sec-scripts-static-semantics-varscopeddeclarations">15.1.6</a>, <a
+ href="#sec-module-static-semantics-static-semantics-varscopeddeclarations">15.2.0.14</a>.</p>
+
+ <div class="gp prod"><span class="nt">LabelledStatement</span> <span class="geq">:</span> <span class="nt">LabelIdentifier</span> <code class="t">:</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Return the VarScopedDeclarations of <i>Statement</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-labelled-statements-runtime-semantics-labelledevaluation">
+ <div class="front">
+ <h1><span class="secnum" id="sec-13.12.5"><a href="#sec-labelled-statements-runtime-semantics-labelledevaluation"
+ title="link to this section">13.12.5</a></span> Runtime Semantics: LabelledEvaluation</h1>
+
+ <p>With argument <var>labelSet</var>.</p>
+
+ <p>See also: <a href="#sec-statement-semantics-static-semantics-varscopeddeclarations">13.0.2</a>, <a
+ href="#sec-do-while-statement-static-semantics-varscopeddeclarations">13.6.1.2</a>, <a
+ href="#sec-while-statement-static-semantics-varscopeddeclarations">13.6.2.2</a>, <a
+ href="#sec-for-statement-static-semantics-varscopeddeclarations">13.6.3.2</a>, <a
+ href="#sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation">13.6.4.6</a>.</p>
+
+ <div class="gp prod"><span class="nt">LabelledStatement</span> <span class="geq">:</span> <span class="nt">LabelIdentifier</span> <code class="t">:</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Let <i>label</i> be the StringValue of <i>LabelIdentifier</i>.</li>
+ <li>Return <a href="#sec-labelledstatementevaluation">LabelledStatementEvaluation</a>(<i>label</i>, <i>Statement</i>,
+ <i>labelSet</i>).</li>
+ </ol>
+ </div>
+
+ <section id="sec-labelledstatementevaluation">
+ <h1><span class="secnum" id="sec-13.12.5.1"><a href="#sec-labelledstatementevaluation"
+ title="link to this section">13.12.5.1</a></span> Runtime Semantics: LabelledStatementEvaluation(label, stmt,
+ labelSet)</h1>
+
+ <p>The abstract operation LabelledStatementEvaluation with arguments <var>label</var>, <var>stmt</var>, and
+ <var>labelSet</var> is performed as follows:</p>
+
+ <ol class="proc">
+ <li>Let <i>newLabelSet</i> be a new <a href="#sec-list-and-record-specification-type">List</a> containing <i>label</i>
+ and the elements of <i>labelSet</i>.</li>
+ <li>If <i>stmt</i> is either a <i>LabelledStatement</i> or a <i>BreakableStatement</i>, then
+ <ol class="block">
+ <li>Let <i>stmtResult</i> be the result of performing LabelledEvaluation of <i>stmt</i> with argument
+ <i>newLabelSet</i>.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>stmtResult</i> be the result of evaluating <i>stmt</i>.</li>
+ </ol>
+ </li>
+ <li>If <i>stmtResult</i>.[[type]] is <span style="font-family: sans-serif">break</span> and <a
+ href="#sec-samevalue">SameValue</a>(<i>stmtResult</i>.[[target]], <i>label</i>), then
+ <ol class="block">
+ <li>Let <i>result</i> be <a href="#sec-normalcompletion">NormalCompletion</a>(<i>stmtResult</i>.[[value]]).</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>result</i> be <i>stmtResult</i>.</li>
+ </ol>
+ </li>
+ <li>Return <i>result</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-runtime-semantics-labelledevaluation-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-13.12.5.2"><a
+ href="#sec-runtime-semantics-labelledevaluation-runtime-semantics-evaluation"
+ title="link to this section">13.12.5.2</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">LabelledStatement</span> <span class="geq">:</span> <span class="nt">LabelIdentifier</span> <code class="t">:</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Let <i>newLabelSet</i> be a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Return the result of performing LabelledEvaluation of this <i>LabelledStatement</i> with argument
+ <i>newLabelSet</i>.</li>
+ </ol>
+ </section>
+ </section>
+ </section>
+
+ <section id="sec-throw-statement">
+ <div class="front">
+ <h1><span class="secnum" id="sec-13.13"><a href="#sec-throw-statement" title="link to this section">13.13</a></span> The
+ <code>throw</code> Statement</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ThrowStatement</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">throw</code> <span class="grhsannot">[no <span class="nt">LineTerminator</span> here]</span> <span class="nt">Expression</span><sub>[In, ?Yield]</sub> <code class="t">;</code></div>
+ </div>
+ </div>
+
+ <section id="sec-throw-statement-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-13.13.1"><a href="#sec-throw-statement-runtime-semantics-evaluation"
+ title="link to this section">13.13.1</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">ThrowStatement</span> <span class="geq">:</span> <code class="t">throw</code> <span class="nt">Expression</span> <code class="t">;</code></div>
+ <ol class="proc">
+ <li>Let <i>exprRef</i> be the result of evaluating <i>Expression</i>.</li>
+ <li>Let <i>exprValue</i> be <a href="#sec-getvalue">GetValue</a>(<i>exprRef</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>exprValue</i>).</li>
+ <li>Return <a href="#sec-completion-record-specification-type">Completion</a>{[[type]]: <span style="font-family:
+ sans-serif">throw</span>, [[value]]: <i>exprValue</i>, [[target]]: <span style="font-family:
+ sans-serif">empty</span>}.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-try-statement">
+ <div class="front">
+ <h1><span class="secnum" id="sec-13.14"><a href="#sec-try-statement" title="link to this section">13.14</a></span> The
+ <code>try</code> Statement</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">TryStatement</span><sub>[Yield, Return]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">try</code> <span class="nt">Block</span><sub>[?Yield, ?Return]</sub> <span class="nt">Catch</span><sub>[?Yield, ?Return]</sub></div>
+ <div class="rhs"><code class="t">try</code> <span class="nt">Block</span><sub>[?Yield, ?Return]</sub> <span class="nt">Finally</span><sub>[?Yield, ?Return]</sub></div>
+ <div class="rhs"><code class="t">try</code> <span class="nt">Block</span><sub>[?Yield, ?Return]</sub> <span class="nt">Catch</span><sub>[?Yield, ?Return]</sub> <span class="nt">Finally</span><sub>[?Yield, ?Return]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">Catch</span><sub>[Yield, Return]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">catch</code> <code class="t">(</code> <span class="nt">CatchParameter</span><sub>[?Yield]</sub> <code class="t">)</code> <span class="nt">Block</span><sub>[?Yield, ?Return]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">Finally</span><sub>[Yield, Return]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">finally</code> <span class="nt">Block</span><sub>[?Yield, ?Return]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">CatchParameter</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">BindingIdentifier</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="nt">BindingPattern</span><sub>[?Yield]</sub></div>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>try</code> statement encloses a block of code in which an exceptional condition
+ can occur, such as a runtime error or a <code>throw</code> statement. The <code>catch</code> clause provides the
+ exception-handling code. When a catch clause catches an exception, its <i>CatchParameter</i> is bound to that
+ exception.</p>
+ </div>
+ </div>
+
+ <section id="sec-try-statement-static-semantics-early-errors">
+ <h1><span class="secnum" id="sec-13.14.1"><a href="#sec-try-statement-static-semantics-early-errors"
+ title="link to this section">13.14.1</a></span> Static Semantics: Early Errors</h1>
+ <div class="gp prod"><span class="nt">Catch</span> <span class="geq">:</span> <code class="t">catch</code> <code class="t">(</code> <span class="nt">CatchParameter</span> <code class="t">)</code> <span class="nt">Block</span></div>
+ <ul>
+ <li>
+ <p>It is a Syntax Error if any element of the BoundNames of <span class="nt">CatchParameter</span> also occurs in the
+ LexicallyDeclaredNames of <span class="nt">Block</span>.</p>
+ </li>
+
+ <li>
+ <p>It is a Syntax Error if any element of the BoundNames of <span class="nt">CatchParameter</span> also occurs in the
+ VarDeclaredNames of <span class="nt">Block</span>.</p>
+ </li>
+ </ul>
+
+ <p class="Note"><i>NOTE	An alternative static semantics for this production is given in <a
+ href="#sec-variablestatements-in-catch-blocks">B.3.3</a>.</i></p>
+ </section>
+
+ <section id="sec-try-statement-static-semantics-vardeclarednames">
+ <h1><span class="secnum" id="sec-13.14.2"><a href="#sec-try-statement-static-semantics-vardeclarednames"
+ title="link to this section">13.14.2</a></span> Static Semantics: VarDeclaredNames</h1>
+
+ <p>See also: <a href="#sec-statement-semantics-static-semantics-vardeclarednames">13.0.1</a>, <a
+ href="#sec-block-static-semantics-vardeclarednames">13.1.8</a>, <a
+ href="#sec-variable-statement-static-semantics-vardeclarednames">13.2.2.2</a>, <a
+ href="#sec-if-statement-static-semantics-vardeclarednames">13.5.1</a>, <a
+ href="#sec-do-while-statement-static-semantics-vardeclarednames">13.6.1.1</a>, <a
+ href="#sec-while-statement-static-semantics-vardeclarednames">13.6.2.1</a>, <a
+ href="#sec-for-statement-static-semantics-vardeclarednames">13.6.3.1</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-vardeclarednames">13.6.4.3</a>, <a
+ href="#sec-with-statement-static-semantics-vardeclarednames">13.10.2</a>, <a
+ href="#sec-switch-statement-static-semantics-vardeclarednames">13.11.4</a>, <a
+ href="#sec-static-semantics-currentlabelset">13.12.2</a>, <a
+ href="#sec-function-definitions-static-semantics-referencessuper">14.1.16</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-vardeclarednames">14.4.12</a>, <a
+ href="#sec-class-definitions-static-semantics-vardeclarednames">14.5.15</a>, <a
+ href="#sec-scripts-static-semantics-vardeclarednames">15.1.5</a>, <a
+ href="#sec-module-static-semantics-static-semantics-vardeclarednames">15.2.0.13</a>.</p>
+
+ <div class="gp prod"><span class="nt">TryStatement</span> <span class="geq">:</span> <code class="t">try</code> <span class="nt">Block</span> <span class="nt">Catch</span></div>
+ <ol class="proc">
+ <li>Let <i>names</i> be VarDeclaredNames of <i>Block</i>.</li>
+ <li>Append to <i>names</i> the elements of the VarDeclaredNames of <i>Catch.</i></li>
+ <li>Return <i>names</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">TryStatement</span> <span class="geq">:</span> <code class="t">try</code> <span class="nt">Block</span> <span class="nt">Finally</span></div>
+ <ol class="proc">
+ <li>Let <i>names</i> be VarDeclaredNames of <i>Block</i>.</li>
+ <li>Append to <i>names</i> the elements of the VarDeclaredNames of <i>Finally.</i></li>
+ <li>Return <i>names</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">TryStatement</span> <span class="geq">:</span> <code class="t">try</code> <span class="nt">Block</span> <span class="nt">Catch</span> <span class="nt">Finally</span></div>
+ <ol class="proc">
+ <li>Let <i>names</i> be VarDeclaredNames of <i>Block</i>.</li>
+ <li>Append to <i>names</i> the elements of the VarDeclaredNames of <i>Catch.</i></li>
+ <li>Append to <i>names</i> the elements of the VarDeclaredNames of <i>Finally.</i></li>
+ <li>Return <i>names</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">Catch</span> <span class="geq">:</span> <code class="t">catch</code> <code class="t">(</code> <span class="nt">CatchParameter</span> <code class="t">)</code> <span class="nt">Block</span></div>
+ <ol class="proc">
+ <li>Return the VarDeclaredNames of <i>Block</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-try-statement-static-semantics-varscopeddeclarations">
+ <h1><span class="secnum" id="sec-13.14.3"><a href="#sec-try-statement-static-semantics-varscopeddeclarations"
+ title="link to this section">13.14.3</a></span> Static Semantics: VarScopedDeclarations</h1>
+
+ <p>See also: <a href="#sec-statement-semantics-static-semantics-varscopeddeclarations">13.0.2</a>, <a
+ href="#sec-block-static-semantics-varscopeddeclarations">13.1.9</a>, <a
+ href="#sec-variable-statement-static-semantics-varscopeddeclarations">13.2.2.3</a>, <a
+ href="#sec-if-statement-static-semantics-varscopeddeclarations">13.5.2</a>, <a
+ href="#sec-do-while-statement-static-semantics-varscopeddeclarations">13.6.1.2</a>, <a
+ href="#sec-while-statement-static-semantics-varscopeddeclarations">13.6.2.2</a>, <a
+ href="#sec-for-statement-static-semantics-varscopeddeclarations">13.6.3.2</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-varscopeddeclarations">13.6.4.4</a>, <a
+ href="#sec-with-statement-static-semantics-varscopeddeclarations">13.10.3</a>, <a
+ href="#sec-switch-statement-static-semantics-varscopeddeclarations">13.11.5</a>, <a
+ href="#sec-labelled-statements-static-semantics-varscopeddeclarations">13.12.4</a>, <a
+ href="#sec-function-definitions-static-semantics-varscopeddeclarations">14.1.18</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-varscopeddeclarations">14.2.14</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-varscopeddeclarations">14.4.13</a>, <a
+ href="#sec-scripts-static-semantics-varscopeddeclarations">15.1.6</a>, <a
+ href="#sec-module-static-semantics-static-semantics-varscopeddeclarations">15.2.0.14</a>.</p>
+
+ <div class="gp prod"><span class="nt">TryStatement</span> <span class="geq">:</span> <code class="t">try</code> <span class="nt">Block</span> <span class="nt">Catch</span></div>
+ <ol class="proc">
+ <li>Let <i>declarations</i> be VarScopedDeclarations of <i>Block</i>.</li>
+ <li>Append to <i>declarations</i> the elements of the VarScopedDeclarations of <i>Catch.</i></li>
+ <li>Return <i>declarations</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">TryStatement</span> <span class="geq">:</span> <code class="t">try</code> <span class="nt">Block</span> <span class="nt">Finally</span></div>
+ <ol class="proc">
+ <li>Let <i>declarations</i> be VarScopedDeclarations of <i>Block</i>.</li>
+ <li>Append to <i>declarations</i> the elements of the VarScopedDeclarations of <i>Finally.</i></li>
+ <li>Return <i>declarations</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">TryStatement</span> <span class="geq">:</span> <code class="t">try</code> <span class="nt">Block</span> <span class="nt">Catch</span> <span class="nt">Finally</span></div>
+ <ol class="proc">
+ <li>Let <i>declarations</i> be VarScopedDeclarations of <i>Block</i>.</li>
+ <li>Append to <i>declarations</i> the elements of the VarScopedDeclarations of <i>Catch.</i></li>
+ <li>Append to <i>declarations</i> the elements of the VarScopedDeclarations of <i>Finally.</i></li>
+ <li>Return <i>declarations</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">Catch</span> <span class="geq">:</span> <code class="t">catch</code> <code class="t">(</code> <span class="nt">CatchParameter</span> <code class="t">)</code> <span class="nt">Block</span></div>
+ <ol class="proc">
+ <li>Return the VarScopedDeclarations of <i>Block</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-try-statement-runtime-semantics-bindinginitialization">
+ <h1><span class="secnum" id="sec-13.14.4"><a href="#sec-try-statement-runtime-semantics-bindinginitialization"
+ title="link to this section">13.14.4</a></span> Runtime Semantics: BindingInitialization</h1>
+
+ <p>With arguments <var>value</var> and <var>environment</var>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> <b>undefined</b> is passed for <var>environment</var> to indicate that a <a
+ href="#sec-putvalue">PutValue</a> operation should be used to assign the initialization value. This is the case for
+ <code>var</code> statements formal parameter lists of non-strict functions. In those cases a lexical binding is hosted and
+ preinitialized prior to evaluation of its initializer.</p>
+ </div>
+
+ <p>See also: <a href="#sec-array-comprehension-runtime-semantics-bindinginitialization">12.2.4.2.2</a>, <b>Error! <a
+ href="#sec-reference-specification-type">Reference</a> source not found.</b>, <a
+ href="#sec-variable-statement-static-semantics-vardeclarednames">13.2.2.2</a>, <a
+ href="#sec-destructuring-binding-patterns-static-semantics-issimpleparameterlist">13.2.3.4</a>.</p>
+
+ <p><span class="prod"><span class="nt">CatchParameter</span> <span class="geq">:</span> <span
+ class="nt">BindingPattern</span></span></p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>value</i>) is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>Return the result of performing BindingInitialization for <i>BindingPattern</i> passing <i>value</i> and
+ <i>environment</i> as the arguments.</li>
+ </ol>
+ </section>
+
+ <section id="sec-runtime-semantics-catchclauseevaluation">
+ <h1><span class="secnum" id="sec-13.14.5"><a href="#sec-runtime-semantics-catchclauseevaluation"
+ title="link to this section">13.14.5</a></span> Runtime Semantics: CatchClauseEvaluation</h1>
+
+ <p>with parameter <var>thrownValue</var></p>
+
+ <div class="gp prod"><span class="nt">Catch</span> <span class="geq">:</span> <code class="t">catch</code> <code class="t">(</code> <span class="nt">CatchParameter</span> <code class="t">)</code> <span class="nt">Block</span></div>
+ <ol class="proc">
+ <li>Let <i>oldEnv</i> be <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-execution-contexts">LexicalEnvironment</a>.</li>
+ <li>Let <i>catchEnv</i> be <a href="#sec-newdeclarativeenvironment">NewDeclarativeEnvironment</a>(<i>oldEnv</i>).</li>
+ <li>For each element <i>argName</i> of the BoundNames of <i>CatchParameter</i>, do
+ <ol class="block">
+ <li>Call the CreateMutableBinding concrete method of <i>catchEnv</i> passing <i>argName</i> as the argument.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: The above call to CreateMutableBinding will never return an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a>.</li>
+ </ol>
+ </li>
+ <li>Let <i>status</i> be the result of performing BindingInitialization for <i>CatchParameter</i> passing
+ <i>thrownValue</i> and <i>catchEnv</i> as arguments.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Set <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-execution-contexts">LexicalEnvironment</a> to <i>catchEnv</i>.</li>
+ <li>Let <i>B</i> be the result of evaluating <i>Block</i>.</li>
+ <li>Set <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-execution-contexts">LexicalEnvironment</a> to <i>oldEnv</i>.</li>
+ <li>Return <i>B</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> No matter how control leaves the <i>Block</i> the <a
+ href="#sec-execution-contexts">LexicalEnvironment</a> is always restored to its former state.</p>
+ </div>
+ </section>
+
+ <section id="sec-try-statement-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-13.14.6"><a href="#sec-try-statement-runtime-semantics-evaluation"
+ title="link to this section">13.14.6</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">TryStatement</span> <span class="geq">:</span> <code class="t">try</code> <span class="nt">Block</span> <span class="nt">Catch</span></div>
+ <ol class="proc">
+ <li>Let <i>B</i> be the result of evaluating <i>Block</i>.</li>
+ <li>If <i>B</i>.[[type]] is not <span style="font-family: sans-serif">throw</span>, return <i>B</i>.</li>
+ <li>Return the result of performing CatchClauseEvaluation of <i>Catch</i> with parameter <i>B</i>.[[value]].</li>
+ </ol>
+ <div class="gp prod"><span class="nt">TryStatement</span> <span class="geq">:</span> <code class="t">try</code> <span class="nt">Block</span> <span class="nt">Finally</span></div>
+ <ol class="proc">
+ <li>Let <i>B</i> be the result of evaluating <i>Block</i>.</li>
+ <li>Let <i>F</i> be the result of evaluating <i>Finally</i>.</li>
+ <li>If <i>F</i>.[[type]] is <span style="font-family: sans-serif">normal</span>, return <i>B</i>.</li>
+ <li>Return <i>F</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">TryStatement</span> <span class="geq">:</span> <code class="t">try</code> <span class="nt">Block</span> <span class="nt">Catch</span> <span class="nt">Finally</span></div>
+ <ol class="proc">
+ <li>Let <i>B</i> be the result of evaluating <i>Block</i>.</li>
+ <li>If <i>B</i>.[[type]] is <span style="font-family: sans-serif">throw</span>, then
+ <ol class="block">
+ <li>Let <i>C</i> be the result of performing CatchClauseEvaluation of <i>Catch</i> with parameter
+ <i>B</i>.[[value]].</li>
+ </ol>
+ </li>
+ <li>Else <i>B</i>.[[type]] is not <span style="font-family: sans-serif">throw</span><b>,</b>
+ <ol class="block">
+ <li>Let <i>C</i> be <i>B</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>F</i> be the result of evaluating <i>Finally</i>.</li>
+ <li>If <i>F</i>.[[type]] is <span style="font-family: sans-serif">normal</span>, return <i>C</i>.</li>
+ <li>Return <i>F</i>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-debugger-statement">
+ <div class="front">
+ <h1><span class="secnum" id="sec-13.15"><a href="#sec-debugger-statement" title="link to this section">13.15</a></span> The
+ <code>debugger</code> statement</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">DebuggerStatement</span> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">debugger</code> <code class="t">;</code></div>
+ </div>
+ </div>
+
+ <section id="sec-debugger-statement-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-13.15.1"><a href="#sec-debugger-statement-runtime-semantics-evaluation"
+ title="link to this section">13.15.1</a></span> Runtime Semantics: Evaluation</h1>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Evaluating the <span class="nt">DebuggerStatement</span> production may allow an
+ implementation to cause a breakpoint when run under a debugger. If a debugger is not present or active this statement has
+ no observable effect.</p>
+ </div>
+
+ <div class="gp prod"><span class="nt">DebuggerStatement</span> <span class="geq">:</span> <code class="t">debugger</code> <code class="t">;</code></div>
+ <ol class="proc">
+ <li>If an implementation defined debugging facility is available and enabled, then
+ <ol class="block">
+ <li>Perform an implementation defined debugging action.</li>
+ <li>Let <i>result</i> be an implementation defined <a href="#sec-completion-record-specification-type">Completion</a>
+ value.</li>
+ </ol>
+ </li>
+ <li>Else
+ <ol class="block">
+ <li>Let <i>result</i> be <a href="#sec-normalcompletion">NormalCompletion</a>(<span style="font-family:
+ sans-serif">empty</span>).</li>
+ </ol>
+ </li>
+ <li>Return <i>result.</i></li>
+ </ol>
+ </section>
+ </section>
+</section>
+
+<section id="sec-ecmascript-language-functions-and-classes">
+ <div class="front">
+ <h1><span class="secnum" id="sec-14"><a href="#sec-ecmascript-language-functions-and-classes"
+ title="link to this section">14</a></span> ECMAScript Language: Functions and Classes</h1>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Various ECMAScript language elements cause the creation of ECMAScript function objects (<a
+ href="#sec-ordinarycreatefromconstructor">9.1.14</a>). Evaluation of such functions starts with the execution of their
+ [[Call]] internal method (<b>Error! <a href="#sec-reference-specification-type">Reference</a> source not found.</b>).</p>
+ </div>
+ </div>
+
+ <section id="sec-function-definitions">
+ <div class="front">
+ <h1><span class="secnum" id="sec-14.1"><a href="#sec-function-definitions" title="link to this section">14.1</a></span>
+ Function Definitions</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">FunctionDeclaration</span><sub>[Yield, Default]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">function</code> <span class="nt">BindingIdentifier</span><sub>[?Yield, ?Default]</sub> <code class="t">(</code> <span class="nt">FormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">FunctionExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">function</code> <span class="nt">BindingIdentifier</span><sub>opt</sub> <code class="t">(</code> <span class="nt">FormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">StrictFormalParameters</span><sub>[Yield, GeneratorParameter]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">FormalParameters</span><sub>[?Yield, ?GeneratorParameter]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">FormalParameters</span><sub>[Yield,GeneratorParameter]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="grhsannot">[empty]</span></div>
+ <div class="rhs"><span class="nt">FormalParameterList</span><sub>[?Yield, ?GeneratorParameter]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">FormalParameterList</span><sub>[Yield,GeneratorParameter]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">FunctionRestParameter</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="nt">FormalsList</span><sub>[?Yield, ?GeneratorParameter]</sub></div>
+ <div class="rhs"><span class="nt">FormalsList</span><sub>[?Yield, ?GeneratorParameter]</sub> <code class="t">,</code> <span class="nt">FunctionRestParameter</span><sub>[?Yield]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">FormalsList</span><sub>[Yield,GeneratorParameter]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">FormalParameter</span><sub>[?Yield, ?GeneratorParameter]</sub></div>
+ <div class="rhs"><span class="nt">FormalsList</span><sub>[?Yield, ?GeneratorParameter]</sub> <code class="t">,</code> <span class="nt">FormalParameter</span><sub>[?Yield,?GeneratorParameter]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">FunctionRestParameter</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">BindingRestElement</span><sub>[Yield]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">FormalParameter</span><sub>[Yield,GeneratorParameter]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">BindingElement</span><sub>[?Yield, ?GeneratorParameter]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">FunctionBody</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">FunctionStatementList</span><sub>[?Yield]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">FunctionStatementList</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">StatementList</span><sub>[?Yield, Return]</sub><sub>opt</sub></div>
+ </div>
+ </div>
+
+ <section id="sec-directive-prologues-and-the-use-strict-directive">
+ <h1><span class="secnum" id="sec-14.1.1"><a href="#sec-directive-prologues-and-the-use-strict-directive"
+ title="link to this section">14.1.1</a></span> Directive Prologues and the Use Strict Directive</h1>
+
+ <p>A Directive Prologue is the longest sequence of <span class="nt">ExpressionStatement</span> productions occurring as the
+ initial <span class="nt">StatementListItem</span> productions of a <span class="nt">FunctionBody</span> or a <span
+ class="nt">ScriptBody</span> and where each <span class="nt">ExpressionStatement</span> in the sequence consists entirely of
+ a <span class="nt">StringLiteral</span> token followed by a semicolon<span style="font-family: Times New Roman">.</span> The
+ semicolon may appear explicitly or may be inserted by <a href="#sec-automatic-semicolon-insertion">automatic semicolon
+ insertion</a>. A Directive Prologue may be an empty sequence.</p>
+
+ <p>A Use Strict Directive is an <span class="nt">ExpressionStatement</span> in a Directive Prologue whose <span
+ class="nt">StringLiteral</span> is either the exact character sequences <code>"use</code> <code>strict"</code> or
+ <code>'use</code> <code>strict'</code>. A Use Strict Directive may not contain an <span
+ class="nt">EscapeSequence</span> or <span class="nt">LineContinuation</span>.</p>
+
+ <p>A Directive Prologue may contain more than one Use Strict Directive. However, an implementation may issue a warning if
+ this occurs.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <i>ExpressionStatement</i> productions of a Directive Prologue are evaluated normally
+ during evaluation of the containing production. Implementations may define implementation specific meanings for
+ <i>ExpressionStatement</i> productions which are not a Use Strict Directive and which occur in a Directive Prologue. If
+ an appropriate notification mechanism exists, an implementation should issue a warning if it encounters in a Directive
+ Prologue an <i>ExpressionStatement</i> that is not a Use Strict Directive and which does not have a meaning defined by the
+ implementation.</p>
+ </div>
+ </section>
+
+ <section id="sec-function-definitions-static-semantics-early-errors">
+ <h1><span class="secnum" id="sec-14.1.2"><a href="#sec-function-definitions-static-semantics-early-errors"
+ title="link to this section">14.1.2</a></span> Static Semantics: Early Errors</h1>
+
+ <p><span class="prod"><span class="nt">FunctionDeclaration</span> <span class="geq">:</span> <code class="t">function</code>
+ <span class="nt">BindingIdentifier</span> <code class="t">(</code> <span class="nt">FormalParameters</span> <code
+ class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code
+ class="t">}</code></span><br>and<br><span class="prod"><span class="nt">FunctionExpression</span> <span class="geq">:</span>
+ <code class="t">function</code> <span class="nt">BindingIdentifier</span><sub>opt</sub> <code class="t">(</code> <span
+ class="nt">FormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span>
+ <code class="t">}</code></span></p>
+
+ <ul>
+ <li>
+ <p>If the source code matching this production is <a href="#sec-strict-mode-code">strict code</a>, the Early Error rules
+ for <span class="prod"><span class="nt">StrictFormalParameters</span> <span class="geq">:</span> <span
+ class="nt">FormalParameters</span></span> are applied.</p>
+ </li>
+
+ <li>
+ <p>It is a Syntax Error if any element of the BoundNames of <i>FormalParameters</i> also occurs in the
+ LexicallyDeclaredNames of <i>FunctionBody</i>.</p>
+ </li>
+ </ul>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The LexicallyDeclaredNames of a <i>FunctionBody</i> does not include identifiers bound
+ using var or function declarations. Simple parameter lists bind identifiers as VarDeclaredNames. Parameter lists that
+ contain destructuring patterns, default value initializers, or a rest parameter bind identifiers as
+ LexicallyDeclaredNames.</p>
+ </div>
+
+ <div class="gp prod"><span class="nt">StrictFormalParameters</span> <span class="geq">:</span> <span class="nt">FormalParameters</span></div>
+ <ul>
+ <li>
+ <p>It is a Syntax Error if BoundNames of <i>FormalParameters</i> contains any duplicate elements.</p>
+ </li>
+ </ul>
+ <div class="gp prod"><span class="nt">FormalParameters</span> <span class="geq">:</span> <span class="nt">FormalParameterList</span></div>
+ <ul>
+ <li>
+ <p>It is a Syntax Error if IsSimpleParameterList of <i>FormalParameterList</i> is <b>false</b> and BoundNames of
+ <i>FormalParameterList</i> contains any duplicate elements.</p>
+ </li>
+ </ul>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Multiple occurrences of the same <i>Identifier</i> in a <i>FormalParamterList</i> is only
+ allowed for non-strict functions and generator functions that have simple parameter lists.</p>
+ </div>
+
+ <div class="gp prod"><span class="nt">FunctionStatementList</span> <span class="geq">:</span> <span class="nt">StatementList</span></div>
+ <ul>
+ <li>
+ <p>It is a Syntax Error if the LexicallyDeclaredNames of <i>StatementList</i> contains any duplicate entries.</p>
+ </li>
+
+ <li>
+ <p>It is a Syntax Error if any element of the LexicallyDeclaredNames of <i>StatementList</i> also occurs in the
+ VarDeclaredNames of <i>StatementList</i>.</p>
+ </li>
+ </ul>
+ </section>
+
+ <section id="sec-function-definitions-static-semantics-boundnames">
+ <h1><span class="secnum" id="sec-14.1.3"><a href="#sec-function-definitions-static-semantics-boundnames"
+ title="link to this section">14.1.3</a></span> Static Semantics: BoundNames</h1>
+
+ <p>See also: <a href="#sec-let-and-const-declarations-static-semantics-boundnames">13.2.1.2</a>, <a
+ href="#sec-variable-statement-static-semantics-boundnames">13.2.2.1</a>, <a
+ href="#sec-identifiers-static-semantics-boundnames">12.1.2</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-boundnames">13.6.4.2</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-boundnames">14.2.2</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-boundnames">14.4.2</a>, <a
+ href="#sec-class-definitions-static-semantics-boundnames">14.5.2</a>, <a
+ href="#sec-imports-static-semantics-boundnames">15.2.1.2</a>, <a
+ href="#sec-exports-static-semantics-boundnames">15.2.2.1</a>.</p>
+
+ <div class="gp prod"><span class="nt">FunctionDeclaration</span> <span class="geq">:</span> <code class="t">function</code> <span class="nt">BindingIdentifier</span> <code class="t">(</code> <span class="nt">FormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return the BoundNames of <i>BindingIdentifier</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">FormalParameters</span> <span class="geq">:</span> <span class="grhsannot">[empty]</span></div>
+ <ol class="proc">
+ <li>Return an empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">FormalParameterList</span> <span class="geq">:</span> <span class="nt">FormalsList</span> <code class="t">,</code> <span class="nt">FunctionRestParameter</span></div>
+ <ol class="proc">
+ <li>Let <i>names</i> be BoundNames of <i>FormalsList</i>.</li>
+ <li>Append to <i>names</i> the BoundNames of <i>FunctionRestParameter.</i></li>
+ <li>Return <i>names</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">FormalsList</span> <span class="geq">:</span> <span class="nt">FormalsList</span> <code class="t">,</code> <span class="nt">FormalParameter</span></div>
+ <ol class="proc">
+ <li>Let <i>names</i> be BoundNames of <i>FormalsList</i>.</li>
+ <li>Append to <i>names</i> the elements of BoundNames of <i>FormalParameter.</i></li>
+ <li>Return <i>names</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-function-definitions-static-semantics-contains">
+ <h1><span class="secnum" id="sec-14.1.4"><a href="#sec-function-definitions-static-semantics-contains"
+ title="link to this section">14.1.4</a></span> Static Semantics: Contains</h1>
+
+ <p>With parameter <var>symbol</var>.</p>
+
+ <p>See also: <a href="#sec-static-semantic-rules">5.3</a>, <a
+ href="#sec-object-initializer-static-semantics-computedpropertycontains">12.2.5.2</a>, <a
+ href="#sec-static-semantics-static-semantics-contains">12.3.1.1</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-contains">14.2.3</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-computedpropertycontains">14.4.3</a>, <a
+ href="#sec-class-definitions-static-semantics-contains">14.5.4</a></p>
+
+ <div class="gp prod"><span class="nt">FunctionDeclaration</span> <span class="geq">:</span> <code class="t">function</code> <span class="nt">BindingIdentifier</span> <code class="t">(</code> <span class="nt">FormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">FunctionExpression</span> <span class="geq">:</span> <code class="t">function</code> <span class="nt">BindingIdentifier</span><sub>opt</sub> <code class="t">(</code> <span class="nt">FormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Static semantic rules that depend upon substructure generally do not look into function
+ definitions.</p>
+ </div>
+ </section>
+
+ <section id="sec-function-definitions-static-semantics-containsexpression">
+ <h1><span class="secnum" id="sec-14.1.5"><a href="#sec-function-definitions-static-semantics-containsexpression"
+ title="link to this section">14.1.5</a></span> Static Semantics: ContainsExpression</h1>
+
+ <p>See also: <a href="#sec-destructuring-binding-patterns-static-semantics-containsexpression">13.2.3.2</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-containsexpression">14.2.4</a>.</p>
+
+ <div class="gp prod"><span class="nt">FormalParameters</span> <span class="geq">:</span> <span class="grhsannot">[empty]</span></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">FormalParameterList</span> <span class="geq">:</span> <span class="nt">FunctionRestParameter</span></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">FormalParameterList</span> <span class="geq">:</span> <span class="nt">FormalsList</span> <code class="t">,</code> <span class="nt">FunctionRestParameter</span></div>
+ <ol class="proc">
+ <li>Return ContainsExpression of <i>FormalsList</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">FormalsList</span> <span class="geq">:</span> <span class="nt">FormalsList</span> <code class="t">,</code> <span class="nt">FormalParameter</span></div>
+ <ol class="proc">
+ <li>If ContainsExpression of <i>FormalsList</i> is <b>true</b>, then return <b>true</b>.</li>
+ <li>Return ContainsExpression of <i>FormalParameter</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-function-definitions-static-semantics-expectedargumentcount">
+ <h1><span class="secnum" id="sec-14.1.6"><a href="#sec-function-definitions-static-semantics-expectedargumentcount"
+ title="link to this section">14.1.6</a></span> Static Semantics: ExpectedArgumentCount</h1>
+
+ <p>See also: <a href="#sec-arrow-function-definitions-static-semantics-expectedargumentcount">14.2.6</a>, <a
+ href="#sec-method-definitions-static-semantics-computedpropertycontains">14.3.2</a>.</p>
+
+ <div class="gp prod"><span class="nt">FormalParameters</span> <span class="geq">:</span> <span class="grhsannot">[empty]</span></div>
+ <ol class="proc">
+ <li>Return 0.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">FormalParameterList</span> <span class="geq">:</span> <span class="nt">FunctionRestParameter</span></div>
+ <ol class="proc">
+ <li>Return 0.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">FormalParameterList</span> <span class="geq">:</span> <span class="nt">FormalsList</span> <code class="t">,</code> <span class="nt">FunctionRestParameter</span></div>
+ <ol class="proc">
+ <li>Return the ExpectedArgumentCount of <i>FormalsList</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The ExpectedArgumentCount of a <i>FormalParameterList</i> is the number of
+ <i>FormalParameters</i> to the left of either the rest parameter or the first <i>FormalParameter</i> with an Initializer.
+ A <i>FormalParameter</i> without an initializer is allowed after the first parameter with an initializer but such
+ parameters are considered to be optional with <b>undefined</b> as their default value.</p>
+ </div>
+
+ <div class="gp prod"><span class="nt">FormalsList</span> <span class="geq">:</span> <span class="nt">FormalParameter</span></div>
+ <ol class="proc">
+ <li>If HasInitializer of <i>FormalParameter</i> is <b>true</b> return 0</li>
+ <li>Return 1.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">FormalsList</span> <span class="geq">:</span> <span class="nt">FormalsList</span> <code class="t">,</code> <span class="nt">FormalParameter</span></div>
+ <ol class="proc">
+ <li>Let <i>count</i> be the ExpectedArgumentCount of <i>FormalsList.</i></li>
+ <li>If HasInitializer of <i>FormalsList</i> is <b>true</b> or HasInitializer of <i>FormalParameter</i> is <b>true</b>,
+ then return <i>count</i>.</li>
+ <li>Return <i>count</i>+1.</li>
+ </ol>
+ </section>
+
+ <section id="sec-function-definitions-static-semantics-hasinitializer">
+ <h1><span class="secnum" id="sec-14.1.7"><a href="#sec-function-definitions-static-semantics-hasinitializer"
+ title="link to this section">14.1.7</a></span> Static Semantics: HasInitializer</h1>
+
+ <p>See also: <a href="#sec-destructuring-binding-patterns-static-semantics-hasinitializer">13.2.3.3</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-hasinitializer">14.2.7</a>.</p>
+
+ <div class="gp prod"><span class="nt">FormalParameters</span> <span class="geq">:</span> <span class="grhsannot">[empty]</span></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">FormalParameterList</span> <span class="geq">:</span> <span class="nt">FunctionRestParameter</span></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">FormalParameterList</span> <span class="geq">:</span> <span class="nt">FormalsList</span> <code class="t">,</code> <span class="nt">FunctionRestParameter</span></div>
+ <ol class="proc">
+ <li>If HasInitializer of <i>FormalsList</i> is <b>true</b>, then return <b>true</b>.</li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">FormalsList</span> <span class="geq">:</span> <span class="nt">FormalsList</span> <code class="t">,</code> <span class="nt">FormalParameter</span></div>
+ <ol class="proc">
+ <li>If HasInitializer of <i>FormalsList</i> is <b>true</b>, then return <b>true</b>.</li>
+ <li>Return HasInitializer of <i>FormalParameter</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-function-definitions-static-semantics-hasname">
+ <h1><span class="secnum" id="sec-14.1.8"><a href="#sec-function-definitions-static-semantics-hasname"
+ title="link to this section">14.1.8</a></span> Static Semantics: HasName</h1>
+
+ <p>See also: <a href="#sec-arrow-function-definitions-static-semantics-hasname">14.2.8</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-hasname">14.4.6</a>, <a
+ href="#sec-class-definitions-static-semantics-hasname">14.5.6</a>.</p>
+
+ <div class="gp prod"><span class="nt">FunctionExpression</span> <span class="geq">:</span> <code class="t">function</code> <code class="t">(</code> <span class="nt">FormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">FunctionExpression</span> <span class="geq">:</span> <code class="t">function</code> <span class="nt">BindingIdentifier</span> <code class="t">(</code> <span class="nt">FormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return <b>true</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-isanonymousfunctiondefinition">
+ <h1><span class="secnum" id="sec-14.1.9"><a href="#sec-isanonymousfunctiondefinition"
+ title="link to this section">14.1.9</a></span> Static Semantics: IsAnonymousFunctionDefinition ( production) Abstract
+ Operation</h1>
+
+ <p>The abstract operation IsAnonymousFunctionDefinition determines if its argument is a function definition that does not
+ bind a name. The argument <var>production</var> is the result of parsing an <span class="nt">AssignmentExpression</span> or
+ <span class="nt">Initializer</span>. The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>If IsFunctionDefinition of <i>production</i> is <b>false</b>, then return <b>false</b>.</li>
+ <li>Let <i>hasName</i> be the result of HasName of <i>production</i>.</li>
+ <li>If <i>hasName</i> is <b>true</b>, then return <b>false</b>.</li>
+ <li>Return <b>true</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-function-definitions-static-semantics-isconstantdeclaration">
+ <h1><span class="secnum" id="sec-14.1.10"><a href="#sec-function-definitions-static-semantics-isconstantdeclaration"
+ title="link to this section">14.1.10</a></span> Static Semantics: IsConstantDeclaration</h1>
+
+ <p>See also: <a href="#sec-let-and-const-declarations-static-semantics-isconstantdeclaration">13.2.1.3</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-hascomputedpropertykey">14.4.5</a>, <a
+ href="#sec-class-definitions-static-semantics-computedpropertycontains">14.5.5</a>.</p>
+
+ <div class="gp prod"><span class="nt">FunctionDeclaration</span> <span class="geq">:</span> <code class="t">function</code> <span class="nt">BindingIdentifier</span> <code class="t">(</code> <span class="nt">FormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-function-definitions-static-semantics-isfunctiondefinition">
+ <h1><span class="secnum" id="sec-14.1.11"><a href="#sec-function-definitions-static-semantics-isfunctiondefinition"
+ title="link to this section">14.1.11</a></span> Static Semantics: IsFunctionDefinition</h1>
+
+ <p>See also: <a href="#sec-semantics-static-semantics-isfunctiondefinition">12.2.0.2</a>, <a
+ href="#sec-grouping-operator-static-semantics-isfunctiondefinition">12.2.10.2</a>, <a
+ href="#sec-static-semantics-static-semantics-isfunctiondefinition">12.3.1.2</a>, <a
+ href="#sec-postfix-expressions-static-semantics-isfunctiondefinition">12.4.2</a>, <a
+ href="#sec-unary-operators-static-semantics-isfunctiondefinition">12.5.2</a>, <a
+ href="#sec-multiplicative-operators-static-semantics-isfunctiondefinition">12.6.1</a>, <a
+ href="#sec-additive-operators-static-semantics-isfunctiondefinition">12.7.1</a>, <a
+ href="#sec-bitwise-shift-operators-static-semantics-isfunctiondefinition">12.8.1</a>, <a
+ href="#sec-relational-operators-static-semantics-isfunctiondefinition">12.9.1</a>, <a
+ href="#sec-equality-operators-static-semantics-isfunctiondefinition">12.10.1</a>, <a
+ href="#sec-binary-bitwise-operators-static-semantics-isfunctiondefinition">12.11.1</a>, <a
+ href="#sec-binary-logical-operators-static-semantics-isfunctiondefinition">12.12.1</a>, <a
+ href="#sec-conditional-operator-static-semantics-isfunctiondefinition">12.13.1</a>, <a
+ href="#sec-assignment-operators-static-semantics-isfunctiondefinition">12.14.2</a>, <a
+ href="#sec-comma-operator-static-semantics-isfunctiondefinition">12.15.1</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-isfunctiondefinition">14.4.8</a>, <a
+ href="#sec-class-definitions-static-semantics-isfunctiondefinition">14.5.8</a>.</p>
+
+ <div class="gp prod"><span class="nt">FunctionExpression</span> <span class="geq">:</span> <code class="t">function</code> <code class="t">(</code> <span class="nt">FormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return <b>true</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">FunctionExpression</span> <span class="geq">:</span> <code class="t">function</code> <span class="nt">BindingIdentifier</span> <code class="t">(</code> <span class="nt">FormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return <b>true</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-function-definitions-static-semantics-issimpleparameterlist">
+ <h1><span class="secnum" id="sec-14.1.12"><a href="#sec-function-definitions-static-semantics-issimpleparameterlist"
+ title="link to this section">14.1.12</a></span> Static Semantics: IsSimpleParameterList</h1>
+
+ <p>See also: <a href="#sec-destructuring-binding-patterns-static-semantics-issimpleparameterlist">13.2.3.4</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-hasname">14.2.8</a></p>
+
+ <div class="gp prod"><span class="nt">FormalParameters</span> <span class="geq">:</span> <span class="grhsannot">[empty]</span></div>
+ <ol class="proc">
+ <li>Return <b>true</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">FormalParameterList</span> <span class="geq">:</span> <span class="nt">FunctionRestParameter</span></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">FormalParameterList</span> <span class="geq">:</span> <span class="nt">FormalsList</span> <code class="t">,</code> <span class="nt">FunctionRestParameter</span></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">FormalsList</span> <span class="geq">:</span> <span class="nt">FormalsList</span> <code class="t">,</code> <span class="nt">FormalParameter</span></div>
+ <ol class="proc">
+ <li>If IsSimpleParameterList of <i>FormalsList</i> is <b>false</b>, return <b>false</b>.</li>
+ <li>Return IsSimpleParameterList of <i>FormalParameter</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">FormalParameter</span> <span class="geq">:</span> <span class="nt">BindingElement</span></div>
+ <ol class="proc">
+ <li>Return IsSimpleParameterList of <i>BindingElement</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-function-definitions-static-semantics-isstrict">
+ <h1><span class="secnum" id="sec-14.1.13"><a href="#sec-function-definitions-static-semantics-isstrict"
+ title="link to this section">14.1.13</a></span> Static Semantics: IsStrict</h1>
+
+ <p>See also: <a href="#sec-scripts-static-semantics-isstrict">15.1.2</a>, <a
+ href="#sec-module-static-semantics-static-semantics-isstrict">15.2.0.7</a>.</p>
+
+ <div class="gp prod"><span class="nt">FunctionStatementList</span> <span class="geq">:</span> <span class="nt">StatementList</span><sub>opt</sub></div>
+ <ol class="proc">
+ <li>If this <i>FunctionStatementList</i> is contained in <a href="#sec-strict-mode-code">strict code</a> or if
+ <i>StatementList</i> is <a href="#sec-strict-mode-code">strict code</a>, then return <b>true</b>. Otherwise, return
+ <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-function-definitions-static-semantics-lexicallyscopeddeclarations">
+ <h1><span class="secnum" id="sec-14.1.14"><a href="#sec-function-definitions-static-semantics-lexicallyscopeddeclarations"
+ title="link to this section">14.1.14</a></span> Static Semantics: LexicallyScopedDeclarations</h1>
+
+ <p>See also: <a href="#sec-switch-statement-static-semantics-lexicallyscopeddeclarations">13.11.2</a>, <a
+ href="#sec-module-static-semantics-static-semantics-lexicallyscopeddeclarations">15.2.0.11</a>.</p>
+
+ <div class="gp prod"><span class="nt">FunctionStatementList</span> <span class="geq">:</span> <span class="grhsannot">[empty]</span></div>
+ <ol class="proc">
+ <li>Return an empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">FunctionStatementList</span> <span class="geq">:</span> <span class="nt">StatementList</span></div>
+ <ol class="proc">
+ <li>Return the TopLevelLexicallyScopedDeclarations of <i>StatementList</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-function-definitions-static-semantics-lexicallydeclarednames">
+ <h1><span class="secnum" id="sec-14.1.15"><a href="#sec-function-definitions-static-semantics-lexicallydeclarednames"
+ title="link to this section">14.1.15</a></span> Static Semantics: LexicallyDeclaredNames</h1>
+
+ <p>See also: <a href="#sec-block-static-semantics-lexicallydeclarednames">13.1.3</a>, <a
+ href="#sec-switch-statement-static-semantics-lexicallydeclarednames">13.11.3</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-lexicallyscopeddeclarations">14.2.10</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-isfunctiondefinition">14.4.8</a>, <a
+ href="#sec-class-definitions-static-semantics-lexicallydeclarednames">14.5.10</a>, <a
+ href="#sec-scripts-static-semantics-lexicallydeclarednames">15.1.3</a>, <a
+ href="#sec-module-static-semantics-static-semantics-lexicallydeclarednames">15.2.0.10</a>.</p>
+
+ <div class="gp prod"><span class="nt">FunctionDeclaration</span> <span class="geq">:</span> <code class="t">function</code> <span class="nt">BindingIdentifier</span> <code class="t">(</code> <span class="nt">FormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return the BoundNames of <i>BindingIdentifier</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">FunctionStatementList</span> <span class="geq">:</span> <span class="grhsannot">[empty]</span></div>
+ <ol class="proc">
+ <li>Return an empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">FunctionStatementList</span> <span class="geq">:</span> <span class="nt">StatementList</span></div>
+ <ol class="proc">
+ <li>Return TopLevelLexicallyDeclaredNames of <i>StatementList</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-function-definitions-static-semantics-referencessuper">
+ <h1><span class="secnum" id="sec-14.1.16"><a href="#sec-function-definitions-static-semantics-referencessuper"
+ title="link to this section">14.1.16</a></span> Static Semantics: ReferencesSuper</h1>
+
+ <p>See also: <a href="#sec-arrow-function-definitions-static-semantics-referencessuper">14.2.12</a>, <a
+ href="#sec-method-definitions-static-semantics-referencessuper">14.3.6</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-referencessuper">14.4.11</a>.</p>
+
+ <div class="gp prod"><span class="nt">FunctionDeclaration</span> <span class="geq">:</span> <code class="t">function</code> <span class="nt">BindingIdentifier</span> <code class="t">(</code> <span class="nt">FormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>If <i>FormalParameters</i> Contains <code>super</code> is <b>true</b>, then return <b>true.</b></li>
+ <li>Return <i>FunctionBody</i> Contains <code>super</code>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">FunctionExpression</span> <span class="geq">:</span> <code class="t">function</code> <span class="nt">BindingIdentifier</span><sub>opt</sub> <code class="t">(</code> <span class="nt">FormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>If <i>FormalParameters</i> Contains <code>super</code> is <b>true</b>, then return <b>true.</b></li>
+ <li>Return <i>FunctionBody</i> Contains <code>super</code>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">FormalParameters</span> <span class="geq">:</span> <span class="grhsannot">[empty]</span></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">FormalParameters</span> <span class="geq">:</span> <span class="nt">FormalParameterList</span></div>
+ <ol class="proc">
+ <li>Return <i>FormalParameterList</i> Contains <code>super</code>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">FunctionBody</span> <span class="geq">:</span> <span class="nt">FunctionStatementList</span></div>
+ <ol class="proc">
+ <li>Return <i>FunctionStatementList</i> Contains <code>super</code>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-function-definitions-static-semantics-vardeclarednames">
+ <h1><span class="secnum" id="sec-14.1.17"><a href="#sec-function-definitions-static-semantics-vardeclarednames"
+ title="link to this section">14.1.17</a></span> Static Semantics: VarDeclaredNames</h1>
+
+ <p>See also: <a href="#sec-statement-semantics-static-semantics-vardeclarednames">13.0.1</a>, <a
+ href="#sec-block-static-semantics-vardeclarednames">13.1.8</a>, <a
+ href="#sec-variable-statement-static-semantics-vardeclarednames">13.2.2.2</a>, <a
+ href="#sec-if-statement-static-semantics-vardeclarednames">13.5.1</a>, <a
+ href="#sec-do-while-statement-static-semantics-vardeclarednames">13.6.1.1</a>, <a
+ href="#sec-while-statement-static-semantics-vardeclarednames">13.6.2.1</a>, <a
+ href="#sec-for-statement-static-semantics-vardeclarednames">13.6.3.1</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-vardeclarednames">13.6.4.3</a>, <a
+ href="#sec-with-statement-static-semantics-vardeclarednames">13.10.2</a>, <a
+ href="#sec-switch-statement-static-semantics-vardeclarednames">13.11.4</a>, <a
+ href="#sec-static-semantics-currentlabelset">13.12.2</a>, <a
+ href="#sec-try-statement-static-semantics-vardeclarednames">13.14.2</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-vardeclarednames">14.4.12</a>, <a
+ href="#sec-class-definitions-static-semantics-vardeclarednames">14.5.15</a>, <a
+ href="#sec-scripts-static-semantics-vardeclarednames">15.1.5</a>, <a
+ href="#sec-module-static-semantics-static-semantics-vardeclarednames">15.2.0.13</a>.</p>
+
+ <div class="gp prod"><span class="nt">FunctionDeclaration</span> <span class="geq">:</span> <code class="t">function</code> <span class="nt">BindingIdentifier</span> <code class="t">(</code> <span class="nt">FormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return an empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">FunctionStatementList</span> <span class="geq">:</span> <span class="grhsannot">[empty]</span></div>
+ <ol class="proc">
+ <li>Return an empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">FunctionStatementList</span> <span class="geq">:</span> <span class="nt">StatementList</span></div>
+ <ol class="proc">
+ <li>Return TopLevelVarDeclaredNames of <i>StatementList</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-function-definitions-static-semantics-varscopeddeclarations">
+ <h1><span class="secnum" id="sec-14.1.18"><a href="#sec-function-definitions-static-semantics-varscopeddeclarations"
+ title="link to this section">14.1.18</a></span> Static Semantics: VarScopedDeclarations</h1>
+
+ <p>See also: <a href="#sec-statement-semantics-static-semantics-varscopeddeclarations">13.0.2</a>, <a
+ href="#sec-block-static-semantics-varscopeddeclarations">13.1.9</a>, <a
+ href="#sec-variable-statement-static-semantics-varscopeddeclarations">13.2.2.3</a>, <a
+ href="#sec-if-statement-static-semantics-varscopeddeclarations">13.5.2</a>, <a
+ href="#sec-do-while-statement-static-semantics-varscopeddeclarations">13.6.1.2</a>, <a
+ href="#sec-while-statement-static-semantics-varscopeddeclarations">13.6.2.2</a>, <a
+ href="#sec-for-statement-static-semantics-varscopeddeclarations">13.6.3.2</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-varscopeddeclarations">13.6.4.4</a>, <a
+ href="#sec-with-statement-static-semantics-varscopeddeclarations">13.10.3</a>, <a
+ href="#sec-switch-statement-static-semantics-varscopeddeclarations">13.11.5</a>, <a
+ href="#sec-labelled-statements-static-semantics-varscopeddeclarations">13.12.4</a>, <a
+ href="#sec-try-statement-static-semantics-varscopeddeclarations">13.14.3</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-varscopeddeclarations">14.2.14</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-varscopeddeclarations">14.4.13</a>, <a
+ href="#sec-scripts-static-semantics-varscopeddeclarations">15.1.6</a>, <a
+ href="#sec-module-static-semantics-static-semantics-varscopeddeclarations">15.2.0.14</a>.</p>
+
+ <div class="gp prod"><span class="nt">FunctionDeclaration</span> <span class="geq">:</span> <code class="t">function</code> <span class="nt">BindingIdentifier</span> <code class="t">(</code> <span class="nt">FormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return an empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">FunctionStatementList</span> <span class="geq">:</span> <span class="grhsannot">[empty]</span></div>
+ <ol class="proc">
+ <li>Return an empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">FunctionStatementList</span> <span class="geq">:</span> <span class="nt">StatementList</span></div>
+ <ol class="proc">
+ <li>Return the TopLevelVarScopedDeclarations of <i>StatementList</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-function-definitions-runtime-semantics-evaluatebody">
+ <h1><span class="secnum" id="sec-14.1.19"><a href="#sec-function-definitions-runtime-semantics-evaluatebody"
+ title="link to this section">14.1.19</a></span> Runtime Semantics: EvaluateBody</h1>
+
+ <p>With parameter <var>functionObject</var>.</p>
+
+ <p>See also: <a href="#sec-arrow-function-definitions-runtime-semantics-evaluatebody">14.2.16</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-varscopeddeclarations">14.4.13</a>.</p>
+
+ <div class="gp prod"><span class="nt">FunctionBody</span> <span class="geq">:</span> <span class="nt">FunctionStatementList</span></div>
+ <ol class="proc">
+ <li>The code of this <i>FunctionBody</i> is <a href="#sec-strict-mode-code">strict mode code</a> if it is contained in <a
+ href="#sec-strict-mode-code">strict mode code</a> or if the <a
+ href="#sec-directive-prologues-and-the-use-strict-directive">Directive Prologue</a> (<a
+ href="#sec-directive-prologues-and-the-use-strict-directive">14.1.1</a>) of its <i>FunctionStatementList</i> contains
+ a <a href="#sec-directive-prologues-and-the-use-strict-directive">Use Strict Directive</a> or if any of the conditions
+ in <a href="#sec-strict-mode-code">10.2.1</a> apply. If the code of this <i>FunctionBody</i> is <a
+ href="#sec-strict-mode-code">strict mode code</a>, <i>FunctionStatementList</i> is evaluated in the following steps as
+ <a href="#sec-strict-mode-code">strict mode code</a>. Otherwise, <i>StatementList</i> is evaluated in the following
+ steps as non-<a href="#sec-strict-mode-code">strict mode code</a>.</li>
+ <li>Let <i>result</i> be the result of evaluating <i>FunctionStatementList</i>.</li>
+ <li>If <i>result</i>.[[type]] is <span style="font-family: sans-serif">return</span> then return <a
+ href="#sec-normalcompletion">NormalCompletion</a>(<i>result</i>.[[value]])</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>result</i>).</li>
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<b>undefined</b>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-function-definitions-runtime-semantics-iteratorbindinginitialization">
+ <h1><span class="secnum" id="sec-14.1.20"><a
+ href="#sec-function-definitions-runtime-semantics-iteratorbindinginitialization"
+ title="link to this section">14.1.20</a></span> Runtime Semantics: IteratorBindingInitialization</h1>
+
+ <p>With parameters <var>iterator</var> and <var>environment</var>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> When <b>undefined</b> is passed for <var>environment</var> it indicates that a <a
+ href="#sec-putvalue">PutValue</a> operation should be used to assign the initialization value. This is the case for
+ formal parameter lists of non-strict functions. In that case the formal parameter bindings are preinitialized in order to
+ deal with the possibility of multiple parameters with the same name.</p>
+ </div>
+
+ <p>See also: <a href="#sec-destructuring-binding-patterns-runtime-semantics-iteratorbindinginitialization">13.2.3.6</a>,
+ .</p>
+
+ <div class="gp prod"><span class="nt">FormalParameters</span> <span class="geq">:</span> <span class="grhsannot">[empty]</span></div>
+ <ol class="proc">
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<span style="font-family: sans-serif">empty</span>).</li>
+ </ol>
+ <div class="gp prod"><span class="nt">FormalParameterList</span> <span class="geq">:</span> <span class="nt">FormalsList</span> <code class="t">,</code> <span class="nt">FunctionRestParameter</span></div>
+ <ol class="proc">
+ <li>Let <i>restIndex</i> be the result of performing IteratorBindingInitialization for <i>FormalsList</i> using
+ <i>iterator</i>, and <i>environment</i> as the arguments.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>restIndex</i>).</li>
+ <li>Return the result of performing IteratorBindingInitialization for <i>FunctionRestParameter</i> using <i>iterator</i>
+ and <i>environment</i> as the arguments.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">FormalsList</span> <span class="geq">:</span> <span class="nt">FormalsList</span> <code class="t">,</code> <span class="nt">FormalParameter</span></div>
+ <ol class="proc">
+ <li>Let <i>status</i> be the result of performing IteratorBindingInitialization for <i>FormalsList</i> using
+ <i>iterator</i> and <i>environment</i> as the arguments.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Return the result of performing IteratorBindingInitialization for <i>FormalParameter</i> using <i>iterator</i> and
+ <i>environment</i> as the arguments.</li>
+ </ol>
+ </section>
+
+ <section id="sec-function-definitions-runtime-semantics-instantiatefunctionobject">
+ <h1><span class="secnum" id="sec-14.1.21"><a href="#sec-function-definitions-runtime-semantics-instantiatefunctionobject"
+ title="link to this section">14.1.21</a></span> Runtime Semantics: InstantiateFunctionObject</h1>
+
+ <p>With parameter <var>scope</var>.</p>
+
+ <p>See also: <a href="#sec-generator-function-definitions-runtime-semantics-instantiatefunctionobject">14.4.15</a>.</p>
+
+ <div class="gp prod"><span class="nt">FunctionDeclaration</span> <span class="geq">:</span> <code class="t">function</code> <span class="nt">BindingIdentifier</span> <code class="t">(</code> <span class="nt">FormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>If the <i>FunctionDeclaration</i> is contained in <a href="#sec-strict-mode-code">strict code</a> or if its
+ <i>FunctionBody</i> is <a href="#sec-strict-mode-code">strict code</a>, then let <i>strict</i> be <b>true</b>.
+ Otherwise let <i>strict</i> be <b>false</b>.</li>
+ <li>Let <i>name</i> be StringValue of <i>BindingIdentifier.</i></li>
+ <li>Let <i>F</i> be <a href="#sec-functioncreate">FunctionCreate</a>(<span style="font-family: sans-serif">Normal</span>,
+ <i>FormalParameters</i>, <i>FunctionBody, scope</i>, <i>strict</i>).</li>
+ <li>If ReferencesSuper of <i>FunctionDeclaration</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Perform <a href="#sec-makemethod">MakeMethod</a>(<i>F</i>, <i>name</i>, <b>undefined</b>).</li>
+ </ol>
+ </li>
+ <li>Perform <a href="#sec-makeconstructor">MakeConstructor</a>(<i>F</i>).</li>
+ <li><a href="#sec-setfunctionname">SetFunctionName</a>(<i>F</i>, <i>name</i>).</li>
+ <li>Return <i>F</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-function-definitions-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-14.1.22"><a href="#sec-function-definitions-runtime-semantics-evaluation"
+ title="link to this section">14.1.22</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">FunctionDeclaration</span> <span class="geq">:</span> <code class="t">function</code> <span class="nt">BindingIdentifier</span> <code class="t">(</code> <span class="nt">FormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<span style="font-family: sans-serif">empty</span>)</li>
+ </ol>
+ <div class="gp prod"><span class="nt">FunctionExpression</span> <span class="geq">:</span> <code class="t">function</code> <code class="t">(</code> <span class="nt">FormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>If the <i>FunctionExpression</i> is contained in <a href="#sec-strict-mode-code">strict code</a> or if its
+ <i>FunctionBody</i> is <a href="#sec-strict-mode-code">strict code</a>, then let <i>strict</i> be <b>true</b>.
+ Otherwise let <i>strict</i> be <b>false</b>.</li>
+ <li>Let <i>scope</i> be the <a href="#sec-execution-contexts">LexicalEnvironment</a> of <a
+ href="#sec-execution-contexts">the running execution context</a>.</li>
+ <li>Let <i>closure</i> be <a href="#sec-functioncreate">FunctionCreate</a>(<span style="font-family:
+ sans-serif">Normal</span>, <i>FormalParameters</i>, <i>FunctionBody, scope</i>, <i>strict</i>).</li>
+ <li>If ReferencesSuper of <i>FunctionExpression</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Perform <a href="#sec-makemethod">MakeMethod</a>(<i>closure</i>, <b>undefined</b>, <b>undefined</b>).</li>
+ </ol>
+ </li>
+ <li>Perform <a href="#sec-makeconstructor">MakeConstructor</a>(<i>closure</i>).</li>
+ <li>Return <i>closure</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">FunctionExpression</span> <span class="geq">:</span> <code class="t">function</code> <span class="nt">BindingIdentifier</span> <code class="t">(</code> <span class="nt">FormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>If the <i>FunctionExpression</i> is contained in <a href="#sec-strict-mode-code">strict code</a> or if its
+ <i>FunctionBody</i> is <a href="#sec-strict-mode-code">strict code</a>, then let <i>strict</i> be <b>true</b>.
+ Otherwise let <i>strict</i> be <b>false</b>.</li>
+ <li>Let <i>runningContext</i> be <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-lexical-environments">Lexical Environment</a>.</li>
+ <li>Let <i>funcEnv</i> be <a href="#sec-newdeclarativeenvironment">NewDeclarativeEnvironment</a>(<i>runningContext</i>
+ ).</li>
+ <li>Let <i>envRec</i> be <i>funcEnv’s</i> environment record.</li>
+ <li>Let <i>name</i> be StringValue of <i>BindingIdentifier</i>.</li>
+ <li>Call the CreateImmutableBinding concrete method of <i>envRec</i> passing <i>name</i> as the argument.</li>
+ <li>Let <i>closure</i> be <a href="#sec-functioncreate">FunctionCreate</a>(<span style="font-family:
+ sans-serif">Normal</span>, <i>FormalParameters</i>, <i>FunctionBody, funcEnv</i>, <i>strict</i>).</li>
+ <li>If ReferencesSuper of <i>FunctionExpression</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Perform <a href="#sec-makemethod">MakeMethod</a>(<i>closure</i>, <i>name</i>, <b>undefined</b>).</li>
+ </ol>
+ </li>
+ <li>Perform <a href="#sec-makeconstructor">MakeConstructor</a>(<i>closure</i>).</li>
+ <li><a href="#sec-setfunctionname">SetFunctionName</a>(<i>closure</i>, <i>name</i>).</li>
+ <li>Call the InitializeBinding concrete method of <i>envRec</i> passing <i>name</i> and <i>closure</i> as the
+ arguments.</li>
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<i>closure</i>).</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> The <i>BindingIdentifier</i> in a <i>FunctionExpression</i> can be referenced from
+ inside the <i>FunctionExpression's</i> <i>FunctionBody</i> to allow the function to call itself recursively. However,
+ unlike in a <i>FunctionDeclaration</i>, the <i>BindingIdentifier</i> in a <i>FunctionExpression</i> cannot be referenced
+ from and does not affect the scope enclosing the <i>FunctionExpression</i>.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 2</span> A <code>prototype</code> property is automatically created for every function defined
+ using a <i>FunctionDeclaration</i> or <i>FunctionExpression</i>, to allow for the possibility that the function will be
+ used as a constructor.</p>
+ </div>
+
+ <div class="gp prod"><span class="nt">FunctionStatementList</span> <span class="geq">:</span> <span class="grhsannot">[empty]</span></div>
+ <ol class="proc">
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<b>undefined</b>).</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-arrow-function-definitions">
+ <div class="front">
+ <h1><span class="secnum" id="sec-14.2"><a href="#sec-arrow-function-definitions"
+ title="link to this section">14.2</a></span> Arrow Function Definitions</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ArrowFunction</span><sub>[In, Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">ArrowParameters</span><sub>[?Yield]</sub> <span class="grhsannot">[no <span class="nt">LineTerminator</span> here]</span> <code class="t">=></code> <span class="nt">ConciseBody</span><sub>[?In]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ArrowParameters</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">BindingIdentifier</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="nt">CoverParenthesizedExpressionAndArrowParameterList</span><sub>[?Yield]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ConciseBody</span><sub>[In]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="grhsannot">[lookahead ≠ { ]</span> <span class="nt">AssignmentExpression</span><sub>[?In]</sub></div>
+ <div class="rhs"><code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ </div>
+
+ <h2>Supplemental Syntax</h2>
+
+ <p>When processing the production</p>
+
+ <p><span class="nt">ArrowParameters</span><sub>[Yield]</sub> <b>:</b> <span
+ class="nt">CoverParenthesizedExpressionAndArrowParameterList</span><sub>[?Yield]</sub></p>
+
+ <p>is recognized the following grammar is used to refine the interpretation of <span class="prod"><span
+ class="nt">CoverParenthesizedExpressionAndArrowParameterList</span> <span class="geq">:</span></span></p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ArrowFormalParameters</span><sub>[Yield, GeneratorParameter]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">(</code> <span class="nt">StrictFormalParameters</span><sub>[?Yield, ?GeneratorParameter]</sub> <code class="t">)</code></div>
+ </div>
+ </div>
+
+ <section id="sec-arrow-function-definitions-static-semantics-early-errors">
+ <h1><span class="secnum" id="sec-14.2.1"><a href="#sec-arrow-function-definitions-static-semantics-early-errors"
+ title="link to this section">14.2.1</a></span> Static Semantics: Early Errors</h1>
+ <div class="gp prod"><span class="nt">ArrowFunction</span> <span class="geq">:</span> <span class="nt">ArrowParameters</span> <code class="t">=></code> <span class="nt">ConciseBody</span></div>
+ <ul>
+ <li>
+ <p>It is a Syntax Error if any element of the BoundNames of <i>ArrowParameters</i> also occurs in the
+ LexicallyDeclaredNames of <i>ConciseBody</i>.</p>
+ </li>
+ </ul>
+
+ <p><span class="nt">ArrowParameters</span><sub>[Yield]</sub> <b>:</b> <span
+ class="nt">CoverParenthesizedExpressionAndArrowParameterList</span><sub>[?Yield]</sub></p>
+
+ <ul>
+ <li>
+ <p>If the <sub>[Yield]</sub> grammar parameter is present on <i>ArrowParameters</i>, it is a Syntax Error if the
+ lexical token sequence matched by <i>CoverParenthesizedExpressionAndArrowParameterList</i><sub>[?Yield]</sub> cannot be
+ parsed with no tokens left over using <i>ArrowFormalParameters</i><sub>[Yield, GeneratorParameter]</sub> as the goal
+ symbol.</p>
+ </li>
+
+ <li>
+ <p>If the <sub>[Yield]</sub> grammar parameter is not present on <i>ArrowParameters</i>, it is a Syntax Error if the
+ lexical token sequence matched by <i>CoverParenthesizedExpressionAndArrowParameterList</i><sub>[?Yield]</sub> cannot be
+ parsed with no tokens left over using <i>ArrowFormalParameters</i> as the goal symbol.</p>
+ </li>
+
+ <li>
+ <p>It is a Syntax Error if any early errors are present for CoveredFormalsList of
+ <i>CoverParenthesizedExpressionAndArrowParameterList</i><sub>[?Yield]</sub>.</p>
+ </li>
+ </ul>
+ </section>
+
+ <section id="sec-arrow-function-definitions-static-semantics-boundnames">
+ <h1><span class="secnum" id="sec-14.2.2"><a href="#sec-arrow-function-definitions-static-semantics-boundnames"
+ title="link to this section">14.2.2</a></span> Static Semantics: BoundNames</h1>
+
+ <p>See also: <a href="#sec-let-and-const-declarations-static-semantics-boundnames">13.2.1.2</a>, <a
+ href="#sec-variable-statement-static-semantics-boundnames">13.2.2.1</a>, <a
+ href="#sec-identifiers-static-semantics-boundnames">12.1.2</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-boundnames">13.6.4.2</a>, <a
+ href="#sec-function-definitions-static-semantics-boundnames">14.1.3</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-boundnames">14.4.2</a>, <a
+ href="#sec-class-definitions-static-semantics-boundnames">14.5.2</a>, <a
+ href="#sec-imports-static-semantics-boundnames">15.2.1.2</a>, <a
+ href="#sec-exports-static-semantics-boundnames">15.2.2.1</a>.</p>
+
+ <p><span class="nt">ArrowParameters</span><sub>[Yield]</sub> <b>:</b> <span
+ class="nt">CoverParenthesizedExpressionAndArrowParameterList</span><sub>[?Yield]</sub></p>
+
+ <ol class="proc">
+ <li>Let <i>formals</i> be CoveredFormalsList of
+ <i>CoverParenthesizedExpressionAndArrowParameterList</i><sub>[?Yield]</sub>.</li>
+ <li>Return the BoundNames of <i>formals</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-arrow-function-definitions-static-semantics-contains">
+ <h1><span class="secnum" id="sec-14.2.3"><a href="#sec-arrow-function-definitions-static-semantics-contains"
+ title="link to this section">14.2.3</a></span> Static Semantics: Contains</h1>
+
+ <p>With parameter <var>symbol</var>.</p>
+
+ <p>See also: <a href="#sec-static-semantic-rules">5.3</a>, <a
+ href="#sec-object-initializer-static-semantics-computedpropertycontains">12.2.5.2</a>, <a
+ href="#sec-static-semantics-static-semantics-contains">12.3.1.1</a>, <a
+ href="#sec-function-definitions-static-semantics-contains">14.1.4</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-computedpropertycontains">14.4.3</a>, <a
+ href="#sec-class-definitions-static-semantics-contains">14.5.4</a></p>
+
+ <div class="gp prod"><span class="nt">ArrowFunction</span> <span class="geq">:</span> <span class="nt">ArrowParameters</span> <code class="t">=></code> <span class="nt">ConciseBody</span></div>
+ <ol class="proc">
+ <li>If <i>symbol</i> is neither <code>super</code> nor <code>this</code>, then return <b>false</b>.</li>
+ <li>If <i>ArrowParameters</i> Contains <i>symbol</i> is <b>true</b>, return <b>true</b>;</li>
+ <li>Return <i>ConciseBody</i> Contains <i>symbol</i> .</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> <span style="font-family: sans-serif">Normally,</span> Contains <span style="font-family:
+ sans-serif">does not look inside most function forms However,</span> Contains is used to detect <code>this</code> and
+ <code>super</code> usage within an <i>ArrowFunction</i>.</p>
+ </div>
+
+ <p><span class="nt">ArrowParameters</span><sub>[Yield]</sub> <b>:</b> <span
+ class="nt">CoverParenthesizedExpressionAndArrowParameterList</span><sub>[?Yield]</sub></p>
+
+ <ol class="proc">
+ <li>Let <i>formals</i> be CoveredFormalsList of
+ <i>CoverParenthesizedExpressionAndArrowParameterList</i><sub>[?Yield]</sub>.</li>
+ <li>Return <i>formals</i> Contains <i>symbol</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-arrow-function-definitions-static-semantics-containsexpression">
+ <h1><span class="secnum" id="sec-14.2.4"><a href="#sec-arrow-function-definitions-static-semantics-containsexpression"
+ title="link to this section">14.2.4</a></span> Static Semantics: ContainsExpression</h1>
+
+ <p>See also: <a href="#sec-destructuring-binding-patterns-static-semantics-containsexpression">13.2.3.2</a>, <a
+ href="#sec-function-definitions-static-semantics-containsexpression">14.1.5</a>.</p>
+
+ <div class="gp prod"><span class="nt">ArrowParameters</span> <span class="geq">:</span> <span class="nt">BindingIdentifier</span></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+
+ <p><span class="nt">ArrowParameters</span><sub>[Yield]</sub> <b>:</b> <span
+ class="nt">CoverParenthesizedExpressionAndArrowParameterList</span><sub>[?Yield]</sub></p>
+
+ <ol class="proc">
+ <li>Let <i>formals</i> be CoveredFormalsList of
+ <i>CoverParenthesizedExpressionAndArrowParameterList</i><sub>[?Yield]</sub>.</li>
+ <li>Return the ContainsExpression of <i>formals</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-static-semantics-coveredformalslist">
+ <h1><span class="secnum" id="sec-14.2.5"><a href="#sec-static-semantics-coveredformalslist"
+ title="link to this section">14.2.5</a></span> Static Semantics: CoveredFormalsList</h1>
+ <div class="gp prod"><span class="nt">ArrowParameters</span> <span class="geq">:</span> <span class="nt">BindingIdentifier</span></div>
+ <ol class="proc">
+ <li>Return <i>BindingIdentifier</i>.</li>
+ </ol>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">CoverParenthesizedExpressionAndArrowParameterList</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">(</code> <span class="nt">Expression</span> <code class="t">)</code></div>
+ <div class="rhs"><code class="t">(</code> <code class="t">)</code></div>
+ <div class="rhs"><code class="t">(</code> <code class="t">...</code> <span class="nt">BindingIdentifier</span> <code class="t">)</code></div>
+ <div class="rhs"><code class="t">(</code> <span class="nt">Expression</span> <code class="t">,</code> <code class="t">...</code> <span class="nt">BindingIdentifier</span> <code class="t">)</code></div>
+ </div>
+
+ <ol class="proc">
+ <li>If the <sub>[Yield]</sub> grammar parameter is present for
+ <i>CoverParenthesizedExpressionAndArrowParameterList</i><sub>[Yield]</sub> return the result of parsing the lexical
+ token stream matched by <i>CoverParenthesizedExpressionAndArrowParameterList</i><sub>[Yield]</sub> using
+ <i>ArrowFormalParameters</i><sub>[Yield, GeneratorParameter]</sub> as the goal symbol.</li>
+ <li>If the <sub>[Yield]</sub> grammar parameter is not present for
+ <i>CoverParenthesizedExpressionAndArrowParameterList</i><sub>[Yield]</sub> return the result of parsing the lexical
+ token stream matched by <i>CoverParenthesizedExpressionAndArrowParameterList</i> using <i>ArrowFormalParameters</i> as
+ the goal symbol.</li>
+ </ol>
+ </section>
+
+ <section id="sec-arrow-function-definitions-static-semantics-expectedargumentcount">
+ <h1><span class="secnum" id="sec-14.2.6"><a href="#sec-arrow-function-definitions-static-semantics-expectedargumentcount"
+ title="link to this section">14.2.6</a></span> Static Semantics: ExpectedArgumentCount</h1>
+
+ <p>See also: <a href="#sec-function-definitions-static-semantics-containsexpression">14.1.5</a>, <a
+ href="#sec-method-definitions-static-semantics-computedpropertycontains">14.3.2</a>.</p>
+
+ <div class="gp prod"><span class="nt">ArrowParameters</span> <span class="geq">:</span> <span class="nt">BindingIdentifier</span></div>
+ <ol class="proc">
+ <li>Return 1.</li>
+ </ol>
+
+ <p><span class="nt">ArrowParameters</span><sub>[Yield]</sub> <b>:</b> <span
+ class="nt">CoverParenthesizedExpressionAndArrowParameterList</span><sub>[?Yield]</sub></p>
+
+ <ol class="proc">
+ <li>Let <i>formals</i> be CoveredFormalsList of
+ <i>CoverParenthesizedExpressionAndArrowParameterList</i><sub>[?Yield]</sub>.</li>
+ <li>Return the ExpectedArgumentCount of <i>formals</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-arrow-function-definitions-static-semantics-hasinitializer">
+ <h1><span class="secnum" id="sec-14.2.7"><a href="#sec-arrow-function-definitions-static-semantics-hasinitializer"
+ title="link to this section">14.2.7</a></span> Static Semantics: HasInitializer</h1>
+
+ <p>See also: <a href="#sec-destructuring-binding-patterns-static-semantics-hasinitializer">13.2.3.3</a>, <a
+ href="#sec-function-definitions-static-semantics-hasinitializer">14.1.7</a>.</p>
+
+ <div class="gp prod"><span class="nt">ArrowParameters</span> <span class="geq">:</span> <span class="nt">BindingIdentifier</span></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ArrowParameters</span> <span class="geq">:</span> <span class="nt">CoverParenthesizedExpressionAndArrowParameterList</span></div>
+ <ol class="proc">
+ <li>Let <i>formals</i> be CoveredFormalsList of <i>CoverParenthesizedExpressionAndArrowParameterList</i>.</li>
+ <li>Return the HasInitializer of <i>formals</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-arrow-function-definitions-static-semantics-hasname">
+ <h1><span class="secnum" id="sec-14.2.8"><a href="#sec-arrow-function-definitions-static-semantics-hasname"
+ title="link to this section">14.2.8</a></span> Static Semantics: HasName</h1>
+
+ <p>See also: <a href="#sec-function-definitions-static-semantics-hasname">14.1.8</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-hasname">14.4.6</a>, <a
+ href="#sec-class-definitions-static-semantics-hasname">14.5.6</a>.</p>
+
+ <div class="gp prod"><span class="nt">ArrowFunction</span> <span class="geq">:</span> <span class="nt">ArrowParameters</span> <code class="t">=></code> <span class="nt">ConciseBody</span></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-arrow-function-definitions-static-semantics-issimpleparameterlist">
+ <h1><span class="secnum" id="sec-14.2.9"><a href="#sec-arrow-function-definitions-static-semantics-issimpleparameterlist"
+ title="link to this section">14.2.9</a></span> Static Semantics: IsSimpleParameterList</h1>
+
+ <p>See also: <a href="#sec-destructuring-binding-patterns-static-semantics-issimpleparameterlist">13.2.3.4</a>, <a
+ href="#sec-function-definitions-static-semantics-isfunctiondefinition">14.1.11</a>.</p>
+
+ <div class="gp prod"><span class="nt">ArrowParameters</span> <span class="geq">:</span> <span class="nt">BindingIdentifier</span></div>
+ <ol class="proc">
+ <li>Return <b>true</b>.</li>
+ </ol>
+
+ <p><span class="nt">ArrowParameters</span><sub>[Yield]</sub> <b>:</b> <span
+ class="nt">CoverParenthesizedExpressionAndArrowParameterList</span><sub>[?Yield]</sub></p>
+
+ <ol class="proc">
+ <li>Let <i>formals</i> be CoveredFormalsList of
+ <i>CoverParenthesizedExpressionAndArrowParameterList</i><sub>[?Yield]</sub>.</li>
+ <li>Return the IsSimpleParameterList of <i>formals</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-arrow-function-definitions-static-semantics-lexicallyscopeddeclarations">
+ <h1><span class="secnum" id="sec-14.2.10"><a
+ href="#sec-arrow-function-definitions-static-semantics-lexicallyscopeddeclarations"
+ title="link to this section">14.2.10</a></span> Static Semantics: LexicallyScopedDeclarations</h1>
+
+ <p>See also: <a href="#sec-switch-statement-static-semantics-lexicallyscopeddeclarations">13.11.2</a>, <a
+ href="#sec-module-static-semantics-static-semantics-lexicallyscopeddeclarations">15.2.0.11</a>.</p>
+
+ <div class="gp prod"><span class="nt">ConciseBody</span> <span class="geq">:</span> <span class="nt">AssignmentExpression</span></div>
+ <ol class="proc">
+ <li>Return an empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-arrow-function-definitions-static-semantics-lexicallydeclarednames">
+ <h1><span class="secnum" id="sec-14.2.11"><a href="#sec-arrow-function-definitions-static-semantics-lexicallydeclarednames"
+ title="link to this section">14.2.11</a></span> Static Semantics: LexicallyDeclaredNames</h1>
+
+ <p>See also: <a href="#sec-block-static-semantics-lexicallydeclarednames">13.1.3</a>, <a
+ href="#sec-switch-statement-static-semantics-lexicallydeclarednames">13.11.3</a>, <a
+ href="#sec-function-definitions-static-semantics-lexicallyscopeddeclarations">14.1.14</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-isfunctiondefinition">14.4.8</a>, <a
+ href="#sec-class-definitions-static-semantics-lexicallydeclarednames">14.5.10</a>, <a
+ href="#sec-scripts-static-semantics-lexicallydeclarednames">15.1.3</a>, <a
+ href="#sec-module-static-semantics-static-semantics-lexicallydeclarednames">15.2.0.10</a>.</p>
+
+ <div class="gp prod"><span class="nt">ConciseBody</span> <span class="geq">:</span> <span class="nt">AssignmentExpression</span></div>
+ <ol class="proc">
+ <li>Return an empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-arrow-function-definitions-static-semantics-referencessuper">
+ <h1><span class="secnum" id="sec-14.2.12"><a href="#sec-arrow-function-definitions-static-semantics-referencessuper"
+ title="link to this section">14.2.12</a></span> Static Semantics: ReferencesSuper</h1>
+
+ <p>See also: <a href="#sec-function-definitions-static-semantics-referencessuper">14.1.16</a>, <a
+ href="#sec-method-definitions-static-semantics-referencessuper">14.3.6</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-referencessuper">14.4.11</a>.</p>
+
+ <div class="gp prod"><span class="nt">ArrowFunction</span> <span class="geq">:</span> <span class="nt">ArrowParameters</span> <code class="t">=></code> <span class="nt">ConciseBody</span></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> ReferencesSuper is used to determine whether a function requires its own super bindings.
+ This is never the case for Arrow Functions.</p>
+ </div>
+ </section>
+
+ <section id="sec-arrow-function-definitions-static-semantics-vardeclarednames">
+ <h1><span class="secnum" id="sec-14.2.13"><a href="#sec-arrow-function-definitions-static-semantics-vardeclarednames"
+ title="link to this section">14.2.13</a></span> Static Semantics: VarDeclaredNames</h1>
+
+ <p>See also: <a href="#sec-statement-semantics-static-semantics-vardeclarednames">13.0.1</a>, <a
+ href="#sec-block-static-semantics-vardeclarednames">13.1.8</a>, <a
+ href="#sec-variable-statement-static-semantics-vardeclarednames">13.2.2.2</a>, <a
+ href="#sec-if-statement-static-semantics-vardeclarednames">13.5.1</a>, <a
+ href="#sec-do-while-statement-static-semantics-vardeclarednames">13.6.1.1</a>, <a
+ href="#sec-while-statement-static-semantics-vardeclarednames">13.6.2.1</a>, <a
+ href="#sec-for-statement-static-semantics-vardeclarednames">13.6.3.1</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-vardeclarednames">13.6.4.3</a>, <a
+ href="#sec-with-statement-static-semantics-vardeclarednames">13.10.2</a>, <a
+ href="#sec-switch-statement-static-semantics-vardeclarednames">13.11.4</a>, <a
+ href="#sec-static-semantics-currentlabelset">13.12.2</a>, <a
+ href="#sec-try-statement-static-semantics-vardeclarednames">13.14.2</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-vardeclarednames">14.4.12</a>, <a
+ href="#sec-class-definitions-static-semantics-vardeclarednames">14.5.15</a>, <a
+ href="#sec-scripts-static-semantics-vardeclarednames">15.1.5</a>, <a
+ href="#sec-module-static-semantics-static-semantics-vardeclarednames">15.2.0.13</a>.</p>
+
+ <div class="gp prod"><span class="nt">ConciseBody</span> <span class="geq">:</span> <span class="nt">AssignmentExpression</span></div>
+ <ol class="proc">
+ <li>Return an empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-arrow-function-definitions-static-semantics-varscopeddeclarations">
+ <h1><span class="secnum" id="sec-14.2.14"><a href="#sec-arrow-function-definitions-static-semantics-varscopeddeclarations"
+ title="link to this section">14.2.14</a></span> Static Semantics: VarScopedDeclarations</h1>
+
+ <p>See also: <a href="#sec-statement-semantics-static-semantics-varscopeddeclarations">13.0.2</a>, <a
+ href="#sec-block-static-semantics-varscopeddeclarations">13.1.9</a>, <a
+ href="#sec-variable-statement-static-semantics-varscopeddeclarations">13.2.2.3</a>, <a
+ href="#sec-if-statement-static-semantics-varscopeddeclarations">13.5.2</a>, <a
+ href="#sec-do-while-statement-static-semantics-varscopeddeclarations">13.6.1.2</a>, <a
+ href="#sec-while-statement-static-semantics-varscopeddeclarations">13.6.2.2</a>, <a
+ href="#sec-for-statement-static-semantics-varscopeddeclarations">13.6.3.2</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-varscopeddeclarations">13.6.4.4</a>, <a
+ href="#sec-with-statement-static-semantics-varscopeddeclarations">13.10.3</a>, <a
+ href="#sec-switch-statement-static-semantics-varscopeddeclarations">13.11.5</a>, <a
+ href="#sec-labelled-statements-static-semantics-varscopeddeclarations">13.12.4</a>, <a
+ href="#sec-try-statement-static-semantics-varscopeddeclarations">13.14.3</a>, <a
+ href="#sec-function-definitions-static-semantics-varscopeddeclarations">14.1.18</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-varscopeddeclarations">14.4.13</a>, <a
+ href="#sec-scripts-static-semantics-varscopeddeclarations">15.1.6</a>, <a
+ href="#sec-module-static-semantics-static-semantics-varscopeddeclarations">15.2.0.14</a>.</p>
+
+ <div class="gp prod"><span class="nt">ConciseBody</span> <span class="geq">:</span> <span class="nt">AssignmentExpression</span></div>
+ <ol class="proc">
+ <li>Return an empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-arrow-function-definitions-runtime-semantics-iteratorbindinginitialization">
+ <h1><span class="secnum" id="sec-14.2.15"><a
+ href="#sec-arrow-function-definitions-runtime-semantics-iteratorbindinginitialization"
+ title="link to this section">14.2.15</a></span> Runtime Semantics: IteratorBindingInitialization</h1>
+
+ <p>With parameters <var>iterator</var> and <var>environment</var>.</p>
+
+ <p>See also: <a href="#sec-array-comprehension-runtime-semantics-bindinginitialization">12.2.4.2.2</a>, <b>Error! <a
+ href="#sec-reference-specification-type">Reference</a> source not found.</b>,<a
+ href="#sec-variable-statement-static-semantics-vardeclarednames">13.2.2.2</a>,<a
+ href="#sec-destructuring-binding-patterns-static-semantics-issimpleparameterlist">13.2.3.4</a>,<a
+ href="#sec-try-statement-static-semantics-varscopeddeclarations">13.14.3</a>, <a
+ href="#sec-function-definitions-runtime-semantics-iteratorbindinginitialization">14.1.20</a>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> When <b>undefined</b> is passed for <var>environment</var> it indicates that a <a
+ href="#sec-putvalue">PutValue</a> operation should be used to assign the initialization value. This is the case for
+ formal parameter lists of non-strict functions. In that case the formal parameter bindings are preinitialized in order to
+ deal with the possibility of multiple parameters with the same name.</p>
+ </div>
+
+ <div class="gp prod"><span class="nt">ArrowParameters</span> <span class="geq">:</span> <span class="nt">BindingIdentifier</span></div>
+ <ol class="proc">
+ <li>Let <i>next</i> be <a href="#sec-iteratorstep">IteratorStep</a>(<i>iterator</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>next</i>).</li>
+ <li>If <i>next</i> is <b>false</b>, then let <i>v</i> be <b>undefined</b></li>
+ <li>Else
+ <ol class="block">
+ <li>Let <i>v</i> be <a href="#sec-iteratorvalue">IteratorValue</a>(<i>next</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>v</i>).</li>
+ </ol>
+ </li>
+ <li>Return the result of performing BindingInitialization for <i>BindingIdentifier</i> using <i>v</i> and
+ <i>environment</i> as the arguments.</li>
+ </ol>
+
+ <p><span class="nt">ArrowParameters</span><sub>[Yield]</sub> <b>:</b> <span
+ class="nt">CoverParenthesizedExpressionAndArrowParameterList</span><sub>[?Yield]</sub></p>
+
+ <ol class="proc">
+ <li>Let <i>formals</i> be CoveredFormalsList of
+ <i>CoverParenthesizedExpressionAndArrowParameterList</i><sub>[?Yield]</sub>.</li>
+ <li>Return the result of performing IteratorBindingInitialization of <i>formals</i> with arguments <i>iterator</i> and
+ <i>environment</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-arrow-function-definitions-runtime-semantics-evaluatebody">
+ <h1><span class="secnum" id="sec-14.2.16"><a href="#sec-arrow-function-definitions-runtime-semantics-evaluatebody"
+ title="link to this section">14.2.16</a></span> Runtime Semantics: EvaluateBody</h1>
+
+ <p>With parameter <var>functionObject</var>.</p>
+
+ <p>See also: <a href="#sec-function-definitions-static-semantics-varscopeddeclarations">14.1.18</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-varscopeddeclarations">14.4.13</a>.</p>
+
+ <div class="gp prod"><span class="nt">ConciseBody</span> <span class="geq">:</span> <span class="nt">AssignmentExpression</span></div>
+ <ol class="proc">
+ <li>The code of this <i>ConciseBody</i> is <a href="#sec-strict-mode-code">strict mode code</a> if it is contained in <a
+ href="#sec-strict-mode-code">strict mode code</a> or if any of the conditions in <a
+ href="#sec-strict-mode-code">10.2.1</a> apply. If the code of this <i>ConciseBody</i> is <a
+ href="#sec-strict-mode-code">strict mode code</a>, <i>AssignmentExpression</i> is evaluated in the following steps as
+ <a href="#sec-strict-mode-code">strict mode code</a>. Otherwise, <i>AssignmentExpression</i> is evaluated in the
+ following steps as non-<a href="#sec-strict-mode-code">strict mode code</a>.</li>
+ <li>Let <i>exprRef</i> be the result of evaluating <i>AssignmentExpression</i>.</li>
+ <li>Let <i>exprValue</i> be <a href="#sec-getvalue">GetValue</a>(<i>exprRef</i>).</li>
+ <li>If <i>exprValue</i>.[[type]] is <span style="font-family: sans-serif">return</span> then return <a
+ href="#sec-normalcompletion">NormalCompletion</a>(<i>exprValue</i>.[[value]]).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>exprValue</i>).</li>
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<i>exprValue</i>).</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> In the absence of extensions to this specification, the test is step 4 will never be
+ <b>true</b>.</p>
+ </div>
+ </section>
+
+ <section id="sec-arrow-function-definitions-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-14.2.17"><a href="#sec-arrow-function-definitions-runtime-semantics-evaluation"
+ title="link to this section">14.2.17</a></span> Runtime Semantics: Evaluation</h1>
+
+ <p><i>ArrowFunction</i><span style="font-family: sans-serif"><sub>[Yield]</sub> <b>:</b></span>
+ <i>ArrowParameters</i><span style="font-family: sans-serif"><sub>[?Yield]</sub></span> <code>=></code>
+ <i>ConciseBody</i></p>
+
+ <ol class="proc">
+ <li>If the code of this <i>ArrowFunction</i> is contained in <a href="#sec-strict-mode-code">strict mode code</a> or if
+ any of the conditions in <a href="#sec-strict-mode-code">10.2.1</a> apply, then let <i>strict</i> be <b>true</b>.
+ Otherwise let <i>strict</i> be <b>false</b>.</li>
+ <li>Let <i>scope</i> be the <a href="#sec-execution-contexts">LexicalEnvironment</a> of <a
+ href="#sec-execution-contexts">the running execution context</a>.</li>
+ <li>Let <i>parameters</i> be CoveredFormalsList of <i>ArrowParameters</i><sub>[?Yield]</sub>.</li>
+ <li>Let <i>closure</i> be <a href="#sec-functioncreate">FunctionCreate</a>(<span style="font-family:
+ sans-serif">Arrow</span>, <i>parameters</i>, <i>ConciseBody, scope</i>, <i>strict</i>).</li>
+ <li>Return <i>closure</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Any reference to <code>arguments</code>, <code>super</code>, or <code>this</code> within
+ an <i>ArrowFunction</i> are resoved to their bindings in the lexically enclosing function. Even though an
+ <i>ArrowFunction</i> may contain references to <code>super</code>, the function object created in step 4 is not made into
+ a method by performing <a href="#sec-makemethod">MakeMethod</a>. An <i>ArrowFunction</i> that references
+ <code>super</code> is always contained within a non-<i>ArrowFunction</i> and the necessary state to implement
+ <code>super</code> is accessible via the <i>scope</i> that is captured by the function object of the
+ <i>ArrowFunction</i>.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-method-definitions">
+ <div class="front">
+ <h1><span class="secnum" id="sec-14.3"><a href="#sec-method-definitions" title="link to this section">14.3</a></span> Method
+ Definitions</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">MethodDefinition</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">PropertyName</span><sub>[?Yield]</sub> <code class="t">(</code> <span class="nt">StrictFormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <div class="rhs"><span class="nt">GeneratorMethod</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><code class="t">get</code> <span class="nt">PropertyName</span><sub>[?Yield]</sub> <code class="t">(</code> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <div class="rhs"><code class="t">set</code> <span class="nt">PropertyName</span><sub>[?Yield]</sub> <code class="t">(</code> <span class="nt">PropertySetParameterList</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">PropertySetParameterList</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">FormalParameter</span></div>
+ </div>
+ </div>
+
+ <section id="sec-method-definitions-static-semantics-early-errors">
+ <h1><span class="secnum" id="sec-14.3.1"><a href="#sec-method-definitions-static-semantics-early-errors"
+ title="link to this section">14.3.1</a></span> Static Semantics: Early Errors</h1>
+ <div class="gp prod"><span class="nt">MethodDefinition</span> <span class="geq">:</span> <span class="nt">PropertyName</span> <code class="t">(</code> <span class="nt">StrictFormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ul>
+ <li>
+ <p>It is a Syntax Error if any element of the BoundNames of <i>StrictFormalParameters</i> also occurs in the
+ LexicallyDeclaredNames of <i>FunctionBody</i>.</p>
+ </li>
+ </ul>
+ <div class="gp prod"><span class="nt">MethodDefinition</span> <span class="geq">:</span> <code class="t">set</code> <span class="nt">PropertyName</span> <code class="t">(</code> <span class="nt">PropertySetParameterList</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ul>
+ <li>
+ <p>It is a Syntax Error if BoundNames of <i>PropertySetParameterList</i> contains any duplicate elements.</p>
+ </li>
+
+ <li>
+ <p>It is a Syntax Error if any element of the BoundNames of <i>PropertySetParameterList</i> also occurs in the
+ LexicallyDeclaredNames of <i>FunctionBody</i>.</p>
+ </li>
+ </ul>
+ </section>
+
+ <section id="sec-method-definitions-static-semantics-computedpropertycontains">
+ <h1><span class="secnum" id="sec-14.3.2"><a href="#sec-method-definitions-static-semantics-computedpropertycontains"
+ title="link to this section">14.3.2</a></span> Static Semantics: ComputedPropertyContains</h1>
+
+ <p>With parameter <var>symbol</var>.</p>
+
+ <p>See also: <a href="#sec-object-initializer-static-semantics-computedpropertycontains">12.2.5.2</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-computedpropertycontains">14.4.3</a>, <a
+ href="#sec-class-definitions-static-semantics-computedpropertycontains">14.5.5</a>.</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">MethodDefinition</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">PropertyName</span> <code class="t">(</code> <span class="nt">StrictFormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <div class="rhs"><code class="t">get</code> <span class="nt">PropertyName</span> <code class="t">(</code> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <div class="rhs"><code class="t">set</code> <span class="nt">PropertyName</span> <code class="t">(</code> <span class="nt">PropertySetParameterList</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return the result of ComputedPropertyContains for <i>PropertyName</i> with argument <i>symbol</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-method-definitions-static-semantics-expectedargumentcount">
+ <h1><span class="secnum" id="sec-14.3.3"><a href="#sec-method-definitions-static-semantics-expectedargumentcount"
+ title="link to this section">14.3.3</a></span> Static Semantics: ExpectedArgumentCount</h1>
+
+ <p>See also: <a href="#sec-function-definitions-static-semantics-containsexpression">14.1.5</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-expectedargumentcount">14.2.6</a>.</p>
+
+ <div class="gp prod"><span class="nt">PropertySetParameterList</span> <span class="geq">:</span> <span class="nt">FormalParameter</span></div>
+ <ol class="proc">
+ <li>If HasInitializer of <i>FormalParameter</i> is <b>true</b> return 0</li>
+ <li>Return 1.</li>
+ </ol>
+ </section>
+
+ <section id="sec-method-definitions-static-semantics-hascomputedpropertykey">
+ <h1><span class="secnum" id="sec-14.3.4"><a href="#sec-method-definitions-static-semantics-hascomputedpropertykey"
+ title="link to this section">14.3.4</a></span> Static Semantics: HasComputedPropertyKey</h1>
+
+ <p><b>See also:</b> <a href="#sec-object-initializer-static-semantics-hascomputedpropertykey">12.2.5.4</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-hascomputedpropertykey">14.4.5</a></p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">MethodDefinition</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">PropertyName</span> <code class="t">(</code> <span class="nt">StrictFormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <div class="rhs"><code class="t">get</code> <span class="nt">PropertyName</span> <code class="t">(</code> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <div class="rhs"><code class="t">set</code> <span class="nt">PropertyName</span> <code class="t">(</code> <span class="nt">PropertySetParameterList</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return HasComputedPropertyKey of <i>PropertyName</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-method-definitions-static-semantics-propname">
+ <h1><span class="secnum" id="sec-14.3.5"><a href="#sec-method-definitions-static-semantics-propname"
+ title="link to this section">14.3.5</a></span> Static Semantics: PropName</h1>
+
+ <p><b>See also:</b> <a href="#sec-object-initializer-static-semantics-propname">12.2.5.6</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-propname">14.4.10</a>, <a
+ href="#sec-class-definitions-static-semantics-propname">14.5.13</a></p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">MethodDefinition</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">PropertyName</span> <code class="t">(</code> <span class="nt">StrictFormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <div class="rhs"><code class="t">get</code> <span class="nt">PropertyName</span> <code class="t">(</code> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <div class="rhs"><code class="t">set</code> <span class="nt">PropertyName</span> <code class="t">(</code> <span class="nt">PropertySetParameterList</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return PropName of <i>PropertyName</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-method-definitions-static-semantics-referencessuper">
+ <h1><span class="secnum" id="sec-14.3.6"><a href="#sec-method-definitions-static-semantics-referencessuper"
+ title="link to this section">14.3.6</a></span> Static Semantics: ReferencesSuper</h1>
+
+ <p>See also: <a href="#sec-function-definitions-static-semantics-referencessuper">14.1.16</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-referencessuper">14.2.12</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-referencessuper">14.4.11</a>.</p>
+
+ <div class="gp prod"><span class="nt">MethodDefinition</span> <span class="geq">:</span> <span class="nt">PropertyName</span> <code class="t">(</code> <span class="nt">StrictFormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>If <i>StrictFormalParameters</i> Contains <code>super</code> is <b>true</b>, then return <b>true.</b></li>
+ <li>Return <i>FunctionBody</i> Contains <code>super</code>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">MethodDefinition</span> <span class="geq">:</span> <code class="t">get</code> <span class="nt">PropertyName</span> <code class="t">(</code> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return <i>FunctionBody</i> Contains <code>super</code>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">MethodDefinition</span> <span class="geq">:</span> <code class="t">set</code> <span class="nt">PropertyName</span> <code class="t">(</code> <span class="nt">PropertySetParameterList</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>If <i>PropertySetParameterList</i> Contains <code>super</code> is <b>true</b>, then return <b>true.</b></li>
+ <li>Return <i>FunctionBody</i> Contains <code>super</code>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-static-semantics-specialmethod">
+ <h1><span class="secnum" id="sec-14.3.7"><a href="#sec-static-semantics-specialmethod"
+ title="link to this section">14.3.7</a></span> Static Semantics: SpecialMethod</h1>
+ <div class="gp prod"><span class="nt">MethodDefinition</span> <span class="geq">:</span> <span class="nt">PropertyName</span> <code class="t">(</code> <span class="nt">StrictFormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">MethodDefinition</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">GeneratorMethod</span></div>
+ <div class="rhs"><code class="t">get</code> <span class="nt">PropertyName</span> <code class="t">(</code> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <div class="rhs"><code class="t">set</code> <span class="nt">PropertyName</span> <code class="t">(</code> <span class="nt">PropertySetParameterList</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return <b>true</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-runtime-semantics-definemethod">
+ <h1><span class="secnum" id="sec-14.3.8"><a href="#sec-runtime-semantics-definemethod"
+ title="link to this section">14.3.8</a></span> Runtime Semantics: DefineMethod</h1>
+
+ <p>With parameters <var>object</var> and optional parameter <span style="font-family: Times New
+ Roman"><i>functionPrototype</i>.</span></p>
+
+ <div class="gp prod"><span class="nt">MethodDefinition</span> <span class="geq">:</span> <span class="nt">PropertyName</span> <code class="t">(</code> <span class="nt">StrictFormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Let <i>propKey</i> be the result of evaluating <i>PropertyName</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>propKey</i>).</li>
+ <li>Let <i>strict</i> be IsStrict of <i>FunctionBody</i>.</li>
+ <li>Let <i>scope</i> be <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-execution-contexts">LexicalEnvironment</a>.</li>
+ <li>Let <i>closure</i> be <a href="#sec-functioncreate">FunctionCreate</a>(<span style="font-family:
+ sans-serif">Method</span>, <i>StrictFormalParameters</i>, <i>FunctionBody, scope</i>, <i>strict</i>). If
+ <i>functionPrototype</i> was passed as a parameter then pass its value as the <i>functionPrototype</i> optional
+ argument of <a href="#sec-functioncreate">FunctionCreate</a>.</li>
+ <li>If ReferencesSuper of <i>MethodDefinition</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Perform <a href="#sec-makemethod">MakeMethod</a>(<i>closure</i>, <i>propKey</i>, <i>object</i>).</li>
+ </ol>
+ </li>
+ <li>Return the Record{[[key]]: <i>propKey</i>, [[closure]]: <i>closure</i>}.</li>
+ </ol>
+ </section>
+
+ <section id="sec-method-definitions-runtime-semantics-propertydefinitionevaluation">
+ <h1><span class="secnum" id="sec-14.3.9"><a href="#sec-method-definitions-runtime-semantics-propertydefinitionevaluation"
+ title="link to this section">14.3.9</a></span> Runtime Semantics: PropertyDefinitionEvaluation</h1>
+
+ <p>With parameter <span style="font-family: Times New Roman"><i>object</i>.</span></p>
+
+ <p>See also: <a href="#sec-object-initializer-runtime-semantics-propertydefinitionevaluation">12.2.5.9</a>, <a
+ href="#sec-generator-function-definitions-runtime-semantics-propertydefinitionevaluation">14.4.16</a>, B.3.1</p>
+
+ <div class="gp prod"><span class="nt">MethodDefinition</span> <span class="geq">:</span> <span class="nt">PropertyName</span> <code class="t">(</code> <span class="nt">StrictFormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Let <i>methodDef</i> be the result of DefineMethod of this <i>MethodDefinition</i> with argument <i>object</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>methodDef</i>).</li>
+ <li><a href="#sec-setfunctionname">SetFunctionName</a>(<i>methodDef</i>.[[closure]], <i>methodDef</i>.[[key]]).</li>
+ <li>Let <i>desc</i> be the <a href="#sec-property-descriptor-specification-type">Property Descriptor</a>{[[Value]]:
+ <i>methodDef</i>.[[closure]], [[Writable]]: <b>true</b>, [[Enumerable]]: <b>true</b>, [[Configurable]]:
+ <b>true</b>}.</li>
+ <li>Return <a href="#sec-definepropertyorthrow">DefinePropertyOrThrow</a>(<i>object</i>, <i>methodDef</i>.[[key]],
+ <i>desc</i>).</li>
+ </ol>
+ <div class="gp prod"><span class="nt">MethodDefinition</span> <span class="geq">:</span> <span class="nt">GeneratorMethod</span></div>
+
+ <p>See <a href="#sec-generator-function-definitions">14.4</a>.</p>
+
+ <div class="gp prod"><span class="nt">MethodDefinition</span> <span class="geq">:</span> <code class="t">get</code> <span class="nt">PropertyName</span> <code class="t">(</code> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Let <i>propKey</i> be the result of evaluating <i>PropertyName</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>propKey</i>).</li>
+ <li>Let <i>strict</i> be IsStrict of <i>FunctionBody</i>.</li>
+ <li>Let <i>scope</i> be <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-execution-contexts">LexicalEnvironment</a>.</li>
+ <li>Let <i>formalParameterList</i> be the production <span class="prod"><span class="nt">FormalParameters</span> <span
+ class="geq">:</span> <span class="grhsannot">[empty]</span></span></li>
+ <li>Let <i>closure</i> be <a href="#sec-functioncreate">FunctionCreate</a>(<span style="font-family:
+ sans-serif">Method</span>, <i>formalParameterList</i>, <i>FunctionBody, scope</i>, <i>strict</i>).</li>
+ <li>If ReferencesSuper of <i>MethodDefinition</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Perform <a href="#sec-makemethod">MakeMethod</a>(<i>closure</i>, <i>propKey</i>, <i>object</i>).</li>
+ </ol>
+ </li>
+ <li><a href="#sec-setfunctionname">SetFunctionName</a>(<i>closure</i>, <i>propKey</i>, <code>"<b>get</b>"</code>).</li>
+ <li>Let <i>desc</i> be the PropertyDescriptor{[[Get]]: <i>closure</i>, [[Enumerable]]: <b>true</b>, [[Configurable]]:
+ <b>true</b>}</li>
+ <li>Return <a href="#sec-definepropertyorthrow">DefinePropertyOrThrow</a>(<i>object</i>, <i>propKey</i>,
+ <i>desc</i>).</li>
+ </ol>
+ <div class="gp prod"><span class="nt">MethodDefinition</span> <span class="geq">:</span> <code class="t">set</code> <span class="nt">PropertyName</span> <code class="t">(</code> <span class="nt">PropertySetParameterList</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Let <i>propKey</i> be the result of evaluating <i>PropertyName</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>propKey</i>).</li>
+ <li>Let <i>strict</i> be IsStrict of <i>FunctionBody</i>.</li>
+ <li>Let <i>scope</i> be <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-execution-contexts">LexicalEnvironment</a>.</li>
+ <li>Let <i>closure</i> be <a href="#sec-functioncreate">FunctionCreate</a>(<span style="font-family:
+ sans-serif">Method</span>, <i>PropertySetParameterList</i>, <i>FunctionBody, scope</i>, <i>strict</i>).</li>
+ <li>If ReferencesSuper of <i>MethodDefinition</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Perform <a href="#sec-makemethod">MakeMethod</a>(<i>closure</i>, <i>propKey</i>, <i>object</i>).</li>
+ </ol>
+ </li>
+ <li><a href="#sec-setfunctionname">SetFunctionName</a>(<i>closure</i>, <i>propKey</i>, <code>"<b>set</b>"</code>).</li>
+ <li>Let <i>desc</i> be the PropertyDescriptor{[[Set]]: <i>closure</i>, [[Enumerable]]: <b>true</b>, [[Configurable]]:
+ <b>true</b>}</li>
+ <li>Return <a href="#sec-definepropertyorthrow">DefinePropertyOrThrow</a>(<i>object</i>, <i>propKey</i>,
+ <i>desc</i>).</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-generator-function-definitions">
+ <div class="front">
+ <h1><span class="secnum" id="sec-14.4"><a href="#sec-generator-function-definitions"
+ title="link to this section">14.4</a></span> Generator Function Definitions</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">GeneratorMethod</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">*</code> <span class="nt">PropertyName</span><sub>[?Yield]</sub> <code class="t">(</code> <span class="nt">StrictFormalParameters</span><sub>[Yield,GeneratorParameter]</sub> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span><sub>[Yield]</sub> <code class="t">}</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">GeneratorDeclaration</span><sub>[Yield, Default]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">function</code> <code class="t">*</code> <span class="nt">BindingIdentifier</span><sub>[?Yield, ?Default]</sub> <code class="t">(</code> <span class="nt">FormalParameters</span><sub>[Yield,GeneratorParameter]</sub> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span><sub>[Yield]</sub> <code class="t">}</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">GeneratorExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">function</code> <code class="t">*</code> <span class="nt">BindingIdentifier</span><sub>[Yield]</sub><sub>opt</sub> <code class="t">(</code> <span class="nt">FormalParameters</span><sub>[Yield,GeneratorParameter]</sub> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span><sub>[Yield]</sub> <code class="t">}</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">YieldExpression</span><sub>[In]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">yield</code></div>
+ <div class="rhs"><code class="t">yield</code> <span class="grhsannot">[no <span class="nt">LineTerminator</span> here]</span> <span class="grhsannot">[Lexical goal <span class="nt">InputElementRegExp</span>]</span> <span class="nt">AssignmentExpression</span><sub>[?In, Yield]</sub></div>
+ <div class="rhs"><code class="t">yield</code> <span class="grhsannot">[no <span class="nt">LineTerminator</span> here]</span> <code class="t">*</code> <span class="grhsannot">[Lexical goal <span class="nt">InputElementRegExp</span>]</span> <span class="nt">AssignmentExpression</span><sub>[?In, Yield]</sub></div>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> <i>YieldExpression</i> cannot be used within the <i>FormalParameters</i> of a generator
+ function because any expressions that are part of <i>FormalParameters</i> are evaluate before the resulting generator
+ object is in a resumable state.</p>
+ </div>
+
+ <h2>Supplemental Syntax</h2>
+
+ <p>The following productions are used as an aid in specifying the semantics of certain ECMAScript language features. They
+ are not used when parsing ECMAScript source code.</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">GeneratorBody</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">FunctionBody</span></div>
+ <div class="rhs"><span class="nt">Comprehension</span></div>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE:</span> Abstract operations relating to generator objects are defined in <a
+ href="#sec-generator-abstract-operations">25.3.3</a>.</p>
+ </div>
+ </div>
+
+ <section id="sec-generator-function-definitions-static-semantics-early-errors">
+ <h1><span class="secnum" id="sec-14.4.1"><a href="#sec-generator-function-definitions-static-semantics-early-errors"
+ title="link to this section">14.4.1</a></span> Static Semantics: Early Errors</h1>
+ <div class="gp prod"><span class="nt">GeneratorMethod</span> <span class="geq">:</span> <code class="t">*</code> <span class="nt">PropertyName</span> <code class="t">(</code> <span class="nt">StrictFormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ul>
+ <li>
+ <p>It is a Syntax Error if any element of the BoundNames of <i>StrictFormalParameters</i> also occurs in the
+ LexicallyDeclaredNames of <i>FunctionBody</i>.</p>
+ </li>
+ </ul>
+
+ <p><span class="prod"><span class="nt">GeneratorDeclaration</span> <span class="geq">:</span> <code
+ class="t">function</code> <code class="t">*</code> <span class="nt">BindingIdentifier</span> <code class="t">(</code> <span
+ class="nt">FormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span>
+ <code class="t">}</code></span><br>and<br><span class="prod"><span class="nt">GeneratorExpression</span> <span
+ class="geq">:</span> <code class="t">function</code> <code class="t">*</code> <span
+ class="nt">BindingIdentifier</span><sub>opt</sub> <code class="t">(</code> <span class="nt">FormalParameters</span> <code
+ class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></span></p>
+
+ <p>If the source code matching this production is <a href="#sec-strict-mode-code">strict code</a>, the Early Error rules for
+ <span class="prod"><span class="nt">StrictFormalParameters</span> <span class="geq">:</span> <span
+ class="nt">FormalParameters</span></span> are applied.</p>
+
+ <ul>
+ <li>
+ <p>It is a Syntax Error if any element of the BoundNames of <i>FormalParameters</i> also occurs in the
+ LexicallyDeclaredNames of <i>FunctionBody</i>.</p>
+ </li>
+ </ul>
+ </section>
+
+ <section id="sec-generator-function-definitions-static-semantics-boundnames">
+ <h1><span class="secnum" id="sec-14.4.2"><a href="#sec-generator-function-definitions-static-semantics-boundnames"
+ title="link to this section">14.4.2</a></span> Static Semantics: BoundNames</h1>
+
+ <p>See also: <a href="#sec-let-and-const-declarations-static-semantics-boundnames">13.2.1.2</a>, <a
+ href="#sec-variable-statement-static-semantics-boundnames">13.2.2.1</a>, <a
+ href="#sec-identifiers-static-semantics-boundnames">12.1.2</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-boundnames">13.6.4.2</a>, <a
+ href="#sec-function-definitions-static-semantics-boundnames">14.1.3</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-boundnames">14.2.2</a>, <a
+ href="#sec-class-definitions-static-semantics-boundnames">14.5.2</a>, <a
+ href="#sec-imports-static-semantics-boundnames">15.2.1.2</a>, <a
+ href="#sec-exports-static-semantics-boundnames">15.2.2.1</a>.</p>
+
+ <div class="gp prod"><span class="nt">GeneratorDeclaration</span> <span class="geq">:</span> <code class="t">function</code> <code class="t">*</code> <span class="nt">BindingIdentifier</span> <code class="t">(</code> <span class="nt">FormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return the BoundNames of <i>BindingIdentifier</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-generator-function-definitions-static-semantics-computedpropertycontains">
+ <h1><span class="secnum" id="sec-14.4.3"><a
+ href="#sec-generator-function-definitions-static-semantics-computedpropertycontains"
+ title="link to this section">14.4.3</a></span> Static Semantics: ComputedPropertyContains</h1>
+
+ <p>With parameter <var>symbol</var>.</p>
+
+ <p>See also: <a href="#sec-object-initializer-static-semantics-computedpropertycontains">12.2.5.2</a>, <a
+ href="#sec-method-definitions-static-semantics-computedpropertycontains">14.3.2</a>, <a
+ href="#sec-class-definitions-static-semantics-computedpropertycontains">14.5.5</a>.</p>
+
+ <div class="gp prod"><span class="nt">GeneratorMethod</span> <span class="geq">:</span> <code class="t">*</code> <span class="nt">PropertyName</span> <code class="t">(</code> <span class="nt">StrictFormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return the result of ComputedPropertyContains for <i>PropertyName</i> with argument <i>symbol</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-generator-function-definitions-static-semantics-contains">
+ <h1><span class="secnum" id="sec-14.4.4"><a href="#sec-generator-function-definitions-static-semantics-contains"
+ title="link to this section">14.4.4</a></span> Static Semantics: Contains</h1>
+
+ <p>With parameter <var>symbol</var>.</p>
+
+ <p>See also: <a href="#sec-static-semantic-rules">5.3</a>, <a
+ href="#sec-object-initializer-static-semantics-computedpropertycontains">12.2.5.2</a>, <a
+ href="#sec-static-semantics-static-semantics-contains">12.3.1.1</a>, <a
+ href="#sec-function-definitions-static-semantics-contains">14.1.4</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-contains">14.2.3</a>, <a
+ href="#sec-class-definitions-static-semantics-contains">14.5.4</a></p>
+
+ <div class="gp prod"><span class="nt">GeneratorDeclaration</span> <span class="geq">:</span> <code class="t">function</code> <code class="t">*</code> <span class="nt">BindingIdentifier</span> <code class="t">(</code> <span class="nt">FormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">GeneratorExpression</span> <span class="geq">:</span> <code class="t">function</code> <code class="t">*</code> <span class="nt">BindingIdentifier</span><sub>opt</sub> <code class="t">(</code> <span class="nt">FormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Static semantic rules that depend upon substructure generally do not look into function
+ definitions.</p>
+ </div>
+ </section>
+
+ <section id="sec-generator-function-definitions-static-semantics-hascomputedpropertykey">
+ <h1><span class="secnum" id="sec-14.4.5"><a
+ href="#sec-generator-function-definitions-static-semantics-hascomputedpropertykey"
+ title="link to this section">14.4.5</a></span> Static Semantics: HasComputedPropertyKey</h1>
+
+ <p><b>See also:</b> <a href="#sec-object-initializer-static-semantics-hascomputedpropertykey">12.2.5.4</a>, <a
+ href="#sec-method-definitions-static-semantics-hascomputedpropertykey">14.3.4</a></p>
+
+ <div class="gp prod"><span class="nt">GeneratorMethod</span> <span class="geq">:</span> <code class="t">*</code> <span class="nt">PropertyName</span> <code class="t">(</code> <span class="nt">StrictFormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return IsComputedPropertyKey of <i>PropertyName</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-generator-function-definitions-static-semantics-hasname">
+ <h1><span class="secnum" id="sec-14.4.6"><a href="#sec-generator-function-definitions-static-semantics-hasname"
+ title="link to this section">14.4.6</a></span> Static Semantics: HasName</h1>
+
+ <p>See also: <a href="#sec-function-definitions-static-semantics-hasname">14.1.8</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-hasname">14.2.8</a>, <a
+ href="#sec-class-definitions-static-semantics-hasname">14.5.6</a>.</p>
+
+ <div class="gp prod"><span class="nt">GeneratorExpression</span> <span class="geq">:</span> <code class="t">function</code> <code class="t">*</code> <code class="t">(</code> <span class="nt">FormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">GeneratorExpression</span> <span class="geq">:</span> <code class="t">function</code> <code class="t">*</code> <span class="nt">BindingIdentifier</span> <code class="t">(</code> <span class="nt">FormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return <b>true</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-generator-function-definitions-static-semantics-isconstantdeclaration">
+ <h1><span class="secnum" id="sec-14.4.7"><a
+ href="#sec-generator-function-definitions-static-semantics-isconstantdeclaration"
+ title="link to this section">14.4.7</a></span> Static Semantics: IsConstantDeclaration</h1>
+
+ <p>See also: <a href="#sec-let-and-const-declarations-static-semantics-isconstantdeclaration">13.2.1.3</a>, <a
+ href="#sec-function-definitions-static-semantics-hasname">14.1.8</a>, <a
+ href="#sec-class-definitions-static-semantics-computedpropertycontains">14.5.5</a>.</p>
+
+ <div class="gp prod"><span class="nt">GeneratorDeclaration</span> <span class="geq">:</span> <code class="t">function</code> <code class="t">*</code> <span class="nt">BindingIdentifier</span> <code class="t">(</code> <span class="nt">FormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-generator-function-definitions-static-semantics-isfunctiondefinition">
+ <h1><span class="secnum" id="sec-14.4.8"><a href="#sec-generator-function-definitions-static-semantics-isfunctiondefinition"
+ title="link to this section">14.4.8</a></span> Static Semantics: IsFunctionDefinition</h1>
+
+ <p>See also: <a href="#sec-semantics-static-semantics-isfunctiondefinition">12.2.0.2</a>, <a
+ href="#sec-grouping-operator-static-semantics-isfunctiondefinition">12.2.10.2</a>, <a
+ href="#sec-static-semantics-static-semantics-isfunctiondefinition">12.3.1.2</a>, <a
+ href="#sec-postfix-expressions-static-semantics-isfunctiondefinition">12.4.2</a>, <a
+ href="#sec-unary-operators-static-semantics-isfunctiondefinition">12.5.2</a>, <a
+ href="#sec-multiplicative-operators-static-semantics-isfunctiondefinition">12.6.1</a>, <a
+ href="#sec-additive-operators-static-semantics-isfunctiondefinition">12.7.1</a>, <a
+ href="#sec-bitwise-shift-operators-static-semantics-isfunctiondefinition">12.8.1</a>, <a
+ href="#sec-relational-operators-static-semantics-isfunctiondefinition">12.9.1</a>, <a
+ href="#sec-equality-operators-static-semantics-isfunctiondefinition">12.10.1</a>, <a
+ href="#sec-binary-bitwise-operators-static-semantics-isfunctiondefinition">12.11.1</a>, <a
+ href="#sec-binary-logical-operators-static-semantics-isfunctiondefinition">12.12.1</a>, <a
+ href="#sec-conditional-operator-static-semantics-isfunctiondefinition">12.13.1</a>, <a
+ href="#sec-assignment-operators-static-semantics-isfunctiondefinition">12.14.2</a>, <a
+ href="#sec-comma-operator-static-semantics-isfunctiondefinition">12.15.1</a>, <a
+ href="#sec-function-definitions-static-semantics-isfunctiondefinition">14.1.11</a>, <a
+ href="#sec-class-definitions-static-semantics-isfunctiondefinition">14.5.8</a>.</p>
+
+ <div class="gp prod"><span class="nt">GeneratorExpression</span> <span class="geq">:</span> <code class="t">function</code> <code class="t">*</code> <code class="t">(</code> <span class="nt">FormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return <b>true</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">GeneratorExpression</span> <span class="geq">:</span> <code class="t">function</code> <code class="t">*</code> <span class="nt">BindingIdentifier</span> <code class="t">(</code> <span class="nt">FormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return <b>true</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-generator-function-definitions-static-semantics-lexicallydeclarednames">
+ <h1><span class="secnum" id="sec-14.4.9"><a
+ href="#sec-generator-function-definitions-static-semantics-lexicallydeclarednames"
+ title="link to this section">14.4.9</a></span> Static Semantics: LexicallyDeclaredNames</h1>
+
+ <p>See also: <a href="#sec-block-static-semantics-lexicallydeclarednames">13.1.3</a>, <a
+ href="#sec-switch-statement-static-semantics-lexicallydeclarednames">13.11.3</a>, <a
+ href="#sec-function-definitions-static-semantics-lexicallyscopeddeclarations">14.1.14</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-lexicallyscopeddeclarations">14.2.10</a>, <a
+ href="#sec-class-definitions-static-semantics-lexicallydeclarednames">14.5.10</a>, <a
+ href="#sec-scripts-static-semantics-lexicallydeclarednames">15.1.3</a>, <a
+ href="#sec-module-static-semantics-static-semantics-lexicallydeclarednames">15.2.0.10</a>.</p>
+
+ <div class="gp prod"><span class="nt">GeneratorDeclaration</span> <span class="geq">:</span> <code class="t">function</code> <code class="t">*</code> <span class="nt">BindingIdentifier</span> <code class="t">(</code> <span class="nt">FormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return the BoundNames of <i>BindingIdentifier</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-generator-function-definitions-static-semantics-propname">
+ <h1><span class="secnum" id="sec-14.4.10"><a href="#sec-generator-function-definitions-static-semantics-propname"
+ title="link to this section">14.4.10</a></span> Static Semantics: PropName</h1>
+
+ <p><b>See also:</b> <a href="#sec-object-initializer-static-semantics-propname">12.2.5.6</a>, <a
+ href="#sec-method-definitions-static-semantics-propname">14.3.5</a>, <a
+ href="#sec-class-definitions-static-semantics-propname">14.5.13</a></p>
+
+ <div class="gp prod"><span class="nt">GeneratorMethod</span> <span class="geq">:</span> <code class="t">*</code> <span class="nt">PropertyName</span> <code class="t">(</code> <span class="nt">StrictFormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return PropName of <i>PropertyName</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-generator-function-definitions-static-semantics-referencessuper">
+ <h1><span class="secnum" id="sec-14.4.11"><a href="#sec-generator-function-definitions-static-semantics-referencessuper"
+ title="link to this section">14.4.11</a></span> Static Semantics: ReferencesSuper</h1>
+
+ <p>See also: <a href="#sec-function-definitions-static-semantics-referencessuper">14.1.16</a>,<a
+ href="#sec-arrow-function-definitions-static-semantics-referencessuper">14.2.12</a>, <a
+ href="#sec-method-definitions-static-semantics-referencessuper">14.3.6</a>.</p>
+
+ <div class="gp prod"><span class="nt">GeneratorDeclaration</span> <span class="geq">:</span> <code class="t">function</code> <code class="t">*</code> <span class="nt">BindingIdentifier</span> <code class="t">(</code> <span class="nt">FormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>If <i>FormalParameters</i> Contains <code>super</code> is <b>true</b>, then return <b>true.</b></li>
+ <li>Return <i>FunctionBody</i> Contains <code>super</code>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">GeneratorExpression</span> <span class="geq">:</span> <code class="t">function</code> <code class="t">*</code> <span class="nt">BindingIdentifier</span><sub>opt</sub> <code class="t">(</code> <span class="nt">FormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>If <i>FormalParameters</i> Contains <code>super</code> is <b>true</b>, then return <b>true.</b></li>
+ <li>Return <i>FunctionBody</i> Contains <code>super</code>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">GeneratorMethod</span> <span class="geq">:</span> <code class="t">*</code> <span class="nt">PropertyName</span> <code class="t">(</code> <span class="nt">StrictFormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>If <i>StrictFormalParameters</i> Contains <code>super</code> is <b>true</b>, then return <b>true.</b></li>
+ <li>Return <i>FunctionBody</i> Contains <code>super</code>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-generator-function-definitions-static-semantics-vardeclarednames">
+ <h1><span class="secnum" id="sec-14.4.12"><a href="#sec-generator-function-definitions-static-semantics-vardeclarednames"
+ title="link to this section">14.4.12</a></span> Static Semantics: VarDeclaredNames</h1>
+
+ <p>See also: <a href="#sec-statement-semantics-static-semantics-vardeclarednames">13.0.1</a>, <a
+ href="#sec-block-static-semantics-vardeclarednames">13.1.8</a>, <a
+ href="#sec-variable-statement-static-semantics-vardeclarednames">13.2.2.2</a>, <a
+ href="#sec-if-statement-static-semantics-vardeclarednames">13.5.1</a>, <a
+ href="#sec-do-while-statement-static-semantics-vardeclarednames">13.6.1.1</a>, <a
+ href="#sec-while-statement-static-semantics-vardeclarednames">13.6.2.1</a>, <a
+ href="#sec-for-statement-static-semantics-vardeclarednames">13.6.3.1</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-vardeclarednames">13.6.4.3</a>, <a
+ href="#sec-with-statement-static-semantics-vardeclarednames">13.10.2</a>, <a
+ href="#sec-switch-statement-static-semantics-vardeclarednames">13.11.4</a>, <a
+ href="#sec-static-semantics-currentlabelset">13.12.2</a>, <a
+ href="#sec-try-statement-static-semantics-vardeclarednames">13.14.2</a>, <a
+ href="#sec-function-definitions-static-semantics-referencessuper">14.1.16</a>, <a
+ href="#sec-class-definitions-static-semantics-vardeclarednames">14.5.15</a>, <a
+ href="#sec-scripts-static-semantics-vardeclarednames">15.1.5</a>, <a
+ href="#sec-module-static-semantics-static-semantics-vardeclarednames">15.2.0.13</a>.</p>
+
+ <div class="gp prod"><span class="nt">GeneratorDeclaration</span> <span class="geq">:</span> <code class="t">function</code> <code class="t">*</code> <span class="nt">BindingIdentifier</span> <code class="t">(</code> <span class="nt">FormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return an empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-generator-function-definitions-static-semantics-varscopeddeclarations">
+ <h1><span class="secnum" id="sec-14.4.13"><a
+ href="#sec-generator-function-definitions-static-semantics-varscopeddeclarations"
+ title="link to this section">14.4.13</a></span> Static Semantics: VarScopedDeclarations</h1>
+
+ <p>See also: <a href="#sec-statement-semantics-static-semantics-varscopeddeclarations">13.0.2</a>, <a
+ href="#sec-block-static-semantics-varscopeddeclarations">13.1.9</a>, <a
+ href="#sec-variable-statement-static-semantics-varscopeddeclarations">13.2.2.3</a>, <a
+ href="#sec-if-statement-static-semantics-varscopeddeclarations">13.5.2</a>, <a
+ href="#sec-do-while-statement-static-semantics-varscopeddeclarations">13.6.1.2</a>, <a
+ href="#sec-while-statement-static-semantics-varscopeddeclarations">13.6.2.2</a>, <a
+ href="#sec-for-statement-static-semantics-varscopeddeclarations">13.6.3.2</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-varscopeddeclarations">13.6.4.4</a>, <a
+ href="#sec-with-statement-static-semantics-varscopeddeclarations">13.10.3</a>, <a
+ href="#sec-switch-statement-static-semantics-varscopeddeclarations">13.11.5</a>, <a
+ href="#sec-labelled-statements-static-semantics-varscopeddeclarations">13.12.4</a>, <a
+ href="#sec-try-statement-static-semantics-varscopeddeclarations">13.14.3</a>, <a
+ href="#sec-function-definitions-static-semantics-varscopeddeclarations">14.1.18</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-varscopeddeclarations">14.2.14</a>, <a
+ href="#sec-scripts-static-semantics-varscopeddeclarations">15.1.6</a>, <a
+ href="#sec-module-static-semantics-static-semantics-varscopeddeclarations">15.2.0.14</a>.</p>
+
+ <div class="gp prod"><span class="nt">GeneratorDeclaration</span> <span class="geq">:</span> <code class="t">function</code> <code class="t">*</code> <span class="nt">BindingIdentifier</span> <code class="t">(</code> <span class="nt">FormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return an empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-generator-function-definitions-runtime-semantics-evaluatebody">
+ <h1><span class="secnum" id="sec-14.4.14"><a href="#sec-generator-function-definitions-runtime-semantics-evaluatebody"
+ title="link to this section">14.4.14</a></span> Runtime Semantics: EvaluateBody</h1>
+
+ <p>With parameter <var>functionObject</var>.</p>
+
+ <p>See also: <a href="#sec-function-definitions-static-semantics-varscopeddeclarations">14.1.18</a>, <a
+ href="#sec-arrow-function-definitions-runtime-semantics-evaluatebody">14.2.16</a>.</p>
+
+ <div class="gp prod"><span class="nt">GeneratorBody</span> <span class="geq">:</span> <span class="nt">FunctionBody</span></div>
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: A <a href="#sec-function-environment-records">Function Environment
+ Record</a> containing a this binding has already been activated.</li>
+ <li>Let <i>env</i> be <a href="#sec-getthisenvironment">GetThisEnvironment</a>( ).</li>
+ <li>Let <i>G</i> be the result of calling the GetThisBinding concrete method of <i>env</i>.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>G</i>) is not Object or if <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>G</i>) is Object and <i>G</i> does not have a
+ [[GeneratorState]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> or if <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>G</i>) is Object and <i>G</i> has a [[GeneratorState]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> and the value of <i>G’s</i>
+ [[GeneratorState]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is not
+ <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>newG</i> be <a
+ href="#sec-ordinarycreatefromconstructor">OrdinaryCreateFromConstructor</a>(<i>functionObject</i>,
+ <code>"%GeneratorPrototype%"</code>, ( [[GeneratorState]], [[GeneratorContext]]) ).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>newG</i>).</li>
+ <li>Let <i>G</i> be <i>newG.</i></li>
+ </ol>
+ </li>
+ <li>Return <a href="#sec-generatorstart">GeneratorStart</a>(<i>G</i>, <i>FunctionBody</i>).</li>
+ </ol>
+ <div class="gp prod"><span class="nt">GeneratorBody</span> <span class="geq">:</span> <span class="nt">Comprehension</span></div>
+ <ol class="proc">
+ <li>Let <i>G</i> be <a href="#sec-objectcreate">ObjectCreate</a>(<span style="font-family:
+ sans-serif">%GeneratorPrototype%</span>, ( [[GeneratorState]], [[GeneratorContext]]) ).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>G</i>).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: the value of <i>G’s</i> [[GeneratorState]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is <b>undefined</b>.</li>
+ <li>Let <i>startStatus</i> be <a href="#sec-generatorstart">GeneratorStart</a>(<i>G</i>, <i>Comprehension</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>startStatus</i>).</li>
+ <li>Return <i>G</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-generator-function-definitions-runtime-semantics-instantiatefunctionobject">
+ <h1><span class="secnum" id="sec-14.4.15"><a
+ href="#sec-generator-function-definitions-runtime-semantics-instantiatefunctionobject"
+ title="link to this section">14.4.15</a></span> Runtime Semantics: InstantiateFunctionObject</h1>
+
+ <p>With parameter <var>scope</var>.</p>
+
+ <p>See also: <a href="#sec-function-definitions-runtime-semantics-instantiatefunctionobject">14.1.21</a>.</p>
+
+ <div class="gp prod"><span class="nt">GeneratorDeclaration</span> <span class="geq">:</span> <code class="t">function</code> <code class="t">*</code> <span class="nt">BindingIdentifier</span> <code class="t">(</code> <span class="nt">FormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>If the <i>GeneratorDeclaration</i> is contained in <a href="#sec-strict-mode-code">strict code</a> or if its
+ <i>FunctionBody</i> is <a href="#sec-strict-mode-code">strict code</a>, then let <i>strict</i> be <b>true</b>.
+ Otherwise let <i>strict</i> be <b>false</b>.</li>
+ <li>Let <i>name</i> be StringValue of <i>BindingIdentifier.</i></li>
+ <li>Using <i>FunctionBody</i> from the production that is being evaluated, let <i>body</i> be the supplemental syntactic
+ grammar production: <span class="prod"><span class="nt">GeneratorBody</span> <span class="geq">:</span> <span
+ class="nt">FunctionBody</span></span> .</li>
+ <li>Let <i>F</i> be <a href="#sec-generatorfunctioncreate">GeneratorFunctionCreate</a>(<span style="font-family:
+ sans-serif">Normal</span>, <i>FormalParameters</i>, <i>body, scope</i>, <i>strict</i>).</li>
+ <li>If ReferencesSuper of <i>GeneratorDeclaration</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Perform <a href="#sec-makemethod">MakeMethod</a>(<i>F</i>, <i>name</i>, <b>undefined</b>).</li>
+ </ol>
+ </li>
+ <li>Let <i>prototype</i> be <a href="#sec-objectcreate">ObjectCreate</a>(<span style="font-family:
+ sans-serif">%GeneratorPrototype%</span>).</li>
+ <li>Perform <a href="#sec-makeconstructor">MakeConstructor</a>(<i>F</i>, <b>true</b>, <i>prototype</i>).</li>
+ <li><a href="#sec-setfunctionname">SetFunctionName</a>(<i>F</i>, <i>name</i>).</li>
+ <li>Return <i>F</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-generator-function-definitions-runtime-semantics-propertydefinitionevaluation">
+ <h1><span class="secnum" id="sec-14.4.16"><a
+ href="#sec-generator-function-definitions-runtime-semantics-propertydefinitionevaluation"
+ title="link to this section">14.4.16</a></span> Runtime Semantics: PropertyDefinitionEvaluation</h1>
+
+ <p>With parameter <span style="font-family: Times New Roman"><i>object</i>.</span></p>
+
+ <p>See also: <a href="#sec-object-initializer-runtime-semantics-propertydefinitionevaluation">12.2.5.9</a>, <a
+ href="#sec-method-definitions-runtime-semantics-propertydefinitionevaluation">14.3.9</a>, B.3.1</p>
+
+ <div class="gp prod"><span class="nt">GeneratorMethod</span> <span class="geq">:</span> <code class="t">*</code> <span class="nt">PropertyName</span> <code class="t">(</code> <span class="nt">StrictFormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Let <i>propKey</i> be the result of evaluating <i>PropertyName</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>propKey</i>).</li>
+ <li>Let <i>strict</i> be IsStrict of <i>FunctionBody</i>.</li>
+ <li>Let <i>scope</i> be <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-execution-contexts">LexicalEnvironment</a>.</li>
+ <li>Using <i>FunctionBody</i> from the production that is being evaluated, let <i>body</i> be the supplemental syntactic
+ grammar production: <span class="prod"><span class="nt">GeneratorBody</span> <span class="geq">:</span> <span
+ class="nt">FunctionBody</span></span> .</li>
+ <li>Let <i>closure</i> be <a href="#sec-generatorfunctioncreate">GeneratorFunctionCreate</a>(<span style="font-family:
+ sans-serif">Method</span>, <i>StrictFormalParameters</i>, <i>body, scope</i>, <i>strict</i>).</li>
+ <li>If ReferencesSuper of <i>GeneratorMethod</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Perform <a href="#sec-makemethod">MakeMethod</a>(<i>closure</i>, <i>propKey</i>, <i>object</i>).</li>
+ </ol>
+ </li>
+ <li>Let <i>prototype</i> be <a href="#sec-objectcreate">ObjectCreate</a>(<span style="font-family:
+ sans-serif">%GeneratorPrototype</span>%).</li>
+ <li>Perform <a href="#sec-makeconstructor">MakeConstructor</a>(<i>closure</i>, <b>true</b>, <i>prototype</i>).</li>
+ <li><a href="#sec-setfunctionname">SetFunctionName</a>(<i>closure</i>, <i>propKey</i>).</li>
+ <li>Let <i>desc</i> be the <a href="#sec-property-descriptor-specification-type">Property Descriptor</a>{[[Value]]:
+ <i>closure</i>, [[Writable]]: <b>true</b>, [[Enumerable]]: <b>true</b>, [[Configurable]]: <b>true</b>}.</li>
+ <li>Return <a href="#sec-definepropertyorthrow">DefinePropertyOrThrow</a>(<i>object</i>, <i>propKey</i>,
+ <i>desc</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-generator-function-definitions-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-14.4.17"><a href="#sec-generator-function-definitions-runtime-semantics-evaluation"
+ title="link to this section">14.4.17</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">GeneratorDeclaration</span> <span class="geq">:</span> <code class="t">function</code> <code class="t">*</code> <span class="nt">BindingIdentifier</span> <code class="t">(</code> <span class="nt">FormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<span style="font-family: sans-serif">empty</span>)</li>
+ </ol>
+ <div class="gp prod"><span class="nt">GeneratorExpression</span> <span class="geq">:</span> <code class="t">function</code> <code class="t">*</code> <code class="t">(</code> <span class="nt">FormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>If the <i>GeneratorExpression</i> is contained in <a href="#sec-strict-mode-code">strict code</a> or if its
+ <i>FunctionBody</i> is <a href="#sec-strict-mode-code">strict code</a>, then let <i>strict</i> be <b>true</b>.
+ Otherwise let <i>strict</i> be <b>false</b>.</li>
+ <li>Using <i>FunctionBody</i> from the production that is being evaluated, let <i>body</i> be the supplemental syntactic
+ grammar production: <span class="prod"><span class="nt">GeneratorBody</span> <span class="geq">:</span> <span
+ class="nt">FunctionBody</span></span> .</li>
+ <li>Let <i>scope</i> be the <a href="#sec-execution-contexts">LexicalEnvironment</a> of <a
+ href="#sec-execution-contexts">the running execution context</a>.</li>
+ <li>Let <i>closure</i> be <a href="#sec-generatorfunctioncreate">GeneratorFunctionCreate</a>(<span style="font-family:
+ sans-serif">Normal</span>, <i>FormalParameters</i>, <i>body, scope</i>, <i>strict</i>).</li>
+ <li>If ReferencesSuper of <i>GeneratorExpression</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Perform <a href="#sec-makemethod">MakeMethod</a>(<i>closure</i>, <b>undefined</b>, <b>undefined</b>).</li>
+ </ol>
+ </li>
+ <li>Let <i>prototype</i> be <a href="#sec-objectcreate">ObjectCreate</a>(<span style="font-family:
+ sans-serif">%GeneratorPrototype%</span>).</li>
+ <li>Perform <a href="#sec-makeconstructor">MakeConstructor</a>(<i>closure</i>, <b>true</b>, <i>prototype</i>).</li>
+ <li>Return <i>closure</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">GeneratorExpression</span> <span class="geq">:</span> <code class="t">function</code> <code class="t">*</code> <span class="nt">BindingIdentifier</span> <code class="t">(</code> <span class="nt">FormalParameters</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>If the <i>GeneratorExpression</i> is contained in <a href="#sec-strict-mode-code">strict code</a> or if its
+ <i>FunctionBody</i> is <a href="#sec-strict-mode-code">strict code</a>, then let <i>strict</i> be <b>true</b>.
+ Otherwise let <i>strict</i> be <b>false</b>.</li>
+ <li>Using <i>FunctionBody</i> from the production that is being evaluated, let <i>body</i> be the supplemental syntactic
+ grammar production: <span class="prod"><span class="nt">GeneratorBody</span> <span class="geq">:</span> <span
+ class="nt">FunctionBody</span></span> .</li>
+ <li>Let <i>runningContext</i> be <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-lexical-environments">Lexical Environment</a>.</li>
+ <li>Let <i>funcEnv</i> be <a
+ href="#sec-newdeclarativeenvironment">NewDeclarativeEnvironment</a>(<i>runningContext</i>).</li>
+ <li>Let <i>envRec</i> be <i>funcEnv’s</i> environment record.</li>
+ <li>Let <i>name</i> be StringValue of <i>BindingIdentifier</i>.</li>
+ <li>Call the CreateImmutableBinding concrete method of <i>envRec</i> passing <i>name</i> as the argument.</li>
+ <li>Let <i>closure</i> be <a href="#sec-generatorfunctioncreate">GeneratorFunctionCreate</a>(<span style="font-family:
+ sans-serif">Normal</span>, <i>FormalParameters</i>, <i>body, funcEnv</i>, <i>strict</i>).</li>
+ <li>If ReferencesSuper of <i>GeneratorExpression</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Perform <a href="#sec-makemethod">MakeMethod</a>(<i>closure</i>, <i>name</i>, <b>undefined</b>).</li>
+ </ol>
+ </li>
+ <li>Let <i>prototype</i> be <a href="#sec-objectcreate">ObjectCreate</a>(<span style="font-family:
+ sans-serif">%GeneratorPrototype%</span>).</li>
+ <li>Perform <a href="#sec-makeconstructor">MakeConstructor</a> (<i>closure</i>, <b>true</b>, <i>prototype</i>).</li>
+ <li><a href="#sec-setfunctionname">SetFunctionName</a>(<i>closure</i>, <i>name</i>).</li>
+ <li>Call the InitializeBinding concrete method of <i>envRec</i> passing <i>name</i> and <i>closure</i> as the
+ arguments.</li>
+ <li>Return <i>closure</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> The <i>BindingIdentifier</i> in a <i>GeneratorExpression</i> can be referenced from
+ inside the <i>GeneratorExpression's</i> <i>FunctionBody</i> to allow the generator code to call itself recursively.
+ However, unlike in a <i>GeneratorDeclaration</i>, the <i>BindingIdentifier</i> in a <i>GeneratorExpression</i> cannot be
+ referenced from and does not affect the scope enclosing the <i>GeneratorExpression</i>.</p>
+ </div>
+
+ <div class="gp prod"><span class="nt">YieldExpression</span> <span class="geq">:</span> <code class="t">yield</code></div>
+ <ol class="proc">
+ <li>Return <a href="#sec-generatoryield">GeneratorYield</a>(<a
+ href="#sec-createiterresultobject">CreateIterResultObject</a>(<b>undefined</b>, <b>false</b>)).</li>
+ </ol>
+ <div class="gp prod"><span class="nt">YieldExpression</span> <span class="geq">:</span> <code class="t">yield</code> <span class="nt">AssignmentExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>exprRef</i> be the result of evaluating <i>AssignmentExpression</i>.</li>
+ <li>Let <i>value</i> be <a href="#sec-getvalue">GetValue</a>(<i>exprRef</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>value</i>).</li>
+ <li>Return <a href="#sec-generatoryield">GeneratorYield</a>(<a
+ href="#sec-createiterresultobject">CreateIterResultObject</a>(<i>value</i>, <b>false</b>)).</li>
+ </ol>
+ <div class="gp prod"><span class="nt">YieldExpression</span> <span class="geq">:</span> <code class="t">yield</code> <code class="t">*</code> <span class="nt">AssignmentExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>exprRef</i> be the result of evaluating <i>AssignmentExpression</i>.</li>
+ <li>Let <i>value</i> be <a href="#sec-getvalue">GetValue</a>(<i>exprRef</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>value</i>).</li>
+ <li>Let <i>iterator</i> be <a href="#sec-getiterator">GetIterator</a>(<i>value</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>iterator</i>)<i>.</i></li>
+ <li>Let <i>received</i> be <a href="#sec-normalcompletion">NormalCompletion</a>(<b>undefined</b>).</li>
+ <li>Repeat
+ <ol class="block">
+ <li>If <i>received</i>.[[type]] is <span style="font-family: sans-serif">normal</span>, then
+ <ol class="block">
+ <li>Let <i>innerResult</i> be <a href="#sec-iteratornext">IteratorNext</a>(<i>iterator</i>,
+ <i>received</i>.[[value]]).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>innerResult</i>).</li>
+ </ol>
+ </li>
+ <li>Else
+ <ol class="block">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>received</i>.[[type]] is <span style="font-family:
+ sans-serif">throw.</span></li>
+ <li>If <a href="#sec-hasproperty">HasProperty</a>(<i>iterator</i>, <code>"throw"</code>) is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>innerResult</i> be <a href="#sec-invoke">Invoke</a>(<i>iterator</i>, <code>"throw"</code>,
+ (<i>received</i>.[[value]])).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>innerResult</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>innerResult</i>) is not Object, then throw
+ a <b>TypeError</b> exception.</li>
+ </ol>
+ </li>
+ <li>Else, return <i>received.</i></li>
+ </ol>
+ </li>
+ <li>Let <i>done</i> be <a href="#sec-iteratorcomplete">IteratorComplete</a>(<i>innerResult</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>done</i>).</li>
+ <li>If <i>done</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Return <a href="#sec-iteratorvalue">IteratorValue</a> (<i>innerResult</i>).</li>
+ </ol>
+ </li>
+ <li>Let <i>received</i> be <a href="#sec-generatoryield">GeneratorYield</a>(<i>innerResult</i>).</li>
+ </ol>
+ </li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-class-definitions">
+ <div class="front">
+ <h1><span class="secnum" id="sec-14.5"><a href="#sec-class-definitions" title="link to this section">14.5</a></span> Class
+ Definitions</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ClassDeclaration</span><sub>[Yield, Default]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">class</code> <span class="nt">BindingIdentifier</span><sub>[?Yield, ?Default]</sub> <span class="nt">ClassTail</span><sub>[?Yield]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ClassExpression</span><sub>[Yield,GeneratorParameter]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">class</code> <span class="nt">BindingIdentifier</span><sub>[?Yield]</sub><sub>opt</sub> <span class="nt">ClassTail</span><sub>[?Yield,?GeneratorParameter]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ClassTail</span><sub>[Yield,GeneratorParameter]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="grhsannot">[~GeneratorParameter]</span> <span class="nt">ClassHeritage</span><sub>[?Yield]</sub><sub>opt</sub> <code class="t">{</code> <span class="nt">ClassBody</span><sub>[?Yield]</sub><sub>opt</sub> <code class="t">}</code></div>
+ <div class="rhs"><span class="grhsannot">[+GeneratorParameter]</span> <span class="nt">ClassHeritage</span><sub>opt</sub> <code class="t">{</code> <span class="nt">ClassBody</span><sub>opt</sub> <code class="t">}</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ClassHeritage</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">extends</code> <span class="nt">LeftHandSideExpression</span><sub>[?Yield]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ClassBody</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">ClassElementList</span><sub>[?Yield]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ClassElementList</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">ClassElement</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><span class="nt">ClassElementList</span><sub>[?Yield]</sub> <span class="nt">ClassElement</span><sub>[?Yield]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ClassElement</span><sub>[Yield]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">MethodDefinition</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><code class="t">static</code> <span class="nt">MethodDefinition</span><sub>[?Yield]</sub></div>
+ <div class="rhs"><code class="t">;</code></div>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> A <i>ClassBody</i> is always <a href="#sec-strict-mode-code">strict code</a>.</p>
+ </div>
+ </div>
+
+ <section id="sec-class-definitions-static-semantics-early-errors">
+ <h1><span class="secnum" id="sec-14.5.1"><a href="#sec-class-definitions-static-semantics-early-errors"
+ title="link to this section">14.5.1</a></span> Static Semantics: Early Errors</h1>
+
+ <p><span class="prod"><span class="nt">ClassDeclaration</span> <span class="geq">:</span> <code class="t">class</code> <span
+ class="nt">BindingIdentifier</span> <span class="nt">ClassTail</span></span></p>
+
+ <p><span class="prod"><span class="nt">ClassExpression</span> <span class="geq">:</span> <code class="t">class</code> <span
+ class="nt">BindingIdentifier</span> <span class="nt">ClassTail</span></span></p>
+
+ <ul>
+ <li>It is a Syntax Error if the StringValue of <i>BindingIdentifier</i> is <code>"let"</code>.</li>
+ </ul>
+ <div class="gp prod"><span class="nt">ClassBody</span> <span class="geq">:</span> <span class="nt">ClassElementList</span></div>
+ <ul>
+ <li>
+ <p>It is a Syntax Error if PrototypePropertyNameList of <i>ClassElementList</i> <i>contains any duplicate entries,
+ unless the following condition is <b>true</b> for each duplicate entry:</i> The duplicated entry occurs exactly twice in
+ the list and one occurrence was obtained from a <code>get</code> accessor <i>MethodDefinition</i> and the other
+ occurrence was obtained from a <code>set</code> accessor <i>MethodDefinition</i>.</p>
+ </li>
+
+ <li>
+ <p>It is a Syntax Error if StaticPropertyNameList of <i>ClassElementList</i> <i>contains any duplicate entries, unless
+ the following condition is <b>true</b></i> <i>for each duplicate entry:</i> The duplicated entry occurs exactly twice in
+ the list and one occurrence was obtained from a <code>get</code> accessor <i>MethodDefinition</i> and the other
+ occurrence was obtained from a <code>set</code> accessor <i>MethodDefinition</i>.</p>
+ </li>
+ </ul>
+ <div class="gp prod"><span class="nt">ClassElement</span> <span class="geq">:</span> <span class="nt">MethodDefinition</span></div>
+ <ul>
+ <li>
+ <p>It is a Syntax Error if PropName of <i>MethodDefinition</i> <i>is</i> <b><span style="font-family:
+ sans-serif">″</span><code>constructor</code><span style="font-family: sans-serif">″</span></b> <i>and
+ SpecialMethod of</i> <i>MethodDefinition</i> <i>is</i> <i><b>true</b>.</i></p>
+ </li>
+ </ul>
+ <div class="gp prod"><span class="nt">ClassElement</span> <span class="geq">:</span> <code class="t">static</code> <span class="nt">MethodDefinition</span></div>
+ <ul>
+ <li>It is a Syntax Error if PropName of <i>MethodDefinition</i> <i>is</i> <b><span style="font-family:
+ sans-serif">″</span><code>prototype</code><span style="font-family: sans-serif">″</span></b><i>.</i></li>
+ </ul>
+ </section>
+
+ <section id="sec-class-definitions-static-semantics-boundnames">
+ <h1><span class="secnum" id="sec-14.5.2"><a href="#sec-class-definitions-static-semantics-boundnames"
+ title="link to this section">14.5.2</a></span> Static Semantics: BoundNames</h1>
+
+ <p>See also: <a href="#sec-let-and-const-declarations-static-semantics-boundnames">13.2.1.2</a>, <a
+ href="#sec-variable-statement-static-semantics-boundnames">13.2.2.1</a>, <a
+ href="#sec-identifiers-static-semantics-boundnames">12.1.2</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-boundnames">13.6.4.2</a>, <a
+ href="#sec-function-definitions-static-semantics-boundnames">14.1.3</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-boundnames">14.2.2</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-boundnames">14.4.2</a>, <a
+ href="#sec-imports-static-semantics-boundnames">15.2.1.2</a>, <a
+ href="#sec-exports-static-semantics-boundnames">15.2.2.1</a>.</p>
+
+ <div class="gp prod"><span class="nt">ClassDeclaration</span> <span class="geq">:</span> <code class="t">class</code> <span class="nt">BindingIdentifier</span> <span class="nt">ClassTail</span></div>
+ <ol class="proc">
+ <li>Return the BoundNames of <i>BindingIdentifier</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-static-semantics-constructormethod">
+ <h1><span class="secnum" id="sec-14.5.3"><a href="#sec-static-semantics-constructormethod"
+ title="link to this section">14.5.3</a></span> Static Semantics: ConstructorMethod</h1>
+ <div class="gp prod"><span class="nt">ClassElementList</span> <span class="geq">:</span> <span class="nt">ClassElement</span></div>
+ <ol class="proc">
+ <li>If <i>ClassElement</i> is the production <span class="prod"><span class="nt">ClassElement</span> <span
+ class="geq">:</span> <code class="t">;</code></span> then, return <span style="font-family:
+ sans-serif">empty</span>.</li>
+ <li>If IsStatic of <i>ClassElement</i> is <b>true</b>, return <span style="font-family: sans-serif">empty</span>.</li>
+ <li>If PropName of <i>ClassElement</i> is not <b><span style="font-family:
+ sans-serif">″</span><code>constructor</code><span style="font-family: sans-serif">″</span></b>, return
+ <span style="font-family: sans-serif">empty</span>.</li>
+ <li>Return <i>ClassElement</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ClassElementList</span> <span class="geq">:</span> <span class="nt">ClassElementList</span> <span class="nt">ClassElement</span></div>
+ <ol class="proc">
+ <li>Let <i>head</i> be ConstructorMethod of <i>ClassElementList.</i></li>
+ <li>If <i>head</i> is not <span style="font-family: sans-serif">empty</span>, return <i>head</i>.</li>
+ <li>If <i>ClassElement</i> is the production <span class="prod"><span class="nt">ClassElement</span> <span
+ class="geq">:</span> <code class="t">;</code></span> then, return <span style="font-family:
+ sans-serif">empty</span>.</li>
+ <li>If IsStatic of <i>ClassElement</i> is <b>true</b>, return <span style="font-family: sans-serif">empty</span>.</li>
+ <li>If PropName of <i>ClassElement</i> is not <b><span style="font-family:
+ sans-serif">″</span><code>constructor</code><span style="font-family: sans-serif">″</span></b>, return
+ <span style="font-family: sans-serif">empty</span>.</li>
+ <li>Return <i>ClassElement</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Early Error rules ensure that there is only one method definition named <b><span
+ style="font-family: sans-serif">″</span><code>constructor</code><span style="font-family:
+ sans-serif">″</span></b> and that it is not an accessor property or generator definition.</p>
+ </div>
+ </section>
+
+ <section id="sec-class-definitions-static-semantics-contains">
+ <h1><span class="secnum" id="sec-14.5.4"><a href="#sec-class-definitions-static-semantics-contains"
+ title="link to this section">14.5.4</a></span> Static Semantics: Contains</h1>
+
+ <p>With parameter <var>symbol</var>.</p>
+
+ <p>See also: <a href="#sec-static-semantic-rules">5.3</a>, <a
+ href="#sec-object-initializer-static-semantics-computedpropertycontains">12.2.5.2</a>, <a
+ href="#sec-static-semantics-static-semantics-contains">12.3.1.1</a>, <a
+ href="#sec-function-definitions-static-semantics-contains">14.1.4</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-contains">14.2.3</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-computedpropertycontains">14.4.3</a></p>
+
+ <div class="gp prod"><span class="nt">ClassTail</span> <span class="geq">:</span> <span class="nt">ClassHeritage</span><sub>opt</sub> <code class="t">{</code> <span class="nt">ClassBody</span> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>If <i>symbol</i> is <i>ClassBody</i>, return <b>true</b>.</li>
+ <li>If <i>symbol</i> is <i>ClassHeritage</i>, then
+ <ol class="block">
+ <li>If <i>ClassHeritage</i> is present, return <b>true</b> otherwise return <b>false</b>.</li>
+ </ol>
+ </li>
+ <li>Let <i>inHeritage</i> be <i>ClassHeritage</i> Contains <i>symbol</i>.</li>
+ <li>If <i>inHeritage</i> is <b>true</b>, then return <b>true</b>.</li>
+ <li>Return the result of ComputedPropertyContains for <i>ClassBody</i> with argument <i>symbol</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Static semantic rules that depend upon substructure generally do not look into class
+ bodies except for <i>PropertyName</i> productions.</p>
+ </div>
+ </section>
+
+ <section id="sec-class-definitions-static-semantics-computedpropertycontains">
+ <h1><span class="secnum" id="sec-14.5.5"><a href="#sec-class-definitions-static-semantics-computedpropertycontains"
+ title="link to this section">14.5.5</a></span> Static Semantics: ComputedPropertyContains</h1>
+
+ <p>With parameter <var>symbol</var>.</p>
+
+ <p>See also: <a href="#sec-object-initializer-static-semantics-computedpropertycontains">12.2.5.2</a>, <a
+ href="#sec-method-definitions-static-semantics-computedpropertycontains">14.3.2</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-computedpropertycontains">14.4.3</a>.</p>
+
+ <div class="gp prod"><span class="nt">ClassElementList</span> <span class="geq">:</span> <span class="nt">ClassElementList</span> <span class="nt">ClassElement</span></div>
+ <ol class="proc">
+ <li>Let <i>inList</i> be the result of ComputedPropertyContains for <i>ClassElementList</i> with argument
+ <i>symbol.</i></li>
+ <li>If <i>inList</i> is <b>true</b>, then return <b>true</b>.</li>
+ <li>Return the result of ComputedPropertyContains for <i>ClassElement</i> with argument <i>symbol</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ClassElement</span> <span class="geq">:</span> <span class="nt">MethodDefinition</span></div>
+ <ol class="proc">
+ <li>Return the result of ComputedPropertyContains for <i>MethodDefinition</i> with argument <i>symbol</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ClassElement</span> <span class="geq">:</span> <code class="t">static</code> <span class="nt">MethodDefinition</span></div>
+ <ol class="proc">
+ <li>Return the result of ComputedPropertyContains for <i>MethodDefinition</i> with argument <i>symbol</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ClassElement</span> <span class="geq">:</span> <code class="t">;</code></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-class-definitions-static-semantics-hasname">
+ <h1><span class="secnum" id="sec-14.5.6"><a href="#sec-class-definitions-static-semantics-hasname"
+ title="link to this section">14.5.6</a></span> Static Semantics: HasName</h1>
+
+ <p>See also: <a href="#sec-function-definitions-static-semantics-hasname">14.1.8</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-hasname">14.2.8</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-hasname">14.4.6</a>.</p>
+
+ <div class="gp prod"><span class="nt">ClassExpression</span> <span class="geq">:</span> <code class="t">class</code> <span class="nt">ClassTail</span></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ClassExpression</span> <span class="geq">:</span> <code class="t">class</code> <span class="nt">BindingIdentifier</span> <span class="nt">ClassTail</span></div>
+ <ol class="proc">
+ <li>Return <b>true</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-class-definitions-static-semantics-isconstantdeclaration">
+ <h1><span class="secnum" id="sec-14.5.7"><a href="#sec-class-definitions-static-semantics-isconstantdeclaration"
+ title="link to this section">14.5.7</a></span> Static Semantics: IsConstantDeclaration</h1>
+
+ <p>See also: <a href="#sec-let-and-const-declarations-static-semantics-isconstantdeclaration">13.2.1.3</a>, <a
+ href="#sec-function-definitions-static-semantics-hasname">14.1.8</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-hascomputedpropertykey">14.4.5</a>.</p>
+
+ <div class="gp prod"><span class="nt">ClassDeclaration</span> <span class="geq">:</span> <code class="t">class</code> <span class="nt">BindingIdentifier</span> <span class="nt">ClassTail</span></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-class-definitions-static-semantics-isfunctiondefinition">
+ <h1><span class="secnum" id="sec-14.5.8"><a href="#sec-class-definitions-static-semantics-isfunctiondefinition"
+ title="link to this section">14.5.8</a></span> Static Semantics: IsFunctionDefinition</h1>
+
+ <p>See also: <a href="#sec-semantics-static-semantics-isfunctiondefinition">12.2.0.2</a>, <a
+ href="#sec-grouping-operator-static-semantics-isfunctiondefinition">12.2.10.2</a>, <a
+ href="#sec-static-semantics-static-semantics-isfunctiondefinition">12.3.1.2</a>, <a
+ href="#sec-postfix-expressions-static-semantics-isfunctiondefinition">12.4.2</a>, <a
+ href="#sec-unary-operators-static-semantics-isfunctiondefinition">12.5.2</a>, <a
+ href="#sec-multiplicative-operators-static-semantics-isfunctiondefinition">12.6.1</a>, <a
+ href="#sec-additive-operators-static-semantics-isfunctiondefinition">12.7.1</a>, <a
+ href="#sec-bitwise-shift-operators-static-semantics-isfunctiondefinition">12.8.1</a>, <a
+ href="#sec-relational-operators-static-semantics-isfunctiondefinition">12.9.1</a>, <a
+ href="#sec-equality-operators-static-semantics-isfunctiondefinition">12.10.1</a>, <a
+ href="#sec-binary-bitwise-operators-static-semantics-isfunctiondefinition">12.11.1</a>, <a
+ href="#sec-binary-logical-operators-static-semantics-isfunctiondefinition">12.12.1</a>, <a
+ href="#sec-conditional-operator-static-semantics-isfunctiondefinition">12.13.1</a>, <a
+ href="#sec-assignment-operators-static-semantics-isfunctiondefinition">12.14.2</a>, <a
+ href="#sec-comma-operator-static-semantics-isfunctiondefinition">12.15.1</a>, <a
+ href="#sec-function-definitions-static-semantics-isfunctiondefinition">14.1.11</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-isfunctiondefinition">14.4.8</a>.</p>
+
+ <div class="gp prod"><span class="nt">ClassExpression</span> <span class="geq">:</span> <code class="t">class</code> <span class="nt">ClassTail</span></div>
+ <ol class="proc">
+ <li>Return <b>true</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ClassExpression</span> <span class="geq">:</span> <code class="t">class</code> <span class="nt">BindingIdentifier</span> <span class="nt">ClassTail</span></div>
+ <ol class="proc">
+ <li>Return <b>true</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-static-semantics-isstatic">
+ <h1><span class="secnum" id="sec-14.5.9"><a href="#sec-static-semantics-isstatic"
+ title="link to this section">14.5.9</a></span> Static Semantics: IsStatic</h1>
+ <div class="gp prod"><span class="nt">ClassElement</span> <span class="geq">:</span> <span class="nt">MethodDefinition</span></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ClassElement</span> <span class="geq">:</span> <code class="t">static</code> <span class="nt">MethodDefinition</span></div>
+ <ol class="proc">
+ <li>Return <b>true</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ClassElement</span> <span class="geq">:</span> <code class="t">;</code></div>
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-class-definitions-static-semantics-lexicallydeclarednames">
+ <h1><span class="secnum" id="sec-14.5.10"><a href="#sec-class-definitions-static-semantics-lexicallydeclarednames"
+ title="link to this section">14.5.10</a></span> Static Semantics: LexicallyDeclaredNames</h1>
+
+ <p>See also: <a href="#sec-block-static-semantics-lexicallydeclarednames">13.1.3</a>, <a
+ href="#sec-switch-statement-static-semantics-lexicallydeclarednames">13.11.3</a>, <a
+ href="#sec-function-definitions-static-semantics-lexicallyscopeddeclarations">14.1.14</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-lexicallyscopeddeclarations">14.2.10</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-isfunctiondefinition">14.4.8</a>, <a
+ href="#sec-scripts-static-semantics-lexicallydeclarednames">15.1.3</a>, <a
+ href="#sec-module-static-semantics-static-semantics-lexicallydeclarednames">15.2.0.10</a>.</p>
+
+ <div class="gp prod"><span class="nt">ClassDeclaration</span> <span class="geq">:</span> <code class="t">class</code> <span class="nt">BindingIdentifier</span> <span class="nt">ClassTail</span></div>
+ <ol class="proc">
+ <li>Return the BoundNames of <i>BindingIdentifier</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-static-semantics-nonconstructormethoddefinitions">
+ <h1><span class="secnum" id="sec-14.5.11"><a href="#sec-static-semantics-nonconstructormethoddefinitions"
+ title="link to this section">14.5.11</a></span> Static Semantics: NonConstructorMethodDefinitions</h1>
+ <div class="gp prod"><span class="nt">ClassElementList</span> <span class="geq">:</span> <span class="nt">ClassElement</span></div>
+ <ol class="proc">
+ <li>If <i>ClassElement</i> is the production <span class="prod"><span class="nt">ClassElement</span> <span
+ class="geq">:</span> <code class="t">;</code></span> then, return a new empty <a
+ href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>If PropName of <i>ClassElement</i> is <b><span style="font-family:
+ sans-serif">″</span><code>constructor</code><span style="font-family: sans-serif">″</span></b>, return a
+ new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Return a <a href="#sec-list-and-record-specification-type">List</a> containing <i>ClassElement</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ClassElementList</span> <span class="geq">:</span> <span class="nt">ClassElementList</span> <span class="nt">ClassElement</span></div>
+ <ol class="proc">
+ <li>Let <i>list</i> be PrototypeMethodDefinitions of <i>ClassElementList.</i></li>
+ <li>If <i>ClassElement</i> is the production <span class="prod"><span class="nt">ClassElement</span> <span
+ class="geq">:</span> <code class="t">;</code></span> then, return <i>list</i>.</li>
+ <li>If IsStatic of <i>ClassElement</i> is <b>false</b> and PropName of <i>ClassElement</i> is <b><span style="font-family:
+ sans-serif">″</span><code>constructor</code><span style="font-family: sans-serif">″</span></b>, return
+ <i>list</i>.</li>
+ <li>Append <i>ClassElement</i> to the end of <i>list</i>.</li>
+ <li>Return <i>list</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-static-semantics-prototypepropertynamelist">
+ <h1><span class="secnum" id="sec-14.5.12"><a href="#sec-static-semantics-prototypepropertynamelist"
+ title="link to this section">14.5.12</a></span> Static Semantics: PrototypePropertyNameList</h1>
+ <div class="gp prod"><span class="nt">ClassElementList</span> <span class="geq">:</span> <span class="nt">ClassElement</span></div>
+ <ol class="proc">
+ <li>If PropName of <i>ClassElement</i> is <span style="font-family: sans-serif">empty</span>, return a new empty <a
+ href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>If IsStatic of <i>ClassElement</i> is <b>true</b>, return a new empty <a
+ href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Return a <a href="#sec-list-and-record-specification-type">List</a> containing PropName of <i>ClassElement</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ClassElementList</span> <span class="geq">:</span> <span class="nt">ClassElementList</span> <span class="nt">ClassElement</span></div>
+ <ol class="proc">
+ <li>Let <i>list</i> be PrototypePropertyNameList of <i>ClassElementList.</i></li>
+ <li>If PropName of <i>ClassElement</i> is <span style="font-family: sans-serif">empty</span>, return <i>list</i>.</li>
+ <li>If IsStatic of <i>ClassElement</i> is <b>true</b>, return <i>list</i>.</li>
+ <li>Append PropName of <i>ClassElement</i> to the end of <i>list</i>.</li>
+ <li>Return <i>list</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-class-definitions-static-semantics-propname">
+ <h1><span class="secnum" id="sec-14.5.13"><a href="#sec-class-definitions-static-semantics-propname"
+ title="link to this section">14.5.13</a></span> Static Semantics: PropName</h1>
+
+ <p><b>See also:</b> <a href="#sec-object-initializer-static-semantics-propname">12.2.5.6</a>, <a
+ href="#sec-method-definitions-static-semantics-propname">14.3.5</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-propname">14.4.10</a></p>
+
+ <div class="gp prod"><span class="nt">ClassElement</span> <span class="geq">:</span> <code class="t">;</code></div>
+ <ol class="proc">
+ <li>Return <span style="font-family: sans-serif">empty</span>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-static-semantics-staticpropertynamelist">
+ <h1><span class="secnum" id="sec-14.5.14"><a href="#sec-static-semantics-staticpropertynamelist"
+ title="link to this section">14.5.14</a></span> Static Semantics: StaticPropertyNameList</h1>
+ <div class="gp prod"><span class="nt">ClassElementList</span> <span class="geq">:</span> <span class="nt">ClassElement</span></div>
+ <ol class="proc">
+ <li>If PropName of <i>ClassElement</i> is <span style="font-family: sans-serif">empty</span>, return a new empty <a
+ href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>If IsStatic of <i>ClassElement</i> is <b>false</b>, return a new empty <a
+ href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Return a <a href="#sec-list-and-record-specification-type">List</a> containing PropName of <i>ClassElement</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ClassElementList</span> <span class="geq">:</span> <span class="nt">ClassElementList</span> <span class="nt">ClassElement</span></div>
+ <ol class="proc">
+ <li>Let <i>list</i> be StaticPropertyNameList of <i>ClassElementList.</i></li>
+ <li>If PropName of <i>ClassElement</i> is <span style="font-family: sans-serif">empty</span>, return <i>list</i>.</li>
+ <li>If IsStatic of <i>ClassElement</i> is <b>false</b>, return <i>list</i>.</li>
+ <li>Append PropName of <i>ClassElement</i> to the end of <i>list</i>.</li>
+ <li>Return <i>list</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-class-definitions-static-semantics-vardeclarednames">
+ <h1><span class="secnum" id="sec-14.5.15"><a href="#sec-class-definitions-static-semantics-vardeclarednames"
+ title="link to this section">14.5.15</a></span> Static Semantics: VarDeclaredNames</h1>
+
+ <p>See also: <a href="#sec-statement-semantics-static-semantics-vardeclarednames">13.0.1</a>, <a
+ href="#sec-block-static-semantics-vardeclarednames">13.1.8</a>, <a
+ href="#sec-variable-statement-static-semantics-vardeclarednames">13.2.2.2</a>, <a
+ href="#sec-if-statement-static-semantics-vardeclarednames">13.5.1</a>, <a
+ href="#sec-do-while-statement-static-semantics-vardeclarednames">13.6.1.1</a>, <a
+ href="#sec-while-statement-static-semantics-vardeclarednames">13.6.2.1</a>, <a
+ href="#sec-for-statement-static-semantics-vardeclarednames">13.6.3.1</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-vardeclarednames">13.6.4.3</a>, <a
+ href="#sec-with-statement-static-semantics-vardeclarednames">13.10.2</a>, <a
+ href="#sec-switch-statement-static-semantics-vardeclarednames">13.11.4</a>, <a
+ href="#sec-static-semantics-currentlabelset">13.12.2</a>, <a
+ href="#sec-try-statement-static-semantics-vardeclarednames">13.14.2</a>, <a
+ href="#sec-function-definitions-static-semantics-referencessuper">14.1.16</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-vardeclarednames">14.4.12</a>, <a
+ href="#sec-scripts-static-semantics-vardeclarednames">15.1.5</a>, <a
+ href="#sec-module-static-semantics-static-semantics-vardeclarednames">15.2.0.13</a>.</p>
+
+ <p><span class="prod"><span class="nt">ClassDeclaration</span> <span class="geq">:</span> <code class="t">class</code> <span
+ class="nt">BindingIdentifier</span> <span class="nt">ClassTail</span></span></p>
+
+ <ol class="proc">
+ <li>Return an empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-runtime-semantics-classdefinitionevaluation">
+ <h1><span class="secnum" id="sec-14.5.16"><a href="#sec-runtime-semantics-classdefinitionevaluation"
+ title="link to this section">14.5.16</a></span> Runtime Semantics: ClassDefinitionEvaluation</h1>
+
+ <p>With parameter <var>className</var>.</p>
+
+ <div class="gp prod"><span class="nt">ClassTail</span> <span class="geq">:</span> <span class="nt">ClassHeritage</span><sub>opt</sub> <code class="t">{</code> <span class="nt">ClassBody</span><sub>opt</sub> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>If <i>ClassHeritage</i><sub>opt</sub> is not present, then
+ <ol class="block">
+ <li>Let <i>protoParent</i> be the intrinsic object %ObjectPrototype%.</li>
+ <li>Let <i>constructorParent</i> be the intrinsic object %FunctionPrototype%.</li>
+ </ol>
+ </li>
+ <li>Else
+ <ol class="block">
+ <li>Let <i>superclass</i> be the result of evaluating <i>ClassHeritage</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>superclass</i>).</li>
+ <li>If <i>superclass</i> is <b>null</b>, then
+ <ol class="block">
+ <li>Let <i>protoParent</i> be <b>null</b>.</li>
+ <li>Let <i>constructorParent</i> be the intrinsic object %FunctionPrototype%.</li>
+ </ol>
+ </li>
+ <li>Else if <a href="#sec-isconstructor">IsConstructor</a>(<i>superclass</i>) is <b>false</b>, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>Else
+ <ol class="block">
+ <li>Let <i>protoParent</i> be <a href="#sec-get-o-p">Get</a>(<i>superclass</i>, <code>"prototype"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>protoParent</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>protoParent</i>) is neither Object nor Null,
+ throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>constructorParent</i> be <i>superclass</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Let <i>proto</i> be <a href="#sec-objectcreate">ObjectCreate</a>(<i>protoParent</i>).</li>
+ <li>Let <i>lex</i> be the <a href="#sec-execution-contexts">LexicalEnvironment</a> of <a
+ href="#sec-execution-contexts">the running execution context</a>.</li>
+ <li>If <i>className</i> is not <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>scope</i> be <a href="#sec-newdeclarativeenvironment">NewDeclarativeEnvironment</a>(<i>lex</i>).</li>
+ <li>Let <i>envRec</i> be <i>scope’s</i> environment record.</li>
+ <li>Call the CreateImmutableBinding concrete method of <i>envRec</i> passing <i>className</i> as the argument.</li>
+ <li>Set <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-execution-contexts">LexicalEnvironment</a> to <i>scope</i>.</li>
+ </ol>
+ </li>
+ <li>If <i>ClassBody</i><sub>opt</sub> is not present, then let <i>constructor</i> be <span style="font-family:
+ sans-serif">empty</span>.</li>
+ <li>Else, let <i>constructor</i> be ConstructorMethod of <i>ClassBody</i>.</li>
+ <li>If <i>constructor</i> is <span style="font-family: sans-serif">empty</span>, then
+ <ol class="block">
+ <li>If <i>ClassHeritage</i><sub>opt</sub> is present, then
+ <ol class="block">
+ <li>Let <i>constructor</i> be the result of parsing the String <code>"constructor(... args){ super</code>
+ <code>(...args);}"</code> using the syntactic grammar with the goal symbol <i>MethodDefinition.</i></li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>constructor</i> be the result of parsing the String <code>"constructor( ){ }"</code> using the
+ syntactic grammar with the goal symbol <i>MethodDefinition.</i></li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Let <i>strict</i> be <b>true</b>.</li>
+ <li>Let <i>constructorInfo</i> be the result of performing DefineMethod for <i>constructor</i> with arguments <i>proto</i>
+ and <i>constructorParent</i> as the optional <i>functionPrototype</i> argument.</li>
+ <li>Let <i>F</i> be <i>constructorInfo</i>.[[closure]]</li>
+ <li>Perform the abstract operation <a href="#sec-makeconstructor">MakeConstructor</a> with argument <i>F</i> and
+ <b>false</b> as the optional <i>writablePrototype</i> argument and <i>proto</i> as the optional <i>prototype</i>
+ argument.</li>
+ <li>Let <i>desc</i> be the PropertyDescriptor{[[Value]]: <i>F</i>, [[Writable]]: <b>true</b>, [[Enumerable]]:
+ <b>false</b>, [[Configurable]]: <b>true</b>}.</li>
+ <li>Call the [[DefineOwnProperty]] internal method of <i>proto</i> with arguments <code>"constructor"</code> and
+ <i>desc.</i></li>
+ <li>If <i>ClassBody</i><sub>opt</sub> is not present, then let <i>methods</i> be a new empty <a
+ href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Else, let <i>methods</i> be NonConstructorMethodDefinitions of <i>ClassBody</i>.</li>
+ <li>For each <i>MethodDefinition</i> <i>m</i> in order from <i>methods</i>
+ <ol class="block">
+ <li>If IsStatic of <i>m</i> is <b>false</b>, then
+ <ol class="block">
+ <li>Let <i>status</i> be the result of performing PropertyDefinitionEvaluation for <i>m</i> with argument
+ <i>proto</i>.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>status</i> be the result of performing PropertyDefinitionEvaluation for <i>s</i> with argument
+ <i>F</i>.</li>
+ </ol>
+ </li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ </ol>
+ </li>
+ <li>Set <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-execution-contexts">LexicalEnvironment</a> to <i>lex</i>.</li>
+ <li>If <i>className</i> is not <b>undefined</b>, then
+ <ol class="block">
+ <li>Call the InitializeBinding concrete method of <i>envRec</i> passing <i>className</i> and <i>F</i> as the
+ arguments.</li>
+ </ol>
+ </li>
+ <li>Return <i>F</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-class-definitions-runtime-semantics-evaluation">
+ <h1><span class="secnum" id="sec-14.5.17"><a href="#sec-class-definitions-runtime-semantics-evaluation"
+ title="link to this section">14.5.17</a></span> Runtime Semantics: Evaluation</h1>
+ <div class="gp prod"><span class="nt">ClassDeclaration</span> <span class="geq">:</span> <code class="t">class</code> <span class="nt">BindingIdentifier</span> <span class="nt">ClassTail</span></div>
+ <ol class="proc">
+ <li>Let <i>className</i> be StringValue(<i>BindingIdentifier</i>).</li>
+ <li>Let <i>value</i> be the result of ClassDefinitionEvaluation of <i>ClassTail</i> with argument <i>className</i></li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>value</i>).</li>
+ <li>Let <i>hasNameProperty</i> be <a href="#sec-hasownproperty">HasOwnProperty</a>(<i>value</i>,
+ <code>"name"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>hasNameProperty</i>).</li>
+ <li>If <i>hasNameProperty</i> is <b>false</b>, then
+ <ol class="block">
+ <li>Perform <a href="#sec-setfunctionname">SetFunctionName</a>(<i>value</i>, <i>className</i>).</li>
+ </ol>
+ </li>
+ <li>Let <i>env</i> be <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-execution-contexts">LexicalEnvironment</a>.</li>
+ <li>Let <i>status</i> be the result of performing BindingInitialization for <i>BindingIdentifier</i> passing <i>value</i>
+ and <i>env</i> as the arguments.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<span style="font-family: sans-serif">empty</span>).</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ClassExpression</span> <span class="geq">:</span> <code class="t">class</code> <span class="nt">BindingIdentifier</span><sub>opt</sub> <span class="nt">ClassTail</span></div>
+ <ol class="proc">
+ <li>If <i>BindingIdentifier</i><sub>opt</sub> is not present, then let <i>className</i> be <b>undefined</b>.</li>
+ <li>Else, let <i>className</i> be StringValue(<i>BindingIdentifier</i>).</li>
+ <li>Let <i>value</i> be the result of ClassDefinitionEvaluation of <i>ClassTail</i> with argument <i>className</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>value</i>).</li>
+ <li>If <i>className</i> is not <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>hasNameProperty</i> be <a href="#sec-hasownproperty">HasOwnProperty</a>(<i>value</i>,
+ <code>"name"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>hasNameProperty</i>).</li>
+ <li>If <i>hasNameProperty</i> is <b>false</b>, then
+ <ol class="block">
+ <li>Perform <a href="#sec-setfunctionname">SetFunctionName</a>(<i>value</i>, <i>className</i>).</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<i>value</i>).</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-tail-position-calls">
+ <div class="front">
+ <h1><span class="secnum" id="sec-14.6"><a href="#sec-tail-position-calls" title="link to this section">14.6</a></span> Tail
+ Position Calls</h1>
+ </div>
+
+ <section id="sec-isintailposition">
+ <h1><span class="secnum" id="sec-14.6.1"><a href="#sec-isintailposition" title="link to this section">14.6.1</a></span>
+ Static Semantics: IsInTailPosition(nonterminal) Abstract Operation</h1>
+
+ <p>The abstract operation IsInTailPosition with argument <var>nonterminal</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>nonterminal</i> is a parsed grammar production.</li>
+ <li>If the source code matching <i>nonterminal</i> is not <a href="#sec-strict-mode-code">strict code</a>, then return
+ <b>false.</b></li>
+ <li>If <i>nonterminal</i> is not contained within a <i>FunctionBody</i> or <i>ConciseBody</i>, then return
+ <b>false</b>.</li>
+ <li>Let <i>body</i> be the <i>FunctionBody</i> or <i>ConciseBody</i> that most closely contains <i>nonterminal</i>.</li>
+ <li>If <i>body</i> is the <i>FunctionBody</i> of a <i>GeneratorMethod</i>, <i>GeneratorDeclaration</i>, or a
+ <i>GeneratorExpression</i>, then return <b>false</b>.</li>
+ <li>Return the result of HasProductionInTailPosition of <i>body</i> with argument <i>nonterminal</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Tail Position calls are only defined in <a href="#sec-strict-mode-code">strict mode
+ code</a> because of a common non-standard language extension (<a href="#sec-addrestrictedfunctionproperties">see
+ 9.2.8</a>) that enables observation of the chain of caller contexts.</p>
+ </div>
+ </section>
+
+ <section id="sec-static-semantics-hasproductionintailposition">
+ <div class="front">
+ <h1><span class="secnum" id="sec-14.6.2"><a href="#sec-static-semantics-hasproductionintailposition"
+ title="link to this section">14.6.2</a></span> Static Semantics: HasProductionInTailPosition</h1>
+
+ <p>With parameter <var>nonterminal</var>.</p>
+ </div>
+
+ <section id="sec-statement-rules">
+ <h1><span class="secnum" id="sec-14.6.2.1"><a href="#sec-statement-rules" title="link to this section">14.6.2.1</a></span>
+ Statement Rules</h1>
+ <div class="gp prod"><span class="nt">ConciseBody</span> <span class="geq">:</span> <span class="nt">AssignmentExpression</span></div>
+ <ol class="proc">
+ <li>Return HasProductionInTailPosition of <i>AssignmentExpression</i> with argument <i>nonterminal</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">StatementList</span> <span class="geq">:</span> <span class="nt">StatementList</span> <span class="nt">StatementListItem</span></div>
+ <ol class="proc">
+ <li>Let <i>has</i> be HasProductionInTailPosition of <i>StatementList</i> with argument <i>nonterminal</i>.</li>
+ <li>If <i>has</i> is <b>true,</b> then return <b>true</b>.</li>
+ <li>Return HasProductionInTailPosition of <i>StatementListItem</i> with argument <i>nonterminal</i>.</li>
+ </ol>
+
+ <p><span class="prod"><span class="nt">FunctionStatementList</span> <span class="geq">:</span> <span
+ class="grhsannot">[empty]</span></span></p>
+
+ <p><span class="prod"><span class="nt">StatementListItem</span> <span class="geq">:</span> <span
+ class="nt">Declaration</span></span></p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">Statement</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">VariableStatement</span></div>
+ <div class="rhs"><span class="nt">EmptyStatement</span></div>
+ <div class="rhs"><span class="nt">ExpressionStatement</span></div>
+ <div class="rhs"><span class="nt">ContinueStatement</span></div>
+ <div class="rhs"><span class="nt">BreakStatement</span></div>
+ <div class="rhs"><span class="nt">ThrowStatement</span></div>
+ <div class="rhs"><span class="nt">DebuggerStatement</span></div>
+ <div class="rhs"><span class="nt">Block</span> <code class="t">:</code> <code class="t">{</code> <code class="t">}</code></div>
+ <div class="rhs"><span class="nt">ReturnStatement</span> <code class="t">:</code> <code class="t">return</code> <code class="t">;</code></div>
+ <div class="rhs"><span class="nt">CaseBlock</span> <code class="t">:</code> <code class="t">{</code> <code class="t">}</code></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">IfStatement</span> <span class="geq">:</span> <code class="t">if</code> <code class="t">(</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">Statement</span> <code class="t">else</code> <span class="nt">Statement</span></div>
+ <ol class="proc">
+ <li>Let <i>has</i> be HasProductionInTailPosition of the first <i>Statement</i> with argument <i>nonterminal</i>.</li>
+ <li>If <i>has</i> is <b>true,</b> then return <b>true</b>.</li>
+ <li>Return HasProductionInTailPosition of the second <i>Statement</i> with argument <i>nonterminal</i>.</li>
+ </ol>
+
+ <p><span class="prod"><span class="nt">IfStatement</span> <span class="geq">:</span> <code class="t">if</code> <code
+ class="t">(</code> <span class="nt">Expression</span> <code class="t">)</code> <span
+ class="nt">Statement</span></span></p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">IterationStatement</span> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">do</code> <span class="nt">Statement</span> <code class="t">while</code> <code class="t">(</code> <span class="nt">Expression</span> <code class="t">)</code> <code class="t">;</code><sub>opt</sub></div>
+ <div class="rhs"><code class="t">while</code> <code class="t">(</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <div class="rhs"><code class="t">for</code> <code class="t">(</code> <span class="nt">Expression</span><sub>opt</sub> <code class="t">;</code> <span class="nt">Expression</span><sub>opt</sub> <code class="t">;</code> <span class="nt">Expression</span><sub>opt</sub> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <div class="rhs"><code class="t">for</code> <code class="t">(</code> <code class="t">var</code> <span class="nt">VariableDeclarationList</span> <code class="t">;</code> <span class="nt">Expression</span><sub>opt</sub> <code class="t">;</code> <span class="nt">Expression</span><sub>opt</sub> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <div class="rhs"><code class="t">for</code> <code class="t">(</code> <span class="nt">LexicalDeclaration</span> <span class="nt">Expression</span><sub>opt</sub> <code class="t">;</code> <span class="nt">Expression</span><sub>opt</sub> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <div class="rhs"><code class="t">for</code> <code class="t">(</code> <span class="nt">LeftHandSideExpression</span> <code class="t">in</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <div class="rhs"><code class="t">for</code> <code class="t">(</code> <code class="t">var</code> <span class="nt">ForBinding</span> <code class="t">in</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <div class="rhs"><code class="t">for</code> <code class="t">(</code> <span class="nt">ForDeclaration</span> <code class="t">in</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <div class="rhs"><code class="t">for</code> <code class="t">(</code> <span class="nt">LeftHandSideExpression</span> <code class="t">of</code> <span class="nt">AssignmentExpression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <div class="rhs"><code class="t">for</code> <code class="t">(</code> <code class="t">var</code> <span class="nt">ForBinding</span> <code class="t">of</code> <span class="nt">AssignmentExpression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <div class="rhs"><code class="t">for</code> <code class="t">(</code> <span class="nt">ForDeclaration</span> <code class="t">of</code> <span class="nt">AssignmentExpression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <div class="rhs"><span class="nt">WithStatement</span> <code class="t">:</code> <code class="t">with</code> <code class="t">(</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">LabelledStatement</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">LabelIdentifier</span> <code class="t">:</code> <span class="nt">Statement</span></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return HasProductionInTailPosition of <i>Statement</i> with argument <i>nonterminal</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ReturnStatement</span> <span class="geq">:</span> <code class="t">return</code> <span class="nt">Expression</span> <code class="t">;</code></div>
+ <ol class="proc">
+ <li>Return HasProductionInTailPosition of <i>Expression</i> with argument <i>nonterminal</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">SwitchStatement</span> <span class="geq">:</span> <code class="t">switch</code> <code class="t">(</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">CaseBlock</span></div>
+ <ol class="proc">
+ <li>Return HasProductionInTailPosition of <i>CaseBlock</i> with argument <i>nonterminal</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">CaseBlock</span> <span class="geq">:</span> <code class="t">{</code> <span class="nt">CaseClauses</span><sub>opt</sub> <span class="nt">DefaultClause</span> <span class="nt">CaseClauses</span><sub>opt</sub> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Let <i>has</i> be <b>false</b>.</li>
+ <li>If the first <i>CaseClauses</i> is present, let <i>has</i> be HasProductionInTailPosition of the first
+ <i>CaseClauses</i> with argument <i>nonterminal</i>.</li>
+ <li>If <i>has</i> is <b>true,</b> then return <b>true</b>.</li>
+ <li>Let <i>has</i> be HasProductionInTailPosition of the <i>DefaultClause</i> with argument <i>nonterminal</i>.</li>
+ <li>If <i>has</i> is <b>true,</b> then return <b>true</b>.</li>
+ <li>If the second <i>CaseClauses</i> is present, let <i>has</i> be HasProductionInTailPosition of the second
+ <i>CaseClauses</i> with argument <i>nonterminal</i>.</li>
+ <li>Return <i>has</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">CaseClauses</span> <span class="geq">:</span> <span class="nt">CaseClauses</span> <span class="nt">CaseClause</span></div>
+ <ol class="proc">
+ <li>Let <i>has</i> be HasProductionInTailPosition of <i>CaseClauses</i> with argument <i>nonterminal</i>.</li>
+ <li>If <i>has</i> is <b>true,</b> then return <b>true</b>.</li>
+ <li>Return HasProductionInTailPosition of <i>CaseClause</i> with argument <i>nonterminal</i>.</li>
+ </ol>
+
+ <p><span class="prod"><span class="nt">CaseClause</span> <span class="geq">:</span> <code class="t">case</code> <span
+ class="nt">Expression</span> <code class="t">:</code> <span class="nt">StatementList</span><sub>opt</sub></span></p>
+
+ <div class="gp prod"><span class="nt">DefaultClause</span> <span class="geq">:</span> <code class="t">default</code> <code class="t">:</code> <span class="nt">StatementList</span><sub>opt</sub></div>
+ <ol class="proc">
+ <li>If <i>StatementList</i> is present, return HasProductionInTailPosition of <i>StatementList</i> with argument
+ <i>nonterminal</i>.</li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">TryStatement</span> <span class="geq">:</span> <code class="t">try</code> <span class="nt">Block</span> <span class="nt">Catch</span></div>
+ <ol class="proc">
+ <li>Return HasProductionInTailPosition of <i>Catch</i> with argument <i>nonterminal</i>.</li>
+ </ol>
+
+ <p><span class="prod"><span class="nt">TryStatement</span> <span class="geq">:</span> <code class="t">try</code> <span
+ class="nt">Block</span> <span class="nt">Finally</span></span></p>
+
+ <div class="gp prod"><span class="nt">TryStatement</span> <span class="geq">:</span> <code class="t">try</code> <span class="nt">Block</span> <span class="nt">Catch</span> <span class="nt">Finally</span></div>
+ <ol class="proc">
+ <li>Return HasProductionInTailPosition of <i>Finally</i> with argument <i>nonterminal</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">Catch</span> <span class="geq">:</span> <code class="t">catch</code> <code class="t">(</code> <span class="nt">CatchParameter</span> <code class="t">)</code> <span class="nt">Block</span></div>
+ <ol class="proc">
+ <li>Return HasProductionInTailPosition of <i>Block</i> with argument <i>nonterminal</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-expression-rules">
+ <h1><span class="secnum" id="sec-14.6.2.2"><a href="#sec-expression-rules"
+ title="link to this section">14.6.2.2</a></span> Expression Rules</h1>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> A potential tail position call that is immediately followed by return <a
+ href="#sec-getvalue">GetValue</a> of the call result is also a possible tail position call. Functional calls cannot
+ return reference values, so such a <a href="#sec-getvalue">GetValue</a> operation will always returns the same value as
+ the actual function call result.</p>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">AssignmentExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">YieldExpression</span></div>
+ <div class="rhs"><span class="nt">ArrowFunction</span></div>
+ <div class="rhs"><span class="nt">LeftHandSideExpression</span> <code class="t">=</code> <span class="nt">AssignmentExpression</span></div>
+ <div class="rhs"><span class="nt">LeftHandSideExpression</span> <span class="nt">AssignmentOperator</span> <span class="nt">AssignmentExpression</span></div>
+ <div class="rhs"><span class="nt">BitwiseANDExpression</span> <code class="t">:</code> <span class="nt">BitwiseANDExpression</span> <code class="t">&</code> <span class="nt">EqualityExpression</span></div>
+ <div class="rhs"><span class="nt">BitwiseXORExpression</span> <code class="t">:</code> <span class="nt">BitwiseXORExpression</span> <code class="t">^</code> <span class="nt">BitwiseANDExpression</span></div>
+ <div class="rhs"><span class="nt">BitwiseORExpression</span> <code class="t">:</code> <span class="nt">BitwiseORExpression</span> <code class="t">|</code> <span class="nt">BitwiseXORExpression</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">EqualityExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">EqualityExpression</span> <code class="t">==</code> <span class="nt">RelationalExpression</span></div>
+ <div class="rhs"><span class="nt">EqualityExpression</span> <code class="t">!=</code> <span class="nt">RelationalExpression</span></div>
+ <div class="rhs"><span class="nt">EqualityExpression</span> <code class="t">===</code> <span class="nt">RelationalExpression</span></div>
+ <div class="rhs"><span class="nt">EqualityExpression</span> <code class="t">!==</code> <span class="nt">RelationalExpression</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">RelationalExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">RelationalExpression</span> <code class="t"><</code> <span class="nt">ShiftExpression</span></div>
+ <div class="rhs"><span class="nt">RelationalExpression</span> <code class="t">></code> <span class="nt">ShiftExpression</span></div>
+ <div class="rhs"><span class="nt">RelationalExpression</span> <code class="t"><=</code> <span class="nt">ShiftExpression</span></div>
+ <div class="rhs"><span class="nt">RelationalExpression</span> <code class="t">>=</code> <span class="nt">ShiftExpression</span></div>
+ <div class="rhs"><span class="nt">RelationalExpression</span> <code class="t">instanceof</code> <span class="nt">ShiftExpression</span></div>
+ <div class="rhs"><span class="nt">RelationalExpression</span> <code class="t">in</code> <span class="nt">ShiftExpression</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ShiftExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">ShiftExpression</span> <code class="t"><<</code> <span class="nt">AdditiveExpression</span></div>
+ <div class="rhs"><span class="nt">ShiftExpression</span> <code class="t">>></code> <span class="nt">AdditiveExpression</span></div>
+ <div class="rhs"><span class="nt">ShiftExpression</span> <code class="t">>>></code> <span class="nt">AdditiveExpression</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">AdditiveExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">AdditiveExpression</span> <code class="t">+</code> <span class="nt">MultiplicativeExpression</span></div>
+ <div class="rhs"><span class="nt">AdditiveExpression</span> <code class="t">-</code> <span class="nt">MultiplicativeExpression</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">MultiplicativeExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">MultiplicativeExpression</span> <code class="t">*</code> <span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><span class="nt">MultiplicativeExpression</span> <code class="t">/</code> <span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><span class="nt">MultiplicativeExpression</span> <code class="t">%</code> <span class="nt">UnaryExpression</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">UnaryExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">delete</code> <span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><code class="t">void</code> <span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><code class="t">typeof</code> <span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><code class="t">++</code> <span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><code class="t">--</code> <span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><code class="t">+</code> <span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><code class="t">-</code> <span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><code class="t">~</code> <span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><code class="t">!</code> <span class="nt">UnaryExpression</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">PostfixExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">LeftHandSideExpression</span> <code class="t">++</code></div>
+ <div class="rhs"><span class="nt">LeftHandSideExpression</span> <code class="t">--</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">CallExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">CallExpression</span> <code class="t">[</code> <span class="nt">Expression</span> <code class="t">]</code></div>
+ <div class="rhs"><span class="nt">CallExpression</span> <code class="t">.</code> <span class="nt">IdentifierName</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">MemberExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">MemberExpression</span> <code class="t">[</code> <span class="nt">Expression</span> <code class="t">]</code></div>
+ <div class="rhs"><span class="nt">MemberExpression</span> <code class="t">.</code> <span class="nt">IdentifierName</span></div>
+ <div class="rhs"><code class="t">super</code> <code class="t">[</code> <span class="nt">Expression</span> <code class="t">]</code></div>
+ <div class="rhs"><code class="t">super</code> <code class="t">.</code> <span class="nt">IdentifierName</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">PrimaryExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">this</code></div>
+ <div class="rhs"><span class="nt">IdentifierReference</span></div>
+ <div class="rhs"><span class="nt">Literal</span></div>
+ <div class="rhs"><span class="nt">ArrayInitializer</span></div>
+ <div class="rhs"><span class="nt">ObjectLiteral</span></div>
+ <div class="rhs"><span class="nt">FunctionExpression</span></div>
+ <div class="rhs"><span class="nt">ClassExpression</span></div>
+ <div class="rhs"><span class="nt">GeneratorExpression</span></div>
+ <div class="rhs"><span class="nt">GeneratorComprehension</span></div>
+ <div class="rhs"><span class="nt">RegularExpressionLiteral</span></div>
+ <div class="rhs"><span class="nt">TemplateLiteral</span></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return <b>false</b>.</li>
+ </ol>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">Expression</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">AssignmentExpression</span></div>
+ <div class="rhs"><span class="nt">Expression</span> <code class="t">,</code> <span class="nt">AssignmentExpression</span></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return HasProductionInTailPosition of <i>AssignmentExpression</i> with argument <i>nonterminal</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ConditionalExpression</span> <span class="geq">:</span> <span class="nt">LogicalORExpression</span> <code class="t">?</code> <span class="nt">AssignmentExpression</span> <code class="t">:</code> <span class="nt">AssignmentExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>has</i> be HasProductionInTailPosition of the first <i>AssignmentExpression</i> with argument
+ <i>nonterminal</i>.</li>
+ <li>If <i>has</i> is <b>true,</b> then return <b>true</b>.</li>
+ <li>Return HasProductionInTailPosition of the second <i>AssignmentExpression</i> with argument <i>nonterminal</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">LogicalANDExpression</span> <span class="geq">:</span> <span class="nt">LogicalANDExpression</span> <code class="t">&&</code> <span class="nt">BitwiseORExpression</span></div>
+ <ol class="proc">
+ <li>Return HasProductionInTailPosition of <i>BitwiseORExpression</i> with argument <i>nonterminal</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">LogicalORExpression</span> <span class="geq">:</span> <span class="nt">LogicalORExpression</span> <code class="t">||</code> <span class="nt">LogicalANDExpression</span></div>
+ <ol class="proc">
+ <li>Return HasProductionInTailPosition of <i>LogicalANDExpression</i> with argument <i>nonterminal</i>.</li>
+ </ol>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">CallExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">MemberExpression</span> <span class="nt">Arguments</span></div>
+ <div class="rhs"><code class="t">super</code> <span class="nt">Arguments</span></div>
+ <div class="rhs"><span class="nt">CallExpression</span> <span class="nt">Arguments</span></div>
+ <div class="rhs"><span class="nt">CallExpression</span> <span class="nt">TemplateLiteral</span></div>
+ </div>
+
+ <ol class="proc">
+ <li>If this <i>CallExpression</i> is <i>nonterminal</i><b>,</b> then return <b>true</b>.</li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">MemberExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">MemberExpression</span> <span class="nt">TemplateLiteral</span></div>
+ <div class="rhs"><code class="t">new</code> <code class="t">super</code> <span class="nt">Arguments</span></div>
+ <div class="rhs"><code class="t">new</code> <span class="nt">MemberExpression</span> <span class="nt">Arguments</span></div>
+ </div>
+
+ <ol class="proc">
+ <li>If this <i>MemberExpression</i> is <i>nonterminal</i><b>,</b> then return <b>true</b>.</li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">NewExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">new</code> <span class="nt">NewExpression</span></div>
+ <div class="rhs"><code class="t">new</code> <code class="t">super</code></div>
+ </div>
+
+ <ol class="proc">
+ <li>If this <i>NewExpression</i> is <i>nonterminal</i><b>,</b> then return <b>true</b>.</li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">PrimaryExpression</span> <span class="geq">:</span> <span class="nt">CoverParenthesizedExpressionAndArrowParameterList</span></div>
+ <ol class="proc">
+ <li>Let <i>expr</i> be CoveredParenthesizedExpression of <i>CoverParenthesizedExpressionAndArrowParameterList</i>.</li>
+ <li>Return HasProductionInTailPosition of <i>expr</i> with argument <i>nonterminal</i>.</li>
+ </ol>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ParenthesizedExpression</span> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">(</code> <span class="nt">Expression</span> <code class="t">)</code></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return HasProductionInTailPosition of <i>Expression</i> with argument <i>nonterminal</i>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-preparefortailcall">
+ <h1><span class="secnum" id="sec-14.6.3"><a href="#sec-preparefortailcall" title="link to this section">14.6.3</a></span>
+ Runtime Semantics: PrepareForTailCall ( )</h1>
+
+ <p>The abstract operation PrepareForTailCall performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>leafContext</i> be <a href="#sec-execution-contexts">the running execution context</a>.</li>
+ <li><a href="#sec-execution-contexts">Suspend</a> <i>leafContext</i>.</li>
+ <li>Pop <i>leafContext</i> from the <a href="#sec-execution-contexts">execution context context stack</a>. The <a
+ href="#sec-execution-contexts">execution context</a> now on the top of the stack becomes <a
+ href="#sec-execution-contexts">the running execution context</a>, however it remains in its <a
+ href="#sec-execution-contexts">suspended</a> state.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>leafContext</i> has no further use. It will never be activated as
+ <a href="#sec-execution-contexts">the running execution context</a>.</li>
+ </ol>
+
+ <p>A tail position call must either release any transient internal resources associated with the currently executing
+ function <a href="#sec-execution-contexts">execution context</a> before invoking the target function or reuse those
+ resources in support of the target function.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> For example, a tail position call should only grow an implementation’s activation
+ record stack by the amount that the size of the target function’s activation record exceeds the size of the calling
+ function’s activation record. If the target function’s activation record is smaller, then the total size of
+ the stack should decrease.</p>
+ </div>
+ </section>
+ </section>
+</section>
+
+<section id="sec-ecmascript-language-scripts-and-modules">
+ <div class="front">
+ <h1><span class="secnum" id="sec-15"><a href="#sec-ecmascript-language-scripts-and-modules"
+ title="link to this section">15</a></span> ECMAScript Language: Scripts and Modules</h1>
+ </div>
+
+ <section id="sec-scripts">
+ <div class="front">
+ <h1><span class="secnum" id="sec-15.1"><a href="#sec-scripts" title="link to this section">15.1</a></span> Scripts</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">Script</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">ScriptBody</span><sub>opt</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ScriptBody</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">StatementList</span></div>
+ </div>
+ </div>
+
+ <section id="sec-scripts-static-semantics-early-errors">
+ <h1><span class="secnum" id="sec-15.1.1"><a href="#sec-scripts-static-semantics-early-errors"
+ title="link to this section">15.1.1</a></span> Static Semantics: Early Errors</h1>
+ <div class="gp prod"><span class="nt">ScriptBody</span> <span class="geq">:</span> <span class="nt">StatementList</span></div>
+ <ul>
+ <li>
+ <p>It is a Syntax Error if the LexicallyDeclaredNames of <span class="nt">StatementList</span> contains any duplicate
+ entries.</p>
+ </li>
+
+ <li>
+ <p>It is a Syntax Error if any element of the <span style="font-family: Times New Roman">LexicallyDeclaredNames</span>
+ of <span class="nt">StatementList</span> also occurs in the <span style="font-family: Times New
+ Roman">VarDeclaredNames</span> of <span class="nt">StatementList</span>.</p>
+ </li>
+
+ <li>
+ <p>It is a Syntax Error if <span class="nt">StatementList</span> <span style="font-family: Times New
+ Roman">Contains</span> <code>super</code>.</p>
+ </li>
+ </ul>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Additional error conditions relating to conflicting or duplicate declarations are checked
+ during module linking prior to evaluation of a <i>Script</i>. If any such errors are detected the <i>Script</i> is not
+ evaluated.</p>
+ </div>
+ </section>
+
+ <section id="sec-scripts-static-semantics-isstrict">
+ <h1><span class="secnum" id="sec-15.1.2"><a href="#sec-scripts-static-semantics-isstrict"
+ title="link to this section">15.1.2</a></span> Static Semantics: IsStrict</h1>
+
+ <p>See also: <a href="#sec-function-definitions-static-semantics-isstrict">14.1.13</a>, <a
+ href="#sec-module-static-semantics-static-semantics-isstrict">15.2.0.7</a>.</p>
+
+ <div class="gp prod"><span class="nt">ScriptBody</span> <span class="geq">:</span> <span class="nt">StatementList</span></div>
+ <ol class="proc">
+ <li>If this <i>ScriptBody</i> is contained in <a href="#sec-strict-mode-code">strict code</a> or if <i>StatementList</i>
+ is <a href="#sec-strict-mode-code">strict code</a>, then return <b>true</b>. Otherwise, return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-scripts-static-semantics-lexicallydeclarednames">
+ <h1><span class="secnum" id="sec-15.1.3"><a href="#sec-scripts-static-semantics-lexicallydeclarednames"
+ title="link to this section">15.1.3</a></span> Static Semantics: LexicallyDeclaredNames</h1>
+
+ <p>See also: <a href="#sec-block-static-semantics-lexicallydeclarednames">13.1.3</a>, <a
+ href="#sec-switch-statement-static-semantics-lexicallydeclarednames">13.11.3</a>, <a
+ href="#sec-function-definitions-static-semantics-lexicallyscopeddeclarations">14.1.14</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-lexicallyscopeddeclarations">14.2.10</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-isfunctiondefinition">14.4.8</a>, <a
+ href="#sec-class-definitions-static-semantics-lexicallydeclarednames">14.5.10</a>, <a
+ href="#sec-module-static-semantics-static-semantics-lexicallydeclarednames">15.2.0.10</a>.</p>
+
+ <div class="gp prod"><span class="nt">ScriptBody</span> <span class="geq">:</span> <span class="nt">StatementList</span></div>
+ <ol class="proc">
+ <li>Return TopLevelLexicallyDeclaredNames of <i>StatementList</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> At the top level of a <i>Script</i>, function declarations are treated like var
+ declarations rather than like lexical declarations.</p>
+ </div>
+ </section>
+
+ <section id="sec-scripts-static-semantics-lexicallyscopeddeclarations">
+ <h1><span class="secnum" id="sec-15.1.4"><a href="#sec-scripts-static-semantics-lexicallyscopeddeclarations"
+ title="link to this section">15.1.4</a></span> Static Semantics: LexicallyScopedDeclarations</h1>
+ <div class="gp prod"><span class="nt">ScriptBody</span> <span class="geq">:</span> <span class="nt">StatementList</span></div>
+ <ol class="proc">
+ <li>Return TopLevelLexicallyScopedDeclarations of <i>StatementList</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-scripts-static-semantics-vardeclarednames">
+ <h1><span class="secnum" id="sec-15.1.5"><a href="#sec-scripts-static-semantics-vardeclarednames"
+ title="link to this section">15.1.5</a></span> Static Semantics: VarDeclaredNames</h1>
+
+ <p>See also: <a href="#sec-statement-semantics-static-semantics-vardeclarednames">13.0.1</a>, <a
+ href="#sec-block-static-semantics-vardeclarednames">13.1.8</a>, <a
+ href="#sec-variable-statement-static-semantics-vardeclarednames">13.2.2.2</a>, <a
+ href="#sec-if-statement-static-semantics-vardeclarednames">13.5.1</a>, <a
+ href="#sec-do-while-statement-static-semantics-vardeclarednames">13.6.1.1</a>, <a
+ href="#sec-while-statement-static-semantics-vardeclarednames">13.6.2.1</a>, <a
+ href="#sec-for-statement-static-semantics-vardeclarednames">13.6.3.1</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-vardeclarednames">13.6.4.3</a>, <a
+ href="#sec-with-statement-static-semantics-vardeclarednames">13.10.2</a>, <a
+ href="#sec-switch-statement-static-semantics-vardeclarednames">13.11.4</a>, <a
+ href="#sec-static-semantics-currentlabelset">13.12.2</a>, <a
+ href="#sec-try-statement-static-semantics-vardeclarednames">13.14.2</a>, <a
+ href="#sec-function-definitions-static-semantics-referencessuper">14.1.16</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-vardeclarednames">14.4.12</a>, <a
+ href="#sec-class-definitions-static-semantics-vardeclarednames">14.5.15</a>, <a
+ href="#sec-module-static-semantics-static-semantics-vardeclarednames">15.2.0.13</a>.</p>
+
+ <div class="gp prod"><span class="nt">ScriptBody</span> <span class="geq">:</span> <span class="nt">StatementList</span></div>
+ <ol class="proc">
+ <li>Return TopLevelVarDeclaredNames of <i>StatementList</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-scripts-static-semantics-varscopeddeclarations">
+ <h1><span class="secnum" id="sec-15.1.6"><a href="#sec-scripts-static-semantics-varscopeddeclarations"
+ title="link to this section">15.1.6</a></span> Static Semantics: VarScopedDeclarations</h1>
+
+ <p>See also: <a href="#sec-statement-semantics-static-semantics-varscopeddeclarations">13.0.2</a>, <a
+ href="#sec-block-static-semantics-varscopeddeclarations">13.1.9</a>, <a
+ href="#sec-variable-statement-static-semantics-varscopeddeclarations">13.2.2.3</a>, <a
+ href="#sec-if-statement-static-semantics-varscopeddeclarations">13.5.2</a>, <a
+ href="#sec-do-while-statement-static-semantics-varscopeddeclarations">13.6.1.2</a>, <a
+ href="#sec-while-statement-static-semantics-varscopeddeclarations">13.6.2.2</a>, <a
+ href="#sec-for-statement-static-semantics-varscopeddeclarations">13.6.3.2</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-varscopeddeclarations">13.6.4.4</a>, <a
+ href="#sec-with-statement-static-semantics-varscopeddeclarations">13.10.3</a>, <a
+ href="#sec-switch-statement-static-semantics-varscopeddeclarations">13.11.5</a>, <a
+ href="#sec-labelled-statements-static-semantics-varscopeddeclarations">13.12.4</a>, <a
+ href="#sec-try-statement-static-semantics-varscopeddeclarations">13.14.3</a>, <a
+ href="#sec-function-definitions-static-semantics-varscopeddeclarations">14.1.18</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-varscopeddeclarations">14.2.14</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-varscopeddeclarations">14.4.13</a>, <a
+ href="#sec-module-static-semantics-static-semantics-varscopeddeclarations">15.2.0.14</a>.</p>
+
+ <p>.</p>
+
+ <div class="gp prod"><span class="nt">ScriptBody</span> <span class="geq">:</span> <span class="nt">StatementList</span></div>
+ <ol class="proc">
+ <li>Return TopLevelVarScopedDeclarations of <i>StatementList</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-runtime-semantics-scriptevaluation">
+ <h1><span class="secnum" id="sec-15.1.7"><a href="#sec-runtime-semantics-scriptevaluation"
+ title="link to this section">15.1.7</a></span> Runtime Semantics: ScriptEvaluation</h1>
+
+ <p>With argument <span style="font-family: Times New Roman"><i>realm</i> and <i>deletableBindings</i></span>.</p>
+
+ <div class="gp prod"><span class="nt">Script</span> <span class="geq">:</span> <span class="nt">ScriptBody</span><sub>opt</sub></div>
+ <ol class="proc">
+ <li>The code of this <i>Script</i> is <a href="#sec-strict-mode-code">strict mode code</a> if the <a
+ href="#sec-directive-prologues-and-the-use-strict-directive">Directive Prologue</a> (<a
+ href="#sec-directive-prologues-and-the-use-strict-directive">14.1.1</a>) of its <i>ScriptBody</i> contains a <a
+ href="#sec-directive-prologues-and-the-use-strict-directive">Use Strict Directive</a> or if any of the conditions of
+ <a href="#sec-strict-mode-code">10.2.1</a> apply. If the code of this <i>Script</i> is <a
+ href="#sec-strict-mode-code">strict mode code</a>, <i>ScriptBody</i> is evaluated in the following steps as <a
+ href="#sec-strict-mode-code">strict mode code</a>. Otherwise <i>ScriptBody</i> is evaluated in the following steps as
+ non-<a href="#sec-strict-mode-code">strict mode code</a>.</li>
+ <li>If <i>ScriptBody</i> is not present, return <a href="#sec-normalcompletion">NormalCompletion</a>(<span
+ style="font-family: sans-serif">empty</span>).</li>
+ <li>Let <i>globalEnv</i> be <i>realm</i>.[[globalEnv]].</li>
+ <li>Let <i>status</i> be GlobalDeclarationInstantiation(<i>ScriptBody</i>, <i>globalEnv</i>, and
+ <i>deletableBindings</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Let <i>progCxt</i> be a new <a href="#sec-execution-contexts">ECMAScript code execution context</a>.</li>
+ <li>Set the <i>progCxt’s</i> <a href="#sec-code-realms">Realm</a> to <i>realm</i>.</li>
+ <li>Set the <i>progCxt’s</i> <a href="#sec-execution-contexts">VariableEnvironment</a> to <i>globalEnv</i>.</li>
+ <li>Set the <i>progCxt’s</i> <a href="#sec-execution-contexts">LexicalEnvironment</a> to <i>globalEnv</i>.</li>
+ <li>If there is a <a href="#sec-execution-contexts">currently running execution context</a>, <a
+ href="#sec-execution-contexts">suspend</a> it.</li>
+ <li>Push <i>progCxt</i> on to <a href="#sec-execution-contexts">the execution context stack</a>; <i>progCxt</i> is now <a
+ href="#sec-execution-contexts">the running execution context</a>.</li>
+ <li>Let <i>result</i> be the result of evaluating <i>ScriptBody</i>.</li>
+ <li><a href="#sec-execution-contexts">Suspend</a> <i>progCxt</i> and remove it from <a href="#sec-execution-contexts">the
+ execution context stack</a>.</li>
+ <li>If <a href="#sec-execution-contexts">the execution context stack</a> is not empty, resume the context that is now on
+ the top of <a href="#sec-execution-contexts">the execution context stack</a> as <a href="#sec-execution-contexts">the
+ running execution context</a>. Otherwise, <a href="#sec-execution-contexts">the execution context stack</a> is now
+ empty and there is no running <a href="#sec-execution-contexts">execution context</a>.</li>
+ <li>Return <i>result</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The processes for initiating the evaluation of a <i>Script</i> and for dealing with the
+ result of such an evaluation are defined by an ECMAScript implementation and not by this specification.</p>
+ </div>
+ </section>
+
+ <section id="sec-runtime-semantics-globaldeclarationinstantiation">
+ <h1><span class="secnum" id="sec-15.1.8"><a href="#sec-runtime-semantics-globaldeclarationinstantiation"
+ title="link to this section">15.1.8</a></span> Runtime Semantics: GlobalDeclarationInstantiation</h1>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> When an <a href="#sec-execution-contexts">execution context</a> is established for
+ evaluating scripts, declarations are instantiated in the current global environment. Each global binding declared in the
+ code is instantiated.</p>
+ </div>
+
+ <p>GlobalDeclarationInstantiation is performed as follows using arguments <span style="font-family: Times New
+ Roman"><i>script</i>,</span> <span style="font-family: Times New Roman"><i>env</i>,</span> <span style="font-family: Times
+ New Roman">and <i>deletableBindings</i></span>. <var>script</var> is the <span class="nt">ScriptBody</span> that for which
+ the <a href="#sec-execution-contexts">execution context</a> is being established. <var>env</var> is <a
+ href="#sec-global-environment-records">the global environment record</a> in which bindings are to be created.
+ <var>deletableBindings</var> is <span class="value">true</span> if the bindings that are created should be deletable.</p>
+
+ <ol class="proc">
+ <li>Let <i>strict</i> be IsStrict of <i>script</i>.</li>
+ <li>Let <i>lexNames</i> be the LexicallyDeclaredNames of <i>script</i>.</li>
+ <li>Let <i>varNames</i> be the VarDeclaredNames of <i>script</i>.</li>
+ <li>For each <i>name</i> in <i>lexNames</i>, do
+ <ol class="block">
+ <li>If the result of calling <i>env’s</i> <a href="#sec-hasvardeclaration">HasVarDeclaration</a> concrete method
+ passing <i>name</i> as the argument is <b>true</b>, throw a <b>SyntaxError</b> exception.</li>
+ <li>If the result of calling <i>env’s</i> <a href="#sec-haslexicaldeclaration">HasLexicalDeclaration</a>
+ concrete method passing <i>name</i> as the argument is <b>true</b>, throw a <b>SyntaxError</b> exception.</li>
+ </ol>
+ </li>
+ <li>For each <i>name</i> in <i>varNames</i>, do
+ <ol class="block">
+ <li>If the result of calling <i>env’s</i> <a href="#sec-haslexicaldeclaration">HasLexicalDeclaration</a>
+ concrete method passing <i>name</i> as the argument is <b>true</b>, throw a <b>SyntaxError</b> exception.</li>
+ </ol>
+ </li>
+ <li>Let <i>varDeclarations</i> be the VarScopedDeclarations of <i>script</i>.</li>
+ <li>Let <i>functionsToInitialize</i> be an empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Let <i>declaredFunctionNames</i> be an empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>For each <i>d</i> in <i>varDeclarations</i>, in reverse list order do
+ <ol class="block">
+ <li>If <i>d</i> is neither a <i>VariableDeclaration</i> or a <i>ForBinding</i>, then
+ <ol class="block">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>d</i> is either a <i>FunctionDeclaration</i> or a
+ <i>GeneratorDeclaration</i>.</li>
+ <li>NOTE	If there are multiple <span style="font-family: Times New Roman"><i>FunctionDeclarations</i></span>
+ for the same name, the last declaration is used.</li>
+ <li>Let <i>fn</i> be the sole element of the BoundNames of <i>d.</i></li>
+ <li>If <i>fn</i> is not an element of <i>declaredFunctionNames</i>, then
+ <ol class="block">
+ <li>Let <i>fnDefinable</i> be the result of calling <i>env’s</i> <a
+ href="#sec-candeclareglobalfunction">CanDeclareGlobalFunction</a> concrete method passing <i>fn</i> as the
+ argument.</li>
+ <li>If <i>fnDefinable</i> is <b>false</b>, throw <b>TypeError</b> exception.</li>
+ <li>Append <i>fn</i> to <i>declaredFunctionNames</i>.</li>
+ <li>Insert <i>d</i> as the first element of <i>functionsToInitialize</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Let <i>declaredVarNames</i> be an empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>For each <i>d</i> in <i>varDeclarations</i>, do
+ <ol class="block">
+ <li>If <i>d</i> is a <i>VariableDeclaration</i> or a <i>ForBinding</i> then
+ <ol class="block">
+ <li>For each String <i>vn</i> in the BoundNames of <i>d</i>, do
+ <ol class="block">
+ <li>If <i>vn</i> is not an element of <i>declaredFunctionNames</i>, then
+ <ol class="block">
+ <li>Let <i>vnDefinable</i> be the result of calling <i>env’s</i> <a
+ href="#sec-candeclareglobalvar">CanDeclareGlobalVar</a> concrete method passing <i>vn</i> as the
+ argument.</li>
+ <li>If <i>vnDefinable</i> is <b>false</b>, throw <b>TypeError</b> exception.</li>
+ <li>If <i>vn</i> is not an element of <i>declaredVarNames</i>, then
+ <ol class="block">
+ <li>Append <i>vn</i> to <i>declaredVarNames</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>NOTE: No abnormal terminations occur after this algorithm step.</li>
+ <li>For each <i>FunctionDeclaration</i> <i>f</i> in <i>functionsToInitialize</i>, do
+ <ol class="block">
+ <li>Let <i>fn</i> be the sole element of the BoundNames of <i>f.</i></li>
+ <li>Let <i>fo</i> be the result of performing InstantiateFunctionObject for <i>f</i> with argument <i>env</i>.</li>
+ <li>Let <i>status</i> be the result of calling <i>env</i>’s <a
+ href="#sec-createglobalfunctionbinding">CreateGlobalFunctionBinding</a> concrete method passing <i>fn</i>,
+ <i>fo</i>, and <i>deletableBindings</i> as the arguments.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ </ol>
+ </li>
+ <li>For each String <i>vn</i> in <i>declaredVarNames</i>, in list order do
+ <ol class="block">
+ <li>Let <i>status</i> be the result of calling <i>env’s</i> <a
+ href="#sec-createglobalvarbinding">CreateGlobalVarBinding</a> concrete method passing <i>vn</i> and
+ <i>deletableBindings</i> as the argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ </ol>
+ </li>
+ <li>Let <i>lexDeclarations</i> be the LexicallyScopedDeclarations of <i>script</i>.</li>
+ <li>For each element <i>d</i> in <i>lexDeclarations</i> do
+ <ol class="block">
+ <li>NOTE	Except for generator function declarations, lexically declarated names are only instantiated here but not
+ initialized.</li>
+ <li>For each element <i>dn</i> of the BoundNames of <i>d</i> do
+ <ol class="block">
+ <li>If IsConstantDeclaration of <i>d</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>status</i> be the result of calling <i>env</i>’s CreateImmutableBinding concrete method
+ passing <i>dn</i> as the argument.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>status</i> be the result of calling <i>env</i>’s CreateMutableBinding concrete method passing
+ <i>dn</i> and <b>false</b> as the arguments.</li>
+ </ol>
+ </li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>status</i> is never an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a> for lexically declared names.</li>
+ </ol>
+ </li>
+ <li>If <i>d</i> is a <i>GeneratorDeclaration</i> production, then
+ <ol class="block">
+ <li>Let <i>fn</i> be the sole element of the BoundNames of <i>d.</i></li>
+ <li>Let <i>fo</i> be the result of performing InstantiateFunctionObject for <i>d</i> with argument
+ <i>env</i>.</li>
+ <li>Let <i>status</i> be the result of calling <i>env</i>’s SetMutableBinding concrete method passing
+ <i>fn</i>, <i>fo</i>, and <b>false</b> as the arguments.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<span style="font-family: sans-serif">empty</span>)</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Early errors specified in <a href="#sec-scripts-static-semantics-early-errors">15.1.1</a>
+ prevent name conflicts between function/var declarations and let/const/class declarations as well as redeclaration of
+ let/const/class bindings for declaration contained within a single <i>Script</i>. However, such conflicts and
+ redeclarations that span more than one <i>Script</i> are detected as runtime errors during GlobalDeclarationInstantiation.
+ If any such errors are detected, no bindings are instantiated for the script.</p>
+
+ <p>Unlike explicit var or function declarations, properties that are directly created on the global object result in
+ global bindings that may be shadowed by let/const/class declarations.</p>
+ </div>
+ </section>
+
+ <section id="sec-scriptevaluationtask">
+ <h1><span class="secnum" id="sec-15.1.9"><a href="#sec-scriptevaluationtask" title="link to this section">15.1.9</a></span>
+ Runtime Semantics: ScriptEvaluationTask ( source )</h1>
+
+ <p>The task ScriptEvaluationTask with parameter <var>source</var> parses, validates, and evaluates the <span
+ class="nt">Script</span> represented by <var>source</var>.</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>source</i> is a <i>SourceCharacter</i> sequence (see 10).</li>
+ <li>Parse <i>source</i> using <i>Script</i> as the goal symbol and analyze the parse result for any Early Error
+ conditions. If the parse was successful and no ealy errors were found, then let <i>script</i> the resulting parse
+ tree. Otherwise, let <i>script</i> be an indication of one or more parsing errors and/or early errors. Parsing and
+ early error detection may be interweaved in an implementation dependent manner. If more than one parse or early error
+ is present, the number and ordering of reported errors is implementation dependent but at least one error must be
+ reported.</li>
+ <li>If <i>script</i> is an error indication, then
+ <ol class="block">
+ <li>Report or log the error(s) in an implementation dependent manner.</li>
+ <li>Let <i>status</i> be <a href="#sec-normalcompletion">NormalCompletion</a>(<b>undefined</b>).</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>realm</i> be <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-code-realms">Realm</a>.</li>
+ <li>Let <i>status</i> be the result of ScriptEvaluation of <i>script</i> with arguments <i>realm</i> and
+ <b>false</b>.</li>
+ </ol>
+ </li>
+ <li>NextTask <i>status</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> An implementation may parse a <i>Script</i> and analyze it for Early Error conditions
+ prior to the execution of the ScriptEvaluationTask for that <i>Script</i>. However, the reporting of any errors must be
+ deferred until the ScriptEvaluationTask is actually exeuted.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-modules">
+ <div class="front">
+ <h1><span class="secnum" id="sec-15.2"><a href="#sec-modules" title="link to this section">15.2</a></span> Modules</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">Module</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">ModuleBody</span><sub>opt</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ModuleBody</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">ModuleItemList</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ModuleItemList</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">ModuleItem</span></div>
+ <div class="rhs"><span class="nt">ModuleItemList</span> <span class="nt">ModuleItem</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ModuleItem</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">ImportDeclaration</span></div>
+ <div class="rhs"><span class="nt">ExportDeclaration</span></div>
+ <div class="rhs"><span class="nt">StatementListItem</span></div>
+ </div>
+ </div>
+
+ <section id="sec-module-static-semantics">
+ <div class="front">
+ <h1><span class="secnum" id="sec-15.2.0"><a href="#sec-module-static-semantics"
+ title="link to this section">15.2.0</a></span> Module Static Semantics</h1>
+ </div>
+
+ <section id="sec-module-static-semantics-static-semantics-early-errors">
+ <h1><span class="secnum" id="sec-15.2.0.1"><a href="#sec-module-static-semantics-static-semantics-early-errors"
+ title="link to this section">15.2.0.1</a></span> Static Semantics: Early Errors</h1>
+ <div class="gp prod"><span class="nt">ModuleBody</span> <span class="geq">:</span> <span class="nt">ModuleItemList</span></div>
+ <ul>
+ <li>
+ <p>It is a Syntax Error if the LexicallyDeclaredNames of <span class="nt">ModuleItemList</span> contains any duplicate
+ entries.</p>
+ </li>
+
+ <li>
+ <p>It is a Syntax Error if the ExportedBindings of <span class="nt">ModuleItemList</span> contains any duplicate
+ entries.</p>
+ </li>
+
+ <li>
+ <p>It is a Syntax Error if any element of the LexicallyDeclaredNames of <span class="nt">ModuleItemList</span> also
+ occurs in the VarDeclaredNames of <span class="nt">ModuleItemList</span>.</p>
+ </li>
+
+ <li>
+ <p>It is a Syntax Error if <span class="nt">ModuleItemList</span> Contains <code>super</code>.</p>
+ </li>
+ </ul>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Additional error conditions relating to conflicting or duplicate declarations are
+ checked during module linking prior to evaluation of a <i>Module</i>. If any such errors are detected the <i>Module</i>
+ is not evaluated.</p>
+ </div>
+ </section>
+
+ <section id="sec-static-semantics-declarednames">
+ <h1><span class="secnum" id="sec-15.2.0.2"><a href="#sec-static-semantics-declarednames"
+ title="link to this section">15.2.0.2</a></span> Static Semantics: DeclaredNames</h1>
+ <div class="gp prod"><span class="nt">Module</span> <span class="geq">:</span> <span class="grhsannot">[empty]</span></div>
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">Module</span> <span class="geq">:</span> <span class="nt">ModuleBody</span></div>
+ <ol class="proc">
+ <li>Let <i>names</i> be LexicallyDeclaredNames of <i>ModuleBody</i>.</li>
+ <li>Append to <i>names</i> the elements of the VarDeclaratedNames of <i>ModuleBody.</i></li>
+ <li>Return <i>names</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-module-static-semantics-static-semantics-exportedbindings">
+ <h1><span class="secnum" id="sec-15.2.0.3"><a href="#sec-module-static-semantics-static-semantics-exportedbindings"
+ title="link to this section">15.2.0.3</a></span> Static Semantics: ExportedBindings</h1>
+
+ <p>See also:<a href="#sec-exports-static-semantics-exportedbindings">15.2.2.2</a>.</p>
+
+ <div class="gp prod"><span class="nt">ModuleItemList</span> <span class="geq">:</span> <span class="grhsannot">[empty]</span></div>
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ModuleItemList</span> <span class="geq">:</span> <span class="nt">ModuleItemList</span> <span class="nt">ModuleItem</span></div>
+ <ol class="proc">
+ <li>Let <i>names</i> be ExportedBindings of <i>ModuleItemList</i>.</li>
+ <li>Append to <i>names</i> the elements of the ExportedBindings of <i>ModuleItem.</i></li>
+ <li>Return <i>names</i>.</li>
+ </ol>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ModuleItem</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">ImportDeclaration</span></div>
+ <div class="rhs"><span class="nt">StatementListItem</span></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-module-static-semantics-static-semantics-exportentries">
+ <h1><span class="secnum" id="sec-15.2.0.4"><a href="#sec-module-static-semantics-static-semantics-exportentries"
+ title="link to this section">15.2.0.4</a></span> Static Semantics: ExportEntries</h1>
+
+ <p>See also:<a href="#sec-exports-static-semantics-exportentries">15.2.2.3</a>.</p>
+
+ <div class="gp prod"><span class="nt">ModuleItemList</span> <span class="geq">:</span> <span class="grhsannot">[empty]</span></div>
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ModuleItemList</span> <span class="geq">:</span> <span class="nt">ModuleItemList</span> <span class="nt">ModuleItem</span></div>
+ <ol class="proc">
+ <li>Let <i>entries</i> be ExportEntries of <i>ModuleItemList</i>.</li>
+ <li>Append to <i>entries</i> the elements of the ExportEntries of <i>ModuleItem.</i></li>
+ <li>Return <i>entries</i>.</li>
+ </ol>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ModuleItem</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">ImportDeclaration</span></div>
+ <div class="rhs"><span class="nt">StatementListItem</span></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-static-semantics-importedbindings">
+ <h1><span class="secnum" id="sec-15.2.0.5"><a href="#sec-static-semantics-importedbindings"
+ title="link to this section">15.2.0.5</a></span> Static Semantics: ImportedBindings</h1>
+ <div class="gp prod"><span class="nt">ModuleItemList</span> <span class="geq">:</span> <span class="grhsannot">[empty]</span></div>
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ModuleItemList</span> <span class="geq">:</span> <span class="nt">ModuleItemList</span> <span class="nt">ModuleItem</span></div>
+ <ol class="proc">
+ <li>Let <i>names</i> be ImportedBindings of <i>ModuleItemList</i>.</li>
+ <li>Append to <i>names</i> the elements of the ImportedBindings of <i>ModuleItem.</i></li>
+ <li>Return <i>names</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ModuleItem</span> <span class="geq">:</span> <span class="nt">ImportDeclaration</span></div>
+ <ol class="proc">
+ <li>Return the BoundNames of <i>ImportDeclaration</i>.</li>
+ </ol>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ModuleItem</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">ExportDeclaration</span></div>
+ <div class="rhs"><span class="nt">StatementListItem</span></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-module-static-semantics-static-semantics-importentries">
+ <h1><span class="secnum" id="sec-15.2.0.6"><a href="#sec-module-static-semantics-static-semantics-importentries"
+ title="link to this section">15.2.0.6</a></span> Static Semantics: ImportEntries</h1>
+
+ <p>See also:<a href="#sec-imports-static-semantics-importentries">15.2.1.3</a>.</p>
+
+ <div class="gp prod"><span class="nt">ModuleItemList</span> <span class="geq">:</span> <span class="grhsannot">[empty]</span></div>
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ModuleItemList</span> <span class="geq">:</span> <span class="nt">ModuleItemList</span> <span class="nt">ModuleItem</span></div>
+ <ol class="proc">
+ <li>Let <i>entries</i> be ImportEntries of <i>ModuleItemList</i>.</li>
+ <li>Append to <i>entries</i> the elements of the ImportEntries of <i>ModuleItem.</i></li>
+ <li>Return <i>entries</i>.</li>
+ </ol>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ModuleItem</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">ExportDeclaration</span></div>
+ <div class="rhs"><span class="nt">StatementListItem</span></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-module-static-semantics-static-semantics-isstrict">
+ <h1><span class="secnum" id="sec-15.2.0.7"><a href="#sec-module-static-semantics-static-semantics-isstrict"
+ title="link to this section">15.2.0.7</a></span> Static Semantics: IsStrict</h1>
+
+ <p>See also: <a href="#sec-function-definitions-static-semantics-isstrict">14.1.13</a>, <a
+ href="#sec-scripts-static-semantics-isstrict">15.1.2</a>.</p>
+
+ <div class="gp prod"><span class="nt">ModuleBody</span> <span class="geq">:</span> <span class="nt">ModuleItemList</span></div>
+ <ol class="proc">
+ <li>Return <b>true</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-static-semantics-knownexportentries">
+ <h1><span class="secnum" id="sec-15.2.0.8"><a href="#sec-static-semantics-knownexportentries"
+ title="link to this section">15.2.0.8</a></span> Static Semantics: KnownExportEntries</h1>
+ <div class="gp prod"><span class="nt">ModuleBody</span> <span class="geq">:</span> <span class="nt">ModuleItemList</span></div>
+ <ol class="proc">
+ <li>Let <i>allExports</i> be ExportEntries of <i>ModuleItemList</i>.</li>
+ <li>Return a new <a href="#sec-list-and-record-specification-type">List</a> containing all the entries of
+ <i>allEntries</i> whose [[ImportName]] field is not <span style="font-family: sans-serif">all</span>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-module-static-semantics-static-semantics-modulerequests">
+ <h1><span class="secnum" id="sec-15.2.0.9"><a href="#sec-module-static-semantics-static-semantics-modulerequests"
+ title="link to this section">15.2.0.9</a></span> Static Semantics: ModuleRequests</h1>
+
+ <p>See also: <a href="#sec-imports-static-semantics-modulerequests">15.2.1.5</a>, <a
+ href="#sec-exports-static-semantics-modulerequests">15.2.2.5</a>.</p>
+
+ <div class="gp prod"><span class="nt">ModuleItemList</span> <span class="geq">:</span> <span class="grhsannot">[empty]</span></div>
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ModuleItemList</span> <span class="geq">:</span> <span class="nt">ModuleItem</span></div>
+ <ol class="proc">
+ <li>Return ModuleRequests of <i>ModuleItem</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ModuleItemList</span> <span class="geq">:</span> <span class="nt">ModuleItemList</span> <span class="nt">ModuleItem</span></div>
+ <ol class="proc">
+ <li>Let <i>moduleNames</i> be ModuleRequests of <i>ModuleItemList</i>.</li>
+ <li>Let <i>additionalNames</i> be ModuleRequests of <i>ModuleItem.</i></li>
+ <li>Append to <i>moduleNames</i> each element of <i>additionalNames</i> that is not already an element of
+ <i>moduleNames.</i></li>
+ <li>Return <i>moduleNames</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ModuleItem</span> <span class="geq">:</span> <span class="nt">StatementListItem</span></div>
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-module-static-semantics-static-semantics-lexicallydeclarednames">
+ <h1><span class="secnum" id="sec-15.2.0.10"><a href="#sec-module-static-semantics-static-semantics-lexicallydeclarednames"
+ title="link to this section">15.2.0.10</a></span> Static Semantics: LexicallyDeclaredNames</h1>
+
+ <p>See also: <a href="#sec-block-static-semantics-lexicallydeclarednames">13.1.3</a>, <a
+ href="#sec-switch-statement-static-semantics-lexicallydeclarednames">13.11.3</a>, <a
+ href="#sec-function-definitions-static-semantics-lexicallyscopeddeclarations">14.1.14</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-lexicallyscopeddeclarations">14.2.10</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-isfunctiondefinition">14.4.8</a>, <a
+ href="#sec-class-definitions-static-semantics-lexicallydeclarednames">14.5.10</a>, <a
+ href="#sec-scripts-static-semantics-lexicallydeclarednames">15.1.3</a>.</p>
+
+ <div class="gp prod"><span class="nt">ModuleItemList</span> <span class="geq">:</span> <span class="grhsannot">[empty]</span></div>
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ModuleItemList</span> <span class="geq">:</span> <span class="nt">ModuleItemList</span> <span class="nt">ModuleItem</span></div>
+ <ol class="proc">
+ <li>Let <i>names</i> be LexicallyDeclaredNames of <i>ModuleItemList</i>.</li>
+ <li>Append to <i>names</i> the elements of the LexicallyDeclaredNames of <i>ModuleItem.</i></li>
+ <li>Return <i>names</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ModuleItem</span> <span class="geq">:</span> <span class="nt">ImportDeclaration</span></div>
+ <ol class="proc">
+ <li>Return the BoundNames of <i>ImportDeclaration</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ModuleItem</span> <span class="geq">:</span> <span class="nt">ExportDeclaration</span></div>
+ <ol class="proc">
+ <li>If <i>ExportDeclaration</i> is <code>export</code> <i>VariableStatement</i><code>;</code> then return a new empty <a
+ href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Return the BoundNames of <i>ExportDeclaration</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ModuleItem</span> <span class="geq">:</span> <span class="nt">StatementListItem</span></div>
+ <ol class="proc">
+ <li>Return LexicallyDeclaredNames of <i>StatementListItem</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> At the top level of a <i>Module</i>, function declarations are treated like lexical
+ declarations rather than like var declarations.</p>
+ </div>
+ </section>
+
+ <section id="sec-module-static-semantics-static-semantics-lexicallyscopeddeclarations">
+ <h1><span class="secnum" id="sec-15.2.0.11"><a
+ href="#sec-module-static-semantics-static-semantics-lexicallyscopeddeclarations"
+ title="link to this section">15.2.0.11</a></span> Static Semantics: LexicallyScopedDeclarations</h1>
+
+ <p>See also: <a href="#sec-block-static-semantics-lexicallyscopeddeclarations">13.1.2</a>, <a
+ href="#sec-switch-statement-static-semantics-lexicallyscopeddeclarations">13.11.2</a>.</p>
+
+ <div class="gp prod"><span class="nt">ModuleItemList</span> <span class="geq">:</span> <span class="grhsannot">[empty]</span></div>
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ModuleItemList</span> <span class="geq">:</span> <span class="nt">ModuleItemList</span> <span class="nt">ModuleItem</span></div>
+ <ol class="proc">
+ <li>Let <i>declarations</i> be LexicallyScopedDeclarations of <i>ModuleItemList</i>.</li>
+ <li>Append to <i>declarations</i> the elements of the LexicallyScopedDeclarations of <i>ModuleItem.</i></li>
+ <li>Return <i>declarations</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ModuleItem</span> <span class="geq">:</span> <span class="nt">ImportDeclaration</span></div>
+ <ol class="proc">
+ <li>If the BoundNames of <i>ImportDeclarations</i> is empty, then return an empty <a
+ href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Return a new <a href="#sec-list-and-record-specification-type">List</a> containing <i>ImportDeclaration</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ModuleItem</span> <span class="geq">:</span> <span class="nt">ExportDeclaration</span></div>
+ <ol class="proc">
+ <li>If <i>ExportDeclaration</i> is <code>export</code> <i>Declaration</i><code>;</code> then return a new <a
+ href="#sec-list-and-record-specification-type">List</a> containing <i>Declaration</i>.</li>
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-static-semantics-unknownexportentries">
+ <h1><span class="secnum" id="sec-15.2.0.12"><a href="#sec-static-semantics-unknownexportentries"
+ title="link to this section">15.2.0.12</a></span> Static Semantics: UnknownExportEntries</h1>
+ <div class="gp prod"><span class="nt">ModuleBody</span> <span class="geq">:</span> <span class="nt">ModuleItemList</span></div>
+ <ol class="proc">
+ <li>Let <i>allExports</i> be ExportEntries of <i>ModuleItemList</i>.</li>
+ <li>Return a new <a href="#sec-list-and-record-specification-type">List</a> containing all the entries of
+ <i>allEntries</i> whose [[ImportName]] field is <span style="font-family: sans-serif">all</span>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-module-static-semantics-static-semantics-vardeclarednames">
+ <h1><span class="secnum" id="sec-15.2.0.13"><a href="#sec-module-static-semantics-static-semantics-vardeclarednames"
+ title="link to this section">15.2.0.13</a></span> Static Semantics: VarDeclaredNames</h1>
+
+ <p>See also: <a href="#sec-statement-semantics-static-semantics-vardeclarednames">13.0.1</a>, <a
+ href="#sec-block-static-semantics-vardeclarednames">13.1.8</a>, <a
+ href="#sec-variable-statement-static-semantics-vardeclarednames">13.2.2.2</a>, <a
+ href="#sec-if-statement-static-semantics-vardeclarednames">13.5.1</a>, <a
+ href="#sec-do-while-statement-static-semantics-vardeclarednames">13.6.1.1</a>, <a
+ href="#sec-while-statement-static-semantics-vardeclarednames">13.6.2.1</a>, <a
+ href="#sec-for-statement-static-semantics-vardeclarednames">13.6.3.1</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-vardeclarednames">13.6.4.3</a>, <a
+ href="#sec-with-statement-static-semantics-vardeclarednames">13.10.2</a>, <a
+ href="#sec-switch-statement-static-semantics-vardeclarednames">13.11.4</a>, <a
+ href="#sec-static-semantics-currentlabelset">13.12.2</a>, <a
+ href="#sec-try-statement-static-semantics-vardeclarednames">13.14.2</a>, <a
+ href="#sec-function-definitions-static-semantics-referencessuper">14.1.16</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-vardeclarednames">14.4.12</a>, <a
+ href="#sec-class-definitions-static-semantics-vardeclarednames">14.5.15</a>, <a
+ href="#sec-scripts-static-semantics-vardeclarednames">15.1.5</a>.</p>
+
+ <div class="gp prod"><span class="nt">ModuleItemList</span> <span class="geq">:</span> <span class="nt">ModuleItemList</span> <span class="nt">ModuleItem</span></div>
+ <ol class="proc">
+ <li>Let <i>names</i> be VarDeclaredNames of <i>ModuleItemList</i>.</li>
+ <li>Append to <i>names</i> the elements of the VarDeclaredNames of <i>ModuleItem.</i></li>
+ <li>Return <i>names</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ModuleItem</span> <span class="geq">:</span> <span class="nt">ImportDeclaration</span></div>
+ <ol class="proc">
+ <li>Return an empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ModuleItem</span> <span class="geq">:</span> <span class="nt">ExportDeclaration</span></div>
+ <ol class="proc">
+ <li>If <i>ExportDeclaration</i> is <code>export</code> <i>VariableStatement</i><code>;</code> then return BoundNames of
+ <i>ExportDeclaration</i>.</li>
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-module-static-semantics-static-semantics-varscopeddeclarations">
+ <h1><span class="secnum" id="sec-15.2.0.14"><a href="#sec-module-static-semantics-static-semantics-varscopeddeclarations"
+ title="link to this section">15.2.0.14</a></span> Static Semantics: VarScopedDeclarations</h1>
+
+ <p>See also: <a href="#sec-statement-semantics-static-semantics-varscopeddeclarations">13.0.2</a>, <a
+ href="#sec-block-static-semantics-varscopeddeclarations">13.1.9</a>, <a
+ href="#sec-variable-statement-static-semantics-varscopeddeclarations">13.2.2.3</a>, <a
+ href="#sec-if-statement-static-semantics-varscopeddeclarations">13.5.2</a>, <a
+ href="#sec-do-while-statement-static-semantics-varscopeddeclarations">13.6.1.2</a>, <a
+ href="#sec-while-statement-static-semantics-varscopeddeclarations">13.6.2.2</a>, <a
+ href="#sec-for-statement-static-semantics-varscopeddeclarations">13.6.3.2</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-varscopeddeclarations">13.6.4.4</a>, <a
+ href="#sec-with-statement-static-semantics-varscopeddeclarations">13.10.3</a>, <a
+ href="#sec-switch-statement-static-semantics-varscopeddeclarations">13.11.5</a>, <a
+ href="#sec-labelled-statements-static-semantics-varscopeddeclarations">13.12.4</a>, <a
+ href="#sec-try-statement-static-semantics-varscopeddeclarations">13.14.3</a>, <a
+ href="#sec-function-definitions-static-semantics-varscopeddeclarations">14.1.18</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-varscopeddeclarations">14.2.14</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-varscopeddeclarations">14.4.13</a>, <a
+ href="#sec-scripts-static-semantics-varscopeddeclarations">15.1.6</a>.</p>
+
+ <p>.</p>
+
+ <div class="gp prod"><span class="nt">ModuleItemList</span> <span class="geq">:</span> <span class="grhsannot">[empty]</span></div>
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ModuleItemList</span> <span class="geq">:</span> <span class="nt">ModuleItemList</span> <span class="nt">ModuleItem</span></div>
+ <ol class="proc">
+ <li>Let <i>declarations</i> be VarScopedDeclarations of <i>ModuleItemList</i>.</li>
+ <li>Append to <i>declarations</i> the elements of the VarScopedDeclarations of <i>ModuleItem.</i></li>
+ <li>Return <i>declarations</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ModuleItem</span> <span class="geq">:</span> <span class="nt">ImportDeclaration</span></div>
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ModuleItem</span> <span class="geq">:</span> <span class="nt">ExportDeclaration</span></div>
+ <ol class="proc">
+ <li>If <i>ExportDeclaration</i> is <code>export</code> <i>VariableStatement</i><code>;</code> then return
+ VarScopedDeclarations of <i>VariableStatement</i>.</li>
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-moduledeclarationinstantiation">
+ <h1><span class="secnum" id="sec-15.2.0.15"><a href="#sec-moduledeclarationinstantiation"
+ title="link to this section">15.2.0.15</a></span> Runtime Semantics: ModuleDeclarationInstantiation( code, env )</h1>
+
+ <p style="background-color: #FFC000">TO DO</p>
+
+ <ol class="proc">
+ <li>Let <i>declarations</i> be the LexicallyScopedDeclarations of <i>code</i>.</li>
+ <li>Let <i>functionsToInitialize</i> be an empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>For each element <i>d</i> in <i>declarations</i> do
+ <ol class="block">
+ <li>For each element <i>dn</i> of the BoundNames of <i>d</i> do
+ <ol class="block">
+ <li>If IsConstantDeclaration of <i>d</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Call <i>env</i>’s CreateImmutableBinding concrete method passing <i>dn</i> as the argument.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>status</i> be the result of calling <i>env</i>’s CreateMutableBinding concrete method
+ passing <i>dn</i> and <b>false</b> as the arguments.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>status</i> is never an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>If <i>d</i> is a <i>GeneratorDeclaration</i> production or a <i>FunctionDeclaration</i> production, then
+ <ol class="block">
+ <li>Append <i>d</i> to <i>functionsToInitialize</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>For each production <i>f</i> in <i>functionsToInitialize</i>, in list order do
+ <ol class="block">
+ <li>Let <i>fn</i> be the sole element of the BoundNames of <i>f.</i></li>
+ <li>Let <i>fo</i> be the result of performing InstantiateFunctionObject for <i>f</i> with argument
+ <i>env</i>.</li>
+ <li>Call <i>env</i>’s InitializeBinding concrete method passing <i>fn</i>, and <i>fo</i> as the
+ arguments.</li>
+ </ol>
+ </li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-imports">
+ <div class="front">
+ <h1><span class="secnum" id="sec-15.2.1"><a href="#sec-imports" title="link to this section">15.2.1</a></span>
+ Imports</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ImportDeclaration</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">ModuleImport</span></div>
+ <div class="rhs"><code class="t">import</code> <span class="nt">ImportClause</span> <span class="nt">FromClause</span> <code class="t">;</code></div>
+ <div class="rhs"><code class="t">import</code> <span class="nt">ModuleSpecifier</span> <code class="t">;</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ModuleImport</span> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">module</code> <span class="grhsannot">[no <span class="nt">LineTerminator</span> here]</span> <span class="nt">ImportedBinding</span> <span class="nt">FromClause</span> <code class="t">;</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">FromClause</span> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">from</code> <span class="nt">ModuleSpecifier</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ImportClause</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">ImportedBinding</span></div>
+ <div class="rhs"><span class="nt">ImportedBinding</span> <code class="t">,</code> <span class="nt">NamedImports</span></div>
+ <div class="rhs"><span class="nt">NamedImports</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">NamedImports</span> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">{</code> <code class="t">}</code></div>
+ <div class="rhs"><code class="t">{</code> <span class="nt">ImportsList</span> <code class="t">}</code></div>
+ <div class="rhs"><code class="t">{</code> <span class="nt">ImportsList</span> <code class="t">,</code> <code class="t">}</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ImportsList</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">ImportSpecifier</span></div>
+ <div class="rhs"><span class="nt">ImportsList</span> <code class="t">,</code> <span class="nt">ImportSpecifier</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ImportSpecifier</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">ImportedBinding</span></div>
+ <div class="rhs"><span class="nt">IdentifierName</span> <code class="t">as</code> <span class="nt">ImportedBinding</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ModuleSpecifier</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">StringLiteral</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ImportedBinding</span> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">BindingIdentifier</span></div>
+ </div>
+ </div>
+
+ <section id="sec-imports-static-semantics-early-errors">
+ <h1><span class="secnum" id="sec-15.2.1.1"><a href="#sec-imports-static-semantics-early-errors"
+ title="link to this section">15.2.1.1</a></span> Static Semantics: Early Errors</h1>
+ <div class="gp prod"><span class="nt">ModuleItem</span> <span class="geq">:</span> <span class="nt">ImportDeclaration</span></div>
+ <ul>
+ <li>
+ <p>It is a Syntax Error if the BoundNames of <span class="nt">ImportDeclaration</span> contains any duplicate
+ entries.</p>
+ </li>
+ </ul>
+ </section>
+
+ <section id="sec-imports-static-semantics-boundnames">
+ <h1><span class="secnum" id="sec-15.2.1.2"><a href="#sec-imports-static-semantics-boundnames"
+ title="link to this section">15.2.1.2</a></span> Static Semantics: BoundNames</h1>
+
+ <p>See also: <a href="#sec-let-and-const-declarations-static-semantics-boundnames">13.2.1.2</a>, <a
+ href="#sec-variable-statement-static-semantics-boundnames">13.2.2.1</a>, <a
+ href="#sec-identifiers-static-semantics-boundnames">12.1.2</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-boundnames">13.6.4.2</a>, <a
+ href="#sec-function-definitions-static-semantics-boundnames">14.1.3</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-boundnames">14.2.2</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-boundnames">14.4.2</a>, <a
+ href="#sec-class-definitions-static-semantics-boundnames">14.5.2</a>, <a
+ href="#sec-exports-static-semantics-boundnames">15.2.2.1</a>.</p>
+
+ <div class="gp prod"><span class="nt">ImportDeclaration</span> <span class="geq">:</span> <code class="t">import</code> <span class="nt">ImportClause</span> <span class="nt">FromClause</span> <code class="t">;</code></div>
+ <ol class="proc">
+ <li>Return the BoundNames of <i>ImportClause</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ImportDeclaration</span> <span class="geq">:</span> <code class="t">import</code> <span class="nt">ModuleSpecifier</span> <code class="t">;</code></div>
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ModuleImport</span> <span class="geq">:</span> <code class="t">module</code> <span class="nt">ImportedBinding</span> <span class="nt">FromClause</span> <code class="t">;</code></div>
+ <ol class="proc">
+ <li>Return the BoundNames of <i>ImportedBinding</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ImportClause</span> <span class="geq">:</span> <span class="nt">ImportedBinding</span> <code class="t">,</code> <span class="nt">NamedImports</span></div>
+ <ol class="proc">
+ <li>Let <i>names</i> be the BoundNames of <i>ImportedBinding</i>.</li>
+ <li>Append to <i>names</i> the elements of the BoundNames of <i>NamedImports</i>.</li>
+ <li>Return <i>names</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">NamedImports</span> <span class="geq">:</span> <code class="t">{</code> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ImportsList</span> <span class="geq">:</span> <span class="nt">ImportsList</span> <code class="t">,</code> <span class="nt">ImportSpecifier</span></div>
+ <ol class="proc">
+ <li>Let <i>names</i> be the BoundNames of <i>ImportsList</i>.</li>
+ <li>Append to <i>names</i> the elements of the BoundNames of <i>ImportSpecifier</i>.</li>
+ <li>Return <i>names</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ImportSpecifier</span> <span class="geq">:</span> <span class="nt">IdentifierName</span> <code class="t">as</code> <span class="nt">ImportedBinding</span></div>
+ <ol class="proc">
+ <li>Return the BoundNames of <i>ImportedBinding</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-imports-static-semantics-importentries">
+ <h1><span class="secnum" id="sec-15.2.1.3"><a href="#sec-imports-static-semantics-importentries"
+ title="link to this section">15.2.1.3</a></span> Static Semantics: ImportEntries</h1>
+
+ <p>See also:<a href="#sec-module-static-semantics-static-semantics-importentries">15.2.0.6</a>.</p>
+
+ <div class="gp prod"><span class="nt">ImportDeclaration</span> <span class="geq">:</span> <code class="t">import</code> <span class="nt">ImportClause</span> <span class="nt">FromClause</span> <code class="t">;</code></div>
+ <ol class="proc">
+ <li>Let <i>module</i> be the sole element of ModuleRequests of <i>FromClause</i>.</li>
+ <li>Return ImportEntriesForModule of <i>ImportClause</i> with argument <i>module</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ImportDeclaration</span> <span class="geq">:</span> <code class="t">import</code> <span class="nt">ModuleSpecifier</span> <code class="t">;</code></div>
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ModuleImport</span> <span class="geq">:</span> <code class="t">module</code> <span class="nt">ImportedBinding</span> <span class="nt">FromClause</span> <code class="t">;</code></div>
+ <ol class="proc">
+ <li>Let <i>module</i> be ModuleRequests of <i>FromClause</i>.</li>
+ <li>Let <i>localName</i> be the StringValue of <i>ImportedBinding</i>.</li>
+ <li>Let <i>entry</i> be the Record {[[ModuleRequest]]: <i>module</i>, [[ImportName]]: <code>"default"</code>,
+ [[LocalName]]: <i>localName</i> }.</li>
+ <li>Return a new <a href="#sec-list-and-record-specification-type">List</a> containing <i>entry</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-static-semantics-importentriesformodule">
+ <h1><span class="secnum" id="sec-15.2.1.4"><a href="#sec-static-semantics-importentriesformodule"
+ title="link to this section">15.2.1.4</a></span> Static Semantics: ImportEntriesForModule</h1>
+
+ <p>With parameter <var>module</var>.</p>
+
+ <div class="gp prod"><span class="nt">ImportClause</span> <span class="geq">:</span> <span class="nt">ImportedBinding</span> <code class="t">,</code> <span class="nt">NamedImports</span></div>
+ <ol class="proc">
+ <li>Let <i>localName</i> be the StringValue of <i>ImportedBinding</i>.</li>
+ <li>Let <i>defaultEntry</i> be the Record {[[ModuleRequest]]: <i>module</i>, [[ImportName]]: <code>"default"</code>,
+ [[LocalName]]: <i>localName</i> }.</li>
+ <li>Return a new <a href="#sec-list-and-record-specification-type">List</a> containing <i>defaultEntry.</i></li>
+ </ol>
+ <div class="gp prod"><span class="nt">ImportClause</span> <span class="geq">:</span> <span class="nt">ImportedBinding</span> <code class="t">,</code> <span class="nt">NamedImports</span></div>
+ <ol class="proc">
+ <li>Let <i>localName</i> be the StringValue of <i>ImportedBinding</i>.</li>
+ <li>Let <i>defaultEntry</i> be the Record {[[ModuleRequest]]: <i>module</i>, [[ImportName]]: <code>"default"</code>,
+ [[LocalName]]: <i>localName</i> }.</li>
+ <li>Let <i>entries</i> be a new <a href="#sec-list-and-record-specification-type">List</a> containing
+ <i>defaultEntry.</i></li>
+ <li>Append to <i>entries</i> the elements of the ImportEntriesForModule of <i>NamedImports</i> with argument
+ <i>module</i>.</li>
+ <li>Return <i>entries</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">NamedImports</span> <span class="geq">:</span> <code class="t">{</code> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ImportsList</span> <span class="geq">:</span> <span class="nt">ImportsList</span> <code class="t">,</code> <span class="nt">ImportSpecifier</span></div>
+ <ol class="proc">
+ <li>Let <i>specs</i> be the ImportEntriesForModule of <i>ImportsList</i> with argument <i>module</i>.</li>
+ <li>Append to <i>specs</i> the elements of the ImportEntriesForModule of <i>ImportSpecifier</i> with argument
+ <i>module</i>.</li>
+ <li>Return <i>specs</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ImportSpecifier</span> <span class="geq">:</span> <span class="nt">ImportedBinding</span></div>
+ <ol class="proc">
+ <li>Let <i>localName</i> be the StringValue of <i>ImportedBinding</i>.</li>
+ <li>Let <i>entry</i> be the Record {[[ModuleRequest]]: <i>module</i>, [[ImportName]]: <i>localName</i> , [[LocalName]]:
+ <i>localName</i> }.</li>
+ <li>Return a new <a href="#sec-list-and-record-specification-type">List</a> containing <i>entry</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ImportSpecifier</span> <span class="geq">:</span> <span class="nt">IdentifierName</span> <code class="t">as</code> <span class="nt">ImportedBinding</span></div>
+ <ol class="proc">
+ <li>Let <i>importName</i> be the StringValue of <i>IdentifierName</i>.</li>
+ <li>Let <i>localName</i> be the StringValue of <i>ImportedBinding</i>.</li>
+ <li>Let <i>entry</i> be the Record {[[ModuleRequest]]: <i>module</i>, [[ImportName]]: <i>importName</i>, [[LocalName]]:
+ <i>localName</i> }.</li>
+ <li>Return a new <a href="#sec-list-and-record-specification-type">List</a> containing <i>entry</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-imports-static-semantics-modulerequests">
+ <h1><span class="secnum" id="sec-15.2.1.5"><a href="#sec-imports-static-semantics-modulerequests"
+ title="link to this section">15.2.1.5</a></span> Static Semantics: ModuleRequests</h1>
+
+ <p>See also: <a href="#sec-module-static-semantics-static-semantics-modulerequests">15.2.0.9</a>, <a
+ href="#sec-exports-static-semantics-modulerequests">15.2.2.5</a>.</p>
+
+ <div class="gp prod"><span class="nt">ImportDeclaration</span> <span class="geq">:</span> <code class="t">import</code> <span class="nt">ImportClause</span> <span class="nt">FromClause</span> <code class="t">;</code></div>
+ <ol class="proc">
+ <li>Return ModuleRequests of <i>FromClause</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ModuleImport</span> <span class="geq">:</span> <code class="t">module</code> <span class="nt">ImportedBinding</span> <span class="nt">FromClause</span> <code class="t">;</code></div>
+ <ol class="proc">
+ <li>Return ModuleRequests of <i>FromClause</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ModuleSpecifier</span> <span class="geq">:</span> <span class="nt">StringLiteral</span></div>
+ <ol class="proc">
+ <li>Return a <a href="#sec-list-and-record-specification-type">List</a> containing the StringValue of
+ <i>StringLiteral</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-runtime-semantics-module-objects">
+ <h1><span class="secnum" id="sec-15.2.1.6"><a href="#sec-runtime-semantics-module-objects"
+ title="link to this section">15.2.1.6</a></span> Runtime Semantics: Module Objects</h1>
+ <div class="gp prod"><span class="nt">ModuleImport</span> <span class="geq">:</span> <code class="t">module</code> <span class="nt">ImportedBinding</span> <span class="nt">FromClause</span> <code class="t">;</code></div>
+
+ <p>An <span class="nt">ModuleImport</span> imports a module and introduces a single binding within the containing module
+ environment. The value of such a binding as a Module object.</p>
+
+ <p>A Module object is an exotic object whose own properties corresponding corresponding to the ExportedBindings of the
+ module identifed by the <span class="nt">ModuleImport</span> <span class="nt">FromClause</span>. Each property name is
+ the StringValue of the corresponding exported binding. These are the only properties of an Module object. Each one is a
+ read-only property with attributes {[[Configurable]]: <span class="value">false</span>, [[Enumerable]]: <span
+ class="value">true</span>}. Module objects are not extensible.</p>
+
+ <p style="background-color: #FFC000">TO DO</p>
+
+ <p style="background-color: #FFC000">Needs to decide whether a module object is an ordinary or an exotic object. Whether
+ properties are accessor or defined via [[Get]], etc.</p>
+ </section>
+ </section>
+
+ <section id="sec-exports">
+ <div class="front">
+ <h1><span class="secnum" id="sec-15.2.2"><a href="#sec-exports" title="link to this section">15.2.2</a></span>
+ Exports</h1>
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ExportDeclaration</span> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">export</code> <code class="t">*</code> <span class="nt">FromClause</span> <code class="t">;</code></div>
+ <div class="rhs"><code class="t">export</code> <span class="nt">ExportClause</span><sub>[NoReference]</sub> <span class="nt">FromClause</span> <code class="t">;</code></div>
+ <div class="rhs"><code class="t">export</code> <span class="nt">ExportClause</span> <code class="t">;</code></div>
+ <div class="rhs"><code class="t">export</code> <span class="nt">VariableStatement</span></div>
+ <div class="rhs"><code class="t">export</code> <span class="nt">Declaration</span><sub>[Default]</sub></div>
+ <div class="rhs"><code class="t">export</code> <code class="t">default</code> <span class="nt">AssignmentExpression</span><sub>[In]</sub> <code class="t">;</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ExportClause</span><sub>[NoReference]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">{</code> <code class="t">}</code></div>
+ <div class="rhs"><code class="t">{</code> <span class="nt">ExportsList</span><sub>[?NoReference]</sub> <code class="t">}</code></div>
+ <div class="rhs"><code class="t">{</code> <span class="nt">ExportsList</span><sub>[?NoReference]</sub> <code class="t">,</code> <code class="t">}</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ExportsList</span><sub>[NoReference]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="nt">ExportSpecifier</span><sub>[?NoReference]</sub></div>
+ <div class="rhs"><span class="nt">ExportsList</span><sub>[?NoReference]</sub> <code class="t">,</code> <span class="nt">ExportSpecifier</span><sub>[?NoReference]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ExportSpecifier</span><sub>[NoReference]</sub> <span class="geq">:</span></div>
+ <div class="rhs"><span class="grhsannot">[~NoReference]</span> <span class="nt">IdentifierReference</span></div>
+ <div class="rhs"><span class="grhsannot">[~NoReference]</span> <span class="nt">IdentifierReference</span> <code class="t">as</code> <span class="nt">IdentifierName</span></div>
+ <div class="rhs"><span class="grhsannot">[+NoReference]</span> <span class="nt">IdentifierName</span></div>
+ <div class="rhs"><span class="grhsannot">[+NoReference]</span> <span class="nt">IdentifierName</span> <code class="t">as</code> <span class="nt">IdentifierName</span></div>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> <i>ExportSpecifier</i> is used to export bindings from the enclosing module
+ <i>Module</i>. <i>ExportSpecifier</i><sub><span style="font-family: sans-serif">[</span>NoReference<span
+ style="font-family: sans-serif">]</span></sub> is used to export bindings from a referenced <i>Module</i>. In that case
+ <i>IdentifierReference</i> restrictions are not applied to the naming of the items to be exported because they are not
+ used to create local bindings.</p>
+ </div>
+ </div>
+
+ <section id="sec-exports-static-semantics-boundnames">
+ <h1><span class="secnum" id="sec-15.2.2.1"><a href="#sec-exports-static-semantics-boundnames"
+ title="link to this section">15.2.2.1</a></span> Static Semantics: BoundNames</h1>
+
+ <p>See also: <a href="#sec-let-and-const-declarations-static-semantics-boundnames">13.2.1.2</a>, <a
+ href="#sec-variable-statement-static-semantics-boundnames">13.2.2.1</a>, <a
+ href="#sec-identifiers-static-semantics-boundnames">12.1.2</a>, <a
+ href="#sec-for-in-and-for-of-statements-static-semantics-boundnames">13.6.4.2</a>, <a
+ href="#sec-function-definitions-static-semantics-boundnames">14.1.3</a>, <a
+ href="#sec-arrow-function-definitions-static-semantics-boundnames">14.2.2</a>, <a
+ href="#sec-generator-function-definitions-static-semantics-boundnames">14.4.2</a>, <a
+ href="#sec-class-definitions-static-semantics-boundnames">14.5.2</a>, <a
+ href="#sec-imports-static-semantics-boundnames">15.2.1.2</a>.</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ExportDeclaration</span> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">export</code> <code class="t">*</code> <span class="nt">FromClause</span> <code class="t">;</code></div>
+ <div class="rhs"><code class="t">export</code> <span class="nt">ExportClause</span> <span class="nt">FromClause</span> <code class="t">;</code></div>
+ <div class="rhs"><code class="t">export</code> <span class="nt">ExportClause</span> <code class="t">;</code></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+
+ <p><span style="font-family: Times New Roman"><span class="prod"><span class="nt">ExportDeclaration</span> <span
+ class="geq">:</span></span></span> <code>export</code> <span class="nt">VariableStatement</span> <code>;</code></p>
+
+ <ol class="proc">
+ <li>Return the BoundNames of <i>VariableStatement</i>.</li>
+ </ol>
+
+ <p><span style="font-family: Times New Roman"><span class="prod"><span class="nt">ExportDeclaration</span> <span
+ class="geq">:</span></span></span> <code>export</code> <span class="nt">Declaration</span><code>;</code></p>
+
+ <ol class="proc">
+ <li>Return the BoundNames of <i>Declaration</i>.</li>
+ </ol>
+
+ <p><span style="font-family: Times New Roman"><span class="prod"><span class="nt">ExportDeclaration</span> <span
+ class="geq">:</span></span></span> <code>export default</code> <span
+ class="nt">AssignmentExpression</span><code>;</code></p>
+
+ <ol class="proc">
+ <li>Return a <a href="#sec-list-and-record-specification-type">List</a> containing <code>"default"</code>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-exports-static-semantics-exportedbindings">
+ <h1><span class="secnum" id="sec-15.2.2.2"><a href="#sec-exports-static-semantics-exportedbindings"
+ title="link to this section">15.2.2.2</a></span> Static Semantics: ExportedBindings</h1>
+
+ <p>See also:<a href="#sec-static-semantics-declarednames">15.2.0.2</a>.</p>
+
+ <div class="gp prod"><span class="nt">ExportDeclaration</span> <span class="geq">:</span> <code class="t">export</code> <code class="t">*</code> <span class="nt">FromClause</span> <code class="t">;</code></div>
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ExportDeclaration</span> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">export</code> <span class="nt">ExportClause</span> <span class="nt">FromClause</span> <code class="t">;</code></div>
+ <div class="rhs"><code class="t">export</code> <span class="nt">ExportClause</span> <code class="t">;</code></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return the ExportedBindings of this <i>ExportClause</i>.</li>
+ </ol>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ExportDeclaration</span> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">export</code> <span class="nt">VariableStatement</span></div>
+ <div class="rhs"><code class="t">export</code> <span class="nt">Declaration</span><sub>[Default]</sub></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return the BoundNames of this <i>ExportDeclaration</i>.</li>
+ </ol>
+
+ <p><span style="font-family: Times New Roman"><span class="prod"><span class="nt">ExportDeclaration</span> <span
+ class="geq">:</span></span></span> <code>export default</code> <span
+ class="nt">AssignmentExpression</span><code>;</code></p>
+
+ <ol class="proc">
+ <li>Return a <a href="#sec-list-and-record-specification-type">List</a> containing <code>"default"</code>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ExportClause</span> <span class="geq">:</span> <code class="t">{</code> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ExportsList</span> <span class="geq">:</span> <span class="nt">ExportsList</span> <code class="t">,</code> <span class="nt">ExportSpecifier</span></div>
+ <ol class="proc">
+ <li>Let <i>names</i> be the ExportedBindings of <i>ExportsList</i>.</li>
+ <li>Append to <i>names</i> the elements of the ExportedBindings of <i>ExportSpecifier</i>.</li>
+ <li>Return <i>names</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ExportSpecifier</span> <span class="geq">:</span> <span class="nt">IdentifierReference</span></div>
+ <ol class="proc">
+ <li>Return a <a href="#sec-list-and-record-specification-type">List</a> containing the StringValue of
+ <i>IdentifierReference</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ExportSpecifier</span> <span class="geq">:</span> <span class="nt">IdentifierReference</span> <code class="t">as</code> <span class="nt">IdentifierName</span></div>
+ <ol class="proc">
+ <li>Return a <a href="#sec-list-and-record-specification-type">List</a> containing the StringValue of
+ <i>IdentifierName</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ExportSpecifier</span> <span class="geq">:</span> <span class="nt">IdentifierName</span></div>
+ <ol class="proc">
+ <li>Return a <a href="#sec-list-and-record-specification-type">List</a> containing the StringValue of
+ <i>IdentifierName</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ExportSpecifier</span> <span class="geq">:</span> <span class="nt">IdentifierName</span> <code class="t">as</code> <span class="nt">IdentifierName</span></div>
+ <ol class="proc">
+ <li>Return a <a href="#sec-list-and-record-specification-type">List</a> containing the StringValue of the second
+ <i>IdentifierName</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-exports-static-semantics-exportentries">
+ <h1><span class="secnum" id="sec-15.2.2.3"><a href="#sec-exports-static-semantics-exportentries"
+ title="link to this section">15.2.2.3</a></span> Static Semantics: ExportEntries</h1>
+
+ <p>See also:<a href="#sec-module-static-semantics-static-semantics-exportentries">15.2.0.4</a>.</p>
+
+ <div class="gp prod"><span class="nt">ExportDeclaration</span> <span class="geq">:</span> <code class="t">export</code> <code class="t">*</code> <span class="nt">FromClause</span> <code class="t">;</code></div>
+ <ol class="proc">
+ <li>Let <i>module</i> be the sole element of ModuleRequests of <i>FromClause</i>.</li>
+ <li>Let <i>entry</i> be the Record {[[ModuleRequest]]: <i>module</i>, [[ImportName]]: <span style="font-family:
+ sans-serif">all</span>, [[LocalName]]: <b>null</b>, [[ExportName]]: <b>null</b> }.</li>
+ <li>Return a new <a href="#sec-list-and-record-specification-type">List</a> containing <i>entry</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ExportDeclaration</span> <span class="geq">:</span> <code class="t">export</code> <span class="nt">ExportClause</span> <span class="nt">FromClause</span> <code class="t">;</code></div>
+ <ol class="proc">
+ <li>Let <i>module</i> be the sole element of ModuleRequests of <i>FromClause</i>.</li>
+ <li>Return ExportEntriesForModule of <i>ExportClause</i> with argument <i>module</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ExportDeclaration</span> <span class="geq">:</span> <code class="t">export</code> <span class="nt">ExportClause</span> <code class="t">;</code></div>
+ <ol class="proc">
+ <li>Return ExportEntriesForModule of <i>ExportClause</i> with argument <b>null</b>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ExportDeclaration</span> <span class="geq">:</span> <code class="t">export</code> <span class="nt">VariableStatement</span> <code class="t">;</code></div>
+ <ol class="proc">
+ <li>Let <i>entries</i> be a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Let <i>names</i> be the BoundNames of <i>VariableStatement</i>.</li>
+ <li>Repeat for each <i>name</i> in <i>names,</i>
+ <ol class="block">
+ <li>Append to <i>entries</i> the Record {[[ModuleRequest]]: <b>null</b>, [[ImportName]]: <b>null</b>, [[LocalName]]:
+ <i>name</i>, [[ExportName]]: <i>name</i> }.</li>
+ </ol>
+ </li>
+ <li>Return <i>entries</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ExportDeclaration</span> <span class="geq">:</span> <code class="t">export</code> <span class="nt">Declaration</span> <code class="t">;</code></div>
+ <ol class="proc">
+ <li>Let <i>entries</i> be a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Let <i>names</i> be the BoundNames of <i>Declaration</i>.</li>
+ <li>Repeat for each <i>name</i> in <i>names,</i>
+ <ol class="block">
+ <li>Append to <i>entries</i> the Record {[[ModuleRequest]]: <b>null</b>, [[ImportName]]: <b>null</b>, [[LocalName]]:
+ <i>name</i>, [[ExportName]]: <i>name</i> }.</li>
+ </ol>
+ </li>
+ <li>Return <i>entries</i>.</li>
+ </ol>
+
+ <p><span style="font-family: Times New Roman"><span class="prod"><span class="nt">ExportDeclaration</span> <span
+ class="geq">:</span></span></span> <code>export default</code> <span
+ class="nt">AssignmentExpression</span><code>;</code></p>
+
+ <ol class="proc">
+ <li>Let <i>entry</i> be the Record {[[ModuleRequest]]: <b>null</b>, [[ImportName]]: <b>null</b>, [[LocalName]]:
+ <code>"default"</code>, [[ExportName]]: <code>"default"</code>}.</li>
+ <li>Return a new <a href="#sec-list-and-record-specification-type">List</a> containing <i>entry</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-static-semantics-exportentriesformodule">
+ <h1><span class="secnum" id="sec-15.2.2.4"><a href="#sec-static-semantics-exportentriesformodule"
+ title="link to this section">15.2.2.4</a></span> Static Semantics: ExportEntriesForModule</h1>
+
+ <p>With parameter <var>module</var>.</p>
+
+ <div class="gp prod"><span class="nt">ExportClause</span> <span class="geq">:</span> <code class="t">{</code> <code class="t">}</code></div>
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ExportsList</span> <span class="geq">:</span> <span class="nt">ExportsList</span> <code class="t">,</code> <span class="nt">ExportSpecifier</span></div>
+ <ol class="proc">
+ <li>Let <i>specs</i> be the ExportEntriesForModule of <i>ExportsList</i> with argument <i>module</i>.</li>
+ <li>Append to <i>specs</i> the elements of the ExportEntriesForModule of <i>ExportSpecifier</i> with argument
+ <i>module</i>.</li>
+ <li>Return <i>specs</i>.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ExportSpecifier</span> <span class="geq">:</span> <span class="nt">IdentifierReference</span></div>
+ <ol class="proc">
+ <li>Let <i>localName</i> be the StringValue of <i>IdentifierReference</i>.</li>
+ <li>Return a new <a href="#sec-list-and-record-specification-type">List</a> containing the Record {[[ModuleRequest]]:
+ <i>module</i>, [[ImportName]]: <b>null</b>, [[LocalName]]: <i>localName</i>, [[ExportName]]: <i>localName</i>
+ }.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ExportSpecifier</span> <span class="geq">:</span> <span class="nt">IdentifierReference</span> <code class="t">as</code> <span class="nt">IdentifierName</span></div>
+ <ol class="proc">
+ <li>Let <i>localName</i> be the StringValue of <i>IdentifierReference</i>.</li>
+ <li>Let <i>exportName</i> be the StringValue of <i>IdentifierName</i>.</li>
+ <li>Return a new <a href="#sec-list-and-record-specification-type">List</a> containing the Record {[[ModuleRequest]]:
+ <i>module</i>, [[ImportName]]: <b>null</b>, [[LocalName]]: <i>localName</i>, [[ExportName]]: <i>exportName</i>
+ }.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ExportSpecifier</span> <span class="geq">:</span> <span class="nt">IdentifierName</span></div>
+ <ol class="proc">
+ <li>Let <i>sourceName</i> be the StringValue of <i>IdentifierName</i>.</li>
+ <li>Return a new <a href="#sec-list-and-record-specification-type">List</a> containing the Record {[[ModuleRequest]]:
+ <i>module</i>, [[ImportName]]: <i>sourceName</i>, [[LocalName]]: <b>null</b>, [[ExportName]]: <i>sourceName</i>
+ }.</li>
+ </ol>
+ <div class="gp prod"><span class="nt">ExportSpecifier</span> <span class="geq">:</span> <span class="nt">IdentifierName</span> <code class="t">as</code> <span class="nt">IdentifierName</span></div>
+ <ol class="proc">
+ <li>Let <i>sourceName</i> be the StringValue of the first <i>IdentifierName</i>.</li>
+ <li>Let <i>exportName</i> be the StringValue of the second <i>IdentifierName</i>.</li>
+ <li>Return a new <a href="#sec-list-and-record-specification-type">List</a> containing the Record {[[ModuleRequest]]:
+ <i>module</i>, [[ImportName]]: <i>sourceName</i>, [[LocalName]]: <b>null</b>, [[ExportName]]: <i>exportName</i>
+ }.</li>
+ </ol>
+ </section>
+
+ <section id="sec-exports-static-semantics-modulerequests">
+ <h1><span class="secnum" id="sec-15.2.2.5"><a href="#sec-exports-static-semantics-modulerequests"
+ title="link to this section">15.2.2.5</a></span> Static Semantics: ModuleRequests</h1>
+
+ <p>See also: <a href="#sec-module-static-semantics-static-semantics-modulerequests">15.2.0.9</a>, <a
+ href="#sec-imports-static-semantics-modulerequests">15.2.1.5</a>.</p>
+
+ <div class="gp prod"><span class="nt">ExportDeclaration</span> <span class="geq">:</span> <code class="t">export</code> <span class="nt">ExportClause</span> <span class="nt">FromClause</span> <code class="t">;</code></div>
+ <ol class="proc">
+ <li>Return the ModuleRequests of <i>FromClause</i>.</li>
+ </ol>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ExportDeclaration</span> <span class="geq">:</span></div>
+ <div class="rhs"><code class="t">export</code> <span class="nt">ExportClause</span> <code class="t">;</code></div>
+ <div class="rhs"><code class="t">export</code> <span class="nt">VariableStatement</span></div>
+ <div class="rhs"><code class="t">export</code> <span class="nt">Declaration</span></div>
+ <div class="rhs"><code class="t">export</code> <code class="t">default</code> <span class="nt">AssignmentExpression</span> <code class="t">;</code></div>
+ </div>
+
+ <ol class="proc">
+ <li>Return a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-runtime-semantics-loader-state">
+ <div class="front">
+ <h1><span class="secnum" id="sec-15.2.3"><a href="#sec-runtime-semantics-loader-state"
+ title="link to this section">15.2.3</a></span> Runtime Semantics: Loader State</h1>
+ </div>
+
+ <section id="sec-loader-records-and-loader-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-15.2.3.1"><a href="#sec-loader-records-and-loader-objects"
+ title="link to this section">15.2.3.1</a></span> Loader Records and Loader Objects</h1>
+
+ <p>Loader Records contain the state of a of distinct module loading context. Each Loader Record has the fields defined
+ in <a href="#table-34">Table 34</a>. Loader objects (<a href="#sec-loader-objects">26.3</a>) are ECMAScript objects that
+ permit ECMAScript code to define and manage module loading contexts.</p>
+
+ <figure>
+ <figcaption><span id="table-34">Table 34</span> — Loader Record Fields</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 0px solid black; border-top: 2px solid #000000">Field Name</th>
+ <th style="border-bottom: 1px solid #000000; border-left: 0px solid black; border-right: 1px solid #000000; border-top: 2px solid #000000">Value Type</th>
+ <th style="border-bottom: 1px solid #000000; border-right: 1px solid #000000; border-top: 2px solid #000000">Meaning</th>
+ </tr>
+ <tr>
+ <td>[[Realm]]</td>
+ <td><a href="#sec-code-realms">Realm</a> Record</td>
+ <td>The <a href="#sec-code-realms">Realm</a> associated with the loader. All scripts and modules evaluated by this loader run in the scope of the global object associated with this <a href="#sec-code-realms">Realm</a>.</td>
+ </tr>
+ <tr>
+ <td>[[Modules]]</td>
+
+ <td>
+ <p><a href="#sec-list-and-record-specification-type">List</a> of</p>
+
+ <p>Record {[[Name]], [[Module]]} where [[Name]] is a String and [[Module]] is a Module Record</p>
+ </td>
+
+ <td>Normalized names bound to fully linked Module records. The list can contain modules whose code has not yet been evaluated. However, except for the case of cyclic imports, such modules are not exposed to user code.</td>
+ </tr>
+ <tr>
+ <td>[[Loads]]</td>
+ <td><a href="#sec-list-and-record-specification-type">List</a> of Load Record</td>
+ <td>Outstanding asynchronous module load requests that have been made to this loader.</td>
+ </tr>
+ <tr>
+ <td>[[LoaderObj]</td>
+ <td>Object or Undefined</td>
+ <td>The Loader object (<a href="#sec-loader-objects">26.3</a>) that reflects this Loader Record.</td>
+ </tr>
+ </table>
+ </figure>
+ </div>
+
+ <section id="sec-createloaderrecord">
+ <h1><span class="secnum" id="sec-15.2.3.1.1"><a href="#sec-createloaderrecord"
+ title="link to this section">15.2.3.1.1</a></span> CreateLoaderRecord(realm, object) Abstract Operation</h1>
+
+ <p>The abstract operation CreateLoaderRecord creates and returns a new Loader Record. The argument <var>realm</var> is
+ the <a href="#sec-code-realms">Realm</a> record that will be associated with Loader. The argument <var>object</var> is
+ the either <code>undefined</code> or the Loader object that will reflect this Loader record.</p>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>loader</i> be a new Loader Record.</li>
+ <li>Set <i>loader</i>.[[Realm]] to <i>realm</i>.</li>
+ <li>Set <i>loader</i>.[[Modules]] to a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Set <i>loader</i>.[[Loads]] to a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Set <i>loader</i>.[[LoaderObj]] to <i>object</i>.</li>
+ <li>Return <i>loader</i>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-load-records-and-loadrequest-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-15.2.3.2"><a href="#sec-load-records-and-loadrequest-objects"
+ title="link to this section">15.2.3.2</a></span> Load Records and LoadRequest Objects</h1>
+
+ <p>The Load Record represents an attempt to locate, fetch, translate, and parse a single module.</p>
+
+ <p>Each Load Record has the fields defined in <a href="#table-35">Table 35</a>:</p>
+
+ <figure>
+ <figcaption><span id="table-35">Table 35</span> — Load Record Fields</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 0px solid black; border-top: 2px solid #000000">Field Name</th>
+ <th style="border-bottom: 1px solid #000000; border-left: 0px solid black; border-right: 1px solid #000000; border-top: 2px solid #000000">Value Type</th>
+ <th style="border-bottom: 1px solid #000000; border-right: 1px solid #000000; border-top: 2px solid #000000">Meaning</th>
+ </tr>
+ <tr>
+ <td>[[Status]]</td>
+ <td>One of: <code>"loading"</code>, <code>"loaded"</code>, <code>"linked"</code>, <code>"failed"</code>.</td>
+ <td>The current state of this Load request.</td>
+ </tr>
+ <tr>
+ <td>[[Name]]</td>
+ <td>String | <span class="value">undefined</span></td>
+ <td>The normalized name of the module being loaded, or <b>undefined</b> if loading an anonymous module.</td>
+ </tr>
+ <tr>
+ <td>[[LinkSets]]</td>
+ <td><a href="#sec-list-and-record-specification-type">List</a> of LinkSet Record</td>
+ <td>A <a href="#sec-list-and-record-specification-type">List</a> of all LinkSets that require this Load request to succeed. There is a many-to-many relation between Load records and LinkSets. A single <code>import()</code> call can have a large dependency tree, involving many Load records. Many <code>import()</code> calls, if they depend on the same module, can be waiting for a single Load to complete.</td>
+ </tr>
+ <tr>
+ <td>[[Metadata]]</td>
+ <td>Object</td>
+ <td>An object passed to each loader hook which hooks may use for any purpose.</td>
+ </tr>
+ <tr>
+ <td>[[Address]]</td>
+ <td>Object | <span class="value">undefined</span></td>
+ <td>The result of the locate hook.</td>
+ </tr>
+ <tr>
+ <td>[[Source]]</td>
+ <td>String | <span class="value">undefined</span></td>
+ <td>The result of the translate hook.</td>
+ </tr>
+ <tr>
+ <td>[[Kind]]</td>
+ <td>One of: <span class="value">undefined</span>, dynamic, declarative</td>
+ <td>Once the Load reaches the <code>"loaded"</code> state, either declarative or dynamic. If the instantiate hook returned <span class="value">undefined</span>, the module is declarative, and <i>load</i>.[[Body]] contains a Module parse. Otherwise, the instantiate hook returned a ModuleFactory object and [[Execute]] contains the .execute callable object.</td>
+ </tr>
+ <tr>
+ <td>[[Body]]</td>
+ <td><span class="value">undefined</span> or a parse result</td>
+ <td>If [[Kind]] is <b>declarative</b>, the parse of a <span class="nt">Module</span> production. Otherwise <span class="value">undefined</span>.</td>
+ </tr>
+ <tr>
+ <td>[[Execute]]</td>
+ <td></td>
+ <td>If [[Kind]] is <b>dynamic</b>, the value of <code>factory.execute</code>. Otherwise <span class="value">undefined</span>.</td>
+ </tr>
+ <tr>
+ <td>[[Dependencies]]</td>
+ <td>Undefined or <a href="#sec-list-and-record-specification-type">List</a> of Records</td>
+ <td>If [[Status]] is not <code>"loading"</code>, a <a href="#sec-list-and-record-specification-type">List</a> of pairs. Each pair consists of two strings: a module name as it appears in a module, import, or export from declaration in <i>load</i>.[[Body]], and the corresponding normalized module name.</td>
+ </tr>
+ <tr>
+ <td>[[Exception]]</td>
+ <td></td>
+ <td>If [[Status]] is "failed", the exception value that was thrown, causing the load to fail. Otherwise, null.</td>
+ </tr>
+ <tr>
+ <td>[[Module]]</td>
+ <td></td>
+ <td>The Module object produced by this load, or <span class="value">undefined</span>.</td>
+ </tr>
+ </table>
+ </figure>
+
+ <p>A LoadRequest object is an ordinary Object, inheriting from <code>Object.prototype</code> with own data properties
+ whose values corresponding certain fields of a corresonding Load Record. A LoadRequest object is created when the value
+ of those fields need to be passed to an ECMAScript function. Every LoadRequest object has <code>name</code>, and
+ <code>metadata</code> properties corresponding to the [[Name]] and [[Metadata]] fields of a Load Record. A LoadRequest
+ object may also have <code>address</code> and <code>source</code> properties corresponding to the [[Address]] and
+ [[Source]] fields of a Load record.</p>
+ </div>
+
+ <section id="sec-createload">
+ <h1><span class="secnum" id="sec-15.2.3.2.1"><a href="#sec-createload"
+ title="link to this section">15.2.3.2.1</a></span> CreateLoad(name) Abstract Operation</h1>
+
+ <p>The abstract operation CreateLoad creates and returns a new Load Record. The argument <var>name</var> is either
+ <code>undefined</code>, indicating an anonymous module, or a normalized module <span style="font-family: Times New
+ Roman">name</span>.</p>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>load</i> be a new Load Record.</li>
+ <li>Set <i>load</i>.[[Status]] to <code>"loading"</code>.</li>
+ <li>Set <i>load</i>.[[Name]] to <i>name</i>.</li>
+ <li>Set <i>load</i>.[[LinkSets]] to a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Set <i>load</i>.[[Metadata]] to <i>metadata</i> <a
+ href="#sec-objectcreate">ObjectCreate</a>(%ObjectPrototype%).</li>
+ <li>Set all other fields of <i>load</i> to <b>undefined</b>.</li>
+ <li>Return <i>load</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-createloadrequestobject">
+ <h1><span class="secnum" id="sec-15.2.3.2.2"><a href="#sec-createloadrequestobject"
+ title="link to this section">15.2.3.2.2</a></span> CreateLoadRequestObject(name, metadata, address, source) Abstract
+ Operation</h1>
+
+ <p>The abstract operation CreateLoadRequestObject performed with arguments <var>name</var>, <var>metadata</var>, and
+ optional arguments <var>address</var> and <var>source</var> returns a new LoadRequest Object. It performs the following
+ steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>obj</i> be <a href="#sec-objectcreate">ObjectCreate</a>(%ObjectPrototype%, ()).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: The following operations will never result in abrupt
+ completions.</li>
+ <li>Perform <a href="#sec-createdataproperty">CreateDataProperty</a> (<i>obj</i>, <code>"name"</code>,
+ <i>name</i>).</li>
+ <li>Perform <a href="#sec-createdataproperty">CreateDataProperty</a> (<i>obj</i>, <code>"metadata"</code>,
+ <i>metadata</i>).</li>
+ <li>If <i>address</i> was passed, then perform <a href="#sec-createdataproperty">CreateDataProperty</a> (<i>obj</i>,
+ <code>"address"</code>, <i>address</i>).</li>
+ <li>If <i>source</i> was passed, then perform <a href="#sec-createdataproperty">CreateDataProperty</a> (<i>obj</i>,
+ <code>"source"</code>, <i>source</i>).</li>
+ <li>Return <i>obj</i>.</li>
+ </ol>
+ </section>
+ </section>
+ </section>
+
+ <section id="sec-runtime-semantics-module-loading">
+ <div class="front">
+ <h1><span class="secnum" id="sec-15.2.4"><a href="#sec-runtime-semantics-module-loading"
+ title="link to this section">15.2.4</a></span> Runtime Semantics: Module Loading</h1>
+ </div>
+
+ <section id="sec-loadmodule">
+ <h1><span class="secnum" id="sec-15.2.4.1"><a href="#sec-loadmodule" title="link to this section">15.2.4.1</a></span>
+ LoadModule(loader, name, options) Abstract Operation</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>loader</i> is a Loader record.</li>
+ <li>Let <i>name</i> be <a href="#sec-tostring">ToString</a>(<i>name</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>name</i>).</li>
+ <li>Let <i>address</i> be <a href="#sec-getoption">GetOption</a>(<i>options</i>, <code>"address"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>address</i>).</li>
+ <li>If <i>address</i> is <b>undefined</b>, let <i>step</i> be <code>"locate"</code>.</li>
+ <li>Else, let <i>step</i> be <code>"fetch"</code>.</li>
+ <li>Let <i>metadata</i> be <a href="#sec-objectcreate">ObjectCreate</a>(%ObjectPrototype%).</li>
+ <li>Return <a href="#sec-promiseofstartloadpartwaythrough">PromiseOfStartLoadPartwayThrough</a>( <i>step</i>,
+ <i>loader</i>, <i>name</i>, <i>metadata</i>, <i>source</i>, <i>address</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-requestload">
+ <div class="front">
+ <h1><span class="secnum" id="sec-15.2.4.2"><a href="#sec-requestload" title="link to this section">15.2.4.2</a></span>
+ RequestLoad(loader, request, refererName, refererAddress) Abstract Operation</h1>
+
+ <p>The RequestLoad abstract operation normalizes the given module name, <var>request</var>, and returns a Promise object
+ that resolves to the value of a Load object for the given module.</p>
+
+ <p>The <var>loader</var> argument is a Loader record.</p>
+
+ <p><var>request</var> is the (non-normalized) name of the module to be imported, as it appears in the import-declaration
+ or as the argument to <code>loader.load()</code> or <code>loader.import()</code>.</p>
+
+ <p><var>refererName</var> and <var>refererAddress</var> provide information about the context of the
+ <code>import()</code> call or import-declaration. This information is passed to all the <var>loader</var> hooks.</p>
+
+ <p>If the requested module is already in the <var>loader</var>'s module registry, RequestLoad returns a Promise object
+ for a Load with the [[Status]] field set to <code>"linked"</code>. If the requested module is loading or loaded but not
+ yet linked, RequestLoad returns a Promise object for an existing Load object from <var>loader</var>.[[Loads]].
+ Otherwise, RequestLoad starts loading the module and returns a Promise object for a new Load Record.</p>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be a new anonymous function as defined by CallNormalize.</li>
+ <li>Set <i>F</i>’s [[Loader]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to
+ <i>loader</i>.</li>
+ <li>Set <i>F</i>’s [[Request]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to
+ <i>request</i>.</li>
+ <li>Set <i>F</i>’s [[RefererName]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>
+ to <i>refererName</i>.</li>
+ <li>Set <i>F</i>’s [[RefererAddress]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> to <i>refererAddress</i>.</li>
+ <li>Let <i>p</i> be <a href="#sec-promisenew">PromiseNew</a>(<i>F</i>).</li>
+ <li>Let <i>G</i> be a new built-in function as defined by GetOrCreateLoad.</li>
+ <li>Set <i>G</i>’s [[Loader]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to
+ <i>loader</i>.</li>
+ <li>Return <a href="#sec-promisethen">PromiseThen</a>(<i>p</i>, <i>G</i>).</li>
+ </ol>
+ </div>
+
+ <section id="sec-callnormalize-resolve-reject-functions">
+ <h1><span class="secnum" id="sec-15.2.4.2.1"><a href="#sec-callnormalize-resolve-reject-functions"
+ title="link to this section">15.2.4.2.1</a></span> CallNormalize(resolve, reject) Functions</h1>
+
+ <p>A CallNormalize function is an anonymous built-in function that calls a <var>loader</var>'s normalize hook.</p>
+
+ <p>Each CallNormalize function has internal slots [[Loader]], [[Request]], [[RefererName]], and [[RefererAddress]].</p>
+
+ <p>When a CallNormalize function <var>F</var> is called with arguments <var>resolve</var> and <var>reject</var>, the
+ following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>loader</i> be the value of <i>F</i>’s [[Loader]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>request</i> be <i>F</i>’s [[Request]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>refererName</i> be the value of <i>F</i>’s [[RefererName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>refererAddress</i> be the value of <i>F</i>’s [[RefererAddress]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>loaderObj</i> be <i>loader</i>.[[LoaderObj]].</li>
+ <li>Let <i>normalizeHook</i> be <a href="#sec-get-o-p">Get</a>(<i>loaderObj</i>, <code>"normalize"</code>).</li>
+ <li>Let <i>name</i> be the result of calling the [[Call]] internal method of <i>normalizeHook</i> passing
+ <i>loaderObj</i> and (<i>request</i>, <i>refererName</i>, <i>refererAddress</i>) as arguments.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>name</i>).</li>
+ <li>Return the result of calling the [[Call]] internal method of <i>resolve</i> passing <b>undefined</b> and
+ (<i>name</i>) as arguments.</li>
+ </ol>
+ </section>
+
+ <section id="sec-getorcreateload-name-functions">
+ <h1><span class="secnum" id="sec-15.2.4.2.2"><a href="#sec-getorcreateload-name-functions"
+ title="link to this section">15.2.4.2.2</a></span> GetOrCreateLoad(name) Functions</h1>
+
+ <p>A GetOrCreateLoad function is an anonymous function that gets or creates a Load Record for a given module
+ <var>name</var>.</p>
+
+ <p>Each GetOrCreateLoad function has a [[Loader]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a>.</p>
+
+ <p>When a GetOrCreateLoad function <var>F</var> is called with argument <var>name</var>, the following steps are
+ taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>loader</i> be <i>F</i>’s [[Loader]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>name</i> be <a href="#sec-tostring">ToString</a>(<i>name</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>name</i>).</li>
+ <li>Let <i>modules</i> be the value of <i>loaderRecord.</i>[[Modules]],</li>
+ <li>Repeat for each Record {[[key]], [[value]]} <i>p</i> that is an element of <i>loader</i>.[[Modules], do
+ <ol class="block">
+ <li>If <a href="#sec-samevalue">SameValue</a>(<i>p</i>.[[key]], <i>name</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>existingModule</i> be the [[value]] field of that Record.</li>
+ <li>Let <i>load</i> be <a href="#sec-createload">CreateLoad</a>(<i>name</i>).</li>
+ <li>Set <i>load</i>.[[Status]] to <code>"linked"</code>.</li>
+ <li>Set <i>load</i>.[[Module]] to <i>existingModule</i>.</li>
+ <li>Return <i>load</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Repeat for each Record <i>load</i> that is an element of <i>loader</i>.[[Loads]], do
+ <ol class="block">
+ <li>If <a href="#sec-samevalue">SameValue</a>(<i>load</i>.[[Name]], <i>name</i>) is <b>true</b>, then
+ <ol class="block">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>load</i>.status is either <code>"loading"</code> or
+ <code>"loaded"</code>.</li>
+ <li>Return <i>load</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Let <i>load</i> be <a href="#sec-createload">CreateLoad</a>(<i>name</i>).</li>
+ <li>Append <i>load</i> to the end of the <a href="#sec-list-and-record-specification-type">List</a>
+ <i>loader</i>.[[Loads]].</li>
+ <li>Call <a href="#sec-proceedtolocate">ProceedToLocate</a>(<i>loader</i>, <i>load</i>).</li>
+ <li>Return <i>load</i>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-proceedtolocate">
+ <div class="front">
+ <h1><span class="secnum" id="sec-15.2.4.3"><a href="#sec-proceedtolocate"
+ title="link to this section">15.2.4.3</a></span> ProceedToLocate(loader, load, p) Abstract Operation</h1>
+
+ <p>The ProceedToLocate abstract operation continues the asynchronous loading process at the <code>locate</code>
+ hook.</p>
+
+ <p>ProceedToLocate performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>p</i> be <a href="#sec-promiseof">PromiseOf</a>(<b>undefined</b>).</li>
+ <li>Let <i>F</i> be a new built-in function object as defined in CallLocate.</li>
+ <li>Set <i>F</i>’s [[Loader]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to
+ <i>loader</i>.</li>
+ <li>Set <i>F</i>’s [[Load]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to
+ <i>load</i>.</li>
+ <li>Let <i>p</i> be <a href="#sec-promisethen">PromiseThen</a>(<i>p</i>, <i>F</i>).</li>
+ <li>Return <a href="#sec-proceedtofetch">ProceedToFetch</a>(<i>loader</i>, <i>load</i>, <i>p</i>).</li>
+ </ol>
+ </div>
+
+ <section id="sec-calllocate-functions">
+ <h1><span class="secnum" id="sec-15.2.4.3.1"><a href="#sec-calllocate-functions"
+ title="link to this section">15.2.4.3.1</a></span> CallLocate Functions</h1>
+
+ <p>A CallLocate function is an anonymous built-in function that calls the <code>locate</code> loader hook. Each
+ CallLocate function has [[Loader]] and [[Load]] internal slots.</p>
+
+ <p>When a CallLocate function <var>F</var> is called, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>loader</i> be the value of <i>F</i>’s [[Loader]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>load</i> be the value of <i>F</i>’s [[Load]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>loaderObj</i> be <i>loader</i>.[[LoaderObj]].</li>
+ <li>Let <i>hook</i> be <a href="#sec-get-o-p">Get</a>(<i>loaderObj</i>, <code>"locate"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>hook</i>).</li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>hook</i>) is <b>false</b>, throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>obj</i> be <a href="#sec-createloadrequestobject">CreateLoadRequestObject</a>(<i>load</i>.[[Name]],
+ <i>load</i>.[[Metadata]]).</li>
+ <li>Return the result of calling the [[Call]] internal method of <i>hook</i> with <i>loader</i> and (<i>obj</i>) as
+ arguments.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-proceedtofetch">
+ <div class="front">
+ <h1><span class="secnum" id="sec-15.2.4.4"><a href="#sec-proceedtofetch"
+ title="link to this section">15.2.4.4</a></span> ProceedToFetch(loader, load, p) Abstract Operation</h1>
+
+ <p>The ProceedToFetch abstract operation continues the asynchronous loading process at the <code>fetch</code> hook by
+ performing the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be a new built-in function object as defined in CallFetch.</li>
+ <li>Set <i>F</i>’s [[Loader]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to
+ <i>loader</i>.</li>
+ <li>Set <i>F</i>’s [[Load]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to
+ <i>load</i>.</li>
+ <li>Set <i>F</i>’s [[AddressPromise]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> to <i>p</i>.</li>
+ <li>Let <i>p</i> be <a href="#sec-promisethen">PromiseThen</a>(<i>p</i>, <i>F</i>).</li>
+ <li>Return <a href="#sec-proceedtotranslate">ProceedToTranslate</a>(<i>loader</i>, <i>load</i>, <i>p</i>).</li>
+ </ol>
+ </div>
+
+ <section id="sec-callfetch-address-functions">
+ <h1><span class="secnum" id="sec-15.2.4.4.1"><a href="#sec-callfetch-address-functions"
+ title="link to this section">15.2.4.4.1</a></span> CallFetch(address) Functions</h1>
+
+ <p>A CallFetch function is an anonymous built-in function that calls the <code>fetch</code> loader hook. Each CallFetch
+ function has [[Loader]] and [[Load]] internal slots.</p>
+
+ <p>When a CallFetch function <var>F</var> is called with argument <var>address</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>loader</i> be the value of <i>F</i>’s [[Loader]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>load</i> be the value of <i>F</i>’s [[Load]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>load</i>.[[LinkSets]] is an empty <a href="#sec-list-and-record-specification-type">List</a>, return
+ <b>undefined</b>.</li>
+ <li>Set <i>load</i>.[[Address]] to <i>address</i>.</li>
+ <li>Let <i>loaderObj</i> be <i>loader</i>.[[LoaderObj]].</li>
+ <li>Let <i>hook</i> be <a href="#sec-get-o-p">Get</a>(<i>loaderObj</i>, <code>"fetch"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>hook</i>).</li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>hook</i>) is false, throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>obj</i> be <a href="#sec-createloadrequestobject">CreateLoadRequestObject</a>(<i>load</i>.[[Name]],
+ <i>load</i>.[[Metadata]], <i>address</i>).</li>
+ <li>Return the result of calling the [[Call]] internal method of <i>hook</i> with <i>loader</i> and (<i>obj</i>) as
+ arguments.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-proceedtotranslate">
+ <div class="front">
+ <h1><span class="secnum" id="sec-15.2.4.5"><a href="#sec-proceedtotranslate"
+ title="link to this section">15.2.4.5</a></span> ProceedToTranslate(loader, load, p) Abstract Operation</h1>
+
+ <p>The ProceedToTranslate abstract operation continues the asynchronous loading process at the <code>translate</code>
+ hook hook by performing performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be a new function object as defined in CallTranslate.</li>
+ <li>Set <i>F</i>’s [[Loader]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to
+ <i>loader</i>.</li>
+ <li>Set <i>F</i>’s [[Load]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to
+ <i>load</i>.</li>
+ <li>Let <i>p</i> be <a href="#sec-promisethen">PromiseThen</a>(<i>p</i>, <i>F</i>).</li>
+ <li>Let <i>F</i> be a new function object as defined in CallInstantiate.</li>
+ <li>Set <i>F</i>’s [[Loader]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to
+ <i>loader</i>.</li>
+ <li>Set <i>F</i>’s [[Load]] to <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>
+ <i>load</i>.</li>
+ <li>Let <i>p</i> be <a href="#sec-promisethen">PromiseThen</a>(<i>p</i>, <i>F</i>).</li>
+ <li>Let <i>F</i> be a new function object as defined in InstantiateSucceeded.</li>
+ <li>Set <i>F</i>’s [[Loader]] to <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>
+ <i>loader</i>.</li>
+ <li>Set <i>F</i>’s [[Load]] to <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>
+ <i>load</i>.</li>
+ <li>Let <i>p</i> be <a href="#sec-promisethen">PromiseThen</a>(<i>p</i>, <i>F</i>).</li>
+ <li>Let <i>F</i> be a new function object as defined in LoadFailed.</li>
+ <li>Set <i>F</i>’s [[Load]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to
+ <i>load</i>.</li>
+ <li>Return <a href="#sec-promisecatch">PromiseCatch</a>(<i>p</i>, <i>F</i>).</li>
+ </ol>
+ </div>
+
+ <section id="sec-calltranslate-functions">
+ <h1><span class="secnum" id="sec-15.2.4.5.1"><a href="#sec-calltranslate-functions"
+ title="link to this section">15.2.4.5.1</a></span> CallTranslate Functions</h1>
+
+ <p>A CallTranslate function is an anonymous built-in function that calls the <code>translate</code> loader hook. Each
+ CallTranslate function has [[Loader]] and [[Load]] internal slots.</p>
+
+ <p>When a CallTranslate function <var>F</var> is called with argument <var>source</var>, the following steps are
+ taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>loader</i> be the value of <i>F</i>’s [[Loader]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>load</i> be the value of <i>F</i>’s [[Load]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>load</i>.[[LinkSets]] is an empty <a href="#sec-list-and-record-specification-type">List</a>, return
+ <b>undefined</b>.</li>
+ <li>Let <i>hook</i> be <a href="#sec-get-o-p">Get</a>(<i>loader</i>, <code>"translate"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>hook</i>).</li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>hook</i>) is false, throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>obj</i> be <a href="#sec-createloadrequestobject">CreateLoadRequestObject</a>(<i>load</i>.[[Name,
+ <i>load</i>.[[Metadata]], <code>"</code>, <i>load</i>.[[Address]], <i>source</i>).</li>
+ <li>Return the result of calling the [[Call]] internal method of <i>hook</i> with <i>loader</i> and (<i>obj</i>) as
+ arguments.</li>
+ </ol>
+ </section>
+
+ <section id="sec-callinstantiate-functions">
+ <h1><span class="secnum" id="sec-15.2.4.5.2"><a href="#sec-callinstantiate-functions"
+ title="link to this section">15.2.4.5.2</a></span> CallInstantiate Functions</h1>
+
+ <p>A CallInstantiate function is an anonymous built-in function that calls the <code>instantiate</code>
+ <var>loader</var> <var>hook</var>. Each CallInstantiate function has [[Loader]] and [[Load]] internal slots.</p>
+
+ <p>When a CallInstantiate function <var>F</var> is called with argument <var>source</var>, the following steps are
+ taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>loader</i> be the value of <i>F</i>’s [[Loader]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>load</i> be the value of <i>F</i>’s [[Load]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>load</i>.[[LinkSets]] is an empty <a href="#sec-list-and-record-specification-type">List</a>, return
+ <b>undefined</b>.</li>
+ <li>Set <i>load</i>.[[Source]] to <i>source</i>.</li>
+ <li>Let <i>loaderObj</i> be <i>loader</i>.[[LoaderObj]].</li>
+ <li>Let <i>hook</i> be <a href="#sec-get-o-p">Get</a>(<i>loaderObj</i>, <code>"instantiate"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>hook</i>).</li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>hook</i>) is <b>false</b>, throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>obj</i> be <a href="#sec-createloadrequestobject">CreateLoadRequestObject</a>(<i>load</i>.[[Name]],
+ <i>load</i>.[[Metadata]], <i>load</i>.[[Address]], <i>source</i>).</li>
+ <li>Return the result of calling the [[Call]] internal method of <i>hook</i> with <i>loader</i> and (<i>obj</i>) as
+ arguments.</li>
+ </ol>
+ </section>
+
+ <section id="sec-instantiatesucceeded-instantiateresult-functions">
+ <h1><span class="secnum" id="sec-15.2.4.5.3"><a href="#sec-instantiatesucceeded-instantiateresult-functions"
+ title="link to this section">15.2.4.5.3</a></span> InstantiateSucceeded(instantiateResult) Functions</h1>
+
+ <p>An InstantiateSucceeded function is an anonymous function that handles the result of the <code>instantiate</code>
+ hook.</p>
+
+ <p>Each InstantiateSucceeded function has [[Loader]] and [[Load]] internal slots.</p>
+
+ <p>When an InstantiateSucceeded function <var>F</var> is called with argument <var>instantiateResult</var>, the
+ following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>loader</i> be the value of <i>F</i>’s [[Loader]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>load</i> be the value of <i>F</i>’s [[Load]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>load</i>.[[LinkSets]] is an empty <a href="#sec-list-and-record-specification-type">List</a>, return
+ <b>undefined</b>.</li>
+ <li>If <i>instantiateResult</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>body</i> be the result of parsing <i>load</i>.[[Source]], interpreted as UTF-16 encoded Unicode text as
+ described in <a href="#sec-static-semantics-utf-16encoding">10.1.1</a>, using <i>Module</i> as the goal
+ symbol. Throw a <b>SyntaxError</b> exception if the parse fails or if any static semantics errors are
+ detected.</li>
+ <li>Set <i>load</i>.[[Body]] to <i>body</i>.</li>
+ <li>Set <i>load</i>.[[Kind]] to <span style="font-family: sans-serif">declarative</span>.</li>
+ <li>Let <i>depsList</i> be the ModuleRequests of <i>body</i>.</li>
+ </ol>
+ </li>
+ <li>Else if <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>instantiateResult</i>) is Object, then
+ <ol class="block">
+ <li>Let <i>deps</i> be <a href="#sec-get-o-p">Get</a>(<i>instantiateResult</i>, <code>"deps"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>deps</i>).</li>
+ <li>If <i>deps</i> is undefined, then let <i>depsList</i> be a new empty <a
+ href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>depsList</i> be IterableToArray(<i>deps</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>depsList</i>).</li>
+ </ol>
+ </li>
+ <li>Let <i>execute</i> be <a href="#sec-get-o-p">Get</a>(<i>instantiateResult</i>, <code>"execute"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>execute</i>).</li>
+ <li>Set <i>load</i>.[[Execute]] to <i>execute</i>.</li>
+ <li>Set <i>load</i>.[[Kind]] to <span style="font-family: sans-serif">dynamic</span>.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Throw a <b>TypeError</b> exception.</li>
+ </ol>
+ </li>
+ <li>Return <a href="#sec-processloaddependencies">ProcessLoadDependencies</a>(<i>load</i>, <i>loader</i>,
+ <i>depsList</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-loadfailed-functions">
+ <h1><span class="secnum" id="sec-15.2.4.5.4"><a href="#sec-loadfailed-functions"
+ title="link to this section">15.2.4.5.4</a></span> LoadFailed Functions</h1>
+
+ <p>A LoadFailed function is an anonymous function that marks a Load Record as having failed. All LinkSets that depend on
+ the Load also fail.</p>
+
+ <p>Each LoadFailed function has a [[Load]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a>.</p>
+
+ <p>When a LoadFailed function <var>F</var> is called with argument <var>exc</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>load</i> be the value of <i>F</i>’s [[Load]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>load</i>.[[Status]] is <code>"loading"</code>.</li>
+ <li>Set <i>load</i>.[[Status]] to `"failed".</li>
+ <li>Set <i>load</i>.[[Exception]] to <i>exc</i>.</li>
+ <li>Let <i>linkSets</i> be a copy of the <a href="#sec-list-and-record-specification-type">List</a>
+ <i>load</i>.[[LinkSets]].</li>
+ <li>For each <i>linkSet</i> in <i>linkSets</i>, in the order in which the <a href="#sec-linkset-records">LinkSet
+ Records</a> were created,
+ <ol class="block">
+ <li>Call <a href="#sec-linksetfailed">LinkSetFailed</a>(<i>linkSet</i>, <i>exc</i>).</li>
+ </ol>
+ </li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>load</i>.[[LinkSets]] is empty.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-processloaddependencies">
+ <div class="front">
+ <h1><span class="secnum" id="sec-15.2.4.6"><a href="#sec-processloaddependencies"
+ title="link to this section">15.2.4.6</a></span> ProcessLoadDependencies(load, loader, depsList) Abstract
+ Operation</h1>
+
+ <p>The ProcessLoadDependencies abstract operation is called after one module has nearly finished loading. It starts new
+ loads as needed to <var>load</var> the module's dependencies.</p>
+
+ <p>ProcessLoadDependencies also arranges for LoadSucceeded to be called.</p>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>refererName</i> be <i>load</i>.[[Name]].</li>
+ <li>Set <i>load</i>.[[Dependencies]] to a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Let <i>loadPromises</i> be a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>For each <i>request</i> in <i>depsList</i>, do
+ <ol class="block">
+ <li>Let <i>p</i> be <a href="#sec-requestload">RequestLoad</a>(<i>loader</i>, <i>request</i>, <i>refererName</i>,
+ <i>load</i>.[[Address]]).</li>
+ <li>Let <i>F</i> be a new built-in function as defined by AddDependencyLoad.</li>
+ <li>Set the [[Load]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>F</i> to
+ <i>load</i>.</li>
+ <li>Set the [[Request]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>F</i> to
+ <i>request</i>.</li>
+ <li>Let <i>p</i> be <a href="#sec-promisethen">PromiseThen</a>(<i>p</i>, <i>F</i>).</li>
+ <li>Append <i>p</i> as the last element of <i>loadPromises</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>p</i> be <a href="#sec-promiseall">PromiseAll</a>(<i>loadPromises</i>).</li>
+ <li>Let <i>F</i> be a new built-in function as defined by LoadSucceeded.</li>
+ <li>Set the [[Load]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>F</i> to
+ <i>load</i>.</li>
+ <li>Return <a href="#sec-promisethen">PromiseThen</a>(<i>p</i>, <i>F</i>).</li>
+ </ol>
+ </div>
+
+ <section id="sec-adddependencyload-depload-functions">
+ <h1><span class="secnum" id="sec-15.2.4.6.1"><a href="#sec-adddependencyload-depload-functions"
+ title="link to this section">15.2.4.6.1</a></span> AddDependencyLoad(depLoad) Functions</h1>
+
+ <p>An AddDependencyLoad function is an anonymous function that adds a Load Record for a dependency to any LinkSets
+ associated with the parent Load.</p>
+
+ <p>Each AddDependencyLoad function has [[ParentLoad]] and [[Request]] internal slots.</p>
+
+ <p>When an AddDependencyLoad function <var>F</var> is called with argument <var>depLoad</var>, the following steps are
+ taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>parentLoad</i> be the value of <i>F</i>’s [[ParentLoad]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>request</i> be the value of <i>F</i>’s [[Request]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: There is no Record in the <a
+ href="#sec-list-and-record-specification-type">List</a> <i>parentLoad</i>.[[Dependencies]] whose [[key]] field is
+ equal to <i>request</i>.</li>
+ <li>Append the Record {[[key]]: <i>request</i>, [[value]]: <i>depLoad</i>.[[Name]]} to the end of the <a
+ href="#sec-list-and-record-specification-type">List</a> <i>parentLoad</i>.[[Dependencies]].</li>
+ <li>If <i>depLoad</i>.[[Status]] is not <code>"linked"</code>, then
+ <ol class="block">
+ <li>Let <i>linkSets</i> be a copy of the <a href="#sec-list-and-record-specification-type">List</a>
+ <i>parentLoad</i>.[[LinkSets]].</li>
+ <li>For each <i>linkSet</i> in <i>linkSets</i>, do
+ <ol class="block">
+ <li>Call <a href="#sec-addloadtolinkset">AddLoadToLinkSet</a>(<i>linkSet</i>, <i>depLoad</i>).</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </section>
+
+ <section id="sec-loadsucceeded-functions">
+ <h1><span class="secnum" id="sec-15.2.4.6.2"><a href="#sec-loadsucceeded-functions"
+ title="link to this section">15.2.4.6.2</a></span> LoadSucceeded Functions</h1>
+
+ <p>A LoadSucceeded function is an anonymous function that transitions a Load Record from <code>"loading"</code> to
+ <code>"loaded"</code> and notifies all associated <a href="#sec-linkset-records">LinkSet Records</a> of the change. This
+ function concludes the loader pipeline. It is called after all a newly loaded module's dependencies are successfully
+ processed.</p>
+
+ <p>Each LoadSucceeded function has a [[Load]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a>.</p>
+
+ <p>When a LoadSucceeded function <var>F</var> is called, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>load</i> be the value of <i>F</i>’s [[Load]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>load</i>.[[Status]] is <code>"loading"</code>.</li>
+ <li>Set <i>load</i>.[[Status]] to <code>"loaded"</code>.</li>
+ <li>Let <i>linkSets</i> be a copy of <i>load</i>.[[LinkSets]].</li>
+ <li>For each <i>linkSet</i> in <i>linkSets</i> in <a href="#sec-list-and-record-specification-type">List</a> order, do
+ <ol class="block">
+ <li>Call <a href="#sec-updatelinksetonload">UpdateLinkSetOnLoad</a>(<i>linkSet</i>, <i>load</i>).</li>
+ </ol>
+ </li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-promiseofstartloadpartwaythrough">
+ <div class="front">
+ <h1><span class="secnum" id="sec-15.2.4.7"><a href="#sec-promiseofstartloadpartwaythrough"
+ title="link to this section">15.2.4.7</a></span> PromiseOfStartLoadPartwayThrough (step, loader, name, metadata,
+ source, address)</h1>
+ <ol class="proc">
+ <li>Let <i>F</i> be a new anonymous function object as defined in AsyncStartLoadPartwayThrough.</li>
+ <li>Let <i>state</i> be the Record { [[Step]]: <code>"translate"</code>, [[Loader]]: <i>loader</i>, [[ModuleName]]:
+ <i>name</i>, [[ModuleMetadata]]: <i>metadata</i>, [[ModuleSource]]: <i>source</i>, [[ModuleAddress]]:
+ <i>address</i>}.</li>
+ <li>Set <i>F</i>’s [[StepState]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to
+ <i>state</i>.</li>
+ <li>Return <a href="#sec-promisenew">PromiseNew</a>(<i>F</i>).</li>
+ </ol>
+ </div>
+
+ <section id="sec-asyncstartloadpartwaythrough-functions">
+ <h1><span class="secnum" id="sec-15.2.4.7.1"><a href="#sec-asyncstartloadpartwaythrough-functions"
+ title="link to this section">15.2.4.7.1</a></span> AsyncStartLoadPartwayThrough Functions</h1>
+
+ <p>An AsyncStartLoadPartwayThrough function is an anonymous function that is used as a Promise executor. When called it
+ creates a new Load Record and populates it with some information provided by the caller, so that loading can proceed
+ from either the <code>locate</code> hook, the <code>fetch</code> hook, or the <code>translate</code> hook. This
+ functionality is used to implement builtin methods like <code><a
+ href="#sec-reflect.loader.prototype.load">Reflect.Loader.prototype.load</a></code>, which permits the user to specify
+ both the normalized module <var>name</var> and the <var>address</var>.</p>
+
+ <p>Each AsyncStartLoadPartwayThrough function has internal slots [[StepState]].</p>
+
+ <p>When an AsyncStartLoadPartwayThrough function <var>F</var> is called with arguments <var>resolve</var> and
+ <var>reject</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>state</i> be the value of <i>F</i>’s [[StepState]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>loader</i> be <i>state</i>.[[Loader]].</li>
+ <li>Let <i>name</i> be <i>state</i>.[[ModuleName]].</li>
+ <li>Let <i>step</i> be <i>state</i>.[[Step]].</li>
+ <li>Repeat for each Record {[[key]], [[value]]} <i>p</i> that is an element of <i>loader</i>.[[Modules], do
+ <ol class="block">
+ <li>If <a href="#sec-samevalue">SameValue</a>(<i>p</i>.[[key]], <i>name</i>) is <b>true</b>, then throw a
+ <b>TypeError</b> exception.</li>
+ </ol>
+ </li>
+ <li>Repeat for element of <i>load</i> or <i>loader</i>.[[Modules], do
+ <ol class="block">
+ <li>If <a href="#sec-samevalue">SameValue</a>(<i>loads</i>.[[Name]], <i>name</i>) is <b>true</b>, then throw a
+ <b>TypeError</b> exception.</li>
+ </ol>
+ </li>
+ <li>Let <i>load</i> be <a href="#sec-createload">CreateLoad</a>(<i>name</i>).</li>
+ <li>Set <i>load</i>.[[Metadata]] to <i>state</i>.[[ModuleMetadata]].</li>
+ <li>Let <i>linkSet</i> be <a href="#sec-createlinkset">CreateLinkSet</a>(<i>loader,</i> <i>load</i>).</li>
+ <li>Append <i>load</i> to the end of <i>loader</i>.[[Loads]].</li>
+ <li>Call the [[Call]] internal method of <i>resolve</i> with arguments <b>undefined</b> and
+ (<i>linkSet</i>.[[Done]]).</li>
+ <li>If <i>step</i> is <code>"locate"</code>,
+ <ol class="block">
+ <li>Call <a href="#sec-proceedtolocate">ProceedToLocate</a>(<i>loader</i>, <i>load</i>).</li>
+ </ol>
+ </li>
+ <li>Else if <i>step</i> is <code>"fetch"</code>,
+ <ol class="block">
+ <li>Let <i>addressPromise</i> be <a href="#sec-promiseof">PromiseOf</a>(<i>state</i>.[[ModuleAddress]]).</li>
+ <li>Call <a href="#sec-proceedtofetch">ProceedToFetch</a>(<i>loader</i>, <i>load</i>, <i>addressPromise</i>).</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>step</i> is <code>"translate"</code>.</li>
+ <li>Set <i>load</i>.[[Address]] to <i>state</i>.[[ModuleAddress]].</li>
+ <li>Let <i>sourcePromise</i> be <a href="#sec-promiseof">PromiseOf</a>(<i>state</i>.[[ModuleSource]]).</li>
+ <li>Call <a href="#sec-proceedtotranslate">ProceedToTranslate</a>(<i>loader</i>, <i>load</i>,
+ <i>sourcePromise</i>).</li>
+ </ol>
+ </li>
+ </ol>
+ </section>
+ </section>
+ </section>
+
+ <section id="sec-runtime-semantics-module-linking">
+ <div class="front">
+ <h1><span class="secnum" id="sec-15.2.5"><a href="#sec-runtime-semantics-module-linking"
+ title="link to this section">15.2.5</a></span> Runtime Semantics: Module Linking</h1>
+ </div>
+
+ <section id="sec-modulelinkage-record">
+ <div class="front">
+ <h1><span class="secnum" id="sec-15.2.5.1"><a href="#sec-modulelinkage-record"
+ title="link to this section">15.2.5.1</a></span> ModuleLinkage Record</h1>
+
+ <p>A ModuleLinkage Record contains the state needed to link a specific module.</p>
+
+ <p>Each LinkSet Record has the fields defined in <a href="#table-36">Table 36</a>.</p>
+
+ <figure>
+ <figcaption><span id="table-36">Table 36</span> — ModuleLinkage Record Fields</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 0px solid black; border-top: 2px solid #000000">Field Name</th>
+ <th style="border-bottom: 1px solid #000000; border-left: 0px solid black; border-right: 1px solid #000000; border-top: 2px solid #000000">Value Type</th>
+ <th style="border-bottom: 1px solid #000000; border-right: 1px solid #000000; border-top: 2px solid #000000">Meaning</th>
+ </tr>
+ <tr>
+ <td>[[Body]]</td>
+ <td>a parse result</td>
+ <td>The parse of a <span class="nt">Module</span> production</td>
+ </tr>
+ <tr>
+ <td>[[BoundNames]]</td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>[[KnownExportEntries]]</td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>[[KnownExportEntries]]</td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>[[ExportDefinitions]]</td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>[[Exports]]</td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>[[Dependenies]]</td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>[[UnlinkedDependencies]]</td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>[[ImportedEntries]]</td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>[[ImportedDefinitions]]</td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>[[LinkErrors]]</td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>[[Environment]]</td>
+ <td></td>
+ <td></td>
+ </tr>
+ </table>
+ </figure>
+ </div>
+
+ <section id="sec-createmodulelinkagerecord">
+ <h1><span class="secnum" id="sec-15.2.5.1.1"><a href="#sec-createmodulelinkagerecord"
+ title="link to this section">15.2.5.1.1</a></span> CreateModuleLinkageRecord (loader, body) Abstract Operation</h1>
+
+ <p>The abstract operation CreateModuleLinkageRecord with arguments <var>loader</var> and <var>body</var> performs the
+ following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>body</i> is a <i>Modulebody</i> parse.</li>
+ <li>Let <i>M</i> be a new object with [[Prototype]] <b>null</b>.</li>
+ <li>Set <i>M</i>.[[Body]] to <i>body</i>.</li>
+ <li>Set <i>M</i>.[[BoundNames]] to DeclaredNames of <i>body</i>.</li>
+ <li>Set <i>M</i>.[[KnownExportEntries]] to KnownExportEntries of <i>body</i>.</li>
+ <li>Set <i>M</i>.[[UnknownExportEntries]] to UnknownExportEntries of <i>body</i>.</li>
+ <li>Set <i>M</i>.[[ExportDefinitions]] to <b>undefined</b>.</li>
+ <li>Set <i>M</i>.[[Exports]] to <b>undefined</b>.</li>
+ <li>Set <i>M</i>.[[Dependencies]] to <b>undefined</b>.</li>
+ <li>Set <i>M</i>.[[UnlinkedDependencies]] to <b>undefined</b>.</li>
+ <li>Set <i>M</i>.[[ImportEntries]] to ImportEntries of <i>body</i>.</li>
+ <li>Set <i>M</i>.[[ImportDefinitions]] to <b>undefined</b>.</li>
+ <li>Set <i>M</i>.[[LinkErrors]] to a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Let <i>realm</i> be <i>loader</i>.[[Realm]].</li>
+ <li>Let <i>globalEnv</i> be <i>realm</i>.[[<i>globalEnv</i>]].</li>
+ <li>Let <i>env</i> be NewModuleEnvironment(<i>globalEnv</i>).</li>
+ <li>Set <i>M</i>.[[Environment]] to <i>env</i>.</li>
+ <li>Return <i>M</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-lookupexport">
+ <h1><span class="secnum" id="sec-15.2.5.1.2"><a href="#sec-lookupexport"
+ title="link to this section">15.2.5.1.2</a></span> LookupExport ( M, exportName )</h1>
+
+ <p>The abstract operation LookupExport with arguments <var>M</var> and <var>exportName</var> performs the following:</p>
+
+ <ol class="proc">
+ <li>If <i>M</i>.[[Exports]] does not contain a record <i>export</i> such that <i>export</i>.[[ExportName]] is equal to
+ <i>exportName</i>, then return <b>undefined</b>.</li>
+ <li>Let <i>export</i> be the record in <i>M</i>.[[Exports]] such that <i>export</i>.[[ExportName]] is equal to
+ <i>exportName</i>.</li>
+ <li>Return <i>export</i>.[[Binding]].</li>
+ </ol>
+ </section>
+
+ <section id="sec-lookupmoduledependency">
+ <h1><span class="secnum" id="sec-15.2.5.1.3"><a href="#sec-lookupmoduledependency"
+ title="link to this section">15.2.5.1.3</a></span> LookupModuleDependency ( M, requestName )</h1>
+
+ <p>The abstract operation LookupModuleDependency with arguments <var>M</var> and <var>requestName</var> performs the
+ following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>M</i> is a <a href="#sec-modulelinkage-record">ModuleLinkage
+ Record</a>.</li>
+ <li>If <i>requestName</i> is <b>null</b> then return <i>M</i>.</li>
+ <li>Let <i>pair</i> be the record in <i>M</i>.[[Dependencies]] such that <i>pair</i>.[[Key]] is equal to
+ <i>requestName</i>.</li>
+ <li>Return <i>pair</i>.[[Module]].</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-linkset-records">
+ <div class="front">
+ <h1><span class="secnum" id="sec-15.2.5.2"><a href="#sec-linkset-records"
+ title="link to this section">15.2.5.2</a></span> LinkSet Records</h1>
+
+ <p>A LinkSet Record represents a call to <code>loader.define()</code>, <code>.load()</code>, <code>.module()</code>, or
+ <code>.import()</code>.</p>
+
+ <p>Each LinkSet Record has the fields defined in <a href="#table-37">Table 37</a>.</p>
+
+ <figure>
+ <figcaption><span id="table-37">Table 37</span> — LinkSet Record Fields</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 0px solid black; border-top: 2px solid #000000">Field Name</th>
+ <th style="border-bottom: 1px solid #000000; border-left: 0px solid black; border-right: 1px solid #000000; border-top: 2px solid #000000">Value Type</th>
+ <th style="border-bottom: 1px solid #000000; border-right: 1px solid #000000; border-top: 2px solid #000000">Meaning</th>
+ </tr>
+ <tr>
+ <td>[[Loader]]</td>
+ <td>Loader Record</td>
+ <td>The Loader record that created this LinkSet.</td>
+ </tr>
+ <tr>
+ <td>[[Loads]]</td>
+ <td><a href="#sec-list-and-record-specification-type">List</a> of Load Record</td>
+ <td>A <a href="#sec-list-and-record-specification-type">List</a> of the Load Records that must finish loading before the modules can be linked and evaluated.</td>
+ </tr>
+ <tr>
+ <td>[[Done]]</td>
+ <td>Promise Object</td>
+ <td>The Promise that becomes fulfilled when all dependencies are loaded and linked together.</td>
+ </tr>
+ <tr>
+ <td>[[Resolve]]</td>
+ <td>Function Object</td>
+ <td>Function used to resolve [[Done]].</td>
+ </tr>
+ <tr>
+ <td>[[Reject]]</td>
+ <td>Function Object</td>
+ <td>Function used to reject [[Done]].</td>
+ </tr>
+ </table>
+ </figure>
+ </div>
+
+ <section id="sec-createlinkset">
+ <h1><span class="secnum" id="sec-15.2.5.2.1"><a href="#sec-createlinkset"
+ title="link to this section">15.2.5.2.1</a></span> CreateLinkSet(loader, startingLoad) Abstract Operation</h1>
+
+ <p>The CreateLinkSet abstract operation creates a new LinkSet record by performing the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>loader</i> is a Loader Record.</li>
+ <li>If <i>loader</i> does not have all of the internal properties of a Loader Instance, throw a TypeError
+ exception.</li>
+ <li>Let <i>promiseCapability</i> be <a href="#sec-promisebuiltincapability">PromiseBuiltinCapability</a>().</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>promiseCapability</i>).</li>
+ <li>Let <i>linkSet</i> be LinkSet {[[Loader]]: <i>loader</i>, [[Loads]]: ( ), [[Done]]:
+ <i>promiseCapability</i>.[[Promise]], [[Resolve]]: <i>promiseCapability</i>.[[Resolve]], [[Reject]]:
+ <i>promiseCapability</i>.[[Reject]] }.</li>
+ <li>Perform <a href="#sec-addloadtolinkset">AddLoadToLinkSet</a>(<i>linkSet</i>, <i>startingLoad</i>).</li>
+ <li>Return <i>linkSet</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-addloadtolinkset">
+ <h1><span class="secnum" id="sec-15.2.5.2.2"><a href="#sec-addloadtolinkset"
+ title="link to this section">15.2.5.2.2</a></span> AddLoadToLinkSet(linkSet, load) Abstract Operation</h1>
+
+ <p>The AddLoadToLinkSet abstract operation associates a LinkSet Record with a Load Record and each of its currently
+ known dependencies, indicating that the LinkSet cannot be linked until those Loads have finished successfully.</p>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>load</i>.[[Status]] is either <code>"loading"</code> or
+ <code>"loaded"</code>.</li>
+ <li>Let <i>loader</i> be <i>linkSet</i>.[[Loader]].</li>
+ <li>If <i>load</i> is not already an element of the <a href="#sec-list-and-record-specification-type">List</a>
+ <i>linkSet</i>.[[Loads]],
+ <ol class="block">
+ <li>Append <i>load</i> to the end of the <a href="#sec-list-and-record-specification-type">List</a>
+ <i>linkSet</i>.[[Loads]].</li>
+ <li>Append <i>linkSet</i> to the end of the <a href="#sec-list-and-record-specification-type">List</a>
+ <i>load</i>.[[LinkSets]].</li>
+ <li>If <i>load</i>.[[Status]] is <code>"loaded"</code>, then
+ <ol class="block">
+ <li>Repeat for each <i>r</i> that is a Record {[[Name]], [[NormalizedName]]} in <i>load</i>.[[Dependencies]],
+ <ol class="block">
+ <li>If there is no element of <i>loader</i>.[[Modules]] whose [[key]] field is equal to <i>name</i>,
+ <ol class="block">
+ <li>If there is an element of <i>loader</i>.[[Loads]] whose [[Name]] field is equal to <i>name</i>,
+ <ol class="block">
+ <li>Let <i>depLoad</i> be that Load Record.</li>
+ <li>Perform AddLoadToLinkSet(<i>linkSet</i>, <i>depLoad</i>).</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </section>
+
+ <section id="sec-updatelinksetonload">
+ <h1><span class="secnum" id="sec-15.2.5.2.3"><a href="#sec-updatelinksetonload"
+ title="link to this section">15.2.5.2.3</a></span> UpdateLinkSetOnLoad(linkSet, load) Abstract Operation</h1>
+
+ <p>The UpdateLinkSetOnLoad abstract operation is called immediately after a Load successfully finishes, after starting
+ Loads for any dependencies that were not already loading, loaded, or in the module registry.</p>
+
+ <p>This operation determines whether <var>linkSet</var> is ready to link, and if so, calls <a
+ href="#sec-link">Link</a>.</p>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>load</i> is an element of <i>linkSet</i>.[[Loads]].</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>load</i>.[[Status]] is either <code>"loaded"</code> or
+ <code>"linked"</code>.</li>
+ <li>Repeat for each <i>element</i> in <i>linkSet</i>.[[Loads]],
+ <ol class="block">
+ <li>If <i>element</i>.[[Status]] is <code>"loading"</code>, then return.</li>
+ </ol>
+ </li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: All Loads in <i>linkSet</i>.[[Loads]] have finished loading.</li>
+ <li>Let <i>startingLoad</i> be the first element of the <a href="#sec-list-and-record-specification-type">List</a>
+ <i>linkSet</i>.[[Loads]].</li>
+ <li>Let <i>status</i> be <a href="#sec-link">Link</a>(<i>linkSet</i>.[[Loads]], <i>linkSet</i>.[[Loader]]).</li>
+ <li>If <i>status</i> is an <a href="#sec-completion-record-specification-type">abrupt completion</a>, then
+ <ol class="block">
+ <li>Return <a href="#sec-linksetfailed">LinkSetFailed</a>(<i>linkSet</i>, <i>status</i>.[[value]]).</li>
+ </ol>
+ </li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>linkSet</i>.[[Loads]] is an empty <a
+ href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Call the [[Call]] internal method of <i>linkSet</i>.[[Resolve]] passing <b>undefined</b> and (<i>startingLoad</i>)
+ as arguments.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: The call performed by step 9 completed normally.</li>
+ </ol>
+ </section>
+
+ <section id="sec-linksetfailed">
+ <h1><span class="secnum" id="sec-15.2.5.2.4"><a href="#sec-linksetfailed"
+ title="link to this section">15.2.5.2.4</a></span> LinkSetFailed(linkSet, exc) Abstract Operation</h1>
+
+ <p>The LinkSetFailed abstract operation is called when a LinkSet fails. It detaches the given LinkSet Record from all
+ Load Records and rejects the <var>linkSet</var>.[[Done]] Promise.</p>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>loader</i> be <i>linkSet</i>.[[Loader]].</li>
+ <li>Let <i>loads</i> be a copy of the <a href="#sec-list-and-record-specification-type">List</a>
+ <i>linkSet</i>.[[Loads]].</li>
+ <li>For each <i>load</i> in <i>loads</i>,
+ <ol class="block">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>linkSet</i> is an element of the <a
+ href="#sec-list-and-record-specification-type">List</a> <i>load</i>.[[LinkSets]].</li>
+ <li>Remove <i>linkSet</i> from the <a href="#sec-list-and-record-specification-type">List</a>
+ <i>load</i>.[[LinkSets]].</li>
+ <li>If <i>load</i>.[[LinkSets]] is empty and <i>load</i> is an element of <i>loader</i>.[[Loads]], then
+ <ol class="block">
+ <li>Remove <i>load</i> from the <a href="#sec-list-and-record-specification-type">List</a>
+ <i>loader</i>.[[Loads]].</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Return the result of calling [[Call]] internal method of <i>linkSet</i>.[[Reject]] passing <b>undefined</b> and
+ (<i>exc</i>) as arguments.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: The call performed by step 4 completed normally.</li>
+ </ol>
+ </section>
+
+ <section id="sec-finishload">
+ <h1><span class="secnum" id="sec-15.2.5.2.5"><a href="#sec-finishload"
+ title="link to this section">15.2.5.2.5</a></span> FinishLoad(loader, load) Abstract Operation</h1>
+
+ <p>The FinishLoad Abstract Operation removes a completed Load Record from all LinkSets and commits the newly loaded
+ Module to the registry. It performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>name</i> be <i>load</i>.[[Name]].</li>
+ <li>If <i>name</i> is not <b>undefined</b>, then
+ <ol class="block">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: There is no Record {[[key]], [[value]]} <i>p</i> that is an
+ element of <i>loader</i>.[[Modules]], such that <a href="#sec-samevalue">SameValue</a>(<i>p</i>.[[key]],
+ <i>load</i>.[[Name]]) is <b>true</b>.</li>
+ <li>Append the Record {[[key]]: <i>load</i>.[[Name]], [[value]]: <i>load</i>.[[Module]]} as the last element of
+ <i>loader</i>.[[Modules]].</li>
+ </ol>
+ </li>
+ <li>If <i>load</i> is an element of the <a href="#sec-list-and-record-specification-type">List</a>
+ <i>loader</i>.[[Loads]], then
+ <ol class="block">
+ <li>Remove <i>load</i> from the <a href="#sec-list-and-record-specification-type">List</a>
+ <i>loader</i>.[[Loads]].</li>
+ </ol>
+ </li>
+ <li>For each <i>linkSet</i> in <i>load</i>.[[LinkSets]],
+ <ol class="block">
+ <li>Remove <i>load</i> from <i>linkSet</i>.[[Loads]].</li>
+ </ol>
+ </li>
+ <li>Remove all elements from the <a href="#sec-list-and-record-specification-type">List</a>
+ <i>load</i>.[[LinkSets]].</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-module-linking-groups">
+ <div class="front">
+ <h1><span class="secnum" id="sec-15.2.5.3"><a href="#sec-module-linking-groups"
+ title="link to this section">15.2.5.3</a></span> Module Linking Groups</h1>
+
+ <p>A load record <span style="font-family: Times New Roman"><i>load</i><sub>1</sub></span> has a <b><i>linkage
+ dependency</i></b> on a load record <span style="font-family: Times New Roman"><i>load</i><sub>2</sub></span> if <span
+ style="font-family: Times New Roman"><i>load</i><sub>2</sub></span> is contained in <span style="font-family: Times New
+ Roman"><i>load</i><sub>1</sub>.[[UnlinkedDependencies]]</span> or there exists a load record <var>load</var> in <span
+ style="font-family: Times New Roman"><i>load</i><sub>1</sub>.[[UnlinkedDependencies]]</span> such that <var>load</var>
+ has a linkage dependency on <span style="font-family: Times New Roman"><i>load</i><sub>2</sub></span>.</p>
+
+ <p>The <b><i>linkage graph</i></b> of a <a href="#sec-list-and-record-specification-type">List</a>, <i><span
+ style="font-family: Times New Roman">list</span>,</i> of load records is the set of load records <var>load</var> such
+ that some load record in <var>list</var> has a linkage dependency on <var>load</var>.</p>
+
+ <p>A <b><i>dependency chain</i></b> from <span style="font-family: Times New Roman"><i>load</i><sub>1</sub></span> to
+ <span style="font-family: Times New Roman"><i>load</i><sub>2</sub></span> is a <a
+ href="#sec-list-and-record-specification-type">List</a> of load records demonstrating the transitive linkage dependency
+ from <span style="font-family: Times New Roman"><i>load</i><sub>1</sub></span> to <span style="font-family: Times New
+ Roman"><i>load</i><sub>2</sub></span>.</p>
+
+ <p>A <b><i>dependency cycle</i></b> is a dependency chain whose first and last elements’ [[Name]] fields have the
+ same value.</p>
+
+ <p>A dependency chain is <b><i>cyclic</i></b> if it contains a subsequence that is a dependency cycle. A dependency
+ chain is <b><i>acyclic</i></b> if it is not cyclic.</p>
+
+ <p>A dependency chain is <b><i>mixed</i></b> if there are two elements with distinct values for their [[Kind]] fields. A
+ <b><i>dependency group transition</i></b> of kind <i>kind</i> is a two-element subsequence <span style="font-family:
+ Times New Roman"><i>load</i><sub>1</sub></span>, <span style="font-family: Times New
+ Roman"><i>load</i><sub>2</sub></span> of a dependency chain such that <span style="font-family: Times New
+ Roman"><i>load</i><sub>1</sub>.[[Kind]]</span> is not equal to <i>kind</i> and <span style="font-family: Times New
+ Roman"><i>load</i><sub>2</sub>.[[Kind]]</span> is equal to <i>kind</i>.</p>
+
+ <p>The <b><i>dependency group count</i></b> of a dependency chain with first element <span style="font-family: Times New
+ Roman"><i>load</i><sub>1</sub></span> is the number of distinct dependency group transitions of kind <span
+ style="font-family: Times New Roman"><i>load</i><sub>1</sub>.[[Kind]]</span>.</p>
+ </div>
+
+ <section id="sec-linkagegroups">
+ <h1><span class="secnum" id="sec-15.2.5.3.1"><a href="#sec-linkagegroups"
+ title="link to this section">15.2.5.3.1</a></span> LinkageGroups ( start )</h1>
+
+ <p>The abstract operation LinkageGroups with argument <var>start</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>start</i> is a <a
+ href="#sec-list-and-record-specification-type">List</a> of <a href="#sec-linkset-records">LinkSet
+ Records</a>.</li>
+ <li>Let <i>G</i> be the linkage graph of <i>start</i>.</li>
+ <li>If there are any mixed dependency cycles in <i>G</i>, throw a new Syntax Error.</li>
+ <li>For each <i>load</i> in <i>G</i>, do
+ <ol class="block">
+ <li>Let <i>n</i> be the largest dependency group count of all acyclic dependency chains in <i>G</i> starting from
+ <i>load</i>.</li>
+ <li>Set <i>load</i>.[[GroupIndex]] to <i>n</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>declarativeGroupCount</i> be the largest [[GroupIndex]] of any <i>load</i> in <i>G</i> such that
+ <i>load</i>.[[Kind]] is <span style="font-family: sans-serif">declarative</span>.</li>
+ <li>Let <i>declarativeGroups</i> be a new <a href="#sec-list-and-record-specification-type">List</a> of length
+ <i>declarativeGroupCount</i> where each element is a new empty <a
+ href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Let <i>dynamicGroupCount</i> be the largest [[GroupIndex]] of any <i>load</i> in <i>G</i> such that
+ <i>load</i>.[[Kind]] is <span style="font-family: sans-serif">dynamic</span>.</li>
+ <li>Let <i>dynamicGroups</i> be a new <a href="#sec-list-and-record-specification-type">List</a> of length
+ <i>dynamicGroupCount</i> where each element is a new empty <a
+ href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Let <i>visited</i> be a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>For each <i>load</i> in <i>start</i>, do
+ <ol class="block">
+ <li>Perform <a href="#sec-buildlinkagegroups">BuildLinkageGroups</a>(<i>load</i>, <i>declarativeGroups</i>,
+ <i>dynamicGroups</i>, and <i>visited</i>).</li>
+ </ol>
+ </li>
+ <li>If any <i>load</i> in the first element of <i>declarativeGroups</i> has a dependency on a load record of [[Kind]]
+ <span style="font-family: sans-serif">dynamic</span>, then
+ <ol class="block">
+ <li>Let <i>groups</i> be a <a href="#sec-list-and-record-specification-type">List</a> constructed by interleaving
+ the elements of <i>dynamicGroups</i> and <i>declarativeGroups</i>, starting with the former.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>let <i>groups</i> be a <a href="#sec-list-and-record-specification-type">List</a> constructed by interleaving
+ the elements of <i>declarativeGroups</i> and <i>dynamicGroups</i>, starting with the former.</li>
+ </ol>
+ </li>
+ <li>Return <i>groups</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-buildlinkagegroups">
+ <h1><span class="secnum" id="sec-15.2.5.3.2"><a href="#sec-buildlinkagegroups"
+ title="link to this section">15.2.5.3.2</a></span> BuildLinkageGroups ( load, declarativeGroups, dynamicGroups,
+ visited )</h1>
+
+ <p>The abstract operation BuildLinkageGroups with arguments <var>load</var>, <var>declarativeGroups</var>, and
+ <var>dynamicGroups</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>If <i>visited</i> contains an element whose [[Name]] is equal to <i>load</i>.[[Name]], then return.</li>
+ <li>Add <i>load</i> to <i>visited</i>.</li>
+ <li>For each <i>dep</i> of <i>load</i>.[[UnlinkedDependencies]], do
+ <ol class="block">
+ <li>Call the BuildLinkageGroups abstract operation passing <i>dep</i>, <i>declarativeGroups</i>,
+ <i>dynamicGroups</i>, and <i>visited</i> as arguments.</li>
+ </ol>
+ </li>
+ <li>Let <i>i</i> be <i>load</i>.[[GroupIndex]].</li>
+ <li>If <i>load</i>.[[Kind]] is <span style="font-family: sans-serif">declarative</span> let <i>groups</i> be
+ <i>declarativeGroups</i>; otherwise let <i>groups</i> be <i>dynamicGroups</i>.</li>
+ <li>Let <i>group</i> be the <i>i</i>th element of <i>groups</i>.</li>
+ <li>Add <i>load</i> to <i>group</i>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-link">
+ <h1><span class="secnum" id="sec-15.2.5.4"><a href="#sec-link" title="link to this section">15.2.5.4</a></span> Link (
+ start, loader )</h1>
+
+ <p>The abstract operation Link with argument <var>start</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>groups</i> be <a href="#sec-linkagegroups">LinkageGroups</a>(<i>start</i>).</li>
+ <li>For each <i>group</i> in <i>groups</i>:
+ <ol class="block">
+ <li>If the [[Kind]] of each element of <i>group</i> is <span style="font-family: sans-serif">declarative</span>,
+ then perfrom <a href="#sec-linkdeclarativemodules">LinkDeclarativeModules</a>(<i>group</i>, <i>loader</i>).</li>
+ <li>Else, perfrom <a href="#sec-linkdynamicmodules">LinkDynamicModules</a>(<i>group</i>, <i>loader</i>).</li>
+ </ol>
+ </li>
+ </ol>
+ </section>
+
+ <section id="sec-linkdeclarativemodules">
+ <div class="front">
+ <h1><span class="secnum" id="sec-15.2.5.5"><a href="#sec-linkdeclarativemodules"
+ title="link to this section">15.2.5.5</a></span> LinkDeclarativeModules ( loads, loader )</h1>
+
+ <p>The abstract operation LinkDeclarativeModules with arguments <var>loads</var> and <var>loader</var> performs the
+ following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>unlinked</i> be a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>For each <i>load</i> in <i>loads</i>, do
+ <ol class="block">
+ <li>If <i>load</i>.[[Status]] is not <b>linked</b>, then
+ <ol class="block">
+ <li>Let <i>module</i> be <a href="#sec-createmodulelinkagerecord">CreateModuleLinkageRecord</a>
+ (<i>loader</i>, <i>load</i>.[[Body]]).</li>
+ <li>Let <i>pair</i> be the record {[[Module]]: <i>module</i>, [[Load]]: <i>load</i>}.</li>
+ <li>Add <i>pair</i> to <i>unlinked</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>For each <i>pair</i> in <i>unlinked</i>, do
+ <ol class="block">
+ <li>Let <i>resolvedDeps</i> be a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Let <i>unlinkedDeps</i> be a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>For each element <i>dep</i> in <i>pair</i>.[[Load]].[[Dependencies]], do
+ <ol class="block">
+ <li>Let <i>requestName</i> be <i>dep</i>.[[Key]].</li>
+ <li>Let <i>normalizedName</i> be <i>dep</i>.[[Value]].</li>
+ <li>If <i>loads</i> contains a record <i>load</i> such that <a
+ href="#sec-samevalue">SameValue</a>(<i>load</i>.[[Name]], <i>normalizedName</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>If <i>load</i>.[[Status]] is <b>linked</b>, then
+ <ol class="block">
+ <li>Let <i>resolvedDep</i> be the record {[[Key]]: <i>requestName</i>, [[Value]]:
+ <i>load</i>.[[Module]]}.</li>
+ <li>Add <i>resolvedDep</i> to <i>resolvedDeps</i>.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>otherPair</i> be the record in <i>unlinked</i> such that <a
+ href="#sec-samevalue">SameValue</a>(<i>otherPair</i>.[[Load]].[[Name]], <i>normalizedName</i>) is
+ <b>true</b>.</li>
+ <li>Add the record {[[Key]]: <i>requestName</i>, [[Value]]: <i>otherPair</i>.[[Module]]} to
+ <i>resolvedDeps</i>.</li>
+ <li>Add <i>otherPair</i>.[[Load]] to <i>unlinkedDeps</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>module</i> be LoaderRegistryLookup(<i>loader</i>, <i>normalizedName</i>).</li>
+ <li>If <i>module</i> is <b>null</b> then
+ <ol class="block">
+ <li>Let <i>error</i> be a new <b>ReferenceError</b> exception.</li>
+ <li>Add <i>error</i> to <i>pair</i>.[[Module]].[[LinkErrors]].</li>
+ </ol>
+ </li>
+ <li>Else, add the record {[[Key]]: <i>requestName</i>, [[Value]]: <i>module</i>} to
+ <i>resolvedDeps.</i></li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Set <i>pair</i>.[[Module]].[[Dependencies]] to <i>resolvedDeps</i>.</li>
+ <li>Set <i>pair</i>.[[Module]].[[UnlinkedDependencies]] to <i>unlinkedDeps</i>.</li>
+ </ol>
+ </li>
+ <li>For each <i>pair</i> in <i>unlinked</i>, do
+ <ol class="block">
+ <li>Perform <a href="#sec-resolveexportentries">ResolveExportEntries</a>(<i>pair</i>.[[Module]], ( ) ).</li>
+ <li>Perform <a href="#sec-resolveexports">ResolveExports</a>(<i>pair</i>.[[Module]]).</li>
+ </ol>
+ </li>
+ <li>For each <i>pair</i> in <i>unlinked</i>, do
+ <ol class="block">
+ <li>Perform <a href="#sec-resolveimportentries">ResolveImportEntries</a>(<i>pair</i>.[[Module]]).</li>
+ <li>Perform <a href="#sec-linkimports">LinkImports</a>(<i>pair</i>.[[Module]]).</li>
+ </ol>
+ </li>
+ <li>If there exists a <i>pair</i> in <i>unlinked</i> such that <i>pair</i>.[[Module]].[[LinkErrors]] is not empty,
+ choose one of the link errors and throw it.</li>
+ <li>For each <i>pair</i> in <i>unlinked</i>, do
+ <ol class="block">
+ <li>Set <i>pair</i>.[[Load]].[[Module]] to <i>pair</i>.[[Module]].</li>
+ <li>Set <i>pair</i>.[[Load]].[[Status]] to <b>linked</b>.</li>
+ <li>Let <i>r</i> beFinishLoad(<i>loader</i>, <i>pair</i>.[[Load]]).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>r</i>).</li>
+ </ol>
+ </li>
+ </ol>
+ </div>
+
+ <section id="sec-linkimports">
+ <h1><span class="secnum" id="sec-15.2.5.5.1"><a href="#sec-linkimports"
+ title="link to this section">15.2.5.5.1</a></span> LinkImports ( M )</h1>
+
+ <p>The abstract operation LinkImports with argument <var>M</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>envRec</i> be <i>M</i>.[[Environment]].</li>
+ <li>Let <i>defs</i> be <i>M</i>.[[ImportDefinitions]].</li>
+ <li>For each <i>def</i> in <i>defs</i>, do
+ <ol class="block">
+ <li>If <i>def</i>.[[ImportName]] is <b>module</b>, then the following steps are taken:
+ <ol class="block">
+ <li>Call the CreateImmutableBinding concrete method of <i>envRec</i> passing <i>def</i>.[[LocalName]] as the
+ argument.</li>
+ <li>Call the InitializeImmutableBinding concrete method of <i>envRec</i> passing <i>def</i>.[[LocalName]] and
+ <i>def</i>.[[Module]] as the arguments.</li>
+ </ol>
+ </li>
+ <li>Otherwise, the following steps are taken:
+ <ol class="block">
+ <li>Let <i>binding</i> be <a href="#sec-resolveexport">ResolveExport</a>(<i>def</i>.[[Module]],
+ <i>def</i>.[[ImportName]], ( )).</li>
+ <li>If <i>binding</i> is <b>undefined</b>, then the following steps are taken:
+ <ol class="block">
+ <li>Let <i>error</i> be a new <a href="#sec-reference-specification-type">Reference</a> Error.</li>
+ <li>Add <i>error</i> to <i>M</i>.[[LinkErrors]].</li>
+ </ol>
+ </li>
+ <li>Otherwise, call the CreateImportBinding concrete method of <i>envRec</i> passing <i>def</i>.[[LocalName]]
+ and <i>binding</i> as the arguments.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-linkdynamicmodules">
+ <h1><span class="secnum" id="sec-15.2.5.6"><a href="#sec-linkdynamicmodules"
+ title="link to this section">15.2.5.6</a></span> LinkDynamicModules ( loads, loader )</h1>
+
+ <p>The abstract operation LinkDynamicModules with arguments <var>loads</var> and <var>loader</var> performs the following
+ steps:</p>
+
+ <ol class="proc">
+ <li>For each <i>load</i> in <i>loads</i>, do
+ <ol class="block">
+ <li>Let <i>exec</i> be <i>load</i>.[[Execute]].</li>
+ <li>Let <i>module</i> be the result of calling the [[Call]] internal method of <i>exec</i> with <b>undefined</b> as
+ the <b>this</b> value and with no arguments.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>module</i>).</li>
+ <li>If <i>module</i> does not have all the internal data properties of a Module Instance Object, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>Set <i>load</i>.[[Module]] to <i>module</i>.</li>
+ <li>Set <i>load</i>.[[Status]] to <b>linked</b>.</li>
+ <li>Let <i>r</i> be <a href="#sec-finishload">FinishLoad</a>(<i>loader</i>, <i>load</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>r</i>).</li>
+ </ol>
+ </li>
+ </ol>
+ </section>
+
+ <section id="sec-resolveexportentries">
+ <h1><span class="secnum" id="sec-15.2.5.7"><a href="#sec-resolveexportentries"
+ title="link to this section">15.2.5.7</a></span> ResolveExportEntries ( M, visited )</h1>
+
+ <p>The abstract operation ResolveExportEntries with arguments <var>M</var> and <var>visited</var> performs the following
+ steps:</p>
+
+ <ol class="proc">
+ <li>If <i>M</i>.[[ExportDefinitions]] is not <b>undefined</b>, then return <i>M</i>.[[ExportDefinitions]].</li>
+ <li>Let <i>defs</i> be a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Let <i>boundNames</i> be <i>M</i>.[[BoundNames]].</li>
+ <li>For each <i>entry</i> in <i>M</i>.[[KnownExportEntries]], do
+ <ol class="block">
+ <li>Let <i>modReq</i> be <i>entry</i>.[[ModuleRequest]].</li>
+ <li>Let <i>otherMod</i> be <a href="#sec-lookupmoduledependency">LookupModuleDependency</a>(<i>M</i>,
+ <i>modReq</i>).</li>
+ <li>If <i>entry</i>.[[Module]] is <b>null</b> and <i>entry</i>.[[LocalName]] is not <b>null</b> and
+ <i>boundNames</i> does not contain <i>entry</i>.[[LocalName]], then the following steps are taken:
+ <ol class="block">
+ <li>Let <i>error</i> be a new <a href="#sec-reference-specification-type">Reference</a> Error.</li>
+ <li>Add <i>error</i> to <i>M</i>.[[LinkErrors]].</li>
+ </ol>
+ </li>
+ <li>Add the record {[[Module]]: <i>otherMod</i>, [[ImportName]]: <i>entry</i>.[[ImportName]], [[LocalName]]:
+ <i>entry</i>.[[LocalName]], [[ExportName]]: <i>entry</i>.[[ExportName]], [[Explicit]]: <b>true</b>} to
+ <i>defs</i>.</li>
+ </ol>
+ </li>
+ <li>For each <i>modReq</i> in <i>M</i>.[[UnknownExportEntries]], do
+ <ol class="block">
+ <li>Let <i>otherMod</i> be <a href="#sec-lookupmoduledependency">LookupModuleDependency</a>( <i>M</i>,
+ <i>modReq</i>).</li>
+ <li>If <i>otherMod</i> is in <i>visited</i>, then the following steps are taken:
+ <ol class="block">
+ <li>Let <i>error</i> be a new Syntax Error.</li>
+ <li>Add <i>error</i> to <i>M</i>.[[LinkErrors]].</li>
+ </ol>
+ </li>
+ <li>Otherwise the following steps are taken:
+ <ol class="block">
+ <li>Add <i>otherMod</i> to <i>visited</i>.</li>
+ <li>Let <i>otherDefs</i> be ResolveExportEntries(<i>otherMod</i>, <i>visited</i> ).</li>
+ <li>For each <i>def</i> of <i>otherDefs</i>, do
+ <ol class="block">
+ <li>Add the record {[[Module]]: <i>otherMod</i>, [[ImportName]]: <i>def</i>.[[ExportName]], [[LocalName]]:
+ <b>null</b>, [[ExportName]]: <i>def</i>.[[ExportName]], [[Explicit]]: <b>false</b>} to <i>defs</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Set <i>M</i>.[[ExportDefinitions]] to <i>defs</i>.</li>
+ <li>Return <i>defs</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-resolveexports">
+ <h1><span class="secnum" id="sec-15.2.5.8"><a href="#sec-resolveexports" title="link to this section">15.2.5.8</a></span>
+ ResolveExports ( M )</h1>
+
+ <p>The abstract operation ResolveExports with argument <var>M</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>For each <i>def</i> in <i>M</i>.[[ExportDefinitions]], do
+ <ol class="block">
+ <li>Perform <a href="#sec-resolveexport">ResolveExport</a>(<i>M</i>, <i>def</i>.[[ExportName]], ( )).</li>
+ </ol>
+ </li>
+ </ol>
+ </section>
+
+ <section id="sec-resolveexport">
+ <h1><span class="secnum" id="sec-15.2.5.9"><a href="#sec-resolveexport" title="link to this section">15.2.5.9</a></span>
+ ResolveExport ( M, exportName, visited )</h1>
+
+ <p>The abstract operation ResolveExport with arguments <var>M</var>, <var>exportName</var>, and <var>visited</var>
+ performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>exports</i> be <i>M</i>.[[Exports]].</li>
+ <li>If <i>exports</i> has a record <i>export</i> such that <i>export</i>.[[ExportName]] is equal to <i>exportName</i>,
+ return <i>export</i>.[[Binding]].</li>
+ <li>Let <i>ref</i> be {[[Module]]: <i>M</i>, [[ExportName]]: <i>exportName</i>}.</li>
+ <li>If <i>visited</i> contains a record equal to <i>ref</i> then the following steps are taken:
+ <ol class="block">
+ <li>Let <i>error</i> be a new Syntax Error.</li>
+ <li>Add <i>error</i> to <i>M</i>.[[LinkErrors]].</li>
+ <li>Return <i>error</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>defs</i> be <i>M</i>.[[ExportDefinitions]].</li>
+ <li>Let <i>overlappingDefs</i> be the <a href="#sec-list-and-record-specification-type">List</a> of records <i>def</i>
+ in <i>defs</i> such that <i>def</i>.[[ExportName]] is equal to <i>exportName</i>.</li>
+ <li>If <i>overlappingDefs</i> is empty, then the following steps are taken:
+ <ol class="block">
+ <li>Let <i>error</i> be a new <a href="#sec-reference-specification-type">Reference</a> Error.</li>
+ <li>Add <i>error</i> to <i>M</i>.[[LinkErrors]].</li>
+ <li>Return <i>error</i>.</li>
+ </ol>
+ </li>
+ <li>If <i>overlappingDefs</i> has more than one record <i>def</i> such that <i>def</i>.[[Explicit]] is <b>true</b>, or
+ if it has length greater than 1 but contains no records <i>def</i> such that <i>def</i>.[[Explicit]] is <b>true</b>,
+ then the following steps are taken:
+ <ol class="block">
+ <li>Let <i>error</i> be a new Syntax Error.</li>
+ <li>Add <i>error</i> to <i>M</i>.[[LinkErrors]].</li>
+ <li>Return <i>error</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>def</i> be the unique record in <i>overlappingDefs</i> such that <i>def</i>.[[Explicit]] is <b>true</b>, or
+ if there is no such record let <i>def</i> be the unique record in <i>overlappingDefs</i>.</li>
+ <li>If <i>def</i>.[[LocalName]] is not <b>null</b>, then the following steps are taken:
+ <ol class="block">
+ <li>Let <i>binding</i> be the record {[[Module]]: <i>M</i>, [[LocalName]]: <i>def</i>.[[LocalName]]}.</li>
+ <li>Let <i>export</i> be the record {[[ExportName]]: <i>exportName</i>, [[Binding]]: <i>binding</i>}.</li>
+ <li>Add <i>export</i> to <i>exports</i>.</li>
+ <li>Return <i>binding</i>.</li>
+ </ol>
+ </li>
+ <li>Add <i>ref</i> to <i>visited</i>.</li>
+ <li>Let <i>binding</i> be ResolveExport(<i>def</i>.[[Module]], <i>def</i>.[[ImportName]], <i>visited</i>).</li>
+ <li>Return <i>binding</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-resolveimportentries">
+ <h1><span class="secnum" id="sec-15.2.5.10"><a href="#sec-resolveimportentries"
+ title="link to this section">15.2.5.10</a></span> ResolveImportEntries ( M )</h1>
+
+ <p>The abstract operation ResolveImportEntries called with argument <var>M</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>entries</i> be <i>M</i>.[[ImportEntries]].</li>
+ <li>Let <i>defs</i> be a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>For each <i>entry</i> in <i>entries</i>, do
+ <ol class="block">
+ <li>Let <i>modReq</i> be <i>entry</i>.[[ModuleRequest]].</li>
+ <li>Let <i>otherMod</i> be <a href="#sec-lookupmoduledependency">LookupModuleDependency</a>(<i>M</i>,
+ <i>modReq</i>).</li>
+ <li>Add the record {[[Module]]: <i>otherMod</i>, [[ImportName]]: <i>entry</i>.[[ImportName]], [[LocalName]]:
+ <i>entry</i>.[[LocalName]]} to <i>defs</i>.</li>
+ </ol>
+ </li>
+ <li>Return <i>defs</i>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-runtime-semantics-module-evaluation">
+ <div class="front">
+ <h1><span class="secnum" id="sec-15.2.6"><a href="#sec-runtime-semantics-module-evaluation"
+ title="link to this section">15.2.6</a></span> Runtime Semantics: Module Evaluation</h1>
+
+ <p>Module bodies are evaluated on demand, as late as possible. The loader uses the function <code><a
+ href="#sec-ensureevaluated">EnsureEvaluated</a></code>, defined below, to run scripts. The loader always calls <code><a
+ href="#sec-ensureevaluated">EnsureEvaluated</a></code> before returning a Module object to user code.</p>
+
+ <p>There is one way a module can be exposed to script before its body has been evaluated. In the case of an import cycle,
+ whichever module is evaluated first can observe the others before they are evaluated. Simply put, we have to start
+ somewhere: one of the modules in the cycle must run before the others.</p>
+ </div>
+
+ <section id="sec-evaluateloadedmodule-load-functions">
+ <h1><span class="secnum" id="sec-15.2.6.1"><a href="#sec-evaluateloadedmodule-load-functions"
+ title="link to this section">15.2.6.1</a></span> EvaluateLoadedModule(load) Functions</h1>
+
+ <p>An EvaluateLoadedModule function is an anonymous built-in function that is used by <code><a
+ href="#sec-reflect.loader.prototype.module">Reflect.Loader.prototype.module</a></code> and
+ <code>Reflect.</code>Loader<code>.prototype.import</code> to ensure that a <span style="font-family: Times New
+ Roman">module</span> has been evaluated before it is passed to script code.</p>
+
+ <p>Each EvaluateLoadedModule function has a [[Loader]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a>.</p>
+
+ <p>When a EvaluateLoadedModule function <var>F</var> is called with argument <var>load</var>, the following steps are
+ taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>loader</i> be <i>F</i>.[[Loader]].</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>load</i>.[[Status]] is <code>"linked"</code>.</li>
+ <li>Let <i>module</i> be <i>load</i>.[[Module]].</li>
+ <li>Let <i>result</i> be <a href="#sec-ensureevaluated">EnsureEvaluated</a>(<i>module</i>, (), <i>loader</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>result</i>).</li>
+ <li>Return <i>module</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-ensureevaluated">
+ <h1><span class="secnum" id="sec-15.2.6.2"><a href="#sec-ensureevaluated" title="link to this section">15.2.6.2</a></span>
+ EnsureEvaluated(mod, seen, loader) Abstract Operation</h1>
+
+ <p>The abstract operation EnsureEvaluated walks the dependency graph of the module <var>mod</var>, evaluating any module
+ bodies that have not already been evaluated (including, finally, <var>mod</var> itself). Modules are evaluated in
+ depth-first, left-to-right, post order, stopping at cycles.</p>
+
+ <p><var>mod</var> and its dependencies must already be linked.</p>
+
+ <p>The <a href="#sec-list-and-record-specification-type">List</a> <var>seen</var> is used to detect cycles. <var>mod</var>
+ must not already be in the <a href="#sec-list-and-record-specification-type">List</a> <var>seen</var>.</p>
+
+ <p>On success, <var>mod</var> and all its dependencies, transitively, will have started to evaluate exactly once.</p>
+
+ <p>EnsureEvaluated performs the following steps:</p>
+
+ <ol class="proc">
+ <li>If <i>mod</i>.[[Evaluated]] is <b>true</b>, return <b>undefined</b>.</li>
+ <li>Append <i>mod</i> as the last element of <i>seen</i>.</li>
+ <li style="background-color: #FFC000">TODO: Create the module environment for <i>mod</i></li>
+ <li>Let <i>deps</i> be <i>mod</i>.[[Dependencies]].</li>
+ <li>For each <i>pair</i> in <i>deps</i>, in <a href="#sec-list-and-record-specification-type">List</a> order,
+ <ol class="block">
+ <li>Let <i>dep</i> be <i>pair</i>.[[value]].</li>
+ <li>If <i>dep</i> is not an element of <i>seen</i>, then
+ <ol class="block">
+ <li>Call EnsureEvaluated with the arguments <i>dep</i>, <i>seen</i>, and <i>loader</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>If <i>mod</i>.[[Evaluated]] is <b>true</b>, return <b>undefined</b>.</li>
+ <li>Set <i>mod</i>.[[Evaluated]] to <b>true</b>.</li>
+ <li>If <i>mod</i>.[[Body]] is <b>undefined</b>, then return <b>undefined</b>.</li>
+ <li>Let <i>status</i> be <a
+ href="#sec-moduledeclarationinstantiation">ModuleDeclarationInstantiation</a>(<i>mod</i>.[[Body]],
+ <i>mod</i>.[[Environment]]).</li>
+ <li>Let <i>initContext</i> be a new <a href="#sec-execution-contexts">ECMAScript code execution context</a>.</li>
+ <li>Set <i>initContext</i>'s <a href="#sec-code-realms">Realm</a> to <i>loader</i>.[[Realm]].</li>
+ <li>Set <i>initContext</i>'s <a href="#sec-execution-contexts">VariableEnvironment</a> to
+ <i>mod</i>.[[Environment]].</li>
+ <li>Set <i>initContext</i>'s <a href="#sec-execution-contexts">LexicalEnvironment</a> to
+ <i>mod</i>.[[Environment]].</li>
+ <li>If there is a <a href="#sec-execution-contexts">currently running execution context</a>, <a
+ href="#sec-execution-contexts">suspend</a> it.</li>
+ <li>Push <i>initContext</i> on to <a href="#sec-execution-contexts">the execution context stack</a>; <i>initContext</i>
+ is now <a href="#sec-execution-contexts">the running execution context</a>.</li>
+ <li>Let <i>r</i> be the result of evaluating <i>mod</i>.[[Body]].</li>
+ <li><a href="#sec-execution-contexts">Suspend</a> <i>initContext</i> and remove it from <a
+ href="#sec-execution-contexts">the execution context stack</a>.</li>
+ <li>Resume the context, if any, that is now on the top of <a href="#sec-execution-contexts">the execution context
+ stack</a> as <a href="#sec-execution-contexts">the running execution context</a>.</li>
+ <li>Return <i>r</i>.</li>
+ </ol>
+ </section>
+ </section>
+ </section>
+</section>
+
+<section id="sec-error-handling-and-language-extensions">
+ <h1><span class="secnum" id="sec-16"><a href="#sec-error-handling-and-language-extensions"
+ title="link to this section">16</a></span> Error Handling and Language Extensions</h1>
+
+ <p>An implementation must report most errors at the time the relevant ECMAScript language construct is evaluated. An <i>early
+ error</i> is an error that can be detected and reported prior to the evaluation of any construct in the <span
+ class="nt">Script</span> containing the error. The presense of an early error prevents the evaluation of the construct. An
+ implementation must report early errors in a <span class="nt">Script</span> as part of the <a
+ href="#sec-scriptevaluationtask">ScriptEvaluationTask</a> for that <span class="nt">Script</span>. Early errors in a <span
+ class="nt">Module</span> are reported at the point when the <span class="nt">Module</span> would be evaluated and the <span
+ class="nt">Module</span> is never initialized. Early errors in <b>eval</b> code are reported at the time <code>eval</code> is
+ called and prevent evaluation of the <b>eval</b> code. All errors that are not early errors are runtime errors.</p>
+
+ <p>An implementation must report as an early error any occurrence of a condition that is listed in a “Static Semantics:
+ Early Errors” subclause of this specification.</p>
+
+ <p>An implementation shall not treat other kinds of errors as early errors even if the compiler can prove that a construct
+ cannot execute without error under any circumstances. An implementation may issue an early warning in such a case, but it should
+ not report the error until the relevant construct is actually executed.</p>
+
+ <p>An implementation shall report all errors as specified, except for the following:</p>
+
+ <ul>
+ <li>
+ <p>An implementation may extend <i>Script</i> syntax, <i>Module</i> syntax, and regular expression pattern or flag syntax.
+ To permit this, all operations (such as calling <code>eval</code>, using a regular expression literal, or using the
+ <code>Function</code> or <code>RegExp</code> constructor) that are allowed to throw <b>SyntaxError</b> are permitted to
+ exhibit implementation-defined behaviour instead of throwing <b>SyntaxError</b> when they encounter an
+ implementation-defined extension to the script syntax or regular expression pattern or flag syntax.</p>
+ </li>
+
+ <li>
+ <p>An implementation may provide additional types, values, objects, properties, and functions beyond those described in this
+ specification. This may cause constructs (such as looking up a variable in the global scope) to have implementation-defined
+ behaviour instead of throwing an error (such as <b>ReferenceError</b>).</p>
+ </li>
+ </ul>
+
+ <p>An implementation may define behaviour other than throwing <b>RangeError</b> for <code>toFixed</code>,
+ <code>toExponential</code>, and <code>toPrecision</code> when the <var>fractionDigits</var> or <var>precision</var> argument is
+ outside the specified range.</p>
+</section>
+
+<section id="sec-ecmascript-standard-built-in-objects">
+ <h1><span class="secnum" id="sec-17"><a href="#sec-ecmascript-standard-built-in-objects"
+ title="link to this section">17</a></span> ECMAScript Standard Built-in Objects</h1>
+
+ <p>There are certain built-in objects available whenever an ECMAScript <span class="nt">Script</span> begins execution. One, the
+ global object, is part of the <a href="#sec-lexical-environments">lexical environment</a> of the executing program. Others are
+ accessible as initial properties of the global object or indirectly as properties of accessible built-in objects.</p>
+
+ <p>Unless specified otherwise, a built-in object that is callable as a function is a Built-in Function object with the
+ characteristics described in <a href="#sec-built-in-function-objects">9.3</a>. Unless specified otherwise, the [[Extensible]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of a built-in object initially has the value
+ <b>true</b>. Every built-in object has a [[Realm]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>
+ whose value is the code <a href="#sec-code-realms">Realm</a> for which the object was initially created.</p>
+
+ <p>Many built-in objects are functions: they can be invoked with arguments. Some of them furthermore are constructors: they are
+ functions intended for use with the <code>new</code> operator. For each built-in function, this specification describes the
+ arguments required by that function and properties of the Function object. For each built-in constructor, this specification
+ furthermore describes properties of the prototype object of that constructor and properties of specific object instances
+ returned by a <code>new</code> expression that invokes that constructor.</p>
+
+ <p>Unless otherwise specified in the description of a particular function, if a built-in function or constructor is given fewer
+ arguments than the function is specified to require, the function or constructor shall behave exactly as if it had been given
+ sufficient additional arguments, each such argument being the <b>undefined</b> value. Such missing arguments are considered to
+ be “not present” and may be identified in that manner by specification algorithms.</p>
+
+ <p>Unless otherwise specified in the description of a particular function, if a built-in function or constructor described is
+ given more arguments than the function is specified to allow, the extra arguments are evaluated by the call and then ignored by
+ the function. However, an implementation may define implementation specific behaviour relating to such arguments as long as the
+ behaviour is not the throwing of a <b>TypeError</b> exception that is predicated simply on the presence of an extra
+ argument.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Implementations that add additional capabilities to the set of built-in functions are
+ encouraged to do so by adding new functions rather than adding new parameters to existing functions.</p>
+ </div>
+
+ <p>Unless otherwise specified every built-in function and every built-in constructor has the Function prototype object, which is
+ the initial value of the expression <code>Function.prototype</code> (<a
+ href="#sec-properties-of-the-function-prototype-object">19.2.3</a>), as the value of its [[Prototype]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</p>
+
+ <p>Unless otherwise specified every built-in prototype object has the Object prototype object, which is the initial value of the
+ expression <code>Object.prototype</code> (<a href="#sec-properties-of-the-object-prototype-object">19.1.3</a>), as the value of
+ its [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, except the Object prototype
+ object itself.</p>
+
+ <p>Built-in function objects that are not identified as constructors do not implement the [[Construct]] internal method unless
+ otherwise specified in the description of a particular function.</p>
+
+ <p>Unless otherwise specified, every built-in function defined in clauses 18 through 26 are created as if by calling the <a
+ href="#sec-createbuiltinfunction">CreateBuiltinFunction</a> abstract operation (<a
+ href="#sec-built-in-function-objects-call-thisargument-argumentslist">9.3.1</a>).</p>
+
+ <p>Every built-in Function object, including constructors, has a <code>length</code> property whose value is an integer. Unless
+ otherwise specified, this value is equal to the largest number of named arguments shown in the subclause headings for the
+ function description, including optional parameters. However, rest parameters shown using the form “...name” are not
+ included in the default argument count.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> For example, the Function object that is the initial value of the <code>slice</code> property
+ of the String prototype object is described under the subclause heading “<a
+ href="#sec-string.prototype.slice">String.prototype.slice</a> (start, end)” which shows the two named arguments start
+ and end; therefore the value of the <code>length</code> property of that Function object is <code>2</code>.</p>
+ </div>
+
+ <p>Unless otherwise specified, the <code>length</code> property of a built-in Function object has the attributes
+ { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]: <b>true</b> }.</p>
+
+ <p>Every built-in Function object, including constructors, that is not identified as an anonymous function has a
+ <code>name</code> property whose value is a String. Unless otherwise specified, this value is the name that is given to the
+ function in this specification. For functions that are specified as properties of objects, the name value is the property name
+ string used to access the function. Functions that are specified as get or set accessor functions of built-in properties have
+ "<code>get</code> " or "<code>set</code> " prepended to the property name string. The value of the <code>name</code> property
+ is explicitly specified for each built-in functions whose <a href="#sec-object-type">property key</a> is a symbol value.</p>
+
+ <p>Unless otherwise specified, the <code>name</code> property of a built-in Function object, if it exists, has the attributes
+ { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]: <b>true</b> }.</p>
+
+ <p>Every other data property described in clauses 18 through 26 has the attributes { [[Writable]]: <b>true</b>, [[Enumerable]]:
+ <b>false</b>, [[Configurable]]: <b>true</b> } unless otherwise specified.</p>
+
+ <p>Every accessor property described in clauses 18 through 26 has the attributes {[[Enumerable]]: <b>false</b>,
+ [[Configurable]]: <b>true</b> } unless otherwise specified. If only a get accessor function is described, the set accessor
+ function is the default value, <b>undefined</b>. If only a set accessor is function is described the get accessor is the
+ default value, <b>undefined</b>.</p>
+</section>
+
+<section id="sec-global-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-18"><a href="#sec-global-object" title="link to this section">18</a></span> The Global
+ Object</h1>
+
+ <p>The unique <i>global object</i> is created before control enters any <a href="#sec-execution-contexts">execution
+ context</a>.</p>
+
+ <p>The global object does not have a [[Construct]] internal method; it is not possible to use the global object as a
+ constructor with the <code>new</code> operator.</p>
+
+ <p>The global object does not have a [[Call]] internal method; it is not possible to invoke the global object as a
+ function.</p>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the global
+ object is implementation-dependent.</p>
+
+ <p>In addition to the properties defined in this specification the global object may have additional host defined properties.
+ This may include a property whose value is the global object itself; for example, in the HTML document object model the
+ <code>window</code> property of the global object is the global object itself.</p>
+ </div>
+
+ <section id="sec-value-properties-of-the-global-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-18.1"><a href="#sec-value-properties-of-the-global-object"
+ title="link to this section">18.1</a></span> Value Properties of the Global Object</h1>
+ </div>
+
+ <section id="sec-value-properties-of-the-global-object-infinity">
+ <h1><span class="secnum" id="sec-18.1.1"><a href="#sec-value-properties-of-the-global-object-infinity"
+ title="link to this section">18.1.1</a></span> Infinity</h1>
+
+ <p>The value of <code>Infinity</code> is <b>+∞</b> (<a href="#sec-ecmascript-language-types-number-type">see
+ 6.1.6</a>). This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-value-properties-of-the-global-object-nan">
+ <h1><span class="secnum" id="sec-18.1.2"><a href="#sec-value-properties-of-the-global-object-nan"
+ title="link to this section">18.1.2</a></span> NaN</h1>
+
+ <p>The value of <code>NaN</code> is <b>NaN</b> (<a href="#sec-ecmascript-language-types-number-type">see 6.1.6</a>). This
+ property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]: <b>false</b>
+ }.</p>
+ </section>
+
+ <section id="sec-undefined">
+ <h1><span class="secnum" id="sec-18.1.3"><a href="#sec-undefined" title="link to this section">18.1.3</a></span>
+ undefined</h1>
+
+ <p>The value of <code>undefined</code> is <b>undefined</b> (<a href="#sec-ecmascript-language-types-undefined-type">see
+ 6.1.1</a>). This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+ </section>
+
+ <section id="sec-function-properties-of-the-global-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-18.2"><a href="#sec-function-properties-of-the-global-object"
+ title="link to this section">18.2</a></span> Function Properties of the Global Object</h1>
+ </div>
+
+ <section id="sec-eval-x">
+ <div class="front">
+ <h1><span class="secnum" id="sec-18.2.1"><a href="#sec-eval-x" title="link to this section">18.2.1</a></span> eval
+ (x)</h1>
+
+ <p>When the <code>eval</code> function is called with one argument <var>x</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>x</i>) is not String, return <i>x</i>.</li>
+ <li>Let <i>script</i> be the ECMAScript code that is the result of parsing <i>x</i>, interpreted as UTF-16 encoded
+ Unicode text as described in <a href="#sec-static-semantics-utf-16encoding">10.1.1</a><i>,</i> for the goal symbol
+ <i>Script</i>. If the parse fails or any early errors are detected, throw a <b>SyntaxError</b> exception (but <a
+ href="#sec-error-handling-and-language-extensions">see also clause 16</a>).</li>
+ <li>If <i>script</i> Contains <i>ScriptBody</i> is <b>false</b>, return <b>undefined</b>.</li>
+ <li>Let <i>strictScript</i> be IsStrict of <i>script</i>.</li>
+ <li>If this is a direct call to eval (<a href="#sec-direct-call-to-eval">18.2.1.1</a>), let <i>direct</i> be
+ <b>true</b>, otherwise let <i>direct</i> be <b>false</b>.</li>
+ <li>If <i>direct</i> is <b>true</b> and the code that made the direct call to eval is <a
+ href="#sec-strict-mode-code">strict code</a>, then let <i>strictCaller</i> be <b>true</b><i>.</i> Otherwise, let
+ <i>strictCaller</i> be <b>false</b><i>.</i></li>
+ <li>Let <i>ctx</i> be <a href="#sec-execution-contexts">the running execution context</a>. If <i>direct</i> is
+ <b>true</b> <i>ctx</i> will be the <a href="#sec-execution-contexts">execution context</a> that performed the direct
+ eval. If <i>direct</i> is <b>false</b> <i>ctx</i> will be the <a href="#sec-execution-contexts">execution
+ context</a> for the invocation of the eval function.</li>
+ <li>Let <i>evalRealm</i> be <i>ctx’s</i> <a href="#sec-code-realms">Realm</a>.</li>
+ <li>If <i>direct</i> is <b>false</b> and <i>strictScript</i> is <b>false</b>, then
+ <ol class="block">
+ <li>Return the result of ScriptEvaluation for <i>script</i> with arguments <i>evalRealm</i> and <b>true</b>.</li>
+ </ol>
+ </li>
+ <li>If <i>direct</i> is <b>true</b>, <i>strictScript</i> is <b>false</b>, <i>strictCaller</i> is <b>false</b>, and
+ <i>ctx’s</i> <a href="#sec-execution-contexts">LexicalEnvironment</a> is the same as
+ <i>evalRealm</i>.[[globalEnv]], then
+ <ol class="block">
+ <li>Return the result of ScriptEvaluation for <i>script</i> with arguments <i>evalRealm</i> and <b>true</b>.</li>
+ </ol>
+ </li>
+ <li>If <i>direct</i> is <b>true</b>, then
+ <ol class="block">
+ <li>If the code that made the direct call to eval is function code and ValidInFunction of <i>script</i> is
+ <b>false</b>, then throw a <b>SyntaxError</b> exception.</li>
+ <li>If the code that made the direct call to eval is module code and ValidInModule of <i>script</i> is <b>false</b>,
+ then throw a <b>SyntaxError</b> exception.</li>
+ </ol>
+ </li>
+ <li>If <i>direct</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>lexEnv</i> be <i>ctx’s</i> <a href="#sec-execution-contexts">LexicalEnvironment</a>.</li>
+ <li>Let <i>varEnv</i> be <i>ctx’s</i> <a href="#sec-execution-contexts">VariableEnvironment</a>.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>lexEnv</i> be <i>evalRealm</i>.[[globalEnv]].</li>
+ <li>Let <i>varEnv</i> be <i>evalRealm</i>.[[globalEnv]].</li>
+ </ol>
+ </li>
+ <li>If <i>strictScript</i> is <b>true</b> or if <i>direct</i> is <b>true</b> and <i>strictCaller</i> is <b>true</b> ,
+ then
+ <ol class="block">
+ <li>Let <i>strictVarEnv</i> be <a
+ href="#sec-newdeclarativeenvironment">NewDeclarativeEnvironment</a>(<i>lexEnv</i>).</li>
+ <li>Let <i>lexEnv</i> be <i>strictVarEnv</i>.</li>
+ <li>Let <i>varEnv</i> be <i>strictVarEnv</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>status</i> be the result of performing Eval Declaration Instantiation as described in <a
+ href="#sec-eval-declaration-instantiation">18.2.1.2</a> with <i>script</i>, <i>varEnv</i>, and <i>lexEnv</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Let <i>evalCxt</i> be a new <a href="#sec-execution-contexts">ECMAScript code execution context</a>.</li>
+ <li>Set the <i>evalCxt’s</i> <a href="#sec-code-realms">Realm</a> to <i>evalRealm</i>.</li>
+ <li>Set the <i>evalCxt’s</i> <a href="#sec-execution-contexts">VariableEnvironment</a> to <i>varEnv</i>.</li>
+ <li>Set the <i>evalCxt’s</i> <a href="#sec-execution-contexts">LexicalEnvironment</a> to <i>lexEnv</i>.</li>
+ <li>If there is a <a href="#sec-execution-contexts">currently running execution context</a>, <a
+ href="#sec-execution-contexts">suspend</a> it.</li>
+ <li>Push <i>evalCxt</i> on to <a href="#sec-execution-contexts">the execution context stack</a>; <i>evalCxt</i> is now
+ <a href="#sec-execution-contexts">the running execution context</a>.</li>
+ <li>Let <i>result</i> be the result of evaluating <i>script</i>.</li>
+ <li><a href="#sec-execution-contexts">Suspend</a> <i>evalCxt</i> and remove it from <a
+ href="#sec-execution-contexts">the execution context stack</a>.</li>
+ <li>Resume the context that is now on the top of <a href="#sec-execution-contexts">the execution context stack</a> as <a
+ href="#sec-execution-contexts">the running execution context</a>.</li>
+ <li>Return <i>result</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The eval code cannot instantiate variable or function bindings in the variable
+ environment of the calling context that invoked the eval if either the code of the calling context or the eval code is
+ <a href="#sec-strict-mode-code">strict code</a>. Instead such bindings are instantiated in a new <a
+ href="#sec-execution-contexts">VariableEnvironment</a> that is only accessible to the eval code.</p>
+ </div>
+ </div>
+
+ <section id="sec-direct-call-to-eval">
+ <h1><span class="secnum" id="sec-18.2.1.1"><a href="#sec-direct-call-to-eval"
+ title="link to this section">18.2.1.1</a></span> Direct Call to Eval</h1>
+
+ <p>A direct call to the eval function is one that is expressed as a <span class="nt">CallExpression</span> that meets all
+ of the following conditions:</p>
+
+ <ul>
+ <li>
+ <p>The <a href="#sec-reference-specification-type">Reference</a> that is the result of evaluating the MemberExpression
+ in the CallExpression will always have an environment record as its base value and its referenced name is "eval".</p>
+ </li>
+
+ <li>
+ <p>The result of calling the abstract operation <a href="#sec-getvalue">GetValue</a> with that <a
+ href="#sec-reference-specification-type">Reference</a> as the argument is the standard built-in function defined in <a
+ href="#sec-eval-x">18.2.1</a>.</p>
+ </li>
+ </ul>
+ </section>
+
+ <section id="sec-eval-declaration-instantiation">
+ <h1><span class="secnum" id="sec-18.2.1.2"><a href="#sec-eval-declaration-instantiation"
+ title="link to this section">18.2.1.2</a></span> Eval Declaration Instantiation</h1>
+ </section>
+ </section>
+
+ <section id="sec-isfinite-number">
+ <h1><span class="secnum" id="sec-18.2.2"><a href="#sec-isfinite-number" title="link to this section">18.2.2</a></span>
+ isFinite (number)</h1>
+
+ <p>Returns <b>false</b> if the argument coerces to <b>NaN</b>, <b>+∞</b>, or <b>−∞</b>, and otherwise
+ returns <b>true</b>.</p>
+
+ <ol class="proc">
+ <li>Let <i>num</i> be <a href="#sec-tonumber">ToNumber</a>(<i>number</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>num</i>).</li>
+ <li>If <i>num</i> is <b>NaN</b>, <b>+∞</b>, or <b>−∞</b>, return <b>false</b>.</li>
+ <li>Otherwise, return <b>true</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-isnan-number">
+ <h1><span class="secnum" id="sec-18.2.3"><a href="#sec-isnan-number" title="link to this section">18.2.3</a></span> isNaN
+ (number)</h1>
+
+ <p>Returns <b>true</b> if the argument coerces to <b>NaN</b>, and otherwise returns <b>false</b>.</p>
+
+ <ol class="proc">
+ <li>Let <i>num</i> be <a href="#sec-tonumber">ToNumber</a>(<i>number</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>num</i>).</li>
+ <li>If <i>num</i> is <b>NaN</b>, return <b>true</b>.</li>
+ <li>Otherwise, return <b>false</b>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> A reliable way for ECMAScript code to test if a value <code>X</code> is a <b>NaN</b> is an
+ expression of the form <code>X !== X</code>. The result will be <b>true</b> if and only if <code>X</code> is a
+ <b>NaN</b>.</p>
+ </div>
+ </section>
+
+ <section id="sec-parsefloat-string">
+ <h1><span class="secnum" id="sec-18.2.4"><a href="#sec-parsefloat-string" title="link to this section">18.2.4</a></span>
+ parseFloat (string)</h1>
+
+ <p>The <code>parseFloat</code> function produces a Number value dictated by interpretation of the contents of the
+ <var>string</var> argument as a decimal literal.</p>
+
+ <p>When the <code>parseFloat</code> function is called, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>inputString</i> be <a href="#sec-tostring">ToString</a>(<i>string</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>inputString</i>).</li>
+ <li>Let <i>trimmedString</i> be a substring of <i>inputString</i> consisting of the leftmost character that is not a
+ <i>StrWhiteSpaceChar</i> and all characters to the right of that character. (In other words, remove leading white
+ space.) If <i>inputString</i> does not contain any such characters, let <i>trimmedString</i> be the empty string.</li>
+ <li>If neither <i>trimmedString</i> nor any prefix of <i>trimmedString</i> satisfies the syntax of a
+ <i>StrDecimalLiteral</i> (<a href="#sec-tonumber-applied-to-the-string-type">see 7.1.3.1</a>), return <b>NaN</b>.</li>
+ <li>Let <i>numberString</i> be the longest prefix of <i>trimmedString</i>, which might be <i>trimmedString</i> itself,
+ that satisfies the syntax of a <i>StrDecimalLiteral</i>.</li>
+ <li>Return the Number value for the MV of <i>numberString</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> <code>parseFloat</code> may interpret only a leading portion of <i>string</i> as a Number
+ value; it ignores any characters that cannot be interpreted as part of the notation of an decimal literal, and no
+ indication is given that any such characters were ignored.</p>
+ </div>
+ </section>
+
+ <section id="sec-parseint-string-radix">
+ <h1><span class="secnum" id="sec-18.2.5"><a href="#sec-parseint-string-radix" title="link to this section">18.2.5</a></span>
+ parseInt (string , radix)</h1>
+
+ <p>The <code>parseInt</code> function produces an integer value dictated by interpretation of the contents of the
+ <var>string</var> argument according to the specified <var>radix</var>. Leading white space in <var>string</var> is ignored.
+ If <var>radix</var> is <b>undefined</b> or 0, it is assumed to be <span style="font-family: Times New Roman">10</span>
+ except when the number begins with the character pairs <code>0x</code> or <code>0X</code>, in which case a radix of 16 is
+ assumed. If <var>radix</var> is <span style="font-family: Times New Roman">16,</span> the number may also optionally begin
+ with the character pairs <code>0x</code> or <code>0X</code>.</p>
+
+ <p>When the <code>parseInt</code> function is called, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>inputString</i> be <a href="#sec-tostring">ToString</a>(<i>string</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>string</i>).</li>
+ <li>Let <i>S</i> be a newly created substring of <i>inputString</i> consisting of the first character that is not a
+ <i>StrWhiteSpaceChar</i> and all characters following that character. (In other words, remove leading white space.) If
+ <i>inputString</i> does not contain any such characters, let <i>S</i> be the empty string.</li>
+ <li>Let <i>sign</i> be 1.</li>
+ <li>If <i>S</i> is not empty and the first character of <i>S</i> is a minus sign <b>-</b>, let <i>sign</i> be
+ −1.</li>
+ <li>If <i>S</i> is not empty and the first character of <i>S</i> is a plus sign <b>+</b> or a minus sign <b>-</b>, then
+ remove the first character from <i>S</i>.</li>
+ <li>Let <i>R</i> = <a href="#sec-toint32">ToInt32</a>(<i>radix</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>R</i>).</li>
+ <li>Let <i>stripPrefix</i> be <b>true</b>.</li>
+ <li>If <i>R</i> ≠ 0, then
+ <ol class="block">
+ <li>If <i>R</i> < 2 or <i>R</i> > 36, then return <b>NaN</b>.</li>
+ <li>If <i>R</i> ≠ 16, let <i>stripPrefix</i> be <b>false</b>.</li>
+ </ol>
+ </li>
+ <li>Else <i>R</i> = 0,
+ <ol class="block">
+ <li>Let <i>R</i> = 10.</li>
+ </ol>
+ </li>
+ <li>If <i>stripPrefix</i> is <b>true</b>, then
+ <ol class="block">
+ <li>If the length of <i>S</i> is at least 2 and the first two characters of <i>S</i> are either
+ “<b>0x</b>” or “<b>0X</b>”, then remove the first two characters from <i>S</i> and let
+ <i>R</i> = 16.</li>
+ </ol>
+ </li>
+ <li>If <i>S</i> contains any character that is not a radix-<i>R</i> digit, then let <i>Z</i> be the substring of <i>S</i>
+ consisting of all characters before the first such character; otherwise, let <i>Z</i> be <i>S</i>.</li>
+ <li>If <i>Z</i> is empty, return <b>NaN</b>.</li>
+ <li>Let <i>mathInt</i> be the mathematical integer value that is represented by <i>Z</i> in radix-<i>R</i> notation, using
+ the letters <b>A</b>-<b>Z</b> and <b>a</b>-<b>z</b> for digits with values 10 through 35. (However, if <i>R</i> is 10
+ and <i>Z</i> contains more than 20 significant digits, every significant digit after the 20th may be replaced by a
+ <b>0</b> digit, at the option of the implementation; and if <i>R</i> is not 2, 4, 8, 10, 16, or 32, then
+ <i>mathInt</i> may be an implementation-dependent approximation to the mathematical integer value that is represented
+ by <i>Z</i> in radix-<i>R</i> notation.)</li>
+ <li>Let <i>number</i> be the Number value for <i>mathInt</i>.</li>
+ <li>Return <i>sign</i> × <i>number</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> <code>parseInt</code> may interpret only a leading portion of <i>string</i> as an integer
+ value; it ignores any characters that cannot be interpreted as part of the notation of an integer, and no indication is
+ given that any such characters were ignored.</p>
+ </div>
+ </section>
+
+ <section id="sec-uri-handling-functions">
+ <div class="front">
+ <h1><span class="secnum" id="sec-18.2.6"><a href="#sec-uri-handling-functions"
+ title="link to this section">18.2.6</a></span> URI Handling Functions</h1>
+
+ <p>Uniform Resource Identifiers, or URIs, are Strings that identify resources (e.g. web pages or files) and transport
+ protocols by which to access them (e.g. HTTP or FTP) on the Internet. The ECMAScript language itself does not provide any
+ support for using URIs except for functions that encode and decode URIs as described in <a
+ href="#sec-decodeuri-encodeduri">18.2.6.2</a>, <a href="#sec-decodeuricomponent-encodeduricomponent">18.2.6.3</a>, <a
+ href="#sec-encodeuri-uri">18.2.6.4</a> and <a href="#sec-encodeuricomponent-uricomponent">18.2.6.5</a></p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Many implementations of ECMAScript provide additional functions and methods that
+ manipulate web pages; these functions are beyond the scope of this standard.</p>
+ </div>
+ </div>
+
+ <section id="sec-uri-syntax-and-semantics">
+ <div class="front">
+ <h1><span class="secnum" id="sec-18.2.6.1"><a href="#sec-uri-syntax-and-semantics"
+ title="link to this section">18.2.6.1</a></span> URI Syntax and Semantics</h1>
+
+ <p>A URI is composed of a sequence of components separated by component separators. The general form is:</p>
+
+ <div class="gp prod"><span class="nt">Scheme</span> <span class="geq">:</span> <span class="nt">First</span> <code class="t">/</code> <span class="nt">Second</span> <code class="t">;</code> <span class="nt">Third</span> <code class="t">?</code> <span class="nt">Fourth</span></div>
+
+ <p>where the italicized names represent components and “<code>:</code>”, “<code>/</code>”,
+ “<code>;</code>” and “<code>?</code>” are reserved characters used as separators. The
+ <code>encodeURI</code> and <code>decodeURI</code> functions are intended to work with complete URIs; they assume that
+ any reserved characters in the URI are intended to have special meaning and so are not encoded. The
+ <code>encodeURIComponent</code> and <code>decodeURIComponent</code> functions are intended to work with the individual
+ component parts of a URI; they assume that any reserved characters represent text and so must be encoded so that they
+ are not interpreted as reserved characters when the component is part of a complete URI.</p>
+
+ <p>The following lexical grammar specifies the form of encoded URIs.</p>
+
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">uri</span> <span class="geq">:::</span></div>
+ <div class="rhs"><span class="nt">uriCharacters</span><sub>opt</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">uriCharacters</span> <span class="geq">:::</span></div>
+ <div class="rhs"><span class="nt">uriCharacter</span> <span class="nt">uriCharacters</span><sub>opt</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">uriCharacter</span> <span class="geq">:::</span></div>
+ <div class="rhs"><span class="nt">uriReserved</span></div>
+ <div class="rhs"><span class="nt">uriUnescaped</span></div>
+ <div class="rhs"><span class="nt">uriEscaped</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">uriReserved</span> <span class="geq">:::</span> <span class="grhsmod">one of</span></div>
+ <div class="rhs"><code class="t">;</code> <code class="t">/</code> <code class="t">?</code> <code class="t">:</code> <code class="t">@</code> <code class="t">&</code> <code class="t">=</code> <code class="t">+</code> <code class="t">$</code> <code class="t">,</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">uriUnescaped</span> <span class="geq">:::</span></div>
+ <div class="rhs"><span class="nt">uriAlpha</span></div>
+ <div class="rhs"><span class="nt">DecimalDigit</span></div>
+ <div class="rhs"><span class="nt">uriMark</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">uriEscaped</span> <span class="geq">:::</span></div>
+ <div class="rhs"><code class="t">%</code> <span class="nt">HexDigit</span> <span class="nt">HexDigit</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">uriAlpha</span> <span class="geq">:::</span> <span class="grhsmod">one of</span></div>
+ <div class="rhs"><code class="t">a</code> <code class="t">b</code> <code class="t">c</code> <code class="t">d</code> <code class="t">e</code> <code class="t">f</code> <code class="t">g</code> <code class="t">h</code> <code class="t">i</code> <code class="t">j</code> <code class="t">k</code> <code class="t">l</code> <code class="t">m</code> <code class="t">n</code> <code class="t">o</code> <code class="t">p</code> <code class="t">q</code> <code class="t">r</code> <code class="t">s</code> <code class="t">t</code> <code class="t">u</code> <code class="t">v</code> <code class="t">w</code> <code class="t">x</code> <code class="t">y</code> <code class="t">z</code></div>
+ <div class="rhs"><code class="t">A</code> <code class="t">B</code> <code class="t">C</code> <code class="t">D</code> <code class="t">E</code> <code class="t">F</code> <code class="t">G</code> <code class="t">H</code> <code class="t">I</code> <code class="t">J</code> <code class="t">K</code> <code class="t">L</code> <code class="t">M</code> <code class="t">N</code> <code class="t">O</code> <code class="t">P</code> <code class="t">Q</code> <code class="t">R</code> <code class="t">S</code> <code class="t">T</code> <code class="t">U</code> <code class="t">V</code> <code class="t">W</code> <code class="t">X</code> <code class="t">Y</code> <code class="t">Z</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">uriMark</span> <span class="geq">:::</span> <span class="grhsmod">one of</span></div>
+ <div class="rhs"><code class="t">-</code> <code class="t">_</code> <code class="t">.</code> <code class="t">!</code> <code class="t">~</code> <code class="t">*</code> <code class="t">'</code> <code class="t">(</code> <code class="t">)</code></div>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The above syntax is based upon RFC 2396 and does not reflect changes introduced by the
+ more recent RFC 3986.</p>
+ </div>
+
+ <p><b>Runtime Semantics</b></p>
+
+ <p>When a character to be included in a URI is not listed above or is not intended to have the special meaning sometimes
+ given to the reserved characters, that character must be encoded. The character is transformed into its UTF-8 encoding,
+ with surrogate pairs first converted from UTF-16 to the corresponding code point value. (Note that for code units in the
+ range [0,127] this results in a single octet with the same value.) The resulting sequence of octets is then transformed
+ into a String with each octet represented by an escape sequence of the form “<code><b>%</b>xx</code>”.</p>
+ </div>
+
+ <section id="sec-encode">
+ <h1><span class="secnum" id="sec-18.2.6.1.1"><a href="#sec-encode" title="link to this section">18.2.6.1.1</a></span>
+ Runtime Semantics: Encode Abstract Operation</h1>
+
+ <p>The encoding and escaping process is described by the abstract operation Encode taking two String arguments
+ <var>string</var> and <var>unescapedSet</var>.</p>
+
+ <ol class="proc">
+ <li>Let <i>strLen</i> be the number of characters in <i>string</i>.</li>
+ <li>Let <i>R</i> be the empty String.</li>
+ <li>Let <i>k</i> be 0.</li>
+ <li>Repeat
+ <ol class="block">
+ <li>If <i>k</i> equals <i>strLen</i>, return <i>R</i>.</li>
+ <li>Let <i>C</i> be the character at position <i>k</i> within <i>string</i>.</li>
+ <li>If <i>C</i> is in <i>unescapedSet</i>, then
+ <ol class="block">
+ <li>Let <i>S</i> be a String containing only the character <i>C</i>.</li>
+ <li>Let <i>R</i> be a new String value computed by concatenating the previous value of <i>R</i> and
+ <i>S</i>.</li>
+ </ol>
+ </li>
+ <li>Else <i>C</i> is not in <i>unescapedSet</i>,
+ <ol class="block">
+ <li>If the code unit value of <i>C</i> is not less than 0xDC00 and not greater than 0xDFFF, throw a <b><a
+ href="#sec-constructor-properties-of-the-global-object-urierror">URIError</a></b> exception.</li>
+ <li>If the code unit value of <i>C</i> is less than 0xD800 or greater than 0xDBFF, then
+ <ol class="block">
+ <li>Let <i>V</i> be the code unit value of <i>C</i>.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Increase <i>k</i> by 1.</li>
+ <li>If <i>k</i> equals <i>strLen</i>, throw a <b><a
+ href="#sec-constructor-properties-of-the-global-object-urierror">URIError</a></b> exception.</li>
+ <li>Let <i>kChar</i> be the code unit value of the character at position <i>k</i> within
+ <i>string</i>.</li>
+ <li>If <i>kChar</i> is less than 0xDC00 or greater than 0xDFFF, throw a <b><a
+ href="#sec-constructor-properties-of-the-global-object-urierror">URIError</a></b> exception.</li>
+ <li>Let <i>V</i> be (((the code unit value of <i>C</i>) – 0xD800) × 0x400 + (<i>kChar</i>
+ – 0xDC00) + 0x10000).</li>
+ </ol>
+ </li>
+ <li>Let <i>Octets</i> be the array of octets resulting by applying the UTF-8 transformation to <i>V</i>, and
+ let <i>L</i> be the array size.</li>
+ <li>Let <i>j</i> be 0.</li>
+ <li>Repeat, while <i>j</i> < <i>L</i>
+ <ol class="block">
+ <li>Let <i>jOctet</i> be the value at position <i>j</i> within <i>Octets</i>.</li>
+ <li>Let <i>S</i> be a String containing three characters “<b>%</b><i>XY</i>” where <i>XY</i>
+ are two uppercase hexadecimal digits encoding the value of <i>jOctet</i>.</li>
+ <li>Let <i>R</i> be a new String value computed by concatenating the previous value of <i>R</i> and
+ <i>S</i>.</li>
+ <li>Increase <i>j</i> by 1.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Increase <i>k</i> by 1.</li>
+ </ol>
+ </li>
+ </ol>
+ </section>
+
+ <section id="sec-decode">
+ <h1><span class="secnum" id="sec-18.2.6.1.2"><a href="#sec-decode" title="link to this section">18.2.6.1.2</a></span>
+ Runtime Semantics: Decode Abstract Operation</h1>
+
+ <p>The unescaping and decoding process is described by the abstract operation Decode taking two String arguments
+ <var>string</var> and <var>reservedSet</var>.</p>
+
+ <ol class="proc">
+ <li>Let <i>strLen</i> be the number of characters in <i>string</i>.</li>
+ <li>Let <i>R</i> be the empty String.</li>
+ <li>Let <i>k</i> be 0.</li>
+ <li>Repeat
+ <ol class="block">
+ <li>If <i>k</i> equals <i>strLen</i>, return <i>R</i>.</li>
+ <li>Let <i>C</i> be the character at position <i>k</i> within <i>string</i>.</li>
+ <li>If <i>C</i> is not ‘<b>%</b>’, then
+ <ol class="block">
+ <li>Let <i>S</i> be the String containing only the character <i>C</i>.</li>
+ </ol>
+ </li>
+ <li>Else <i>C</i> is ‘<b>%</b>’,
+ <ol class="block">
+ <li>Let <i>start</i> be <i>k</i>.</li>
+ <li>If <i>k</i> + 2 is greater than or equal to <i>strLen</i>, throw a <b><a
+ href="#sec-constructor-properties-of-the-global-object-urierror">URIError</a></b> exception.</li>
+ <li>If the characters at position (<i>k</i>+1) and (<i>k</i> + 2) within <i>string</i> do not represent
+ hexadecimal digits, throw a <b><a
+ href="#sec-constructor-properties-of-the-global-object-urierror">URIError</a></b> exception.</li>
+ <li>Let <i>B</i> be the 8-bit value represented by the two hexadecimal digits at position (<i>k</i> + 1) and
+ (<i>k</i> + 2).</li>
+ <li>Increment <i>k</i> by 2.</li>
+ <li>If the most significant bit in <i>B</i> is 0, then
+ <ol class="block">
+ <li>Let <i>C</i> be the character with code unit value <i>B</i>.</li>
+ <li>If <i>C</i> is not in <i>reservedSet</i>, then
+ <ol class="block">
+ <li>Let <i>S</i> be the String containing only the character <i>C</i>.</li>
+ </ol>
+ </li>
+ <li>Else <i>C</i> is in <i>reservedSet</i>,
+ <ol class="block">
+ <li>Let <i>S</i> be the substring of <i>string</i> from position <i>start</i> to position <i>k</i>
+ included.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Else the most significant bit in <i>B</i> is 1,
+ <ol class="block">
+ <li>Let <i>n</i> be the smallest nonnegative integer such that (<i>B</i> << <i>n</i>) & 0x80 is
+ equal to 0.</li>
+ <li>If <i>n</i> equals 1 or <i>n</i> is greater than 4, throw a <b><a
+ href="#sec-constructor-properties-of-the-global-object-urierror">URIError</a></b> exception.</li>
+ <li>Let <i>Octets</i> be an array of 8-bit integers of size <i>n</i>.</li>
+ <li>Put <i>B</i> into <i>Octets</i> at position 0.</li>
+ <li>If <i>k</i> + (3 × (<i>n</i> – 1)) is greater than or equal to <i>strLen</i>, throw a
+ <b><a href="#sec-constructor-properties-of-the-global-object-urierror">URIError</a></b>
+ exception.</li>
+ <li>Let <i>j</i> be 1.</li>
+ <li>Repeat, while <i>j</i> < <i>n</i>
+ <ol class="block">
+ <li>Increment <i>k</i> by 1.</li>
+ <li>If the character at position <i>k</i> within <i>string</i> is not <code>"%″</code>, throw a
+ <b><a href="#sec-constructor-properties-of-the-global-object-urierror">URIError</a></b>
+ exception.</li>
+ <li>If the characters at position (<i>k</i> +1) and (<i>k</i> + 2) within <i>string</i> do not
+ represent hexadecimal digits, throw a <b><a
+ href="#sec-constructor-properties-of-the-global-object-urierror">URIError</a></b> exception.</li>
+ <li>Let <i>B</i> be the 8-bit value represented by the two hexadecimal digits at position (<i>k</i> +
+ 1) and (<i>k</i> + 2).</li>
+ <li>If the two most significant bits in <i>B</i> are not 10, throw a <b><a
+ href="#sec-constructor-properties-of-the-global-object-urierror">URIError</a></b> exception.</li>
+ <li>Increment <i>k</i> by 2.</li>
+ <li>Put <i>B</i> into <i>Octets</i> at position <i>j</i>.</li>
+ <li>Increment <i>j</i> by 1.</li>
+ </ol>
+ </li>
+ <li>Let <i>V</i> be the value obtained by applying the UTF-8 transformation to <i>Octets</i>, that is,
+ from an array of octets into a 21-bit value. If <i>Octets</i> does not contain a valid UTF-8 encoding
+ of a Unicode code point throw a <b><a
+ href="#sec-constructor-properties-of-the-global-object-urierror">URIError</a></b> exception.</li>
+ <li>If <i>V</i> < 0x10000, then
+ <ol class="block">
+ <li>Let <i>C</i> be the character with code unit value <i>V</i>.</li>
+ <li>If <i>C</i> is not in <i>reservedSet</i>, then
+ <ol class="block">
+ <li>Let <i>S</i> be the String containing only the character <i>C</i>.</li>
+ </ol>
+ </li>
+ <li>Else <i>C</i> is in <i>reservedSet</i>,
+ <ol class="block">
+ <li>Let <i>S</i> be the substring of <i>string</i> from position <i>start</i> to position <i>k</i>
+ included.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Else <i>V</i> ≥ 0x10000,
+ <ol class="block">
+ <li>Let <i>L</i> be (((<i>V</i> – 0x10000) & 0x3FF) + 0xDC00).</li>
+ <li>Let <i>H</i> be ((((<i>V</i> – 0x10000) >> 10) & 0x3FF) + 0xD800).</li>
+ <li>Let <i>S</i> be the String containing the two characters with code unit values <i>H</i> and
+ <i>L</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Let <i>R</i> be a new String value computed by concatenating the previous value of <i>R</i> and <i>S</i>.</li>
+ <li>Increase <i>k</i> by 1.</li>
+ </ol>
+ </li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> This syntax of Uniform Resource Identifiers is based upon RFC 2396 and does not
+ reflect the more recent RFC 3986 which replaces RFC 2396. A formal description and implementation of UTF-8 is given
+ in RFC 3629.</p>
+ </div>
+
+ <p>In UTF-8, characters are encoded using sequences of 1 to 6 octets. The only octet of a "sequence" of one has the
+ higher-order bit set to 0, the remaining 7 bits being used to encode the character value. In a sequence of n octets,
+ n>1, the initial octet has the n higher-order bits set to 1, followed by a bit set to 0. The remaining bits of that
+ octet contain bits from the value of the character to be encoded. The following octets all have the higher-order bit set
+ to 1 and the following bit set to 0, leaving 6 bits in each to contain bits from the character to be encoded. The
+ possible UTF-8 encodings of ECMAScript characters are specified in <a href="#table-38">Table 38</a>.</p>
+
+ <figure>
+ <figcaption><span id="table-38">Table 38</span> — UTF-8 Encodings</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 0px solid black; border-left: 0px solid black; border-top: 0px solid black">Code Unit Value</th>
+ <th style="border-bottom: 0px solid black; border-top: 0px solid black">Representation</th>
+ <th style="border-bottom: 0px solid black; border-top: 0px solid black">1<sup>st</sup> Octet</th>
+ <th style="border-bottom: 0px solid black; border-top: 0px solid black">2<sup>nd</sup> Octet</th>
+ <th style="border-bottom: 0px solid black; border-top: 0px solid black">3<sup>rd</sup> Octet</th>
+ <th style="border-bottom: 0px solid black; border-right: 0px solid black; border-top: 0px solid black">4<sup>th</sup> Octet</th>
+ </tr>
+ <tr>
+ <td><code>0x0000 - 0x007F</code></td>
+ <td><code>00000000</code> <code><b>0</b><i>zzzzzzz</i></code></td>
+ <td><code><b>0</b><i>zzzzzzz</i></code></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td><code>0x0080 - 0x07FF</code></td>
+ <td><code><b>00000</b><i>yyy yyzzzzzz</i></code></td>
+ <td><code><b>110</b><i>yyyyy</i></code></td>
+ <td><code><b>10</b><i>zzzzzz</i></code></td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td><code>0x0800 - 0xD7FF</code></td>
+ <td><span style="font-family: monospace"><i>xxxxyyyy yyzzzzzz</i></span></td>
+ <td><code><b>1110</b><i>xxxx</i></code></td>
+ <td><code><b>10</b><i>yyyyyy</i></code></td>
+ <td><code><b>10</b><i>zzzzzz</i></code></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>
+ <p><code>0xD800 - 0xDBFF</code></p>
+
+ <p><i>followed by</i></p>
+
+ <p><code>0xDC00 – 0xDFFF</code></p>
+ </td>
+
+ <td>
+ <p><code><b>110110</b><i>vv vvwwwwxx</i></code></p>
+
+ <p><i>followed by</i></p>
+
+ <p><code><b>110111</b><i>yy yyzzzzzz</i></code></p>
+ </td>
+
+ <td><code><b>11110</b><i>uuu</i></code></td>
+ <td><code><b>10</b><i>uuwwww</i></code></td>
+ <td><code><b>10</b><i>xxyyyy</i></code></td>
+ <td><code><b>10</b><i>zzzzzz</i></code></td>
+ </tr>
+ <tr>
+ <td>
+ <p><code>0xD800 - 0xDBFF</code></p>
+
+ <p><i>not followed by</i></p>
+
+ <p><code>0xDC00 – 0xDFFF</code></p>
+ </td>
+
+ <td><span style="font-family: sans-serif"><i>causes</i></span> <code><b><a href="#sec-constructor-properties-of-the-global-object-urierror">URIError</a></b></code></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td><code>0xDC00 – 0xDFFF</code></td>
+ <td><span style="font-family: sans-serif"><i>causes</i></span> <code><b><a href="#sec-constructor-properties-of-the-global-object-urierror">URIError</a></b></code></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td><code>0xE000 - 0xFFFF</code></td>
+ <td><span style="font-family: monospace"><i>xxxxyyyy yyzzzzzz</i></span></td>
+ <td><code><b>1110</b><i>xxxx</i></code></td>
+ <td><code><b>10</b><i>yyyyyy</i></code></td>
+ <td><code><b>10</b><i>zzzzzz</i></code></td>
+ <td></td>
+ </tr>
+ </table>
+ </figure>
+
+ <p>Where</p>
+
+ <p><i>uuuuu</i> = <span style="font-family: monospace"><i>vvvv</i></span> + 1</p>
+
+ <p>to account for the addition of 0x10000 as in Surrogates, section 3.7, of the Unicode Standard.</p>
+
+ <p>The range of code unit values 0xD800-0xDFFF is used to encode surrogate pairs; the above transformation combines a
+ UTF-16 surrogate pair into a UTF-32 representation and encodes the resulting 21-bit value in UTF-8. Decoding
+ reconstructs the surrogate pair.</p>
+
+ <p>RFC 3629 prohibits the decoding of invalid UTF-8 octet sequences. For example, the invalid sequence C0 80 must not
+ decode into the character U+0000. Implementations of the Decode algorithm are required to throw a <b><a
+ href="#sec-constructor-properties-of-the-global-object-urierror">URIError</a></b> when encountering such invalid
+ sequences.</p>
+ </section>
+ </section>
+
+ <section id="sec-decodeuri-encodeduri">
+ <h1><span class="secnum" id="sec-18.2.6.2"><a href="#sec-decodeuri-encodeduri"
+ title="link to this section">18.2.6.2</a></span> decodeURI (encodedURI)</h1>
+
+ <p>The <code>decodeURI</code> function computes a new version of a URI in which each escape sequence and UTF-8 encoding of
+ the sort that might be introduced by the <code>encodeURI</code> function is replaced with the character that it
+ represents. Escape sequences that could not have been introduced by <code>encodeURI</code> are not replaced.</p>
+
+ <p>When the <code>decodeURI</code> function is called with one argument <var>encodedURI</var>, the following steps are
+ taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>uriString</i> be <a href="#sec-tostring">ToString</a>(<i>encodedURI</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>uriString</i>).</li>
+ <li>Let <i>reservedURISet</i> be a String containing one instance of each character valid in <i>uriReserved</i> plus
+ “<code>#</code>”.</li>
+ <li>Return the result of calling <a href="#sec-decode">Decode</a>(<i>uriString</i>, <i>reservedURISet</i>)</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The character “<code>#</code>” is not decoded from escape sequences even
+ though it is not a reserved URI character.</p>
+ </div>
+ </section>
+
+ <section id="sec-decodeuricomponent-encodeduricomponent">
+ <h1><span class="secnum" id="sec-18.2.6.3"><a href="#sec-decodeuricomponent-encodeduricomponent"
+ title="link to this section">18.2.6.3</a></span> decodeURIComponent (encodedURIComponent)</h1>
+
+ <p>The <code>decodeURIComponent</code> function computes a new version of a URI in which each escape sequence and UTF-8
+ encoding of the sort that might be introduced by the <code>encodeURIComponent</code> function is replaced with the
+ character that it represents.</p>
+
+ <p>When the <code>decodeURIComponent</code> function is called with one argument <var>encodedURIComponent</var>, the
+ following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>componentString</i> be <a href="#sec-tostring">ToString</a>(<i>encodedURIComponent</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>componentString</i>).</li>
+ <li>Let <i>reservedURIComponentSet</i> be the empty String.</li>
+ <li>Return <a href="#sec-decode">Decode</a>(<i>componentString</i>, <i>reservedURIComponentSet</i>)</li>
+ </ol>
+ </section>
+
+ <section id="sec-encodeuri-uri">
+ <h1><span class="secnum" id="sec-18.2.6.4"><a href="#sec-encodeuri-uri" title="link to this section">18.2.6.4</a></span>
+ encodeURI (uri)</h1>
+
+ <p>The <code>encodeURI</code> function computes a new version of a URI in which each instance of certain characters is
+ replaced by one, two, three, or four escape sequences representing the UTF-8 encoding of the character.</p>
+
+ <p>When the <code>encodeURI</code> function is called with one argument <span class="nt">uri</span>, the following steps
+ are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>uriString</i> be <a href="#sec-tostring">ToString</a>(<i>uri</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>uriString</i>).</li>
+ <li>Let <i>unescapedURISet</i> be a String containing one instance of each character valid in <i>uriReserved</i> and
+ <i>uriUnescaped</i> plus "<code>#</code>".</li>
+ <li>Return <a href="#sec-encode">Encode</a>(<i>uriString</i>, <i>unescapedURISet</i>)</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The character <span style="font-family: sans-serif">"</span><code>#</code><span
+ style="font-family: sans-serif">"</span> is not encoded to an escape sequence even though it is not a reserved or
+ unescaped URI character.</p>
+ </div>
+ </section>
+
+ <section id="sec-encodeuricomponent-uricomponent">
+ <h1><span class="secnum" id="sec-18.2.6.5"><a href="#sec-encodeuricomponent-uricomponent"
+ title="link to this section">18.2.6.5</a></span> encodeURIComponent (uriComponent)</h1>
+
+ <p>The <code>encodeURIComponent</code> function computes a new version of a URI in which each instance of certain
+ characters is replaced by one, two, three, or four escape sequences representing the UTF-8 encoding of the character.</p>
+
+ <p>When the <code>encodeURIComponent</code> function is called with one argument <span class="nt">uriComponent</span>, the
+ following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>componentString</i> be <a href="#sec-tostring">ToString</a>(<i>uriComponent</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>componentString</i>).</li>
+ <li>Let <i>unescapedURIComponentSet</i> be a String containing one instance of each character valid in
+ <i>uriUnescaped</i>.</li>
+ <li>Return <a href="#sec-encode">Encode</a>(<i>componentString</i>, <i>unescapedURIComponentSet</i>)</li>
+ </ol>
+ </section>
+ </section>
+ </section>
+
+ <section id="sec-constructor-properties-of-the-global-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-18.3"><a href="#sec-constructor-properties-of-the-global-object"
+ title="link to this section">18.3</a></span> Constructor Properties of the Global Object</h1>
+ </div>
+
+ <section id="sec-constructor-properties-of-the-global-object-array">
+ <h1><span class="secnum" id="sec-18.3.1"><a href="#sec-constructor-properties-of-the-global-object-array"
+ title="link to this section">18.3.1</a></span> Array ( . . . )</h1>
+
+ <p>See <a href="#sec-array-constructor">22.1.1</a>.</p>
+ </section>
+
+ <section id="sec-constructor-properties-of-the-global-object-arraybuffer">
+ <h1><span class="secnum" id="sec-18.3.2"><a href="#sec-constructor-properties-of-the-global-object-arraybuffer"
+ title="link to this section">18.3.2</a></span> ArrayBuffer ( . . . )</h1>
+
+ <p>See <a href="#sec-arraybuffer-constructor">24.1.2</a>.</p>
+ </section>
+
+ <section id="sec-constructor-properties-of-the-global-object-boolean">
+ <h1><span class="secnum" id="sec-18.3.3"><a href="#sec-constructor-properties-of-the-global-object-boolean"
+ title="link to this section">18.3.3</a></span> Boolean ( . . . )</h1>
+
+ <p>See <a href="#sec-boolean-constructor">19.3.1</a>.</p>
+ </section>
+
+ <section id="sec-constructor-properties-of-the-global-object-dataview">
+ <h1><span class="secnum" id="sec-18.3.4"><a href="#sec-constructor-properties-of-the-global-object-dataview"
+ title="link to this section">18.3.4</a></span> DataView ( . . . )</h1>
+
+ <p>See <a href="#sec-dataview-constructor">24.2.2</a>.</p>
+ </section>
+
+ <section id="sec-constructor-properties-of-the-global-object-date">
+ <h1><span class="secnum" id="sec-18.3.5"><a href="#sec-constructor-properties-of-the-global-object-date"
+ title="link to this section">18.3.5</a></span> Date ( . . . )</h1>
+
+ <p>See <a href="#sec-date-constructor">20.3.2</a>.</p>
+ </section>
+
+ <section id="sec-constructor-properties-of-the-global-object-error">
+ <h1><span class="secnum" id="sec-18.3.6"><a href="#sec-constructor-properties-of-the-global-object-error"
+ title="link to this section">18.3.6</a></span> Error ( . . . )</h1>
+
+ <p>See <a href="#sec-error-constructor">19.5.1</a>.</p>
+ </section>
+
+ <section id="sec-constructor-properties-of-the-global-object-evalerror">
+ <h1><span class="secnum" id="sec-18.3.7"><a href="#sec-constructor-properties-of-the-global-object-evalerror"
+ title="link to this section">18.3.7</a></span> EvalError ( . . . )</h1>
+
+ <p>See <a href="#sec-native-error-types-used-in-this-standard-evalerror">19.5.5.1</a>.</p>
+ </section>
+
+ <section id="sec-float32array">
+ <h1><span class="secnum" id="sec-18.3.8"><a href="#sec-float32array" title="link to this section">18.3.8</a></span>
+ Float32Array ( . . . )</h1>
+
+ <p>See <a href="#sec-typedarray-constructors">22.2.4</a>.</p>
+ </section>
+
+ <section id="sec-float64array">
+ <h1><span class="secnum" id="sec-18.3.9"><a href="#sec-float64array" title="link to this section">18.3.9</a></span>
+ Float64Array ( . . . )</h1>
+
+ <p>See <a href="#sec-typedarray-constructors">22.2.4</a>.</p>
+ </section>
+
+ <section id="sec-constructor-properties-of-the-global-object-function">
+ <h1><span class="secnum" id="sec-18.3.10"><a href="#sec-constructor-properties-of-the-global-object-function"
+ title="link to this section">18.3.10</a></span> Function ( . . . )</h1>
+
+ <p>See <a href="#sec-function-constructor">19.2.1</a>.</p>
+ </section>
+
+ <section id="sec-int8array">
+ <h1><span class="secnum" id="sec-18.3.11"><a href="#sec-int8array" title="link to this section">18.3.11</a></span> Int8Array
+ ( . . . )</h1>
+
+ <p>See <a href="#sec-typedarray-constructors">22.2.4</a>.</p>
+ </section>
+
+ <section id="sec-int16array">
+ <h1><span class="secnum" id="sec-18.3.12"><a href="#sec-int16array" title="link to this section">18.3.12</a></span>
+ Int16Array ( . . . )</h1>
+
+ <p>See <a href="#sec-typedarray-constructors">22.2.4</a>.</p>
+ </section>
+
+ <section id="sec-int32array">
+ <h1><span class="secnum" id="sec-18.3.13"><a href="#sec-int32array" title="link to this section">18.3.13</a></span>
+ Int32Array ( . . . )</h1>
+
+ <p>See <a href="#sec-typedarray-constructors">22.2.4</a>.</p>
+ </section>
+
+ <section id="sec-map">
+ <h1><span class="secnum" id="sec-18.3.14"><a href="#sec-map" title="link to this section">18.3.14</a></span> Map ( . . .
+ )</h1>
+
+ <p>See <a href="#sec-map-constructor">23.1.1</a>.</p>
+ </section>
+
+ <section id="sec-constructor-properties-of-the-global-object-number">
+ <h1><span class="secnum" id="sec-18.3.15"><a href="#sec-constructor-properties-of-the-global-object-number"
+ title="link to this section">18.3.15</a></span> Number ( . . . )</h1>
+
+ <p>See <a href="#sec-number-constructor">20.1.1</a>.</p>
+ </section>
+
+ <section id="sec-constructor-properties-of-the-global-object-object">
+ <h1><span class="secnum" id="sec-18.3.16"><a href="#sec-constructor-properties-of-the-global-object-object"
+ title="link to this section">18.3.16</a></span> Object ( . . . )</h1>
+
+ <p>See <a href="#sec-object-constructor">19.1.1</a>.</p>
+ </section>
+
+ <section id="sec-constructor-properties-of-the-global-object-rangeerror">
+ <h1><span class="secnum" id="sec-18.3.17"><a href="#sec-constructor-properties-of-the-global-object-rangeerror"
+ title="link to this section">18.3.17</a></span> RangeError ( . . . )</h1>
+
+ <p>See <a href="#sec-native-error-types-used-in-this-standard-rangeerror">19.5.5.2</a>.</p>
+ </section>
+
+ <section id="sec-constructor-properties-of-the-global-object-referenceerror">
+ <h1><span class="secnum" id="sec-18.3.18"><a href="#sec-constructor-properties-of-the-global-object-referenceerror"
+ title="link to this section">18.3.18</a></span> ReferenceError ( . . . )</h1>
+
+ <p>See <a href="#sec-native-error-types-used-in-this-standard-referenceerror">19.5.5.3</a>.</p>
+ </section>
+
+ <section id="sec-constructor-properties-of-the-global-object-regexp">
+ <h1><span class="secnum" id="sec-18.3.19"><a href="#sec-constructor-properties-of-the-global-object-regexp"
+ title="link to this section">18.3.19</a></span> RegExp ( . . . )</h1>
+
+ <p>See <a href="#sec-properties-of-the-regexp-constructor">21.2.4</a>.</p>
+ </section>
+
+ <section id="sec-set">
+ <h1><span class="secnum" id="sec-18.3.20"><a href="#sec-set" title="link to this section">18.3.20</a></span> Set ( . . .
+ )</h1>
+
+ <p>See <a href="#sec-set-constructor">23.2.1</a>.</p>
+ </section>
+
+ <section id="sec-constructor-properties-of-the-global-object-string">
+ <h1><span class="secnum" id="sec-18.3.21"><a href="#sec-constructor-properties-of-the-global-object-string"
+ title="link to this section">18.3.21</a></span> String ( . . . )</h1>
+
+ <p>See <a href="#sec-string-constructor">21.1.1</a>.</p>
+ </section>
+
+ <section id="sec-constructor-properties-of-the-global-object-symbol">
+ <h1><span class="secnum" id="sec-18.3.22"><a href="#sec-constructor-properties-of-the-global-object-symbol"
+ title="link to this section">18.3.22</a></span> Symbol ( . . . )</h1>
+
+ <p>See <a href="#sec-symbol-constructor">19.4.1</a>.</p>
+ </section>
+
+ <section id="sec-constructor-properties-of-the-global-object-syntaxerror">
+ <h1><span class="secnum" id="sec-18.3.23"><a href="#sec-constructor-properties-of-the-global-object-syntaxerror"
+ title="link to this section">18.3.23</a></span> SyntaxError ( . . . )</h1>
+
+ <p>See <a href="#sec-native-error-types-used-in-this-standard-syntaxerror">19.5.5.4</a>.</p>
+ </section>
+
+ <section id="sec-constructor-properties-of-the-global-object-typeerror">
+ <h1><span class="secnum" id="sec-18.3.24"><a href="#sec-constructor-properties-of-the-global-object-typeerror"
+ title="link to this section">18.3.24</a></span> TypeError ( . . . )</h1>
+
+ <p>See <a href="#sec-native-error-types-used-in-this-standard-typeerror">19.5.5.5</a>.</p>
+ </section>
+
+ <section id="sec-uint8array">
+ <h1><span class="secnum" id="sec-18.3.25"><a href="#sec-uint8array" title="link to this section">18.3.25</a></span>
+ Uint8Array ( . . . )</h1>
+
+ <p>See <a href="#sec-typedarray-constructors">22.2.4</a>.</p>
+ </section>
+
+ <section id="sec-uint8clampedarray">
+ <h1><span class="secnum" id="sec-18.3.26"><a href="#sec-uint8clampedarray" title="link to this section">18.3.26</a></span>
+ Uint8ClampedArray ( . . . )</h1>
+
+ <p>See <a href="#sec-typedarray-constructors">22.2.4</a>.</p>
+ </section>
+
+ <section id="sec-uint16array">
+ <h1><span class="secnum" id="sec-18.3.27"><a href="#sec-uint16array" title="link to this section">18.3.27</a></span>
+ Uint16Array ( . . . )</h1>
+
+ <p>See <a href="#sec-typedarray-constructors">22.2.4</a>.</p>
+ </section>
+
+ <section id="sec-uint32array">
+ <h1><span class="secnum" id="sec-18.3.28"><a href="#sec-uint32array" title="link to this section">18.3.28</a></span>
+ Uint32Array ( . . . )</h1>
+
+ <p>See <a href="#sec-typedarray-constructors">22.2.4</a>.</p>
+ </section>
+
+ <section id="sec-constructor-properties-of-the-global-object-urierror">
+ <h1><span class="secnum" id="sec-18.3.29"><a href="#sec-constructor-properties-of-the-global-object-urierror"
+ title="link to this section">18.3.29</a></span> URIError ( . . . )</h1>
+
+ <p>See <a href="#sec-native-error-types-used-in-this-standard-urierror">19.5.5.6</a>.</p>
+ </section>
+
+ <section id="sec-constructor-properties-of-the-global-object-weakmap">
+ <h1><span class="secnum" id="sec-18.3.30"><a href="#sec-constructor-properties-of-the-global-object-weakmap"
+ title="link to this section">18.3.30</a></span> WeakMap ( . . . )</h1>
+
+ <p>See <a href="#sec-weakmap-constructor">23.3.1</a>.</p>
+ </section>
+
+ <section id="sec-constructor-properties-of-the-global-object-weakset">
+ <h1><span class="secnum" id="sec-18.3.31"><a href="#sec-constructor-properties-of-the-global-object-weakset"
+ title="link to this section">18.3.31</a></span> WeakSet ( . . . )</h1>
+
+ <p>See <a href="#sec-weakset-objects">23.4</a>.</p>
+ </section>
+ </section>
+
+ <section id="sec-other-properties-of-the-global-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-18.4"><a href="#sec-other-properties-of-the-global-object"
+ title="link to this section">18.4</a></span> Other Properties of the Global Object</h1>
+ </div>
+
+ <section id="sec-json">
+ <h1><span class="secnum" id="sec-18.4.1"><a href="#sec-json" title="link to this section">18.4.1</a></span> JSON</h1>
+
+ <p>See <a href="#sec-json-object">24.3</a>.</p>
+ </section>
+
+ <section id="sec-math">
+ <h1><span class="secnum" id="sec-18.4.2"><a href="#sec-math" title="link to this section">18.4.2</a></span> Math</h1>
+
+ <p>See <a href="#sec-math-object">20.2</a>.</p>
+ </section>
+
+ <section id="sec-other-properties-of-the-global-object-proxy">
+ <h1><span class="secnum" id="sec-18.4.3"><a href="#sec-other-properties-of-the-global-object-proxy"
+ title="link to this section">18.4.3</a></span> Proxy ( . . . )</h1>
+
+ <p>See <a href="#sec-proxy-constructor-function">26.5.1</a>.</p>
+ </section>
+
+ <section id="sec-reflect">
+ <h1><span class="secnum" id="sec-18.4.4"><a href="#sec-reflect" title="link to this section">18.4.4</a></span> Reflect</h1>
+
+ <p>See <a href="#sec-reflect-object">26.1</a>.</p>
+ </section>
+
+ <section id="sec-system">
+ <h1><span class="secnum" id="sec-18.4.5"><a href="#sec-system" title="link to this section">18.4.5</a></span> System</h1>
+
+ <p>See <a href="#sec-system-object">26.4</a>.</p>
+ </section>
+ </section>
+</section>
+
+<section id="sec-fundamental-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-19"><a href="#sec-fundamental-objects" title="link to this section">19</a></span> Fundamental
+ Objects</h1>
+ </div>
+
+ <section id="sec-object-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-19.1"><a href="#sec-object-objects" title="link to this section">19.1</a></span> Object
+ Objects</h1>
+ </div>
+
+ <section id="sec-object-constructor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-19.1.1"><a href="#sec-object-constructor" title="link to this section">19.1.1</a></span>
+ The Object Constructor</h1>
+
+ <p>The Object constructor is the %Object% intrinsic object and the initial value of the <code>Object</code> property of
+ the global object. When <code>Object</code> is called as a function rather than as a constructor, it performs a type
+ conversion.</p>
+
+ <p>The <code>Object</code> constructor is designed to be subclassable. It may be used as the value of an
+ <code>extends</code> clause of a class declaration.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Subclass constructors that inherit from the Object constructor typically should not
+ include a <code>super</code> call to <code>Object</code> as it performs no initialization action on its
+ <code>this</code> value and does not return its <code>this</code> value as its value.</p>
+ </div>
+ </div>
+
+ <section id="sec-object-value">
+ <h1><span class="secnum" id="sec-19.1.1.1"><a href="#sec-object-value" title="link to this section">19.1.1.1</a></span>
+ Object ( [ value ] )</h1>
+
+ <p>When <code>Object</code> function is called with optional argument <var>value</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>If <i>value</i> is <b>null</b>, <b>undefined</b> or not supplied, return <a
+ href="#sec-objectcreate">ObjectCreate</a>(%ObjectPrototype%).</li>
+ <li>Return <a href="#sec-toobject">ToObject</a>(<i>value</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-new-object-argumentslist">
+ <h1><span class="secnum" id="sec-19.1.1.2"><a href="#sec-new-object-argumentslist"
+ title="link to this section">19.1.1.2</a></span> new Object ( ...argumentsList )</h1>
+
+ <p>When <code>Object</code> is called as part of a new expression , it creates a new object:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be the <code>Object</code> function object on which the <code>new</code> operator was applied.</li>
+ <li>Let <i>argumentsList</i> be the <i>argumentsList</i> argument of the [[Construct]] internal method that was invoked
+ by the <code>new</code> operator.</li>
+ <li>Return the result of calling the [[Call]] internal method of <i>F</i>, providing <b>undefined</b> and
+ <i>argumentsList</i> as the arguments.</li>
+ </ol>
+
+ <p>The above steps defined the [[Construct]] internal method of the Object constructor. Object may not be implemented as
+ an <a href="#sec-ecmascript-function-objects">ECMAScript function object</a> because this definition differs from the
+ definition of [[Construct]] used by ECMAScript function objects.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-object-constructor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-19.1.2"><a href="#sec-properties-of-the-object-constructor"
+ title="link to this section">19.1.2</a></span> Properties of the Object Constructor</h1>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the
+ Object constructor is the standard built-in Function prototype object.</p>
+
+ <p>Besides the <code>length</code> property (whose value is <b>1</b>), the Object constructor has the following
+ properties:</p>
+ </div>
+
+ <section id="sec-object.assign">
+ <h1><span class="secnum" id="sec-19.1.2.1"><a href="#sec-object.assign" title="link to this section">19.1.2.1</a></span>
+ Object.assign ( target, ...sources )</h1>
+
+ <p>The <b>assign</b> function is used to copy the values of all of the enumerable own properties from one or more source
+ objects to a <var>target</var> object. When the <b>assign</b> function is called, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>to</i> be <a href="#sec-toobject">ToObject</a>(<i>target</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>to</i>).</li>
+ <li>If fewer than two arguments were passed, then return <i>to</i>.</li>
+ <li>Let <i>sources</i> be the <a href="#sec-list-and-record-specification-type">List</a> of argument vales starting with
+ the second argument.</li>
+ <li>For each element <i>nextSource</i> of <i>sources</i>, in ascending index order,
+ <ol class="block">
+ <li>Let <i>from</i> be <a href="#sec-toobject">ToObject</a>(<i>nextSource</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>from</i>).</li>
+ <li>Let <i>keysArray</i> be the result of calling the [[OwnPropertyKeys]] internal method of <i>nextSource</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>keysArray</i>).</li>
+ <li>Let <i>lenValue</i> be <a href="#sec-get-o-p">Get</a>(<i>keysArray</i>, <code>"length"</code>).</li>
+ <li>Let <i>len</i> be <a href="#sec-tolength">ToLength</a>(<i>lenValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>len</i>).</li>
+ <li>Let <i>nextIndex</i> be 0.</li>
+ <li>Let <i>pendingException</i> be <b>undefined</b>.</li>
+ <li>Repeat while <i>nextIndex</i> <i>< len</i>,
+ <ol class="block">
+ <li>Let <i>nextKey</i> be <a href="#sec-get-o-p">Get</a>(<i>keysArray</i>, <a
+ href="#sec-tostring">ToString</a>(<i>nextIndex</i>)).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>nextKey</i>).</li>
+ <li>Let <i>desc</i> be the result of calling the [[GetOwnProperty]] internal method of <i>from</i> with argument
+ <i>nextKey</i>.</li>
+ <li>If <i>desc</i> is an <a href="#sec-completion-record-specification-type">abrupt completion</a>, then
+ <ol class="block">
+ <li>If <i>pendingException</i> is <b>undefined</b>, then set <i>pendingException</i> to <i>desc</i>.</li>
+ </ol>
+ </li>
+ <li>Else if <i>desc</i> is not <b>undefined</b> and <i>desc</i>.[[Enumerable]] is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>propValue</i> be <a href="#sec-get-o-p">Get</a>(<i>from</i>, <i>nextKey</i>).</li>
+ <li>If <i>propValue</i> is an <a href="#sec-completion-record-specification-type">abrupt completion</a>,
+ then
+ <ol class="block">
+ <li>If <i>pendingException</i> is <b>undefined</b>, then set <i>pendingException</i> to
+ <i>propValue</i>.</li>
+ </ol>
+ </li>
+ <li>else
+ <ol class="block">
+ <li>Let <i>status</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>to</i>, <i>nextKey</i>,
+ <i>propValue</i>, <b>true</b>);</li>
+ <li>If <i>status</i> is an <a href="#sec-completion-record-specification-type">abrupt completion</a>,
+ then
+ <ol class="block">
+ <li>If <i>pendingException</i> is <b>undefined</b>, then set <i>pendingException</i> to
+ <i>status</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Increment <i>nextIndex</i> by 1.</li>
+ </ol>
+ </li>
+ <li>If <i>pendingException</i> is not <b>undefined</b>, then return <i>pendingException</i>.</li>
+ </ol>
+ </li>
+ <li>Return <i>to</i>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>assign</code> method is <b>2</b>.</p>
+ </section>
+
+ <section id="sec-object.create">
+ <h1><span class="secnum" id="sec-19.1.2.2"><a href="#sec-object.create" title="link to this section">19.1.2.2</a></span>
+ Object.create ( O [ , Properties ] )</h1>
+
+ <p>The <b>create</b> function creates a new object with a specified prototype. When the <b>create</b> function is called,
+ the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object or Null throw a <b>TypeError</b>
+ exception.</li>
+ <li>Let <i>obj</i> be <a href="#sec-objectcreate">ObjectCreate</a>(<i>O</i>).</li>
+ <li>If the argument <i>Properties</i> is present and not <b>undefined</b>, then
+ <ol class="block">
+ <li>Return the result of the abstract operation <a
+ href="#sec-objectdefineproperties">ObjectDefineProperties</a>(<i>obj</i>, <i>Properties</i>).</li>
+ </ol>
+ </li>
+ <li>Return <i>obj</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-object.defineproperties">
+ <div class="front">
+ <h1><span class="secnum" id="sec-19.1.2.3"><a href="#sec-object.defineproperties"
+ title="link to this section">19.1.2.3</a></span> Object.defineProperties ( O, Properties )</h1>
+
+ <p>The <b>defineProperties</b> function is used to add own properties and/or update the attributes of existing own
+ properties of an object. When the <b>defineProperties</b> function is called, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Return the result of the abstract operation <a href="#sec-objectdefineproperties">ObjectDefineProperties</a> with
+ arguments <i>O</i> and <i>Properties</i>.</li>
+ </ol>
+ </div>
+
+ <section id="sec-objectdefineproperties">
+ <h1><span class="secnum" id="sec-19.1.2.3.1"><a href="#sec-objectdefineproperties"
+ title="link to this section">19.1.2.3.1</a></span> Runtime Semantics: ObjectDefineProperties Abstract Operation</h1>
+
+ <p>The abstract operation ObjectDefineProperties with arguments <i>O</i> and <i>Properties</i> performs the following
+ steps:</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object throw a <b>TypeError</b>
+ exception.</li>
+ <li>Let <i>props</i> be <a href="#sec-toobject">ToObject</a>(<i>Properties</i>).</li>
+ <li>Let <i>names</i> be a <a href="#sec-list-and-record-specification-type">List</a> containing the keys of each
+ enumerable own property of <i>props.</i></li>
+ <li>Let <i>descriptors</i> be an empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>For each element <i>P</i> of <i>names</i> in list order,
+ <ol class="block">
+ <li>Let <i>descObj</i> be the result of <a href="#sec-get-o-p">Get</a>( <i>props</i>, <i>P</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>descObj</i>).</li>
+ <li>Let <i>desc</i> be the result of calling <a href="#sec-topropertydescriptor">ToPropertyDescriptor</a> with
+ <i>descObj</i> as the argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>desc</i>).</li>
+ <li>Append the pair (a two element <a href="#sec-list-and-record-specification-type">List</a>) consisting of
+ <i>P</i> and <i>desc</i> to the end of <i>descriptors</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>pendingException</i> be <b>undefined</b>.</li>
+ <li>For each <i>pair</i> from <i>descriptors</i> in list order,
+ <ol class="block">
+ <li>Let <i>P</i> be the first element of <i>pair</i>.</li>
+ <li>Let <i>desc</i> be the second element of <i>pair</i>.</li>
+ <li>Let <i>status</i> be the result of <a
+ href="#sec-definepropertyorthrow">DefinePropertyOrThrow</a>(<i>O</i>,<i>P</i>, <i>desc</i>).</li>
+ <li>If <i>status</i> is an <a href="#sec-completion-record-specification-type">abrupt completion</a> then,
+ <ol class="block">
+ <li>If <i>pendingException</i> is <b>undefined</b>, then set <i>pendingException</i> to <i>status</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>pendingException</i>).</li>
+ <li>Return <i>O</i>.</li>
+ </ol>
+
+ <p>If an implementation defines a specific order of enumeration for the for-in statement, that same enumeration order
+ must be used to order the list elements in step 3 of this algorithm.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> An exception in defining an individual property in step 7 does not terminate the
+ process of defining other properties. All valid property definitions are processed.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-object.defineproperty">
+ <h1><span class="secnum" id="sec-19.1.2.4"><a href="#sec-object.defineproperty"
+ title="link to this section">19.1.2.4</a></span> Object.defineProperty ( O, P, Attributes )</h1>
+
+ <p>The <b>defineProperty</b> function is used to add an own property and/or update the attributes of an existing own
+ property of an object. When the <b>defineProperty</b> function is called, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object throw a <b>TypeError</b>
+ exception.</li>
+ <li>Let <i>key</i> be <a href="#sec-topropertykey">ToPropertyKey</a>(<i>P</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>key</i>).</li>
+ <li>Let <i>desc</i> be the result of calling <a
+ href="#sec-topropertydescriptor">ToPropertyDescriptor</a>(<i>Attributes</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>desc</i>).</li>
+ <li>Let <i>success</i> be the result of <a href="#sec-definepropertyorthrow">DefinePropertyOrThrow</a>(<i>O,key</i>,
+ <i>desc</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>success</i>).</li>
+ <li>Return <i>O</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-object.freeze">
+ <h1><span class="secnum" id="sec-19.1.2.5"><a href="#sec-object.freeze" title="link to this section">19.1.2.5</a></span>
+ Object.freeze ( O )</h1>
+
+ <p>When the <b>freeze</b> function is called, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object, return <i>O</i>.</li>
+ <li>Let <i>status</i> be the result of <a href="#sec-setintegritylevel">SetIntegrityLevel</a>( <i>O</i>,
+ "<code>frozen</code>").</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>If <i>status</i> is <b>false</b>, throw a <b>TypeError</b> exception.</li>
+ <li>Return <i>O</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-object.getownpropertydescriptor">
+ <h1><span class="secnum" id="sec-19.1.2.6"><a href="#sec-object.getownpropertydescriptor"
+ title="link to this section">19.1.2.6</a></span> Object.getOwnPropertyDescriptor ( O, P )</h1>
+
+ <p>When the <code>getOwnPropertyDescriptor</code> function is called, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>obj</i> be <a href="#sec-toobject">ToObject</a>(<i>O</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>obj</i>).</li>
+ <li>Let <i>key</i> be <a href="#sec-topropertykey">ToPropertyKey</a>(<i>P</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>key</i>).</li>
+ <li>Let <i>desc</i> be the result of calling the [[GetOwnProperty]] internal method of <i>obj</i> with argument
+ <i>key</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>desc</i>).</li>
+ <li>Return the result of calling <a href="#sec-frompropertydescriptor">FromPropertyDescriptor</a>(<i>desc</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-object.getownpropertynames">
+ <h1><span class="secnum" id="sec-19.1.2.7"><a href="#sec-object.getownpropertynames"
+ title="link to this section">19.1.2.7</a></span> Object.getOwnPropertyNames ( O )</h1>
+
+ <p>When the <b>getOwnPropertyNames</b> function is called, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Return <a href="#sec-getownpropertykeys">GetOwnPropertyKeys</a>(<i>O</i>, String).</li>
+ </ol>
+ </section>
+
+ <section id="sec-object.getownpropertysymbols">
+ <div class="front">
+ <h1><span class="secnum" id="sec-19.1.2.8"><a href="#sec-object.getownpropertysymbols"
+ title="link to this section">19.1.2.8</a></span> Object.getOwnPropertySymbols ( O )</h1>
+
+ <p>When the <b>getOwnPropertySymbols</b> function is called with argument <var>O</var>, the following steps are
+ taken:</p>
+
+ <ol class="proc">
+ <li>Return <a href="#sec-getownpropertykeys">GetOwnPropertyKeys</a>(<i>O</i>, Symbol).</li>
+ </ol>
+ </div>
+
+ <section id="sec-getownpropertykeys">
+ <h1><span class="secnum" id="sec-19.1.2.8.1"><a href="#sec-getownpropertykeys"
+ title="link to this section">19.1.2.8.1</a></span> GetOwnPropertyKeys ( O, Type ) Abstract Operation</h1>
+
+ <p>The abstract operation GetOwnPropertyKeys is called with arguments <var>O</var> and <span class="nt">Type</span>
+ where <var>O</var> is an Object and <span class="nt">Type</span> is one of the ECMAScript specification types String or
+ Symbol. The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>obj</i> be <a href="#sec-toobject">ToObject</a>(<i>O</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>obj</i>).</li>
+ <li>Let <i>keysArray</i> be the result of calling the [[OwnPropertyKeys]] internal method of <i>obj</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>keysArray</i>).</li>
+ <li>Let <i>lenValue</i> be <a href="#sec-get-o-p">Get</a>(<i>keysArray</i>, <code>"length"</code>).</li>
+ <li>Let <i>len</i> be <a href="#sec-tolength">ToLength</a>(<i>lenValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>len</i>).</li>
+ <li>Let <i>nextIndex</i> be 0.</li>
+ <li>Let <i>nameList</i> be a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Repeat while <i>nextIndex</i> <i>< len</i>,
+ <ol class="block">
+ <li>Let <i>nextKey</i> be <a href="#sec-get-o-p">Get</a>(<i>keysArray</i>, <a
+ href="#sec-tostring">ToString</a>(<i>nextIndex</i>)).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>nextKey</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>nextKey</i>) is <i>Type</i>, then
+ <ol class="block">
+ <li>Append <i>nextKey</i> as the last element of <i>nameList</i>.</li>
+ </ol>
+ </li>
+ <li>Increment <i>nextIndex</i> by 1.</li>
+ </ol>
+ </li>
+ <li>Return <a href="#sec-createarrayfromlist">CreateArrayFromList</a>(<i>nameList</i>).</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-object.getprototypeof">
+ <h1><span class="secnum" id="sec-19.1.2.9"><a href="#sec-object.getprototypeof"
+ title="link to this section">19.1.2.9</a></span> Object.getPrototypeOf ( O )</h1>
+
+ <p>When the <code>getPrototypeOf</code> function is called with argument <var>O</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>obj</i> be <a href="#sec-toobject">ToObject</a>(<i>O</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>obj</i>).</li>
+ <li>Return the result of calling the [[GetPrototypeOf]] internal method of <i>obj</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-object.is">
+ <h1><span class="secnum" id="sec-19.1.2.10"><a href="#sec-object.is" title="link to this section">19.1.2.10</a></span>
+ Object.is ( value1, value2 )</h1>
+
+ <p>When the <b>is</b> function is called with arguments <var>value1</var> and <var>value2</var> the following steps are
+ taken:</p>
+
+ <ol class="proc">
+ <li>Return <a href="#sec-samevalue">SameValue</a>(<i>value1</i>, <i>value2</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-object.isextensible">
+ <h1><span class="secnum" id="sec-19.1.2.11"><a href="#sec-object.isextensible"
+ title="link to this section">19.1.2.11</a></span> Object.isExtensible ( O )</h1>
+
+ <p>When the <b>isExtensible</b> function is called with argument <var>O</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object, return <b>false</b>.</li>
+ <li>Return the result of <a href="#sec-isextensible-o">IsExtensible</a>(<i>O</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-object.isfrozen">
+ <h1><span class="secnum" id="sec-19.1.2.12"><a href="#sec-object.isfrozen"
+ title="link to this section">19.1.2.12</a></span> Object.isFrozen ( O )</h1>
+
+ <p>When the <b>isFrozen</b> function is called with argument <var>O</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object, return <b>true</b>.</li>
+ <li>Return <a href="#sec-testintegritylevel">TestIntegrityLevel</a>(<i>O</i>, "<code>frozen</code>").</li>
+ </ol>
+ </section>
+
+ <section id="sec-object.issealed">
+ <h1><span class="secnum" id="sec-19.1.2.13"><a href="#sec-object.issealed"
+ title="link to this section">19.1.2.13</a></span> Object.isSealed ( O )</h1>
+
+ <p>When the <b>isSealed</b> function is called with argument <var>O</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object, return <b>true</b>.</li>
+ <li>Return <a href="#sec-testintegritylevel">TestIntegrityLevel</a>(<i>O</i>, "<code>sealed</code>").</li>
+ </ol>
+ </section>
+
+ <section id="sec-object.keys">
+ <h1><span class="secnum" id="sec-19.1.2.14"><a href="#sec-object.keys" title="link to this section">19.1.2.14</a></span>
+ Object.keys ( O )</h1>
+
+ <p>When the <b>keys</b> function is called with argument <var>O</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>obj</i> be <a href="#sec-toobject">ToObject</a>(<i>O</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>obj</i>).</li>
+ <li>Let <i>keysArray</i> be the result of calling the [[OwnPropertyKeys]] internal method of <i>obj</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>keysArray</i>).</li>
+ <li>Let <i>lenValue</i> be <a href="#sec-get-o-p">Get</a>(<i>keysArray</i>, <code>"length"</code>).</li>
+ <li>Let <i>len</i> be <a href="#sec-tolength">ToLength</a>(<i>lenValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>len</i>).</li>
+ <li>Let <i>nextIndex</i> be 0.</li>
+ <li>Let <i>nameList</i> be a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Repeat while <i>nextIndex</i> <i>< len</i>,
+ <ol class="block">
+ <li>Let <i>nextKey</i> be <a href="#sec-get-o-p">Get</a>(<i>keysArray</i>, <a
+ href="#sec-tostring">ToString</a>(<i>nextIndex</i>)).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>nextKey</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>nextKey</i>) is String, then
+ <ol class="block">
+ <li>Let <i>desc</i> be the result of calling the [[GetOwnProperty]] internal method of <i>O</i> with argument
+ <i>nextKey</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>desc</i>).</li>
+ <li>If <i>desc</i> is not <b>undefined</b> and <i>desc</i>.[[Enumerable]] is <b>true</b>, then
+ <ol class="block">
+ <li>Append <i>nextKey</i> as the last element of <i>nameList</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Increment <i>nextIndex</i> by 1.</li>
+ </ol>
+ </li>
+ <li>Return <a href="#sec-createarrayfromlist">CreateArrayFromList</a>(<i>nameList</i>).</li>
+ </ol>
+
+ <p>If an implementation defines a specific order of enumeration for the for-in statement, the same order must be used for
+ the elements of the array returned in step 11.</p>
+ </section>
+
+ <section id="sec-object.preventextensions">
+ <h1><span class="secnum" id="sec-19.1.2.15"><a href="#sec-object.preventextensions"
+ title="link to this section">19.1.2.15</a></span> Object.preventExtensions ( O )</h1>
+
+ <p>When the <b>preventExtensions</b> function is called, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object, return <i>O</i>.</li>
+ <li>Let <i>status</i> be the result of calling the [[PreventExtensions]] internal method of <i>O</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>If <i>status</i> is <b>false</b>, throw a <b>TypeError</b> exception.</li>
+ <li>Return <i>O</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-object.prototype">
+ <h1><span class="secnum" id="sec-19.1.2.16"><a href="#sec-object.prototype"
+ title="link to this section">19.1.2.16</a></span> Object.prototype</h1>
+
+ <p>The initial value of <code>Object.prototype</code> is the standard built-in Object prototype object (<a
+ href="#sec-properties-of-the-object-prototype-object">19.1.3</a>).</p>
+
+ <p>This property has the attributes {[[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-object.seal">
+ <h1><span class="secnum" id="sec-19.1.2.17"><a href="#sec-object.seal" title="link to this section">19.1.2.17</a></span>
+ Object.seal ( O )</h1>
+
+ <p>When the <b>seal</b> function is called, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object, return <i>O</i>.</li>
+ <li>Let <i>status</i> be the result of <a href="#sec-setintegritylevel">SetIntegrityLevel</a>( <i>O</i>,
+ "<code>sealed</code>").</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>If <i>status</i> is <b>false</b>, throw a <b>TypeError</b> exception.</li>
+ <li>Return <i>O</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-object.setprototypeof">
+ <h1><span class="secnum" id="sec-19.1.2.18"><a href="#sec-object.setprototypeof"
+ title="link to this section">19.1.2.18</a></span> Object.setPrototypeOf ( O, proto )</h1>
+
+ <p>When the <code>setPrototypeOf</code> function is called with arguments <span style="font-family: Times New
+ Roman"><i>O</i> and</span> proto, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be <a href="#sec-checkobjectcoercible">CheckObjectCoercible</a>(<i>O</i>)<i>.</i></li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>O</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>proto</i>) is neither Object nor Null, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object, then return <i>O</i>.</li>
+ <li>Let <i>status</i> be the result of calling the [[SetPrototypeOf]] internal method of <i>O</i> with argument
+ <i>proto</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>If <i>status</i> is <b>false</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Return <i>O</i>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-object-prototype-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-19.1.3"><a href="#sec-properties-of-the-object-prototype-object"
+ title="link to this section">19.1.3</a></span> Properties of the Object Prototype Object</h1>
+
+ <p>The Object prototype object is an ordinary object.</p>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the
+ Object prototype object is <b>null</b> and the initial value of the [[Extensible]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is <b>true</b>.</p>
+ </div>
+
+ <section id="sec-object.prototype.constructor">
+ <h1><span class="secnum" id="sec-19.1.3.1"><a href="#sec-object.prototype.constructor"
+ title="link to this section">19.1.3.1</a></span> Object.prototype.constructor</h1>
+
+ <p>The initial value of <code>Object.prototype.constructor</code> is the standard built-in <code>Object</code>
+ constructor.</p>
+ </section>
+
+ <section id="sec-object.prototype.hasownproperty">
+ <h1><span class="secnum" id="sec-19.1.3.2"><a href="#sec-object.prototype.hasownproperty"
+ title="link to this section">19.1.3.2</a></span> Object.prototype.hasOwnProperty ( V )</h1>
+
+ <p>When the <code>hasOwnProperty</code> method is called with argument <var>V</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>P</i> be <a href="#sec-topropertykey">ToPropertyKey</a>(<i>V</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>P</i>).</li>
+ <li>Let <i>O</i> be the result of calling <a href="#sec-toobject">ToObject</a> passing the <b>this</b> value as the
+ argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>O</i>).</li>
+ <li>Return the result of <a href="#sec-hasownproperty">HasOwnProperty</a>(<i>O</i>, <i>P</i>).</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The ordering of steps 1 and 3 is chosen to ensure that any exception that would have
+ been thrown by step 1 in previous editions of this specification will continue to be thrown even if the <b>this</b>
+ value is <b>undefined</b> or <b>null</b>.</p>
+ </div>
+ </section>
+
+ <section id="sec-object.prototype.isprototypeof">
+ <h1><span class="secnum" id="sec-19.1.3.3"><a href="#sec-object.prototype.isprototypeof"
+ title="link to this section">19.1.3.3</a></span> Object.prototype.isPrototypeOf ( V )</h1>
+
+ <p>When the <code>isPrototypeOf</code> method is called with argument <var>V</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>If <i>V</i> is not an object, return <b>false</b>.</li>
+ <li>Let <i>O</i> be the result of calling <a href="#sec-toobject">ToObject</a> passing the <b>this</b> value as the
+ argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>O</i>).</li>
+ <li>Repeat
+ <ol class="block">
+ <li>Let <i>V</i> be the result of calling the [[GetPrototypeOf]] internal method of <i>V</i> with no arguments.</li>
+ <li>if <i>V</i> is <b>null</b>, return <b>false</b></li>
+ <li>If <a href="#sec-samevalue">SameValue</a>(<i>O</i>, <i>V</i>) is <b>true</b>, then return <b>true</b>.</li>
+ </ol>
+ </li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The ordering of steps 1 and 2 preserves the behaviour specified by previous editions of
+ this specification for the case where V is not an object and the <b>this</b> value is <b>undefined</b> or null.</p>
+ </div>
+ </section>
+
+ <section id="sec-object.prototype.propertyisenumerable">
+ <h1><span class="secnum" id="sec-19.1.3.4"><a href="#sec-object.prototype.propertyisenumerable"
+ title="link to this section">19.1.3.4</a></span> Object.prototype.propertyIsEnumerable ( V )</h1>
+
+ <p>When the <code>propertyIsEnumerable</code> method is called with argument <var>V</var>, the following steps are
+ taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>P</i> be <a href="#sec-topropertykey">ToPropertyKey</a>(<i>V</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>P</i>).</li>
+ <li>Let <i>O</i> be the result of calling <a href="#sec-toobject">ToObject</a> passing the <b>this</b> value as the
+ argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>O</i>).</li>
+ <li>Let <i>desc</i> be the result of calling the [[GetOwnProperty]] internal method of <i>O</i> passing <i>P</i> as the
+ argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>desc</i>).</li>
+ <li>If <i>desc</i> is <b>undefined</b>, return <b>false</b>.</li>
+ <li>Return the value of <i>desc</i>.[[Enumerable]].</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> This method does not consider objects in the prototype chain.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 2</span> The ordering of steps 1 and 3 is chosen to ensure that any exception that would have
+ been thrown by step 1 in previous editions of this specification will continue to be thrown even if the <b>this</b>
+ value is <b>undefined</b> or <b>null</b>.</p>
+ </div>
+ </section>
+
+ <section id="sec-object.prototype.tolocalestring">
+ <h1><span class="secnum" id="sec-19.1.3.5"><a href="#sec-object.prototype.tolocalestring"
+ title="link to this section">19.1.3.5</a></span> Object.prototype.toLocaleString ( )</h1>
+
+ <p>When the <b>toLocaleString</b> method is called, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>Return the result of <a href="#sec-invoke">Invoke</a>(<i>O</i>, <code>"toString"</code>).</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> This function is provided to give all Objects a generic <code>toLocaleString</code>
+ interface, even though not all may use it. Currently, <code>Array</code>, <code>Number</code>, and <code>Date</code>
+ provide their own locale-sensitive <code>toLocaleString</code> methods.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 2</span> The first parameter to this function is likely to be used in a future version of this
+ standard; it is recommended that implementations do not use this parameter position for anything else.</p>
+ </div>
+ </section>
+
+ <section id="sec-object.prototype.tostring">
+ <h1><span class="secnum" id="sec-19.1.3.6"><a href="#sec-object.prototype.tostring"
+ title="link to this section">19.1.3.6</a></span> Object.prototype.toString ( )</h1>
+
+ <p>When the <code>toString</code> method is called, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>If the <b>this</b> value is <b>undefined</b>, return <code>"[object Undefined]"</code>.</li>
+ <li>If the <b>this</b> value is <b>null</b>, return <code>"[object Null]"</code>.</li>
+ <li>Let <i>O</i> be the result of calling <a href="#sec-toobject">ToObject</a> passing the <b>this</b> value as the
+ argument.</li>
+ <li>If <i>O</i> is an exotic Array object, then let <i>builtinTag</i> be <code>"Array"</code>.</li>
+ <li>Else, if <i>O</i> is an exotic String object, then let <i>builtinTag</i> be <code>"String"</code>.</li>
+ <li>Else, if <i>O</i> has an [[ParameterMap]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a>, then let <i>builtinTag</i> be <code>"Arguments"</code>.</li>
+ <li>Else, if <i>O</i> has a [[Call]] internal method, then let <i>builtinTag</i> be <code>"Function"</code>.</li>
+ <li>Else, if <i>O</i> has an [[ErrorData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>,
+ then let <i>builtinTag</i> be <code>"Error"</code>.</li>
+ <li>Else, if <i>O</i> has a [[BooleanData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>,
+ then let <i>builtinTag</i> be <code>"Boolean"</code>.</li>
+ <li>Else, if <i>O</i> has a [[NumberData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>,
+ then let <i>builtinTag</i> be <code>"Number"</code>.</li>
+ <li>Else, if <i>O</i> has a [[DateValue]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>,
+ then let <i>builtinTag</i> be <code>"Date"</code>.</li>
+ <li>Else, if <i>O</i> has a [[RegExpMatcher]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a>, then let <i>builtinTag</i> be <code>"RegExp"</code>.</li>
+ <li>Else, let <i>builtinTag</i> be <code>"Object"</code>.</li>
+ <li>Let <i>hasTag</i> be the result of <a href="#sec-hasproperty">HasProperty</a>(<i>O</i>, @@toStringTag).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>hasTag</i>).</li>
+ <li>If <i>hasTag</i> is <b>false</b>, then let <i>tag</i> be <i>builtinTag</i>.</li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>tag</i> be the result of <a href="#sec-get-o-p">Get</a>(<i>O</i>, @@toStringTag).</li>
+ <li>If <i>tag</i> is an <a href="#sec-completion-record-specification-type">abrupt completion</a>, let <i>tag</i> be
+ <a href="#sec-normalcompletion">NormalCompletion</a>(<code>"???"</code>).</li>
+ <li>Let <i>tag</i> be <i>tag</i>.[[value]].</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>tag</i>) is not String, let <i>tag</i> be
+ <code>"???"</code>.</li>
+ <li>If <i>tag</i> is any of <code>"Arguments"</code>, <code>"Array"</code>, <code>"Boolean"</code>,
+ <code>"Date"</code>, <code>"Error"</code>, <code>"Function"</code>, <code>"Number"</code>,
+ <code>"RegExp"</code>, or <code>"String"</code> and <a href="#sec-samevalue">SameValue</a>(<i>tag</i>,
+ <i>builtinTag</i>) is <b>false</b>, then let <i>tag</i> be the string value <code>"~"</code> concatenated with
+ the current value of <i>tag</i>.</li>
+ </ol>
+ </li>
+ <li>Return the String value that is the result of concatenating the three Strings <code>"[object "</code>, <i>tag</i>,
+ and <code>"]"</code>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Historically, this function was occasionally used to access the string value of the
+ [[Class]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> that was used in previous editions
+ of this specification as a nominal type tag for various built-in objects. The above definition of <code>toString</code>
+ preserves the ability to use it as a reliable test for those specific kinds of built-in objects but it does not provide
+ a reliable type testing mechanism for other kinds of built-in or program defined objects.</p>
+ </div>
+ </section>
+
+ <section id="sec-object.prototype.valueof">
+ <h1><span class="secnum" id="sec-19.1.3.7"><a href="#sec-object.prototype.valueof"
+ title="link to this section">19.1.3.7</a></span> Object.prototype.valueOf ( )</h1>
+
+ <p>When the <b>valueOf</b> method is called, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the result of calling <a href="#sec-toobject">ToObject</a> passing the <b>this</b> value as the
+ argument.</li>
+ <li>Return <i>O</i>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-object-instances">
+ <h1><span class="secnum" id="sec-19.1.4"><a href="#sec-properties-of-object-instances"
+ title="link to this section">19.1.4</a></span> Properties of Object Instances</h1>
+
+ <p>Object instances have no special properties beyond those inherited from the Object prototype object.</p>
+ </section>
+ </section>
+
+ <section id="sec-function-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-19.2"><a href="#sec-function-objects" title="link to this section">19.2</a></span> Function
+ Objects</h1>
+ </div>
+
+ <section id="sec-function-constructor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-19.2.1"><a href="#sec-function-constructor"
+ title="link to this section">19.2.1</a></span> The Function Constructor</h1>
+
+ <p>The Function constructor is the %Function% intrinsic object and the initial value of the <code>Function</code> property
+ of the global object. When <code>Function</code> is called as a function rather than as a constructor, it creates and
+ initializes a new Function object. Thus the function call <code><b>Function(</b>…<b>)</b></code> is equivalent to
+ the object creation expression <code><b>new Function(</b>…<b>)</b></code> with the same arguments. However, if the
+ <b>this</b> value passed in the call is an Object with a [[Code]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> whose value is <span
+ class="value">undefined</span>, it initializes the <b>this</b> value using the argument values. This permits
+ <code>Function</code> to be used both as factory method and to perform constructor instance initialization.</p>
+
+ <p><code>Function</code> may be subclassed and subclass constructors may perform a <code>super</code> invocation of the
+ <code>Function</code> constructor to initialize subclass instances. However, all syntactic forms for defining function
+ objects create instances of <code>Function</code>. There is no syntactic means to create instances of
+ <code>Function</code> subclasses except for the built-in Generator Function subclass.</p>
+ </div>
+
+ <section id="sec-function-p1-p2-pn-body">
+ <h1><span class="secnum" id="sec-19.2.1.1"><a href="#sec-function-p1-p2-pn-body"
+ title="link to this section">19.2.1.1</a></span> Function ( p1, p2, … , pn, body )</h1>
+
+ <p>The last argument specifies the body (executable code) of a function; any preceding arguments specify formal
+ parameters.</p>
+
+ <p>When the <code>Function</code> function is called with some arguments <var>p1</var>, <var>p2</var>, … ,
+ <var>pn</var>, <var>body</var> (where <var>n</var> might be <span style="font-family: Times New Roman">0</span>, that is,
+ there are no “<var>p</var>” arguments, and where <var>body</var> might also not be provided), the following
+ steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>argCount</i> be the total number of arguments passed to this function invocation.</li>
+ <li>Let <i>P</i> be the empty String.</li>
+ <li>If <i>argCount</i> = 0, let <i>bodyText</i> be the empty String.</li>
+ <li>Else if <i>argCount</i> = 1, let <i>bodyText</i> be that argument.</li>
+ <li>Else <i>argCount</i> > 1,
+ <ol class="block">
+ <li>Let <i>firstArg</i> be the first argument.</li>
+ <li>Let <i>P</i> be <a href="#sec-tostring">ToString</a>(<i>firstArg</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>P</i>).</li>
+ <li>Let <i>k</i> be 2.</li>
+ <li>Repeat, while <i>k</i> < <i>argCount</i>
+ <ol class="block">
+ <li>Let <i>nextArg</i> be the <i>k</i>’th argument.</li>
+ <li>Let <i>nextArgString</i> be <a href="#sec-tostring">ToString</a>(<i>nextArg</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>nextArgString</i>).</li>
+ <li>Let <i>P</i> be the result of concatenating the previous value of <i>P</i>, the String <code>","</code> (a
+ comma), and <i>nextArgString</i>.</li>
+ <li>Increase <i>k</i> by 1.</li>
+ </ol>
+ </li>
+ <li>Let <i>bodyText</i> be the <i>k</i>’th argument.</li>
+ </ol>
+ </li>
+ <li>Let <i>bodyText</i> be <a href="#sec-tostring">ToString</a>(<i>bodyText</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>bodyText</i>).</li>
+ <li>Let <i>parameters</i> be the result of parsing <i>P</i>, interpreted as UTF-16 encoded Unicode text as described in
+ <a href="#sec-static-semantics-utf-16encoding">10.1.1</a><i>,</i> using <i>FormalParameters</i> as the goal symbol.
+ Throw a <b>SyntaxError</b> exception if the parse fails.</li>
+ <li>Let <i>body</i> be the result of parsing <i>bodyText</i>, interpreted as UTF-16 encoded Unicode text as described in
+ <a href="#sec-static-semantics-utf-16encoding">10.1.1</a><i>,</i> using <i>FunctionBody</i> as the goal symbol.
+ Throw a <b>SyntaxError</b> exception if the parse fails or if any static semantics errors are detected.</li>
+ <li>If IsSimpleParameterList of <i>parameters</i> is <b>false</b> and any element of the BoundNames of <i>parameters</i>
+ also occurs in the VarDeclaredNames of <i>body</i>, then throw a <b>SyntaxError</b> exception.</li>
+ <li>If any element of the BoundNames of <i>parameters</i> also occurs in the LexicallyDeclaredNames of <i>body</i>, then
+ throw a <b>SyntaxError</b> exception.</li>
+ <li>If <i>bodyText</i> is <a href="#sec-strict-mode-code">strict mode code</a> (<a href="#sec-strict-mode-code">see
+ 10.2.1</a>) then let <i>strict</i> be <b>true</b>, else let <i>strict</i> be <b>false</b>.</li>
+ <li>Let <i>scope</i> be <a href="#sec-global-environment-records">the Global Environment</a>.</li>
+ <li>Let <i>F</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>F</i>) is not Object or if <i>F</i> does not have a
+ [[Code]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> or if the value of [[Code]] is
+ not <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>C</i> be the function that is currently being evaluated.</li>
+ <li>Let <i>proto</i> be the result of <a
+ href="#sec-getprototypefromconstructor">GetPrototypeFromConstructor</a>(<i>C</i>,
+ <code>"%FunctionPrototype%"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>proto</i>).</li>
+ <li>Let <i>F</i> be <a href="#sec-functionallocate">FunctionAllocate</a>(<i>C</i>, <i>strict</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>F</i>).</li>
+ </ol>
+ </li>
+ <li>If the value of <i>F’s</i> [[FunctionKind]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> is not <code>"normal"</code>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>isExtensible</i> be <a href="#sec-isextensible-o">IsExtensible</a>(<i>F</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>isExtensible</i>).</li>
+ <li>If <i>isExtensible</i> is <b>false</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>status</i> be <a href="#sec-functioninitialize">FunctionInitialize</a>(<i>F</i>, <span style="font-family:
+ sans-serif">Normal</span>, <i>strict</i>, <i>parameters</i>, <i>body, scope</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>If ReferencesSuper of <i>body</i> is <b>true</b> or ReferencesSuper of <i>parameters</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Perform <a href="#sec-makemethod">MakeMethod</a>(<i>F</i>, <b>undefined</b>, <b>undefined</b>).</li>
+ </ol>
+ </li>
+ <li>Let <i>status</i> be the result of <a href="#sec-makeconstructor">MakeConstructor</a> with argument <i>F</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Let <i>hasName</i> be <a href="#sec-hasownproperty">HasOwnProperty</a>(<i>F</i>, <code>"<b>name</b>"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>hasName</i>).</li>
+ <li>If <i>hasName</i> is <b>false</b>, then perform <a href="#sec-setfunctionname">SetFunctionName</a>(<i>F</i>,
+ <code>"<b>anonymous</b>"</code>).</li>
+ <li>Return <i>F</i>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>Funtion</code> function is <b>1</b> (<a href="#sec-function.length">see
+ 19.2.2.1</a>).</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> A <code>prototype</code> property is automatically created for every function created
+ using the <code>Function</code> constructor, to provide for the possibility that the function will be used as a
+ constructor.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 2</span> It is permissible but not necessary to have one argument for each formal parameter to
+ be specified. For example, all three of the following expressions produce the same result:</p>
+
+ <pre>new Function("a", "b", "c", "return a+b+c")</pre>
+ <pre>new Function("a, b, c", "return a+b+c")</pre>
+ <pre>new Function("a,b", "c", "return a+b+c")</pre>
+ </div>
+ </section>
+
+ <section id="sec-new-function-argumentslist">
+ <h1><span class="secnum" id="sec-19.2.1.2"><a href="#sec-new-function-argumentslist"
+ title="link to this section">19.2.1.2</a></span> new Function ( ...argumentsList )</h1>
+
+ <p>When <code>Function</code> is called as part of a <code>new</code> expression, it initializes the newly created
+ object.</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be the <code>Function</code> function object on which the <code>new</code> operator was applied.</li>
+ <li>Let <i>argumentsList</i> be the <i>argumentsList</i> argument of the [[Construct]] internal method that was invoked
+ by the <code>new</code> operator.</li>
+ <li>Return the result of <a href="#sec-construct-f-argumentslist">Construct</a> (<i>F</i>, <i>argumentsList</i>).</li>
+ </ol>
+
+ <p>If <code>Function</code> is implemented as an <a href="#sec-ecmascript-function-objects">ECMAScript function
+ object</a>, its [[Construct]] internal method will perform the above steps.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-function-constructor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-19.2.2"><a href="#sec-properties-of-the-function-constructor"
+ title="link to this section">19.2.2</a></span> Properties of the Function Constructor</h1>
+
+ <p>The Function constructor is itself a built-in Function object. The value of the [[Prototype]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the Function constructor is
+ %FunctionPrototype%, the intrinsic Function prototype object (<a
+ href="#sec-properties-of-the-function-prototype-object">19.2.3</a>).</p>
+
+ <p>The value of the [[Extensible]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the
+ Function constructor is <b>true</b>.</p>
+
+ <p>The Function constructor has the following properties:</p>
+ </div>
+
+ <section id="sec-function.length">
+ <h1><span class="secnum" id="sec-19.2.2.1"><a href="#sec-function.length" title="link to this section">19.2.2.1</a></span>
+ Function.length</h1>
+
+ <p>This is a data property with a value of 1. This property has the attributes { [[Writable]]: <span
+ class="value">false</span>, [[Enumerable]]: <span class="value">false</span>, [[Configurable]]: <span
+ class="value">true</span> }.</p>
+ </section>
+
+ <section id="sec-function.prototype">
+ <h1><span class="secnum" id="sec-19.2.2.2"><a href="#sec-function.prototype"
+ title="link to this section">19.2.2.2</a></span> Function.prototype</h1>
+
+ <p>The value of <code>Function.prototype</code> is %FunctionPrototype%, the intrinsic Function prototype object (<a
+ href="#sec-properties-of-the-function-prototype-object">19.2.3</a>).</p>
+
+ <p>This property has the attributes { [[Writable]]: <span class="value">false</span>, [[Enumerable]]: <span
+ class="value">false</span>, [[Configurable]]: <span class="value">false</span> }.</p>
+ </section>
+
+ <section id="sec-function-@@create">
+ <h1><span class="secnum" id="sec-19.2.2.3"><a href="#sec-function-@@create"
+ title="link to this section">19.2.2.3</a></span> Function[ @@create ] ( )</h1>
+
+ <p>The @@create method of an object <var>F</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be the <b>this</b> value.</li>
+ <li>Let <i>proto</i> be the result of <a
+ href="#sec-getprototypefromconstructor">GetPrototypeFromConstructor</a>(<i>F</i>,
+ <code>"%FunctionPrototype%"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>proto</i>).</li>
+ <li>Return <a href="#sec-functionallocate">FunctionAllocate</a>(<i>proto</i>, <b>false</b>).</li>
+ </ol>
+
+ <p>The value of the <code>name</code> property of this function is <code>"[Symbol.create]"</code>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <span class="value">false</span>, [[Enumerable]]: <span
+ class="value">false</span>, [[Configurable]]: <span class="value">true</span> }.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The Function <code>@@create</code> function passes <b>false</b> as the <i>strict</i>
+ parameter to <a href="#sec-functionallocate">FunctionAllocate</a>. This causes the allocated <a
+ href="#sec-ecmascript-function-objects">ECMAScript function object</a> to have the internal methods of a non-strict
+ function. The <code>Function</code> constructor may reset the functions [[Strict]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to <b>true</b>. It is up to the implementation
+ whether this also changes the internal methods.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-function-prototype-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-19.2.3"><a href="#sec-properties-of-the-function-prototype-object"
+ title="link to this section">19.2.3</a></span> Properties of the Function Prototype Object</h1>
+
+ <p>The Function prototype object is itself a Built-in Function object. When invoked, it accepts any arguments and returns
+ <b>undefined</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The Function prototype object is specified to be a function object to ensure
+ compatibility with ECMAScript code that was created prior to the 6<sup>th</sup> Edition of this specification.</p>
+ </div>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the
+ Function prototype object is the intrinsic object %ObjectPrototype% (<a
+ href="#sec-properties-of-the-object-prototype-object">19.1.3</a>). The initial value of the [[Extensible]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the Function prototype object is
+ <b>true</b>.</p>
+
+ <p>The Function prototype object does not have a <code>prototype</code> property.</p>
+
+ <p>The value of The <code>length</code> property of the Function prototype object is <b>0</b>.</p>
+
+ <p>The value of the <code>name</code> property of the Function prototype object is the empty String.</p>
+ </div>
+
+ <section id="sec-function.prototype.apply">
+ <h1><span class="secnum" id="sec-19.2.3.1"><a href="#sec-function.prototype.apply"
+ title="link to this section">19.2.3.1</a></span> Function.prototype.apply ( thisArg, argArray )</h1>
+
+ <p>When the <code>apply</code> method is called on an object <var>func</var> with arguments <var>thisArg</var> and
+ <var>argArray</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>func</i>) is <b>false</b>, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>argArray</i> is <b>null</b> or <b>undefined</b>, then
+ <ol class="block">
+ <li>Return the result of calling the [[Call]] internal method of <i>func</i>, providing <i>thisArg</i> as
+ <i>thisArgument</i> and an empty <a href="#sec-list-and-record-specification-type">List</a> of arguments as
+ <i>argumentsList</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>argList</i> be the result of <a
+ href="#sec-createlistfromarraylike">CreateListFromArrayLike</a>(<i>argArray</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>argList</i> ).</li>
+ <li>Perform <a href="#sec-preparefortailcall">PrepareForTailCall</a>().</li>
+ <li>Return the result of calling the [[Call]] internal method of <i>func</i>, providing <i>thisArg</i> as
+ <i>thisArgument</i> and <i>argList</i> as <i>argumentsList</i>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>apply</code> method is <b>2</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The thisArg value is passed without modification as the <b>this</b> value. This is a
+ change from Edition 3, where an <b>undefined</b> or <b>null</b> thisArg is replaced with the global object and <a
+ href="#sec-toobject">ToObject</a> is applied to all other values and that result is passed as the <b>this</b> value.
+ Even though the thisArg is passed without modification, non-strict mode functions still perform these transfromations
+ upon entry to the function.</p>
+ </div>
+ </section>
+
+ <section id="sec-function.prototype.bind">
+ <h1><span class="secnum" id="sec-19.2.3.2"><a href="#sec-function.prototype.bind"
+ title="link to this section">19.2.3.2</a></span> Function.prototype.bind ( thisArg , ...args)</h1>
+
+ <p>When the <code>bind</code> is called with argument <var>thisArg</var> and zero or more <var>args</var>, it performs the
+ following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>Target</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>Target</i>) is <b>false</b>, throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>args</i> be a new (possibly empty) <a href="#sec-list-and-record-specification-type">List</a> consisting of
+ all of the argument values provided after <i>thisArg</i> in order.</li>
+ <li>Let <i>F</i> be the result of the abstract operation <a href="#sec-boundfunctioncreate">BoundFunctionCreate</a> with
+ arguments <i>Target</i>, <i>thisArg</i>, and <i>args</i>.</li>
+ <li>If <i>Target</i> has a <a href="#sec-bound-function-exotic-objects">[[BoundTargetFunction]]</a> <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, then
+ <ol class="block">
+ <li>Let <i>targetLen</i> be the result of <a href="#sec-get-o-p">Get</a>(<i>Target</i>, <code>"length"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>targetLen</i>).</li>
+ <li>Let <i>L</i> be the larger of 0 and the result of <i>targetLen</i> minus the number of elements of
+ <i>A</i>.</li>
+ </ol>
+ </li>
+ <li>Else let <i>L</i> be 0.</li>
+ <li>Call the [[DefineOwnProperty]] internal method of <i>F</i> with arguments <code>"length"</code> and
+ PropertyDescriptor {[[Value]]: <i>L</i>, [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>true</b>}.</li>
+ <li>Let <i>targetRealm</i> be <a href="#sec-boundfunctiontargetrealm">BoundFunctionTargetRealm</a>(<i>Target</i>).</li>
+ <li>Perform the <a href="#sec-addrestrictedfunctionproperties">AddRestrictedFunctionProperties</a>(<i>F</i>,
+ <i>targetRealm</i>).</li>
+ <li>Return <i>F</i>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>bind</code> method is <b>1</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Function objects created using <code>Function.prototype.bind</code> are exotic objects.
+ They also do not have a <code>prototype</code> property.</p>
+ </div>
+ </section>
+
+ <section id="sec-function.prototype.call">
+ <h1><span class="secnum" id="sec-19.2.3.3"><a href="#sec-function.prototype.call"
+ title="link to this section">19.2.3.3</a></span> Function.prototype.call (thisArg , ...args)</h1>
+
+ <p>When the <code>call</code> method is called on an object <var>func</var> with argument, <var>thisArg</var> and zero or
+ more <var>args</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>func</i>) is <b>false</b>, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>Let <i>argList</i> be an empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>If this method was called with more than one argument then in left to right order starting with <i>the second
+ argument</i> append each argument as the last element of <i>argList</i></li>
+ <li>Perform <a href="#sec-preparefortailcall">PrepareForTailCall</a>().</li>
+ <li>Return the result of calling the [[Call]] internal method of <i>func</i>, providing <i>thisArg</i> as
+ <i>thisArgument</i> and <i>argList</i> as <i>argumentsList</i>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>call</code> method is <b>1</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The thisArg value is passed without modification as the <b>this</b> value. This is a
+ change from Edition 3, where an <b>undefined</b> or <b>null</b> thisArg is replaced with the global object and <a
+ href="#sec-toobject">ToObject</a> is applied to all other values and that result is passed as the <b>this</b> value.
+ Even though the thisArg is passed without modification, non-strict mode functions still perform these transfromations
+ upon entry to the function.</p>
+ </div>
+ </section>
+
+ <section id="sec-function.prototype.constructor">
+ <h1><span class="secnum" id="sec-19.2.3.4"><a href="#sec-function.prototype.constructor"
+ title="link to this section">19.2.3.4</a></span> Function.prototype.constructor</h1>
+
+ <p>The initial value of <code>Function.prototype.constructor</code> is the intrinsic object %Function%.</p>
+ </section>
+
+ <section id="sec-function.prototype.tomethod">
+ <h1><span class="secnum" id="sec-19.2.3.5"><a href="#sec-function.prototype.tomethod"
+ title="link to this section">19.2.3.5</a></span> Function.prototype.toMethod (newHome [ , methodName ] )</h1>
+
+ <p>When the <code>toMethod</code> method is called on an object <var>func</var> with argument <var>superBinding</var> and
+ optional argument <var>methodName</var> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>newHome</i>) is not Object, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>If <i>func</i> is an <a href="#sec-ecmascript-function-objects">ECMAScript function object</a> or an exotic Built-in
+ function object, then
+ <ol class="block">
+ <li>If <i>methodName</i> is not <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>methodName</i> be <a href="#sec-topropertykey">ToPropertyKey</a>(<i>methodName</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>methodName</i>).</li>
+ </ol>
+ </li>
+ <li>Return <a href="#sec-clonemethod">CloneMethod</a>(<i>func</i>, <i>newHome</i>, <i>methodName</i>).</li>
+ </ol>
+ </li>
+ <li>If <i>func</i> is a <a href="#sec-bound-function-exotic-objects">Bound Function</a> exotic object, then return <a
+ href="#sec-boundfunctionclone">BoundFunctionClone</a>(<i>func</i>).</li>
+ <li>If <i>func</i> is any other exotic function object that supports the equivalent of the <a
+ href="#sec-clonemethod">CloneMethod</a> abstract operation, then return an appropriately cloned object.</li>
+ <li>Throw a <b>TypeError</b> exception.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>toMethod</code> method is <b>1</b>.</p>
+ </section>
+
+ <section id="sec-function.prototype.tostring">
+ <h1><span class="secnum" id="sec-19.2.3.6"><a href="#sec-function.prototype.tostring"
+ title="link to this section">19.2.3.6</a></span> Function.prototype.toString ( )</h1>
+
+ <p>An implementation-dependent String source code representation of the <b>this</b> object is returned. This
+ representation has the syntax of a <span class="nt">FunctionDeclaration</span> <span style="font-family: Times New
+ Roman"><i>FunctionExpression</i>, <i>GeneratorDeclaration, GeneratorExpession, ClassDeclaration</i>,
+ <i>ClassExpression</i>, <i>ArrowFunction</i>, <i>MethodDefinition</i>, or <i>GeneratorMethod</i> depending upon the actual
+ characteristics of the object</span>. In particular that the use and placement of white space, line terminators, and
+ semicolons within the representation String is implementation-dependent.</p>
+
+ <p>If the object was defined using ECMAScript code and the returned string representation is in the form of a <span
+ class="nt">FunctionDeclaration</span> <span style="font-family: Times New Roman"><i>FunctionExpression</i>,
+ <i>GeneratorDeclaration, GeneratorExpession, ClassDeclaration</i>, <i>ClassExpression</i>, or <i>ArrowFunction</i></span>
+ then the representation must be such that if the string is evaluated, using <code>eval</code> in a lexical context that is
+ equivalent to the lexical context used to create the original object, it will result in a new functionally equivalent
+ object. The returned source code must not mention freely any variables that were not mentioned freely by the original
+ function’s source code, even if these “extra” names were originally in scope. If the implementation
+ cannot produce a source code string that meets these criteria then it must return a string for which <code>eval</code>
+ will throw a <b>SyntaxError</b> exception.</p>
+
+ <p>The <code>toString</code> function is not generic; it throws a <b>TypeError</b> exception if its <b>this</b> value does
+ not have a [[Call]] internal method. Therefore, it cannot be transferred to other kinds of objects for use as a
+ method.</p>
+ </section>
+
+ <section id="sec-function.prototype-@@create">
+ <h1><span class="secnum" id="sec-19.2.3.7"><a href="#sec-function.prototype-@@create"
+ title="link to this section">19.2.3.7</a></span> Function.prototype[ @@create ] ( )</h1>
+
+ <p>The @@create method of an object <var>F</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Return the result of calling <a
+ href="#sec-ordinarycreatefromconstructor">OrdinaryCreateFromConstructor</a>(<i>F</i>,
+ <code>"%ObjectPrototype%"</code>).</li>
+ </ol>
+
+ <p>The value of the <code>name</code> property of this function is <code>"[Symbol.create]"</code>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <span class="value">false</span>, [[Enumerable]]: <span
+ class="value">false</span>, [[Configurable]]: <span class="value">true</span> }.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> This is the default @@create method that is inherited by all ordinary constructor
+ functions that do not explicitly over-ride it.</p>
+ </div>
+ </section>
+
+ <section id="sec-function.prototype-@@hasinstance">
+ <h1><span class="secnum" id="sec-19.2.3.8"><a href="#sec-function.prototype-@@hasinstance"
+ title="link to this section">19.2.3.8</a></span> Function.prototype[@@hasInstance] ( V )</h1>
+
+ <p>When the @@hasInstance method of an object <var>F</var> is called with value <var>V</var>, the following steps are
+ taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be the <b>this</b> value.</li>
+ <li>Return the result of <a href="#sec-ordinaryhasinstance">OrdinaryHasInstance</a>(<i>F</i>, <i>V</i>).</li>
+ </ol>
+
+ <p>The value of the <code>name</code> property of this function is <code>"[Symbol.hasInstance]"</code>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <span class="value">false</span>,
+ [[Configurable]]: <span class="value">false</span> }.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> This is the default implementation of <code>@@hasInstance</code> that most functions
+ inherit. <code>@@hasInstance</code> is called by the <code>instanceof</code> operator to deterimine whether a value is
+ an instance of a specific constructor. An expression such as</p>
+
+ <pre>v instanceof F</pre>
+
+ <p>evaluates as</p>
+
+ <pre>F[@@hasInstance](v)</pre>
+
+ <p>A constructor function can control which objects are recognized as its instances by <code>instanceof</code> by
+ exposing a different <code>@@hasInstance</code> method on the function.</p>
+
+ <p>This property is non-writable and non-configurable to prevent tampering that could be used to globally expose the
+ target function of a <a href="#sec-bound-function-exotic-objects">bound function</a>.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-function-instances">
+ <div class="front">
+ <h1><span class="secnum" id="sec-19.2.4"><a href="#sec-function-instances" title="link to this section">19.2.4</a></span>
+ Function Instances</h1>
+
+ <p>Every function instance is an <a href="#sec-ecmascript-function-objects">ECMAScript function object</a> and has the
+ internal slots listed in <a href="#table-26">Table 26</a>.</p>
+
+ <p>Function instances that correspond to strict mode functions and function instances created using the <b><a
+ href="#sec-function.prototype.bind">Function.prototype.bind</a> method</b> (<a
+ href="#sec-function.prototype.bind">19.2.3.2</a>) have properties named <span class="value">caller</span> and
+ <code>arguments</code> that throw a <b>TypeError</b> exception. An ECMAScript implementation must not associate any
+ implementation specific behaviour with accesses of these properties from strict mode function code.</p>
+
+ <p>The Function instances have the following properties:</p>
+ </div>
+
+ <section id="sec-function-instances-length">
+ <h1><span class="secnum" id="sec-19.2.4.1"><a href="#sec-function-instances-length"
+ title="link to this section">19.2.4.1</a></span> length</h1>
+
+ <p>The value of the <code>length</code> property is an integer that indicates the typical number of arguments expected by
+ the function. However, the language permits the function to be invoked with some other number of arguments. The behaviour
+ of a function when invoked on a number of arguments other than the number specified by its <code>length</code> property
+ depends on the function. This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>,
+ [[Configurable]]: <b>true</b> }.</p>
+ </section>
+
+ <section id="sec-name">
+ <h1><span class="secnum" id="sec-19.2.4.2"><a href="#sec-name" title="link to this section">19.2.4.2</a></span> name</h1>
+
+ <p>The value of the <code>name</code> property is an String that is descriptive of the function. The name has no semantic
+ significance but is typically a variable or property name that is used to refer to the function at its point of definition
+ in ECMAScript code. This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>,
+ [[Configurable]]: <b>true</b> }.</p>
+
+ <p>Anonymous functions objects that do not have a contextual name associated with them by this specification do not have a
+ <code>name</code> own property but inherit the <code>name</code> property of %FunctionPrototype%.</p>
+
+ <p class="Note">Function objects created using <code><a
+ href="#sec-function.prototype.bind">Function.prototype.bind</a></code> do not have a <code>name</code> property.</p>
+ </section>
+
+ <section id="sec-function-instances-prototype">
+ <h1><span class="secnum" id="sec-19.2.4.3"><a href="#sec-function-instances-prototype"
+ title="link to this section">19.2.4.3</a></span> prototype</h1>
+
+ <p>Function instances that can be used as a constructor have a <code>prototype</code> property. Whenever such a function
+ instance is created another ordinary object is also created and is the initial value of the function’s
+ <code>prototype</code> property. Unless otherwise specified, the value of the prototype property is used to initialize the
+ [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of a newly created ordinary
+ object before the Function object is invoked as a constructor for that newly created object.</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>true</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Function objects created using <code><a
+ href="#sec-function.prototype.bind">Function.prototype.bind</a></code>, or by evaluating a <i>MethodDefinition</i> (that
+ is not a <i>GeneratorMethod</i>) or an <i>ArrowFunction</i> grammar production do not have a <code>prototype</code>
+ property.</p>
+ </div>
+ </section>
+ </section>
+ </section>
+
+ <section id="sec-boolean-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-19.3"><a href="#sec-boolean-objects" title="link to this section">19.3</a></span> Boolean
+ Objects</h1>
+ </div>
+
+ <section id="sec-boolean-constructor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-19.3.1"><a href="#sec-boolean-constructor" title="link to this section">19.3.1</a></span>
+ The Boolean Constructor</h1>
+
+ <p>The Boolean constructor is the %Boolean% intrinsic object and the initial value of the <code>Boolean</code> property of
+ the global object. When <code>Boolean</code> is called as a function rather than as a constructor, it performs a type
+ conversion. However, if the <b>this</b> value passed in the call is an Object with an uninitialized [[BooleanData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, it initializes the <b>this</b> value using the
+ argument value. This permits <code>Boolean</code> to be used both to perform type conversion and to perform constructor
+ instance initialization.</p>
+
+ <p>The <code>Boolean</code> constructor is designed to be subclassable. It may be used as the value of an
+ <code>extends</code> clause of a class declaration. Subclass constructors that intended to inherit the specified
+ <code>Boolean</code> behaviour must include a <code>super</code> call to the <code>Boolean</code> constructor to
+ initialize the [[BooleanData]] state of subclass instances.</p>
+ </div>
+
+ <section id="sec-boolean-constructor-boolean-value">
+ <h1><span class="secnum" id="sec-19.3.1.1"><a href="#sec-boolean-constructor-boolean-value"
+ title="link to this section">19.3.1.1</a></span> Boolean ( value )</h1>
+
+ <p>When <code>Boolean</code> is called with argument <var>value</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>Let <i>b</i> be <a href="#sec-toboolean">ToBoolean</a>(<i>value</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is Object and <i>O</i> has a [[BooleanData]]
+ <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> and the value of [[BooleanData]] is
+ <b>undefined</b>, then
+ <ol class="block">
+ <li>Set the value of <i>O’s</i> [[BooleanData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to <i>b</i>.</li>
+ <li>Return <i>O</i>.</li>
+ </ol>
+ </li>
+ <li>Return <i>b</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-new-boolean-argumentslist">
+ <h1><span class="secnum" id="sec-19.3.1.2"><a href="#sec-new-boolean-argumentslist"
+ title="link to this section">19.3.1.2</a></span> new Boolean ( ...argumentsList )</h1>
+
+ <p>When <code>Boolean</code> is called as part of a new expression , it initializes a newly created object:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be the <code>Boolean</code> function object on which the <code>new</code> operator was applied.</li>
+ <li>Let <i>argumentsList</i> be the <i>argumentsList</i> argument of the [[Construct]] internal method that was invoked
+ by the <code>new</code> operator.</li>
+ <li>Return the result of <a href="#sec-construct-f-argumentslist">Construct</a> (<i>F</i>, <i>argumentsList</i>).</li>
+ </ol>
+
+ <p>If <code>Boolean</code> is implemented as an <a href="#sec-ecmascript-function-objects">ECMAScript function object</a>,
+ its [[Construct]] internal method will perform the above steps.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-boolean-constructor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-19.3.2"><a href="#sec-properties-of-the-boolean-constructor"
+ title="link to this section">19.3.2</a></span> Properties of the Boolean Constructor</h1>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the
+ Boolean constructor is the Function prototype object (<a
+ href="#sec-properties-of-the-function-prototype-object">19.2.3</a>).</p>
+
+ <p>Besides the <code>length</code> property (whose value is <b>1</b>), the Boolean constructor has the following
+ properties:</p>
+ </div>
+
+ <section id="sec-boolean.prototype">
+ <h1><span class="secnum" id="sec-19.3.2.1"><a href="#sec-boolean.prototype"
+ title="link to this section">19.3.2.1</a></span> Boolean.prototype</h1>
+
+ <p>The initial value of <code>Boolean.prototype</code> is the Boolean prototype object (<a
+ href="#sec-properties-of-the-boolean-prototype-object">19.3.3</a>).</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-boolean-@@create">
+ <h1><span class="secnum" id="sec-19.3.2.2"><a href="#sec-boolean-@@create"
+ title="link to this section">19.3.2.2</a></span> Boolean[ @@create ] ( )</h1>
+
+ <p>The @@create method of an object <var>F</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be the <b>this</b> value.</li>
+ <li>Let <i>obj</i> be the result of calling <a
+ href="#sec-ordinarycreatefromconstructor">OrdinaryCreateFromConstructor</a>(<i>F</i>,
+ <code>"%BooleanPrototype%"</code>, ( [[BooleanData]]) ).</li>
+ <li>Return <i>obj</i>.</li>
+ </ol>
+
+ <p>The value of the <code>name</code> property of this function is <code>"[Symbol.create]"</code>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>true</b> }.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> [[BooleanData]] is initially assigned the value <b>undefined</b> as a flag to indicate
+ that the instance has not yet been initialized by the Boolean constructor. This flag value is never directly exposed to
+ ECMAScript code; hence implementations may choose to encode the flag in some other manner.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-boolean-prototype-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-19.3.3"><a href="#sec-properties-of-the-boolean-prototype-object"
+ title="link to this section">19.3.3</a></span> Properties of the Boolean Prototype Object</h1>
+
+ <p>The Boolean prototype object is an ordinary object. It is not a Boolean instance and does not have a [[BooleanData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</p>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the
+ Boolean prototype object is the standard built-in Object prototype object (<a
+ href="#sec-properties-of-the-object-prototype-object">19.1.3</a>).</p>
+
+ <p>The abstract operation <span style="font-family: Times New Roman">thisBooleanValue(<i>value</i>)</span> performs the
+ following steps:</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>value</i>) is Boolean, return <i>value</i>.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>value)</i> is Object and <i>value</i> has a
+ [[BooleanData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, then
+ <ol class="block">
+ <li>Let <i>b</i> be the value of <i>value’s</i> [[BooleanData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>b</i> is not <b>undefined</b>, then return <i>b</i>.</li>
+ </ol>
+ </li>
+ <li>Throw a <b>TypeError</b> exception.</li>
+ </ol>
+ </div>
+
+ <section id="sec-boolean.prototype.constructor">
+ <h1><span class="secnum" id="sec-19.3.3.1"><a href="#sec-boolean.prototype.constructor"
+ title="link to this section">19.3.3.1</a></span> Boolean.prototype.constructor</h1>
+
+ <p>The initial value of <code>Boolean.prototype.constructor</code> is the built-in <code>Boolean</code> constructor.</p>
+ </section>
+
+ <section id="sec-boolean.prototype.tostring">
+ <h1><span class="secnum" id="sec-19.3.3.2"><a href="#sec-boolean.prototype.tostring"
+ title="link to this section">19.3.3.2</a></span> Boolean.prototype.toString ( )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>b</i> be thisBooleanValue(<b>this</b> value).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>b</i>).</li>
+ <li>If <i>b</i> is <b>true</b>, then return <code>"true"</code>; else return <code>"false"</code>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-boolean.prototype.valueof">
+ <h1><span class="secnum" id="sec-19.3.3.3"><a href="#sec-boolean.prototype.valueof"
+ title="link to this section">19.3.3.3</a></span> Boolean.prototype.valueOf ( )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Return thisBooleanValue(<b>this</b> value).</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-boolean-instances">
+ <h1><span class="secnum" id="sec-19.3.4"><a href="#sec-properties-of-boolean-instances"
+ title="link to this section">19.3.4</a></span> Properties of Boolean Instances</h1>
+
+ <p>Boolean instances are ordinary objects that inherit properties from the Boolean prototype object. Boolean instances have
+ a [[BooleanData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>. The [[BooleanData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is the Boolean value represented by this Boolean
+ object.</p>
+ </section>
+ </section>
+
+ <section id="sec-symbol-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-19.4"><a href="#sec-symbol-objects" title="link to this section">19.4</a></span> Symbol
+ Objects</h1>
+ </div>
+
+ <section id="sec-symbol-constructor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-19.4.1"><a href="#sec-symbol-constructor" title="link to this section">19.4.1</a></span>
+ The Symbol Constructor</h1>
+
+ <p>The Symbol constructor is the %Symbol% intrinsic object and the initial value of the <code>Symbol</code> property of
+ the global object. When <code>Symbol</code> is called as a function rather than as a constructor, it returns a new Symbol
+ value.</p>
+
+ <p>The <code>Symbol</code> constructor is not intended to be used with the <code>new</code> operator or to be subclassed.
+ It may be used as the value of an <code>extends</code> clause of a class declaration but a <code>super</code> call to the
+ <code>Symbol</code> constructor will not initialize the state of subclass instances.</p>
+ </div>
+
+ <section id="sec-symbol-description">
+ <h1><span class="secnum" id="sec-19.4.1.1"><a href="#sec-symbol-description"
+ title="link to this section">19.4.1.1</a></span> Symbol ( [ description ] )</h1>
+
+ <p>When <code>Symbol</code> is called with optional argument <var>description</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>If <i>description</i> is <b>undefined</b>, then let <i>descString</i> be <b>undefined</b>.</li>
+ <li>Else, let <i>descString</i> be <a href="#sec-tostring">ToString</a>(<i>description</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>descString</i>).</li>
+ <li>Return a new unique Symbol value whose [[Description]] value is <i>descString</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-new-symbol-argumentslist">
+ <h1><span class="secnum" id="sec-19.4.1.2"><a href="#sec-new-symbol-argumentslist"
+ title="link to this section">19.4.1.2</a></span> new Symbol ( ...argumentsList )</h1>
+
+ <p>When <code>Symbol</code> is called as part of a new expression , it initializes a newly created object:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be the <code>Symbol</code> function object on which the <code>new</code> operator was applied.</li>
+ <li>Let <i>argumentsList</i> be the <i>argumentsList</i> argument of the [[Construct]] internal method that was invoked
+ by the <code>new</code> operator.</li>
+ <li>Return the result of <a href="#sec-construct-f-argumentslist">Construct</a> (<i>F</i>, <i>argumentsList</i>).</li>
+ </ol>
+
+ <p>If <code>Symbol</code> is implemented as an <a href="#sec-ecmascript-function-objects">ECMAScript function object</a>,
+ its [[Construct]] internal method will perform the above steps.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Symbol has ordinary [[Construct]] behaviour but the definition of its @@create method
+ causes <code>new Symbol</code> to throw a <b>TypeError</b> exception.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-symbol-constructor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-19.4.2"><a href="#sec-properties-of-the-symbol-constructor"
+ title="link to this section">19.4.2</a></span> Properties of the Symbol Constructor</h1>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the
+ Symbol constructor is the Function prototype object (<a
+ href="#sec-properties-of-the-function-prototype-object">19.2.3</a>).</p>
+
+ <p>Besides the <code>length</code> property (whose value is <b>1</b>), the Symbol constructor has the following
+ properties:</p>
+ </div>
+
+ <section id="sec-symbol.create">
+ <h1><span class="secnum" id="sec-19.4.2.1"><a href="#sec-symbol.create" title="link to this section">19.4.2.1</a></span>
+ Symbol.create</h1>
+
+ <p>The initial value of <code>Symbol.create</code> is the well known symbol @@create (<a href="#table-1">Table 1</a>).</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-symbol.for">
+ <h1><span class="secnum" id="sec-19.4.2.2"><a href="#sec-symbol.for" title="link to this section">19.4.2.2</a></span>
+ Symbol.for ( key )</h1>
+
+ <p>When <code>Symbol.for</code> is called with argument <var>key</var> it performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>stringKey</i> be <a href="#sec-tostring">ToString</a>(<i>key</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>stringKey)</i>.</li>
+ <li>For each element <i>e</i> of the GlobalSymbolRegistry <a href="#sec-list-and-record-specification-type">List</a>,
+ <ol class="block">
+ <li>If <a href="#sec-samevalue">SameValue</a>(<i>e</i>.[[key]], <i>stringKey</i>) is <b>true</b>, then return
+ <i>e</i>.[[symbol]].</li>
+ </ol>
+ </li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: GlobalSymbolRegistry does not currently contain an entry for
+ <i>stringKey</i>.</li>
+ <li>Let <i>newSymbol</i> be a new unique Symbol value whose [[Description]] is <i>stringKey</i>.</li>
+ <li>Append the record { [[key]]: <i>stringKey</i>, [[symbol]]: <i>newSymbol</i> } to the GlobalSymbolRegistry <a
+ href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Return <i>newSymbol</i>.</li>
+ </ol>
+
+ <p>The GlobalSymbolRegistry is a <a href="#sec-list-and-record-specification-type">List</a> that is globally available.
+ It is shared by all Code Realms. Prior to the evaluation of any ECMAScript code it is initialized as an empty <a
+ href="#sec-list-and-record-specification-type">List</a>. Elements of the GlobalSymbolRegistry are Records with the
+ structure defined in <a href="#table-39">Table 39</a>.</p>
+
+ <figure>
+ <figcaption><span id="table-39">Table 39</span> — GlobalSymbolRegistry Record Fields</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 0px solid black; border-top: 2px solid #000000">Field Name</th>
+ <th style="border-bottom: 1px solid #000000; border-left: 0px solid black; border-right: 1px solid #000000; border-top: 2px solid #000000">Value</th>
+ <th style="border-bottom: 1px solid #000000; border-right: 1px solid #000000; border-top: 2px solid #000000">Usage</th>
+ </tr>
+ <tr>
+ <td>[[key]]</td>
+ <td>A String</td>
+ <td>A string key used to globally identify a Symbol.</td>
+ </tr>
+ <tr>
+ <td>[[symbol]]</td>
+ <td>A Symbol</td>
+ <td>A symbol that can be retrieved from any <a href="#sec-code-realms">Realm</a>.</td>
+ </tr>
+ </table>
+ </figure>
+ </section>
+
+ <section id="sec-symbol.hasinstance">
+ <h1><span class="secnum" id="sec-19.4.2.3"><a href="#sec-symbol.hasinstance"
+ title="link to this section">19.4.2.3</a></span> Symbol.hasInstance</h1>
+
+ <p>The initial value of <code>Symbol.hasInstance</code> is the well known symbol @@hasInstance (<a href="#table-1">Table
+ 1</a>).</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-symbol.isconcatspreadable">
+ <h1><span class="secnum" id="sec-19.4.2.4"><a href="#sec-symbol.isconcatspreadable"
+ title="link to this section">19.4.2.4</a></span> Symbol.isConcatSpreadable</h1>
+
+ <p>The initial value of <code>Symbol.isConcatSpreadable</code> is the well known symbol @@isConcatSpreadable (<a
+ href="#table-1">Table 1</a>).</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-symbol.isregexp">
+ <h1><span class="secnum" id="sec-19.4.2.5"><a href="#sec-symbol.isregexp" title="link to this section">19.4.2.5</a></span>
+ Symbol.isRegExp</h1>
+
+ <p>The initial value of <code>Symbol.isRegExp</code> is the well known symbol @@isRegExp (<a href="#table-1">Table
+ 1</a>).</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-symbol.iterator">
+ <h1><span class="secnum" id="sec-19.4.2.6"><a href="#sec-symbol.iterator" title="link to this section">19.4.2.6</a></span>
+ Symbol.iterator</h1>
+
+ <p>The initial value of <code>Symbol.iterator</code> is the well known symbol @@iterator (<a href="#table-1">Table
+ 1</a>).</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-symbol.keyfor">
+ <h1><span class="secnum" id="sec-19.4.2.7"><a href="#sec-symbol.keyfor" title="link to this section">19.4.2.7</a></span>
+ Symbol.keyFor ( sym )</h1>
+
+ <p>When <code>Symbol.keyFor</code> is called with argument <var>sym</var> it performs the following steps:</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>sym</i>) is not Symbol, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>For each element <i>e</i> of the GlobalSymbolRegistry <a href="#sec-list-and-record-specification-type">List</a> (<a
+ href="#sec-symbol.for">see 19.4.2.2</a>),
+ <ol class="block">
+ <li>If <a href="#sec-samevalue">SameValue</a>(<i>e</i>.[[symbol]], <i>sym</i>) is <b>true</b>, then return
+ <i>e</i>.[[key]].</li>
+ </ol>
+ </li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: GlobalSymbolRegistry does not currently contain an entry for
+ <i>sym</i>.</li>
+ <li>Return <b>undefined</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-symbol.prototype">
+ <h1><span class="secnum" id="sec-19.4.2.8"><a href="#sec-symbol.prototype"
+ title="link to this section">19.4.2.8</a></span> Symbol.prototype</h1>
+
+ <p>The initial value of <code>Symbol.prototype</code> is the Symbol prototype object (<a
+ href="#sec-properties-of-the-symbol-prototype-object">19.4.3</a>).</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-symbol.toprimitive">
+ <h1><span class="secnum" id="sec-19.4.2.9"><a href="#sec-symbol.toprimitive"
+ title="link to this section">19.4.2.9</a></span> Symbol.toPrimitive</h1>
+
+ <p>The initial value of <code>Symbol.toPrimitive</code> is the well known symbol @@toPrimitive (<a href="#table-1">Table
+ 1</a>).</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-symbol.tostringtag">
+ <h1><span class="secnum" id="sec-19.4.2.10"><a href="#sec-symbol.tostringtag"
+ title="link to this section">19.4.2.10</a></span> Symbol.toStringTag</h1>
+
+ <p>The initial value of <code>Symbol.toStringTag</code> is the well known symbol @@toStringTag (<a href="#table-1">Table
+ 1</a>).</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-symbol.unscopables">
+ <h1><span class="secnum" id="sec-19.4.2.11"><a href="#sec-symbol.unscopables"
+ title="link to this section">19.4.2.11</a></span> Symbol.unscopables</h1>
+
+ <p>The initial value of <code>Symbol.</code>unscopables is the well known symbol @@unscopables (<a href="#table-1">Table
+ 1</a>).</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-symbol-@@create">
+ <h1><span class="secnum" id="sec-19.4.2.12"><a href="#sec-symbol-@@create"
+ title="link to this section">19.4.2.12</a></span> Symbol[ @@create ] ( )</h1>
+
+ <p>The @@create method of a Symbol object <var>F</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Throw a <b>TypeError</b> exception.</li>
+ </ol>
+
+ <p>The value of the <code>name</code> property of this function is <code>"[Symbol.create]"</code>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>true</b> }.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-symbol-prototype-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-19.4.3"><a href="#sec-properties-of-the-symbol-prototype-object"
+ title="link to this section">19.4.3</a></span> Properties of the Symbol Prototype Object</h1>
+
+ <p>The Symbol prototype object is an ordinary object. It is not a Symbol instance and does not have a [[SymbolData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</p>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the
+ Symbol prototype object is the standard built-in Object prototype object (<a
+ href="#sec-properties-of-the-object-prototype-object">19.1.3</a>).</p>
+ </div>
+
+ <section id="sec-symbol.prototype.constructor">
+ <h1><span class="secnum" id="sec-19.4.3.1"><a href="#sec-symbol.prototype.constructor"
+ title="link to this section">19.4.3.1</a></span> Symbol.prototype.constructor</h1>
+
+ <p>The initial value of <code>Symbol.prototype.constructor</code> is the built-in <code>Symbol</code> constructor.</p>
+ </section>
+
+ <section id="sec-symbol.prototype.tostring">
+ <h1><span class="secnum" id="sec-19.4.3.2"><a href="#sec-symbol.prototype.tostring"
+ title="link to this section">19.4.3.2</a></span> Symbol.prototype.toString ( )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>s</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>s</i>) is Symbol, then let <i>sym</i> be
+ <i>s</i>.</li>
+ <li>Else,
+ <ol class="block">
+ <li>If <i>s</i> does not have a [[SymbolData]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>sym</i> be the value of <i>s’s</i> [[SymbolData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ </ol>
+ </li>
+ <li>Let <i>desc</i> be the value of <i>sym’s</i> [[Description]] attribute.</li>
+ <li>If <i>desc</i> is <b>undefined</b>, then let <i>desc</i> be the empty string.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>desc</i>) is String.</li>
+ <li>Let <i>result</i> be the result of concatenating the strings <code>"Symbol("</code>, <i>desc</i>, and
+ <code>")"</code>.</li>
+ <li>Return <i>result</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-symbol.prototype.valueof">
+ <h1><span class="secnum" id="sec-19.4.3.3"><a href="#sec-symbol.prototype.valueof"
+ title="link to this section">19.4.3.3</a></span> Symbol.prototype.valueOf ( )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>s</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>s</i>) is Symbol, then return <i>s</i>.</li>
+ <li>If <i>s</i> does not have a [[SymbolData]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a>, then throw a <b>TypeError</b> exception.</li>
+ <li>Return the value of <i>s’s</i> [[SymbolData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-symbol.prototype-@@toprimitive">
+ <h1><span class="secnum" id="sec-19.4.3.4"><a href="#sec-symbol.prototype-@@toprimitive"
+ title="link to this section">19.4.3.4</a></span> Symbol.prototype [ @@toPrimitive ] ( hint )</h1>
+
+ <p>This function is called by ECMAScript language operators to convert an object to a primitive value. The allowed values
+ for <var>hint</var> are "<code>default</code>", "<code>number</code>", and "<code>string</code>". Implicit conversion of
+ Symbol objects to primitive values is not allowed.</p>
+
+ <p>When the <code>@@toPrimitive</code> method is called with argument <var>hint</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Throw a <b>TypeError</b> exception.</li>
+ </ol>
+
+ <p>The value of the <code>name</code> property of this function is <code>"[Symbol.toPrimitive]"</code>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <span class="value">false</span>, [[Enumerable]]: <span
+ class="value">false</span>, [[Configurable]]: <span class="value">true</span> }.</p>
+ </section>
+
+ <section id="sec-symbol.prototype-@@tostringtag">
+ <h1><span class="secnum" id="sec-19.4.3.5"><a href="#sec-symbol.prototype-@@tostringtag"
+ title="link to this section">19.4.3.5</a></span> Symbol.prototype [ @@toStringTag ]</h1>
+
+ <p>The initial value of the @@toStringTag property is the string value <b>"<code>Symbol</code>"</b>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <span class="value">false</span>, [[Enumerable]]: <span
+ class="value">false</span>, [[Configurable]]: <span class="value">true</span> }.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-symbol-instances">
+ <h1><span class="secnum" id="sec-19.4.4"><a href="#sec-properties-of-symbol-instances"
+ title="link to this section">19.4.4</a></span> Properties of Symbol Instances</h1>
+
+ <p>Symbol instances are ordinary objects that inherit properties from the Symbol prototype object. Symbol instances have a
+ [[SymbolData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>. The [[SymbolData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is the Symbol value represented by this Symbol
+ object.</p>
+ </section>
+ </section>
+
+ <section id="sec-error-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-19.5"><a href="#sec-error-objects" title="link to this section">19.5</a></span> Error
+ Objects</h1>
+
+ <p>Instances of Error objects are thrown as exceptions when runtime errors occur. The Error objects may also serve as base
+ objects for user-defined exception classes.</p>
+ </div>
+
+ <section id="sec-error-constructor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-19.5.1"><a href="#sec-error-constructor" title="link to this section">19.5.1</a></span>
+ The Error Constructor</h1>
+
+ <p>The Error constructor is the %Error% intrinsic object and the initial value of the <code>Error</code> property of the
+ global object. When <code>Error</code> is called as a function rather than as a constructor, it creates and initializes a
+ new Error object. Thus the function call <code><b>Error(</b>…<b>)</b></code> is equivalent to the object creation
+ expression <code><b>new Error(</b>…<b>)</b></code> with the same arguments. However, if the <b>this</b> value
+ passed in the call is an Object with an uninitialized [[ErrorData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, it initializes the <b>this</b> value using the
+ argument value rather than creating a new object. This permits <code>Error</code> to be used both as factory method and to
+ perform constructor instance initialization.</p>
+
+ <p>The <code>Error</code> constructor is designed to be subclassable. It may be used as the value of an
+ <code>extends</code> clause of a class declaration. Subclass constructors that intended to inherit the specified
+ <code>Error</code> behaviour should include a <code>super</code> call to the <code>Error</code> constructor to initialize
+ subclass instances.</p>
+ </div>
+
+ <section id="sec-error-message">
+ <h1><span class="secnum" id="sec-19.5.1.1"><a href="#sec-error-message" title="link to this section">19.5.1.1</a></span>
+ Error ( message )</h1>
+
+ <p>When the <code>Error</code> function is called with argument <i>message</i> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>func</i> be this <code>Error</code> function object.</li>
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object or <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is Object and <i>O</i> does not have an
+ [[ErrorData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> or <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is Object and <i>O</i> has an [[ErrorData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> and the value of [[ErrorData]] is not
+ <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>O</i> be the result of calling <a
+ href="#sec-ordinarycreatefromconstructor">OrdinaryCreateFromConstructor</a>(<i>func</i>,
+ <code>"%ErrorPrototype%"</code>,<br>( [[ErrorData]]) ).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>O</i>).</li>
+ </ol>
+ </li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>)
+ is Object.</li>
+ <li>Set the value of <i>O’s</i> [[ErrorData]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> to any value other than <b>undefined</b>.</li>
+ <li>If <i>message</i> is not <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>msg</i> be <a href="#sec-tostring">ToString</a>(<i>message</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>msg</i>).</li>
+ <li>Let <i>msgDesc</i> be the PropertyDescriptor{[[Value]]: <i>msg</i>, [[Writable]]: <b>true</b>, [[Enumerable]]:
+ <b>false</b>, [[Configurable]]: <b>true</b>}.</li>
+ <li>Let <i>status</i> be the result of <a href="#sec-definepropertyorthrow">DefinePropertyOrThrow</a>(<i>O</i>,
+ "<code>message</code>", <i>msgDesc</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ </ol>
+ </li>
+ <li>Return <i>O</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-new-error-argumentslist">
+ <h1><span class="secnum" id="sec-19.5.1.2"><a href="#sec-new-error-argumentslist"
+ title="link to this section">19.5.1.2</a></span> new Error ( ...argumentsList )</h1>
+
+ <p>When <code>Error</code> called as part of a new expression with argument list <i>argumentsList</i> it performs the
+ following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be the <code>Error</code> function object on which the <code>new</code> operator was applied.</li>
+ <li>Let <i>argumentsList</i> be the <i>argumentsList</i> argument of the [[Construct]] internal method that was invoked
+ by the <code>new</code> operator.</li>
+ <li>Return the result of <a href="#sec-construct-f-argumentslist">Construct</a> (<i>F</i>, <i>argumentsList</i>).</li>
+ </ol>
+
+ <p>If <code>Error</code> is implemented as an <a href="#sec-ecmascript-function-objects">ECMAScript function object</a>,
+ its [[Construct]] internal method will perform the above steps.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-error-constructor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-19.5.2"><a href="#sec-properties-of-the-error-constructor"
+ title="link to this section">19.5.2</a></span> Properties of the Error Constructor</h1>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the Error
+ constructor is the Function prototype object (<a href="#sec-properties-of-the-function-prototype-object">19.2.3</a>).</p>
+
+ <p>Besides the <code>length</code> property (whose value is <b>1</b>), the Error constructor has the following
+ properties:</p>
+ </div>
+
+ <section id="sec-error.prototype">
+ <h1><span class="secnum" id="sec-19.5.2.1"><a href="#sec-error.prototype" title="link to this section">19.5.2.1</a></span>
+ Error.prototype</h1>
+
+ <p>The initial value of <code>Error.prototype</code> is the Error prototype object (<a
+ href="#sec-properties-of-the-error-prototype-object">19.5.3</a>).</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-error-@@create">
+ <h1><span class="secnum" id="sec-19.5.2.2"><a href="#sec-error-@@create" title="link to this section">19.5.2.2</a></span>
+ Error[ @@create ] ( )</h1>
+
+ <p>The @@create method of an object <var>F</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be the <b>this</b> value.</li>
+ <li>Let <i>obj</i> be the result of calling <a
+ href="#sec-ordinarycreatefromconstructor">OrdinaryCreateFromConstructor</a>(<i>F</i>,
+ <code>"%ErrorPrototype%"</code>, ( [[ErrorData]]) ).</li>
+ <li>Return <i>obj</i>.</li>
+ </ol>
+
+ <p>The value of the <code>name</code> property of this function is <code>"[Symbol.create]"</code>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <span class="value">false</span>, [[Enumerable]]: <span
+ class="value">false</span>, [[Configurable]]: <span class="value">true</span> }.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> [[ErrorData]] is initially assigned the value <b>undefined</b> as a flag to indicate
+ that the instance has not yet been initialized by the Error constructor. This flag value is never directly exposed to
+ ECMAScript code; hence implementations may choose to encode the flag in some other manner.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-error-prototype-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-19.5.3"><a href="#sec-properties-of-the-error-prototype-object"
+ title="link to this section">19.5.3</a></span> Properties of the Error Prototype Object</h1>
+
+ <p>The Error prototype object is an ordinary object. It is not an Error instance and does not have an [[ErrorData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</p>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the Error
+ prototype object is the standard built-in Object prototype object (<a
+ href="#sec-properties-of-the-object-prototype-object">19.1.3</a>).</p>
+ </div>
+
+ <section id="sec-error.prototype.constructor">
+ <h1><span class="secnum" id="sec-19.5.3.1"><a href="#sec-error.prototype.constructor"
+ title="link to this section">19.5.3.1</a></span> Error.prototype.constructor</h1>
+
+ <p>The initial value of <code>Error.prototype.constructor</code> is the built-in <code>Error</code> constructor.</p>
+ </section>
+
+ <section id="sec-error.prototype.message">
+ <h1><span class="secnum" id="sec-19.5.3.2"><a href="#sec-error.prototype.message"
+ title="link to this section">19.5.3.2</a></span> Error.prototype.message</h1>
+
+ <p>The initial value of <code>Error.prototype.message</code> is the empty String.</p>
+ </section>
+
+ <section id="sec-error.prototype.name">
+ <h1><span class="secnum" id="sec-19.5.3.3"><a href="#sec-error.prototype.name"
+ title="link to this section">19.5.3.3</a></span> Error.prototype.name</h1>
+
+ <p>The initial value of <code>Error.prototype.name</code> is <code>"<b>Error</b>"</code>.</p>
+ </section>
+
+ <section id="sec-error.prototype.tostring">
+ <h1><span class="secnum" id="sec-19.5.3.4"><a href="#sec-error.prototype.tostring"
+ title="link to this section">19.5.3.4</a></span> Error.prototype.toString ( )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object, throw a <b>TypeError</b>
+ exception.</li>
+ <li>Let <i>name</i> be the result of <a href="#sec-get-o-p">Get</a>(<i>O</i>, <code>"name"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>name</i>).</li>
+ <li>If <i>name</i> is <b>undefined</b>, then let <i>name</i> be <code>"<b>Error</b>"</code>; else let <i>name</i> be <a
+ href="#sec-tostring">ToString</a>(<i>name</i>).</li>
+ <li>Let <i>msg</i> be the result of <a href="#sec-get-o-p">Get</a>(<i>O</i>, <code>"message"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>msg</i>).</li>
+ <li>If <i>msg</i> is <b>undefined</b>, then let <i>msg</i> be the empty String; else let <i>msg</i> be <a
+ href="#sec-tostring">ToString</a>(<i>msg</i>).</li>
+ <li>If <i>name</i> is the empty String, return <i>msg</i><code>.</code></li>
+ <li>If <i>msg</i> is the empty String, return <i>name</i><code>.</code></li>
+ <li>Return the result of concatenating <i>name</i>, <code>":"</code>, a single space character, and <i>msg</i>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-error-instances">
+ <h1><span class="secnum" id="sec-19.5.4"><a href="#sec-properties-of-error-instances"
+ title="link to this section">19.5.4</a></span> Properties of Error Instances</h1>
+
+ <p>Error instances are ordinary objects that inherit properties from the Error prototype object and have an [[ErrorData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> whose initial value is <span
+ class="value">undefined</span>. The only specified uses of [[ErrorData]] is to flag whether or not an Error instance has
+ been initialized by the Error constructor and to identify them as Error objects within <code><a
+ href="#sec-object.prototype.tostring">Object.prototype.toString</a></code>.</p>
+ </section>
+
+ <section id="sec-native-error-types-used-in-this-standard">
+ <div class="front">
+ <h1><span class="secnum" id="sec-19.5.5"><a href="#sec-native-error-types-used-in-this-standard"
+ title="link to this section">19.5.5</a></span> Native Error Types Used in This Standard</h1>
+
+ <p>A new instance of one of the <i>NativeError</i> objects below is thrown when a runtime error is detected. All of these
+ objects share the same structure, as described in <a href="#sec-nativeerror-object-structure">19.5.6</a>.</p>
+ </div>
+
+ <section id="sec-native-error-types-used-in-this-standard-evalerror">
+ <h1><span class="secnum" id="sec-19.5.5.1"><a href="#sec-native-error-types-used-in-this-standard-evalerror"
+ title="link to this section">19.5.5.1</a></span> EvalError</h1>
+
+ <p>This exception is not currently used within this specification. This object remains for compatibility with previous
+ editions of this specification.</p>
+ </section>
+
+ <section id="sec-native-error-types-used-in-this-standard-rangeerror">
+ <h1><span class="secnum" id="sec-19.5.5.2"><a href="#sec-native-error-types-used-in-this-standard-rangeerror"
+ title="link to this section">19.5.5.2</a></span> RangeError</h1>
+
+ <p>Indicates a value that is not in the set or range of allowable values. See 15.4.2.2, 15.4.5.1, 15.7.4.2, 15.7.4.5,
+ 15.7.4.6, 15.7.4.7, and 15.9.5.43.</p>
+ </section>
+
+ <section id="sec-native-error-types-used-in-this-standard-referenceerror">
+ <h1><span class="secnum" id="sec-19.5.5.3"><a href="#sec-native-error-types-used-in-this-standard-referenceerror"
+ title="link to this section">19.5.5.3</a></span> ReferenceError</h1>
+
+ <p>Indicate that an invalid reference value has been detected. See 8.9.1, 8.9.2, <a
+ href="#sec-strict-mode-code">10.2.1</a>, 10.2.1.1.4, 10.2.1.2.4, and 11.13.1.</p>
+ </section>
+
+ <section id="sec-native-error-types-used-in-this-standard-syntaxerror">
+ <h1><span class="secnum" id="sec-19.5.5.4"><a href="#sec-native-error-types-used-in-this-standard-syntaxerror"
+ title="link to this section">19.5.5.4</a></span> SyntaxError</h1>
+
+ <p>Indicates that a parsing error has occurred. See 11.1.5, 11.3.1, 11.3.2, 11.4.1, 11.4.4, 11.4.5, 11.13.1, 11.13.2, <a
+ href="#sec-this-keyword">12.2.1</a>, <a href="#sec-equality-operators-static-semantics-isfunctiondefinition">12.10.1</a>,
+ <a href="#sec-assignment-operators-static-semantics-early-errors">12.14.1</a>, <a href="#sec-block">13.1</a>, 15.1.2.1,
+ 15.3.2.1, 15.10.2.2, 15.10.2.5, 15.10.2.9, 15.10.2.15, 15.10.2.19, 15.10.4.1, and 15.12.2.</p>
+ </section>
+
+ <section id="sec-native-error-types-used-in-this-standard-typeerror">
+ <h1><span class="secnum" id="sec-19.5.5.5"><a href="#sec-native-error-types-used-in-this-standard-typeerror"
+ title="link to this section">19.5.5.5</a></span> TypeError</h1>
+
+ <p>Indicates the actual type of an operand is different than the expected type. See 8.6.2, 8.9.2, 8.10.5, 8.12.5, 8.12.7,
+ 8.12.8, 8.12.9, 9.9, 9.10, <a href="#sec-strict-mode-code">10.2.1</a>, 10.2.1.1.3, 10.6, 11.2.2, 11.2.3, 11.4.1, <a
+ href="#sec-template-literal-lexical-components">11.8.6</a>, 11.8.7, 11.3.1, <a
+ href="#sec-declarations-and-the-variable-statement">13.2</a>, <a href="#sec-destructuring-binding-patterns">13.2.3</a>,
+ 15, <a href="#sec-load-records-and-loadrequest-objects">15.2.3.2</a>, 15.2.3.3, 15.2.3.4, 15.2.3.5, 15.2.3.6, 15.2.3.7,
+ 15.2.3.8, 15.2.3.9, 15.2.3.10, 15.2.3.11, 15.2.3.12, 15.2.3.13, 15.2.3.14, <a href="#sec-proceedtolocate">15.2.4.3</a>,
+ 15.3.3.2, 15.3.3.3, 15.3.3.4, 15.3.3.5, 15.3.3.5.2, 15.3.3.5.3, 15.3.4, 15.3.4.3, 15.3.4.4, 15.4.3.3, 15.4.3.11,
+ 15.4.3.16, 15.4.3.17, 15.4.3.18, 15.4.3.19, 15.4.3.20, 15.4.3.21, 15.4.3.22, 15.4.5.1, 15.5.4.2, 15.5.4.3, 15.6.4.2,
+ 15.6.4.3, 15.7.4, 15.7.4.2, 15.7.4.4, 15.9.5, 15.9.5.44, 15.10.4.1, 15.10.6, 15.11.4.4 and 15.12.3.</p>
+ </section>
+
+ <section id="sec-native-error-types-used-in-this-standard-urierror">
+ <h1><span class="secnum" id="sec-19.5.5.6"><a href="#sec-native-error-types-used-in-this-standard-urierror"
+ title="link to this section">19.5.5.6</a></span> URIError</h1>
+
+ <p>Indicates that one of the global URI handling functions was used in a way that is incompatible with its definition. See
+ <a href="#sec-scripts-static-semantics-lexicallydeclarednames">15.1.3</a>.</p>
+ </section>
+ </section>
+
+ <section id="sec-nativeerror-object-structure">
+ <div class="front">
+ <h1><span class="secnum" id="sec-19.5.6"><a href="#sec-nativeerror-object-structure"
+ title="link to this section">19.5.6</a></span> <i>NativeError</i> Object Structure</h1>
+
+ <p>When an ECMAScript implementation detects a runtime error, it throws a new instance of one of the <i>NativeError</i>
+ objects defined in <a href="#sec-native-error-types-used-in-this-standard">19.5.5</a>. Each of these objects has the
+ structure described below, differing only in the name used as the constructor name instead of <i>NativeError</i>, in the
+ <b>name</b> property of the prototype object, and in the implementation-defined <code>message</code> property of the
+ prototype object.</p>
+
+ <p>For each error object, references to <i>NativeError</i> in the definition should be replaced with the appropriate error
+ object name from <a href="#sec-native-error-types-used-in-this-standard">19.5.5</a>.</p>
+ </div>
+
+ <section id="sec-nativeerror-constructors">
+ <div class="front">
+ <h1><span class="secnum" id="sec-19.5.6.1"><a href="#sec-nativeerror-constructors"
+ title="link to this section">19.5.6.1</a></span> <i>NativeError</i> Constructors</h1>
+
+ <p>When a <i>NativeError</i> constructor is called as a function rather than as a constructor, it creates and
+ initializes a new object. A call of the object as a function is equivalent to calling it as a constructor with the same
+ arguments. However, if the <b>this</b> value passed in the call is an Object with an uninitialized [[ErrorData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, it initializes the <b>this</b> value using the
+ argument value. This permits a <i>NativeError</i> to be used both as factory method and to perform constructor instance
+ initialization.</p>
+
+ <p>The <i>NativeError</i> constructor is designed to be subclassable. It may be used as the value of an
+ <code>extends</code> clause of a class declaration. Subclass constructors that intended to inherit the specified
+ <i>NativeError</i> behaviour should include a <code>super</code> call to the <i>NativeError</i> constructor to
+ initialize subclass instances.</p>
+ </div>
+
+ <section id="sec-nativeerror">
+ <h1><span class="secnum" id="sec-19.5.6.1.1"><a href="#sec-nativeerror"
+ title="link to this section">19.5.6.1.1</a></span> NativeError ( message )</h1>
+
+ <p>When a <i>NativeError</i> function is called with argument <i>message</i> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>func</i> be this <i>NativeError</i> function object.</li>
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object or <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is Object and <i>O</i> does not have an
+ [[ErrorData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> or <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is Object and <i>O</i> has an [[ErrorData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> and the value of [[ErrorData]] is not
+ <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>O</i> be the result of calling <a
+ href="#sec-ordinarycreatefromconstructor">OrdinaryCreateFromConstructor</a>(<i>func</i>,
+ <code>"%<i>NativeError</i>Prototype%"</code>, ( [[ErrorData]]) ).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>O</i>).</li>
+ </ol>
+ </li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is Object.</li>
+ <li>Set the value of <i>O’s</i> [[ErrorData]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> to any value other than <b>undefined</b>.</li>
+ <li>If <i>message</i> is not <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>msg</i> be <a href="#sec-tostring">ToString</a>(<i>message</i>).</li>
+ <li>Let <i>msgDesc</i> be the PropertyDescriptor{[[Value]]: <i>msg</i>, [[Writable]]: <b>true</b>, [[Enumerable]]:
+ <b>false</b>, [[Configurable]]: <b>true</b>}.</li>
+ <li>Let <i>status</i> be the result of <a href="#sec-definepropertyorthrow">DefinePropertyOrThrow</a>(<i>O</i>,
+ "<code>message</code>", <i>msgDesc</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ </ol>
+ </li>
+ <li>Return <i>O</i>.</li>
+ </ol>
+
+ <p>The actual value of the string passed in step 3.a is either <code>"%EvalErrorPrototype%"</code>,
+ <code>"%RangeErrorPrototype%"</code>, <code>"%ReferenceErrorPrototype%"</code>, <code>"%SyntaxErrorPrototype%"</code>,
+ <code>"%TypeErrorPrototype%"</code>, or <code>"%URIErrorPrototype%"</code> corresponding to which <i>NativeError</i>
+ constructor is being defined.</p>
+ </section>
+
+ <section id="sec-new-nativeerror-argumentslist">
+ <h1><span class="secnum" id="sec-19.5.6.1.2"><a href="#sec-new-nativeerror-argumentslist"
+ title="link to this section">19.5.6.1.2</a></span> new <i>NativeError</i> ( ...argumentsList )</h1>
+
+ <p>When a <i>NativeError</i> constructor is called as part of a new expression with argument list <i>argumentsList</i>
+ it performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be this <i>NativeError</i> function object on which the <code>new</code> operator was applied.</li>
+ <li>Let <i>argumentsList</i> be the <i>argumentsList</i> argument of the [[Construct]] internal method that was
+ invoked by the <code>new</code> operator.</li>
+ <li>Return the result of <a href="#sec-construct-f-argumentslist">Construct</a> (<i>F</i>, <i>argumentsList</i>).</li>
+ </ol>
+
+ <p>If a <i>NativeError</i> constructor is implemented as an <a href="#sec-ecmascript-function-objects">ECMAScript
+ function object</a>, its [[Construct]] internal method will perform the above steps.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-nativeerror-constructors">
+ <div class="front">
+ <h1><span class="secnum" id="sec-19.5.6.2"><a href="#sec-properties-of-the-nativeerror-constructors"
+ title="link to this section">19.5.6.2</a></span> Properties of the <i>NativeError</i> Constructors</h1>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of a
+ <i>NativeError</i> constructor is the Error constructor object (<a href="#sec-error-constructor">19.5.1</a>).</p>
+
+ <p>Besides the <code>length</code> property (whose value is <b>1</b>), each <i>NativeError</i> constructor has the
+ following properties:</p>
+ </div>
+
+ <section id="sec-nativeerror.prototype">
+ <h1><span class="secnum" id="sec-19.5.6.2.1"><a href="#sec-nativeerror.prototype"
+ title="link to this section">19.5.6.2.1</a></span> NativeError.prototype</h1>
+
+ <p>The initial value of <b><i>NativeError</i><code>.prototype</code></b> is a <i>NativeError</i> prototype object (<a
+ href="#sec-properties-of-the-nativeerror-prototype-objects">19.5.6.3</a>). Each <i>NativeError</i> constructor has a
+ separate prototype object.</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-nativeerror-@@create">
+ <h1><span class="secnum" id="sec-19.5.6.2.2"><a href="#sec-nativeerror-@@create"
+ title="link to this section">19.5.6.2.2</a></span> <i>NativeError</i> [ @@create ] ( )</h1>
+
+ <p>The @@create method of an object <var>F</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be the <b>this</b> value.</li>
+ <li>Let <i>obj</i> be <a href="#sec-ordinarycreatefromconstructor">OrdinaryCreateFromConstructor</a>(<i>F</i>,
+ <i>NativeErrorPrototype</i>, ([[ErrorData]]) ).</li>
+ <li>Return <i>obj</i>.</li>
+ </ol>
+
+ <p>The actual value passed as <span class="nt">NativeErrorPrototype</span> in step 2 is either
+ <code>"%EvalErrorPrototype%"</code>, <code>"%RangeErrorPrototype%"</code>, <code>"%ReferenceErrorPrototype%"</code>,
+ <code>"%SyntaxErrorPrototype%"</code>, <code>"%TypeErrorPrototype%"</code>, or <code>"%URIErrorPrototype%"</code>
+ corresponding to which <i>NativeError</i> constructor is being defined.</p>
+
+ <p>The value of the <code>name</code> property of this function is <code>"[Symbol.create]"</code>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <span class="value">false</span>, [[Enumerable]]: <span
+ class="value">false</span>, [[Configurable]]: <span class="value">true</span> }.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> [[ErrorData]] is initially assigned the value <b>undefined</b> as a flag to indicate
+ that the instance has not yet been initialized by the <i>NativeError</i> constructor. This flag value is never
+ directly exposed to ECMAScript code; hence implementations may choose to encode the flag in some other manner.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-nativeerror-prototype-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-19.5.6.3"><a href="#sec-properties-of-the-nativeerror-prototype-objects"
+ title="link to this section">19.5.6.3</a></span> Properties of the <i>NativeError</i> Prototype Objects</h1>
+
+ <p>Each <i>NativeError</i> prototype object is an ordinary object. It is not an Error instance and does not have an
+ [[ErrorData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</p>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of each
+ <i>NativeError</i> prototype object is the standard built-in Error prototype object (<a
+ href="#sec-properties-of-the-error-prototype-object">19.5.3</a>).</p>
+ </div>
+
+ <section id="sec-nativeerror.prototype.constructor">
+ <h1><span class="secnum" id="sec-19.5.6.3.1"><a href="#sec-nativeerror.prototype.constructor"
+ title="link to this section">19.5.6.3.1</a></span> <i>NativeError</i>.prototype.constructor</h1>
+
+ <p>The initial value of the <code>constructor</code> property of the prototype for a given <i>NativeError</i>
+ constructor is the <i>NativeError</i> constructor function itself (<a
+ href="#sec-nativeerror-constructors">19.5.6.1</a>).</p>
+ </section>
+
+ <section id="sec-nativeerror.prototype.message">
+ <h1><span class="secnum" id="sec-19.5.6.3.2"><a href="#sec-nativeerror.prototype.message"
+ title="link to this section">19.5.6.3.2</a></span> <i>NativeError</i>.prototype.message</h1>
+
+ <p>The initial value of the <code>message</code> property of the prototype for a given <i>NativeError</i> constructor is
+ the empty String.</p>
+ </section>
+
+ <section id="sec-nativeerror.prototype.name">
+ <h1><span class="secnum" id="sec-19.5.6.3.3"><a href="#sec-nativeerror.prototype.name"
+ title="link to this section">19.5.6.3.3</a></span> <i>NativeError</i>.prototype.name</h1>
+
+ <p>The initial value of the <code>name</code> property of the prototype for a given <i>NativeError</i> constructor is a
+ string consisting of the name of the constructor (the name used instead of <i>NativeError</i>).</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-nativeerror-instances">
+ <h1><span class="secnum" id="sec-19.5.6.4"><a href="#sec-properties-of-nativeerror-instances"
+ title="link to this section">19.5.6.4</a></span> Properties of <i>NativeError</i> Instances</h1>
+
+ <p><i>NativeError</i> instances are ordinary objects that inherit properties from their <i>NativeError</i> prototype
+ object and have an [[ErrorData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> whose initial
+ value is <span class="value">undefined</span>. The only specified use of [[ErrorData]] is to flag whether or not an Error
+ or <i>NativeError</i> instance has been initialized by its constructor.</p>
+ </section>
+ </section>
+ </section>
+</section>
+
+<section id="sec-numbers-and-dates">
+ <div class="front">
+ <h1><span class="secnum" id="sec-20"><a href="#sec-numbers-and-dates" title="link to this section">20</a></span> Numbers and
+ Dates</h1>
+ </div>
+
+ <section id="sec-number-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-20.1"><a href="#sec-number-objects" title="link to this section">20.1</a></span> Number
+ Objects</h1>
+ </div>
+
+ <section id="sec-number-constructor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-20.1.1"><a href="#sec-number-constructor" title="link to this section">20.1.1</a></span>
+ The Number Constructor</h1>
+
+ <p>The Number constructor is the %Number% intrinsic object and the initial value of the <code>Number</code> property of
+ the global object. When <code>Number</code> is called as a function rather than as a constructor, it performs a type
+ conversion. However, if the <b>this</b> value passed in the call is an Object with an uninitialized [[NumberData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, it initializes the <b>this</b> value using the
+ argument value. This permits <code>Number</code> to be used both to perform type conversion and to perform constructor
+ instance initialization.</p>
+
+ <p>The <code>Number</code> constructor is designed to be subclassable. It may be used as the value of an
+ <code>extends</code> clause of a class declaration. Subclass constructors that intended to inherit the specified
+ <code>Number</code> behaviour must include a <code>super</code> call to the <code>Number</code> constructor to initialize
+ the [[NumberData]] state of subclass instances.</p>
+ </div>
+
+ <section id="sec-number-constructor-number-value">
+ <h1><span class="secnum" id="sec-20.1.1.1"><a href="#sec-number-constructor-number-value"
+ title="link to this section">20.1.1.1</a></span> Number ( [ value ] )</h1>
+
+ <p>When <code>Number</code> is called with argument <var>number</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>If no arguments were passed to this function invocation, then let <i>n</i> be +0.</li>
+ <li>Else, let <i>n</i> be <a href="#sec-tonumber">ToNumber</a>(<i>value</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>n</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is Object and <i>O</i> has a [[NumberData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> and the value of [[NumberData]] is
+ <b>undefined</b>, then
+ <ol class="block">
+ <li>Set the value of <i>O’s</i> [[NumberData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to <i>n</i>.</li>
+ <li>Return <i>O</i>.</li>
+ </ol>
+ </li>
+ <li>Return <i>n</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-new-number-argumentslist">
+ <h1><span class="secnum" id="sec-20.1.1.2"><a href="#sec-new-number-argumentslist"
+ title="link to this section">20.1.1.2</a></span> new Number ( ...argumentsList )</h1>
+
+ <p>When <code>Number</code> is called as part of a new expression with argument list <i>argumentsList</i>it performs the
+ following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be the <code>Number</code> function object on which the <code>new</code> operator was applied.</li>
+ <li>Let <i>argumentsList</i> be the <i>argumentsList</i> argument of the [[Construct]] internal method that was invoked
+ by the <code>new</code> operator.</li>
+ <li>Return <a href="#sec-construct-f-argumentslist">Construct</a> (<i>F</i>, <i>argumentsList</i>).</li>
+ </ol>
+
+ <p>If <code>Number</code> is implemented as an <a href="#sec-ecmascript-function-objects">ECMAScript function object</a>,
+ its [[Construct]] internal method will perform the above steps.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-number-constructor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-20.1.2"><a href="#sec-properties-of-the-number-constructor"
+ title="link to this section">20.1.2</a></span> Properties of the Number Constructor</h1>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the
+ Number constructor is the Function prototype object (<a
+ href="#sec-properties-of-the-function-prototype-object">19.2.3</a>).</p>
+
+ <p>Besides the <code>length</code> property (whose value is <b>1</b>), the Number constructor has the following
+ properties:</p>
+ </div>
+
+ <section id="sec-number.epsilon">
+ <h1><span class="secnum" id="sec-20.1.2.1"><a href="#sec-number.epsilon" title="link to this section">20.1.2.1</a></span>
+ Number.EPSILON</h1>
+
+ <p>The value of Number.EPSILON is the difference between 1 and the smallest value greater than 1 that is representable as
+ a Number value, which is approximately 2.2204460492503130808472633361816 x 10‍<sup>−‍16</sup>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-number.isfinite">
+ <h1><span class="secnum" id="sec-20.1.2.2"><a href="#sec-number.isfinite" title="link to this section">20.1.2.2</a></span>
+ Number.isFinite ( number )</h1>
+
+ <p>When the <code>Number.isFinite</code> is called with one argument <var>number</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>number</i>) is not Number, return <b>false</b>.</li>
+ <li>If <i>number</i> is <b>NaN</b>, <b>+∞</b>, or <b>−∞</b>, return <b>false</b>.</li>
+ <li>Otherwise, return <b>true</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-number.isinteger">
+ <h1><span class="secnum" id="sec-20.1.2.3"><a href="#sec-number.isinteger"
+ title="link to this section">20.1.2.3</a></span> Number.isInteger ( number )</h1>
+
+ <p>When the <code>Number.isInteger</code> is called with one argument <var>number</var>, the following steps are
+ taken:</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>number</i>) is not Number, return <b>false</b>.</li>
+ <li>If <i>number</i> is <b>NaN</b>, <b>+∞</b>, or <b>−∞</b>, return <b>false</b>.</li>
+ <li>Let <i>integer</i> be <a href="#sec-tointeger">ToInteger</a>(<i>number</i>).</li>
+ <li>If <i>integer</i> is not equal to <i>number</i>, return <b>false</b>.</li>
+ <li>Otherwise, return <b>true</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-number.isnan">
+ <h1><span class="secnum" id="sec-20.1.2.4"><a href="#sec-number.isnan" title="link to this section">20.1.2.4</a></span>
+ Number.isNaN ( number )</h1>
+
+ <p>When the <code>Number.isNaN</code> is called with one argument <var>number</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>number</i>) is not Number, return <b>false</b>.</li>
+ <li>If <i>number</i> is <b>NaN</b>, return <b>true</b>.</li>
+ <li>Otherwise, return <b>false</b>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> This function differs from the global isNaN function (<a
+ href="#sec-isnan-number">18.2.3</a>) is that it does not convert its argument to a Number before determining whether it
+ is NaN.</p>
+ </div>
+ </section>
+
+ <section id="sec-number.issafeinteger">
+ <h1><span class="secnum" id="sec-20.1.2.5"><a href="#sec-number.issafeinteger"
+ title="link to this section">20.1.2.5</a></span> Number.isSafeInteger ( number )</h1>
+
+ <p>When the <code>Number.isSafeInteger</code> is called with one argument <var>number</var>, the following steps are
+ taken:</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>number</i>) is not Number, return <b>false</b>.</li>
+ <li>If <i>number</i> is <b>NaN</b>, <b>+∞</b>, or <b>−∞</b>, return <b>false</b>.</li>
+ <li>Let <i>integer</i> be <a href="#sec-tointeger">ToInteger</a>(<i>number</i>).</li>
+ <li>If <i>integer</i> is not equal to <i>number</i>, return <b>false</b>.</li>
+ <li>If <a href="#sec-algorithm-conventions">abs</a>(<i>integer</i>) ≤ 2<sup>53</sup>−1, then return
+ <b>true</b>.</li>
+ <li>Otherwise, return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-number.max_safe_integer">
+ <h1><span class="secnum" id="sec-20.1.2.6"><a href="#sec-number.max_safe_integer"
+ title="link to this section">20.1.2.6</a></span> Number.MAX_SAFE_INTEGER</h1>
+
+ <p>The value of Number.MAX_SAFE_INTEGER is 9007199254740991 (2<sup>53</sup>−1).</p>
+
+ <p><br>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-number.max_value">
+ <h1><span class="secnum" id="sec-20.1.2.7"><a href="#sec-number.max_value"
+ title="link to this section">20.1.2.7</a></span> Number.MAX_VALUE</h1>
+
+ <p>The value of <code>Number.MAX_VALUE</code> is the largest positive finite value of the Number type, which is
+ approximately <span style="font-family: Times New Roman">1.7976931348623157 × 10<sup>308</sup></span>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-number.nan">
+ <h1><span class="secnum" id="sec-20.1.2.8"><a href="#sec-number.nan" title="link to this section">20.1.2.8</a></span>
+ Number.NaN</h1>
+
+ <p>The value of <code>Number.NaN</code> is <b>NaN</b>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-number.negative_infinity">
+ <h1><span class="secnum" id="sec-20.1.2.9"><a href="#sec-number.negative_infinity"
+ title="link to this section">20.1.2.9</a></span> Number.NEGATIVE_INFINITY</h1>
+
+ <p>The value of Number.NEGATIVE_INFINITY is −∞.</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-number.min_safe_integer">
+ <h1><span class="secnum" id="sec-20.1.2.10"><a href="#sec-number.min_safe_integer"
+ title="link to this section">20.1.2.10</a></span> Number.MIN_SAFE_INTEGER</h1>
+
+ <p>The value of Number.MIN_SAFE_INTEGER is −9007199254740991 (−(2<sup>53</sup>−1)).</p>
+
+ <p><br>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-number.min_value">
+ <h1><span class="secnum" id="sec-20.1.2.11"><a href="#sec-number.min_value"
+ title="link to this section">20.1.2.11</a></span> Number.MIN_VALUE</h1>
+
+ <p>The value of <code>Number.MIN_VALUE</code> is the smallest positive value of the Number type, which is approximately
+ <span style="font-family: Times New Roman">5 × 10<sup>−324</sup></span>.</p>
+
+ <p>In the IEEE-764 double precision binary representation, the smallest possible value is a denormalized number. If an
+ implementation does not support denormalized values, the value of <code>Number.MIN_VALUE</code> must be the smallest
+ non-zero positive value that can actually be represented by the implementation.</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-number.parsefloat">
+ <h1><span class="secnum" id="sec-20.1.2.12"><a href="#sec-number.parsefloat"
+ title="link to this section">20.1.2.12</a></span> Number.parseFloat ( string )</h1>
+
+ <p>The value of the <code>Number.parseFloat</code> data property is the same built-in function object that is the value of
+ the <code>parseFloat</code> property of the global object defined in <a href="#sec-parsefloat-string">18.2.4</a>.</p>
+ </section>
+
+ <section id="sec-number.parseint">
+ <h1><span class="secnum" id="sec-20.1.2.13"><a href="#sec-number.parseint"
+ title="link to this section">20.1.2.13</a></span> Number.parseInt ( string, radix )</h1>
+
+ <p>The value of the <code>Number.parseInt</code> data property is the same built-in function object that is the value of
+ the <code>parseInt</code> property of the global object defined in <a href="#sec-parseint-string-radix">18.2.5</a>.</p>
+ </section>
+
+ <section id="sec-number.positive_infinity">
+ <h1><span class="secnum" id="sec-20.1.2.14"><a href="#sec-number.positive_infinity"
+ title="link to this section">20.1.2.14</a></span> Number.POSITIVE_INFINITY</h1>
+
+ <p>The value of Number.POSITIVE_INFINITY is +∞.</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-number.prototype">
+ <h1><span class="secnum" id="sec-20.1.2.15"><a href="#sec-number.prototype"
+ title="link to this section">20.1.2.15</a></span> Number.prototype</h1>
+
+ <p>The initial value of <code>Number.prototype</code> is the Number prototype object (<a
+ href="#sec-properties-of-the-number-prototype-object">20.1.3</a>).</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-number-@@create">
+ <h1><span class="secnum" id="sec-20.1.2.16"><a href="#sec-number-@@create"
+ title="link to this section">20.1.2.16</a></span> Number[ @@create ] ( )</h1>
+
+ <p>The @@create method of an object <var>F</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be the <b>this</b> value.</li>
+ <li>Let <i>obj</i> be <a href="#sec-ordinarycreatefromconstructor">OrdinaryCreateFromConstructor</a>(<i>F</i>,
+ <code>"%NumberPrototype%"</code>, ( [[NumberData]])).</li>
+ <li>Return <i>obj</i>.</li>
+ </ol>
+
+ <p>The value of the <code>name</code> property of this function is <code>"[Symbol.create]"</code>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <span class="value">false</span>, [[Enumerable]]: <span
+ class="value">false</span>, [[Configurable]]: <span class="value">true</span> }.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> [[NumberData]] is initially assigned the value <b>undefined</b> as a flag to indicate
+ that the instance has not yet been initialized by the Number constructor. This flag value is never directly exposed to
+ ECMAScript code; hence implementations may choose to encode the flag in some other manner.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-number-prototype-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-20.1.3"><a href="#sec-properties-of-the-number-prototype-object"
+ title="link to this section">20.1.3</a></span> Properties of the Number Prototype Object</h1>
+
+ <p>The Number prototype object is an ordinary object. It is not a Number instance and does not have a [[NumberData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</p>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the
+ Number prototype object is the standard built-in Object prototype object (<a
+ href="#sec-properties-of-the-object-prototype-object">19.1.3</a>).</p>
+
+ <p>Unless explicitly stated otherwise, the methods of the Number prototype object defined below are not generic and the
+ <b>this</b> value passed to them must be either a Number value or an object that has a [[NumberData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> that has been initialized to a Number value.</p>
+
+ <p>The abstract operation <span style="font-family: Times New Roman">thisNumberValue(<i>value</i>)</span> performs the
+ following steps:</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>value</i>) is Number, return <i>value</i>.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>value)</i> is Object and <i>value</i> has a
+ [[NumberData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, then
+ <ol class="block">
+ <li>Let <i>n</i> be the value of <i>value’s</i> [[NumberData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>n</i> is not <b>undefined</b>, then return <i>n</i>.</li>
+ </ol>
+ </li>
+ <li>Throw a <b>TypeError</b> exception.</li>
+ </ol>
+
+ <p>The phrase “this Number value” within the specification of a method refers to the result returned by
+ calling the abstract operation <span style="font-family: Times New Roman">thisNumberValue</span> with the <b>this</b>
+ value of the method invocation passed as the argument.</p>
+ </div>
+
+ <section id="sec-number.prototype.constructor">
+ <h1><span class="secnum" id="sec-20.1.3.1"><a href="#sec-number.prototype.constructor"
+ title="link to this section">20.1.3.1</a></span> Number.prototype.constructor</h1>
+
+ <p>The initial value of <code>Number.prototype.constructor</code> is the built-in <code>Number</code> constructor.</p>
+ </section>
+
+ <section id="sec-number.prototype.toexponential">
+ <h1><span class="secnum" id="sec-20.1.3.2"><a href="#sec-number.prototype.toexponential"
+ title="link to this section">20.1.3.2</a></span> Number.prototype.toExponential ( fractionDigits )</h1>
+
+ <p>Return a String containing this Number value represented in decimal exponential notation with one digit before the
+ significand's decimal point and <var>fractionDigits</var> digits after the significand's decimal point. If
+ <var>fractionDigits</var> is <b>undefined</b>, include as many significand digits as necessary to uniquely specify the
+ Number (just like in <a href="#sec-tostring">ToString</a> except that in this case the Number is always output in
+ exponential notation). Specifically, perform the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>x</i> be thisNumberValue(<b>this</b> value).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>x</i>).</li>
+ <li>Let <i>f</i> be <a href="#sec-tointeger">ToInteger</a>(<i>fractionDigits</i>).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>f</i> is 0, when <i>fractionDigits</i> is <b>undefined</b>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>f</i>).</li>
+ <li>If <i>x</i> is <b>NaN</b>, return the String <code>"NaN"</code>.</li>
+ <li>Let <i>s</i> be the empty String.</li>
+ <li>If <i>x</i> <i><</i> 0, then
+ <ol class="block">
+ <li>Let <i>s</i> be <code>"-"</code>.</li>
+ <li>Let <i>x</i> = –<i>x</i>.</li>
+ </ol>
+ </li>
+ <li>If <i>x</i> = +∞, then
+ <ol class="block">
+ <li>Return the concatenation of the Strings <i>s</i> and <code>"Infinity"</code>.</li>
+ </ol>
+ </li>
+ <li>If <i>f</i> < 0 or <i>f</i> > 20, throw a <b>RangeError</b> exception.</li>
+ <li>If <i>x</i> = 0, then
+ <ol class="block">
+ <li>Let <i>m</i> be the String consisting of <i>f</i>+1 occurrences of the code unit 0x0030.</li>
+ <li>Let <i>e</i> = 0.</li>
+ </ol>
+ </li>
+ <li>Else <i>x</i> ≠ 0,
+ <ol class="block">
+ <li>If <i>fractionDigits</i> is not <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>e</i> and <i>n</i> be integers such that 10<sup><i>f</i></sup> ≤ <i>n</i> <
+ 10<sup><i>f</i>+1</sup> and for which the exact mathematical value of <i>n</i> ×
+ 10<sup><i>e</i>–<i>f</i></sup> – <i>x</i> is as close to zero as possible. If there are two such
+ sets of <i>e</i> and <i>n</i>, pick the <i>e</i> and <i>n</i> for which <i>n</i> ×
+ 10<sup><i>e</i>–<i>f</i></sup> is larger.</li>
+ </ol>
+ </li>
+ <li>Else <i>fractionDigits</i> is <b>undefined</b>,
+ <ol class="block">
+ <li>Let <i>e</i>, <i>n</i>, and <i>f</i> be integers such that <i>f</i> ≥ 0, 10<sup><i>f</i></sup> ≤
+ <i>n</i> < 10<sup><i>f</i>+1</sup>, the number value for n × 10<sup><i>e</i>–<i>f</i></sup>
+ is <i>x</i>, and <i>f</i> is as small as possible. Note that the decimal representation of <i>n</i> has
+ <i>f</i>+1 digits, <i>n</i> is not divisible by 10, and the least significant digit of <i>n</i> is not
+ necessarily uniquely determined by these criteria.</li>
+ </ol>
+ </li>
+ <li>Let <i>m</i> be the String consisting of the digits of the decimal representation of <i>n</i> (in order, with no
+ leading zeroes).</li>
+ </ol>
+ </li>
+ <li>If <i>f</i> ≠ 0, then
+ <ol class="block">
+ <li>Let <i>a</i> be the first element of <i>m</i>, and let <i>b</i> be the remaining <i>f</i> elements of
+ <i>m</i>.</li>
+ <li>Let <i>m</i> be the concatenation of the three Strings <i>a</i>, <code>"."</code>, and <i>b</i>.</li>
+ </ol>
+ </li>
+ <li>If <i>e</i> = 0, then
+ <ol class="block">
+ <li>Let <i>c</i> = <code>"+".</code></li>
+ <li>Let <i>d</i> = <code>"0".</code></li>
+ </ol>
+ </li>
+ <li>Else
+ <ol class="block">
+ <li>If <i>e</i> > 0, then let <i>c</i> = <code>"+".</code></li>
+ <li>Else <i>e</i> ≤ 0,
+ <ol class="block">
+ <li>Let <i>c</i> = <code>"-"</code>.</li>
+ <li>Let <i>e</i> = –<i>e</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>d</i> be the String consisting of the digits of the decimal representation of <i>e</i> (in order, with no
+ leading zeroes).</li>
+ </ol>
+ </li>
+ <li>Let <i>m</i> be the concatenation of the four Strings <i>m</i>, <code>"e"</code>, <i>c</i>, and <i>d</i>.</li>
+ <li>Return the concatenation of the Strings <i>s</i> and <i>m</i>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>toExponential</code> method is <b>1</b>.</p>
+
+ <p>If the <code>toExponential</code> method is called with more than one argument, then the behaviour is undefined (see <a
+ href="#sec-ecmascript-standard-built-in-objects">clause 17</a>).</p>
+
+ <p>An implementation is permitted to extend the behaviour of <code>toExponential</code> for values of
+ <var>fractionDigits</var> less than 0 or greater than 20. In this case <code>toExponential</code> would not necessarily
+ throw <b>RangeError</b> for such values.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> For implementations that provide more accurate conversions than required by the rules
+ above, it is recommended that the following alternative version of step 12.b.i be used as a guideline:</p>
+
+ <ol class="proc">
+ <li>Let <i>e</i>, <i>n</i>, and <i>f</i> be integers such that <i>f</i> ≥ 0, 10<sup><i>f</i></sup> ≤ n <
+ 10<sup><i>f</i>+1</sup>, the number value for n × 10<sup><i>e</i>–<i>f</i></sup> is x, and <i>f</i> is
+ as small as possible. If there are multiple possibilities for <i>n</i>, choose the value of <i>n</i> for which
+ <i>n</i> × 10<sup><i>e</i>–<i>f</i></sup> is closest in value to <i>x</i>. If there are two such
+ possible values of <i>n</i>, choose the one that is even.</li>
+ </ol>
+ </div>
+ </section>
+
+ <section id="sec-number.prototype.tofixed">
+ <h1><span class="secnum" id="sec-20.1.3.3"><a href="#sec-number.prototype.tofixed"
+ title="link to this section">20.1.3.3</a></span> Number.prototype.toFixed ( fractionDigits )</h1>
+
+ <div class="note">
+ <p><span class="nh">Note</span> <b>toFixed</b> returns a String containing this Number value represented in decimal
+ fixed-point notation with <i>fractionDigits</i> digits after the decimal point. If <i>fractionDigits</i> is
+ <b>undefined</b>, 0 is assumed.</p>
+ </div>
+
+ <p>The following steps are performed:</p>
+
+ <ol class="proc">
+ <li>Let <i>x</i> be thisNumberValue(<b>this</b> value).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>x</i>).</li>
+ <li>Let <i>f</i> be <a href="#sec-tointeger">ToInteger</a>(<i>fractionDigits</i>). (If <i>fractionDigits</i> is
+ <b>undefined</b>, this step produces the value <code>0</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>f</i>).</li>
+ <li>If <i>f</i> < 0 or <i>f</i> > 20, throw a <b>RangeError</b> exception.</li>
+ <li>If <i>x</i> is <b>NaN</b>, return the String <code>"NaN"</code>.</li>
+ <li>Let <i>s</i> be the empty String.</li>
+ <li>If <i>x</i> < 0, then
+ <ol class="block">
+ <li>Let <i>s</i> be "<code>-</code>".</li>
+ <li>Let <i>x</i> = –<i>x</i>.</li>
+ </ol>
+ </li>
+ <li>If <i>x</i> ≥ 10<sup>21</sup>, then
+ <ol class="block">
+ <li>Let <i>m</i> = <a href="#sec-tostring">ToString</a>(<i>x</i>).</li>
+ </ol>
+ </li>
+ <li>Else <i>x</i> < 10<sup>21</sup>,
+ <ol class="block">
+ <li>Let <i>n</i> be an integer for which the exact mathematical value of <i>n</i> ÷ 10<sup>f</sup> –
+ <i>x</i> is as close to zero as possible. If there are two such <i>n</i>, pick the larger <i>n</i>.</li>
+ <li>If <i>n</i> = 0, let <i>m</i> be the String <code>"0"</code>. Otherwise, let <i>m</i> be the String consisting
+ of the digits of the decimal representation of <i>n</i> (in order, with no leading zeroes).</li>
+ <li>If <i>f</i> ≠ 0, then
+ <ol class="block">
+ <li>Let <i>k</i> be the number of elements in <i>m</i>.</li>
+ <li>If <i>k</i> ≤ <i>f</i>, then
+ <ol class="block">
+ <li>Let <i>z</i> be the String consisting of <i>f</i>+1–<i>k</i> occurrences of the code unit
+ 0x0030.</li>
+ <li>Let <i>m</i> be the concatenation of Strings <i>z</i> and <i>m</i>.</li>
+ <li>Let <i>k</i> = <i>f</i> + 1.</li>
+ </ol>
+ </li>
+ <li>Let <i>a</i> be the first <i>k</i>–<i>f</i> elements of <i>m</i>, and let <i>b</i> be the remaining
+ <i>f</i> elements of <i>m</i>.</li>
+ <li>Let <i>m</i> be the concatenation of the three Strings <i>a</i>, <code>"."</code>, and <i>b</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Return the concatenation of the Strings <i>s</i> and <i>m</i>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>toFixed</code> method is <b>1</b>.</p>
+
+ <p>If the <code>toFixed</code> method is called with more than one argument, then the behaviour is undefined (see <a
+ href="#sec-ecmascript-standard-built-in-objects">clause 17</a>).</p>
+
+ <p>An implementation is permitted to extend the behaviour of <code>toFixed</code> for values of <var>fractionDigits</var>
+ less than 0 or greater than 20. In this case <code>toFixed</code> would not necessarily throw <b>RangeError</b> for such
+ values.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The output of <code>toFixed</code> may be more precise than <code>toString</code> for
+ some values because toString only prints enough significant digits to distinguish the number from adjacent number
+ values. For example,</p>
+
+ <p>(<code>1000000000000000128).toString()</code> returns <code>"1000000000000000100"</code>,<br>while
+ (<code>1000000000000000128).toFixed(0)</code> returns <code>"1000000000000000128"</code>.</p>
+ </div>
+ </section>
+
+ <section id="sec-number.prototype.tolocalestring">
+ <h1><span class="secnum" id="sec-20.1.3.4"><a href="#sec-number.prototype.tolocalestring"
+ title="link to this section">20.1.3.4</a></span> Number.prototype.toLocaleString( [ reserved1 [ , reserved2 ] ])</h1>
+
+ <p>An ECMAScript implementation that includes the ECMA-402 International API must implement the
+ <code>Number.prototype.toLocaleString</code> method as specified in the ECMA-402 specification. If an ECMAScript
+ implementation does not include the ECMA-402 API the following specification of the <code>toLocaleString</code> method is
+ used.</p>
+
+ <p>Produces a String value that represents this Number value formatted according to the conventions of the host
+ environment’s current locale. This function is implementation-dependent, and it is permissible, but not encouraged,
+ for it to return the same thing as <code>toString</code>.</p>
+
+ <p>The meanings of the optional parameters to this method are defined in the ECMA-402 specification; implementations that
+ do not include ECMA-402 support must not use those parameter position for anything else.</p>
+
+ <p>The <code>length</code> property of the <code>toLocaleString</code> method is <b>0</b>.</p>
+ </section>
+
+ <section id="sec-number.prototype.toprecision">
+ <h1><span class="secnum" id="sec-20.1.3.5"><a href="#sec-number.prototype.toprecision"
+ title="link to this section">20.1.3.5</a></span> Number.prototype.toPrecision ( precision )</h1>
+
+ <p>Return a String containing this Number value represented either in decimal exponential notation with one digit before
+ the significand's decimal point and <span style="font-family: Times New Roman"><i>precision</i>–1</span> digits
+ after the significand's decimal point or in decimal fixed notation with <var>precision</var> significant digits. If
+ <var>precision</var> is <b>undefined</b>, call <a href="#sec-tostring">ToString</a> (<a href="#sec-tostring">7.1.12</a>)
+ instead. Specifically, perform the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>x</i> be thisNumberValue(<b>this</b> value).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>x</i>).</li>
+ <li>If <i>precision</i> is <b>undefined</b>, return <a href="#sec-tostring">ToString</a>(<i>x</i>).</li>
+ <li>Let <i>p</i> be <a href="#sec-tointeger">ToInteger</a>(<i>precision</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>p</i>).</li>
+ <li>If <i>x</i> is <b>NaN</b>, return the String <code>"NaN"</code>.</li>
+ <li>Let <i>s</i> be the empty String.</li>
+ <li>If <i>x</i> < 0, then
+ <ol class="block">
+ <li>Let <i>s</i> be <code>"-"</code>.</li>
+ <li>Let <i>x</i> = –<i>x</i>.</li>
+ </ol>
+ </li>
+ <li>If <i>x</i> = +∞, then
+ <ol class="block">
+ <li>Return the concatenation of the Strings <i>s</i> and <code>"Infinity"</code>.</li>
+ </ol>
+ </li>
+ <li>If <i>p</i> < 1 or <i>p</i> > 21, throw a <b>RangeError</b> exception.</li>
+ <li>If <i>x</i> = 0, then
+ <ol class="block">
+ <li>Let <i>m</i> be the String consisting of <i>p</i> occurrences of the code unit 0x0030 (the Unicode character
+ ‘<code>0</code>’).</li>
+ <li>Let <i>e</i> = 0.</li>
+ </ol>
+ </li>
+ <li>Else <i>x</i> ≠ 0,
+ <ol class="block">
+ <li>Let <i>e</i> and <i>n</i> be integers such that 10<sup><i>p</i>–1</sup> ≤ <i>n</i> <
+ 10<sup><i>p</i></sup> and for which the exact mathematical value of <i>n</i> ×
+ 10<sup><i>e</i>–<i>p</i>+1</sup> – <i>x</i> is as close to zero as possible. If there are two such
+ sets of <i>e</i> and <i>n</i>, pick the <i>e</i> and <i>n</i> for which <i>n</i> ×
+ 10<sup><i>e</i>–<i>p</i>+1</sup> is larger.</li>
+ <li>Let <i>m</i> be the String consisting of the digits of the decimal representation of <i>n</i> (in order, with no
+ leading zeroes).</li>
+ <li>If <i>e</i> < –6 or <i>e</i> ≥ <i>p</i>, then
+ <ol class="block">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>e</i> ≠ 0</li>
+ <li>Let <i>a</i> be the first element of <i>m</i>, and let <i>b</i> be the remaining <i>p</i>–1 elements
+ of <i>m</i>.</li>
+ <li>Let <i>m</i> be the concatenation of the three Strings <i>a</i>, <code>"."</code>, and <i>b</i>.</li>
+ <li>If <i>e</i> > 0, then
+ <ol class="block">
+ <li>Let <i>c</i> = <code>"+"</code>.</li>
+ </ol>
+ </li>
+ <li>Else <i>e</i> < 0,
+ <ol class="block">
+ <li>Let <i>c</i> = <code>"-"</code>.</li>
+ <li>Let <i>e</i> = –<i>e</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>d</i> be the String consisting of the digits of the decimal representation of <i>e</i> (in order,
+ with no leading zeroes).</li>
+ <li>Return the concatenation of the five Strings <i>s</i>, <i>m</i>, <code>"e"</code>, <i>c</i>, and
+ <i>d</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>If <i>e</i> = <i>p</i>–1, then return the concatenation of the Strings <i>s</i> and <i>m</i>.</li>
+ <li>If <i>e</i> ≥ 0, then
+ <ol class="block">
+ <li>Let <i>m</i> be the concatenation of the first <i>e</i>+1 elements of <i>m</i>, the code unit 0x002E (Unicode
+ character ‘<code>.</code>’), and the remaining <i>p</i>– (<i>e</i>+1) elements of
+ <i>m</i>.</li>
+ </ol>
+ </li>
+ <li>Else <i>e</i> < 0,
+ <ol class="block">
+ <li>Let <i>m</i> be the concatenation of the String <code>"0."</code>, –(<i>e</i>+1) occurrences of code unit
+ 0x0030 (the Unicode character ‘<code>0</code>’), and the String <i>m</i>.</li>
+ </ol>
+ </li>
+ <li>Return the concatenation of the Strings <i>s</i> and <i>m</i>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>toPrecision</code> method is <b>1</b>.</p>
+
+ <p>If the <code>toPrecision</code> method is called with more than one argument, then the behaviour is undefined (see <a
+ href="#sec-ecmascript-standard-built-in-objects">clause 17</a>).</p>
+
+ <p>An implementation is permitted to extend the behaviour of <code>toPrecision</code> for values of <var>precision</var>
+ less than 1 or greater than 21. In this case <code>toPrecision</code> would not necessarily throw <b>RangeError</b> for
+ such values.</p>
+ </section>
+
+ <section id="sec-number.prototype.tostring">
+ <h1><span class="secnum" id="sec-20.1.3.6"><a href="#sec-number.prototype.tostring"
+ title="link to this section">20.1.3.6</a></span> Number.prototype.toString ( [ radix ] )</h1>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The optional <i>radix</i> should be an integer value in the inclusive range 2 to 36. If
+ <i>radix</i> not present or is <b>undefined</b> the Number 10 is used as the value of <i>radix</i>.</p>
+ </div>
+
+ <p>The following steps are performed:</p>
+
+ <ol class="proc">
+ <li>Let <i>x</i> be thisNumberValue(<b>this</b> value).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>x</i>).</li>
+ <li>If <i>radix</i> is not present, then let <i>radixNumber</i> be 10.</li>
+ <li>Else if <i>radix</i> is <b>undefined</b>, then let <i>radixNumber</i> be 10.</li>
+ <li>Else let <i>radixNumber</i> be <a href="#sec-tointeger">ToInteger</a>(<i>radix</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>radixNumber</i>).</li>
+ <li>If <i>radixNumber</i> < 2 or <i>radixNumber</i> > 36, then throw a <b>RangeError</b> exception.</li>
+ <li>If <i>radixNumber</i> = 10, then return <a href="#sec-tostring">ToString</a>(<i>x</i>).</li>
+ <li>Return the String representation of this Number value using the radix specified by <i>radixNumber</i>. Letters
+ <code>a</code>-<code>z</code> are used for digits with values 10 through 35. The precise algorithm is
+ implementation-dependent, however the algorithm should be a generalisation of that specified in <a
+ href="#sec-tostring-applied-to-the-number-type">7.1.12.1</a>.</li>
+ </ol>
+
+ <p>The <code>toString</code> function is not generic; it throws a <b>TypeError</b> exception if its <b>this</b> value is
+ not a Number or a Number object. Therefore, it cannot be transferred to other kinds of objects for use as a method.</p>
+ </section>
+
+ <section id="sec-number.prototype.valueof">
+ <h1><span class="secnum" id="sec-20.1.3.7"><a href="#sec-number.prototype.valueof"
+ title="link to this section">20.1.3.7</a></span> Number.prototype.valueOf ( )</h1>
+ <ol class="proc">
+ <li>Let <i>x</i> be thisNumberValue(<b>this</b> value).</li>
+ <li>Return <i>x</i>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-number-instances">
+ <h1><span class="secnum" id="sec-20.1.4"><a href="#sec-properties-of-number-instances"
+ title="link to this section">20.1.4</a></span> Properties of Number Instances</h1>
+
+ <p>Number instances are ordinary objects that inherit properties from the Number prototype object. Number instances also
+ have a [[NumberData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>. The [[NumberData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is the Number value represented by this Number
+ object.</p>
+ </section>
+ </section>
+
+ <section id="sec-math-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-20.2"><a href="#sec-math-object" title="link to this section">20.2</a></span> The Math
+ Object</h1>
+
+ <p>The Math object is a single ordinary object.</p>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the Math
+ object is the standard built-in Object prototype object (<a
+ href="#sec-properties-of-the-object-prototype-object">19.1.3</a>).</p>
+
+ <p>The Math is not a function object. It does not have a [[Construct]] internal method; it is not possible to use the Math
+ object as a constructor with the <code>new</code> operator. The Math object also does not have a [[Call]] internal method;
+ it is not possible to invoke the Math object as a function.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> In this specification, the phrase “the Number value for <i>x</i>” has a
+ technical meaning defined in <a href="#sec-ecmascript-language-types-number-type">6.1.6</a>.</p>
+ </div>
+ </div>
+
+ <section id="sec-value-properties-of-the-math-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-20.2.1"><a href="#sec-value-properties-of-the-math-object"
+ title="link to this section">20.2.1</a></span> Value Properties of the Math Object</h1>
+ </div>
+
+ <section id="sec-math.e">
+ <h1><span class="secnum" id="sec-20.2.1.1"><a href="#sec-math.e" title="link to this section">20.2.1.1</a></span>
+ Math.E</h1>
+
+ <p>The Number value for <var>e</var>, the base of the natural logarithms, which is approximately
+ 2.7182818284590452354.</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-math.ln10">
+ <h1><span class="secnum" id="sec-20.2.1.2"><a href="#sec-math.ln10" title="link to this section">20.2.1.2</a></span>
+ Math.LN10</h1>
+
+ <p>The Number value for the natural logarithm of 10, which is approximately 2.302585092994046.</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-math.log10e">
+ <h1><span class="secnum" id="sec-20.2.1.3"><a href="#sec-math.log10e" title="link to this section">20.2.1.3</a></span>
+ Math.LOG10E</h1>
+
+ <p>The Number value for the base-<span style="font-family: Times New Roman">10</span> logarithm of <var>e</var>, the base
+ of the natural logarithms; this value is approximately <span style="font-family: Times New
+ Roman">0.4342944819032518</span>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The value of <code>Math.LOG10E</code> is approximately the reciprocal of the value of
+ <code>Math.LN10</code>.</p>
+ </div>
+ </section>
+
+ <section id="sec-math.ln2">
+ <h1><span class="secnum" id="sec-20.2.1.4"><a href="#sec-math.ln2" title="link to this section">20.2.1.4</a></span>
+ Math.LN2</h1>
+
+ <p>The Number value for the natural logarithm of 2, which is approximately 0.6931471805599453.</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-math.log2e">
+ <h1><span class="secnum" id="sec-20.2.1.5"><a href="#sec-math.log2e" title="link to this section">20.2.1.5</a></span>
+ Math.LOG2E</h1>
+
+ <p>The Number value for the base-<span style="font-family: Times New Roman">2</span> logarithm of <var>e</var>, the base
+ of the natural logarithms; this value is approximately <span style="font-family: Times New
+ Roman">1.4426950408889634</span>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The value of <code>Math.LOG2E</code> is approximately the reciprocal of the value of
+ <code>Math.LN2</code>.</p>
+ </div>
+ </section>
+
+ <section id="sec-math.pi">
+ <h1><span class="secnum" id="sec-20.2.1.6"><a href="#sec-math.pi" title="link to this section">20.2.1.6</a></span>
+ Math.PI</h1>
+
+ <p>The Number value for <span style="font-family: Times New Roman">π</span>, the ratio of the circumference of a circle
+ to its diameter, which is approximately <span style="font-family: Times New Roman">3.1415926535897932</span>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-math.sqrt1_2">
+ <h1><span class="secnum" id="sec-20.2.1.7"><a href="#sec-math.sqrt1_2" title="link to this section">20.2.1.7</a></span>
+ Math.SQRT1_2</h1>
+
+ <p>The Number value for the square root of <span style="font-family: Times New Roman">½</span>, which is
+ approximately <span style="font-family: Times New Roman">0.7071067811865476</span>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The value of <code>Math.SQRT1_2</code> is approximately the reciprocal of the value of
+ <code>Math.SQRT2</code>.</p>
+ </div>
+ </section>
+
+ <section id="sec-math.sqrt2">
+ <h1><span class="secnum" id="sec-20.2.1.8"><a href="#sec-math.sqrt2" title="link to this section">20.2.1.8</a></span>
+ Math.SQRT2</h1>
+
+ <p>The Number value for the square root of <span style="font-family: Times New Roman">2</span>, which is approximately
+ <span style="font-family: Times New Roman">1.4142135623730951</span>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-math-@@tostringtag">
+ <h1><span class="secnum" id="sec-20.2.1.9"><a href="#sec-math-@@tostringtag"
+ title="link to this section">20.2.1.9</a></span> Math [ @@toStringTag ]</h1>
+
+ <p>The initial value of the @@toStringTag property is the string value <b>"<code>Math</code>"</b>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <span class="value">false</span>, [[Enumerable]]: <span
+ class="value">false</span>, [[Configurable]]: <span class="value">true</span> }.</p>
+ </section>
+ </section>
+
+ <section id="sec-function-properties-of-the-math-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-20.2.2"><a href="#sec-function-properties-of-the-math-object"
+ title="link to this section">20.2.2</a></span> Function Properties of the Math Object</h1>
+
+ <p>Each of the following <code>Math</code> object functions applies the <a href="#sec-tonumber">ToNumber</a> abstract
+ operation to each of its arguments (in left-to-right order if there is more than one). If <a
+ href="#sec-tonumber">ToNumber</a> returns an <a href="#sec-completion-record-specification-type">abrupt completion</a>,
+ that <a href="#sec-completion-record-specification-type">Completion Record</a> is immediately returned. Otherwise, the
+ function performs a computation on the resulting Number value(s). The value returned by each function is a Number.</p>
+
+ <p>In the function descriptions below, the symbols NaN, −0, +0, −∞ and +∞ refer to the Number
+ values described in <a href="#sec-ecmascript-language-types-number-type">6.1.6</a>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The behaviour of the functions <code>acos</code>, <code>acosh</code>, <code>asin</code>,
+ <code>asinh</code>, <code>atan</code>, <code>atanh</code>, <code>atan2</code>, <code>cbrt</code>, <code>cos</code>,
+ <code>cosh</code>, <code>exp</code>, <code>hypot</code>, <code>log</code>,<code>log1p</code>, <code>log2</code>,
+ <code>log10</code>, <code>pow</code>, <code>sin</code>, <code>sinh</code>, <code>sqrt</code>, <code>tan</code>, and
+ <code>tanh</code> is not precisely specified here except to require specific results for certain argument values that
+ represent boundary cases of interest. For other argument values, these functions are intended to compute approximations
+ to the results of familiar mathematical functions, but some latitude is allowed in the choice of approximation
+ algorithms. The general intent is that an implementer should be able to use the same mathematical library for ECMAScript
+ on a given hardware platform that is available to C programmers on that platform.</p>
+ </div>
+
+ <p>Although the choice of algorithms is left to the implementation, it is recommended (but not specified by this standard)
+ that implementations use the approximation algorithms for IEEE 754 arithmetic contained in <code>fdlibm</code>, the freely
+ distributable mathematical library from Sun Microsystems (<a
+ href="http://www.netlib.org/fdlibm">http://www.netlib.org/fdlibm</a><code>)</code>.</p>
+ </div>
+
+ <section id="sec-math.abs">
+ <h1><span class="secnum" id="sec-20.2.2.1"><a href="#sec-math.abs" title="link to this section">20.2.2.1</a></span>
+ Math.abs ( x )</h1>
+
+ <p>Returns the absolute value of <var>x</var>; the result has the same magnitude as <var>x</var> but has positive
+ sign.</p>
+
+ <ul>
+ <li>If <i>x</i> is NaN, the result is NaN.</li>
+ <li>If <i>x</i> is −0, the result is +0.</li>
+ <li>If <i>x</i> is −∞, the result is +∞.</li>
+ </ul>
+ </section>
+
+ <section id="sec-math.acos">
+ <h1><span class="secnum" id="sec-20.2.2.2"><a href="#sec-math.acos" title="link to this section">20.2.2.2</a></span>
+ Math.acos ( x )</h1>
+
+ <p>Returns an implementation-dependent approximation to the arc cosine of <var>x</var>. The result is expressed in radians
+ and ranges from <span style="font-family: Times New Roman">+0</span> to <span style="font-family: Times New
+ Roman">+π</span>.</p>
+
+ <ul>
+ <li>If <i>x</i> is NaN, the result is NaN.</li>
+ <li>If <i>x</i> is greater than 1, the result is NaN.</li>
+ <li>If <i>x</i> is less than <b>−</b>1, the result is NaN.</li>
+ <li>If <i>x</i> is exactly 1, the result is +0.</li>
+ </ul>
+ </section>
+
+ <section id="sec-math.acosh">
+ <h1><span class="secnum" id="sec-20.2.2.3"><a href="#sec-math.acosh" title="link to this section">20.2.2.3</a></span>
+ Math.acosh( x )</h1>
+
+ <p>Returns an implementation-dependent approximation to the inverse hyperbolic cosine of <i>x</i>.</p>
+
+ <ul>
+ <li>If <i>x</i> is NaN, the result is NaN.</li>
+ <li>If x is less than 1, the result is NaN.</li>
+ <li>If x is 1, the result is +0.</li>
+ <li>If <i>x</i> is +∞, the result is +∞.</li>
+ </ul>
+ </section>
+
+ <section id="sec-math.asin">
+ <h1><span class="secnum" id="sec-20.2.2.4"><a href="#sec-math.asin" title="link to this section">20.2.2.4</a></span>
+ Math.asin ( x )</h1>
+
+ <p>Returns an implementation-dependent approximation to the arc sine of <var>x</var>. The result is expressed in radians
+ and ranges from <span style="font-family: Times New Roman">−π/2</span> to <span style="font-family: Times New
+ Roman">+π/2</span>.</p>
+
+ <ul>
+ <li>If <i>x</i> is NaN, the result is NaN.</li>
+ <li>If <i>x</i> is greater than 1, the result is NaN.</li>
+ <li>If <i>x</i> is less than –1, the result is NaN.</li>
+ <li>If <i>x</i> is +0, the result is +0.</li>
+ <li>If <i>x</i> is −0, the result is −0.</li>
+ </ul>
+ </section>
+
+ <section id="sec-math.asinh">
+ <h1><span class="secnum" id="sec-20.2.2.5"><a href="#sec-math.asinh" title="link to this section">20.2.2.5</a></span>
+ Math.asinh( x )</h1>
+
+ <p>Returns an implementation-dependent approximation to the inverse hyperbolic sine of <i>x</i>.</p>
+
+ <ul>
+ <li>If <i>x</i> is NaN, the result is NaN.</li>
+ <li>If <i>x</i> is +0, the result is +0.</li>
+ <li>If <i>x</i> is −0, the result is −0.</li>
+ <li>If <i>x</i> is +∞, the result is +∞.</li>
+ <li>If x is −∞, the result is −∞.</li>
+ </ul>
+ </section>
+
+ <section id="sec-math.atan">
+ <h1><span class="secnum" id="sec-20.2.2.6"><a href="#sec-math.atan" title="link to this section">20.2.2.6</a></span>
+ Math.atan ( x )</h1>
+
+ <p>Returns an implementation-dependent approximation to the arc tangent of <var>x</var>. The result is expressed in
+ radians and ranges from <span style="font-family: Times New Roman">−π/2</span> to <span style="font-family: Times
+ New Roman">+π/2</span>.</p>
+
+ <ul>
+ <li>If <i>x</i> is NaN, the result is NaN.</li>
+ <li>If <i>x</i> is +0, the result is +0.</li>
+ <li>If <i>x</i> is −0, the result is −0.</li>
+ <li>If <i>x</i> is +∞, the result is an implementation-dependent approximation to +π/2.</li>
+ <li>If <i>x</i> is −∞, the result is an implementation-dependent approximation to −π/2.</li>
+ </ul>
+ </section>
+
+ <section id="sec-math.atanh">
+ <h1><span class="secnum" id="sec-20.2.2.7"><a href="#sec-math.atanh" title="link to this section">20.2.2.7</a></span>
+ Math.atanh( x )</h1>
+
+ <p>Returns an implementation-dependent approximation to the inverse hyperbolic tangent of <i>x</i>.</p>
+
+ <ul>
+ <li>If <i>x</i> is NaN, the result is NaN.</li>
+ <li>If <i>x</i> is less than −1, the result is NaN.</li>
+ <li>If <i>x</i> is greater than 1, the result is NaN.</li>
+ <li>If <i>x</i> is −1, the result is −∞.</li>
+ <li>If <i>x</i> is +1, the result is +∞.</li>
+ <li>If <i>x</i> is +0, the result is +0.</li>
+ <li>If <i>x</i> is −0, the result is −0.</li>
+ </ul>
+ </section>
+
+ <section id="sec-math.atan2">
+ <h1><span class="secnum" id="sec-20.2.2.8"><a href="#sec-math.atan2" title="link to this section">20.2.2.8</a></span>
+ Math.atan2 ( y, x )</h1>
+
+ <p>Returns an implementation-dependent approximation to the arc tangent of the quotient <span style="font-family: Times
+ New Roman"><i>y</i><b>/</b><i>x</i></span> of the arguments <var>y</var> and <var>x</var>, where the signs of <var>y</var>
+ and <var>x</var> are used to determine the quadrant of the result. Note that it is intentional and traditional for the
+ two-argument arc tangent function that the argument named <var>y</var> be first and the argument named <var>x</var> be
+ second. The result is expressed in radians and ranges from <span style="font-family: Times New Roman">−π</span>
+ to <span style="font-family: Times New Roman">+π</span>.</p>
+
+ <ul>
+ <li>If either <i>x</i> or <i>y</i> is NaN, the result is NaN.</li>
+ <li>If <i>y</i>>0 and <i>x</i> is +0, the result is an implementation-dependent approximation to +π/2.</li>
+ <li>If <i>y</i>>0 and <i>x</i> is −0, the result is an implementation-dependent approximation to +π/2.</li>
+ <li>If <i>y</i> is +0 and <i>x</i>>0, the result is +0.</li>
+ <li>If <i>y</i> is +0 and <i>x</i> is +0, the result is +0.</li>
+ <li>If <i>y</i> is +0 and <i>x</i> is −0, the result is an implementation-dependent approximation to +π.</li>
+ <li>If <i>y</i> is +0 and <i>x</i><0, the result is an implementation-dependent approximation to +π.</li>
+ <li>If <i>y</i> is −0 and <i>x</i>>0, the result is −0.</li>
+ <li>If <i>y</i> is −0 and <i>x</i> is +0, the result is −0.</li>
+ <li>If <i>y</i> is −0 and <i>x</i> is −0, the result is an implementation-dependent approximation to
+ −π.</li>
+ <li>If <i>y</i> is −0 and <i>x</i><0, the result is an implementation-dependent approximation to
+ −π.</li>
+ <li>If <i>y</i><0 and <i>x</i> is +0, the result is an implementation-dependent approximation to −π/2.</li>
+ <li>If <i>y</i><0 and <i>x</i> is −0, the result is an implementation-dependent approximation to
+ −π/2.</li>
+ <li>If <i>y</i>>0 and <i>y</i> is finite and <i>x</i> is +∞, the result is +0.</li>
+ <li>If <i>y</i>>0 and <i>y</i> is finite and <i>x</i> is −∞, the result if an implementation-dependent
+ approximation to +π.</li>
+ <li>If <i>y</i><0 and <i>y</i> is finite and <i>x</i> is +∞, the result is −0.</li>
+ <li>If <i>y</i><0 and <i>y</i> is finite and <i>x</i> is −∞, the result is an implementation-dependent
+ approximation to −π.</li>
+ <li>If <i>y</i> is +∞ and <i>x</i> is finite, the result is an implementation-dependent approximation to
+ +π/2.</li>
+ <li>If <i>y</i> is −∞ and <i>x</i> is finite, the result is an implementation-dependent approximation to
+ −π/2.</li>
+ <li>If <i>y</i> is +∞ and <i>x</i> is +∞, the result is an implementation-dependent approximation to
+ +π/4.</li>
+ <li>If <i>y</i> is +∞ and <i>x</i> is −∞, the result is an implementation-dependent approximation to
+ +3π/4.</li>
+ <li>If <i>y</i> is −∞ and <i>x</i> is +∞, the result is an implementation-dependent approximation to
+ −π/4.</li>
+ <li>If <i>y</i> is −∞ and <i>x</i> is −∞, the result is an implementation-dependent
+ approximation to −3π/4.</li>
+ </ul>
+ </section>
+
+ <section id="sec-math.cbrt">
+ <h1><span class="secnum" id="sec-20.2.2.9"><a href="#sec-math.cbrt" title="link to this section">20.2.2.9</a></span>
+ Math.cbrt ( x )</h1>
+
+ <p>Returns an implementation-dependent approximation to the cube root of <i>x</i>.</p>
+
+ <ul>
+ <li>If <i>x</i> is NaN, the result is NaN.</li>
+ <li>If <i>x</i> is +0, the result is +0.</li>
+ <li>If <i>x</i> is −0, the result is −0.</li>
+ <li>If <i>x</i> is +∞, the result is +∞.</li>
+ <li>If <i>x</i> is −∞, the result is −∞.</li>
+ </ul>
+ </section>
+
+ <section id="sec-math.ceil">
+ <h1><span class="secnum" id="sec-20.2.2.10"><a href="#sec-math.ceil" title="link to this section">20.2.2.10</a></span>
+ Math.ceil ( x )</h1>
+
+ <p>Returns the smallest (closest to <b>−∞</b>) Number value that is not less than <var>x</var> and is equal to
+ a mathematical integer. If <var>x</var> is already an integer, the result is <var>x</var>.</p>
+
+ <ul>
+ <li>If <i>x</i> is NaN, the result is NaN.</li>
+ <li>If <i>x</i> is +0, the result is +0.</li>
+ <li>If <i>x</i> is −0, the result is −0.</li>
+ <li>If <i>x</i> is +∞, the result is +∞.</li>
+ <li>If <i>x</i> is −∞, the result is −∞.</li>
+ <li>If <i>x</i> is less than 0 but greater than -1, the result is −0.</li>
+ </ul>
+
+ <p>The value of <code>Math.ceil(x)</code> is the same as the value of <code>-<a
+ href="#sec-math.floor">Math.floor</a>(-x)</code>.</p>
+ </section>
+
+ <section id="sec-math.clz32">
+ <h1><span class="secnum" id="sec-20.2.2.11"><a href="#sec-math.clz32" title="link to this section">20.2.2.11</a></span>
+ Math.clz32 ( x )</h1>
+
+ <p>When <code>Math.clz32</code> is called with one argument <var>x</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>n</i> be <a href="#sec-touint32">ToUint32</a>(<i>x</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>n</i>).</li>
+ <li>Let <i>p</i> be the number of leading zero bits in the 32-bit binary representation of <i>n</i>.</li>
+ <li>Return <i>p</i>.</li>
+ </ol>
+
+ <p class="Note">NOTE If <i>n</i> is 0, <i>p</i> will be 32. If the most significant bit of the 32-bit binary encoding of
+ <i>n</i> is 1, <i>p</i> will be 0.</p>
+ </section>
+
+ <section id="sec-math.cos">
+ <h1><span class="secnum" id="sec-20.2.2.12"><a href="#sec-math.cos" title="link to this section">20.2.2.12</a></span>
+ Math.cos ( x )</h1>
+
+ <p>Returns an implementation-dependent approximation to the cosine of <var>x</var>. The argument is expressed in
+ radians.</p>
+
+ <ul>
+ <li>If <i>x</i> is NaN, the result is NaN.</li>
+ <li>If <i>x</i> is +0, the result is 1.</li>
+ <li>If <i>x</i> is −0, the result is 1.</li>
+ <li>If <i>x</i> is +∞, the result is NaN.</li>
+ <li>If <i>x</i> is −∞, the result is NaN.</li>
+ </ul>
+ </section>
+
+ <section id="sec-math.cosh">
+ <h1><span class="secnum" id="sec-20.2.2.13"><a href="#sec-math.cosh" title="link to this section">20.2.2.13</a></span>
+ Math.cosh ( x )</h1>
+
+ <p>Returns an implementation-dependent approximation to the hyperbolic cosine of <i>x</i>.</p>
+
+ <ul>
+ <li>If <i>x</i> is NaN, the result is NaN.</li>
+ <li>If <i>x</i> is +0, the result is 1.</li>
+ <li>If <i>x</i> is −0, the result is 1.</li>
+ <li>If <i>x</i> is +∞, the result is +∞.</li>
+ <li>If <i>x</i> is −∞, the result is +∞.</li>
+ </ul>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The value of cosh(x) is the same as <i>(exp(x) + exp(-x))/2</i>.</p>
+ </div>
+ </section>
+
+ <section id="sec-math.exp">
+ <h1><span class="secnum" id="sec-20.2.2.14"><a href="#sec-math.exp" title="link to this section">20.2.2.14</a></span>
+ Math.exp ( x )</h1>
+
+ <p>Returns an implementation-dependent approximation to the exponential function of <var>x</var> (<var>e</var> raised to
+ the power of <var>x</var>, where <var>e</var> is the base of the natural logarithms).</p>
+
+ <ul>
+ <li>If <i>x</i> is NaN, the result is NaN.</li>
+ <li>If <i>x</i> is +0, the result is 1.</li>
+ <li>If <i>x</i> is −0, the result is 1.</li>
+ <li>If <i>x</i> is +∞, the result is +∞.</li>
+ <li>If <i>x</i> is −∞, the result is +0.</li>
+ </ul>
+ </section>
+
+ <section id="sec-math.expm1">
+ <h1><span class="secnum" id="sec-20.2.2.15"><a href="#sec-math.expm1" title="link to this section">20.2.2.15</a></span>
+ Math.expm1 ( x )</h1>
+
+ <p>Returns an implementation-dependent approximation to subtracting 1 from the exponential function of <i>x</i> (<i>e</i>
+ raised to the power of <i>x</i>, where <i>e</i> is the base of the natural logarithms). The result is computed in a way
+ that is accurate even when the value of x is close 0.</p>
+
+ <ul>
+ <li>If <i>x</i> is NaN, the result is NaN.</li>
+ <li>If <i>x</i> is +0, the result is +0.</li>
+ <li>If <i>x</i> is −0, the result is −0.</li>
+ <li>If <i>x</i> is +∞, the result is +∞.</li>
+ <li>If <i>x</i> is −∞, the result is −1.</li>
+ </ul>
+ </section>
+
+ <section id="sec-math.floor">
+ <h1><span class="secnum" id="sec-20.2.2.16"><a href="#sec-math.floor" title="link to this section">20.2.2.16</a></span>
+ Math.floor ( x )</h1>
+
+ <p>Returns the greatest (closest to <b>+∞</b>) Number value that is not greater than <var>x</var> and is equal to a
+ mathematical integer. If <var>x</var> is already an integer, the result is <var>x</var>.</p>
+
+ <ul>
+ <li>If <i>x</i> is NaN, the result is NaN.</li>
+ <li>If <i>x</i> is +0, the result is +0.</li>
+ <li>If <i>x</i> is −0, the result is −0.</li>
+ <li>If <i>x</i> is +∞, the result is +∞.</li>
+ <li>If <i>x</i> is −∞, the result is −∞.</li>
+ <li>If <i>x</i> is greater than 0 but less than 1, the result is +0.</li>
+ </ul>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The value of <code>Math.<a href="#sec-algorithm-conventions">floor</a>(x)</code> is the
+ same as the value of <code>-<a href="#sec-math.ceil">Math.ceil</a>(-x)</code>.</p>
+ </div>
+ </section>
+
+ <section id="sec-math.fround">
+ <h1><span class="secnum" id="sec-20.2.2.17"><a href="#sec-math.fround" title="link to this section">20.2.2.17</a></span>
+ Math.fround ( x )</h1>
+
+ <p>When <code>Math.fround</code> is called with argument <i>x</i> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>If <i>x</i> is NaN, return NaN.</li>
+ <li>If <i>x</i> is one of +0, −0, +∞, −∞, then return <i>x</i>.</li>
+ <li>Let <i>x32</i> be the result of converting <i>x</i> to a value in IEEE-754-2008 binary32 format using
+ roundTiesToEven.</li>
+ <li>Let <i>x64</i> be the result of converting <i>x32</i> to a value in IEEE-754-2008 binary64 format.</li>
+ <li>Return the ECMAScript Number value corresponding to <i>x64</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-math.hypot">
+ <h1><span class="secnum" id="sec-20.2.2.18"><a href="#sec-math.hypot" title="link to this section">20.2.2.18</a></span>
+ Math.hypot ( value1 , value2 , …values )</h1>
+
+ <p><code>Math.hypot</code> returns an implementation-dependent approximation of the square root of the sum of squares of
+ its arguments.</p>
+
+ <ul>
+ <li>If no arguments are passed, the result is +0.</li>
+ <li>If any argument is +∞, the result is +∞.</li>
+ <li>If any argument is −∞, the result is +∞.</li>
+ <li>If no argument is +∞ or −∞, and any argument is NaN, the result is NaN.</li>
+ <li>If all arguments are either +0 or −0, the result is +0.</li>
+ </ul>
+
+ <p>The length property of the <code>hypot</code> function is 2.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Implementations should take care to avoid the loss of precision from overflows and
+ underflows that are prone to occur in naive implementations when this function is called with more than two
+ arguments.</p>
+ </div>
+ </section>
+
+ <section id="sec-math.imul">
+ <h1><span class="secnum" id="sec-20.2.2.19"><a href="#sec-math.imul" title="link to this section">20.2.2.19</a></span>
+ Math.imul ( x, y )</h1>
+
+ <p>When the <code>Math.imul</code> is called with arguments <var>x</var> and <var>y</var> the following steps are
+ taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>a</i> be <a href="#sec-touint32">ToUint32</a>(<i>x</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>a</i>).</li>
+ <li>Let <i>b</i> be <a href="#sec-touint32">ToUint32</a>(<i>y</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>b</i>).</li>
+ <li>Let <i>product</i> be (<i>a</i> × <i>b</i>) <a href="#sec-algorithm-conventions">modulo</a>
+ 2<sup>32</sup>.</li>
+ <li>If <i>product</i> ≥ 2<sup>31</sup>, return <i>product</i> − 2<sup>32</sup>, otherwise return
+ <i>product</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-math.log">
+ <h1><span class="secnum" id="sec-20.2.2.20"><a href="#sec-math.log" title="link to this section">20.2.2.20</a></span>
+ Math.log ( x )</h1>
+
+ <p>Returns an implementation-dependent approximation to the natural logarithm of <var>x</var>.</p>
+
+ <ul>
+ <li>If <i>x</i> is NaN, the result is NaN.</li>
+ <li>If <i>x</i> is less than 0, the result is NaN.</li>
+ <li>If <i>x</i> is +0 or −0, the result is −∞.</li>
+ <li>If <i>x</i> is 1, the result is +0.</li>
+ <li>If <i>x</i> is +∞, the result is +∞.</li>
+ </ul>
+ </section>
+
+ <section id="sec-math.log1p">
+ <h1><span class="secnum" id="sec-20.2.2.21"><a href="#sec-math.log1p" title="link to this section">20.2.2.21</a></span>
+ Math.log1p ( x )</h1>
+
+ <p>Returns an implementation-dependent approximation to the natural logarithm of 1 + <i>x</i>. The result is computed in
+ a way that is accurate even when the value of x is close to zero.</p>
+
+ <ul>
+ <li>If <i>x</i> is NaN, the result is NaN.</li>
+ <li>If <i>x</i> is less than -1, the result is NaN.</li>
+ <li>If x is -1, the result is -∞.</li>
+ <li>If <i>x</i> is +0, the result is +0.</li>
+ <li>If <i>x</i> is −0, the result is −0.</li>
+ <li>If <i>x</i> is +∞, the result is +∞.</li>
+ </ul>
+ </section>
+
+ <section id="sec-math.log10">
+ <h1><span class="secnum" id="sec-20.2.2.22"><a href="#sec-math.log10" title="link to this section">20.2.2.22</a></span>
+ Math.log10 ( x )</h1>
+
+ <p>Returns an implementation-dependent approximation to the base 10 logarithm of <i>x</i>.</p>
+
+ <ul>
+ <li>If <i>x</i> is NaN, the result is NaN.</li>
+ <li>If <i>x</i> is less than 0, the result is NaN.</li>
+ <li>If <i>x</i> is +0, the result is −∞.</li>
+ <li>If <i>x</i> is −0, the result is −∞.</li>
+ <li>If <i>x</i> is 1, the result is +0.</li>
+ <li>If <i>x</i> is +∞, the result is +∞.</li>
+ </ul>
+ </section>
+
+ <section id="sec-math.log2">
+ <h1><span class="secnum" id="sec-20.2.2.23"><a href="#sec-math.log2" title="link to this section">20.2.2.23</a></span>
+ Math.log2 ( x )</h1>
+
+ <p>Returns an implementation-dependent approximation to the base 2 logarithm of <i>x</i>.</p>
+
+ <ul>
+ <li>If <i>x</i> is NaN, the result is NaN.</li>
+ <li>If <i>x</i> is less than 0, the result is NaN.</li>
+ <li>If <i>x</i> is +0, the result is −∞.</li>
+ <li>If <i>x</i> is −0, the result is −∞.</li>
+ <li>If <i>x</i> is 1, the result is +0.</li>
+ <li>If <i>x</i> is +∞, the result is +∞.</li>
+ </ul>
+ </section>
+
+ <section id="sec-math.max">
+ <h1><span class="secnum" id="sec-20.2.2.24"><a href="#sec-math.max" title="link to this section">20.2.2.24</a></span>
+ Math.max ( value1, value2 , …values )</h1>
+
+ <p>Given zero or more arguments, calls <a href="#sec-tonumber">ToNumber</a> on each of the arguments and returns the
+ largest of the resulting values.</p>
+
+ <ul>
+ <li>
+ <p>If no arguments are given, the result is −∞.</p>
+ </li>
+
+ <li>
+ <p>If any value is NaN, the result is NaN.</p>
+ </li>
+
+ <li>
+ <p>The comparison of values to determine the largest value is done using the Abstract Relational Comparison algorithm
+ (<a href="#sec-isinteger">7.2.8</a>) except that +0 is considered to be larger than −0.</p>
+ </li>
+ </ul>
+
+ <p>The <code>length</code> property of the <code>max</code> method is <b>2</b>.</p>
+ </section>
+
+ <section id="sec-math.min">
+ <h1><span class="secnum" id="sec-20.2.2.25"><a href="#sec-math.min" title="link to this section">20.2.2.25</a></span>
+ Math.min ( value1, value2 , …values )</h1>
+
+ <p>Given zero or more arguments, calls <a href="#sec-tonumber">ToNumber</a> on each of the arguments and returns the
+ smallest of the resulting values.</p>
+
+ <ul>
+ <li>
+ <p>If no arguments are given, the result is +∞.</p>
+ </li>
+
+ <li>
+ <p>If any value is NaN, the result is NaN.</p>
+ </li>
+
+ <li>
+ <p>The comparison of values to determine the smallest value is done using the Abstract Relational Comparison algorithm
+ (<a href="#sec-isinteger">7.2.8</a>) except that +0 is considered to be larger than −0.</p>
+ </li>
+ </ul>
+
+ <p>The <code>length</code> property of the <code>min</code> method is <b>2</b>.</p>
+ </section>
+
+ <section id="sec-math.pow">
+ <h1><span class="secnum" id="sec-20.2.2.26"><a href="#sec-math.pow" title="link to this section">20.2.2.26</a></span>
+ Math.pow ( x, y )</h1>
+
+ <p>Returns an implementation-dependent approximation to the result of raising <var>x</var> to the power <var>y</var>.</p>
+
+ <ul>
+ <li>If <i>y</i> is NaN, the result is NaN.</li>
+ <li>If <i>y</i> is +0, the result is 1, even if <i>x</i> is NaN.</li>
+ <li>If <i>y</i> is −0, the result is 1, even if <i>x</i> is NaN.</li>
+ <li>If <i>x</i> is NaN and <i>y</i> is nonzero, the result is NaN.</li>
+ <li>If <a href="#sec-algorithm-conventions">abs</a>(<i>x</i>)>1 and <i>y</i> is +∞, the result is
+ +∞.</li>
+ <li>If <a href="#sec-algorithm-conventions">abs</a>(<i>x</i>)>1 and <i>y</i> is −∞, the result is
+ +0.</li>
+ <li>If <a href="#sec-algorithm-conventions">abs</a>(<i>x</i>) is 1 and <i>y</i> is +∞, the result is NaN.</li>
+ <li>If <a href="#sec-algorithm-conventions">abs</a>(<i>x</i>) is 1 and <i>y</i> is −∞, the result is
+ NaN.</li>
+ <li>If <a href="#sec-algorithm-conventions">abs</a>(<i>x</i>)<1 and <i>y</i> is +∞, the result is +0.</li>
+ <li>If <a href="#sec-algorithm-conventions">abs</a>(<i>x</i>)<1 and <i>y</i> is −∞, the result is
+ +∞.</li>
+ <li>If <i>x</i> is +∞ and <i>y</i>>0, the result is +∞.</li>
+ <li>If <i>x</i> is +∞ and <i>y</i><0, the result is +0.</li>
+ <li>If <i>x</i> is −∞ and <i>y</i>>0 and <i>y</i> is an odd integer, the result is −∞.</li>
+ <li>If <i>x</i> is −∞ and <i>y</i>>0 and <i>y</i> is not an odd integer, the result is +∞.</li>
+ <li>If <i>x</i> is −∞ and <i>y</i><0 and <i>y</i> is an odd integer, the result is −0.</li>
+ <li>If <i>x</i> is −∞ and <i>y</i><0 and <i>y</i> is not an odd integer, the result is +0.</li>
+ <li>If <i>x</i> is +0 and <i>y</i>>0, the result is +0.</li>
+ <li>If <i>x</i> is +0 and <i>y</i><0, the result is +∞.</li>
+ <li>If <i>x</i> is −0 and <i>y</i>>0 and <i>y</i> is an odd integer, the result is −0.</li>
+ <li>If <i>x</i> is −0 and <i>y</i>>0 and <i>y</i> is not an odd integer, the result is +0.</li>
+ <li>If <i>x</i> is −0 and <i>y</i><0 and <i>y</i> is an odd integer, the result is −∞.</li>
+ <li>If <i>x</i> is −0 and <i>y</i><0 and <i>y</i> is not an odd integer, the result is +∞.</li>
+ <li>If <i>x</i><0 and <i>x</i> is finite and <i>y</i> is finite and <i>y</i> is not an integer, the result is
+ NaN.</li>
+ </ul>
+ </section>
+
+ <section id="sec-math.random">
+ <h1><span class="secnum" id="sec-20.2.2.27"><a href="#sec-math.random" title="link to this section">20.2.2.27</a></span>
+ Math.random ( )</h1>
+
+ <p>Returns a Number value with positive sign, greater than or equal to 0 but less than 1, chosen randomly or pseudo
+ randomly with approximately uniform distribution over that range, using an implementation-dependent algorithm or strategy.
+ This function takes no arguments.</p>
+
+ <p>Each <code>Math.random</code> function created for distinct code Realms must produce a distinct sequence of values from
+ successive calls.</p>
+ </section>
+
+ <section id="sec-math.round">
+ <h1><span class="secnum" id="sec-20.2.2.28"><a href="#sec-math.round" title="link to this section">20.2.2.28</a></span>
+ Math.round ( x )</h1>
+
+ <p>Returns the Number value that is closest to <var>x</var> and is equal to a mathematical integer. If two integer Number
+ values are equally close to <var>x</var>, then the result is the Number value that is closer to <span style="font-family:
+ Times New Roman">+∞</span>. If <var>x</var> is already an integer, the result is <var>x</var>.</p>
+
+ <ul>
+ <li>If <i>x</i> is NaN, the result is NaN.</li>
+ <li>If <i>x</i> is +0, the result is +0.</li>
+ <li>If <i>x</i> is −0, the result is −0.</li>
+ <li>If <i>x</i> is +∞, the result is +∞.</li>
+ <li>If <i>x</i> is −∞, the result is −∞.</li>
+ <li>If <i>x</i> is greater than 0 but less than 0.5, the result is +0.</li>
+ <li>If <i>x</i> is less than 0 but greater than or equal to -0.5, the result is −0.</li>
+ </ul>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> <code>Math.round(3.5)</code> returns 4, but <code>Math.round(–3.5)</code>
+ returns –3.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 2</span> The value of <code>Math.round(x)</code> is not always the same as the value of
+ <code><a href="#sec-math.floor">Math.floor</a>(x+0.5)</code>. When <code>x</code> is −0 or is less than 0 but
+ greater than or equal to -0.5, <code>Math.round(x)</code> returns −0, but <code><a
+ href="#sec-math.floor">Math.floor</a>(x+0.5)</code> returns +0. <code>Math.round(x)</code> may also differ from the
+ value of <code><a href="#sec-math.floor">Math.floor</a>(x+0.5)</code><span style="font-family: sans-serif">because of
+ internal rounding when computing</span> <code>x+0.5</code><span style="font-family: sans-serif">.</span></p>
+ </div>
+ </section>
+
+ <section id="sec-math.sign">
+ <h1><span class="secnum" id="sec-20.2.2.29"><a href="#sec-math.sign" title="link to this section">20.2.2.29</a></span>
+ Math.sign(x)</h1>
+
+ <p>Returns the sign of the x, indicating whether x is positive, negative or zero.</p>
+
+ <ul>
+ <li>If <i>x</i> is NaN, the result is NaN.</li>
+ <li>If <i>x</i> is −0, the result is −0.</li>
+ <li>If <i>x</i> is +0, the result is +0.</li>
+ <li>If <i>x</i> is negative and not −0, the result is −1.</li>
+ <li>If <i>x</i> is positive and not +0, the result is +1.</li>
+ </ul>
+ </section>
+
+ <section id="sec-math.sin">
+ <h1><span class="secnum" id="sec-20.2.2.30"><a href="#sec-math.sin" title="link to this section">20.2.2.30</a></span>
+ Math.sin ( x )</h1>
+
+ <p>Returns an implementation-dependent approximation to the sine of <var>x</var>. The argument is expressed in
+ radians.</p>
+
+ <ul>
+ <li>If <i>x</i> is NaN, the result is NaN.</li>
+ <li>If <i>x</i> is +0, the result is +0.</li>
+ <li>If <i>x</i> is −0, the result is −0.</li>
+ <li>If <i>x</i> is +∞ or −∞, the result is NaN.</li>
+ </ul>
+ </section>
+
+ <section id="sec-math.sinh">
+ <h1><span class="secnum" id="sec-20.2.2.31"><a href="#sec-math.sinh" title="link to this section">20.2.2.31</a></span>
+ Math.sinh( x )</h1>
+
+ <p>Returns an implementation-dependent approximation to the hyperbolic sine of <i>x</i>.</p>
+
+ <ul>
+ <li>If <i>x</i> is NaN, the result is NaN.</li>
+ <li>If <i>x</i> is +0, the result is +0.</li>
+ <li>If <i>x</i> is −0, the result is −0.</li>
+ <li>If <i>x</i> is +∞, the result is +∞.</li>
+ <li>If x is −∞, the result is −∞.</li>
+ </ul>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The value of sinh(x) is the same as <i>(exp(x) - exp(-x))/2</i>.</p>
+ </div>
+ </section>
+
+ <section id="sec-math.sqrt">
+ <h1><span class="secnum" id="sec-20.2.2.32"><a href="#sec-math.sqrt" title="link to this section">20.2.2.32</a></span>
+ Math.sqrt ( x )</h1>
+
+ <p>Returns an implementation-dependent approximation to the square root of <var>x</var>.</p>
+
+ <ul>
+ <li>If <i>x</i> is NaN, the result is NaN.</li>
+ <li>If <i>x</i> is less than 0, the result is NaN.</li>
+ <li>If <i>x</i> is +0, the result is +0.</li>
+ <li>If <i>x</i> is −0, the result is −0.</li>
+ <li>If <i>x</i> is +∞, the result is +∞.</li>
+ </ul>
+ </section>
+
+ <section id="sec-math.tan">
+ <h1><span class="secnum" id="sec-20.2.2.33"><a href="#sec-math.tan" title="link to this section">20.2.2.33</a></span>
+ Math.tan ( x )</h1>
+
+ <p>Returns an implementation-dependent approximation to the tangent of <var>x</var>. The argument is expressed in
+ radians.</p>
+
+ <ul>
+ <li>If <i>x</i> is NaN, the result is NaN.</li>
+ <li>If <i>x</i> is +0, the result is +0.</li>
+ <li>If <i>x</i> is −0, the result is −0.</li>
+ <li>If <i>x</i> is +∞ or −∞, the result is NaN.</li>
+ </ul>
+ </section>
+
+ <section id="sec-math.tanh">
+ <h1><span class="secnum" id="sec-20.2.2.34"><a href="#sec-math.tanh" title="link to this section">20.2.2.34</a></span>
+ Math.tanh ( x )</h1>
+
+ <p>Returns an implementation-dependent approximation to the hyperbolic tangent of <i>x</i>.</p>
+
+ <ul>
+ <li>If <i>x</i> is NaN, the result is NaN.</li>
+ <li>If <i>x</i> is +0, the result is +0.</li>
+ <li>If <i>x</i> is −0, the result is −0.</li>
+ <li>If <i>x</i> is +∞, the result is +1.</li>
+ <li>If <i>x</i> is −∞, the result is -1.</li>
+ </ul>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The value of tanh(x) is the same as <i>(exp(x) - exp(-x))/(exp(x) + exp(-x))</i>.</p>
+ </div>
+ </section>
+
+ <section id="sec-math.trunc">
+ <h1><span class="secnum" id="sec-20.2.2.35"><a href="#sec-math.trunc" title="link to this section">20.2.2.35</a></span>
+ Math.trunc ( x )</h1>
+
+ <p>Returns the integral part of the number <var>x</var>, removing any fractional digits. If <var>x</var> is already an
+ integer, the result is <var>x</var>.</p>
+
+ <ul>
+ <li>If <i>x</i> is NaN, the result is NaN.</li>
+ <li>If <i>x</i> is −0, the result is −0.</li>
+ <li>If <i>x</i> is +0, the result is +0.</li>
+ <li>If <i>x</i> is +∞, the result is +∞.</li>
+ <li>If x is −∞, the result is −∞.</li>
+ <li>If <i>x</i> is greater than 0 but less than 1, the result is +0.</li>
+ <li>If <i>x</i> is less than 0 but greater than <span style="font-family: sans-serif">−</span>1, the result is
+ <span style="font-family: sans-serif">−</span>0.</li>
+ </ul>
+ </section>
+ </section>
+ </section>
+
+ <section id="sec-date-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-20.3"><a href="#sec-date-objects" title="link to this section">20.3</a></span> Date
+ Objects</h1>
+ </div>
+
+ <section id="sec-overview-of-date-objects-and-definitions-of-abstract-operations">
+ <div class="front">
+ <h1><span class="secnum" id="sec-20.3.1"><a href="#sec-overview-of-date-objects-and-definitions-of-abstract-operations"
+ title="link to this section">20.3.1</a></span> Overview of Date Objects and Definitions of Abstract Operations</h1>
+
+ <p>The following functions are abstract operations that operate on time values (defined in <a
+ href="#sec-time-values-and-time-range">20.3.1.1</a>). Note that, in every case, if any argument to one of these functions
+ is <b>NaN</b>, the result will be <b>NaN</b>.</p>
+ </div>
+
+ <section id="sec-time-values-and-time-range">
+ <h1><span class="secnum" id="sec-20.3.1.1"><a href="#sec-time-values-and-time-range"
+ title="link to this section">20.3.1.1</a></span> Time Values and Time Range</h1>
+
+ <p>A Date object contains a Number indicating a particular instant in time to within a millisecond. Such a Number is
+ called a <i>time value</i>. A time value may also be <b>NaN</b>, indicating that the Date object does not represent a
+ specific instant of time.</p>
+
+ <p>Time is measured in ECMAScript in milliseconds since 01 January, 1970 UTC. In time values leap seconds are ignored. It
+ is assumed that there are exactly 86,400,000 milliseconds per day. ECMAScript Number values can represent all integers
+ from –9,007,199,254,740,992 to 9,007,199,254,740,992; this range suffices to measure times to millisecond precision
+ for any instant that is within approximately 285,616 years, either forward or backward, from 01 January, 1970 UTC.</p>
+
+ <p>The actual range of times supported by ECMAScript Date objects is slightly smaller: exactly –100,000,000 days to
+ 100,000,000 days measured relative to midnight at the beginning of 01 January, 1970 UTC. This gives a range of
+ 8,640,000,000,000,000 milliseconds to either side of 01 January, 1970 UTC.</p>
+
+ <p>The exact moment of midnight at the beginning of 01 January, 1970 UTC is represented by the value <b>+0</b>.</p>
+ </section>
+
+ <section id="sec-day-number-and-time-within-day">
+ <h1><span class="secnum" id="sec-20.3.1.2"><a href="#sec-day-number-and-time-within-day"
+ title="link to this section">20.3.1.2</a></span> Day Number and Time within Day</h1>
+
+ <p>A given <a href="#sec-time-values-and-time-range">time value</a> <i>t</i> belongs to day number</p>
+
+ <div class="display">Day(<i>t</i>) = <a href="#sec-algorithm-conventions">floor</a>(<i>t</i> / msPerDay)</div>
+
+ <p>where the number of milliseconds per day is</p>
+
+ <div class="display">msPerDay = 86400000</div>
+
+ <p>The remainder is called the time within the day:</p>
+
+ <div class="display">TimeWithinDay(<i>t</i>) = <i>t</i> <a href="#sec-algorithm-conventions">modulo</a> msPerDay</div>
+ </section>
+
+ <section id="sec-year-number">
+ <h1><span class="secnum" id="sec-20.3.1.3"><a href="#sec-year-number" title="link to this section">20.3.1.3</a></span>
+ Year Number</h1>
+
+ <p>ECMAScript uses an extrapolated Gregorian system to map a day number to a year number and to determine the month and
+ date within that year. In this system, leap years are precisely those which are (divisible by <span style="font-family:
+ Times New Roman">4</span>) and ((not divisible by <span style="font-family: Times New Roman">100</span>) or (divisible by
+ <span style="font-family: Times New Roman">400</span>)). The number of days in year number <var>y</var> is therefore
+ defined by</p>
+
+ <div class="display">DaysInYear(<i>y</i>) 	= 365 if (<i>y</i> <a href="#sec-algorithm-conventions">modulo</a> 4) ≠ 0<br>= 366 if (<i>y</i> <a href="#sec-algorithm-conventions">modulo</a> 4) = 0 and (<i>y</i> <a href="#sec-algorithm-conventions">modulo</a> 100) ≠ 0<br>= 365 if (<i>y</i> <a href="#sec-algorithm-conventions">modulo</a> 100) = 0 and (<i>y</i> <a href="#sec-algorithm-conventions">modulo</a> 400) ≠ 0<br>= 366 if (<i>y</i> <a href="#sec-algorithm-conventions">modulo</a> 400) = 0</div>
+
+ <p>All non-leap years have <span style="font-family: Times New Roman">365</span> days with the usual number of days per
+ month and leap years have an extra day in February. The day number of the first day of year <var>y</var> is given by:</p>
+
+ <div class="display">DayFromYear(<i>y</i>)	 = 365 × (<i>y</i>−1970) + <a href="#sec-algorithm-conventions">floor</a>((<i>y</i>−1969)/4) − <a href="#sec-algorithm-conventions">floor</a>((<i>y</i>−1901)/100) + <a href="#sec-algorithm-conventions">floor</a>((<i>y</i>−1601)/400)</div>
+
+ <p>The <a href="#sec-time-values-and-time-range">time value</a> of the start of a year is:</p>
+
+ <div class="display">TimeFromYear(<i>y</i>)	 = <a href="#sec-day-number-and-time-within-day">msPerDay</a> × DayFromYear(<i>y</i>)</div>
+
+ <p>A <a href="#sec-time-values-and-time-range">time value</a> determines a year by:</p>
+
+ <div class="display">YearFromTime(<i>t</i>) 	= the largest integer <i>y</i> (closest to positive infinity) such that TimeFromYear(<i>y</i>) ≤ <i>t</i></div>
+
+ <p>The leap-year function is 1 for a time within a leap year and otherwise is zero:</p>
+
+ <div class="display">InLeapYear(<i>t</i>)	= 0 if DaysInYear(YearFromTime(<i>t</i>)) = 365<br>= 1 if DaysInYear(YearFromTime<i>(t</i>)) = 366</div>
+ </section>
+
+ <section id="sec-month-number">
+ <h1><span class="secnum" id="sec-20.3.1.4"><a href="#sec-month-number" title="link to this section">20.3.1.4</a></span>
+ Month Number</h1>
+
+ <p>Months are identified by an integer in the range <span style="font-family: Times New Roman">0</span> to <span
+ style="font-family: Times New Roman">11</span>, inclusive. The mapping MonthFromTime(<i>t</i>) from a <a
+ href="#sec-time-values-and-time-range">time value</a> <i>t</i> to a month number is defined by:</p>
+
+ <div class="display">MonthFromTime(<i>t</i>)	= 0	if	0	≤ DayWithinYear(<i>t</i>) < 31<br>	= 1	if	31 	≤ DayWithinYear (<i>t</i>) < 59+<a href="#sec-year-number">InLeapYear</a>(<i>t</i>)<br>	= 2	if	59+<a href="#sec-year-number">InLeapYear</a>(<i>t</i>) 	≤ DayWithinYear (<i>t</i>) < 90+<a href="#sec-year-number">InLeapYear</a>(<i>t</i>)<br>	= 3	if	90+<a href="#sec-year-number">InLeapYear</a>(<i>t</i>) 	≤ DayWithinYear (<i>t</i>) < 120+<a href="#sec-year-number">InLeapYear</a>(<i>t</i>)<br>	= 4	if	120+<a href="#sec-year-number">InLeapYear</a>(<i>t</i>) 	≤ DayWithinYear (<i>t</i>) < 151+<a href="#sec-year-number">InLeapYear</a>(<i>t</i>)<br>	= 5	if	151+<a href="#sec-year-number">InLeapYear</a>(<i>t</i>) 	≤ DayWithinYear (<i>t</i>) < 181+<a href="#sec-year-number">InLeapYear</a>(<i>t</i>)<br>	= 6	if	181+<a href="#sec-year-number">InLeapYear</a>(<i>t</i>) 	≤ DayWithinYear (<i>t</i>) < 212+<a href="#sec-year-number">InLeapYear</a>(<i>t</i>)<br>	= 7	if	212+<a href="#sec-year-number">InLeapYear</a>(<i>t</i>) 	≤ DayWithinYear (<i>t</i>) < 243+<a href="#sec-year-number">InLeapYear</a>(<i>t</i>)<br>	= 8	if	243+<a href="#sec-year-number">InLeapYear</a>(<i>t</i>) 	≤ DayWithinYear (<i>t</i>) < 273+<a href="#sec-year-number">InLeapYear</a>(<i>t</i>)<br>	= 9	if	273+<a href="#sec-year-number">InLeapYear</a>(<i>t</i>) 	≤ DayWithinYear (<i>t</i>) < 304+<a href="#sec-year-number">InLeapYear</a>(<i>t</i>)<br>	= 10	if	304+<a href="#sec-year-number">InLeapYear</a>(<i>t</i>) 	≤ DayWithinYear (<i>t</i>) < 334+<a href="#sec-year-number">InLeapYear</a>(<i>t</i>)<br>	= 11	if	334+<a href="#sec-year-number">InLeapYear</a>(<i>t</i>) 	≤ DayWithinYear (<i>t</i>) < 365+<a href="#sec-year-number">InLeapYear</a>(<i>t</i>)</div>
+
+ <p>where</p>
+
+ <div class="display">DayWithinYear(<i>t</i>)	= <a href="#sec-day-number-and-time-within-day">Day</a>(<i>t</i>)−DayFromYear(<a href="#sec-year-number">YearFromTime</a>(<i>t)</i>)</div>
+
+ <p>A month value of <span style="font-family: Times New Roman">0</span> specifies January; <span style="font-family: Times
+ New Roman">1</span> specifies February; <span style="font-family: Times New Roman">2</span> specifies March; <span
+ style="font-family: Times New Roman">3</span> specifies April; <span style="font-family: Times New
+ Roman">4</span> specifies May; <span style="font-family: Times New Roman">5</span> specifies June; <span
+ style="font-family: Times New Roman">6</span> specifies July; <span style="font-family: Times New Roman">7</span>
+ specifies August; <span style="font-family: Times New Roman">8</span> specifies September; <span style="font-family: Times
+ New Roman">9</span> specifies October; <span style="font-family: Times New Roman">10</span> specifies November; and <span
+ style="font-family: Times New Roman">11</span> specifies December. Note that <span style="font-family: Times New
+ Roman">MonthFromTime(0) = 0</span>, corresponding to Thursday, 01 January, 1970.</p>
+ </section>
+
+ <section id="sec-date-number">
+ <h1><span class="secnum" id="sec-20.3.1.5"><a href="#sec-date-number" title="link to this section">20.3.1.5</a></span>
+ Date Number</h1>
+
+ <p>A date number is identified by an integer in the range <span style="font-family: Times New Roman">1</span> through
+ <span style="font-family: Times New Roman">31</span>, inclusive. The mapping DateFromTime(<i>t</i>) from a <a
+ href="#sec-time-values-and-time-range">time value</a> <i>t</i> to a month number is defined by:</p>
+
+ <div class="display">DateFromTime(<i>t</i>)	= <a href="#sec-month-number">DayWithinYear</a>(<i>t</i>)+1		if <a href="#sec-month-number">MonthFromTime</a>(<i>t</i>)=0<br>		= <a href="#sec-month-number">DayWithinYear</a>(<i>t</i>)−30		if <a href="#sec-month-number">MonthFromTime</a>(<i>t</i>)=1<br>		= <a href="#sec-month-number">DayWithinYear</a>(<i>t</i>)−58−<a href="#sec-year-number">InLeapYear</a>(<i>t</i>)	if <a href="#sec-month-number">MonthFromTime</a>(<i>t</i>)=2<br>		= <a href="#sec-month-number">DayWithinYear</a>(<i>t</i>)−89−<a href="#sec-year-number">InLeapYear</a>(<i>t</i>)	if <a href="#sec-month-number">MonthFromTime</a>(<i>t</i>)=3<br>		= <a href="#sec-month-number">DayWithinYear</a>(<i>t</i>)−119−<a href="#sec-year-number">InLeapYear</a>(<i>t</i>)	if <a href="#sec-month-number">MonthFromTime</a>(<i>t</i>)=4<br>		= <a href="#sec-month-number">DayWithinYear</a>(<i>t</i>)−150−<a href="#sec-year-number">InLeapYear</a>(<i>t</i>)	if <a href="#sec-month-number">MonthFromTime</a>(<i>t</i>)=5<br>		= <a href="#sec-month-number">DayWithinYear</a>(<i>t</i>)−180−<a href="#sec-year-number">InLeapYear</a>(<i>t</i>)	if <a href="#sec-month-number">MonthFromTime</a>(<i>t</i>)=6<br>		= <a href="#sec-month-number">DayWithinYear</a>(<i>t</i>)−211−<a href="#sec-year-number">InLeapYear</a>(<i>t</i>)	if <a href="#sec-month-number">MonthFromTime</a>(<i>t</i>)=7<br>		= <a href="#sec-month-number">DayWithinYear</a>(<i>t</i>)−242−<a href="#sec-year-number">InLeapYear</a>(<i>t</i>)	if <a href="#sec-month-number">MonthFromTime</a>(<i>t</i>)=8<br>		= <a href="#sec-month-number">DayWithinYear</a>(<i>t</i>)−272−<a href="#sec-year-number">InLeapYear</a>(<i>t</i>)	if <a href="#sec-month-number">MonthFromTime</a>(<i>t</i>)=9<br>		= <a href="#sec-month-number">DayWithinYear</a>(<i>t</i>)−303−<a href="#sec-year-number">InLeapYear</a>(<i>t</i>)	if <a href="#sec-month-number">MonthFromTime</a>(<i>t</i>)=10<br>		= <a href="#sec-month-number">DayWithinYear</a>(<i>t</i>)−333−<a href="#sec-year-number">InLeapYear</a>(<i>t</i>)	if <a href="#sec-month-number">MonthFromTime</a>(<i>t</i>)=11</div>
+ </section>
+
+ <section id="sec-week-day">
+ <h1><span class="secnum" id="sec-20.3.1.6"><a href="#sec-week-day" title="link to this section">20.3.1.6</a></span> Week
+ Day</h1>
+
+ <p>The weekday for a particular <a href="#sec-time-values-and-time-range">time value</a> <var>t</var> is defined as</p>
+
+ <div class="display">WeekDay(<i>t</i>)	 = (<a href="#sec-day-number-and-time-within-day">Day</a>(<i>t</i>) + 4) <a href="#sec-algorithm-conventions">modulo</a> 7</div>
+
+ <p>A weekday value of <span style="font-family: Times New Roman">0</span> specifies Sunday; <span style="font-family:
+ Times New Roman">1</span> specifies Monday; <span style="font-family: Times New Roman">2</span> specifies Tuesday; <span
+ style="font-family: Times New Roman">3</span> specifies Wednesday; <span style="font-family: Times New
+ Roman">4</span> specifies Thursday; <span style="font-family: Times New Roman">5</span> specifies Friday; and <span
+ style="font-family: Times New Roman">6</span> specifies Saturday. Note that <span style="font-family: Times New
+ Roman">WeekDay(0) = 4</span>, corresponding to Thursday, 01 January, 1970.</p>
+ </section>
+
+ <section id="sec-local-time-zone-adjustment">
+ <h1><span class="secnum" id="sec-20.3.1.7"><a href="#sec-local-time-zone-adjustment"
+ title="link to this section">20.3.1.7</a></span> Local Time Zone Adjustment</h1>
+
+ <p>An implementation of ECMAScript is expected to determine the local time zone adjustment. The local time zone adjustment
+ is a value LocalTZA measured in milliseconds which when added to UTC represents the local <i>standard</i> time. Daylight
+ saving time is <i>not</i> reflected by LocalTZA.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> It is recommended that implementations use the time zone information of the IANA Time
+ Zone Database.</p>
+ </div>
+ </section>
+
+ <section id="sec-daylight-saving-time-adjustment">
+ <h1><span class="secnum" id="sec-20.3.1.8"><a href="#sec-daylight-saving-time-adjustment"
+ title="link to this section">20.3.1.8</a></span> Daylight Saving Time Adjustment</h1>
+
+ <p>An implementation dependent algorithm using best available information on time zones to determine the local daylight
+ saving time adjustment DaylightSavingTA(<i>t</i>), measured in milliseconds. An implementation of ECMAScript is expected
+ to make its best effort to determine the local daylight saving time adjustment.</p>
+ </section>
+
+ <section id="sec-local-time">
+ <h1><span class="secnum" id="sec-20.3.1.9"><a href="#sec-local-time" title="link to this section">20.3.1.9</a></span>
+ Local Time</h1>
+
+ <p>Conversion from UTC to local time is defined by</p>
+
+ <div class="display">LocalTime(<i>t</i>) = <i>t</i> + <a href="#sec-local-time-zone-adjustment">LocalTZA</a> + <a href="#sec-daylight-saving-time-adjustment">DaylightSavingTA</a>(<i>t</i>)</div>
+
+ <p>Conversion from local time to UTC is defined by</p>
+
+ <div class="display">UTC(<i>t</i>) = <i>t</i> – <a href="#sec-local-time-zone-adjustment">LocalTZA</a> – <a href="#sec-daylight-saving-time-adjustment">DaylightSavingTA</a>(<i>t</i> – <a href="#sec-local-time-zone-adjustment">LocalTZA</a>)</div>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> UTC(LocalTime(<i>t</i>)) is not necessarily always equal to <i>t</i>.</p>
+ </div>
+ </section>
+
+ <section id="sec-hours-minutes-second-and-milliseconds">
+ <h1><span class="secnum" id="sec-20.3.1.10"><a href="#sec-hours-minutes-second-and-milliseconds"
+ title="link to this section">20.3.1.10</a></span> Hours, Minutes, Second, and Milliseconds</h1>
+
+ <p>The following functions are useful in decomposing time values:</p>
+
+ <div class="display">HourFromTime(<i>t</i>)	= <a href="#sec-algorithm-conventions">floor</a>(<i>t</i> / msPerHour) <a href="#sec-algorithm-conventions">modulo</a> HoursPerDay</div>
+ <div class="display">MinFromTime(<i>t</i>)	= <a href="#sec-algorithm-conventions">floor</a>(<i>t</i> / msPerMinute) <a href="#sec-algorithm-conventions">modulo</a> MinutesPerHour</div>
+ <div class="display">SecFromTime(<i>t</i>)	= <a href="#sec-algorithm-conventions">floor</a>(<i>t</i> / msPerSecond) <a href="#sec-algorithm-conventions">modulo</a> SecondsPerMinute</div>
+ <div class="display">msFromTime(<i>t</i>)	= <i>t</i> <a href="#sec-algorithm-conventions">modulo</a> msPerSecond</div>
+
+ <p>where</p>
+
+ <div class="display">HoursPerDay	= 24</div>
+ <div class="display">MinutesPerHour	= 60</div>
+ <div class="display">SecondsPerMinute	= 60</div>
+ <div class="display">msPerSecond	= 1000</div>
+ <div class="display">msPerMinute	= 60000	= msPerSecond × SecondsPerMinute</div>
+ <div class="display">msPerHour	= 3600000	= msPerMinute × MinutesPerHour</div>
+ </section>
+
+ <section id="sec-maketime">
+ <h1><span class="secnum" id="sec-20.3.1.11"><a href="#sec-maketime" title="link to this section">20.3.1.11</a></span>
+ MakeTime (hour, min, sec, ms)</h1>
+
+ <p>The operator MakeTime calculates a number of milliseconds from its four arguments, which must be ECMAScript Number
+ values. This operator functions as follows:</p>
+
+ <ol class="proc">
+ <li>If <i>hour</i> is not finite or <i>min</i> is not finite or <i>sec</i> is not finite or <i>ms</i> is not finite,
+ return <b>NaN</b>.</li>
+ <li>Let <i>h</i> be <a href="#sec-tointeger">ToInteger</a>(<i>hour</i>).</li>
+ <li>Let <i>m</i> be <a href="#sec-tointeger">ToInteger</a>(<i>min</i>).</li>
+ <li>Let <i>s</i> be <a href="#sec-tointeger">ToInteger</a>(<i>sec</i>).</li>
+ <li>Let <i>milli</i> be <a href="#sec-tointeger">ToInteger</a>(<i>ms</i>).</li>
+ <li>Let <i>t</i> be <i>h</i> <code>*</code> <a href="#sec-hours-minutes-second-and-milliseconds">msPerHour</a>
+ <code>+</code> <i>m</i> <code>*</code> <a href="#sec-hours-minutes-second-and-milliseconds">msPerMinute</a>
+ <code>+</code> <i>s</i> <code>*</code> <a href="#sec-hours-minutes-second-and-milliseconds">msPerSecond</a>
+ <code>+</code> <i>milli</i>, performing the arithmetic according to IEEE 754 rules (that is, as if using the
+ ECMAScript operators <code>*</code> and <code>+</code>).</li>
+ <li>Return <i>t</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-makeday">
+ <h1><span class="secnum" id="sec-20.3.1.12"><a href="#sec-makeday" title="link to this section">20.3.1.12</a></span>
+ MakeDay (year, month, date)</h1>
+
+ <p>The operator MakeDay calculates a number of days from its three arguments, which must be ECMAScript Number values. This
+ operator functions as follows:</p>
+
+ <ol class="proc">
+ <li>If <i>year</i> is not finite or <i>month</i> is not finite or <i>date</i> is not finite, return <b>NaN</b>.</li>
+ <li>Let <i>y</i> be <a href="#sec-tointeger">ToInteger</a>(<i>year</i>).</li>
+ <li>Let <i>m</i> be <a href="#sec-tointeger">ToInteger</a>(<i>month</i>).</li>
+ <li>Let <i>dt</i> be <a href="#sec-tointeger">ToInteger</a>(<i>date</i>).</li>
+ <li>Let <i>ym</i> be <i>y</i> + <a href="#sec-algorithm-conventions">floor</a>(<i>m</i> /12).</li>
+ <li>Let <i>mn</i> be <i>m</i> <a href="#sec-algorithm-conventions">modulo</a> 12.</li>
+ <li>Find a value <i>t</i> such that <a href="#sec-year-number">YearFromTime</a>(<i>t</i>) is <i>ym</i> and <a
+ href="#sec-month-number">MonthFromTime</a>(<i>t</i>) is <i>mn</i> and <a
+ href="#sec-date-number">DateFromTime</a>(<i>t</i>) is 1; but if this is not possible (because some argument is out
+ of range), return <b>NaN</b>.</li>
+ <li>Return <a href="#sec-day-number-and-time-within-day">Day</a>(<i>t</i>) + <i>dt</i> − 1.</li>
+ </ol>
+ </section>
+
+ <section id="sec-makedate">
+ <h1><span class="secnum" id="sec-20.3.1.13"><a href="#sec-makedate" title="link to this section">20.3.1.13</a></span>
+ MakeDate (day, time)</h1>
+
+ <p>The operator MakeDate calculates a number of milliseconds from its two arguments, which must be ECMAScript Number
+ values. This operator functions as follows:</p>
+
+ <ol class="proc">
+ <li>If <i>day</i> is not finite or <i>time</i> is not finite, return <b>NaN</b>.</li>
+ <li>Return <i>day</i> × <a href="#sec-day-number-and-time-within-day">msPerDay</a> + <i>time</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-timeclip">
+ <h1><span class="secnum" id="sec-20.3.1.14"><a href="#sec-timeclip" title="link to this section">20.3.1.14</a></span>
+ TimeClip (time)</h1>
+
+ <p>The operator TimeClip calculates a number of milliseconds from its argument, which must be an ECMAScript Number value.
+ This operator functions as follows:</p>
+
+ <ol class="proc">
+ <li>If <i>time</i> is not finite, return <b>NaN</b>.</li>
+ <li>If <a href="#sec-algorithm-conventions">abs</a>(<i>time</i>) > 8.64 <span style="font-family:
+ sans-serif">×</span> 10<sup>15</sup>, return <b>NaN</b>.</li>
+ <li>Return <a href="#sec-tointeger">ToInteger</a>(<i>time</i>) + (<b>+0</b>). (Adding a positive zero converts
+ <b>−0</b> to <b>+0</b>.)</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The point of step 3 is that an implementation is permitted a choice of internal
+ representations of time values, for example as a 64-bit signed integer or as a 64-bit floating-point value. Depending on
+ the implementation, this internal representation may or may not distinguish <b>−0</b> and <b>+0</b>.</p>
+ </div>
+ </section>
+
+ <section id="sec-date-time-string-format">
+ <div class="front">
+ <h1><span class="secnum" id="sec-20.3.1.15"><a href="#sec-date-time-string-format"
+ title="link to this section">20.3.1.15</a></span> Date Time String Format</h1>
+
+ <p>ECMAScript defines a string interchange format for date-times based upon a simplification of the ISO 8601 Extended
+ Format. The format is as follows: <code>YYYY-MM-DDTHH:mm:ss.sss<i>Z</i></code></p>
+
+ <p>Where the fields are as follows:</p>
+
+ <p><code>YYYY</code>	<span style="font-family: sans-serif">is the decimal digits of the year 0000 to 9999 in the
+ Gregorian calendar.</span></p>
+
+ <p><code>-</code>	<span style="font-family: sans-serif">“</span><code>-</code><span style="font-family:
+ sans-serif">” (hyphen) appears literally twice in the string.</span></p>
+
+ <p><code>MM</code>	<span style="font-family: sans-serif">is the month of the year from 01 (January) to 12
+ (December).</span></p>
+
+ <p><code>DD</code>	<span style="font-family: sans-serif">is the day of the month from 01 to 31.</span></p>
+
+ <p><code>T</code>	<span style="font-family: sans-serif">“</span><code>T</code><span style="font-family:
+ sans-serif">” appears literally in the string, to indicate the beginning of the time element.</span></p>
+
+ <p><code>HH</code>	<span style="font-family: sans-serif">is the number of complete hours that have passed since
+ midnight as two decimal digits from 00 to 24.</span></p>
+
+ <p><code>:</code>	<span style="font-family: sans-serif">“</span><code>:</code><span style="font-family:
+ sans-serif">” (colon) appears literally twice in the string.</span></p>
+
+ <p><code>mm</code>	<span style="font-family: sans-serif">is the number of complete minutes since the start of the
+ hour as two decimal digits from 00 to 59.</span></p>
+
+ <p><code>ss</code>	<span style="font-family: sans-serif">is the number of complete seconds since the start of the
+ minute as two decimal digits from 00 to 59.</span></p>
+
+ <p><code>.</code>	<span style="font-family: sans-serif">“</span><code>.</code><span style="font-family:
+ sans-serif">” (dot) appears literally in the string.</span></p>
+
+ <p><code>sss</code>	<span style="font-family: sans-serif">is the number of complete milliseconds since the start of
+ the second as three decimal digits.</span></p>
+
+ <p><code>Z</code>	<span style="font-family: sans-serif">is the time zone offset specified as
+ “</span><code>Z</code><span style="font-family: sans-serif">” (for UTC) or either
+ “</span><code>+</code><span style="font-family: sans-serif">” or “</span><code>-</code><span
+ style="font-family: sans-serif">” followed by a time expression</span> <code>HH:mm</code></p>
+
+ <p>This format includes date-only forms:</p>
+
+ <pre>YYYY<br>YYYY-MM<br>YYYY-MM-DD</pre>
+
+ <p>It also includes “date-time” forms that consist of one of the above date-only forms immediately followed
+ by one of the following time forms with an optional time zone offset appended:</p>
+
+ <pre>THH:mm<br>THH:mm:ss<br>THH:mm:ss.sss</pre>
+
+ <p>All numbers must be base <span style="font-family: Times New Roman">10</span>. If the <code>MM</code> or
+ <code>DD</code> fields are absent “<code>01</code>” is used as the value. If the <code>HH</code>,
+ <code>mm</code>, or <code>ss</code> fields are absent “<code>00</code>” is used as the value and the value
+ of an absent <code>sss</code> field is “<code>000</code>”. If the time zone offset is absent, the date-time
+ is interpreted as a local time.</p>
+
+ <p>Illegal values (out-of-bounds as well as syntax errors) in a format string means that the format string is not a
+ valid instance of this format.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> As every day both starts and ends with midnight, the two notations
+ <code>00:00</code> and <code>24:00</code> are available to distinguish the two midnights that can be associated with
+ one date. This means that the following two notations refer to exactly the same point in time:
+ <code>1995-02-04T24:00</code> and <code>1995-02-05T00:00</code></p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 2</span> There exists no international standard that specifies abbreviations for civil time
+ zones like CET, EST, etc. and sometimes the same abbreviation is even used for two very different time zones. For this
+ reason, ISO 8601 and this format specifies numeric representations of date and time.</p>
+ </div>
+ </div>
+
+ <section id="sec-extended-years">
+ <h1><span class="secnum" id="sec-20.3.1.15.1"><a href="#sec-extended-years"
+ title="link to this section">20.3.1.15.1</a></span> Extended years</h1>
+
+ <p>ECMAScript requires the ability to specify <span style="font-family: Times New Roman">6</span> digit years (extended
+ years); approximately <span style="font-family: Times New Roman">285,426</span> years, either forward or backward, from
+ 01 January, 1970 UTC. To represent years before <span style="font-family: Times New Roman">0</span> or after <span
+ style="font-family: Times New Roman">9999</span>, ISO 8601 permits the expansion of the year representation, but only by
+ prior agreement between the sender and the receiver. In the simplified ECMAScript format such an expanded year
+ representation shall have <span style="font-family: Times New Roman">2</span> extra year digits and is always prefixed
+ with a + or – sign. The year <span style="font-family: Times New Roman">0</span> is considered positive and hence
+ prefixed with a + sign.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Examples of extended years:</p>
+
+ <p>-283457-03-21T15:00:59.008Z	283458 B.C.<span style="font-family: Times New
+ Roman"><br></span>-000001-01-01T00:00:00Z	2 B.C.<span style="font-family: Times New
+ Roman"><br></span>+000000-01-01T00:00:00Z	1 B.C.<span style="font-family: Times New
+ Roman"><br></span>+000001-01-01T00:00:00Z	1 A.D.<span style="font-family: Times New
+ Roman"><br></span>+001970-01-01T00:00:00Z	1970 A.D.<span style="font-family: Times New
+ Roman"><br></span>+002009-12-15T00:00:00Z	2009 A.D.<span style="font-family: Times New
+ Roman"><br></span>+287396-10-12T08:59:00.992Z	287396 A.D.</p>
+ </div>
+ </section>
+ </section>
+ </section>
+
+ <section id="sec-date-constructor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-20.3.2"><a href="#sec-date-constructor" title="link to this section">20.3.2</a></span>
+ The Date Constructor</h1>
+
+ <p>The Date constructor is the %Date% intrinsic object and the initial value of the <code>Date</code> property of the
+ global object. When <code>Date</code> is called as a function rather than as a constructor, it returns a String
+ representing the current time (UTC). However, if the <b>this</b> value passed in the call is an Object with an
+ uninitialized [[DateValue]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, <code>Date</code>
+ initializes the <b>this</b> object using the argument value. This permits <code>Date</code> to be used both as a function
+ for creating data strings and to perform constructor instance initialization.</p>
+
+ <p>The <code>Date</code> constructor is designed to be subclassable. It may be used as the value of an
+ <code>extends</code> clause of a class declaration. Subclass constructors that intended to inherit the specified
+ <code>Date</code> behaviour must include a <code>super</code> call to the <code>Date</code> constructor to initialize the
+ [[DateValue]] state of subclass instances.</p>
+ </div>
+
+ <section id="sec-date-year-month-date-hours-minutes-seconds-ms">
+ <h1><span class="secnum" id="sec-20.3.2.1"><a href="#sec-date-year-month-date-hours-minutes-seconds-ms"
+ title="link to this section">20.3.2.1</a></span> Date ( year, month [, date [ , hours [ , minutes [ , seconds [ , ms ]
+ ] ] ] ] )</h1>
+
+ <p>This description applies only if the Date constructor is called with at least two arguments.</p>
+
+ <p>When the <code>Date</code> function is called the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>numberOfArgs</i> be the number of arguments passed to this function call.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>numberOfArgs</i> ≥ 2.</li>
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is Object and <i>O</i> has a [[DateValue]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> and the value of [[DateValue]] is
+ <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>y</i> be <a href="#sec-tonumber">ToNumber</a>(<i>year</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>year</i>).</li>
+ <li>Let <i>m</i> be <a href="#sec-tonumber">ToNumber</a>(<i>month</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>month</i>).</li>
+ <li>If <i>date</i> is supplied then let <i>dt</i> be <a href="#sec-tonumber">ToNumber</a>(<i>date</i>); else let
+ <i>dt</i> be <b>1</b>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>dt</i>).</li>
+ <li>If <i>hours</i> is supplied then let <i>h</i> be <a href="#sec-tonumber">ToNumber</a>(<i>hours</i>); else let
+ <i>h</i> be <b>0</b>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>h</i>).</li>
+ <li>If <i>minutes</i> is supplied then let <i>min</i> be <a href="#sec-tonumber">ToNumber</a>(<i>minutes</i>); else
+ let <i>min</i> be <b>0</b>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>min</i>).</li>
+ <li>If <i>seconds</i> is supplied then let <i>s</i> be <a href="#sec-tonumber">ToNumber</a>(<i>seconds</i>); else
+ let <i>s</i> be <b>0</b>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>s</i>).</li>
+ <li>If <i>ms</i> is supplied then let <i>milli</i> be <a href="#sec-tonumber">ToNumber</a>(<i>ms</i>); else let
+ <i>milli</i> be <b>0</b>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>milli</i>).</li>
+ <li>If <i>y</i> is not <b>NaN</b> and 0 ≤ <a
+ href="#sec-tointeger">ToInteger</a>(<i>y</i>) ≤ 99, then let <i>yr</i> be 1900+<a
+ href="#sec-tointeger">ToInteger</a>(<i>y</i>); otherwise, let <i>yr</i> be <i>y</i>.</li>
+ <li>Let <i>finalDate</i> be <a href="#sec-makedate">MakeDate</a>(<a href="#sec-makeday">MakeDay</a>(<i>yr</i>,
+ <i>m</i>, <i>dt</i>), <a href="#sec-maketime">MakeTime</a>(<i>h</i>, <i>min</i>, <i>s</i>, <i>milli</i>)).</li>
+ <li>Set the [[DateValue]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i> to
+ <a href="#sec-timeclip">TimeClip</a>(<a href="#sec-local-time">UTC</a>(<i>finalDate</i>)).</li>
+ <li>Return <i>O</i>.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>now</i> be the Number that is the <a href="#sec-time-values-and-time-range">time value</a> (UTC)
+ identifying the current time.</li>
+ <li>Return <a href="#sec-todatestring">ToDateString</a> (<i>now</i>).</li>
+ </ol>
+ </li>
+ </ol>
+ </section>
+
+ <section id="sec-date-value">
+ <h1><span class="secnum" id="sec-20.3.2.2"><a href="#sec-date-value" title="link to this section">20.3.2.2</a></span> Date
+ ( value )</h1>
+
+ <p>This description applies only if the Date constructor is called with exactly one argument.</p>
+
+ <p>When the <code>Date</code> function is called the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>numberOfArgs</i> be the number of arguments passed to this function call.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>numberOfArgs</i> = 1.</li>
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is Object and <i>O</i> has a [[DateValue]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> and the value of [[DateValue]] is
+ <b>undefined</b>, then
+ <ol class="block">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>value</i>) is Object and <i>value</i> has a
+ [[DateValue]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, then
+ <ol class="block">
+ <li>Let <i>tv</i> be thisTimeValue(<i>value</i>).</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>v</i> be <a href="#sec-toprimitive">ToPrimitive</a>(<i>value</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>v</i>) is String, then
+ <ol class="block">
+ <li>Let <i>tv</i> be the result of parsing <i>v</i> as a date, in exactly the same manner as for the
+ <code>parse</code> method (<a href="#sec-date.parse">20.3.3.2</a>). If the parse resulted in an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a>, <i>tv</i> is the <a
+ href="#sec-completion-record-specification-type">Completion Record</a>.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>tv</i> be <a href="#sec-tonumber">ToNumber</a>(<i>v</i>).</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>tv</i>).</li>
+ <li>Set the [[DateValue]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i> to
+ <a href="#sec-timeclip">TimeClip</a>(<i>tv</i>).</li>
+ <li>Return <i>O</i>.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>now</i> be the Number that is the <a href="#sec-time-values-and-time-range">time value</a> (UTC)
+ identifying the current time.</li>
+ <li>Return <a href="#sec-todatestring">ToDateString</a> (<i>now</i>).</li>
+ </ol>
+ </li>
+ </ol>
+ </section>
+
+ <section id="sec-date-constructor-date">
+ <h1><span class="secnum" id="sec-20.3.2.3"><a href="#sec-date-constructor-date"
+ title="link to this section">20.3.2.3</a></span> Date ( )</h1>
+
+ <p>This description applies only if the Date constructor is called with no arguments.</p>
+
+ <p>When the <code>Date</code> function is called the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>numberOfArgs</i> be the number of arguments passed to this function call.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>numberOfArgs</i> = 0.</li>
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is Object and <i>O</i> has a [[DateValue]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> and the value of [[DateValue]] is
+ <b>undefined</b>, then
+ <ol class="block">
+ <li>Set the [[DateValue]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i> to
+ the <a href="#sec-time-values-and-time-range">time value</a> (UTC) identifying the current time.</li>
+ <li>Return <i>O</i>.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>now</i> be the Number that is the <a href="#sec-time-values-and-time-range">time value</a> (UTC)
+ identifying the current time.</li>
+ <li>Return <a href="#sec-todatestring">ToDateString</a> (<i>now</i>).</li>
+ </ol>
+ </li>
+ </ol>
+ </section>
+
+ <section id="sec-new-date-argumentslist">
+ <h1><span class="secnum" id="sec-20.3.2.4"><a href="#sec-new-date-argumentslist"
+ title="link to this section">20.3.2.4</a></span> new Date ( ...argumentsList )</h1>
+
+ <p>When <code>Date</code> is called as part of a new expression with argument list <var>argumentsList</var> it performs
+ the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be the <code>Date</code> function object on which the <code>new</code> operator was applied.</li>
+ <li>Let <i>argumentsList</i> be the <i>argumentsList</i> argument of the [[Construct]] internal method that was invoked
+ by the <code>new</code> operator.</li>
+ <li>Return <a href="#sec-construct-f-argumentslist">Construct</a> (<i>F</i>, <i>argumentsList</i>).</li>
+ </ol>
+
+ <p>If <code>Date</code> is implemented as an <a href="#sec-ecmascript-function-objects">ECMAScript function object</a>,
+ its [[Construct]] internal method will perform the above steps.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-date-constructor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-20.3.3"><a href="#sec-properties-of-the-date-constructor"
+ title="link to this section">20.3.3</a></span> Properties of the Date Constructor</h1>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the Date
+ constructor is the Function prototype object (<a href="#sec-properties-of-the-function-prototype-object">19.2.3</a>).</p>
+
+ <p>Besides the <code>length</code> property (whose value is <code>7</code>), the Date constructor has the following
+ properties:</p>
+ </div>
+
+ <section id="sec-date.now">
+ <h1><span class="secnum" id="sec-20.3.3.1"><a href="#sec-date.now" title="link to this section">20.3.3.1</a></span>
+ Date.now ( )</h1>
+
+ <p>The <code>now</code> function return a Number value that is the <a href="#sec-time-values-and-time-range">time
+ value</a> designating the UTC date and time of the occurrence of the call to <code>now</code>.</p>
+ </section>
+
+ <section id="sec-date.parse">
+ <h1><span class="secnum" id="sec-20.3.3.2"><a href="#sec-date.parse" title="link to this section">20.3.3.2</a></span>
+ Date.parse ( string )</h1>
+
+ <p>The <code>parse</code> function applies the <a href="#sec-tostring">ToString</a> operator to its argument. If <a
+ href="#sec-tostring">ToString</a> results in an <a href="#sec-completion-record-specification-type">abrupt completion</a>
+ the <a href="#sec-completion-record-specification-type">Completion Record</a> is immediately returned. Otherwise,
+ <code>parse</code> interprets the resulting String as a date and time; it returns a Number, the UTC <a
+ href="#sec-time-values-and-time-range">time value</a> corresponding to the date and time. The String may be interpreted as
+ a local time, a UTC time, or a time in some other time zone, depending on the contents of the String. The function first
+ attempts to parse the format of the String according to the rules (including extended years) called out in Date Time
+ String Format (<a href="#sec-date-time-string-format">20.3.1.15</a>). If the String does not conform to that format the
+ function may fall back to any implementation-specific heuristics or implementation-specific date formats. Unrecognizable
+ Strings or dates containing illegal element values in the format String shall cause <code>Date.parse</code> to return
+ <b>NaN</b>.</p>
+
+ <p>If <var>x</var> is any Date object whose milliseconds amount is zero within a particular implementation of ECMAScript,
+ then all of the following expressions should produce the same numeric value in that implementation, if all the properties
+ referenced have their initial values:</p>
+
+ <pre><i>x</i>.valueOf()</pre>
+ <pre>Date.parse(<i>x</i>.toString())</pre>
+ <pre>Date.parse(<i>x</i>.toUTCString())</pre>
+ <pre>Date.parse(<i>x</i>.toISOString())</pre>
+
+ <p>However, the expression</p>
+
+ <pre>Date.parse(<i>x</i>.toLocaleString())</pre>
+
+ <p>is not required to produce the same Number value as the preceding three expressions and, in general, the value produced
+ by <code>Date.parse</code> is implementation-dependent when given any String value that does not conform to the Date Time
+ String Format (<a href="#sec-date-time-string-format">20.3.1.15</a>) and that could not be produced in that implementation
+ by the <code>toString</code> or <code>toUTCString</code> method.</p>
+ </section>
+
+ <section id="sec-date.prototype">
+ <h1><span class="secnum" id="sec-20.3.3.3"><a href="#sec-date.prototype" title="link to this section">20.3.3.3</a></span>
+ Date.prototype</h1>
+
+ <p>The initial value of <code>Date.prototype</code> is the built-in Date prototype object (<a
+ href="#sec-properties-of-the-date-prototype-object">20.3.4</a>).</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-date.utc">
+ <h1><span class="secnum" id="sec-20.3.3.4"><a href="#sec-date.utc" title="link to this section">20.3.3.4</a></span>
+ Date.UTC ( year, month [ , date [ , hours [ , minutes [ , seconds [ , ms ] ] ] ] ] )</h1>
+
+ <p>When the <code>UTC</code> function is called with fewer than two arguments, the behaviour is implementation-dependent.
+ When the <code>UTC</code> function is called with two to seven arguments, it computes the date from <var>year</var>,
+ <var>month</var> and (optionally) <var>date</var>, <var>hours</var>, <var>minutes</var>, <var>seconds</var> and
+ <var>ms</var>. The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>y</i> be <a href="#sec-tonumber">ToNumber</a>(<i>year</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>y</i>).</li>
+ <li>Let <i>m</i> be <a href="#sec-tonumber">ToNumber</a>(<i>month</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>m</i>).</li>
+ <li>If <i>date</i> is supplied then let <i>dt</i> be <a href="#sec-tonumber">ToNumber</a>(<i>date</i>); else let
+ <i>dt</i> be <b>1</b>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>dt</i>).</li>
+ <li>If <i>hours</i> is supplied then let <i>h</i> be <a href="#sec-tonumber">ToNumber</a>(<i>hours</i>); else let
+ <i>h</i> be <b>0</b>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>h</i>).</li>
+ <li>If <i>minutes</i> is supplied then let <i>min</i> be <a href="#sec-tonumber">ToNumber</a>(<i>minutes</i>); else let
+ <i>min</i> be <b>0</b>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>min</i>).</li>
+ <li>If <i>seconds</i> is supplied then let <i>s</i> be <a href="#sec-tonumber">ToNumber</a>(<i>seconds</i>); else let
+ <i>s</i> be <b>0</b>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>s</i>).</li>
+ <li>If <i>ms</i> is supplied then let <i>milli</i> be <a href="#sec-tonumber">ToNumber</a>(<i>ms</i>); else let
+ <i>milli</i> be <b>0</b>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>milli</i>).</li>
+ <li>If <i>y</i> is not <b>NaN</b> and 0 ≤ <a
+ href="#sec-tointeger">ToInteger</a>(<i>y</i>) ≤ 99, then let <i>yr</i> be 1900+<a
+ href="#sec-tointeger">ToInteger</a>(<i>y</i>); otherwise, let <i>yr</i> be <i>y</i>.</li>
+ <li>Return <a href="#sec-timeclip">TimeClip</a>(<a href="#sec-makedate">MakeDate</a>(<a
+ href="#sec-makeday">MakeDay</a>(<i>yr</i>, <i>m</i>, <i>dt</i>), <a href="#sec-maketime">MakeTime</a>(<i>h</i>,
+ <i>min</i>, <i>s</i>, <i>milli</i>))).</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>UTC</code> function is <b>7</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>UTC</code> function differs from the <code>Date</code> constructor in two
+ ways: it returns a <a href="#sec-time-values-and-time-range">time value</a> as a Number, rather than creating a Date
+ object, and it interprets the arguments in UTC rather than as local time.</p>
+ </div>
+ </section>
+
+ <section id="sec-date-@@create">
+ <h1><span class="secnum" id="sec-20.3.3.5"><a href="#sec-date-@@create" title="link to this section">20.3.3.5</a></span>
+ Date[ @@create ] ( )</h1>
+
+ <p>The @@create method of an object <var>F</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>obj</i> be <a href="#sec-ordinarycreatefromconstructor">OrdinaryCreateFromConstructor</a>(<i>F</i>,
+ <code>"%DatePrototype%"</code>, ( [[DateValue]])).</li>
+ <li>Return <i>obj</i>.</li>
+ </ol>
+
+ <p>The value of the <code>name</code> property of this function is <code>"[Symbol.create]"</code>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <span class="value">false</span>, [[Enumerable]]: <span
+ class="value">false</span>, [[Configurable]]: <span class="value">true</span> }.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> [[DateValue]] is initially assigned the value <b>undefined</b> as a flag to indicate
+ that the instance has not yet been initialized by the Date constructor. This flag value is never directly exposed to
+ ECMAScript code; hence implementations may choose to encode the flag in some other manner.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-date-prototype-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-20.3.4"><a href="#sec-properties-of-the-date-prototype-object"
+ title="link to this section">20.3.4</a></span> Properties of the Date Prototype Object</h1>
+
+ <p>The Date prototype object is itself an ordinary object. It is not a Date instance and does not have a [[DateValue]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</p>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the Date
+ prototype object is the standard built-in Object prototype object (<a
+ href="#sec-properties-of-the-date-prototype-object">20.3.4</a>).</p>
+
+ <p>Unless explicitly defined otherwise, the methods of the Date prototype object defined below are not generic and the
+ <b>this</b> value passed to them must be an object that has a [[DateValue]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> that has been initialized to a <a
+ href="#sec-time-values-and-time-range">time value</a>.</p>
+
+ <p>The abstract operation <span style="font-family: Times New Roman">thisTimeValue(<i>value</i>)</span> performs the
+ following steps:</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>value)</i> is Object and <i>value</i> has a
+ [[DateValue]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, then
+ <ol class="block">
+ <li>Let <i>n</i> be the value of <i>value’s</i> [[DateValue]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>n</i> is not <b>undefined</b>, then return <i>n</i>.</li>
+ </ol>
+ </li>
+ <li>Throw a <b>TypeError</b> exception.</li>
+ </ol>
+
+ <p>In following descriptions of functions that are properties of the Date prototype object, the phrase “this Date
+ object” refers to the object that is the <b>this</b> value for the invocation of the function. The phrase
+ “this <a href="#sec-time-values-and-time-range">time value</a>” within the specification of a method refers to
+ the result returned by calling the abstract operation <span style="font-family: Times New Roman">thisTimeValue</span>
+ with the <b>this</b> value of the method invocation passed as the argument.</p>
+ </div>
+
+ <section id="sec-date.prototype.constructor">
+ <h1><span class="secnum" id="sec-20.3.4.1"><a href="#sec-date.prototype.constructor"
+ title="link to this section">20.3.4.1</a></span> Date.prototype.constructor</h1>
+
+ <p>The initial value of <code>Date.prototype.constructor</code> is the built-in <code>Date</code> constructor.</p>
+ </section>
+
+ <section id="sec-date.prototype.getdate">
+ <h1><span class="secnum" id="sec-20.3.4.2"><a href="#sec-date.prototype.getdate"
+ title="link to this section">20.3.4.2</a></span> Date.prototype.getDate ( )</h1>
+ <ol class="proc">
+ <li>Let <i>t</i> be <a href="#sec-properties-of-the-date-prototype-object">this time value</a>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>t</i>).</li>
+ <li>If <i>t</i> is <b>NaN</b>, return <b>NaN</b>.</li>
+ <li>Return <a href="#sec-date-number">DateFromTime</a>(<a href="#sec-local-time">LocalTime</a>(<i>t</i>)).</li>
+ </ol>
+ </section>
+
+ <section id="sec-date.prototype.getday">
+ <h1><span class="secnum" id="sec-20.3.4.3"><a href="#sec-date.prototype.getday"
+ title="link to this section">20.3.4.3</a></span> Date.prototype.getDay ( )</h1>
+ <ol class="proc">
+ <li>Let <i>t</i> be <a href="#sec-properties-of-the-date-prototype-object">this time value</a>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>t</i>).</li>
+ <li>If <i>t</i> is <b>NaN</b>, return <b>NaN</b>.</li>
+ <li>Return <a href="#sec-week-day">WeekDay</a>(<a href="#sec-local-time">LocalTime</a>(<i>t</i>)).</li>
+ </ol>
+ </section>
+
+ <section id="sec-date.prototype.getfullyear">
+ <h1><span class="secnum" id="sec-20.3.4.4"><a href="#sec-date.prototype.getfullyear"
+ title="link to this section">20.3.4.4</a></span> Date.prototype.getFullYear ( )</h1>
+ <ol class="proc">
+ <li>Let <i>t</i> be <a href="#sec-properties-of-the-date-prototype-object">this time value</a>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>t</i>).</li>
+ <li>If <i>t</i> is <b>NaN</b>, return <b>NaN</b>.</li>
+ <li>Return <a href="#sec-year-number">YearFromTime</a>(<a href="#sec-local-time">LocalTime</a>(<i>t</i>)).</li>
+ </ol>
+ </section>
+
+ <section id="sec-date.prototype.gethours">
+ <h1><span class="secnum" id="sec-20.3.4.5"><a href="#sec-date.prototype.gethours"
+ title="link to this section">20.3.4.5</a></span> Date.prototype.getHours ( )</h1>
+ <ol class="proc">
+ <li>Let <i>t</i> be <a href="#sec-properties-of-the-date-prototype-object">this time value</a>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>t</i>).</li>
+ <li>If <i>t</i> is <b>NaN</b>, return <b>NaN</b>.</li>
+ <li>Return <a href="#sec-hours-minutes-second-and-milliseconds">HourFromTime</a>(<a
+ href="#sec-local-time">LocalTime</a>(<i>t</i>)).</li>
+ </ol>
+ </section>
+
+ <section id="sec-date.prototype.getmilliseconds">
+ <h1><span class="secnum" id="sec-20.3.4.6"><a href="#sec-date.prototype.getmilliseconds"
+ title="link to this section">20.3.4.6</a></span> Date.prototype.getMilliseconds ( )</h1>
+ <ol class="proc">
+ <li>Let <i>t</i> be <a href="#sec-properties-of-the-date-prototype-object">this time value</a>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>t</i>).</li>
+ <li>If <i>t</i> is <b>NaN</b>, return <b>NaN</b>.</li>
+ <li>Return <a href="#sec-hours-minutes-second-and-milliseconds">msFromTime</a>(<a
+ href="#sec-local-time">LocalTime</a>(<i>t</i>)).</li>
+ </ol>
+ </section>
+
+ <section id="sec-date.prototype.getminutes">
+ <h1><span class="secnum" id="sec-20.3.4.7"><a href="#sec-date.prototype.getminutes"
+ title="link to this section">20.3.4.7</a></span> Date.prototype.getMinutes ( )</h1>
+ <ol class="proc">
+ <li>Let <i>t</i> be <a href="#sec-properties-of-the-date-prototype-object">this time value</a>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>t</i>).</li>
+ <li>If <i>t</i> is <b>NaN</b>, return <b>NaN</b>.</li>
+ <li>Return <a href="#sec-hours-minutes-second-and-milliseconds">MinFromTime</a>(<a
+ href="#sec-local-time">LocalTime</a>(<i>t</i>)).</li>
+ </ol>
+ </section>
+
+ <section id="sec-date.prototype.getmonth">
+ <h1><span class="secnum" id="sec-20.3.4.8"><a href="#sec-date.prototype.getmonth"
+ title="link to this section">20.3.4.8</a></span> Date.prototype.getMonth ( )</h1>
+ <ol class="proc">
+ <li>Let <i>t</i> be <a href="#sec-properties-of-the-date-prototype-object">this time value</a>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>t</i>).</li>
+ <li>If <i>t</i> is <b>NaN</b>, return <b>NaN</b>.</li>
+ <li>Return <a href="#sec-month-number">MonthFromTime</a>(<a href="#sec-local-time">LocalTime</a>(<i>t</i>)).</li>
+ </ol>
+ </section>
+
+ <section id="sec-date.prototype.getseconds">
+ <h1><span class="secnum" id="sec-20.3.4.9"><a href="#sec-date.prototype.getseconds"
+ title="link to this section">20.3.4.9</a></span> Date.prototype.getSeconds ( )</h1>
+ <ol class="proc">
+ <li>Let <i>t</i> be <a href="#sec-properties-of-the-date-prototype-object">this time value</a>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>t</i>).</li>
+ <li>If <i>t</i> is <b>NaN</b>, return <b>NaN</b>.</li>
+ <li>Return <a href="#sec-hours-minutes-second-and-milliseconds">SecFromTime</a>(<a
+ href="#sec-local-time">LocalTime</a>(<i>t</i>)).</li>
+ </ol>
+ </section>
+
+ <section id="sec-date.prototype.gettime">
+ <h1><span class="secnum" id="sec-20.3.4.10"><a href="#sec-date.prototype.gettime"
+ title="link to this section">20.3.4.10</a></span> Date.prototype.getTime ( )</h1>
+ <ol class="proc">
+ <li>Return <a href="#sec-properties-of-the-date-prototype-object">this time value</a>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-date.prototype.gettimezoneoffset">
+ <h1><span class="secnum" id="sec-20.3.4.11"><a href="#sec-date.prototype.gettimezoneoffset"
+ title="link to this section">20.3.4.11</a></span> Date.prototype.getTimezoneOffset ( )</h1>
+
+ <p>Returns the difference between local time and UTC time in minutes.</p>
+
+ <ol class="proc">
+ <li>Let <i>t</i> be <a href="#sec-properties-of-the-date-prototype-object">this time value</a>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>t</i>).</li>
+ <li>If <i>t</i> is <b>NaN</b>, return <b>NaN</b>.</li>
+ <li>Return (<i>t</i> − <a href="#sec-local-time">LocalTime</a>(<i>t</i>)) / <a
+ href="#sec-hours-minutes-second-and-milliseconds">msPerMinute</a>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-date.prototype.getutcdate">
+ <h1><span class="secnum" id="sec-20.3.4.12"><a href="#sec-date.prototype.getutcdate"
+ title="link to this section">20.3.4.12</a></span> Date.prototype.getUTCDate ( )</h1>
+ <ol class="proc">
+ <li>Let <i>t</i> be <a href="#sec-properties-of-the-date-prototype-object">this time value</a>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>t</i>).</li>
+ <li>If <i>t</i> is <b>NaN</b>, return <b>NaN</b>.</li>
+ <li>Return <a href="#sec-date-number">DateFromTime</a>(<i>t</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-date.prototype.getutcday">
+ <h1><span class="secnum" id="sec-20.3.4.13"><a href="#sec-date.prototype.getutcday"
+ title="link to this section">20.3.4.13</a></span> Date.prototype.getUTCDay ( )</h1>
+ <ol class="proc">
+ <li>Let <i>t</i> be <a href="#sec-properties-of-the-date-prototype-object">this time value</a>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>t</i>).</li>
+ <li>If <i>t</i> is <b>NaN</b>, return <b>NaN</b>.</li>
+ <li>Return <a href="#sec-week-day">WeekDay</a>(<i>t</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-date.prototype.getutcfullyear">
+ <h1><span class="secnum" id="sec-20.3.4.14"><a href="#sec-date.prototype.getutcfullyear"
+ title="link to this section">20.3.4.14</a></span> Date.prototype.getUTCFullYear ( )</h1>
+ <ol class="proc">
+ <li>Let <i>t</i> be <a href="#sec-properties-of-the-date-prototype-object">this time value</a>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>t</i>).</li>
+ <li>If <i>t</i> is <b>NaN</b>, return <b>NaN</b>.</li>
+ <li>Return <a href="#sec-year-number">YearFromTime</a>(<i>t</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-date.prototype.getutchours">
+ <h1><span class="secnum" id="sec-20.3.4.15"><a href="#sec-date.prototype.getutchours"
+ title="link to this section">20.3.4.15</a></span> Date.prototype.getUTCHours ( )</h1>
+ <ol class="proc">
+ <li>Let <i>t</i> be <a href="#sec-properties-of-the-date-prototype-object">this time value</a>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>t</i>).</li>
+ <li>If <i>t</i> is <b>NaN</b>, return <b>NaN</b>.</li>
+ <li>Return <a href="#sec-hours-minutes-second-and-milliseconds">HourFromTime</a>(<i>t</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-date.prototype.getutcmilliseconds">
+ <h1><span class="secnum" id="sec-20.3.4.16"><a href="#sec-date.prototype.getutcmilliseconds"
+ title="link to this section">20.3.4.16</a></span> Date.prototype.getUTCMilliseconds ( )</h1>
+ <ol class="proc">
+ <li>Let <i>t</i> be <a href="#sec-properties-of-the-date-prototype-object">this time value</a>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>t</i>).</li>
+ <li>If <i>t</i> is <b>NaN</b>, return <b>NaN</b>.</li>
+ <li>Return <a href="#sec-hours-minutes-second-and-milliseconds">msFromTime</a>(<i>t</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-date.prototype.getutcminutes">
+ <h1><span class="secnum" id="sec-20.3.4.17"><a href="#sec-date.prototype.getutcminutes"
+ title="link to this section">20.3.4.17</a></span> Date.prototype.getUTCMinutes ( )</h1>
+ <ol class="proc">
+ <li>Let <i>t</i> be <a href="#sec-properties-of-the-date-prototype-object">this time value</a>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>t</i>).</li>
+ <li>If <i>t</i> is <b>NaN</b>, return <b>NaN</b>.</li>
+ <li>Return <a href="#sec-hours-minutes-second-and-milliseconds">MinFromTime</a>(<i>t</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-date.prototype.getutcmonth">
+ <h1><span class="secnum" id="sec-20.3.4.18"><a href="#sec-date.prototype.getutcmonth"
+ title="link to this section">20.3.4.18</a></span> Date.prototype.getUTCMonth ( )</h1>
+ <ol class="proc">
+ <li>Let <i>t</i> be <a href="#sec-properties-of-the-date-prototype-object">this time value</a>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>t</i>).</li>
+ <li>If <i>t</i> is <b>NaN</b>, return <b>NaN</b>.</li>
+ <li>Return <a href="#sec-month-number">MonthFromTime</a>(<i>t</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-date.prototype.getutcseconds">
+ <h1><span class="secnum" id="sec-20.3.4.19"><a href="#sec-date.prototype.getutcseconds"
+ title="link to this section">20.3.4.19</a></span> Date.prototype.getUTCSeconds ( )</h1>
+ <ol class="proc">
+ <li>Let <i>t</i> be <a href="#sec-properties-of-the-date-prototype-object">this time value</a>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>t</i>).</li>
+ <li>If <i>t</i> is <b>NaN</b>, return <b>NaN</b>.</li>
+ <li>Return <a href="#sec-hours-minutes-second-and-milliseconds">SecFromTime</a>(<i>t</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-date.prototype.setdate">
+ <h1><span class="secnum" id="sec-20.3.4.20"><a href="#sec-date.prototype.setdate"
+ title="link to this section">20.3.4.20</a></span> Date.prototype.setDate ( date )</h1>
+ <ol class="proc">
+ <li>Let <i>t</i> be the result of <a href="#sec-local-time">LocalTime</a>(<a
+ href="#sec-properties-of-the-date-prototype-object">this time value</a>).</li>
+ <li>Let <i>dt</i> be <a href="#sec-tonumber">ToNumber</a>(<i>date</i>).</li>
+ <li>Let <i>newDate</i> be <a href="#sec-makedate">MakeDate</a>(<a href="#sec-makeday">MakeDay</a>(<a
+ href="#sec-year-number">YearFromTime</a>(<i>t</i>), <a href="#sec-month-number">MonthFromTime</a>(<i>t</i>),
+ <i>dt</i>), <a href="#sec-day-number-and-time-within-day">TimeWithinDay</a>(<i>t</i>)).</li>
+ <li>Let <i>u</i> be <a href="#sec-timeclip">TimeClip</a>(<a href="#sec-local-time">UTC</a>(<i>newDate</i>)).</li>
+ <li>Set the [[DateValue]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of this Date
+ object to <i>u</i>.</li>
+ <li>Return <i>u</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-date.prototype.setfullyear">
+ <h1><span class="secnum" id="sec-20.3.4.21"><a href="#sec-date.prototype.setfullyear"
+ title="link to this section">20.3.4.21</a></span> Date.prototype.setFullYear ( year [ , month [ , date ] ] )</h1>
+ <ol class="proc">
+ <li>Let <i>t</i> be the result of <a href="#sec-local-time">LocalTime</a>(<a
+ href="#sec-properties-of-the-date-prototype-object">this time value</a>); but if <a
+ href="#sec-properties-of-the-date-prototype-object">this time value</a> is <b>NaN</b>, let <i>t</i> be
+ <b>+0</b>.</li>
+ <li>Let <i>y</i> be <a href="#sec-tonumber">ToNumber</a>(<i>year</i>).</li>
+ <li>If <i>month</i> is not specified, then let <i>m</i> be <a href="#sec-month-number">MonthFromTime</a>(<i>t</i>);
+ otherwise, let <i>m</i> be <a href="#sec-tonumber">ToNumber</a>(<i>month</i>).</li>
+ <li>If <i>date</i> is not specified, then let <i>dt</i> be <a href="#sec-date-number">DateFromTime</a>(<i>t</i>);
+ otherwise, let <i>dt</i> be <a href="#sec-tonumber">ToNumber</a>(<i>date</i>).</li>
+ <li>Let <i>newDate</i> be <a href="#sec-makedate">MakeDate</a>(<a href="#sec-makeday">MakeDay</a>(<i>y</i>, <i>m</i>,
+ <i>dt</i>), <a href="#sec-day-number-and-time-within-day">TimeWithinDay</a>(<i>t</i>)).</li>
+ <li>Let <i>u</i> be <a href="#sec-timeclip">TimeClip</a>(<a href="#sec-local-time">UTC</a>(<i>newDate</i>)).</li>
+ <li>Set the [[DateValue]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of this Date
+ object to <i>u</i>.</li>
+ <li>Return <i>u</i>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>setFullYear</code> method is <b>3</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> If <i>month</i> is not specified, this method behaves as if <i>month</i> were specified
+ with the value <code>getMonth()</code>. If <i>date</i> is not specified, it behaves as if <i>date</i> were specified
+ with the value <code>getDate()</code>.</p>
+ </div>
+ </section>
+
+ <section id="sec-date.prototype.sethours">
+ <h1><span class="secnum" id="sec-20.3.4.22"><a href="#sec-date.prototype.sethours"
+ title="link to this section">20.3.4.22</a></span> Date.prototype.setHours ( hour [ , min [ , sec [ , ms ] ] ] )</h1>
+ <ol class="proc">
+ <li>Let <i>t</i> be the result of <a href="#sec-local-time">LocalTime</a>(<a
+ href="#sec-properties-of-the-date-prototype-object">this time value</a>).</li>
+ <li>Let <i>h</i> be <a href="#sec-tonumber">ToNumber</a>(<i>hour</i>).</li>
+ <li>If <i>min</i> is not specified, then let <i>m</i> be <a
+ href="#sec-hours-minutes-second-and-milliseconds">MinFromTime</a>(<i>t</i>); otherwise, let <i>m</i> be <a
+ href="#sec-tonumber">ToNumber</a>(<i>min</i>).</li>
+ <li>If <i>sec</i> is not specified, then let <i>s</i> be <a
+ href="#sec-hours-minutes-second-and-milliseconds">SecFromTime</a>(<i>t</i>); otherwise, let <i>s</i> be <a
+ href="#sec-tonumber">ToNumber</a>(<i>sec</i>).</li>
+ <li>If <i>ms</i> is not specified, then let <i>milli</i> be <a
+ href="#sec-hours-minutes-second-and-milliseconds">msFromTime</a>(<i>t</i>); otherwise, let <i>milli</i> be <a
+ href="#sec-tonumber">ToNumber</a>(<i>ms</i>).</li>
+ <li>Let <i>date</i> be <a href="#sec-makedate">MakeDate</a>(<a
+ href="#sec-day-number-and-time-within-day">Day</a>(<i>t</i>), <a href="#sec-maketime">MakeTime</a>(<i>h</i>,
+ <i>m</i>, <i>s</i>, <i>milli</i>)).</li>
+ <li>Let <i>u</i> be <a href="#sec-timeclip">TimeClip</a>(<a href="#sec-local-time">UTC</a>(<i>date</i>)).</li>
+ <li>Set the [[DateValue]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of this Date
+ object to <i>u</i>.</li>
+ <li>Return <i>u</i>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>setHours</code> method is <b>4</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> If <i>min</i> is not specified, this method behaves as if <i>min</i> were specified with
+ the value <code>getMinutes()</code>. If <i>sec</i> is not specified, it behaves as if <i>sec</i> were specified with the
+ value <code>getSeconds()</code>. If <i>ms</i> is not specified, it behaves as if <i>ms</i> were specified with the value
+ <code>getMilliseconds()</code>.</p>
+ </div>
+ </section>
+
+ <section id="sec-date.prototype.setmilliseconds">
+ <h1><span class="secnum" id="sec-20.3.4.23"><a href="#sec-date.prototype.setmilliseconds"
+ title="link to this section">20.3.4.23</a></span> Date.prototype.setMilliseconds ( ms )</h1>
+ <ol class="proc">
+ <li>Let <i>t</i> be the result of <a href="#sec-local-time">LocalTime</a>(<a
+ href="#sec-properties-of-the-date-prototype-object">this time value</a>).</li>
+ <li>Let <i>time</i> be <a href="#sec-maketime">MakeTime</a>(<a
+ href="#sec-hours-minutes-second-and-milliseconds">HourFromTime</a>(<i>t</i>), <a
+ href="#sec-hours-minutes-second-and-milliseconds">MinFromTime</a>(<i>t</i>), <a
+ href="#sec-hours-minutes-second-and-milliseconds">SecFromTime</a>(<i>t</i>), <a
+ href="#sec-tonumber">ToNumber</a>(<i>ms</i>)).</li>
+ <li>Let <i>u</i> be <a href="#sec-timeclip">TimeClip</a>(<a href="#sec-local-time">UTC</a>(<a
+ href="#sec-makedate">MakeDate</a>(<a href="#sec-day-number-and-time-within-day">Day</a>(<i>t</i>),
+ <i>time</i>))).</li>
+ <li>Set the [[DateValue]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of this Date
+ object to <i>u</i>.</li>
+ <li>Return <i>u</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-date.prototype.setminutes">
+ <h1><span class="secnum" id="sec-20.3.4.24"><a href="#sec-date.prototype.setminutes"
+ title="link to this section">20.3.4.24</a></span> Date.prototype.setMinutes ( min [ , sec [ , ms ] ] )</h1>
+ <ol class="proc">
+ <li>Let <i>t</i> be the result of <a href="#sec-local-time">LocalTime</a>(<a
+ href="#sec-properties-of-the-date-prototype-object">this time value</a>).</li>
+ <li>Let <i>m</i> be <a href="#sec-tonumber">ToNumber</a>(<i>min</i>).</li>
+ <li>If <i>sec</i> is not specified, then let <i>s</i> be <a
+ href="#sec-hours-minutes-second-and-milliseconds">SecFromTime</a>(<i>t</i>); otherwise, let <i>s</i> be <a
+ href="#sec-tonumber">ToNumber</a>(<i>sec</i>).</li>
+ <li>If <i>ms</i> is not specified, then let <i>milli</i> be <a
+ href="#sec-hours-minutes-second-and-milliseconds">msFromTime</a>(<i>t</i>); otherwise, let <i>milli</i> be <a
+ href="#sec-tonumber">ToNumber</a>(<i>ms</i>).</li>
+ <li>Let <i>date</i> be <a href="#sec-makedate">MakeDate</a>(<a
+ href="#sec-day-number-and-time-within-day">Day</a>(<i>t</i>), <a href="#sec-maketime">MakeTime</a>(<a
+ href="#sec-hours-minutes-second-and-milliseconds">HourFromTime</a>(<i>t</i>), <i>m</i>, <i>s</i>,
+ <i>milli</i>)).</li>
+ <li>Let <i>u</i> be <a href="#sec-timeclip">TimeClip</a>(<a href="#sec-local-time">UTC</a>(<i>date</i>)).</li>
+ <li>Set the [[DateValue]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of this Date
+ object to <i>u</i>.</li>
+ <li>Return <i>u</i>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>setMinutes</code> method is <b>3</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> If <i>sec</i> is not specified, this method behaves as if <i>sec</i> were specified with
+ the value <code>getSeconds()</code>. If <i>ms</i> is not specified, this behaves as if <i>ms</i> were specified with the
+ value <code>getMilliseconds()</code>.</p>
+ </div>
+ </section>
+
+ <section id="sec-date.prototype.setmonth">
+ <h1><span class="secnum" id="sec-20.3.4.25"><a href="#sec-date.prototype.setmonth"
+ title="link to this section">20.3.4.25</a></span> Date.prototype.setMonth ( month [ , date ] )</h1>
+ <ol class="proc">
+ <li>Let <i>t</i> be the result of <a href="#sec-local-time">LocalTime</a>(<a
+ href="#sec-properties-of-the-date-prototype-object">this time value</a>).</li>
+ <li>Let <i>m</i> be <a href="#sec-tonumber">ToNumber</a>(<i>month</i>).</li>
+ <li>If <i>date</i> is not specified, then let <i>dt</i> be <a href="#sec-date-number">DateFromTime</a>(<i>t</i>);
+ otherwise, let <i>dt</i> be <a href="#sec-tonumber">ToNumber</a>(<i>date</i>).</li>
+ <li>Let <i>newDate</i> be <a href="#sec-makedate">MakeDate</a>(<a href="#sec-makeday">MakeDay</a>(<a
+ href="#sec-year-number">YearFromTime</a>(<i>t</i>), <i>m</i>, <i>dt</i>), <a
+ href="#sec-day-number-and-time-within-day">TimeWithinDay</a>(<i>t</i>)).</li>
+ <li>Let <i>u</i> be <a href="#sec-timeclip">TimeClip</a>(<a href="#sec-local-time">UTC</a>(<i>newDate</i>)).</li>
+ <li>Set the [[DateValue]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of this Date
+ object to <i>u</i>.</li>
+ <li>Return <i>u</i>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>setMonth</code> method is <b>2</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> If <i>date</i> is not specified, this method behaves as if <i>date</i> were specified
+ with the value <code>getDate()</code>.</p>
+ </div>
+ </section>
+
+ <section id="sec-date.prototype.setseconds">
+ <h1><span class="secnum" id="sec-20.3.4.26"><a href="#sec-date.prototype.setseconds"
+ title="link to this section">20.3.4.26</a></span> Date.prototype.setSeconds ( sec [ , ms ] )</h1>
+ <ol class="proc">
+ <li>Let <i>t</i> be the result of <a href="#sec-local-time">LocalTime</a>(<a
+ href="#sec-properties-of-the-date-prototype-object">this time value</a>).</li>
+ <li>Let <i>s</i> be <a href="#sec-tonumber">ToNumber</a>(<i>sec</i>).</li>
+ <li>If <i>ms</i> is not specified, then let <i>milli</i> be <a
+ href="#sec-hours-minutes-second-and-milliseconds">msFromTime</a>(<i>t</i>); otherwise, let <i>milli</i> be <a
+ href="#sec-tonumber">ToNumber</a>(<i>ms</i>).</li>
+ <li>Let <i>date</i> be <a href="#sec-makedate">MakeDate</a>(<a
+ href="#sec-day-number-and-time-within-day">Day</a>(<i>t</i>), <a href="#sec-maketime">MakeTime</a>(<a
+ href="#sec-hours-minutes-second-and-milliseconds">HourFromTime</a>(<i>t</i>), <a
+ href="#sec-hours-minutes-second-and-milliseconds">MinFromTime</a>(<i>t</i>), <i>s</i>, <i>milli</i>)).</li>
+ <li>Let <i>u</i> be <a href="#sec-timeclip">TimeClip</a>(<a href="#sec-local-time">UTC</a>(<i>date</i>)).</li>
+ <li>Set the [[DateValue]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of this Date
+ object to <i>u</i>.</li>
+ <li>Return <i>u</i>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>setSeconds</code> method is <b>2</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> If <i>ms</i> is not specified, this method behaves as if <i>ms</i> were specified with
+ the value <code>getMilliseconds()</code>.</p>
+ </div>
+ </section>
+
+ <section id="sec-date.prototype.settime">
+ <h1><span class="secnum" id="sec-20.3.4.27"><a href="#sec-date.prototype.settime"
+ title="link to this section">20.3.4.27</a></span> Date.prototype.setTime ( time )</h1>
+ <ol class="proc">
+ <li>Let <i>v</i> be <a href="#sec-timeclip">TimeClip</a>(<a href="#sec-tonumber">ToNumber</a>(<i>time</i>)).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>v</i>).</li>
+ <li>Set the [[DateValue]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of this Date
+ object to <i>v</i>.</li>
+ <li>Return <i>v</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-date.prototype.setutcdate">
+ <h1><span class="secnum" id="sec-20.3.4.28"><a href="#sec-date.prototype.setutcdate"
+ title="link to this section">20.3.4.28</a></span> Date.prototype.setUTCDate ( date )</h1>
+ <ol class="proc">
+ <li>Let <i>t</i> be <a href="#sec-properties-of-the-date-prototype-object">this time value</a>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>t</i>).</li>
+ <li>Let <i>dt</i> be <a href="#sec-tonumber">ToNumber</a>(<i>date</i>).</li>
+ <li>Let <i>newDate</i> be <a href="#sec-makedate">MakeDate</a>(<a href="#sec-makeday">MakeDay</a>(<a
+ href="#sec-year-number">YearFromTime</a>(<i>t</i>), <a href="#sec-month-number">MonthFromTime</a>(<i>t</i>),
+ <i>dt</i>), <a href="#sec-day-number-and-time-within-day">TimeWithinDay</a>(<i>t</i>)).</li>
+ <li>Let <i>v</i> be <a href="#sec-timeclip">TimeClip</a>(<i>newDate</i>).</li>
+ <li>Set the [[DateValue]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of this Date
+ object to <i>v</i>.</li>
+ <li>Return <i>v</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-date.prototype.setutcfullyear">
+ <h1><span class="secnum" id="sec-20.3.4.29"><a href="#sec-date.prototype.setutcfullyear"
+ title="link to this section">20.3.4.29</a></span> Date.prototype.setUTCFullYear ( year [ , month [ , date ] ] )</h1>
+ <ol class="proc">
+ <li>Let <i>t</i> be <a href="#sec-properties-of-the-date-prototype-object">this time value</a>; but if <a
+ href="#sec-properties-of-the-date-prototype-object">this time value</a> is <b>NaN</b>, let <i>t</i> be
+ <b>+0</b>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>t</i>).</li>
+ <li>Let <i>y</i> be <a href="#sec-tonumber">ToNumber</a>(<i>year</i>).</li>
+ <li>If <i>month</i> is not specified, then let <i>m</i> be <a href="#sec-month-number">MonthFromTime</a>(<i>t</i>);
+ otherwise, let <i>m</i> be <a href="#sec-tonumber">ToNumber</a>(<i>month</i>).</li>
+ <li>If <i>date</i> is not specified, then let <i>dt</i> be <a href="#sec-date-number">DateFromTime</a>(<i>t</i>);
+ otherwise, let <i>dt</i> be <a href="#sec-tonumber">ToNumber</a>(<i>date</i>).</li>
+ <li>Let <i>newDate</i> be <a href="#sec-makedate">MakeDate</a>(<a href="#sec-makeday">MakeDay</a>(<i>y</i>, <i>m</i>,
+ <i>dt</i>), <a href="#sec-day-number-and-time-within-day">TimeWithinDay</a>(<i>t</i>)).</li>
+ <li>Let <i>v</i> be <a href="#sec-timeclip">TimeClip</a>(<i>newDate</i>).</li>
+ <li>Set the [[DateValue]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of this Date
+ object to <i>v</i>.</li>
+ <li>Return <i>v</i>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>setUTCFullYear</code> method is <b>3</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> If <i>month</i> is not specified, this method behaves as if <i>month</i> were specified
+ with the value <code>getUTCMonth()</code>. If <i>date</i> is not specified, it behaves as if <i>date</i> were specified
+ with the value <code>getUTCDate()</code>.</p>
+ </div>
+ </section>
+
+ <section id="sec-date.prototype.setutchours">
+ <h1><span class="secnum" id="sec-20.3.4.30"><a href="#sec-date.prototype.setutchours"
+ title="link to this section">20.3.4.30</a></span> Date.prototype.setUTCHours ( hour [ , min [ , sec [ , ms ] ] ]
+ )</h1>
+ <ol class="proc">
+ <li>Let <i>t</i> be <a href="#sec-properties-of-the-date-prototype-object">this time value</a>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>t</i>).</li>
+ <li>Let <i>h</i> be <a href="#sec-tonumber">ToNumber</a>(<i>hour</i>).</li>
+ <li>If <i>min</i> is not specified, then let <i>m</i> be <a
+ href="#sec-hours-minutes-second-and-milliseconds">MinFromTime</a>(<i>t</i>); otherwise, let <i>m</i> be <a
+ href="#sec-tonumber">ToNumber</a>(<i>min</i>).</li>
+ <li>If <i>sec</i> is not specified, then let <i>s</i> be <a
+ href="#sec-hours-minutes-second-and-milliseconds">SecFromTime</a>(<i>t</i>); otherwise, let <i>s</i> be <a
+ href="#sec-tonumber">ToNumber</a>(<i>sec</i>).</li>
+ <li>If <i>ms</i> is not specified, then let <i>milli</i> be <a
+ href="#sec-hours-minutes-second-and-milliseconds">msFromTime</a>(<i>t</i>); otherwise, let <i>milli</i> be <a
+ href="#sec-tonumber">ToNumber</a>(<i>ms</i>).</li>
+ <li>Let <i>newDate</i> be <a href="#sec-makedate">MakeDate</a>(<a
+ href="#sec-day-number-and-time-within-day">Day</a>(<i>t</i>), <a href="#sec-maketime">MakeTime</a>(<i>h</i>,
+ <i>m</i>, <i>s</i>, <i>milli</i>)).</li>
+ <li>Let <i>v</i> be <a href="#sec-timeclip">TimeClip</a>(<i>newDate</i>).</li>
+ <li>Set the [[DateValue]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of this Date
+ object to <i>v</i>.</li>
+ <li>Return <i>v</i>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>setUTCHours</code> method is <b>4</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> If <i>min</i> is not specified, this method behaves as if <i>min</i> were specified with
+ the value <code>getUTCMinutes()</code>. If <i>sec</i> is not specified, it behaves as if <i>sec</i> were specified with
+ the value <code>getUTCSeconds()</code>. If <i>ms</i> is not specified, it behaves as if <i>ms</i> were specified with
+ the value <code>getUTCMilliseconds()</code>.</p>
+ </div>
+ </section>
+
+ <section id="sec-date.prototype.setutcmilliseconds">
+ <h1><span class="secnum" id="sec-20.3.4.31"><a href="#sec-date.prototype.setutcmilliseconds"
+ title="link to this section">20.3.4.31</a></span> Date.prototype.setUTCMilliseconds ( ms )</h1>
+ <ol class="proc">
+ <li>Let <i>t</i> be <a href="#sec-properties-of-the-date-prototype-object">this time value</a>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>t</i>).</li>
+ <li>Let <i>time</i> be <a href="#sec-maketime">MakeTime</a>(<a
+ href="#sec-hours-minutes-second-and-milliseconds">HourFromTime</a>(<i>t</i>), <a
+ href="#sec-hours-minutes-second-and-milliseconds">MinFromTime</a>(<i>t</i>), <a
+ href="#sec-hours-minutes-second-and-milliseconds">SecFromTime</a>(<i>t</i>), <a
+ href="#sec-tonumber">ToNumber</a>(<i>ms</i>)).</li>
+ <li>Let <i>v</i> be <a href="#sec-timeclip">TimeClip</a>(<a href="#sec-makedate">MakeDate</a>(<a
+ href="#sec-day-number-and-time-within-day">Day</a>(<i>t</i>), <i>time</i>)).</li>
+ <li>Set the [[DateValue]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of this Date
+ object to <i>v</i>.</li>
+ <li>Return <i>v</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-date.prototype.setutcminutes">
+ <h1><span class="secnum" id="sec-20.3.4.32"><a href="#sec-date.prototype.setutcminutes"
+ title="link to this section">20.3.4.32</a></span> Date.prototype.setUTCMinutes ( min [ , sec [, ms ] ] )</h1>
+ <ol class="proc">
+ <li>Let <i>t</i> be <a href="#sec-properties-of-the-date-prototype-object">this time value</a>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>t</i>).</li>
+ <li>Let <i>m</i> be <a href="#sec-tonumber">ToNumber</a>(<i>min</i>).</li>
+ <li>If <i>sec</i> is not specified, then let <i>s</i> be <a
+ href="#sec-hours-minutes-second-and-milliseconds">SecFromTime</a>(<i>t</i>); otherwise, let <i>s</i> be <a
+ href="#sec-tonumber">ToNumber</a>(<i>sec</i>).</li>
+ <li>If <i>ms</i> is not specified, then let <i>milli</i> be <a
+ href="#sec-hours-minutes-second-and-milliseconds">msFromTime</a>(<i>t</i>); otherwise, let <i>milli</i> be <a
+ href="#sec-tonumber">ToNumber</a>(<i>ms</i>).</li>
+ <li>Let <i>date</i> be <a href="#sec-makedate">MakeDate</a>(<a
+ href="#sec-day-number-and-time-within-day">Day</a>(<i>t</i>), <a href="#sec-maketime">MakeTime</a>(<a
+ href="#sec-hours-minutes-second-and-milliseconds">HourFromTime</a>(<i>t</i>), <i>m</i>, <i>s</i>,
+ <i>milli</i>)).</li>
+ <li>Let <i>v</i> be <a href="#sec-timeclip">TimeClip</a>(<i>date</i>).</li>
+ <li>Set the [[DateValue]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of this Date
+ object to <i>v</i>.</li>
+ <li>Return <i>v</i>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>setUTCMinutes</code> method is <b>3</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> If <i>sec</i> is not specified, this method behaves as if <i>sec</i> were specified with
+ the value <code>getUTCSeconds()</code>. If <i>ms</i> is not specified, it function behaves as if <i>ms</i> were
+ specified with the value return by <code>getUTCMilliseconds()</code>.</p>
+ </div>
+ </section>
+
+ <section id="sec-date.prototype.setutcmonth">
+ <h1><span class="secnum" id="sec-20.3.4.33"><a href="#sec-date.prototype.setutcmonth"
+ title="link to this section">20.3.4.33</a></span> Date.prototype.setUTCMonth ( month [ , date ] )</h1>
+ <ol class="proc">
+ <li>Let <i>t</i> be <a href="#sec-properties-of-the-date-prototype-object">this time value</a>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>t</i>).</li>
+ <li>Let <i>m</i> be <a href="#sec-tonumber">ToNumber</a>(<i>month</i>).</li>
+ <li>If <i>date</i> is not specified, then let <i>dt</i> be <a href="#sec-date-number">DateFromTime</a>(<i>t</i>);
+ otherwise, let <i>dt</i> be <a href="#sec-tonumber">ToNumber</a>(<i>date</i>).</li>
+ <li>Let <i>newDate</i> be <a href="#sec-makedate">MakeDate</a>(<a href="#sec-makeday">MakeDay</a>(<a
+ href="#sec-year-number">YearFromTime</a>(<i>t</i>), <i>m</i>, <i>dt</i>), <a
+ href="#sec-day-number-and-time-within-day">TimeWithinDay</a>(<i>t</i>)).</li>
+ <li>Let <i>v</i> be <a href="#sec-timeclip">TimeClip</a>(<i>newDate</i>).</li>
+ <li>Set the [[DateValue]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of this Date
+ object to <i>v</i>.</li>
+ <li>Return <i>v</i>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>setUTCMonth</code> method is <b>2</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> If <i>date</i> is not specified, this method behaves as if <i>date</i> were specified
+ with the value <code>getUTCDate()</code>.</p>
+ </div>
+ </section>
+
+ <section id="sec-date.prototype.setutcseconds">
+ <h1><span class="secnum" id="sec-20.3.4.34"><a href="#sec-date.prototype.setutcseconds"
+ title="link to this section">20.3.4.34</a></span> Date.prototype.setUTCSeconds ( sec [ , ms ] )</h1>
+ <ol class="proc">
+ <li>Let <i>t</i> be <a href="#sec-properties-of-the-date-prototype-object">this time value</a>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>t</i>).</li>
+ <li>Let <i>s</i> be <a href="#sec-tonumber">ToNumber</a>(<i>sec</i>).</li>
+ <li>If <i>ms</i> is not specified, then let <i>milli</i> be <a
+ href="#sec-hours-minutes-second-and-milliseconds">msFromTime</a>(<i>t</i>); otherwise, let <i>milli</i> be <a
+ href="#sec-tonumber">ToNumber</a>(<i>ms</i>).</li>
+ <li>Let <i>date</i> be <a href="#sec-makedate">MakeDate</a>(<a
+ href="#sec-day-number-and-time-within-day">Day</a>(<i>t</i>), <a href="#sec-maketime">MakeTime</a>(<a
+ href="#sec-hours-minutes-second-and-milliseconds">HourFromTime</a>(<i>t</i>), <a
+ href="#sec-hours-minutes-second-and-milliseconds">MinFromTime</a>(<i>t</i>), <i>s</i>, <i>milli</i>)).</li>
+ <li>Let <i>v</i> be <a href="#sec-timeclip">TimeClip</a>(<i>date</i>).</li>
+ <li>Set the [[DateValue]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of this Date
+ object to <i>v</i>.</li>
+ <li>Return <i>v</i>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>setUTCSeconds</code> method is <b>2</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> If <i>ms</i> is not specified, this methold behaves as if <i>ms</i> were specified with
+ the value <code>getUTCMilliseconds()</code>.</p>
+ </div>
+ </section>
+
+ <section id="sec-date.prototype.todatestring">
+ <h1><span class="secnum" id="sec-20.3.4.35"><a href="#sec-date.prototype.todatestring"
+ title="link to this section">20.3.4.35</a></span> Date.prototype.toDateString ( )</h1>
+
+ <p>This function returns a String value. The contents of the String are implementation-dependent, but are intended to
+ represent the “date” portion of the Date in the current time zone in a convenient, human-readable form.</p>
+ </section>
+
+ <section id="sec-date.prototype.toisostring">
+ <h1><span class="secnum" id="sec-20.3.4.36"><a href="#sec-date.prototype.toisostring"
+ title="link to this section">20.3.4.36</a></span> Date.prototype.toISOString ( )</h1>
+
+ <p>This function returns a String value representing the instance in time corresponding to <a
+ href="#sec-properties-of-the-date-prototype-object">this time value</a>. The format of the String is the Date Time string
+ format defined in <a href="#sec-date-time-string-format">20.3.1.15</a>. All fields are present in the String. The time
+ zone is always UTC, denoted by the suffix Z. If <a href="#sec-properties-of-the-date-prototype-object">this time value</a>
+ is not a finite Number or if the year is not a value that can be represented in that format (if necessary using extended
+ year format), a <b>RangeError</b> exception is thrown.</p>
+ </section>
+
+ <section id="sec-date.prototype.tojson">
+ <h1><span class="secnum" id="sec-20.3.4.37"><a href="#sec-date.prototype.tojson"
+ title="link to this section">20.3.4.37</a></span> Date.prototype.toJSON ( key )</h1>
+
+ <p>This function provides a String representation of a Date object for use by <code><a
+ href="#sec-json.stringify">JSON.stringify</a></code> (<a href="#sec-json.stringify">24.3.2</a>).</p>
+
+ <p>When the <code>toJSON</code> method is called with argument <var>key</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the result of calling <a href="#sec-toobject">ToObject</a>, giving it the <b>this</b> value as its
+ argument.</li>
+ <li>Let <i>tv</i> be <a href="#sec-toprimitive">ToPrimitive</a>(<i>O</i>, hint Number).</li>
+ <li>If <i>tv</i> is a Number and is not finite, return <b>null</b>.</li>
+ <li>Return <a href="#sec-invoke">Invoke</a>(<i>O</i>, <code>"toISOString"</code>).</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> The argument is ignored.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 2</span> The <code>toJSON</code> function is intentionally generic; it does not require that
+ its <b>this</b> value be a Date object. Therefore, it can be transferred to other kinds of objects for use as a method.
+ However, it does require that any such object have a <code>toISOString</code> method.</p>
+ </div>
+ </section>
+
+ <section id="sec-date.prototype.tolocaledatestring">
+ <h1><span class="secnum" id="sec-20.3.4.38"><a href="#sec-date.prototype.tolocaledatestring"
+ title="link to this section">20.3.4.38</a></span> Date.prototype.toLocaleDateString ( [ reserved1 [ , reserved2 ] ]
+ )</h1>
+
+ <p>An ECMAScript implementation that includes the ECMA-402 International API must implement the
+ <code>Date.prototype.toLocaleDateString</code> method as specified in the ECMA-402 specification. If an ECMAScript
+ implementation does not include the ECMA-402 API the following specification of the <code>toLocaleDateString</code>
+ method is used.</p>
+
+ <p>This function returns a String value. The contents of the String are implementation-dependent, but are intended to
+ represent the “date” portion of the Date in the current time zone in a convenient, human-readable form that
+ corresponds to the conventions of the host environment’s current locale.</p>
+
+ <p>The meaning of the optional parameters to this method are defined in the ECMA-402 specification; implementations that
+ do not include ECMA-402 support must not use those parameter position for anything else.</p>
+
+ <p>The <code>length</code> property of the <code>toLocaleDateString</code> method is <b>0</b>.</p>
+ </section>
+
+ <section id="sec-date.prototype.tolocalestring">
+ <h1><span class="secnum" id="sec-20.3.4.39"><a href="#sec-date.prototype.tolocalestring"
+ title="link to this section">20.3.4.39</a></span> Date.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] )</h1>
+
+ <p>An ECMAScript implementation that includes the ECMA-402 International API must implement the
+ <code>Date.prototype.toLocaleString</code> method as specified in the ECMA-402 specification. If an ECMAScript
+ implementation does not include the ECMA-402 API the following specification of the <code>toLocaleString</code> method is
+ used.</p>
+
+ <p>This function returns a String value. The contents of the String are implementation-dependent, but are intended to
+ represent the Date in the current time zone in a convenient, human-readable form that corresponds to the conventions of
+ the host environment’s current locale.</p>
+
+ <p>The meaning of the optional parameters to this method are defined in the ECMA-402 specification; implementations that
+ do not include ECMA-402 support must not use those parameter position for anything else.</p>
+
+ <p>The <code>length</code> property of the <code>toLocaleString</code> method is <b>0</b>.</p>
+ </section>
+
+ <section id="sec-date.prototype.tolocaletimestring">
+ <h1><span class="secnum" id="sec-20.3.4.40"><a href="#sec-date.prototype.tolocaletimestring"
+ title="link to this section">20.3.4.40</a></span> Date.prototype.toLocaleTimeString ( [ reserved1 [ , reserved2 ] ]
+ )</h1>
+
+ <p>An ECMAScript implementation that includes the ECMA-402 International API must implement the
+ <code>Date.prototype.toLocaleTimeString</code> method as specified in the ECMA-402 specification. If an ECMAScript
+ implementation does not include the ECMA-402 API the following specification of the <code>toLocaleString</code> method is
+ used.</p>
+
+ <p>This function returns a String value. The contents of the String are implementation-dependent, but are intended to
+ represent the “time” portion of the Date in the current time zone in a convenient, human-readable form that
+ corresponds to the conventions of the host environment’s current locale.</p>
+
+ <p>The meaning of the optional parameters to this method are defined in the ECMA-402 specification; implementations that
+ do not include ECMA-402 support must not use those parameter position for anything else.</p>
+
+ <p>The <code>length</code> property of the <code>toLocaleTimeString</code> method is <b>0</b>.</p>
+ </section>
+
+ <section id="sec-date.prototype.tostring">
+ <div class="front">
+ <h1><span class="secnum" id="sec-20.3.4.41"><a href="#sec-date.prototype.tostring"
+ title="link to this section">20.3.4.41</a></span> Date.prototype.toString ( )</h1>
+
+ <p>The following steps are performed:</p>
+
+ <ol class="proc">
+ <li>Let <i>tv</i> be <a href="#sec-properties-of-the-date-prototype-object">this time value</a>.</li>
+ <li>Return <a href="#sec-todatestring">ToDateString</a>(<i>tv)</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> For any Date object <span style="font-family: monospace"><i>d</i></span> whose
+ milliseconds amount is zero, the result of <code><a href="#sec-date.parse">Date.parse</a>(<i>d</i>.toString())</code>
+ is equal to <code><i>d</i>.valueOf()</code>. See <a href="#sec-date.parse">20.3.3.2</a>.</p>
+ </div>
+ </div>
+
+ <section id="sec-todatestring">
+ <h1><span class="secnum" id="sec-20.3.4.41.1"><a href="#sec-todatestring"
+ title="link to this section">20.3.4.41.1</a></span> Runtime Semantics: ToDateString(tv) Abstract Operation</h1>
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>tv</i>) is Number.</li>
+ <li>If <i>tv</i> is NaN, then return <code>"Invalid Date"</code>.</li>
+ <li>Return an implementation-dependent String value that represents <i>tv</i> as a date and time in the current time
+ zone using a convenient, human-readable form.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-date.prototype.totimestring">
+ <h1><span class="secnum" id="sec-20.3.4.42"><a href="#sec-date.prototype.totimestring"
+ title="link to this section">20.3.4.42</a></span> Date.prototype.toTimeString ( )</h1>
+
+ <p>This function returns a String value. The contents of the String are implementation-dependent, but are intended to
+ represent the “time” portion of the Date in the current time zone in a convenient, human-readable form.</p>
+ </section>
+
+ <section id="sec-date.prototype.toutcstring">
+ <h1><span class="secnum" id="sec-20.3.4.43"><a href="#sec-date.prototype.toutcstring"
+ title="link to this section">20.3.4.43</a></span> Date.prototype.toUTCString ( )</h1>
+
+ <p>This function returns a String value. The contents of the String are implementation-dependent, but are intended to
+ represent <a href="#sec-properties-of-the-date-prototype-object">this time value</a> in a convenient, human-readable form
+ in UTC.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The intent is to produce a String representation of a date that is more readable than
+ the format specified in <a href="#sec-date-time-string-format">20.3.1.15</a>. It is not essential that the chosen format
+ be unambiguous or easily machine parsable. If an implementation does not have a preferred human-readable format it is
+ recommended to use the format defined in <a href="#sec-date-time-string-format">20.3.1.15</a> but with a space rather
+ than a “<code>T</code>” used to separate the date and time elements.</p>
+ </div>
+ </section>
+
+ <section id="sec-date.prototype.valueof">
+ <h1><span class="secnum" id="sec-20.3.4.44"><a href="#sec-date.prototype.valueof"
+ title="link to this section">20.3.4.44</a></span> Date.prototype.valueOf ( )</h1>
+
+ <p>The <code>valueOf</code> function returns a Number, which is <a
+ href="#sec-properties-of-the-date-prototype-object">this time value</a>.</p>
+ </section>
+
+ <section id="sec-date.prototype-@@toprimitive">
+ <h1><span class="secnum" id="sec-20.3.4.45"><a href="#sec-date.prototype-@@toprimitive"
+ title="link to this section">20.3.4.45</a></span> Date.prototype [ @@toPrimitive ] ( hint )</h1>
+
+ <p>This function is called by ECMAScript language operators to convert an object to a primitive value. The allowed values
+ for <var>hint</var> are "<code>default</code>", "<code>number</code>", and "<code>string</code>". Date objects, are
+ unique among built-in ECMAScript object in that they treat "<code>default</code>" as being equivalent to
+ "<code>string</code>", All other built-in ECMAScript objects treat "<code>default</code>" as being equivalent to
+ "<code>number</code>".</p>
+
+ <p>When the <code>@@toPrimitive</code> method is called with argument <var>hint</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the <b>this</b> value<b>.</b></li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>hint</i> is the string value "<code>string</code>" or the string value "<code>default</code>" , then
+ <ol class="block">
+ <li>Let <i>tryFirst</i> be "<code>string</code>".</li>
+ </ol>
+ </li>
+ <li>Else if <i>hint</i> is the string value "<code>number</code>", then
+ <ol class="block">
+ <li>Let <i>tryFirst</i> be "<code>number</code>".</li>
+ </ol>
+ </li>
+ <li>Else, throw a <b>TypeError</b> exception.</li>
+ <li>Return the result of OrdinaryToPrimitive(<i>O</i>, <i>tryFirst</i>).</li>
+ </ol>
+
+ <p>The value of the <code>name</code> property of this function is <code>"[Symbol.toPrimitive]"</code>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <span class="value">false</span>, [[Enumerable]]: <span
+ class="value">false</span>, [[Configurable]]: <span class="value">true</span> }.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-date-instances">
+ <h1><span class="secnum" id="sec-20.3.5"><a href="#sec-properties-of-date-instances"
+ title="link to this section">20.3.5</a></span> Properties of Date Instances</h1>
+
+ <p>Date instances are ordinary objects that inherit properties from the Date prototype object. Date instances also have a
+ [[DateValue]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>. The [[DateValue]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is the <a
+ href="#sec-time-values-and-time-range">time value</a> represented by this Date object.</p>
+ </section>
+ </section>
+</section>
+
+<section id="sec-text-processing">
+ <div class="front">
+ <h1><span class="secnum" id="sec-21"><a href="#sec-text-processing" title="link to this section">21</a></span> Text
+ Processing</h1>
+ </div>
+
+ <section id="sec-string-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-21.1"><a href="#sec-string-objects" title="link to this section">21.1</a></span> String
+ Objects</h1>
+ </div>
+
+ <section id="sec-string-constructor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-21.1.1"><a href="#sec-string-constructor" title="link to this section">21.1.1</a></span>
+ The String Constructor</h1>
+
+ <p>The String constructor is the %String% intrinsic object and the initial value of the <code>String</code> property of
+ the global object. When <code>String</code> is called as a function rather than as a constructor, it performs a type
+ conversion. However, if the <b>this</b> value passed in the call is an Object with an uninitialized [[StringData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, it initializes the <b>this</b> value using the
+ argument value. This permits <code>String</code> to be used both to perform type conversion and to perform constructor
+ instance initialization.</p>
+
+ <p>The <code>String</code> constructor is designed to be subclassable. It may be used as the value of an
+ <code>extends</code> clause of a class declaration. Subclass constructors that intended to inherit the specified
+ <code>String</code> behaviour must include a <code>super</code> call to the <code>String</code> constructor to initialize
+ the [[StringData]] state of subclass instances.</p>
+ </div>
+
+ <section id="sec-string-constructor-string-value">
+ <h1><span class="secnum" id="sec-21.1.1.1"><a href="#sec-string-constructor-string-value"
+ title="link to this section">21.1.1.1</a></span> String ( value )</h1>
+
+ <p>When <code>String</code> is called with argument <var>value</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>If no arguments were passed to this function invocation, then let <i>s</i> be <code>""</code>.</li>
+ <li>Else, let <i>s</i> be <a href="#sec-tostring">ToString</a>(<i>value</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>s</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is Object and <i>O</i> has a [[StringData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> and the value of [[StringData]] is
+ <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>length</i> be the number of code unit elements in <i>s.</i></li>
+ <li>Let <i>status</i> be the result of <a href="#sec-definepropertyorthrow">DefinePropertyOrThrow</a>(<i>O</i>,
+ <code>"length"</code>, PropertyDescriptor{[[Value]]: <i>length</i>, [[Writable]]: <b>false</b>, [[Enumerable]]:
+ <b>false</b>, [[Configurable]]: <b>false</b> }).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Set the value of <i>O’s</i> [[StringData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to <i>s</i>.</li>
+ <li>Return <i>O</i>.</li>
+ </ol>
+ </li>
+ <li>Return <i>s</i>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>String</code> function is <b>1</b>.</p>
+ </section>
+
+ <section id="sec-new-string-argumentslist">
+ <h1><span class="secnum" id="sec-21.1.1.2"><a href="#sec-new-string-argumentslist"
+ title="link to this section">21.1.1.2</a></span> new String ( ...argumentsList )</h1>
+
+ <p>When <code>String</code> is called as part of a new expression , it initializes a newly created exotic String
+ object:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be the <code>String</code> function object on which the <code>new</code> operator was applied.</li>
+ <li>Let <i>argumentsList</i> be the <i>argumentsList</i> argument of the [[Construct]] internal method that was invoked
+ by the <code>new</code> operator.</li>
+ <li>Return the result of <a href="#sec-construct-f-argumentslist">Construct</a> (<i>F</i>, <i>argumentsList</i>).</li>
+ </ol>
+
+ <p>If <code>String</code> is implemented as an <a href="#sec-ecmascript-function-objects">ECMAScript function object</a>,
+ its [[Construct]] internal method will perform the above steps.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-string-constructor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-21.1.2"><a href="#sec-properties-of-the-string-constructor"
+ title="link to this section">21.1.2</a></span> Properties of the String Constructor</h1>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the
+ String constructor is the standard built-in Function prototype object (<a
+ href="#sec-properties-of-the-function-prototype-object">19.2.3</a>).</p>
+
+ <p>Besides the <code>length</code> property (whose value is <b>1</b>), the String constructor has the following
+ properties:</p>
+ </div>
+
+ <section id="sec-string.fromcharcode">
+ <h1><span class="secnum" id="sec-21.1.2.1"><a href="#sec-string.fromcharcode"
+ title="link to this section">21.1.2.1</a></span> String.fromCharCode ( ...codeUnits )</h1>
+
+ <p>The <code>String.fromCharCode</code> function may be called with any number of arguments which form the rest parameter
+ <var>codeUnits</var>. The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>codeUnits</i> is be a <a href="#sec-list-and-record-specification-type">List</a> containing the arguments
+ passed to this function.</li>
+ <li>Let <i>length</i> be the number of elements in <i>codeUnits</i><b>.</b></li>
+ <li>Let <i>elements</i> be a new <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Let <i>nextIndex</i> be 0.</li>
+ <li>Repeat while <i>nextIndex</i> < <i>length</i>
+ <ol class="block">
+ <li>Let <i>next</i> be <i>codeUnits</i>[<i>nextIndex</i>].</li>
+ <li>Let <i>nextCU</i> be <a href="#sec-touint16">ToUint16</a>(<i>next</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>nextCU</i>).</li>
+ <li>Append <i>nextCU</i> to the end of <i>elements</i>.</li>
+ <li>Let <i>nextIndex</i> be <i>nextIndex</i> + 1.</li>
+ </ol>
+ </li>
+ <li>Return the String value whose elements are, in order, the elements in the <a
+ href="#sec-list-and-record-specification-type">List</a> <i>elements</i>. If <i>length</i> is 0, the empty string is
+ returned.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>fromCharCode</code> function is <b>1</b>.</p>
+ </section>
+
+ <section id="sec-string.fromcodepoint">
+ <h1><span class="secnum" id="sec-21.1.2.2"><a href="#sec-string.fromcodepoint"
+ title="link to this section">21.1.2.2</a></span> String.fromCodePoint ( ...codePoints )</h1>
+
+ <p>The <code>String.fromCodePoint</code> function may be called with any number of arguments which form the rest parameter
+ <var>codePoints</var>. The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>codePoints</i> be a <a href="#sec-list-and-record-specification-type">List</a> containing the arguments
+ passed to this function.</li>
+ <li>Let <i>length</i> be number of elements in <i>codePoints</i><code>.</code></li>
+ <li>Let <i>elements</i> be a new <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Let <i>nextIndex</i> be 0.</li>
+ <li>Repeat while <i>nextIndex</i> < <i>length</i>
+ <ol class="block">
+ <li>Let <i>next</i> be <i>codePoints</i>[<i>nextIndex</i>].</li>
+ <li>Let <i>nextCP</i> be <a href="#sec-tonumber">ToNumber</a>(<i>next</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>nextCP</i>).</li>
+ <li>If <a href="#sec-samevalue">SameValue</a>(<i>nextCP</i>, <a href="#sec-tointeger">ToInteger</a>(<i>nextCP</i>))
+ is <b>false</b>, then throw a <b>RangeError</b> exception.</li>
+ <li>If <i>nextCP</i> < 0 or <i>nextCP</i> > 0x10FFFF, then throw a <b>RangeError</b> exception.</li>
+ <li>Append the elements of the <a href="#sec-static-semantics-utf-16encoding">UTF-16Encoding</a> (<a
+ href="#sec-static-semantics-utf-16encoding">10.1.1</a>) of <i>nextCP</i> to the end of <i>elements</i>.</li>
+ <li>Let <i>nextIndex</i> be <i>nextIndex</i> + 1.</li>
+ </ol>
+ </li>
+ <li>Return the String value whose elements are, in order, the elements in the <a
+ href="#sec-list-and-record-specification-type">List</a> <i>elements</i>. If <i>length</i> is 0, the empty string is
+ returned.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>fromCodePoint</code> function is <b>1</b>.</p>
+ </section>
+
+ <section id="sec-string.prototype">
+ <h1><span class="secnum" id="sec-21.1.2.3"><a href="#sec-string.prototype"
+ title="link to this section">21.1.2.3</a></span> String.prototype</h1>
+
+ <p>The initial value of <code>String.prototype</code> is the standard built-in String prototype object (<a
+ href="#sec-properties-of-the-string-prototype-object">21.1.3</a>).</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-string.raw">
+ <h1><span class="secnum" id="sec-21.1.2.4"><a href="#sec-string.raw" title="link to this section">21.1.2.4</a></span>
+ String.raw ( callSite , ...substitutions )</h1>
+
+ <p>The <code>String.raw</code> function may be called with a variable number of arguments. The first argument is
+ <var>callSite</var> and the remainder of the arguments form the <a href="#sec-list-and-record-specification-type">List</a>
+ <var>substitutions</var>. The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>substitutions</i> be a <a href="#sec-list-and-record-specification-type">List</a> consisting of all of the
+ arguments passed to this function, starting with the second argument. If fewer than two arguments were passed, the
+ <a href="#sec-list-and-record-specification-type">List</a> is empty.</li>
+ <li>Let <i>numberOfSubstitutions</i> be the numer of elements in <i>substitutions</i>.</li>
+ <li>Let <i>cooked</i> be <a href="#sec-toobject">ToObject</a>(<i>callSite</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>cooked</i>).</li>
+ <li>Let <i>rawValue</i> be the result of <a href="#sec-get-o-p">Get</a>(<i>cooked</i>,
+ <code>"raw"</code>)<code>.</code></li>
+ <li>Let <i>raw</i> be <a href="#sec-toobject">ToObject</a>(<i>rawValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>raw</i>).</li>
+ <li>Let <i>len</i> be the result of <a href="#sec-get-o-p">Get</a>(<i>raw</i>, <code>"length"</code>)<code>.</code></li>
+ <li>Let <i>literalSegments</i> be <a href="#sec-tolength">ToLength</a>(<i>len</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>literalSegments</i>).</li>
+ <li>If <i>literalSegments</i> ≤ 0, then return the empty string.</li>
+ <li>Let <i>stringElements</i> be a new <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Let <i>nextIndex</i> be 0.</li>
+ <li>Repeat
+ <ol class="block">
+ <li>Let <i>nextKey</i> be <a href="#sec-tostring">ToString</a>(<i>nextIndex</i>).</li>
+ <li>Let <i>next</i> be the result of <a href="#sec-get-o-p">Get</a>(<i>raw</i>, <i>nextKey</i>).</li>
+ <li>Let <i>nextSeg</i> be <a href="#sec-tostring">ToString</a>(<i>next</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>nextSeg</i>).</li>
+ <li>Append in order the code unit elements of <i>nextSeg</i> to the end of <i>stringElements</i>.</li>
+ <li>If <i>nextIndex</i> + 1 = <i>literalSegments</i>, then
+ <ol class="block">
+ <li>Return the string value whose elements are, in order, the elements in the <a
+ href="#sec-list-and-record-specification-type">List</a> <i>stringElements</i>. If <i>stringElements</i> has
+ no elements, the empty string is returned.</li>
+ </ol>
+ </li>
+ <li>If <i>nextIndex< numberOfSubstitutions</i>, then let <i>next</i> be
+ <i>substitutions</i>[<i>nextIndex</i>].</li>
+ <li>Else, let <i>next</i> is the empty String.</li>
+ <li>Let <i>nextSub</i> be <a href="#sec-tostring">ToString</a>(<i>next</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>nextSub</i>).</li>
+ <li>Append in order the code unit elements of <i>nextSub</i> to the end of <i>stringElements</i>.</li>
+ <li>Let <i>nextIndex</i> be <i>nextIndex</i> + 1.</li>
+ </ol>
+ </li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>raw</code> function is <b>1</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> String.raw is intended for use as a tag function of a Tagged Template String (<a
+ href="#sec-tagged-templates">12.3.7</a>). When called as such the first argument will be a well formed template call
+ site object and the rest parameter will contain the substitution values.</p>
+ </div>
+ </section>
+
+ <section id="sec-string-@@create">
+ <h1><span class="secnum" id="sec-21.1.2.5"><a href="#sec-string-@@create" title="link to this section">21.1.2.5</a></span>
+ String[ @@create ] ( )</h1>
+
+ <p>The @@create method of an object <var>F</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be the <b>this</b> value.</li>
+ <li>Let <i>proto</i> be the result of <a
+ href="#sec-getprototypefromconstructor">GetPrototypeFromConstructor</a>(<i>F</i>,
+ <code>"%StringPrototype%"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>proto</i>).</li>
+ <li>Let <i>obj</i> be the result of calling <a href="#sec-stringcreate">StringCreate</a> (<i>proto</i>).</li>
+ <li>Return <i>obj</i>.</li>
+ </ol>
+
+ <p>The value of the <code>name</code> property of this function is <code>"[Symbol.create]"</code>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>true</b> }.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> [[StringData]] is initially assigned the value <b>undefined</b> as a flag to indicate
+ that the instance has not yet been initialized by the String constructor. This flag value is never directly exposed to
+ ECMAScript code; hence implementations may choose to encode the flag in some other manner.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-string-prototype-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-21.1.3"><a href="#sec-properties-of-the-string-prototype-object"
+ title="link to this section">21.1.3</a></span> Properties of the String Prototype Object</h1>
+
+ <p>The String prototype object is itself an ordinary object. It is not a String instance and does not have a
+ [[StringData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</p>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the
+ String prototype object is the standard built-in Object prototype object (<a
+ href="#sec-properties-of-the-object-prototype-object">19.1.3</a>).</p>
+
+ <p>Unless explicitly stated otherwise, the methods of the String prototype object defined below are not generic and the
+ <b>this</b> value passed to them must be either a String value or an object that has a [[StringData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> that has been initialized to a String value.</p>
+
+ <p>The abstract operation <span style="font-family: Times New Roman">thisStringValue(<i>value</i>)</span> performs the
+ following steps:</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>value</i>) is String, return <i>value</i>.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>value)</i> is Object and <i>value</i> has a
+ [[StringData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, then
+ <ol class="block">
+ <li>Let <i>s</i> be the value of <i>value’s</i> [[StringData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>s</i> is not <b>undefined</b>, then return <i>s</i>.</li>
+ </ol>
+ </li>
+ <li>Throw a <b>TypeError</b> exception.</li>
+ </ol>
+
+ <p>The phrase “this String value” within the specification of a method refers to the result returned by
+ calling the abstract operation <span style="font-family: Times New Roman">thisStringValue</span> with the <b>this</b>
+ value of the method invocation passed as the argument.</p>
+ </div>
+
+ <section id="sec-string.prototype.charat">
+ <h1><span class="secnum" id="sec-21.1.3.1"><a href="#sec-string.prototype.charat"
+ title="link to this section">21.1.3.1</a></span> String.prototype.charAt ( pos )</h1>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Returns a single element String containing the code unit at element position <i>pos</i>
+ in the String value resulting from converting this object to a String. If there is no element at that position, the
+ result is the empty String. The result is a String value, not a String object.</p>
+
+ <p>If <i>pos</i> is a value of Number type that is an integer, then the result of
+ <code>x.charAt(</code><i>pos</i><code>)</code> is equal to the result of
+ <code>x.substring(</code><i>pos</i><code>,</code> <i>pos</i><code>+1)</code>.</p>
+ </div>
+
+ <p>When the <code>charAt</code> method is called with one argument <var>pos</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be <a href="#sec-checkobjectcoercible">CheckObjectCoercible</a>(<b>this</b> value).</li>
+ <li>Let <i>S</i> be <a href="#sec-tostring">ToString</a>(<i>O</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>S</i>).</li>
+ <li>Let <i>position</i> be <a href="#sec-tointeger">ToInteger</a>(<i>pos</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>position</i>).</li>
+ <li>Let <i>size</i> be the number of elements in <i>S</i>.</li>
+ <li>If <i>position</i> < 0 or <i>position</i> ≥ <i>size</i>, return the empty String.</li>
+ <li>Return a String of length 1, containing one code unit from <i>S</i>, namely the code unit at position
+ <i>position</i>, where the first (leftmost) code unit in <i>S</i> is considered to be at position 0, the next one at
+ position 1, and so on.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>charAt</code> function is intentionally generic; it does not require that its
+ <b>this</b> value be a String object. Therefore, it can be transferred to other kinds of objects for use as a
+ method.</p>
+ </div>
+ </section>
+
+ <section id="sec-string.prototype.charcodeat">
+ <h1><span class="secnum" id="sec-21.1.3.2"><a href="#sec-string.prototype.charcodeat"
+ title="link to this section">21.1.3.2</a></span> String.prototype.charCodeAt ( pos )</h1>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Returns a Number (a nonnegative integer less than 2<sup>16</sup>) that is the code unit
+ value of the string element at position <i>pos</i> in the String resulting from converting this object to a String. If
+ there is no element at that position, the result is <b>NaN</b>.</p>
+ </div>
+
+ <p>When the <code>charCodeAt</code> method is called with one argument <var>pos</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be <a href="#sec-checkobjectcoercible">CheckObjectCoercible</a>(<b>this</b> value).</li>
+ <li>Let <i>S</i> be <a href="#sec-tostring">ToString</a>(<i>O</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>S</i>).</li>
+ <li>Let <i>position</i> be <a href="#sec-tointeger">ToInteger</a>(<i>pos</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>position</i>).</li>
+ <li>Let <i>size</i> be the number of elements in <i>S</i>.</li>
+ <li>If <i>position</i> < 0 or <i>position</i> ≥ <i>size</i>, return <b>NaN</b>.</li>
+ <li>Return a value of Number type, whose value is the code unit value of the element at position <i>position</i> in the
+ String <i>S</i>, where the first (leftmost) element in <i>S</i> is considered to be at position 0, the next one at
+ position 1, and so on.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>charCodeAt</code> function is intentionally generic; it does not require that
+ its <b>this</b> value be a String object. Therefore it can be transferred to other kinds of objects for use as a
+ method.</p>
+ </div>
+ </section>
+
+ <section id="sec-string.prototype.codepointat">
+ <h1><span class="secnum" id="sec-21.1.3.3"><a href="#sec-string.prototype.codepointat"
+ title="link to this section">21.1.3.3</a></span> String.prototype.codePointAt ( pos )</h1>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Returns a nonnegative integer Number less than 1114112 (0x110000) that is the UTF-16
+ encoded code point value starting at the string element at position <i>pos</i> in the String resulting from converting
+ this object to a String. If there is no element at that position, the result is <b>undefined</b>. If a valid UTF-16
+ surrogate pair does not begin at <i>pos</i>, the result is the code unit at <i>pos</i>.</p>
+ </div>
+
+ <p>When the <code>codePointAt</code> method is called with one argument <var>pos</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be <a href="#sec-checkobjectcoercible">CheckObjectCoercible</a>(<b>this</b> value).</li>
+ <li>Let <i>S</i> be <a href="#sec-tostring">ToString</a>(<i>O</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>S</i>).</li>
+ <li>Let <i>position</i> be <a href="#sec-tointeger">ToInteger</a>(<i>pos</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>position</i>).</li>
+ <li>Let <i>size</i> be the number of elements in <i>S</i>.</li>
+ <li>If <i>position</i> < 0 or <i>position</i> ≥ <i>size</i>, return <b>undefined</b>.</li>
+ <li>Let <i>first</i> be the code unit value of the element at index <i>position</i> in the String <i>S</i>.</li>
+ <li>If <i>first</i> < 0xD800 or <i>first</i> > 0xDBFF or <i>position</i>+1 = <i>size</i>, then return
+ <i>first</i>.</li>
+ <li>Let <i>second</i> be the code unit value of the element at index <i>position</i>+1 in the String <i>S</i>.</li>
+ <li>If <i>second</i> < 0xDC00 or <i>second</i> > 0xDFFF, then return <i>first</i>.</li>
+ <li>Return ((<i>first</i> – 0xD800) × 1024) + (<i>second</i> – 0xDC00) + 0x10000.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>codePointAt</code> function is intentionally generic; it does not require that
+ its <b>this</b> value be a String object. Therefore it can be transferred to other kinds of objects for use as a
+ method.</p>
+ </div>
+ </section>
+
+ <section id="sec-string.prototype.concat">
+ <h1><span class="secnum" id="sec-21.1.3.4"><a href="#sec-string.prototype.concat"
+ title="link to this section">21.1.3.4</a></span> String.prototype.concat ( ...args )</h1>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> When the <code>concat</code> method is called it returns a String consisting of the
+ string elements of this object (converted to a String) followed by the string elements of each of the arguments
+ converted to a String. The result is a String value, not a String object.</p>
+ </div>
+
+ <p>When the <code>concat</code> method is called with zero or more arguments the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be <a href="#sec-checkobjectcoercible">CheckObjectCoercible</a>(<b>this</b> value).</li>
+ <li>Let <i>S</i> be <a href="#sec-tostring">ToString</a>(<i>O</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>S</i>).</li>
+ <li>Let <i>args</i> be a <a href="#sec-list-and-record-specification-type">List</a> whose elements are the arguments
+ passed to this function.</li>
+ <li>Let <i>R</i> be <i>S</i>.</li>
+ <li>Repeat, while <i>args</i> is not empty
+ <ol class="block">
+ <li>Remove the first element from <i>args</i> and let <i>next</i> be the value of that element.</li>
+ <li>Let <i>nextString</i> be <a href="#sec-tostring">ToString</a>(<i>next</i>)</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>nextString</i>).</li>
+ <li>Let <i>R</i> be the String value consisting of the string elements in the previous value of <i>R</i> followed by
+ the string elements of <i>nextString</i>.</li>
+ </ol>
+ </li>
+ <li>Return <i>R</i>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>concat</code> method is <b>1</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>concat</code> function is intentionally generic; it does not require that its
+ <b>this</b> value be a String object. Therefore it can be transferred to other kinds of objects for use as a method.</p>
+ </div>
+ </section>
+
+ <section id="sec-string.prototype.constructor">
+ <h1><span class="secnum" id="sec-21.1.3.5"><a href="#sec-string.prototype.constructor"
+ title="link to this section">21.1.3.5</a></span> String.prototype.constructor</h1>
+
+ <p>The initial value of <code>String.prototype.constructor</code> is the built-in <code>String</code> constructor.</p>
+ </section>
+
+ <section id="sec-string.prototype.contains">
+ <h1><span class="secnum" id="sec-21.1.3.6"><a href="#sec-string.prototype.contains"
+ title="link to this section">21.1.3.6</a></span> String.prototype.contains ( searchString [ , position ] )</h1>
+
+ <p>The <b>contains</b> method takes two arguments, <i>searchString</i> and <i>position</i>, and performs the following
+ steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be <a href="#sec-checkobjectcoercible">CheckObjectCoercible</a>(<b>this</b> value).</li>
+ <li>Let <i>S</i> be <a href="#sec-tostring">ToString</a>(<i>O</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>S</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>searchString</i>) is Object, then
+ <ol class="block">
+ <li>Let <i>isRegExp</i> be <a href="#sec-hasproperty">HasProperty</a>(<i>searchString</i>, @@isRegExp).</li>
+ <li>If <i>isRegExp</i> is <b>true</b>, then throw a <b>TypeError</b> exception.</li>
+ </ol>
+ </li>
+ <li>Let <i>searchStr</i> be <a href="#sec-tostring">ToString</a>(<i>searchString</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>searchStr</i>).</li>
+ <li>Let <i>pos</i> be <a href="#sec-tointeger">ToInteger</a>(<i>position</i>). (If <i>position</i> is <b>undefined</b>,
+ this step produces the value <b>0</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>pos</i>).</li>
+ <li>Let <i>len</i> be the number of elements in <i>S</i>.</li>
+ <li>Let <i>start</i> be min(max(<i>pos</i>, 0), <i>len</i>).</li>
+ <li>Let <i>searchLen</i> be the number of elements in <i>searchStr</i>.</li>
+ <li>If there exists any integer <i>k</i> not smaller than <i>start</i> such that <i>k</i> + <i>searchLen</i> is not
+ greater than <i>len</i>, and for all nonnegative integers <i>j</i> less than <i>searchLen</i>, the character at
+ position <i>k</i>+<i>j</i> of <i>S</i> is the same as the character at position <i>j</i> of <i>searchStr,</i> return
+ <b>true</b>; but if there is no such integer <i>k</i>, return <b>false</b>.</li>
+ </ol>
+
+ <p>The <b>length</b> property of the <b>contains</b> method is <b>1</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> If <i>searchString</i> appears as a substring of the result of converting this object
+ to a String, at one or more positions that are greater than or equal to <i>position</i>, then return <b>true</b>;
+ otherwise, returns <b>false</b>. If <i>position</i> is <b>undefined</b>, 0 is assumed, so as to search all of the
+ String.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 2</span> Throwing an exception if the first argument is a RegExp is specified in order to allow
+ future editions to define extends that allow such argument values.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 3</span> The <code>contains</code> function is intentionally generic; it does not require that
+ its <b>this</b> value be a String object. Therefore, it can be transferred to other kinds of objects for use as a
+ method.</p>
+ </div>
+ </section>
+
+ <section id="sec-string.prototype.endswith">
+ <h1><span class="secnum" id="sec-21.1.3.7"><a href="#sec-string.prototype.endswith"
+ title="link to this section">21.1.3.7</a></span> String.prototype.endsWith ( searchString [ , endPosition] )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be <a href="#sec-checkobjectcoercible">CheckObjectCoercible</a>(<b>this</b> value).</li>
+ <li>Let <i>S</i> be <a href="#sec-tostring">ToString</a>(<i>O</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>S</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>searchString</i>) is Object, then
+ <ol class="block">
+ <li>Let <i>isRegExp</i> be <a href="#sec-hasproperty">HasProperty</a>(<i>searchString</i>, @@isRegExp).</li>
+ <li>If <i>isRegExp</i> is <b>true</b>, then throw a <b>TypeError</b> exception.</li>
+ </ol>
+ </li>
+ <li>Let <i>searchStr</i> be <a href="#sec-tostring">ToString</a>(<i>searchString</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>searchStr</i>).</li>
+ <li>Let <i>len</i> be the number of elements in <i>S</i>.</li>
+ <li>If <i>endPosition</i> is <b>undefined</b>, let <i>pos</i> be <i>len</i>, else let <i>pos</i> be <a
+ href="#sec-tointeger">ToInteger</a>(<i>endPosition</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>pos</i>).</li>
+ <li>Let <i>end</i> be min(max(<i>pos</i>, 0), <i>len</i>).</li>
+ <li>Let <i>searchLength</i> be the number of elements in <i>searchStr</i>.</li>
+ <li>Let <i>start</i> be <i>end</i> - <i>searchLength</i>.</li>
+ <li>If <i>start</i> is less than 0, return <b>false</b><i>.</i></li>
+ <li>If the <i>searchLength</i> sequence of elements of <i>S</i> starting at <i>start</i> is the same as the full element
+ sequence of <i>searchStr</i>, return <b>true</b>.</li>
+ <li>Otherwise, return <b>false</b>.</li>
+ </ol>
+
+ <p>The <b>length</b> property of the <b>endsWith</b> method is <b>1</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> Returns <b>true</b> if the sequence of elements of <i>searchString</i> converted to a
+ String is the same as the corresponding elements of this object (converted to a String) starting at <i>endPosition</i>
+ – length(this). Otherwise returns <b>false</b>.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 2</span> Throwing an exception if the first argument is a RegExp is specified in order to allow
+ future editions to define extends that allow such argument values.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 3</span> The <b>endsWith</b> function is intentionally generic; it does not require that its
+ <b>this</b> value be a String object. Therefore, it can be transferred to other kinds of objects for use as a
+ method.</p>
+ </div>
+ </section>
+
+ <section id="sec-string.prototype.indexof">
+ <h1><span class="secnum" id="sec-21.1.3.8"><a href="#sec-string.prototype.indexof"
+ title="link to this section">21.1.3.8</a></span> String.prototype.indexOf ( searchString [ , position ] )</h1>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> If <i>searchString</i> appears as a substring of the result of converting this object to
+ a String, at one or more positions that are greater than or equal to <i>position</i>, then the index of the smallest
+ such position is returned; otherwise, <code>‑1</code> is returned. If <i>position</i> is <b>undefined</b>, 0 is
+ assumed, so as to search all of the String.</p>
+ </div>
+
+ <p>The <code>indexOf</code> method takes two arguments, <var>searchString</var> and <var>position</var>, and performs the
+ following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be <a href="#sec-checkobjectcoercible">CheckObjectCoercible</a>(<b>this</b> value).</li>
+ <li>Let <i>S</i> be <a href="#sec-tostring">ToString</a>(<i>O</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>S</i>).</li>
+ <li>Let <i>searchStr</i> be <a href="#sec-tostring">ToString</a>(<i>searchString</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>searchString</i>).</li>
+ <li>Let <i>pos</i> be <a href="#sec-tointeger">ToInteger</a>(<i>position</i>). (If <i>position</i> is <b>undefined</b>,
+ this step produces the value <code>0</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>pos</i>).</li>
+ <li>Let <i>len</i> be the number of elements in <i>S</i>.</li>
+ <li>Let <i>start</i> be min(max(<i>pos</i>, 0), <i>len</i>).</li>
+ <li>Let <i>searchLen</i> be the number of elements in <i>searchStr</i>.</li>
+ <li>Return the smallest possible integer <i>k</i> not smaller than <i>start</i> such that <i>k</i>+ <i>searchLen</i> is
+ not greater than <i>len</i>, and for all nonnegative integers <i>j</i> less than <i>searchLen</i>, the code unit at
+ position <i>k</i>+<i>j</i> of <i>S</i> is the same as the code unit at position <i>j</i> of <i>searchStr</i>; but if
+ there is no such integer <i>k</i>, then return the value <code>-1</code><span style="font-family:
+ sans-serif">.</span></li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>indexOf</code> method is <b>1</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>indexOf</code> function is intentionally generic; it does not require that its
+ <b>this</b> value be a String object. Therefore, it can be transferred to other kinds of objects for use as a
+ method.</p>
+ </div>
+ </section>
+
+ <section id="sec-string.prototype.lastindexof">
+ <h1><span class="secnum" id="sec-21.1.3.9"><a href="#sec-string.prototype.lastindexof"
+ title="link to this section">21.1.3.9</a></span> String.prototype.lastIndexOf ( searchString [ , position ] )</h1>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> If <i>searchString</i> appears as a substring of the result of converting this object to
+ a String at one or more positions that are smaller than or equal to <i>position</i>, then the index of the greatest such
+ position is returned; otherwise, <code>‑1</code> is returned. If <i>position</i> is <b>undefined</b>, the length
+ of the String value is assumed, so as to search all of the String.</p>
+ </div>
+
+ <p>The <code>lastIndexOf</code> method takes two arguments, <var>searchString</var> and <var>position</var>, and performs
+ the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be <a href="#sec-checkobjectcoercible">CheckObjectCoercible</a>(<b>this</b> value).</li>
+ <li>Let <i>S</i> be <a href="#sec-tostring">ToString</a>(<i>O</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>S</i>).</li>
+ <li>Let <i>searchStr</i> be <a href="#sec-tostring">ToString</a>(<i>searchString</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>searchString</i>).</li>
+ <li>Let <i>numPos</i> be <a href="#sec-tonumber">ToNumber</a>(<i>position</i>). (If <i>position</i> is <b>undefined</b>,
+ this step produces the value <b>NaN</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>numPos</i>).</li>
+ <li>If <i>numPos</i> is <b>NaN</b>, let <i>pos</i> be <b>+∞</b>; otherwise, let <i>pos</i> be <a
+ href="#sec-tointeger">ToInteger</a>(<i>numPos</i>).</li>
+ <li>Let <i>len</i> be the number of elements in <i>S</i>.</li>
+ <li>Let <i>start</i> be min(max(<i>pos</i>, 0), <i>len</i>).</li>
+ <li>Let <i>searchLen</i> be the number of elements in <i>searchStr</i>.</li>
+ <li>Return the largest possible nonnegative integer <i>k</i> not larger than <i>start</i> such that <i>k</i>+
+ <i>searchLen</i> is not greater than <i>len</i>, and for all nonnegative integers <i>j</i> less than
+ <i>searchLen</i>, the code unit at position <i>k</i>+<i>j</i> of <i>S</i> is the same as the code unit at position
+ <i>j</i> of <i>searchStr</i>; but if there is no such integer <i>k</i>, then return the value <code>-1</code>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>lastIndexOf</code> method is <b>1</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>lastIndexOf</code> function is intentionally generic; it does not require that
+ its <b>this</b> value be a String object. Therefore, it can be transferred to other kinds of objects for use as a
+ method.</p>
+ </div>
+ </section>
+
+ <section id="sec-string.prototype.localecompare">
+ <h1><span class="secnum" id="sec-21.1.3.10"><a href="#sec-string.prototype.localecompare"
+ title="link to this section">21.1.3.10</a></span> String.prototype.localeCompare ( that [, reserved1 [ , reserved2 ] ]
+ )</h1>
+
+ <p>An ECMAScript implementation that includes the ECMA-402 International API must implement the <code>localeCompare</code>
+ method as specified in the ECMA-402 specification. If an ECMAScript implementation does not include the ECMA-402 API the
+ following specification of the <code>localeCompare</code> method is used.</p>
+
+ <p>When the <code>localeCompare</code> method is called with argument <var>that</var>, it returns a Number other than
+ <b>NaN</b> that represents the result of a locale-sensitive String comparison of the <b>this</b> value (converted to a
+ String) with <var>that</var> (converted to a String). The two Strings are <var>S</var> and <span class="nt">That</span>.
+ The two Strings are compared in an implementation-defined fashion. The result is intended to order String values in the
+ sort order specified by the system default locale, and will be negative, zero, or positive, depending on whether
+ <var>S</var> comes before <span class="nt">That</span> in the sort order, the Strings are equal, or <var>S</var> comes
+ after <span class="nt">That</span> in the sort order, respectively.</p>
+
+ <p>Before perform the comparisons the following steps are performed to prepare the Strings:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be <a href="#sec-checkobjectcoercible">CheckObjectCoercible</a>(<b>this</b> value).</li>
+ <li>Let <i>S</i> be <a href="#sec-tostring">ToString</a>(<i>O</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>S</i>).</li>
+ <li>Let <i>That</i> be <a href="#sec-tostring">ToString</a>(<i>that</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>That</i>).</li>
+ </ol>
+
+ <p>The meaning of the optional second and third parameters to this method are defined in the ECMA-402 specification;
+ implementations that do not include ECMA-402 support must not assign any other interpretation to those parameter
+ position.</p>
+
+ <p>The <code>localeCompare</code> method, if considered as a function of two arguments <b>this</b> and <var>that</var>, is
+ a consistent comparison function (as defined in <a href="#sec-array.prototype.sort">22.1.3.24</a>) on the set of all
+ Strings.</p>
+
+ <p>The actual return values are implementation-defined to permit implementers to encode additional information in the
+ value, but the function is required to define a total ordering on all Strings. If the implementation performs
+ language-sensitive comparisions it must return <code>0</code> when comparing Strings that are considered canonically
+ equivalent by the Unicode standard.</p>
+
+ <p>If no language-sensitive comparison at all is available from the host environment, this function may perform a bitwise
+ comparison.</p>
+
+ <p>The <code>length</code> property of the <code>localeCompare</code> method is <b>1</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> The <code>localeCompare</code> method itself is not directly suitable as an argument
+ to <code><a href="#sec-array.prototype.sort">Array.prototype.sort</a></code> because the latter requires a function of
+ two arguments.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 2</span> This function is intended to rely on whatever language-sensitive comparison
+ functionality is available to the ECMAScript environment from the host environment, and to compare according to the
+ rules of the host environment’s current locale. This function must treat Strings that are canonically equivalent
+ according to the Unicode standard as identical. It is also recommended that this function not honour Unicode
+ compatibility equivalences or decompositions. For a definition and discussion of canonical equivalence see the Unicode
+ Standard, chapters 2 and 3, as well as Unicode Annex #15, Unicode Normalization Forms and Unicode Technical Note #5
+ Canonical Equivalence in Applications. Also see Unicode Technical Stardard #10, Unicode Collation Algorithm.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 3</span> The <code>localeCompare</code> function is intentionally generic; it does not require
+ that its <b>this</b> value be a String object. Therefore, it can be transferred to other kinds of objects for use as a
+ method.</p>
+ </div>
+ </section>
+
+ <section id="sec-string.prototype.match">
+ <h1><span class="secnum" id="sec-21.1.3.11"><a href="#sec-string.prototype.match"
+ title="link to this section">21.1.3.11</a></span> String.prototype.match ( regexp )</h1>
+
+ <p>When the <code>match</code> method is called with argument <var>regexp</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be <a href="#sec-checkobjectcoercible">CheckObjectCoercible</a>(<b>this</b> value).</li>
+ <li>Let <i>S</i> be <a href="#sec-tostring">ToString</a>(<i>O</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>S</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>regexp</i>) is Object and <a
+ href="#sec-hasproperty">HasProperty</a>(<i>regexp</i>, @@isRegExp) is <b>true</b>, then let <i>rx</i> be
+ <i>regexp</i>;</li>
+ <li>Else, let <i>rx</i> be the result of the abstract operation <a href="#sec-regexpcreate">RegExpCreate</a> (<a
+ href="#sec-abstract-operations-for-the-regexp-constructor">21.2.3.3</a>) with arguments <i>regexp</i> and
+ <b>undefined</b>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>rx</i>).</li>
+ <li>Return the result of <a href="#sec-invoke">Invoke</a>(<i>rx</i>, <code>"match"</code>, ( <i>S</i> )). <i>.</i></li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>match</code> function is intentionally generic; it does not require that its
+ <b>this</b> value be a String object. Therefore, it can be transferred to other kinds of objects for use as a
+ method.</p>
+ </div>
+ </section>
+
+ <section id="sec-string.prototype.normalize">
+ <h1><span class="secnum" id="sec-21.1.3.12"><a href="#sec-string.prototype.normalize"
+ title="link to this section">21.1.3.12</a></span> String.prototype.normalize ( [ form ] )</h1>
+
+ <p>When the <code>normalize</code> method is called with one argument <var>form</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be <a href="#sec-checkobjectcoercible">CheckObjectCoercible</a>(<b>this</b> value).</li>
+ <li>Let <i>S</i> be <a href="#sec-tostring">ToString</a>(<i>O</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>S</i>).</li>
+ <li>If <i>form</i> is not provided or <i>form</i> is <b>undefined</b> let <i>form</i> be
+ <code><b>"</b>NFC<b>"</b></code>.</li>
+ <li>Let <i>f</i> be <a href="#sec-tostring">ToString</a>(<i>form</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>f</i>).</li>
+ <li>If <i>f</i> is not one of <code><b>"</b>NFC<b>"</b></code>, <code><b>"</b>NFD<b>"</b></code>,
+ <code><b>"</b>NFKC<b>"</b></code>, or <code><b>"</b>NFKD<b>"</b></code>, then throw a <b>RangeError</b>
+ Exception.</li>
+ <li>Let <i>ns</i> be the String value is the result of normalizing <i>S</i> into the normalization form named by
+ <i>f</i> as specified in <i>Unicode Standard Annex #15, Unicode</i> <i>Normalization Forms</i>.</li>
+ <li>Return <i>ns</i>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>normalize</code> method is <b>0</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>normalize</code> function is intentionally generic; it does not require that
+ its <b>this</b> value be a String object. Therefore it can be transferred to other kinds of objects for use as a
+ method.</p>
+ </div>
+ </section>
+
+ <section id="sec-string.prototype.repeat">
+ <h1><span class="secnum" id="sec-21.1.3.13"><a href="#sec-string.prototype.repeat"
+ title="link to this section">21.1.3.13</a></span> String.prototype.repeat ( count )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be <a href="#sec-checkobjectcoercible">CheckObjectCoercible</a>(<b>this</b> value).</li>
+ <li>Let <i>S</i> be <a href="#sec-tostring">ToString</a>(<i>O</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>S</i>).</li>
+ <li>Let <i>n</i> be the result of calling <a href="#sec-tointeger">ToInteger</a>(<i>count</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>n</i>).</li>
+ <li>If <i>n</i> < 0, then throw a <b>RangeError</b> exception.</li>
+ <li>If <i>n</i> is +∞, then throw a <b>RangeError</b> exception.</li>
+ <li>Let <i>T</i> be a String value that is made from <i>n</i> copies of <i>S</i> appended together. If <i>n</i> is 0,
+ <i>T</i> is the empty String.</li>
+ <li>Return <i>T</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> This method creates a String consisting of the string elements of this object
+ (converted to String) repeated <i>count</i> times.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 2</span> The <code>repeat</code> function is intentionally generic; it does not require that
+ its <b>this</b> value be a String object. Therefore, it can be transferred to other kinds of objects for use as a
+ method.</p>
+ </div>
+ </section>
+
+ <section id="sec-string.prototype.replace">
+ <div class="front">
+ <h1><span class="secnum" id="sec-21.1.3.14"><a href="#sec-string.prototype.replace"
+ title="link to this section">21.1.3.14</a></span> String.prototype.replace (searchValue, replaceValue )</h1>
+
+ <p>When the <code>replace</code> method is called with arguments <var>searchValue</var> and <var>replaceValue</var> the
+ following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be <a href="#sec-checkobjectcoercible">CheckObjectCoercible</a>(<b>this</b> value).</li>
+ <li>Let <i>string</i> be <a href="#sec-tostring">ToString</a>(<i>O</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>string</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>searchValue</i>) is Object and <a
+ href="#sec-hasproperty">HasProperty</a>(<i>searchValue</i>, @@isRegExp) is <b>true</b>, then
+ <ol class="block">
+ <li>Return <a href="#sec-invoke">Invoke</a>(<i>searchValue</i>, <code>"replace"</code>, (<i>string</i>,
+ <i>replaceValue</i>)).</li>
+ </ol>
+ </li>
+ <li>Let <i>searchString</i> be <a href="#sec-tostring">ToString</a>(<i>searchValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>searchString</i>).</li>
+ <li>Search <i>string</i> for the first occurrence of <i>searchString</i> and let <i>pos</i> be the index position
+ within <i>string</i> of the first code unit of the matched substring and let <i>matched</i> be
+ <i>searchString</i>. If no occurrences of <i>searchString</i> were found, return <i>string</i>.</li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>replaceValue</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>replValue</i> be the result of calling the [[Call]] internal method of <i>replaceValue</i> passing
+ <b>undefined</b> as the <b>this</b> value and a <a href="#sec-list-and-record-specification-type">List</a>
+ containing <i>matched</i>, <i>pos</i>, and <i>string</i> as the argument list.</li>
+ <li>Let <i>replStr</i> be <a href="#sec-tostring">ToString</a>(<i>replValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>replStr</i>).</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>captures</i> be an empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Let <i>replacement</i> be <a href="#sec-tostring">ToString</a>(<i>replaceValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>replacement</i>).</li>
+ <li>Let <i>replStr</i> be <a href="#sec-getreplacesubstitution">GetReplaceSubstitution</a>(<i>matched</i>,
+ <i>string</i>, <i>pos</i>, <i>captures</i>, <i>replacement</i>).</li>
+ </ol>
+ </li>
+ <li>Let <i>tailPos</i> be <i>pos</i> + the number of code units in <i>matched</i>.</li>
+ <li>Let <i>newString</i> be the String formed by concatenating the first <i>pos</i> code units of <i>string</i>,
+ <i>replStr</i>, and the trailing substring of <i>string</i> starting at index <i>tailPos</i>. If <i>pos</i> is 0,
+ the first element of the concatenation will be the empty String.</li>
+ <li>Return <i>newString</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>replace</code> function is intentionally generic; it does not require that
+ its <b>this</b> value be a String object. Therefore, it can be transferred to other kinds of objects for use as a
+ method.</p>
+ </div>
+ </div>
+
+ <section id="sec-getreplacesubstitution">
+ <h1><span class="secnum" id="sec-21.1.3.14.1"><a href="#sec-getreplacesubstitution"
+ title="link to this section">21.1.3.14.1</a></span> Runtime Semantics: GetReplaceSubstitution Abstract
+ Operation</h1>
+
+ <p>The abstract operation GetReplaceSubstitution(<var>matched</var>, <var>string</var>, <var>position</var>, <span
+ style="font-family: Times New Roman"><i>captures</i>, <i>replacement</i></span>) performs the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>matched</i>) is String.</li>
+ <li>Let <i>matchLength</i> be the number of code units in <i>matched</i>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>string</i>) is String.</li>
+ <li>Let <i>stringLength</i> be the number of code units in <i>string</i>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>position</i> is a nonnegative integer.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>position</i> ≤ <i>stringLength</i>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>captures</i> is a possibly empty <a
+ href="#sec-list-and-record-specification-type">List</a> of Strings.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>:<a href="#sec-ecmascript-data-types-and-values">Type</a>(
+ <i>replacement</i>) is String</li>
+ <li>Let <i>tailPos</i> be <i>position</i> + <i>matchLength</i>.</li>
+ <li>Let <i>m</i> be the number of elements in <i>captures</i>.</li>
+ <li>Let <i>result</i> be a String value derived from <i>replacement</i> by copying code unit elements from
+ <i>replacement</i> to <i>result</i> while performing replacements as specified in <a href="#table-40">Table
+ 40</a>. These <code>$</code> replacements are done left-to-right, and, once such a replacement is performed, the
+ new replacement text is not subject to further replacements.</li>
+ <li>Return <i>result</i>.</li>
+ </ol>
+
+ <figure>
+ <figcaption><span id="table-40">Table 40</span> — Replacement Text Symbol Substitutions</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-top: 2px solid #000000">Code units</th>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 0px solid black; border-top: 2px solid #000000">Unicode Characters</th>
+ <th style="border-bottom: 1px solid #000000; border-left: 0px solid black; border-right: 1px solid #000000; border-top: 2px solid #000000">Replacement text</th>
+ </tr>
+ <tr>
+ <td>0x0024, 0x0024</td>
+ <td><code>$$</code></td>
+ <td><code>$</code></td>
+ </tr>
+ <tr>
+ <td>0x0024, 0x0026</td>
+ <td><code>$&</code></td>
+ <td><i>matched</i></td>
+ </tr>
+ <tr>
+ <td>0x0024, 0x0060</td>
+ <td><code>$`</code></td>
+ <td>If <i>position</i> is 0, the replacement is the empty String. Otherwise the replacement is the substring of <i>string</i> that starts at index 0 and whose last code point is at index <i>position</i> -1.</td>
+ </tr>
+ <tr>
+ <td>0x0024, 0x0027</td>
+ <td><code>$'</code></td>
+ <td>If <i>tailPos</i> ≥ <i>stringLength</i>, the replacement is the empty String. Otherwise the replacement is the substring of <i>string</i> that starts at index <i>tailPos</i> and continues to the end of <i>string</i>.</td>
+ </tr>
+ <tr>
+ <td>0x0024, N where<br>0x0031 ≤ N ≤ 0x0039</td>
+ <td><code>$n</code> <span style="font-family: Times New Roman">where</span> <code><br>n</code> <span style="font-family: Times New Roman">is one of</span> <code>1 2 3 4 5 6 7 8 9</code> <span style="font-family: Times New Roman">and</span> <code>$n</code> <span style="font-family: Times New Roman">is not followed by a decimal digit</span></td>
+ <td>The <i>n</i><sup>th</sup> element of <i>captures</i>, where <i>n</i> is a single digit in the range 1 to 9. If <i>n</i>≤<i>m</i> and the <i>n</i>th element of <i>captures</i> is <b>undefined</b>, use the empty String instead. If <i>n</i>><i>m</i>, the result is implementation-defined.</td>
+ </tr>
+ <tr>
+ <td>0x0024, N, N where<br>0x0030 ≤ N ≤ 0x0039</td>
+ <td><code>$nn</code> <span style="font-family: Times New Roman">where</span> <code><br>n</code> <span style="font-family: Times New Roman">is one of</span> <code>0 1 2 3 4 5 6 7 8 9</code></td>
+ <td>The <i>nn</i><sup>th</sup> element of <i>captures</i>, where <i>nn</i> is a two-digit decimal number in the range 01 to 99. If <i>nn</i>≤<i>m</i> and the <i>nn</i><sup>th</sup> element of <i>captures</i> is <b>undefined</b>, use the empty String instead. If <i>nn</i> is 00 or <i>nn</i>><i>m</i>, the result is implementation-defined.</td>
+ </tr>
+ <tr>
+ <td>0x0024</td>
+ <td><code>$</code> <span style="font-family: Times New Roman">in any context that does not match any of the above.</span></td>
+ <td><code>$</code></td>
+ </tr>
+ </table>
+ </figure>
+ </section>
+ </section>
+
+ <section id="sec-string.prototype.search">
+ <h1><span class="secnum" id="sec-21.1.3.15"><a href="#sec-string.prototype.search"
+ title="link to this section">21.1.3.15</a></span> String.prototype.search ( regexp )</h1>
+
+ <p>When the search method is called with argument <var>regexp</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be <a href="#sec-checkobjectcoercible">CheckObjectCoercible</a>(<b>this</b> value).</li>
+ <li>Let <i>string</i> be <a href="#sec-tostring">ToString</a>(<i>O</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>string</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>regexp</i>) is Object and <a
+ href="#sec-hasproperty">HasProperty</a>(<i>regexp</i>, @@isRegExp) is <b>true</b> , then,
+ <ol class="block">
+ <li>Let <i>rx</i> be <i>regexp</i>;</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>rx</i> be the result of the abstract operation <a href="#sec-regexpcreate">RegExpCreate</a> (<a
+ href="#sec-abstract-operations-for-the-regexp-constructor">21.2.3.3</a>) with arguments <i>regexp</i> and
+ <b>undefined</b>.</li>
+ </ol>
+ </li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>rx</i>).</li>
+ <li>Return the result of <a href="#sec-invoke">Invoke</a>(<i>rx</i>, <code>"search"</code>, (<i>string</i>)).</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>search</code> function is intentionally generic; it does not require that its
+ <b>this</b> value be a String object. Therefore, it can be transferred to other kinds of objects for use as a
+ method.</p>
+ </div>
+ </section>
+
+ <section id="sec-string.prototype.slice">
+ <h1><span class="secnum" id="sec-21.1.3.16"><a href="#sec-string.prototype.slice"
+ title="link to this section">21.1.3.16</a></span> String.prototype.slice ( start, end )</h1>
+
+ <p>The <code>slice</code> method takes two arguments, <var>start</var> and <var>end</var>, and returns a substring of the
+ result of converting this object to a String, starting from element position <var>start</var> and running to, but not
+ including, element position <var>end</var> (or through the end of the String if <var>end</var> is <b>undefined</b>). If
+ <var>start</var> is negative, it is treated as <span style="font-family: Times New
+ Roman"><i>sourceLength</i>+<i>start</i></span> where <var>sourceLength</var> is the length of the String. If
+ <var>end</var> is negative, it is treated as <span style="font-family: Times New
+ Roman"><i>sourceLength</i>+<i>end</i></span> where <var>sourceLength</var> is the length of the String. The result is a
+ String value, not a String object. The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be <a href="#sec-checkobjectcoercible">CheckObjectCoercible</a>(<b>this</b> value).</li>
+ <li>Let <i>S</i> be <a href="#sec-tostring">ToString</a>(<i>O</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>S</i>).</li>
+ <li>Let <i>len</i> be the number of elements in <i>S</i>.</li>
+ <li>Let <i>intStart</i> be <a href="#sec-tointeger">ToInteger</a>(<i>start</i>).</li>
+ <li>If <i>end</i> is <b>undefined</b>, let <i>intEnd</i> be <i>len</i>; else let <i>intEnd</i> be <a
+ href="#sec-tointeger">ToInteger</a>(<i>end</i>).</li>
+ <li>If <i>intStart</i> is negative, let <i>from</i> be max(<i>len</i> + <i>intStart</i>,0); else let <i>from</i> be
+ min(<i>intStart</i>, <i>len</i>).</li>
+ <li>If <i>intEnd</i> is negative, let <i>to</i> be max(<i>len</i> + <i>intEnd</i>,0); else let <i>to</i> be
+ min(<i>intEnd</i>, <i>len</i>).</li>
+ <li>Let <i>span</i> be max(<i>to</i> – <i>from</i>,0).</li>
+ <li>Return a String value containing <i>span</i> consecutive elements from <i>S</i> beginning with the element at
+ position <i>from</i>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>slice</code> method is <b>2</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>slice</code> function is intentionally generic; it does not require that its
+ <b>this</b> value be a String object. Therefore it can be transferred to other kinds of objects for use as a method.</p>
+ </div>
+ </section>
+
+ <section id="sec-string.prototype.split">
+ <div class="front">
+ <h1><span class="secnum" id="sec-21.1.3.17"><a href="#sec-string.prototype.split"
+ title="link to this section">21.1.3.17</a></span> String.prototype.split ( separator, limit )</h1>
+
+ <p>Returns an Array object into which substrings of the result of converting this object to a String have been stored.
+ The substrings are determined by searching from left to right for occurrences of <var>separator</var>; these occurrences
+ are not part of any substring in the returned array, but serve to divide up the String value. The value of
+ <var>separator</var> may be a String of any length or it may be a RegExp object.</p>
+
+ <p>When the <code>split</code> method is called, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be <a href="#sec-checkobjectcoercible">CheckObjectCoercible</a>(<b>this</b> value).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>O</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>separator</i>) is Object and <a
+ href="#sec-hasproperty">HasProperty</a>(<i>separator</i>, @@isRegExp) is <b>true</b> , then,
+ <ol class="block">
+ <li>Return the result of <a href="#sec-invoke">Invoke</a>(<i>separator</i>, <code>"split"</code>, (<i>O</i>,
+ <i>limit</i>))</li>
+ </ol>
+ </li>
+ <li>Let <i>S</i> be <a href="#sec-tostring">ToString</a>(<i>O</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>S</i>).</li>
+ <li>Let <i>A</i> be the result of the abstract operation <a href="#sec-arraycreate">ArrayCreate</a> with argument
+ 0.</li>
+ <li>Let <i>lengthA</i> be 0.</li>
+ <li>If <i>limit</i> is <b>undefined</b>, let <i>lim</i> = 2<sup>53</sup>–1; else let <i>lim</i> = <a
+ href="#sec-tolength">ToLength</a>(<i>limit</i>).</li>
+ <li>Let <i>s</i> be the number of elements in <i>S</i>.</li>
+ <li>Let <i>p</i> = 0.</li>
+ <li>Let <i>R</i> be <a href="#sec-tostring">ToString</a>(<i>separator</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>R</i>).</li>
+ <li>If <i>lim</i> = 0, return <i>A</i>.</li>
+ <li>If <i>separator</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>Call <a href="#sec-createdataproperty">CreateDataProperty</a>(<i>A</i>, <code>"<b>0</b>"</code>,
+ <i>S</i>).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: The above call will never result in an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a>.</li>
+ <li>Return <i>A</i>.</li>
+ </ol>
+ </li>
+ <li>If <i>s</i> = 0, then
+ <ol class="block">
+ <li>Let <i>z</i> be the result of <a href="#sec-splitmatch">SplitMatch</a>(<i>S</i>, 0, <i>R</i>).</li>
+ <li>If <i>z</i> is not <b>false</b>, return <i>A</i>.</li>
+ <li>Call <a href="#sec-createdataproperty">CreateDataProperty</a>(<i>A</i>, <code>"<b>0</b>"</code>,
+ <i>S</i>).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: The above call will never result in an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a>.</li>
+ <li>Return <i>A</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>q</i> = <i>p</i>.</li>
+ <li>Repeat, while <i>q</i> ≠ <i>s</i>
+ <ol class="block">
+ <li>Let <i>e</i> be the result of <a href="#sec-splitmatch">SplitMatch</a>(<i>S, q, R</i>).</li>
+ <li>If <i>e</i> is <b>false</b>, then let <i>q</i> = <i>q</i>+1.</li>
+ <li>Else <i>e</i> is an integer index into <i>S</i>,
+ <ol class="block">
+ <li>If <i>e</i> = <i>p</i>, then let <i>q</i> = <i>q</i>+1.</li>
+ <li>Else <i>e</i> ≠ <i>p</i>,
+ <ol class="block">
+ <li>Let <i>T</i> be a String value equal to the substring of <i>S</i> consisting of the code units at
+ positions <i>p</i> (inclusive) through <i>q</i> (exclusive).</li>
+ <li>Call <a href="#sec-createdataproperty">CreateDataProperty</a>(<i>A</i>, <a
+ href="#sec-tostring">ToString</a>(<i>lengthA</i>), <i>T</i>).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: The above call will never result in an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a>.</li>
+ <li>Increment <i>lengthA</i> by 1.</li>
+ <li>If <i>lengthA</i> = <i>lim</i>, return <i>A</i>.</li>
+ <li>Let <i>p</i> = <i>e</i>.</li>
+ <li>Let <i>q</i> = <i>p</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Let <i>T</i> be a String value equal to the substring of <i>S</i> consisting of the code units at positions
+ <i>p</i> (inclusive) through <i>s</i> (exclusive).</li>
+ <li>Call <a href="#sec-createdataproperty">CreateDataProperty</a>(<i>A</i>, <a
+ href="#sec-tostring">ToString</a>(<i>lengthA</i>), <i>T</i>).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: The above call will never result in an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a>.</li>
+ <li>Return <i>A</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The value of <i>separator</i> may be an empty String, an empty regular expression, or
+ a regular expression that can match an empty String. In this case, <i>separator</i> does not match the empty substring
+ at the beginning or end of the input String, nor does it match the empty substring at the end of the previous
+ separator match. (For example, if <i>separator</i> is the empty String, the String is split up into individual code
+ unit elements; the length of the result array equals the length of the String, and each substring contains one code
+ unit.) If <i>separator</i> is a regular expression, only the first match at a given position of the <b>this</b> String
+ is considered, even if backtracking could yield a non-empty-substring match at that position. (For example,
+ <code>"ab".split(/a*?/)</code> evaluates to the array <code>["a","b"]</code>, while <code>"ab".split(/a*/)</code>
+ evaluates to the array<code>["","b"]</code>.)</p>
+
+ <p>If the <b>this</b> object is (or converts to) the empty String, the result depends on whether <i>separator</i> can
+ match the empty String. If it can, the result array contains no elements. Otherwise, the result array contains one
+ element, which is the empty String.</p>
+
+ <p>If <i>separator</i> is a regular expression that contains capturing parentheses, then each time <i>separator</i> is
+ matched the results (including any <b>undefined</b> results) of the capturing parentheses are spliced into the output
+ array. For example,</p>
+
+ <pre>"A<B>bold</B>and<CODE>coded</CODE>".split(/<(\/)?([^<>]+)>/)</pre>
+
+ <p>evaluates to the array</p>
+
+ <pre>["A", undefined, "B", "bold", "/", "B", "and", undefined,<br> "CODE", "coded", "/", "CODE", ""]</pre>
+
+ <p>If <i>separator</i> is <b>undefined</b>, then the result array contains just one String, which is the <b>this</b>
+ value (converted to a String). If <i>limit</i> is not <b>undefined</b>, then the output array is truncated so that it
+ contains no more than <i>limit</i> elements.</p>
+ </div>
+ </div>
+
+ <section id="sec-splitmatch">
+ <h1><span class="secnum" id="sec-21.1.3.17.1"><a href="#sec-splitmatch"
+ title="link to this section">21.1.3.17.1</a></span> Runtime Semantics: SplitMatch Abstract Operation</h1>
+
+ <p>The abstract operation SplitMatch takes three parameters, a String <var>S</var>, an integer <var>q</var>, and a
+ String <var>R</var>, and performs the following in order to return either <b>false</b> or the end index of a match:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>R</i>) must be String. Let <i>r</i> be the number of
+ code units in <i>R</i>.</li>
+ <li>Let <i>s</i> be the number of code units in <i>S</i>.</li>
+ <li>If <i>q</i>+<i>r</i> > <i>s</i> then return <b>false</b>.</li>
+ <li>If there exists an integer <i>i</i> between 0 (inclusive) and <i>r</i> (exclusive) such that the code unit at
+ position <i>q</i>+<i>i</i> of <i>S</i> is different from the code unit at position <i>i</i> of <i>R</i>, then
+ return <b>false</b>.</li>
+ <li>Return <i>q</i>+<i>r</i>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>split</code> method is <b>2</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE </span> The <code>split</code> function is intentionally generic; it does not require that
+ its <b>this</b> value be a String object. Therefore, it can be transferred to other kinds of objects for use as a
+ method.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-string.prototype.startswith">
+ <h1><span class="secnum" id="sec-21.1.3.18"><a href="#sec-string.prototype.startswith"
+ title="link to this section">21.1.3.18</a></span> String.prototype.startsWith ( searchString [, position ] )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be <a href="#sec-checkobjectcoercible">CheckObjectCoercible</a>(<b>this</b> value).</li>
+ <li>Let <i>S</i> be <a href="#sec-tostring">ToString</a>(<i>O</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>S</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>searchString</i>) is Object, then
+ <ol class="block">
+ <li>Let <i>isRegExp</i> be <a href="#sec-hasproperty">HasProperty</a>(<i>searchString</i>, @@isRegExp).</li>
+ <li>If <i>isRegExp</i> is <b>true</b>, then throw a <b>TypeError</b> exception.</li>
+ </ol>
+ </li>
+ <li>Let <i>searchStr</i> be <a href="#sec-tostring">ToString</a>(<i>searchString</i>).</li>
+ <li>Let <i>pos</i> be <a href="#sec-tointeger">ToInteger</a>(<i>position</i>). (If <i>position</i> is <b>undefined</b>,
+ this step produces the value <b>0</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>pos</i>).</li>
+ <li>Let <i>len</i> be the number of elements in <i>S</i>.</li>
+ <li>Let <i>start</i> be min(max(<i>pos</i>, 0), <i>len</i>).</li>
+ <li>Let <i>searchLength</i> be the number of elements in <i>searchStr</i>.</li>
+ <li>If <i>searchLength+start</i> is greater than <i>len</i>, return <b>false</b><i>.</i></li>
+ <li>If the <i>searchLength</i> sequence of elements of <i>S</i> starting at <i>start</i> is the same as the full element
+ sequence of <i>searchStr</i>, return <b>true</b>.</li>
+ <li>Otherwise, return <b>false</b>.</li>
+ </ol>
+
+ <p>The <b>length</b> property of the <b>startsWith</b> method is <b>1</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> This method returns <b>true</b> if the sequence of elements of <i>searchString</i>
+ converted to a String is the same as the corresponding elements of this object (converted to a String) starting at
+ <i>position</i>. Otherwise returns <b>false</b>.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 2</span> Throwing an exception if the first argument is a RegExp is specified in order to allow
+ future editions to define extends that allow such argument values.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 3</span> The <b>startsWith</b> function is intentionally generic; it does not require that its
+ <b>this</b> value be a String object. Therefore, it can be transferred to other kinds of objects for use as a
+ method.</p>
+ </div>
+ </section>
+
+ <section id="sec-string.prototype.substring">
+ <h1><span class="secnum" id="sec-21.1.3.19"><a href="#sec-string.prototype.substring"
+ title="link to this section">21.1.3.19</a></span> String.prototype.substring ( start, end )</h1>
+
+ <p>The <b>substring</b> method takes two arguments, <var>start</var> and <var>end</var>, and returns a substring of the
+ result of converting this object to a String, starting from element position <var>start</var> and running to, but not
+ including, element position <var>end</var> of the String (or through the end of the String is <var>end</var> is
+ <b>undefined</b>). The result is a String value, not a String object.</p>
+
+ <p>If either argument is <b>NaN</b> or negative, it is replaced with zero; if either argument is larger than the length of
+ the String, it is replaced with the length of the String.</p>
+
+ <p>If <var>start</var> is larger than <var>end</var>, they are swapped.</p>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be <a href="#sec-checkobjectcoercible">CheckObjectCoercible</a>(<b>this</b> value).</li>
+ <li>Let <i>S</i> be <a href="#sec-tostring">ToString</a>(<i>O</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>S</i>).</li>
+ <li>Let <i>len</i> be the number of elements in <i>S</i>.</li>
+ <li>Let <i>intStart</i> be <a href="#sec-tointeger">ToInteger</a>(<i>start</i>).</li>
+ <li>If <i>end</i> is <b>undefined</b>, let <i>intEnd</i> be <i>len</i>; else let <i>intEnd</i> be <a
+ href="#sec-tointeger">ToInteger</a>(<i>end</i>).</li>
+ <li>Let <i>finalStart</i> be min(max(<i>intStart</i>, 0), <i>len</i>).</li>
+ <li>Let <i>finalEnd</i> be min(max(<i>intEnd</i>, 0), <i>len</i>).</li>
+ <li>Let <i>from</i> be min(<i>finalStart</i>, <i>finalEnd</i>).</li>
+ <li>Let <i>to</i> be max(<i>finalStart</i>, <i>finalEnd</i>).</li>
+ <li>Return a String whose length is <i>to</i> - <i>from</i>, containing code units from <i>S</i>, namely the code units
+ with indices <i>from</i> through <i>to</i> −1, in ascending order.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>substring</code> method is <b>2</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>substring</code> function is intentionally generic; it does not require that
+ its <b>this</b> value be a String object. Therefore, it can be transferred to other kinds of objects for use as a
+ method.</p>
+ </div>
+ </section>
+
+ <section id="sec-string.prototype.tolocalelowercase">
+ <h1><span class="secnum" id="sec-21.1.3.20"><a href="#sec-string.prototype.tolocalelowercase"
+ title="link to this section">21.1.3.20</a></span> String.prototype.toLocaleLowerCase ( )</h1>
+
+ <p>This function interprets a string value as a sequence of code points, as described in <a
+ href="#sec-ecmascript-language-types-string-type">6.1.4</a>.</p>
+
+ <p>This function works exactly the same as <code>toLowerCase</code> except that its result is intended to yield the
+ correct result for the host environment’s current locale, rather than a locale-independent result. There will only
+ be a difference in the few cases (such as Turkish) where the rules for that language conflict with the regular Unicode
+ case mappings.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> The first parameter to this function is likely to be used in a future version of this
+ standard; it is recommended that implementations do not use this parameter position for anything else.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 2</span> The <code>toLocaleLowerCase</code> function is intentionally generic; it does not
+ require that its <b>this</b> value be a String object. Therefore, it can be transferred to other kinds of objects for
+ use as a method.</p>
+ </div>
+ </section>
+
+ <section id="sec-string.prototype.tolocaleuppercase">
+ <h1><span class="secnum" id="sec-21.1.3.21"><a href="#sec-string.prototype.tolocaleuppercase"
+ title="link to this section">21.1.3.21</a></span> String.prototype.toLocaleUpperCase ( )</h1>
+
+ <p>This function interprets a string value as a sequence of code points, as described in <a
+ href="#sec-ecmascript-language-types-string-type">6.1.4</a>.</p>
+
+ <p>This function works exactly the same as <code>toUpperCase</code> except that its result is intended to yield the
+ correct result for the host environment’s current locale, rather than a locale-independent result. There will only
+ be a difference in the few cases (such as Turkish) where the rules for that language conflict with the regular Unicode
+ case mappings.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> The first parameter to this function is likely to be used in a future version of this
+ standard; it is recommended that implementations do not use this parameter position for anything else.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 2</span> The <code>toLocaleUpperCase</code> function is intentionally generic; it does not
+ require that its <b>this</b> value be a String object. Therefore, it can be transferred to other kinds of objects for
+ use as a method.</p>
+ </div>
+ </section>
+
+ <section id="sec-string.prototype.tolowercase">
+ <h1><span class="secnum" id="sec-21.1.3.22"><a href="#sec-string.prototype.tolowercase"
+ title="link to this section">21.1.3.22</a></span> String.prototype.toLowerCase ( )</h1>
+
+ <p>This function interprets a string value as a sequence of code points, as described in <a
+ href="#sec-ecmascript-language-types-string-type">6.1.4</a>. The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be <a href="#sec-checkobjectcoercible">CheckObjectCoercible</a>(<b>this</b> value).</li>
+ <li>Let <i>S</i> be <a href="#sec-tostring">ToString</a>(<i>O</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>S</i>).</li>
+ <li>Let <i>cpList</i> be a <a href="#sec-list-and-record-specification-type">List</a> containing in order the code
+ points as defined in <a href="#sec-ecmascript-language-types-string-type">6.1.4</a> of <i>S</i>, starting at the
+ first element of <i>S</i>.</li>
+ <li>For each code point <i>c</i> in <i>cpList</i>, if the Unicode Character Database provides a language insensitive
+ lower case equivalent of <i>c</i> then replace <i>c</i> in <i>cpList</i> with that equivalent code point(s).</li>
+ <li>Let <i>cuList</i> be a new <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>For each code point <i>c</i> in <i>cpList</i>, in order, append to <i>cuList</i> the elements of the <a
+ href="#sec-static-semantics-utf-16encoding">UTF-16Encoding</a> (<a
+ href="#sec-static-semantics-utf-16encoding">10.1.1</a>) of <i>c</i>.</li>
+ <li>Let <i>L</i> be a String whose elements are, in order, the elements of <i>cuList</i> .</li>
+ <li>Return <i>L</i>.</li>
+ </ol>
+
+ <p class="Note">The result must be derived according to the locale-insensitive case mappings in the Unicode Character
+ Database (this explicitly includes not only the UnicodeData.txt file, but also all locale-insensitive mappings in the
+ SpecialCasings.txt file that accompanies it).</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> The case mapping of some code points may produce multiple code points . In this case
+ the result String may not be the same length as the source String. Because both <code>toUpperCase</code> and
+ <code>toLowerCase</code> have context-sensitive behaviour, the functions are not symmetrical. In other words,
+ <code>s.toUpperCase().toLowerCase()</code> is not necessarily equal to <code>s.toLowerCase()</code>.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 2</span> The <code>toLowerCase</code> function is intentionally generic; it does not require
+ that its <b>this</b> value be a String object. Therefore, it can be transferred to other kinds of objects for use as a
+ method.</p>
+ </div>
+ </section>
+
+ <section id="sec-string.prototype.tostring">
+ <h1><span class="secnum" id="sec-21.1.3.23"><a href="#sec-string.prototype.tostring"
+ title="link to this section">21.1.3.23</a></span> String.prototype.toString ( )</h1>
+
+ <p>When the <code>toString</code> method is called, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>s</i> be thisStringValue(<b>this</b> value).</li>
+ <li>Return <i>s</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> For a String object, the <code>toString</code> method happens to return the same thing
+ as the <code>valueOf</code> method.</p>
+ </div>
+ </section>
+
+ <section id="sec-string.prototype.touppercase">
+ <h1><span class="secnum" id="sec-21.1.3.24"><a href="#sec-string.prototype.touppercase"
+ title="link to this section">21.1.3.24</a></span> String.prototype.toUpperCase ( )</h1>
+
+ <p>This function interprets a string value as a sequence of code points, as described in <a
+ href="#sec-ecmascript-language-types-string-type">6.1.4</a>.</p>
+
+ <p>This function behaves in exactly the same way as <code><a
+ href="#sec-string.prototype.tolowercase">String.prototype.toLowerCase</a></code>, except that code points are mapped to
+ their <var>uppercase</var> equivalents as specified in the Unicode Character Database.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>toUpperCase</code> function is intentionally generic; it does not require that
+ its <b>this</b> value be a String object. Therefore, it can be transferred to other kinds of objects for use as a
+ method.</p>
+ </div>
+ </section>
+
+ <section id="sec-string.prototype.trim">
+ <h1><span class="secnum" id="sec-21.1.3.25"><a href="#sec-string.prototype.trim"
+ title="link to this section">21.1.3.25</a></span> String.prototype.trim ( )</h1>
+
+ <p>This function interprets a string value as a sequence of code points, as described in <a
+ href="#sec-ecmascript-language-types-string-type">6.1.4</a>.</p>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be <a href="#sec-checkobjectcoercible">CheckObjectCoercible</a>(<b>this</b> value).</li>
+ <li>Let <i>S</i> be <a href="#sec-tostring">ToString</a>(<i>O</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>S</i>).</li>
+ <li>Let <i>T</i> be a String value that is a copy of <i>S</i> with both leading and trailing white space removed. The
+ definition of white space is the union of <i>WhiteSpace</i> and <i>LineTerminator</i>. When determining whether a
+ Unicode code point is in Unicode general category “Zs”, code unit sequences are interpreted as UTF-16
+ encoded code point sequences as specified in <a href="#sec-ecmascript-language-types-string-type">6.1.4</a>.</li>
+ <li>Return <i>T</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>trim</code> function is intentionally generic; it does not require that its
+ <b>this</b> value be a String object. Therefore, it can be transferred to other kinds of objects for use as a
+ method.</p>
+ </div>
+ </section>
+
+ <section id="sec-string.prototype.valueof">
+ <h1><span class="secnum" id="sec-21.1.3.26"><a href="#sec-string.prototype.valueof"
+ title="link to this section">21.1.3.26</a></span> String.prototype.valueOf ( )</h1>
+
+ <p>When the <code>valueOf</code> method is called, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>s</i> be thisStringValue(<b>this</b> value).</li>
+ <li>Return <i>s</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-string.prototype-@@iterator">
+ <h1><span class="secnum" id="sec-21.1.3.27"><a href="#sec-string.prototype-@@iterator"
+ title="link to this section">21.1.3.27</a></span> String.prototype [ @@iterator ]( )</h1>
+
+ <p>When the @@iterator method is called it returns an Iterator object (<a href="#sec-iterator-interface">25.1.2</a>) that
+ iterates over the code points of a String value, returning each code point as a String value. The following steps are
+ taken:</p>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be <a href="#sec-checkobjectcoercible">CheckObjectCoercible</a>(<b>this</b> value).</li>
+ <li>Let <i>S</i> be <a href="#sec-tostring">ToString</a>(<i>O</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>S</i>).</li>
+ <li>Return the result of calling the <a href="#sec-createstringiterator">CreateStringIterator</a> abstract operation
+ with argument <i>S</i>.</li>
+ </ol>
+
+ <p>The value of the <code>name</code> property of this function is <code>"[Symbol.iterator]"</code>.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-string-instances">
+ <div class="front">
+ <h1><span class="secnum" id="sec-21.1.4"><a href="#sec-properties-of-string-instances"
+ title="link to this section">21.1.4</a></span> Properties of String Instances</h1>
+
+ <p>String instances are String exotic objects and have the internal methods specified for such objects. String instances
+ inherit properties from the String prototype object. String instances also have a [[StringData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</p>
+
+ <p>String instances have a <code>length</code> property, and a set of enumerable properties with integer indexed
+ names.</p>
+ </div>
+
+ <section id="sec-properties-of-string-instances-length">
+ <h1><span class="secnum" id="sec-21.1.4.1"><a href="#sec-properties-of-string-instances-length"
+ title="link to this section">21.1.4.1</a></span> length</h1>
+
+ <p>The number of elements in the String value represented by this String object.</p>
+
+ <p>Once a String object is initialized, this property is unchanging. It has the attributes { [[Writable]]: <b>false</b>,
+ [[Enumerable]]: <b>false</b>, [[Configurable]]: <b>false</b> }.</p>
+ </section>
+ </section>
+
+ <section id="sec-string-iterator-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-21.1.5"><a href="#sec-string-iterator-objects"
+ title="link to this section">21.1.5</a></span> String Iterator Objects</h1>
+
+ <p>An String Iterator is an object, that represents a specific iteration over some specific String instance object. There
+ is not a named constructor for String Iterator objects. Instead, String iterator objects are created by calling certain
+ methods of String instance objects.</p>
+ </div>
+
+ <section id="sec-createstringiterator">
+ <h1><span class="secnum" id="sec-21.1.5.1"><a href="#sec-createstringiterator"
+ title="link to this section">21.1.5.1</a></span> CreateStringIterator Abstract Operation</h1>
+
+ <p>Several methods of String objects return Iterator objects. The abstract operation CreateStringIterator with argument
+ <var>string</var> is used to create such iterator objects. It performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>s</i> be the result of calling <a href="#sec-tostring">ToString</a>(<i>string</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>s</i>).</li>
+ <li>Let <i>iterator</i> be the result of <a href="#sec-objectcreate">ObjectCreate</a>(%StringIteratorPrototype%,
+ ([[IteratedStringt]], [[StringIteratorNextIndex]] )).</li>
+ <li>Set <i>iterator’s</i> [[IteratedString]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> to <i>s</i>.</li>
+ <li>Set <i>iterator’s</i> [[StringIteratorNextIndex]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to 0.</li>
+ <li>Return <i>iterator</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-%stringiteratorprototype%-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-21.1.5.2"><a href="#sec-%stringiteratorprototype%-object"
+ title="link to this section">21.1.5.2</a></span> The %StringIteratorPrototype% Object</h1>
+
+ <p>All String Iterator Objects inherit properties from the %StringIteratorPrototype% intrinsic object. The
+ %StringIteratorPrototype% object is an ordinary object and its [[Prototype]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is the %ObjectPrototype% intrinsic object. In
+ addition, %StringIteratorPrototype% has the following properties:</p>
+ </div>
+
+ <section id="sec-%stringiteratorprototype%.next">
+ <h1><span class="secnum" id="sec-21.1.5.2.1"><a href="#sec-%stringiteratorprototype%.next"
+ title="link to this section">21.1.5.2.1</a></span> %StringIteratorPrototype%.next ( )</h1>
+ <ol class="proc">
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object, throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>O</i> does not have all of the internal slots of an String Iterator Instance (<a
+ href="#sec-properties-of-string-iterator-instances">21.1.5.3</a>), throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>s</i> be the value of the [[IteratedString]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>If <i>s</i> is <b>undefined</b>, then return <a
+ href="#sec-createiterresultobject">CreateIterResultObject</a>(<b>undefined</b>, <b>true</b>).</li>
+ <li>Let <i>position</i> be the value of the [[StringIteratorNextIndex]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>Let <i>len</i> be the number of elements in <i>s</i>.</li>
+ <li>If <i>position</i> ≥ <i>len</i>, then
+ <ol class="block">
+ <li>Set the value of the [[IteratedString]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> of <i>O</i> to <b>undefined</b>.</li>
+ <li>Return <a href="#sec-createiterresultobject">CreateIterResultObject</a>(<b>undefined</b>, <b>true</b>).</li>
+ </ol>
+ </li>
+ <li>Let <i>first</i> be the code unit value of the element at index <i>position</i> in <i>s</i>.</li>
+ <li>If <i>first</i> < 0xD800 or <i>first</i> > 0xDBFF or <i>position</i>+1 = <i>len</i>, then let
+ <i>resultString</i> be the string consisting of the single code unit <i>first</i>.</li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>second</i> be the code unit value of the element at index <i>position</i>+1 in the String
+ <i>S</i>.</li>
+ <li>If <i>second</i> < 0xDC00 or <i>second</i> > 0xDFFF, then let <i>resultString</i> be the string
+ consisting of the single code unit <i>first</i>.</li>
+ <li>Else, let <i>resultString</i> be the string consisting of the code unit <i>first</i> followed by the code unit
+ <i>second</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>resultSize</i> be the number of code units in <i>resultString</i>.</li>
+ <li>Set the value of the [[StringIteratorNextIndex]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i> to <i>position</i>+
+ <i>resultSize</i>.</li>
+ <li>Return <a href="#sec-createiterresultobject">CreateIterResultObject</a>(<i>resultString</i>, <b>false</b>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-%stringiteratorprototype%-@@iterator">
+ <h1><span class="secnum" id="sec-21.1.5.2.2"><a href="#sec-%stringiteratorprototype%-@@iterator"
+ title="link to this section">21.1.5.2.2</a></span> %StringIteratorPrototype% [ @@iterator ] ( )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Return the <b>this</b> value.</li>
+ </ol>
+
+ <p>The value of the <code>name</code> property of this function is <code>"[Symbol.iterator]"</code>.</p>
+ </section>
+
+ <section id="sec-%stringiteratorprototype%-@@tostringtag">
+ <h1><span class="secnum" id="sec-21.1.5.2.3"><a href="#sec-%stringiteratorprototype%-@@tostringtag"
+ title="link to this section">21.1.5.2.3</a></span> %StringIteratorPrototype% [ @@toStringTag ]</h1>
+
+ <p>The initial value of the @@toStringTag property is the string value <b>"<code>String Iterator</code>"</b>.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-string-iterator-instances">
+ <h1><span class="secnum" id="sec-21.1.5.3"><a href="#sec-properties-of-string-iterator-instances"
+ title="link to this section">21.1.5.3</a></span> Properties of String Iterator Instances</h1>
+
+ <p>String Iterator instances are ordinary objects that inherit properties from the %StringIteratorPrototype% intrinsic
+ object. String Iterator instances are initially created with the internal slots listed in <a href="#table-43">Table
+ 43</a>.</p>
+
+ <figure>
+ <figcaption><span id="table-41">Table 41</span> — Internal Slots of String Iterator Instances</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-top: 2px solid #000000">Internal Slot</th>
+ <th style="border-bottom: 1px solid #000000; border-left: 0px solid black; border-right: 1px solid #000000; border-top: 2px solid #000000">Description</th>
+ </tr>
+ <tr>
+ <td>[[IteratedString]]</td>
+ <td>The String value whose elements are being iterated.</td>
+ </tr>
+ <tr>
+ <td>[[StringIteratorNextIndex]]</td>
+ <td>The integer index of the next string index to be examined by this iteration.</td>
+ </tr>
+ </table>
+ </figure>
+ </section>
+ </section>
+ </section>
+
+ <section id="sec-regexp-regular-expression-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-21.2"><a href="#sec-regexp-regular-expression-objects"
+ title="link to this section">21.2</a></span> RegExp (Regular Expression) Objects</h1>
+
+ <p>A RegExp object contains a regular expression and the associated flags.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The form and functionality of regular expressions is modelled after the regular expression
+ facility in the Perl 5 programming language.</p>
+ </div>
+ </div>
+
+ <section id="sec-patterns">
+ <h1><span class="secnum" id="sec-21.2.1"><a href="#sec-patterns" title="link to this section">21.2.1</a></span>
+ Patterns</h1>
+
+ <p>The <code>RegExp</code> constructor applies the following grammar to the input pattern String. An error occurs if the
+ grammar cannot interpret the String as an expansion of <span class="nt">Pattern</span>.</p>
+
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">Pattern</span><sub>[U]</sub> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">Disjunction</span><sub>[?U]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">Disjunction</span><sub>[U]</sub> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">Alternative</span><sub>[?U]</sub></div>
+ <div class="rhs"><span class="nt">Alternative</span><sub>[?U]</sub> <code class="t">|</code> <span class="nt">Disjunction</span><sub>[?U]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">Alternative</span><sub>[U]</sub> <span class="geq">::</span></div>
+ <div class="rhs"><span class="grhsannot">[empty]</span></div>
+ <div class="rhs"><span class="nt">Alternative</span><sub>[?U]</sub> <span class="nt">Term</span><sub>[?U]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">Term</span><sub>[U]</sub> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">Assertion</span><sub>[?U]</sub></div>
+ <div class="rhs"><span class="nt">Atom</span><sub>[?U]</sub></div>
+ <div class="rhs"><span class="nt">Atom</span><sub>[?U]</sub> <span class="nt">Quantifier</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">Assertion</span><sub>[U]</sub> <span class="geq">::</span></div>
+ <div class="rhs"><code class="t">^</code></div>
+ <div class="rhs"><code class="t">$</code></div>
+ <div class="rhs"><code class="t">\</code> <code class="t">b</code></div>
+ <div class="rhs"><code class="t">\</code> <code class="t">B</code></div>
+ <div class="rhs"><code class="t">(</code> <code class="t">?</code> <code class="t">=</code> <span class="nt">Disjunction</span><sub>[?U]</sub> <code class="t">)</code></div>
+ <div class="rhs"><code class="t">(</code> <code class="t">?</code> <code class="t">!</code> <span class="nt">Disjunction</span><sub>[?U]</sub> <code class="t">)</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">Quantifier</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">QuantifierPrefix</span></div>
+ <div class="rhs"><span class="nt">QuantifierPrefix</span> <code class="t">?</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">QuantifierPrefix</span> <span class="geq">::</span></div>
+ <div class="rhs"><code class="t">*</code></div>
+ <div class="rhs"><code class="t">+</code></div>
+ <div class="rhs"><code class="t">?</code></div>
+ <div class="rhs"><code class="t">{</code> <span class="nt">DecimalDigits</span> <code class="t">}</code></div>
+ <div class="rhs"><code class="t">{</code> <span class="nt">DecimalDigits</span> <code class="t">,</code> <code class="t">}</code></div>
+ <div class="rhs"><code class="t">{</code> <span class="nt">DecimalDigits</span> <code class="t">,</code> <span class="nt">DecimalDigits</span> <code class="t">}</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">Atom</span><sub>[U]</sub> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">PatternCharacter</span></div>
+ <div class="rhs"><code class="t">.</code></div>
+ <div class="rhs"><code class="t">\</code> <span class="nt">AtomEscape</span><sub>[?U]</sub></div>
+ <div class="rhs"><span class="nt">CharacterClass</span><sub>[?U]</sub></div>
+ <div class="rhs"><code class="t">(</code> <span class="nt">Disjunction</span><sub>[?U]</sub> <code class="t">)</code></div>
+ <div class="rhs"><code class="t">(</code> <code class="t">?</code> <code class="t">:</code> <span class="nt">Disjunction</span><sub>[?U]</sub> <code class="t">)</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">SyntaxCharacter</span> <span class="geq">::</span> <span class="grhsmod">one of</span></div>
+ <div class="rhs"><code class="t">^</code> <code class="t">$</code> <code class="t">\</code> <code class="t">.</code> <code class="t">*</code> <code class="t">+</code> <code class="t">?</code> <code class="t">(</code> <code class="t">)</code> <code class="t">[</code> <code class="t">]</code> <code class="t">{</code> <code class="t">}</code> <code class="t">|</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">PatternCharacter</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">SourceCharacter</span> <span class="grhsmod">but not</span> <span class="nt">SyntaxCharacter</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">AtomEscape</span><sub>[U]</sub> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">DecimalEscape</span></div>
+ <div class="rhs"><span class="nt">CharacterEscape</span><sub>[?U]</sub></div>
+ <div class="rhs"><span class="nt">CharacterClassEscape</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">CharacterEscape</span><sub>[U]</sub> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">ControlEscape</span></div>
+ <div class="rhs"><code class="t">c</code> <span class="nt">ControlLetter</span></div>
+ <div class="rhs"><span class="nt">HexEscapeSequence</span></div>
+ <div class="rhs"><span class="nt">RegExpUnicodeEscapeSequence</span><sub>[?U]</sub></div>
+ <div class="rhs"><span class="nt">IdentityEscape</span><sub>[?U]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ControlEscape</span> <span class="geq">::</span> <span class="grhsmod">one of</span></div>
+ <div class="rhs"><code class="t">f</code> <code class="t">n</code> <code class="t">r</code> <code class="t">t</code> <code class="t">v</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ControlLetter</span> <span class="geq">::</span> <span class="grhsmod">one of</span></div>
+ <div class="rhs"><code class="t">a</code> <code class="t">b</code> <code class="t">c</code> <code class="t">d</code> <code class="t">e</code> <code class="t">f</code> <code class="t">g</code> <code class="t">h</code> <code class="t">i</code> <code class="t">j</code> <code class="t">k</code> <code class="t">l</code> <code class="t">m</code> <code class="t">n</code> <code class="t">o</code> <code class="t">p</code> <code class="t">q</code> <code class="t">r</code> <code class="t">s</code> <code class="t">t</code> <code class="t">u</code> <code class="t">v</code> <code class="t">w</code> <code class="t">x</code> <code class="t">y</code> <code class="t">z</code></div>
+ <div class="rhs"><code class="t">A</code> <code class="t">B</code> <code class="t">C</code> <code class="t">D</code> <code class="t">E</code> <code class="t">F</code> <code class="t">G</code> <code class="t">H</code> <code class="t">I</code> <code class="t">J</code> <code class="t">K</code> <code class="t">L</code> <code class="t">M</code> <code class="t">N</code> <code class="t">O</code> <code class="t">P</code> <code class="t">Q</code> <code class="t">R</code> <code class="t">S</code> <code class="t">T</code> <code class="t">U</code> <code class="t">V</code> <code class="t">W</code> <code class="t">X</code> <code class="t">Y</code> <code class="t">Z</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">RegExpUnicodeEscapeSequence</span><sub>[U]</sub> <span class="geq">::</span></div>
+ <div class="rhs"><span class="grhsannot">[+U]</span> <code class="t">u</code> <span class="nt">LeadSurrogate</span> <code class="t">\u</code> <span class="nt">TrailSurrogate</span></div>
+ <div class="rhs"><code class="t">u</code> <span class="nt">Hex4Digits</span></div>
+ <div class="rhs"><span class="grhsannot">[+U]</span> <code class="t">u{</code> <span class="nt">HexDigits</span> <code class="t">}</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">LeadSurrogate</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">Hex4Digits</span> <span class="grhsannot">[match only if the CV of <span class="nt">Hex4Digits</span> is in the inclusive range 0xD800 to 0xDBFF]</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">TrailSurrogate</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">Hex4Digits</span> <span class="grhsannot">[match only if the CV of <span class="nt">Hex4Digits</span> is in the inclusive range 0xDC00 to 0xDFFF]</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">IdentityEscape</span><sub>[U]</sub> <span class="geq">::</span></div>
+ <div class="rhs"><span class="grhsannot">[+U]</span> <span class="nt">SyntaxCharacter</span></div>
+ <div class="rhs"><span class="grhsannot">[~U]</span> <span class="nt">SourceCharacter</span> <span class="grhsmod">but not</span> <span class="nt">IdentifierPart</span></div>
+ <div class="rhs"><span class="grhsannot">[~U]</span> <ZWJ></div>
+ <div class="rhs"><span class="grhsannot">[~U]</span> <ZWNJ></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">DecimalEscape</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">DecimalIntegerLiteral</span> <span class="grhsannot">[lookahead ∉ <span class="nt">DecimalDigit</span>]</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">CharacterClassEscape</span> <span class="geq">::</span> <span class="grhsmod">one of</span></div>
+ <div class="rhs"><code class="t">d</code> <code class="t">D</code> <code class="t">s</code> <code class="t">S</code> <code class="t">w</code> <code class="t">W</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">CharacterClass</span><sub>[U]</sub> <span class="geq">::</span></div>
+ <div class="rhs"><code class="t">[</code> <span class="grhsannot">[lookahead ∉ {<code class="t">^</code>}]</span> <span class="nt">ClassRanges</span><sub>[?U]</sub> <code class="t">]</code></div>
+ <div class="rhs"><code class="t">[</code> <code class="t">^</code> <span class="nt">ClassRanges</span><sub>[?U]</sub> <code class="t">]</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ClassRanges</span><sub>[U]</sub> <span class="geq">::</span></div>
+ <div class="rhs"><span class="grhsannot">[empty]</span></div>
+ <div class="rhs"><span class="nt">NonemptyClassRanges</span><sub>[?U]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">NonemptyClassRanges</span><sub>[U]</sub> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">ClassAtom</span><sub>[?U]</sub></div>
+ <div class="rhs"><span class="nt">ClassAtom</span><sub>[?U]</sub> <span class="nt">NonemptyClassRangesNoDash</span><sub>[?U]</sub></div>
+ <div class="rhs"><span class="nt">ClassAtom</span><sub>[?U]</sub> <code class="t">-</code> <span class="nt">ClassAtom</span><sub>[?U]</sub> <span class="nt">ClassRanges</span><sub>[?U]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">NonemptyClassRangesNoDash</span><sub>[U]</sub> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">ClassAtom</span><sub>[?U]</sub></div>
+ <div class="rhs"><span class="nt">ClassAtomNoDash</span><sub>[?U]</sub> <span class="nt">NonemptyClassRangesNoDash</span><sub>[?U]</sub></div>
+ <div class="rhs"><span class="nt">ClassAtomNoDash</span><sub>[?U]</sub> <code class="t">-</code> <span class="nt">ClassAtom</span><sub>[?U]</sub> <span class="nt">ClassRanges</span><sub>[?U]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ClassAtom</span><sub>[U]</sub> <span class="geq">::</span></div>
+ <div class="rhs"><code class="t">-</code></div>
+ <div class="rhs"><span class="nt">ClassAtomNoDash</span><sub>[?U]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ClassAtomNoDash</span><sub>[U]</sub> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">SourceCharacter</span> <span class="grhsmod">but not one of</span> <code class="t">\</code> <span class="grhsmod">or</span> <code class="t">]</code> <span class="grhsmod">or</span> <code class="t">-</code></div>
+ <div class="rhs"><code class="t">\</code> <span class="nt">ClassEscape</span><sub>[?U]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ClassEscape</span><sub>[U]</sub> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">DecimalEscape</span></div>
+ <div class="rhs"><code class="t">b</code></div>
+ <div class="rhs"><span class="nt">CharacterEscape</span><sub>[?U]</sub></div>
+ <div class="rhs"><span class="nt">CharacterClassEscape</span></div>
+ </div>
+ </section>
+
+ <section id="sec-pattern-semantics">
+ <div class="front">
+ <h1><span class="secnum" id="sec-21.2.2"><a href="#sec-pattern-semantics" title="link to this section">21.2.2</a></span>
+ Pattern Semantics</h1>
+
+ <p>A regular expression pattern is converted into an internal procedure using the process described below. An
+ implementation is encouraged to use more efficient algorithms than the ones listed below, as long as the results are the
+ same. The internal procedure is used as the value of a RegExp object’s [[RegExpMatcher]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</p>
+
+ <p>A <span class="nt">Pattern</span> is either a BMP pattern or a Unicode pattern depending upon whether or not its
+ associated flags contain an <code>"u"</code>. A BMP pattern matches against a String interpreted as consisting of a
+ sequence of Unicode code units. A Unicode pattern matches against a String interpreted as consisting of Unicode code
+ points encoded using UTF-16. In the context of describing the behaviour of a BMP pattern “character” means a
+ Unicode code unit. In the context of describing the behaviour of a Unicode pattern “character” means a UTF-16
+ code point. In either context, “character value” means the numeric value of the code unit or code point.</p>
+
+ <p>The semantics of <span class="nt">Pattern</span> is defined as if a <span class="nt">Pattern</span> was a <a
+ href="#sec-list-and-record-specification-type">List</a> of <span class="nt">SourceCharacter</span> values where each <span
+ class="nt">SourceCharacter</span> corresponds to a Unicode code point. If a BMP pattern contains a non-BMP <span
+ class="nt">SourceCharacter</span> the entire pattern is encoded using UTF-16 and the individual code units of that
+ encoding are used as the elements of the <a href="#sec-list-and-record-specification-type">List</a>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> For example, consider a pattern expressed in source code as the single non-BMP character
+ <span style="font-family: sans-serif">U+1D11E (MUSICAL SYMBOL G CLEF). Interpreted as a Unicode pattern, it would be a
+ single element (character) <a href="#sec-list-and-record-specification-type">List</a> consisting of the single code
+ point 0x1D11E. However, interpreted as a BMP pattern, it is first UTF-16 encoded to produce a two element <a
+ href="#sec-list-and-record-specification-type">List</a> consisting of the code units 0xD834 and 0xDD1E.</span></p>
+
+ <p>Patterns are passed to the RegExp constructor as ECMAScript string values in which non-BMP characters are UTF-16
+ encoded. For example, the single character MUSICAL SYMBOL G CLEF pattern, expressed as a string value, is a String of
+ length 2 whose elements were the code units 0xD834 and 0xDD1E. So no further translation of the string would be
+ necessary to process it as a BMP pattern consisting of two pattern characters. However, to process it as a Unicode
+ pattern the string value must treated as if it was UTF-16 decoded into a <a
+ href="#sec-list-and-record-specification-type">List</a> consisting of a single pattern character, the code point
+ U+1D11E.</p>
+
+ <p>An implementation may not actually perform such translations to or from UTF-16, but the semantics of this
+ specification requires that the result of pattern matching be as if such translations were performed.</p>
+ </div>
+ </div>
+
+ <section id="sec-notation">
+ <h1><span class="secnum" id="sec-21.2.2.1"><a href="#sec-notation" title="link to this section">21.2.2.1</a></span>
+ Notation</h1>
+
+ <p>The descriptions below use the following variables:</p>
+
+ <ul>
+ <li>
+ <p><span class="nt">Input</span> is a <a href="#sec-list-and-record-specification-type">List</a> consisting of all of
+ the characters, in order, of the String being matched by the regular expression pattern. Each character is either a
+ code unit or a code point, depending upon the kind of pattern involved. The notation <span style="font-family: Times
+ New Roman"><i>input</i>[<i>n</i>]</span> means the <span style="font-family: Times New
+ Roman"><i>n<sup>th</sup></i></span> character of <var>input</var>, where <var>n</var> can range between 0 (inclusive)
+ and <span class="nt">InputLength</span> (exclusive).</p>
+ </li>
+
+ <li>
+ <p><span class="nt">InputLength</span> is the number of characters in <span class="nt">Input</span>.</p>
+ </li>
+
+ <li>
+ <p><span class="nt">NcapturingParens</span> is the total number of left capturing parentheses (i.e. the total number
+ of times the <span class="prod"><span class="nt">Atom</span> <span class="geq">::</span> <code class="t">(</code>
+ <span class="nt">Disjunction</span> <code class="t">)</code></span> production is expanded) in the pattern. A left
+ capturing parenthesis is any <code>(</code> pattern character that is matched by the <code>(</code> terminal of the
+ <span class="prod"><span class="nt">Atom</span> <span class="geq">::</span> <code class="t">(</code> <span
+ class="nt">Disjunction</span> <code class="t">)</code></span> production.</p>
+ </li>
+
+ <li>
+ <p><span class="nt">IgnoreCase</span> is <b>true</b> if the RegExp object's [[OriginalFlags]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> contains <code>"i"</code> and otherwise is
+ <b>false</b>.</p>
+ </li>
+
+ <li>
+ <p><span class="nt">Multiline</span> is <b>true</b> if the RegExp object’s [[OriginalFlags]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> contains <code>"m"</code> and otherwise is
+ <b>false</b>.</p>
+ </li>
+
+ <li>
+ <p><span class="nt">Unicode</span> is <b>true</b> if the RegExp object’s [[OriginalFlags]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> contains <code>"u"</code> and otherwise is
+ <b>false</b>.</p>
+ </li>
+ </ul>
+
+ <p>Furthermore, the descriptions below use the following internal data structures:</p>
+
+ <ul>
+ <li>
+ <p>A <span class="nt">CharSet</span> is a mathematical set of characters, either code units or code points depending
+ up the state of the <span class="nt">Unicode</span> flag. “All characters” means either all code unit
+ values or all code point values also depending upon the state if <span class="nt">Unicode</span>.</p>
+ </li>
+
+ <li>
+ <p>A <span class="nt">State</span> is an ordered pair <span style="font-family: Times New Roman">(<i>endIndex</i>,
+ <i>captures</i>)</span> where <var>endIndex</var> is an integer and <var>captures</var> is a <a
+ href="#sec-list-and-record-specification-type">List</a> of <span class="nt">NcapturingParens</span> values. <span
+ class="nt">States</span> are used to represent partial match states in the regular expression matching algorithms. The
+ <var>endIndex</var> is one plus the index of the last input character matched so far by the pattern, while
+ <var>captures</var> holds the results of capturing parentheses. The <span style="font-family: Times New
+ Roman"><i>n<sup>th</sup></i></span> element of <var>captures</var> is either a <a
+ href="#sec-list-and-record-specification-type">List</a> that represents the value obtained by the <span
+ style="font-family: Times New Roman"><i>n<sup>th</sup></i></span> set of capturing parentheses or <b>undefined</b> if
+ the <span style="font-family: Times New Roman"><i>n<sup>th</sup></i></span> set of capturing parentheses hasn’t
+ been reached yet. Due to backtracking, many <span class="nt">States</span> may be in use at any time during the
+ matching process.</p>
+ </li>
+
+ <li>
+ <p>A <span class="nt">MatchResult</span> is either a <span class="nt">State</span> or the special token <b>failure</b>
+ that indicates that the match failed.</p>
+ </li>
+
+ <li>
+ <p>A <span class="nt">Continuation</span> procedure is an internal closure (i.e. an internal procedure with some
+ arguments already bound to values) that takes one <span class="nt">State</span> argument and returns a <span
+ class="nt">MatchResult</span> result. If an internal closure references variables which are bound in the function that
+ creates the closure, the closure uses the values that these variables had at the time the closure was created. The
+ <span class="nt">Continuation</span> attempts to match the remaining portion (specified by the closure's already-bound
+ arguments) of the pattern against <span class="nt">Input</span>, starting at the intermediate state given by its <span
+ class="nt">State</span> argument. If the match succeeds, the <span class="nt">Continuation</span> returns the final
+ <span class="nt">State</span> that it reached; if the match fails, the <span class="nt">Continuation</span> returns
+ <b>failure</b>.</p>
+ </li>
+
+ <li>
+ <p>A <span class="nt">Matcher</span> procedure is an internal closure that takes two arguments — a <span
+ class="nt">State</span> and a <span class="nt">Continuation</span> — and returns a <span
+ class="nt">MatchResult</span> result. A <span class="nt">Matcher</span> attempts to match a middle subpattern
+ (specified by the closure's already-bound arguments) of the pattern against <span class="nt">Input</span>, starting at
+ the intermediate state given by its <span class="nt">State</span> argument. The <span class="nt">Continuation</span>
+ argument should be a closure that matches the rest of the pattern. After matching the subpattern of a pattern to
+ obtain a new <span class="nt">State</span>, the <span class="nt">Matcher</span> then calls <span
+ class="nt">Continuation</span> on that new <span class="nt">State</span> to test if the rest of the pattern can match
+ as well. If it can, the <i>Matcher</i> returns the <span class="nt">State</span> returned by <span
+ class="nt">Continuation</span>; if not, the <span class="nt">Matcher</span> may try different choices at its choice
+ points, repeatedly calling <span class="nt">Continuation</span> until it either succeeds or all possibilities have
+ been exhausted.</p>
+ </li>
+
+ <li>
+ <p>An <span class="nt">AssertionTester</span> procedure is an internal closure that takes a <span
+ class="nt">State</span> argument and returns a Boolean result. The assertion tester tests a specific condition
+ (specified by the closure's already-bound arguments) against the current place in <span class="nt">Input</span> and
+ returns <b>true</b> if the condition matched or <b>false</b> if not.</p>
+ </li>
+
+ <li>
+ <p>An <span class="nt">EscapeValue</span> is either a character or an integer. An <span class="nt">EscapeValue</span>
+ is used to denote the interpretation of a <span class="nt">DecimalEscape</span> escape sequence: a character
+ <var>ch</var> means that the escape sequence is interpreted as the character <var>ch</var>, while an integer
+ <var>n</var> means that the escape sequence is interpreted as a backreference to the <span style="font-family: Times
+ New Roman"><i>n</i><sup>th</sup></span> set of capturing parentheses.</p>
+ </li>
+ </ul>
+ </section>
+
+ <section id="sec-pattern">
+ <h1><span class="secnum" id="sec-21.2.2.2"><a href="#sec-pattern" title="link to this section">21.2.2.2</a></span>
+ Pattern</h1>
+
+ <p>The production <span class="prod"><span class="nt">Pattern</span> <span class="geq">::</span> <span
+ class="nt">Disjunction</span></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Evaluate <i>Disjunction</i> to obtain a Matcher <i>m</i>.</li>
+ <li>Return an internal closure that takes two arguments, a String <i>str</i> and an integer <i>index</i>, and performs
+ the following:
+ <ol class="nested proc">
+ <li>If <i>Unicode</i> is <b>true</b>, then let <i>Input</i> be a <a
+ href="#sec-list-and-record-specification-type">List</a> consisting of the sequence of code points of <i>str</i>
+ interpreted as a UTF-16 encoded Unicode string. Otherwise, let <i>Input</i> be a <a
+ href="#sec-list-and-record-specification-type">List</a> consisting of the sequence of code units that are the
+ elements of <i>str</i>. <i>Input</i> will be used throughout the algorithms in <a
+ href="#sec-pattern-semantics">21.2.2</a>. Each element of <i>Input</i> is considered to be a character.</li>
+ <li>Let <i>listIndex</i> be the index into <i>Input</i> of the character that was obtained from element <i>index</i>
+ of <i>str</i>.</li>
+ <li>Let <i>InputLength</i> be the number of characters contained in <i>Input</i>. This variable will be used
+ throughout the algorithms in <a href="#sec-pattern-semantics">21.2.2</a>.</li>
+ <li>Let <i>c</i> be a Continuation that always returns its State argument as a successful MatchResult.</li>
+ <li>Let <i>cap</i> be a <a href="#sec-list-and-record-specification-type">List</a> of <i>NcapturingParens</i>
+ <b>undefined</b> values, indexed 1 through <i>NcapturingParens</i>.</li>
+ <li>Let <i>x</i> be the State (<i>listIndex</i>, <i>cap</i>).</li>
+ <li>Call <i>m</i>(<i>x</i>, <i>c</i>) and return its result.</li>
+ </ol>
+ </li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> A Pattern evaluates ("compiles") to an internal procedure value. <code><a
+ href="#sec-regexp.prototype.exec">RegExp.prototype.exec</a></code> and other methods can then apply this procedure to a
+ String and an offset within the String to determine whether the pattern would match starting at exactly that offset
+ within the String, and, if it does match, what the values of the capturing parentheses would be. The algorithms in <a
+ href="#sec-pattern-semantics">21.2.2</a> are designed so that compiling a pattern may throw a <b>SyntaxError</b>
+ exception; on the other hand, once the pattern is successfully compiled, applying its result internal procedure to find
+ a match in a String cannot throw an exception (except for any host-defined exceptions that can occur anywhere such as
+ out-of-memory).</p>
+ </div>
+ </section>
+
+ <section id="sec-disjunction">
+ <h1><span class="secnum" id="sec-21.2.2.3"><a href="#sec-disjunction" title="link to this section">21.2.2.3</a></span>
+ Disjunction</h1>
+
+ <p>The production <span class="prod"><span class="nt">Disjunction</span> <span class="geq">::</span> <span
+ class="nt">Alternative</span></span> evaluates by evaluating <span class="nt">Alternative</span> to obtain a <span
+ style="font-family: Times New Roman">Matcher</span> and returning that <span style="font-family: Times New
+ Roman">Matcher</span>.</p>
+
+ <p>The production <span class="prod"><span class="nt">Disjunction</span> <span class="geq">::</span> <span
+ class="nt">Alternative</span> <code class="t">|</code> <span class="nt">Disjunction</span></span> evaluates as
+ follows:</p>
+
+ <ol class="proc">
+ <li>Evaluate <i>Alternative</i> to obtain a Matcher <i>m1</i>.</li>
+ <li>Evaluate <i>Disjunction</i> to obtain a Matcher <i>m2</i>.</li>
+ <li>Return an internal Matcher closure that takes two arguments, a State <i>x</i> and a Continuation <i>c</i>, and
+ performs the following:
+ <ol class="nested proc">
+ <li>Call <i>m1</i>(<i>x</i>, <i>c</i>) and let <i>r</i> be its result.</li>
+ <li>If <i>r</i> isn't <b>failure</b>, return <i>r</i>.</li>
+ <li>Call <i>m2</i>(<i>x</i>, <i>c</i>) and return its result.</li>
+ </ol>
+ </li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>|</code> regular expression operator separates two alternatives. The pattern
+ first tries to match the left <i>Alternative</i> (followed by the sequel of the regular expression); if it fails, it
+ tries to match the right <i>Disjunction</i> (followed by the sequel of the regular expression). If the left
+ <i>Alternative</i>, the right <i>Disjunction</i>, and the sequel all have choice points, all choices in the sequel are
+ tried before moving on to the next choice in the left <i>Alternative</i>. If choices in the left <i>Alternative</i> are
+ exhausted, the right <i>Disjunction</i> is tried instead of the left <i>Alternative</i>. Any capturing parentheses
+ inside a portion of the pattern skipped by <code>|</code> produce <b>undefined</b> values instead of Strings. Thus, for
+ example,</p>
+
+ <pre>/a|ab/.exec("abc")</pre>
+
+ <p>returns the result <code>"a"</code> and not <code>"ab"</code>. Moreover,</p>
+
+ <pre>/((a)|(ab))((c)|(bc))/.exec("abc")</pre>
+
+ <p>returns the array</p>
+
+ <pre>["abc", "a", "a", undefined, "bc", undefined, "bc"]</pre>
+
+ <p>and not</p>
+
+ <pre>["abc", "ab", undefined, "ab", "c", "c", undefined]</pre>
+ </div>
+ </section>
+
+ <section id="sec-alternative">
+ <h1><span class="secnum" id="sec-21.2.2.4"><a href="#sec-alternative" title="link to this section">21.2.2.4</a></span>
+ Alternative</h1>
+
+ <p>The production <span class="prod"><span class="nt">Alternative</span> <span class="geq">::</span> <span
+ class="grhsannot">[empty]</span></span> evaluates by returning a Matcher that takes two arguments, a State <var>x</var>
+ and a Continuation <var>c</var>, and returns the result of calling <var>c</var>(<var>x</var>).</p>
+
+ <p>The production <span class="prod"><span class="nt">Alternative</span> <span class="geq">::</span> <span
+ class="nt">Alternative</span> <span class="nt">Term</span></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Evaluate <i>Alternative</i> to obtain a Matcher <i>m1</i>.</li>
+ <li>Evaluate <i>Term</i> to obtain a Matcher <i>m2</i>.</li>
+ <li>Return an internal Matcher closure that takes two arguments, a State <i>x</i> and a Continuation <i>c</i>, and
+ performs the following:
+ <ol class="nested proc">
+ <li>Create a Continuation <i>d</i> that takes a State argument <i>y</i> and returns the result of calling
+ <i>m2</i>(<i>y</i>, <i>c</i>).</li>
+ <li>Call <i>m1</i>(<i>x</i>, <i>d</i>) and return its result.</li>
+ </ol>
+ </li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Consecutive <i>Terms</i> try to simultaneously match consecutive portions of
+ <i>Input</i>. If the left <i>Alternative</i>, the right <i>Term</i>, and the sequel of the regular expression all have
+ choice points, all choices in the sequel are tried before moving on to the next choice in the right <i>Term</i>, and all
+ choices in the right <i>Term</i> are tried before moving on to the next choice in the left <i>Alternative</i>.</p>
+ </div>
+ </section>
+
+ <section id="sec-term">
+ <div class="front">
+ <h1><span class="secnum" id="sec-21.2.2.5"><a href="#sec-term" title="link to this section">21.2.2.5</a></span>
+ Term</h1>
+
+ <p>The production <span class="prod"><span class="nt">Term</span> <span class="geq">::</span> <span
+ class="nt">Assertion</span></span> evaluates by returning an internal Matcher closure that takes two arguments, a State
+ <var>x</var> and a Continuation <var>c</var>, and performs the following:</p>
+
+ <ol class="proc">
+ <li>Evaluate <i>Assertion</i> to obtain an AssertionTester <i>t</i>.</li>
+ <li>Call <i>t</i>(<i>x</i>) and let <i>r</i> be the resulting Boolean value.</li>
+ <li>If <i>r</i> is <b>false</b>, return <b>failure</b>.</li>
+ <li>Call <i>c</i>(<i>x</i>) and return its result.</li>
+ </ol>
+
+ <p>The production <span class="prod"><span class="nt">Term</span> <span class="geq">::</span> <span
+ class="nt">Atom</span></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Return the Matcher that is the result of evaluating <i>Atom</i>.</li>
+ </ol>
+
+ <p>The production <span class="prod"><span class="nt">Term</span> <span class="geq">::</span> <span
+ class="nt">Atom</span> <span class="nt">Quantifier</span></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Evaluate <i>Atom</i> to obtain a Matcher <i>m</i>.</li>
+ <li>Evaluate <i>Quantifier</i> to obtain the three results: an integer <i>min</i>, an integer (or ∞) <i>max</i>,
+ and Boolean <i>greedy</i>.</li>
+ <li>If <i>max</i> is finite and less than <i>min</i>, then throw a <b>SyntaxError</b> exception.</li>
+ <li>Let <i>parenIndex</i> be the number of left capturing parentheses in the entire regular expression that occur to
+ the left of this production expansion's <i>Term</i>. This is the total number of times the <span
+ class="prod"><span class="nt">Atom</span> <span class="geq">::</span> <code class="t">(</code> <span
+ class="nt">Disjunction</span> <code class="t">)</code></span> production is expanded prior to this production's
+ <i>Term</i> plus the total number of <span class="prod"><span class="nt">Atom</span> <span class="geq">::</span>
+ <code class="t">(</code> <span class="nt">Disjunction</span> <code class="t">)</code></span> productions enclosing
+ this <i>Term</i>.</li>
+ <li>Let <i>parenCount</i> be the number of left capturing parentheses in the expansion of this production's
+ <i>Atom</i>. This is the total number of <span class="prod"><span class="nt">Atom</span> <span
+ class="geq">::</span> <code class="t">(</code> <span class="nt">Disjunction</span> <code class="t">)</code></span>
+ productions enclosed by this production's <i>Atom</i>.</li>
+ <li>Return an internal Matcher closure that takes two arguments, a State <i>x</i> and a Continuation <i>c</i>, and
+ performs the following:
+ <ol class="nested proc">
+ <li>Call RepeatMatcher(<i>m</i>, <i>min</i>, <i>max</i>, <i>greedy</i>, <i>x</i>, <i>c</i>, <i>parenIndex</i>,
+ <i>parenCount</i>) and return its result.</li>
+ </ol>
+ </li>
+ </ol>
+ </div>
+
+ <section id="sec-runtime-semantics-repeatmatcher-abstract-operation">
+ <h1><span class="secnum" id="sec-21.2.2.5.1"><a href="#sec-runtime-semantics-repeatmatcher-abstract-operation"
+ title="link to this section">21.2.2.5.1</a></span> Runtime Semantics: RepeatMatcher Abstract Operation</h1>
+
+ <p>The abstract operation <span style="font-family: Times New Roman">RepeatMatcher</span> takes eight parameters, a
+ Matcher <var>m</var>, an integer <var>min</var>, an integer (or ∞) <var>max</var>, a Boolean <var>greedy</var>, a
+ State <var>x</var>, a Continuation <var>c</var>, an integer <var>parenIndex</var>, and an integer <var>parenCount</var>,
+ and performs the following:</p>
+
+ <ol class="proc">
+ <li>If <i>max</i> is zero, then call <i>c</i>(<i>x</i>) and return its result.</li>
+ <li>Create an internal Continuation closure <i>d</i> that takes one State argument <i>y</i> and performs the
+ following:
+ <ol class="nested proc">
+ <li>If <i>min</i> is zero and <i>y</i>'s <i>endIndex</i> is equal to <i>x</i>'s <i>endIndex</i>, then return
+ <b>failure</b>.</li>
+ <li>If <i>min</i> is zero then let <i>min2</i> be zero; otherwise let <i>min2</i> be <i>min</i>–1.</li>
+ <li>If <i>max</i> is ∞, then let <i>max2</i> be ∞; otherwise let <i>max2</i> be
+ <i>max</i>–1.</li>
+ <li>Call RepeatMatcher(<i>m</i>, <i>min2</i>, <i>max2</i>, <i>greedy</i>, <i>y</i>, <i>c</i>, <i>parenIndex</i>,
+ <i>parenCount</i>) and return its result.</li>
+ </ol>
+ </li>
+ <li>Let <i>cap</i> be a fresh copy of <i>x</i>'s <i>captures</i> <a
+ href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>For every integer <i>k</i> that satisfies <i>parenIndex</i> < <i>k</i> and <i>k</i> ≤
+ <i>parenIndex</i>+<i>parenCount</i>, set <i>cap</i>[<i>k</i>] to <b>undefined</b>.</li>
+ <li>Let <i>e</i> be <i>x</i>'s <i>endIndex</i>.</li>
+ <li>Let <i>xr</i> be the State (<i>e</i>, <i>cap</i>).</li>
+ <li>If <i>min</i> is not zero, then call <i>m</i>(<i>xr</i>, <i>d</i>) and return its result.</li>
+ <li>If <i>greedy</i> is <b>false</b>, then
+ <ol class="block">
+ <li>Call <i>c</i>(<i>x</i>) and let <i>z</i> be its result.</li>
+ <li>If <i>z</i> is not <b>failure</b>, return <i>z</i>.</li>
+ <li>Call <i>m</i>(<i>xr</i>, <i>d</i>) and return its result.</li>
+ </ol>
+ </li>
+ <li>Call <i>m</i>(<i>xr</i>, <i>d</i>) and let <i>z</i> be its result.</li>
+ <li>If <i>z</i> is not <b>failure</b>, return <i>z</i>.</li>
+ <li>Call <i>c</i>(<i>x</i>) and return its result.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> An <i>Atom</i> followed by a <i>Quantifier</i> is repeated the number of times
+ specified by the <i>Quantifier</i>. A <i>Quantifier</i> can be non-greedy, in which case the <i>Atom</i> pattern is
+ repeated as few times as possible while still matching the sequel, or it can be greedy, in which case the <i>Atom</i>
+ pattern is repeated as many times as possible while still matching the sequel. The <i>Atom</i> pattern is repeated
+ rather than the input character sequence that it matches, so different repetitions of the <i>Atom</i> can match
+ different input substrings.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 2</span> If the <i>Atom</i> and the sequel of the regular expression all have choice points,
+ the <i>Atom</i> is first matched as many (or as few, if non-greedy) times as possible. All choices in the sequel are
+ tried before moving on to the next choice in the last repetition of <i>Atom</i>. All choices in the last
+ (n<sup>th</sup>) repetition of <i>Atom</i> are tried before moving on to the next choice in the next-to-last
+ (n–1)<sup>st</sup> repetition of <i>Atom</i>; at which point it may turn out that more or fewer repetitions of
+ <i>Atom</i> are now possible; these are exhausted (again, starting with either as few or as many as possible) before
+ moving on to the next choice in the (n-1)<sup>st</sup> repetition of <i>Atom</i> and so on.</p>
+
+ <p>Compare</p>
+
+ <pre>/a[a-z]{2,4}/.exec("abcdefghi")</pre>
+
+ <p>which returns <code>"abcde"</code> with</p>
+
+ <pre>/a[a-z]{2,4}?/.exec("abcdefghi")</pre>
+
+ <p>which returns <code>"abc"</code>.</p>
+
+ <p>Consider also</p>
+
+ <pre>/(aa|aabaac|ba|b|c)*/.exec("aabaac")</pre>
+
+ <p>which, by the choice point ordering above, returns the array</p>
+
+ <pre>["aaba", "ba"]</pre>
+
+ <p>and not any of:</p>
+
+ <pre>["aabaac", "aabaac"]</pre>
+ <pre>["aabaac", "c"]</pre>
+
+ <p>The above ordering of choice points can be used to write a regular expression that calculates the greatest common
+ divisor of two numbers (represented in unary notation). The following example calculates the gcd of 10 and 15:</p>
+
+ <pre>"aaaaaaaaaa,aaaaaaaaaaaaaaa".replace(/^(a+)\1*,\1+$/,"$1")</pre>
+
+ <p>which returns the gcd in unary notation <code>"aaaaa"</code>.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 3</span> Step 5 of the RepeatMatcher clears <i>Atom's</i> captures each time <i>Atom</i> is
+ repeated. We can see its behaviour in the regular expression</p>
+
+ <pre>/(z)((a+)?(b+)?(c))*/.exec("zaacbbbcac")</pre>
+
+ <p>which returns the array</p>
+
+ <pre>["zaacbbbcac", "z", "ac", "a", undefined, "c"]</pre>
+
+ <p>and not</p>
+
+ <pre>["zaacbbbcac", "z", "ac", "a", "bbb", "c"]</pre>
+
+ <p>because each iteration of the outermost <code>*</code> clears all captured Strings contained in the quantified
+ <span class="nt">Atom</span>, which in this case includes capture Strings numbered 2, 3, 4, and 5.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 4</span> Step 1 of the RepeatMatcher's <i>d</i> closure states that, once the minimum number
+ of repetitions has been satisfied, any more expansions of <i>Atom</i> that match the empty character sequence are not
+ considered for further repetitions. This prevents the regular expression engine from falling into an infinite loop on
+ patterns such as:</p>
+
+ <pre>/(a*)*/.exec("b")</pre>
+
+ <p>or the slightly more complicated:</p>
+
+ <pre>/(a*)b\1+/.exec("baaaac")</pre>
+
+ <p>which returns the array</p>
+
+ <pre>["b", ""]</pre>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-assertion">
+ <div class="front">
+ <h1><span class="secnum" id="sec-21.2.2.6"><a href="#sec-assertion" title="link to this section">21.2.2.6</a></span>
+ Assertion</h1>
+
+ <p>The production <span class="prod"><span class="nt">Assertion</span> <span class="geq">::</span> <code
+ class="t">^</code></span> evaluates by returning an internal AssertionTester closure that takes a State argument
+ <var>x</var> and performs the following:</p>
+
+ <ol class="proc">
+ <li>Let <i>e</i> be <i>x</i>'s <i>endIndex</i>.</li>
+ <li>If <i>e</i> is zero, return <b>true</b>.</li>
+ <li>If <i>Multiline</i> is <b>false</b>, return <b>false</b>.</li>
+ <li>If the character <i>Input</i>[<i>e</i>–1] is one of <i>LineTerminator</i>, return <b>true</b>.</li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Even when the <code>y</code> flag is used with a pattern, <code>^</code> always
+ matches only at the beginning of <i>Input</i>, or (if <i>Multiline</i> is <b>true</b>) at the beginning of a line.</p>
+ </div>
+
+ <p>The production <span class="prod"><span class="nt">Assertion</span> <span class="geq">::</span> <code
+ class="t">$</code></span> evaluates by returning an internal AssertionTester closure that takes a State argument
+ <var>x</var> and performs the following:</p>
+
+ <ol class="proc">
+ <li>Let <i>e</i> be <i>x</i>'s <i>endIndex</i>.</li>
+ <li>If <i>e</i> is equal to <i>InputLength</i>, return <b>true</b>.</li>
+ <li>If <i>Multiline</i> is <b>false</b>, return <b>false</b>.</li>
+ <li>If the character <i>Input</i>[<i>e</i>] is one of <i>LineTerminator</i>, return <b>true</b>.</li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+
+ <p>The production <span class="prod"><span class="nt">Assertion</span> <span class="geq">::</span> <code
+ class="t">\</code> <code class="t">b</code></span> evaluates by returning an internal AssertionTester closure that takes
+ a State argument <var>x</var> and performs the following:</p>
+
+ <ol class="proc">
+ <li>Let <i>e</i> be <i>x</i>'s <i>endIndex</i>.</li>
+ <li>Call IsWordChar(<i>e</i>–1) and let <i>a</i> be the Boolean result.</li>
+ <li>Call IsWordChar(<i>e</i>) and let <i>b</i> be the Boolean result.</li>
+ <li>If <i>a</i> is <b>true</b> and <i>b</i> is <b>false</b>, return <b>true</b>.</li>
+ <li>If <i>a</i> is <b>false</b> and <i>b</i> is <b>true</b>, return <b>true</b>.</li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+
+ <p>The production <span class="prod"><span class="nt">Assertion</span> <span class="geq">::</span> <code
+ class="t">\</code> <code class="t">B</code></span> evaluates by returning an internal AssertionTester closure that takes
+ a State argument <var>x</var> and performs the following:</p>
+
+ <ol class="proc">
+ <li>Let <i>e</i> be <i>x</i>'s <i>endIndex</i>.</li>
+ <li>Call IsWordChar(<i>e</i>–1) and let <i>a</i> be the Boolean result.</li>
+ <li>Call IsWordChar(<i>e</i>) and let <i>b</i> be the Boolean result.</li>
+ <li>If <i>a</i> is <b>true</b> and <i>b</i> is <b>false</b>, return <b>false</b>.</li>
+ <li>If <i>a</i> is <b>false</b> and <i>b</i> is <b>true</b>, return <b>false</b>.</li>
+ <li>Return <b>true</b>.</li>
+ </ol>
+
+ <p>The production <span class="prod"><span class="nt">Assertion</span> <span class="geq">::</span> <code
+ class="t">(</code> <code class="t">?</code> <code class="t">=</code> <span class="nt">Disjunction</span> <code
+ class="t">)</code></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Evaluate <i>Disjunction</i> to obtain a Matcher <i>m</i>.</li>
+ <li>Return an internal Matcher closure that takes two arguments, a State <i>x</i> and a Continuation <i>c</i>, and
+ performs the following steps:
+ <ol class="nested proc">
+ <li>Let <i>d</i> be a Continuation that always returns its State argument as a successful MatchResult.</li>
+ <li>Call <i>m</i>(<i>x</i>, <i>d</i>) and let <i>r</i> be its result.</li>
+ <li>If <i>r</i> is <b>failure</b>, return <b>failure</b>.</li>
+ <li>Let <i>y</i> be <i>r</i>'s State.</li>
+ <li>Let <i>cap</i> be <i>y</i>'s <i>captures</i> <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Let <i>xe</i> be <i>x</i>'s <i>endIndex</i>.</li>
+ <li>Let <i>z</i> be the State (<i>xe</i>, <i>cap</i>).</li>
+ <li>Call <i>c</i>(<i>z</i>) and return its result.</li>
+ </ol>
+ </li>
+ </ol>
+
+ <p>The production <span class="prod"><span class="nt">Assertion</span> <span class="geq">::</span> <code
+ class="t">(</code> <code class="t">?</code> <code class="t">!</code> <span class="nt">Disjunction</span> <code
+ class="t">)</code></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Evaluate <i>Disjunction</i> to obtain a Matcher <i>m</i>.</li>
+ <li>Return an internal Matcher closure that takes two arguments, a State <i>x</i> and a Continuation <i>c</i>, and
+ performs the following steps:
+ <ol class="nested proc">
+ <li>Let <i>d</i> be a Continuation that always returns its State argument as a successful MatchResult.</li>
+ <li>Call <i>m</i>(<i>x</i>, <i>d</i>) and let <i>r</i> be its result.</li>
+ <li>If <i>r</i> isn't <b>failure</b>, return <b>failure</b>.</li>
+ <li>Call <i>c</i>(<i>x</i>) and return its result.</li>
+ </ol>
+ </li>
+ </ol>
+ </div>
+
+ <section id="sec-runtime-semantics-iswordchar-abstract-operation">
+ <h1><span class="secnum" id="sec-21.2.2.6.1"><a href="#sec-runtime-semantics-iswordchar-abstract-operation"
+ title="link to this section">21.2.2.6.1</a></span> Runtime Semantics: IsWordChar Abstract Operation</h1>
+
+ <p>The abstract operation IsWordChar takes an integer parameter <var>e</var> and performs the following:</p>
+
+ <ol class="proc">
+ <li>If <i>e</i> is –1 or <i>e</i> is <i>InputLength</i>, return <b>false</b>.</li>
+ <li>Let <i>c</i> be the character <i>Input</i>[<i>e</i>].</li>
+ <li>If <i>c</i> is one of the sixty-three characters below, return <b>true</b>.
+ <figure>
+ <table class="lightweight-table">
+ <tr>
+ <td><code>a</code></td>
+ <td><code>b</code></td>
+ <td><code>c</code></td>
+ <td><code>d</code></td>
+ <td><code>e</code></td>
+ <td><code>f</code></td>
+ <td><code>g</code></td>
+ <td><code>h</code></td>
+ <td><code>i</code></td>
+ <td><code>j</code></td>
+ <td><code>k</code></td>
+ <td><code>l</code></td>
+ <td><code>m</code></td>
+ <td><code>n</code></td>
+ <td><code>o</code></td>
+ <td><code>p</code></td>
+ <td><code>q</code></td>
+ <td><code>r</code></td>
+ <td><code>s</code></td>
+ <td><code>t</code></td>
+ <td><code>u</code></td>
+ <td><code>v</code></td>
+ <td><code>w</code></td>
+ <td><code>x</code></td>
+ <td><code>y</code></td>
+ <td><code>z</code></td>
+ </tr>
+ <tr>
+ <td><code>A</code></td>
+ <td><code>B</code></td>
+ <td><code>C</code></td>
+ <td><code>D</code></td>
+ <td><code>E</code></td>
+ <td><code>F</code></td>
+ <td><code>G</code></td>
+ <td><code>H</code></td>
+ <td><code>I</code></td>
+ <td><code>J</code></td>
+ <td><code>K</code></td>
+ <td><code>L</code></td>
+ <td><code>M</code></td>
+ <td><code>N</code></td>
+ <td><code>O</code></td>
+ <td><code>P</code></td>
+ <td><code>Q</code></td>
+ <td><code>R</code></td>
+ <td><code>S</code></td>
+ <td><code>T</code></td>
+ <td><code>U</code></td>
+ <td><code>V</code></td>
+ <td><code>W</code></td>
+ <td><code>X</code></td>
+ <td><code>Y</code></td>
+ <td><code>Z</code></td>
+ </tr>
+ <tr>
+ <td><code>0</code></td>
+ <td><code>1</code></td>
+ <td><code>2</code></td>
+ <td><code>3</code></td>
+ <td><code>4</code></td>
+ <td><code>5</code></td>
+ <td><code>6</code></td>
+ <td><code>7</code></td>
+ <td><code>8</code></td>
+ <td><code>9</code></td>
+ <td><code>_</code></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ </tr>
+ </table>
+ </figure>
+ </li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-quantifier">
+ <h1><span class="secnum" id="sec-21.2.2.7"><a href="#sec-quantifier" title="link to this section">21.2.2.7</a></span>
+ Quantifier</h1>
+
+ <p>The production <span class="prod"><span class="nt">Quantifier</span> <span class="geq">::</span> <span
+ class="nt">QuantifierPrefix</span></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Evaluate <i>QuantifierPrefix</i> to obtain the two results: an integer <i>min</i> and an integer (or ∞)
+ <i>max</i>.</li>
+ <li>Return the three results <i>min</i>, <i>max</i>, and <b>true</b>.</li>
+ </ol>
+
+ <p>The production <span class="prod"><span class="nt">Quantifier</span> <span class="geq">::</span> <span
+ class="nt">QuantifierPrefix</span> <code class="t">?</code></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Evaluate <i>QuantifierPrefix</i> to obtain the two results: an integer <i>min</i> and an integer (or ∞)
+ <i>max</i>.</li>
+ <li>Return the three results <i>min</i>, <i>max</i>, and <b>false</b>.</li>
+ </ol>
+
+ <p>The production <span class="prod"><span class="nt">QuantifierPrefix</span> <span class="geq">::</span> <code
+ class="t">*</code></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Return the two results 0 and ∞.</li>
+ </ol>
+
+ <p>The production <span class="prod"><span class="nt">QuantifierPrefix</span> <span class="geq">::</span> <code
+ class="t">+</code></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Return the two results 1 and ∞.</li>
+ </ol>
+
+ <p>The production <span class="prod"><span class="nt">QuantifierPrefix</span> <span class="geq">::</span> <code
+ class="t">?</code></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Return the two results 0 and 1.</li>
+ </ol>
+
+ <p>The production <span class="prod"><span class="nt">QuantifierPrefix</span> <span class="geq">::</span> <code
+ class="t">{</code> <span class="nt">DecimalDigits</span> <code class="t">}</code></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Let <i>i</i> be the MV of <i>DecimalDigits</i> (<a href="#sec-literals-numeric-literals">see 11.8.3</a>).</li>
+ <li>Return the two results <i>i</i> and <i>i</i>.</li>
+ </ol>
+
+ <p>The production <span class="prod"><span class="nt">QuantifierPrefix</span> <span class="geq">::</span> <code
+ class="t">{</code> <span class="nt">DecimalDigits</span> <code class="t">,</code> <code class="t">}</code></span>
+ evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Let <i>i</i> be the MV of <i>DecimalDigits</i>.</li>
+ <li>Return the two results <i>i</i> and ∞.</li>
+ </ol>
+
+ <p>The production <span class="prod"><span class="nt">QuantifierPrefix</span> <span class="geq">::</span> <code
+ class="t">{</code> <span class="nt">DecimalDigits</span> <code class="t">,</code> <span class="nt">DecimalDigits</span>
+ <code class="t">}</code></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Let <i>i</i> be the MV of the first <i>DecimalDigits</i>.</li>
+ <li>Let <i>j</i> be the MV of the second <i>DecimalDigits</i>.</li>
+ <li>Return the two results <i>i</i> and <i>j</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-atom">
+ <div class="front">
+ <h1><span class="secnum" id="sec-21.2.2.8"><a href="#sec-atom" title="link to this section">21.2.2.8</a></span>
+ Atom</h1>
+
+ <p>The production <span class="prod"><span class="nt">Atom</span> <span class="geq">::</span> <span
+ class="nt">PatternCharacter</span></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Let <i>ch</i> be the character matched by <i>PatternCharacter</i>.</li>
+ <li>Let <i>A</i> be a one-element CharSet containing the character <i>ch</i>.</li>
+ <li>Call CharacterSetMatcher(<i>A</i>, <b>false</b>) and return its Matcher result.</li>
+ </ol>
+
+ <p>The production <span class="prod"><span class="nt">Atom</span> <span class="geq">::</span> <code
+ class="t">.</code></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Let <i>A</i> be the set of all characters except <i>LineTerminator</i>.</li>
+ <li>Call CharacterSetMatcher(<i>A</i>, <b>false</b>) and return its Matcher result.</li>
+ </ol>
+
+ <p>The production <span class="prod"><span class="nt">Atom</span> <span class="geq">::</span> <code class="t">\</code>
+ <span class="nt">AtomEscape</span></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Return the Matcher that is the result of evaluating <i>AtomEscape</i>.</li>
+ </ol>
+
+ <p>The production <span class="prod"><span class="nt">Atom</span> <span class="geq">::</span> <span
+ class="nt">CharacterClass</span></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Evaluate <i>CharacterClass</i> to obtain a CharSet <i>A</i> and a Boolean <i>invert</i>.</li>
+ <li>Call CharacterSetMatcher(<i>A</i>, <i>invert</i>) and return its Matcher result.</li>
+ </ol>
+
+ <p>The production <span class="prod"><span class="nt">Atom</span> <span class="geq">::</span> <code class="t">(</code>
+ <span class="nt">Disjunction</span> <code class="t">)</code></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Evaluate <i>Disjunction</i> to obtain a Matcher <i>m</i>.</li>
+ <li>Let <i>parenIndex</i> be the number of left capturing parentheses in the entire regular expression that occur to
+ the left of this production expansion's initial left parenthesis. This is the total number of times the <span
+ class="prod"><span class="nt">Atom</span> <span class="geq">::</span> <code class="t">(</code> <span
+ class="nt">Disjunction</span> <code class="t">)</code></span> production is expanded prior to this production's
+ <i>Atom</i> plus the total number of <span class="prod"><span class="nt">Atom</span> <span class="geq">::</span>
+ <code class="t">(</code> <span class="nt">Disjunction</span> <code class="t">)</code></span> productions enclosing
+ this <i>Atom</i>.</li>
+ <li>Return an internal Matcher closure that takes two arguments, a State <i>x</i> and a Continuation <i>c</i>, and
+ performs the following steps:
+ <ol class="nested proc">
+ <li>Create an internal Continuation closure <i>d</i> that takes one State argument <i>y</i> and performs the
+ following steps:
+ <ol class="nested proc">
+ <li>Let <i>cap</i> be a fresh copy of <i>y</i>'s <i>captures</i> <a
+ href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Let <i>xe</i> be <i>x</i>'s <i>endIndex</i>.</li>
+ <li>Let <i>ye</i> be <i>y</i>'s <i>endIndex</i>.</li>
+ <li>Let <i>s</i> be a fresh <a href="#sec-list-and-record-specification-type">List</a> whose characters are
+ the characters of <i>Input</i> at positions <i>xe</i> (inclusive) through <i>ye</i> (exclusive).</li>
+ <li>Set <i>cap</i>[<i>parenIndex</i>+1] to <i>s</i>.</li>
+ <li>Let <i>z</i> be the State (<i>ye</i>, <i>cap</i>).</li>
+ <li>Call <i>c</i>(<i>z</i>) and return its result.</li>
+ </ol>
+ </li>
+ <li>Call <i>m</i>(<i>x</i>, <i>d</i>) and return its result.</li>
+ </ol>
+ </li>
+ </ol>
+
+ <p>The production <span class="prod"><span class="nt">Atom</span> <span class="geq">::</span> <code class="t">(</code>
+ <code class="t">?</code> <code class="t">:</code> <span class="nt">Disjunction</span> <code class="t">)</code></span>
+ evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Return the Matcher that is the result of evaluating <i>Disjunction</i>.</li>
+ </ol>
+ </div>
+
+ <section id="sec-runtime-semantics-charactersetmatcher-abstract-operation">
+ <h1><span class="secnum" id="sec-21.2.2.8.1"><a href="#sec-runtime-semantics-charactersetmatcher-abstract-operation"
+ title="link to this section">21.2.2.8.1</a></span> Runtime Semantics: CharacterSetMatcher Abstract Operation</h1>
+
+ <p>The abstract operation CharacterSetMatcher takes two arguments, a CharSet <var>A</var> and a Boolean flag
+ <var>invert</var>, and performs the following:</p>
+
+ <ol class="proc">
+ <li>Return an internal Matcher closure that takes two arguments, a State <i>x</i> and a Continuation <i>c</i>, and
+ performs the following steps:
+ <ol class="nested proc">
+ <li>Let <i>e</i> be <i>x</i>'s <i>endIndex</i>.</li>
+ <li>If <i>e</i> is <i>InputLength</i>, return <b>failure</b>.</li>
+ <li>Let <i>ch</i> be the character <i>Input</i>[<i>e</i>].</li>
+ <li>Let <i>cc</i> be the result of Canonicalize(<i>ch</i>).</li>
+ <li>If <i>invert</i> is <b>false</b>, then
+ <ol class="block">
+ <li>If there does not exist a member <i>a</i> of set <i>A</i> such that Canonicalize(<i>a</i>) is <i>cc</i>,
+ return <b>failure</b>.</li>
+ </ol>
+ </li>
+ <li>Else <i>invert</i> is <b>true</b>,
+ <ol class="block">
+ <li>If there exists a member <i>a</i> of set <i>A</i> such that Canonicalize(<i>a</i>) is <i>cc</i>, return
+ <b>failure.</b></li>
+ </ol>
+ </li>
+ <li>Let <i>cap</i> be <i>x</i>'s <i>captures</i> <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Let <i>y</i> be the State (<i>e</i>+1, <i>cap</i>).</li>
+ <li>Call <i>c</i>(<i>y</i>) and return its result.</li>
+ </ol>
+ </li>
+ </ol>
+ </section>
+
+ <section id="sec-runtime-semantics-canonicalize-abstract-operation">
+ <h1><span class="secnum" id="sec-21.2.2.8.2"><a href="#sec-runtime-semantics-canonicalize-abstract-operation"
+ title="link to this section">21.2.2.8.2</a></span> Runtime Semantics: Canonicalize Abstract Operation</h1>
+
+ <p>The abstract operation Canonicalize takes a character parameter <var>ch</var> and performs the following steps:</p>
+
+ <ol class="proc">
+ <li>If <i>IgnoreCase</i> is <b>false</b>, return <i>ch</i>.</li>
+ <li>If <i>Unicode</i> is <b>true</b>,
+ <ol class="block">
+ <li>If the file CaseFolding.txt of the Unicode Character Database provides a simple or common case folding mapping
+ for <i>ch</i>, then return the result of applying that mapping to <i>ch</i>.</li>
+ <li>Else, return <i>ch.</i></li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>ch</i> is a UTF-16 code unit.</li>
+ <li>Let <i>s</i> be the ECMAScript String value consisting of the single code unit <i>ch</i>.</li>
+ <li>Let <i>u</i> be the same result produced as if by performing the algorithm for <code><a
+ href="#sec-string.prototype.touppercase">String.prototype.toUpperCase</a></code> using <i>s</i> as the
+ <b>this</b> value.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>u</i>).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>u</i> is a String value.</li>
+ <li>If <i>u</i> does not consist of a single code unit, then return <i>ch</i>.</li>
+ <li>Let <i>cu</i> be <i>u</i>’s single code unit element.</li>
+ <li>If <i>ch</i>'s code unit value ≥ 128 and <i>cu</i>'s code unit value < 128, then return <i>ch</i>.</li>
+ <li>Return <i>cu</i>.</li>
+ </ol>
+ </li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> Parentheses of the form <code>(</code> <i>Disjunction</i> <code>)</code> serve both
+ to group the components of the <i>Disjunction</i> pattern together and to save the result of the match. The result can
+ be used either in a backreference (<code>\</code> followed by a nonzero decimal number), referenced in a replace
+ String, or returned as part of an array from the regular expression matching internal procedure. To inhibit the
+ capturing behaviour of parentheses, use the form <code>(?:</code> <i>Disjunction</i> <code>)</code> instead.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 2</span> The form <code>(?=</code> <i>Disjunction</i> <code>)</code> specifies a zero-width
+ positive lookahead. In order for it to succeed, the pattern inside <i>Disjunction</i> must match at the current
+ position, but the current position is not advanced before matching the sequel. If <i>Disjunction</i> can match at the
+ current position in several ways, only the first one is tried. Unlike other regular expression operators, there is no
+ backtracking into a <code>(?=</code> form (this unusual behaviour is inherited from Perl). This only matters when the
+ <i>Disjunction</i> contains capturing parentheses and the sequel of the pattern contains backreferences to those
+ captures.</p>
+
+ <p>For example,</p>
+
+ <pre>/(?=(a+))/.exec("baaabac")</pre>
+
+ <p>matches the empty String immediately after the first <code>b</code> and therefore returns the array:</p>
+
+ <pre>["", "aaa"]</pre>
+
+ <p>To illustrate the lack of backtracking into the lookahead, consider:</p>
+
+ <pre>/(?=(a+))a*b\1/.exec("baaabac")</pre>
+
+ <p>This expression returns</p>
+
+ <pre>["aba", "a"]</pre>
+
+ <p>and not:</p>
+
+ <pre>["aaaba", "a"]</pre>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 3</span> The form <code>(?!</code> <i>Disjunction</i> <code>)</code> specifies a zero-width
+ negative lookahead. In order for it to succeed, the pattern inside <i>Disjunction</i> must fail to match at the
+ current position. The current position is not advanced before matching the sequel. <i>Disjunction</i> can contain
+ capturing parentheses, but backreferences to them only make sense from within <i>Disjunction</i> itself.
+ Backreferences to these capturing parentheses from elsewhere in the pattern always return <b>undefined</b> because the
+ negative lookahead must fail for the pattern to succeed. For example,</p>
+
+ <pre>/(.*?)a(?!(a+)b\2c)\2(.*)/.exec("baaabaac")</pre>
+
+ <p>looks for an <code>a</code> not immediately followed by some positive number n of <code>a</code>'s, a
+ <code>b</code>, another n <code>a</code>'s (specified by the first <code>\2</code>) and a <code>c</code>. The second
+ <code>\2</code> is outside the negative lookahead, so it matches against <b>undefined</b> and therefore always
+ succeeds. The whole expression returns the array:</p>
+
+ <pre>["baaabaac", "ba", undefined, "abaac"]</pre>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 4</span> In case-insignificant matches when <i>Unicode</i> is <b>true</b>, all characters are
+ implicitly case-folded using the simple mapping provided by the Unicode standard immediately before they are compared.
+ The simple mapping always maps to a single code point, so it does not map, for example, <code>"ß"</code> (U+00DF
+ to <code>"SS"</code>. It may however map a code point outside the Basic Latin range to a character within, for
+ example, “<span style="font-family: sans-serif">ſ</span>” (U+017F) to “s”. Such
+ characters are not mapped if <i>Unicode</i> is <b>false</b>. This prevents Unicode code points such as U+0131 and
+ U+017F from matching regular expressions such as <code>/[a‑z]/i</code>, but they will match
+ <code>/[a‑z]/ui</code>.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-atomescape">
+ <h1><span class="secnum" id="sec-21.2.2.9"><a href="#sec-atomescape" title="link to this section">21.2.2.9</a></span>
+ AtomEscape</h1>
+
+ <p>The production <span class="prod"><span class="nt">AtomEscape</span> <span class="geq">::</span> <span
+ class="nt">DecimalEscape</span></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Evaluate <i>DecimalEscape</i> to obtain an EscapeValue <i>E</i>.</li>
+ <li>If <i>E</i> is a character, then
+ <ol class="block">
+ <li>Let <i>ch</i> be <i>E</i>'s character.</li>
+ <li>Let <i>A</i> be a one-element CharSet containing the character <i>ch</i>.</li>
+ <li>Call CharacterSetMatcher(<i>A</i>, <b>false</b>) and return its Matcher result.</li>
+ </ol>
+ </li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>E</i> must be an integer.</li>
+ <li>Let <i>n</i> be that integer.</li>
+ <li>If <i>n</i>=0 or <i>n</i>><i>NcapturingParens</i> then throw a <b>SyntaxError</b> exception.</li>
+ <li>Return an internal Matcher closure that takes two arguments, a State <i>x</i> and a Continuation <i>c</i>, and
+ performs the following steps:
+ <ol class="nested proc">
+ <li>Let <i>cap</i> be <i>x</i>'s <i>captures</i> <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Let <i>s</i> be <i>cap</i>[<i>n</i>].</li>
+ <li>If <i>s</i> is <b>undefined</b>, then call <i>c</i>(<i>x</i>) and return its result.</li>
+ <li>Let <i>e</i> be <i>x</i>'s <i>endIndex</i>.</li>
+ <li>Let <i>len</i> be <i>s</i>'s length.</li>
+ <li>Let <i>f</i> be <i>e</i>+<i>len</i>.</li>
+ <li>If <i>f</i>><i>InputLength</i>, return <b>failure</b>.</li>
+ <li>If there exists an integer <i>i</i> between 0 (inclusive) and <i>len</i> (exclusive) such that
+ Canonicalize(<i>s</i>[<i>i</i>]) is not the same character value as Canonicalize(<i>Input</i>
+ [<i>e</i>+<i>i</i>]), then return <b>failure</b>.</li>
+ <li>Let <i>y</i> be the State (<i>f</i>, <i>cap</i>).</li>
+ <li>Call <i>c</i>(<i>y</i>) and return its result.</li>
+ </ol>
+ </li>
+ </ol>
+
+ <p>The production <span class="prod"><span class="nt">AtomEscape</span> <span class="geq">::</span> <span
+ class="nt">CharacterEscape</span></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Evaluate <i>CharacterEscape</i> to obtain a character <i>ch</i>.</li>
+ <li>Let <i>A</i> be a one-element CharSet containing the character <i>ch</i>.</li>
+ <li>Call CharacterSetMatcher(<i>A</i>, <b>false</b>) and return its Matcher result.</li>
+ </ol>
+
+ <p>The production <span class="prod"><span class="nt">AtomEscape</span> <span class="geq">::</span> <span
+ class="nt">CharacterClassEscape</span></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Evaluate <i>CharacterClassEscape</i> to obtain a CharSet <i>A</i>.</li>
+ <li>Call CharacterSetMatcher(<i>A</i>, <b>false</b>) and return its Matcher result.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> An escape sequence of the form <code>\</code> followed by a nonzero decimal number
+ <i>n</i> matches the result of the <i>n</i>th set of capturing parentheses (<a href="#sec-decimalescape">see
+ 21.2.2.11</a>). It is an error if the regular expression has fewer than <i>n</i> capturing parentheses. If the regular
+ expression has <i>n</i> or more capturing parentheses but the <i>n</i>th one is <b>undefined</b> because it has not
+ captured anything, then the backreference always succeeds.</p>
+ </div>
+ </section>
+
+ <section id="sec-characterescape">
+ <h1><span class="secnum" id="sec-21.2.2.10"><a href="#sec-characterescape"
+ title="link to this section">21.2.2.10</a></span> CharacterEscape</h1>
+
+ <p>The production <span class="prod"><span class="nt">CharacterEscape</span> <span class="geq">::</span> <span
+ class="nt">ControlEscape</span></span> evaluates by returning the character according to <a href="#table-42">Table
+ 42</a>.</p>
+
+ <figure>
+ <figcaption><span id="table-42">Table 42</span> — ControlEscape Character Values</figcaption>
+ <table class="real-table">
+ <tr>
+ <th>ControlEscape</th>
+ <th>Character Value</th>
+ <th>Code Point</th>
+ <th>Name</th>
+ <th>Symbol</th>
+ </tr>
+ <tr>
+ <td><code>t</code></td>
+ <td>9</td>
+ <td><code>U+0009</code></td>
+ <td>horizontal tab</td>
+ <td><HT></td>
+ </tr>
+ <tr>
+ <td><code>n</code></td>
+ <td>10</td>
+ <td><code>U+000A</code></td>
+ <td>line feed (new line)</td>
+ <td><LF></td>
+ </tr>
+ <tr>
+ <td><code>v</code></td>
+ <td>11</td>
+ <td><code>U+000B</code></td>
+ <td>vertical tab</td>
+ <td><VT></td>
+ </tr>
+ <tr>
+ <td><code>f</code></td>
+ <td>12</td>
+ <td><code>U+000C</code></td>
+ <td>form feed</td>
+ <td><FF></td>
+ </tr>
+ <tr>
+ <td><code>r</code></td>
+ <td>13</td>
+ <td><code>U+000D</code></td>
+ <td>carriage return</td>
+ <td><CR></td>
+ </tr>
+ </table>
+ </figure>
+
+ <p>The production <span class="prod"><span class="nt">CharacterEscape</span> <span class="geq">::</span> <code
+ class="t">c</code> <span class="nt">ControlLetter</span></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Let <i>ch</i> be the character matched by <i>ControlLetter</i>.</li>
+ <li>Let <i>i</i> be <i>ch</i>'s character value.</li>
+ <li>Let <i>j</i> be the remainder of dividing <i>i</i> by 32.</li>
+ <li>Return the character whose character value is <i>j</i>.</li>
+ </ol>
+
+ <p>The production <span class="prod"><span class="nt">CharacterEscape</span> <span class="geq">::</span> <span
+ class="nt">HexEscapeSequence</span></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Return the character whose code is the CV of <i>HexEscapeSequence</i>.</li>
+ </ol>
+
+ <p>The production <span class="prod"><span class="nt">CharacterEscape</span> <span class="geq">::</span> <span
+ class="nt">RegExpUnicodeEscapeSequence</span></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Return the result of evaluating <i>RegExpUnicodeEscapeSequence</i>.</li>
+ </ol>
+
+ <p>The production <span class="prod"><span class="nt">CharacterEscape</span> <span class="geq">::</span> <span
+ class="nt">IdentityEscape</span></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Return the character matched by <i>IdentityEscape</i>.</li>
+ </ol>
+
+ <p>The production <span class="prod"><span class="nt">RegExpUnicodeEscapeSequence</span> <span class="geq">::</span> <code
+ class="t">u</code> <span class="nt">LeadSurrogate</span> <code class="t">\u</code> <span
+ class="nt">TrailSurrogate</span></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Let <i>lead</i> be the result of evaluating <i>LeadSurrogate</i>.</li>
+ <li>Let <i>trail</i> be the result of evaluating <i>TrailSurrogate</i>.</li>
+ <li>Let <i>cp</i> be <a href="#sec-utf16decode">UTF16Decode</a>(<i>lead</i>, <i>trail</i>).</li>
+ <li>Return the character whose character value is <i>cp</i>.</li>
+ </ol>
+
+ <p>The production <span class="prod"><span class="nt">RegExpUnicodeEscapeSequence</span> <span class="geq">::</span> <code
+ class="t">u</code> <span class="nt">Hex4Digits</span></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Return the character whose code is the CV of <i>Hex4Digits</i>.</li>
+ </ol>
+
+ <p>The production <span class="prod"><span class="nt">RegExpUnicodeEscapeSequence</span> <span class="geq">::</span> <code
+ class="t">u{</code> <span class="nt">HexDigits</span> <code class="t">}</code></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Return the character whose code is the MV of <i>HexDigits</i>.</li>
+ </ol>
+
+ <p>The production <span class="prod"><span class="nt">LeadSurrogate</span> <span class="geq">::</span> <span
+ class="nt">Hex4Digits</span></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Return the character whose code is the CV of <i>Hex4Digits</i>.</li>
+ </ol>
+
+ <p>The production <span class="prod"><span class="nt">TrailSurrogate</span> <span class="geq">::</span> <span
+ class="nt">Hex4Digits</span></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Return the character whose code is the CV of <i>Hex4Digits</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-decimalescape">
+ <h1><span class="secnum" id="sec-21.2.2.11"><a href="#sec-decimalescape" title="link to this section">21.2.2.11</a></span>
+ DecimalEscape</h1>
+
+ <p>The production <span class="prod"><span class="nt">DecimalEscape</span> <span class="geq">::</span> <span
+ class="nt">DecimalIntegerLiteral</span></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Let <i>i</i> be the MV of <i>DecimalIntegerLiteral</i>.</li>
+ <li>If <i>i</i> is zero, return the EscapeValue consisting of the character U+0000 (NULL).</li>
+ <li>Return the EscapeValue consisting of the integer <i>i</i>.</li>
+ </ol>
+
+ <p>The definition of “the MV of <span class="nt">DecimalIntegerLiteral</span>” is in <a
+ href="#sec-literals-numeric-literals">11.8.3</a>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> If <code>\</code> is followed by a decimal number <i>n</i> whose first digit is not
+ <code>0</code>, then the escape sequence is considered to be a backreference. It is an error if <i>n</i> is greater than
+ the total number of left capturing parentheses in the entire regular expression. <code>\0</code> represents the
+ <NUL> character and cannot be followed by a decimal digit.</p>
+ </div>
+ </section>
+
+ <section id="sec-characterclassescape">
+ <h1><span class="secnum" id="sec-21.2.2.12"><a href="#sec-characterclassescape"
+ title="link to this section">21.2.2.12</a></span> CharacterClassEscape</h1>
+
+ <p>The production <span class="prod"><span class="nt">CharacterClassEscape</span> <span class="geq">::</span> <code
+ class="t">d</code></span> evaluates by returning the ten-element set of characters containing the characters
+ <code>0</code> through <code>9</code> inclusive.</p>
+
+ <p>The production <span class="prod"><span class="nt">CharacterClassEscape</span> <span class="geq">::</span> <code
+ class="t">D</code></span> evaluates by returning the set of all characters not included in the set returned by <span
+ class="prod"><span class="nt">CharacterClassEscape</span> <span class="geq">::</span> <code class="t">d</code></span>
+ .</p>
+
+ <p>The production <span class="prod"><span class="nt">CharacterClassEscape</span> <span class="geq">::</span> <code
+ class="t">s</code></span> evaluates by returning the set of characters containing the characters that are on the
+ right-hand side of the <span class="nt">WhiteSpace</span> (<a href="#sec-white-space">11.2</a>) or <span
+ class="nt">LineTerminator</span> (<a href="#sec-line-terminators">11.3</a>) productions.</p>
+
+ <p>The production <span class="prod"><span class="nt">CharacterClassEscape</span> <span class="geq">::</span> <code
+ class="t">S</code></span> evaluates by returning the set of all characters not included in the set returned by <span
+ class="prod"><span class="nt">CharacterClassEscape</span> <span class="geq">::</span> <code class="t">s</code></span>
+ .</p>
+
+ <p>The production <span class="prod"><span class="nt">CharacterClassEscape</span> <span class="geq">::</span> <code
+ class="t">w</code></span> evaluates by returning the set of characters containing the sixty-three characters:</p>
+
+ <figure>
+ <table class="lightweight-table">
+ <tr>
+ <td><code>a</code></td>
+ <td><code>b</code></td>
+ <td><code>c</code></td>
+ <td><code>d</code></td>
+ <td><code>e</code></td>
+ <td><code>f</code></td>
+ <td><code>g</code></td>
+ <td><code>h</code></td>
+ <td><code>i</code></td>
+ <td><code>j</code></td>
+ <td><code>k</code></td>
+ <td><code>l</code></td>
+ <td><code>m</code></td>
+ <td><code>n</code></td>
+ <td><code>o</code></td>
+ <td><code>p</code></td>
+ <td><code>q</code></td>
+ <td><code>r</code></td>
+ <td><code>s</code></td>
+ <td><code>t</code></td>
+ <td><code>u</code></td>
+ <td><code>v</code></td>
+ <td><code>w</code></td>
+ <td><code>x</code></td>
+ <td><code>y</code></td>
+ <td><code>z</code></td>
+ </tr>
+ <tr>
+ <td><code>A</code></td>
+ <td><code>B</code></td>
+ <td><code>C</code></td>
+ <td><code>D</code></td>
+ <td><code>E</code></td>
+ <td><code>F</code></td>
+ <td><code>G</code></td>
+ <td><code>H</code></td>
+ <td><code>I</code></td>
+ <td><code>J</code></td>
+ <td><code>K</code></td>
+ <td><code>L</code></td>
+ <td><code>M</code></td>
+ <td><code>N</code></td>
+ <td><code>O</code></td>
+ <td><code>P</code></td>
+ <td><code>Q</code></td>
+ <td><code>R</code></td>
+ <td><code>S</code></td>
+ <td><code>T</code></td>
+ <td><code>U</code></td>
+ <td><code>V</code></td>
+ <td><code>W</code></td>
+ <td><code>X</code></td>
+ <td><code>Y</code></td>
+ <td><code>Z</code></td>
+ </tr>
+ <tr>
+ <td><code>0</code></td>
+ <td><code>1</code></td>
+ <td><code>2</code></td>
+ <td><code>3</code></td>
+ <td><code>4</code></td>
+ <td><code>5</code></td>
+ <td><code>6</code></td>
+ <td><code>7</code></td>
+ <td><code>8</code></td>
+ <td><code>9</code></td>
+ <td><code>_</code></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ </tr>
+ </table>
+ </figure>
+
+ <p>The production <span class="prod"><span class="nt">CharacterClassEscape</span> <span class="geq">::</span> <code
+ class="t">W</code></span> evaluates by returning the set of all characters not included in the set returned by <span
+ class="prod"><span class="nt">CharacterClassEscape</span> <span class="geq">::</span> <code class="t">w</code></span>
+ .</p>
+ </section>
+
+ <section id="sec-characterclass">
+ <h1><span class="secnum" id="sec-21.2.2.13"><a href="#sec-characterclass"
+ title="link to this section">21.2.2.13</a></span> CharacterClass</h1>
+
+ <p>The production <span class="prod"><span class="nt">CharacterClass</span> <span class="geq">::</span> <code
+ class="t">[</code> <span class="nt">ClassRanges</span> <code class="t">]</code></span> evaluates by evaluating <span
+ class="nt">ClassRanges</span> to obtain a CharSet and returning that CharSet and the Boolean <b>false</b>.</p>
+
+ <p>The production <span class="prod"><span class="nt">CharacterClass</span> <span class="geq">::</span> <code
+ class="t">[</code> <code class="t">^</code> <span class="nt">ClassRanges</span> <code class="t">]</code></span> evaluates
+ by evaluating <span class="nt">ClassRanges</span> to obtain a CharSet and returning that CharSet and the Boolean
+ <b>true</b>.</p>
+ </section>
+
+ <section id="sec-classranges">
+ <h1><span class="secnum" id="sec-21.2.2.14"><a href="#sec-classranges" title="link to this section">21.2.2.14</a></span>
+ ClassRanges</h1>
+
+ <p>The production <span class="prod"><span class="nt">ClassRanges</span> <span class="geq">::</span> <span
+ class="grhsannot">[empty]</span></span> evaluates by returning the empty CharSet.</p>
+
+ <p>The production <span class="prod"><span class="nt">ClassRanges</span> <span class="geq">::</span> <span
+ class="nt">NonemptyClassRanges</span></span> evaluates by evaluating <span class="nt">NonemptyClassRanges</span> to obtain
+ a CharSet and returning that CharSet.</p>
+ </section>
+
+ <section id="sec-nonemptyclassranges">
+ <div class="front">
+ <h1><span class="secnum" id="sec-21.2.2.15"><a href="#sec-nonemptyclassranges"
+ title="link to this section">21.2.2.15</a></span> NonemptyClassRanges</h1>
+
+ <p>The production <span class="prod"><span class="nt">NonemptyClassRanges</span> <span class="geq">::</span> <span
+ class="nt">ClassAtom</span></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Return the CharSet that is the result of evaluating <i>ClassAtom</i>.</li>
+ </ol>
+
+ <p>The production <span class="prod"><span class="nt">NonemptyClassRanges</span> <span class="geq">::</span> <span
+ class="nt">ClassAtom</span> <span class="nt">NonemptyClassRangesNoDash</span></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Evaluate <i>ClassAtom</i> to obtain a CharSet <i>A</i>.</li>
+ <li>Evaluate <i>NonemptyClassRangesNoDash</i> to obtain a CharSet <i>B</i>.</li>
+ <li>Return the union of CharSets <i>A</i> and <i>B</i>.</li>
+ </ol>
+
+ <p>The production <span class="prod"><span class="nt">NonemptyClassRanges</span> <span class="geq">::</span> <span
+ class="nt">ClassAtom</span> <code class="t">-</code> <span class="nt">ClassAtom</span> <span
+ class="nt">ClassRanges</span></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Evaluate the first <i>ClassAtom</i> to obtain a CharSet <i>A</i>.</li>
+ <li>Evaluate the second <i>ClassAtom</i> to obtain a CharSet <i>B</i>.</li>
+ <li>Evaluate <i>ClassRanges</i> to obtain a CharSet <i>C</i>.</li>
+ <li>Call CharacterRange(<i>A</i>, <i>B</i>) and let <i>D</i> be the resulting CharSet.</li>
+ <li>Return the union of CharSets <i>D</i> and <i>C</i>.</li>
+ </ol>
+ </div>
+
+ <section id="sec-runtime-semantics-characterrange-abstract-operation">
+ <h1><span class="secnum" id="sec-21.2.2.15.1"><a href="#sec-runtime-semantics-characterrange-abstract-operation"
+ title="link to this section">21.2.2.15.1</a></span> Runtime Semantics: CharacterRange Abstract Operation</h1>
+
+ <p>The abstract operation CharacterRange takes two CharSet parameters <var>A</var> and <var>B</var> and performs the
+ following:</p>
+
+ <ol class="proc">
+ <li>If <i>A</i> does not contain exactly one character or <i>B</i> does not contain exactly one character then throw a
+ <b>SyntaxError</b> exception.</li>
+ <li>Let <i>a</i> be the one character in CharSet <i>A</i>.</li>
+ <li>Let <i>b</i> be the one character in CharSet <i>B</i>.</li>
+ <li>Let <i>i</i> be the character value of character <i>a</i>.</li>
+ <li>Let <i>j</i> be the character value of character <i>b</i>.</li>
+ <li>If <i>i</i> > <i>j</i> then throw a <b>SyntaxError</b> exception.</li>
+ <li>Return the set containing all characters numbered <i>i</i> through <i>j</i>, inclusive.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-nonemptyclassrangesnodash">
+ <h1><span class="secnum" id="sec-21.2.2.16"><a href="#sec-nonemptyclassrangesnodash"
+ title="link to this section">21.2.2.16</a></span> NonemptyClassRangesNoDash</h1>
+
+ <p>The production <span class="prod"><span class="nt">NonemptyClassRangesNoDash</span> <span class="geq">::</span> <span
+ class="nt">ClassAtom</span></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Return the CharSet that is the result of evaluating <i>ClassAtom</i>.</li>
+ </ol>
+
+ <p>The production <span class="prod"><span class="nt">NonemptyClassRangesNoDash</span> <span class="geq">::</span> <span
+ class="nt">ClassAtomNoDash</span> <span class="nt">NonemptyClassRangesNoDash</span></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Evaluate <i>ClassAtomNoDash</i> to obtain a CharSet <i>A</i>.</li>
+ <li>Evaluate <i>NonemptyClassRangesNoDash</i> to obtain a CharSet <i>B</i>.</li>
+ <li>Return the union of CharSets <i>A</i> and <i>B</i>.</li>
+ </ol>
+
+ <p>The production <span class="prod"><span class="nt">NonemptyClassRangesNoDash</span> <span class="geq">::</span> <span
+ class="nt">ClassAtomNoDash</span> <code class="t">-</code> <span class="nt">ClassAtom</span> <span
+ class="nt">ClassRanges</span></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Evaluate <i>ClassAtomNoDash</i> to obtain a CharSet <i>A</i>.</li>
+ <li>Evaluate <i>ClassAtom</i> to obtain a CharSet <i>B</i>.</li>
+ <li>Evaluate <i>ClassRanges</i> to obtain a CharSet <i>C</i>.</li>
+ <li>Call CharacterRange(<i>A</i>, <i>B</i>) and let <i>D</i> be the resulting CharSet.</li>
+ <li>Return the union of CharSets <i>D</i> and <i>C</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> <i>ClassRanges</i> can expand into single <i>ClassAtoms</i> and/or ranges of two
+ <i>ClassAtoms</i> separated by dashes. In the latter case the <i>ClassRanges</i> includes all characters between the
+ first <i>ClassAtom</i> and the second <i>ClassAtom</i>, inclusive; an error occurs if either <i>ClassAtom</i> does not
+ represent a single character (for example, if one is <code>\w</code>) or if the first <i>ClassAtom's</i> character value
+ is greater than the second <i>ClassAtom's</i> character value.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 2</span> Even if the pattern ignores case, the case of the two ends of a range is significant
+ in determining which characters belong to the range. Thus, for example, the pattern <code>/[E-F]/i</code> matches only
+ the letters <code>E</code>, <code>F</code>, <code>e</code>, and <code>f</code>, while the pattern <code>/[E-f]/i</code>
+ matches all upper and lower-case letters in the Unicode Basic Latin block as well as the symbols <code>[</code>,
+ <code>\</code>, <code>]</code>, <code>^</code>, <code>_</code>, and <code>`</code>.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 3</span> A <code>-</code> character can be treated literally or it can denote a range. It is
+ treated literally if it is the first or last character of <span class="nt">ClassRanges</span>, the beginning or end
+ limit of a range specification, or immediately follows a range specification.</p>
+ </div>
+ </section>
+
+ <section id="sec-classatom">
+ <h1><span class="secnum" id="sec-21.2.2.17"><a href="#sec-classatom" title="link to this section">21.2.2.17</a></span>
+ ClassAtom</h1>
+
+ <p>The production <span class="prod"><span class="nt">ClassAtom</span> <span class="geq">::</span> <code
+ class="t">-</code></span> evaluates by returning the CharSet containing the one character <code>-</code>.</p>
+
+ <p>The production <span class="prod"><span class="nt">ClassAtom</span> <span class="geq">::</span> <span
+ class="nt">ClassAtomNoDash</span></span> evaluates by evaluating <span class="nt">ClassAtomNoDash</span> to obtain a
+ CharSet and returning that CharSet.</p>
+ </section>
+
+ <section id="sec-classatomnodash">
+ <h1><span class="secnum" id="sec-21.2.2.18"><a href="#sec-classatomnodash"
+ title="link to this section">21.2.2.18</a></span> ClassAtomNoDash</h1>
+
+ <p>The production <span class="prod"><span class="nt">ClassAtomNoDash</span> <span class="geq">::</span> <span
+ class="nt">SourceCharacter</span> <span class="grhsmod">but not one of</span> <code class="t">\</code> <span
+ class="grhsmod">or</span> <code class="t">]</code> <span class="grhsmod">or</span> <code class="t">-</code></span>
+ evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Return the CharSet containing the character matched by <i>SourceCharacter</i>.</li>
+ </ol>
+
+ <p>The production <span class="prod"><span class="nt">ClassAtomNoDash</span> <span class="geq">::</span> <code
+ class="t">\</code> <span class="nt">ClassEscape</span></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Return the CharSet that is the result of evaluating <i>ClassEscape</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-classescape">
+ <h1><span class="secnum" id="sec-21.2.2.19"><a href="#sec-classescape" title="link to this section">21.2.2.19</a></span>
+ ClassEscape</h1>
+
+ <p>The production <span class="prod"><span class="nt">ClassEscape</span> <span class="geq">::</span> <span
+ class="nt">DecimalEscape</span></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Evaluate <i>DecimalEscape</i> to obtain an EscapeValue <i>E</i>.</li>
+ <li>If <i>E</i> is not a character then throw a <b>SyntaxError</b> exception.</li>
+ <li>Let <i>ch</i> be <i>E</i>'s character.</li>
+ <li>Return the one-element CharSet containing the character <i>ch</i>.</li>
+ </ol>
+
+ <p>The production <span class="prod"><span class="nt">ClassEscape</span> <span class="geq">::</span> <code
+ class="t">b</code></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Return the CharSet containing the single character <BS> U+0008 (BACKSPACE).</li>
+ </ol>
+
+ <p>The production <span class="prod"><span class="nt">ClassEscape</span> <span class="geq">::</span> <span
+ class="nt">CharacterEscape</span></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Return the CharSet containing the single character that is the result of evaluating <i>CharacterEscape</i>.</li>
+ </ol>
+
+ <p>The production <span class="prod"><span class="nt">ClassEscape</span> <span class="geq">::</span> <span
+ class="nt">CharacterClassEscape</span></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Return the CharSet that is the result of evaluating <i>CharacterClassEscape</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> A <i>ClassAtom</i> can use any of the escape sequences that are allowed in the rest of
+ the regular expression except for <code>\b</code>, <code>\B</code>, and backreferences. Inside a <i>CharacterClass</i>,
+ <code>\b</code> means the backspace character, while <code>\B</code> and backreferences raise errors. Using a
+ backreference inside a <i>ClassAtom</i> causes an error.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-regexp-constructor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-21.2.3"><a href="#sec-regexp-constructor" title="link to this section">21.2.3</a></span>
+ The RegExp Constructor</h1>
+
+ <p>The RegExp constructor is the %RegExp% intrinsic object and the initial value of the <code>RegExp</code> property of
+ the global object. When <code>RegExp</code> is called as a function rather than as a constructor, it creates and
+ initializes a new RegExp object. Thus the function call <code><b>RegExp(</b>…<b>)</b></code> is equivalent to the
+ object creation expression <code><b>new RegExp(</b>…<b>)</b></code> with the same arguments. However, if the
+ <b>this</b> value passed in the call is an Object with a [[RegExpMatcher]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> whose value is <span
+ class="value">undefined</span>, it initializes the <b>this</b> value using the argument values. This permits
+ <code>RegExp</code> to be used both as factory method and to perform constructor instance initialization.</p>
+
+ <p>The <code>RegExp</code> constructor is designed to be subclassable. It may be used as the value of an
+ <code>extends</code> clause of a class declaration. Subclass constructors that intended to inherit the specified
+ <code>RegExp</code> behaviour must include a <code>super</code> call to the <code>RegExp</code> constructor to initialize
+ subclass instances.</p>
+ </div>
+
+ <section id="sec-regexp-pattern-flags">
+ <h1><span class="secnum" id="sec-21.2.3.1"><a href="#sec-regexp-pattern-flags"
+ title="link to this section">21.2.3.1</a></span> RegExp ( pattern, flags )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>func</i> be this <code>RegExp</code> function object.</li>
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object or <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is Object and <i>O</i> does not have a
+ [[RegExpMatcher]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> or <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is Object and <i>O</i> has a [[RegExpMatcher]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> and the value of [[RegExpMatcher]] is not
+ <b>undefined</b>, then
+ <ol class="block">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>pattern</i>) is Object and <i>O</i> has a
+ [[RegExpMatcher]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> and <i>flags</i>
+ is <b>undefined</b>, then
+ <ol class="block">
+ <li>Return <i>pattern</i>;</li>
+ </ol>
+ </li>
+ <li>Let <i>O</i> be the result of calling the abstract operation <a href="#sec-regexpalloc">RegExpAlloc</a> with
+ argument <i>func</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>O</i>).</li>
+ </ol>
+ </li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>pattern</i>) is Object and <i>pattern</i> has a
+ [[RegExpMatcher]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, then
+ <ol class="block">
+ <li>If the value of <i>pattern’s</i> [[RegExpMatcher]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is <b>undefined</b>, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>If <i>flags</i> is not <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>P</i> be the value of <i>pattern’s</i> [[OriginalSource]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>F</i> be the value of <i>pattern’s</i> [[OriginalFlags]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>P</i> be <i>pattern</i>.</li>
+ <li>Let <i>F</i> be <i>flags</i>.</li>
+ </ol>
+ </li>
+ <li>Return the result of the abstract operation <a href="#sec-regexpinitialize">RegExpInitialize</a> with arguments
+ <i>O,</i> <i>P</i>, and <i>F</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> If pattern is supplied using a <i>StringLiteral</i>, the usual escape sequence
+ substitutions are performed before the String is processed by RegExp. If pattern must contain an escape sequence to be
+ recognized by RegExp, any backslash <code>\</code> characters must be escaped within the <i>StringLiteral</i> to prevent
+ them being removed when the contents of the <i>StringLiteral</i> are formed.</p>
+ </div>
+ </section>
+
+ <section id="sec-new-regexp-argumentslist">
+ <h1><span class="secnum" id="sec-21.2.3.2"><a href="#sec-new-regexp-argumentslist"
+ title="link to this section">21.2.3.2</a></span> new RegExp( ...argumentsList )</h1>
+
+ <p>When <code>RegExp</code> is called as part of a new expression with argument list <var>argumentsList</var> it performs
+ the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be the <code>RegExp</code> function object on which the <code>new</code> operator was applied.</li>
+ <li>Let <i>argumentsList</i> be the <i>argumentsList</i> argument of the [[Construct]] internal method that was invoked
+ by the <code>new</code> operator.</li>
+ <li>Return the result of <a href="#sec-construct-f-argumentslist">Construct</a> (<i>F</i>, <i>argumentsList</i>).</li>
+ </ol>
+
+ <p>If <code>RegExp</code> is implemented as an <a href="#sec-ecmascript-function-objects">ECMAScript function object</a>,
+ its [[Construct]] internal method will perform the above steps.</p>
+ </section>
+
+ <section id="sec-abstract-operations-for-the-regexp-constructor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-21.2.3.3"><a href="#sec-abstract-operations-for-the-regexp-constructor"
+ title="link to this section">21.2.3.3</a></span> Abstract Operations for the RegExp Constructor</h1>
+ </div>
+
+ <section id="sec-regexpalloc">
+ <h1><span class="secnum" id="sec-21.2.3.3.1"><a href="#sec-regexpalloc"
+ title="link to this section">21.2.3.3.1</a></span> Runtime Semantics: RegExpAlloc Abstract Operation</h1>
+
+ <p>When the abstract operation RegExpAlloc with argument <var>constructor</var> is called, the following steps are
+ taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>obj</i> be the result of calling <a
+ href="#sec-ordinarycreatefromconstructor">OrdinaryCreateFromConstructor</a>(<i>constructor</i>,
+ <code>"%RegExpPrototype%"</code>, ( [[RegExpMatcher]], [[OriginalSource]], [[OriginalFlags]])).</li>
+ <li>Let <i>status</i> be the result of <a href="#sec-definepropertyorthrow">DefinePropertyOrThrow</a>(<i>obj</i>,
+ <code>"lastIndex"</code>, PropertyDescriptor {[[Writable]]: <b>true</b>, [[Enumberable]]: <b>false</b>,
+ [[Configurable]]: <b>false</b>}).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Return <i>obj</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> [[RegExpMatcher]] is initially assigned the value <b>undefined</b> as a flag to
+ indicate that the instance has not yet been initialized by the <b>RegExp</b> constructor. This flag value is never
+ directly exposed to ECMAScript code; hence implementations may choose to encode the flag in some other manner.</p>
+ </div>
+ </section>
+
+ <section id="sec-regexpinitialize">
+ <h1><span class="secnum" id="sec-21.2.3.3.2"><a href="#sec-regexpinitialize"
+ title="link to this section">21.2.3.3.2</a></span> Runtime Semantics: RegExpInitialize Abstract Operation</h1>
+
+ <p>When the abstract operation RegExpInitialize with arguments <i><span style="font-family: Times New
+ Roman">obj</span>,</i> <var>pattern</var>, and <var>flags</var> is called, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>If <i>pattern</i> is <b>undefined</b>, then let <i>P</i> be the empty String.</li>
+ <li>Else, let <i>P</i> be <a href="#sec-tostring">ToString</a>(<i>pattern</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>P</i>).</li>
+ <li>If <i>flags</i> is <b>undefined</b>, then let <i>F</i> be the empty String.</li>
+ <li>Else, let <i>F</i> be <a href="#sec-tostring">ToString</a>(<i>flags</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>F</i>).</li>
+ <li>If <i>F</i> contains any character other than <code>"g"</code>, <code>"i"</code>, <code>"m"</code>,
+ <code>"u"</code>, or <code>"y"</code> or if it contains the same character more than once, then throw a
+ <b>SyntaxError</b> exception.</li>
+ <li>If <i>F</i> contains <code>"u"</code> then let <i>BMP</i> be <b>false</b>, else let <i>BMP</i> be
+ <b>true</b>.</li>
+ <li>If <i>BMP</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Parse <i>P</i> interpreted as UTF-16 encoded Unicode code points using the grammars in <a
+ href="#sec-patterns">21.2.1</a>. The goal symbol for the parse is <i>Pattern</i>.Throw a <b>SyntaxError</b>
+ exception if <i>P</i> did not conform to the grammar or if any characters of <i>P</i> where not matched by the
+ parse.</li>
+ <li>Let <i>patternCharacters</i> be a <a href="#sec-list-and-record-specification-type">List</a> whose elements
+ are the code unit elements of <i>P.</i></li>
+ </ol>
+ </li>
+ <li>Else
+ <ol class="block">
+ <li>Parse <i>P</i> interpreted as UTF-16 encoded Unicode code points using the grammars in <a
+ href="#sec-patterns">21.2.1</a>. The goal symbol for the parse is <i>Pattern</i><sub>[U]</sub>. Throw a
+ <b>SyntaxError</b> exception if <i>P</i> did not conform to the grammar or if any characters of <i>P</i> where
+ not matched by the parse.</li>
+ <li>Let <i>patternCharacters</i> be a <a href="#sec-list-and-record-specification-type">List</a> whose elements
+ are the code points of <i>P</i> interpreted as sequence of UTF-16 encoded Unicode code points<i>.</i></li>
+ </ol>
+ </li>
+ <li>Set the value of <i>obj’s</i> [[OriginalSource]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to <i>P</i>.</li>
+ <li>Set the value of <i>obj’s</i> [[OriginalFlags]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to <i>F</i>.</li>
+ <li>Set <i>obj’s</i> [[RegExpMatcher]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> to the internal procedure that evaluates the above parse of <i>P</i> by applying the semantics provided
+ in <a href="#sec-pattern-semantics">21.2.2</a> using <i>patternCharacters</i> as the pattern’s <a
+ href="#sec-list-and-record-specification-type">List</a> of <i>SourceCharacter</i> values and <i>F</i> as the flag
+ parameters.</li>
+ <li>Let <i>putStatus</i> be the result of <a href="#sec-put-o-p-v-throw">Put</a>(<i>obj</i>, <code>"lastIndex"</code>,
+ 0, <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>putStatus</i>).</li>
+ <li>Return <i>obj</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-regexpcreate">
+ <h1><span class="secnum" id="sec-21.2.3.3.3"><a href="#sec-regexpcreate"
+ title="link to this section">21.2.3.3.3</a></span> Runtime Semantics: RegExpCreate Abstract Operation</h1>
+
+ <p>When the abstract operation RegExpCreate with arguments <var>P</var> and <var>F</var> is called, the following steps
+ are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>obj</i> be the result of calling the abstract operation <a href="#sec-regexpalloc">RegExpAlloc</a> with
+ argument <span style="font-family: sans-serif">%RegExp%</span>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>obj</i>).</li>
+ <li>Return the result of the abstract operation <a href="#sec-regexpinitialize">RegExpInitialize</a> with arguments
+ <i>obj,</i> <i>P</i>, and <i>F</i> .</li>
+ </ol>
+ </section>
+
+ <section id="sec-escaperegexppattern">
+ <h1><span class="secnum" id="sec-21.2.3.3.4"><a href="#sec-escaperegexppattern"
+ title="link to this section">21.2.3.3.4</a></span> Runtime Semantics: EscapeRegExpPattern Abstract Operation</h1>
+
+ <p>When the abstract operation EscapeRegExpPattern with arguments <var>P</var> and <var>F</var> is called, the following
+ occurs:</p>
+
+ <p>Let <var>S</var> be a String in the form of a <span class="nt">Pattern</span> (<span
+ class="nt">Pattern</span><sub>[U]</sub> if <var>F</var> contains <code>"u"</code>) equivalent to <var>P</var>
+ interpreted as UTF-16 encoded Unicode code points, in which certain code points are escaped as described below.
+ <var>S</var> may or may not be identical to <var>P</var>; however, the internal procedure that would result from
+ evaluating <var>S</var> as a <span class="nt">Pattern</span> (<span class="nt">Pattern</span><sub>[U]</sub> if
+ <var>F</var> contains <code>"u"</code>) must behave identically to the internal procedure given by the constructed
+ object's [[RegExpMatcher]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>. Separate calls
+ to this abstract operation using the same values for <var>P</var> and <var>F</var> must produce identical results.</p>
+
+ <p>The characters <code>/</code> or any <span class="nt">LineTerminator</span> occurring in the pattern shall be escaped
+ in <var>S</var> as necessary to ensure that the String value formed by concatenating the Strings <code>"/"</code>,
+ <var>S</var>, <code>"/"</code>, and <var>F</var> can be parsed (in an appropriate lexical context) as a <span
+ class="nt">RegularExpressionLiteral</span> that behaves identically to the constructed regular expression. For example,
+ if <var>P</var> is <code>"/"</code>, then <var>S</var> could be <code>"\/"</code> or <code>"\u002F"</code>, among other
+ possibilities, but not <code>"/"</code>, because <code>///</code> followed by <var>F</var> would be parsed as a <span
+ class="nt">SingleLineComment</span> rather than a <span class="nt">RegularExpressionLiteral</span>. If <var>P</var> is
+ the empty String, this specification can be met by letting <var>S</var> be <code>"(?:)"</code>.</p>
+
+ <p>Return <var>S</var>.</p>
+ </section>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-regexp-constructor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-21.2.4"><a href="#sec-properties-of-the-regexp-constructor"
+ title="link to this section">21.2.4</a></span> Properties of the RegExp Constructor</h1>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the
+ RegExp constructor is the standard built-in Function prototype object (<a
+ href="#sec-properties-of-the-function-prototype-object">19.2.3</a>).</p>
+
+ <p>Besides the <code>length</code> property (whose value is <b>2</b>), the RegExp constructor has the following
+ properties:</p>
+ </div>
+
+ <section id="sec-regexp.prototype">
+ <h1><span class="secnum" id="sec-21.2.4.1"><a href="#sec-regexp.prototype"
+ title="link to this section">21.2.4.1</a></span> RegExp.prototype</h1>
+
+ <p>The initial value of <code>RegExp.prototype</code> is the RegExp prototype object (<a
+ href="#sec-properties-of-the-regexp-prototype-object">21.2.5</a>).</p>
+
+ <p>This property shall have the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>,
+ [[Configurable]]: <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-regexp-@@create">
+ <h1><span class="secnum" id="sec-21.2.4.2"><a href="#sec-regexp-@@create" title="link to this section">21.2.4.2</a></span>
+ RegExp[ @@create ] ( )</h1>
+
+ <p>The @@create method of an object <var>F</var> performs the following:</p>
+
+ <ol class="proc">
+ <li>Return the result of calling the abstract operation <a href="#sec-regexpalloc">RegExpAlloc</a> with argument
+ <i>F</i>.</li>
+ </ol>
+
+ <p>The value of the <code>name</code> property of this function is <code>"[Symbol.create]"</code>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <span class="value">false</span>, [[Enumerable]]: <span
+ class="value">false</span>, [[Configurable]]: <span class="value">true</span> }.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-regexp-prototype-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-21.2.5"><a href="#sec-properties-of-the-regexp-prototype-object"
+ title="link to this section">21.2.5</a></span> Properties of the RegExp Prototype Object</h1>
+
+ <p>The RegExp prototype object is an ordinary object. It is not a RegExp instance and does not have a [[RegExpMatcher]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> or any of the other internal slots of RegExp
+ instance objects.</p>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the
+ RegExp prototype object is the standard built-in Object prototype object (<a
+ href="#sec-properties-of-the-object-prototype-object">19.1.3</a>).</p>
+
+ <p>The RegExp prototype object does not have a <code>valueOf</code> property of its own; however, it inherits the
+ <code>valueOf</code> property from the Object prototype object.</p>
+ </div>
+
+ <section id="sec-regexp.prototype.constructor">
+ <h1><span class="secnum" id="sec-21.2.5.1"><a href="#sec-regexp.prototype.constructor"
+ title="link to this section">21.2.5.1</a></span> RegExp.prototype.constructor</h1>
+
+ <p>The initial value of <code>RegExp.prototype.constructor</code> is the standard built-in <code>RegExp</code>
+ constructor.</p>
+ </section>
+
+ <section id="sec-regexp.prototype.exec">
+ <div class="front">
+ <h1><span class="secnum" id="sec-21.2.5.2"><a href="#sec-regexp.prototype.exec"
+ title="link to this section">21.2.5.2</a></span> RegExp.prototype.exec ( string )</h1>
+
+ <p>Performs a regular expression match of <var>string</var> against the regular expression and returns an Array object
+ containing the results of the match, or <b>null</b> if <var>string</var> did not match.</p>
+
+ <p>The String <span style="font-family: Times New Roman"><a href="#sec-tostring">ToString</a>(<i>string</i>)</span> is
+ searched for an occurrence of the regular expression pattern as follows:</p>
+
+ <ol class="proc">
+ <li>Let <i>R</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>R)</i> is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>R</i> does not have a [[RegExpMatcher]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a>, then throw a <b>TypeError</b> exception.</li>
+ <li>If the value of <i>R’s</i> [[RegExpMatcher]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is <b>undefined</b>, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>Let <i>S</i> be <a href="#sec-tostring">ToString</a>(<i>string</i>)</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>S</i>).</li>
+ <li>Return <a href="#sec-regexpbuiltinexec">RegExpBuiltinExec</a>(<i>R</i>, <i>S</i><b>)</b>.</li>
+ </ol>
+ </div>
+
+ <section id="sec-regexpexec">
+ <h1><span class="secnum" id="sec-21.2.5.2.1"><a href="#sec-regexpexec"
+ title="link to this section">21.2.5.2.1</a></span> Runtime Semantics: RegExpExec ( R, S ) Abstract Operation</h1>
+
+ <p>The abstract operation RegExpExec with arguments <var>R</var> and <var>S</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>R)</i> is Object.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>S</i>) is String.</li>
+ <li>Let <i>exec</i> be <a href="#sec-get-o-p">Get</a>(<i>R</i>, <code>"<b>exec"</b></code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>exec</i>).</li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>exec</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>result</i> be the result of calling the [[Call]] internal method of <i>exec</i> with arguments
+ <i>R</i>, and (<i>S</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>result</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>result</i>) is neither Object or Null, then
+ throw a <b>TypeError</b> exception.</li>
+ <li>Return(<i>result</i>).</li>
+ </ol>
+ </li>
+ <li>If <i>R</i> does not have a [[RegExpMatcher]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a>, then throw a <b>TypeError</b> exception.</li>
+ <li>If the value of <i>R’s</i> [[RegExpMatcher]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is <b>undefined</b>, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>Return <a href="#sec-regexpbuiltinexec">RegExpBuiltinExec</a>(<i>R</i>, <i>S</i><b>)</b>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> If a callable <code>exec</code> property is not found this algorithm falls back to
+ attempting to use the built-in RegExp matching algoritm. This provides compatable behaviour for code written for prior
+ editions where most built-in algorithms that use regular expressions did not perform a dynamic property lookup of
+ <code>exec</code>.</p>
+ </div>
+ </section>
+
+ <section id="sec-regexpbuiltinexec">
+ <h1><span class="secnum" id="sec-21.2.5.2.2"><a href="#sec-regexpbuiltinexec"
+ title="link to this section">21.2.5.2.2</a></span> Runtime Semantics: RegExpBuiltinExec ( R, S ) Abstract
+ Operation</h1>
+
+ <p>The abstract operation RegExpBuiltinExec with arguments <var>R</var> and <var>S</var> performs the following
+ steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>R</i> is an initialized RegExp instance.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>S</i>) is String.</li>
+ <li>Let <i>length</i> be the number of code units in <i>S</i>.</li>
+ <li>Let <i>lastIndex</i> be <a href="#sec-get-o-p">Get</a>(<i>R</i>,<code>"<b>lastIndex</b>"</code>).</li>
+ <li>Let <i>i</i> be <a href="#sec-tointeger">ToInteger</a>(<i>lastIndex</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>i</i>).</li>
+ <li>Let <i>global</i> be <a href="#sec-toboolean">ToBoolean</a>(<a href="#sec-get-o-p">Get</a>(<i>R</i>,
+ <code>"<b>global"</b></code>)).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>global</i>).</li>
+ <li>Let <i>sticky</i> be <a href="#sec-toboolean">ToBoolean</a>(<a href="#sec-get-o-p">Get</a>(<i>R</i>,
+ <code>"<b>sticky"</b></code>)).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>sticky</i>).</li>
+ <li>If <i>global</i> is <b>false</b> and <i>sticky</i> is <b>false</b>, then let <i>i</i> = 0.</li>
+ <li>Let <i>matcher</i> be the value of <i>R’s</i> [[RegExpMatcher]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>flags</i> be the value of <i>R’s</i> [[OriginalFlags]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>flags</i> contains <code>"u"</code> then let <i>fullUnicode</i> be <b>true</b>, else let <i>fullUnicode</i>
+ be <b>false.</b></li>
+ <li>Let <i>matchSucceeded</i> be <b>false</b>.</li>
+ <li>Repeat, while <i>matchSucceeded</i> is <b>false</b>
+ <ol class="block">
+ <li>If <i>i</i> < 0 or <i>i</i> > <i>length</i>, then
+ <ol class="block">
+ <li>Let <i>putStatus</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>R</i>, <code>"<b>lastIndex"</b></code>,
+ 0, <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>putStatus</i>).</li>
+ <li>Return <b>null</b>.</li>
+ </ol>
+ </li>
+ <li>Let <i>r</i> be the result of calling <i>matcher</i> with arguments <i>S</i> and <i>i</i>.</li>
+ <li>If <i>r</i> is <b>failure</b>, then
+ <ol class="block">
+ <li>If <i>sticky</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>putStatus</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>R</i>,
+ <code>"<b>lastIndex"</b></code>, 0, <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>putStatus</i>).</li>
+ <li>Return <b>null</b>.</li>
+ </ol>
+ </li>
+ <li>Let <i>i</i> = <i>i</i>+1.</li>
+ </ol>
+ </li>
+ <li>else
+ <ol class="block">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>r</i> is a State.</li>
+ <li>Set <i>matchSucceeded</i> to <b>true</b>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Let <i>e</i> be <i>r</i>'s <i>endIndex</i> value.</li>
+ <li>If <i>fullUnicode</i> is <b>true</b>, then
+ <ol class="block">
+ <li><i>e</i> is an index into the <i>Input</i> character list, derived from <i>S</i>, matched by <i>matcher</i>.
+ Let <i>eUTF</i> be the smallest index into <i>S</i> that corresponds to the character at element <i>e</i> of
+ <i>Input</i>. If <i>e</i> isgreater than the length of <i>Input</i>, then <i>eUTF</i> is 1 + the number of
+ code units in <i>S.</i></li>
+ <li>Let <i>e</i> be <i>eUTF</i>.</li>
+ </ol>
+ </li>
+ <li>If <i>global</i> is <b>true</b> or <i>sticky</i> is <b>true</b>,
+ <ol class="block">
+ <li>Let <i>putStatus</i> be the result of <a href="#sec-put-o-p-v-throw">Put</a>(<i>R</i>,
+ <code>"<b>lastIndex"</b></code>, <i>e</i>, <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>putStatus</i>).</li>
+ </ol>
+ </li>
+ <li>Let <i>n</i> be the length of <i>r</i>'s <i>captures</i> <a
+ href="#sec-list-and-record-specification-type">List</a>. (This is the same value as <a
+ href="#sec-notation">21.2.2.1</a>'s <i>NcapturingParens</i>.)</li>
+ <li>Let <i>A</i> be the result of the abstract operation <a href="#sec-arraycreate">ArrayCreate</a>(<i>n</i> +
+ 1).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: The value of <i>A</i>’s <code>"<b>length"</b></code>
+ property is <i>n</i> + 1.</li>
+ <li>Let <i>matchIndex</i> be <i>i</i>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: The following <a
+ href="#sec-createdataproperty">CreateDataProperty</a> calls will not result in an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a>.</li>
+ <li>Perform <a href="#sec-createdataproperty">CreateDataProperty</a>(<i>A</i>, <code>"<b>index"</b></code>,
+ <i>matchIndex</i>).</li>
+ <li>Perform <a href="#sec-createdataproperty">CreateDataProperty</a>(<i>A</i>, <code>"<b>input"</b></code>,
+ <i>S</i>).</li>
+ <li>Let <i>matchedSubstr</i> be the matched substring (i.e. the portion of <i>S</i> between offset <i>i</i> inclusive
+ and offset <i>e</i> exclusive).</li>
+ <li>Perform <a href="#sec-createdataproperty">CreateDataProperty</a>(<i>A</i>, <code>"<b>0"</b></code>,
+ <i>matchedSubstr</i>).</li>
+ <li>For each integer <i>i</i> such that <i>i</i> > 0 and <i>i</i> ≤ <i>n</i>
+ <ol class="block">
+ <li>Let <i>captureI</i> be <i>i</i><sup>th</sup> element of <i>r</i>'s <i>captures</i> <a
+ href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>If <i>fullUnicode</i> is <b>true</b>,
+ <ol class="block">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>captureI</i> is a <a
+ href="#sec-list-and-record-specification-type">List</a> of code points.</li>
+ <li>Let <i>captureString</i> be a string whose elements are the <a
+ href="#sec-static-semantics-utf-16encoding">UTF-16Encoding</a> <span style="font-family: sans-serif">(<a
+ href="#sec-static-semantics-utf-16encoding">10.1.1</a>)</span> of the code points of <i>capture.</i></li>
+ </ol>
+ </li>
+ <li>Else, <i>fullUnicode</i> is <b>false</b>,
+ <ol class="block">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>captureI</i> is a <a
+ href="#sec-list-and-record-specification-type">List</a> of code units.</li>
+ <li>Let <i>captureString</i> be a string whose elements are the code units of <i>captureI.</i></li>
+ </ol>
+ </li>
+ <li>Perform <a href="#sec-createdataproperty">CreateDataProperty</a>(<i>A</i>, <a
+ href="#sec-tostring">ToString</a>(<i>i</i>) , <i>captureString</i>).</li>
+ </ol>
+ </li>
+ <li>Return <i>A</i>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-get-regexp.prototype.global">
+ <h1><span class="secnum" id="sec-21.2.5.3"><a href="#sec-get-regexp.prototype.global"
+ title="link to this section">21.2.5.3</a></span> get RegExp.prototype.global</h1>
+
+ <p><code>RegExp.prototype.global</code> is an accessor property whose set accessor function is <span
+ class="value">undefined</span>. Its get accessor function performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>R</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>R)</i> is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>R</i> does not have an [[OriginalFlags]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>flags</i> be the value of <i>R’s</i> [[OriginalFlags]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>flags</i> is <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>If <i>flags</i> contains the character <code>"g"</code>, then return <b>true</b>.</li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-get-regexp.prototype.ignorecase">
+ <h1><span class="secnum" id="sec-21.2.5.4"><a href="#sec-get-regexp.prototype.ignorecase"
+ title="link to this section">21.2.5.4</a></span> get RegExp.prototype.ignoreCase</h1>
+
+ <p><code>RegExp.prototype.ignoreCase</code> is an accessor property whose set accessor function is <span
+ class="value">undefined</span>. Its get accessor function performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>R</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>R)</i> is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>R</i> does not have an [[OriginalFlags]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>flags</i> be the value of <i>R’s</i> [[OriginalFlags]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>flags</i> is <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>If <i>flags</i> contains the character <code>"i"</code>, then return <b>true</b>.</li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-regexp.prototype.match">
+ <h1><span class="secnum" id="sec-21.2.5.5"><a href="#sec-regexp.prototype.match"
+ title="link to this section">21.2.5.5</a></span> RegExp.prototype.match ( string )</h1>
+
+ <p>When the <code>match</code> method is called with argument <var>string</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>rx</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>rx)</i> is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>Let <i>S</i> be <a href="#sec-tostring">ToString</a>(<i>string</i>)</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>S</i>).</li>
+ <li>Let <i>global</i> be <a href="#sec-toboolean">ToBoolean</a>(<a href="#sec-get-o-p">Get</a>(<i>rx</i>,
+ <code>"global"</code>)).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>global</i>).</li>
+ <li>If <i>global</i> is not <b>true</b>, then
+ <ol class="block">
+ <li>Return the result of <a href="#sec-regexpexec">RegExpExec</a>(<i>rx</i>, <i>S</i>).</li>
+ </ol>
+ </li>
+ <li>Else <i>global</i> is <b>true</b>,
+ <ol class="block">
+ <li>Let <i>putStatus</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>rx</i>, <code>"lastIndex"</code>, 0,
+ <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>putStatus</i>).</li>
+ <li>Let <i>A</i> be <a href="#sec-arraycreate">ArrayCreate</a>(0).</li>
+ <li>Let <i>previousLastIndex</i> be 0.</li>
+ <li>Let <i>n</i> be 0.</li>
+ <li>Repeat,
+ <ol class="block">
+ <li>Let <i>result</i> be <a href="#sec-regexpexec">RegExpExec</a>(<i>rx</i>, <i>S</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>result</i>).</li>
+ <li>If <i>result</i> is <b>null</b>, then
+ <ol class="block">
+ <li>If <i>n</i>=0, then return <b>null</b>.</li>
+ <li>Else, return <i>A</i>.</li>
+ </ol>
+ </li>
+ <li>Else <i>result</i> is not <b>null</b>,
+ <ol class="block">
+ <li>Let <i>thisIndex</i> be <a href="#sec-tointeger">ToInteger</a>(<a href="#sec-get-o-p">Get</a>(<i>rx</i>,
+ <code>"lastIndex"</code>)).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>thisIndex</i>).</li>
+ <li>If <i>thisIndex</i> = <i>previousLastIndex</i> then
+ <ol class="block">
+ <li>Let <i>putStatus</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>rx</i>, <code>"lastIndex"</code>,
+ <i>thisIndex</i>+1, <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>putStatus</i>).</li>
+ <li>Set <i>previousLastIndex</i> to <i>thisIndex</i>+1.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Set <i>previousLastIndex</i> to <i>thisIndex</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>matchStr</i> be <a href="#sec-get-o-p">Get</a>(<i>result</i>, <code>"0"</code>).</li>
+ <li>Let <i>defineStatus</i> be <a
+ href="#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a>(<i>A</i>, <a
+ href="#sec-tostring">ToString</a>(<i>n</i>), <i>matchStr</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>defineStatus</i>).</li>
+ <li>Increment <i>n</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </section>
+
+ <section id="sec-get-regexp.prototype.multiline">
+ <h1><span class="secnum" id="sec-21.2.5.6"><a href="#sec-get-regexp.prototype.multiline"
+ title="link to this section">21.2.5.6</a></span> get RegExp.prototype.multiline</h1>
+
+ <p><code>RegExp.prototype.multiline</code> is an accessor property whose set accessor function is <span
+ class="value">undefined</span>. Its get accessor function performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>R</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>R)</i> is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>R</i> does not have an [[OriginalFlags]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>flags</i> be the value of <i>R’s</i> [[OriginalFlags]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>flags</i> is <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>If <i>flags</i> contains the character <code>"m"</code>, then return <b>true</b>.</li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-regexp.prototype.replace">
+ <h1><span class="secnum" id="sec-21.2.5.7"><a href="#sec-regexp.prototype.replace"
+ title="link to this section">21.2.5.7</a></span> RegExp.prototype.replace ( string, replaceValue )</h1>
+
+ <p>When the <code>replace</code> method is called with arguments <var>string</var> and <var>replaceValue</var> the
+ following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>rx</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>rx)</i> is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>Let <i>nCaptures</i> be the number of left capturing parentheses in <i>rx</i> (using <i>NcapturingParens</i> as
+ specified in <a href="#sec-notation">21.2.2.1</a>)</li>
+ <li>Let <i>S</i> be <a href="#sec-tostring">ToString</a>(<i>string</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>S</i>).</li>
+ <li>Let <i>lengthS</i> be the number of code unit elements in <i>S</i>.</li>
+ <li>Let <i>functionalReplace</i> be <a href="#sec-iscallable">IsCallable</a>(<i>replaceValue</i>).</li>
+ <li>If <i>functionReplace</i> is <b>false</b>, then
+ <ol class="block">
+ <li>Let <i>replaceValue</i> be <a href="#sec-tostring">ToString</a>(<i>replaceValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>replaceValue</i>)..</li>
+ </ol>
+ </li>
+ <li>Let <i>global</i> be <a href="#sec-toboolean">ToBoolean</a>(<a href="#sec-get-o-p">Get</a>(<i>rx</i>,
+ <code>"global"</code>)).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>global</i>).</li>
+ <li>If <i>global</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>putStatus</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>rx</i>, <code>"lastIndex"</code>, 0,
+ <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>putStatus</i>).</li>
+ </ol>
+ </li>
+ <li>Let <i>previousLastIndex</i> be 0.</li>
+ <li>Let <i>results</i> be a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Let <i>done</i> be <b>false</b>.</li>
+ <li>Repeat, while <i>done</i> is <b>false</b>
+ <ol class="block">
+ <li>Let <i>result</i> be <a href="#sec-regexpexec">RegExpExec</a>(<i>rx</i>, <i>S</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>result</i>).</li>
+ <li>If <i>result</i> is <b>null</b>, then set <i>done</i> to <b>true</b>.</li>
+ <li>Else <i>result</i> is not <b>null</b>,
+ <ol class="block">
+ <li>If <i>global</i> is <b>false</b>, then set <i>done</i> to <b>true</b>.</li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>thisIndex</i> be <a href="#sec-tointeger">ToInteger</a>(<a href="#sec-get-o-p">Get</a>(<i>rx</i>,
+ <code>"lastIndex"</code>)).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>thisIndex</i>).</li>
+ <li>If <i>thisIndex</i> = <i>previousLastIndex</i> then
+ <ol class="block">
+ <li>Let <i>putStatus</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>rx</i>, <code>"lastIndex"</code>,
+ <i>thisIndex</i>+1, <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>putStatus</i>).</li>
+ <li>Set <i>previousLastIndex</i> to <i>thisIndex</i>+1.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Set <i>previousLastIndex</i> to <i>thisIndex</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>If <i>result</i> is not <b>null</b>, then append <i>result</i> to the end of <i>results</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>accumulatedResult</i> be the empty String value.</li>
+ <li>Let <i>nextSrcPosition</i> be 0.</li>
+ <li>Let <i>done</i> be <b>false</b>.</li>
+ <li>Repeat, for each <i>result</i> in <i>results</i>,
+ <ol class="block">
+ <li>Let <i>matched</i> be <a href="#sec-tostring">ToString</a>(<a href="#sec-get-o-p">Get</a>(<i>result</i>,
+ <code>"0"</code>)).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>matched</i>).</li>
+ <li>Let <i>matchLength</i> be the number of code units in <i>matched</i>.</li>
+ <li>Let <i>position</i> be <a href="#sec-tointeger">ToInteger</a>(<a href="#sec-get-o-p">Get</a>(<i>result</i>,
+ <code>"index"</code>)).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>position</i>).</li>
+ <li>Let <i>position</i> be max(min(<i>position</i>, <i>lengthS</i>), 0).</li>
+ <li>Let <i>n</i> be 1.</li>
+ <li>Let <i>captures</i> be an empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Repeat while <i>n</i> ≤ <i>nCaptures</i>
+ <ol class="block">
+ <li>Let <i>capN</i> be <a href="#sec-get-o-p">Get</a>(<i>result</i>, <a
+ href="#sec-tostring">ToString</a>(<i>n</i>)).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>capN</i>) is not Undefined, then let
+ <i>capN</i> be <a href="#sec-tostring">ToString</a>(<i>capN</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>capN</i>).</li>
+ <li>Append <i>capN</i> as the last element of <i>captures.</i></li>
+ <li>Let <i>n</i> be <i>n</i>+1</li>
+ </ol>
+ </li>
+ <li>If <i>functionalReplace</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>replacerArgs</i> be the <a href="#sec-list-and-record-specification-type">List</a>
+ (<i>matched</i>).</li>
+ <li>Append in list order the elements of <i>captures</i> to the end of the <a
+ href="#sec-list-and-record-specification-type">List</a> <i>replacerArgs</i>.</li>
+ <li>Append <i>position</i> and <i>S</i> as the last two elements of <i>replacerArgs.</i></li>
+ <li>Let <i>replValue</i> be the result of calling the [[Call]] internal method of <i>replaceValue</i> passing
+ <b>undefined</b> as the <b>this</b> value and <i>replacerArgs</i> as the argument list.</li>
+ <li>Let <i>replacement</i> be <a href="#sec-tostring">ToString</a>(<i>replValue</i>).</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>replacement</i> be <a href="#sec-getreplacesubstitution">GetReplaceSubstitution</a>(<i>matched</i>,
+ <i>S</i>, <i>position</i>, <i>captures</i>, <i>replaceValue</i>).</li>
+ </ol>
+ </li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>replacement</i>).</li>
+ <li>If <i>position</i> ≥ <i>nextSourcePosition</i>, then
+ <ol class="block">
+ <li>NOTE	<i>position</i> should not normally move backwards. If it does, it is in indication of a
+ ill-behaving RegExp subclass or use of an access triggered side-effect to change the global flag or other
+ characteristics of <i>rx.</i> In such cases, the corresponding substitution is ignored.</li>
+ <li>Let <i>accumulatedResult</i> be the String formed by concatenating the code units of the current value of
+ <i>accumulatedResult</i> with the substring of <i>S</i> consisting of the code units from
+ <i>nextSrcPosition</i> (inclusive) up to <i>position</i> (exclusive) and with the code units of
+ <i>replacement</i>.</li>
+ <li>Let <i>nextSrcPosition</i> be <i>position</i> + <i>matchLength</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>If <i>nextSrcPosition</i> ≥ the number of code units in <i>S</i>, then return <i>accumulatedResult</i>.</li>
+ <li>Return the String formed by concatenating the code units of <i>accumulatedResult</i> with the substring of <i>S</i>
+ consisting of the code units from <i>nextSrcPosition</i> (inclusive) up through the final code unit of <i>S</i>
+ (inclusive).</li>
+ </ol>
+ </section>
+
+ <section id="sec-regexp.prototype.search">
+ <h1><span class="secnum" id="sec-21.2.5.8"><a href="#sec-regexp.prototype.search"
+ title="link to this section">21.2.5.8</a></span> RegExp.prototype.search ( string )</h1>
+
+ <p>When the search method is called with argument <var>string</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>rx</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>rx)</i> is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>Let <i>s</i> be <a href="#sec-tostring">ToString</a>(<i>string</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>s</i>).</li>
+ <li>Let <i>previousLastIndex</i> be <a href="#sec-get-o-p">Get</a>(<i>rx</i>, <code>"lastIndex"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>previousLastIndex</i>).</li>
+ <li>Let <i>status</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>rx</i>, <code>"lastIndex"</code>, 0,
+ <b>true)</b></li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>)</li>
+ <li>Let <i>result</i> be <a href="#sec-regexpexec">RegExpExec</a>(<i>rx</i>, <i>s</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>result</i>).</li>
+ <li>Let <i>status</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>rx</i>, <code>"lastIndex"</code>,
+ <i>previousLastIndex</i>, <b>true)</b></li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>)</li>
+ <li>If <i>result</i> is <b>null</b>, return –1.</li>
+ <li>Return <a href="#sec-get-o-p">Get</a>(<i>result</i>, <code>"index"</code>).</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>lastIndex</code> and <code>global</code> properties of this RegExp object are
+ ignored when performing the search. The <code>lastIndex</code> property is left unchanged.</p>
+ </div>
+ </section>
+
+ <section id="sec-get-regexp.prototype.source">
+ <h1><span class="secnum" id="sec-21.2.5.9"><a href="#sec-get-regexp.prototype.source"
+ title="link to this section">21.2.5.9</a></span> get RegExp.prototype.source</h1>
+
+ <p><code>RegExp.prototype.source</code> is an accessor property whose set accessor function is <span
+ class="value">undefined</span>. Its get accessor function performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>R</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>R)</i> is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>R</i> does not have an [[OriginalSource]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> throw a <b>TypeError</b> exception.</li>
+ <li>If <i>R</i> does not have an [[OriginalFlags]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>src</i> be the value of <i>R’s</i> [[OriginalSource]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>flags</i> be the value of <i>R’s</i> [[OriginalFlags]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If either <i>src</i> or <i>flags</i> is <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Return <a href="#sec-escaperegexppattern">EscapeRegExpPattern</a>(<i>src</i>, <i>flags</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-regexp.prototype.split">
+ <h1><span class="secnum" id="sec-21.2.5.10"><a href="#sec-regexp.prototype.split"
+ title="link to this section">21.2.5.10</a></span> RegExp.prototype.split ( string, limit )</h1>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Returns an Array object into which substrings of the result of converting <i>string</i>
+ to a String have been stored. The substrings are determined by searching from left to right for matches of the
+ <b>this</b> value regular expression; these occurrences are not part of any substring in the returned array, but serve
+ to divide up the String value.</p>
+
+ <p>The <b>this</b> value may be an empty regular expression or a regular expression that can match an empty String. In
+ this case, <span style="font-family: sans-serif">regular expression</span> does not match the empty substring at the
+ beginning or end of the input String, nor does it match the empty substring at the end of the previous separator match.
+ (For example, if the regular expression matches the empty String, the String is split up into individual code unit
+ elements; the length of the result array equals the length of the String, and each substring contains one code unit.)
+ Only the first match at a given position of the <b>this</b> String is considered, even if backtracking could yield a
+ non-empty-substring match at that position. (For example, <code>/a*?/.split("ab")</code> evaluates to the array
+ <code>["a","b"]</code>, while <code>/a*/.split("ab")</code> evaluates to the array<code>["","b"]</code>.)</p>
+
+ <p>If the <i>string</i> is (or converts to) the empty String, the result depends on whether the regular expression can
+ match the empty String. If it can, the result array contains no elements. Otherwise, the result array contains one
+ element, which is the empty String.</p>
+
+ <p>If the regular expression that contains capturing parentheses, then each time <i>separator</i> is matched the results
+ (including any <b>undefined</b> results) of the capturing parentheses are spliced into the output array.
+ For example,</p>
+
+ <p><span style="font-family:
+ sans-serif">/<(\/)?([^<>]+)>/.split("A<B>bold</B>and<CODE>coded</CODE>")</span></p>
+
+ <p>evaluates to the array</p>
+
+ <p><span style="font-family: sans-serif">["A", undefined, "B", "bold", "/", "B", "and", undefined,"CODE", "coded", "/",
+ "CODE", ""]</span></p>
+
+ <p>If <i>limit</i> is not <b>undefined</b>, then the output array is truncated so that it contains no more than
+ <i>limit</i> elements.</p>
+ </div>
+
+ <p>When the <code>split</code> method is called, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>rx</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>rx)</i> is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>rx</i> does not have a [[RegExpMatcher]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a>, then throw a <b>TypeError</b> exception.</li>
+ <li>If the value of <i>rx’s</i> [[RegExpMatcher]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is <b>undefined</b>, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>Let <i>matcher</i> be the value of <i>rx’s</i> [[RegExpMatcher]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>S</i> be <a href="#sec-tostring">ToString</a>(<i>string</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>S</i>).</li>
+ <li>Let <i>A</i> be the result of the abstract operation <a href="#sec-arraycreate">ArrayCreate</a> with argument
+ 0.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>A</i>).</li>
+ <li>Let <i>lengthA</i> be 0.</li>
+ <li>If <i>limit</i> is <b>undefined</b>, let <i>lim</i> = 2<sup>53</sup>–1; else let <i>lim</i> = <a
+ href="#sec-tolength">ToLength</a>(<i>limit</i>).</li>
+ <li>Let <i>s</i> be the number of elements in <i>S</i>.</li>
+ <li>Let <i>p</i> = 0.</li>
+ <li>If <i>lim</i> = 0, return <i>A</i>.</li>
+ <li>If <i>s</i> = 0, then
+ <ol class="block">
+ <li>Let <i>z</i> be the result of calling the <i>matcher</i> with arguments <i>S</i> and 0.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>z</i>).</li>
+ <li>If <i>z</i> is not <b>failure</b>, return <i>A</i>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: The following call will never result in an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a>.</li>
+ <li>Call <a href="#sec-createdataproperty">CreateDataProperty</a>(<i>A</i>, <code>"<b>0</b>"</code>,
+ <i>S</i>).</li>
+ <li>Return <i>A</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>q</i> = <i>p</i>.</li>
+ <li>Repeat, while <i>q</i> ≠ <i>s</i>
+ <ol class="block">
+ <li>Let <i>z</i> be the result of calling the <i>matcher</i> with arguments <i>S</i> and <i>q</i></li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>z</i>).</li>
+ <li>If <i>z</i> is <b>failure</b>, then let <i>q</i> = <i>q</i>+1.</li>
+ <li>Else <i>z</i> is not <b>failure</b>,
+ <ol class="block">
+ <li><i>z</i> must be a State. Let <i>e</i> be <i>z</i>'s <i>endIndex</i> and let <i>cap</i> be <i>z</i>'s
+ <i>captures</i> <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>If <i>e</i> = <i>p</i>, then let <i>q</i> = <i>q</i>+1.</li>
+ <li>Else <i>e</i> ≠ <i>p</i>,
+ <ol class="block">
+ <li>Let <i>T</i> be a String value equal to the substring of <i>S</i> consisting of the elements at
+ positions <i>p</i> (inclusive) through <i>q</i> (exclusive).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: The following call will never result in an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a>.</li>
+ <li>Call <a href="#sec-createdataproperty">CreateDataProperty</a>(<i>A</i>, <a
+ href="#sec-tostring">ToString</a>(<i>lengthA</i>), <i>T</i>).</li>
+ <li>If <i>lengthA</i> = <i>lim</i>, return <i>A</i>.</li>
+ <li>Let <i>p</i> = <i>e</i>.</li>
+ <li>Let <i>i</i> = 0.</li>
+ <li>Repeat, while <i>i</i> is not equal to the number of elements in <i>cap</i>.
+ <ol class="block">
+ <li>Let <i>i</i> = <i>i</i>+1.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: The following call will never result in an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a>.</li>
+ <li>Call <a href="#sec-createdataproperty">CreateDataProperty</a>(<i>A</i>, <a
+ href="#sec-tostring">ToString</a>(<i>lengthA</i>), <i>cap</i>[<i>i</i>]).</li>
+ <li>Increment <i>lengthA</i> by 1.</li>
+ <li>If <i>lengthA</i> = <i>lim</i>, return <i>A</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>q</i> = <i>p</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Let <i>T</i> be a String value equal to the substring of <i>S</i> consisting of the elements at positions <i>p</i>
+ (inclusive) through <i>s</i> (exclusive).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: The following call will never result in an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a>.</li>
+ <li>Call <a href="#sec-createdataproperty">CreateDataProperty</a>(<i>A</i>, <a
+ href="#sec-tostring">ToString</a>(<i>lengthA</i>), <i>T</i> ).</li>
+ <li>Return <i>A</i>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>split</code> method is <b>2</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> The <code>split</code> method ignores the value of the <code>global</code> property of
+ this RegExp object.</p>
+ </div>
+ </section>
+
+ <section id="sec-get-regexp.prototype.sticky">
+ <h1><span class="secnum" id="sec-21.2.5.11"><a href="#sec-get-regexp.prototype.sticky"
+ title="link to this section">21.2.5.11</a></span> get RegExp.prototype.sticky</h1>
+
+ <p><code>RegExp.prototype.sticky</code> is an accessor property whose set accessor function is <span
+ class="value">undefined</span>. Its get accessor function performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>R</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>R)</i> is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>R</i> does not have an [[OriginalFlags]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>flags</i> be the value of <i>R’s</i> [[OriginalFlags]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>flags</i> is <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>If <i>flags</i> contains the character <code>"y"</code>, then return <b>true</b>.</li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-regexp.prototype.test">
+ <h1><span class="secnum" id="sec-21.2.5.12"><a href="#sec-regexp.prototype.test"
+ title="link to this section">21.2.5.12</a></span> RegExp.prototype.test( S )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>R</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>R)</i> is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>Let <i>string</i> be <a href="#sec-tostring">ToString</a>(<i>S</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>string</i>).</li>
+ <li>Let <i>match</i> be <a href="#sec-regexpexec">RegExpExec</a>(<i>R</i>, <i>string</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>match</i>).</li>
+ <li>If <i>match</i> is not <b>null</b>, then return <b>true</b>; else return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-regexp.prototype.tostring">
+ <h1><span class="secnum" id="sec-21.2.5.13"><a href="#sec-regexp.prototype.tostring"
+ title="link to this section">21.2.5.13</a></span> RegExp.prototype.toString ( )</h1>
+ <ol class="proc">
+ <li>Let <i>R</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>R)</i> is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>R</i> does not have a [[RegExpMatcher]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a>, then throw a <b>TypeError</b> exception.</li>
+ <li>If the value of <i>R’s</i> [[RegExpMatcher]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is <b>undefined</b>, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>Let <i>pattern</i> be <a href="#sec-tostring">ToString</a>(<a href="#sec-get-o-p">Get</a>(<i>R</i>,
+ <code>"source"</code>)).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>pattern</i>).</li>
+ <li>Let <i>result</i> be the String value formed by concatenating <code>"<b>/</b>"</code>, <i>pattern</i>, and
+ <code>"<b>/</b>"</code>.</li>
+ <li>Let <i>global</i> be <a href="#sec-toboolean">ToBoolean</a>(<a href="#sec-get-o-p">Get</a>(<i>R</i>,
+ <code>"global"</code>)).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>global</i>).</li>
+ <li>If <i>global</i> is <b>true</b>, then append <code>"g"</code> as the last character of <i>result</i>.</li>
+ <li>Let <i>ignoreCase</i> be <a href="#sec-toboolean">ToBoolean</a>(<a href="#sec-get-o-p">Get</a>(<i>R</i>,
+ <code>"ignoreCase"</code>)).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>ignoreCase</i>).</li>
+ <li>If <i>ignoreCase</i> is <b>true</b>, then append <code>"i"</code> as the last character of <i>result</i>.</li>
+ <li>Let <i>multiline</i> be <a href="#sec-toboolean">ToBoolean</a>(<a href="#sec-get-o-p">Get</a>(<i>R</i>,
+ <code>"multiline"</code>)).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>multiline</i>).</li>
+ <li>If <i>multiline</i> is <b>true</b>, then append <code>"m"</code> as the last character of <i>result</i>.</li>
+ <li>Let <i>unicode</i> be <a href="#sec-toboolean">ToBoolean</a>(<a href="#sec-get-o-p">Get</a>(<i>R</i>,
+ <code>"unicode"</code>)).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>unicode</i>).</li>
+ <li>If <i>unicode</i> is <b>true</b>, then append <code>"u"</code> as the last character of <i>result</i>.</li>
+ <li>Let <i>sticky</i> be <a href="#sec-toboolean">ToBoolean</a>(<a href="#sec-get-o-p">Get</a>(<i>R</i>,
+ <code>"sticky"</code>)).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>sticky</i>).</li>
+ <li>If <i>sticky</i> is <b>true</b>, then append <code>"y"</code> as the last character of <i>result</i>.</li>
+ <li>Return <i>result</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The returned String has the form of a <i>RegularExpressionLiteral</i> that evaluates to
+ another RegExp object with the same behaviour as this object.</p>
+ </div>
+ </section>
+
+ <section id="sec-get-regexp.prototype.unicode">
+ <h1><span class="secnum" id="sec-21.2.5.14"><a href="#sec-get-regexp.prototype.unicode"
+ title="link to this section">21.2.5.14</a></span> get RegExp.prototype.unicode</h1>
+
+ <p><code>RegExp.prototype.unicode</code> is an accessor property whose set accessor function is <span
+ class="value">undefined</span>. Its get accessor function performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>R</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>R)</i> is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>R</i> does not have an [[OriginalFlags]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>flags</i> be the value of <i>R’s</i> [[OriginalFlags]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>flags</i> is <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>If <i>flags</i> contains the character <code>"u"</code>, then return <b>true</b>.</li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-regexp.prototype-@@isregexp">
+ <h1><span class="secnum" id="sec-21.2.5.15"><a href="#sec-regexp.prototype-@@isregexp"
+ title="link to this section">21.2.5.15</a></span> RegExp.prototype [ @@isRegExp ]</h1>
+
+ <p>The initial value of the @@isRegExp property is <span class="value">true</span>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <span class="value">false</span>, [[Enumerable]]: <span
+ class="value">false</span>, [[Configurable]]: <span class="value">true</span> }.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The @@isRegExp property is used by <code>String.prototype</code> methods to identify
+ objects that have the basic behaviour of regular expressions. The absence of a @@isRegExp property or the existence of
+ such a property whose value is <b>null</b> indicates that the object should is not intended to be used as regular
+ expression object.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-regexp-instances">
+ <div class="front">
+ <h1><span class="secnum" id="sec-21.2.6"><a href="#sec-properties-of-regexp-instances"
+ title="link to this section">21.2.6</a></span> Properties of RegExp Instances</h1>
+
+ <p>RegExp instances are ordinary objects that inherit properties from the RegExp prototype object. RegExp instances have
+ internal slots [[RegExpMatcher]], [[OriginalSource]], and [[OriginalFlags]]. The value of the [[RegExpMatcher]] internal
+ slot is an implementation dependent representation of the <span class="nt">Pattern</span> of the RegExp object.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Prior to the 6<sup>th</sup> Edition, <code>RegExp</code> instances were specified as
+ having the own data properties <code>source</code>, <code>global</code>, <code>ignoreCase</code>, and
+ <code>multiline</code>. Those properties are now specified as accessor properties of <a
+ href="#sec-regexp.prototype">RegExp.prototype</a>.</p>
+ </div>
+
+ <p>RegExp instances also have the following property:</p>
+ </div>
+
+ <section id="sec-lastindex">
+ <h1><span class="secnum" id="sec-21.2.6.1"><a href="#sec-lastindex" title="link to this section">21.2.6.1</a></span>
+ lastIndex</h1>
+
+ <p>The value of the <code>lastIndex</code> property specifies the String position at which to start the next match. It is
+ coerced to an integer when used (<a href="#sec-regexp.prototype.exec">see 21.2.5.2</a>). This property shall have the
+ attributes { [[Writable]]: <b>true</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]: <b>false</b> }.</p>
+ </section>
+ </section>
+ </section>
+</section>
+
+<section id="sec-indexed-collections">
+ <div class="front">
+ <h1><span class="secnum" id="sec-22"><a href="#sec-indexed-collections" title="link to this section">22</a></span> Indexed
+ Collections</h1>
+ </div>
+
+ <section id="sec-array-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-22.1"><a href="#sec-array-objects" title="link to this section">22.1</a></span> Array
+ Objects</h1>
+
+ <p>Array objects are exotic objects that give special treatment to a certain class of property names. See <a
+ href="#sec-boundfunctionclone">9.4.1.4</a> for a definition of this special treatment.</p>
+
+ <p>An Array object, <var>O</var>, is said to be <i>sparse</i> if the following algorithm returns <b>true</b>:</p>
+
+ <ol class="proc">
+ <li>Let <i>len</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <code>"length"</code>).</li>
+ <li>For each integer <i>i</i> in the range 0≤<i>i</i><<a href="#sec-touint32">ToUint32</a>(<i>len</i>)
+ <ol class="block">
+ <li>Let <i>elem</i> be the result of calling the [[GetOwnProperty]] internal method of <i>O</i> with argument <a
+ href="#sec-tostring">ToString</a>(<i>i</i>).</li>
+ <li>If <i>elem</i> is <b>undefined</b>, return <b>true</b>.</li>
+ </ol>
+ </li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </div>
+
+ <section id="sec-array-constructor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-22.1.1"><a href="#sec-array-constructor" title="link to this section">22.1.1</a></span>
+ The Array Constructor</h1>
+
+ <p>The Array constructor is the %Array% intrinsic object and the initial value of the <code>Array</code> property of the
+ global object. When <code>Array</code> is called as a function rather than as a constructor, it creates and initializes a
+ new Array object. Thus the function call <code><b>Array(</b>…<b>)</b></code> is equivalent to the object creation
+ expression <code><b>new Array(</b>…<b>)</b></code> with the same arguments. However, if the <b>this</b> value
+ passed in the call is an Object with an [[ArrayInitializationState]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> whose value is <span
+ class="value">undefined</span>, it initializes the <b>this</b> value using the argument values. This permits
+ <code>Array</code> to be used both as factory method and to perform constructor instance initialization.</p>
+
+ <p>The <code>Array</code> constructor is designed to be subclassable. It may be used as the value of an
+ <code>extends</code> clause of a class declaration. Subclass constructors that intended to inherit the specified
+ <code>Array</code> behaviour must include a <code>super</code> call to the <code>Array</code> constructor to initialize
+ subclass instances.</p>
+
+ <p>The <code>length</code> property of the <code>Array</code> constructor function is <b>1</b>.</p>
+ </div>
+
+ <section id="sec-array-constructor-array">
+ <h1><span class="secnum" id="sec-22.1.1.1"><a href="#sec-array-constructor-array"
+ title="link to this section">22.1.1.1</a></span> Array ( )</h1>
+
+ <p>This description applies if and only if the Array constructor is called with no arguments.</p>
+
+ <ol class="proc">
+ <li>Let <i>numberOfArgs</i> be the number of arguments passed to this function call.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>numberOfArgs</i> = 0.</li>
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is Object and <i>O</i> has an
+ [[ArrayInitializationState]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> and the
+ value of [[ArrayInitializationState]] is <b>false</b>, then
+ <ol class="block">
+ <li>Set the value of <i>O’s</i> [[ArrayInitializationState]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to <b>true</b>.</li>
+ <li>Let <i>array</i> be <i>O</i>.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>F</i> be this function.</li>
+ <li>Let <i>proto</i> be <a href="#sec-getprototypefromconstructor">GetPrototypeFromConstructor</a>(<i>F</i>,
+ <code>"%ArrayPrototype%"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>proto</i>).</li>
+ <li>Let <i>array</i> be <a href="#sec-arraycreate">ArrayCreate</a>(0, <i>proto</i>).</li>
+ </ol>
+ </li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>array</i>).</li>
+ <li>Let <i>putStatus</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>array</i>, <code>"length"</code>, 0,
+ <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>putStatus</i>).</li>
+ <li>Return <i>array</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-array-len">
+ <h1><span class="secnum" id="sec-22.1.1.2"><a href="#sec-array-len" title="link to this section">22.1.1.2</a></span> Array
+ (len)</h1>
+
+ <p>This description applies if and only if the Array constructor is called with exactly one argument.</p>
+
+ <ol class="proc">
+ <li>Let <i>numberOfArgs</i> be the number of arguments passed to this function call.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>numberOfArgs</i> = 1.</li>
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is Object and <i>O</i> has an
+ [[ArrayInitializationState]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> and the
+ value of [[ArrayInitializationState]] is <b>false</b>, then
+ <ol class="block">
+ <li>Set the value of <i>O’s</i> [[ArrayInitializationState]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to <b>true</b>.</li>
+ <li>Let <i>array</i> be <i>O</i>.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>F</i> be this function.</li>
+ <li>Let <i>proto</i> be <a href="#sec-getprototypefromconstructor">GetPrototypeFromConstructor</a>(<i>F</i>,
+ <code>"%ArrayPrototype%"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>proto</i>).</li>
+ <li>Let <i>array</i> be <a href="#sec-arraycreate">ArrayCreate</a>(0, <i>proto</i>).</li>
+ </ol>
+ </li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>array</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>len</i>) is not Number, then
+ <ol class="block">
+ <li>Let <i>defineStatus</i> be <a href="#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a>(<i>array</i>,
+ <code>"<b>0</b>"</code>, <i>len</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>defineStatus</i>).</li>
+ <li>Let <i>intLen</i> be 1.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>intLen</i> be <a href="#sec-touint32">ToUint32</a>(<i>len</i>).</li>
+ <li>If <i>intLen</i> ≠ <i>len</i>, then throw a <b>RangeError</b> exception.</li>
+ </ol>
+ </li>
+ <li>Let <i>putStatus</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>array</i>, <code>"length"</code>, <i>intLen</i>,
+ <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>putStatus</i>).</li>
+ <li>Return <i>array</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-array-items">
+ <h1><span class="secnum" id="sec-22.1.1.3"><a href="#sec-array-items" title="link to this section">22.1.1.3</a></span>
+ Array (...items )</h1>
+
+ <p>This description applies if and only if the Array constructor is called with at least two arguments.</p>
+
+ <p>When the <code>Array</code> function is called the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>numberOfArgs</i> be the number of arguments passed to this function call.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>numberOfArgs</i> ≥ 2.</li>
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is Object and <i>O</i> has an
+ [[ArrayInitializationState]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> and the
+ value of [[ArrayInitializationState]] is <b>false</b>, then
+ <ol class="block">
+ <li>Set the value of <i>O’s</i> [[ArrayInitializationState]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to <b>true</b>.</li>
+ <li>Let <i>array</i> be <i>O</i>.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>F</i> be this function.</li>
+ <li>Let <i>proto</i> be <a href="#sec-getprototypefromconstructor">GetPrototypeFromConstructor</a>(<i>F</i>,
+ <code>"%ArrayPrototype%"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>proto</i>).</li>
+ <li>Let <i>array</i> be <a href="#sec-arraycreate">ArrayCreate</a>(<i>numberOfArgs</i>, <i>proto</i>).</li>
+ </ol>
+ </li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>array</i>).</li>
+ <li>Let <i>k</i> be 0.</li>
+ <li>Let <i>items</i> be a zero-origined <a href="#sec-list-and-record-specification-type">List</a> containing the
+ argument items in order.</li>
+ <li>Repeat, while <i>k</i> < <i>numberOfArgs</i>
+ <ol class="block">
+ <li>Let <i>Pk</i> be <a href="#sec-tostring">ToString</a>(<i>k</i>).</li>
+ <li>Let <i>itemK</i> be <i>k</i><sup>th</sup> element of <i>items</i>.</li>
+ <li>Let <i>defineStatus</i> be <a href="#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a>(<i>array</i>,
+ <i>Pk</i>, <i>itemK</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>defineStatus</i>).</li>
+ <li>Increase <i>k</i> by 1.</li>
+ </ol>
+ </li>
+ <li>Let <i>putStatus</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>array</i>, <code>"length"</code>,
+ <i>numberOfArgs</i>, <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>putStatus</i>).</li>
+ <li>Return <i>array</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-new-array-argumentslist">
+ <h1><span class="secnum" id="sec-22.1.1.4"><a href="#sec-new-array-argumentslist"
+ title="link to this section">22.1.1.4</a></span> new Array ( ... argumentsList)</h1>
+
+ <p>When <code>Array</code> is called as part of a <code>new</code> expression, it initializes a newly created object.</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be the <code>Array</code> function object on which the <code>new</code> operator was applied.</li>
+ <li>Let <i>argumentsList</i> be the <i>argumentsList</i> argument of the [[Construct]] internal method that was invoked
+ by the <code>new</code> operator.</li>
+ <li>Return the result of <a href="#sec-construct-f-argumentslist">Construct</a> (<i>F</i>, <i>argumentsList</i>).</li>
+ </ol>
+
+ <p>If <code>Array</code> is implemented as an <a href="#sec-ecmascript-function-objects">ECMAScript function object</a>,
+ its [[Construct]] internal method will perform the above steps.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-array-constructor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-22.1.2"><a href="#sec-properties-of-the-array-constructor"
+ title="link to this section">22.1.2</a></span> Properties of the Array Constructor</h1>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the Array
+ constructor is the Function prototype object (<a href="#sec-properties-of-the-function-prototype-object">19.2.3</a>).</p>
+
+ <p>Besides the <code>length</code> property (whose value is <b>1</b>), the Array constructor has the following
+ properties:</p>
+ </div>
+
+ <section id="sec-array.from">
+ <h1><span class="secnum" id="sec-22.1.2.1"><a href="#sec-array.from" title="link to this section">22.1.2.1</a></span>
+ Array.from ( arrayLike [ , mapfn [ , thisArg ] ] )</h1>
+
+ <p>When the <code>from</code> method is called with argument <var>arrayLike</var> and optional arguments <var>mapfn</var>
+ and <var>thisArg</var> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>C</i> be the <b>this</b> value.</li>
+ <li>Let <i>items</i> be <a href="#sec-toobject">ToObject</a>(<i>arrayLike</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>items</i>).</li>
+ <li>If <i>mapfn</i> is <b>undefined</b>, then let <i>mapping</i> be <b>false.</b></li>
+ <li>else
+ <ol class="block">
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>mapfn</i>) is <b>false</b>, throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>thisArg</i> was supplied, let <i>T</i> be <i>thisArg</i>; else let <i>T</i> be <b>undefined</b>.</li>
+ <li>Let <i>mapping</i> be <b>true</b></li>
+ </ol>
+ </li>
+ <li>Let <i>usingIterator</i> be <a href="#sec-checkiterable">CheckIterable</a>(<i>items</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>usingIterator</i>).</li>
+ <li>If <i>usingIterator</i> is not <b>undefined</b>, then
+ <ol class="block">
+ <li>If <a href="#sec-isconstructor">IsConstructor</a>(<i>C</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>A</i> be the result of calling the [[Construct]] internal method of <i>C</i> with an empty argument
+ list.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>A</i> be <a href="#sec-arraycreate">ArrayCreate</a>(0).</li>
+ </ol>
+ </li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>A</i>).</li>
+ <li>Let <i>iterator</i> be <a href="#sec-getiterator">GetIterator</a>(<i>items</i>, <i>usingIterator</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>iterator</i>).</li>
+ <li>Let <i>k</i> be 0.</li>
+ <li>Repeat
+ <ol class="block">
+ <li>Let <i>Pk</i> be <a href="#sec-tostring">ToString</a>(<i>k</i>).</li>
+ <li>Let <i>next</i> be <a href="#sec-iteratorstep">IteratorStep</a>(<i>iterator</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>next</i>).</li>
+ <li>If <i>next</i> is <b>false</b>, then
+ <ol class="block">
+ <li>Let <i>putStatus</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>A</i>, <code>"length"</code>,
+ <i>k</i>, <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>putStatus</i>).</li>
+ <li>Return <i>A</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>nextValue</i> be <a href="#sec-iteratorvalue">IteratorValue</a>(<i>next</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>nextValue</i>).</li>
+ <li>If <i>mapping</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>mappedValue</i> be the result of calling the [[Call]] internal method of <i>mapfn</i> with
+ <i>T</i> as <i>thisArgument</i> and (<i>nextValue</i>, <i>k</i>) as <i>argumentsList</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>mappedValue</i>).</li>
+ </ol>
+ </li>
+ <li>Else, let <i>mappedValue</i> be <i>nextValue</i>.</li>
+ <li>Let <i>defineStatus</i> be <a href="#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a>(<i>A</i>,
+ <i>Pk</i>, <i>mappedValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>defineStatus</i>).</li>
+ <li>Increase <i>k</i> by 1.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>items</i> is not an Iterator so assume it is an array-like
+ object.</li>
+ <li>Let <i>lenValue</i> be <a href="#sec-get-o-p">Get</a>(<i>items</i>, <code>"length"</code>).</li>
+ <li>Let <i>len</i> be <a href="#sec-tolength">ToLength</a>(<i>lenValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>len</i>).</li>
+ <li>If <a href="#sec-isconstructor">IsConstructor</a>(<i>C</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>A</i> be the result of calling the [[Construct]] internal method of <i>C</i> with an argument list
+ containing the single item <i>len</i>.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>A</i> be <a href="#sec-arraycreate">ArrayCreate</a>(<i>len</i>).</li>
+ </ol>
+ </li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>A</i>).</li>
+ <li>Let <i>k</i> be 0.</li>
+ <li>Repeat, while <i>k</i> < <i>len</i>
+ <ol class="block">
+ <li>Let <i>Pk</i> be <a href="#sec-tostring">ToString</a>(<i>k</i>).</li>
+ <li>Let <i>kValue</i> be <a href="#sec-get-o-p">Get</a>(<i>items</i>, <i>Pk</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>kValue</i>).</li>
+ <li>If <i>mapping</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>mappedValue</i> be the result of calling the [[Call]] internal method of <i>mapfn</i> with <i>T</i>
+ as <i>thisArgument</i> and (<i>kValue</i>, <i>k</i>) as <i>argumentsList</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>mappedValue</i>).</li>
+ </ol>
+ </li>
+ <li>Else, let <i>mappedValue</i> be <i>kValue</i>.</li>
+ <li>Let <i>defineStatus</i> be <a href="#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a>(<i>A</i>,
+ <i>Pk</i>, <i>mappedValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>defineStatus</i>).</li>
+ <li>Increase <i>k</i> by 1.</li>
+ </ol>
+ </li>
+ <li>Let <i>putStatus</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>A</i>, <code>"length"</code>, <i>len</i>,
+ <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>putStatus</i>).</li>
+ <li>Return <i>A</i>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>from</code> method is <b>1</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>from</code> function is an intentionally generic factory method; it does not
+ require that its <b>this</b> value be the Array constructor. Therefore it can be transferred to or inherited by any
+ other constructors that may be called with a single numeric argument.</p>
+ </div>
+ </section>
+
+ <section id="sec-array.isarray">
+ <h1><span class="secnum" id="sec-22.1.2.2"><a href="#sec-array.isarray" title="link to this section">22.1.2.2</a></span>
+ Array.isArray ( arg )</h1>
+
+ <p>The <code>isArray</code> function takes one argument <var>arg</var>, and performs the following:</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>arg</i>) is not Object, return <b>false</b>.</li>
+ <li>If <i>arg</i> is an exotic Array object, then return <b>true</b>.</li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-array.of">
+ <h1><span class="secnum" id="sec-22.1.2.3"><a href="#sec-array.of" title="link to this section">22.1.2.3</a></span>
+ Array.of ( ...items )</h1>
+
+ <p>When the <code>of</code> method is called with any number of arguments, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>len</i> be the actual number of arguments passed to this function.</li>
+ <li>Let <i>items</i> be the <a href="#sec-list-and-record-specification-type">List</a> of arguments passed to this
+ function.</li>
+ <li>Let <i>C</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-isconstructor">IsConstructor</a>(<i>C</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>A</i> be the result of calling the [[Construct]] internal method of <i>C</i> with an argument list
+ containing the single item <i>len</i>.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>A</i> be <a href="#sec-arraycreate">ArrayCreate</a>(<i>len</i>).</li>
+ </ol>
+ </li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>A</i>).</li>
+ <li>Let <i>k</i> be 0.</li>
+ <li>Repeat, while <i>k</i> < <i>len</i>
+ <ol class="block">
+ <li>Let <i>kValue</i> be element <i>k</i> of <i>items</i>.</li>
+ <li>Let <i>defineStatus</i> be <a
+ href="#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a>(<i>A</i>,<i>Pk</i>,
+ <i>kValue</i>.[[value]]).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>defineStatus</i>).</li>
+ <li>Increase <i>k</i> by 1.</li>
+ </ol>
+ </li>
+ <li>Let <i>putStatus</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>A</i>, <code>"length"</code>, <i>len</i>,
+ <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>putStatus</i>).</li>
+ <li>Return <i>A</i>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>of</code> method is <b>0</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> The <i>items</i> argument is assumed to be a well-formed rest argument value.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 2</span> The <code>of</code> function is an intentionally generic factory method; it does not
+ require that its <b>this</b> value be the Array constructor. Therefore it can be transferred to or inherited by other
+ constructors that may be called with a single numeric argument.</p>
+ </div>
+ </section>
+
+ <section id="sec-array.prototype">
+ <h1><span class="secnum" id="sec-22.1.2.4"><a href="#sec-array.prototype" title="link to this section">22.1.2.4</a></span>
+ Array.prototype</h1>
+
+ <p>The value of <code>Array.prototype</code> is %ArrayPrototype%, the intrinsic Array prototype object (<a
+ href="#sec-properties-of-the-array-prototype-object">22.1.3</a>).</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-array-@@create">
+ <h1><span class="secnum" id="sec-22.1.2.5"><a href="#sec-array-@@create" title="link to this section">22.1.2.5</a></span>
+ Array[ @@create ] ( )</h1>
+
+ <p>The @@create method of an object <var>F</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be the <b>this</b> value.</li>
+ <li>Let <i>proto</i> be <a href="#sec-getprototypefromconstructor">GetPrototypeFromConstructor</a>(<i>F</i>,
+ <code>"%ArrayPrototype%"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>proto</i>).</li>
+ <li>Let <i>obj</i> be <a href="#sec-arraycreate">ArrayCreate</a>(<b>undefined</b>, <i>proto</i>).</li>
+ <li>Return <i>obj</i>.</li>
+ </ol>
+
+ <p>The value of the <code>name</code> property of this function is <code>"[Symbol.create]"</code>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>true</b> }.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> Passing <b>undefined</b> as the first argument to <a
+ href="#sec-arraycreate">ArrayCreate</a> causes the [[ArrayInitializationState]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the array to be initially assigned the value
+ <b>false</b>. This is a flag used to indicate that the instance has not yet been initialized by the <code>Array</code>
+ constructor. This flag value is never directly exposed to ECMAScript code; hence implementations may choose to encode
+ the flag in any unobservable manner.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 2</span> The Array <code>@@create</code> function is intentionally generic; it does not require
+ that its <b>this</b> value be the Array constructor object. It can be transferred to other constructor functions for use
+ as a <code>@@create</code> method. When used with other constructors, this function will create an exotic Array object
+ whose [[Prototype]] value is obtained from the associated constructor.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-array-prototype-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-22.1.3"><a href="#sec-properties-of-the-array-prototype-object"
+ title="link to this section">22.1.3</a></span> Properties of the Array Prototype Object</h1>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the Array
+ prototype object is the intrinsic object %ObjectPrototype%.</p>
+
+ <p>The Array prototype object is itself an ordinary object. It is not an Array instance and does not have a
+ <code>length</code> property .</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The Array prototype object does not have a <code>valueOf</code> property of its own;
+ however, it inherits the <code>valueOf</code> property from the standard built-in Object prototype Object.</p>
+ </div>
+ </div>
+
+ <section id="sec-array.prototype.concat">
+ <div class="front">
+ <h1><span class="secnum" id="sec-22.1.3.1"><a href="#sec-array.prototype.concat"
+ title="link to this section">22.1.3.1</a></span> Array.prototype.concat ( ...arguments )</h1>
+
+ <p>When the <code>concat</code> method is called with zero or more arguments, it returns an array containing the array
+ elements of the object followed by the array elements of each argument in order.</p>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the result of calling <a href="#sec-toobject">ToObject</a> passing the <b>this</b> value as the
+ argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>O</i>).</li>
+ <li>Let <i>A</i> be <b>undefined</b>.</li>
+ <li>If <i>O</i> is an exotic Array object, then
+ <ol class="block">
+ <li>Let <i>C</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <code>"constructor"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>C</i>).</li>
+ <li>If <a href="#sec-isconstructor">IsConstructor</a>(<i>C</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>thisRealm</i> be <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-code-realms">Realm</a>.</li>
+ <li>If <i>thisRealm</i> and the value of <i>C’s</i> [[Realm]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> are the same value, then
+ <ol class="block">
+ <li>Let <i>A</i> be the result of calling the [[Construct]] internal method of <i>C</i> with argument
+ (0).</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>If <i>A</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>A</i> be <a href="#sec-arraycreate">ArrayCreate</a>(0).</li>
+ </ol>
+ </li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>A</i>).</li>
+ <li>Let <i>n</i> be 0.</li>
+ <li>Let <i>items</i> be a <a href="#sec-list-and-record-specification-type">List</a> whose first element is <i>O</i>
+ and whose subsequent elements are, in left to right order, the arguments that were passed to this function
+ invocation.</li>
+ <li>Repeat, while <i>items</i> is not empty
+ <ol class="block">
+ <li>Remove the first element from <i>items</i> and let <i>E</i> be the value of the element.</li>
+ <li>Let <i>spreadable</i> be <a href="#sec-isconcatspreadable">IsConcatSpreadable</a>(<i>E</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>spreadable</i>).</li>
+ <li>If <i>spreadable</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>k</i> be 0.</li>
+ <li>Let <i>lenVal</i> be <a href="#sec-get-o-p">Get</a>(<i>E</i>, <code>"length"</code>).</li>
+ <li>Let <i>len</i> be <a href="#sec-tolength">ToLength</a>(<i>lenVal</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>len</i>).</li>
+ <li>Repeat, while <i>k</i> < <i>len</i>
+ <ol class="block">
+ <li>Let <i>P</i> be <a href="#sec-tostring">ToString</a>(<i>k</i>).</li>
+ <li>Let <i>exists</i> be <a href="#sec-hasproperty">HasProperty</a>(<i>E</i>, <i>P</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>exists</i>).</li>
+ <li>If <i>exists</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>subElement</i> be <a href="#sec-get-o-p">Get</a>(<i>E</i>, <i>P</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>subElement</i>).</li>
+ <li>Let <i>status</i> be <a href="#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a>
+ (<i>A</i>, <a href="#sec-tostring">ToString</a>(<i>n</i>), <i>subElement</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ </ol>
+ </li>
+ <li>Increase <i>n</i> by 1.</li>
+ <li>Increase <i>k</i> by 1.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Else <i>E</i> is added as a single item rather than spread,
+ <ol class="block">
+ <li>Let <i>status</i> be <a href="#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a> (<i>A</i>, <a
+ href="#sec-tostring">ToString</a>(<i>n</i>), <i>E</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Increase <i>n</i> by 1.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Let <i>putStatus</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>A</i>, <code>"length"</code>, <i>n</i>,
+ <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>putStatus</i>).</li>
+ <li>Return <i>A</i>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>concat</code> method is <b>1</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> The explicit setting of the <code>length</code> property in step 10 is necessary to
+ ensure that its value is correct in situations where the trailing elements of the result Array are not present.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 2</span> The <code>concat</code> function is intentionally generic; it does not require that
+ its <b>this</b> value be an Array object. Therefore it can be transferred to other kinds of objects for use as a
+ method. Whether the <code>concat</code> function can be applied successfully to an exotic object that is not an Array
+ is implementation-dependent.</p>
+ </div>
+ </div>
+
+ <section id="sec-isconcatspreadable">
+ <h1><span class="secnum" id="sec-22.1.3.1.1"><a href="#sec-isconcatspreadable"
+ title="link to this section">22.1.3.1.1</a></span> IsConcatSpreadable ( O ) Abstract Operation</h1>
+
+ <p>The abstract operation IsConcatSpreadable with argument <i>O</i> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object, then return
+ <b>false</b>.</li>
+ <li>Let <i>spreadable</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, @@isConcatSpreadable).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>spreadable</i>).</li>
+ <li>If <i>spreadable</i> is not <b>undefined</b>, then return <a
+ href="#sec-toboolean">ToBoolean</a>(<i>spreadable</i>).</li>
+ <li>If <i>O</i> is an exotic Array object, then return <b>true</b>.</li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-array.prototype.constructor">
+ <h1><span class="secnum" id="sec-22.1.3.2"><a href="#sec-array.prototype.constructor"
+ title="link to this section">22.1.3.2</a></span> Array.prototype.constructor</h1>
+
+ <p>The initial value of <code>Array.prototype.constructor</code> is the standard built-in <code>Array</code>
+ constructor.</p>
+ </section>
+
+ <section id="sec-array.prototype.copywithin">
+ <h1><span class="secnum" id="sec-22.1.3.3"><a href="#sec-array.prototype.copywithin"
+ title="link to this section">22.1.3.3</a></span> Array.prototype.copyWithin (target, start [ , end ] )</h1>
+
+ <p>The <code>copyWithin</code> method takes up to three arguments <var>target</var>, <var>start</var> and
+ <var>end</var>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <i>end</i> argument is optional with the length of the <b>this</b> object as its
+ default value. If <i>target</i> is negative, it is treated as <i>length</i>+<i>target</i> where <i>length</i> is the
+ length of the array. If <i>start</i> is negative, it is treated as <i>length</i>+<i>start</i>. If <i>end</i> is
+ negative, it is treated as <i>length</i>+<i>end</i>.</p>
+ </div>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the result of calling <a href="#sec-toobject">ToObject</a> passing the <b>this</b> value as the
+ argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>O</i>).</li>
+ <li>Let <i>lenVal</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <code>"length"</code>).</li>
+ <li>Let <i>len</i> be <a href="#sec-tolength">ToLength</a>(<i>lenVal</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>len</i>).</li>
+ <li>Let <i>relativeTarget</i> be <a href="#sec-tointeger">ToInteger</a>(<i>target</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>relativeTarget</i>).</li>
+ <li>If <i>relativeTarget</i> is negative, let <i>to</i> be max((<i>len</i> + <i>relativeTarget</i>),0); else let
+ <i>to</i> be min(<i>relativeTarget</i>, <i>len</i>).</li>
+ <li>Let <i>relativeStart</i> be <a href="#sec-tointeger">ToInteger</a>(<i>start</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>relativeStart</i>).</li>
+ <li>If <i>relativeStart</i> is negative, let <i>from</i> be max((<i>len</i> + <i>relativeStart</i>),0); else let
+ <i>from</i> be min(<i>relativeStart</i>, <i>len</i>).</li>
+ <li>If <i>end</i> is <b>undefined</b>, let <i>relativeEnd</i> be <i>len</i>; else let <i>relativeEnd</i> be <a
+ href="#sec-tointeger">ToInteger</a>(<i>end</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>relativeEnd</i>).</li>
+ <li>If <i>relativeEnd</i> is negative, let <i>final</i> be max((<i>len</i> + <i>relativeEnd</i>),0); else let
+ <i>final</i> be min(<i>relativeEnd</i>, <i>len</i>).</li>
+ <li>Let <i>count</i> be min(<i>final</i>-<i>from</i>, <i>len</i>-<i>to</i>).</li>
+ <li>If <i>from</i><<i>to</i> and <i>to</i><<i>from</i>+<i>count</i>
+ <ol class="block">
+ <li>Let <i>direction</i> = -1.</li>
+ <li>Let <i>from</i> = <i>from</i> + <i>count</i> -1.</li>
+ <li>Let <i>to</i> = <i>to</i> + <i>count</i> -1.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>direction</i> = 1.</li>
+ </ol>
+ </li>
+ <li>Repeat, while <i>count</i> > 0
+ <ol class="block">
+ <li>Let <i>fromKey</i> be <a href="#sec-tostring">ToString</a>(<i>from</i>).</li>
+ <li>Let <i>toKey</i> be <a href="#sec-tostring">ToString</a>(<i>to</i>).</li>
+ <li>Let <i>fromPresent</i> be <a href="#sec-hasproperty">HasProperty</a>(<i>O</i>, <i>fromKey</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>fromPresent</i>).</li>
+ <li>If <i>fromPresent</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>fromVal</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <i>fromKey</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>fromVal</i>).</li>
+ <li>Let <i>putStatus</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>O</i>, <i>toKey</i>, <i>fromVal</i>,
+ <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>putStatus</i>).</li>
+ </ol>
+ </li>
+ <li>Else <i>fromPresent</i> is <b>false</b>,
+ <ol class="block">
+ <li>Let <i>deleteStatus</i> be <a href="#sec-deletepropertyorthrow">DeletePropertyOrThrow</a>(<i>O</i>,
+ <i>toKey</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>deleteStatus</i>).</li>
+ </ol>
+ </li>
+ <li>Let <i>from</i> be <i>from</i> + <i>direction</i>.</li>
+ <li>Let <i>to</i> be <i>to</i> + <i>direction</i>.</li>
+ <li>Let <i>count</i> be <i>count</i> − 1.</li>
+ </ol>
+ </li>
+ <li>Return <i>O</i>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>copyWithin</code> method is <b>2</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> The <code>copyWithin</code> function is intentionally generic; it does not require
+ that its <b>this</b> value be an Array object. Therefore it can be transferred to other kinds of objects for use as a
+ method. Whether the <code>copyWithin</code> function can be applied successfully to an exotic object that is not an
+ Array is implementation-dependent.</p>
+ </div>
+ </section>
+
+ <section id="sec-array.prototype.entries">
+ <h1><span class="secnum" id="sec-22.1.3.4"><a href="#sec-array.prototype.entries"
+ title="link to this section">22.1.3.4</a></span> Array.prototype.entries ( )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the result of calling <a href="#sec-toobject">ToObject</a> with the <b>this</b> value as its
+ argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>O</i>).</li>
+ <li>Return <a href="#sec-createarrayiterator">CreateArrayIterator</a>(<i>O</i>, <code>"key+value"</code>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-array.prototype.every">
+ <h1><span class="secnum" id="sec-22.1.3.5"><a href="#sec-array.prototype.every"
+ title="link to this section">22.1.3.5</a></span> Array.prototype.every ( callbackfn [ , thisArg] )</h1>
+
+ <p class="Note"><span style="font-family: sans-serif">NOTE</span>	<i>callbackfn</i> should be a function that accepts
+ three arguments and returns a value that is coercible to the Boolean value <b>true</b> or <b>false</b>. <code>every</code>
+ calls <i>callbackfn</i> once for each element present in the array, in ascending order, until it finds one where
+ <i>callbackfn</i> returns <b>false</b>. If such an element is found, <code>every</code> immediately returns <b>false</b>.
+ Otherwise, if <i>callbackfn</i> returned <b>true</b> for all elements, <code>every</code> will return <b>true</b>.
+ <i>callbackfn</i> is called only for elements of the array which actually exist; it is not called for missing elements of
+ the array.</p>
+
+ <p class="Note">If a <i>thisArg</i> parameter is provided, it will be used as the <b>this</b> value for each invocation of
+ <i>callbackfn</i>. If it is not provided, <b>undefined</b> is used instead.</p>
+
+ <p class="Note"><i>callbackfn</i> is called with three arguments: the value of the element, the index of the element, and
+ the object being traversed.</p>
+
+ <p class="Note"><code>every</code> does not directly mutate the object on which it is called but the object may be mutated
+ by the calls to <i>callbackfn</i>.</p>
+
+ <p class="Note">The range of elements processed by <code>every</code> is set before the first call to <i>callbackfn</i>.
+ Elements which are appended to the array after the call to <code>every</code> begins will not be visited by
+ <i>callbackfn</i>. If existing elements of the array are changed, their value as passed to <i>callbackfn</i> will be the
+ value at the time <code>every</code> visits them; elements that are deleted after the call to <code>every</code> begins
+ and before being visited are not visited. <code>every</code> acts like the "for all" quantifier in mathematics. In
+ particular, for an empty array, it returns <b>true</b>.</p>
+
+ <p>When the <code>every</code> method is called with one or two arguments, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the result of calling <a href="#sec-toobject">ToObject</a> passing the <b>this</b> value as the
+ argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>O</i>).</li>
+ <li>Let <i>lenValue</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <code>"length"</code>)</li>
+ <li>Let <i>len</i> be <a href="#sec-tolength">ToLength</a>(<i>lenValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>len</i>).</li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>callbackfn</i>) is <b>false</b>, throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>thisArg</i> was supplied, let <i>T</i> be <i>thisArg</i>; else let <i>T</i> be <b>undefined</b>.</li>
+ <li>Let <i>k</i> be 0.</li>
+ <li>Repeat, while <i>k</i> < <i>len</i>
+ <ol class="block">
+ <li>Let <i>Pk</i> be <a href="#sec-tostring">ToString</a>(<i>k</i>).</li>
+ <li>Let <i>kPresent</i> be <a href="#sec-hasproperty">HasProperty</a>(<i>O</i>, <i>Pk</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>kPresent</i>).</li>
+ <li>If <i>kPresent</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>kValue</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <i>Pk</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>kValue</i>).</li>
+ <li>Let <i>testResult</i> be the result of calling the [[Call]] internal method of <i>callbackfn</i> with
+ <i>T</i> as <i>thisArgument</i> and a <a href="#sec-list-and-record-specification-type">List</a> containing
+ <i>kValue</i>, <i>k</i>, and <i>O</i> as <i>argumentsList</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>testResult</i>).</li>
+ <li>If <a href="#sec-toboolean">ToBoolean</a>(<i>testResult)</i> is <b>false</b>, return <b>false</b>.</li>
+ </ol>
+ </li>
+ <li>Increase <i>k</i> by 1.</li>
+ </ol>
+ </li>
+ <li>Return <b>true</b>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>every</code> method is <b>1</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>every</code> function is intentionally generic; it does not require that its
+ <b>this</b> value be an Array object. Therefore it can be transferred to other kinds of objects for use as a method.
+ Whether the <code>every</code> function can be applied successfully to an exotic object that is not an Array is
+ implementation-dependent.</p>
+ </div>
+ </section>
+
+ <section id="sec-array.prototype.fill">
+ <h1><span class="secnum" id="sec-22.1.3.6"><a href="#sec-array.prototype.fill"
+ title="link to this section">22.1.3.6</a></span> Array.prototype.fill (value [ , start [ , end ] ] )</h1>
+
+ <p>The <code>fill</code> method takes up to three arguments <var>value</var>, <var>start</var> and <var>end</var>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <i>start</i> and <i>end</i> arguments are optional with default values of 0 and the
+ length of the <b>this</b> object. If <i>start</i> is negative, it is treated as <i>length</i>+<i>start</i> where
+ <i>length</i> is the length of the array. If <i>end</i> is negative, it is treated as <i>length</i>+<i>end</i>.</p>
+ </div>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the result of calling <a href="#sec-toobject">ToObject</a> passing the <b>this</b> value as the
+ argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>O</i>).</li>
+ <li>Let <i>lenVal</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <code>"length"</code>).</li>
+ <li>Let <i>len</i> be <a href="#sec-tolength">ToLength</a>(<i>lenVal</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>len</i>).</li>
+ <li>Let <i>relativeStart</i> be <a href="#sec-tointeger">ToInteger</a>(<i>start</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>relativeStart</i>).</li>
+ <li>If <i>relativeStart</i> is negative, let <i>k</i> be max((<i>len</i> + <i>relativeStart</i>),0); else let <i>k</i>
+ be min(<i>relativeStart</i>, <i>len</i>).</li>
+ <li>If <i>end</i> is <b>undefined</b>, let <i>relativeEnd</i> be <i>len</i>; else let <i>relativeEnd</i> be <a
+ href="#sec-tointeger">ToInteger</a>(<i>end</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>relativeEnd</i>).</li>
+ <li>If <i>relativeEnd</i> is negative, let <i>final</i> be max((<i>len</i> + <i>relativeEnd</i>),0); else let
+ <i>final</i> be min(<i>relativeEnd</i>, <i>len</i>).</li>
+ <li>Repeat, while <i>k</i> < <i>final</i>
+ <ol class="block">
+ <li>Let <i>Pk</i> be <a href="#sec-tostring">ToString</a>(<i>k</i>).</li>
+ <li>Let <i>putStatus</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>O</i>, <i>Pk</i>, <i>value</i>,
+ <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>putStatus</i>).</li>
+ <li>Increase <i>k</i> by 1.</li>
+ </ol>
+ </li>
+ <li>Return <i>O</i>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>fill</code> method is <b>1</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> The <code>fill</code> function is intentionally generic; it does not require that its
+ <b>this</b> value be an Array object. Therefore it can be transferred to other kinds of objects for use as a method.
+ Whether the <code>fill</code> function can be applied successfully to an exotic object that is not an Array is
+ implementation-dependent.</p>
+ </div>
+ </section>
+
+ <section id="sec-array.prototype.filter">
+ <h1><span class="secnum" id="sec-22.1.3.7"><a href="#sec-array.prototype.filter"
+ title="link to this section">22.1.3.7</a></span> Array.prototype.filter ( callbackfn [ , thisArg ] )</h1>
+
+ <p class="Note"><span style="font-family: sans-serif">NOTE</span>	<i>callbackfn</i> should be a function that accepts
+ three arguments and returns a value that is coercible to the Boolean value <b>true</b> or <b>false</b>.
+ <code>filter</code> calls <i>callbackfn</i> once for each element in the array, in ascending order, and constructs a new
+ array of all the values for which <i>callbackfn</i> returns <b>true</b>. <i>callbackfn</i> is called only for elements of
+ the array which actually exist; it is not called for missing elements of the array.</p>
+
+ <p class="Note">If a <i>thisArg</i> parameter is provided, it will be used as the <b>this</b> value for each invocation of
+ <i>callbackfn</i>. If it is not provided, <b>undefined</b> is used instead.</p>
+
+ <p class="Note"><i>callbackfn</i> is called with three arguments: the value of the element, the index of the element, and
+ the object being traversed.</p>
+
+ <p class="Note"><code>filter</code> does not directly mutate the object on which it is called but the object may be
+ mutated by the calls to <i>callbackfn</i>.</p>
+
+ <p class="Note">The range of elements processed by <code>filter</code> is set before the first call to <i>callbackfn</i>.
+ Elements which are appended to the array after the call to <code>filter</code> begins will not be visited by
+ <i>callbackfn</i>. If existing elements of the array are changed their value as passed to <i>callbackfn</i> will be the
+ value at the time <code>filter</code> visits them; elements that are deleted after the call to <code>filter</code> begins
+ and before being visited are not visited.</p>
+
+ <p>When the <code>filter</code> method is called with one or two arguments, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the result of calling <a href="#sec-toobject">ToObject</a> passing the <b>this</b> value as the
+ argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>O</i>).</li>
+ <li>Let <i>lenValue</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <code>"length"</code>).</li>
+ <li>Let <i>len</i> be <a href="#sec-tolength">ToLength</a>(<i>lenValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>len</i>).</li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>callbackfn</i>) is <b>false</b>, throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>thisArg</i> was supplied, let <i>T</i> be <i>thisArg</i>; else let <i>T</i> be <b>undefined</b>.</li>
+ <li>Let <i>A</i> be <b>undefined</b>.</li>
+ <li>If <i>O</i> is an exotic Array object, then
+ <ol class="block">
+ <li>Let <i>C</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <code>"constructor"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>C</i>).</li>
+ <li>If <a href="#sec-isconstructor">IsConstructor</a>(<i>C</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>thisRealm</i> be <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-code-realms">Realm</a>.</li>
+ <li>If <i>thisRealm</i> and the value of <i>C’s</i> [[Realm]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> are the same value, then
+ <ol class="block">
+ <li>Let <i>A</i> be the result of calling the [[Construct]] internal method of <i>C</i> with an argument
+ list containing the single item 0.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>If <i>A</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>A</i> be <a href="#sec-arraycreate">ArrayCreate</a>(0).</li>
+ </ol>
+ </li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>A</i>).</li>
+ <li>Let <i>k</i> be 0.</li>
+ <li>Let <i>to</i> be 0.</li>
+ <li>Repeat, while <i>k</i> < <i>len</i>
+ <ol class="block">
+ <li>Let <i>Pk</i> be <a href="#sec-tostring">ToString</a>(<i>k</i>).</li>
+ <li>Let <i>kPresent</i> be <a href="#sec-hasproperty">HasProperty</a>(<i>O</i>, <i>Pk</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>kPresent</i>).</li>
+ <li>If <i>kPresent</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>kValue</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <i>Pk</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>kValue</i>).</li>
+ <li>Let <i>selected</i> be the result of calling the [[Call]] internal method of <i>callbackfn</i> with <i>T</i>
+ as <i>thisArgument</i> and a <a href="#sec-list-and-record-specification-type">List</a> containing
+ <i>kValue</i>, <i>k</i>, and <i>O</i> as <i>argumentsList</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>selected</i>).</li>
+ <li>If <a href="#sec-toboolean">ToBoolean</a>(<i>selected</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>status</i> be <a href="#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a> (<i>A</i>,
+ <a href="#sec-tostring">ToString</a>(<i>to</i>), <i>kValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Increase <i>to</i> by 1.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Increase <i>k</i> by 1.</li>
+ </ol>
+ </li>
+ <li>Return <i>A</i>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>filter</code> method is <b>1</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>filter</code> function is intentionally generic; it does not require that its
+ <b>this</b> value be an Array object. Therefore it can be transferred to other kinds of objects for use as a method.
+ Whether the <code>filter</code> function can be applied successfully to an exotic object that is not an Array is
+ implementation-dependent.</p>
+ </div>
+ </section>
+
+ <section id="sec-array.prototype.find">
+ <h1><span class="secnum" id="sec-22.1.3.8"><a href="#sec-array.prototype.find"
+ title="link to this section">22.1.3.8</a></span> Array.prototype.find ( predicate [ , thisArg ] )</h1>
+
+ <p class="Note"><span style="font-family: sans-serif">NOTE</span>	<i>predicate</i> should be a function that accepts
+ three arguments and returns a value that is coercible to the Boolean value <b>true</b> or <b>false</b>. <code>find</code>
+ calls <i>predicate</i> once for each element present in the array, in ascending order, until it finds one where
+ <i>predicate</i> returns <b>true</b>. If such an element is found, <code>find</code> immediately returns that element
+ value. Otherwise, <code>find</code> returns <b>undefined</b>. <i>predicate</i> is called only for elements of the array
+ which actually exist; it is not called for missing elements of the array.</p>
+
+ <p class="Note">If a <i>thisArg</i> parameter is provided, it will be used as the <b>this</b> value for each invocation of
+ <i>predicate</i>. If it is not provided, <b>undefined</b> is used instead.</p>
+
+ <p class="Note"><i>predicate</i> is called with three arguments: the value of the element, the index of the element, and
+ the object being traversed.</p>
+
+ <p class="Note"><code>find</code> does not directly mutate the object on which it is called but the object may be mutated
+ by the calls to <i>predicate</i>.</p>
+
+ <p class="Note">The range of elements processed by <code>find</code> is set before the first call to <i>callbackfn</i>.
+ Elements that are appended to the array after the call to <code>find</code> begins will not be visited by
+ <i>callbackfn</i>. If existing elements of the array are changed, their value as passed to <i>predicate</i> will be the
+ value at the time that <code>find</code> visits them; elements that are deleted after the call to <code>find</code> begins
+ and before being visited are not visited.</p>
+
+ <p>When the <code>find</code> method is called with one or two arguments, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the result of calling <a href="#sec-toobject">ToObject</a> passing the <b>this</b> value as the
+ argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>O</i>).</li>
+ <li>Let <i>lenValue</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <code>"length"</code>).</li>
+ <li>Let <i>len</i> be <a href="#sec-tolength">ToLength</a>(<i>lenValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>len</i>).</li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>predicate</i>) is <b>false</b>, throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>thisArg</i> was supplied, let <i>T</i> be <i>thisArg</i>; else let <i>T</i> be <b>undefined</b>.</li>
+ <li>Let <i>k</i> be 0.</li>
+ <li>Repeat, while <i>k</i> < <i>len</i>
+ <ol class="block">
+ <li>Let <i>Pk</i> be <a href="#sec-tostring">ToString</a>(<i>k</i>).</li>
+ <li>Let <i>kPresent</i> be <a href="#sec-hasproperty">HasProperty</a>(<i>O</i>, <i>Pk</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>kPresent</i>).</li>
+ <li>If <i>kPresent</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>kValue</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <i>Pk</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>kValue</i>).</li>
+ <li>Let <i>testResult</i> be the result of calling the [[Call]] internal method of <i>predicate</i> with
+ <i>T</i> as <i>thisArgument</i> and a <a href="#sec-list-and-record-specification-type">List</a> containing
+ <i>kValue</i>, <i>k</i>, and <i>O</i> as <i>argumentsList</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>testResult</i>).</li>
+ <li>If <a href="#sec-toboolean">ToBoolean</a>(<i>testResult)</i> is <b>true</b>, return <i>kValue</i>.</li>
+ </ol>
+ </li>
+ <li>Increase <i>k</i> by 1.</li>
+ </ol>
+ </li>
+ <li>Return <b>undefined</b>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>find</code> method is <b>1</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>find</code> function is intentionally generic; it does not require that its
+ <b>this</b> value be an Array object. Therefore it can be transferred to other kinds of objects for use as a method.
+ Whether the <code>find</code> function can be applied successfully to an exotic object that is not an Array is
+ implementation-dependent.</p>
+ </div>
+ </section>
+
+ <section id="sec-array.prototype.findindex">
+ <h1><span class="secnum" id="sec-22.1.3.9"><a href="#sec-array.prototype.findindex"
+ title="link to this section">22.1.3.9</a></span> Array.prototype.findIndex ( predicate [ , thisArg ] )</h1>
+
+ <p class="Note"><span style="font-family: sans-serif">NOTE</span>	<i>predicate</i> should be a function that accepts
+ three arguments and returns a value that is coercible to the Boolean value <b>true</b> or <b>false</b>.
+ <code>findIndex</code> calls <i>predicate</i> once for each element present in the array, in ascending order, until it
+ finds one where <i>predicate</i> returns <b>true</b>. If such an element is found, <code>findIndex</code> immediately
+ returns the index of that element value. Otherwise, <code>findIndex</code> returns -1. <i>predicate</i> is called only for
+ elements of the array which actually exist; it is not called for missing elements of the array.</p>
+
+ <p class="Note">If a <i>thisArg</i> parameter is provided, it will be used as the <b>this</b> value for each invocation of
+ <i>predicate</i>. If it is not provided, <b>undefined</b> is used instead.</p>
+
+ <p class="Note"><i>predicate</i> is called with three arguments: the value of the element, the index of the element, and
+ the object being traversed.</p>
+
+ <p class="Note"><code>findIndex</code> does not directly mutate the object on which it is called but the object may be
+ mutated by the calls to <i>predicate</i>.</p>
+
+ <p class="Note">The range of elements processed by <code>findIndex</code> is set before the first call to
+ <i>callbackfn</i>. Elements that are appended to the array after the call to <code>findIndex</code> begins will not be
+ visited by <i>callbackfn</i>. If existing elements of the array are changed, their value as passed to <i>predicate</i>
+ will be the value at the time that <code>findIndex</code> visits them; elements that are deleted after the call to
+ <code>findIndex</code> begins and before being visited are not visited.</p>
+
+ <p>When the <code>findIndex</code> method is called with one or two arguments, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the result of calling <a href="#sec-toobject">ToObject</a> passing the <b>this</b> value as the
+ argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>O</i>).</li>
+ <li>Let <i>lenValue</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <code>"length"</code>).</li>
+ <li>Let <i>len</i> be <a href="#sec-tolength">ToLength</a>(<i>lenValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>len</i>).</li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>predicate</i>) is <b>false</b>, throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>thisArg</i> was supplied, let <i>T</i> be <i>thisArg</i>; else let <i>T</i> be <b>undefined</b>.</li>
+ <li>Let <i>k</i> be 0.</li>
+ <li>Repeat, while <i>k</i> < <i>len</i>
+ <ol class="block">
+ <li>Let <i>Pk</i> be <a href="#sec-tostring">ToString</a>(<i>k</i>).</li>
+ <li>Let <i>kPresent</i> be <a href="#sec-hasproperty">HasProperty</a>(<i>O</i>, <i>Pk</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>kPresent</i>).</li>
+ <li>If <i>kPresent</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>kValue</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <i>Pk</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>kValue</i>).</li>
+ <li>Let <i>testResult</i> be the result of calling the [[Call]] internal method of <i>predicate</i> with
+ <i>T</i> as <i>thisArgument</i> and a <a href="#sec-list-and-record-specification-type">List</a> containing
+ <i>kValue</i>, <i>k</i>, and <i>O</i> as <i>argumentsList</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>testResult</i>).</li>
+ <li>If <a href="#sec-toboolean">ToBoolean</a>(<i>testResult)</i> is <b>true</b>, return <i>k</i>.</li>
+ </ol>
+ </li>
+ <li>Increase <i>k</i> by 1.</li>
+ </ol>
+ </li>
+ <li>Return -1.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>findIndex</code> method is <b>1</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>findIndex</code> function is intentionally generic; it does not require that
+ its <b>this</b> value be an Array object. Therefore it can be transferred to other kinds of objects for use as a method.
+ Whether the <code>findIndex</code> function can be applied successfully to an exotic object that is not an Array is
+ implementation-dependent.</p>
+ </div>
+ </section>
+
+ <section id="sec-array.prototype.foreach">
+ <h1><span class="secnum" id="sec-22.1.3.10"><a href="#sec-array.prototype.foreach"
+ title="link to this section">22.1.3.10</a></span> Array.prototype.forEach ( callbackfn [ , thisArg ] )</h1>
+
+ <p class="Note"><span style="font-family: sans-serif">NOTE</span>	<i>callbackfn</i> should be a function that accepts
+ three arguments. <code>forEach</code> calls <i>callbackfn</i> once for each element present in the array, in ascending
+ order. <i>callbackfn</i> is called only for elements of the array which actually exist; it is not called for missing
+ elements of the array.</p>
+
+ <p class="Note">If a <i>thisArg</i> parameter is provided, it will be used as the <b>this</b> value for each invocation of
+ <i>callbackfn</i>. If it is not provided, <b>undefined</b> is used instead.</p>
+
+ <p class="Note"><i>callbackfn</i> is called with three arguments: the value of the element, the index of the element, and
+ the object being traversed.</p>
+
+ <p class="Note"><code>forEach</code> does not directly mutate the object on which it is called but the object may be
+ mutated by the calls to <i>callbackfn</i>.</p>
+
+ <p class="Note">The range of elements processed by <code>forEach</code> is set before the first call to <i>callbackfn</i>.
+ Elements which are appended to the array after the call to <code>forEach</code> begins will not be visited by
+ <i>callbackfn</i>. If existing elements of the array are changed, their value as passed to callback will be the value at
+ the time <code>forEach</code> visits them; elements that are deleted after the call to <code>forEach</code> begins and
+ before being visited are not visited.</p>
+
+ <p>When the <code>forEach</code> method is called with one or two arguments, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the result of calling <a href="#sec-toobject">ToObject</a> passing the <b>this</b> value as the
+ argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>O</i>).</li>
+ <li>Let <i>lenValue</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <code>"length"</code>).</li>
+ <li>Let <i>len</i> be <a href="#sec-tolength">ToLength</a>(<i>lenValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>len</i>).</li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>callbackfn</i>) is <b>false</b>, throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>thisArg</i> was supplied, let <i>T</i> be <i>thisArg</i>; else let <i>T</i> be <b>undefined</b>.</li>
+ <li>Let <i>k</i> be 0.</li>
+ <li>Repeat, while <i>k</i> < <i>len</i>
+ <ol class="block">
+ <li>Let <i>Pk</i> be <a href="#sec-tostring">ToString</a>(<i>k</i>).</li>
+ <li>Let <i>kPresent</i> be <a href="#sec-hasproperty">HasProperty</a>(<i>O</i>, <i>Pk</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>kPresent</i>).</li>
+ <li>If <i>kPresent</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>kValue</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <i>Pk</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>kValue</i>).</li>
+ <li>Let <i>funcResult</i> be the result of calling the [[Call]] internal method of <i>callbackfn</i> with
+ <i>T</i> as <i>thisArgument</i> and a <a href="#sec-list-and-record-specification-type">List</a> containing
+ <i>kValue</i>, <i>k</i>, and <i>O</i> as <i>argumentsList</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>funcResult</i>).</li>
+ </ol>
+ </li>
+ <li>Increase <i>k</i> by 1.</li>
+ </ol>
+ </li>
+ <li>Return <b>undefined</b>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>forEach</code> method is <b>1</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>forEach</code> function is intentionally generic; it does not require that its
+ <b>this</b> value be an Array object. Therefore it can be transferred to other kinds of objects for use as a method.
+ Whether the <code>forEach</code> function can be applied successfully to an exotic object that is not an Array is
+ implementation-dependent.</p>
+ </div>
+ </section>
+
+ <section id="sec-array.prototype.indexof">
+ <h1><span class="secnum" id="sec-22.1.3.11"><a href="#sec-array.prototype.indexof"
+ title="link to this section">22.1.3.11</a></span> Array.prototype.indexOf ( searchElement [ , fromIndex ] )</h1>
+
+ <p class="Note"><span style="font-family: sans-serif">NOTE</span>	<code>indexOf</code> compares <i>searchElement</i>
+ to the elements of the array, in ascending order, using the Strict Equality Comparison algorithm (<a
+ href="#sec-strict-equality-comparison">7.2.11</a>), and if found at one or more positions, returns the index of the first
+ such position; otherwise, −1is returned.</p>
+
+ <p class="Note">The optional second argument <i>fromIndex</i> defaults to 0 (i.e. the whole array is searched). If it is
+ greater than or equal to the length of the array, −1is returned, i.e. the array will not be searched. If it is
+ negative, it is used as the offset from the end of the array to compute <i>fromIndex</i>. If the computed index is less
+ than 0, the whole array will be searched.</p>
+
+ <p>When the <code>indexOf</code> method is called with one or two arguments, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the result of calling <a href="#sec-toobject">ToObject</a> passing the <b>this</b> value as the
+ argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>O</i>).</li>
+ <li>Let <i>lenValue</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <code>"length"</code>)</li>
+ <li>Let <i>len</i> be <a href="#sec-tolength">ToLength</a>(<i>lenValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>len</i>).</li>
+ <li>If <i>len</i> is 0, return −1.</li>
+ <li>If argument <i>fromIndex</i> was passed let <i>n</i> be <a href="#sec-tointeger">ToInteger</a>(<i>fromIndex</i>);
+ else let <i>n</i> be 0.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>n</i>).</li>
+ <li>If <i>n</i> ≥ <i>len</i>, return −1.</li>
+ <li>If <i>n</i> ≥ 0, then
+ <ol class="block">
+ <li>Let <i>k</i> be <i>n</i>.</li>
+ </ol>
+ </li>
+ <li>Else <i>n</i><0,
+ <ol class="block">
+ <li>Let <i>k</i> be <i>len</i> - <a href="#sec-algorithm-conventions">abs</a>(<i>n</i>).</li>
+ <li>If <i>k</i> < 0, then let <i>k</i> be 0.</li>
+ </ol>
+ </li>
+ <li>Repeat, while <i>k</i><<i>len</i>
+ <ol class="block">
+ <li>Let <i>kPresent</i> be <a href="#sec-hasproperty">HasProperty</a>(<i>O</i>, <a
+ href="#sec-tostring">ToString</a>(<i>k</i>)).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>kPresent</i>).</li>
+ <li>If <i>kPresent</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>elementK</i> be the result of <a href="#sec-get-o-p">Get</a>(<i>O</i>, <a
+ href="#sec-tostring">ToString</a>(<i>k</i>)).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>elementK</i>).</li>
+ <li>Let <i>same</i> be the result of performing Strict Equality Comparison <i>searchElement</i> ===
+ <i>elementK</i>.</li>
+ <li>If <i>same</i> is <b>true,</b> return <i>k</i>.</li>
+ </ol>
+ </li>
+ <li>Increase <i>k</i> by 1.</li>
+ </ol>
+ </li>
+ <li>Return -1.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>indexOf</code> method is <b>1</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>indexOf</code> function is intentionally generic; it does not require that its
+ <b>this</b> value be an Array object. Therefore it can be transferred to other kinds of objects for use as a method.
+ Whether the <code>indexOf</code> function can be applied successfully to an exotic object that is not an Array is
+ implementation-dependent.</p>
+ </div>
+ </section>
+
+ <section id="sec-array.prototype.join">
+ <h1><span class="secnum" id="sec-22.1.3.12"><a href="#sec-array.prototype.join"
+ title="link to this section">22.1.3.12</a></span> Array.prototype.join (separator)</h1>
+
+ <p class="Note"><span style="font-family: sans-serif">NOTE</span>	The elements of the array are converted to Strings,
+ and these Strings are then concatenated, separated by occurrences of the <i>separator</i>. If no separator is provided, a
+ single comma is used as the separator.</p>
+
+ <p>The <code>join</code> method takes one argument, <var>separator</var>, and performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the result of calling <a href="#sec-toobject">ToObject</a> passing the <b>this</b> value as the
+ argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>O</i>).</li>
+ <li>Let <i>lenVal</i> be the result of <a href="#sec-get-o-p">Get</a>(<i>O</i>, <code>"length"</code>).</li>
+ <li>Let <i>len</i> be <a href="#sec-tolength">ToLength</a>(<i>lenVal</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>len</i>).</li>
+ <li>If <i>separator</i> is <b>undefined</b>, let <i>separator</i> be the single-element String <code>","</code>.</li>
+ <li>Let <i>sep</i> be <a href="#sec-tostring">ToString</a>(<i>separator</i>).</li>
+ <li>If <i>len</i> is zero, return the empty String.</li>
+ <li>Let <i>element0</i> be the result of <a href="#sec-get-o-p">Get</a>(<i>O</i>, <code>"0"</code>).</li>
+ <li>If <i>element0</i> is <b>undefined</b> or <b>null</b>, let <i>R</i> be the empty String; otherwise, let <i>R</i> be
+ <a href="#sec-tostring">ToString</a>(<i>element0</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>R</i>).</li>
+ <li>Let <i>k</i> be <code>1</code>.</li>
+ <li>Repeat, while <i>k</i> < <i>len</i>
+ <ol class="block">
+ <li>Let <i>S</i> be the String value produced by concatenating <i>R</i> and <i>sep</i>.</li>
+ <li>Let <i>element</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <a
+ href="#sec-tostring">ToString</a>(<i>k</i>)).</li>
+ <li>If <i>element</i> is <b>undefined</b> or <b>null</b>, then let <i>next</i> be the empty String; otherwise, let
+ <i>next</i> be <a href="#sec-tostring">ToString</a>(<i>element</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>next</i>).</li>
+ <li>Let <i>R</i> be a String value produced by concatenating <i>S</i> and <i>next</i>.</li>
+ <li>Increase <i>k</i> by 1.</li>
+ </ol>
+ </li>
+ <li>Return <i>R</i>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>join</code> method is <b>1</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>join</code> function is intentionally generic; it does not require that its
+ <b>this</b> value be an Array object. Therefore, it can be transferred to other kinds of objects for use as a method.
+ Whether the <code>join</code> function can be applied successfully to an exotic object that is not an Array is
+ implementation-dependent.</p>
+ </div>
+ </section>
+
+ <section id="sec-array.prototype.keys">
+ <h1><span class="secnum" id="sec-22.1.3.13"><a href="#sec-array.prototype.keys"
+ title="link to this section">22.1.3.13</a></span> Array.prototype.keys ( )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the result of calling <a href="#sec-toobject">ToObject</a> with the <b>this</b> value as its
+ argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>O</i>).</li>
+ <li>Return <a href="#sec-createarrayiterator">CreateArrayIterator</a>(<i>O</i>, <code>"key"</code>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-array.prototype.lastindexof">
+ <h1><span class="secnum" id="sec-22.1.3.14"><a href="#sec-array.prototype.lastindexof"
+ title="link to this section">22.1.3.14</a></span> Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] )</h1>
+
+ <p class="Note"><span style="font-family: sans-serif">NOTE</span>	<code>lastIndexOf</code> compares
+ <i>searchElement</i> to the elements of the array in descending order using the Strict Equality Comparison algorithm (<a
+ href="#sec-strict-equality-comparison">7.2.11</a>), and if found at one or more positions, returns the index of the last
+ such position; otherwise, −1is returned.</p>
+
+ <p class="Note">The optional second argument <i>fromIndex</i> defaults to the array's length minus one (i.e. the whole
+ array is searched). If it is greater than or equal to the length of the array, the whole array will be searched. If it is
+ negative, it is used as the offset from the end of the array to compute <i>fromIndex</i>. If the computed index is less
+ than 0, −1is returned.</p>
+
+ <p>When the <code>lastIndexOf</code> method is called with one or two arguments, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the result of calling <a href="#sec-toobject">ToObject</a> passing the <b>this</b> value as the
+ argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>O</i>).</li>
+ <li>Let <i>lenValue</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <code>"length"</code>)</li>
+ <li>Let <i>len</i> be <a href="#sec-tolength">ToLength</a>(<i>lenValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>len</i>).</li>
+ <li>If <i>len</i> is 0, return -1.</li>
+ <li>If argument <i>fromIndex</i> was passed let <i>n</i> be <a href="#sec-tointeger">ToInteger</a>(<i>fromIndex</i>);
+ else let <i>n</i> be <i>len</i>-1.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>n</i>).</li>
+ <li>If <i>n</i> ≥ 0, then let <i>k</i> be min(<i>n</i>, <i>len</i> – 1).</li>
+ <li>Else <i>n</i> < 0,
+ <ol class="block">
+ <li>Let <i>k</i> be <i>len</i> - <a href="#sec-algorithm-conventions">abs</a>(<i>n</i>).</li>
+ </ol>
+ </li>
+ <li>Repeat, while <i>k</i>≥ 0
+ <ol class="block">
+ <li>Let <i>kPresent</i> be <a href="#sec-hasproperty">HasProperty</a>(<i>O</i>, <a
+ href="#sec-tostring">ToString</a>(<i>k</i>)).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>kPresent</i>).</li>
+ <li>If <i>kPresent</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>elementK</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <a
+ href="#sec-tostring">ToString</a>(<i>k</i>)).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>elementK</i>).</li>
+ <li>Let <i>same</i> be the result of performing Strict Equality Comparison <br><i>searchElement</i> ===
+ <i>elementK</i>.</li>
+ <li>If <i>same</i> is <b>true,</b> return <i>k</i>.</li>
+ </ol>
+ </li>
+ <li>Decrease <i>k</i> by 1.</li>
+ </ol>
+ </li>
+ <li>Return -1.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>lastIndexOf</code> method is <b>1</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>lastIndexOf</code> function is intentionally generic; it does not require that
+ its <b>this</b> value be an Array object. Therefore it can be transferred to other kinds of objects for use as a method.
+ Whether the <code>lastIndexOf</code> function can be applied successfully to an exotic object that is not an Array is
+ implementation-dependent.</p>
+ </div>
+ </section>
+
+ <section id="sec-array.prototype.map">
+ <h1><span class="secnum" id="sec-22.1.3.15"><a href="#sec-array.prototype.map"
+ title="link to this section">22.1.3.15</a></span> Array.prototype.map ( callbackfn [ , thisArg ] )</h1>
+
+ <p class="Note"><span style="font-family: sans-serif">NOTE</span>	<i>callbackfn</i> should be a function that accepts
+ three arguments. <code>map</code> calls <i>callbackfn</i> once for each element in the array, in ascending order, and
+ constructs a new Array from the results. <i>callbackfn</i> is called only for elements of the array which actually exist;
+ it is not called for missing elements of the array.</p>
+
+ <p class="Note">If a <i>thisArg</i> parameter is provided, it will be used as the <b>this</b> value for each invocation of
+ <i>callbackfn</i>. If it is not provided, <b>undefined</b> is used instead.</p>
+
+ <p class="Note"><i>callbackfn</i> is called with three arguments: the value of the element, the index of the element, and
+ the object being traversed.</p>
+
+ <p class="Note"><code>map</code> does not directly mutate the object on which it is called but the object may be mutated
+ by the calls to <i>callbackfn</i>.</p>
+
+ <p class="Note">The range of elements processed by <code>map</code> is set before the first call to <i>callbackfn</i>.
+ Elements which are appended to the array after the call to <code>map</code> begins will not be visited by
+ <i>callbackfn</i>. If existing elements of the array are changed, their value as passed to <i>callbackfn</i> will be the
+ value at the time <code>map</code> visits them; elements that are deleted after the call to <code>map</code> begins and
+ before being visited are not visited.</p>
+
+ <p>When the <code>map</code> method is called with one or two arguments, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the result of calling <a href="#sec-toobject">ToObject</a> passing the <b>this</b> value as the
+ argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>O</i>).</li>
+ <li>Let <i>lenValue</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <code>"length"</code>)</li>
+ <li>Let <i>len</i> be <a href="#sec-tolength">ToLength</a>(<i>lenValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>len</i>).</li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>callbackfn</i>) is <b>false</b>, throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>thisArg</i> was supplied, let <i>T</i> be <i>thisArg</i>; else let <i>T</i> be <b>undefined</b>.</li>
+ <li>Let <i>A</i> be <b>undefined</b>.</li>
+ <li>If <i>O</i> is an exotic Array object, then
+ <ol class="block">
+ <li>Let <i>C</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <code>"constructor"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>C</i>).</li>
+ <li>If <a href="#sec-isconstructor">IsConstructor</a>(<i>C</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>thisRealm</i> be <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-code-realms">Realm</a>.</li>
+ <li>If <i>thisRealm</i> and the value of <i>C’s</i> [[Realm]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> are the same value, then
+ <ol class="block">
+ <li>Let <i>A</i> be the result of calling the [[Construct]] internal method of <i>C</i> with an argument
+ list containing the single item <i>len</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>If <i>A</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>A</i> be <a href="#sec-arraycreate">ArrayCreate</a>(<i>len</i>).</li>
+ </ol>
+ </li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>A</i>).</li>
+ <li>Let <i>k</i> be 0.</li>
+ <li>Repeat, while <i>k</i> < <i>len</i>
+ <ol class="block">
+ <li>Let <i>Pk</i> be <a href="#sec-tostring">ToString</a>(<i>k</i>).</li>
+ <li>Let <i>kPresent</i> be <a href="#sec-hasproperty">HasProperty</a>(<i>O</i>, <i>Pk</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>kPresent</i>).</li>
+ <li>If <i>kPresent</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>kValue</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <i>Pk</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>kValue</i>).</li>
+ <li>Let <i>mappedValue</i> be the result of calling the [[Call]] internal method of <i>callbackfn</i> with
+ <i>T</i> as <i>thisArgument</i> and a <a href="#sec-list-and-record-specification-type">List</a> containing
+ <i>kValue</i>, <i>k</i>, and <i>O</i> as <i>argumentsList</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>mappedValue</i>).</li>
+ <li>Let <i>status</i> be <a href="#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a> (<i>A</i>,
+ <i>Pk</i>, <i>mappedValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ </ol>
+ </li>
+ <li>Increase <i>k</i> by 1.</li>
+ </ol>
+ </li>
+ <li>Return <i>A</i>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>map</code> method is <b>1</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>map</code> function is intentionally generic; it does not require that its
+ <b>this</b> value be an Array object. Therefore it can be transferred to other kinds of objects for use as a method.
+ Whether the <code>map</code> function can be applied successfully to an exotic object that is not an Array is
+ implementation-dependent.</p>
+ </div>
+ </section>
+
+ <section id="sec-array.prototype.pop">
+ <h1><span class="secnum" id="sec-22.1.3.16"><a href="#sec-array.prototype.pop"
+ title="link to this section">22.1.3.16</a></span> Array.prototype.pop ( )</h1>
+
+ <p class="Note"><span style="font-family: sans-serif">NOTE</span>	The last element of the array is removed from the
+ array and returned.</p>
+
+ <p>When the <code>pop</code> method is called the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the result of calling <a href="#sec-toobject">ToObject</a> passing the <b>this</b> value as the
+ argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>O</i>).</li>
+ <li>Let <i>lenVal</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <code>"length"</code>).</li>
+ <li>Let <i>len</i> be <a href="#sec-tolength">ToLength</a>(<i>lenVal</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>len</i>).</li>
+ <li>If <i>len</i> is zero,
+ <ol class="block">
+ <li>Let <i>putStatus</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>O</i>, <code>"length"</code>, 0,
+ <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>putStatus</i>).</li>
+ <li>Return <b>undefined</b>.</li>
+ </ol>
+ </li>
+ <li>Else <i>len</i> > 0,
+ <ol class="block">
+ <li>Let <i>newLen</i> be <i>len</i>–1.</li>
+ <li>Let <i>indx</i> be <a href="#sec-tostring">ToString</a>(<i>newLen</i>).</li>
+ <li>Let <i>element</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <i>indx</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>element</i>).</li>
+ <li>Let <i>deleteStatus</i> be <a href="#sec-deletepropertyorthrow">DeletePropertyOrThrow</a>(<i>O</i>,
+ <i>indx</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>deleteStatus</i>).</li>
+ <li>Let <i>putStatus</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>O</i>, <code>"length"</code>, <i>newLen</i>,
+ <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>putStatus</i>).</li>
+ <li>Return <i>element</i>.</li>
+ </ol>
+ </li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>pop</code> function is intentionally generic; it does not require that its
+ <b>this</b> value be an Array object. Therefore it can be transferred to other kinds of objects for use as a method.
+ Whether the <code>pop</code> function can be applied successfully to an exotic object that is not an Array is
+ implementation-dependent.</p>
+ </div>
+ </section>
+
+ <section id="sec-array.prototype.push">
+ <h1><span class="secnum" id="sec-22.1.3.17"><a href="#sec-array.prototype.push"
+ title="link to this section">22.1.3.17</a></span> Array.prototype.push ( ...items )</h1>
+
+ <p class="Note"><span style="font-family: sans-serif">NOTE</span>	The arguments are appended to the end of the array,
+ in the order in which they appear. The new length of the array is returned as the result of the call.</p>
+
+ <p>When the <code>push</code> method is called with zero or more arguments the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the result of calling <a href="#sec-toobject">ToObject</a> passing the <b>this</b> value as the
+ argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>O</i>).</li>
+ <li>Let <i>lenVal</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <code>"length"</code>).</li>
+ <li>Let <i>n</i> be <a href="#sec-tolength">ToLength</a>(<i>lenVal</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>n</i>).</li>
+ <li>Let <i>items</i> be a <a href="#sec-list-and-record-specification-type">List</a> whose elements are, in left to
+ right order, the arguments that were passed to this function invocation.</li>
+ <li>Repeat, while <i>items</i> is not empty
+ <ol class="block">
+ <li>Remove the first element from <i>items</i> and let <i>E</i> be the value of the element.</li>
+ <li>Let <i>putStatus</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>O</i>, <a
+ href="#sec-tostring">ToString</a>(<i>n</i>), <i>E</i>, <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>putStatus</i>).</li>
+ <li>Increase <i>n</i> by 1.</li>
+ </ol>
+ </li>
+ <li>Let <i>putStatus</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>O</i>, <code>"length"</code>, <i>n</i>,
+ <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>putStatus</i>).</li>
+ <li>Return <i>n</i>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>push</code> method is <b>1</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>push</code> function is intentionally generic; it does not require that its
+ <b>this</b> value be an Array object. Therefore it can be transferred to other kinds of objects for use as a method.
+ Whether the <code>push</code> function can be applied successfully to an exotic object that is not an Array is
+ implementation-dependent.</p>
+ </div>
+ </section>
+
+ <section id="sec-array.prototype.reduce">
+ <h1><span class="secnum" id="sec-22.1.3.18"><a href="#sec-array.prototype.reduce"
+ title="link to this section">22.1.3.18</a></span> Array.prototype.reduce ( callbackfn [ , initialValue ] )</h1>
+
+ <p class="Note"><span style="font-family: sans-serif">NOTE</span>	<i>callbackfn</i> should be a function that takes
+ four arguments. <code>reduce</code> calls the callback, as a function, once for each element present in the array, in
+ ascending order.</p>
+
+ <p class="Note"><i>callbackfn</i> is called with four arguments: the <i>previousValue</i> (or value from the previous call
+ to <i>callbackfn</i>), the <i>currentValue</i> (value of the current element), the <i>currentIndex</i>, and the object
+ being traversed. The first time that callback is called, the <i>previousValue</i> and <i>currentValue</i> can be one of
+ two values. If an <i>initialValue</i> was provided in the call to <code>reduce</code>, then <i>previousValue</i> will be
+ equal to <i>initialValue</i> and <i>currentValue</i> will be equal to the first value in the array. If no
+ <i>initialValue</i> was provided, then <i>previousValue</i> will be equal to the first value in the array and
+ <i>currentValue</i> will be equal to the second. It is a <b>TypeError</b> if the array contains no elements and
+ <i>initialValue</i> is not provided.</p>
+
+ <p class="Note"><code>reduce</code> does not directly mutate the object on which it is called but the object may be
+ mutated by the calls to <i>callbackfn</i>.</p>
+
+ <p class="Note">The range of elements processed by <code>reduce</code> is set before the first call to <i>callbackfn</i>.
+ Elements that are appended to the array after the call to <code>reduce</code> begins will not be visited by
+ <i>callbackfn</i>. If existing elements of the array are changed, their value as passed to <i>callbackfn</i> will be the
+ value at the time <code>reduce</code> visits them; elements that are deleted after the call to <code>reduce</code> begins
+ and before being visited are not visited.</p>
+
+ <p>When the <code>reduce</code> method is called with one or two arguments, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the result of calling <a href="#sec-toobject">ToObject</a> passing the <b>this</b> value as the
+ argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>O</i>).</li>
+ <li>Let <i>lenValue</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <code>"length"</code>).</li>
+ <li>Let <i>len</i> be <a href="#sec-tolength">ToLength</a>(<i>lenValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>len</i>).</li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>callbackfn</i>) is <b>false</b>, throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>len</i> is 0 and <i>initialValue</i> is not present, throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>k</i> be 0.</li>
+ <li>If <i>initialValue</i> is present, then
+ <ol class="block">
+ <li>Set <i>accumulator</i> to <i>initialValue</i>.</li>
+ </ol>
+ </li>
+ <li>Else <i>initialValue</i> is not present,
+ <ol class="block">
+ <li>Let <i>kPresent</i> be <b>false</b>.</li>
+ <li>Repeat, while <i>kPresent</i> is <b>false</b> and <i>k</i> < <i>len</i>
+ <ol class="block">
+ <li>Let <i>Pk</i> be <a href="#sec-tostring">ToString</a>(<i>k</i>).</li>
+ <li>Let <i>kPresent</i> be <a href="#sec-hasproperty">HasProperty</a>(<i>O</i>, <i>Pk</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>kPresent</i>).</li>
+ <li>If <i>kPresent</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>accumulator</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <i>Pk</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>accumulator</i>).</li>
+ </ol>
+ </li>
+ <li>Increase <i>k</i> by 1.</li>
+ </ol>
+ </li>
+ <li>If <i>kPresent</i> is <b>false</b>, throw a <b>TypeError</b> exception.</li>
+ </ol>
+ </li>
+ <li>Repeat, while <i>k</i> < <i>len</i>
+ <ol class="block">
+ <li>Let <i>Pk</i> be <a href="#sec-tostring">ToString</a>(<i>k</i>).</li>
+ <li>Let <i>kPresent</i> be <a href="#sec-hasproperty">HasProperty</a>(<i>O</i>, <i>Pk</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>kPresent</i>).</li>
+ <li>If <i>kPresent</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>kValue</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <i>Pk</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>kValue</i>).</li>
+ <li>Let <i>accumulator</i> be the result of calling the [[Call]] internal method of <i>callbackfn</i> with
+ <b>undefined</b> as <i>thisArgument</i> and a <a href="#sec-list-and-record-specification-type">List</a>
+ containing <i>accumulator</i>, <i>kValue</i>, <i>k</i>, and <i>O</i> as <i>argumentsList</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>accumulator</i>).</li>
+ </ol>
+ </li>
+ <li>Increase <i>k</i> by 1.</li>
+ </ol>
+ </li>
+ <li>Return <i>accumulator</i>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>reduce</code> method is <b>1</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>reduce</code> function is intentionally generic; it does not require that its
+ <b>this</b> value be an Array object. Therefore it can be transferred to other kinds of objects for use as a method.
+ Whether the <code>reduce</code> function can be applied successfully to an exotic object that is not an Array is
+ implementation-dependent.</p>
+ </div>
+ </section>
+
+ <section id="sec-array.prototype.reduceright">
+ <h1><span class="secnum" id="sec-22.1.3.19"><a href="#sec-array.prototype.reduceright"
+ title="link to this section">22.1.3.19</a></span> Array.prototype.reduceRight ( callbackfn [ , initialValue ] )</h1>
+
+ <p class="Note"><span style="font-family: sans-serif">NOTE</span>	<i>callbackfn</i> should be a function that takes
+ four arguments. <code>reduceRight</code> calls the callback, as a function, once for each element present in the array, in
+ descending order.</p>
+
+ <p class="Note"><i>callbackfn</i> is called with four arguments: the <i>previousValue</i> (or value from the previous call
+ to <i>callbackfn</i>), the <i>currentValue</i> (value of the current element), the <i>currentIndex</i>, and the object
+ being traversed. The first time the function is called, the <i>previousValue</i> and <i>currentValue</i> can be one of two
+ values. If an <i>initialValue</i> was provided in the call to <code>reduceRight</code>, then <i>previousValue</i> will be
+ equal to <i>initialValue</i> and <i>currentValue</i> will be equal to the last value in the array. If no
+ <i>initialValue</i> was provided, then <i>previousValue</i> will be equal to the last value in the array and
+ <i>currentValue</i> will be equal to the second-to-last value. It is a <b>TypeError</b> if the array contains no elements
+ and <i>initialValue</i> is not provided.</p>
+
+ <p class="Note"><code>reduceRight</code> does not directly mutate the object on which it is called but the object may be
+ mutated by the calls to <i>callbackfn</i>.</p>
+
+ <p class="Note">The range of elements processed by <code>reduceRight</code> is set before the first call to
+ <i>callbackfn</i>. Elements that are appended to the array after the call to <code>reduceRight</code> begins will not be
+ visited by <i>callbackfn</i>. If existing elements of the array are changed by <i>callbackfn</i>, their value as passed to
+ <i>callbackfn</i> will be the value at the time <code>reduceRight</code> visits them; elements that are deleted after the
+ call to <code>reduceRight</code> begins and before being visited are not visited.</p>
+
+ <p>When the <code>reduceRight</code> method is called with one or two arguments, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the result of calling <a href="#sec-toobject">ToObject</a> passing the <b>this</b> value as the
+ argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>O</i>).</li>
+ <li>Let <i>lenValue</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <code>"length"</code>).</li>
+ <li>Let <i>len</i> be <a href="#sec-tolength">ToLength</a>(<i>lenValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>len</i>).</li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>callbackfn</i>) is <b>false</b>, throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>len</i> is 0 and <i>initialValue</i> is not present, throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>k</i> be <i>len</i>-1.</li>
+ <li>If <i>initialValue</i> is present, then
+ <ol class="block">
+ <li>Set <i>accumulator</i> to <i>initialValue</i>.</li>
+ </ol>
+ </li>
+ <li>Else <i>initialValue</i> is not present,
+ <ol class="block">
+ <li>Let <i>kPresent</i> be <b>false</b>.</li>
+ <li>Repeat, while <i>kPresent</i> is <b>false</b> and <i>k</i> ≥ 0
+ <ol class="block">
+ <li>Let <i>Pk</i> be <a href="#sec-tostring">ToString</a>(<i>k</i>).</li>
+ <li>Let <i>kPresent</i> be <a href="#sec-hasproperty">HasProperty</a>(<i>O</i>, <i>Pk</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>kPresent</i>).</li>
+ <li>If <i>kPresent</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>accumulator</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <i>Pk</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>accumulator</i>).</li>
+ </ol>
+ </li>
+ <li>Decrease <i>k</i> by 1.</li>
+ </ol>
+ </li>
+ <li>If <i>kPresent</i> is <b>false</b>, throw a <b>TypeError</b> exception.</li>
+ </ol>
+ </li>
+ <li>Repeat, while <i>k</i> ≥ 0
+ <ol class="block">
+ <li>Let <i>Pk</i> be <a href="#sec-tostring">ToString</a>(<i>k</i>).</li>
+ <li>Let <i>kPresent</i> be <a href="#sec-hasproperty">HasProperty</a>(<i>O</i>, <i>Pk</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>kPresent</i>).</li>
+ <li>If <i>kPresent</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>kValue</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <i>Pk</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>kValue</i>).</li>
+ <li>Let <i>accumulator</i> be the result of calling the [[Call]] internal method of <i>callbackfn</i> with
+ <b>undefined</b> as <i>thisArgument</i> and a <a href="#sec-list-and-record-specification-type">List</a>
+ containing <i>accumulator</i>, <i>kValue</i>, <i>k</i>, and <i>O</i> as <i>argumentsList</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>accumulator</i>).</li>
+ </ol>
+ </li>
+ <li>Decrease <i>k</i> by 1.</li>
+ </ol>
+ </li>
+ <li>Return <i>accumulator</i>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>reduceRight</code> method is <b>1</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>reduceRight</code> function is intentionally generic; it does not require that
+ its this value be an Array object. Therefore it can be transferred to other kinds of objects for use as a method.
+ Whether the <code>reduceRight</code> function can be applied successfully to an exotic object that is not an Array is
+ implementation-dependent.</p>
+ </div>
+ </section>
+
+ <section id="sec-array.prototype.reverse">
+ <h1><span class="secnum" id="sec-22.1.3.20"><a href="#sec-array.prototype.reverse"
+ title="link to this section">22.1.3.20</a></span> Array.prototype.reverse ( )</h1>
+
+ <p class="Note"><span style="font-family: sans-serif">NOTE</span>	The elements of the array are rearranged so as to
+ reverse their order. The object is returned as the result of the call.</p>
+
+ <p>When the <code>reverse</code> method is called the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the result of calling <a href="#sec-toobject">ToObject</a> passing the <b>this</b> value as the
+ argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>O</i>).</li>
+ <li>Let <i>lenVal</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <code>"length"</code>).</li>
+ <li>Let <i>len</i> be <a href="#sec-tolength">ToLength</a>(<i>lenVal</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>len</i>).</li>
+ <li>Let <i>middle</i> be <a href="#sec-algorithm-conventions">floor</a>(<i>len</i>/2).</li>
+ <li>Let <i>lower</i> be <b>0</b>.</li>
+ <li>Repeat, while <i>lower</i> ≠ <i>middle</i>
+ <ol class="block">
+ <li>Let <i>upper</i> be <i>len</i>− <i>lower</i> −1.</li>
+ <li>Let <i>upperP</i> be <a href="#sec-tostring">ToString</a>(<i>upper</i>).</li>
+ <li>Let <i>lowerP</i> be <a href="#sec-tostring">ToString</a>(<i>lower</i>).</li>
+ <li>Let <i>lowerExists</i> be <a href="#sec-hasproperty">HasProperty</a>(<i>O</i>, <i>lowerP</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>lowerExists</i>).</li>
+ <li>If <i>lowerExists</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>lowerValue</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <i>lowerP</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>lowerValue</i>).</li>
+ </ol>
+ </li>
+ <li>Let <i>upperExists</i> be <a href="#sec-hasproperty">HasProperty</a>(<i>O</i>, <i>upperP</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>upperExists</i>).</li>
+ <li>If <i>upperExists</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>upperValue</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <i>upper</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>upperValue</i>).</li>
+ </ol>
+ </li>
+ <li>If <i>lowerExists</i> is <b>true</b> and <i>upperExists</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>putStatus</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>O</i>, <i>lowerP</i>, <i>upperValue</i>,
+ <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>putStatus</i>).</li>
+ <li>Let <i>putStatus</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>O</i>, <i>upperP</i>, <i>lowerValue</i>,
+ <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>putStatus</i>).</li>
+ </ol>
+ </li>
+ <li>Else if <i>lowerExists</i> is <b>false</b> and <i>upperExists</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>putStatus</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>O</i>, <i>lowerP</i>, <i>upperValue</i>,
+ <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>putStatus</i>).</li>
+ <li>Let <i>deleteStatus</i> be <a href="#sec-deletepropertyorthrow">DeletePropertyOrThrow</a> (<i>O</i>,
+ <i>upperP</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>deleteStatus</i>).</li>
+ </ol>
+ </li>
+ <li>Else if <i>lowerExists</i> is <b>true</b> and <i>upperExists</i> is <b>false</b>, then
+ <ol class="block">
+ <li>Let <i>deleteStatus</i> be <a href="#sec-deletepropertyorthrow">DeletePropertyOrThrow</a> (<i>O</i>,
+ <i>lowerP</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>deleteStatus</i>).</li>
+ <li>Let <i>putStatus</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>O</i>, <i>upperP</i>, <i>lowerValue</i>,
+ <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>putStatus</i>).</li>
+ </ol>
+ </li>
+ <li>Else both <i>lowerExists</i> and <i>upperExists</i> are <b>false</b>,
+ <ol class="block">
+ <li>No action is required.</li>
+ </ol>
+ </li>
+ <li>Increase <i>lower</i> by 1.</li>
+ </ol>
+ </li>
+ <li>Return <i>O</i> .</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>reverse</code> function is intentionally generic; it does not require that its
+ <b>this</b> value be an Array object. Therefore, it can be transferred to other kinds of objects for use as a method.
+ Whether the <code>reverse</code> function can be applied successfully to an exotic object that is not an Array is
+ implementation-dependent.</p>
+ </div>
+ </section>
+
+ <section id="sec-array.prototype.shift">
+ <h1><span class="secnum" id="sec-22.1.3.21"><a href="#sec-array.prototype.shift"
+ title="link to this section">22.1.3.21</a></span> Array.prototype.shift ( )</h1>
+
+ <p class="Note"><span style="font-family: sans-serif">NOTE</span>	The first element of the array is removed from the
+ array and returned.</p>
+
+ <p>When the <code>shift</code> method is called the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the result of calling <a href="#sec-toobject">ToObject</a> passing the <b>this</b> value as the
+ argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>O</i>).</li>
+ <li>Let <i>lenVal</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <code>"length"</code>).</li>
+ <li>Let <i>len</i> be <a href="#sec-tolength">ToLength</a>(<i>lenVal</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>len</i>).</li>
+ <li>If <i>len</i> is zero, then
+ <ol class="block">
+ <li>Let <i>putStatus</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>O</i>, <code>"length"</code>, 0,
+ <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>putStatus</i>).</li>
+ <li>Return <b>undefined</b>.</li>
+ </ol>
+ </li>
+ <li>Let <i>first</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <code>"<b>0</b>"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>first</i>).</li>
+ <li>Let <i>k</i> be 1.</li>
+ <li>Repeat, while <i>k</i> < <i>len</i>
+ <ol class="block">
+ <li>Let <i>from</i> be <a href="#sec-tostring">ToString</a>(<i>k</i>).</li>
+ <li>Let <i>to</i> be <a href="#sec-tostring">ToString</a>(<i>k</i>–1).</li>
+ <li>Let <i>fromPresent</i> be <a href="#sec-hasproperty">HasProperty</a>(<i>O</i>, <i>from</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>fromPresent</i>).</li>
+ <li>If <i>fromPresent</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>fromVal</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <i>from</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>fromVal</i>).</li>
+ <li>Let <i>putStatus</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>O</i>, <i>to</i>, <i>fromVal</i>,
+ <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>putStatus</i>).</li>
+ </ol>
+ </li>
+ <li>Else <i>fromPresent</i> is <b>false</b>,
+ <ol class="block">
+ <li>Let <i>deleteStatus</i> be <a href="#sec-deletepropertyorthrow">DeletePropertyOrThrow</a>(<i>O</i>,
+ <i>to</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>deleteStatus</i>).</li>
+ </ol>
+ </li>
+ <li>Increase <i>k</i> by 1.</li>
+ </ol>
+ </li>
+ <li>Let <i>deleteStatus</i> be <a href="#sec-deletepropertyorthrow">DeletePropertyOrThrow</a>(<i>O</i>, <a
+ href="#sec-tostring">ToString</a>(<i>len</i>–1)).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>deleteStatus</i>).</li>
+ <li>Let <i>putStatus</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>O</i>, <code>"length"</code>, <i>len</i>–1,
+ <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>putStatus</i>).</li>
+ <li>Return <i>first</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>shift</code> function is intentionally generic; it does not require that its
+ <b>this</b> value be an Array object. Therefore it can be transferred to other kinds of objects for use as a method.
+ Whether the <code>shift</code> function can be applied successfully to an exotic object that is not an Array is
+ implementation-dependent.</p>
+ </div>
+ </section>
+
+ <section id="sec-array.prototype.slice">
+ <h1><span class="secnum" id="sec-22.1.3.22"><a href="#sec-array.prototype.slice"
+ title="link to this section">22.1.3.22</a></span> Array.prototype.slice (start, end)</h1>
+
+ <p class="Note"><span style="font-family: sans-serif">NOTE</span>	The <code>slice</code> method takes two arguments,
+ <i>start</i> and <i>end</i>, and returns an array containing the elements of the array from element <i>start</i> up to,
+ but not including, element <i>end</i> (or through the end of the array if <i>end</i> is <b>undefined</b>). If <i>start</i>
+ is negative, it is treated as <i>length</i>+<i>start</i> where <i>length</i> is the length of the array. If <i>end</i> is
+ negative, it is treated as <i>length</i>+<i>end</i> where <i>length</i> is the length of the array.</p>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the result of calling <a href="#sec-toobject">ToObject</a> passing the <b>this</b> value as the
+ argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>O</i>).</li>
+ <li>Let <i>lenVal</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <code>"length"</code>).</li>
+ <li>Let <i>len</i> be <a href="#sec-tolength">ToLength</a>(<i>lenVal</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>len</i>).</li>
+ <li>Let <i>relativeStart</i> be <a href="#sec-tointeger">ToInteger</a>(<i>start</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>relativeStart</i>).</li>
+ <li>If <i>relativeStart</i> is negative, let <i>k</i> be max((<i>len</i> + <i>relativeStart</i>),0); else let <i>k</i>
+ be min(<i>relativeStart</i>, <i>len</i>).</li>
+ <li>If <i>end</i> is <b>undefined</b>, let <i>relativeEnd</i> be <i>len</i>; else let <i>relativeEnd</i> be <a
+ href="#sec-tointeger">ToInteger</a>(<i>end</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>relativeEnd</i>).</li>
+ <li>If <i>relativeEnd</i> is negative, let <i>final</i> be max((<i>len</i> + <i>relativeEnd</i>),0); else let
+ <i>final</i> be min(<i>relativeEnd</i>, <i>len</i>).</li>
+ <li>Let <i>count</i> be max(<i>final</i> – <i>k</i>, 0).</li>
+ <li>Let <i>A</i> be <b>undefined</b>.</li>
+ <li>If <i>O</i> is an exotic Array object, then
+ <ol class="block">
+ <li>Let <i>C</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <code>"constructor"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>C</i>).</li>
+ <li>If <a href="#sec-isconstructor">IsConstructor</a>(<i>C</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>thisRealm</i> be <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-code-realms">Realm</a>.</li>
+ <li>If <i>thisRealm</i> and the value of <i>C’s</i> [[Realm]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> are the same value, then
+ <ol class="block">
+ <li>Let <i>A</i> be the result of calling the [[Construct]] internal method of <i>C</i> with argument
+ (<i>count</i>).</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>If <i>A</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>A</i> be <a href="#sec-arraycreate">ArrayCreate</a>(<i>count</i>).</li>
+ </ol>
+ </li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>A</i>).</li>
+ <li>Let <i>n</i> be 0.</li>
+ <li>Repeat, while <i>k</i> < <i>final</i>
+ <ol class="block">
+ <li>Let <i>Pk</i> be <a href="#sec-tostring">ToString</a>(<i>k</i>).</li>
+ <li>Let <i>kPresent</i> be <a href="#sec-hasproperty">HasProperty</a>(<i>O</i>, <i>Pk</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>kPresent</i>).</li>
+ <li>If <i>kPresent</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>kValue</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <i>Pk</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>kValue</i>).</li>
+ <li>Let <i>status</i> be <a href="#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a>(<i>A</i>, <a
+ href="#sec-tostring">ToString</a>(<i>n</i>), <i>kValue</i> ).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ </ol>
+ </li>
+ <li>Increase <i>k</i> by 1.</li>
+ <li>Increase <i>n</i> by 1.</li>
+ </ol>
+ </li>
+ <li>Let <i>putStatus</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>A</i>, <code>"length"</code>, <i>n</i>,
+ <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>putStatus</i>).</li>
+ <li>Return <i>A</i>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>slice</code> method is <b>2</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> The explicit setting of the <code>length</code> property of the result Array in step
+ 19 is necessary to ensure that its value is correct in situations where the trailing elements of the result Array are
+ not present.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 2</span> The <code>slice</code> function is intentionally generic; it does not require that its
+ <b>this</b> value be an Array object. Therefore it can be transferred to other kinds of objects for use as a method.
+ Whether the <code>slice</code> function can be applied successfully to an exotic object that is not an Array is
+ implementation-dependent.</p>
+ </div>
+ </section>
+
+ <section id="sec-array.prototype.some">
+ <h1><span class="secnum" id="sec-22.1.3.23"><a href="#sec-array.prototype.some"
+ title="link to this section">22.1.3.23</a></span> Array.prototype.some ( callbackfn [ , thisArg ] )</h1>
+
+ <p class="Note"><span style="font-family: sans-serif">NOTE</span>	<i>callbackfn</i> should be a function that accepts
+ three arguments and returns a value that is coercible to the Boolean value <b>true</b> or <b>false</b>. <code>some</code>
+ calls <i>callbackfn</i> once for each element present in the array, in ascending order, until it finds one where
+ <i>callbackfn</i> returns <b>true</b>. If such an element is found, <code>some</code> immediately returns <b>true</b>.
+ Otherwise, <code>some</code> returns <b>false</b>. <i>callbackfn</i> is called only for elements of the array which
+ actually exist; it is not called for missing elements of the array.</p>
+
+ <p class="Note">If a <i>thisArg</i> parameter is provided, it will be used as the <b>this</b> value for each invocation of
+ <i>callbackfn</i>. If it is not provided, <b>undefined</b> is used instead.</p>
+
+ <p class="Note"><i>callbackfn</i> is called with three arguments: the value of the element, the index of the element, and
+ the object being traversed.</p>
+
+ <p class="Note"><code>some</code> does not directly mutate the object on which it is called but the object may be mutated
+ by the calls to <i>callbackfn</i>.</p>
+
+ <p class="Note">The range of elements processed by <code>some</code> is set before the first call to <i>callbackfn</i>.
+ Elements that are appended to the array after the call to <code>some</code> begins will not be visited by
+ <i>callbackfn</i>. If existing elements of the array are changed, their value as passed to <i>callbackfn</i> will be the
+ value at the time that <code>some</code> visits them; elements that are deleted after the call to <code>some</code> begins
+ and before being visited are not visited. <code>some</code> acts like the "exists" quantifier in mathematics. In
+ particular, for an empty array, it returns <b>false</b>.</p>
+
+ <p>When the <code>some</code> method is called with one or two arguments, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the result of calling <a href="#sec-toobject">ToObject</a> passing the <b>this</b> value as the
+ argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>O</i>).</li>
+ <li>Let <i>lenValue</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <code>"length"</code>).</li>
+ <li>Let <i>len</i> be <a href="#sec-tolength">ToLength</a>(<i>lenValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>len</i>).</li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>callbackfn</i>) is <b>false</b>, throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>thisArg</i> was supplied, let <i>T</i> be <i>thisArg</i>; else let <i>T</i> be <b>undefined</b>.</li>
+ <li>Let <i>k</i> be 0.</li>
+ <li>Repeat, while <i>k</i> < <i>len</i>
+ <ol class="block">
+ <li>Let <i>Pk</i> be <a href="#sec-tostring">ToString</a>(<i>k</i>).</li>
+ <li>Let <i>kPresent</i> be <a href="#sec-hasproperty">HasProperty</a>(<i>O</i>, <i>Pk</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>kPresent</i>).</li>
+ <li>If <i>kPresent</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>kValue</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <i>Pk</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>kValue</i>).</li>
+ <li>Let <i>testResult</i> be the result of calling the [[Call]] internal method of <i>callbackfn</i> with
+ <i>T</i> as <i>thisArgument</i> and a <a href="#sec-list-and-record-specification-type">List</a> containing
+ <i>kValue</i>, <i>k</i>, and <i>O</i> as <i>argumentsList</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>testResult</i>).</li>
+ <li>If <a href="#sec-toboolean">ToBoolean</a>(<i>testResult)</i> is <b>true</b>, return <b>true</b>.</li>
+ </ol>
+ </li>
+ <li>Increase <i>k</i> by 1.</li>
+ </ol>
+ </li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>some</code> method is <b>1</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>some</code> function is intentionally generic; it does not require that its
+ <b>this</b> value be an Array object. Therefore it can be transferred to other kinds of objects for use as a method.
+ Whether the <code>some</code> function can be applied successfully to an exotic object that is not an Array is
+ implementation-dependent.</p>
+ </div>
+ </section>
+
+ <section id="sec-array.prototype.sort">
+ <div class="front">
+ <h1><span class="secnum" id="sec-22.1.3.24"><a href="#sec-array.prototype.sort"
+ title="link to this section">22.1.3.24</a></span> Array.prototype.sort (comparefn)</h1>
+
+ <p>The elements of this array are sorted. The sort is not necessarily stable (that is, elements that compare equal do
+ not necessarily remain in their original order). If <var>comparefn</var> is not <b>undefined</b>, it should be a
+ function that accepts two arguments <var>x</var> and <var>y</var> and returns a negative value if <var>x</var> <span
+ style="font-family: Times New Roman"><</span> <var>y</var>, zero if <var>x</var> <span style="font-family: Times New
+ Roman">=</span> <var>y</var>, or a positive value if <var>x</var> <span style="font-family: Times New Roman">></span>
+ <var>y</var>.</p>
+
+ <p>Upon entry, the following steps are performed to initialize evaluation of the <code>sort</code> function:</p>
+
+ <ol class="proc">
+ <li>Let <i>obj</i> be the result of calling <a href="#sec-toobject">ToObject</a> passing the <b>this</b> value as the
+ argument.</li>
+ <li>Let <i>lenValue</i> be <a href="#sec-get-o-p">Get</a>(<i>obj</i>, <code>"length"</code>).</li>
+ <li>Let <i>len</i> be <a href="#sec-tolength">ToLength</a>(<i>lenValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>len</i>).</li>
+ </ol>
+
+ <p>The result of the <code>sort</code> function is then determined as follows:</p>
+
+ <p>If <var>comparefn</var> is not <b>undefined</b> and is not a consistent comparison function for the elements of this
+ array (see below), the behaviour of <code>sort</code> is implementation-defined.</p>
+
+ <p>Let <var>proto</var> be the result of calling the [[GetPrototypeOf]] internal method of <var>obj</var>. If
+ <var>proto</var> is not <b>null</b> and there exists an integer <var>j</var> such that all of the conditions below are
+ satisfied then the behaviour of <code>sort</code> is implementation-defined:</p>
+
+ <ul>
+ <li><var>obj</var> is sparse (<a href="#sec-array-objects">22.1</a>)</li>
+ <li>0 ≤ <var>j</var> < <var>len</var></li>
+ <li>The result of <a href="#sec-hasproperty">HasProperty</a>(<var>proto</var>, <span style="font-family: Times New
+ Roman"><a href="#sec-tostring">ToString</a>(<i>j</i>))</span> is <b>true</b>.</li>
+ </ul>
+
+ <p>The behaviour of <code>sort</code> is also implementation defined if <var>obj</var> is sparse and any of the
+ following conditions are true:</p>
+
+ <ul>
+ <li>
+ <p>The result of the predicate <a href="#sec-isextensible-o">IsExtensible</a>(<span style="font-family: Times New
+ Roman"><i>obj</i>)</span> is <b>false</b>.</p>
+ </li>
+
+ <li>
+ <p>Any array index property of <var>obj</var> whose name is a nonnegative integer less than <var>len</var> is a data
+ property whose [[Configurable]] attribute is <b>false</b>.</p>
+ </li>
+ </ul>
+
+ <p>The behaviour of <code>sort</code> is also implementation defined if any array index property of <var>obj</var> whose
+ name is a nonnegative integer less than <var>len</var> is an accessor property or is a data property whose [[Writable]]
+ attribute is <b>false</b>.</p>
+
+ <p>Otherwise, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Perform an implementation-dependent sequence of calls to the [[Get]] and [[Set]] internal methods of <i>obj</i>,
+ to the <a href="#sec-deletepropertyorthrow">DeletePropertyOrThrow</a> abstract operation with <i>obj</i> as the
+ first argument, and to <a href="#sec-sortcompare">SortCompare</a> (described below), where the <a
+ href="#sec-object-type">property key</a> argument for each call to [[Get]], [[Set]], or <a
+ href="#sec-deletepropertyorthrow">DeletePropertyOrThrow</a> is the string representation of a nonnegative integer
+ less than <i>len</i> and where the arguments for calls to <a href="#sec-sortcompare">SortCompare</a> are results
+ of previous calls to the [[Get]] internal method. If <i>obj</i> is not sparse then <a
+ href="#sec-deletepropertyorthrow">DeletePropertyOrThrow</a> must not be called. If any [[Set]] call returns
+ <b>false</b> a <b>TypeError</b> exception is thrown. If an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a> is returned from any of these operations,
+ it is immediately returned as the value of this function.</li>
+ <li>Return <i>obj</i>.</li>
+ </ol>
+
+ <p>The returned object must have the following two characteristics:</p>
+
+ <ul>
+ <li>
+ <p>There must be some mathematical permutation <span style="font-family: Times New Roman">π</span> of the
+ nonnegative integers less than <var>len</var>, such that for every nonnegative integer <var>j</var> less than
+ <var>len</var>, if property <span style="font-family: Times New Roman">old[<i>j</i>]</span> existed, then <span
+ style="font-family: Times New Roman">new[π(<i>j</i>)]</span> is exactly the same value as <span
+ style="font-family: Times New Roman">old[<i>j</i>]</span><b>,</b>. But if property <span style="font-family: Times
+ New Roman">old[<i>j</i>]</span> did not exist, then <span style="font-family: Times New
+ Roman">new[π(<i>j</i>)]</span> does not exist.</p>
+ </li>
+
+ <li>
+ <p>Then for all nonnegative integers <var>j</var> and <var>k</var>, each less than <var>len</var>, if <span
+ style="font-family: Times New Roman"><a href="#sec-sortcompare">SortCompare</a>(<i>j</i>,<i>k</i>) < 0</span>
+ (see <a href="#sec-sortcompare">SortCompare</a> below), then <span style="font-family: Times New
+ Roman"><b>π</b>(<i>j</i>) <</span> <span style="font-family: Times New
+ Roman"><b>π</b>(<i>k</i>)</span>.</p>
+ </li>
+ </ul>
+
+ <p>Here the notation <span style="font-family: Times New Roman">old[<i>j</i>]</span> is used to refer to the
+ hypothetical result of calling the [[Get]] internal method of <var>obj</var> with argument <var>j</var> before this
+ function is executed, and the notation <span style="font-family: Times New Roman">new[<i>j</i>]</span> to refer to the
+ hypothetical result of calling the [[Get]] internal method of <var>obj</var> with argument <var>j</var> after this
+ function has been executed.</p>
+
+ <p>A function <var>comparefn</var> is a consistent comparison function for a set of values <var>S</var> if all of the
+ requirements below are met for all values <var>a</var>, <var>b</var>, and <var>c</var> (possibly the same value) in the
+ set <var>S</var>: The notation <span style="font-family: Times New
+ Roman"><i>a</i> <<sub>CF</sub></span> <var>b</var> means <span style="font-family: Times New
+ Roman"><i>comparefn</i>(<i>a</i>,<i>b</i>) < 0</span>; <span style="font-family: Times New
+ Roman"><i>a</i> =<sub>CF</sub></span> <var>b</var> means <span style="font-family: Times New
+ Roman"><i>comparefn</i>(<i>a</i>,<i>b</i>) = 0</span> (of either sign); and <span style="font-family: Times
+ New Roman"><i>a</i> ><sub>CF</sub></span> <var>b</var> means <span style="font-family: Times New
+ Roman"><i>comparefn</i>(<i>a</i>,<i>b</i>) > 0</span>.</p>
+
+ <ul>
+ <li>
+ <p>Calling <i>comparefn</i>(<i>a</i>,<i>b</i>) always returns the same value <i>v</i> when given a specific pair of
+ values <i>a</i> and <i>b</i> as its two arguments. Furthermore, <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>v</i>) is Number, and <i>v</i> is not NaN. Note that this
+ implies that exactly one of <i>a</i> <<sub>CF</sub> <i>b</i>,
+ <i>a</i> =<sub>CF</sub> <i>b</i>, and <i>a</i> ><sub>CF</sub> <i>b</i> will be true for a
+ given pair of <i>a</i> and <i>b</i>.</p>
+ </li>
+
+ <li>
+ <p>Calling <i>comparefn</i>(<i>a</i>,<i>b</i>) does not modify <i>obj</i>.</p>
+ </li>
+
+ <li>
+ <p><i>a</i> =<sub>CF</sub> <i>a</i> (reflexivity)</p>
+ </li>
+
+ <li>
+ <p>If <i>a</i> =<sub>CF</sub> <i>b</i>, then <i>b</i> =<sub>CF</sub> <i>a</i> (symmetry)</p>
+ </li>
+
+ <li>
+ <p>If <i>a</i> =<sub>CF</sub> <i>b</i> and <i>b</i> =<sub>CF</sub> <i>c</i>, then
+ <i>a</i> =<sub>CF</sub> <i>c</i> (transitivity of =<sub>CF</sub>)</p>
+ </li>
+
+ <li>
+ <p>If <i>a</i> <<sub>CF</sub> <i>b</i> and <i>b</i> <<sub>CF</sub> <i>c</i>, then
+ <i>a</i> <<sub>CF</sub> <i>c</i> (transitivity of <<sub>CF</sub>)</p>
+ </li>
+
+ <li>
+ <p>If <i>a</i> ><sub>CF</sub> <i>b</i> and <i>b</i> ><sub>CF</sub> <i>c</i>, then
+ <i>a</i> ><sub>CF</sub> <i>c</i> (transitivity of ><sub>CF</sub>)</p>
+ </li>
+ </ul>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> The above conditions are necessary and sufficient to ensure that <i>comparefn</i>
+ divides the set <i>S</i> into equivalence classes and that these equivalence classes are totally ordered.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 2</span> The <code>sort</code> function is intentionally generic; it does not require that
+ its <b>this</b> value be an Array object. Therefore, it can be transferred to other kinds of objects for use as a
+ method. Whether the <code>sort</code> function can be applied successfully to an exotic object that is not an Array is
+ implementation-dependent.</p>
+ </div>
+ </div>
+
+ <section id="sec-sortcompare">
+ <h1><span class="secnum" id="sec-22.1.3.24.1"><a href="#sec-sortcompare"
+ title="link to this section">22.1.3.24.1</a></span> Runtime Semantics: SortCompare Abstract Operation</h1>
+
+ <p>When the SortCompare abstract operation is called with two arguments <var>j</var> and <var>k</var>, the following
+ steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>jString</i> be <a href="#sec-tostring">ToString</a>(<i>j</i>).</li>
+ <li>Let <i>kString</i> be <a href="#sec-tostring">ToString</a>(<i>k</i>).</li>
+ <li>Let <i>hasj</i> be <a href="#sec-hasproperty">HasProperty</a>(<i>obj</i>, <i>jString</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>hasj</i>).</li>
+ <li>Let <i>hask</i> be <a href="#sec-hasproperty">HasProperty</a>(<i>obj</i>, <i>kString</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>hask</i>).</li>
+ <li>If <i>hasj</i> and <i>hask</i> are both <b>false</b>, then return <b>+0</b>.</li>
+ <li>If <i>hasj</i> is <b>false</b>, then return 1.</li>
+ <li>If <i>hask</i> is <b>false</b>, then return –1.</li>
+ <li>Let <i>x</i> be <a href="#sec-get-o-p">Get</a>(<i>obj</i>,<i>jString</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>x</i>).</li>
+ <li>Let <i>y</i> be <a href="#sec-get-o-p">Get</a>(<i>obj</i>, <i>kString</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>y</i>).</li>
+ <li>If <i>x</i> and <i>y</i> are both <b>undefined</b>, return <b>+0</b>.</li>
+ <li>If <i>x</i> is <b>undefined</b>, return 1.</li>
+ <li>If <i>y</i> is <b>undefined</b>, return −1.</li>
+ <li>If the argument <i>comparefn</i> is not <b>undefined</b>, then
+ <ol class="block">
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>comparefn</i>) is <b>false</b>, throw a <b>TypeError</b>
+ exception.</li>
+ <li>Return the result of calling the [[Call]] internal method of <i>comparefn</i> passing <b>undefined</b> as
+ <i>thisArgument</i> and with a <a href="#sec-list-and-record-specification-type">List</a> containing the
+ values of <i>x</i> and <i>y</i> as the <i>argumentsList</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>xString</i> be <a href="#sec-tostring">ToString</a>(<i>x</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>xString</i>).</li>
+ <li>Let <i>yString</i> be <a href="#sec-tostring">ToString</a>(<i>y</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>yString</i>).</li>
+ <li>If <i>xString</i> < <i>yString</i>, return −1.</li>
+ <li>If <i>xString</i> > <i>yString</i>, return 1.</li>
+ <li>Return <b>+0</b>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE </span> Because non-existent property values always compare greater than <b>undefined</b>
+ property values, and <b>undefined</b> always compares greater than any other value, <b>undefined</b> property values
+ always sort to the end of the result, followed by non-existent property values.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-array.prototype.splice">
+ <h1><span class="secnum" id="sec-22.1.3.25"><a href="#sec-array.prototype.splice"
+ title="link to this section">22.1.3.25</a></span> Array.prototype.splice (start, deleteCount , ...items )</h1>
+
+ <p class="Note"><span style="font-family: sans-serif">NOTE</span>	When the <code>splice</code> method is called with
+ two or more arguments <i>start</i>, <i>deleteCount</i> and zero or more <i>items</i>,., the <i>deleteCount</i> elements of
+ the array starting at integer index <i>start</i> are replaced by the arguments <i>items</i>,. An Array object containing
+ the deleted elements (if any) is returned.</p>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the result of calling <a href="#sec-toobject">ToObject</a> passing the <b>this</b> value as the
+ argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>O</i>).</li>
+ <li>Let <i>lenVal</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <code>"length"</code>)</li>
+ <li>Let <i>len</i> be <a href="#sec-tolength">ToLength</a>(<i>lenVal</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>len</i>).</li>
+ <li>Let <i>relativeStart</i> be <a href="#sec-tointeger">ToInteger</a>(<i>start</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>relativeStart</i>).</li>
+ <li>If <i>relativeStart</i> is negative, let <i>actualStart</i> be max((<i>len</i> + <i>relativeStart</i>),0); else let
+ <i>actualStart</i> be min(<i>relativeStart</i>, <i>len</i>).</li>
+ <li>If the number of actual arguments is 0, then
+ <ol class="block">
+ <li>Let <i>actualDeleteCount</i> be 0.</li>
+ </ol>
+ </li>
+ <li>Else if the number of actual arguments is 1, then
+ <ol class="block">
+ <li>Let <i>actualDeleteCount</i> be <i>len</i> - <i>actualStart</i></li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>dc</i> be <a href="#sec-tointeger">ToInteger</a>(<i>deleteCount</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>dc</i>).</li>
+ <li>Let <i>actualDeleteCount</i> be min(max(<i>dc</i>,0), <i>len</i> – <i>actualStart</i>).</li>
+ </ol>
+ </li>
+ <li>Let <i>A</i> be <b>undefined</b>.</li>
+ <li>If <i>O</i> is an exotic Array object, then
+ <ol class="block">
+ <li>Let <i>C</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <code>"constructor"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>C</i>).</li>
+ <li>If <a href="#sec-isconstructor">IsConstructor</a>(<i>C</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>thisRealm</i> be <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-code-realms">Realm</a>.</li>
+ <li>If <i>thisRealm</i> and the value of <i>C’s</i> [[Realm]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> are the same value, then
+ <ol class="block">
+ <li>Let <i>A</i> be the result of calling the [[Construct]] internal method of <i>C</i> with argument
+ (<i>actualDeleteCount</i>).</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>If <i>A</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>A</i> be <a href="#sec-arraycreate">ArrayCreate</a>(<i>actualDeleteCount</i>).</li>
+ </ol>
+ </li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>A</i>).</li>
+ <li>Let <i>k</i> be 0.</li>
+ <li>Repeat, while <i>k</i> < <i>actualDeleteCount</i>
+ <ol class="block">
+ <li>Let <i>from</i> be <a href="#sec-tostring">ToString</a>(<i>actualStart</i>+<i>k</i>).</li>
+ <li>Let <i>fromPresent</i> be <a href="#sec-hasproperty">HasProperty</a>(<i>O</i>, <i>from</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>fromPresent</i>).</li>
+ <li>If <i>fromPresent</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>fromValue</i> be <a href="#sec-get-o-p">Get</a>(<i>O,</i> <i>from</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>fromValue</i>).</li>
+ <li>Let <i>status</i> be <a href="#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a>(<i>A</i>, <a
+ href="#sec-tostring">ToString</a>(<i>k</i>), <i>fromValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ </ol>
+ </li>
+ <li>Increment <i>k</i> by 1.</li>
+ </ol>
+ </li>
+ <li>Let <i>putStatus</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>A</i>, <code>"length"</code>,
+ <i>actualDeleteCount</i>, <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>putStatus</i>).</li>
+ <li>Let <i>items</i> be a <a href="#sec-list-and-record-specification-type">List</a> whose elements are, in left to
+ right order, the portion of the actual argument list starting with the third argument. The list will be empty fewer
+ than three arguments were passed.</li>
+ <li>Let <i>itemCount</i> be the number of elements in <i>items</i>.</li>
+ <li>If <i>itemCount</i> < <i>actualDeleteCount</i>, then
+ <ol class="block">
+ <li>Let <i>k</i> be <i>actualStart</i>.</li>
+ <li>Repeat, while <i>k</i> < (<i>len</i> – <i>actualDeleteCount</i>)
+ <ol class="block">
+ <li>Let <i>from</i> be <a href="#sec-tostring">ToString</a>(<i>k</i>+<i>actualDeleteCount</i>).</li>
+ <li>Let <i>to</i> be <a href="#sec-tostring">ToString</a>(<i>k</i>+<i>itemCount</i>).</li>
+ <li>Let <i>fromPresent</i> be <a href="#sec-hasproperty">HasProperty</a>(<i>O</i>, <i>from</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>fromPresent</i>).</li>
+ <li>If <i>fromPresent</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>fromValue</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <i>from</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>fromValue</i>).</li>
+ <li>Let <i>putStatus</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>O</i>, <i>to</i>, <i>fromValue</i>,
+ <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>putStatus</i>).</li>
+ </ol>
+ </li>
+ <li>Else <i>fromPresent</i> is <b>false</b>,
+ <ol class="block">
+ <li>Let <i>deleteStatus</i> be <a href="#sec-deletepropertyorthrow">DeletePropertyOrThrow</a>(<i>O</i>,
+ <i>to</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>deleteStatus</i>).</li>
+ </ol>
+ </li>
+ <li>Increase <i>k</i> by 1.</li>
+ </ol>
+ </li>
+ <li>Let <i>k</i> be <i>len</i>.</li>
+ <li>Repeat, while <i>k</i> > (<i>len</i> – <i>actualDeleteCount</i> + <i>itemCount</i>)
+ <ol class="block">
+ <li>Let <i>deleteStatus</i> be <a href="#sec-deletepropertyorthrow">DeletePropertyOrThrow</a>(<i>O</i>, <a
+ href="#sec-tostring">ToString</a>(<i>k</i>–1)).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>deleteStatus</i>).</li>
+ <li>Decrease <i>k</i> by 1.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Else if <i>itemCount</i> > <i>actualDeleteCount</i>, then
+ <ol class="block">
+ <li>Let <i>k</i> be (<i>len</i> – <i>actualDeleteCount</i>).</li>
+ <li>Repeat, while <i>k</i> > <i>actualStart</i>
+ <ol class="block">
+ <li>Let <i>from</i> be <a href="#sec-tostring">ToString</a>(<i>k</i> + <i>actualDeleteCount</i> – 1).</li>
+ <li>Let <i>to</i> be <a href="#sec-tostring">ToString</a>(<i>k</i> + <i>itemCount</i> – 1)</li>
+ <li>Let <i>fromPresent</i> be <a href="#sec-hasproperty">HasProperty</a>(<i>O</i>, <i>from</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>fromPresent</i>).</li>
+ <li>If <i>fromPresent</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>fromValue</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <i>from</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>fromValue</i>).</li>
+ <li>Let <i>putStatus</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>O</i>, <i>to</i>, <i>fromValue</i>,
+ <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>putStatus</i>).</li>
+ </ol>
+ </li>
+ <li>Else <i>fromPresent</i> is <b>false</b>,
+ <ol class="block">
+ <li>Let <i>deleteStatus</i> be <a href="#sec-deletepropertyorthrow">DeletePropertyOrThrow</a>(<i>O</i>,
+ <i>to</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>deleteStatus</i>).</li>
+ </ol>
+ </li>
+ <li>Decrease <i>k</i> by 1.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Let <i>k</i> be <i>actualStart</i>.</li>
+ <li>Repeat, while <i>items</i> is not empty
+ <ol class="block">
+ <li>Remove the first element from <i>items</i> and let <i>E</i> be the value of that element.</li>
+ <li>Let <i>putStatus</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>O</i>, <a
+ href="#sec-tostring">ToString</a>(<i>k</i>), <i>E</i>, <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>putStatus</i>).</li>
+ <li>Increase <i>k</i> by 1.</li>
+ </ol>
+ </li>
+ <li>Let <i>putStatus</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>O</i>, <code>"length"</code>, <i>len</i> –
+ <i>actualDeleteCount</i> + <i>itemCount</i>, <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>putStatus</i>).</li>
+ <li>Return <i>A</i>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>splice</code> method is <b>2</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> The explicit setting of the <code>length</code> property of the result Array in step
+ 18 is necessary to ensure that its value is correct in situations where its trailing elements are not present.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 2</span> The <code>splice</code> function is intentionally generic; it does not require that
+ its <b>this</b> value be an Array object. Therefore it can be transferred to other kinds of objects for use as a method.
+ Whether the <code>splice</code> function can be applied successfully to an exotic object that is not an Array is
+ implementation-dependent.</p>
+ </div>
+ </section>
+
+ <section id="sec-array.prototype.tolocalestring">
+ <h1><span class="secnum" id="sec-22.1.3.26"><a href="#sec-array.prototype.tolocalestring"
+ title="link to this section">22.1.3.26</a></span> Array.prototype.toLocaleString ( )</h1>
+
+ <p class="Note"><span style="font-family: sans-serif">NOTE</span>	The elements of the array are converted to Strings
+ using their <code>toLocaleString</code> methods, and these Strings are then concatenated, separated by occurrences of a
+ separator String that has been derived in an implementation-defined locale-specific way. The result of calling this
+ function is intended to be analogous to the result of <code>toString</code>, except that the result of this function is
+ intended to be locale-specific.</p>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>array</i> be the result of calling <a href="#sec-toobject">ToObject</a> passing the <b>this</b> value as the
+ argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>array</i>).</li>
+ <li>Let <i>arrayLen</i> be <a href="#sec-get-o-p">Get</a>(<i>array</i>, <code>"length"</code>).</li>
+ <li>Let <i>len</i> be <a href="#sec-tolength">ToLength</a>(<i>arrayLen</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>len</i>).</li>
+ <li>Let <i>separator</i> be the String value for the list-separator String appropriate for the host environment’s
+ current locale (this is derived in an implementation-defined way).</li>
+ <li>If <i>len</i> is zero, return the empty String.</li>
+ <li>Let <i>firstElement</i> be <a href="#sec-get-o-p">Get</a>(<i>array</i>, <code>"0"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>firstElement</i>).</li>
+ <li>If <i>firstElement</i> is <b>undefined</b> or <b>null</b>, then
+ <ol class="block">
+ <li>Let <i>R</i> be the empty String.</li>
+ </ol>
+ </li>
+ <li>Else
+ <ol class="block">
+ <li>Let <i>R</i> be <a href="#sec-invoke">Invoke</a>(<i>firstElement</i>, <code>"toLocaleString"</code>).</li>
+ <li>Let <i>R</i> be <a href="#sec-tostring">ToString</a>(<i>R</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>R</i>).</li>
+ </ol>
+ </li>
+ <li>Let <i>k</i> be <code>1</code>.</li>
+ <li>Repeat, while <i>k</i> < <i>len</i>
+ <ol class="block">
+ <li>Let <i>S</i> be a String value produced by concatenating <i>R</i> and <i>separator</i>.</li>
+ <li>Let <i>nextElement</i> be <a href="#sec-get-o-p">Get</a>(<i>array</i>, <a
+ href="#sec-tostring">ToString</a>(<i>k</i>)).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>nextElement</i>).</li>
+ <li>If <i>nextElement</i> is <b>undefined</b> or <b>null</b>, then
+ <ol class="block">
+ <li>Let <i>R</i> be the empty String.</li>
+ </ol>
+ </li>
+ <li>Else
+ <ol class="block">
+ <li>Let <i>R</i> be <a href="#sec-invoke">Invoke</a>(<i>nextElement</i>, <code>"toLocaleString"</code>).</li>
+ <li>Let <i>R</i> be <a href="#sec-tostring">ToString</a>(<i>R</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>R</i>).</li>
+ </ol>
+ </li>
+ <li>Let <i>R</i> be a String value produced by concatenating <i>S</i> and <i>R</i>.</li>
+ <li>Increase <i>k</i> by 1.</li>
+ </ol>
+ </li>
+ <li>Return <i>R</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> The first parameter to this function is likely to be used in a future version of this
+ standard; it is recommended that implementations do not use this parameter position for anything else.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 2</span> The <code>toLocaleString</code> function is intentionally generic; it does not require
+ that its <b>this</b> value be an Array object. Therefore it can be transferred to other kinds of objects for use as a
+ method. Whether the <code>toLocaleString</code> function can be applied successfully to an exotic object that is not an
+ Array is implementation-dependent.</p>
+ </div>
+ </section>
+
+ <section id="sec-array.prototype.tostring">
+ <h1><span class="secnum" id="sec-22.1.3.27"><a href="#sec-array.prototype.tostring"
+ title="link to this section">22.1.3.27</a></span> Array.prototype.toString ( )</h1>
+
+ <p>When the <code>toString</code> method is called, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>array</i> be the result of calling <a href="#sec-toobject">ToObject</a> on the <b>this</b> value.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>array</i>).</li>
+ <li>Let <i>func</i> be <a href="#sec-get-o-p">Get</a>(<i>array</i>, <code>"join"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>func</i>).</li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>func</i>) is <b>false</b>, then let <i>func</i> be the intrinsic
+ function %ObjProto_toString% (<a href="#sec-object.prototype.tostring">19.1.3.6</a>).</li>
+ <li>Return the result of calling the [[Call]] internal method of <i>func</i> providing <i>array</i> as
+ <i>thisArgument</i> and an empty <a href="#sec-list-and-record-specification-type">List</a> as
+ <i>argumentsList</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>toString</code> function is intentionally generic; it does not require that
+ its <b>this</b> value be an Array object. Therefore it can be transferred to other kinds of objects for use as a method.
+ Whether the <code>toString</code> function can be applied successfully to an exotic object that is not an Array is
+ implementation-dependent.</p>
+ </div>
+ </section>
+
+ <section id="sec-array.prototype.unshift">
+ <h1><span class="secnum" id="sec-22.1.3.28"><a href="#sec-array.prototype.unshift"
+ title="link to this section">22.1.3.28</a></span> Array.prototype.unshift ( ...items )</h1>
+
+ <p class="Note"><span style="font-family: sans-serif">NOTE</span>	The arguments are prepended to the start of the
+ array, such that their order within the array is the same as the order in which they appear in the argument list.</p>
+
+ <p>When the <code>unshift</code> method is called with zero or more arguments <var>item1</var>, <var>item2</var>, etc.,
+ the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the result of calling <a href="#sec-toobject">ToObject</a> passing the <b>this</b> value as the
+ argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>O</i>).</li>
+ <li>Let <i>lenVal</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <code>"length"</code>)</li>
+ <li>Let <i>len</i> be <a href="#sec-tolength">ToLength</a>(<i>lenVal</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>len</i>).</li>
+ <li>Let <i>argCount</i> be the number of actual arguments.</li>
+ <li>If <i>argCount</i> > 0, then
+ <ol class="block">
+ <li>Let <i>k</i> be <i>len</i>.</li>
+ <li>Repeat, while <i>k</i> > 0,
+ <ol class="block">
+ <li>Let <i>from</i> be <a href="#sec-tostring">ToString</a>(<i>k</i>–1).</li>
+ <li>Let <i>to</i> be <a href="#sec-tostring">ToString</a>(<i>k</i>+<i>argCount</i> –1).</li>
+ <li>Let <i>fromPresent</i> be <a href="#sec-hasproperty">HasProperty</a>(<i>O</i>, <i>from</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>fromPresent</i>).</li>
+ <li>If <i>fromPresent</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>fromValue</i> be the result of <a href="#sec-get-o-p">Get</a>(<i>O</i>, <i>from</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>fromValue</i>).</li>
+ <li>Let <i>putStatus</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>O</i>, <i>to</i>, <i>fromValue</i>,
+ <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>putStatus</i>).</li>
+ </ol>
+ </li>
+ <li>Else <i>fromPresent</i> is <b>false</b>,
+ <ol class="block">
+ <li>Let <i>deleteStatus</i> be <a href="#sec-deletepropertyorthrow">DeletePropertyOrThrow</a>(<i>O</i>,
+ <i>to</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>deleteStatus</i>).</li>
+ </ol>
+ </li>
+ <li>Decrease <i>k</i> by 1.</li>
+ </ol>
+ </li>
+ <li>Let <i>j</i> be 0.</li>
+ <li>Let <i>items</i> be a <a href="#sec-list-and-record-specification-type">List</a> whose elements are, in left to
+ right order, the arguments that were passed to this function invocation.</li>
+ <li>Repeat, while <i>items</i> is not empty
+ <ol class="block">
+ <li>Remove the first element from <i>items</i> and let <i>E</i> be the value of that element.</li>
+ <li>Let <i>putStatus</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>O</i>, <a
+ href="#sec-tostring">ToString</a>(<i>j</i>), <i>E</i>, <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>putStatus</i>).</li>
+ <li>Increase <i>j</i> by 1.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Let <i>putStatus</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>O</i>, <code>"length"</code>,
+ <i>len</i>+<i>argCount</i>, <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>putStatus</i>).</li>
+ <li>Return <i>len</i>+<i>argCount</i>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>unshift</code> method is <b>1</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>unshift</code> function is intentionally generic; it does not require that its
+ <b>this</b> value be an Array object. Therefore it can be transferred to other kinds of objects for use as a method.
+ Whether the <code>unshift</code> function can be applied successfully to an exotic object that is not an Array is
+ implementation-dependent.</p>
+ </div>
+ </section>
+
+ <section id="sec-array.prototype.values">
+ <h1><span class="secnum" id="sec-22.1.3.29"><a href="#sec-array.prototype.values"
+ title="link to this section">22.1.3.29</a></span> Array.prototype.values ( )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the result of calling <a href="#sec-toobject">ToObject</a> with the <b>this</b> value as its
+ argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>O</i>).</li>
+ <li>Return the result of calling the <a href="#sec-createarrayiterator">CreateArrayIterator</a> abstract operation with
+ arguments <i>O</i> and <code>"value"</code>.</li>
+ </ol>
+
+ <p>This function is the %ArrayProto_values% intrinsic object.</p>
+ </section>
+
+ <section id="sec-array.prototype-@@iterator">
+ <h1><span class="secnum" id="sec-22.1.3.30"><a href="#sec-array.prototype-@@iterator"
+ title="link to this section">22.1.3.30</a></span> Array.prototype [ @@iterator ] ( )</h1>
+
+ <p>The initial value of the @@iterator property is the same function object as the initial value of the <b><a
+ href="#sec-array.prototype.values">Array.prototype.values</a></b> property.</p>
+ </section>
+
+ <section id="sec-array.prototype-@@unscopables">
+ <h1><span class="secnum" id="sec-22.1.3.31"><a href="#sec-array.prototype-@@unscopables"
+ title="link to this section">22.1.3.31</a></span> Array.prototype [ @@unscopables ]</h1>
+
+ <p>The initial value of the @@unscopables data property is an object created by the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>blackList</i> be <a href="#sec-arraycreate">ArrayCreate</a>(7, <span style="font-family:
+ sans-serif">%ArrayPrototype%</span>).</li>
+ <li>Perform <a href="#sec-createdataproperty">CreateDataProperty</a>(<i>blackList</i>, <code>"0"</code>,
+ <code>"find"</code>).</li>
+ <li>Perform <a href="#sec-createdataproperty">CreateDataProperty</a>(<i>blackList</i>, <code>"1"</code>,
+ <code>"findIndex"</code>).</li>
+ <li>Perform <a href="#sec-createdataproperty">CreateDataProperty</a>(<i>blackList</i>, <code>"2"</code>,
+ <code>"fill"</code>).</li>
+ <li>Perform <a href="#sec-createdataproperty">CreateDataProperty</a>(<i>blackList</i>, <code>"3"</code>,
+ <code>"copyWithin"</code>).</li>
+ <li>Perform <a href="#sec-createdataproperty">CreateDataProperty</a>(<i>blackList</i>, <code>"4"</code>,
+ <code>"entries"</code>).</li>
+ <li>Perform <a href="#sec-createdataproperty">CreateDataProperty</a>(<i>blackList</i>, <code>"5"</code>,
+ <code>"keys"</code>).</li>
+ <li>Perform <a href="#sec-createdataproperty">CreateDataProperty</a>(<i>blackList</i>, <b><code>"6</code>"</b>,
+ <b>"<code>values"</code></b>).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: Each of the above calls will return <b>true</b>.</li>
+ <li>Return <i>blackList</i>.</li>
+ </ol>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <span class="value">false</span>,
+ [[Configurable]]: <span class="value">true</span> }.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The elements of this array are property names that were not included as standard
+ properties of <code>Array.prototype</code> prior to the sixth edition of this specification. These names are ignored for
+ <code>with</code> statement binding purposes in order to preserve the behaviour of existing code that might use one of
+ these names as a binding in an outer scope that is shadowed by a <code>with</code> statement whose binding object is an
+ Array object.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-array-instances">
+ <div class="front">
+ <h1><span class="secnum" id="sec-22.1.4"><a href="#sec-properties-of-array-instances"
+ title="link to this section">22.1.4</a></span> Properties of Array Instances</h1>
+
+ <p>Array instances are exotic Array objects and have the internal methods specified for such objects. Array instances
+ inherit properties from the Array prototype object. Array instances also have an [[ArrayInitializationState]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</p>
+
+ <p>Array instances have a <code>length</code> property, and a set of enumerable properties with array index names.</p>
+ </div>
+
+ <section id="sec-properties-of-array-instances-length">
+ <h1><span class="secnum" id="sec-22.1.4.1"><a href="#sec-properties-of-array-instances-length"
+ title="link to this section">22.1.4.1</a></span> length</h1>
+
+ <p>The <code>length</code> property of this Array object is a data property whose value is always numerically greater than
+ the name of every deletable property whose name is an array index.</p>
+
+ <p>The <code>length</code> property initially has the attributes <span style="font-family: Times New Roman">{
+ [[Writable]]: <b>true</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]: <b>false</b> }</span>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Attempting to set the length property of an Array object to a value that is numerically
+ less than or equal to the largest numeric property name of an existing array indexed non-deletable property of the array
+ will result in the length being set to a numeric value that is one greater than that largest numeric property name. See
+ <a href="#sec-array-exotic-objects-defineownproperty-p-desc">9.4.2.1</a>.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-array-iterator-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-22.1.5"><a href="#sec-array-iterator-objects"
+ title="link to this section">22.1.5</a></span> Array Iterator Objects</h1>
+
+ <p>An Array Iterator is an object, that represents a specific iteration over some specific Array instance object. There is
+ not a named constructor for Array Iterator objects. Instead, Array iterator objects are created by calling certain methods
+ of Array instance objects.</p>
+ </div>
+
+ <section id="sec-createarrayiterator">
+ <h1><span class="secnum" id="sec-22.1.5.1"><a href="#sec-createarrayiterator"
+ title="link to this section">22.1.5.1</a></span> CreateArrayIterator Abstract Operation</h1>
+
+ <p>Several methods of Array objects return Iterator objects. The abstract operation CreateArrayIterator with arguments
+ <var>array</var> and <var>kind</var> is used to create such iterator objects. It performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be <a href="#sec-toobject">ToObject</a>(<i>array</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>O</i>).</li>
+ <li>Let <i>iterator</i> be <a href="#sec-objectcreate">ObjectCreate</a>(%ArrayIteratorPrototype%, ([[IteratedObject]],
+ [[ArrayIteratorNextIndex]], [[ArrayIterationKind]])).</li>
+ <li>Set <i>iterator’s</i> [[IteratedObject]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> to <i>O</i>.</li>
+ <li>Set <i>iterator’s</i> [[ArrayIteratorNextIndex]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to 0.</li>
+ <li>Set <i>iterator’s</i> [[ArrayIterationKind]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to <i>kind</i>.</li>
+ <li>Return <i>iterator</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-%arrayiteratorprototype%-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-22.1.5.2"><a href="#sec-%arrayiteratorprototype%-object"
+ title="link to this section">22.1.5.2</a></span> The %ArrayIteratorPrototype% Object</h1>
+
+ <p>All Array Iterator Objects inherit properties from the %ArrayIteratorPrototype% intrinsic object. The
+ %ArrayIteratorPrototype% object is an ordinary object and its [[Prototype]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is the %ObjectPrototype% intrinsic object. In
+ addition, %ArrayIteratorPrototype% has the following properties:</p>
+ </div>
+
+ <section id="sec-%arrayiteratorprototype%-next">
+ <h1><span class="secnum" id="sec-22.1.5.2.1"><a href="#sec-%arrayiteratorprototype%-next"
+ title="link to this section">22.1.5.2.1</a></span> %ArrayIteratorPrototype%. next( )</h1>
+ <ol class="proc">
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object, throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>O</i> does not have all of the internal slots of an Array Iterator Instance (<a
+ href="#sec-properties-of-array-iterator-instances">22.1.5.3</a>), throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>a</i> be the value of the [[IteratedObject]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>If <i>a</i> is <b>undefined</b>, then return <a
+ href="#sec-createiterresultobject">CreateIterResultObject</a>(<b>undefined</b>, <b>true</b>).</li>
+ <li>Let <i>index</i> be the value of the [[ArrayIteratorNextIndex]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>Let <i>itemKind</i> be the value of the [[ArrayIterationKind]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>Let <i>lenValue</i> be <a href="#sec-get-o-p">Get</a>(<i>a</i>, <code>"length"</code>).</li>
+ <li>Let <i>len</i> be <a href="#sec-tolength">ToLength</a>(<i>lenValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>len</i>).</li>
+ <li>If <i>index</i> ≥ <i>len</i>, then
+ <ol class="block">
+ <li>Set the value of the [[IteratedObject]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> of <i>O</i> to <b>undefined</b>.</li>
+ <li>Return <a href="#sec-createiterresultobject">CreateIterResultObject</a>(<b>undefined</b>, <b>true</b>).</li>
+ </ol>
+ </li>
+ <li>Set the value of the [[ArrayIteratorNextIndex]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> of <i>O</i> to <i>index</i>+1.</li>
+ <li>If <i>itemKind</i> is <b>"<code>key</code>"</b>, then let <i>result</i> be <i>index</i>.</li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>elementKey</i> be <a href="#sec-tostring">ToString</a>(<i>index</i>).</li>
+ <li>Let <i>elementValue</i> be <a href="#sec-get-o-p">Get</a>(<i>a</i>, <i>elementKey</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>elementValue</i>).</li>
+ </ol>
+ </li>
+ <li>If <i>itemKind</i> is <b>"<code>value</code>"</b>, then let <i>result</i> be <i>elementValue</i>.</li>
+ <li>Else,
+ <ol class="block">
+ <li><a href="#sec-algorithm-conventions">Assert</a> <i>itemKind</i> is <b>"<code>key+value</code>"</b>,.</li>
+ <li>Let <i>result</i> be <a href="#sec-arraycreate">ArrayCreate</a>(2).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>result</i> is a new, well-formed Array object so the
+ following operations will never fail.</li>
+ <li>Call <a href="#sec-createdataproperty">CreateDataProperty</a>(<i>result</i>, <b>"<code>0</code>"</b>,
+ <i>index</i>).</li>
+ <li>Call <a href="#sec-createdataproperty">CreateDataProperty</a>(<i>result</i>, <b>"<code>1</code>"</b>,
+ <i>elementValue</i>).</li>
+ </ol>
+ </li>
+ <li>Return <a href="#sec-createiterresultobject">CreateIterResultObject</a>(<i>result</i>, <b>false</b>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-%arrayiteratorprototype%-@@iterator">
+ <h1><span class="secnum" id="sec-22.1.5.2.2"><a href="#sec-%arrayiteratorprototype%-@@iterator"
+ title="link to this section">22.1.5.2.2</a></span> %ArrayIteratorPrototype% [ @@iterator ] ( )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Return the <b>this</b> value.</li>
+ </ol>
+
+ <p>The value of the <code>name</code> property of this function is <code>"[Symbol.iterator]"</code>.</p>
+ </section>
+
+ <section id="sec-%arrayiteratorprototype%-@@tostringtag">
+ <h1><span class="secnum" id="sec-22.1.5.2.3"><a href="#sec-%arrayiteratorprototype%-@@tostringtag"
+ title="link to this section">22.1.5.2.3</a></span> %ArrayIteratorPrototype% [ @@toStringTag ]</h1>
+
+ <p>The initial value of the @@toStringTag property is the string value <b>"<code>Array Iterator</code>"</b>.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-array-iterator-instances">
+ <h1><span class="secnum" id="sec-22.1.5.3"><a href="#sec-properties-of-array-iterator-instances"
+ title="link to this section">22.1.5.3</a></span> Properties of Array Iterator Instances</h1>
+
+ <p>Array Iterator instances are ordinary objects that inherit properties from the %ArrayIteratorPrototype% intrinsic
+ object. Array Iterator instances are initially created with the internal slots listed in <a href="#table-43">Table
+ 43</a>.</p>
+
+ <figure>
+ <figcaption><span id="table-43">Table 43</span> — Internal Slots of Array Iterator Instances</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-top: 2px solid #000000">Internal Slot</th>
+ <th style="border-bottom: 1px solid #000000; border-left: 0px solid black; border-right: 1px solid #000000; border-top: 2px solid #000000">Description</th>
+ </tr>
+ <tr>
+ <td>[[IteratedObject]]</td>
+ <td>The object whose array elements are being iterated.</td>
+ </tr>
+ <tr>
+ <td>[[ArrayIteratorNextIndex]]</td>
+ <td>The integer index of the next array index to be examined by this iteration.</td>
+ </tr>
+ <tr>
+ <td>[[ArrayIterationKind]]</td>
+ <td>A string value that identifies what is to be returned for each element of the iteration. The possible values are: <b>"<code>key</code>"</b>, <b>"<code>value</code>"</b>, <b>"<code>key+value</code>"</b>.</td>
+ </tr>
+ </table>
+ </figure>
+ </section>
+ </section>
+ </section>
+
+ <section id="sec-typedarray-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-22.2"><a href="#sec-typedarray-objects" title="link to this section">22.2</a></span>
+ <i>TypedArray</i> Objects</h1>
+
+ <p><i>TypedArray</i> objects present an array-like view of an underlying binary data buffer (<a
+ href="#sec-arraybuffer-objects">24.1</a>). Each element of a <i>TypedArray</i> instance has the same underlying binary
+ scalar data type. There is a distinct <i>TypedArray</i> constructor, listed in <a href="#table-44">Table 44</a>, for each of
+ the nine supported element types. Each constructor in <a href="#table-44">Table 44</a> has a corresponding distinct
+ prototype object.</p>
+
+ <figure>
+ <figcaption><span id="table-44">Table 44</span> – The <i>TypedArray</i> Constructors</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="background-color: #BFBFBF">Constructor Name</th>
+ <th style="background-color: #BFBFBF">Element<br>Type</th>
+ <th style="background-color: #BFBFBF">Element Size</th>
+ <th style="background-color: #BFBFBF">Conversion Operation</th>
+ <th style="background-color: #BFBFBF">Description</th>
+ <th style="background-color: #BFBFBF">Equivalent C Type</th>
+ </tr>
+ <tr>
+ <td><a href="#sec-int8array">Int8Array</a></td>
+ <td>Int8</td>
+ <td>1</td>
+ <td><a href="#sec-toint8">ToInt8</a></td>
+ <td>8-bit 2’s complement signed integer</td>
+ <td>signed char</td>
+ </tr>
+ <tr>
+ <td><a href="#sec-uint8array">Uint8Array</a></td>
+ <td>Uint8</td>
+ <td>1</td>
+ <td><a href="#sec-touint8">ToUint8</a></td>
+ <td>8-bit unsigned integer</td>
+ <td>unsigned char</td>
+ </tr>
+ <tr>
+ <td><a href="#sec-uint8clampedarray">Uint8ClampedArray</a></td>
+ <td>Uint8C</td>
+ <td>1</td>
+ <td><a href="#sec-touint8clamp">ToUint8Clamp</a></td>
+ <td>8-bit unsigned integer (clamped conversion)</td>
+ <td>unsigned char</td>
+ </tr>
+ <tr>
+ <td><a href="#sec-int16array">Int16Array</a></td>
+ <td>Int16</td>
+ <td>2</td>
+ <td><a href="#sec-toint16">ToInt16</a></td>
+ <td>16-bit 2’s complement signed integer</td>
+ <td>Short</td>
+ </tr>
+ <tr>
+ <td><a href="#sec-uint16array">Uint16Array</a></td>
+ <td>Uint16</td>
+ <td>2</td>
+ <td><a href="#sec-touint16">ToUint16</a></td>
+ <td>16-bit unsigned integer</td>
+ <td>unsigned short</td>
+ </tr>
+ <tr>
+ <td><a href="#sec-int32array">Int32Array</a></td>
+ <td>Int32</td>
+ <td>4</td>
+ <td><a href="#sec-toint32">ToInt32</a></td>
+ <td>32-bit 2’s complement signed integer</td>
+ <td>Int</td>
+ </tr>
+ <tr>
+ <td><a href="#sec-uint32array">Uint32Array</a></td>
+ <td>Uint32</td>
+ <td>4</td>
+ <td><a href="#sec-touint32">ToUint32</a></td>
+ <td>32-bit unsigned integer</td>
+ <td>unsigned int</td>
+ </tr>
+ <tr>
+ <td><a href="#sec-float32array">Float32Array</a></td>
+ <td>Float32</td>
+ <td>4</td>
+ <td></td>
+ <td>32-bit IEEE floating point</td>
+ <td>Float</td>
+ </tr>
+ <tr>
+ <td><a href="#sec-float64array">Float64Array</a></td>
+ <td>Float64</td>
+ <td>8</td>
+ <td></td>
+ <td>64-bit IEEE floating point</td>
+ <td>Double</td>
+ </tr>
+ </table>
+ </figure>
+
+ <p>In the definitions below, references to <i>TypedArray</i> should be replaced with the appropriate constructor name from
+ the above table. The phrase “the element size in bytes” refers to the value in the Element Size column of the
+ table in the row corresponding to the constructor. The phrase “element Type” refers to the value in the Element
+ Type column for that row.</p>
+ </div>
+
+ <section id="sec-%typedarray%-intrinsic-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-22.2.1"><a href="#sec-%typedarray%-intrinsic-object"
+ title="link to this section">22.2.1</a></span> The %TypedArray% Intrinsic Object</h1>
+
+ <p>The %TypedArray% intrinsic object is a constructor-like function object that all of the <i>TypedArray</i> constructor
+ object inherit from. %TypedArray% and its corresponding prototype object provide common properties that are inherited by
+ all <i>TypedArray</i> constructors and their instances. The %TypedArray% intrinsic does not have a global name or appear
+ as a property of the global object.</p>
+
+ <p>If the <b>this</b> value passed in the call is an Object with a [[ViewedArrayBuffer]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> whose value is <span
+ class="value">undefined</span>, it initializes the <b>this</b> value using the argument values. This permits super
+ invocation of the <i>TypedArray</i> constructors by <i>TypedArray</i> subclasses.</p>
+
+ <p>The %TypedArray% intrinsic function object is designed to act as the superclass of the various <i>TypedArray</i>
+ constructors. Those constructors use %TypedArray% to initialize their instances by invoking %TypedArray% as if by making a
+ <code>super</code> call. The %TypedArray% intrinsic function is not designed to be directly called in any other way. If
+ %TypedArray% is directly called or called as part of a <code>new</code> expression an exception is thrown.</p>
+
+ <p>The actual behaviour of a <code>super</code> call of %TypedArray% depends upon the number and kind of arguments that
+ are passed to it.</p>
+ </div>
+
+ <section id="sec-%typedarray%-length">
+ <h1><span class="secnum" id="sec-22.2.1.1"><a href="#sec-%typedarray%-length"
+ title="link to this section">22.2.1.1</a></span> %TypedArray% ( length )</h1>
+
+ <p>This description applies if and only when %TypedArray% function is called and the Type of the first argument is not
+ Object.</p>
+
+ <p>%TypedArray% called with argument <var>length</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>length</i>) is not Object.</li>
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>O</i> does not have a [[TypedArrayName]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a>, then throw a <b>TypeError</b> exception.</li>
+ <li>If the value of <i>O’s</i> [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is <b>undefined</b>, then throw a
+ <b>TypeError</b> exception.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>O</i> has a [[ViewedArrayBuffer]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If the value of <i>O’s</i> [[ViewedArrayBuffer]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is not <b>undefined</b>, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>Let <i>constructorName</i> be the string value of <i>O</i>’s [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>elementType</i> be the string value of the Element Type value in <a href="#table-44">Table 44</a> for
+ <i>constructorName</i>.</li>
+ <li>Let <i>numberLength</i> be <a href="#sec-tonumber">ToNumber</a>(<i>length</i>).</li>
+ <li>Let <i>elementLength</i> be <a href="#sec-tolength">ToLength</a>(<i>numberLength</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>elementLength</i>).</li>
+ <li>If <a href="#sec-samevaluezero">SameValueZero</a>(<i>numberLength</i>, <i>elementLength</i>) is <b>false</b>, then
+ throw a <b>RangeError</b> exception.</li>
+ <li>Let <i>data</i> be <a href="#sec-allocatearraybuffer">AllocateArrayBuffer</a>(%ArrayBuffer%).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>data</i>).</li>
+ <li>Let <i>elementSize</i> be the Element Size value in <a href="#table-44">Table 44</a> for
+ <i>constructorName</i>.</li>
+ <li>Let <i>byteLength</i> be <i>elementSize</i> × <i>elementLength</i>.</li>
+ <li>Let <i>status</i> be <a href="#sec-setarraybufferdata">SetArrayBufferData</a>(<i>data</i>, <i>byteLength</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Set <i>O’s</i> [[ViewedArrayBuffer]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> to <i>data</i>.</li>
+ <li>Set <i>O</i>’s [[ByteLength]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to
+ <i>byteLength</i>.</li>
+ <li>Set <i>O</i>’s [[ByteOffset]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to
+ 0.</li>
+ <li>Set <i>O</i>’s [[ArrayLength]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to
+ <i>elementLength</i>.</li>
+ <li>Return <i>O</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-%typedarray%-typedarray">
+ <h1><span class="secnum" id="sec-22.2.1.2"><a href="#sec-%typedarray%-typedarray"
+ title="link to this section">22.2.1.2</a></span> %TypedArray% ( typedArray )</h1>
+
+ <p>This description applies if and only if the %TypedArray% function is called with at least one argument and the Type of
+ the first argument is Object and that object has a [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</p>
+
+ <p>%TypedArray%called with argument <var>typedArray</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>typedArray</i>) is Object and <i>typedArray</i> has a
+ [[TypedArrayName]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>srcArray</i> be <i>typedArray</i>.</li>
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object or if <i>O</i> does not have a
+ [[TypedArrayName]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>If the value of <i>O’s</i> [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is <b>undefined</b>, then throw a
+ <b>TypeError</b> exception.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>O</i> has a [[ViewedArrayBuffer]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If the value of <i>O’s</i> [[ViewedArrayBuffer]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is not <b>undefined</b>, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>If the value of <i>srcArray’s</i> [[ViewedArrayBuffer]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is <b>undefined</b>, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>Let <i>constructorName</i> be the string value of <i>O</i>’s [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>elementType</i> be the string value of the Element Type value in <a href="#table-44">Table 44</a> for
+ <i>constructorName</i>.</li>
+ <li>Let <i>elementLength</i> be the value of <i>srcArray’s</i> [[ArrayLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>srcName</i> be the string value of <i>srcArray’s</i> [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>srcType</i> be the string value of the Element Type value in <a href="#table-44">Table 44</a> for
+ <i>srcName</i>.</li>
+ <li>Let <i>srcElementSize</i> be the Element Size value in <a href="#table-44">Table 44</a> for <i>srcName</i>.</li>
+ <li>Let <i>srcData</i> be the value of <i>srcArray’s</i> [[ViewedArrayBuffer]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>srcByteOffset</i> be the value of <i>srcArray</i>’s [[ByteOffset]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>elementSize</i> be the Element Size value in <a href="#table-44">Table 44</a> for
+ <i>constructorName</i>.</li>
+ <li>Let <i>byteLength</i> be <i>elementSize</i> × <i>elementLength</i>.</li>
+ <li>If <a href="#sec-samevalue">SameValue</a>(<i>elementType</i>,<i>srcType</i>), then
+ <ol class="block">
+ <li>Let <i>data</i> be <a href="#sec-clonearraybuffer">CloneArrayBuffer</a>(<i>srcData</i>,
+ <i>srcByteOffset</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>data</i>).</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>bufferConstructor</i> be <a href="#sec-get-o-p">Get</a>(<i>srcData</i>, <code>"constructor"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>bufferConstructor</i>).</li>
+ <li>If <i>bufferConstructor</i> is <b>undefined</b>, then let <i>bufferConstructor</i> be %ArrayBuffer%.</li>
+ <li>Let <i>data</i> be <a href="#sec-allocatearraybuffer">AllocateArrayBuffer</a>(<i>bufferConstructor</i>).</li>
+ <li>Let <i>status</i> be <a href="#sec-setarraybufferdata">SetArrayBufferData</a>(<i>data</i>,
+ <i>byteLength</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Let <i>srcByteIndex</i> be <i>srcByteOffset</i>.</li>
+ <li>Let <i>targetByteIndex</i> be 0.</li>
+ <li>Let <i>count</i> be <i>elementLength</i>.</li>
+ <li>Repeat, while <i>count</i> >0
+ <ol class="block">
+ <li>Let <i>value</i> be <a href="#sec-getvaluefrombuffer">GetValueFromBuffer</a> (<i>srcData</i>,
+ <i>srcByteIndex</i>, <i>srcType</i>).</li>
+ <li>Let <i>status</i> be <a href="#sec-setvalueinbuffer">SetValueInBuffer</a>(<i>data</i>,
+ <i>targetByteIndex</i>, <i>elementType</i>, <i>value</i>).</li>
+ <li>Set <i>srcByteIndex</i> to <i>srcByteIndex</i> + <i>srcElementSize</i>.</li>
+ <li>Set <i>targetByteIndex</i> to <i>targetByteIndex</i> + <i>elementSize</i>.</li>
+ <li>Decrement <i>count</i> by 1.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>If the value of <i>O’s</i> [[ViewedArrayBuffer]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is not <b>undefined</b>, then throw a
+ <b>TypeError</b> exception.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>O</i> has not been reentrantly initialized.</li>
+ <li>Set <i>O’s</i> [[ViewedArrayBuffer]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> to <i>data</i>.</li>
+ <li>Set <i>O</i>’s [[ByteLength]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to
+ <i>byteLength</i>.</li>
+ <li>Set <i>O</i>’s [[ByteOffset]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to
+ 0.</li>
+ <li>Set <i>O</i>’s [[ArrayLength]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to
+ <i>elementLength</i>.</li>
+ <li>Return <i>O</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-%typedarray%-object">
+ <h1><span class="secnum" id="sec-22.2.1.3"><a href="#sec-%typedarray%-object"
+ title="link to this section">22.2.1.3</a></span> %TypedArray% ( object )</h1>
+
+ <p>This description applies when the %TypedArray% function is called with at least one argument and the Type of first
+ argument is Object and that object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</p>
+
+ <p>%TypedArray% called with argument <var>object</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>object</i>) is Object and <i>object</i> does not have
+ either a [[TypedArrayName]] or an [[ArrayBufferData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object or if <i>O</i> does not have a
+ [[TypedArrayName]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>If the value of <i>O’s</i> [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is <b>undefined</b>, then throw a
+ <b>TypeError</b> exception.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>O</i> has a [[ViewedArrayBuffer]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If the value of <i>O’s</i> [[ViewedArrayBuffer]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is not <b>undefined</b>, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>Return <a href="#sec-typedarrayfrom">TypedArrayFrom</a>(<b>undefined</b>, <i>O</i>, <i>items</i>, <b>undefined</b>,
+ <b>undefined</b>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-%typedarray%-buffer-byteoffset-length">
+ <h1><span class="secnum" id="sec-22.2.1.4"><a href="#sec-%typedarray%-buffer-byteoffset-length"
+ title="link to this section">22.2.1.4</a></span> %TypedArray% ( buffer [ , byteOffset [ , length ] ] )</h1>
+
+ <p>This description applies when the %TypedArray% function is called with at least one argument and the Type of the first
+ argument is Object and that object has an [[ArrayBufferData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</p>
+
+ <p>%TypedArray% called with arguments <span style="font-family: Times New Roman"><i>buffer</i>, <i>byteOffset</i>, and
+ <i>length</i></span> performs the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>buffer</i>) is Object and <i>buffer</i> has an
+ [[ArrayBufferData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>If the value of <i>buffer</i>’s [[ArrayBufferData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is <b>undefined</b>, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object or if <i>O</i> does not have a
+ [[TypedArrayName]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>If the value of <i>O’s</i> [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is <b>undefined</b>, then throw a
+ <b>TypeError</b> exception.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>O</i> has a [[ViewedArrayBuffer]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If the value of <i>O’s</i> [[ViewedArrayBuffer]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is not <b>undefined</b>, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>Let <i>constructorName</i> be the string value of <i>O</i>’s [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>elementType</i> be the string value of the Element Type value in <a href="#table-44">Table 44</a> for
+ <i>constructorName</i>.</li>
+ <li>Let <i>elementSize</i> be the Number value of the Element Size value in <a href="#table-44">Table 44</a> for
+ <i>constructorName</i>.</li>
+ <li>Let <i>offset</i> be <a href="#sec-tointeger">ToInteger</a>(<i>byteOffset</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>offset</i>).</li>
+ <li>If <i>offset</i> < 0, then throw a <b>RangeError</b> exception.</li>
+ <li>If <i>offset</i> <a href="#sec-algorithm-conventions">modulo</a> <i>elementSize</i> ≠ 0, then throw a
+ <b>RangeError</b> exception.</li>
+ <li>Let <i>bufferByteLength</i> be the value of <i>buffer’s</i> [[ArrayBufferByteLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>length</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>If <i>bufferByteLength</i> <a href="#sec-algorithm-conventions">modulo</a> <i>elementSize</i> ≠ 0, then throw
+ a <b>RangeError</b> exception.</li>
+ <li>Let <i>newByteLength</i> be <i>bufferByteLength</i> – <i>offset</i>.</li>
+ <li>If <i>newByteLength</i> < 0, then throw a <b>RangeError</b> exception.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>newLength</i> be <a href="#sec-tolength">ToLength</a>(<i>length).</i></li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>newLength</i>).</li>
+ <li>Let <i>newByteLength</i> be <i>newLength</i> × <i>elementSize</i>.</li>
+ <li>If <i>offset</i>+<i>newByteLength</i> > <i>bufferByteLength</i>, then throw a <b>RangeError</b>
+ exception.</li>
+ </ol>
+ </li>
+ <li>If the value of <i>O’s</i> [[ViewedArrayBuffer]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is not <b>undefined</b>, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>Set <i>O’s</i> [[ViewedArrayBuffer]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> to <i>buffer</i>.</li>
+ <li>Set <i>O</i>’s [[ByteLength]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to
+ <i>newByteLength</i>.</li>
+ <li>Set <i>O</i>’s [[ByteOffset]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to
+ <i>offset</i>.</li>
+ <li>Set <i>O</i>’s [[ArrayLength]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to
+ <i>newByteLength /</i> <i>elementSize</i> .</li>
+ <li>Return <i>O</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-%typedarray%-all-other-argument-combinations">
+ <h1><span class="secnum" id="sec-22.2.1.5"><a href="#sec-%typedarray%-all-other-argument-combinations"
+ title="link to this section">22.2.1.5</a></span> %TypedArray% ( all other argument combinations )</h1>
+
+ <p>If the %TypedArray% function is called with arguments that do not match any of the preceeding argument descriptions a
+ <b>TypeError</b> exception is thrown.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-%typedarray%-intrinsic-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-22.2.2"><a href="#sec-properties-of-the-%typedarray%-intrinsic-object"
+ title="link to this section">22.2.2</a></span> Properties of the %TypedArray% Intrinsic Object</h1>
+
+ <p>The %TypedArray% intrinsic object is a built-in function object. The value of the [[Prototype]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of %TypedArray% is the Function prototype object
+ (<a href="#sec-properties-of-the-function-prototype-object">19.2.3</a>).</p>
+
+ <p>Besides a <code>length</code> property whose value is 3 and a <code>name</code> property whose value is
+ <code>"TypedArray"</code>, %TypedArray% has the following properties:</p>
+ </div>
+
+ <section id="sec-%typedarray%.from">
+ <div class="front">
+ <h1><span class="secnum" id="sec-22.2.2.1"><a href="#sec-%typedarray%.from"
+ title="link to this section">22.2.2.1</a></span> %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] )</h1>
+
+ <p>When the <code>from</code> method is called with argument <var>source</var>, and optional arguments <i>mapfn</i> and
+ <i>thisArg</i>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>C</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-isconstructor">IsConstructor</a>(<i>C</i>) is <b>false</b>, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>Let <i>items</i> be <a href="#sec-toobject">ToObject</a>(<i>source</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>items</i>).</li>
+ <li>If <i>mapfn</i> was supplied, let <i>f</i> be <i>mapfn</i>; otherwise let <i>f</i> be <b>undefined</b>.</li>
+ <li>If <i>f</i> is not <b>undefined</b>, then
+ <ol class="block">
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>f</i>) is <b>false</b>, then throw a <b>TypeError</b>
+ exception.</li>
+ </ol>
+ </li>
+ <li>If <i>thisArg</i> was supplied, let <i>t</i> be <i>thisArg</i>; else let <i>t</i> be <b>undefined</b>.</li>
+ <li>Return <a href="#sec-typedarrayfrom">TypedArrayFrom</a>(<i>constructor</i>, <b>undefined</b>, <i>items</i>,
+ <i>f</i>, <i>t</i>).</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>from</code> method is <b>1</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>from</code> function is an intentionally generic factory method; it does not
+ require that its <b>this</b> value be a Typed Array constructor. Therefore it can be transferred to or inherited by
+ any other constructors that may be called with a single numeric argument. This function uses [[Put]] to store elements
+ into a newly created object and assume that the constructor sets the <code>length</code> property of the new object to
+ the argument value passed to it.</p>
+ </div>
+ </div>
+
+ <section id="sec-typedarrayfrom">
+ <h1><span class="secnum" id="sec-22.2.2.1.1"><a href="#sec-typedarrayfrom"
+ title="link to this section">22.2.2.1.1</a></span> Runtime Semantics: TypedArrayFrom( constructor, target, items,
+ mapfn, thisArg )</h1>
+
+ <p>When the TypedArrayFrom abstract operation is called with arguments <span style="font-family: Times New
+ Roman"><i>constructor</i>,</span> <span style="font-family: Times New Roman"><i>target</i>,</span> <var>items</var>,
+ <var>mapfn</var>, and <var>thisArg</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>C</i> be <i>constructor</i>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: one of <i>constructor</i> and <i>target</i> is
+ <b>undefined.</b></li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: If <i>constructor</i> is not <b>undefined</b>, then <a
+ href="#sec-isconstructor">IsConstructor</a>(<i>C</i>) is <b>true</b>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>target</i> is either <b>undefined</b> or an Object that has
+ been validated by the %TypedArray% constructor as described in <a
+ href="#sec-%typedarray%-object">22.2.1.3</a></li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>items</i>) is Object.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>mapfn</i>) is either a callable Object or Undefined.</li>
+ <li>If <i>mapfn</i> is <b>undefined</b>, then let <i>mapping</i> be <b>false.</b></li>
+ <li>else
+ <ol class="block">
+ <li>Let <i>T</i> be <i>thisArg</i>.</li>
+ <li>Let <i>mapping</i> be <b>true</b></li>
+ </ol>
+ </li>
+ <li>Let <i>usingIterator</i> be <a href="#sec-checkiterable">CheckIterable</a>(<i>items</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>usingIterator</i>).</li>
+ <li>If <i>usingIterator</i> is not <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>iterator</i> be <a href="#sec-getiterator">GetIterator</a>(<i>items</i>, <i>usingIterator</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>iterator</i>).</li>
+ <li>Let <i>values</i> be a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Let <i>next</i> be <b>true</b>.</li>
+ <li>Repeat, while <i>next</i> is not <b>false</b>
+ <ol class="block">
+ <li>Let <i>next</i> be <a href="#sec-iteratorstep">IteratorStep</a>(<i>iterator</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>next</i>).</li>
+ </ol>
+ </li>
+ <li>If <i>next</i> is not <b>false</b>, then
+ <ol class="block">
+ <li>Let <i>nextValue</i> be <a href="#sec-iteratorvalue">IteratorValue</a>(<i>next</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>nextValue</i>).</li>
+ <li>Append <i>nextValue</i> to the end of the <a href="#sec-list-and-record-specification-type">List</a>
+ <i>values</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>len</i> be the number of elements in <i>values</i>.</li>
+ <li>Let <i>targetObj</i> be <a href="#sec-typedarrayallocorinit">TypedArrayAllocOrInit</a>(<i>C</i>,
+ <i>target</i>, <i>len</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>targetObj</i>).</li>
+ <li>Let <i>k</i> be 0.</li>
+ <li>Repeat, while <i>k</i> < <i>len</i>
+ <ol class="block">
+ <li>Let <i>Pk</i> be <a href="#sec-tostring">ToString</a>(<i>k</i>).</li>
+ <li>Let <i>kValue</i> be the first element of <i>values</i> and remove that element from <i>list</i>.</li>
+ <li>If <i>mapping</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>mappedValue</i> be the result of calling the [[Call]] internal method of <i>mapfn</i> with
+ <i>T</i> as <i>thisArgument</i> and (<i>kValue</i>, <i>k</i>) as <i>argumentsList</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>mappedValue</i>).</li>
+ </ol>
+ </li>
+ <li>Else, let <i>mappedValue</i> be <i>kValue</i>.</li>
+ <li>Let <i>putStatus</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>targetObj</i>, <i>Pk</i>,
+ <i>mappedValue</i>, <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>putStatus</i>).</li>
+ <li>Increase <i>k</i> by 1.</li>
+ </ol>
+ </li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>values</i> is now an empty <a
+ href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Return <i>targetObj</i>.</li>
+ </ol>
+ </li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>items</i> is not an Iterator so assume it is an array-like
+ object.</li>
+ <li>Let <i>lenValue</i> be <a href="#sec-get-o-p">Get</a>(<i>items</i>, <code>"length"</code>).</li>
+ <li>Let <i>len</i> be <a href="#sec-tolength">ToLength</a>(<i>lenValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>len</i>).</li>
+ <li>Let <i>targetObj</i> be <a href="#sec-typedarrayallocorinit">TypedArrayAllocOrInit</a>(<i>C</i>, <i>target</i>,
+ <i>len</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>targetObj</i>).</li>
+ <li>Let <i>k</i> be 0.</li>
+ <li>Repeat, while <i>k</i> < <i>len</i>
+ <ol class="block">
+ <li>Let <i>Pk</i> be <a href="#sec-tostring">ToString</a>(<i>k</i>).</li>
+ <li>Let <i>kValue</i> be <a href="#sec-get-o-p">Get</a>(<i>items</i>, <i>Pk</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>kValue</i>).</li>
+ <li>If <i>mapping</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>mappedValue</i> be the result of calling the [[Call]] internal method of <i>mapfn</i> with <i>T</i>
+ as <i>thisArgument</i> and (<i>kValue</i>, <i>k</i>) as <i>argumentsList</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>mappedValue</i>).</li>
+ </ol>
+ </li>
+ <li>Else, let <i>mappedValue</i> be <i>kValue</i>.</li>
+ <li>Let <i>putStatus</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>targetObj</i>, <i>Pk</i>,
+ <i>mappedValue</i>, <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>putStatus</i>).</li>
+ <li>Increase <i>k</i> by 1.</li>
+ </ol>
+ </li>
+ <li>Return <i>targetObj</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-typedarrayallocorinit">
+ <h1><span class="secnum" id="sec-22.2.2.1.2"><a href="#sec-typedarrayallocorinit"
+ title="link to this section">22.2.2.1.2</a></span> Runtime Semantics: TypedArrayAllocOrInit( constructor, target,
+ length)</h1>
+
+ <p>When the TypedArrayAllocOrInit abstract operation is called with arguments <span style="font-family: Times New
+ Roman"><i>constructor</i>, <i>target</i>,</span> and <var>length</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: one of <i>constructor</i> and <i>target</i> is
+ <b>undefined.</b></li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: If <i>constructor</i> is not <b>undefined</b>, then <a
+ href="#sec-isconstructor">IsConstructor</a>(<i>constructor</i>) is <b>true</b>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>target</i> is either <b>undefined</b> or an Object that has
+ been validated by the %TypedArray% constructor as described in <a
+ href="#sec-%typedarray%-object">22.2.1.3</a></li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>length</i>) is Number.</li>
+ <li>If <i>target</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>targetObj</i> be the result of calling the [[Construct]] internal method of <i>constructor</i> with
+ argument (<i>length</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>targetObj</i>).</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>targetObj</i> be <i>target</i>.</li>
+ <li>Let <i>constructorName</i> be the string value of <i>targetObj</i>’s [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>elementType</i> be the string value of the Element Type value in <a href="#table-44">Table 44</a> for
+ <i>constructorName</i>.</li>
+ <li>Let <i>data</i> be <a href="#sec-allocatearraybuffer">AllocateArrayBuffer</a>(<span style="font-family:
+ sans-serif">%ArrayBuffer%</span>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>data</i>).</li>
+ <li>Let <i>elementSize</i> be the Element Size value in <a href="#table-44">Table 44</a> for
+ <i>constructorName</i>.</li>
+ <li>Let <i>byteLength</i> be <i>elementSize</i> × <i>length</i>.</li>
+ <li>Let <i>status</i> be <a href="#sec-setarraybufferdata">SetArrayBufferData</a>(<i>data</i>,
+ <i>byteLength</i>)</li>
+ <li>Note: Side-effects of preceding steps may have already initialized <i>targetObj</i>.</li>
+ <li>If the value of <i>targetObj’s</i> [[ViewedArrayBuffer]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is not <b>undefined</b>, then throw a
+ <b>TypeError</b> exception.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Set <i>targetObj’s</i> [[ViewedArrayBuffer]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to <i>data</i>.</li>
+ <li>Set <i>targetObj</i>’s [[ByteLength]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> to <i>byteLength</i>.</li>
+ <li>Set <i>targetObj</i>’s [[ByteOffset]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> to 0.</li>
+ <li>Set <i>targetObj</i>’s [[ArrayLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to <i>length</i>.</li>
+ </ol>
+ </li>
+ <li>Return <i>targetObj</i>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-%typedarray%.of">
+ <h1><span class="secnum" id="sec-22.2.2.2"><a href="#sec-%typedarray%.of" title="link to this section">22.2.2.2</a></span>
+ %TypedArray%.of ( ...items )</h1>
+
+ <p>When the <code>of</code> method is called with any number of arguments, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>len</i> be the actual number of arguments passed to this function.</li>
+ <li>Let <i>items</i> be the <a href="#sec-list-and-record-specification-type">List</a> of arguments passed to this
+ function.</li>
+ <li>Let <i>C</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-isconstructor">IsConstructor</a>(<i>C</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>newObj</i> be the result of calling the [[Construct]] internal method of <i>C</i> with argument
+ (<i>len</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>newObj</i>).</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Throw a <b>TypeError</b> exception.</li>
+ </ol>
+ </li>
+ <li>Let <i>k</i> be 0.</li>
+ <li>Repeat, while <i>k</i> < <i>len</i>
+ <ol class="block">
+ <li>Let <i>kValue</i> be element <i>k</i> of <i>items</i>.</li>
+ <li>Let <i>status</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>newObj</i>,<i>Pk</i>, <i>kValue</i>.[[value]],
+ <b>true</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Increase <i>k</i> by 1.</li>
+ </ol>
+ </li>
+ <li>Return <i>newObj</i>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>of</code> method is <b>0</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> The <i>items</i> argument is assumed to be a well-formed rest argument value.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 2</span> The <code>of</code> function is an intentionally generic factory method; it does not
+ require that its <b>this</b> value be a <i>TypedArray</i> constructor. Therefore it can be transferred to or inherited
+ by other constructors that may be called with a single numeric argument. However, it does assume that constructor
+ creates and initializes a length property that is initialized to its argument value.</p>
+ </div>
+ </section>
+
+ <section id="sec-%typedarray%.prototype">
+ <h1><span class="secnum" id="sec-22.2.2.3"><a href="#sec-%typedarray%.prototype"
+ title="link to this section">22.2.2.3</a></span> %TypedArray%.prototype</h1>
+
+ <p>The initial value of %TypedArray%.prototype is the %TypedArrayPrototype% intrinsic object (<a
+ href="#sec-properties-of-the-%typedarrayprototype%-object">22.2.3</a>).</p>
+
+ <p>This property has the attributes { [[Writable]]: <span class="value">false</span>, [[Enumerable]]: <span
+ class="value">false</span>, [[Configurable]]: <span class="value">false</span> }.</p>
+ </section>
+
+ <section id="sec-%typedarray%-@@create">
+ <h1><span class="secnum" id="sec-22.2.2.4"><a href="#sec-%typedarray%-@@create"
+ title="link to this section">22.2.2.4</a></span> %TypedArray% [ @@create ] ( )</h1>
+
+ <p>The @@create method of %TypedArray% performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be the <b>this</b> value.</li>
+ <li>Let <i>proto</i> be <a href="#sec-getprototypefromconstructor">GetPrototypeFromConstructor</a>(<i>F</i>,
+ <code>"%TypedArrayPrototype%"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>proto</i>).</li>
+ <li>Let <i>obj</i> be <a href="#sec-integerindexedobjectcreate">IntegerIndexedObjectCreate</a> (<i>proto</i>).</li>
+ <li>Add a [[ViewedArrayBuffer]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to
+ <i>obj</i> and set its initial value to <b>undefined</b>.</li>
+ <li>Add a [[TypedArrayName]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to <i>obj</i>
+ and set its initial value to <b>undefined</b> .</li>
+ <li>Add a [[ByteLength]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to <i>obj</i> and
+ set its initial value to 0.</li>
+ <li>Add a [[ByteOffset]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to <i>obj</i> and
+ set its initial value to 0.</li>
+ <li>Add an [[ArrayLength]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to <i>obj</i> and
+ set its initial value to 0.</li>
+ <li>Return <i>obj</i>.</li>
+ </ol>
+
+ <p>The value of the <code>name</code> property of this function is <code>"[Symbol.create]"</code>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <span class="value">false</span>, [[Enumerable]]: <span
+ class="value">false</span>, [[Configurable]]: <span class="value">true</span> }.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-%typedarrayprototype%-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-22.2.3"><a href="#sec-properties-of-the-%typedarrayprototype%-object"
+ title="link to this section">22.2.3</a></span> Properties of the %TypedArrayPrototype% Object</h1>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the
+ %TypedArrayPrototype% object is the standard built-in Object prototype object (<a
+ href="#sec-properties-of-the-object-prototype-object">19.1.3</a>). The %TypedArrayPrototype% object is an ordinary object.
+ It does not have a [[ViewedArrayBuffer]] or or any other of the internal slots that are specific to <i>TypedArray</i>
+ instance objects.</p>
+ </div>
+
+ <section id="sec-get-%typedarray%.prototype.buffer">
+ <h1><span class="secnum" id="sec-22.2.3.1"><a href="#sec-get-%typedarray%.prototype.buffer"
+ title="link to this section">22.2.3.1</a></span> get %TypedArray%.prototype.buffer</h1>
+
+ <p>%TypedArray%.<code>prototype.buffer</code> is an accessor property whose set accessor function is <span
+ class="value">undefined</span>. Its get accessor function performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object, throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>O</i> does not have a [[ViewedArrayBuffer]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>buffer</i> be the value of <i>O</i>’s [[ViewedArrayBuffer]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>buffer</i> is <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Return <i>buffer</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-get-%typedarray%.prototype.bytelength">
+ <h1><span class="secnum" id="sec-22.2.3.2"><a href="#sec-get-%typedarray%.prototype.bytelength"
+ title="link to this section">22.2.3.2</a></span> get %TypedArray%.prototype.byteLength</h1>
+
+ <p>%TypedArray%.<code>prototype.byteLength</code> is an accessor property whose set accessor function is <span
+ class="value">undefined</span>. Its get accessor function performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object, throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>O</i> does not have a [[ViewedArrayBuffer]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>buffer</i> be the value of <i>O</i>’s [[ViewedArrayBuffer]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>buffer</i> is <b>undefined</b>, then return 0.</li>
+ <li>Let <i>size</i> be the value of <i>O</i>’s [[ByteLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Return <i>size</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-get-%typedarray%.prototype.byteoffset">
+ <h1><span class="secnum" id="sec-22.2.3.3"><a href="#sec-get-%typedarray%.prototype.byteoffset"
+ title="link to this section">22.2.3.3</a></span> get %TypedArray%.prototype.byteOffset</h1>
+
+ <p>%TypedArray%.<code>prototype.byteOffset</code> is an accessor property whose set accessor function is <span
+ class="value">undefined</span>. Its get accessor function performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object, throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>O</i> does not have a [[ViewedArrayBuffer]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>buffer</i> be the value of <i>O</i>’s [[ViewedArrayBuffer]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>buffer</i> is <b>undefined</b>, then return 0.</li>
+ <li>Let <i>offset</i> be the value of <i>O</i>’s [[ByteOffset]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Return <i>offset</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-%typedarray%.prototype.constructor">
+ <h1><span class="secnum" id="sec-22.2.3.4"><a href="#sec-%typedarray%.prototype.constructor"
+ title="link to this section">22.2.3.4</a></span> %TypedArray%.prototype.constructor</h1>
+
+ <p>The initial value of %TypedArray%.prototype.constructor is the %TypedArray% intrinsic object.</p>
+ </section>
+
+ <section id="sec-%typedarray%.prototype.copywithin">
+ <h1><span class="secnum" id="sec-22.2.3.5"><a href="#sec-%typedarray%.prototype.copywithin"
+ title="link to this section">22.2.3.5</a></span> %TypedArray%.prototype.copyWithin (target, start, end = this.length
+ )</h1>
+
+ <p>%TypedArray%<code>.prototype.copyWithin</code> is a distinct function that implements the same algorithm as <code><a
+ href="#sec-array.prototype.copywithin">Array.prototype.copyWithin</a></code> as defined in <a
+ href="#sec-array.prototype.copywithin">22.1.3.3</a> except that the <b>this</b> object’s [[ArrayLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is accessed in place of performing a [[Get]] of
+ <code>"length"</code>. The implementation of the algorithm may be optimized with the knowledge that the <b>this</b> value
+ is an object that has a fixed length and whose integer indexed properties are not sparse. However, such optimization must
+ not introduce any observable changes in the specified behaviour of the algorithm.</p>
+
+ <p>This function is not generic. If the <b>this</b> value is not a object with a [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, a <span class="value">TypeError</span> exception
+ is immediately thrown when this function is called.</p>
+
+ <p>The <code>length</code> property of the <code>copyWithin</code> method is <b>2</b>.</p>
+ </section>
+
+ <section id="sec-%typedarray%.prototype.entries">
+ <h1><span class="secnum" id="sec-22.2.3.6"><a href="#sec-%typedarray%.prototype.entries"
+ title="link to this section">22.2.3.6</a></span> %TypedArray%.prototype.entries ( )</h1>
+
+ <p>The initial value of the %TypedArray%.<code>prototype.entries</code> data property is the same built-in function object
+ as the <code><a href="#sec-array.prototype.entries">Array.prototype.entries</a></code> method defined in <a
+ href="#sec-array.prototype.entries">22.1.3.4</a>.</p>
+ </section>
+
+ <section id="sec-%typedarray%.prototype.every">
+ <h1><span class="secnum" id="sec-22.2.3.7"><a href="#sec-%typedarray%.prototype.every"
+ title="link to this section">22.2.3.7</a></span> %TypedArray%.prototype.every ( callbackfn [ , thisArg ] )</h1>
+
+ <p>%TypedArray%<code>.prototype.every</code> is a distinct function that implements the same algorithm as <code><a
+ href="#sec-array.prototype.every">Array.prototype.every</a></code> as defined in <a
+ href="#sec-array.prototype.every">22.1.3.5</a> except that the <b>this</b> object’s [[ArrayLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is accessed in place of performing a [[Get]] of
+ <code>"length"</code>. The implementation of the algorithm may be optimized with the knowledge that the <b>this</b> value
+ is an object that has a fixed length and whose integer indexed properties are not sparse. However, such optimization must
+ not introduce any observable changes in the specified behaviour of the algorithm.</p>
+
+ <p>This function is not generic. If the <b>this</b> value is not a object with a [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, a <span class="value">TypeError</span> exception
+ is immediately thrown when this function is called.</p>
+
+ <p>The <code>length</code> property of the <code>every</code> method is <b>1</b>.</p>
+ </section>
+
+ <section id="sec-%typedarray%.prototype.fill">
+ <h1><span class="secnum" id="sec-22.2.3.8"><a href="#sec-%typedarray%.prototype.fill"
+ title="link to this section">22.2.3.8</a></span> %TypedArray%.prototype.fill (value [ , start [ , end ] ] )</h1>
+
+ <p>%TypedArray%<code>.prototype.fill</code> is a distinct function that implements the same algorithm as <code><a
+ href="#sec-array.prototype.fill">Array.prototype.fill</a></code> as defined in <a
+ href="#sec-array.prototype.fill">22.1.3.6</a> except that the <b>this</b> object’s [[ArrayLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is accessed in place of performing a [[Get]] of
+ <code>"length"</code>. The implementation of the algorithm may be optimized with the knowledge that the <b>this</b> value
+ is an object that has a fixed length and whose integer indexed properties are not sparse. However, such optimization must
+ not introduce any observable changes in the specified behaviour of the algorithm.</p>
+
+ <p>This function is not generic. If the <b>this</b> value is not a object with a [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, a <span class="value">TypeError</span> exception
+ is immediately thrown when this function is called.</p>
+
+ <p>The <code>length</code> property of the <code>fill</code> method is <b>1</b>.</p>
+ </section>
+
+ <section id="sec-%typedarray%.prototype.filter">
+ <h1><span class="secnum" id="sec-22.2.3.9"><a href="#sec-%typedarray%.prototype.filter"
+ title="link to this section">22.2.3.9</a></span> %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] )</h1>
+
+ <p>The interpretation and use of the arguments of %TypedArray%<code>.prototype.filter</code> are the same as for <code><a
+ href="#sec-array.prototype.filter">Array.prototype.filter</a></code> as defined in <a
+ href="#sec-array.prototype.filter">22.1.3.7</a>.</p>
+
+ <p>When the <code>filter</code> method is called with one or two arguments, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object, throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>O</i> does not have a [[TypedArrayName]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>len</i> be the value of <i>O’s</i> [[ArrayLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>callbackfn</i>) is <b>false</b>, throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>thisArg</i> was supplied, let <i>T</i> be <i>thisArg</i>; else let <i>T</i> be <b>undefined</b>.</li>
+ <li>Let <i>C</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <code>"constructor"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>C</i>).</li>
+ <li>If <a href="#sec-isconstructor">IsConstructor</a>(<i>C</i>) is <b>false</b>, then
+ <ol class="block">
+ <li>Throw a <b>TypeError</b> exception.</li>
+ </ol>
+ </li>
+ <li>Let <i>kept</i> be a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Let <i>k</i> be 0.</li>
+ <li>Let <i>captured</i> be 0.</li>
+ <li>Repeat, while <i>k</i> < <i>len</i>
+ <ol class="block">
+ <li>Let <i>Pk</i> be <a href="#sec-tostring">ToString</a>(<i>k</i>).</li>
+ <li>Let <i>kValue</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <i>Pk</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>kValue</i>).</li>
+ <li>Let <i>selected</i> be the result of calling the [[Call]] internal method of <i>callbackfn</i> with <i>T</i> as
+ <i>thisArgument</i> and a <a href="#sec-list-and-record-specification-type">List</a> containing <i>kValue</i>,
+ <i>k</i>, and <i>O</i> as <i>argumentsList</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>selected</i>).</li>
+ <li>If <a href="#sec-toboolean">ToBoolean</a>(<i>selected</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>Append <i>kValue</i> to the end of <i>kept</i>.</li>
+ <li>Increase <i>captured</i> by 1.</li>
+ </ol>
+ </li>
+ <li>Increase <i>k</i> by 1.</li>
+ </ol>
+ </li>
+ <li>Let <i>A</i> be the result of calling the [[Construct]] internal method of <i>C</i> with argument
+ (<i>captured</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>A</i>).</li>
+ <li>Let <i>n</i> be 0.</li>
+ <li>For each element <i>e</i> of <i>kept</i>
+ <ol class="block">
+ <li>Let <i>status</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>A</i>, <a
+ href="#sec-tostring">ToString</a>(<i>n</i>), <i>e</i>, <b>true</b> ).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Increment <i>n</i> by 1.</li>
+ </ol>
+ </li>
+ <li>Return <i>A</i>.</li>
+ </ol>
+
+ <p>This function is not generic. If the <b>this</b> value is not a object with a [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, a <span class="value">TypeError</span> exception
+ is immediately thrown when this function is called.</p>
+
+ <p>The <code>length</code> property of the <code>filter</code> method is <b>1</b>.</p>
+ </section>
+
+ <section id="sec-%typedarray%.prototype.find">
+ <h1><span class="secnum" id="sec-22.2.3.10"><a href="#sec-%typedarray%.prototype.find"
+ title="link to this section">22.2.3.10</a></span> %TypedArray%.prototype.find (predicate [ , thisArg ] )</h1>
+
+ <p>%TypedArray%<code>.prototype.find</code> is a distinct function that implements the same algorithm as <code><a
+ href="#sec-array.prototype.find">Array.prototype.find</a></code> as defined in <a
+ href="#sec-array.prototype.find">22.1.3.8</a> except that the <b>this</b> object’s [[ArrayLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is accessed in place of performing a [[Get]] of
+ <code>"length"</code>. The implementation of the algorithm may be optimized with the knowledge that the <b>this</b> value
+ is an object that has a fixed length and whose integer indexed properties are not sparse. However, such optimization must
+ not introduce any observable changes in the specified behaviour of the algorithm.</p>
+
+ <p>This function is not generic. If the <b>this</b> value is not a object with a [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, a <span class="value">TypeError</span> exception
+ is immediately thrown when this function is called.</p>
+
+ <p>The <code>length</code> property of the <code>find</code> method is <b>1</b>.</p>
+ </section>
+
+ <section id="sec-%typedarray%.prototype.findindex">
+ <h1><span class="secnum" id="sec-22.2.3.11"><a href="#sec-%typedarray%.prototype.findindex"
+ title="link to this section">22.2.3.11</a></span> %TypedArray%.prototype.findIndex ( predicate [ , thisArg ] )</h1>
+
+ <p>%TypedArray%<code>.prototype.findIndex</code> is a distinct function that implements the same algorithm as <code><a
+ href="#sec-array.prototype.findindex">Array.prototype.findIndex</a></code> as defined in <a
+ href="#sec-array.prototype.findindex">22.1.3.9</a> except that the <b>this</b> object’s [[ArrayLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is accessed in place of performing a [[Get]] of
+ <code>"length"</code>. The implementation of the algorithm may be optimized with the knowledge that the <b>this</b> value
+ is an object that has a fixed length and whose integer indexed properties are not sparse. However, such optimization must
+ not introduce any observable changes in the specified behaviour of the algorithm.</p>
+
+ <p>This function is not generic. If the <b>this</b> value is not a object with a [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, a <span class="value">TypeError</span> exception
+ is immediately thrown when this function is called.</p>
+
+ <p>The <code>length</code> property of the <code>findIndex</code> method is <b>1</b>.</p>
+ </section>
+
+ <section id="sec-%typedarray%.prototype.foreach">
+ <h1><span class="secnum" id="sec-22.2.3.12"><a href="#sec-%typedarray%.prototype.foreach"
+ title="link to this section">22.2.3.12</a></span> %TypedArray%.prototype.forEach ( callbackfn [ , thisArg ] )</h1>
+
+ <p>%TypedArray%<code>.prototype.forEach</code> is a distinct function that implements the same algorithm as <code><a
+ href="#sec-array.prototype.foreach">Array.prototype.forEach</a></code> as defined in <a
+ href="#sec-array.prototype.foreach">22.1.3.10</a> except that the <b>this</b> object’s [[ArrayLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is accessed in place of performing a [[Get]] of
+ <code>"length"</code>. The implementation of the algorithm may be optimized with the knowledge that the <b>this</b> value
+ is an object that has a fixed length and whose integer indexed properties are not sparse. However, such optimization must
+ not introduce any observable changes in the specified behaviour of the algorithm.</p>
+
+ <p>This function is not generic. If the <b>this</b> value is not a object with a [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, a <span class="value">TypeError</span> exception
+ is immediately thrown when this function is called.</p>
+
+ <p>The <code>length</code> property of the <code>forEach</code> method is <b>1</b>.</p>
+ </section>
+
+ <section id="sec-%typedarray%.prototype.indexof">
+ <h1><span class="secnum" id="sec-22.2.3.13"><a href="#sec-%typedarray%.prototype.indexof"
+ title="link to this section">22.2.3.13</a></span> %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] )</h1>
+
+ <p>%TypedArray%<code>.prototype.indexOf</code> is a distinct function that implements the same algorithm as <code><a
+ href="#sec-array.prototype.indexof">Array.prototype.indexOf</a></code> as defined in <a
+ href="#sec-array.prototype.indexof">22.1.3.11</a> except that the <b>this</b> object’s [[ArrayLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is accessed in place of performing a [[Get]] of
+ <code>"length"</code>. The implementation of the algorithm may be optimized with the knowledge that the <b>this</b> value
+ is an object that has a fixed length and whose integer indexed properties are not sparse. However, such optimization must
+ not introduce any observable changes in the specified behaviour of the algorithm.</p>
+
+ <p>This function is not generic. If the <b>this</b> value is not a object with a [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, a <span class="value">TypeError</span> exception
+ is immediately thrown when this function is called.</p>
+
+ <p>The <code>length</code> property of the <code>indexOf</code> method is <b>1</b>.</p>
+ </section>
+
+ <section id="sec-%typedarray%.prototype.join">
+ <h1><span class="secnum" id="sec-22.2.3.14"><a href="#sec-%typedarray%.prototype.join"
+ title="link to this section">22.2.3.14</a></span> %TypedArray%.prototype.join ( separator )</h1>
+
+ <p>%TypedArray%<code>.prototype.join</code> is a distinct function that implements the same algorithm as <code><a
+ href="#sec-array.prototype.join">Array.prototype.join</a></code> as defined in <a
+ href="#sec-array.prototype.join">22.1.3.12</a> except that the <b>this</b> object’s [[ArrayLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is accessed in place of performing a [[Get]] of
+ <code>"length"</code>. The implementation of the algorithm may be optimized with the knowledge that the <b>this</b> value
+ is an object that has a fixed length and whose integer indexed properties are not sparse. However, such optimization must
+ not introduce any observable changes in the specified behaviour of the algorithm.</p>
+
+ <p>This function is not generic. If the <b>this</b> value is not a object with a [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, a <span class="value">TypeError</span> exception
+ is immediately thrown when this function is called.</p>
+ </section>
+
+ <section id="sec-%typedarray%.prototype.keys">
+ <h1><span class="secnum" id="sec-22.2.3.15"><a href="#sec-%typedarray%.prototype.keys"
+ title="link to this section">22.2.3.15</a></span> %TypedArray%.prototype.keys ( )</h1>
+
+ <p>The initial value of the %TypedArray%.<code>prototype.keys</code> data property is the same built-in function object as
+ the <code><a href="#sec-array.prototype.keys">Array.prototype.keys</a></code> method defined in <a
+ href="#sec-array.prototype.keys">22.1.3.13</a>.</p>
+ </section>
+
+ <section id="sec-%typedarray%.prototype.lastindexof">
+ <h1><span class="secnum" id="sec-22.2.3.16"><a href="#sec-%typedarray%.prototype.lastindexof"
+ title="link to this section">22.2.3.16</a></span> %TypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ]
+ )</h1>
+
+ <p>%TypedArray%<code>.prototype.lastIndexOf</code> is a distinct function that implements the same algorithm as <code><a
+ href="#sec-array.prototype.lastindexof">Array.prototype.lastIndexOf</a></code> as defined in <a
+ href="#sec-array.prototype.lastindexof">22.1.3.14</a> except that the <b>this</b> object’s [[ArrayLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is accessed in place of performing a [[Get]] of
+ <code>"length"</code>. The implementation of the algorithm may be optimized with the knowledge that the <b>this</b> value
+ is an object that has a fixed length and whose integer indexed properties are not sparse. However, such optimization must
+ not introduce any observable changes in the specified behaviour of the algorithm.</p>
+
+ <p>This function is not generic. If the <b>this</b> value is not a object with a [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, a <span class="value">TypeError</span> exception
+ is immediately thrown when this function is called.</p>
+
+ <p>The <code>length</code> property of the <code>lastIndexOf</code> method is <b>1</b>.</p>
+ </section>
+
+ <section id="sec-get-%typedarray%.prototype.length">
+ <h1><span class="secnum" id="sec-22.2.3.17"><a href="#sec-get-%typedarray%.prototype.length"
+ title="link to this section">22.2.3.17</a></span> get %TypedArray%.prototype.length</h1>
+
+ <p>%TypedArray%.<code>prototype.length</code> is an accessor property whose set accessor function is <span
+ class="value">undefined</span>. Its get accessor function performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object, throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>O</i> does not have a [[TypedArrayName]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a>, then throw a <b>TypeError</b> exception.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>O</i> has [[ViewedArrayBuffer]] and [[ArrayLength]] internal
+ slots.</li>
+ <li>Let <i>buffer</i> be the value of <i>O</i>’s [[ViewedArrayBuffer]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>buffer</i> is <b>undefined</b>, then return 0.</li>
+ <li>Let <i>length</i> be the value of <i>O</i>’s [[ArrayLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Return <i>length</i>.</li>
+ </ol>
+
+ <p>This function is not generic. If the <b>this</b> value is not a object with a [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, a <span class="value">TypeError</span> exception
+ is immediately thrown when this function is called.</p>
+ </section>
+
+ <section id="sec-%typedarray%.prototype.map">
+ <h1><span class="secnum" id="sec-22.2.3.18"><a href="#sec-%typedarray%.prototype.map"
+ title="link to this section">22.2.3.18</a></span> %TypedArray%.prototype.map ( callbackfn [ , thisArg ] )</h1>
+
+ <p>The interpretation and use of the arguments of %TypedArray%<code>.prototype.map</code> are the same as for <code><a
+ href="#sec-array.prototype.map">Array.prototype.map</a></code> as defined in <a
+ href="#sec-array.prototype.map">22.1.3.15</a>.</p>
+
+ <p>When the <code>map</code> method is called with one or two arguments, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object, throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>O</i> does not have a [[TypedArrayName]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>len</i> be the value of <i>O’s</i> [[ArrayLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>callbackfn</i>) is <b>false</b>, throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>thisArg</i> was supplied, let <i>T</i> be <i>thisArg</i>; else let <i>T</i> be <b>undefined</b>.</li>
+ <li>Let <i>C</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <code>"constructor"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>C</i>).</li>
+ <li>If <a href="#sec-isconstructor">IsConstructor</a>(<i>C</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>A</i> be the result of calling the [[Construct]] internal method of <i>C</i> with argument <a
+ href="#sec-list-and-record-specification-type">List</a> (<i>len</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>A</i>).</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Throw a <b>TypeError</b> exception.</li>
+ </ol>
+ </li>
+ <li>Let <i>k</i> be 0.</li>
+ <li>Repeat, while <i>k</i> < <i>len</i>
+ <ol class="block">
+ <li>Let <i>Pk</i> be <a href="#sec-tostring">ToString</a>(<i>k</i>).</li>
+ <li>Let <i>kValue</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <i>Pk</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>kValue</i>).</li>
+ <li>Let <i>mappedValue</i> be the result of calling the [[Call]] internal method of <i>callbackfn</i> with <i>T</i>
+ as <i>thisArgument</i> and a <a href="#sec-list-and-record-specification-type">List</a> containing
+ <i>kValue</i>, <i>k</i>, and <i>O</i> as <i>argumentsList</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>mappedValue</i>).</li>
+ <li>Let <i>status</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>A</i>, <i>Pk</i>, <i>mappedValue</i>, <b>true</b>
+ ).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Increase <i>k</i> by 1.</li>
+ </ol>
+ </li>
+ <li>Return <i>A</i>.</li>
+ </ol>
+
+ <p>This function is not generic. If the <b>this</b> value is not a object with a [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, a <span class="value">TypeError</span> exception
+ is immediately thrown when this function is called.</p>
+
+ <p>The <code>length</code> property of the <code>map</code> method is <b>1</b>.</p>
+ </section>
+
+ <section id="sec-%typedarray%.prototype.reduce">
+ <h1><span class="secnum" id="sec-22.2.3.19"><a href="#sec-%typedarray%.prototype.reduce"
+ title="link to this section">22.2.3.19</a></span> %TypedArray%.prototype.reduce ( callbackfn [ , initialValue ] )</h1>
+
+ <p>%TypedArray%<code>.prototype.reduce</code> is a distinct function that implements the same algorithm as <code><a
+ href="#sec-array.prototype.reduce">Array.prototype.reduce</a></code> as defined in <a
+ href="#sec-array.prototype.reduce">22.1.3.18</a> except that the <b>this</b> object’s [[ArrayLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is accessed in place of performing a [[Get]] of
+ <code>"length"</code>. The implementation of the algorithm may be optimized with the knowledge that the <b>this</b> value
+ is an object that has a fixed length and whose integer indexed properties are not sparse. However, such optimization must
+ not introduce any observable changes in the specified behaviour of the algorithm.</p>
+
+ <p>This function is not generic. If the <b>this</b> value is not a object with a [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, a <span class="value">TypeError</span> exception
+ is immediately thrown when this function is called.</p>
+
+ <p>The <code>length</code> property of the <code>reduce</code> method is <b>1</b>.</p>
+ </section>
+
+ <section id="sec-%typedarray%.prototype.reduceright">
+ <h1><span class="secnum" id="sec-22.2.3.20"><a href="#sec-%typedarray%.prototype.reduceright"
+ title="link to this section">22.2.3.20</a></span> %TypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ]
+ )</h1>
+
+ <p>%TypedArray%<code>.prototype.reduceRight</code> is a distinct function that implements the same algorithm as <code><a
+ href="#sec-array.prototype.reduceright">Array.prototype.reduceRight</a></code> as defined in <a
+ href="#sec-array.prototype.reduceright">22.1.3.19</a> except that the <b>this</b> object’s [[ArrayLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is accessed in place of performing a [[Get]] of
+ <code>"length"</code>. The implementation of the algorithm may be optimized with the knowledge that the <b>this</b> value
+ is an object that has a fixed length and whose integer indexed properties are not sparse. However, such optimization must
+ not introduce any observable changes in the specified behaviour of the algorithm.</p>
+
+ <p>This function is not generic. If the <b>this</b> value is not a object with a [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, a <span class="value">TypeError</span> exception
+ is immediately thrown when this function is called.</p>
+
+ <p>The <code>length</code> property of the <code>reduceRight</code> method is <b>1</b>.</p>
+ </section>
+
+ <section id="sec-%typedarray%.prototype.reverse">
+ <h1><span class="secnum" id="sec-22.2.3.21"><a href="#sec-%typedarray%.prototype.reverse"
+ title="link to this section">22.2.3.21</a></span> %TypedArray%.prototype.reverse ( )</h1>
+
+ <p>%TypedArray%<code>.prototype.reverse</code> is a distinct function that implements the same algorithm as <code><a
+ href="#sec-array.prototype.reverse">Array.prototype.reverse</a></code> as defined in <a
+ href="#sec-array.prototype.reverse">22.1.3.20</a> except that the <b>this</b> object’s [[ArrayLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is accessed in place of performing a [[Get]] of
+ <code>"length"</code>. The implementation of the algorithm may be optimized with the knowledge that the <b>this</b> value
+ is an object that has a fixed length and whose integer indexed properties are not sparse. However, such optimization must
+ not introduce any observable changes in the specified behaviour of the algorithm.</p>
+
+ <p>This function is not generic. If the <b>this</b> value is not a object with a [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, a <span class="value">TypeError</span> exception
+ is immediately thrown when this function is called.</p>
+ </section>
+
+ <section id="sec-%typedarray%.prototype.set-array-offset">
+ <h1><span class="secnum" id="sec-22.2.3.22"><a href="#sec-%typedarray%.prototype.set-array-offset"
+ title="link to this section">22.2.3.22</a></span> %TypedArray%.prototype.set(array [ , offset ] )</h1>
+
+ <p>Set multiple values in this <i>TypedArray</i>, reading the values from the object <i>array</i>. The optional
+ <i>offset</i> value indicates the first element index in this <i>TypedArray</i> where values are written. If omitted, it
+ is assumed to be 0.</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>array</i> does not have a [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>. If it does, the definition in <a
+ href="#sec-%typedarray%.prototype.set-typedarray-offset">22.2.3.23</a> applies.</li>
+ <li>Let <i>target</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>target</i>) is not Object, throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>target</i> does not have a [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, then throw a <b>TypeError</b>
+ exception.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>target</i> has a [[ViewedArrayBuffer]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>targetBuffer</i> be the value of <i>target</i>’s [[ViewedArrayBuffer]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>targetBuffer</i> is <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>targetLength</i> be the value of <i>target</i>’s [[ArrayLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>targetOffset</i> be <a href="#sec-tointeger">ToInteger</a> (<i>offset</i>)</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>targetOffset</i>).</li>
+ <li>If <i>targetOffset</i> < 0, then throw a <b>RangeError</b> exception.</li>
+ <li>Let <i>targetName</i> be the string value of <i>target</i>’s [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>targetElementSize</i> be the Number value of the Element Size value specified in <a href="#table-44">Table
+ 44</a> for <i>targetName</i>.</li>
+ <li>Let <i>targetType</i> be the string value of the Element Type value in <a href="#table-44">Table 44</a> for
+ <i>targetName</i>.</li>
+ <li>Let <i>targetByteOffset</i> be the value of <i>target</i>’s [[ByteOffset]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>src</i> be <a href="#sec-toobject">ToObject</a>(<i>array</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>src</i>).</li>
+ <li>Let <i>srcLen</i> be <a href="#sec-get-o-p">Get</a>(<i>src</i>, <code>"length"</code>).</li>
+ <li>Let <i>numberLength</i> be <a href="#sec-tonumber">ToNumber</a>(<i>srcLen</i>).</li>
+ <li>Let <i>srcLength</i> be <a href="#sec-tointeger">ToInteger</a>(<i>numberLength</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>srcLength</i>).</li>
+ <li>If <i>numberLength</i> ≠ <i>srcLength</i> or <i>srcLength</i> < 0, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>srcLength</i> + <i>targetOffset</i> > <i>targetLength</i>, then throw a <b>RangeError</b> exception.</li>
+ <li>Let <i>targetByteIndex</i> be <i>targetOffset</i> × <i>targetElementSize</i> + <i>targetByteOffset</i>.</li>
+ <li>Let <i>k</i> be 0.</li>
+ <li>Let <i>limit</i> be <i>targetByteIndex</i> + <i>targetElementSize</i> × min(<i>srcLength</i>,
+ <i>targetLength</i> – <i>targetOffset</i>).</li>
+ <li>Repeat, while <i>targetByteIndex</i> < <i>limit</i>
+ <ol class="block">
+ <li>Let <i>Pk</i> be <a href="#sec-tostring">ToString</a>(<i>k</i>).</li>
+ <li>Let <i>kValue</i> be <a href="#sec-get-o-p">Get</a>(<i>src</i>, <i>Pk</i>).</li>
+ <li>Let <i>kNumber</i> be <a href="#sec-tonumber">ToNumber</a>(<i>kValue</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>kNumber</i>).</li>
+ <li>Perform <a href="#sec-setvalueinbuffer">SetValueInBuffer</a>(<i>targetBuffer</i>, <i>targetByteIndex</i>,
+ <i>targetType</i>, <i>kNumber</i>).</li>
+ <li>Set <i>k</i> to <i>k</i> + 1.</li>
+ <li>Set <i>targetByteIndex</i> to <i>targetByteIndex</i> + <i>targetElementSize</i>.</li>
+ </ol>
+ </li>
+ <li>Return <b>undefined</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-%typedarray%.prototype.set-typedarray-offset">
+ <h1><span class="secnum" id="sec-22.2.3.23"><a href="#sec-%typedarray%.prototype.set-typedarray-offset"
+ title="link to this section">22.2.3.23</a></span> %TypedArray%.prototype.set(typedArray [, offset ] )</h1>
+
+ <p>Set multiple values in this <i>TypedArray</i>, reading the values from the <var>typedArray</var> argument object. The
+ optional <i>offset</i> value indicates the first element index in this <i>TypedArray</i> where values are written. If
+ omitted, it is assumed to be 0.</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>typedArray</i> has a [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>. If it does not, the definition in <a
+ href="#sec-%typedarray%.prototype.set-array-offset">22.2.3.22</a> applies.</li>
+ <li>Let <i>target</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>target</i>) is not Object, throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>target</i> does not have a [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, then throw a <b>TypeError</b>
+ exception.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>target</i> has a [[ViewedArrayBuffer]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>targetBuffer</i> be the value of <i>target</i>’s [[ViewedArrayBuffer]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>targetBuffer</i> is <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>srcBuffer</i> be the value of <i>typedArray</i>’s [[ViewedArrayBuffer]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>srcBuffer</i> is <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>targetLength</i> be the value of <i>target</i>’s [[ArrayLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>targetOffset</i> be <a href="#sec-tointeger">ToInteger</a> (<i>offset</i>)</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>targetOffset</i>).</li>
+ <li>If <i>targetOffset</i> < 0, then throw a <b>RangeError</b> exception.</li>
+ <li>Let <i>targetName</i> be the string value of <i>target</i>’s [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>targetType</i> be the string value of the Element Type value in <a href="#table-44">Table 44</a> for
+ <i>targetName</i>.</li>
+ <li>Let <i>targetElementSize</i> be the Number value of the Element Size value specified in <a href="#table-44">Table
+ 44</a> for <i>targetName</i>.</li>
+ <li>Let <i>targetByteOffset</i> be the value of <i>target</i>’s [[ByteOffset]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>srcName</i> be the string value of <i>typedArray</i>’s [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>srcType</i> be the string value of the Element Type value in <a href="#table-44">Table 44</a> for
+ <i>srcName</i> .</li>
+ <li>Let <i>srcElementSize</i> be the Number value of the Element Size value specified in <a href="#table-44">Table
+ 44</a> for <i>srcName</i>.</li>
+ <li>Let <i>srcLength</i> be the value of <i>typedArray</i>’s [[ArrayLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>srcByteOffset</i> be the value of <i>typedArray</i>’s [[ByteOffset]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>srcLength</i> + <i>targetOffset</i> > <i>targetLength</i>, then throw a <b>RangeError</b> exception.</li>
+ <li>If <a href="#sec-samevalue">SameValue</a>(<i>srcBuffer</i>, <i>targetBuffer</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>srcBuffer</i> be <a href="#sec-clonearraybuffer">CloneArrayBuffer</a>(<i>srcBuffer</i>,
+ <i>srcByteOffset</i>).</li>
+ <li>Let <i>srcByteIndex</i> be 0.</li>
+ </ol>
+ </li>
+ <li>Else, let <i>srcByteIndex</i> be <i>srcByteOffset</i>.</li>
+ <li>Let <i>targetByteIndex</i> be <i>targetOffset</i> × <i>targetElementSize</i> + <i>targetByteOffset</i>.</li>
+ <li>Let <i>limit</i> be <i>targetByteIndex</i> + <i>targetElementSize</i> × min(<i>srcLength</i>,
+ <i>targetLength</i> – <i>targetOffset</i>).</li>
+ <li>Repeat, while <i>targetByteIndex</i> < <i>limit</i>
+ <ol class="block">
+ <li>Let <i>value</i> be <a href="#sec-getvaluefrombuffer">GetValueFromBuffer</a> (<i>srcBuffer</i>,
+ <i>srcByteIndex</i>, <i>srcType</i>).</li>
+ <li>Let <i>status</i> be <a href="#sec-setvalueinbuffer">SetValueInBuffer</a> (<i>targetBuffer</i>,
+ <i>targetByteIndex</i>, <i>targetType</i>, <i>value</i>).</li>
+ <li>Set <i>srcByteIndex</i> to <i>srcByteIndex</i> + <i>srcElementSize</i>.</li>
+ <li>Set <i>targetByteIndex</i> to <i>targetByteIndex</i> + <i>targetElementSize</i>.</li>
+ </ol>
+ </li>
+ <li>Return <b>undefined</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-%typedarray%.prototype.slice">
+ <h1><span class="secnum" id="sec-22.2.3.24"><a href="#sec-%typedarray%.prototype.slice"
+ title="link to this section">22.2.3.24</a></span> %TypedArray%.prototype.slice ( start, end )</h1>
+
+ <p>The interpretation and use of the arguments of %TypedArray%<code>.prototype.slice</code> are the same as for <code><a
+ href="#sec-array.prototype.slice">Array.prototype.slice</a></code> as defined in <a
+ href="#sec-array.prototype.slice">22.1.3.22</a>. The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object, throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>O</i> does not have a [[TypedArrayName]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>len</i> be the value of <i>O’s</i> [[ArrayLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>relativeStart</i> be <a href="#sec-tointeger">ToInteger</a>(<i>start</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>relativeStart</i>).</li>
+ <li>If <i>relativeStart</i> is negative, let <i>k</i> be max((<i>len</i> + <i>relativeStart</i>),0); else let <i>k</i>
+ be min(<i>relativeStart</i>, <i>len</i>).</li>
+ <li>If <i>end</i> is <b>undefined</b>, let <i>relativeEnd</i> be <i>len</i>; else let <i>relativeEnd</i> be <a
+ href="#sec-tointeger">ToInteger</a>(<i>end</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>relativeEnd</i>).</li>
+ <li>If <i>relativeEnd</i> is negative, let <i>final</i> be max((<i>len</i> + <i>relativeEnd</i>),0); else let
+ <i>final</i> be min(<i>relativeEnd</i>, <i>len</i>).</li>
+ <li>Let <i>count</i> be max(<i>final</i> – <i>k</i>, 0).</li>
+ <li>Let <i>C</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <code>"constructor"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>C</i>).</li>
+ <li>If <a href="#sec-isconstructor">IsConstructor</a>(<i>C</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>A</i> be the result of calling the [[Construct]] internal method of <i>C</i> with argument
+ (<i>count</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>A</i>).</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Throw a <b>TypeError</b> exception.</li>
+ </ol>
+ </li>
+ <li>Let <i>n</i> be 0.</li>
+ <li>Repeat, while <i>k</i> < <i>final</i>
+ <ol class="block">
+ <li>Let <i>Pk</i> be <a href="#sec-tostring">ToString</a>(<i>k</i>).</li>
+ <li>Let <i>kValue</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <i>Pk</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>kValue</i>).</li>
+ <li>Let <i>status</i> be <a href="#sec-put-o-p-v-throw">Put</a>(<i>A</i>, <a
+ href="#sec-tostring">ToString</a>(<i>n</i>), <i>kValue</i>, <b>true</b> ).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Increase <i>k</i> by 1.</li>
+ <li>Increase <i>n</i> by 1.</li>
+ </ol>
+ </li>
+ <li>Return <i>A</i>.</li>
+ </ol>
+
+ <p>This function is not generic. If the <b>this</b> value is not a object with a [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, a <span class="value">TypeError</span> exception
+ is immediately thrown when this function is called.</p>
+
+ <p>The <code>length</code> property of the <code>slice</code> method is <b>2</b>.</p>
+ </section>
+
+ <section id="sec-%typedarray%.prototype.some">
+ <h1><span class="secnum" id="sec-22.2.3.25"><a href="#sec-%typedarray%.prototype.some"
+ title="link to this section">22.2.3.25</a></span> %TypedArray%.prototype.some ( callbackfn [ , thisArg ] )</h1>
+
+ <p>%TypedArray%<code>.prototype.some</code> is a distinct function that implements the same algorithm as <code><a
+ href="#sec-array.prototype.some">Array.prototype.some</a></code> as defined in <a
+ href="#sec-array.prototype.some">22.1.3.23</a> except that the <b>this</b> object’s [[ArrayLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is accessed in place of performing a [[Get]] of
+ <code>"length"</code>. The implementation of the algorithm may be optimized with the knowledge that the <b>this</b> value
+ is an object that has a fixed length and whose integer indexed properties are not sparse. However, such optimization must
+ not introduce any observable changes in the specified behaviour of the algorithm.</p>
+
+ <p>This function is not generic. If the <b>this</b> value is not a object with a [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, a <span class="value">TypeError</span> exception
+ is immediately thrown when this function is called.</p>
+
+ <p>The <code>length</code> property of the <code>some</code> method is <b>1</b>.</p>
+ </section>
+
+ <section id="sec-%typedarray%.prototype.sort">
+ <h1><span class="secnum" id="sec-22.2.3.26"><a href="#sec-%typedarray%.prototype.sort"
+ title="link to this section">22.2.3.26</a></span> %TypedArray%.prototype.sort ( comparefn )</h1>
+
+ <p>%TypedArray%<code>.prototype.sort</code> is a distinct function that, except as described below, implements the same
+ requirements as those of <code><a href="#sec-array.prototype.sort">Array.prototype.sort</a></code> as defined in <a
+ href="#sec-array.prototype.sort">22.1.3.24</a>. The implementation of the %TypedArray%<code>.prototype.sort</code>
+ specification may be optimized with the knowledge that the <b>this</b> value is an object that has a fixed length and
+ whose integer indexed properties are not sparse. The only internal methods of the <b>this</b> object that the algorithm
+ may call are [[Get]] and [[Set]].</p>
+
+ <p>This function is not generic. If the <b>this</b> value is not a object with a [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, a <span class="value">TypeError</span> exception
+ is immediately thrown when it is called.</p>
+
+ <p>Upon entry, the following steps are performed to initialize evaluation of the <code>sort</code> function. These steps
+ are used instead of the entry steps in <a href="#sec-array.prototype.sort">22.1.3.24</a>:</p>
+
+ <ol class="proc">
+ <li>Let <i>obj</i> be the <b>this</b> value as the argument.</li>
+ <li>If <i>obj</i> does not have a [[TypedArrayName]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>len</i> be the value of <i>obj</i>’s [[ArrayLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ </ol>
+
+ <p>The following version of <a href="#sec-sortcompare">SortCompare</a> is used by
+ %TypedArray%<code>.prototype.sort</code>. It performs a numeric comparison rather than the string comparsion used in <a
+ href="#sec-array.prototype.sort">22.1.3.24</a>.</p>
+
+ <p>The Typed Array <a href="#sec-sortcompare">SortCompare</a> abstract operation is called with two arguments <var>j</var>
+ and <var>k</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>jString</i> be <a href="#sec-tostring">ToString</a>(<i>j</i>).</li>
+ <li>Let <i>kString</i> be <a href="#sec-tostring">ToString</a>(<i>k</i>).</li>
+ <li>Let <i>x</i> be <a href="#sec-get-o-p">Get</a>(<i>obj</i>,<i>jString</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>x</i>).</li>
+ <li>Let <i>y</i> be the result of <a href="#sec-get-o-p">Get</a>(<i>obj</i>, <i>kString</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>y</i>).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: Both <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>x</i>) and <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>y</i>) is Number.</li>
+ <li>If <i>x</i> and <i>y</i> are both <b>NaN</b>, return <b>+0</b>.</li>
+ <li>If <i>x</i> is <b>NaN</b>, return 1.</li>
+ <li>If <i>y</i> is <b>NaN</b>, return −1.</li>
+ <li>If the argument <i>comparefn</i> is not <b>undefined</b>, then
+ <ol class="block">
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>comparefn</i>) is <b>false</b>, throw a <b>TypeError</b>
+ exception.</li>
+ <li>Return the result of calling the [[Call]] internal method of <i>comparefn</i> passing <b>undefined</b> as
+ <i>thisArgument</i> and with a <a href="#sec-list-and-record-specification-type">List</a> containing the values
+ of <i>x</i> and <i>y</i> as the <i>argumentsList</i>.</li>
+ </ol>
+ </li>
+ <li>If <i>x</i> < <i>y</i>, return −1.</li>
+ <li>If <i>x</i> > <i>y</i>, return 1.</li>
+ <li>Return <b>+0</b>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> Because <b>NaN</b> always compares greater than any other value, <b>NaN</b> property
+ values always sort to the end of the result.</p>
+ </div>
+ </section>
+
+ <section id="sec-%typedarray%.prototype.subarray">
+ <h1><span class="secnum" id="sec-22.2.3.27"><a href="#sec-%typedarray%.prototype.subarray"
+ title="link to this section">22.2.3.27</a></span> %TypedArray%.prototype.subarray( [ begin [ , end ] ] )</h1>
+
+ <p>Returns a new <i>TypedArray</i> object whose element types is the same as this <i>TypedArray</i> and whose ArrayBuffer
+ is the same as the ArrayBuffer of this <i>TypedArray</i>, referencing the elements at <var>begin</var>, inclusive, up to
+ <var>end</var>, exclusive. If either <var>begin</var> or <var>end</var> is negative, it refers to an index from the end of
+ the array, as opposed to from the beginning.</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object, throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>O</i> does not have a [[TypedArrayName]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a>, then throw a <b>TypeError</b> exception.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>O</i> has a [[ViewedArrayBuffer]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>buffer</i> be the value of <i>O</i>’s [[ViewedArrayBuffer]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>buffer</i> is <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>srcLength</i> be the value of <i>O</i>’s [[ArrayLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>beginInt</i> be <a href="#sec-tointeger">ToInteger</a>(<i>begin</i>)</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>beginInt</i>).</li>
+ <li>If <i>beginInt</i> < 0, then let <i>beginInt</i> be <i>srcLength</i> + <i>beginInt</i>.</li>
+ <li>Let <i>beginIndex</i> be min(<i>srcLength</i>, max(0, <i>beginInt</i>)).</li>
+ <li>If <i>end</i> is <b>undefined</b>, then let <i>end</i> be <i>srcLength</i>.</li>
+ <li>Let <i>endInt</i> be <a href="#sec-tointeger">ToInteger</a>(<i>end</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>endInt</i>).</li>
+ <li>If <i>endInt</i> < 0, then let <i>endInt</i> be <i>srcLength</i> + <i>endInt</i>.</li>
+ <li>Let <i>endIndex</i> be max(0,min(<i>srcLength</i>, <i>endInt</i>)).</li>
+ <li>If <i>endIndex</i> < <i>beginIndex</i>, then let <i>endIndex</i> be <i>beginIndex</i>.</li>
+ <li>Let <i>newLength</i> be <i>endIndex</i> - <i>beginIndex</i>.</li>
+ <li>Let <i>constructorName</i> be the string value of <i>O</i>’s [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>elementType</i> be the string value of the Element Type value in <a href="#table-44">Table 44</a> for
+ <i>constructorName</i>.</li>
+ <li>Let <i>elementSize</i> be the Number value of the Element Size value specified in <a href="#table-44">Table 44</a>
+ for <i>constructorName</i>.</li>
+ <li>Let <i>srcByteOffset</i> be the value of <i>O</i>’s [[ByteOffset]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>beginByteOffset</i> be <i>srcByteOffset</i> + <i>beginIndex</i> × <i>elementSize</i>.</li>
+ <li>Let <i>constructor</i> be <a href="#sec-get-o-p">Get</a>(<i>O</i>, <code>"constructor"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>constructor</i>).</li>
+ <li>If <a href="#sec-isconstructor">IsConstructor</a>(<i>constructor</i>) is <b>false</b>, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>Let <i>argumentsList</i> be a <a href="#sec-list-and-record-specification-type">List</a> consisting of
+ <i>buffer</i>, <i>beginByteOffset</i>, and <i>newLength</i>.</li>
+ <li>Return the result of calling the [[Construct]] internal method of <i>constructor</i> with <i>argumentsList</i> as
+ the argument.</li>
+ </ol>
+ </section>
+
+ <section id="sec-%typedarray%.prototype.tolocalestring">
+ <h1><span class="secnum" id="sec-22.2.3.28"><a href="#sec-%typedarray%.prototype.tolocalestring"
+ title="link to this section">22.2.3.28</a></span> %TypedArray%.prototype.toLocaleString ( )</h1>
+
+ <p>The initial value of the %TypedArray%.prototype.toLocaleString data property is the same built-in function object as
+ the <a href="#sec-array.prototype.tolocalestring">Array.prototype.toLocaleString</a> method defined in <a
+ href="#sec-array.prototype.tolocalestring">22.1.3.26</a>.</p>
+ </section>
+
+ <section id="sec-%typedarray%.prototype.tostring">
+ <h1><span class="secnum" id="sec-22.2.3.29"><a href="#sec-%typedarray%.prototype.tostring"
+ title="link to this section">22.2.3.29</a></span> %TypedArray%.prototype.toString ( )</h1>
+
+ <p>The initial value of the %TypedArray%.prototype.toString data property is the same built-in function object as the <a
+ href="#sec-array.prototype.tostring">Array.prototype.toString</a> method defined in <a
+ href="#sec-array.prototype.tostring">22.1.3.27</a>.</p>
+ </section>
+
+ <section id="sec-%typedarray%.prototype.values">
+ <h1><span class="secnum" id="sec-22.2.3.30"><a href="#sec-%typedarray%.prototype.values"
+ title="link to this section">22.2.3.30</a></span> %TypedArray%.prototype.values ( )</h1>
+
+ <p>The initial value of the %TypedArray%.<code>prototype.values</code> data property is the same built-in function object
+ as the <code><a href="#sec-array.prototype.values">Array.prototype.values</a></code> method defined in <a
+ href="#sec-array.prototype.values">22.1.3.29</a>.</p>
+ </section>
+
+ <section id="sec-%typedarray%.prototype-@@iterator">
+ <h1><span class="secnum" id="sec-22.2.3.31"><a href="#sec-%typedarray%.prototype-@@iterator"
+ title="link to this section">22.2.3.31</a></span> %TypedArray%.prototype [ @@iterator ] ( )</h1>
+
+ <p>The initial value of the @@iterator property is the same function object as the initial value of the
+ %TypedArray%<b>.prototype.values</b> property.</p>
+ </section>
+
+ <section id="sec-get-%typedarray%.prototype-@@tostringtag">
+ <h1><span class="secnum" id="sec-22.2.3.32"><a href="#sec-get-%typedarray%.prototype-@@tostringtag"
+ title="link to this section">22.2.3.32</a></span> get %TypedArray%.prototype [ @@toStringTag ]</h1>
+
+ <p>%TypedArray%.<code>prototype[@@toStringTag]</code> is an accessor property whose set accessor function is <span
+ class="value">undefined</span>. Its get accessor function performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object, throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>O</i> does not have a [[TypedArrayName]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a>, throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>name</i> be the value of <i>O</i>’s [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If the value of <i>O</i>’s [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is <b>undefined</b>, throw a
+ <b>TypeError</b> exception.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>name</i> is a String value.</li>
+ <li>Return <i>name</i>.</li>
+ </ol>
+
+ <p>This property has the attributes { [[Enumerable]]: <span class="value">false</span>, [[Configurable]]: <span
+ class="value">true</span> }.</p>
+
+ <p>The initial value of the <code>name</code> property of this function is <code>"get [Symbol.toStringTag]"</code>.</p>
+ </section>
+ </section>
+
+ <section id="sec-typedarray-constructors">
+ <div class="front">
+ <h1><span class="secnum" id="sec-22.2.4"><a href="#sec-typedarray-constructors"
+ title="link to this section">22.2.4</a></span> The <i>TypedArray</i> Constructors</h1>
+
+ <p>Each of these <i>TypedArray</i> constructor objects has the structure described below, differing only in the name used
+ as the constructor name instead of <i>TypedArray</i>, in <a href="#table-44">Table 44</a>.</p>
+
+ <p>When a <i>TypedArray</i> constructor is called as a function rather than as a constructor, it initializes a new
+ <i>TypedArray</i> object. The <b>this</b> value passed in the call must be an Object with a [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> and a [[ViewedArrayBuffer]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> whose value is <span
+ class="value">undefined</span>. The constructor function initializes the <b>this</b> value using the argument values.</p>
+
+ <p>The <i>TypedArray</i> constructors are designed to be subclassable. They may be used as the value of an
+ <code>extends</code> clause of a class declaration. Subclass constructors that intended to inherit the specified
+ <i>TypedArray</i> behaviour must include a <code>super</code> call to the <i>TypedArray</i> constructor to initialize
+ subclass instances.</p>
+ </div>
+
+ <section id="sec-typedarray">
+ <h1><span class="secnum" id="sec-22.2.4.1"><a href="#sec-typedarray" title="link to this section">22.2.4.1</a></span>
+ <i>TypedArray</i>( ... argumentsList)</h1>
+
+ <p>A <i>TypedArray</i> constructor with a list of arguments <i>argumentsList</i> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>O</i> does not have a [[TypedArrayName]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a>, then throw a <b>TypeError</b> exception.</li>
+ <li>If the value of <i>O’s</i> [[TypedArrayName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is not <b>undefined</b>, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>Set <i>O’s</i> [[TypedArrayName]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>
+ to the String value from the constructor name column in the row of <a href="#table-44">Table 44</a> corresponding to
+ this constructor.</li>
+ <li>Let <i>F</i> be the <i>TypedArray</i> function object that was called.</li>
+ <li>Let <i>realmF</i> be <i>F’s</i> [[Realm]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a>.</li>
+ <li>Let <i>super</i> be <i>realmF</i>.[[intrinsics]].[[<span style="font-family: sans-serif">%TypedArray%]]</span>.</li>
+ <li>Let <i>argumentsList</i> be the <i>argumentsList</i> argument of the [[Call]] internal method that invoked
+ <i>F</i>.</li>
+ <li>Return the result of calling the [[Call]] internal method of <i>super</i> with <i>O</i> and <i>argumentsList</i> as
+ arguments.</li>
+ </ol>
+ </section>
+
+ <section id="sec-new-typedarray-argumentslist">
+ <h1><span class="secnum" id="sec-22.2.4.2"><a href="#sec-new-typedarray-argumentslist"
+ title="link to this section">22.2.4.2</a></span> new <i>TypedArray</i>( ... argumentsList)</h1>
+
+ <p>A <i>TypedArray</i> constructor called as part of a new expression performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be the <i>TypedArray</i> function object on which the <code>new</code> operator was applied.</li>
+ <li>Let <i>argumentsList</i> be the <i>argumentsList</i> argument of the [[Construct]] internal method that was invoked
+ by the <code>new</code> operator.</li>
+ <li>Return <a href="#sec-construct-f-argumentslist">Construct</a>(<i>F</i>, <i>argumentsList</i>).</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-typedarray-constructors">
+ <div class="front">
+ <h1><span class="secnum" id="sec-22.2.5"><a href="#sec-properties-of-the-typedarray-constructors"
+ title="link to this section">22.2.5</a></span> Properties of the <i>TypedArray</i> Constructors</h1>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of each
+ <i>TypedArray</i> constructor is the %TypedArray% intrinsic object (<a
+ href="#sec-%typedarray%-intrinsic-object">22.2.1</a>).</p>
+
+ <p>Each <i>TypedArray</i> constructor has a <code>name</code> property whose value is the String value of the constructor
+ name specifried for it in <a href="#table-44">Table 44</a>.</p>
+
+ <p>Besides a <code>length</code> property (whose value is 3), each <i>TypedArray</i> constructor has the following
+ properties:</p>
+ </div>
+
+ <section id="sec-typedarray.bytes_per_element">
+ <h1><span class="secnum" id="sec-22.2.5.1"><a href="#sec-typedarray.bytes_per_element"
+ title="link to this section">22.2.5.1</a></span> <i>TypedArray</i>.BYTES_PER_ELEMENT</h1>
+
+ <p>The value of <i>TypedArray</i>.BYTES_PER_ELEMENT is the Number value of the Element Size value specified in <a
+ href="#table-44">Table 44</a> for <i>TypedArray</i>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-typedarray.prototype">
+ <h1><span class="secnum" id="sec-22.2.5.2"><a href="#sec-typedarray.prototype"
+ title="link to this section">22.2.5.2</a></span> <i>TypedArray</i>.prototype</h1>
+
+ <p>The initial value of <i>TypedArray</i>.prototype is the corresponding <i>TypedArray</i> prototype object (<a
+ href="#sec-properties-of-typedarray-prototype-objects">22.2.6</a>).</p>
+
+ <p>This property has the attributes { [[Writable]]: <span class="value">false</span>, [[Enumerable]]: <span
+ class="value">false</span>, [[Configurable]]: <span class="value">false</span> }.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-typedarray-prototype-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-22.2.6"><a href="#sec-properties-of-typedarray-prototype-objects"
+ title="link to this section">22.2.6</a></span> Properties of <i>TypedArray</i> Prototype Objects</h1>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of a
+ <i>TypedArray</i> prototype object is the standard built-in %TypedArrayPrototype% object (<a
+ href="#sec-properties-of-the-%typedarrayprototype%-object">22.2.3</a>). A <i>TypedArray</i> prototype object is an
+ ordinary object. It does not have a [[ViewedArrayBuffer]] or or any other of the internal slots that are specific to
+ <i>TypedArray</i> instance objects.</p>
+ </div>
+
+ <section id="sec-typedarray.prototype.bytes_per_element">
+ <h1><span class="secnum" id="sec-22.2.6.1"><a href="#sec-typedarray.prototype.bytes_per_element"
+ title="link to this section">22.2.6.1</a></span> <i>TypedArray</i>.prototype.BYTES_PER_ELEMENT</h1>
+
+ <p>The value of <i>TypedArray</i>.prototype.BYTES_PER_ELEMENT is the Number value of the Element Size value specified in
+ <a href="#table-44">Table 44</a> for <i>TypedArray</i>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-typedarray.prototype.constructor">
+ <h1><span class="secnum" id="sec-22.2.6.2"><a href="#sec-typedarray.prototype.constructor"
+ title="link to this section">22.2.6.2</a></span> <i>TypedArray</i>.prototype.constructor</h1>
+
+ <p>The initial value of a <i>TypedArray</i>.prototype.constructor is the corresponding standard built-in <i>TypedArray</i>
+ constructor.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-typedarray-instances">
+ <h1><span class="secnum" id="sec-22.2.7"><a href="#sec-properties-of-typedarray-instances"
+ title="link to this section">22.2.7</a></span> Properties of <i>TypedArray</i> Instances</h1>
+
+ <p><i>TypedArray</i> instances are Integer Indexed exotic objects. Each <i>TypedArray</i> instances inherits properties from
+ the corresponding <i>TypedArray</i> prototype object. Each <i>TypedArray</i> instances have the following internal slots:
+ [[TypedArrayName]], [[ViewedArrayBuffer]], [[ByteLength]], [[ByteOffset]], and [[ArrayLength]].</p>
+ </section>
+ </section>
+</section>
+
+<section id="sec-keyed-collection">
+ <div class="front">
+ <h1><span class="secnum" id="sec-23"><a href="#sec-keyed-collection" title="link to this section">23</a></span> Keyed
+ Collection</h1>
+ </div>
+
+ <section id="sec-map-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-23.1"><a href="#sec-map-objects" title="link to this section">23.1</a></span> Map
+ Objects</h1>
+
+ <p>Map objects are collections of key/value pairs where both the keys and values may be arbitrary <a
+ href="#sec-ecmascript-language-types">ECMAScript language values</a>. A distinct key value may only occur in one key/value
+ pair within the Map’s collection. Distinct key values are discriminated using the <a
+ href="#sec-samevaluezero">SameValueZero</a> comparision algorithm.</p>
+
+ <p>Map object must be implemented using either hash tables or other mechanisms that, on average, provide access times that
+ are sublinear on the number of elements in the collection. The data structures used in this Map objects specification is
+ only intended to describe the required observable semantics of Map objects. It is not intended to be a viable
+ implementation model.</p>
+ </div>
+
+ <section id="sec-map-constructor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-23.1.1"><a href="#sec-map-constructor" title="link to this section">23.1.1</a></span> The
+ Map Constructor</h1>
+
+ <p>The Map constructor is the %Map% intrinsic object and the initial value of the <code>Map</code> property of the global
+ object. When <code>Map</code> is called as a function rather than as a constructor, it initializes its <b>this</b> value
+ with the internal state necessary to support the <code>Map.prototype</code> built-in methods.</p>
+
+ <p>The <code>Map</code> constructor is designed to be subclassable. It may be used as the value in an <code>extends</code>
+ clause of a class definition. Subclass constructors that intend to inherit the specified <code>Map</code> behaviour must
+ include a <code>super</code> call to <code>Map</code>.</p>
+ </div>
+
+ <section id="sec-map-iterable">
+ <h1><span class="secnum" id="sec-23.1.1.1"><a href="#sec-map-iterable" title="link to this section">23.1.1.1</a></span>
+ Map ( [ iterable ] )</h1>
+
+ <p>When the <code>Map</code> function is called with optional argument the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>map</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>map</i>) is not Object then, throw a
+ <b>TypeError</b> exception.</li>
+ <li>If <i>map</i> does not have a [[MapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a>, then throw a <b>TypeError</b> exception.</li>
+ <li>If <i>map’s</i> [[MapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is not
+ <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>If <i>iterable</i> is not present, let <i>iterable</i> be <b>undefined</b>.</li>
+ <li>If <i>iterable</i> is either <b>undefined</b> or <b>null</b>, then let <i>iter</i> be <b>undefined</b>.</li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>iter</i> be the result of <a href="#sec-getiterator">GetIterator</a>(<i>iterable</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>iter</i>).</li>
+ <li>Let <i>adder</i> be the result of <a href="#sec-get-o-p">Get</a>(<i>map</i>, <code>"set"</code>)<b>.</b></li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>adder</i>).</li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>adder</i>) is <b>false</b>, throw a <b>TypeError</b>
+ Exception.</li>
+ </ol>
+ </li>
+ <li>If the value of <i>map’s</i> [[MapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> is not <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>map</i> has not been reentrantly initialized.</li>
+ <li>Set <i>map’s</i> [[MapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to a
+ new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>If <i>iter</i> is <b>undefined</b>, then return <i>map</i>.</li>
+ <li>Repeat
+ <ol class="block">
+ <li>Let <i>next</i> be the result of <a href="#sec-iteratorstep">IteratorStep</a>(<i>iter</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>next</i>).</li>
+ <li>If <i>next</i> is <b>false</b>, then return <a
+ href="#sec-normalcompletion">NormalCompletion</a>(<i>map</i>).</li>
+ <li>Let <i>nextItem</i> be <a href="#sec-iteratorvalue">IteratorValue</a>(<i>next</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>nextItem</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>nextItem</i>) is not Object, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>Let <i>k</i> be the result of <a href="#sec-get-o-p">Get</a>(<i>nextItem</i>, <code>"0"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>k</i>).</li>
+ <li>Let <i>v</i> be the result of <a href="#sec-get-o-p">Get</a>(<i>nextItem</i>, <code>"1"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>v</i>).</li>
+ <li>Let <i>status</i> be the result of calling the [[Call]] internal method of <i>adder</i> with <i>map</i> as
+ <i>thisArgument</i> and a <a href="#sec-list-and-record-specification-type">List</a> whose elements are <i>k</i>
+ and <i>v</i> as <i>argumentsList</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ </ol>
+ </li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> If the parameter <i>iterable</i> is present, it is expected to be an object that
+ implements an @@iterator method that returns an iterator object that produces a two element array-like object whose
+ first element is a value that will be used as an Map key and whose second element is the value to associate with that
+ key.</p>
+ </div>
+ </section>
+
+ <section id="sec-new-map-argumentslist">
+ <h1><span class="secnum" id="sec-23.1.1.2"><a href="#sec-new-map-argumentslist"
+ title="link to this section">23.1.1.2</a></span> new Map ( ... argumentsList )</h1>
+
+ <p>When <code>Map</code> is called as part of a <code>new</code> expression it is a constructor: it initializes a newly
+ created object.</p>
+
+ <p><code>Map</code> called as part of a new expression with argument list <var>argumentsList</var> performs the following
+ steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be the Map function object on which the <code>new</code> operator was applied.</li>
+ <li>Let <i>argumentsList</i> be the <i>argumentsList</i> argument of the [[Construct]] internal method that was invoked
+ by the <code>new</code> operator.</li>
+ <li>Return the result of <a href="#sec-construct-f-argumentslist">Construct</a>(<i>F</i>, <i>argumentsList</i>).</li>
+ </ol>
+
+ <p>If Map is implemented as an <a href="#sec-ecmascript-function-objects">ECMAScript function object</a>, its
+ [[Construct]] internal method will perform the above steps.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-map-constructor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-23.1.2"><a href="#sec-properties-of-the-map-constructor"
+ title="link to this section">23.1.2</a></span> Properties of the Map Constructor</h1>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the Map
+ constructor is the Function prototype object (<a href="#sec-properties-of-the-function-prototype-object">19.2.3</a>).</p>
+
+ <p>Besides the <code>length</code> property (whose value is <b>1</b>), the Map constructor has the following
+ properties:</p>
+ </div>
+
+ <section id="sec-map.prototype">
+ <h1><span class="secnum" id="sec-23.1.2.1"><a href="#sec-map.prototype" title="link to this section">23.1.2.1</a></span>
+ Map.prototype</h1>
+
+ <p>The initial value of <code>Map.prototype</code> is the Map prototype object (<a
+ href="#sec-properties-of-the-map-prototype-object">23.1.3</a>).</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-map-@@create">
+ <h1><span class="secnum" id="sec-23.1.2.2"><a href="#sec-map-@@create" title="link to this section">23.1.2.2</a></span>
+ Map[ @@create ] ( )</h1>
+
+ <p>The @@create method of a Map function object <var>F</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be the <b>this</b> value.</li>
+ <li>Let <i>obj</i> be the result of calling <a
+ href="#sec-ordinarycreatefromconstructor">OrdinaryCreateFromConstructor</a>(<i>F</i>, <code>"%MapPrototype%"</code>,
+ ([[MapData]]) ).</li>
+ <li>Return <i>obj</i>.</li>
+ </ol>
+
+ <p>The value of the <code>name</code> property of this function is <code>"[Symbol.create]"</code>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>true</b> }.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-map-prototype-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-23.1.3"><a href="#sec-properties-of-the-map-prototype-object"
+ title="link to this section">23.1.3</a></span> Properties of the Map Prototype Object</h1>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the Map
+ prototype object is the standard built-in Object prototype object (<a
+ href="#sec-properties-of-the-object-prototype-object">19.1.3</a>). The Map prototype object is an ordinary object. It does
+ not have a [[MapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</p>
+ </div>
+
+ <section id="sec-map.prototype.clear">
+ <h1><span class="secnum" id="sec-23.1.3.1"><a href="#sec-map.prototype.clear"
+ title="link to this section">23.1.3.1</a></span> Map.prototype.clear ( )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>M</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>M)</i> is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>M</i> does not have a [[MapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>
+ throw a <b>TypeError</b> exception.</li>
+ <li>If <i>M’s</i> [[MapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is
+ <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>entries</i> be the <a href="#sec-list-and-record-specification-type">List</a> that is the value of
+ <i>M</i>’s [[MapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Repeat for each Record {[[key]], [[value]]} <i>p</i> that is an element of <i>entries,</i>
+ <ol class="block">
+ <li>Set <i>p</i>.[[key]] to <span style="font-family: sans-serif">empty</span><i>.</i></li>
+ <li>Set <i>p</i>.[[value]] to <span style="font-family: sans-serif">empty</span><i>.</i></li>
+ </ol>
+ </li>
+ <li>Return <b>undefined</b>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The existing [[MapData]] <a href="#sec-list-and-record-specification-type">List</a> is
+ preserved because there may be existing MapIterator objects that are <a href="#sec-execution-contexts">suspended</a>
+ midway through iterating over that <a href="#sec-list-and-record-specification-type">List</a>.</p>
+ </div>
+ </section>
+
+ <section id="sec-map.prototype.constructor">
+ <h1><span class="secnum" id="sec-23.1.3.2"><a href="#sec-map.prototype.constructor"
+ title="link to this section">23.1.3.2</a></span> Map.prototype.constructor</h1>
+
+ <p>The initial value of <code>Map.prototype.constructor</code> is the built-in <code>Map</code> constructor.</p>
+ </section>
+
+ <section id="sec-map.prototype.delete">
+ <h1><span class="secnum" id="sec-23.1.3.3"><a href="#sec-map.prototype.delete"
+ title="link to this section">23.1.3.3</a></span> Map.prototype.delete ( key )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>M</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>M)</i> is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>M</i> does not have a [[MapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>
+ throw a <b>TypeError</b> exception.</li>
+ <li>If <i>M’s</i> [[MapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is
+ <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>entries</i> be the <a href="#sec-list-and-record-specification-type">List</a> that is the value of
+ <i>M</i>’s [[MapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Repeat for each Record {[[key]], [[value]]} <i>p</i> that is an element of <i>entries,</i>
+ <ol class="block">
+ <li>If <i>p</i>.[[key]] is not <span style="font-family: sans-serif">empty</span> and <a
+ href="#sec-samevaluezero">SameValueZero</a>(<i>p</i>.[[key]], <i>key</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>Set <i>p</i>.[[key]] to <span style="font-family: sans-serif">empty</span><i>.</i></li>
+ <li>Set <i>p</i>.[[value]] to <span style="font-family: sans-serif">empty</span><i>.</i></li>
+ <li>Return <b>true</b>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The value <b>empty</b> is used as a specification device to indicate that an entry has
+ been deleted. Actual implementations may take other actions such as physically removing the entry from internal data
+ structures.</p>
+ </div>
+ </section>
+
+ <section id="sec-map.prototype.entries">
+ <h1><span class="secnum" id="sec-23.1.3.4"><a href="#sec-map.prototype.entries"
+ title="link to this section">23.1.3.4</a></span> Map.prototype.entries ( )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>M</i> be the <b>this</b> value.</li>
+ <li>Return the result of calling the <a href="#sec-createmapiterator">CreateMapIterator</a> abstract operation with
+ arguments <i>M</i> and <code>"key+value"</code>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-map.prototype.foreach">
+ <h1><span class="secnum" id="sec-23.1.3.5"><a href="#sec-map.prototype.foreach"
+ title="link to this section">23.1.3.5</a></span> Map.prototype.forEach ( callbackfn [ , thisArg ] )</h1>
+
+ <p class="Note"><span style="font-family: sans-serif">NOTE</span>	<i>callbackfn</i> should be a function that accepts
+ three arguments. <code>forEach</code> calls <i>callbackfn</i> once for each key/value pair present in the map object, in
+ key insertion order. <i>callbackfn</i> is called only for keys of the map which actually exist; it is not called for keys
+ that have been deleted from the map.</p>
+
+ <p class="Note">If a <i>thisArg</i> parameter is provided, it will be used as the <b>this</b> value for each invocation of
+ <i>callbackfn</i>. If it is not provided, <b>undefined</b> is used instead.</p>
+
+ <p class="Note"><i>callbackfn</i> is called with three arguments: the value of the item, the key of the item, and the Map
+ object being traversed.</p>
+
+ <p class="Note"><code>forEach</code> does not directly mutate the object on which it is called but the object may be
+ mutated by the calls to <i>callbackfn</i>.</p>
+
+ <p>When the <code>forEach</code> method is called with one or two arguments, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>M</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>M)</i> is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>M</i> does not have a [[MapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>
+ throw a <b>TypeError</b> exception.</li>
+ <li>If <i>M’s</i> [[MapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is
+ <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>callbackfn</i>) is <b>false</b>, throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>thisArg</i> was supplied, let <i>T</i> be <i>thisArg</i>; else let <i>T</i> be <b>undefined</b>.</li>
+ <li>Let <i>entries</i> be the <a href="#sec-list-and-record-specification-type">List</a> that is the value of
+ <i>M</i>’s [[MapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Repeat for each Record {[[key]], [[value]]} <i>e</i> that is an element of <i>entries,</i> in original key insertion
+ order
+ <ol class="block">
+ <li>If <i>e</i>.[[key]] is not <span style="font-family: sans-serif">empty</span>, then
+ <ol class="block">
+ <li>Let <i>funcResult</i> be the result of calling the [[Call]] internal method of <i>callbackfn</i> with
+ <i>T</i> as <i>thisArgument</i> and a <a href="#sec-list-and-record-specification-type">List</a> containing
+ <i>e</i>.[[value]], <i>e</i>.[[key]], and <i>M</i> as <i>argumentsList</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>funcResult</i>).</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Return <b>undefined</b>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>forEach</code> method is <b>1</b>.</p>
+ </section>
+
+ <section id="sec-map.prototype.get">
+ <h1><span class="secnum" id="sec-23.1.3.6"><a href="#sec-map.prototype.get"
+ title="link to this section">23.1.3.6</a></span> Map.prototype.get ( key )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>M</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>M)</i> is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>M</i> does not have a [[MapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>
+ throw a <b>TypeError</b> exception.</li>
+ <li>If <i>M’s</i> [[MapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is
+ <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>entries</i> be the <a href="#sec-list-and-record-specification-type">List</a> that is the value of
+ <i>M</i>’s [[MapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Repeat for each Record {[[key]], [[value]]} <i>p</i> that is an element of <i>entries,</i>
+ <ol class="block">
+ <li>If <i>p</i>.[[key]] is not <span style="font-family: sans-serif">empty</span> and <a
+ href="#sec-samevaluezero">SameValueZero</a>(<i>p</i>.[[key]], <i>key</i>) is <b>true</b>, then return
+ <i>p</i>.[[value]].</li>
+ </ol>
+ </li>
+ <li>Return <b>undefined</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-map.prototype.has">
+ <h1><span class="secnum" id="sec-23.1.3.7"><a href="#sec-map.prototype.has"
+ title="link to this section">23.1.3.7</a></span> Map.prototype.has ( key )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>M</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>M)</i> is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>M</i> does not have a [[MapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>
+ throw a <b>TypeError</b> exception.</li>
+ <li>If <i>M’s</i> [[MapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is
+ <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>entries</i> be the <a href="#sec-list-and-record-specification-type">List</a> that is the value of
+ <i>M</i>’s [[MapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Repeat for each Record {[[key]], [[value]]} <i>p</i> that is an element of <i>entries,</i>
+ <ol class="block">
+ <li>If <i>p</i>.[[key]] is not <span style="font-family: sans-serif">empty</span> and <a
+ href="#sec-samevaluezero">SameValueZero</a>(<i>p</i>.[[key]], <i>key</i>) is <b>true</b>, then return
+ <b>true</b><i>.</i></li>
+ </ol>
+ </li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-map.prototype.keys">
+ <h1><span class="secnum" id="sec-23.1.3.8"><a href="#sec-map.prototype.keys"
+ title="link to this section">23.1.3.8</a></span> Map.prototype.keys ( )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>M</i> be the <b>this</b> value.</li>
+ <li>Return the result of calling the <a href="#sec-createmapiterator">CreateMapIterator</a> abstract operation with
+ arguments <i>M</i> and <code>"key"</code>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-map.prototype.set">
+ <h1><span class="secnum" id="sec-23.1.3.9"><a href="#sec-map.prototype.set"
+ title="link to this section">23.1.3.9</a></span> Map.prototype.set ( key , value )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>M</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>M)</i> is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>M</i> does not have a [[MapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>
+ throw a <b>TypeError</b> exception.</li>
+ <li>If <i>M’s</i> [[MapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is
+ <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>entries</i> be the <a href="#sec-list-and-record-specification-type">List</a> that is the value of
+ <i>M</i>’s [[MapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Repeat for each Record {[[key]], [[value]]} <i>p</i> that is an element of <i>entries,</i>
+ <ol class="block">
+ <li>If <i>p</i>.[[key]] is not <span style="font-family: sans-serif">empty</span> and <a
+ href="#sec-samevaluezero">SameValueZero</a>(<i>p</i>.[[key]], <i>key</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>Set <i>p</i>.[[value]] to <i>value.</i></li>
+ <li>Return <i>M</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>If <i>key</i> is −0, then let <i>key</i> be +0.</li>
+ <li>Let <i>p</i> be the Record {[[key]]: <i>key</i>, [[value]]: <i>value</i>}.</li>
+ <li>Append <i>p</i> as the last element of <i>entries</i>.</li>
+ <li>Return <i>M</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-get-map.prototype.size">
+ <h1><span class="secnum" id="sec-23.1.3.10"><a href="#sec-get-map.prototype.size"
+ title="link to this section">23.1.3.10</a></span> get Map.prototype.size</h1>
+
+ <p>Map.prototype.size is an accessor property whose set accessor function is <span class="value">undefined</span>. Its get
+ accessor function performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>M</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>M)</i> is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>M</i> does not have a [[MapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>
+ throw a <b>TypeError</b> exception.</li>
+ <li>If <i>M’s</i> [[MapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is
+ <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>entries</i> be the <a href="#sec-list-and-record-specification-type">List</a> that is the value of
+ <i>M</i>’s [[MapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>count</i> be 0.</li>
+ <li>For each Record {[[key]], [[value]]} <i>p</i> that is an element of <i>entries</i>
+ <ol class="block">
+ <li>If <i>p</i>.[[key]] is not <span style="font-family: sans-serif">empty</span> then
+ <ol class="block">
+ <li>Set <i>count</i> to <i>count</i>+1.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Return <i>count</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-map.prototype.values">
+ <h1><span class="secnum" id="sec-23.1.3.11"><a href="#sec-map.prototype.values"
+ title="link to this section">23.1.3.11</a></span> Map.prototype.values ( )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>M</i> be the <b>this</b> value.</li>
+ <li>Return the result of calling the <a href="#sec-createmapiterator">CreateMapIterator</a> abstract operation with
+ arguments <i>M</i> and <code>"value"</code>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-map.prototype-@@iterator">
+ <h1><span class="secnum" id="sec-23.1.3.12"><a href="#sec-map.prototype-@@iterator"
+ title="link to this section">23.1.3.12</a></span> Map.prototype [ @@iterator ]( )</h1>
+
+ <p>The initial value of the @@iterator property is the same function object as the initial value of the <b>entries</b>
+ property.</p>
+ </section>
+
+ <section id="sec-map.prototype-@@tostringtag">
+ <h1><span class="secnum" id="sec-23.1.3.13"><a href="#sec-map.prototype-@@tostringtag"
+ title="link to this section">23.1.3.13</a></span> Map.prototype [ @@toStringTag ]</h1>
+
+ <p>The initial value of the @@toStringTag property is the string value <b>"<code>Map</code>"</b>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <span class="value">false</span>, [[Enumerable]]: <span
+ class="value">false</span>, [[Configurable]]: <span class="value">true</span> }.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-map-instances">
+ <h1><span class="secnum" id="sec-23.1.4"><a href="#sec-properties-of-map-instances"
+ title="link to this section">23.1.4</a></span> Properties of Map Instances</h1>
+
+ <p>Map instances are ordinary objects that inherit properties from the Map prototype. Map instances also have a [[MapData]]
+ <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</p>
+ </section>
+
+ <section id="sec-map-iterator-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-23.1.5"><a href="#sec-map-iterator-objects"
+ title="link to this section">23.1.5</a></span> Map Iterator Objects</h1>
+
+ <p>A Map Iterator is an object, that represents a specific iteration over some specific Map instance object. There is not
+ a named constructor for Map Iterator objects. Instead, map iterator objects are created by calling certain methods of Map
+ instance objects.</p>
+ </div>
+
+ <section id="sec-createmapiterator">
+ <h1><span class="secnum" id="sec-23.1.5.1"><a href="#sec-createmapiterator"
+ title="link to this section">23.1.5.1</a></span> CreateMapIterator Abstract Operation</h1>
+
+ <p>Several methods of Map objects return Iterator objects. The abstract operation CreateMapIterator with arguments
+ <var>map</var> and <var>kind</var> is used to create such iterator objects. It performs the following steps:</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>map</i>) is not Object, throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>map</i> does not have a [[MapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> throw a <b>TypeError</b> exception.</li>
+ <li>If the value of <i>map’s</i> [[MapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> is <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>iterator</i> be the result of <a href="#sec-objectcreate">ObjectCreate</a>(%MapIteratorPrototype%, ([[Map]],
+ [[MapNextIndex]], [[MapIterationKind]])).</li>
+ <li>Set <i>iterator’s</i> [[Map]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to
+ <i>map</i>.</li>
+ <li>Set <i>iterator’s</i> [[MapNextIndex]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> to 0.</li>
+ <li>Set <i>iterator’s</i> [[MapIterationKind]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> to <i>kind</i>.</li>
+ <li>Return <i>iterator</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-%mapiteratorprototype%-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-23.1.5.2"><a href="#sec-%mapiteratorprototype%-object"
+ title="link to this section">23.1.5.2</a></span> The %MapIteratorPrototype% Object</h1>
+
+ <p>All Map Iterator Objects inherit properties from the %MapIteratorPrototype% intrinsic object. The
+ %MapIteratorPrototype% intrinsic object is an ordinary object and its [[Prototype]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is the %ObjectPrototype% intrinsic object. In
+ addition, %MapIteratorPrototype% has the following properties:</p>
+ </div>
+
+ <section id="sec-%mapiteratorprototype%.next">
+ <h1><span class="secnum" id="sec-23.1.5.2.1"><a href="#sec-%mapiteratorprototype%.next"
+ title="link to this section">23.1.5.2.1</a></span> %MapIteratorPrototype%.next ( )</h1>
+ <ol class="proc">
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object, throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>O</i> does not have all of the internal slots of a Map Iterator Instance (<a
+ href="#sec-properties-of-map-iterator-instances">23.1.5.3</a>), throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>m</i> be the value of the [[Map]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> of <i>O</i>.</li>
+ <li>Let <i>index</i> be the value of the [[MapNextIndex]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>Let <i>itemKind</i> be the value of the [[MapIterationKind]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>If <i>m</i> is <b>undefined</b>, then return <a
+ href="#sec-createiterresultobject">CreateIterResultObject</a>(<b>undefined</b>, <b>true</b>)</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>m</i> has a [[MapData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> and <i>m</i> has been initialized so the
+ value of [[MapData]] is not <b>undefined</b>.</li>
+ <li>Let <i>entries</i> be the <a href="#sec-list-and-record-specification-type">List</a> that is the value of the
+ [[MapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>m</i>.</li>
+ <li>Repeat while <i>index</i> is less than the total number of elements of <i>entries</i>. The number of elements must
+ be redetermined each time this method is evaluated.
+ <ol class="block">
+ <li>Let <i>e</i> be the Record {[[key]], [[value]]} that is the value of <i>entries</i>[<i>index</i>].</li>
+ <li>Set <i>index</i> to <i>index</i>+1;</li>
+ <li>Set the [[MapNextIndex]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of
+ <i>O</i> to <i>index</i>.</li>
+ <li>If <i>e</i>.[[key]] is not <span style="font-family: sans-serif">empty</span>, then
+ <ol class="block">
+ <li>If <i>itemKind</i> is <b>"<code>key</code>"</b> then, let <i>result</i> be <i>e</i>.[[key]].</li>
+ <li>Else if <i>itemKind</i> is <b>"<code>value</code>"</b> then, let <i>result</i> be <i>e</i>.[[value]].</li>
+ <li>Else,
+ <ol class="block">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>itemKind</i> is <code>"key+value"</code>.</li>
+ <li>Let <i>result</i> be the result of performing <a href="#sec-arraycreate">ArrayCreate</a>(2).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>result</i> is a new, well-formed Array object so
+ the following operations will never fail.</li>
+ <li>Call <a href="#sec-createdataproperty">CreateDataProperty</a>(<i>result</i>, <b>"<code>0</code>"</b>,
+ <i>e</i>.[[key]]) .</li>
+ <li>Call <a href="#sec-createdataproperty">CreateDataProperty</a>(<i>result</i>, <b>"<code>1</code>"</b>,
+ <i>e</i>.[[value]]).</li>
+ </ol>
+ </li>
+ <li>Return <a href="#sec-createiterresultobject">CreateIterResultObject</a>(<i>result</i>, <b>false</b>).</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Set the [[Map]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i> to
+ <b>undefined</b>.</li>
+ <li>Return <a href="#sec-createiterresultobject">CreateIterResultObject</a>(<b>undefined</b>, <b>true</b>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-%mapiteratorprototype%-@@iterator">
+ <h1><span class="secnum" id="sec-23.1.5.2.2"><a href="#sec-%mapiteratorprototype%-@@iterator"
+ title="link to this section">23.1.5.2.2</a></span> %MapIteratorPrototype% [ @@iterator ] ( )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Return the <b>this</b> value.</li>
+ </ol>
+
+ <p>The value of the <code>name</code> property of this function is <code>"[Symbol.iterator]"</code>.</p>
+ </section>
+
+ <section id="sec-%mapiteratorprototype%-@@tostringtag">
+ <h1><span class="secnum" id="sec-23.1.5.2.3"><a href="#sec-%mapiteratorprototype%-@@tostringtag"
+ title="link to this section">23.1.5.2.3</a></span> %MapIteratorPrototype% [ @@toStringTag ]</h1>
+
+ <p>The initial value of the @@toStringTag property is the string value <b>"<code>Map Iterator</code>"</b>.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-map-iterator-instances">
+ <h1><span class="secnum" id="sec-23.1.5.3"><a href="#sec-properties-of-map-iterator-instances"
+ title="link to this section">23.1.5.3</a></span> Properties of Map Iterator Instances</h1>
+
+ <p>Map Iterator instances are ordinary objects that inherit properties from the %MapIteratorPrototype% intrinsic object.
+ Map Iterator instances are initially created with the internal slots described in <a href="#table-45">Table 45</a>.</p>
+
+ <figure>
+ <figcaption><span id="table-45">Table 45</span> — Internal Slots of Map Iterator Instances</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-top: 2px solid #000000">Internal Slot</th>
+ <th style="border-bottom: 1px solid #000000; border-left: 0px solid black; border-right: 1px solid #000000; border-top: 2px solid #000000">Description</th>
+ </tr>
+ <tr>
+ <td>[[Map]]</td>
+ <td>The Map object that is being iterated.</td>
+ </tr>
+ <tr>
+ <td>[[MapNextIndex]]</td>
+ <td>The integer index of the next Map data element to be examined by this iterator.</td>
+ </tr>
+ <tr>
+ <td>[[MapIterationKind]]</td>
+ <td>A string value that identifies what is to be returned for each element of the iteration. The possible values are: <b>"<code>key</code>"</b>, <b>"<code>value</code>"</b>, <b>"<code>key+value</code>"</b>.</td>
+ </tr>
+ </table>
+ </figure>
+ </section>
+ </section>
+ </section>
+
+ <section id="sec-set-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-23.2"><a href="#sec-set-objects" title="link to this section">23.2</a></span> Set
+ Objects</h1>
+
+ <p>Set objects are collections of <a href="#sec-ecmascript-language-types">ECMAScript language values</a>. A distinct value
+ may only occur once as an element of a Set’s collection. Distinct values are discriminated using the <a
+ href="#sec-samevaluezero">SameValueZero</a> comparision algorithm.</p>
+
+ <p>Set objects must be implemented using either hash tables or other mechanisms that, on average, provide access times that
+ are sublinear on the number of elements in the collection. The data structures used in this Set objects specification is
+ only intended to describe the required observable semantics of Set objects. It is not intended to be a viable
+ implementation model.</p>
+ </div>
+
+ <section id="sec-set-constructor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-23.2.1"><a href="#sec-set-constructor" title="link to this section">23.2.1</a></span> The
+ Set Constructor</h1>
+
+ <p>The Set constructor is the %Set% intrinsic object and the initial value of the <code>Set</code> property of the global
+ object. When <code>Set</code> is called as a function rather than as a constructor, it initializes its <b>this</b> value
+ with the internal state necessary to support the <code>Set.prototype</code> built-in methods.</p>
+
+ <p>The <code>Set</code> constructor is designed to be subclassable. It may be used as the value in an <code>extends</code>
+ clause of a class definition. Subclass constructors that intend to inherit the specified <code>Set</code> behaviour must
+ include a <code>super</code> call to <code>Set</code>.</p>
+ </div>
+
+ <section id="sec-set-iterable">
+ <h1><span class="secnum" id="sec-23.2.1.1"><a href="#sec-set-iterable" title="link to this section">23.2.1.1</a></span>
+ Set ( [ iterable ] )</h1>
+
+ <p>When the <code>Set</code> function is called with optional argument <var>iterable</var> the following steps are
+ taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>set</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>set</i>) is not Object then, throw a
+ <b>TypeError</b> exception.</li>
+ <li>If <i>set</i> does not have a [[SetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a>, then throw a <b>TypeError</b> exception.</li>
+ <li>If <i>set’s</i> [[SetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is not
+ <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>If <i>iterable</i> is not present, let <i>iterable</i> be <b>undefined</b>.</li>
+ <li>If <i>iterable</i> is either <b>undefined</b> or <b>null</b>, then let <i>iter</i> be <b>undefined</b>.</li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>iter</i> be the result of <a href="#sec-getiterator">GetIterator</a>(<i>iterable</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>iter</i>).</li>
+ <li>Let <i>adder</i> be the result of <a href="#sec-get-o-p">Get</a>(<i>set</i>, <code>"add"</code>)<b>.</b></li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>adder</i>).</li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>adder</i>) is <b>false</b>, throw a <b>TypeError</b>
+ Exception.</li>
+ </ol>
+ </li>
+ <li>If the value of <i>set’s</i> [[SetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> is not <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>set</i> has not been reentrantly initialized.</li>
+ <li>Set <i>set’s</i> [[SetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to a
+ new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>If <i>iter</i> is <b>undefined</b>, then return <i>set</i>.</li>
+ <li>Repeat
+ <ol class="block">
+ <li>Let <i>next</i> be the result of <a href="#sec-iteratorstep">IteratorStep</a>(<i>iter</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>next</i>).</li>
+ <li>If <i>next</i> is <b>false</b>, then return <i>set</i>.</li>
+ <li>Let <i>nextValue</i> be <a href="#sec-iteratorvalue">IteratorValue</a>(<i>next</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>nextValue</i>).</li>
+ <li>Let <i>status</i> be the result of calling the [[Call]] internal method of <i>adder</i> with <i>set</i> as
+ <i>thisArgument</i> and a <a href="#sec-list-and-record-specification-type">List</a> whose sole element is
+ <i>nextValue</i> as <i>argumentsList</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ </ol>
+ </li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Using a method call for inserting values during initialization enables subclasses to
+ that redefine add to still make a super call to the inherited constructor.</p>
+ </div>
+ </section>
+
+ <section id="sec-new-set-argumentslist">
+ <h1><span class="secnum" id="sec-23.2.1.2"><a href="#sec-new-set-argumentslist"
+ title="link to this section">23.2.1.2</a></span> new Set ( ...argumentsList )</h1>
+
+ <p>When <code>Set</code> is called as part of a <code>new</code> expression it is a constructor: it initializes a newly
+ created object. Set called as part of a new expression with argument list <i>argumentsList</i> performs the following
+ steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be the Set function object on which the <code>new</code> operator was applied.</li>
+ <li>Let <i>argumentsList</i> be the <i>argumentsList</i> argument of the [[Construct]] internal method that was invoked
+ by the <code>new</code> operator.</li>
+ <li>Return the result of <a href="#sec-construct-f-argumentslist">Construct</a>(<i>F</i>, <i>argumentsList</i>).</li>
+ </ol>
+
+ <p>If Set is implemented as an <a href="#sec-ecmascript-function-objects">ECMAScript function object</a>, its
+ [[Construct]] internal method will perform the above steps.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-set-constructor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-23.2.2"><a href="#sec-properties-of-the-set-constructor"
+ title="link to this section">23.2.2</a></span> Properties of the Set Constructor</h1>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the Set
+ constructor is the Function prototype object (<a href="#sec-properties-of-the-function-prototype-object">19.2.3</a>).</p>
+
+ <p>Besides the <code>length</code> property (whose value is <b>1</b>), the Set constructor has the following
+ properties:</p>
+ </div>
+
+ <section id="sec-set.prototype">
+ <h1><span class="secnum" id="sec-23.2.2.1"><a href="#sec-set.prototype" title="link to this section">23.2.2.1</a></span>
+ Set.prototype</h1>
+
+ <p>The initial value of <code>Set.prototype</code> is the intrinsic %SetPrototype% object (<a
+ href="#sec-properties-of-the-set-prototype-object">23.2.3</a>).</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-set-@@create">
+ <h1><span class="secnum" id="sec-23.2.2.2"><a href="#sec-set-@@create" title="link to this section">23.2.2.2</a></span>
+ Set[ @@create ] ( )</h1>
+
+ <p>The @@create method of a Set function object <var>F</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be the <b>this</b> value.</li>
+ <li>Let <i>obj</i> be the result of calling <a
+ href="#sec-ordinarycreatefromconstructor">OrdinaryCreateFromConstructor</a>(<i>F</i>, <code>"%SetPrototype%"</code>,
+ ( [[SetData]])).</li>
+ <li>Return <i>obj</i>.</li>
+ </ol>
+
+ <p>The value of the <code>name</code> property of this function is <code>"[Symbol.create]"</code>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>true</b> }.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-set-prototype-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-23.2.3"><a href="#sec-properties-of-the-set-prototype-object"
+ title="link to this section">23.2.3</a></span> Properties of the Set Prototype Object</h1>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the Set
+ prototype object is the standard built-in Object prototype object (<a
+ href="#sec-properties-of-the-object-prototype-object">19.1.3</a>). The Set prototype object is an ordinary object. It does
+ not have a [[SetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</p>
+ </div>
+
+ <section id="sec-set.prototype.add">
+ <h1><span class="secnum" id="sec-23.2.3.1"><a href="#sec-set.prototype.add"
+ title="link to this section">23.2.3.1</a></span> Set.prototype.add ( value )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>S</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>S)</i> is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>S</i> does not have a [[SetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>
+ throw a <b>TypeError</b> exception.</li>
+ <li>If <i>S’s</i> [[SetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is
+ <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>entries</i> be the <a href="#sec-list-and-record-specification-type">List</a> that is the value of
+ <i>S</i>’s [[SetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Repeat for each <i>e</i> that is an element of <i>entries,</i>
+ <ol class="block">
+ <li>If <i>e</i> is not <span style="font-family: sans-serif">empty</span> and <a
+ href="#sec-samevaluezero">SameValueZero</a>(<i>e</i>, <i>value</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>Return <i>S</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>If <i>value</i> is −0, then let <i>value</i> be +0.</li>
+ <li>Append <i>value</i> as the last element of <i>entries</i>.</li>
+ <li>Return <i>S</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-set.prototype.clear">
+ <h1><span class="secnum" id="sec-23.2.3.2"><a href="#sec-set.prototype.clear"
+ title="link to this section">23.2.3.2</a></span> Set.prototype.clear ( )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>S</i> be <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>S)</i> is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>S</i> does not have a [[SetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>
+ throw a <b>TypeError</b> exception.</li>
+ <li>If <i>S’s</i> [[SetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is
+ <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>entries</i> be the <a href="#sec-list-and-record-specification-type">List</a> that is the value of
+ <i>S</i>’s [[SetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Repeat for each <i>e</i> that is an element of <i>entries,</i>
+ <ol class="block">
+ <li>Replace the element of <i>entries</i> whose value is <i>e</i> with an element whose value is <span
+ style="font-family: sans-serif">empty</span><i>.</i></li>
+ </ol>
+ </li>
+ <li>Return <b>undefined</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-set.prototype.constructor">
+ <h1><span class="secnum" id="sec-23.2.3.3"><a href="#sec-set.prototype.constructor"
+ title="link to this section">23.2.3.3</a></span> Set.prototype.constructor</h1>
+
+ <p>The initial value of <code>Set.prototype.constructor</code> is the built-in <code>Set</code> constructor.</p>
+ </section>
+
+ <section id="sec-set.prototype.delete">
+ <h1><span class="secnum" id="sec-23.2.3.4"><a href="#sec-set.prototype.delete"
+ title="link to this section">23.2.3.4</a></span> Set.prototype.delete ( value )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>S</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>S)</i> is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>S</i> does not have a [[SetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>
+ throw a <b>TypeError</b> exception.</li>
+ <li>If <i>S’s</i> [[SetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is
+ <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>entries</i> be the <a href="#sec-list-and-record-specification-type">List</a> that is the value of
+ <i>S</i>’s [[SetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Repeat for each <i>e</i> that is an element of <i>entries</i>,
+ <ol class="block">
+ <li>If <i>e</i> is not <span style="font-family: sans-serif">empty</span> and <a
+ href="#sec-samevaluezero">SameValueZero</a>(<i>e</i>, <i>value</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>Replace the element of <i>entries</i> whose value is <i>e</i> with an element whose value is <span
+ style="font-family: sans-serif">empty</span><i>.</i></li>
+ <li>Return <b>true</b>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The value <b>empty</b> is used as a specification device to indicate that an entry has
+ been deleted. Actual implementations may take other actions such as physically removing the entry from internal data
+ structures.</p>
+ </div>
+ </section>
+
+ <section id="sec-set.prototype.entries">
+ <h1><span class="secnum" id="sec-23.2.3.5"><a href="#sec-set.prototype.entries"
+ title="link to this section">23.2.3.5</a></span> Set.prototype.entries ( )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>S</i> be the <b>this</b> value.</li>
+ <li>Return the result of calling the <a href="#sec-createsetiterator">CreateSetIterator</a> abstract operation with
+ arguments <i>S</i> and <b>"<code>key+value</code>"</b>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> For iteration purposes, a Set appears similar to a Map where each entry has the same
+ value for its key and value.</p>
+ </div>
+ </section>
+
+ <section id="sec-set.prototype.foreach">
+ <h1><span class="secnum" id="sec-23.2.3.6"><a href="#sec-set.prototype.foreach"
+ title="link to this section">23.2.3.6</a></span> Set.prototype.forEach ( callbackfn [ , thisArg ] )</h1>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> <i>callbackfn</i> should be a function that accepts three arguments.
+ <code>forEach</code> calls <i>callbackfn</i> once for each value present in the set object, in value insertion order.
+ <i>callbackfn</i> is called only for values of the Set which actually exist; it is not called for keys that have been
+ deleted from the set.</p>
+
+ <p>If a <i>thisArg</i> parameter is provided, it will be used as the <b>this</b> value for each invocation of
+ <i>callbackfn</i>. If it is not provided, <b>undefined</b> is used instead.</p>
+
+ <p>If <i>callbackfn</i> is an Arrow Function, <b>this</b> was lexically bound when the function was created so
+ <i>thisArg</i> will have no effect.</p>
+
+ <p><i>callbackfn</i> is called with three arguments: the first two arguments are a value contained in the Set. The same
+ value of passed for both arguments. The Set object being traversed is passed as the third argument.</p>
+
+ <p>The <i>callbackfn</i> is called with three arguments to be consistent with the call back functions used by
+ <code>forEach</code> methods for Map and Array. For Sets, each item value is considered to be both the key and the
+ value.</p>
+
+ <p><code>forEach</code> does not directly mutate the object on which it is called but the object may be mutated by the
+ calls to <i>callbackfn</i>.</p>
+
+ <p>Each value is normally visited only once. However, a value will be revisited if it is deleted after it has been
+ visited and then re-added before the to <code>forEach</code> call completes. Values that are deleted after the call to
+ <code>forEach</code> begins and before being visited are not visited unless the value is added again before the to
+ <code>forEach</code> call completes. New values added, after the call to <code>forEach</code> begins are visited.</p>
+ </div>
+
+ <p>When the <code>forEach</code> method is called with one or two arguments, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>S</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>S)</i> is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>S</i> does not have a [[SetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>
+ throw a <b>TypeError</b> exception.</li>
+ <li>If <i>S’s</i> [[SetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is
+ <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>callbackfn</i>) is <b>false</b>, throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>thisArg</i> was supplied, let <i>T</i> be <i>thisArg</i>; else let <i>T</i> be <b>undefined</b>.</li>
+ <li>Let <i>entries</i> be the <a href="#sec-list-and-record-specification-type">List</a> that is the value of
+ <i>S</i>’s [[SetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Repeat for each <i>e</i> that is an element of <i>entries,</i> in original insertion order
+ <ol class="block">
+ <li>If <i>e</i> is not <span style="font-family: sans-serif">empty</span>, then
+ <ol class="block">
+ <li>Let <i>funcResult</i> be the result of calling the [[Call]] internal method of <i>callbackfn</i> with
+ <i>T</i> as <i>thisArgument</i> and a <a href="#sec-list-and-record-specification-type">List</a> containing
+ <i>e</i>, <i>e</i>, and <i>S</i> as <i>argumentsList</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>funcResult</i>).</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Return <b>undefined</b>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>forEach</code> method is <b>1</b>.</p>
+ </section>
+
+ <section id="sec-set.prototype.has">
+ <h1><span class="secnum" id="sec-23.2.3.7"><a href="#sec-set.prototype.has"
+ title="link to this section">23.2.3.7</a></span> Set.prototype.has ( value )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>S</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>S)</i> is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>S</i> does not have a [[SetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>
+ throw a <b>TypeError</b> exception.</li>
+ <li>If <i>S’s</i> [[SetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is
+ <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>entries</i> be the <a href="#sec-list-and-record-specification-type">List</a> that is the value of
+ <i>S</i>’s [[SetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Repeat for each <i>e</i> that is an element of <i>entries,</i>
+ <ol class="block">
+ <li>If <i>e</i> is not <span style="font-family: sans-serif">empty</span> and <a
+ href="#sec-samevaluezero">SameValueZero</a>(<i>e</i>, <i>value</i>) is <b>true</b>, then return
+ <b>true</b><i>.</i></li>
+ </ol>
+ </li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-set.prototype.keys">
+ <h1><span class="secnum" id="sec-23.2.3.8"><a href="#sec-set.prototype.keys"
+ title="link to this section">23.2.3.8</a></span> Set.prototype.keys ( )</h1>
+
+ <p>The initial value of the <code>keys</code> property is the same function object as the initial value of the
+ <code>values</code> property.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> For iteration purposes, a Set appears similar to a Map where each entry has the same
+ value for its key and value.</p>
+ </div>
+ </section>
+
+ <section id="sec-get-set.prototype.size">
+ <h1><span class="secnum" id="sec-23.2.3.9"><a href="#sec-get-set.prototype.size"
+ title="link to this section">23.2.3.9</a></span> get Set.prototype.size</h1>
+
+ <p><code>Set.prototype.size</code> is an accessor property whose set accessor function is <span
+ class="value">undefined</span>. Its get accessor function performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>S</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>S)</i> is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>S</i> does not have a [[SetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>
+ throw a <b>TypeError</b> exception.</li>
+ <li>If <i>S’s</i> [[SetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is
+ <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>entries</i> be the <a href="#sec-list-and-record-specification-type">List</a> that is the value of
+ <i>S</i>’s [[SetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>count</i> be 0.</li>
+ <li>For each <i>e</i> that is an element of <i>entries</i>
+ <ol class="block">
+ <li>If <i>e</i> is not <span style="font-family: sans-serif">empty</span> then
+ <ol class="block">
+ <li>Set <i>count</i> to <i>count</i>+1.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Return <i>count</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-set.prototype.values">
+ <h1><span class="secnum" id="sec-23.2.3.10"><a href="#sec-set.prototype.values"
+ title="link to this section">23.2.3.10</a></span> Set.prototype.values ( )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>S</i> be the <b>this</b> value.</li>
+ <li>Return the result of calling the <a href="#sec-createsetiterator">CreateSetIterator</a> abstract operation with
+ argument <i>S</i> and <b>"<code>value</code>"</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-set.prototype-@@iterator">
+ <h1><span class="secnum" id="sec-23.2.3.11"><a href="#sec-set.prototype-@@iterator"
+ title="link to this section">23.2.3.11</a></span> Set.prototype [@@iterator ] ( )</h1>
+
+ <p>The initial value of the @@iterator property is the same function object as the initial value of the
+ <code>values</code> property.</p>
+ </section>
+
+ <section id="sec-set.prototype-@@tostringtag">
+ <h1><span class="secnum" id="sec-23.2.3.12"><a href="#sec-set.prototype-@@tostringtag"
+ title="link to this section">23.2.3.12</a></span> Set.prototype [ @@toStringTag ]</h1>
+
+ <p>The initial value of the @@toStringTag property is the string value <b>"<code>Set</code>"</b>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <span class="value">false</span>, [[Enumerable]]: <span
+ class="value">false</span>, [[Configurable]]: <span class="value">true</span> }.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-set-instances">
+ <h1><span class="secnum" id="sec-23.2.4"><a href="#sec-properties-of-set-instances"
+ title="link to this section">23.2.4</a></span> Properties of Set Instances</h1>
+
+ <p>Set instances are ordinary objects that inherit properties from the Set prototype. After initialization by the Set
+ constructor, Set instances also have a [[SetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a>.</p>
+ </section>
+
+ <section id="sec-set-iterator-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-23.2.5"><a href="#sec-set-iterator-objects"
+ title="link to this section">23.2.5</a></span> Set Iterator Objects</h1>
+
+ <p>A Set Iterator is an ordinary object, with the structure defined below, that represents a specific iteration over some
+ specific Set instance object. There is not a named constructor for Set Iterator objects. Instead, set iterator objects
+ are created by calling certain methods of Set instance objects.</p>
+ </div>
+
+ <section id="sec-createsetiterator">
+ <h1><span class="secnum" id="sec-23.2.5.1"><a href="#sec-createsetiterator"
+ title="link to this section">23.2.5.1</a></span> CreateSetIterator Abstract Operation</h1>
+
+ <p>Several methods of Set objects return Iterator objects. The abstract operation CreateSetIterator with arguments
+ <var>set</var> and <var>kind</var> is used to create such iterator objects. It performs the following steps:</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>set</i>) is not Object, throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>set</i> does not have a [[SetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> throw a <b>TypeError</b> exception.</li>
+ <li>If <i>set’s</i> [[SetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is
+ <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>iterator</i> be the result of <a href="#sec-objectcreate">ObjectCreate</a>(%SetIteratorPrototype%,
+ ([[IteratedSet]], [[SetNextIndex]], [[SetIterationKind]])).</li>
+ <li>Set <i>iterator’s</i> [[IteratedSet]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> to <i>set</i>.</li>
+ <li>Set <i>iterator’s</i> [[SetNextIndex]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> to 0.</li>
+ <li>Set <i>iterator’s</i> [[SetIterationKind]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> to <i>kind</i>.</li>
+ <li>Return <i>iterator</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-%setiteratorprototype%-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-23.2.5.2"><a href="#sec-%setiteratorprototype%-object"
+ title="link to this section">23.2.5.2</a></span> The %SetIteratorPrototype% Object</h1>
+
+ <p>All Set Iterator Objects inherit properties from the %SetIteratorPrototype% intrinsic object. The
+ %SetIteratorPrototype% intrinsic object is an ordinary object and its [[Prototype]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is the %ObjectPrototype% intrinsic object. In
+ addition, %SetIteratorPrototype% has the following properties:</p>
+ </div>
+
+ <section id="sec-%setiteratorprototype%.next">
+ <h1><span class="secnum" id="sec-23.2.5.2.1"><a href="#sec-%setiteratorprototype%.next"
+ title="link to this section">23.2.5.2.1</a></span> %SetIteratorPrototype%.next ( )</h1>
+ <ol class="proc">
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object, throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>O</i> does not have all of the internal slots of a Set Iterator Instance (<a
+ href="#sec-properties-of-set-iterator-instances">23.2.5.3</a>), throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>s</i> be the value of the [[IteratedSet]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>Let <i>index</i> be the value of the [[SetNextIndex]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>Let <i>itemKind</i> be the value of the [[SetIterationKind]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>If <i>s</i> is <b>undefined</b>, then return <a
+ href="#sec-createiterresultobject">CreateIterResultObject</a>(<b>undefined</b>, <b>true</b>).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>s</i> has a [[SetData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> and <i>s</i> has been initialized so the
+ value of [[SetData]] is not <b>undefined</b>.</li>
+ <li>Let <i>entries</i> be the <a href="#sec-list-and-record-specification-type">List</a> that is the value of the
+ [[SetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>s</i>.</li>
+ <li>Repeat while <i>index</i> is less than the total number of elements of <i>entries</i>. The number of elements must
+ be redetermined each time this method is evaluated.
+ <ol class="block">
+ <li>Let <i>e</i> be <i>entries</i>[<i>index</i>].</li>
+ <li>Set <i>index</i> to <i>index</i>+1;</li>
+ <li>Set the [[SetNextIndex]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of
+ <i>O</i> to <i>index</i>.</li>
+ <li>If <i>e</i> is not <span style="font-family: sans-serif">empty</span>, then
+ <ol class="block">
+ <li>If <i>itemKind</i> is <b>"<code>key+value</code>"</b> then,
+ <ol class="block">
+ <li>Let <i>result</i> be the result of performing <a href="#sec-arraycreate">ArrayCreate</a>(2).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>result</i> is a new, well-formed Array object so
+ the following operations will never fail.</li>
+ <li>Call <a href="#sec-createdataproperty">CreateDataProperty</a>(<i>result</i>, <b>"<code>0</code>"</b>,
+ <i>e</i>) .</li>
+ <li>Call <a href="#sec-createdataproperty">CreateDataProperty</a>(<i>result</i>, <b>"<code>1</code>"</b>,
+ <i>e</i>).</li>
+ <li>Return <a href="#sec-createiterresultobject">CreateIterResultObject</a>(<i>result</i>,
+ <b>false</b>).</li>
+ </ol>
+ </li>
+ <li>Return <a href="#sec-createiterresultobject">CreateIterResultObject</a>(<i>e</i>, <b>false</b>).</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Set the [[IteratedSet]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i> to
+ <b>undefined</b>.</li>
+ <li>Return <a href="#sec-createiterresultobject">CreateIterResultObject</a>(<b>undefined</b>, <b>true</b>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-%setiteratorprototype%-@@iterator">
+ <h1><span class="secnum" id="sec-23.2.5.2.2"><a href="#sec-%setiteratorprototype%-@@iterator"
+ title="link to this section">23.2.5.2.2</a></span> %SetIteratorPrototype% [ @@iterator ] ( )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Return the <b>this</b> value.</li>
+ </ol>
+
+ <p>The value of the <code>name</code> property of this function is <code>"[Symbol.iterator]"</code>.</p>
+ </section>
+
+ <section id="sec-%setiteratorprototype%-@@tostringtag">
+ <h1><span class="secnum" id="sec-23.2.5.2.3"><a href="#sec-%setiteratorprototype%-@@tostringtag"
+ title="link to this section">23.2.5.2.3</a></span> %SetIteratorPrototype% [ @@toStringTag ]</h1>
+
+ <p>The initial value of the @@toStringTag property is the string value <b>"<code>Set Iterator</code>"</b>.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-set-iterator-instances">
+ <h1><span class="secnum" id="sec-23.2.5.3"><a href="#sec-properties-of-set-iterator-instances"
+ title="link to this section">23.2.5.3</a></span> Properties of Set Iterator Instances</h1>
+
+ <p>Set Iterator instances are ordinary objects that inherit properties from the %SetIteratorPrototype% intrinsic object.
+ Set Iterator instances are initially created with the internal slots specified in <a href="#table-46">Table 46</a>.</p>
+
+ <figure>
+ <figcaption><span id="table-46">Table 46</span> — Internal Slots of Set Iterator Instances</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-top: 2px solid #000000">Internal Slot</th>
+ <th style="border-bottom: 1px solid #000000; border-left: 0px solid black; border-right: 1px solid #000000; border-top: 2px solid #000000">Description</th>
+ </tr>
+ <tr>
+ <td>[[IteratedSet]]</td>
+ <td>The Set object that is being iterated.</td>
+ </tr>
+ <tr>
+ <td style="border-bottom: 0px solid black">[[SetNextIndex]]</td>
+ <td style="border-bottom: 0px solid black">The integer index of the next Set data element to be examined by this iterator</td>
+ </tr>
+ <tr>
+ <td style="border-top: 0px solid black">[[SetIterationKind]]</td>
+ <td style="border-top: 0px solid black">A string value that identifies what is to be returned for each element of the iteration. The possible values are: <b>"<code>key</code>"</b>, <b>"<code>value</code>"</b>, <b>"<code>key+value</code>"</b>. <b>"<code>key</code>"</b> and <b>"<code>value</code>"</b> have the same meaning.</td>
+ </tr>
+ </table>
+ </figure>
+ </section>
+ </section>
+ </section>
+
+ <section id="sec-weakmap-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-23.3"><a href="#sec-weakmap-objects" title="link to this section">23.3</a></span> WeakMap
+ Objects</h1>
+
+ <p>WeakMap objects are collections of key/value pairs where the keys are objects and values may be arbitrary <a
+ href="#sec-ecmascript-language-types">ECMAScript language values</a>. A WeakMap may be queried to see if it contains an
+ key/value pair with a specific key, but no mechanisms is provided for enumerating the objects it holds as keys. If an object
+ that is being used as the key of a WeakMap key/value pair is only reachable by following a chain of references that start
+ within that WeakMap, then that key/value pair is inaccessible and is automatically removed from the WeakMap. WeakMap
+ implementations must detect and remove such key/value pairs and any associated resources.</p>
+
+ <p>An implementation may impose an arbitrarily determined latency between the time a key/value pair of a WeakMap becomes
+ inaccessible and the time when the key/value pair is removed from the WeakMap. If this latency was observable to ECMAScript
+ program, it would be a source of indeterminacy that could impact program execution. For that reason, an ECMAScript
+ implementation must not provide any means to observe a key of a WeakMap that does not require the observer to present the
+ observed key.</p>
+
+ <p>WeakMap objects must be implemented using either hash tables or other mechanisms that, on average, provide access times
+ that are sublinear on the number of key/value pairs in the collection. The data structure used in this WeakMap objects
+ specification are only intended to describe the required observable semantics of WeakMap objects. It is not intended to be
+ a viable implementation model.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> WeakMap and WeakSets are intended to provide mechanisms for dynamically associating state
+ with an object in a manner that does not “leak” memory resources if, in the absence of the WeakMap or WeakSet,
+ the object otherwise became inaccessible and subject to resource reclamation by the implementation’s garbage
+ collection mechanisms. Achieving this characteristic requires coordination between the WeakMap or WeakSet implementation
+ and the garbage collector. The following references describe mechanism that may be useful to implementations of WeakMap
+ and WeakSets:</p>
+
+ <p>Barry Hayes. 1997. Ephemerons: a new finalization mechanism. In <i>Proceedings of the 12th ACM SIGPLAN conference on
+ Object-oriented programming, systems, languages, and applications (OOPSLA '97)</i>, A. Michael Berman (Ed.). ACM, New
+ York, NY, USA, 176-183. <a
+ href="http://doi.acm.org/10.1145/263698.263733">http://doi.acm.org/10.1145/263698.263733</a>.</p>
+
+ <p>Alexandra Barros, Roberto Ierusalimschy, Eliminating Cycles in Weak Tables. Journal of Universal Computer Science -
+ J.UCS , vol. 14, no. 21, pp. 3481-3497, 2008. <a
+ href="http://www.jucs.org/jucs_14_21/eliminating_cycles_in_weak">http://www.jucs.org/jucs_14_21/eliminating_cycles_in_weak</a></p>
+ </div>
+ </div>
+
+ <section id="sec-weakmap-constructor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-23.3.1"><a href="#sec-weakmap-constructor" title="link to this section">23.3.1</a></span>
+ The WeakMap Constructor</h1>
+
+ <p>The WeakMap constructor is the %WeakMap% intrinsic object and the initial value of the <code>WeakMap</code> property of
+ the global object. When <code>WeakMap</code> is called as a function rather than as a constructor, it initializes its
+ <b>this</b> value with the internal state necessary to support the <code><a
+ href="#sec-weakmap.prototype">WeakMap.prototype</a></code> built-in methods.</p>
+
+ <p>The <code>WeakMap</code> constructor is designed to be subclassable. It may be used as the value in an
+ <code>extends</code> clause of a class definition. Subclass constructors that intend to inherit the specified
+ <code>WeakMap</code> behaviour must include a <code>super</code> call to <code>WeakMap</code>.</p>
+ </div>
+
+ <section id="sec-weakmap-iterable">
+ <h1><span class="secnum" id="sec-23.3.1.1"><a href="#sec-weakmap-iterable"
+ title="link to this section">23.3.1.1</a></span> WeakMap ( [ iterable ] )</h1>
+
+ <p>When the <code>WeakMap</code> function is called with optional argument <var>iterable</var> the following steps are
+ taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>map</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>map</i>) is not Object then, throw a
+ <b>TypeError</b> exception.</li>
+ <li>If <i>map</i> does not have a [[WeakMapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a>, then throw a <b>TypeError</b> exception.</li>
+ <li>If <i>map’s</i> [[WeakMapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is
+ not <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>If <i>iterable</i> is not present, let <i>iterable</i> be <b>undefined</b>.</li>
+ <li>If <i>iterable</i> is either <b>undefined</b> or <b>null</b>, then let <i>iter</i> be <b>undefined</b>.</li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>iter</i> be the result of <a href="#sec-getiterator">GetIterator</a>(<i>iterable</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>iter</i>).</li>
+ <li>Let <i>adder</i> be the result of <a href="#sec-get-o-p">Get</a>(<i>map</i>, <code>"set"</code>)<b>.</b></li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>adder</i>).</li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>adder</i>) is <b>false</b>, throw a <b>TypeError</b>
+ Exception.</li>
+ </ol>
+ </li>
+ <li>If the value of <i>map’s</i> [[WeakMapData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is not <b>undefined</b>, then throw a
+ <b>TypeError</b> exception.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>map</i> has not been reentrantly initialized.</li>
+ <li>Set <i>map’s</i> [[WeakMapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>
+ to a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>If <i>iter</i> is <b>undefined</b>, then return <i>map</i>.</li>
+ <li>Repeat
+ <ol class="block">
+ <li>Let <i>next</i> be the result of <a href="#sec-iteratorstep">IteratorStep</a>(<i>iter</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>next</i>).</li>
+ <li>If <i>next</i> is <b>false</b>, then return <a
+ href="#sec-normalcompletion">NormalCompletion</a>(<i>map</i>).</li>
+ <li>Let <i>nextValue</i> be <a href="#sec-iteratorvalue">IteratorValue</a>(<i>next</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>nextValue</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>nextValue</i>) is not Object, then throw a
+ <b>TypeError</b> exception</li>
+ <li>Let <i>k</i> be the result of <a href="#sec-get-o-p">Get</a>(<i>nextValue</i>, <code>"0"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>k</i>).</li>
+ <li>Let <i>v</i> be the result of <a href="#sec-get-o-p">Get</a>(<i>nextValue</i>, <code>"1"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>v</i>).</li>
+ <li>Let <i>status</i> be the result of calling the [[Call]] internal method of <i>adder</i> with <i>map</i> as
+ <i>thisArgument</i> and a <a href="#sec-list-and-record-specification-type">List</a> whose elements are <i>k</i>
+ and <i>v</i> as <i>argumentsList</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ </ol>
+ </li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> If the parameter <i>iterable</i> is present, it is expected to be an object that
+ implements an @@iterator method that returns an iterator object that produces a two element array-like object whose
+ first element is a value that will be used as a WeakMap key and whose second element is the value to associate with that
+ key.</p>
+ </div>
+ </section>
+
+ <section id="sec-new-weakmap-argumentslist">
+ <h1><span class="secnum" id="sec-23.3.1.2"><a href="#sec-new-weakmap-argumentslist"
+ title="link to this section">23.3.1.2</a></span> new WeakMap ( ...argumentsList )</h1>
+
+ <p>When <code>WeakMap</code> is called as part of a <code>new</code> expression it is a constructor: it initializes a
+ newly created object.</p>
+
+ <p><code>WeakMap</code> called as part of a new expression with argument list <i>argumentsList</i> performs the following
+ steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be the WeakMap function object on which the <code>new</code> operator was applied.</li>
+ <li>Let <i>argumentsList</i> be the <i>argumentsList</i> argument of the [[Construct]] internal method that was invoked
+ by the <code>new</code> operator.</li>
+ <li>Return the result of <a href="#sec-construct-f-argumentslist">Construct</a>(<i>F</i>, <i>argumentsList</i>).</li>
+ </ol>
+
+ <p>If WeakMap is implemented as an <a href="#sec-ecmascript-function-objects">ECMAScript function object</a>, its
+ [[Construct]] internal method will perform the above steps.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-weakmap-constructor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-23.3.2"><a href="#sec-properties-of-the-weakmap-constructor"
+ title="link to this section">23.3.2</a></span> Properties of the WeakMap Constructor</h1>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the
+ WeakMap constructor is the Function prototype object (<a
+ href="#sec-properties-of-the-function-prototype-object">19.2.3</a>).</p>
+
+ <p>Besides the <code>length</code> property (whose value is <b>1</b>), the WeakMap constructor has the following
+ properties:</p>
+ </div>
+
+ <section id="sec-weakmap.prototype">
+ <h1><span class="secnum" id="sec-23.3.2.1"><a href="#sec-weakmap.prototype"
+ title="link to this section">23.3.2.1</a></span> WeakMap.prototype</h1>
+
+ <p>The initial value of <code>WeakMap.prototype</code> is the WeakMap prototype object (<a
+ href="#sec-properties-of-the-weakmap-prototype-object">23.3.3</a>).</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-weakmap-@@create">
+ <h1><span class="secnum" id="sec-23.3.2.2"><a href="#sec-weakmap-@@create"
+ title="link to this section">23.3.2.2</a></span> WeakMap[ @@create ] ( )</h1>
+
+ <p>The @@create method of a WeakMap object <var>F</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be the <b>this</b> value.</li>
+ <li>Let <i>obj</i> be the result of calling <a
+ href="#sec-ordinarycreatefromconstructor">OrdinaryCreateFromConstructor</a>(<i>F</i>,
+ <code>"%WeakMapPrototype%"</code>, ( [[WeakMapData]] )).</li>
+ <li>Return <i>obj</i>.</li>
+ </ol>
+
+ <p>The value of the <code>name</code> property of this function is <code>"[Symbol.create]"</code>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>true</b> }.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-weakmap-prototype-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-23.3.3"><a href="#sec-properties-of-the-weakmap-prototype-object"
+ title="link to this section">23.3.3</a></span> Properties of the WeakMap Prototype Object</h1>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the
+ WeakMap prototype object is the standard built-in Object prototype object (<a
+ href="#sec-properties-of-the-object-prototype-object">19.1.3</a>). The WeakMap prototype object is an ordinary object. It
+ does not have a [[WeakMapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</p>
+ </div>
+
+ <section id="sec-weakmap.prototype.clear">
+ <h1><span class="secnum" id="sec-23.3.3.1"><a href="#sec-weakmap.prototype.clear"
+ title="link to this section">23.3.3.1</a></span> WeakMap.prototype.clear ( )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>M</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>M)</i> is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>M</i> does not have a [[WeakMapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> throw a <b>TypeError</b> exception.</li>
+ <li>If <i>M’s</i> [[WeakMapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is
+ <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Set the value of <i>M</i>’s [[WeakMapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> to a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Return <b>undefined</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-weakmap.prototype.constructor">
+ <h1><span class="secnum" id="sec-23.3.3.2"><a href="#sec-weakmap.prototype.constructor"
+ title="link to this section">23.3.3.2</a></span> WeakMap.prototype.constructor</h1>
+
+ <p>The initial value of <code>WeakMap.prototype.constructor</code> is the built-in <code>WeakMap</code> constructor.</p>
+ </section>
+
+ <section id="sec-weakmap.prototype.delete">
+ <h1><span class="secnum" id="sec-23.3.3.3"><a href="#sec-weakmap.prototype.delete"
+ title="link to this section">23.3.3.3</a></span> WeakMap.prototype.delete ( key )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>M</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>M)</i> is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>M</i> does not have a [[WeakMapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>entries</i> be the <a href="#sec-list-and-record-specification-type">List</a> that is the value of
+ <i>M</i>’s [[WeakMapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>entries</i> is <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>key</i>) is not Object, then return
+ <b>false</b>.</li>
+ <li>Repeat for each Record {[[key]], [[value]]} <i>p</i> that is an element of <i>entries,</i>
+ <ol class="block">
+ <li>If <i>p</i>.[[key]] is not <span style="font-family: sans-serif">empty</span> and <a
+ href="#sec-samevalue">SameValue</a>(<i>p</i>.[[key]], <i>key</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>Set <i>p</i>.[[key]] to <span style="font-family: sans-serif">empty</span><i>.</i></li>
+ <li>Set <i>p</i>.[[value]] to <span style="font-family: sans-serif">empty</span><i>.</i></li>
+ <li>Return <b>true</b>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The value <b>empty</b> is used as a specification device to indicate that an entry has
+ been deleted. Actual implementations may take other actions such as physically removing the entry from internal data
+ structures.</p>
+ </div>
+ </section>
+
+ <section id="sec-weakmap.prototype.get">
+ <h1><span class="secnum" id="sec-23.3.3.4"><a href="#sec-weakmap.prototype.get"
+ title="link to this section">23.3.3.4</a></span> WeakMap.prototype.get ( key )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>M</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>M)</i> is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>M</i> does not have a [[WeakMapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>entries</i> be the <a href="#sec-list-and-record-specification-type">List</a> that is the value of
+ <i>M</i>’s [[WeakMapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>entries</i> is <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>key</i>) is not Object, then return
+ <b>undefined</b>.</li>
+ <li>Repeat for each Record {[[key]], [[value]]} <i>p</i> that is an element of <i>entries,</i>
+ <ol class="block">
+ <li>If <i>p</i>.[[key]] is not <span style="font-family: sans-serif">empty</span> and <a
+ href="#sec-samevalue">SameValue</a>(<i>p</i>.[[key]], <i>key</i>) is <b>true</b>, then return
+ <i>p</i>.[[value]].</li>
+ </ol>
+ </li>
+ <li>Return <b>undefined</b><i>.</i></li>
+ </ol>
+ </section>
+
+ <section id="sec-weakmap.prototype.has">
+ <h1><span class="secnum" id="sec-23.3.3.5"><a href="#sec-weakmap.prototype.has"
+ title="link to this section">23.3.3.5</a></span> WeakMap.prototype.has ( key )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>M</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>M)</i> is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>M</i> does not have a [[WeakMapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>entries</i> be the <a href="#sec-list-and-record-specification-type">List</a> that is the value of
+ <i>M</i>’s [[WeakMapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>entries</i> is <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>key</i>) is not Object, then return
+ <b>false</b>.</li>
+ <li>Repeat for each Record {[[key]], [[value]]} <i>p</i> that is an element of <i>entries,</i>
+ <ol class="block">
+ <li>If <i>p</i>.[[key]] is not <span style="font-family: sans-serif">empty</span> and <a
+ href="#sec-samevalue">SameValue</a>(<i>p</i>.[[key]], <i>key</i>) is <b>true</b>, then return
+ <b>true</b><i>.</i></li>
+ </ol>
+ </li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-weakmap.prototype.set">
+ <h1><span class="secnum" id="sec-23.3.3.6"><a href="#sec-weakmap.prototype.set"
+ title="link to this section">23.3.3.6</a></span> WeakMap.prototype.set ( key , value )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>M</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>M)</i> is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>M</i> does not have a [[WeakMapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>entries</i> be the <a href="#sec-list-and-record-specification-type">List</a> that is the value of
+ <i>M</i>’s [[WeakMapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>entries</i> is <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>key</i>) is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>Repeat for each Record {[[key]], [[value]]} <i>p</i> that is an element of <i>entries,</i>
+ <ol class="block">
+ <li>If <i>p</i>.[[key]] is not <span style="font-family: sans-serif">empty</span> and <a
+ href="#sec-samevalue">SameValue</a>(<i>p</i>.[[key]], <i>key</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>Set <i>p</i>.[[value]] to <i>value.</i></li>
+ <li>Return <i>M</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Let <i>p</i> be the Record {[[key]]: <i>key</i>, [[value]]: <i>value</i>}.</li>
+ <li>Append <i>p</i> as the last element of <i>entries</i>.</li>
+ <li>Return <i>M</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-weakmap.prototype-@@tostringtag">
+ <h1><span class="secnum" id="sec-23.3.3.7"><a href="#sec-weakmap.prototype-@@tostringtag"
+ title="link to this section">23.3.3.7</a></span> WeakMap.prototype [ @@toStringTag ]</h1>
+
+ <p>The initial value of the @@toStringTag property is the string value <b>"<code>WeakMap</code>"</b>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <span class="value">false</span>, [[Enumerable]]: <span
+ class="value">false</span>, [[Configurable]]: <span class="value">true</span> }.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-weakmap-instances">
+ <h1><span class="secnum" id="sec-23.3.4"><a href="#sec-properties-of-weakmap-instances"
+ title="link to this section">23.3.4</a></span> Properties of WeakMap Instances</h1>
+
+ <p>WeakMap instances are ordinary objects that inherit properties from the WeakMap prototype. WeakMap instances also have a
+ [[WeakMapData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</p>
+ </section>
+ </section>
+
+ <section id="sec-weakset-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-23.4"><a href="#sec-weakset-objects" title="link to this section">23.4</a></span> WeakSet
+ Objects</h1>
+
+ <p>WeakSet objects are collections of objects. A distinct object may only occur once as an element of a WeakSet’s
+ collection. A WeakSet may be queried to see if it contains a specific object, but no mechanisms is provided for enumerating
+ the objects it holds. If an object that is contain by a WeakSet is only reachable by following a chain of references that
+ start within that WeakSet, then that object is inaccessible and is automatically removed from the WeakSet. WeakSet
+ implementations must detect and remove such objects and any associated resources.</p>
+
+ <p>An implementation may impose an arbitrarily determined latency between the time an object contained in a WeakSet becomes
+ inaccessible and the time when the object is removed from the WeakSet. If this latency was observable to ECMAScript program,
+ it would be a source of indeterminacy that could impact program execution. For that reason, an ECMAScript
+ implementation must not provide any means to determine if a WeakSet contains a particular object that does not require the
+ observer to present the observed object.</p>
+
+ <p>WeakSet objects must be implemented using either hash tables or other mechanisms that, on average, provide access times
+ that are sublinear on the number of elements in the collection. The data structure used in this WeakSet objects
+ specification is only intended to describe the required observable semantics of WeakSet objects. It is not intended to be a
+ viable implementation model.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> See the NOTE in <a href="#sec-weakmap-objects">23.3</a>.</p>
+ </div>
+ </div>
+
+ <section id="sec-weakset-constructor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-23.4.1"><a href="#sec-weakset-constructor" title="link to this section">23.4.1</a></span>
+ The WeakSet Constructor</h1>
+
+ <p>The WeakSet constructor is the %WeakSet% intrinsic object and the initial value of the <code>WeakSet</code> property of
+ the global object. When <code>WeakSet</code> is called as a function rather than as a constructor, it initializes its
+ <b>this</b> value with the internal state necessary to support the <code><a
+ href="#sec-weakset.prototype">WeakSet.prototype</a></code> built-in methods.</p>
+
+ <p>The <code>WeakSet</code> constructor is designed to be subclassable. It may be used as the value in an
+ <code>extends</code> clause of a class definition. Subclass constructors that intend to inherit the specified
+ <code>WeakSet</code> behaviour must include a <code>super</code> call to <code>WeakSet</code>.</p>
+ </div>
+
+ <section id="sec-weakset-iterable">
+ <h1><span class="secnum" id="sec-23.4.1.1"><a href="#sec-weakset-iterable"
+ title="link to this section">23.4.1.1</a></span> WeakSet ( [ iterable ] )</h1>
+
+ <p>When the <code>WeakSet</code> function is called with optional argument <var>iterable</var> the following steps are
+ taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>set</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>set</i>) is not Object then, throw a
+ <b>TypeError</b> exception.</li>
+ <li>If <i>set</i> does not have a [[WeakSetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a>, then throw a <b>TypeError</b> exception.</li>
+ <li>If <i>set’s</i> [[WeakSetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is
+ not <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>If <i>iterable</i> is not present, let <i>iterable</i> be <b>undefined</b>.</li>
+ <li>If <i>iterable</i> is either <b>undefined</b> or <b>null</b>, then let <i>iter</i> be <b>undefined</b>.</li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>iter</i> be the result of <a href="#sec-getiterator">GetIterator</a>(<i>iterable</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>iter</i>).</li>
+ <li>Let <i>adder</i> be the result of <a href="#sec-get-o-p">Get</a>(<i>set</i>, <code>"add"</code>)<b>.</b></li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>adder</i>).</li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>adder</i>) is <b>false</b>, throw a <b>TypeError</b>
+ Exception.</li>
+ </ol>
+ </li>
+ <li>If the value of <i>set’s</i> [[WeakSetData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is not <b>undefined</b>, then throw a
+ <b>TypeError</b> exception.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>set</i> has not been reentrantly initialized.</li>
+ <li>Set <i>set’s</i> [[WeakSetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>
+ to a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>If <i>iter</i> is <b>undefined</b>, then return <i>set</i>.</li>
+ <li>Repeat
+ <ol class="block">
+ <li>Let <i>next</i> be the result of <a href="#sec-iteratorstep">IteratorStep</a>(<i>iter</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>next</i>).</li>
+ <li>If <i>next</i> is <b>false</b>, then return <a
+ href="#sec-normalcompletion">NormalCompletion</a>(<i>set</i>).</li>
+ <li>Let <i>nextValue</i> be <a href="#sec-iteratorvalue">IteratorValue</a>(<i>next</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>nextValue</i>).</li>
+ <li>Let <i>status</i> be the result of calling the [[Call]] internal method of <i>adder</i> with <i>set</i> as
+ <i>thisArgument</i> and a <a href="#sec-list-and-record-specification-type">List</a> whose sole element is
+ <i>nextValue</i> as <i>argumentsList</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ </ol>
+ </li>
+ </ol>
+ </section>
+
+ <section id="sec-new-weakset-argumentslist">
+ <h1><span class="secnum" id="sec-23.4.1.2"><a href="#sec-new-weakset-argumentslist"
+ title="link to this section">23.4.1.2</a></span> new WeakSet ( ...argumentsList)</h1>
+
+ <p>When <code>WeakSet</code> is called as part of a <code>new</code> expression it is a constructor: it initializes a
+ newly created object.</p>
+
+ <p><code>WeakSet</code> called as part of a new expression with argument list <i>argumentsList</i> performs the following
+ steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be the <code>WeakSet</code> function object on which the <code>new</code> operator was applied.</li>
+ <li>Let <i>argumentsList</i> be the <i>argumentsList</i> argument of the [[Construct]] internal method that was invoked
+ by the <code>new</code> operator.</li>
+ <li>Return the result of <a href="#sec-construct-f-argumentslist">Construct</a>(<i>F</i>, <i>argumentsList</i>).</li>
+ </ol>
+
+ <p>If WeakSet is implemented as an <a href="#sec-ecmascript-function-objects">ECMAScript function object</a>, its
+ [[Construct]] internal method will perform the above steps.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-weakset-constructor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-23.4.2"><a href="#sec-properties-of-the-weakset-constructor"
+ title="link to this section">23.4.2</a></span> Properties of the WeakSet Constructor</h1>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the
+ WeakSet constructor is the Function prototype object (<a
+ href="#sec-properties-of-the-function-prototype-object">19.2.3</a>).</p>
+
+ <p>Besides the <code>length</code> property (whose value is <b>1</b>), the WeakSet constructor has the following
+ properties:</p>
+ </div>
+
+ <section id="sec-weakset.prototype">
+ <h1><span class="secnum" id="sec-23.4.2.1"><a href="#sec-weakset.prototype"
+ title="link to this section">23.4.2.1</a></span> WeakSet.prototype</h1>
+
+ <p>The initial value of <code>WeakSet.prototype</code> is the intrinsic %WeakSetPrototype% object (<a
+ href="#sec-properties-of-the-weakset-prototype-object">23.4.3</a>).</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-weakset-@@create">
+ <h1><span class="secnum" id="sec-23.4.2.2"><a href="#sec-weakset-@@create"
+ title="link to this section">23.4.2.2</a></span> WeakSet [ @@create ] ( )</h1>
+
+ <p>The @@create method of a WeakSet function object <var>F</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be the <b>this</b> value.</li>
+ <li>Let <i>obj</i> be the result of calling <a
+ href="#sec-ordinarycreatefromconstructor">OrdinaryCreateFromConstructor</a>(<i>F</i>,
+ <code>"%WeakSetPrototype%"</code>, ( [[WeakSetData]] )).</li>
+ <li>Return <i>obj</i>.</li>
+ </ol>
+
+ <p>The value of the <code>name</code> property of this function is <code>"[Symbol.create]"</code>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>true</b> }.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-weakset-prototype-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-23.4.3"><a href="#sec-properties-of-the-weakset-prototype-object"
+ title="link to this section">23.4.3</a></span> Properties of the WeakSet Prototype Object</h1>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the
+ WeakSet prototype object is the standard built-in Object prototype object (<a
+ href="#sec-properties-of-the-object-prototype-object">19.1.3</a>). The WeakSet prototype object is an ordinary object. It
+ does not have a [[WeakSetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</p>
+ </div>
+
+ <section id="sec-weakset.prototype.add">
+ <h1><span class="secnum" id="sec-23.4.3.1"><a href="#sec-weakset.prototype.add"
+ title="link to this section">23.4.3.1</a></span> WeakSet.prototype.add ( value )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>S</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>S)</i> is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>S</i> does not have a [[WeakSetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> throw a <b>TypeError</b> exception.</li>
+ <li>If <i>S’s</i> [[WeakSetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is
+ <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>value)</i> is not Object, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>Let <i>entries</i> be the <a href="#sec-list-and-record-specification-type">List</a> that is the value of
+ <i>S</i>’s [[WeakSetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Repeat for each <i>e</i> that is an element of <i>entries,</i>
+ <ol class="block">
+ <li>If <i>e</i> is not <span style="font-family: sans-serif">empty</span> and <a
+ href="#sec-samevalue">SameValue</a>(<i>e</i>, <i>value</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>Return <i>S</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Append <i>value</i> as the last element of <i>entries</i>.</li>
+ <li>Return <i>S</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-weakset.prototype.clear">
+ <h1><span class="secnum" id="sec-23.4.3.2"><a href="#sec-weakset.prototype.clear"
+ title="link to this section">23.4.3.2</a></span> WeakSet.prototype.clear ( )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>S</i> be <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>S)</i> is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>S</i> does not have a [[WeakSetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> throw a <b>TypeError</b> exception.</li>
+ <li>If <i>S’s</i> [[WeakSetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is
+ <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Set the value of <i>S</i>’s [[WeakSetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> to a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Return <b>undefined</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-weakset.prototype.constructor">
+ <h1><span class="secnum" id="sec-23.4.3.3"><a href="#sec-weakset.prototype.constructor"
+ title="link to this section">23.4.3.3</a></span> WeakSet.prototype.constructor</h1>
+
+ <p>The initial value of <code>WeakSet.prototype.constructor</code> is the %WeakSet% intrinsic object.</p>
+ </section>
+
+ <section id="sec-weakset.prototype.delete">
+ <h1><span class="secnum" id="sec-23.4.3.4"><a href="#sec-weakset.prototype.delete"
+ title="link to this section">23.4.3.4</a></span> WeakSet.prototype.delete ( value )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>S</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>S)</i> is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>S</i> does not have a [[WeakSetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> throw a <b>TypeError</b> exception.</li>
+ <li>If <i>S’s</i> [[WeakSetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is
+ <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>value)</i> is not Object, then return
+ <b>false</b>.</li>
+ <li>Let <i>entries</i> be the <a href="#sec-list-and-record-specification-type">List</a> that is the value of
+ <i>S</i>’s [[WeakSetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Repeat for each <i>e</i> that is an element of <i>entries</i>,
+ <ol class="block">
+ <li>If <i>e</i> is not <span style="font-family: sans-serif">empty</span> and <a
+ href="#sec-samevalue">SameValue</a>(<i>e</i>, <i>value</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>Replace the element of <i>entries</i> whose value is <i>e</i> with an element whose value is <span
+ style="font-family: sans-serif">empty</span><i>.</i></li>
+ <li>Return <b>true</b>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The value <b>empty</b> is used as a specification device to indicate that an entry has
+ been deleted. Actual implementations may take other actions such as physically removing the entry from internal data
+ structures.</p>
+ </div>
+ </section>
+
+ <section id="sec-weakset.prototype.has">
+ <h1><span class="secnum" id="sec-23.4.3.5"><a href="#sec-weakset.prototype.has"
+ title="link to this section">23.4.3.5</a></span> WeakSet.prototype.has ( value )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>S</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>S)</i> is not Object, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>S</i> does not have a [[WeakSetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> throw a <b>TypeError</b> exception.</li>
+ <li>If <i>S’s</i> [[WeakSetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is
+ <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>entries</i> be the <a href="#sec-list-and-record-specification-type">List</a> that is the value of
+ <i>S</i>’s [[WeakSetData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>value</i>) is not Object, then return
+ <b>false.</b></li>
+ <li>Repeat for each <i>e</i> that is an element of <i>entries,</i>
+ <ol class="block">
+ <li>If <i>e</i> is not <span style="font-family: sans-serif">empty</span> and <a
+ href="#sec-samevalue">SameValue</a>(<i>e</i>, <i>value</i>), then return <b>true</b><i>.</i></li>
+ </ol>
+ </li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-weakset.prototype-@@tostringtag">
+ <h1><span class="secnum" id="sec-23.4.3.6"><a href="#sec-weakset.prototype-@@tostringtag"
+ title="link to this section">23.4.3.6</a></span> WeakSet.prototype [ @@toStringTag ]</h1>
+
+ <p>The initial value of the @@toStringTag property is the string value <b>"Weak<code>Set</code>"</b>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <span class="value">false</span>, [[Enumerable]]: <span
+ class="value">false</span>, [[Configurable]]: <span class="value">true</span> }.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-weakset-instances">
+ <h1><span class="secnum" id="sec-23.4.4"><a href="#sec-properties-of-weakset-instances"
+ title="link to this section">23.4.4</a></span> Properties of WeakSet Instances</h1>
+
+ <p>WeakSet instances are ordinary objects that inherit properties from the WeakSet prototype. After initialization by the
+ WeakSet constructor, WeakSet instances also have a [[WeakSetData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</p>
+ </section>
+ </section>
+</section>
+
+<section id="sec-structured-data">
+ <div class="front">
+ <h1><span class="secnum" id="sec-24"><a href="#sec-structured-data" title="link to this section">24</a></span> Structured
+ Data</h1>
+ </div>
+
+ <section id="sec-arraybuffer-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-24.1"><a href="#sec-arraybuffer-objects" title="link to this section">24.1</a></span>
+ ArrayBuffer Objects</h1>
+ </div>
+
+ <section id="sec-abstract-operations-for-arraybuffer-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-24.1.1"><a href="#sec-abstract-operations-for-arraybuffer-objects"
+ title="link to this section">24.1.1</a></span> Abstract Operations For ArrayBuffer Objects</h1>
+ </div>
+
+ <section id="sec-allocatearraybuffer">
+ <h1><span class="secnum" id="sec-24.1.1.1"><a href="#sec-allocatearraybuffer"
+ title="link to this section">24.1.1.1</a></span> AllocateArrayBuffer( constructor )</h1>
+
+ <p>The abstract operation AllocateArrayBuffer with argument <var>constructor</var> is used to create an uninitialized
+ ArrayBuffer object. It performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>obj</i> be <a href="#sec-ordinarycreatefromconstructor">OrdinaryCreateFromConstructor</a>(<i>constructor</i>,
+ <code>"%ArrayBufferPrototype%"</code>, ( [[ArrayBufferData]], [[ArrayBufferByteLength]]) ).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>obj</i>).</li>
+ <li>Set the [[ArrayBufferByteLength]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of
+ <i>obj</i> to 0.</li>
+ <li>Return <i>obj</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-neuterarraybuffer">
+ <h1><span class="secnum" id="sec-24.1.1.2"><a href="#sec-neuterarraybuffer"
+ title="link to this section">24.1.1.2</a></span> NeuterArrayBuffer( arrayBuffer )</h1>
+
+ <p>The abstract operation NeuterArrayBuffer with argument <var>arrayBuffer</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>arrayBuffer</i>) is Object and it has [[ArrayBufferData]]
+ and [[ArrayBufferByteLength]] internal slots.</li>
+ <li>Set <i>arrayBuffer’s</i> [[ArrayBufferData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to <b>null</b>.</li>
+ <li>Set <i>arrayBuffer</i>’s [[ArrayBufferByteLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to 0.</li>
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<b>null</b>).</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Neutering an ArrayBuffer instance disassociated the <a href="#sec-data-blocks">Data
+ Block</a> used as its backing store from the instance and sets the byte length of the buffer to 0. No operations
+ defined by this specification uses the NeuterArrayBuffer abstract operation. However, an ECMAScript implementation or
+ host environment may define such operations.</p>
+ </div>
+ </section>
+
+ <section id="sec-setarraybufferdata">
+ <h1><span class="secnum" id="sec-24.1.1.3"><a href="#sec-setarraybufferdata"
+ title="link to this section">24.1.1.3</a></span> SetArrayBufferData( arrayBuffer, bytes )</h1>
+
+ <p>The abstract operation SetArrayBufferData with arguments <span style="font-family: Times New Roman"><i>arrayBuffer</i>
+ and <i>bytes</i></span> is used to initialize the storage block encapsulated by an ArrayBuffer object. It performs the
+ following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>arrayBuffer</i>).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>arrayBuffer</i>) is Object and it has an
+ [[ArrayBufferData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>bytes</i> is a positive integer.</li>
+ <li>Let <i>block</i> be <a href="#sec-createbytedatablock">CreateByteDataBlock</a>(<i>bytes</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>block</i>).</li>
+ <li>Set <i>arrayBuffer’s</i> [[ArrayBufferData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to <i>block</i>.</li>
+ <li>Set <i>arrayBuffer</i>’s [[ArrayBufferByteLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to <i>bytes</i>.</li>
+ <li>Return <i>arrayBuffer</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-clonearraybuffer">
+ <h1><span class="secnum" id="sec-24.1.1.4"><a href="#sec-clonearraybuffer"
+ title="link to this section">24.1.1.4</a></span> CloneArrayBuffer( srcBuffer, srcByteOffset )</h1>
+
+ <p>The abstract operation <span style="font-family: Times New Roman">CloneArrayBuffer</span> takes two parameters, an
+ ArrayBuffer <var>srcBuffer</var> and an integer <var>srcByteOffset</var>. It creates a new ArrayBufer whose data is a copy
+ of <var>srcBuffer’s</var> data starting at <var>srcByteOffset</var>. This operation performs the following
+ steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>srcBuffer</i>) is Object and it has an [[ArrayBufferData]]
+ <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>srcBlock</i> be the value of <i>srcBuffer’s</i> [[ArrayBufferData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>srcBlock</i> is <b>undefined</b> or <b>null</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>srcLength</i> be the value of <i>srcBuffer</i>’s [[ArrayBufferByteLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>bufferConstructor</i> be <a href="#sec-get-o-p">Get</a>(<i>srcBuffer</i>, <code>"constructor"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>bufferConstructor</i>).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>srcByteOffset</i> ≤ <i>srcLength</i>.</li>
+ <li>Let <i>cloneLength</i> be <i>srcLength</i> – <i>srcByteOffset.</i></li>
+ <li>If <i>bufferConstructor</i> is <b>undefined</b>, then let <i>bufferConstructor</i> be %ArrayBuffer%.</li>
+ <li>Let <i>targetBuffer</i> be <a
+ href="#sec-allocatearraybuffer">AllocateArrayBuffer</a>(<i>bufferConstructor</i>).</li>
+ <li>Let <i>status</i> be <a href="#sec-setarraybufferdata">SetArrayBufferData</a>(<i>targetBuffer</i>,
+ <i>cloneLength</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Let <i>targetBlock</i> be the value of <i>targetBuffer’s</i> [[ArrayBufferData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Perform <a href="#sec-copydatablockbytes">CopyDataBlockBytes</a>(<i>targetBlock</i>, 0, <i>srcBlock</i>,
+ <i>srcByteOffset</i>, <i>cloneLength</i>).</li>
+ <li>Return <i>targetBuffer</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-getvaluefrombuffer">
+ <h1><span class="secnum" id="sec-24.1.1.5"><a href="#sec-getvaluefrombuffer"
+ title="link to this section">24.1.1.5</a></span> GetValueFromBuffer ( arrayBuffer, byteIndex, type, isLittleEndian
+ )</h1>
+
+ <p>The abstract operation <span style="font-family: Times New Roman">GetValueFromBuffer</span> takes four parameters, an
+ ArrayBuffer <var>arrayBuffer</var>, an integer <var>byteIndex</var>, a String <var>type</var>, and optionally a Boolean
+ <var>isLittleEndian</var>. This operation performs the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: There are sufficient bytes in <i>arrayBuffer</i> starting at
+ <i>byteIndex</i> to represent a value of <i>type</i>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>byteIndex</i> is a positive integer.</li>
+ <li>Let <i>block</i> be <i>arrayBuffer’s</i> [[ArrayBufferData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>block</i> is <b>undefined</b> or <b>null</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>elementSize</i> be the Number value of the Element Size value specified in <a href="#table-44">Table 44</a>
+ for Element Type <i>type</i>.</li>
+ <li>Let <i>rawValue</i> be a <a href="#sec-list-and-record-specification-type">List</a> of <i>elementSize containing, in
+ order,</i> the <i>elementSize</i> bytes starting at <i>byteIndex</i> of <i>block</i>.</li>
+ <li>If <i>isLittleEndian</i> is not present, set <i>isLittleEndian</i> to either <b>true</b> or <b>false</b>. The choice
+ is implementation dependent and should be the alternative that is most efficient for the implementation. An
+ implementation must use the same value each time this step is executed and the same value must be used for the
+ corresponding step in the <a href="#sec-setvalueinbuffer">SetValueInBuffer</a> abstract operation.</li>
+ <li>If <i>isLittleEndian</i> is <b>false</b>, reverse the order of the elements of <i>rawValue</i>.</li>
+ <li>If <i>type</i> is “Float32” , then
+ <ol class="block">
+ <li>Let <i>value</i> be the byte elements of <i>rawValue</i> concatenated and interpreted as a little-endian bit
+ string encoding of an IEEE 754-2008 binary32 value.</li>
+ <li>If <i>value</i> is an IEEE 754-2008 binary32 NaN value, return the <b>NaN</b> Number value.</li>
+ <li>Return the Number value that corresponds to <i>value</i>.</li>
+ </ol>
+ </li>
+ <li>If <i>type</i> is “Float64” , then
+ <ol class="block">
+ <li>Let <i>value</i> be the byte elements of <i>rawValue</i> concatenated and interpreted as a little-endian bit
+ string encoding of an IEEE 754-2008 binary64 value.</li>
+ <li>If <i>value</i> is an IEEE 754-2008 binary64 NaN value, return the <b>NaN</b> Number value.</li>
+ <li>Return the Number value that corresponds to <i>value</i>.</li>
+ </ol>
+ </li>
+ <li>If the first character of <i>type</i> is <code>"U"</code>, then
+ <ol class="block">
+ <li>Let <i>intValue</i> be the byte elements of <i>rawValue</i> concatenated and interpreted as a bit string
+ encoding of an unsigned little-endian binary number.</li>
+ </ol>
+ </li>
+ <li>Else
+ <ol class="block">
+ <li>Let <i>intValue</i> be the byte elements of <i>rawValue</i> concatenated and interpreted as a bit string
+ encoding of a binary little-endian 2’s complement number of bit length <i>elementSize</i> × 8.</li>
+ </ol>
+ </li>
+ <li>Return the Number value that corresponds to <i>intValue</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-setvalueinbuffer">
+ <h1><span class="secnum" id="sec-24.1.1.6"><a href="#sec-setvalueinbuffer"
+ title="link to this section">24.1.1.6</a></span> SetValueInBuffer ( arrayBuffer, byteIndex, type, value,
+ isLittleEndian )</h1>
+
+ <p>The abstract operation <span style="font-family: Times New Roman">SetValueInBuffer</span> takes five parameters, an
+ ArrayBuffer <var>arrayBuffer</var>, an integer <var>byteIndex</var>, a String <var>type</var>, a Number <i>value</i>, and
+ optionally a Boolean <var>isLittleEndian</var>. This operation performs the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: There are sufficient bytes in <i>arrayBuffer</i> starting at
+ <i>byteIndex</i> to represent a value of <i>type</i>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>byteIndex</i> is a positive integer.</li>
+ <li>Let <i>block</i> be <i>arrayBuffer’s</i> [[ArrayBufferData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>block</i> is <b>undefined</b> or <b>null</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>elementSize</i> be the Number value of the Element Size specified in <a href="#table-44">Table 44</a> for
+ Element Type <i>type</i>.</li>
+ <li>If <i>isLittleEndian</i> is not present, set <i>isLittleEndian</i> to either <b>true</b> or <b>false</b>. The choice
+ is implementation dependent and should be the alternative that is most efficient for the implementation. An
+ implementation must use the same value each time this step is executed and the same value must be used for the
+ corresponding step in the <a href="#sec-getvaluefrombuffer">GetValueFromBuffer</a> abstract operation.</li>
+ <li>If <i>type</i> is “Float32” , then
+ <ol class="block">
+ <li>Set <i>rawValue</i> to a <a href="#sec-list-and-record-specification-type">List</a> containing the 4 bytes that
+ are the result of converting <i>value</i> to IEEE-868-2008 binary32 format using “Round to nearest, ties
+ to even” rounding mode. If <i>isLittleEndian</i> is <b>false</b>, the bytes are arranged in big endian
+ order. Otherwise, the bytes are arranged in little endian order. If <i>value</i> is <b>NaN</b>, <i>rawValue</i>
+ may be set to any implementation choosen non-signaling NaN encoding.</li>
+ </ol>
+ </li>
+ <li>Else, if <i>type</i> is “Float64” , then
+ <ol class="block">
+ <li>Set <i>rawValue</i> to a <a href="#sec-list-and-record-specification-type">List</a> containing the 8 bytes that
+ are the IEEE-868-2008 binary64 format encoding of <i>value</i>. If <i>isLittleEndian</i> is <b>false</b>, the
+ bytes are arranged in big endian order. Otherwise, the bytes are arranged in little endian order. If
+ <i>value</i> is <b>NaN</b>, <i>rawValue</i> may be set to any implementation choosen non-signaling NaN
+ encoding.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>n</i> be the Element Size value in <a href="#table-44">Table 44</a> for the row containing the value of
+ <i>type</i> as its Element Type entry.</li>
+ <li>Let <i>convOp</i> be the abstract operation named in the Conversion Operation column in <a
+ href="#table-44">Table 44</a> for Element Type <i>type</i>.</li>
+ <li>Let <i>intValue</i> be the result of calling <i>convOp</i> with <i>value</i> as its argument .</li>
+ <li>If <i>intValue</i> ≥ 0, then
+ <ol class="block">
+ <li>Let <i>rawBytes</i> be a <a href="#sec-list-and-record-specification-type">List</a> containing the
+ <i>n</i>-byte binary encoding of <i>intValue</i>. If <i>isLittleEndian</i> is <b>false</b>, the bytes are
+ ordered in big endian order. Otherwise, the bytes are ordered in little endian order.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>rawBytes</i> be a <a href="#sec-list-and-record-specification-type">List</a> containing the
+ <i>n</i>-byte binary 2’s complement encoding of <i>intValue</i>. If <i>isLittleEndian</i> is
+ <b>false</b>, the bytes are ordered in big endian order. Otherwise, the bytes are ordered in little endian
+ order.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Store the individual bytes of <i>rawBytes</i> in order starting at position <i>byteIndex</i> of <i>block</i>.</li>
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a> (<b>undefined</b>).</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-arraybuffer-constructor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-24.1.2"><a href="#sec-arraybuffer-constructor"
+ title="link to this section">24.1.2</a></span> The ArrayBuffer Constructor</h1>
+
+ <p>The ArrayBuffer constructor is the %ArrayBuffer% intrinsic object and the initial value of the <code>ArrayBuffer</code>
+ property of the global object. When <code>ArrayBuffer</code> is called as a function rather than as a constructor, its
+ <b>this</b> value must be an Object with an [[ArrayBufferData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> whose value is <span
+ class="value">undefined.</span> The ArrayBuffer constructor initializes the <b>this</b> value using the argument
+ values.</p>
+
+ <p>The <code>ArrayBuffer</code> constructor is designed to be subclassable. It may be used as the value of an
+ <code>extends</code> clause of a class declaration. Subclass constructors that intended to inherit the specified
+ <code>ArrayBuffer</code> behaviour must include a <code>super</code> call to the <code>ArrayBuffer</code> constructor to
+ initialize subclass instances.</p>
+ </div>
+
+ <section id="sec-arraybuffer-length">
+ <h1><span class="secnum" id="sec-24.1.2.1"><a href="#sec-arraybuffer-length"
+ title="link to this section">24.1.2.1</a></span> ArrayBuffer( length )</h1>
+
+ <p>ArrayBuffer called as function with argument <var>length</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object or if <i>O</i> does not have an
+ [[ArrayBufferData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> or if the value of
+ <i>O’s</i> [[ArrayBufferData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is
+ not <b>undefined</b>, then
+ <ol class="block">
+ <li>Throw a <b>TypeError</b> exception.</li>
+ </ol>
+ </li>
+ <li>Let <i>numberLength</i> be <a href="#sec-tonumber">ToNumber</a>(<i>length</i>).</li>
+ <li>Let <i>byteLength</i> be <a href="#sec-tolength">ToLength</a>(<i>numberLength</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>byteLength</i>).</li>
+ <li>If <a href="#sec-samevaluezero">SameValueZero</a>(<i>numberLength</i>, <i>byteLength</i>) is <b>false</b>, then
+ throw a <b>RangeError</b> exception.</li>
+ <li>If the value of <i>O’s</i> [[ArrayBufferData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is not <b>undefined</b>, then
+ <ol class="block">
+ <li>Throw a <b>TypeError</b> exception.</li>
+ </ol>
+ </li>
+ <li>Return the result of <a href="#sec-setarraybufferdata">SetArrayBufferData</a>(<i>O</i>, <i>byteLength</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-new-arraybuffer-argumentslist">
+ <h1><span class="secnum" id="sec-24.1.2.2"><a href="#sec-new-arraybuffer-argumentslist"
+ title="link to this section">24.1.2.2</a></span> new ArrayBuffer( ...argumentsList )</h1>
+
+ <p>ArrayBuffer called as part of a new expression performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be the ArrayBuffer function object on which the <code>new</code> operator was applied.</li>
+ <li>Let <i>argumentsList</i> be the <i>argumentsList</i> argument of the [[Construct]] internal method that was invoked
+ by the <code>new</code> operator.</li>
+ <li>Return the result of <a href="#sec-construct-f-argumentslist">Construct</a>(<i>F</i>, <i>argumentsList</i>).</li>
+ </ol>
+
+ <p>If ArrayBuffer is implemented as an <a href="#sec-ecmascript-function-objects">ECMAScript function object</a>, its
+ [[Construct]] internal method will perform the above steps.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-arraybuffer-constructor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-24.1.3"><a href="#sec-properties-of-the-arraybuffer-constructor"
+ title="link to this section">24.1.3</a></span> Properties of the ArrayBuffer Constructor</h1>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the
+ ArrayBuffer constructor is the Function prototype object (<a
+ href="#sec-properties-of-the-function-prototype-object">19.2.3</a>).</p>
+
+ <p>Besides its <code>length</code> property (whose value is 1), the ArrayBuffer constructor has the following
+ properties:</p>
+ </div>
+
+ <section id="sec-arraybuffer.isview">
+ <h1><span class="secnum" id="sec-24.1.3.1"><a href="#sec-arraybuffer.isview"
+ title="link to this section">24.1.3.1</a></span> ArrayBuffer.isView ( arg )</h1>
+
+ <p>The isView function takes one argument <var>arg</var>, and performs the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>arg</i>) is not Object, return <b>false</b>.</li>
+ <li>If <i>arg</i> has a [[ViewedArrayBuffer]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a>, then return <b>true</b>.</li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-arraybuffer.prototype">
+ <h1><span class="secnum" id="sec-24.1.3.2"><a href="#sec-arraybuffer.prototype"
+ title="link to this section">24.1.3.2</a></span> ArrayBuffer.prototype</h1>
+
+ <p>The initial value of ArrayBuffer.prototype is the ArrayBuffer prototype object (<a
+ href="#sec-properties-of-the-arraybuffer-prototype-object">24.1.4</a>).</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-arraybuffer-@@create">
+ <h1><span class="secnum" id="sec-24.1.3.3"><a href="#sec-arraybuffer-@@create"
+ title="link to this section">24.1.3.3</a></span> ArrayBuffer[ @@create ] ( )</h1>
+
+ <p>The @@create method of an ArrayBuffer function object <var>F</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be the <b>this</b> value.</li>
+ <li>Return the result of calling <a href="#sec-allocatearraybuffer">AllocateArrayBuffer</a>(<i>F</i>).</li>
+ </ol>
+
+ <p>The value of the <code>name</code> property of this function is <code>"[Symbol.create]"</code>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <span class="value">false</span>, [[Enumerable]]: <span
+ class="value">false</span>, [[Configurable]]: <span class="value">true</span> }.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-arraybuffer-prototype-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-24.1.4"><a href="#sec-properties-of-the-arraybuffer-prototype-object"
+ title="link to this section">24.1.4</a></span> Properties of the ArrayBuffer Prototype Object</h1>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the
+ ArrayBuffer prototype object is the standard built-in Object prototype object (<a
+ href="#sec-properties-of-the-object-prototype-object">19.1.3</a>). The ArrayBuffer prototype object is an ordinary object.
+ It does not have an [[ArrayBufferData]] or [[ArrayBufferByteLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</p>
+ </div>
+
+ <section id="sec-get-arraybuffer.prototype.bytelength">
+ <h1><span class="secnum" id="sec-24.1.4.1"><a href="#sec-get-arraybuffer.prototype.bytelength"
+ title="link to this section">24.1.4.1</a></span> get ArrayBuffer.prototype.byteLength</h1>
+
+ <p><code>ArrayBuffer.prototype.byteLength</code> is an accessor property whose set accessor function is <span
+ class="value">undefined</span>. Its get accessor function performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object, throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>O</i> does not have an [[ArrayBufferData]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> throw a <b>TypeError</b> exception.</li>
+ <li>If the value of <i>O</i>’s [[ArrayBufferData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is <b>undefined</b> or <b>null</b>, then
+ throw a <b>TypeError</b> exception.</li>
+ <li>If the value of <i>O</i>’s [[ArrayBufferData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is <b>null</b>, then return 0.</li>
+ <li>Let <i>length</i> be the value of <i>O</i>’s [[ArrayBufferByteLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Return <i>length</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-arraybuffer.prototype.constructor">
+ <h1><span class="secnum" id="sec-24.1.4.2"><a href="#sec-arraybuffer.prototype.constructor"
+ title="link to this section">24.1.4.2</a></span> ArrayBuffer.prototype.constructor</h1>
+
+ <p>The initial value of ArrayBuffer.prototype.constructor is the standard built-in ArrayBuffer constructor.</p>
+ </section>
+
+ <section id="sec-arraybuffer.prototype.slice">
+ <h1><span class="secnum" id="sec-24.1.4.3"><a href="#sec-arraybuffer.prototype.slice"
+ title="link to this section">24.1.4.3</a></span> ArrayBuffer.prototype.slice ( start , end )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object, throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>O</i> does not have an [[ArrayBufferData]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> throw a <b>TypeError</b> exception.</li>
+ <li>If the value of <i>O</i>’s [[ArrayBufferData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is <b>undefined</b> or <b>null</b>, then
+ throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>len</i> be the value of <i>O</i>’s [[ArrayBufferByteLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>relativeStart</i> be <a href="#sec-tointeger">ToInteger</a>(<i>start</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>relativeStart</i>).</li>
+ <li>If <i>relativeStart</i> is negative, let <i>first</i> be max((<i>len</i> + <i>relativeStart</i>),0); else let
+ <i>first</i> be min(<i>relativeStart</i>, <i>len</i>).</li>
+ <li>If <i>end</i> is <b>undefined</b>, let <i>relativeEnd</i> be <i>len</i>; else let <i>relativeEnd</i> be <a
+ href="#sec-tointeger">ToInteger</a>(<i>end</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>relativeEnd</i>).</li>
+ <li>If <i>relativeEnd</i> is negative, let <i>final</i> be max((<i>len</i> + <i>relativeEnd</i>),0); else let
+ <i>final</i> be min(<i>relativeEnd</i>, <i>len</i>).</li>
+ <li>Let <i>newLen</i> be max(<i>final</i>-<i>first</i>,0).</li>
+ <li>Let <i>ctor</i> be the result of <a href="#sec-get-o-p">Get</a>(<i>O</i>, <b>"<code>constructor</code>"</b>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>ctor</i>).</li>
+ <li>If <a href="#sec-isconstructor">IsConstructor</a>(<i>ctor</i>) is <b>false</b>, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>Let <i>new</i> be the result of calling the [[Construct]] internal method of <i>ctor</i> with a new <a
+ href="#sec-list-and-record-specification-type">List</a> containing the single element <i>newLen</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>new</i>).</li>
+ <li>If <i>new</i> does not have an [[ArrayBufferData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> throw a <b>TypeError</b> exception.</li>
+ <li>If the value of <i>new</i>’s [[ArrayBufferData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is <b>undefined</b>, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>If the value of <i>new</i>’s [[ArrayBufferByteLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> < <i>newLen</i>, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>Let <i>fromBuf</i> be the value of <i>O</i>’s [[ArrayBufferData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>toBuf</i> be the value of <i>new</i>’s [[ArrayBufferData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Perform <a href="#sec-copydatablockbytes">CopyDataBlockBytes</a>(<i>toBuf</i>, 0, <i>fromBuf</i>, <i>first</i>,
+ <i>newLen</i>).</li>
+ <li>Return <i>new</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-arraybuffer.prototype-@@tostringtag">
+ <h1><span class="secnum" id="sec-24.1.4.4"><a href="#sec-arraybuffer.prototype-@@tostringtag"
+ title="link to this section">24.1.4.4</a></span> ArrayBuffer.prototype [ @@toStringTag ]</h1>
+
+ <p>The initial value of the @@toStringTag property is the string value <b>"<code>ArrayBuffer</code>"</b>.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-arraybuffer-instances">
+ <h1><span class="secnum" id="sec-24.1.5"><a href="#sec-properties-of-the-arraybuffer-instances"
+ title="link to this section">24.1.5</a></span> Properties of the ArrayBuffer Instances</h1>
+
+ <p>ArrayBuffer instances inherit properties from the ArrayBuffer prototype object. ArrayBuffer instances each have an
+ [[ArrayBufferData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> and an
+ [[ArrayBufferByteLength]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</p>
+
+ <p>ArrayBuffer instances whose [[ArrayBufferData]] is <b>null</b> are considered to be <i>neutered</i> and all operators to
+ access or modify data contained in the ArrayBuffer instance will fail.</p>
+ </section>
+ </section>
+
+ <section id="sec-dataview-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-24.2"><a href="#sec-dataview-objects" title="link to this section">24.2</a></span> DataView
+ Objects</h1>
+ </div>
+
+ <section id="sec-abstract-operations-for-dataview-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-24.2.1"><a href="#sec-abstract-operations-for-dataview-objects"
+ title="link to this section">24.2.1</a></span> Abstract Operations For DataView Objects</h1>
+ </div>
+
+ <section id="sec-getviewvalue">
+ <h1><span class="secnum" id="sec-24.2.1.1"><a href="#sec-getviewvalue" title="link to this section">24.2.1.1</a></span>
+ GetViewValue ( view, requestIndex, isLittleEndian, type )</h1>
+
+ <p>The abstract operation GetViewValue with arguments <var>view</var>, <var>requestIndex</var>, <var>isLittleEndian</var>,
+ and <var>type</var> is used by functions on DataView instances is to retrieve values from the view’s buffer. It
+ performs the following steps:</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>view</i>) is not Object, throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>view</i> does not have a [[DataView]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>buffer</i> be the value of <i>view’s</i> [[ViewedArrayBuffer]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>buffer</i> is <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>numberIndex</i> be <a href="#sec-tonumber">ToNumber</a>(<i>requestIndex</i>)</li>
+ <li>Let <i>getIndex</i> be <a href="#sec-tointeger">ToInteger</a>(<i>numberIndex</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>getIndex</i>).</li>
+ <li>If <i>numberIndex</i> ≠ <i>getIndex</i> or <i>getIndex</i> < 0, then throw a <b>RangeError</b> exception.</li>
+ <li>Let <i>isLittleEndian</i> be <a href="#sec-toboolean">ToBoolean</a>(<i>isLittleEndian</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>isLittleEndian</i>).</li>
+ <li>Let <i>viewOffset</i> be the value of <i>view’s</i> [[ByteOffset]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>viewSize</i> be the value of <i>view’s</i> [[ByteLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>elementSize</i> be the Number value of the Element Size value specified in <a href="#table-44">Table 44</a>
+ for <i>type</i>.</li>
+ <li>If <i>getIndex</i> +<i>elementSize</i> > <i>viewSize</i>, then throw a <b>RangeError</b> exception.</li>
+ <li>Let <i>bufferIndex</i> be <i>getIndex</i> + <i>viewOffset</i>.</li>
+ <li>Return the result of <a href="#sec-getvaluefrombuffer">GetValueFromBuffer</a>(<i>buffer</i>, <i>bufferIndex</i>,
+ <i>type</i>, <i>isLittleEndian</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-setviewvalue">
+ <h1><span class="secnum" id="sec-24.2.1.2"><a href="#sec-setviewvalue" title="link to this section">24.2.1.2</a></span>
+ SetViewValue ( view, requestIndex, isLittleEndian, type, value )</h1>
+
+ <p>The abstract operation SetViewValue with arguments <var>view</var>, <var>requestIndex</var>, <var>isLittleEndian</var>,
+ <var>type</var>, and <var>value</var> is used by functions on DataView instances to store values into the view’s
+ buffer. It performs the following steps:</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>view</i>) is not Object, throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>view</i> does not have a [[DataView]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>buffer</i> be the value of <i>view’s</i> [[ViewedArrayBuffer]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>buffer</i> is <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>numberIndex</i> be <a href="#sec-tonumber">ToNumber</a>(<i>requestIndex</i>)</li>
+ <li>Let <i>getIndex</i> be <a href="#sec-tointeger">ToInteger</a>(<i>numberIndex</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>getIndex</i>).</li>
+ <li>If <i>numberIndex</i> ≠ <i>getIndex</i> or <i>getIndex</i> < 0, then throw a <b>RangeError</b> exception.</li>
+ <li>Let <i>isLittleEndian</i> be <a href="#sec-toboolean">ToBoolean</a>(<i>isLittleEndian</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>isLittleEndian</i>).</li>
+ <li>Let <i>viewOffset</i> be the value of <i>view’s</i> [[ByteOffset]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>viewSize</i> be the value of <i>view’s</i> [[ByteLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>elementSize</i> be the Number value of the Element Size value specified in <a href="#table-44">Table 44</a>
+ for <i>type</i>.</li>
+ <li>If <i>getIndex</i> +<i>elementSize</i> > <i>viewSize</i>, then throw a <b>RangeError</b> exception.</li>
+ <li>Let <i>bufferIndex</i> be <i>getIndex</i> + <i>viewOffset</i>.</li>
+ <li>Return the result of <a href="#sec-setvalueinbuffer">SetValueInBuffer</a>(<i>buffer</i>, <i>bufferIndex</i>,
+ <i>type</i>, <i>value</i>, <i>isLittleEndian</i>).</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The algorithms for <a href="#sec-getviewvalue">GetViewValue</a> and SetViewValue are
+ identical except for their final steps.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-dataview-constructor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-24.2.2"><a href="#sec-dataview-constructor"
+ title="link to this section">24.2.2</a></span> The DataView Constructor</h1>
+
+ <p>The DataView constructor is the %DataView% intrinsic object and the initial value of the <code>DataView</code> property
+ of the global object. When <code>DataView</code> is called as a function rather than as a constructor, it initializes its
+ <b>this</b> value with the internal state necessary to support the <code><a
+ href="#sec-dataview.prototype">DataView.prototype</a></code> internal methods.</p>
+
+ <p>The <code>DataView</code> constructor is designed to be subclassable. It may be used as the value of an
+ <code>extends</code> clause of a class declaration. Subclass constructors that intended to inherit the specified
+ <code>DataView</code> behaviour must include a <code>super</code> call to the <code>DataView</code> constructor to
+ initialize subclass instances.</p>
+ </div>
+
+ <section id="sec-dataview-buffer-byteoffset-bytelength">
+ <h1><span class="secnum" id="sec-24.2.2.1"><a href="#sec-dataview-buffer-byteoffset-bytelength"
+ title="link to this section">24.2.2.1</a></span> DataView (buffer [ , byteOffset [ , byteLength ] ] )</h1>
+
+ <p><code>DataView</code> called with arguments <span style="font-family: Times New Roman"><i>buffer</i>,
+ <i>byteOffset</i>, and <i>length</i></span> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object or if <i>O</i> does not have a
+ [[DataView]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, throw a <b>TypeError</b>
+ exception.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>O</i> has a [[ViewedArrayBuffer]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If the value of <i>O’s</i> [[ViewedArrayBuffer]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is not <b>undefined</b>, then
+ <ol class="block">
+ <li>Throw a <b>TypeError</b> exception.</li>
+ </ol>
+ </li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>buffer</i>) is not Object, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>If <i>buffer</i> does not have an [[ArrayBufferData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>If the value of <i>buffer</i>’s [[ArrayBufferData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is <b>undefined</b>, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>Let <i>numberOffset</i> be <a href="#sec-tonumber">ToNumber</a>(<i>byteOffset</i>).</li>
+ <li>Let <i>offset</i> be <a href="#sec-tointeger">ToInteger</a>(<i>numberOffset</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>offset</i>).</li>
+ <li>If <i>numberOffset</i> ≠ <i>offset</i> or <i>offset</i> < 0, then throw a <b>RangeError</b> exception.</li>
+ <li>Let <i>bufferByteLength</i> be the value of <i>buffer’s</i> [[ArrayBufferByteLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>offset</i> > <i>bufferByteLength</i>, then throw a <b>RangeError</b> exception.</li>
+ <li>If <i>byteLength</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>viewByteLength</i> be <i>bufferByteLength</i> – <i>offset</i>.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>numberLength</i> be <a href="#sec-tonumber">ToNumber</a>(<i>byteLength</i>).</li>
+ <li>Let <i>viewLength</i> be <a href="#sec-tointeger">ToInteger</a> (<i>numberLength).</i></li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>viewLength</i>).</li>
+ <li>If <i>numberLength</i> ≠ <i>viewLength</i> or <i>viewLength</i> < 0, then throw a <b>RangeError</b>
+ exception.</li>
+ <li>Let <i>viewByteLength</i> be <i>viewLength</i>.</li>
+ <li>If <i>offset</i>+<i>viewByteLength</i> > <i>bufferByteLength</i>, then throw a <b>RangeError</b>
+ exception.</li>
+ </ol>
+ </li>
+ <li>If the value of <i>O’s</i> [[ViewedArrayBuffer]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is not <b>undefined</b>, then throw a
+ <b>TypeError</b> exception,</li>
+ <li>Set <i>O’s</i> [[ViewedArrayBuffer]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> to <i>buffer</i>.</li>
+ <li>Set <i>O</i>’s [[ByteLength]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to
+ <i>viewByteLength</i>.</li>
+ <li>Set <i>O</i>’s [[ByteOffset]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to
+ <i>offset</i>.</li>
+ <li>Return <i>O</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-new-dataview-argumentslist">
+ <h1><span class="secnum" id="sec-24.2.2.2"><a href="#sec-new-dataview-argumentslist"
+ title="link to this section">24.2.2.2</a></span> new DataView ( ...argumentsList )</h1>
+
+ <p>When <code>DataView</code> is called as part of a new expression it performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be the function object on which the <code>new</code> operator was applied.</li>
+ <li>Let <i>argumentsList</i> be the <i>argumentsList</i> argument of the [[Construct]] internal method that was invoked
+ by the <code>new</code> operator.</li>
+ <li>Return the result of <a href="#sec-construct-f-argumentslist">Construct</a>(<i>F</i>, <i>argumentsList</i>).</li>
+ </ol>
+
+ <p>If <code>DataView</code> is implemented as an <a href="#sec-ecmascript-function-objects">ECMAScript function
+ object</a>, its [[Construct]] internal method will perform the above steps.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-dataview-constructor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-24.2.3"><a href="#sec-properties-of-the-dataview-constructor"
+ title="link to this section">24.2.3</a></span> Properties of the DataView Constructor</h1>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the
+ <code>DataView</code> constructor is the <code>Function</code> prototype object (<a
+ href="#sec-properties-of-the-function-prototype-object">19.2.3</a>).</p>
+
+ <p>Besides the <code>length</code> <code>property</code> (whose value is 3), the DataView constructor has the following
+ properties:</p>
+ </div>
+
+ <section id="sec-dataview.prototype">
+ <h1><span class="secnum" id="sec-24.2.3.1"><a href="#sec-dataview.prototype"
+ title="link to this section">24.2.3.1</a></span> DataView.prototype</h1>
+
+ <p>The initial value of <code>DataView.prototype</code> is the DataView prototype object (<a
+ href="#sec-properties-of-the-dataview-prototype-object">24.2.4</a>).</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-dataview-@@create">
+ <h1><span class="secnum" id="sec-24.2.3.2"><a href="#sec-dataview-@@create"
+ title="link to this section">24.2.3.2</a></span> DataView [ @@create ] ( )</h1>
+
+ <p>The @@create method of a DataView function object <var>F</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be the <b>this</b> value.</li>
+ <li>Let <i>obj</i> be the result of calling <a
+ href="#sec-ordinarycreatefromconstructor">OrdinaryCreateFromConstructor</a>(<i>F</i>,
+ <code>"%DataViewPrototype%"</code>, ( [[DataView]], [[ViewedArrayBuffer]], [[ByteLength]], [[ByteOffset]]) ).</li>
+ <li>Set the value of <i>obj’s</i> [[DataView]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> to <b>true</b>.</li>
+ <li>Return <i>obj</i>.</li>
+ </ol>
+
+ <p>The value of the <code>name</code> property of this function is <code>"[Symbol.create]"</code>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>true</b> }.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The value of the [[DataView]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is not used within this specification. The
+ simple presense of that <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is used within the
+ specification to identify objects created using this @@create method.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-dataview-prototype-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-24.2.4"><a href="#sec-properties-of-the-dataview-prototype-object"
+ title="link to this section">24.2.4</a></span> Properties of the DataView Prototype Object</h1>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the
+ DataView prototype object is the standard built-in Object prototype object (<a
+ href="#sec-properties-of-the-object-prototype-object">19.1.3</a>). The DataView prototype object is an ordinary object. It
+ does not have a [[DataView]], [[ViewedArrayBuffer]], [[ByteLength]], or [[ByteOffset]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</p>
+ </div>
+
+ <section id="sec-get-dataview.prototype.buffer">
+ <h1><span class="secnum" id="sec-24.2.4.1"><a href="#sec-get-dataview.prototype.buffer"
+ title="link to this section">24.2.4.1</a></span> get DataView.prototype.buffer</h1>
+
+ <p><code>DataView.prototype.buffer</code> is an accessor property whose set accessor function is <span
+ class="value">undefined</span>. Its get accessor function performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object, throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>O</i> does not have a [[ViewedArrayBuffer]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>buffer</i> be the value of <i>O</i>’s [[ViewedArrayBuffer]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>buffer</i> is <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Return <i>buffer</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-get-dataview.prototype.bytelength">
+ <h1><span class="secnum" id="sec-24.2.4.2"><a href="#sec-get-dataview.prototype.bytelength"
+ title="link to this section">24.2.4.2</a></span> get DataView.prototype.byteLength</h1>
+
+ <p><code>DataView</code>.<code>prototype.byteLength</code> is an accessor property whose set accessor function is <span
+ class="value">undefined</span>. Its get accessor function performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object, throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>O</i> does not have a [[ViewedArrayBuffer]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>buffer</i> be the value of <i>O</i>’s [[ViewedArrayBuffer]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>buffer</i> is <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>size</i> be the value of <i>O</i>’s [[ByteLength]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Return <i>size</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-get-dataview.prototype.byteoffset">
+ <h1><span class="secnum" id="sec-24.2.4.3"><a href="#sec-get-dataview.prototype.byteoffset"
+ title="link to this section">24.2.4.3</a></span> get DataView.prototype.byteOffset</h1>
+
+ <p><code>DataView</code>.<code>prototype.byteOffset</code> is an accessor property whose set accessor function is <span
+ class="value">undefined</span>. Its get accessor function performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object, throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>O</i> does not have a [[ViewedArrayBuffer]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>buffer</i> be the value of <i>O</i>’s [[ViewedArrayBuffer]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>buffer</i> is <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>offset</i> be the value of <i>O</i>’s [[ByteOffset]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Return <i>offset</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-dataview.prototype.constructor">
+ <h1><span class="secnum" id="sec-24.2.4.4"><a href="#sec-dataview.prototype.constructor"
+ title="link to this section">24.2.4.4</a></span> DataView.prototype.constructor</h1>
+
+ <p>The initial value of <code>DataView.prototype.constructor</code> is the standard built-in DataView constructor.</p>
+ </section>
+
+ <section id="sec-dataview.prototype.getfloat32">
+ <h1><span class="secnum" id="sec-24.2.4.5"><a href="#sec-dataview.prototype.getfloat32"
+ title="link to this section">24.2.4.5</a></span> DataView.prototype.getFloat32 ( byteOffset [ , littleEndian ] )</h1>
+
+ <p>When the <code>getFloat32</code> method is called with argument <var>byteOffset</var> and optional argument
+ <i>littleEndian</i> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>v</i> be the <b>this</b> value.</li>
+ <li>If <i>littleEndian</i> is not present, then let <i>littleEndian</i> be <b>false</b>.</li>
+ <li>Return the result of <a href="#sec-getviewvalue">GetViewValue</a>(<i>v</i>, <i>byteOffset</i>, <i>littleEndian</i>,
+ <code>"Float32"</code>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-dataview.prototype.getfloat64">
+ <h1><span class="secnum" id="sec-24.2.4.6"><a href="#sec-dataview.prototype.getfloat64"
+ title="link to this section">24.2.4.6</a></span> DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] )</h1>
+
+ <p>When the <code>getFloat64</code> method is called with argument <var>byteOffset</var> and optional argument
+ <i>littleEndian</i> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>v</i> be the <b>this</b> value.</li>
+ <li>If <i>littleEndian</i> is not present, then let <i>littleEndian</i> be <b>false</b>.</li>
+ <li>Return the result of <a href="#sec-getviewvalue">GetViewValue</a>(<i>v</i>, <i>byteOffset</i>, <i>littleEndian</i>,
+ <code>"Float64"</code>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-dataview.prototype.getint8">
+ <h1><span class="secnum" id="sec-24.2.4.7"><a href="#sec-dataview.prototype.getint8"
+ title="link to this section">24.2.4.7</a></span> DataView.prototype.getInt8 ( byteOffset )</h1>
+
+ <p>When the <code>getInt8</code> method is called with argument <var>byteOffset</var> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>v</i> be the <b>this</b> value.</li>
+ <li>Return the result of <a href="#sec-getviewvalue">GetViewValue</a>(<i>v</i>, <i>byteOffset</i>, <b>true</b>,
+ <code>"Int8"</code>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-dataview.prototype.getint16">
+ <h1><span class="secnum" id="sec-24.2.4.8"><a href="#sec-dataview.prototype.getint16"
+ title="link to this section">24.2.4.8</a></span> DataView.prototype.getInt16 ( byteOffset [ , littleEndian ] )</h1>
+
+ <p>When the <code>getInt16</code> method is called with argument <var>byteOffset</var> and optional argument
+ <i>littleEndian</i> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>v</i> be the <b>this</b> value.</li>
+ <li>If <i>littleEndian</i> is not present, then let <i>littleEndian</i> be <b>false</b>.</li>
+ <li>Return the result of <a href="#sec-getviewvalue">GetViewValue</a>(<i>v</i>, <i>byteOffset</i>, <i>littleEndian</i>,
+ <code>"Int16"</code>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-dataview.prototype.getint32">
+ <h1><span class="secnum" id="sec-24.2.4.9"><a href="#sec-dataview.prototype.getint32"
+ title="link to this section">24.2.4.9</a></span> DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] )</h1>
+
+ <p>When the <code>getInt32</code> method is called with argument <var>byteOffset</var> and optional argument
+ <i>littleEndian</i> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>v</i> be the <b>this</b> value.</li>
+ <li>If <i>littleEndian</i> is not present, then let <i>littleEndian</i> be <b>undefined</b>.</li>
+ <li>Return the result of <a href="#sec-getviewvalue">GetViewValue</a>(<i>v</i>, <i>byteOffset</i>, <i>littleEndian</i>,
+ <code>"Int32"</code>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-dataview.prototype.getuint8">
+ <h1><span class="secnum" id="sec-24.2.4.10"><a href="#sec-dataview.prototype.getuint8"
+ title="link to this section">24.2.4.10</a></span> DataView.prototype.getUint8 ( byteOffset )</h1>
+
+ <p>When the <code>getUint8</code> method is called with argument <var>byteOffset</var> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>v</i> be the <b>this</b> value.</li>
+ <li>Return the result of <a href="#sec-getviewvalue">GetViewValue</a>(<i>v</i>, <i>byteOffset</i>, <b>true</b>,
+ <code>"Uint8"</code>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-dataview.prototype.getuint16">
+ <h1><span class="secnum" id="sec-24.2.4.11"><a href="#sec-dataview.prototype.getuint16"
+ title="link to this section">24.2.4.11</a></span> DataView.prototype.getUint16 ( byteOffset [ , littleEndian ] )</h1>
+
+ <p>When the <code>getUint16</code> method is called with argument <var>byteOffset</var> and optional argument
+ <i>littleEndian</i> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>v</i> be the <b>this</b> value.</li>
+ <li>If <i>littleEndian</i> is not present, then let <i>littleEndian</i> be <b>false</b>.</li>
+ <li>Return the result of <a href="#sec-getviewvalue">GetViewValue</a>(<i>v</i>, <i>byteOffset</i>, <i>littleEndian</i>,
+ <code>"Uint16"</code>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-dataview.prototype.getuint32">
+ <h1><span class="secnum" id="sec-24.2.4.12"><a href="#sec-dataview.prototype.getuint32"
+ title="link to this section">24.2.4.12</a></span> DataView.prototype.getUint32 ( byteOffset [ , littleEndian ] )</h1>
+
+ <p>When the <code>getUint32</code> method is called with argument <var>byteOffset</var> and optional argument
+ <i>littleEndian</i> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>v</i> be the <b>this</b> value.</li>
+ <li>If <i>littleEndian</i> is not present, then let <i>littleEndian</i> be <b>false</b>.</li>
+ <li>Return the result of <a href="#sec-getviewvalue">GetViewValue</a>(<i>v</i>, <i>byteOffset</i>, <i>littleEndian</i>,
+ <code>"Uint32"</code>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-dataview.prototype.setfloat32">
+ <h1><span class="secnum" id="sec-24.2.4.13"><a href="#sec-dataview.prototype.setfloat32"
+ title="link to this section">24.2.4.13</a></span> DataView.prototype.setFloat32 ( byteOffset, value [ , littleEndian ]
+ )</h1>
+
+ <p>When the <code>setFloat32</code> method is called with arguments <var>byteOffset</var> and <var>value</var> and
+ optional argument <i>littleEndian</i> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>v</i> be the <b>this</b> value.</li>
+ <li>If <i>littleEndian</i> is not present, then let <i>littleEndian</i> be <b>false</b>.</li>
+ <li>Return the result of <a href="#sec-setviewvalue">SetViewValue</a>(<i>v</i>, <i>byteOffset</i>, <i>littleEndian</i>,
+ <code>"Float32"</code>, <i>value</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-dataview.prototype.setfloat64">
+ <h1><span class="secnum" id="sec-24.2.4.14"><a href="#sec-dataview.prototype.setfloat64"
+ title="link to this section">24.2.4.14</a></span> DataView.prototype.setFloat64 ( byteOffset, value [ , littleEndian ]
+ )</h1>
+
+ <p>When the <code>setFloat64</code> method is called with arguments <var>byteOffset</var> and <var>value</var> and
+ optional argument <i>littleEndian</i> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>v</i> be the <b>this</b> value.</li>
+ <li>If <i>littleEndian</i> is not present, then let <i>littleEndian</i> be <b>false</b>.</li>
+ <li>Return the result of <a href="#sec-setviewvalue">SetViewValue</a>(<i>v</i>, <i>byteOffset</i>, <i>littleEndian</i>,
+ <code>"Float64"</code>, <i>value</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-dataview.prototype.setint8">
+ <h1><span class="secnum" id="sec-24.2.4.15"><a href="#sec-dataview.prototype.setint8"
+ title="link to this section">24.2.4.15</a></span> DataView.prototype.setInt8 ( byteOffset, value )</h1>
+
+ <p>When the <code>setInt8</code> method is called with arguments <var>byteOffset</var> and <var>value</var> the following
+ steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>v</i> be the <b>this</b> value.</li>
+ <li>Return the result of <a href="#sec-setviewvalue">SetViewValue</a>(<i>v</i>, <i>byteOffset</i>, <b>true</b>,
+ <code>"Int8"</code>, <i>value</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-dataview.prototype.setint16">
+ <h1><span class="secnum" id="sec-24.2.4.16"><a href="#sec-dataview.prototype.setint16"
+ title="link to this section">24.2.4.16</a></span> DataView.prototype.setInt16 ( byteOffset, value [ , littleEndian ]
+ )</h1>
+
+ <p>When the <code>setInt16</code> method is called with arguments <var>byteOffset</var> and <var>value</var> and optional
+ argument <i>littleEndian</i> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>v</i> be the <b>this</b> value.</li>
+ <li>If <i>littleEndian</i> is not present, then let <i>littleEndian</i> be <b>false</b>.</li>
+ <li>Return the result of <a href="#sec-setviewvalue">SetViewValue</a>(<i>v</i>, <i>byteOffset</i>, <i>littleEndian</i>,
+ <code>"Int16"</code>, <i>value</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-dataview.prototype.setint32">
+ <h1><span class="secnum" id="sec-24.2.4.17"><a href="#sec-dataview.prototype.setint32"
+ title="link to this section">24.2.4.17</a></span> DataView.prototype.setInt32 ( byteOffset, value [ , littleEndian ]
+ )</h1>
+
+ <p>When the <code>setInt32</code> method is called with arguments <var>byteOffset</var> and <var>value</var> and optional
+ argument <i>littleEndian</i> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>v</i> be the <b>this</b> value.</li>
+ <li>If <i>littleEndian</i> is not present, then let <i>littleEndian</i> be <b>false</b>.</li>
+ <li>Return the result of <a href="#sec-setviewvalue">SetViewValue</a>(<i>v</i>, <i>byteOffset</i>, <i>littleEndian</i>,
+ <code>"Int32"</code>, <i>value</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-dataview.prototype.setuint8">
+ <h1><span class="secnum" id="sec-24.2.4.18"><a href="#sec-dataview.prototype.setuint8"
+ title="link to this section">24.2.4.18</a></span> DataView.prototype.setUint8 ( byteOffset, value )</h1>
+
+ <p>When the <code>setUint8</code> method is called with arguments <var>byteOffset</var> and <var>value</var> the following
+ steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>v</i> be the <b>this</b> value.</li>
+ <li>Return the result of <a href="#sec-setviewvalue">SetViewValue</a>(<i>v</i>, <i>byteOffset</i>, <b>true</b>,
+ <code>"Uint8"</code>, <i>value</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-dataview.prototype.setuint16">
+ <h1><span class="secnum" id="sec-24.2.4.19"><a href="#sec-dataview.prototype.setuint16"
+ title="link to this section">24.2.4.19</a></span> DataView.prototype.setUint16 ( byteOffset, value [ , littleEndian ]
+ )</h1>
+
+ <p>When the <code>setUint16</code> method is called with arguments <var>byteOffset</var> and <var>value</var> and optional
+ argument <i>littleEndian</i> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>v</i> be the <b>this</b> value.</li>
+ <li>If <i>littleEndian</i> is not present, then let <i>littleEndian</i> be <b>false</b>.</li>
+ <li>Return the result of <a href="#sec-setviewvalue">SetViewValue</a>(<i>v</i>, <i>byteOffset</i>, <i>littleEndian</i>,
+ <code>"Uint16"</code>, <i>value</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-dataview.prototype.setuint32">
+ <h1><span class="secnum" id="sec-24.2.4.20"><a href="#sec-dataview.prototype.setuint32"
+ title="link to this section">24.2.4.20</a></span> DataView.prototype.setUint32 ( byteOffset, value [ , littleEndian ]
+ )</h1>
+
+ <p>When the <code>setUint32</code> method is called with arguments <var>byteOffset</var> and <var>value</var> and optional
+ argument <i>littleEndian</i> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>v</i> be the <b>this</b> value.</li>
+ <li>If <i>littleEndian</i> is not present, then let <i>littleEndian</i> be <b>false</b>.</li>
+ <li>Return the result of <a href="#sec-setviewvalue">SetViewValue</a>(<i>v</i>, <i>byteOffset</i>, <i>littleEndian</i>,
+ <code>"Uint32"</code>, <i>value</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-dataview.prototype-@@tostringtag">
+ <h1><span class="secnum" id="sec-24.2.4.21"><a href="#sec-dataview.prototype-@@tostringtag"
+ title="link to this section">24.2.4.21</a></span> DataView.prototype[ @@toStringTag ]</h1>
+
+ <p>The initial value of the @@toStringTag property is the string value <b>"<code>DataView</code>"</b>.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-dataview-instances">
+ <h1><span class="secnum" id="sec-24.2.5"><a href="#sec-properties-of-dataview-instances"
+ title="link to this section">24.2.5</a></span> Properties of DataView Instances</h1>
+
+ <p>DataView instances are ordinary objects that inherit properties from the DataView prototype object. DataView instances
+ each have a [[DataView]], [[ViewedArrayBuffer]], [[ByteLength]], and [[ByteOffset]] internal slots.</p>
+ </section>
+ </section>
+
+ <section id="sec-json-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-24.3"><a href="#sec-json-object" title="link to this section">24.3</a></span> The JSON
+ Object</h1>
+
+ <p>The <b>JSON</b> object is a single ordinary object that contains two functions, <b>parse</b> and <b>stringify</b>, that
+ are used to parse and construct JSON texts. The JSON Data Interchange Format is defined in ECMA-404. The JSON interchange
+ format used in this specification is exactly that described by ECMA-404.</p>
+
+ <p>Conforming implementations of <b><a href="#sec-json.parse">JSON.parse</a></b> and <b><a
+ href="#sec-json.stringify">JSON.stringify</a></b> must support the exact interchange format described in this specification
+ without any deletions or extensions to the format.</p>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the JSON
+ object is the standard built-in Object prototype object (<a
+ href="#sec-properties-of-the-object-prototype-object">19.1.3</a>). The value of the [[Extensible]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the JSON object is set to <b>true</b>.</p>
+
+ <p>The JSON object does not have a [[Construct]] internal method; it is not possible to use the JSON object as a constructor
+ with the <code>new</code> operator.</p>
+
+ <p>The JSON object does not have a [[Call]] internal method; it is not possible to invoke the JSON object as a function.</p>
+ </div>
+
+ <section id="sec-json.parse">
+ <div class="front">
+ <h1><span class="secnum" id="sec-24.3.1"><a href="#sec-json.parse" title="link to this section">24.3.1</a></span>
+ JSON.parse ( text [ , reviver ] )</h1>
+
+ <p>The <code>parse</code> function parses a JSON text (a JSON-formatted String) and produces an ECMAScript value. The JSON
+ format is a subset of the syntax for ECMAScript literals, Array Initializers and Object Initializers. After parsing, JSON
+ objects are realized as ECMAScript objects. JSON arrays are realized as ECMAScript Array instances. JSON strings, numbers,
+ booleans, and null are realized as ECMAScript Strings, Numbers, Booleans, and <b>null</b>.</p>
+
+ <p>The optional <i>reviver</i> parameter is a function that takes two parameters, (<i>key</i> and <i>value</i>). It can
+ filter and transform the results. It is called with each of the <i>key</i>/<i>value</i> pairs produced by the parse, and
+ its return value is used instead of the original value. If it returns what it received, the structure is not modified. If
+ it returns <b>undefined</b> then the property is deleted from the result.</p>
+
+ <ol class="proc">
+ <li>Let <i>JText</i> be <a href="#sec-tostring">ToString</a>(<i>text</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>JText</i>).</li>
+ <li>Parse <i>JText</i> interpreted as UTF-16 encoded Unicode points as a JSON text as specified in <br>ECMA-404. Throw a
+ <b>SyntaxError</b> exception if <i>JText</i> is not a valid JSON text as defined in that specification.</li>
+ <li>Let <i>scriptText</i> be the result of concatenating <code>"("</code>, <i>JText</i>, and <code>");"</code>.</li>
+ <li>Let <i>completion</i> be the result of parsing and evaluating <i>scriptText</i> as if it was the source text of an
+ ECMAScript <i>Script</i>. but using the alternative definition of <i>DoubleStringCharacter</i> provided below. The
+ extended PropertyDefinitionEvaluation semantics defined in <a
+ href="#sec-__proto__-property-names-in-object-initializers">B.3.1</a> must not be used during the evaluation.</li>
+ <li>Let <i>unfiltered</i> be <i>completion</i>.[[value]].</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>unfiltered</i> will be either a primitive value or an object
+ that is defined by either an <i>ArrayLiteral</i> or an <i>ObjectLiteral</i>.</li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>reviver</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>root</i> be <a href="#sec-objectcreate">ObjectCreate</a>(%ObjectPrototype%).</li>
+ <li>Let <i>status</i> be the result of <a href="#sec-createdataproperty">CreateDataProperty</a>(<i>root</i>, the
+ empty String, <i>unfiltered</i>).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>status</i> is <b>true</b>.</li>
+ <li>Return the result of calling the abstract operation <a href="#sec-walk">Walk</a>, passing <i>root</i> and the
+ empty String. The abstract operation <a href="#sec-walk">Walk</a> is described below.</li>
+ </ol>
+ </li>
+ <li>Else
+ <ol class="block">
+ <li>Return <i>unfiltered</i>.</li>
+ </ol>
+ </li>
+ </ol>
+
+ <p>JSON allows Unicode code points U+2028 and U+2029 to directly appear in <span class="nt">String</span> literals without
+ using an escape sequence. This is enabled by using the following alternative definition of <span
+ class="nt">DoubleStringCharacter</span> when parsing <var>scriptText</var> in step 5:</p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">DoubleStringCharacter</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">SourceCharacter</span> <span class="grhsmod">but not one of</span> <code class="t">"</code> <span class="grhsmod">or</span> <code class="t">\</code> <span class="grhsmod">or</span> <span class="gprose">U+0000 through U+001F</span></div>
+ <div class="rhs"><code class="t">\</code> <span class="nt">EscapeSequence</span></div>
+ </div>
+
+ <ul>
+ <li>
+ <p>The CV of <span class="prod"><span class="nt">DoubleStringCharacter</span> <span class="geq">::</span> <span
+ class="nt">SourceCharacter</span> <span class="grhsmod">but not one of</span> <code class="t">"</code> <span
+ class="grhsmod">or</span> <code class="t">\</code> <span class="grhsmod">or</span></span> U+0000 <b>through</b> U+001F
+ is the <a href="#sec-static-semantics-utf-16encoding">UTF-16Encoding</a> (<a
+ href="#sec-static-semantics-utf-16encoding">10.1.1</a>) of the code point value of <i>SourceCharacter</i>.</p>
+ </li>
+ </ul>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The syntax of a valid JSON text is a subset of the ECMAScript <i>PrimaryExpression</i>
+ syntax. Hence a valid JSON text is also a valid <i>PrimaryExpression</i>. Step 3 above verifies that <i>JText</i>
+ conforms to that subset. When <i>scriptText</i> is parsed and evaluated as a <i>Script</i> the result will be either a
+ String, Number, Boolean, or Null primitive value or an Object defined as if by an <i>ArrayLiteral</i> or
+ <i>ObjectLiteral</i>.</p>
+ </div>
+ </div>
+
+ <section id="sec-walk">
+ <h1><span class="secnum" id="sec-24.3.1.1"><a href="#sec-walk" title="link to this section">24.3.1.1</a></span> Runtime
+ Semantics: Walk Abstract Operation</h1>
+
+ <p>The abstract operation Walk is a recursive abstract operation that takes two parameters: a <var>holder</var> object and
+ the String <var>name</var> of a property in that object. Walk uses the value of <var>reviver</var> that was originally
+ passed to the above parse function.</p>
+
+ <ol class="proc">
+ <li>Let <i>val</i> be the result of <a href="#sec-get-o-p">Get</a>(<i>holder</i>, <i>name</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>val</i>).</li>
+ <li>If <i>val</i> is an object, then
+ <ol class="block">
+ <li>If <i>val</i> is an exotic Array object then
+ <ol class="block">
+ <li>Set <i>I</i> to 0.</li>
+ <li>Let <i>len</i> be the result of <a href="#sec-get-o-p">Get</a>(<i>val</i>, <code>"length"</code>).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>len</i> is not an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a> and its value is a positive
+ integer.</li>
+ <li>Repeat while <i>I</i> < <i>len</i>,
+ <ol class="block">
+ <li>Let <i>newElement</i> be the result of calling the abstract operation Walk, passing <i>val</i> and <a
+ href="#sec-tostring">ToString</a>(<i>I</i>).</li>
+ <li>If <i>newElement</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>status</i> be the result of calling the [[Delete]] internal method of <i>val</i> with <a
+ href="#sec-tostring">ToString</a>(<i>I</i>) as the argument.</li>
+ </ol>
+ </li>
+ <li>Else
+ <ol class="block">
+ <li>Let <i>status</i> be the result of calling the [[DefineOwnProperty]] internal method of <i>val</i>
+ with arguments <a href="#sec-tostring">ToString</a>(<i>I</i>) and PropertyDescriptor{[[Value]]:
+ <i>newElement</i>, [[Writable]]: <b>true</b>, [[Enumerable]]: <b>true</b>, [[Configurable]]:
+ <b>true</b>}.</li>
+ <li>NOTE This algorithm intentionally does not throw an exception if status is <b>false</b>.</li>
+ </ol>
+ </li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Add 1 to <i>I</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Else
+ <ol class="block">
+ <li>Let <i>keys</i> be a <a href="#sec-list-and-record-specification-type">List</a> of String values consisting
+ of the names of all the own properties of <i>val</i> whose [[Enumerable]] attribute is <b>true</b>. The
+ ordering of the Strings is the same as that used by the <b><a href="#sec-object.keys">Object.keys</a></b>
+ standard built-in function.</li>
+ <li>For each String <i>P</i> in <i>keys</i> do,
+ <ol class="block">
+ <li>Let <i>newElement</i> be the result of calling the abstract operation Walk, passing <i>val</i> and
+ <i>P</i>.</li>
+ <li>If <i>newElement</i> is <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>status</i> be the result of calling the [[Delete]] internal method of <i>val</i> with
+ <i>P</i> as the argument.</li>
+ </ol>
+ </li>
+ <li>Else
+ <ol class="block">
+ <li>Let <i>status</i> be the result of calling the [[DefineOwnProperty]] internal method of <i>val</i>
+ with arguments <i>P</i> and PropertyDescriptor{[[Value]]: <i>newElement</i>, [[Writable]]:
+ <b>true</b>, [[Enumerable]]: <b>true</b>, [[Configurable]]: <b>true</b>}.</li>
+ <li>NOTE This algorithm intentionally does not throw an exception if status is <b>false</b>.</li>
+ </ol>
+ </li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Return the result of calling the [[Call]] internal method of <i>reviver</i> passing <i>holder</i> as
+ <i>thisArgument</i> and with a <a href="#sec-list-and-record-specification-type">List</a> containing <i>name</i> and
+ <i>val</i> as <i>argumentsList</i>.</li>
+ </ol>
+
+ <p>It is not permitted for a conforming implementation of <code><a href="#sec-json.parse">JSON.parse</a></code> to extend
+ the JSON grammars. If an implementation wishes to support a modified or extended JSON interchange format it must do so by
+ defining a different parse function.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> In the case where there are duplicate name Strings within an object, lexically preceding
+ values for the same key shall be overwritten.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-json.stringify">
+ <div class="front">
+ <h1><span class="secnum" id="sec-24.3.2"><a href="#sec-json.stringify" title="link to this section">24.3.2</a></span>
+ JSON.stringify ( value [ , replacer [ , space ] ] )</h1>
+
+ <p>The <code>stringify</code> function returns a String in UTF-16 encoded JSON format representing an ECMAScript value. It
+ can take three parameters. The <var>value</var> parameter is an ECMAScript value, which is usually an object or array,
+ although it can also be a String, Boolean, Number or <b>null</b>. The optional <var>replacer</var> parameter is either a
+ function that alters the way objects and arrays are stringified, or an array of Strings and Numbers that acts as a white
+ list for selecting the object properties that will be stringified. The optional <var>space</var> parameter is a String or
+ Number that allows the result to have white space injected into it to improve human readability.</p>
+
+ <p>These are the steps in stringifying an object:</p>
+
+ <ol class="proc">
+ <li>Let <i>stack</i> be an empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Let <i>indent</i> be the empty String.</li>
+ <li>Let <i>PropertyList</i> and <i>ReplacerFunction</i> be <b>undefined</b>.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>replacer</i>) is Object, then
+ <ol class="block">
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>replacer</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>ReplacerFunction</i> be <i>replacer</i>.</li>
+ </ol>
+ </li>
+ <li>Else if <i>replacer</i> is an exotic Array object, then
+ <ol class="block">
+ <li>Let <i>PropertyList</i> be an empty <a href="#sec-list-and-record-specification-type">List</a></li>
+ <li>For each value <i>v</i> of a property of <i>replacer</i> that has an array index property name. The
+ properties are enumerated in the ascending array index order of their names.
+ <ol class="block">
+ <li>Let <i>item</i> be <b>undefined</b>.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>v</i>) is String then let <i>item</i> be
+ <i>v.</i></li>
+ <li>Else if <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>v</i>) is Number then let
+ <i>item</i> be <a href="#sec-tostring">ToString</a>(<i>v</i>).</li>
+ <li>Else if <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>v</i>) is Object then,
+ <ol class="block">
+ <li>If <i>v</i> has a [[StringData]] or [[NumberData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, then let <i>item</i> be <a
+ href="#sec-tostring">ToString</a>(<i>v</i>).</li>
+ </ol>
+ </li>
+ <li>If <i>item</i> is not <b>undefined</b> and <i>item</i> is not currently an element of
+ <i>PropertyList</i> then,
+ <ol class="block">
+ <li>Append <i>item</i> to the end of <i>PropertyList</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>space</i>) is Object then,
+ <ol class="block">
+ <li>If <i>space</i> has a [[NumberData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>
+ then,
+ <ol class="block">
+ <li>Let <i>space</i> be <a href="#sec-tonumber">ToNumber</a>(<i>space</i>).</li>
+ </ol>
+ </li>
+ <li>Else if <i>space</i> has a [[StringData]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> then,
+ <ol class="block">
+ <li>Let <i>space</i> be <a href="#sec-tostring">ToString</a>(<i>space</i>).</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>space</i>) is Number
+ <ol class="block">
+ <li>Let <i>space</i> be min(10, <a href="#sec-tointeger">ToInteger</a>(<i>space</i>)).</li>
+ <li>Set <i>gap</i> to a String containing <i>space</i> occurrences of code unit 0x0020 (the Unicode space
+ character). This will be the empty String if <i>space</i> is less than 1.</li>
+ </ol>
+ </li>
+ <li>Else if <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>space)</i> is String
+ <ol class="block">
+ <li>If the number of elements in <i>space</i> is 10 or less, set <i>gap</i> to <i>space</i> otherwise set <i>gap</i>
+ to a String consisting of the first 10 elements of <i>space</i>.</li>
+ </ol>
+ </li>
+ <li>Else
+ <ol class="block">
+ <li>Set <i>gap</i> to the empty String.</li>
+ </ol>
+ </li>
+ <li>Let <i>wrapper</i> be <a href="#sec-objectcreate">ObjectCreate</a>(%ObjectPrototype%).</li>
+ <li>Let <i>status</i> be the result of <a href="#sec-createdataproperty">CreateDataProperty</a>(<i>wrapper</i>, the
+ empty String, <i>value</i>).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>status</i> is <b>true</b>.</li>
+ <li>Return the result of calling the abstract operation Str(the empty String, <i>wrapper</i>).</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE 1</span> JSON structures are allowed to be nested to any depth, but they must be acyclic. If
+ <i>value</i> is or contains a cyclic structure, then the stringify function must throw a <b>TypeError</b> exception.
+ This is an example of a value that cannot be stringified:</p>
+
+ <pre>a = [];</pre>
+ <pre>a[0] = a;</pre>
+ <pre>my_text = JSON.stringify(a); // This must throw a TypeError.</pre>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 2</span> Symbolic primitive values are rendered as follows:</p>
+
+ <ul>
+ <li>The <b>null</b> value is rendered in JSON text as the String <code>null</code>.</li>
+ <li>The <b>undefined</b> value is not rendered.</li>
+ <li>The <b>true</b> value is rendered in JSON text as the String <code>true</code>.</li>
+ <li>The <b>false</b> value is rendered in JSON text as the String <code>false</code>.</li>
+ </ul>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 3</span> String values are wrapped in double quotes. The characters <code>"</code> and
+ <code>\</code> are escaped with <code>\</code> prefixes. Control characters are replaced with escape sequences
+ <code>\u</code>HHHH, or with the shorter forms, <code>\b</code> (backspace), <code>\f</code> (formfeed), <code>\n</code>
+ (newline), <code>\r</code> (carriage return), <code>\t</code> (tab).</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 4</span> Finite numbers are stringified as if by calling <a
+ href="#sec-tostring">ToString</a><b>(</b><i>number</i><b>)</b>. <b>NaN</b> and Infinity regardless of sign are
+ represented as the String <code>null</code>.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 5</span> Values that do not have a JSON representation (such as <b>undefined</b> and functions)
+ do not produce a String. Instead they produce the <b>undefined</b> value. In arrays these values are represented as the
+ String <code>null</code>. In objects an unrepresentable value causes the property to be excluded from
+ stringification.</p>
+ </div>
+
+ <div class="note">
+ <p><span class="nh">NOTE 6</span> An object is rendered as an opening left brace followed by zero or more properties,
+ separated with commas, closed with a right brace. A property is a quoted String representing the key or property name, a
+ colon, and then the stringified property value. An array is rendered as an opening left bracket followed by zero or more
+ values, separated with commas, closed with a right bracket.</p>
+ </div>
+ </div>
+
+ <section id="sec-runtime-semantics-str-abstract-operation">
+ <h1><span class="secnum" id="sec-24.3.2.1"><a href="#sec-runtime-semantics-str-abstract-operation"
+ title="link to this section">24.3.2.1</a></span> Runtime Semantics: Str Abstract Operation</h1>
+
+ <p>The abstract operation <span style="font-family: Times New Roman">Str(<i>key</i>, <i>holder</i>)</span> has access to
+ <span class="nt">ReplacerFunction</span> from the invocation of the <code>stringify</code> method. Its algorithm is as
+ follows:</p>
+
+ <ol class="proc">
+ <li>Let <i>value</i> be the result of <a href="#sec-get-o-p">Get</a>(<i>holder</i>, <i>key</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>value</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>value</i>) is Object, then
+ <ol class="block">
+ <li>Let <i>toJSON</i> be the result of <a href="#sec-get-o-p">Get</a>(<i>value</i>, <code>"toJSON"</code>).</li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>toJSON</i>) is <b>true</b>
+ <ol class="block">
+ <li>Let <i>value</i> be the result of calling the [[Call]] internal method of <i>toJSON</i> passing <i>value</i>
+ as <i>thisArgument</i> and a <a href="#sec-list-and-record-specification-type">List</a> containing
+ <i>key</i> as <i>argumentsList</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>value</i>).</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>If <i>ReplacerFunction</i> is not <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>value</i> be the result of calling the [[Call]] internal method of <i>ReplacerFunction</i> passing
+ <i>holder</i> as the <b>this</b> value and with an argument list consisting of <i>key</i> and <i>value</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>value</i>).</li>
+ </ol>
+ </li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>value</i>) is Object then,
+ <ol class="block">
+ <li>If <i>value</i> has a [[NumberData]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>
+ then,
+ <ol class="block">
+ <li>Let <i>value</i> be <a href="#sec-tonumber">ToNumber</a>(<i>value</i>).</li>
+ </ol>
+ </li>
+ <li>Else if <i>value</i> has a [[StringData]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> then,
+ <ol class="block">
+ <li>Let <i>value</i> be <a href="#sec-tostring">ToString</a>(<i>value</i>).</li>
+ </ol>
+ </li>
+ <li>Else if <i>value</i> has a [[BooleanData]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> then,
+ <ol class="block">
+ <li>Let <i>value</i> be the value of the [[BooleanData]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>value</i>.</li>
+ <li>If <i>value</i> is <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>If <i>value</i> is <b>null</b> then return <code>"null"</code>.</li>
+ <li>If <i>value</i> is <b>true</b> then return <code>"true"</code>.</li>
+ <li>If <i>value</i> is <b>false</b> then return <code>"false"</code>.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>value</i>) is String, then return the result of
+ calling the abstract operation <a href="#sec-quote">Quote</a> with argument <i>value</i>.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>value</i>) is Number
+ <ol class="block">
+ <li>If <i>value</i> is finite then return <a href="#sec-tostring">ToString</a>(<i>value</i>).</li>
+ <li>Else, return <code>"null"</code>.</li>
+ </ol>
+ </li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>value</i>) is Object, and <a
+ href="#sec-iscallable">IsCallable</a>(<i>value</i>) is <b>false</b>
+ <ol class="block">
+ <li>If <i>value</i> is an exotic Array object then
+ <ol class="block">
+ <li>Return the result of calling the abstract operation JA with argument <i>value</i>.</li>
+ </ol>
+ </li>
+ <li>Else, return the result of calling the abstract operation JO with argument <i>value</i>.</li>
+ </ol>
+ </li>
+ <li>Return <b>undefined</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-quote">
+ <h1><span class="secnum" id="sec-24.3.2.2"><a href="#sec-quote" title="link to this section">24.3.2.2</a></span> Runtime
+ Semantics: Quote Abstract Operation</h1>
+
+ <p>The abstract operation <span style="font-family: Times New Roman">Quote(<i>value</i>)</span> wraps a String value in
+ double quotes and escapes characters within it.</p>
+
+ <ol class="proc">
+ <li>Let <i>product</i> be code unit 0x0022 (the Unicode double quote character).</li>
+ <li>For each code unit <i>C</i> in <i>value</i>
+ <ol class="block">
+ <li>If <i>C</i> is 0x0022 or 0x005C (the Unicode reverse solidus character)
+ <ol class="block">
+ <li>Let <i>product</i> be the concatenation of <i>product</i> and code unit 0x005C.</li>
+ <li>Let <i>product</i> be the concatenation of <i>product</i> and <i>C</i>.</li>
+ </ol>
+ </li>
+ <li>Else if <i>C</i> is backspace, formfeed, newline, carriage return, or tab
+ <ol class="block">
+ <li>Let <i>product</i> be the concatenation of <i>product</i> and code unit 0x005C (the Unicode backslash
+ character).</li>
+ <li>Let <i>abbrev</i> be the string value corresponding to the value of <i>C</i> as follows:
+ <table class="lightweight">
+ <tr>
+ <td>backspace</td>
+ <td><span class="string value">"b"</span></td>
+ </tr>
+ <tr>
+ <td>formfeed</td>
+ <td><span class="string value">"f"</span></td>
+ </tr>
+ <tr>
+ <td>newline</td>
+ <td><span class="string value">"n"</span></td>
+ </tr>
+ <tr>
+ <td>carriage return</td>
+ <td><span class="string value">"r"</span></td>
+ </tr>
+ <tr>
+ <td>tab</td>
+ <td><span class="string value">"t"</span></td>
+ </tr>
+ </table>
+ </li>
+ <li>Let <i>product</i> be the concatenation of <i>product</i> and <i>abbrev</i>.</li>
+ </ol>
+ </li>
+ <li>Else if <i>C</i> has a code unit value less than 0x0020 (the Unicode space character)
+ <ol class="block">
+ <li>Let <i>product</i> be the concatenation of <i>product</i> and code unit 0x005C (the Unicode backslash
+ character).</li>
+ <li>Let <i>product</i> be the concatenation of <i>product</i> and <code>"u"</code>.</li>
+ <li>Let <i>hex</i> be the string result of converting the numeric code unit value of <i>C</i> to a String of
+ four hexadecimal digits. Alphabetic hexadecimal digits are presented as lowercase characters.</li>
+ <li>Let <i>product</i> be the concatenation of <i>product</i> and <i>hex</i>.</li>
+ </ol>
+ </li>
+ <li>Else
+ <ol class="block">
+ <li>Let <i>product</i> be the concatenation of <i>product</i> and <i>C</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Let <i>product</i> be the concatenation of <i>product</i> and code unit 0x0022 (the Unicode double quote
+ character).</li>
+ <li>Return <i>product</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-runtime-semantics-jo-abstract-operation">
+ <h1><span class="secnum" id="sec-24.3.2.3"><a href="#sec-runtime-semantics-jo-abstract-operation"
+ title="link to this section">24.3.2.3</a></span> Runtime Semantics: JO Abstract Operation</h1>
+
+ <p>The abstract operation <span style="font-family: Times New Roman">JO(<i>value</i>)</span> serializes an object. It has
+ access to the <var>stack</var>, <var>indent</var>, <var>gap</var>, and <span class="nt">PropertyList</span> of the
+ invocation of the stringify method.</p>
+
+ <ol class="proc">
+ <li>If <i>stack</i> contains <i>value</i> then throw a <b>TypeError</b> exception because the structure is
+ cyclical.</li>
+ <li>Append <i>value</i> to <i>stack</i>.</li>
+ <li>Let <i>stepback</i> be <i>indent</i>.</li>
+ <li>Let <i>indent</i> be the concatenation of <i>indent</i> and <i>gap</i>.</li>
+ <li>If <i>PropertyList</i> is not <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>K</i> be <i>PropertyList</i>.</li>
+ </ol>
+ </li>
+ <li>Else
+ <ol class="block">
+ <li>Let <i>K</i> be a <a href="#sec-list-and-record-specification-type">List</a> of Strings consisting of the keys
+ of all the own properties of <i>value</i> whose [[Enumerable]] attribute is <b>true</b> and whose <a
+ href="#sec-object-type">property key</a> is a String value. The ordering of the Strings is the same as that used
+ by the <b><a href="#sec-object.keys">Object.keys</a></b> standard built-in function.</li>
+ </ol>
+ </li>
+ <li>Let <i>partial</i> be an empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>For each element <i>P</i> of <i>K</i>,
+ <ol class="block">
+ <li>Let <i>strP</i> be the result of Str(<i>P</i>, <i>value</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>strP</i>).</li>
+ <li>If <i>strP</i> is not <b>undefined</b>
+ <ol class="block">
+ <li>Let <i>member</i> be the result of calling the abstract operation <a href="#sec-quote">Quote</a> with
+ argument <i>P</i>.</li>
+ <li>Let <i>member</i> be the concatenation of <i>member</i> and the string <code>":</code>".</li>
+ <li>If <i>gap</i> is not the empty String
+ <ol class="block">
+ <li>Let <i>member</i> be the concatenation of <i>member</i> and code unit 0x0020 (the Unicode space
+ character).</li>
+ </ol>
+ </li>
+ <li>Let <i>member</i> be the concatenation of <i>member</i> and <i>strP</i>.</li>
+ <li>Append <i>member</i> to <i>partial</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>If <i>partial</i> is empty, then
+ <ol class="block">
+ <li>Let <i>final</i> be <code>"{}"</code>.</li>
+ </ol>
+ </li>
+ <li>Else
+ <ol class="block">
+ <li>If <i>gap</i> is the empty String
+ <ol class="block">
+ <li>Let <i>properties</i> be a String formed by concatenating all the element Strings of <i>partial</i> with
+ each adjacent pair of Strings separated with code unit 0x002C (the Unicode comma character). A comma is not
+ inserted either before the first String or after the last String.</li>
+ <li>Let <i>final</i> be the result of concatenating <b><code>"{"</code>,</b> <i>properties</i>, and
+ <code>"}"</code>.</li>
+ </ol>
+ </li>
+ <li>Else <i>gap</i> is not the empty String
+ <ol class="block">
+ <li>Let <i>separator</i> be the result of concatenating code unit 0x002C (the comma character), code unit 0x000A
+ (the line feed character), and <i>indent</i>.</li>
+ <li>Let <i>properties</i> be a String formed by concatenating all the element Strings of <i>partial</i> with
+ each adjacent pair of Strings separated with <i>separator</i>. The <i>separator</i> String is not inserted
+ either before the first String or after the last String.</li>
+ <li>Let <i>final</i> be the result of concatenating <code>"{"</code>, code unit 0x000A (the line feed
+ character), <i>indent</i>, <i>properties</i>, code unit 0x000A, <i>stepback</i>, and <code>"}</code>".</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Remove the last element of <i>stack</i>.</li>
+ <li>Let <i>indent</i> be <i>stepback</i>.</li>
+ <li>Return <i>final</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-runtime-semantics-ja-abstract-operation">
+ <h1><span class="secnum" id="sec-24.3.2.4"><a href="#sec-runtime-semantics-ja-abstract-operation"
+ title="link to this section">24.3.2.4</a></span> Runtime Semantics: JA Abstract Operation</h1>
+
+ <p>The abstract operation <span style="font-family: Times New Roman">JA(<i>value</i>)</span> serializes an array. It has
+ access to the <var>stack</var>, <var>indent</var>, and <var>gap</var> of the invocation of the stringify method. The
+ representation of arrays includes only the elements between zero and <code>array.length</code> <span style="font-family:
+ Times New Roman">– 1</span> inclusive. Properties whose keys are not array indexes are excluded from the
+ stringification. An array is stringified as an open left bracket, elements separated by comma, and a closing right
+ bracket.</p>
+
+ <ol class="proc">
+ <li>If <i>stack</i> contains <i>value</i> then throw a <b>TypeError</b> exception because the structure is
+ cyclical.</li>
+ <li>Append <i>value</i> to <i>stack</i>.</li>
+ <li>Let <i>stepback</i> be <i>indent</i>.</li>
+ <li>Let <i>indent</i> be the concatenation of <i>indent</i> and <i>gap</i>.</li>
+ <li>Let <i>partial</i> be an empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>value</i> is a standard array object and hence its
+ <code>"length"</code> property is a nonnegative integer.</li>
+ <li>Let <i>lenVal</i> be the result of <a href="#sec-get-o-p">Get</a>(<i>value</i>, <code>"length"</code>)</li>
+ <li>Let <i>len</i> be <a href="#sec-tolength">ToLength</a>(<i>lenVal</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>len</i>).</li>
+ <li>Let <i>index</i> be 0.</li>
+ <li>Repeat while <i>index</i> < <i>len</i>
+ <ol class="block">
+ <li>Let <i>strP</i> be the result of calling the abstract operation Str(<a
+ href="#sec-tostring">ToString</a>(<i>index</i>), <i>value</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>strP</i>).</li>
+ <li>If <i>strP</i> is <b>undefined</b>
+ <ol class="block">
+ <li>Append <code>"null"</code> to <i>partial</i>.</li>
+ </ol>
+ </li>
+ <li>Else
+ <ol class="block">
+ <li>Append <i>strP</i> to <i>partial</i>.</li>
+ </ol>
+ </li>
+ <li>Increment <i>index</i> by 1.</li>
+ </ol>
+ </li>
+ <li>If <i>partial</i> is empty, then
+ <ol class="block">
+ <li>Let <i>final</i> be <code>"[]"</code>.</li>
+ </ol>
+ </li>
+ <li>Else
+ <ol class="block">
+ <li>If <i>gap</i> is the empty String
+ <ol class="block">
+ <li>Let <i>properties</i> be a String formed by concatenating all the element Strings of <i>partial</i> with
+ each adjacent pair of Strings separated with code unit 0x002C (the comma character). A comma is not inserted
+ either before the first String or after the last String.</li>
+ <li>Let <i>final</i> be the result of concatenating <b><code>"["</code>,</b> <i>properties</i>, and
+ <code>"]"</code>.</li>
+ </ol>
+ </li>
+ <li>Else
+ <ol class="block">
+ <li>Let <i>separator</i> be the result of concatenating code unit 0x002C (the comma character), code unit 0x000A
+ (the line feed character), and <i>indent</i>.</li>
+ <li>Let <i>properties</i> be a String formed by concatenating all the element Strings of <i>partial</i> with
+ each adjacent pair of Strings separated with <i>separator</i>. The <i>separator</i> String is not inserted
+ either before the first String or after the last String.</li>
+ <li>Let <i>final</i> be the result of concatenating <code>"["</code>, code unit 0x000A (the line feed
+ character), <i>indent</i>, <i>properties</i>, code unit 0x000A, <i>stepback</i>, and <code>"]</code>".</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Remove the last element of <i>stack</i>.</li>
+ <li>Let <i>indent</i> be <i>stepback</i>.</li>
+ <li>Return <i>final</i>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-json-@@tostringtag">
+ <h1><span class="secnum" id="sec-24.3.3"><a href="#sec-json-@@tostringtag" title="link to this section">24.3.3</a></span>
+ JSON [ @@toStringTag ]</h1>
+
+ <p>The initial value of the @@toStringTag property is the string value <b>"<code>JSON</code>"</b>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <span class="value">false</span>, [[Enumerable]]: <span
+ class="value">false</span>, [[Configurable]]: <span class="value">true</span> }.</p>
+ </section>
+ </section>
+</section>
+
+<section id="sec-control-abstraction-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-25"><a href="#sec-control-abstraction-objects" title="link to this section">25</a></span>
+ Control Abstraction Objects</h1>
+ </div>
+
+ <section id="sec-common-iteration-interfaces">
+ <div class="front">
+ <h1><span class="secnum" id="sec-25.1"><a href="#sec-common-iteration-interfaces"
+ title="link to this section">25.1</a></span> Common Iteration Interfaces</h1>
+
+ <p>An interface is a set of property keys whose associated values match a specific specification. Any object that provides
+ all the properties as described by an interface’s specification <i>conforms</i> to that interface. An interface is not
+ represented by an distinct object. There may be many separately implemented objects that conform to any interface. An
+ individual object may conform to multiple interfaces.</p>
+ </div>
+
+ <section id="sec-iterable-interface">
+ <h1><span class="secnum" id="sec-25.1.1"><a href="#sec-iterable-interface" title="link to this section">25.1.1</a></span>
+ The <i>Iterable</i> Interface</h1>
+
+ <p>The <i>Iterable</i> interface includes the following property:</p>
+
+ <figure>
+ <table class="real-table">
+ <tr>
+ <th style="background-color: #A6A6A6; border-bottom: 0px solid black; border-top: 1px solid #000080">Property</th>
+ <th style="background-color: #A6A6A6; border-bottom: 0px solid black; border-top: 1px solid #000080">Value</th>
+ <th style="background-color: #A6A6A6; border-bottom: 0px solid black; border-top: 1px solid #000080">Requirements</th>
+ </tr>
+ <tr>
+ <td style="border-top: 0px solid black"><code>@@iterator</code></td>
+ <td style="border-top: 0px solid black">A zero arguments function that returns an object.</td>
+ <td style="border-top: 0px solid black">The function returns an object that conforms to the <i>iterator</i> interface.</td>
+ </tr>
+ </table>
+ </figure>
+ </section>
+
+ <section id="sec-iterator-interface">
+ <h1><span class="secnum" id="sec-25.1.2"><a href="#sec-iterator-interface" title="link to this section">25.1.2</a></span>
+ The <i>Iterator</i> Interface</h1>
+
+ <p>The <i>Iterator</i> interface includes the following properties:</p>
+
+ <figure>
+ <table class="real-table">
+ <tr>
+ <th style="background-color: #A6A6A6; border-bottom: 0px solid black; border-top: 1px solid #000080">Property</th>
+ <th style="background-color: #A6A6A6; border-bottom: 0px solid black; border-top: 1px solid #000080">Value</th>
+ <th style="background-color: #A6A6A6; border-bottom: 0px solid black; border-top: 1px solid #000080">Requirements</th>
+ </tr>
+ <tr>
+ <td style="border-top: 0px solid black"><code>next</code></td>
+ <td style="border-top: 0px solid black">A function that returns an object.</td>
+ <td style="border-top: 0px solid black">The function returns an object that conforms to the <i>IteratorResult</i> interface. If a previous call to the <code>next</code> method of an <i>Iterator</i> has returned an <i>IteratorResult</i> object whose <code>done</code> property is <b>true</b>, then all subsequent calls to the <code>next</code> method of that object must also return an <i>IteratorResult</i> object whose <code>done</code> property is <b>true</b>,</td>
+ </tr>
+ </table>
+ </figure>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Arguments may be passed to the next function but their interpretation and validity is
+ dependent upon the target Iterator. The for-of statement and other common users of Iterators do not pass any arguments, so
+ Iterators that expect to be used in such a manner must be prepared to deal with being called with no arguments.</p>
+ </div>
+ </section>
+
+ <section id="sec-iteratorresult-interface">
+ <h1><span class="secnum" id="sec-25.1.3"><a href="#sec-iteratorresult-interface"
+ title="link to this section">25.1.3</a></span> The <i>IteratorResult</i> Interface</h1>
+
+ <p>The <i>IteratorResult</i> interface includes the following properties:</p>
+
+ <figure>
+ <table class="real-table">
+ <tr>
+ <th style="background-color: #A6A6A6; border-bottom: 0px solid black; border-top: 1px solid #000080">Property</th>
+ <th style="background-color: #A6A6A6; border-bottom: 0px solid black; border-top: 1px solid #000080">Value</th>
+ <th style="background-color: #A6A6A6; border-bottom: 0px solid black; border-top: 1px solid #000080">Requirements</th>
+ </tr>
+ <tr>
+ <td style="border-bottom: 0px solid black; border-top: 0px solid black"><code>done</code></td>
+ <td style="border-bottom: 0px solid black; border-top: 0px solid black">Either <span class="value">true</span> or <span class="value">false</span>.</td>
+ <td style="border-bottom: 0px solid black; border-top: 0px solid black">This is the result status of an <i>iterator</i> <code>next</code> method call. If the end of the iterator was reached <code>done</code> is <span class="value">true</span>. If the end was not reached <code>done</code> is <span class="value">false</span> and a value is available. If a <code>done</code> property (either own or inherited does not exist), it is consider to have the value <span class="value">false</span>.</td>
+ </tr>
+ <tr>
+ <td style="border-top: 0px solid black"><code>value</code></td>
+ <td style="border-top: 0px solid black">Any ECMAScript languge value.</td>
+ <td style="border-top: 0px solid black">If done is <span class="value">false</span>, this is the current iteration element value. If done is <span class="value">true</span>, this is the return value of the iterator, if it supplied one. If the iterator does not have a return value, <code>value</code> is <span class="value">undefined</span>. In that case, the <code>value</code> property may be absent from the conforming object if it does not inherit an explicit <code>value</code> property.</td>
+ </tr>
+ </table>
+ </figure>
+ </section>
+ </section>
+
+ <section id="sec-generatorfunction-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-25.2"><a href="#sec-generatorfunction-objects" title="link to this section">25.2</a></span>
+ GeneratorFunction Objects</h1>
+
+ <p><code>Generator Function</code> objects are constructor functions that are usually created by evaluating <span
+ class="nt">GeneratorDeclaration</span>, <span class="nt">GeneratorExpression</span>, and <span
+ class="nt">GeneratorMethod</span> syntactic productions. They may also be created by calling the
+ <code>GeneratorFunction</code> constructor.</p>
+
+ <figure>
+ <img alt="A staggering variety of boxes and arrows." height="958" src="figure-2.png" width="968">
+ <figcaption>Figure 2 (Informative) — Generator Objects Relationships</figcaption>
+ </figure>
+ </div>
+
+ <section id="sec-generatorfunction-constructor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-25.2.1"><a href="#sec-generatorfunction-constructor"
+ title="link to this section">25.2.1</a></span> The GeneratorFunction Constructor</h1>
+
+ <p>The GeneratorFunction constructor is the %GeneratorFunction% intrinsic. When <code>GeneratorFunction</code> is called
+ as a function rather than as a constructor, it creates and initializes a new GeneratorFunction object. Thus the function
+ call <code>GeneratorFunction</code> <code><b>(</b>…<b>)</b></code> is equivalent to the object creation expression
+ <code>new GeneratorFunction</code> <code><b>(</b>…<b>)</b></code> with the same arguments. However, if the
+ <b>this</b> value passed in the call is an Object with a [[Code]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> whose value is <span
+ class="value">undefined</span>, it initializes the <b>this</b> value using the argument values. This permits
+ <code>GeneratorFunction</code> to be used both as factory method and to perform constructor instance initialization.</p>
+
+ <p><code>GeneratorFunction</code> may be subclassed and subclass constructors may perform a <code>super</code> invocation
+ of the <code>GeneratorFunction</code> constructor to initialize subclass instances. However, all syntactic forms for
+ defining generator function objects create direct instances of <code>GeneratorFunction</code>. There is no syntactic means
+ to create instances of <code>GeneratorFunction</code> subclasses.</p>
+ </div>
+
+ <section id="sec-generatorfunction">
+ <h1><span class="secnum" id="sec-25.2.1.1"><a href="#sec-generatorfunction"
+ title="link to this section">25.2.1.1</a></span> GeneratorFunction (p1, p2, … , pn, body)</h1>
+
+ <p>The last argument specifies the body (executable code) of a generator function; any preceding arguments specify formal
+ parameters.</p>
+
+ <p>When the <code>GeneratorFunction</code> function is called with some arguments <var>p1</var>, <var>p2</var>, … ,
+ <var>pn</var>, <var>body</var> (where <var>n</var> might be <span style="font-family: Times New Roman">0</span>, that is,
+ there are no “<var>p</var>” arguments, and where <var>body</var> might also not be provided), the following
+ steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>argCount</i> be the total number of arguments passed to this function invocation.</li>
+ <li>Let <i>P</i> be the empty String.</li>
+ <li>If <i>argCount</i> = 0, let <i>bodyText</i> be the empty String.</li>
+ <li>Else if <i>argCount</i> = 1, let <i>bodyText</i> be that argument.</li>
+ <li>Else <i>argCount</i> > 1,
+ <ol class="block">
+ <li>Let <i>firstArg</i> be the first argument.</li>
+ <li>Let <i>P</i> be <a href="#sec-tostring">ToString</a>(<i>firstArg</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>P</i>).</li>
+ <li>Let <i>k</i> be 2.</li>
+ <li>Repeat, while <i>k</i> < <i>argCount</i>
+ <ol class="block">
+ <li>Let <i>nextArg</i> be the <i>k</i>’th argument.</li>
+ <li>Let <i>nextArgString</i> be <a href="#sec-tostring">ToString</a>(<i>nextArg</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>nextArgString</i>).</li>
+ <li>Let <i>P</i> be the result of concatenating the previous value of <i>P</i>, the String <code>","</code> (a
+ comma), and <i>nextArgString</i>.</li>
+ <li>Increase <i>k</i> by 1.</li>
+ </ol>
+ </li>
+ <li>Let <i>bodyText</i> be the <i>k</i>’th argument.</li>
+ </ol>
+ </li>
+ <li>Let <i>bodyText</i> be <a href="#sec-tostring">ToString</a>(<i>bodyText</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>bodyText</i>).</li>
+ <li>Let <i>parameters</i> be the result of parsing <i>P</i>, interpreted as UTF-16 encoded Unicode text as described in
+ <a href="#sec-static-semantics-utf-16encoding">10.1.1</a><i>,</i> using <i>FormalParameters</i> as the goal symbol.
+ Throw a <b>SyntaxError</b> exception if the parse fails.</li>
+ <li>Let <i>funcBody</i> be the result of parsing <i>bodyText</i>, interpreted as UTF-16 encoded Unicode text as
+ described in <a href="#sec-static-semantics-utf-16encoding">10.1.1</a><i>,</i> using
+ <i>FunctionBody</i><sub>[Yield]</sub> as the goal symbol. Throw a <b>SyntaxError</b> exception if the parse fails or
+ if any static semantics errors are detected.</li>
+ <li>If IsSimpleParameterList of <i>parameters</i> is <b>false</b> and any element of the BoundNames of <i>parameters</i>
+ also occurs in the VarDeclaredNames of <i>funcBody</i>, then throw a <b>SyntaxError</b> exception.</li>
+ <li>If any element of the BoundNames of <i>parameters</i> also occurs in the LexicallyDeclaredNames of <i>funcBody</i>,
+ then throw a <b>SyntaxError</b> exception.</li>
+ <li>If <i>bodyText</i> is <a href="#sec-strict-mode-code">strict mode code</a> (<a href="#sec-strict-mode-code">see
+ 10.2.1</a>) then let <i>strict</i> be <b>true</b>, else let <i>strict</i> be <b>false</b>.</li>
+ <li>Let <i>scope</i> be <a href="#sec-global-environment-records">the Global Environment</a>.</li>
+ <li>Let <i>F</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>F</i>) is not Object or if <i>F</i> does not have a
+ [[Code]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> or if the value of [[Code]] is
+ not <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>C</i> be the function that is currently being evaluated.</li>
+ <li>Let <i>proto</i> be the result of <a
+ href="#sec-getprototypefromconstructor">GetPrototypeFromConstructor</a>(<i>C</i>,
+ <code>"%Generator%"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>proto</i>).</li>
+ <li>Let <i>F</i> be <a href="#sec-functionallocate">FunctionAllocate</a>(<i>proto</i> , <i>strict</i>,
+ <code>"generator"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>F</i>)..</li>
+ </ol>
+ </li>
+ <li>Let <i>isExtensible</i> be <a href="#sec-isextensible-o">IsExtensible</a>(<i>F</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>isExtensible</i>).</li>
+ <li>If <i>isExtensible</i> is <b>false</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>If the value of <i>F’s</i> [[FunctionKind]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> is not <code>"generator"</code>, then throw a <b>TypeError</b> exception.</li>
+ <li>Using <i>funcBody</i> as the <i>FunctionBody</i> production, let <i>body</i> be the supplemental syntactic grammar
+ production: <span class="prod"><span class="nt">GeneratorBody</span> <span class="geq">:</span> <span
+ class="nt">FunctionBody</span></span> .</li>
+ <li>Let <i>status</i> be <a href="#sec-functioninitialize">FunctionInitialize</a>(<i>F</i>, <span style="font-family:
+ sans-serif">Normal</span>, <i>strict</i>, <i>parameters</i>, <i>body, scope</i>).</li>
+ <li>Let <i>prototype</i> <a href="#sec-objectcreate">ObjectCreate</a>(<span style="font-family:
+ sans-serif">%GeneratorPrototype%</span>).</li>
+ <li>If ReferencesSuper(<i>funcBody</i>) is <b>true</b> or ReferencesSuper(<i>parameters</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>Perform <a href="#sec-makemethod">MakeMethod</a>(<i>F</i>, <b>undefined</b>, <b>undefined</b>).</li>
+ </ol>
+ </li>
+ <li>Let <i>status</i> be the result of the abstract operation <a href="#sec-makeconstructor">MakeConstructor</a> with
+ arguments <i>F</i>, <b>true</b>, and <i>prototype</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>Let <i>hasName</i> be <a href="#sec-hasownproperty">HasOwnProperty</a>(<i>F</i>, <code>"<b>name</b>"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>hasName</i>).</li>
+ <li>If <i>hasName</i> is <b>false</b>, then perform <a href="#sec-setfunctionname">SetFunctionName</a>(<i>F</i>,
+ <code>"<b>anonymous</b>"</code>).</li>
+ <li>Return <i>F</i>.</li>
+ </ol>
+
+ <p>A <code>prototype</code> property is automatically created for every function created using the
+ <code>GeneratorFunction</code> constructor, to provide for the possibility that the function will be used as a
+ constructor.</p>
+ </section>
+
+ <section id="sec-new-generatorfunction-argumentslist">
+ <h1><span class="secnum" id="sec-25.2.1.2"><a href="#sec-new-generatorfunction-argumentslist"
+ title="link to this section">25.2.1.2</a></span> new GeneratorFunction ( ... argumentsList)</h1>
+
+ <p>When <code>GeneratorFunction</code> is called as part of a <code>new</code> expression, it creates and initializes a
+ newly created object:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be the <code>GeneratorFunction</code> function object on which the <code>new</code> operator was
+ applied.</li>
+ <li>Let <i>argumentsList</i> be the <i>argumentsList</i> argument of the [[Construct]] internal method that was invoked
+ by the <code>new</code> operator.</li>
+ <li>Return the result of <a href="#sec-construct-f-argumentslist">Construct</a> (<i>F</i>, <i>argumentsList</i>).</li>
+ </ol>
+
+ <p>If <code>GeneratorFunction</code> is implemented as an <a href="#sec-ecmascript-function-objects">ECMAScript function
+ object</a>, its [[Construct]] internal method will perform the above steps.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-generatorfunction-constructor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-25.2.2"><a href="#sec-properties-of-the-generatorfunction-constructor"
+ title="link to this section">25.2.2</a></span> Properties of the GeneratorFunction Constructor</h1>
+
+ <p>The GeneratorFunction constructor is a built-in Function object that inherits from the Function constructor. The value
+ of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the GeneratorFunction
+ constructor is the intrinsic object %Function%.</p>
+
+ <p>The value of the [[Extensible]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the
+ GeneratorFunction constructor is <b>true</b>.</p>
+
+ <p>The value of the <code>name</code> property of the GeneratorFunction is <code>"<b>GeneratorFunction</b>"</code>.</p>
+
+ <p>The GeneratorFunction constructor has the following properties:</p>
+ </div>
+
+ <section id="sec-generatorfunction.length">
+ <h1><span class="secnum" id="sec-25.2.2.1"><a href="#sec-generatorfunction.length"
+ title="link to this section">25.2.2.1</a></span> GeneratorFunction.length</h1>
+
+ <p>This is a data property with a value of 1. This property has the attributes { [[Writable]]: <b>false</b>,
+ [[Enumerable]]: <b>false</b>, [[Configurable]]: <b>true</b> }.</p>
+ </section>
+
+ <section id="sec-generatorfunction.prototype">
+ <h1><span class="secnum" id="sec-25.2.2.2"><a href="#sec-generatorfunction.prototype"
+ title="link to this section">25.2.2.2</a></span> GeneratorFunction.prototype</h1>
+
+ <p>The initial value of <code>GeneratorFunction.prototype</code> is %Generator%, the standard built-in GeneratorFunction
+ prototype.</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-generatorfunction-@@create">
+ <h1><span class="secnum" id="sec-25.2.2.3"><a href="#sec-generatorfunction-@@create"
+ title="link to this section">25.2.2.3</a></span> GeneratorFunction[ @@create ] ( )</h1>
+
+ <p>The @@create method of an object <var>F</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be the <b>this</b> value.</li>
+ <li>Let <i>proto</i> be the result of <a
+ href="#sec-getprototypefromconstructor">GetPrototypeFromConstructor</a>(<i>F</i>, <code>"%Generator%"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>proto</i>).</li>
+ <li>Return <a href="#sec-functionallocate">FunctionAllocate</a>(<i>proto</i>, <b>false</b>,
+ <code>"generator"</code>).</li>
+ </ol>
+
+ <p>The value of the <code>name</code> property of this function is <code>"[Symbol.create]"</code>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <span class="value">false</span>, [[Enumerable]]: <span
+ class="value">false</span>, [[Configurable]]: <span class="value">true</span> }.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The GeneratorFunction <code>@@create</code> function passes <b>false</b> as the
+ <i>strict</i> parameter to <a href="#sec-functionallocate">FunctionAllocate</a>. This causes the allocated <a
+ href="#sec-ecmascript-function-objects">ECMAScript function object</a> to have the internal methods of a non-strict
+ function. The <code>GeneratorFunction</code> constructor may reset the functions [[Strict]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to <b>true</b>. It is up to the implementation
+ whether this also changes the internal methods.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-generatorfunction-prototype-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-25.2.3"><a href="#sec-properties-of-the-generatorfunction-prototype-object"
+ title="link to this section">25.2.3</a></span> Properties of the GeneratorFunction Prototype Object</h1>
+
+ <p>The GeneratorFunction prototype object is an ordinary object. It is not a function object and does not have a [[Code]]
+ <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> or any other of the internal slots listed in
+ <a href="#table-26">Table 26</a> or <a href="#table-47">Table 47</a>. In addition to being the value of the prototype
+ property of the %GeneratorFunction% intrinsic and is itself the %Generator% intrinsic.</p>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the
+ GeneratorFunction prototype object is the %FunctionPrototype% intrinsic object. The initial value of the [[Extensible]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the GeneratorFunction prototype object is
+ <b>true</b>.</p>
+ </div>
+
+ <section id="sec-generatorfunction.prototype.constructor">
+ <h1><span class="secnum" id="sec-25.2.3.1"><a href="#sec-generatorfunction.prototype.constructor"
+ title="link to this section">25.2.3.1</a></span> GeneratorFunction.prototype.constructor</h1>
+
+ <p>The initial value of <code>GeneratorFunction.prototype.constructor</code> is the intrinsic object
+ %GeneratorFunction%.</p>
+
+ <p>This property has the attributes { [[Writable]]: <span class="value">false</span>, [[Enumerable]]: <span
+ class="value">false</span>, [[Configurable]]: <span class="value">true</span> }.</p>
+ </section>
+
+ <section id="sec-generatorfunction.prototype.prototype">
+ <h1><span class="secnum" id="sec-25.2.3.2"><a href="#sec-generatorfunction.prototype.prototype"
+ title="link to this section">25.2.3.2</a></span> GeneratorFunction.prototype.prototype</h1>
+
+ <p>The value of <code>GeneratorFunction.prototype.prototype</code> is the %GeneratorPrototype% intrinsic object.</p>
+
+ <p>This property has the attributes { [[Writable]]: <span class="value">false</span>, [[Enumerable]]: <span
+ class="value">false</span>, [[Configurable]]: <span class="value">true</span> }.</p>
+ </section>
+
+ <section id="sec-generatorfunction.prototype-@@tostringtag">
+ <h1><span class="secnum" id="sec-25.2.3.3"><a href="#sec-generatorfunction.prototype-@@tostringtag"
+ title="link to this section">25.2.3.3</a></span> GeneratorFunction.prototype [ @@toStringTag ]</h1>
+
+ <p>The initial value of the @@toStringTag property is the string value <b>"<code>GeneratorFunction</code>"</b>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <span class="value">false</span>, [[Enumerable]]: <span
+ class="value">false</span>, [[Configurable]]: <span class="value">true</span> }.</p>
+ </section>
+
+ <section id="sec-generatorfunction.prototype-@@create">
+ <h1><span class="secnum" id="sec-25.2.3.4"><a href="#sec-generatorfunction.prototype-@@create"
+ title="link to this section">25.2.3.4</a></span> GeneratorFunction.prototype [ @@create ] ( )</h1>
+
+ <p>The @@create method of an object <var>F</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be the <b>this</b> value.</li>
+ <li>Let <i>obj</i> be the result of calling <a
+ href="#sec-ordinarycreatefromconstructor">OrdinaryCreateFromConstructor</a>(<i>F</i>,
+ <code>"%GeneratorPrototype%"</code>, ( [[GeneratorState]], [[GeneratorContext]]) ).</li>
+ <li>Return <i>obj</i>.</li>
+ </ol>
+
+ <p>The value of the <code>name</code> property of this function is <code>"[Symbol.create]"</code>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <span class="value">true</span>, [[Enumerable]]: <span
+ class="value">false</span>, [[Configurable]]: <span class="value">true</span> }.</p>
+ </section>
+ </section>
+
+ <section id="sec-generatorfunction-instances">
+ <div class="front">
+ <h1><span class="secnum" id="sec-25.2.4"><a href="#sec-generatorfunction-instances"
+ title="link to this section">25.2.4</a></span> GeneratorFunction Instances</h1>
+
+ <p>Every GeneratorFunction instance is an <a href="#sec-ecmascript-function-objects">ECMAScript function object</a> and
+ has the internal slots listed in <a href="#table-26">Table 26</a>. The value of the [[FunctionKind]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> for all such instances is
+ "<code>generator</code>".</p>
+
+ <p>The GeneratorFunction instances have the following own properties:</p>
+ </div>
+
+ <section id="sec-generatorfunction-instances-length">
+ <h1><span class="secnum" id="sec-25.2.4.1"><a href="#sec-generatorfunction-instances-length"
+ title="link to this section">25.2.4.1</a></span> length</h1>
+
+ <p>The value of the <code>length</code> property is an integer that indicates the typical number of arguments expected by
+ the GeneratorFunction. However, the language permits the function to be invoked with some other number of arguments. The
+ behaviour of a GeneratorFunction when invoked on a number of arguments other than the number specified by its
+ <code>length</code> property depends on the function.</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>true</b> }.</p>
+ </section>
+
+ <section id="sec-generatorfunction-instances-prototype">
+ <h1><span class="secnum" id="sec-25.2.4.2"><a href="#sec-generatorfunction-instances-prototype"
+ title="link to this section">25.2.4.2</a></span> prototype</h1>
+
+ <p>Whenever a GeneratorFunction instance is created another ordinary object is also created and is the initial value of
+ the generator function’s <code>prototype</code> property. The value of the prototype property is used to initialize
+ the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of a newly created Generator
+ object before the generator function object is invoked as a constructor for that newly created object.</p>
+
+ <p>This property has the attributes { [[Writable]]: <span class="value">false</span>, [[Enumerable]]: <span
+ class="value">false</span>, [[Configurable]]: <span class="value">true</span> }.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Unlike function instances, the object that is the value of the a
+ GeneratorFunction’s <code>prototype</code> property does not have a <code>constructor</code> property whose value
+ is the GeneratorFunction instance.</p>
+ </div>
+ </section>
+ </section>
+ </section>
+
+ <section id="sec-generator-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-25.3"><a href="#sec-generator-objects" title="link to this section">25.3</a></span>
+ Generator Objects</h1>
+
+ <p>A Generator object is an instance of a generator function and conforms to both the <i>Iterator</i> and <i>Iterable</i>
+ interfaces.</p>
+
+ <p>Generator instances directly inherit properties from the object that is the value of the <code>prototype</code> property
+ of the Generator function that created the instance. Generator instances indirectly inherit properties from the Generator
+ Prototype intrinsic, %GeneratorPrototype%.</p>
+ </div>
+
+ <section id="sec-properties-of-generator-prototype">
+ <div class="front">
+ <h1><span class="secnum" id="sec-25.3.1"><a href="#sec-properties-of-generator-prototype"
+ title="link to this section">25.3.1</a></span> Properties of Generator Prototype</h1>
+
+ <p>The Generator prototype object is the %GeneratorPrototype% intrinsic. It is also the initial value of the
+ <code>prototype</code> property of the %Generator% intrinsic (the GeneratorFrunction.prototype).</p>
+
+ <p>The Generator prototype is an ordinary object. It is not a Generator instance and does not have a [[GeneratorState]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</p>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the
+ Generator prototype object is the intrinsic object %ObjectPrototype% (<a
+ href="#sec-properties-of-the-object-prototype-object">19.1.3</a>). The initial value of the [[Extensible]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the Function prototype object is
+ <b>true</b>.</p>
+
+ <p>All Generator instances indirectly inherit properties of the Generator prototype object.</p>
+ </div>
+
+ <section id="sec-generator.prototype.constructor">
+ <h1><span class="secnum" id="sec-25.3.1.1"><a href="#sec-generator.prototype.constructor"
+ title="link to this section">25.3.1.1</a></span> Generator.prototype.constructor</h1>
+
+ <p>The initial value of <code>Generator.prototype.constructor</code> is the intrinsic object %Generator%.</p>
+
+ <p>This property has the attributes { [[Writable]]: <span class="value">false</span>, [[Enumerable]]: <span
+ class="value">false</span>, [[Configurable]]: <span class="value">true</span> }.</p>
+ </section>
+
+ <section id="sec-generator.prototype.next">
+ <h1><span class="secnum" id="sec-25.3.1.2"><a href="#sec-generator.prototype.next"
+ title="link to this section">25.3.1.2</a></span> Generator.prototype.next ( value )</h1>
+
+ <p>The <code>next</code> method performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>g</i> be the <b>this</b> value.</li>
+ <li>Return the result of <a href="#sec-generatorresume">GeneratorResume</a>(<i>g</i>, <i>value</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-generator.prototype.throw">
+ <h1><span class="secnum" id="sec-25.3.1.3"><a href="#sec-generator.prototype.throw"
+ title="link to this section">25.3.1.3</a></span> Generator.prototype.throw ( exception )</h1>
+
+ <p>The <code>throw</code> method performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>generator</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>generator</i>) is not Object, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>If <i>generator</i> does not have a [[GeneratorState]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>Let <i>state</i> be the value of <i>generator’s</i> [[GeneratorState]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>generator</i> also has a [[GeneratorContext]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>E</i> be <a href="#sec-completion-record-specification-type">Completion</a>{[[type]]: <span
+ style="font-family: sans-serif">throw</span>, [[value]]: <i>exception</i>, [[target]]: <span style="font-family:
+ sans-serif">empty</span>}.</li>
+ <li>If <i>state</i> is <code>"completed"</code>, then return <i>E</i>.</li>
+ <li>If <i>state</i> is neither <code>"suspendedStart"</code> nor <code>"suspendedYield"</code>, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>If <i>state</i> is <code>"suspendedStart"</code> then,
+ <ol class="block">
+ <li>Set <i>generator’s</i> [[GeneratorState]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to <code>"completed"</code>.</li>
+ <li>Once a generator enters the <code>"completed"</code> state it never leaves it and its associated <a
+ href="#sec-execution-contexts">execution context</a> is never resumed. Any execution state associated with
+ <i>generator</i> can be discard at this point.</li>
+ <li>Return <i>E</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>genContext</i> be the value of <i>generator’s</i> [[GeneratorContext]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>methodContext</i> be <a href="#sec-execution-contexts">the running execution context</a>.</li>
+ <li><a href="#sec-execution-contexts">Suspend</a> <i>methodContext</i>.</li>
+ <li>Set <i>generator’s</i> [[GeneratorState]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> to <code>"executing"</code>.</li>
+ <li>Push <i>genContext</i> onto <a href="#sec-execution-contexts">the execution context stack</a>; <i>genContext</i> is
+ now <a href="#sec-execution-contexts">the running execution context</a>.</li>
+ <li>Resume the <a href="#sec-execution-contexts">suspended</a> evaluation of <i>genContext</i> using <i>E</i> as the
+ result of the operation that <a href="#sec-execution-contexts">suspended</a> it. Let <i>result</i> be the value
+ returned by the resumed compation.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: When we return here, <i>genContext</i> has already been removed
+ from <a href="#sec-execution-contexts">the execution context stack</a> and <i>methodContext</i> is <a
+ href="#sec-execution-contexts">the currently running execution context</a>.</li>
+ <li>Return <i>result</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-generator.prototype-@@iterator">
+ <h1><span class="secnum" id="sec-25.3.1.4"><a href="#sec-generator.prototype-@@iterator"
+ title="link to this section">25.3.1.4</a></span> Generator.prototype [ @@iterator ] ( )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Return the <b>this</b> value.</li>
+ </ol>
+
+ <p>The value of the <code>name</code> property of this function is <code>"[Symbol.iterator]"</code>.</p>
+ </section>
+
+ <section id="sec-generator.prototype-@@tostringtag">
+ <h1><span class="secnum" id="sec-25.3.1.5"><a href="#sec-generator.prototype-@@tostringtag"
+ title="link to this section">25.3.1.5</a></span> Generator.prototype [ @@toStringTag ]</h1>
+
+ <p>The initial value of the @@toStringTag property is the string value <b>"<code>Generator</code>"</b>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <span class="value">false</span>, [[Enumerable]]: <span
+ class="value">false</span>, [[Configurable]]: <span class="value">true</span> }.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-generator-instances">
+ <h1><span class="secnum" id="sec-25.3.2"><a href="#sec-properties-of-generator-instances"
+ title="link to this section">25.3.2</a></span> Properties of Generator Instances</h1>
+
+ <p>Generator instances are initially created with the internal slots described in <a href="#table-47">Table 47</a>.</p>
+
+ <figure>
+ <figcaption><span id="table-47">Table 47</span> — Internal Slots of Generator Instances</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-top: 2px solid #000000">Internal Slot</th>
+ <th style="border-bottom: 1px solid #000000; border-left: 0px solid black; border-right: 1px solid #000000; border-top: 2px solid #000000">Description</th>
+ </tr>
+ <tr>
+ <td>[[GeneratorState]]</td>
+ <td>The current execution state of the generator. The possible values are: <b>undefined</b>, <code>"suspendedStart"</code><span style="font-family: Times New Roman">,</span> <code>"suspendedYield"</code><span style="font-family: Times New Roman">,</span> <code>"executing"</code>, and <code>"completed"</code><span style="font-family: Times New Roman">.</span></td>
+ </tr>
+ <tr>
+ <td>[[GeneratorContext]]</td>
+ <td>The <a href="#sec-execution-contexts">execution context</a> that is used when executing the code of this generator.</td>
+ </tr>
+ </table>
+ </figure>
+ </section>
+
+ <section id="sec-generator-abstract-operations">
+ <div class="front">
+ <h1><span class="secnum" id="sec-25.3.3"><a href="#sec-generator-abstract-operations"
+ title="link to this section">25.3.3</a></span> Generator Abstract Operations</h1>
+ </div>
+
+ <section id="sec-generatorstart">
+ <h1><span class="secnum" id="sec-25.3.3.1"><a href="#sec-generatorstart" title="link to this section">25.3.3.1</a></span>
+ GeneratorStart (generator, generatorBody)</h1>
+
+ <p>The abstract operation GeneratorStart with arguments <span style="font-family: Times New Roman"><i>generator</i> and
+ <i>generatorBody</i></span> performs the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: The value of <i>generator’s</i> [[GeneratorState]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is <b>undefined</b>.</li>
+ <li>Let <i>genContext</i> be <a href="#sec-execution-contexts">the running execution context</a>.</li>
+ <li>Set the Generator component of <i>genContext</i> to <i>generator.</i></li>
+ <li>Set the code evaluation state of <i>genContext</i> such that when evaluation is resumed for that <a
+ href="#sec-execution-contexts">execution context</a> the following steps will be performed:
+ <ol class="block">
+ <li>Let <i>result</i> be the result of evaluating <i>generatorBody</i>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: If we return here, the generator either threw an exception or
+ performed either an implicit or explicit return.</li>
+ <li>Remove <i>genContext</i> from <a href="#sec-execution-contexts">the execution context stack</a> and restore the
+ <a href="#sec-execution-contexts">execution context</a> that is at the top of <a
+ href="#sec-execution-contexts">the execution context stack</a> as <a href="#sec-execution-contexts">the running
+ execution context</a>.</li>
+ <li>Set <i>generator’s</i> [[GeneratorState]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to <code>"completed"</code>.</li>
+ <li>Once a generator enters the <code>"completed"</code> state it never leaves it and its associated <a
+ href="#sec-execution-contexts">execution context</a> is never resumed. Any execution state associated with
+ <i>generator</i> can be discard at this point.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>result</i>).</li>
+ <li>Return <a href="#sec-createiterresultobject">CreateIterResultObject</a>(<i>result</i>, <b>true</b>).</li>
+ </ol>
+ </li>
+ <li>Set <i>generator’s</i> [[GeneratorContext]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> to <i>genContext</i>.</li>
+ <li>Set <i>generator’s</i> [[GeneratorState]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> to <code>"suspendedStart"</code>.</li>
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<i>generator</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-generatorresume">
+ <h1><span class="secnum" id="sec-25.3.3.2"><a href="#sec-generatorresume" title="link to this section">25.3.3.2</a></span>
+ GeneratorResume ( generator, value )</h1>
+
+ <p>The abstract operation GeneratorResume with arguments <span style="font-family: Times New Roman"><i>generator</i> and
+ <i>value</i></span> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>generator</i>) is not Object, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>If <i>generator</i> does not have a [[GeneratorState]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>Let <i>state</i> be the value of <i>generator’s</i> [[GeneratorState]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>generator</i> also has a [[GeneratorContext]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>state</i> is <code>"completed"</code>, then return <a
+ href="#sec-createiterresultobject">CreateIterResultObject</a>(<b>undefined</b>, <b>true</b>).</li>
+ <li>If <i>state</i> is neither <code>"suspendedStart"</code> nor <code>"suspendedYield"</code>, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>Let <i>genContext</i> be the value of <i>generator’s</i> [[GeneratorContext]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>methodContext</i> be <a href="#sec-execution-contexts">the running execution context</a>.</li>
+ <li><a href="#sec-execution-contexts">Suspend</a> <i>methodContext</i>.</li>
+ <li>Set <i>generator’s</i> [[GeneratorState]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> to <code>"executing"</code>.</li>
+ <li>Push <i>genContext</i> onto <a href="#sec-execution-contexts">the execution context stack</a>; <i>genContext</i> is
+ now <a href="#sec-execution-contexts">the running execution context</a>.</li>
+ <li>Resume the <a href="#sec-execution-contexts">suspended</a> evaluation of <i>genContext</i> using <a
+ href="#sec-normalcompletion">NormalCompletion</a>(<i>value</i>) as the result of the operation that <a
+ href="#sec-execution-contexts">suspended</a> it. Let <i>result</i> be the value returned by the resumed
+ computation.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: When we return here, <i>genContext</i> has already been removed
+ from <a href="#sec-execution-contexts">the execution context stack</a> and <i>methodContext</i> is <a
+ href="#sec-execution-contexts">the currently running execution context</a>.</li>
+ <li>Return <i>result</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-generatoryield">
+ <h1><span class="secnum" id="sec-25.3.3.3"><a href="#sec-generatoryield" title="link to this section">25.3.3.3</a></span>
+ GeneratorYield ( iterNextObj )</h1>
+
+ <p>The abstract operation GeneratorYield with argument <var>iterNextObj</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>iterNextObj</i> is an Object that implemented the
+ <i>IteratorResult</i> interface.</li>
+ <li>Let <i>genContext</i> be <a href="#sec-execution-contexts">the running execution context</a>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>genContext</i> is the <a
+ href="#sec-execution-contexts">execution context</a> of a generator.</li>
+ <li>Let <i>generator</i> be the value of the Generator component of <i>genContext</i>.</li>
+ <li>Set the value of <i>generator’s</i> [[GeneratorState]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to <code>"suspendedYield"</code>.</li>
+ <li>Remove <i>genContext</i> from <a href="#sec-execution-contexts">the execution context stack</a> and restore the <a
+ href="#sec-execution-contexts">execution context</a> that is at the top of <a href="#sec-execution-contexts">the
+ execution context stack</a> as <a href="#sec-execution-contexts">the running execution context</a>.</li>
+ <li>Set the code evaluation state of <i>genContext</i> such that when evaluation is resumed with a <a
+ href="#sec-completion-record-specification-type">Completion</a> <i>resumptionValue</i> the following steps will be
+ performed:
+ <ol class="block">
+ <li>Return <i>resumptionValue</i>.</li>
+ <li>NOTE: This returns to the evaluation of the <i>YieldExpression</i> production that originally called this
+ abstract operation.</li>
+ </ol>
+ </li>
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<i>iterNextObj</i>).</li>
+ <li>NOTE: This returns to the evaluation of the operation that had most previously resumed evaluation of
+ <i>genContext</i>.</li>
+ </ol>
+ </section>
+ </section>
+ </section>
+
+ <section id="sec-promise-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-25.4"><a href="#sec-promise-objects" title="link to this section">25.4</a></span> Promise
+ Objects</h1>
+
+ <p>A Promise is an object that is used as a placeholder for the eventual results of a deferred (and possibly asynchronous)
+ computation.</p>
+
+ <p>Any Promise object is in one of three mutually exclusive states: <i>fulfilled</i>, <i>rejected</i>, and
+ <i>pending</i>:</p>
+
+ <ul>
+ <li>
+ <p>A promise <code>p</code> is fulfilled if <code>p.then(f, r)</code> will immediately enqueue a Task to call the
+ function <code>f</code>.</p>
+ </li>
+
+ <li>
+ <p>A promise <code>p</code> is rejected if <code>p.then(f, r)</code> will immediately enqueue a Task to call the
+ function <code>r</code>.</p>
+ </li>
+
+ <li>
+ <p>A promise is pending if it is neither fulfilled nor rejected.</p>
+ </li>
+ </ul>
+
+ <p>A promise is said to be <i>settled</i> if it is not pending, i.e. if it is either fulfilled or rejected.</p>
+
+ <p>A promise is <i>resolved</i> if it is settled or if it has been "locked in" to match the state of another promise.
+ Attempting to resolve or reject a resolved promise has no effect. A promise is <i>unresolved</i> if it is not resolved. An
+ unresolved promise is always in the pending state. A resolved promise may be pending, fulfilled or rejected.</p>
+ </div>
+
+ <section id="sec-promise-abstract-operations">
+ <div class="front">
+ <h1><span class="secnum" id="sec-25.4.1"><a href="#sec-promise-abstract-operations"
+ title="link to this section">25.4.1</a></span> Promise Abstract Operations</h1>
+ </div>
+
+ <section id="sec-promisecapability-records">
+ <div class="front">
+ <h1><span class="secnum" id="sec-25.4.1.1"><a href="#sec-promisecapability-records"
+ title="link to this section">25.4.1.1</a></span> PromiseCapability Records</h1>
+
+ <p>A PromiseCapability is a Record value used to encapsulate a promise object along with the functions that are capable
+ of resolving or rejecting that promise object. PromiseCapability records are produced by the <a
+ href="#sec-newpromisecapability">NewPromiseCapability</a> abstract operation.</p>
+
+ <p>PromiseCapability Records have the fields listed in <a href="#table-48">Table 48</a>.</p>
+
+ <figure>
+ <figcaption><span id="table-48">Table 48</span> — PromiseCapability Record Fields</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 0px solid black; border-top: 2px solid #000000">Field Name</th>
+ <th style="border-bottom: 1px solid #000000; border-left: 0px solid black; border-right: 1px solid #000000; border-top: 2px solid #000000">Value</th>
+ <th style="border-bottom: 1px solid #000000; border-right: 1px solid #000000; border-top: 2px solid #000000">Meaning</th>
+ </tr>
+ <tr>
+ <td>[[Promise]]</td>
+ <td>An object</td>
+ <td>An object that is usable as a promise.</td>
+ </tr>
+ <tr>
+ <td>[[Resolve]]</td>
+ <td>A function object</td>
+ <td>The function that is used to resolve the given promise object.</td>
+ </tr>
+ <tr>
+ <td>[[Reject]]</td>
+ <td>A function object</td>
+ <td>The function that is used to reject the given promise object.</td>
+ </tr>
+ </table>
+ </figure>
+ </div>
+
+ <section id="sec-ifabruptrejectpromise">
+ <h1><span class="secnum" id="sec-25.4.1.1.1"><a href="#sec-ifabruptrejectpromise"
+ title="link to this section">25.4.1.1.1</a></span> IfAbruptRejectPromise ( value, capability )</h1>
+
+ <p>IfAbruptRejectPromise is a short hand for a sequence of algorithm steps that use a PromiseCapability record. An
+ algorithm step of the form:</p>
+
+ <ol class="proc">
+ <li>IfAbruptRejectPromise(<i>value</i>, <i>capability</i>).</li>
+ </ol>
+
+ <p>means the same thing as:</p>
+
+ <ol class="proc">
+ <li>If <i>value</i> is an <a href="#sec-completion-record-specification-type">abrupt completion</a>,
+ <ol class="block">
+ <li>Let <i>rejectResult</i> be the result of calling the [[Call]] internal method of <i>capability</i>.[[Reject]]
+ with <b>undefined</b> as <i>thisArgument</i> and (<i>value</i>.[[value]]) as <i>argumentsList</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>rejectResult</i>).</li>
+ <li>Return <i>capability</i>.[[Promise]].</li>
+ </ol>
+ </li>
+ <li>Else if <i>value</i> is a <a href="#sec-completion-record-specification-type">Completion Record</a>, then let
+ <i>value</i> be <i>value</i>.[[value]].</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-promisereaction-records">
+ <h1><span class="secnum" id="sec-25.4.1.2"><a href="#sec-promisereaction-records"
+ title="link to this section">25.4.1.2</a></span> PromiseReaction Records</h1>
+
+ <p>The PromiseReaction is a Record value used to store information about how a promise should react when it becomes
+ resolved or rejected with a given value. PromiseReaction records are created by the <code>then</code> method of the
+ Promise prototype, and are used by a <a href="#sec-promisereactiontask">PromiseReactionTask</a>.</p>
+
+ <p>PromiseReaction records have the fields listed in <a href="#table-49">Table 49</a>.</p>
+
+ <figure>
+ <figcaption><span id="table-49">Table 49</span> — PromiseReaction Record Fields</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 0px solid black; border-top: 2px solid #000000">Field Name</th>
+ <th style="border-bottom: 1px solid #000000; border-left: 0px solid black; border-right: 1px solid #000000; border-top: 2px solid #000000">Value</th>
+ <th style="border-bottom: 1px solid #000000; border-right: 1px solid #000000; border-top: 2px solid #000000">Meaning</th>
+ </tr>
+ <tr>
+ <td>[[Capabilities]]</td>
+ <td>A PromiseCapability record</td>
+ <td>The capabilities of the promise for which this record provides a reaction handler.</td>
+ </tr>
+ <tr>
+ <td>[[Handler]]</td>
+ <td>A function object or a String</td>
+ <td>The function that should be applied to the incoming value, and whose return value will govern what happens to the derived promise. If [[Handler]] is <code>"Identity"</code> it is equivalent to a function that simply returns its first argument. If [[Handler]] is <code>"Thrower"</code> it is equivalent to a function that throws its first argument as an exception.</td>
+ </tr>
+ </table>
+ </figure>
+ </section>
+
+ <section id="sec-createresolvingfunctions">
+ <div class="front">
+ <h1><span class="secnum" id="sec-25.4.1.3"><a href="#sec-createresolvingfunctions"
+ title="link to this section">25.4.1.3</a></span> CreateResolvingFunctions ( promise )</h1>
+
+ <p>When CreateResolvingFunctions is performed with argument <var>promise</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>alreadyResolved</i> be a new Record { [[value]]: <b>false</b> }.</li>
+ <li>Let <i>resolve</i> be a new built-in function object as defined in Promise Resolve Functions (<a
+ href="#sec-promise-resolve-functions">25.4.1.4</a>).</li>
+ <li>Set the [[Promise]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>resolve</i>
+ to <i>promise</i>.</li>
+ <li>Set the [[AlreadyResolved]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of
+ <i>resolve</i> to <i>alreadyResolved</i>.</li>
+ <li>Let <i>reject</i> be a new built-in function object as defined in Promise Reject Functions (<a
+ href="#sec-promise-reject-functions">25.4.1.3.1</a>).</li>
+ <li>Set the [[Promise]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>reject</i>
+ to <i>promise</i>.</li>
+ <li>Set the [[AlreadyResolved]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of
+ <i>reject</i> to <i>alreadyResolved</i>.</li>
+ <li>Return a new Record { [[Resolve]]: <i>resolve</i>, [[Reject]]: <i>reject</i> }.</li>
+ </ol>
+ </div>
+
+ <section id="sec-promise-reject-functions">
+ <h1><span class="secnum" id="sec-25.4.1.3.1"><a href="#sec-promise-reject-functions"
+ title="link to this section">25.4.1.3.1</a></span> Promise Reject Functions</h1>
+
+ <p>A promise reject function is an anonymous built-in function that has [[Promise]] and [[AlreadyResolved]] internal
+ slots.</p>
+
+ <p>When a promise reject function <var>F</var> is called with argument <var>reason</var>, the following steps are
+ taken:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>F</i> has a [[Promise]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> whose value is an Object.</li>
+ <li>Let <i>promise</i> be the value of <i>F</i>'s [[Promise]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>alreadyResolved</i> be the value of <i>F</i>'s [[AlreadyResolved]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>alreadyResolved</i>.[[value]] is <b>true</b>, then return <b>undefined</b>.</li>
+ <li>Set <i>alreadyResolved</i>.[[value]] to <b>true</b>.</li>
+ <li>Return <a href="#sec-rejectpromise">RejectPromise</a>(<i>promise</i>, <i>reason</i>).</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-promise-resolve-functions">
+ <h1><span class="secnum" id="sec-25.4.1.4"><a href="#sec-promise-resolve-functions"
+ title="link to this section">25.4.1.4</a></span> Promise Resolve Functions</h1>
+
+ <p>A promise resolve function is an anonymous built-in function that has [[Promise]] and [[AlreadyResolved]] internal
+ slots.</p>
+
+ <p>When a promise resolve function <var>F</var> is called with argument <var>resolution</var>, the following steps are
+ taken:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>F</i> has a [[Promise]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> whose value is an Object.</li>
+ <li>Let <i>promise</i> be the value of <i>F</i>'s [[Promise]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>alreadyResolved</i> be the value of <i>F</i>'s [[AlreadyResolved]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>alreadyResolved</i>.[[value]] is <b>true</b>, then return <b>undefined</b>.</li>
+ <li>Set <i>alreadyResolved</i>.[[value]] to <b>true</b>.</li>
+ <li>If <a href="#sec-samevalue">SameValue</a>(<i>resolution</i>, <i>promise</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>selfResolutionError</i> be a newly-created <b>TypeError</b> object.</li>
+ <li>Return <a href="#sec-rejectpromise">RejectPromise</a>(<i>promise</i>, <i>selfResolutionError</i>).</li>
+ </ol>
+ </li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>resolution</i>) is not Object, then
+ <ol class="block">
+ <li>Return <a href="#sec-fulfillpromise">FulfillPromise</a>(<i>promise</i>, <i>resolution</i>).</li>
+ </ol>
+ </li>
+ <li>Let <i>then</i> be <a href="#sec-get-o-p">Get</a>(<i>resolution</i>, <code>"then"</code>).</li>
+ <li>If <i>then</i> is an <a href="#sec-completion-record-specification-type">abrupt completion</a>, then
+ <ol class="block">
+ <li>Return <a href="#sec-rejectpromise">RejectPromise</a>(<i>promise</i>, <i>then</i>.[[value]]).</li>
+ </ol>
+ </li>
+ <li>Let <i>then</i> be <i>then</i>.[[value]].</li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>then</i>) is <b>false</b>, then
+ <ol class="block">
+ <li>Return <a href="#sec-fulfillpromise">FulfillPromise</a>(<i>promise</i>, <i>resolution</i>).</li>
+ </ol>
+ </li>
+ <li>Perform EnqueueTas (<code>"PromiseTasks",</code> <a
+ href="#sec-promiseresolvethenabletask">PromiseResolveThenableTask</a>, (<i>promise</i>, <i>resolution</i>,
+ <i>then</i>))</li>
+ <li>Return <b>undefined</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-fulfillpromise">
+ <h1><span class="secnum" id="sec-25.4.1.5"><a href="#sec-fulfillpromise" title="link to this section">25.4.1.5</a></span>
+ FulfillPromise ( promise, value)</h1>
+
+ <p>When the FulfillPromise abstract operation is called with arguments <var>promise</var> and <var>value</var> the
+ following steps are taken:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: the value of <i>promise</i>'s [[PromiseState]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is <code>"pending"</code>.</li>
+ <li>Let <i>reactions</i> be the value of <i>promise</i>'s [[PromiseFulfillReactions]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Set the value of <i>promise</i>'s [[PromiseResult]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to <i>value</i>.</li>
+ <li>Set the value of <i>promise</i>'s [[PromiseFulfillReactions]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to <b>undefined</b>.</li>
+ <li>Set the value of <i>promise</i>'s [[PromiseRejectReactions]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to <b>undefined</b>.</li>
+ <li>Set the value of <i>promise</i>'s [[PromiseState]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to <code>"fulfilled"</code>.</li>
+ <li>Return <a href="#sec-triggerpromisereactions">TriggerPromiseReactions</a>(<i>reactions</i>, <i>value</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-newpromisecapability">
+ <div class="front">
+ <h1><span class="secnum" id="sec-25.4.1.6"><a href="#sec-newpromisecapability"
+ title="link to this section">25.4.1.6</a></span> NewPromiseCapability ( C )</h1>
+
+ <p>The abstract operation NewPromiseCapability takes a constructor function, and attempts to use that constructor
+ function in the fashion of the built-in <code>Promise</code> constructor to create a Promise object and extract its
+ resolve and reject functions. The promise plus the resolve and reject functions are used to initialize a new
+ PromiseCapability record which is returned as the value of this abstract operation.</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-isconstructor">IsConstructor</a>(<i>C</i>) is <b>false</b>, throw a <b>TypeError</b>
+ exception.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>C</i> is a constructor function that supports the parameter
+ conventions of the <code>Promise</code> constructor (<a href="#sec-promise">see 25.4.3.1</a>).</li>
+ <li>Let <i>promise</i> be <a href="#sec-createfromconstructor">CreateFromConstructor</a>(<i>C</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>promise</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>promise</i>) is not Object, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>Return <a href="#sec-createpromisecapabilityrecord">CreatePromiseCapabilityRecord</a>(<i>promise</i>,
+ <i>C</i>).</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> This abstract operation supports Promise subclassing, as it is generic on any
+ constructor that calls a passed executor function argument in the same way as the Promise constructor. It is used to
+ generalize static methods of the Promise constructor to any subclass.</p>
+ </div>
+ </div>
+
+ <section id="sec-createpromisecapabilityrecord">
+ <h1><span class="secnum" id="sec-25.4.1.6.1"><a href="#sec-createpromisecapabilityrecord"
+ title="link to this section">25.4.1.6.1</a></span> CreatePromiseCapabilityRecord( promise, constructor )</h1>
+
+ <p>When the CreatePromiseCapabilityRecord abstract operation is called with arguments <var>promise</var> and
+ <var>constructor</var> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>promise</i> is an uninitialized object created as if by
+ invoking @@create on <i>constructor</i>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a
+ href="#sec-isconstructor">IsConstructor</a>(<i>constructor</i>) is <b>true</b>.</li>
+ <li>Let <i>promiseCapability</i> be a new PromiseCapability { [[Promise]]: <i>promise</i>, [[Resolve]]:
+ <b>undefined</b>, [[Reject]]: <b>undefined</b> }.</li>
+ <li>Let <i>executor</i> be a new built-in function object as defined in <a
+ href="#sec-getcapabilitiesexecutor-functions">GetCapabilitiesExecutor Functions</a> (<a
+ href="#sec-createpromisecapabilityrecord">25.4.1.6.1</a>).</li>
+ <li>Set the [[Capability]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of
+ <i>executor</i> to <i>promiseCapability</i>.</li>
+ <li>Let <i>constructorResult</i> be the result of calling the [[Call]] internal method of <i>constructor</i>, passing
+ <i>promise</i> and (<i>executor</i>) as the arguments.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>constructorResult</i>).</li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>promiseCapability</i>.[[Resolve]]) is <b>false</b>, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>promiseCapability</i>.[[Reject]]) is <b>false</b>, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>constructorResult</i>) is Object and <a
+ href="#sec-samevalue">SameValue</a>(<i>promise</i>, <i>constructorResult</i>) is <b>false</b>, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>Return <i>promiseCapability</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-getcapabilitiesexecutor-functions">
+ <h1><span class="secnum" id="sec-25.4.1.6.2"><a href="#sec-getcapabilitiesexecutor-functions"
+ title="link to this section">25.4.1.6.2</a></span> GetCapabilitiesExecutor Functions</h1>
+
+ <p>A GetCapabilitiesExecutor function is an anonymous built-in function that has a [[Capability]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</p>
+
+ <p>When a GetCapabilitiesExecutor function <var>F</var> is called with arguments <var>resolve</var> and
+ <var>reject</var> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>F</i> has a [[Capability]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> whose value is a PromiseCapability
+ Record.</li>
+ <li>Let <i>promiseCapability</i> be the value of <i>F</i>'s [[Capability]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>promiseCapability</i>.[[Resolve]] is not <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>If <i>promiseCapability</i>.[[Reject]] is not <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Set <i>promiseCapability</i>.[[Resolve]] to <i>resolve</i>.</li>
+ <li>Set <i>promiseCapability</i>.[[Reject]] to <i>reject</i>.</li>
+ <li>Return <b>undefined</b>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-ispromise">
+ <h1><span class="secnum" id="sec-25.4.1.7"><a href="#sec-ispromise" title="link to this section">25.4.1.7</a></span>
+ IsPromise ( x )</h1>
+
+ <p>The abstract operation IsPromise checks for the promise brand on an object.</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>x</i>) is not Object, return <b>false</b>.</li>
+ <li>If <i>x</i> does not have a [[PromiseState]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a>, return <b>false</b>.</li>
+ <li>If the value of <i>x</i>'s [[PromiseState]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> is <b>undefined</b>, return <b>false</b>.</li>
+ <li>Return <b>true</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-rejectpromise">
+ <h1><span class="secnum" id="sec-25.4.1.8"><a href="#sec-rejectpromise" title="link to this section">25.4.1.8</a></span>
+ RejectPromise ( promise, reason)</h1>
+
+ <p>When the RejectPromise abstract operation is called with arguments <var>promise</var> and <var>reason</var> the
+ following steps are taken:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: the value of <i>promise</i>'s [[PromiseState]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is <code>"pending"</code>.</li>
+ <li>Let <i>reactions</i> be the value of <i>promise</i>'s [[PromiseRejectReactions]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Set the value of <i>promise</i>'s [[PromiseResult]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to <i>reason</i>.</li>
+ <li>Set the value of <i>promise</i>'s [[PromiseFulfillReactions]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to <b>undefined</b>.</li>
+ <li>Set the value of <i>promise</i>'s [[PromiseRejectReactions]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to <b>undefined</b>.</li>
+ <li>Set the value of <i>promise</i>'s [[PromiseState]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to <code>"rejected"</code>.</li>
+ <li>Return <a href="#sec-triggerpromisereactions">TriggerPromiseReactions</a>(<i>reactions</i>, <i>reason</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-triggerpromisereactions">
+ <h1><span class="secnum" id="sec-25.4.1.9"><a href="#sec-triggerpromisereactions"
+ title="link to this section">25.4.1.9</a></span> TriggerPromiseReactions ( reactions, argument )</h1>
+
+ <p>The abstract operation TriggerPromiseReactions takes a collection of functions to trigger in the next Task, and calls
+ them, passing each the given argument. Typically, these reactions will modify a previously-returned promise, possibly
+ calling in to a user-supplied handler before doing so.</p>
+
+ <ol class="proc">
+ <li>Repeat for each <i>reaction</i> in <i>reactions</i>, in original insertion order
+ <ol class="block">
+ <li>Perform <a href="#sec-enqueuetask">EnqueueTask</a>(<code>"PromiseTasks",</code> <a
+ href="#sec-promisereactiontask">PromiseReactionTask</a>, (<i>reaction</i>, <i>argument</i>)).</li>
+ </ol>
+ </li>
+ <li>Return <b>undefined</b>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-promise-tasks">
+ <div class="front">
+ <h1><span class="secnum" id="sec-25.4.2"><a href="#sec-promise-tasks" title="link to this section">25.4.2</a></span>
+ Promise Tasks</h1>
+ </div>
+
+ <section id="sec-promisereactiontask">
+ <h1><span class="secnum" id="sec-25.4.2.1"><a href="#sec-promisereactiontask"
+ title="link to this section">25.4.2.1</a></span> PromiseReactionTask ( reaction, argument )</h1>
+
+ <p>The task PromiseReactionTask with parameters <var>reaction</var> and <var>argument</var> applies the appropriate
+ handler to the incoming value, and uses the handler's return value to resolve or reject the derived promise associated
+ with that handler.</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>reaction</i> is a PromiseReaction Record.</li>
+ <li>Let <i>promiseCapability</i> be <i>reaction</i>.[[Capabilities]].</li>
+ <li>Let <i>handler</i> be <i>reaction</i>.[[Handler]].</li>
+ <li>If <i>handler</i> is <code>"Identity"</code>, then let <i>handlerResult</i> be <a
+ href="#sec-normalcompletion">NormalCompletion</a>(<i>argument</i>).</li>
+ <li>Else If <i>handler</i> is <code>"Thrower"</code>, then let <i>handlerResult</i> be <a
+ href="#sec-completion-record-specification-type">Completion</a>{[[type]]: <span style="font-family:
+ sans-serif">throw</span>, [[value]]: <i>argument</i>, [[target]]: <span style="font-family:
+ sans-serif">empty</span>}.</li>
+ <li>Else, let <i>handlerResult</i> be the result of calling the [[Call]] internal method of <i>handler</i> passing
+ <b>undefined</b> as <i>thisArgument</i> and (<i>argument</i>) as <i>argumentsList</i>.</li>
+ <li>If <i>handlerResult</i> is an <a href="#sec-completion-record-specification-type">abrupt completion</a>, then
+ <ol class="block">
+ <li>Let <i>status</i> be the result of calling the [[Call]] internal method of <i>promiseCapability</i>.[[Reject]]
+ passing <b>undefined</b> as <i>thisArgument</i> and (<i>handlerResult</i>.[[value]]) as
+ <i>argumentsList</i>.</li>
+ <li>NextTask <i>status</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>handlerResult</i> be <i>handlerResult</i>.[[value]].</li>
+ <li>Let <i>status</i> be the result of calling the [[Call]] internal method of <i>promiseCapability</i>.[[Resolve]]
+ passing <b>undefined</b> as <i>thisArgument</i> and (<i>handlerResult</i>) as <i>argumentsList.</i></li>
+ <li>NextTask <i>status</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-promiseresolvethenabletask">
+ <h1><span class="secnum" id="sec-25.4.2.2"><a href="#sec-promiseresolvethenabletask"
+ title="link to this section">25.4.2.2</a></span> PromiseResolveThenableTask ( promiseToResolve, thenable, then)</h1>
+
+ <p>The task PromiseResolveThenableTask with parameters <var>promiseToResolve</var>, <var>thenable</var>, and
+ <var>then</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>resolvingFunctions</i> be <a
+ href="#sec-createresolvingfunctions">CreateResolvingFunctions</a>(<i>promise</i>).</li>
+ <li>Let <i>thenCallResult</i> be the result of calling the [[Call]] internal method of <i>then</i> passing
+ <i>thenable</i> as the <i>thisArgument</i> and (<i>resolvingFunctions</i>.[[Resolve]],
+ <i>resolvingFunctions</i>.[[Reject]]) as <i>argumentsList</i>.</li>
+ <li>If <i>thenCallResult</i> is an <a href="#sec-completion-record-specification-type">abrupt completion</a>,
+ <ol class="block">
+ <li>Let <i>status</i> be the result of calling the [[Call]] internal method of <i>resolvingFunctions</i>.[[Reject]]
+ passing <b>undefined</b> as the <i>thisArgument</i> and (<i>thenCallResult</i>.[[value]]) as
+ <i>argumentsList.</i></li>
+ <li>NextTask <i>status.</i></li>
+ </ol>
+ </li>
+ <li>NextTask <i>thenCallResult</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> This Task uses the supplied thenable and its <code>then</code> method to resolve the
+ given promise. This process must take place as a Task to ensure that the evaluation of the <code>then</code> method
+ occurs after evaluation of any surrounding code has completed.</p>
+ </div>
+ </section>
+ </section>
+
+ <section id="sec-promise-constructor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-25.4.3"><a href="#sec-promise-constructor" title="link to this section">25.4.3</a></span>
+ The Promise Constructor</h1>
+
+ <p>The Promise constructor is the %Promise% intrinsic object and the initial value of the <code>Promise</code> property of
+ the global object. When <code>Promise</code> is called as a function rather than as a constructor, it initializes its
+ <b>this</b> value with the internal state necessary to support the <code>Promise.prototype</code> methods.</p>
+
+ <p>The <code>Promise</code> constructor is designed to be subclassable. It may be used as the value in an
+ <code>extends</code> clause of a class definition. Subclass constructors that intend to inherit the specified
+ <code>Promise</code> behaviour must include a <code>super</code> call to <code>Promise</code>.</p>
+ </div>
+
+ <section id="sec-promise">
+ <div class="front">
+ <h1><span class="secnum" id="sec-25.4.3.1"><a href="#sec-promise" title="link to this section">25.4.3.1</a></span>
+ Promise ( executor )</h1>
+
+ <p>When the <code>Promise</code> function is called with argument <var>executor</var> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>promise</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>promise</i>) is not Object, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>If <i>promise</i> does not have a [[PromiseState]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>promise</i>'s [[PromiseState]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>
+ is not <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>executor</i>) is <b>false</b>, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>Return <a href="#sec-initializepromise">InitializePromise</a>(<i>promise</i>, <i>executor</i>).</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <i>executor</i> argument must be a function object. It is called for initiating
+ and reporting completion of the possibly deferred action represented by this Promise object. The executor is called
+ with two arguments: <i>resolve</i> and <i>reject</i>. These are functions that may be used by the <i>executor</i>
+ function to report eventual completion or failure of the deferred computation. Returning from the executor function
+ does not mean that the deferred action has been completed but only that the request to eventually perform the deferred
+ action has been accepted.</p>
+
+ <p>The <i>resolve</i> function that is passed to an <i>executor</i> function accepts a single argument. The
+ <i>executor</i> code may eventually call the <i>resolve</i> function to indicate that it wishes to resolve the
+ associated Promise object. The argument passed to the <i>resolve</i> function represents the eventual value of the
+ deferred action and can be either the actual fulfillment value or another Promise object which will provide the value
+ if it is fulfilled.</p>
+
+ <p>The <i>reject</i> function that is passed to an <i>executor</i> function accepts a single argument. The
+ <i>executor</i> code may eventually call the <i>reject</i> function to indicate that the associated Promise is
+ rejected and will never be fulfilled. The argument passed to the <i>reject</i> function is used as the rejection value
+ of the promise. Typically it will be an <code>Error</code> object.</p>
+ </div>
+
+ <p>The resolve and reject functions passed to an <var>executor</var> function by the Promise constructor have the
+ capability to actually resolve and reject the associated promise. Subclasses may have different constructor behaviour
+ that passes in customized values for resolve and reject.</p>
+ </div>
+
+ <section id="sec-initializepromise">
+ <h1><span class="secnum" id="sec-25.4.3.1.1"><a href="#sec-initializepromise"
+ title="link to this section">25.4.3.1.1</a></span> InitializePromise ( promise, executor )</h1>
+
+ <p>The abstract operation InitializePromise initializes a newly allocated <var>promise</var> object using an
+ <var>executor</var> function.</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>promise</i> has a [[PromiseState]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> and its value is <b>undefined.</b></li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a href="#sec-iscallable">IsCallable</a>(<i>executor</i>) is
+ <b>true</b>.</li>
+ <li>Set <i>promise</i>'s [[PromiseState]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>
+ to <code>"pending"</code>.</li>
+ <li>Set <i>promise</i>'s [[PromiseFulfillReactions]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to a new empty <a
+ href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Set <i>promise</i>'s [[PromiseRejectReactions]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> to a new empty <a href="#sec-list-and-record-specification-type">List</a>.</li>
+ <li>Let <i>resolvingFunctions</i> be <a
+ href="#sec-createresolvingfunctions">CreateResolvingFunctions</a>(<i>promise</i>).</li>
+ <li>Let <i>completion</i> be the result of calling the [[Call]] internal method of <i>executor</i> with
+ <b>undefined</b> as <i>thisArgument</i> and (<i>resolvingFunctions</i>.[[Resolve]],
+ <i>resolvingFunctions</i>.[[Reject]]) as <i>argumentsList</i>.</li>
+ <li>If <i>completion</i> is an <a href="#sec-completion-record-specification-type">abrupt completion</a>, then
+ <ol class="block">
+ <li>Let <i>status</i> be the result of calling the [[Call]] internal method of
+ <i>resolvingFunctions</i>.[[Reject]] with <b>undefined</b> as <i>thisArgument</i> and
+ (<i>completion</i>.[[value]]) as <i>argumentsList</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ </ol>
+ </li>
+ <li>Return <i>promise</i>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-new-promise-argumentslist">
+ <h1><span class="secnum" id="sec-25.4.3.2"><a href="#sec-new-promise-argumentslist"
+ title="link to this section">25.4.3.2</a></span> new Promise ( ... argumentsList )</h1>
+
+ <p>When <code>Promise</code> is called as part of a <code>new</code> expression it is a constructor: it initializes a
+ newly created object.</p>
+
+ <p><code>Promise</code> called as part of a new expression with argument list <i>argumentsList</i> performs the following
+ steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be the Promise function object on which the <code>new</code> operator was applied.</li>
+ <li>Let <i>argumentsList</i> be the <i>argumentsList</i> argument of the [[Construct]] internal method that was invoked
+ by the <code>new</code> operator.</li>
+ <li>Return <a href="#sec-construct-f-argumentslist">Construct</a>(<i>F</i>, <i>argumentsList</i>).</li>
+ </ol>
+
+ <p>If Promise is implemented as an <a href="#sec-ecmascript-function-objects">ECMAScript function object</a>, its
+ [[Construct]] internal method will perform the above steps.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-promise-constructor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-25.4.4"><a href="#sec-properties-of-the-promise-constructor"
+ title="link to this section">25.4.4</a></span> Properties of the Promise Constructor</h1>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the
+ <code>Promise</code> constructor is the <code>Function</code> prototype object (<a
+ href="#sec-properties-of-the-function-prototype-object">19.2.3</a>).</p>
+
+ <p>Besides the <code>length</code> property (whose value is 1), the Promise constructor has the following properties:</p>
+ </div>
+
+ <section id="sec-promise.all">
+ <div class="front">
+ <h1><span class="secnum" id="sec-25.4.4.1"><a href="#sec-promise.all" title="link to this section">25.4.4.1</a></span>
+ Promise.all ( iterable )</h1>
+
+ <p>The <code>all</code> function returns a new promise which is fulfilled with an array of fulfillment values for the
+ passed promises, or rejects with the reason of the first passed promise that rejects. It resoves all elements of the
+ passed iterable to promises as it runs this algorithm.</p>
+
+ <ol class="proc">
+ <li>Let <i>C</i> be the <b>this</b> value.</li>
+ <li>Let <i>promiseCapability</i> be <a href="#sec-newpromisecapability">NewPromiseCapability</a>(<i>C</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>promiseCapability</i>).</li>
+ <li>Let <i>iterator</i> be <a href="#sec-getiterator">GetIterator</a>(<i>iterable</i>).</li>
+ <li><a href="#sec-ifabruptrejectpromise">IfAbruptRejectPromise</a>(<i>iterator</i>, <i>promiseCapability</i>).</li>
+ <li>Let <i>values</i> be <a href="#sec-arraycreate">ArrayCreate</a>(0).</li>
+ <li>Let <i>remainingElementsCount</i> be a new Record { [[value]]: 1 }.</li>
+ <li>Let <i>index</i> be 0.</li>
+ <li>Repeat
+ <ol class="block">
+ <li>Let <i>next</i> be <a href="#sec-iteratorstep">IteratorStep</a>(<i>iterator</i>).</li>
+ <li><a href="#sec-ifabruptrejectpromise">IfAbruptRejectPromise</a>(<i>next</i>, <i>promiseCapability</i>).</li>
+ <li>If <i>next</i> is <b>false</b>,
+ <ol class="block">
+ <li>Set <i>remainingElementsCount</i>.[[value]] to <i>remainingElementsCount</i>.[[value]] - 1.</li>
+ <li>If <i>remainingElementsCount</i>.[[value]] is 0,
+ <ol class="block">
+ <li>Let <i>resolveResult</i> be the result of calling the [[Call]] internal method of
+ <i>promiseCapability</i>.[[Resolve]] with <b>undefined</b> as <i>thisArgument</i> and (<i>values</i>)
+ as <i>argumentsList</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>resolveResult</i>).</li>
+ </ol>
+ </li>
+ <li>Return <i>promiseCapability</i>.[[Promise]].</li>
+ </ol>
+ </li>
+ <li>Let <i>nextValue</i> be <a href="#sec-iteratorvalue">IteratorValue</a>(<i>next</i>).</li>
+ <li><a href="#sec-ifabruptrejectpromise">IfAbruptRejectPromise</a>(<i>nextValue</i>,
+ <i>promiseCapability</i>).</li>
+ <li>Let <i>nextPromise</i> be <a href="#sec-invoke">Invoke</a>(<i>C</i>, <code>"resolve"</code>,
+ (<i>nextValue</i>)).</li>
+ <li><a href="#sec-ifabruptrejectpromise">IfAbruptRejectPromise</a>(<i>nextPromise</i>,
+ <i>promiseCapability</i>).</li>
+ <li>Let <i>resolveElement</i> be a new built-in function object as defined in Promise.all Resolve Element
+ Functions.</li>
+ <li>Set the [[AlreadyCalled]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of
+ <i>resolveElement</i> to <b>false</b>.</li>
+ <li>Set the [[Index]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of
+ <i>resolveElement</i> to <i>index</i>.</li>
+ <li>Set the [[Values]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of
+ <i>resolveElement</i> to <i>values</i>.</li>
+ <li>Set the [[Capabilities]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of
+ <i>resolveElement</i> to <i>promiseCapability</i>.</li>
+ <li>Set the [[RemainingElements]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of
+ <i>resolveElement</i> to <i>remainingElementsCount</i>.</li>
+ <li>Set <i>remainingElementsCount</i>.[[value]] to <i>remainingElementsCount</i>.[[value]] + 1.</li>
+ <li>Let <i>result</i> be <a href="#sec-invoke">Invoke</a>(<i>nextPromise</i>, <code>"then"</code>,
+ (<i>resolveElement</i>, <i>promiseCapability</i>.[[Reject]])).</li>
+ <li><a href="#sec-ifabruptrejectpromise">IfAbruptRejectPromise</a>(<i>result</i>, <i>promiseCapability</i>).</li>
+ <li>Set <i>index</i> to <i>index</i> + 1.</li>
+ </ol>
+ </li>
+ </ol>
+
+ <p class="Note">Note: The <code>all</code> function requires its <b>this</b> value to be a constructor function that
+ supports the parameter conventions of the <code>Promise</code> constructor.</p>
+ </div>
+
+ <section id="sec-promise.all-resolve-element-functions">
+ <h1><span class="secnum" id="sec-25.4.4.1.1"><a href="#sec-promise.all-resolve-element-functions"
+ title="link to this section">25.4.4.1.1</a></span> Promise.all Resolve Element Functions</h1>
+
+ <p>A <a href="#sec-promise.all">Promise.all</a> resolve element function is an anonymous built-in function that is used
+ to resolve a specific <a href="#sec-promise.all">Promise.all</a> element. Each <a
+ href="#sec-promise.all">Promise.all</a> resolve element function has [[Index]], [[Values]], [[Capabilities]],
+ [[RemainingElements]], and [[AlreadyCalled]] internal slots.</p>
+
+ <p>When a <a href="#sec-promise.all">Promise.all</a> resolve element function <var>F</var> is called with argument
+ <var>x</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>If the value of <i>F</i>'s [[AlreadyCalled]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> is <b>true</b>, then return <b>undefined</b>.</li>
+ <li>Set the value of <i>F</i>'s [[AlreadyCalled]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> to <b>true</b>.</li>
+ <li>Let <i>index</i> be the value of <i>F</i>'s [[Index]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>values</i> be the value of <i>F</i>'s [[Values]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>promiseCapability</i> be the value of <i>F</i>'s [[Capabilities]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>remainingElementsCount</i> be the value of <i>F</i>'s [[RemainingElements]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>result</i> be <a href="#sec-createdataproperty">CreateDataProperty</a>(<i>values</i>, <a
+ href="#sec-tostring">ToString</a>(<i>index</i>), <i>x</i>).</li>
+ <li><a href="#sec-ifabruptrejectpromise">IfAbruptRejectPromise</a>(<i>result</i>, <i>promiseCapability</i>).</li>
+ <li>Set <i>remainingElementsCount</i>.[[value]] to <i>remainingElementsCount</i>.[[value]] - 1.</li>
+ <li>If <i>remainingElementsCount</i>.[[value]] is 0,
+ <ol class="block">
+ <li>Return the result of calling the [[Call]] internal method of <i>promiseCapability</i>.[[Resolve]] with
+ <b>undefined</b> as <i>thisArgument</i> and (<i>values</i>) as <i>argumentsList</i>.</li>
+ </ol>
+ </li>
+ <li>Return <b>undefined</b>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-promise.prototype">
+ <h1><span class="secnum" id="sec-25.4.4.2"><a href="#sec-promise.prototype"
+ title="link to this section">25.4.4.2</a></span> Promise.prototype</h1>
+
+ <p>The initial value of <code>Promise.prototype</code> is the Promise prototype object (<a
+ href="#sec-allocatepromise">25.4.4.6.1</a>).</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-promise.race">
+ <h1><span class="secnum" id="sec-25.4.4.3"><a href="#sec-promise.race" title="link to this section">25.4.4.3</a></span>
+ Promise.race ( iterable )</h1>
+
+ <p>The <code>race</code> function returns a new promise which is settled in the same way as the first passed promise to
+ settle. It resolves all elements of the passed <span style="font-family: Times New Roman">iterable</span> to promises as
+ it runs this algorithm.</p>
+
+ <ol class="proc">
+ <li>Let <i>C</i> be the <b>this</b> value.</li>
+ <li>Let <i>promiseCapability</i> be <a href="#sec-newpromisecapability">NewPromiseCapability</a>(<i>C</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>promiseCapability</i>).</li>
+ <li>Let <i>iterator</i> be <a href="#sec-getiterator">GetIterator</a>(<i>iterable</i>).</li>
+ <li><a href="#sec-ifabruptrejectpromise">IfAbruptRejectPromise</a>(<i>iterator</i>, <i>promiseCapability</i>).</li>
+ <li>Repeat
+ <ol class="block">
+ <li>Let <i>next</i> be <a href="#sec-iteratorstep">IteratorStep</a>(<i>iterator</i>).</li>
+ <li><a href="#sec-ifabruptrejectpromise">IfAbruptRejectPromise</a>(<i>next</i>, <i>promiseCapability</i>).</li>
+ <li>If <i>next</i> is <b>false</b>, return <i>promiseCapability</i>.[[Promise]].</li>
+ <li>Let <i>nextValue</i> be <a href="#sec-iteratorvalue">IteratorValue</a>(<i>next</i>).</li>
+ <li><a href="#sec-ifabruptrejectpromise">IfAbruptRejectPromise</a>(<i>nextValue</i>, <i>promiseCapability</i>).</li>
+ <li>Let <i>nextPromise</i> be <a href="#sec-invoke">Invoke</a>(<i>C</i>, <code>"resolve"</code>,
+ (<i>nextValue</i>)).</li>
+ <li><a href="#sec-ifabruptrejectpromise">IfAbruptRejectPromise</a>(<i>nextPromise</i>,
+ <i>promiseCapability</i>).</li>
+ <li>Let <i>result</i> be <a href="#sec-invoke">Invoke</a>(<i>nextPromise</i>, <code>"then"</code>,
+ (<i>promiseCapability</i>.[[Resolve]], <i>promiseCapability</i>.[[Reject]])).</li>
+ <li><a href="#sec-ifabruptrejectpromise">IfAbruptRejectPromise</a>(<i>result</i>, <i>promiseCapability</i>).</li>
+ </ol>
+ </li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>race</code> function requires its <b>this</b> value to be a constructor
+ function that supports the parameter conventions of the <code>Promise</code> constructor. It also requires that its
+ <b>this</b> value provides a <code>resolve</code> method.</p>
+ </div>
+ </section>
+
+ <section id="sec-promise.reject">
+ <h1><span class="secnum" id="sec-25.4.4.4"><a href="#sec-promise.reject" title="link to this section">25.4.4.4</a></span>
+ Promise.reject ( r )</h1>
+
+ <p>The <code>reject</code> function returns a new promise rejected with the passed argument.</p>
+
+ <ol class="proc">
+ <li>Let <i>C</i> be the <b>this</b> value.</li>
+ <li>Let <i>promiseCapability</i> be <a href="#sec-newpromisecapability">NewPromiseCapability</a>(<i>C</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>promiseCapability</i>).</li>
+ <li>Let <i>rejectResult</i> be the result of calling the [[Call]] internal method of <i>promiseCapability</i>.[[Reject]]
+ with <b>undefined</b> as <i>thisArgument</i> and (<i>r</i>) as <i>argumentsList</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>rejectResult</i>).</li>
+ <li>Return <i>promiseCapability</i>.[[Promise]].</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>reject</code> function requires that its <b>this</b> value to be a constructor
+ function that supports the parameter conventions of the <code>Promise</code> constructor.</p>
+ </div>
+ </section>
+
+ <section id="sec-promise.resolve">
+ <h1><span class="secnum" id="sec-25.4.4.5"><a href="#sec-promise.resolve" title="link to this section">25.4.4.5</a></span>
+ Promise.resolve ( x )</h1>
+
+ <p>The <code>resolve</code> function returns either a new promise resolved with the passed argument, or the argument
+ itself if the argument a promise produced by this construtor.</p>
+
+ <ol class="proc">
+ <li>Let <i>C</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ispromise">IsPromise</a>(<i>x</i>) is <b>true</b>,
+ <ol class="block">
+ <li>Let <i>constructor</i> be the value of <i>x</i>'s [[PromiseConstructor]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <a href="#sec-samevalue">SameValue</a>(<i>constructor</i>, <i>C</i>) is <b>true</b>, return <i>x</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>promiseCapability</i> be <a href="#sec-newpromisecapability">NewPromiseCapability</a>(<i>C</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>promiseCapability</i>).</li>
+ <li>Let <i>resolveResult</i> be the result of calling the [[Call]] internal method of
+ <i>promiseCapability</i>.[[Resolve]] with <b>undefined</b> as <i>thisArgument</i> and (<i>x</i>) as
+ <i>argumentsList</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>resolveResult</i>).</li>
+ <li>Return <i>promiseCapability</i>.[[Promise]].</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>resolve</code> function requires that its <b>this</b> value to be a
+ constructor function that supports the parameter conventions of the <code>Promise</code> constructor.</p>
+ </div>
+ </section>
+
+ <section id="sec-promise-@@create">
+ <div class="front">
+ <h1><span class="secnum" id="sec-25.4.4.6"><a href="#sec-promise-@@create"
+ title="link to this section">25.4.4.6</a></span> Promise [ @@create ] ( )</h1>
+
+ <p>The @@create method of a Promise function object <var>F</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be the <b>this</b> value.</li>
+ <li>Return <a href="#sec-allocatepromise">AllocatePromise</a>(<i>F</i>).</li>
+ </ol>
+
+ <p>The value of the <code>name</code> property of this function is <code>"[Symbol.create]"</code>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>true</b> }.</p>
+ </div>
+
+ <section id="sec-allocatepromise">
+ <h1><span class="secnum" id="sec-25.4.4.6.1"><a href="#sec-allocatepromise"
+ title="link to this section">25.4.4.6.1</a></span> AllocatePromise ( constructor )</h1>
+
+ <p>The abstract operation AllocatePromise allocates a new promise object using the <var>constructor</var> argument.</p>
+
+ <ol class="proc">
+ <li>Let <i>obj</i> be <a
+ href="#sec-ordinarycreatefromconstructor">OrdinaryCreateFromConstructor</a>(<i>constructor</i>,
+ <code>"%PromisePrototype%"</code>, ([[PromiseState]], [[PromiseConstructor]], [[PromiseResult]],
+ [[PromiseFulfillReactions]], [[PromiseRejectReactions]]) ).</li>
+ <li>Set the value of <i>obj’s</i> [[PromiseConstructor]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to <i>constructor</i>.</li>
+ <li>Return <i>obj</i>.</li>
+ </ol>
+ </section>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-promise-prototype-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-25.4.5"><a href="#sec-properties-of-the-promise-prototype-object"
+ title="link to this section">25.4.5</a></span> Properties of the Promise Prototype Object</h1>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the
+ Promise prototype object is the standard built-in Object prototype object (<a
+ href="#sec-properties-of-the-object-prototype-object">19.1.3</a>). The Promise prototype object is an ordinary object. It
+ does not have a [[PromiseState]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> or any of the
+ other internal slots of Promise instances.</p>
+ </div>
+
+ <section id="sec-promise.prototype.catch">
+ <h1><span class="secnum" id="sec-25.4.5.1"><a href="#sec-promise.prototype.catch"
+ title="link to this section">25.4.5.1</a></span> Promise.prototype.catch ( onRejected )</h1>
+
+ <p>When the <code>catch</code> method is called with argument <var>onRejected</var> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>promise</i> be the <b>this</b> value.</li>
+ <li>Return <a href="#sec-invoke">Invoke</a>(<i>promise</i>, <code>"then"</code>, (<b>undefined</b>,
+ <i>onRejected</i>)).</li>
+ </ol>
+ </section>
+
+ <section id="sec-promise.prototype.constructor">
+ <h1><span class="secnum" id="sec-25.4.5.2"><a href="#sec-promise.prototype.constructor"
+ title="link to this section">25.4.5.2</a></span> Promise.prototype.constructor</h1>
+
+ <p>The initial value of <code>Promise.prototype.constructor</code> is the standard built-in Promise constructor.</p>
+ </section>
+
+ <section id="sec-promise.prototype.then">
+ <h1><span class="secnum" id="sec-25.4.5.3"><a href="#sec-promise.prototype.then"
+ title="link to this section">25.4.5.3</a></span> Promise.prototype.then ( onFulfilled , onRejected )</h1>
+
+ <p>When the <code>then</code> method is called with arguments <var>onFulfilled</var> and <var>onRejected</var> the
+ following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>promise</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ispromise">IsPromise</a>(<i>promise</i>) is <b>false</b>, throw a <b>TypeError</b> exception.</li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>onFulfilled</i>) is <b>false</b>, then
+ <ol class="block">
+ <li>Let <i>onFulfilled</i> be <code>"Identity"</code>.</li>
+ </ol>
+ </li>
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>onRejected</i>) is <b>false</b>, then
+ <ol class="block">
+ <li>Let <i>onRejected</i> be <code>"Thrower"</code>.</li>
+ </ol>
+ </li>
+ <li>Let <i>C</i> be <a href="#sec-get-o-p">Get</a>(<i>promise</i>, <code>"constructor"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>C</i>).</li>
+ <li>Let <i>promiseCapability</i> be <a href="#sec-newpromisecapability">NewPromiseCapability</a>(<i>C</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>promiseCapability</i>).</li>
+ <li>Let <i>fulfillReaction</i> be the PromiseReaction { [[Capabilities]]: <i>promiseCapability</i>, [[Handler]]:
+ <i>onFulfilled</i> }.</li>
+ <li>Let <i>rejectReaction</i> be the PromiseReaction { [[Capabilities]]: <i>promiseCapability</i>, [[Handler]]:
+ <i>onRejected</i>}.</li>
+ <li>If the value of <i>promise</i>'s [[PromiseState]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> is <code>"pending"</code>,
+ <ol class="block">
+ <li>Append <i>fulfillReaction</i> as the last element of the <a
+ href="#sec-list-and-record-specification-type">List</a> that is the value of <i>promise</i>'s
+ [[PromiseFulfillReactions]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Append <i>rejectReaction</i> as the last element of the <a
+ href="#sec-list-and-record-specification-type">List</a> that is the value of <i>promise</i>'s
+ [[PromiseRejectReactions]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ </ol>
+ </li>
+ <li>Else if the value of <i>promise</i>'s [[PromiseState]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is <code>"fulfilled"</code>,
+ <ol class="block">
+ <li>Let <i>value</i> be the value of <i>promise</i>'s [[PromiseResult]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Perform <a href="#sec-enqueuetask">EnqueueTask</a>(<code>"PromiseTasks"</code>, <a
+ href="#sec-promisereactiontask">PromiseReactionTask</a>, (<i>fulfillReaction</i>, <i>value</i>)).</li>
+ </ol>
+ </li>
+ <li>Else if the value of <i>promise</i>'s [[PromiseState]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is <code>"rejected"</code>,
+ <ol class="block">
+ <li>Let <i>reason</i> be the value of <i>promise</i>'s [[PromiseResult]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Perform <a href="#sec-enqueuetask">EnqueueTask</a>(<code>"PromiseTasks"</code>, <a
+ href="#sec-promisereactiontask">PromiseReactionTask</a>, (<i>rejectReaction</i>, <i>reason</i>)).</li>
+ </ol>
+ </li>
+ <li>Return <i>promiseCapability</i>.[[Promise]].</li>
+ </ol>
+ </section>
+
+ <section id="sec-promise.prototype-@@tostringtag">
+ <h1><span class="secnum" id="sec-25.4.5.4"><a href="#sec-promise.prototype-@@tostringtag"
+ title="link to this section">25.4.5.4</a></span> Promise.prototype [ @@toStringTag ]</h1>
+
+ <p>The initial value of the @@toStringTag property is the string value <b>"<code>Promise</code>"</b>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <span class="value">false</span>, [[Enumerable]]: <span
+ class="value">false</span>, [[Configurable]]: <span class="value">true</span> }.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-promise-instances">
+ <h1><span class="secnum" id="sec-25.4.6"><a href="#sec-properties-of-promise-instances"
+ title="link to this section">25.4.6</a></span> Properties of Promise Instances</h1>
+
+ <p>Promise instances are ordinary objects that inherit properties from the Promise prototype object (the intrinsic,
+ %PromisePrototype%). Promise instances are initially created with the internal slots described in <a href="#table-50">Table
+ 50</a>.</p>
+
+ <figure>
+ <figcaption><span id="table-50">Table 50</span> — Internal Slots of Promise Instances</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-top: 2px solid #000000">Internal Slot</th>
+ <th style="border-bottom: 1px solid #000000; border-left: 0px solid black; border-right: 1px solid #000000; border-top: 2px solid #000000">Description</th>
+ </tr>
+ <tr>
+ <td>[[PromiseState]]</td>
+ <td>A string value that governs how a promise will react to incoming calls to its <code>then</code> method. The possible values are: <b>undefined</b>, <code>"pending"</code><span style="font-family: Times New Roman">,</span> <code>"fulfilled"</code>, and <code>"rejected"</code><span style="font-family: Times New Roman">.</span></td>
+ </tr>
+ <tr>
+ <td>[[PromiseConstructor]]</td>
+ <td>The function object that was used to construct this promise. Checked by the <code>resolve</code> method of the <code>Promise</code> constructor.</td>
+ </tr>
+ <tr>
+ <td>[[PromiseResult]]</td>
+ <td>The value with which the promise has been fulfilled or rejected, if any. Only meaningful if <span style="font-family: Times New Roman">[[PromiseState]]</span> is not <code>"pending"</code>.</td>
+ </tr>
+ <tr>
+ <td>[[PromiseFulfillReactions]]</td>
+ <td>A <a href="#sec-list-and-record-specification-type">List</a> of PromiseReaction records to be processed when/if the promise transitions from the <code>"pending"</code> state to the<code>"fulfilled"</code> state.</td>
+ </tr>
+ <tr>
+ <td>[[PromiseRejectReactions]]</td>
+ <td>A <a href="#sec-list-and-record-specification-type">List</a> of PromiseReaction records to be processed when/if the promise transitions from the <code>"pending"</code> state to the<code>"rejected"</code> state.</td>
+ </tr>
+ </table>
+ </figure>
+ </section>
+ </section>
+</section>
+
+<section id="sec-reflection">
+ <div class="front">
+ <h1><span class="secnum" id="sec-26"><a href="#sec-reflection" title="link to this section">26</a></span> Reflection</h1>
+ </div>
+
+ <section id="sec-reflect-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-26.1"><a href="#sec-reflect-object" title="link to this section">26.1</a></span> The
+ Reflect Object</h1>
+
+ <p>The Reflect object is a single ordinary object.</p>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the Reflect
+ object is the standard built-in Object prototype object (<a
+ href="#sec-properties-of-the-object-prototype-object">19.1.3</a>).</p>
+
+ <p>The Reflect object is not a function object. It does not have a [[Construct]] internal method; it is not possible to use
+ the Reflect object as a constructor with the <code>new</code> operator. The Reflect object also does not have a [[Call]]
+ internal method; it is not possible to invoke the Reflect object as a function.</p>
+ </div>
+
+ <section id="sec-reflect.apply">
+ <h1><span class="secnum" id="sec-26.1.1"><a href="#sec-reflect.apply" title="link to this section">26.1.1</a></span>
+ Reflect.apply ( target, thisArgument, argumentsList )</h1>
+
+ <p>When the <code>apply</code> function is called with arguments <span style="font-family: Times New Roman"><i>target</i>,
+ <i>thisArgument</i></span>, and <var>argumentsList</var> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>target</i>) is <b>false</b>, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>Let <i>args</i> be <a href="#sec-createlistfromarraylike">CreateListFromArrayLike</a>(<i>argumentsList</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>args</i>).</li>
+ <li>Perform the <a href="#sec-preparefortailcall">PrepareForTailCall</a> abstract operation.</li>
+ <li>Return the result of calling the [[Call]] internal method of <i>target</i> with arguments <i>thisArgument</i> and
+ <i>args</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-reflect.construct">
+ <h1><span class="secnum" id="sec-26.1.2"><a href="#sec-reflect.construct" title="link to this section">26.1.2</a></span>
+ Reflect.construct ( target, argumentsList )</h1>
+
+ <p>When the <code>construct</code> function is called with arguments <var>target</var> and <var>argumentsList</var> the
+ following steps are taken:</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-isconstructor">IsConstructor</a>(<i>target</i>) is <b>false</b>, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>Let <i>args</i> be <a href="#sec-createlistfromarraylike">CreateListFromArrayLike</a>(<i>argumentsList</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>args</i>).</li>
+ <li>Return the result of calling the [[Construct]] internal method of <i>target</i> with argument <i>args</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-reflect.defineproperty">
+ <h1><span class="secnum" id="sec-26.1.3"><a href="#sec-reflect.defineproperty"
+ title="link to this section">26.1.3</a></span> Reflect.defineProperty ( target, propertyKey, attributes )</h1>
+
+ <p>When the <code>defineProperty</code> function is called with arguments <span style="font-family: Times New
+ Roman"><i>target</i>, <i>propertyKey</i></span>, and <var>attributes</var> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>obj</i> be <a href="#sec-toobject">ToObject</a>(<i>target</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>obj</i>).</li>
+ <li>Let <i>key</i> be <a href="#sec-topropertykey">ToPropertyKey</a>(<i>propertyKey</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>key</i>).</li>
+ <li>Let <i>desc</i> be the result of calling <a href="#sec-topropertydescriptor">ToPropertyDescriptor</a> with
+ <i>attributes</i> as the argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>desc</i>).</li>
+ <li>Return the result of calling the [[DefineOwnProperty]] internal method of <i>obj</i> with arguments <i>key</i>, and
+ <i>desc</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-reflect.deleteproperty">
+ <h1><span class="secnum" id="sec-26.1.4"><a href="#sec-reflect.deleteproperty"
+ title="link to this section">26.1.4</a></span> Reflect.deleteProperty ( target, propertyKey )</h1>
+
+ <p>When the <code>deleteProperty</code> function is called with arguments <span style="font-family: Times New
+ Roman"><i>target</i> and <i>propertyKey</i></span>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>obj</i> be <a href="#sec-toobject">ToObject</a>(<i>target</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>obj</i>).</li>
+ <li>Let <i>key</i> be <a href="#sec-topropertykey">ToPropertyKey</a>(<i>propertyKey</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>key</i>).</li>
+ <li>Return the result of calling the [[Delete]] internal method of <i>obj</i> with argument <i>key</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-reflect.enumerate">
+ <h1><span class="secnum" id="sec-26.1.5"><a href="#sec-reflect.enumerate" title="link to this section">26.1.5</a></span>
+ Reflect.enumerate ( target )</h1>
+
+ <p>When the <code>enumerate</code> function is called with argument <var>target</var> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>obj</i> be <a href="#sec-toobject">ToObject</a>(<i>target</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>obj</i>).</li>
+ <li>Let <i>iterator</i> be the result of calling the [[Enumerate]] internal method of <i>obj</i>.</li>
+ <li>Return <i>iterator</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-reflect.get">
+ <h1><span class="secnum" id="sec-26.1.6"><a href="#sec-reflect.get" title="link to this section">26.1.6</a></span>
+ Reflect.get ( target, propertyKey [ , receiver ])</h1>
+
+ <p>When the <code>get</code> function is called with arguments <span style="font-family: Times New Roman"><i>target</i>,
+ <i>propertyKey</i></span>, and <var>receiver</var> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>obj</i> be <a href="#sec-toobject">ToObject</a>(<i>target</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>obj</i>).</li>
+ <li>Let <i>key</i> be <a href="#sec-topropertykey">ToPropertyKey</a>(<i>propertyKey</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>key</i>).</li>
+ <li>If <i>receiver</i> is not present, then
+ <ol class="block">
+ <li>Let <i>receiver</i> be <i>target</i>.</li>
+ </ol>
+ </li>
+ <li>Return the result of calling the [[Get]] internal method of <i>obj</i> with arguments <i>key</i>, and
+ <i>receiver</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-reflect.getownpropertydescriptor">
+ <h1><span class="secnum" id="sec-26.1.7"><a href="#sec-reflect.getownpropertydescriptor"
+ title="link to this section">26.1.7</a></span> Reflect.getOwnPropertyDescriptor ( target, propertyKey )</h1>
+
+ <p>When the <code>getOwnPropertyDescriptor</code> function is called with arguments <span style="font-family: Times New
+ Roman"><i>target</i> and <i>propertyKey</i></span>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>obj</i> be <a href="#sec-toobject">ToObject</a>(<i>target</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>obj</i>).</li>
+ <li>Let <i>key</i> be <a href="#sec-topropertykey">ToPropertyKey</a>(<i>propertyKey</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>key</i>).</li>
+ <li>Let <i>desc</i> be the result of calling the [[GetOwnProperty]] internal method of <i>obj</i> with argument
+ <i>key</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>desc</i>).</li>
+ <li>Return the result of calling <a href="#sec-frompropertydescriptor">FromPropertyDescriptor</a>(<i>desc</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-reflect.getprototypeof">
+ <h1><span class="secnum" id="sec-26.1.8"><a href="#sec-reflect.getprototypeof"
+ title="link to this section">26.1.8</a></span> Reflect.getPrototypeOf ( target )</h1>
+
+ <p>When the <code>getPrototypeOf</code> function is called with argument <var>target</var> the following steps are
+ taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>obj</i> be <a href="#sec-toobject">ToObject</a>(<i>target</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>obj</i>).</li>
+ <li>Return the result of calling the [[GetPrototypeOf]] internal method of <i>obj</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-reflect.has">
+ <h1><span class="secnum" id="sec-26.1.9"><a href="#sec-reflect.has" title="link to this section">26.1.9</a></span>
+ Reflect.has ( target, propertyKey )</h1>
+
+ <p>When the <code>has</code> function is called with arguments <span style="font-family: Times New Roman"><i>target</i> and
+ <i>propertyKey</i></span>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>obj</i> be <a href="#sec-toobject">ToObject</a>(<i>target</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>obj</i>).</li>
+ <li>Let <i>key</i> be <a href="#sec-topropertykey">ToPropertyKey</a>(<i>propertyKey</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>key</i>).</li>
+ <li>Return the result of calling the [[HasProperty]] internal method of <i>obj</i> with argument <i>key</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-reflect.isextensible">
+ <h1><span class="secnum" id="sec-26.1.10"><a href="#sec-reflect.isextensible"
+ title="link to this section">26.1.10</a></span> Reflect.isExtensible (target)</h1>
+
+ <p>When the <code>isExtensible</code> function is called with argument <var>target</var> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>obj</i> be <a href="#sec-toobject">ToObject</a>(<i>target</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>obj</i>).</li>
+ <li>Return the result of calling the [[IsExtensible]] internal method of <i>obj</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-reflect.ownkeys">
+ <h1><span class="secnum" id="sec-26.1.11"><a href="#sec-reflect.ownkeys" title="link to this section">26.1.11</a></span>
+ Reflect.ownKeys ( target )</h1>
+
+ <p>When the <code>ownKeys</code> function is called with argument <var>target</var> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>obj</i> be <a href="#sec-toobject">ToObject</a>(<i>target</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>obj</i>).</li>
+ <li>Return the result of calling the [[OwnPropertyKeys]] internal method of <i>obj</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-reflect.preventextensions">
+ <h1><span class="secnum" id="sec-26.1.12"><a href="#sec-reflect.preventextensions"
+ title="link to this section">26.1.12</a></span> Reflect.preventExtensions ( target )</h1>
+
+ <p>When the <code>preventExtensions</code> function is called with argument <var>target</var>, the following steps are
+ taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>obj</i> be <a href="#sec-toobject">ToObject</a>(<i>target</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>obj</i>).</li>
+ <li>Return the result of calling the [[PreventExtensions]] internal method of <i>obj</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-reflect.set">
+ <h1><span class="secnum" id="sec-26.1.13"><a href="#sec-reflect.set" title="link to this section">26.1.13</a></span>
+ Reflect.set ( target, propertyKey, V [ , receiver ] )</h1>
+
+ <p>When the <code>set</code> function is called with arguments <span style="font-family: Times New Roman"><i>target</i>,
+ <i>V</i>, <i>propertyKey</i></span>, and <var>receiver</var> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>obj</i> be <a href="#sec-toobject">ToObject</a>(<i>target</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>obj</i>).</li>
+ <li>Let <i>key</i> be <a href="#sec-topropertykey">ToPropertyKey</a>(<i>propertyKey</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>key</i>).</li>
+ <li>If <i>receiver</i> is not present, then
+ <ol class="block">
+ <li>Let <i>receiver</i> be <i>target</i>.</li>
+ </ol>
+ </li>
+ <li>Return the result of calling the [[Set]] internal method of <i>obj</i> with arguments <i>key</i>, <i>V</i>, and
+ <i>receiver</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-reflect.setprototypeof">
+ <h1><span class="secnum" id="sec-26.1.14"><a href="#sec-reflect.setprototypeof"
+ title="link to this section">26.1.14</a></span> Reflect.setPrototypeOf ( target, proto )</h1>
+
+ <p>When the <code>setPrototypeOf</code> function is called with arguments <span style="font-family: Times New
+ Roman"><i>target</i> and <i>propertyKey</i></span>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>obj</i> be <a href="#sec-toobject">ToObject</a>(<i>target</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>obj</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>proto</i>) is not Object and <i>proto</i> is not
+ <b>null</b>, then throw a <b>TypeError</b> exception</li>
+ <li>Return the result of calling the [[SetPrototypeOf]] internal method of <i>obj</i> with argument <i>proto</i>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-realm-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-26.2"><a href="#sec-realm-objects" title="link to this section">26.2</a></span> Realm
+ Objects</h1>
+ </div>
+
+ <section id="sec-reflect.realm-constructor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-26.2.1"><a href="#sec-reflect.realm-constructor"
+ title="link to this section">26.2.1</a></span> The Reflect.Realm Constructor</h1>
+
+ <p>The initial value of <code>Reflect.<a href="#sec-code-realms">Realm</a></code> is the %Realm% intrinsic object.
+ <code>Reflect.<a href="#sec-code-realms">Realm</a></code> is the constructor for <a href="#sec-code-realms">Realm</a>
+ objects. When <code>Reflect.<a href="#sec-code-realms">Realm</a></code> is called as a function rather than as a
+ constructor, it initializes its <b>this</b> value with the internal state necessary to support the
+ <code>Reflect.Realm.prototype</code> built-in methods.</p>
+
+ <p>The <code>Reflect.<a href="#sec-code-realms">Realm</a></code> constructor is designed to be subclassable. It may be
+ used as the value in an <code>extends</code> clause of a class definition. Subclass constructors that intend to inherit
+ the specified <a href="#sec-code-realms">Realm</a> behaviour must include a <code>super</code> call to <code>Reflect.<a
+ href="#sec-code-realms">Realm</a></code>.</p>
+ </div>
+
+ <section id="sec-reflect.realm">
+ <h1><span class="secnum" id="sec-26.2.1.1"><a href="#sec-reflect.realm" title="link to this section">26.2.1.1</a></span>
+ Reflect.Realm ( [ target , handler ] )</h1>
+
+ <p>When the <code>Reflect.<a href="#sec-code-realms">Realm</a></code> function is called with optional arguments
+ <var>target</var> and <var>handler</var> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>realmObject</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>realmObject</i>) is not Object or <i>realmObject</i>
+ does not have a [[RealmRecord]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, throw a
+ <b>TypeError</b> exception.</li>
+ <li>If the value of <i>realmObject</i>’s [[RealmRecord]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is not <b>undefined</b>, throw a
+ <b>TypeError</b> exception.</li>
+ <li>If any arguments were passed to this function, then
+ <ol class="block">
+ <li>Let <i>newGlobal</i> be <a href="#sec-proxycreate">ProxyCreate</a>(<i>target</i>, <i>handler</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>newGlobal</i>)</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>newGlobal</i> be <b>undefined</b>.</li>
+ </ol>
+ </li>
+ <li>Let <i>realmRec</i> be <a href="#sec-createrealm">CreateRealm</a>().</li>
+ <li>Perform <a href="#sec-setrealmglobalobj">SetRealmGlobalObj</a>(<i>realmRec</i>, <i>newGlobal</i>).</li>
+ <li>Let <i>translate</i> be <a href="#sec-getmethod">GetMethod</a>(<i>realmObject</i>, <code>"directEval"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>translate</i>).</li>
+ <li>Let <i>fallback</i> be <a href="#sec-getmethod">GetMethod</a>(<i>realmObject</i>, <code>"nonEval"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>fallback</i>).</li>
+ <li>Let <i>indirectEval</i> be <a href="#sec-getmethod">GetMethod</a>(<i>realmObject</i>,
+ <code>"indirectEval"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>indirectEval</i>).</li>
+ <li>Set <i>realmRec</i>.[[directEvalTranslate]] to <i>translate</i>.</li>
+ <li>Set <i>realmRec</i>.[[nonEvalFallback]] to <i>fallback</i>.</li>
+ <li>Set <i>realmRec</i>.[[indirectEval]] to <i>indirectEval</i>.</li>
+ <li>NOTE the following step ensures that this function was not reentrantly applied to <var>realmObject</var> during the
+ above steps.</li>
+ <li>If the value of <i>realmObject</i>’s [[RealmRecord]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is not <b>undefined</b>, throw a
+ <b>TypeError</b> exception.</li>
+ <li>Set <i>realmObject</i>’s [[RealmRecord]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> to <i>realmRec</i>.</li>
+ <li>Let <i>initGlobal</i> be <a href="#sec-getmethod">GetMethod</a>(<i>realmObject</i>, <code>"initGlobal"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>initGlobal</i>).</li>
+ <li>If <i>initGlobal</i> is not <b>undefined</b>, then
+ <ol class="block">
+ <li>Let <i>status</i> be the result of calling the [[Call]] internal method of <i>initGlobal</i>, passing
+ <i>realmObject</i> as the <b>this</b> value and no arguments.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>status</i> be <a href="#sec-setdefaultglobalbindings">SetDefaultGlobalBindings</a>(<i>realmRec</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ </ol>
+ </li>
+ <li>Return <i>realmObject</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-new-reflect.realm-argumentslist">
+ <h1><span class="secnum" id="sec-26.2.1.2"><a href="#sec-new-reflect.realm-argumentslist"
+ title="link to this section">26.2.1.2</a></span> new Reflect.Realm ( ...argumentsList )</h1>
+
+ <p>When <code>Reflect.<a href="#sec-code-realms">Realm</a></code> is called as part of a <code>new</code> expression it is
+ a constructor: it initializes a newly created object. It performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be the %Realm% function object on which the <code>new</code> operator was applied.</li>
+ <li>Let <i>argumentsList</i> be the <i>argumentsList</i> argument of the [[Construct]] internal method that was invoked
+ by the <code>new</code> operator.</li>
+ <li>Return the result of <a href="#sec-construct-f-argumentslist">Construct</a>(<i>F</i>, <i>argumentsList</i>).</li>
+ </ol>
+
+ <p>If <code>Reflect.<a href="#sec-code-realms">Realm</a></code> is implemented as an <a
+ href="#sec-ecmascript-function-objects">ECMAScript function object</a>, its [[Construct]] internal method will perform the
+ above steps.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-reflect.realm-constructor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-26.2.2"><a href="#sec-properties-of-the-reflect.realm-constructor"
+ title="link to this section">26.2.2</a></span> Properties of the Reflect.Realm Constructor</h1>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the
+ <code>Reflect.<a href="#sec-code-realms">Realm</a></code> constructor is the Function prototype object (<a
+ href="#sec-properties-of-the-function-prototype-object">19.2.3</a>).</p>
+
+ <p>Besides the <code>length</code> property (whose value is <b>0</b>), the <code>Reflect.<a
+ href="#sec-code-realms">Realm</a></code> constructor has the following properties:</p>
+ </div>
+
+ <section id="sec-reflect.realm.prototype">
+ <h1><span class="secnum" id="sec-26.2.2.1"><a href="#sec-reflect.realm.prototype"
+ title="link to this section">26.2.2.1</a></span> Reflect.Realm.prototype</h1>
+
+ <p>The initial value of <code>Reflect.Realm.prototype</code> is the intrinsic %RealmPrototype% object (<a
+ href="#sec-properties-of-the-reflect.realm-prototype-object">26.2.3</a>).</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-reflect.realm-@@create">
+ <h1><span class="secnum" id="sec-26.2.2.2"><a href="#sec-reflect.realm-@@create"
+ title="link to this section">26.2.2.2</a></span> Reflect.Realm [ @@create ] ( )</h1>
+
+ <p>The @@create method of a <code>Reflect.<a href="#sec-code-realms">Realm</a></code> function object <var>F</var>
+ performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be the <b>this</b> value.</li>
+ <li>Let <i>obj</i> be the result of calling <a
+ href="#sec-ordinarycreatefromconstructor">OrdinaryCreateFromConstructor</a>(<i>F</i>,
+ <code>"%RealmPrototype%"</code>, ( [[RealmRecord]])).</li>
+ <li>Return <i>obj</i>.</li>
+ </ol>
+
+ <p>The value of the <code>name</code> property of this function is <code>"[Symbol.create]"</code>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>true</b> }.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-reflect.realm-prototype-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-26.2.3"><a href="#sec-properties-of-the-reflect.realm-prototype-object"
+ title="link to this section">26.2.3</a></span> Properties of the Reflect.Realm Prototype Object</h1>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the
+ <code>Reflect.<a href="#sec-code-realms">Realm</a></code> prototype object is the standard built-in Object prototype
+ object (<a href="#sec-properties-of-the-object-prototype-object">19.1.3</a>). The <code>Reflect.<a
+ href="#sec-code-realms">Realm</a></code> prototype object is an ordinary object. It does not have a [[RealmRecord]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</p>
+ </div>
+
+ <section id="sec-reflect.realm.prototype.constructor">
+ <h1><span class="secnum" id="sec-26.2.3.1"><a href="#sec-reflect.realm.prototype.constructor"
+ title="link to this section">26.2.3.1</a></span> Reflect.Realm.prototype.constructor</h1>
+
+ <p>The initial value of <code>Reflect.Realm.prototype.constructor</code> is the built-in %Realm% constructor.</p>
+ </section>
+
+ <section id="sec-reflect.realm.prototype.eval">
+ <h1><span class="secnum" id="sec-26.2.3.2"><a href="#sec-reflect.realm.prototype.eval"
+ title="link to this section">26.2.3.2</a></span> Reflect.Realm.prototype.eval ( source )</h1>
+
+ <p>When <code>Reflect.Realm.prototype.eval</code> is called with argument <var>source</var> it performs the following
+ steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>realmObject</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>realmObject</i>) is not Object or <i>realmObject</i>
+ does not have a [[RealmRecord]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, throw a
+ <b>TypeError</b> exception.</li>
+ <li>Let <i>realm</i> be the value of <i>realmObject</i>’s [[RealmRecord]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>realm</i> is <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Return the result of IndirectEval(<i>realm,</i> <i>source</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-get-reflect.realm.prototype.global">
+ <h1><span class="secnum" id="sec-26.2.3.3"><a href="#sec-get-reflect.realm.prototype.global"
+ title="link to this section">26.2.3.3</a></span> get Reflect.Realm.prototype.global</h1>
+
+ <p><code>Reflect.Realm.prototype.global</code> is an accessor property whose set accessor function is <span
+ class="value">undefined</span>. Its get accessor function performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>realmObject</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>realmObject</i>) is not Object or <i>realmObject</i>
+ does not have a [[RealmRecord]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, throw a
+ <b>TypeError</b> exception.</li>
+ <li>Let <i>realm</i> be the value of <i>realmObject</i>’s [[RealmRecord]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>realm</i> is <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Return <i>realm</i>.[[globalThis]].</li>
+ </ol>
+ </section>
+
+ <section id="sec-get-reflect.realm.prototype.intrinsics">
+ <h1><span class="secnum" id="sec-26.2.3.4"><a href="#sec-get-reflect.realm.prototype.intrinsics"
+ title="link to this section">26.2.3.4</a></span> get Reflect.Realm.prototype.intrinsics</h1>
+
+ <p><code>Reflect.Realm.prototype.intrinsics</code> is an accessor property whose set accessor function is <span
+ class="value">undefined</span>. Its get accessor function performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>realmObject</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>realmObject</i>) is not Object or <i>realmObject</i>
+ does not have a [[RealmRecord]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, throw a
+ <b>TypeError</b> exception.</li>
+ <li>Let <i>realm</i> be the value of <i>realmObject</i>’s [[RealmRecord]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>realm</i> is <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>table</i> be <a href="#sec-objectcreate">ObjectCreate</a>(%ObjectPrototype%).</li>
+ <li>Let <i>intrinsics</i> be <i>realm’s</i> [[instrinsics]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>For each <i>name</i> in the “Intrinsic Key” column of <a href="#table-7">Table 7</a>, in row order do
+ <ol class="block">
+ <li>Let <i>object</i> be the value of the field of <i>intrinsics</i> whose name is <i>name</i>.</li>
+ <li>Perform <a href="#sec-createdataproperty">CreateDataProperty</a>(<i>table</i>, <i>key</i>, <i>object</i>).</li>
+ </ol>
+ </li>
+ <li>Return <i>table</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-get-reflect.realm.prototype.stdlib">
+ <h1><span class="secnum" id="sec-26.2.3.5"><a href="#sec-get-reflect.realm.prototype.stdlib"
+ title="link to this section">26.2.3.5</a></span> get Reflect.Realm.prototype.stdlib</h1>
+
+ <p><code>Reflect.Realm.prototype.stdlib</code> is an accessor property whose set accessor function is <span
+ class="value">undefined</span>. Its get accessor function performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>realmObject</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>realmObject</i>) is not Object or <i>realmObject</i>
+ does not have a [[RealmRecord]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, throw a
+ <b>TypeError</b> exception.</li>
+ <li>Let <i>realm</i> be the value of <i>realmObject</i>’s [[RealmRecord]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>realm</i> is <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>props</i> be <a href="#sec-objectcreate">ObjectCreate</a>(%ObjectPrototype%).</li>
+ <li>For each property of the Global Object specified in <a href="#sec-global-object">clause 18</a>, do
+ <ol class="block">
+ <li>Let <i>name</i> be the string value of the property name.</li>
+ <li>Let <i>desc</i> be the fully populated data property descriptor for the property containing the specified
+ attributes for the property. For properties whose values are functions, the value of the [[Value]] attribute is
+ the corresponding intrinsic function object for <i>realm</i>.</li>
+ <li>Let <i>status</i> be <a href="#sec-definepropertyorthrow">DefinePropertyOrThrow</a>(<i>props</i>, <i>name</i>,
+ <i>desc</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ </ol>
+ </li>
+ <li>Return <i>props</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The object returned is suitable for use as the second argument to <a
+ href="#sec-object.defineproperties">Object.defineProperties</a>. A <a href="#sec-code-realms">Realm</a>’s global
+ object can be initialized with its <a href="#sec-global-object">clause 18</a> standard values using an expression such
+ as:</p>
+
+ <pre><a href="#sec-object.defineproperties">Object.defineProperties</a>(newRealm.global, newRealm.stdlib);</pre>
+ </div>
+ </section>
+
+ <section id="sec-reflect.realm.prototype-@@tostringtag">
+ <h1><span class="secnum" id="sec-26.2.3.6"><a href="#sec-reflect.realm.prototype-@@tostringtag"
+ title="link to this section">26.2.3.6</a></span> Reflect.Realm.prototype [ @@toStringTag ]</h1>
+
+ <p>The initial value of the @@toStringTag property is the string value <code>"Reflect.<a
+ href="#sec-code-realms">Realm</a>"</code>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <span class="value">false</span>, [[Enumerable]]: <span
+ class="value">false</span>, [[Configurable]]: <span class="value">true</span> }.</p>
+ </section>
+
+ <section id="sec-realm-subclass-extension-properties">
+ <div class="front">
+ <h1><span class="secnum" id="sec-26.2.3.7"><a href="#sec-realm-subclass-extension-properties"
+ title="link to this section">26.2.3.7</a></span> Realm Subclass Extension Properties</h1>
+
+ <p>The following properties are intended to be over-ridden by subclasses of <code>Reflect.<a
+ href="#sec-code-realms">Realm</a></code>.</p>
+ </div>
+
+ <section id="sec-reflect.realm.prototype.directeval">
+ <h1><span class="secnum" id="sec-26.2.3.7.1"><a href="#sec-reflect.realm.prototype.directeval"
+ title="link to this section">26.2.3.7.1</a></span> Reflect.Realm.prototype.directEval ( source )</h1>
+
+ <p>When <code>Reflect.Realm.prototype.directEval</code> is called with argument <var>source</var> it performs the
+ following steps:</p>
+
+ <ol class="proc">
+ <li>Return <i>source</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> If an apparent direct eval call had multiple arguments, those arguments are all passed
+ to this function.</p>
+ </div>
+ </section>
+
+ <section id="sec-reflect.realm.prototype.indirecteval">
+ <h1><span class="secnum" id="sec-26.2.3.7.2"><a href="#sec-reflect.realm.prototype.indirecteval"
+ title="link to this section">26.2.3.7.2</a></span> Reflect.Realm.prototype.indirectEval ( source )</h1>
+
+ <p>When <code>Reflect.Realm.prototype.indirectEval</code> is called with argument <var>source</var> it performs the
+ following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>realmObject</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>realmObject</i>) is not Object or
+ <i>realmObject</i> does not have a [[RealmRecord]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>realm</i> be the value of <i>realmObject</i>’s [[RealmRecord]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>realm</i> is <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Return IndirectEval(<i>realm,</i> <i>source</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-reflect.realm.prototype.initglobal">
+ <h1><span class="secnum" id="sec-26.2.3.7.3"><a href="#sec-reflect.realm.prototype.initglobal"
+ title="link to this section">26.2.3.7.3</a></span> Reflect.Realm.prototype.initGlobal ( )</h1>
+
+ <p>When <code>Reflect.Realm.prototype.initGlobal</code> is called it performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>realmObject</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>realmObject</i>) is not Object or
+ <i>realmObject</i> does not have a [[RealmRecord]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>realmRec</i> be the value of <i>realmObject</i>’s [[RealmRecord]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>realmRec</i> is <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Return <a href="#sec-setdefaultglobalbindings">SetDefaultGlobalBindings</a>(<i>realmRec</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-reflect.realm.prototype.noneval">
+ <h1><span class="secnum" id="sec-26.2.3.7.4"><a href="#sec-reflect.realm.prototype.noneval"
+ title="link to this section">26.2.3.7.4</a></span> Reflect.Realm.prototype.nonEval (function, thisValue,
+ argumentsList )</h1>
+
+ <p>When <code>Reflect.Realm.prototype.nonEval</code> is called with arguments <var>function</var>, <var>thisValue</var>,
+ and <var>argumentsList</var> it performs the following steps:</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>function</i>) is <b>false</b>, then throw a <b>TypeError</b>
+ exception.</li>
+ <li>Let <i>args</i> be <a href="#sec-createlistfromarraylike">CreateListFromArrayLike</a>(<i>argumentsList</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>args</i>).</li>
+ <li>Perform <a href="#sec-preparefortailcall">PrepareForTailCall</a>( ).</li>
+ <li>Return the result of calling the [[Call]] internal method of <i>function</i>with arguments <i>thisValue</i> and
+ <i>args</i>.</li>
+ </ol>
+ </section>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-reflect.realm-instances">
+ <h1><span class="secnum" id="sec-26.2.4"><a href="#sec-properties-of-reflect.realm-instances"
+ title="link to this section">26.2.4</a></span> Properties of Reflect.Realm Instances</h1>
+
+ <p><code>Reflect.<a href="#sec-code-realms">Realm</a></code> instances are ordinary objects that inherit properties from the
+ <code>Reflect.<a href="#sec-code-realms">Realm</a></code> prototype object. <code>Reflect.<a
+ href="#sec-code-realms">Realm</a></code> instances each have a [[RealmRecord]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</p>
+ </section>
+ </section>
+
+ <section id="sec-loader-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-26.3"><a href="#sec-loader-objects" title="link to this section">26.3</a></span> Loader
+ Objects</h1>
+
+ <p>Loader objects are able to load the source code of an ECMAScript <span class="nt">Module</span> in the context of a
+ specific <a href="#sec-code-realms">Realm</a>.</p>
+ </div>
+
+ <section id="sec-reflect.loader-constructor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-26.3.1"><a href="#sec-reflect.loader-constructor"
+ title="link to this section">26.3.1</a></span> The Reflect.Loader Constructor</h1>
+
+ <p>The initialize value of <code>Reflect.Loader</code> is the %Loader% intrinsic object. <code>Reflect.Loader</code> is
+ the constructor for Loader objects. When <code>Reflect.Loader</code> is called as a function rather than as a constructor,
+ it initializes its <b>this</b> value with the internal state necessary to support the
+ <code>Reflect.Loader.prototype</code> built-in methods.</p>
+
+ <p>The <code>Reflect.Loader</code> constructor is designed to be subclassable. It may be used as the value in an
+ <code>extends</code> clause of a class definition. Subclass constructors that intend to support the specified Loader
+ behaviour must include a <code>super</code> call to <code>Reflect.Loader</code>.</p>
+ </div>
+
+ <section id="sec-reflect.loader">
+ <h1><span class="secnum" id="sec-26.3.1.1"><a href="#sec-reflect.loader" title="link to this section">26.3.1.1</a></span>
+ Reflect.Loader ( [ options ] )</h1>
+
+ <p>When the Reflect.Loader function is called with optional argument <var>options</var> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>loader</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>loader</i>) is not Object, throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>loader</i> does not have a [[LoaderRecord]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a>, throw a <b>TypeError</b> exception.</li>
+ <li>If the value of <i>loader</i>’s [[LoaderRecord]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is not <b>undefined</b>, throw a
+ <b>TypeError</b> exception.</li>
+ <li>Let <i>realmObject</i> be the result of <a href="#sec-getoption">GetOption</a>(<i>options</i>,
+ <code>"realm"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>realmObject</i>).</li>
+ <li>If <i>realmObject</i> is <b>undefined</b>, let <i>realm</i> be the <a href="#sec-code-realms">Realm</a> of <a
+ href="#sec-execution-contexts">the running execution context</a>.</li>
+ <li>Else,
+ <ol class="block">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>realmObject</i>) is not Object or
+ <i>realmObject</i> does not have a [[RealmRecord]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, throw a <b>TypeError</b>
+ exception.</li>
+ <li>Let <i>realm</i> be the value of <i>realmObject</i>’s [[RealmRecord]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>realm</i> is <b>undefined</b>, throw a <b>TypeError</b> exception.</li>
+ </ol>
+ </li>
+ <li>For each <i>name</i> in the <a href="#sec-list-and-record-specification-type">List</a> (<code>"normalize"</code>,
+ <code>"locate"</code>, <code>"fetch"</code>, <code>"translate"</code>, <code>"instantiate"</code>),
+ <ol class="block">
+ <li>Let <i>hook</i> be the result of <a href="#sec-getoption">GetOption</a>(<i>options</i>, <i>name</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>hook</i>).</li>
+ <li>If <i>hook</i> is not <b>undefined</b>,
+ <ol class="block">
+ <li>If <a href="#sec-iscallable">IsCallable</a>(<i>hook</i>) is <b>false,</b> throw a <b>TypeError</b>
+ exception.</li>
+ <li>Let <i>result</i> be <a href="#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a>(<i>loader</i>,
+ <i>name</i>, <i>hook</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>result</i>).</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>NOTE the following step ensures that this function was not reentrantly applied to <span style="font-family: Times
+ New Roman"><i>loader</i></span> during the above steps.</li>
+ <li>If the value of <i>loader</i>’s [[LoaderRecord]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is not <b>undefined</b>, throw a
+ <b>TypeError</b> exception.</li>
+ <li>Let <i>loaderRecord</i> be <a href="#sec-createloaderrecord">CreateLoaderRecord</a>(<i>realm</i>,
+ <i>loader</i>).</li>
+ <li>Set <i>loader</i>’s [[LoaderRecord]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> to <i>loaderRecord</i>.</li>
+ <li>Return <i>loader</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-new-reflect.loader-argumentslist">
+ <h1><span class="secnum" id="sec-26.3.1.2"><a href="#sec-new-reflect.loader-argumentslist"
+ title="link to this section">26.3.1.2</a></span> new Reflect.Loader ( ...argumentsList )</h1>
+
+ <p>When <code>Reflect.Loader</code> is called as part of a <code>new</code> expression it is a constructor: it initializes
+ a newly created object. It performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be the <code>Reflect.Loader</code> function object on which the <code>new</code> operator was
+ applied.</li>
+ <li>Let <i>argumentsList</i> be the <i>argumentsList</i> argument of the [[Construct]] internal method that was invoked
+ by the <code>new</code> operator.</li>
+ <li>Return the result of <a href="#sec-construct-f-argumentslist">Construct</a>(<i>F</i>, <i>argumentsList</i>).</li>
+ </ol>
+
+ <p>If <code>Reflect.Loader</code> is implemented as an <a href="#sec-ecmascript-function-objects">ECMAScript function
+ object</a>, its [[Construct]] internal method will perform the above steps.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-loader-constructor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-26.3.2"><a href="#sec-properties-of-the-loader-constructor"
+ title="link to this section">26.3.2</a></span> Properties of the Loader Constructor</h1>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the
+ <code>Reflect.Loader</code> constructor is the Function prototype object (<a
+ href="#sec-properties-of-the-function-prototype-object">19.2.3</a>).</p>
+
+ <p>Besides the <code>length</code> property (whose value is <b>0</b>), the <code>Reflect.Loader</code> constructor has the
+ following properties:</p>
+ </div>
+
+ <section id="sec-reflect.loader.prototype">
+ <h1><span class="secnum" id="sec-26.3.2.1"><a href="#sec-reflect.loader.prototype"
+ title="link to this section">26.3.2.1</a></span> Reflect.Loader.prototype</h1>
+
+ <p>The initial value of <code>Reflect.Loader.prototype</code> is the intrinsic %LoaderPrototype% object (<a
+ href="#sec-properties-of-the-reflect.loader-prototype-object">26.3.3</a>).</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>false</b> }.</p>
+ </section>
+
+ <section id="sec-reflect.loader-@@create">
+ <h1><span class="secnum" id="sec-26.3.2.2"><a href="#sec-reflect.loader-@@create"
+ title="link to this section">26.3.2.2</a></span> Reflect.Loader [ @@create ] ( )</h1>
+
+ <p>The @@create method of a <code>Reflect.Loader</code> function object <var>F</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be the <b>this</b> value.</li>
+ <li>Let <i>obj</i> be the result of calling <a
+ href="#sec-ordinarycreatefromconstructor">OrdinaryCreateFromConstructor</a>(<i>F</i>,
+ <code>"%LoaderPrototype%"</code>, ([[LoaderRecord]])).</li>
+ <li>Return <i>obj</i>.</li>
+ </ol>
+
+ <p>The value of the <code>name</code> property of this function is <code>"[Symbol.create]"</code>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <b>false</b>, [[Enumerable]]: <b>false</b>, [[Configurable]]:
+ <b>true</b> }.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-reflect.loader-prototype-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-26.3.3"><a href="#sec-properties-of-the-reflect.loader-prototype-object"
+ title="link to this section">26.3.3</a></span> Properties of the Reflect.Loader Prototype Object</h1>
+
+ <p>The value of the [[Prototype]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of the
+ <code>Reflect.Loader</code> prototype object is the standard built-in Object prototype object (<a
+ href="#sec-properties-of-the-object-prototype-object">19.1.3</a>). The <code>Reflect.Loader</code> prototype object is an
+ ordinary object. It does not have a [[LoaderRecord]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a>.</p>
+
+ <p>The phrase "<span style="font-family: Times New Roman">this Loader</span>" within the specification of the following
+ methods refers to the result returned by performing the abstract operation thisLoader with the <b>this</b> value of the
+ current method invocation passed as the argument.</p>
+
+ <p>The abstract operation thisLoader with argument <var>value</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>value</i>) is Object and <i>value</i> has a
+ [[LoaderRecord]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, then
+ <ol class="block">
+ <li>Let <i>r</i> be <i>value</i>’s [[LoaderRecord]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>r</i> is not <b>undefined</b>, then return <i>value</i>.</li>
+ </ol>
+ </li>
+ <li>Throw a <b>TypeError</b> exception.</li>
+ </ol>
+ </div>
+
+ <section id="sec-reflect.loader.prototype.constructor">
+ <h1><span class="secnum" id="sec-26.3.3.1"><a href="#sec-reflect.loader.prototype.constructor"
+ title="link to this section">26.3.3.1</a></span> Reflect.Loader.prototype.constructor</h1>
+
+ <p>The initial value of <code>Reflect.Loader.prototype.constructor</code> is the built-in %Loader% constructor.</p>
+ </section>
+
+ <section id="sec-reflect.loader.prototype.define">
+ <h1><span class="secnum" id="sec-26.3.3.2"><a href="#sec-reflect.loader.prototype.define"
+ title="link to this section">26.3.3.2</a></span> Reflect.Loader.prototype.define ( name, source [ , options ] )</h1>
+
+ <p>The <code>define</code> method installs a module in this <var>loader</var>'s module registry for <var>source</var>
+ using <var>name</var> as the registry key. The module is not immediately available. The <code>translate</code> and
+ <code>instantiate</code> hooks are called asynchronously, and dependencies are loaded asynchronously. <code>define</code>
+ returns a Promise object that resolves to <span class="value">undefined</span> when the new module and its dependencies
+ are installed in the registry.</p>
+
+ <p>When the <code>define</code> method is called with arguments <var>name</var>, <var>source</var>, and optional argument
+ <var>options</var> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>loader</i> be this Loader.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>loader</i>).</li>
+ <li>Let <i>loaderRecord</i> be <i>loader’s</i> [[LoaderRecord]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>name</i> be <a href="#sec-tostring">ToString</a>(<i>name</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>name</i>).</li>
+ <li>Let <i>address</i> be <a href="#sec-getoption">GetOption</a>(<i>options</i>, <code>"address"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>address</i>).</li>
+ <li>Let <i>metadata</i> be <a href="#sec-getoption">GetOption</a>(<i>options</i>, <code>"metadata"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>metadata</i>).</li>
+ <li>If <i>metadata</i> is <b>undefined</b> then let <i>metadata</i> be <a
+ href="#sec-objectcreate">ObjectCreate</a>(%ObjectPrototype%).</li>
+ <li>Let <i>p</i> be <a
+ href="#sec-promiseofstartloadpartwaythrough">PromiseOfStartLoadPartwayThrough</a>(<code>"translate"</code>,
+ <i>loaderRecord</i>, <i>name</i>, <i>metadata</i>, <i>source</i>, <i>address</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>p</i>).</li>
+ <li>Let <i>G</i> be a new function as defined by ReturnUndefined.</li>
+ <li>Let <i>p</i> be the result of calling <a href="#sec-promisethen">PromiseThen</a>(<i>p</i>, <i>G</i>).</li>
+ <li>Return <i>p</i>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>define</code> method is <b>2</b>.</p>
+ </section>
+
+ <section id="sec-reflect.loader.prototype.delete">
+ <h1><span class="secnum" id="sec-26.3.3.3"><a href="#sec-reflect.loader.prototype.delete"
+ title="link to this section">26.3.3.3</a></span> Reflect.Loader.prototype.delete ( name )</h1>
+
+ <p>The <code>delete</code> method removes an entry whose key is <var>name</var> from this <var>loader</var>'s module
+ registry. It performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>loader</i> be this Loader.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>loader</i>).</li>
+ <li>Let <i>loaderRecord</i> be <i>loader’s</i> [[LoaderRecord]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>name</i> be <a href="#sec-tostring">ToString</a>(<i>name</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>name</i>).</li>
+ <li>Let <i>modules</i> be the value of <i>loaderRecord</i>.[[Modules]],</li>
+ <li>Repeat for each Record {[[<i>name</i>]], [[value]]} <i>p</i> that is an element of <i>modules</i>,
+ <ol class="block">
+ <li>If <a href="#sec-samevalue">SameValue</a>(<i>p</i>.[[key]], <i>name</i>), then
+ <ol class="block">
+ <li>Set <i>p</i>.[[key]] to <span style="font-family: sans-serif">empty</span>.</li>
+ <li>Set <i>p</i>.[[value]] to <span style="font-family: sans-serif">empty</span>.</li>
+ <li>Return <b>true</b>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-reflect.loader.prototype.entries">
+ <h1><span class="secnum" id="sec-26.3.3.4"><a href="#sec-reflect.loader.prototype.entries"
+ title="link to this section">26.3.3.4</a></span> Reflect.Loader.prototype.entries ( )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>loader</i> be this Loader.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>loader</i>).</li>
+ <li>Return the result of <a href="#sec-createloaderiterator">CreateLoaderIterator</a>(<i>loader</i>,
+ <code>"key+value"</code>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-reflect.loader.prototype.get">
+ <h1><span class="secnum" id="sec-26.3.3.5"><a href="#sec-reflect.loader.prototype.get"
+ title="link to this section">26.3.3.5</a></span> Reflect.Loader.prototype.get ( name )</h1>
+
+ <p>If this Loader's module registry contains a Module with the given normalized <var>name</var>, return it. Otherwise,
+ return <span class="value">undefined</span>. If the module is in the registry but has never been evaluated, first
+ synchronously evaluate the bodies of the module and any dependencies that have not evaluated yet.</p>
+
+ <p>When the <code>get</code> method is called with the argument <var>name</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>loader</i> be this Loader.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>loader</i>).</li>
+ <li>Let <i>loaderRecord</i> be <i>loader’s</i> [[LoaderRecord]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>name</i> be <a href="#sec-tostring">ToString</a>(<i>name</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>name</i>).</li>
+ <li>Let <i>modules</i> be the value of <i>loaderRecord.</i>[[Modules]],</li>
+ <li>Repeat for each Record {[[key]], [[value]]} <i>p</i> that is an element of <i>modules</i>,
+ <ol class="block">
+ <li>If <a href="#sec-samevalue">SameValue</a>(<i>p</i>.[[key]], <i>name</i>) is <b>true</b>, then
+ <ol class="block">
+ <li>Let <i>module</i> be <i>p</i>.[[value]].</li>
+ <li>Let <i>result</i> be <a href="#sec-ensureevaluated">EnsureEvaluated</a>(<i>module</i>,
+ (),<i>loaderRecord</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>result</i>).</li>
+ <li>Return <i>p</i>.[[value]].</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Return <b>undefined</b>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-get-reflect.loader.prototype.global">
+ <h1><span class="secnum" id="sec-26.3.3.6"><a href="#sec-get-reflect.loader.prototype.global"
+ title="link to this section">26.3.3.6</a></span> get Reflect.Loader.prototype.global</h1>
+
+ <p><code>Reflect.Loader.prototype.global</code> is an accessor property whose set accessor function is <span
+ class="value">undefined</span>. Its get accessor function performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>loader</i> be this Loader.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>loader</i>).</li>
+ <li>Let <i>loaderRecord</i> be <i>loader’s</i> [[LoaderRecord]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>realm</i> be the value of <i>loaderRecord</i>.[[Realm]].</li>
+ <li>Return <i>realm</i>.[[globalThis]].</li>
+ </ol>
+ </section>
+
+ <section id="sec-reflect.loader.prototype.has">
+ <h1><span class="secnum" id="sec-26.3.3.7"><a href="#sec-reflect.loader.prototype.has"
+ title="link to this section">26.3.3.7</a></span> Reflect.Loader.prototype.has ( name )</h1>
+
+ <p>When the <code>Reflect.Loader.prototype.<b>has</b></code> method is called with argument <var>name</var> the following
+ steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>loader</i> be this Loader.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>loader</i>).</li>
+ <li>Let <i>loaderRecord</i> be <i>loader’s</i> [[LoaderRecord]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>name</i> be <a href="#sec-tostring">ToString</a>(<i>name</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>name</i>).</li>
+ <li>Let <i>modules</i> be the value of <i>loaderRecord.</i>[[Modules]],</li>
+ <li>Repeat for each Record {[[key]], [[value]]} <i>p</i> that is an element of <i>modules</i>,
+ <ol class="block">
+ <li>If <a href="#sec-samevalue">SameValue</a>(<i>p</i>.[[key]], <i>name</i>) is <b>true</b>, then return
+ <b>true</b>.</li>
+ </ol>
+ </li>
+ <li>Return <b>false</b>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> This method does not call any hooks or run any module code.</p>
+ </div>
+ </section>
+
+ <section id="sec-reflect.loader.prototype.import">
+ <h1><span class="secnum" id="sec-26.3.3.8"><a href="#sec-reflect.loader.prototype.import"
+ title="link to this section">26.3.3.8</a></span> Reflect.Loader.prototype.import ( name [ , options ] )</h1>
+
+ <p>The <code>import</code> method asynchronously loads, links, and evaluates a module and all its dependencies if these
+ actions have not already been performed. The argument <var>name</var> is the registry key for the module.
+ <code>import</code> returns a Promise that resolves to the <code>Module</code> object once it has been committed to the
+ registry and evaluated.</p>
+
+ <p>When the <code>import</code> method is called with argument <var>name</var> and optional arguments <var>options</var>
+ the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>loader</i> be this Loader.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>loader</i>).</li>
+ <li>Let <i>loaderRecord</i> be <i>loader’s</i> [[LoaderRecord]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>p</i> be the result of calling <a href="#sec-loadmodule">LoadModule</a>(<i>loaderRecord</i>, <i>name</i>,
+ <i>options</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>p</i>).</li>
+ <li>Let <i>F</i> be a new function object as defined by EvaluateLoadedModule.</li>
+ <li>Set <i>F</i>’s [[Loader]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to
+ <i>loaderRecord</i>.</li>
+ <li>Let <i>p</i> be <a href="#sec-promisethen">PromiseThen</a>(<i>p</i>, <i>F</i>).</li>
+ <li>Return <i>p</i>.</li>
+ </ol>
+
+ <p>If the optional argument <var>options</var> is an object with an <code>address</code> property the string value of that
+ property is used as the module location and module loading starts with the fetch step. If an <code>address</code> property
+ is not present, module loading starts with the locate step.</p>
+
+ <p>The <code>length</code> property of the <code>import</code> method is <b>1</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Invoking the <code>import</code> method is the dynamic equivalent (when combined with
+ normalization) of:<br> <span class="prod"><span class="nt">ImportDeclaration</span> <span
+ class="geq">::</span> <code class="t">import</code> <span class="nt">ModuleSpecifier</span> <code
+ class="t">;</code></span></p>
+ </div>
+ </section>
+
+ <section id="sec-reflect.loader.prototype.keys">
+ <h1><span class="secnum" id="sec-26.3.3.9"><a href="#sec-reflect.loader.prototype.keys"
+ title="link to this section">26.3.3.9</a></span> Reflect.Loader.prototype.keys ( )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>loader</i> be this Loader.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>loader</i>).</li>
+ <li>Return the result of <a href="#sec-createloaderiterator">CreateLoaderIterator</a>(<i>loader</i>,
+ <code>"key"</code>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-reflect.loader.prototype.load">
+ <h1><span class="secnum" id="sec-26.3.3.10"><a href="#sec-reflect.loader.prototype.load"
+ title="link to this section">26.3.3.10</a></span> Reflect.Loader.prototype.load ( name [ , options ] )</h1>
+
+ <p>The <code>load</code> method asynchronously loads and links and all its dependencies if these actions have not already
+ been performed. The argument <var>name</var> is the registry key for the module. <code>load</code> returns a Promise that
+ resolves to the <code>Module</code> object once it has been committed to the registry.</p>
+
+ <p>When the <code>load</code> method is called with argument <var>name</var> and optional arguments <var>options</var> the
+ following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>loader</i> be this Loader.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>loader</i>).</li>
+ <li>Let <i>loaderRecord</i> be <i>loader’s</i> [[LoaderRecord]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>p</i> be the result of calling <a href="#sec-loadmodule">LoadModule</a>(<i>loaderRecord</i>, <i>name</i>,
+ <i>options</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>p</i>).</li>
+ <li>Let <i>p</i> be <a href="#sec-promisethen">PromiseThen</a>(<i>p</i>, %ReturnUndefined%).</li>
+ <li>Return <i>p</i>.</li>
+ </ol>
+
+ <p>If the optional argument <var>options</var> is an object with an <code>address</code> property. The string value of
+ that property is used as the module location and module loading starts with the fetch step. If an <code>address</code>
+ property is not present, module loading starts with the locate step.</p>
+
+ <p>The <code>length</code> property of the <code>load</code> method is <b>1</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>load</code> method differs from the <code>import</code> method in that it does
+ not force evaluation of the loaded module.</p>
+ </div>
+ </section>
+
+ <section id="sec-reflect.loader.prototype.module">
+ <h1><span class="secnum" id="sec-26.3.3.11"><a href="#sec-reflect.loader.prototype.module"
+ title="link to this section">26.3.3.11</a></span> Reflect.Loader.prototype.module ( source [, options ] )</h1>
+
+ <p>The <code>module</code> method asynchronously loads, links, and evaluates an anonymous module from <var>source</var>.
+ The module's dependencies, if any, are loaded and committed to the registry. The anonymous module itself is not added to
+ the registry. <code>module</code> returns a Promise object that resolves to a new Module instance object once the given
+ module body has been evaluated.</p>
+
+ <p>When the <code>module</code> method is called with argument <var>source</var> and optional arguments <var>options</var>
+ the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>loader</i> be this Loader.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>loader</i>).</li>
+ <li>Let <i>loaderRecord</i> be <i>loader’s</i> [[LoaderRecord]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>options</i> was not passed, then let <i>options</i> be <b>undefined</b>.</li>
+ <li>Let <i>address</i> be <a href="#sec-getoption">GetOption</a>(<i>options</i>, <code>"address"</code>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>address</i>).</li>
+ <li>Let <i>load</i> be <a href="#sec-createload">CreateLoad</a>(<b>undefined</b>).</li>
+ <li>Set <i>load</i>.[[Address]] to <i>address</i>.</li>
+ <li>Let <i>linkSet</i> be <a href="#sec-createlinkset">CreateLinkSet</a>(<i>loaderRecord</i>, <i>load</i>).</li>
+ <li>Let <i>successCallback</i> be a new function object as defined by EvaluateLoadedModule.</li>
+ <li>Set <i>successCallback</i>’s [[Loader]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> to <i>loaderRecord</i>.</li>
+ <li>Set <i>successCallback</i>’s [[Load]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> to <i>load</i>.</li>
+ <li>Let <i>p</i> be the result of calling <a href="#sec-promisethen">PromiseThen</a>(<i>linkSet</i>.[[Done]],
+ <i>successCallback</i>).</li>
+ <li>Let <i>sourcePromise</i> be <a href="#sec-promiseof">PromiseOf</a>(<i>source</i>).</li>
+ <li>Perform <a href="#sec-proceedtotranslate">ProceedToTranslate</a>(<i>loaderRecord</i>, <i>load</i>,
+ <i>sourcePromise</i>).</li>
+ <li>Return <i>p</i>.</li>
+ </ol>
+
+ <p>The optional argument <var>options</var> is an object with an <code>address</code> property.</p>
+
+ <p>The <code>length</code> property of the <code>module</code> method is <b>1</b>.</p>
+ </section>
+
+ <section id="sec-reflect.loader.prototype.newmodule">
+ <h1><span class="secnum" id="sec-26.3.3.12"><a href="#sec-reflect.loader.prototype.newmodule"
+ title="link to this section">26.3.3.12</a></span> Reflect.Loader.prototype.newModule ( obj )</h1>
+
+ <p style="background-color: #FFC000">TO DO</p>
+
+ <p style="background-color: #FFC000">In the prototype this is the Module Factory Function. However, this factory seems to
+ have only specialized utility and it seems to unnecessarily clutter the “global” namespace of Module
+ abstractions. Making it a method of module loaders seems like a more sanity thing to do, but we can break it out if
+ that;s what people really want.</p>
+
+ <p style="background-color: #FFC000">Also need to reconcile with are execute factory returns by the instantiate hook. Is
+ this method intended to be able as an execute factory. If sho it probably needs to accept multiple arguments.</p>
+
+ <p>When the <code>newModule</code> method is called with argument <var>obj</var> it creates a new Module objects whose
+ export properties are derived form the properties of <var>obj</var>. The following steps are performed:</p>
+
+ <ol class="proc">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>obj</i>) is not Object, throw a <b>TypeError</b>
+ exception.</li>
+ <li>Let <i>mod</i> be CreateLinkedModuleInstance( )</li>
+ <li>Let <i>keys</i> be the result of calling the ObjectKeys abstract operation passing <i>obj</i> as the argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>keys</i>).</li>
+ <li>For each <i>key</i> in <i>keys</i>, do
+ <ol class="block">
+ <li>Let <i>value</i> be the result of <a href="#sec-get-o-p">Get</a>(<i>obj</i>, <i>key</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>value</i>).</li>
+ <li>Let <i>F</i> be the result of calling CreateConstantGetter(<i>key</i>, <i>value</i>).</li>
+ <li>Let <i>desc</i> be the PropertyDescriptor {[[Configurable]]: <b>false</b>, [[Enumerable]]: <b>true</b>, [[Get]]:
+ <i>F</i>, [[Set]]: <b>undefined</b>}.</li>
+ <li>Let <i>status</i> be the result of calling the <a href="#sec-definepropertyorthrow">DefinePropertyOrThrow</a>
+ abstract operation passing <i>mod</i>, <i>key</i>, and <i>desc</i> as arguments.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ </ol>
+ </li>
+ <li>Call the [[PreventExtensions]] internal method of <i>mod</i>.</li>
+ <li>Return <i>mod</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-get-reflect.loader.prototype.realm">
+ <h1><span class="secnum" id="sec-26.3.3.13"><a href="#sec-get-reflect.loader.prototype.realm"
+ title="link to this section">26.3.3.13</a></span> get Reflect.Loader.prototype.realm</h1>
+
+ <p><code>Reflect.Loader.prototype.realm</code> is an accessor property whose set accessor function is <span
+ class="value">undefined</span>. Its get accessor function performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>loader</i> be this Loader.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>loader</i>).</li>
+ <li>Let <i>loaderRecord</i> be <i>loader’s</i> [[LoaderRecord]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Return RealmObjectFor(<i>loaderRecord</i>.[[Realm]]).</li>
+ </ol>
+ </section>
+
+ <section id="sec-reflect.loader.prototype.set">
+ <h1><span class="secnum" id="sec-26.3.3.14"><a href="#sec-reflect.loader.prototype.set"
+ title="link to this section">26.3.3.14</a></span> Reflect.Loader.prototype.set ( name, module )</h1>
+
+ <p>Store a <span style="font-family: Times New Roman">Module obj</span> in this Loader's <var>module</var> registry,
+ overwriting any existing entry with the same <var>name</var>.</p>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>loader</i> be this Loader.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>loader</i>).</li>
+ <li>Let <i>loaderRecord</i> be <i>loader’s</i> [[LoaderRecord]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>name</i> be <a href="#sec-tostring">ToString</a>(<i>name</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>name</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>module</i>) is not Object, throw a <b>TypeError</b>
+ exception.</li>
+ <li>Let <i>modules</i> be the value of <i>loaderRecord.</i>[[Modules]],</li>
+ <li>Repeat for each Record {[[key]], [[value]]} <i>p</i> that is an element of <i>modules</i>,
+ <ol class="block">
+ <li>If <a href="#sec-samevalue">SameValue</a>(<i>p</i>.[[key]], <i>name</i>) is <b>true</b>, then
+ <ol class="nested proc">
+ <li>Set <i>p</i>.[[value]] to <i>module</i>.</li>
+ <li>Return <i>loader</i>.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Let <i>p</i> be the Record {[[key]]: <i>name</i>, [[value]]: <i>module</i>}.</li>
+ <li>Append <i>p</i> as the last record of <i>loaderRecord</i>.[[Modules]].</li>
+ <li>Return <i>loader</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-reflect.loader.prototype.values">
+ <h1><span class="secnum" id="sec-26.3.3.15"><a href="#sec-reflect.loader.prototype.values"
+ title="link to this section">26.3.3.15</a></span> Reflect.Loader.prototype.values ( )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>loader</i> be this Loader.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>loader</i>).</li>
+ <li>Return the result of <a href="#sec-createloaderiterator">CreateLoaderIterator</a>(<i>loader</i>,
+ <code>"value"</code>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-reflect.loader.prototype-@@iterator">
+ <h1><span class="secnum" id="sec-26.3.3.16"><a href="#sec-reflect.loader.prototype-@@iterator"
+ title="link to this section">26.3.3.16</a></span> Reflect.Loader.prototype[@@iterator] ( )</h1>
+
+ <p>The initial value of the @@iterator property is the same function object as the initial value of the
+ <code>entries</code> property.</p>
+ </section>
+
+ <section id="sec-reflect.loader.prototype-@@tostringtag">
+ <h1><span class="secnum" id="sec-26.3.3.17"><a href="#sec-reflect.loader.prototype-@@tostringtag"
+ title="link to this section">26.3.3.17</a></span> Reflect.Loader.prototype [ @@toStringTag ]</h1>
+
+ <p>The initial value of the @@toStringTag property is the string value <code>"Reflect.Loader"</code>.</p>
+
+ <p>This property has the attributes { [[Writable]]: <span class="value">false</span>, [[Enumerable]]: <span
+ class="value">false</span>, [[Configurable]]: <span class="value">true</span> }.</p>
+ </section>
+
+ <section id="sec-reflect.loader-pipeline-hook-properties">
+ <div class="front">
+ <h1><span class="secnum" id="sec-26.3.3.18"><a href="#sec-reflect.loader-pipeline-hook-properties"
+ title="link to this section">26.3.3.18</a></span> Reflect.Loader Pipeline Hook Properties</h1>
+
+ <p>Loader hooks are methods that are called at various points in the process of loading a module.
+ <code>Loader.prototype</code> provides default implementations for the hook methods. However, individual Loader object
+ may over-ride these defaults using own properties.</p>
+ </div>
+
+ <section id="sec-reflect.loader.prototype.normalize">
+ <h1><span class="secnum" id="sec-26.3.3.18.1"><a href="#sec-reflect.loader.prototype.normalize"
+ title="link to this section">26.3.3.18.1</a></span> Reflect.Loader.prototype.normalize ( name, refererName,
+ refererAddress )</h1>
+
+ <p>When the <code>normalize</code> loader hook is called with arguments <var>name</var>, <var>refererName</var>, and
+ <var>refererAddress</var> <var>loadRequest</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>name</i>) is String.</li>
+ <li>Return <i>name</i>.</li>
+ </ol>
+
+ <p>This is a Loader hook that may be over-ridden by an own property of Loader instances. The <code>normalize</code> hook
+ is called once per distinct <span class="nt">ModuleSpecifier</span> String value in a <span
+ class="nt">ModuleBody</span>, while the module <span class="nt">ModuleBody</span> with that is being loaded. The
+ <var>name</var> argument is the StringValue of a <span class="nt">ModuleSpecifier</span>.</p>
+
+ <p>The <code>normalize</code> hook returns an eventual String, the normalized module name, which is used for the rest of
+ the import process. In particular, the [[Loads]] and [[Modules]] Lists of a ModuleLinkage record are both keyed by
+ normalized module names. The module registry contains at most one module for a given normalized module name.</p>
+
+ <p>After calling this hook, if the normalized module <var>name</var> is in the registry or the load table, no new Load
+ Record is created. Otherwise the loader initiates a load for that module that starts by calling the <code>locate</code>
+ hook.</p>
+ </section>
+
+ <section id="sec-reflect.loader.prototype.locate">
+ <h1><span class="secnum" id="sec-26.3.3.18.2"><a href="#sec-reflect.loader.prototype.locate"
+ title="link to this section">26.3.3.18.2</a></span> Reflect.Loader.prototype.locate ( loadRequest )</h1>
+
+ <p>When the locate method is called with argument <var>loadRequest</var> the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Return the result of <a href="#sec-get-o-p">Get</a>(<i>loadRequest</i>, <code>"name"</code>).</li>
+ </ol>
+
+ <p>This is a Loader hook that may be over-ridden by an own property of Loader instances. The <code>locate</code> hook is
+ called for each distinct normalized import <span class="nt">ModuleSpecifier</span> immediately after the
+ <code>normalize</code> hook returns successfully, unless the module is already loaded or loading.</p>
+
+ <p>The <code>locate</code> hook is called to obtain to determine the Loader-dependent resource address (URL, path, etc.)
+ corresponding to normalized module name. The resource address is used later in the Loader pipeline to retrieve the
+ source code of the requested module.</p>
+
+ <p>When a <code>locate</code> hook is called by an Loader object the argument <var>loadRequest</var> is a LoadRequest
+ object (<a href="#sec-load-records-and-loadrequest-objects">15.2.3.2</a>). The value of the <code>name</code> property
+ is the normalized module name. The <code>locate</code> hook returns an eventual value that is used as the resource
+ address. When the returned value is resolved, loading will continue with the <code>fetch</code> hook.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>System.locate</code> hook typically is significantly more complicated than
+ the default <code>locate</code> hook.</p>
+ </div>
+ </section>
+
+ <section id="sec-reflect.loader.prototype.fetch">
+ <h1><span class="secnum" id="sec-26.3.3.18.3"><a href="#sec-reflect.loader.prototype.fetch"
+ title="link to this section">26.3.3.18.3</a></span> Reflect.Loader.prototype.fetch ( loadRequest )</h1>
+
+ <p>When the <code>fetch</code> loader hook is called with argument <var>loadRequest</var>, the following steps are
+ taken:</p>
+
+ <ol class="proc">
+ <li>Throw a <b>TypeError</b> exception.</li>
+ </ol>
+
+ <p>This is a Loader hook that will normally be over-ridden by an own property of Loader instances. The
+ <code>fetch</code> hook is called by a Loader for all modules whose source code was not directly provided to the Loader.
+ It is also used to process the <code>import</code> keyword. The <code>fetch</code> hook is not called for module bodies
+ directly provided as arguments to <code>loader.module()</code> or <code>loader.define()</code>. However, the
+ <code>fetch</code> hook may be called when loading other modules imported by such modules.</p>
+
+ <p>When a <code>fetch</code> hook is called by an Loader object the argument <var>loadRequest</var> is a LoadRequest
+ object (<a href="#sec-load-records-and-loadrequest-objects">15.2.3.2</a>) with an <code>address</code> property. The
+ value of the <code>address</code> property identifies the module source code to fetch. The fetch hook returns an
+ eventual String containing the source code of the module.</p>
+ </section>
+
+ <section id="sec-reflect.loader.prototype.translate">
+ <h1><span class="secnum" id="sec-26.3.3.18.4"><a href="#sec-reflect.loader.prototype.translate"
+ title="link to this section">26.3.3.18.4</a></span> Reflect.Loader.prototype.translate ( loadRequest )</h1>
+
+ <p>When the translate method is called, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Return the result of <a href="#sec-get-o-p">Get</a>(<i>loadRequest</i>, <code>"source"</code>).</li>
+ </ol>
+
+ <p>This is a <code>Loader</code> hook that may be over-ridden by an own property of Loader instances. The
+ <code>translate</code> hook is called for each <span class="nt">ModuleBody</span> including those passed to
+ <code>loader.module()</code> or <code>loader.define()</code>.The <code>translate</code> hook is called prior to parsing
+ the <span class="nt">ModuleBody</span> and provides a Loader the opportunity to modify or replace the source code that
+ will be parsed.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> An example of the use of the <code>translate</code> hook would be to translate source
+ code for a another programing language into an ECMAScript <i>ModuleBody</i>.</p>
+ </div>
+
+ <p>When a <code>translate</code> hook is called by an Loader object the argument <var>loadRequest</var> is a LoadRequest
+ object (<a href="#sec-load-records-and-loadrequest-objects">15.2.3.2</a>) with <code>address</code> and
+ <code>source</code> properties. The value of the <code>address</code> property identifies the module source code to
+ fetch. The value of the <code>source</code> property is the resolved value returned from the <code>fetch</code> hook.
+ The <code>translate</code> hook returns either an eventual String value ECMAScript that will be parsed as a <span
+ class="nt">ModuleBody</span>.</p>
+ </section>
+
+ <section id="sec-reflect.loader.prototype.instantiate">
+ <h1><span class="secnum" id="sec-26.3.3.18.5"><a href="#sec-reflect.loader.prototype.instantiate"
+ title="link to this section">26.3.3.18.5</a></span> Reflect.Loader.prototype.instantiate ( loadRequest )</h1>
+
+ <p>When the instantiate loader hook is called with argument <var>loadRequest</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Return <b>undefined</b>.</li>
+ </ol>
+
+ <p>This hook allows a Loader to provide interoperability with other module systems.</p>
+
+ <p>When a <code>instantiate</code> hook is called by an Loader object the argument, <var>loadRequest</var>, is a
+ LoadRequest object (<a href="#sec-load-records-and-loadrequest-objects">15.2.3.2</a>) with <code>address</code> and
+ <code>source</code> properties. <var>loadRequest</var><code>.name</code>, <var>loadRequest</var><code>.metadata</code>,
+ and <var>loadRequest</var><code>.address</code> are the same values passed to the <code>fetch</code> and
+ <code>translate</code> hooks. <var>loadRequest</var><code>.source</code> is the value produced by the
+ <code>translate</code> hook.</p>
+
+ <p>If the <code>instantiate</code> hook returns an eventual <b>undefined</b>, then the loader uses the default linking
+ behaviour. It parses <var>loadRequest</var><code>.source</code> as a Module, looks at its imports, loads its
+ dependencies asynchronously, and finally links them together and adds them to the registry.</p>
+
+ <p>Otherwise, the <code>instantiate</code> hook must return an eventual <var>instantiationRequest</var> object. An
+ <var>instantiateRequest</var> object has two required properties. The value of the <code>deps</code> property is an
+ array of strings. Each string is the name of a module upon which the module identified by <var>loadRequest</var> has
+ dependencies. The value of the <code>execute</code> property is a function which the loader will use to create the
+ module and link it with its clients and dependencies. The function should expect to receive the same number of arguments
+ as the size of the <code>deps</code> array and must return an eventual Module object. The arguments are Module objects
+ and have a one-to-one correspondence with elements of the <code>deps</code> array.</p>
+
+ <p>The module is evaluated during the linking process. First all of the modules it depends upon are linked and evaluated
+ , and then passed to the <code>execute</code> function. Then the resulting module is linked with the downstream
+ dependencies.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> This feature is provided in order to permit custom loaders to support using
+ <code>import</code> to import pre-ES6 modules such as AMD modules. The design requires incremental linking when such
+ modules are present, but it ensures that modules implemented with standard source-level module declarations can still
+ be statically validated.</p>
+ </div>
+ </section>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-reflect.loader-instances">
+ <h1><span class="secnum" id="sec-26.3.4"><a href="#sec-properties-of-reflect.loader-instances"
+ title="link to this section">26.3.4</a></span> Properties of Reflect.Loader Instances</h1>
+
+ <p>Loader instances are ordinary objects that inherit properties from the %LoaderPrototype% intrinsic object. Loader
+ instances each have a [[Loader]] interal slot whose value after initialization is the Loader Record that the Load instance
+ reflects.</p>
+ </section>
+
+ <section id="sec-loader-iterator-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-26.3.5"><a href="#sec-loader-iterator-objects"
+ title="link to this section">26.3.5</a></span> Loader Iterator Objects</h1>
+
+ <p>A Loader Iterator object represents a specific iteration over the module registry of some specific Loader instance
+ object. There is not a named constructor for Loader Iterator objects. Instead, Loader iterator objects are created by
+ calling certain methods of Loader instance objects.</p>
+ </div>
+
+ <section id="sec-createloaderiterator">
+ <h1><span class="secnum" id="sec-26.3.5.1"><a href="#sec-createloaderiterator"
+ title="link to this section">26.3.5.1</a></span> CreateLoaderIterator Abstract Operation</h1>
+
+ <p>Several methods of Loader objects return Iterator objects. The abstract operation CreateLoaderIterator with arguments
+ <var>loader</var> and <var>kind</var> is used to create such iterator objects. It performs the following steps:</p>
+
+ <ol class="proc">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>loader</i> is an initialized Loader instance object.</li>
+ <li>Let <i>iterator</i> be <a href="#sec-objectcreate">ObjectCreate</a>(<span style="font-family:
+ sans-serif">%LoaderIteratorPrototype%</span>, ([[Loader]], [[LoaderNextIndex]], [[LoaderIterationKind]])).</li>
+ <li>Set <i>iterator’s</i> [[Loader]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>
+ to <i>loader</i>.</li>
+ <li>Set <i>iterator’s</i> [[LoaderNextIndex]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> to 0.</li>
+ <li>Set <i>iterator’s</i> [[LoaderIterationKind]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to <i>kind</i>.</li>
+ <li>Return <i>iterator</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-%loaderiteratorprototype%-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-26.3.5.2"><a href="#sec-%loaderiteratorprototype%-object"
+ title="link to this section">26.3.5.2</a></span> The %LoaderIteratorPrototype% Object</h1>
+
+ <p>All Loader Iterator Objects inherit properties from the %LoaderIteratorPrototype% intrinsic object. The
+ %LoaderIteratorPrototype% intrinsic object is an ordinary object and its [[Prototype]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is the %ObjectPrototype% intrinsic object. In
+ addition, %LoaderIteratorPrototype% has the following properties:</p>
+ </div>
+
+ <section id="sec-%loaderiteratorprototype%.next">
+ <h1><span class="secnum" id="sec-26.3.5.2.1"><a href="#sec-%loaderiteratorprototype%.next"
+ title="link to this section">26.3.5.2.1</a></span> %LoaderIteratorPrototype%.next ( )</h1>
+ <ol class="proc">
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object, throw a <b>TypeError</b>
+ exception.</li>
+ <li>If <i>O</i> does not have all of the internal slots of a Loader Iterator Instance (<a
+ href="#sec-properties-of-loader-iterator-instances">26.3.5.3</a>), throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>m</i> be the value of the [[Loader]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> of <i>O</i>.</li>
+ <li>Let <i>loaderRecord</i> be <i>m’s</i> [[LoaderRecord]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>index</i> be the value of the [[LoaderNextIndex]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>Let <i>itemKind</i> be the value of the [[LoaderIterationKind]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i>.</li>
+ <li>If <i>m</i> is <b>undefined</b>, then return <a
+ href="#sec-createiterresultobject">CreateIterResultObject</a>(<b>undefined</b>, <b>true</b>).</li>
+ <li>Let <i>entries</i> be the <a href="#sec-list-and-record-specification-type">List</a> that is the value of the
+ <i>loaderRecord</i>.[[Modules]].</li>
+ <li>Repeat while <i>index</i> is less than the total number of elements of <i>entries</i>. The number of elements must
+ be redetermined each time this method is evaluated.
+ <ol class="block">
+ <li>Let <i>e</i> be the Record {[[key]], [[value]]} that is the value of <i>entries</i>[<i>index</i>].</li>
+ <li>Set <i>index</i> to <i>index</i>+1;</li>
+ <li>Set the [[LoaderNextIndex]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of
+ <i>O</i> to <i>index</i>.</li>
+ <li>If <i>e</i>.[[key]] is not <span style="font-family: sans-serif">empty</span>, then
+ <ol class="block">
+ <li>If <i>itemKind</i> is <b>"<code>key</code>"</b> then, let <i>result</i> be <i>e</i>.[[key]].</li>
+ <li>Else if <i>itemKind</i> is <b>"<code>value</code>"</b> then, let <i>result</i> be <i>e</i>.[[value]].</li>
+ <li>Else,
+ <ol class="block">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>itemKind</i> is <code>"key+value"</code>.</li>
+ <li>Let <i>result</i> be the result of performing <a href="#sec-arraycreate">ArrayCreate</a>(2).</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>result</i> is a new, well-formed Array object so
+ the following operations will never fail.</li>
+ <li>Call <a href="#sec-createdataproperty">CreateDataProperty</a>(<i>result</i>, <b>"<code>0</code>"</b>,
+ <i>e</i>.[[key]]) .</li>
+ <li>Call <a href="#sec-createdataproperty">CreateDataProperty</a>(<i>result</i>, <b>"<code>1</code>"</b>,
+ <i>e</i>.[[value]]).</li>
+ </ol>
+ </li>
+ <li>Return <a href="#sec-createiterresultobject">CreateIterResultObject</a>(<i>result</i>, <b>false</b>).</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Set the [[Loader]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>O</i> to
+ <b>undefined</b>.</li>
+ <li>Return <a href="#sec-createiterresultobject">CreateIterResultObject</a>(<b>undefined</b>, <b>true</b>).</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> Setting the [[Loader]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to undefined when the iterator is exhausted
+ ensures that the same iterator cannot be restarted if new entries are subsequently added. This condition is tested in
+ step 8.</p>
+ </div>
+ </section>
+
+ <section id="sec-%loaderiteratorprototype%-@@iterator">
+ <h1><span class="secnum" id="sec-26.3.5.2.2"><a href="#sec-%loaderiteratorprototype%-@@iterator"
+ title="link to this section">26.3.5.2.2</a></span> %LoaderIteratorPrototype% [ @@iterator ] ( )</h1>
+
+ <p>The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Return the <b>this</b> value.</li>
+ </ol>
+
+ <p>The value of the <code>name</code> property of this function is <code>"[Symbol.iterator]"</code>.</p>
+ </section>
+
+ <section id="sec-%loaderiteratorprototype%-@@tostringtag">
+ <h1><span class="secnum" id="sec-26.3.5.2.3"><a href="#sec-%loaderiteratorprototype%-@@tostringtag"
+ title="link to this section">26.3.5.2.3</a></span> %LoaderIteratorPrototype% [ @@toStringTag ]</h1>
+
+ <p>The initial value of the @@toStringTag property is the string value <b>"<code>Loader Iterator</code>"</b>.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-loader-iterator-instances">
+ <h1><span class="secnum" id="sec-26.3.5.3"><a href="#sec-properties-of-loader-iterator-instances"
+ title="link to this section">26.3.5.3</a></span> Properties of Loader Iterator Instances</h1>
+
+ <p>Loader Iterator instances are ordinary objects that inherit properties from the %LoaderIteratorPrototype% intrinsic
+ object. Loader Iterator instances are initially created with the internal slots described in <a href="#table-51">Table
+ 51</a>.</p>
+
+ <figure>
+ <figcaption><span id="table-51">Table 51</span> — Internal Slots of Loader Iterator Instances</figcaption>
+ <table class="real-table">
+ <tr>
+ <th style="border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-top: 2px solid #000000">Internal Slot</th>
+ <th style="border-bottom: 1px solid #000000; border-left: 0px solid black; border-right: 1px solid #000000; border-top: 2px solid #000000">Description</th>
+ </tr>
+ <tr>
+ <td>[[Loader]]</td>
+ <td>The Loader object that is being iterated.</td>
+ </tr>
+ <tr>
+ <td>[[LoaderNextIndex]]</td>
+ <td>The integer index of the next Loader registry data element to be examined by this iterator.</td>
+ </tr>
+ <tr>
+ <td>[[LoaderIterationKind]]</td>
+ <td>A string value that identifies what is to be returned for each element of the iteration. The possible values are: <b>"<code>key</code>"</b>, <b>"<code>value</code>"</b>, <b>"<code>key+value</code>"</b>.</td>
+ </tr>
+ </table>
+ </figure>
+ </section>
+ </section>
+ </section>
+
+ <section id="sec-system-object">
+ <h1><span class="secnum" id="sec-26.4"><a href="#sec-system-object" title="link to this section">26.4</a></span> The System
+ Object</h1>
+
+ <p>The System object is the Loader Object instance associated with the <a href="#sec-code-realms">Realm</a> of the current
+ global object.</p>
+ </section>
+
+ <section id="sec-proxy-objects">
+ <div class="front">
+ <h1><span class="secnum" id="sec-26.5"><a href="#sec-proxy-objects" title="link to this section">26.5</a></span> Proxy
+ Objects</h1>
+ </div>
+
+ <section id="sec-proxy-constructor-function">
+ <div class="front">
+ <h1><span class="secnum" id="sec-26.5.1"><a href="#sec-proxy-constructor-function"
+ title="link to this section">26.5.1</a></span> The Proxy Constructor Function</h1>
+
+ <p>The Proxy Constructor is a Built-in Function with unique [[Construct]] behaviour. It is not intended to be
+ subclassed.</p>
+
+ <p>The Proxy Constructor does not have a <code>prototype</code> property.</p>
+
+ <p>The value of the <code>length</code> property of the Proxy Constructor is 2.</p>
+ </div>
+
+ <section id="sec-proxy-target-handler">
+ <h1><span class="secnum" id="sec-26.5.1.1"><a href="#sec-proxy-target-handler"
+ title="link to this section">26.5.1.1</a></span> Proxy ( target, handler )</h1>
+
+ <p>The <code>Proxy</code> function is not intended to be directly called as a function. If it is called, the following
+ steps are performed:</p>
+
+ <ol class="proc">
+ <li>Throw a <b>TypeError</b> exception.</li>
+ </ol>
+ </section>
+
+ <section id="sec-new-proxy-target-handler">
+ <h1><span class="secnum" id="sec-26.5.1.2"><a href="#sec-new-proxy-target-handler"
+ title="link to this section">26.5.1.2</a></span> new Proxy ( target, handler )</h1>
+
+ <p>When <code>Proxy</code> is called as part of a <code>new</code> expression it is a constructor: it creates and
+ initializes a new exotic proxy object. <code>Proxy</code> called as part of a new expression with arguments
+ <var>target</var> and <var>handler</var> performs the following steps:</p>
+
+ <ol class="proc">
+ <li>Return <a href="#sec-proxycreate">ProxyCreate</a>(<i>target</i>, <i>handler</i>).</li>
+ </ol>
+
+ <p>If <code>Proxy</code> is implemented as an <a href="#sec-ecmascript-function-objects">ECMAScript function object</a>,
+ it must have a [[Construct]] internal method that performs the above steps.</p>
+ </section>
+ </section>
+
+ <section id="sec-properties-of-the-proxy-constructor-function">
+ <div class="front">
+ <h1><span class="secnum" id="sec-26.5.2"><a href="#sec-properties-of-the-proxy-constructor-function"
+ title="link to this section">26.5.2</a></span> Properties of the Proxy Constructor Function</h1>
+ </div>
+
+ <section id="sec-proxy.revocable">
+ <div class="front">
+ <h1><span class="secnum" id="sec-26.5.2.1"><a href="#sec-proxy.revocable"
+ title="link to this section">26.5.2.1</a></span> Proxy.revocable ( target, handler )</h1>
+
+ <p>The <code>Proxy.revocable</code> function is used to create a revocable Proxy object. When
+ <code>Proxy.revocable</code> is called with arguments <var>target</var> and <var>handler</var> the following steps are
+ taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>p</i> be <a href="#sec-proxycreate">ProxyCreate</a>(<i>target</i>, <i>handler</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>p</i>).</li>
+ <li>Let <i>revoker</i> be a new built-in function object as defined in <a
+ href="#sec-proxy-revocation-functions">26.5.2.1.1</a>.</li>
+ <li>Set the [[RevokableProxy]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of
+ <i>revoker</i> to <i>p</i>.</li>
+ <li>Let <i>result</i> be <a href="#sec-objectcreate">ObjectCreate</a>(%ObjectPrototype%).</li>
+ <li><a href="#sec-createdataproperty">CreateDataProperty</a>(<i>result</i>, <code>"proxy"</code>, <i>p</i>).</li>
+ <li><a href="#sec-createdataproperty">CreateDataProperty</a>(<i>result</i>, <code>"revoke"</code>,
+ <i>revoker</i>).</li>
+ <li>Return <i>result</i>.</li>
+ </ol>
+ </div>
+
+ <section id="sec-proxy-revocation-functions">
+ <h1><span class="secnum" id="sec-26.5.2.1.1"><a href="#sec-proxy-revocation-functions"
+ title="link to this section">26.5.2.1.1</a></span> Proxy Revocation Functions</h1>
+
+ <p>A Proxy revocation function is an anonymous function that has the ability to invalidate a specific Proxy object.</p>
+
+ <p>Each Proxy revocation function has a [[RevokableProxy]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</p>
+
+ <p>When a Proxy revocation function, <var>F</var>, is called the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>p</i> be the value of <i>F</i>’s [[RevokableProxy]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>p</i> is <b>null</b>, then return <b>undefined</b>.</li>
+ <li>Set the value of <i>F</i>’s [[RevokableProxy]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to <b>null</b>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>p</i> is a Proxy object.</li>
+ <li>Set the [[ProxyTarget]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>p</i> to
+ <b>null</b>.</li>
+ <li>Set the [[ProxyHandler]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of <i>p</i>
+ to <b>null</b>.</li>
+ <li>Return <b>undefined</b>.</li>
+ </ol>
+ </section>
+ </section>
+ </section>
+ </section>
+</section>
+
+<section id="sec-grammar-summary">
+ <div class="front">
+ <h1><span class="secnum" id="sec-A"><a href="#sec-grammar-summary" title="link to this section">Annex A</a></span> <span
+ class="section-status">(informative)</span> Grammar Summary</h1>
+
+ <p style="background-color: #FFC000"><b>TODO: The Grammars in the Annex have not yet been updated for ES6. For now, see the
+ grammars in the main body of the specification.</b></p>
+ </div>
+
+ <section id="sec-lexical-grammar">
+ <div class="front">
+ <h1><span class="secnum" id="sec-A.1"><a href="#sec-lexical-grammar" title="link to this section">A.1</a></span> Lexical
+ Grammar</h1>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-source-text">See 10.1</a></div>
+ <div class="lhs"><span class="nt">SourceCharacter</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="gprose">any Unicode code point</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-ecmascript-language-lexical-grammar">See clause 11</a></div>
+ <div class="lhs"><span class="nt">InputElementDiv</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">WhiteSpace</span></div>
+ <div class="rhs"><span class="nt">LineTerminator</span></div>
+ <div class="rhs"><span class="nt">Comment</span></div>
+ <div class="rhs"><span class="nt">Token</span></div>
+ <div class="rhs"><span class="nt">RightBracePunctuator</span></div>
+ <div class="rhs"><span class="nt">DivPunctuator</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-ecmascript-language-lexical-grammar">See clause 11</a></div>
+ <div class="lhs"><span class="nt">InputElementRegExp</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">WhiteSpace</span></div>
+ <div class="rhs"><span class="nt">LineTerminator</span></div>
+ <div class="rhs"><span class="nt">Comment</span></div>
+ <div class="rhs"><span class="nt">Token</span></div>
+ <div class="rhs"><span class="nt">RightBracePunctuator</span></div>
+ <div class="rhs"><span class="nt">RegularExpressionLiteral</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-ecmascript-language-lexical-grammar">See clause 11</a></div>
+ <div class="lhs"><span class="nt">InputElementTemplateTail</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">WhiteSpace</span></div>
+ <div class="rhs"><span class="nt">LineTerminator</span></div>
+ <div class="rhs"><span class="nt">Comment</span></div>
+ <div class="rhs"><span class="nt">Token</span></div>
+ <div class="rhs"><span class="nt">DivPunctuator</span></div>
+ <div class="rhs"><span class="nt">TemplateSubstitutionTail</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-white-space">See 11.2</a></div>
+ <div class="lhs"><span class="nt">WhiteSpace</span> <span class="geq">::</span> </div>
+ <div class="rhs"><TAB></div>
+ <div class="rhs"><VT></div>
+ <div class="rhs"><FF></div>
+ <div class="rhs"><SP></div>
+ <div class="rhs"><NBSP></div>
+ <div class="rhs"><BOM></div>
+ <div class="rhs"><USP></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-line-terminators">See 11.3</a></div>
+ <div class="lhs"><span class="nt">LineTerminator</span> <span class="geq">::</span> </div>
+ <div class="rhs"><LF></div>
+ <div class="rhs"><CR></div>
+ <div class="rhs"><LS></div>
+ <div class="rhs"><PS></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-line-terminators">See 11.3</a></div>
+ <div class="lhs"><span class="nt">LineTerminatorSequence</span> <span class="geq">::</span> </div>
+ <div class="rhs"><LF></div>
+ <div class="rhs"><CR> <span class="grhsannot">[lookahead ∉ <LF> ]</span></div>
+ <div class="rhs"><LS></div>
+ <div class="rhs"><PS></div>
+ <div class="rhs"><CR> <LF></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-comments">See 11.4</a></div>
+ <div class="lhs"><span class="nt">Comment</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">MultiLineComment</span></div>
+ <div class="rhs"><span class="nt">SingleLineComment</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-comments">See 11.4</a></div>
+ <div class="lhs"><span class="nt">MultiLineComment</span> <span class="geq">::</span> </div>
+ <div class="rhs"><code class="t">/*</code> <span class="nt">MultiLineCommentChars</span><sub>opt</sub> <code class="t">*/</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-comments">See 11.4</a></div>
+ <div class="lhs"><span class="nt">MultiLineCommentChars</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">MultiLineNotAsteriskChar</span> <span class="nt">MultiLineCommentChars</span><sub>opt</sub></div>
+ <div class="rhs"><code class="t">*</code> <span class="nt">PostAsteriskCommentChars</span><sub>opt</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-comments">See 11.4</a></div>
+ <div class="lhs"><span class="nt">PostAsteriskCommentChars</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">MultiLineNotForwardSlashOrAsteriskChar</span> <span class="nt">MultiLineCommentChars</span><sub>opt</sub></div>
+ <div class="rhs"><code class="t">*</code> <span class="nt">PostAsteriskCommentChars</span><sub>opt</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-comments">See 11.4</a></div>
+ <div class="lhs"><span class="nt">MultiLineNotAsteriskChar</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">SourceCharacter</span> <span class="grhsmod">but not</span> <code class="t">*</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-comments">See 11.4</a></div>
+ <div class="lhs"><span class="nt">MultiLineNotForwardSlashOrAsteriskChar</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">SourceCharacter</span> <span class="grhsmod">but not one of</span> <code class="t">/</code> <span class="grhsmod">or</span> <code class="t">*</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-comments">See 11.4</a></div>
+ <div class="lhs"><span class="nt">SingleLineComment</span> <span class="geq">::</span> </div>
+ <div class="rhs"><code class="t">//</code> <span class="nt">SingleLineCommentChars</span><sub>opt</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-comments">See 11.4</a></div>
+ <div class="lhs"><span class="nt">SingleLineCommentChars</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">SingleLineCommentChar</span> <span class="nt">SingleLineCommentChars</span><sub>opt</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-comments">See 11.4</a></div>
+ <div class="lhs"><span class="nt">SingleLineCommentChar</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">SourceCharacter</span> <span class="grhsmod">but not</span> <span class="nt">LineTerminator</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-tokens">See 11.5</a></div>
+ <div class="lhs"><span class="nt">Token</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">IdentifierName</span></div>
+ <div class="rhs"><span class="nt">Punctuator</span></div>
+ <div class="rhs"><span class="nt">NumericLiteral</span></div>
+ <div class="rhs"><span class="nt">StringLiteral</span></div>
+ <div class="rhs"><span class="nt">Template</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-names-and-keywords">See 11.6</a></div>
+ <div class="lhs"><span class="nt">IdentifierName</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">IdentifierStart</span></div>
+ <div class="rhs"><span class="nt">IdentifierName</span> <span class="nt">IdentifierPart</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-names-and-keywords">See 11.6</a></div>
+ <div class="lhs"><span class="nt">IdentifierStart</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">UnicodeIDStart</span></div>
+ <div class="rhs"><code class="t">$</code></div>
+ <div class="rhs"><code class="t">_</code></div>
+ <div class="rhs"><code class="t">\</code> <span class="nt">UnicodeEscapeSequence</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-names-and-keywords">See 11.6</a></div>
+ <div class="lhs"><span class="nt">IdentifierPart</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">UnicodeIDContinue</span></div>
+ <div class="rhs"><code class="t">$</code></div>
+ <div class="rhs"><code class="t">_</code></div>
+ <div class="rhs"><code class="t">\</code> <span class="nt">UnicodeEscapeSequence</span></div>
+ <div class="rhs"><ZWNJ></div>
+ <div class="rhs"><ZWJ></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-names-and-keywords">See 11.6</a></div>
+ <div class="lhs"><span class="nt">UnicodeIDStart</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="gprose">any Unicode code point with the Unicode property “ID_Start”</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-names-and-keywords">See 11.6</a></div>
+ <div class="lhs"><span class="nt">UnicodeIDContinue</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="gprose">any Unicode code point with the Unicode property “ID_Continue”</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-reserved-words">See 11.6.2</a></div>
+ <div class="lhs"><span class="nt">ReservedWord</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">Keyword</span></div>
+ <div class="rhs"><span class="nt">FutureReservedWord</span></div>
+ <div class="rhs"><span class="nt">NullLiteral</span></div>
+ <div class="rhs"><span class="nt">BooleanLiteral</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-keywords">See 11.6.2.1</a></div>
+ <div class="lhs"><span class="nt">Keyword</span> <span class="geq">::</span> <span class="grhsmod">one of</span> </div>
+ </div>
+
+ <figure>
+ <table class="lightweight-table">
+ <tr>
+ <td><code>break</code></td>
+ <td><code>do</code></td>
+ <td><code>in</code></td>
+ <td><code>typeof</code></td>
+ </tr>
+ <tr>
+ <td><code>case</code></td>
+ <td><code>else</code></td>
+ <td><code>instanceof</code></td>
+ <td><code>var</code></td>
+ </tr>
+ <tr>
+ <td><code>catch</code></td>
+ <td><code>export</code></td>
+ <td><code>new</code></td>
+ <td><code>void</code></td>
+ </tr>
+ <tr>
+ <td><code>class</code></td>
+ <td><code>extends</code></td>
+ <td><code>return</code></td>
+ <td><code>while</code></td>
+ </tr>
+ <tr>
+ <td><code>const</code></td>
+ <td><code>finally</code></td>
+ <td><code>super</code></td>
+ <td><code>with</code></td>
+ </tr>
+ <tr>
+ <td><code>continue</code></td>
+ <td><code>for</code></td>
+ <td><code>switch</code></td>
+ <td><code>yield</code></td>
+ </tr>
+ <tr>
+ <td><code>debugger</code></td>
+ <td><code>function</code></td>
+ <td><code>this</code></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td><code>delete</code></td>
+ <td><code>import</code></td>
+ <td><code>try</code></td>
+ <td></td>
+ </tr>
+ </table>
+ </figure>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-future-reserved-words">See 11.6.2.2</a></div>
+ <div class="lhs"><span class="nt">FutureReservedWord</span> <span class="geq">::</span> </div>
+ <div class="rhs"><code class="t">enum</code></div>
+ </div>
+
+ <p>The following tokens are also considered to be <span class="nt">FutureReservedWords</span> when parsing <a
+ href="#sec-strict-mode-code">strict mode code</a> (<a href="#sec-strict-mode-code">see 10.2.1</a>).</p>
+
+ <figure>
+ <table class="lightweight-table">
+ <tr>
+ <td><code>implements</code></td>
+ <td><code>package</code></td>
+ <td><code>protected</code></td>
+ <td><code>static</code></td>
+ </tr>
+ <tr>
+ <td><code>interface</code></td>
+ <td><code>private</code></td>
+ <td><code>public</code></td>
+ <td></td>
+ </tr>
+ </table>
+ </figure>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-punctuators">See 11.7</a></div>
+ <div class="lhs"><span class="nt">Punctuator</span> <span class="geq">::</span> <span class="grhsmod">one of</span> </div>
+ </div>
+
+ <figure>
+ <table class="lightweight-table">
+ <tr>
+ <td><code>{</code></td>
+ <td><code>}</code></td>
+ <td><code>(</code></td>
+ <td><code>)</code></td>
+ <td><code>[</code></td>
+ <td><code>]</code></td>
+ </tr>
+ <tr>
+ <td><code>.</code></td>
+ <td><code>;</code></td>
+ <td><code>,</code></td>
+ <td><code><</code></td>
+ <td><code>></code></td>
+ <td><code><=</code></td>
+ </tr>
+ <tr>
+ <td><code>>=</code></td>
+ <td><code>==</code></td>
+ <td><code>!=</code></td>
+ <td><code>===</code></td>
+ <td><code>!==</code></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td><code>+</code></td>
+ <td><code>-</code></td>
+ <td><code>*</code></td>
+ <td><code>%</code></td>
+ <td><code>++</code></td>
+ <td><code>--</code></td>
+ </tr>
+ <tr>
+ <td><code><<</code></td>
+ <td><code>>></code></td>
+ <td><code>>>></code></td>
+ <td><code>&</code></td>
+ <td><code>|</code></td>
+ <td><code>^</code></td>
+ </tr>
+ <tr>
+ <td><code>!</code></td>
+ <td><code>~</code></td>
+ <td><code>&&</code></td>
+ <td><code>||</code></td>
+ <td><code>?</code></td>
+ <td><code>:</code></td>
+ </tr>
+ <tr>
+ <td><code>=</code></td>
+ <td><code>+=</code></td>
+ <td><code>-=</code></td>
+ <td><code>*=</code></td>
+ <td><code>%=</code></td>
+ <td><code><<=</code></td>
+ </tr>
+ <tr>
+ <td><code>>>=</code></td>
+ <td><code>>>>=</code></td>
+ <td><code>&=</code></td>
+ <td><code>|=</code></td>
+ <td><code>^=</code></td>
+ <td><code>=></code></td>
+ </tr>
+ </table>
+ </figure>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-punctuators">See 11.7</a></div>
+ <div class="lhs"><span class="nt">DivPunctuator</span> <span class="geq">::</span> <span class="grhsmod">one of</span> </div>
+ </div>
+
+ <figure>
+ <table class="lightweight-table">
+ <tr>
+ <td><code>/</code></td>
+ <td><code>/=</code></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ </tr>
+ </table>
+ </figure>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-punctuators">See 11.7</a></div>
+ <div class="lhs"><span class="nt">RightBracePunctuator</span> <span class="geq">::</span> <span class="grhsmod">one of</span> </div>
+ </div>
+
+ <figure>
+ <table class="lightweight-table">
+ <tr>
+ <td><code>}</code></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ </tr>
+ </table>
+ </figure>
+
+ <div class="gp">
+ <div class="gsumxref">See 7.8.1</div>
+ <div class="lhs"><span class="nt">NullLiteral</span> <span class="geq">::</span> </div>
+ <div class="rhs"><code class="t">null</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-boolean-literals">See 11.8.2</a></div>
+ <div class="lhs"><span class="nt">BooleanLiteral</span> <span class="geq">::</span> </div>
+ <div class="rhs"><code class="t">true</code></div>
+ <div class="rhs"><code class="t">false</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-numeric-literals">See 11.8.3</a></div>
+ <div class="lhs"><span class="nt">NumericLiteral</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">DecimalLiteral</span></div>
+ <div class="rhs"><span class="nt">BinaryIntegerLiteral</span></div>
+ <div class="rhs"><span class="nt">OctalIntegerLiteral</span></div>
+ <div class="rhs"><span class="nt">HexIntegerLiteral</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-numeric-literals">See 11.8.3</a></div>
+ <div class="lhs"><span class="nt">DecimalLiteral</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">DecimalIntegerLiteral</span> <code class="t">.</code> <span class="nt">DecimalDigits</span><sub>opt</sub> <span class="nt">ExponentPart</span><sub>opt</sub></div>
+ <div class="rhs"><code class="t">.</code> <span class="nt">DecimalDigits</span> <span class="nt">ExponentPart</span><sub>opt</sub></div>
+ <div class="rhs"><span class="nt">DecimalIntegerLiteral</span> <span class="nt">ExponentPart</span><sub>opt</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-numeric-literals">See 11.8.3</a></div>
+ <div class="lhs"><span class="nt">DecimalIntegerLiteral</span> <span class="geq">::</span> </div>
+ <div class="rhs"><code class="t">0</code></div>
+ <div class="rhs"><span class="nt">NonZeroDigit</span> <span class="nt">DecimalDigits</span><sub>opt</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-numeric-literals">See 11.8.3</a></div>
+ <div class="lhs"><span class="nt">DecimalDigits</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">DecimalDigit</span></div>
+ <div class="rhs"><span class="nt">DecimalDigits</span> <span class="nt">DecimalDigit</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-numeric-literals">See 11.8.3</a></div>
+ <div class="lhs"><span class="nt">DecimalDigit</span> <span class="geq">::</span> <span class="grhsmod">one of</span> </div>
+ <div class="rhs"><code class="t">0</code> <code class="t">1</code> <code class="t">2</code> <code class="t">3</code> <code class="t">4</code> <code class="t">5</code> <code class="t">6</code> <code class="t">7</code> <code class="t">8</code> <code class="t">9</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-numeric-literals">See 11.8.3</a></div>
+ <div class="lhs"><span class="nt">NonZeroDigit</span> <span class="geq">::</span> <span class="grhsmod">one of</span> </div>
+ <div class="rhs"><code class="t">1</code> <code class="t">2</code> <code class="t">3</code> <code class="t">4</code> <code class="t">5</code> <code class="t">6</code> <code class="t">7</code> <code class="t">8</code> <code class="t">9</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-numeric-literals">See 11.8.3</a></div>
+ <div class="lhs"><span class="nt">ExponentPart</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">ExponentIndicator</span> <span class="nt">SignedInteger</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-numeric-literals">See 11.8.3</a></div>
+ <div class="lhs"><span class="nt">ExponentIndicator</span> <span class="geq">::</span> <span class="grhsmod">one of</span> </div>
+ <div class="rhs"><code class="t">e</code> <code class="t">E</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-numeric-literals">See 11.8.3</a></div>
+ <div class="lhs"><span class="nt">SignedInteger</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">DecimalDigits</span></div>
+ <div class="rhs"><code class="t">+</code> <span class="nt">DecimalDigits</span></div>
+ <div class="rhs"><code class="t">-</code> <span class="nt">DecimalDigits</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-numeric-literals">See 11.8.3</a></div>
+ <div class="lhs"><span class="nt">BinaryIntegerLiteral</span> <span class="geq">::</span> </div>
+ <div class="rhs"><code class="t">0b</code> <span class="nt">BinaryDigits</span></div>
+ <div class="rhs"><code class="t">0B</code> <span class="nt">BinaryDigits</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-numeric-literals">See 11.8.3</a></div>
+ <div class="lhs"><span class="nt">BinaryDigits</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">BinaryDigit</span></div>
+ <div class="rhs"><span class="nt">BinaryDigits</span> <span class="nt">BinaryDigit</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-numeric-literals">See 11.8.3</a></div>
+ <div class="lhs"><span class="nt">BinaryDigit</span> <span class="geq">::</span> <span class="grhsmod">one of</span> </div>
+ <div class="rhs"><code class="t">0</code> <code class="t">1</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-numeric-literals">See 11.8.3</a></div>
+ <div class="lhs"><span class="nt">OctalIntegerLiteral</span> <span class="geq">::</span> </div>
+ <div class="rhs"><code class="t">0o</code> <span class="nt">OctalDigits</span></div>
+ <div class="rhs"><code class="t">0O</code> <span class="nt">OctalDigits</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-numeric-literals">See 11.8.3</a></div>
+ <div class="lhs"><span class="nt">OctalDigits</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">OctalDigit</span></div>
+ <div class="rhs"><span class="nt">OctalDigits</span> <span class="nt">OctalDigit</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-numeric-literals">See 11.8.3</a></div>
+ <div class="lhs"><span class="nt">OctalDigit</span> <span class="geq">::</span> <span class="grhsmod">one of</span> </div>
+ <div class="rhs"><code class="t">0</code> <code class="t">1</code> <code class="t">2</code> <code class="t">3</code> <code class="t">4</code> <code class="t">5</code> <code class="t">6</code> <code class="t">7</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-numeric-literals">See 11.8.3</a></div>
+ <div class="lhs"><span class="nt">HexIntegerLiteral</span> <span class="geq">::</span> </div>
+ <div class="rhs"><code class="t">0x</code> <span class="nt">HexDigits</span></div>
+ <div class="rhs"><code class="t">0X</code> <span class="nt">HexDigist</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-numeric-literals">See 11.8.3</a></div>
+ <div class="lhs"><span class="nt">HexDigits</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">HexDigit</span></div>
+ <div class="rhs"><span class="nt">HexDigits</span> <span class="nt">HexDigit</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-numeric-literals">See 11.8.3</a></div>
+ <div class="lhs"><span class="nt">HexDigit</span> <span class="geq">::</span> <span class="grhsmod">one of</span> </div>
+ <div class="rhs"><code class="t">0</code> <code class="t">1</code> <code class="t">2</code> <code class="t">3</code> <code class="t">4</code> <code class="t">5</code> <code class="t">6</code> <code class="t">7</code> <code class="t">8</code> <code class="t">9</code> <code class="t">a</code> <code class="t">b</code> <code class="t">c</code> <code class="t">d</code> <code class="t">e</code> <code class="t">f</code> <code class="t">A</code> <code class="t">B</code> <code class="t">C</code> <code class="t">D</code> <code class="t">E</code> <code class="t">F</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-string-literals">See 11.8.4</a></div>
+ <div class="lhs"><span class="nt">StringLiteral</span> <span class="geq">::</span> </div>
+ <div class="rhs"><code class="t">"</code> <span class="nt">DoubleStringCharacters</span><sub>opt</sub> <code class="t">"</code></div>
+ <div class="rhs"><code class="t">'</code> <span class="nt">SingleStringCharacters</span><sub>opt</sub> <code class="t">'</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-string-literals">See 11.8.4</a></div>
+ <div class="lhs"><span class="nt">DoubleStringCharacters</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">DoubleStringCharacter</span> <span class="nt">DoubleStringCharacters</span><sub>opt</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-string-literals">See 11.8.4</a></div>
+ <div class="lhs"><span class="nt">SingleStringCharacters</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">SingleStringCharacter</span> <span class="nt">SingleStringCharacters</span><sub>opt</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-string-literals">See 11.8.4</a></div>
+ <div class="lhs"><span class="nt">DoubleStringCharacter</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">SourceCharacter</span> <span class="grhsmod">but not one of</span> <code class="t">"</code> <span class="grhsmod">or</span> <code class="t">\</code> <span class="grhsmod">or</span> <span class="nt">LineTerminator</span></div>
+ <div class="rhs"><code class="t">\</code> <span class="nt">EscapeSequence</span></div>
+ <div class="rhs"><span class="nt">LineContinuation</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-string-literals">See 11.8.4</a></div>
+ <div class="lhs"><span class="nt">SingleStringCharacter</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">SourceCharacter</span> <span class="grhsmod">but not one of</span> <code class="t">'</code> <span class="grhsmod">or</span> <code class="t">\</code> <span class="grhsmod">or</span> <span class="nt">LineTerminator</span></div>
+ <div class="rhs"><code class="t">\</code> <span class="nt">EscapeSequence</span></div>
+ <div class="rhs"><span class="nt">LineContinuation</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-string-literals">See 11.8.4</a></div>
+ <div class="lhs"><span class="nt">LineContinuation</span> <span class="geq">::</span> </div>
+ <div class="rhs"><code class="t">\</code> <span class="nt">LineTerminatorSequence</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-string-literals">See 11.8.4</a></div>
+ <div class="lhs"><span class="nt">EscapeSequence</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">CharacterEscapeSequence</span></div>
+ <div class="rhs"><code class="t">0</code> <span class="grhsannot">[lookahead ∉ <span class="nt">DecimalDigit</span>]</span></div>
+ <div class="rhs"><span class="nt">HexEscapeSequence</span></div>
+ <div class="rhs"><span class="nt">UnicodeEscapeSequence</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-string-literals">See 11.8.4</a></div>
+ <div class="lhs"><span class="nt">CharacterEscapeSequence</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">SingleEscapeCharacter</span></div>
+ <div class="rhs"><span class="nt">NonEscapeCharacter</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-string-literals">See 11.8.4</a></div>
+ <div class="lhs"><span class="nt">SingleEscapeCharacter</span> <span class="geq">::</span> <span class="grhsmod">one of</span> </div>
+ <div class="rhs"><code class="t">'</code> <code class="t">"</code> <code class="t">\</code> <code class="t">b</code> <code class="t">f</code> <code class="t">n</code> <code class="t">r</code> <code class="t">t</code> <code class="t">v</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-string-literals">See 11.8.4</a></div>
+ <div class="lhs"><span class="nt">NonEscapeCharacter</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">SourceCharacter</span> <span class="grhsmod">but not one of</span> <span class="nt">EscapeCharacter</span> <span class="grhsmod">or</span> <span class="nt">LineTerminator</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-string-literals">See 11.8.4</a></div>
+ <div class="lhs"><span class="nt">EscapeCharacter</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">SingleEscapeCharacter</span></div>
+ <div class="rhs"><span class="nt">DecimalDigit</span></div>
+ <div class="rhs"><code class="t">x</code></div>
+ <div class="rhs"><code class="t">u</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-string-literals">See 11.8.4</a></div>
+ <div class="lhs"><span class="nt">HexEscapeSequence</span> <span class="geq">::</span> </div>
+ <div class="rhs"><code class="t">x</code> <span class="nt">HexDigit</span> <span class="nt">HexDigit</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-string-literals">See 11.8.4</a></div>
+ <div class="lhs"><span class="nt">UnicodeEscapeSequence</span> <span class="geq">::</span> </div>
+ <div class="rhs"><code class="t">u</code> <span class="nt">Hex4Digits</span></div>
+ <div class="rhs"><code class="t">u{</code> <span class="nt">HexDigits</span> <code class="t">}</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-string-literals">See 11.8.4</a></div>
+ <div class="lhs"><span class="nt">Hex4Digits</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">HexDigit</span> <span class="nt">HexDigit</span> <span class="nt">HexDigit</span> <span class="nt">HexDigit</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-regular-expression-literals">See 11.8.5</a></div>
+ <div class="lhs"><span class="nt">RegularExpressionLiteral</span> <span class="geq">::</span> </div>
+ <div class="rhs"><code class="t">/</code> <span class="nt">RegularExpressionBody</span> <code class="t">/</code> <span class="nt">RegularExpressionFlags</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-regular-expression-literals">See 11.8.5</a></div>
+ <div class="lhs"><span class="nt">RegularExpressionBody</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">RegularExpressionFirstChar</span> <span class="nt">RegularExpressionChars</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-regular-expression-literals">See 11.8.5</a></div>
+ <div class="lhs"><span class="nt">RegularExpressionChars</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="grhsannot">[empty]</span></div>
+ <div class="rhs"><span class="nt">RegularExpressionChars</span> <span class="nt">RegularExpressionChar</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-regular-expression-literals">See 11.8.5</a></div>
+ <div class="lhs"><span class="nt">RegularExpressionFirstChar</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">RegularExpressionNonTerminator</span> <span class="grhsmod">but not one of</span> <code class="t">*</code> <span class="grhsmod">or</span> <code class="t">\</code> <span class="grhsmod">or</span> <code class="t">/</code> <span class="grhsmod">or</span> <code class="t">[</code></div>
+ <div class="rhs"><span class="nt">RegularExpressionBackslashSequence</span></div>
+ <div class="rhs"><span class="nt">RegularExpressionClass</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-regular-expression-literals">See 11.8.5</a></div>
+ <div class="lhs"><span class="nt">RegularExpressionChar</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">RegularExpressionNonTerminator</span> <span class="grhsmod">but not one of</span> <code class="t">\</code> <span class="grhsmod">or</span> <code class="t">/</code> <span class="grhsmod">or</span> <code class="t">[</code></div>
+ <div class="rhs"><span class="nt">RegularExpressionBackslashSequence</span></div>
+ <div class="rhs"><span class="nt">RegularExpressionClass</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-regular-expression-literals">See 11.8.5</a></div>
+ <div class="lhs"><span class="nt">RegularExpressionBackslashSequence</span> <span class="geq">::</span> </div>
+ <div class="rhs"><code class="t">\</code> <span class="nt">RegularExpressionNonTerminator</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-regular-expression-literals">See 11.8.5</a></div>
+ <div class="lhs"><span class="nt">RegularExpressionNonTerminator</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">SourceCharacter</span> <span class="grhsmod">but not</span> <span class="nt">LineTerminator</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-regular-expression-literals">See 11.8.5</a></div>
+ <div class="lhs"><span class="nt">RegularExpressionClass</span> <span class="geq">::</span> </div>
+ <div class="rhs"><code class="t">[</code> <span class="nt">RegularExpressionClassChars</span> <code class="t">]</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-regular-expression-literals">See 11.8.5</a></div>
+ <div class="lhs"><span class="nt">RegularExpressionClassChars</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="grhsannot">[empty]</span></div>
+ <div class="rhs"><span class="nt">RegularExpressionClassChars</span> <span class="nt">RegularExpressionClassChar</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-regular-expression-literals">See 11.8.5</a></div>
+ <div class="lhs"><span class="nt">RegularExpressionClassChar</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">RegularExpressionNonTerminator</span> <span class="grhsmod">but not one of</span> <code class="t">]</code> <span class="grhsmod">or</span> <code class="t">\</code></div>
+ <div class="rhs"><span class="nt">RegularExpressionBackslashSequence</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-literals-regular-expression-literals">See 11.8.5</a></div>
+ <div class="lhs"><span class="nt">RegularExpressionFlags</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="grhsannot">[empty]</span></div>
+ <div class="rhs"><span class="nt">RegularExpressionFlags</span> <span class="nt">IdentifierPart</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-template-literal-lexical-components">See 11.8.6</a></div>
+ <div class="lhs"><span class="nt">Template</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">NoSubstitutionTemplate</span></div>
+ <div class="rhs"><span class="nt">TemplateHead</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-template-literal-lexical-components">See 11.8.6</a></div>
+ <div class="lhs"><span class="nt">NoSubstitutionTemplate</span> <span class="geq">::</span> </div>
+ <div class="rhs"><code class="t">`</code> <span class="nt">TemplateCharacters</span><sub>opt</sub> <code class="t">`</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-template-literal-lexical-components">See 11.8.6</a></div>
+ <div class="lhs"><span class="nt">TemplateHead</span> <span class="geq">::</span> </div>
+ <div class="rhs"><code class="t">`</code> <span class="nt">TemplateCharacters</span><sub>opt</sub> <code class="t">${</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-template-literal-lexical-components">See 11.8.6</a></div>
+ <div class="lhs"><span class="nt">TemplateSubstitutionTail</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">TemplateMiddle</span></div>
+ <div class="rhs"><span class="nt">TemplateTail</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-template-literal-lexical-components">See 11.8.6</a></div>
+ <div class="lhs"><span class="nt">TemplateMiddle</span> <span class="geq">::</span> </div>
+ <div class="rhs"><code class="t">}</code> <span class="nt">TemplateCharacters</span><sub>opt</sub> <code class="t">${</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-template-literal-lexical-components">See 11.8.6</a></div>
+ <div class="lhs"><span class="nt">TemplateTail</span> <span class="geq">::</span> </div>
+ <div class="rhs"><code class="t">}</code> <span class="nt">TemplateCharacters</span><sub>opt</sub> <code class="t">`</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-template-literal-lexical-components">See 11.8.6</a></div>
+ <div class="lhs"><span class="nt">TemplateCharacters</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">TemplateCharacter</span> <span class="nt">TemplateCharacters</span><sub>opt</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-template-literal-lexical-components">See 11.8.6</a></div>
+ <div class="lhs"><span class="nt">TemplateCharacter</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">SourceCharacter</span> <span class="grhsmod">but not one of</span> <code class="t">`</code> <span class="grhsmod">or</span> <code class="t">\</code> <span class="grhsmod">or</span> <code class="t">$</code> <span class="grhsmod">or</span> <span class="nt">LineTerminatorSequence</span></div>
+ <div class="rhs"><code class="t">$</code> <span class="grhsannot">[lookahead ≠ { ]</span></div>
+ <div class="rhs"><code class="t">\</code> <span class="nt">EscapeSequence</span></div>
+ <div class="rhs"><span class="nt">LineContinuation</span></div>
+ <div class="rhs"><span class="nt">LineTerminatorSequence</span></div>
+ </div>
+ </div>
+
+ <section>
+ <h1>Expressions</h1>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-unicode-format-control-characters">See 11.1</a></div>
+ <div class="lhs"><span class="nt">PrimaryExpression</span> <span class="geq">:</span> </div>
+ <div class="rhs"><code class="t">this</code></div>
+ <div class="rhs"><span class="nt">Identifier</span></div>
+ <div class="rhs"><span class="nt">Literal</span></div>
+ <div class="rhs"><span class="nt">ArrayLiteral</span></div>
+ <div class="rhs"><span class="nt">ObjectLiteral</span></div>
+ <div class="rhs"><code class="t">(</code> <span class="nt">Expression</span> <code class="t">)</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref">See 11.1.4</div>
+ <div class="lhs"><span class="nt">ArrayLiteral</span> <span class="geq">:</span> </div>
+ <div class="rhs"><code class="t">[</code> <span class="nt">Elision</span><sub>opt</sub> <code class="t">]</code></div>
+ <div class="rhs"><code class="t">[</code> <span class="nt">ElementList</span> <code class="t">]</code></div>
+ <div class="rhs"><code class="t">[</code> <span class="nt">ElementList</span> <code class="t">,</code> <span class="nt">Elision</span><sub>opt</sub> <code class="t">]</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref">See 11.1.4</div>
+ <div class="lhs"><span class="nt">ElementList</span> <span class="geq">:</span> </div>
+ <div class="rhs"><span class="nt">Elision</span><sub>opt</sub> <span class="nt">AssignmentExpression</span></div>
+ <div class="rhs"><span class="nt">ElementList</span> <code class="t">,</code> <span class="nt">Elision</span><sub>opt</sub> <span class="nt">AssignmentExpression</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref">See 11.1.4</div>
+ <div class="lhs"><span class="nt">Elision</span> <span class="geq">:</span> </div>
+ <div class="rhs"><code class="t">,</code></div>
+ <div class="rhs"><span class="nt">Elision</span> <code class="t">,</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref">See 11.1.5</div>
+ <div class="lhs"><span class="nt">ObjectLiteral</span> <span class="geq">:</span> </div>
+ <div class="rhs"><code class="t">{</code> <code class="t">}</code></div>
+ <div class="rhs"><code class="t">{</code> <span class="nt">PropertyDefinitionList</span> <code class="t">}</code></div>
+ <div class="rhs"><code class="t">{</code> <span class="nt">PropertyDefinitionList</span> <code class="t">,</code> <code class="t">}</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref">See 11.1.5</div>
+ <div class="lhs"><span class="nt">PropertyDefinitionList</span> <span class="geq">:</span> </div>
+ <div class="rhs"><span class="nt">PropertyDefinition</span></div>
+ <div class="rhs"><span class="nt">PropertyDefinitionList</span> <code class="t">,</code> <span class="nt">PropertyDefinition</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref">See 11.1.5</div>
+ <div class="lhs"><span class="nt">PropertyDefinition</span> <span class="geq">:</span> </div>
+ <div class="rhs"><span class="nt">PropertyName</span> <code class="t">:</code> <span class="nt">AssignmentExpression</span></div>
+ <div class="rhs"><code class="t">get</code> <span class="nt">PropertyName</span> <code class="t">(</code> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ <div class="rhs"><code class="t">set</code> <span class="nt">PropertyName</span> <code class="t">(</code> <span class="nt">PropertySetParameterList</span> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref">See 11.1.5</div>
+ <div class="lhs"><span class="nt">PropertyName</span> <span class="geq">:</span> </div>
+ <div class="rhs"><span class="nt">IdentifierName</span></div>
+ <div class="rhs"><span class="nt">StringLiteral</span></div>
+ <div class="rhs"><span class="nt">NumericLiteral</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref">See 11.1.5</div>
+ <div class="lhs"><span class="nt">PropertySetParameterList</span> <span class="geq">:</span> </div>
+ <div class="rhs"><span class="nt">Identifier</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-white-space">See 11.2</a></div>
+ <div class="lhs"><span class="nt">MemberExpression</span> <span class="geq">:</span> </div>
+ <div class="rhs"><span class="nt">PrimaryExpression</span></div>
+ <div class="rhs"><span class="nt">FunctionExpression</span></div>
+ <div class="rhs"><span class="nt">MemberExpression</span> <code class="t">[</code> <span class="nt">Expression</span> <code class="t">]</code></div>
+ <div class="rhs"><span class="nt">MemberExpression</span> <code class="t">.</code> <span class="nt">IdentifierName</span></div>
+ <div class="rhs"><code class="t">new</code> <span class="nt">MemberExpression</span> <span class="nt">Arguments</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-white-space">See 11.2</a></div>
+ <div class="lhs"><span class="nt">NewExpression</span> <span class="geq">:</span> </div>
+ <div class="rhs"><span class="nt">MemberExpression</span></div>
+ <div class="rhs"><code class="t">new</code> <span class="nt">NewExpression</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-white-space">See 11.2</a></div>
+ <div class="lhs"><span class="nt">CallExpression</span> <span class="geq">:</span> </div>
+ <div class="rhs"><span class="nt">MemberExpression</span> <span class="nt">Arguments</span></div>
+ <div class="rhs"><span class="nt">CallExpression</span> <span class="nt">Arguments</span></div>
+ <div class="rhs"><span class="nt">CallExpression</span> <code class="t">[</code> <span class="nt">Expression</span> <code class="t">]</code></div>
+ <div class="rhs"><span class="nt">CallExpression</span> <code class="t">.</code> <span class="nt">IdentifierName</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-white-space">See 11.2</a></div>
+ <div class="lhs"><span class="nt">Arguments</span> <span class="geq">:</span> </div>
+ <div class="rhs"><code class="t">(</code> <code class="t">)</code></div>
+ <div class="rhs"><code class="t">(</code> <span class="nt">ArgumentList</span> <code class="t">)</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-white-space">See 11.2</a></div>
+ <div class="lhs"><span class="nt">ArgumentList</span> <span class="geq">:</span> </div>
+ <div class="rhs"><span class="nt">AssignmentExpression</span></div>
+ <div class="rhs"><span class="nt">ArgumentList</span> <code class="t">,</code> <span class="nt">AssignmentExpression</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-white-space">See 11.2</a></div>
+ <div class="lhs"><span class="nt">LeftHandSideExpression</span> <span class="geq">:</span> </div>
+ <div class="rhs"><span class="nt">NewExpression</span></div>
+ <div class="rhs"><span class="nt">CallExpression</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-line-terminators">See 11.3</a></div>
+ <div class="lhs"><span class="nt">PostfixExpression</span> <span class="geq">:</span> </div>
+ <div class="rhs"><span class="nt">LeftHandSideExpression</span></div>
+ <div class="rhs"><span class="nt">LeftHandSideExpression</span> <span class="grhsannot">[no <span class="nt">LineTerminator</span> here]</span> <code class="t">++</code></div>
+ <div class="rhs"><span class="nt">LeftHandSideExpression</span> <span class="grhsannot">[no <span class="nt">LineTerminator</span> here]</span> <code class="t">--</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-comments">See 11.4</a></div>
+ <div class="lhs"><span class="nt">UnaryExpression</span> <span class="geq">:</span> </div>
+ <div class="rhs"><span class="nt">PostfixExpression</span></div>
+ <div class="rhs"><code class="t">delete</code> <span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><code class="t">void</code> <span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><code class="t">typeof</code> <span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><code class="t">++</code> <span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><code class="t">--</code> <span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><code class="t">+</code> <span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><code class="t">-</code> <span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><code class="t">~</code> <span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><code class="t">!</code> <span class="nt">UnaryExpression</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-tokens">See 11.5</a></div>
+ <div class="lhs"><span class="nt">MultiplicativeExpression</span> <span class="geq">:</span> </div>
+ <div class="rhs"><span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><span class="nt">MultiplicativeExpression</span> <code class="t">*</code> <span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><span class="nt">MultiplicativeExpression</span> <code class="t">/</code> <span class="nt">UnaryExpression</span></div>
+ <div class="rhs"><span class="nt">MultiplicativeExpression</span> <code class="t">%</code> <span class="nt">UnaryExpression</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-names-and-keywords">See 11.6</a></div>
+ <div class="lhs"><span class="nt">AdditiveExpression</span> <span class="geq">:</span> </div>
+ <div class="rhs"><span class="nt">MultiplicativeExpression</span></div>
+ <div class="rhs"><span class="nt">AdditiveExpression</span> <code class="t">+</code> <span class="nt">MultiplicativeExpression</span></div>
+ <div class="rhs"><span class="nt">AdditiveExpression</span> <code class="t">-</code> <span class="nt">MultiplicativeExpression</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-punctuators">See 11.7</a></div>
+ <div class="lhs"><span class="nt">ShiftExpression</span> <span class="geq">:</span> </div>
+ <div class="rhs"><span class="nt">AdditiveExpression</span></div>
+ <div class="rhs"><span class="nt">ShiftExpression</span> <code class="t"><<</code> <span class="nt">AdditiveExpression</span></div>
+ <div class="rhs"><span class="nt">ShiftExpression</span> <code class="t">>></code> <span class="nt">AdditiveExpression</span></div>
+ <div class="rhs"><span class="nt">ShiftExpression</span> <code class="t">>>></code> <span class="nt">AdditiveExpression</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-ecmascript-language-lexical-grammar-literals">See 11.8</a></div>
+ <div class="lhs"><span class="nt">RelationalExpression</span> <span class="geq">:</span> </div>
+ <div class="rhs"><span class="nt">ShiftExpression</span></div>
+ <div class="rhs"><span class="nt">RelationalExpression</span> <code class="t"><</code> <span class="nt">ShiftExpression</span></div>
+ <div class="rhs"><span class="nt">RelationalExpression</span> <code class="t">></code> <span class="nt">ShiftExpression</span></div>
+ <div class="rhs"><span class="nt">RelationalExpression</span> <code class="t"><=</code> <span class="nt">ShiftExpression</span></div>
+ <div class="rhs"><span class="nt">RelationalExpression</span> <code class="t">>=</code> <span class="nt">ShiftExpression</span></div>
+ <div class="rhs"><span class="nt">RelationalExpression</span> <code class="t">instanceof</code> <span class="nt">ShiftExpression</span></div>
+ <div class="rhs"><span class="nt">RelationalExpression</span> <code class="t">in</code> <span class="nt">ShiftExpression</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-automatic-semicolon-insertion">See 11.9</a></div>
+ <div class="lhs"><span class="nt">EqualityExpression</span> <span class="geq">:</span> </div>
+ <div class="rhs"><span class="nt">RelationalExpression</span></div>
+ <div class="rhs"><span class="nt">EqualityExpression</span> <code class="t">==</code> <span class="nt">RelationalExpression</span></div>
+ <div class="rhs"><span class="nt">EqualityExpression</span> <code class="t">!=</code> <span class="nt">RelationalExpression</span></div>
+ <div class="rhs"><span class="nt">EqualityExpression</span> <code class="t">===</code> <span class="nt">RelationalExpression</span></div>
+ <div class="rhs"><span class="nt">EqualityExpression</span> <code class="t">!==</code> <span class="nt">RelationalExpression</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref">See 11.10</div>
+ <div class="lhs"><span class="nt">BitwiseANDExpression</span> <span class="geq">:</span> </div>
+ <div class="rhs"><span class="nt">EqualityExpression</span></div>
+ <div class="rhs"><span class="nt">BitwiseANDExpression</span> <code class="t">&</code> <span class="nt">EqualityExpression</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref">See 11.10</div>
+ <div class="lhs"><span class="nt">BitwiseXORExpression</span> <span class="geq">:</span> </div>
+ <div class="rhs"><span class="nt">BitwiseANDExpression</span></div>
+ <div class="rhs"><span class="nt">BitwiseXORExpression</span> <code class="t">^</code> <span class="nt">BitwiseANDExpression</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref">See 11.10</div>
+ <div class="lhs"><span class="nt">BitwiseORExpression</span> <span class="geq">:</span> </div>
+ <div class="rhs"><span class="nt">BitwiseXORExpression</span></div>
+ <div class="rhs"><span class="nt">BitwiseORExpression</span> <code class="t">|</code> <span class="nt">BitwiseXORExpression</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref">See 11.11</div>
+ <div class="lhs"><span class="nt">LogicalANDExpression</span> <span class="geq">:</span> </div>
+ <div class="rhs"><span class="nt">BitwiseORExpression</span></div>
+ <div class="rhs"><span class="nt">LogicalANDExpression</span> <code class="t">&&</code> <span class="nt">BitwiseORExpression</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref">See 11.11</div>
+ <div class="lhs"><span class="nt">LogicalORExpression</span> <span class="geq">:</span> </div>
+ <div class="rhs"><span class="nt">LogicalANDExpression</span></div>
+ <div class="rhs"><span class="nt">LogicalORExpression</span> <code class="t">||</code> <span class="nt">LogicalANDExpression</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref">See 11.12</div>
+ <div class="lhs"><span class="nt">ConditionalExpression</span> <span class="geq">:</span> </div>
+ <div class="rhs"><span class="nt">LogicalORExpression</span></div>
+ <div class="rhs"><span class="nt">LogicalORExpression</span> <code class="t">?</code> <span class="nt">AssignmentExpression</span> <code class="t">:</code> <span class="nt">AssignmentExpression</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref">See 11.13</div>
+ <div class="lhs"><span class="nt">AssignmentExpression</span> <span class="geq">:</span> </div>
+ <div class="rhs"><span class="nt">ConditionalExpression</span></div>
+ <div class="rhs"><span class="nt">LeftHandSideExpression</span> <code class="t">=</code> <span class="nt">AssignmentExpression</span></div>
+ <div class="rhs"><span class="nt">LeftHandSideExpression</span> <span class="nt">AssignmentOperator</span> <span class="nt">AssignmentExpression</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref">See 11.13</div>
+ <div class="lhs"><span class="nt">AssignmentOperator</span> <span class="geq">:</span> <span class="grhsmod">one of</span> </div>
+ </div>
+
+ <figure>
+ <table class="lightweight-table">
+ <tr>
+ <td><code>*=</code></td>
+ <td><code>/=</code></td>
+ <td><code>%=</code></td>
+ <td><code>+=</code></td>
+ <td><code>-=</code></td>
+ <td><code><<=</code></td>
+ <td><code>>>=</code></td>
+ <td><code>>>>=</code></td>
+ <td><code>&=</code></td>
+ <td><code>^=</code></td>
+ <td><code>|=</code></td>
+ </tr>
+ </table>
+ </figure>
+
+ <div class="gp">
+ <div class="gsumxref">See 11.14</div>
+ <div class="lhs"><span class="nt">Expression</span> <span class="geq">:</span> </div>
+ <div class="rhs"><span class="nt">AssignmentExpression</span></div>
+ <div class="rhs"><span class="nt">Expression</span> <code class="t">,</code> <span class="nt">AssignmentExpression</span></div>
+ </div>
+ </section>
+
+ <section>
+ <h1>Statements</h1>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-ecmascript-language-expressions">See clause 12</a></div>
+ <div class="lhs"><span class="nt">Statement</span> <span class="geq">:</span> </div>
+ <div class="rhs"><span class="nt">Block</span></div>
+ <div class="rhs"><span class="nt">VariableStatement</span></div>
+ <div class="rhs"><span class="nt">EmptyStatement</span></div>
+ <div class="rhs"><span class="nt">ExpressionStatement</span></div>
+ <div class="rhs"><span class="nt">IfStatement</span></div>
+ <div class="rhs"><span class="nt">IterationStatement</span></div>
+ <div class="rhs"><span class="nt">ContinueStatement</span></div>
+ <div class="rhs"><span class="nt">BreakStatement</span></div>
+ <div class="rhs"><span class="nt">ReturnStatement</span></div>
+ <div class="rhs"><span class="nt">WithStatement</span></div>
+ <div class="rhs"><span class="nt">LabelledStatement</span></div>
+ <div class="rhs"><span class="nt">SwitchStatement</span></div>
+ <div class="rhs"><span class="nt">ThrowStatement</span></div>
+ <div class="rhs"><span class="nt">TryStatement</span></div>
+ <div class="rhs"><span class="nt">DebuggerStatement</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-identifiers">See 12.1</a></div>
+ <div class="lhs"><span class="nt">Block</span> <span class="geq">:</span> </div>
+ <div class="rhs"><code class="t">{</code> <span class="nt">StatementList</span><sub>opt</sub> <code class="t">}</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-identifiers">See 12.1</a></div>
+ <div class="lhs"><span class="nt">StatementList</span> <span class="geq">:</span> </div>
+ <div class="rhs"><span class="nt">Statement</span></div>
+ <div class="rhs"><span class="nt">StatementList</span> <span class="nt">Statement</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-primary-expression">See 12.2</a></div>
+ <div class="lhs"><span class="nt">VariableStatement</span> <span class="geq">:</span> </div>
+ <div class="rhs"><code class="t">var</code> <span class="nt">VariableDeclarationList</span> <code class="t">;</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-primary-expression">See 12.2</a></div>
+ <div class="lhs"><span class="nt">VariableDeclarationList</span> <span class="geq">:</span> </div>
+ <div class="rhs"><span class="nt">VariableDeclaration</span></div>
+ <div class="rhs"><span class="nt">VariableDeclarationList</span> <code class="t">,</code> <span class="nt">VariableDeclaration</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-primary-expression">See 12.2</a></div>
+ <div class="lhs"><span class="nt">VariableDeclaration</span> <span class="geq">:</span> </div>
+ <div class="rhs"><span class="nt">Identifier</span> <span class="nt">Initialiser</span><sub>opt</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-primary-expression">See 12.2</a></div>
+ <div class="lhs"><span class="nt">Initialiser</span> <span class="geq">:</span> </div>
+ <div class="rhs"><code class="t">=</code> <span class="nt">AssignmentExpression</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-left-hand-side-expressions">See 12.3</a></div>
+ <div class="lhs"><span class="nt">EmptyStatement</span> <span class="geq">:</span> </div>
+ <div class="rhs"><code class="t">;</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-postfix-expressions">See 12.4</a></div>
+ <div class="lhs"><span class="nt">ExpressionStatement</span> <span class="geq">:</span> </div>
+ <div class="rhs"><span class="grhsannot">[lookahead ∉ {<code class="t">{</code>, <code class="t">function</code>}]</span> <span class="nt">Expression</span> <code class="t">;</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-unary-operators">See 12.5</a></div>
+ <div class="lhs"><span class="nt">IfStatement</span> <span class="geq">:</span> </div>
+ <div class="rhs"><code class="t">if</code> <code class="t">(</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">Statement</span> <code class="t">else</code> <span class="nt">Statement</span></div>
+ <div class="rhs"><code class="t">if</code> <code class="t">(</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-multiplicative-operators">See 12.6</a></div>
+ <div class="lhs"><span class="nt">IterationStatement</span> <span class="geq">:</span> </div>
+ <div class="rhs"><code class="t">do</code> <span class="nt">Statement</span> <code class="t">while</code> <code class="t">(</code> <span class="nt">Expression</span> <code class="t">)</code> <code class="t">;</code></div>
+ <div class="rhs"><code class="t">while</code> <code class="t">(</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <div class="rhs"><code class="t">for</code> <code class="t">(</code> <span class="nt">Expression</span><sub>opt</sub> <code class="t">;</code> <span class="nt">Expression</span><sub>opt</sub> <code class="t">;</code> <span class="nt">Expression</span><sub>opt</sub> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <div class="rhs"><code class="t">for</code> <code class="t">(</code> <code class="t">var</code> <span class="nt">VariableDeclarationList</span> <code class="t">;</code> <span class="nt">Expression</span><sub>opt</sub> <code class="t">;</code> <span class="nt">Expression</span><sub>opt</sub> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <div class="rhs"><code class="t">for</code> <code class="t">(</code> <span class="nt">LeftHandSideExpression</span> <code class="t">in</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ <div class="rhs"><code class="t">for</code> <code class="t">(</code> <code class="t">var</code> <span class="nt">VariableDeclaration</span> <code class="t">in</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-additive-operators">See 12.7</a></div>
+ <div class="lhs"><span class="nt">ContinueStatement</span> <span class="geq">:</span> </div>
+ <div class="rhs"><code class="t">continue</code> <code class="t">;</code></div>
+ <div class="rhs"><code class="t">continue</code> <span class="grhsannot">[no <span class="nt">LineTerminator</span> here]</span> <span class="nt">Identifier</span> <code class="t">;</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-bitwise-shift-operators">See 12.8</a></div>
+ <div class="lhs"><span class="nt">BreakStatement</span> <span class="geq">:</span> </div>
+ <div class="rhs"><code class="t">break</code> <code class="t">;</code></div>
+ <div class="rhs"><code class="t">break</code> <span class="grhsannot">[no <span class="nt">LineTerminator</span> here]</span> <span class="nt">Identifier</span> <code class="t">;</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-relational-operators">See 12.9</a></div>
+ <div class="lhs"><span class="nt">ReturnStatement</span> <span class="geq">:</span> </div>
+ <div class="rhs"><code class="t">return</code> <code class="t">;</code></div>
+ <div class="rhs"><code class="t">return</code> <span class="grhsannot">[no <span class="nt">LineTerminator</span> here]</span> <span class="nt">Expression</span> <code class="t">;</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-equality-operators">See 12.10</a></div>
+ <div class="lhs"><span class="nt">WithStatement</span> <span class="geq">:</span> </div>
+ <div class="rhs"><code class="t">with</code> <code class="t">(</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">Statement</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-binary-bitwise-operators">See 12.11</a></div>
+ <div class="lhs"><span class="nt">SwitchStatement</span> <span class="geq">:</span> </div>
+ <div class="rhs"><code class="t">switch</code> <code class="t">(</code> <span class="nt">Expression</span> <code class="t">)</code> <span class="nt">CaseBlock</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-binary-bitwise-operators">See 12.11</a></div>
+ <div class="lhs"><span class="nt">CaseBlock</span> <span class="geq">:</span> </div>
+ <div class="rhs"><code class="t">{</code> <span class="nt">CaseClauses</span><sub>opt</sub> <code class="t">}</code></div>
+ <div class="rhs"><code class="t">{</code> <span class="nt">CaseClauses</span><sub>opt</sub> <span class="nt">DefaultClause</span> <span class="nt">CaseClauses</span><sub>opt</sub> <code class="t">}</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-binary-bitwise-operators">See 12.11</a></div>
+ <div class="lhs"><span class="nt">CaseClauses</span> <span class="geq">:</span> </div>
+ <div class="rhs"><span class="nt">CaseClause</span></div>
+ <div class="rhs"><span class="nt">CaseClauses</span> <span class="nt">CaseClause</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-binary-bitwise-operators">See 12.11</a></div>
+ <div class="lhs"><span class="nt">CaseClause</span> <span class="geq">:</span> </div>
+ <div class="rhs"><code class="t">case</code> <span class="nt">Expression</span> <code class="t">:</code> <span class="nt">StatementList</span><sub>opt</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-binary-bitwise-operators">See 12.11</a></div>
+ <div class="lhs"><span class="nt">DefaultClause</span> <span class="geq">:</span> </div>
+ <div class="rhs"><code class="t">default</code> <code class="t">:</code> <span class="nt">StatementList</span><sub>opt</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-binary-logical-operators">See 12.12</a></div>
+ <div class="lhs"><span class="nt">LabelledStatement</span> <span class="geq">:</span> </div>
+ <div class="rhs"><span class="nt">Identifier</span> <code class="t">:</code> <span class="nt">Statement</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-conditional-operator">See 12.13</a></div>
+ <div class="lhs"><span class="nt">ThrowStatement</span> <span class="geq">:</span> </div>
+ <div class="rhs"><code class="t">throw</code> <span class="grhsannot">[no <span class="nt">LineTerminator</span> here]</span> <span class="nt">Expression</span> <code class="t">;</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-assignment-operators">See 12.14</a></div>
+ <div class="lhs"><span class="nt">TryStatement</span> <span class="geq">:</span> </div>
+ <div class="rhs"><code class="t">try</code> <span class="nt">Block</span> <span class="nt">Catch</span></div>
+ <div class="rhs"><code class="t">try</code> <span class="nt">Block</span> <span class="nt">Finally</span></div>
+ <div class="rhs"><code class="t">try</code> <span class="nt">Block</span> <span class="nt">Catch</span> <span class="nt">Finally</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-assignment-operators">See 12.14</a></div>
+ <div class="lhs"><span class="nt">Catch</span> <span class="geq">:</span> </div>
+ <div class="rhs"><code class="t">catch</code> <code class="t">(</code> <span class="nt">Identifier</span> <code class="t">)</code> <span class="nt">Block</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-assignment-operators">See 12.14</a></div>
+ <div class="lhs"><span class="nt">Finally</span> <span class="geq">:</span> </div>
+ <div class="rhs"><code class="t">finally</code> <span class="nt">Block</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-comma-operator">See 12.15</a></div>
+ <div class="lhs"><span class="nt">DebuggerStatement</span> <span class="geq">:</span> </div>
+ <div class="rhs"><code class="t">debugger</code> <code class="t">;</code></div>
+ </div>
+ </section>
+
+ <section>
+ <h1>Functions and Scripts</h1>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-ecmascript-language-statements-and-declarations">See clause 13</a></div>
+ <div class="lhs"><span class="nt">FunctionDeclaration</span> <span class="geq">:</span> </div>
+ <div class="rhs"><code class="t">function</code> <span class="nt">Identifier</span> <code class="t">(</code> <span class="nt">FormalParameterList</span><sub>opt</sub> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-ecmascript-language-statements-and-declarations">See clause 13</a></div>
+ <div class="lhs"><span class="nt">FunctionExpression</span> <span class="geq">:</span> </div>
+ <div class="rhs"><code class="t">function</code> <span class="nt">Identifier</span><sub>opt</sub> <code class="t">(</code> <span class="nt">FormalParameterList</span><sub>opt</sub> <code class="t">)</code> <code class="t">{</code> <span class="nt">FunctionBody</span> <code class="t">}</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-ecmascript-language-statements-and-declarations">See clause 13</a></div>
+ <div class="lhs"><span class="nt">FormalParameterList</span> <span class="geq">:</span> </div>
+ <div class="rhs"><span class="nt">Identifier</span></div>
+ <div class="rhs"><span class="nt">FormalParameterList</span> <code class="t">,</code> <span class="nt">Identifier</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-ecmascript-language-statements-and-declarations">See clause 13</a></div>
+ <div class="lhs"><span class="nt">FunctionBody</span> <span class="geq">:</span> </div>
+ <div class="rhs"><span class="nt">SourceElements</span><sub>opt</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-ecmascript-language-functions-and-classes">See clause 14</a></div>
+ <div class="lhs"><span class="nt">Program</span> <span class="geq">:</span> </div>
+ <div class="rhs"><span class="nt">SourceElements</span><sub>opt</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-ecmascript-language-functions-and-classes">See clause 14</a></div>
+ <div class="lhs"><span class="nt">SourceElements</span> <span class="geq">:</span> </div>
+ <div class="rhs"><span class="nt">SourceElement</span></div>
+ <div class="rhs"><span class="nt">SourceElements</span> <span class="nt">SourceElement</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-ecmascript-language-functions-and-classes">See clause 14</a></div>
+ <div class="lhs"><span class="nt">SourceElement</span> <span class="geq">:</span> </div>
+ <div class="rhs"><span class="nt">Statement</span></div>
+ <div class="rhs"><span class="nt">FunctionDeclaration</span></div>
+ </div>
+ </section>
+
+ <section>
+ <h1>Number Conversions</h1>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-tonumber-applied-to-the-string-type">See 7.1.3.1</a></div>
+ <div class="lhs"><span class="nt">StringNumericLiteral</span> <span class="geq">:::</span> </div>
+ <div class="rhs"><span class="nt">StrWhiteSpace</span><sub>opt</sub></div>
+ <div class="rhs"><span class="nt">StrWhiteSpace</span><sub>opt</sub> <span class="nt">StrNumericLiteral</span> <span class="nt">StrWhiteSpace</span><sub>opt</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-tonumber-applied-to-the-string-type">See 7.1.3.1</a></div>
+ <div class="lhs"><span class="nt">StrWhiteSpace</span> <span class="geq">:::</span> </div>
+ <div class="rhs"><span class="nt">StrWhiteSpaceChar</span> <span class="nt">StrWhiteSpace</span><sub>opt</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-tonumber-applied-to-the-string-type">See 7.1.3.1</a></div>
+ <div class="lhs"><span class="nt">StrWhiteSpaceChar</span> <span class="geq">:::</span> </div>
+ <div class="rhs"><span class="nt">WhiteSpace</span></div>
+ <div class="rhs"><span class="nt">LineTerminator</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-tonumber-applied-to-the-string-type">See 7.1.3.1</a></div>
+ <div class="lhs"><span class="nt">StrNumericLiteral</span> <span class="geq">:::</span> </div>
+ <div class="rhs"><span class="nt">StrDecimalLiteral</span></div>
+ <div class="rhs"><span class="nt">HexIntegerLiteral</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-tonumber-applied-to-the-string-type">See 7.1.3.1</a></div>
+ <div class="lhs"><span class="nt">StrDecimalLiteral</span> <span class="geq">:::</span> </div>
+ <div class="rhs"><span class="nt">StrUnsignedDecimalLiteral</span></div>
+ <div class="rhs"><code class="t">+</code> <span class="nt">StrUnsignedDecimalLiteral</span></div>
+ <div class="rhs"><code class="t">-</code> <span class="nt">StrUnsignedDecimalLiteral</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-tonumber-applied-to-the-string-type">See 7.1.3.1</a></div>
+ <div class="lhs"><span class="nt">StrUnsignedDecimalLiteral</span> <span class="geq">:::</span> </div>
+ <div class="rhs"><span class="nt">Infinity</span></div>
+ <div class="rhs"><span class="nt">DecimalDigits</span> <code class="t">.</code> <span class="nt">DecimalDigits</span><sub>opt</sub> <span class="nt">ExponentPart</span><sub>opt</sub></div>
+ <div class="rhs"><code class="t">.</code> <span class="nt">DecimalDigits</span> <span class="nt">ExponentPart</span><sub>opt</sub></div>
+ <div class="rhs"><span class="nt">DecimalDigits</span> <span class="nt">ExponentPart</span><sub>opt</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-tonumber-applied-to-the-string-type">See 7.1.3.1</a></div>
+ <div class="lhs"><span class="nt">DecimalDigits</span> <span class="geq">:::</span> </div>
+ <div class="rhs"><span class="nt">DecimalDigit</span></div>
+ <div class="rhs"><span class="nt">DecimalDigits</span> <span class="nt">DecimalDigit</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-tonumber-applied-to-the-string-type">See 7.1.3.1</a></div>
+ <div class="lhs"><span class="nt">DecimalDigit</span> <span class="geq">:::</span> <span class="grhsmod">one of</span> </div>
+ <div class="rhs"><code class="t">0</code> <code class="t">1</code> <code class="t">2</code> <code class="t">3</code> <code class="t">4</code> <code class="t">5</code> <code class="t">6</code> <code class="t">7</code> <code class="t">8</code> <code class="t">9</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-tonumber-applied-to-the-string-type">See 7.1.3.1</a></div>
+ <div class="lhs"><span class="nt">ExponentPart</span> <span class="geq">:::</span> </div>
+ <div class="rhs"><span class="nt">ExponentIndicator</span> <span class="nt">SignedInteger</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-tonumber-applied-to-the-string-type">See 7.1.3.1</a></div>
+ <div class="lhs"><span class="nt">ExponentIndicator</span> <span class="geq">:::</span> <span class="grhsmod">one of</span> </div>
+ <div class="rhs"><code class="t">e</code> <code class="t">E</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-tonumber-applied-to-the-string-type">See 7.1.3.1</a></div>
+ <div class="lhs"><span class="nt">SignedInteger</span> <span class="geq">:::</span> </div>
+ <div class="rhs"><span class="nt">DecimalDigits</span></div>
+ <div class="rhs"><code class="t">+</code> <span class="nt">DecimalDigits</span></div>
+ <div class="rhs"><code class="t">-</code> <span class="nt">DecimalDigits</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-tonumber-applied-to-the-string-type">See 7.1.3.1</a></div>
+ <div class="lhs"><span class="nt">HexIntegerLiteral</span> <span class="geq">:::</span> </div>
+ <div class="rhs"><code class="t">0x</code> <span class="nt">HexDigit</span></div>
+ <div class="rhs"><code class="t">0X</code> <span class="nt">HexDigit</span></div>
+ <div class="rhs"><span class="nt">HexIntegerLiteral</span> <span class="nt">HexDigit</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-tonumber-applied-to-the-string-type">See 7.1.3.1</a></div>
+ <div class="lhs"><span class="nt">HexDigit</span> <span class="geq">:::</span> <span class="grhsmod">one of</span> </div>
+ <div class="rhs"><code class="t">0</code> <code class="t">1</code> <code class="t">2</code> <code class="t">3</code> <code class="t">4</code> <code class="t">5</code> <code class="t">6</code> <code class="t">7</code> <code class="t">8</code> <code class="t">9</code> <code class="t">a</code> <code class="t">b</code> <code class="t">c</code> <code class="t">d</code> <code class="t">e</code> <code class="t">f</code> <code class="t">A</code> <code class="t">B</code> <code class="t">C</code> <code class="t">D</code> <code class="t">E</code> <code class="t">F</code></div>
+ </div>
+ </section>
+
+ <section>
+ <h1>Universal Resource Identifier Character Classes</h1>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-scripts-static-semantics-lexicallydeclarednames">See 15.1.3</a></div>
+ <div class="lhs"><span class="nt">uri</span> <span class="geq">:::</span> </div>
+ <div class="rhs"><span class="nt">uriCharacters</span><sub>opt</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-scripts-static-semantics-lexicallydeclarednames">See 15.1.3</a></div>
+ <div class="lhs"><span class="nt">uriCharacters</span> <span class="geq">:::</span> </div>
+ <div class="rhs"><span class="nt">uriCharacter</span> <span class="nt">uriCharacters</span><sub>opt</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-scripts-static-semantics-lexicallydeclarednames">See 15.1.3</a></div>
+ <div class="lhs"><span class="nt">uriCharacter</span> <span class="geq">:::</span> </div>
+ <div class="rhs"><span class="nt">uriReserved</span></div>
+ <div class="rhs"><span class="nt">uriUnescaped</span></div>
+ <div class="rhs"><span class="nt">uriEscaped</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-scripts-static-semantics-lexicallydeclarednames">See 15.1.3</a></div>
+ <div class="lhs"><span class="nt">uriReserved</span> <span class="geq">:::</span> <span class="grhsmod">one of</span> </div>
+ <div class="rhs"><code class="t">;</code> <code class="t">/</code> <code class="t">?</code> <code class="t">:</code> <code class="t">@</code> <code class="t">&</code> <code class="t">=</code> <code class="t">+</code> <code class="t">$</code> <code class="t">,</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-scripts-static-semantics-lexicallydeclarednames">See 15.1.3</a></div>
+ <div class="lhs"><span class="nt">uriUnescaped</span> <span class="geq">:::</span> </div>
+ <div class="rhs"><span class="nt">uriAlpha</span></div>
+ <div class="rhs"><span class="nt">DecimalDigit</span></div>
+ <div class="rhs"><span class="nt">uriMark</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-scripts-static-semantics-lexicallydeclarednames">See 15.1.3</a></div>
+ <div class="lhs"><span class="nt">uriEscaped</span> <span class="geq">:::</span> </div>
+ <div class="rhs"><code class="t">%</code> <span class="nt">HexDigit</span> <span class="nt">HexDigit</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-scripts-static-semantics-lexicallydeclarednames">See 15.1.3</a></div>
+ <div class="lhs"><span class="nt">uriAlpha</span> <span class="geq">:::</span> <span class="grhsmod">one of</span> </div>
+ <div class="rhs"><code class="t">a</code> <code class="t">b</code> <code class="t">c</code> <code class="t">d</code> <code class="t">e</code> <code class="t">f</code> <code class="t">g</code> <code class="t">h</code> <code class="t">i</code> <code class="t">j</code> <code class="t">k</code> <code class="t">l</code> <code class="t">m</code> <code class="t">n</code> <code class="t">o</code> <code class="t">p</code> <code class="t">q</code> <code class="t">r</code> <code class="t">s</code> <code class="t">t</code> <code class="t">u</code> <code class="t">v</code> <code class="t">w</code> <code class="t">x</code> <code class="t">y</code> <code class="t">z</code></div>
+ <div class="rhs"><code class="t">A</code> <code class="t">B</code> <code class="t">C</code> <code class="t">D</code> <code class="t">E</code> <code class="t">F</code> <code class="t">G</code> <code class="t">H</code> <code class="t">I</code> <code class="t">J</code> <code class="t">K</code> <code class="t">L</code> <code class="t">M</code> <code class="t">N</code> <code class="t">O</code> <code class="t">P</code> <code class="t">Q</code> <code class="t">R</code> <code class="t">S</code> <code class="t">T</code> <code class="t">U</code> <code class="t">V</code> <code class="t">W</code> <code class="t">X</code> <code class="t">Y</code> <code class="t">Z</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref"><a href="#sec-scripts-static-semantics-lexicallydeclarednames">See 15.1.3</a></div>
+ <div class="lhs"><span class="nt">uriMark</span> <span class="geq">:::</span> <span class="grhsmod">one of</span> </div>
+ <div class="rhs"><code class="t">-</code> <code class="t">_</code> <code class="t">.</code> <code class="t">!</code> <code class="t">~</code> <code class="t">*</code> <code class="t">'</code> <code class="t">(</code> <code class="t">)</code></div>
+ </div>
+ </section>
+
+ <section>
+ <h1>Regular Expressions</h1>
+
+ <div class="gp">
+ <div class="gsumxref">See 15.10.1</div>
+ <div class="lhs"><span class="nt">Pattern</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">Disjunction</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref">See 15.10.1</div>
+ <div class="lhs"><span class="nt">Disjunction</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">Alternative</span></div>
+ <div class="rhs"><span class="nt">Alternative</span> <code class="t">|</code> <span class="nt">Disjunction</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref">See 15.10.1</div>
+ <div class="lhs"><span class="nt">Alternative</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="grhsannot">[empty]</span></div>
+ <div class="rhs"><span class="nt">Alternative</span> <span class="nt">Term</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref">See 15.10.1</div>
+ <div class="lhs"><span class="nt">Term</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">Assertion</span></div>
+ <div class="rhs"><span class="nt">Atom</span></div>
+ <div class="rhs"><span class="nt">Atom</span> <span class="nt">Quantifier</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref">See 15.10.1</div>
+ <div class="lhs"><span class="nt">Assertion</span> <span class="geq">::</span> </div>
+ <div class="rhs"><code class="t">^</code></div>
+ <div class="rhs"><code class="t">$</code></div>
+ <div class="rhs"><code class="t">\</code> <code class="t">b</code></div>
+ <div class="rhs"><code class="t">\</code> <code class="t">B</code></div>
+ <div class="rhs"><code class="t">(</code> <code class="t">?</code> <code class="t">=</code> <span class="nt">Disjunction</span> <code class="t">)</code></div>
+ <div class="rhs"><code class="t">(</code> <code class="t">?</code> <code class="t">!</code> <span class="nt">Disjunction</span> <code class="t">)</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref">See 15.10.1</div>
+ <div class="lhs"><span class="nt">Quantifier</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">QuantifierPrefix</span></div>
+ <div class="rhs"><span class="nt">QuantifierPrefix</span> <code class="t">?</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref">See 15.10.1</div>
+ <div class="lhs"><span class="nt">QuantifierPrefix</span> <span class="geq">::</span> </div>
+ <div class="rhs"><code class="t">*</code></div>
+ <div class="rhs"><code class="t">+</code></div>
+ <div class="rhs"><code class="t">?</code></div>
+ <div class="rhs"><code class="t">{</code> <span class="nt">DecimalDigits</span> <code class="t">}</code></div>
+ <div class="rhs"><code class="t">{</code> <span class="nt">DecimalDigits</span> <code class="t">,</code> <code class="t">}</code></div>
+ <div class="rhs"><code class="t">{</code> <span class="nt">DecimalDigits</span> <code class="t">,</code> <span class="nt">DecimalDigits</span> <code class="t">}</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref">See 15.10.1</div>
+ <div class="lhs"><span class="nt">Atom</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">PatternCharacter</span></div>
+ <div class="rhs"><code class="t">.</code></div>
+ <div class="rhs"><code class="t">\</code> <span class="nt">AtomEscape</span></div>
+ <div class="rhs"><span class="nt">CharacterClass</span></div>
+ <div class="rhs"><code class="t">(</code> <span class="nt">Disjunction</span> <code class="t">)</code></div>
+ <div class="rhs"><code class="t">(</code> <code class="t">?</code> <code class="t">:</code> <span class="nt">Disjunction</span> <code class="t">)</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref">See 15.10.1</div>
+ <div class="lhs"><span class="nt">PatternCharacter</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">SourceCharacter</span> <span class="grhsmod">but not one of</span> <code class="t">-</code></div>
+ <div class="rhs"><code class="t">^</code> <code class="t">$</code> <code class="t">\</code> <code class="t">.</code> <code class="t">*</code> <code class="t">+</code> <code class="t">?</code> <code class="t">(</code> <code class="t">)</code> <code class="t">[</code> <code class="t">]</code> <code class="t">{</code> <code class="t">}</code> <code class="t">|</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref">See 15.10.1</div>
+ <div class="lhs"><span class="nt">AtomEscape</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">DecimalEscape</span></div>
+ <div class="rhs"><span class="nt">CharacterEscape</span></div>
+ <div class="rhs"><span class="nt">CharacterClassEscape</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref">See 15.10.1</div>
+ <div class="lhs"><span class="nt">CharacterEscape</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">ControlEscape</span></div>
+ <div class="rhs"><code class="t">c</code> <span class="nt">ControlLetter</span></div>
+ <div class="rhs"><span class="nt">HexEscapeSequence</span></div>
+ <div class="rhs"><span class="nt">UnicodeEscapeSequence</span></div>
+ <div class="rhs"><span class="nt">IdentityEscape</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref">See 15.10.1</div>
+ <div class="lhs"><span class="nt">ControlEscape</span> <span class="geq">::</span> <span class="grhsmod">one of</span> </div>
+ <div class="rhs"><code class="t">f</code> <code class="t">n</code> <code class="t">r</code> <code class="t">t</code> <code class="t">v</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref">See 15.10.1</div>
+ <div class="lhs"><span class="nt">ControlLetter</span> <span class="geq">::</span> <span class="grhsmod">one of</span> </div>
+ <div class="rhs"><code class="t">a</code> <code class="t">b</code> <code class="t">c</code> <code class="t">d</code> <code class="t">e</code> <code class="t">f</code> <code class="t">g</code> <code class="t">h</code> <code class="t">i</code> <code class="t">j</code> <code class="t">k</code> <code class="t">l</code> <code class="t">m</code> <code class="t">n</code> <code class="t">o</code> <code class="t">p</code> <code class="t">q</code> <code class="t">r</code> <code class="t">s</code> <code class="t">t</code> <code class="t">u</code> <code class="t">v</code> <code class="t">w</code> <code class="t">x</code> <code class="t">y</code> <code class="t">z</code></div>
+ <div class="rhs"><code class="t">A</code> <code class="t">B</code> <code class="t">C</code> <code class="t">D</code> <code class="t">E</code> <code class="t">F</code> <code class="t">G</code> <code class="t">H</code> <code class="t">I</code> <code class="t">J</code> <code class="t">K</code> <code class="t">L</code> <code class="t">M</code> <code class="t">N</code> <code class="t">O</code> <code class="t">P</code> <code class="t">Q</code> <code class="t">R</code> <code class="t">S</code> <code class="t">T</code> <code class="t">U</code> <code class="t">V</code> <code class="t">W</code> <code class="t">X</code> <code class="t">Y</code> <code class="t">Z</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref">See 15.10.1</div>
+ <div class="lhs"><span class="nt">IdentityEscape</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">SourceCharacter</span> <span class="grhsmod">but not</span> <span class="nt">IdentifierPart</span></div>
+ <div class="rhs"><ZWJ></div>
+ <div class="rhs"><ZWNJ></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref">See 15.10.1</div>
+ <div class="lhs"><span class="nt">DecimalEscape</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">DecimalIntegerLiteral</span> <span class="grhsannot">[lookahead ∉ <span class="nt">DecimalDigit</span>]</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref">See 15.10.1</div>
+ <div class="lhs"><span class="nt">CharacterClassEscape</span> <span class="geq">::</span> <span class="grhsmod">one of</span> </div>
+ <div class="rhs"><code class="t">d</code> <code class="t">D</code> <code class="t">s</code> <code class="t">S</code> <code class="t">w</code> <code class="t">W</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref">See 15.10.1</div>
+ <div class="lhs"><span class="nt">CharacterClass</span> <span class="geq">::</span> </div>
+ <div class="rhs"><code class="t">[</code> <span class="grhsannot">[lookahead ∉ {<code class="t">^</code>}]</span> <span class="nt">ClassRanges</span> <code class="t">]</code></div>
+ <div class="rhs"><code class="t">[</code> <code class="t">^</code> <span class="nt">ClassRanges</span> <code class="t">]</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref">See 15.10.1</div>
+ <div class="lhs"><span class="nt">ClassRanges</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="grhsannot">[empty]</span></div>
+ <div class="rhs"><span class="nt">NonemptyClassRanges</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref">See 15.10.1</div>
+ <div class="lhs"><span class="nt">NonemptyClassRanges</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">ClassAtom</span></div>
+ <div class="rhs"><span class="nt">ClassAtom</span> <span class="nt">NonemptyClassRangesNoDash</span></div>
+ <div class="rhs"><span class="nt">ClassAtom</span> <code class="t">–</code> <span class="nt">ClassAtom</span> <span class="nt">ClassRanges</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref">See 15.10.1</div>
+ <div class="lhs"><span class="nt">NonemptyClassRangesNoDash</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">ClassAtom</span></div>
+ <div class="rhs"><span class="nt">ClassAtomNoDash</span> <span class="nt">NonemptyClassRangesNoDash</span></div>
+ <div class="rhs"><span class="nt">ClassAtomNoDash</span> <code class="t">–</code> <span class="nt">ClassAtom</span> <span class="nt">ClassRanges</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref">See 15.10.1</div>
+ <div class="lhs"><span class="nt">ClassAtom</span> <span class="geq">::</span> </div>
+ <div class="rhs"><code class="t">-</code></div>
+ <div class="rhs"><span class="nt">ClassAtomNoDash</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref">See 15.10.1</div>
+ <div class="lhs"><span class="nt">ClassAtomNoDash</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">SourceCharacter</span> <span class="grhsmod">but not one of</span> <code class="t">\</code> <span class="grhsmod">or</span> <code class="t">]</code> <span class="grhsmod">or</span> <code class="t">-</code></div>
+ <div class="rhs"><code class="t">\</code> <span class="nt">ClassEscape</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="gsumxref">See 15.10.1</div>
+ <div class="lhs"><span class="nt">ClassEscape</span> <span class="geq">::</span> </div>
+ <div class="rhs"><span class="nt">DecimalEscape</span></div>
+ <div class="rhs"><code class="t">b</code></div>
+ <div class="rhs"><span class="nt">CharacterEscape</span></div>
+ <div class="rhs"><span class="nt">CharacterClassEscape</span></div>
+ </div>
+ </section>
+ </section>
+</section>
+
+<section id="sec-additional-ecmascript-features-for-web-browsers">
+ <div class="front">
+ <h1><span class="secnum" id="sec-B"><a href="#sec-additional-ecmascript-features-for-web-browsers"
+ title="link to this section">Annex B</a></span> <span class="section-status">(normative)</span> Additional ECMAScript
+ Features for Web Browsers</h1>
+
+ <p>The ECMAScript language syntax and semantics defined in this annex are required when the ECMAScript host is a web browser.
+ The content of this annex is normative but optional if the ECMAScript host is not a web browser.</p>
+ </div>
+
+ <section id="sec-additional-syntax">
+ <div class="front">
+ <h1><span class="secnum" id="sec-B.1"><a href="#sec-additional-syntax" title="link to this section">B.1</a></span>
+ Additional Syntax</h1>
+ </div>
+
+ <section id="sec-additional-syntax-numeric-literals">
+ <h1><span class="secnum" id="sec-B.1.1"><a href="#sec-additional-syntax-numeric-literals"
+ title="link to this section">B.1.1</a></span> Numeric Literals</h1>
+
+ <p>The syntax and semantics of <a href="#sec-literals-numeric-literals">11.8.3</a> is extended as follows except that this
+ extension is not allowed for <a href="#sec-strict-mode-code">strict mode code</a>:</p>
+
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">NumericLiteral</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">DecimalLiteral</span></div>
+ <div class="rhs"><span class="nt">BinaryIntegerLiteral</span></div>
+ <div class="rhs"><span class="nt">OctalIntegerLiteral</span></div>
+ <div class="rhs"><span class="nt">HexIntegerLiteral</span></div>
+ <div class="rhs"><span class="nt">LegacyOctalIntegerLiteral</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">LegacyOctalIntegerLiteral</span> <span class="geq">::</span></div>
+ <div class="rhs"><code class="t">0</code> <span class="nt">OctalDigit</span></div>
+ <div class="rhs"><span class="nt">LegacyOctalIntegerLiteral</span> <span class="nt">OctalDigit</span></div>
+ </div>
+
+ <p><span class="marker">B.1.1.1	</span><b>Static Semantics</b></p>
+
+ <ul>
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">LegacyOctalIntegerLiteral</span> <span class="geq">::</span> <code
+ class="t">0</code> <span class="nt">OctalDigit</span></span> is the MV of <span class="nt">OctalDigit</span>.</p>
+ </li>
+
+ <li>
+ <p>The MV of <span class="prod"><span class="nt">LegacyOctalIntegerLiteral</span> <span class="geq">::</span> <span
+ class="nt">LegacyOctalIntegerLiteral</span> <span class="nt">OctalDigit</span></span> is (the MV of <span
+ class="nt">LegacyOctalIntegerLiteral</span> times 8) plus the MV of <span class="nt">OctalDigit</span>.</p>
+ </li>
+ </ul>
+ </section>
+
+ <section id="sec-additional-syntax-string-literals">
+ <h1><span class="secnum" id="sec-B.1.2"><a href="#sec-additional-syntax-string-literals"
+ title="link to this section">B.1.2</a></span> String Literals</h1>
+
+ <p>The syntax and semantics of <a href="#sec-literals-string-literals">11.8.4</a> is extended as follows except that this
+ extension is not allowed for <a href="#sec-strict-mode-code">strict mode code</a>:</p>
+
+ <h2>Syntax</h2>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">EscapeSequence</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">CharacterEscapeSequence</span></div>
+ <div class="rhs"><span class="nt">OctalEscapeSequence</span></div>
+ <div class="rhs"><span class="nt">HexEscapeSequence</span></div>
+ <div class="rhs"><span class="nt">UnicodeEscapeSequence</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">OctalEscapeSequence</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">OctalDigit</span> <span class="grhsannot">[lookahead ∉ <span class="nt">DecimalDigit</span>]</span></div>
+ <div class="rhs"><span class="nt">ZeroToThree</span> <span class="nt">OctalDigit</span> <span class="grhsannot">[lookahead ∉ <span class="nt">DecimalDigit</span>]</span></div>
+ <div class="rhs"><span class="nt">FourToSeven</span> <span class="nt">OctalDigit</span></div>
+ <div class="rhs"><span class="nt">ZeroToThree</span> <span class="nt">OctalDigit</span> <span class="nt">OctalDigit</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ZeroToThree</span> <span class="geq">::</span> <span class="grhsmod">one of</span></div>
+ <div class="rhs"><code class="t">0</code> <code class="t">1</code> <code class="t">2</code> <code class="t">3</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">FourToSeven</span> <span class="geq">::</span> <span class="grhsmod">one of</span></div>
+ <div class="rhs"><code class="t">4</code> <code class="t">5</code> <code class="t">6</code> <code class="t">7</code></div>
+ </div>
+
+ <p>This definition of <span class="nt">EscapeSequence</span> is not used when parsing <span
+ class="nt">TemplateCharacter</span> (<a href="#sec-template-literal-lexical-components">11.8.6</a>).</p>
+
+ <p><span class="marker">B.1.2.1	</span><b>Static Semantics</b></p>
+
+ <ul>
+ <li>The CV of <span class="prod"><span class="nt">EscapeSequence</span> <span class="geq">::</span> <span
+ class="nt">OctalEscapeSequence</span></span> is the CV of the <i>OctalEscapeSequence</i>.</li>
+ <li>The CV of <span class="prod"><span class="nt">OctalEscapeSequence</span> <span class="geq">::</span> <span
+ class="nt">OctalDigit</span></span> is the character whose code unit value is the MV of the <i>OctalDigit</i>.</li>
+ <li>The CV of <span class="prod"><span class="nt">OctalEscapeSequence</span> <span class="geq">::</span> <span
+ class="nt">ZeroToThree</span> <span class="nt">OctalDigit</span></span> is the character whose code unit value is (8
+ times the MV of the <i>ZeroToThree</i>) plus the MV of the <i>OctalDigit</i>.</li>
+ <li>The CV of <span class="prod"><span class="nt">OctalEscapeSequence</span> <span class="geq">::</span> <span
+ class="nt">FourToSeven</span> <span class="nt">OctalDigit</span></span> is the character whose code unit value is (8
+ times the MV of the <i>FourToSeven</i>) plus the MV of the <i>OctalDigit</i>.</li>
+ <li>The CV of <span class="prod"><span class="nt">OctalEscapeSequence</span> <span class="geq">::</span> <span
+ class="nt">ZeroToThree</span> <span class="nt">OctalDigit</span> <span class="nt">OctalDigit</span></span> is the
+ character whose code unit value is (64 (that is, 8<sup>2</sup>) times the MV of the <i>ZeroToThree</i>) plus (8 times
+ the MV of the first <i>OctalDigit</i>) plus the MV of the second <i>OctalDigit</i>.</li>
+ <li>The MV of <span class="prod"><span class="nt">ZeroToThree</span> <span class="geq">::</span> <code
+ class="t">0</code></span> is 0.</li>
+ <li>The MV of <span class="prod"><span class="nt">ZeroToThree</span> <span class="geq">::</span> <code
+ class="t">1</code></span> is 1.</li>
+ <li>The MV of <span class="prod"><span class="nt">ZeroToThree</span> <span class="geq">::</span> <code
+ class="t">2</code></span> is 2.</li>
+ <li>The MV of <span class="prod"><span class="nt">ZeroToThree</span> <span class="geq">::</span> <code
+ class="t">3</code></span> is 3.</li>
+ <li>The MV of <span class="prod"><span class="nt">FourToSeven</span> <span class="geq">::</span> <code
+ class="t">4</code></span> is 4.</li>
+ <li>The MV of <span class="prod"><span class="nt">FourToSeven</span> <span class="geq">::</span> <code
+ class="t">5</code></span> is 5.</li>
+ <li>The MV of <span class="prod"><span class="nt">FourToSeven</span> <span class="geq">::</span> <code
+ class="t">6</code></span> is 6.</li>
+ <li>The MV of <span class="prod"><span class="nt">FourToSeven</span> <span class="geq">::</span> <code
+ class="t">7</code></span> is 7.</li>
+ </ul>
+ </section>
+
+ <section id="sec-html-like-comments">
+ <h1><span class="secnum" id="sec-B.1.3"><a href="#sec-html-like-comments" title="link to this section">B.1.3</a></span>
+ HTML-like Comments</h1>
+
+ <p style="background-color: #F79646">TODO See <a
+ href="http://javascript.spec.whatwg.org/">http://javascript.spec.whatwg.org/</a>#comment-syntax</p>
+ </section>
+
+ <section id="sec-regular-expressions-patterns">
+ <h1><span class="secnum" id="sec-B.1.4"><a href="#sec-regular-expressions-patterns"
+ title="link to this section">B.1.4</a></span> Regular Expressions Patterns</h1>
+
+ <p>The syntax of <a href="#sec-patterns">21.2.1</a> is extended as modified and extended as follows. These changes introduce
+ ambiguities that are broken by the ordering or grammar productions and by contextual information. The following grammar is
+ used, with each alternative considered only if previous production alternatives do not match.</p>
+
+ <p><b>Syntax</b></p>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">Term</span><sub>[U]</sub> <span class="geq">::</span></div>
+ <div class="rhs"><span class="grhsannot">[~U]</span> <span class="nt">ExtendedTerm</span></div>
+ <div class="rhs"><span class="grhsannot">[+U]</span> <span class="nt">Assertion</span><sub>[U]</sub></div>
+ <div class="rhs"><span class="grhsannot">[+U]</span> <span class="nt">Atom</span><sub>[U]</sub></div>
+ <div class="rhs"><span class="grhsannot">[+U]</span> <span class="nt">Atom</span><sub>[U]</sub> <span class="nt">Quantifier</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ExtendedTerm</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">Assertion</span></div>
+ <div class="rhs"><span class="nt">AtomNoBrace</span> <span class="nt">Quantifier</span></div>
+ <div class="rhs"><span class="nt">Atom</span></div>
+ <div class="rhs"><span class="nt">QuantifiableAssertion</span> <span class="nt">Quantifier</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">AtomNoBrace</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">PatternCharacterNoBrace</span></div>
+ <div class="rhs"><code class="t">.</code></div>
+ <div class="rhs"><code class="t">\</code> <span class="nt">AtomEscape</span></div>
+ <div class="rhs"><span class="nt">CharacterClass</span></div>
+ <div class="rhs"><code class="t">(</code> <span class="nt">Disjunction</span> <code class="t">)</code></div>
+ <div class="rhs"><code class="t">(</code> <code class="t">?</code> <code class="t">:</code> <span class="nt">Disjunction</span> <code class="t">)</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">Atom</span><sub>[U]</sub> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">PatternCharacter</span></div>
+ <div class="rhs"><code class="t">.</code></div>
+ <div class="rhs"><code class="t">\</code> <span class="nt">AtomEscape</span><sub>[?U]</sub></div>
+ <div class="rhs"><span class="nt">CharacterClass</span><sub>[?U]</sub></div>
+ <div class="rhs"><code class="t">(</code> <span class="nt">Disjunction</span><sub>[?U]</sub> <code class="t">)</code></div>
+ <div class="rhs"><code class="t">(</code> <code class="t">?</code> <code class="t">:</code> <span class="nt">Disjunction</span><sub>[?U]</sub> <code class="t">)</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">PatternCharacterNoBrace</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">SourceCharacter</span> <span class="grhsmod">but not one of</span></div>
+ <div class="rhs"><code class="t">^</code> <code class="t">$</code> <code class="t">\</code> <code class="t">.</code> <code class="t">*</code> <code class="t">+</code> <code class="t">?</code> <code class="t">(</code> <code class="t">)</code> <code class="t">[</code> <code class="t">]</code> <code class="t">{</code> <code class="t">}</code> <code class="t">|</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">PatternCharacter</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">SourceCharacter</span> <span class="grhsmod">but not one of</span></div>
+ <div class="rhs"><code class="t">^</code> <code class="t">$</code> <code class="t">\</code> <code class="t">.</code> <code class="t">*</code> <code class="t">+</code> <code class="t">?</code> <code class="t">(</code> <code class="t">)</code> <code class="t">[</code> <code class="t">]</code> <code class="t">|</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">QuantifiableAssertion</span> <span class="geq">::</span></div>
+ <div class="rhs"><code class="t">(</code> <code class="t">?</code> <code class="t">=</code> <span class="nt">Disjunction</span> <code class="t">)</code></div>
+ <div class="rhs"><code class="t">(</code> <code class="t">?</code> <code class="t">!</code> <span class="nt">Disjunction</span> <code class="t">)</code></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">Assertion</span><sub>[U]</sub> <span class="geq">::</span></div>
+ <div class="rhs"><code class="t">^</code></div>
+ <div class="rhs"><code class="t">$</code></div>
+ <div class="rhs"><code class="t">\</code> <code class="t">b</code></div>
+ <div class="rhs"><code class="t">\</code> <code class="t">B</code></div>
+ <div class="rhs"><span class="grhsannot">[+U]</span> <code class="t">(</code> <code class="t">?</code> <code class="t">=</code> <span class="nt">Disjunction</span><sub>[?U]</sub> <code class="t">)</code></div>
+ <div class="rhs"><span class="grhsannot">[+U]</span> <code class="t">(</code> <code class="t">?</code> <code class="t">!</code> <span class="nt">Disjunction</span><sub>[?U]</sub> <code class="t">)</code></div>
+ <div class="rhs"><span class="grhsannot">[~U]</span> <span class="nt">QuantifiableAssertion</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">AtomEscape</span><sub>[U]</sub> <span class="geq">::</span></div>
+ <div class="rhs"><span class="grhsannot">[+U]</span> <span class="nt">DecimalEscape</span></div>
+ <div class="rhs"><span class="grhsannot">[~U]</span> <span class="nt">DecimalEscape</span> <code class="t">but</code> <code class="t">only</code> <code class="t">if</code> <code class="t">the</code> <code class="t">integer</code> <code class="t">value</code> <code class="t">of</code> <span class="nt">DecimalEscape</span> <code class="t">is</code> <code class="t"><=</code> <span class="nt">NCapturingParens</span></div>
+ <div class="rhs"><span class="grhsannot">[+U]</span> <span class="nt">CharacterEscape</span><sub>[U]</sub></div>
+ <div class="rhs"><span class="grhsannot">[+U]</span> <span class="nt">CharacterClassEscape</span></div>
+ <div class="rhs"><span class="grhsannot">[~U]</span> <span class="nt">CharacterClassEscape</span></div>
+ <div class="rhs"><span class="grhsannot">[~U]</span> <span class="nt">CharacterEscape</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">CharacterEscape</span><sub>[U]</sub> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">ControlEscape</span></div>
+ <div class="rhs"><code class="t">c</code> <span class="nt">ControlLetter</span></div>
+ <div class="rhs"><span class="nt">HexEscapeSequence</span></div>
+ <div class="rhs"><span class="nt">RegExpUnicodeEscapeSequence</span><sub>[?U]</sub></div>
+ <div class="rhs"><span class="grhsannot">[~U]</span> <span class="nt">OctalEscapeSequence</span></div>
+ <div class="rhs"><span class="nt">IdentityEscape</span><sub>[?U]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">IdentityEscape</span><sub>[U]</sub> <span class="geq">::</span></div>
+ <div class="rhs"><span class="grhsannot">[+U]</span> <span class="nt">SyntaxCharacter</span></div>
+ <div class="rhs"><span class="grhsannot">[~U]</span> <span class="nt">SourceCharacter</span> <span class="grhsmod">but not</span> <code class="t">c</code></div>
+ <div class="rhs"><span class="grhsannot">[~U]</span> <ZWJ></div>
+ <div class="rhs"><span class="grhsannot">[~U]</span> <ZWNJ></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">NonemptyClassRanges</span><sub>[U]</sub> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">ClassAtom</span><sub>[?U]</sub></div>
+ <div class="rhs"><span class="nt">ClassAtom</span><sub>[?U]</sub> <span class="nt">NonemptyClassRangesNoDash</span><sub>[?U]</sub></div>
+ <div class="rhs"><span class="grhsannot">[+U]</span> <span class="nt">ClassAtom</span><sub>[U]</sub> <code class="t">-</code> <span class="nt">ClassAtom</span><sub>[U]</sub> <span class="nt">ClassRanges</span><sub>[U]</sub></div>
+ <div class="rhs"><span class="grhsannot">[~U]</span> <span class="nt">ClassAtomInRange</span> <code class="t">-</code> <span class="nt">ClassAtomInRange</span> <span class="nt">ClassRanges</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">NonemptyClassRangesNoDash</span><sub>[U]</sub> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">ClassAtom</span><sub>[?U]</sub></div>
+ <div class="rhs"><span class="nt">ClassAtomNoDash</span><sub>[?U]</sub> <span class="nt">NonemptyClassRangesNoDash</span><sub>[?U]</sub></div>
+ <div class="rhs"><span class="grhsannot">[+U]</span> <span class="nt">ClassAtomNoDash</span><sub>[U]</sub> <code class="t">-</code> <span class="nt">ClassAtom</span><sub>[U]</sub> <span class="nt">ClassRanges</span><sub>[U]</sub></div>
+ <div class="rhs"><span class="grhsannot">[~U]</span> <span class="nt">ClassAtomNoDashInRange</span> <code class="t">-</code> <span class="nt">ClassAtomInRange</span> <span class="nt">ClassRanges</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ClassAtom</span><sub>[U]</sub> <span class="geq">::</span></div>
+ <div class="rhs"><code class="t">-</code></div>
+ <div class="rhs"><span class="nt">ClassAtomNoDash</span><sub>[?U]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ClassAtomNoDash</span><sub>[U]</sub> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">SourceCharacter</span> <span class="grhsmod">but not one of</span> <code class="t">\</code> <span class="grhsmod">or</span> <code class="t">]</code> <span class="grhsmod">or</span> <code class="t">-</code></div>
+ <div class="rhs"><code class="t">\</code> <span class="nt">ClassEscape</span><sub>[?U]</sub></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ClassAtomInRange</span> <span class="geq">::</span></div>
+ <div class="rhs"><code class="t">-</code></div>
+ <div class="rhs"><span class="nt">ClassAtomNoDashInRange</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ClassAtomNoDashInRange</span> <span class="geq">::</span></div>
+ <div class="rhs"><span class="nt">SourceCharacter</span> <span class="grhsmod">but not one of</span> <code class="t">\</code> <span class="grhsmod">or</span> <code class="t">]</code> <span class="grhsmod">or</span> <code class="t">-</code></div>
+ <div class="rhs"><code class="t">\</code> <span class="nt">ClassEscape</span> <code class="t">but</code> <code class="t">only</code> <code class="t">if</code> <span class="nt">ClassEscape</span> <code class="t">evaluates</code> <code class="t">to</code> <code class="t">a</code> <span class="nt">CharSet</span> <code class="t">with</code> <code class="t">exactly</code> <code class="t">one</code> <code class="t">character</code></div>
+ <div class="rhs"><code class="t">\</code> <span class="nt">IdentityEscape</span></div>
+ </div>
+
+ <div class="gp">
+ <div class="lhs"><span class="nt">ClassEscape</span><sub>[U]</sub> <span class="geq">::</span></div>
+ <div class="rhs"><span class="grhsannot">[+U]</span> <span class="nt">DecimalEscape</span></div>
+ <div class="rhs"><span class="grhsannot">[~U]</span> <span class="nt">DecimalEscape</span> <code class="t">but</code> <code class="t">only</code> <code class="t">if</code> <code class="t">the</code> <code class="t">integer</code> <code class="t">value</code> <code class="t">of</code> <span class="nt">DecimalEscape</span> <code class="t">is</code> <code class="t"><=</code> <span class="nt">NCapturingParens</span></div>
+ <div class="rhs"><code class="t">b</code></div>
+ <div class="rhs"><span class="grhsannot">[+U]</span> <span class="nt">CharacterEscape</span><sub>[U]</sub></div>
+ <div class="rhs"><span class="grhsannot">[+U]</span> <span class="nt">CharacterClassEscape</span></div>
+ <div class="rhs"><span class="grhsannot">[~U]</span> <span class="nt">CharacterClassEscape</span></div>
+ <div class="rhs"><span class="grhsannot">[~U]</span> <span class="nt">CharacterEscape</span></div>
+ </div>
+
+ <p><span class="marker">B.1.4.1	</span><b>Pattern Semantics</b></p>
+
+ <p>The semantics of <a href="#sec-pattern-semantics">21.2.2</a> is extended as follows:</p>
+
+ <p>Within <a href="#sec-term">21.2.2.5</a> reference to “<span class="prod"><span class="nt">Atom</span> <span
+ class="geq">::</span> <code class="t">(</code> <span class="nt">Disjunction</span> <code class="t">)</code></span> ”
+ are to be interpreted as meaning “<span class="prod"><span class="nt">Atom</span> <span class="geq">::</span> <code
+ class="t">(</code> <span class="nt">Disjunction</span> <code class="t">)</code></span> or <span class="prod"><span
+ class="nt">AtomNoBrace</span> <span class="geq">::</span> <code class="t">(</code> <span class="nt">Disjunction</span> <code
+ class="t">)</code></span> ”.</p>
+
+ <p>Term (<a href="#sec-term">21.2.2.5</a>) includes the following additional evaluation rule:</p>
+
+ <p>The production <span class="prod"><span class="nt">Term</span> <span class="geq">::</span> <span
+ class="nt">QuantifiableAssertion</span> <span class="nt">Quantifier</span></span> evaluates the same as the production <span
+ class="prod"><span class="nt">Term</span> <span class="geq">::</span> <span class="nt">Atom</span> <span
+ class="nt">Quantifier</span></span> but with <span class="nt">QuantifiableAssertion</span> substituted for <span
+ style="font-family: Times New Roman"><i>Atom</i>.</span></p>
+
+ <p>Atom (<a href="#sec-atom">21.2.2.8</a>) evaluation rules for the <span class="nt">Atom</span> productions except for
+ <span class="prod"><span class="nt">Atom</span> <span class="geq">::</span> <span class="nt">PatternCharacter</span></span>
+ are also used for the <span class="nt">AtomNoBrace</span> productions, but with <span class="nt">AtomNoBrace</span>
+ substituted for <span style="font-family: Times New Roman"><i>Atom</i>.</span> The following evaluation rule is also
+ added:</p>
+
+ <p>The production <span class="prod"><span class="nt">AtomNoBrace</span> <span class="geq">::</span> <span
+ class="nt">PatternCharacterNoBrace</span></span> evaluates as follows:</p>
+
+ <ol class="proc">
+ <li>Let <i>ch</i> be the character represented by <i>PatternCharacterNoBrace</i>.</li>
+ <li>Let <i>A</i> be a one-element CharSet containing the character <i>ch</i>.</li>
+ <li>Call CharacterSetMatcher(<i>A</i>, <b>false</b>) and return its Matcher result.</li>
+ </ol>
+
+ <p>CharacterEscape (<a href="#sec-characterescape">21.2.2.10</a>) includes the following additional evaluation rule:</p>
+
+ <p>The production <span class="prod"><span class="nt">CharacterEscape</span> <span class="geq">::</span> <span
+ class="nt">OctalEscapeSequence</span></span> evaluates by evaluating the CV of the <span
+ class="nt">OctalscapeSequence</span> (<a href="#sec-additional-syntax-string-literals">see B.1.2</a>) and returning its
+ character result.</p>
+
+ <p>ClassAtom (<a href="#sec-classatom">21.2.2.17</a>) includes the following additional evaluation rules:</p>
+
+ <p>The production <span class="prod"><span class="nt">ClassAtomInRange</span> <span class="geq">::</span> <code
+ class="t">-</code></span> evaluates by returning the CharSet containing the one character <code>-</code>.</p>
+
+ <p>The production <span class="prod"><span class="nt">ClassAtomInRange</span> <span class="geq">::</span> <span
+ class="nt">ClassAtomNoDashInRange</span></span> evaluates by evaluating <span class="nt">ClassAtomNoDashInRange</span> to
+ obtain a CharSet and returning that CharSet.</p>
+
+ <p>ClassAtomNoDash (<a href="#sec-classatomnodash">21.2.2.18</a>) includes the following additional evaluation rules:</p>
+
+ <p>The production <span class="prod"><span class="nt">ClassAtomNoDashInRange</span> <span class="geq">::</span> <span
+ class="nt">SourceCharacter</span> <span class="grhsmod">but not one of</span> <code class="t">\</code> <span
+ class="grhsmod">or</span> <code class="t">]</code> <span class="grhsmod">or</span> <code class="t">-</code></span> evaluates
+ by returning a one-element CharSet containing the character represented by <span class="nt">SourceCharacter</span>.</p>
+
+ <p>The production <span class="prod"><span class="nt">ClassAtomNoDashInRange</span> <span class="geq">::</span> <code
+ class="t">\</code> <span class="nt">ClassEscape</span></span> but ony if…, evaluates by evaluating <span
+ class="nt">ClassEscape</span> to obtain a CharSet and returning that CharSet.</p>
+
+ <p>The production <span class="prod"><span class="nt">ClassAtomNoDashInRange</span> <span class="geq">::</span> <code
+ class="t">\</code> <span class="nt">IdentityEscape</span></span> evaluates by returning the character represented by <span
+ class="nt">IdentityEscape</span>.</p>
+ </section>
+ </section>
+
+ <section id="sec-additional-built-in-properties">
+ <div class="front">
+ <h1><span class="secnum" id="sec-B.2"><a href="#sec-additional-built-in-properties"
+ title="link to this section">B.2</a></span> Additional Built-in Properties</h1>
+
+ <p>When the ECMAScript host is a web browser the following additional properties of the standard built-in objects are
+ defined.</p>
+ </div>
+
+ <section id="sec-additional-properties-of-the-global-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-B.2.1"><a href="#sec-additional-properties-of-the-global-object"
+ title="link to this section">B.2.1</a></span> Additional Properties of the Global Object</h1>
+ </div>
+
+ <section id="sec-escape-string">
+ <h1><span class="secnum" id="sec-B.2.1.1"><a href="#sec-escape-string" title="link to this section">B.2.1.1</a></span>
+ escape (string)</h1>
+
+ <p>The <code>escape</code> function is a property of the global object. It computes a new version of a String value in
+ which certain characters have been replaced by a hexadecimal escape sequence.</p>
+
+ <p>For those characters being replaced whose code unit value is <code>0xFF</code> or less, a two-digit escape sequence of
+ the form <code>%</code><i>xx</i> is used. For those characters being replaced whose code unit value is greater than
+ <code>0xFF</code>, a four-digit escape sequence of the form <code>%u</code><i>xxxx</i> is used.</p>
+
+ <p>When the <code>escape</code> function is called with one argument <var>string</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>string</i> be <a href="#sec-tostring">ToString</a>(<i>string</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>string</i>).</li>
+ <li>Let <i>length</i> be the number of code units in <i>string</i>.</li>
+ <li>Let <i>R</i> be the empty string.</li>
+ <li>Let <i>k</i> be 0.</li>
+ <li>Repeat, while <i>k</i> < <i>length</i>,
+ <ol class="block">
+ <li>Let <i>char</i> be the code unit (represented as a 16-bit unsigned integer) at position <i>k</i> within
+ <i>string</i>.</li>
+ <li>If <i>char</i> is the code point of one of the 69 nonblank
+ characters<br><code>″ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@*_+-./″<br></code>then,
+ <ol class="block">
+ <li>Let <i>S</i> be a String containing the single character <i>char</i>.</li>
+ </ol>
+ </li>
+ <li>Else if <i>char</i> > 256,
+ <ol class="block">
+ <li>Let <i>S</i> be a String containing six characters <code>″%u</code><i>wxyz</i><code>″</code>
+ where <i>wxyz</i> are four hexadecimal digits encoding the value of <i>char</i>.</li>
+ </ol>
+ </li>
+ <li>Else, <i>char</i> < 256
+ <ol class="block">
+ <li>Let <i>S</i> be a String containing three characters <code>″%</code><i>xy</i><code>″</code>
+ where <i>xy</i> are two hexadecimal digits encoding the value of <i>char</i>.</li>
+ </ol>
+ </li>
+ <li>Let <i>R</i> be a new String value computed by concatenating the previous value of <i>R</i> and <i>S</i>.</li>
+ <li>Increase <i>k</i> by 1.</li>
+ </ol>
+ </li>
+ <li>Return <i>R</i>.</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The encoding is partly based on the encoding described in RFC 1738, but the entire
+ encoding specified in this standard is described above without regard to the contents of RFC 1738. This encoding does
+ not reflect changes to RFC 1738 made by RFC 3986.</p>
+ </div>
+ </section>
+
+ <section id="sec-unescape-string">
+ <h1><span class="secnum" id="sec-B.2.1.2"><a href="#sec-unescape-string" title="link to this section">B.2.1.2</a></span>
+ unescape (string)</h1>
+
+ <p>The <code>unescape</code> function is a property of the global object. It computes a new version of a String value in
+ which each escape sequence of the sort that might be introduced by the <code>escape</code> function is replaced with the
+ character that it represents.</p>
+
+ <p>When the <code>unescape</code> function is called with one argument <var>string</var>, the following steps are
+ taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>string</i> be <a href="#sec-tostring">ToString</a>(<i>string</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>string</i>).</li>
+ <li>Let <i>length</i> be the number of code units in <i>string</i>.</li>
+ <li>Let <i>R</i> be the empty String.</li>
+ <li>Let <i>k</i> be 0.</li>
+ <li>Repeat, while <i>k</i> ≠ <i>length</i>
+ <ol class="block">
+ <li>Let <i>c</i> be the code unit at position <i>k</i> within <i>string</i>.</li>
+ <li>If <i>c</i> is <code>%</code>,
+ <ol class="block">
+ <li>If <i>k</i> ≤ <i>length</i>−6 and the code unit at position <i>k</i>+1 within <i>string</i> is
+ <code>u</code> and the four code units at positions <i>k</i>+2, <i>k</i>+3, <i>k</i>+4, and <i>k</i>+5
+ within <i>string</i> are all hexadecimal digits, then
+ <ol class="block">
+ <li>Let <i>c</i> be the code unit whose value is the integer represented by the four hexadecimal digits at
+ positions <i>k</i>+2, <i>k</i>+3, <i>k</i>+4, and <i>k</i>+5 within <i>string</i>.</li>
+ <li>Increase <i>k</i> by 5.</li>
+ </ol>
+ </li>
+ <li>Else if <i>k</i> ≤ <i>length</i>−3 and the two code units at positions <i>k</i>+1 and <i>k</i>+2
+ within <i>string</i> are both hexadecimal digits, then
+ <ol class="block">
+ <li>Let <i>c</i> be the code unit whose value is the integer represented by two zeroes plus the two
+ hexadecimal digits at positions <i>k</i>+1 and <i>k</i>+2 within <i>string</i>.</li>
+ <li>Increase <i>k</i> by 2.</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ <li>Let <i>R</i> be a new String value computed by concatenating the previous value of <i>R</i> and <i>c</i>.</li>
+ <li>Increase <i>k</i> by 1.</li>
+ </ol>
+ </li>
+ <li>Return <i>R</i>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-additional-properties-of-the-object.prototype-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-B.2.2"><a href="#sec-additional-properties-of-the-object.prototype-object"
+ title="link to this section">B.2.2</a></span> Additional Properties of the Object.prototype Object</h1>
+ </div>
+
+ <section id="sec-object.prototype.__proto__">
+ <div class="front">
+ <h1><span class="secnum" id="sec-B.2.2.1"><a href="#sec-object.prototype.__proto__"
+ title="link to this section">B.2.2.1</a></span> Object.prototype.__proto__</h1>
+
+ <p>Object.prototype.__proto__ is an accessor property with attributes { [[Enumerable]]: <span
+ class="value">false</span>, [[Configurable]]: <span class="value">true</span> }. The [[Get]] and [[Set]] attributes are
+ defined as follows</p>
+ </div>
+
+ <section id="sec-get-object.prototype.__proto__">
+ <h1><span class="secnum" id="sec-B.2.2.1.1"><a href="#sec-get-object.prototype.__proto__"
+ title="link to this section">B.2.2.1.1</a></span> get Object.prototype.__proto__</h1>
+
+ <p>The value of the [[Get]] attribute is a built-in function that requires no arguments. It performs the following
+ steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the result of calling <a href="#sec-toobject">ToObject</a> passing the <b>this</b> value as the
+ argument.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>O</i>).</li>
+ <li>Return the result of calling the [[GetPrototypeOf]] internal method of <i>O</i>.</li>
+ </ol>
+ </section>
+
+ <section id="sec-set-object.prototype.__proto__">
+ <h1><span class="secnum" id="sec-B.2.2.1.2"><a href="#sec-set-object.prototype.__proto__"
+ title="link to this section">B.2.2.1.2</a></span> set Object.prototype.__proto__</h1>
+
+ <p>The value of the [[Set]] attribute is a built-in function that takes an argument <var>proto</var>. It performs the
+ following steps:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be <a href="#sec-checkobjectcoercible">CheckObjectCoercible</a>(<b>this</b> value)<i>.</i></li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>O</i>).</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>proto</i>) is neither Object nor Null, then return
+ <b>undefined</b>.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O)</i> is not Object, then return
+ <b>undefined</b>.</li>
+ <li>Let <i>status</i> be the result of calling the [[SetPrototypeOf]] internal method of <i>O</i> with argument
+ <i>proto</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>status</i>).</li>
+ <li>If <i>status</i> is <b>false</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Return <b>undefined</b>.</li>
+ </ol>
+ </section>
+ </section>
+ </section>
+
+ <section id="sec-additional-properties-of-the-string.prototype-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-B.2.3"><a href="#sec-additional-properties-of-the-string.prototype-object"
+ title="link to this section">B.2.3</a></span> Additional Properties of the String.prototype Object</h1>
+ </div>
+
+ <section id="sec-string.prototype.substr">
+ <h1><span class="secnum" id="sec-B.2.3.1"><a href="#sec-string.prototype.substr"
+ title="link to this section">B.2.3.1</a></span> String.prototype.substr (start, length)</h1>
+
+ <p>The <code>substr</code> method takes two arguments, <var>start</var> and <var>length</var>, and returns a substring of
+ the result of converting the <b>this</b> object to a String, starting from character position <var>start</var> and running
+ for <var>length</var> characters (or through the end of the String if <var>length</var> is <b>undefined</b>). If
+ <var>start</var> is negative, it is treated as <span style="font-family: Times New
+ Roman">(<i>sourceLength</i>+<i>start</i>)</span> where <var>sourceLength</var> is the length of the String. The result is
+ a String value, not a String object. The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be <a href="#sec-checkobjectcoercible">CheckObjectCoercible</a>(<b>this</b> value).</li>
+ <li>Let <i>S</i> be <a href="#sec-tostring">ToString</a>(<i>O</i>).</li>
+ <li>Let <i>intStart</i> be <a href="#sec-tointeger">ToInteger</a>(<i>start</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>intStart</i>).</li>
+ <li>If <i>length</i> is <b>undefined</b>, let <i>end</i> be <b>+∞</b>; otherwise let <i>end</i> be <a
+ href="#sec-tointeger">ToInteger</a>(<i>length</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>end</i>).</li>
+ <li>Let <i>size</i> be the number of characters in <i>S</i>.</li>
+ <li>If <i>intStart</i> is negative, then let <i>intStart</i> be max(<i>size</i> + <i>intStart</i>,0).</li>
+ <li>Let <i>resultLength</i> be min(max(<i>end</i>,0), <i>size</i> – <i>intStart</i>).</li>
+ <li>If <i>resultLength</i> ≤ 0, return the empty String <code>""</code>.</li>
+ <li>Return a String containing <i>resultLength</i> consecutive characters from <i>S</i> beginning with the character at
+ position <i>intStart</i>.</li>
+ </ol>
+
+ <p>The <code>length</code> property of the <code>substr</code> method is <b>2</b>.</p>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>substr</code> function is intentionally generic; it does not require that its
+ <b>this</b> value be a String object. Therefore it can be transferred to other kinds of objects for use as a method.</p>
+ </div>
+ </section>
+
+ <section id="sec-string.prototype.anchor">
+ <div class="front">
+ <h1><span class="secnum" id="sec-B.2.3.2"><a href="#sec-string.prototype.anchor"
+ title="link to this section">B.2.3.2</a></span> String.prototype.anchor ( name )</h1>
+
+ <p>When the <b>anchor</b> method is called with argument <var>name</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>S</i> be the <b>this</b> value.</li>
+ <li>Return <a href="#sec-createhtml">CreateHTML</a>(<i>S</i>, <code>"a"</code>, <code>"name"</code>,
+ <i>name</i>).</li>
+ </ol>
+ </div>
+
+ <section id="sec-createhtml">
+ <h1><span class="secnum" id="sec-B.2.3.2.1"><a href="#sec-createhtml" title="link to this section">B.2.3.2.1</a></span>
+ CreateHTML ( name ) Abstract Operation</h1>
+
+ <p>The abstract operation <span style="font-family: Times New Roman">CreateHTML</span> is called with arguments
+ <var>string, tag</var>, <var>attribute</var>, and <span style="font-family: Times New Roman"><i>value</i>.</span> The
+ arguments <var>tag</var> and <var>attribute</var> must be string values. The following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>str</i> be <a href="#sec-checkobjectcoercible">CheckObjectCoercible</a>(<i>string</i>).</li>
+ <li>Let <i>S</i> be <a href="#sec-tostring">ToString</a>(<i>str</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>S</i>).</li>
+ <li>Let <i>p1</i> be the string value that is the concatenation of <code>"<"</code> and <i>tag</i>.</li>
+ <li>If <i>attribute</i> is not the empty String, then
+ <ol class="block">
+ <li>Let <i>V</i> be <a href="#sec-tostring">ToString</a>(<i>value</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>V</i>).</li>
+ <li>Let <i>escapedV</i> be the string value that is the same as <i>V</i> except that each occurrence of the
+ character <code>"</code> (code unit value 0x0022) in <i>V</i> has been replaced with the six character
+ sequence <code>"&quot;"</code>.</li>
+ <li>Let <i>p1</i> be the string value that is the concatenation of the following string values:
+ <ul>
+ <li>The string value of <i>p1</i></li>
+ <li>Code unit 0x0020 (a single SPACE)</li>
+ <li>The string value of <i>attribute</i></li>
+ <li>Code unit 0x003D (a single <code>=</code>)</li>
+ <li>Code unit 0x0022 (a single QUOTATION MARK)</li>
+ <li>The string value of <i>escapedV</i></li>
+ <li>Code unit 0x0022 (a single QUOTATION MARK)</li>
+ </ul>
+ </li>
+ </ol>
+ </li>
+ <li>Let <i>p2</i> be the string value that is the concatenation of <i>p1</i> and <code>">"</code>.</li>
+ <li>Let <i>p3</i> be the string value that is the concatenation of <i>p2</i> and <i>S</i>.</li>
+ <li>Let <i>p4</i> be the string value that is the concatenation of <i>p3</i>, <code>"</"</code>, <i>tag</i>, and
+ <code>">"</code>.</li>
+ <li>Return <i>p4</i>.</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-string.prototype.big">
+ <h1><span class="secnum" id="sec-B.2.3.3"><a href="#sec-string.prototype.big"
+ title="link to this section">B.2.3.3</a></span> String.prototype.big ()</h1>
+
+ <p>When the <b>big</b> method is called with no arguments, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>S</i> be the <b>this</b> value.</li>
+ <li>Return <a href="#sec-createhtml">CreateHTML</a>(<i>S</i>, <code>"big"</code>, <code>""</code>,
+ <code>""</code>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-string.prototype.blink">
+ <h1><span class="secnum" id="sec-B.2.3.4"><a href="#sec-string.prototype.blink"
+ title="link to this section">B.2.3.4</a></span> String.prototype.blink ()</h1>
+
+ <p>When the <b>blink</b> method is called with no arguments, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>S</i> be the <b>this</b> value.</li>
+ <li>Return <a href="#sec-createhtml">CreateHTML</a>(<i>S</i>, <code>"blink"</code>, <code>""</code>,
+ <code>""</code>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-string.prototype.bold">
+ <h1><span class="secnum" id="sec-B.2.3.5"><a href="#sec-string.prototype.bold"
+ title="link to this section">B.2.3.5</a></span> String.prototype.bold ()</h1>
+
+ <p>When the <b>bold</b> method is called with no arguments, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>S</i> be the <b>this</b> value.</li>
+ <li>Return <a href="#sec-createhtml">CreateHTML</a>(<i>S</i>, <code>"b"</code>, <code>""</code>, <code>""</code>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-string.prototype.fixed">
+ <h1><span class="secnum" id="sec-B.2.3.6"><a href="#sec-string.prototype.fixed"
+ title="link to this section">B.2.3.6</a></span> String.prototype.fixed ()</h1>
+
+ <p>When the <b>fixed</b> method is called with no arguments, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>S</i> be the <b>this</b> value.</li>
+ <li>Return <a href="#sec-createhtml">CreateHTML</a>(<i>S</i>, <code>"tt"</code>, <code>""</code>, <code>""</code>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-string.prototype.fontcolor">
+ <h1><span class="secnum" id="sec-B.2.3.7"><a href="#sec-string.prototype.fontcolor"
+ title="link to this section">B.2.3.7</a></span> String.prototype.fontcolor ( color )</h1>
+
+ <p>When the <b>fontcolor</b> method is called with argument <var>color</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>S</i> be the <b>this</b> value.</li>
+ <li>Return <a href="#sec-createhtml">CreateHTML</a>(<i>S</i>, <code>"font"</code>, <code>"color"</code>,
+ <i>color</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-string.prototype.fontsize">
+ <h1><span class="secnum" id="sec-B.2.3.8"><a href="#sec-string.prototype.fontsize"
+ title="link to this section">B.2.3.8</a></span> String.prototype.fontsize ( size )</h1>
+
+ <p>When the <b>fontsize</b> method is called with argument <var>size</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>S</i> be the <b>this</b> value.</li>
+ <li>Return <a href="#sec-createhtml">CreateHTML</a>(<i>S</i>, <code>"font"</code>, <code>"size"</code>,
+ <i>size</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-string.prototype.italics">
+ <h1><span class="secnum" id="sec-B.2.3.9"><a href="#sec-string.prototype.italics"
+ title="link to this section">B.2.3.9</a></span> String.prototype.italics ()</h1>
+
+ <p>When the <b>italics</b> method is called with no arguments, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>S</i> be the <b>this</b> value.</li>
+ <li>Return <a href="#sec-createhtml">CreateHTML</a>(<i>S</i>, <code>"i"</code>, <code>""</code>, <code>""</code>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-string.prototype.link">
+ <h1><span class="secnum" id="sec-B.2.3.10"><a href="#sec-string.prototype.link"
+ title="link to this section">B.2.3.10</a></span> String.prototype.link ( url )</h1>
+
+ <p>When the <b>link</b> method is called with argument <var>url</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>S</i> be the <b>this</b> value.</li>
+ <li>Return <a href="#sec-createhtml">CreateHTML</a>(<i>S</i>, <code>"a"</code>, <code>"href"</code>, <i>url</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-string.prototype.small">
+ <h1><span class="secnum" id="sec-B.2.3.11"><a href="#sec-string.prototype.small"
+ title="link to this section">B.2.3.11</a></span> String.prototype.small ()</h1>
+
+ <p>When the <b>small</b> method is called with no arguments, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>S</i> be the <b>this</b> value.</li>
+ <li>Return <a href="#sec-createhtml">CreateHTML</a>(<i>S</i>, <code>"small"</code>, <code>""</code>,
+ <code>""</code>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-string.prototype.strike">
+ <h1><span class="secnum" id="sec-B.2.3.12"><a href="#sec-string.prototype.strike"
+ title="link to this section">B.2.3.12</a></span> String.prototype.strike ()</h1>
+
+ <p>When the <b>strike</b> method is called with no arguments, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>S</i> be the <b>this</b> value.</li>
+ <li>Return <a href="#sec-createhtml">CreateHTML</a>(<i>S</i>, <code>"strike"</code>, <code>""</code>,
+ <code>""</code>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-string.prototype.sub">
+ <h1><span class="secnum" id="sec-B.2.3.13"><a href="#sec-string.prototype.sub"
+ title="link to this section">B.2.3.13</a></span> String.prototype.sub ()</h1>
+
+ <p>When the <b>sub</b> method is called with no arguments, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>S</i> be the <b>this</b> value.</li>
+ <li>Return <a href="#sec-createhtml">CreateHTML</a>(<i>S</i>, <code>"sub"</code>, <code>""</code>,
+ <code>""</code>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-string.prototype.sup">
+ <h1><span class="secnum" id="sec-B.2.3.14"><a href="#sec-string.prototype.sup"
+ title="link to this section">B.2.3.14</a></span> String.prototype.sup ()</h1>
+
+ <p>When the <b>sup</b> method is called with no arguments, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>S</i> be the <b>this</b> value.</li>
+ <li>Return <a href="#sec-createhtml">CreateHTML</a>(<i>S</i>, <code>"sup"</code>, <code>""</code>,
+ <code>""</code>).</li>
+ </ol>
+ </section>
+ </section>
+
+ <section id="sec-additional-properties-of-the-date.prototype-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-B.2.4"><a href="#sec-additional-properties-of-the-date.prototype-object"
+ title="link to this section">B.2.4</a></span> Additional Properties of the Date.prototype Object</h1>
+ </div>
+
+ <section id="sec-date.prototype.getyear">
+ <h1><span class="secnum" id="sec-B.2.4.1"><a href="#sec-date.prototype.getyear"
+ title="link to this section">B.2.4.1</a></span> Date.prototype.getYear ( )</h1>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>getFullYear</code> method is preferred for nearly all purposes, because it
+ avoids the “year 2000 problem.”</p>
+ </div>
+
+ <p>When the <b>getYear</b> method is called with no arguments, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>t</i> be <a href="#sec-properties-of-the-date-prototype-object">this time value</a>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>t</i>).</li>
+ <li>If <i>t</i> is <b>NaN</b>, return <b>NaN</b>.</li>
+ <li>Return <a href="#sec-year-number">YearFromTime</a>(<a href="#sec-local-time">LocalTime</a>(<i>t</i>)) −
+ 1900.</li>
+ </ol>
+ </section>
+
+ <section id="sec-date.prototype.setyear">
+ <h1><span class="secnum" id="sec-B.2.4.2"><a href="#sec-date.prototype.setyear"
+ title="link to this section">B.2.4.2</a></span> Date.prototype.setYear (year)</h1>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>setFullYear</code> method is preferred for nearly all purposes, because it
+ avoids the “year 2000 problem.”</p>
+ </div>
+
+ <p>When the <b>setYear</b> method is called with one argument <var>year</var>, the following steps are taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>t</i> be <a href="#sec-local-time">LocalTime</a>(<a href="#sec-properties-of-the-date-prototype-object">this
+ time value</a>); but if <a href="#sec-properties-of-the-date-prototype-object">this time value</a> is <b>NaN</b>,
+ let <i>t</i> be <b>+0</b>.</li>
+ <li>Let <i>y</i> be <a href="#sec-tonumber">ToNumber</a>(<i>year</i>).</li>
+ <li>If <i>y</i> is <b>NaN</b>, set the [[DateValue]] <a href="#sec-object-internal-methods-and-internal-slots">internal
+ slot</a> of this Date object to <b>NaN</b> and return <b>NaN</b>.</li>
+ <li>If <i>y</i> is not <b>NaN</b> and 0 ≤ <a href="#sec-tointeger">ToInteger</a>(<i>y</i>) ≤ 99 then let
+ <i>yyyy</i> be <a href="#sec-tointeger">ToInteger</a>(<i>y</i>) + 1900. Otherwise, let <i>yyyy</i> be
+ <i>y</i>.</li>
+ <li>Let <i>d</i> be <a href="#sec-makeday">MakeDay</a>(<i>yyyy</i>, <a
+ href="#sec-month-number">MonthFromTime</a>(<i>t</i>), <a href="#sec-date-number">DateFromTime</a>(<i>t</i>)).</li>
+ <li>Let <i>date</i> be <a href="#sec-local-time">UTC</a>(<a href="#sec-makedate">MakeDate</a>(<i>d</i>, <a
+ href="#sec-day-number-and-time-within-day">TimeWithinDay</a>(<i>t</i>))).</li>
+ <li>Set the [[DateValue]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of this Date
+ object to <a href="#sec-timeclip">TimeClip</a>(<i>date</i>).</li>
+ <li>Return the value of the [[DateValue]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a> of
+ this Date object.</li>
+ </ol>
+ </section>
+
+ <section id="sec-date.prototype.togmtstring">
+ <h1><span class="secnum" id="sec-B.2.4.3"><a href="#sec-date.prototype.togmtstring"
+ title="link to this section">B.2.4.3</a></span> Date.prototype.toGMTString ( )</h1>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The property <code>toUTCString</code> is preferred. The <code>toGMTString</code>
+ property is provided principally for compatibility with old code. It is recommended that the <code>toUTCString</code>
+ property be used in new ECMAScript code.</p>
+ </div>
+
+ <p>The Function object that is the initial value of <code>Date.prototype.toGMTString</code> is the same Function object
+ that is the initial value of <code><a href="#sec-date.prototype.toutcstring">Date.prototype.toUTCString</a></code>.</p>
+ </section>
+ </section>
+
+ <section id="sec-additional-properties-of-the-regexp.prototype-object">
+ <div class="front">
+ <h1><span class="secnum" id="sec-B.2.5"><a href="#sec-additional-properties-of-the-regexp.prototype-object"
+ title="link to this section">B.2.5</a></span> Additional Properties of the RegExp.prototype Object</h1>
+ </div>
+
+ <section id="sec-regexp.prototype.compile">
+ <h1><span class="secnum" id="sec-B.2.5.1"><a href="#sec-regexp.prototype.compile"
+ title="link to this section">B.2.5.1</a></span> RegExp.prototype.compile (pattern, flags )</h1>
+
+ <p>When the <b>compile</b> method is called with arguments <i>pattern</i> and <i>flags</i>, the following steps are
+ taken:</p>
+
+ <ol class="proc">
+ <li>Let <i>O</i> be the <b>this</b> value.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is not Object or <a
+ href="#sec-ecmascript-data-types-and-values">Type</a>(<i>O</i>) is Object and <i>O</i> does not have a
+ [[RegExpMatcher]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, then
+ <ol class="block">
+ <li>Throw a <b>TypeError</b> exception.</li>
+ </ol>
+ </li>
+ <li>Let <i>extensible</i> be the result of calling the [[IsExtensible]] internal method of <i>O</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>extensible</i>).</li>
+ <li>If <i>extensible</i> is <b>false</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>pattern</i>) is Object and <i>pattern</i> has a
+ [[RegExpMatcher]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>, then
+ <ol class="block">
+ <li>If the value of <i>pattern’s</i> [[RegExpMatcher]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> is <b>undefined</b>, then throw a
+ <b>TypeError</b> exception.</li>
+ <li>If <i>flags</i> is not <b>undefined</b>, then throw a <b>TypeError</b> exception.</li>
+ <li>Let <i>P</i> be the value of <i>pattern’s</i> [[OriginalSource]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>Let <i>F</i> be the value of <i>pattern’s</i> [[OriginalFlags]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ </ol>
+ </li>
+ <li>Else,
+ <ol class="block">
+ <li>Let <i>P</i> be <i>pattern</i>.</li>
+ <li>Let <i>F</i> be <i>flags</i>.</li>
+ </ol>
+ </li>
+ <li>Return <a href="#sec-regexpinitialize">RegExpInitialize</a>(<i>O,</i> <i>P</i>, <i>F</i>).</li>
+ </ol>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <code>compile</code> method completely reinitializes the <b>this</b> object RegExp
+ with a new pattern and flags. An implementaton may interpret use of this method as an assertion that the resulting
+ RegExp object will be used multiple times and hence is a candidate for extra optimization.</p>
+ </div>
+ </section>
+ </section>
+ </section>
+
+ <section id="sec-other-additional-features">
+ <div class="front">
+ <h1><span class="secnum" id="sec-B.3"><a href="#sec-other-additional-features" title="link to this section">B.3</a></span>
+ Other Additional Features</h1>
+ </div>
+
+ <section id="sec-__proto__-property-names-in-object-initializers">
+ <h1><span class="secnum" id="sec-B.3.1"><a href="#sec-__proto__-property-names-in-object-initializers"
+ title="link to this section">B.3.1</a></span> __proto__ Property Names in Object Initializers</h1>
+
+ <p>In <a href="#sec-object-initializer-runtime-semantics-propertydefinitionevaluation">12.2.5.9</a> the
+ PropertyDefinitionEvaluation algorithm for the production <span class="prod"><span class="nt">PropertyDefinition</span>
+ <span class="geq">:</span> <span class="nt">PropertyName</span> <code class="t">:</code> <span
+ class="nt">AssignmentExpression</span></span> is replaced with the following:</p>
+
+ <div class="gp prod"><span class="nt">PropertyDefinition</span> <span class="geq">:</span> <span class="nt">PropertyName</span> <code class="t">:</code> <span class="nt">AssignmentExpression</span></div>
+ <ol class="proc">
+ <li>Let <i>propKey</i> be the result of evaluating <i>PropertyName</i>.</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>propKey</i>).</li>
+ <li>Let <i>exprValueRef</i> be the result of evaluating <i>AssignmentExpression</i>.</li>
+ <li>Let <i>propValue</i> be <a href="#sec-getvalue">GetValue</a>(<i>exprValueRef</i>).</li>
+ <li><a href="#sec-returnifabrupt">ReturnIfAbrupt</a>(<i>propValue</i>).</li>
+ <li>If <i>propKey</i> is the string value <code>"__proto__"</code> and if IsComputedPropertyKey(<i>propKey</i>) is
+ <b>false</b>, then
+ <ol class="block">
+ <li>If <a href="#sec-ecmascript-data-types-and-values">Type</a>(<i>propValue</i>) is either Object or Null, then
+ <ol class="block">
+ <li>Return the result of calling the [[SetPrototypeOf]] internal method of <i>object</i> with argument
+ <i>propValue</i>.</li>
+ </ol>
+ </li>
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<span style="font-family:
+ sans-serif">empty</span>).</li>
+ </ol>
+ </li>
+ <li>If <a href="#sec-isanonymousfunctiondefinition">IsAnonymousFunctionDefinition</a>(<i>AssignmentExpression</i>) is
+ <b>true</b>, then
+ <ol class="block">
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>propValue</i> is an <a
+ href="#sec-ecmascript-function-objects">ECMAScript function object</a>.</li>
+ <li>Let <i>referencesSuper</i> be the value of <i>propValue</i>’s [[NeedsSuper]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a>.</li>
+ <li>If <i>referencesSuper</i> is <b>true</b>, then
+ <ol class="block">
+ <li>Set the <i>propValue</i>’s [[HomeObject]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to <i>object</i>.</li>
+ <li>Set the <i>propValue</i>’s [[MethodName]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> to <i>propKey</i>.</li>
+ </ol>
+ </li>
+ <li><a href="#sec-setfunctionname">SetFunctionName</a>(<i>propValue</i>, <i>propKey</i>).</li>
+ </ol>
+ </li>
+ <li>Let <i>desc</i> be the <a href="#sec-property-descriptor-specification-type">Property Descriptor</a>{[[Value]]:
+ <i>propValue</i>, [[Writable]]: <b>true</b>, [[Enumerable]]: <b>true</b>, [[Configurable]]: <b>true</b>}</li>
+ <li>Return <a href="#sec-definepropertyorthrow">DefinePropertyOrThrow</a>(<i>object</i>, <i>propKey</i>,
+ <i>desc</i>).</li>
+ </ol>
+ </section>
+
+ <section id="sec-web-legacy-compatibility-for-block-level-function-declarations">
+ <h1><span class="secnum" id="sec-B.3.2"><a href="#sec-web-legacy-compatibility-for-block-level-function-declarations"
+ title="link to this section">B.3.2</a></span> Web Legacy Compatibility for Block-Level Function Declarations</h1>
+
+ <p>Prior to the Sixth Edition, the ECMAScript specification did not define the occurrence of a <span
+ class="nt">FunctionDeclaration</span> as an element of a <span class="nt">Block</span> statement’s <span
+ class="nt">StatementList</span>. However, support for that form of <span class="nt">FunctionDeclaration</span> was an
+ allowable extension and most browser-hosted ECMAScript implementations permitted them. Unfortunately, the semantics of such
+ declarations differ among those implementations. Because of these semantic differences, existing web ECMAScript code that
+ uses <span class="nt">Block</span> level function declarations is only portable among browser implementation if the usage
+ only depends upon the semantic intersection of all of the browser implementations for such declarations. The following are
+ the use cases that fall within that intersection semantics:</p>
+
+ <ol class="proc">
+ <li>A function is declared and only referenced within a single block
+ <ul>
+ <li>
+ <p>A function declaration with the name <var>f</var> is declared exactly once within the function code of an
+ enclosing function <var>g</var> and that declaration is nested within a <span class="nt">Block</span>.</p>
+ </li>
+
+ <li>
+ <p>No other declaration of <var>f</var> that is not a <code>var</code> declaration occurs within the function code
+ of <var>g</var></p>
+ </li>
+
+ <li>
+ <p>All references to <var>f</var> occur within the <span class="nt">StatementList</span> of the <span
+ class="nt">Block</span> containing the declaration of <var>f</var>.</p>
+ </li>
+ </ul>
+ </li>
+ <li>A function is declared and possibly used within a single <span class="nt">Block</span> but also referenced by an inner
+ function definition that is not contained within that same <span class="nt">Block</span>.
+ <ul>
+ <li>
+ <p>A function declaration with the name <var>f</var> is declared exactly once within the function code of an
+ enclosing function <var>g</var> and that declaration is nested within a <span class="nt">Block</span>.</p>
+ </li>
+
+ <li>
+ <p>No other declaration of <var>f</var> that is not a <code>var</code> declaration occurs within the function code
+ of <var>g</var></p>
+ </li>
+
+ <li>
+ <p>References to <var>f</var> may occur within the <span class="nt">StatementList</span> of the <span
+ class="nt">Block</span> containing the declaration of <var>f</var>.</p>
+ </li>
+
+ <li>
+ <p>References to <var>f</var> occur within the function code of <var>g</var> that lexically follows the <span
+ class="nt">Block</span> containing the declaration of <var>f</var>.</p>
+ </li>
+ </ul>
+ </li>
+ <li>A function is declared and possibly used within a single block but also referenced within subsequent blocks.
+ <ul>
+ <li>
+ <p>A function declaration with the name <var>f</var> is declared exactly once within the function code of an
+ enclosing function <var>g</var> and that declaration is nested within a <span class="nt">Block</span>.</p>
+ </li>
+
+ <li>
+ <p>No other declaration of <var>f</var> that is not a <code>var</code> declaration occurs within the function code
+ of <var>g</var></p>
+ </li>
+
+ <li>
+ <p>References to <var>f</var> may occur within the <span class="nt">StatementList</span> of the <span
+ class="nt">Block</span> containing the declaration of <var>f</var>.</p>
+ </li>
+
+ <li>
+ <p>References to <var>f</var> occur within another function <var>h</var> that is nested within <var>g</var> and no
+ other declaration of <var>f</var> shadows the references to <var>f</var> from within <var>h</var>.</p>
+ </li>
+
+ <li>
+ <p>All invocations of <i>h</i> occur after the declaration of <i>f</i> has been evaluated.</p>
+ </li>
+ </ul>
+ </li>
+ </ol>
+
+ <p>The first use case is interoperable with the semantics of <span class="nt">Block</span> level function declarations
+ provided by ECMA-262 Edition 6. Any pre-existing ECMAScript code that employees that use case will operate using the Block
+ level function declarations semantics defined by clauses 9, 13, and 14 of this specification.</p>
+
+ <p>Sixth edition interoperability for the second and third use cases requires the following extensions to the <a
+ href="#sec-ordinary-and-exotic-objects-behaviours">clause 9</a> and 14 semantics. These extensions are applied to each
+ non-strict mode function <var>g</var> for each <i>FunctionDeclaration</i> <i>f</i> that is directly contained in the
+ <i>StatementList</i> of a <i>Block</i>, <i>CaseClause</i>, or <i>DefaultClause</i> that is part of the function code of
+ <i>g</i></p>
+
+ <ol class="proc">
+ <li>Let <i>F</i> be StringValue of the <i>BindingIdentifier</i> of <i>FunctionDeclaration</i> <i>f</i>.</li>
+ <li>If replacing the <i>FunctionDeclaration</i> <i>f</i> with a <i>VariableStatement</i> that has <i>F</i> as a
+ <i>BindingIdentifier</i> would not produce any Early Errors for <i>g</i>, then
+ <ol class="block">
+ <li>During <a href="#sec-functiondeclarationinstantiation">FunctionDeclarationInstantiation</a> (<a
+ href="#sec-functiondeclarationinstantiation">9.2.13</a>) for <i>g</i> perform the following steps immediately
+ before performing step 30:
+ <ol class="block">
+ <li><span style="font-family: sans-serif">NOTE	A var binding for</span> <i>F</i> <span style="font-family:
+ sans-serif">is only instantiated here if it is not also a VarDeclaredName, the name of a formal parameter, or
+ another</span> <i>FunctionDeclarations</i>.</li>
+ <li>If <i>instantiatedVarNames</i> does not contain <i>F</i>, then
+ <ol class="block">
+ <li>Let <i>status</i> be the result of calling <i>env’s</i> CreateMutableBinding concrete method passing
+ <i>F</i> as the argument.</li>
+ <li>NOTE The new binding is not initialized during <a
+ href="#sec-functiondeclarationinstantiation">FunctionDeclarationInstantiation</a>.</li>
+ <li><a href="#sec-algorithm-conventions">Assert</a>: <i>status</i> is never an <a
+ href="#sec-completion-record-specification-type">abrupt completion</a>.</li>
+ <li>In place of the <i>FunctionDeclaration</i> Evaluation algorithm provide in <a
+ href="#sec-function-definitions-static-semantics-vardeclarednames">14.1.17</a>, perform the following
+ steps to evaluate the <i>FunctionDeclaration</i> <i>f</i>:
+ <ol class="nested proc">
+ <li>Let <i>fenv</i> be <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-execution-contexts">VariableEnvironment</a>.</li>
+ <li>Let <i>benv</i> be <a href="#sec-execution-contexts">the running execution context</a>’s <a
+ href="#sec-execution-contexts">LexicalEnvironment</a>.</li>
+ <li>Let <i>fobj</i> be the result of calling the GetBindingValue concrete method of <i>benv</i> with
+ arguments <i>F</i> and <b>false</b>.</li>
+ <li>If the binding for <i>F</i> in <i>fenv</i> has not been initialized, then</li>
+ <li>Call the InitializeBinding concrete method of <i>fenv</i> with arguments <i>F</i> and
+ <i>fobj</i>.</li>
+ <li>Return <a href="#sec-normalcompletion">NormalCompletion</a>(<span style="font-family:
+ sans-serif">empty</span>).</li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+ </li>
+ </ol>
+
+ <p>If an ECMAScript implementation has a mechanism for reporting diagnostic warning messages, a warning should be produced
+ for each function <i>g</i> whose function code contains a <i>FunctionDeclaration</i> for which step 2.a above will be
+ performed.</p>
+ </section>
+
+ <section id="sec-variablestatements-in-catch-blocks">
+ <h1><span class="secnum" id="sec-B.3.3"><a href="#sec-variablestatements-in-catch-blocks"
+ title="link to this section">B.3.3</a></span> VariableStatements in Catch blocks</h1>
+
+ <p>The content of <a href="#sec-try-statement-static-semantics-early-errors">subclause 13.14.1</a> is replaced with the
+ following:</p>
+
+ <div class="gp prod"><span class="nt">Catch</span> <span class="geq">:</span> <code class="t">catch</code> <code class="t">(</code> <span class="nt">CatchParameter</span> <code class="t">)</code> <span class="nt">Block</span></div>
+ <ul>
+ <li>
+ <p>It is a Syntax Error if any element of the BoundNames of <span class="nt">CatchParameter</span> also occurs in the
+ LexicallyDeclaredNames of <span class="nt">Block</span>.</p>
+ </li>
+
+ <li>
+ <p>It is a Syntax Error if any element of the BoundNames of <span class="nt">CatchParameter</span> also occurs in the
+ VarDeclaredNames of <var>Block, unless that element is only bound by a VariableStatment or</var> <var>the
+ VariableDeclarationList of a for statement, or the ForBinding of a for-in statement</var>.</p>
+ </li>
+ </ul>
+
+ <div class="note">
+ <p><span class="nh">NOTE</span> The <i>Block</i> of a <i>Catch</i> clause may contain <code>var</code> declarations that
+ bind a name that is also bound by the <i>CatchParameter</i>. At runtime, such bindings are instantiated in the
+ VariableDeclarationEnvironment. They do not shadow the same-named bindings introduced by the <i>CatchParameter</i> and
+ hence the <i>Initializer</i> for such <code>var</code> declarations will assign to the corresponding catch parameter
+ rather than the <code>var</code> binding. The relaxation of the normal static semantic rule does not apply to names only
+ bound by for-of statements.</p>
+ </div>
+ </section>
+ </section>
+</section>
+
+<section id="sec-strict-mode-of-ecmascript">
+ <h1><span class="secnum" id="sec-C"><a href="#sec-strict-mode-of-ecmascript"
+ title="link to this section">Annex C</a></span> <span class="section-status">(informative)</span> The Strict Mode of
+ ECMAScript</h1>
+
+ <p><b>The strict mode restriction and exceptions</b></p>
+
+ <ul>
+ <li>
+ <p>The identifiers "<code>implements</code>", "<code>interface</code>", "<code>let</code>", "<code>package</code>",
+ "<code>private</code>", "<code>protected</code>", "<code>public</code>", "<code>static</code>", and "<code>yield</code>" are
+ classified as <i>FutureReservedWord</i> tokens within <a href="#sec-strict-mode-code">strict mode code</a>. (<a
+ href="#sec-future-reserved-words">11.6.2.2</a>).</p>
+ </li>
+
+ <li>
+ <p>A conforming implementation, when processing <a href="#sec-strict-mode-code">strict mode code</a>, may not extend the
+ syntax of <i>NumericLiteral</i> (<a href="#sec-literals-numeric-literals">11.8.3</a>) to include
+ <i>LegacyOctalIntegerLiteral</i> as described in <a href="#sec-additional-syntax-numeric-literals">B.1.1</a>.</p>
+ </li>
+
+ <li>
+ <p>A conforming implementation, when processing <a href="#sec-strict-mode-code">strict mode code</a> (<a
+ href="#sec-strict-mode-code">see 10.2.1</a>), may not extend the syntax of <i>EscapeSequence</i> to include
+ <i>LegacyOctalEscapeSequence</i> as described in <a href="#sec-additional-syntax-string-literals">B.1.2</a>.</p>
+ </li>
+
+ <li>
+ <p>Assignment to an undeclared identifier or otherwise unresolvable reference does not create a property in the global
+ object. When a simple assignment occurs within <a href="#sec-strict-mode-code">strict mode code</a>, its <i>LeftHandSide</i>
+ must not evaluate to an <a href="#sec-reference-specification-type">unresolvable Reference</a>. If it does a
+ <b>ReferenceError</b> exception is thrown (<a href="#sec-putvalue">6.2.3.2</a>). The <i>LeftHandSide</i> also may not be a
+ reference to a data property with the attribute value {[[Writable]]:<b>false</b>}, to an accessor property with the
+ attribute value {[[Set]]:<b>undefined</b>}, nor to a non-existent property of an object whose [[Extensible]] <a
+ href="#sec-object-internal-methods-and-internal-slots">internal slot</a> has the value <b>false</b>. In these cases a
+ <code>TypeError</code> exception is thrown (<a href="#sec-assignment-operators">12.14</a>).</p>
+ </li>
+
+ <li>
+ <p>The identifier <code>eval</code> or <code>arguments</code> may not appear as the <i>LeftHandSideExpression</i> of an
+ Assignment operator (<a href="#sec-assignment-operators">12.14</a>) or of a <i>PostfixExpression</i> (<a
+ href="#sec-assignment-operators">12.14</a>) or as the <i>UnaryExpression</i> operated upon by a Prefix Increment (<a
+ href="#sec-prefix-increment-operator">12.5.7</a>) or a Prefix Decrement (<a
+ href="#sec-prefix-decrement-operator">12.5.8</a>) operator.</p>
+ </li>
+
+ <li>
+ <p>Arguments objects for strict mode functions define non-configurable accessor properties named "<code>caller</code>" and
+ "<code>callee</code>" which throw a <b>TypeError</b> exception on access (<a
+ href="#sec-addrestrictedfunctionproperties">9.2.8</a>).</p>
+ </li>
+
+ <li>
+ <p>Arguments objects for strict mode functions do not dynamically share their array indexed property values with the
+ corresponding formal parameter bindings of their functions. (<a href="#sec-arguments-exotic-objects">9.4.4</a>).</p>
+ </li>
+
+ <li>
+ <p>For strict mode functions, if an arguments object is created the binding of the local identifier <code>arguments</code>
+ to the arguments object is immutable and hence may not be the target of an assignment expression. (<a
+ href="#sec-functiondeclarationinstantiation">9.2.13</a>).</p>
+ </li>
+
+ <li>
+ <p>It is a <b>SyntaxError</b> if <a href="#sec-strict-mode-code">strict mode code</a> contains an <i>ObjectLiteral</i> with
+ more than one definition of any data property (<a
+ href="#sec-object-initializer-static-semantics-early-errors">12.2.5.1</a>).</p>
+ </li>
+
+ <li>
+ <p>It is a <b>SyntaxError</b> if the <i>Identifier</i> <code>"eval"</code> or the <i>Identifier</i> <code>"arguments"</code>
+ occurs as the <i>Identifier</i> in a <span class="nt">PropertySetParameterList</span> of a <span
+ class="nt">PropertyDefinition</span> that is contained in <a href="#sec-strict-mode-code">strict code</a> or if its
+ <i>FunctionBody</i> is <a href="#sec-strict-mode-code">strict code</a> (<a
+ href="#sec-object-initializer-static-semantics-early-errors">12.2.5.1</a>).</p>
+ </li>
+
+ <li>
+ <p>Strict mode eval code cannot instantiate variables or functions in the variable environment of the caller to eval.
+ Instead, a new variable environment is created and that environment is used for declaration binding instantiation for the
+ eval code (<a href="#sec-eval-x">18.2.1</a>).</p>
+ </li>
+
+ <li>
+ <p>If <b>this</b> is evaluated within <a href="#sec-strict-mode-code">strict mode code</a>, then the <b>this</b> value is
+ not coerced to an object. A <b>this</b> value of <b>null</b> or <b>undefined</b> is not converted to the global object and
+ primitive values are not converted to wrapper objects. The <b>this</b> value passed via a function call (including calls
+ made using <code><a href="#sec-function.prototype.apply">Function.prototype.apply</a></code> and <b><code><a
+ href="#sec-function.prototype.call">Function.prototype.call</a></code>)</b> do not coerce the passed this value to an object
+ (<a href="#sec-getthisenvironment">8.3.2</a>, <a href="#sec-this-keyword">12.2.1</a>, <a
+ href="#sec-function.prototype.apply">19.2.3.1</a>, <a href="#sec-function.prototype.call">19.2.3.3</a>).</p>
+ </li>
+
+ <li>
+ <p>When a <code>delete</code> operator occurs within <a href="#sec-strict-mode-code">strict mode code</a>, a
+ <b>SyntaxError</b> is thrown if its <i>UnaryExpression</i> is a direct reference to a variable, function argument, or
+ function name (<a href="#sec-delete-operator">12.5.4</a>).</p>
+ </li>
+
+ <li>
+ <p>When a <code>delete</code> operator occurs within <a href="#sec-strict-mode-code">strict mode code</a>, a
+ <b>TypeError</b> is thrown if the property to be deleted has the attribute { [[Configurable]]:<b>false</b> } (<a
+ href="#sec-delete-operator">12.5.4</a>).</p>
+ </li>
+
+ <li>
+ <p>It is a <b>SyntaxError</b> if a <i>VariableDeclaration</i> occurs within <a href="#sec-strict-mode-code">strict code</a>
+ and its <i>Identifier</i> is <code>eval</code> or <code>arguments</code> (<a
+ href="#sec-variable-statement">13.2.2</a>).</p>
+ </li>
+
+ <li>
+ <p>Strict mode code may not include a <i>WithStatement</i>. The occurrence of a <i>WithStatement</i> in such a context is a
+ <b>SyntaxError</b> (<a href="#sec-with-statement">13.10</a>).</p>
+ </li>
+
+ <li>
+ <p>It is a <b>SyntaxError</b> if a <i>TryStatement</i> with a <i>Catch</i> occurs within <a
+ href="#sec-strict-mode-code">strict code</a> and the <i>Identifier</i> of the <i>Catch</i> production is <code>eval</code>
+ or <code>arguments</code> (<a href="#sec-try-statement">13.14</a>)</p>
+ </li>
+
+ <li>
+ <p>It is a <b>SyntaxError</b> if the identifier <code>eval</code> or <code>arguments</code> appears within the
+ <i>FormalParameters</i> of a strict mode <i>FunctionDeclaration</i> or <i>FunctionExpression</i> (<a
+ href="#sec-identifiers-static-semantics-early-errors">12.1.1</a>)</p>
+ </li>
+
+ <li>
+ <p>A strict mode function may not have two or more formal parameters that have the same name. An attempt to create such a
+ function using a <i>FunctionDeclaration</i>, <i>FunctionExpression</i>, or <code>Function</code> constructor is a
+ <b>SyntaxError</b> (<a href="#sec-function-definitions">14.1</a>, <a href="#sec-function-constructor">19.2.1</a>).</p>
+ </li>
+
+ <li>
+ <p>An implementation may not extend, beyond that defined in this specification, the meanings within strict mode functions of
+ properties named <code>caller</code> or <code>arguments</code> of function instances. ECMAScript code may not create or
+ modify properties with these names on function objects that correspond to strict mode functions (<a
+ href="#sec-ecmascript-function-objects-getownproperty-p">9.2.1</a>, <a href="#sec-arguments-exotic-objects">9.4.4</a>).</p>
+ </li>
+
+ <li>
+ <p>It is a <b>SyntaxError</b> to use within <a href="#sec-strict-mode-code">strict mode code</a> the identifiers
+ <code>eval</code> or <code>arguments</code> as the <i>Identifier</i> of a <i>FunctionDeclaration</i> or
+ <i>FunctionExpression</i> (<a href="#sec-identifiers-static-semantics-early-errors">12.1.1</a>, <a
+ href="#sec-function-definitions">14.1</a>). Attempting to dynamically define such a strict mode function using the
+ <code>Function</code> constructor (<a href="#sec-function-constructor">19.2.1</a>) will throw a <b>SyntaxError</b>
+ exception.</p>
+ </li>
+ </ul>
+</section>
+
+<section id="sec-corrections-and-clarifications-that-may-introduce-incompatibilities-with-prior-editions">
+ <div class="front">
+ <h1><span class="secnum" id="sec-D"><a
+ href="#sec-corrections-and-clarifications-that-may-introduce-incompatibilities-with-prior-editions"
+ title="link to this section">Annex D</a></span> <span class="section-status">(informative)</span> Corrections and
+ Clarifications That May Introduce Incompatibilities with Prior Editions</h1>
+ </div>
+
+ <section id="sec-corrections-and-clarifications-that-may-introduce-incompatibilities-with-prior-editions-in-the-6th-edition">
+ <h1><span class="secnum" id="sec-D.1"><a
+ href="#sec-corrections-and-clarifications-that-may-introduce-incompatibilities-with-prior-editions-in-the-6th-edition"
+ title="link to this section">D.1</a></span> In the 6<sup>th</sup> Edition</h1>
+
+ <p>9: In Edition 6, Function calls are not allowed to return a <a href="#sec-reference-specification-type">Reference</a>
+ value.</p>
+
+ <p><a href="#sec-iteration-statements">13.6</a>: In Edition 6, a terminating semi-colon is no longer required at the end of a
+ do-while statement.</p>
+
+ <p><a href="#sec-iteration-statements">13.6</a>: Prior to Edition 6, an initialization expression could appear as part of the
+ <i>VariableDeclaration</i> that precedes the <code>in</code> keyword. The value of that expression was always discarded. In
+ Edition 6, the <i>ForBind</i> in that same position does not allow the occurance of such an initializer.</p>
+
+ <p><a href="#sec-try-statement">13.14</a>: In Edition 6, it is an early error for a <span class="nt">Catch</span> clause to
+ contained a <code>var</code> declaration for the same <span class="nt">Identifier</span> that appears as the <span
+ class="nt">Catch</span> clause parameter. In previous editions, such a variable declaration would be instantiated in the
+ enclosing variable environment but the declaration’s <span class="nt">Initializer</span> value would be assigned to the
+ <span class="nt">Catch</span> parameter.</p>
+
+ <p><a href="#sec-method-definitions">14.3</a> In Edition 6, the function objects that are created as the values of the [[Get]]
+ or [[Set]] attribute of accessor properties in an <span class="nt">ObjectLiteral</span> are not constructor functions. In
+ Edition 5, they were constructors.</p>
+
+ <p>0 and <a href="#sec-object.defineproperties">19.1.2.3</a>: In Edition 6, all property additions and changes are processed,
+ even if one of them throws an exception. If an exception occurs during such processing, the first such exception is thrown
+ after all propertie are processed. In Edition 5, processing of property additions and changes immediately terminated when the
+ first exception occurred.</p>
+
+ <p><a href="#sec-object.freeze">19.1.2.5</a>: In Edition 6, if the argument to <code><a
+ href="#sec-object.freeze">Object.freeze</a></code> is not an object it is treated as if it was a non-extensible ordinary
+ object with no own properties. In Edition 5, a non-object argument always causes a <span class="value">TypeError</span> to be
+ thrown.</p>
+
+ <p><a href="#sec-object.getownpropertydescriptor">19.1.2.6</a>: In Edition 6, if the argument to <code><a
+ href="#sec-object.getownpropertydescriptor">Object.getOwnPropertyDescriptor</a></code> is not an object an attempt is make to
+ coerce the argument using <a href="#sec-toobject">ToObject</a>. If the coerecion is successful the result is used in place of
+ the original argument value. In Edition 5, a non-object argument always causes a <span class="value">TypeError</span> to be
+ thrown.</p>
+
+ <p><a href="#sec-object.getownpropertynames">19.1.2.7</a>: In Edition 6, if the argument to <code><a
+ href="#sec-object.getownpropertynames">Object.getOwnPropertyNames</a></code> is not an object an attempt is make to coerce the
+ argument using <a href="#sec-toobject">ToObject</a>. If the coerecion is successful the result is used in place of the
+ original argument value. In Edition 5, a non-object argument always causes a <span class="value">TypeError</span> to be
+ thrown.</p>
+
+ <p><a href="#sec-object.getprototypeof">19.1.2.9</a>: In Edition 6, if the argument to <code><a
+ href="#sec-object.getprototypeof">Object.getPrototypeOf</a></code> is not an object an attempt is make to coerce the argument
+ using <a href="#sec-toobject">ToObject</a>. If the coerecion is successful the result is used in place of the original
+ argument value. In Edition 5, a non-object argument always causes a <b>TypeError</b> to be thrown.</p>
+
+ <p><a href="#sec-object.isextensible">19.1.2.11</a>: In Edition 6, if the argument to <code><a
+ href="#sec-object.isextensible">Object.isExtensible</a></code> is not an object it is treated as if it was a non-extensible
+ ordinary object with no own properties. In Edition 5, a non-object argument always causes a <span
+ class="value">TypeError</span> to be thrown.</p>
+
+ <p><a href="#sec-object.isfrozen">19.1.2.12</a>: In Edition 6, if the argument to <code><a
+ href="#sec-object.isfrozen">Object.isFrozen</a></code> is not an object it is treated as if it was a non-extensible ordinary
+ object with no own properties. In Edition 5, a non-object argument always causes a <span class="value">TypeError</span> to be
+ thrown.</p>
+
+ <p><a href="#sec-object.issealed">19.1.2.13</a>: In Edition 6, if the argument to <code><a
+ href="#sec-object.issealed">Object.isSealed</a></code> is not an object it is treated as if it was a non-extensible ordinary
+ object with no own properties. In Edition 5, a non-object argument always causes a <span class="value">TypeError</span> to be
+ thrown.</p>
+
+ <p><a href="#sec-object.keys">19.1.2.14</a>: In Edition 6, if the argument to <code><a
+ href="#sec-object.keys">Object.keys</a></code> is not an object an attempt is make to coerce the argument using <a
+ href="#sec-toobject">ToObject</a>. If the coerecion is successful the result is used in place of the original argument value.
+ In Edition 5, a non-object argument always causes a <span class="value">TypeError</span> to be thrown.</p>
+
+ <p><a href="#sec-object.preventextensions">19.1.2.15</a>: In Edition 6, if the argument to <code><a
+ href="#sec-object.preventextensions">Object.preventExtensions</a></code> is not an object it is treated as if it was a
+ non-extensible ordinary object with no own properties. In Edition 5, a non-object argument always causes a <span
+ class="value">TypeError</span> to be thrown.</p>
+
+ <p><a href="#sec-object.seal">19.1.2.17</a>: In Edition 6, if the argument to <code><a
+ href="#sec-object.seal">Object.seal</a></code> is not an object it is treated as if it was a non-extensible ordinary object
+ with no own properties. In Edition 5, a non-object argument always causes a <span class="value">TypeError</span> to be
+ thrown.</p>
+
+ <p><a href="#sec-function-instances-length">19.2.4.1</a>: In Edition 6, the <code>length</code> property of function instances
+ is configurable. In previous editions it was non-configurable.</p>
+
+ <p><a href="#sec-properties-of-the-boolean-prototype-object">19.3.3</a> In Edition 6, the Boolean prototype object is not a
+ Boolean instance. In previous editions it was a Boolean instance whose Boolean value was <b>false</b>.</p>
+
+ <p><a href="#sec-properties-of-the-number-prototype-object">20.1.3</a> In Edition 6, the Number prototype object is not a
+ Number instance. In previous editions it was a Number instance whose number value was +0.</p>
+
+ <p><a href="#sec-properties-of-the-date-prototype-object">20.3.4</a> In Edition 6, the Date prototype object is not a Date
+ instance. In previous editions it was a Date instance whose TimeValue was NaN.</p>
+
+ <p><a href="#sec-properties-of-the-array-prototype-object">22.1.3</a> In Edition 6, the Array prototype object is not an Array
+ instance. In previous editions it was an Array instance with a length property whose value was +0.</p>
+
+ <p><a href="#sec-properties-of-the-string-prototype-object">21.1.3</a> In Edition 6, the String prototype object is not a
+ String instance. In previous editions it was a String instance whose String value was the empty string.</p>
+
+ <p><a href="#sec-string.prototype.tolowercase">21.1.3.22</a> and <a href="#sec-string.prototype.touppercase">21.1.3.24</a> In
+ Edition 6, lowercase/upper conversion processing operates on code points. In previous editions such the conversion processing
+ was only applied to individual code units. The only affected code points are those in the Deseret block of Unicode</p>
+
+ <p><a href="#sec-string.prototype.trim">21.1.3.25</a> In Edition 6, the <code><a
+ href="#sec-string.prototype.trim">String.prototype.trim</a></code> method is defined to recognize white space code points that
+ may exists outside of the Unicode BMP. However, as of Unicode 6.1 no such code points are defined. In previous editions such
+ code points would not have been recognized as white space.</p>
+
+ <p><a href="#sec-properties-of-the-regexp-prototype-object">21.2.5</a> In Edition 6, the RegExp prototype object is not a
+ RegExp instance. In previous editions it was a RegExp instance whose pattern is the empty string.</p>
+
+ <p><a href="#sec-properties-of-the-regexp-prototype-object">21.2.5</a> In Edition 6, <code>source</code>, <code>global</code>,
+ <code>ignoreCase</code>, and <code>multiline</code> are accessor properties defined on the RegExp prototype object. In
+ previous editions they were data properties defined on RegExp instances.</p>
+
+ <p><a href="#sec-properties-of-the-array-prototype-object">22.1.3</a> In Edition 6, the Array prototype object is not an Array
+ instance. In previous editions it was an Array instance with a length property whose value was +0.</p>
+ </section>
+
+ <section id="sec-corrections-and-clarifications-that-may-introduce-incompatibilities-with-prior-editions-in-the-5th-edition">
+ <h1><span class="secnum" id="sec-D.2"><a
+ href="#sec-corrections-and-clarifications-that-may-introduce-incompatibilities-with-prior-editions-in-the-5th-edition"
+ title="link to this section">D.2</a></span> In the 5<sup>th</sup> Edition</h1>
+
+ <p>Clause references in this list refer to the clause numbers used in Edition 5 and 5.1.</p>
+
+ <p>7.1: Unicode format control characters are no longer stripped from ECMAScript source text before processing. In Edition 5,
+ if such a character appears in a <span class="nt">StringLiteral</span> or <span class="nt">RegularExpressionLiteral</span> the
+ character will be incorporated into the literal where in Edition 3 the character would not be incorporated into the
+ literal.</p>
+
+ <p>7.2: Unicode character <BOM> is now treated as whitespace and its presence in the middle of what appears to be an
+ identifier could result in a syntax error which would not have occurred in Edition 3</p>
+
+ <p>7.3: Line terminator characters that are preceded by an escape sequence are now allowed within a string literal token. In
+ Edition 3 a syntax error would have been produced.</p>
+
+ <p>7.8.5: Regular expression literals now return a unique object each time the literal is evaluated. This change is detectable
+ by any programs that test the object identity of such literal values or that are sensitive to the shared side effects.</p>
+
+ <p>7.8.5: Edition 5 requires early reporting of any possible RegExp constructor errors that would be produced when converting
+ a <span class="nt">RegularExpressionLiteral</span> to a RegExp object. Prior to Edition 5 implementations were permitted to
+ defer the reporting of such errors until the actual execution time creation of the object.</p>
+
+ <p>7.8.5: In Edition 5 unescaped “/” characters may appear as a <span class="nt">CharacterClass</span> in a
+ regular expression literal. In Edition 3 such a character would have been interpreted as the final character of the
+ literal.</p>
+
+ <p>10.4.2: In Edition 5, indirect calls to the <code>eval</code> function use <a href="#sec-global-environment-records">the
+ global environment</a> as both the variable environment and <a href="#sec-lexical-environments">lexical environment</a> for
+ the eval code. In Edition 3, the variable and lexical environments of the caller of an indirect <code>eval</code> was used as
+ the environments for the eval code.</p>
+
+ <p>15.4.3: In Edition 5 all methods of <code>Array.prototype</code> are intentionally generic. In Edition 3
+ <code>toString</code> and <code>toLocaleString</code> were not generic and would throw a <code>TypeError</code> exception if
+ applied to objects that were not instances of Array.</p>
+
+ <p>10.6: In Edition 5 the array indexed properties of argument objects that correspond to actual formal parameters are
+ enumerable. In Edition 3, such properties were not enumerable.</p>
+
+ <p>10.6: In Edition 5 the value of the [[Class]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>
+ of an arguments object is <code>"Arguments"</code>. In Edition 3, it was <code>"Object"</code>. This is observable if
+ <code>toString</code> is called as a method of an arguments object.</p>
+
+ <p>12.6.4: for-in statements no longer throw a <b>TypeError</b> if the <code>in</code> expression evaluates to <b>null</b> or
+ <b>undefined</b>. Instead, the statement behaves as if the value of the expression was an object with no enumerable
+ properties.</p>
+
+ <p>15: In Edition 5, the following new properties are defined on built-in objects that exist in Edition 3: <code><a
+ href="#sec-object.getprototypeof">Object.getPrototypeOf</a></code>, <code><a
+ href="#sec-object.getownpropertydescriptor">Object.getOwnPropertyDescriptor</a></code>, <code><a
+ href="#sec-object.getownpropertynames">Object.getOwnPropertyNames</a></code>, <b><code><a
+ href="#sec-object.create">Object.create</a></code>,</b> <code><a
+ href="#sec-object.defineproperty">Object.defineProperty</a></code>, <code><a
+ href="#sec-object.defineproperties">Object.defineProperties</a></code>, <code><a
+ href="#sec-object.seal">Object.seal</a></code>, <code><a href="#sec-object.freeze">Object.freeze</a></code>, <code><a
+ href="#sec-object.preventextensions">Object.preventExtensions</a></code>, <code><a
+ href="#sec-object.issealed">Object.isSealed</a></code>, <code><a href="#sec-object.isfrozen">Object.isFrozen</a></code>,
+ <code><a href="#sec-object.isextensible">Object.isExtensible</a></code>, <code><a
+ href="#sec-object.keys">Object.keys</a></code>, <code><a
+ href="#sec-function.prototype.bind">Function.prototype.bind</a></code>, <code><a
+ href="#sec-array.prototype.indexof">Array.prototype.indexOf</a></code>, <code><a
+ href="#sec-array.prototype.lastindexof">Array.prototype.lastIndexOf</a></code>, <code><a
+ href="#sec-array.prototype.every">Array.prototype.every</a></code>, <code><a
+ href="#sec-array.prototype.some">Array.prototype.some</a></code>, <code><a
+ href="#sec-array.prototype.foreach">Array.prototype.forEach</a></code>, <code><a
+ href="#sec-array.prototype.map">Array.prototype.map</a></code>, <code><a
+ href="#sec-array.prototype.filter">Array.prototype.filter</a></code>, <code><a
+ href="#sec-array.prototype.reduce">Array.prototype.reduce</a></code>, <code><a
+ href="#sec-array.prototype.reduceright">Array.prototype.reduceRight</a></code>, <code><a
+ href="#sec-string.prototype.trim">String.prototype.trim</a></code>, <code><a href="#sec-date.now">Date.now</a></code>,
+ <code><a href="#sec-date.prototype.toisostring">Date.prototype.toISOString</a>, <a
+ href="#sec-date.prototype.tojson">Date.prototype.toJSON</a></code>.</p>
+
+ <p>15: Implementations are now required to ignore extra arguments to standard built-in methods unless otherwise explicitly
+ specified. In Edition 3 the handling of extra arguments was unspecified and implementations were explicitly allowed to throw a
+ <b>TypeError</b> exception.</p>
+
+ <p>15.1.1: The value properties <b>NaN</b>, <b>Infinity</b>, and <b>undefined</b> of the Global Object have been changed to be
+ read-only properties.</p>
+
+ <p>15.1.2.1. Implementations are no longer permitted to restrict the use of eval in ways that are not a direct call. In
+ addition, any invocation of eval that is not a direct call uses <a href="#sec-global-environment-records">the global
+ environment</a> as its variable environment rather than the caller’s variable environment.</p>
+
+ <p>15.1.2.2: The specification of the function <code>parseInt</code> no longer allows implementations to treat Strings
+ beginning with a <code>0</code> character as octal values.</p>
+
+ <p>15.3.3.3: In Edition 3, a <b>TypeError</b> is thrown if the second argument passed to <code><a
+ href="#sec-function.prototype.apply">Function.prototype.apply</a></code> is neither an array object nor an arguments object.
+ In Edition 5, the second argument may be any kind of generic array-like object that has a valid <code>length</code>
+ property.</p>
+
+ <p>15.3.3.3, 15.3.3.4: In Edition 3 passing <b>undefined</b> or <b>null</b> as the first argument to either <code><a
+ href="#sec-function.prototype.apply">Function.prototype.apply</a></code> or <code><a
+ href="#sec-function.prototype.call">Function.prototype.call</a></code> causes the global object to be passed to the indirectly
+ invoked target function as the <b>this</b> value. If the first argument is a primitive value the result of calling <a
+ href="#sec-toobject">ToObject</a> on the primitive value is passed as the <b>this</b> value. In Edition 5, these
+ transformations are not performed and the actual first argument value is passed as the <b>this</b> value. This difference will
+ normally be unobservable to existing ECMAScript Edition 3 code because a corresponding transformation takes place upon
+ activation of the target function. However, depending upon the implementation, this difference may be observable by host
+ object functions called using <code>apply</code> or <code>call</code>. In addition, invoking a standard built-in function in
+ this manner with <b>null</b> or <b>undefined</b> passed as the <b>this</b> value will in many cases cause behaviour in Edition
+ 5 implementations that differ from Edition 3 behaviour. In particular, in Edition 5 built-in functions that are specified to
+ actually use the passed <b>this</b> value as an object typically throw a <b>TypeError</b> exception if passed <b>null</b> or
+ <b>undefined</b> as the <b>this</b> value.</p>
+
+ <p>15.3.4.2: In Edition 5, the <code>prototype</code> property of Function instances is not enumerable. In Edition 3, this
+ property was enumerable.</p>
+
+ <p>15.5.5.2: In Edition 5, the individual characters of a String object’s [[StringData]] may be accessed as array
+ indexed properties of the String object. These properties are non-writable and non-configurable and shadow any inherited
+ properties with the same names. In Edition 3, these properties did not exist and ECMAScript code could dynamically add and
+ remove writable properties with such names and could access inherited properties with such names.</p>
+
+ <p>15.9.4.2: <code><a href="#sec-date.parse">Date.parse</a></code> is now required to first attempt to parse its argument as
+ an ISO format string. Programs that use this format but depended upon implementation specific behaviour (including failure)
+ may behave differently.</p>
+
+ <p>15.10.2.12: In Edition 5, <code>\s</code> now additionally matches <BOM>.</p>
+
+ <p>15.10.4.1: In Edition 3, the exact form of the String value of the <code>source</code> property of an object created by the
+ <code>RegExp</code> constructor is implementation defined. In Edition 5, the String must conform to certain specified
+ requirements and hence may be different from that produced by an Edition 3 implementation.</p>
+
+ <p>15.10.6.4: In Edition 3, the result of <code><a href="#sec-regexp.prototype.tostring">RegExp.prototype.toString</a></code>
+ need not be derived from the value of the RegExp object’s <code>source</code> property. In Edition 5 the result must be
+ derived from the <code>source</code> property in a specified manner and hence may be different from the result produced by an
+ Edition 3 implementation.</p>
+
+ <p>15.11.2.1, 15.11.4.3: In Edition 5, if an initial value for the <code>message</code> property of an Error object is not
+ specified via the <code>Error</code> constructor the initial value of the property is the empty String. In Edition 3, such an
+ initial value is implementation defined.</p>
+
+ <p>15.11.4.4: In Edition 3, the result of <code><a href="#sec-error.prototype.tostring">Error.prototype.toString</a></code>
+ is implementation defined. In Edition 5, the result is fully specified and hence may differ from some Edition 3
+ implementations.</p>
+
+ <p>15.12: In Edition 5, the name <code>JSON</code> is defined in <a href="#sec-global-environment-records">the global
+ environment</a>. In Edition 3, testing for the presence of that name will show it to be <b>undefined</b> unless it is defined
+ by the program or implementation.</p>
+ </section>
+</section>
+
+<section id="sec-additions-and-changes-that-introduce-incompatibilities-with-prior-editions">
+ <div class="front">
+ <h1><span class="secnum" id="sec-E"><a href="#sec-additions-and-changes-that-introduce-incompatibilities-with-prior-editions"
+ title="link to this section">Annex E</a></span> <span class="section-status">(informative)</span> Additions and
+ Changes that Introduce Incompatibilities with Prior Editions</h1>
+ </div>
+
+ <section id="sec-additions-and-changes-that-introduce-incompatibilities-with-prior-editions-in-the-6th-edition">
+ <h1><span class="secnum" id="sec-E.1"><a
+ href="#sec-additions-and-changes-that-introduce-incompatibilities-with-prior-editions-in-the-6th-edition"
+ title="link to this section">E.1</a></span> In the 6<sup>th</sup> Edition</h1>
+
+ <p>9: In Edition 6, Function calls are not allowed to return a <a href="#sec-reference-specification-type">Reference</a>
+ value.</p>
+
+ <p><a href="#sec-iteration-statements">13.6</a>: In Edition 6, a terminating semi-colon is no longer required at the end of a
+ do-while statement.</p>
+
+ <p><a href="#sec-iteration-statements">13.6</a>: Prior to Edition 6, an initialization expression could appear as part of the
+ <i>VariableDeclaration</i> that precedes the <code>in</code> keyword. The value of that expression was always discarded. In
+ Edition 6, the <i>ForBind</i> in that same position does not allow the occurrence of such an initializer.</p>
+
+ <p><a href="#sec-try-statement">13.14</a>: In Edition 6, it is an early error for a <span class="nt">Catch</span> clause to
+ contain a <code>var</code> declaration for the same <span class="nt">Identifier</span> that appears as the <span
+ class="nt">Catch</span> clause parameter. In previous editions, such a variable declaration would be instantiated in the
+ enclosing variable environment but the declaration’s <span class="nt">Initializer</span> value would be assigned to the
+ <span class="nt">Catch</span> parameter.</p>
+
+ <p><a href="#sec-method-definitions">14.3</a> In Edition 6, the function objects that are created as the values of the [[Get]]
+ or [[Set]] attribute of accessor properties in an <span class="nt">ObjectLiteral</span> are not constructor functions. In
+ Edition 5, they were constructors.</p>
+
+ <p>0 and <a href="#sec-object.defineproperties">19.1.2.3</a>: In Edition 6, all property additions and changes are processed,
+ even if one of them throws an exception. If an exception occurs during such processing, the first such exception is thrown
+ after all properties are processed. In Edition 5, processing of property additions and changes immediately terminated when the
+ first exception occurred.</p>
+
+ <p><a href="#sec-object.freeze">19.1.2.5</a>: In Edition 6, if the argument to <code><a
+ href="#sec-object.freeze">Object.freeze</a></code> is not an object it is treated as if it was a non-extensible ordinary
+ object with no own properties. In Edition 5, a non-object argument always causes a <span class="value">TypeError</span> to be
+ thrown.</p>
+
+ <p><a href="#sec-object.getownpropertydescriptor">19.1.2.6</a>: In Edition 6, if the argument to <code><a
+ href="#sec-object.getownpropertydescriptor">Object.getOwnPropertyDescriptor</a></code> is not an object an attempt is made to
+ coerce the argument using <a href="#sec-toobject">ToObject</a>. If the coerecion is successful the result is used in place of
+ the original argument value. In Edition 5, a non-object argument always causes a <span class="value">TypeError</span> to be
+ thrown.</p>
+
+ <p><a href="#sec-object.getownpropertynames">19.1.2.7</a>: In Edition 6, if the argument to <code><a
+ href="#sec-object.getownpropertynames">Object.getOwnPropertyNames</a></code> is not an object an attempt is made to coerce the
+ argument using <a href="#sec-toobject">ToObject</a>. If the coercion is successful the result is used in place of the
+ original argument value. In Edition 5, a non-object argument always causes a <span class="value">TypeError</span> to be
+ thrown.</p>
+
+ <p><a href="#sec-object.getprototypeof">19.1.2.9</a>: In Edition 6, if the argument to <code><a
+ href="#sec-object.getprototypeof">Object.getPrototypeOf</a></code> is not an object an attempt is made to coerce the argument
+ using <a href="#sec-toobject">ToObject</a>. If the coercion is successful the result is used in place of the original
+ argument value. In Edition 5, a non-object argument always causes a <b>TypeError</b> to be thrown.</p>
+
+ <p><a href="#sec-object.isextensible">19.1.2.11</a>: In Edition 6, if the argument to <code><a
+ href="#sec-object.isextensible">Object.isExtensible</a></code> is not an object it is treated as if it was a non-extensible
+ ordinary object with no own properties. In Edition 5, a non-object argument always causes a <span
+ class="value">TypeError</span> to be thrown.</p>
+
+ <p><a href="#sec-object.isfrozen">19.1.2.12</a>: In Edition 6, if the argument to <code><a
+ href="#sec-object.isfrozen">Object.isFrozen</a></code> is not an object it is treated as if it was a non-extensible ordinary
+ object with no own properties. In Edition 5, a non-object argument always causes a <span class="value">TypeError</span> to be
+ thrown.</p>
+
+ <p><a href="#sec-object.issealed">19.1.2.13</a>: In Edition 6, if the argument to <code><a
+ href="#sec-object.issealed">Object.isSealed</a></code> is not an object it is treated as if it was a non-extensible ordinary
+ object with no own properties. In Edition 5, a non-object argument always causes a <span class="value">TypeError</span> to be
+ thrown.</p>
+
+ <p><a href="#sec-object.keys">19.1.2.14</a>: In Edition 6, if the argument to <code><a
+ href="#sec-object.keys">Object.keys</a></code> is not an object an attempt is make to coerce the argument using <a
+ href="#sec-toobject">ToObject</a>. If the coerecion is successful the result is used in place of the original argument value.
+ In Edition 5, a non-object argument always causes a <span class="value">TypeError</span> to be thrown.</p>
+
+ <p><a href="#sec-object.preventextensions">19.1.2.15</a>: In Edition 6, if the argument to <code><a
+ href="#sec-object.preventextensions">Object.preventExtensions</a></code> is not an object it is treated as if it was a
+ non-extensible ordinary object with no own properties. In Edition 5, a non-object argument always causes a <span
+ class="value">TypeError</span> to be thrown.</p>
+
+ <p><a href="#sec-object.seal">19.1.2.17</a>: In Edition 6, if the argument to <code><a
+ href="#sec-object.seal">Object.seal</a></code> is not an object it is treated as if it was a non-extensible ordinary object
+ with no own properties. In Edition 5, a non-object argument always causes a <span class="value">TypeError</span> to be
+ thrown.</p>
+
+ <p><a href="#sec-function-instances-length">19.2.4.1</a>: In Edition 6, the <code>length</code> property of function instances
+ is configurable. In previous editions it was non-configurable.</p>
+
+ <p><a href="#sec-properties-of-the-boolean-prototype-object">19.3.3</a> In Edition 6, the Boolean prototype object is not a
+ Boolean instance. In previous editions it was a Boolean instance whose Boolean value was <b>false</b>.</p>
+
+ <p><a href="#sec-properties-of-the-number-prototype-object">20.1.3</a> In Edition 6, the Number prototype object is not a
+ Number instance. In previous editions it was a Number instance whose number value was +0.</p>
+
+ <p><a href="#sec-properties-of-the-date-prototype-object">20.3.4</a> In Edition 6, the Date prototype object is not a Date
+ instance. In previous editions it was a Date instance whose TimeValue was NaN.</p>
+
+ <p><a href="#sec-properties-of-the-array-prototype-object">22.1.3</a> In Edition 6, the Array prototype object is not an Array
+ instance. In previous editions it was an Array instance with a length property whose value was +0.</p>
+
+ <p><a href="#sec-properties-of-the-string-prototype-object">21.1.3</a> In Edition 6, the String prototype object is not a
+ String instance. In previous editions it was a String instance whose String value was the empty string.</p>
+
+ <p><a href="#sec-string.prototype.tolowercase">21.1.3.22</a> and <a href="#sec-string.prototype.touppercase">21.1.3.24</a> In
+ Edition 6, lowercase/upper conversion processing operates on code points. In previous editions such the conversion processing
+ was only applied to individual code units. The only affected code points are those in the Deseret block of Unicode</p>
+
+ <p><a href="#sec-string.prototype.trim">21.1.3.25</a> In Edition 6, the <code><a
+ href="#sec-string.prototype.trim">String.prototype.trim</a></code> method is defined to recognize white space code points that
+ may exists outside of the Unicode BMP. However, as of Unicode 6.1 no such code points are defined. In previous editions such
+ code points would not have been recognized as white space.</p>
+
+ <p><a href="#sec-properties-of-the-regexp-prototype-object">21.2.5</a> In Edition 6, the RegExp prototype object is not a
+ RegExp instance. In previous editions it was a RegExp instance whose pattern is the empty string.</p>
+
+ <p><a href="#sec-properties-of-the-regexp-prototype-object">21.2.5</a> In Edition 6, <code>source</code>, <code>global</code>,
+ <code>ignoreCase</code>, and <code>multiline</code> are accessor properties defined on the RegExp prototype object. In
+ previous editions they were data properties defined on RegExp instances.</p>
+
+ <p><a href="#sec-properties-of-the-array-prototype-object">22.1.3</a> In Edition 6, the Array prototype object is not an Array
+ instance. In previous editions it was an Array instance with a length property whose value was +0.</p>
+ </section>
+
+ <section id="sec-additions-and-changes-that-introduce-incompatibilities-with-prior-editions-in-the-5th-edition">
+ <h1><span class="secnum" id="sec-E.2"><a
+ href="#sec-additions-and-changes-that-introduce-incompatibilities-with-prior-editions-in-the-5th-edition"
+ title="link to this section">E.2</a></span> In the 5<sup>th</sup> Edition</h1>
+
+ <p>Clause references in this list refer to the clause numbers used in Edition 5 and 5.1.</p>
+
+ <p>7.1: Unicode format control characters are no longer stripped from ECMAScript source text before processing. In Edition 5,
+ if such a character appears in a <span class="nt">StringLiteral</span> or <span class="nt">RegularExpressionLiteral</span> the
+ character will be incorporated into the literal where in Edition 3 the character would not be incorporated into the
+ literal.</p>
+
+ <p>7.2: Unicode character <BOM> is now treated as whitespace and its presence in the middle of what appears to be an
+ identifier could result in a syntax error which would not have occurred in Edition 3</p>
+
+ <p>7.3: Line terminator characters that are preceded by an escape sequence are now allowed within a string literal token. In
+ Edition 3 a syntax error would have been produced.</p>
+
+ <p>7.8.5: Regular expression literals now return a unique object each time the literal is evaluated. This change is detectable
+ by any programs that test the object identity of such literal values or that are sensitive to the shared side effects.</p>
+
+ <p>7.8.5: Edition 5 requires early reporting of any possible RegExp constructor errors that would be produced when converting
+ a <span class="nt">RegularExpressionLiteral</span> to a RegExp object. Prior to Edition 5 implementations were permitted to
+ defer the reporting of such errors until the actual execution time creation of the object.</p>
+
+ <p>7.8.5: In Edition 5 unescaped “/” characters may appear as a <span class="nt">CharacterClass</span> in a
+ regular expression literal. In Edition 3 such a character would have been interpreted as the final character of the
+ literal.</p>
+
+ <p>10.4.2: In Edition 5, indirect calls to the <code>eval</code> function use <a href="#sec-global-environment-records">the
+ global environment</a> as both the variable environment and <a href="#sec-lexical-environments">lexical environment</a> for
+ the eval code. In Edition 3, the variable and lexical environments of the caller of an indirect <code>eval</code> were used
+ as the environments for the eval code.</p>
+
+ <p>15.4.3: In Edition 5 all methods of <code>Array.prototype</code> are intentionally generic. In Edition 3
+ <code>toString</code> and <code>toLocaleString</code> were not generic and would throw a <code>TypeError</code> exception if
+ applied to objects that were not instances of Array.</p>
+
+ <p>10.6: In Edition 5 the array indexed properties of argument objects that correspond to actual formal parameters are
+ enumerable. In Edition 3, such properties were not enumerable.</p>
+
+ <p>10.6: In Edition 5 the value of the [[Class]] <a href="#sec-object-internal-methods-and-internal-slots">internal slot</a>
+ of an arguments object is <code>"Arguments"</code>. In Edition 3, it was <code>"Object"</code>. This is observable if
+ <code>toString</code> is called as a method of an arguments object.</p>
+
+ <p>12.6.4: for-in statements no longer throw a <b>TypeError</b> if the <code>in</code> expression evaluates to <b>null</b> or
+ <b>undefined</b>. Instead, the statement behaves as if the value of the expression was an object with no enumerable
+ properties.</p>
+
+ <p>15: In Edition 5, the following new properties are defined on built-in objects that exist in Edition 3: <code><a
+ href="#sec-object.getprototypeof">Object.getPrototypeOf</a></code>, <code><a
+ href="#sec-object.getownpropertydescriptor">Object.getOwnPropertyDescriptor</a></code>, <code><a
+ href="#sec-object.getownpropertynames">Object.getOwnPropertyNames</a></code>, <b><code><a
+ href="#sec-object.create">Object.create</a></code>,</b> <code><a
+ href="#sec-object.defineproperty">Object.defineProperty</a></code>, <code><a
+ href="#sec-object.defineproperties">Object.defineProperties</a></code>, <code><a
+ href="#sec-object.seal">Object.seal</a></code>, <code><a href="#sec-object.freeze">Object.freeze</a></code>, <code><a
+ href="#sec-object.preventextensions">Object.preventExtensions</a></code>, <code><a
+ href="#sec-object.issealed">Object.isSealed</a></code>, <code><a href="#sec-object.isfrozen">Object.isFrozen</a></code>,
+ <code><a href="#sec-object.isextensible">Object.isExtensible</a></code>, <code><a
+ href="#sec-object.keys">Object.keys</a></code>, <code><a
+ href="#sec-function.prototype.bind">Function.prototype.bind</a></code>, <code><a
+ href="#sec-array.prototype.indexof">Array.prototype.indexOf</a></code>, <code><a
+ href="#sec-array.prototype.lastindexof">Array.prototype.lastIndexOf</a></code>, <code><a
+ href="#sec-array.prototype.every">Array.prototype.every</a></code>, <code><a
+ href="#sec-array.prototype.some">Array.prototype.some</a></code>, <code><a
+ href="#sec-array.prototype.foreach">Array.prototype.forEach</a></code>, <code><a
+ href="#sec-array.prototype.map">Array.prototype.map</a></code>, <code><a
+ href="#sec-array.prototype.filter">Array.prototype.filter</a></code>, <code><a
+ href="#sec-array.prototype.reduce">Array.prototype.reduce</a></code>, <code><a
+ href="#sec-array.prototype.reduceright">Array.prototype.reduceRight</a></code>, <code><a
+ href="#sec-string.prototype.trim">String.prototype.trim</a></code>, <code><a href="#sec-date.now">Date.now</a></code>,
+ <code><a href="#sec-date.prototype.toisostring">Date.prototype.toISOString</a>, <a
+ href="#sec-date.prototype.tojson">Date.prototype.toJSON</a></code>.</p>
+
+ <p>15: Implementations are now required to ignore extra arguments to standard built-in methods unless otherwise explicitly
+ specified. In Edition 3 the handling of extra arguments was unspecified and implementations were explicitly allowed to throw a
+ <b>TypeError</b> exception.</p>
+
+ <p>15.1.1: The value properties <b>NaN</b>, <b>Infinity</b>, and <b>undefined</b> of the Global Object have been changed to be
+ read-only properties.</p>
+
+ <p>15.1.2.1. Implementations are no longer permitted to restrict the use of eval in ways that are not a direct call. In
+ addition, any invocation of eval that is not a direct call uses <a href="#sec-global-environment-records">the global
+ environment</a> as its variable environment rather than the caller’s variable environment.</p>
+
+ <p>15.1.2.2: The specification of the function <code>parseInt</code> no longer allows implementations to treat Strings
+ beginning with a <code>0</code> character as octal values.</p>
+
+ <p>15.3.3.3: In Edition 3, a <b>TypeError</b> is thrown if the second argument passed to <code><a
+ href="#sec-function.prototype.apply">Function.prototype.apply</a></code> is neither an array object nor an arguments object.
+ In Edition 5, the second argument may be any kind of generic array-like object that has a valid <code>length</code>
+ property.</p>
+
+ <p>15.3.3.3, 15.3.3.4: In Edition 3 passing <b>undefined</b> or <b>null</b> as the first argument to either <code><a
+ href="#sec-function.prototype.apply">Function.prototype.apply</a></code> or <code><a
+ href="#sec-function.prototype.call">Function.prototype.call</a></code> causes the global object to be passed to the indirectly
+ invoked target function as the <b>this</b> value. If the first argument is a primitive value the result of calling <a
+ href="#sec-toobject">ToObject</a> on the primitive value is passed as the <b>this</b> value. In Edition 5, these
+ transformations are not performed and the actual first argument value is passed as the <b>this</b> value. This difference will
+ normally be unobservable to existing ECMAScript Edition 3 code because a corresponding transformation takes place upon
+ activation of the target function. However, depending upon the implementation, this difference may be observable by host
+ object functions called using <code>apply</code> or <code>call</code>. In addition, invoking a standard built-in function in
+ this manner with <b>null</b> or <b>undefined</b> passed as the <b>this</b> value will in many cases cause behaviour in Edition
+ 5 implementations that differ from Edition 3 behaviour. In particular, in Edition 5 built-in functions that are specified to
+ actually use the passed <b>this</b> value as an object typically throw a <b>TypeError</b> exception if passed <b>null</b> or
+ <b>undefined</b> as the <b>this</b> value.</p>
+
+ <p>15.3.4.2: In Edition 5, the <code>prototype</code> property of Function instances is not enumerable. In Edition 3, this
+ property was enumerable.</p>
+
+ <p>15.5.5.2: In Edition 5, the individual characters of a String object’s [[StringData]] may be accessed as array
+ indexed properties of the String object. These properties are non-writable and non-configurable and shadow any inherited
+ properties with the same names. In Edition 3, these properties did not exist and ECMAScript code could dynamically add and
+ remove writable properties with such names and could access inherited properties with such names.</p>
+
+ <p>15.9.4.2: <code><a href="#sec-date.parse">Date.parse</a></code> is now required to first attempt to parse its argument as
+ an ISO format string. Programs that use this format but depended upon implementation specific behaviour (including failure)
+ may behave differently.</p>
+
+ <p>15.10.2.12: In Edition 5, <code>\s</code> now additionally matches <BOM>.</p>
+
+ <p>15.10.4.1: In Edition 3, the exact form of the String value of the <code>source</code> property of an object created by the
+ <code>RegExp</code> constructor is implementation defined. In Edition 5, the String must conform to certain specified
+ requirements and hence may be different from that produced by an Edition 3 implementation.</p>
+
+ <p>15.10.6.4: In Edition 3, the result of <code><a href="#sec-regexp.prototype.tostring">RegExp.prototype.toString</a></code>
+ need not be derived from the value of the RegExp object’s <code>source</code> property. In Edition 5 the result must be
+ derived from the <code>source</code> property in a specified manner and hence may be different from the result produced by an
+ Edition 3 implementation.</p>
+
+ <p>15.11.2.1, 15.11.4.3: In Edition 5, if an initial value for the <code>message</code> property of an Error object is not
+ specified via the <code>Error</code> constructor the initial value of the property is the empty String. In Edition 3, such an
+ initial value is implementation defined.</p>
+
+ <p>15.11.4.4: In Edition 3, the result of <code><a href="#sec-error.prototype.tostring">Error.prototype.toString</a></code>
+ is implementation defined. In Edition 5, the result is fully specified and hence may differ from some Edition 3
+ implementations.</p>
+
+ <p>15.12: In Edition 5, the name <code>JSON</code> is defined in <a href="#sec-global-environment-records">the global
+ environment</a>. In Edition 3, testing for the presence of that name will show it to be <b>undefined</b> unless it is defined
+ by the program or implementation.</p>
+ </section>
+</section>
+
+<section>
+ <h1>Bibliography</h1>
+
+ <p><span class="marker">[1]	</span>ISO 8601:2004(E) <i>Data elements and interchange formats – Information
+ interchange</i> <span style="font-family: Times New Roman">—</span> <i>Representation of dates and times</i></p>
+
+ <p><span class="marker">[2]	</span>RFC 1738 “Uniform Resource Locators (URL)”, available at
+ <http://tools.ietf.org/html/rfc1738></p>
+
+ <p><span class="marker">[3]	</span>RFC 2396 “Uniform Resource Identifiers (URI): Generic Syntax”, available at
+ <http://tools.ietf.org/html/rfc2396></p>
+
+ <p><span class="marker">[4]	</span>RFC 3629 “UTF-8, a transformation format of ISO 10646”, available at
+ <http://tools.ietf.org/html/rfc3629></p>
+
+ <p><span class="marker">[5]	</span>RFC 4627 “The application/json Media Type for JavaScript Object Notation
+ (JSON)” , available at <http://tools.ietf.org/html/rfc4627></p>
+
+ <p><span class="marker">[6]	</span>Unicode Inc. (2010), Unicode Technical Report #15: “Unicode Normalization
+ Forms”, available at <http://www.unicode.org/reports/tr15/tr15-29.html></p>
+
+ <p></p>
+</section>
+</body>
+</html>