diff options
author | James M Snell <jasnell@gmail.com> | 2020-02-26 01:37:33 +0300 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2020-03-02 21:58:36 +0300 |
commit | 0fac393d263fc7e2f4f054c9d4aab0c1c3cf00c8 (patch) | |
tree | f11f3380bc282709feed38b957e38ad3adf2a4a5 /src/stream_base.cc | |
parent | 68e36ade3de2205c583f2cc6a2d2ec192b75cc95 (diff) |
src: improve handling of internal field counting
Change suggested by bnoordhuis.
Improve handing of internal field counting by using enums.
Helps protect against future possible breakage if field
indexes are ever changed or added to.
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/31960
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'src/stream_base.cc')
-rw-r--r-- | src/stream_base.cc | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/stream_base.cc b/src/stream_base.cc index eaccfc995c7..28a3bf65fc0 100644 --- a/src/stream_base.cc +++ b/src/stream_base.cc @@ -340,7 +340,8 @@ MaybeLocal<Value> StreamBase::CallJSOnreadMethod(ssize_t nread, AsyncWrap* wrap = GetAsyncWrap(); CHECK_NOT_NULL(wrap); - Local<Value> onread = wrap->object()->GetInternalField(kOnReadFunctionField); + Local<Value> onread = wrap->object()->GetInternalField( + StreamBase::kOnReadFunctionField); CHECK(onread->IsFunction()); return wrap->MakeCallback(onread.As<Function>(), arraysize(argv), argv); } @@ -409,8 +410,11 @@ void StreamBase::AddMethods(Environment* env, Local<FunctionTemplate> t) { True(env->isolate())); t->PrototypeTemplate()->SetAccessor( FIXED_ONE_BYTE_STRING(env->isolate(), "onread"), - BaseObject::InternalFieldGet<kOnReadFunctionField>, - BaseObject::InternalFieldSet<kOnReadFunctionField, &Value::IsFunction>); + BaseObject::InternalFieldGet< + StreamBase::kOnReadFunctionField>, + BaseObject::InternalFieldSet< + StreamBase::kOnReadFunctionField, + &Value::IsFunction>); } void StreamBase::GetFD(const FunctionCallbackInfo<Value>& args) { |