summaryrefslogtreecommitdiff
path: root/javascript/jsapi/dom.bnd
blob: 3a355256faf09d267be366e9f5278ed16be8e232 (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
/* DOM bindings entries */

webidlfile "dom.idl";

/* interface Node members */


getter textContent %{
	dom_exception exc;
	dom_string *content;

	exc = dom_node_get_text_content(private->node, &content);
	if (exc != DOM_NO_ERR) {
		return JS_FALSE;
	}

	if (content != NULL) {
		jsret = JS_NewStringCopyN(cx, dom_string_data(content), dom_string_length(content));
		dom_string_unref(content);

	}
%}


operation appendChild %{
	struct dom_node *result = NULL;
	dom_exception exc;

	struct jsclass_private *node_private;
	dom_node_type node_type;

	JSLOG("appending %p", node);

	/* CAUTION this expects all Node objects private pointers to
	 * have private->node in the same place
	 */
	/* text */
	node_private = JS_GetInstancePrivate(cx, node, &JSClass_Text, NULL);
	if (node_private == NULL) {
		/* element */
		node_private = JS_GetInstancePrivate(cx, node, &JSClass_HTMLElement, NULL);
	}

	if (node_private == NULL) {
		/* type error? */
		return JS_FALSE;
	}

	/* append the found element */
	exc = dom_node_append_child(private->node, node_private->node, &result);
	if (exc != DOM_NO_ERR) {
		return JS_FALSE;
	}

	if (result != NULL) {
		exc = dom_node_get_node_type(result, &node_type);
		if (exc != DOM_NO_ERR) {
			return JS_FALSE;
		}
		switch (node_type) {
		case DOM_ELEMENT_NODE:
			jsret = jsapi_new_HTMLElement(cx, NULL, NULL, (dom_element *)result, private->htmlc);
			break;

		case DOM_TEXT_NODE:
			jsret = jsapi_new_Text(cx, NULL, NULL, (dom_text *)result, private->htmlc);
			break;

		default:
			JSLOG("Unsupported result node type %d", node_type);
		}

	} else {
		JSLOG("No result");
	}
%}