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

Class ArrayWrapper

src/NodeRTLib/ProjectFiles/CollectionsWrap.h:44–198  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42
43template <class T>
44class ArrayWrapper : NodeRT::WrapperBase {
45 public:
46 static void Init() {
47 EscapableHandleScope scope;
48
49 Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(New);
50 s_constructorTemplate.Reset(localRef);
51
52 localRef->SetClassName(
53 Nan::New<String>("Windows::Foundation::Array").ToLocalChecked());
54 localRef->InstanceTemplate()->SetInternalFieldCount(1);
55 Nan::SetIndexedPropertyHandler(localRef->InstanceTemplate(), Get, Set);
56
57 Nan::SetAccessor(localRef->PrototypeTemplate(),
58 Nan::New<String>("length").ToLocalChecked(), LengthGetter);
59
60 return;
61 }
62
63 static Local<Value> CreateArrayWrapper(
64 ::Platform::Array<T> ^ winRtInstance,
65 const std::function<Local<Value>(T)>& getterFunc = nullptr,
66 const std::function<bool(Local<Value>)>& checkTypeFunc = nullptr,
67 const std::function<T(Local<Value>)>& convertToTypeFunc = nullptr) {
68 EscapableHandleScope scope;
69 if (winRtInstance == nullptr) {
70 return scope.Escape(Undefined());
71 }
72
73 if (s_constructorTemplate.IsEmpty()) {
74 Init();
75 }
76
77 v8::Local<Value> args[] = {Undefined()};
78 Local<FunctionTemplate> localRef =
79 Nan::New<FunctionTemplate>(s_constructorTemplate);
80 Local<Object> objectInstance =
81 Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), 0, args)
82 .ToLocalChecked();
83 if (objectInstance.IsEmpty()) {
84 return scope.Escape(Undefined());
85 }
86
87 ArrayWrapper<T>* wrapperInstance = new ArrayWrapper<T>(
88 winRtInstance, getterFunc, checkTypeFunc, convertToTypeFunc);
89 wrapperInstance->Wrap(objectInstance);
90 return scope.Escape(objectInstance);
91 }
92
93 virtual ::Platform::Object ^ GetObjectInstance() const override {
94 return _instance;
95 }
96
97 private:
98 ArrayWrapper(
99 ::Platform::Array<T> ^ winRtInstance,
100 const std::function<Local<Value>(T)>& getterFunc,
101 const std::function<bool(Local<Value>)>& checkTypeFunc = nullptr,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected