| 1372 | |
| 1373 | template <class K, class V> |
| 1374 | class MapViewWrapper : NodeRT::WrapperBase { |
| 1375 | public: |
| 1376 | static void Init() { |
| 1377 | HandleScope scope; |
| 1378 | |
| 1379 | Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(New); |
| 1380 | s_constructorTemplate.Reset(localRef); |
| 1381 | localRef->SetClassName( |
| 1382 | Nan::New<String>("Windows::Foundation::Collections:IMapView") |
| 1383 | .ToLocalChecked()); |
| 1384 | localRef->InstanceTemplate()->SetInternalFieldCount(1); |
| 1385 | |
| 1386 | Nan::SetPrototypeMethod(localRef, "hasKey", HasKey); |
| 1387 | Nan::SetPrototypeMethod(localRef, "lookup", Lookup); |
| 1388 | Nan::SetPrototypeMethod(localRef, "split", Split); |
| 1389 | Nan::SetPrototypeMethod(localRef, "first", First); |
| 1390 | |
| 1391 | Nan::SetAccessor(localRef->PrototypeTemplate(), |
| 1392 | Nan::New<String>("size").ToLocalChecked(), SizeGetter); |
| 1393 | Nan::SetAccessor(localRef->PrototypeTemplate(), |
| 1394 | Nan::New<String>("length").ToLocalChecked(), SizeGetter); |
| 1395 | |
| 1396 | return; |
| 1397 | } |
| 1398 | |
| 1399 | static Local<Value> CreateMapViewWrapper( |
| 1400 | ::Windows::Foundation::Collections::IMapView<K, V> ^ winRtInstance, |
| 1401 | const std::function<Local<Value>(K)>& keyGetterFunc, |
| 1402 | const std::function<bool(Local<Value>)>& checkKeyTypeFunc, |
| 1403 | const std::function<K(Local<Value>)>& convertToKeyTypeFunc, |
| 1404 | const std::function<Local<Value>(V)>& valueGetterFunc) { |
| 1405 | EscapableHandleScope scope; |
| 1406 | if (winRtInstance == nullptr) { |
| 1407 | return scope.Escape(Undefined()); |
| 1408 | } |
| 1409 | |
| 1410 | if (s_constructorTemplate.IsEmpty()) { |
| 1411 | Init(); |
| 1412 | } |
| 1413 | |
| 1414 | v8::Local<Value> args[] = {Undefined()}; |
| 1415 | Local<FunctionTemplate> localRef = |
| 1416 | Nan::New<FunctionTemplate>(s_constructorTemplate); |
| 1417 | Local<Object> objectInstance = |
| 1418 | Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), 0, args) |
| 1419 | .ToLocalChecked(); |
| 1420 | if (objectInstance.IsEmpty()) { |
| 1421 | return scope.Escape(Undefined()); |
| 1422 | } |
| 1423 | |
| 1424 | MapViewWrapper<K, V>* wrapperInstance = |
| 1425 | new MapViewWrapper<K, V>(winRtInstance, keyGetterFunc, checkKeyTypeFunc, |
| 1426 | convertToKeyTypeFunc, valueGetterFunc); |
| 1427 | wrapperInstance->Wrap(objectInstance); |
| 1428 | return scope.Escape(objectInstance); |
| 1429 | } |
| 1430 | |
| 1431 | virtual ::Platform::Object ^ GetObjectInstance() const override { |
nothing calls this directly
no outgoing calls
no test coverage detected