MCPcopy Index your code
hub / github.com/nodejs/node-addon-api / CheckDetachUpdatesData

Function CheckDetachUpdatesData

test/array_buffer.cc:162–221  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

160}
161
162void CheckDetachUpdatesData(const CallbackInfo& info) {
163 if (!info[0].IsArrayBuffer()) {
164 Error::New(info.Env(), "A buffer was expected.")
165 .ThrowAsJavaScriptException();
166 return;
167 }
168
169 ArrayBuffer buffer = info[0].As<ArrayBuffer>();
170
171 // This potentially causes the buffer to cache its data pointer and length.
172 buffer.Data();
173 buffer.ByteLength();
174
175#if NAPI_VERSION >= 7
176 if (buffer.IsDetached()) {
177 Error::New(info.Env(), "Buffer should not be detached.")
178 .ThrowAsJavaScriptException();
179 return;
180 }
181#endif
182
183 if (info.Length() == 2) {
184 // Detach externally (in JavaScript).
185 if (!info[1].IsFunction()) {
186 Error::New(info.Env(), "A function was expected.")
187 .ThrowAsJavaScriptException();
188 return;
189 }
190
191 Function detach = info[1].As<Function>();
192 detach.Call({});
193 } else {
194#if NAPI_VERSION >= 7
195 // Detach directly.
196 buffer.Detach();
197#else
198 return;
199#endif
200 }
201
202#if NAPI_VERSION >= 7
203 if (!buffer.IsDetached()) {
204 Error::New(info.Env(), "Buffer should be detached.")
205 .ThrowAsJavaScriptException();
206 return;
207 }
208#endif
209
210 if (buffer.Data() != nullptr) {
211 Error::New(info.Env(), "Incorrect data pointer.")
212 .ThrowAsJavaScriptException();
213 return;
214 }
215
216 if (buffer.ByteLength() != 0) {
217 Error::New(info.Env(), "Incorrect buffer length.")
218 .ThrowAsJavaScriptException();
219 return;

Callers

nothing calls this directly

Calls 8

EnvMethod · 0.80
DataMethod · 0.80
ByteLengthMethod · 0.80
IsDetachedMethod · 0.80
LengthMethod · 0.80
CallMethod · 0.80
DetachMethod · 0.80

Tested by

no test coverage detected