diff --git a/src/env-inl.h b/src/env-inl.h index fa241f9706ec65..1aa62fc18ded52 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -583,9 +583,11 @@ inline void Environment::ThrowUVException(int errorno, inline v8::Local Environment::NewFunctionTemplate(v8::FunctionCallback callback, - v8::Local signature) { + v8::Local signature, + v8::ConstructorBehavior behavior) { v8::Local external = as_external(); - return v8::FunctionTemplate::New(isolate(), callback, external, signature); + return v8::FunctionTemplate::New(isolate(), callback, external, + signature, 0, behavior); } inline void Environment::SetMethod(v8::Local that, @@ -605,7 +607,8 @@ inline void Environment::SetProtoMethod(v8::Local that, const char* name, v8::FunctionCallback callback) { v8::Local signature = v8::Signature::New(isolate(), that); - v8::Local t = NewFunctionTemplate(callback, signature); + v8::Local t = + NewFunctionTemplate(callback, signature, v8::ConstructorBehavior::kThrow); // kInternalized strings are created in the old space. const v8::NewStringType type = v8::NewStringType::kInternalized; v8::Local name_string = diff --git a/src/env.h b/src/env.h index af4470ad8632fe..252151028164d2 100644 --- a/src/env.h +++ b/src/env.h @@ -687,7 +687,9 @@ class Environment { inline v8::Local NewFunctionTemplate(v8::FunctionCallback callback, v8::Local signature = - v8::Local()); + v8::Local(), + v8::ConstructorBehavior behavior = + v8::ConstructorBehavior::kAllow); // Convenience methods for NewFunctionTemplate(). inline void SetMethod(v8::Local that, diff --git a/test/parallel/test-env-newprotomethod-remove-unnecessary-prototypes.js b/test/parallel/test-env-newprotomethod-remove-unnecessary-prototypes.js new file mode 100644 index 00000000000000..bcc522cd45ad50 --- /dev/null +++ b/test/parallel/test-env-newprotomethod-remove-unnecessary-prototypes.js @@ -0,0 +1,18 @@ +'use strict'; +require('../common'); + +// This test ensures that unnecessary prototypes are no longer +// being generated by Environment::NewFunctionTemplate. + +const assert = require('assert'); + +[ + process.binding('udp_wrap').UDP.prototype.bind6, + process.binding('tcp_wrap').TCP.prototype.bind6, + process.binding('udp_wrap').UDP.prototype.send6, + process.binding('tcp_wrap').TCP.prototype.bind, + process.binding('udp_wrap').UDP.prototype.close, + process.binding('tcp_wrap').TCP.prototype.open +].forEach((binding, i) => { + assert.strictEqual('prototype' in binding, false, `Test ${i} failed`); +});