本文整理汇总了C++中js::MutableHandleValue::setObject方法的典型用法代码示例。如果您正苦于以下问题:C++ MutableHandleValue::setObject方法的具体用法?C++ MutableHandleValue::setObject怎么用?C++ MutableHandleValue::setObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类js::MutableHandleValue
的用法示例。
在下文中一共展示了MutableHandleValue::setObject方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rq
template<> void ScriptInterface::ToJSVal<CColor>(JSContext* cx, JS::MutableHandleValue ret, CColor const& val)
{
JSAutoRequest rq(cx);
JS::RootedObject obj(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
if (!obj)
{
ret.setUndefined();
return;
}
JS::RootedValue r(cx);
JS::RootedValue g(cx);
JS::RootedValue b(cx);
JS::RootedValue a(cx);
ToJSVal(cx, &r, val.r);
ToJSVal(cx, &g, val.g);
ToJSVal(cx, &b, val.b);
ToJSVal(cx, &a, val.a);
JS_SetProperty(cx, obj, "r", r);
JS_SetProperty(cx, obj, "g", g);
JS_SetProperty(cx, obj, "b", b);
JS_SetProperty(cx, obj, "a", a);
ret.setObject(*obj);
}
示例2:
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;
}
示例3: arrayRooted
/*! @brief Convert a YARP list into a %JavaScript object.
@param[in] jct The %JavaScript engine context.
@param[in,out] theData The output object.
@param[in] inputValue The value to be processed. */
static void
convertList(JSContext * jct,
JS::MutableHandleValue theData,
const yarp::os::Bottle & inputValue)
{
ODL_ENTER(); //####
ODL_P2("jct = ", jct, "inputValue = ", &inputValue); //####
JSObject * valueArray = JS_NewArrayObject(jct, 0);
if (valueArray)
{
JS::RootedObject arrayRooted(jct);
JS::RootedValue anElement(jct);
JS::RootedId aRootedId(jct);
arrayRooted = valueArray;
for (int ii = 0, mm = inputValue.size(); mm > ii; ++ii)
{
yarp::os::Value aValue(inputValue.get(ii));
convertValue(jct, &anElement, aValue);
if (JS_IndexToId(jct, ii, &aRootedId))
{
JS_SetPropertyById(jct, arrayRooted, aRootedId, anElement);
}
}
theData.setObject(*valueArray);
}
ODL_EXIT(); //####
} // convertList
示例4: HoldJSObjects
NS_IMETHODIMP
nsUDPMessage::GetRawData(JSContext* cx,
JS::MutableHandleValue aRawData)
{
if(!mJsobj){
mJsobj = dom::Uint8Array::Create(cx, nullptr, mData.Length(), mData.Elements());
HoldJSObjects(this);
}
aRawData.setObject(*mJsobj);
return NS_OK;
}
示例5:
static bool
surface_from_g_argument(JSContext *context,
JS::MutableHandleValue value_p,
GIArgument *arg)
{
JSObject *obj;
obj = gjs_cairo_surface_from_surface(context, (cairo_surface_t*)arg->v_pointer);
if (!obj)
return false;
value_p.setObject(*obj);
return true;
}
示例6: rq
template<typename T> static void ToJSVal_vector(JSContext* cx, JS::MutableHandleValue ret, const std::vector<T>& val)
{
JSAutoRequest rq(cx);
JS::RootedObject obj(cx, JS_NewArrayObject(cx, 0));
if (!obj)
{
ret.setUndefined();
return;
}
for (u32 i = 0; i < val.size(); ++i)
{
JS::RootedValue el(cx);
ScriptInterface::ToJSVal<T>(cx, &el, val[i]);
JS_SetElement(cx, obj, i, el);
}
ret.setObject(*obj);
}
示例7: rq
// TODO: This is copy-pasted from scriptinterface/ScriptConversions.cpp (#define VECTOR stuff), would be nice to remove the duplication
template<> void ScriptInterface::ToJSVal<std::vector<CFixedVector2D> >(JSContext* cx, JS::MutableHandleValue ret, const std::vector<CFixedVector2D>& val)
{
JSAutoRequest rq(cx);
JS::RootedObject obj(cx, JS_NewArrayObject(cx, 0));
if (!obj)
{
ret.setUndefined();
return;
}
for (size_t i = 0; i < val.size(); ++i)
{
JS::RootedValue el(cx);
ScriptInterface::ToJSVal<CFixedVector2D>(cx, &el, val[i]);
JS_SetElement(cx, obj, i, el);
}
ret.setObject(*obj);
}
示例8: empty
/*! @brief Convert a YARP dictionary into a %JavaScript object.
@param[in] jct The %JavaScript engine context.
@param[in,out] theData The output object.
@param[in] inputAsList The input dictionary as a list. */
static void
convertDictionary(JSContext * jct,
JS::MutableHandleValue theData,
const yarp::os::Bottle & inputAsList)
{
ODL_ENTER(); //####
ODL_P3("jct = ", jct, "theData = ", &theData, "inputAsList = ", &inputAsList); //####
JS::RootedObject empty(jct);
JSObject * valueObject = JS_NewObject(jct, NULL);
if (valueObject)
{
JS::RootedObject objectRooted(jct);
JS::RootedValue anElement(jct);
objectRooted = valueObject;
for (int ii = 0, mm = inputAsList.size(); mm > ii; ++ii)
{
yarp::os::Value anEntry(inputAsList.get(ii));
if (anEntry.isList())
{
yarp::os::Bottle * entryAsList = anEntry.asList();
if (entryAsList && (2 == entryAsList->size()))
{
yarp::os::Value aValue(entryAsList->get(1));
convertValue(jct, &anElement, aValue);
JS_SetProperty(jct, objectRooted, entryAsList->get(0).toString().c_str(),
anElement);
}
}
}
theData.setObject(*valueObject);
}
ODL_EXIT(); //####
} // convertDictionary
示例9: value
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");
}
}