Skip to content

Commit bc65316

Browse files
committed
reload the web page after abort()
1 parent fef1a27 commit bc65316

File tree

3 files changed

+70
-55
lines changed

3 files changed

+70
-55
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ PERL_GIT:=https://github.com/mirrors/perl.git
33
PERL_VERSION:=v5.18.1
44

55
all: microperl.js gen.modules.js
6+
echo '(function bootPerl() {' > perl.js
67
cat prelude.js >> perl.js
78
cat microperl.js >> perl.js
9+
echo '}());' >> perl.js
810
echo '#!/usr/bin/env node' > perl-cli.js
911
cat perl.js >> perl-cli.js
1012
chmod +x perl-cli.js

prelude.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,71 @@ var Module = {
66
//preRun: [], // called before every run()
77
};
88

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+
}

web/index.html

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -25,61 +25,6 @@
2525
</style>
2626
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
2727
<script src="perl.js"></script>
28-
<script>
29-
jQuery(function($) {
30-
function output(s) {
31-
var output = $('#output');
32-
output.val(output.val() + s + "\n");
33-
}
34-
function onOutput(c) {
35-
var o = $('#output');
36-
o.val(o.val() + String.fromCharCode(s));
37-
}
38-
function onInput() {
39-
return null;
40-
}
41-
Module.stdin = onInput;
42-
Module.stdout = onOutput;
43-
Module.stderr = onOutput;
44-
Module.print = output;
45-
Module.printErr = output;
46-
Module.exit = function exit(status) {
47-
EXITSTATUS = status;
48-
STACKTOP = initialStackTop;
49-
throw new ExitStatus(status);
50-
};
51-
52-
var src = location.hash;
53-
if (src) {
54-
$('#input').val(decodeURIComponent(src.slice(1)));
55-
}
56-
else {
57-
$('#input').val(
58-
"use strict;\n" +
59-
"use warnings;\n" +
60-
"\n" +
61-
"print \"Hello, perl.js!\\n\"\n");
62-
Module.callMain(['--version'])
63-
}
64-
65-
$('#eval').click(function() {
66-
$('#output').val('');
67-
preloadStartTime = null;
68-
ABORT = false;
69-
try {
70-
try { FS.unlink('/input') } catch (e) { }
71-
FS.createDataFile('/', 'input', $('#input').val(), true, true);
72-
Module.callMain(['/input'])
73-
} catch (err) {
74-
output(err.message || err.toString());
75-
}
76-
finally {
77-
var src = encodeURIComponent($('#input').val());
78-
location.hash = src;
79-
}
80-
});
81-
});
82-
</script>
8328
</head>
8429
<body>
8530

0 commit comments

Comments
 (0)