Skip to content

Commit

Permalink
use d8 instead of node for js
Browse files Browse the repository at this point in the history
  • Loading branch information
SunriseFox committed Mar 30, 2019
1 parent 3809215 commit b0bd183
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 44 deletions.
4 changes: 2 additions & 2 deletions judgecore/conf/a.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"sid": 10001,
"filename": "main.cpp",
"lang": "c++",
"filename": "main.js",
"lang": "javascript",
"path": {
"base": null,
"code": null,
Expand Down
2 changes: 1 addition & 1 deletion judgecore/conf/c.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"debug": false,
"debug": true,
"path": {
"base": "/mnt/data/"
}
Expand Down
44 changes: 3 additions & 41 deletions judgecore/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,52 +595,13 @@ int compile_exec_cpp (json& j) {
}

int compile_exec_javascript (json& j) {
UNUSED(j);
if (debug)
cout << "language is javascript, skip compile" << endl;
ofstream script(path["exec"] + ".nodejs");
string s = R"+(const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false,
crlfDelay: Infinity,
});
const line = (async function* _readLine() {
for await (const line of rl) {
yield line;
}
})()
async function read() {
return (await line.next()).value
}
function write(data) {
process.stdout.write(data.toString())
}
function writeLine(data) {
process.stdout.write(data + '\n')
}
process.on('unhandledRejection', (reason, p) => {
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason)
process.exit(-1)
});
(async function main() {
)+"
+ readFile(path["code"]) +
R"+(
})().then(() => process.exit(0)))+";
script << s << endl;
script.close();

ofstream exec(path["exec"]);
exec << "#! /bin/bash\n";
exec << "exec node --no-warnings --max-old-space-size=" + to_string(j["max_memory"].get<int>() / 4000) + " " + path["exec"] + ".nodejs" << endl;
exec << "exec /usr/bin/v8/d8 " + path["code"] << endl;
exec.close();
return 0;
}
Expand Down Expand Up @@ -1483,6 +1444,7 @@ RESULT do_compare(json& j, const map<string, string>& extra) {
if (r == -1)
perror("fd_in");

unlink(extra["output"].c_str());
int fd_out = open(extra["output"].c_str(), O_WRONLY | O_CREAT | O_TRUNC);
if (r != -1) {
r = dup2(fd_out, STDOUT_FILENO);
Expand Down

0 comments on commit b0bd183

Please sign in to comment.