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

Function TestSharedArrayBufferData

test/shared_array_buffer.cc:59–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

57}
58
59Value TestSharedArrayBufferData(const CallbackInfo& info) {
60 if (info.Length() < 1) {
61 Error::New(info.Env(), "Wrong number of arguments")
62 .ThrowAsJavaScriptException();
63 return Value();
64 } else if (!info[0].IsSharedArrayBuffer()) {
65 Error::New(info.Env(),
66 "Wrong type of arguments. Expects a SharedArrayBuffer as first "
67 "argument.")
68 .ThrowAsJavaScriptException();
69 return Value();
70 }
71
72 auto byte_length = info[0].As<SharedArrayBuffer>().ByteLength();
73 void* data = info[0].As<SharedArrayBuffer>().Data();
74
75 if (byte_length > 0 && data != nullptr) {
76 uint8_t* bytes = static_cast<uint8_t*>(data);
77 for (size_t i = 0; i < byte_length; i++) {
78 bytes[i] = i % 256;
79 }
80
81 return Boolean::New(info.Env(), true);
82 }
83
84 return Boolean::New(info.Env(), false);
85}
86#endif
87} // end anonymous namespace
88

Callers

nothing calls this directly

Calls 6

LengthMethod · 0.80
EnvMethod · 0.80
ByteLengthMethod · 0.80
DataMethod · 0.80
ValueClass · 0.50

Tested by

no test coverage detected