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
|
#include "JSCAttr.h"
#include "JSCElement.h"
#include "JSCNode.h"
namespace Arabica {
namespace DOM {
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());
return JSValueMakeString(ctx, stringRef);
}
JSValueRef JSCAttr::specifiedAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) {
struct JSCAttrPrivate* privData = (struct JSCAttrPrivate*)JSObjectGetPrivate(object);
return JSValueMakeNumber(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());
return JSValueMakeString(ctx, stringRef);
}
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, sizeof(localValueBuffer));
std::string localValue(localValueBuffer, localValueMaxSize);
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, arabicaRet);
return arbaicaRetObj;
}
}
}
|