diff options
author | Anatoli Papirovski <apapirovski@mac.com> | 2018-01-19 15:42:59 -0500 |
---|---|---|
committer | Anatoli Papirovski <apapirovski@mac.com> | 2018-01-29 11:37:29 -0500 |
commit | eeede3b19c8bdb78605764eec75bea327c9014ff (patch) | |
tree | f57709e12c4e7e9562951bb07042f0023925a441 /src/node_domain.cc | |
parent | e4743ab61929bcccc729165e74eb6d6b3ef25135 (diff) | |
download | android-node-v8-eeede3b19c8bdb78605764eec75bea327c9014ff.tar.gz android-node-v8-eeede3b19c8bdb78605764eec75bea327c9014ff.tar.bz2 android-node-v8-eeede3b19c8bdb78605764eec75bea327c9014ff.zip |
domain: further abstract usage in C++
Move the majority of C++ domain-related code into JS land by introducing
a top level domain callback which handles entering & exiting the domain.
Move the rest of the domain necessities into their own file that creates
an internal binding, to avoid exposing domain-related code on the
process object.
Modify an existing test slightly to better test domain-related code.
PR-URL: https://github.com/nodejs/node/pull/18291
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/node_domain.cc')
-rw-r--r-- | src/node_domain.cc | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/node_domain.cc b/src/node_domain.cc new file mode 100644 index 0000000000..f4f585ac4f --- /dev/null +++ b/src/node_domain.cc @@ -0,0 +1,34 @@ +#include "v8.h" +#include "node_internals.h" + +namespace node { +namespace domain { + +using v8::Context; +using v8::Function; +using v8::FunctionCallbackInfo; +using v8::Local; +using v8::Object; +using v8::Value; + + +void Enable(const FunctionCallbackInfo<Value>& args) { + Environment* env = Environment::GetCurrent(args); + + CHECK(args[0]->IsFunction()); + + env->set_domain_callback(args[0].As<Function>()); +} + +void Initialize(Local<Object> target, + Local<Value> unused, + Local<Context> context) { + Environment* env = Environment::GetCurrent(context); + + env->SetMethod(target, "enable", Enable); +} + +} // namespace domain +} // namespace node + +NODE_MODULE_CONTEXT_AWARE_INTERNAL(domain, node::domain::Initialize) |