From 0fb3d536561646882bdec0ae925317c5d29285a4 Mon Sep 17 00:00:00 2001 From: Luis Pina Date: Mon, 6 Jul 2020 16:13:19 -0500 Subject: [PATCH] Added tests for pending issues --- .../javascript/tests/Issue645Test.java | 48 +++++++++++++++++ .../javascript/tests/Issue662Test.java | 52 ++++++++++++++++++ .../javascript/tests/Issue663Test.java | 53 +++++++++++++++++++ 3 files changed, 153 insertions(+) create mode 100644 testsrc/org/mozilla/javascript/tests/Issue645Test.java create mode 100644 testsrc/org/mozilla/javascript/tests/Issue662Test.java create mode 100644 testsrc/org/mozilla/javascript/tests/Issue663Test.java diff --git a/testsrc/org/mozilla/javascript/tests/Issue645Test.java b/testsrc/org/mozilla/javascript/tests/Issue645Test.java new file mode 100644 index 0000000000..c6f207037f --- /dev/null +++ b/testsrc/org/mozilla/javascript/tests/Issue645Test.java @@ -0,0 +1,48 @@ +/* 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; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.mozilla.javascript.Context; +import org.mozilla.javascript.Scriptable; + +import static org.junit.Assert.assertEquals; + +public class Issue645Test { + private Scriptable m_scope; + + @Before + public void init() { + Context cx = Context.enter(); + cx.setOptimizationLevel(-1); + m_scope = cx.initStandardObjects(); + } + + @After + public void cleanup() { + Context.exit(); + } + + private void test(String testCode, Object expected) { + Object result = null; + try{ + result = eval(testCode); + } catch(Exception e) { + result = "EXCEPTIONCAUGHT"; + } + + assertEquals(expected, result); + } + + private Object eval(String source) { + Context cx = Context.getCurrentContext(); + return cx.evaluateString(m_scope, source, "source", 1, null); + + } + + @Test + public void testIssue662() { test( "for(({});;){ }", null); } +} diff --git a/testsrc/org/mozilla/javascript/tests/Issue662Test.java b/testsrc/org/mozilla/javascript/tests/Issue662Test.java new file mode 100644 index 0000000000..034ac65420 --- /dev/null +++ b/testsrc/org/mozilla/javascript/tests/Issue662Test.java @@ -0,0 +1,52 @@ +/* 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; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.mozilla.javascript.Context; +import org.mozilla.javascript.EcmaError; +import org.mozilla.javascript.Scriptable; +import org.mozilla.javascript.Undefined; + +import static org.junit.Assert.assertEquals; + +public class Issue662Test { + private Scriptable m_scope; + + @Before + public void init() { + Context cx = Context.enter(); + cx.setOptimizationLevel(-1); + m_scope = cx.initStandardObjects(); + } + + @After + public void cleanup() { + Context.exit(); + } + + private void test(String testCode, Object expected) { + Object result = null; + try{ + result = eval(testCode); + } catch(Exception e) { + result = "EXCEPTIONCAUGHT"; + } + + assertEquals(expected, result); + } + + private Object eval(String source) { + Context cx = Context.getCurrentContext(); + return cx.evaluateString(m_scope, source, "source", 1, null); + + } + + @Test + public void testIssue662() { + test( "[\"\".h]=y", null); + } +} diff --git a/testsrc/org/mozilla/javascript/tests/Issue663Test.java b/testsrc/org/mozilla/javascript/tests/Issue663Test.java new file mode 100644 index 0000000000..eb4464701e --- /dev/null +++ b/testsrc/org/mozilla/javascript/tests/Issue663Test.java @@ -0,0 +1,53 @@ +/* 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; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.mozilla.javascript.Context; +import org.mozilla.javascript.EcmaError; +import org.mozilla.javascript.Scriptable; + +import static org.junit.Assert.assertEquals; + +public class Issue663Test { + private Scriptable m_scope; + + @Before + public void init() { + Context cx = Context.enter(); + cx.setOptimizationLevel(-1); + m_scope = cx.initStandardObjects(); + } + + @After + public void cleanup() { + Context.exit(); + } + + private void test(String testCode, Object expected) { + Object result = null; + try{ + result = eval(testCode); + } catch(EcmaError e) { + // Expected + } catch(Exception e) { + result = "EXCEPTIONCAUGHT"; + } + + assertEquals(expected, result); + } + + private Object eval(String source) { + Context cx = Context.getCurrentContext(); + return cx.evaluateString(m_scope, source, "source", 1, null); + + } + + @Test + public void testIssue663() { + test("\\u000a:S<6", null); + } +}