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

tls_wrap: proxy handle methods in prototype #1108

Closed
wants to merge 1 commit into from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 8 additions & 8 deletions lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,14 @@ var proxiedMethods = [
'setPendingInstances'
];

// Proxy HandleWrap, PipeWrap and TCPWrap methods
proxiedMethods.forEach(function(name) {
tls_wrap.TLSWrap.prototype[name] = function methodProxy() {
if (this._parent[name])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, is this check really necessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we could remove it somewhere later, but I better secure ourselves with this for now.

return this._parent[name].apply(this._parent, arguments);
};
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we care about the extra performance lost to creating a closure and referring to the call as this._parent[name] instead of this._parent.<name>?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, it shouldn't be critical here.


TLSSocket.prototype._wrapHandle = function(handle) {
var res;

Expand All @@ -297,14 +305,6 @@ TLSSocket.prototype._wrapHandle = function(handle) {
}
});

// Proxy HandleWrap, PipeWrap and TCPWrap methods
proxiedMethods.forEach(function(name) {
res[name] = function methodProxy() {
if (handle[name])
return handle[name].apply(handle, arguments);
};
});

return res;
};

Expand Down
7 changes: 5 additions & 2 deletions src/tls_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -809,8 +809,8 @@ int TLSWrap::SelectSNIContextCallback(SSL* s, int* ad, void* arg) {


void TLSWrap::Initialize(Handle<Object> target,
Handle<Value> unused,
Handle<Context> context) {
Handle<Value> unused,
Handle<Context> context) {
Environment* env = Environment::GetCurrent(context);

env->SetMethod(target, "wrap", TLSWrap::Wrap);
Expand All @@ -835,6 +835,9 @@ void TLSWrap::Initialize(Handle<Object> target,

env->set_tls_wrap_constructor_template(t);
env->set_tls_wrap_constructor_function(t->GetFunction());

target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "TLSWrap"),
t->GetFunction());
}

} // namespace node
Expand Down