1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-09-19 01:36:33 -04:00
elinks/src/viewer/text/vs.h
Miciah Dashiel Butler Masters 3932af9b17 SMJS: handle view_state outliving wrapping object
Currently, it is possible for the JSObject that wraps a struct view_state
to outlive the view_state.  Using the properties of the JSObject wrapper
will then cause a crash.

This patch adds a smjs_detach_view_state_object function, which is called
in destroy_vs, to dissociate the struct view_state from the JSObject
wrapper.  To this end, the patch modifies the struct view_state to point
the JSObject wrapper.  smjs_get_view_state_object will use this pointer
if it is set, and copy_vs will copy this pointer to the new view_state.
The patch also modifies view_state_get_property and
view_state_set_property to return immediately if the view_state has been
destroyed.  Finally, the patch adds a finalizer (view_state_finalize)
that clears the pointer from the struct view_state to the JSObject.
2011-11-14 04:34:51 +00:00

67 lines
1.9 KiB
C

#ifndef EL__VIEWER_TEXT_VS_H
#define EL__VIEWER_TEXT_VS_H
#include "util/lists.h"
/* Crossdeps are evil. */
struct document_view;
struct form_state;
struct session;
struct uri;
struct view_state {
#ifdef CONFIG_SCRIPTING_SPIDERMONKEY
struct JSObject *jsobject; /* Instance of view_state_class */
#endif
struct document_view *doc_view;
struct uri *uri;
LIST_OF(struct form_view) forms;
struct form_state *form_info;
int form_info_len;
/** Horizontal scrolling. If @c x is e.g. 2, then the
* leftmost two columns of the document have been scrolled out
* of sight. @c x should never be negative. */
int x;
/** Vertical scrolling. If @c y is e.g. 1, then the first
* line of the document has been scrolled out of sight. @c y
* should never be negative. */
int y;
/** The index of the focused link in the document.links array,
* or -1 of none. */
int current_link;
int old_current_link;
int plain;
unsigned int wrap:1;
unsigned int did_fragment:1;
#ifdef CONFIG_ECMASCRIPT
/** If set, we reset the interpreter state the next time we are going
* to render document attached to this view state. This means a real
* document (not just struct document_view, which randomly appears and
* disappears during gradual rendering) is getting replaced. So set this
* always when you replace the view_state URI, but also when reloading
* the document. You also cannot reset the document right away because
* it might take some time before the first rerendering is done and
* until then the old document is still hanging there. */
unsigned int ecmascript_fragile:1;
struct ecmascript_interpreter *ecmascript;
#endif
};
void init_vs(struct view_state *, struct uri *uri, int);
void destroy_vs(struct view_state *, int blast_ecmascript);
void copy_vs(struct view_state *, struct view_state *);
void check_vs(struct document_view *);
void next_frame(struct session *, int);
#endif