Skip to content

Commit a4d6e42

Browse files
committed
🔧
1 parent 2b67e2c commit a4d6e42

3 files changed

Lines changed: 0 additions & 152 deletions

File tree

packages/webgpu/cpp/jsi/NativeObject.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include <unordered_map>
1515
#include <utility>
1616

17-
#include "RNFJSIHelper.h"
1817
#include "WGPULogger.h"
1918

2019
// Forward declare to avoid circular dependency

packages/webgpu/cpp/jsi/RNFJSIConverter.h

Lines changed: 0 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@
55
#pragma once
66

77
#include <memory>
8-
#include <array>
9-
#include <future>
108
#include <vector>
119
#include <string>
1210
#include <utility>
1311
#include <type_traits>
14-
#include <unordered_map>
1512
#include <limits>
1613
#include <variant>
1714
#include <map>
@@ -20,7 +17,6 @@
2017
#include <jsi/jsi.h>
2118

2219
#include "RNFEnumMapper.h"
23-
#include "RNFJSIHelper.h"
2420
#include "RNFPromise.h"
2521

2622
#include "Unions.h"
@@ -275,102 +271,6 @@ template <typename ElementType> struct JSIConverter<std::vector<ElementType>> {
275271
}
276272
};
277273

278-
// std::unordered_map<std::string, T> <> Record<string, T>
279-
template <typename ValueType> struct JSIConverter<std::unordered_map<std::string, ValueType>> {
280-
static std::unordered_map<std::string, ValueType> fromJSI(jsi::Runtime& runtime, const jsi::Value& arg, bool outOfBound) {
281-
jsi::Object object = arg.asObject(runtime);
282-
jsi::Array propertyNames = object.getPropertyNames(runtime);
283-
size_t length = propertyNames.size(runtime);
284-
285-
std::unordered_map<std::string, ValueType> map;
286-
map.reserve(length);
287-
for (size_t i = 0; i < length; ++i) {
288-
std::string key = propertyNames.getValueAtIndex(runtime, i).asString(runtime).utf8(runtime);
289-
jsi::Value value = object.getProperty(runtime, key.c_str());
290-
map.emplace(key, JSIConverter<ValueType>::fromJSI(runtime, value, outOfBound));
291-
}
292-
return map;
293-
}
294-
static jsi::Value toJSI(jsi::Runtime& runtime, const std::unordered_map<std::string, ValueType>& map) {
295-
jsi::Object object(runtime);
296-
for (const auto& pair : map) {
297-
jsi::Value value = JSIConverter<ValueType>::toJSI(runtime, pair.second);
298-
jsi::String key = jsi::String::createFromUtf8(runtime, pair.first);
299-
object.setProperty(runtime, key, std::move(value));
300-
}
301-
return object;
302-
}
303-
};
304-
305-
// HostObject (non-NativeState) <> {}
306-
template <typename T> struct is_shared_ptr_to_host_object : std::false_type {};
307-
308-
// Only match HostObject types that are NOT NativeState types
309-
template <typename T>
310-
struct is_shared_ptr_to_host_object<std::shared_ptr<T>>
311-
: std::bool_constant<std::is_base_of_v<jsi::HostObject, T> &&
312-
!std::is_base_of_v<jsi::NativeState, T>> {};
313-
314-
template <typename T> struct JSIConverter<T, std::enable_if_t<is_shared_ptr_to_host_object<T>::value>> {
315-
using TPointee = typename T::element_type;
316-
317-
#if DEBUG
318-
inline static std::string getFriendlyTypename() {
319-
std::string name = std::string(typeid(TPointee).name());
320-
#if __has_include(<cxxabi.h>)
321-
int status = 0;
322-
char* demangled_name = abi::__cxa_demangle(name.c_str(), NULL, NULL, &status);
323-
if (status == 0) {
324-
name = demangled_name;
325-
std::free(demangled_name);
326-
}
327-
#endif
328-
return name;
329-
}
330-
331-
inline static std::string invalidTypeErrorMessage(const std::string& typeDescription, const std::string& reason) {
332-
return "Cannot convert \"" + typeDescription + "\" to HostObject<" + getFriendlyTypename() + ">! " + reason;
333-
}
334-
#endif
335-
336-
static T fromJSI(jsi::Runtime& runtime, const jsi::Value& arg, bool outOfBound) {
337-
#if DEBUG
338-
if (arg.isUndefined()) {
339-
[[unlikely]];
340-
throw jsi::JSError(runtime, invalidTypeErrorMessage("undefined", "It is undefined!"));
341-
}
342-
if (!arg.isObject()) {
343-
[[unlikely]];
344-
std::string stringRepresentation = arg.toString(runtime).utf8(runtime);
345-
throw jsi::JSError(runtime, invalidTypeErrorMessage(stringRepresentation, "It is not an object!"));
346-
}
347-
#endif
348-
jsi::Object object = arg.getObject(runtime);
349-
#if DEBUG
350-
if (!object.isHostObject<TPointee>(runtime)) {
351-
[[unlikely]];
352-
std::string stringRepresentation = arg.toString(runtime).utf8(runtime);
353-
throw jsi::JSError(runtime, invalidTypeErrorMessage(stringRepresentation, "It is a different HostObject<T>!"));
354-
}
355-
#endif
356-
return object.getHostObject<TPointee>(runtime);
357-
}
358-
static jsi::Value toJSI(jsi::Runtime& runtime, const T& arg) {
359-
#if DEBUG
360-
if (arg == nullptr) {
361-
[[unlikely]];
362-
throw jsi::JSError(runtime, "Cannot convert nullptr to HostObject<" + getFriendlyTypename() + ">!");
363-
}
364-
#endif
365-
auto result = jsi::Object::createFromHostObject(runtime, arg);
366-
auto memoryPressure = arg->getMemoryPressure();
367-
if (memoryPressure > 0) {
368-
result.setExternalMemoryPressure(runtime, memoryPressure);
369-
}
370-
return result;
371-
}
372-
};
373-
374274
// NativeState <> {}
375275
template <typename T> struct is_shared_ptr_to_native_state : std::false_type {};
376276

packages/webgpu/cpp/jsi/RNFJSIHelper.h

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)