当前位置: 首页>>代码示例>>C++>>正文


C++ JS_GetGlobalObject函数代码示例

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


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


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