提交 3814c7cc 编写于 作者: S sundar

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
上级 af9d07b8
......@@ -223,7 +223,9 @@ public final class RhinoScriptEngine extends AbstractScriptEngine
} 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 @@ public final class RhinoScriptEngine extends AbstractScriptEngine
" 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" +
......
......@@ -107,7 +107,7 @@ public abstract class CompiledScript {
}
/**
* 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>
......
/*
* 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);
}
}
};
/*
* 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());
}
};
/*
* 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+/=]/;");
}
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册