@@ -453,6 +453,16 @@ class NgRcBufPointer : public MemoryRetainer { |
453 | 453 | bool internalizable_ = false; |
454 | 454 | }; |
455 | 455 |
|
| 456 | +template <typename allocator_t> |
| 457 | +struct NgHeaderBase : public MemoryRetainer { |
| 458 | + virtual v8::MaybeLocal<v8::String> GetName(allocator_t* allocator) const = 0; |
| 459 | + virtual v8::MaybeLocal<v8::String> GetValue(allocator_t* allocator) const = 0; |
| 460 | + virtual std::string name() const = 0; |
| 461 | + virtual std::string value() const = 0; |
| 462 | + virtual size_t length() const = 0; |
| 463 | + virtual std::string ToString() const; |
| 464 | +}; |
| 465 | + |
456 | 466 | // The ng libraries use nearly identical structs to represent |
457 | 467 | // received http headers. The NgHeader class wraps those in a |
458 | 468 | // consistent way and allows converting the name and value to |
@@ -461,7 +471,7 @@ class NgRcBufPointer : public MemoryRetainer { |
461 | 471 | // memory tracking, and implementation of static utility functions. |
462 | 472 | // See Http2HeaderTraits in node_http2.h for an example. |
463 | 473 | template <typename T> |
464 | | -class NgHeader : public MemoryRetainer { |
| 474 | +class NgHeader final : public NgHeaderBase<typename T::allocator_t> { |
465 | 475 | public: |
466 | 476 | typedef typename T::rcbufferpointer_t rcbufferpointer_t; |
467 | 477 | typedef typename T::rcbufferpointer_t::rcbuf_t rcbuf_t; |
@@ -487,28 +497,20 @@ class NgHeader : public MemoryRetainer { |
487 | 497 | // object to the v8 string. Once the v8 string is garbage collected, |
488 | 498 | // the reference counter will be decremented. |
489 | 499 |
|
490 | | - inline v8::MaybeLocal<v8::String> GetName(allocator_t* allocator) const; |
491 | | - inline v8::MaybeLocal<v8::String> GetValue(allocator_t* allocator) const; |
| 500 | + inline v8::MaybeLocal<v8::String> GetName( |
| 501 | + allocator_t* allocator) const override; |
| 502 | + inline v8::MaybeLocal<v8::String> GetValue( |
| 503 | + allocator_t* allocator) const override; |
492 | 504 |
|
493 | | - inline std::string name() const; |
494 | | - inline std::string value() const; |
495 | | - inline size_t length() const; |
| 505 | + inline std::string name() const override; |
| 506 | + inline std::string value() const override; |
| 507 | + inline size_t length() const override; |
496 | 508 |
|
497 | | - void MemoryInfo(MemoryTracker* tracker) const override { |
498 | | - tracker->TrackField("name", name_); |
499 | | - tracker->TrackField("value", value_); |
500 | | - } |
| 509 | + void MemoryInfo(MemoryTracker* tracker) const override; |
501 | 510 |
|
502 | 511 | SET_MEMORY_INFO_NAME(NgHeader) |
503 | 512 | SET_SELF_SIZE(NgHeader) |
504 | 513 |
|
505 | | - std::string ToString() const { |
506 | | - std::string ret = name(); |
507 | | - ret += " = "; |
508 | | - ret += value(); |
509 | | - return ret; |
510 | | - } |
511 | | - |
512 | 514 | private: |
513 | 515 | Environment* env_; |
514 | 516 | rcbufferpointer_t name_; |
|