xref: /third_party/node/test/addons/null-buffer-neuter/binding.cc (revision 1cb0ef41)
  • Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/node/test/addons/null-buffer-neuter/
1#include <node.h>
2#include <node_buffer.h>
3#include <v8.h>
4
5#include <assert.h>
6
7static int alive;
8
9static void FreeCallback(char* data, void* hint) {
10  assert(data == nullptr);
11  alive--;
12}
13
14void IsAlive(const v8::FunctionCallbackInfo<v8::Value>& args) {
15  args.GetReturnValue().Set(alive);
16}
17
18void Run(const v8::FunctionCallbackInfo<v8::Value>& args) {
19  v8::Isolate* isolate = args.GetIsolate();
20  alive++;
21
22  {
23    v8::HandleScope scope(isolate);
24    v8::Local<v8::Object> buf = node::Buffer::New(
25          isolate,
26          nullptr,
27          0,
28          FreeCallback,
29          nullptr).ToLocalChecked();
30
31    char* data = node::Buffer::Data(buf);
32    assert(data == nullptr);
33  }
34}
35
36void init(v8::Local<v8::Object> exports) {
37  NODE_SET_METHOD(exports, "run", Run);
38  NODE_SET_METHOD(exports, "isAlive", IsAlive);
39}
40
41NODE_MODULE(NODE_GYP_MODULE_NAME, init)
42

Indexes created Thu Nov 07 10:32:03 CST 2024