@@ -114,13 +114,6 @@ typedef int mode_t;
114
114
#include < dlfcn.h>
115
115
#endif
116
116
117
- #ifdef __APPLE__
118
- #include < crt_externs.h>
119
- #define environ (*_NSGetEnviron ())
120
- #elif !defined(_MSC_VER)
121
- extern char **environ;
122
- #endif
123
-
124
117
// This is used to load built-in modules. Instead of using
125
118
// __attribute__((constructor)), we call the _register_<modname>
126
119
// function for each built-in modules explicitly in
@@ -168,9 +161,6 @@ using v8::Undefined;
168
161
using v8::V8;
169
162
using v8::Value;
170
163
171
- static Mutex process_mutex;
172
- static Mutex environ_mutex;
173
-
174
164
static bool v8_is_profiling = false ;
175
165
static bool node_is_initialized = false ;
176
166
static uv_once_t init_modpending_once = UV_ONCE_INIT;
@@ -1694,221 +1684,6 @@ static void GetLinkedBinding(const FunctionCallbackInfo<Value>& args) {
1694
1684
args.GetReturnValue ().Set (effective_exports);
1695
1685
}
1696
1686
1697
- static void ProcessTitleGetter (Local<Name> property,
1698
- const PropertyCallbackInfo<Value>& info) {
1699
- char buffer[512 ];
1700
- uv_get_process_title (buffer, sizeof (buffer));
1701
- info.GetReturnValue ().Set (String::NewFromUtf8 (info.GetIsolate (), buffer,
1702
- v8::NewStringType::kNormal ).ToLocalChecked ());
1703
- }
1704
-
1705
-
1706
- static void ProcessTitleSetter (Local<Name> property,
1707
- Local<Value> value,
1708
- const PropertyCallbackInfo<void >& info) {
1709
- node::Utf8Value title (info.GetIsolate (), value);
1710
- TRACE_EVENT_METADATA1 (" __metadata" , " process_name" , " name" ,
1711
- TRACE_STR_COPY (*title));
1712
- uv_set_process_title (*title);
1713
- }
1714
-
1715
-
1716
- static void EnvGetter (Local<Name> property,
1717
- const PropertyCallbackInfo<Value>& info) {
1718
- Isolate* isolate = info.GetIsolate ();
1719
- if (property->IsSymbol ()) {
1720
- return info.GetReturnValue ().SetUndefined ();
1721
- }
1722
- Mutex::ScopedLock lock (environ_mutex);
1723
- #ifdef __POSIX__
1724
- node::Utf8Value key (isolate, property);
1725
- const char * val = getenv (*key);
1726
- if (val) {
1727
- return info.GetReturnValue ().Set (String::NewFromUtf8 (isolate, val,
1728
- v8::NewStringType::kNormal ).ToLocalChecked ());
1729
- }
1730
- #else // _WIN32
1731
- node::TwoByteValue key (isolate, property);
1732
- WCHAR buffer[32767 ]; // The maximum size allowed for environment variables.
1733
- SetLastError (ERROR_SUCCESS);
1734
- DWORD result = GetEnvironmentVariableW (reinterpret_cast <WCHAR*>(*key),
1735
- buffer,
1736
- arraysize (buffer));
1737
- // If result >= sizeof buffer the buffer was too small. That should never
1738
- // happen. If result == 0 and result != ERROR_SUCCESS the variable was not
1739
- // found.
1740
- if ((result > 0 || GetLastError () == ERROR_SUCCESS) &&
1741
- result < arraysize (buffer)) {
1742
- const uint16_t * two_byte_buffer = reinterpret_cast <const uint16_t *>(buffer);
1743
- Local<String> rc = String::NewFromTwoByte (isolate, two_byte_buffer);
1744
- return info.GetReturnValue ().Set (rc);
1745
- }
1746
- #endif
1747
- }
1748
-
1749
-
1750
- static void EnvSetter (Local<Name> property,
1751
- Local<Value> value,
1752
- const PropertyCallbackInfo<Value>& info) {
1753
- Environment* env = Environment::GetCurrent (info);
1754
- if (env->options ()->pending_deprecation && env->EmitProcessEnvWarning () &&
1755
- !value->IsString () && !value->IsNumber () && !value->IsBoolean ()) {
1756
- if (ProcessEmitDeprecationWarning (
1757
- env,
1758
- " Assigning any value other than a string, number, or boolean to a "
1759
- " process.env property is deprecated. Please make sure to convert the "
1760
- " value to a string before setting process.env with it." ,
1761
- " DEP0104" ).IsNothing ())
1762
- return ;
1763
- }
1764
-
1765
- Mutex::ScopedLock lock (environ_mutex);
1766
- #ifdef __POSIX__
1767
- node::Utf8Value key (info.GetIsolate (), property);
1768
- node::Utf8Value val (info.GetIsolate (), value);
1769
- setenv (*key, *val, 1 );
1770
- #else // _WIN32
1771
- node::TwoByteValue key (info.GetIsolate (), property);
1772
- node::TwoByteValue val (info.GetIsolate (), value);
1773
- WCHAR* key_ptr = reinterpret_cast <WCHAR*>(*key);
1774
- // Environment variables that start with '=' are read-only.
1775
- if (key_ptr[0 ] != L' =' ) {
1776
- SetEnvironmentVariableW (key_ptr, reinterpret_cast <WCHAR*>(*val));
1777
- }
1778
- #endif
1779
- // Whether it worked or not, always return value.
1780
- info.GetReturnValue ().Set (value);
1781
- }
1782
-
1783
-
1784
- static void EnvQuery (Local<Name> property,
1785
- const PropertyCallbackInfo<Integer>& info) {
1786
- Mutex::ScopedLock lock (environ_mutex);
1787
- int32_t rc = -1 ; // Not found unless proven otherwise.
1788
- if (property->IsString ()) {
1789
- #ifdef __POSIX__
1790
- node::Utf8Value key (info.GetIsolate (), property);
1791
- if (getenv (*key))
1792
- rc = 0 ;
1793
- #else // _WIN32
1794
- node::TwoByteValue key (info.GetIsolate (), property);
1795
- WCHAR* key_ptr = reinterpret_cast <WCHAR*>(*key);
1796
- SetLastError (ERROR_SUCCESS);
1797
- if (GetEnvironmentVariableW (key_ptr, nullptr , 0 ) > 0 ||
1798
- GetLastError () == ERROR_SUCCESS) {
1799
- rc = 0 ;
1800
- if (key_ptr[0 ] == L' =' ) {
1801
- // Environment variables that start with '=' are hidden and read-only.
1802
- rc = static_cast <int32_t >(v8::ReadOnly) |
1803
- static_cast <int32_t >(v8::DontDelete) |
1804
- static_cast <int32_t >(v8::DontEnum);
1805
- }
1806
- }
1807
- #endif
1808
- }
1809
- if (rc != -1 )
1810
- info.GetReturnValue ().Set (rc);
1811
- }
1812
-
1813
-
1814
- static void EnvDeleter (Local<Name> property,
1815
- const PropertyCallbackInfo<Boolean >& info) {
1816
- Mutex::ScopedLock lock (environ_mutex);
1817
- if (property->IsString ()) {
1818
- #ifdef __POSIX__
1819
- node::Utf8Value key (info.GetIsolate (), property);
1820
- unsetenv (*key);
1821
- #else
1822
- node::TwoByteValue key (info.GetIsolate (), property);
1823
- WCHAR* key_ptr = reinterpret_cast <WCHAR*>(*key);
1824
- SetEnvironmentVariableW (key_ptr, nullptr );
1825
- #endif
1826
- }
1827
-
1828
- // process.env never has non-configurable properties, so always
1829
- // return true like the tc39 delete operator.
1830
- info.GetReturnValue ().Set (true );
1831
- }
1832
-
1833
-
1834
- static void EnvEnumerator (const PropertyCallbackInfo<Array>& info) {
1835
- Environment* env = Environment::GetCurrent (info);
1836
- Isolate* isolate = env->isolate ();
1837
- Local<Context> ctx = env->context ();
1838
- Local<Function> fn = env->push_values_to_array_function ();
1839
- Local<Value> argv[NODE_PUSH_VAL_TO_ARRAY_MAX];
1840
- size_t idx = 0 ;
1841
-
1842
- Mutex::ScopedLock lock (environ_mutex);
1843
- #ifdef __POSIX__
1844
- int size = 0 ;
1845
- while (environ[size])
1846
- size++;
1847
-
1848
- Local<Array> envarr = Array::New (isolate);
1849
-
1850
- for (int i = 0 ; i < size; ++i) {
1851
- const char * var = environ[i];
1852
- const char * s = strchr (var, ' =' );
1853
- const int length = s ? s - var : strlen (var);
1854
- argv[idx] = String::NewFromUtf8 (isolate,
1855
- var,
1856
- v8::NewStringType::kNormal ,
1857
- length).ToLocalChecked ();
1858
- if (++idx >= arraysize (argv)) {
1859
- fn->Call (ctx, envarr, idx, argv).ToLocalChecked ();
1860
- idx = 0 ;
1861
- }
1862
- }
1863
- if (idx > 0 ) {
1864
- fn->Call (ctx, envarr, idx, argv).ToLocalChecked ();
1865
- }
1866
- #else // _WIN32
1867
- WCHAR* environment = GetEnvironmentStringsW ();
1868
- if (environment == nullptr )
1869
- return ; // This should not happen.
1870
- Local<Array> envarr = Array::New (isolate);
1871
- WCHAR* p = environment;
1872
- while (*p) {
1873
- WCHAR* s;
1874
- if (*p == L' =' ) {
1875
- // If the key starts with '=' it is a hidden environment variable.
1876
- p += wcslen (p) + 1 ;
1877
- continue ;
1878
- } else {
1879
- s = wcschr (p, L' =' );
1880
- }
1881
- if (!s) {
1882
- s = p + wcslen (p);
1883
- }
1884
- const uint16_t * two_byte_buffer = reinterpret_cast <const uint16_t *>(p);
1885
- const size_t two_byte_buffer_len = s - p;
1886
- argv[idx] = String::NewFromTwoByte (isolate,
1887
- two_byte_buffer,
1888
- String::kNormalString ,
1889
- two_byte_buffer_len);
1890
- if (++idx >= arraysize (argv)) {
1891
- fn->Call (ctx, envarr, idx, argv).ToLocalChecked ();
1892
- idx = 0 ;
1893
- }
1894
- p = s + wcslen (s) + 1 ;
1895
- }
1896
- if (idx > 0 ) {
1897
- fn->Call (ctx, envarr, idx, argv).ToLocalChecked ();
1898
- }
1899
- FreeEnvironmentStringsW (environment);
1900
- #endif
1901
-
1902
- info.GetReturnValue ().Set (envarr);
1903
- }
1904
-
1905
-
1906
- static void GetParentProcessId (Local<Name> property,
1907
- const PropertyCallbackInfo<Value>& info) {
1908
- info.GetReturnValue ().Set (Integer::New (info.GetIsolate (), uv_os_getppid ()));
1909
- }
1910
-
1911
-
1912
1687
static Local<Object> GetFeatures (Environment* env) {
1913
1688
EscapableHandleScope scope (env->isolate ());
1914
1689
0 commit comments