2019-12-02 05:21:56 -08:00
|
|
|
/*
|
2021-12-30 15:08:43 -08:00
|
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
2019-12-02 05:21:56 -08:00
|
|
|
*
|
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
|
|
|
*/
|
|
|
|
|
2023-09-13 20:12:55 -07:00
|
|
|
#include "YogaJniException.h"
|
2019-12-02 05:21:56 -08:00
|
|
|
#include <stdexcept>
|
|
|
|
#include <string>
|
|
|
|
#include "common.h"
|
|
|
|
|
2023-07-12 09:38:40 -07:00
|
|
|
namespace facebook::yoga::vanillajni {
|
2019-12-02 05:21:56 -08:00
|
|
|
|
|
|
|
YogaJniException::YogaJniException() {
|
2022-08-30 18:49:10 -07:00
|
|
|
jclass cl = getCurrentEnv()->FindClass("java/lang/RuntimeException");
|
2019-12-02 05:21:56 -08:00
|
|
|
static const jmethodID methodId = facebook::yoga::vanillajni::getMethodId(
|
|
|
|
getCurrentEnv(), cl, "<init>", "()V");
|
|
|
|
auto throwable = getCurrentEnv()->NewObject(cl, methodId);
|
2019-12-03 15:57:51 -08:00
|
|
|
throwable_ =
|
|
|
|
newGlobalRef(getCurrentEnv(), static_cast<jthrowable>(throwable));
|
2019-12-02 05:21:56 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
YogaJniException::YogaJniException(jthrowable throwable) {
|
2019-12-03 15:57:51 -08:00
|
|
|
throwable_ = newGlobalRef(getCurrentEnv(), throwable);
|
2019-12-02 05:21:56 -08:00
|
|
|
}
|
|
|
|
|
2024-03-02 23:11:50 -08:00
|
|
|
YogaJniException::YogaJniException(YogaJniException&& rhs) noexcept
|
2019-12-02 05:21:56 -08:00
|
|
|
: throwable_(std::move(rhs.throwable_)) {}
|
|
|
|
|
|
|
|
YogaJniException::YogaJniException(const YogaJniException& rhs) {
|
2019-12-03 15:57:51 -08:00
|
|
|
throwable_ = newGlobalRef(getCurrentEnv(), rhs.throwable_.get());
|
2019-12-02 05:21:56 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
YogaJniException::~YogaJniException() {
|
|
|
|
try {
|
|
|
|
throwable_.reset();
|
|
|
|
} catch (...) {
|
|
|
|
std::terminate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ScopedLocalRef<jthrowable> YogaJniException::getThrowable() const noexcept {
|
2019-12-03 15:57:51 -08:00
|
|
|
return make_local_ref(
|
|
|
|
getCurrentEnv(),
|
|
|
|
static_cast<jthrowable>(getCurrentEnv()->NewLocalRef(throwable_.get())));
|
2019-12-02 05:21:56 -08:00
|
|
|
}
|
2023-07-12 09:38:40 -07:00
|
|
|
|
|
|
|
} // namespace facebook::yoga::vanillajni
|