diff --git a/Jint.Tests.Test262/BuiltIns/GeneratorTests.cs b/Jint.Tests.Test262/BuiltIns/GeneratorTests.cs index 41b5faf82a..9c45e8b238 100644 --- a/Jint.Tests.Test262/BuiltIns/GeneratorTests.cs +++ b/Jint.Tests.Test262/BuiltIns/GeneratorTests.cs @@ -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) diff --git a/Jint/Native/Function/FunctionConstructor.cs b/Jint/Native/Function/FunctionConstructor.cs index 3e8ef95718..d9f078bd46 100644 --- a/Jint/Native/Function/FunctionConstructor.cs +++ b/Jint/Native/Function/FunctionConstructor.cs @@ -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()) { @@ -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) diff --git a/Jint/Native/Function/ScriptFunctionInstance.cs b/Jint/Native/Function/ScriptFunctionInstance.cs index 7793deb656..00a6fa9397 100644 --- a/Jint/Native/Function/ScriptFunctionInstance.cs +++ b/Jint/Native/Function/ScriptFunctionInstance.cs @@ -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)); @@ -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; /// /// https://tc39.es/ecma262/#sec-ecmascript-function-objects-construct-argumentslist-newtarget diff --git a/Jint/Native/Generator/GeneratorFunctionPrototype.cs b/Jint/Native/Generator/GeneratorFunctionPrototype.cs index 3d5191f490..e0fbe1f10a 100644 --- a/Jint/Native/Generator/GeneratorFunctionPrototype.cs +++ b/Jint/Native/Generator/GeneratorFunctionPrototype.cs @@ -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) @@ -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); diff --git a/Jint/Native/Generator/GeneratorInstance.cs b/Jint/Native/Generator/GeneratorInstance.cs index ddc2f0c5d2..dfea9f9b9d 100644 --- a/Jint/Native/Generator/GeneratorInstance.cs +++ b/Jint/Native/Generator/GeneratorInstance.cs @@ -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); } } diff --git a/Jint/Native/Global/GlobalObject.cs b/Jint/Native/Global/GlobalObject.cs index bdc29b4ddf..93e6b9f670 100644 --- a/Jint/Native/Global/GlobalObject.cs +++ b/Jint/Native/Global/GlobalObject.cs @@ -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), @@ -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), diff --git a/Jint/Runtime/Interpreter/Expressions/JintAssignmentExpression.cs b/Jint/Runtime/Interpreter/Expressions/JintAssignmentExpression.cs index 8d34ed3502..f404ce72ed 100644 --- a/Jint/Runtime/Interpreter/Expressions/JintAssignmentExpression.cs +++ b/Jint/Runtime/Interpreter/Expressions/JintAssignmentExpression.cs @@ -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); } @@ -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; - } - } } } \ No newline at end of file diff --git a/Jint/Runtime/Interpreter/Expressions/JintYieldExpression.cs b/Jint/Runtime/Interpreter/Expressions/JintYieldExpression.cs index 5be08782f7..441501ad8c 100644 --- a/Jint/Runtime/Interpreter/Expressions/JintYieldExpression.cs +++ b/Jint/Runtime/Interpreter/Expressions/JintYieldExpression.cs @@ -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 @@ -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); } /*