52 lines
1.2 KiB
HTML
52 lines
1.2 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>Examples - Buffer</title>
|
|
</head>
|
|
<body>
|
|
<h1>Buffer</h1>
|
|
|
|
<a href="index.html">List</a> - <a href="buffer.py.html">Source</a> - <a href="buffer.wat.html">WebAssembly</a>
|
|
|
|
<div style="white-space: pre;" id="results"></div>
|
|
|
|
|
|
<script type="text/javascript" src="./include.js"></script>
|
|
<script type="text/javascript">
|
|
let importObject = {};
|
|
|
|
// Run a single test
|
|
function run_test(app, str)
|
|
{
|
|
let offset = alloc_bytes(app, str);
|
|
|
|
let js_chars = [];
|
|
let wasm_chars = [];
|
|
for(let idx = 0; idx < str.length; ++idx) {
|
|
js_chars.push(str.charCodeAt(idx));
|
|
wasm_chars.push(app.instance.exports.index(offset, idx));
|
|
}
|
|
|
|
let result = js_chars.every(function(value, index) { return value === wasm_chars[index]})
|
|
|
|
test_result(result, {
|
|
'summary': 'js_chars == wasm_chars, for "' + str + '"',
|
|
'attributes': {
|
|
'js_chars': js_chars,
|
|
'wasm_chars': wasm_chars,
|
|
}
|
|
});
|
|
}
|
|
|
|
WebAssembly.instantiateStreaming(fetch('buffer.wasm'), importObject)
|
|
.then(app => {
|
|
run_test(app, '');
|
|
run_test(app, 'a');
|
|
run_test(app, 'Hello');
|
|
run_test(app, 'The quick brown fox jumps over the lazy dog');
|
|
});
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|