JSValue JSDocument::getCSSCanvasContext(JSC::ExecState& state) { VM& vm = state.vm(); auto scope = DECLARE_THROW_SCOPE(vm); if (UNLIKELY(state.argumentCount() < 4)) return throwException(&state, scope, createNotEnoughArgumentsError(&state)); auto contextId = state.uncheckedArgument(0).toWTFString(&state); if (UNLIKELY(state.hadException())) return jsUndefined(); auto name = state.uncheckedArgument(1).toWTFString(&state); if (UNLIKELY(state.hadException())) return jsUndefined(); auto width = convert<int32_t>(state, state.uncheckedArgument(2), NormalConversion); if (UNLIKELY(state.hadException())) return jsUndefined(); auto height = convert<int32_t>(state, state.uncheckedArgument(3), NormalConversion); if (UNLIKELY(state.hadException())) return jsUndefined(); auto* context = wrapped().getCSSCanvasContext(WTFMove(contextId), WTFMove(name), WTFMove(width), WTFMove(height)); if (!context) return jsNull(); #if ENABLE(WEBGL) if (is<WebGLRenderingContextBase>(*context)) return toJS(&state, globalObject(), downcast<WebGLRenderingContextBase>(*context)); #endif return toJS(&state, globalObject(), downcast<CanvasRenderingContext2D>(*context)); }
static JSC::JSValue dataFunctioni(DataFunctionToCall f, JSC::ExecState& state, WebGLRenderingContextBase& context) { if (state.argumentCount() != 2) return state.vm().throwException(&state, createNotEnoughArgumentsError(&state)); WebGLUniformLocation* location = JSWebGLUniformLocation::toWrapped(state.uncheckedArgument(0)); if (!location && !state.uncheckedArgument(0).isUndefinedOrNull()) return throwTypeError(&state); RefPtr<Int32Array> webGLArray = toInt32Array(state.uncheckedArgument(1)); ExceptionCode ec = 0; if (webGLArray) { switch (f) { case f_uniform1v: context.uniform1iv(location, *webGLArray, ec); break; case f_uniform2v: context.uniform2iv(location, *webGLArray, ec); break; case f_uniform3v: context.uniform3iv(location, *webGLArray, ec); break; case f_uniform4v: context.uniform4iv(location, *webGLArray, ec); break; default: break; } setDOMException(&state, ec); return jsUndefined(); } Vector<int, 64> array; if (!toVector(state, state.uncheckedArgument(1), array)) return throwTypeError(&state); 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(&state, ec); return jsUndefined(); }
static JSC::JSValue dataFunctionMatrix(DataFunctionMatrixToCall f, JSC::ExecState& state, WebGLRenderingContextBase& context) { if (state.argumentCount() != 3) return state.vm().throwException(&state, createNotEnoughArgumentsError(&state)); WebGLUniformLocation* location = JSWebGLUniformLocation::toWrapped(state.uncheckedArgument(0)); if (!location && !state.uncheckedArgument(0).isUndefinedOrNull()) return throwTypeError(&state); bool transpose = state.uncheckedArgument(1).toBoolean(&state); if (state.hadException()) return jsUndefined(); RefPtr<Float32Array> webGLArray = toFloat32Array(state.uncheckedArgument(2)); ExceptionCode ec = 0; if (webGLArray) { switch (f) { case f_uniformMatrix2fv: context.uniformMatrix2fv(location, transpose, *webGLArray, ec); break; case f_uniformMatrix3fv: context.uniformMatrix3fv(location, transpose, *webGLArray, ec); break; case f_uniformMatrix4fv: context.uniformMatrix4fv(location, transpose, *webGLArray, ec); break; } setDOMException(&state, ec); return jsUndefined(); } Vector<float, 64> array; if (!toVector(state, state.uncheckedArgument(2), array)) return throwTypeError(&state); switch (f) { case f_uniformMatrix2fv: context.uniformMatrix2fv(location, transpose, array.data(), array.size(), ec); break; case f_uniformMatrix3fv: context.uniformMatrix3fv(location, transpose, array.data(), array.size(), ec); break; case f_uniformMatrix4fv: context.uniformMatrix4fv(location, transpose, array.data(), array.size(), ec); break; } setDOMException(&state, ec); return jsUndefined(); }
static JSC::JSValue dataFunctionf(DataFunctionToCall f, JSC::ExecState& state, WebGLRenderingContextBase& context) { if (state.argumentCount() != 2) return state.vm().throwException(&state, createNotEnoughArgumentsError(&state)); WebGLUniformLocation* location = 0; long index = -1; if (functionForUniform(f)) { location = JSWebGLUniformLocation::toWrapped(state.uncheckedArgument(0)); if (!location && !state.uncheckedArgument(0).isUndefinedOrNull()) return throwTypeError(&state); } else index = state.uncheckedArgument(0).toInt32(&state); if (state.hadException()) return jsUndefined(); RefPtr<Float32Array> webGLArray = toFloat32Array(state.uncheckedArgument(1)); if (state.hadException()) return jsUndefined(); ExceptionCode ec = 0; if (webGLArray) { switch (f) { case f_uniform1v: context.uniform1fv(location, *webGLArray, ec); break; case f_uniform2v: context.uniform2fv(location, *webGLArray, ec); break; case f_uniform3v: context.uniform3fv(location, *webGLArray, ec); break; case f_uniform4v: context.uniform4fv(location, *webGLArray, ec); break; case f_vertexAttrib1v: context.vertexAttrib1fv(index, *webGLArray); break; case f_vertexAttrib2v: context.vertexAttrib2fv(index, *webGLArray); break; case f_vertexAttrib3v: context.vertexAttrib3fv(index, *webGLArray); break; case f_vertexAttrib4v: context.vertexAttrib4fv(index, *webGLArray); break; } setDOMException(&state, ec); return jsUndefined(); } Vector<float, 64> array; if (!toVector(state, state.uncheckedArgument(1), array)) return throwTypeError(&state); switch (f) { case f_uniform1v: context.uniform1fv(location, array.data(), array.size(), ec); break; case f_uniform2v: context.uniform2fv(location, array.data(), array.size(), ec); break; case f_uniform3v: context.uniform3fv(location, array.data(), array.size(), ec); break; case f_uniform4v: context.uniform4fv(location, array.data(), array.size(), ec); break; case f_vertexAttrib1v: context.vertexAttrib1fv(index, array.data(), array.size()); break; case f_vertexAttrib2v: context.vertexAttrib2fv(index, array.data(), array.size()); break; case f_vertexAttrib3v: context.vertexAttrib3fv(index, array.data(), array.size()); break; case f_vertexAttrib4v: context.vertexAttrib4fv(index, array.data(), array.size()); break; } setDOMException(&state, ec); return jsUndefined(); }