tizen beta release
[profile/ivi/webkit-efl.git] / Source / WebCore / bindings / js / JSWebGLRenderingContextCustom.cpp
1 /*
2  * Copyright (C) 2009 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
24  */
25
26 #include "config.h"
27
28 #if ENABLE(WEBGL)
29
30 #include "JSWebGLRenderingContext.h"
31
32 #include "ExceptionCode.h"
33 #include "HTMLCanvasElement.h"
34 #include "HTMLImageElement.h"
35 #include "JSFloat32Array.h"
36 #include "JSHTMLCanvasElement.h"
37 #include "JSHTMLImageElement.h"
38 #include "JSImageData.h"
39 #include "JSInt32Array.h"
40 #include "JSOESStandardDerivatives.h"
41 #include "JSOESTextureFloat.h"
42 #include "JSOESVertexArrayObject.h"
43 #include "JSUint8Array.h"
44 #include "JSWebGLBuffer.h"
45 #include "JSWebGLFramebuffer.h"
46 #include "JSWebGLProgram.h"
47 #include "JSWebGLRenderbuffer.h"
48 #include "JSWebGLShader.h"
49 #include "JSWebGLTexture.h"
50 #include "JSWebGLUniformLocation.h"
51 #include "JSWebGLVertexArrayObjectOES.h"
52 #include "JSWebKitCSSMatrix.h"
53 #include "JSWebKitLoseContext.h"
54 #include "NotImplemented.h"
55 #include "OESStandardDerivatives.h"
56 #include "OESTextureFloat.h"
57 #include "OESVertexArrayObject.h"
58 #include "WebGLBuffer.h"
59 #include "WebGLDebugRendererInfo.h"
60 #include "WebGLDebugShaders.h"
61 #include "WebGLExtension.h"
62 #include "WebGLFramebuffer.h"
63 #include "WebGLGetInfo.h"
64 #include "WebGLProgram.h"
65 #include "WebGLRenderingContext.h"
66 #include "WebGLVertexArrayObjectOES.h"
67 #include "WebKitLoseContext.h"
68 #include <runtime/Error.h>
69 #include <runtime/JSArray.h>
70 #include <wtf/FastMalloc.h>
71 #include <wtf/Float32Array.h>
72 #include <wtf/Int32Array.h>
73 #include <wtf/OwnFastMallocPtr.h>
74
75 #if ENABLE(VIDEO)
76 #include "HTMLVideoElement.h"
77 #include "JSHTMLVideoElement.h"
78 #endif
79
80 using namespace JSC;
81
82 namespace WebCore {
83
84 static JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, const WebGLGetInfo& info)
85 {
86     switch (info.getType()) {
87     case WebGLGetInfo::kTypeBool:
88         return jsBoolean(info.getBool());
89     case WebGLGetInfo::kTypeBoolArray: {
90         MarkedArgumentBuffer list;
91         const Vector<bool>& value = info.getBoolArray();
92         for (size_t ii = 0; ii < value.size(); ++ii)
93             list.append(jsBoolean(value[ii]));
94         return constructArray(exec, globalObject, list);
95     }
96     case WebGLGetInfo::kTypeFloat:
97         return jsNumber(info.getFloat());
98     case WebGLGetInfo::kTypeInt:
99         return jsNumber(info.getInt());
100     case WebGLGetInfo::kTypeNull:
101         return jsNull();
102     case WebGLGetInfo::kTypeString:
103         return jsString(exec, info.getString());
104     case WebGLGetInfo::kTypeUnsignedInt:
105         return jsNumber(info.getUnsignedInt());
106     case WebGLGetInfo::kTypeWebGLBuffer:
107         return toJS(exec, globalObject, info.getWebGLBuffer());
108     case WebGLGetInfo::kTypeWebGLFloatArray:
109         return toJS(exec, globalObject, info.getWebGLFloatArray());
110     case WebGLGetInfo::kTypeWebGLFramebuffer:
111         return toJS(exec, globalObject, info.getWebGLFramebuffer());
112     case WebGLGetInfo::kTypeWebGLIntArray:
113         return toJS(exec, globalObject, info.getWebGLIntArray());
114     // FIXME: implement WebGLObjectArray
115     // case WebGLGetInfo::kTypeWebGLObjectArray:
116     case WebGLGetInfo::kTypeWebGLProgram:
117         return toJS(exec, globalObject, info.getWebGLProgram());
118     case WebGLGetInfo::kTypeWebGLRenderbuffer:
119         return toJS(exec, globalObject, info.getWebGLRenderbuffer());
120     case WebGLGetInfo::kTypeWebGLTexture:
121         return toJS(exec, globalObject, info.getWebGLTexture());
122     case WebGLGetInfo::kTypeWebGLUnsignedByteArray:
123         return toJS(exec, globalObject, info.getWebGLUnsignedByteArray());
124     case WebGLGetInfo::kTypeWebGLVertexArrayObjectOES:
125         return toJS(exec, globalObject, info.getWebGLVertexArrayObjectOES());
126     default:
127         notImplemented();
128         return jsUndefined();
129     }
130 }
131
132 enum ObjectType {
133     kBuffer, kRenderbuffer, kTexture, kVertexAttrib
134 };
135
136 static JSValue getObjectParameter(JSWebGLRenderingContext* obj, ExecState* exec, ObjectType objectType)
137 {
138     if (exec->argumentCount() != 2)
139         return throwSyntaxError(exec);
140
141     ExceptionCode ec = 0;
142     WebGLRenderingContext* context = static_cast<WebGLRenderingContext*>(obj->impl());
143     unsigned target = exec->argument(0).toInt32(exec);
144     if (exec->hadException())
145         return jsUndefined();
146     unsigned pname = exec->argument(1).toInt32(exec);
147     if (exec->hadException())
148         return jsUndefined();
149     WebGLGetInfo info;
150     switch (objectType) {
151     case kBuffer:
152         info = context->getBufferParameter(target, pname, ec);
153         break;
154     case kRenderbuffer:
155         info = context->getRenderbufferParameter(target, pname, ec);
156         break;
157     case kTexture:
158         info = context->getTexParameter(target, pname, ec);
159         break;
160     case kVertexAttrib:
161         // target => index
162         info = context->getVertexAttrib(target, pname, ec);
163         break;
164     default:
165         notImplemented();
166         break;
167     }
168     if (ec) {
169         setDOMException(exec, ec);
170         return jsUndefined();
171     }
172     return toJS(exec, obj->globalObject(), info);
173 }
174
175 enum WhichProgramCall {
176     kProgramParameter, kUniform
177 };
178
179 static JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, WebGLExtension* extension)
180 {
181     if (!extension)
182         return jsNull();
183     switch (extension->getName()) {
184     case WebGLExtension::WebKitLoseContextName:
185         return toJS(exec, globalObject, static_cast<WebKitLoseContext*>(extension));
186     case WebGLExtension::OESStandardDerivativesName:
187         return toJS(exec, globalObject, static_cast<OESStandardDerivatives*>(extension));
188     case WebGLExtension::OESTextureFloatName:
189         return toJS(exec, globalObject, static_cast<OESTextureFloat*>(extension));
190     case WebGLExtension::OESVertexArrayObjectName:
191         return toJS(exec, globalObject, static_cast<OESVertexArrayObject*>(extension));
192     case WebGLExtension::WebGLDebugRendererInfoName:
193         return toJS(exec, globalObject, static_cast<WebGLDebugRendererInfo*>(extension));
194     case WebGLExtension::WebGLDebugShadersName:
195         return toJS(exec, globalObject, static_cast<WebGLDebugShaders*>(extension));
196     }
197     ASSERT_NOT_REACHED();
198     return jsNull();
199 }
200
201 void JSWebGLRenderingContext::visitChildren(JSCell* cell, SlotVisitor& visitor)
202 {
203     JSWebGLRenderingContext* thisObject = jsCast<JSWebGLRenderingContext*>(cell);
204     ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);
205     COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
206     ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren());
207     Base::visitChildren(thisObject, visitor);
208     visitor.addOpaqueRoot(thisObject->impl());
209 }
210
211 JSValue JSWebGLRenderingContext::getAttachedShaders(ExecState* exec)
212 {
213     if (exec->argumentCount() < 1)
214         return throwSyntaxError(exec);
215     ExceptionCode ec = 0;
216     WebGLRenderingContext* context = static_cast<WebGLRenderingContext*>(impl());
217     if (exec->argumentCount() > 0 && !exec->argument(0).isUndefinedOrNull() && !exec->argument(0).inherits(&JSWebGLProgram::s_info))
218         return throwTypeError(exec);
219     WebGLProgram* program = toWebGLProgram(exec->argument(0));
220     if (exec->hadException())
221         return jsNull();
222     Vector<RefPtr<WebGLShader> > shaders;
223     bool succeed = context->getAttachedShaders(program, shaders, ec);
224     if (ec) {
225         setDOMException(exec, ec);
226         return jsNull();
227     }
228     if (!succeed)
229         return jsNull();
230     MarkedArgumentBuffer list;
231     for (size_t ii = 0; ii < shaders.size(); ++ii)
232         list.append(toJS(exec, globalObject(), shaders[ii].get()));
233     return constructArray(exec, globalObject(), list);
234 }
235
236 JSValue JSWebGLRenderingContext::getExtension(ExecState* exec)
237 {
238     if (exec->argumentCount() < 1)
239         return throwSyntaxError(exec);
240
241     WebGLRenderingContext* context = static_cast<WebGLRenderingContext*>(impl());
242     const String& name = ustringToString(exec->argument(0).toString(exec));
243     if (exec->hadException())
244         return jsUndefined();
245     WebGLExtension* extension = context->getExtension(name);
246     return toJS(exec, globalObject(), extension);
247 }
248
249 JSValue JSWebGLRenderingContext::getBufferParameter(ExecState* exec)
250 {
251     return getObjectParameter(this, exec, kBuffer);
252 }
253
254 JSValue JSWebGLRenderingContext::getFramebufferAttachmentParameter(ExecState* exec)
255 {
256     if (exec->argumentCount() != 3)
257         return throwSyntaxError(exec);
258
259     ExceptionCode ec = 0;
260     WebGLRenderingContext* context = static_cast<WebGLRenderingContext*>(impl());
261     unsigned target = exec->argument(0).toInt32(exec);
262     if (exec->hadException())
263         return jsUndefined();
264     unsigned attachment = exec->argument(1).toInt32(exec);
265     if (exec->hadException())
266         return jsUndefined();
267     unsigned pname = exec->argument(2).toInt32(exec);
268     if (exec->hadException())
269         return jsUndefined();
270     WebGLGetInfo info = context->getFramebufferAttachmentParameter(target, attachment, pname, ec);
271     if (ec) {
272         setDOMException(exec, ec);
273         return jsUndefined();
274     }
275     return toJS(exec, globalObject(), info);
276 }
277
278 JSValue JSWebGLRenderingContext::getParameter(ExecState* exec)
279 {
280     if (exec->argumentCount() != 1)
281         return throwSyntaxError(exec);
282
283     ExceptionCode ec = 0;
284     WebGLRenderingContext* context = static_cast<WebGLRenderingContext*>(impl());
285     unsigned pname = exec->argument(0).toInt32(exec);
286     if (exec->hadException())
287         return jsUndefined();
288     WebGLGetInfo info = context->getParameter(pname, ec);
289     if (ec) {
290         setDOMException(exec, ec);
291         return jsUndefined();
292     }
293     return toJS(exec, globalObject(), info);
294 }
295
296 JSValue JSWebGLRenderingContext::getProgramParameter(ExecState* exec)
297 {
298     if (exec->argumentCount() != 2)
299         return throwSyntaxError(exec);
300
301     ExceptionCode ec = 0;
302     WebGLRenderingContext* context = static_cast<WebGLRenderingContext*>(impl());
303     if (exec->argumentCount() > 0 && !exec->argument(0).isUndefinedOrNull() && !exec->argument(0).inherits(&JSWebGLProgram::s_info))
304         return throwTypeError(exec);
305     WebGLProgram* program = toWebGLProgram(exec->argument(0));
306     unsigned pname = exec->argument(1).toInt32(exec);
307     if (exec->hadException())
308         return jsUndefined();
309     WebGLGetInfo info = context->getProgramParameter(program, pname, ec);
310     if (ec) {
311         setDOMException(exec, ec);
312         return jsUndefined();
313     }
314     return toJS(exec, globalObject(), info);
315 }
316
317 JSValue JSWebGLRenderingContext::getRenderbufferParameter(ExecState* exec)
318 {
319     return getObjectParameter(this, exec, kRenderbuffer);
320 }
321
322 JSValue JSWebGLRenderingContext::getShaderParameter(ExecState* exec)
323 {
324     if (exec->argumentCount() != 2)
325         return throwSyntaxError(exec);
326
327     ExceptionCode ec = 0;
328     WebGLRenderingContext* context = static_cast<WebGLRenderingContext*>(impl());
329     if (exec->argumentCount() > 0 && !exec->argument(0).isUndefinedOrNull() && !exec->argument(0).inherits(&JSWebGLShader::s_info))
330         return throwTypeError(exec);
331     WebGLShader* shader = toWebGLShader(exec->argument(0));
332     unsigned pname = exec->argument(1).toInt32(exec);
333     if (exec->hadException())
334         return jsUndefined();
335     WebGLGetInfo info = context->getShaderParameter(shader, pname, ec);
336     if (ec) {
337         setDOMException(exec, ec);
338         return jsUndefined();
339     }
340     return toJS(exec, globalObject(), info);
341 }
342
343 JSValue JSWebGLRenderingContext::getSupportedExtensions(ExecState* exec)
344 {
345     WebGLRenderingContext* context = static_cast<WebGLRenderingContext*>(impl());
346     if (context->isContextLost())
347         return jsNull();
348     Vector<String> value = context->getSupportedExtensions();
349     MarkedArgumentBuffer list;
350     for (size_t ii = 0; ii < value.size(); ++ii)
351         list.append(jsString(exec, value[ii]));
352     return constructArray(exec, globalObject(), list);
353 }
354
355 JSValue JSWebGLRenderingContext::getTexParameter(ExecState* exec)
356 {
357     return getObjectParameter(this, exec, kTexture);
358 }
359
360 JSValue JSWebGLRenderingContext::getUniform(ExecState* exec)
361 {
362     if (exec->argumentCount() != 2)
363         return throwSyntaxError(exec);
364
365     ExceptionCode ec = 0;
366     WebGLRenderingContext* context = static_cast<WebGLRenderingContext*>(impl());
367     if (exec->argumentCount() > 0 && !exec->argument(0).isUndefinedOrNull() && !exec->argument(0).inherits(&JSWebGLProgram::s_info))
368         return throwTypeError(exec);
369     WebGLProgram* program = toWebGLProgram(exec->argument(0));
370     if (exec->argumentCount() > 1 && !exec->argument(1).isUndefinedOrNull() && !exec->argument(1).inherits(&JSWebGLUniformLocation::s_info))
371         return throwTypeError(exec);
372     WebGLUniformLocation* loc = toWebGLUniformLocation(exec->argument(1));
373     if (exec->hadException())
374         return jsUndefined();
375     WebGLGetInfo info = context->getUniform(program, loc, ec);
376     if (ec) {
377         setDOMException(exec, ec);
378         return jsUndefined();
379     }
380     return toJS(exec, globalObject(), info);
381 }
382
383 JSValue JSWebGLRenderingContext::getVertexAttrib(ExecState* exec)
384 {
385     return getObjectParameter(this, exec, kVertexAttrib);
386 }
387
388 template<typename T, size_t inlineCapacity>
389 bool toVector(JSC::ExecState* exec, JSC::JSValue value, Vector<T, inlineCapacity>& vector)
390 {
391     if (!value.isObject())
392         return false;
393
394     JSC::JSObject* object = asObject(value);
395     int32_t length = object->get(exec, JSC::Identifier(exec, "length")).toInt32(exec);
396
397     if (!vector.tryReserveCapacity(length))
398         return false;
399     vector.resize(length);
400
401     for (int32_t i = 0; i < length; ++i) {
402         JSC::JSValue v = object->get(exec, i);
403         if (exec->hadException())
404             return false;
405         vector[i] = static_cast<T>(v.toNumber(exec));
406     }
407
408     return true;
409 }
410
411 enum DataFunctionToCall {
412     f_uniform1v, f_uniform2v, f_uniform3v, f_uniform4v,
413     f_vertexAttrib1v, f_vertexAttrib2v, f_vertexAttrib3v, f_vertexAttrib4v
414 };
415
416 enum DataFunctionMatrixToCall {
417     f_uniformMatrix2fv, f_uniformMatrix3fv, f_uniformMatrix4fv
418 };
419
420 static bool functionForUniform(DataFunctionToCall f)
421 {
422     switch (f) {
423     case f_uniform1v:
424     case f_uniform2v:
425     case f_uniform3v:
426     case f_uniform4v:
427         return true;
428         break;
429     default: break;
430     }
431     return false;
432 }
433
434 static JSC::JSValue dataFunctionf(DataFunctionToCall f, JSC::ExecState* exec, WebGLRenderingContext* context)
435 {
436     if (exec->argumentCount() != 2)
437         return throwSyntaxError(exec);
438     
439     WebGLUniformLocation* location = 0;
440     long index = -1;
441     
442     if (functionForUniform(f)) {
443         if (exec->argumentCount() > 0 && !exec->argument(0).isUndefinedOrNull() && !exec->argument(0).inherits(&JSWebGLUniformLocation::s_info))
444             return throwTypeError(exec);
445         location = toWebGLUniformLocation(exec->argument(0));
446     } else
447         index = exec->argument(0).toInt32(exec);
448
449     if (exec->hadException())
450         return jsUndefined();
451         
452     RefPtr<Float32Array> webGLArray = toFloat32Array(exec->argument(1));
453     if (exec->hadException())    
454         return jsUndefined();
455         
456     ExceptionCode ec = 0;
457     if (webGLArray) {
458         switch (f) {
459         case f_uniform1v:
460             context->uniform1fv(location, webGLArray.get(), ec);
461             break;
462         case f_uniform2v:
463             context->uniform2fv(location, webGLArray.get(), ec);
464             break;
465         case f_uniform3v:
466             context->uniform3fv(location, webGLArray.get(), ec);
467             break;
468         case f_uniform4v:
469             context->uniform4fv(location, webGLArray.get(), ec);
470             break;
471         case f_vertexAttrib1v:
472             context->vertexAttrib1fv(index, webGLArray.get());
473             break;
474         case f_vertexAttrib2v:
475             context->vertexAttrib2fv(index, webGLArray.get());
476             break;
477         case f_vertexAttrib3v:
478             context->vertexAttrib3fv(index, webGLArray.get());
479             break;
480         case f_vertexAttrib4v:
481             context->vertexAttrib4fv(index, webGLArray.get());
482             break;
483         }
484         
485         setDOMException(exec, ec);
486         return jsUndefined();
487     }
488
489     Vector<float, 64> array;
490     if (!toVector(exec, exec->argument(1), array))
491         return throwTypeError(exec);
492
493     switch (f) {
494     case f_uniform1v:
495         context->uniform1fv(location, array.data(), array.size(), ec);
496         break;
497     case f_uniform2v:
498         context->uniform2fv(location, array.data(), array.size(), ec);
499         break;
500     case f_uniform3v:
501         context->uniform3fv(location, array.data(), array.size(), ec);
502         break;
503     case f_uniform4v:
504         context->uniform4fv(location, array.data(), array.size(), ec);
505         break;
506     case f_vertexAttrib1v:
507         context->vertexAttrib1fv(index, array.data(), array.size());
508         break;
509     case f_vertexAttrib2v:
510         context->vertexAttrib2fv(index, array.data(), array.size());
511         break;
512     case f_vertexAttrib3v:
513         context->vertexAttrib3fv(index, array.data(), array.size());
514         break;
515     case f_vertexAttrib4v:
516         context->vertexAttrib4fv(index, array.data(), array.size());
517         break;
518     }
519     
520     setDOMException(exec, ec);
521     return jsUndefined();
522 }
523
524 static JSC::JSValue dataFunctioni(DataFunctionToCall f, JSC::ExecState* exec, WebGLRenderingContext* context)
525 {
526     if (exec->argumentCount() != 2)
527         return throwSyntaxError(exec);
528
529     if (exec->argumentCount() > 0 && !exec->argument(0).isUndefinedOrNull() && !exec->argument(0).inherits(&JSWebGLUniformLocation::s_info))
530         return throwTypeError(exec);
531     WebGLUniformLocation* location = toWebGLUniformLocation(exec->argument(0));
532   
533     if (exec->hadException())
534         return jsUndefined();
535         
536     RefPtr<Int32Array> webGLArray = toInt32Array(exec->argument(1));
537     if (exec->hadException())    
538         return jsUndefined();
539         
540     ExceptionCode ec = 0;
541     if (webGLArray) {
542         switch (f) {
543         case f_uniform1v:
544             context->uniform1iv(location, webGLArray.get(), ec);
545             break;
546         case f_uniform2v:
547             context->uniform2iv(location, webGLArray.get(), ec);
548             break;
549         case f_uniform3v:
550             context->uniform3iv(location, webGLArray.get(), ec);
551             break;
552         case f_uniform4v:
553             context->uniform4iv(location, webGLArray.get(), ec);
554             break;
555         default:
556             break;
557         }
558         
559         setDOMException(exec, ec);
560         return jsUndefined();
561     }
562
563
564     Vector<int, 64> array;
565     if (!toVector(exec, exec->argument(1), array))
566         return throwTypeError(exec);
567
568     switch (f) {
569     case f_uniform1v:
570         context->uniform1iv(location, array.data(), array.size(), ec);
571         break;
572     case f_uniform2v:
573         context->uniform2iv(location, array.data(), array.size(), ec);
574         break;
575     case f_uniform3v:
576         context->uniform3iv(location, array.data(), array.size(), ec);
577         break;
578     case f_uniform4v:
579         context->uniform4iv(location, array.data(), array.size(), ec);
580         break;
581     default:
582         break;
583     }
584     
585     setDOMException(exec, ec);
586     return jsUndefined();
587 }
588
589 static JSC::JSValue dataFunctionMatrix(DataFunctionMatrixToCall f, JSC::ExecState* exec, WebGLRenderingContext* context)
590 {
591     if (exec->argumentCount() != 3)
592         return throwSyntaxError(exec);
593
594     if (exec->argumentCount() > 0 && !exec->argument(0).isUndefinedOrNull() && !exec->argument(0).inherits(&JSWebGLUniformLocation::s_info))
595         return throwTypeError(exec);
596     WebGLUniformLocation* location = toWebGLUniformLocation(exec->argument(0));
597
598     if (exec->hadException())    
599         return jsUndefined();
600         
601     bool transpose = exec->argument(1).toBoolean(exec);
602     if (exec->hadException())    
603         return jsUndefined();
604         
605     RefPtr<Float32Array> webGLArray = toFloat32Array(exec->argument(2));
606     if (exec->hadException())    
607         return jsUndefined();
608         
609     ExceptionCode ec = 0;
610     if (webGLArray) {
611         switch (f) {
612         case f_uniformMatrix2fv:
613             context->uniformMatrix2fv(location, transpose, webGLArray.get(), ec);
614             break;
615         case f_uniformMatrix3fv:
616             context->uniformMatrix3fv(location, transpose, webGLArray.get(), ec);
617             break;
618         case f_uniformMatrix4fv:
619             context->uniformMatrix4fv(location, transpose, webGLArray.get(), ec);
620             break;
621         }
622         
623         setDOMException(exec, ec);
624         return jsUndefined();
625     }
626
627     Vector<float, 64> array;
628     if (!toVector(exec, exec->argument(2), array))
629         return throwTypeError(exec);
630
631     switch (f) {
632     case f_uniformMatrix2fv:
633         context->uniformMatrix2fv(location, transpose, array.data(), array.size(), ec);
634         break;
635     case f_uniformMatrix3fv:
636         context->uniformMatrix3fv(location, transpose, array.data(), array.size(), ec);
637         break;
638     case f_uniformMatrix4fv:
639         context->uniformMatrix4fv(location, transpose, array.data(), array.size(), ec);
640         break;
641     }
642
643     setDOMException(exec, ec);
644     return jsUndefined();
645 }
646
647 JSC::JSValue JSWebGLRenderingContext::uniform1fv(JSC::ExecState* exec)
648 {
649     return dataFunctionf(f_uniform1v, exec, static_cast<WebGLRenderingContext*>(impl()));
650 }
651
652 JSC::JSValue JSWebGLRenderingContext::uniform1iv(JSC::ExecState* exec)
653 {
654     return dataFunctioni(f_uniform1v, exec, static_cast<WebGLRenderingContext*>(impl()));
655 }
656
657 JSC::JSValue JSWebGLRenderingContext::uniform2fv(JSC::ExecState* exec)
658 {
659     return dataFunctionf(f_uniform2v, exec, static_cast<WebGLRenderingContext*>(impl()));
660 }
661
662 JSC::JSValue JSWebGLRenderingContext::uniform2iv(JSC::ExecState* exec)
663 {
664     return dataFunctioni(f_uniform2v, exec, static_cast<WebGLRenderingContext*>(impl()));
665 }
666
667 JSC::JSValue JSWebGLRenderingContext::uniform3fv(JSC::ExecState* exec)
668 {
669     return dataFunctionf(f_uniform3v, exec, static_cast<WebGLRenderingContext*>(impl()));
670 }
671
672 JSC::JSValue JSWebGLRenderingContext::uniform3iv(JSC::ExecState* exec)
673 {
674     return dataFunctioni(f_uniform3v, exec, static_cast<WebGLRenderingContext*>(impl()));
675 }
676
677 JSC::JSValue JSWebGLRenderingContext::uniform4fv(JSC::ExecState* exec)
678 {
679     return dataFunctionf(f_uniform4v, exec, static_cast<WebGLRenderingContext*>(impl()));
680 }
681
682 JSC::JSValue JSWebGLRenderingContext::uniform4iv(JSC::ExecState* exec)
683 {
684     return dataFunctioni(f_uniform4v, exec, static_cast<WebGLRenderingContext*>(impl()));
685 }
686
687 JSC::JSValue JSWebGLRenderingContext::uniformMatrix2fv(JSC::ExecState* exec)
688 {
689     return dataFunctionMatrix(f_uniformMatrix2fv, exec, static_cast<WebGLRenderingContext*>(impl()));
690 }
691
692 JSC::JSValue JSWebGLRenderingContext::uniformMatrix3fv(JSC::ExecState* exec)
693 {
694     return dataFunctionMatrix(f_uniformMatrix3fv, exec, static_cast<WebGLRenderingContext*>(impl()));
695 }
696
697 JSC::JSValue JSWebGLRenderingContext::uniformMatrix4fv(JSC::ExecState* exec)
698 {
699     return dataFunctionMatrix(f_uniformMatrix4fv, exec, static_cast<WebGLRenderingContext*>(impl()));
700 }
701
702 JSC::JSValue JSWebGLRenderingContext::vertexAttrib1fv(JSC::ExecState* exec)
703 {
704     return dataFunctionf(f_vertexAttrib1v, exec, static_cast<WebGLRenderingContext*>(impl()));
705 }
706
707 JSC::JSValue JSWebGLRenderingContext::vertexAttrib2fv(JSC::ExecState* exec)
708 {
709     return dataFunctionf(f_vertexAttrib2v, exec, static_cast<WebGLRenderingContext*>(impl()));
710 }
711
712 JSC::JSValue JSWebGLRenderingContext::vertexAttrib3fv(JSC::ExecState* exec)
713 {
714     return dataFunctionf(f_vertexAttrib3v, exec, static_cast<WebGLRenderingContext*>(impl()));
715 }
716
717 JSC::JSValue JSWebGLRenderingContext::vertexAttrib4fv(JSC::ExecState* exec)
718 {
719     return dataFunctionf(f_vertexAttrib4v, exec, static_cast<WebGLRenderingContext*>(impl()));
720 }
721
722 } // namespace WebCore
723
724 #endif // ENABLE(WEBGL)