• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!DOCTYPE html>
2<html>
3<head>
4<title>WebIDL 2 Checker</title>
5
6<script src='../lib/webidl2.js'></script>
7<script>
8let parserResult = undefined;
9
10function formatParserOutput() {
11  const outputEl = document.getElementById('webidl-checker-output');
12  if (parserResult) {
13    const prettyPrintEl = document.getElementById('pretty-print');
14    outputEl.innerText = JSON.stringify(parserResult, null, prettyPrintEl.checked ? 2 : null);
15  } else {
16    outputEl.innerText = '';
17  }
18}
19
20function checkWebIDL(textToCheck) {
21  const validation = document.getElementById('webidl-checker-validation');
22  parserResult = null;
23  try {
24    parserResult = WebIDL2.parse(textToCheck);
25    validation.innerText = 'WebIDL parsed successfully!';
26  } catch (e) {
27    validation.innerText = 'Exception while parsing WebIDL. See JavaScript console for more details.\n\n' + e.toString();
28    // Pass it along to the JavaScript console.
29    throw e;
30  } finally {
31    formatParserOutput();
32  }
33}
34</script>
35<style>
36textarea {
37  font-family: monospace;
38}
39</style>
40</head>
41<body>
42<h2>WebIDL Checker</h2>
43<p>This is an online checker for WebIDL built on the <a href="https://github.com/w3c/webidl2.js">webidl2.js</a> project.</p>
44<p>Enter your WebIDL to check below:</p>
45<textarea id='webidl-to-check' rows='20' cols='80'></textarea>
46<br>
47<input type='button' value='Check WebIDL' onclick='checkWebIDL(document.getElementById("webidl-to-check").value)'>
48<p>Validation results:</p>
49<textarea id='webidl-checker-validation' rows='20' cols='80'></textarea>
50<p>Parser output:</p>
51<textarea id='webidl-checker-output' rows='20' cols='80'></textarea>
52<br>
53<input type='checkbox' id='pretty-print' checked='true' onchange='formatParserOutput()'>Pretty Print
54</body>
55</html>
56