This commit completes Phase 3 (Event System) and includes a thorough midpoint review that identified and fixed critical gaps from earlier phases. Major accomplishments: • Complete event system with addEventListener/removeEventListener API • Event dispatch system with preventDefault/stopPropagation support • Click event integration with w3m's existing mouse handling system • Enhanced document.write() from stub to functional implementation • Fixed critical anchor-DOM integration gap from Phase 2 • Comprehensive code review and stub elimination • Full DOM element extraction and JavaScript object conversion • Working noscript tag suppression when JavaScript is enabled Testing verified: • JavaScript execution and DOM manipulation working correctly • document.write() creates DOM elements and displays content properly • noscript content correctly hidden when JavaScript is enabled • Click events integrate properly with w3m's mouse system • No compilation errors or warnings (except minor unused variable) Phase status: Phases 1-3 now complete and fully functional. Remaining stubs are safe and won't cause unexpected behavior. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
89 lines
2.9 KiB
C
89 lines
2.9 KiB
C
/*
|
|
* w3m JavaScript Integration Header
|
|
*
|
|
* This file provides the main JavaScript integration interface for w3m.
|
|
* It defines the core structures and functions needed to execute JavaScript
|
|
* within w3m's text-based browser environment.
|
|
*/
|
|
|
|
#ifndef W3M_JAVASCRIPT_H
|
|
#define W3M_JAVASCRIPT_H
|
|
|
|
#ifdef USE_JAVASCRIPT
|
|
|
|
#include "quickjs/quickjs.h"
|
|
#include "fm.h"
|
|
|
|
/* Forward declarations */
|
|
struct _Buffer;
|
|
struct Line;
|
|
struct Anchor;
|
|
struct FormList;
|
|
|
|
/* Forward declaration for event system */
|
|
struct W3MEventSystem;
|
|
|
|
/* JavaScript Context Management */
|
|
typedef struct {
|
|
JSRuntime *runtime;
|
|
JSContext *context;
|
|
JSValue global_obj;
|
|
JSValue document_obj;
|
|
JSValue window_obj;
|
|
int memory_limit;
|
|
int execution_timeout;
|
|
struct W3MEventSystem *event_system; /* Event system reference */
|
|
} W3MJSContext;
|
|
|
|
/* JavaScript state per buffer */
|
|
typedef struct {
|
|
W3MJSContext *ctx; /* JavaScript context */
|
|
W3MJSContext *js_ctx; /* Legacy field for compatibility */
|
|
struct W3MEventSystem *event_system; /* Event system */
|
|
struct W3MDocument *dom_document; /* DOM document */
|
|
JSValue *script_objects; /* Array of script element objects */
|
|
int script_count;
|
|
char **pending_scripts; /* Scripts to execute on load */
|
|
int pending_count;
|
|
int scripts_enabled;
|
|
} BufferJSState;
|
|
|
|
/* Core JavaScript Engine Functions */
|
|
W3MJSContext *w3m_js_create_context(void);
|
|
void w3m_js_destroy_context(W3MJSContext *ctx);
|
|
int w3m_js_execute_script(W3MJSContext *ctx, const char *script, const char *filename);
|
|
void w3m_js_set_timeout(W3MJSContext *ctx, int timeout_ms);
|
|
void w3m_js_set_memory_limit(W3MJSContext *ctx, int limit_bytes);
|
|
|
|
/* Buffer JavaScript Integration */
|
|
BufferJSState *w3m_js_init_buffer_state(Buffer *buf);
|
|
void w3m_js_cleanup_buffer_state(BufferJSState *state);
|
|
void w3m_js_add_pending_script(BufferJSState *state, const char *script);
|
|
void w3m_js_execute_pending_scripts(BufferJSState *state);
|
|
|
|
/* DOM Integration */
|
|
void w3m_js_bind_dom_objects(W3MJSContext *ctx, Buffer *buf);
|
|
JSValue w3m_js_create_element_object(W3MJSContext *ctx, struct Line *line, int pos);
|
|
void w3m_js_update_buffer_from_dom(W3MJSContext *ctx, Buffer *buf);
|
|
|
|
/* Event System */
|
|
void w3m_js_fire_event(W3MJSContext *ctx, const char *event_type, JSValue target);
|
|
int w3m_js_has_event_listener(W3MJSContext *ctx, JSValue target, const char *event_type);
|
|
|
|
/* Form Integration */
|
|
void w3m_js_bind_form_events(W3MJSContext *ctx, struct FormList *form);
|
|
int w3m_js_validate_form(W3MJSContext *ctx, struct FormList *form);
|
|
|
|
/* Configuration */
|
|
extern int w3m_js_enabled;
|
|
extern int w3m_js_timeout;
|
|
extern int w3m_js_memory_limit;
|
|
extern int w3m_js_network_enabled;
|
|
|
|
/* Utility Functions */
|
|
char *w3m_js_value_to_string(W3MJSContext *ctx, JSValue val);
|
|
void w3m_js_report_error(W3MJSContext *ctx, const char *msg);
|
|
|
|
#endif /* USE_JAVASCRIPT */
|
|
|
|
#endif /* W3M_JAVASCRIPT_H */ |