void std_map_string_string_to_jsval(JSContext* cx, const std::map<std::string, std::string>& v, JS::MutableHandleValue retVal) {
        JS::RootedObject proto(cx);
        JS::RootedObject parent(cx);
#if defined(MOZJS_MAJOR_VERSION) and MOZJS_MAJOR_VERSION >= 52
        JS::RootedObject jsRet(cx, JS_NewObject(cx, NULL));
#elif defined(MOZJS_MAJOR_VERSION) and MOZJS_MAJOR_VERSION >= 26
        JS::RootedObject jsRet(cx, JS_NewObject(cx, NULL, proto, parent));
#else
        JSObject *jsRet = JS_NewObject(cx, NULL, NULL, NULL);
#endif

        for (auto iter = v.begin(); iter != v.end(); ++iter) {
#if defined(MOZJS_MAJOR_VERSION) and MOZJS_MAJOR_VERSION >= 26
            JS::RootedValue element(cx);
#else
            jsval element;
#endif

            std::string key = iter->first;
            std::string val = iter->second;

            JSString* jsstr = JS_NewStringCopyZ(cx, val.c_str());
            element = JS::StringValue(jsstr);

            if (!key.empty()) {
#if defined(MOZJS_MAJOR_VERSION) and MOZJS_MAJOR_VERSION >= 26
                JS_SetProperty(cx, jsRet, key.c_str(), element);
#else
                JS_SetProperty(cx, jsRet, key.c_str(), &element);
#endif
            }
        }

        retVal.set(JS::ObjectOrNullValue(jsRet.get()));
    }
jsval shareInfo_to_jsval(JSContext* cx, const sdkbox::PluginShare::ShareResponse& response) {
    JS::RootedObject proto(cx);
    JS::RootedObject parent(cx);
#if defined(MOZJS_MAJOR_VERSION) and MOZJS_MAJOR_VERSION >= 26
    JS::RootedObject jsRet(cx, JS_NewObject(cx, NULL, proto, parent));
#else
    JSObject *jsRet = JS_NewObject(cx, NULL, NULL, NULL);
#endif

#if defined(MOZJS_MAJOR_VERSION) and MOZJS_MAJOR_VERSION >= 26
    JS::RootedValue state(cx);
#else
    jsval state;
#endif
    state = int32_to_jsval(cx, response.state);
#if defined(MOZJS_MAJOR_VERSION) and MOZJS_MAJOR_VERSION >= 26
    JS_SetProperty(cx, jsRet, "state", state);
#else
    JS_SetProperty(cx, jsRet, "state", &state);
#endif

#if defined(MOZJS_MAJOR_VERSION) and MOZJS_MAJOR_VERSION >= 26
    JS::RootedValue errStr(cx);
#else
    jsval errStr;
#endif
    errStr = std_string_to_jsval(cx, response.error);
#if defined(MOZJS_MAJOR_VERSION) and MOZJS_MAJOR_VERSION >= 26
    JS_SetProperty(cx, jsRet, "error", errStr);
#else
    JS_SetProperty(cx, jsRet, "error", &errStr);
#endif

    return OBJECT_TO_JSVAL(jsRet);
}
    virtual void onEvent(Ref *controlButton, Control::EventType event)
    {
        js_proxy_t* p = jsb_get_native_proxy(controlButton);
        if (!p)
        {
            log("Failed to get proxy for control button %p", controlButton);
            return;
        }

        JSContext* cx = ScriptingCore::getInstance()->getGlobalContext();

        jsval dataVal[2];
        dataVal[0] = OBJECT_TO_JSVAL(p->obj);
        int arg1 = (int)event;
        dataVal[1] = INT_TO_JSVAL(arg1);
        JS::RootedValue jsRet(cx);

        _callback->invoke(2, dataVal, &jsRet);
    }
    virtual void onEvent(Ref *controlButton, Control::EventType event)
    {
        js_proxy_t * p;
        JS_GET_PROXY(p, controlButton);
        if (!p)
        {
            log("Failed to get proxy for control button");
            return;
        }
        
        jsval dataVal[2];
        dataVal[0] = OBJECT_TO_JSVAL(p->obj);
        int arg1 = (int)event;
        dataVal[1] = INT_TO_JSVAL(arg1);

        JSContext* cx = ScriptingCore::getInstance()->getGlobalContext();
        JS::RootedValue jsRet(cx);

        ScriptingCore::getInstance()->executeJSFunctionWithThisObj(JS::RootedValue(cx, OBJECT_TO_JSVAL(_jsTarget)), JS::RootedValue(cx, OBJECT_TO_JSVAL(_jsFunc)), JS::HandleValueArray::fromMarkedLocation(2, dataVal), &jsRet);
    }
示例#5
0
bool ScriptInterface::CallFunctionVoid(JS::HandleValue val, const char* name)
{
	JSAutoRequest rq(m->m_cx);
	JS::RootedValue jsRet(m->m_cx);
	return CallFunction_(val, name, JS::HandleValueArray::empty(), &jsRet);
}