本文整理汇总了C++中js::MutableHandleValue类的典型用法代码示例。如果您正苦于以下问题:C++ MutableHandleValue类的具体用法?C++ MutableHandleValue怎么用?C++ MutableHandleValue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MutableHandleValue类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:,项目名称:,代码行数:28,代码来源:
示例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;
}
}
开发者ID:dumganhar,项目名称:libjsapi,代码行数:34,代码来源:object.cpp
示例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);
}
开发者ID:alphan102,项目名称:gecko-dev,代码行数:32,代码来源:WebGL2ContextUniforms.cpp
示例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;
}
}
开发者ID:Nazi-Nigger,项目名称:gecko-dev,代码行数:33,代码来源:WebGL2ContextSamplers.cpp
示例5: JSSetter_volume
bool JSAudioContext::JSSetter_volume(JSContext *cx, JS::MutableHandleValue vp)
{
if (vp.isNumber()) {
m_Audio->setVolume((float)vp.toNumber());
}
return true;
}
开发者ID:nidium,项目名称:Nidium,代码行数:8,代码来源:JSAudioContext.cpp
示例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);
}
开发者ID:alphan102,项目名称:gecko-dev,代码行数:58,代码来源:WebGL2ContextUniforms.cpp
示例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();
}
开发者ID:krichter722,项目名称:0ad,代码行数:9,代码来源:ScriptConversions.cpp
示例8: JSSetter_position
bool JSAudioNodeCustomSource::JSSetter_position(JSContext *cx,
JS::MutableHandleValue vp)
{
if (vp.isNumber()) {
this->getNode<AudioSourceCustom>()->seek(vp.toNumber());
}
return true;
}
开发者ID:nidium,项目名称:Nidium,代码行数:9,代码来源:JSAudioNode.cpp
示例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);
}
开发者ID:Noctem,项目名称:gecko-dev,代码行数:56,代码来源:WebGL2ContextQueries.cpp
示例10: GuiPoll
void CNetClient::GuiPoll(JS::MutableHandleValue ret)
{
if (m_GuiMessageQueue.empty())
{
ret.setUndefined();
return;
}
ret.set(m_GuiMessageQueue.front());
m_GuiMessageQueue.pop_front();
}
开发者ID:joselitofilho,项目名称:0ad,代码行数:11,代码来源:NetClient.cpp
示例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());
}
}
开发者ID:victoryang,项目名称:gjs,代码行数:12,代码来源:byteArray.cpp
示例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));
}
开发者ID:Rektosauros,项目名称:0ad,代码行数:13,代码来源:ScriptInterface.cpp
示例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()));
}
开发者ID:Jaryli,项目名称:mongo,代码行数:14,代码来源:implscope.cpp
示例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");
}
开发者ID:ShaneHarvey,项目名称:mongo,代码行数:14,代码来源:idwrapper.cpp
示例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;
}
开发者ID:nidium,项目名称:Nidium,代码行数:7,代码来源:JSAudioContext.cpp
示例16:
bool
gjs_lookup_interface_constructor(JSContext *context,
GType gtype,
JS::MutableHandleValue value_p)
{
JSObject *constructor;
GIBaseInfo *interface_info;
interface_info = g_irepository_find_by_gtype(NULL, gtype);
if (interface_info == NULL) {
gjs_throw(context, "Cannot expose non introspectable interface %s",
g_type_name(gtype));
return false;
}
g_assert(g_base_info_get_type(interface_info) ==
GI_INFO_TYPE_INTERFACE);
constructor = gjs_lookup_generic_constructor(context, interface_info);
if (G_UNLIKELY (constructor == NULL))
return false;
g_base_info_unref(interface_info);
value_p.setObject(*constructor);
return true;
}
开发者ID:GNOME,项目名称:gjs,代码行数:28,代码来源:interface.cpp
示例17:
static JSBool
byte_array_set_index(JSContext *context,
JS::HandleObject obj,
ByteArrayInstance *priv,
gsize idx,
JS::MutableHandleValue value_p)
{
guint8 v;
if (!gjs_value_to_byte(context, value_p, &v)) {
return JS_FALSE;
}
byte_array_ensure_array(priv);
/* grow the array if necessary */
if (idx >= priv->array->len) {
g_byte_array_set_size(priv->array,
idx + 1);
}
g_array_index(priv->array, guint8, idx) = v;
/* Stop JS from storing a copy of the value */
value_p.set(JSVAL_VOID);
return JS_TRUE;
}
开发者ID:victoryang,项目名称:gjs,代码行数:28,代码来源:byteArray.cpp
示例18: fromStatus
void MongoStatusInfo::fromStatus(JSContext* cx, Status status, JS::MutableHandleValue value) {
auto scope = getScope(cx);
JS::RootedValue undef(cx);
undef.setUndefined();
JS::AutoValueArray<1> args(cx);
ValueReader(cx, args[0]).fromStringData(status.reason());
JS::RootedObject error(cx);
scope->getProto<ErrorInfo>().newInstance(args, &error);
JS::RootedObject thisv(cx);
scope->getProto<MongoStatusInfo>().newObjectWithProto(&thisv, error);
ObjectWrapper thisvObj(cx, thisv);
thisvObj.defineProperty(
InternedString::code,
undef,
JSPROP_ENUMERATE | JSPROP_SHARED,
smUtils::wrapConstrainedMethod<Functions::code, false, MongoStatusInfo>);
thisvObj.defineProperty(
InternedString::reason,
undef,
JSPROP_ENUMERATE | JSPROP_SHARED,
smUtils::wrapConstrainedMethod<Functions::reason, false, MongoStatusInfo>);
JS_SetPrivate(thisv, scope->trackedNew<Status>(std::move(status)));
value.setObjectOrNull(thisv);
}
开发者ID:i80and,项目名称:mongo,代码行数:30,代码来源:status.cpp
示例19: ar
/**
* gjs_string_from_ucs4:
* @cx: a #JSContext
* @ucs4_string: string of #gunichar
* @n_chars: number of characters in @ucs4_string or -1 for zero-terminated
* @value_p: JS::Value that will be filled with a string
*
* Returns: true on success, false otherwise in which case a JS error is thrown
*/
bool
gjs_string_from_ucs4(JSContext *cx,
const gunichar *ucs4_string,
ssize_t n_chars,
JS::MutableHandleValue value_p)
{
long u16_string_length;
GError *error = NULL;
char16_t *u16_string =
reinterpret_cast<char16_t *>(g_ucs4_to_utf16(ucs4_string, n_chars, NULL,
&u16_string_length, &error));
if (!u16_string) {
gjs_throw(cx, "Failed to convert UCS-4 string to UTF-16: %s",
error->message);
g_error_free(error);
return false;
}
JSAutoRequest ar(cx);
/* Avoid a copy - assumes that g_malloc == js_malloc == malloc */
JS::RootedString str(cx, JS_NewUCString(cx, u16_string, u16_string_length));
if (!str) {
gjs_throw(cx, "Failed to convert UCS-4 string to UTF-16");
return false;
}
value_p.setString(str);
return true;
}
开发者ID:leigh123linux,项目名称:cjs,代码行数:40,代码来源:jsapi-util-string.cpp
示例20: std_map_string_string_to_jsval
void std_map_string_string_to_jsval(JSContext* cx, const std::map<std::string, std::string>& v, JS::MutableHandleValue retVal) {
JS::RootedObject proto(cx);
JS::RootedObject parent(cx);
#if defined(MOZJS_MAJOR_VERSION) and MOZJS_MAJOR_VERSION >= 52
JS::RootedObject jsRet(cx, JS_NewObject(cx, NULL));
#elif defined(MOZJS_MAJOR_VERSION) and MOZJS_MAJOR_VERSION >= 26
JS::RootedObject jsRet(cx, JS_NewObject(cx, NULL, proto, parent));
#else
JSObject *jsRet = JS_NewObject(cx, NULL, NULL, NULL);
#endif
for (auto iter = v.begin(); iter != v.end(); ++iter) {
#if defined(MOZJS_MAJOR_VERSION) and MOZJS_MAJOR_VERSION >= 26
JS::RootedValue element(cx);
#else
jsval element;
#endif
std::string key = iter->first;
std::string val = iter->second;
JSString* jsstr = JS_NewStringCopyZ(cx, val.c_str());
element = JS::StringValue(jsstr);
if (!key.empty()) {
#if defined(MOZJS_MAJOR_VERSION) and MOZJS_MAJOR_VERSION >= 26
JS_SetProperty(cx, jsRet, key.c_str(), element);
#else
JS_SetProperty(cx, jsRet, key.c_str(), &element);
#endif
}
}
retVal.set(JS::ObjectOrNullValue(jsRet.get()));
}
开发者ID:sdkbox,项目名称:sdkbox-sample-appnext,代码行数:35,代码来源:SDKBoxJSHelper.cpp
注:本文中的js::MutableHandleValue类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论