Permalink
Browse files

Fix Bootstrap's version of KeyValuePair having no fields. Fixes issue #…

  • Loading branch information...
1 parent 3b35f42 commit d685f5b430601507a61fb16f079ee9b60f7a2c4b @kg kg committed Jul 18, 2012
Showing with 29 additions and 2 deletions.
  1. +10 −1 Libraries/JSIL.Bootstrap.js
  2. +1 −0 Tests/ComparisonTests.cs
  3. +16 −0 Tests/TestCases/DictionaryKeyValuePairs.cs
  4. +2 −1 Tests/Tests.csproj
@@ -3306,7 +3306,7 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2", function ($)
function GetEnumerator () {
var dict = this._dict;
var tKvp = System.Collections.Generic.KeyValuePair$b2.Of(this.TKey, this.TValue);
- var current = new tKvp(null, null);
+ var tKey = this.TKey, tValue = this.TValue;
return new JSIL.AbstractEnumerator(
function getNext (result) {
@@ -3319,6 +3319,7 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2", function ($)
var bucket = dict[bucketKey];
if ((valueIndex >= 0) && (valueIndex < bucket.length)) {
+ var current = this._state.current;
current.key = bucket[valueIndex][0];
current.value = bucket[valueIndex][1];
result.value = current;
@@ -3333,6 +3334,7 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2", function ($)
},
function reset () {
this._state = {
+ current: new tKvp(JSIL.DefaultValue(tKey), JSIL.DefaultValue(tValue)),
keys: Object.keys(dict),
bucketIndex: 0,
valueIndex: -1
@@ -3406,6 +3408,13 @@ JSIL.ImplementExternals("System.Collections.Generic.KeyValuePair`2", function ($
});
JSIL.MakeStruct("System.ValueType", "System.Collections.Generic.KeyValuePair`2", true, ["TKey", "TValue"], function ($) {
+ $.Field({Static:false, Public:false}, "key", $.GenericParameter("TKey"));
+
+ $.Field({Static:false, Public:false}, "value", $.GenericParameter("TValue"));
+
+ $.Property({Static:false, Public:true }, "Key");
+
+ $.Property({Static:false, Public:true }, "Value");
});
JSIL.MakeClass("System.Object", "System.Collections.Generic.Dictionary`2", true, ["TKey", "TValue"], function ($) {
@@ -213,6 +213,7 @@ public class ComparisonTests : GenericTestFixture {
@"TestCases\Dictionary.cs",
@"TestCases\DictionaryInitializer.cs",
@"TestCases\DictionaryEnumerator.cs",
+ @"TestCases\DictionaryKeyValuePairs.cs",
}, MakeDefaultProvider(), new AssemblyCache()
);
}
@@ -0,0 +1,16 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+
+public static class Program {
+ public static void Main (string[] args) {
+ Dictionary<string, string> dict = new Dictionary<string, string>();
+
+ dict.Add("key1", "value1");
+ dict.Add("key2", "value2");
+
+ foreach (var kvp in dict) {
+ Console.WriteLine(kvp);
+ }
+ }
+}
View
@@ -195,7 +195,8 @@
<None Include="SimpleTestCases\TruncationRoundToZero.cs" />
<None Include="SimpleTestCases\StringRemove.cs" />
<None Include="SimpleTestCases\ArrayDefaultValues2.cs" />
- <None Include="SimpleTestCases\IntegerToString.cs" />
+ <None Include="SimpleTestCases\IntegerToStringNullFormat.cs" />
+ <None Include="TestCases\DictionaryKeyValuePairs.cs" />
<Compile Include="XMLTests.cs" />
<Compile Include="DependencyTests.cs" />
<None Include="TestCases\GenericParameterNameShadowing.cs" />

0 comments on commit d685f5b

Please sign in to comment.