• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ JSStringCreateWithUTF8CString函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中JSStringCreateWithUTF8CString函数的典型用法代码示例。如果您正苦于以下问题:C++ JSStringCreateWithUTF8CString函数的具体用法?C++ JSStringCreateWithUTF8CString怎么用?C++ JSStringCreateWithUTF8CString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了JSStringCreateWithUTF8CString函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: keyDownCallback

static JSValueRef keyDownCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
    if (argumentCount < 1)
        return JSValueMakeUndefined(context);

    static JSStringRef ctrlKey = JSStringCreateWithUTF8CString("ctrlKey");
    static JSStringRef shiftKey = JSStringCreateWithUTF8CString("shiftKey");
    static JSStringRef altKey = JSStringCreateWithUTF8CString("altKey");
    static JSStringRef metaKey = JSStringCreateWithUTF8CString("metaKey");
    static JSStringRef lengthProperty = JSStringCreateWithUTF8CString("length");

    COMPtr<IWebFramePrivate> framePrivate;
    if (SUCCEEDED(frame->QueryInterface(&framePrivate)))
        framePrivate->layout();
    
    JSStringRef character = JSValueToStringCopy(context, arguments[0], exception);
    ASSERT(!exception || !*exception);
    int charCode = JSStringGetCharactersPtr(character)[0];
    int virtualKeyCode = toupper(LOBYTE(VkKeyScan(charCode)));
    JSStringRelease(character);

    // Hack to map option-delete to ctrl-delete
    // Remove this when we fix <rdar://problem/5102974> layout tests need a way to decide how to choose the appropriate modifier keys
    bool convertOptionToCtrl = false;
    if (virtualKeyCode == VK_DELETE || virtualKeyCode == VK_BACK)
        convertOptionToCtrl = true;
    
    BYTE keyState[256];
    if (argumentCount > 1) {
        ::GetKeyboardState(keyState);

        BYTE newKeyState[256];
        memcpy(newKeyState, keyState, sizeof(keyState));

        JSObjectRef modifiersArray = JSValueToObject(context, arguments[1], exception);
        if (modifiersArray) {
            int modifiersCount = JSValueToNumber(context, JSObjectGetProperty(context, modifiersArray, lengthProperty, 0), 0);
            for (int i = 0; i < modifiersCount; ++i) {
                JSValueRef value = JSObjectGetPropertyAtIndex(context, modifiersArray, i, 0);
                JSStringRef string = JSValueToStringCopy(context, value, 0);
                if (JSStringIsEqual(string, ctrlKey))
                    newKeyState[VK_CONTROL] = 0x80;
                else if (JSStringIsEqual(string, shiftKey))
                    newKeyState[VK_SHIFT] = 0x80;
                else if (JSStringIsEqual(string, altKey)) {
                    if (convertOptionToCtrl)
                        newKeyState[VK_CONTROL] = 0x80;
                    else
                        newKeyState[VK_MENU] = 0x80;
                } else if (JSStringIsEqual(string, metaKey))
                    newKeyState[VK_MENU] = 0x80;

                JSStringRelease(string);
            }
        }

        ::SetKeyboardState(newKeyState);
    }

    MSG msg = makeMsg(webViewWindow, WM_KEYDOWN, virtualKeyCode, 0);
    dispatchMessage(&msg);
    
    if (argumentCount > 1)
        ::SetKeyboardState(keyState);

    return JSValueMakeUndefined(context);
}
开发者ID:gvsurenderreddy,项目名称:symbiandump-mw4,代码行数:67,代码来源:EventSender.cpp


示例2: main

