| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3d4a829 commit 0c236d1
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -114,13 +114,15 @@ using v8::Locker; | |||
| 114 | 114 | using v8::MaybeLocal; | |
| 115 | 115 | using v8::Message; | |
| 116 | 116 | using v8::Name; | |
| 117 | + using v8::NamedPropertyHandlerConfiguration; | ||
| 117 | 118 | using v8::Null; | |
| 118 | 119 | using v8::Number; | |
| 119 | 120 | using v8::Object; | |
| 120 | 121 | using v8::ObjectTemplate; | |
| 121 | 122 | using v8::Promise; | |
| 122 | 123 | using v8::PromiseRejectMessage; | |
| 123 | 124 | using v8::PropertyCallbackInfo; | |
| 125 | + using v8::PropertyHandlerFlags; | ||
| 124 | 126 | using v8::ScriptOrigin; | |
| 125 | 127 | using v8::SealHandleScope; | |
| 126 | 128 | using v8::String; | |
@@ -2673,7 +2675,7 @@ static void ProcessTitleSetter(Local<Name> property, | |||
| 2673 | 2675 | } | |
| 2674 | 2676 | ||
| 2675 | 2677 | ||
| 2676 | - static void EnvGetter(Local<String> property, | ||
| 2678 | + static void EnvGetter(Local<Name> property, | ||
| 2677 | 2679 | const PropertyCallbackInfo<Value>& info) { | |
| 2678 | 2680 | Isolate* isolate = info.GetIsolate(); | |
| 2679 | 2681 | #ifdef __POSIX__ | |
@@ -2701,7 +2703,7 @@ static void EnvGetter(Local<String> property, | |||
| 2701 | 2703 | } | |
| 2702 | 2704 | ||
| 2703 | 2705 | ||
| 2704 | - static void EnvSetter(Local<String> property, | ||
| 2706 | + static void EnvSetter(Local<Name> property, | ||
| 2705 | 2707 | Local<Value> value, | |
| 2706 | 2708 | const PropertyCallbackInfo<Value>& info) { | |
| 2707 | 2709 | #ifdef __POSIX__ | |
@@ -2722,7 +2724,7 @@ static void EnvSetter(Local<String> property, | |||
| 2722 | 2724 | } | |
| 2723 | 2725 | ||
| 2724 | 2726 | ||
| 2725 | - static void EnvQuery(Local<String> property, | ||
| 2727 | + static void EnvQuery(Local<Name> property, | ||
| 2726 | 2728 | const PropertyCallbackInfo<Integer>& info) { | |
| 2727 | 2729 | int32_t rc = -1; // Not found unless proven otherwise. | |
| 2728 | 2730 | #ifdef __POSIX__ | |
@@ -2748,7 +2750,7 @@ static void EnvQuery(Local<String> property, | |||
| 2748 | 2750 | } | |
| 2749 | 2751 | ||
| 2750 | 2752 | ||
| 2751 | - static void EnvDeleter(Local<String> property, | ||
| 2753 | + static void EnvDeleter(Local<Name> property, | ||
| 2752 | 2754 | const PropertyCallbackInfo<Boolean>& info) { | |
| 2753 | 2755 | #ifdef __POSIX__ | |
| 2754 | 2756 | node::Utf8Value key(info.GetIsolate(), property); | |
@@ -3147,12 +3149,15 @@ void SetupProcessObject(Environment* env, | |||
| 3147 | 3149 | // create process.env | |
| 3148 | 3150 | Local<ObjectTemplate> process_env_template = | |
| 3149 | 3151 | ObjectTemplate::New(env->isolate()); | |
| 3150 | - process_env_template->SetNamedPropertyHandler(EnvGetter, | ||
| 3151 | - EnvSetter, | ||
| 3152 | - EnvQuery, | ||
| 3153 | - EnvDeleter, | ||
| 3154 | - EnvEnumerator, | ||
| 3155 | - env->as_external()); | ||
| 3152 | + process_env_template->SetHandler(NamedPropertyHandlerConfiguration( | ||
| 3153 | + EnvGetter, | ||
| 3154 | + EnvSetter, | ||
| 3155 | + EnvQuery, | ||
| 3156 | + EnvDeleter, | ||
| 3157 | + EnvEnumerator, | ||
| 3158 | + env->as_external(), | ||
| 3159 | + PropertyHandlerFlags::kOnlyInterceptStrings)); | ||
| 3160 | + | ||
| 3156 | 3161 | Local<Object> process_env = | |
| 3157 | 3162 | process_env_template->NewInstance(env->context()).ToLocalChecked(); | |
| 3158 | 3163 | process->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "env"), 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