• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ JS_DefineObject函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了JS_DefineObject函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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");
		}
	}
}
开发者ID:CIHANGIRCAN,项目名称:vibestreamer,代码行数:53,代码来源:Engine.cpp


示例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;
}
开发者ID:AllenDou,项目名称:firefox,代码行数:55,代码来源:nsSecurityManagerFactory.cpp


示例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);
	}
}
开发者ID:joejoyce,项目名称:jsEngine,代码行数:29,代码来源:web.cpp


示例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;
}
开发者ID:odistagon,项目名称:cyeonna,代码行数:34,代码来源:xgg_dom.c


示例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;
}
开发者ID:mandrake,项目名称:lulzjs,代码行数:30,代码来源:Output.cpp


示例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;
}
开发者ID:kshostak,项目名称:showtime,代码行数:31,代码来源:js_settings.c


示例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;
}
开发者ID:pankajtanwar,项目名称:ponkey,代码行数:27,代码来源:jsnavigator.c


示例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;
}
开发者ID:Kitiara,项目名称:UOX3,代码行数:31,代码来源:jsj_JavaPackage.c


示例9: beforeTest

JSBool beforeTest(JSContext *cx)
{
	JSObject *global=JS_GetGlobalObject(cx);

	JS_DefineObject(cx,global,"testobj",&testobj_class,NULL,JSPROP_ENUMERATE|JSFUN_CONSTRUCTOR);
	
}
开发者ID:trarck,项目名称:learnspidermonkey,代码行数:7,代码来源:test_binding_object.cpp


示例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);
}
开发者ID:Rektosauros,项目名称:0ad,代码行数:60,代码来源:ScriptInterface.cpp


示例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;
}
开发者ID:odistagon,项目名称:cyeonna,代码行数:8,代码来源:xgg_pluginhelper.c


示例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;
}
开发者ID:mindbit,项目名称:libjssql,代码行数:46,代码来源:jssql.c


示例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");
}
开发者ID:donald-hanson,项目名称:battle-of-the-sexes,代码行数:8,代码来源:cg_js_sys_cvar.c


示例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;
}
开发者ID:Displacer,项目名称:freewrl,代码行数:58,代码来源:jsj_JavaPackage.c


示例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;
}
开发者ID:AbrahamJewowich,项目名称:FreeSWITCH,代码行数:11,代码来源:jsdso.c


示例16: js_CreateConioObject

JSObject* js_CreateConioObject(JSContext* cx, JSObject* parent)
{
	JSObject*	obj;

	if((obj = JS_DefineObject(cx, parent, "conio", &js_conio_class, NULL
		,JSPROP_ENUMERATE|JSPROP_READONLY))==NULL)
		return(NULL);

	return(obj);
}
开发者ID:kindy,项目名称:synchronet-bbs-1,代码行数:10,代码来源:js_conio.c


示例17: init

	JSBool init(JSContext* cx, JSObject* scope)
	{ 
		JSObject* newObj = JS_DefineObject(cx, scope, "Strings", NULL, NULL, 0);
		if(!newObj)
			return false;
			
		if(!JS_DefineFunctions(cx, newObj, functionsDefs))
			return false;
			
		return true;
	}
开发者ID:FunkMonkey,项目名称:Bound,代码行数:11,代码来源:Strings.cpp


示例18: 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_SetOffthreadIonCompilationEnabled(m_runtime->m_rt, true);

	// For GC debugging:
	// JS_SetGCZeal(m_cx, 2, JS_DEFAULT_ZEAL_FREQ);

	JS_SetContextPrivate(m_cx, NULL);

	JS_SetErrorReporter(m_runtime->m_rt, ErrorReporter);

	JS_SetGlobalJitCompilerOption(m_runtime->m_rt, JSJITCOMPILER_ION_ENABLE, 1);
	JS_SetGlobalJitCompilerOption(m_runtime->m_rt, JSJITCOMPILER_BASELINE_ENABLE, 1);

	JS::RuntimeOptionsRef(m_cx).setExtraWarnings(1)
		.setWerror(0)
		.setVarObjFix(1)
		.setStrictMode(1);

	JS::CompartmentOptions opt;
	opt.setVersion(JSVERSION_LATEST);
	// Keep JIT code during non-shrinking GCs. This brings a quite big performance improvement.
	opt.setPreserveJitCode(true);

	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();

	JS_DefineProperty(m_cx, m_glob, "global", globalRootedVal, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT);

	m_nativeScope = JS_DefineObject(m_cx, m_glob, nativeScopeName, nullptr, 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);
	Register("ProfileAttribute", ::ProfileAttribute, 1);

	runtime->RegisterContext(m_cx);
}
开发者ID:krichter722,项目名称:0ad,代码行数:53,代码来源:ScriptInterface.cpp


示例19: JS_InitClass

    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]);
        }
    }
开发者ID:Kitiara,项目名称:UOX3,代码行数:40,代码来源:CJSEngine.cpp


示例20: js_InitMathClass

JSObject *
js_InitMathClass(JSContext *cx, JSObject *obj)
{
    JSObject *Math;
    
    Math = JS_DefineObject(cx, obj, "Math", &math_class, NULL, 0);
    if (!Math)
        return NULL;
    if (!JS_DefineFunctions(cx, Math, math_static_methods))
        return NULL;
    if (!JS_DefineConstDoubles(cx, Math, math_constants))
        return NULL;
    return Math;
}
开发者ID:Hiroyuki-Nagata,项目名称:js-1.5-rc6a,代码行数:14,代码来源:jsmath.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ JS_DestroyRuntime函数代码示例发布时间:2022-05-30
下一篇:
C++ JS_ClearPendingException函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap