summaryrefslogtreecommitdiffstats
path: root/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCAttr.cpp
blob: 31349cbdfd20dbf0edd406de4375ff5d7018fe94 (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
91
92
93
94
95
96
97
98
99
100
101
/**
 *  @file
 *  @author     This file has been generated by generate-bindings.pl. DO NOT MODIFY!
 *  @copyright  Simplified BSD
 *
 *  @cond
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the FreeBSD license as published by the FreeBSD
 *  project.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 *  You should have received a copy of the FreeBSD license along with this
 *  program. If not, see <http://www.opensource.org/licenses/bsd-license>.
 *  @endcond
 */
#include "JSCAttr.h"
#include "JSCElement.h"
#include "JSCNode.h"

namespace Arabica {
namespace DOM {

JSClassRef JSCAttr::Tmpl;

JSStaticValue JSCAttr::staticValues[] = {
	{ "name", nameAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
	{ "specified", specifiedAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
	{ "value", valueAttrGetter, valueAttrSetter, kJSPropertyAttributeDontDelete },
	{ "ownerElement", ownerElementAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },

	{ 0, 0, 0, 0 }
};

JSStaticFunction JSCAttr::staticFunctions[] = {
	{ 0, 0, 0 }
};

JSValueRef JSCAttr::nameAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) {
	struct JSCAttrPrivate* privData = (struct JSCAttrPrivate*)JSObjectGetPrivate(object);

	JSStringRef stringRef = JSStringCreateWithUTF8CString(privData->nativeObj->getName().c_str());
	JSValueRef retVal = JSValueMakeString(ctx, stringRef);
	JSStringRelease(stringRef);
	return retVal;
}


JSValueRef JSCAttr::specifiedAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) {
	struct JSCAttrPrivate* privData = (struct JSCAttrPrivate*)JSObjectGetPrivate(object);

	return JSValueMakeBoolean(ctx, privData->nativeObj->getSpecified());
}


JSValueRef JSCAttr::valueAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) {
	struct JSCAttrPrivate* privData = (struct JSCAttrPrivate*)JSObjectGetPrivate(object);

	JSStringRef stringRef = JSStringCreateWithUTF8CString(privData->nativeObj->getValue().c_str());
	JSValueRef retVal = JSValueMakeString(ctx, stringRef);
	JSStringRelease(stringRef);
	return retVal;
}


bool JSCAttr::valueAttrSetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef value, JSValueRef* exception) {
	struct JSCAttrPrivate* privData = (struct JSCAttrPrivate*)JSObjectGetPrivate(thisObj);

	JSStringRef stringReflocalValue = JSValueToStringCopy(ctx, value, exception);
	size_t localValueMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalValue);
	char* localValueBuffer = new char[localValueMaxSize];
	JSStringGetUTF8CString(stringReflocalValue, localValueBuffer, localValueMaxSize);
	std::string localValue(localValueBuffer);
	JSStringRelease(stringReflocalValue);
	free(localValueBuffer);

	privData->nativeObj->setValue(localValue);
	return true;
}

JSValueRef JSCAttr::ownerElementAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) {
	struct JSCAttrPrivate* privData = (struct JSCAttrPrivate*)JSObjectGetPrivate(object);

	if (!privData->nativeObj->getOwnerElement()) return JSValueMakeUndefined(ctx);
	Arabica::DOM::Element<std::string>* arabicaRet = new Arabica::DOM::Element<std::string>(privData->nativeObj->getOwnerElement());

	JSClassRef arbaicaRetClass = JSCElement::getTmpl();

	struct JSCElement::JSCElementPrivate* retPrivData = new JSCElement::JSCElementPrivate();
	retPrivData->dom = privData->dom;
	retPrivData->nativeObj = arabicaRet;

	JSObjectRef arbaicaRetObj = JSObjectMake(ctx, arbaicaRetClass, retPrivData);
	return arbaicaRetObj;
}


}
}