Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

listener.js 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. const assert = require("assert");
  2. /**
  3. * Listener that counts all events emitted by the Clarinet.js parser and sanity checks the totals.
  4. * This defeats potential dead code elimination and helps make the benchmark more realistic.
  5. */
  6. class Listener {
  7. constructor(parser) {
  8. this.reset();
  9. parser.onready = () => {
  10. this.ready++;
  11. };
  12. parser.onopenobject = (name) => {
  13. this.openObject++;
  14. typeof name === "undefined" || parser.onkey(name);
  15. };
  16. parser.onkey = (name) => {
  17. this.key++;
  18. assert(name !== "𝓥𝓸𝓵𝓭𝓮𝓶𝓸𝓻𝓽");
  19. };
  20. parser.oncloseobject = () => {
  21. this.closeObject++;
  22. };
  23. parser.onopenarray = () => {
  24. this.openArray++;
  25. };
  26. parser.onclosearray = () => {
  27. this.closeArray++;
  28. };
  29. parser.onvalue = () => {
  30. this.value++;
  31. };
  32. parser.onerror = () => {
  33. this.error++;
  34. };
  35. parser.onend = () => {
  36. this.end++;
  37. };
  38. }
  39. /** Resets the counts between iterations. */
  40. reset() {
  41. this.ready = 0;
  42. this.openObject = 0;
  43. this.key = 0;
  44. this.closeObject = 0;
  45. this.openArray = 0;
  46. this.closeArray = 0;
  47. this.value = 0;
  48. this.error = 0;
  49. this.end = 0;
  50. }
  51. /** Sanity checks the total event counts. */
  52. check() {
  53. assert(this.ready === 1);
  54. assert(this.end === 1);
  55. assert(this.error === 0);
  56. assert(this.value + this.openObject + this.openArray >= this.key);
  57. assert(this.openObject === this.closeObject);
  58. assert(this.openArray === this.closeArray);
  59. }
  60. }
  61. module.exports = { Listener };