Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lahma committed Jan 4, 2021
1 parent 5f1892c commit 506294a
Show file tree
Hide file tree
Showing 17 changed files with 608 additions and 188 deletions.
15 changes: 15 additions & 0 deletions Jint.Tests.Test262/Language/Expressions/YieldTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Xunit;

namespace Jint.Tests.Test262.Language.Expressions
{
public class YieldTests : Test262Test
{
[Theory(DisplayName = "language\\expressions\\yield")]
[MemberData(nameof(SourceFiles), "language\\expressions\\yield", false)]
[MemberData(nameof(SourceFiles), "language\\expressions\\yield", true, Skip = "Skipped")]
protected void New(SourceFile sourceFile)
{
RunTestInternal(sourceFile);
}
}
}
8 changes: 0 additions & 8 deletions Jint.Tests.Test262/Test262Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,6 @@ public static IEnumerable<object[]> SourceFiles(string pathPrefix, bool skipped)
skip = true;
reason = "BigInt not implemented";
break;
case "generators":
skip = true;
reason = "generators not implemented";
break;
case "async-functions":
skip = true;
reason = "async-functions not implemented";
Expand All @@ -235,10 +231,6 @@ public static IEnumerable<object[]> SourceFiles(string pathPrefix, bool skipped)
skip = true;
reason = "MetaProperty not implemented";
break;
case "super":
skip = true;
reason = "super not implemented";
break;
case "String.prototype.replaceAll":
skip = true;
reason = "not in spec yet";
Expand Down
63 changes: 28 additions & 35 deletions Jint/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public Engine(Action<Engine, Options> options)

Object = ObjectConstructor.CreateObjectConstructor(this);
Function = FunctionConstructor.CreateFunctionConstructor(this);
GeneratorFunction = GeneratorFunctionConstructor.CreateGeneratorConstructor(this);
_callerCalleeArgumentsThrowerConfigurable = new GetSetPropertyDescriptor.ThrowerPropertyDescriptor(this, PropertyFlag.Configurable | PropertyFlag.CustomJsValue, "'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them");
_callerCalleeArgumentsThrowerNonConfigurable = new GetSetPropertyDescriptor.ThrowerPropertyDescriptor(this, PropertyFlag.CustomJsValue, "'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them");

Expand Down Expand Up @@ -207,6 +208,7 @@ public Engine(Action<Engine, Options> options)
public GlobalObject Global { get; }
public ObjectConstructor Object { get; }
public FunctionConstructor Function { get; }
public GeneratorFunctionConstructor GeneratorFunction { get; }
public ArrayConstructor Array { get; }
public MapConstructor Map { get; }
public SetConstructor Set { get; }
Expand Down Expand Up @@ -369,7 +371,7 @@ internal Engine Execute(Script script, bool resetState)
GlobalEnvironment);

var list = new JintStatementList(this, null, script.Body);

var result = list.Execute();
if (result.Type == CompletionType.Throw)
{
Expand Down Expand Up @@ -452,7 +454,7 @@ internal JsValue GetValue(Reference reference, bool returnReferenceToPool)
{
return baseValue;
}

if (reference.IsPropertyReference())
{
var property = reference.GetReferencedName();
Expand Down Expand Up @@ -588,15 +590,6 @@ internal void PutValue(Reference reference, JsValue value)
((EnvironmentRecord) baseValue).SetMutableBinding(TypeConverter.ToString(reference.GetReferencedName()), value, reference.IsStrictReference());
}
}

/// <summary>
/// http://www.ecma-international.org/ecma-262/6.0/#sec-initializereferencedbinding
/// </summary>
public void InitializeReferenceBinding(Reference reference, JsValue value)
{
var baseValue = (EnvironmentRecord) reference.GetBase();
baseValue.InitializeBinding(TypeConverter.ToString(reference.GetReferencedName()), value);
}

/// <summary>
/// Invoke the current value as function.
Expand Down Expand Up @@ -686,7 +679,7 @@ public JsValue GetValue(JsValue scope, JsValue property)
_referencePool.Return(reference);
return jsValue;
}

/// <summary>
/// https://tc39.es/ecma262/#sec-resolvebinding
/// </summary>
Expand Down Expand Up @@ -742,7 +735,7 @@ internal JsValue ResolveThisBinding()
var envRec = GetThisEnvironment();
return envRec.GetThisBinding();
}

/// <summary>
/// https://tc39.es/ecma262/#sec-globaldeclarationinstantiation
/// </summary>
Expand All @@ -756,7 +749,7 @@ private void GlobalDeclarationInstantiation(
var functionDeclarations = hoistingScope._functionDeclarations;
var varDeclarations = hoistingScope._variablesDeclarations;
var lexDeclarations = hoistingScope._lexicalDeclarations;

var functionToInitialize = new LinkedList<FunctionDeclaration>();
var declaredFunctionNames = new HashSet<string>();
var declaredVarNames = new List<string>();
Expand Down Expand Up @@ -797,7 +790,7 @@ private void GlobalDeclarationInstantiation(
{
ExceptionHelper.ThrowSyntaxError(this, $"Identifier '{vn}' has already been declared");
}

if (!declaredFunctionNames.Contains(vn))
{
var vnDefinable = envRec.CanDeclareGlobalVar(vn);
Expand All @@ -822,13 +815,13 @@ private void GlobalDeclarationInstantiation(
for (var j = 0; j < boundNames.Count; j++)
{
var dn = boundNames[j];
if (envRec.HasVarDeclaration(dn)
if (envRec.HasVarDeclaration(dn)
|| envRec.HasLexicalDeclaration(dn)
|| envRec.HasRestrictedGlobalProperty(dn))
{
ExceptionHelper.ThrowSyntaxError(this, $"Identifier '{dn}' has already been declared");
}

if (d.Kind == VariableDeclarationKind.Const)
{
envRec.CreateImmutableBinding(dn, strict: true);
Expand All @@ -844,13 +837,13 @@ private void GlobalDeclarationInstantiation(
foreach (var f in functionToInitialize)
{
var fn = f.Id!.Name;

if (envRec.HasLexicalDeclaration(fn))
{
ExceptionHelper.ThrowSyntaxError(this, $"Identifier '{fn}' has already been declared");
}
var fo = Function.CreateFunctionObject(f, env);

var fo = Function.InstantiateFunctionObject(f, env);
envRec.CreateGlobalFunctionBinding(fn, fo, canBeDeleted: false);
}

Expand Down Expand Up @@ -912,7 +905,7 @@ internal ArgumentsInstance FunctionDeclarationInstantiation(
// slower set
envRec.AddFunctionParameters(func.Function, argumentsList);
}

// Let iteratorRecord be CreateListIteratorRecord(argumentsList).
// If hasDuplicates is true, then
// Perform ? IteratorBindingInitialization for formals with iteratorRecord and undefined as arguments.
Expand All @@ -939,7 +932,7 @@ internal ArgumentsInstance FunctionDeclarationInstantiation(
// in the formal parameter list do not have visibility of declarations in the function body.
varEnv = LexicalEnvironment.NewDeclarativeEnvironment(this, env);
varEnvRec = (DeclarativeEnvironmentRecord) varEnv._record;

UpdateVariableEnvironment(varEnv);

for (var i = 0; i < configuration.VarsToInitialize.Count; i++)
Expand All @@ -949,8 +942,8 @@ internal ArgumentsInstance FunctionDeclarationInstantiation(
varEnvRec.CreateMutableBindingAndInitialize(pair.Name, canBeDeleted: false, initialValue);
}
}
// NOTE: Annex B.3.3.1 adds additional steps at this point.

// NOTE: Annex B.3.3.1 adds additional steps at this point.
// A https://tc39.es/ecma262/#sec-web-compat-functiondeclarationinstantiation

LexicalEnvironment lexEnv;
Expand All @@ -968,7 +961,7 @@ internal ArgumentsInstance FunctionDeclarationInstantiation(
}

var lexEnvRec = lexEnv._record;

UpdateLexicalEnvironment(lexEnv);

if (configuration.LexicalDeclarations.Length > 0)
Expand All @@ -992,13 +985,13 @@ private void InitializeFunctions(
foreach (var f in functionsToInitialize)
{
var fn = f.Id.Name;
var fo = Function.CreateFunctionObject(f, lexEnv);
var fo = Function.InstantiateFunctionObject(f, lexEnv);
varEnvRec.SetMutableBinding(fn, fo, strict: false);
}
}

private static void InitializeLexicalDeclarations(
JintFunctionDefinition.State.LexicalVariableDeclaration[] lexicalDeclarations,
JintFunctionDefinition.State.LexicalVariableDeclaration[] lexicalDeclarations,
EnvironmentRecord lexEnvRec)
{
foreach (var d in lexicalDeclarations)
Expand All @@ -1019,9 +1012,9 @@ private static void InitializeLexicalDeclarations(
}

private ArgumentsInstance CreateMappedArgumentsObject(
FunctionInstance func,
FunctionInstance func,
Key[] formals,
JsValue[] argumentsList,
JsValue[] argumentsList,
DeclarativeEnvironmentRecord envRec,
bool hasRestParameter)
{
Expand All @@ -1043,7 +1036,7 @@ internal void EvalDeclarationInstantiation(
bool strict)
{
var hoistingScope = HoistingScope.GetProgramLevelDeclarations(script);

var lexEnvRec = (DeclarativeEnvironmentRecord) lexEnv._record;
var varEnvRec = varEnv._record;

Expand Down Expand Up @@ -1084,7 +1077,7 @@ internal void EvalDeclarationInstantiation(
thisLex = thisLex._outer;
}
}

var functionDeclarations = hoistingScope._functionDeclarations;
var functionsToInitialize = new LinkedList<FunctionDeclaration>();
var declaredFunctionNames = new HashSet<string>();
Expand Down Expand Up @@ -1138,7 +1131,7 @@ internal void EvalDeclarationInstantiation(
}
}
}

var lexicalDeclarations = hoistingScope._lexicalDeclarations;
var lexicalDeclarationsCount = lexicalDeclarations?.Count;
for (var i = 0; i < lexicalDeclarationsCount; i++)
Expand All @@ -1163,7 +1156,7 @@ internal void EvalDeclarationInstantiation(
foreach (var f in functionsToInitialize)
{
var fn = f.Id.Name;
var fo = Function.CreateFunctionObject(f, lexEnv);
var fo = Function.InstantiateFunctionObject(f, lexEnv);
if (varEnvRec is GlobalEnvironmentRecord ger)
{
ger.CreateGlobalFunctionBinding(fn, fo, canBeDeleted: true);
Expand Down Expand Up @@ -1220,7 +1213,7 @@ internal JsValue Call(ICallable callable, JsValue thisObject, JsValue[] argument
{
return Call(functionInstance, thisObject, arguments, expression);
}

return callable.Call(thisObject, arguments);
}

Expand All @@ -1230,7 +1223,7 @@ internal JsValue Construct(IConstructor constructor, JsValue[] arguments, JsValu
{
return Construct(functionInstance, arguments, newTarget, expression);
}

return constructor.Construct(arguments, newTarget);
}

Expand Down
Loading

0 comments on commit 506294a

Please sign in to comment.