本文整理汇总了C++中js::MutableHandleValue::setString方法的典型用法代码示例。如果您正苦于以下问题:C++ MutableHandleValue::setString方法的具体用法?C++ MutableHandleValue::setString怎么用?C++ MutableHandleValue::setString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类js::MutableHandleValue
的用法示例。
在下文中一共展示了MutableHandleValue::setString方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: JSGetter___dirname
bool JSGlobal::JSGetter___dirname(JSContext *cx, JS::MutableHandleValue vp)
{
Path path(JSUtils::CurrentJSCaller(cx), false, true);
vp.setString(JS_NewStringCopyZ(cx, path.dir()));
return true;
}
示例3: JSGetter___filename
bool JSGlobal::JSGetter___filename(JSContext *cx, JS::MutableHandleValue vp)
{
char *filename = JSUtils::CurrentJSCaller(cx);
vp.setString(JS_NewStringCopyZ(cx, filename));
free(filename);
return true;
}
示例4: 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();
}
示例5: def_timestep_image_map_get_url
CEXPORT bool def_timestep_image_map_get_url(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) {
JS_BeginRequest(cx);
timestep_image_map *thiz = (timestep_image_map*)JS_GetPrivate(obj.get());
if (thiz) {
vp.setString(JS_NewStringCopyZ(cx, thiz->url));
}
JS_EndRequest(cx);
return true;
}
示例6: 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");
}
示例7: str
bool
gjs_string_from_utf8(JSContext *context,
const char *utf8_string,
JS::MutableHandleValue value_p)
{
JS_BeginRequest(context);
JS::ConstUTF8CharsZ chars(utf8_string, strlen(utf8_string));
JS::RootedString str(context, JS_NewStringCopyUTF8Z(context, chars));
if (str)
value_p.setString(str);
JS_EndRequest(context);
return str != nullptr;
}
示例8: str
bool
gjs_string_from_utf8(JSContext *context,
const char *utf8_string,
ssize_t n_bytes,
JS::MutableHandleValue value_p)
{
char16_t *u16_string;
glong u16_string_length;
GError *error;
/* intentionally using n_bytes even though glib api suggests n_chars; with
* n_chars (from g_utf8_strlen()) the result appears truncated
*/
error = NULL;
u16_string =
reinterpret_cast<char16_t *>(g_utf8_to_utf16(utf8_string, n_bytes, NULL,
&u16_string_length, &error));
if (!u16_string) {
gjs_throw(context,
"Failed to convert UTF-8 string to "
"JS string: %s",
error->message);
g_error_free(error);
return false;
}
JS_BeginRequest(context);
/* Avoid a copy - assumes that g_malloc == js_malloc == malloc */
JS::RootedString str(context,
JS_NewUCString(context, u16_string, u16_string_length));
if (str)
value_p.setString(str);
JS_EndRequest(context);
return str != NULL;
}
示例9: if
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