Merge branch 'master' of github.com:NikVolf/wasm-tools

This commit is contained in:
NikVolf
2017-04-20 17:00:56 +03:00
+19 -6
View File
@@ -6,7 +6,7 @@
if (!('WebAssembly' in window)) {
alert('you need a browser with wasm support enabled :(');
}
function loadWebAssembly(filename, imports) {
return fetch(filename)
.then(response => response.arrayBuffer())
@@ -15,7 +15,7 @@
imports = imports || {};
imports.env = imports.env || {};
var env = imports.env;
imports.env.memoryBase = imports.env.memoryBase || 0;
imports.env.memoryBase = imports.env.memoryBase || 1024;
imports.env.tableBase = imports.env.tableBase || 0;
/* rust/emscripten imports
@@ -44,11 +44,18 @@
(import "env" "tableBase" (global (;4;) i32))
*/
env.DYNAMICTOP_PTR = env.DYNAMICTOP_PTR || 0;
var memory = new WebAssembly.Memory({ initial: 256, maximum: 256 });
env.STACKTOP = env.STACKTOP || 0;
env.STACK_MAX = env.STACK_MAX || 5*1024*1024;
env.enlargeMemory = env.enlargeMemory || function() { throw "error enlarging memory"; };
env.getTotalMemory = env.getTotalMemory || function() { return 65536 * 256; };
env.DYNAMICTOP_PTR = env.STACK_MAX;
env.enlargeMemory = env.enlargeMemory || function() {
console.log("called enlargeMemory(" + JSON.stringify(arguments) + ");");
return 1;
};
env.getTotalMemory = env.getTotalMemory || function() {
return 16 * 1024 * 1024;
};
env.abortOnCannotGrowMemory = env.abortOnCannotGrowMemory || function() { throw "abort growing memory"; };
env._abort = env._abort || function() { throw "_abort"; };
env.abort = env.abort || function() { throw "abort"; };
@@ -77,7 +84,7 @@
}
if (!imports.env.memory) {
imports.env.memory = new WebAssembly.Memory({ initial: 256, maximum: 256 });
imports.env.memory = memory;
}
if (!imports.env.table) {
imports.env.table = new WebAssembly.Table({ initial: 0, maximum: 0, element: 'anyfunc' });
@@ -88,8 +95,14 @@
loadWebAssembly('out/contract.wasm')
.then(instance => {
debugger;
var exports = instance.exports;
var call = exports._call;
var malloc = exports._malloc;
var data_ptr = malloc(1024*8);
console.log("data_ptr: " + data_ptr);
var button = document.getElementById('do-call');
button.value = 'Execute call';
button.addEventListener('click', function() {