mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-04-24 22:57:58 +00:00
Add web worker compatibility
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Web Worker Example</title>
|
||||
<style>
|
||||
/* Ensure the pre tag wraps long lines */
|
||||
pre {
|
||||
white-space: pre-wrap; /* Wrap long lines */
|
||||
word-wrap: break-word; /* Break long words */
|
||||
max-width: 100%; /* Optional: Ensures it doesn't overflow container */
|
||||
overflow-wrap: break-word; /* Another method for wrapping */
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Revive Compilation Output</h1>
|
||||
<pre id="output"></pre>
|
||||
<script>
|
||||
var outputElement = document.getElementById('output');
|
||||
var worker = new Worker('./worker.js');
|
||||
worker.addEventListener('message', function (e) {
|
||||
const output = e.data.output
|
||||
outputElement.textContent = output;
|
||||
}, false);
|
||||
|
||||
worker.postMessage({
|
||||
contractCode: 'contract C { function f() public { } }',
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../../../target/wasm32-unknown-emscripten/release/resolc.js
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../../../target/wasm32-unknown-emscripten/release/resolc.wasm
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,52 @@
|
||||
|
||||
importScripts('./soljson.js');
|
||||
importScripts('./resolc.js');
|
||||
|
||||
// Handle messages from the main thread
|
||||
onmessage = async function (e) {
|
||||
const contractCode = e.data.contractCode
|
||||
const sourceCode = {
|
||||
language: 'Solidity',
|
||||
sources: {
|
||||
contract: {
|
||||
content: contractCode,
|
||||
}
|
||||
},
|
||||
settings: {
|
||||
optimizer: {
|
||||
enabled: true,
|
||||
runs: 200,
|
||||
},
|
||||
outputSelection: {
|
||||
'*': {
|
||||
'*': ['abi'],
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
const m = createRevive();
|
||||
|
||||
m.soljson = Module;
|
||||
|
||||
// Set input data for stdin
|
||||
m.setStdinData(JSON.stringify(sourceCode));
|
||||
|
||||
var stdoutString = "";
|
||||
m.setStdoutCallback(function(char) {
|
||||
if (char.charCodeAt(0) === '\n') {
|
||||
console.log("new line")
|
||||
exit
|
||||
}
|
||||
stdoutString += char;
|
||||
});
|
||||
|
||||
var stderrString = "";
|
||||
m.setStderrCallback(function(char) {
|
||||
stderrString += char;
|
||||
});
|
||||
|
||||
// Compile the Solidity source code
|
||||
m.callMain(['--standard-json']);
|
||||
|
||||
postMessage({output: stdoutString || stderrString});
|
||||
};
|
||||
Reference in New Issue
Block a user