XenevaOS
Loading...
Searching...
No Matches
js.h
Go to the documentation of this file.
1
13#ifndef NS_JS_H
14#define NS_JS_H
15
16#include <stdint.h>
17#include <stddef.h>
18#include <stdbool.h>
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24#define NS_JS_SCRIPT_MAX (64 * 1024)
25
26/* Sink kinds: how a JS output chunk must render. */
27#define NS_JS_KIND_WRITE 0 /* document.write: carries the current run style */
28#define NS_JS_KIND_LOG 1 /* console.log/info/debug: dim gray */
29#define NS_JS_KIND_WARN 2 /* console.warn + alert: amber */
30#define NS_JS_KIND_ERR 3 /* console.error + uncaught exceptions: red */
31
32typedef void NsJsSinkFn(const char* s, size_t n, int kind);
33
34/* One sink for the whole page; set before the first fetch. */
36
37/* Per-page lifecycle: NsJsBegin replaces any previous context (dropping
38 * its timers), scans <title>, then NsJsScriptChunk accumulates each
39 * <script> body until </script> runs NsJsRunPending. The context (and any
40 * armed timers) survives past the parse until the next NsJsBegin. */
41void NsJsBegin(const char* url);
42void NsJsScanTitle(const char* src, size_t len);
43void NsJsScriptChunk(char c);
44void NsJsScriptSrcAttr(const char* attr); /* len>0 => external, not fetched */
45void NsJsScriptType(const char* type); /* non-JS types (ld+json) are not evaled */
46void NsJsRunPending(void); /* </script>: eval accumulated body */
47void NsJsFlushConsole(void); /* drain console lines to the sink */
48void NsJsEnd(void); /* destroy context (rarely needed) */
49
50/* Fire due timers and promise jobs. Returns true if a callback ran
51 * (caller repaints). Poll every few ms when the postbox is idle. */
52bool NsJsTick(void);
53int NsJsTimerCount(void); /* armed timers, for loop heuristics */
54
55/* 1 if a script asked to load another page. Copy the URL out and clear
56 * the request. The caller fetches it after the script returns. */
57int NsJsConsumeNav(char* out, size_t outsz);
58
59/* The DOM exists only after the hubbub parse. Scripts that run during
60 * the HTML scan still see a soft document; timers that fire later see
61 * this tree. A setAttribute that changes style sets the dirty flag. */
62struct NsCssNode;
63void NsJsSetDocument(struct NsCssNode* root);
64int NsJsConsumeDirty(void);
65
66const char* NsJsVersion(void); /* "QuickJS 2026-06-04" */
67
68/* 0 when this page did not start QuickJS. Bing is one of those pages. */
69int NsJsActive(void);
70
71/* 1 when the page assigned this global to an object. */
72int NsJsDefined(const char* name);
73
74#ifdef __cplusplus
75}
76#endif
77
78#endif
#define out(...)
Definition main.cpp:65
void * fn
Definition audrv.c:980
struct drm_crtc struct drm_plane struct drm_plane const struct drm_crtc_funcs const char * name
Definition drm_crtc.h:1242
size_t len
Definition initial.c:23
void NsJsRunPending(void)
Definition js.c:1438
int NsJsConsumeNav(char *out, size_t outsz)
Definition js.c:766
void NsJsSetDocument(struct NsCssNode *root)
Definition js.c:1254
void NsJsScriptChunk(char c)
Definition js.c:1379
int NsJsTimerCount(void)
Definition js.c:614
int NsJsConsumeDirty(void)
Definition js.c:1259
void NsJsEnd(void)
Definition js.c:1323
void NsJsScanTitle(const char *src, size_t len)
Definition js.c:1328
void NsJsFlushConsole(void)
Definition js.c:125
int NsJsDefined(const char *name)
Definition js.c:1424
int NsJsActive(void)
Definition js.c:1290
void NsJsSinkFn(const char *s, size_t n, int kind)
Definition js.h:32
void NsJsScriptType(const char *type)
Definition js.c:1375
bool NsJsTick(void)
Definition js.c:756
void NsJsScriptSrcAttr(const char *attr)
Definition js.c:1358
const char * NsJsVersion(void)
Definition js.c:48
void NsJsBegin(const char *url)
Definition js.c:1294
void NsJsSetSink(NsJsSinkFn *fn)
Definition js.c:779
Definition css.h:37
TTY * root
Definition tty.cpp:47