1
0
mirror of https://github.com/rkd77/elinks.git synced 2025-01-03 14:57:44 -05:00

[ecmascript] Fix location.reload

This commit is contained in:
Witold Filipczyk 2024-09-21 12:42:31 +02:00
parent 2133aca5a0
commit ab1f909416
11 changed files with 44 additions and 43 deletions

View File

@ -754,25 +754,25 @@ delayed_goto(void *data)
if (deg->vs->doc_view) { if (deg->vs->doc_view) {
goto_uri_frame(deg->vs->doc_view->session, deg->uri, goto_uri_frame(deg->vs->doc_view->session, deg->uri,
deg->vs->doc_view->name, deg->vs->doc_view->name,
CACHE_MODE_NORMAL); deg->reload ? CACHE_MODE_FORCE_RELOAD : CACHE_MODE_NORMAL);
} }
done_uri(deg->uri); done_uri(deg->uri);
mem_free(deg); mem_free(deg);
} }
void 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); char *url2 = stracpy(url);
if (url2) { if (url2) {
location_goto(doc_view, url2); location_goto(doc_view, url2, reload);
mem_free(url2); mem_free(url2);
} }
} }
void 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; char *new_abs_url;
struct uri *new_uri; struct uri *new_uri;
@ -796,6 +796,7 @@ location_goto(struct document_view *doc_view, char *url)
assert(doc_view->vs); assert(doc_view->vs);
deg->vs = doc_view->vs; deg->vs = doc_view->vs;
deg->uri = new_uri; deg->uri = new_uri;
deg->reload = reload;
/* It does not seem to be very safe inside of frames to /* It does not seem to be very safe inside of frames to
* call goto_uri() right away. */ * call goto_uri() right away. */
register_bottom_half(delayed_goto, deg); register_bottom_half(delayed_goto, deg);

View File

