| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent cf5a00e commit 8a91616
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -115,13 +115,15 @@ using v8::Locker; | |||
| 115 | 115 | using v8::MaybeLocal; | |
| 116 | 116 | using v8::Message; | |
| 117 | 117 | using v8::Name; | |
| 118 | + using v8::NamedPropertyHandlerConfiguration; | ||
| 118 | 119 | using v8::Null; | |
| 119 | 120 | using v8::Number; | |
| 120 | 121 | using v8::Object; | |
| 121 | 122 | using v8::ObjectTemplate; | |
| 122 | 123 | using v8::Promise; | |
| 123 | 124 | using v8::PromiseRejectMessage; | |
| 124 | 125 | using v8::PropertyCallbackInfo; | |
| 126 | + using v8::PropertyHandlerFlags; | ||
| 125 | 127 | using v8::ScriptOrigin; | |
| 126 | 128 | using v8::SealHandleScope; | |
| 127 | 129 | using v8::String; | |
@@ -2719,7 +2721,7 @@ static void ProcessTitleSetter(Local<Name> property, | |||
| 2719 | 2721 | } | |
| 2720 | 2722 | ||
| 2721 | 2723 | ||
| 2722 | - static void EnvGetter(Local<String> property, | ||
| 2724 | + static void EnvGetter(Local<Name> property, | ||
| 2723 | 2725 | const PropertyCallbackInfo<Value>& info) { | |
| 2724 | 2726 | Isolate* isolate = info.GetIsolate(); | |
| 2725 | 2727 | #ifdef __POSIX__ | |
@@ -2747,7 +2749,7 @@ static void EnvGetter(Local<String> property, | |||
| 2747 | 2749 | } | |
| 2748 | 2750 | ||
| 2749 | 2751 | ||
| 2750 | - static void EnvSetter(Local<String> property, | ||
| 2752 | + static void EnvSetter(Local<Name> property, | ||
| 2751 | 2753 | Local<Value> value, | |
| 2752 | 2754 | const PropertyCallbackInfo<Value>& info) { | |
| 2753 | 2755 | #ifdef __POSIX__ | |
@@ -2768,7 +2770,7 @@ static void EnvSetter(Local<String> property, | |||
| 2768 | 2770 | } | |
| 2769 | 2771 | ||
| 2770 | 2772 | ||
| 2771 | - static void EnvQuery(Local<String> property, | ||
| 2773 | + static void EnvQuery(Local<Name> property, | ||
| 2772 | 2774 | const PropertyCallbackInfo<Integer>& info) { | |
| 2773 | 2775 | int32_t rc = -1; // Not found unless proven otherwise. | |
| 2774 | 2776 | #ifdef __POSIX__ | |
@@ -2794,7 +2796,7 @@ static void EnvQuery(Local<String> property, | |||
| 2794 | 2796 | } | |
| 2795 | 2797 | ||
| 2796 | 2798 | ||
| 2797 | - static void EnvDeleter(Local<String> property, | ||
| 2799 | + static void EnvDeleter(Local<Name> property, | ||
| 2798 | 2800 | const PropertyCallbackInfo<Boolean>& info) { | |
| 2799 | 2801 | #ifdef __POSIX__ | |
| 2800 | 2802 | node::Utf8Value key(info.GetIsolate(), property); | |
@@ -3221,12 +3223,15 @@ void SetupProcessObject(Environment* env, | |||
| 3221 | 3223 | // create process.env | |
| 3222 | 3224 | Local<ObjectTemplate> process_env_template = | |
| 3223 | 3225 | ObjectTemplate::New(env->isolate()); | |
| 3224 | - process_env_template->SetNamedPropertyHandler(EnvGetter, | ||
| 3225 | - EnvSetter, | ||
| 3226 | - EnvQuery, | ||
| 3227 | - EnvDeleter, | ||
| 3228 | - EnvEnumerator, | ||
| 3229 | - env->as_external()); | ||
| 3226 | + process_env_template->SetHandler(NamedPropertyHandlerConfiguration( | ||
| 3227 | + EnvGetter, | ||
| 3228 | + EnvSetter, | ||
| 3229 | + EnvQuery, | ||
| 3230 | + EnvDeleter, | ||
| 3231 | + EnvEnumerator, | ||
| 3232 | + env->as_external(), | ||
| 3233 | + PropertyHandlerFlags::kOnlyInterceptStrings)); | ||
| 3234 | + | ||
| 3230 | 3235 | Local<Object> process_env = | |
| 3231 | 3236 | process_env_template->NewInstance(env->context()).ToLocalChecked(); | |
| 3232 | 3237 | process->Set(env->env_string(), process_env); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,34 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + require('../common'); | ||
| 3 | + | ||
| 4 | + const assert = require('assert'); | ||
| 5 | + | ||
| 6 | + // Test that the v8 named property handler intercepts callbacks | ||
| 7 | + // when properties are defined as Strings and NOT for Symbols. | ||
| 8 | + // | ||
| 9 | + // With the kOnlyInterceptStrings flag, manipulating properties via | ||
| 10 | + // Strings is intercepted by the callbacks, while Symbols adopt | ||
| 11 | + // the default global behaviour. | ||
| 12 | + // Removing the kOnlyInterceptStrings flag, adds intercepting to Symbols, | ||
| 13 | + // which causes Type Error at process.env[symbol]=42 due to process.env being | ||
| 14 | + // strongly typed for Strings | ||
| 15 | + // (node::Utf8Value key(info.GetIsolate(), property);). | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + const symbol = Symbol('sym'); | ||
| 19 | + | ||
| 20 | + // check if its undefined | ||
| 21 | + assert.strictEqual(process.env[symbol], undefined); | ||
| 22 | + | ||
| 23 | + // set a value using a Symbol | ||
| 24 | + process.env[symbol] = 42; | ||
| 25 | + | ||
| 26 | + // set a value using a String (call to EnvSetter, node.cc) | ||
| 27 | + process.env['s'] = 42; | ||
| 28 | + | ||
| 29 | + //check the values after substitutions | ||
| 30 | + assert.strictEqual(42, process.env[symbol]); | ||
| 31 | + assert.strictEqual('42', process.env['s']); | ||
| 32 | + | ||
| 33 | + delete process.env[symbol]; | ||
| 34 | + assert.strictEqual(undefined, process.env[symbol]); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments