本文整理汇总了C++中JS_GC函数的典型用法代码示例。如果您正苦于以下问题:C++ JS_GC函数的具体用法?C++ JS_GC怎么用?C++ JS_GC使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了JS_GC函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PreWrap
static JSObject*
PreWrap(JSContext* cx, JS::HandleObject scope, JS::HandleObject obj,
JS::HandleObject objectPassedToWrap)
{
JS_GC(JS_GetRuntime(cx));
return obj;
}
示例2: shell_global_gc
/**
* shell_global_gc:
* @global: A #ShellGlobal
*
* Start a garbage collection process. For more information, see
* https://developer.mozilla.org/En/JS_GC
*/
void
shell_global_gc (ShellGlobal *global)
{
JSContext *context = gjs_context_get_native_context (global->js_context);
JS_GC (context);
}
示例3: gc
static JSBool
gc(JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval)
{
JS_GC(cx);
*rval = JSVAL_VOID;
return JS_TRUE;
}
示例4: JSCLASS_HAS_RESERVED_SLOTS
JSObject *newDelegate()
{
static const JSClass delegateClass = {
"delegate",
JSCLASS_GLOBAL_FLAGS | JSCLASS_HAS_RESERVED_SLOTS(1),
JS_PropertyStub,
JS_DeletePropertyStub,
JS_PropertyStub,
JS_StrictPropertyStub,
JS_EnumerateStub,
JS_ResolveStub,
JS_ConvertStub,
nullptr,
nullptr,
nullptr,
nullptr,
JS_GlobalObjectTraceHook
};
/* Create the global object. */
JS::CompartmentOptions options;
options.setVersion(JSVERSION_LATEST);
JS::RootedObject global(cx);
global = JS_NewGlobalObject(cx, &delegateClass, nullptr, JS::FireOnNewGlobalHook, options);
JS_SetReservedSlot(global, 0, JS::Int32Value(42));
/*
* Ensure the delegate is not in the nursery because for the purpose of this
* test we're going to put it in a private slot where it won't get updated.
*/
JS_GC(rt);
return global;
}
示例5: gc
static JSBool
gc(JSContext* cx, uintN argc, jsval* vp)
{
JS_GC(cx);
JS_SET_RVAL(cx, vp, JSVAL_VOID);
return JS_TRUE;
}
示例6: NS_ASSERTION
void
nsXREDirProvider::DoShutdown()
{
if (mProfileNotified) {
nsCOMPtr<nsIObserverService> obsSvc =
mozilla::services::GetObserverService();
NS_ASSERTION(obsSvc, "No observer service?");
if (obsSvc) {
static const char16_t kShutdownPersist[] = MOZ_UTF16("shutdown-persist");
obsSvc->NotifyObservers(nullptr, "profile-change-net-teardown", kShutdownPersist);
obsSvc->NotifyObservers(nullptr, "profile-change-teardown", kShutdownPersist);
// Phase 2c: Now that things are torn down, force JS GC so that things which depend on
// resources which are about to go away in "profile-before-change" are destroyed first.
JSRuntime *rt = xpc::GetJSRuntime();
if (rt) {
JS_GC(rt);
}
// Phase 3: Notify observers of a profile change
obsSvc->NotifyObservers(nullptr, "profile-before-change", kShutdownPersist);
obsSvc->NotifyObservers(nullptr, "profile-before-change2", kShutdownPersist);
}
mProfileNotified = false;
}
}
示例7: SameCompartmentWrap
static JSObject *
SameCompartmentWrap(JSContext *cx, JSObject *objArg)
{
JS::RootedObject obj(cx, objArg);
JS_GC(JS_GetRuntime(cx));
return obj;
}
示例8: js_gc
static JSBool
js_gc(JSContext *cx, uintN argc, jsval *arglist)
{
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
jsval *argv=JS_ARGV(cx, arglist);
JSBool forced=JS_TRUE;
js_callback_t* cb;
JS_SET_RVAL(cx, arglist, JSVAL_VOID);
if((cb=(js_callback_t*)JS_GetPrivate(cx,obj))==NULL)
return(JS_FALSE);
if(argc)
JS_ValueToBoolean(cx,argv[0],&forced);
if(forced)
JS_GC(cx);
else
JS_MaybeGC(cx);
cb->gc_attempts++;
return(JS_TRUE);
}
示例9: root
JS_NEVER_INLINE bool
cls_testIsAboutToBeFinalized_bug528645::createAndTestRooted()
{
jsvalRoot root(cx);
/*
* Check various types of GC things against JS_IsAboutToBeFinalized.
* Make sure to include unit and numeric strings to the set.
*/
EVAL("var x = 1.1; "
"[''+x, 'a', '123456789', 'something'.substring(1), "
"{}, [], new Function('return 10;'), <xml/>];",
root.addr());
JSObject *array = JSVAL_TO_OBJECT(root.value());
JS_ASSERT(JS_IsArrayObject(cx, array));
JSBool ok = JS_GetArrayLength(cx, array, &checkPointersLength);
CHECK(ok);
checkPointers = (void **) malloc(sizeof(void *) * checkPointersLength);
CHECK(checkPointers);
checkPointersStaticStrings = 0;
for (jsuint i = 0; i != checkPointersLength; ++i) {
jsval v;
ok = JS_GetElement(cx, array, i, &v);
CHECK(ok);
JS_ASSERT(JSVAL_IS_GCTHING(v));
JS_ASSERT(!JSVAL_IS_NULL(v));
checkPointers[i] = JSVAL_TO_GCTHING(v);
if (JSString::isStatic(checkPointers[i]))
++checkPointersStaticStrings;
}
oldGCCallback = JS_SetGCCallback(cx, TestAboutToBeFinalizedCallback);
JS_GC(cx);
/*
* All GC things are rooted via the root holding the array containing them
* and TestAboutToBeFinalizedCallback must keep them as is.
*/
for (jsuint i = 0; i != checkPointersLength; ++i)
CHECK(checkPointers[i]);
/*
* Overwrite the registers and stack with new GC things to avoid false
* positives with the finalization test.
*/
EVAL("[]", root.addr());
array = JSVAL_TO_OBJECT(root.value());
JS_ASSERT(JS_IsArrayObject(cx, array));
jsuint tmp;
CHECK(JS_GetArrayLength(cx, array, &tmp));
CHECK(ok);
return true;
}
示例10: PreWrap
static void
PreWrap(JSContext* cx, JS::HandleObject scope, JS::HandleObject obj,
JS::HandleObject objectPassedToWrap,
JS::MutableHandleObject retObj)
{
JS_GC(cx);
retObj.set(obj);
}
示例11: PreWrap
static JSObject *
PreWrap(JSContext *cx, JSObject *scopeArg, JSObject *objArg, unsigned flags)
{
JS::RootedObject scope(cx, scopeArg);
JS::RootedObject obj(cx, objArg);
JS_GC(JS_GetRuntime(cx));
return obj;
}
示例12: EmptyTrapHandler
static JSTrapStatus
EmptyTrapHandler(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval,
jsval closure)
{
JS_GC(JS_GetRuntime(cx));
if (JSVAL_IS_STRING(closure))
++emptyTrapCallCount;
return JSTRAP_CONTINUE;
}
示例13: JS_DumpHeap
void ScriptInterface::DumpHeap()
{
#if MOZJS_DEBUG_ABI
JS_DumpHeap(GetJSRuntime(), stderr, NULL, JSTRACE_OBJECT, NULL, (size_t)-1, NULL);
#endif
fprintf(stderr, "# Bytes allocated: %u\n", JS_GetGCParameter(GetJSRuntime(), JSGC_BYTES));
JS_GC(GetJSRuntime());
fprintf(stderr, "# Bytes allocated after GC: %u\n", JS_GetGCParameter(GetJSRuntime(), JSGC_BYTES));
}
示例14: AfxGlobal_gc
static JSBool
AfxGlobal_gc(JSContext *cx, unsigned argc, JS::Value *vp)
{
JS::CallReceiver rec = JS::CallReceiverFromVp(vp);
JS_GC(g_JsRt);
rec.rval().set(JSVAL_VOID);
return JS_TRUE;
}
示例15: JS_SetContextThread
JsExecutionContext::~JsExecutionContext()
{
JS_SetContextThread(cx);
JS_GC(cx);
JS_BeginRequest(cx);
JS_ClearScope(cx, obj);
JS_EndRequest(cx);
JS_ClearContextThread(cx);
JS_DestroyContext(cx);
JS_DestroyRuntime(rt);
}