1/*
2    This file is part of the WebKit open source project.
3    This file has been generated by generate-bindings.pl. DO NOT MODIFY!
4
5    This library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Library General Public
7    License as published by the Free Software Foundation; either
8    version 2 of the License, or (at your option) any later version.
9
10    This library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Library General Public License for more details.
14
15    You should have received a copy of the GNU Library General Public License
16    along with this library; see the file COPYING.LIB.  If not, write to
17    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18    Boston, MA 02110-1301, USA.
19*/
20
21#include "config.h"
22#include "JSFloat64Array.h"
23
24#include "ExceptionCode.h"
25#include "JSArrayBufferViewHelper.h"
26#include "JSDOMBinding.h"
27#include "JSFloat32Array.h"
28#include "JSInt32Array.h"
29#include <runtime/Error.h>
30#include <runtime/Float64Array.h>
31#include <runtime/Int32Array.h>
32#include <runtime/PropertyNameArray.h>
33#include <wtf/GetPtr.h>
34
35using namespace JSC;
36
37namespace WebCore {
38
39/* Hash table */
40
41static const HashTableValue JSFloat64ArrayTableValues[] =
42{
43    { "constructor", DontEnum | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFloat64ArrayConstructor), (intptr_t)0, NoIntrinsic },
44    { 0, 0, 0, 0, NoIntrinsic }
45};
46
47static const HashTable JSFloat64ArrayTable = { 2, 1, JSFloat64ArrayTableValues, 0 };
48/* Hash table for constructor */
49
50static const HashTableValue JSFloat64ArrayConstructorTableValues[] =
51{
52    { 0, 0, 0, 0, NoIntrinsic }
53};
54
55static const HashTable JSFloat64ArrayConstructorTable = { 1, 0, JSFloat64ArrayConstructorTableValues, 0 };
56EncodedJSValue JSC_HOST_CALL JSFloat64ArrayConstructor::constructJSFloat64Array(ExecState* exec)
57{
58    JSFloat64ArrayConstructor* jsConstructor = jsCast<JSFloat64ArrayConstructor*>(exec->callee());
59    RefPtr<Float64Array> array = constructArrayBufferView<Float64Array, double>(exec);
60    if (!array.get())
61        // Exception has already been thrown.
62        return JSValue::encode(JSValue());
63    return JSValue::encode(asObject(toJS(exec, jsConstructor->globalObject(), array.get())));
64}
65
66JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, Float64Array* object)
67{
68    return toJSArrayBufferView<JSFloat64Array>(exec, globalObject, object);
69}
70
71void JSFloat64Array::indexSetter(JSC::ExecState* exec, unsigned index, JSC::JSValue value)
72{
73    impl()->set(index, value.toNumber(exec));
74}
75
76static const HashTable* getJSFloat64ArrayConstructorTable(ExecState* exec)
77{
78    return getHashTableForGlobalData(exec->vm(), &JSFloat64ArrayConstructorTable);
79}
80
81const ClassInfo JSFloat64ArrayConstructor::s_info = { "Float64ArrayConstructor", &Base::s_info, 0, getJSFloat64ArrayConstructorTable, CREATE_METHOD_TABLE(JSFloat64ArrayConstructor) };
82
83JSFloat64ArrayConstructor::JSFloat64ArrayConstructor(Structure* structure, JSDOMGlobalObject* globalObject)
84    : DOMConstructorObject(structure, globalObject)
85{
86}
87
88void JSFloat64ArrayConstructor::finishCreation(ExecState* exec, JSDOMGlobalObject* globalObject)
89{
90    Base::finishCreation(exec->vm());
91    ASSERT(inherits(info()));
92    putDirect(exec->vm(), exec->propertyNames().prototype, JSFloat64ArrayPrototype::self(exec, globalObject), DontDelete | ReadOnly);
93    putDirect(exec->vm(), exec->propertyNames().length, jsNumber(1), ReadOnly | DontDelete | DontEnum);
94}
95
96bool JSFloat64ArrayConstructor::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
97{
98    return getStaticValueSlot<JSFloat64ArrayConstructor, JSDOMWrapper>(exec, getJSFloat64ArrayConstructorTable(exec), jsCast<JSFloat64ArrayConstructor*>(object), propertyName, slot);
99}
100
101bool JSFloat64ArrayConstructor::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, PropertyName propertyName, PropertyDescriptor& descriptor)
102{
103    return getStaticValueDescriptor<JSFloat64ArrayConstructor, JSDOMWrapper>(exec, getJSFloat64ArrayConstructorTable(exec), jsCast<JSFloat64ArrayConstructor*>(object), propertyName, descriptor);
104}
105
106ConstructType JSFloat64ArrayConstructor::getConstructData(JSCell*, ConstructData& constructData)
107{
108    constructData.native.function = constructJSFloat64Array;
109    return ConstructTypeHost;
110}
111
112/* Hash table for prototype */
113
114static const HashTableValue JSFloat64ArrayPrototypeTableValues[] =
115{
116    { "foo", DontDelete | JSC::Function, (intptr_t)static_cast<NativeFunction>(jsFloat64ArrayPrototypeFunctionFoo), (intptr_t)1, NoIntrinsic },
117    { "set", DontDelete | JSC::Function, (intptr_t)static_cast<NativeFunction>(jsFloat64ArrayPrototypeFunctionSet), (intptr_t)0, NoIntrinsic },
118    { 0, 0, 0, 0, NoIntrinsic }
119};
120
121static const HashTable JSFloat64ArrayPrototypeTable = { 4, 3, JSFloat64ArrayPrototypeTableValues, 0 };
122static const HashTable* getJSFloat64ArrayPrototypeTable(ExecState* exec)
123{
124    return getHashTableForGlobalData(exec->vm(), &JSFloat64ArrayPrototypeTable);
125}
126
127const ClassInfo JSFloat64ArrayPrototype::s_info = { "Float64ArrayPrototype", &Base::s_info, 0, getJSFloat64ArrayPrototypeTable, CREATE_METHOD_TABLE(JSFloat64ArrayPrototype) };
128
129JSObject* JSFloat64ArrayPrototype::self(ExecState* exec, JSGlobalObject* globalObject)
130{
131    return getDOMPrototype<JSFloat64Array>(exec, globalObject);
132}
133
134bool JSFloat64ArrayPrototype::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
135{
136    JSFloat64ArrayPrototype* thisObject = jsCast<JSFloat64ArrayPrototype*>(object);
137    return getStaticFunctionSlot<JSObject>(exec, getJSFloat64ArrayPrototypeTable(exec), thisObject, propertyName, slot);
138}
139
140bool JSFloat64ArrayPrototype::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, PropertyName propertyName, PropertyDescriptor& descriptor)
141{
142    JSFloat64ArrayPrototype* thisObject = jsCast<JSFloat64ArrayPrototype*>(object);
143    return getStaticFunctionDescriptor<JSObject>(exec, getJSFloat64ArrayPrototypeTable(exec), thisObject, propertyName, descriptor);
144}
145
146static const HashTable* getJSFloat64ArrayTable(ExecState* exec)
147{
148    return getHashTableForGlobalData(exec->vm(), &JSFloat64ArrayTable);
149}
150
151const ClassInfo JSFloat64Array::s_info = { "Float64Array", &Base::s_info, 0, getJSFloat64ArrayTable , CREATE_METHOD_TABLE(JSFloat64Array) };
152
153JSFloat64Array::JSFloat64Array(Structure* structure, JSDOMGlobalObject* globalObject, PassRefPtr<Float64Array> impl)
154    : JSArrayBufferView(structure, globalObject, impl)
155{
156}
157
158void JSFloat64Array::finishCreation(VM& vm)
159{
160    Base::finishCreation(vm);
161    TypedArrayDescriptor descriptor(JSFloat64Array::info(), OBJECT_OFFSETOF(JSFloat64Array, m_storage), OBJECT_OFFSETOF(JSFloat64Array, m_storageLength));
162    vm.registerTypedArrayDescriptor(impl(), descriptor);
163    m_storage = impl()->data();
164    m_storageLength = impl()->length();
165    ASSERT(inherits(info()));
166}
167
168JSObject* JSFloat64Array::createPrototype(ExecState* exec, JSGlobalObject* globalObject)
169{
170    return JSFloat64ArrayPrototype::create(exec->vm(), globalObject, JSFloat64ArrayPrototype::createStructure(exec->vm(), globalObject, JSArrayBufferViewPrototype::self(exec, globalObject)));
171}
172
173bool JSFloat64Array::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
174{
175    JSFloat64Array* thisObject = jsCast<JSFloat64Array*>(object);
176    ASSERT_GC_OBJECT_INHERITS(thisObject, info());
177    unsigned index = propertyName.asIndex();
178    if (index != PropertyName::NotAnIndex && index < static_cast<Float64Array*>(thisObject->impl())->length()) {
179        slot.setValue(thisObject, thisObject->getByIndex(exec, index));
180        return true;
181    }
182    return getStaticValueSlot<JSFloat64Array, Base>(exec, getJSFloat64ArrayTable(exec), thisObject, propertyName, slot);
183}
184
185bool JSFloat64Array::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, PropertyName propertyName, PropertyDescriptor& descriptor)
186{
187    JSFloat64Array* thisObject = jsCast<JSFloat64Array*>(object);
188    ASSERT_GC_OBJECT_INHERITS(thisObject, info());
189    unsigned index = propertyName.asIndex();
190    if (index != PropertyName::NotAnIndex && index < static_cast<Float64Array*>(thisObject->impl())->length()) {
191        descriptor.setDescriptor(thisObject->getByIndex(exec, index), DontDelete);
192        return true;
193    }
194    return getStaticValueDescriptor<JSFloat64Array, Base>(exec, getJSFloat64ArrayTable(exec), thisObject, propertyName, descriptor);
195}
196
197bool JSFloat64Array::getOwnPropertySlotByIndex(JSObject* object, ExecState* exec, unsigned index, PropertySlot& slot)
198{
199    JSFloat64Array* thisObject = jsCast<JSFloat64Array*>(object);
200    ASSERT_GC_OBJECT_INHERITS(thisObject, info());
201    if (index < static_cast<Float64Array*>(thisObject->impl())->length()) {
202        slot.setValue(thisObject, thisObject->getByIndex(exec, index));
203        return true;
204    }
205    return Base::getOwnPropertySlotByIndex(thisObject, exec, index, slot);
206}
207
208JSValue jsFloat64ArrayConstructor(ExecState* exec, JSValue slotBase, PropertyName)
209{
210    JSFloat64Array* domObject = jsCast<JSFloat64Array*>(asObject(slotBase));
211    return JSFloat64Array::getConstructor(exec, domObject->globalObject());
212}
213
214void JSFloat64Array::put(JSCell* cell, ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot& slot)
215{
216    JSFloat64Array* thisObject = jsCast<JSFloat64Array*>(cell);
217    ASSERT_GC_OBJECT_INHERITS(thisObject, info());
218    unsigned index = propertyName.asIndex();
219    if (index != PropertyName::NotAnIndex) {
220        thisObject->indexSetter(exec, index, value);
221        return;
222    }
223    Base::put(thisObject, exec, propertyName, value, slot);
224}
225
226void JSFloat64Array::putByIndex(JSCell* cell, ExecState* exec, unsigned index, JSValue value, bool shouldThrow)
227{
228    JSFloat64Array* thisObject = jsCast<JSFloat64Array*>(cell);
229    ASSERT_GC_OBJECT_INHERITS(thisObject, info());
230    if (index <= MAX_ARRAY_INDEX) {
231        UNUSED_PARAM(shouldThrow);
232        thisObject->indexSetter(exec, index, value);
233        return;
234    }
235    Base::putByIndex(cell, exec, index, value, shouldThrow);
236}
237
238void JSFloat64Array::getOwnPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
239{
240    JSFloat64Array* thisObject = jsCast<JSFloat64Array*>(object);
241    ASSERT_GC_OBJECT_INHERITS(thisObject, info());
242    for (unsigned i = 0; i < static_cast<Float64Array*>(thisObject->impl())->length(); ++i)
243        propertyNames.add(Identifier::from(exec, i));
244     Base::getOwnPropertyNames(thisObject, exec, propertyNames, mode);
245}
246
247JSValue JSFloat64Array::getConstructor(ExecState* exec, JSGlobalObject* globalObject)
248{
249    return getDOMConstructor<JSFloat64ArrayConstructor>(exec, jsCast<JSDOMGlobalObject*>(globalObject));
250}
251
252EncodedJSValue JSC_HOST_CALL jsFloat64ArrayPrototypeFunctionFoo(ExecState* exec)
253{
254    JSValue thisValue = exec->thisValue();
255    if (!thisValue.inherits(JSFloat64Array::info()))
256        return throwVMTypeError(exec);
257    JSFloat64Array* castedThis = jsCast<JSFloat64Array*>(asObject(thisValue));
258    ASSERT_GC_OBJECT_INHERITS(castedThis, JSFloat64Array::info());
259    Float64Array* impl = static_cast<Float64Array*>(castedThis->impl());
260    if (exec->argumentCount() < 1)
261        return throwVMError(exec, createNotEnoughArgumentsError(exec));
262    Float32Array* array(toFloat32Array(exec->argument(0)));
263    if (exec->hadException())
264        return JSValue::encode(jsUndefined());
265
266    JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(impl->foo(array)));
267    return JSValue::encode(result);
268}
269
270EncodedJSValue JSC_HOST_CALL jsFloat64ArrayPrototypeFunctionSet(ExecState* exec)
271{
272    JSValue thisValue = exec->thisValue();
273    if (!thisValue.inherits(JSFloat64Array::info()))
274        return throwVMTypeError(exec);
275    JSFloat64Array* castedThis = jsCast<JSFloat64Array*>(asObject(thisValue));
276    ASSERT_GC_OBJECT_INHERITS(castedThis, JSFloat64Array::info());
277    return JSValue::encode(setWebGLArrayHelper<Float64Array, double>(exec, castedThis->impl()));
278}
279
280
281JSValue JSFloat64Array::getByIndex(ExecState*, unsigned index)
282{
283    ASSERT_GC_OBJECT_INHERITS(this, info());
284    double result = static_cast<Float64Array*>(impl())->item(index);
285    if (std::isnan(result))
286        return jsNaN();
287    return JSValue(result);
288}
289
290Float64Array* toFloat64Array(JSC::JSValue value)
291{
292    return value.inherits(JSFloat64Array::info()) ? jsCast<JSFloat64Array*>(asObject(value))->impl() : 0;
293}
294
295}
296