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

Module support fixes and improvements #1102

Merged
merged 31 commits into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a1114df
Module handling fixes and improvements
lahma Mar 5, 2022
dcc405d
fix GetOwnPropertyKeys
lahma Mar 5, 2022
fac21f5
Identify module in parsing error messages
christianrondeau Mar 5, 2022
2e3f6ae
Remove Execute/Evaluate a module from script
christianrondeau Mar 6, 2022
dc2f1c9
Enrich error messages to identify source module
christianrondeau Mar 6, 2022
f3aab62
Correctly inner link, add failing test for cyclic
christianrondeau Mar 6, 2022
e5d2968
Fix Test262Test not providing root module path
christianrondeau Mar 6, 2022
941286f
Fix indirect renamed exports not added to module requests
christianrondeau Mar 6, 2022
15b6f01
Fix indirect renamed exports resolution
christianrondeau Mar 6, 2022
a655f0c
Prevent writing to namespace object
christianrondeau Mar 7, 2022
e8863ec
Always run module tests in strict mode
christianrondeau Mar 7, 2022
273439c
Fix indirect export resolve name
christianrondeau Mar 7, 2022
306a72c
Rename JsModule to ModuleRecord to match ecmascript specs
christianrondeau Mar 7, 2022
637702a
Extract base ModuleRecord from CyclicModuleRecord to match ecmascript…
christianrondeau Mar 7, 2022
99af4a8
Use abstract ModuleRecord or ScriptOrModule to better match ecmascript
christianrondeau Mar 7, 2022
bdf3cce
Extract SourceTextModuleRecord from CyclicModuleRecord to better matc…
christianrondeau Mar 7, 2022
adc222c
Support recursive cyclic modules
christianrondeau Mar 7, 2022
967188f
Fix inversed renamed export implementation
christianrondeau Mar 7, 2022
377a8ad
Fix incorrect use of local vs import name in export entries
christianrondeau Mar 7, 2022
1497e37
Fix two star imports conflicting not considered ambiguous
christianrondeau Mar 8, 2022
3414313
Import bindings should be initialized as immutable undefined
christianrondeau Mar 8, 2022
4863368
Export default function assign function name "default"
christianrondeau Mar 8, 2022
d99f285
Allow coercion of primitives to objects during assignments in strict …
christianrondeau Mar 8, 2022
2089eea
Remove useless strict assignement property check (fixed elsewhere)
christianrondeau Mar 8, 2022
0d404ea
Skip generator tests in module tests (not implemented)
christianrondeau Mar 8, 2022
0bce4ae
Fix named exports incorrectly bound by the declaration
christianrondeau Mar 9, 2022
4013603
Fix skipped module-code gen tests
christianrondeau Mar 9, 2022
5520bae
Re-enable skipped module tests and add builder function overloads
christianrondeau Mar 9, 2022
a27cc0e
Add skipped test for dynamic import
christianrondeau Mar 9, 2022
256e54d
dynamic import
christianrondeau Mar 9, 2022
21da8d9
remove LINQ from HoistingScope, add missing Fact attribute, small cle…
lahma Mar 9, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
51 changes: 0 additions & 51 deletions Jint.Tests.Test262/Language/ModuleTestHost.cs

This file was deleted.

49 changes: 3 additions & 46 deletions Jint.Tests.Test262/Language/ModuleTests.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using Jint.Runtime;
using Jint.Runtime.Modules;
using System;
using System.IO;
using System.Reflection;
using Xunit;
using Xunit.Sdk;

namespace Jint.Tests.Test262.Language;

Expand All @@ -15,59 +9,22 @@ public class ModuleTests : Test262Test
[MemberData(nameof(SourceFiles), "language\\module-code", true, Skip = "Skipped")]
protected void ModuleCode(SourceFile sourceFile)
{
RunModuleTest(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)
{
RunModuleTest(sourceFile);
RunTestInternal(sourceFile);
}

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

private static void RunModuleTest(SourceFile sourceFile)
{
if (sourceFile.Skip)
{
return;
}

var code = sourceFile.Code;

var options = new Options();
options.Host.Factory = _ => new ModuleTestHost();
options.EnableModules(Path.Combine(BasePath, "test"));

var engine = new Engine(options);

var negative = code.IndexOf("negative:", StringComparison.OrdinalIgnoreCase) != -1;
string lastError = null;

try
{
engine.LoadModule(sourceFile.FullPath);
}
catch (JavaScriptException ex)
{
lastError = ex.ToString();
}
catch (Exception ex)
{
lastError = ex.ToString();
}

if (!negative && !string.IsNullOrWhiteSpace(lastError))
{
throw new XunitException(lastError);
}
RunTestInternal(sourceFile);
}
}
4 changes: 2 additions & 2 deletions Jint.Tests.Test262/SingleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ public void TestSingle()

