1010import java .nio .charset .StandardCharsets ;
1111import javax .script .ScriptContext ;
1212import org .mozilla .javascript .Context ;
13- import org .mozilla .javascript .Function ;
1413import org .mozilla .javascript .ScriptRuntime ;
1514import org .mozilla .javascript .Scriptable ;
1615import org .mozilla .javascript .ScriptableObject ;
16+ import org .mozilla .javascript .Undefined ;
1717
1818/**
1919 * This class defines the following built-in functions for the RhinoScriptEngine.
@@ -36,21 +36,28 @@ void register(Context cx, ScriptableObject scope, ScriptContext sc) {
3636 stdout = sc .getWriter ();
3737 }
3838
39- scope .defineFunctionProperties (
40- new String [] {"print" },
41- Builtins .class ,
42- ScriptableObject .PERMANENT | ScriptableObject .DONTENUM );
39+ scope .defineProperty (
40+ scope ,
41+ "print" ,
42+ 0 ,
43+ Builtins ::print ,
44+ ScriptableObject .PERMANENT | ScriptableObject .DONTENUM ,
45+ ScriptableObject .DONTENUM | ScriptableObject .READONLY );
4346 }
4447
45- public static void print (Context cx , Scriptable thisObj , Object [] args , Function f )
46- throws IOException {
47- Builtins self = getSelf (thisObj );
48- for (Object arg : args ) {
49- self .stdout .write (ScriptRuntime .toString (arg ));
48+ private static Object print (Context cx , Scriptable scope , Scriptable thisObj , Object [] args ) {
49+ try {
50+ Builtins self = getSelf (thisObj );
51+ for (Object arg : args ) {
52+ self .stdout .write (ScriptRuntime .toString (arg ));
53+ }
54+ self .stdout .write ('\n' );
55+ // ref bug https://github.com/mozilla/rhino/issues/1356
56+ self .stdout .flush ();
57+ } catch (IOException e ) {
58+ throw Context .throwAsScriptRuntimeEx (e );
5059 }
51- self .stdout .write ('\n' );
52- // ref bug https://github.com/mozilla/rhino/issues/1356
53- self .stdout .flush ();
60+ return Undefined .instance ;
5461 }
5562
5663 private static Builtins getSelf (Scriptable scope ) {
0 commit comments