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

Class IterableWrapper

src/NodeRTLib/ProjectFiles/CollectionsWrap.h:363–461  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

361
362template <class T>
363class IterableWrapper : NodeRT::WrapperBase {
364 public:
365 static void Init() {
366 HandleScope scope;
367
368 Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(New);
369 s_constructorTemplate.Reset(localRef);
370 localRef->SetClassName(
371 Nan::New<String>("Windows::Foundation::Collections:IIterable")
372 .ToLocalChecked());
373 localRef->InstanceTemplate()->SetInternalFieldCount(1);
374
375 Nan::SetPrototypeMethod(localRef, "first", First);
376
377 return;
378 }
379
380 static Local<Value> CreateIterableWrapper(
381 ::Windows::Foundation::Collections::IIterable<T> ^ winRtInstance,
382 const std::function<Local<Value>(T)>& getterFunc = nullptr) {
383 EscapableHandleScope scope;
384 if (winRtInstance == nullptr) {
385 return scope.Escape(Undefined());
386 }
387
388 if (s_constructorTemplate.IsEmpty()) {
389 Init();
390 }
391
392 v8::Local<Value> args[] = {Undefined()};
393 Local<FunctionTemplate> localRef =
394 Nan::New<FunctionTemplate>(s_constructorTemplate);
395 Local<Object> objectInstance =
396 Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), 0, args)
397 .ToLocalChecked();
398
399 if (objectInstance.IsEmpty()) {
400 return scope.Escape(Undefined());
401 }
402
403 IterableWrapper<T>* wrapperInstance =
404 new IterableWrapper<T>(winRtInstance, getterFunc);
405 wrapperInstance->Wrap(objectInstance);
406 return scope.Escape(objectInstance);
407 }
408
409 virtual ::Platform::Object ^ GetObjectInstance() const override {
410 return _instance;
411 }
412
413 private:
414 IterableWrapper(::Windows::Foundation::Collections::IIterable<T> ^
415 winRtInstance,
416 const std::function<Local<Value>(T)>& getterFunc)
417 : _instance(winRtInstance), _getterFunc(getterFunc) {}
418
419 static void New(Nan::NAN_METHOD_ARGS_TYPE info) {
420 NodeRT::Utils::SetHiddenValue(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected