Skip to content

Commit

Permalink
win: fix test-process-env
Browse files Browse the repository at this point in the history
Remove support for setting process.env.TZ as it doesn't seem we can do it
x-platform without fixing V8.
  • Loading branch information
ry committed Aug 11, 2011
1 parent e62cdd0 commit e6b06bc
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions Makefile
Expand Up @@ -177,6 +177,7 @@ UVTEST += simple/test-module-load-list
UVTEST += simple/test-path
UVTEST += simple/test-pipe-stream
UVTEST += simple/test-pipe-file-to-http
UVTEST += simple/test-process-env
UVTEST += simple/test-pump-file2tcp
UVTEST += simple/test-pump-file2tcp-noexist
UVTEST += simple/test-punycode
Expand Down
25 changes: 23 additions & 2 deletions src/node.cc
Expand Up @@ -2002,13 +2002,23 @@ static Handle<Value> EnvGetterWarn(Local<String> property,
static Handle<Value> EnvSetter(Local<String> property,
Local<Value> value,
const AccessorInfo& info) {
HandleScope scope;
String::Utf8Value key(property);
String::Utf8Value val(value);

#ifdef __POSIX__
setenv(*key, *val, 1);
#else // __WIN32__
NO_IMPL_MSG(setenv)
int n = key.length() + val.length() + 2;
char* pair = new char[n];
snprintf(pair, n, "%s=%s", *key, *val);
int r = _putenv(pair);
if (r) {
fprintf(stderr, "error putenv: '%s'\n", pair);
}
delete [] pair;
#endif

return value;
}

Expand All @@ -2026,15 +2036,26 @@ static Handle<Integer> EnvQuery(Local<String> property,

static Handle<Boolean> EnvDeleter(Local<String> property,
const AccessorInfo& info) {
HandleScope scope;

String::Utf8Value key(property);

if (getenv(*key)) {
#ifdef __POSIX__
unsetenv(*key); // prototyped as `void unsetenv(const char*)` on some platforms
#else
NO_IMPL_MSG(unsetenv)
int n = key.length() + 2;
char* pair = new char[n];
snprintf(pair, n, "%s=", *key);
int r = _putenv(pair);
if (r) {
fprintf(stderr, "error unsetenv: '%s'\n", pair);
}
delete [] pair;
#endif
return True();
}

return False();
}

Expand Down
11 changes: 11 additions & 0 deletions test/simple/test-process-env.js
Expand Up @@ -25,10 +25,21 @@ process.env.TZ = 'Europe/Amsterdam';
assert = require('assert');
spawn = require('child_process').spawn;

/* For the moment we are not going to support setting the timezone via the
* environment variables. The problem is that various V8 platform backends
* deal with timezone in different ways. The windows platform backend caches
* the timezone value while the Linux one hits libc for every query.
https://github.com/joyent/node/blob/08782931205bc4f6d28102ebc29fd806e8ccdf1f/deps/v8/src/platform-linux.cc#L339-345
https://github.com/joyent/node/blob/08782931205bc4f6d28102ebc29fd806e8ccdf1f/deps/v8/src/platform-win32.cc#L590-596
// time difference between Greenwich and Amsterdam is +2 hours in the summer
date = new Date('Fri, 10 Sep 1982 03:15:00 GMT');
assert.equal(3, date.getUTCHours());
assert.equal(5, date.getHours());
*/


// changes in environment should be visible to child processes
if (process.argv[2] == 'you-are-the-child') {
Expand Down

0 comments on commit e6b06bc

Please sign in to comment.