Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update generator and module/export/import related tests #978

Merged
merged 1 commit into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
23 changes: 23 additions & 0 deletions Jint.Tests.Test262/BuiltIns/GeneratorTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Xunit;

namespace Jint.Tests.Test262.BuiltIns
{
public class GeneratorTests : Test262Test
{
[Theory(DisplayName = "built-ins\\GeneratorFunction", Skip = "TODO")]
[MemberData(nameof(SourceFiles), "built-ins\\GeneratorFunction", false)]
[MemberData(nameof(SourceFiles), "built-ins\\GeneratorFunction", true, Skip = "Skipped")]
protected void GeneratorFunction(SourceFile sourceFile)
{
RunTestInternal(sourceFile);
}

[Theory(DisplayName = "built-ins\\GeneratorPrototype")]
[MemberData(nameof(SourceFiles), "built-ins\\GeneratorPrototype", false)]
[MemberData(nameof(SourceFiles), "built-ins\\GeneratorPrototype", true, Skip = "Skipped")]
protected void GeneratorPrototype(SourceFile sourceFile)
{
RunTestInternal(sourceFile);
}
}
}
31 changes: 31 additions & 0 deletions Jint.Tests.Test262/Language/ModuleTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Xunit;

namespace Jint.Tests.Test262.Language
{
public class ModuleTests : Test262Test
{
[Theory(DisplayName = "language\\module-code", Skip = "TODO")]
[MemberData(nameof(SourceFiles), "language\\module-code", false)]
[MemberData(nameof(SourceFiles), "language\\module-code", true, Skip = "Skipped")]
protected void ModuleCode(SourceFile sourceFile)
{
RunTestInternal(sourceFile);
}

[Theory(DisplayName = "language\\export")]
[MemberData(nameof(SourceFiles), "language\\export", false)]
[MemberData(nameof(SourceFiles), "language\\export", true, Skip = "Skipped")]
protected void Export(SourceFile sourceFile)
{
RunTestInternal(sourceFile);
}

[Theory(DisplayName = "language\\import", Skip = "TODO")]
[MemberData(nameof(SourceFiles), "language\\import", false)]
[MemberData(nameof(SourceFiles), "language\\import", true, Skip = "Skipped")]
protected void Import(SourceFile sourceFile)
{
RunTestInternal(sourceFile);
}
}
}
8 changes: 7 additions & 1 deletion Jint.Tests.Test262/Test262Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,15 @@ protected void RunTestCode(string fileName, string code, bool strict)
var includes = Regex.Match(code, @"includes: \[(.+?)\]");
if (includes.Success)
{
var files = includes.Groups[1].Captures[0].Value.Split(',');
var files = includes.Groups[1].Captures[0].Value.Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);
foreach (var file in files)
{
if (file == "hidden-constructors.js")
{
// suite refers to non-existent file
continue;
}

engine.Execute(Sources[file.Trim()]);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-properties-of-the-generatorfunction-constructor
es6id: 25.2.2
description: Object extensibility
info: |
The value of the [[Extensible]] internal slot of the GeneratorFunction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-generatorfunction
es6id: 25.2.1.1
description: Definition of instance `length` property
info: |
[...]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-generatorfunction
es6id: 25.2.1.1
description: Definition of instance `prototype` property
info: |
[...]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-generatorfunction
es6id: 25.2.1.1
description: Definition of instance `length` property
info: |
[...]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description: >
When invoked via the function invocation pattern with multiple arguments,
the GeneratorFunction intrinsic creates a valid generator whose body is the
last argument evaluated as source code and whose formal parameters are
defined by the preceeding arguments.
defined by the preceding arguments.
features: [generators]
---*/

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-ecmascript-standard-built-in-objects
description: >
The GeneratorFunction constructor implements [[Construct]]
info: |
IsConstructor ( argument )

The abstract operation IsConstructor takes argument argument (an ECMAScript language value).
It determines if argument is a function object with a [[Construct]] internal method.
It performs the following steps when called:

If Type(argument) is not Object, return false.
If argument has a [[Construct]] internal method, return true.
Return false.
includes: [isConstructor.js, hidden-constructors.js]
features: [Reflect.construct]
---*/

assert.sameValue(isConstructor(GeneratorFunction), true, 'isConstructor(GeneratorFunction) must return true');
new GeneratorFunction();

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-generatorfunction.length
es6id: 25.2.2.1
description: >
This is a data property with a value of 1. This property has the attributes {
[[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-properties-of-the-generatorfunction-constructor
es6id: 25.2.2
description: Function "name" property
info: |
The value of the name property of the GeneratorFunction is
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright (C) 2020 Alexey Shvayka. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-createdynamicfunction
description: >
While default [[Prototype]] value derives from realm of the newTarget,
"prototype" object inherits from %Object.prototype% of constructor's realm.
info: |
GeneratorFunction ( p1, p2, … , pn, body )

[...]
3. Return ? CreateDynamicFunction(C, NewTarget, generator, args).

CreateDynamicFunction ( constructor, newTarget, kind, args )

[...]
18. Let proto be ? GetPrototypeFromConstructor(newTarget, fallbackProto).
19. Let realmF be the current Realm Record.
20. Let scope be realmF.[[GlobalEnv]].
21. Let F be ! OrdinaryFunctionCreate(proto, parameters, body, non-lexical-this, scope).
[...]
23. If kind is generator, then
a. Let prototype be OrdinaryObjectCreate(%Generator.prototype%).
b. Perform DefinePropertyOrThrow(F, "prototype", PropertyDescriptor { [[Value]]: prototype,
[[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }).
[...]
30. Return F.
features: [generators, cross-realm, Reflect]
---*/

var realmA = $262.createRealm().global;
realmA.calls = 0;
var aGeneratorFunction = realmA.eval("(function* () {})").constructor;
var aGeneratorPrototype = Object.getPrototypeOf(
realmA.eval("(function* () {})").prototype
);

var realmB = $262.createRealm().global;
var bGeneratorFunction = realmB.eval("(function* () {})").constructor;
var newTarget = new realmB.Function();
newTarget.prototype = null;

var fn = Reflect.construct(aGeneratorFunction, ["calls += 1;"], newTarget);
assert.sameValue(Object.getPrototypeOf(fn), bGeneratorFunction.prototype);
assert.sameValue(Object.getPrototypeOf(fn.prototype), aGeneratorPrototype);

var gen = fn();
assert(gen instanceof realmA.Object);
gen.next();
assert.sameValue(realmA.calls, 1);
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-generatorfunction
es6id: 25.2.1.1
description: Default [[Prototype]] value derived from realm of the newTarget
info: |
[...]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-generatorfunction.prototype.constructor
es6id: 25.2.3.1
description: >
`constructor` property of the GeneratorFunction.prototype object
info: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-properties-of-the-generatorfunction-prototype-object
es6id: 25.2.3
description: Object extensibility
info: |
The initial value of the [[Extensible]] internal slot of the
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (C) 2020 Alexey Shvayka. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-properties-of-the-generatorfunction-prototype-object
description: >
%GeneratorFunction.prototype% is an ordinary non-callable object.
info: |
Properties of the GeneratorFunction Prototype Object

The GeneratorFunction prototype object:

[...]
* is an ordinary object.
* is not a function object and does not have an [[ECMAScriptCode]] internal slot
or any other of the internal slots listed in Table 28 or Table 74.
features: [generators]
---*/

var GeneratorFunctionPrototype = Object.getPrototypeOf(function* () {});

assert.sameValue(typeof GeneratorFunctionPrototype, "object");
assert.throws(TypeError, function() {
GeneratorFunctionPrototype();
});

assert(!GeneratorFunctionPrototype.hasOwnProperty("length"), "length");
assert(!GeneratorFunctionPrototype.hasOwnProperty("name"), "name");
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-generatorvalidate
es6id: 25.3.3.2
description: >
A TypeError should be thrown if the generator is resumed while in the
"executing" state and the generator should be marked as "completed"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-ecmascript-standard-built-in-objects
description: >
Object.getPrototypeOf((function* g() {}).prototype).next does not implement [[Construct]], is not new-able
info: |
ECMAScript Function Objects

Built-in function objects that are not identified as constructors do not
implement the [[Construct]] internal method unless otherwise specified in
the description of a particular function.

sec-evaluatenew

...
7. If IsConstructor(constructor) is false, throw a TypeError exception.
...
includes: [isConstructor.js]
features: [Reflect.construct, generators, arrow-function]
---*/

assert.sameValue(
isConstructor(Object.getPrototypeOf((function* g() {}).prototype).next),
false,
'isConstructor(Object.getPrototypeOf((function* g() {}).prototype).next) must return false'
);

assert.throws(TypeError, () => {
function* g() {} let iterator = g(); new iterator.next();
}, '`function* g() {} let iterator = g(); new iterator.next()` throws TypeError');

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-generator.prototype.next
es6id: 25.3.1.2
description: >
A TypeError should be thrown from GeneratorValidate (25.3.3.2) if the
context of `next` does not define the [[GeneratorState]] internal slot.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-generator.prototype.next
es6id: 25.3.1.2
description: >
A TypeError should be thrown from GeneratorValidate (25.3.3.2) if the "this"
value of `next` is not an object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-generatorvalidate
es6id: 25.3.3.2
description: >
A TypeError should be thrown if the generator is in the "executing" state,
and the generator should be marked as "completed"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-ecmascript-standard-built-in-objects
description: >
Object.getPrototypeOf((function* g() {}).prototype).return does not implement [[Construct]], is not new-able
info: |
ECMAScript Function Objects

Built-in function objects that are not identified as constructors do not
implement the [[Construct]] internal method unless otherwise specified in
the description of a particular function.

sec-evaluatenew

...
7. If IsConstructor(constructor) is false, throw a TypeError exception.
...
includes: [isConstructor.js]
features: [Reflect.construct, generators, arrow-function]
---*/

assert.sameValue(
isConstructor(Object.getPrototypeOf((function* g() {}).prototype).return),
false,
'isConstructor(Object.getPrototypeOf((function* g() {}).prototype).return) must return false'
);

assert.throws(TypeError, () => {
function* g() {} let iterator = g(); new iterator.return();
}, '`function* g() {} let iterator = g(); new iterator.return()` throws TypeError');

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-generator.prototype.return
es6id: 25.3.1.3
description: >
A TypeError should be thrown from GeneratorValidate (25.3.3.2) if the
context of `return` does not define the [[GeneratorState]] internal slot.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-generator.prototype.return
es6id: 25.3.1.3
description: >
A TypeError should be thrown from GeneratorValidate (25.3.3.2) if the "this"
value of `return` is not an object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-generatorvalidate
es6id: 25.3.3.2
description: >
A TypeError should be thrown if the generator is in the "executing" state,
and the generator should be marked as "completed"
Expand Down
Loading