int main(int argc, char* argv[])
{
    const char *scriptPath = "testapi.js";
    if (argc > 1) {
        scriptPath = argv[1];
    }
    
    // Test garbage collection with a fresh context
    context = JSGlobalContextCreateInGroup(NULL, NULL);
    TestInitializeFinalize = true;
    testInitializeFinalize();
    JSGlobalContextRelease(context);
    TestInitializeFinalize = false;

    ASSERT(Base_didFinalize);

    JSClassDefinition globalObjectClassDefinition = kJSClassDefinitionEmpty;
    globalObjectClassDefinition.initialize = globalObject_initialize;
    globalObjectClassDefinition.staticValues = globalObject_staticValues;
    globalObjectClassDefinition.staticFunctions = globalObject_staticFunctions;
    globalObjectClassDefinition.attributes = kJSClassAttributeNoAutomaticPrototype;
    JSClassRef globalObjectClass = JSClassCreate(&globalObjectClassDefinition);
    context = JSGlobalContextCreateInGroup(NULL, globalObjectClass);

    JSGlobalContextRetain(context);
    JSGlobalContextRelease(context);

    JSObjectRef globalObject = JSContextGetGlobalObject(context);
    ASSERT(JSValueIsObject(context, globalObject));
    
    JSValueRef jsUndefined = JSValueMakeUndefined(context);
    JSValueRef jsNull = JSValueMakeNull(context);
    JSValueRef jsTrue = JSValueMakeBoolean(context, true);
    JSValueRef jsFalse = JSValueMakeBoolean(context, false);
    JSValueRef jsZero = JSValueMakeNumber(context, 0);
    JSValueRef jsOne = JSValueMakeNumber(context, 1);
    JSValueRef jsOneThird = JSValueMakeNumber(context, 1.0 / 3.0);
    JSObjectRef jsObjectNoProto = JSObjectMake(context, NULL, NULL);
    JSObjectSetPrototype(context, jsObjectNoProto, JSValueMakeNull(context));

    // FIXME: test funny utf8 characters
    JSStringRef jsEmptyIString = JSStringCreateWithUTF8CString("");
    JSValueRef jsEmptyString = JSValueMakeString(context, jsEmptyIString);
    
    JSStringRef jsOneIString = JSStringCreateWithUTF8CString("1");
    JSValueRef jsOneString = JSValueMakeString(context, jsOneIString);

    UniChar singleUniChar = 65; // Capital A
    CFMutableStringRef cfString = 
        CFStringCreateMutableWithExternalCharactersNoCopy(kCFAllocatorDefault,
                                                          &singleUniChar,
                                                          1,
                                                          1,
                                                          kCFAllocatorNull);

    JSStringRef jsCFIString = JSStringCreateWithCFString(cfString);
    JSValueRef jsCFString = JSValueMakeString(context, jsCFIString);
    
    CFStringRef cfEmptyString = CFStringCreateWithCString(kCFAllocatorDefault, "", kCFStringEncodingUTF8);
    
    JSStringRef jsCFEmptyIString = JSStringCreateWithCFString(cfEmptyString);
    JSValueRef jsCFEmptyString = JSValueMakeString(context, jsCFEmptyIString);

    CFIndex cfStringLength = CFStringGetLength(cfString);
    UniChar* buffer = (UniChar*)malloc(cfStringLength * sizeof(UniChar));
    CFStringGetCharacters(cfString, 
                          CFRangeMake(0, cfStringLength), 
                          buffer);
    JSStringRef jsCFIStringWithCharacters = JSStringCreateWithCharacters((JSChar*)buffer, cfStringLength);
    JSValueRef jsCFStringWithCharacters = JSValueMakeString(context, jsCFIStringWithCharacters);
    
    JSStringRef jsCFEmptyIStringWithCharacters = JSStringCreateWithCharacters((JSChar*)buffer, CFStringGetLength(cfEmptyString));
    free(buffer);
    JSValueRef jsCFEmptyStringWithCharacters = JSValueMakeString(context, jsCFEmptyIStringWithCharacters);

    ASSERT(JSValueGetType(context, jsUndefined) == kJSTypeUndefined);
    ASSERT(JSValueGetType(context, jsNull) == kJSTypeNull);
    ASSERT(JSValueGetType(context, jsTrue) == kJSTypeBoolean);
    ASSERT(JSValueGetType(context, jsFalse) == kJSTypeBoolean);
    ASSERT(JSValueGetType(context, jsZero) == kJSTypeNumber);
    ASSERT(JSValueGetType(context, jsOne) == kJSTypeNumber);
    ASSERT(JSValueGetType(context, jsOneThird) == kJSTypeNumber);
    ASSERT(JSValueGetType(context, jsEmptyString) == kJSTypeString);
    ASSERT(JSValueGetType(context, jsOneString) == kJSTypeString);
    ASSERT(JSValueGetType(context, jsCFString) == kJSTypeString);
    ASSERT(JSValueGetType(context, jsCFStringWithCharacters) == kJSTypeString);
    ASSERT(JSValueGetType(context, jsCFEmptyString) == kJSTypeString);
    ASSERT(JSValueGetType(context, jsCFEmptyStringWithCharacters) == kJSTypeString);

    JSObjectRef myObject = JSObjectMake(context, MyObject_class(context), NULL);
    JSStringRef myObjectIString = JSStringCreateWithUTF8CString("MyObject");
    JSObjectSetProperty(context, globalObject, myObjectIString, myObject, kJSPropertyAttributeNone, NULL);
    JSStringRelease(myObjectIString);
    
    JSValueRef exception;

    // Conversions that throw exceptions
    exception = NULL;
    ASSERT(NULL == JSValueToObject(context, jsNull, &exception));
    ASSERT(exception);
//.........这里部分代码省略.........
开发者ID:acss,项目名称:owb-mirror,代码行数:101,代码来源:testapi.c


示例3: pdf_jsimp_execute

void pdf_jsimp_execute(pdf_jsimp *imp, char *code)
{
	JSStringRef jcode = JSStringCreateWithUTF8CString(code);
	JSEvaluateScript(imp->jscore_ctx, jcode, NULL, NULL, 0, NULL);
	JSStringRelease(jcode);
}
开发者ID:azaleafisitania,项目名称:sumatrapdf,代码行数:6,代码来源:pdf-jsimp-jscore.c


示例4: applicationControllerStr

void ApplicationTestController::makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception)
{
    JSRetainPtr<JSStringRef> applicationControllerStr(Adopt, JSStringCreateWithUTF8CString("applicationTestController"));
    JSValueRef applicationControllerObject = JSObjectMake(context, getJSClass(), this);
    JSObjectSetProperty(context, windowObject, applicationControllerStr.get(), applicationControllerObject, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, exception);
}
开发者ID:jackiekaon,项目名称:owb-mirror,代码行数:6,代码来源:ApplicationTestController.cpp


示例5: init_widget_js_obj

