@@ -6,3 +6,71 @@ var Module = {
6
6
//preRun: [], // called before every run()
7
7
} ;
8
8
9
+ if ( typeof jQuery !== "undefined" ) { // for the web
10
+ jQuery ( function ( $ ) {
11
+ function output ( s ) {
12
+ var output = $ ( '#output' ) ;
13
+ output . val ( output . val ( ) + s + "\n" ) ;
14
+ }
15
+ function onOutput ( c ) {
16
+ var o = $ ( '#output' ) ;
17
+ o . val ( o . val ( ) + String . fromCharCode ( s ) ) ;
18
+ }
19
+ function onInput ( ) {
20
+ return null ;
21
+ }
22
+ Module . stdin = onInput ;
23
+ Module . stdout = onOutput ;
24
+ Module . stderr = onOutput ;
25
+ Module . print = output ;
26
+ Module . printErr = output ;
27
+ Module . exit = function exit ( status ) {
28
+ EXITSTATUS = status ;
29
+ STACKTOP = initialStackTop ;
30
+ throw new ExitStatus ( status ) ;
31
+ } ;
32
+
33
+ $ ( '#output' ) . val ( sessionStorage . getItem ( 'output' ) ) ;
34
+
35
+ $ ( '#eval' ) . click ( function ( ) {
36
+ sessionStorage . removeItem ( 'output' ) ;
37
+ $ ( '#output' ) . val ( '' ) ;
38
+ preloadStartTime = null ;
39
+ ABORT = false ;
40
+ try {
41
+ try { FS . unlink ( '/input' ) } catch ( e ) { }
42
+ FS . createDataFile ( '/' , 'input' , $ ( '#input' ) . val ( ) , true , true ) ;
43
+ Module . callMain ( [ '/input' ] ) ;
44
+ } catch ( err ) {
45
+ output ( err . message || err . toString ( ) ) ;
46
+ }
47
+ finally {
48
+ var src = encodeURIComponent ( $ ( '#input' ) . val ( ) ) ;
49
+ location . hash = src ;
50
+ }
51
+ } ) ;
52
+
53
+ var src = location . hash ;
54
+ if ( src ) {
55
+ $ ( '#input' ) . val ( decodeURIComponent ( src . slice ( 1 ) ) ) ;
56
+ $ ( '#eval' ) . trigger ( 'click' ) ;
57
+ }
58
+ else {
59
+ $ ( '#input' ) . val (
60
+ "use strict;\n" +
61
+ "use warnings;\n" +
62
+ "\n" +
63
+ "print \"Hello, perl.js!\\n\"\n" ) ;
64
+ Module . callMain ( [ '--version' ] )
65
+ }
66
+
67
+
68
+ // monky patch
69
+ Module . abort = abort = function abort ( text ) {
70
+ alert ( 'abort!' ) ;
71
+ sessionStorage . setItem ( 'output' , $ ( '#output' ) . val ( ) ) ;
72
+ window . location . reload ( ) ;
73
+ Module . exit ( 1 ) ;
74
+ } ;
75
+ } ) ;
76
+ }
0 commit comments