if (code.IndexOf("onlyStrict", StringComparison.Ordinal) < 0)
{
RunTestCode(sourceFile.Source, code, strict: false);
RunTestCode(sourceFile.Source, code, strict: false, null);
}

if (code.IndexOf("noStrict", StringComparison.Ordinal) < 0)
{
RunTestCode(sourceFile.Source, code, strict: true);
RunTestCode(sourceFile.Source, code, strict: true, null);
}
}
}
Expand Down
35 changes: 26 additions & 9 deletions Jint.Tests.Test262/Test262Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public abstract class Test262Test

private static readonly HashSet<string> _strictSkips = new(StringComparer.OrdinalIgnoreCase);

private static readonly Regex _moduleFlagRegex = new Regex(@"flags:\s*?\[.*?module.*?]", RegexOptions.Compiled);

static Test262Test()
{
//NOTE: The Date tests in test262 assume the local timezone is Pacific Standard Time
Expand Down Expand Up @@ -96,12 +98,19 @@ static Test262Test()
}
}

protected void RunTestCode(string fileName, string code, bool strict)
protected void RunTestCode(string fileName, string code, bool strict, string fullPath)
{
var engine = new Engine(cfg => cfg
.LocalTimeZone(_pacificTimeZone)
.Strict(strict)
);
var module = _moduleFlagRegex.IsMatch(code);

var engine = new Engine(cfg =>
{
cfg.LocalTimeZone(_pacificTimeZone);
cfg.Strict(strict);
if (module)
{
cfg.EnableModules(Path.Combine(BasePath, "test", Path.GetDirectoryName(fullPath)!));
}
});

engine.Execute(Sources["sta.js"]);
engine.Execute(Sources["assert.js"]);
Expand Down Expand Up @@ -162,7 +171,15 @@ protected void RunTestCode(string fileName, string code, bool strict)
bool negative = code.IndexOf("negative:", StringComparison.Ordinal) > -1;
try
{
engine.Execute(new JavaScriptParser(code, new ParserOptions(fileName)).ParseScript());
if (module)
{
engine.AddModule(fullPath, builder => builder.AddSource(code));
engine.ImportModule(fullPath);
}
else
{
engine.Execute(new JavaScriptParser(code, new ParserOptions(fileName)).ParseScript());
}
}
catch (JavaScriptException j)
{
Expand All @@ -186,15 +203,15 @@ protected void RunTestInternal(SourceFile sourceFile)
return;
}

if (sourceFile.Code.IndexOf("onlyStrict", StringComparison.Ordinal) < 0)
if (sourceFile.Code.IndexOf("onlyStrict", StringComparison.Ordinal) < 0 && !_moduleFlagRegex.IsMatch(sourceFile.Code))
{
RunTestCode(sourceFile.Source, sourceFile.Code, strict: false);
RunTestCode(sourceFile.Source, sourceFile.Code, strict: false, fullPath: sourceFile.FullPath);
}

if (!_strictSkips.Contains(sourceFile.Source)
&& sourceFile.Code.IndexOf("noStrict", StringComparison.Ordinal) < 0)
{
RunTestCode(sourceFile.Source, sourceFile.Code, strict: true);
RunTestCode(sourceFile.Source, sourceFile.Code, strict: true, fullPath: sourceFile.FullPath);
}
}

Expand Down
8 changes: 8 additions & 0 deletions Jint.Tests.Test262/test/skipped.json
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,14 @@
"source": "language/statements/class/subclass/builtin-objects/GeneratorFunction/regular-subclassing.js",
"reason": "generators not implemented"
},
{
"source": "language/module-code/instn-local-bndng-export-gen.js",
"reason": "generators not implemented"
},
{
"source": "language/module-code/instn-local-bndng-gen.js",
"reason": "generators not implemented"
},

// Eval problems

Expand Down