Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: move AsyncResource impl out of public header #26348

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@
'dependencies': [ 'deps/histogram/histogram.gyp:histogram' ],

'sources': [
'src/api/async_resource.cc',
'src/api/callback.cc',
'src/api/encoding.cc',
'src/api/environment.cc',
Expand Down
70 changes: 70 additions & 0 deletions src/api/async_resource.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include "node.h"

namespace node {

using v8::Function;
using v8::HandleScope;
using v8::Isolate;
using v8::Local;
using v8::MaybeLocal;
using v8::Object;
using v8::String;
using v8::Value;

AsyncResource::AsyncResource(Isolate* isolate,
Local<Object> resource,
const char* name,
async_id trigger_async_id)
: isolate_(isolate),
resource_(isolate, resource) {
async_context_ = EmitAsyncInit(isolate, resource, name,
trigger_async_id);
}

AsyncResource::~AsyncResource() {
EmitAsyncDestroy(isolate_, async_context_);
resource_.Reset();
}

MaybeLocal<Value> AsyncResource::MakeCallback(Local<Function> callback,
int argc,
Local<Value>* argv) {
return node::MakeCallback(isolate_, get_resource(),
callback, argc, argv,
async_context_);
}

MaybeLocal<Value> AsyncResource::MakeCallback(const char* method,
int argc,
Local<Value>* argv) {
return node::MakeCallback(isolate_, get_resource(),
method, argc, argv,
async_context_);
}

MaybeLocal<Value> AsyncResource::MakeCallback(Local<String> symbol,
int argc,
Local<Value>* argv) {
return node::MakeCallback(isolate_, get_resource(),
symbol, argc, argv,
async_context_);
}

Local<Object> AsyncResource::get_resource() {
return resource_.Get(isolate_);
}

async_id AsyncResource::get_async_id() const {
return async_context_.async_id;
}

async_id AsyncResource::get_trigger_async_id() const {
return async_context_.trigger_async_id;
}

AsyncResource::CallbackScope::CallbackScope(AsyncResource* res)
: node::CallbackScope(res->isolate_,
res->resource_.Get(res->isolate_),
res->async_context_) {}

} // namespace node
56 changes: 14 additions & 42 deletions src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -756,69 +756,41 @@ v8::MaybeLocal<v8::Value> MakeCallback(v8::Isolate* isolate,
/* Helper class users can optionally inherit from. If
* `AsyncResource::MakeCallback()` is used, then all four callbacks will be
* called automatically. */
class AsyncResource {
class NODE_EXTERN AsyncResource {
public:
AsyncResource(v8::Isolate* isolate,
v8::Local<v8::Object> resource,
const char* name,
async_id trigger_async_id = -1)
: isolate_(isolate),
resource_(isolate, resource) {
async_context_ = EmitAsyncInit(isolate, resource, name,
trigger_async_id);
}
async_id trigger_async_id = -1);

virtual ~AsyncResource() {
EmitAsyncDestroy(isolate_, async_context_);
resource_.Reset();
}
virtual ~AsyncResource();
refack marked this conversation as resolved.
Show resolved Hide resolved

AsyncResource(const AsyncResource&) = delete;
void operator=(const AsyncResource&) = delete;

v8::MaybeLocal<v8::Value> MakeCallback(
v8::Local<v8::Function> callback,
int argc,
v8::Local<v8::Value>* argv) {
return node::MakeCallback(isolate_, get_resource(),
callback, argc, argv,
async_context_);
}
v8::Local<v8::Value>* argv);

v8::MaybeLocal<v8::Value> MakeCallback(
const char* method,
int argc,
v8::Local<v8::Value>* argv) {
return node::MakeCallback(isolate_, get_resource(),
method, argc, argv,
async_context_);
}
v8::Local<v8::Value>* argv);

v8::MaybeLocal<v8::Value> MakeCallback(
v8::Local<v8::String> symbol,
int argc,
v8::Local<v8::Value>* argv) {
return node::MakeCallback(isolate_, get_resource(),
symbol, argc, argv,
async_context_);
}
v8::Local<v8::Value>* argv);

v8::Local<v8::Object> get_resource() {
return resource_.Get(isolate_);
}

async_id get_async_id() const {
return async_context_.async_id;
}

async_id get_trigger_async_id() const {
return async_context_.trigger_async_id;
}
v8::Local<v8::Object> get_resource();
async_id get_async_id() const;
async_id get_trigger_async_id() const;

protected:
class CallbackScope : public node::CallbackScope {
class NODE_EXTERN CallbackScope : public node::CallbackScope {
public:
explicit CallbackScope(AsyncResource* res)
: node::CallbackScope(res->isolate_,
res->resource_.Get(res->isolate_),
res->async_context_) {}
explicit CallbackScope(AsyncResource* res);
};

private:
Expand Down