mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
e2f151f5b2
The getter for process.env already allows symbols to be used, and `in` operator as a read-only operator can do the same. `delete a[b]` operator in ES always returns `true` without doing anything when `b in a === false`. Allow symbols in the deleter accordingly. PR-URL: https://github.com/nodejs/node/pull/11709 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
29 lines
890 B
JavaScript
29 lines
890 B
JavaScript
'use strict';
|
||
require('../common');
|
||
|
||
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 returns undefined.
|
||
assert.strictEqual(process.env[symbol], undefined);
|
||
|
||
// Verify that assigning via a symbol key throws.
|
||
assert.throws(() => {
|
||
process.env[symbol] = 42;
|
||
}, errRegExp);
|
||
|
||
// Verify that assigning a symbol value throws.
|
||
assert.throws(() => {
|
||
process.env.foo = symbol;
|
||
}, errRegExp);
|
||
|
||
// Verify that using a symbol with the in operator returns false.
|
||
assert.strictEqual(symbol in process.env, false);
|
||
|
||
// Verify that deleting a symbol key returns true.
|
||
assert.strictEqual(delete process.env[symbol], true);
|
||
|
||
// Checks that well-known symbols like `Symbol.toStringTag` won’t throw.
|
||
assert.doesNotThrow(() => Object.prototype.toString.call(process.env));
|