mirror of
https://github.com/rkd77/elinks.git
synced 2024-11-04 08:17:17 -05:00
[spidermonkey] onreadystatechange_run
xhr_open is finished
This commit is contained in:
parent
1cb4df952c
commit
a6360d8928
@ -51,6 +51,13 @@
|
|||||||
#include "viewer/text/link.h"
|
#include "viewer/text/link.h"
|
||||||
#include "viewer/text/vs.h"
|
#include "viewer/text/vs.h"
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
const unsigned short UNSENT = 0;
|
||||||
|
const unsigned short OPENED = 1;
|
||||||
|
const unsigned short HEADERS_RECEIVED = 2;
|
||||||
|
const unsigned short LOADING = 3;
|
||||||
|
const unsigned short DONE = 4;
|
||||||
|
|
||||||
static bool xhr_get_property_onabort(JSContext *cx, unsigned int argc, JS::Value *vp);
|
static bool xhr_get_property_onabort(JSContext *cx, unsigned int argc, JS::Value *vp);
|
||||||
static bool xhr_get_property_onerror(JSContext *cx, unsigned int argc, JS::Value *vp);
|
static bool xhr_get_property_onerror(JSContext *cx, unsigned int argc, JS::Value *vp);
|
||||||
@ -85,8 +92,8 @@ static bool xhr_set_property_responseType(JSContext *cx, unsigned int argc, JS::
|
|||||||
static bool xhr_set_property_timeout(JSContext *cx, unsigned int argc, JS::Value *vp);
|
static bool xhr_set_property_timeout(JSContext *cx, unsigned int argc, JS::Value *vp);
|
||||||
static bool xhr_set_property_withCredentials(JSContext *cx, unsigned int argc, JS::Value *vp);
|
static bool xhr_set_property_withCredentials(JSContext *cx, unsigned int argc, JS::Value *vp);
|
||||||
|
|
||||||
|
|
||||||
struct xhr {
|
struct xhr {
|
||||||
|
std::map<string, string> requestHeaders;
|
||||||
struct download download;
|
struct download download;
|
||||||
struct ecmascript_interpreter *interpreter;
|
struct ecmascript_interpreter *interpreter;
|
||||||
JS::RootedObject thisval;
|
JS::RootedObject thisval;
|
||||||
@ -107,12 +114,17 @@ struct xhr {
|
|||||||
char *upload;
|
char *upload;
|
||||||
bool async;
|
bool async;
|
||||||
bool withCredentials;
|
bool withCredentials;
|
||||||
|
bool isSend;
|
||||||
|
bool isUpload;
|
||||||
int method;
|
int method;
|
||||||
int readyState;
|
|
||||||
int status;
|
int status;
|
||||||
int timeout;
|
int timeout;
|
||||||
|
unsigned short readyState;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void onload_run(void *data);
|
||||||
|
static void onreadystatechange_run(void *data);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
xhr_finalize(JSFreeOp *op, JSObject *xhr_obj)
|
xhr_finalize(JSFreeOp *op, JSObject *xhr_obj)
|
||||||
{
|
{
|
||||||
@ -131,6 +143,7 @@ xhr_finalize(JSFreeOp *op, JSObject *xhr_obj)
|
|||||||
mem_free_if(xhr->responseURL);
|
mem_free_if(xhr->responseURL);
|
||||||
mem_free_if(xhr->statusText);
|
mem_free_if(xhr->statusText);
|
||||||
mem_free_if(xhr->upload);
|
mem_free_if(xhr->upload);
|
||||||
|
xhr->requestHeaders.clear();
|
||||||
mem_free(xhr);
|
mem_free(xhr);
|
||||||
|
|
||||||
JS::SetPrivate(xhr_obj, nullptr);
|
JS::SetPrivate(xhr_obj, nullptr);
|
||||||
@ -387,6 +400,18 @@ xhr_open(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO terminate fetch
|
||||||
|
xhr->isSend = false;
|
||||||
|
xhr->isUpload = false;
|
||||||
|
xhr->requestHeaders.clear();
|
||||||
|
mem_free_set(&xhr->response, NULL);
|
||||||
|
mem_free_set(&xhr->responseText, NULL);
|
||||||
|
|
||||||
|
if (xhr->readyState != OPENED) {
|
||||||
|
xhr->readyState = OPENED;
|
||||||
|
register_bottom_half(onreadystatechange_run, xhr);
|
||||||
|
}
|
||||||
|
|
||||||
args.rval().setUndefined();
|
args.rval().setUndefined();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -425,6 +450,25 @@ onload_run(void *data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
onreadystatechange_run(void *data)
|
||||||
|
{
|
||||||
|
struct xhr *xhr = (struct xhr *)data;
|
||||||
|
|
||||||
|
if (xhr) {
|
||||||
|
struct ecmascript_interpreter *interpreter = xhr->interpreter;
|
||||||
|
JSContext *ctx = (JSContext *)interpreter->backend_data;
|
||||||
|
JS::Realm *comp = JS::EnterRealm(ctx, (JSObject *)interpreter->ac);
|
||||||
|
JS::RootedValue r_val(ctx);
|
||||||
|
interpreter->heartbeat = add_heartbeat(interpreter);
|
||||||
|
JS_CallFunctionValue(ctx, xhr->thisval, xhr->onreadystatechange, JS::HandleValueArray::empty(), &r_val);
|
||||||
|
done_heartbeat(interpreter->heartbeat);
|
||||||
|
JS::LeaveRealm(ctx, comp);
|
||||||
|
|
||||||
|
check_for_rerender(interpreter, "xhr_onreadystatechange");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
xhr_loading_callback(struct download *download, struct xhr *xhr)
|
xhr_loading_callback(struct download *download, struct xhr *xhr)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user