-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
96a5e18
commit 39c59c0
Showing
6 changed files
with
92 additions
and
5 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { dedent } from '../utils.js'; | ||
import { io, stdio } from './_utils.js'; | ||
|
||
const type = 'php-wasm'; | ||
|
||
// TODO: almost nothing is implemented | ||
|
||
// REQUIRES INTEGRATION TEST | ||
/* c8 ignore start */ | ||
export default { | ||
type, | ||
module: (version = '0.0.3') => `https://cdn.jsdelivr.net/npm/@webreflection/php@${version}/es.js`, | ||
async engine({ PhpWeb }, _, url) { | ||
const { stderr, get } = stdio(); | ||
const interpreter = await new Promise(resolve => { | ||
let timer = 0, chunks = []; | ||
const php = new PhpWeb({ | ||
print: (message) => { | ||
chunks.push(message); | ||
clearTimeout(timer); | ||
timer = setTimeout(() => { | ||
document.getElementById('target').innerHTML = chunks.splice(0).join(''); | ||
}); | ||
}, | ||
printErr: (message) => { | ||
if (message) stderr(message); | ||
}, | ||
locateFile: () => `${url.slice(0, url.lastIndexOf('/'))}/php-web.wasm` | ||
}); | ||
php.addEventListener('ready', () => { | ||
resolve(get(php)); | ||
}); | ||
}); | ||
// TODO: to be implemented | ||
// if (config.files) await fetchFiles(this, interpreter, config.files); | ||
// if (config.fetch) await fetchPaths(this, interpreter, config.fetch); | ||
return interpreter; | ||
}, | ||
// Fallback to globally defined module fields | ||
registerJSModule: () => { | ||
// TODO: to be implemented | ||
}, | ||
run: (interpreter, code, ...args) => { | ||
// TODO: this is always async | ||
try { | ||
return interpreter.run(`<?php ${dedent(code)} ?>`, ...args); | ||
} | ||
catch (error) { | ||
io.get(interpreter).stderr(error); | ||
} | ||
}, | ||
runAsync: async (interpreter, code, ...args) => { | ||
try { | ||
return await interpreter.run(`<?php ${dedent(code)} ?>`, ...args); | ||
} | ||
catch (error) { | ||
io.get(interpreter).stderr(error); | ||
} | ||
}, | ||
runEvent: async () => { | ||
// TODO: to be implemented | ||
throw new SyntaxError('runEvent are not implemented'); | ||
}, | ||
transform: (_, value) => value, | ||
writeFile: () => { | ||
// TODO: to be implemented | ||
throw new SyntaxError('writeFile is not implemented'); | ||
}, | ||
}; | ||
/* c8 ignore stop */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width,initial-scale=1.0" /> | ||
<title>PHP</title> | ||
<link rel="stylesheet" href="style.css" /> | ||
<script type="module" src="../core.js"></script> | ||
</head> | ||
<body> | ||
<script type="php-wasm"> | ||
phpinfo(); | ||
</script> | ||
<div id="target"></div> | ||
</body> | ||
</html> |