| 1640 | |
| 1641 | template <class K, class V> |
| 1642 | class MapWrapper : NodeRT::WrapperBase { |
| 1643 | public: |
| 1644 | static void Init() { |
| 1645 | HandleScope scope; |
| 1646 | |
| 1647 | Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(New); |
| 1648 | s_constructorTemplate.Reset(localRef); |
| 1649 | localRef->SetClassName( |
| 1650 | Nan::New<String>("Windows::Foundation::Collections:IMap") |
| 1651 | .ToLocalChecked()); |
| 1652 | localRef->InstanceTemplate()->SetInternalFieldCount(1); |
| 1653 | |
| 1654 | Nan::SetPrototypeMethod(localRef, "hasKey", HasKey); |
| 1655 | Nan::SetPrototypeMethod(localRef, "lookup", Lookup); |
| 1656 | Nan::SetPrototypeMethod(localRef, "getView", GetView); |
| 1657 | Nan::SetPrototypeMethod(localRef, "clear", Clear); |
| 1658 | Nan::SetPrototypeMethod(localRef, "insert", Insert); |
| 1659 | Nan::SetPrototypeMethod(localRef, "remove", Remove); |
| 1660 | Nan::SetPrototypeMethod(localRef, "first", First); |
| 1661 | |
| 1662 | Nan::SetAccessor(localRef->PrototypeTemplate(), |
| 1663 | Nan::New<String>("size").ToLocalChecked(), SizeGetter); |
| 1664 | Nan::SetAccessor(localRef->PrototypeTemplate(), |
| 1665 | Nan::New<String>("length").ToLocalChecked(), SizeGetter); |
| 1666 | |
| 1667 | return; |
| 1668 | } |
| 1669 | |
| 1670 | static Local<Value> CreateMapWrapper( |
| 1671 | ::Windows::Foundation::Collections::IMap<K, V> ^ winRtInstance, |
| 1672 | const std::function<Local<Value>(K)>& keyGetterFunc, |
| 1673 | const std::function<bool(Local<Value>)>& checkKeyTypeFunc, |
| 1674 | const std::function<K(Local<Value>)>& convertToKeyTypeFunc, |
| 1675 | const std::function<Local<Value>(V)>& valueGetterFunc, |
| 1676 | const std::function<bool(Local<Value>)>& checkValueTypeFunc, |
| 1677 | const std::function<V(Local<Value>)>& convertToValueTypeFunc) { |
| 1678 | EscapableHandleScope scope; |
| 1679 | if (winRtInstance == nullptr) { |
| 1680 | return scope.Escape(Undefined()); |
| 1681 | } |
| 1682 | |
| 1683 | if (s_constructorTemplate.IsEmpty()) { |
| 1684 | Init(); |
| 1685 | } |
| 1686 | |
| 1687 | v8::Local<Value> args[] = {Undefined()}; |
| 1688 | Local<FunctionTemplate> localRef = |
| 1689 | Nan::New<FunctionTemplate>(s_constructorTemplate); |
| 1690 | Local<Object> objectInstance = |
| 1691 | Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), 0, args) |
| 1692 | .ToLocalChecked(); |
| 1693 | if (objectInstance.IsEmpty()) { |
| 1694 | return scope.Escape(Undefined()); |
| 1695 | } |
| 1696 | |
| 1697 | MapWrapper<K, V>* wrapperInstance = new MapWrapper<K, V>( |
| 1698 | winRtInstance, keyGetterFunc, checkKeyTypeFunc, convertToKeyTypeFunc, |
| 1699 | valueGetterFunc, checkValueTypeFunc, convertToValueTypeFunc); |
nothing calls this directly
no outgoing calls
no test coverage detected