| 202 | |
| 203 | template <class T> |
| 204 | class IteratorWrapper : NodeRT::WrapperBase { |
| 205 | public: |
| 206 | static void Init() { |
| 207 | HandleScope scope; |
| 208 | |
| 209 | Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(New); |
| 210 | s_constructorTemplate.Reset(localRef); |
| 211 | localRef->SetClassName( |
| 212 | Nan::New<String>("Windows::Foundation::Collections:IIterator") |
| 213 | .ToLocalChecked()); |
| 214 | localRef->InstanceTemplate()->SetInternalFieldCount(1); |
| 215 | |
| 216 | Nan::SetPrototypeMethod(localRef, "getMany", GetMany); |
| 217 | Nan::SetPrototypeMethod(localRef, "moveNext", MoveNext); |
| 218 | |
| 219 | Nan::SetAccessor(localRef->PrototypeTemplate(), |
| 220 | Nan::New<String>("current").ToLocalChecked(), |
| 221 | CurrentGetter); |
| 222 | Nan::SetAccessor(localRef->PrototypeTemplate(), |
| 223 | Nan::New<String>("hasCurrent").ToLocalChecked(), |
| 224 | HasCurrentGetter); |
| 225 | |
| 226 | return; |
| 227 | } |
| 228 | |
| 229 | static Local<Value> CreateIteratorWrapper( |
| 230 | ::Windows::Foundation::Collections::IIterator<T> ^ winRtInstance, |
| 231 | const std::function<Local<Value>(T)>& getterFunc = nullptr) { |
| 232 | EscapableHandleScope scope; |
| 233 | if (winRtInstance == nullptr) { |
| 234 | return scope.Escape(Undefined()); |
| 235 | } |
| 236 | |
| 237 | if (s_constructorTemplate.IsEmpty()) { |
| 238 | Init(); |
| 239 | } |
| 240 | |
| 241 | v8::Local<Value> args[] = {Undefined()}; |
| 242 | Local<FunctionTemplate> localRef = |
| 243 | Nan::New<FunctionTemplate>(s_constructorTemplate); |
| 244 | Local<Object> objectInstance = |
| 245 | Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), 0, args) |
| 246 | .ToLocalChecked(); |
| 247 | if (objectInstance.IsEmpty()) { |
| 248 | return scope.Escape(Undefined()); |
| 249 | } |
| 250 | |
| 251 | IteratorWrapper<T>* wrapperInstance = |
| 252 | new IteratorWrapper<T>(winRtInstance, getterFunc); |
| 253 | wrapperInstance->Wrap(objectInstance); |
| 254 | return scope.Escape(objectInstance); |
| 255 | } |
| 256 | |
| 257 | virtual ::Platform::Object ^ GetObjectInstance() const override { |
| 258 | return _instance; |
| 259 | } |
| 260 | |
| 261 | private: |
nothing calls this directly
no outgoing calls
no test coverage detected