The changes introdcued here replace the deprecated v8 method SetNamedPropertyHandler() to SetHandler() in node.cc. Prior to refactoring, the method defined callbacks when accessing object properties defined by Strings and not Symbols. test/parallel/test-v8-interceptStrings-not-Symbols.js demonstrates that this behaviour remained unchanged after refactoring. PR-URL: https://github.com/nodejs/node/pull/9062 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
34 lines
1 KiB
JavaScript
34 lines
1 KiB
JavaScript
'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]);
|