Scala.js IR

Introduction

This document specifies the run-time semantics of the Scala.js IR (Intermediate Representation), typically abbreviated as SJSIR.

This specification is to be interpreted as an addition to the ECMAScript 2018 specification. It adds the definitions of abstract operations, internal methods, exotic objects, class definitions, statements and expressions necessary for the IR. In particular, to reduce duplication with the original specification, the SJSIR specification adds new alternatives for the Statement and Expression targets. These new alternatives cannot be written in source code of the ECMAScript Language. Conversely, original productions from the ECMAScript Language are not part of the valid syntax of SJSIR trees.

The current specification concerns a linked and typechecked SJSIR codebase. It does not describe typechecking rules, nor the behavior to apply in case a codebase does not link.

1SJSIR Data Types

The SJSIR uses specific data types to store information about classes and types. Technically, they are all subsets of the ECMAScript Language Values, except SJSIR Classes, which are Records.

1.1SJSIR Classes

An SJSIR Class represents an SJSIR class at run-time, both its static definition and its run-time per-class state. An SJSIR Class is a Record with the fields described in Table 1.

Table 1: Attributes of an SJSIR Class
Attribute Name Value Domain Description
[[Environment]] Lexical Environment The Lexical Environment with an SJSIR program Environment Record where this class was defined.
[[IsPrimitive]] Boolean Whether this class represents a primitive type.
[[IsArray]] Boolean Whether this class represents an array type.
[[Name]] String The fully qualified name of the class, e.g., "java.lang.Object" or "java.io.Serializable".
[[ClassDef]] SJSIRClassDef | empty The Parse Node of type SJSIRClassDef that was used to define this Class, if any. This value is empty if and only if this class represents a primitive type or an array type.
[[Superclass]] SJSIR Class | Null The SJSIR Class which is the superclass of this class, if any.
[[Interfaces]] List of SJSIR Class The SJSIR Classes which are the directly implemented interfaces of this class, if any.
[[ComponentClass]] SJSIR Class | Null If this class represents an array type, the class representing its elements. Otherwise, null.
[[ArrayClass]] SJSIR Class | Undefined The unique, lazily create SJSIR Class representing arrays of this class.
[[StaticFields]] Object | Null An Object containing the values of the static fields of this class, or null if this class represents a primitive type or an array type.
[[ClassOf]] Object | Undefined The unique, lazily created instance of java.lang.Class representing this class.
[[JSClassValue]] Object | Undefined The unique, lazily created class value for this top-level js class or js module class.
[[ModuleInstance]] Object | Null | Undefined The unique, lazily created singleton instance of this module class or js module class.

1.1.1CreateSJSIRClassBase ( E, name )

When the abstract operation CreateSJSIRClassBase is called with a Lexical Environment as argument E and a String as argument name, the following steps are performed:

  1. Let class be a new SJSIR Class.
  2. Set class.[[Environment]] to E.
  3. Set class.[[Name]] to name.
  4. Set class.[[IsPrimitive]] to false.
  5. Set class.[[IsArray]] to false.
  6. Set class.[[ClassDef]] to empty.
  7. Set class.[[Superclass]] to null.
  8. Set class.[[Interfaces]] to « ».
  9. Set class.[[ComponentClass]] to null.
  10. Set class.[[ArrayClass]] to undefined.
  11. Set class.[[StaticFields]] to null.
  12. Set class.[[ClassOf]] to undefined.
  13. Set class.[[JSClassValue]] to undefined.
  14. Set class.[[ModuleInstance]] to undefined.
  15. Perform RegisterSJSIRClass(E, class).
  16. Return class.

1.1.2CreateSJSIRPrimitiveClass ( E, name )

When the abstract operation CreateSJSIRPrimitiveClass is called with a Lexical Environment as argument E and a String as argument name, the following steps are performed:

  1. Let class be a CreateSJSIRClassBase(E, name).
  2. Set class.[[IsPrimitive]] to true.
  3. Return class.

1.1.3CreateSJSIRClass ( E, classDef )

When the abstract operation CreateSJSIRClass is called with a Lexical Environment as argument E and an SJSIRClassDef as argument classDef, the following steps are performed:

  1. Let className be the StringValue of the SJSIRClassName of classDef.
  2. Let class be a CreateSJSIRClassBase(E, className).
  3. Set class.[[ClassDef]] to classDef.
  4. If SJSIRExtendsClause is present in classDef, then
    1. Let extendsClause be the SJSIRExtendsClause of classDef.
    2. Let superClassNameNode be the SJSIRClassName of extendsClause.
    3. Let superClassName be the StringValue of superClassNameNode.
    4. Let superClass be GetSJSIRClass(E, superClassName).
    5. Set class.[[Superclass]] to superClass.
  5. If SJSIRImplementsClause is present in classDef, then
    1. Let implementsClause be the SJSIRImplementsClause of classDef.
    2. Let I be the List of SJSIRClassName items in implementsClause, in source text order.
    3. Let interfaces be a new empty List.
    4. For each SJSIRClassName interfaceNameNode in I, do
      1. Let interfaceName be the StringValue of interfaceNameNode.
      2. Let interface be GetSJSIRClass(E, interfaceName).
      3. Append interface at the end of interfaces.
    5. Set class.[[Interfaces]] to interfaces.
  6. Let staticFields be ObjectCreate(null).
  7. Let static be true.
  8. Perform ! SJSIRCreateFields of classDef with arguments staticFields and static.
  9. Set class.[[StaticFields]] to staticFields.
  10. Return class.

1.1.4CreateSJSIRArrayClass ( E, componentClass )

When the abstract operation CreateSJSIRArrayClass is called with a Lexical Environment as argument E and an SJSIR Class as argument componentClass, the following steps are performed:

  1. Let componentName be componentClass.[[Name]].
  2. If componentClass.[[IsPrimitive]] is true, then
    1. If componentName is "void", then
      1. Set componentName to "V".
    2. If componentName is "boolean", then
      1. Set componentName to "Z".
    3. If componentName is "char", then
      1. Set componentName to "C".
    4. If componentName is "byte", then
      1. Set componentName to "B".
    5. If componentName is "short", then
      1. Set componentName to "S".
    6. If componentName is "int", then
      1. Set componentName to "I".
    7. If componentName is "long", then
      1. Set componentName to "J".
    8. If componentName is "float", then
      1. Set componentName to "F".
    9. If componentName is "double", then
      1. Set componentName to "D".
    10. Let name be the string-concatenation of "[" and componentName.
  3. Else, if componentClass.[[IsArray]] is true, then
    1. Let name be the string-concatenation of "[" and componentName.
  4. Else,
    1. Let name be the string-concatenation of "[L", componentName and ";".
  5. Let class be a CreateSJSIRClassBase(E, name).
  6. Set class.[[IsArray]] to true.
  7. Set class.[[ComponentClass]] to componentClass.
  8. Set class.[[Superclass]] to GetSJSIRClass(E, "java.lang.Object").
  9. Let cloneable be GetSJSIRClass(E, "java.lang.Cloneable").
  10. Let serializable be GetSJSIRClass(E, "java.io.Serializable").
  11. Set class.[[Interfaces]] to « cloneable, serializable, ».
  12. Return class.

1.1.5SJSIRGetArrayClassOf ( componentClass )

When the abstract operation SJSIRGetArrayClassOf is called with an SJSIR Class as argument componentClass, the following steps are performed:

  1. arrayClass be componentClass.[[ArrayClass]].
  2. If arrayClass is undefined, then
    1. Let env be componentClass.[[Environment]].
    2. Set arrayClass to CreateSJSIRArrayClass(env, componentClass).
  3. Return arrayClass.

2Abstract Operations

2.1Type Conversion

2.1.1ToInt64 ( argument )

The abstract operation ToInt64 converts argument to one of 264 integer values in the range -263 through 263-1, inclusive. This abstract operation functions as follows:

  1. If argument is a mathematical integer value,
    1. Let int be argument.
  2. Else,
    1. Let number be ? ToNumber(argument).
    2. If number is NaN, +0, -0, +∞, or -∞, return +0.
    3. Let int be the mathematical value that is the same sign as number and whose magnitude is floor(abs(number)).
  3. Let int64bit be int modulo 264.
  4. If int64bit ≥ 263, return int64bit - 264; otherwise return int64bit.

2.1.2ToFloat32 ( argument )

The abstract operation ToFloat32 converts argument to a number that fits in the IEEE 754-2008 binary32 format. This abstract operation functions as follows:

  1. Let number be ? ToNumber(argument).
  2. If number is NaN, return NaN.
  3. If number is +0, -0, +∞, or -∞, return number.
  4. Let x32 be the result of converting number to a value in IEEE 754-2008 binary32 format using roundTiesToEven.
  5. Let x64 be the result of converting x32 to a value in IEEE 754-2008 binary64 format.
  6. Return the ECMAScript Number value corresponding to x64.
Note

This algorithm is equivalent to the one performed by the function Math.fround.

2.2SJSIRIsSubclass ( class, otherClass )

When the abstract operation SJSIRIsSubclass is called with two SJSIR Classes class and otherClass, the following steps are taken:

  1. If otherClass is class, return true.
  2. If class.[[IsPrimitive]] is true, return false.
  3. If otherClass.[[IsPrimitive]] is true, return false.
  4. If SameValue(otherClass.[[Name]], "java.lang.Object") is true, return true.
  5. Let superClass be class.[[Superclass]].
  6. If superClass is not null,
    1. If SJSIRIsSubclass(superClass, otherClass) is true, return true.
  7. Let interfaces be class.[[Interfaces]].
    1. For each interface in interfaces, do
      1. If SJSIRIsSubclass(interface, otherClass) is true, return true.
  8. If class.[[IsArray]] is false, return false.
  9. If otherClass.[[IsArray]] is false, return false.
  10. Return SJSIRIsSubclass(class.[[ComponentClass]], otherClass.[[ComponentClass]]).

2.3SJSIRIsValueOfClass ( value, class )

When the abstract operation SJSIRIsValueOfClass is called with an ECMAScript Language Value value and an SJSIR Class class, the following steps are taken:

  1. Assert: class.[[IsPrimitive]] is false.
  2. If class.[[IsArray]] is false, then
    1. Assert: class.[[ClassDef]] is not empty.
    2. Assert: the SJSIRClassKind of class.[[ClassDef]] is either class, module class or interface.
    3. Let className be class.[[Name]].
    4. If className is "java.lang.Boolean",
      1. Return the result of SJSIRTypeHasValue of boolean with argument value.
    5. If className is "java.lang.Character",
      1. Return the result of SJSIRTypeHasValue of char with argument value.
    6. If className is "java.lang.Byte",
      1. Return the result of SJSIRTypeHasValue of byte with argument value.
    7. If className is "java.lang.Short",
      1. Return the result of SJSIRTypeHasValue of short with argument value.
    8. If className is "java.lang.Int",
      1. Return the result of SJSIRTypeHasValue of int with argument value.
    9. If className is "java.lang.Long",
      1. Return the result of SJSIRTypeHasValue of long with argument value.
    10. If className is "java.lang.Float",
      1. Return the result of SJSIRTypeHasValue of float with argument value.
    11. If className is "java.lang.Double",
      1. Return the result of SJSIRTypeHasValue of double with argument value.
    12. If className is "java.lang.String",
      1. Return the result of SJSIRTypeHasValue of string with argument value.
    13. If className is "scala.runtime.BoxedUnit",
      1. Return the result of SJSIRTypeHasValue of undef with argument value.
  3. Let valueClass be SJSIRRepresentativeClass(value).
  4. Return SJSIRIsSubclass(valueClass, class).
Note

The SJSIRIsValueOfClass abstract operation cannot be called with a class that represents a type that is not valid in an isInstanceOf tree.

2.4SJSIRIsValueOfType ( value, type )

When the abstract operation SJSIRIsValueOfType is called with an ECMAScript Language Value value and a Parse Node of type SJSIRType type, the following steps are taken:

  1. Return the result of SJSIRTypeHasValue of type with argument value.
Note

This operation tests whether value is a valid value for an expression that was typed as type. It is often used in Assertions that validate type soundness.

2.5SJSIRCreateClassDataOf ( class )

When the abstract operation SJSIRCreateClassDataOf is called with an SJSIR Class class, the following steps are taken:

  1. Let data be ObjectCreate(%ObjectPrototype%, « [[SJSIRClass]] »).
  2. Set data.[[SJSIRClass]] to class.
  3. Perform CreateDataProperty(data, "name", class.[[Name]]).
  4. Perform CreateDataProperty(data, "isPrimitive", class.[[IsPrimitive]]).
  5. Perform CreateDataProperty(data, "isArrayClass", class.[[IsArray]]).
  6. Let classDef be class.[[ClassDef]].
  7. If classDef is empty, then
    1. Perform CreateDataProperty(data, "isInterface", false).
    2. Perform CreateDataProperty(data, "isRawJSType", false).
  8. Else,
    1. Let classKind be the SJSIRClassKind of classDef.
    2. If classKind is interface, then
      1. Perform CreateDataProperty(data, "isInterface", true).
      2. Perform CreateDataProperty(data, "isRawJSType", false).
    3. Else, if classKind is class or module class, then
      1. Perform CreateDataProperty(data, "isInterface", false).
      2. Perform CreateDataProperty(data, "isRawJSType", false).
    4. Else,
      1. Perform CreateDataProperty(data, "isInterface", false).
      2. Perform CreateDataProperty(data, "isRawJSType", true).
  9. Let isInstanceSteps be the steps of an IsInstance function as specified below.
  10. Let isInstance be CreateBuiltinFunction(isInstanceSteps, « [[Class]] »).
  11. Set isInstance.[[Class]] to class.
  12. Perform CreateDataProperty(data, "isInstance", isInstance).
  13. Let isAssignableFromSteps be the steps of an IsAssignableFrom function as specified below.
  14. Let isAssignableFrom be CreateBuiltinFunction(isAssignableFromSteps, « »).
  15. Perform CreateDataProperty(data, "isAssignableFrom", isAssignableFrom).
  16. Let getSuperclassSteps be the steps of a GetSuperclass function as specified below.
  17. Let getSuperclass be CreateBuiltinFunction(getSuperclassSteps, « »).
  18. Perform CreateDataProperty(data, "getSuperclass", getSuperclass).
  19. Let getComponentTypeSteps be the steps of a GetComponentType function as specified below.
  20. Let getComponentType be CreateBuiltinFunction(getComponentTypeSteps, « »).
  21. Perform CreateDataProperty(data, "getComponentType", getComponentType).
  22. Let newArrayOfThisClassSteps be the steps of a NewArrayOfThisClass function as specified below.
  23. Let newArrayOfThisClass be CreateBuiltinFunction(newArrayOfThisClassSteps, « »).
  24. Perform CreateDataProperty(data, "newArrayOfThisClass", newArrayOfThisClass).
  25. Return data.

An IsInstance function is an anonymous built-in function with a [[Class]] internal slot. When an IsInstance function f is called with argument value it performs the following steps:

  1. Let class be f.[[Class]].
  2. If class.[[IsPrimitive]] is true, then return false.
  3. Let classDef be class.[[ClassDef]].
  4. If classDef is not empty, then
    1. Let classKind be the SJSIRClassKind of classDef.
    2. If classKind is neither class nor module class nor interface, then
      1. Throw a TypeError exception.
  5. Return SJSIRIsValueOfClass(value, class).

An IsAssignableFrom function is an anonymous built-in function without internal slot. When an IsAssignableFrom function f is called with argument otherData it performs the following steps:

  1. Let thisData be this value.
  2. If thisData does not have an [[SJSIRClass]] internal slot, then
    1. Throw a TypeError exception.
  3. If otherData does not have an [[SJSIRClass]] internal slot, then
    1. Throw a TypeError exception.
  4. Return SJSIRIsSubclass(otherData.[[SJSIRClass]], thisData.[[SJSIRClass]]).

A GetSuperclass function is an anonymous built-in function without internal slot. When a GetSuperclass function f that expects no arguments is called it performs the following steps:

  1. Let thisData be this value.
  2. If thisData does not have an [[SJSIRClass]] internal slot, then
    1. Throw a TypeError exception.
  3. Let class be thisData.[[SJSIRClass]].
  4. Let superClass be class.[[Superclass]].
  5. If superClass is null, return null.
  6. Return SJSIRClassOf(superClass).

A GetComponentType function is an anonymous built-in function without internal slot. When a GetComponentType function f that expects no arguments is called it performs the following steps:

  1. Let thisData be this value.
  2. If thisData does not have an [[SJSIRClass]] internal slot, then
    1. Throw a TypeError exception.
  3. Let class be thisData.[[SJSIRClass]].
  4. Let componentClass be class.[[ComponentClass]].
  5. If componentClass is null, return null.
  6. Return SJSIRClassOf(componentClass).

A NewArrayOfThisClass function is an anonymous built-in function with a [[Class]] internal slot. When a NewArrayOfThisClass function f is called with argument lengths it performs the following steps:

  1. Let thisData be this value.
  2. If thisData does not have an [[SJSIRClass]] internal slot, then
    1. Throw a TypeError exception.
  3. Let class be thisData.[[SJSIRClass]].
  4. Let lengthsList be CreateListFromArrayLike(lengths, « Number »).
  5. If lengthsList is empty, then
    1. Trigger an SJSIR Undefined Behavior.
  6. For each length in lengthsList, do
    1. If SJSIRIsValueOfType(length, int) is false,
      1. Trigger an SJSIR Undefined Behavior.
  7. Return ? CreateMultiSJSIRArrayObject(class, lengthsList).

2.6SJSIRClassOf ( class )

When the abstract operation SJSIRClassOf is called with an SJSIR Class class, the following steps are taken:

  1. Let classOf be class.[[ClassOf]].
  2. If classOf is not undefined, return classOf.
  3. Let data be SJSIRCreateClassDataOf(class).
  4. Let jlClassClass be ResolveSJSIRClass("java.lang.Class").
  5. Let argList be « data ».
  6. Let obj be ! SJSIRScalaObjectAllocate(jlClassClass).
  7. Let classDef be jlClassClass.[[ClassDef]].
  8. Let static be false.
  9. Let ctorDef be the result of SJSIRGetMethodInClass of classDef with parameters "init___O" and static.
  10. Assert: ctorDef is a SJSIRClassMember with the production def SJSIRCtorName SJSIRMethodSignature = SJSIRTree.
  11. Perform ? SJSIREvaluateMethod of ctorDef with parameters obj and argList.
  12. Set class.[[ClassOf]] to obj.
  13. Return obj.

2.7SJSIRZeroOfClass ( class )

When the abstract operation SJSIRZeroOfClass is called with an SJSIR Class class, the following steps are taken:

  1. If class.[[IsPrimitive]] is false, return null.
  2. Let name be class.[[Name]].
  3. If SameValue(name, "Z"), return false.
  4. If SameValue(name, "C"), return CreateSJSIRCharObject(0).
  5. If SameValue(name, "J"), return CreateSJSIRLongObject(0).
  6. return 0.

2.8SJSIRLoadConstructorOf ( class )

When the abstract operation SJSIRLoadConstructorOf is called with an SJSIR Class class, the following steps are taken:

  1. Let classDef be class.[[ClassDef]].
  2. Let classKind be the SJSIRClassKind of classDef.
  3. If classKind is native js class, then
    1. Assert: the SJSIRNativeLoadSpec of classDef is present.
    2. Let nativeLoadSpec be the SJSIRNativeLoadSpec of classDef.
    3. Return the result of SJSIRLoadSpecEvaluation of nativeLoadSpec with argument classDef.
  4. Assert: classKind is js class or js module class.
  5. Let jsClassValue be class.[[JSClassValue]].
  6. If jsClassValue is not undefined, return jsClassValue.
  7. Set jsClassValue to the result of evaluating SJSIRCreateJSClassValue of classDef with argument empty.
  8. ReturnIfAbrupt(jsClassValue).
  9. Set class.[[JSClassValue]] to jsClassValue.
  10. Perform ? SJSIRStaticInitialization of classDef.
  11. Return jsClassValue.

2.9SJSIRLoadModule ( class )

When the abstract operation SJSIRLoadModule is called with an SJSIR Class class, the following steps are taken:

  1. Let classDef be class.[[ClassDef]].
  2. Let classKind be the SJSIRClassKind of classDef.
  3. If classKind is native js module class, then
    1. Assert: the SJSIRNativeLoadSpec of classDef is present.
    2. Let nativeLoadSpec be the SJSIRNativeLoadSpec of classDef.
    3. Return the result of SJSIRLoadSpecEvaluation of nativeLoadSpec with argument classDef.
  4. Let moduleInstance be class.[[ModuleInstance]].
  5. If moduleInstance is null, then
    1. Trigger an SJSIR Undefined Behavior.
  6. If moduleInstance is not undefined, return moduleInstance.
  7. Set class.[[ModuleInstance]] to null.
  8. If classKind is js module class, then
    1. Let constructor be ? SJSIRLoadConstructorOf(class).
    2. Assert: IsConstructor(constructor) is true.
    3. Set moduleInstance to ? Construct(constructor, « »).
  9. Else,
    1. Assert: classKind is module class.
    2. Set moduleInstance to ! SJSIRScalaObjectAllocate(class).
    3. Let static be false.
    4. Let ctorDef be the result of SJSIRGetMethodInClass of classDef with parameters "init___" and static.
    5. Assert: ctorDef is a SJSIRClassMember with the production def SJSIRCtorName SJSIRMethodSignature = SJSIRTree.
    6. Perform ? SJSIREvaluateMethod of ctorDef with parameters moduleInstance and argList.
  10. Set class.[[ModuleInstance]] to moduleInstance.
  11. Return moduleInstance.

2.10SJSIRLookupMethodInSuperclasses ( class, methodName )

When the abstract operation SJSIRLookupMethodInSuperclasses is called with an SJSIR Class class and a String methodName, the following steps are taken:

  1. Let classDef be class.[[ClassDef]].
  2. Let static be false.
  3. Let inThisClass be the result of SJSIRGetMethodInClass of classDef with parameters methodName and static.
  4. If inThisClass is not empty, return inThisClass.
  5. Let superClass be class.[[Superclass]].
  6. If superClass is null, then
    1. Return empty.
  7. Else,
    1. Return SJSIRLookupMethodInSuperclasses(superClass, methodName).

2.11SJSIRFindAllDefaultImplementationsOfMethod ( class, methodName )

When the abstract operation SJSIRFindAllDefaultImplementationsOfMethod is called with an SJSIR Class class and a String methodName, the following steps are taken:

  1. Let superClass be class.[[Superclass]].
  2. If superClass is null, then
    1. Let result be a new empty List.
  3. Else,
    1. Let result be SJSIRFindAllDefaultImplementationsOfMethod(superClass, methodName).
  4. Let interfaces be class.[[Interfaces]].
  5. For each interface in interfaces, do
    1. Let intfResult be SJSIRFindAllDefaultImplementationsOfMethod(interface, methodName).
    2. Append all the elements of intfResult to result.
  6. Return result.
  7. Let classDef be class.[[ClassDef]].
  8. Let static be false.
  9. Let classKind be the SJSIRClassKind of classDef.
  10. If classKind is interface, then
    1. Let inThisClass be the result of SJSIRGetMethodInClass of classDef with parameters methodName and static.
    2. If inThisClass is not empty, then
      1. Append {[[Intf]]:class, [[MethodDef]]:inThisClass} to result.
  11. Return result.

2.12SJSIRResolveMethod ( class, methodName )

When the abstract operation SJSIRResolveMethod is called with an SJSIR Class class and a String methodName, the following steps are taken:

  1. Let classDef be class.[[ClassDef]].
  2. Let classKind be the SJSIRClassKind of classDef.
  3. If classKind is interface, then
    1. Let result be the result of SJSIRGetMethodInClass of classDef with arguments methodName and false.
    2. Assert: result is not empty.
    3. Return result.
  4. Else,
    1. Assert: classKind is class or module class.
    2. Let inSuperClasses be SJSIRLookupMethodInSuperclasses(class, methodName).
    3. If inSuperClasses is not empty,
      1. Return inSuperClasses.
    4. Let allDefaultImplementations be SJSIRFindAllDefaultImplementationsOfMethod(class, methodName).
    5. For each defaultImpl in allDefaultImplementations, do
      1. Let shadowsAll be true.
      2. For each otherDefaultImpl in allDefaultImplementations, do
        1. If SJSIRIsSubclass(defaultImpl.[[Intf]], otherDefaultImpl.[[Intf]]) is false, then
          1. Set shadowsAll to false.
      3. If shadowsAll is true, then
        1. Return defaultImpl.[[MethodDef]].
    6. Assert: this step is never reached.

2.13SJSIRResolveReflectiveMethod ( class, methodName )

When the abstract operation SJSIRResolveReflectiveMethod is called with an SJSIR Class class and a String methodName, the following steps are taken:

  1. Let classDef be class.[[ClassDef]].
  2. Let classKind be the SJSIRClassKind of classDef.
  3. Assert: classKind is class or module class.
  4. Let inSuperClasses be SJSIRLookupMethodInSuperclasses(class, methodName).
  5. If inSuperClasses is not empty,
    1. Let protoMethodDef be inSuperClasses.
  6. Else,
    1. Let allDefaultImplementations be SJSIRFindAllDefaultImplementationsOfMethod(class, methodName).
    2. If allDefaultImplementations is not empty, then
      1. Let protoMethodDef be allDefaultImplementations[0].
    3. Else,
      1. Return empty.
  7. Assert: protoMethodDef is a SJSIRClassMember with the production def SJSIRMethodName SJSIRMethodSignature = SJSIRTree.
  8. Let exactMethodNameNode be the SJSIRMethodName of protoMethodDef.
  9. Let exactMethodName be the StringValue of exactMethodNameNode.
  10. Return SJSIRResolveMethod(class, exactMethodName).
Note

SJSIRResolveReflectiveMethod first performs a loose resolution algorithm to determine what is the exact method name from the reflective proxy name. Afterwards, it reruns an actual resolution using SJSIRResolveMethod so that the proper target for the given exact method name is called.

2.14SJSIRResolveMemberExport ( class, propName )

When the abstract operation SJSIRResolveMemberExport is called with an SJSIR Class class and a String propName, the following steps are taken:

  1. Let classDef be class.[[ClassDef]].
  2. Assert: classDef is not empty.
  3. Assert: the SJSIRClassKind of classDef is class or module class.
  4. Let memberDef be SJSIRGetMemberExportInClass of classDef with argument propName.
  5. If memberDef is not empty, return memberDef.
  6. Let superclass be class.[[Superclass]].
  7. If superclass is null, return empty.
  8. Return SJSIRResolveMemberExport(superclass, propName).

2.15SJSIRResolveGlobalRef ( name )

When the abstract operation SJSIRResolveGlobalRef is called with a String name, the following steps are taken:

  1. Let lex be the running execution context's LexicalEnvironment.
  2. Let globalEnv be FindSJSIRProgramEnv(lex).
  3. Let outer be the value of globalEnv's outer environment reference.
  4. Let outerRec be outer's EnvironmentRecord.
  5. If outerRec is a Module Environment Record, then
    1. Set outer to the value of outer's outer environment reference.
  6. Return ? ResolveBinding(name, outer).
Note

A JS Global Reference always refers to bindings that surround the SJSIR program. They can never refer to local variables or other bindings introduced by an SJSIR program child nodes. If the SJSIR program is in a module, the module environment is bypassed as well, so that bindings for imports are avoided as well.

3Executable Code and Execution Contexts

3.1Lexical Environments

3.1.1Environment Records

3.1.1.1SJSIR Program Environment Records

An SJSIR program Environment Record is a declarative Environment Record that is used to represent the top-level scope of an SJSIR program. It stores and gives access to the global SJSIR class table, as well as some other global state of the SJSIR program, such as the [[LinkingInfo]] object.

SJSIR program Environment Records have the additional state fields listed in Table 2.

Table 2: Additional Fields of SJSIR Program Environment Records
Field Name Value Meaning
[[LinkingInfo]] Object The Object returned by the <linking-info> SJSIRTree.
[[ClassTable]] List of SJSIR Class List of all the SJSIR classes in the program.

SJSIR program Environment Records support all of the declarative Environment Record methods listed in Table 15 and share the same specifications for all of those methods except for HasThisBinding. However, it is not expected to ever containing bindings of its own, since no construct in this specification creates a binding at the level of an SJSIR program Environment Record.

3.1.1.2SJSIR Method Environment Records

An SJSIR method Environment Record is a declarative Environment Record that is used to represent the top-level scope of a method in a Scala class and, if the method is not static, provides a this binding.

SJSIR method Environment Records have the additional state fields listed in Table 3.

Table 3: Additional Fields of SJSIR Method Environment Records
Field Name Value Meaning
[[ThisValue]] Any This is the this value used for this invocation of the method.
[[IsStatic]] Boolean If true, the method is a static method which does not have any binding for this.

SJSIR method Environment Records support all of the declarative Environment Record methods listed in Table 15 and share the same specifications for all of those methods except for HasThisBinding. In addition, SJSIR method Environment Records support the methods listed in Table 4:

Table 4: Additional Methods of SJSIR method Environment Records
Method Purpose
GetThisBinding() Return the value of this Environment Record's this binding.

The behaviour of the additional concrete specification methods for SJSIR method Environment Records is defined by the following algorithms:

3.1.1.2.1HasThisBinding ( )

  1. Let envRec be the SJSIR method Environment Record for which the method was invoked.
  2. If envRec.[[IsStatic]] is true, return false; otherwise, return true.

3.1.1.2.2GetThisBinding ( )

  1. Let envRec be the SJSIR method Environment Record for which the method was invoked.
  2. Assert: envRec.[[IsStatic]] is not "static".
  3. Return envRec.[[ThisValue]].

3.1.2Lexical Environment Operations

The following abstract operations are used in this specification to operate upon lexical environments:

3.1.2.1CreateSJSIRLinkingInfo ( globalThis )

When the abstract operation CreateSJSIRLinkingInfo is called with an ECMAScript Language Value as argument globalThis, the following steps are performed:

  1. Let semantics be ObjectCreate(%ObjectPrototype%).
  2. Let asInstanceOfs be an implementation-defined Number value chosen among 0, 1 and 2.
  3. Perform CreateDataProperty(semantics, "asInstanceOfs", asInstanceOfs).
  4. Let arrayIndexOutOfBounds be an implementation-defined Number value chosen among 0, 1 and 2.
  5. Perform CreateDataProperty(semantics, "arrayIndexOutOfBounds", arrayIndexOutOfBounds).
  6. Let moduleInit be an implementation-defined Number value chosen among 0, 1 and 2.
  7. Perform CreateDataProperty(semantics, "moduleInit", moduleInit).
  8. Let strictFloats be an implementation-defined Boolean value.
  9. Perform CreateDataProperty(semantics, "strictFloats", strictFloats).
  10. Let productionMode be an implementation-defined Boolean value.
  11. Perform CreateDataProperty(semantics, "productionMode", productionMode).
  12. Perform SetIntegrityLevel(semantics, "frozen").
  13. Let linkingInfo be ObjectCreate(%ObjectPrototype%).
  14. Perform CreateDataProperty(linkingInfo, "semantics", semantics).
  15. Let assumingES6 be an implementation-defined Boolean value.
  16. Perform CreateDataProperty(linkingInfo, "assumingES6", assumingES6).
  17. Let linkerVersion be an implementation-defined String value.
  18. Perform CreateDataProperty(linkingInfo, "linkerVersion", linkerVersion).
  19. Perform CreateDataProperty(linkingInfo, "globalThis", globalThis).
  20. Perform SetIntegrityLevel(linkingInfo, "frozen").
  21. Return linkingInfo.

3.1.2.2NewSJSIRProgramEnvironment ( E, globalThis )

When the abstract operation NewSJSIRProgramEnvironment is called with a Lexical Environment as argument E and an ECMAScript Language Value as argument globalThis, the following steps are performed:

  1. Let env be a new Lexical Environment.
  2. Let envRec be a new SJSIR program Environment Record containing no bindings.
  3. Set envRec.[[LinkingInfo]] to CreateSJSIRLinkingInfo(globalThis).
  4. Set envRec.[[ClassTable]] to a new empty List.
  5. Set env's EnvironmentRecord to envRec.
  6. Set the outer lexical environment reference of env to E.
  7. Return env.

3.1.2.3FindSJSIRProgramEnv ( lex )

When the abstract operation FindSJSIRProgramEnv is called with a Lexical Environment as argument lex, the following steps are performed:

  1. Assert: lex is not null.
  2. Let envRec be lex's EnvironmentRecord.
  3. If envRec is an SJSIR program Environment Record, then
    1. Return lex.
  4. Else,
    1. Let outer be the value of lex's outer environment reference.
    2. Return FindSJSIRProgramEnv(outer).
Note

FindSJSIRProgramEnv must not be called if there is no Lexical Environment with an SJSIR program Environment Record in the chain.

3.1.2.4GetSJSIRLinkingInfo ( lex )

When the abstract operation GetSJSIRLinkingInfo is called with a Lexical Environment as argument lex, the following steps are performed:

  1. Let env be FindSJSIRProgramEnv(lex).
  2. Let envRec be env's EnvironmentRecord.
  3. Return envRec.[[LinkingInfo]].

3.1.2.5GetSJSIRClass ( lex, className [ , primitive ] )

When the abstract operation GetSJSIRClass is called with a Lexical Environment as argument lex, a String as argument className, and an optional Boolean as argument primitive, the following steps are performed:

  1. If primitive is not present, let primitive be false.
  2. Let env be FindSJSIRProgramEnv(lex).
  3. Let envRec be env's EnvironmentRecord.
  4. Let classTable be envRec.[[ClassTable]].
  5. For each class in classTable, do
    1. If class.[[IsArray]] is false, then
      1. If SameValue(class.[[IsPrimitive]], primitive) is true, then
        1. If SameValue(class.[[Name]], className) is true, then
          1. Return class.
  6. Assert: this is unreachable.

3.1.2.6RegisterSJSIRClass ( lex, class )

When the abstract operation RegisterSJSIRClass is called with a Lexical Environment as argument lex and an SJSIR Class as argument class, the following steps are performed:

  1. Let envRec be lex's EnvironmentRecord.
  2. Assert: envRec is an SJSIR program Environment Record.
  3. Let classTable be envRec.[[ClassTable]].
  4. Append class to classTable.

3.1.2.7NewSJSIRMethodEnvironment ( E, thisValue )

When the abstract operation NewSJSIRMethodEnvironment is called with arguments E and thisValue, the following steps are performed:

  1. Assert: E is a LexicalEnvironment with an SJSIR program Environment Record.
  2. Assert: thisValue is empty or an ECMAScript language value.
  3. Let env be a new Lexical Environment.
  4. Let envRec be a new SJSIR method Environment Record containing no bindings.
  5. If thisValue is not empty, then
    1. Set envRec.[[IsStatic]] to false.
    2. Set envRec.[[ThisValue]] to thisValue.
  6. Else,
    1. Set envRec.[[IsStatic]] to true.
  7. Set env's EnvironmentRecord to envRec.
  8. Set the outer lexical environment reference of env to E.
  9. Return env.

3.2Execution Contexts

3.2.1ResolveSJSIRLinkingInfo ( )

The ResolveSJSIRLinkingInfo abstract operation is get the linking info of the current SJSIR program. During execution of ECMAScript code, ResolveSJSIRLinkingInfo is performed using the following algorithm:

  1. Let env be the running execution context's LexicalEnvironment.
  2. Assert: env is a Lexical Environment.
  3. Return GetSJSIRLinkingInfo(env).

3.2.2ResolveSJSIRClass ( className [ , primitive ] )

The ResolveSJSIRClass abstract operation is used to look up the given className in the current SJSIR class table. During execution of ECMAScript code, ResolveSJSIRClass is performed using the following algorithm:

  1. Let env be the running execution context's LexicalEnvironment.
  2. Assert: env is a Lexical Environment.
  3. If primitive is present, then
    1. Return GetSJSIRClass(env, className, primitive).
  4. Else,
    1. Return GetSJSIRClass(env, className).

4SJSIR Exotic Objects Behaviors

4.1SJSIR Scala Objects

An SJSIR Scala object is an exotic object that belongs to an SJSIR Class, and stores the values for its instance fields. Unlike ordinary objects, SJSIR Scala objects do not have an explicit [[Prototype]] internal slot, since they receive their inherited behavior from their SJSIR Class instead, stored in the [[SJSIRClass]] internal slot. Data properties are internally used to store the value of instance fields, but they are not accessible to ECMAScript source code through [[Get]] nor [[Set]]. In general, most of the essential internal methods of SJSIR Scala objects trigger Undefined Behavior except in very specific cases.

SJSIR Scala objects have the internal slots listed in Table 5.

Table 5: Internal Slots of SJSIR Scala Objects
Internal Slot Type Description
[[SJSIRClass]] SJSIR Class The class of this object, as specified when it was instantiated.
[[Extensible]] Boolean Whether this object is extensible. Note that this internal slot is only used by [[IsExtensible]] and [[PreventExtensions]], and does not actually affect whether it is allowed to alter the properties of an SJSIR Scala object.

SJSIR Scala exotic objects provide alternative definitions for all of the internal methods.

4.1.1[[GetPrototypeOf]] ( )

When the [[GetPrototypeOf]] internal method of an SJSIR Scala exotic object O is called, the following steps are taken:

  1. If O has an [[ErrorData]] internal slot, then
    1. Let eventualProto be %ErrorPrototype%.
  2. Else,
    1. Let eventualProto be %ObjectPrototype%.
  3. Let fakeProto be an implementation-defined, possibly exotic object, whose only guarantee is that there exists a finite integer n >= 0 such that repeatedly calling [[GetPrototypeOf]] n times will yield eventualProto.
  4. Let fakeProto.
Note

The above specification allows some algorithms such as OrdinaryHasInstance to have a well-defined behavior when manipulating SJSIR exotic objects. At the same time, it is loose enough to allow implementations to flatten class hierarchies as an optimization. Note that n = 0 is the case where fakeProto is the same object as eventualProto.

4.1.2[[SetPrototypeOf]] ( V )

When the [[SetPrototypeOf]] internal method of an SJSIR Scala exotic object O is called with argument V, the following steps are taken:

  1. Return ? SetImmutablePrototype(O, V).

4.1.3[[IsExtensible]] ( )

When the [[IsExtensible]] internal method of an SJSIR Scala exotic object O is called, the following steps are taken:

  1. Return ! OrdinaryIsExtensible(O).

4.1.4[[PreventExtensions]] ( )

When the [[PreventExtensions]] internal method of an SJSIR Scala exotic object O is called, the following steps are taken:

  1. Return ! OrdinaryPreventExtensions(O).

4.1.5[[GetOwnProperty]] ( P )

When the [[GetOwnProperty]] internal method of an SJSIR Scala exotic object O is called with property key P, the following steps are taken:

  1. Trigger an SJSIR Undefined Behavior.

4.1.6[[DefineOwnProperty]] ( P, Desc )

When the [[DefineOwnProperty]] internal method of an SJSIR Scala exotic object O is called with property key P and Property Descriptor Desc, the following steps are taken:

  1. Trigger an SJSIR Undefined Behavior.

4.1.7[[HasProperty]] ( P )

When the [[HasProperty]] internal method of an SJSIR Scala exotic object O is called with property key P, the following steps are taken:

  1. Return an implementation-defined Boolean value.

4.1.8[[Get]] ( P, Receiver )

When the [[Get]] internal method of an SJSIR Scala exotic object O is called with property key P and ECMAScript language value Receiver, the following steps are taken:

  1. Assert: IsPropertyKey(P) is true.
  2. If SameValue(Receiver, O) is false, trigger an SJSIR Undefined Behavior.
  3. If Type(P) is not String, then
    1. Trigger an SJSIR Undefined Behavior.
  4. Assert: Type(P) is String.
  5. If SJSIRIsValueOfType(O, char) is true, then
    1. Let charToStringSteps be the steps of an CharToString function as specified below.
    2. Let charToString be CreateBuiltinFunction(charToStringSteps, « [[Target]] »).
    3. Set charToString.[[Target]] to O.
    4. Return charToString.
  6. If SJSIRIsValueOfType(O, long) is true, then
    1. Let longToStringSteps be the steps of an LongToString function as specified below.
    2. Let longToString be CreateBuiltinFunction(longToStringSteps, « [[Target]] »).
    3. Set longToString.[[Target]] to O.
    4. Return longToString.
  7. Assert: O has an [[SJSIRClass]] internal slot.
  8. Let class be O.[[SJSIRClass]].
  9. Let memberDef be SJSIRResolveMemberExport(class, P).
  10. If memberDef is empty, then
    1. Trigger an SJSIR Undefined Behavior.
  11. Assert: memberDef is an SJSIRClassMember.
  12. Let programEnv be class.[[Environment]].
  13. Return the result of performing SJSIRExportedMemberGet of memberDef with arguments programEnv and O.

