mirror of https://github.com/lukechilds/node.git
Browse Source
This commit causes process.env to throw when a symbol is used as either a key or a value. Fixes: https://github.com/nodejs/node/issues/9429 PR-URL: https://github.com/nodejs/node/pull/9446 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Minwoo Jung <jmwsoft@gmail.com>v6
cjihrig
8 years ago
3 changed files with 32 additions and 42 deletions
@ -0,0 +1,26 @@ |
|||||
|
'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 throws.
|
||||
|
assert.throws(() => { |
||||
|
process.env[symbol]; |
||||
|
}, errRegExp); |
||||
|
|
||||
|
// 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 throws.
|
||||
|
assert.throws(() => { |
||||
|
symbol in process.env; |
||||
|
}, errRegExp); |
@ -1,34 +0,0 @@ |
|||||
'use strict'; |
|
||||
require('../common'); |
|
||||
|
|
||||
const assert = require('assert'); |
|
||||
|
|
||||
// Test that the v8 named property handler intercepts callbacks
|
|
||||
// when properties are defined as Strings and NOT for Symbols.
|
|
||||
//
|
|
||||
// With the kOnlyInterceptStrings flag, manipulating properties via
|
|
||||
// Strings is intercepted by the callbacks, while Symbols adopt
|
|
||||
// the default global behaviour.
|
|
||||
// Removing the kOnlyInterceptStrings flag, adds intercepting to Symbols,
|
|
||||
// which causes Type Error at process.env[symbol]=42 due to process.env being
|
|
||||
// strongly typed for Strings
|
|
||||
// (node::Utf8Value key(info.GetIsolate(), property);).
|
|
||||
|
|
||||
|
|
||||
const symbol = Symbol('sym'); |
|
||||
|
|
||||
// check if its undefined
|
|
||||
assert.strictEqual(process.env[symbol], undefined); |
|
||||
|
|
||||
// set a value using a Symbol
|
|
||||
process.env[symbol] = 42; |
|
||||
|
|
||||
// set a value using a String (call to EnvSetter, node.cc)
|
|
||||
process.env['s'] = 42; |
|
||||
|
|
||||
//check the values after substitutions
|
|
||||
assert.strictEqual(42, process.env[symbol]); |
|
||||
assert.strictEqual('42', process.env['s']); |
|
||||
|
|
||||
delete process.env[symbol]; |
|
||||
assert.strictEqual(undefined, process.env[symbol]); |
|
Loading…
Reference in new issue