Skip to content

Commit

Permalink
Promise lets go again (#889)
Browse files Browse the repository at this point in the history
  • Loading branch information
twop committed May 13, 2021
1 parent 517900f commit 426aced
Show file tree
Hide file tree
Showing 379 changed files with 13,041 additions and 748 deletions.
15 changes: 15 additions & 0 deletions Jint.Tests.Test262/BuiltIns/PromiseTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Xunit;

namespace Jint.Tests.Test262.BuiltIns
{
public class PromiseTests : Test262Test
{
[Theory(DisplayName = "built-ins\\Promise")]
[MemberData(nameof(SourceFiles), "built-ins\\Promise", false)]
[MemberData(nameof(SourceFiles), "built-ins\\Promise", true, Skip = "Skipped")]
protected void Promise(SourceFile sourceFile)
{
RunTestInternal(sourceFile);
}
}
}
68 changes: 39 additions & 29 deletions Jint.Tests.Test262/Test262Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public abstract class Test262Test

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

static Test262Test()
{
//NOTE: The Date tests in test262 assume the local timezone is Pacific Standard Time
Expand All @@ -54,6 +54,7 @@ static Test262Test()
"assert.js",
"arrayContains.js",
"isConstructor.js",
"promiseHelper.js",
"propertyHelper.js",
"compareArray.js",
"decimalToHexString.js",
Expand Down Expand Up @@ -96,26 +97,28 @@ protected void RunTestCode(string code, bool strict)

engine.Execute(Sources["sta.js"], CreateParserOptions("sta.js"));
engine.Execute(Sources["assert.js"], CreateParserOptions("assert.js"));
engine.SetValue("print", new ClrFunctionInstance(engine, "print", (thisObj, args) => TypeConverter.ToString(args.At(0))));
engine.SetValue("print",
new ClrFunctionInstance(engine, "print", (thisObj, args) => TypeConverter.ToString(args.At(0))));

var o = engine.Object.Construct(Arguments.Empty);
o.FastSetProperty("evalScript", new PropertyDescriptor(new ClrFunctionInstance(engine, "evalScript", (thisObj, args) =>
{
if (args.Length > 1)
o.FastSetProperty("evalScript", new PropertyDescriptor(new ClrFunctionInstance(engine, "evalScript",
(thisObj, args) =>
{
throw new Exception("only script parsing supported");
}
if (args.Length > 1)
{
throw new Exception("only script parsing supported");
}
var options = new ParserOptions {AdaptRegexp = true, Tolerant = false};
var parser = new JavaScriptParser(args.At(0).AsString(), options);
var script = parser.ParseScript(strict);
var options = new ParserOptions { AdaptRegexp = true, Tolerant = false };
var parser = new JavaScriptParser(args.At(0).AsString(), options);
var script = parser.ParseScript(strict);
var value = engine.Execute(script).GetCompletionValue();
var value = engine.Execute(script).GetCompletionValue();
return value;
}), true, true, true));
return value;
}), true, true, true));
engine.SetValue("$262", o);

var includes = Regex.Match(code, @"includes: \[(.+?)\]");
if (includes.Success)
{
Expand All @@ -130,7 +133,7 @@ protected void RunTestCode(string code, bool strict)
{
engine.Execute(Sources["propertyHelper.js"], CreateParserOptions("propertyHelper.js"));
}

string lastError = null;

bool negative = code.IndexOf("negative:", StringComparison.Ordinal) > -1;
Expand Down Expand Up @@ -277,7 +280,7 @@ public static IEnumerable<object[]> SourceFiles(string pathPrefix, bool skipped)
}
}
}

if (code.IndexOf("SpecialCasing.txt") > -1)
{
skip = true;
Expand Down Expand Up @@ -307,49 +310,57 @@ public static IEnumerable<object[]> SourceFiles(string pathPrefix, bool skipped)
skip = true;
reason = "Promise not implemented";
}

if (name.StartsWith("language/statements/class/subclass/builtin-objects/TypedArray"))
{
skip = true;
reason = "TypedArray not implemented";
}

if (name.StartsWith("language/statements/class/subclass/builtin-objects/WeakMap"))
{
skip = true;
reason = "WeakMap not implemented";
}

if (name.StartsWith("language/statements/class/subclass/builtin-objects/WeakSet"))
{
skip = true;
reason = "WeakSet not implemented";
}

if (name.StartsWith("language/statements/class/subclass/builtin-objects/ArrayBuffer/"))
{
skip = true;
reason = "ArrayBuffer not implemented";
}

if (name.StartsWith("language/statements/class/subclass/builtin-objects/DataView"))
{
skip = true;
reason = "DataView not implemented";
}

if (name.StartsWith("language/statements/class/subclass/builtins.js"))
{
skip = true;
reason = "Uint8Array not implemented";
}

if (name.StartsWith("built-ins/RegExp/CharacterClassEscapes/"))
{
skip = true;
reason = "for-of not implemented";
}

// Promises
if (name.StartsWith("built-ins/Promise/allSettled") ||
name.StartsWith("built-ins/Promise/any"))
{
skip = true;
reason = "Promise.any and Promise.allSettled are not implemented yet";
}

if (file.EndsWith("tv-line-continuation.js")
|| file.EndsWith("tv-line-terminator-sequence.js")
|| file.EndsWith("special-characters.js"))
Expand All @@ -376,20 +387,19 @@ public static IEnumerable<object[]> SourceFiles(string pathPrefix, bool skipped)

return results;
}
private static ParserOptions CreateParserOptions(string fileName) =>

private static ParserOptions CreateParserOptions(string fileName) =>
new ParserOptions(fileName)
{
AdaptRegexp = true,
Tolerant = true
};
}

public class SourceFile : IXunitSerializable
{
public SourceFile()
{

}

public SourceFile(
Expand Down Expand Up @@ -435,4 +445,4 @@ public override string ToString()
return Source;
}
}
}
}
139 changes: 81 additions & 58 deletions Jint.Tests.Test262/harness/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,86 +3,109 @@
/*---
description: |
Collection of assertion functions used throughout test262
defines: [assert]
---*/


function assert(mustBeTrue, message) {
if (mustBeTrue === true) {
return;
}

if (message === undefined) {
message = 'Expected true but got ' + String(mustBeTrue);
}
$ERROR(message);
if (mustBeTrue === true) {
return;
}

if (message === undefined) {
message = 'Expected true but got ' + assert._toString(mustBeTrue);
}
$ERROR(message);
}

assert._isSameValue = function (a, b) {
if (a === b) {
// Handle +/-0 vs. -/+0
return a !== 0 || 1 / a === 1 / b;
}
if (a === b) {
// Handle +/-0 vs. -/+0
return a !== 0 || 1 / a === 1 / b;
}

// Handle NaN vs. NaN
return a !== a && b !== b;
// Handle NaN vs. NaN
return a !== a && b !== b;
};

assert.sameValue = function (actual, expected, message) {
if (assert._isSameValue(actual, expected)) {
return;
}
try {
if (assert._isSameValue(actual, expected)) {
return;
}
} catch (error) {
$ERROR(message + ' (_isSameValue operation threw) ' + error);
return;
}

if (message === undefined) {
message = '';
} else {
message += ' ';
}
if (message === undefined) {
message = '';
} else {
message += ' ';
}

message += 'Expected SameValue(«' + String(actual) + '», «' + String(expected) + '») to be true';
message += 'Expected SameValue(«' + assert._toString(actual) + '», «' + assert._toString(expected) + '») to be true';

$ERROR(message);
$ERROR(message);
};

assert.notSameValue = function (actual, unexpected, message) {
if (!assert._isSameValue(actual, unexpected)) {
return;
}
if (!assert._isSameValue(actual, unexpected)) {
return;
}

if (message === undefined) {
message = '';
} else {
message += ' ';
}
if (message === undefined) {
message = '';
} else {
message += ' ';
}

message += 'Expected SameValue(«' + String(actual) + '», «' + String(unexpected) + '») to be false';
message += 'Expected SameValue(«' + assert._toString(actual) + '», «' + assert._toString(unexpected) + '») to be false';

$ERROR(message);
$ERROR(message);
};

assert.throws = function (expectedErrorConstructor, func, message) {
if (typeof func !== "function") {
$ERROR('assert.throws requires two arguments: the error constructor ' +
'and a function to run');
return;
}
if (message === undefined) {
message = '';
} else {
message += ' ';
}

try {
func();
} catch (thrown) {
if (typeof thrown !== 'object' || thrown === null) {
message += 'Thrown value was not an object!';
$ERROR(message);
} else if (thrown.constructor !== expectedErrorConstructor) {
message += 'Expected a ' + expectedErrorConstructor.name + ' but got a ' + thrown.constructor.name;
$ERROR(message);
if (typeof func !== "function") {
$ERROR('assert.throws requires two arguments: the error constructor ' +
'and a function to run');
return;
}
if (message === undefined) {
message = '';
} else {
message += ' ';
}

try {
func();
} catch (thrown) {
if (typeof thrown !== 'object' || thrown === null) {
message += 'Thrown value was not an object!';
$ERROR(message);
} else if (thrown.constructor !== expectedErrorConstructor) {
message += 'Expected a ' + expectedErrorConstructor.name + ' but got a ' + thrown.constructor.name;
$ERROR(message);
}
return;
}
return;
}

message += 'Expected a ' + expectedErrorConstructor.name + ' to be thrown but no exception was thrown at all';
$ERROR(message);
message += 'Expected a ' + expectedErrorConstructor.name + ' to be thrown but no exception was thrown at all';
$ERROR(message);
};

assert._toString = function (value) {
try {
if (value === 0 && 1 / value === -Infinity) {
return '-0';
}

return String(value);
} catch (err) {
if (err.name === 'TypeError') {
return Object.prototype.toString.call(value);
}

throw err;
}
};
17 changes: 11 additions & 6 deletions Jint.Tests.Test262/harness/sta.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,26 @@
/*---
description: |
Provides both:
- An error class to avoid false positives when testing for thrown exceptions
- A function to explicitly throw an exception using the Test262Error class
defines: [Test262Error, $ERROR, $DONOTEVALUATE]
---*/


function Test262Error(message) {
this.message = message || "";
this.message = message || "";
}

Test262Error.prototype.toString = function () {
return "Test262Error: " + this.message;
return "Test262Error: " + this.message;
};

var $ERROR;
$ERROR = function $ERROR(message) {
throw new Test262Error(message);
Test262Error.thrower = (...args) => {
throw new Test262Error(...args);
};

var $ERROR = Test262Error.thrower;

function $DONOTEVALUATE() {
throw "Test262: This statement should not be evaluated.";
}

0 comments on commit 426aced

Please sign in to comment.