diff options
-rw-r--r-- | src/node.cc | 3 | ||||
-rw-r--r-- | test/parallel/test-process-env-symbols.js | 9 | ||||
-rw-r--r-- | test/parallel/test-util-inspect.js | 2 |
3 files changed, 10 insertions, 4 deletions
diff --git a/src/node.cc b/src/node.cc index e4c17af3ec..476c147c0b 100644 --- a/src/node.cc +++ b/src/node.cc @@ -2681,6 +2681,9 @@ static void ProcessTitleSetter(Local<Name> property, static void EnvGetter(Local<Name> property, const PropertyCallbackInfo<Value>& info) { Isolate* isolate = info.GetIsolate(); + if (property->IsSymbol()) { + return info.GetReturnValue().SetUndefined(); + } #ifdef __POSIX__ node::Utf8Value key(isolate, property); const char* val = getenv(*key); diff --git a/test/parallel/test-process-env-symbols.js b/test/parallel/test-process-env-symbols.js index bb6e1f8778..a8798fc457 100644 --- a/test/parallel/test-process-env-symbols.js +++ b/test/parallel/test-process-env-symbols.js @@ -5,10 +5,8 @@ const assert = require('assert'); const symbol = Symbol('sym'); const errRegExp = /^TypeError: Cannot convert a Symbol value to a string$/; -// Verify that getting via a symbol key throws. -assert.throws(() => { - process.env[symbol]; -}, errRegExp); +// Verify that getting via a symbol key returns undefined. +assert.strictEqual(process.env[symbol], undefined); // Verify that assigning via a symbol key throws. assert.throws(() => { @@ -24,3 +22,6 @@ assert.throws(() => { assert.throws(() => { symbol in process.env; }, errRegExp); + +// Checks that well-known symbols like `Symbol.toStringTag` won’t throw. +assert.doesNotThrow(() => Object.prototype.toString.call(process.env)); diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index f730ec1c98..7fd6829542 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -925,3 +925,5 @@ checkAlignment(new Map(big_array.map(function(y) { return [y, null]; }))); util.inspect.defaultOptions = 'bad'; }, /"options" must be an object/); } + +assert.doesNotThrow(() => util.inspect(process)); |