testErrorInterceptorGC.cpp (869B)
1 #include "js/ErrorInterceptor.h" 2 #include "jsapi-tests/tests.h" 3 4 namespace { 5 6 // An interceptor that triggers GC: 7 struct ErrorInterceptorWithGC : JSErrorInterceptor { 8 void interceptError(JSContext* cx, JS::HandleValue val) override { 9 JS::PrepareForFullGC(cx); 10 JS::NonIncrementalGC(cx, JS::GCOptions::Shrink, JS::GCReason::DEBUG_GC); 11 } 12 }; 13 14 } // namespace 15 16 BEGIN_TEST(testErrorInterceptorGC) { 17 JSErrorInterceptor* original = JS_GetErrorInterceptorCallback(cx->runtime()); 18 19 ErrorInterceptorWithGC interceptor; 20 JS_SetErrorInterceptorCallback(cx->runtime(), &interceptor); 21 22 CHECK(!execDontReport("0 = 0;", __FILE__, __LINE__)); 23 24 CHECK(JS_IsExceptionPending(cx)); 25 JS_ClearPendingException(cx); 26 27 // Restore the original error interceptor. 28 JS_SetErrorInterceptorCallback(cx->runtime(), original); 29 30 return true; 31 } 32 END_TEST(testErrorInterceptorGC)