summaryrefslogtreecommitdiff
path: root/test/addons/new-target/binding.cc
blob: c2777c831e484abf27c163af2cf0a24aa991760a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <node.h>
#include <v8.h>

namespace {

inline void NewClass(const v8::FunctionCallbackInfo<v8::Value>& args) {
  // this != new.target since we are being invoked through super().
  assert(args.IsConstructCall());
  assert(!args.This()->StrictEquals(args.NewTarget()));
}

inline void Initialize(v8::Local<v8::Object> binding) {
  auto isolate = binding->GetIsolate();
  auto context = isolate->GetCurrentContext();
  binding->Set(v8::String::NewFromUtf8(
        isolate, "Class", v8::NewStringType::kNormal).ToLocalChecked(),
               v8::FunctionTemplate::New(isolate, NewClass)
                   ->GetFunction(context)
                   .ToLocalChecked());
}

NODE_MODULE(NODE_GYP_MODULE_NAME, Initialize)

}  // anonymous namespace