Skip to content

Fix TODOs in the TurboModule implementation #30

Description

@kraenhansen

Umbrella for the TODO/FIXME markers left in the C++ TurboModule implementation.

Note

The permalinks originally in this issue pointed at react-native-node-api-modules and the pre-rename packages/react-native-node-api-modules/cpp/ paths, so none of them resolved any more. Refreshed below against 29a527d, with each marker mapped to the issue that now covers it.

CxxNodeApiHostModule.cpprequireNodeAddon returns undefined on bad arguments

CxxNodeApiHostModule::requireNodeAddon(jsi::Runtime &rt,
react::TurboModule &turboModule,
const jsi::Value args[], size_t count) {
auto &thisModule = static_cast<CxxNodeApiHostModule &>(turboModule);
if (1 == count && args[0].isString()) {
return thisModule.requireNodeAddon(rt, args[0].asString(rt));
}
// TODO: Throw a meaningful error
return jsi::Value::undefined();
}

Covered by #50.

CxxNodeApiHostModule.cpp — the addon's declared Node-API version is never read

https://github.com/callstackincubator/react-native-node-api/blob/29a527d87fa8cb965b0048b1b4c1cff2b0eab281/packages/host/cpp/CxxNodeApiHostModule.cpp#L127-L131

https://github.com/callstackincubator/react-native-node-api/blob/29a527d87fa8cb965b0048b1b4c1cff2b0eab281/packages/host/cpp/CxxNodeApiHostModule.cpp#L142-L145

Covered by #4 (sub-issue), which also depends on #3 for the napi_module_register half. Both call sites already carry @see links to #4 in the source.

CxxNodeApiHostModule.hpp + AddonLoaders.hpp — Windows loaders

The LoaderPolicy alias is hardcoded to PosixLoader, so Win32Loader/WinRTLoader are never selected, and all four Windows failure paths detect an error and discard it instead of calling GetLastError():

using LoaderPolicy = PosixLoader; // FIXME: HACK: This is temporary workaround
// for my lazyness (work on iOS and Android)

#if defined(_WIN32)
struct Win32Loader {
using Module = HMODULE;
using Symbol = void *;
static Module loadLibrary(const char *filePath) {
assert(NULL != filePath);
Module result = LoadLibrary(filePath);
if (NULL == result) {
// TODO: Handle the error case... call GetLastError() that gives us error
// code as DWORD
}
return result;
}
static Symbol getSymbol(Module library, const char *name) {
assert(NULL != library);
assert(NULL != name);
Symbol result = GetProcAddress(library, name);
if (NULL == result) {
// TODO: Handle the error case... call GetLastError() that gives us error
// code as DWORD
}
return result;
}
static void unloadLibrary(Module library) {
if (NULL != library) {
FreeLibrary(library);
}
}
};
struct WinRTLoader {
using Module = HMODULE;
using Symbol = void *;
static Module loadLibrary(const char *filePath) {
assert(NULL != filePath);
Module result = LoadPackagedLibrary(filePath);
if (NULL == result) {
// TODO: Handle the error case... call GetLastError() that gives us error
// code as DWORD
}
return result;
}
static Symbol getSymbol(Module library, const char *name) {
assert(NULL != library);
assert(NULL != name);
Symbol result = GetProcAddress(library, name);
if (NULL == result) {
// TODO: Handle the error case... call GetLastError() that gives us error
// code as DWORD
}
return result;

Covered by #419.

Markers added since this issue was filed

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions