NetSurf
|
Interface to javascript engine functions. More...
#include "utils/errors.h"
Go to the source code of this file.
Typedefs | |
typedef struct jsheap | jsheap |
JavaScript interpreter heap. More... | |
typedef struct jsthread | jsthread |
JavaScript interpreter thread. More... | |
Functions | |
void | js_initialise (void) |
Initialise javascript interpreter. More... | |
void | js_finalise (void) |
finalise javascript interpreter More... | |
nserror | js_newheap (int timeout, jsheap **heap) |
Create a new javascript heap. More... | |
void | js_destroyheap (jsheap *heap) |
Destroy a previously created heap. More... | |
nserror | js_newthread (jsheap *heap, void *win_priv, void *doc_priv, jsthread **thread) |
Create a new javascript thread. More... | |
nserror | js_closethread (jsthread *thread) |
Close a javascript thread. More... | |
void | js_destroythread (jsthread *thread) |
Destroy a javascript thread. More... | |
bool | js_exec (jsthread *thread, const uint8_t *txt, size_t txtlen, const char *name) |
execute some javascript in a context More... | |
bool | js_fire_event (jsthread *thread, const char *type, struct dom_document *doc, struct dom_node *target) |
fire an event at a dom node More... | |
bool | js_dom_event_add_listener (jsthread *thread, struct dom_document *document, struct dom_node *node, struct dom_string *event_type_dom, void *js_funcval) |
void | js_handle_new_element (jsthread *thread, struct dom_element *node) |
Handle a new element being created. More... | |
void | js_event_cleanup (jsthread *thread, struct dom_event *evt) |
Handle an event propagation finished callback. More... | |
Interface to javascript engine functions.
Definition in file js.h.
JavaScript interpreter thread.
When we create a browsing context itself (window+content) we have to create a JS thread to attach to the browsing context.
JS threads are associated with heaps and will be destroyed when the heap is destroyed. They can be shut down manually though and should be for object lifetime safety reasons.
Close a javascript thread.
This should be called when the HTML content which owns the thread is being closed. This is a separate process from destroying the thread and merely disconnects any callbacks and thus hopefully stops additional JS things from triggering. If any code runs and attempts to register callbacks after closedown, they will fail.
thread | The thread to close down |
Definition at line 761 of file dukky.c.
References CTX, duk_get_global_string(), duk_get_top(), duk_set_top(), dukky_pcall(), jsthread::heap, MAGIC, NSERROR_OK, and NSLOG.
Referenced by html_close(), and html_stop().
void js_destroyheap | ( | jsheap * | heap | ) |
Destroy a previously created heap.
heap | The heap to destroy |
Definition at line 638 of file dukky.c.
References dukky_destroyheap(), jsheap::live_threads, and jsheap::pending_destroy.
Referenced by browser_window_destroy_internal().
void js_destroythread | ( | jsthread * | thread | ) |
Destroy a javascript thread.
This should be called when the browsing context is done with the thread.
This will be called when the HTML content associated with the browsing context is being destroyed. The thread should have already been closed down during the HTML content close.
thread | The thread to be destroyed |
Definition at line 815 of file dukky.c.
References dukky_destroythread(), jsthread::in_use, and jsthread::pending_destroy.
Referenced by html_destroy(), and js_newthread().
bool js_dom_event_add_listener | ( | jsthread * | thread, |
struct dom_document * | document, | ||
struct dom_node * | node, | ||
struct dom_string * | event_type_dom, | ||
void * | js_funcval | ||
) |
void js_event_cleanup | ( | jsthread * | thread, |
struct dom_event * | evt | ||
) |
Handle an event propagation finished callback.
This is called once an event finishes propagating, no matter how it finishes. The intent here is that the JS context can perform any cleanups it may need to perform before the DOM finishes and the event may end up freed.
Definition at line 1551 of file dukky.c.
References CTX, duk_del_prop(), duk_get_global_string(), duk_pop(), duk_push_pointer(), dukky_enter_thread(), dukky_leave_thread(), and EVENT_MAGIC.
Referenced by dom_default_action_finished_cb(), and js_fire_event().
bool js_exec | ( | jsthread * | thread, |
const uint8_t * | txt, | ||
size_t | txtlen, | ||
const char * | name | ||
) |
execute some javascript in a context
Definition at line 922 of file dukky.c.
References CTX, DUK_COMPILE_EVAL, DUK_EXEC_ERROR, duk_get_boolean(), duk_get_top(), duk_pcall(), duk_pcompile_lstring_filename, duk_push_boolean(), duk_push_string(), duk_set_top(), dukky_dump_error(), dukky_enter_thread(), dukky_leave_thread(), dukky_reset_start_time(), NSLOG, jsthread::pending_destroy, and PRIsizet.
Referenced by select_script_handler().
void js_finalise | ( | void | ) |
finalise javascript interpreter
Definition at line 590 of file dukky.c.
Referenced by netsurf_exit().
bool js_fire_event | ( | jsthread * | thread, |
const char * | type, | ||
struct dom_document * | doc, | ||
struct dom_node * | target | ||
) |
fire an event at a dom node
Definition at line 1567 of file dukky.c.
References CTX, duk_get_global_string(), duk_get_prop(), duk_get_prop_string(), duk_insert(), duk_is_undefined(), duk_pcall_method(), duk_pop(), duk_pop_n(), duk_push_global_object(), duk_push_lstring(), duk_safe_to_string, dukky_enter_thread(), dukky_get_current_value_of_event_handler(), dukky_leave_thread(), dukky_push_event(), dukky_push_node(), dukky_reset_start_time(), HANDLER_MAGIC, js_event_cleanup(), NSLOG, and type.
Referenced by html_finish_conversion().
void js_handle_new_element | ( | jsthread * | thread, |
struct dom_element * | node | ||
) |
Handle a new element being created.
This is called once an element is inserted into the DOM document handled by the context provided. The JS implementation must then scan the element for on* attributes and register appropriate listeners for those handlers.
Definition at line 1471 of file dukky.c.
References CTX, dukky_enter_thread(), dukky_leave_thread(), and dukky_register_event_listener_for().
Referenced by dom_default_action_DOMNodeInserted_cb().
void js_initialise | ( | void | ) |
Initialise javascript interpreter.
TODO: Forces JS on for our testing, needs changing before a release lest we incur the wrath of others.
Definition at line 577 of file dukky.c.
References javascript_init().
Referenced by netsurf_init().
Create a new javascript heap.
There is usually one heap per browser window.
timeout | elapsed wallclock time (in seconds) before callback is called |
heap | Updated to the created JS heap |
Definition at line 598 of file dukky.c.
References jsheap::ctx, duk_create_heap(), duk_push_boolean(), duk_push_global_object(), duk_push_object(), duk_put_global_string(), duk_put_prop_string(), dukky_alloc_function(), dukky_free_function(), dukky_realloc_function(), NSERROR_NOMEM, NSERROR_OK, NSLOG, and THREAD_MAP.
Referenced by browser_window_initialise_common().
Create a new javascript thread.
This is called once for a page with javascript script tags on it. It constructs a fresh global window object and prepares the JS browsing context. It's important that threads are shut down cleanly when the browsing context is going to be cleaned up.
heap | The heap to create the thread within |
win_priv | The value to give to the Window constructor as the window |
doc_priv | The value to give to the Document constructor as the document |
thread | Updated to the created thread |
Definition at line 650 of file dukky.c.
References jsheap::ctx, jsthread::ctx, CTX, DUK_COMPILE_EVAL, duk_del_prop_string(), duk_get_global_string(), duk_get_prop_string(), duk_pcompile_lstring_filename, duk_pop(), duk_push_global_object(), duk_push_int(), duk_push_null(), duk_push_object(), duk_push_pointer(), duk_push_string(), duk_push_thread, duk_put_global_string(), duk_put_prop(), duk_put_prop_index(), duk_put_prop_string(), duk_require_context(), duk_safe_to_string, duk_set_global_object(), dukky_create_object(), dukky_log_stack_frame(), dukky_pcall(), EVENT_MAGIC, GENERICS_MAGIC, jsthread::heap, js_destroythread(), jsheap::live_threads, jsheap::next_thread, NSERROR_INIT_FAILED, NSERROR_NOMEM, NSERROR_OK, NSLOG, jsheap::pending_destroy, jsthread::thread_idx, and THREAD_MAP.
Referenced by browser_window_callback().