void WebGL2Context::GetSamplerParameter(JSContext*, WebGLSampler* sampler, GLenum pname, JS::MutableHandleValue retval) { retval.setNull(); if (IsContextLost()) return; if (!sampler || sampler->IsDeleted()) return ErrorInvalidOperation("getSamplerParameter: invalid sampler"); if (!ValidateSamplerParameterName(pname, "getSamplerParameter")) return; switch (pname) { case LOCAL_GL_TEXTURE_MIN_FILTER: case LOCAL_GL_TEXTURE_MAG_FILTER: case LOCAL_GL_TEXTURE_WRAP_S: case LOCAL_GL_TEXTURE_WRAP_T: case LOCAL_GL_TEXTURE_WRAP_R: case LOCAL_GL_TEXTURE_COMPARE_MODE: case LOCAL_GL_TEXTURE_COMPARE_FUNC: retval.set(JS::Int32Value( WebGLContextUnchecked::GetSamplerParameteriv(sampler, pname))); return; case LOCAL_GL_TEXTURE_MIN_LOD: case LOCAL_GL_TEXTURE_MAX_LOD: retval.set(JS::Float32Value( WebGLContextUnchecked::GetSamplerParameterfv(sampler, pname))); return; } }
template<> void ScriptInterface::ToJSVal<IComponent*>(JSContext* cx, JS::MutableHandleValue ret, IComponent* const& val) { JSAutoRequest rq(cx); if (val == NULL) { ret.setNull(); return; } // If this is a scripted component, just return the JS object directly JS::RootedValue instance(cx, val->GetJSInstance()); if (!instance.isNull()) { ret.set(instance); return; } // Otherwise we need to construct a wrapper object // (TODO: cache wrapper objects?) JS::RootedObject obj(cx); if (!val->NewJSObject(*ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface, &obj)) { // Report as an error, since scripts really shouldn't try to use unscriptable interfaces LOGERROR("IComponent does not have a scriptable interface"); ret.setUndefined(); return; } JS_SetPrivate(obj, static_cast<void*>(val)); ret.setObject(*obj); }
void WebGL2Context::GetActiveUniformBlockParameter(JSContext* cx, const WebGLProgram& program, GLuint uniformBlockIndex, GLenum pname, JS::MutableHandleValue out_retval, ErrorResult& out_error) { out_retval.setNull(); if (IsContextLost()) return; if (!ValidateObject("getActiveUniformBlockParameter: program", program)) return; MakeContextCurrent(); switch(pname) { case LOCAL_GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER: case LOCAL_GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER: case LOCAL_GL_UNIFORM_BLOCK_BINDING: case LOCAL_GL_UNIFORM_BLOCK_DATA_SIZE: case LOCAL_GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS: out_retval.set(program.GetActiveUniformBlockParam(uniformBlockIndex, pname)); return; case LOCAL_GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES: out_retval.set(program.GetActiveUniformBlockActiveUniforms(cx, uniformBlockIndex, &out_error)); return; } ErrorInvalidEnumInfo("getActiveUniformBlockParameter: parameter", pname); }
void WebGLContext::GetQuery(JSContext* cx, GLenum target, GLenum pname, JS::MutableHandleValue retval) { const FuncScope funcScope(*this, "getQuery"); retval.setNull(); if (IsContextLost()) return; switch (pname) { case LOCAL_GL_CURRENT_QUERY_EXT: { if (IsExtensionEnabled(WebGLExtensionID::EXT_disjoint_timer_query) && target == LOCAL_GL_TIMESTAMP) { // Doesn't seem illegal to ask about, but is always null. // TIMESTAMP has no slot, so ValidateQuerySlotByTarget would generate // INVALID_ENUM. return; } const auto& slot = ValidateQuerySlotByTarget(target); if (!slot || !*slot) return; const auto& query = *slot; if (target != query->Target()) return; JS::Rooted<JS::Value> v(cx); dom::GetOrCreateDOMReflector(cx, slot->get(), &v); retval.set(v); } return; case LOCAL_GL_QUERY_COUNTER_BITS_EXT: if (!IsExtensionEnabled(WebGLExtensionID::EXT_disjoint_timer_query)) break; if (target != LOCAL_GL_TIME_ELAPSED_EXT && target != LOCAL_GL_TIMESTAMP_EXT) { ErrorInvalidEnumInfo("target", target); return; } { GLint bits = 0; gl->fGetQueryiv(target, pname, &bits); if (!Has64BitTimestamps() && bits > 32) { bits = 32; } retval.set(JS::Int32Value(bits)); } return; default: break; } ErrorInvalidEnumInfo("pname", pname); }
void WebGLContext::GetQueryParameter(JSContext*, const WebGLQuery& query, GLenum pname, JS::MutableHandleValue retval) { const FuncScope funcScope(*this, "getQueryParameter"); retval.setNull(); if (IsContextLost()) return; if (!ValidateObject("query", query)) return; query.GetQueryParameter(pname, retval); }
void ScriptInterface::CallConstructor(JS::HandleValue ctor, JS::HandleValueArray argv, JS::MutableHandleValue out) { JSAutoRequest rq(m->m_cx); if (!ctor.isObject()) { LOGERROR("CallConstructor: ctor is not an object"); out.setNull(); return; } JS::RootedObject ctorObj(m->m_cx, &ctor.toObject()); out.setObjectOrNull(JS_New(m->m_cx, ctorObj, argv)); }
void WebGLContext::GetQueryParameter(JSContext*, const WebGLQuery& query, GLenum pname, JS::MutableHandleValue retval, const char* funcName) { if (!funcName) { funcName = "getQueryParameter"; } retval.setNull(); if (IsContextLost()) return; if (!ValidateObject(funcName, query)) return; query.GetQueryParameter(pname, retval); }
void WebGL2Context::GetActiveUniforms(JSContext* cx, const WebGLProgram& program, const dom::Sequence<GLuint>& uniformIndices, GLenum pname, JS::MutableHandleValue retval) { const char funcName[] = "getActiveUniforms"; retval.setNull(); if (IsContextLost()) return; if (!ValidateUniformEnum(this, pname, funcName)) return; if (!ValidateObject("getActiveUniforms: program", program)) return; const auto& numActiveUniforms = program.LinkInfo()->uniforms.size(); for (const auto& curIndex : uniformIndices) { if (curIndex >= numActiveUniforms) { ErrorInvalidValue("%s: Too-large active uniform index queried.", funcName); return; } } const auto& count = uniformIndices.Length(); JS::Rooted<JSObject*> array(cx, JS_NewArrayObject(cx, count)); UniquePtr<GLint[]> samples(new GLint[count]); if (!array || !samples) { ErrorOutOfMemory("%s: Failed to allocate buffers.", funcName); return; } retval.setObject(*array); MakeContextCurrent(); gl->fGetActiveUniformsiv(program.mGLName, count, uniformIndices.Elements(), pname, samples.get()); switch (pname) { case LOCAL_GL_UNIFORM_TYPE: case LOCAL_GL_UNIFORM_SIZE: case LOCAL_GL_UNIFORM_BLOCK_INDEX: case LOCAL_GL_UNIFORM_OFFSET: case LOCAL_GL_UNIFORM_ARRAY_STRIDE: case LOCAL_GL_UNIFORM_MATRIX_STRIDE: for (size_t i = 0; i < count; ++i) { JS::RootedValue value(cx); value = JS::Int32Value(samples[i]); if (!JS_DefineElement(cx, array, i, value, JSPROP_ENUMERATE)) return; } break; case LOCAL_GL_UNIFORM_IS_ROW_MAJOR: for (size_t i = 0; i < count; ++i) { JS::RootedValue value(cx); value = JS::BooleanValue(samples[i]); if (!JS_DefineElement(cx, array, i, value, JSPROP_ENUMERATE)) return; } break; default: MOZ_CRASH("Invalid pname"); } }
static void convertValue(JSContext * jct, JS::MutableHandleValue theData, const yarp::os::Value & inputValue) { ODL_ENTER(); //#### ODL_P2("jct = ", jct, "inputValue = ", &inputValue); //#### if (inputValue.isBool()) { theData.setBoolean(inputValue.asBool()); } else if (inputValue.isInt()) { theData.setInt32(inputValue.asInt()); } else if (inputValue.isString()) { YarpString value = inputValue.asString(); JSString * aString = JS_NewStringCopyZ(jct, value.c_str()); if (aString) { theData.setString(aString); } } else if (inputValue.isDouble()) { theData.setDouble(inputValue.asDouble()); } else if (inputValue.isDict()) { yarp::os::Property * value = inputValue.asDict(); if (value) { yarp::os::Bottle asList(value->toString()); convertDictionary(jct, theData, asList); } } else if (inputValue.isList()) { yarp::os::Bottle * value = inputValue.asList(); if (value) { yarp::os::Property asDict; if (ListIsReallyDictionary(*value, asDict)) { convertDictionary(jct, theData, *value); } else { convertList(jct, theData, *value); } } } else { // We don't know what to do with this... theData.setNull(); } ODL_EXIT(); //#### } // convertValue