Skip to content

Commit 19e0069

Browse files
committed
优化: execute 增加空值校验
1 parent dce96db commit 19e0069

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

native/cpp/quickjs_wrapper.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -780,12 +780,17 @@ jbyteArray QuickJSWrapper::compile(JNIEnv *env, jstring source, jstring file_nam
780780
return result;
781781
}
782782

783-
jobject QuickJSWrapper::execute(JNIEnv *env, jobject thiz, jbyteArray byteCode) {
784-
const auto buffer = env->GetByteArrayElements(byteCode, nullptr);
785-
const auto bufferLength = env->GetArrayLength(byteCode);
783+
jobject QuickJSWrapper::execute(JNIEnv *env, jobject thiz, jbyteArray bytecode) {
784+
if(bytecode == nullptr) {
785+
throwJSException(env, "bytecode can not be null");
786+
return nullptr;
787+
}
788+
789+
const auto buffer = env->GetByteArrayElements(bytecode, nullptr);
790+
const auto bufferLength = env->GetArrayLength(bytecode);
786791
const auto flags = JS_READ_OBJ_BYTECODE | JS_READ_OBJ_REFERENCE;
787792
auto obj = JS_ReadObject(context, reinterpret_cast<const uint8_t*>(buffer), bufferLength, flags);
788-
env->ReleaseByteArrayElements(byteCode, buffer, JNI_ABORT);
793+
env->ReleaseByteArrayElements(bytecode, buffer, JNI_ABORT);
789794

790795
if (JS_IsException(obj)) {
791796
throwJSException(env, context);

0 commit comments

Comments
 (0)