another map fix
diff --git a/src/org/mozilla/javascript/NativeMap.java b/src/org/mozilla/javascript/NativeMap.java index 4752436e..bcc7ef2 100644 --- a/src/org/mozilla/javascript/NativeMap.java +++ b/src/org/mozilla/javascript/NativeMap.java
@@ -207,7 +207,13 @@ throw ScriptRuntime.typeError1("msg.arg.not.object", ScriptRuntime.typeof(sVal)); } Object finalKey = sVal.get(0, sVal); + if (finalKey == NOT_FOUND) { + finalKey = Undefined.instance; + } Object finalVal = sVal.get(1, sVal); + if (finalVal == NOT_FOUND) { + finalVal = Undefined.instance; + } set.call(cx, scope, map, new Object[] { finalKey, finalVal }); } }
diff --git a/testsrc/jstests/es6/map.js b/testsrc/jstests/es6/map.js new file mode 100644 index 0000000..b154eb5 --- /dev/null +++ b/testsrc/jstests/es6/map.js
@@ -0,0 +1,37 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +load("testsrc/assert.js"); + +res = ""; + +function logElement(value, key, m) { + res += "map[" + key + "] = '" + value + "' "; +} + +(function TestForEach() { + res = "a) "; + var myMap = new Map([['key1', 'value1'], ['key2', 17]]); + myMap.forEach(logElement); + + assertEquals("a) map[key1] = 'value1' map[key2] = '17' ", res); +})(); + +(function TestForEachNoKey() { + res = "b) "; + var myMap = new Map([['', 'value1'], [, 17], [undefined, 18], [null, 19]]); + myMap.forEach(logElement); + + assertEquals("b) map[] = 'value1' map[undefined] = '18' map[null] = '19' ", res); +})(); + +(function TestForEachNoValue() { + res = "c) "; + var myMap = new Map([['key1', ''], ['key2',], ['key3', undefined], ['key4', null]]); + myMap.forEach(logElement); + + assertEquals("c) map[key1] = '' map[key2] = 'undefined' map[key3] = 'undefined' map[key4] = 'null' ", res); +})(); + +"success"; \ No newline at end of file
diff --git a/testsrc/org/mozilla/javascript/tests/es6/NativeMapTest.java b/testsrc/org/mozilla/javascript/tests/es6/NativeMapTest.java new file mode 100644 index 0000000..3029474 --- /dev/null +++ b/testsrc/org/mozilla/javascript/tests/es6/NativeMapTest.java
@@ -0,0 +1,16 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package org.mozilla.javascript.tests.es6; + +import org.mozilla.javascript.Context; +import org.mozilla.javascript.drivers.LanguageVersion; +import org.mozilla.javascript.drivers.RhinoTest; +import org.mozilla.javascript.drivers.ScriptTestsBase; + +@RhinoTest("testsrc/jstests/es6/map.js") +@LanguageVersion(Context.VERSION_ES6) +public class NativeMapTest extends ScriptTestsBase +{ +}