@ -143,6 +143,7 @@ struct delayed_goto {
* disappear during wild dances inside of frames or so. */ * disappear during wild dances inside of frames or so. */
struct view_state *vs; struct view_state *vs;
struct uri *uri; struct uri *uri;
unsigned int reload:1;
}; };
/* Why is the interpreter bound to {struct view_state} instead of {struct /* 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 toggle_ecmascript(struct session *ses);
void location_goto(struct document_view *doc_view, 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); void location_goto_const(struct document_view *doc_view, const char *url, int reload);
extern char *console_error_filename; extern char *console_error_filename;
extern char *console_log_filename; extern char *console_log_filename;

View File

@ -803,7 +803,7 @@ mjs_document_set_property_url(js_State *J)
js_error(J, "!url"); js_error(J, "!url");
return; return;
} }
location_goto_const(doc_view, url); location_goto_const(doc_view, url, 0);
js_pushundefined(J); js_pushundefined(J);
} }

View File

@ -10,6 +10,7 @@
#include "elinks.h" #include "elinks.h"
#include "document/document.h"
#include "document/view.h" #include "document/view.h"
#include "ecmascript/ecmascript.h" #include "ecmascript/ecmascript.h"
#include "ecmascript/mujs.h" #include "ecmascript/mujs.h"
@ -319,7 +320,7 @@ mjs_location_set_property_hash(js_State *J)
js_error(J, "!str"); js_error(J, "!str");
return; return;
} }
location_goto_const(vs->doc_view, str); location_goto_const(vs->doc_view, str, 0);
js_pushundefined(J); js_pushundefined(J);
} }
@ -345,7 +346,7 @@ mjs_location_set_property_host(js_State *J)
js_error(J, "!str"); js_error(J, "!str");
return; return;
} }
location_goto_const(vs->doc_view, str); location_goto_const(vs->doc_view, str, 0);
js_pushundefined(J); js_pushundefined(J);
} }
@ -371,7 +372,7 @@ mjs_location_set_property_hostname(js_State *J)
js_error(J, "!str"); js_error(J, "!str");
return; return;
} }
location_goto_const(vs->doc_view, str); location_goto_const(vs->doc_view, str, 0);
js_pushundefined(J); js_pushundefined(J);
} }
@ -397,7 +398,7 @@ mjs_location_set_property_href(js_State *J)
js_error(J, "!str"); js_error(J, "!str");
return; return;
} }
location_goto_const(vs->doc_view, str); location_goto_const(vs->doc_view, str, 0);
js_pushundefined(J); js_pushundefined(J);
} }
@ -423,7 +424,7 @@ mjs_location_set_property_pathname(js_State *J)
js_error(J, "!str"); js_error(J, "!str");
return; return;
} }
location_goto_const(vs->doc_view, str); location_goto_const(vs->doc_view, str, 0);
js_pushundefined(J); js_pushundefined(J);
} }
@ -449,7 +450,7 @@ mjs_location_set_property_port(js_State *J)
js_error(J, "!str"); js_error(J, "!str");
return; return;
} }
location_goto_const(vs->doc_view, str); location_goto_const(vs->doc_view, str, 0);
js_pushundefined(J); js_pushundefined(J);
} }
@ -475,7 +476,7 @@ mjs_location_set_property_protocol(js_State *J)
js_error(J, "!str"); js_error(J, "!str");
return; return;
} }
location_goto_const(vs->doc_view, str); location_goto_const(vs->doc_view, str, 0);
js_pushundefined(J); js_pushundefined(J);
} }
@ -501,7 +502,7 @@ mjs_location_set_property_search(js_State *J)
js_error(J, "!str"); js_error(J, "!str");
return; return;
} }
location_goto_const(vs->doc_view, str); location_goto_const(vs->doc_view, str, 0);
js_pushundefined(J); js_pushundefined(J);
} }
@ -528,7 +529,7 @@ mjs_location_assign(js_State *J)
js_error(J, "out of memory"); js_error(J, "out of memory");
return; return;
} }
location_goto_const(vs->doc_view, url); location_goto_const(vs->doc_view, url, 0);
js_pushundefined(J); js_pushundefined(J);
} }
@ -548,7 +549,7 @@ mjs_location_reload(js_State *J)
js_error(J, "!vs"); js_error(J, "!vs");
return; return;
} }
location_goto_const(vs->doc_view, ""); location_goto_const(vs->doc_view, struri(vs->doc_view->document->uri), 1);
js_pushundefined(J); js_pushundefined(J);
} }
@ -584,7 +585,7 @@ mjs_location_replace(js_State *J)
del_from_history(&ses->history, loc); del_from_history(&ses->history, loc);
} }
} }
location_goto_const(vs->doc_view, url); location_goto_const(vs->doc_view, url, 0);
js_pushundefined(J); js_pushundefined(J);
} }

View File

@ -204,7 +204,7 @@ mjs_window_set_property_location(js_State *J)
js_pushnull(J); js_pushnull(J);
return; return;
} }
location_goto_const(doc_view, url); location_goto_const(doc_view, url, 0);
js_pushundefined(J); js_pushundefined(J);
} }

View File

@ -636,7 +636,7 @@ js_document_set_property_location(JSContext *ctx, JSValueConst this_val, JSValue
return JS_EXCEPTION; return JS_EXCEPTION;
} }
location_goto_const(doc_view, url); location_goto_const(doc_view, url, 0);
JS_FreeCString(ctx, url); JS_FreeCString(ctx, url);
return JS_UNDEFINED; return JS_UNDEFINED;
@ -889,7 +889,7 @@ js_document_set_property_url(JSContext *ctx, JSValueConst this_val, JSValue val)
if (!url) { if (!url) {
return JS_EXCEPTION; return JS_EXCEPTION;
} }
location_goto_const(doc_view, url); location_goto_const(doc_view, url, 0);
JS_FreeCString(ctx, url); JS_FreeCString(ctx, url);
return JS_UNDEFINED; return JS_UNDEFINED;

View File

@ -10,6 +10,7 @@
#include "elinks.h" #include "elinks.h"
#include "document/document.h"
#include "document/view.h" #include "document/view.h"
#include "ecmascript/ecmascript.h" #include "ecmascript/ecmascript.h"
#include "ecmascript/quickjs.h" #include "ecmascript/quickjs.h"
@ -352,7 +353,7 @@ js_location_set_property_hash(JSContext *ctx, JSValueConst this_val, JSValue val
if (!str) { if (!str) {
return JS_EXCEPTION; return JS_EXCEPTION;
} }
location_goto_const(vs->doc_view, str); location_goto_const(vs->doc_view, str, 0);
JS_FreeCString(ctx, str); JS_FreeCString(ctx, str);
return JS_UNDEFINED; return JS_UNDEFINED;
@ -383,7 +384,7 @@ js_location_set_property_host(JSContext *ctx, JSValueConst this_val, JSValue val
if (!str) { if (!str) {
return JS_EXCEPTION; return JS_EXCEPTION;
} }
location_goto_const(vs->doc_view, str); location_goto_const(vs->doc_view, str, 0);
JS_FreeCString(ctx, str); JS_FreeCString(ctx, str);
return JS_UNDEFINED; return JS_UNDEFINED;
@ -414,7 +415,7 @@ js_location_set_property_hostname(JSContext *ctx, JSValueConst this_val, JSValue
if (!str) { if (!str) {
return JS_EXCEPTION; return JS_EXCEPTION;
} }
location_goto_const(vs->doc_view, str); location_goto_const(vs->doc_view, str, 0);
JS_FreeCString(ctx, str); JS_FreeCString(ctx, str);
return JS_UNDEFINED; return JS_UNDEFINED;
@ -445,7 +446,7 @@ js_location_set_property_href(JSContext *ctx, JSValueConst this_val, JSValue val
if (!str) { if (!str) {
return JS_EXCEPTION; return JS_EXCEPTION;
} }
location_goto_const(vs->doc_view, str); location_goto_const(vs->doc_view, str, 0);
JS_FreeCString(ctx, str); JS_FreeCString(ctx, str);
return JS_UNDEFINED; return JS_UNDEFINED;
@ -476,7 +477,7 @@ js_location_set_property_pathname(JSContext *ctx, JSValueConst this_val, JSValue
if (!str) { if (!str) {
return JS_EXCEPTION; return JS_EXCEPTION;
} }
location_goto_const(vs->doc_view, str); location_goto_const(vs->doc_view, str, 0);
JS_FreeCString(ctx, str); JS_FreeCString(ctx, str);
return JS_UNDEFINED; return JS_UNDEFINED;
@ -507,7 +508,7 @@ js_location_set_property_port(JSContext *ctx, JSValueConst this_val, JSValue val
if (!str) { if (!str) {
return JS_EXCEPTION; return JS_EXCEPTION;
} }
location_goto_const(vs->doc_view, str); location_goto_const(vs->doc_view, str, 0);
JS_FreeCString(ctx, str); JS_FreeCString(ctx, str);
return JS_UNDEFINED; return JS_UNDEFINED;
@ -538,7 +539,7 @@ js_location_set_property_protocol(JSContext *ctx, JSValueConst this_val, JSValue
if (!str) { if (!str) {
return JS_EXCEPTION; return JS_EXCEPTION;
} }
location_goto_const(vs->doc_view, str); location_goto_const(vs->doc_view, str, 0);
JS_FreeCString(ctx, str); JS_FreeCString(ctx, str);
return JS_UNDEFINED; return JS_UNDEFINED;
@ -569,7 +570,7 @@ js_location_set_property_search(JSContext *ctx, JSValueConst this_val, JSValue v
if (!str) { if (!str) {
return JS_EXCEPTION; return JS_EXCEPTION;
} }
location_goto_const(vs->doc_view, str); location_goto_const(vs->doc_view, str, 0);
JS_FreeCString(ctx, str); JS_FreeCString(ctx, str);
return JS_UNDEFINED; return JS_UNDEFINED;
@ -597,7 +598,7 @@ js_location_assign(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst
if (!url) { if (!url) {
return JS_EXCEPTION; return JS_EXCEPTION;
} }
location_goto_const(vs->doc_view, url); location_goto_const(vs->doc_view, url, 0);
JS_FreeCString(ctx, url); JS_FreeCString(ctx, url);
return JS_UNDEFINED; return JS_UNDEFINED;
@ -620,7 +621,7 @@ js_location_reload(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst
#endif #endif
return JS_EXCEPTION; 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; return JS_UNDEFINED;
} }
@ -656,7 +657,7 @@ js_location_replace(JSContext *ctx, JSValueConst this_val, int argc, JSValueCons
del_from_history(&ses->history, loc); 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); JS_FreeCString(ctx, url);
return JS_UNDEFINED; return JS_UNDEFINED;

View File

@ -573,7 +573,7 @@ js_window_set_property_location(JSContext *ctx, JSValueConst this_val, JSValue v
return JS_EXCEPTION; return JS_EXCEPTION;
} }
location_goto_const(doc_view, url); location_goto_const(doc_view, url, 0);
JS_FreeCString(ctx, url); JS_FreeCString(ctx, url);
return JS_UNDEFINED; return JS_UNDEFINED;

View File

@ -875,7 +875,7 @@ document_set_property_location(JSContext *ctx, unsigned int argc, JS::Value *vp)
char *url = jsval_to_string(ctx, args[0]); char *url = jsval_to_string(ctx, args[0]);
if (url) { if (url) {
location_goto(doc_view, url); location_goto(doc_view, url, 0);
mem_free(url); mem_free(url);
} }
@ -1131,7 +1131,7 @@ document_set_property_url(JSContext *ctx, unsigned int argc, JS::Value *vp)
doc_view = vs->doc_view; doc_view = vs->doc_view;
char *url = jsval_to_string(ctx, args[0]); char *url = jsval_to_string(ctx, args[0]);
if (url) { if (url) {
location_goto(doc_view, url); location_goto(doc_view, url, 0);
mem_free(url); mem_free(url);
} }

View File

@ -1004,7 +1004,7 @@ location_assign(JSContext *ctx, unsigned int argc, JS::Value *rval)
if (!url) { if (!url) {
return false; return false;
} }
location_goto(doc_view, url); location_goto(doc_view, url, 0);
mem_free(url); mem_free(url);
return true; return true;
@ -1050,7 +1050,7 @@ location_reload(JSContext *ctx, unsigned int argc, JS::Value *rval)
return false; return false;
} }
doc_view = vs->doc_view; doc_view = vs->doc_view;
location_goto_const(doc_view, ""); location_goto_const(doc_view, struri(doc_view->document->uri), 1);
return true; return true;
} }
@ -1114,7 +1114,7 @@ location_replace(JSContext *ctx, unsigned int argc, JS::Value *rval)
del_from_history(&ses->history, loc); del_from_history(&ses->history, loc);
} }
} }
location_goto(doc_view, url); location_goto(doc_view, url, 0);
mem_free(url); mem_free(url);
return true; 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); char *url = jsval_to_string(ctx, val);
if (url) { if (url) {
location_goto(doc_view, url); location_goto(doc_view, url, 0);
mem_free(url); mem_free(url);
} }
} }

View File

@ -174,9 +174,6 @@ find_child_frame(struct document_view *doc_view, struct frame_desc *tframe)
} }
#endif #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_addEventListener(JSContext *ctx, unsigned int argc, JS::Value *rval);
static bool window_alert(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); 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]); char *url = jsval_to_string(ctx, args[0]);
if (url) { if (url) {
location_goto(doc_view, url); location_goto(doc_view, url, 0);
mem_free(url); mem_free(url);
} }