本文整理汇总了C++中JS_DefineObject函数的典型用法代码示例。如果您正苦于以下问题:C++ JS_DefineObject函数的具体用法?C++ JS_DefineObject怎么用?C++ JS_DefineObject使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了JS_DefineObject函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: JS_DefineObject
void Engine::createPredefinedObjects(JSContext *cx,JSObject *obj,HttpServerRequest &httpRequest)
{
JSObject *predefinedObj = NULL;
predefinedObj = JS_DefineObject(cx,obj,"response",JsHttpServerResponse::getJsClass(),NULL,JSPROP_PERMANENT|JSPROP_READONLY|JSPROP_ENUMERATE);
if ( predefinedObj==NULL ) {
LogManager::getInstance()->warning(LOGGER_CLASSNAME,"Failed to create predefined \"response\" object");
}
predefinedObj = JS_DefineObject(cx,obj,"request",JsHttpServerRequest::getJsClass(),NULL,JSPROP_PERMANENT|JSPROP_READONLY|JSPROP_ENUMERATE);
if ( predefinedObj==NULL ) {
LogManager::getInstance()->warning(LOGGER_CLASSNAME,"Failed to create predefined \"request\" object");
}
predefinedObj = JS_DefineObject(cx,obj,"server",JsServer::getJsClass(),NULL,JSPROP_PERMANENT|JSPROP_READONLY|JSPROP_ENUMERATE);
if ( predefinedObj==NULL ) {
LogManager::getInstance()->warning(LOGGER_CLASSNAME,"Failed to create predefined \"server\" object");
}
if ( httpRequest.getSession()!=NULL )
{
predefinedObj = JS_DefineObject(cx,obj,"session",JsHttpSession::getJsClass(),NULL,JSPROP_PERMANENT|JSPROP_READONLY|JSPROP_ENUMERATE);
if ( predefinedObj==NULL ) {
LogManager::getInstance()->warning(LOGGER_CLASSNAME,"Failed to create predefined \"session\" object");
}
else {
JS_SetPrivate(cx,predefinedObj,new HttpSession::Ptr(httpRequest.getSession()));
}
}
else
{
if ( JS_DefineProperty(cx,obj,"session",JSVAL_NULL,NULL,NULL,JSPROP_PERMANENT|JSPROP_READONLY|JSPROP_ENUMERATE)==JS_FALSE ) {
LogManager::getInstance()->warning(LOGGER_CLASSNAME,"Failed to create predefined \"session\" object");
}
}
if ( httpRequest.getSite()!=NULL )
{
predefinedObj = JS_DefineObject(cx,obj,"site",JsSite::getJsClass(),NULL,JSPROP_PERMANENT|JSPROP_READONLY|JSPROP_ENUMERATE);
if ( predefinedObj==NULL ) {
LogManager::getInstance()->warning(LOGGER_CLASSNAME,"Failed to create predefined \"site\" object");
}
else {
JS_SetPrivate(cx,predefinedObj,httpRequest.getSite());
}
}
else
{
if ( JS_DefineProperty(cx,obj,"site",JSVAL_NULL,NULL,NULL,JSPROP_PERMANENT|JSPROP_READONLY|JSPROP_ENUMERATE)==JS_FALSE ) {
LogManager::getInstance()->warning(LOGGER_CLASSNAME,"Failed to create predefined \"site\" object");
}
}
}
示例2: JS_GetGlobalObject
/*
* "Steal" calls to netscape.security.PrivilegeManager.enablePrivilege,
* et. al. so that code that worked with 4.0 can still work.
*/
NS_IMETHODIMP
nsSecurityNameSet::InitializeNameSet(nsIScriptContext* aScriptContext)
{
JSContext *cx = (JSContext *) aScriptContext->GetNativeContext();
JSObject *global = JS_GetGlobalObject(cx);
/*
* Find Object.prototype's class by walking up the global object's
* prototype chain.
*/
JSObject *obj = global;
JSObject *proto;
JSAutoRequest ar(cx);
while ((proto = JS_GetPrototype(cx, obj)) != nsnull)
obj = proto;
JSClass *objectClass = JS_GET_CLASS(cx, obj);
jsval v;
if (!JS_GetProperty(cx, global, "netscape", &v))
return NS_ERROR_FAILURE;
JSObject *securityObj;
if (JSVAL_IS_OBJECT(v)) {
/*
* "netscape" property of window object exists; get the
* "security" property.
*/
obj = JSVAL_TO_OBJECT(v);
if (!JS_GetProperty(cx, obj, "security", &v) || !JSVAL_IS_OBJECT(v))
return NS_ERROR_FAILURE;
securityObj = JSVAL_TO_OBJECT(v);
} else {
/* define netscape.security object */
obj = JS_DefineObject(cx, global, "netscape", objectClass, nsnull, 0);
if (obj == nsnull)
return NS_ERROR_FAILURE;
securityObj = JS_DefineObject(cx, obj, "security", objectClass,
nsnull, 0);
if (securityObj == nsnull)
return NS_ERROR_FAILURE;
}
/* Define PrivilegeManager object with the necessary "static" methods. */
obj = JS_DefineObject(cx, securityObj, "PrivilegeManager", objectClass,
nsnull, 0);
if (obj == nsnull)
return NS_ERROR_FAILURE;
return JS_DefineFunctions(cx, obj, PrivilegeManager_static_methods)
? NS_OK
: NS_ERROR_FAILURE;
}
示例3: webInit
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);
}
}
示例4: xgg_new_nodelist
JSObject* xgg_new_nodelist(XJSECTX* pctxa, JSObject* poparent)
{
JSBool b1;
#ifdef NODELISTISCLASS
JSObject* pobjbase = 0;
JSObject* pobj = JS_DefineObject(pctxa->pctx, poparent,
pszobjname, &class_nodelist, pobjbase,
JSPROP_PERMANENT | JSPROP_READONLY | JSPROP_ENUMERATE);
#else //NODELISTISCLASS
JSObject* pobj = JS_NewArrayObject(pctxa->pctx, 0, NULL);
if(pobj == 0) {
XJSE_TRACE("(E) JS_NewArrayObject() failed!");
goto failed;
}
#if 0
b1 = JS_DefineFunctions(pctxa->pctx, pobj, funcs_nodelist);
if(b1 != JS_TRUE)
goto failed;
b1 = JS_DefineProperties(pctxa->pctx, pobj, props_nodelist);
if(b1 != JS_TRUE)
goto failed;
#endif
#endif //NODELISTISCLASS
//
b1 = xgg_nodelist_ctor(pctxa->pctx, pobj, 0, 0, 0); //args, rval
if(b1 != JS_TRUE) {
XJSE_TRACE("(E) xgg_nodelist_ctor failed!");
}
//
return pobj;
failed:
return 0;
}
示例5: Output_initialize
JSBool
Output_initialize (JSContext* cx)
{
JSBool result = JS_FALSE;
JS_BeginRequest(cx);
JS_EnterLocalRootScope(cx);
jsval property;
JSObject* output = JS_DefineObject(cx, ((LCGIData*) JS_GetContextPrivate(cx))->global,
"Output", &Output_class, NULL, 0
);
if (output) {
property = INT_TO_JSVAL(1024);
JS_SetProperty(cx, output, "limit", &property);
property = JSVAL_FALSE;
JS_SetProperty(cx, output, "buffered", &property);
property = JS_GetEmptyStringValue(cx);
JS_SetProperty(cx, output, "content", &property);
result = JS_TRUE;
}
JS_LeaveLocalRootScope(cx);
JS_EndRequest(cx);
return result;
}
示例6: jss_create
static js_setting_t *
jss_create(JSContext *cx, JSObject *obj, const char *id, jsval *rval,
JSObject *func, js_setting_group_t *jsg, int persistent)
{
if(jsg->jsg_root == NULL) {
JS_ReportError(cx, "Settings group has been destroyed");
return NULL;
}
if(!JS_ObjectIsFunction(cx, func)) {
JS_ReportError(cx, "Callback is not a function");
return NULL;
}
js_setting_t *jss = calloc(1, sizeof(js_setting_t));
jss->jss_cx = cx;
jss->jss_refcount = 1;
jss->jss_jsg = jsg;
jss->jss_key = persistent && jsg->jsg_kv_url ? strdup(id) : NULL;
LIST_INSERT_HEAD(&jsg->jsg_settings, jss, jss_link);
atomic_add(&jsg->jsg_refcount, 1);
JS_AddNamedRoot(cx, &jss->jss_obj, "jss");
jss->jss_obj = OBJECT_TO_JSVAL(JS_DefineObject(cx, obj, id,
&setting_class, NULL, 0));
*rval = jss->jss_obj;
JS_SetPrivate(cx, JSVAL_TO_OBJECT(jss->jss_obj), jss);
jsval v = OBJECT_TO_JSVAL(func);
JS_SetProperty(cx, JSVAL_TO_OBJECT(jss->jss_obj), "callback", &v);
return jss;
}
示例7: js_InitNavigatorClass
JSObject *
js_InitNavigatorClass(JSContext *cx, JSObject *obj) {
JSObject *Navigator;
Navigator = JS_DefineObject(cx, obj, "navigator", &navigator_class, NULL, 0);
if (!Navigator)
return NULL;
if (!JS_DefineFunctions(cx, Navigator, navigator_static_methods))
return NULL;
if (!JS_DefineProperties(cx, Navigator, navigator_properties))
return NULL;
CMNavigator *cmNav;
cmNav = JS_malloc(cx, sizeof *cmNav);
if (!cmNav)
return NULL;
memset(cmNav, 0 , sizeof *cmNav);
cmNav->appVersion = JS_malloc(cx, strlen("Firefox/2"));
cmNav->appVersion = strdup("Firefox/2");
JS_SetPrivate(cx, Navigator, cmNav);
return Navigator;
}
示例8: define_JavaPackage
static JSObject *
define_JavaPackage(JSContext *cx, JSObject *parent_obj,
const char *obj_name, const char *path, int flags, int access)
{
JSObject *package_obj;
JavaPackage_Private *package;
package_obj = JS_DefineObject(cx, parent_obj, obj_name, &JavaPackage_class, 0, JSPROP_PERMANENT | access);
if (!package_obj)
return NULL;
/* Attach private, native data to the JS object */
package = (JavaPackage_Private *)JS_malloc(cx, sizeof(JavaPackage_Private));
JS_SetPrivate(cx, package_obj, (void *)package);
if (path)
package->path = JS_strdup(cx, path);
else
package->path = "";
package->flags = flags;
/* Check for OOM */
if (!package->path) {
JS_DeleteProperty(cx, parent_obj, obj_name);
JS_free(cx, package);
return NULL;
}
return package_obj;
}
示例9: beforeTest
JSBool beforeTest(JSContext *cx)
{
JSObject *global=JS_GetGlobalObject(cx);
JS_DefineObject(cx,global,"testobj",&testobj_class,NULL,JSPROP_ENUMERATE|JSFUN_CONSTRUCTOR);
}
示例10: m_runtime
ScriptInterface_impl::ScriptInterface_impl(const char* nativeScopeName, const shared_ptr<ScriptRuntime>& runtime) :
m_runtime(runtime), m_glob(runtime->m_rt), m_nativeScope(runtime->m_rt)
{
bool ok;
m_cx = JS_NewContext(m_runtime->m_rt, STACK_CHUNK_SIZE);
ENSURE(m_cx);
JS_SetParallelIonCompilationEnabled(m_runtime->m_rt, true);
// For GC debugging:
// JS_SetGCZeal(m_cx, 2);
JS_SetContextPrivate(m_cx, NULL);
JS_SetErrorReporter(m_cx, ErrorReporter);
JS_SetGlobalJitCompilerOption(m_runtime->m_rt, JSJITCOMPILER_ION_ENABLE, 1);
JS_SetGlobalJitCompilerOption(m_runtime->m_rt, JSJITCOMPILER_BASELINE_ENABLE, 1);
JS::ContextOptionsRef(m_cx).setExtraWarnings(1)
.setWerror(0)
.setVarObjFix(1)
.setStrictMode(1);
JS::CompartmentOptions opt;
opt.setVersion(JSVERSION_LATEST);
JSAutoRequest rq(m_cx);
JS::RootedObject globalRootedVal(m_cx, JS_NewGlobalObject(m_cx, &global_class, NULL, JS::OnNewGlobalHookOption::FireOnNewGlobalHook, opt));
m_comp = JS_EnterCompartment(m_cx, globalRootedVal);
ok = JS_InitStandardClasses(m_cx, globalRootedVal);
ENSURE(ok);
m_glob = globalRootedVal.get();
// Use the testing functions to globally enable gcPreserveCode. This brings quite a
// big performance improvement. In future SpiderMonkey versions, we should probably
// use the functions implemented here: https://bugzilla.mozilla.org/show_bug.cgi?id=1068697
JS::RootedObject testingFunctionsObj(m_cx, js::GetTestingFunctions(m_cx));
ENSURE(testingFunctionsObj);
JS::RootedValue ret(m_cx);
JS_CallFunctionName(m_cx, testingFunctionsObj, "gcPreserveCode", JS::HandleValueArray::empty(), &ret);
JS_DefineProperty(m_cx, m_glob, "global", globalRootedVal, JSPROP_ENUMERATE | JSPROP_READONLY
| JSPROP_PERMANENT);
m_nativeScope = JS_DefineObject(m_cx, m_glob, nativeScopeName, NULL, NULL, JSPROP_ENUMERATE | JSPROP_READONLY
| JSPROP_PERMANENT);
JS_DefineFunction(m_cx, globalRootedVal, "print", ::print, 0, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(m_cx, globalRootedVal, "log", ::logmsg, 1, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(m_cx, globalRootedVal, "warn", ::warn, 1, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(m_cx, globalRootedVal, "error", ::error, 1, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(m_cx, globalRootedVal, "deepcopy", ::deepcopy, 1, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT);
Register("ProfileStart", ::ProfileStart, 1);
Register("ProfileStop", ::ProfileStop, 0);
runtime->RegisterContext(m_cx);
}
示例11: xjse_xgg_new_pluginhelper
JSObject* xjse_xgg_new_pluginhelper(XJSECTX* pctxa, const char* pszobjname)
{
JSObject* pobj = JS_DefineObject(pctxa->pctx, pctxa->poglobal,
pszobjname, &class_xgg_pluginhelper, 0,
JSPROP_PERMANENT | JSPROP_READONLY | JSPROP_ENUMERATE);
return pobj;
}
示例12: JS_SqlInit
JSBool JS_SqlInit(JSContext *cx, JSObject *global)
{
JS_Log(JS_LOG_INFO, "%s\n", VERSION_STR);
JSObject *obj;
obj = JS_DefineObject(cx, global, "DriverManager", &DriverManager_class, NULL, JSPROP_ENUMERATE);
if (!obj) {
JS_Log(JS_LOG_ERR, "Failed to create the DriverManager object\n");
return JS_FALSE;
}
if (!JS_DefineFunctions(cx, obj, DriverManager_functions))
return JS_FALSE;
JSObject *drivers = JS_NewArrayObject(cx, 0, NULL);
if (drivers == NULL)
return JS_FALSE;
if (JS_DefineProperty(cx, obj, "drivers", OBJECT_TO_JSVAL(drivers), NULL, NULL,
JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT) == JS_FALSE) {
JS_Log(JS_LOG_ERR, "Failed define drivers property\n");
return JS_FALSE;
}
JSObject *statement;
statement = JS_DefineObject(cx, global, "Statement", NULL, NULL, JSPROP_ENUMERATE);
if (!statement) {
JS_Log(JS_LOG_ERR, "Failed to create the Statement object\n");
return JS_FALSE;
}
if (JS_DefineProperty(cx, statement, "RETURN_GENERATED_KEYS", JSVAL_ONE, NULL, NULL,
JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT) == JS_FALSE) {
JS_Log(JS_LOG_ERR, "Failed define RETURN_GENERATED_KEYS property\n");
return JS_FALSE;
}
if (JS_DefineProperty(cx, statement, "NO_GENERATED_KEYS", JSVAL_ZERO, NULL, NULL,
JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT) == JS_FALSE) {
JS_Log(JS_LOG_ERR, "Failed define NO_GENERATED_KEYS property\n");
return JS_FALSE;
}
return JS_TRUE;
}
示例13: CG_JS_Sys_Cvar_Init
void CG_JS_Sys_Cvar_Init(JSContext *ctx, JSObject *Sys)
{
JSObject *cvar = JS_DefineObject(ctx, Sys, "Cvar", &cvar_class, NULL, 0);
if (!cvar)
CG_Error("Failed to Define javascript Cvar object\n");
if (!JS_DefineFunctions(ctx, cvar, cvar_static_methods))
CG_Error("Failed to Define javascript Cvar functions\n");
}
示例14: define_JavaPackage
static JSObject *
define_JavaPackage(JSContext *cx, JSObject *parent_obj,
const char *obj_name, const char *path, int flags, int access)
{
JSObject *package_obj, *obj;
JavaPackage_Private *package;
jsval v;
/*
* Expose the same JSObject for Packages.java and java.
* "java" will be defined during the java package initialization stage.
* "Packages.java" will be lazily resolved by JavaPackage_resolve.
* Ditto for sun and netscape.
* See bugzilla bug: https://bugzilla.mozilla.org/show_bug.cgi?id=248409.
*/
if (!strcmp(obj_name, path) &&
(obj = JS_GetParent(cx, parent_obj)) &&
JS_LookupProperty(cx, obj, obj_name, &v) &&
!JSVAL_IS_PRIMITIVE(v))
{
if (!JS_DefineProperty(cx, parent_obj, obj_name, v, NULL, NULL,
JSPROP_PERMANENT | access)) {
return NULL;
}
package_obj = JSVAL_TO_OBJECT(v);
return package_obj;
}
package_obj = JS_DefineObject(cx, parent_obj, obj_name, &JavaPackage_class,
0, JSPROP_PERMANENT | access);
if (!package_obj)
return NULL;
/* Attach private, native data to the JS object */
package = (JavaPackage_Private *)JS_malloc(cx, sizeof(JavaPackage_Private));
if (!package) {
JS_DeleteProperty(cx, parent_obj, obj_name);
return NULL;
}
JS_SetPrivate(cx, package_obj, (void *)package);
if (path)
package->path = JS_strdup(cx, path);
else
package->path = "";
package->flags = flags;
/* Check for OOM */
if (!package->path) {
JS_DeleteProperty(cx, parent_obj, obj_name);
JS_free(cx, package);
return NULL;
}
return package_obj;
}
示例15:
/* JavaScript DSO class global initializer */
JSObject *js_InitDSOClass(JSContext *cx, JSObject *obj)
{
JSObject *DSO;
if ((DSO = JS_DefineObject(cx, obj, "DSO", &dso_class, NULL, 0)) == NULL)
return NULL;
if (!JS_DefineFunctions(cx, DSO, dso_methods))
return NULL;
return DSO;
}