ECMAScript 4 Netscape Proposal
Formal Description
Syntactic Semantics
|
|
Monday, June 30, 2003
The syntactic semantics describe the actions the parser takes to evaluate an ECMAScript 4 program. For convenience, the syntactic
grammar is repeated here. The starting nonterminal is Program. See also the
description of the semantic notation.
The semantics are under construction. Many execution paths resulting in ???? represent semantics yet to be implemented.
This document is also available as a Word RTF file.
Terminals
General tokens: Identifier NegatedMinLong
Number RegularExpression String
VirtualSemicolon
Punctuation tokens: !
!=
!==
%
%=
&
&&
&&=
&=
(
)
*
*=
+
++
+=
,
-
--
-=
.
...
/
/=
:
::
;
<
<<
<<=
<=
=
==
===
>
>=
>>
>>=
>>>
>>>=
?
[
]
^
^=
^^
^^=
{
|
|=
||
||=
}
~
Reserved words: as
break
case
catch
class
const
continue
default
delete
do
else
extends
false
finally
for
function
if
import
in
instanceof
is
namespace
new
null
package
private
public
return
super
switch
this
throw
true
try
typeof
use
var
void
while
with
Future reserved words: abstract
debugger
enum
export
goto
implements
interface
native
protected
synchronized
throws
transient
volatile
Non-reserved words: get
set
Data Model
Semantic Exceptions
Extended integers and rationals
Objects
Undefined
Null
Strings
Namespaces
Qualified Names
The notation
ns::
id is a shorthand for
QualifiedNamenamespace:
ns,
id:
id.
Attributes
Classes
Simple Instances
Slots
Uninstantiated Functions
record UninstantiatedFunction
end record;
Method Closures
Dates
Regular Expressions
Packages
Objects with Limits
References
Modes of expression evaluation
Contexts
Labels
Function Support
Environments
Properties
Miscellaneous
Data Operations
Numeric Utilities
proc unsignedWrap32(
i:
Integer): {0 ... 2
32 – 1}
end proc;
proc signedWrap32(
i:
Integer): {–2
31 ... 2
31 – 1}
if j 231 then j j – 232 end if;
return j
end proc;
proc unsignedWrap64(
i:
Integer): {0 ... 2
64 – 1}
end proc;
proc signedWrap64(
i:
Integer): {–2
63 ... 2
63 – 1}
if j 263 then j j – 264 end if;
return j
end proc;
case x of
{NaNf32, NaNf64, +f32, +f64, –f32, –f64} do return 0;
end case
end proc;
case i of
if j > limit then j limit end if;
if negativeFromEnd and j < 0 then j j + limit end if;
if j < 0 then j 0 end if;
note 0 j limit;
return j
end case
end proc;
case x of
{
NaNf32,
NaNf64,
+f32,
+f64,
–f32,
–f64}
do return none;
{+zerof32, +zerof64, –zerof32, –zerof64} do return 0;
end case
end proc;
if –263 i 263 – 1 then return ilong
elsif 263 i 264 – 1 then return iulong
else return if64
end if
end proc;
if 0 i 264 – 1 then return iulong
elsif –263 i –1 then return ilong
else return if64
end if
end proc;
elsif |q| 253 then return qf64
elsif q < –263 – 1/2 or q 264 – 1/2 then return qf64
else
Let i be the integer closest to q. If q is halfway between
two integers, pick i so that it is even.
note –263 i 264 – 1;
if i < 263 then return ilong else return iulong end if
end if
end proc;
elsif |q| 253 then return qf64
elsif q < –263 – 1/2 or q 264 – 1/2 then return qf64
else
Let i be the integer closest to q. If q is halfway between
two integers, pick i so that it is even.
note –263 i 264 – 1;
if i 0 then return iulong else return ilong end if
end if
end proc;
case q of
{
+zero}
do return +zerof32;
{
–zero}
do return –zerof32;
end case
end proc;
case q of
{
+zero}
do return +zerof64;
{
–zero}
do return –zerof64;
end case
end proc;
case x of
{+zerof32, +zerof64, –zerof32, –zerof64} do return 0;
end case
end proc;
case x of
{–f64} do return –f32;
{–zerof64} do return –zerof32;
{+zerof64} do return +zerof32;
{+f64} do return +f32;
{NaNf64} do return NaNf32;
end case
end proc;
if x {
NaNf32,
NaNf64}
or y {
NaNf32,
NaNf64}
then return unordered
elsif x {
+f32,
+f64}
and y {
+f32,
+f64}
then return equal
elsif x {
–f32,
–f64}
and y {
–f32,
–f64}
then return equal
elsif x {
+f32,
+f64}
or y {
–f32,
–f64}
then return greater
elsif x {
–f32,
–f64}
or y {
+f32,
+f64}
then return less
else
if xr <
yr then return less
end if
end if
end proc;
Character Utilities
proc integerToUTF16(
i: {0 ... 0x10FFFF}):
String
else
j: {0 ... 0xFFFFF} i – 0x10000;
return [high, low]
end if
end proc;
while i |s| do
if s[i] {‘«uD800»
’ ... ‘«uDBFF»
’} and
i + 1 |s| and
s[i + 1] {‘«uDC00»
’ ... ‘«uDFFF»
’} then
else ch s[i]; i i + 1
end if;
result result [ch]
end while;
return result
end proc;
return ch converted to a lower case character
using the Unicode full, locale-independent case mapping. A single character may be converted to multiple
characters. If
ch has no lower case equivalent, then the result is the string
char21ToUTF16(
ch).
end proc;
return ch converted to a lower case character
using the Unicode full case mapping in the host environment’s current locale. A single character may be
converted to multiple characters. If
ch has no lower case equivalent, then the result is the string
char21ToUTF16(
ch).
end proc;
return ch converted to a upper case character
using the Unicode full, locale-independent case mapping. A single character may be converted to multiple
characters. If
ch has no upper case equivalent, then the result is the string
char21ToUTF16(
ch).
end proc;
return ch converted to a upper case character
using the Unicode full case mapping in the host environment’s current locale. A single character may be
converted to multiple characters. If
ch has no upper case equivalent, then the result is the string
char21ToUTF16(
ch).
end proc;
Object Utilities
Object Class Inquiries
if c = d then return true
else
if s =
none then return false end if;
end if
end proc;
Object to Boolean Conversion
case o of
Float32 do return o {
+zerof32,
–zerof32,
NaNf32};
Float64 do return o {
+zerof64,
–zerof64,
NaNf64};
end case
end proc;
Object to Primitive Conversion
case h of
if toStringMethod none then
end if;
if valueOfMethod none then
end if;
if valueOfMethod none then
end if;
if toStringMethod none then
end if
end case;
throw a
TypeError exception
— cannot convert this object to a primitive
end proc;
Object to Number Conversions
case a of
Null {
false}
do return +zerof64;
{true} do return 1f64;
end case
end proc;
case a of
Null {
false}
do return +zerof32;
{true} do return 1f32;
end case
end proc;
case a of
Null {
false}
do return 0;
{true} do return 1;
{
+f32,
+f64}
do return +;
{
–f32,
–f64}
do return –;
{+zerof32, +zerof64, –zerof32, –zerof64} do return 0;
throw a
RangeError exception
— the value
a is not an integer
end if;
return r;
end case
end proc;
Apply the lexer grammar with the start symbol
StringNumericLiteral to the string
s.
throw a
TypeError exception
— the string
s does not contain a number
else
end if
end proc;
Object to String Conversions
case a of
{false} do return “false
”;
{true} do return “true
”;
end case
end proc;
if |digits| = 1 then mantissa digits
else mantissa [digits[0]] “.
” digits[1 ...]
end if;
end proc;
case x of
{NaNf32} do return “NaN
”;
{+zerof32, –zerof32} do return “0
”;
{+f32} do return “Infinity
”;
{–f32} do return “-Infinity
”;
else
Let e, k, and s be integers such that k
1, 10k–1
s
10k,
(s10e+1–k)f32
= x, and k is as small as possible.
note k is the number of digits in
the decimal representation of s, s is not divisible by 10, and the least significant
digit of s is not necessarily uniquely determined by the above criteria.
When there are multiple possibilities for s according to the rules above,
implementations are encouraged but not required to select the one according to the following rule: Select
the value of s for which
s10e+1–k
is closest in value to r; if there are two such possible values of s, choose the one
that is even.
if k – 1
e 20
then return digits repeat(‘
0
’,
e + 1 –
k)
elsif 0 e 20 then return digits[0 ... e] “.
” digits[e + 1 ...]
elsif –6
e < 0
then return “
0.
”
repeat(‘
0
’, –(
e + 1))
digits
end if
end if
end case
end proc;
case x of
{NaNf64} do return “NaN
”;
{+zerof64, –zerof64} do return “0
”;
{+f64} do return “Infinity
”;
{–f64} do return “-Infinity
”;
else
Let e, k, and s be integers such that k
1, 10k–1
s
10k,
(s10e+1–k)f64
= x, and k is as small as possible.
note k is the number of digits in
the decimal representation of s, s is not divisible by 10, and the least significant
digit of s is not necessarily uniquely determined by the above criteria.
When there are multiple possibilities for s according to the rules above,
implementations are encouraged but not required to select the one according to the following rule: Select
the value of s for which
s10e+1–k
is closest in value to r; if there are two such possible values of s, choose the one
that is even.
if k – 1
e 20
then return digits repeat(‘
0
’,
e + 1 –
k)
elsif 0 e 20 then return digits[0 ... e] “.
” digits[e + 1 ...]
elsif –6
e < 0
then return “
0.
”
repeat(‘
0
’, –(
e + 1))
digits
end if
end if
end case
end proc;
Object to Qualified Name Conversion
Object to Class Conversion
Object to Attribute Conversion
else
note If o is not an attribute, try to
call it with no arguments.
end if
end proc;
Implicit Coercions
if result none then return result
else throw a
TypeError exception
— coercion failed
end if
end proc;
if result none then return result
else throw a
TypeError exception
— coercion failed
end if
end proc;
if result {
none,
null}
then return result
else throw a
TypeError exception
— coercion failed
end if
end proc;
if o =
null or is(
o,
c)
then return o else return none end if
end proc;
Attributes
if b = false then return false
elsif a {
none,
true}
then return b
elsif b = true then return a
if a = b then return a
return CompoundAttributenamespaces: {
a,
b},
explicit:
false,
enumerable:
false,
dynamic:
false,
category:
none,
overrideMod:
none,
prototype:
false,
unused:
false
end if
else
note At this point both a and
b are compound attributes.
throw an
AttributeError exception
— attributes
a and
b have conflicting contents
else
end if
end if
end proc;
case a of
return CompoundAttributenamespaces: {},
explicit:
false,
enumerable:
false,
dynamic:
false,
category:
none,
overrideMod:
none,
prototype:
false,
unused:
false;
return CompoundAttributenamespaces: {
a},
explicit:
false,
enumerable:
false,
dynamic:
false,
category:
none,
overrideMod:
none,
prototype:
false,
unused:
false;
end case
end proc;
Access Utilities
if a =
none then return {}
end if;
end proc;
matchingSlots:
Slot{} {
s |
s o.
slots such that s.
id =
id};
return the one element of matchingSlots
end proc;
case setup of
throw a
ConstantError exception
— a constant’s type or initialiser cannot depend on the value of that constant
end case
end proc;
throw a
ReferenceError exception
— cannot initialise a
const
variable twice
end if;
return coercedValue
end proc;
Environmental Utilities
if some c env satisfies c Class then
Let
c be the first element of
env that is a
Class.
return c
end if;
end proc;
for each frame env do
end for each;
end proc;
end if;
return env[0 ... i]
end proc;
return regionalEnv[|regionalEnv| – 1]
end proc;
while env[
i]
Package do i i + 1
end while;
note Every environment ends with a
Package frame, so one will always be found.
return env[i]
end proc;
Property Lookup
note If the same property was found via several
different bindings b, then it will appear only once in the set matchingProperties.
if matchingProperties = {}
then return none
elsif |matchingProperties| = 1 then return the one element of matchingProperties
else
throw a
ReferenceError exception
— this access is ambiguous because the bindings it found belong to several different local
properties
end if
end proc;
if matches = {}
then return none
elsif |matches| = 1 then return the one element of matches
else
throw a
ReferenceError exception
— this access is ambiguous because it found several different instance properties in the same class
end if
end proc;
case o of
end case;
if m none then return m end if;
if flat then return none end if;
end proc;
note Start from the root class (Object
)
and proceed through more specific classes that are ancestors of c.
if m none then return m end if
end for each;
end proc;
throw a
ReferenceError exception
— can’t access instance properties outside an instance method without supplying an instance
object
end if;
throw a
ReferenceError exception
— can’t access instance properties inside a non-instance method without supplying an instance
object
end if;
throw a
ReferenceError exception
— can’t access instance properties inside a non-instance method without supplying an instance
object
end if;
throw an
UninitializedError exception
— can’t access instance properties from within a constructor before the superconstructor has been
called
end if;
return this
end proc;
return findBaseInstanceProperty(
c, {
qname},
read)
none or
findBaseInstanceProperty(
c, {
qname},
write)
none or
findArchetypeProperty(
o, {
qname},
read,
flat)
none or
findArchetypeProperty(
o, {
qname},
write,
flat)
none
end proc;
Reading
case r of
end case;
if result none then return result
else
throw a
ReferenceError exception
— property not found, and no default value is available
end if
end proc;
throw a
ReferenceError exception
— property not found, and no default value is available
end if;
return result
end proc;
end if;
if length =
none then throw a
RangeError exception
— length not an integer
else throw a
RangeError exception
— length out of range
end if
end proc;
At the implementation’s discretion either do nothing, set
result to
none, or
throw a
ReferenceError.
end if;
return result
end proc;
if |args| 1 then
throw an
ArgumentError exception
— exactly one argument must be supplied
end if;
return limit.
read(
o,
limit, {
qname},
none,
undefinedIfMissing,
phase)
end proc;
while i < |env| do
case frame of
result limit.
read(
frame,
limit,
multiname,
env,
false,
phase);
case phase of
throw a
ConstantError exception
— cannot read a
with
statement’s frame from a constant expression;
throw an
UninitializedError exception
— cannot read a
with
statement’s frame before that statement’s
expression has been evaluated
end case
end if;
result limit.
read(
value,
limit,
multiname,
env,
false,
phase)
end case;
if result none then return result end if;
i i + 1
end while;
throw a
ReferenceError exception
— no property found with the name
multiname
end proc;
case m of
case phase of
throw a
ConstantError exception
— a constant expression cannot read dynamic properties;
end case
end if;
throw a
ReferenceError exception
— cannot read an instance property without supplying an instance
end if;
end case
end proc;
note readInstanceProperty
is only called in cases where the instance property is known to exist, so
mBase cannot be
none here.
end proc;
case m of
throw a
ConstantError exception
— a constant expression cannot read mutable variables
end if;
case phase of
throw a
ConstantError exception
— cannot read uninitalised
const
variables from a constant expression;
throw an
UninitializedError exception
— cannot read a
const
instance variable before it is initialised
end case
end if;
return v;
m cannot be an
InstanceSetter
because these are only represented as write-only properties.
end case
end proc;
case m of
throw a
ReferenceError exception
— cannot access a property defined in a scope outside the current region if any block inside the current
region shadows it;
throw a
ConstantError exception
— a constant expression cannot read mutable variables
end if;
return value;
throw a
ConstantError exception
— a constant expression cannot read mutable variables
end if;
case value of
note Try to run a const
variable’s initialiser if there is one.
case phase of
throw a
ConstantError exception
— a constant expression cannot access a constant with a missing or recursive
initialiser;
end case
end if;
try
note If initialisation failed, restore
m.
initializer to its original value so it can be
tried later.
throw x
end try;
return coercedValue;
note An uninstantiated function can only be
found when
phase =
compile.
throw a
ConstantError exception
— an uninstantiated function is not a constant expression
end case;
note An uninstantiated getter can only be found
when
phase =
compile.
throw a
ConstantError exception
— an uninstantiated getter is not a constant expression
end if;
return m.
call(
env,
phase);
m cannot be a
Setter because these are
only represented as write-only properties.
end case
end proc;
Writing
case r of
throw a
ReferenceError exception
— a non-reference is not a valid target of an assignment;
end case;
throw a
ReferenceError exception
— property not found and could not be created
end if
end proc;
result: {
none,
ok}
limit.
write(
o,
limit,
multiname,
none,
newValue,
true,
phase);
throw a
ReferenceError exception
— property not found and could not be created
end if
end proc;
throw a
RangeError exception
— length out of range
end if;
Evaluate
dotWrite(
o, {
public::“
length
”},
lengthf64,
phase) and ignore its result
end proc;
end if;
if deleteResult = false then
end if
else
if writeResult =
none then
throw a
ReferenceError exception
— element not found and could not be created
end if
end if
end proc;
if |args| 1 then
throw an
ArgumentError exception
— exactly one argument must be supplied
end if;
return limit.
write(
o,
limit, {
qname},
none,
newValue,
createIfMissing,
phase)
end proc;
while i < |env| do
case frame of
result
limit.
write(
frame,
limit,
multiname,
env,
newValue,
false,
phase);
throw an
UninitializedError exception
— cannot read a
with
statement’s frame before that statement’s expression
has been evaluated
end if;
result limit.
write(
value,
limit,
multiname,
env,
newValue,
false,
phase)
end case;
if result =
ok then return end if;
i i + 1
end while;
if createIfMissing then
note Try to write the variable into pkg
again, this time allowing new dynamic bindings to be created dynamically.
result: {
none,
ok}
limit.
write(
pkg,
limit,
multiname,
env,
newValue,
true,
phase);
if result =
ok then return end if
end if;
throw a
ReferenceError exception
— no existing property found with the name
multiname and one could not be created
end proc;
end if;
case m of
note Before trying to create a new dynamic
property named qname, check that there is no read-only fixed property with the same name.
end if
end if;
throw a
ReferenceError exception
— cannot write an instance property without supplying an instance
end if;
end case
end proc;
o.
localBindings
o.
localBindings
{
LocalBindingqname:
qname,
accesses:
readWrite,
explicit:
false,
enumerable:
enumerable,
content:
dv}
end proc;
case m of
throw a
ReferenceError exception
— cannot initialise a
const
instance variable twice
end if;
throw a
ReferenceError exception
— cannot write to an instance method;
m cannot be an
InstanceGetter
because these are only represented as read-only properties.
end case
end proc;
case m of
throw a
ReferenceError exception
— cannot access a property defined in a scope outside the current region if any block inside the current
region shadows it;
m cannot be a
Getter because these are
only represented as read-only properties.
note All instances are resolved for the
run phase, so
env none.
Evaluate
m.
call(
newValue,
env,
phase) and ignore its result
end case
end proc;
Deleting
case r of
if strict then
throw a
ReferenceError exception
— a non-reference is not a valid target for
delete
in strict mode
else result true
end if;
end case;
if result none then return result else return true end if
end proc;
if |args| 1 then
throw an
ArgumentError exception
— exactly one argument must be supplied
end if;
return limit.
delete(
o,
limit, {
qname},
none,
phase)
end proc;
while i < |env| do
case frame of
result limit.
delete(
frame,
limit,
multiname,
env,
phase);
throw an
UninitializedError exception
— cannot read a
with
statement’s frame before that statement’s expression
has been evaluated
end if;
result limit.
delete(
value,
limit,
multiname,
env,
phase)
end case;
if result none then return result end if;
i i + 1
end while;
return true
end proc;
case m of
throw a
ReferenceError exception
— cannot access a property defined in a scope outside the current region if any block inside the current
region shadows it;
if o Class or env =
none then return false end if;
return false
end case
end proc;
Enumerating
end for each;
if super =
none then return e
end if
end proc;
end for each;
end if;
return e
end proc;
Calling Instances
case a of
Class do return a.
call(
this,
a,
args,
phase);
return f(this, a, args, phase);
end case
end proc;
note This function can be used in a constant
expression.
throw a
ConstantError exception
— cannot call a class before its definition has been compiled
end if;
if |args| 1 then
throw an
ArgumentError exception
— exactly one argument must be supplied
end if;
end proc;
Creating Instances
throw a
ConstantError exception
— cannot construct an instance of a class before its definition has been compiled
end if;
throw a
ConstantError exception
— a class constructor call is not a constant expression because it evaluates to a new object each time it
is evaluated
end if;
Evaluate
callInit(
this,
c,
args,
phase) and ignore its result;
return this
end proc;
end for each;
return new SimpleInstancelocalBindings: {},
archetype:
archetype,
sealed:
not c.
dynamic,
type:
c,
slots:
slots,
call:
call,
construct:
construct,
env:
env
end proc;
if init none then Evaluate
init(
this,
args,
phase) and ignore its result
else
if args [] then
throw an
ArgumentError exception
— the default constructor does not take any arguments
end if
end if
end proc;
Adding Local Definitions
throw an
AttributeError exception
— a local definition cannot have the
override
attribute
end if;
if explicit and innerFrame Package then
throw an
AttributeError exception
— the
explicit
attribute can only be used at the top level of a package
end if;
if namespaces2 = {}
then namespaces2 {
public}
end if;
multiname:
Multiname {
ns::
id |
ns namespaces2};
end if;
if innerFrame Class and id =
innerFrame.
name then
throw a
DefinitionError exception
— a
static
property of a class cannot have the same name as the class, regardless of the
namespace
end if;
for each frame regionalEnv[1 ...] do
throw a
DefinitionError exception
— this definition would shadow a property defined in an outer scope within the same region
end if
end for each;
newBindings:
LocalBinding{}
{
LocalBindingqname:
qname,
accesses:
accesses,
explicit:
explicit,
enumerable:
true,
content:
m |
qname multiname};
note Mark the bindings of
multiname as
forbidden in all non-innermost frames in the current region if they
haven’t been marked as such already.
for each frame regionalEnv[1 ...] do
end for each;
return multiname
end proc;
regionalFrame:
Frame regionalEnv[|
regionalEnv| – 1];
note env is either a
Package or a
ParameterFrame because hoisting only occurs into package or
function scope.
existingBindings:
LocalBinding{}
{
b |
b regionalFrame.
localBindings such that b.
qname =
qname};
regionalFrame regionalEnv[|regionalEnv| – 2];
end if;
if existingBindings = {} then
regionalFrame.
localBindings
regionalFrame.
localBindings
{
LocalBindingqname:
qname,
accesses:
readWrite,
explicit:
false,
enumerable:
true,
content:
v};
return v
elsif |existingBindings| 1 then
throw a
DefinitionError exception
— a hoisted definition conflicts with a non-hoisted one
else
throw a
DefinitionError exception
— a hoisted definition conflicts with a non-hoisted one
end if;
note At this point a hoisted binding of the same
var
already exists, so there is no need to create another one. Overwrite its initial value if the
new definition is a function
definition.
regionalFrame.localBindings regionalFrame.localBindings – {b};
regionalFrame.
localBindings
regionalFrame.
localBindings
{
LocalBindingenumerable:
true, other fields from
b};
return m
end if
end proc;
Adding Instance Definitions
for each qname multiname do
if mBase =
none then mBase m
elsif m none and m mBase then
throw a
DefinitionError exception
— cannot override two separate superclass methods at the same time
end if
end for each
end if;
return mBase
end proc;
if explicit then
throw an
AttributeError exception
— the
explicit
attribute can only be used at the top level of a package
end if;
requestedMultiname:
Multiname {
ns::
id |
ns namespaces};
if requestedMultiname = {} then
definedMultiname {
public::
id};
searchedMultiname openMultiname;
note definedMultiname searchedMultiname
because the public
namespace is always open.
else definedMultiname requestedMultiname; searchedMultiname requestedMultiname
end if;
if not (requestedMultiname definedMultiname) then
throw a
DefinitionError exception
— cannot extend the set of a property’s namespaces when overriding it
end if;
case m of
end case;
if not goodKind then
throw a
DefinitionError exception
— a method can override only another method, a variable can override only another variable, a getter can
override only a getter or a variable, and a setter can override only a setter or a variable
end if;
if mOverridden.
final then
end if
end if;
end if;
case overrideMod of
throw a
DefinitionError exception
— a definition that overrides a superclass’s property must be marked with the
override
attribute
end if;
throw a
DefinitionError exception
— this definition is hidden by one in a superclass when accessed without a namespace qualifier; in the
rare cases where this is intentional, use the
override(false)
attribute
end if;
{false} do
throw a
DefinitionError exception
— this definition is marked with
override(false)
but it overrides a superclass’s
property
end if;
{true} do
throw a
DefinitionError exception
— this definition is marked with
override
or
override(true)
but it
doesn’t override a superclass’s property
end if;
end case;
return mOverridden
end proc;
Instantiation
end if;
if instantiations {} then
Suppose that
instantiateFunction
were to choose at its discretion some element
i2 of
instantiations, assign
i2.
env env,
and return
i. If the behaviour of doing that assignment were observationally indistinguishable by the
rest of the program from the behaviour of returning
i without modifying
i2.
env, then the implementation may, but does not
have to,
return i2 now, discarding (or not even bothering to
create) the value of
i.
note The above rule allows an implementation to
avoid creating a fresh closure each time a local function is instantiated if it can show that the closures would
behave identically. This optimisation is not transparent to the programmer because the instantiations will be
===
to each other and share one set of properties (including the prototype
property,
if applicable) rather than each having its own. ECMAScript programs should not rely on this distinction.
end if;
return i
end proc;
case m of
note m.
setup =
none
because
Setup must have been called on a frame before that frame can be
instantiated.
end if;
end case
end proc;
tuple PropertyTranslation
end tuple;
end proc;
return instantiatedFrame
end proc;
note properties will contain the set of
all
SingletonProperty records found in the
frame.
note If any of the parameters (including the rest
parameter) are anonymous, their bindings will not be present in
frame.
localBindings. In this situation, the following
steps add their
SingletonProperty records to
properties.
for each p frame.
parameters do properties properties {
p.
var}
end for each;
if rest none then properties properties {
rest}
end if;
end proc;
else instantiatedFrame.
rest translateProperty(
rest)
end if;
return instantiatedFrame
end proc;
Sealing
proc sealAllLocalProperties(
o:
Object)
end proc;
for each m matchingProperties do
end for each
end if
end proc;
Standard Class Utilities
if n |args| then return default end if;
if arg =
undefined then return default else return arg end if
end proc;
return LocalBindingqname:
qname,
accesses:
readWrite,
explicit:
false,
enumerable:
false,
content:
new Variabletype:
type,
value:
value,
immutable:
false,
setup:
none,
initializer:
none
end proc;
return the one element of matchingBindings
end proc;
Expressions
Syntax
{allowIn, noIn}
Terminal Actions
Body[
RegularExpression]:
String;
Flags[
RegularExpression]:
String;
Identifiers
Syntax
Semantics
Qualified Identifiers
Syntax
SimpleQualifiedIdentifier
Validation
Setup
Evaluation
throw a
TypeError exception
— the qualifier must be a namespace
end if;
end proc;
Primary Expressions
Syntax
null
| true
| false
| Number
| String
| this
| RegularExpression
Validation
throw a
SyntaxError exception
—
this
can be used outside a function only in non-strict mode
end if
throw a
SyntaxError exception
— this function does not define
this
end if;
Evaluate
Validate[
ArrayLiteral](
cxt,
env) and ignore its result;
Evaluate
Validate[
ObjectLiteral](
cxt,
env) and ignore its result;
end proc;
throw a
SyntaxError exception
—
private
is meaningful only inside a class
end if
end proc;
Setup
Evaluation
note If
Validate
passed,
this can be uninitialised only when
phase =
compile.
throw a
ConstantError exception
— a constant expression cannot read an uninitialised
this parameter
end if;
throw an
UninitializedError exception
— can’t access
this
from within a constructor before the superconstructor has been
called
end if;
return this;
return Body[RegularExpression] “#
” Flags[RegularExpression];
end proc;
note Validate
already ensured that
c none.
end proc;
Function Expressions
Syntax
Validation
Setup
Evaluation
throw a
ConstantError exception
— a
function
expression is not a constant expression because it can evaluate to different
values
end if;
throw a
ConstantError exception
— a
function
expression is not a constant expression because it can evaluate to different
values
end if;
return f
end proc;
Object Literals
Syntax
Validation
Setup
Setup[
FieldList]
() propagates the call to
Setup to nonterminals in the expansion of
FieldList.
Setup[
FieldName]
() propagates the call to
Setup to nonterminals in the expansion of
FieldName.
Evaluation
throw a
ConstantError exception
— an object literal is not a constant expression because it evaluates to a new object each time it is
evaluated
end if;
Evaluate
Eval[
FieldList](
env,
o,
phase) and ignore its result;
return o
end proc;
Evaluate
dotWrite(
o,
multiname,
value,
phase) and ignore its result
end proc;
Array Literals
Syntax
Validation
Setup
Evaluation
throw a
ConstantError exception
— an array literal is not a constant expression because it evaluates to a new object each time it is
evaluated
end if;
return o
end proc;
Evaluate
Eval[
LiteralElement](
env,
length,
o,
phase) and ignore its result;
return length + 1;
Evaluate
Eval[
LiteralElement](
env,
length,
o,
phase) and ignore its result;
end proc;
Evaluate
indexWrite(
o,
length,
value,
phase) and ignore its result
end proc;
Super Expressions
Syntax
Validation
throw a
SyntaxError exception
— a
super
expression is meaningful only inside a class
end if;
throw a
SyntaxError exception
— a
super
expression without an argument is meaningful only inside an instance method or a
constructor
end if;
throw a
SyntaxError exception
— a
super
expression is meaningful only if the enclosing class has a superclass
end if;
throw a
SyntaxError exception
— a
super
expression is meaningful only inside a class
end if;
throw a
SyntaxError exception
— a
super
expression is meaningful only if the enclosing class has a superclass
end if;
end proc;
Setup
Evaluation
note If
Validate
passed,
this can be uninitialised only when
phase =
compile.
throw a
ConstantError exception
— a constant expression cannot read an uninitialised
this parameter
end if;
throw an
UninitializedError exception
— can’t access
super
from within a constructor before the superconstructor has been
called
end if;
end proc;
note Validate ensured
that
limit cannot be
none at this point.
if coerced =
null then return null end if;
end proc;
Postfix Expressions
Syntax
Validation
Setup
Evaluation
case r of
end case;
return call(
base,
f,
args,
phase)
end proc;
case r of
end case;
return call(
base,
f,
args,
phase);
throw a
ConstantError exception
—
++
cannot be used in a constant expression
end if;
return b;
throw a
ConstantError exception
—
--
cannot be used in a constant expression
end if;
return b
end proc;
Property Operators
Syntax
Validation
Setup
Setup[
Brackets] ()
propagates the call to
Setup to nonterminals in the expansion of
Brackets.
Setup[
Arguments]
() propagates the call to
Setup to nonterminals in the expansion of
Arguments.
Evaluation
while i length do
An implementation may, at its discretion, either
throw
a
ReferenceError or treat the hole as a missing
argument, substituting the called function’s default parameter value if there is one,
undefined if the called function is unchecked, or
throwing an
ArgumentError exception otherwise. An implementation must
not replace such a hole with
undefined except when the called
function is unchecked or happens to have
undefined as its default
parameter value.
end if;
args args [arg];
i i + 1
end while;
return args
end proc;
Unary Operators
Syntax
Validation
Setup
Evaluation
throw a
ConstantError exception
—
delete
cannot be used in a constant expression
end if;
throw a
ConstantError exception
—
++
cannot be used in a constant expression
end if;
return c;
throw a
ConstantError exception
—
--
cannot be used in a constant expression
end if;
return c;
end proc;
case x of
i: {0 ... 2
64 – 1}
x.
value;
end case
end proc;
Multiplicative Operators
Syntax
Validation
Setup
Evaluation
Additive Operators
Syntax
Validation
Setup
Evaluation
Bitwise Shift Operators
Syntax
Validation
Setup
Evaluation
Relational Operators
Syntax
RelationalExpressionallowIn
Validation
Setup
Evaluation
Equality Operators
Syntax
Validation
Setup
Evaluation
Binary Bitwise Operators
Syntax
Validation
Setup
Evaluation
return bitOr(
a,
b,
phase)
end proc;
Binary Logical Operators
Syntax
Validation
Setup
Evaluation
Conditional Operator
Syntax
Validation
Setup
Evaluation
Assignment Operators
Syntax
*=
| /=
| %=
| +=
| -=
| <<=
| >>=
| >>>=
| &=
| ^=
| |=
Semantics
Validation
Setup
Evaluation
throw a
ConstantError exception
— assignment cannot be used in a constant expression
end if;
return b;
throw a
ConstantError exception
— assignment cannot be used in a constant expression
end if;
return result;
throw a
ConstantError exception
— assignment cannot be used in a constant expression
end if;
end case;
return result
end proc;
Comma Expressions
Syntax
Validation
Setup
Evaluation
Type Expressions
Syntax
Validation
Setup and Evaluation
Statements
Syntax
{abbrev, noShortIf, full}
;
| VirtualSemicolon
| «empty»
SemicolonnoShortIf
;
| VirtualSemicolon
| «empty»
Semicolonfull
;
| VirtualSemicolon
Validation
Evaluate
Validate[
Block](
cxt,
env,
jt,
preinst) and ignore its result;
Evaluate
Validate[
IfStatement](
cxt,
env,
jt) and ignore its result;
Evaluate
Validate[
DoStatement](
cxt,
env,
sl,
jt) and ignore its result;
Evaluate
Validate[
WhileStatement](
cxt,
env,
sl,
jt) and ignore its result;
Evaluate
Validate[
ForStatement](
cxt,
env,
sl,
jt) and ignore its result;
Evaluate
Validate[
WithStatement](
cxt,
env,
jt) and ignore its result;
Evaluate
Validate[
TryStatement](
cxt,
env,
jt) and ignore its result
end proc;
Evaluate
Validate[
Statement](
cxt,
env,
sl,
jt,
false) and ignore its result;
Evaluate
Validate[
Attributes](
cxt,
env) and ignore its result;
Evaluate
Setup[
Attributes]() and ignore its result;
throw a
TypeError exception
— attributes other than
true
and
false
may be used in a statement but not a
substatement
end if;
if attr then Evaluate
Validate[
Substatements](
cxt,
env,
jt) and ignore its result
end if
end proc;
Evaluate
Validate[
Substatementabbrev](
cxt,
env, {},
jt) and ignore its result
end proc;
Evaluate
Validate[
Substatementfull](
cxt,
env, {},
jt) and ignore its result
end proc;
Setup
Setup[
Statement]
() propagates the call to
Setup to nonterminals in the expansion of
Statement.
Evaluation
Empty Statement
Syntax
Expression Statement
Syntax
Validation
Setup
Evaluation
Super Statement
Syntax
Validation
throw a
SyntaxError exception
— a
super
statement is meaningful only inside a constructor
end if;
Evaluate
Validate[
Arguments](
cxt,
env) and ignore its result;
end proc;
Setup
Evaluation
throw a
ReferenceError exception
— the superconstructor cannot be called twice
end if;
return this
end proc;
Block Statement
Syntax
Validation
Evaluate
Validate[
Directives](
localCxt,
[frame] env,
jt,
preinst,
none)
and ignore its result
end proc;
CompileFrame[
Block]
compileFrame;
Preinstantiate[
Block]
preinst;
Evaluate
ValidateUsingFrame[
Block](
cxt,
env,
jt,
preinst,
compileFrame)
and ignore its result
end proc;
Setup
Setup[
Block] () propagates the call to
Setup to nonterminals in the expansion of
Block.
Evaluation
if Preinstantiate[
Block]
then runtimeFrame compileFrame
end if;
end proc;
Labeled Statements
Syntax
Validation
throw a
SyntaxError exception
— nesting labeled statements with the same label is not permitted
end if;
Evaluate
Validate[
Substatement](
cxt,
env,
sl {
name},
jt2) and ignore its result
end proc;
Setup
Evaluation
If Statement
Syntax
Validation
Evaluate
Validate[
Substatementabbrev](
cxt,
env, {},
jt) and ignore its result;
Evaluate
Validate[
Substatementfull](
cxt,
env, {},
jt) and ignore its result;
Evaluate
Validate[
SubstatementnoShortIf1](
cxt,
env, {},
jt) and ignore its result;
Evaluate
Validate[
Substatement2](
cxt,
env, {},
jt) and ignore its result
end proc;
Setup
Evaluation
Switch Statement
Semantics
Syntax
Validation
throw a
SyntaxError exception
— a
case
statement may have at most one default clause
end if;
Evaluate
Validate[
CaseElements](
localCxt,
[compileFrame] env,
jt2)
and ignore its result
end proc;
Evaluate
Validate[
Directive](
cxt,
env,
jt,
false,
none) and ignore its result;
Evaluate
Validate[
CaseLabel](
cxt,
env,
jt) and ignore its result
end proc;
Evaluate
Validate[
ListExpressionallowIn](
cxt,
env) and ignore its result;
end proc;
Setup
Setup[
CaseLabel]
() propagates the call to
Setup to nonterminals in the expansion of
CaseLabel.
Evaluation
if result Object then return result end if;
if result Object then return result end if;
return d
end proc;
Do-While Statement
Syntax
Validation
Evaluate
Validate[
Substatementabbrev](
cxt,
env, {},
jt2) and ignore its result;
end proc;
Setup
Evaluation
While Statement
Syntax
Validation
Evaluate
Validate[
Substatement](
cxt,
env, {},
jt2) and ignore its result
end proc;
Setup
Evaluation
For Statements
Syntax
Validation
Evaluate
Validate[
ForInitializer](
cxt,
compileEnv) and ignore its result;
Evaluate
Validate[
Substatement](
cxt,
compileEnv, {},
jt2) and ignore its result;
Evaluate
Validate[
ListExpressionallowIn](
cxt,
env) and ignore its result;
Evaluate
Validate[
ForInBinding](
cxt,
compileEnv) and ignore its result;
Evaluate
Validate[
Substatement](
cxt,
compileEnv, {},
jt2) and ignore its result
end proc;
Evaluate
Validate[
ListExpressionnoIn](
cxt,
env) and ignore its result;
Evaluate
Validate[
Attributes](
cxt,
env) and ignore its result;
Evaluate
Setup[
Attributes]() and ignore its result;
if attr false then
end if
end proc;
Evaluate
Validate[
Attributes](
cxt,
env) and ignore its result;
Evaluate
Setup[
Attributes]() and ignore its result;
if attr = false then
throw an
AttributeError exception
— the
false
attribute canot be applied to a
for
-
in
variable
definition
end if;
end proc;
Setup
Evaluation
try
remainingIndices:
Object{}
oldIndices;
while remainingIndices {} do
index:
Object any element of
remainingIndices;
remainingIndices remainingIndices – {index};
Evaluate
WriteBinding[
ForInBinding](
runtimeEnv,
index)
and ignore its result;
end try;
if newIndices oldIndices then
The implementation may, at its discretion, add none, some, or all of the objects in the
set difference newIndices – oldIndices to remainingIndices;
The implementation may, at its discretion, remove none, some, or all of the objects in
the set difference oldIndices – newIndices from
remainingIndices;
end if;
oldIndices newIndices
end while;
return d1
end try
end proc;
Evaluate
WriteBinding[
VariableBindingnoIn](
env,
newValue) and ignore its result;
Evaluate
WriteBinding[
VariableBindingnoIn](
env,
newValue) and ignore its result
end proc;
With Statement
Syntax
Validation
compileEnv:
Environment [compileLocalFrame] [compileWithFrame] env;
Evaluate
Validate[
Substatement](
cxt,
compileEnv, {},
jt) and ignore its result
end proc;
Setup
Evaluation
runtimeEnv:
Environment [runtimeLocalFrame] [runtimeWithFrame] env;
end proc;
Continue and Break Statements
Syntax
Validation
throw a
SyntaxError exception
— there is no enclosing statement to which to continue
end if;
throw a
SyntaxError exception
— there is no enclosing labeled statement to which to continue
end if
end proc;
throw a
SyntaxError exception
— there is no enclosing statement to which to break
end if;
throw a
SyntaxError exception
— there is no enclosing labeled statement to which to break
end if
end proc;
Setup
Evaluation
Return Statement
Syntax
Validation
throw a
SyntaxError exception
— a
return
statement must be located inside a function
end if;
throw a
SyntaxError exception
— a
return
statement must be located inside a function
end if;
throw a
SyntaxError exception
— a
return
statement inside a setter or constructor cannot return a value
end if;
Evaluate
Validate[
ListExpressionallowIn](
cxt,
env) and ignore its result
end proc;
Setup
Evaluation
Throw Statement
Syntax
Validation
Setup
Evaluation
Try Statement
Syntax
Validation
Evaluate
Validate[
Block](
cxt,
env,
jt,
false) and ignore its result;
Evaluate
Validate[
CatchClauses](
cxt,
env,
jt) and ignore its result;
Evaluate
Validate[
Block1](
cxt,
env,
jt,
false) and ignore its result;
Evaluate
Validate[
Block2](
cxt,
env,
jt,
false) and ignore its result
end proc;
Evaluate
Validate[
Parameter](
cxt,
compileEnv,
compileFrame) and ignore its result;
Evaluate
Validate[
Block](
cxt,
compileEnv,
jt,
false) and ignore its result
end proc;
Setup
Evaluate
Setup[
Block]() and ignore its result
end proc;
Evaluation
try return Eval[
Block](
env,
d)
else
if r reject then return r else throw x end if
end if
end try;
try result Eval[
Block1](
env,
d)
end try;
note At this point exactly one of
result
and
exception has a non-
none value.
try
note The exception has been handled, so clear
it.
result r;
end if
note The
catch
clause threw
another exception or
ControlTransfer x, so
replace the original exception with
x.
exception x
end try
end if;
note The
finally
clause is executed
even if the original block exited due to a
ControlTransfer
(
break
,
continue
, or
return
).
note The
finally
clause is not inside
a
try-
catch semantic statement, so if it
throws another exception or
ControlTransfer, then the
original exception or
ControlTransfer exception is
dropped.
note At this point exactly one of
result
and
exception has a non-
none value.
if exception none then throw exception else return result end if
end proc;
note Validate created
one local variable with the name in
qname, so
v Variable.
end if
end proc;
Directives
Syntax
Validation
if attr {
none,
true}
then
throw an
AttributeError exception
— an ordinary statement only permits the attributes
true
and
false
end if;
Evaluate
Validate[
Statement](
cxt,
env, {},
jt,
preinst) and ignore its result;
Evaluate
Validate[
Attributes](
cxt,
env) and ignore its result;
Evaluate
Setup[
Attributes]() and ignore its result;
if attr3 =
false then Enabled[
Directive]
false
else
end if;
Evaluate
Validate[
Attributes](
cxt,
env) and ignore its result;
Evaluate
Setup[
Attributes]() and ignore its result;
if attr3 =
false then Enabled[
Directive]
false
else
Evaluate
Validate[
Directives](
localCxt,
env,
jt,
preinst,
attr3)
and ignore its result
end if;
if attr {
none,
true}
then Evaluate
Validate[
Pragma](
cxt) and ignore its result
else
throw an
AttributeError exception
— a
pragma
directive only permits the attributes
true
and
false
end if
end proc;
Evaluate
Validate[
ClassDefinition](
cxt,
env,
preinst,
attr) and ignore its result;
Evaluate
Validate[
ImportDirective](
cxt,
env,
preinst,
attr) and ignore its result;
if attr {
none,
true}
then
Evaluate
Validate[
UseDirective](
cxt,
env) and ignore its result
else
throw an
AttributeError exception
— a
use
directive only permits the attributes
true
and
false
end if
end proc;
Setup
Evaluation
Attributes
Syntax
Validation
Setup
Setup[
Attribute]
() propagates the call to
Setup to nonterminals in the expansion of
Attribute.
Evaluation
if a = false then return false end if;
end proc;
Use Directive
Syntax
Validation
for each v values do
namespaces namespaces {v}
end for each;
end proc;
Import Directive
Syntax
Validation
if not preinst then
throw a
SyntaxError exception
— a package may be imported only in a preinstantiated scope
end if;
throw a
SyntaxError exception
— a package may be imported only into a package scope
end if;
if attr {
none,
true}
then
throw an
AttributeError exception
— an unnamed
import
directive only permits the attributes
true
and
false
end if;
if not preinst then
throw a
SyntaxError exception
— a package may be imported only in a preinstantiated scope
end if;
throw a
SyntaxError exception
— a package may be imported only into a package scope
end if;
throw an
AttributeError exception
— a package definition cannot have the
dynamic
attribute
end if;
throw an
AttributeError exception
— a package definition cannot have the
prototype
attribute
end if;
end proc;
Look for a package bound to
name in the implementation’s list of available
packages. If one is found, let
pkg:
Package be that
package; otherwise, throw an implementation-defined error.
case initialize of
() () do
Evaluate initialize() and ignore its result;
end case;
return pkg
end proc;
Pragma
Syntax
true
| false
| Number
| -
Number
| -
NegatedMinLong
| String
Validation
Validate[
Pragma]
(
cxt:
Context) propagates the call to
Validate to nonterminals in the expansion of
Pragma.
Evaluate
Validate[
PragmaExpr](
cxt,
false) and ignore its result;
Evaluate
Validate[
PragmaExpr](
cxt,
true) and ignore its result
end proc;
if name = “strict
” then
if value =
false then cxt.
strict false;
return end if
end if;
if name = “ecmascript
” then
if value {
undefined, 4
f64}
then return end if;
if value {1f64, 2f64, 3f64} then
An implementation may optionally modify cxt to disable features not available in
ECMAScript Edition value other than subsequent pragmas.
return
end if
end if;
if not optional then throw a
SyntaxError exception
end if
end proc;
Definitions
Variable Definition
Syntax
Validation
else
throw an
AttributeError exception
— a variable definition cannot have the
dynamic
attribute
end if;
throw an
AttributeError exception
— a variable definition cannot have the
prototype
attribute
end if;
else
throw an
AttributeError exception
— non-class variables cannot have a
static
,
virtual
, or
final
attribute
end if
end if;
case category of
if noInitializer and initializer none then
throw a
SyntaxError exception
— a
for
-
in
statement’s variable definition must not have an
initialiser
end if;
end proc;
v:
Variable
new Variablevalue:
none,
immutable:
immutable,
setup:
variableSetup,
initializer:
initializer,
initializerEnv:
env;
note not noInitializer;
end if;
end case
end if
end proc;
Setup
case v of
if defaultValue =
none then
end if;
end if;
if overriddenVar none then t overriddenVar.
type
end if
end if;
if initializer none then defaultValue initializer(
env,
compile)
if defaultValue =
none then
throw an
UninitializedError exception
— Cannot declare a mutable instance variable of type
Never
end if
end if;
end case
end proc;
Evaluation
note The
properties set consists of
exactly one
Variable element because
innerFrame was
constructed with that
Variable inside
Validate.
v:
Variable the one element of
properties;
case initializer of
end case;
end case
end proc;
note The
properties set consists of
exactly one
Variable element because
innerFrame was
constructed with that
Variable inside
Validate.
v:
Variable the one element of
properties;
Evaluate
writeVariable(
v,
newValue,
false) and ignore its result;
end case
end proc;
Simple Variable Definition
Syntax
A SimpleVariableDefinition represents the subset of
VariableDefinition expansions that may be used when the variable
definition is used as a
Substatement
instead of a
Directive
in non-strict mode. In strict mode variable definitions may not be used as substatements.
UntypedVariableBindingList
Validation
throw a
SyntaxError exception
— a variable may not be defined in a substatement except inside a non-strict function or non-strict
top-level code; to fix this error, place the definition inside a block
end if;
end proc;
Setup
Evaluation
Evaluate
lexicalWrite(
env, {
qname},
value,
false,
run) and ignore its result
end if
end proc;
Function Definition
Syntax
Validation
case handling of
throw an
AttributeError exception
— a getter or setter cannot have the
prototype
attribute
end if;
note not (unchecked or hoisted);
if preinst then boundEnv env end if;
case handling of
end case
end case;
end proc;
throw an
AttributeError exception
— an instance method cannot have the
prototype
attribute
end if;
case handling of
end case;
if mOverridden none and mOverridden.
enumerable then enumerable true end if;
end proc;
throw an
AttributeError exception
— a class constructor cannot have the
prototype
attribute
end if;
throw a
SyntaxError exception
— a class constructor cannot be a getter or a setter
end if;
end if;
end proc;
throw an
AttributeError exception
— a function cannot have the
dynamic
attribute
end if;
note preinst;
Evaluate
ValidateStatic[
FunctionDefinition](
cxt,
env,
preinst,
a,
false,
false)
and ignore its result;
Evaluate
ValidateConstructor[
FunctionDefinition](
cxt,
env,
frame,
a)
and ignore its result
else
Evaluate
ValidateInstance[
FunctionDefinition](
cxt,
env,
frame,
a,
false)
and ignore its result
end if;
Evaluate
ValidateInstance[
FunctionDefinition](
cxt,
env,
frame,
a,
false)
and ignore its result;
Evaluate
ValidateInstance[
FunctionDefinition](
cxt,
env,
frame,
a,
true)
and ignore its result
end case
else
throw an
AttributeError exception
— non-class functions cannot have a
static
,
virtual
, or
final
attribute
end if;
Evaluate
ValidateStatic[
FunctionDefinition](
cxt,
env,
preinst,
a,
unchecked,
hoisted)
and ignore its result
end if
end proc;
compileFrame:
ParameterFrame
new ParameterFramelocalBindings: {},
kind:
kind,
handling:
handling,
callsSuperconstructor:
false,
superconstructorCalled:
superconstructorCalled,
this:
none,
parameters:
[],
rest:
none;
end if;
Evaluate
Validate[
Parameters](
localCxt,
compileEnv,
compileFrame)
and ignore its result;
Evaluate
Validate[
Result](
localCxt,
compileEnv) and ignore its result;
Evaluate
Validate[
Block](
localCxt,
compileEnv,
JumpTargetsbreakTargets: {},
continueTargets: {}
,
false) and ignore its result
end proc;
Setup
case overriddenProperty of
Evaluate
SetupOverride[
FunctionCommon](
overriddenProperty.
signature)
and ignore its result;
This cannot happen because ValidateInstance already
ensured that a function cannot override an instance variable.
overriddenSignature
new ParameterFramelocalBindings: {},
kind:
instanceFunction,
handling:
get,
callsSuperconstructor:
false,
superconstructorCalled:
false,
this:
none,
parameters:
[],
rest:
none,
returnType:
overriddenProperty.
type;
end case;
Evaluate
SetupOverride[
FunctionCommon](
overriddenSignature)
and ignore its result
end case
end proc;
Evaluate
Setup[
Parameters](
compileEnv,
compileFrame) and ignore its result;
Evaluate
Setup[
Result](
compileEnv,
compileFrame) and ignore its result;
Evaluate
Setup[
Block]() and ignore its result
end proc;
Evaluate
SetupOverride[
Parameters](
compileEnv,
compileFrame,
overriddenSignature)
and ignore its result;
Evaluate
SetupOverride[
Result](
compileEnv,
compileFrame,
overriddenSignature)
and ignore its result;
Evaluate
Setup[
Block]() and ignore its result
end proc;
Evaluation
note The check that
phase
compile also
ensures that
Setup has been called.
throw a
ConstantError exception
— a constant expression cannot call user-defined functions
end if;
else runtimeThis this
end if
end if;
Evaluate
assignArguments(
runtimeFrame,
f,
args,
phase) and ignore its result;
try
Evaluate
Eval[
Block](
[runtimeFrame] runtimeEnv,
undefined)
and ignore its result;
end try;
end proc;
note The check that
phase
compile also
ensures that
Setup has been called.
throw a
ConstantError exception
— a constant expression cannot call user-defined getters
end if;
try
Evaluate
Eval[
Block](
[runtimeFrame] runtimeEnv,
undefined)
and ignore its result;
throw a
SyntaxError exception
— a getter must return a value and may not return by falling off the end of its code
end try;
end proc;
note The check that
phase
compile also
ensures that
Setup has been called.
throw a
ConstantError exception
— a constant expression cannot call setters
end if;
try
Evaluate
Eval[
Block](
[runtimeFrame] runtimeEnv,
undefined)
and ignore its result
end try
end proc;
note The check that
phase
compile also
ensures that
Setup has been called.
throw a
ConstantError exception
— a constant expression cannot call user-defined functions
end if;
note Class frames are always preinstantiated, so the
run environment is the same as compile environment.
try
Evaluate
Eval[
Block](
[runtimeFrame] env,
undefined) and ignore its result;
end try;
end proc;
note The check that
phase
compile also
ensures that
Setup has been called.
throw a
ConstantError exception
— a constant expression cannot call user-defined getters
end if;
note Class frames are always preinstantiated, so the
run environment is the same as compile environment.
try
Evaluate
Eval[
Block](
[runtimeFrame] env,
undefined) and ignore its result;
throw a
SyntaxError exception
— a getter must return a value and may not return by falling off the end of its code
end try;
end proc;
note The check that
phase
compile also
ensures that
Setup has been called.
throw a
ConstantError exception
— a constant expression cannot call setters
end if;
note Class frames are always preinstantiated, so the
run environment is the same as compile environment.
try Evaluate
Eval[
Block](
[runtimeFrame] env,
undefined) and ignore its result
end try
end proc;
note Class frames are always preinstantiated, so the
run environment is the same as compile environment.
end if;
try Evaluate
Eval[
Block](
[runtimeFrame] env,
undefined) and ignore its result
end try;
throw an
UninitializedError exception
— the superconstructor must be called before returning normally from a constructor
end if
end proc;
note The check that
phase
compile also
ensures that
Setup has been called.
throw a
ConstantError exception
— a constant expression cannot call user-defined prototype constructors
end if;
throw a
TypeError exception
— bad
prototype
value
end if;
Evaluate
assignArguments(
runtimeFrame,
f,
args,
phase) and ignore its result;
try
Evaluate
Eval[
Block](
[runtimeFrame] runtimeEnv,
undefined)
and ignore its result;
end try;
if coercedResult PrimitiveObject then return o else return coercedResult end if
end proc;
if parameters [] or rest none then
throw a
SyntaxError exception
— a getter cannot take any parameters
end if;
if |
parameters| 1
or rest none then
throw a
SyntaxError exception
— a setter must take exactly one parameter
end if;
throw a
SyntaxError exception
— a setter’s parameter cannot be optional
end if
end case
end proc;
This procedure performs a number of checks on the arguments, including checking their count,
names, and values. Although this procedure performs these checks in a specific order for expository purposes, an
implementation may perform these checks in a different order, which could have the effect of reporting a different
error if there are multiple errors. For example, if a function only allows between 2 and 4 arguments, the first of
which must be a Number
and is passed five arguments the first of which is a String
, then
the implementation may throw an exception either about the argument count mismatch or about the type coercion
error in the first argument.
end if;
for each arg args do
if i < |parameters| then
if argOrDefault =
undefined and default none then argOrDefault default
end if;
if argumentsObject none then
note Create an alias of v as the
ith entry of the arguments
object.
end if
elsif restObject none then
Evaluate
indexWrite(
restObject,
j,
arg,
phase) and ignore its result;
note argumentsObject =
none
because a function can't have both a rest parameter and an
arguments
object.
j j + 1
elsif argumentsObject none then
Evaluate
indexWrite(
argumentsObject,
i,
arg,
phase) and ignore its result
else
throw an
ArgumentError exception
— more arguments than parameters were supplied, and the called function does not have a
...
parameter and is not unchecked.
end if;
i i + 1
end for each;
while i < |parameters| do
else
throw an
ArgumentError exception
— fewer arguments than parameters were supplied, and the called function does not supply default
values for the missing parameters and is not unchecked.
end if
end if;
i i + 1
end while
end proc;
Syntax
Validation
Evaluate
Validate[
Parameter](
cxt,
env,
compileFrame) and ignore its result;
Evaluate
Validate[
Parameter](
cxt,
env,
compileFrame) and ignore its result;
end proc;
Setup
throw a
DefinitionError exception
— mismatch with the overridden method’s signature
end if;
Evaluate
SetupOverride[
NonemptyParameters](
compileEnv,
compileFrame,
overriddenSignature,
overriddenSignature.
parameters) and ignore its
result
end proc;
Evaluate
Setup[
ParameterInit](
compileEnv,
compileFrame) and ignore its result;
Evaluate
Setup[
ParameterInit](
compileEnv,
compileFrame) and ignore its result;
end proc;
if overriddenParameters = [] then
throw a
DefinitionError exception
— mismatch with the overridden method’s signature
end if;
Evaluate
SetupOverride[
ParameterInit](
compileEnv,
compileFrame,
overriddenParameters[0])
and ignore its result;
if |
overriddenParameters| 1
or overriddenSignature.
rest none then
throw a
DefinitionError exception
— mismatch with the overridden method’s signature
end if;
if overriddenParameters = [] then
throw a
DefinitionError exception
— mismatch with the overridden method’s signature
end if;
Evaluate
SetupOverride[
ParameterInit](
compileEnv,
compileFrame,
overriddenParameters[0])
and ignore its result;
Evaluate
SetupOverride[
NonemptyParameters1](
compileEnv,
compileFrame,
overriddenSignature,
overriddenParameters[1 ...]) and ignore
its result;
if overriddenParameters [] then
throw a
DefinitionError exception
— mismatch with the overridden method’s signature
end if;
throw a
DefinitionError exception
— mismatch with the overridden method’s signature
end if
end proc;
throw a
SyntaxError exception
— a required parameter cannot follow an optional one
end if;
case v of
end case;
end if
end proc;
if newDefault =
none then newDefault overriddenParameter.
default end if;
throw a
SyntaxError exception
— a required parameter cannot follow an optional one
end if;
if type overriddenParameter.
var.
type then
throw a
DefinitionError exception
— mismatch with the overridden method’s signature
end if;
end proc;
Evaluate
Setup[
Parameter](
compileEnv,
compileFrame,
none) and ignore its result;
Evaluate
Setup[
Parameter](
compileEnv,
compileFrame,
default) and ignore its result
end proc;
Evaluate
SetupOverride[
Parameter](
compileEnv,
compileFrame,
none,
overriddenParameter)
and ignore its result;
Evaluate
SetupOverride[
Parameter](
compileEnv,
compileFrame,
default,
overriddenParameter)
and ignore its result
end proc;
throw a
SyntaxError exception
— a setter or constructor cannot define a return type
end if;
end proc;
throw a
DefinitionError exception
— mismatch with the overridden method’s signature
end if;
end proc;
Class Definition
Syntax
Validation
if not preinst then
throw a
SyntaxError exception
— a class may be defined only in a preinstantiated scope
end if;
throw a
ConstantError exception
— cannot override a class before its definition has been compiled
end if;
end if;
throw an
AttributeError exception
— a class definition cannot have the
prototype
attribute
end if;
throw an
AttributeError exception
— non-class property definitions cannot have a
static
attribute
end if;
final false;
throw an
AttributeError exception
— a class definition cannot have the
virtual
attribute
end case;
c:
Class
new ClasslocalBindings: {},
instanceProperties: {},
super:
super,
prototype:
super.
prototype,
complete:
false,
name:
Name[
Identifier],
typeofString: “
object
”,
privateNamespace:
privateNamespace,
dynamic:
dynamic,
final:
final,
defaultValue:
null,
defaultHint:
hintNumber,
hasProperty:
super.
hasProperty,
bracketRead:
super.
bracketRead,
bracketWrite:
super.
bracketWrite,
bracketDelete:
super.
bracketDelete,
read:
super.
read,
write:
super.
write,
delete:
super.
delete,
enumerate:
super.
enumerate,
call:
ordinaryCall,
construct:
ordinaryConstruct,
init:
none,
is:
ordinaryIs,
coerce:
ordinaryCoerce;
Evaluate
ValidateUsingFrame[
Block](
innerCxt,
env,
JumpTargetsbreakTargets: {},
continueTargets: {}
,
preinst,
c) and ignore its result;
end proc;
Evaluate
Validate[
TypeExpressionallowIn](
cxt,
env) and ignore its result;
end proc;
Setup
Evaluate
Setup[
Block]() and ignore its result
end proc;
Evaluation
return EvalUsingFrame[
Block](
env,
c,
d)
end proc;
Namespace Definition
Syntax
Validation
if not preinst then
throw a
SyntaxError exception
— a namespace may be defined only in a preinstantiated scope
end if;
throw an
AttributeError exception
— a namespace definition cannot have the
dynamic
attribute
end if;
throw an
AttributeError exception
— a namespace definition cannot have the
prototype
attribute
end if;
throw an
AttributeError exception
— non-class property definitions cannot have a
static
attribute
end if;
throw an
AttributeError exception
— a namespace definition cannot have the
virtual
or
final
attribute
end case;
end proc;
Programs
Syntax
Processing
begin
Evaluate
Validate[
Directives](
cxt,
initialEnvironment,
JumpTargetsbreakTargets: {},
continueTargets: {}
,
true,
none) and ignore its result;
Evaluate
Setup[
Directives]() and ignore its result;
end;
Package Definition
Syntax
Processing
begin
Evaluate
Validate[
Block](
cxt,
initialEnvironment,
JumpTargetsbreakTargets: {},
continueTargets: {}
,
true) and ignore its result;
Evaluate
Setup[
Block]() and ignore its result;
proc evalPackage()
Evaluate
Eval[
Block](
initialEnvironment,
undefined) and ignore its result;
end proc;
Bind name to package pkg in the system’s list of packages in an
implementation-defined manner.
end;
Name[
PackageName String]
=
Value[
String] processed in an
implementation-defined manner;
Predefined Identifiers
return new PackagelocalBindings:
{
stdExplicitConstBinding(
internal::“
internal
”,
Namespace,
internal),
stdConstBinding(
public::“
explicit
”,
Attribute,
global_explicit),
stdConstBinding(
public::“
enumerable
”,
Attribute,
global_enumerable),
stdConstBinding(
public::“
dynamic
”,
Attribute,
global_dynamic),
stdConstBinding(
public::“
static
”,
Attribute,
global_static),
stdConstBinding(
public::“
virtual
”,
Attribute,
global_virtual),
stdConstBinding(
public::“
final
”,
Attribute,
global_final),
stdConstBinding(
public::“
prototype
”,
Attribute,
global_prototype),
stdConstBinding(
public::“
unused
”,
Attribute,
global_unused),
stdFunction(
public::“
override
”,
global_override, 1),
stdConstBinding(
public::“
NaN
”,
Number,
NaNf64),
stdConstBinding(
public::“
Infinity
”,
Number,
+f64),
stdConstBinding(
public::“
fNaN
”,
float,
NaNf32),
stdConstBinding(
public::“
fInfinity
”,
float,
+f32),
stdConstBinding(
public::“
undefined
”,
Void,
undefined),
stdFunction(
public::“
eval
”,
global_eval, 1),
stdFunction(
public::“
parseInt
”,
global_parseint, 2),
stdFunction(
public::“
parseLong
”,
global_parselong, 2),
stdFunction(
public::“
parseFloat
”,
global_parsefloat, 1),
stdFunction(
public::“
isNaN
”,
global_isnan, 1),
stdFunction(
public::“
isFinite
”,
global_isfinite, 1),
stdFunction(
public::“
decodeURI
”,
global_decodeuri, 1),
stdFunction(
public::“
decodeURIComponent
”,
global_decodeuricomponent, 1),
stdFunction(
public::“
encodeURI
”,
global_encodeuri, 1),
stdFunction(
public::“
encodeURIComponent
”,
global_encodeuricomponent, 1),
stdConstBinding(
public::“
Object
”,
Class,
Object),
stdConstBinding(
public::“
Never
”,
Class,
Never),
stdConstBinding(
public::“
Void
”,
Class,
Void),
stdConstBinding(
public::“
Null
”,
Class,
Null),
stdConstBinding(
public::“
Boolean
”,
Class,
Boolean),
stdConstBinding(
public::“
GeneralNumber
”,
Class,
GeneralNumber),
stdConstBinding(
public::“
long
”,
Class,
long),
stdConstBinding(
public::“
ulong
”,
Class,
ulong),
stdConstBinding(
public::“
float
”,
Class,
float),
stdConstBinding(
public::“
Number
”,
Class,
Number),
stdConstBinding(
public::“
sbyte
”,
Class,
sbyte),
stdConstBinding(
public::“
byte
”,
Class,
byte),
stdConstBinding(
public::“
short
”,
Class,
short),
stdConstBinding(
public::“
ushort
”,
Class,
ushort),
stdConstBinding(
public::“
int
”,
Class,
int),
stdConstBinding(
public::“
uint
”,
Class,
uint),
stdConstBinding(
public::“
char
”,
Class,
char),
stdConstBinding(
public::“
String
”,
Class,
String),
stdConstBinding(
public::“
Array
”,
Class,
Array),
stdConstBinding(
public::“
Namespace
”,
Class,
Namespace),
stdConstBinding(
public::“
Attribute
”,
Class,
Attribute),
stdConstBinding(
public::“
Date
”,
Class,
Date),
stdConstBinding(
public::“
RegExp
”,
Class,
RegExp),
stdConstBinding(
public::“
Class
”,
Class,
Class),
stdConstBinding(
public::“
Function
”,
Class,
Function),
stdConstBinding(
public::“
PrototypeFunction
”,
Class,
PrototypeFunction),
stdConstBinding(
public::“
Package
”,
Class,
Package),
stdConstBinding(
public::“
Error
”,
Class,
Error),
stdConstBinding(
public::“
ArgumentError
”,
Class,
ArgumentError),
stdConstBinding(
public::“
AttributeError
”,
Class,
AttributeError),
stdConstBinding(
public::“
ConstantError
”,
Class,
ConstantError),
stdConstBinding(
public::“
DefinitionError
”,
Class,
DefinitionError),
stdConstBinding(
public::“
EvalError
”,
Class,
EvalError),
stdConstBinding(
public::“
RangeError
”,
Class,
RangeError),
stdConstBinding(
public::“
ReferenceError
”,
Class,
ReferenceError),
stdConstBinding(
public::“
SyntaxError
”,
Class,
SyntaxError),
stdConstBinding(
public::“
TypeError
”,
Class,
TypeError),
stdConstBinding(
public::“
UninitializedError
”,
Class,
UninitializedError),
stdConstBinding(
public::“
URIError
”,
Class,
URIError)},
archetype:
ObjectPrototype,
name: “”,
initialize:
none,
sealed:
false,
internalNamespace:
internal
end proc;
Built-in Namespaces
Built-in Attributes
note This function does not check phase
and therefore can be used in a constant expression.
if args = [] then overrideMod true
elsif |args| = 1 then
else throw an
ArgumentError exception
— too many arguments supplied
end if;
return CompoundAttributenamespaces: {},
explicit:
false,
enumerable:
false,
dynamic:
false,
category:
none,
overrideMod:
overrideMod,
prototype:
false,
unused:
false
end proc;
Built-in Functions
Evaluate ???? and ignore its result
end proc;
note This function can be used in a constant
expression if the arguments can be converted to primitives in constant expressions.
if |args| {1, 2} then
throw an
ArgumentError exception
— at least one and at most two arguments must be supplied
end if;
end proc;
if r {0, 2 ... 36}
then throw a
RangeError exception
— radix out of
range
end if;
end while;
sign: {–1, 1} 1;
if i < |s| then
if s[i] = ‘+
’ then i i + 1 elsif s[i] = ‘-
’ then sign –1; i i + 1 end if
end if;
if r {0, 16} and i + 2 |s| and s[i ... i + 1] {“0x
”, “0X
”} then
end if;
if r = 0 then r 10 end if;
while i < |
s|
and digit none do
elsif ch {‘A
’ ... ‘Z
’} then
elsif ch {‘a
’ ... ‘z
’} then
end if;
if digit none and digit r then digit none end if;
if digit none then n nr +
digit;
i i + 1
end if
end while;
if i =
start then return NaN end if;
if n 0 then return nsign
elsif sign > 0
then return +zero
end if
end proc;
note This function can be used in a constant
expression if the arguments can be converted to primitives in constant expressions.
if |args| {1, 2} then
throw an
ArgumentError exception
— at least one and at most two arguments must be supplied
end if;
case i of
end case
end proc;
note This function can be used in a constant
expression if its argument can be converted to a primitive in a constant expression.
if |args| 1 then
throw an
ArgumentError exception
— exactly one argument must be supplied
end if;
Apply the lexer grammar with the start symbol
StringDecimalLiteral to the string
s. If the grammar can interpret neither
s nor any prefix of
s as an expansion of
StringDecimalLiteral, then
return NaNf64. Otherwise, let
p be the longest prefix of
s (possibly
s itself) such that
p is an
expansion of
StringDecimalLiteral.
q:
ExtendedRational
the value of the action
Lex applied to
p’s expansion of the nonterminal
StringDecimalLiteral;
end proc;
note This function can be used in a constant
expression if its argument can be converted to a primitive in a constant expression.
if |args| 1 then
throw an
ArgumentError exception
— exactly one argument must be supplied
end if;
return x {NaNf32, NaNf64}
end proc;
note This function can be used in a constant
expression if its argument can be converted to a primitive in a constant expression.
if |args| 1 then
throw an
ArgumentError exception
— exactly one argument must be supplied
end if;
return x {NaNf32, NaNf64, +f32, +f64, –f32, –f64}
end proc;
Evaluate ???? and ignore its result
end proc;
Evaluate ???? and ignore its result
end proc;
Evaluate ???? and ignore its result
end proc;
Evaluate ???? and ignore its result
end proc;
Built-in Classes
Evaluate ???? and ignore its result
end proc;
Evaluate ???? and ignore its result
end proc;
Object
Object:
Class
=
new ClasslocalBindings: {},
instanceProperties: {},
super:
none,
prototype:
ObjectPrototype,
complete:
true,
name: “
Object
”,
typeofString: “
object
”,
dynamic:
true,
final:
false,
defaultValue:
undefined,
defaultHint:
hintNumber,
hasProperty:
ordinaryHasProperty,
bracketRead:
ordinaryBracketRead,
bracketWrite:
ordinaryBracketWrite,
bracketDelete:
ordinaryBracketDelete,
read:
ordinaryRead,
write:
ordinaryWrite,
delete:
ordinaryDelete,
enumerate:
ordinaryEnumerate,
call:
callObject,
construct:
constructObject,
init:
none,
is:
ordinaryIs,
coerce:
coerceObject;
note This function does not check phase
and therefore can be used in a constant expression.
elsif |args| = 1 then return args[0]
else throw an
ArgumentError exception
— at most one argument can be supplied
end if
end proc;
note This function does not check phase
and therefore can be used in a constant expression.
if |args| > 1 then
throw an
ArgumentError exception
— at most one argument can be supplied
end if;
else return o
end if
end proc;
ObjectPrototype:
SimpleInstance
=
new SimpleInstancelocalBindings:
{
stdConstBinding(
public::“
constructor
”,
Class,
Object),
stdFunction(
public::“
toString
”,
Object_toString, 0),
stdFunction(
public::“
toLocaleString
”,
Object_toLocaleString, 0),
stdFunction(
public::“
valueOf
”,
Object_valueOf, 0),
stdFunction(
public::“
hasOwnProperty
”,
Object_hasOwnProperty, 1),
stdFunction(
public::“
isPrototypeOf
”,
Object_isPrototypeOf, 1),
stdFunction(
public::“
propertyIsEnumerable
”,
Object_propertyIsEnumerable, 1),
stdFunction(
public::“
sealProperty
”,
Object_sealProperty, 1)},
archetype:
none,
sealed:
prototypesSealed,
type:
Object,
slots: {},
call:
none,
construct:
none,
env:
none;
note This function does not check phase
and therefore can be used in a constant expression.
note This function ignores any arguments passed to it
in args.
return “
[object
”
c.
name “
]
”
end proc;
throw a
ConstantError exception
—
toLocaleString
cannot be called from a constant expression
end if;
return call(
this,
toStringMethod,
args,
phase)
end proc;
note This function does not check phase
and therefore can be used in a constant expression.
note This function ignores any arguments passed to it
in args.
return this
end proc;
throw a
ConstantError exception
—
hasOwnProperty
cannot be called from a constant expression
end if;
if |args| 1 then
throw an
ArgumentError exception
— exactly one argument must be supplied
end if;
end proc;
throw a
ConstantError exception
—
isPrototypeOf
cannot be called from a constant expression
end if;
if |args| 1 then
throw an
ArgumentError exception
— exactly one argument must be supplied
end if;
end proc;
throw a
ConstantError exception
—
propertyIsEnumerable
cannot be called from a constant expression
end if;
if |args| 1 then
throw an
ArgumentError exception
— exactly one argument must be supplied
end if;
end if;
end if;
end proc;
throw a
ConstantError exception
—
sealProperty
cannot be called from a constant expression
end if;
if |args| > 1 then
throw an
ArgumentError exception
— at most one argument can be supplied
end if;
if arg =
false then Evaluate
sealObject(
this) and ignore its result
elsif arg = true then
end if;
end proc;
Never
Never:
Class
=
new ClasslocalBindings: {},
instanceProperties: {},
super:
Object,
prototype:
none,
complete:
true,
name: “
Never
”,
typeofString: “”,
dynamic:
false,
final:
true,
defaultValue:
none,
hasProperty:
ordinaryHasProperty,
bracketRead:
ordinaryBracketRead,
bracketWrite:
ordinaryBracketWrite,
bracketDelete:
ordinaryBracketDelete,
read:
ordinaryRead,
write:
ordinaryWrite,
delete:
ordinaryDelete,
enumerate:
ordinaryEnumerate,
call:
sameAsConstruct,
construct:
constructNever,
init:
none,
is:
ordinaryIs,
coerce:
coerceNever;
if |args| > 1 then
throw an
ArgumentError exception
— at most one argument can be supplied
end if;
throw a
TypeError exception
— no coercions to
Never
are possible
end proc;
Void
Void:
Class
=
new ClasslocalBindings: {},
instanceProperties: {},
super:
Object,
prototype:
none,
complete:
true,
name: “
Void
”,
typeofString: “
undefined
”,
dynamic:
false,
final:
true,
defaultValue:
undefined,
hasProperty:
ordinaryHasProperty,
bracketRead:
ordinaryBracketRead,
bracketWrite:
ordinaryBracketWrite,
bracketDelete:
ordinaryBracketDelete,
read:
ordinaryRead,
write:
ordinaryWrite,
delete:
ordinaryDelete,
enumerate:
ordinaryEnumerate,
call:
callVoid,
construct:
constructVoid,
init:
none,
is:
ordinaryIs,
coerce:
coerceVoid;
note This function does not check phase
and therefore can be used in a constant expression.
if |args| > 1 then
throw an
ArgumentError exception
— at most one argument can be supplied
end if;
end proc;
note This function does not check phase
and therefore can be used in a constant expression.
if |
args| 0
then throw an
ArgumentError exception
— no arguments can be supplied
end if;
end proc;
Null
Null:
Class
=
new ClasslocalBindings: {},
instanceProperties: {},
super:
Object,
prototype:
none,
complete:
true,
name: “
Null
”,
typeofString: “
object
”,
dynamic:
false,
final:
true,
defaultValue:
null,
hasProperty:
ordinaryHasProperty,
bracketRead:
ordinaryBracketRead,
bracketWrite:
ordinaryBracketWrite,
bracketDelete:
ordinaryBracketDelete,
read:
ordinaryRead,
write:
ordinaryWrite,
delete:
ordinaryDelete,
enumerate:
ordinaryEnumerate,
call:
callNull,
construct:
constructNull,
init:
none,
is:
ordinaryIs,
coerce:
coerceNull;
note This function does not check phase
and therefore can be used in a constant expression.
if |args| > 1 then
throw an
ArgumentError exception
— at most one argument can be supplied
end if;
end proc;
note This function does not check phase
and therefore can be used in a constant expression.
if |
args| 0
then throw an
ArgumentError exception
— no arguments can be supplied
end if;
end proc;
if o =
null then return o else return none end if
end proc;
Boolean
Boolean:
Class
=
new ClasslocalBindings: {},
instanceProperties: {},
super:
Object,
prototype:
BooleanPrototype,
complete:
true,
name: “
Boolean
”,
typeofString: “
boolean
”,
dynamic:
false,
final:
true,
defaultValue:
false,
hasProperty:
ordinaryHasProperty,
bracketRead:
ordinaryBracketRead,
bracketWrite:
ordinaryBracketWrite,
bracketDelete:
ordinaryBracketDelete,
read:
ordinaryRead,
write:
ordinaryWrite,
delete:
ordinaryDelete,
enumerate:
ordinaryEnumerate,
call:
sameAsConstruct,
construct:
constructBoolean,
init:
none,
is:
ordinaryIs,
coerce:
coerceBoolean;
note This function does not check phase
and therefore can be used in a constant expression.
if |args| > 1 then
throw an
ArgumentError exception
— at most one argument can be supplied
end if;
end proc;
BooleanPrototype:
SimpleInstance
=
new SimpleInstancelocalBindings:
{
stdConstBinding(
public::“
constructor
”,
Class,
Boolean),
stdFunction(
public::“
toString
”,
Boolean_toString, 0),
stdReserve(
public::“
valueOf
”,
ObjectPrototype)},
archetype:
ObjectPrototype,
sealed:
prototypesSealed,
type:
Object,
slots: {},
call:
none,
construct:
none,
env:
none;
note This function can be used in a constant
expression.
note This function ignores any arguments passed to it
in args.
end proc;
GeneralNumber
GeneralNumber:
Class
=
new ClasslocalBindings: {},
instanceProperties: {},
super:
Object,
prototype:
GeneralNumberPrototype,
complete:
true,
name: “
GeneralNumber
”,
typeofString: “
object
”,
dynamic:
false,
final:
true,
defaultValue:
NaNf64,
defaultHint:
hintNumber,
hasProperty:
ordinaryHasProperty,
bracketRead:
ordinaryBracketRead,
bracketWrite:
ordinaryBracketWrite,
bracketDelete:
ordinaryBracketDelete,
read:
ordinaryRead,
write:
ordinaryWrite,
delete:
ordinaryDelete,
enumerate:
ordinaryEnumerate,
call:
sameAsConstruct,
construct:
constructGeneralNumber,
init:
none,
is:
ordinaryIs,
coerce:
coerceGeneralNumber;
note This function can be used in a constant
expression if the argument can be converted to a primitive in a constant expression.
if |args| = 0 then return +zerof64
else throw an
ArgumentError exception
— at most one argument can be supplied
end if
end proc;
GeneralNumberPrototype:
SimpleInstance
=
new SimpleInstancelocalBindings:
{
stdConstBinding(
public::“
constructor
”,
Class,
GeneralNumber),
stdFunction(
public::“
toString
”,
GeneralNumber_toString, 1),
stdReserve(
public::“
valueOf
”,
ObjectPrototype),
stdFunction(
public::“
toFixed
”,
GeneralNumber_toFixed, 1),
stdFunction(
public::“
toExponential
”,
GeneralNumber_toExponential, 1),
stdFunction(
public::“
toPrecision
”,
GeneralNumber_toPrecision, 1)},
archetype:
ObjectPrototype,
sealed:
prototypesSealed,
type:
Object,
slots: {},
call:
none,
construct:
none,
env:
none;
note This function can be used in a constant
expression if this and the argument can be converted to primitives in constant expressions.
note This function is generic and can be applied even
if this is not a general number.
if radix < 2
or radix > 36
then throw a
RangeError exception
— bad radix
end if;
else
return x converted to a string containing a
base-radix number in an implementation-defined manner
end if
end proc;
precisionLimit:
Integer = an
implementation-defined integer not less than 20;
note This function can be used in a constant
expression if this and the argument can be converted to primitives in constant expressions.
note This function is generic and can be applied even
if this is not a general number.
if |args| > 1 then
throw an
ArgumentError exception
— at most one argument can be supplied
end if;
end if;
if r < 0 then sign “-
”; r –r end if;
n:
Integer r10
fractionDigits + 1/2;
if fractionDigits = 0 then return sign digits
else
if |digits| fractionDigits then
digits repeat(‘
0
’,
fractionDigits + 1 – |
digits|)
digits
end if;
k:
Integer |
digits| –
fractionDigits;
return sign digits[0 ... k – 1] “.
” digits[k ...]
end if
end proc;
note This function can be used in a constant
expression if this and the argument can be converted to primitives in constant expressions.
note This function is generic and can be applied even
if this is not a general number.
if |args| > 1 then
throw an
ArgumentError exception
— at most one argument can be supplied
end if;
if fractionDigits {
+,
–}
or
(
fractionDigits NaN and (
fractionDigits < 0
or fractionDigits >
precisionLimit))
then
end if;
if r < 0 then sign “-
”; r –r end if;
if fractionDigits NaN then
if r = 0
then digits repeat(‘
0
’,
fractionDigits + 1);
e 0
else
e log10(r);
n:
Integer r10
fractionDigits–e + 1/2;
note At this point
10fractionDigits n 10fractionDigits+1
if n = 10fractionDigits+1 then n n/10; e e + 1 end if;
end if;
note At this point the string digits has
exactly fractionDigits + 1 digits
elsif r = 0 then digits “0
”; e 0
e |digits| – 1;
while digits[|digits| – 1] = ‘0
’ do digits digits[0 ... |digits| – 2] end while
else
case x of
Let e, k, and s be integers such that k
1, 10k–1
s
10k,
(s10e+1–k)f32
= x, and k is as small as possible.
Let e, k, and s be integers such that k
1, 10k–1
s
10k,
(s10e+1–k)f64
= x, and k is as small as possible.
end case;
note k is the number of digits in the
decimal representation of s, s is not divisible by 10, and the least significant digit of
s is not necessarily uniquely determined by the above criteria.
When there are multiple possibilities for s according to the rules above,
implementations are encouraged but not required to select the one according to the following rules: Select the
value of s for which
s10e+1–k
is closest in value to r; if there are two such possible values of s, choose the one that
is even.
end if;
end proc;
note This function can be used in a constant
expression if this and the argument can be converted to primitives in constant expressions.
note This function is generic and can be applied even
if this is not a general number.
if |args| > 1 then
throw an
ArgumentError exception
— at most one argument can be supplied
end if;
end if;
if r < 0 then sign “-
”; r –r end if;
if r = 0
then digits repeat(‘
0
’,
precision);
e 0
else
e log10(r);
note At this point
10precision–1 n 10precision
if n = 10precision then n n/10; e e + 1 end if;
end if;
note At this point the string digits has
exactly precision digits
elsif e = precision – 1 then return sign digits
elsif e 0 then return sign digits[0 ... e] “.
” digits[e + 1 ...]
else return sign “
0.
”
repeat(‘
0
’, –(
e + 1))
digits
end if
end proc;
long
long:
Class
=
new ClasslocalBindings:
{
stdConstBinding(
public::“
MAX_VALUE
”,
ulong, (2
63 – 1)
long),
stdConstBinding(
public::“
MIN_VALUE
”,
ulong, (–2
63)
long)},
instanceProperties: {},
super:
GeneralNumber,
prototype:
longPrototype,
complete:
true,
name: “
long
”,
typeofString: “
long
”,
dynamic:
false,
final:
true,
defaultValue: 0
long,
hasProperty:
ordinaryHasProperty,
bracketRead:
ordinaryBracketRead,
bracketWrite:
ordinaryBracketWrite,
bracketDelete:
ordinaryBracketDelete,
read:
ordinaryRead,
write:
ordinaryWrite,
delete:
ordinaryDelete,
enumerate:
ordinaryEnumerate,
call:
sameAsConstruct,
construct:
constructLong,
init:
none,
is:
ordinaryIs,
coerce:
coerceLong;
note This function can be used in a constant
expression if the argument can be converted to a primitive in a constant expression.
if |args| > 1 then
throw an
ArgumentError exception
— at most one argument can be supplied
end if;
if –263 i 263 – 1 then return ilong
end if
end proc;
if i none and –2
63 i 2
63 – 1
then return ilong
end if
end proc;
longPrototype:
SimpleInstance
=
new SimpleInstancelocalBindings:
{
stdConstBinding(
public::“
constructor
”,
Class,
long),
stdReserve(
public::“
toString
”,
GeneralNumberPrototype),
stdReserve(
public::“
valueOf
”,
GeneralNumberPrototype)},
archetype:
GeneralNumberPrototype,
sealed:
prototypesSealed,
type:
Object,
slots: {},
call:
none,
construct:
none,
env:
none;
ulong
ulong:
Class
=
new ClasslocalBindings:
{
stdConstBinding(
public::“
MAX_VALUE
”,
ulong, (2
64 – 1)
ulong),
stdConstBinding(
public::“
MIN_VALUE
”,
ulong, 0
ulong)},
instanceProperties: {},
super:
GeneralNumber,
prototype:
ulongPrototype,
complete:
true,
name: “
ulong
”,
typeofString: “
ulong
”,
dynamic:
false,
final:
true,
defaultValue: 0
ulong,
hasProperty:
ordinaryHasProperty,
bracketRead:
ordinaryBracketRead,
bracketWrite:
ordinaryBracketWrite,
bracketDelete:
ordinaryBracketDelete,
read:
ordinaryRead,
write:
ordinaryWrite,
delete:
ordinaryDelete,
enumerate:
ordinaryEnumerate,
call:
sameAsConstruct,
construct:
constructULong,
init:
none,
is:
ordinaryIs,
coerce:
coerceULong;
note This function can be used in a constant
expression if the argument can be converted to a primitive in a constant expression.
if |args| > 1 then
throw an
ArgumentError exception
— at most one argument can be supplied
end if;
if 0 i 264 – 1 then return iulong
end if
end proc;
if i none and 0
i 2
64 – 1
then return iulong
end if
end proc;
ulongPrototype:
SimpleInstance
=
new SimpleInstancelocalBindings:
{
stdConstBinding(
public::“
constructor
”,
Class,
ulong),
stdReserve(
public::“
toString
”,
GeneralNumberPrototype),
stdReserve(
public::“
valueOf
”,
GeneralNumberPrototype)},
archetype:
GeneralNumberPrototype,
sealed:
prototypesSealed,
type:
Object,
slots: {},
call:
none,
construct:
none,
env:
none;
float
float:
Class
=
new ClasslocalBindings:
{
stdConstBinding(
public::“
MAX_VALUE
”,
float, (3.402823510
38)
f32),
stdConstBinding(
public::“
MIN_VALUE
”,
float, (10
–45)
f32),
stdConstBinding(
public::“
NaN
”,
float,
NaNf32),
stdConstBinding(
public::“
NEGATIVE_INFINITY
”,
float,
–f32),
stdConstBinding(
public::“
POSITIVE_INFINITY
”,
float,
+f32)},
instanceProperties: {},
super:
GeneralNumber,
prototype:
floatPrototype,
complete:
true,
name: “
float
”,
typeofString: “
float
”,
dynamic:
false,
final:
true,
defaultValue:
NaNf32,
hasProperty:
ordinaryHasProperty,
bracketRead:
ordinaryBracketRead,
bracketWrite:
ordinaryBracketWrite,
bracketDelete:
ordinaryBracketDelete,
read:
ordinaryRead,
write:
ordinaryWrite,
delete:
ordinaryDelete,
enumerate:
ordinaryEnumerate,
call:
sameAsConstruct,
construct:
constructFloat,
init:
none,
is:
ordinaryIs,
coerce:
coerceFloat;
note This function can be used in a constant
expression if the argument can be converted to a primitive in a constant expression.
if |args| = 0 then return +zerof32
else throw an
ArgumentError exception
— at most one argument can be supplied
end if
end proc;
floatPrototype:
SimpleInstance
=
new SimpleInstancelocalBindings:
{
stdConstBinding(
public::“
constructor
”,
Class,
float),
stdReserve(
public::“
toString
”,
GeneralNumberPrototype),
stdReserve(
public::“
valueOf
”,
GeneralNumberPrototype)},
archetype:
GeneralNumberPrototype,
sealed:
prototypesSealed,
type:
Object,
slots: {},
call:
none,
construct:
none,
env:
none;
Number
Number:
Class
=
new ClasslocalBindings:
{
stdConstBinding(
public::“
MAX_VALUE
”,
Number, (1.797693134862315710
308)
f64),
stdConstBinding(
public::“
MIN_VALUE
”,
Number, (510
–324)
f64),
stdConstBinding(
public::“
NaN
”,
Number,
NaNf64),
stdConstBinding(
public::“
NEGATIVE_INFINITY
”,
Number,
–f64),
stdConstBinding(
public::“
POSITIVE_INFINITY
”,
Number,
+f64)},
instanceProperties: {},
super:
GeneralNumber,
prototype:
NumberPrototype,
complete:
true,
name: “
Number
”,
typeofString: “
number
”,
dynamic:
false,
final:
true,
defaultValue:
NaNf64,
hasProperty:
ordinaryHasProperty,
bracketRead:
ordinaryBracketRead,
bracketWrite:
ordinaryBracketWrite,
bracketDelete:
ordinaryBracketDelete,
read:
ordinaryRead,
write:
ordinaryWrite,
delete:
ordinaryDelete,
enumerate:
ordinaryEnumerate,
call:
sameAsConstruct,
construct:
constructNumber,
init:
none,
is:
ordinaryIs,
coerce:
coerceNumber;
note This function can be used in a constant
expression if the argument can be converted to a primitive in a constant expression.
if |args| = 0 then return +zerof64
else throw an
ArgumentError exception
— at most one argument can be supplied
end if
end proc;
NumberPrototype:
SimpleInstance
=
new SimpleInstancelocalBindings:
{
stdConstBinding(
public::“
constructor
”,
Class,
Number),
stdReserve(
public::“
toString
”,
GeneralNumberPrototype),
stdReserve(
public::“
valueOf
”,
GeneralNumberPrototype)},
archetype:
GeneralNumberPrototype,
sealed:
prototypesSealed,
type:
Object,
slots: {},
call:
none,
construct:
none,
env:
none;
note This function can be used in a constant
expression if the argument can be converted to a primitive in a constant expression.
if |args| > 1 then
throw an
ArgumentError exception
— at most one argument can be supplied
end if;
if i none and low i high then
note –zerof64
is coerced to +zerof64.
return if64
end if;
end proc;
if o Float64 then return false end if;
return i none and low i high
end proc;
if i none and low i high then
note –zerof32,
+zerof32, and –zerof64 are
all coerced to +zerof64.
return if64
end if;
end proc;
return new ClasslocalBindings:
{
stdConstBinding(
public::“
MAX_VALUE
”,
Number,
highf64),
stdConstBinding(
public::“
MIN_VALUE
”,
Number,
lowf64)},
instanceProperties: {},
super:
Number,
prototype:
Number.
prototype,
complete:
true,
name:
name,
typeofString: “
number
”,
dynamic:
false,
final:
true,
defaultValue:
+zerof64,
hasProperty:
Number.
hasProperty,
bracketRead:
Number.
bracketRead,
bracketWrite:
Number.
bracketWrite,
bracketDelete:
Number.
bracketDelete,
read:
Number.
read,
write:
Number.
write,
delete:
Number.
delete,
enumerate:
Number.
enumerate,
call:
sameAsConstruct,
construct:
construct,
init:
none,
is:
is,
coerce:
coerce
end proc;
char
char:
Class
=
new ClasslocalBindings: {
stdFunction(
public::“
fromCharCode
”,
char_fromCharCode, 1)},
instanceProperties: {},
super:
Object,
prototype:
charPrototype,
complete:
true,
name: “
char
”,
typeofString: “
char
”,
dynamic:
false,
final:
true,
defaultValue: ‘
«NUL»
’,
hasProperty:
ordinaryHasProperty,
bracketRead:
ordinaryBracketRead,
bracketWrite:
ordinaryBracketWrite,
bracketDelete:
ordinaryBracketDelete,
read:
ordinaryRead,
write:
ordinaryWrite,
delete:
ordinaryDelete,
enumerate:
ordinaryEnumerate,
call:
sameAsConstruct,
construct:
constructChar,
init:
none,
is:
ordinaryIs,
coerce:
coerceChar;
note This function can be used in a constant
expression if the argument can be converted to a primitive in a constant expression.
if |args| 1 then
throw an
ArgumentError exception
— exactly one argument must be supplied
end if;
if |
s| 1
then throw a
RangeError exception
— only one character may be
given
end if;
return s[0]
end proc;
note This function can be used in a constant
expression if the argument can be converted to a primitive in a constant expression.
if |args| > 1 then
throw an
ArgumentError exception
— at most one argument can be supplied
end if;
elsif arg Char16 then return arg
else
if |
s| 1
then throw a
RangeError exception
— only one character may be given
end if;
return s[0]
end if
end proc;
note This function can be used in a constant
expression if the argument can be converted to a primitive in a constant expression.
if |args| 1 then
throw an
ArgumentError exception
— exactly one argument must be supplied
end if;
else throw a
RangeError exception
— character code out of range
end if
end proc;
charPrototype:
SimpleInstance
=
new SimpleInstancelocalBindings:
{
stdConstBinding(
public::“
constructor
”,
Class,
char),
stdReserve(
public::“
toString
”,
StringPrototype),
stdReserve(
public::“
valueOf
”,
StringPrototype)},
archetype:
StringPrototype,
sealed:
prototypesSealed,
type:
Object,
slots: {},
call:
none,
construct:
none,
env:
none;
String
String:
Class
=
new ClasslocalBindings: {
stdFunction(
public::“
fromCharCode
”,
String_fromCharCode, 1)},
instanceProperties: {
new InstanceGettermultiname: {
public::“
length
”},
final:
true,
enumerable:
false,
call:
String_length},
super:
Object,
prototype:
StringPrototype,
complete:
true,
name: “
String
”,
typeofString: “
string
”,
dynamic:
false,
final:
true,
defaultValue:
null,
hasProperty:
stringHasProperty,
bracketRead:
ordinaryBracketRead,
bracketWrite:
ordinaryBracketWrite,
bracketDelete:
ordinaryBracketDelete,
read:
readString,
write:
ordinaryWrite,
delete:
ordinaryDelete,
enumerate:
ordinaryEnumerate,
call:
sameAsConstruct,
construct:
constructString,
init:
none,
is:
ordinaryIs,
coerce:
coerceString;
if i none then return i < |
o|
else
return findBaseInstanceProperty(
c, {
qname},
read)
none or
findBaseInstanceProperty(
c, {
qname},
write)
none or
findArchetypeProperty(
o, {
qname},
read,
flat)
none or
findArchetypeProperty(
o, {
qname},
write,
flat)
none
end if
end proc;
if i < |o| then return o[i]
elsif undefinedIfMissing then return undefined
end if
end if
end if;
return ordinaryRead(
o,
limit,
multiname,
env,
undefinedIfMissing,
phase)
end proc;
note This function can be used in a constant
expression if the argument can be converted to a primitive in a constant expression.
if |args| = 0 then return “”
else throw an
ArgumentError exception
— at most one argument can be supplied
end if
end proc;
elsif o Char16 then return [o]
end if
end proc;
note this String
because this getter cannot be extracted from the
String
class.
return lengthf64
end proc;
note This function can be used in a constant
expression if the arguments can be converted to primitives in constant expressions.
for each arg args do
else throw a
RangeError exception
— character code out of range
end if
end for each;
return s
end proc;
StringPrototype:
SimpleInstance
=
new SimpleInstancelocalBindings:
{
stdConstBinding(
public::“
constructor
”,
Class,
String),
stdFunction(
public::“
toString
”,
String_toString, 0),
stdReserve(
public::“
valueOf
”,
ObjectPrototype),
stdFunction(
public::“
charAt
”,
String_charAt, 1),
stdFunction(
public::“
charCodeAt
”,
String_charCodeAt, 1),
stdFunction(
public::“
concat
”,
String_concat, 1),
stdFunction(
public::“
indexOf
”,
String_indexOf, 1),
stdFunction(
public::“
lastIndexOf
”,
String_lastIndexOf, 1),
stdFunction(
public::“
localeCompare
”,
String_localeCompare, 1),
stdFunction(
public::“
match
”,
String_match, 1),
stdFunction(
public::“
replace
”,
String_replace, 1),
stdFunction(
public::“
search
”,
String_search, 1),
stdFunction(
public::“
slice
”,
String_slice, 2),
stdFunction(
public::“
split
”,
String_split, 2),
stdFunction(
public::“
substring
”,
String_substring, 2),
stdFunction(
public::“
toLowerCase
”,
String_toLowerCase, 0),
stdFunction(
public::“
toLocaleLowerCase
”,
String_toLocaleLowerCase, 0),
stdFunction(
public::“
toUpperCase
”,
String_toUpperCase, 0),
stdFunction(
public::“
toLocaleUpperCase
”,
String_toLocaleUpperCase, 0)},
archetype:
ObjectPrototype,
sealed:
prototypesSealed,
type:
Object,
slots: {},
call:
none,
construct:
none,
env:
none;
note This function can be used in a constant
expression if this can be converted to a primitive in a constant expression.
note This function is generic and can be applied even
if this is not a string.
note This function ignores any arguments passed to it
in args.
end proc;
note This function can be used in a constant
expression if this and the argument can be converted to primitives in constant expressions.
note This function is generic and can be applied even
if this is not a string.
if |args| > 1 then
throw an
ArgumentError exception
— at most one argument can be supplied
end if;
elsif position {
+,
–}
and 0
position < |
s|
then return [s[
position]
]
else return “”
end if
end proc;
note This function can be used in a constant
expression if this and the argument can be converted to primitives in constant expressions.
note This function is generic and can be applied even
if this is not a string.
if |args| > 1 then
throw an
ArgumentError exception
— at most one argument can be supplied
end if;
elsif position {
+,
–}
and 0
position < |
s|
then
else return NaNf64
end if
end proc;
note This function can be used in a constant
expression if this and the argument can be converted to primitives in constant expressions.
note This function is generic and can be applied even
if this is not a string.
return s
end proc;
note This function can be used in a constant
expression if this and the arguments can be converted to primitives in constant expressions.
note This function is generic and can be applied even
if this is not a string.
if |args| {1, 2} then
throw an
ArgumentError exception
— at least one and at most two arguments must be supplied
end if;
while position + |pattern| |s| do
if s[position ... position + |pattern| – 1] = pattern then return positionf64
end if;
position position + 1
end while;
return (–1)f64
end proc;
note This function can be used in a constant
expression if this and the arguments can be converted to primitives in constant expressions.
note This function is generic and can be applied even
if this is not a string.
if |args| {1, 2} then
throw an
ArgumentError exception
— at least one and at most two arguments must be supplied
end if;
if position + |pattern| > |s| then position |s| – |pattern| end if;
while position 0 do
if s[position ... position + |pattern| – 1] = pattern then return positionf64
end if;
position position – 1
end while;
return (–1)f64
end proc;
note This function is generic and can be applied even
if this is not a string.
throw a
ConstantError exception
—
localeCompare
cannot be called from a constant expression
end if;
if |args| < 1 then
throw an
ArgumentError exception
— at least one argument must be supplied
end if;
Let
result:
Object be a value of type
Number that is the result of a locale-sensitive string comparison of
s1 and
s2. The two strings are compared in an implementation-defined fashion. The result is
intended to order strings in the sort order specified by the system default locale, and will be negative, zero, or
positive, depending on whether
s1 comes before
s2 in the sort order, they are equal, or
s1 comes after
s2 in the sort order, respectively. The result shall not be
NaNf64. The comparison shall be a consistent comparison function on the set
of all strings.
return result
end proc;
note This function is generic and can be applied even
if this is not a string.
throw a
ConstantError exception
—
match
cannot be called from a constant expression
end if;
if |args| 1 then
throw an
ArgumentError exception
— exactly one argument must be supplied
end if;
Evaluate ???? and ignore its result
end proc;
note This function is generic and can be applied even
if this is not a string.
throw a
ConstantError exception
—
replace
cannot be called from a constant expression
end if;
if |args| 2 then
throw an
ArgumentError exception
— exactly two arguments must be supplied
end if;
Evaluate ???? and ignore its result
end proc;
note This function is generic and can be applied even
if this is not a string.
throw a
ConstantError exception
—
search
cannot be called from a constant expression
end if;
if |args| 1 then
throw an
ArgumentError exception
— exactly one argument must be supplied
end if;
Evaluate ???? and ignore its result
end proc;
note This function can be used in a constant
expression if this and the arguments can be converted to primitives in constant expressions.
note This function is generic and can be applied even
if this is not a string.
if |args| > 2 then
throw an
ArgumentError exception
— at most two arguments can be supplied
end if;
if start < end then return s[start ... end – 1] else return “” end if
end proc;
note This function is generic and can be applied even
if this is not a string.
throw a
ConstantError exception
—
split
cannot be called from a constant expression
end if;
if |args| > 2 then
throw an
ArgumentError exception
— at most two arguments can be supplied
end if;
Evaluate ???? and ignore its result
end proc;
note This function can be used in a constant
expression if this and the arguments can be converted to primitives in constant expressions.
note This function is generic and can be applied even
if this is not a string.
if |args| > 2 then
throw an
ArgumentError exception
— at most two arguments can be supplied
end if;
if start end then return s[start ... end – 1]
else return s[end ... start – 1]
end if
end proc;
note This function can be used in a constant
expression if this can be converted to a primitive in a constant expression.
note This function is generic and can be applied even
if this is not a string.
return r
end proc;
note This function is generic and can be applied even
if this is not a string.
throw a
ConstantError exception
—
toLocaleLowerCase
cannot be called from a constant expression
end if;
return r
end proc;
note This function can be used in a constant
expression if this can be converted to a primitive in a constant expression.
note This function is generic and can be applied even
if this is not a string.
return r
end proc;
note This function is generic and can be applied even
if this is not a string.
throw a
ConstantError exception
—
toLocaleUpperCase
cannot be called from a constant expression
end if;
return r
end proc;
Array
Array:
Class
=
new ClasslocalBindings: {},
instanceProperties: {
new InstanceVariablemultiname: {
arrayPrivate::“
length
”},
final:
true,
enumerable:
false,
type:
Number,
defaultValue:
+zerof64,
immutable:
false,
new InstanceGettermultiname: {
public::“
length
”},
final:
true,
enumerable:
false,
call:
Array_getLength,
new InstanceSettermultiname: {
public::“
length
”},
final:
true,
enumerable:
false,
call:
Array_setLength},
super:
Object,
prototype:
ArrayPrototype,
complete:
true,
name: “
Array
”,
typeofString: “
object
”,
privateNamespace:
arrayPrivate,
dynamic:
true,
final:
true,
defaultValue:
null,
defaultHint:
hintNumber,
hasProperty:
ordinaryHasProperty,
bracketRead:
ordinaryBracketRead,
bracketWrite:
ordinaryBracketWrite,
bracketDelete:
ordinaryBracketDelete,
read:
ordinaryRead,
write:
writeArray,
delete:
ordinaryDelete,
enumerate:
ordinaryEnumerate,
call:
sameAsConstruct,
construct:
ordinaryConstruct,
init:
initArray,
is:
ordinaryIs,
coerce:
ordinaryCoerce;
arrayLimit:
Integer
= an implementation-defined integer value between 2
32 – 1 and 2
53 inclusive;
throw a
RangeError exception
— array index out of range
end if;
if i length then
end if
end if
end if;
return result
end proc;
note length {NaNf64, +f64, –f64};
return n
end proc;
throw a
RangeError exception
— array length out of range
end if;
end proc;
if |
multiname| 1
then return none end if;
if name [] then
if name = “0
” then return 0
elsif name[0] ‘0
’ and (every ch name satisfies ch {‘0
’ ... ‘9
’}) then
end if
end if;
end proc;
if |args| = 1 then
throw a
RangeError exception
— array length must be an integer
end if;
return
end if
end if;
for each arg args do
Evaluate
indexWrite(
this,
i,
arg,
phase) and ignore its result;
i i + 1
end for each;
note The call to
indexWrite above also set the array’s length to
i.
end proc;
note is(
this,
Array)
because this getter cannot be extracted from the
Array
class.
end proc;
note is(
this,
Array)
because this setter cannot be extracted from the
Array
class.
throw a
ConstantError exception
— an array’s
length
cannot be set from a constant expression
end if;
throw a
RangeError exception
— array length out of range or not an integer
end if;
if newLength < oldLength then
note Delete all indexed properties greater than or
equal to the new length
return i none and newLength i <
oldLength
end proc;
end if;
end proc;
ArrayPrototype:
SimpleInstance
=
new SimpleInstancelocalBindings:
{
stdConstBinding(
public::“
constructor
”,
Class,
Array),
stdFunction(
public::“
toString
”,
Array_toString, 0),
stdFunction(
public::“
toLocaleString
”,
Array_toLocaleString, 0),
stdFunction(
public::“
concat
”,
Array_concat, 1),
stdFunction(
public::“
join
”,
Array_join, 1),
stdFunction(
public::“
pop
”,
Array_pop, 0),
stdFunction(
public::“
push
”,
Array_push, 1),
stdFunction(
public::“
reverse
”,
Array_reverse, 0),
stdFunction(
public::“
shift
”,
Array_shift, 0),
stdFunction(
public::“
slice
”,
Array_slice, 2),
stdFunction(
public::“
sort
”,
Array_sort, 1),
stdFunction(
public::“
splice
”,
Array_splice, 2),
stdFunction(
public::“
unshift
”,
Array_unshift, 1)},
archetype:
ObjectPrototype,
sealed:
prototypesSealed,
type:
Object,
slots: {},
call:
none,
construct:
none,
env:
none;
throw a
ConstantError exception
—
toString
cannot be called on an
Array
from a constant expression
end if;
note This function is generic and can be applied even
if this is not an Array
.
note This function ignores any arguments passed to it
in args.
end proc;
throw a
ConstantError exception
—
toLocaleString
cannot be called on an
Array
from a constant expression
end if;
note This function is generic and can be applied even
if this is not an Array
.
note This function passes any arguments passed to it
in args to toLocaleString
applied to the elements of the array.
separator:
String
the list-separator string appropriate for the host’s current locale, derived in an implementation-defined
way;
while i length do
s:
Object call(
elt,
toLocaleStringMethod,
args,
phase);
throw a
TypeError exception
—
toLocaleString
should return a string
end if;
end if;
i i + 1;
if i length then result result separator end if
end while;
return result
end proc;
throw a
ConstantError exception
—
concat
cannot be called from a constant expression
end if;
note This function is generic and can be applied even
if this is not an Array
.
constituents:
Object[]
[this] args;
for each o constituents do
while k oLength do
Evaluate
indexWrite(
array,
i,
elt,
phase) and ignore its result
end if;
k k + 1;
i i + 1
end while
else Evaluate
indexWrite(
array,
i,
o,
phase) and ignore its result;
i i + 1
end if
end for each;
return array
end proc;
throw a
ConstantError exception
—
join
cannot be called from a constant expression
end if;
note This function is generic and can be applied even
if this is not an Array
.
if |args| > 1 then
throw an
ArgumentError exception
— at most one argument can be supplied
end if;
end proc;
while i length do
end if;
i i + 1;
if i length then result result separator end if
end while;
return result
end proc;
throw a
ConstantError exception
—
pop
cannot be called from a constant expression
end if;
note This function is generic and can be applied even
if this is not an Array
.
if |
args| 0
then throw an
ArgumentError exception
— no arguments can be supplied
end if;
if length 0 then
length length – 1;
end if
end if;
Evaluate
writeLength(
this,
length,
phase) and ignore its result;
return result
end proc;
throw a
ConstantError exception
—
push
cannot be called from a constant expression
end if;
note This function is generic and can be applied even
if this is not an Array
.
for each arg args do
Evaluate
indexWrite(
this,
length,
arg,
phase) and ignore its result;
length length + 1
end for each;
Evaluate
writeLength(
this,
length,
phase) and ignore its result;
return lengthf64
end proc;
throw a
ConstantError exception
—
reverse
cannot be called from a constant expression
end if;
note This function is generic and can be applied even
if this is not an Array
.
if |
args| 0
then throw an
ArgumentError exception
— no arguments can be supplied
end if;
while lo < hi do
Evaluate
indexWrite(
this,
lo,
hiElt,
phase) and ignore its result;
Evaluate
indexWrite(
this,
hi,
loElt,
phase) and ignore its result;
lo lo + 1;
hi hi – 1
end while;
return this
end proc;
throw a
ConstantError exception
—
shift
cannot be called from a constant expression
end if;
note This function is generic and can be applied even
if this is not an Array
.
if |
args| 0
then throw an
ArgumentError exception
— no arguments can be supplied
end if;
if length 0 then
if elt none then result elt end if;
while i length do
Evaluate
indexWrite(
this,
i – 1,
elt,
phase) and ignore its result;
i i + 1
end while;
length length – 1;
end if;
Evaluate
writeLength(
this,
length,
phase) and ignore its result;
return result
end proc;
throw a
ConstantError exception
—
slice
cannot be called on an
Array
from a constant expression
end if;
note This function is generic and can be applied even
if this is not an Array
.
if |args| > 2 then
throw an
ArgumentError exception
— at most two arguments can be supplied
end if;
end proc;
while i < end do
Evaluate
indexWrite(
slice,
j,
elt,
phase) and ignore its result;
i i + 1;
j j + 1
end while;
Evaluate
writeLength(
slice,
j,
phase) and ignore its result;
return slice
end proc;
throw a
ConstantError exception
—
sort
cannot be called from a constant expression
end if;
note This function is generic and can be applied even
if this is not an Array
.
if |args| > 1 then
throw an
ArgumentError exception
— at most one argument can be supplied
end if;
Evaluate ???? and ignore its result
end proc;
throw a
ConstantError exception
—
splice
cannot be called from a constant expression
end if;
note This function is generic and can be applied even
if this is not an Array
.
if |args| < 2 then
throw an
ArgumentError exception
— at least two arguments must be supplied
end if;
newElts:
Object[]
args[2 ...];
countDiff:
Integer newEltCount –
deleteCount;
if countDiff < 0 then
i start + deleteCount;
while i length do
Evaluate
indexWrite(
this,
i +
countDiff,
elt,
phase) and ignore its result;
i i + 1
end while;
i 0;
while i countDiff do
i i – 1;
Evaluate
indexWrite(
this,
length +
i,
none,
phase) and ignore its result
end while
elsif countDiff > 0 then
i length;
while i start + deleteCount do
i i – 1;
Evaluate
indexWrite(
this,
i +
countDiff,
elt,
phase) and ignore its result
end while
end if;
Evaluate
writeLength(
this,
length +
countDiff,
phase) and ignore its result;
i start;
for each arg newElts do
Evaluate
indexWrite(
this,
i,
arg,
phase) and ignore its result;
i i + 1
end for each;
return deletedSlice
end proc;
throw a
ConstantError exception
—
unshift
cannot be called from a constant expression
end if;
note This function is generic and can be applied even
if this is not an Array
.
if nArgs = 0 then
At the implementation’s discretion, either do nothing or
return newLengthf64
end if;
Evaluate
writeLength(
this,
newLength,
phase) and ignore its result;
while i 0 do
i i – 1;
Evaluate
indexWrite(
this,
i +
nArgs,
elt,
phase) and ignore its result
end while;
for each arg args do
Evaluate
indexWrite(
this,
i,
arg,
phase) and ignore its result;
i i + 1
end for each;
return newLengthf64
end proc;
Namespace
Namespace:
Class
=
new ClasslocalBindings: {},
instanceProperties: {},
super:
Object,
prototype:
NamespacePrototype,
complete:
true,
name: “
Namespace
”,
typeofString: “
namespace
”,
dynamic:
false,
final:
true,
defaultValue:
null,
defaultHint:
hintString,
hasProperty:
ordinaryHasProperty,
bracketRead:
ordinaryBracketRead,
bracketWrite:
ordinaryBracketWrite,
bracketDelete:
ordinaryBracketDelete,
read:
ordinaryRead,
write:
ordinaryWrite,
delete:
ordinaryDelete,
enumerate:
ordinaryEnumerate,
call:
ordinaryCall,
construct:
constructNamespace,
init:
none,
is:
ordinaryIs,
coerce:
ordinaryCoerce;
note This function can be used in a constant
expression if its argument is a string.
if |args| > 1 then
throw an
ArgumentError exception
— at most one argument can be supplied
end if;
throw a
ConstantError exception
— a constant expression cannot construct new anonymous namespaces
end if;
if name = “”
then return public
else
end if
end if
end proc;
NamespacePrototype:
SimpleInstance
=
new SimpleInstancelocalBindings:
{
stdFunction(
public::“
toString
”,
Namespace_toString, 0),
stdReserve(
public::“
valueOf
”,
ObjectPrototype)},
archetype:
ObjectPrototype,
sealed:
prototypesSealed,
type:
Object,
slots: {},
call:
none,
construct:
none,
env:
none;
note This function does not check phase
and therefore can be used in a constant expression.
note This function ignores any arguments passed to it
in args.
end proc;
Attribute
Attribute:
Class
=
new ClasslocalBindings: {},
instanceProperties: {},
super:
Object,
prototype:
ObjectPrototype,
complete:
true,
name: “
Attribute
”,
typeofString: “
object
”,
dynamic:
false,
final:
true,
defaultValue:
null,
defaultHint:
hintString,
hasProperty:
ordinaryHasProperty,
bracketRead:
ordinaryBracketRead,
bracketWrite:
ordinaryBracketWrite,
bracketDelete:
ordinaryBracketDelete,
read:
ordinaryRead,
write:
ordinaryWrite,
delete:
ordinaryDelete,
enumerate:
ordinaryEnumerate,
call:
dummyCall,
construct:
dummyConstruct,
init:
none,
is:
ordinaryIs,
coerce:
ordinaryCoerce;
Date
Date:
Class
=
new ClasslocalBindings: {},
instanceProperties: {},
super:
Object,
prototype:
DatePrototype,
complete:
true,
name: “
Date
”,
typeofString: “
object
”,
dynamic:
true,
final:
true,
defaultValue:
null,
defaultHint:
hintString,
hasProperty:
ordinaryHasProperty,
bracketRead:
ordinaryBracketRead,
bracketWrite:
ordinaryBracketWrite,
bracketDelete:
ordinaryBracketDelete,
read:
ordinaryRead,
write:
ordinaryWrite,
delete:
ordinaryDelete,
enumerate:
ordinaryEnumerate,
call:
dummyCall,
construct:
dummyConstruct,
init:
none,
is:
ordinaryIs,
coerce:
ordinaryCoerce;
RegExp
RegExp:
Class
=
new ClasslocalBindings: {},
instanceProperties: {},
super:
Object,
prototype:
RegExpPrototype,
complete:
true,
name: “
RegExp
”,
typeofString: “
object
”,
dynamic:
true,
final:
true,
defaultValue:
null,
defaultHint:
hintNumber,
hasProperty:
ordinaryHasProperty,
bracketRead:
ordinaryBracketRead,
bracketWrite:
ordinaryBracketWrite,
bracketDelete:
ordinaryBracketDelete,
read:
ordinaryRead,
write:
ordinaryWrite,
delete:
ordinaryDelete,
enumerate:
ordinaryEnumerate,
call:
dummyCall,
construct:
dummyConstruct,
init:
none,
is:
ordinaryIs,
coerce:
ordinaryCoerce;
Class
Class:
Class
=
new ClasslocalBindings: {},
instanceProperties: {
classPrototypeGetter},
super:
Object,
prototype:
ClassPrototype,
complete:
true,
name: “
Class
”,
typeofString: “
function
”,
dynamic:
false,
final:
true,
defaultValue:
null,
defaultHint:
hintString,
hasProperty:
ordinaryHasProperty,
bracketRead:
ordinaryBracketRead,
bracketWrite:
ordinaryBracketWrite,
bracketDelete:
ordinaryBracketDelete,
read:
ordinaryRead,
write:
ordinaryWrite,
delete:
ordinaryDelete,
enumerate:
ordinaryEnumerate,
call:
dummyCall,
construct:
dummyConstruct,
init:
none,
is:
ordinaryIs,
coerce:
ordinaryCoerce;
note this Class
because this getter cannot be extracted from the
Class
class.
if prototype =
none then return undefined else return prototype end if
end proc;
ClassPrototype:
SimpleInstance
=
new SimpleInstancelocalBindings:
{
stdConstBinding(
public::“
constructor
”,
Class,
Class),
stdFunction(
public::“
toString
”,
Class_toString, 0),
stdReserve(
public::“
valueOf
”,
ObjectPrototype),
stdConstBinding(
public::“
length
”,
Number, 1
f64)},
archetype:
ObjectPrototype,
sealed:
prototypesSealed,
type:
Object,
slots: {},
call:
none,
construct:
none,
env:
none;
note This function does not check phase
and therefore can be used in a constant expression.
note This function ignores any arguments passed to it
in args.
return “
[class
”
c.
name “
]
”
end proc;
Function
Function:
Class
=
new ClasslocalBindings: {},
instanceProperties: {
ivarFunctionLength},
super:
Object,
prototype:
FunctionPrototype,
complete:
true,
name: “
Function
”,
typeofString: “
function
”,
dynamic:
false,
final:
true,
defaultValue:
null,
defaultHint:
hintString,
hasProperty:
ordinaryHasProperty,
bracketRead:
ordinaryBracketRead,
bracketWrite:
ordinaryBracketWrite,
bracketDelete:
ordinaryBracketDelete,
read:
ordinaryRead,
write:
ordinaryWrite,
delete:
ordinaryDelete,
enumerate:
ordinaryEnumerate,
call:
dummyCall,
construct:
dummyConstruct,
init:
none,
is:
ordinaryIs,
coerce:
ordinaryCoerce;
PrototypeFunction
PrototypeFunction:
Class
=
new ClasslocalBindings: {},
instanceProperties:
{
new InstanceVariablemultiname: {
public::“
prototype
”},
final:
true,
enumerable:
false,
type:
Object,
defaultValue:
undefined,
immutable:
false},
super:
Function,
prototype:
FunctionPrototype,
complete:
true,
name: “
Function
”,
typeofString: “
function
”,
dynamic:
true,
final:
true,
defaultValue:
null,
defaultHint:
hintString,
hasProperty:
ordinaryHasProperty,
bracketRead:
ordinaryBracketRead,
bracketWrite:
ordinaryBracketWrite,
bracketDelete:
ordinaryBracketDelete,
read:
ordinaryRead,
write:
ordinaryWrite,
delete:
ordinaryDelete,
enumerate:
ordinaryEnumerate,
call:
dummyCall,
construct:
dummyConstruct,
init:
none,
is:
ordinaryIs,
coerce:
ordinaryCoerce;
Package
Package:
Class
=
new ClasslocalBindings: {},
instanceProperties: {},
super:
Object,
prototype:
ObjectPrototype,
complete:
true,
name: “
Package
”,
typeofString: “
object
”,
dynamic:
true,
final:
true,
defaultValue:
null,
defaultHint:
hintString,
hasProperty:
ordinaryHasProperty,
bracketRead:
ordinaryBracketRead,
bracketWrite:
ordinaryBracketWrite,
bracketDelete:
ordinaryBracketDelete,
read:
ordinaryRead,
write:
ordinaryWrite,
delete:
ordinaryDelete,
enumerate:
ordinaryEnumerate,
call:
dummyCall,
construct:
dummyConstruct,
init:
none,
is:
ordinaryIs,
coerce:
ordinaryCoerce;
Error
Error:
Class
=
new ClasslocalBindings: {},
instanceProperties: {
new InstanceVariablemultiname: {
public::“
name
”},
final:
false,
enumerable:
true,
type:
String,
defaultValue:
null,
immutable:
false,
new InstanceVariablemultiname: {
public::“
message
”},
final:
false,
enumerable:
true,
type:
String,
defaultValue:
null,
immutable:
false},
super:
Object,
prototype:
ErrorPrototype,
complete:
true,
name: “
Error
”,
typeofString: “
object
”,
dynamic:
true,
final:
false,
defaultValue:
null,
defaultHint:
hintNumber,
hasProperty:
ordinaryHasProperty,
bracketRead:
ordinaryBracketRead,
bracketWrite:
ordinaryBracketWrite,
bracketDelete:
ordinaryBracketDelete,
read:
ordinaryRead,
write:
ordinaryWrite,
delete:
ordinaryDelete,
enumerate:
ordinaryEnumerate,
call:
callError,
construct:
ordinaryConstruct,
init:
initError,
is:
ordinaryIs,
coerce:
ordinaryCoerce;
if |args| > 1 then
throw an
ArgumentError exception
— at most one argument can be supplied
end if;
end if
end proc;
if |args| > 1 then
throw an
ArgumentError exception
— at most one argument can be supplied
end if;
Evaluate
dotWrite(
this, {
public::“
name
”},
name,
phase) and ignore its result;
end if;
Evaluate
dotWrite(
this, {
public::“
message
”},
message,
phase) and ignore its result
end proc;
ErrorPrototype:
SimpleInstance
=
new SimpleInstancelocalBindings:
{
stdConstBinding(
public::“
constructor
”,
Class,
Error),
stdFunction(
public::“
toString
”,
Error_toString, 1),
stdVarBinding(
public::“
name
”,
String, “
Error
”),
stdVarBinding(
public::“
message
”,
String, an
implementation-defined string)},
archetype:
ObjectPrototype,
sealed:
prototypesSealed,
type:
Object,
slots: {},
call:
none,
construct:
none,
env:
none;
throw a
ConstantError exception
—
toString
cannot be called on an
Error
from a constant expression
end if;
note This function ignores any arguments passed to it
in args.
return an implementation-defined string derived from
name, message, and optionally other properties of err
end proc;
Error Subclasses
if |args| > 1 then
throw an
ArgumentError exception
— at most one argument can be supplied
end if;
end if
end proc;
c:
Class
new ClasslocalBindings: {},
instanceProperties: {},
super:
Error,
complete:
false,
name:
name,
typeofString: “
object
”,
dynamic:
true,
final:
false,
defaultValue:
null,
defaultHint:
hintNumber,
hasProperty:
Error.
hasProperty,
bracketRead:
Error.
bracketRead,
bracketWrite:
Error.
bracketWrite,
bracketDelete:
Error.
bracketDelete,
read:
Error.
read,
write:
Error.
write,
delete:
Error.
delete,
enumerate:
Error.
enumerate,
call:
call,
construct:
ordinaryConstruct,
init:
none,
is:
ordinaryIs,
coerce:
ordinaryCoerce;
prototype:
SimpleInstance
new SimpleInstancelocalBindings:
{
stdConstBinding(
public::“
constructor
”,
Class,
c),
stdVarBinding(
public::“
name
”,
String,
name),
stdVarBinding(
public::“
message
”,
String, an
implementation-defined string)},
archetype:
ErrorPrototype,
sealed:
prototypesSealed,
type:
Object,
slots: {},
call:
none,
construct:
none,
env:
none;
if |args| > 1 then
throw an
ArgumentError exception
— at most one argument can be supplied
end if;
Evaluate
dotWrite(
this, {
public::“
name
”},
name2,
phase) and ignore its result;
end if;
Evaluate
dotWrite(
this, {
public::“
message
”},
message,
phase) and ignore its result
end proc;
return c
end proc;