15.4 Method Definitions

Syntax

MethodDefinition[Yield, Await] : PropertyName[?Yield, ?Await] ( UniqueFormalParameters[~Yield, ~Await] ) { FunctionBody[~Yield, ~Await] } GeneratorMethod[?Yield, ?Await] AsyncMethod[?Yield, ?Await] AsyncGeneratorMethod[?Yield, ?Await] get PropertyName[?Yield, ?Await] ( ) { FunctionBody[~Yield, ~Await] } set PropertyName[?Yield, ?Await] ( PropertySetParameterList ) { FunctionBody[~Yield, ~Await] } PropertySetParameterList : FormalParameter[~Yield, ~Await]

15.4.1 Static Semantics: Early Errors

MethodDefinition : PropertyName ( UniqueFormalParameters ) { FunctionBody } MethodDefinition : set PropertyName ( PropertySetParameterList ) { FunctionBody }

15.4.2 Static Semantics: HasDirectSuper

MethodDefinition : PropertyName ( UniqueFormalParameters ) { FunctionBody }
  1. If UniqueFormalParameters Contains SuperCall is true, return true.
  2. Return FunctionBody Contains SuperCall.
MethodDefinition : get PropertyName ( ) { FunctionBody }
  1. Return FunctionBody Contains SuperCall.
MethodDefinition : set PropertyName ( PropertySetParameterList ) { FunctionBody }
  1. If PropertySetParameterList Contains SuperCall is true, return true.
  2. Return FunctionBody Contains SuperCall.
GeneratorMethod : * PropertyName ( UniqueFormalParameters ) { GeneratorBody }
  1. If UniqueFormalParameters Contains SuperCall is true, return true.
  2. Return GeneratorBody Contains SuperCall.
AsyncGeneratorMethod : async * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody }
  1. If UniqueFormalParameters Contains SuperCall is true, return true.
  2. Return AsyncGeneratorBody Contains SuperCall.
AsyncMethod : async PropertyName ( UniqueFormalParameters ) { AsyncFunctionBody }
  1. If UniqueFormalParameters Contains SuperCall is true, return true.
  2. Return AsyncFunctionBody Contains SuperCall.

15.4.3 Static Semantics: SpecialMethod

MethodDefinition : PropertyName ( UniqueFormalParameters ) { FunctionBody }
  1. Return false.
MethodDefinition : GeneratorMethod AsyncMethod AsyncGeneratorMethod get PropertyName ( ) { FunctionBody } set PropertyName ( PropertySetParameterList ) { FunctionBody }
  1. Return true.

15.4.4 Runtime Semantics: DefineMethod

With parameter object and optional parameter functionPrototype.

MethodDefinition : PropertyName ( UniqueFormalParameters ) { FunctionBody }
  1. Let propKey be the result of evaluating PropertyName.
  2. ReturnIfAbrupt(propKey).
  3. Let scope be the running execution context's LexicalEnvironment.
  4. If functionPrototype is present, then
    1. Let prototype be functionPrototype.
  5. Else,
    1. Let prototype be %Function.prototype%.
  6. Let sourceText be the source text matched by MethodDefinition.
  7. Let closure be OrdinaryFunctionCreate(prototype, sourceText, UniqueFormalParameters, FunctionBody, non-lexical-this, scope).
  8. Perform MakeMethod(closure, object).
  9. Return the Record { [[Key]]: propKey, [[Closure]]: closure }.

15.4.5 Runtime Semantics: MethodDefinitionEvaluation

With parameters object and enumerable.

MethodDefinition : PropertyName ( UniqueFormalParameters ) { FunctionBody }
  1. Let methodDef be ? DefineMethod of MethodDefinition with argument object.
  2. Perform SetFunctionName(methodDef.[[Closure]], methodDef.[[Key]]).
  3. Let desc be the PropertyDescriptor { [[Value]]: methodDef.[[Closure]], [[Writable]]: true, [[Enumerable]]: enumerable, [[Configurable]]: true }.
  4. Return ? DefinePropertyOrThrow(object, methodDef.[[Key]], desc).
