65 lines
1.7 KiB
JavaScript
65 lines
1.7 KiB
JavaScript
function alloc_bytes(app, data)
|
|
{
|
|
let stdlib_types___alloc_bytes__ = app.instance.exports['stdlib.types.__alloc_bytes__']
|
|
|
|
if( typeof data == 'string' ) {
|
|
// TODO: Unicode
|
|
data = Uint8Array.from(data.split('').map(x => x.charCodeAt()));
|
|
}
|
|
|
|
let offset = stdlib_types___alloc_bytes__(data.length);
|
|
let i8arr = new Uint8Array(app.instance.exports.memory.buffer, offset + 4, data.length);
|
|
i8arr.set(data);
|
|
|
|
return offset;
|
|
}
|
|
|
|
function run_times(times, callback)
|
|
{
|
|
let sum = 0;
|
|
for(let idx = 0; idx < times; idx += 1) {
|
|
const t0 = performance.now();
|
|
callback();
|
|
const t1 = performance.now();
|
|
sum += t1 - t0;
|
|
}
|
|
console.log(sum);
|
|
return sum / times;
|
|
}
|
|
|
|
function test_result(is_pass, data)
|
|
{
|
|
data = data || {};
|
|
|
|
let result_details = document.createElement('details');
|
|
|
|
let result_summary = document.createElement('summary');
|
|
result_summary.textContent =
|
|
(is_pass ? 'Test passed: ' : 'Test failed: ')
|
|
+ (data.summary ?? '(no summary)')
|
|
;
|
|
result_summary.setAttribute('style', is_pass ? 'background: green' : 'background: red');
|
|
result_details.appendChild(result_summary);
|
|
|
|
if( data.attributes ) {
|
|
let table = document.createElement('table');
|
|
|
|
Object.keys(data.attributes).forEach(idx => {
|
|
let td0 = document.createElement('td');
|
|
td0.textContent = idx;
|
|
let td1 = document.createElement('td');
|
|
td1.textContent = data.attributes[idx];
|
|
|
|
let tr = document.createElement('tr');
|
|
tr.appendChild(td0);
|
|
tr.appendChild(td1);
|
|
|
|
table.appendChild(tr);
|
|
});
|
|
result_details.append(table);
|
|
}
|
|
|
|
let results = document.getElementById('results');
|
|
results.appendChild(result_details);
|
|
}
|