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

C++ JS_GetGlobalObject函数代码示例

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

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



在下文中一共展示了JS_GetGlobalObject函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: spidermonkey_eval_stringback

unsigned char *
spidermonkey_eval_stringback(struct ecmascript_interpreter *interpreter,
			     struct string *code)
{
	JSBool ret;
	JSContext *ctx;
	jsval rval;

	assert(interpreter);
	if (!js_module_init_ok) return NULL;
	ctx = interpreter->backend_data;
	interpreter->ret = NULL;
#if defined(CONFIG_ECMASCRIPT_SMJS_HEARTBEAT)
	interpreter->heartbeat = add_heartbeat(interpreter);
#elif defined(HAVE_JS_SETBRANCHCALLBACK)
	setup_safeguard(interpreter, ctx);
#endif
	ret = JS_EvaluateScript(ctx, JS_GetGlobalObject(ctx),
	                        code->source, code->length, "", 0, &rval);
#if defined(CONFIG_ECMASCRIPT_SMJS_HEARTBEAT)
	done_heartbeat(interpreter->heartbeat);
#endif
	if (ret == JS_FALSE) {
		return NULL;
	}
	if (JSVAL_IS_VOID(rval) || JSVAL_IS_NULL(rval)) {
		/* Undefined value. */
		return NULL;
	}

	return stracpy(jsval_to_string(ctx, &rval));
}
开发者ID:Efreak,项目名称:elinks,代码行数:32,代码来源:spidermonkey.c


示例2: 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


示例3: initialize

static JSObject*
initialize(JSContext *cx)
{
    js::SetRuntimeProfilingStack(cx->runtime, stack, &size, 10);
    return JS_InitClass(cx, JS_GetGlobalObject(cx), NULL, &ptestClass, Prof, 0,
                        NULL, ptestFunctions, NULL, NULL);
}
开发者ID:CrtronicsStudio,项目名称:spidermonkey,代码行数:7,代码来源:testProfileStrings.cpp


示例4: FRAGMENT

FRAGMENT(jsval, simple) {
  JS::Rooted<jsval> fortytwo(cx, INT_TO_JSVAL(42));
  JS::Rooted<jsval> negone(cx, INT_TO_JSVAL(-1));
  JS::Rooted<jsval> undefined(cx, JSVAL_VOID);
  JS::Rooted<jsval> null(cx, JSVAL_NULL);
  JS::Rooted<jsval> js_true(cx, JSVAL_TRUE);
  JS::Rooted<jsval> js_false(cx, JSVAL_FALSE);
  JS::Rooted<jsval> elements_hole(cx, js::MagicValue(JS_ELEMENTS_HOLE));

  JS::Rooted<jsval> empty_string(cx);
  empty_string.setString(JS_NewStringCopyZ(cx, ""));
  JS::Rooted<jsval> friendly_string(cx);
  friendly_string.setString(JS_NewStringCopyZ(cx, "Hello!"));

  JS::Rooted<jsval> global(cx);
  global.setObject(*JS_GetGlobalObject(cx));

  // Some interesting value that floating-point won't munge.
  JS::Rooted<jsval> onehundredthirtysevenonehundredtwentyeighths(cx, DOUBLE_TO_JSVAL(137.0 / 128.0));

  breakpoint();

  (void) fortytwo;
  (void) negone;
  (void) undefined;
  (void) js_true;
  (void) js_false;
  (void) null;
  (void) elements_hole;
  (void) empty_string;
  (void) friendly_string;
  (void) global;
}
开发者ID:JSilver99,项目名称:mozilla-central,代码行数:33,代码来源:test-jsval.cpp


示例5: gjs_keep_alive_create_in_global

static JSObject*
gjs_keep_alive_create_in_global(JSContext *context)
{
    JSObject *keep_alive;
    JSObject *global;

    JS_BeginRequest(context);

    global = JS_GetGlobalObject(context);

    keep_alive = gjs_keep_alive_new(context);

    if (!JS_DefineProperty(context, global,
                           GLOBAL_KEEP_ALIVE_NAME,
                           OBJECT_TO_JSVAL(keep_alive),
                           NULL, NULL,
                           /* No ENUMERATE since this is a hidden
                            * implementation detail kind of property
                            */
                           JSPROP_READONLY | JSPROP_PERMANENT))
        gjs_fatal("no memory to define keep_alive property");

    JS_EndRequest(context);
    return keep_alive;
}
开发者ID:sjokkis,项目名称:gjs,代码行数:25,代码来源:keep-alive.c


示例6: NS_InitInstallTriggerGlobalClass

//
// InstallTriggerGlobal class initialization
//
nsresult NS_InitInstallTriggerGlobalClass(nsIScriptContext *aContext, void **aPrototype)
{
  JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
  JSObject *proto = nsnull;
  JSObject *constructor = nsnull;
  JSObject *global = JS_GetGlobalObject(jscontext);
  jsval vp;

  if ((PR_TRUE != JS_LookupProperty(jscontext, global, "InstallTriggerGlobal", &vp)) ||
      !JSVAL_IS_OBJECT(vp) ||
      ((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) ||
      (PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) ||
      !JSVAL_IS_OBJECT(vp))
  {
    nsresult rv = InitInstallTriggerGlobalClass(jscontext, global, (void**)&proto);
    if (NS_FAILED(rv)) return rv;
  }
  else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp))
  {
    proto = JSVAL_TO_OBJECT(vp);
  }
  else
  {
    return NS_ERROR_FAILURE;
  }

  if (aPrototype)
    *aPrototype = proto;

  return NS_OK;
}
开发者ID:LittleForker,项目名称:mozilla-central,代码行数:34,代码来源:nsJSInstallTriggerGlobal.cpp


示例7: gjstest_test_func_gjs_jsapi_util_string_js_string_utf8

static void
gjstest_test_func_gjs_jsapi_util_string_js_string_utf8(void)
{
    GjsUnitTestFixture fixture;
    JSContext *context;
    JSObject *global;

    const char *utf8_string = "\303\211\303\226 foobar \343\203\237";
    char *utf8_result;
    jsval js_string;

    _gjs_unit_test_fixture_begin(&fixture);
    context = fixture.context;
    global = JS_GetGlobalObject(context);
    JSCompartment *oldCompartment = JS_EnterCompartment(context, global);

    g_assert(gjs_string_from_utf8(context, utf8_string, -1, &js_string) == JS_TRUE);
    g_assert(JSVAL_IS_STRING(js_string));
    g_assert(gjs_string_to_utf8(context, js_string, &utf8_result) == JS_TRUE);

    JS_LeaveCompartment(context, oldCompartment);
    _gjs_unit_test_fixture_finish(&fixture);

    g_assert(g_str_equal(utf8_string, utf8_result));

    g_free(utf8_result);
}
开发者ID:victoryang,项目名称:gjs,代码行数:27,代码来源:gjs-tests.cpp


示例8: NS_ENSURE_TRUE

NS_IMETHODIMP
nsDOMWorkerMessageEvent::GetData(nsAString& aData)
{
  nsIXPConnect* xpc = nsContentUtils::XPConnect();
  NS_ENSURE_TRUE(xpc, NS_ERROR_UNEXPECTED);

  nsAXPCNativeCallContext* cc;
  nsresult rv = xpc->GetCurrentNativeCallContext(&cc);
  NS_ENSURE_SUCCESS(rv, rv);
  NS_ENSURE_TRUE(cc, NS_ERROR_UNEXPECTED);

  if (!mDataValWasReparented) {
    if (JSVAL_IS_OBJECT(mDataVal) && !JSVAL_IS_NULL(mDataVal)) {
      JSContext* cx;
      rv = cc->GetJSContext(&cx);
      NS_ENSURE_SUCCESS(rv, rv);

      rv =
        nsContentUtils::ReparentClonedObjectToScope(cx,
                                                    JSVAL_TO_OBJECT(mDataVal),
                                                    JS_GetGlobalObject(cx));
      NS_ENSURE_SUCCESS(rv, rv);
    }
    mDataValWasReparented = PR_TRUE;
  }

  jsval* retval;
  rv = cc->GetRetValPtr(&retval);
  NS_ENSURE_SUCCESS(rv, rv);

  cc->SetReturnValueWasSet(PR_TRUE);
  *retval = mDataVal;
  return NS_OK;
}
开发者ID:lofter2011,项目名称:Icefox,代码行数:34,代码来源:nsDOMWorkerEvents.cpp


示例9: ejs_alloc

