2005-09-15 09:58:31 -04:00
|
|
|
/* The SpiderMonkey window 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 "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/window.h"
|
|
|
|
#include "intl/gettext/libintl.h"
|
|
|
|
#include "main/select.h"
|
|
|
|
#include "osdep/newwin.h"
|
|
|
|
#include "osdep/sysname.h"
|
|
|
|
#include "protocol/http/http.h"
|
|
|
|
#include "protocol/uri.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 JSBool window_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp);
|
|
|
|
static JSBool window_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp);
|
|
|
|
|
|
|
|
const JSClass window_class = {
|
|
|
|
"window",
|
2006-11-20 14:49:17 -05:00
|
|
|
JSCLASS_HAS_PRIVATE, /* struct view_state * */
|
2005-09-15 09:58:31 -04:00
|
|
|
JS_PropertyStub, JS_PropertyStub,
|
|
|
|
window_get_property, window_set_property,
|
|
|
|
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-12-06 16:09:14 -05:00
|
|
|
/* Tinyids of properties. Use negative values to distinguish these
|
|
|
|
* from array indexes (even though this object has no array elements).
|
|
|
|
* ECMAScript code should not use these directly as in window[-1];
|
|
|
|
* future versions of ELinks may change the numbers. */
|
2005-09-15 09:58:31 -04:00
|
|
|
enum window_prop {
|
2006-12-06 16:09:14 -05:00
|
|
|
JSP_WIN_CLOSED = -1,
|
|
|
|
JSP_WIN_PARENT = -2,
|
|
|
|
JSP_WIN_SELF = -3,
|
|
|
|
JSP_WIN_STATUS = -4,
|
|
|
|
JSP_WIN_TOP = -5,
|
2005-09-15 09:58:31 -04:00
|
|
|
};
|
|
|
|
/* "location" is special because we need to simulate "location.href"
|
|
|
|
* when the code is asking directly for "location". We do not register
|
|
|
|
* it as a "known" property since that was yielding strange bugs
|
|
|
|
* (SpiderMonkey was still asking us about the "location" string after
|
|
|
|
* assigning to it once), instead we do just a little string
|
|
|
|
* comparing. */
|
|
|
|
const JSPropertySpec window_props[] = {
|
|
|
|
{ "closed", JSP_WIN_CLOSED, JSPROP_ENUMERATE | JSPROP_READONLY },
|
|
|
|
{ "parent", JSP_WIN_PARENT, JSPROP_ENUMERATE | JSPROP_READONLY },
|
|
|
|
{ "self", JSP_WIN_SELF, JSPROP_ENUMERATE | JSPROP_READONLY },
|
2006-10-24 14:41:25 -04:00
|
|
|
{ "status", JSP_WIN_STATUS, JSPROP_ENUMERATE },
|
2005-09-15 09:58:31 -04:00
|
|
|
{ "top", JSP_WIN_TOP, JSPROP_ENUMERATE | JSPROP_READONLY },
|
|
|
|
{ "window", JSP_WIN_SELF, JSPROP_ENUMERATE | JSPROP_READONLY },
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static JSObject *
|
|
|
|
try_resolve_frame(struct document_view *doc_view, unsigned char *id)
|
|
|
|
{
|
|
|
|
struct session *ses = doc_view->session;
|
|
|
|
struct frame *target;
|
|
|
|
|
|
|
|
assert(ses);
|
|
|
|
target = ses_find_frame(ses, id);
|
|
|
|
if (!target) return NULL;
|
|
|
|
if (target->vs.ecmascript_fragile)
|
|
|
|
ecmascript_reset_state(&target->vs);
|
|
|
|
if (!target->vs.ecmascript) return NULL;
|
|
|
|
return JS_GetGlobalObject(target->vs.ecmascript->backend_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
static struct frame_desc *
|
|
|
|
find_child_frame(struct document_view *doc_view, struct frame_desc *tframe)
|
|
|
|
{
|
|
|
|
struct frameset_desc *frameset = doc_view->document->frame_desc;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!frameset)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < frameset->n; i++) {
|
|
|
|
struct frame_desc *frame = &frameset->frame_desc[i];
|
|
|
|
|
|
|
|
if (frame == tframe)
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-11-23 16:33:43 -05:00
|
|
|
/* @window_class.getProperty */
|
2005-09-15 09:58:31 -04:00
|
|
|
static JSBool
|
|
|
|
window_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
|
|
|
|
{
|
2006-11-24 01:50:12 -05:00
|
|
|
struct view_state *vs;
|
|
|
|
|
2006-12-03 04:14:22 -05:00
|
|
|
/* This can be called if @obj if not itself an instance of the
|
|
|
|
* appropriate class but has one in its prototype chain. Fail
|
|
|
|
* such calls. */
|
|
|
|
if (!JS_InstanceOf(ctx, obj, (JSClass *) &window_class, NULL))
|
|
|
|
return JS_FALSE;
|
2006-11-25 01:54:58 -05:00
|
|
|
|
2007-05-27 11:32:53 -04:00
|
|
|
vs = JS_GetInstancePrivate(ctx, obj, (JSClass *) &window_class, NULL);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
/* No need for special window.location measurements - when
|
|
|
|
* location is then evaluated in string context, toString()
|
|
|
|
* is called which we overrode for that class below, so
|
|
|
|
* everything's fine. */
|
|
|
|
if (JSVAL_IS_STRING(id)) {
|
|
|
|
struct document_view *doc_view = vs->doc_view;
|
|
|
|
JSObject *obj;
|
|
|
|
|
|
|
|
obj = try_resolve_frame(doc_view, jsval_to_string(ctx, &id));
|
|
|
|
/* TODO: Try other lookups (mainly element lookup) until
|
|
|
|
* something yields data. */
|
|
|
|
if (obj) {
|
|
|
|
object_to_jsval(ctx, vp, obj);
|
|
|
|
}
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!JSVAL_IS_INT(id))
|
|
|
|
return JS_TRUE;
|
|
|
|
|
|
|
|
undef_to_jsval(ctx, vp);
|
|
|
|
|
|
|
|
switch (JSVAL_TO_INT(id)) {
|
|
|
|
case JSP_WIN_CLOSED:
|
|
|
|
/* TODO: It will be a major PITA to implement this properly.
|
|
|
|
* Well, perhaps not so much if we introduce reference tracking
|
|
|
|
* for (struct session)? Still... --pasky */
|
|
|
|
boolean_to_jsval(ctx, vp, 0);
|
|
|
|
break;
|
|
|
|
case JSP_WIN_SELF:
|
|
|
|
object_to_jsval(ctx, vp, obj);
|
|
|
|
break;
|
|
|
|
case JSP_WIN_PARENT:
|
|
|
|
/* XXX: It would be nice if the following worked, yes.
|
|
|
|
* The problem is that we get called at the point where
|
|
|
|
* document.frame properties are going to be mostly NULL.
|
|
|
|
* But the problem is deeper because at that time we are
|
|
|
|
* yet building scrn_frames so our parent might not be there
|
|
|
|
* yet (XXX: is this true?). The true solution will be to just
|
|
|
|
* have struct document_view *(document_view.parent). --pasky */
|
|
|
|
/* FIXME: So now we alias window.parent to window.top, which is
|
|
|
|
* INCORRECT but works for the most common cases of just two
|
|
|
|
* frames. Better something than nothing. */
|
|
|
|
#if 0
|
|
|
|
{
|
|
|
|
/* This is horrible. */
|
|
|
|
struct document_view *doc_view = vs->doc_view;
|
|
|
|
struct session *ses = doc_view->session;
|
|
|
|
struct frame_desc *frame = doc_view->document->frame;
|
|
|
|
|
|
|
|
if (!ses->doc_view->document->frame_desc) {
|
|
|
|
INTERNAL("Looking for parent but there're no frames.");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
assert(frame);
|
|
|
|
doc_view = ses->doc_view;
|
|
|
|
if (find_child_frame(doc_view, frame))
|
|
|
|
goto found_parent;
|
|
|
|
foreach (doc_view, ses->scrn_frames) {
|
|
|
|
if (find_child_frame(doc_view, frame))
|
|
|
|
goto found_parent;
|
|
|
|
}
|
|
|
|
INTERNAL("Cannot find frame %s parent.",doc_view->name);
|
|
|
|
break;
|
|
|
|
|
|
|
|
found_parent:
|
|
|
|
some_domain_security_check();
|
|
|
|
if (doc_view->vs.ecmascript_fragile)
|
|
|
|
ecmascript_reset_state(&doc_view->vs);
|
|
|
|
assert(doc_view->ecmascript);
|
|
|
|
object_to_jsval(ctx, vp, JS_GetGlobalObject(doc_view->ecmascript->backend_data));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2006-10-26 16:30:26 -04:00
|
|
|
case JSP_WIN_STATUS:
|
|
|
|
return JS_FALSE;
|
2005-09-15 09:58:31 -04:00
|
|
|
case JSP_WIN_TOP:
|
|
|
|
{
|
|
|
|
struct document_view *doc_view = vs->doc_view;
|
|
|
|
struct document_view *top_view = doc_view->session->doc_view;
|
|
|
|
JSObject *newjsframe;
|
|
|
|
|
|
|
|
assert(top_view && top_view->vs);
|
|
|
|
if (top_view->vs->ecmascript_fragile)
|
|
|
|
ecmascript_reset_state(top_view->vs);
|
|
|
|
if (!top_view->vs->ecmascript)
|
|
|
|
break;
|
|
|
|
newjsframe = JS_GetGlobalObject(top_view->vs->ecmascript->backend_data);
|
|
|
|
|
|
|
|
/* Keep this unrolled this way. Will have to check document.domain
|
|
|
|
* JS property. */
|
|
|
|
/* Note that this check is perhaps overparanoid. If top windows
|
|
|
|
* is alien but some other child window is not, we should still
|
|
|
|
* let the script walk thru. That'd mean moving the check to
|
|
|
|
* other individual properties in this switch. */
|
|
|
|
if (compare_uri(vs->uri, top_view->vs->uri, URI_HOST))
|
|
|
|
object_to_jsval(ctx, vp, newjsframe);
|
|
|
|
/* else */
|
|
|
|
/****X*X*X*** SECURITY VIOLATION! RED ALERT, SHIELDS UP! ***X*X*X****\
|
|
|
|
|* (Pasky was apparently looking at the Links2 JS code . ___ ^.^ *|
|
|
|
|
\* for too long.) `.(,_,)\o/ */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2007-05-27 11:36:31 -04:00
|
|
|
/* Unrecognized integer property ID; someone is using
|
|
|
|
* the object as an array. SMJS builtin classes (e.g.
|
2006-12-03 05:07:07 -05:00
|
|
|
* js_RegExpClass) just return JS_TRUE in this case
|
|
|
|
* and leave *@vp unchanged. Do the same here.
|
|
|
|
* (Actually not quite the same, as we already used
|
|
|
|
* @undef_to_jsval.) */
|
2005-09-15 09:58:31 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void location_goto(struct document_view *doc_view, unsigned char *url);
|
|
|
|
|
2006-11-23 16:33:43 -05:00
|
|
|
/* @window_class.setProperty */
|
2005-09-15 09:58:31 -04:00
|
|
|
static JSBool
|
|
|
|
window_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
|
|
|
|
{
|
2006-11-24 01:50:12 -05:00
|
|
|
struct view_state *vs;
|
|
|
|
|
2006-12-03 04:14:22 -05:00
|
|
|
/* This can be called if @obj if not itself an instance of the
|
|
|
|
* appropriate class but has one in its prototype chain. Fail
|
|
|
|
* such calls. */
|
|
|
|
if (!JS_InstanceOf(ctx, obj, (JSClass *) &window_class, NULL))
|
|
|
|
return JS_FALSE;
|
2006-11-25 01:54:58 -05:00
|
|
|
|
2007-05-27 11:32:53 -04:00
|
|
|
vs = JS_GetInstancePrivate(ctx, obj, (JSClass *) &window_class, NULL);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
if (JSVAL_IS_STRING(id)) {
|
|
|
|
if (!strcmp(jsval_to_string(ctx, &id), "location")) {
|
|
|
|
struct document_view *doc_view = vs->doc_view;
|
|
|
|
|
|
|
|
location_goto(doc_view, jsval_to_string(ctx, vp));
|
|
|
|
/* Do NOT touch our .location property, evil
|
|
|
|
* SpiderMonkey!! */
|
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!JSVAL_IS_INT(id))
|
|
|
|
return JS_TRUE;
|
|
|
|
|
|
|
|
switch (JSVAL_TO_INT(id)) {
|
2006-10-24 14:41:25 -04:00
|
|
|
case JSP_WIN_STATUS:
|
|
|
|
mem_free_set(&vs->doc_view->session->status.window_status, stracpy(jsval_to_string(ctx, vp)));
|
|
|
|
print_screen_status(vs->doc_view->session);
|
|
|
|
return JS_TRUE;
|
2005-09-15 09:58:31 -04:00
|
|
|
default:
|
2007-05-27 11:36:31 -04:00
|
|
|
/* Unrecognized integer property ID; someone is using
|
|
|
|
* the object as an array. SMJS builtin classes (e.g.
|
2006-12-03 05:07:07 -05:00
|
|
|
* js_RegExpClass) just return JS_TRUE in this case.
|
|
|
|
* Do the same here. */
|
2005-09-15 09:58:31 -04:00
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static JSBool window_alert(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
|
|
|
|
static JSBool window_open(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
|
2006-10-24 09:52:44 -04:00
|
|
|
static JSBool window_setTimeout(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
const JSFunctionSpec window_funcs[] = {
|
|
|
|
{ "alert", window_alert, 1 },
|
|
|
|
{ "open", window_open, 3 },
|
2006-10-24 09:52:44 -04:00
|
|
|
{ "setTimeout", window_setTimeout, 2 },
|
2005-09-15 09:58:31 -04:00
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
2006-11-23 16:33:43 -05:00
|
|
|
/* @window_funcs{"alert"} */
|
2005-09-15 09:58:31 -04:00
|
|
|
static JSBool
|
|
|
|
window_alert(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
|
|
|
{
|
2006-11-24 01:50:12 -05:00
|
|
|
struct view_state *vs;
|
2005-09-15 09:58:31 -04:00
|
|
|
unsigned char *string;
|
|
|
|
|
2006-11-25 01:54:58 -05:00
|
|
|
if (!JS_InstanceOf(ctx, obj, (JSClass *) &window_class, argv)) return JS_FALSE;
|
|
|
|
|
2007-05-27 11:32:53 -04:00
|
|
|
vs = JS_GetInstancePrivate(ctx, obj, (JSClass *) &window_class, argv);
|
2006-11-24 01:50:12 -05:00
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
if (argc != 1)
|
|
|
|
return JS_TRUE;
|
|
|
|
|
|
|
|
string = jsval_to_string(ctx, &argv[0]);
|
|
|
|
if (!*string)
|
|
|
|
return JS_TRUE;
|
|
|
|
|
|
|
|
info_box(vs->doc_view->session->tab->term, MSGBOX_FREE_TEXT,
|
|
|
|
N_("JavaScript Alert"), ALIGN_CENTER, stracpy(string));
|
|
|
|
|
|
|
|
undef_to_jsval(ctx, rval);
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
2006-11-23 16:33:43 -05:00
|
|
|
/* @window_funcs{"open"} */
|
2005-09-15 09:58:31 -04:00
|
|
|
static JSBool
|
|
|
|
window_open(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
|
|
|
{
|
2006-11-24 01:50:12 -05:00
|
|
|
struct view_state *vs;
|
|
|
|
struct document_view *doc_view;
|
|
|
|
struct session *ses;
|
2006-04-02 11:00:55 -04:00
|
|
|
unsigned char *frame = "";
|
2005-09-15 09:58:31 -04:00
|
|
|
unsigned char *url;
|
|
|
|
struct uri *uri;
|
|
|
|
static time_t ratelimit_start;
|
|
|
|
static int ratelimit_count;
|
|
|
|
|
2006-11-25 01:54:58 -05:00
|
|
|
if (!JS_InstanceOf(ctx, obj, (JSClass *) &window_class, argv)) return JS_FALSE;
|
|
|
|
|
2007-05-27 11:32:53 -04:00
|
|
|
vs = JS_GetInstancePrivate(ctx, obj, (JSClass *) &window_class, argv);
|
2006-11-24 01:50:12 -05:00
|
|
|
doc_view = vs->doc_view;
|
|
|
|
ses = doc_view->session;
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
if (get_opt_bool("ecmascript.block_window_opening")) {
|
|
|
|
#ifdef CONFIG_LEDS
|
|
|
|
set_led_value(ses->status.popup_led, 'P');
|
|
|
|
#endif
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc < 1) return JS_TRUE;
|
|
|
|
|
2006-04-02 11:00:55 -04:00
|
|
|
url = stracpy(jsval_to_string(ctx, &argv[0]));
|
|
|
|
trim_chars(url, ' ', 0);
|
2006-01-30 04:47:24 -05:00
|
|
|
if (argc > 1) {
|
2006-04-02 11:00:55 -04:00
|
|
|
frame = stracpy(jsval_to_string(ctx, &argv[1]));
|
|
|
|
if (!frame) {
|
|
|
|
mem_free(url);
|
|
|
|
return JS_TRUE;
|
2006-01-30 04:47:24 -05:00
|
|
|
}
|
2006-04-02 11:00:55 -04:00
|
|
|
if (!ecmascript_check_url(url, frame)) return JS_TRUE;
|
2006-01-30 04:47:24 -05:00
|
|
|
}
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
/* Ratelimit window opening. Recursive window.open() is very nice.
|
|
|
|
* We permit at most 20 tabs in 2 seconds. The ratelimiter is very
|
|
|
|
* rough but shall suffice against the usual cases. */
|
|
|
|
if (!ratelimit_start || time(NULL) - ratelimit_start > 2) {
|
|
|
|
ratelimit_start = time(NULL);
|
|
|
|
ratelimit_count = 0;
|
|
|
|
} else {
|
|
|
|
ratelimit_count++;
|
|
|
|
if (ratelimit_count > 20)
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: Support for window naming and perhaps some window features? */
|
|
|
|
|
2006-04-02 11:00:55 -04:00
|
|
|
url = join_urls(doc_view->document->uri, url);
|
2005-09-15 09:58:31 -04:00
|
|
|
if (!url) return JS_TRUE;
|
|
|
|
uri = get_uri(url, 0);
|
|
|
|
mem_free(url);
|
|
|
|
if (!uri) return JS_TRUE;
|
|
|
|
|
|
|
|
|
2006-04-02 11:00:55 -04:00
|
|
|
if (*frame && strcasecmp(frame, "_blank")) {
|
2005-09-15 09:58:31 -04:00
|
|
|
struct delayed_open *deo = mem_calloc(1, sizeof(*deo));
|
|
|
|
|
|
|
|
if (deo) {
|
|
|
|
deo->ses = ses;
|
|
|
|
deo->uri = get_uri_reference(uri);
|
2006-04-02 11:00:55 -04:00
|
|
|
deo->target = stracpy(frame);
|
2005-09-15 09:58:31 -04:00
|
|
|
register_bottom_half(delayed_goto_uri_frame, deo);
|
|
|
|
boolean_to_jsval(ctx, rval, 1);
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!get_cmd_opt_bool("no-connect")
|
|
|
|
&& !get_cmd_opt_bool("no-home")
|
|
|
|
&& !get_cmd_opt_bool("anonymous")
|
|
|
|
&& can_open_in_new(ses->tab->term)) {
|
|
|
|
open_uri_in_new_window(ses, uri, NULL, ENV_ANY,
|
|
|
|
CACHE_MODE_NORMAL, TASK_NONE);
|
|
|
|
boolean_to_jsval(ctx, rval, 1);
|
|
|
|
} else {
|
|
|
|
/* When opening a new tab, we might get rerendered, losing our
|
|
|
|
* context and triggerring a disaster, so postpone that. */
|
|
|
|
struct delayed_open *deo = mem_calloc(1, sizeof(*deo));
|
|
|
|
|
|
|
|
if (deo) {
|
|
|
|
deo->ses = ses;
|
|
|
|
deo->uri = get_uri_reference(uri);
|
|
|
|
register_bottom_half(delayed_open, deo);
|
|
|
|
boolean_to_jsval(ctx, rval, 1);
|
|
|
|
} else {
|
|
|
|
undef_to_jsval(ctx, rval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
|
|
|
done_uri(uri);
|
|
|
|
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
2006-10-24 09:52:44 -04:00
|
|
|
|
2006-11-23 16:33:43 -05:00
|
|
|
/* @window_funcs{"setTimeout"} */
|
2006-10-24 09:52:44 -04:00
|
|
|
static JSBool
|
|
|
|
window_setTimeout(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
|
|
|
{
|
|
|
|
struct ecmascript_interpreter *interpreter = JS_GetContextPrivate(ctx);
|
|
|
|
unsigned char *code;
|
|
|
|
int timeout;
|
|
|
|
|
|
|
|
if (argc != 2)
|
|
|
|
return JS_TRUE;
|
|
|
|
|
|
|
|
code = jsval_to_string(ctx, &argv[0]);
|
|
|
|
if (!*code)
|
|
|
|
return JS_TRUE;
|
|
|
|
|
|
|
|
code = stracpy(code);
|
|
|
|
if (!code)
|
|
|
|
return JS_TRUE;
|
|
|
|
timeout = atoi(jsval_to_string(ctx, &argv[1]));
|
2006-11-22 19:24:56 -05:00
|
|
|
if (timeout <= 0) {
|
|
|
|
mem_free(code);
|
2006-11-21 02:01:36 -05:00
|
|
|
return JS_TRUE;
|
2006-11-22 19:24:56 -05:00
|
|
|
}
|
2006-10-24 09:52:44 -04:00
|
|
|
ecmascript_set_timeout(interpreter, code, timeout);
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|