本文整理汇总了C++中js::MutableHandleValue类的典型用法代码示例。如果您正苦于以下问题:C++ MutableHandleValue类的具体用法?C++ MutableHandleValue怎么用?C++ MutableHandleValue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MutableHandleValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rq
template<> void ScriptInterface::ToJSVal<CFixedVector3D>(JSContext* cx, JS::MutableHandleValue ret, const CFixedVector3D& val)
{
JSAutoRequest rq(cx);
// apply the Vector3D prototype to the return value;
ScriptInterface::CxPrivate* pCxPrivate = ScriptInterface::GetScriptInterfaceAndCBData(cx);
JS::RootedObject proto(cx, &pCxPrivate->pScriptInterface->GetCachedValue(ScriptInterface::CACHE_VECTOR3DPROTO).toObject());
JS::RootedObject obj(cx, JS_NewObject(cx, nullptr, proto, JS::NullPtr()));
if (!obj)
{
ret.setUndefined();
return;
}
JS::RootedValue x(cx);
JS::RootedValue y(cx);
JS::RootedValue z(cx);
ToJSVal(cx, &x, val.X);
ToJSVal(cx, &y, val.Y);
ToJSVal(cx, &z, val.Z);
JS_SetProperty(cx, obj, "x", x);
JS_SetProperty(cx, obj, "y", y);
JS_SetProperty(cx, obj, "z", z);
ret.setObject(*obj);
}
示例2: ar
bool rs::jsapi::Object::Get(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) {
JSAutoRequest ar(cx);
auto state = Object::GetState(cx, obj);
if (state != nullptr && state->getter != nullptr) {
Value value(cx);
auto name = JSID_TO_STRING(id);
char nameBuffer[256];
auto nameLength = JS_EncodeStringToBuffer(cx, name, nameBuffer, sizeof(nameBuffer) - 1);
try {
value.setUndefined();
if (nameLength < sizeof(nameBuffer)) {
nameBuffer[nameLength] = '\0';
state->getter(nameBuffer, value);
} else {
std::vector<char> nameVector(nameLength + 1);
nameLength = JS_EncodeStringToBuffer(cx, name, &nameVector[0], nameVector.size() - 1);
nameVector[nameLength] = '\0';
state->getter(&nameVector[0], value);
}
vp.set(value);
return true;
} catch (const std::exception& ex) {
JS_ReportError(cx, ex.what());
return false;
}
} else {
vp.setUndefined();
return true;
}
}
示例3: MakeContextCurrent
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);
}
示例4: ErrorInvalidOperation
void
WebGL2Context::GetSamplerParameter(JSContext*, WebGLSampler* sampler, GLenum pname, JS::MutableHandleValue retval)
{
if (IsContextLost())
return;
if (!sampler || sampler->IsDeleted())
return ErrorInvalidOperation("getSamplerParameter: invalid sampler");
if (!ValidateSamplerParameterName(pname, "getSamplerParameter"))
return;
retval.set(JS::NullValue());
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;
}
}
示例5: JSSetter_volume
bool JSAudioContext::JSSetter_volume(JSContext *cx, JS::MutableHandleValue vp)
{
if (vp.isNumber()) {
m_Audio->setVolume((float)vp.toNumber());
}
return true;
}
示例6: switch
void
WebGL2Context::GetIndexedParameter(JSContext* cx, GLenum target, GLuint index,
JS::MutableHandleValue retval, ErrorResult& out_error)
{
const char funcName[] = "getIndexedParameter";
retval.set(JS::NullValue());
if (IsContextLost())
return;
const std::vector<IndexedBufferBinding>* bindings;
switch (target) {
case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER_START:
case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
bindings = &(mBoundTransformFeedback->mIndexedBindings);
break;
case LOCAL_GL_UNIFORM_BUFFER_BINDING:
case LOCAL_GL_UNIFORM_BUFFER_START:
case LOCAL_GL_UNIFORM_BUFFER_SIZE:
bindings = &mIndexedUniformBufferBindings;
break;
default:
ErrorInvalidEnumInfo("getIndexedParameter: target", target);
return;
}
if (index >= bindings->size()) {
ErrorInvalidValue("%s: `index` must be < %s.", funcName,
"MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS");
return;
}
const auto& binding = (*bindings)[index];
JS::Value ret = JS::NullValue();
switch (target) {
case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
case LOCAL_GL_UNIFORM_BUFFER_BINDING:
if (binding.mBufferBinding) {
ret = WebGLObjectAsJSValue(cx, binding.mBufferBinding.get(), out_error);
}
break;
case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER_START:
case LOCAL_GL_UNIFORM_BUFFER_START:
ret = JS::NumberValue(binding.mRangeStart);
break;
case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
case LOCAL_GL_UNIFORM_BUFFER_SIZE:
ret = JS::NumberValue(binding.mRangeSize);
break;
}
retval.set(ret);
}
示例7: rq
template<> void ScriptInterface::ToJSVal<const char*>(JSContext* cx, JS::MutableHandleValue ret, const char* const& val)
{
JSAutoRequest rq(cx);
JS::RootedString str(cx, JS_NewStringCopyZ(cx, val));
if (str)
ret.setString(str);
else
ret.setUndefined();
}
示例8: JSSetter_position
bool JSAudioNodeCustomSource::JSSetter_position(JSContext *cx,
JS::MutableHandleValue vp)
{
if (vp.isNumber()) {
this->getNode<AudioSourceCustom>()->seek(vp.toNumber());
}
return true;
}
示例9: GetQuery
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);
}
示例10: GuiPoll
void CNetClient::GuiPoll(JS::MutableHandleValue ret)
{
if (m_GuiMessageQueue.empty())
{
ret.setUndefined();
return;
}
ret.set(m_GuiMessageQueue.front());
m_GuiMessageQueue.pop_front();
}
示例11: JS_NewNumberValue
static JSBool
gjs_value_from_gsize(JSContext *context,
gsize v,
JS::MutableHandleValue value_p)
{
if (v > (gsize) JSVAL_INT_MAX) {
value_p.set(INT_TO_JSVAL(v));
return JS_TRUE;
} else {
return JS_NewNumberValue(context, v, value_p.address());
}
}
示例12: CallConstructor
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));
}
示例13: _MozJSCreateFunction
void MozJSImplScope::_MozJSCreateFunction(const char* raw,
ScriptingFunction functionNumber,
JS::MutableHandleValue fun) {
std::string code = str::stream() << "_funcs" << functionNumber << " = "
<< parseJSFunctionOrExpression(_context, StringData(raw));
JS::CompileOptions co(_context);
setCompileOptions(&co);
_checkErrorState(JS::Evaluate(_context, _global, co, code.c_str(), code.length(), fun));
uassert(10232,
"not a function",
fun.isObject() && JS_ObjectIsFunction(_context, fun.toObjectOrNull()));
}
示例14: toValue
void IdWrapper::toValue(JS::MutableHandleValue value) const {
if (isInt()) {
value.setInt32(toInt32());
return;
}
if (isString()) {
auto str = JSID_TO_STRING(_value);
value.setString(str);
return;
}
uasserted(ErrorCodes::BadValue, "Failed to toValue() non-string and non-integer jsid");
}
示例15: JSGetter_channels
bool JSAudioContext::JSGetter_channels(JSContext *cx, JS::MutableHandleValue vp)
{
AudioParameters *params = m_Audio->m_OutputParameters;
vp.setInt32(params->m_Channels);
return true;
}