static void
init_widget_js_obj (void *context, struct widget *widget) {
	char classname[64];
	snprintf(classname, 64, "widget_%s", widget->type);
	const JSClassDefinition widget_js_def = {
		.className = classname,
		.staticFunctions = widget->js_staticfuncs,
	};

	JSClassRef class_def = JSClassCreate(&widget_js_def);
	JSObjectRef class_obj = JSObjectMake(context, class_def, widget);
	JSObjectRef global_obj = JSContextGetGlobalObject(context);
	JSStringRef str_name = JSStringCreateWithUTF8CString(classname);
	JSObjectSetProperty(context, global_obj, str_name, class_obj, kJSPropertyAttributeNone, NULL);
	JSStringRelease(str_name);

	widget->js_context = context;
	widget->js_object = class_obj;
}

static struct widget*
spawn_widget (struct bar *bar, void *context, json_t *config, const char *name) {
	widget_main_t widget_main;
	widget_type_t widget_type;
	char libname[64];
	snprintf(libname, 64, "libwidget_%s", name);
	gchar *libpath = g_module_build_path(LIBDIR, libname);
	GModule *lib = g_module_open(libpath, G_MODULE_BIND_LOCAL);
	pthread_t return_thread;
	struct widget *widget = calloc(1, sizeof(struct widget));

	if (lib == NULL) {
		LOG_WARN("loading of '%s' (%s) failed", libpath, name);

		goto error;
	}

	if (!g_module_symbol(lib, "widget_main", (void*)&widget_main)) {
		LOG_WARN("loading of '%s' (%s) failed: unable to load module symbol", libpath, name);

		goto error;
	}

	JSStaticFunction *js_staticfuncs = calloc(1, sizeof(JSStaticFunction));
	if (g_module_symbol(lib, "widget_js_staticfuncs", (void*)&js_staticfuncs)) {
		widget->js_staticfuncs = js_staticfuncs;
	}
	else {
		free(js_staticfuncs);
	}

	widget->bar = bar;
	widget->config = config;
	widget->name = strdup(name);

	pthread_mutex_init(&widget->exit_mutex, NULL);
	pthread_cond_init(&widget->exit_cond, NULL);

	if (g_module_symbol(lib, "widget_type", (void*)&widget_type)) {
		widget->type = widget_type();
	}
	else {
		widget->type = widget->name;
	}

	init_widget_js_obj(context, widget);

	if (pthread_create(&return_thread, NULL, (void*(*)(void*))widget_main, widget) != 0) {
		LOG_ERR("failed to start widget %s: %s", name, strerror(errno));

		goto error;
	}

	widget->thread = return_thread;

	return widget;

error:
	if (widget->name != NULL) {
		free(widget->name);
	}
	if (widget->js_staticfuncs != NULL) {
		free(widget->js_staticfuncs);
	}
	free(widget);

	return 0;
}
开发者ID:jhanssen,项目名称:candybar,代码行数:88,代码来源:widgets.c


示例6: putForJSBuffer

/**
 * put
 */
JSValueRef putForJSBuffer (JSContextRef ctx, JSObjectRef function, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
    BUFFER(buffer);
    ARGCOUNT(4);
    JSValueRef bufValueRef = arguments[0];
    if (!JSValueIsObject(ctx,bufValueRef))
    {
        JSStringRef string = JSStringCreateWithUTF8CString("first argument must be a buffer object");
        JSValueRef message = JSValueMakeString(ctx, string);
        JSStringRelease(string);
        *exception = JSObjectMakeError(ctx, 1, &message, 0);
        return JSValueMakeUndefined(ctx);
    }
    JSObjectRef bufObjectRef = JSValueToObject(ctx,bufValueRef,exception);
    CHECK_EXCEPTION_UNDEFINED
    JSBuffer *srcBuffer = (JSBuffer*)HyperloopGetPrivateObjectAsJSBuffer(bufObjectRef);
    if (srcBuffer==nullptr)
    {
        JSStringRef string = JSStringCreateWithUTF8CString("first argument must be a buffer object (JSBuffer nullptr)");
        JSValueRef message = JSValueMakeString(ctx, string);
        JSStringRelease(string);
        *exception = JSObjectMakeError(ctx, 1, &message, 0);
        return JSValueMakeUndefined(ctx);
    }

    GET_NUMBER(1,srcIndex);
    GET_NUMBER(2,srcLength);
    GET_NUMBER(3,destIndex);

    if (srcLength > srcBuffer->length)
    {
        JSStringRef string = JSStringCreateWithUTF8CString("source length passed in greater than source buffer length");
        JSValueRef message = JSValueMakeString(ctx, string);
        JSStringRelease(string);
        *exception = JSObjectMakeError(ctx, 1, &message, 0);
        return JSValueMakeUndefined(ctx);
    }

    if (srcLength <= 0)
    {
        JSStringRef string = JSStringCreateWithUTF8CString("source length must be greater than 0");
        JSValueRef message = JSValueMakeString(ctx, string);
        JSStringRelease(string);
        *exception = JSObjectMakeError(ctx, 1, &message, 0);
        return JSValueMakeUndefined(ctx);
    }

	throw ref new Exception(0, "JSBuffer's putForJSBuffer has not been implemented on Windows yet.");
    /*void *src = &(srcBuffer->buffer[(int)srcIndex]);
    size_t newsize = (buffer->length - (int)destIndex);
    newsize = newsize + srcLength - newsize;
    void *dest = &(buffer->buffer[(int)destIndex]);

    if (newsize  > buffer->length)
    {
        // new to grow it
        void *copy = malloc(buffer->length);
        size_t copylen = buffer->length;
        memcpy(copy, buffer->buffer, copylen);
        free(buffer->buffer);
        buffer->buffer = malloc(newsize);
        buffer->length = newsize;
        memcpy(buffer->buffer,copy,copylen);
    }
    memcpy(dest, src, (int)srcLength);

    return object;*/
}
开发者ID:pec1985,项目名称:hyperloop,代码行数:71,代码来源:JSBuffer.cpp


