js/src/jsapi-tests/testErrorInterceptorGC.cpp
author criss <ccozmuta@mozilla.com>
Sat, 02 Jul 2022 00:35:27 +0300
changeset 622844 5140fba12e4a4c58953227b0ba20efbefbf8086b
parent 589452 01fc3504c9844fc6dbf61e8a0a39bcadc81201bd
permissions -rw-r--r--
Merge autoland to mozilla-central. a=merge

#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)