mirror of
https://github.com/rkd77/elinks.git
synced 2024-11-02 08:57:19 -04:00
[ecmascript] Added ecmascript_string_item_list.
This struct will contain info about current script element.
This commit is contained in:
parent
71174f6ddf
commit
0ff62b5ee8
@ -293,7 +293,7 @@ reset_document(struct document *document)
|
|||||||
free_uri_list(&document->css_imports);
|
free_uri_list(&document->css_imports);
|
||||||
#endif
|
#endif
|
||||||
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS)
|
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS)
|
||||||
free_string_list(&document->onload_snippets);
|
free_ecmascript_string_list(&document->onload_snippets);
|
||||||
free_uri_list(&document->ecmascript_imports);
|
free_uri_list(&document->ecmascript_imports);
|
||||||
mem_free_set(&document->text, NULL);
|
mem_free_set(&document->text, NULL);
|
||||||
/// kill_timer(&document->timeout);
|
/// kill_timer(&document->timeout);
|
||||||
@ -363,7 +363,7 @@ done_document(struct document *document)
|
|||||||
free_uri_list(&document->css_imports);
|
free_uri_list(&document->css_imports);
|
||||||
#endif
|
#endif
|
||||||
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS)
|
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS)
|
||||||
free_string_list(&document->onload_snippets);
|
free_ecmascript_string_list(&document->onload_snippets);
|
||||||
free_uri_list(&document->ecmascript_imports);
|
free_uri_list(&document->ecmascript_imports);
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -16,6 +16,7 @@ extern "C" {
|
|||||||
|
|
||||||
struct cache_entry;
|
struct cache_entry;
|
||||||
struct document_refresh;
|
struct document_refresh;
|
||||||
|
struct ecmascript_string_list_item;
|
||||||
struct ecmascript_timeout;
|
struct ecmascript_timeout;
|
||||||
struct el_form_control;
|
struct el_form_control;
|
||||||
struct frame_desc;
|
struct frame_desc;
|
||||||
@ -211,7 +212,7 @@ struct document {
|
|||||||
* by an external reference - you must wait with processing other items
|
* by an external reference - you must wait with processing other items
|
||||||
* until it gets resolved and loaded. New items are guaranteed to
|
* until it gets resolved and loaded. New items are guaranteed to
|
||||||
* always appear at the list end. */
|
* always appear at the list end. */
|
||||||
LIST_OF(struct string_list_item) onload_snippets;
|
LIST_OF(struct ecmascript_string_list_item) onload_snippets;
|
||||||
/** @todo FIXME: We should externally maybe using cache_entry store the
|
/** @todo FIXME: We should externally maybe using cache_entry store the
|
||||||
* dependencies between the various entries so nothing gets removed
|
* dependencies between the various entries so nothing gets removed
|
||||||
* unneeded. */
|
* unneeded. */
|
||||||
|
@ -310,8 +310,8 @@ not_processed:
|
|||||||
|
|
||||||
/* Create URL reference onload snippet. */
|
/* Create URL reference onload snippet. */
|
||||||
insert_in_string(&import_url, 0, "^", 1);
|
insert_in_string(&import_url, 0, "^", 1);
|
||||||
add_to_string_list(&html_context->part->document->onload_snippets,
|
add_to_ecmascript_string_list(&html_context->part->document->onload_snippets,
|
||||||
import_url, -1);
|
import_url, -1, html_top->name - html_context->part->document->text);
|
||||||
|
|
||||||
imported:
|
imported:
|
||||||
/* Retreat. Do not permit nested scripts, tho'. */
|
/* Retreat. Do not permit nested scripts, tho'. */
|
||||||
@ -390,8 +390,8 @@ imported:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (html_context->part->document && *html != '^') {
|
if (html_context->part->document && *html != '^') {
|
||||||
add_to_string_list(&html_context->part->document->onload_snippets,
|
add_to_ecmascript_string_list(&html_context->part->document->onload_snippets,
|
||||||
html, *end - html);
|
html, *end - html, html_top->name - html_context->part->document->text);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -109,8 +109,8 @@ kill_html_stack_item(struct html_context *html_context, struct html_element *e)
|
|||||||
&& html_context->part->document
|
&& html_context->part->document
|
||||||
&& onload && *onload && *onload != '^') {
|
&& onload && *onload && *onload != '^') {
|
||||||
/* XXX: The following expression alone amounts two #includes. */
|
/* XXX: The following expression alone amounts two #includes. */
|
||||||
add_to_string_list(&html_context->part->document->onload_snippets,
|
add_to_ecmascript_string_list(&html_context->part->document->onload_snippets,
|
||||||
onload, -1);
|
onload, -1, 0);
|
||||||
}
|
}
|
||||||
mem_free_if(onload);
|
mem_free_if(onload);
|
||||||
#endif
|
#endif
|
||||||
|
@ -64,10 +64,10 @@
|
|||||||
* But I want to take no risk by reworking that now. --pasky */
|
* But I want to take no risk by reworking that now. --pasky */
|
||||||
static void
|
static void
|
||||||
add_snippets(struct ecmascript_interpreter *interpreter,
|
add_snippets(struct ecmascript_interpreter *interpreter,
|
||||||
LIST_OF(struct string_list_item) *doc_snippets,
|
LIST_OF(struct ecmascript_string_list_item) *doc_snippets,
|
||||||
LIST_OF(struct string_list_item) *queued_snippets)
|
LIST_OF(struct ecmascript_string_list_item) *queued_snippets)
|
||||||
{
|
{
|
||||||
struct string_list_item *doc_current = (struct string_list_item *)doc_snippets->next;
|
struct ecmascript_string_list_item *doc_current = (struct ecmascript_string_list_item *)doc_snippets->next;
|
||||||
|
|
||||||
#ifdef CONFIG_LEDS
|
#ifdef CONFIG_LEDS
|
||||||
if (list_empty(*queued_snippets) && interpreter->vs->doc_view->session)
|
if (list_empty(*queued_snippets) && interpreter->vs->doc_view->session)
|
||||||
@ -86,10 +86,10 @@ add_snippets(struct ecmascript_interpreter *interpreter,
|
|||||||
* again. */
|
* again. */
|
||||||
#ifdef CONFIG_DEBUG
|
#ifdef CONFIG_DEBUG
|
||||||
/* Hopefully. */
|
/* Hopefully. */
|
||||||
struct string_list_item *iterator = queued_snippets->next;
|
struct ecmascript_string_list_item *iterator = queued_snippets->next;
|
||||||
|
|
||||||
while (iterator != (struct string_list_item *) queued_snippets) {
|
while (iterator != (struct ecmascript_string_list_item *) queued_snippets) {
|
||||||
if (doc_current == (struct string_list_item *) doc_snippets) {
|
if (doc_current == (struct ecmascript_string_list_item *) doc_snippets) {
|
||||||
INTERNAL("add_snippets(): doc_snippets shorter than queued_snippets!");
|
INTERNAL("add_snippets(): doc_snippets shorter than queued_snippets!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -111,10 +111,10 @@ add_snippets(struct ecmascript_interpreter *interpreter,
|
|||||||
}
|
}
|
||||||
|
|
||||||
assert(doc_current);
|
assert(doc_current);
|
||||||
for (; doc_current != (struct string_list_item *) doc_snippets;
|
for (; doc_current != (struct ecmascript_string_list_item *) doc_snippets;
|
||||||
doc_current = doc_current->next) {
|
doc_current = doc_current->next) {
|
||||||
add_to_string_list(queued_snippets, doc_current->string.source,
|
add_to_ecmascript_string_list(queued_snippets, doc_current->string.source,
|
||||||
doc_current->string.length);
|
doc_current->string.length, doc_current->element_offset);
|
||||||
#if 0
|
#if 0
|
||||||
DBG("Adding snippet\n%.*s\n #####",
|
DBG("Adding snippet\n%.*s\n #####",
|
||||||
doc_current->string.length,
|
doc_current->string.length,
|
||||||
@ -125,12 +125,12 @@ add_snippets(struct ecmascript_interpreter *interpreter,
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
process_snippets(struct ecmascript_interpreter *interpreter,
|
process_snippets(struct ecmascript_interpreter *interpreter,
|
||||||
LIST_OF(struct string_list_item) *snippets,
|
LIST_OF(struct ecmascript_string_list_item) *snippets,
|
||||||
struct string_list_item **current)
|
struct ecmascript_string_list_item **current)
|
||||||
{
|
{
|
||||||
if (!*current)
|
if (!*current)
|
||||||
*current = (struct string_list_item *)snippets->next;
|
*current = (struct ecmascript_string_list_item *)snippets->next;
|
||||||
for (; *current != (struct string_list_item *) snippets;
|
for (; *current != (struct ecmascript_string_list_item *) snippets;
|
||||||
(*current) = (*current)->next) {
|
(*current) = (*current)->next) {
|
||||||
struct string *string = &(*current)->string;
|
struct string *string = &(*current)->string;
|
||||||
char *uristring;
|
char *uristring;
|
||||||
|
@ -109,6 +109,50 @@ char *local_storage_filename;
|
|||||||
|
|
||||||
int local_storage_ready;
|
int local_storage_ready;
|
||||||
|
|
||||||
|
struct string *
|
||||||
|
add_to_ecmascript_string_list(LIST_OF(struct ecmascript_string_list_item) *list,
|
||||||
|
const char *source, int length, int element_offset)
|
||||||
|
{
|
||||||
|
struct ecmascript_string_list_item *item;
|
||||||
|
struct string *string;
|
||||||
|
|
||||||
|
assertm(list && source, "[add_to_string_list]");
|
||||||
|
if_assert_failed return NULL;
|
||||||
|
|
||||||
|
item = (struct ecmascript_string_list_item *)mem_alloc(sizeof(*item));
|
||||||
|
if (!item) return NULL;
|
||||||
|
|
||||||
|
string = &item->string;
|
||||||
|
if (length < 0) length = strlen(source);
|
||||||
|
|
||||||
|
if (!init_string(string)
|
||||||
|
|| !add_bytes_to_string(string, source, length)) {
|
||||||
|
done_string(string);
|
||||||
|
mem_free(item);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
item->element_offset = element_offset;
|
||||||
|
|
||||||
|
add_to_list_end(*list, item);
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
free_ecmascript_string_list(LIST_OF(struct ecmascript_string_list_item) *list)
|
||||||
|
{
|
||||||
|
assertm(list != NULL, "[free_string_list]");
|
||||||
|
if_assert_failed return;
|
||||||
|
|
||||||
|
while (!list_empty(*list)) {
|
||||||
|
struct ecmascript_string_list_item *item = (struct ecmascript_string_list_item *)list->next;
|
||||||
|
|
||||||
|
del_from_list(item);
|
||||||
|
done_string(&item->string);
|
||||||
|
mem_free(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
is_prefix(char *prefix, char *url, int dl)
|
is_prefix(char *prefix, char *url, int dl)
|
||||||
{
|
{
|
||||||
@ -276,7 +320,7 @@ ecmascript_put_interpreter(struct ecmascript_interpreter *interpreter)
|
|||||||
#else
|
#else
|
||||||
spidermonkey_put_interpreter(interpreter);
|
spidermonkey_put_interpreter(interpreter);
|
||||||
#endif
|
#endif
|
||||||
free_string_list(&interpreter->onload_snippets);
|
free_ecmascript_string_list(&interpreter->onload_snippets);
|
||||||
done_string(&interpreter->code);
|
done_string(&interpreter->code);
|
||||||
/* Is it superfluous? */
|
/* Is it superfluous? */
|
||||||
if (interpreter->vs->doc_view) {
|
if (interpreter->vs->doc_view) {
|
||||||
|
@ -45,6 +45,11 @@ struct terminal;
|
|||||||
struct uri;
|
struct uri;
|
||||||
struct view_state;
|
struct view_state;
|
||||||
|
|
||||||
|
struct ecmascript_string_list_item {
|
||||||
|
LIST_HEAD(struct ecmascript_string_list_item);
|
||||||
|
struct string string;
|
||||||
|
int element_offset;
|
||||||
|
};
|
||||||
|
|
||||||
struct ecmascript_interpreter {
|
struct ecmascript_interpreter {
|
||||||
struct view_state *vs;
|
struct view_state *vs;
|
||||||
@ -70,8 +75,8 @@ struct ecmascript_interpreter {
|
|||||||
* any new snippets in document.onload_snippets). Instead, as we
|
* any new snippets in document.onload_snippets). Instead, as we
|
||||||
* go through the list we maintain a pointer to the last processed
|
* go through the list we maintain a pointer to the last processed
|
||||||
* entry. */
|
* entry. */
|
||||||
LIST_OF(struct string_list_item) onload_snippets;
|
LIST_OF(struct ecmascript_string_list_item) onload_snippets;
|
||||||
struct string_list_item *current_onload_snippet;
|
struct ecmascript_string_list_item *current_onload_snippet;
|
||||||
|
|
||||||
/* ID of the {struct document} where those onload_snippets belong to.
|
/* ID of the {struct document} where those onload_snippets belong to.
|
||||||
* It is kept at 0 until it is definitively hard-attached to a given
|
* It is kept at 0 until it is definitively hard-attached to a given
|
||||||
@ -190,6 +195,10 @@ void free_document(void *doc);
|
|||||||
void location_goto(struct document_view *doc_view, char *url);
|
void location_goto(struct document_view *doc_view, char *url);
|
||||||
void location_goto_const(struct document_view *doc_view, const char *url);
|
void location_goto_const(struct document_view *doc_view, const char *url);
|
||||||
|
|
||||||
|
struct string *add_to_ecmascript_string_list(LIST_OF(struct ecmascript_string_list_item) *list, const char *string, int length, int element_offset);
|
||||||
|
|
||||||
|
void free_ecmascript_string_list(LIST_OF(struct ecmascript_string_list_item) *list);
|
||||||
|
|
||||||
extern char *console_error_filename;
|
extern char *console_error_filename;
|
||||||
extern char *console_log_filename;
|
extern char *console_log_filename;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user