Skip to content

Commit

Permalink
src: removed unnecessary prototypes from Environment::SetProtoMethod
Browse files Browse the repository at this point in the history
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: #17668
Refs: #20321
PR-URL: #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>
  • Loading branch information
brandontruggles authored and MylesBorins committed May 9, 2018
1 parent 0b16c24 commit df2cddc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
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`);
});

0 comments on commit df2cddc

Please sign in to comment.