MethodDefinition : get PropertyName ( ) { FunctionBody }
  1. Let propKey be the result of evaluating PropertyName.
  2. ReturnIfAbrupt(propKey).
  3. Let scope be the running execution context's LexicalEnvironment.
  4. Let sourceText be the source text matched by MethodDefinition.
  5. Let formalParameterList be an instance of the production FormalParameters : [empty] .
  6. Let closure be OrdinaryFunctionCreate(%Function.prototype%, sourceText, formalParameterList, FunctionBody, non-lexical-this, scope).
  7. Perform MakeMethod(closure, object).
  8. Perform SetFunctionName(closure, propKey, "get").
  9. Let desc be the PropertyDescriptor { [[Get]]: closure, [[Enumerable]]: enumerable, [[Configurable]]: true }.
  10. Return ? DefinePropertyOrThrow(object, propKey, desc).
MethodDefinition : set PropertyName ( PropertySetParameterList ) { FunctionBody }
  1. Let propKey be the result of evaluating PropertyName.
  2. ReturnIfAbrupt(propKey).
  3. Let scope be the running execution context's LexicalEnvironment.
  4. Let sourceText be the source text matched by MethodDefinition.
  5. Let closure be OrdinaryFunctionCreate(%Function.prototype%, sourceText, PropertySetParameterList, FunctionBody, non-lexical-this, scope).
  6. Perform MakeMethod(closure, object).
  7. Perform SetFunctionName(closure, propKey, "set").
  8. Let desc be the PropertyDescriptor { [[Set]]: closure, [[Enumerable]]: enumerable, [[Configurable]]: true }.
  9. Return ? DefinePropertyOrThrow(object, propKey, desc).
GeneratorMethod : * PropertyName ( UniqueFormalParameters ) { GeneratorBody }
  1. Let propKey be the result of evaluating PropertyName.
  2. ReturnIfAbrupt(propKey).
  3. Let scope be the running execution context's LexicalEnvironment.
  4. Let sourceText be the source text matched by GeneratorMethod.
  5. Let closure be OrdinaryFunctionCreate(%GeneratorFunction.prototype%, sourceText, UniqueFormalParameters, GeneratorBody, non-lexical-this, scope).
  6. Perform MakeMethod(closure, object).
  7. Perform SetFunctionName(closure, propKey).
  8. Let prototype be ! OrdinaryObjectCreate(%GeneratorFunction.prototype.prototype%).
  9. Perform DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }).
  10. Let desc be the PropertyDescriptor { [[Value]]: closure, [[Writable]]: true, [[Enumerable]]: enumerable, [[Configurable]]: true }.
  11. Return ? DefinePropertyOrThrow(object, propKey, desc).
AsyncGeneratorMethod : async * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody }
  1. Let propKey be the result of evaluating PropertyName.
  2. ReturnIfAbrupt(propKey).
  3. Let scope be the running execution context's LexicalEnvironment.
  4. Let sourceText be the source text matched by AsyncGeneratorMethod.
  5. Let closure be ! OrdinaryFunctionCreate(%AsyncGeneratorFunction.prototype%, sourceText, UniqueFormalParameters, AsyncGeneratorBody, non-lexical-this, scope).
  6. Perform ! MakeMethod(closure, object).
  7. Perform ! SetFunctionName(closure, propKey).
  8. Let prototype be ! OrdinaryObjectCreate(%AsyncGeneratorFunction.prototype.prototype%).
  9. Perform ! DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }).
  10. Let desc be PropertyDescriptor { [[Value]]: closure, [[Writable]]: true, [[Enumerable]]: enumerable, [[Configurable]]: true }.
  11. Return ? DefinePropertyOrThrow(object, propKey, desc).
AsyncMethod : async PropertyName ( UniqueFormalParameters ) { AsyncFunctionBody }
  1. Let propKey be the result of evaluating PropertyName.
  2. ReturnIfAbrupt(propKey).
  3. Let scope be the LexicalEnvironment of the running execution context.
  4. Let sourceText be the source text matched by AsyncMethod.
  5. Let closure be ! OrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, UniqueFormalParameters, AsyncFunctionBody, non-lexical-this, scope).
  6. Perform ! MakeMethod(closure, object).
  7. Perform ! SetFunctionName(closure, propKey).
  8. Let desc be the PropertyDescriptor { [[Value]]: closure, [[Writable]]: true, [[Enumerable]]: enumerable, [[Configurable]]: true }.
  9. Return ? DefinePropertyOrThrow(object, propKey, desc).