MCPcopy Create free account
hub / github.com/NodeRT/NodeRT / KeyValuePairWrapper

Class KeyValuePairWrapper

src/NodeRTLib/ProjectFiles/CollectionsWrap.h:1250–1368  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1248
1249template <class K, class V>
1250class KeyValuePairWrapper : NodeRT::WrapperBase {
1251 public:
1252 static void Init() {
1253 HandleScope scope;
1254
1255 Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(New);
1256 s_constructorTemplate.Reset(localRef);
1257 localRef->SetClassName(
1258 Nan::New<String>("Windows::Foundation::Collections:IKeyValuePair")
1259 .ToLocalChecked());
1260 localRef->InstanceTemplate()->SetInternalFieldCount(1);
1261
1262 Nan::SetAccessor(localRef->PrototypeTemplate(),
1263 Nan::New<String>("key").ToLocalChecked(), KeyGetter);
1264 Nan::SetAccessor(localRef->PrototypeTemplate(),
1265 Nan::New<String>("value").ToLocalChecked(), ValueGetter);
1266
1267 return;
1268 }
1269
1270 static Local<Value> CreateKeyValuePairWrapper(
1271 ::Windows::Foundation::Collections::IKeyValuePair<K, V> ^ winRtInstance,
1272 const std::function<Local<Value>(K)>& keyGetterFunc,
1273 const std::function<Local<Value>(V)>& valueGetterFunc) {
1274 EscapableHandleScope scope;
1275 if (winRtInstance == nullptr) {
1276 return scope.Escape(Undefined());
1277 }
1278
1279 if (s_constructorTemplate.IsEmpty()) {
1280 Init();
1281 }
1282
1283 v8::Local<Value> args[] = {Undefined()};
1284 Local<FunctionTemplate> localRef =
1285 Nan::New<FunctionTemplate>(s_constructorTemplate);
1286 Local<Object> objectInstance =
1287 Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), 0, args)
1288 .ToLocalChecked();
1289 if (objectInstance.IsEmpty()) {
1290 return scope.Escape(Undefined());
1291 }
1292
1293 KeyValuePairWrapper<K, V>* wrapperInstance = new KeyValuePairWrapper<K, V>(
1294 winRtInstance, keyGetterFunc, valueGetterFunc);
1295 wrapperInstance->Wrap(objectInstance);
1296 return scope.Escape(objectInstance);
1297 }
1298
1299 virtual ::Platform::Object ^ GetObjectInstance() const override {
1300 return _instance;
1301 }
1302
1303 private:
1304 KeyValuePairWrapper(::Windows::Foundation::Collections::IKeyValuePair<K, V> ^
1305 winRtInstance,
1306 const std::function<Local<Value>(K)>& keyGetterFunc,
1307 const std::function<Local<Value>(V)>& valueGetterFunc)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected