summaryrefslogtreecommitdiffstats
path: root/js/src/jsapi-tests/testErrorInterceptorGC.cpp
blob: 67dac2f2dd216e2f071081c4a01ba73d1d8d3114 (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
#include "js/ErrorInterceptor.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, JS::GCOptions::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)