Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 380dfe4

Browse filesBrowse files
brandontrugglesMylesBorins
authored andcommitted
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: #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>
1 parent d55f90d commit 380dfe4
Copy full SHA for 380dfe4

File tree

Expand file treeCollapse file tree

3 files changed

+27
-4
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+27
-4
lines changed
Open diff view settings
Collapse file

‎src/env-inl.h‎

Copy file name to clipboardExpand all lines: src/env-inl.h
+6-3Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -583,9 +583,11 @@ inline void Environment::ThrowUVException(int errorno,
583583

584584
inline v8::Local<v8::FunctionTemplate>
585585
Environment::NewFunctionTemplate(v8::FunctionCallback callback,
586-
v8::Local<v8::Signature> signature) {
586+
v8::Local<v8::Signature> signature,
587+
v8::ConstructorBehavior behavior) {
587588
v8::Local<v8::External> external = as_external();
588-
return v8::FunctionTemplate::New(isolate(), callback, external, signature);
589+
return v8::FunctionTemplate::New(isolate(), callback, external,
590+
signature, 0, behavior);
589591
}
590592

591593
inline void Environment::SetMethod(v8::Local<v8::Object> that,
@@ -605,7 +607,8 @@ inline void Environment::SetProtoMethod(v8::Local<v8::FunctionTemplate> that,
605607
const char* name,
606608
v8::FunctionCallback callback) {
607609
v8::Local<v8::Signature> signature = v8::Signature::New(isolate(), that);
608-
v8::Local<v8::FunctionTemplate> t = NewFunctionTemplate(callback, signature);
610+
v8::Local<v8::FunctionTemplate> t =
611+
NewFunctionTemplate(callback, signature, v8::ConstructorBehavior::kThrow);
609612
// kInternalized strings are created in the old space.
610613
const v8::NewStringType type = v8::NewStringType::kInternalized;
611614
v8::Local<v8::String> name_string =
Collapse file

‎src/env.h‎

Copy file name to clipboardExpand all lines: src/env.h
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,9 @@ class Environment {
687687
inline v8::Local<v8::FunctionTemplate>
688688
NewFunctionTemplate(v8::FunctionCallback callback,
689689
v8::Local<v8::Signature> signature =
690-
v8::Local<v8::Signature>());
690+
v8::Local<v8::Signature>(),
691+
v8::ConstructorBehavior behavior =
692+
v8::ConstructorBehavior::kAllow);
691693

692694
// Convenience methods for NewFunctionTemplate().
693695
inline void SetMethod(v8::Local<v8::Object> that,
Collapse file
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
require('../common');
3+
4+
// This test ensures that unnecessary prototypes are no longer
5+
// being generated by Environment::NewFunctionTemplate.
6+
7+
const assert = require('assert');
8+
9+
[
10+
process.binding('udp_wrap').UDP.prototype.bind6,
11+
process.binding('tcp_wrap').TCP.prototype.bind6,
12+
process.binding('udp_wrap').UDP.prototype.send6,
13+
process.binding('tcp_wrap').TCP.prototype.bind,
14+
process.binding('udp_wrap').UDP.prototype.close,
15+
process.binding('tcp_wrap').TCP.prototype.open
16+
].forEach((binding, i) => {
17+
assert.strictEqual('prototype' in binding, false, `Test ${i} failed`);
18+
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.