当前位置: 首页>>代码示例>>C++>>正文


C++ JSStringRelease函数代码示例

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


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

示例1: js_cb_launcher_submit

static JSValueRef
js_cb_launcher_submit(JSContextRef context,
                      JSObjectRef function,
                      JSObjectRef self,
                      size_t argc,
                      const JSValueRef argv[],
                      JSValueRef* exception)
{
    if (argc != 2)
        return JSValueMakeNull(context);

    int len = JSValueToNumber(context, argv[0], NULL);
    JSObjectRef arr = JSValueToObject(context, argv[1], NULL);

    static const int CMD_LINE_SIZE = 4096;
    static const int CMD_ARGS_SIZE = 256;

    char  cmd_str_buf[CMD_LINE_SIZE];
    int   cmd_str_buf_cur = 0;
    char *cmd_idx_buf[CMD_ARGS_SIZE];

    if (len == 0 || len >= CMD_ARGS_SIZE) return JSValueMakeNull(context);

    int i;
    for (i = 0; i < len; ++ i)
    {
        JSValueRef cur = JSObjectGetPropertyAtIndex(context, arr, i, NULL);
        JSStringRef str = JSValueToStringCopy(context, cur, NULL);
        size_t l = JSStringGetUTF8CString(str, cmd_str_buf + cmd_str_buf_cur, CMD_LINE_SIZE - cmd_str_buf_cur);
        cmd_idx_buf[i] = cmd_str_buf + cmd_str_buf_cur;
        cmd_str_buf_cur += l;
        JSStringRelease(str);
        JSValueUnprotect(context, cur);
    }
    cmd_idx_buf[i] = 0;

    if (fork() == 0)
    {
        /* Redirect I/O streams */
        freopen("/dev/null", "r", stdin);
        freopen("/dev/null", "w", stdout);
        execvp(cmd_idx_buf[0], cmd_idx_buf);
        fprintf(stderr, "RETURNED");
        exit(1);
    }
    
    return JSValueMakeNull(context);
}
开发者ID:HenryHu,项目名称:weblet,代码行数:48,代码来源:main.c

示例2: mk_zs__

void mk_zs__(WebKitWebView* wwv){
	WebKitWebFrame* web_frame;
	JSGlobalContextRef js_context;
	JSObjectRef js_global;
	JSStringRef js_function_name;
	JSObjectRef js_function;
	web_frame = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (wwv));
	js_context = webkit_web_frame_get_global_context (web_frame);
	js_global = JSContextGetGlobalObject (js_context);
	js_function_name = JSStringCreateWithUTF8CString (s1_[zs_].c_str());
	js_function = JSObjectMakeFunctionWithCallback (js_context,
			js_function_name, zs__);
	JSObjectSetProperty (js_context, js_global, js_function_name, js_function,
			kJSPropertyAttributeNone, NULL);
	JSStringRelease (js_function_name);
}
开发者ID:BGCX261,项目名称:zhscript-svn-to-git,代码行数:16,代码来源:control___.cpp

示例3: JSValueCreateJSONString

std::string NX::Value::toJSON(unsigned int indent)
{
  JSValueRef exception = nullptr;
  JSStringRef strRef = JSValueCreateJSONString(myContext, myVal, indent, &exception);
  if (exception)
  {
    NX::Object except (myContext, exception);
    throw std::runtime_error (except["message"]->toString());
  }
  std::size_t len = JSStringGetMaximumUTF8CStringSize (strRef);
  std::string str (len, ' ');
  len = JSStringGetUTF8CString (strRef, &str[0], len);
  JSStringRelease (strRef);
  str.resize (len);
  return str;
}
开发者ID:cigraphics,项目名称:nexusjs,代码行数:16,代码来源:value.cpp

示例4: print_callAsFunction

static JSValueRef print_callAsFunction(JSContextRef context, JSObjectRef functionObject, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
    UNUSED_PARAM(functionObject);
    UNUSED_PARAM(thisObject);
    
    if (argumentCount > 0) {
        JSStringRef string = JSValueToStringCopy(context, arguments[0], NULL);
        size_t sizeUTF8 = JSStringGetMaximumUTF8CStringSize(string);
        char stringUTF8[sizeUTF8];
        JSStringGetUTF8CString(string, stringUTF8, sizeUTF8);
        printf("%s\n", stringUTF8);
        JSStringRelease(string);
    }
    
    return JSValueMakeUndefined(context);
}
开发者ID:FilipBE,项目名称:qtextended,代码行数:16,代码来源:testapi.c

示例5: MyObject_hasInstance

static bool MyObject_hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleValue, JSValueRef* exception)
{
    UNUSED_PARAM(context);
    UNUSED_PARAM(constructor);

    if (JSValueIsString(context, possibleValue) && JSStringIsEqualToUTF8CString(JSValueToStringCopy(context, possibleValue, 0), "throwOnHasInstance")) {
        JSEvaluateScript(context, JSStringCreateWithUTF8CString("throw 'an exception'"), constructor, JSStringCreateWithUTF8CString("test script"), 1, exception);
        return false;
    }

    JSStringRef numberString = JSStringCreateWithUTF8CString("Number");
    JSObjectRef numberConstructor = JSValueToObject(context, JSObjectGetProperty(context, JSContextGetGlobalObject(context), numberString, exception), exception);
    JSStringRelease(numberString);

    return JSValueIsInstanceOfConstructor(context, possibleValue, numberConstructor, exception);
}
开发者ID:jackiekaon,项目名称:owb-mirror,代码行数:16,代码来源:testapi.c

示例6: plat_create_window

void* plat_create_window(void* tag, int w, int h) {
  struct gtk_state* state = malloc(sizeof(struct gtk_state));
  state->tag = tag;

  GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title(GTK_WINDOW(window), "WebUI");

  state->window = window;

  gtk_signal_connect(GTK_OBJECT(window), "destroy",
                     GTK_SIGNAL_FUNC(close_window), state);

  GtkWidget* scroll = gtk_scrolled_window_new(NULL, NULL);
  state->web_view = webkit_web_view_new();

  gtk_container_add(GTK_CONTAINER(scroll), state->web_view);
  gtk_container_add(GTK_CONTAINER(window), scroll);

  WebKitWebFrame* web_frame = webkit_web_view_get_main_frame(
                              WEBKIT_WEB_VIEW(state->web_view));

  gtk_window_set_default_size(GTK_WINDOW(window), w, h);
  gtk_widget_show_all(window);

  JSGlobalContextRef jsctx = webkit_web_frame_get_global_context(web_frame);

  state->jsctx = jsctx;

  JSClassDefinition system_def = kJSClassDefinitionEmpty;
  system_def.className = "ruby";
  system_def.getProperty = ruby_getprop;

  JSClassRef system_class = JSClassCreate(&system_def);

  JSObjectRef o = JSObjectMake(jsctx, system_class, NULL);
  if(!JSObjectSetPrivate(o, tag)) {
    printf("WebKit is busted.\n");
    abort();
  }

  JSStringRef	name = JSStringCreateWithUTF8CString("ruby");
  JSObjectSetProperty(jsctx, JSContextGetGlobalObject(jsctx), name, o,
                      kJSPropertyAttributeDontDelete, NULL);
  JSStringRelease(name);

  return state;
}
开发者ID:deadprogram,项目名称:webui,代码行数:47,代码来源:webui_gtk.c

示例7: JSString

 JSValue::operator JSString() const {
   HAL_JSVALUE_LOCK_GUARD;
   JSValueRef exception { nullptr };
   JSStringRef js_string_ref = JSValueToStringCopy(static_cast<JSContextRef>(js_context__), js_value_ref__, &exception);
   if (exception) {
     // If this assert fails then we need to JSStringRelease
     // js_string_ref.
     assert(!js_string_ref);
     detail::ThrowRuntimeError("JSValue", JSValue(js_context__, exception));
   }
   
   assert(js_string_ref);
   JSString js_string(js_string_ref);
   JSStringRelease(js_string_ref);
   
   return js_string;
 }
开发者ID:CodexLabs,项目名称:HAL,代码行数:17,代码来源:JSValue.cpp

示例8: function_file_writer_write

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

        char *descriptor = value_to_c_string(ctx, args[0]);
        JSStringRef str_ref = JSValueToStringCopy(ctx, args[1], NULL);

        ufile_write(descriptor_str_to_int(descriptor), str_ref);

        free(descriptor);
        JSStringRelease(str_ref);
    }

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

示例9: code

    void JavaScriptModuleInstance::Run()
    {
        std::string code(FileUtils::ReadFile(this->path));

        // Check the script's syntax.
        JSValueRef exception;
        JSStringRef jsCode = JSStringCreateWithUTF8CString(code.c_str());
        bool syntax = JSCheckScriptSyntax(context, jsCode, NULL, 0, &exception);
        if (!syntax)
        {
            KValueRef e = KJSUtil::ToKrollValue(exception, context, NULL);
            JSStringRelease(jsCode);
            throw ValueException(e);
        }

        KJSUtil::Evaluate(context, code.c_str());
    }
