void webInit(JSContext *cx){ curl_global_init(CURL_GLOBAL_DEFAULT); curlHandle = curl_multi_init(); if(!curlHandle){ fprint(stderr,"Unable to start curl\n"); exit(EXIT_FAILURE); } JSObject* object = NULL; object = JS_DefineObject(cx, JS_GetGlobalObject(cx),"web", NULL, NULL,0); if(object) { static JSFunctionSpec webFuncSpec[5]= { JS_FS("getRq", webGetRq,0,0), JS_FS("postRq", webPostRq,0,0), JS_FS("launchBrowser",webLaunchBrowser,0,0), JS_FS("monsterHash",webMonsterHash,0,0), JS_FS_END }; if(!JS_DefineFunctions(cx, object, webFuncSpec)) fprint(stderr,"Unable to create web object\n"); print("loaded module web\n"); } else { fprint(stderr,"Problem creating web object, perhaps oom\n EXITING\n"); exit(EXIT_FAILURE); } }
void initLine(JSContext *cx){ static JSFunctionSpec lineFuncSpec[3]= { JS_FS("drawLines", drawLines,0,0), JS_FS("addPoint",addPoint,0,0), JS_FS_END }; JS_InitClass(cx, JS_GetGlobalObject(cx), NULL , &lineList, constructorLL, 1, NULL , lineFuncSpec,NULL,NULL); }
void utilInit(JSContext *cx){ JSObject* object = NULL; object = JS_DefineObject(cx, JS_GetGlobalObject(cx),"util", NULL, NULL,0); if(object) { static const JSFunctionSpec utilFuncSpec[2] = { JS_FS("forceGC", utilForceGC,0,0), JS_FS_END }; if(!JS_DefineFunctions(cx, object, utilFuncSpec)) fprint(stderr,"Unable to create util object\n"); //print("loaded module util\n"); } else { fprint(stderr,"Problem creating util object, perhaps oom\n EXITING\n"); exit(EXIT_FAILURE); } }
//--------------------------------------------------- // Exposing the functionality //--------------------------------------------------- JSBool init(JSContext* cx, JSObject* scope) { JSFunctionSpec functions[] = { // VOID FUNCTION, 1 PARAMETER JS_FS("void_param0_constCharPtr", void_param0_constCharPtr_wrap, 1, 0), JS_FS("void_param0_stdString", void_param0_stdString_wrap, 1, 0), JS_FS("void_param0_constStdStringRef", void_param0_constStdStringRef_wrap, 1, 0), // RETURN VALUE, NO PARAMETER JS_FS("constCharPtr_param0", constCharPtr_param0_wrap, 0, 0), JS_FS("stdString_param0", stdString_param0_wrap, 0, 0), JS_FS("constStdStringRef_param0", constStdStringRef_param0_wrap, 0, 0), JS_FS("constStdStringPtr_param0", constStdStringPtr_param0_wrap, 0, 0), JS_FS_END }; if(!JS_DefineFunctions(cx, scope, functions)) return false; return true; }
ji->ji_root, NULL, 0, 0, year, season, episode, 0); rstr_release(imdb); rstr_release(title); *rval = JSVAL_VOID; return JS_TRUE; } /** * */ static JSFunctionSpec item_proto_functions[] = { JS_FS("onEvent", js_item_onEvent, 2, 0, 0), JS_FS("destroy", js_item_destroy, 0, 0, 0), JS_FS("addOptURL", js_item_addOptURL, 2, 0, 0), JS_FS("addOptAction", js_item_addOptAction, 2, 0, 0), JS_FS("addOptSeparator", js_item_addOptSeparator, 1, 0, 0), JS_FS("dump", js_item_dump, 0, 0, 0), JS_FS("enable", js_item_enable, 0, 0, 0), JS_FS("disable", js_item_disable, 0, 0, 0), JS_FS("moveBefore", js_item_moveBefore, 1, 0, 0), JS_FS("bindVideoMetadata", js_item_bindVideoMetadata, 1, 0, 0), JS_FS_END }; /** *
//////////////////////////////////////////////////////////////////////////////// // Class: http // Description: Manages HTTP state //////////////////////////////////////////////////////////////////////////////// // Section: Global variables struct unit_ext m_http_ext = { .load = m_http_load, .post = m_http_post, .unload = m_http_unload, }; static JSFunctionSpec m_http_functions[] = { JS_FS("header", m_http_header, 1, 0), JS_FS("setcookie", m_http_setcookie, 1, 0), JS_FS("session", m_http_session, 0, 0), JS_FS_END }; //////////////////////////////////////////////////////////////////////////////// // Section: Interface JSBool m_http_load(unit_t n) { if (!JS_DefineFunctions(n->context, n->global, m_http_functions)) return JS_FALSE; return JS_TRUE; } JSBool m_http_post(unit_t n) {
#include <string.h> #include <errno.h> // lib includes #include <jsapi.h> // local includes #include "../../pistonmonkey.h" #include "../../jsutil.h" #include "../../memutil.h" #include "File.h" // local globals static JSFunctionSpec File_functions[] = { JS_FS("exists", File_function_exists, 0, 0, 0), JS_FS("isFile", File_function_isFile, 0, 0, 0), JS_FS("isDirectory", File_function_isDirectory, 0, 0, 0), JS_FS("readAll", File_function_readAll, 0, 0, 0), JS_FS("size", File_function_size, 0, 0, 0), JS_FS_END }; static JSFunctionSpec File_functions_static[] = { JS_FS("exists", File_function_exists_static, 0, 0, 0), JS_FS("isFile", File_function_isFile_static, 0, 0, 0), JS_FS("isDirectory", File_function_isDirectory_static, 0, 0, 0), JS_FS("readAll", File_function_readAll_static, 0, 0, 0), JS_FS("size", File_function_size_static, 0, 0, 0), JS_FS_END
switch (rpmaugPrint(aug, NULL, _path)) { case 0: /* success */ *rval = JSVAL_TRUE; break; default: case -1: /* failure */ *rval = JSVAL_FALSE; break; } ok = JS_TRUE; exit: return ok; } static JSFunctionSpec rpmaug_funcs[] = { JS_FS("defvar", rpmaug_defvar, 0,0), JS_FS("get", rpmaug_get, 0,0), JS_FS("set", rpmaug_set, 0,0), JS_FS("insert", rpmaug_insert, 0,0), JS_FS("rm", rpmaug_rm, 0,0), JS_FS("remove", rpmaug_rm, 0,0), JS_FS("mv", rpmaug_mv, 0,0), JS_FS("move", rpmaug_mv, 0,0), JS_FS("match", rpmaug_match, 0,0), JS_FS("save", rpmaug_save, 0,0), JS_FS("load", rpmaug_load, 0,0), JS_FS("print", rpmaug_print, 0,0), JS_FS_END }; /* --- Object properties */
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, req_dtor, JSCLASS_NO_OPTIONAL_MEMBERS }; JSPropertySpec CouchHTTPProperties[] = { {"status", 0, JSPROP_READONLY, req_status, NULL}, {0, 0, 0, 0, 0} }; JSFunctionSpec CouchHTTPFunctions[] = { JS_FS("_open", (JSNative) req_open, 3, JSFUN_FAST_NATIVE, 0), JS_FS("_setRequestHeader", (JSNative) req_set_hdr, 2, JSFUN_FAST_NATIVE, 0), JS_FS("_send", (JSNative) req_send, 1, JSFUN_FAST_NATIVE, 0), JS_FS_END }; static JSClass global_class = { "GlobalClass", JSCLASS_GLOBAL_FLAGS, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_EnumerateStub, JS_ResolveStub,
{"SYSLOG_LOCAL7", LOG_LOCAL7}, #if 0 // syslog priorities {"SYSLOG_EMERG", LOG_EMERG}, {"SYSLOG_ALERT", LOG_ALERT}, {"SYSLOG_CRIT", LOG_CRIT}, {"SYSLOG_ERR", LOG_ERR}, {"SYSLOG_WARNING", LOG_WARNING}, {"SYSLOG_NOTICE", LOG_NOTICE}, {"SYSLOG_INFO", LOG_INFO}, {"SYSLOG_DEBUG", LOG_DEBUG}, #endif }; static JSFunctionSpec Sys_functions[] = { JS_FS("openlog", Sys_openlog, 2, 0), JS_FS("loadModule", Sys_loadModule, 1, 0), JS_FS_END }; JSBool js_sys_init(JSContext *cx, JSObject *global) { JSObject *sys; unsigned i; sys = JS_DefineObject(cx, global, Sys_class.name, &Sys_class, NULL, 0); if (!sys) return JS_FALSE; if (!JS_DefineFunctions(cx, sys, Sys_functions)) return JS_FALSE;
GET_PRIVATE(ch); return JS_TRUE; } JSPropertySpec ngx_http_js__nginx_chain__props[] = { // {"uri", REQUEST_URI, JSPROP_READONLY, NULL, NULL}, {0, 0, 0, NULL, NULL} }; JSFunctionSpec ngx_http_js__nginx_chain__funcs[] = { JS_FS("toString", method_toString, 0, 0, 0), JS_FS_END }; JSClass ngx_http_js__nginx_chain__class = { "Chain", JSCLASS_HAS_PRIVATE | JSCLASS_HAS_RESERVED_SLOTS(NGX_JS_CHAIN_SLOTS_COUNT), JS_PropertyStub, JS_PropertyStub, getProperty, setProperty, JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub, JSCLASS_NO_OPTIONAL_MEMBERS }; JSBool ngx_http_js__nginx_chain__init(JSContext *cx, JSObject *global) {
*rval = JSVAL_FALSE; { int ret = mpf->sync(mpf); if (ret) fprintf(stderr, "DB_MPOOLFILE->sync: %s\n", db_strerror(ret)); *rval = (!ret ? JSVAL_TRUE : JSVAL_FALSE); } ok = JS_TRUE; exit: return ok; } static JSFunctionSpec rpmmpf_funcs[] = { JS_FS("close", rpmmpf_Close, 0,0,0), JS_FS("get", rpmmpf_Get, 0,0,0), JS_FS("open", rpmmpf_Open, 0,0,0), JS_FS("put", rpmmpf_Put, 0,0,0), JS_FS("sync", rpmmpf_Sync, 0,0,0), JS_FS_END }; /* --- Object properties */ #define _TABLE(_v) #_v, _##_v, JSPROP_ENUMERATE, NULL, NULL enum rpmmpf_tinyid { _DEBUG = -2, _CLEARLEN = -3, _FILEID = -4,
jsval *argv = JS_ARGV(cx, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); void * ptr = JS_GetInstancePrivate(cx, obj, &rpmpsClass, NULL); rpmps ps = ptr; JSBool ok = JS_FALSE; _METHOD_DEBUG_ENTRY(_debug); rpmpsPrint(NULL, ps); ok = JS_TRUE; return ok; } static JSFunctionSpec rpmps_funcs[] = { JS_FS("push", rpmps_push, 0,0), JS_FS("print", rpmps_print, 0,0), JS_FS_END }; /* --- Object properties */ enum rpmps_tinyid { _DEBUG = -2, _LENGTH = -3, }; static JSPropertySpec rpmps_props[] = { {"debug", _DEBUG, JSPROP_ENUMERATE, NULL, NULL}, {"length", _LENGTH, JSPROP_ENUMERATE, NULL, NULL}, {NULL, 0, 0, NULL, NULL} };
return JS_TRUE; } JSBool BackdropGetColorFunc(JSContext *cx, unsigned argc, jsval *vp) { uint8_t r, g, b; backdrop_get_color(&r, &g, &b); JSObject *list = JS_NewArrayObject(cx, 3, NULL); if (list) { JS::Value val; val = INT_TO_JSVAL(red); JS_SetElement(cx, list, 0, &val); val = INT_TO_JSVAL(green); JS_SetElement(cx, list, 1, &val); val = INT_TO_JSVAL(blue); JS_SetElement(cx, list, 2, &val); JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(list)); return JS_TRUE; } return JS_FALSE; } JSFunctionSpec backdrop_functions[3] = { JS_FS("backdropGetColor", BackdropGetColorFunc, 0, 0), JS_FS("backdropSetColor", BackdropSetColorFunc, 3, 0), JS_FS_END };
return DOUBLE_TO_JSVAL(d); break; case HMF_DBL: if((d = JS_NewDouble(cx, f->hmf_dbl)) != NULL) return DOUBLE_TO_JSVAL(d); break; } return JSVAL_NULL; } /** * */ static JSFunctionSpec setting_functions[] = { JS_FS("createBool", js_createBool, 4, 0, 0), JS_FS("createString", js_createString, 4, 0, 0), JS_FS("createMultiOpt", js_createMultiOpt, 5, 0, 0), JS_FS("createInfo", js_createInfo, 3, 0, 0), JS_FS("createDivider", js_createDivider, 1, 0, 0), JS_FS("createInt", js_createInt, 8, 0, 0), JS_FS("createAction", js_createAction, 2, 0, 0), JS_FS("destroy", js_destroy, 0, 0, 0), JS_FS_END }; /** *
syck_emitter_flush(emitter, 0); #ifdef NOTYET luaL_pushresult(&bonus->output); #endif ok = JS_TRUE; exit: bonus->iob = rpmiobFree(bonus->iob); syck_free_emitter(emitter); return ok; } static JSFunctionSpec syck_funcs[] = { JS_FS("load", syck_load, 0,0,0), JS_FS("dump", syck_dump, 0,0,0), JS_FS_END }; /* --- Object properties */ enum syck_tinyid { _DEBUG = -2, }; static JSPropertySpec syck_props[] = { {"debug", _DEBUG, JSPROP_ENUMERATE, NULL, NULL}, {NULL, 0, 0, NULL, NULL} }; static JSBool
JSBool ok = JS_FALSE; _METHOD_DEBUG_ENTRY(_debug); if (!(ok = JS_ConvertArguments(cx, argc, argv, "s", &s))) goto exit; (void) headerSetOrigin(h, s); JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(JS_NewStringCopyZ(cx, headerGetOrigin(h)))); ok = JS_TRUE; exit: return ok; } static JSFunctionSpec rpmhdr_funcs[] = { JS_FS("ds", rpmhdr_ds, 0,0), JS_FS("fi", rpmhdr_fi, 0,0), JS_FS("sprintf", rpmhdr_sprintf, 0,0), JS_FS("getorigin", rpmhdr_getorigin, 0,0), JS_FS("setorigin", rpmhdr_setorigin, 0,0), JS_FS_END }; /* --- Object properties */ enum rpmhdr_tinyid { _DEBUG = -2, }; static JSPropertySpec rpmhdr_props[] = { {"debug", _DEBUG, JSPROP_ENUMERATE, NULL, NULL}, {NULL, 0, 0, NULL, NULL}
} SDL_Quit(); return 0; } JSBool JS_SetPixel(JSContext *cx, uintN argc, jsval *vp) { uint32 x, y, r, g, b; if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "uuuuu", &x, &y, &r, &g, &b)) return JS_FALSE; JS_SET_RVAL(cx, vp, JSVAL_VOID); return JS_TRUE; } static JSFunctionSpec stageFunctions[] = { JS_FS("setPixel", JS_SetPixel, 5, 0), JS_FS_END }; int Stage::Initialize() { if (!JS_DefineFunctions(cx, global, stageFunctions)) { return JS_FALSE; } return JS_TRUE; } void Stage::Blit(char *dst, const char *src, size_t size) { for (int y = 0; y < size / screen->pitch; y++) { int start = y * screen->pitch;
return JS_FALSE; jsrefcount s = JS_SuspendRequest(cx); usleep(msec * 1000); JS_ResumeRequest(cx, s); *rval = JSVAL_VOID; return JS_TRUE; } /** * */ static JSFunctionSpec showtime_functions[] = { JS_FS("trace", js_trace, 1, 0, 0), JS_FS("print", js_print, 1, 0, 0), JS_FS("httpGet", js_httpGet, 2, 0, 0), JS_FS("httpPost", js_httpPost, 2, 0, 0), JS_FS("readFile", js_readFile, 1, 0, 0), JS_FS("queryStringSplit", js_queryStringSplit, 1, 0, 0), JS_FS("httpEscape", js_httpEscape, 1, 0, 0), JS_FS("createService", js_createService, 4, 0, 0), JS_FS("canHandle", js_canHandle, 1, 0, 0), JS_FS("getAuthCredentials", js_getAuthCredentials, 4, 0, 0), JS_FS("message", js_message, 3, 0, 0), JS_FS("sleep", js_sleep, 1, 0, 0), JS_FS("JSONEncode", js_json_encode, 1, 0, 0), JS_FS("JSONDecode", js_json_decode, 1, 0, 0), JS_FS_END };
if (dc == NULL) goto exit; (void) rpmDigestFinal(dc, &s, &ns, 1); *rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, s)); (void) JS_SetPrivate(cx, obj, (void *)NULL); ok = JS_TRUE; exit: s = _free(s); return ok; } static JSFunctionSpec rpmdc_funcs[] = { JS_FS("init", rpmdc_Init, 0,0,0), JS_FS("update", rpmdc_Update, 0,0,0), JS_FS("fini", rpmdc_Fini, 0,0,0), JS_FS_END }; /* --- Object properties */ enum rpmdc_tinyid { _DEBUG = -2, _ALGO = -3, _ASN1 = -4, _NAME = -5, }; static JSPropertySpec rpmdc_props[] = { {"debug", _DEBUG, JSPROP_ENUMERATE, NULL, NULL},
_METHOD_DEBUG_ENTRY(_debug); *vp = JSVAL_FALSE; if (!(ok = JS_ConvertArguments(cx, argc, argv, "o", &o)) || (_b = JS_GetInstancePrivate(cx, o, &rpmbfClass, NULL)) == NULL) goto exit; if (!rpmbfUnion(_a, _b)) *vp = JSVAL_TRUE; ok = JS_TRUE; exit: return ok; } static JSFunctionSpec rpmbf_funcs[] = { JS_FS("add", rpmbf_add, 0,0), JS_FS("chk", rpmbf_chk, 0,0), JS_FS("clr", rpmbf_clr, 0,0), JS_FS("del", rpmbf_del, 0,0), JS_FS("intersect", rpmbf_intersect, 0,0), JS_FS("union", rpmbf_union, 0,0), JS_FS_END }; /* --- Object properties */ enum rpmbf_tinyid { _DEBUG = -2, _LENGTH = -3, }; static JSPropertySpec rpmbf_props[] = {
} rv = xpc->GetCOWForObject(cx, JS_GetParent(cx, object), object, rval); if (NS_FAILED(rv)) { JS_ReportError(cx, "nsIXPConnect->GetCOWForObject() failed"); return JS_FALSE; } return JS_TRUE; } #endif static JSFunctionSpec endpointFunctions[] = { JS_FS("wrap", wrapObject, 2, JSPROP_ENUMERATE, 0), JS_FS("unwrap", unwrapObject, 1, JSPROP_ENUMERATE, 0), JS_FS("unwrapAny", unwrapAnyObject, 1, JSPROP_ENUMERATE, 0), JS_FS("getWrapper", getWrapper, 1, JSPROP_ENUMERATE, 0), JS_FS("profileMemory", profileMemory, 1, JSPROP_ENUMERATE, 0), JS_FS("enumerate", TCB_enumerate, 1, JSPROP_ENUMERATE, 0), JS_FS("functionInfo", TCB_functionInfo, 1, JSPROP_ENUMERATE, 0), JS_FS("seal", TCB_seal, 1, JSPROP_ENUMERATE, 0), JS_FS("getClassName", TCB_getClassName, 1, JSPROP_ENUMERATE, 0), #ifdef USE_COWS JS_FS("makeCOW", makeCOW, 1, JSPROP_ENUMERATE, 0), #endif JS_FS_END }; nsJetpack::nsJetpack()
} static JSClass global_class = {"global", JSCLASS_NEW_RESOLVE | JSCLASS_GLOBAL_FLAGS, JS_PropertyStub, JS_DeletePropertyStub, JS_PropertyStub, JS_StrictPropertyStub, JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, nullptr, JSCLASS_NO_OPTIONAL_MEMBERS }; static JSFunctionSpec global_functions[]={ JS_FS("echo", Runtime::echo,1,0), JS_FS("logVersion", Runtime::version,0,0), JS_FS_END }; void reportError(JSContext *cx, const char *message, JSErrorReport *report) { fprintf(stderr, "%s:%u:%s\n", report->filename ? report->filename : "[no filename]", (unsigned int) report->lineno, message); } int run(JSContext *cx) { /* Enter a request before running anything in the context */ JSAutoRequest ar(cx); /* Create the global object in a new compartment. */
js::EnableRuntimeProfilingStack(cx->runtime(), false); return true; } static bool Prof(JSContext* cx, unsigned argc, jsval *vp) { JSObject *obj = JS_NewObjectForConstructor(cx, &ptestClass, vp); if (!obj) return false; JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); return true; } static const JSFunctionSpec ptestFunctions[] = { JS_FS("test_fn", test_fn, 0, 0), JS_FS("test_fn2", test_fn2, 0, 0), JS_FS("enable", enable, 0, 0), JS_FS("disable", disable, 0, 0), JS_FS_END }; static JSObject* initialize(JSContext *cx) { js::SetRuntimeProfilingStack(cx->runtime(), pstack, &psize, 10); JS::RootedObject global(cx, JS::CurrentGlobalOrNull(cx)); return JS_InitClass(cx, global, nullptr, &ptestClass, Prof, 0, nullptr, ptestFunctions, nullptr, nullptr); }
nsDependentJSString message; if (!message.init(cx, arg1)) return false; nsString alertMessage; alertMessage.SetCapacity(32 + message.Length()); alertMessage += NS_LITERAL_STRING("PAC-alert: "); alertMessage += message; PACLogToConsole(alertMessage); args.rval().setUndefined(); /* return undefined */ return true; } static const JSFunctionSpec PACGlobalFunctions[] = { JS_FS("dnsResolve", PACDnsResolve, 1, 0), JS_FS("myIpAddress", PACMyIpAddress, 0, 0), JS_FS("alert", PACProxyAlert, 1, 0), JS_FS_END }; // JSRuntimeWrapper is a c++ object that manages the runtime and context // for the JS engine used on the PAC thread. It is initialized and destroyed // on the PAC thread. class JSRuntimeWrapper { public: static JSRuntimeWrapper *Create() { JSRuntimeWrapper *entry = new JSRuntimeWrapper();
JSBool calendarDateChanged(JSContext *cx, uint32_t argc, jsval *vp) { jsval *argv = JS_ARGV(cx, vp); jsval yearJSV = argv[0]; jsval monthJSV = argv[1]; jsval dayJSV = argv[2]; int year = JSVAL_TO_INT(yearJSV); int month = JSVAL_TO_INT(monthJSV); int day = JSVAL_TO_INT(dayJSV); c_addLogToCLI(1, "[C++] calendarDateChanged delegate called in C++"); c_addLogToCLI(1, "[C++] calendarDateChanged Y/%d M/%d D/%d", year, month, day); JS_SET_RVAL(cx, vp, JSVAL_NULL); return JS_TRUE; } static JSFunctionSpec myjs_global_functions[] = { JS_FS("js_addLogToCLI", js_addLogToCLI, 2, 0), JS_FS("calendarDateChanged", calendarDateChanged, 3, 0), JS_FS_END }; /* test list */ #define TESTS_COUNT 10 const std::string g_aTestNames[TESTS_COUNT] = { "1. SpiderMonkey Init", "2. call JS function - 0 param, 0 return", "3. call JS function - 1 param(Basic Type) , 1 return(Basic Type)", "4. call JS function - 0 param , 1 return(cocos2d Object)", "5. call JS function - 1 param(cocos2d Object) , 0 return",
{ JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject* obj = JS_NewObjectForConstructor(cx, &ptestClass, args); if (!obj) return false; args.rval().setObject(*obj); return true; } static bool test_fn(JSContext* cx, unsigned argc, jsval* vp) { called_test_fn++; return true; } static const JSFunctionSpec ptestFunctions[] = { JS_FS( "test_fn", test_fn, 0, 0 ), JS_FS_END }; BEGIN_TEST(testClassGetter_isCalled) { CHECK(JS_InitClass(cx, global, js::NullPtr(), &ptestClass, PTest, 0, nullptr, ptestFunctions, nullptr, nullptr)); EXEC("function check() { var o = new PTest(); o.test_fn(); o.test_value1; o.test_value2; o.test_value1; }"); for (int i = 1; i < 9; i++) { JS::RootedValue rval(cx); CHECK(JS_CallFunctionName(cx, global, "check", JS::HandleValueArray::empty(), &rval)); CHECK_SAME(INT_TO_JSVAL(called_test_fn), INT_TO_JSVAL(i));
} else if ( !strcmp( propertyName, "h" ) ) { target->h=value.toInt32(); } else if ( !strcmp( propertyName, "autoResize" ) ) { target->autoResize=value.toBoolean(); } else if ( !strcmp( propertyName, "main" ) ) { target->main=value.toBoolean(); } return true; } static JSFunctionSpec rendertarget_functions[] = { JS_FS( "create", RenderTarget_create, 0, 0 ), JS_FS( "destroy", RenderTarget_destroy, 0, 0 ), JS_FS( "dispose", RenderTarget_dispose, 0, 0 ), JS_FS( "unbind", RenderTarget_unbind, 0, 0 ), JS_FS( "bind", RenderTarget_bind, 0, 0 ), JS_FS( "bindAsTexture", RenderTarget_bindAsTexture, 0, 0 ), JS_FS( "resize", RenderTarget_resize, 0, 0 ), JS_FS( "setViewport", RenderTarget_setViewport, 0, 0 ), JS_FS( "setScissor", RenderTarget_setScissor, 0, 0 ), JS_FS( "clear", RenderTarget_clear, 0, 0 ), JS_FS_END }; // ---------------------------------------------------------------
{"t_tkey", ns_t_tkey}, {"t_tsig", ns_t_tsig}, {"t_ixfr", ns_t_ixfr}, {"t_axfr", ns_t_axfr}, {"t_mailb", ns_t_mailb}, {"t_maila", ns_t_maila}, {"t_any", ns_t_any}, {"t_uri", ns_t_uri}, {"t_caa", ns_t_caa}, {"t_avc", ns_t_avc}, {"t_ta", ns_t_ta}, {"t_dlv", ns_t_dlv}, }; static JSFunctionSpec Dns_functions[] = { JS_FS("revAddr", Dns_revAddr, 2, 0), JS_FS("query", Dns_query, 2, 0), JS_FS_END }; JSBool js_dns_init(JSContext *cx, JSObject *global) { JSObject *dns; unsigned i; dns = JS_DefineObject(cx, global, Dns_class.name, &Dns_class, NULL, 0); if (!dns) return JS_FALSE; if (!JS_DefineFunctions(cx, dns, Dns_functions))
/* Throw a JavaScript exception. */ JS_ReportError(cx, "new_space: couldn't parse out grav args"); return JS_FALSE; } cpSpace* space = sugs::physics::createChipmunkSpaceFrom(gravX, gravY); JSObject* spaceHolder = sugs::physics::newSpaceContainerObject(cx, space, spaceObj); jsval rVal = OBJECT_TO_JSVAL(spaceHolder); JS_SET_RVAL(cx, vp, rVal); return JS_TRUE; } static JSFunctionSpec reformer_chipmunk_native_functions[] = { JS_FS("__native_chipmunk_new_space", new_space, 2, 0), JS_FS_END }; namespace sugs { namespace physics { void ChipmunkPhysicsComponent::setup(jsEnv jsEnv, pathStrings paths) { JS_DefineFunctions(jsEnv.cx, jsEnv.global, reformer_chipmunk_native_functions); } sugs::core::ext::Component* ChipmunkPhysicsComponentFactory::create(jsEnv jsEnv, JSObject* configJson) { return new sugs::physics::ChipmunkPhysicsComponent();