-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Add test with complex callback that returns complex return type …
…(ArrayBuffer) (#441) * fix: Add test with complex callback that returns complex return type (ArrayBuffer) * Update HybridTestObjectCpp.cpp * fix: Don't use `borrowing` when copying
- Loading branch information
Showing
24 changed files
with
515 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/// | ||
/// JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____.hpp | ||
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. | ||
/// https://github.com/mrousavy/nitro | ||
/// Copyright © 2024 Marc Rousavy @ Margelo | ||
/// | ||
|
||
#pragma once | ||
|
||
#include <fbjni/fbjni.h> | ||
#include <functional> | ||
|
||
#include <functional> | ||
#include <NitroModules/Promise.hpp> | ||
#include <NitroModules/ArrayBuffer.hpp> | ||
#include <NitroModules/JPromise.hpp> | ||
#include <NitroModules/JArrayBuffer.hpp> | ||
#include <NitroModules/JUnit.hpp> | ||
|
||
namespace margelo::nitro::image { | ||
|
||
using namespace facebook; | ||
|
||
/** | ||
* C++ representation of the callback Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____. | ||
* This is a Kotlin `() -> Promise<Promise<ArrayBuffer>>`, backed by a `std::function<...>`. | ||
*/ | ||
struct JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____ final: public jni::HybridClass<JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____> { | ||
public: | ||
static jni::local_ref<JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____::javaobject> fromCpp(const std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::shared_ptr<ArrayBuffer>>>>>()>& func) { | ||
return JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____::newObjectCxxArgs(func); | ||
} | ||
|
||
public: | ||
jni::local_ref<JPromise::javaobject> call() { | ||
std::shared_ptr<Promise<std::shared_ptr<Promise<std::shared_ptr<ArrayBuffer>>>>> __result = _func(); | ||
return [&]() { | ||
jni::local_ref<JPromise::javaobject> __localPromise = JPromise::create(); | ||
jni::global_ref<JPromise::javaobject> __promise = jni::make_global(__localPromise); | ||
__result->addOnResolvedListener([=](const std::shared_ptr<Promise<std::shared_ptr<ArrayBuffer>>>& __result) { | ||
__promise->cthis()->resolve([&]() { | ||
jni::local_ref<JPromise::javaobject> __localPromise = JPromise::create(); | ||
jni::global_ref<JPromise::javaobject> __promise = jni::make_global(__localPromise); | ||
__result->addOnResolvedListener([=](const std::shared_ptr<ArrayBuffer>& __result) { | ||
__promise->cthis()->resolve(JArrayBuffer::wrap(__result)); | ||
}); | ||
__result->addOnRejectedListener([=](const std::exception_ptr& __error) { | ||
auto __jniError = jni::getJavaExceptionForCppException(__error); | ||
__promise->cthis()->reject(__jniError); | ||
}); | ||
return __localPromise; | ||
}()); | ||
}); | ||
__result->addOnRejectedListener([=](const std::exception_ptr& __error) { | ||
auto __jniError = jni::getJavaExceptionForCppException(__error); | ||
__promise->cthis()->reject(__jniError); | ||
}); | ||
return __localPromise; | ||
}(); | ||
} | ||
|
||
public: | ||
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/image/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____;"; | ||
static void registerNatives() { | ||
registerHybrid({makeNativeMethod("call", JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____::call)}); | ||
} | ||
|
||
private: | ||
explicit JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____(const std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::shared_ptr<ArrayBuffer>>>>>()>& func): _func(func) { } | ||
|
||
private: | ||
friend HybridBase; | ||
std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::shared_ptr<ArrayBuffer>>>>>()> _func; | ||
}; | ||
|
||
} // namespace margelo::nitro::image |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
.../Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/// | ||
/// Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____.kt | ||
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. | ||
/// https://github.com/mrousavy/nitro | ||
/// Copyright © 2024 Marc Rousavy @ Margelo | ||
/// | ||
|
||
package com.margelo.nitro.image | ||
|
||
import androidx.annotation.Keep | ||
import com.facebook.jni.HybridData | ||
import com.facebook.proguard.annotations.DoNotStrip | ||
import com.margelo.nitro.core.* | ||
import dalvik.annotation.optimization.FastNative | ||
|
||
/** | ||
* Represents the JavaScript callback `() => std::shared_ptr<Promise<std::shared_ptr<Promise<std::shared_ptr<ArrayBuffer>>>>>`. | ||
* This is implemented in C++, via a `std::function<...>`. | ||
*/ | ||
@DoNotStrip | ||
@Keep | ||
@Suppress("RedundantSuppression", "ConvertSecondaryConstructorToPrimary", "RedundantUnitReturnType", "KotlinJniMissingFunction", "ClassName", "unused") | ||
class Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____ { | ||
@DoNotStrip | ||
@Keep | ||
private val mHybridData: HybridData | ||
|
||
@DoNotStrip | ||
@Keep | ||
private constructor(hybridData: HybridData) { | ||
mHybridData = hybridData | ||
} | ||
|
||
/** | ||
* Converts this function to a Kotlin Lambda. | ||
* This exists purely as syntactic sugar, and has minimal runtime overhead. | ||
*/ | ||
fun toLambda(): () -> Promise<Promise<ArrayBuffer>> = this::call | ||
|
||
/** | ||
* Call the given JS callback. | ||
* @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted. | ||
*/ | ||
@FastNative | ||
external fun call(): Promise<Promise<ArrayBuffer>> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.