Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Make process.env less weird #3521

Closed
isaacs opened this issue Jun 24, 2012 · 5 comments
Closed

Make process.env less weird #3521

isaacs opened this issue Jun 24, 2012 · 5 comments
Assignees
Milestone

Comments

@isaacs
Copy link

isaacs commented Jun 24, 2012

The process.env object is a bit weird. It doesn't do prototypical inheritance at all, though its __proto__ member evaluates to an object. What's worse, it reports errors in these cases really strangely:

> process.env.toString()
TypeError: Property 'toString' of object #<error> is not a function
> process.env.xyz = function() { return 'xyz' }
[Function]
> process.env.xyz()
TypeError: Property 'xyz' of object #<error> is not a function

The historical reason for this is that process.env is actually a proxy object that calls getenv and setenv behind the scenes. This is important, because it provides a way to interact with addons that may be running in the same process (but not in the V8 runtime.) If they call setenv then the results should be visible on this object.

However, the EnvSetter and EnvGetter functions should treat __proto__ differently, and should use the Object.prototype as the prototype, so that process.env behaves more like a regular JavaScript object.

Also, whatever is causing that #<error> in the TypeError has got to go. It should report its [[Class]] value as object Environment or some such.

This cannot be done in Node v0.8, since it is a behavior change.

@piscisaureus
Copy link

@isaacs Had to revert because master was completely broken by it.

@bnoordhuis
Copy link
Member

For the record, it was making node fail at startup.

#
# Fatal error in ../deps/v8/src/handles-inl.h, line 65
# CHECK(reinterpret_cast<Address>(*location_) != kHandleZapValue) failed
#
==29807== Process terminating with default action of signal 5 (SIGTRAP)
==29807==    at 0xC23C9D: v8::internal::OS::DebugBreak() (platform-linux.cc:389)
==29807==    by 0xC23C91: v8::internal::OS::Abort() (platform-linux.cc:371)
==29807==    by 0x8BA8CB: V8_Fatal (checks.cc:58)
==29807==    by 0x895B8F: v8::internal::Handle<v8::internal::Object>::operator*() const (handles-inl.h:65)
==29807==    by 0xA2FD27: v8::internal::JSObject::GetPropertyWithInterceptor(v8::internal::JSReceiver*, v8::internal::String*, PropertyAttributes*) (objects.cc:10290)
==29807==    by 0xA0DC3E: v8::internal::Object::GetProperty(v8::internal::Object*, v8::internal::LookupResult*, v8::internal::String*, PropertyAttributes*) (objects.cc:639)
==29807==    by 0xA0D59F: v8::internal::Object::GetProperty(v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, v8::internal::LookupResult*, v8::internal::Handle<v8::internal::String>, PropertyAttributes*) (objects.cc:565)
==29807==    by 0xC4522A: v8::internal::LoadIC::Load(v8::internal::InlineCacheState, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::String>) (ic.cc:922)
==29807==    by 0xC4A4FA: v8::internal::LoadIC_Miss(v8::internal::Arguments, v8::internal::Isolate*) (ic.cc:2067)
==29807==    by 0x3F5DC580618D: ???

@ghost ghost assigned isaacs Jun 29, 2012
@isaacs
Copy link
Author

isaacs commented Jun 29, 2012

Wow, that's weird. How do you get it to blow up like that?

@isaacs
Copy link
Author

isaacs commented Jun 29, 2012

That is, is this a bug in V8's AccessorInfo stuff, or did I do something stupid like let the info->Data() get GC'd?

@bnoordhuis
Copy link
Member

@isaacs Sorry, I forgot to close this issue again. I've re-applied your commit in fee02db. The problem was a missing scope.Close(...).

isaacs added a commit that referenced this issue Jul 19, 2012
* nextTick: Handle tick callbacks before any other I/O (isaacs)

* Enable color customization of `util.inspect` (Pavel Lang)

* tls: Speed and memory improvements (Fedor Indutny)

* readline: Use one history item for reentered line (Vladimir Beloborodov)

* punycode: update to v1.1.1 (Mathias Bynens)

* Fix #3521 Make process.env more like a regular Object (isaacs)
isaacs added a commit that referenced this issue Jul 20, 2012
* nextTick: Handle tick callbacks before any other I/O (isaacs)

* Enable color customization of `util.inspect` (Pavel Lang)

* tls: Speed and memory improvements (Fedor Indutny)

* readline: Use one history item for reentered line (Vladimir Beloborodov)

* punycode: update to v1.1.1 (Mathias Bynens)

* Fix #3521 Make process.env more like a regular Object (isaacs)
isaacs added a commit that referenced this issue Jul 20, 2012
* punycode: update to v1.1.1 (Mathias Bynens)

* c-ares: upgrade to 1.9.0 (Saúl Ibarra Corretgé)

* dns: ignore rogue DNS servers reported by windows (Saúl Ibarra Corretgé)

* unix: speed up uv_async_send() (Ben Noordhuis)

* darwin: get cpu model correctly on mac (Xidorn Quan)

* nextTick: Handle tick callbacks before any other I/O (isaacs)

* Enable color customization of `util.inspect` (Pavel Lang)

* tls: Speed and memory improvements (Fedor Indutny)

* readline: Use one history item for reentered line (Vladimir Beloborodov)

* Fix #3521 Make process.env more like a regular Object (isaacs)
dscape added a commit to dscape/node that referenced this issue Sep 7, 2012
* 'master' of git://github.com/joyent/node: (143 commits)
  tls: use slab allocator
  tls: make tls a little bit faster
  readline: Use one history item for reentered line
  punycode: update to v1.1.1
  tools: update gyp to r1426
  deps: upgrade libuv to 5031a5b
  build: rename strict_aliasing to node_no_strict_aliasing
  build: disable -fstrict-aliasing for any gcc < 4.6.0
  build: detect cc version with -dumpversion
  deps: upgrade libuv to cc1b3de
  doc: document setTimeout / setInterval behavior
  build: handle output of localized gcc or clang
  build: rename openssl configure switches
  deps: upgrade libuv to 3b8c0da
  doc: fs.lchmod() is only available on OS X
  Blog post about 0.8.1
  Re-apply commit e307468.
  Revert "Fix nodejs#3521 Use an object as the process.env proto"
  2012.06.29, Version 0.8.1 (stable)
  blog: Require posts to have a date
  ...
rochoa added a commit to CartoDB/node-mapnik that referenced this issue Sep 24, 2014
…oesn't work like a proper JS object.

```
$ node -v
v0.8.28
$ node
> typeof process.env
'object'
> typeof process.env.hasOwnProperty
'undefined'
```

See: nodejs/node-v0.x-archive#3521
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants