From ab1f90941687eda4e02954dde150aae7addfd34e Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Sat, 21 Sep 2024 12:42:31 +0200 Subject: [PATCH] [ecmascript] Fix location.reload --- src/ecmascript/ecmascript.c | 9 +++++---- src/ecmascript/ecmascript.h | 5 +++-- src/ecmascript/mujs/document.c | 2 +- src/ecmascript/mujs/location.c | 23 ++++++++++++----------- src/ecmascript/mujs/window.c | 2 +- src/ecmascript/quickjs/document.c | 4 ++-- src/ecmascript/quickjs/location.c | 23 ++++++++++++----------- src/ecmascript/quickjs/window.c | 2 +- src/ecmascript/spidermonkey/document.cpp | 4 ++-- src/ecmascript/spidermonkey/location.cpp | 8 ++++---- src/ecmascript/spidermonkey/window.cpp | 5 +---- 11 files changed, 44 insertions(+), 43 deletions(-) diff --git a/src/ecmascript/ecmascript.c b/src/ecmascript/ecmascript.c index 5f488cbbf..cce889281 100644 --- a/src/ecmascript/ecmascript.c +++ b/src/ecmascript/ecmascript.c @@ -754,25 +754,25 @@ delayed_goto(void *data) if (deg->vs->doc_view) { goto_uri_frame(deg->vs->doc_view->session, deg->uri, deg->vs->doc_view->name, - CACHE_MODE_NORMAL); + deg->reload ? CACHE_MODE_FORCE_RELOAD : CACHE_MODE_NORMAL); } done_uri(deg->uri); mem_free(deg); } void -location_goto_const(struct document_view *doc_view, const char *url) +location_goto_const(struct document_view *doc_view, const char *url, int reload) { char *url2 = stracpy(url); if (url2) { - location_goto(doc_view, url2); + location_goto(doc_view, url2, reload); mem_free(url2); } } void -location_goto(struct document_view *doc_view, char *url) +location_goto(struct document_view *doc_view, char *url, int reload) { char *new_abs_url; struct uri *new_uri; @@ -796,6 +796,7 @@ location_goto(struct document_view *doc_view, char *url) assert(doc_view->vs); deg->vs = doc_view->vs; deg->uri = new_uri; + deg->reload = reload; /* It does not seem to be very safe inside of frames to * call goto_uri() right away. */ register_bottom_half(delayed_goto, deg); diff --git a/src/ecmascript/ecmascript.h b/src/ecmascript/ecmascript.h index 662c8a10b..9d780e070 100644 --- a/src/ecmascript/ecmascript.h +++ b/src/ecmascript/ecmascript.h @@ -143,6 +143,7 @@ struct delayed_goto { * disappear during wild dances inside of frames or so. */ struct view_state *vs; struct uri *uri; + unsigned int reload:1; }; /* Why is the interpreter bound to {struct view_state} instead of {struct @@ -190,8 +191,8 @@ void check_for_rerender(struct ecmascript_interpreter *interpreter, const char* void toggle_ecmascript(struct session *ses); -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(struct document_view *doc_view, char *url, int reload); +void location_goto_const(struct document_view *doc_view, const char *url, int reload); extern char *console_error_filename; extern char *console_log_filename; diff --git a/src/ecmascript/mujs/document.c b/src/ecmascript/mujs/document.c index 27f8fedfb..1333d6349 100644 --- a/src/ecmascript/mujs/document.c +++ b/src/ecmascript/mujs/document.c @@ -803,7 +803,7 @@ mjs_document_set_property_url(js_State *J) js_error(J, "!url"); return; } - location_goto_const(doc_view, url); + location_goto_const(doc_view, url, 0); js_pushundefined(J); } diff --git a/src/ecmascript/mujs/location.c b/src/ecmascript/mujs/location.c index 2dc72f66b..de9912991 100644 --- a/src/ecmascript/mujs/location.c +++ b/src/ecmascript/mujs/location.c @@ -10,6 +10,7 @@ #include "elinks.h" +#include "document/document.h" #include "document/view.h" #include "ecmascript/ecmascript.h" #include "ecmascript/mujs.h" @@ -319,7 +320,7 @@ mjs_location_set_property_hash(js_State *J) js_error(J, "!str"); return; } - location_goto_const(vs->doc_view, str); + location_goto_const(vs->doc_view, str, 0); js_pushundefined(J); } @@ -345,7 +346,7 @@ mjs_location_set_property_host(js_State *J) js_error(J, "!str"); return; } - location_goto_const(vs->doc_view, str); + location_goto_const(vs->doc_view, str, 0); js_pushundefined(J); } @@ -371,7 +372,7 @@ mjs_location_set_property_hostname(js_State *J) js_error(J, "!str"); return; } - location_goto_const(vs->doc_view, str); + location_goto_const(vs->doc_view, str, 0); js_pushundefined(J); } @@ -397,7 +398,7 @@ mjs_location_set_property_href(js_State *J) js_error(J, "!str"); return; } - location_goto_const(vs->doc_view, str); + location_goto_const(vs->doc_view, str, 0); js_pushundefined(J); } @@ -423,7 +424,7 @@ mjs_location_set_property_pathname(js_State *J) js_error(J, "!str"); return; } - location_goto_const(vs->doc_view, str); + location_goto_const(vs->doc_view, str, 0); js_pushundefined(J); } @@ -449,7 +450,7 @@ mjs_location_set_property_port(js_State *J) js_error(J, "!str"); return; } - location_goto_const(vs->doc_view, str); + location_goto_const(vs->doc_view, str, 0); js_pushundefined(J); } @@ -475,7 +476,7 @@ mjs_location_set_property_protocol(js_State *J) js_error(J, "!str"); return; } - location_goto_const(vs->doc_view, str); + location_goto_const(vs->doc_view, str, 0); js_pushundefined(J); } @@ -501,7 +502,7 @@ mjs_location_set_property_search(js_State *J) js_error(J, "!str"); return; } - location_goto_const(vs->doc_view, str); + location_goto_const(vs->doc_view, str, 0); js_pushundefined(J); } @@ -528,7 +529,7 @@ mjs_location_assign(js_State *J) js_error(J, "out of memory"); return; } - location_goto_const(vs->doc_view, url); + location_goto_const(vs->doc_view, url, 0); js_pushundefined(J); } @@ -548,7 +549,7 @@ mjs_location_reload(js_State *J) js_error(J, "!vs"); return; } - location_goto_const(vs->doc_view, ""); + location_goto_const(vs->doc_view, struri(vs->doc_view->document->uri), 1); js_pushundefined(J); } @@ -584,7 +585,7 @@ mjs_location_replace(js_State *J) del_from_history(&ses->history, loc); } } - location_goto_const(vs->doc_view, url); + location_goto_const(vs->doc_view, url, 0); js_pushundefined(J); } diff --git a/src/ecmascript/mujs/window.c b/src/ecmascript/mujs/window.c index 2110fe046..765687c96 100644 --- a/src/ecmascript/mujs/window.c +++ b/src/ecmascript/mujs/window.c @@ -204,7 +204,7 @@ mjs_window_set_property_location(js_State *J) js_pushnull(J); return; } - location_goto_const(doc_view, url); + location_goto_const(doc_view, url, 0); js_pushundefined(J); } diff --git a/src/ecmascript/quickjs/document.c b/src/ecmascript/quickjs/document.c index dcde47b24..aa69b9f61 100644 --- a/src/ecmascript/quickjs/document.c +++ b/src/ecmascript/quickjs/document.c @@ -636,7 +636,7 @@ js_document_set_property_location(JSContext *ctx, JSValueConst this_val, JSValue return JS_EXCEPTION; } - location_goto_const(doc_view, url); + location_goto_const(doc_view, url, 0); JS_FreeCString(ctx, url); return JS_UNDEFINED; @@ -889,7 +889,7 @@ js_document_set_property_url(JSContext *ctx, JSValueConst this_val, JSValue val) if (!url) { return JS_EXCEPTION; } - location_goto_const(doc_view, url); + location_goto_const(doc_view, url, 0); JS_FreeCString(ctx, url); return JS_UNDEFINED; diff --git a/src/ecmascript/quickjs/location.c b/src/ecmascript/quickjs/location.c index 69b27e46f..ae185cd59 100644 --- a/src/ecmascript/quickjs/location.c +++ b/src/ecmascript/quickjs/location.c @@ -10,6 +10,7 @@ #include "elinks.h" +#include "document/document.h" #include "document/view.h" #include "ecmascript/ecmascript.h" #include "ecmascript/quickjs.h" @@ -352,7 +353,7 @@ js_location_set_property_hash(JSContext *ctx, JSValueConst this_val, JSValue val if (!str) { return JS_EXCEPTION; } - location_goto_const(vs->doc_view, str); + location_goto_const(vs->doc_view, str, 0); JS_FreeCString(ctx, str); return JS_UNDEFINED; @@ -383,7 +384,7 @@ js_location_set_property_host(JSContext *ctx, JSValueConst this_val, JSValue val if (!str) { return JS_EXCEPTION; } - location_goto_const(vs->doc_view, str); + location_goto_const(vs->doc_view, str, 0); JS_FreeCString(ctx, str); return JS_UNDEFINED; @@ -414,7 +415,7 @@ js_location_set_property_hostname(JSContext *ctx, JSValueConst this_val, JSValue if (!str) { return JS_EXCEPTION; } - location_goto_const(vs->doc_view, str); + location_goto_const(vs->doc_view, str, 0); JS_FreeCString(ctx, str); return JS_UNDEFINED; @@ -445,7 +446,7 @@ js_location_set_property_href(JSContext *ctx, JSValueConst this_val, JSValue val if (!str) { return JS_EXCEPTION; } - location_goto_const(vs->doc_view, str); + location_goto_const(vs->doc_view, str, 0); JS_FreeCString(ctx, str); return JS_UNDEFINED; @@ -476,7 +477,7 @@ js_location_set_property_pathname(JSContext *ctx, JSValueConst this_val, JSValue if (!str) { return JS_EXCEPTION; } - location_goto_const(vs->doc_view, str); + location_goto_const(vs->doc_view, str, 0); JS_FreeCString(ctx, str); return JS_UNDEFINED; @@ -507,7 +508,7 @@ js_location_set_property_port(JSContext *ctx, JSValueConst this_val, JSValue val if (!str) { return JS_EXCEPTION; } - location_goto_const(vs->doc_view, str); + location_goto_const(vs->doc_view, str, 0); JS_FreeCString(ctx, str); return JS_UNDEFINED; @@ -538,7 +539,7 @@ js_location_set_property_protocol(JSContext *ctx, JSValueConst this_val, JSValue if (!str) { return JS_EXCEPTION; } - location_goto_const(vs->doc_view, str); + location_goto_const(vs->doc_view, str, 0); JS_FreeCString(ctx, str); return JS_UNDEFINED; @@ -569,7 +570,7 @@ js_location_set_property_search(JSContext *ctx, JSValueConst this_val, JSValue v if (!str) { return JS_EXCEPTION; } - location_goto_const(vs->doc_view, str); + location_goto_const(vs->doc_view, str, 0); JS_FreeCString(ctx, str); return JS_UNDEFINED; @@ -597,7 +598,7 @@ js_location_assign(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst if (!url) { return JS_EXCEPTION; } - location_goto_const(vs->doc_view, url); + location_goto_const(vs->doc_view, url, 0); JS_FreeCString(ctx, url); return JS_UNDEFINED; @@ -620,7 +621,7 @@ js_location_reload(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst #endif return JS_EXCEPTION; } - location_goto_const(vs->doc_view, ""); + location_goto_const(vs->doc_view, struri(vs->doc_view->document->uri), 1); return JS_UNDEFINED; } @@ -656,7 +657,7 @@ js_location_replace(JSContext *ctx, JSValueConst this_val, int argc, JSValueCons del_from_history(&ses->history, loc); } } - location_goto_const(vs->doc_view, url); + location_goto_const(vs->doc_view, url, 0); JS_FreeCString(ctx, url); return JS_UNDEFINED; diff --git a/src/ecmascript/quickjs/window.c b/src/ecmascript/quickjs/window.c index 22a509e1a..02aca6ae2 100644 --- a/src/ecmascript/quickjs/window.c +++ b/src/ecmascript/quickjs/window.c @@ -573,7 +573,7 @@ js_window_set_property_location(JSContext *ctx, JSValueConst this_val, JSValue v return JS_EXCEPTION; } - location_goto_const(doc_view, url); + location_goto_const(doc_view, url, 0); JS_FreeCString(ctx, url); return JS_UNDEFINED; diff --git a/src/ecmascript/spidermonkey/document.cpp b/src/ecmascript/spidermonkey/document.cpp index bfcae01f9..18d487e07 100644 --- a/src/ecmascript/spidermonkey/document.cpp +++ b/src/ecmascript/spidermonkey/document.cpp @@ -875,7 +875,7 @@ document_set_property_location(JSContext *ctx, unsigned int argc, JS::Value *vp) char *url = jsval_to_string(ctx, args[0]); if (url) { - location_goto(doc_view, url); + location_goto(doc_view, url, 0); mem_free(url); } @@ -1131,7 +1131,7 @@ document_set_property_url(JSContext *ctx, unsigned int argc, JS::Value *vp) doc_view = vs->doc_view; char *url = jsval_to_string(ctx, args[0]); if (url) { - location_goto(doc_view, url); + location_goto(doc_view, url, 0); mem_free(url); } diff --git a/src/ecmascript/spidermonkey/location.cpp b/src/ecmascript/spidermonkey/location.cpp index cda707357..5ebdf80f5 100644 --- a/src/ecmascript/spidermonkey/location.cpp +++ b/src/ecmascript/spidermonkey/location.cpp @@ -1004,7 +1004,7 @@ location_assign(JSContext *ctx, unsigned int argc, JS::Value *rval) if (!url) { return false; } - location_goto(doc_view, url); + location_goto(doc_view, url, 0); mem_free(url); return true; @@ -1050,7 +1050,7 @@ location_reload(JSContext *ctx, unsigned int argc, JS::Value *rval) return false; } doc_view = vs->doc_view; - location_goto_const(doc_view, ""); + location_goto_const(doc_view, struri(doc_view->document->uri), 1); return true; } @@ -1114,7 +1114,7 @@ location_replace(JSContext *ctx, unsigned int argc, JS::Value *rval) del_from_history(&ses->history, loc); } } - location_goto(doc_view, url); + location_goto(doc_view, url, 0); mem_free(url); return true; @@ -1144,7 +1144,7 @@ location_goto_common(JSContext *ctx, struct document_view *doc_view, JS::HandleV char *url = jsval_to_string(ctx, val); if (url) { - location_goto(doc_view, url); + location_goto(doc_view, url, 0); mem_free(url); } } diff --git a/src/ecmascript/spidermonkey/window.cpp b/src/ecmascript/spidermonkey/window.cpp index de76d5dc1..07db1a344 100644 --- a/src/ecmascript/spidermonkey/window.cpp +++ b/src/ecmascript/spidermonkey/window.cpp @@ -174,9 +174,6 @@ find_child_frame(struct document_view *doc_view, struct frame_desc *tframe) } #endif - -void location_goto(struct document_view *doc_view, char *url); - static bool window_addEventListener(JSContext *ctx, unsigned int argc, JS::Value *rval); static bool window_alert(JSContext *ctx, unsigned int argc, JS::Value *rval); static bool window_clearInterval(JSContext *ctx, unsigned int argc, JS::Value *rval); @@ -998,7 +995,7 @@ window_set_property_location(JSContext *ctx, unsigned int argc, JS::Value *vp) char *url = jsval_to_string(ctx, args[0]); if (url) { - location_goto(doc_view, url); + location_goto(doc_view, url, 0); mem_free(url); }