react-native-mmkv 2.7.0 → 2.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/MMKV/Core/Core.xcodeproj/project.pbxproj +15 -19
  2. package/MMKV/Core/Core.xcodeproj/xcshareddata/xcschemes/Core.xcscheme +1 -1
  3. package/MMKV/Core/Core.xcodeproj/xcshareddata/xcschemes/MMKVWatchCore.xcscheme +1 -1
  4. package/MMKV/Core/MMBuffer.cpp +18 -0
  5. package/MMKV/Core/MMBuffer.h +1 -0
  6. package/MMKV/Core/MMKV.cpp +173 -33
  7. package/MMKV/Core/MMKV.h +44 -0
  8. package/MMKV/Core/MMKVMetaInfo.hpp +18 -0
  9. package/MMKV/Core/MMKVPredef.h +2 -2
  10. package/MMKV/Core/MMKV_IO.cpp +477 -68
  11. package/MMKV/Core/MMKV_OSX.cpp +65 -14
  12. package/MMKV/Core/MemoryFile_Win32.cpp +39 -35
  13. package/MMKV/Core/MiniPBCoder.cpp +3 -7
  14. package/MMKV/Core/MiniPBCoder_OSX.cpp +4 -4
  15. package/MMKV/Core/PBUtility.cpp +1 -1
  16. package/MMKV/Core/PBUtility.h +7 -0
  17. package/MMKV/Core/aes/AESCrypt.h +1 -1
  18. package/MMKV/Core/aes/openssl/openssl_aes-armv4.S +4 -0
  19. package/README.md +14 -6
  20. package/android/build.gradle +2 -0
  21. package/android/src/main/AndroidManifest.xml +1 -2
  22. package/android/src/main/cpp/cpp-adapter.cpp +5 -0
  23. package/cpp/TypedArray.cpp +187 -199
  24. package/cpp/TypedArray.h +112 -109
  25. package/ios/JSIUtils.mm +2 -1
  26. package/ios/MmkvModule.mm +12 -7
  27. package/lib/commonjs/MMKV.js +0 -10
  28. package/lib/commonjs/MMKV.js.map +1 -1
  29. package/lib/commonjs/createMMKV.web.js +55 -12
  30. package/lib/commonjs/createMMKV.web.js.map +1 -1
  31. package/lib/commonjs/hooks.js +7 -0
  32. package/lib/commonjs/hooks.js.map +1 -1
  33. package/lib/module/MMKV.js +0 -10
  34. package/lib/module/MMKV.js.map +1 -1
  35. package/lib/module/createMMKV.web.js +55 -12
  36. package/lib/module/createMMKV.web.js.map +1 -1
  37. package/lib/module/hooks.js +7 -0
  38. package/lib/module/hooks.js.map +1 -1
  39. package/lib/typescript/MMKV.d.ts +0 -12
  40. package/lib/typescript/MMKV.d.ts.map +1 -1
  41. package/lib/typescript/createMMKV.web.d.ts.map +1 -1
  42. package/lib/typescript/hooks.d.ts.map +1 -1
  43. package/package.json +15 -10
  44. package/src/MMKV.ts +248 -0
  45. package/src/PlatformChecker.ts +7 -0
  46. package/src/createMMKV.mock.ts +33 -0
  47. package/src/createMMKV.ts +70 -0
  48. package/src/createMMKV.web.ts +119 -0
  49. package/src/createTextEncoder.ts +16 -0
  50. package/src/hooks.ts +232 -0
  51. package/src/index.ts +2 -0
  52. package/MMKV/LICENSE.TXT +0 -193
  53. package/MMKV/README.md +0 -291
@@ -9,62 +9,70 @@
9
9
  #include "TypedArray.h"
10
10
 
11
11
  #include <unordered_map>
12
+ #include <memory>
13
+ #include <utility>
14
+ #include <vector>
15
+ #include <algorithm>
16
+ #include <string>
12
17
 
13
18
  template <TypedArrayKind T>
14
19
  using ContentType = typename typedArrayTypeMap<T>::type;
15
20
 
16
- enum class Prop
17
- {
18
- Buffer, // "buffer"
19
- Constructor, // "constructor"
20
- Name, // "name"
21
- Proto, // "__proto__"
22
- Length, // "length"
23
- ByteLength, // "byteLength"
24
- ByteOffset, // "offset"
25
- IsView, // "isView"
26
- ArrayBuffer, // "ArrayBuffer"
27
- Int8Array, // "Int8Array"
28
- Int16Array, // "Int16Array"
29
- Int32Array, // "Int32Array"
30
- Uint8Array, // "Uint8Array"
31
- Uint8ClampedArray, // "Uint8ClampedArray"
32
- Uint16Array, // "Uint16Array"
33
- Uint32Array, // "Uint32Array"
34
- Float32Array, // "Float32Array"
35
- Float64Array, // "Float64Array"
21
+ enum class Prop {
22
+ Buffer, // "buffer"
23
+ Constructor, // "constructor"
24
+ Name, // "name"
25
+ Proto, // "__proto__"
26
+ Length, // "length"
27
+ ByteLength, // "byteLength"
28
+ ByteOffset, // "offset"
29
+ IsView, // "isView"
30
+ ArrayBuffer, // "ArrayBuffer"
31
+ Int8Array, // "Int8Array"
32
+ Int16Array, // "Int16Array"
33
+ Int32Array, // "Int32Array"
34
+ Uint8Array, // "Uint8Array"
35
+ Uint8ClampedArray, // "Uint8ClampedArray"
36
+ Uint16Array, // "Uint16Array"
37
+ Uint32Array, // "Uint32Array"
38
+ Float32Array, // "Float32Array"
39
+ Float64Array, // "Float64Array"
36
40
  };
37
41
 
38
- class PropNameIDCache
39
- {
40
- public:
41
- const jsi::PropNameID &get(jsi::Runtime &runtime, Prop prop)
42
- {
43
- if (!this->props[prop])
44
- {
45
- this->props[prop] = std::make_unique<jsi::PropNameID>(createProp(runtime, prop));
46
- }
47
- return *(this->props[prop]);
42
+ class PropNameIDCache {
43
+ public:
44
+ const jsi::PropNameID &get(jsi::Runtime &runtime, Prop prop) {
45
+ auto key = reinterpret_cast<uintptr_t>(&runtime);
46
+ if (this->props.find(key) == this->props.end()) {
47
+ this->props[key] = std::unordered_map<Prop, std::unique_ptr<jsi::PropNameID>>();
48
48
  }
49
+ if (!this->props[key][prop]) {
50
+ this->props[key][prop] = std::make_unique<jsi::PropNameID>(createProp(runtime, prop));
51
+ }
52
+ return *(this->props[key][prop]);
53
+ }
49
54
 
50
- const jsi::PropNameID &getConstructorNameProp(jsi::Runtime &runtime, TypedArrayKind kind);
55
+ const jsi::PropNameID &getConstructorNameProp(jsi::Runtime &runtime, TypedArrayKind kind);
51
56
 
52
- void invalidate()
53
- {
54
- props.erase(props.begin(), props.end());
57
+ void invalidate(uintptr_t key) {
58
+ if (props.find(key) != props.end()) {
59
+ props[key].clear();
55
60
  }
61
+ }
56
62
 
57
- private:
58
- std::unordered_map<Prop, std::unique_ptr<jsi::PropNameID>> props;
63
+ private:
64
+ std::unordered_map<uintptr_t, std::unordered_map<Prop, std::unique_ptr<jsi::PropNameID>>> props;
59
65
 
60
- jsi::PropNameID createProp(jsi::Runtime &runtime, Prop prop);
66
+ jsi::PropNameID createProp(jsi::Runtime &runtime, Prop prop);
61
67
  };
62
68
 
63
69
  PropNameIDCache propNameIDCache;
64
70
 
65
- void invalidateJsiPropNameIDCache()
66
- {
67
- propNameIDCache.invalidate();
71
+ InvalidateCacheOnDestroy::InvalidateCacheOnDestroy(jsi::Runtime &runtime) {
72
+ key = reinterpret_cast<uintptr_t>(&runtime);
73
+ }
74
+ InvalidateCacheOnDestroy::~InvalidateCacheOnDestroy() {
75
+ propNameIDCache.invalidate(key);
68
76
  }
69
77
 
70
78
  TypedArrayKind getTypedArrayKindForName(const std::string &name);
@@ -82,235 +90,216 @@ TypedArrayBase::TypedArrayBase(jsi::Runtime &runtime, size_t size, TypedArrayKin
82
90
  TypedArrayBase::TypedArrayBase(jsi::Runtime &runtime, const jsi::Object &obj)
83
91
  : jsi::Object(jsi::Value(runtime, obj).asObject(runtime)) {}
84
92
 
85
- TypedArrayKind TypedArrayBase::getKind(jsi::Runtime &runtime) const
86
- {
87
- auto constructorName = this->getProperty(runtime, propNameIDCache.get(runtime, Prop::Constructor))
88
- .asObject(runtime)
89
- .getProperty(runtime, propNameIDCache.get(runtime, Prop::Name))
90
- .asString(runtime)
91
- .utf8(runtime);
92
- return getTypedArrayKindForName(constructorName);
93
- };
93
+ TypedArrayKind TypedArrayBase::getKind(jsi::Runtime &runtime) const {
94
+ auto constructorName = this->getProperty(runtime, propNameIDCache.get(runtime, Prop::Constructor))
95
+ .asObject(runtime)
96
+ .getProperty(runtime, propNameIDCache.get(runtime, Prop::Name))
97
+ .asString(runtime)
98
+ .utf8(runtime);
99
+ return getTypedArrayKindForName(constructorName);
100
+ }
94
101
 
95
- size_t TypedArrayBase::size(jsi::Runtime &runtime) const
96
- {
97
- return getProperty(runtime, propNameIDCache.get(runtime, Prop::Length)).asNumber();
102
+ size_t TypedArrayBase::size(jsi::Runtime &runtime) const {
103
+ return getProperty(runtime, propNameIDCache.get(runtime, Prop::Length)).asNumber();
98
104
  }
99
105
 
100
- size_t TypedArrayBase::length(jsi::Runtime &runtime) const
101
- {
102
- return getProperty(runtime, propNameIDCache.get(runtime, Prop::Length)).asNumber();
106
+ size_t TypedArrayBase::length(jsi::Runtime &runtime) const {
107
+ return getProperty(runtime, propNameIDCache.get(runtime, Prop::Length)).asNumber();
103
108
  }
104
109
 
105
- size_t TypedArrayBase::byteLength(jsi::Runtime &runtime) const
106
- {
107
- return getProperty(runtime, propNameIDCache.get(runtime, Prop::ByteLength)).asNumber();
110
+ size_t TypedArrayBase::byteLength(jsi::Runtime &runtime) const {
111
+ return getProperty(runtime, propNameIDCache.get(runtime, Prop::ByteLength)).asNumber();
108
112
  }
109
113
 
110
- size_t TypedArrayBase::byteOffset(jsi::Runtime &runtime) const
111
- {
112
- return getProperty(runtime, propNameIDCache.get(runtime, Prop::ByteOffset)).asNumber();
114
+ size_t TypedArrayBase::byteOffset(jsi::Runtime &runtime) const {
115
+ return getProperty(runtime, propNameIDCache.get(runtime, Prop::ByteOffset)).asNumber();
113
116
  }
114
117
 
115
- bool TypedArrayBase::hasBuffer(jsi::Runtime &runtime) const
116
- {
117
- auto buffer = getProperty(runtime, propNameIDCache.get(runtime, Prop::Buffer));
118
- return buffer.isObject() && buffer.asObject(runtime).isArrayBuffer(runtime);
118
+ bool TypedArrayBase::hasBuffer(jsi::Runtime &runtime) const {
119
+ auto buffer = getProperty(runtime, propNameIDCache.get(runtime, Prop::Buffer));
120
+ return buffer.isObject() && buffer.asObject(runtime).isArrayBuffer(runtime);
119
121
  }
120
122
 
121
- std::vector<uint8_t> TypedArrayBase::toVector(jsi::Runtime &runtime)
122
- {
123
- auto start =
124
- reinterpret_cast<uint8_t *>(getBuffer(runtime).data(runtime) + byteOffset(runtime));
125
- auto end = start + byteLength(runtime);
126
- return std::vector<uint8_t>(start, end);
123
+ std::vector<uint8_t> TypedArrayBase::toVector(jsi::Runtime &runtime) {
124
+ auto start = reinterpret_cast<uint8_t *>(getBuffer(runtime).data(runtime) + byteOffset(runtime));
125
+ auto end = start + byteLength(runtime);
126
+ return std::vector<uint8_t>(start, end);
127
127
  }
128
128
 
129
- jsi::ArrayBuffer TypedArrayBase::getBuffer(jsi::Runtime &runtime) const
130
- {
131
- auto buffer = getProperty(runtime, propNameIDCache.get(runtime, Prop::Buffer));
132
- if (buffer.isObject() && buffer.asObject(runtime).isArrayBuffer(runtime))
133
- {
134
- return buffer.asObject(runtime).getArrayBuffer(runtime);
135
- }
136
- else
137
- {
138
- throw std::runtime_error("no ArrayBuffer attached");
139
- }
129
+ jsi::ArrayBuffer TypedArrayBase::getBuffer(jsi::Runtime &runtime) const {
130
+ auto buffer = getProperty(runtime, propNameIDCache.get(runtime, Prop::Buffer));
131
+ if (buffer.isObject() && buffer.asObject(runtime).isArrayBuffer(runtime)) {
132
+ return buffer.asObject(runtime).getArrayBuffer(runtime);
133
+ } else {
134
+ throw std::runtime_error("no ArrayBuffer attached");
135
+ }
140
136
  }
141
137
 
142
- bool isTypedArray(jsi::Runtime &runtime, const jsi::Object &jsObj)
143
- {
144
- auto jsVal = runtime.global()
145
- .getProperty(runtime, propNameIDCache.get(runtime, Prop::ArrayBuffer))
146
- .asObject(runtime)
147
- .getProperty(runtime, propNameIDCache.get(runtime, Prop::IsView))
148
- .asObject(runtime)
149
- .asFunction(runtime)
150
- .callWithThis(runtime, runtime.global(), {jsi::Value(runtime, jsObj)});
151
- if (jsVal.isBool())
152
- {
153
- return jsVal.getBool();
154
- }
155
- else
156
- {
157
- throw std::runtime_error("value is not a boolean");
158
- }
138
+ bool isTypedArray(jsi::Runtime &runtime, const jsi::Object &jsObj) {
139
+ auto jsVal = runtime.global()
140
+ .getProperty(runtime, propNameIDCache.get(runtime, Prop::ArrayBuffer))
141
+ .asObject(runtime)
142
+ .getProperty(runtime, propNameIDCache.get(runtime, Prop::IsView))
143
+ .asObject(runtime)
144
+ .asFunction(runtime)
145
+ .callWithThis(runtime, runtime.global(), {jsi::Value(runtime, jsObj)});
146
+ if (jsVal.isBool()) {
147
+ return jsVal.getBool();
148
+ } else {
149
+ throw std::runtime_error("value is not a boolean");
150
+ }
159
151
  }
160
152
 
161
- TypedArrayBase getTypedArray(jsi::Runtime &runtime, const jsi::Object &jsObj)
162
- {
163
- auto jsVal = runtime.global()
164
- .getProperty(runtime, propNameIDCache.get(runtime, Prop::ArrayBuffer))
165
- .asObject(runtime)
166
- .getProperty(runtime, propNameIDCache.get(runtime, Prop::IsView))
167
- .asObject(runtime)
168
- .asFunction(runtime)
169
- .callWithThis(runtime, runtime.global(), {jsi::Value(runtime, jsObj)});
170
- if (jsVal.isBool())
171
- {
172
- return TypedArrayBase(runtime, jsObj);
173
- }
174
- else
175
- {
176
- throw std::runtime_error("value is not a boolean");
177
- }
153
+ TypedArrayBase getTypedArray(jsi::Runtime &runtime, const jsi::Object &jsObj) {
154
+ auto jsVal = runtime.global()
155
+ .getProperty(runtime, propNameIDCache.get(runtime, Prop::ArrayBuffer))
156
+ .asObject(runtime)
157
+ .getProperty(runtime, propNameIDCache.get(runtime, Prop::IsView))
158
+ .asObject(runtime)
159
+ .asFunction(runtime)
160
+ .callWithThis(runtime, runtime.global(), {jsi::Value(runtime, jsObj)});
161
+ if (jsVal.isBool()) {
162
+ return TypedArrayBase(runtime, jsObj);
163
+ } else {
164
+ throw std::runtime_error("value is not a boolean");
165
+ }
178
166
  }
179
167
 
180
- std::vector<uint8_t> arrayBufferToVector(jsi::Runtime &runtime, jsi::Object &jsObj)
181
- {
182
- if (!jsObj.isArrayBuffer(runtime))
183
- {
184
- throw std::runtime_error("Object is not an ArrayBuffer");
185
- }
186
- auto jsArrayBuffer = jsObj.getArrayBuffer(runtime);
168
+ std::vector<uint8_t> arrayBufferToVector(jsi::Runtime &runtime, jsi::Object &jsObj) {
169
+ if (!jsObj.isArrayBuffer(runtime)) {
170
+ throw std::runtime_error("Object is not an ArrayBuffer");
171
+ }
172
+ auto jsArrayBuffer = jsObj.getArrayBuffer(runtime);
187
173
 
188
- uint8_t *dataBlock = jsArrayBuffer.data(runtime);
189
- size_t blockSize =
190
- jsArrayBuffer.getProperty(runtime, propNameIDCache.get(runtime, Prop::ByteLength)).asNumber();
191
- return std::vector<uint8_t>(dataBlock, dataBlock + blockSize);
174
+ uint8_t *dataBlock = jsArrayBuffer.data(runtime);
175
+ size_t blockSize =
176
+ jsArrayBuffer.getProperty(runtime, propNameIDCache.get(runtime, Prop::ByteLength)).asNumber();
177
+ return std::vector<uint8_t>(dataBlock, dataBlock + blockSize);
192
178
  }
193
179
 
194
180
  void arrayBufferUpdate(
195
181
  jsi::Runtime &runtime,
196
182
  jsi::ArrayBuffer &buffer,
197
183
  std::vector<uint8_t> data,
198
- size_t offset)
199
- {
200
- uint8_t *dataBlock = buffer.data(runtime);
201
- size_t blockSize = buffer.size(runtime);
202
- if (data.size() > blockSize)
203
- {
204
- throw jsi::JSError(runtime, "ArrayBuffer is to small to fit data");
205
- }
206
- std::copy(data.begin(), data.end(), dataBlock + offset);
184
+ size_t offset) {
185
+ uint8_t *dataBlock = buffer.data(runtime);
186
+ size_t blockSize = buffer.size(runtime);
187
+ if (data.size() > blockSize) {
188
+ throw jsi::JSError(runtime, "ArrayBuffer is to small to fit data");
189
+ }
190
+ std::copy(data.begin(), data.end(), dataBlock + offset);
207
191
  }
208
192
 
209
193
  template <TypedArrayKind T>
210
- TypedArray<T>::TypedArray(jsi::Runtime &runtime, size_t size) : TypedArrayBase(runtime, size, T){};
194
+ TypedArray<T>::TypedArray(jsi::Runtime &runtime, size_t size) : TypedArrayBase(runtime, size, T) {}
211
195
 
212
196
  template <TypedArrayKind T>
213
197
  TypedArray<T>::TypedArray(jsi::Runtime &runtime, std::vector<ContentType<T>> data)
214
- : TypedArrayBase(runtime, data.size(), T)
215
- {
216
- update(runtime, data);
217
- };
198
+ : TypedArrayBase(runtime, data.size(), T) {
199
+ update(runtime, data);
200
+ }
218
201
 
219
202
  template <TypedArrayKind T>
220
203
  TypedArray<T>::TypedArray(TypedArrayBase &&base) : TypedArrayBase(std::move(base)) {}
221
204
 
222
205
  template <TypedArrayKind T>
223
- std::vector<ContentType<T>> TypedArray<T>::toVector(jsi::Runtime &runtime)
224
- {
225
- auto start =
226
- reinterpret_cast<ContentType<T> *>(getBuffer(runtime).data(runtime) + byteOffset(runtime));
227
- auto end = start + size(runtime);
228
- return std::vector<ContentType<T>>(start, end);
206
+ std::vector<ContentType<T>> TypedArray<T>::toVector(jsi::Runtime &runtime) {
207
+ auto start =
208
+ reinterpret_cast<ContentType<T> *>(getBuffer(runtime).data(runtime) + byteOffset(runtime));
209
+ auto end = start + size(runtime);
210
+ return std::vector<ContentType<T>>(start, end);
229
211
  }
230
212
 
231
213
  template <TypedArrayKind T>
232
- void TypedArray<T>::update(jsi::Runtime &runtime, const std::vector<ContentType<T>> &data)
233
- {
234
- if (data.size() != size(runtime))
235
- {
236
- throw jsi::JSError(runtime, "TypedArray can only be updated with a vector of the same size");
237
- }
238
- uint8_t *rawData = getBuffer(runtime).data(runtime) + byteOffset(runtime);
239
- std::copy(data.begin(), data.end(), reinterpret_cast<ContentType<T> *>(rawData));
214
+ void TypedArray<T>::update(jsi::Runtime &runtime, const std::vector<ContentType<T>> &data) {
215
+ if (data.size() != size(runtime)) {
216
+ throw jsi::JSError(runtime, "TypedArray can only be updated with a vector of the same size");
217
+ }
218
+ uint8_t *rawData = getBuffer(runtime).data(runtime) + byteOffset(runtime);
219
+ std::copy(data.begin(), data.end(), reinterpret_cast<ContentType<T> *>(rawData));
220
+ }
221
+
222
+ template <TypedArrayKind T>
223
+ void TypedArray<T>::updateUnsafe(jsi::Runtime &runtime, ContentType<T> *data, size_t length) {
224
+ if (length != size(runtime)) {
225
+ throw jsi::JSError(runtime, "TypedArray can only be updated with an array of the same size");
226
+ }
227
+ uint8_t *rawData = getBuffer(runtime).data(runtime) + byteOffset(runtime);
228
+ memcpy(rawData, data, length);
229
+ }
230
+
231
+ template <TypedArrayKind T>
232
+ uint8_t* TypedArray<T>::data(jsi::Runtime &runtime) {
233
+ return getBuffer(runtime).data(runtime) + byteOffset(runtime);
240
234
  }
241
235
 
242
236
  const jsi::PropNameID &PropNameIDCache::getConstructorNameProp(
243
237
  jsi::Runtime &runtime,
244
- TypedArrayKind kind)
245
- {
246
- switch (kind)
247
- {
238
+ TypedArrayKind kind) {
239
+ switch (kind) {
248
240
  case TypedArrayKind::Int8Array:
249
- return get(runtime, Prop::Int8Array);
241
+ return get(runtime, Prop::Int8Array);
250
242
  case TypedArrayKind::Int16Array:
251
- return get(runtime, Prop::Int16Array);
243
+ return get(runtime, Prop::Int16Array);
252
244
  case TypedArrayKind::Int32Array:
253
- return get(runtime, Prop::Int32Array);
245
+ return get(runtime, Prop::Int32Array);
254
246
  case TypedArrayKind::Uint8Array:
255
- return get(runtime, Prop::Uint8Array);
247
+ return get(runtime, Prop::Uint8Array);
256
248
  case TypedArrayKind::Uint8ClampedArray:
257
- return get(runtime, Prop::Uint8ClampedArray);
249
+ return get(runtime, Prop::Uint8ClampedArray);
258
250
  case TypedArrayKind::Uint16Array:
259
- return get(runtime, Prop::Uint16Array);
251
+ return get(runtime, Prop::Uint16Array);
260
252
  case TypedArrayKind::Uint32Array:
261
- return get(runtime, Prop::Uint32Array);
253
+ return get(runtime, Prop::Uint32Array);
262
254
  case TypedArrayKind::Float32Array:
263
- return get(runtime, Prop::Float32Array);
255
+ return get(runtime, Prop::Float32Array);
264
256
  case TypedArrayKind::Float64Array:
265
- return get(runtime, Prop::Float64Array);
266
- }
257
+ return get(runtime, Prop::Float64Array);
258
+ }
267
259
  }
268
260
 
269
- jsi::PropNameID PropNameIDCache::createProp(jsi::Runtime &runtime, Prop prop)
270
- {
271
- auto create = [&](const std::string &propName)
272
- {
273
- return jsi::PropNameID::forUtf8(runtime, propName);
274
- };
275
- switch (prop)
276
- {
261
+ jsi::PropNameID PropNameIDCache::createProp(jsi::Runtime &runtime, Prop prop) {
262
+ auto create = [&](const std::string &propName) {
263
+ return jsi::PropNameID::forUtf8(runtime, propName);
264
+ };
265
+ switch (prop) {
277
266
  case Prop::Buffer:
278
- return create("buffer");
267
+ return create("buffer");
279
268
  case Prop::Constructor:
280
- return create("constructor");
269
+ return create("constructor");
281
270
  case Prop::Name:
282
- return create("name");
271
+ return create("name");
283
272
  case Prop::Proto:
284
- return create("__proto__");
273
+ return create("__proto__");
285
274
  case Prop::Length:
286
- return create("length");
275
+ return create("length");
287
276
  case Prop::ByteLength:
288
- return create("byteLength");
277
+ return create("byteLength");
289
278
  case Prop::ByteOffset:
290
- return create("byteOffset");
279
+ return create("byteOffset");
291
280
  case Prop::IsView:
292
- return create("isView");
281
+ return create("isView");
293
282
  case Prop::ArrayBuffer:
294
- return create("ArrayBuffer");
283
+ return create("ArrayBuffer");
295
284
  case Prop::Int8Array:
296
- return create("Int8Array");
285
+ return create("Int8Array");
297
286
  case Prop::Int16Array:
298
- return create("Int16Array");
287
+ return create("Int16Array");
299
288
  case Prop::Int32Array:
300
- return create("Int32Array");
289
+ return create("Int32Array");
301
290
  case Prop::Uint8Array:
302
- return create("Uint8Array");
291
+ return create("Uint8Array");
303
292
  case Prop::Uint8ClampedArray:
304
- return create("Uint8ClampedArray");
293
+ return create("Uint8ClampedArray");
305
294
  case Prop::Uint16Array:
306
- return create("Uint16Array");
295
+ return create("Uint16Array");
307
296
  case Prop::Uint32Array:
308
- return create("Uint32Array");
297
+ return create("Uint32Array");
309
298
  case Prop::Float32Array:
310
- return create("Float32Array");
299
+ return create("Float32Array");
311
300
  case Prop::Float64Array:
312
- return create("Float64Array");
313
- }
301
+ return create("Float64Array");
302
+ }
314
303
  }
315
304
 
316
305
  std::unordered_map<std::string, TypedArrayKind> nameToKindMap = {
@@ -325,9 +314,8 @@ std::unordered_map<std::string, TypedArrayKind> nameToKindMap = {
325
314
  {"Float64Array", TypedArrayKind::Float64Array},
326
315
  };
327
316
 
328
- TypedArrayKind getTypedArrayKindForName(const std::string &name)
329
- {
330
- return nameToKindMap.at(name);
317
+ TypedArrayKind getTypedArrayKindForName(const std::string &name) {
318
+ return nameToKindMap.at(name);
331
319
  }
332
320
 
333
321
  template class TypedArray<TypedArrayKind::Int8Array>;