summaryrefslogtreecommitdiffstats
path: root/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOMImplementation.cpp
blob: 66c9666d42577c3eda2dbea0147089b81ded31ed (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include "JSCDOMImplementation.h"
#include "JSCDocument.h"
#include "JSCDocumentType.h"

namespace Arabica {
namespace DOM {

JSClassRef JSCDOMImplementation::Tmpl;

JSStaticValue JSCDOMImplementation::staticValues[] = {

	{ 0, 0, 0, 0 }
};

JSStaticFunction JSCDOMImplementation::staticFunctions[] = {
	{ "hasFeature", hasFeatureCallback, kJSPropertyAttributeDontDelete },
	{ "createDocumentType", createDocumentTypeCallback, kJSPropertyAttributeDontDelete },
	{ "createDocument", createDocumentCallback, kJSPropertyAttributeDontDelete },
	{ 0, 0, 0 }
};
JSValueRef JSCDOMImplementation::hasFeatureCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) {
	if (argumentCount < 2) {
		std::string errorMsg = "Wrong number of arguments in hasFeature";
		JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str());
		JSValueRef exceptionString =JSValueMakeString(ctx, string);
		JSStringRelease(string);
		*exception = JSValueToObject(ctx, exceptionString, NULL);
		return NULL;
	}

	struct JSCDOMImplementationPrivate* privData = (struct JSCDOMImplementationPrivate*)JSObjectGetPrivate(thisObj);

	JSStringRef stringReflocalFeature = JSValueToStringCopy(ctx, arguments[0], exception);
	size_t localFeatureMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalFeature);
	char* localFeatureBuffer = new char[localFeatureMaxSize];
	JSStringGetUTF8CString(stringReflocalFeature, localFeatureBuffer, sizeof(localFeatureBuffer));
	std::string localFeature(localFeatureBuffer, localFeatureMaxSize);
	free(localFeatureBuffer);

	JSStringRef stringReflocalVersion = JSValueToStringCopy(ctx, arguments[1], exception);
	size_t localVersionMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalVersion);
	char* localVersionBuffer = new char[localVersionMaxSize];
	JSStringGetUTF8CString(stringReflocalVersion, localVersionBuffer, sizeof(localVersionBuffer));
	std::string localVersion(localVersionBuffer, localVersionMaxSize);
	free(localVersionBuffer);


	bool retVal = privData->nativeObj->hasFeature(localFeature, localVersion);

	JSValueRef jscRetVal = JSValueMakeBoolean(ctx, retVal);
	return jscRetVal;
}

JSValueRef JSCDOMImplementation::createDocumentTypeCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) {
	if (argumentCount < 3) {
		std::string errorMsg = "Wrong number of arguments in createDocumentType";
		JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str());
		JSValueRef exceptionString =JSValueMakeString(ctx, string);
		JSStringRelease(string);
		*exception = JSValueToObject(ctx, exceptionString, NULL);
		return NULL;
	}

	struct JSCDOMImplementationPrivate* privData = (struct JSCDOMImplementationPrivate*)JSObjectGetPrivate(thisObj);

	JSStringRef stringReflocalQualifiedName = JSValueToStringCopy(ctx, arguments[0], exception);
	size_t localQualifiedNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalQualifiedName);
	char* localQualifiedNameBuffer = new char[localQualifiedNameMaxSize];
	JSStringGetUTF8CString(stringReflocalQualifiedName, localQualifiedNameBuffer, sizeof(localQualifiedNameBuffer));
	std::string localQualifiedName(localQualifiedNameBuffer, localQualifiedNameMaxSize);
	free(localQualifiedNameBuffer);

	JSStringRef stringReflocalPublicId = JSValueToStringCopy(ctx, arguments[1], exception);
	size_t localPublicIdMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalPublicId);
	char* localPublicIdBuffer = new char[localPublicIdMaxSize];
	JSStringGetUTF8CString(stringReflocalPublicId, localPublicIdBuffer, sizeof(localPublicIdBuffer));
	std::string localPublicId(localPublicIdBuffer, localPublicIdMaxSize);
	free(localPublicIdBuffer);

	JSStringRef stringReflocalSystemId = JSValueToStringCopy(ctx, arguments[2], exception);
	size_t localSystemIdMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalSystemId);
	char* localSystemIdBuffer = new char[localSystemIdMaxSize];
	JSStringGetUTF8CString(stringReflocalSystemId, localSystemIdBuffer, sizeof(localSystemIdBuffer));
	std::string localSystemId(localSystemIdBuffer, localSystemIdMaxSize);
	free(localSystemIdBuffer);


	Arabica::DOM::DocumentType<std::string>* retVal = new Arabica::DOM::DocumentType<std::string>(privData->nativeObj->createDocumentType(localQualifiedName, localPublicId, localSystemId));
	JSClassRef retClass = JSCDocumentType::getTmpl();

	struct JSCDocumentType::JSCDocumentTypePrivate* retPrivData = new JSCDocumentType::JSCDocumentTypePrivate();
	retPrivData->dom = privData->dom;
	retPrivData->nativeObj = retVal;

	JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData);

	return retObj;

}

JSValueRef JSCDOMImplementation::createDocumentCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) {
	if (argumentCount < 3) {
		std::string errorMsg = "Wrong number of arguments in createDocument";
		JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str());
		JSValueRef exceptionString =JSValueMakeString(ctx, string);
		JSStringRelease(string);
		*exception = JSValueToObject(ctx, exceptionString, NULL);
		return NULL;
	}

	struct JSCDOMImplementationPrivate* privData = (struct JSCDOMImplementationPrivate*)JSObjectGetPrivate(thisObj);

	JSStringRef stringReflocalNamespaceURI = JSValueToStringCopy(ctx, arguments[0], exception);
	size_t localNamespaceURIMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNamespaceURI);
	char* localNamespaceURIBuffer = new char[localNamespaceURIMaxSize];
	JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, sizeof(localNamespaceURIBuffer));
	std::string localNamespaceURI(localNamespaceURIBuffer, localNamespaceURIMaxSize);
	free(localNamespaceURIBuffer);

	JSStringRef stringReflocalQualifiedName = JSValueToStringCopy(ctx, arguments[1], exception);
	size_t localQualifiedNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalQualifiedName);
	char* localQualifiedNameBuffer = new char[localQualifiedNameMaxSize];
	JSStringGetUTF8CString(stringReflocalQualifiedName, localQualifiedNameBuffer, sizeof(localQualifiedNameBuffer));
	std::string localQualifiedName(localQualifiedNameBuffer, localQualifiedNameMaxSize);
	free(localQualifiedNameBuffer);

	Arabica::DOM::DocumentType<std::string>* localDoctype = ((struct JSCDocumentType::JSCDocumentTypePrivate*)JSObjectGetPrivate(thisObj))->nativeObj;

	Arabica::DOM::Document<std::string>* retVal = new Arabica::DOM::Document<std::string>(privData->nativeObj->createDocument(localNamespaceURI, localQualifiedName, *localDoctype));
	JSClassRef retClass = JSCDocument::getTmpl();

	struct JSCDocument::JSCDocumentPrivate* retPrivData = new JSCDocument::JSCDocumentPrivate();
	retPrivData->dom = privData->dom;
	retPrivData->nativeObj = retVal;

	JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData);

	return retObj;

}


}
}