mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-14 01:51:03 +00:00
JS: Fix encoding conversion from utf16 to utf8 (#131)
This commit is contained in:
committed by
GitHub
parent
2cb8f82266
commit
afe44ad21b
@@ -15,3 +15,4 @@ tmp
|
|||||||
package-lock.json
|
package-lock.json
|
||||||
/*.html
|
/*.html
|
||||||
/build
|
/build
|
||||||
|
soljson.js
|
||||||
|
|||||||
@@ -1,18 +1,21 @@
|
|||||||
.PHONY: install format test test-solidity test-cli test-integration test-workspace clean docs docs-build
|
.PHONY: install format test test-solidity test-cli test-integration test-workspace clean docs docs-build
|
||||||
|
|
||||||
RUSTFLAGS_EMSCRIPTEN := \
|
RUSTFLAGS_EMSCRIPTEN := \
|
||||||
-Clink-arg=-sEXPORTED_FUNCTIONS=_main,_free,_malloc \
|
-C link-arg=-sEXPORTED_FUNCTIONS=_main,_free,_malloc \
|
||||||
-Clink-arg=-sNO_INVOKE_RUN \
|
-C link-arg=-sNO_INVOKE_RUN=1 \
|
||||||
-Clink-arg=-sEXIT_RUNTIME \
|
-C link-arg=-sEXIT_RUNTIME=1 \
|
||||||
-Clink-arg=-sINITIAL_MEMORY=64MB \
|
-C link-arg=-sALLOW_MEMORY_GROWTH=1 \
|
||||||
-Clink-arg=-sTOTAL_MEMORY=3GB \
|
-C link-arg=-sEXPORTED_RUNTIME_METHODS=FS,callMain,stringToNewUTF8 \
|
||||||
-Clink-arg=-sALLOW_MEMORY_GROWTH \
|
-C link-arg=-sMODULARIZE=1 \
|
||||||
-Clink-arg=-sEXPORTED_RUNTIME_METHODS=FS,callMain,stringToNewUTF8,cwrap \
|
-C link-arg=-sEXPORT_NAME=createRevive \
|
||||||
-Clink-arg=-sMODULARIZE \
|
-C link-arg=-sWASM_ASYNC_COMPILATION=0 \
|
||||||
-Clink-arg=-sEXPORT_NAME=createRevive \
|
-C link-arg=-sDYNAMIC_EXECUTION=0 \
|
||||||
-Clink-arg=-sWASM_ASYNC_COMPILATION=0 \
|
-C link-arg=-sALLOW_TABLE_GROWTH=1 \
|
||||||
-Clink-arg=--js-library=js/embed/soljson_interface.js \
|
-C link-arg=--js-library=js/embed/soljson_interface.js \
|
||||||
-Clink-arg=--pre-js=js/embed/pre.js
|
-C link-arg=--pre-js=js/embed/pre.js \
|
||||||
|
-C link-arg=-sNODEJS_CATCH_EXIT=0 \
|
||||||
|
-C link-arg=-sDISABLE_EXCEPTION_CATCHING=0 \
|
||||||
|
-C opt-level=3
|
||||||
|
|
||||||
install: install-bin install-npm
|
install: install-bin install-npm
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -8,4 +8,5 @@ To create a new pre-release:
|
|||||||
2. Push a release tag to `main`
|
2. Push a release tag to `main`
|
||||||
3. Manually trigger the `Build revive-debian` action
|
3. Manually trigger the `Build revive-debian` action
|
||||||
4. Create a __pre-release__ from the tag and manually upload the build artifact generated by the action
|
4. Create a __pre-release__ from the tag and manually upload the build artifact generated by the action
|
||||||
5. Update the [contract-docs](https://github.com/paritytech/contract-docs/) accordingly
|
5. Manually upload `resolc.js` and `resolc.wasm` from the `build-revive-wasm` action artifacts.
|
||||||
|
6. Update the [contract-docs](https://github.com/paritytech/contract-docs/) accordingly
|
||||||
|
|||||||
+26
-21
@@ -1,47 +1,52 @@
|
|||||||
var Module = {
|
var Module = {
|
||||||
stdinData: "",
|
stdinData: null,
|
||||||
stdoutCallback: null,
|
stdinDataPosition: 0,
|
||||||
stderrCallback: null,
|
stdoutData: [],
|
||||||
|
stderrData: [],
|
||||||
|
|
||||||
// Function to set a callback for stdout
|
// Function to read and return all collected stdout data as a string
|
||||||
setStdoutCallback: function(callback) {
|
readFromStdout: function() {
|
||||||
this.stdoutCallback = callback;
|
if (!this.stdoutData.length) return "";
|
||||||
|
const decoder = new TextDecoder('utf-8');
|
||||||
|
const data = decoder.decode(new Uint8Array(this.stdoutData));
|
||||||
|
this.stdoutData = [];
|
||||||
|
return data;
|
||||||
},
|
},
|
||||||
|
|
||||||
// Function to set a callback for stderr
|
// Function to read and return all collected stderr data as a string
|
||||||
setStderrCallback: function(callback) {
|
readFromStderr: function() {
|
||||||
this.stderrCallback = callback;
|
if (!this.stderrData.length) return "";
|
||||||
|
const decoder = new TextDecoder('utf-8');
|
||||||
|
const data = decoder.decode(new Uint8Array(this.stderrData));
|
||||||
|
this.stderrData = [];
|
||||||
|
return data;
|
||||||
},
|
},
|
||||||
|
|
||||||
// Function to set input data for stdin
|
// Function to set input data for stdin
|
||||||
setStdinData: function(data) {
|
writeToStdin: function(data) {
|
||||||
this.stdinData = data;
|
const encoder = new TextEncoder();
|
||||||
|
this.stdinData = encoder.encode(data);
|
||||||
|
this.stdinDataPosition = 0;
|
||||||
},
|
},
|
||||||
|
|
||||||
// `preRun` is called before the program starts running
|
// `preRun` is called before the program starts running
|
||||||
preRun: function() {
|
preRun: function() {
|
||||||
// Define a custom stdin function
|
// Define a custom stdin function
|
||||||
function customStdin() {
|
function customStdin() {
|
||||||
if (Module.stdinData.length === 0) {
|
if (!Module.stdinData || Module.stdinDataPosition >= Module.stdinData.length) {
|
||||||
return null; // End of input (EOF)
|
return null; // End of input (EOF)
|
||||||
}
|
}
|
||||||
const char = Module.stdinData.charCodeAt(0);
|
return Module.stdinData[Module.stdinDataPosition++];
|
||||||
Module.stdinData = Module.stdinData.slice(1); // Remove the character from input
|
|
||||||
return char;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define a custom stdout function
|
// Define a custom stdout function
|
||||||
function customStdout(char) {
|
function customStdout(char) {
|
||||||
if (Module.stdoutCallback) {
|
Module.stdoutData.push(char);
|
||||||
Module.stdoutCallback(String.fromCharCode(char));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define a custom stderr function
|
// Define a custom stderr function
|
||||||
function customStderr(char) {
|
function customStderr(char) {
|
||||||
if (Module.stderrCallback) {
|
Module.stderrData.push(char);
|
||||||
Module.stderrCallback(String.fromCharCode(char));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FS.init(customStdin, customStdout, customStderr);
|
FS.init(customStdin, customStdout, customStderr);
|
||||||
|
|||||||
@@ -24,28 +24,17 @@ mergeInto(LibraryManager.library, {
|
|||||||
} else {
|
} else {
|
||||||
throw new Error('Unknown environment: Unable to load resolc.js');
|
throw new Error('Unknown environment: Unable to load resolc.js');
|
||||||
}
|
}
|
||||||
revive.setStdinData(inputJson);
|
revive.writeToStdin(inputJson);
|
||||||
|
|
||||||
let stdoutString = "";
|
|
||||||
revive.setStdoutCallback(function(char) {
|
|
||||||
if (char.charCodeAt(0) === '\n') {
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
stdoutString += char;
|
|
||||||
});
|
|
||||||
|
|
||||||
let stderrString = "";
|
|
||||||
revive.setStderrCallback(function(char) {
|
|
||||||
stderrString += char;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Call main on the new instance
|
// Call main on the new instance
|
||||||
const result = revive.callMain(['--recursive-process']);
|
const result = revive.callMain(['--recursive-process']);
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
|
const stderrString = revive.readFromStderr();
|
||||||
const error = JSON.stringify({ type: 'error', message: stderrString || "Unknown error" });
|
const error = JSON.stringify({ type: 'error', message: stderrString || "Unknown error" });
|
||||||
return stringToNewUTF8(error);
|
return stringToNewUTF8(error);
|
||||||
} else {
|
} else {
|
||||||
|
const stdoutString = revive.readFromStdout();
|
||||||
const json = JSON.stringify({ type: 'success', data: stdoutString });
|
const json = JSON.stringify({ type: 'success', data: stdoutString });
|
||||||
return stringToNewUTF8(json);
|
return stringToNewUTF8(json);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,26 +34,12 @@ async function runCompiler() {
|
|||||||
m.soljson = soljson;
|
m.soljson = soljson;
|
||||||
|
|
||||||
// Set input data for stdin
|
// Set input data for stdin
|
||||||
m.setStdinData(JSON.stringify(compilerStandardJsonInput));
|
m.writeToStdin(JSON.stringify(compilerStandardJsonInput));
|
||||||
|
|
||||||
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
|
// Compile the Solidity source code
|
||||||
let x = m.callMain(['--standard-json']);
|
let x = m.callMain(['--standard-json']);
|
||||||
console.log("Stdout: " + stdoutString);
|
console.log("Stdout: " + m.readFromStdout());
|
||||||
console.error("Stderr: " + stderrString);
|
console.error("Stderr: " + m.readFromStderr());
|
||||||
}
|
}
|
||||||
|
|
||||||
runCompiler().catch(err => {
|
runCompiler().catch(err => {
|
||||||
|
|||||||
@@ -29,24 +29,10 @@ onmessage = async function (e) {
|
|||||||
m.soljson = Module;
|
m.soljson = Module;
|
||||||
|
|
||||||
// Set input data for stdin
|
// Set input data for stdin
|
||||||
m.setStdinData(JSON.stringify(sourceCode));
|
m.writeToStdin(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
|
// Compile the Solidity source code
|
||||||
m.callMain(['--standard-json']);
|
m.callMain(['--standard-json']);
|
||||||
|
|
||||||
postMessage({output: stdoutString || stderrString});
|
postMessage({output: m.readFromStdout() || m.readFromStderr()});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user