Skip to content

Commit

Permalink
More wasm feature checking
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonGross committed Nov 24, 2023
1 parent f6ed837 commit 1fedd93
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions fiat-html/disable-wasm-option.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,39 @@
document.addEventListener('DOMContentLoaded', async function() {
const wasmCheckbox = document.getElementById('wasm');
const extraWasmLabel = document.getElementById('extraWasmLabel');
wasmCheckbox.disabled = true; // Initially disable the checkbox
wasmCheckbox.disabled = true; // Initially disable the checkbox

try {
if (await wasmFeatureDetect.tailCall()) {
wasmCheckbox.disabled = false; // Re-enable the checkbox if tail calls are supported
const features = {
tailCall: await wasmFeatureDetect.tailCall(),
gc: await wasmFeatureDetect.gc(),
exceptions: await wasmFeatureDetect.exceptions()
};

const unsupportedFeatures = Object.entries(features)
.filter(([feature, supported]) => !supported)
.map(([feature]) => feature);

if (unsupportedFeatures.length === 0) {
wasmCheckbox.disabled = false; // Re-enable the checkbox if all features are supported
} else {
wasmCheckbox.checked = false;

let featureText = unsupportedFeatures.join(', ');
let firefoxText = unsupportedFeatures.map(feature => {
if (feature === 'tailCall') return 'javascript.options.wasm_tail_calls';
if (feature === 'gc') return 'javascript.options.wasm_gc';
if (feature === 'exceptions') return 'javascript.options.wasm_exceptions';
return feature;
}).join(', ');

if (navigator.userAgent.includes('Firefox')) {
extraWasmLabel.innerHTML = '(enable <code>javascript.options.wasm_tail_calls</code> in <code>about:config</code>)';
extraWasmLabel.innerHTML = `(enable <code>${firefoxText}</code> in <code>about:config</code>)`;
} else {
extraWasmLabel.innerHTML = '(wasm tail calls not supported)';
extraWasmLabel.innerHTML = `(missing wasm support for: ${featureText})`;
}
}
} catch (error) {
console.error('Error checking wasm tail call support:', error);
console.error('Error checking wasm feature support:', error);
}
});

0 comments on commit 1fedd93

Please sign in to comment.