开发者ID:fossamikom,项目名称:TideSDK,代码行数:17,代码来源:javascript_module_instance.cpp

示例10: ext_util_js_ref_to_string

/**
 * Returns a new allocates string for given value reference.
 * String must be freed if not used anymore.
 */
char* ext_util_js_ref_to_string(JSContextRef ctx, JSValueRef ref)
{
    char *string;
    size_t len;
    JSStringRef str_ref;

    g_return_val_if_fail(ref != NULL, NULL);

    str_ref = JSValueToStringCopy(ctx, ref, NULL);
    len     = JSStringGetMaximumUTF8CStringSize(str_ref);

    string = g_new0(char, len);
    JSStringGetUTF8CString(str_ref, string, len);
    JSStringRelease(str_ref);

    return string;
}
开发者ID:cdlscpmv,项目名称:vimb,代码行数:21,代码来源:ext-util.c

示例11: JSValueToStringCopy

static char *js2utf8(JSContextRef ctx, JSValueRef val, size_t* out_len) {
	JSStringRef str = JSValueToStringCopy(ctx, val, NULL);
	size_t max = 0, len;
	char *buf;

	max = JSStringGetMaximumUTF8CStringSize(str);
	buf = malloc(max);
	len = JSStringGetUTF8CString(str, buf, max);

	if (out_len) {
		*out_len = len;
	}

	JSStringRelease(str);

	return buf;
}
开发者ID:rottame,项目名称:gtk-webkit-ruby,代码行数:17,代码来源:webkit.c

示例12: ENABLE

HRESULT STDMETHODCALLTYPE DRTDesktopNotificationPresenter::checkNotificationPermission(
        /* [in] */ BSTR origin, 
        /* [out, retval] */ int* result)
{
#if ENABLE(NOTIFICATIONS)
    JSStringRef jsOrigin = JSStringCreateWithBSTR(origin);
    bool allowed = ::gLayoutTestController->checkDesktopNotificationPermission(jsOrigin);

    if (allowed)
        *result = WebCore::NotificationPresenter::PermissionAllowed;
    else
        *result = WebCore::NotificationPresenter::PermissionDenied;

    JSStringRelease(jsOrigin);
#endif
    return S_OK;
}
开发者ID:0x4d52,项目名称:JavaScriptCore-X,代码行数:17,代码来源:DRTDesktopNotificationPresenter.cpp

示例13: JSStringCreateWithUTF8CString

size_t VJSArray::GetLength() const
{
	size_t length;
	JSStringRef jsString = JSStringCreateWithUTF8CString( "length");
	JSValueRef result = JSObjectGetProperty( fContext, fObject, jsString, NULL);
	JSStringRelease( jsString);
	if (testAssert( result != NULL))
	{
		double r = JSValueToNumber( fContext, result, NULL);
		length = (size_t) r;
	}
	else
	{
		length = 0;
	}
	return length;
}
开发者ID:sanyaade-iot,项目名称:core-XToolbox,代码行数:17,代码来源:VJSValue.cpp

示例14: ext_util_js_eval

/**
 * Evaluates given string as script and return if this call succeed or not.
 */
gboolean ext_util_js_eval(JSContextRef ctx, const char *script, JSValueRef *result)
{
    JSStringRef js_str;
    JSValueRef exc = NULL, res = NULL;

    js_str = JSStringCreateWithUTF8CString(script);
    res = JSEvaluateScript(ctx, js_str, JSContextGetGlobalObject(ctx), NULL, 0, &exc);
    JSStringRelease(js_str);

    if (exc) {
        *result = exc;
        return FALSE;
    }

    *result = res;
    return TRUE;
}
开发者ID:cdlscpmv,项目名称:vimb,代码行数:20,代码来源:ext-util.c

示例15: js_fill_exception

void js_fill_exception(JSContextRef ctx,
                       JSValueRef* excp,
                       const char* format,
                       ...)
{
    va_list args;
    va_start (args, format);
    char* str = g_strdup_vprintf(format, args);
    va_end(args);

    JSStringRef string = JSStringCreateWithUTF8CString(str);
    JSValueRef exc_str = JSValueMakeString(ctx, string);
    JSStringRelease(string);
    g_free(str);

    *excp= JSValueToObject(ctx, exc_str, NULL);
}
开发者ID:choldrim,项目名称:deepin-installer,代码行数:17,代码来源:jsextension.c


注:本文中的JSStringRelease函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。