Skip to content

Commit 13c4f44

Browse files
committed
test: add new.target add-on regression test
Add a test that checks that new.target inheritance works when inheriting from a constructor defined in C++. PR-URL: nodejs#9689 Refs: nodejs#9288 Refs: nodejs#9293 Reviewed-By: Anna Henningsen <[email protected]>
1 parent 515b1f3 commit 13c4f44

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

test/addons/new-target/binding.cc

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <node.h>
2+
#include <v8.h>
3+
4+
namespace {
5+
6+
inline void NewClass(const v8::FunctionCallbackInfo<v8::Value>&) {}
7+
8+
inline void Initialize(v8::Local<v8::Object> binding) {
9+
auto isolate = binding->GetIsolate();
10+
binding->Set(v8::String::NewFromUtf8(isolate, "Class"),
11+
v8::FunctionTemplate::New(isolate, NewClass)->GetFunction());
12+
}
13+
14+
NODE_MODULE(binding, Initialize)
15+
16+
} // anonymous namespace

test/addons/new-target/binding.gyp

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
'targets': [
3+
{
4+
'target_name': 'binding',
5+
'defines': [ 'V8_DEPRECATION_WARNINGS=1' ],
6+
'sources': [ 'binding.cc' ]
7+
}
8+
]
9+
}

test/addons/new-target/test.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
3+
const common = require('../../common');
4+
const assert = require('assert');
5+
const binding = require(`./build/${common.buildType}/binding`);
6+
7+
class Class extends binding.Class {
8+
constructor() {
9+
super();
10+
this.method();
11+
}
12+
method() {
13+
this.ok = true;
14+
}
15+
}
16+
17+
assert.ok(new Class() instanceof binding.Class);
18+
assert.ok(new Class().ok);

0 commit comments

Comments
 (0)