Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup! src: store onread callback in internal field
  • Loading branch information
addaleax committed Mar 21, 2019
commit 6c6817ff0ff3a65a0fca6af376b4a6fce7b01ada
8 changes: 4 additions & 4 deletions src/base_object-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,20 @@ BaseObject::MakeLazilyInitializedJSTemplate(Environment* env) {
return t;
}

template <int kField>
template <int Field>
void BaseObject::InternalFieldGet(
v8::Local<v8::String> property,
const v8::PropertyCallbackInfo<v8::Value>& info) {
info.GetReturnValue().Set(info.This()->GetInternalField(kField));
info.GetReturnValue().Set(info.This()->GetInternalField(Field));
}

template <int kField, bool (v8::Value::* typecheck)() const>
template <int Field, bool (v8::Value::* typecheck)() const>
void BaseObject::InternalFieldSet(v8::Local<v8::String> property,
v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<void>& info) {
// This could be e.g. value->IsFunction().
CHECK_IMPLIES(typecheck != nullptr, ((*value)->*typecheck)());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since typecheck is never nullptr currently, maybe change the CHECK_IMPLIES into a simple CHECK?

You could also remove the default template argument and have a second, single-arg InternalFieldSet() without a check.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I’ve turned it into a simple CHECK and removed the nullptr default. We can always adjust this if we want.

info.This()->SetInternalField(kField, value);
info.This()->SetInternalField(Field, value);
}

} // namespace node
Expand Down
4 changes: 2 additions & 2 deletions src/base_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ class BaseObject : public MemoryRetainer {
Environment* env);

// Setter/Getter pair for internal fields that can be passed to SetAccessor.
template <int kField>
template <int Field>
static void InternalFieldGet(v8::Local<v8::String> property,
const v8::PropertyCallbackInfo<v8::Value>& info);
template <int kField, bool (v8::Value::* typecheck)() const = nullptr>
template <int Field, bool (v8::Value::* typecheck)() const = nullptr>
static void InternalFieldSet(v8::Local<v8::String> property,
v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<void>& info);
Expand Down