summaryrefslogtreecommitdiff
path: root/src/node_os.cc
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2014-10-13 15:19:55 +0200
committerFedor Indutny <fedor@indutny.com>2014-10-13 23:46:46 +0400
commitd3c317e08ac6a624fde8b242905992eafdd954ac (patch)
tree1dd2756855ab5b4513503acc660705fa898c5c64 /src/node_os.cc
parentb45d33617b569bf5fa84c9343da9f7d129756968 (diff)
downloadandroid-node-v8-d3c317e08ac6a624fde8b242905992eafdd954ac.tar.gz
android-node-v8-d3c317e08ac6a624fde8b242905992eafdd954ac.tar.bz2
android-node-v8-d3c317e08ac6a624fde8b242905992eafdd954ac.zip
src: attach env directly to api functions
Attach the per-context execution environment directly to API functions. Rationale: * Gets node one step closer to multi-isolate readiness. * Avoids multi-context confusion, e.g. when the caller and callee live in different contexts. * Avoids expensive calls to pthread_getspecific() on platforms where V8 does not know how to use the thread-local storage directly. (Linux, the BSDs.) PR-URL: https://github.com/node-forward/node/pull/18 Reviewed-By: Fedor Indutny <fedor@indutny.com>
Diffstat (limited to 'src/node_os.cc')
-rw-r--r--src/node_os.cc35
1 files changed, 18 insertions, 17 deletions
diff --git a/src/node_os.cc b/src/node_os.cc
index 4d8dc5c31d..53d3d21e56 100644
--- a/src/node_os.cc
+++ b/src/node_os.cc
@@ -60,14 +60,14 @@ using v8::Value;
static void GetEndianness(const FunctionCallbackInfo<Value>& args) {
- Environment* env = Environment::GetCurrent(args.GetIsolate());
+ Environment* env = Environment::GetCurrent(args);
const char* rval = IsBigEndian() ? "BE" : "LE";
args.GetReturnValue().Set(OneByteString(env->isolate(), rval));
}
static void GetHostname(const FunctionCallbackInfo<Value>& args) {
- Environment* env = Environment::GetCurrent(args.GetIsolate());
+ Environment* env = Environment::GetCurrent(args);
char buf[MAXHOSTNAMELEN + 1];
if (gethostname(buf, sizeof(buf))) {
@@ -85,7 +85,7 @@ static void GetHostname(const FunctionCallbackInfo<Value>& args) {
static void GetOSType(const FunctionCallbackInfo<Value>& args) {
- Environment* env = Environment::GetCurrent(args.GetIsolate());
+ Environment* env = Environment::GetCurrent(args);
const char* rval;
#ifdef __POSIX__
@@ -103,7 +103,7 @@ static void GetOSType(const FunctionCallbackInfo<Value>& args) {
static void GetOSRelease(const FunctionCallbackInfo<Value>& args) {
- Environment* env = Environment::GetCurrent(args.GetIsolate());
+ Environment* env = Environment::GetCurrent(args);
const char* rval;
#ifdef __POSIX__
@@ -134,7 +134,7 @@ static void GetOSRelease(const FunctionCallbackInfo<Value>& args) {
static void GetCPUInfo(const FunctionCallbackInfo<Value>& args) {
- Environment* env = Environment::GetCurrent(args.GetIsolate());
+ Environment* env = Environment::GetCurrent(args);
uv_cpu_info_t* cpu_infos;
int count, i;
@@ -198,7 +198,7 @@ static void GetUptime(const FunctionCallbackInfo<Value>& args) {
static void GetLoadAvg(const FunctionCallbackInfo<Value>& args) {
- Environment* env = Environment::GetCurrent(args.GetIsolate());
+ Environment* env = Environment::GetCurrent(args);
double loadavg[3];
uv_loadavg(loadavg);
Local<Array> loads = Array::New(env->isolate(), 3);
@@ -210,7 +210,7 @@ static void GetLoadAvg(const FunctionCallbackInfo<Value>& args) {
static void GetInterfaceAddresses(const FunctionCallbackInfo<Value>& args) {
- Environment* env = Environment::GetCurrent(args.GetIsolate());
+ Environment* env = Environment::GetCurrent(args);
uv_interface_address_t* interfaces;
int count, i;
char ip[INET6_ADDRSTRLEN];
@@ -289,16 +289,17 @@ static void GetInterfaceAddresses(const FunctionCallbackInfo<Value>& args) {
void Initialize(Handle<Object> target,
Handle<Value> unused,
Handle<Context> context) {
- NODE_SET_METHOD(target, "getEndianness", GetEndianness);
- NODE_SET_METHOD(target, "getHostname", GetHostname);
- NODE_SET_METHOD(target, "getLoadAvg", GetLoadAvg);
- NODE_SET_METHOD(target, "getUptime", GetUptime);
- NODE_SET_METHOD(target, "getTotalMem", GetTotalMemory);
- NODE_SET_METHOD(target, "getFreeMem", GetFreeMemory);
- NODE_SET_METHOD(target, "getCPUs", GetCPUInfo);
- NODE_SET_METHOD(target, "getOSType", GetOSType);
- NODE_SET_METHOD(target, "getOSRelease", GetOSRelease);
- NODE_SET_METHOD(target, "getInterfaceAddresses", GetInterfaceAddresses);
+ Environment* env = Environment::GetCurrent(context);
+ env->SetMethod(target, "getEndianness", GetEndianness);
+ env->SetMethod(target, "getHostname", GetHostname);
+ env->SetMethod(target, "getLoadAvg", GetLoadAvg);
+ env->SetMethod(target, "getUptime", GetUptime);
+ env->SetMethod(target, "getTotalMem", GetTotalMemory);
+ env->SetMethod(target, "getFreeMem", GetFreeMemory);
+ env->SetMethod(target, "getCPUs", GetCPUInfo);
+ env->SetMethod(target, "getOSType", GetOSType);
+ env->SetMethod(target, "getOSRelease", GetOSRelease);
+ env->SetMethod(target, "getInterfaceAddresses", GetInterfaceAddresses);
}
} // namespace os