src: removed unnecessary prototypes from Environment::SetProtoMethod
Added an optional parameter of type v8::ConstructorBehavior to Environment::NewFunctionTemplate, defaulting to v8::ConstructorBehavior::kAllow. Also modified Environment::SetProtoMethod to pass v8::ConstructorBehavior::kThrow to its call to Environment::NewFunctionTemplate. Fixes: https://github.com/nodejs/node/issues/17668 Refs: https://github.com/nodejs/node/pull/20321 PR-URL: https://github.com/nodejs/node/pull/20321 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
parent
67790962da
commit
64348f5ea5
@ -583,9 +583,11 @@ inline void Environment::ThrowUVException(int errorno,
|
||||
|
||||
inline v8::Local<v8::FunctionTemplate>
|
||||
Environment::NewFunctionTemplate(v8::FunctionCallback callback,
|
||||
v8::Local<v8::Signature> signature) {
|
||||
v8::Local<v8::Signature> signature,
|
||||
v8::ConstructorBehavior behavior) {
|
||||
v8::Local<v8::External> 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<v8::Object> that,
|
||||
@ -605,7 +607,8 @@ inline void Environment::SetProtoMethod(v8::Local<v8::FunctionTemplate> that,
|
||||
const char* name,
|
||||
v8::FunctionCallback callback) {
|
||||
v8::Local<v8::Signature> signature = v8::Signature::New(isolate(), that);
|
||||
v8::Local<v8::FunctionTemplate> t = NewFunctionTemplate(callback, signature);
|
||||
v8::Local<v8::FunctionTemplate> t =
|
||||
NewFunctionTemplate(callback, signature, v8::ConstructorBehavior::kThrow);
|
||||
// kInternalized strings are created in the old space.
|
||||
const v8::NewStringType type = v8::NewStringType::kInternalized;
|
||||
v8::Local<v8::String> name_string =
|
||||
|
@ -687,7 +687,9 @@ class Environment {
|
||||
inline v8::Local<v8::FunctionTemplate>
|
||||
NewFunctionTemplate(v8::FunctionCallback callback,
|
||||
v8::Local<v8::Signature> signature =
|
||||
v8::Local<v8::Signature>());
|
||||
v8::Local<v8::Signature>(),
|
||||
v8::ConstructorBehavior behavior =
|
||||
v8::ConstructorBehavior::kAllow);
|
||||
|
||||
// Convenience methods for NewFunctionTemplate().
|
||||
inline void SetMethod(v8::Local<v8::Object> that,
|
||||
|
@ -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`);
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user