Skip to content

Instantly share code, notes, and snippets.

@anba
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anba/e6b525c124d09dafaed6 to your computer and use it in GitHub Desktop.
Save anba/e6b525c124d09dafaed6 to your computer and use it in GitHub Desktop.
ES6 classes: deferring the creation step

F.[[Call]](thisArgument, argumentsList, thisConstructor) :

  1. ...
  2. If thisArgument is empty, then let calledAsConstructor be true; else let calledAsConstructor be false.
  3. Let result be the result of EvaluateBody...
  4. ReturnIfAbrupt(result).
  5. If calledAsConstructor is true and Type(result) is not Object, then
  6. TODO: Interaction with Tail-Call semantics?
  7. Let thisValue be GetThisBinding().
  8. NOTE: 'thisValue' may be empty, callers need to handle this case!
  9. Let result be NormalCompletion(thisValue).
  10. Return result.

F.[[Construct]](receiver, argumentsList):

  1. If F.[[NeedsSuper]] is false, then
  2. Let obj be the result of OrdinaryCreateFromConstructor(receiver.prototype, "%ObjectPrototype%").
  3. ReturnIfAbrupt(obj).
  4. Else,
  5. Let obj be empty.
  6. Let result be the result of F.[[Call]](obj, argumentsList, receiver).
  7. ReturnIfAbrupt(result).
  8. If result is empty, then throw a (Reference|Type)Error exception.
  9. If Type(result) is Object, return result.
  10. Assert: obj is not empty.
  11. Return obj.

Semantics of a super-method call:

  1. Let F be the method referenced by super.method. (!!!)
  2. Let thisValue be GetThisBinding().
  3. If thisValue is not empty,
    1. Let result be the result of F.[[Call]](thisValue, args).
  4. Else,
    1. If IsConstructor(F) is false, then throw a TypeError exception.
    2. Let receiver be GetThisConstructor().
    3. Let result be the result of F.[[Construct]](receiver, args).
    4. ReturnIfAbrupt(result).
    5. Assert: Type(result) is Object.
    6. If GetThisBinding() is empty, then InitializeThisBinding(result).
  5. Return result.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment