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

Function CreateBufferCopy

test/buffer.cc:108–133  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

106}
107
108Value CreateBufferCopy(const CallbackInfo& info) {
109 InitData(testData, testLength);
110
111 Buffer<uint16_t> buffer =
112 Buffer<uint16_t>::Copy(info.Env(), testData, testLength);
113
114 if (buffer.Length() != testLength) {
115 Error::New(info.Env(), "Incorrect buffer length.")
116 .ThrowAsJavaScriptException();
117 return Value();
118 }
119
120 if (buffer.Data() == testData) {
121 Error::New(info.Env(), "Copy should have different memory.")
122 .ThrowAsJavaScriptException();
123 return Value();
124 }
125
126 if (!VerifyData(buffer.Data(), buffer.Length())) {
127 Error::New(info.Env(), "Copy data is incorrect.")
128 .ThrowAsJavaScriptException();
129 return Value();
130 }
131
132 return buffer;
133}
134
135#include "buffer_new_or_copy-inl.h"
136

Callers

nothing calls this directly

Calls 7

EnvMethod · 0.80
LengthMethod · 0.80
DataMethod · 0.80
InitDataFunction · 0.70
VerifyDataFunction · 0.70
ValueClass · 0.50

Tested by

no test coverage detected