A CharToString function is an anonymous built-in function with a [[Target]] internal slot. When a CharToString function f that expects no argument is called it performs the following steps:

  1. Let charObject be this value.
  2. If SameValue(charObject, f.[[Target]]) is false, then
    1. Trigger an SJSIR Undefined Behavior.
  3. Let codeUnit be charObject.[[SJSIRCharValue]].
  4. Return the String value of length 1 containing one code unit codeUnit.

A LongToString function is an anonymous built-in function with a [[Target]] internal slot. When a LongToString function f that expects no argument is called it performs the following steps:

  1. Let longObject be this value.
  2. If SameValue(longObject, f.[[Target]]) is false, then
    1. Trigger an SJSIR Undefined Behavior.
  3. Let value be longObject.[[SJSIRLongValue]].
  4. If value >= 0, then
    1. Return the String value consisting of the code units of the digits of the decimal representation of value.
  5. Else,
    1. Set value to -value.
    2. Let str be the String value consisting of the code units of the digits of the decimal representation of value.
    3. Return the string-concatenation of the String "-" and str.

4.1.9[[Set]] ( P, V, Receiver )

When the [[Set]] internal method of an SJSIR Scala exotic object O is called with property key P, value V, and ECMAScript language value Receiver, the following steps are taken:

  1. Assert: IsPropertyKey(P) is true.
  2. If SameValue(Receiver, O) is false, trigger an SJSIR Undefined Behavior.
  3. If Type(P) is not String, then
    1. Trigger an SJSIR Undefined Behavior.
  4. Assert: Type(P) is String.
  5. If SJSIRIsValueOfType(O, char) is true, then
    1. Trigger an SJSIR Undefined Behavior.
  6. If SJSIRIsValueOfType(O, long) is true, then
    1. Trigger an SJSIR Undefined Behavior.
  7. Assert: O has an [[SJSIRClass]] internal slot.
  8. Let class be O.[[SJSIRClass]].
  9. Let memberDef be SJSIRResolveMemberExport(class, P).
  10. If memberDef is empty, then
    1. Trigger an SJSIR Undefined Behavior.
  11. Assert: memberDef is an SJSIRClassMember.
  12. Let programEnv be class.[[Environment]].
  13. Return the result of performing SJSIRExportedMemberSet of memberDef with arguments programEnv, O and V.

4.1.10[[Delete]] ( P )

When the [[Delete]] internal method of an SJSIR Scala exotic object O is called with property key P, the following steps are taken:

  1. Assert: IsPropertyKey(P) is true.
  2. Trigger an SJSIR Undefined Behavior.

4.1.11[[OwnPropertyKeys]] ( )

When the [[OwnPropertyKeys]] internal method of an SJSIR Scala exotic object O is called, the following steps are taken:

  1. Return an implementation-defined List that conforms to the invariants of [[OwnPropertyKeys]].

4.1.12SJSIRScalaObjectAllocate ( class )

When called with an argument class of type SJSIR Class, the abstract operation SJSIRScalaObjectAllocate performs the following steps:

  1. Assert: class is an SJSIR Class.
  2. Let throwableClass be ResolveSJSIRClass("java.lang.Throwable").
  3. If SJSIRIsSubclass(class, throwableClass), then
    1. Let additionalSlots be « [[ErrorData]] » [[ErrorData]].
  4. Else,
    1. Let additionalSlots be « »
  5. Let O be a newly created SJSIR Scala object with the internal slots listed in Table 5 and those in additionalSlots. All of those internal slots are initialized to undefined.
  6. Set O's essential internal methods to the definitions specified in 4.1.
  7. Set O.[[SJSIRClass]] to class.
  8. Set O.[[Extensible]] to an implementation-defined Boolean value.
  9. Let classDef be class.[[ClassDef]].
  10. Let static be false.
  11. Perform ! SJSIRCreateFields of classDef with arguments O and static.
  12. Return O.

4.2SJSIR Array Objects

An SJSIR Array object is an SJSIR Scala object whose class is an array class, i.e., its [[SJSIRClass]] refers to an SJSIR Class whose [[IsArray]] internal slot is true.

In addition to the internal slots SJSIR Scala objects, SJSIR Array objects have the internal slots listed in Table 6.

Table 6: Internal Slots of SJSIR Array Objects
Internal Slot Type Description
[[SJSIRArrayElements]] List of ECMAScript Language Value The elements stored in this array.

4.2.1CreateSJSIRArrayObject ( componentClass, length )

When called with arguments componentClass of type SJSIR Class and length of type Number, the abstract operation CreateSJSIRArrayObject performs the following steps:

  1. Assert: componentClass is an SJSIR Class.
  2. Assert: SJSIRIsValueOfType(length, int) is true.
  3. If length < 0, then
    1. Throw a RangeError exception.
  4. Let class be SJSIRGetArrayClassOf(componentClass).
  5. Let elements be a new empty List.
  6. Let zeroElement be SJSIRZeroOfClass(componentClass).
  7. Let index be 0.
  8. Repeat, while index < length
    1. Append zeroElement at the end of elements.
    2. Set index to index + 1.
  9. Let O be a newly created SJSIR Array object with the internal slots listed in Table 5 and Table 6. All of those internal slots are initialized to undefined.
  10. Set O's essential internal methods to the definitions specified in 4.1.
  11. Set O.[[SJSIRClass]] to class.
  12. Set O.[[Extensible]] to an implementation-defined Boolean value.
  13. Set O.[[SJSIRArrayElements]] to elements.
  14. Return O.

4.2.2CreateMultiSJSIRArrayObjectBase ( arrayClass, lengths, lengthIndex )

When called with arguments componentClass of type SJSIR Class, lengths of type List of Number and lengthIndex of type Number, the abstract operation CreateMultiSJSIRArrayObjectBase performs the following steps:

  1. Assert: arrayClass is an SJSIR Class.
  2. Assert: arrayClass.[[IsArray]] is true.
  3. Let lengthOfLengths be the length of lengths.
  4. Assert: lengthIndex < lengthOfLengths.
  5. Let componentClass be arrayClass.[[ComponentClass]].
  6. Let len be lengths[lengthIndex].
  7. Let O be CreateSJSIRArrayObject(componentClass, len).
  8. Let nextIndex be lengthIndex + 1.
  9. If nextIndex < lengthOfLengths, then
    1. Let elements be O.[[SJSIRArrayElements]].
    2. Let i be 0.
    3. Repeat, while i < len
      1. Let nestedArray be CreateMultiSJSIRArrayObjectBase(componentClass, lengths, nextIndex).
      2. Set elements[i] to nestedArray.
      3. Set i to i + 1.
  10. Return O.

4.2.3CreateMultiSJSIRArrayObject ( componentClass, lengths )

When called with arguments componentClass of type SJSIR Class and lengths of type List of Number, the abstract operation CreateMultiSJSIRArrayObject performs the following steps:

  1. Assert: componentClass is an SJSIR Class.
  2. Let len be the length of lengths.
  3. Assert: len0.
  4. Let arrayClass be componentClass.
  5. Let i be 0.
  6. Repeat, while i < len
    1. Let arrayClass be SJSIRGetArrayClassOf(arrayClass).
    2. Set i to i + 1.
  7. Return CreateMultiSJSIRArrayObjectBase(arrayClass, lengths, 0).

4.2.4SJSIRArrayClone ( O )

When called with argument O, the abstract operation SJSIRArrayClone performs the following steps:

  1. Assert: O has an [[SJSIRArrayElements]] internal slot.
  2. Let class be O.[[SJSIRClass]].
  3. Assert: class.[[IsArray]] is true.
  4. Let componentClass be class.[[ComponentClass]].
  5. Let elements be O.[[SJSIRArrayElements]].
  6. Let len be the length of elements.
  7. Let clone be CreateSJSIRArrayObject(componentClass, len).
  8. Let cloneElements be a copy of elements.
  9. Set clone.[[SJSIRArrayElements]] to cloneElements.
  10. Return clone.

4.3SJSIR Char Objects

An SJSIR Char object is similar to an SJSIR Scala object except it represents a value of type char. It has the same implementation for the essential methods, but not the same internal slots.

SJSIR Char objects have the internal slots listed in Table 7.

Table 7: Internal Slots of SJSIR Char Objects
Internal Slot Type Description
[[SJSIRCharValue]] Number The numerical value of the code unit that this char represents.
[[Extensible]] Boolean Whether this object is extensible. Note that this internal slot is only used by [[IsExtensible]] and [[PreventExtensions]], and does not actually affect whether it is allowed to alter the properties of an SJSIR Char object.

4.3.1CreateSJSIRCharObject ( charValue )

When called with an argument charValue of type Number, the abstract operation CreateSJSIRCharObject performs the following steps:

  1. Assert: charValue is a Number.
  2. Assert: SameValue(! ToUint16(charValue), charValue) is true.
  3. Let O be a newly created SJSIR Char object with the internal slots listed in Table 7. All of those internal slots are initialized to undefined.
  4. Set O's essential internal methods to the definitions specified in 4.1.
  5. Set O.[[SJSIRCharValue]] to charValue.
  6. Set O.[[Extensible]] to an implementation-defined Boolean value.
  7. Return O.

4.4SJSIR Long Objects

An SJSIR Long object is similar to an SJSIR Scala object except it represents a value of type long. It has the same implementation for the essential methods, but not the same internal slots.

SJSIR Long objects have the internal slots listed in Table 8.

Table 8: Internal Slots of SJSIR Long Objects
Internal Slot Type Description
[[SJSIRLongValue]] Mathematical integer value The value represented by this SJSIR Long object.
[[Extensible]] Boolean Whether this object is extensible. Note that this internal slot is only used by [[IsExtensible]] and [[PreventExtensions]], and does not actually affect whether it is allowed to alter the properties of an SJSIR Long object.

4.4.1CreateSJSIRLongObject ( longValue )

When called with an argument longValue that is a mathematical integer value, the abstract operation CreateSJSIRLongObject performs the following steps:

  1. Assert: longValue is a mathematical integer value.
  2. Assert: ! ToInt64(longValue) &eq; longValue.
  3. Let O be a newly created SJSIR Long object with the internal slots listed in Table 8. All of those internal slots are initialized to undefined.
  4. Set O's essential internal methods to the definitions specified in 4.1.
  5. Set O.[[SJSIRLongValue]] to longValue.
  6. Set O.[[Extensible]] to an implementation-defined Boolean value.
  7. Return O.

5Modifications to the ECMAScript Language productions

5.1Scripts

Syntax

Script:ScriptBodyopt ScriptBody:StatementList[~Yield, ~Await, ~Return] SJSIRProgram

5.1.1Static Semantics: Early Errors

ScriptBody:SJSIRProgram
  • It is a Syntax Error if the SJSIRProgram does not link or does not typecheck.

5.1.2Static Semantics: IsStrict

ScriptBody:SJSIRProgram
  1. Return true.

5.2Modules

Syntax

Module:ModuleBodyopt ModuleBody:ModuleItemList SJSIRProgram

5.2.1Module Semantics

5.2.1.1Static Semantics: Early Errors

ModuleBody:SJSIRProgram
  • It is a Syntax Error if the SJSIRProgram does not link or does not typecheck.

5.3Primary Expression

Syntax

PrimaryExpression[Yield, Await]:this IdentifierReference[?Yield, ?Await] Literal ArrayLiteral[?Yield, ?Await] ObjectLiteral[?Yield, ?Await] FunctionExpression ClassExpression[?Yield, ?Await] GeneratorExpression AsyncFunctionExpression AsyncGeneratorExpression RegularExpressionLiteral TemplateLiteral[?Yield, ?Await, ~Tagged] CoverParenthesizedExpressionAndArrowParameterList[?Yield, ?Await] SJSIRTree

5.3.1Semantics

5.3.1.1Static Semantics: HasName

PrimaryExpression:SJSIRTree
  1. Return false.

5.3.1.2Static Semantics: IsFunctionDefinition

PrimaryExpression:SJSIRTree
  1. Return false.

5.3.1.3Static Semantics: IsIdentifierRef

PrimaryExpression:SJSIRTree
  1. Return false.

5.3.1.4Static Semantics: IsValidSimpleAssignmentTarget

PrimaryExpression:SJSIRTree
  1. Return false.

5.4ECMAScript Language: Statements and Declarations

Syntax

Statement[Yield, Await, Return]:BlockStatement[?Yield, ?Await, ?Return] VariableStatement[?Yield, ?Await] EmptyStatement ExpressionStatement[?Yield, ?Await] IfStatement[?Yield, ?Await, ?Return] BreakableStatement[?Yield, ?Await, ?Return] ContinueStatement[?Yield, ?Await] BreakStatement[?Yield, ?Await] [+Return]ReturnStatement[?Yield, ?Await] WithStatement[?Yield, ?Await, ?Return] LabelledStatement[?Yield, ?Await, ?Return] ThrowStatement[?Yield, ?Await] TryStatement[?Yield, ?Await, ?Return] DebuggerStatement SJSIRTree

5.4.1Statement Semantics

5.4.1.1Static Semantics: ContainsDuplicateLabels

With parameter labelSet.

Statement:SJSIRTree
  1. Return false.

5.4.1.2Static Semantics: ContainsUndefinedBreakTarget

With parameter labelSet.

Statement:SJSIRTree
  1. Return false.

5.4.1.3Static Semantics: ContainsUndefinedContinueTarget

With parameters iterationSet and labelSet.

Statement:SJSIRTree
  1. Return false.

5.4.1.4Static Semantics: VarDeclaredNames

Statement:SJSIRTree
  1. Return a new empty List.

5.4.1.5Static Semantics: VarScopedDeclarations

Statement:SJSIRTree
  1. Return a new empty List.

6SJSIR Programs

Abstract Syntax

SJSIR programs cannot be written in ECMAScript Language Source Code, so their Syntax is an abstract syntax.

The algorithms in this specification assume that the SJSIRClassDef are ordered so that all classes are defined after their respective superclasses and superinterfaces. Since typechecking ensures that there is no cycle, such an order always exists and can be computed, if necessary. We omit this step for simplicity.

SJSIRProgram:SJSIRClassDefsSJSIRTreeopt SJSIRClassDefs:SJSIRClassDef SJSIRClassDefsSJSIRClassDef

6.1SJSIR Program Semantics

6.1.1Static Semantics: LexicallyDeclaredNames

SJSIRProgram:SJSIRClassDefsSJSIRTreeopt
  1. Return a new empty List.

6.1.2Static Semantics: LexicallyScopedDeclarations

SJSIRProgram:SJSIRClassDefsSJSIRTreeopt
  1. Return LexicallyScopedDeclarations of SJSIRClassDefs.
SJSIRClassDefs:SJSIRClassDefsSJSIRClassDef
  1. Let declarations be LexicallyScopedDeclarations of SJSIRClassDefs.
  2. Append to declarations the elements of the LexicallyScopedDeclarations of SJSIRClassDef.
  3. Return declarations.

6.1.3Static Semantics: VarDeclaredNames

SJSIRProgram:SJSIRClassDefsSJSIRTreeopt
  1. Return a new empty List.

6.1.4Static Semantics: VarScopedDeclarations

SJSIRProgram:SJSIRClassDefsSJSIRTreeopt
  1. Return a new empty List.

6.1.5Static Semantics: ExportEntries

SJSIRProgram:SJSIRClassDefsSJSIRTreeopt
  1. Return ExportEntries of SJSIRClassDefs.
SJSIRClassDefs:SJSIRClassDefsSJSIRClassDef
  1. Let entries be ExportEntries of SJSIRClassDefs.
  2. Append to entries the elements of the ExportEntries of SJSIRClassDef.
  3. Return entries.

6.1.6Static Semantics: ImportEntries

SJSIRProgram:SJSIRClassDefsSJSIRTreeopt
  1. Return ImportEntries of SJSIRClassDefs.
SJSIRClassDefs:SJSIRClassDefsSJSIRClassDef
  1. Let entries be ImportEntries of SJSIRClassDefs.
  2. Append to entries the elements of the ImportEntries of SJSIRClassDef.
  3. Return entries.

6.1.7Static Semantics: ModuleRequests

SJSIRProgram:SJSIRClassDefsSJSIRTreeopt
  1. Return ModuleRequests of SJSIRClassDefs.
SJSIRClassDefs:SJSIRClassDefsSJSIRClassDef
  1. Let moduleNames be ModuleRequests of SJSIRClassDefs.
  2. Let additionalNames be ModuleRequests of SJSIRClassDef.
  3. Append to moduleNames each element of additionalNames that is not already an element of moduleNames.
  4. Return moduleNames.

6.1.8Runtime Semantics: Evaluation

SJSIRProgram:SJSIRClassDefsSJSIRTreeopt
  1. Let globalThisRef be ? ResolveThisBinding().
  2. Let globalThis be ? GetValue(globalThisRef).
  3. Let oldEnv be the running execution context's LexicalEnvironment.
  4. Let innerEnv be NewSJSIRProgramEnvironment(oldEnv, globalThis).
  5. Set the running execution context's LexicalEnvironment to innerEnv.
  6. Perform CreateSJSIRPrimitiveClass(innerEnv, "void").
  7. Perform CreateSJSIRPrimitiveClass(innerEnv, "boolean").
  8. Perform CreateSJSIRPrimitiveClass(innerEnv, "char").
  9. Perform CreateSJSIRPrimitiveClass(innerEnv, "byte").
  10. Perform CreateSJSIRPrimitiveClass(innerEnv, "short").
  11. Perform CreateSJSIRPrimitiveClass(innerEnv, "int").
  12. Perform CreateSJSIRPrimitiveClass(innerEnv, "long").
  13. Perform CreateSJSIRPrimitiveClass(innerEnv, "float").
  14. Perform CreateSJSIRPrimitiveClass(innerEnv, "double").
  15. Let result be the result of evaluating SJSIRClassDefinition of SJSIRClassDefs.
  16. If result is not an abrupt completion, then
    1. Set result the result of evaluating SJSIRInitializeTopLevelExports of SJSIRClassDefs.
  17. If result is not an abrupt completion and SJSIRTree is present, then
    1. Set result to the result of evaluating SJSIRTree.
  18. Set the running execution context's LexicalEnvironment to oldEnv.
  19. Return result.
Note

No matter how control leaves the SJSIRProgram the LexicalEnvironment is always restored to its former state.

SJSIRClassDefs:SJSIRClassDef
  1. Return the result of evaluating SJSIRClassDef.
SJSIRClassDefs:SJSIRClassDefsSJSIRClassDef
  1. Let cdl be the result of evaluating SJSIRClassDefs.
  2. ReturnIfAbrupt(cdl).
  3. Return the result of evaluating SJSIRClassDef.

7SJSIR Types

Abstract Syntax

SJSIR types cannot be written in ECMAScript Language Source Code, so their Syntax is an abstract syntax.

SJSIRType:SJSIRClassName SJSIRType[] void any nothing null boolean char byte short int long float double string undef

7.1SJSIR Type Semantics

7.1.1Runtime Semantics: SJSIRTypeToClass

SJSIRType:SJSIRClassName
  1. If value is null, return true.
  2. Let className be the StringValue of SJSIRClassName.
  3. Return ResolveSJSIRClass(className).
SJSIRType:SJSIRType[]
  1. Let componentClass be the result of SJSIRTypeToClass of SJSIRType.
  2. Return SJSIRGetArrayClassOf(componentClass).
SJSIRType:void
  1. Return ResolveSJSIRClass("void", true).
SJSIRType:boolean
  1. Return ResolveSJSIRClass("boolean", true).
SJSIRType:char
  1. Return ResolveSJSIRClass("char", true).
SJSIRType:byte
  1. Return ResolveSJSIRClass("byte", true).
SJSIRType:short
  1. Return ResolveSJSIRClass("short", true).
SJSIRType:int
  1. Return ResolveSJSIRClass("int", true).
SJSIRType:long
  1. Return ResolveSJSIRClass("long", true).
SJSIRType:float
  1. Return ResolveSJSIRClass("float", true).
SJSIRType:double
  1. Return ResolveSJSIRClass("double", true).
SJSIRType:any nothing null string undef
  1. Assert: this case is unreachable.

7.1.2Runtime Semantics: SJSIRZeroOf

SJSIRType:SJSIRClassName SJSIRType[] any nothing null
  1. Return null.
SJSIRType:boolean
  1. Return false.
SJSIRType:char
  1. Return CreateSJSIRCharObject(0).
SJSIRType:byte short int float double
  1. Return 0.
SJSIRType:long
  1. Return CreateSJSIRLongObject(0).
SJSIRType:string
  1. Return "".
SJSIRType:undef
  1. Return undefined.
SJSIRType:void
  1. Assert: this case is unreachable.

7.1.3Runtime Semantics: SJSIRTypeHasValue

With parameter value.

SJSIRType:SJSIRClassName SJSIRType[]
  1. Let class be the result of SJSIRTypeToClass of this SJSIRType.
  2. Return SJSIRIsValueOfClass(value, class).
SJSIRType:void
  1. Return false.
SJSIRType:any
  1. Return true.
SJSIRType:nothing
  1. Return false.
SJSIRType:null
  1. If value is null, return true, else return false.
SJSIRType:boolean
  1. If Type(value) is Boolean, return true, else return false.
SJSIRType:char
  1. If value has an [[SJSIRCharValue]] internal slot, return true, else return false.
SJSIRType:byte
  1. If Type(value) is not Number, return false.
  2. Let byteValue be ! ToInt8(value).
  3. Return the result of SameValue(byteValue, value).
SJSIRType:short
  1. If Type(value) is not Number, return false.
  2. Let shortValue be ! ToInt16(value).
  3. Return the result of SameValue(shortValue, value).
SJSIRType:int
  1. If Type(value) is not Number, return false.
  2. Let intValue be ! ToInt32(value).
  3. Return the result of SameValue(intValue, value).
SJSIRType:long
  1. If value has an [[SJSIRLongValue]] internal slot, return true, else return false.
SJSIRType:float
  1. If Type(value) is not Number, return false.
  2. Let floatValue be ! ToFloat32(value).
  3. Return the result of SameValue(floatValue, value).
SJSIRType:double
  1. If Type(value) is Number, return true, else return false.
SJSIRType:string
  1. If Type(value) is String, return true, else return false.
SJSIRType:undef
  1. If value is undefined, return true, else return false.

7.1.4Runtime Semantics: SJSIRTypeHasNonNullValue

With parameter value.

SJSIRType:SJSIRType SJSIRType[] void any nothing null boolean char byte short int long float double string undef
  1. If value is null, return false.
  2. Return the result of SJSIRTypeHasValue of this SJSIRType with argument value.

8SJSIR Class and Member Definitions

Abstract Syntax

SJSIR class and member definitions cannot be written in ECMAScript Language Source Code, so their Syntax is an abstract syntax.

SJSIRClassDef:SJSIRClassCapturesoptSJSIRClassKindSJSIRClassNameSJSIRExtendsClauseoptSJSIRImplementsClauseoptSJSIRNativeLoadSpecopt{SJSIRClassMembers} SJSIRClassCaptures:<> <SJSIRParamDefList> SJSIRParamDefs:() (SJSIRParamDefList) SJSIRParamDefsRestAllowed:() (SJSIRRestParamDef) (SJSIRParamDefList) (SJSIRParamDefList,SJSIRRestParamDef) SJSIRParamDefList:SJSIRParamDef SJSIRParamDefList,SJSIRParamDef SJSIRParamDef:varoptIdentifier:SJSIRType SJSIRRestParamDef:varopt...Identifier:SJSIRType SJSIRClassKind:class module class interface abstract js type js class js module class native js class native js module class SJSIRExtendsClause:extendsSJSIRClassNameSJSIRSuperclassValueopt SJSIRSuperclassValue:viaSJSIRTree SJSIRImplementsClause:implementsSJSIRClassName SJSIRImplementsClause,SJSIRClassName SJSIRNativeLoadSpec:loadfromSJSIRGlobalLoadSpec loadfromSJSIRImportLoadSpec SJSIRGlobalLoadSpec:global:IdentifierSJSIRLoadSpecPath SJSIRImportLoadSpec:import(StringLiteral)SJSIRLoadSpecPathSJSIRLoadSpecFallbackopt SJSIRLoadSpecPath:[empty] SJSIRLoadSpecPathStringLiteral SJSIRLoadSpecFallback:fallbackSJSIRGlobalLoadSpec SJSIRClassName:Identifier SJSIRClassName.Identifier SJSIRClassMembers:[empty] SJSIRClassMembersSJSIRClassMember SJSIRClassMember:staticoptSJSIRValOrVarIdentifier:SJSIRType defSJSIRCtorNameSJSIRMethodSignature=SJSIRTree staticoptdefSJSIRMethodNameSJSIRMethodSignature=SJSIRTree defSJSIRMethodNameSJSIRMethodSignature staticoptSJSIRValOrVar[SJSIRTree]:SJSIRType staticoptdef[SJSIRTree]SJSIRParamDefsRestAllowed=SJSIRTree staticoptprop[SJSIRTree]SJSIRPropGetteroptSJSIRPropSetteropt export topclassStringLiteral export topmoduleStringLiteral export topstaticdefStringLiteralSJSIRParamDefsRestAllowed=SJSIRTree export topstaticfieldIdentifierasStringLiteral SJSIRValOrVar:val var SJSIRMethodSignature:SJSIRParamDefsSJSIRResultTypeopt SJSIRResultType::SJSIRType SJSIRPropGetter:get()=SJSIRTree SJSIRPropSetter:set(SJSIRParamDef){SJSIRTree} SJSIRCtorName::init___IdentifierName SJSIRReflProxyName::[lookahead ∉ SJSIRCtorName]IdentifierName__ SJSIRMethodName::[lookahead ∉ { SJSIRCtorName, SJSIRReflProxyName }]IdentifierName__IdentifierName

8.1SJSIR Class Definition

8.1.1Static Semantics: StringValue

SJSIRCtorName::init___IdentifierName SJSIRReflProxyName::[lookahead ∉ SJSIRCtorName]IdentifierName__ SJSIRMethodName::[lookahead ∉ { SJSIRCtorName, SJSIRReflProxyName }]IdentifierName__IdentifierName
  1. Return the String value consisting of the sequence of code units corresponding to this non-terminal. In determining the sequence any occurrences of \ UnicodeEscapeSequence are first replaced with the code point represented by the UnicodeEscapeSequence and then the code points of the entire non-terminal are converted to code units by UTF16Encoding each code point.
SJSIRClassName:Identifier
  1. Return the StringValue of Identifier.
SJSIRClassName:SJSIRClassName.Identifier
  1. Return the string-concatenation of the StringValue of SJSIRClassName, the code unit 0x002E (FULL STOP) and the StringValue of Identifier.

8.1.2Static Semantics: SJSIRInternalName

SJSIRClassName:Identifier
  1. Let name the StringValue of Identifier.
  2. Return the string-concatenation of the string "import_" and name.
SJSIRClassName:SJSIRClassName.Identifier
  1. Return the string-concatenation of the SJSIRInternalName of SJSIRClassName, the code unit 0x005F (LOW LINE) and the SJSIRInternalName of Identifier.
SJSIRClassMember:export topclassStringLiteral export topmoduleStringLiteral export topstaticdefStringLiteralSJSIRParamDefsRestAllowed=SJSIRTree export topstaticfieldIdentifierasStringLiteral
  1. Let name be the StringValue of StringLiteral.
  2. If this SJSIRClassMember is enclosed in a ModuleBody, then
    1. Let bindingName be the string-concatenation of the string "export_" and name.
    2. Return « bindingName ».
  3. Else,
    1. Return name.

8.1.3Static Semantics: LexicallyScopedDeclarations

SJSIRClassDef:SJSIRClassCapturesoptSJSIRClassKindSJSIRClassNameSJSIRExtendsClauseoptSJSIRImplementsClauseoptSJSIRNativeLoadSpecopt{SJSIRClassMembers}
  1. Return the LexicallyScopedDeclarations of SJSIRClassMembers.
SJSIRClassMembers:[empty]
  1. Return a new empty List.
SJSIRClassMembers:SJSIRClassMembersSJSIRClassMember
  1. Let declarations be LexicallyScopedDeclarations of SJSIRClassMembers.
  2. Append to declarations the elements of the LexicallyScopedDeclarations of SJSIRClassMember.
  3. Return declarations.
SJSIRClassMember:staticoptSJSIRValOrVarIdentifier:SJSIRType defSJSIRCtorNameSJSIRMethodSignature=SJSIRTree staticoptdefSJSIRMethodNameSJSIRMethodSignature=SJSIRTree defSJSIRMethodNameSJSIRMethodSignature staticoptSJSIRValOrVar[SJSIRTree]:SJSIRType staticoptdef[SJSIRTree]SJSIRParamDefsRestAllowed=SJSIRTree staticoptprop[SJSIRTree]SJSIRPropGetteroptSJSIRPropSetteropt
  1. Return a new empty List.
SJSIRClassMember:export topclassStringLiteral export topmoduleStringLiteral export topstaticdefStringLiteralSJSIRParamDefsRestAllowed=SJSIRTree export topstaticfieldIdentifierasStringLiteral
  1. Let declaration be this SJSIRClassMember.
  2. Return « declaration ».

8.1.4Static Semantics: BoundNames

SJSIRClassMember:export topclassStringLiteral export topmoduleStringLiteral export topstaticdefStringLiteralSJSIRParamDefsRestAllowed=SJSIRTree export topstaticfieldIdentifierasStringLiteral
  1. Let internalName be the SJSIRInternalName of this SJSIRClassMember.
  2. Return « internalName ».

8.1.5Static Semantics: IsConstantDeclaration

SJSIRClassMember:export topclassStringLiteral export topmoduleStringLiteral export topstaticdefStringLiteralSJSIRParamDefsRestAllowed=SJSIRTree
  1. Return true.
SJSIRClassMember:export topstaticfieldIdentifierasStringLiteral
  1. Return false.

8.1.6Static Semantics: ExportEntries

SJSIRClassDef:SJSIRClassCapturesoptSJSIRClassKindSJSIRClassNameSJSIRExtendsClauseoptSJSIRImplementsClauseoptSJSIRNativeLoadSpecopt{SJSIRClassMembers}
  1. Return the ExportEntries of SJSIRClassMembers.
SJSIRClassMembers:[empty]
  1. Return a new empty List.
SJSIRClassMembers:SJSIRClassMembersSJSIRClassMember
  1. Let entries be ExportEntries of SJSIRClassMembers.
  2. Append to entries the elements of the ExportEntries of SJSIRClassMember.
  3. Return entries.
SJSIRClassMember:staticoptSJSIRValOrVarIdentifier:SJSIRType defSJSIRCtorNameSJSIRMethodSignature=SJSIRTree staticoptdefSJSIRMethodNameSJSIRMethodSignature=SJSIRTree defSJSIRMethodNameSJSIRMethodSignature staticoptSJSIRValOrVar[SJSIRTree]:SJSIRType staticoptdef[SJSIRTree]SJSIRParamDefsRestAllowed=SJSIRTree staticoptprop[SJSIRTree]SJSIRPropGetteroptSJSIRPropSetteropt
  1. Return a new empty List.
SJSIRClassMember:export topclassStringLiteral export topmoduleStringLiteral export topstaticdefStringLiteralSJSIRParamDefsRestAllowed=SJSIRTree export topstaticfieldIdentifierasStringLiteral
  1. Let internalName be the SJSIRInternalName of this SJSIRClassMember.
  2. Let exportName be the StringValue of StringLiteral.
  3. Let entry be the ExportEntry Record {[[ModuleRequest]]: null, [[ImportName]]: null, [[LocalName]]: internalName, [[ExportName]]: exportName}.
  4. Return « entry ».

8.1.7Static Semantics: SJSIRImportName

SJSIRLoadSpecPath:[empty]
  1. Return the String "*".
SJSIRLoadSpecPath:SJSIRLoadSpecPathStringLiteral
  1. Let importName be SJSIRImportName of SJSIRLoadSpecPath.
  2. If SameValue(importName, "*") is true, then
    1. Return the StringValue of StringLiteral.
  3. Else,
    1. Return importName.
Note

SJSIRImportName returns the StringValue of the first (most nested) StringLiteral of this SJSIRLoadSpecPath, or "*" if it is completely empty.

8.1.8Static Semantics: ImportEntries

SJSIRClassDef:SJSIRClassCapturesoptSJSIRClassKindSJSIRClassNameSJSIRExtendsClauseoptSJSIRImplementsClauseoptSJSIRNativeLoadSpecopt{SJSIRClassMembers}
  1. If this SJSIRClassDef is enclosed in a ModuleBody, then
    1. If SJSIRNativeLoadSpec is present and has the production loadfrom SJSIRImportLoadSpec, then
      1. Let loadSpec be the SJSIRImportLoadSpec of SJSIRNativeLoadSpec.
      2. Let moduleStringLiteral be the StringLiteral of loadSpec.
      3. Let module be the StringValue of moduleStringLiteral.
      4. Let path be the SJSIRLoadSpecPath of loadSpec.
      5. Let importName be SJSIRImportName of path.
      6. Let localName be SJSIRInternalName of this SJSIRClassDef.
      7. Let entry be the ImportEntry Record {[[ModuleRequest]]: module, [[ImportName]]: importName, [[LocalName]]: localName }.
      8. Return « entry »
  2. Return « ».

8.1.9Static Semantics: ModuleRequests

SJSIRProgram:SJSIRClassDefsSJSIRTreeopt
  1. Return ModuleRequests of SJSIRClassDefs.
SJSIRClassDefs:SJSIRClassDefsSJSIRClassDef
  1. Let moduleNames be ModuleRequests of SJSIRClassDefs.
  2. Let additionalNames be ModuleRequests of SJSIRClassDef.
  3. Append to moduleNames each element of additionalNames that is not already an element of moduleNames.
  4. Return moduleNames.

8.1.10Static Semantics: SJSIRGetMethodInClass

With parameters methodName and static.

SJSIRClassDef:SJSIRClassCapturesoptSJSIRClassKindSJSIRClassNameSJSIRExtendsClauseoptSJSIRImplementsClauseoptSJSIRNativeLoadSpecopt{SJSIRClassMembers}
  1. Return the SJSIRGetMethodInClass of SJSIRClassMembers with parameters methodName and static.
SJSIRClassMembers:[empty]
  1. Return empty.
SJSIRClassMembers:SJSIRClassMembersSJSIRClassMember
  1. Let inList be SJSIRGetMethodInClass of SJSIRClassMembers with parameters methodName and static.
  2. If inList is not empty, return inList.
  3. Return the result of SJSIRGetMethodInClass of SJSIRClassMember with parameters methodName and static.
SJSIRClassMember:staticdefSJSIRMethodNameSJSIRMethodSignature=SJSIRTree
  1. If static is false, return empty.
  2. Let thisMethodName be the StringValue of SJSIRMethodName.
  3. If SameValue(thisMethodName, methodName), then
    1. Return this SJSIRClassMember.
  4. Else,
    1. Return empty.
SJSIRClassMember:defSJSIRCtorNameSJSIRMethodSignature=SJSIRTree
  1. If static is true, return empty.
  2. Let thisCtorName be the StringValue of SJSIRCtorName.
  3. If SameValue(thisCtorName, methodName), then
    1. Return this SJSIRClassMember.
  4. Else,
    1. Return empty.
SJSIRClassMember:defSJSIRMethodNameSJSIRMethodSignature=SJSIRTree
  1. If static is true, return empty.
  2. Let thisMethodName be the StringValue of SJSIRMethodName.
  3. If SameValue(thisMethodName, methodName), then
    1. Return this SJSIRClassMember.
  4. Else if methodName ends with "__", then
    1. NOTE: It is a reflective proxy method name.
    2. Let searchPos be the length of thisMethodName.
    3. Repeat, while the code units at index searchPos-1 and searchPos-2 in methodName are not both 0x005F (LOW LINE)
      1. Assert: searchPos > 2.
      2. Set searchPos to searchPos - 1.
    4. If the sequence of elements of thisMethodName starting at 0 of length searchPos is the same as the full element sequence of methodName, then
      1. Return this SJSIRClassMember.
    5. Else,
      1. Return empty.
  5. Else,
    1. Return empty.
SJSIRClassMember:other
  1. Return empty.

8.1.11Static Semantics: SJSIRGetMemberExportInClass

With argument propName.

SJSIRClassDef:SJSIRClassCapturesoptSJSIRClassKindSJSIRClassNameSJSIRExtendsClauseoptSJSIRImplementsClauseoptSJSIRNativeLoadSpecopt{SJSIRClassMembers}
  1. Return the SJSIRGetMemberExportInClass of SJSIRClassMembers with argument propName.
SJSIRClassMembers:[empty]
  1. Return empty.
SJSIRClassMembers:SJSIRClassMembersSJSIRClassMember
  1. Let inList be SJSIRGetMemberExportInClass of SJSIRClassMembers with argument propName.
  2. If inList is not empty, return inList.
  3. Return the result of SJSIRGetMemberExportInClass of SJSIRClassMember with argument propName.
SJSIRClassMember:def[SJSIRTree]SJSIRParamDefsRestAllowed=SJSIRTree
  1. Let thisPropNameTree be the first SJSIRTree.
  2. Assert: thisPropNameTree is a StringLiteral.
  3. Let thisPropName be the StringValue of thisPropNameTree.
  4. If SameValue(thisPropName, _propName) is true, then
    1. Return this SJSIRClassMember.
  5. Else,
    1. Return empty.
SJSIRClassMember:prop[SJSIRTree]SJSIRPropGetteroptSJSIRPropSetteropt
  1. Let thisPropNameTree be SJSIRTree.
  2. Assert: thisPropNameTree is a StringLiteral.
  3. Let thisPropName be the StringValue of thisPropNameTree.
  4. If SameValue(thisPropName, _propName) is true, then
    1. Return this SJSIRClassMember.
  5. Else,
    1. Return empty.
SJSIRClassMember:other
  1. Return empty.

8.1.12Static Semantics: TranslateJSPropertyName

SJSIRTree:StringLiteral
  1. Let literalPropName be a new Parse Node of type LiteralPropertyName whose only child is StringLiteral.
  2. Return a new Parse Node of type PropertyName whose only child is literalPropName.
SJSIRTree:other
  1. Let computedPropName be a new Parse Node of type ComputedPropertyName whose only child is this SJSIRTree.
  2. Return a new Parse Node of type PropertyName whose only child is computedPropName.

8.1.13Static Semantics: TranslateJSClassMembers

SJSIRClassMembers:[empty]
  1. Return a new empty List.
SJSIRClassMembers:SJSIRClassMembersSJSIRClassMember
  1. Let prevClassElements be TranslateJSClassMembers of SJSIRClassMembers.
  2. Let thisClassElements be TranslateJSClassMembers of SJSIRClassMember.
  3. For each classElement in thisClassElements, do
    1. Append classElement at the end of prevClassElements.
  4. Return prevClassElements.
SJSIRClassMember:staticoptdef[SJSIRTree]SJSIRParamDefsRestAllowed=SJSIRTree
  1. Let propertyName be TranslateJSPropertyName of the first SJSIRTree.
  2. Let formalParameters be TranslateFormalParams of SJSIRParamDefsRestAllowed.
  3. Let uniqueFormalParameters be a new Parse Node of type UniqueFormalParameters whose only child is formalParameters.
  4. Let return be a new Parse Node of type ReturnStatement whose only child is the second SJSIRTree.
  5. Let body be new Parse Node of type FunctionBody whose only child is return (wrapped in a StatementList, wrapped in a FunctionStatementList.
  6. Let methodDef be a new Parse Node of type MethodDefinition with the production PropertyName ( UniqueFormalParameters ) { FunctionBody } with propertyName, uniqueFormalParameters and body as children.
  7. If static is present, then
    1. Let classElement be a new Parse Node of type ClassElement whose only child is methodDef.
  8. Else,
    1. Let classElement be a new Parse Node of type ClassElement whose children are static and methodDef.
  9. Return « classElement »
SJSIRClassMember:staticoptprop[SJSIRTree]SJSIRPropGetteroptSJSIRPropSetteropt
  1. Let result be a new empty List.
  2. Let propertyName be TranslateJSPropertyName of the first SJSIRTree.
  3. If SJSIRPropGetter is present, then
    1. Let getterBodyTree be the SJSIRTree of SJSIRPropGetter.
    2. Let getterReturn be a new Parse Node of type ReturnStatement whose only child is getterBodyTree.
    3. Let getterBody be new Parse Node of type FunctionBody whose only child is getterReturn (wrapped in a StatementList, wrapped in a FunctionStatementList).
    4. Let getterMethodDef be a new Parse Node of type MethodDefinition with the production get PropertyName ( ) { FunctionBody } with propertyName, and getterBody as children.
    5. If static is present, then
      1. Let getterClassElement be a new Parse Node of type ClassElement whose only child is getterMethodDef.
    6. Else,
      1. Let getterClassElement be a new Parse Node of type ClassElement whose children are static and getterMethodDef.
    7. Append getterClassElement at the end of result.
  4. If SJSIRPropSetter is present, then
    1. Let setterParamDef be the SJSIRParamDef of SJSIRPropSetter.
    2. Let setterBodyTree be the SJSIRTree of SJSIRPropSetter.
    3. Let setterFormalParameter be TranslateFormalParam of setterParamDef.
    4. Let setterFormalParamList be a new Parse Node of type PropertySetParameterList whose only child is setterFormalParameter.
    5. Let setterBody be new Parse Node of type FunctionBody whose only child is setterBodyTree (wrapped in a StatementList, wrapped in a FunctionStatementList).
    6. Let setterMethodDef be a new Parse Node of type MethodDefinition with the production set PropertyName ( PropertySetParameterList ) { FunctionBody } with propertyName, setterFormalParamList and setterBody as children.
    7. If static is present, then
      1. Let setterClassElement be a new Parse Node of type ClassElement whose only child is setterMethodDef.
    8. Else,
      1. Let setterClassElement be a new Parse Node of type ClassElement whose children are static and setterMethodDef.
    9. Append setterClassElement at the end of result.
  5. Return result.
SJSIRClassMember:other
  1. Return a new empty List.

8.1.14Static Semantics: TranslateJSClassBody

SJSIRClassMembers:[empty]
  1. Assert: this case is unreachable.
SJSIRClassMembers:SJSIRClassMembersSJSIRClassMember
  1. Let classElements be TranslateJSClassMembers of this SJSIRClassMembers.
  2. Let classElementList be empty.
  3. For each classElement in classElements, do
    1. If classElementList is empty, then
      1. Set classElementList to a new Parse Node of type ClassElementList with classElement as only child.
    2. Else,
      1. Let newClassElementList be a new Parse Node of type ClassElementList with classElementList and classElement as children.
      2. Set classElementList to newClassElementList.
  4. Assert: classElementList is not empty.
  5. Return a new Parse Node of type ClassBody with classElementList as only child.

8.1.15Runtime Semantics: SJSIRLoadSpecPathEvaluation

With argument obj and ignoreInnermost.

SJSIRLoadSpecPath : [empty]
  1. Return obj.
SJSIRLoadSpecPath : SJSIRLoadSpecPath StringLiteral
  1. If ignoreInnermost is true and SJSIRLoadSpecPath has the production [empty], then
    1. Return obj.
  2. Else,
    1. Let obj2 be ? SJSIRLoadSpecPathEvaluation of SJSIRLoadSpecPath with argument obj.
    2. Let bv be ? RequireObjectCoercible(obj2).
    3. Let propertyKey be the StringValue of StringLiteral.
    4. Let ref be a value of type Reference whose base value component is bv, whose referenced name component is propertyKey, and whose strict reference flag is true.
    5. Return ? GetValue(ref).

8.1.16Runtime Semantics: SJSIRLoadSpecEvaluation

With parameter classDef.

SJSIRGlobalLoadSpec:global:IdentifierSJSIRLoadSpecPath
  1. Let name be the StringValue of Identifier
  2. Let globalRef be ? SJSIRResolveGlobalRef(name).
  3. Let globalVal be ? GetValue(globalRef).
  4. Return the result of evaluating SJSIRLoadSpecPathEvaluation of SJSIRLoadSpecPath with arguments globalVal and false.
SJSIRImportLoadSpec:import(StringLiteral)SJSIRLoadSpecPathSJSIRLoadSpecFallbackopt
  1. If this node is enclosed in a ScriptBody, then
    1. Assert: SJSIRLoadSpecFallback is present.
    2. Return the result of SJSIRLoadSpecEvaluation of SJSIRLoadSpecFallback with argument classDef.
  2. Else,
    1. Let internalName be the SJSIRInternalName of classDef.
    2. Let lex be the running execution context's LexicalEnvironment.
    3. Let globalEnv be FindSJSIRProgramEnv(lex).
    4. Let binding be ! ResolveBinding(interfaceName, globalEnv).
    5. Let initialVal be ? GetValue(binding).
    6. Return the result of evaluating SJSIRLoadSpecPathEvaluation of SJSIRLoadSpecPath with arguments initialVal and true.

8.1.17Runtime Semantics: SJSIRClassDefinition

SJSIRClassDef:SJSIRClassCapturesoptSJSIRClassKindSJSIRClassNameSJSIRExtendsClauseoptSJSIRImplementsClauseoptSJSIRNativeLoadSpecopt{SJSIRClassMembers}
  1. Let env be the running execution context's LexicalEnvironment.
  2. Let classDef be this SJSIRClassDef.
  3. Let class be CreateSJSIRClass(env, classDef).
  4. Perform the CreateStaticFields of SJSIRClassMembers.
  5. Return NormalCompletion(empty).

8.1.18Runtime Semantics: SJSIRInitializeTopLevelExports

SJSIRClassDef:SJSIRClassCapturesoptSJSIRClassKindSJSIRClassNameSJSIRExtendsClauseoptSJSIRImplementsClauseoptSJSIRNativeLoadSpecopt{SJSIRClassMembers}
  1. Let className with the StringValue of SJSIRClassName.
  2. Let class be ResolveSJSIRClass(className).
  3. Return the result of SJSIRInitializeTopLevelExports of SJSIRClassMembers with argument class.

8.1.19Runtime Semantics: SJSIRInitializeTopLevelExportsForClass

With parameter class.

  1. Return the result of SJSIRInitializeTopLevelExports of SJSIRClassMembers with argument class.
SJSIRClassMembers:[empty]
  1. Return NormalCompletion(empty).
SJSIRClassMembers:SJSIRClassMembersSJSIRClassMember
  1. Perform ? SJSIRInitializeTopLevelExports of SJSIRClassMembers with argument class.
  2. Return the result of SJSIRInitializeTopLevelExports of SJSIRClassMember with argument class.
SJSIRClassMember:staticoptSJSIRValOrVarIdentifier:SJSIRType defSJSIRCtorNameSJSIRMethodSignature=SJSIRTree staticoptdefSJSIRMethodNameSJSIRMethodSignature=SJSIRTree defSJSIRMethodNameSJSIRMethodSignature staticoptSJSIRValOrVar[SJSIRTree]:SJSIRType staticoptdef[SJSIRTree]SJSIRParamDefsRestAllowed=SJSIRTree staticoptprop[SJSIRTree]SJSIRPropGetteroptSJSIRPropSetteropt
  1. Return NormalCompletion(empty).
SJSIRClassMember:export topclassStringLiteral
  1. Let internalName be the SJSIRInternalName of this SJSIRClassMember.
  2. Let lhs be ResolveBinding(internalName).
  3. Let jsClassValue be ? SJSIRLoadConstructorOf(class).
  4. Return InitializeReferencedBinding(lhs, jsClassValue).
SJSIRClassMember:export topmoduleStringLiteral
  1. Let internalName be the SJSIRInternalName of this SJSIRClassMember.
  2. Let lhs be ResolveBinding(internalName).
  3. Let moduleValue be ? SJSIRLoadModule(class).
  4. Return InitializeReferencedBinding(lhs, moduleValue).
SJSIRClassMember:export topstaticdefStringLiteralSJSIRParamDefsRestAllowed=SJSIRTree
  1. Let internalName be the SJSIRInternalName of this SJSIRClassMember.
  2. Let lhs be ResolveBinding(internalName).
  3. Let formalParameters be TranslateFormalParams of SJSIRParamDefsRestAllowed.
  4. Let functionBody be an instance of ReturnStatement with production return Expression whose only child is SJSIRTree.
  5. Let lex be the running execution context's LexicalEnvironment.
  6. Let strict be true.
  7. Let closure be FunctionCreate(Normal, formalParameters, functionBody, lex, strict).
  8. Perform MakeConstructor(closure).
  9. Return closure.
  10. Return InitializeReferencedBinding(lhs, closure).
SJSIRClassMember:export topstaticfieldIdentifierasStringLiteral
  1. Let internalName be the SJSIRInternalName of this SJSIRClassMember.
  2. Let lhs be ResolveBinding(internalName).
  3. Let staticFields be class.[[StaticFields]].
  4. Let fieldName be the StringValue of Identifier.
  5. Return ! staticFields.[[Get]](fieldName, staticFields).
  6. Return InitializeReferencedBinding(lhs, closure).

8.1.20Runtime Semantics: SJSIRUpdateStaticFieldExport

With parameters fieldName and newValue.

  1. Return the result of SJSIRUpdateStaticFieldExport of SJSIRClassMembers with arguments fieldName and newValue.
SJSIRClassMembers:[empty]
  1. Return NormalCompletion(empty).
SJSIRClassMembers:SJSIRClassMembersSJSIRClassMember
  1. Perform ? SJSIRUpdateStaticFieldExport of SJSIRClassMembers with arguments fieldName and newValue.
  2. Return the result of SJSIRUpdateStaticFieldExport of SJSIRClassMember with arguments fieldName and newValue.
SJSIRClassMember:staticoptSJSIRValOrVarIdentifier:SJSIRType defSJSIRCtorNameSJSIRMethodSignature=SJSIRTree staticoptdefSJSIRMethodNameSJSIRMethodSignature=SJSIRTree defSJSIRMethodNameSJSIRMethodSignature staticoptSJSIRValOrVar[SJSIRTree]:SJSIRType staticoptdef[SJSIRTree]SJSIRParamDefsRestAllowed=SJSIRTree staticoptprop[SJSIRTree]SJSIRPropGetteroptSJSIRPropSetteropt export topclassStringLiteral export topmoduleStringLiteral export topstaticdefStringLiteralSJSIRParamDefsRestAllowed=SJSIRTree
  1. Return NormalCompletion(empty).
SJSIRClassMember:export topstaticfieldIdentifierasStringLiteral
  1. Let thisField be StringValue of Identifier.
  2. If SameValue(thisField, fieldName) is false, then
    1. Return NormalCompletion(empty).
  3. Else,
    1. Let lex be the running execution context's LexicalEnvironment.
    2. Let globalEnv be FindSJSIRProgramEnv(lex).
    3. Let internalName be the SJSIRInternalName of this SJSIRClassMember.
    4. Let lhs be ResolveBinding(internalName, globalEnv).
    5. Return ? PutValue(lhs, newValue).

8.1.21Runtime Semantics: Evaluation

SJSIRExtendsClause:extendsSJSIRClassNameSJSIRSuperclassValue
  1. Return the result of evaluating SJSIRSuperclassValue.
SJSIRExtendsClause:extendsSJSIRClassName
  1. Let env be the running execution context's LexicalEnvironment.
  2. Let className be the StringValue of SJSIRClassName.
  3. Let class be ResolveSJSIRClass(className).
  4. Return ? SJSIRLoadConstructorOf(class).

8.1.22Runtime Semantics: SJSIRBindParams

With parameters env, argList and listIndex.

SJSIRClassCaptures:<>
  1. Let len be the length of argList.
  2. Assert: SameValue(listIndex, len) is true.
  3. Return listIndex.
SJSIRClassCaptures:<SJSIRParamDefList>
  1. Let newListIndex be the result of SJSIRBindParams of SJSIRParamDefList with arguments env, argList and listIndex.
  2. Let len be the length of argList.
  3. Assert: SameValue(newListIndex, len) is true.
  4. Return newListIndex.
SJSIRParamDefs:()
  1. Let len be the length of argList.
  2. Assert: SameValue(listIndex, len) is true.
  3. Return listIndex.
SJSIRParamDefs:(SJSIRParamDefList)
  1. Let newListIndex be the result of SJSIRBindParams of SJSIRParamDefList with arguments env, argList and listIndex.
  2. Let len be the length of argList.
  3. Assert: SameValue(newListIndex, len) is true.
  4. Return newListIndex.
SJSIRParamDefList:SJSIRParamDefList,SJSIRParamDef
  1. Let nextListIndex be the result of SJSIRBindParams of SJSIRParamDefList with arguments env, argList and listIndex.
  2. Let newListIndex be the result of SJSIRBindParams of SJSIRParamDef with arguments env, argList and nextListIndex.
  3. Return newListIndex.
SJSIRParamDef:varIdentifier:SJSIRType
  1. Let len be the length of argList.
  2. Assert: SameValue(listIndex, len) is false.
  3. Let value be argList[listIndex].
  4. Assert: SJSIRIsValueOfType(value, SJSIRType) is true.
  5. Let envRec be env's EnvironmentRecord.
  6. Let dn be the StringValue of Identifier.
  7. Perform ! envRec.CreateMutableBinding(dn, false).
  8. Return listIndex+1.
SJSIRParamDef:Identifier:SJSIRType
  1. Let len be the length of argList.
  2. Assert: SameValue(listIndex, len) is false.
  3. Let value be argList[listIndex].
  4. Assert: SJSIRIsValueOfType(value, SJSIRType) is true.
  5. Let envRec be env's EnvironmentRecord.
  6. Let dn be the StringValue of Identifier.
  7. Perform ! envRec.CreateImmutableBinding(dn, true).
  8. Return listIndex+1.
Note

Since there are no rest parameters in SJSIRParamDefs, and because of typechecking, the number of actual arguments is always equal to the number of formal parameters.

8.1.23Runtime Semantics: SJSIREvaluateMethodBody

With parameters receiver, argList and body.

SJSIRMethodSignature:SJSIRParamDefsSJSIRResultTypeopt
  1. Let oldEnv be the running execution context's LexicalEnvironment.
  2. Let programEnv be FindSJSIRProgramEnv(oldEnv).
  3. Let env be NewSJSIRMethodEnvironment(programEnv, receiver).
  4. Perform SJSIRBindParams of SJSIRParamDefs with arguments env, argList and 0.
  5. Set the running execution context's LexicalEnvironment to env.
  6. Let result be the result of evaluating SJSIRTree.
  7. Assert: result.[[Type]] is either normal or throw.
  8. Set the running execution context's LexicalEnvironment to oldEnv.
  9. Return result.
Note

Completion records whose type is continue or return cannot happen here because no SJSIRTree ever produce one. Moreover, any completion record with type break should have been caught by the appropriate labeled block.

8.1.24Runtime Semantics: SJSIREvaluateMethod

With parameters receiver and argList.

SJSIRClassMember:staticdefSJSIRMethodNameSJSIRMethodSignature=SJSIRTree
  1. Assert: receiver is empty.
  2. Return the result of evaluating SJSIREvaluateMethodBody of SJSIRMethodSignature with arguments receiver, argList and SJSIRTree.
SJSIRClassMember:defSJSIRCtorNameSJSIRMethodSignature=SJSIRTree
  1. Assert: receiver is not empty.
  2. Return the result of evaluating SJSIREvaluateMethodBody of SJSIRMethodSignature with arguments receiver, argList and SJSIRTree.
SJSIRClassMember:defSJSIRMethodNameSJSIRMethodSignature=SJSIRTree
  1. Assert: receiver is not empty.
  2. Return the result of evaluating SJSIREvaluateMethodBody of SJSIRMethodSignature with arguments receiver, argList and SJSIRTree.

8.1.25Runtime Semantics: SJSIRExportedMemberGet

With parameters programEnv and receiver.

SJSIRClassMember:def[SJSIRTree]SJSIRParamDefsRestAllowed=SJSIRTree
  1. Let formalParameters be TranslateFormalParams of SJSIRParamDefsRestAllowed.
  2. Let functionBody be an instance of ReturnStatement with production return Expression whose only child is SJSIRTree.
  3. Let scope be NewDeclarativeEnvironment(programEnv).
  4. Perform ? SJSIRCapturesEvaluation of SJSIRCaptures with argument scope.
  5. Let strict be true.
  6. Let closure be FunctionCreate(Method, formalParameters, functionBody, scope, strict).
  7. Return closure.
Note 1

The returned function is intended to be called with a this value which is the same object as receiver. If it is called with a different this value, it should trigger an SJSIR Undefined Behavior. This part of the specification is not spelled out to keep some factorization.

Note 2

An implementation is allowed to return the same function object on successive calls to this operation.

SJSIRClassMember:prop[SJSIRTree]SJSIRPropGetteroptSJSIRPropSetteropt
  1. If SJSIRPropGetter is not present, then
    1. Trigger an SJSIR Undefined Behavior.
  2. Let body be the SJSIRTree of SJSIRPropGetter.
  3. Let env be NewSJSIRMethodEnvironment(programEnv, receiver).
  4. Set the running execution context's LexicalEnvironment to env.
  5. Let result be the result of evaluating SJSIRTree.
  6. Assert: result.[[Type]] is either normal or throw.
  7. Set the running execution context's LexicalEnvironment to oldEnv.
  8. Return result.

8.1.26Runtime Semantics: SJSIRExportedMemberSet

With parameters programEnv, receiver and value.

SJSIRClassMember:def[SJSIRTree]SJSIRParamDefsRestAllowed=SJSIRTree
  1. Trigger an SJSIR Undefined Behavior.
SJSIRClassMember:prop[SJSIRTree]SJSIRPropGetteroptSJSIRPropSetteropt
  1. If SJSIRPropSetter is not present, then
    1. Trigger an SJSIR Undefined Behavior.
  2. Let paramDef be the SJSIRParamDef of SJSIRPropSetter.
  3. Let body be the SJSIRTree of SJSIRPropSetter.
  4. Let env be NewSJSIRMethodEnvironment(programEnv, receiver).
  5. Perform SJSIRBindParams of paramDef with arguments env, « value » and 0.
  6. Set the running execution context's LexicalEnvironment to env.
  7. Let result be the result of evaluating SJSIRTree.
  8. Assert: result.[[Type]] is either normal or throw.
  9. Set the running execution context's LexicalEnvironment to oldEnv.
  10. ReturnIfAbrupt(result).
  11. Return true.

8.1.27Runtime Semantics: SJSIRCreateFields

With arguments obj and static.

SJSIRClassDef:SJSIRClassCapturesoptSJSIRClassKindSJSIRClassNameSJSIRExtendsClauseoptSJSIRImplementsClauseoptSJSIRNativeLoadSpecopt{SJSIRClassMembers}
  1. Return the result of evaluating SJSIRCreateFields of SJSIRClassMembers with arguments obj and static.
SJSIRClassMembers:[empty]
  1. Return NormalCompletion(empty).
SJSIRClassMembers:SJSIRClassMembersSJSIRClassMember
  1. Perform ? SJSIRCreateFields of SJSIRClassMembers with arguments obj and static.
  2. Perform ? SJSIRCreateFields of SJSIRClassMember with arguments obj and static.
  3. Return NormalCompletion(empty).
SJSIRClassMember:staticoptSJSIRValOrVarIdentifier:SJSIRType
  1. If static is true and static is not present, return empty.
  2. If static is false and static is present, return empty.
  3. Let propertyName be the StringValue of Identifier.
  4. Let zeroValue be SJSIRZeroOf of SJSIRType.
  5. Perform ? CreateDataProperty(obj, propertyName, zeroValue).
  6. Return NormalCompletion(empty).
SJSIRClassMember:staticoptSJSIRValOrVar[SJSIRTree]:SJSIRType
  1. If static is true and static is not present, return empty.
  2. If static is false and static is present, return empty.
  3. Let propertyNameRef be the result of evaluating SJSIRTree.
  4. Let propertyName be ? GetValue(propertyNameRef).
  5. Let propertyKey be ? ToPropertyKey(propertyName).
  6. Let zeroValue be SJSIRZeroOf of SJSIRType.
  7. Perform ? CreateDataProperty(obj, propertyKey, zeroValue).
  8. Return NormalCompletion(empty).
SJSIRClassMember:other
  1. Return NormalCompletion(empty).

8.1.28Runtime Semantics: SJSIRCreateJSClassValue

With argument captureValues.

SJSIRClassDef:SJSIRClassCapturesoptSJSIRClassKindSJSIRClassNameSJSIRExtendsClauseoptSJSIRImplementsClauseoptSJSIRNativeLoadSpecopt{SJSIRClassMembers}
  1. Assert: SJSIRClassKind is either js class or module js class.
  2. Assert: SJSIRExtendsClause is present.
  3. Assert: SJSIRNativeLoadSpec is not present.
  4. Let lex be the running execution context's LexicalEnvironment.
  5. Let programEnv be FindSJSIRProgramEnv(lex).
  6. If SJSIRClassCaptures is present, then
    1. Assert: captureValues is not empty.
    2. Let classScope be NewDeclarativeEnvironment(programEnv).
    3. Perform SJSIRBindParams(classScope, captureValues, 0).
  7. Else,
    1. Let classScope be programEnv.
  8. Set the running execution context's LexicalEnvironment to classScope.
  9. Let superclass be the result of evaluating SJSIRExtendsClause.
  10. Set the running execution context's LexicalEnvironment to lex.
  11. ReturnIfAbrupt(superclass).
  12. If superclass is null, then
    1. Let protoParent be null.
    2. Let constructorParent be the intrinsic object %FunctionPrototype%.
  13. Else if IsConstructor(superclass) is false, throw a TypeError exception.
  14. Else,
    1. Let protoParent be ? Get(superclass, "prototype").
    2. If Type(protoParent) is neither Object nor Null, throw a TypeError exception.
    3. Let constructorParent be superclass.
  15. Let proto be ObjectCreate(protoParent).
  16. Let classBody be TranslateJSClassBody of SJSIRClassMembers.
  17. Let constructor be ConstructorMethod of classBody.
  18. Assert: constructor is not empty.
  19. Set the running execution context's LexicalEnvironment to classScope.
  20. Let constructorInfo be the result of performing DefineMethod for constructor with arguments proto and constructorParent as the optional functionPrototype argument.
  21. Assert: constructorInfo is not an abrupt completion.
  22. Let F be constructorInfo.[[Closure]].
  23. Set F.[[ConstructorKind]] to "derived".
  24. Perform MakeConstructor(F, false, proto).
  25. Perform MakeClassConstructor(F).
  26. Perform CreateMethodProperty(proto, "constructor", F).
  27. Let methods be NonConstructorMethodDefinitions of classBody.
  28. For each ClassElement m in order from methods, do
    1. If IsStatic of m is false, then
      1. Let status be the result of performing PropertyDefinitionEvaluation for m with arguments proto and false.
    2. Else,
      1. Let status be the result of performing PropertyDefinitionEvaluation for m with arguments F and false.
    3. If status is an abrupt completion, then
      1. Set the running execution context's LexicalEnvironment to lex.
      2. Return Completion(status).
  29. Set the running execution context's LexicalEnvironment to lex.
  30. Perform ? SJSIRCreateFields of SJSIRClassMembers with arguments F and true.
  31. Return F.
Note

These steps mimic the steps of ClassDefinitionEvaluation for ClassTail.

9SJSIR Statements and Expressions

In the Scala.js IR, statements and expressions are all part of a unique syntactic category of SJSIRTree. The only distinction is that we conventionally call an expression a tree whose result type is not void.

Abstract Syntax

SJSIR trees cannot be written in ECMAScript Language Source Code, so their Syntax is an abstract syntax.

SJSIRTree:SJSIRSeq SJSIRLocalValVar this Identifier Identifier=SJSIRTree mod:SJSIRClassName mod:SJSIRClassName=this skip if[SJSIRType](SJSIRTree)SJSIRTreeelseSJSIRTree while(SJSIRTree){SJSIRTree} do{SJSIRTree}while(SJSIRTree) LabelIdentifier[SJSIRType]:{SJSIRTree} return@LabelIdentifierSJSIRTree for(valIdentifierinSJSIRTree){SJSIRTree} try[SJSIRType]{SJSIRTree}catch(Identifier){SJSIRTree} try{SJSIRTree}finally{SJSIRTree} throwSJSIRTree SJSIRMatch debugger newSJSIRClassName.SJSIRConstructorNameSJSIRArguments SJSIRTree.Identifier SJSIRTree.Identifier=SJSIRTree SJSIRClassName::Identifier SJSIRClassName::Identifier=SJSIRTree SJSIRTree.SJSIRMethodNameSJSIRArguments SJSIRTree.SJSIRClassName::SJSIRMethodNameSJSIRArguments SJSIRClassName::SJSIRMethodNameSJSIRArguments SJSIRTree.SJSIRReflProxyNameSJSIRArguments !SJSIRTree (SJSIRType)SJSIRTree SJSIRTreeSJSIRBinaryOpSJSIRTree newSJSIRType[SJSIRTree] newSJSIRType[]SJSIRArguments SJSIRTree.arr::length SJSIRTree.arr::[SJSIRTree] SJSIRTree.arr::[SJSIRTree]=SJSIRTree SJSIRTree.isInstanceOf[SJSIRType] SJSIRTree.asInstanceOf[SJSIRType] <get-class>(SJSIRTree) <linking-info> newSJSIRTreeSJSIRJSArguments SJSIRJSPropRef SJSIRJSPropRef=SJSIRTree deleteSJSIRJSPropRef SJSIRJSPropRefSJSIRJSArguments SJSIRTreeSJSIRJSArguments superSJSIRJSArguments SJSIRJSUnaryOpSJSIRTree SJSIRTreeSJSIRJSBinaryOpSJSIRTree constructorOf[SJSIRClassName] SJSIRJSArrayConstr SJSIRJSObjectConstr global:Identifier SJSIRLiteral SJSIRClosure createJSClass[SJSIRClassName]SJSIRArguments SJSIRArguments:() (SJSIRArgumentList) SJSIRArgumentList:SJSIRTree SJSIRArgumentList,SJSIRTree SJSIRBinaryOp:one of===!==+[string]==[boolean]!=[boolean]|[boolean]&[boolean]+[int]-[int]*[int]/[int]%[int]|[int]&[int]^[int]<<[int]>>>[int]>>[int]==[int]!=[int]<[int]<=[int]>[int]>=[int]+[long]-[long]*[long]/[long]%[long]|[long]&[long]^[long]<<[long]>>>[long]>>[long]==[long]!=[long]<[long]<=[long]>[long]>=[long]+[float]-[float]*[float]/[float]%[float]+[double]-[double]*[double]/[double]%[double]==[double]!=[double]<[double]<=[double]>[double]>=[double] SJSIRJSArguments:() (SJSIRJSArgumentList) SJSIRJSArgumentList:SJSIRTree ...SJSIRTree SJSIRJSArgumentList,SJSIRTree SJSIRJSArgumentList,...SJSIRTree SJSIRJSPropRef:SJSIRTree[SJSIRTree] super(SJSIRTree)::SJSIRTree[SJSIRTree] SJSIRJSUnaryOp:one of+-~!typeof SJSIRJSBinaryOp:one of===!==+-*/%|&^<<>>>>><<=>>=&&||ininstanceof

9.1Sequence

Abstract Syntax

SJSIRSeq:SJSIRTree;SJSIRTree

9.1.1Runtime Semantics: Evaluation

SJSIRSeq:SJSIRTree;SJSIRTree
  1. Let sl be the result of evaluating the first SJSIRTree.
  2. ReturnIfAbrupt(sl).
  3. Let s2 be the result of evaluating the second SJSIRTree.
  4. Return ? GetValue(s2).

9.2Local variable

Abstract Syntax

SJSIRLocalValVar:valIdentifier:SJSIRType=SJSIRTree;SJSIRTree varIdentifier:SJSIRType=SJSIRTree;SJSIRTree

9.2.1Static Semantics: IsConstantDeclaration

SJSIRLocalValVar:varIdentifier:SJSIRType=SJSIRTree;SJSIRTree
  1. Return true.
SJSIRLocalValVar:valIdentifier:SJSIRType=SJSIRTree;SJSIRTree
  1. Return false.

9.2.2Runtime Semantics: Evaluation

SJSIRLocalValVar:valIdentifier:SJSIRType=SJSIRTree;SJSIRTree varIdentifier:SJSIRType=SJSIRTree;SJSIRTree
  1. Let rhs be the result of evaluating the first SJSIRTree.
  2. Let rhsValue be ? GetValue(rhs).
  3. Assert: SJSIRIsValueOfType(rhsValue, SJSIRType) is true.
  4. Let oldEnv be the running execution context's LexicalEnvironment.
  5. Let innerEnv be NewDeclarativeEnvironment(oldEnv).
  6. Let innerEnvRec be innerEnv's EnvironmentRecord.
  7. Let dn be the StringValue of Identifier.
  8. If IsConstantDeclaration of SJSIRLocalValVar is true, then
    1. Perform ! envRec.CreateImmutableBinding(dn, true).
  9. Else,
    1. Perform ! envRec.CreateMutableBinding(dn, false).
  10. Perform ! envRec.InitializeBinding(dn, rhsValue).
  11. Set the running execution context's LexicalEnvironment to innerEnv.
  12. Let result be the result of evaluating the second SJSIRTree.
  13. Set the running execution context's LexicalEnvironment to oldEnv.
  14. Return result.
Note

No matter how control leaves the SJSIRLocalValVar the LexicalEnvironment is always restored to its former state.

9.3The this Keyword

9.3.1Runtime Semantics: Evaluation

SJSIRTree:this
  1. Let binding be ! ResolveThisBinding().
  2. Return ! GetValue(binding).

9.4Identifier Reference

9.4.1Runtime Semantics: Evaluation

SJSIRTree:Identifier
  1. Let binding be ! ResolveBinding(StringValue of Identifier).
  2. Return ! GetValue(binding).

9.5Assign Var

9.5.1Runtime Semantics: Evaluation

SJSIRTree:Identifier=SJSIRTree
  1. Let rhs be the result of evaluating SJSIRTree.
  2. Let rhsValue be ? GetValue(rhs).
  3. Let vn be the StringValue of Identifier.
  4. Let lhs be ! ResolveBinding(vn).
  5. Perform ! PutValue(lhs, _rhsValue).
  6. Return NormalCompletion(empty).

9.6Load Module

9.6.1Runtime Semantics: Evaluation

SJSIRTree:mod:SJSIRClassName
  1. Let className be the StringValue of SJSIRClassName.
  2. Let class be ResolveSJSIRClass(className).
  3. Return ? SJSIRLoadModule(class).

9.7Store Module

9.7.1Runtime Semantics: Evaluation

SJSIRTree:mod:SJSIRClassName=this
  1. Let rhs be ! ResolveThisBinding().
  2. Let className be the StringValue of SJSIRClassName.
  3. Let class be ResolveSJSIRClass(className).
  4. Set class.[[ModuleInstance]] to rhs.
  5. Return NormalCompletion(empty).

9.8Skip

Note

The skip statement does nothing. It can be used in places where a statement is expected but we do not want to perform any action, for example in the else branch of an if statement.

9.8.1Runtime Semantics: Evaluation

SJSIRTree:skip
  1. Return NormalCompletion(empty).

9.9Conditional

9.9.1Runtime Semantics: Evaluation

SJSIRTree:if[SJSIRType](SJSIRTree)SJSIRTreeelseSJSIRTree
  1. Let lref be the result of evaluating the first SJSIRTree.
  2. Let lval be ? GetValue(lref).
  3. Assert: Type(lval) is Boolean.
  4. If lval is true, then
    1. Let trueRef be the result of evaluating the second SJSIRTree.
    2. Return trueRef.
  5. Else,
    1. Let falseRef be the result of evaluating the third SJSIRTree.
    2. Return ? falseRef.

9.10While Loop

9.10.1Runtime Semantics: Evaluation

SJSIRTree:while(SJSIRTree){SJSIRTree}
  1. Repeat,
    1. Let condRef be the result of evaluating the first SJSIRTree.
    2. Let condValue be ? GetValue(condRef).
    3. Assert: Type(condValue) is Boolean.
    4. If condValue is false, return NormalCompletion(empty).
    5. Let stmtResult be the result of evaluating the second SJSIRTree.
    6. ReturnIfAbrupt(stmtResult).

9.11Do-While Loop

9.11.1Runtime Semantics: Evaluation

SJSIRTree:do{SJSIRTree}while(SJSIRTree)
  1. Repeat,
    1. Let stmtResult be the result of evaluating the first SJSIRTree.
    2. ReturnIfAbrupt(stmtResult).
    3. Let condRef be the result of evaluating the second SJSIRTree.
    4. Let condValue be ? GetValue(condRef).
    5. Assert: Type(condValue) is Boolean.
    6. If condValue is false, return NormalCompletion(empty).

9.12Labeled Block

9.12.1Runtime Semantics: Evaluation

SJSIRTree:LabelIdentifier[SJSIRType]:{SJSIRTree}
  1. Let label be the StringValue of LabelIdentifier.
  2. Let stmtResult be the result of evaluating the SJSIRTree.
  3. If stmtResult.[[Type]] is break and SameValue(stmtResult.[[Target]], label) is true, then
    1. Set stmtResult to NormalCompletion(stmtResult.[[Value]]).
  4. Return Completion(stmtResult).
Note

If the declared type of the Labeled Block is void, then the Value of the break completion record is always discarded.

9.13Return from Labeled Block

9.13.1Runtime Semantics: Evaluation

SJSIRTree:return@LabelIdentifierSJSIRTree
  1. Let label be the StringValue of LabelIdentifier.
  2. Let result be the result of evaluating the SJSIRTree.
  3. Let resultValue be ? GetValue(result).
  4. Return Completion{[[Type]]: break, [[Value]]: resultValue, [[Target]]: label }.
Note

The return keyword of SJSIR is a halfbreed between ECMAScript's return and break: it breaks to a labeled block, but with a result value.

9.14For-In Loop

9.14.1Runtime Semantics: Evaluation

SJSIRTree:for(valIdentifierinSJSIRTree){SJSIRTree}
  1. Let lhs be a new Parse Node of type ForDeclaration whose LetOrConst is const and whose ForBinding is Identifier.
  2. Let key be ForIn/OfHeadEvaluation(« », the first SJSIRTree, enumerate).
  3. If key.[[Type]] is break and key.[[Target]] is empty, then
    1. Return NormalCompletion(empty).
  4. Let keyResult be ? key.
  5. Return ? ForIn/OfBodyEvaluation(lhs, the second SJSIRTree, keyResult, enumerate, lexicalBinding, « »).

9.15Try-Catch

9.15.1Runtime Semantics: Evaluation

SJSIRTree:try[SJSIRType]{SJSIRTree}catch(Identifier){SJSIRTree}
  1. Let B be the result of evaluating the first SJSIRTree.
  2. If B.[[Type]] is not throw, then
    1. Return Completion(UpdateEmpty(B, undefined)).
  3. Let thrownValue be B.[[Value]].
  4. Let oldEnv be the running execution context's LexicalEnvironment.
  5. Let catchEnv be NewDeclarativeEnvironment(oldEnv).
  6. Let catchEnvRec be catchEnv's EnvironmentRecord.
  7. Let argName be the StringValue of Identifier.
  8. Perform ! catchEnvRec.CreateImutableBinding(argName, true).
  9. Perform ! catchEnvRec.InitializeBinding(argName, thrownValue).
  10. Set the running execution context's LexicalEnvironment to catchEnv.
  11. Let C be the result of evaluating the second SJSIRTree.
  12. Set the running execution context's LexicalEnvironment to oldEnv.
  13. Return Completion(UpdateEmpty(C, undefined)).

9.16Try-Finally

9.16.1Runtime Semantics: Evaluation

SJSIRTree:try{SJSIRTree}finally{SJSIRTree}
  1. Let B be the result of evaluating the first SJSIRTree.
  2. Let F be the result of evaluating the second SJSIRTree.
  3. If F.[[Type]] is normal, set F to B.
  4. Return Completion(UpdateEmpty(F, undefined)).

9.17Throw

9.17.1Runtime Semantics: Evaluation

SJSIRTree:throwSJSIRTree
  1. Let exprRef be the result of evaluating SJSIRTree.
  2. Let exprValue be ? GetValue(exprRef).
  3. Return Completion{[[Type]]: throw, [[Value]]: exprValue, [[Target]]: empty}.

9.18Match

Abstract Syntax

SJSIRMatch:match[SJSIRType](SJSIRTree){SJSIRMatchClausesSJSIRMatchDefaultClause} SJSIRMatchClauses:[empty] SJSIRMatchClausesSJSIRMatchClause SJSIRMatchClause:caseSJSIRMatchAlternatives=>SJSIRTree SJSIRMatchAlternatives:NumericLiteral SJSIRMatchAlternatives|NumericLiteral SJSIRMatchDefaultClause:case_=>SJSIRTree

9.18.1Static Semantics : AlternativeSet

SJSIRMatchAlternatives:NumericLiteral
  1. Let altSet be a new empty Set.
  2. Let altValue be the number whose value is MV of NumericLiteral as defined in 11.8.3.
  3. Append altValue to altSet.
  4. Return altSet.
SJSIRMatchAlternatives:SJSIRMatchAlternatives|NumericLiteral
  1. Let altSet be the AlternativeSet of SJSIRMatchAlternatives.
  2. Let altValue be the number whose value is MV of NumericLiteral as defined in 11.8.3.
  3. Append altValue to altSet.
  4. Return altSet.

9.18.2Static Semantics : MatchClauses

SJSIRMatchClauses:[empty]
  1. Return a new empty List.
SJSIRMatchClauses:SJSIRMatchClausesSJSIRMatchClause
  1. Let clauseList be the MatchClauses of SJSIRMatchClauses.
  2. Append the MatchClauses of SJSIRMatchClause to clauseList.
  3. Return clauseList.
SJSIRMatchClause:caseSJSIRMatchAlternatives=>SJSIRTree
  1. Let altSet be the AlternativeSet of SJSIRMatchAlternatives.
  2. Let body be the Parse Node SJSIRTree.
  3. Return « {[[AltSet]]:altSet, [[Body]]:body} ».

9.18.3Runtime Semantics : Evaluation

SJSIRMatch:match[SJSIRType](SJSIRTree){SJSIRMatchClausesSJSIRMatchDefaultClause}
  1. Let expr be the result of evaluating SJSIRTree.
  2. Let exprValue be ? GetValue(expr).
  3. Assert: SJSIRIsValueOfType(exprValue, int) is true.
  4. Let clauseList be the MatchClauses of SJSIRMatchClauses.
  5. For each element clause of clauseList, do
    1. If clause.[[AltSet]] contains exprValue, then
      1. Let result be the result of evaluating clause.[[Body]].
      2. Return result.
  6. Let result be the result of evaluating the SJSIRTree of SJSIRMatchDefaultClause.
  7. Return result.

9.19The debugger Statement

9.19.1Runtime Semantics: Evaluation

Note

Evaluating a debugger statement may allow an implementation to cause a breakpoint when run under a debugger. If a debugger is not present or active this statement has no observable effect.

SJSIRTree:debugger
  1. If an implementation-defined debugging facility is available and enabled, then
    1. Perform an implementation-defined debugging action.
    2. Let result be an implementation-defined Completion value.
  2. Else,
    1. Let result be NormalCompletion(empty).
  3. Return result.

9.20Scala object instantiation

9.20.1Runtime Semantics: Evaluation

SJSIRTree:newSJSIRClassName.SJSIRConstructorNameSJSIRArguments
  1. Let className be the StringValue of SJSIRClassName.
  2. Let class be ResolveSJSIRClass(className).
  3. Let ctorName be the StringValue of SJSIRConstructorName.
  4. Let argList be ArgumentListEvaluation of SJSIRArguments.
  5. ReturnIfAbrupt(argList).
  6. Let obj be ! SJSIRScalaObjectAllocate(class).
  7. Let classDef be class.[[ClassDef]].
  8. Let static be false.
  9. Let ctorDef be the result of SJSIRGetMethodInClass of classDef with parameters ctorName and static.
  10. Assert: ctorDef is a SJSIRClassMember with the production def SJSIRCtorName SJSIRMethodSignature = SJSIRTree.
  11. Perform ? SJSIREvaluateMethod of ctorDef with parameters obj and argList.
  12. Return obj.

9.21Scala field get

9.21.1Runtime Semantics: Evaluation

SJSIRTree:SJSIRTree.Identifier
  1. Let objRef be the result of evaluating SJSIRTree.
  2. Let obj be ? GetValue(objRef).
  3. If obj is the null value, then
    1. Trigger an SJSIR Undefined Behavior.
  4. Assert: obj has an [[SJSIRClass]] internal slot.
  5. Let fieldName be the StringValue of Identifier.
  6. Assert: obj has an own data property with key fieldName.
  7. Let X be obj's own property whose key is fieldName.
  8. Assert: X has a [[Value]] internal slot.
  9. Return X.[[Value]].
Note

This algorithm by-passes the [[Get]] internal method of obj, which would otherwise trigger an undefined behavior.

9.22Scala field set

9.22.1Runtime Semantics: Evaluation

SJSIRTree:SJSIRTree.Identifier=SJSIRTree
  1. Let objRef be the result of evaluating the first SJSIRTree.
  2. Let obj be ? GetValue(objRef).
  3. If obj is the null value, then
    1. Trigger an SJSIR Undefined Behavior.
  4. Assert: obj has an [[SJSIRClass]] internal slot.
  5. Let fieldName be the StringValue of Identifier.
  6. Assert: obj has an own data property with key fieldName.
  7. Let X be obj's own property whose key is fieldName.
  8. Assert: X has a [[Value]] internal slot.
  9. Let rhsRef be the result of evaluating the second SJSIRTree.
  10. Set X.[[Value]] to ? GetValue(rhsRef).
  11. Return NormalCompletion(empty).
Note

This algorithm by-passes the [[Set]] internal method of obj, which would otherwise trigger an undefined behavior.

9.23Scala static field get

9.23.1Runtime Semantics: Evaluation

SJSIRTree:SJSIRClassName::Identifier
  1. Let className be the StringValue of SJSIRClassName.
  2. Let class be ResolveSJSIRClass(className).
  3. Let staticFields be class.[[StaticFields]].
  4. Let fieldName be the StringValue of Identifier.
  5. Return ! staticFields.[[Get]](fieldName, staticFields).

9.24Scala static field set

9.24.1Runtime Semantics: Evaluation

SJSIRTree:SJSIRClassName::Identifier=SJSIRTree
  1. Let className be the StringValue of SJSIRClassName.
  2. Let class be ResolveSJSIRClass(className).
  3. Let staticFields be class.[[StaticFields]].
  4. Let fieldName be the StringValue of Identifier.
  5. Let rhsRef be the result of evaluating the second SJSIRTree.
  6. Let rhs be ? GetValue(rhsRef).
  7. Perform ! staticFields.[[Set]](fieldName, rhs, staticFields).
  8. Let classDef be class.[[ClassDef]].
  9. Perform ! SJSIRUpdateStaticFieldExport of classDef with arguments fieldName and rhs.
  10. Return NormalCompletion(empty).

9.25Scala method apply

9.25.1SJSIRRepresentativeClass ( V )

When the SJSIRRepresentativeClass abstract operation is called with an ECMAScript Language Value V, the following steps are taken:

  1. If V has an [[SJSIRClass]] internal slot, then
    1. Return V.[[SJSIRClass]].
  2. If Type(V) is Boolean, then
    1. Return ResolveSJSIRClass("java.lang.Boolean").
  3. If V has an [[SJSIRCharValue]] internal slot, then
    1. Return ResolveSJSIRClass("java.lang.Character").
  4. If Type(V) is Number, then
    1. Return ResolveSJSIRClass("java.lang.Double").
    2. NOTE: "java.lang.Double" is used for all non-long numeric values.
  5. If V has an [[SJSIRLongValue]] internal slot, then
    1. Return ResolveSJSIRClass("java.lang.Long").
  6. If Type(V) is String, then
    1. Return ResolveSJSIRClass("java.lang.String").
  7. If Type(V) is Undefined, then
    1. Return ResolveSJSIRClass("scala.runtime.BoxedUnit").
  8. Return ResolveSJSIRClass("java.lang.Object").

9.25.2Runtime Semantics: Evaluation

SJSIRTree:SJSIRTree.SJSIRMethodNameSJSIRArguments
  1. Let objRef be the result of evaluating SJSIRTree.
  2. Let obj be ? GetValue(objRef).
  3. If obj is the null value, then
    1. Trigger an SJSIR Undefined Behavior.
  4. Let class be SJSIRRepresentativeClass(obj).
  5. Let methodName be the StringValue of SJSIRMethodName.
  6. Let argList be ArgumentListEvaluation of SJSIRArguments.
  7. ReturnIfAbrupt(argList).
  8. If SameValue(methodName, "toString__T") is true and obj does not have an [[SJSIRClass]] internal slot, then
    1. Return ? ToString(obj).
  9. If class.[[IsArray]] is true and SameValue(methodName, "clone__O") is true, then
    1. Assert: argList is empty.
    2. Return SJSIRArrayClone(obj).
  10. Let methodDef be SJSIRResolveMethod(class, methodName).
  11. Assert: methodDef is a SJSIRClassMember with the production def SJSIRMethodName SJSIRMethodSignature = SJSIRTree.
  12. Return the result of evaluating SJSIREvaluateMethod of methodDef with parameters obj and argList.

9.26Scala method apply statically

9.26.1Runtime Semantics: Evaluation

SJSIRTree:SJSIRTree.SJSIRClassName::SJSIRMethodNameSJSIRArguments
  1. Let objRef be the result of evaluating SJSIRTree.
  2. Let obj be ? GetValue(objRef).
  3. If obj is the null value, then
    1. Trigger an SJSIR Undefined Behavior.
  4. Let className be the StringValue of SJSIRClassName.
  5. Let class be ResolveSJSIRClass(className).
  6. Assert: SJSIRIsValueOfClass(obj, class) is true.
  7. Let methodName be the StringValue of SJSIRMethodName.
  8. Let argList be ArgumentListEvaluation of SJSIRArguments.
  9. ReturnIfAbrupt(argList).
  10. Let methodDef be SJSIRResolveMethod(class, methodName).
  11. Assert: methodDef is a SJSIRClassMember with the production def SJSIRMethodName SJSIRMethodSignature = SJSIRTree.
  12. Return the result of evaluating SJSIREvaluateMethod of methodDef with parameters obj and argList.

9.27Scala method apply static

9.27.1Runtime Semantics: Evaluation

SJSIRTree:SJSIRClassName::SJSIRMethodNameSJSIRArguments
  1. Let className be the StringValue of SJSIRClassName.
  2. Let class be ResolveSJSIRClass(className).
  3. Let methodName be the StringValue of SJSIRMethodName.
  4. Let argList be ArgumentListEvaluation of SJSIRArguments.
  5. ReturnIfAbrupt(argList).
  6. Let classDef be class.[[ClassDef]].
  7. Let static be true.
  8. Let methodDef be the result of SJSIRGetMethodInClass of classDef with parameters methodName and static.
  9. Assert: methodDef is a SJSIRClassMember with the production static def SJSIRMethodName SJSIRMethodSignature = SJSIRTree.
  10. Return the result of evaluating SJSIREvaluateMethod of methodDef with parameters empty and argList.

9.28Scala method reflective apply

9.28.1Runtime Semantics: Evaluation

SJSIRTree:SJSIRTree.SJSIRReflProxyNameSJSIRArguments
  1. Let objRef be the result of evaluating SJSIRTree.
  2. Let obj be ? GetValue(objRef).
  3. If obj is the null value, then
    1. Trigger an SJSIR Undefined Behavior.
  4. Let class be SJSIRRepresentativeClass(obj).
  5. Let methodName be the StringValue of SJSIRReflProxyName.
  6. Let argList be ArgumentListEvaluation of SJSIRArguments.
  7. ReturnIfAbrupt(argList).
  8. If class.[[IsArray]] is true and SameValue(methodName, "clone__") is true, then
    1. Assert: argList is empty.
    2. Return SJSIRArrayClone(obj).
  9. Let methodDef be SJSIRResolveReflectiveMethod(class, methodName).
  10. If methodDef is empty, then
    1. Throw a TypeError exception.
  11. Assert: methodDef is a SJSIRClassMember with the production def SJSIRMethodName SJSIRMethodSignature = SJSIRTree.
  12. Let result the result of evaluating SJSIREvaluateMethod of methodDef with parameters obj and argList.
  13. Return UpdateEmpty(result, undefined).

9.29Boolean Not

9.29.1Runtime Semantics: Evaluation

SJSIRTree:!SJSIRTree
  1. Let ref be the result of evaluating SJSIRTree.
  2. Let val be ? GetValue(ref).
  3. Assert: Type(val) is Boolean.
  4. If val is true, then
    1. Return false.
  5. Else,
    1. Return true.

9.30Primitive conversion

9.30.1Runtime Semantics: Evaluation

SJSIRTree:(char)SJSIRTree
  1. Let ref be the result of evaluating SJSIRTree.
  2. Let val be ? GetValue(ref).
  3. Assert: SJSIRIsValueOfType(val, int) is true.
  4. Let charValue be ToUint16(val).
  5. Return CreateSJSIRCharObject(charValue).
SJSIRTree:(byte)SJSIRTree
  1. Let ref be the result of evaluating SJSIRTree.
  2. Let val be ? GetValue(ref).
  3. Assert: SJSIRIsValueOfType(val, int) is true.
  4. Return ToInt8(val).
SJSIRTree:(short)SJSIRTree
  1. Let ref be the result of evaluating SJSIRTree.
  2. Let val be ? GetValue(ref).
  3. Assert: SJSIRIsValueOfType(val, int) is true.
  4. Return ToInt16(val).
SJSIRTree:(int)SJSIRTree
  1. Let ref be the result of evaluating SJSIRTree.
  2. Let val be ? GetValue(ref).
  3. If val has an [[SJSIRCharValue]] internal slot, then
    1. Return val.[[SJSIRCharValue]].
  4. If val has an [[SJSIRLongValue]] internal slot, then
    1. Let longValue be val.[[SJSIRLongValue]].
    2. Let int32bit be longValue modulo 232.
    3. If int32bit ≥ 231, return int32bit - 232; otherwise return int32bit.
  5. Assert: Type(val) is Number.
  6. Return ToInt32(val).
SJSIRTree:(long)SJSIRTree
  1. Let ref be the result of evaluating SJSIRTree.
  2. Let val be ? GetValue(ref).
  3. Assert: Type(val) is Number.
  4. Let longValue be ToInt64(val).
  5. Return CreateSJSIRLongObject(longValue).
SJSIRTree:(float)SJSIRTree
  1. Let ref be the result of evaluating SJSIRTree.
  2. Let val be ? GetValue(ref).
  3. Assert: Type(val) is Number.
  4. Return ToFloat32(val).
SJSIRTree:(double)SJSIRTree
  1. Let ref be the result of evaluating SJSIRTree.
  2. Let val be ? GetValue(ref).
  3. If val has an [[SJSIRLongValue]] internal slot, then
    1. Let longValue be val.[[SJSIRLongValue]].
    2. If longValue = 0, then
      1. Return +0.
    3. Else,
      1. Return the Number value of longValue.
  4. Assert: Type(val) is Number.
  5. Return val.

9.31Binary operator

9.31.1Runtime Semantics: SJSIRBinaryOpEvaluation

With arguments lval and rval.

SJSIRBinaryOp:===
  1. Return the result of performing Strict Equality Comparison rval === lval.
SJSIRBinaryOp:!==
  1. Let r be the result of performing Strict Equality Comparison rval === lval.
  2. If r is true, return false. Otherwise, return true.
SJSIRBinaryOp:+[string]
  1. Let lprim be ? ToPrimitive(lval).
  2. Let rprim be ? ToPrimitive(rval).
  3. Let lstr be ? ToString(lprim).
  4. Let rstr be ? ToString(rprim).
  5. Return the string-concatenation of lstr and rstr.
Note

The algorithm performs ToPrimitive followed by ToString to match the exact behavior of ECMAScript's primitive + in the case where at least one of the operands' ToPrimitive returns a String. For all practical purposes with well-behaved values, this should be equivalent to directly calling ToString.

SJSIRBinaryOp:==[boolean]
  1. Assert: SJSIRIsValueOfType(lval, boolean) is true.
  2. Assert: SJSIRIsValueOfType(rval, boolean) is true.
  3. Return the result of performing Strict Equality Comparison rval === lval.
SJSIRBinaryOp:!=[boolean]
  1. Assert: SJSIRIsValueOfType(lval, boolean) is true.
  2. Assert: SJSIRIsValueOfType(rval, boolean) is true.
  3. Let r be the result of performing Strict Equality Comparison rval === lval.
  4. If r is true, return false. Otherwise, return true.
SJSIRBinaryOp:|[boolean]
  1. Assert: SJSIRIsValueOfType(lval, boolean) is true.
  2. Assert: SJSIRIsValueOfType(rval, boolean) is true.
  3. If lval is true or rval is true, return true; else return false.
SJSIRBinaryOp:&[boolean]
  1. Assert: SJSIRIsValueOfType(lval, boolean) is true.
  2. Assert: SJSIRIsValueOfType(rval, boolean) is true.
  3. If lval is true and rval is true, return true; else return false.
SJSIRBinaryOp:+[int]
  1. Assert: SJSIRIsValueOfType(lval, int) is true.
  2. Assert: SJSIRIsValueOfType(rval, int) is true.
  3. Return ! ToInt32(lval + rval).
SJSIRBinaryOp:etc. SJSIRBinaryOp:+[long]
  1. Assert: SJSIRIsValueOfType(lval, long) is true.
  2. Assert: SJSIRIsValueOfType(rval, long) is true.
  3. Let r be lval.[[SJSIRLongValue]] + rval.[[SJSIRLongValue]].
  4. Let r64 be ! ToInt64(r).
  5. Return CreateSJSIRLongObject(r64).
SJSIRBinaryOp:etc.

9.31.2Runtime Semantics: Evaluation

SJSIRTree:SJSIRTreeSJSIRBinaryOpSJSIRTree
  1. Let lref be the result of evaluating the first SJSIRTree.
  2. Let lval be ? GetValue(lref).
  3. Let rref be the result of evaluating the second SJSIRTree.
  4. Let rval be ? GetValue(rref).
  5. Return ? SJSIRBinaryOpEvaluation of SJSIRBinaryOp with arguments lval and rval.

9.32New Scala array

9.32.1Runtime Semantics: Evaluation

SJSIRTree:newSJSIRType[SJSIRArgumentList]
  1. Let lengths be the result of ArgumentListEvaluation of SJSIRArgumentList.
  2. Assert: lengths is not empty.
  3. Assert: for all elements len of lengths, SJSIRIsValueOfType(len, int) is true.
  4. Let componentClass be the result of SJSIRTypeToClass of SJSIRType.
  5. Return ? CreateMultiSJSIRArrayObject(componentClass, lengths).

9.33New Scala array value

9.33.1Runtime Semantics: Evaluation

SJSIRTree:newSJSIRType[]SJSIRArguments
  1. Let componentClass be the result of SJSIRTypeToClass of SJSIRType.
  2. Let argList be the result of evaluating ArgumentListEvaluation of SJSIRArguments.
  3. Let len be the length of argList.
  4. Let array be ? CreateSJSIRArrayObject(componentClass, len).
  5. Let arrayElements be array.[[SJSIRArrayElements]].
  6. Let index be 0.
  7. For each arg in argList, do
    1. Assert: SJSIRIsValueOfType(arg, SJSIRType) is true.
    2. Set arrayElements[index] to arg.
    3. Set index to index + 1.
  8. Return array.

9.34Scala array element length

9.34.1Runtime Semantics: Evaluation

SJSIRTree:SJSIRTree.arr::length
  1. Let objRef be the result of evaluating SJSIRTree.
  2. Let obj be ? GetValue(objRef).
  3. If obj is the null value, then
    1. Trigger an SJSIR Undefined Behavior.
  4. Assert: obj has an [[SJSIRArrayElements]] internal slot.
  5. Let elements be obj.[[SJSIRArrayElements]].
  6. Return the length of elements.

9.35Scala array element get

9.35.1Runtime Semantics: Evaluation

SJSIRTree:SJSIRTree.arr::[SJSIRTree]
  1. Let objRef be the result of evaluating the first SJSIRTree.
  2. Let obj be ? GetValue(objRef).
  3. If obj is the null value, then
    1. Trigger an SJSIR Undefined Behavior.
  4. Assert: obj has an [[SJSIRArrayElements]] internal slot.
  5. Let elements be obj.[[SJSIRArrayElements]].
  6. Let indexRef be the result of evaluating the second SJSIRTree.
  7. Let index be ? GetValue(indexRef).
  8. Assert: SJSIRIsValueOfType(index, int) is true.
  9. If index < 0 or index >= the length of elements, then
    1. Trigger an SJSIR Undefined Behavior.
  10. Return elements[index].

9.36Scala array element set

9.36.1Runtime Semantics: Evaluation

SJSIRTree:SJSIRTree.arr::[SJSIRTree]=SJSIRTree
  1. Let objRef be the result of evaluating the first SJSIRTree.
  2. Let obj be ? GetValue(objRef).
  3. If obj is the null value, then
    1. Trigger an SJSIR Undefined Behavior.
  4. Assert: obj has an [[SJSIRArrayElements]] internal slot.
  5. Let elements be obj.[[SJSIRArrayElements]].
  6. Let indexRef be the result of evaluating the second SJSIRTree.
  7. Let index be ? GetValue(indexRef).
  8. Assert: SJSIRIsValueOfType(index, int) is true.
  9. Let rhsRef be the result of evaluating the third SJSIRTree.
  10. Let rhs be ? GetValue(rhsRef).
  11. If index < 0 or index >= the length of elements, then
    1. Trigger an SJSIR Undefined Behavior.
  12. If rhs is not a valid value for the type of elements of obj, then
    1. Trigger an SJSIR Undefined Behavior.
  13. Set elements[index] to rhs.
  14. Return NormalCompletion(empty).

9.37Instance test

9.37.1Runtime Semantics: Evaluation

SJSIRTree:SJSIRTree.isInstanceOf[SJSIRType]
  1. Let objRef be the result of evaluating the first SJSIRTree.
  2. Let obj be ? GetValue(objRef).
  3. Return the result of SJSIRTypeHasNonNullValue of SJSIRType with argument obj.

9.38Downcast

9.38.1Runtime Semantics: Evaluation

SJSIRTree:SJSIRTree.asInstanceOf[SJSIRType]
  1. Let objRef be the result of evaluating the first SJSIRTree.
  2. Let obj be ? GetValue(objRef).
  3. If obj is null, then
    1. Return the result of SJSIRZeroOf of SJSIRType.
  4. Let isInstance be the result of SJSIRTypeHasValue of SJSIRType with argument obj.
  5. If isInstance is true, then
    1. Return obj.
  6. Trigger an SJSIR Undefined Behavior.

9.39Get class

9.39.1Runtime Semantics: Evaluation

SJSIRTree:<get-class>(SJSIRTree)
  1. Let objRef be the result of evaluating the first SJSIRTree.
  2. Let obj be ? GetValue(objRef).
  3. If obj is null, then
    1. Trigger an Undefined Behavior.
  4. If obj has an [[SJSIRClass]] internal slot, then
    1. Return ? SJSIRClassOf(obj.[[SJSIRClass]]).
  5. If SJSIRIsValueOfType(obj, boolean) is true, then
    1. Return ? SJSIRClassOf(ResolveSJSIRClass("java.lang.Boolean")).
  6. If SJSIRIsValueOfType(obj, char) is true, then
    1. Return ? SJSIRClassOf(ResolveSJSIRClass("java.lang.Character")).
  7. If SJSIRIsValueOfType(obj, byte) is true, then
    1. Return ? SJSIRClassOf(ResolveSJSIRClass("java.lang.Byte")).
  8. If SJSIRIsValueOfType(obj, short) is true, then
    1. Return ? SJSIRClassOf(ResolveSJSIRClass("java.lang.Short")).
  9. If SJSIRIsValueOfType(obj, int) is true, then
    1. Return ? SJSIRClassOf(ResolveSJSIRClass("java.lang.Integer")).
  10. If SJSIRIsValueOfType(obj, float) is true, then
    1. Return ? SJSIRClassOf(ResolveSJSIRClass("java.lang.Float")).
  11. If SJSIRIsValueOfType(obj, double) is true, then
    1. Return ? SJSIRClassOf(ResolveSJSIRClass("java.lang.Double")).
  12. If SJSIRIsValueOfType(obj, long) is true, then
    1. Return ? SJSIRClassOf(ResolveSJSIRClass("java.lang.Long")).
  13. If SJSIRIsValueOfType(obj, string) is true, then
    1. Return ? SJSIRClassOf(ResolveSJSIRClass("java.lang.String")).
  14. If SJSIRIsValueOfType(obj, undef) is true, then
    1. Return ? SJSIRClassOf(ResolveSJSIRClass("scala.runtime.BoxedUnit")).
  15. Return null.

9.40Get linking info

9.40.1Runtime Semantics: Evaluation

SJSIRTree:<linking-info>
  1. Return ! ResolveSJSIRLinkingInfo().

9.41JS new

9.41.1Runtime Semantics: Evaluation

SJSIRTree:newSJSIRTreeSJSIRJSArguments
  1. Let ctorRef be the result of evaluating SJSIRTree.
  2. Let ctor be ? GetValue(ctorRef).
  3. Let argList be ArgumentListEvaluation of SJSIRJSArguments.
  4. ReturnIfAbrupt(argList).
  5. If IsConstructor(ctor) is false, throw a TypeError exception.
  6. Return ? Construct(ctor, argList).
Note

This algorithm mimics that of ECMAScript's new operator.

9.42JS property get

9.42.1Runtime Semantics: Evaluation

SJSIRTree:SJSIRJSPropRef
  1. Let ref be the result of evaluating SJSIRJSPropRef.
  2. Return ? GetValue(ref).

9.43JS property set

9.43.1Runtime Semantics: Evaluation

SJSIRTree:SJSIRJSPropRef=SJSIRTree
  1. Let lref be the result of evaluating SJSIRJSPropRef.
  2. ReturnIfAbrupt(lref).
  3. Let rref be the result of evaluating SJSIRTree.
  4. Let rval be ? GetValue(rref).
  5. Perform ? PutValue(lref, rval).
  6. Return NormalCompletion(empty).

9.44JS property deletion

9.44.1Runtime Semantics: Evaluation

SJSIRTree:deleteSJSIRJSPropRef
  1. Let ref be the result of evaluating SJSIRJSPropRef.
  2. ReturnIfAbrupt(ref).
  3. Assert: IsPropertyReference(ref) is true.
  4. Assert: IsSuperReference(ref) is false.
  5. Assert: IsStrictReference(ref) is true.
  6. Let baseObj be ! ToObject(GetBase(ref)).
  7. Let deleteStatus be ? baseObj.[[Delete]](GetReferencedName(ref)).
  8. If deleteStatus is false, throw a TypeError exception.
  9. Return NormalCompletion(empty).
Note

This algorithm mimics that of ECMAScript's delete operator for strict non-super property references.

9.45JS method call

9.45.1Runtime Semantics: Evaluation

SJSIRTree:SJSIRJSPropRefSJSIRJSArguments
  1. Let ref be the result of evaluating SJSIRJSPropRef.
  2. Let func be ? GetValue(ref).
  3. Let arguments be SJSIRJSArguments.
  4. Let tailCall be false.
  5. NOTE: Implementations are allowed to use true for tailCall in "appropriate" situations. TODO: properly specify this.
  6. Return ? EvaluateCall(func, ref, arguments, tailCall).
Note

This algorithm mimics that of ECMAScript's function calls where the MemberExpression evaluates to a Property Reference.

9.46JS function call

9.46.1Runtime Semantics: Evaluation

SJSIRTree:SJSIRTreeSJSIRJSArguments
  1. Let ref be the result of evaluating SJSIRTree.
  2. Let func be ? GetValue(ref).
  3. Let arguments be SJSIRJSArguments.
  4. Let tailCall be false.
  5. NOTE: Implementations are allowed to use true for tailCall in "appropriate" situations. TODO: properly specify this.
  6. Return ? EvaluateCall(func, func, arguments, tailCall).
Note

This algorithm mimics that of ECMAScript's function calls where the MemberExpression does not evaluate to a Property Reference. Even in cases where it would, we force the non-reference semantics by passing func for the ref parameter instead of ref. This ensures that the this value will not be bound to the base value of ref, if any.

9.47JS super constructor call

9.47.1Runtime Semantics: Evaluation

SJSIRTree:superSJSIRJSArguments
  1. Let newTarget be GetNewTarget().
  2. Assert: Type(newTarget) is Object.
  3. Let func be ? GetSuperConstructor().
  4. Let arguments be SJSIRJSArguments.
  5. ReturnIfAbrupt(arguments).
  6. Let result be ? Construct(func, arguments, newTarget).
  7. Let thisER be GetThisEnvironment().
  8. Perform ? thisER.BindThisValue(result).
  9. Let classDef be the enclosing SJSIRClassDef.
  10. Perform ? SJSIRCreateFields of classDef with arguments result and false.
  11. Return NormalCompletion(empty).
Note

This algorithm mimics that of ECMAScript's super call. In addition, after the call to the super constructor has returned and this has been bound to result, it creates the non-static fields of the enclosing class as data properties of result.

9.48JS unary operator

9.48.1Runtime Semantics: Evaluation

SJSIRTree:SJSIRJSUnaryOpSJSIRTree
  1. Let unaryExpression be an instance of UnaryExpression with child nodes SJSIRJSUnaryOp and SJSIRTree.
  2. Let result be the result of evaluating unaryExpression.
  3. Return ? GetValue(result).
Note

This algorithm delegates to the evaluation of UnaryExpression in all cases. In particular, if SJSIRJSUnaryOp is typeof and SJSIRTree evaluates to an Unresolvable Reference, this operation will return "undefined" rather than throwing a ReferenceError exception.

9.49JS binary operator

9.49.1Runtime Semantics: Evaluation

SJSIRTree:SJSIRTreeSJSIRJSBinaryOpSJSIRTree
  1. Let binaryExpression be an instance of LogicalORExpression with as child nodes the first SJSIRTree, the SJSIRJSUnaryOp and the second SJSIRTree, using the appropriate child non-terminals.
  2. Let result be the result of evaluating binaryExpression.
  3. Return ? GetValue(result).
Note

This algorithm delegates to the evaluation of LogicalORExpression in all cases. In particular, if SJSIRJSBinaryOp is && or ||, short-circuiting applies.

9.50JS constuctorOf

9.50.1Runtime Semantics: Evaluation

SJSIRTree:constuctorOf[SJSIRClassName]
  1. Let className be the StringValue of SJSIRClassName.
  2. Let class be ResolveSJSIRClass(className).
  3. Return ? SJSIRLoadConstructorOf(class).

9.51JS array constructor

Abstract Syntax

SJSIRJSArrayConstr:[] [SJSIRJSArgumentList]

9.51.1Runtime Semantics: Evaluation

SJSIRTree:[]
  1. Return ! ArrayCreate(0).
SJSIRTree:[SJSIRJSArgumentList]
  1. Let argList be ArgumentListEvaluation of SJSIRJSArgumentList.
  2. Return CreateArrayFromList(argList).

9.52JS object constructor

Abstract Syntax

SJSIRJSObjectConstr:{} {SJSIRJSObjectFieldList} SJSIRJSObjectFieldList:SJSIRJSObjectField SJSIRJSObjectFieldList,SJSIRJSObjectField SJSIRJSObjectField:[SJSIRTree]:SJSIRTree

9.52.1Runtime Semantics: Evaluation

SJSIRTree:{}
  1. Return ObjectCreate(%ObjectPrototype%).
SJSIRTree:{SJSIRJSObjectFieldList}
  1. Let obj be ObjectCreate(%ObjectPrototype%).
  2. Perform ? Evaluation of SJSIRJSObjectFieldList with argument obj.
  3. Return obj.
SJSIRJSObjectFieldList:SJSIRJSObjectFieldList,SJSIRJSObjectField
  1. Perform ? Evaluation of SJSIRJSObjectFieldList with argument obj.
  2. Perform ? Evaluation of SJSIRJSObjectField with argument obj.
SJSIRJSObjectField:[SJSIRTree]:SJSIRTree
  1. Let propRef be the result of evaluating the first SJSIRTree.
  2. Let propName be ? GetValue(propRef).
  3. Let propKey be ? ToPropertyKey(propName).
  4. Let exprValueRef be the result of evaluating the second SJSIRTree.
  5. Let propValue be ? GetValue(exprValueRef).
  6. Return CreateDataPropertyOrThrow(obj, propKey, propValue).

9.53JS Global Reference

9.53.1Runtime Semantics: Evaluation

SJSIRTree:global:Identifier
  1. Let name be the StringValue of Identifier
  2. Return ? SJSIRResolveGlobalRef(name).
Note

JS global reference trees are the only production of SJSIRTree whose Evaluation produces a Reference value. As such, they have a special meaning when directly enclosed within a production for typeof.

9.54Literals

Abstract Syntax

SJSIRLiteral:NullLiteral BooleanLiteral NumericLiteral StringLiteral SJSIRUndefinedLiteral SJSIRClassOfLiteral SJSIRUndefinedLiteral:undefined SJSIRClassOfLiteral:classOf[SJSIRType]

9.54.1Runtime Semantics: Evaluation

SJSIRUndefinedLiteral:undefined
  1. Return undefined.
SJSIRClassOfLiteral:classOf[SJSIRType]
  1. Let class be the result of SJSIRTypeToClass of SJSIRType.
  2. Return ? SJSIRClassOf(class).

9.55Closure creation

Abstract Syntax

SJSIRClosure:SJSIRClosureKindSJSIRCapturesSJSIRParamDefsRestAllowed=SJSIRTree SJSIRClosureKind:arrow-lambda function-lambda SJSIRCaptures:<> <SJSIRCaptureList> SJSIRCaptureList:SJSIRCapture SJSIRCaptureList,SJSIRCapture SJSIRCapture:Identifier:SJSIRType=SJSIRTree

9.55.1Static Semantics: SJSIRClosureFunctionKind

SJSIRClosureKind:arrow-lambda
  1. Return Arrow.
SJSIRClosureKind:function-lambda
  1. Return Normal.

9.55.2Static Semantics: TranslateFormalParams

SJSIRParamDefs:()
  1. Return an instance of FormalParameters with the production |[empty]|.
SJSIRParamDefs:(SJSIRParamDefList)
  1. Let paramList be TranslateFormalParamList of SJSIRParamDefList.
  2. Return an instance of FormalParameters with the production FormalParameterList whose only child is paramList.
SJSIRParamDefsRestAllowed:()
  1. Return an instance of FormalParameters with the production |[empty]|.
SJSIRParamDefsRestAllowed:(SJSIRRestParamDef)
  1. Let restParam be TranslateFormalRestParam of SJSIRRestParamDef.
  2. Return an instance of FormalParameters with the production FunctionRestParamater whose only child is restParam.
SJSIRParamDefsRestAllowed:(SJSIRParamDefList)
  1. Let paramList be TranslateFormalParamList of SJSIRParamDefList.
  2. Return an instance of FormalParameters with the production FormalParameterList whose only child is paramList.
SJSIRParamDefsRestAllowed:(SJSIRParamDefList,SJSIRRestParamDef)
  1. Let paramList be TranslateFormalParamList of SJSIRParamDefList.
  2. Let restParam be TranslateFormalRestParam of SJSIRRestParamDef.
  3. Return an instance of FormalParameters with the production FormalParameterList , FunctionRestParamater whose children are paramList and restParam.

9.55.3Static Semantics: TranslateFormalParamList

SJSIRParamDefsList:SJSIRParamDef
  1. Let param be TranslateFormalParam of SJSIRParamDef.
  2. Return an instance of FormalParameterList with the production FormalParamaeter whose only child is param.
SJSIRParamDefsList:SJSIRParamDefListSJSIRParamDef
  1. Let paramList be TranslateFormalParamList of SJSIRParamDefList.
  2. Let param be TranslateFormalParam of SJSIRParamDef.
  3. Return an instance of FormalParameters with the production FormalParameterList , FormalParamater whose children are paramList and param.

9.55.4Static Semantics: TranslateFormalParam

SJSIRParamDef:varoptIdentifier:SJSIRType
  1. Return an instance of FormalParameter whose only child is Identifier (through the single-child nonterminals BindingElement, SingleNameBinding and BindingIdentifier).

9.55.5Static Semantics: TranslateFormalRestParam

SJSIRRestParamDef:varopt...Identifier:SJSIRType
  1. Return an instance of FunctionRestParamater whose only child is Identifier (through the single-child nonterminals BindingRestElement and ... BindingIdentifier).

9.55.6Runtime Semantics: SJSIRCapturesEvaluation

With parameter E.

SJSIRCaptures:<>
  1. Return NormalCompletion(empty).
SJSIRCaptureList:SJSIRCaptureList,SJSIRCapture
  1. Perform ? SJSIRCapturesEvaluation of SJSIRCaptureList with argument E.
  2. Perform ? SJSIRCapturesEvaluation of SJSIRCapture with argument E.
SJSIRCapture:Identifier:SJSIRType=SJSIRTree
  1. Let ref be the result of evaluating SJSIRTree.
  2. Let val be ? GetValue(ref).
  3. Assert SJSIRIsValueOfType(val, SJSIRType) is true.
  4. Let name be the StringValue of Identifier.
  5. Let envRec be E's EnvironmentRecord.
  6. Perform ! envRec.CreateImmutableBinding(name, true).
  7. Perform ! envRec.InitializeBinding(name, val).
  8. Return NormalCompletion(empty).

9.55.7Runtime Semantics: Evaluation

SJSIRClosure:SJSIRClosureKindSJSIRCapturesSJSIRParamDefsRestAllowed=SJSIRTree
  1. Let kind be SJSIRClosureFunctionKind of SJSIRClosureKind.
  2. Let formalParameters be TranslateFormalParams of SJSIRParamDefsRestAllowed.
  3. Let functionBody be an instance of ReturnStatement with production return Expression whose only child is SJSIRTree.
  4. Let lex be the running execution context's LexicalEnvironment.
  5. Let globalEnv be FindSJSIRProgramEnv(lex).
  6. Let scope be NewDeclarativeEnvironment(globalEnv).
  7. Perform ? SJSIRCapturesEvaluation of SJSIRCaptures with argument scope.
  8. Let strict be true.
  9. Let closure be FunctionCreate(kind, formalParameters, functionBody, scope, strict).
  10. If kind is Normal, then
    1. Perform MakeConstructor(closure).
  11. Return closure.

9.56JS Class Creation

9.56.1Runtime Semantics: Evaluation

SJSIRTree:createJSClass[SJSIRClassName]SJSIRArguments
  1. Let className be the StringValue of SJSIRClassName.
  2. Let class be ResolveSJSIRClass(className).
  3. Let classDef be class.[[ClassDef]].
  4. Let captureValues be ArgumentListEvaluation of SJSIRArguments.
  5. ReturnIfAbrupt(captureValues).
  6. Return the result of SJSIRCreateJSClassValue of classDef with argument captureValues.

9.57Argument lists

Note

The evaluation of an argument list produces a List of values.

9.57.1Runtime Semantics: ArgumentListEvaluation

SJSIRArguments:()
  1. Return a new empty List.
SJSIRArgumentList:SJSIRTree
  1. Let ref be the result of evaluating SJSIRTree.
  2. Let arg be ? GetValue(ref).
  3. Return a List whose sole items is arg.
SJSIRArgumentList:SJSIRArgumentList,SJSIRTree
  1. Let precedingArgs be ArgumentListEvaluation of SJSIRArgumentList.
  2. ReturnIfAbrupt(precedingArgs).
  3. Let ref be the result of evaluating SJSIRTree.
  4. Let arg be ? GetValue(ref).
  5. Append arg to the end of precedingArgs.
  6. Return precedingArgs.
SJSIRJSArguments:()
  1. Return a new empty List.
SJSIRJSArgumentList:SJSIRTree
  1. Let ref be the result of evaluating SJSIRTree.
  2. Let arg be ? GetValue(ref).
  3. Return a List whose sole items is arg.
SJSIRJSArgumentList:...SJSIRTree
  1. Let list be a new empty List.
  2. Let spreadRef be the result of evaluating SJSIRTree.
  3. Let iterator be ? GetIterator(? GetValue(spreadRef)).
  4. Repeat,
    1. Let next be ? IteratorStep(iterator).
    2. If next is false, return list.
    3. Let nextArg be ? IteratorValue(next).
    4. Append nextArg to the end of list.
SJSIRJSArgumentList:SJSIRJSArgumentList,SJSIRTree
  1. Let precedingArgs be ArgumentListEvaluation of SJSIRJSArgumentList.
  2. ReturnIfAbrupt(precedingArgs).
  3. Let ref be the result of evaluating SJSIRTree.
  4. Let arg be ? GetValue(ref).
  5. Append arg to the end of precedingArgs.
  6. Return precedingArgs.
SJSIRJSArgumentList:SJSIRJSArgumentList,SJSIRTree
  1. Let precedingArgs be ArgumentListEvaluation of SJSIRJSArgumentList.
  2. ReturnIfAbrupt(precedingArgs).
  3. Let spreadRef be the result of evaluating SJSIRTree.
  4. Let iterator be ? GetIterator(? GetValue(spreadRef)).
  5. Repeat,
    1. Let next be ? IteratorStep(iterator).
    2. If next is false, return precedingArgs.
    3. Let nextArg be ? IteratorValue(next).
    4. Append nextArg to the end of precedingArgs.

9.58JS property reference

9.58.1Runtime Semantics: Evaluation

SJSIRJSPropRef:SJSIRTree[SJSIRTree]
  1. Let baseReference be the result of evaluating the first SJSIRTree.
  2. Let baseValue be ? GetValue(baseReference).
  3. Let propertyNameReference be the result of evaluating the second SJSIRTree.
  4. Let propertyNameValue be ? GetValue(propertyNameReference).
  5. Let bv be ? RequireObjectCoercible(baseValue).
  6. Let propertyKey be ? ToPropertyKey(propertyNameValue).
  7. Return a value of type Reference whose base value component is bv, whose referenced name component is propertyKey, and whose strict reference flag is true.
  8. NOTE: SJSIR programs are always in strict mode.
Note 1

This algorithm mimics that of the production MemberExpression : MemberExpression [ Expression ] of ECMAScript's property accessor evaluation.

SJSIRJSPropRef:super(SJSIRTree)::SJSIRTree[SJSIRTree]
  1. Let superCtorRef be the result of evaluating the first SJSIRTree.
  2. Let superCtor be ? GetValue(superCtorRef).
  3. Let thisReference be the result of evaluating the second SJSIRTree.
  4. Let thisValue be ? GetValue(thisReference).
  5. Let propertyNameReference be the result of evaluating the third SJSIRTree.
  6. Let propertyNameValue be ? GetValue(propertyNameReference).
  7. Let propertyKey be ? ToPropertyKey(propertyNameValue).
  8. Let superCtorObj be ? RequireObjectCoercible(superCtor).
  9. Let superCtorProto be ? superCtorObj.[[Get]]("prototype", superCtorObj).
  10. Let homeObject be ObjectCreate(superCtorProto).
  11. Return a value of type Reference that is a Super Reference whose base value component is homeObject, whose referenced name component is propertyKey, whose thisValue component is thisValue, and whose strict reference flag is true.
  12. NOTE: SJSIR programs are always in strict mode.
Note 2

There is a mismatch between the semantics of the first SJSIRTree (which is the super class value) and those of the base value of ECMAScript's Super Reference values (which is the home object, i.e., the prototype property of the enclosing class value). This algorithm solves this mismatch by creating a temporary homeObject whose prototype will be the value of the prototype property of superCtor.

ACopyright & Software License

Ecma International

Rue du Rhone 114

CH-1204 Geneva

Tel: +41 22 849 6000

Fax: +41 22 849 6001

Web: https://ecma-international.org/

Copyright Notice

© 2018 Ecma International

This draft document may be copied and furnished to others, and derivative works that comment on or otherwise explain it or assist in its implementation may be prepared, copied, published, and distributed, in whole or in part, without restriction of any kind, provided that the above copyright notice and this section are included on all such copies and derivative works. However, this document itself may not be modified in any way, including by removing the copyright notice or references to Ecma International, except as needed for the purpose of developing any document or deliverable produced by Ecma International.

This disclaimer is valid only prior to final version of this document. After approval all rights on the standard are reserved by Ecma International.

The limited permissions are granted through the standardization phase and will not be revoked by Ecma International or its successors or assigns during this time.

This document and the information contained herein is provided on an "AS IS" basis and ECMA INTERNATIONAL DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY OWNERSHIP RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.

Software License

All Software contained in this document ("Software") is protected by copyright and is being made available under the "BSD License", included below. This Software may be subject to third party rights (rights from parties other than Ecma International), including patent rights, and no licenses under such third party rights are granted under this license even if the third party concerned is a member of Ecma International. SEE THE ECMA CODE OF CONDUCT IN PATENT MATTERS AVAILABLE AT https://ecma-international.org/memento/codeofconduct.htm FOR INFORMATION REGARDING THE LICENSING OF PATENT CLAIMS THAT ARE REQUIRED TO IMPLEMENT ECMA INTERNATIONAL STANDARDS.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of the authors nor Ecma International may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE ECMA INTERNATIONAL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ECMA INTERNATIONAL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.