NetSurf
Data Structures | Macros | Functions
dukky.c File Reference

Duktapeish implementation of javascript engine functions. More...

#include <stdint.h>
#include <nsutils/time.h>
#include "netsurf/inttypes.h"
#include "utils/utils.h"
#include "utils/nsoption.h"
#include "utils/log.h"
#include "utils/corestrings.h"
#include "content/content.h"
#include "javascript/js.h"
#include "javascript/content.h"
#include "duktape/binding.h"
#include "duktape/generics.js.inc"
#include "duktape/polyfill.js.inc"
#include "duktape.h"
#include "dukky.h"
#include <dom/dom.h>
Include dependency graph for dukky.c:

Go to the source code of this file.

Data Structures

struct  jsheap
 dukky javascript heap More...
 
struct  jsthread
 dukky javascript thread More...
 

Macros

#define EVENT_MAGIC   MAGIC(EVENT_MAP)
 
#define HANDLER_LISTENER_MAGIC   MAGIC(HANDLER_LISTENER_MAP)
 
#define HANDLER_MAGIC   MAGIC(HANDLER_MAP)
 
#define EVENT_LISTENER_JS_MAGIC   MAGIC(EVENT_LISTENER_JS_MAP)
 
#define GENERICS_MAGIC   MAGIC(GENERICS_TABLE)
 
#define THREAD_MAP   MAGIC(THREAD_MAP)
 
#define SET_HTML_CLASS(CLASS)
 
#define CTX   (ret->ctx)
 
#define CTX   (thread->ctx)
 
#define JS_EXEC_TIMEOUT_MS   10000 /* 10 seconds */
 

Functions

static duk_ret_t dukky_populate_object (duk_context *ctx, void *udata)
 
duk_ret_t dukky_create_object (duk_context *ctx, const char *name, int args)
 
duk_bool_t dukky_push_node_stacked (duk_context *ctx)
 
static void dukky_html_element_class_from_tag_type (dom_html_element_type type, const char **html_class, size_t *html_class_len)
 
static void dukky_push_node_klass (duk_context *ctx, struct dom_node *node)
 
duk_bool_t dukky_push_node (duk_context *ctx, struct dom_node *node)
 
static duk_ret_t dukky_bad_constructor (duk_context *ctx)
 
void dukky_inject_not_ctr (duk_context *ctx, int idx, const char *name)
 
static void * dukky_alloc_function (void *udata, duk_size_t size)
 
static void * dukky_realloc_function (void *udata, void *ptr, duk_size_t size)
 
static void dukky_free_function (void *udata, void *ptr)
 
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...
 
static void dukky_destroyheap (jsheap *heap)
 
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...
 
static void dukky_destroythread (jsthread *thread)
 Destroy a Duktape thread. More...
 
void js_destroythread (jsthread *thread)
 Destroy a javascript thread. More...
 
static void dukky_enter_thread (jsthread *thread)
 
static void dukky_leave_thread (jsthread *thread)
 
duk_bool_t dukky_check_timeout (void *udata)
 
static void dukky_dump_error (duk_context *ctx)
 
static void dukky_reset_start_time (duk_context *ctx)
 
duk_int_t dukky_pcall (duk_context *ctx, duk_size_t argc, bool reset_timeout)
 
void dukky_push_generics (duk_context *ctx, const char *generic)
 
static duk_int_t dukky_push_context_dump (duk_context *ctx, void *udata)
 
void dukky_log_stack_frame (duk_context *ctx, const char *reason)
 
bool js_exec (jsthread *thread, const uint8_t *txt, size_t txtlen, const char *name)
 execute some javascript in a context More...
 
static const char * dukky_event_proto (dom_event *evt)
 
void dukky_push_event (duk_context *ctx, dom_event *evt)
 
static void dukky_push_handler_code_ (duk_context *ctx, dom_string *name, dom_event_target *et)
 
bool dukky_get_current_value_of_event_handler (duk_context *ctx, dom_string *name, dom_event_target *et)
 
static void dukky_generic_event_handler (dom_event *evt, void *pw)
 
void dukky_register_event_listener_for (duk_context *ctx, struct dom_element *ele, dom_string *name, bool capture)
 
bool dukky_event_target_push_listeners (duk_context *ctx, bool dont_create)
 
void dukky_shuffle_array (duk_context *ctx, duk_uarridx_t idx)
 
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...
 
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...
 

Detailed Description

Duktapeish implementation of javascript engine functions.

Definition in file dukky.c.

Macro Definition Documentation

◆ CTX [1/2]

#define CTX   (ret->ctx)

Definition at line 758 of file dukky.c.

◆ CTX [2/2]

#define CTX   (thread->ctx)

Definition at line 758 of file dukky.c.

◆ EVENT_LISTENER_JS_MAGIC

#define EVENT_LISTENER_JS_MAGIC   MAGIC(EVENT_LISTENER_JS_MAP)

Definition at line 52 of file dukky.c.

◆ EVENT_MAGIC

#define EVENT_MAGIC   MAGIC(EVENT_MAP)

Definition at line 49 of file dukky.c.

◆ GENERICS_MAGIC

#define GENERICS_MAGIC   MAGIC(GENERICS_TABLE)

Definition at line 53 of file dukky.c.

◆ HANDLER_LISTENER_MAGIC

#define HANDLER_LISTENER_MAGIC   MAGIC(HANDLER_LISTENER_MAP)

Definition at line 50 of file dukky.c.

◆ HANDLER_MAGIC

#define HANDLER_MAGIC   MAGIC(HANDLER_MAP)

Definition at line 51 of file dukky.c.

◆ JS_EXEC_TIMEOUT_MS

#define JS_EXEC_TIMEOUT_MS   10000 /* 10 seconds */

◆ SET_HTML_CLASS

#define SET_HTML_CLASS (   CLASS)
Value:
*html_class = PROTO_NAME(HTML##CLASS##ELEMENT); \
*html_class_len = \
SLEN(PROTO_NAME(HTML)) + \
SLEN(#CLASS) + \
SLEN("ELEMENT");

Definition at line 205 of file dukky.c.

◆ THREAD_MAP

#define THREAD_MAP   MAGIC(THREAD_MAP)

Definition at line 54 of file dukky.c.

Function Documentation

◆ dukky_alloc_function()

static void * dukky_alloc_function ( void *  udata,
duk_size_t  size 
)
static

Definition at line 548 of file dukky.c.

Referenced by js_newheap().

Here is the caller graph for this function:

◆ dukky_bad_constructor()

static duk_ret_t dukky_bad_constructor ( duk_context ctx)
static

Definition at line 521 of file dukky.c.

References DUK_ERR_ERROR, and duk_error.

Referenced by dukky_inject_not_ctr().

Here is the caller graph for this function:

◆ dukky_check_timeout()

duk_bool_t dukky_check_timeout ( void *  udata)

Definition at line 840 of file dukky.c.

References jsheap::exec_start_time, and JS_EXEC_TIMEOUT_MS.

◆ dukky_create_object()

duk_ret_t dukky_create_object ( duk_context ctx,
const char *  name,
int  args 
)

Definition at line 116 of file dukky.c.

References DUK_EXEC_SUCCESS, duk_insert(), duk_push_int(), duk_push_object(), duk_push_string(), duk_put_prop_string(), duk_safe_call(), dukky_populate_object(), HANDLER_LISTENER_MAGIC, HANDLER_MAGIC, and NSLOG.

Referenced by dukky_push_event(), and js_newthread().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dukky_destroyheap()

static void dukky_destroyheap ( jsheap heap)
static

Definition at line 628 of file dukky.c.

References jsheap::ctx, duk_destroy_heap(), jsheap::live_threads, NSLOG, and jsheap::pending_destroy.

Referenced by dukky_destroythread(), and js_destroyheap().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dukky_destroythread()

static void dukky_destroythread ( jsthread thread)
static

Destroy a Duktape thread.

Definition at line 783 of file dukky.c.

References jsheap::ctx, CTX, duk_del_prop_index(), duk_gc(), DUK_GC_COMPACT, duk_get_global_string(), duk_pop(), dukky_destroyheap(), dukky_pcall(), jsthread::heap, jsthread::in_use, jsheap::live_threads, MAGIC, NSLOG, jsheap::pending_destroy, jsthread::pending_destroy, jsthread::thread_idx, and THREAD_MAP.

Referenced by dukky_leave_thread(), and js_destroythread().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dukky_dump_error()

static void dukky_dump_error ( duk_context ctx)
static

Definition at line 856 of file dukky.c.

References duk_dup_top(), duk_pop(), duk_safe_to_stacktrace(), and NSLOG.

Referenced by dukky_pcall(), and js_exec().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dukky_enter_thread()

static void dukky_enter_thread ( jsthread thread)
static

Definition at line 823 of file dukky.c.

References jsthread::in_use.

Referenced by js_event_cleanup(), js_exec(), js_fire_event(), and js_handle_new_element().

Here is the caller graph for this function:

◆ dukky_event_proto()

static const char * dukky_event_proto ( dom_event *  evt)
static

Definition at line 974 of file dukky.c.

References type.

Referenced by dukky_push_event().

Here is the caller graph for this function:

◆ dukky_event_target_push_listeners()

bool dukky_event_target_push_listeners ( duk_context ctx,
bool  dont_create 
)

Definition at line 1408 of file dukky.c.

References duk_dup(), duk_get_prop(), duk_get_prop_string(), duk_insert(), duk_is_undefined(), duk_pop(), duk_pop_2(), duk_pop_3(), duk_push_array(), duk_push_object(), duk_push_undefined(), duk_put_prop(), duk_put_prop_string(), and EVENT_LISTENER_JS_MAGIC.

Referenced by dukky_generic_event_handler().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dukky_free_function()

static void dukky_free_function ( void *  udata,
void *  ptr 
)
static

Definition at line 570 of file dukky.c.

Referenced by js_newheap().

Here is the caller graph for this function:

◆ dukky_generic_event_handler()

static void dukky_generic_event_handler ( dom_event *  evt,
void *  pw 
)
static

Definition at line 1143 of file dukky.c.

References duk_dup(), duk_get_int(), duk_get_prop_index(), duk_get_prop_string(), duk_insert(), duk_is_boolean(), duk_pcall_method(), duk_pop(), duk_pop_2(), duk_pop_n(), duk_push_array(), duk_push_lstring(), duk_put_prop_index(), duk_safe_to_string, duk_to_boolean(), duk_to_int(), dukky_event_target_push_listeners(), dukky_get_current_value_of_event_handler(), dukky_push_event(), dukky_push_node(), dukky_reset_start_time(), dukky_shuffle_array(), ELF_CAPTURE, ELF_ONCE, and NSLOG.

Referenced by dukky_register_event_listener_for().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dukky_get_current_value_of_event_handler()

bool dukky_get_current_value_of_event_handler ( duk_context ctx,
dom_string *  name,
dom_event_target *  et 
)
Todo:
This is entirely wrong, but it's hard to get right

Definition at line 1090 of file dukky.c.

References DUK_COMPILE_FUNCTION, duk_concat(), duk_get_prop(), duk_get_prop_string(), duk_insert(), duk_is_undefined(), duk_pcompile, duk_pop(), duk_pop_2(), duk_push_lstring(), duk_push_string(), dukky_push_handler_code_(), HANDLER_MAGIC, and NSLOG.

Referenced by dukky_generic_event_handler(), and js_fire_event().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dukky_html_element_class_from_tag_type()

static void dukky_html_element_class_from_tag_type ( dom_html_element_type  type,
const char **  html_class,
size_t *  html_class_len 
)
static

Definition at line 212 of file dukky.c.

References fallthrough, IFRAME, SET_HTML_CLASS, SLEN, and type.

Referenced by dukky_push_node_klass().

Here is the caller graph for this function:

◆ dukky_inject_not_ctr()

void dukky_inject_not_ctr ( duk_context ctx,
int  idx,
const char *  name 
)

Definition at line 527 of file dukky.c.

References duk_insert(), duk_push_c_function(), duk_put_prop_string(), and dukky_bad_constructor().

Here is the call graph for this function:

◆ dukky_leave_thread()

static void dukky_leave_thread ( jsthread thread)
static

Definition at line 829 of file dukky.c.

References dukky_destroythread(), jsthread::in_use, and jsthread::pending_destroy.

Referenced by js_event_cleanup(), js_exec(), js_fire_event(), and js_handle_new_element().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dukky_log_stack_frame()

void dukky_log_stack_frame ( duk_context ctx,
const char *  reason 
)

Definition at line 909 of file dukky.c.

References duk_pop(), duk_push_string(), duk_safe_call(), duk_safe_to_string, dukky_push_context_dump(), and NSLOG.

Referenced by js_newthread().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dukky_pcall()

duk_int_t dukky_pcall ( duk_context ctx,
duk_size_t  argc,
bool  reset_timeout 
)

Definition at line 876 of file dukky.c.

References duk_pcall(), dukky_dump_error(), and dukky_reset_start_time().

Referenced by dukky_destroythread(), js_closethread(), and js_newthread().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dukky_populate_object()

static duk_ret_t dukky_populate_object ( duk_context ctx,
void *  udata 
)
static

Definition at line 78 of file dukky.c.

References duk_call(), duk_dup(), duk_get_global_string(), duk_get_int(), duk_get_prop(), duk_get_prop_string(), duk_get_string(), duk_insert(), duk_is_undefined(), duk_pop(), duk_pop_2(), duk_push_string(), duk_remove(), duk_set_prototype(), and NSLOG.

Referenced by dukky_create_object(), and dukky_push_node_stacked().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dukky_push_context_dump()

static duk_int_t dukky_push_context_dump ( duk_context ctx,
void *  udata 
)
static

Definition at line 903 of file dukky.c.

References duk_push_context_dump().

Referenced by dukky_log_stack_frame().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dukky_push_event()

void dukky_push_event ( duk_context ctx,
dom_event *  evt 
)

Definition at line 1006 of file dukky.c.

References duk_dup(), DUK_EXEC_SUCCESS, duk_get_global_string(), duk_get_prop(), duk_is_undefined(), duk_pop(), duk_push_object(), duk_push_pointer(), duk_put_prop(), duk_replace(), dukky_create_object(), dukky_event_proto(), and EVENT_MAGIC.

Referenced by dukky_generic_event_handler(), and js_fire_event().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dukky_push_generics()

void dukky_push_generics ( duk_context ctx,
const char *  generic 
)

Definition at line 892 of file dukky.c.

References duk_get_global_string(), duk_get_prop_string(), duk_remove(), and GENERICS_MAGIC.

Here is the call graph for this function:

◆ dukky_push_handler_code_()

static void dukky_push_handler_code_ ( duk_context ctx,
dom_string *  name,
dom_event_target *  et 
)
static

Definition at line 1040 of file dukky.c.

References duk_push_lstring().

Referenced by dukky_get_current_value_of_event_handler().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dukky_push_node()

duk_bool_t dukky_push_node ( duk_context ctx,
struct dom_node *  node 
)

Definition at line 482 of file dukky.c.

References duk_dup(), duk_get_global_string(), duk_get_prop(), duk_insert(), duk_is_undefined(), duk_pop(), duk_pop_2(), duk_push_pointer(), duk_safe_to_string, dukky_push_node_klass(), dukky_push_node_stacked(), NSLOG, NSLOG_COMPILED_MIN_LEVEL, and NSLOG_LEVEL_DEEPDEBUG.

Referenced by dukky_generic_event_handler(), dukky_register_event_listener_for(), and js_fire_event().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dukky_push_node_klass()

static void dukky_push_node_klass ( duk_context ctx,
struct dom_node *  node 
)
static

Definition at line 406 of file dukky.c.

References duk_push_lstring(), duk_push_string(), dukky_html_element_class_from_tag_type(), NSLOG, and type.

Referenced by dukky_push_node().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dukky_push_node_stacked()

duk_bool_t dukky_push_node_stacked ( duk_context ctx)

Definition at line 147 of file dukky.c.

References duk_dup(), DUK_EXEC_SUCCESS, duk_get_global_string(), duk_get_prop(), duk_get_top(), duk_insert(), duk_is_undefined(), duk_pop(), duk_pop_3(), duk_push_int(), duk_push_object(), duk_put_prop(), duk_put_prop_string(), duk_safe_call(), duk_safe_to_string, duk_set_top(), dukky_populate_object(), HANDLER_LISTENER_MAGIC, HANDLER_MAGIC, NSLOG, NSLOG_COMPILED_MIN_LEVEL, and NSLOG_LEVEL_DEEPDEBUG.

Referenced by dukky_push_node().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dukky_realloc_function()

static void * dukky_realloc_function ( void *  udata,
void *  ptr,
duk_size_t  size 
)
static

Definition at line 556 of file dukky.c.

Referenced by js_newheap().

Here is the caller graph for this function:

◆ dukky_register_event_listener_for()

void dukky_register_event_listener_for ( duk_context ctx,
struct dom_element *  ele,
dom_string *  name,
bool  capture 
)

Definition at line 1344 of file dukky.c.

References duk_get_prop_string(), duk_has_prop(), duk_pop_2(), duk_push_boolean(), duk_push_global_object(), duk_push_lstring(), duk_put_prop(), dukky_generic_event_handler(), dukky_push_node(), HANDLER_LISTENER_MAGIC, and NSLOG.

Referenced by js_handle_new_element().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dukky_reset_start_time()

static void dukky_reset_start_time ( duk_context ctx)
static

Definition at line 867 of file dukky.c.

References duk_get_memory_functions(), jsheap::exec_start_time, and duk_memory_functions::udata.

Referenced by dukky_generic_event_handler(), dukky_pcall(), js_exec(), and js_fire_event().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dukky_shuffle_array()

void dukky_shuffle_array ( duk_context ctx,
duk_uarridx_t  idx 
)

Definition at line 1458 of file dukky.c.

References duk_del_prop_index(), duk_get_prop_index(), duk_pop(), and duk_put_prop_index().

Referenced by dukky_generic_event_handler().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ js_closethread()

nserror js_closethread ( jsthread thread)

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.

Parameters
threadThe thread to close down
Returns
NSERROR_OK on success, appropriate error otherwise

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ js_destroyheap()

void js_destroyheap ( jsheap heap)

Destroy a previously created heap.

Parameters
heapThe 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ js_destroythread()

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.

Parameters
threadThe 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ js_event_cleanup()

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ js_exec()

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ js_finalise()

void js_finalise ( void  )

finalise javascript interpreter

Definition at line 590 of file dukky.c.

Referenced by netsurf_exit().

Here is the caller graph for this function:

◆ js_fire_event()

bool js_fire_event ( jsthread thread,
const char *  type,
struct dom_document *  doc,
struct dom_node *  target 
)

fire an event at a dom node

Todo:
Make this more generic, this only handles load and only targetting the window, so that we actually stand a chance of getting 3.4 out.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ js_handle_new_element()

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ js_initialise()

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ js_newheap()

nserror js_newheap ( int  timeout,
jsheap **  heap 
)

Create a new javascript heap.

There is usually one heap per browser window.

Parameters
timeoutelapsed wallclock time (in seconds) before callback is called
heapUpdated to the created JS heap
Returns
NSERROR_OK on success, appropriate error otherwise.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ js_newthread()

nserror js_newthread ( jsheap heap,
void *  win_priv,
void *  doc_priv,
jsthread **  thread 
)

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.

Parameters
heapThe heap to create the thread within
win_privThe value to give to the Window constructor as the window
doc_privThe value to give to the Document constructor as the document
threadUpdated to the created thread
Returns
NSERROR_OK on success, appropriate error otherwise

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().

Here is the call graph for this function:
Here is the caller graph for this function: