mirror of
https://github.com/nodejs/node.git
synced 2026-12-06 05:18:56 -05:00
- Instead of storing a pointer whose type refers to the specific subclass of `BaseObject`, just store a `BaseObject*` directly. This means in particular that one can cast to classes along the way of the inheritance chain without issues, and that `BaseObject*` no longer needs to be the first superclass in the case of multiple inheritance. In particular, this renders hack-y solutions to this problem (likeddc19be6de) obsolete and addresses a `TODO` comment of mine. - Move wrapping/unwrapping methods to the `BaseObject` class. We use these almost exclusively for `BaseObject`s, and I hope that this gives a better idea of how (and for what) these are used in our code. - Perform initialization/deinitialization of the internal field in the `BaseObject*` constructor/destructor. This makes the code a bit more obviously correct, avoids explicit calls for this in subclass constructors, and in particular allows us to avoid crash situations when we previously called `ClearWrap()` during GC. This also means that we enforce that the object passed to the `BaseObject` constructor needs to have an internal field. This is the only reason for the test change. - Change the signature of `MakeWeak()` to not require a pointer argument. Previously, this would always have been the same as `this`, and no other value made sense. Also, the parameter was something that I personally found somewhat confusing when becoming familiar with Node’s code. - Add a `TODO` comment that motivates switching to real inheritance for the JS types we expose from the native side. This patch brings us a lot closer to being able to do that. - Some less significant drive-by cleanup. Since we *effectively* already store the `BaseObject*` pointer anyway sinceddc19be6de, I do not think that this is going to have any impact on diagnostic tooling. Fixes: https://github.com/nodejs/node/issues/18897 PR-URL: https://github.com/nodejs/node/pull/20455 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
56 lines
1.5 KiB
C++
56 lines
1.5 KiB
C++
#ifndef SRC_JS_STREAM_H_
|
|
#define SRC_JS_STREAM_H_
|
|
|
|
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
|
|
#include "async_wrap.h"
|
|
#include "env.h"
|
|
#include "stream_base.h"
|
|
#include "v8.h"
|
|
|
|
namespace node {
|
|
|
|
class JSStream : public AsyncWrap, public StreamBase {
|
|
public:
|
|
static void Initialize(v8::Local<v8::Object> target,
|
|
v8::Local<v8::Value> unused,
|
|
v8::Local<v8::Context> context);
|
|
|
|
bool IsAlive() override;
|
|
bool IsClosing() override;
|
|
int ReadStart() override;
|
|
int ReadStop() override;
|
|
|
|
int DoShutdown(ShutdownWrap* req_wrap) override;
|
|
int DoWrite(WriteWrap* w,
|
|
uv_buf_t* bufs,
|
|
size_t count,
|
|
uv_stream_t* send_handle) override;
|
|
|
|
size_t self_size() const override { return sizeof(*this); }
|
|
|
|
protected:
|
|
JSStream(Environment* env, v8::Local<v8::Object> obj);
|
|
|
|
AsyncWrap* GetAsyncWrap() override;
|
|
|
|
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
static void ReadBuffer(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
static void EmitEOF(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void OnAllocImpl(size_t size, uv_buf_t* buf, void* ctx);
|
|
static void OnReadImpl(ssize_t nread,
|
|
const uv_buf_t* buf,
|
|
uv_handle_type pending,
|
|
void* ctx);
|
|
|
|
template <class Wrap>
|
|
static void Finish(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
};
|
|
|
|
} // namespace node
|
|
|
|
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
|
|
#endif // SRC_JS_STREAM_H_
|