-
-
Notifications
You must be signed in to change notification settings - Fork 547
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix some prototype chain issues uncovered by compat-table
- Loading branch information
Showing
22 changed files
with
1,064 additions
and
958 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 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 |
---|---|---|
@@ -1,14 +1,47 @@ | ||
using Jint.Runtime; | ||
|
||
namespace Jint.Tests.Runtime | ||
namespace Jint.Tests.Runtime; | ||
|
||
public class MapTests | ||
{ | ||
public class MapTests | ||
[Fact] | ||
public void ShouldThrowWhenCalledWithoutNew() | ||
{ | ||
[Fact] | ||
public void ShouldThrowWhenCalledWithoutNew() | ||
{ | ||
var e = Assert.Throws<JavaScriptException>(() => new Engine().Execute("const m = new Map(); Map.call(m,[]);")); | ||
Assert.Equal("Constructor Map requires 'new'", e.Message); | ||
} | ||
var e = Assert.Throws<JavaScriptException>(() => new Engine().Execute("const m = new Map(); Map.call(m,[]);")); | ||
Assert.Equal("Constructor Map requires 'new'", e.Message); | ||
} | ||
|
||
[Fact] | ||
public void NegativeZeroKeyConvertsToPositiveZero() | ||
{ | ||
const string Script = @" | ||
var map = new Map(); | ||
map.set(-0, ""foo""); | ||
var k; | ||
map.forEach(function (value, key) { | ||
k = 1 / key; | ||
}); | ||
return k === Infinity && map.get(+0) === ""foo"";"; | ||
|
||
Assert.True(new Engine().Evaluate(Script).AsBoolean()); | ||
} | ||
|
||
[Fact] | ||
public void HasProperIteratorPrototypeChain() | ||
{ | ||
const string Script = @" | ||
// Iterator instance | ||
var iterator = new Map()[Symbol.iterator](); | ||
// %MapIteratorPrototype% | ||
var proto1 = Object.getPrototypeOf(iterator); | ||
// %IteratorPrototype% | ||
var proto2 = Object.getPrototypeOf(proto1);"; | ||
|
||
var engine = new Engine(); | ||
engine.Execute(Script); | ||
Assert.True(engine.Evaluate("proto2.hasOwnProperty(Symbol.iterator)").AsBoolean()); | ||
Assert.True(engine.Evaluate("!proto1.hasOwnProperty(Symbol.iterator)").AsBoolean()); | ||
Assert.True(engine.Evaluate("!iterator.hasOwnProperty(Symbol.iterator)").AsBoolean()); | ||
Assert.True(engine.Evaluate("iterator[Symbol.iterator]() === iterator").AsBoolean()); | ||
} | ||
} |
Oops, something went wrong.