示例7: main

gint
main (gint argc, gchar ** argv)
{
  JSGlobalContextRef ctx;

  JSStringRef str;
  JSObjectRef func;
  JSValueRef result;
  JSValueRef exception = NULL;

  JsonObject *obj;
  JsonNode *node;

  g_type_init();

  gchar *buffer;

  if (argc != 2)
    {
      printf ("Usage: %s <script>\n", argv[0]);
      return 1;
    }

  ctx = JSGlobalContextCreate (NULL);

  str = JSStringCreateWithUTF8CString ("emitIntermediate");
  func = JSObjectMakeFunctionWithCallback (ctx, str, js_emitIntermediate);
  JSObjectSetProperty (ctx, JSContextGetGlobalObject (ctx), str, func,
		       kJSPropertyAttributeNone, NULL);
  JSStringRelease (str);

  str = JSStringCreateWithUTF8CString ("emit");
  func = JSObjectMakeFunctionWithCallback (ctx, str, js_emit);
  JSObjectSetProperty (ctx, JSContextGetGlobalObject (ctx), str, func,
		       kJSPropertyAttributeNone, NULL);
  JSStringRelease (str);

  str = JSStringCreateWithUTF8CString (argv[1]);
  result = JSEvaluateScript (ctx, str, NULL, NULL, 0, &exception);
  JSStringRelease (str);

  obj = json_object_new ();

  if (!result || exception)
    {
      js_value (ctx, exception, &node);

      json_object_set_member (obj, "error", node);

      json_object_set_boolean_member (obj, "status", FALSE);

      JSGlobalContextRelease (ctx);
    }
  else
    {
      json_object_set_boolean_member (obj, "status", TRUE);
    }

  JsonNode *node1 = json_node_new (JSON_NODE_OBJECT);

  if (node1 == NULL)
    {
      json_object_unref (obj);
      JSGlobalContextRelease (ctx);
      return 1;
    }

  json_node_set_object (node1, obj);

  JsonGenerator *gen = json_generator_new();

  if (gen == NULL)
    {
      json_node_free (node1);
      JSGlobalContextRelease (ctx);
      return 1;
    }

  json_generator_set_root (gen, node1 );
  buffer = json_generator_to_data (gen,NULL);

  if (buffer == NULL)
    {
      json_node_free (node1);
      JSGlobalContextRelease (ctx);
      return 1;
    }

  json_node_free (node1);

  puts (buffer);
  g_free (buffer);

  JSGlobalContextRelease (ctx);
  return 0;
}
开发者ID:dplatform,项目名称:dupin,代码行数:96,代码来源:dp_js.c


示例8: c_string_to_value

JSValueRef c_string_to_value(JSContextRef ctx, const char *s) {
    JSStringRef str = JSStringCreateWithUTF8CString(s);
    return JSValueMakeString(ctx, str);
}
开发者ID:mfikes,项目名称:planck,代码行数:4,代码来源:jsc_utils.c


示例9: array_get_count

int array_get_count(JSContextRef ctx, JSObjectRef arr) {
    JSStringRef pname = JSStringCreateWithUTF8CString("length");
    JSValueRef val = JSObjectGetProperty(ctx, arr, pname, NULL);
    JSStringRelease(pname);
    return (int) JSValueToNumber(ctx, val, NULL);
}
开发者ID:mfikes,项目名称:planck,代码行数:6,代码来源:jsc_utils.c


示例10: tester_js_test

static const JSClassDefinition tester_def = {
	0,
	kJSClassAttributeNone,
	"TesterClass",
	NULL,
	NULL,
	tester_static_funcs,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL
};

static JSValueRef tester_js_test(JSContextRef ctx, JSObjectRef func, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef *ex) {
	JSStringRef str = JSStringCreateWithUTF8CString("Test!");
	return JSValueMakeString(ctx, str);
}

/*
 * Adds Tester class to a context
 */
void add_tester_js_class() {
	cwebkit_add_js_class_to_list(tester_def, JSStringCreateWithUTF8CString("tester"));
}
开发者ID:kramerc,项目名称:cwebkit,代码行数:31,代码来源:js.c


示例11: function_load

