static JSC::JSValue dataFunctioni(DataFunctionToCall f, JSC::ExecState* exec, WebGLRenderingContext& context) { if (exec->argumentCount() != 2) return exec->vm().throwException(exec, createNotEnoughArgumentsError(exec)); WebGLUniformLocation* location = toWebGLUniformLocation(exec->uncheckedArgument(0)); if (!location && !exec->uncheckedArgument(0).isUndefinedOrNull()) return throwTypeError(exec); RefPtr<Int32Array> webGLArray = toInt32Array(exec->uncheckedArgument(1)); ExceptionCode ec = 0; if (webGLArray) { switch (f) { case f_uniform1v: context.uniform1iv(location, webGLArray.get(), ec); break; case f_uniform2v: context.uniform2iv(location, webGLArray.get(), ec); break; case f_uniform3v: context.uniform3iv(location, webGLArray.get(), ec); break; case f_uniform4v: context.uniform4iv(location, webGLArray.get(), ec); break; default: break; } setDOMException(exec, ec); return jsUndefined(); } Vector<int, 64> array; if (!toVector(exec, exec->uncheckedArgument(1), array)) return throwTypeError(exec); switch (f) { case f_uniform1v: context.uniform1iv(location, array.data(), array.size(), ec); break; case f_uniform2v: context.uniform2iv(location, array.data(), array.size(), ec); break; case f_uniform3v: context.uniform3iv(location, array.data(), array.size(), ec); break; case f_uniform4v: context.uniform4iv(location, array.data(), array.size(), ec); break; default: break; } setDOMException(exec, ec); return jsUndefined(); }
static v8::Handle<v8::Value> uniformHelperi(const v8::Arguments& args, FunctionToCall functionToCall) { // Forms: // * glUniform1iv(GLUniformLocation location, Array data); // * glUniform1iv(GLUniformLocation location, Int32Array data); // * glUniform2iv(GLUniformLocation location, Array data); // * glUniform2iv(GLUniformLocation location, Int32Array data); // * glUniform3iv(GLUniformLocation location, Array data); // * glUniform3iv(GLUniformLocation location, Int32Array data); // * glUniform4iv(GLUniformLocation location, Array data); // * glUniform4iv(GLUniformLocation location, Int32Array data); if (args.Length() != 2) { V8Proxy::setDOMException(SYNTAX_ERR); return notHandledByInterceptor(); } WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(args.Holder()); if (args.Length() > 0 && !isUndefinedOrNull(args[0]) && !V8WebGLUniformLocation::HasInstance(args[0])) { V8Proxy::throwTypeError(); return notHandledByInterceptor(); } bool ok = false; WebGLUniformLocation* location = toWebGLUniformLocation(args[0], ok); if (V8Int32Array::HasInstance(args[1])) { Int32Array* array = V8Int32Array::toNative(args[1]->ToObject()); ASSERT(array != NULL); ExceptionCode ec = 0; switch (functionToCall) { case kUniform1v: context->uniform1iv(location, array, ec); break; case kUniform2v: context->uniform2iv(location, array, ec); break; case kUniform3v: context->uniform3iv(location, array, ec); break; case kUniform4v: context->uniform4iv(location, array, ec); break; default: ASSERT_NOT_REACHED(); break; } if (ec) V8Proxy::setDOMException(ec); return v8::Undefined(); } if (args[1].IsEmpty() || !args[1]->IsArray()) { V8Proxy::throwTypeError(); return notHandledByInterceptor(); } v8::Handle<v8::Array> array = v8::Local<v8::Array>::Cast(args[1]); uint32_t len = array->Length(); int* data = jsArrayToIntArray(array, len); if (!data) { // FIXME: consider different / better exception type. V8Proxy::setDOMException(SYNTAX_ERR); return notHandledByInterceptor(); } ExceptionCode ec = 0; switch (functionToCall) { case kUniform1v: context->uniform1iv(location, data, len, ec); break; case kUniform2v: context->uniform2iv(location, data, len, ec); break; case kUniform3v: context->uniform3iv(location, data, len, ec); break; case kUniform4v: context->uniform4iv(location, data, len, ec); break; default: ASSERT_NOT_REACHED(); break; } fastFree(data); if (ec) V8Proxy::setDOMException(ec); return v8::Undefined(); }