-
-
Notifications
You must be signed in to change notification settings - Fork 560
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade test262 suite and fix issues
* create shims for async generators * add initial version of Math.sumPrecise which won't pass all the tests (insane as usual) * harmonize function expression building
- Loading branch information
Showing
13 changed files
with
592 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
Jint/Native/AsyncGenerator/AsyncGeneratorFunctionConstructor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using Jint.Native.AsyncFunction; | ||
using Jint.Native.Function; | ||
using Jint.Native.Iterator; | ||
using Jint.Native.Object; | ||
using Jint.Runtime; | ||
using Jint.Runtime.Descriptors; | ||
|
||
namespace Jint.Native.Generator; | ||
|
||
/// <summary> | ||
/// https://tc39.es/ecma262/#sec-asyncgeneratorfunction-constructor | ||
/// </summary> | ||
internal sealed class AsyncGeneratorFunctionConstructor : Constructor | ||
{ | ||
private static readonly JsString _functionName = new("AsyncGeneratorFunction"); | ||
|
||
internal AsyncGeneratorFunctionConstructor( | ||
Engine engine, | ||
Realm realm, | ||
AsyncFunctionPrototype prototype, | ||
IteratorPrototype iteratorPrototype) | ||
: base(engine, realm, _functionName) | ||
{ | ||
PrototypeObject = new AsyncGeneratorFunctionPrototype(engine, this, prototype, iteratorPrototype); | ||
_prototype = PrototypeObject; | ||
_prototypeDescriptor = new PropertyDescriptor(PrototypeObject, PropertyFlag.AllForbidden); | ||
_length = new PropertyDescriptor(JsNumber.PositiveOne, PropertyFlag.Configurable); | ||
} | ||
|
||
public AsyncGeneratorFunctionPrototype PrototypeObject { get; } | ||
|
||
protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments) | ||
{ | ||
return Construct(arguments, thisObject); | ||
} | ||
|
||
public override ObjectInstance Construct(JsValue[] arguments, JsValue newTarget) | ||
{ | ||
var function = _realm.Intrinsics.Function.CreateDynamicFunction( | ||
this, | ||
newTarget, | ||
FunctionKind.AsyncGenerator, | ||
arguments); | ||
|
||
return function; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
Jint/Native/AsyncGenerator/AsyncGeneratorFunctionPrototype.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using Jint.Collections; | ||
using Jint.Native.AsyncFunction; | ||
using Jint.Native.Iterator; | ||
using Jint.Native.Symbol; | ||
using Jint.Runtime; | ||
using Jint.Runtime.Descriptors; | ||
|
||
namespace Jint.Native.Generator; | ||
|
||
/// <summary> | ||
/// https://tc39.es/ecma262/#sec-properties-of-asyncgeneratorfunction-prototype | ||
/// </summary> | ||
internal sealed class AsyncGeneratorFunctionPrototype : Prototype | ||
{ | ||
private readonly AsyncGeneratorFunctionConstructor? _constructor; | ||
|
||
internal AsyncGeneratorFunctionPrototype( | ||
Engine engine, | ||
AsyncGeneratorFunctionConstructor constructor, | ||
AsyncFunctionPrototype prototype, | ||
IteratorPrototype iteratorPrototype) : base(engine, engine.Realm) | ||
{ | ||
_constructor = constructor; | ||
_prototype = prototype; | ||
PrototypeObject = new AsyncGeneratorPrototype(engine, this, iteratorPrototype); | ||
} | ||
|
||
public AsyncGeneratorPrototype PrototypeObject { get; } | ||
|
||
protected override void Initialize() | ||
{ | ||
var properties = new PropertyDictionary(2, checkExistingKeys: false) | ||
{ | ||
[KnownKeys.Constructor] = new PropertyDescriptor(_constructor, PropertyFlag.Configurable), | ||
[KnownKeys.Prototype] = new PropertyDescriptor(PrototypeObject, PropertyFlag.Configurable) | ||
}; | ||
SetProperties(properties); | ||
var symbols = new SymbolDictionary(1) | ||
{ | ||
[GlobalSymbolRegistry.ToStringTag] = new PropertyDescriptor("AsyncGeneratorFunction", PropertyFlag.Configurable) | ||
}; | ||
SetSymbols(symbols); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
using Jint.Collections; | ||
using Jint.Native.Iterator; | ||
using Jint.Native.Object; | ||
using Jint.Native.Symbol; | ||
using Jint.Runtime; | ||
using Jint.Runtime.Descriptors; | ||
using Jint.Runtime.Interop; | ||
|
||
namespace Jint.Native.Generator; | ||
|
||
/// <summary> | ||
/// https://tc39.es/ecma262/#sec-asyncgenerator-objects | ||
/// </summary> | ||
internal sealed class AsyncGeneratorPrototype : ObjectInstance | ||
{ | ||
private readonly AsyncGeneratorFunctionPrototype _constructor; | ||
|
||
internal AsyncGeneratorPrototype( | ||
Engine engine, | ||
AsyncGeneratorFunctionPrototype constructor, | ||
IteratorPrototype iteratorPrototype) : base(engine) | ||
{ | ||
_constructor = constructor; | ||
_prototype = iteratorPrototype; | ||
} | ||
|
||
protected override void Initialize() | ||
{ | ||
const PropertyFlag PropertyFlags = PropertyFlag.Configurable | PropertyFlag.Writable; | ||
const PropertyFlag LengthFlags = PropertyFlag.Configurable; | ||
var properties = new PropertyDictionary(4, false) | ||
{ | ||
["constructor"] = new(_constructor, PropertyFlag.Configurable), | ||
["next"] = new(new ClrFunction(Engine, "next", Next, 1, LengthFlags), PropertyFlags), | ||
["return"] = new(new ClrFunction(Engine, "return", Return, 1, LengthFlags), PropertyFlags), | ||
["throw"] = new(new ClrFunction(Engine, "throw", Throw, 1, LengthFlags), PropertyFlags) | ||
}; | ||
SetProperties(properties); | ||
|
||
var symbols = new SymbolDictionary(1) | ||
{ | ||
[GlobalSymbolRegistry.ToStringTag] = new("Generator", PropertyFlag.Configurable) | ||
}; | ||
SetSymbols(symbols); | ||
} | ||
|
||
/// <summary> | ||
/// https://tc39.es/ecma262/#sec-generator.prototype.next | ||
/// </summary> | ||
private ObjectInstance Next(JsValue thisObject, JsValue[] arguments) | ||
{ | ||
var g = AssertGeneratorInstance(thisObject); | ||
var value = arguments.At(0, null!); | ||
return g.GeneratorResume(value, null); | ||
} | ||
|
||
/// <summary> | ||
/// https://tc39.es/ecma262/#sec-generator.prototype.return | ||
/// </summary> | ||
private JsValue Return(JsValue thisObject, JsValue[] arguments) | ||
{ | ||
var g = AssertGeneratorInstance(thisObject); | ||
var value = arguments.At(0); | ||
var C = new Completion(CompletionType.Return, value, null!); | ||
return g.GeneratorResumeAbrupt(C, null); | ||
} | ||
|
||
/// <summary> | ||
/// https://tc39.es/ecma262/#sec-generator.prototype.throw | ||
/// </summary> | ||
private JsValue Throw(JsValue thisObject, JsValue[] arguments) | ||
{ | ||
var g = AssertGeneratorInstance(thisObject); | ||
var exception = arguments.At(0); | ||
var C = new Completion(CompletionType.Throw, exception, null!); | ||
return g.GeneratorResumeAbrupt(C, null); | ||
} | ||
|
||
private GeneratorInstance AssertGeneratorInstance(JsValue thisObj) | ||
{ | ||
var generatorInstance = thisObj as GeneratorInstance; | ||
if (generatorInstance is null) | ||
{ | ||
ExceptionHelper.ThrowTypeError(_engine.Realm, "object must be a Generator instance"); | ||
} | ||
|
||
return generatorInstance; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.