mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
[spidermonkey] Beginning of xhr implementation.
This commit is contained in:
parent
7a4dc487a5
commit
8ea4b24092
@ -38,6 +38,7 @@
|
|||||||
#include "ecmascript/spidermonkey/screen.h"
|
#include "ecmascript/spidermonkey/screen.h"
|
||||||
#include "ecmascript/spidermonkey/unibar.h"
|
#include "ecmascript/spidermonkey/unibar.h"
|
||||||
#include "ecmascript/spidermonkey/window.h"
|
#include "ecmascript/spidermonkey/window.h"
|
||||||
|
#include "ecmascript/spidermonkey/xhr.h"
|
||||||
#include "intl/libintl.h"
|
#include "intl/libintl.h"
|
||||||
#include "main/select.h"
|
#include "main/select.h"
|
||||||
#include "osdep/newwin.h"
|
#include "osdep/newwin.h"
|
||||||
@ -146,7 +147,8 @@ spidermonkey_get_interpreter(struct ecmascript_interpreter *interpreter)
|
|||||||
{
|
{
|
||||||
JSContext *ctx;
|
JSContext *ctx;
|
||||||
JSObject *console_obj, *document_obj, /* *forms_obj,*/ *history_obj, *location_obj,
|
JSObject *console_obj, *document_obj, /* *forms_obj,*/ *history_obj, *location_obj,
|
||||||
*statusbar_obj, *menubar_obj, *navigator_obj, *localstorage_obj, *screen_obj;
|
*statusbar_obj, *menubar_obj, *navigator_obj, *localstorage_obj, *screen_obj,
|
||||||
|
*xhr_obj;
|
||||||
|
|
||||||
assert(interpreter);
|
assert(interpreter);
|
||||||
if (!js_module_init_ok) return NULL;
|
if (!js_module_init_ok) return NULL;
|
||||||
@ -284,6 +286,16 @@ spidermonkey_get_interpreter(struct ecmascript_interpreter *interpreter)
|
|||||||
goto release_and_fail;
|
goto release_and_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xhr_obj = spidermonkey_InitClass(ctx, window_obj, NULL,
|
||||||
|
&xhr_class, xhr_constructor, 0,
|
||||||
|
xhr_props,
|
||||||
|
xhr_funcs,
|
||||||
|
NULL, NULL);
|
||||||
|
|
||||||
|
if (!xhr_obj) {
|
||||||
|
goto release_and_fail;
|
||||||
|
}
|
||||||
|
|
||||||
JS::SetRealmPrivate(js::GetContextRealm(ctx), interpreter);
|
JS::SetRealmPrivate(js::GetContextRealm(ctx), interpreter);
|
||||||
|
|
||||||
return ctx;
|
return ctx;
|
||||||
|
@ -3,6 +3,6 @@ include $(top_builddir)/Makefile.config
|
|||||||
INCLUDES += $(SPIDERMONKEY_CFLAGS)
|
INCLUDES += $(SPIDERMONKEY_CFLAGS)
|
||||||
|
|
||||||
OBJS = attr.obj attributes.obj collection.obj console.obj document.obj element.obj form.obj forms.obj heartbeat.obj history.obj implementation.obj input.obj \
|
OBJS = attr.obj attributes.obj collection.obj console.obj document.obj element.obj form.obj forms.obj heartbeat.obj history.obj implementation.obj input.obj \
|
||||||
location.obj localstorage.obj navigator.obj nodelist.obj screen.obj unibar.obj window.obj
|
location.obj localstorage.obj navigator.obj nodelist.obj screen.obj unibar.obj window.obj xhr.obj
|
||||||
|
|
||||||
include $(top_srcdir)/Makefile.lib
|
include $(top_srcdir)/Makefile.lib
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#INCLUDES += $(SPIDERMONKEY_CFLAGS)
|
#INCLUDES += $(SPIDERMONKEY_CFLAGS)
|
||||||
|
|
||||||
srcs += files('attr.cpp', 'attributes.cpp', 'collection.cpp', 'console.cpp', 'document.cpp', 'element.cpp', 'form.cpp', 'forms.cpp', 'heartbeat.cpp', 'history.cpp', 'implementation.cpp', 'input.cpp',
|
srcs += files('attr.cpp', 'attributes.cpp', 'collection.cpp', 'console.cpp', 'document.cpp', 'element.cpp', 'form.cpp', 'forms.cpp', 'heartbeat.cpp', 'history.cpp', 'implementation.cpp', 'input.cpp',
|
||||||
'location.cpp', 'localstorage.cpp', 'navigator.cpp', 'nodelist.cpp', 'screen.cpp', 'unibar.cpp', 'window.cpp')
|
'location.cpp', 'localstorage.cpp', 'navigator.cpp', 'nodelist.cpp', 'screen.cpp', 'unibar.cpp', 'window.cpp', 'xhr.cpp')
|
||||||
|
934
src/ecmascript/spidermonkey/xhr.cpp
Normal file
934
src/ecmascript/spidermonkey/xhr.cpp
Normal file
@ -0,0 +1,934 @@
|
|||||||
|
/* The SpiderMonkey xhr object implementation. */
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "elinks.h"
|
||||||
|
|
||||||
|
#include "ecmascript/spidermonkey/util.h"
|
||||||
|
#include <js/BigInt.h>
|
||||||
|
#include <js/Conversions.h>
|
||||||
|
|
||||||
|
#include "bfu/dialog.h"
|
||||||
|
#include "cache/cache.h"
|
||||||
|
#include "cookies/cookies.h"
|
||||||
|
#include "dialogs/menu.h"
|
||||||
|
#include "dialogs/status.h"
|
||||||
|
#include "document/html/frames.h"
|
||||||
|
#include "document/document.h"
|
||||||
|
#include "document/forms.h"
|
||||||
|
#include "document/view.h"
|
||||||
|
#include "ecmascript/ecmascript.h"
|
||||||
|
#include "ecmascript/spidermonkey.h"
|
||||||
|
#include "ecmascript/spidermonkey/heartbeat.h"
|
||||||
|
#include "ecmascript/spidermonkey/xhr.h"
|
||||||
|
#include "ecmascript/timer.h"
|
||||||
|
#include "intl/libintl.h"
|
||||||
|
#include "main/select.h"
|
||||||
|
#include "main/timer.h"
|
||||||
|
#include "network/connection.h"
|
||||||
|
#include "osdep/newwin.h"
|
||||||
|
#include "osdep/sysname.h"
|
||||||
|
#include "protocol/http/http.h"
|
||||||
|
#include "protocol/uri.h"
|
||||||
|
#include "session/download.h"
|
||||||
|
#include "session/history.h"
|
||||||
|
#include "session/location.h"
|
||||||
|
#include "session/session.h"
|
||||||
|
#include "session/task.h"
|
||||||
|
#include "terminal/tab.h"
|
||||||
|
#include "terminal/terminal.h"
|
||||||
|
#include "util/conv.h"
|
||||||
|
#include "util/memory.h"
|
||||||
|
#include "util/string.h"
|
||||||
|
#include "viewer/text/draw.h"
|
||||||
|
#include "viewer/text/form.h"
|
||||||
|
#include "viewer/text/link.h"
|
||||||
|
#include "viewer/text/vs.h"
|
||||||
|
|
||||||
|
|
||||||
|
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_onload(JSContext *cx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool xhr_get_property_onloadend(JSContext *cx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool xhr_get_property_onloadstart(JSContext *cx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool xhr_get_property_onprogress(JSContext *cx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool xhr_get_property_onreadystatechange(JSContext *cx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool xhr_get_property_ontimeout(JSContext *cx, unsigned int argc, JS::Value *vp);
|
||||||
|
|
||||||
|
static bool xhr_get_property_readyState(JSContext *cx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool xhr_get_property_response(JSContext *cx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool xhr_get_property_responseText(JSContext *cx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool xhr_get_property_responseType(JSContext *cx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool xhr_get_property_responseURL(JSContext *cx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool xhr_get_property_status(JSContext *cx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool xhr_get_property_statusText(JSContext *cx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool xhr_get_property_timeout(JSContext *cx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool xhr_get_property_upload(JSContext *cx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool xhr_get_property_withCredentials(JSContext *cx, unsigned int argc, JS::Value *vp);
|
||||||
|
|
||||||
|
static bool xhr_set_property_onabort(JSContext *cx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool xhr_set_property_onerror(JSContext *cx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool xhr_set_property_onload(JSContext *cx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool xhr_set_property_onloadend(JSContext *cx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool xhr_set_property_onloadstart(JSContext *cx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool xhr_set_property_onprogress(JSContext *cx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool xhr_set_property_onreadystatechange(JSContext *cx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool xhr_set_property_ontimeout(JSContext *cx, unsigned int argc, JS::Value *vp);
|
||||||
|
|
||||||
|
static bool xhr_set_property_responseType(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);
|
||||||
|
|
||||||
|
|
||||||
|
struct xhr {
|
||||||
|
struct download download;
|
||||||
|
struct ecmascript_interpreter *interpreter;
|
||||||
|
JS::RootedObject thisval;
|
||||||
|
JS::RootedValue onabort;
|
||||||
|
JS::RootedValue onerror;
|
||||||
|
JS::RootedValue onload;
|
||||||
|
JS::RootedValue onloadend;
|
||||||
|
JS::RootedValue onloadstart;
|
||||||
|
JS::RootedValue onprogress;
|
||||||
|
JS::RootedValue onreadystatechange;
|
||||||
|
JS::RootedValue ontimeout;
|
||||||
|
char *response;
|
||||||
|
char *responseText;
|
||||||
|
char *responseType;
|
||||||
|
char *responseURL;
|
||||||
|
char *statusText;
|
||||||
|
char *upload;
|
||||||
|
char *withCredentials;
|
||||||
|
int readyState;
|
||||||
|
int status;
|
||||||
|
int timeout;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void
|
||||||
|
xhr_finalize(JSFreeOp *op, JSObject *xhr_obj)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
struct xhr *xhr = (struct xhr *)JS::GetPrivate(xhr_obj);
|
||||||
|
|
||||||
|
if (xhr) {
|
||||||
|
mem_free_if(xhr->response);
|
||||||
|
mem_free_if(xhr->responseText);
|
||||||
|
mem_free_if(xhr->responseType);
|
||||||
|
mem_free_if(xhr->responseURL);
|
||||||
|
mem_free_if(xhr->statusText);
|
||||||
|
mem_free_if(xhr->upload);
|
||||||
|
mem_free_if(xhr->withCredentials);
|
||||||
|
mem_free(xhr);
|
||||||
|
|
||||||
|
JS::SetPrivate(xhr_obj, nullptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JSClassOps xhr_ops = {
|
||||||
|
nullptr, // addProperty
|
||||||
|
nullptr, // deleteProperty
|
||||||
|
nullptr, // enumerate
|
||||||
|
nullptr, // newEnumerate
|
||||||
|
nullptr, // resolve
|
||||||
|
nullptr, // mayResolve
|
||||||
|
xhr_finalize, // finalize
|
||||||
|
nullptr, // call
|
||||||
|
nullptr, // hasInstance
|
||||||
|
nullptr, // construct
|
||||||
|
JS_GlobalObjectTraceHook // trace
|
||||||
|
};
|
||||||
|
|
||||||
|
JSClass xhr_class = {
|
||||||
|
"XMLHttpRequest",
|
||||||
|
JSCLASS_HAS_PRIVATE,
|
||||||
|
&xhr_ops
|
||||||
|
};
|
||||||
|
|
||||||
|
bool
|
||||||
|
xhr_constructor(JSContext* ctx, unsigned argc, JS::Value* vp)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject newObj(ctx, JS_NewObjectForConstructor(ctx, &xhr_class, args));
|
||||||
|
JS::Realm *comp = js::GetContextRealm(ctx);
|
||||||
|
|
||||||
|
if (!comp) {
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp);
|
||||||
|
|
||||||
|
if (!newObj) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
struct xhr *xhr = (struct xhr *)mem_calloc(1, sizeof(*xhr));
|
||||||
|
xhr->interpreter = interpreter;
|
||||||
|
xhr->thisval = newObj;
|
||||||
|
JS::SetPrivate(newObj, xhr);
|
||||||
|
args.rval().setObject(*newObj);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
JSPropertySpec xhr_props[] = {
|
||||||
|
JS_PSGS("onabort", xhr_get_property_onabort, xhr_set_property_onabort, JSPROP_ENUMERATE),
|
||||||
|
JS_PSGS("onerror", xhr_get_property_onerror, xhr_set_property_onerror, JSPROP_ENUMERATE),
|
||||||
|
JS_PSGS("onload", xhr_get_property_onload, xhr_set_property_onload, JSPROP_ENUMERATE),
|
||||||
|
JS_PSGS("onloadend", xhr_get_property_onloadend, xhr_set_property_onloadend, JSPROP_ENUMERATE),
|
||||||
|
JS_PSGS("onloadstart", xhr_get_property_onloadstart, xhr_set_property_onloadstart, JSPROP_ENUMERATE),
|
||||||
|
JS_PSGS("onprogress", xhr_get_property_onprogress, xhr_set_property_onprogress, JSPROP_ENUMERATE),
|
||||||
|
JS_PSGS("onreadystatechange", xhr_get_property_onreadystatechange, xhr_set_property_onreadystatechange, JSPROP_ENUMERATE),
|
||||||
|
JS_PSGS("ontimeout", xhr_get_property_ontimeout, xhr_set_property_ontimeout, JSPROP_ENUMERATE),
|
||||||
|
JS_PSG("readyState", xhr_get_property_readyState, JSPROP_ENUMERATE),
|
||||||
|
JS_PSG("response", xhr_get_property_response, JSPROP_ENUMERATE),
|
||||||
|
JS_PSG("responseText", xhr_get_property_responseText, JSPROP_ENUMERATE),
|
||||||
|
JS_PSGS("responseType", xhr_get_property_responseType, xhr_set_property_responseType, JSPROP_ENUMERATE),
|
||||||
|
JS_PSG("responseURL", xhr_get_property_responseURL, JSPROP_ENUMERATE),
|
||||||
|
JS_PSG("status", xhr_get_property_status, JSPROP_ENUMERATE),
|
||||||
|
JS_PSG("statusText", xhr_get_property_statusText, JSPROP_ENUMERATE),
|
||||||
|
JS_PSGS("timeout", xhr_get_property_timeout, xhr_set_property_timeout, JSPROP_ENUMERATE),
|
||||||
|
JS_PSG("upload", xhr_get_property_upload, JSPROP_ENUMERATE),
|
||||||
|
JS_PSGS("withCredentials",xhr_get_property_withCredentials, xhr_set_property_withCredentials, JSPROP_ENUMERATE),
|
||||||
|
JS_PS_END
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool xhr_abort(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||||
|
static bool xhr_getAllResponseHeaders(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||||
|
static bool xhr_getResponseHeader(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||||
|
static bool xhr_open(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||||
|
static bool xhr_overrideMimeType(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||||
|
static bool xhr_send(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||||
|
static bool xhr_setRequestHeader(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||||
|
|
||||||
|
const spidermonkeyFunctionSpec xhr_funcs[] = {
|
||||||
|
{ "abort", xhr_abort, 0 },
|
||||||
|
{ "getAllResponseHeaders", xhr_getAllResponseHeaders, 0 },
|
||||||
|
{ "getResponseHeader", xhr_getResponseHeader, 1 },
|
||||||
|
{ "open", xhr_open, 5 },
|
||||||
|
{ "overrideMimeType", xhr_overrideMimeType, 1 },
|
||||||
|
{ "send", xhr_send, 1 },
|
||||||
|
{ "setRequestHeader", xhr_setRequestHeader, 2 },
|
||||||
|
{ NULL }
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool
|
||||||
|
xhr_abort(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = JS::CallArgsFromVp(argc, rval);
|
||||||
|
// JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
/// TODO
|
||||||
|
args.rval().setUndefined();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
xhr_getAllResponseHeaders(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = JS::CallArgsFromVp(argc, rval);
|
||||||
|
// JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
/// TODO
|
||||||
|
|
||||||
|
args.rval().setUndefined();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
xhr_getResponseHeader(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = JS::CallArgsFromVp(argc, rval);
|
||||||
|
// JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
/// TODO
|
||||||
|
|
||||||
|
args.rval().setUndefined();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
xhr_open(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = JS::CallArgsFromVp(argc, rval);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
struct xhr *xhr = (struct xhr *)(JS::GetPrivate(hobj));
|
||||||
|
|
||||||
|
if (!xhr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
mem_free_set(&xhr->responseURL, jsval_to_string(ctx, args[1]));
|
||||||
|
args.rval().setUndefined();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
xhr_overrideMimeType(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = JS::CallArgsFromVp(argc, rval);
|
||||||
|
// JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
/// TODO
|
||||||
|
|
||||||
|
args.rval().setUndefined();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
onload_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->onload, JS::HandleValueArray::empty(), &r_val);
|
||||||
|
done_heartbeat(interpreter->heartbeat);
|
||||||
|
JS::LeaveRealm(ctx, comp);
|
||||||
|
|
||||||
|
check_for_rerender(interpreter, "xhr_onload");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
xhr_loading_callback(struct download *download, struct xhr *xhr)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
if (is_in_result_state(download->state)) {
|
||||||
|
struct cache_entry *cached = download->cached;
|
||||||
|
|
||||||
|
if (!cached) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
struct fragment *fragment = get_cache_fragment(cached);
|
||||||
|
|
||||||
|
if (!fragment) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mem_free_set(&xhr->responseText, memacpy(fragment->data, fragment->length));
|
||||||
|
xhr->status = 200;
|
||||||
|
mem_free_set(&xhr->statusText, stracpy("OK"));
|
||||||
|
register_bottom_half(onload_run, xhr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
xhr_send(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = JS::CallArgsFromVp(argc, rval);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
JS::Realm *comp = js::GetContextRealm(ctx);
|
||||||
|
|
||||||
|
if (!comp) {
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp);
|
||||||
|
struct xhr *xhr = (struct xhr *)(JS::GetPrivate(hobj));
|
||||||
|
struct view_state *vs;
|
||||||
|
struct document_view *doc_view;
|
||||||
|
vs = interpreter->vs;
|
||||||
|
doc_view = vs->doc_view;
|
||||||
|
|
||||||
|
if (!xhr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
xhr->download.data = xhr;
|
||||||
|
xhr->download.callback = (download_callback_T *)xhr_loading_callback;
|
||||||
|
struct uri *uri = get_uri(xhr->responseURL, URI_NONE);
|
||||||
|
|
||||||
|
if (uri) {
|
||||||
|
load_uri(uri, doc_view->session->referrer, &xhr->download, PRI_MAIN, CACHE_MODE_NORMAL, -1);
|
||||||
|
done_uri(uri);
|
||||||
|
}
|
||||||
|
args.rval().setUndefined();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
xhr_setRequestHeader(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = JS::CallArgsFromVp(argc, rval);
|
||||||
|
// JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
/// TODO
|
||||||
|
|
||||||
|
args.rval().setUndefined();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
xhr_get_property_onabort(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
struct xhr *xhr = (struct xhr *)(JS::GetPrivate(hobj));
|
||||||
|
|
||||||
|
if (!xhr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
args.rval().set(xhr->onabort);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
xhr_set_property_onabort(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
struct xhr *xhr = (struct xhr *)(JS::GetPrivate(hobj));
|
||||||
|
|
||||||
|
if (!xhr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
JS::RootedValue fun(ctx, args[0]);
|
||||||
|
xhr->onabort = fun;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
xhr_get_property_onerror(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
struct xhr *xhr = (struct xhr *)(JS::GetPrivate(hobj));
|
||||||
|
|
||||||
|
if (!xhr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
args.rval().set(xhr->onerror);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
xhr_set_property_onerror(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
struct xhr *xhr = (struct xhr *)(JS::GetPrivate(hobj));
|
||||||
|
|
||||||
|
if (!xhr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
JS::RootedValue fun(ctx, args[0]);
|
||||||
|
xhr->onerror = fun;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
xhr_get_property_onload(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
struct xhr *xhr = (struct xhr *)(JS::GetPrivate(hobj));
|
||||||
|
|
||||||
|
if (!xhr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
args.rval().set(xhr->onload);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
xhr_set_property_onload(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
struct xhr *xhr = (struct xhr *)(JS::GetPrivate(hobj));
|
||||||
|
|
||||||
|
if (!xhr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
JS::RootedValue fun(ctx, args[0]);
|
||||||
|
xhr->onload = fun;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
xhr_get_property_onloadend(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
struct xhr *xhr = (struct xhr *)(JS::GetPrivate(hobj));
|
||||||
|
|
||||||
|
if (!xhr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
args.rval().set(xhr->onloadend);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
xhr_set_property_onloadend(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
struct xhr *xhr = (struct xhr *)(JS::GetPrivate(hobj));
|
||||||
|
|
||||||
|
if (!xhr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
JS::RootedValue fun(ctx, args[0]);
|
||||||
|
xhr->onloadend = fun;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
xhr_get_property_onloadstart(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
struct xhr *xhr = (struct xhr *)(JS::GetPrivate(hobj));
|
||||||
|
|
||||||
|
if (!xhr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
args.rval().set(xhr->onloadstart);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
xhr_set_property_onloadstart(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
struct xhr *xhr = (struct xhr *)(JS::GetPrivate(hobj));
|
||||||
|
|
||||||
|
if (!xhr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
JS::RootedValue fun(ctx, args[0]);
|
||||||
|
xhr->onloadstart = fun;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
xhr_get_property_onprogress(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
struct xhr *xhr = (struct xhr *)(JS::GetPrivate(hobj));
|
||||||
|
|
||||||
|
if (!xhr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
args.rval().set(xhr->onprogress);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
xhr_set_property_onprogress(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
struct xhr *xhr = (struct xhr *)(JS::GetPrivate(hobj));
|
||||||
|
|
||||||
|
if (!xhr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
JS::RootedValue fun(ctx, args[0]);
|
||||||
|
xhr->onprogress = fun;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
xhr_get_property_onreadystatechange(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
struct xhr *xhr = (struct xhr *)(JS::GetPrivate(hobj));
|
||||||
|
|
||||||
|
if (!xhr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
args.rval().set(xhr->onreadystatechange);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
xhr_set_property_onreadystatechange(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
struct xhr *xhr = (struct xhr *)(JS::GetPrivate(hobj));
|
||||||
|
|
||||||
|
if (!xhr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
JS::RootedValue fun(ctx, args[0]);
|
||||||
|
xhr->onreadystatechange = fun;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
xhr_get_property_ontimeout(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
struct xhr *xhr = (struct xhr *)(JS::GetPrivate(hobj));
|
||||||
|
|
||||||
|
if (!xhr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
args.rval().set(xhr->ontimeout);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
xhr_set_property_ontimeout(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
struct xhr *xhr = (struct xhr *)(JS::GetPrivate(hobj));
|
||||||
|
|
||||||
|
if (!xhr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
JS::RootedValue fun(ctx, args[0]);
|
||||||
|
xhr->ontimeout = fun;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
xhr_get_property_readyState(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
struct xhr *xhr = (struct xhr *)(JS::GetPrivate(hobj));
|
||||||
|
|
||||||
|
if (!xhr) {
|
||||||
|
args.rval().setNull();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
args.rval().setInt32(xhr->readyState);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
xhr_get_property_response(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
struct xhr *xhr = (struct xhr *)(JS::GetPrivate(hobj));
|
||||||
|
|
||||||
|
if (!xhr || !xhr->response) {
|
||||||
|
args.rval().setNull();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
args.rval().setString(JS_NewStringCopyZ(ctx, xhr->response));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
xhr_get_property_responseText(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
struct xhr *xhr = (struct xhr *)(JS::GetPrivate(hobj));
|
||||||
|
|
||||||
|
if (!xhr || !xhr->responseText) {
|
||||||
|
args.rval().setNull();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
args.rval().setString(JS_NewStringCopyZ(ctx, xhr->responseText));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
xhr_get_property_responseType(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
struct xhr *xhr = (struct xhr *)(JS::GetPrivate(hobj));
|
||||||
|
|
||||||
|
if (!xhr || !xhr->responseType) {
|
||||||
|
args.rval().setNull();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
args.rval().setString(JS_NewStringCopyZ(ctx, xhr->responseType));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
xhr_get_property_responseURL(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
struct xhr *xhr = (struct xhr *)(JS::GetPrivate(hobj));
|
||||||
|
|
||||||
|
if (!xhr || !xhr->responseURL) {
|
||||||
|
args.rval().setNull();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
args.rval().setString(JS_NewStringCopyZ(ctx, xhr->responseURL));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
xhr_get_property_status(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
struct xhr *xhr = (struct xhr *)(JS::GetPrivate(hobj));
|
||||||
|
|
||||||
|
if (!xhr) {
|
||||||
|
args.rval().setNull();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
args.rval().setInt32(xhr->status);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
xhr_get_property_statusText(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
struct xhr *xhr = (struct xhr *)(JS::GetPrivate(hobj));
|
||||||
|
|
||||||
|
if (!xhr || !xhr->statusText) {
|
||||||
|
args.rval().setNull();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
args.rval().setString(JS_NewStringCopyZ(ctx, xhr->statusText));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
xhr_get_property_upload(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
struct xhr *xhr = (struct xhr *)(JS::GetPrivate(hobj));
|
||||||
|
|
||||||
|
if (!xhr || !xhr->upload) {
|
||||||
|
args.rval().setNull();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
args.rval().setString(JS_NewStringCopyZ(ctx, xhr->upload));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
xhr_get_property_timeout(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
struct xhr *xhr = (struct xhr *)(JS::GetPrivate(hobj));
|
||||||
|
|
||||||
|
if (!xhr) {
|
||||||
|
args.rval().setNull();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
args.rval().setInt32(xhr->timeout);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
xhr_get_property_withCredentials(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
struct xhr *xhr = (struct xhr *)(JS::GetPrivate(hobj));
|
||||||
|
|
||||||
|
if (!xhr || !xhr->withCredentials) {
|
||||||
|
args.rval().setNull();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
args.rval().setString(JS_NewStringCopyZ(ctx, xhr->withCredentials));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
xhr_set_property_responseType(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
struct xhr *xhr = (struct xhr *)(JS::GetPrivate(hobj));
|
||||||
|
|
||||||
|
if (!xhr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
mem_free_set(&xhr->responseType, jsval_to_string(ctx, args[0]));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
xhr_set_property_timeout(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
struct xhr *xhr = (struct xhr *)(JS::GetPrivate(hobj));
|
||||||
|
|
||||||
|
if (!xhr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
xhr->timeout = args[0].toInt32();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
xhr_set_property_withCredentials(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
struct xhr *xhr = (struct xhr *)(JS::GetPrivate(hobj));
|
||||||
|
|
||||||
|
if (!xhr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
mem_free_set(&xhr->withCredentials, jsval_to_string(ctx, args[0]));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
11
src/ecmascript/spidermonkey/xhr.h
Normal file
11
src/ecmascript/spidermonkey/xhr.h
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#ifndef EL__ECMASCRIPT_SPIDERMONKEY_XHR_H
|
||||||
|
#define EL__ECMASCRIPT_SPIDERMONKEY_XHR_H
|
||||||
|
|
||||||
|
#include "ecmascript/spidermonkey/util.h"
|
||||||
|
|
||||||
|
extern JSClass xhr_class;
|
||||||
|
extern JSPropertySpec xhr_props[];
|
||||||
|
extern const spidermonkeyFunctionSpec xhr_funcs[];
|
||||||
|
bool xhr_constructor(JSContext* ctx, unsigned argc, JS::Value* vp);
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user