JSValueRef function_load(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[PATH_MAX];
        JSStringRef path_str = JSValueToStringCopy(ctx, args[0], NULL);
        assert(JSStringGetLength(path_str) < PATH_MAX);
        JSStringGetUTF8CString(path_str, path, PATH_MAX);
        JSStringRelease(path_str);

        // debug_print_value("load", ctx, args[0]);

        time_t last_modified = 0;
        char *contents = NULL;
        char *loaded_path = strdup(path);

        bool developing = (config.num_src_paths == 1 &&
                           strcmp(config.src_paths[0].type, "src") == 0 &&
                           str_has_suffix(config.src_paths[0].path, "/planck-cljs/src/") == 0);

        if (!developing) {
            contents = bundle_get_contents(path);
            last_modified = 0;
        }

        // load from classpath
        if (contents == NULL) {
            for (int i = 0; i < config.num_src_paths; i++) {
                if (config.src_paths[i].blacklisted) {
                    continue;
                }

                char *type = config.src_paths[i].type;
                char *location = config.src_paths[i].path;

                if (strcmp(type, "src") == 0) {
                    char *full_path = str_concat(location, path);
                    contents = get_contents(full_path, &last_modified);
                    if (contents != NULL) {
                        free(loaded_path);
                        loaded_path = strdup(full_path);
                    }
                    free(full_path);
                } else if (strcmp(type, "jar") == 0) {
                    struct stat file_stat;
                    if (stat(location, &file_stat) == 0) {
                        contents = get_contents_zip(location, path, &last_modified);
                    } else {
                        cljs_perror(location);
                        config.src_paths[i].blacklisted = true;
                    }
                }

                if (contents != NULL) {
                    break;
                }
            }
        }

        // load from out/
        if (contents == NULL) {
            if (config.out_path != NULL) {
                char *full_path = str_concat(config.out_path, path);
                contents = get_contents(full_path, &last_modified);
                free(full_path);
            }
        }

        if (developing && contents == NULL) {
            contents = bundle_get_contents(path);
            last_modified = 0;
        }

        if (contents != NULL) {
            JSStringRef contents_str = JSStringCreateWithUTF8CString(contents);
            free(contents);
            JSStringRef loaded_path_str = JSStringCreateWithUTF8CString(loaded_path);
            free(loaded_path);

            JSValueRef res[3];
            res[0] = JSValueMakeString(ctx, contents_str);
            res[1] = JSValueMakeNumber(ctx, last_modified);
            res[2] = JSValueMakeString(ctx, loaded_path_str);
            return JSObjectMakeArray(ctx, 3, res, NULL);
        }
    }

    return JSValueMakeNull(ctx);
}
开发者ID:mfikes,项目名称:planck,代码行数:90,代码来源:functions.c


示例12: if

