Skip to content

Commit 2a6cabb

Browse files
committed
tweaks
1 parent 2bc53d4 commit 2a6cabb

File tree

8 files changed

+19
-34
lines changed

8 files changed

+19
-34
lines changed

Jint.Tests.Test262/BuiltIns/GeneratorTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace Jint.Tests.Test262.BuiltIns
44
{
55
public class GeneratorTests : Test262Test
66
{
7-
[Theory(DisplayName = "built-ins\\GeneratorFunction", Skip = "TODO")]
7+
[Theory(DisplayName = "built-ins\\GeneratorFunction")]
88
[MemberData(nameof(SourceFiles), "built-ins\\GeneratorFunction", false)]
99
[MemberData(nameof(SourceFiles), "built-ins\\GeneratorFunction", true, Skip = "Skipped")]
1010
protected void GeneratorFunction(SourceFile sourceFile)

Jint/Native/Function/FunctionConstructor.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ internal FunctionInstance CreateDynamicFunction(
5454
FunctionKind kind,
5555
JsValue[] args)
5656
{
57-
/* TODO
58-
var callerContext = _engine.GetExecutionContext(1);
57+
// TODO var callerContext = _engine.GetExecutionContext(1);
58+
var callerContext = _engine.ExecutionContext;
5959
var callerRealm = callerContext.Realm;
60-
var calleeRealm = engine.ExecutionContext.Realm;
60+
var calleeRealm = _engine.ExecutionContext.Realm;
61+
6162
_engine._host.EnsureCanCompileStrings(callerRealm, calleeRealm);
62-
*/
6363

6464
if (newTarget.IsUndefined())
6565
{
@@ -191,7 +191,7 @@ internal FunctionInstance CreateDynamicFunction(
191191

192192
if (kind == FunctionKind.Generator)
193193
{
194-
var prototype = OrdinaryObjectCreate(_realm.Intrinsics.GeneratorFunction.PrototypeObject.Prototype);
194+
var prototype = OrdinaryObjectCreate(_realm.Intrinsics.GeneratorFunction.PrototypeObject.PrototypeObject);
195195
F.DefinePropertyOrThrow(CommonProperties.Prototype, new PropertyDescriptor(prototype, PropertyFlag.Writable));
196196
}
197197
else if (kind == FunctionKind.AsyncGenerator)

Jint/Native/Function/ScriptFunctionInstance.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ internal ScriptFunctionInstance(
4141
_prototype = proto ?? _engine.Realm.Intrinsics.Function.PrototypeObject;
4242
_length = new LazyPropertyDescriptor(null, _ => JsNumber.Create(function.Initialize(this).Length), PropertyFlag.Configurable);
4343

44-
if (!function.Strict && !engine._isStrict && function.Function is not ArrowFunctionExpression)
44+
if (!function.Strict
45+
&& !engine._isStrict
46+
&& function.Function is not ArrowFunctionExpression
47+
&& !function.Function.Generator)
4548
{
4649
DefineOwnProperty(CommonProperties.Arguments, engine._callerCalleeArgumentsThrowerConfigurable);
4750
DefineOwnProperty(CommonProperties.Caller, new PropertyDescriptor(Undefined, PropertyFlag.Configurable));
@@ -103,7 +106,8 @@ public override JsValue Call(JsValue thisArgument, JsValue[] arguments)
103106

104107
internal override bool IsConstructor =>
105108
(_homeObject.IsUndefined() || _isClassConstructor)
106-
&& _functionDefinition?.Function is not ArrowFunctionExpression;
109+
&& _functionDefinition?.Function is not ArrowFunctionExpression
110+
&& _functionDefinition?.Function.Generator != true;
107111

108112
/// <summary>
109113
/// https://tc39.es/ecma262/#sec-ecmascript-function-objects-construct-argumentslist-newtarget

Jint/Native/Generator/GeneratorFunctionPrototype.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ public sealed class GeneratorFunctionPrototype : ObjectInstance
1414
{
1515
private readonly GeneratorFunctionConstructor _constructor;
1616

17-
internal GeneratorFunctionPrototype(Engine engine,
17+
internal GeneratorFunctionPrototype(
18+
Engine engine,
1819
GeneratorFunctionConstructor constructor,
1920
FunctionPrototype prototype,
2021
IteratorPrototype iteratorPrototype) : base(engine)
@@ -30,7 +31,7 @@ protected override void Initialize()
3031
{
3132
var properties = new PropertyDictionary(2, checkExistingKeys: false)
3233
{
33-
["constructor"] = new PropertyDescriptor(_constructor, PropertyFlag.NonEnumerable),
34+
["constructor"] = new PropertyDescriptor(_constructor, PropertyFlag.Configurable),
3435
["prototype"] = new PropertyDescriptor(PrototypeObject, PropertyFlag.Configurable)
3536
};
3637
SetProperties(properties);

Jint/Native/Generator/GeneratorInstance.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,10 @@ private JsValue ResumeExecution(ExecutionContext genContext, EvaluationContext c
100100
}
101101
else if (result.Type == CompletionType.Return)
102102
{
103-
resultValue = new IteratorInstance.ValueIteratorPosition(_engine, result.Value, _generatorBody.Completed);
103+
resultValue = new IteratorInstance.ValueIteratorPosition(_engine, result.Value, false);
104104
if (_generatorBody.Completed)
105105
{
106106
_generatorState = GeneratorState.Completed;
107-
resultValue.Set(CommonProperties.Done, JsBoolean.True);
108107
}
109108
}
110109

Jint/Native/Global/GlobalObject.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ protected override void Initialize()
3333
const PropertyFlag lengthFlags = PropertyFlag.Configurable;
3434
const PropertyFlag propertyFlags = PropertyFlag.Configurable | PropertyFlag.Writable;
3535

36-
var properties = new PropertyDictionary(54, checkExistingKeys: false)
36+
var properties = new PropertyDictionary(55, checkExistingKeys: false)
3737
{
3838
["Object"] = new PropertyDescriptor(_realm.Intrinsics.Object, propertyFlags),
3939
["Function"] = new PropertyDescriptor(_realm.Intrinsics.Function, propertyFlags),
@@ -53,6 +53,7 @@ protected override void Initialize()
5353
["BigUint64Array"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.BigUint64Array, propertyFlags),
5454
["Float32Array"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.Float32Array, propertyFlags),
5555
["Float64Array"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.Float64Array, propertyFlags),
56+
["GeneratorFunction"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.GeneratorFunction, propertyFlags),
5657
["Map"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.Map, propertyFlags),
5758
["Set"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.Set, propertyFlags),
5859
["WeakMap"] = new LazyPropertyDescriptor(this, static state => ((GlobalObject) state)._realm.Intrinsics.WeakMap, propertyFlags),

Jint/Runtime/Interpreter/Expressions/JintAssignmentExpression.cs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ internal static JintExpression Build(Engine engine, AssignmentExpression express
2828
return new BindingPatternAssignmentExpression(expression);
2929
}
3030

31-
if (expression.Right is YieldExpression)
32-
{
33-
return new YieldAssignmentExpression(expression);
34-
}
35-
3631
return new SimpleAssignmentExpression(expression);
3732
}
3833

@@ -385,19 +380,5 @@ private ExpressionResult SetValue(EvaluationContext context)
385380
return null;
386381
}
387382
}
388-
389-
private sealed class YieldAssignmentExpression : JintExpression
390-
{
391-
public YieldAssignmentExpression(AssignmentExpression expression) : base(expression)
392-
{
393-
throw new System.NotImplementedException();
394-
}
395-
396-
protected override ExpressionResult EvaluateInternal(EvaluationContext context)
397-
{
398-
ExceptionHelper.ThrowNotImplementedException();
399-
return default;
400-
}
401-
}
402383
}
403384
}

Jint/Runtime/Interpreter/Expressions/JintYieldExpression.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using Esprima.Ast;
22
using Jint.Native;
33
using Jint.Native.Generator;
4-
using Jint.Native.Iterator;
54
using Jint.Native.Object;
65

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

41-
return new Completion(CompletionType.Return, Yield(new IteratorResult(engine, value, JsBoolean.False)), _expression.Location);
40+
return new ExpressionResult(ExpressionCompletionType.Return, Yield(value), _expression.Location);
4241
}
4342

4443
/*

0 commit comments

Comments
 (0)