Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug Fix for Issue #17668 - Unused prototype objects from V8 FunctionTemplate initialization #20321

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 =
Expand Down
4 changes: 3 additions & 1 deletion src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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`);
});