switch_status_t teletone_load(JSContext * cx, JSObject * obj)
{
	JS_InitClass(cx, obj, NULL, &teletone_class, teletone_construct, 3, teletone_props, teletone_methods, teletone_props, teletone_methods);
	return SWITCH_STATUS_SUCCESS;
}
CEXPORT void timestep_image_map_add_to_object(JSObject *parent) {
	JSContext *cx = get_js_context();
	JS_InitClass(cx, parent, NULL, (JSClass*)&timestep_image_map_class, def_timestep_image_map_class_constructor,
		12, (JSPropertySpec *)properties, (JSFunctionSpec *)functions, NULL, NULL);
}
Пример #3
0
switch_status_t curl_load(JSContext * cx, JSObject * obj)
{
	JS_InitClass(cx, obj, NULL, &curl_class, curl_construct, 3, curl_props, curl_methods, curl_props, curl_methods);
	return SWITCH_STATUS_SUCCESS;
}
Пример #4
0
    };

    static JSFunctionSpec funcs[] = {
        JS_FN("isDirectory", js_util_DirectoryUtils_isDirectory, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("isEmpty", js_util_DirectoryUtils_isEmpty, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("hasFile", js_util_DirectoryUtils_hasFile, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("walkDirs", js_util_DirectoryUtils_walkDirs, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("walkFiles", js_util_DirectoryUtils_walkFiles, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FS_END
    };

    jsb_util_DirectoryUtils_prototype = JS_InitClass(
                                            cx, global,
                                            JS::NullPtr(), // parent proto
                                            jsb_util_DirectoryUtils_class,
                                            empty_constructor, 0, // constructor
                                            nullptr,
                                            funcs,
                                            nullptr, // no static properties
                                            st_funcs);

    // add the proto and JSClass to the type->js info hash table
    JSB_ADD_CALSS_TO_HASH_TABLE(util, DirectoryUtils, Utils::DirectoryUtils)
}


void jsb_register_util( JSContext* cx, JS::HandleObject global )
{
    JS::RootedObject util(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
    JS::RootedValue utilVal(cx);
    utilVal = OBJECT_TO_JSVAL(util);
CEXPORT void animate_add_to_object(JSObject *parent) {
	JSContext *cx = get_js_context();
	JS_InitClass(cx, parent, NULL, (JSClass*)&animate_class, def_animate_class_constructor,
		2, (JSPropertySpec *)properties, (JSFunctionSpec *)functions, NULL, NULL);
}
Пример #6
0
int
main(int argc, const char* argv[])
{
    JSRuntime* rt = NULL;
    JSContext* cx = NULL;
    JSObject* global = NULL;
    JSObject* klass = NULL;
    JSScript* script;
    JSString* scriptsrc;
    jschar* schars;
    size_t slen;
    jsval sroot;
    jsval result;
    int i;

    couch_args* args = couch_parse_args(argc, argv);

    rt = JS_NewRuntime(args->stack_size);
    if(rt == NULL)
        return 1;

    cx = JS_NewContext(rt, 8L * 1024L);
    if(cx == NULL)
        return 1;

    JS_SetErrorReporter(cx, couch_error);
    JS_ToggleOptions(cx, JSOPTION_XML);
    JS_SetContextPrivate(cx, args);
    
    SETUP_REQUEST(cx);

    global = JS_NewObject(cx, &global_class, NULL, NULL);
    if(global == NULL)
        return 1;

    JS_SetGlobalObject(cx, global);
    
    if(!JS_InitStandardClasses(cx, global))
        return 1;

    if(couch_load_funcs(cx, global, global_functions) != JS_TRUE)
        return 1;
 
    if(args->use_http) {
        http_check_enabled();

        klass = JS_InitClass(
            cx, global,
            NULL,
            &CouchHTTPClass, req_ctor,
            0,
            CouchHTTPProperties, CouchHTTPFunctions,
            NULL, NULL
        );

        if(!klass)
        {
            fprintf(stderr, "Failed to initialize CouchHTTP class.\n");
            exit(2);
        }
    } 

    for (i = 0 ; args->scripts[i] ; i++) {
        // Convert script source to jschars.
        scriptsrc = couch_readfile(cx, args->scripts[i]);
        if(!scriptsrc)
            return 1;

        schars = JS_GetStringChars(scriptsrc);
        slen = JS_GetStringLength(scriptsrc);

        // Root it so GC doesn't collect it.
        sroot = STRING_TO_JSVAL(scriptsrc);
        if(JS_AddRoot(cx, &sroot) != JS_TRUE) {
            fprintf(stderr, "Internal root error.\n");
            return 1;
        }

        // Compile and run
        script = JS_CompileUCScript(cx, global, schars, slen,
                                    args->scripts[i], 1);
        if(!script) {
            fprintf(stderr, "Failed to compile script.\n");
            return 1;
        }

        JS_ExecuteScript(cx, global, script, &result);

        // Warning message if we don't remove it.
        JS_RemoveRoot(cx, &sroot);
    }

    FINISH_REQUEST(cx);
    JS_DestroyContext(cx);
    JS_DestroyRuntime(rt);
    JS_ShutDown();

    return 0;
}
Пример #7
0
JSObject * JsMenuItemFontBinding::BindingOnEngine(JSContext *context,
		JSObject *global, JSObject *parent) {
	obj = JS_InitClass(context, global, parent, &clz, Create, 0, NULL, NULL,
			NULL, NULL);
	return obj;
}
void js_register_cocos2dx_experimental_video_VideoPlayer(JSContext *cx, JS::HandleObject global) {
    jsb_cocos2d_experimental_ui_VideoPlayer_class = (JSClass *)calloc(1, sizeof(JSClass));
    jsb_cocos2d_experimental_ui_VideoPlayer_class->name = "VideoPlayer";
    jsb_cocos2d_experimental_ui_VideoPlayer_class->addProperty = JS_PropertyStub;
    jsb_cocos2d_experimental_ui_VideoPlayer_class->delProperty = JS_DeletePropertyStub;
    jsb_cocos2d_experimental_ui_VideoPlayer_class->getProperty = JS_PropertyStub;
    jsb_cocos2d_experimental_ui_VideoPlayer_class->setProperty = JS_StrictPropertyStub;
    jsb_cocos2d_experimental_ui_VideoPlayer_class->enumerate = JS_EnumerateStub;
    jsb_cocos2d_experimental_ui_VideoPlayer_class->resolve = JS_ResolveStub;
    jsb_cocos2d_experimental_ui_VideoPlayer_class->convert = JS_ConvertStub;
    jsb_cocos2d_experimental_ui_VideoPlayer_class->finalize = js_cocos2d_experimental_ui_VideoPlayer_finalize;
    jsb_cocos2d_experimental_ui_VideoPlayer_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2);

    static JSPropertySpec properties[] = {
        JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_PS_END
    };

    static JSFunctionSpec funcs[] = {
        JS_FN("getFileName", js_cocos2dx_experimental_video_VideoPlayer_getFileName, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getURL", js_cocos2dx_experimental_video_VideoPlayer_getURL, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("play", js_cocos2dx_experimental_video_VideoPlayer_play, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setKeepAspectRatioEnabled", js_cocos2dx_experimental_video_VideoPlayer_setKeepAspectRatioEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("stop", js_cocos2dx_experimental_video_VideoPlayer_stop, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setFullScreenEnabled", js_cocos2dx_experimental_video_VideoPlayer_setFullScreenEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setFileName", js_cocos2dx_experimental_video_VideoPlayer_setFileName, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setURL", js_cocos2dx_experimental_video_VideoPlayer_setURL, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("isKeepAspectRatioEnabled", js_cocos2dx_experimental_video_VideoPlayer_isKeepAspectRatioEnabled, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("onPlayEvent", js_cocos2dx_experimental_video_VideoPlayer_onPlayEvent, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("isFullScreenEnabled", js_cocos2dx_experimental_video_VideoPlayer_isFullScreenEnabled, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("isPlaying", js_cocos2dx_experimental_video_VideoPlayer_isPlaying, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("seekTo", js_cocos2dx_experimental_video_VideoPlayer_seekTo, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FS_END
    };

    static JSFunctionSpec st_funcs[] = {
        JS_FN("create", js_cocos2dx_experimental_video_VideoPlayer_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FS_END
    };

    jsb_cocos2d_experimental_ui_VideoPlayer_prototype = JS_InitClass(
        cx, global,
        JS::RootedObject(cx, jsb_cocos2d_ui_Widget_prototype),
        jsb_cocos2d_experimental_ui_VideoPlayer_class,
        js_cocos2dx_experimental_video_VideoPlayer_constructor, 0, // constructor
        properties,
        funcs,
        NULL, // no static properties
        st_funcs);
    // make the class enumerable in the registered namespace
//  bool found;
//FIXME: Removed in Firefox v27 
//  JS_SetPropertyAttributes(cx, global, "VideoPlayer", JSPROP_ENUMERATE | JSPROP_READONLY, &found);

    // add the proto and JSClass to the type->js info hash table
    TypeTest<cocos2d::experimental::ui::VideoPlayer> t;
    js_type_class_t *p;
    std::string typeName = t.s_name();
    if (_js_global_type_map.find(typeName) == _js_global_type_map.end())
    {
        p = (js_type_class_t *)malloc(sizeof(js_type_class_t));
        p->jsclass = jsb_cocos2d_experimental_ui_VideoPlayer_class;
        p->proto = jsb_cocos2d_experimental_ui_VideoPlayer_prototype;
        p->parentProto = jsb_cocos2d_ui_Widget_prototype;
        _js_global_type_map.insert(std::make_pair(typeName, p));
    }
}
Пример #9
0
    void CJSRuntime::InitializePrototypes(void)
    {
        protoList.resize(JSP_COUNT);

        JSContext *cx = jsContext;
        JSObject *obj = jsGlobal;

        protoList[JSP_CHAR]     = JS_InitClass(cx, obj, NULL, &UOXChar_class.base,    NULL,        0,        CCharacterProps,         CChar_Methods,       NULL,    NULL);
        protoList[JSP_ITEM]     = JS_InitClass(cx, obj, NULL, &UOXItem_class.base,    NULL,        0,        CItemProps,              CItem_Methods,       NULL,    NULL);
        protoList[JSP_SPELL]    = JS_InitClass(cx, obj, NULL, &UOXSpell_class,        NULL,        0,        CSpellProperties,        NULL,                NULL,    NULL);
        protoList[JSP_SPELLS]   = JS_InitClass(cx, obj, NULL, &UOXSpells_class,       NULL,        0,        NULL,                    NULL,                NULL,    NULL);
        protoList[JSP_SOCK]     = JS_InitClass(cx, obj, NULL, &UOXSocket_class.base,  NULL,        0,        CSocketProps,            CSocket_Methods,     NULL,    NULL);
        protoList[JSP_ACCOUNTS] = JS_InitClass(cx, obj, NULL, &UOXAccount_class,      NULL,        0,        CAccountProperties,      CAccount_Methods,    NULL,    NULL);
        protoList[JSP_CONSOLE]  = JS_InitClass(cx, obj, NULL, &UOXConsole_class,      NULL,        0,        CConsoleProperties,      CConsole_Methods,    NULL,    NULL);
        protoList[JSP_REGION]   = JS_InitClass(cx, obj, NULL, &UOXRegion_class,       NULL,        0,        CRegionProperties,       NULL,                NULL,    NULL);
        protoList[JSP_RESOURCE] = JS_InitClass(cx, obj, NULL, &UOXResource_class,     NULL,        0,        CResourceProperties,     NULL,                NULL,    NULL);
        protoList[JSP_RACE]     = JS_InitClass(cx, obj, NULL, &UOXRace_class,         NULL,        0,        CRaceProperties,         CRace_Methods,       NULL,    NULL);
        protoList[JSP_GUILD]    = JS_InitClass(cx, obj, NULL, &UOXGuild_class,        NULL,        0,        CGuildProperties,        CGuild_Methods,      NULL,    NULL);
        protoList[JSP_PARTY]    = JS_InitClass(cx, obj, NULL, &UOXParty_class.base,   NULL,        0,        CPartyProperties,        CParty_Methods,      NULL,    NULL);
        protoList[JSP_PACKET]   = JS_InitClass(cx, obj, NULL, &UOXPacket_class,       Packet,      0,        NULL,                    NULL,                NULL,    NULL);
        protoList[JSP_GUMP]     = JS_InitClass(cx, obj, NULL, &UOXGump_class,         Gump,        0,        NULL,                    NULL,                NULL,    NULL);
        protoList[JSP_FILE]     = JS_InitClass(cx, obj, NULL, &UOXFile_class,         UOXCFile,    0,        NULL,                    NULL,                NULL,    NULL);
        spellsObj               = JS_DefineObject(cx, obj, "Spells", &UOXSpells_class, protoList[JSP_SPELLS], 0);
        accountsObj             = JS_DefineObject(cx, obj, "Accounts", &UOXAccount_class, protoList[JSP_ACCOUNTS], 0);
        consoleObj              = JS_DefineObject(cx, obj, "Console", &UOXConsole_class, protoList[JSP_CONSOLE], 0);
        protoList[JSACT_SQL]    = JS_InitClass(cx, obj, NULL, &UOXSQLM_class,        NULL,        0,        CSQLMProperties,        CSQLM_Methods,        NULL,    NULL);
        sqlmObj                 = JS_DefineObject(cx, obj, "SQLM", &UOXSQLM_class, protoList[JSACT_SQL], 0);
        JS_LockGCThing(cx, sqlmObj);
        JS_LockGCThing(cx, spellsObj);
        //JS_AddRoot(cx, &spellsObj);
        JS_LockGCThing(cx, accountsObj);
        //JS_AddRoot(cx, &accountsObj);
        JS_LockGCThing(cx, consoleObj);
        //JS_AddRoot(cx, &consoleObj);
        for (size_t i = JSP_ITEM; i < JSP_COUNT; ++i)
        {
            JS_LockGCThing(cx, protoList[i]);
            //JS_AddRoot(cx, &protoList[i]);
        }
    }
void js_register_PluginAppodealJS_PluginAppodeal(JSContext *cx, JSObject *global) {
    jsb_sdkbox_PluginAppodeal_class = (JSClass *)calloc(1, sizeof(JSClass));
    jsb_sdkbox_PluginAppodeal_class->name = "PluginAppodeal";
    jsb_sdkbox_PluginAppodeal_class->addProperty = JS_PropertyStub;
    jsb_sdkbox_PluginAppodeal_class->delProperty = JS_DeletePropertyStub;
    jsb_sdkbox_PluginAppodeal_class->getProperty = JS_PropertyStub;
    jsb_sdkbox_PluginAppodeal_class->setProperty = JS_StrictPropertyStub;
    jsb_sdkbox_PluginAppodeal_class->enumerate = JS_EnumerateStub;
    jsb_sdkbox_PluginAppodeal_class->resolve = JS_ResolveStub;
    jsb_sdkbox_PluginAppodeal_class->convert = JS_ConvertStub;
    jsb_sdkbox_PluginAppodeal_class->finalize = js_PluginAppodealJS_PluginAppodeal_finalize;
    jsb_sdkbox_PluginAppodeal_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2);

    static JSPropertySpec properties[] = {
        {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER},
        {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER}
    };

    static JSFunctionSpec funcs[] = {
        JS_FS_END
    };

    static JSFunctionSpec st_funcs[] = {
        JS_FN("isAutocacheEnabled", js_PluginAppodealJS_PluginAppodeal_isAutocacheEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("hideBanner", js_PluginAppodealJS_PluginAppodeal_hideBanner, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserGender", js_PluginAppodealJS_PluginAppodeal_setUserGender, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getSDKVersion", js_PluginAppodealJS_PluginAppodeal_getSDKVersion, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("disableNetworkForAdType", js_PluginAppodealJS_PluginAppodeal_disableNetworkForAdType, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserSmokingAttitude", js_PluginAppodealJS_PluginAppodeal_setUserSmokingAttitude, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserInterests", js_PluginAppodealJS_PluginAppodeal_setUserInterests, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserBirthday", js_PluginAppodealJS_PluginAppodeal_setUserBirthday, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("init", js_PluginAppodealJS_PluginAppodeal_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("disableLocationPermissionCheck", js_PluginAppodealJS_PluginAppodeal_disableLocationPermissionCheck, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserAlcoholAttitude", js_PluginAppodealJS_PluginAppodeal_setUserAlcoholAttitude, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserOccupation", js_PluginAppodealJS_PluginAppodeal_setUserOccupation, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("isReadyForShowWithStyle", js_PluginAppodealJS_PluginAppodeal_isReadyForShowWithStyle, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserVkId", js_PluginAppodealJS_PluginAppodeal_setUserVkId, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("cacheAd", js_PluginAppodealJS_PluginAppodeal_cacheAd, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setAutocache", js_PluginAppodealJS_PluginAppodeal_setAutocache, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setDebugEnabled", js_PluginAppodealJS_PluginAppodeal_setDebugEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserAge", js_PluginAppodealJS_PluginAppodeal_setUserAge, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserEmail", js_PluginAppodealJS_PluginAppodeal_setUserEmail, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("confirmUsage", js_PluginAppodealJS_PluginAppodeal_confirmUsage, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserFacebookId", js_PluginAppodealJS_PluginAppodeal_setUserFacebookId, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserRelationship", js_PluginAppodealJS_PluginAppodeal_setUserRelationship, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("showAd", js_PluginAppodealJS_PluginAppodeal_showAd, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FS_END
    };

    jsb_sdkbox_PluginAppodeal_prototype = JS_InitClass(
        cx, global,
        NULL, // parent proto
        jsb_sdkbox_PluginAppodeal_class,
        dummy_constructor<sdkbox::PluginAppodeal>, 0, // no constructor
        properties,
        funcs,
        NULL, // no static properties
        st_funcs);
    // make the class enumerable in the registered namespace
//  bool found;
//FIXME: Removed in Firefox v27
//  JS_SetPropertyAttributes(cx, global, "PluginAppodeal", JSPROP_ENUMERATE | JSPROP_READONLY, &found);

    // add the proto and JSClass to the type->js info hash table
    TypeTest<sdkbox::PluginAppodeal> t;
    js_type_class_t *p;
    std::string typeName = t.s_name();
    if (_js_global_type_map.find(typeName) == _js_global_type_map.end())
    {
        p = (js_type_class_t *)malloc(sizeof(js_type_class_t));
        p->jsclass = jsb_sdkbox_PluginAppodeal_class;
        p->proto = jsb_sdkbox_PluginAppodeal_prototype;
        p->parentProto = NULL;
        _js_global_type_map.insert(std::make_pair(typeName, p));
    }
}
void js_register_cocos2dx_experimental_webView_WebView(JSContext *cx, JS::HandleObject global) {
    jsb_cocos2d_experimental_ui_WebView_class = (JSClass *)calloc(1, sizeof(JSClass));
    jsb_cocos2d_experimental_ui_WebView_class->name = "WebView";
    jsb_cocos2d_experimental_ui_WebView_class->addProperty = JS_PropertyStub;
    jsb_cocos2d_experimental_ui_WebView_class->delProperty = JS_DeletePropertyStub;
    jsb_cocos2d_experimental_ui_WebView_class->getProperty = JS_PropertyStub;
    jsb_cocos2d_experimental_ui_WebView_class->setProperty = JS_StrictPropertyStub;
    jsb_cocos2d_experimental_ui_WebView_class->enumerate = JS_EnumerateStub;
    jsb_cocos2d_experimental_ui_WebView_class->resolve = JS_ResolveStub;
    jsb_cocos2d_experimental_ui_WebView_class->convert = JS_ConvertStub;
    jsb_cocos2d_experimental_ui_WebView_class->finalize = js_cocos2d_experimental_ui_WebView_finalize;
    jsb_cocos2d_experimental_ui_WebView_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2);

    static JSPropertySpec properties[] = {
        JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_PS_END
    };

    static JSFunctionSpec funcs[] = {
        JS_FN("canGoBack", js_cocos2dx_experimental_webView_WebView_canGoBack, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("loadHTMLString", js_cocos2dx_experimental_webView_WebView_loadHTMLString, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("goForward", js_cocos2dx_experimental_webView_WebView_goForward, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("goBack", js_cocos2dx_experimental_webView_WebView_goBack, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setScalesPageToFit", js_cocos2dx_experimental_webView_WebView_setScalesPageToFit, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getOnDidFailLoading", js_cocos2dx_experimental_webView_WebView_getOnDidFailLoading, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("loadFile", js_cocos2dx_experimental_webView_WebView_loadFile, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("loadURL", js_cocos2dx_experimental_webView_WebView_loadURL, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("evaluateJS", js_cocos2dx_experimental_webView_WebView_evaluateJS, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getOnJSCallback", js_cocos2dx_experimental_webView_WebView_getOnJSCallback, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("canGoForward", js_cocos2dx_experimental_webView_WebView_canGoForward, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getOnShouldStartLoading", js_cocos2dx_experimental_webView_WebView_getOnShouldStartLoading, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("stopLoading", js_cocos2dx_experimental_webView_WebView_stopLoading, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("reload", js_cocos2dx_experimental_webView_WebView_reload, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setJavascriptInterfaceScheme", js_cocos2dx_experimental_webView_WebView_setJavascriptInterfaceScheme, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getOnDidFinishLoading", js_cocos2dx_experimental_webView_WebView_getOnDidFinishLoading, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FS_END
    };

    static JSFunctionSpec st_funcs[] = {
        JS_FN("create", js_cocos2dx_experimental_webView_WebView_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FS_END
    };

    jsb_cocos2d_experimental_ui_WebView_prototype = JS_InitClass(
                cx, global,
                JS::RootedObject(cx, jsb_cocos2d_ui_Widget_prototype),
                jsb_cocos2d_experimental_ui_WebView_class,
                js_cocos2dx_experimental_webView_WebView_constructor, 0, // constructor
                properties,
                funcs,
                NULL, // no static properties
                st_funcs);
    // make the class enumerable in the registered namespace
//  bool found;
//FIXME: Removed in Firefox v27
//  JS_SetPropertyAttributes(cx, global, "WebView", JSPROP_ENUMERATE | JSPROP_READONLY, &found);

    // add the proto and JSClass to the type->js info hash table
    TypeTest<cocos2d::experimental::ui::WebView> t;
    js_type_class_t *p;
    std::string typeName = t.s_name();
    if (_js_global_type_map.find(typeName) == _js_global_type_map.end())
    {
        p = (js_type_class_t *)malloc(sizeof(js_type_class_t));
        p->jsclass = jsb_cocos2d_experimental_ui_WebView_class;
        p->proto = jsb_cocos2d_experimental_ui_WebView_prototype;
        p->parentProto = jsb_cocos2d_ui_Widget_prototype;
        _js_global_type_map.insert(std::make_pair(typeName, p));
    }
}
void js_register_PluginAppodealJS_PluginAppodeal(JSContext *cx, JSObject *global) {
    jsb_sdkbox_PluginAppodeal_class = (JSClass *)calloc(1, sizeof(JSClass));
    jsb_sdkbox_PluginAppodeal_class->name = "PluginAppodeal";
    jsb_sdkbox_PluginAppodeal_class->addProperty = JS_PropertyStub;
    jsb_sdkbox_PluginAppodeal_class->delProperty = JS_PropertyStub;
    jsb_sdkbox_PluginAppodeal_class->getProperty = JS_PropertyStub;
    jsb_sdkbox_PluginAppodeal_class->setProperty = JS_StrictPropertyStub;
    jsb_sdkbox_PluginAppodeal_class->enumerate = JS_EnumerateStub;
    jsb_sdkbox_PluginAppodeal_class->resolve = JS_ResolveStub;
    jsb_sdkbox_PluginAppodeal_class->convert = JS_ConvertStub;
    jsb_sdkbox_PluginAppodeal_class->finalize = js_PluginAppodealJS_PluginAppodeal_finalize;
    jsb_sdkbox_PluginAppodeal_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2);

    JSPropertySpec *properties = NULL;

    JSFunctionSpec *funcs = NULL;

    static JSFunctionSpec st_funcs[] = {
        JS_FN("isAutocacheEnabled", js_PluginAppodealJS_PluginAppodeal_isAutocacheEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("hideBanner", js_PluginAppodealJS_PluginAppodeal_hideBanner, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserGender", js_PluginAppodealJS_PluginAppodeal_setUserGender, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getSDKVersion", js_PluginAppodealJS_PluginAppodeal_getSDKVersion, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("disableNetworkForAdType", js_PluginAppodealJS_PluginAppodeal_disableNetworkForAdType, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserSmokingAttitude", js_PluginAppodealJS_PluginAppodeal_setUserSmokingAttitude, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserInterests", js_PluginAppodealJS_PluginAppodeal_setUserInterests, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserBirthday", js_PluginAppodealJS_PluginAppodeal_setUserBirthday, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("init", js_PluginAppodealJS_PluginAppodeal_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("disableLocationPermissionCheck", js_PluginAppodealJS_PluginAppodeal_disableLocationPermissionCheck, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserAlcoholAttitude", js_PluginAppodealJS_PluginAppodeal_setUserAlcoholAttitude, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserOccupation", js_PluginAppodealJS_PluginAppodeal_setUserOccupation, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("isReadyForShowWithStyle", js_PluginAppodealJS_PluginAppodeal_isReadyForShowWithStyle, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserVkId", js_PluginAppodealJS_PluginAppodeal_setUserVkId, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("cacheAd", js_PluginAppodealJS_PluginAppodeal_cacheAd, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setAutocache", js_PluginAppodealJS_PluginAppodeal_setAutocache, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setDebugEnabled", js_PluginAppodealJS_PluginAppodeal_setDebugEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserAge", js_PluginAppodealJS_PluginAppodeal_setUserAge, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserEmail", js_PluginAppodealJS_PluginAppodeal_setUserEmail, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("confirmUsage", js_PluginAppodealJS_PluginAppodeal_confirmUsage, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserFacebookId", js_PluginAppodealJS_PluginAppodeal_setUserFacebookId, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserRelationship", js_PluginAppodealJS_PluginAppodeal_setUserRelationship, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("showAd", js_PluginAppodealJS_PluginAppodeal_showAd, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FS_END
    };

    jsb_sdkbox_PluginAppodeal_prototype = JS_InitClass(
        cx, global,
        NULL, // parent proto
        jsb_sdkbox_PluginAppodeal_class,
        dummy_constructor<sdkbox::PluginAppodeal>, 0, // no constructor
        properties,
        funcs,
        NULL, // no static properties
        st_funcs);
    // make the class enumerable in the registered namespace
    JSBool found;
    JS_SetPropertyAttributes(cx, global, "PluginAppodeal", JSPROP_ENUMERATE | JSPROP_READONLY, &found);

    // add the proto and JSClass to the type->js info hash table
    TypeTest<sdkbox::PluginAppodeal> t;
    js_type_class_t *p;
    uint32_t typeId = t.s_id();
    HASH_FIND_INT(_js_global_type_ht, &typeId, p);
    if (!p) {
        p = (js_type_class_t *)malloc(sizeof(js_type_class_t));
        p->type = typeId;
        p->jsclass = jsb_sdkbox_PluginAppodeal_class;
        p->proto = jsb_sdkbox_PluginAppodeal_prototype;
        p->parentProto = NULL;
        HASH_ADD_INT(_js_global_type_ht, type, p);
    }
}
void js_register_PluginLeaderboardJS_PluginLeaderboard(JSContext *cx, JS::HandleObject global) {
    jsb_sdkbox_PluginLeaderboard_class = (JSClass *)calloc(1, sizeof(JSClass));
    jsb_sdkbox_PluginLeaderboard_class->name = "PluginLeaderboard";
    jsb_sdkbox_PluginLeaderboard_class->addProperty = JS_PropertyStub;
    jsb_sdkbox_PluginLeaderboard_class->delProperty = JS_DeletePropertyStub;
    jsb_sdkbox_PluginLeaderboard_class->getProperty = JS_PropertyStub;
    jsb_sdkbox_PluginLeaderboard_class->setProperty = JS_StrictPropertyStub;
    jsb_sdkbox_PluginLeaderboard_class->enumerate = JS_EnumerateStub;
    jsb_sdkbox_PluginLeaderboard_class->resolve = JS_ResolveStub;
    jsb_sdkbox_PluginLeaderboard_class->convert = JS_ConvertStub;
    jsb_sdkbox_PluginLeaderboard_class->finalize = js_PluginLeaderboardJS_PluginLeaderboard_finalize;
    jsb_sdkbox_PluginLeaderboard_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2);

    static JSPropertySpec properties[] = {
        JS_PSG("__nativeObj", js_is_native_obj, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_PS_END
    };

    static JSFunctionSpec funcs[] = {
        JS_FS_END
    };

    static JSFunctionSpec st_funcs[] = {
        JS_FN("getLeaderboard", js_PluginLeaderboardJS_PluginLeaderboard_getLeaderboard, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("init", js_PluginLeaderboardJS_PluginLeaderboard_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("submitScore", js_PluginLeaderboardJS_PluginLeaderboard_submitScore, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FS_END
    };

    jsb_sdkbox_PluginLeaderboard_prototype = JS_InitClass(
        cx, global,
        JS::NullPtr(), // parent proto
        jsb_sdkbox_PluginLeaderboard_class,
        dummy_constructor<sdkbox::PluginLeaderboard>, 0, // no constructor
        properties,
        funcs,
        NULL, // no static properties
        st_funcs);
    // make the class enumerable in the registered namespace
//  bool found;
//FIXME: Removed in Firefox v27
//  JS_SetPropertyAttributes(cx, global, "PluginLeaderboard", JSPROP_ENUMERATE | JSPROP_READONLY, &found);

    // add the proto and JSClass to the type->js info hash table
#if (SDKBOX_COCOS_JSB_VERSION >= 2)
    JS::RootedObject proto(cx, jsb_sdkbox_PluginLeaderboard_prototype);
    jsb_register_class<sdkbox::PluginLeaderboard>(cx, jsb_sdkbox_PluginLeaderboard_class, proto, JS::NullPtr());
#else
    TypeTest<sdkbox::PluginLeaderboard> t;
    js_type_class_t *p;
    std::string typeName = t.s_name();
    if (_js_global_type_map.find(typeName) == _js_global_type_map.end())
    {
        p = (js_type_class_t *)malloc(sizeof(js_type_class_t));
        p->jsclass = jsb_sdkbox_PluginLeaderboard_class;
        p->proto = jsb_sdkbox_PluginLeaderboard_prototype;
        p->parentProto = NULL;
        _js_global_type_map.insert(std::make_pair(typeName, p));
    }
#endif
}
Пример #14
0
void js_register_cocos2dx_spine_Skeleton(JSContext *cx, JSObject *global) {
	jsb_spine_Skeleton_class = (JSClass *)calloc(1, sizeof(JSClass));
	jsb_spine_Skeleton_class->name = "Skeleton";
	jsb_spine_Skeleton_class->addProperty = JS_PropertyStub;
	jsb_spine_Skeleton_class->delProperty = JS_DeletePropertyStub;
	jsb_spine_Skeleton_class->getProperty = JS_PropertyStub;
	jsb_spine_Skeleton_class->setProperty = JS_StrictPropertyStub;
	jsb_spine_Skeleton_class->enumerate = JS_EnumerateStub;
	jsb_spine_Skeleton_class->resolve = JS_ResolveStub;
	jsb_spine_Skeleton_class->convert = JS_ConvertStub;
	jsb_spine_Skeleton_class->finalize = js_spine_Skeleton_finalize;
	jsb_spine_Skeleton_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2);

	static JSPropertySpec properties[] = {
		{0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER}
	};

	static JSFunctionSpec funcs[] = {
		JS_FN("setToSetupPose", js_cocos2dx_spine_Skeleton_setToSetupPose, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setBlendFunc", js_cocos2dx_spine_Skeleton_setBlendFunc, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("onDraw", js_cocos2dx_spine_Skeleton_onDraw, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setSlotsToSetupPose", js_cocos2dx_spine_Skeleton_setSlotsToSetupPose, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("getAttachment", js_cocos2dx_spine_Skeleton_getAttachment, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setAttachment", js_cocos2dx_spine_Skeleton_setAttachment, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("getBlendFunc", js_cocos2dx_spine_Skeleton_getBlendFunc, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setSkin", js_cocos2dx_spine_Skeleton_setSkin, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("findSlot", js_cocos2dx_spine_Skeleton_findSlot, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("updateWorldTransform", js_cocos2dx_spine_Skeleton_updateWorldTransform, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setBonesToSetupPose", js_cocos2dx_spine_Skeleton_setBonesToSetupPose, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("findBone", js_cocos2dx_spine_Skeleton_findBone, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FS_END
	};

	static JSFunctionSpec st_funcs[] = {
		JS_FN("createWithFile", js_cocos2dx_spine_Skeleton_createWithFile, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FS_END
	};

	jsb_spine_Skeleton_prototype = JS_InitClass(
		cx, global,
		jsb_cocos2d_Node_prototype,
		jsb_spine_Skeleton_class,
		js_cocos2dx_spine_Skeleton_constructor, 0, // constructor
		properties,
		funcs,
		NULL, // no static properties
		st_funcs);
	// make the class enumerable in the registered namespace
	JSBool found;
	JS_SetPropertyAttributes(cx, global, "Skeleton", JSPROP_ENUMERATE | JSPROP_READONLY, &found);

	// add the proto and JSClass to the type->js info hash table
	TypeTest<spine::Skeleton> t;
	js_type_class_t *p;
	std::string typeName = t.s_name();
	if (_js_global_type_map.find(typeName) == _js_global_type_map.end())
	{
		p = (js_type_class_t *)malloc(sizeof(js_type_class_t));
		p->jsclass = jsb_spine_Skeleton_class;
		p->proto = jsb_spine_Skeleton_prototype;
		p->parentProto = jsb_cocos2d_Node_prototype;
		_js_global_type_map.insert(std::make_pair(typeName, p));
	}
}
void js_register_PluginGoogleAnalyticsJS_PluginGoogleAnalytics(JSContext *cx, JSObject *global) {
    jsb_sdkbox_PluginGoogleAnalytics_class = (JSClass *)calloc(1, sizeof(JSClass));
    jsb_sdkbox_PluginGoogleAnalytics_class->name = "PluginGoogleAnalytics";
    jsb_sdkbox_PluginGoogleAnalytics_class->addProperty = JS_PropertyStub;
    jsb_sdkbox_PluginGoogleAnalytics_class->delProperty = JS_DeletePropertyStub;
    jsb_sdkbox_PluginGoogleAnalytics_class->getProperty = JS_PropertyStub;
    jsb_sdkbox_PluginGoogleAnalytics_class->setProperty = JS_StrictPropertyStub;
    jsb_sdkbox_PluginGoogleAnalytics_class->enumerate = JS_EnumerateStub;
    jsb_sdkbox_PluginGoogleAnalytics_class->resolve = JS_ResolveStub;
    jsb_sdkbox_PluginGoogleAnalytics_class->convert = JS_ConvertStub;
    jsb_sdkbox_PluginGoogleAnalytics_class->finalize = js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_finalize;
    jsb_sdkbox_PluginGoogleAnalytics_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2);

    static JSPropertySpec properties[] = {
        {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER},
        {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER}
    };

    static JSFunctionSpec funcs[] = {
        JS_FS_END
    };

    static JSFunctionSpec st_funcs[] = {
        JS_FN("createTracker", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_createTracker, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setMetric", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_setMetric, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("stopPeriodicalDispatch", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_stopPeriodicalDispatch, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setDryRun", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_setDryRun, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("logEvent", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_logEvent, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("dispatchPeriodically", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_dispatchPeriodically, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("init", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("logScreen", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_logScreen, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("startSession", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_startSession, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("logException", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_logException, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUser", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_setUser, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("stopSession", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_stopSession, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setDimension", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_setDimension, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("logSocial", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_logSocial, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("enableAdvertisingTracking", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_enableAdvertisingTracking, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("dispatchHits", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_dispatchHits, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("enableTracker", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_enableTracker, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("logTiming", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_logTiming, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FS_END
    };

    jsb_sdkbox_PluginGoogleAnalytics_prototype = JS_InitClass(
                cx, global,
                NULL, // parent proto
                jsb_sdkbox_PluginGoogleAnalytics_class,
                dummy_constructor<sdkbox::PluginGoogleAnalytics>, 0, // no constructor
                properties,
                funcs,
                NULL, // no static properties
                st_funcs);
    // make the class enumerable in the registered namespace
//  bool found;
//FIXME: Removed in Firefox v27
//  JS_SetPropertyAttributes(cx, global, "PluginGoogleAnalytics", JSPROP_ENUMERATE | JSPROP_READONLY, &found);

    // add the proto and JSClass to the type->js info hash table
    TypeTest<sdkbox::PluginGoogleAnalytics> t;
    js_type_class_t *p;
    std::string typeName = t.s_name();
    if (_js_global_type_map.find(typeName) == _js_global_type_map.end())
    {
        p = (js_type_class_t *)malloc(sizeof(js_type_class_t));
        p->jsclass = jsb_sdkbox_PluginGoogleAnalytics_class;
        p->proto = jsb_sdkbox_PluginGoogleAnalytics_prototype;
        p->parentProto = NULL;
        _js_global_type_map.insert(std::make_pair(typeName, p));
    }
}
Пример #16
0
void js_register_fygui_FYPropCell(JSContext *cx, JSObject *global) {
	jsb_FYPropCell_class = (JSClass *)calloc(1, sizeof(JSClass));
	jsb_FYPropCell_class->name = "FYPropCell";
	jsb_FYPropCell_class->addProperty = JS_PropertyStub;
	jsb_FYPropCell_class->delProperty = JS_PropertyStub;
	jsb_FYPropCell_class->getProperty = JS_PropertyStub;
	jsb_FYPropCell_class->setProperty = JS_StrictPropertyStub;
	jsb_FYPropCell_class->enumerate = JS_EnumerateStub;
	jsb_FYPropCell_class->resolve = JS_ResolveStub;
	jsb_FYPropCell_class->convert = JS_ConvertStub;
	jsb_FYPropCell_class->finalize = js_fygui_FYPropCell_finalize;
	jsb_FYPropCell_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2);

	static JSPropertySpec properties[] = {
		{0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER}
	};

	static JSFunctionSpec funcs[] = {
		JS_FN("getOrgPosition", js_fygui_FYPropCell_getOrgPosition, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("getCellVisibleRect", js_fygui_FYPropCell_getCellVisibleRect, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("onEnter", js_fygui_FYPropCell_onEnter, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setSelected", js_fygui_FYPropCell_setSelected, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setCellPosition", js_fygui_FYPropCell_setCellPosition, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setTouchDelegate", js_fygui_FYPropCell_setTouchDelegate, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setPropId", js_fygui_FYPropCell_setPropId, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("fyDragDropCancelled", js_fygui_FYPropCell_fyDragDropCancelled, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setOneTouchedDelegate", js_fygui_FYPropCell_setOneTouchedDelegate, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("getTouchDelegate", js_fygui_FYPropCell_getTouchDelegate, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setDoubleTouchsTimeElapse", js_fygui_FYPropCell_setDoubleTouchsTimeElapse, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("isHighlighted", js_fygui_FYPropCell_isHighlighted, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("getPropIndex", js_fygui_FYPropCell_getPropIndex, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("getDoubleTouchsTimeElapse", js_fygui_FYPropCell_getDoubleTouchsTimeElapse, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("fyDragDropMoved", js_fygui_FYPropCell_fyDragDropMoved, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("getCellPosition", js_fygui_FYPropCell_getCellPosition, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("getTouchedPriority", js_fygui_FYPropCell_getTouchedPriority, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("isSelected", js_fygui_FYPropCell_isSelected, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("getOrgParent", js_fygui_FYPropCell_getOrgParent, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("cleanup", js_fygui_FYPropCell_cleanup, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("fyDragDropEnded", js_fygui_FYPropCell_fyDragDropEnded, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("getDoubleTouchsDelegate", js_fygui_FYPropCell_getDoubleTouchsDelegate, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setShakeRange", js_fygui_FYPropCell_setShakeRange, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setEnableDragDrop", js_fygui_FYPropCell_setEnableDragDrop, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setDragCheckTime", js_fygui_FYPropCell_setDragCheckTime, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("fyDragDropBegan", js_fygui_FYPropCell_fyDragDropBegan, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("isEnableDragDrop", js_fygui_FYPropCell_isEnableDragDrop, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("dragToTopLayer", js_fygui_FYPropCell_dragToTopLayer, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("dropToLayer", js_fygui_FYPropCell_dropToLayer, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("getPropId", js_fygui_FYPropCell_getPropId, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setTouchedPriority", js_fygui_FYPropCell_setTouchedPriority, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("getDragCheckTime", js_fygui_FYPropCell_getDragCheckTime, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setDoubleTouchsDelegate", js_fygui_FYPropCell_setDoubleTouchsDelegate, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setEnableDoubleTouchs", js_fygui_FYPropCell_setEnableDoubleTouchs, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("onExit", js_fygui_FYPropCell_onExit, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("isTouchInside", js_fygui_FYPropCell_isTouchInside, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("isEnableDoubleTouchs", js_fygui_FYPropCell_isEnableDoubleTouchs, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("getOneTouchedDelegate", js_fygui_FYPropCell_getOneTouchedDelegate, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setPropIndex", js_fygui_FYPropCell_setPropIndex, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("getShakeRange", js_fygui_FYPropCell_getShakeRange, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setHighlighted", js_fygui_FYPropCell_setHighlighted, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("ctor", js_fygui_FYPropCell_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FS_END
	};

	static JSFunctionSpec st_funcs[] = {
		JS_FN("create", js_fygui_FYPropCell_create, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("createWithBatchNode", js_fygui_FYPropCell_createWithBatchNode, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FS_END
	};

	jsb_FYPropCell_prototype = JS_InitClass(
		cx, global,
		jsb_CCSprite_prototype,
		jsb_FYPropCell_class,
		js_fygui_FYPropCell_constructor, 0, // constructor
		properties,
		funcs,
		NULL, // no static properties
		st_funcs);
	// make the class enumerable in the registered namespace
	JSBool found;
	JS_SetPropertyAttributes(cx, global, "FYPropCell", JSPROP_ENUMERATE | JSPROP_READONLY, &found);

	// add the proto and JSClass to the type->js info hash table
	TypeTest<FYPropCell> t;
	js_type_class_t *p;
	uint32_t typeId = t.s_id();
	HASH_FIND_INT(_js_global_type_ht, &typeId, p);
	if (!p) {
		p = (js_type_class_t *)malloc(sizeof(js_type_class_t));
		p->type = typeId;
		p->jsclass = jsb_FYPropCell_class;
		p->proto = jsb_FYPropCell_prototype;
		p->parentProto = jsb_CCSprite_prototype;
		HASH_ADD_INT(_js_global_type_ht, type, p);
	}
}
void js_register_PluginGoogleAnalyticsJS_PluginGoogleAnalytics(JSContext *cx, JSObject *global) {
    jsb_sdkbox_PluginGoogleAnalytics_class = (JSClass *)calloc(1, sizeof(JSClass));
    jsb_sdkbox_PluginGoogleAnalytics_class->name = "PluginGoogleAnalytics";
    jsb_sdkbox_PluginGoogleAnalytics_class->addProperty = JS_PropertyStub;
    jsb_sdkbox_PluginGoogleAnalytics_class->delProperty = JS_PropertyStub;
    jsb_sdkbox_PluginGoogleAnalytics_class->getProperty = JS_PropertyStub;
    jsb_sdkbox_PluginGoogleAnalytics_class->setProperty = JS_StrictPropertyStub;
    jsb_sdkbox_PluginGoogleAnalytics_class->enumerate = JS_EnumerateStub;
    jsb_sdkbox_PluginGoogleAnalytics_class->resolve = JS_ResolveStub;
    jsb_sdkbox_PluginGoogleAnalytics_class->convert = JS_ConvertStub;
    jsb_sdkbox_PluginGoogleAnalytics_class->finalize = js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_finalize;
    jsb_sdkbox_PluginGoogleAnalytics_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2);

    JSPropertySpec *properties = NULL;

    JSFunctionSpec *funcs = NULL;

    static JSFunctionSpec st_funcs[] = {
        JS_FN("createTracker", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_createTracker, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setMetric", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_setMetric, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("stopPeriodicalDispatch", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_stopPeriodicalDispatch, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setDryRun", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_setDryRun, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("logEvent", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_logEvent, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("dispatchPeriodically", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_dispatchPeriodically, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("init", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("logScreen", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_logScreen, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("startSession", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_startSession, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("logException", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_logException, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUser", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_setUser, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("stopSession", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_stopSession, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setDimension", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_setDimension, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("logSocial", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_logSocial, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("enableAdvertisingTracking", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_enableAdvertisingTracking, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("dispatchHits", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_dispatchHits, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("enableTracker", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_enableTracker, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("logTiming", js_PluginGoogleAnalyticsJS_PluginGoogleAnalytics_logTiming, 4, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FS_END
    };

    jsb_sdkbox_PluginGoogleAnalytics_prototype = JS_InitClass(
                cx, global,
                NULL, // parent proto
                jsb_sdkbox_PluginGoogleAnalytics_class,
                dummy_constructor<sdkbox::PluginGoogleAnalytics>, 0, // no constructor
                properties,
                funcs,
                NULL, // no static properties
                st_funcs);
    // make the class enumerable in the registered namespace
    JSBool found;
    JS_SetPropertyAttributes(cx, global, "PluginGoogleAnalytics", JSPROP_ENUMERATE | JSPROP_READONLY, &found);

    // add the proto and JSClass to the type->js info hash table
    TypeTest<sdkbox::PluginGoogleAnalytics> t;
    js_type_class_t *p;
    uint32_t typeId = t.s_id();
    HASH_FIND_INT(_js_global_type_ht, &typeId, p);
    if (!p) {
        p = (js_type_class_t *)malloc(sizeof(js_type_class_t));
        p->type = typeId;
        p->jsclass = jsb_sdkbox_PluginGoogleAnalytics_class;
        p->proto = jsb_sdkbox_PluginGoogleAnalytics_prototype;
        p->parentProto = NULL;
        HASH_ADD_INT(_js_global_type_ht, type, p);
    }
}
Пример #18
0
JSObject*
gjs_init_class_dynamic(JSContext      *context,
                       JSObject       *in_object,
                       JSObject       *parent_proto,
                       const char     *ns_name,
                       const char     *class_name,
                       JSClass        *clasp,
                       JSNative        constructor,
                       uintN           nargs,
                       JSPropertySpec *ps,
                       JSFunctionSpec *fs,
                       JSPropertySpec *static_ps,
                       JSFunctionSpec *static_fs)
{
    jsval value;
    char *private_name;
    JSObject *global;
    JSObject *prototype;

    if (clasp->name != NULL) {
        g_warning("Dynamic class should not have a name in the JSClass struct");
        return NULL;
    }

    JS_BeginRequest(context);

    /* We use a special "fake" global object to store our constructors
     * in for future use. Using the actual global object of the context would
     * result in different contexts having different class definitions for
     * the same GObject class; since the proxies are shared between all
     * contexts, this would produce confusing results.
     */
    global = gjs_get_import_global(context);

    /* JS_InitClass() wants to define the constructor in the global object, so
     * we give it a private and namespaced name... passing in the namespace
     * object instead of global object seems to break JS_ConstructObject()
     * which then can't find the constructor for the class. I am probably
     * missing something.
     */
    private_name = g_strdup_printf("_private_%s_%s", ns_name, class_name);

    prototype = NULL;
    if (gjs_object_get_property(context, global,
                                private_name, &value) &&
        JSVAL_IS_OBJECT(value)) {
        jsval proto_val;

        g_free(private_name); /* don't need it anymore */

        if (!gjs_object_require_property(context, JSVAL_TO_OBJECT(value), NULL,
                                         "prototype", &proto_val) ||
            !JSVAL_IS_OBJECT(proto_val)) {
            gjs_throw(context, "prototype was not defined or not an object?");
            goto error;
        }
        prototype = JSVAL_TO_OBJECT(proto_val);
    } else {
        DynamicJSClass *class_copy;
        RuntimeData *rd;

        rd = get_data_from_context(context);

        class_copy = g_slice_new0(DynamicJSClass);
        class_copy->base = *clasp;

        class_copy->base.name = private_name; /* Pass ownership of memory */
        class_copy->static_class = clasp;

        /* record the allocated class to be destroyed with the runtime and so
         * we can do an IS_DYNAMIC_CLASS check
         */
        g_hash_table_replace(rd->dynamic_classes,
                             class_copy, class_copy);

        gjs_debug(GJS_DEBUG_GREPO,
                  "Initializing dynamic class %s %p",
                  class_name, class_copy);

        prototype = JS_InitClass(context, global,
                                 parent_proto, &class_copy->base,
                                 constructor, nargs,
                                 ps, fs,
                                 static_ps, static_fs);
        if (prototype == NULL)
            goto error;

        /* Retrieve the property again so we can define it in
         * in_object
         */
        if (!gjs_object_require_property(context, global, NULL,
                                         class_copy->base.name, &value))
            goto error;
    }
    g_assert(!JSVAL_IS_VOID(value));
    g_assert(prototype != NULL);

    /* Now manually define our constructor with a sane name, in the
     * namespace object.
     */
    if (!JS_DefineProperty(context, in_object,
                           class_name,
                           value,
                           NULL, NULL,
                           GJS_MODULE_PROP_FLAGS))
        goto error;

    JS_EndRequest(context);
    return prototype;

 error:
    JS_EndRequest(context);
    return NULL;
}
Пример #19
0
JSObject*
gjs_keep_alive_new(JSContext *context)
{
    JSObject *keep_alive;
    JSObject *global;

    /* This function creates an unattached KeepAlive object; following our
     * general strategy, we have a single KeepAlive class with a constructor
     * stored on our single "load global" pseudo-global object, and we create
     * instances with the load global as parent.
     */

    g_assert(context != NULL);

    JS_BeginRequest(context);

    global = gjs_get_import_global(context);

    g_assert(global != NULL);

    if (!gjs_object_has_property(context, global, gjs_keep_alive_class.name)) {
        JSObject *prototype;

        gjs_debug(GJS_DEBUG_KEEP_ALIVE,
                  "Initializing keep-alive class in context %p global %p",
                  context, global);

        prototype = JS_InitClass(context, global,
                                 /* parent prototype JSObject* for
                                  * prototype; NULL for
                                  * Object.prototype
                                  */
                                 NULL,
                                 &gjs_keep_alive_class,
                                 /* constructor for instances (NULL for
                                  * none - just name the prototype like
                                  * Math - rarely correct)
                                  */
                                 gjs_keep_alive_constructor,
                                 /* number of constructor args */
                                 0,
                                 /* props of prototype */
                                 &gjs_keep_alive_proto_props[0],
                                 /* funcs of prototype */
                                 &gjs_keep_alive_proto_funcs[0],
                                 /* props of constructor, MyConstructor.myprop */
                                 NULL,
                                 /* funcs of constructor, MyConstructor.myfunc() */
                                 NULL);
        if (prototype == NULL)
            gjs_fatal("Can't init class %s", gjs_keep_alive_class.name);

        g_assert(gjs_object_has_property(context, global, gjs_keep_alive_class.name));

        gjs_debug(GJS_DEBUG_KEEP_ALIVE, "Initialized class %s prototype %p",
                  gjs_keep_alive_class.name, prototype);
    }

    gjs_debug(GJS_DEBUG_KEEP_ALIVE,
              "Creating new keep-alive object for context %p global %p",
              context, global);

    keep_alive = JS_ConstructObject(context, &gjs_keep_alive_class, NULL, global);
    if (keep_alive == NULL) {
        gjs_log_exception(context, NULL);
        gjs_fatal("Failed to create keep_alive object");
    }

    JS_EndRequest(context);

    return keep_alive;
}
Пример #20
0
JSObject*
gjs_keep_alive_new(JSContext *context)
{
    JSObject *keep_alive;
    JSObject *global;

    g_assert(context != NULL);

    JS_BeginRequest(context);

    /* put constructor in the global namespace */
    global = JS_GetGlobalObject(context);

    g_assert(global != NULL);

    if (!gjs_object_has_property(context, global, gjs_keep_alive_class.name)) {
        JSObject *prototype;

        gjs_debug(GJS_DEBUG_KEEP_ALIVE,
                  "Initializing keep-alive class in context %p global %p",
                  context, global);

        prototype = JS_InitClass(context, global,
                                 /* parent prototype JSObject* for
                                  * prototype; NULL for
                                  * Object.prototype
                                  */
                                 NULL,
                                 &gjs_keep_alive_class,
                                 /* constructor for instances (NULL for
                                  * none - just name the prototype like
                                  * Math - rarely correct)
                                  */
                                 keep_alive_constructor,
                                 /* number of constructor args */
                                 0,
                                 /* props of prototype */
                                 &gjs_keep_alive_proto_props[0],
                                 /* funcs of prototype */
                                 &gjs_keep_alive_proto_funcs[0],
                                 /* props of constructor, MyConstructor.myprop */
                                 NULL,
                                 /* funcs of constructor, MyConstructor.myfunc() */
                                 NULL);
        if (prototype == NULL)
            gjs_fatal("Can't init class %s", gjs_keep_alive_class.name);

        g_assert(gjs_object_has_property(context, global, gjs_keep_alive_class.name));

        gjs_debug(GJS_DEBUG_KEEP_ALIVE, "Initialized class %s prototype %p",
                  gjs_keep_alive_class.name, prototype);
    }

    gjs_debug(GJS_DEBUG_KEEP_ALIVE,
              "Creating new keep-alive object for context %p global %p",
              context, global);

    /* Without the "global" parent object, this craters inside of
     * xulrunner because in jsobj.c:js_ConstructObject it looks up
     * VOID as the constructor.  Exploring in gdb, it is walking up
     * the scope chain in a way that involves scary xpconnect-looking
     * stuff. Having "global" as parent seems to fix it. But, it would
     * not hurt to understand this better.
     */
    keep_alive = JS_ConstructObject(context, &gjs_keep_alive_class, NULL, global);
    if (keep_alive == NULL) {
        gjs_log_exception(context, NULL);
        gjs_fatal("Failed to create keep_alive object");
    }

    JS_EndRequest(context);

    return keep_alive;
}
void js_register_autogentestbindings_SimpleNativeClass(JSContext *cx, JSObject *global) {
	jsb_SimpleNativeClass_class = (JSClass *)calloc(1, sizeof(JSClass));
	jsb_SimpleNativeClass_class->name = "SimpleNativeClass";
	jsb_SimpleNativeClass_class->addProperty = JS_PropertyStub;
	jsb_SimpleNativeClass_class->delProperty = JS_DeletePropertyStub;
	jsb_SimpleNativeClass_class->getProperty = JS_PropertyStub;
	jsb_SimpleNativeClass_class->setProperty = JS_StrictPropertyStub;
	jsb_SimpleNativeClass_class->enumerate = JS_EnumerateStub;
	jsb_SimpleNativeClass_class->resolve = JS_ResolveStub;
	jsb_SimpleNativeClass_class->convert = JS_ConvertStub;
	jsb_SimpleNativeClass_class->finalize = js_SimpleNativeClass_finalize;
	jsb_SimpleNativeClass_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2);

	static JSPropertySpec properties[] = {
		{"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER},
		{0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER}
	};

	static JSFunctionSpec funcs[] = {
		JS_FN("getAnotherMoreComplexField", js_autogentestbindings_SimpleNativeClass_getAnotherMoreComplexField, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setSomeField", js_autogentestbindings_SimpleNativeClass_setSomeField, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("receivesLongLong", js_autogentestbindings_SimpleNativeClass_receivesLongLong, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("thisReturnsALongLong", js_autogentestbindings_SimpleNativeClass_thisReturnsALongLong, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("getObjectType", js_autogentestbindings_SimpleNativeClass_getObjectType, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setAnotherMoreComplexField", js_autogentestbindings_SimpleNativeClass_setAnotherMoreComplexField, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("setSomeOtherField", js_autogentestbindings_SimpleNativeClass_setSomeOtherField, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("getSomeOtherField", js_autogentestbindings_SimpleNativeClass_getSomeOtherField, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("returnsACString", js_autogentestbindings_SimpleNativeClass_returnsACString, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("doSomeProcessing", js_autogentestbindings_SimpleNativeClass_doSomeProcessing, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("getSomeField", js_autogentestbindings_SimpleNativeClass_getSomeField, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FN("returnsAString", js_autogentestbindings_SimpleNativeClass_returnsAString, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FS_END
	};

	static JSFunctionSpec st_funcs[] = {
		JS_FN("func", js_autogentestbindings_SimpleNativeClass_func, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
		JS_FS_END
	};

	jsb_SimpleNativeClass_prototype = JS_InitClass(
		cx, global,
		NULL, // parent proto
		jsb_SimpleNativeClass_class,
		js_autogentestbindings_SimpleNativeClass_constructor, 0, // constructor
		properties,
		funcs,
		NULL, // no static properties
		st_funcs);
	// make the class enumerable in the registered namespace
//	bool found;
//FIXME: Removed in Firefox v27	
//	JS_SetPropertyAttributes(cx, global, "SimpleNativeClass", JSPROP_ENUMERATE | JSPROP_READONLY, &found);

	// add the proto and JSClass to the type->js info hash table
	TypeTest<SimpleNativeClass> t;
	js_type_class_t *p;
	std::string typeName = t.s_name();
	if (_js_global_type_map.find(typeName) == _js_global_type_map.end())
	{
		p = (js_type_class_t *)malloc(sizeof(js_type_class_t));
		p->jsclass = jsb_SimpleNativeClass_class;
		p->proto = jsb_SimpleNativeClass_prototype;
		p->parentProto = NULL;
		_js_global_type_map.insert(std::make_pair(typeName, p));
	}
}
Пример #22
0
JSURL *
lm_NewURL(JSContext *cx, MochaDecoder *decoder, LO_AnchorData *anchor_data,
          JSObject *document)
{
    JSObject *obj;
    JSURL *url;
    JSString *str;

    if (!decoder->url_prototype) {
	obj = JS_InitClass(cx, decoder->window_object, 
			   decoder->event_receiver_prototype, &lm_url_class, 
			   Url, 0, url_props, NULL, NULL, NULL);
	if (!obj)
	    return NULL;
	decoder->url_prototype = obj;
    }

    url = JS_malloc(cx, sizeof *url);
    if (!url)
	return NULL;
    XP_BZERO(url, sizeof *url);

    obj = JS_NewObject(cx, &lm_url_class, decoder->url_prototype, 
                       lm_GetOuterObject(decoder));
    if (!obj || !JS_SetPrivate(cx, obj, url)) {
	JS_free(cx, url);
	return NULL;
    }

    if (!JS_DefineFunctions(cx, obj, url_methods))
	return NULL;

    url->url_decoder = HOLD_BACK_COUNT(decoder);
    url->url_type = FORM_TYPE_NONE;
    url->index = URL_NOT_INDEXED;
    url->url_object = obj;

    str = JS_NewStringCopyZ(cx, (char *) anchor_data->anchor);
    if (!str)
	return NULL;
    url->href = str;
    if (!JS_AddNamedRoot(cx, &url->href, "url.href"))
	return NULL;

    if (anchor_data->target) {
	str = JS_NewStringCopyZ(cx, (char *) anchor_data->target);
	if (!str)
	    return NULL;
	url->target = str;
    }
    if (!JS_AddNamedRoot(cx, &url->target, "url.target"))
	return NULL;

    if (anchor_data->element && anchor_data->element->type == LO_TEXT) {
	str = lm_LocalEncodingToStr(decoder->window_context, 
		(char *) anchor_data->element->lo_text.text);
	if (!str)
	    return NULL;
	url->text = str;
    }
    if (!JS_AddNamedRoot(cx, &url->text, "url.text"))
	return NULL;

    return url;
}
Пример #23
0
JSObject*
gjs_init_class_dynamic(JSContext      *context,
                       JSObject       *in_object,
                       JSObject       *parent_proto,
                       const char     *ns_name,
                       const char     *class_name,
                       JSClass        *clasp,
                       JSNative        constructor,
                       uintN           nargs,
                       JSPropertySpec *ps,
                       JSFunctionSpec *fs,
                       JSPropertySpec *static_ps,
                       JSFunctionSpec *static_fs)
{
    jsval value;
    char *private_name;
    JSObject *prototype;
    JSContext *load_context;

    if (clasp->name != NULL) {
        g_warning("Dynamic class should not have a name in the JSClass struct");
        return NULL;
    }

    JS_BeginRequest(context);

    /* We replace the passed-in context and global object with our
     * runtime-global permanent load context. Otherwise, in a
     * process with multiple contexts, we'd arbitrarily define
     * the class in whatever global object initialized the
     * class first, which is not desirable.
     */
    load_context = gjs_runtime_get_load_context(JS_GetRuntime(context));
    JS_BeginRequest(load_context);

    /* JS_InitClass() wants to define the constructor in the global object, so
     * we give it a private and namespaced name... passing in the namespace
     * object instead of global object seems to break JS_ConstructObject()
     * which then can't find the constructor for the class. I am probably
     * missing something.
     */
    private_name = g_strdup_printf("_private_%s_%s", ns_name, class_name);

    prototype = NULL;
    if (gjs_object_get_property(load_context, JS_GetGlobalObject(load_context),
                                private_name, &value) &&
        JSVAL_IS_OBJECT(value)) {
        jsval proto_val;

        g_free(private_name); /* don't need it anymore */

        if (!gjs_object_require_property(load_context, JSVAL_TO_OBJECT(value), NULL,
                                         "prototype", &proto_val) ||
            !JSVAL_IS_OBJECT(proto_val)) {
            gjs_throw(load_context, "prototype was not defined or not an object?");
            goto error;
        }
        prototype = JSVAL_TO_OBJECT(proto_val);
    } else {
        DynamicJSClass *class_copy;
        RuntimeData *rd;

        rd = get_data_from_context(load_context);

        class_copy = g_slice_new0(DynamicJSClass);
        class_copy->base = *clasp;

        class_copy->base.name = private_name; /* Pass ownership of memory */
        class_copy->static_class = clasp;

        /* record the allocated class to be destroyed with the runtime and so
         * we can do an IS_DYNAMIC_CLASS check
         */
        g_hash_table_replace(rd->dynamic_classes,
                             class_copy, class_copy);

        gjs_debug(GJS_DEBUG_GREPO,
                  "Initializing dynamic class %s %p",
                  class_name, class_copy);

        prototype = JS_InitClass(load_context, JS_GetGlobalObject(load_context),
                                 parent_proto, &class_copy->base,
                                 constructor, nargs,
                                 ps, fs,
                                 static_ps, static_fs);

        /* Retrieve the property again so we can define it in
         * in_object
         */
        if (!gjs_object_require_property(load_context, JS_GetGlobalObject(load_context), NULL,
                                         class_copy->base.name, &value))
            goto error;
    }
    g_assert(value != JSVAL_VOID);
    g_assert(prototype != NULL);

    /* Now manually define our constructor with a sane name, in the
     * namespace object.
     */
    if (!JS_DefineProperty(load_context, in_object,
                           class_name,
                           value,
                           NULL, NULL,
                           GJS_MODULE_PROP_FLAGS))
        goto error;

    JS_EndRequest(load_context);
    JS_EndRequest(context);
    return prototype;

 error:
    /* Move the exception to the calling context from load context.
     */
    if (!gjs_move_exception(load_context, context)) {
        /* set an exception since none was set */
        gjs_throw(context, "No exception was set, but class initialize failed somehow");
    }

    JS_EndRequest(load_context);
    JS_EndRequest(context);
    return NULL;
}
Пример #24
0
void js_register_PluginAdColonyJS_PluginAdColony(JSContext *cx, JSObject *global) {
    jsb_sdkbox_PluginAdColony_class = (JSClass *)calloc(1, sizeof(JSClass));
    jsb_sdkbox_PluginAdColony_class->name = "PluginAdColony";
    jsb_sdkbox_PluginAdColony_class->addProperty = JS_PropertyStub;
    jsb_sdkbox_PluginAdColony_class->delProperty = JS_DeletePropertyStub;
    jsb_sdkbox_PluginAdColony_class->getProperty = JS_PropertyStub;
    jsb_sdkbox_PluginAdColony_class->setProperty = JS_StrictPropertyStub;
    jsb_sdkbox_PluginAdColony_class->enumerate = JS_EnumerateStub;
    jsb_sdkbox_PluginAdColony_class->resolve = JS_ResolveStub;
    jsb_sdkbox_PluginAdColony_class->convert = JS_ConvertStub;
    jsb_sdkbox_PluginAdColony_class->finalize = js_PluginAdColonyJS_PluginAdColony_finalize;
    jsb_sdkbox_PluginAdColony_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2);

    static JSPropertySpec properties[] = {
        {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER},
        {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER}
    };

    static JSFunctionSpec funcs[] = {
        JS_FS_END
    };

    static JSFunctionSpec st_funcs[] = {
        JS_FN("getVideosPerReward", js_PluginAdColonyJS_PluginAdColony_getVideosPerReward, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getCustomID", js_PluginAdColonyJS_PluginAdColony_getCustomID, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("zoneStatusForZone", js_PluginAdColonyJS_PluginAdColony_zoneStatusForZone, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("show", js_PluginAdColonyJS_PluginAdColony_show, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getStatus", js_PluginAdColonyJS_PluginAdColony_getStatus, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("videoAdCurrentlyRunning", js_PluginAdColonyJS_PluginAdColony_videoAdCurrentlyRunning, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("turnAllAdsOff", js_PluginAdColonyJS_PluginAdColony_turnAllAdsOff, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getVendorIdentifier", js_PluginAdColonyJS_PluginAdColony_getVendorIdentifier, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserMetadata", js_PluginAdColonyJS_PluginAdColony_setUserMetadata, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("init", js_PluginAdColonyJS_PluginAdColony_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getUniqueDeviceID", js_PluginAdColonyJS_PluginAdColony_getUniqueDeviceID, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getAdvertisingIdentifier", js_PluginAdColonyJS_PluginAdColony_getAdvertisingIdentifier, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("userInterestedIn", js_PluginAdColonyJS_PluginAdColony_userInterestedIn, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setCustomID", js_PluginAdColonyJS_PluginAdColony_setCustomID, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("notifyIAPComplete", js_PluginAdColonyJS_PluginAdColony_notifyIAPComplete, 5, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getVideoCreditBalance", js_PluginAdColonyJS_PluginAdColony_getVideoCreditBalance, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("cancelAd", js_PluginAdColonyJS_PluginAdColony_cancelAd, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FS_END
    };

    jsb_sdkbox_PluginAdColony_prototype = JS_InitClass(
        cx, global,
        NULL, // parent proto
        jsb_sdkbox_PluginAdColony_class,
        dummy_constructor<sdkbox::PluginAdColony>, 0, // no constructor
        properties,
        funcs,
        NULL, // no static properties
        st_funcs);
    // make the class enumerable in the registered namespace
//  bool found;
//FIXME: Removed in Firefox v27 
//  JS_SetPropertyAttributes(cx, global, "PluginAdColony", JSPROP_ENUMERATE | JSPROP_READONLY, &found);

    // add the proto and JSClass to the type->js info hash table
    TypeTest<sdkbox::PluginAdColony> t;
    js_type_class_t *p;
    std::string typeName = t.s_name();
    if (_js_global_type_map.find(typeName) == _js_global_type_map.end())
    {
        p = (js_type_class_t *)malloc(sizeof(js_type_class_t));
        p->jsclass = jsb_sdkbox_PluginAdColony_class;
        p->proto = jsb_sdkbox_PluginAdColony_prototype;
        p->parentProto = NULL;
        _js_global_type_map.insert(std::make_pair(typeName, p));
    }
}
void js_register_PluginFacebookJS_PluginFacebook(JSContext *cx, JSObject *global) {
    jsb_sdkbox_PluginFacebook_class = (JSClass *)calloc(1, sizeof(JSClass));
    jsb_sdkbox_PluginFacebook_class->name = "PluginFacebook";
    jsb_sdkbox_PluginFacebook_class->addProperty = JS_PropertyStub;
    jsb_sdkbox_PluginFacebook_class->delProperty = JS_DeletePropertyStub;
    jsb_sdkbox_PluginFacebook_class->getProperty = JS_PropertyStub;
    jsb_sdkbox_PluginFacebook_class->setProperty = JS_StrictPropertyStub;
    jsb_sdkbox_PluginFacebook_class->enumerate = JS_EnumerateStub;
    jsb_sdkbox_PluginFacebook_class->resolve = JS_ResolveStub;
    jsb_sdkbox_PluginFacebook_class->convert = JS_ConvertStub;
    jsb_sdkbox_PluginFacebook_class->finalize = js_PluginFacebookJS_PluginFacebook_finalize;
    jsb_sdkbox_PluginFacebook_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2);

    static JSPropertySpec properties[] = {
        {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER},
        {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER}
    };

    static JSFunctionSpec funcs[] = {
        JS_FS_END
    };

    static JSFunctionSpec st_funcs[] = {
        JS_FN("fetchFriends", js_PluginFacebookJS_PluginFacebook_fetchFriends, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getAccessToken", js_PluginFacebookJS_PluginFacebook_getAccessToken, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getUserID", js_PluginFacebookJS_PluginFacebook_getUserID, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("init", js_PluginFacebookJS_PluginFacebook_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("logout", js_PluginFacebookJS_PluginFacebook_logout, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("isLoggedIn", js_PluginFacebookJS_PluginFacebook_isLoggedIn, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("login", js_PluginFacebookJS_PluginFacebook_login, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getSDKVersion", js_PluginFacebookJS_PluginFacebook_getSDKVersion, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FS_END
    };

    jsb_sdkbox_PluginFacebook_prototype = JS_InitClass(
        cx, global,
        NULL, // parent proto
        jsb_sdkbox_PluginFacebook_class,
        dummy_constructor<sdkbox::PluginFacebook>, 0, // no constructor
        properties,
        funcs,
        NULL, // no static properties
        st_funcs);
    // make the class enumerable in the registered namespace
//  bool found;
//FIXME: Removed in Firefox v27 
//  JS_SetPropertyAttributes(cx, global, "PluginFacebook", JSPROP_ENUMERATE | JSPROP_READONLY, &found);

    // add the proto and JSClass to the type->js info hash table
    TypeTest<sdkbox::PluginFacebook> t;
    js_type_class_t *p;
    std::string typeName = t.s_name();
    if (_js_global_type_map.find(typeName) == _js_global_type_map.end())
    {
        p = (js_type_class_t *)malloc(sizeof(js_type_class_t));
        p->jsclass = jsb_sdkbox_PluginFacebook_class;
        p->proto = jsb_sdkbox_PluginFacebook_prototype;
        p->parentProto = NULL;
        _js_global_type_map.insert(std::make_pair(typeName, p));
    }
}
Пример #26
0
void js_register_PluginAdColonyJS_PluginAdColony(JSContext *cx, JSObject *global) {
    jsb_sdkbox_PluginAdColony_class = (JSClass *)calloc(1, sizeof(JSClass));
    jsb_sdkbox_PluginAdColony_class->name = "PluginAdColony";
    jsb_sdkbox_PluginAdColony_class->addProperty = JS_PropertyStub;
    jsb_sdkbox_PluginAdColony_class->delProperty = JS_PropertyStub;
    jsb_sdkbox_PluginAdColony_class->getProperty = JS_PropertyStub;
    jsb_sdkbox_PluginAdColony_class->setProperty = JS_StrictPropertyStub;
    jsb_sdkbox_PluginAdColony_class->enumerate = JS_EnumerateStub;
    jsb_sdkbox_PluginAdColony_class->resolve = JS_ResolveStub;
    jsb_sdkbox_PluginAdColony_class->convert = JS_ConvertStub;
    jsb_sdkbox_PluginAdColony_class->finalize = js_PluginAdColonyJS_PluginAdColony_finalize;
    jsb_sdkbox_PluginAdColony_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2);

    JSPropertySpec *properties = NULL;

    JSFunctionSpec *funcs = NULL;

    static JSFunctionSpec st_funcs[] = {
        JS_FN("getVideosPerReward", js_PluginAdColonyJS_PluginAdColony_getVideosPerReward, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getCustomID", js_PluginAdColonyJS_PluginAdColony_getCustomID, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("zoneStatusForZone", js_PluginAdColonyJS_PluginAdColony_zoneStatusForZone, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("show", js_PluginAdColonyJS_PluginAdColony_show, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getStatus", js_PluginAdColonyJS_PluginAdColony_getStatus, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("videoAdCurrentlyRunning", js_PluginAdColonyJS_PluginAdColony_videoAdCurrentlyRunning, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("turnAllAdsOff", js_PluginAdColonyJS_PluginAdColony_turnAllAdsOff, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getVendorIdentifier", js_PluginAdColonyJS_PluginAdColony_getVendorIdentifier, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setUserMetadata", js_PluginAdColonyJS_PluginAdColony_setUserMetadata, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("init", js_PluginAdColonyJS_PluginAdColony_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getUniqueDeviceID", js_PluginAdColonyJS_PluginAdColony_getUniqueDeviceID, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getAdvertisingIdentifier", js_PluginAdColonyJS_PluginAdColony_getAdvertisingIdentifier, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("userInterestedIn", js_PluginAdColonyJS_PluginAdColony_userInterestedIn, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setCustomID", js_PluginAdColonyJS_PluginAdColony_setCustomID, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("notifyIAPComplete", js_PluginAdColonyJS_PluginAdColony_notifyIAPComplete, 5, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getVideoCreditBalance", js_PluginAdColonyJS_PluginAdColony_getVideoCreditBalance, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("cancelAd", js_PluginAdColonyJS_PluginAdColony_cancelAd, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FS_END
    };

    jsb_sdkbox_PluginAdColony_prototype = JS_InitClass(
        cx, global,
        NULL, // parent proto
        jsb_sdkbox_PluginAdColony_class,
        dummy_constructor<sdkbox::PluginAdColony>, 0, // no constructor
        properties,
        funcs,
        NULL, // no static properties
        st_funcs);
    // make the class enumerable in the registered namespace
    JSBool found;
    JS_SetPropertyAttributes(cx, global, "PluginAdColony", JSPROP_ENUMERATE | JSPROP_READONLY, &found);

    // add the proto and JSClass to the type->js info hash table
    TypeTest<sdkbox::PluginAdColony> t;
    js_type_class_t *p;
    uint32_t typeId = t.s_id();
    HASH_FIND_INT(_js_global_type_ht, &typeId, p);
    if (!p) {
        p = (js_type_class_t *)malloc(sizeof(js_type_class_t));
        p->type = typeId;
        p->jsclass = jsb_sdkbox_PluginAdColony_class;
        p->proto = jsb_sdkbox_PluginAdColony_prototype;
        p->parentProto = NULL;
        HASH_ADD_INT(_js_global_type_ht, type, p);
    }
}
Пример #27
0
static JSObject*
importer_new(JSContext *context,
             gboolean   is_root)
{
    JSObject *importer;
    Importer *priv;
    JSObject *global;
    JSBool found;

    global = gjs_get_import_global(context);

    if (!JS_HasProperty(context, global, gjs_importer_class.name, &found))
        g_error("HasProperty call failed creating importer class");

    if (!found) {
        JSObject *prototype;
        prototype = JS_InitClass(context, global,
                                 /* parent prototype JSObject* for
                                  * prototype; NULL for
                                  * Object.prototype
                                  */
                                 NULL,
                                 &gjs_importer_class,
                                 /* constructor for instances (NULL for
                                  * none - just name the prototype like
                                  * Math - rarely correct)
                                  */
                                 gjs_importer_constructor,
                                 /* number of constructor args */
                                 0,
                                 /* props of prototype */
                                 &gjs_importer_proto_props[0],
                                 /* funcs of prototype */
                                 &gjs_importer_proto_funcs[0],
                                 /* props of constructor, MyConstructor.myprop */
                                 NULL,
                                 /* funcs of constructor, MyConstructor.myfunc() */
                                 NULL);
        if (prototype == NULL)
            g_error("Can't init class %s", gjs_importer_class.name);

        gjs_debug(GJS_DEBUG_IMPORTER, "Initialized class %s prototype %p",
                  gjs_importer_class.name, prototype);
    }

    importer = JS_NewObject(context, &gjs_importer_class, NULL, global);
    if (importer == NULL)
        g_error("No memory to create importer importer");

    priv = g_slice_new0(Importer);
    priv->is_root = is_root;

    GJS_INC_COUNTER(importer);

    g_assert(priv_from_js(context, importer) == NULL);
    JS_SetPrivate(importer, priv);

    gjs_debug_lifecycle(GJS_DEBUG_IMPORTER,
                        "importer constructor, obj %p priv %p", importer, priv);

    return importer;
}
Пример #28
0
void CG_JS_Vector_Init(JSContext *ctx, JSObject *global)
{
	JS_InitClass(ctx, global, NULL, &vector3_class, vector3_constructor, 3, NULL, NULL, NULL, NULL);  
	JS_InitClass(ctx, global, NULL, &vector4_class, vector4_constructor, 4, NULL, NULL, NULL, NULL);  
}
Пример #29
0
static JSObject *
gjs_keep_alive_new(JSContext *context)
{
    KeepAlive *priv;
    bool found;

    /* This function creates an unattached KeepAlive object; following our
     * general strategy, we have a single KeepAlive class with a constructor
     * stored on our single "load global" pseudo-global object, and we create
     * instances with the load global as parent.
     */

    g_assert(context != NULL);

    JSAutoRequest ar(context);

    JS::RootedObject global(context, gjs_get_import_global(context));

    g_assert(global != NULL);

    if (!JS_HasProperty(context, global, gjs_keep_alive_class.name, &found))
        return NULL;

    if (!found) {
        JSObject *prototype;

        gjs_debug(GJS_DEBUG_KEEP_ALIVE,
                  "Initializing keep-alive class in context %p global %p",
                  context, global.get());

        prototype = JS_InitClass(context, global,
                                 /* parent prototype JSObject* for
                                  * prototype; NULL for
                                  * Object.prototype
                                  */
                                 JS::NullPtr(),
                                 &gjs_keep_alive_class,
                                 /* constructor for instances (NULL for
                                  * none - just name the prototype like
                                  * Math - rarely correct)
                                  */
                                 gjs_keep_alive_constructor,
                                 /* number of constructor args */
                                 0,
                                 /* props of prototype */
                                 &gjs_keep_alive_proto_props[0],
                                 /* funcs of prototype */
                                 &gjs_keep_alive_proto_funcs[0],
                                 /* props of constructor, MyConstructor.myprop */
                                 NULL,
                                 /* funcs of constructor, MyConstructor.myfunc() */
                                 NULL);
        if (prototype == NULL)
            g_error("Can't init class %s", gjs_keep_alive_class.name);

        gjs_debug(GJS_DEBUG_KEEP_ALIVE, "Initialized class %s prototype %p",
                  gjs_keep_alive_class.name, prototype);
    }

    gjs_debug(GJS_DEBUG_KEEP_ALIVE,
              "Creating new keep-alive object for context %p global %p",
              context, global.get());

    JS::RootedObject keep_alive(context,
        JS_NewObject(context, &gjs_keep_alive_class, JS::NullPtr(), global));
    if (keep_alive == NULL) {
        gjs_log_exception(context);
        g_error("Failed to create keep_alive object");
    }

    priv = g_slice_new0(KeepAlive);
    priv->children = g_hash_table_new_full(child_hash, child_equal, NULL, child_free);

    g_assert(priv_from_js(context, keep_alive) == NULL);
    JS_SetPrivate(keep_alive, priv);

    gjs_debug_lifecycle(GJS_DEBUG_KEEP_ALIVE,
                        "keep_alive constructor, obj %p priv %p",
                        keep_alive.get(), priv);

    return keep_alive;
}
void js_register_PluginChartboostJS_PluginChartboost(JSContext *cx, JSObject *global) {
    jsb_sdkbox_PluginChartboost_class = (JSClass *)calloc(1, sizeof(JSClass));
    jsb_sdkbox_PluginChartboost_class->name = "PluginChartboost";
    jsb_sdkbox_PluginChartboost_class->addProperty = JS_PropertyStub;
    jsb_sdkbox_PluginChartboost_class->delProperty = JS_PropertyStub;
    jsb_sdkbox_PluginChartboost_class->getProperty = JS_PropertyStub;
    jsb_sdkbox_PluginChartboost_class->setProperty = JS_StrictPropertyStub;
    jsb_sdkbox_PluginChartboost_class->enumerate = JS_EnumerateStub;
    jsb_sdkbox_PluginChartboost_class->resolve = JS_ResolveStub;
    jsb_sdkbox_PluginChartboost_class->convert = JS_ConvertStub;
    jsb_sdkbox_PluginChartboost_class->finalize = js_PluginChartboostJS_PluginChartboost_finalize;
    jsb_sdkbox_PluginChartboost_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2);

    JSPropertySpec *properties = NULL;

    JSFunctionSpec *funcs = NULL;

    static JSFunctionSpec st_funcs[] = {
        JS_FN("handleOpenURL", js_PluginChartboostJS_PluginChartboost_handleOpenURL, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setAutoCacheAds", js_PluginChartboostJS_PluginChartboost_setAutoCacheAds, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setStatusBarBehavior", js_PluginChartboostJS_PluginChartboost_setStatusBarBehavior, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("isAnyViewVisible", js_PluginChartboostJS_PluginChartboost_isAnyViewVisible, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getCustomID", js_PluginChartboostJS_PluginChartboost_getCustomID, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("show", js_PluginChartboostJS_PluginChartboost_show, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("cache", js_PluginChartboostJS_PluginChartboost_cache, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setShouldDisplayLoadingViewForMoreApps", js_PluginChartboostJS_PluginChartboost_setShouldDisplayLoadingViewForMoreApps, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setShouldRequestInterstitialsInFirstSession", js_PluginChartboostJS_PluginChartboost_setShouldRequestInterstitialsInFirstSession, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("didPassAgeGate", js_PluginChartboostJS_PluginChartboost_didPassAgeGate, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setShouldPrefetchVideoContent", js_PluginChartboostJS_PluginChartboost_setShouldPrefetchVideoContent, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("init", js_PluginChartboostJS_PluginChartboost_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("getAutoCacheAds", js_PluginChartboostJS_PluginChartboost_getAutoCacheAds, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("closeImpression", js_PluginChartboostJS_PluginChartboost_closeImpression, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setCustomID", js_PluginChartboostJS_PluginChartboost_setCustomID, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("isAvailable", js_PluginChartboostJS_PluginChartboost_isAvailable, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("setShouldPauseClickForConfirmation", js_PluginChartboostJS_PluginChartboost_setShouldPauseClickForConfirmation, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FS_END
    };

    jsb_sdkbox_PluginChartboost_prototype = JS_InitClass(
            cx, global,
            NULL, // parent proto
            jsb_sdkbox_PluginChartboost_class,
            dummy_constructor<sdkbox::PluginChartboost>, 0, // no constructor
            properties,
            funcs,
            NULL, // no static properties
            st_funcs);
    // make the class enumerable in the registered namespace
    JSBool found;
    JS_SetPropertyAttributes(cx, global, "PluginChartboost", JSPROP_ENUMERATE | JSPROP_READONLY, &found);

    // add the proto and JSClass to the type->js info hash table
    TypeTest<sdkbox::PluginChartboost> t;
    js_type_class_t *p;
    uint32_t typeId = t.s_id();
    HASH_FIND_INT(_js_global_type_ht, &typeId, p);
    if (!p) {
        p = (js_type_class_t *)malloc(sizeof(js_type_class_t));
        p->type = typeId;
        p->jsclass = jsb_sdkbox_PluginChartboost_class;
        p->proto = jsb_sdkbox_PluginChartboost_prototype;
        p->parentProto = NULL;
        HASH_ADD_INT(_js_global_type_ht, type, p);
    }
}