-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src: replace SetNamedPropertyHandler() with SetHandler()
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.
- Loading branch information
Showing
2 changed files
with
50 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'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]); |