OpenJDK / portola / portola
changeset 7991:96cdf8806d96
6508943: small typo in the documentation
6759414: javascript engine can not write to StringWriter
6869617: RhinoScriptEngine bug : ScriptException cause not set (with fix)
7012701: Add a test to check that Rhino's RegExp parser accepts unescaped '['
Reviewed-by: alanb, jjh
author | sundar |
---|---|
date | Mon, 17 Jan 2011 13:29:12 +0530 |
parents | 57019dc81b66 |
children | 42ed82f1c067 |
files | jdk/src/share/classes/com/sun/script/javascript/RhinoScriptEngine.java jdk/src/share/classes/javax/script/CompiledScript.java jdk/test/javax/script/CauseExceptionTest.java jdk/test/javax/script/StringWriterPrintTest.java jdk/test/javax/script/UnescapedBracketRegExTest.java |
diffstat | 5 files changed, 139 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/jdk/src/share/classes/com/sun/script/javascript/RhinoScriptEngine.java Fri Jan 14 15:31:45 2011 -0800 +++ b/jdk/src/share/classes/com/sun/script/javascript/RhinoScriptEngine.java Mon Jan 17 13:29:12 2011 +0530 @@ -223,7 +223,9 @@ } catch (RhinoException re) { if (DEBUG) re.printStackTrace(); int line = (line = re.lineNumber()) == 0 ? -1 : line; - throw new ScriptException(re.toString(), re.sourceName(), line); + ScriptException se = new ScriptException(re.toString(), re.sourceName(), line); + se.initCause(re); + throw se; } finally { cx.exit(); } @@ -257,6 +259,8 @@ " str = 'null'; \n" + " } \n" + " var out = context.getWriter(); \n" + + " if (!(out instanceof java.io.PrintWriter))\n" + + " out = new java.io.PrintWriter(out); \n" + " out.print(String(str)); \n" + " if (newline) out.print('\\n'); \n" + " out.flush(); \n" +
--- a/jdk/src/share/classes/javax/script/CompiledScript.java Fri Jan 14 15:31:45 2011 -0800 +++ b/jdk/src/share/classes/javax/script/CompiledScript.java Mon Jan 17 13:29:12 2011 +0530 @@ -107,7 +107,7 @@ } /** - * Returns the <code>ScriptEngine</code> wbose <code>compile</code> method created this <code>CompiledScript</code>. + * Returns the <code>ScriptEngine</code> whose <code>compile</code> method created this <code>CompiledScript</code>. * The <code>CompiledScript</code> will execute in this engine. * * @return The <code>ScriptEngine</code> that created this <code>CompiledScript</code>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/javax/script/CauseExceptionTest.java Mon Jan 17 13:29:12 2011 +0530 @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 6869617 + * @summary RhinoScriptEngine bug : ScriptException cause not set (with fix) + */ + +import javax.script.*; +import java.io.*; + +public class CauseExceptionTest { + public static void main(String[] args) throws ScriptException, NoSuchMethodException { + ScriptEngineManager sem = new ScriptEngineManager(); + ScriptEngine engine = sem.getEngineByName("js"); + engine.eval("function hello_world() { println('hello world'); throw 'out of here'; } "); + Invocable invocable = (Invocable) engine; + try { + invocable.invokeFunction("hello_world", (Object[])null); + } catch (ScriptException se) { + Throwable cause = se.getCause(); + if (cause == null) { + throw new RuntimeException("null cause"); + } + System.out.println(cause); + } + } +};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/javax/script/StringWriterPrintTest.java Mon Jan 17 13:29:12 2011 +0530 @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 6759414 + * @summary javascript engine can not write to StringWriter. + */ + +import javax.script.*; +import java.io.*; + +public class StringWriterPrintTest { + public static void main(String[] args) throws ScriptException { + ScriptEngineManager sem = new ScriptEngineManager(); + ScriptEngine engine = sem.getEngineByName("js"); + StringWriter sw = new StringWriter(); + engine.eval("print(\"hello world 1\\n\")"); + engine.getContext().setWriter(sw); + // the following "print" call throws exception + engine.eval("print(\"hello world 2\\n\")"); + System.out.println(sw.toString()); + } +};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/javax/script/UnescapedBracketRegExTest.java Mon Jan 17 13:29:12 2011 +0530 @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 7012701 + * @summary 7012701 Add a test to check that Rhino's RegExp parser accepts unescaped '[' + */ + +import javax.script.*; +import java.io.*; + +public class UnescapedBracketRegExTest { + public static void main(String[] args) throws ScriptException { + ScriptEngineManager sem = new ScriptEngineManager(); + ScriptEngine engine = sem.getEngineByName("js"); + // the following throws exception + engine.eval("var x = /[a-zA-Z+/=]/;"); + } +};