File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ var evaluate1 = function ( ) {
2
+ ( function ( ) {
3
+ print ( eval ( "this" ) ) ;
4
+ } ) . call ( this ) ;
5
+ } ;
6
+
7
+ var evaluate2 = function ( ) {
8
+ var context = { } ;
9
+ ( function ( ) {
10
+ print ( eval ( "this" ) ) ;
11
+ } ) . call ( context ) ;
12
+ } ;
13
+
14
+ var evaluate3 = function ( context ) {
15
+ ( function ( ) {
16
+ print ( eval ( "this" ) ) ;
17
+ } ) . call ( context ) ;
18
+ } ;
Original file line number Diff line number Diff line change
1
+ package com .winterbe .java8 ;
2
+
3
+ import jdk .nashorn .api .scripting .NashornScriptEngine ;
4
+
5
+ import javax .script .ScriptEngineManager ;
6
+ import javax .script .ScriptException ;
7
+
8
+ /**
9
+ * @author Benjamin Winterberg
10
+ */
11
+ public class Nashorn8 {
12
+ public static void main (String [] args ) throws ScriptException , NoSuchMethodException {
13
+ NashornScriptEngine engine = (NashornScriptEngine ) new ScriptEngineManager ().getEngineByName ("nashorn" );
14
+ engine .eval ("load('res/nashorn8.js')" );
15
+
16
+ engine .invokeFunction ("evaluate1" );
17
+ engine .invokeFunction ("evaluate2" );
18
+ engine .invokeFunction ("evaluate3" , "Foobar" );
19
+ engine .invokeFunction ("evaluate3" , new Person ("John" , "Doe" ));
20
+ }
21
+
22
+ }
You can’t perform that action at this time.
0 commit comments