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