summaryrefslogtreecommitdiff
path: root/javascript/duktape/window.c
blob: 3bad2ab9aef6f6c792d85641f3ae0c66053ab365 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* DO NOT USE, DODGY BIT FOR VINCE */

#include <dom/dom.h>

#include "utils/log.h"

#include "javascript/dukky.h"

#include "desktop/browser.h"
#include "render/html.h"
#include "render/html_internal.h"
#include "utils/nsurl.h"

DUKKY_FUNC_INIT(window, struct browser_window *win,
		struct html_content *htmlc)
{
	DUKKY_FUNC_T(event_target, __init)(ctx, &priv->parent);
	LOG("Initialise %p (priv=%p)", duk_get_heapptr(ctx, 0), priv);
	/* element window */
	priv->win = win;
	priv->htmlc = htmlc;
	LOG("win=%p htmlc=%p", priv->win, priv->htmlc);
	
	LOG("URL is %s", nsurl_access(browser_window_get_url(priv->win)));
	
	/* populate window.window */
	duk_dup(ctx, 0);
	duk_put_prop_string(ctx, 0, "window");
}

DUKKY_FUNC_FINI(window)
{
	/* do any window finalisation here, priv ptr exists */
	LOG("Finalise %p", duk_get_heapptr(ctx, 0));
	DUKKY_FUNC_T(event_target, __fini)(ctx, &priv->parent);
}

static DUKKY_FUNC(window, __constructor)
{
	DUKKY_CREATE_PRIVATE(window);
	DUKKY_FUNC_T(window, __init)(ctx, priv,
				     duk_get_pointer(ctx, 1),
				     duk_get_pointer(ctx, 2));
	duk_set_top(ctx, 1);
	return 1;
}

static DUKKY_FUNC(window, __destructor)
{
	DUKKY_SAFE_GET_PRIVATE(window, 0);
	DUKKY_FUNC_T(window, __fini)(ctx, priv);
	free(priv);
	return 0;
}

static DUKKY_GETTER(window,document)
{
	DUKKY_GET_METHOD_PRIVATE(window);
	LOG("priv=%p", priv);
	dom_document *doc = priv->htmlc->document;
	dukky_push_node(ctx, (struct dom_node *)doc);
	return 1;
}

static DUKKY_SETTER(window,document)
{
	LOG("BWUAhAHAHAHAHA FUCK OFF");
	return 0;
}

#define STEAL_THING(X)				\
	duk_get_global_string(ctx, #X);		\
	duk_put_prop_string(ctx, 0, #X)

DUKKY_FUNC(window, __proto)
{
	STEAL_THING(undefined);
	/* Populate window's prototypical functionality */
	DUKKY_POPULATE_FULL_PROPERTY(window, document);
	/* Exposed prototypes */
	DUKKY_GET_PROTOTYPE(node);
	duk_put_prop_string(ctx, 0, "Node");
	/* Set this prototype's prototype (left-parent)*/
	DUKKY_GET_PROTOTYPE(event_target);
	duk_set_prototype(ctx, 0);
	/* And the initialiser/finalizer */
	DUKKY_SET_DESTRUCTOR(0, window);
	DUKKY_SET_CONSTRUCTOR(0, window, 2);
	return 1; /* The proto object */
}