| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 942a9ed commit 5df3dc1
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,6 +11,7 @@ | |||
| 11 | 11 | ||
| 12 | 12 | namespace node { | |
| 13 | 13 | ||
| 14 | + using v8::AccessorSignature; | ||
| 14 | 15 | using v8::External; | |
| 15 | 16 | using v8::FunctionCallbackInfo; | |
| 16 | 17 | using v8::FunctionTemplate; | |
@@ -31,27 +32,33 @@ void StreamBase::AddMethods(Environment* env, | |||
| 31 | 32 | HandleScope scope(env->isolate()); | |
| 32 | 33 | ||
| 33 | 34 | enum PropertyAttribute attributes = | |
| 34 | - static_cast<PropertyAttribute>(v8::ReadOnly | v8::DontDelete); | ||
| 35 | + static_cast<PropertyAttribute>( | ||
| 36 | + v8::ReadOnly | v8::DontDelete | v8::DontEnum); | ||
| 37 | + Local<AccessorSignature> signature = | ||
| 38 | + AccessorSignature::New(env->isolate(), t); | ||
| 35 | 39 | t->PrototypeTemplate()->SetAccessor(env->fd_string(), | |
| 36 | 40 | GetFD<Base>, | |
| 37 | 41 | nullptr, | |
| 38 | 42 | env->as_external(), | |
| 39 | 43 | v8::DEFAULT, | |
| 40 | - attributes); | ||
| 44 | + attributes, | ||
| 45 | + signature); | ||
| 41 | 46 | ||
| 42 | 47 | t->PrototypeTemplate()->SetAccessor(env->external_stream_string(), | |
| 43 | 48 | GetExternal<Base>, | |
| 44 | 49 | nullptr, | |
| 45 | 50 | env->as_external(), | |
| 46 | 51 | v8::DEFAULT, | |
| 47 | - attributes); | ||
| 52 | + attributes, | ||
| 53 | + signature); | ||
| 48 | 54 | ||
| 49 | 55 | t->PrototypeTemplate()->SetAccessor(env->bytes_read_string(), | |
| 50 | 56 | GetBytesRead<Base>, | |
| 51 | 57 | nullptr, | |
| 52 | 58 | env->as_external(), | |
| 53 | 59 | v8::DEFAULT, | |
| 54 | - attributes); | ||
| 60 | + attributes, | ||
| 61 | + signature); | ||
| 55 | 62 | ||
| 56 | 63 | env->SetProtoMethod(t, "readStart", JSMethod<Base, &StreamBase::ReadStart>); | |
| 57 | 64 | env->SetProtoMethod(t, "readStop", JSMethod<Base, &StreamBase::ReadStop>); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,19 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + require('../common'); | ||
| 4 | + | ||
| 5 | + // This tests that the prototype accessors added by StreamBase::AddMethods | ||
| 6 | + // are not enumerable. They could be enumerated when inspecting the prototype | ||
| 7 | + // with util.inspect or the inspector protocol. | ||
| 8 | + | ||
| 9 | + const assert = require('assert'); | ||
| 10 | + | ||
| 11 | + // Or anything that calls StreamBase::AddMethods when setting up its prototype | ||
| 12 | + const TTY = process.binding('tty_wrap').TTY; | ||
| 13 | + | ||
| 14 | + { | ||
| 15 | + assert.strictEqual(TTY.prototype.propertyIsEnumerable('bytesRead'), false); | ||
| 16 | + assert.strictEqual(TTY.prototype.propertyIsEnumerable('fd'), false); | ||
| 17 | + assert.strictEqual( | ||
| 18 | + TTY.prototype.propertyIsEnumerable('_externalStream'), false); | ||
| 19 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,27 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + require('../common'); | ||
| 4 | + | ||
| 5 | + // This tests that the prototype accessors added by StreamBase::AddMethods | ||
| 6 | + // do not raise assersions when called with incompatible receivers. | ||
| 7 | + | ||
| 8 | + const assert = require('assert'); | ||
| 9 | + | ||
| 10 | + // Or anything that calls StreamBase::AddMethods when setting up its prototype | ||
| 11 | + const TTY = process.binding('tty_wrap').TTY; | ||
| 12 | + | ||
| 13 | + // Should throw instead of raise assertions | ||
| 14 | + { | ||
| 15 | + const msg = /TypeError: Method \w+ called on incompatible receiver/; | ||
| 16 | + assert.throws(() => { | ||
| 17 | + TTY.prototype.bytesRead; | ||
| 18 | + }, msg); | ||
| 19 | + | ||
| 20 | + assert.throws(() => { | ||
| 21 | + TTY.prototype.fd; | ||
| 22 | + }, msg); | ||
| 23 | + | ||
| 24 | + assert.throws(() => { | ||
| 25 | + TTY.prototype._externalStream; | ||
| 26 | + }, msg); | ||
| 27 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments