本文整理汇总了C++中JSStringGetUTF8CString函数的典型用法代码示例。如果您正苦于以下问题:C++ JSStringGetUTF8CString函数的具体用法?C++ JSStringGetUTF8CString怎么用?C++ JSStringGetUTF8CString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了JSStringGetUTF8CString函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: JSValueToStringCopy
bool S_CCLabelTTF::initWithContext(JSContextRef ctx, JSObjectRef obj, size_t argumentCount, const JSValueRef arguments[])
{
bool result = true;
if (argumentCount == 3) {
char *buffText = (char *)malloc(128);
char *buffFont = (char *)malloc(128);
JSStringRef jsLabelText = JSValueToStringCopy(ctx, arguments[0], NULL);
JSStringRef jsFontName = JSValueToStringCopy(ctx, arguments[1], NULL);
float fontSize = JSValueToNumber(ctx, arguments[2], NULL);
JSStringGetUTF8CString(jsLabelText, buffText, 128);
JSStringGetUTF8CString(jsFontName, buffFont, 128);
if (!CCLabelTTF::initWithString(buffText, buffFont, fontSize)) {
return false;
}
free(buffText);
free(buffFont);
} else {
if (!CCLabelTTF::init()) {
result = false;
}
}
if (result) {
setUserData(obj);
}
return result;
}
示例2: jsstring_to_cstr
char* jsstring_to_cstr(JSContextRef ctx, JSStringRef js_string)
{
size_t len = JSStringGetMaximumUTF8CStringSize(js_string);
char *c_str = g_new(char, len);
JSStringGetUTF8CString(js_string, c_str, len);
return c_str;
}
示例3: spjsdata_has_property_cb
// has property methods for callbacks. method parameter definitions( e.message, e.otp, e.data)
bool spjsdata_has_property_cb(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName)
{
bool ret = false;
int propertySize = JSStringGetMaximumUTF8CStringSize(propertyName);
char* property = (char *)malloc(propertySize * sizeof(char));
JSStringGetUTF8CString(propertyName, property, propertySize);
if(strcmp(kParamOTP,property) == 0)
{
ret = true;
}
if(strcmp(kParamCode,property) == 0)
{
ret = true;
}
if(strcmp(kParamMessage,property) == 0)
{
ret = true;
}
if(strcmp(kParamData,property) == 0)
{
ret = true;
}
free(property);
return ret;
}
示例4: setMarkedTextCallback
static JSValueRef setMarkedTextCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
if (!view)
return JSValueMakeUndefined(context);
if (argumentCount < 3)
return JSValueMakeUndefined(context);
JSStringRef string = JSValueToStringCopy(context, arguments[0], exception);
g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context));
size_t bufferSize = JSStringGetMaximumUTF8CStringSize(string);
GOwnPtr<gchar> stringBuffer(static_cast<gchar*>(g_malloc(bufferSize)));
JSStringGetUTF8CString(string, stringBuffer.get(), bufferSize);
JSStringRelease(string);
int start = static_cast<int>(JSValueToNumber(context, arguments[1], exception));
g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context));
int end = static_cast<int>(JSValueToNumber(context, arguments[2], exception));
g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context));
DumpRenderTreeSupportGtk::setComposition(view, stringBuffer.get(), start, end);
return JSValueMakeUndefined(context);
}
示例5: web_view_javascript_finished
static void web_view_javascript_finished(GObject *object,
GAsyncResult *result,
gpointer user_data)
{
WebKitJavascriptResult *js_result;
JSValueRef value;
JSGlobalContextRef context;
GError *error = NULL;
js_result = webkit_web_view_run_javascript_finish(WEBKIT_WEB_VIEW(object), result, &error);
if (!js_result) {
g_warning ("Error running javascript: %s", error->message);
g_error_free (error);
return;
}
context = webkit_javascript_result_get_global_context(js_result);
value = webkit_javascript_result_get_value(js_result);
if (JSValueIsString(context, value)) {
JSStringRef js_str_value;
gchar *str_value;
gsize str_length;
js_str_value = JSValueToStringCopy(context, value, NULL);
str_length = JSStringGetMaximumUTF8CStringSize(js_str_value);
str_value = (gchar *)g_malloc(str_length);
JSStringGetUTF8CString(js_str_value, str_value, str_length);
JSStringRelease(js_str_value);
g_free (str_value);
} else {
g_warning("Error running javascript: unexpected return value");
}
webkit_javascript_result_unref(js_result);
}
示例6: function_read_file
JSValueRef function_read_file(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject,
size_t argc, const JSValueRef args[], JSValueRef *exception) {
// TODO: implement fully
if (argc == 1 && JSValueGetType(ctx, args[0]) == kJSTypeString) {
char path[100];
JSStringRef path_str = JSValueToStringCopy(ctx, args[0], NULL);
assert(JSStringGetLength(path_str) < 100);
JSStringGetUTF8CString(path_str, path, 100);
JSStringRelease(path_str);
// debug_print_value("read_file", ctx, args[0]);
time_t last_modified = 0;
char *contents = get_contents(path, &last_modified);
if (contents != NULL) {
JSStringRef contents_str = JSStringCreateWithUTF8CString(contents);
free(contents);
JSValueRef res[2];
res[0] = JSValueMakeString(ctx, contents_str);
res[1] = JSValueMakeNumber(ctx, last_modified);
return JSObjectMakeArray(ctx, 2, res, NULL);
}
}
return JSValueMakeNull(ctx);
}
示例7: if
JSValueRef JSCCharacterData::appendDataCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) {
struct JSCCharacterDataPrivate* privData = (struct JSCCharacterDataPrivate*)JSObjectGetPrivate(thisObj);
if (false) {
} else if (argumentCount == 1 &&
JSValueIsString(ctx, arguments[0])) {
JSStringRef stringReflocalArg = JSValueToStringCopy(ctx, arguments[0], exception);
size_t localArgMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalArg);
char* localArgBuffer = new char[localArgMaxSize];
JSStringGetUTF8CString(stringReflocalArg, localArgBuffer, localArgMaxSize);
std::string localArg(localArgBuffer);
JSStringRelease(stringReflocalArg);
free(localArgBuffer);
privData->nativeObj->appendData(localArg);
JSValueRef jscRetVal = JSValueMakeUndefined(ctx);
return jscRetVal;
}
JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling appendData");
*exception = JSValueMakeString(ctx, exceptionString);
JSStringRelease(exceptionString);
return JSValueMakeUndefined(ctx);
}
示例8: arg_to_string
/*
* Converts an argument to a string.
*
* Convert a JSValueRef argument to a g_malloc'd gchar string. Calling function
* is responsible for g_freeing the string.
*/
static gchar *
arg_to_string(JSContextRef context, JSValueRef arg, JSValueRef *exception) {
JSStringRef string;
size_t size;
gchar *result;
if (JSValueGetType(context, arg) != kJSTypeString) {
_mkexception(context, exception, EXPECTSTRING);
return NULL;
}
string = JSValueToStringCopy(context, arg, exception);
if (!string) {
return NULL;
}
size = JSStringGetMaximumUTF8CStringSize(string);
result = g_malloc(size);
if (!result) {
return NULL;
}
JSStringGetUTF8CString(string, result, size);
JSStringRelease(string);
return result;
}
示例9: setProperty
static bool setProperty(JSContextRef jscore_ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef *exception)
{
pdf_jsimp *imp;
char buf[STRING_BUF_SIZE];
prop *p;
priv_data *pdata = JSObjectGetPrivate(object);
if (pdata == NULL)
return false;
JSStringGetUTF8CString(propertyName, buf, STRING_BUF_SIZE);
p = find_prop(pdata->type->props, buf);
if (p == NULL)
return false;
imp = pdata->type->imp;
switch(p->type)
{
case PROP_FN:
break;
case PROP_VAL:
{
pdf_jsimp_obj *pval = wrap_val(imp, value);
p->u.val.set(imp->nat_ctx, pdata->natobj, pval);
pdf_jsimp_drop_obj(imp, pval);
}
break;
}
return true;
}
示例10: HyperloopJSStringToStringCopy
/**
* return a char* from a JSStringRef as string which must be delete when finished
*/
EXPORTAPI char * HyperloopJSStringToStringCopy(JSContextRef ctx, JSStringRef str, JSValueRef *exception)
{
auto size = JSStringGetMaximumUTF8CStringSize(str);
auto buf = new char[size];
JSStringGetUTF8CString(str,buf,size);
return buf;
}
示例11: element_text_equal_to
static gboolean element_text_equal_to(JSContextRef context, const gchar* text)
{
JSStringRef scriptString = JSStringCreateWithUTF8CString(
"window.document.getElementById(\"in\").value;");
JSValueRef value = JSEvaluateScript(context, scriptString, 0, 0, 0, 0);
JSStringRelease(scriptString);
// If the value isn't a string, the element is probably a div
// so grab the innerText instead.
if (!JSValueIsString(context, value)) {
JSStringRef scriptString = JSStringCreateWithUTF8CString(
"window.document.getElementById(\"in\").innerText;");
value = JSEvaluateScript(context, scriptString, 0, 0, 0, 0);
JSStringRelease(scriptString);
}
g_assert(JSValueIsString(context, value));
JSStringRef inputString = JSValueToStringCopy(context, value, 0);
g_assert(inputString);
gint size = JSStringGetMaximumUTF8CStringSize(inputString);
gchar* cString = g_malloc(size);
JSStringGetUTF8CString(inputString, cString, size);
JSStringRelease(inputString);
gboolean result = g_utf8_collate(cString, text) == 0;
g_free(cString);
return result;
}
示例12: js_extract_string
static gchar* js_extract_string(JSStringRef string)
{
gsize size = JSStringGetMaximumUTF8CStringSize(string);
gchar* gstr = (gchar*) g_malloc(size);
JSStringGetUTF8CString(string, gstr, size);
return gstr;
}
示例13: JSValueToStringCopy
char *pdf_jsimp_to_string(pdf_jsimp *imp, pdf_jsimp_obj *obj)
{
fz_context *ctx = imp->ctx;
JSStringRef jstr = JSValueToStringCopy(imp->jscore_ctx, obj->ref, NULL);
int len;
if (jstr == NULL)
return "";
fz_try(ctx)
{
len = JSStringGetMaximumUTF8CStringSize(jstr);
fz_free(ctx, obj->str);
obj->str = NULL;
obj->str = fz_malloc(ctx, len+1);
JSStringGetUTF8CString(jstr, obj->str, len+1);
}
fz_always(ctx)
{
JSStringRelease(jstr);
}
fz_catch(ctx)
{
fz_rethrow(ctx);
}
return obj->str;
}
示例14: function_import_script
JSValueRef function_import_script(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject,
size_t argc, const JSValueRef args[], JSValueRef* exception) {
if (argc == 1 && JSValueGetType(ctx, args[0]) == kJSTypeString) {
JSStringRef path_str_ref = JSValueToStringCopy(ctx, args[0], NULL);
assert(JSStringGetLength(path_str_ref) < 100);
char tmp[100];
tmp[0] = '\0';
JSStringGetUTF8CString(path_str_ref, tmp, 100);
JSStringRelease(path_str_ref);
char *path = tmp;
if (str_has_prefix(path, "goog/../") == 0) {
path = path + 8;
}
char *source = NULL;
if (out_path == NULL) {
source = bundle_get_contents(path);
} else {
char *full_path = str_concat(out_path, path);
source = get_contents(full_path, NULL);
free(full_path);
}
if (source != NULL) {
evaluate_script(ctx, source, path);
free(source);
}
}
return JSValueMakeUndefined(ctx);
}
示例15: JSStringGetMaximumUTF8CStringSize
std::wstring hyperloop::getWString(JSStringRef sValue) {
size_t sLength = JSStringGetMaximumUTF8CStringSize(sValue);
char* cValue = new char[sLength];
JSStringGetUTF8CString(sValue, cValue, sLength);
std::string s_str = cValue;
std::wstring w_str(s_str.begin(), s_str.end());
return w_str;
}