Skip to content

Commit

Permalink
JSS.Lib: Implement the HasThisBinding abstract operation
Browse files Browse the repository at this point in the history
  • Loading branch information
PrestonLTaylor committed Jan 11, 2024
1 parent a13d795 commit f68665f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
7 changes: 7 additions & 0 deletions JSS.Lib/Execution/DeclarativeEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,12 @@ override public Completion GetBindingValue(string N, bool S)
return Completion.NormalCompletion(binding.Value);
}

// 9.1.1.1.8 HasThisBinding ( ), https://tc39.es/ecma262/#sec-declarative-environment-records-hasthisbinding
override public bool HasThisBinding()
{
// 1. Return false.
return false;
}

private readonly Dictionary<string, Binding> _identifierToBinding = new();
}
3 changes: 1 addition & 2 deletions JSS.Lib/Execution/Environment.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using JSS.Lib.AST.Values;
using ValueType = JSS.Lib.AST.Values.ValueType;
using Object = JSS.Lib.AST.Values.Object;

namespace JSS.Lib.Execution;

Expand All @@ -18,7 +17,7 @@ internal abstract class Environment : Value
virtual public Completion SetMutableBinding(string N, Value V, bool S) { throw new NotImplementedException(); }
virtual public Completion GetBindingValue(string N, bool S) { throw new NotImplementedException(); }
virtual public Completion DeleteBinding(string N) { throw new NotImplementedException(); }
virtual public bool HasThisBinding() { throw new NotImplementedException(); }
abstract public bool HasThisBinding();
virtual public bool HasSuperBinding() { throw new NotImplementedException(); }
virtual public Value WithBaseObject() { throw new NotImplementedException(); }
virtual public Completion GetThisBinding() { throw new InvalidOperationException(); }
Expand Down
9 changes: 8 additions & 1 deletion JSS.Lib/Execution/FunctionEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,15 @@ public Completion BindThisValue(Value V)
return Completion.NormalCompletion(V);
}

// 9.1.1.3.2 HasThisBinding ( ), https://tc39.es/ecma262/#sec-function-environment-records-hasthisbinding
override public bool HasThisBinding()
{
// 1. If envRec.[[ThisBindingStatus]] is LEXICAL, return false; otherwise, return true.
return ThisBindingStatus != ThisBindingStatus.LEXICAL;
}

// 9.1.1.3.4 GetThisBinding ( ), https://tc39.es/ecma262/#sec-function-environment-records-getthisbinding
public override Completion GetThisBinding()
override public Completion GetThisBinding()
{
// 1. Assert: envRec.[[ThisBindingStatus]] is not LEXICAL.
Debug.Assert(ThisBindingStatus != ThisBindingStatus.LEXICAL);
Expand Down
7 changes: 7 additions & 0 deletions JSS.Lib/Execution/GlobalEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ override public Completion GetBindingValue(string N, bool S)
return ObjectRecord.GetBindingValue(N, S);
}

// 9.1.1.4.8 HasThisBinding ( ), https://tc39.es/ecma262/#sec-global-environment-records-hasthisbinding
public override bool HasThisBinding()
{
// 1. Return true.
return true;
}

// 9.1.1.4.11 GetThisBinding ( ), https://tc39.es/ecma262/#sec-global-environment-records-getthisbinding
public override Completion GetThisBinding()
{
Expand Down
7 changes: 7 additions & 0 deletions JSS.Lib/Execution/ObjectEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ override public Completion GetBindingValue(string N, bool S)
return Object.Get(BindingObject, N);
}

// 9.1.1.2.8 HasThisBinding ( ), https://tc39.es/ecma262/#sec-object-environment-records-hasthisbinding
override public bool HasThisBinding()
{
// 1. Return false.
return false;
}

public Object BindingObject { get; }
public bool IsWithEnvironment { get; }
}

0 comments on commit f68665f

Please sign in to comment.