summaryrefslogtreecommitdiff
path: root/src/stream_base-inl.h
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2017-11-07 19:28:06 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2017-11-11 12:52:51 +0800
commit1ee32444ca8651131a413cfe80a3a21a67875fc7 (patch)
tree85f78dd89722c67552bbdaa75e1a8c855567a68d /src/stream_base-inl.h
parente6245030b193db7de9daad1e455f1fcb7ce4daac (diff)
downloadandroid-node-v8-1ee32444ca8651131a413cfe80a3a21a67875fc7.tar.gz
android-node-v8-1ee32444ca8651131a413cfe80a3a21a67875fc7.tar.bz2
android-node-v8-1ee32444ca8651131a413cfe80a3a21a67875fc7.zip
src: make StreamBase prototype accessors robust
This PR makes the prototype accessors added by StreamBase::AddMethods nonenumerable and checks the signatures in the accessors so they throw instead of raising assertions when called with incompatible receivers. They could be enumerated when inspecting the prototype with util.inspect or the inspector protocol. PR-URL: https://github.com/nodejs/node/pull/16860 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'src/stream_base-inl.h')
-rw-r--r--src/stream_base-inl.h15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/stream_base-inl.h b/src/stream_base-inl.h
index e1e50802f2..807e138ef7 100644
--- a/src/stream_base-inl.h
+++ b/src/stream_base-inl.h
@@ -11,6 +11,7 @@
namespace node {
+using v8::AccessorSignature;
using v8::External;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
@@ -31,27 +32,33 @@ void StreamBase::AddMethods(Environment* env,
HandleScope scope(env->isolate());
enum PropertyAttribute attributes =
- static_cast<PropertyAttribute>(v8::ReadOnly | v8::DontDelete);
+ static_cast<PropertyAttribute>(
+ v8::ReadOnly | v8::DontDelete | v8::DontEnum);
+ Local<AccessorSignature> signature =
+ AccessorSignature::New(env->isolate(), t);
t->PrototypeTemplate()->SetAccessor(env->fd_string(),
GetFD<Base>,
nullptr,
env->as_external(),
v8::DEFAULT,
- attributes);
+ attributes,
+ signature);
t->PrototypeTemplate()->SetAccessor(env->external_stream_string(),
GetExternal<Base>,
nullptr,
env->as_external(),
v8::DEFAULT,
- attributes);
+ attributes,
+ signature);
t->PrototypeTemplate()->SetAccessor(env->bytes_read_string(),
GetBytesRead<Base>,
nullptr,
env->as_external(),
v8::DEFAULT,
- attributes);
+ attributes,
+ signature);
env->SetProtoMethod(t, "readStart", JSMethod<Base, &StreamBase::ReadStart>);
env->SetProtoMethod(t, "readStop", JSMethod<Base, &StreamBase::ReadStop>);