Browse Source

win: fix test-process-env

Remove support for setting process.env.TZ as it doesn't seem we can do it
x-platform without fixing V8.
v0.7.4-release
Ryan Dahl 14 years ago
parent
commit
e6b06bc6c5
  1. 1
      Makefile
  2. 25
      src/node.cc
  3. 11
      test/simple/test-process-env.js

1
Makefile

@ -177,6 +177,7 @@ UVTEST += simple/test-module-load-list
UVTEST += simple/test-path UVTEST += simple/test-path
UVTEST += simple/test-pipe-stream UVTEST += simple/test-pipe-stream
UVTEST += simple/test-pipe-file-to-http UVTEST += simple/test-pipe-file-to-http
UVTEST += simple/test-process-env
UVTEST += simple/test-pump-file2tcp UVTEST += simple/test-pump-file2tcp
UVTEST += simple/test-pump-file2tcp-noexist UVTEST += simple/test-pump-file2tcp-noexist
UVTEST += simple/test-punycode UVTEST += simple/test-punycode

25
src/node.cc

@ -2002,13 +2002,23 @@ static Handle<Value> EnvGetterWarn(Local<String> property,
static Handle<Value> EnvSetter(Local<String> property, static Handle<Value> EnvSetter(Local<String> property,
Local<Value> value, Local<Value> value,
const AccessorInfo& info) { const AccessorInfo& info) {
HandleScope scope;
String::Utf8Value key(property); String::Utf8Value key(property);
String::Utf8Value val(value); String::Utf8Value val(value);
#ifdef __POSIX__ #ifdef __POSIX__
setenv(*key, *val, 1); setenv(*key, *val, 1);
#else // __WIN32__ #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 #endif
return value; return value;
} }
@ -2026,15 +2036,26 @@ static Handle<Integer> EnvQuery(Local<String> property,
static Handle<Boolean> EnvDeleter(Local<String> property, static Handle<Boolean> EnvDeleter(Local<String> property,
const AccessorInfo& info) { const AccessorInfo& info) {
HandleScope scope;
String::Utf8Value key(property); String::Utf8Value key(property);
if (getenv(*key)) { if (getenv(*key)) {
#ifdef __POSIX__ #ifdef __POSIX__
unsetenv(*key); // prototyped as `void unsetenv(const char*)` on some platforms unsetenv(*key); // prototyped as `void unsetenv(const char*)` on some platforms
#else #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 #endif
return True(); return True();
} }
return False(); return False();
} }

11
test/simple/test-process-env.js

@ -25,10 +25,21 @@ process.env.TZ = 'Europe/Amsterdam';
assert = require('assert'); assert = require('assert');
spawn = require('child_process').spawn; 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 // time difference between Greenwich and Amsterdam is +2 hours in the summer
date = new Date('Fri, 10 Sep 1982 03:15:00 GMT'); date = new Date('Fri, 10 Sep 1982 03:15:00 GMT');
assert.equal(3, date.getUTCHours()); assert.equal(3, date.getUTCHours());
assert.equal(5, date.getHours()); assert.equal(5, date.getHours());
*/
// changes in environment should be visible to child processes // changes in environment should be visible to child processes
if (process.argv[2] == 'you-are-the-child') { if (process.argv[2] == 'you-are-the-child') {

Loading…
Cancel
Save