summaryrefslogtreecommitdiffstats
path: root/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ArrayBuffer.cpp
blob: 1328b19a16666fa47b8a8b5bfd0f817d5021d77c (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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/**
 *  @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 "V8ArrayBuffer.h"

namespace Arabica {
namespace DOM {

v8::Persistent<v8::FunctionTemplate> V8ArrayBuffer::Tmpl;
v8::Persistent<v8::FunctionTemplate> V8ArrayBuffer::Constr;

v8::Handle<v8::Value> V8ArrayBuffer::constructor(const v8::Arguments& args) {
	if (!args.IsConstructCall())
		return v8::ThrowException(v8::String::New("Cannot call constructor as function"));

	uscxml::ArrayBuffer* localInstance = NULL;
	if (false) {
	} else if (args.Length() == 1 &&
	           args[0]->IsUint32()) {

		unsigned long localLength = args[0]->ToNumber()->Uint32Value();
		localInstance = new uscxml::ArrayBuffer(localLength);

	}
	if (!localInstance) {
		throw V8Exception("Parameter mismatch while calling constructor for ArrayBuffer");
		return v8::Undefined();
	}

	v8::Handle<v8::Function> retCtor = V8ArrayBuffer::getTmpl()->GetFunction();
	v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance());

	struct V8ArrayBuffer::V8ArrayBufferPrivate* retPrivData = new V8ArrayBuffer::V8ArrayBufferPrivate();
	retPrivData->nativeObj = localInstance;

	retObj->SetInternalField(0, V8DOM::toExternal(retPrivData));

	retObj.MakeWeak(0, V8ArrayBuffer::jsDestructor);
	return retObj;
}

v8::Handle<v8::Value> V8ArrayBuffer::byteLengthAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) {
	v8::Local<v8::Object> self = info.Holder();
	struct V8ArrayBufferPrivate* privData = V8DOM::toClassPtr<V8ArrayBufferPrivate >(self->GetInternalField(0));

	return v8::Integer::New(privData->nativeObj->getByteLength());
}

v8::Handle<v8::Value> V8ArrayBuffer::mimeTypeAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) {
	v8::Local<v8::Object> self = info.Holder();
	struct V8ArrayBufferPrivate* privData = V8DOM::toClassPtr<V8ArrayBufferPrivate >(self->GetInternalField(0));

	return v8::String::New(privData->nativeObj->getMimeType().c_str());
}

void V8ArrayBuffer::mimeTypeAttrSetter(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::AccessorInfo& info) {
	v8::Local<v8::Object> self = info.Holder();
	struct V8ArrayBufferPrivate* privData = V8DOM::toClassPtr<V8ArrayBufferPrivate >(self->GetInternalField(0));
	v8::String::AsciiValue localMimeType(value);
	privData->nativeObj->setMimeType(*localMimeType);
}

v8::Handle<v8::Value> V8ArrayBuffer::md5Callback(const v8::Arguments& args) {

	v8::Local<v8::Object> self = args.Holder();
	struct V8ArrayBufferPrivate* privData = V8DOM::toClassPtr<V8ArrayBufferPrivate >(self->GetInternalField(0));
	if (false) {
	} else if (args.Length() == 0) {

		std::string retVal = privData->nativeObj->md5();

		return v8::String::New(retVal.c_str());
	}
	throw V8Exception("Parameter mismatch while calling md5");
	return v8::Undefined();
}

v8::Handle<v8::Value> V8ArrayBuffer::base64Callback(const v8::Arguments& args) {

	v8::Local<v8::Object> self = args.Holder();
	struct V8ArrayBufferPrivate* privData = V8DOM::toClassPtr<V8ArrayBufferPrivate >(self->GetInternalField(0));
	if (false) {
	} else if (args.Length() == 0) {

		std::string retVal = privData->nativeObj->base64();

		return v8::String::New(retVal.c_str());
	}
	throw V8Exception("Parameter mismatch while calling base64");
	return v8::Undefined();
}

v8::Handle<v8::Value> V8ArrayBuffer::sliceCallback(const v8::Arguments& args) {

	v8::Local<v8::Object> self = args.Holder();
	struct V8ArrayBufferPrivate* privData = V8DOM::toClassPtr<V8ArrayBufferPrivate >(self->GetInternalField(0));
	if (false) {
	} else if (args.Length() == 2 &&
	           args[0]->IsInt32() &&
	           args[1]->IsInt32()) {
		long localBegin = args[0]->ToNumber()->Int32Value();
		long localEnd = args[1]->ToNumber()->Int32Value();

		uscxml::ArrayBuffer* retVal = new uscxml::ArrayBuffer(privData->nativeObj->slice(localBegin, localEnd));
		v8::Handle<v8::Function> retCtor = V8ArrayBuffer::getTmpl()->GetFunction();
		v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance());

		struct V8ArrayBuffer::V8ArrayBufferPrivate* retPrivData = new V8ArrayBuffer::V8ArrayBufferPrivate();
		retPrivData->dom = privData->dom;
		retPrivData->nativeObj = retVal;

		retObj->SetInternalField(0, V8DOM::toExternal(retPrivData));

		retObj.MakeWeak(0, V8ArrayBuffer::jsDestructor);
		return retObj;

	} else if (args.Length() == 1 &&
	           args[0]->IsInt32()) {
		long localBegin = args[0]->ToNumber()->Int32Value();

		uscxml::ArrayBuffer* retVal = new uscxml::ArrayBuffer(privData->nativeObj->slice(localBegin));
		v8::Handle<v8::Function> retCtor = V8ArrayBuffer::getTmpl()->GetFunction();
		v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance());

		struct V8ArrayBuffer::V8ArrayBufferPrivate* retPrivData = new V8ArrayBuffer::V8ArrayBufferPrivate();
		retPrivData->dom = privData->dom;
		retPrivData->nativeObj = retVal;

		retObj->SetInternalField(0, V8DOM::toExternal(retPrivData));

		retObj.MakeWeak(0, V8ArrayBuffer::jsDestructor);
		return retObj;

	}
	throw V8Exception("Parameter mismatch while calling slice");
	return v8::Undefined();
}

v8::Handle<v8::Value> V8ArrayBuffer::isViewCallback(const v8::Arguments& args) {

	v8::Local<v8::Object> self = args.Holder();
	struct V8ArrayBufferPrivate* privData = V8DOM::toClassPtr<V8ArrayBufferPrivate >(self->GetInternalField(0));
	if (false) {
	} else if (args.Length() == 1 &&
	           true) {
		void* localValue = v8::External::Unwrap(args[0]->ToObject()->GetInternalField(0));

		bool retVal = privData->nativeObj->isView(localValue);

		return v8::Boolean::New(retVal);
	}
	throw V8Exception("Parameter mismatch while calling isView");
	return v8::Undefined();
}
bool V8ArrayBuffer::hasInstance(v8::Handle<v8::Value> value) {
	return getTmpl()->HasInstance(value);
}

}
}