JSValueRef JSCInt16Array::setCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) {

	struct JSCInt16ArrayPrivate* privData = (struct JSCInt16ArrayPrivate*)JSObjectGetPrivate(thisObj);

	if (false) {
	} else if (argumentCount == 2 &&
	           JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCInt16Array::getTmpl()) &&
	           JSValueIsNumber(ctx, arguments[1])) {
		uscxml::Int16Array* localArray = ((struct JSCInt16Array::JSCInt16ArrayPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj;
		unsigned long localOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception);

		privData->nativeObj->set(localArray, localOffset);

		JSValueRef jscRetVal = JSValueMakeUndefined(ctx);
		return jscRetVal;
	} else if (argumentCount == 2 &&
	           JSValueIsNumber(ctx, arguments[0]) &&
	           JSValueIsNumber(ctx, arguments[1])) {
		unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception);
		short localValue = (short)JSValueToNumber(ctx, arguments[1], exception);

		privData->nativeObj->set(localIndex, localValue);

		JSValueRef jscRetVal = JSValueMakeUndefined(ctx);
		return jscRetVal;
	} else if (argumentCount == 2 &&
	           JSValueIsObject(ctx, arguments[0]) &&
	           JSValueIsNumber(ctx, arguments[1])) {

		std::vector<short> localArray;

		JSValueRef localArrayItem;
		unsigned int localArrayIndex = 0;
		while((localArrayItem = JSObjectGetPropertyAtIndex(ctx, JSValueToObject(ctx, arguments[0], exception), localArrayIndex, exception))) {
			if (JSValueIsUndefined(ctx, localArrayItem))
				break;
			if (JSValueIsNumber(ctx,localArrayItem))
				localArray.push_back(JSValueToNumber(ctx, localArrayItem, exception));
			localArrayIndex++;
		}
		unsigned long localOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception);

		privData->nativeObj->set(localArray, localOffset);

		JSValueRef jscRetVal = JSValueMakeUndefined(ctx);
		return jscRetVal;
	} else if (argumentCount == 1 &&
	           JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCInt16Array::getTmpl())) {
		uscxml::Int16Array* localArray = ((struct JSCInt16Array::JSCInt16ArrayPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj;

		privData->nativeObj->set(localArray);

		JSValueRef jscRetVal = JSValueMakeUndefined(ctx);
		return jscRetVal;
	} else if (argumentCount == 1 &&
	           JSValueIsObject(ctx, arguments[0])) {

		std::vector<short> localArray;

		JSValueRef localArrayItem;
		unsigned int localArrayIndex = 0;
		while((localArrayItem = JSObjectGetPropertyAtIndex(ctx, JSValueToObject(ctx, arguments[0], exception), localArrayIndex, exception))) {
			if (JSValueIsUndefined(ctx, localArrayItem))
				break;
			if (JSValueIsNumber(ctx,localArrayItem))
				localArray.push_back(JSValueToNumber(ctx, localArrayItem, exception));
			localArrayIndex++;
		}

		privData->nativeObj->set(localArray);

		JSValueRef jscRetVal = JSValueMakeUndefined(ctx);
		return jscRetVal;
	}

	JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling set");
	*exception = JSValueMakeString(ctx, exceptionString);
	JSStringRelease(exceptionString);
	return JSValueMakeUndefined(ctx);
}
开发者ID:bjqiwei,项目名称:uscxml,代码行数:80,代码来源:JSCInt16Array.cpp


示例13: function_http_request

JSValueRef function_http_request(JSContextRef ctx, JSObjectRef function, JSObjectRef this_object,
		size_t argc, const JSValueRef args[], JSValueRef* exception) {
	if (argc == 1 && JSValueGetType(ctx, args[0]) == kJSTypeObject) {
		JSObjectRef opts = JSValueToObject(ctx, args[0], NULL);
		JSValueRef url_ref = JSObjectGetProperty(ctx, opts, JSStringCreateWithUTF8CString("url"), NULL);
		char *url = value_to_c_string(ctx, url_ref);
		JSValueRef timeout_ref = JSObjectGetProperty(ctx, opts, JSStringCreateWithUTF8CString("timeout"), NULL);
		time_t timeout = 0;
		if (JSValueIsNumber(ctx, timeout_ref)) {
			timeout = (time_t) JSValueToNumber(ctx, timeout_ref, NULL);
		}
		JSValueRef method_ref = JSObjectGetProperty(ctx, opts, JSStringCreateWithUTF8CString("method"), NULL);
		char *method = value_to_c_string(ctx, method_ref);
		JSValueRef body_ref = JSObjectGetProperty(ctx, opts, JSStringCreateWithUTF8CString("body"), NULL);

		JSObjectRef headers_obj = JSValueToObject(ctx, JSObjectGetProperty(ctx, opts, JSStringCreateWithUTF8CString("headers"), NULL), NULL);

		CURL *handle = curl_easy_init();
		assert(handle != NULL);

		curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, method);
		curl_easy_setopt(handle, CURLOPT_URL, url);

		struct curl_slist *headers = NULL;
		if (!JSValueIsNull(ctx, headers_obj)) {
			JSPropertyNameArrayRef properties = JSObjectCopyPropertyNames(ctx, headers_obj);
			int n = JSPropertyNameArrayGetCount(properties);
			for (int i = 0; i < n; i++) {
				JSStringRef key_str = JSPropertyNameArrayGetNameAtIndex(properties, i);
				JSValueRef val_ref = JSObjectGetProperty(ctx, headers_obj, key_str, NULL);

				int len = JSStringGetLength(key_str) + 1;
				char *key = malloc(len * sizeof(char));
				JSStringGetUTF8CString(key_str, key, len);
				JSStringRef val_as_str = to_string(ctx, val_ref);
				char *val = value_to_c_string(ctx, JSValueMakeString(ctx, val_as_str));
				JSStringRelease(val_as_str);

				int len_key = strlen(key);
				int len_val = strlen(val);
				char *header = malloc((len_key + len_val + 2 + 1) * sizeof(char));
				sprintf(header, "%s: %s", key, val);
				curl_slist_append(headers, header);
				free(header);

				free(key);
				free(val);
			}

			curl_easy_setopt(handle, CURLOPT_HEADER, headers);
		}

		// curl_easy_setopt(handle, CURLOPT_HEADER, 1L);
		curl_easy_setopt(handle, CURLOPT_TIMEOUT, timeout);

		struct read_string_state input_state;
		if (!JSValueIsUndefined(ctx, body_ref)) {
			char *body = value_to_c_string(ctx, body_ref);
			input_state.input = body;
			input_state.offset = 0;
			input_state.length = strlen(body);
			curl_easy_setopt(handle, CURLOPT_READDATA, &input_state);
			curl_easy_setopt(handle, CURLOPT_READFUNCTION, read_string_callback);
		}

		JSObjectRef response_headers = JSObjectMake(ctx, NULL, NULL);
		struct header_state header_state;
		header_state.ctx = ctx;
		header_state.headers = response_headers;
		curl_easy_setopt(handle, CURLOPT_HEADERDATA, &header_state);
		curl_easy_setopt(handle, CURLOPT_HEADERFUNCTION, header_to_object_callback);

		struct write_state body_state;
		body_state.offset = 0;
		body_state.length = 0;
		body_state.data = NULL;
		curl_easy_setopt(handle, CURLOPT_WRITEDATA, &body_state);
		curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, write_string_callback);

		JSObjectRef result = JSObjectMake(ctx, NULL, NULL);

		int res = curl_easy_perform(handle);
		if (res != 0) {
			JSStringRef error_str = JSStringCreateWithUTF8CString(curl_easy_strerror(res));
			JSObjectSetProperty(ctx, result, JSStringCreateWithUTF8CString("error"), JSValueMakeString(ctx, error_str), kJSPropertyAttributeReadOnly, NULL);
		}

		int status = 0;
		curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &status);

		// printf("%d bytes, %x\n", body_state.offset, body_state.data);
		if (body_state.data != NULL) {
			JSStringRef body_str = JSStringCreateWithUTF8CString(body_state.data);
			JSObjectSetProperty(ctx, result, JSStringCreateWithUTF8CString("body"), JSValueMakeString(ctx, body_str), kJSPropertyAttributeReadOnly, NULL);
			free(body_state.data);
		}

		JSObjectSetProperty(ctx, result, JSStringCreateWithUTF8CString("status"), JSValueMakeNumber(ctx, status), kJSPropertyAttributeReadOnly, NULL);
		JSObjectSetProperty(ctx, result, JSStringCreateWithUTF8CString("headers"), response_headers, kJSPropertyAttributeReadOnly, NULL);

//.........这里部分代码省略.........
开发者ID:heyLu,项目名称:planck,代码行数:101,代码来源:http.c


示例14: setExceptionForString

static void setExceptionForString(JSContextRef context, JSValueRef* exception, const char* string)
{
    JSRetainPtr<JSStringRef> exceptionString(Adopt, JSStringCreateWithUTF8CString(string));
    *exception = JSValueMakeString(context, exceptionString.get());
}
开发者ID:achellies,项目名称:WinCEWebKit,代码行数:5,代码来源:EventSendingController.cpp


示例15: window_object_cleared_callback

static void
window_object_cleared_callback(WebKitScriptWorld *world,
							   WebKitWebPage *web_page,
							   WebKitFrame *frame,
							   LightDMGreeter *greeter) {

	JSObjectRef gettext_object, lightdm_greeter_object, config_file_object, greeter_util_object;
	JSGlobalContextRef jsContext;
	JSObjectRef globalObject;
	WebKitDOMDocument *dom_document;
	WebKitDOMDOMWindow *dom_window;
	gchar *message = "LockHint";

	page_id = webkit_web_page_get_id(web_page);

	jsContext = webkit_frame_get_javascript_context_for_script_world(frame, world);
	globalObject = JSContextGetGlobalObject(jsContext);

	gettext_class = JSClassCreate(&gettext_definition);
	lightdm_greeter_class = JSClassCreate(&lightdm_greeter_definition);
	lightdm_user_class = JSClassCreate(&lightdm_user_definition);
	lightdm_language_class = JSClassCreate(&lightdm_language_definition);
	lightdm_layout_class = JSClassCreate(&lightdm_layout_definition);
	lightdm_session_class = JSClassCreate(&lightdm_session_definition);
	config_file_class = JSClassCreate(&config_file_definition);
	greeter_util_class = JSClassCreate(&greeter_util_definition);

	gettext_object = JSObjectMake(jsContext, gettext_class, NULL);

	JSObjectSetProperty(jsContext,
						globalObject,
						JSStringCreateWithUTF8CString("gettext"),
						gettext_object,
						kJSPropertyAttributeNone,
						NULL);

	lightdm_greeter_object = JSObjectMake(jsContext, lightdm_greeter_class, greeter);

	JSObjectSetProperty(jsContext,
						globalObject,
						JSStringCreateWithUTF8CString("lightdm"),
						lightdm_greeter_object,
						kJSPropertyAttributeNone,
						NULL);

	config_file_object = JSObjectMake(jsContext, config_file_class, greeter);

	JSObjectSetProperty(jsContext,
						globalObject,
						JSStringCreateWithUTF8CString("config"),
						config_file_object,
						kJSPropertyAttributeNone,
						NULL);

	greeter_util_object = JSObjectMake(jsContext, greeter_util_class, NULL);

	JSObjectSetProperty(jsContext,
						globalObject,
						JSStringCreateWithUTF8CString("greeterutil"),
						greeter_util_object,
						kJSPropertyAttributeNone,
						NULL);



	/* If the greeter was started as a lock-screen, send message to our UI process. */
	if (lightdm_greeter_get_lock_hint(greeter)) {
		dom_document = webkit_web_page_get_dom_document(web_page);
		dom_window = webkit_dom_document_get_default_view(dom_document);

		if (dom_window) {
			webkit_dom_dom_window_webkit_message_handlers_post_message(dom_window,
																	   "GreeterBridge", message);
		}
	}

}
开发者ID:sbalneav,项目名称:lightdm-webkit2-greeter,代码行数:77,代码来源:lightdm-webkit2-greeter-ext.c


示例16: eval_js

/* Javascript*/
void
eval_js(WebKitWebView * web_view, const gchar *script, GString *result, const char *file) {
    WebKitWebFrame *frame;
    JSGlobalContextRef context;
    JSObjectRef globalobject;
    JSStringRef js_file;
    JSStringRef js_script;
    JSValueRef js_result;
    JSValueRef js_exc = NULL;
    JSStringRef js_result_string;
    size_t js_result_size;

    frame = webkit_web_view_get_main_frame(WEBKIT_WEB_VIEW(web_view));
    context = webkit_web_frame_get_global_context(frame);
    globalobject = JSContextGetGlobalObject(context);

    /* evaluate the script and get return value*/
    js_script = JSStringCreateWithUTF8CString(script);
    js_file = JSStringCreateWithUTF8CString(file);
    js_result = JSEvaluateScript(context, js_script, globalobject, js_file, 0, &js_exc);
    if (result && js_result && !JSValueIsUndefined(context, js_result)) {
        js_result_string = JSValueToStringCopy(context, js_result, NULL);
        js_result_size = JSStringGetMaximumUTF8CStringSize(js_result_string);

        if (js_result_size) {
            char js_result_utf8[js_result_size];
            JSStringGetUTF8CString(js_result_string, js_result_utf8, js_result_size);
            g_string_assign(result, js_result_utf8);
        }

        JSStringRelease(js_result_string);
    }
    else if (js_exc) {
        size_t size;
        JSStringRef prop, val;
        JSObjectRef exc = JSValueToObject(context, js_exc, NULL);

        printf("Exception occured while executing script:\n");

        /* Print file */
        prop = JSStringCreateWithUTF8CString("sourceURL");
        val = JSValueToStringCopy(context, JSObjectGetProperty(context, exc, prop, NULL), NULL);
        size = JSStringGetMaximumUTF8CStringSize(val);
        if(size) {
            char cstr[size];
            JSStringGetUTF8CString(val, cstr, size);
            printf("At %s", cstr);
        }
        JSStringRelease(prop);
        JSStringRelease(val);

        /* Print line */
        prop = JSStringCreateWithUTF8CString("line");
        val = JSValueToStringCopy(context, JSObjectGetProperty(context, exc, prop, NULL), NULL);
        size = JSStringGetMaximumUTF8CStringSize(val);
        if(size) {
            char cstr[size];
            JSStringGetUTF8CString(val, cstr, size);
            printf(":%s: ", cstr);
        }
        JSStringRelease(prop);
        JSStringRelease(val);

        /* Print message */
        val = JSValueToStringCopy(context, exc, NULL);
        size = JSStringGetMaximumUTF8CStringSize(val);
        if(size) {
            char cstr[size];
            JSStringGetUTF8CString(val, cstr, size);
            printf("%s\n", cstr);
        }
        JSStringRelease(val);
    }

    /* cleanup */
    JSStringRelease(js_script);
    JSStringRelease(js_file);
}
开发者ID:TaylanUB,项目名称:uzbl,代码行数:79,代码来源:uzbl-core.c


示例17: JSStringCreateWithUTF8CString

JSStringRef MDNativeBindingFunction::propertyName()
{
    return JSStringCreateWithUTF8CString(m_jsNativeFunc.name);
}
开发者ID:bytewang,项目名称:vitas,代码行数:4,代码来源:MDNativeBindingManager.cpp


示例18: function_fstat

JSValueRef function_fstat(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject,
                          size_t argc, const JSValueRef args[], JSValueRef *exception) {
    if (argc == 1
        && JSValueGetType(ctx, args[0]) == kJSTypeString) {

        char *path = value_to_c_string(ctx, args[0]);

        struct stat file_stat;

        int retval = lstat(path, &file_stat);

        if (retval == 0) {
            JSObjectRef result = JSObjectMake(ctx, NULL, NULL);

            char *type = "unknown";
            if (S_ISDIR(file_stat.st_mode)) {
                type = "directory";
            } else if (S_ISREG(file_stat.st_mode)) {
                type = "file";
            } else if (S_ISLNK(file_stat.st_mode)) {
                type = "symbolic-link";
            } else if (S_ISSOCK(file_stat.st_mode)) {
                type = "socket";
            } else if (S_ISFIFO(file_stat.st_mode)) {
                type = "fifo";
            } else if (S_ISCHR(file_stat.st_mode)) {
                type = "character-special";
            } else if (S_ISBLK(file_stat.st_mode)) {
                type = "block-special";
            }

            JSObjectSetProperty(ctx, result, JSStringCreateWithUTF8CString("type"),
                                c_string_to_value(ctx, type),
                                kJSPropertyAttributeReadOnly, NULL);


            double device_id = (double) file_stat.st_rdev;
            if (device_id) {
                JSObjectSetProperty(ctx, result, JSStringCreateWithUTF8CString("device-id"),
                                    JSValueMakeNumber(ctx, device_id),
                                    kJSPropertyAttributeReadOnly, NULL);
            }

            double file_number = (double) file_stat.st_ino;
            if (file_number) {
                JSObjectSetProperty(ctx, result, JSStringCreateWithUTF8CString("file-number"),
                                    JSValueMakeNumber(ctx, file_number),
                                    kJSPropertyAttributeReadOnly, NULL);
            }

            JSObjectSetProperty(ctx, result, JSStringCreateWithUTF8CString("permissions"),
                                JSValueMakeNumber(ctx, (double) (ACCESSPERMS & file_stat.st_mode)),
                                kJSPropertyAttributeReadOnly, NULL);

            JSObjectSetProperty(ctx, result, JSStringCreateWithUTF8CString("reference-count"),
                                JSValueMakeNumber(ctx, (double) file_stat.st_nlink),
                                kJSPropertyAttributeReadOnly, NULL);

            JSObjectSetProperty(ctx, result, JSStringCreateWithUTF8CString("uid"),
                                JSValueMakeNumber(ctx, (double) file_stat.st_uid),
                                kJSPropertyAttributeReadOnly, NULL);

            struct passwd *uid_passwd = getpwuid(file_stat.st_uid);

            if (uid_passwd) {
                JSObjectSetProperty(ctx, result, JSStringCreateWithUTF8CString("uname"),
                                    c_string_to_value(ctx, uid_passwd->pw_name),
                                    kJSPropertyAttributeReadOnly, NULL);
            }

            JSObjectSetProperty(ctx, result, JSStringCreateWithUTF8CString("gid"),
                                JSValueMakeNumber(ctx, (double) file_stat.st_gid),
                                kJSPropertyAttributeReadOnly, NULL);

            struct group *gid_group = getgrgid(file_stat.st_gid);

            if (gid_group) {
                JSObjectSetProperty(ctx, result, JSStringCreateWithUTF8CString("gname"),
                                    c_string_to_value(ctx, gid_group->gr_name),
                                    kJSPropertyAttributeReadOnly, NULL);
            }

            JSObjectSetProperty(ctx, result, JSStringCreateWithUTF8CString("file-size"),
                                JSValueMakeNumber(ctx, (double) file_stat.st_size),
                                kJSPropertyAttributeReadOnly, NULL);

#ifdef __APPLE__
#define birthtime(x) x.st_birthtime
#else
#define birthtime(x) x.st_ctime
#endif

            JSObjectSetProperty(ctx, result, JSStringCreateWithUTF8CString("created"),
                                JSValueMakeNumber(ctx, 1000 * birthtime(file_stat)),
                                kJSPropertyAttributeReadOnly, NULL);

            JSObjectSetProperty(ctx, result, JSStringCreateWithUTF8CString("modifie 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ JSStringGetUTF8CString函数代码示例发布时间:2022-05-30
下一篇:
C++ JSStringCopyUTF8CString函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap