js_browser.h 924 B

12345678910111213141516171819202122232425262728
  1. /* Minimal browser bindings for the embedded MuJS interpreter.
  2. *
  3. * The host owns the document and the UI; this layer only exposes the small
  4. * DOM surface the first JavaScript milestone needs: console.log, alert,
  5. * document.getElementById(...).textContent and location.href. */
  6. #ifndef JS_BROWSER_H
  7. #define JS_BROWSER_H
  8. struct br_doc;
  9. struct js_browser_host {
  10. void (*status)(const char *msg, int error);
  11. void (*report)(const char *msg);
  12. void (*navigate)(const char *url);
  13. void (*changed)(void);
  14. const char *page_url; /* location.href for every script on the page */
  15. };
  16. /* Create a state for this document. Returns 0 on success. */
  17. int js_browser_start(struct br_doc *doc, const struct js_browser_host *host);
  18. void js_browser_stop(void);
  19. /* Run one script. `url` is used in error messages and by location.href. */
  20. int js_browser_run(const char *source, const char *url);
  21. int js_browser_active(void);
  22. #endif