summaryrefslogtreecommitdiffstats
path: root/js/src/jsapi-tests/testErrorInterceptorGC.cpp
blob: 83ceecdb1a44c035af13e7de7d0d8ff6b81ea6c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "jsapi.h"

#include "jsapi-tests/tests.h"

namespace {

// An interceptor that triggers GC:
struct ErrorInterceptorWithGC : JSErrorInterceptor {
  void interceptError(JSContext* cx, JS::HandleValue val) override {
    JS::PrepareForFullGC(cx);
    JS::NonIncrementalGC(cx, GC_SHRINK, JS::GCReason::DEBUG_GC);
  }
};

}  // namespace

BEGIN_TEST(testErrorInterceptorGC) {
  JSErrorInterceptor* original = JS_GetErrorInterceptorCallback(cx->runtime());

  ErrorInterceptorWithGC interceptor;
  JS_SetErrorInterceptorCallback(cx->runtime(), &interceptor);

  CHECK(!execDontReport("0 = 0;", __FILE__, __LINE__));

  CHECK(JS_IsExceptionPending(cx));
  JS_ClearPendingException(cx);

  // Restore the original error interceptor.
  JS_SetErrorInterceptorCallback(cx->runtime(), original);

  return true;
}
END_TEST(testErrorInterceptorGC)