Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
lahma committed Oct 31, 2021
1 parent 2bc53d4 commit 2a6cabb
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Jint.Tests.Test262/BuiltIns/GeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Jint.Tests.Test262.BuiltIns
{
public class GeneratorTests : Test262Test
{
[Theory(DisplayName = "built-ins\\GeneratorFunction", Skip = "TODO")]
[Theory(DisplayName = "built-ins\\GeneratorFunction")]
[MemberData(nameof(SourceFiles), "built-ins\\GeneratorFunction", false)]
[MemberData(nameof(SourceFiles), "built-ins\\GeneratorFunction", true, Skip = "Skipped")]
protected void GeneratorFunction(SourceFile sourceFile)
Expand Down
10 changes: 5 additions & 5 deletions Jint/Native/Function/FunctionConstructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ internal FunctionInstance CreateDynamicFunction(
FunctionKind kind,
JsValue[] args)
{
/* TODO
var callerContext = _engine.GetExecutionContext(1);
// TODO var callerContext = _engine.GetExecutionContext(1);
var callerContext = _engine.ExecutionContext;
var callerRealm = callerContext.Realm;
var calleeRealm = engine.ExecutionContext.Realm;
var calleeRealm = _engine.ExecutionContext.Realm;

_engine._host.EnsureCanCompileStrings(callerRealm, calleeRealm);
*/

if (newTarget.IsUndefined())
{
Expand Down Expand Up @@ -191,7 +191,7 @@ internal FunctionInstance CreateDynamicFunction(

if (kind == FunctionKind.Generator)
{
var prototype = OrdinaryObjectCreate(_realm.Intrinsics.GeneratorFunction.PrototypeObject.Prototype);
var prototype = OrdinaryObjectCreate(_realm.Intrinsics.GeneratorFunction.PrototypeObject.PrototypeObject);
F.DefinePropertyOrThrow(CommonProperties.Prototype, new PropertyDescriptor(prototype, PropertyFlag.Writable));
}
else if (kind == FunctionKind.AsyncGenerator)
Expand Down
8 changes: 6 additions & 2 deletions Jint/Native/Function/ScriptFunctionInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ internal ScriptFunctionInstance(
_prototype = proto ?? _engine.Realm.Intrinsics.Function.PrototypeObject;
_length = new LazyPropertyDescriptor(null, _ => JsNumber.Create(function.Initialize(this).Length), PropertyFlag.Configurable);

if (!function.Strict && !engine._isStrict && function.Function is not ArrowFunctionExpression)
if (!function.Strict
&& !engine._isStrict
&& function.Function is not ArrowFunctionExpression
&& !function.Function.Generator)
{
DefineOwnProperty(CommonProperties.Arguments, engine._callerCalleeArgumentsThrowerConfigurable);
DefineOwnProperty(CommonProperties.Caller, new PropertyDescriptor(Undefined, PropertyFlag.Configurable));
Expand Down Expand Up @@ -103,7 +106,8 @@ public override JsValue Call(JsValue thisArgument, JsValue[] arguments)

internal override bool IsConstructor =>
(_homeObject.IsUndefined() || _isClassConstructor)
&& _functionDefinition?.Function is not ArrowFunctionExpression;
&& _functionDefinition?.Function is not ArrowFunctionExpression
&& _functionDefinition?.Function.Generator != true;

/// <summary>
/// https://tc39.es/ecma262/#sec-ecmascript-function-objects-construct-argumentslist-newtarget
Expand Down
5 changes: 3 additions & 2 deletions Jint/Native/Generator/GeneratorFunctionPrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public sealed class GeneratorFunctionPrototype : ObjectInstance
{
private readonly GeneratorFunctionConstructor _constructor;

internal GeneratorFunctionPrototype(Engine engine,
internal GeneratorFunctionPrototype(
Engine engine,
GeneratorFunctionConstructor constructor,
FunctionPrototype prototype,
IteratorPrototype iteratorPrototype) : base(engine)
Expand All @@ -30,7 +31,7 @@ protected override void Initialize()
{
var properties = new PropertyDictionary(2, checkExistingKeys: false)
{
["constructor"] = new PropertyDescriptor(_constructor, PropertyFlag.NonEnumerable),
["constructor"] = new PropertyDescriptor(_constructor, PropertyFlag.Configurable),
["prototype"] = new PropertyDescriptor(PrototypeObject, PropertyFlag.Configurable)
};
SetProperties(properties);
Expand Down
3 changes: 1 addition & 2 deletions Jint/Native/Generator/GeneratorInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,10 @@ private JsValue ResumeExecution(ExecutionContext genContext, EvaluationContext c
}
else if (result.Type == CompletionType.Return)
{
resultValue = new IteratorInstance.ValueIteratorPosition(_engine, result.Value, _generatorBody.Completed);
resultValue = new IteratorInstance.ValueIteratorPosition(_engine, result.Value, false);
if (_generatorBody.Completed)
{
_generatorState = GeneratorState.Completed;
resultValue.Set(CommonProperties.Done, JsBoolean.True);
}
}

Expand Down
3 changes: 2 additions & 1 deletion Jint/Native/Global/GlobalObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected override void Initialize()
const PropertyFlag lengthFlags = PropertyFlag.Configurable;
const PropertyFlag propertyFlags = PropertyFlag.Configurable | PropertyFlag.Writable;

var properties = new PropertyDictionary(54, checkExistingKeys: false)
var properties = new PropertyDictionary(55, checkExistingKeys: false)
{
["Object"] = new PropertyDescriptor(_realm.Intrinsics.Object, propertyFlags),
["Function"] = new PropertyDescriptor(_realm.Intrinsics.Function, propertyFlags),
Expand All @@ -53,6 +53,7 @@ protected override void Initialize()
["BigUint64Array"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.BigUint64Array, propertyFlags),
["Float32Array"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.Float32Array, propertyFlags),
["Float64Array"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.Float64Array, propertyFlags),
["GeneratorFunction"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.GeneratorFunction, propertyFlags),
["Map"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.Map, propertyFlags),
["Set"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.Set, propertyFlags),
["WeakMap"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.WeakMap, propertyFlags),
Expand Down
19 changes: 0 additions & 19 deletions Jint/Runtime/Interpreter/Expressions/JintAssignmentExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ internal static JintExpression Build(Engine engine, AssignmentExpression express
return new BindingPatternAssignmentExpression(expression);
}

if (expression.Right is YieldExpression)
{
return new YieldAssignmentExpression(expression);
}

return new SimpleAssignmentExpression(expression);
}

Expand Down Expand Up @@ -385,19 +380,5 @@ private ExpressionResult SetValue(EvaluationContext context)
return null;
}
}

private sealed class YieldAssignmentExpression : JintExpression
{
public YieldAssignmentExpression(AssignmentExpression expression) : base(expression)
{
throw new System.NotImplementedException();
}

protected override ExpressionResult EvaluateInternal(EvaluationContext context)
{
ExceptionHelper.ThrowNotImplementedException();
return default;
}
}
}
}
3 changes: 1 addition & 2 deletions Jint/Runtime/Interpreter/Expressions/JintYieldExpression.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Esprima.Ast;
using Jint.Native;
using Jint.Native.Generator;
using Jint.Native.Iterator;
using Jint.Native.Object;

namespace Jint.Runtime.Interpreter.Expressions
Expand Down Expand Up @@ -38,7 +37,7 @@ protected override ExpressionResult EvaluateInternal(EvaluationContext context)
// TODO return YieldDelegate(value);
}

return new Completion(CompletionType.Return, Yield(new IteratorResult(engine, value, JsBoolean.False)), _expression.Location);
return new ExpressionResult(ExpressionCompletionType.Return, Yield(value), _expression.Location);
}

/*
Expand Down

0 comments on commit 2a6cabb

Please sign in to comment.