1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

[ecmascript] Added ecmascript_string_item_list.

This struct will contain info about current script element.
This commit is contained in:
Witold Filipczyk 2022-11-14 21:17:24 +01:00
parent 71174f6ddf
commit 0ff62b5ee8
7 changed files with 79 additions and 25 deletions

View File

@ -293,7 +293,7 @@ reset_document(struct document *document)
free_uri_list(&document->css_imports);
#endif
#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);
mem_free_set(&document->text, NULL);
/// kill_timer(&document->timeout);
@ -363,7 +363,7 @@ done_document(struct document *document)
free_uri_list(&document->css_imports);
#endif
#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);
{

View File

@ -16,6 +16,7 @@ extern "C" {
struct cache_entry;
struct document_refresh;
struct ecmascript_string_list_item;
struct ecmascript_timeout;
struct el_form_control;
struct frame_desc;
@ -211,7 +212,7 @@ struct document {
* by an external reference - you must wait with processing other items
* until it gets resolved and loaded. New items are guaranteed to
* 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
* dependencies between the various entries so nothing gets removed
* unneeded. */

View File

@ -310,8 +310,8 @@ not_processed:
/* Create URL reference onload snippet. */
insert_in_string(&import_url, 0, "^", 1);
add_to_string_list(&html_context->part->document->onload_snippets,
import_url, -1);
add_to_ecmascript_string_list(&html_context->part->document->onload_snippets,
import_url, -1, html_top->name - html_context->part->document->text);
imported:
/* Retreat. Do not permit nested scripts, tho'. */
@ -390,8 +390,8 @@ imported:
}
if (html_context->part->document && *html != '^') {
add_to_string_list(&html_context->part->document->onload_snippets,
html, *end - html);
add_to_ecmascript_string_list(&html_context->part->document->onload_snippets,
html, *end - html, html_top->name - html_context->part->document->text);
}
#endif
}

View File

@ -109,8 +109,8 @@ kill_html_stack_item(struct html_context *html_context, struct html_element *e)
&& html_context->part->document
&& onload && *onload && *onload != '^') {
/* XXX: The following expression alone amounts two #includes. */
add_to_string_list(&html_context->part->document->onload_snippets,
onload, -1);
add_to_ecmascript_string_list(&html_context->part->document->onload_snippets,
onload, -1, 0);
}
mem_free_if(onload);
#endif

View File

@ -64,10 +64,10 @@
* But I want to take no risk by reworking that now. --pasky */
static void
add_snippets(struct ecmascript_interpreter *interpreter,
LIST_OF(struct string_list_item) *doc_snippets,
LIST_OF(struct string_list_item) *queued_snippets)
LIST_OF(struct ecmascript_string_list_item) *doc_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
if (list_empty(*queued_snippets) && interpreter->vs->doc_view->session)
@ -86,10 +86,10 @@ add_snippets(struct ecmascript_interpreter *interpreter,
* again. */
#ifdef CONFIG_DEBUG
/* 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) {
if (doc_current == (struct string_list_item *) doc_snippets) {
while (iterator != (struct ecmascript_string_list_item *) queued_snippets) {
if (doc_current == (struct ecmascript_string_list_item *) doc_snippets) {
INTERNAL("add_snippets(): doc_snippets shorter than queued_snippets!");
return;
}
@ -111,10 +111,10 @@ add_snippets(struct ecmascript_interpreter *interpreter,
}
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) {
add_to_string_list(queued_snippets, doc_current->string.source,
doc_current->string.length);
add_to_ecmascript_string_list(queued_snippets, doc_current->string.source,
doc_current->string.length, doc_current->element_offset);
#if 0
DBG("Adding snippet\n%.*s\n #####",
doc_current->string.length,
@ -125,12 +125,12 @@ add_snippets(struct ecmascript_interpreter *interpreter,
static void
process_snippets(struct ecmascript_interpreter *interpreter,
LIST_OF(struct string_list_item) *snippets,
struct string_list_item **current)
LIST_OF(struct ecmascript_string_list_item) *snippets,
struct ecmascript_string_list_item **current)
{
if (!*current)
*current = (struct string_list_item *)snippets->next;
for (; *current != (struct string_list_item *) snippets;
*current = (struct ecmascript_string_list_item *)snippets->next;
for (; *current != (struct ecmascript_string_list_item *) snippets;
(*current) = (*current)->next) {
struct string *string = &(*current)->string;
char *uristring;

View File

@ -109,6 +109,50 @@ char *local_storage_filename;
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
is_prefix(char *prefix, char *url, int dl)
{
@ -276,7 +320,7 @@ ecmascript_put_interpreter(struct ecmascript_interpreter *interpreter)
#else
spidermonkey_put_interpreter(interpreter);
#endif
free_string_list(&interpreter->onload_snippets);
free_ecmascript_string_list(&interpreter->onload_snippets);
done_string(&interpreter->code);
/* Is it superfluous? */
if (interpreter->vs->doc_view) {

View File

@ -45,6 +45,11 @@ struct terminal;
struct uri;
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 view_state *vs;
@ -70,8 +75,8 @@ struct ecmascript_interpreter {
* any new snippets in document.onload_snippets). Instead, as we
* go through the list we maintain a pointer to the last processed
* entry. */
LIST_OF(struct string_list_item) onload_snippets;
struct string_list_item *current_onload_snippet;
LIST_OF(struct ecmascript_string_list_item) onload_snippets;
struct ecmascript_string_list_item *current_onload_snippet;
/* 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
@ -190,6 +195,10 @@ void free_document(void *doc);
void location_goto(struct document_view *doc_view, 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_log_filename;