From 2ebceed790641ee73026cf3c81785a7e957f161e Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Fri, 18 Nov 2016 23:02:00 +0100 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/9689 Refs: https://github.com/nodejs/node/issues/9288 Refs: https://github.com/nodejs/node/pull/9293 Reviewed-By: Anna Henningsen --- test/addons/new-target/binding.cc | 16 ++++++++++++++++ test/addons/new-target/binding.gyp | 9 +++++++++ test/addons/new-target/test.js | 18 ++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 test/addons/new-target/binding.cc create mode 100644 test/addons/new-target/binding.gyp create mode 100644 test/addons/new-target/test.js diff --git a/test/addons/new-target/binding.cc b/test/addons/new-target/binding.cc new file mode 100644 index 00000000000000..a7e18eff70ea0d --- /dev/null +++ b/test/addons/new-target/binding.cc @@ -0,0 +1,16 @@ +#include +#include + +namespace { + +inline void NewClass(const v8::FunctionCallbackInfo&) {} + +inline void Initialize(v8::Local binding) { + auto isolate = binding->GetIsolate(); + binding->Set(v8::String::NewFromUtf8(isolate, "Class"), + v8::FunctionTemplate::New(isolate, NewClass)->GetFunction()); +} + +NODE_MODULE(binding, Initialize) + +} // anonymous namespace diff --git a/test/addons/new-target/binding.gyp b/test/addons/new-target/binding.gyp new file mode 100644 index 00000000000000..7ede63d94a0d77 --- /dev/null +++ b/test/addons/new-target/binding.gyp @@ -0,0 +1,9 @@ +{ + 'targets': [ + { + 'target_name': 'binding', + 'defines': [ 'V8_DEPRECATION_WARNINGS=1' ], + 'sources': [ 'binding.cc' ] + } + ] +} diff --git a/test/addons/new-target/test.js b/test/addons/new-target/test.js new file mode 100644 index 00000000000000..e4864adb1c24f3 --- /dev/null +++ b/test/addons/new-target/test.js @@ -0,0 +1,18 @@ +'use strict'; + +const common = require('../../common'); +const assert = require('assert'); +const binding = require(`./build/${common.buildType}/binding`); + +class Class extends binding.Class { + constructor() { + super(); + this.method(); + } + method() { + this.ok = true; + } +} + +assert.ok(new Class() instanceof binding.Class); +assert.ok(new Class().ok);