Files
yoga/java/jni/corefunctions.h
Sidharth Guglani ac8eb111a9 Add defensive check for result returned after JNI function calls
Summary:
Added method which checks if value(methodId, fieldId, class ...) returned by JNI functions (getMethod, getField, getClass ...) is valid or not and throw exception if they are not valid

##Changelog:
[Internal][Yoga] Add defensive check for result returned after JNI calls

Reviewed By: astreet

Differential Revision: D18745718

fbshipit-source-id: 2af26eda15fbe7834e1c9b274deeed4f106274ab
2019-12-02 05:24:54 -08:00

55 lines
1.6 KiB
C++

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <jni.h>
#include <cstddef>
namespace facebook {
namespace yoga {
namespace vanillajni {
/**
* This method has to be called before using the vanillajni library. This method
* is typically called when doing initialization in the "on load" JNI hook of a
* particular library.
*
* This method is thread safe, and after the first time it's called it has no
* initialization effect.
*
* @param env use this output parameter to get a JNIEnv to use for things such
* as registering native methods and such.
* @param vm the VM instance passed by JNI. This is usually the VM instance
* that is passed to the "on load" JNI hook.
* @return an integer value to return from the "on load" hook.
*/
jint ensureInitialized(JNIEnv** env, JavaVM* vm);
/**
* Returns a JNIEnv* suitable for the current thread. If the current thread is
* not attached to the Java VM, this method aborts execution.
*/
JNIEnv* getCurrentEnv();
/**
* Logs an error message and aborts the current process.
*/
void logErrorMessageAndDie(const char* message);
/**
* Checks whether there is a pending JNI exception. If so, it logs an error
* message and aborts the current process. Otherwise it does nothing.
*/
void assertNoPendingJniException(JNIEnv* env);
void assertNoPendingJniExceptionIf(JNIEnv* env, bool condition);
} // namespace vanillajni
} // namespace yoga
} // namespace facebook