spidermonkey_vm *sm_initialize(long thread_stack, long heap_size) {
  spidermonkey_vm *vm = ejs_alloc(sizeof(spidermonkey_vm));
  spidermonkey_state *state = ejs_alloc(sizeof(spidermonkey_state));
  state->branch_count = 0;
  state->error = NULL;
  state->terminate = 0;
  int gc_size = (int) heap_size * 0.25;
  vm->runtime = JS_NewRuntime(MAX_GC_SIZE);
  JS_SetGCParameter(vm->runtime, JSGC_MAX_BYTES, heap_size);
  JS_SetGCParameter(vm->runtime, JSGC_MAX_MALLOC_BYTES, gc_size);
  vm->context = JS_NewContext(vm->runtime, 8192);
  JS_SetScriptStackQuota(vm->context, thread_stack);

  begin_request(vm);
  JS_SetOptions(vm->context, JSOPTION_VAROBJFIX);
  JS_SetOptions(vm->context, JSOPTION_STRICT);
  JS_SetOptions(vm->context, JSOPTION_COMPILE_N_GO);
  JS_SetOptions(vm->context, JSVERSION_LATEST);
  vm->global = JS_NewCompartmentAndGlobalObject(vm->context, &global_class, NULL);
  JS_InitStandardClasses(vm->context, vm->global);
  JS_SetErrorReporter(vm->context, on_error);
  JS_SetOperationCallback(vm->context, on_branch);
  JS_SetContextPrivate(vm->context, state);
  JSNative funptr = (JSNative) &js_log;
  JS_DefineFunction(vm->context, JS_GetGlobalObject(vm->context), "ejsLog", funptr,
                    0, 0);
  end_request(vm);

  return vm;
}
开发者ID:systra,项目名称:erlang_js,代码行数:30,代码来源:spidermonkey.c


示例10: 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


示例11: NS_MAX

nsresult
nsDOMWorkerTimeout::FunctionCallback::Run(nsDOMWorkerTimeout* aTimeout,
                                          JSContext* aCx)
{
  PRInt32 lateness = NS_MAX(0, PRInt32(PR_Now() - aTimeout->mTargetTime)) /
                     (PRTime)PR_USEC_PER_MSEC;
  mCallbackArgs[mCallbackArgsLength - 1] = INT_TO_JSVAL(lateness);

  JSObject* global = JS_GetGlobalObject(aCx);
  NS_ENSURE_TRUE(global, NS_ERROR_FAILURE);

  nsTArray<jsval> argv;
  PRBool success = argv.SetCapacity(mCallbackArgsLength);
  NS_ENSURE_TRUE(success, NS_ERROR_OUT_OF_MEMORY);

  for (PRUint32 index = 0; index < mCallbackArgsLength; index++) {
    argv.AppendElement(mCallbackArgs[index]);
  }

  jsval rval;
  JSBool ok =
    JS_CallFunctionValue(aCx, global, mCallback, mCallbackArgsLength,
                         argv.Elements(), &rval);
  NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE);

  return NS_OK;
}
开发者ID:Akin-Net,项目名称:mozilla-central,代码行数:27,代码来源:nsDOMWorkerTimeout.cpp


示例12: qq_js_load

qq_jso_t* qq_js_load(qq_js_t* js,const char* file)
{
    JSObject* global = JS_GetGlobalObject(js->context);
    JSObject* script = JS_CompileFile(js->context, global, file);
    JS_ExecuteScript(js->context, global, script, NULL);
    return (qq_jso_t*)script;
}
开发者ID:badcell,项目名称:kopete-lwqq,代码行数:7,代码来源:js.cpp


示例13: webRspGetImg

JSBool webRspGetImg(JSContext *cx, uintN argc, jsval *vp) {
	SDL_Texture *tx = NULL;
	JSObject * object = NULL;
	jsval vl;
	JS_GetProperty(cx,JS_GetGlobalObject(cx),"Image",&vl);
	object = JS_New(cx,JSVAL_TO_OBJECT(vl),0,NULL);
	if(object){
		JSObject *ob = NULL;
		ob = JSVAL_TO_OBJECT(JS_THIS(cx,vp));
		if(ob){
			CURLMsg *msg;
			msg = (CURLMsg*) JS_GetPrivate(cx,ob);
			if(msg){
				rqPrivate *rq = NULL;
				curl_easy_getinfo(msg->easy_handle,CURLINFO_PRIVATE,(char**)&rq);
				if(rq){
					SDL_RWops* rwop = NULL;
					rwop = SDL_RWFromConstMem(rq->data,rq->size);
					if(rwop){
						tx = IMG_LoadTexture_RW(renderer,rwop,1);
						//tx = IMG_LoadTextureTyped_RW(renderer,rwop,1,"JPEG");
						SDL_RenderCopy(renderer,tx,NULL,NULL);
						if(tx){
							JS_SetPrivate(cx,object,tx);
							imageAddProps(cx,object);
							print("hi\n");
							JS_SET_RVAL(cx,vp,OBJECT_TO_JSVAL(object));
						}
					}
				}
			}
		}
	}
	return JS_TRUE;
}
开发者ID:joejoyce,项目名称:jsEngine,代码行数:35,代码来源:web.cpp


示例14: f

JSScript *createScriptViaXDR(JSPrincipals *prin, JSPrincipals *orig, int testCase)
{
    const char src[] =
        "function f() { return 1; }\n"
        "f;\n";

    js::RootedObject global(cx, JS_GetGlobalObject(cx));
    JSScript *script = CompileScriptForPrincipalsVersionOrigin(cx, global, prin, orig,
                                                               src, strlen(src), "test", 1,
                                                               JSVERSION_DEFAULT);
    if (!script)
        return NULL;

    if (testCase == TEST_SCRIPT || testCase == TEST_SERIALIZED_FUNCTION) {
        script = FreezeThaw(cx, script);
        if (!script)
            return NULL;
        if (testCase == TEST_SCRIPT)
            return script;
    }

    JS::Value v;
    JSBool ok = JS_ExecuteScript(cx, global, script, &v);
    if (!ok || !v.isObject())
        return NULL;
    js::RootedObject funobj(cx, &v.toObject());
    if (testCase == TEST_FUNCTION) {
        funobj = FreezeThaw(cx, funobj);
        if (!funobj)
            return NULL;
    }
    return GetScript(cx, funobj);
}
开发者ID:LyeSS,项目名称:mozilla-central,代码行数:33,代码来源:testXDR.cpp


示例15: test_fn2

static JSBool
test_fn2(JSContext *cx, unsigned argc, jsval *vp)
{
    jsval r;
    JS::RootedObject global(cx, JS_GetGlobalObject(cx));
    return JS_CallFunctionName(cx, global, "d", 0, NULL, &r);
}
开发者ID:JSilver99,项目名称:mozilla-central,代码行数:7,代码来源:testProfileStrings.cpp


示例16: JS_GetGlobalObject

nsresult
nsDOMWorkerTimeout::ExpressionCallback::Run(nsDOMWorkerTimeout* aTimeout,
                                            JSContext* aCx)
{
  JSObject* global = JS_GetGlobalObject(aCx);
  NS_ENSURE_TRUE(global, NS_ERROR_FAILURE);

  JSPrincipals* principal = nsDOMWorkerSecurityManager::WorkerPrincipal();
  NS_ENSURE_TRUE(principal, NS_ERROR_FAILURE);

  JSString* expression = JS_ValueToString(aCx, mExpression);
  NS_ENSURE_TRUE(expression, NS_ERROR_FAILURE);

  jschar* string = JS_GetStringChars(expression);
  NS_ENSURE_TRUE(string, NS_ERROR_FAILURE);

  size_t stringLength = JS_GetStringLength(expression);

  jsval rval;
  PRBool success = JS_EvaluateUCScriptForPrincipals(aCx, global, principal,
                                                    string, stringLength,
                                                    mFileName.get(),
                                                    mLineNumber, &rval);
  if (!success) {
    return NS_ERROR_FAILURE;
  }

  return NS_OK;
}
开发者ID:MozillaOnline,项目名称:gecko-dev,代码行数:29,代码来源:nsDOMWorkerTimeout.cpp


示例17: PJS_DefineFunction

PJS_Function *
PJS_DefineFunction(PJS_Context *inContext, const char *functionName, SV *perlCallback) {
    PJS_Function *function;
    JSContext    *js_context = inContext->cx;
    SV *sv;
    
    if (PJS_GetFunctionByName(inContext, functionName) != NULL) {
        warn("Function named '%s' is already defined in the context");
        return NULL;
    }
    
    if ((function = PJS_CreateFunction(functionName, perlCallback)) == NULL) {
        return NULL;
    }
    
    /* Add the function to the javascript context */
    if (JS_DefineFunction(js_context, JS_GetGlobalObject(js_context), functionName, PJS_invoke_perl_function, 0, 0) == JS_FALSE) {
        warn("Failed to define function");
        PJS_DestroyFunction(function);
        return NULL;
    }

    sv = newSV(0);
	sv_setref_pv(sv, "JavaScript::PerlFunction", (void*) function);
	
    if (functionName != NULL) {
        SvREFCNT_inc(sv);
        hv_store(inContext->function_by_name, functionName, strlen(functionName), sv, 0);
    }
    
    return function;
}
开发者ID:happygiraffe,项目名称:javascript,代码行数:32,代码来源:PJS_Context.c


示例18: gjs_explain_scope

void
gjs_explain_scope(JSContext  *context,
                  const char *title)
{
    JSContext *load_context;
    JSContext *call_context;
    JSObject *global;
    JSObject *parent;
    GString *chain;

    gjs_debug(GJS_DEBUG_SCOPE,
              "=== %s ===",
              title);

    load_context = gjs_runtime_peek_load_context(JS_GetRuntime(context));
    call_context = gjs_runtime_peek_call_context(JS_GetRuntime(context));

    JS_BeginRequest(context);
    JS_BeginRequest(load_context);
    JS_BeginRequest(call_context);

    JS_EnterLocalRootScope(context);

    gjs_debug(GJS_DEBUG_SCOPE,
              "  Context: %p %s",
              context,
              context == load_context ? "(LOAD CONTEXT)" :
              context == call_context ? "(CALL CONTEXT)" :
              "");

    global = JS_GetGlobalObject(context);
    gjs_debug(GJS_DEBUG_SCOPE,
              "  Global: %p %s",
              global, gjs_value_debug_string(context, OBJECT_TO_JSVAL(global)));

    parent = JS_GetScopeChain(context);
    chain = g_string_new(NULL);
    while (parent != NULL) {
        const char *debug;
        debug = gjs_value_debug_string(context, OBJECT_TO_JSVAL(parent));

        if (chain->len > 0)
            g_string_append(chain, ", ");

        g_string_append_printf(chain, "%p %s",
                               parent, debug);
        parent = JS_GetParent(context, parent);
    }
    gjs_debug(GJS_DEBUG_SCOPE,
              "  Chain: %s",
              chain->str);
    g_string_free(chain, TRUE);

    JS_LeaveLocalRootScope(context);

    JS_EndRequest(call_context);
    JS_EndRequest(load_context);
    JS_EndRequest(context);
}
开发者ID:sjokkis,项目名称:gjs,代码行数:59,代码来源:jsapi-util.c


示例19: DEBUGJS_InitClass

/**
 * initialize this JSClass
 */
JSObject *jhtml_tablerow_Init(JSContext *cx, JSObject *proto)
{
	//initialize the HTMLTableRowElement Class
	return DEBUGJS_InitClass(cx, JS_GetGlobalObject(cx), proto, &JSHtmlTableRowElement,
    				(JSNative) JHTMLTableRow, 0,
    				jhtml_tablerow_props, jhtml_tablerow_methods,
    				WEBC_NULL, WEBC_NULL);
}
开发者ID:peteratebs,项目名称:webcwebbrowser,代码行数:11,代码来源:jhtblrow.cpp


示例20: DEBUGJS_InitClass

JSObject *jhtml_textarea_Init(JSContext *cx, JSObject *proto)
{
	//initialize the HTMLTextAreaElement Class
	return DEBUGJS_InitClass(cx, JS_GetGlobalObject(cx), proto, &JSHtmlTextAreaElement,
    				(JSNative) JHTMLTextArea, 0,
    				jhtml_textarea_props, jhtml_textarea_methods,
    				WEBC_NULL, WEBC_NULL);
}
开发者ID:peteratebs,项目名称:webcwebbrowser,代码行数:8,代码来源:jhtarea.cpp



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ JS_GetInstancePrivate函数代码示例发布时间:2022-05-30
下一篇:
C++ JS_GetContextPrivate函数代码示例发布时间: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