Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access all declared variables in global namespace in globalThis #49619

Closed
ganeshkbhat opened this issue Sep 12, 2023 · 4 comments
Closed

Access all declared variables in global namespace in globalThis #49619

ganeshkbhat opened this issue Sep 12, 2023 · 4 comments
Labels
feature request Issues that request new features to be added to Node.js.

Comments

@ganeshkbhat
Copy link

ganeshkbhat commented Sep 12, 2023

What is the problem this feature will solve?

Access all declared variables (primitives or objects) in global namespace in globalThis. It will give access to all const's, var's, function's, let's declarations in one pre-defined, read-only globalThis.global definition. Currently, it is not accessible. Only global declarations of node.js environments are available.`

What is the feature you are proposing to solve the problem?

Access all declared variables (primitives or objects) in global namespace in globalThis. It will give access to all const's, var's, function's, let's declarations in one pre-defined, read-only globalThis.global definition.

What alternatives have you considered?

None. The only other alternative is to write a javascript file regex parser to get all declarations of const's, var's, function's, let's declarations

@ganeshkbhat
Copy link
Author

Would you consider this use case as well along with access to finding declarations? #47099 (comment)

@aduh95
Copy link
Contributor

aduh95 commented Sep 12, 2023

Can you give a specific example of code and what would be the expected behavior?

@bnoordhuis
Copy link
Member

Read up on the built-in inspector module, it probably does what you want. Some assembly required.

@bnoordhuis bnoordhuis closed this as not planned Won't fix, can't repro, duplicate, stale Sep 17, 2023
@ganeshkbhat
Copy link
Author

ganeshkbhat commented Dec 24, 2023

@bnoordhuis adding to this, it seems like/ behaviour none of the variable's, let's, const's, function's declaration made in the code already without using declarations like global.variable is not accessible from globals even as read-only which should not be the case. A presence of this or access to v8/v8.dev#717 or #45158 can lead to better AST or (read-only) access to variables.

I am seeing acorn: 8.10.0 here. What is this and what is the relevance here? Any way to access this in the newer versions of nodejs?

Microsoft Windows [Version 10.0.22631.2861]
(c) Microsoft Corporation. All rights reserved.

C:\Users\ganes>node --eval "console.log(require('process'))"
process {
  version: 'v21.1.0',
  versions: {
    node: '21.1.0',
    acorn: '8.10.0',
    ada: '2.7.2',
    ares: '1.20.1',
    base64: '0.5.0',
    brotli: '1.0.9',
    cjs_module_lexer: '1.2.2',
    cldr: '43.1',
    icu: '73.2',
    llhttp: '9.1.2',
    modules: '120',
    napi: '9',
    nghttp2: '1.57.0',
    nghttp3: '0.7.0',
    ngtcp2: '0.8.1',
    openssl: '3.0.10+quic',
    simdutf: '3.2.18',
    tz: '2023c',
    undici: '5.26.4',
    unicode: '15.0',
    uv: '1.46.0',
    uvwasi: '0.0.19',
    v8: '11.8.172.15-node.14',
    zlib: '1.2.13.1-motley'
  },
  arch: 'x64',
  platform: 'win32',
  release: {
    name: 'node',
    sourceUrl: 'https://nodejs.org/download/release/v21.1.0/node-v21.1.0.tar.gz',
    headersUrl: 'https://nodejs.org/download/release/v21.1.0/node-v21.1.0-headers.tar.gz',
    libUrl: 'https://nodejs.org/download/release/v21.1.0/win-x64/node.lib'
  },
  _rawDebug: [Function: _rawDebug],
  moduleLoadList: [
    'Internal Binding builtins',
    'Internal Binding errors',
    'NativeModule internal/assert',
    'Internal Binding util',
    'NativeModule internal/errors',
    'Internal Binding config',
    'Internal Binding timers',
    'Internal Binding async_wrap',
    'Internal Binding task_queue',
    'Internal Binding symbols',
    'NativeModule internal/async_hooks',
    'Internal Binding constants',
    'Internal Binding types',
    'Internal Binding options',
    'NativeModule internal/options',
    'NativeModule internal/util',
    'NativeModule internal/util/types',
    'NativeModule internal/validators',
    'NativeModule internal/linkedlist',
    'NativeModule internal/priority_queue',
    'Internal Binding icu',
    'NativeModule internal/util/inspect',
    'NativeModule internal/util/debuglog',
    'NativeModule internal/timers',
    'NativeModule events',
    'Internal Binding buffer',
    'Internal Binding string_decoder',
    'NativeModule internal/buffer',
    'NativeModule buffer',
    'Internal Binding messaging',
    'NativeModule internal/worker/js_transferable',
    'Internal Binding process_methods',
    'NativeModule internal/process/per_thread',
    'Internal Binding credentials',
    'NativeModule internal/process/promises',
    'NativeModule internal/fixed_queue',
    'NativeModule async_hooks',
    'NativeModule internal/process/task_queues',
    'NativeModule timers',
    'Internal Binding trace_events',
    'NativeModule internal/constants',
    'NativeModule path',
    'Internal Binding contextify',
    'NativeModule internal/vm',
    'NativeModule internal/process/execution',
    'NativeModule internal/process/warning',
    'NativeModule internal/querystring',
    'NativeModule querystring',
    'Internal Binding url',
    'NativeModule internal/url',
    'NativeModule internal/source_map/source_map_cache',
    'NativeModule internal/console/constructor',
    'NativeModule internal/console/global',
    'Internal Binding permission',
    'NativeModule internal/process/permission',
    'NativeModule internal/util/inspector',
    'Internal Binding inspector',
    'NativeModule util',
    'NativeModule internal/webidl',
    'Internal Binding performance',
    'NativeModule internal/perf/utils',
    'NativeModule internal/event_target',
    'Internal Binding blob',
    'Internal Binding mksnapshot',
    'NativeModule internal/v8/startup_snapshot',
    'NativeModule internal/process/signal',
    'Internal Binding fs',
    'Internal Binding encoding_binding',
    'NativeModule internal/encoding',
    'NativeModule internal/webstreams/util',
    'NativeModule internal/webstreams/queuingstrategies',
    'NativeModule internal/blob',
    'NativeModule internal/fs/utils',
    'NativeModule fs',
    'NativeModule internal/idna',
    'NativeModule url',
    'NativeModule internal/modules/helpers',
    'NativeModule internal/modules/package_json_reader',
    'Internal Binding module_wrap',
    'NativeModule internal/modules/cjs/loader',
    'NativeModule internal/process/pre_execution',
    'NativeModule internal/modules/esm/utils',
    'NativeModule internal/vm/module',
    'NativeModule internal/inspector_async_hook',
    'Internal Binding wasm_web_api',
    'Internal Binding worker',
    'NativeModule internal/modules/run_main',
    'NativeModule internal/net',
    'NativeModule internal/dns/utils',
    'NativeModule internal/modules/esm/loader',
    'NativeModule internal/source_map/source_map',
    'NativeModule module',
    'NativeModule internal/process/esm_loader',
    'NativeModule process',
    'NativeModule internal/abort_controller',
    'NativeModule internal/streams/utils',
    'NativeModule internal/streams/end-of-stream',
    'NativeModule internal/streams/destroy',
    'NativeModule internal/streams/legacy',
    'NativeModule internal/streams/add-abort-signal',
    ... 32 more items
  ],
  binding: [Function: binding],
  _linkedBinding: [Function: _linkedBinding],
  _events: [Object: null prototype] {
    newListener: [Function: startListeningIfSignal],
    removeListener: [Function: stopListeningIfSignal],
    warning: [Function: onWarning],
    SIGWINCH: [
      [Function: refreshStdoutOnSigWinch],
      [Function: refreshStderrOnSigWinch]
    ]
  },
  _eventsCount: 4,
  _maxListeners: undefined,
  domain: null,
  _exiting: [Getter/Setter],
  exitCode: [Getter/Setter],
  config: {
    target_defaults: {
      cflags: [],
      default_configuration: 'Release',
      defines: [Array],
      include_dirs: [],
      libraries: []
    },
    variables: {
      asan: 0,
      coverage: false,
      dcheck_always_on: 0,
      debug_nghttp2: false,
      debug_node: false,
      enable_lto: false,
      enable_pgo_generate: false,
      enable_pgo_use: false,
      error_on_warn: false,
      force_dynamic_crt: 0,
      host_arch: 'x64',
      icu_data_in: '..\\..\\deps\\icu-tmp\\icudt73l.dat',
      icu_endianness: 'l',
      icu_gyp_path: 'tools/icu/icu-generic.gyp',
      icu_path: 'deps/icu-small',
      icu_small: false,
      icu_ver_major: '73',
      is_debug: 0,
      libdir: 'lib',
      llvm_version: '0.0',
      napi_build_version: '9',
      nasm_version: '2.16',
      node_builtin_shareable_builtins: [Array],
      node_byteorder: 'little',
      node_debug_lib: false,
      node_enable_d8: false,
      node_enable_v8_vtunejit: false,
      node_fipsinstall: false,
      node_install_corepack: true,
      node_install_npm: true,
      node_library_files: [Array],
      node_module_version: 120,
      node_no_browser_globals: false,
      node_prefix: '\\usr\\local',
      node_release_urlbase: 'https://nodejs.org/download/release/',
      node_shared: false,
      node_shared_brotli: false,
      node_shared_cares: false,
      node_shared_http_parser: false,
      node_shared_libuv: false,
      node_shared_nghttp2: false,
      node_shared_nghttp3: false,
      node_shared_ngtcp2: false,
      node_shared_openssl: false,
      node_shared_zlib: false,
      node_tag: '',
      node_target_type: 'executable',
      node_use_bundled_v8: true,
      node_use_node_code_cache: true,
      node_use_node_snapshot: true,
      node_use_openssl: true,
      node_use_v8_platform: true,
      node_with_ltcg: true,
      node_without_node_options: false,
      node_write_snapshot_as_array_literals: true,
      openssl_is_fips: false,
      openssl_quic: true,
      ossfuzz: false,
      shlib_suffix: 'so.120',
      single_executable_application: true,
      target_arch: 'x64',
      v8_enable_31bit_smis_on_64bit_arch: 0,
      v8_enable_extensible_ro_snapshot: 0,
      v8_enable_gdbjit: 0,
      v8_enable_hugepage: 0,
      v8_enable_i18n_support: 1,
      v8_enable_inspector: 1,
      v8_enable_javascript_promise_hooks: 1,
      v8_enable_lite_mode: 0,
      v8_enable_object_print: 1,
      v8_enable_pointer_compression: 0,
      v8_enable_shared_ro_heap: 1,
      v8_enable_short_builtin_calls: 1,
      v8_enable_webassembly: 1,
      v8_no_strict_aliasing: 1,
      v8_optimized_debug: 1,
      v8_promise_internal_field_count: 1,
      v8_random_seed: 0,
      v8_trace_maps: 0,
      v8_use_siphash: 1,
      want_separate_host_toolset: 0
    }
  },
  dlopen: [Function: dlopen],
  uptime: [Function: uptime],
  _getActiveRequests: [Function: _getActiveRequests],
  _getActiveHandles: [Function: _getActiveHandles],
  getActiveResourcesInfo: [Function: getActiveResourcesInfo],
  reallyExit: [Function: reallyExit],
  _kill: [Function: _kill],
  cpuUsage: [Function: cpuUsage],
  resourceUsage: [Function: resourceUsage],
  memoryUsage: [Function: memoryUsage] { rss: [Function: rss] },
  constrainedMemory: [Function: constrainedMemory],
  kill: [Function: kill],
  exit: [Function: exit],
  hrtime: [Function: hrtime] { bigint: [Function: hrtimeBigInt] },
  openStdin: [Function (anonymous)],
  allowedNodeEnvironmentFlags: NodeEnvironmentFlagsSet(0) [Set] {
    '--icu-data-dir',
    '--title',
    '--use-largepages',
    '--trace-tls',
    '--no-trace-tls',
    '--trace-event-categories',
    '--trace-event-file-pattern',
    '--v8-pool-size',
    '--force-context-aware',
    '--no-force-context-aware',
    '--disallow-code-generation-from-strings',
    '--report-dir',
    '--trace-sync-io',
    '--no-trace-sync-io',
    '--zero-fill-buffers',
    '--no-zero-fill-buffers',
    '--diagnostic-dir',
    '--experimental-worker',
    '--disable-proto',
    '--node-snapshot',
    '--no-node-snapshot',
    '--debug-arraybuffer-allocations',
    '--no-debug-arraybuffer-allocations',
    '--abort-on-uncaught-exception',
    '--snapshot-blob',
    '--pending-deprecation',
    '--no-pending-deprecation',
    '--use-bundled-ca',
    '--no-use-bundled-ca',
    '--report-filename',
    '--report-compact',
    '--no-report-compact',
    '--report-on-fatalerror',
    '--no-report-on-fatalerror',
    '--perf-prof',
    '--report-signal',
    '--openssl-config',
    '--tls-cipher-list',
    '--use-openssl-ca',
    '--no-use-openssl-ca',
    '--node-memory-debug',
    '--enable-fips',
    '--no-enable-fips',
    '--force-fips',
    '--no-force-fips',
    '--secure-heap',
    '--secure-heap-min',
    '--openssl-legacy-provider',
    '--no-openssl-legacy-provider',
    '--openssl-shared-config',
    '--no-openssl-shared-config',
    '--trace-sigint',
    '--no-trace-sigint',
    '--track-heap-objects',
    '--no-track-heap-objects',
    '--experimental-detect-module',
    '--no-experimental-detect-module',
    '--warnings',
    '--no-warnings',
    '--experimental-repl-await',
    '--no-experimental-repl-await',
    '--experimental-json-modules',
    '--interpreted-frames-native-stack',
    '--perf-basic-prof-only-functions',
    '--max-old-space-size',
    '--allow-fs-write',
    '--max-semi-space-size',
    '--experimental-websocket',
    '--no-experimental-websocket',
    '--experimental-permission',
    '--no-experimental-permission',
    '--perf-basic-prof',
    '--perf-prof-unwinding-info',
    '--unhandled-rejections',
    '--experimental-network-imports',
    '--no-experimental-network-imports',
    '--stack-trace-limit',
    '--jitless',
    '--experimental-top-level-await',
    '--require',
    '--huge-max-old-generation-size',
    '--experimental-shadow-realm',
    '--no-experimental-shadow-realm',
    '--report-uncaught-exception',
    '--no-report-uncaught-exception',
    '--report-on-signal',
    '--no-report-on-signal',
    '--enable-etw-stack-walking',
    '--conditions',
    '--experimental-abortcontroller',
    '--experimental-policy',
    '--enable-source-maps',
    '--no-enable-source-maps',
    '--experimental-vm-modules',
    '--no-experimental-vm-modules',
    '--dns-result-order',
    '--network-family-autoselection',
    '--no-network-family-autoselection',
    '--insecure-http-parser',
    '--no-insecure-http-parser',
    ... 102 more items,
    [Symbol(internal properties)]: { array: [Array], set: [Set] }
  },
  assert: [Function: deprecated],
  features: {
    inspector: true,
    debug: false,
    uv: true,
    ipv6: true,
    tls_alpn: true,
    tls_sni: true,
    tls_ocsp: true,
    tls: true,
    cached_builtins: [Getter]
  },
  _fatalException: [Function (anonymous)],
  setUncaughtExceptionCaptureCallback: [Function: setUncaughtExceptionCaptureCallback],
  hasUncaughtExceptionCaptureCallback: [Function: hasUncaughtExceptionCaptureCallback],
  emitWarning: [Function: emitWarning],
  nextTick: [Function: nextTick],
  _tickCallback: [Function: runNextTicks],
  sourceMapsEnabled: [Getter],
  setSourceMapsEnabled: [Function: setSourceMapsEnabled],
  _debugProcess: [Function: _debugProcess],
  _debugEnd: [Function: _debugEnd],
  _startProfilerIdleNotifier: [Function (anonymous)],
  _stopProfilerIdleNotifier: [Function (anonymous)],
  stdout: [Getter],
  stdin: [Getter],
  stderr: [Getter],
  abort: [Function: abort],
  umask: [Function: wrappedUmask],
  chdir: [Function: wrappedChdir],
  cwd: [Function: wrappedCwd],
  env: {
    ALLUSERSPROFILE: 'C:\\ProgramData',
    APPDATA: 'C:\\Users\\ganes\\AppData\\Roaming',
    ChocolateyInstall: 'C:\\ProgramData\\chocolatey',
    ChocolateyLastPathUpdate: '133441465779742958',
    CommonProgramFiles: 'C:\\Program Files\\Common Files',
    'CommonProgramFiles(x86)': 'C:\\Program Files (x86)\\Common Files',
    CommonProgramW6432: 'C:\\Program Files\\Common Files',
    COMPUTERNAME: 'DESKTOP-549FNM1',
    ComSpec: 'C:\\Windows\\system32\\cmd.exe',
    DriverData: 'C:\\Windows\\System32\\Drivers\\DriverData',
    EFC_21400: '1',
    FPS_BROWSER_APP_PROFILE_STRING: 'Internet Explorer',
    FPS_BROWSER_USER_PROFILE_STRING: 'Default',
    HOMEDRIVE: 'C:',
    HOMEPATH: '\\Users\\ganes',
    LOCALAPPDATA: 'C:\\Users\\ganes\\AppData\\Local',
    LOGONSERVER: '\\\\DESKTOP-549FNM1',
    NUMBER_OF_PROCESSORS: '8',
    OneDrive: 'C:\\Users\\ganes\\OneDrive',
    OneDriveConsumer: 'C:\\Users\\ganes\\OneDrive',
    OS: 'Windows_NT',
    Path: 'C:\\Python312\\Scripts\\;C:\\Python312\\;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\OpenSSH\\;C:\\Program Files\\dotnet\\;C:\\Users\\ganes\\OneDrive\\Documents\\binaries\\git\\cmd;C:\\Users\\ganes\\OneDrive\\Documents\\binaries\\git\\mingw64\\bin;C:\\Users\\ganes\\OneDrive\\Documents\\binaries\\git\\usr\\bin;C:\\Users\\ganes\\OneDrive\\Documents\\binaries\\nodejs\\;C:\\ProgramData\\chocolatey\\bin;C:\\Users\\ganes\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\ganes\\AppData\\Roaming\\npm',
    PATHEXT: '.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY;.PYW',
    PROCESSOR_ARCHITECTURE: 'AMD64',
    PROCESSOR_IDENTIFIER: 'Intel64 Family 6 Model 142 Stepping 12, GenuineIntel',
    PROCESSOR_LEVEL: '6',
    PROCESSOR_REVISION: '8e0c',
    ProgramData: 'C:\\ProgramData',
    ProgramFiles: 'C:\\Program Files',
    'ProgramFiles(x86)': 'C:\\Program Files (x86)',
    ProgramW6432: 'C:\\Program Files',
    PROMPT: '$P$G',
    PSModulePath: 'C:\\Program Files\\WindowsPowerShell\\Modules;C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\Modules',
    PUBLIC: 'C:\\Users\\Public',
    SESSIONNAME: 'Console',
    SystemDrive: 'C:',
    SystemRoot: 'C:\\Windows',
    TEMP: 'C:\\Users\\ganes\\AppData\\Local\\Temp',
    TMP: 'C:\\Users\\ganes\\AppData\\Local\\Temp',
    USERDOMAIN: 'DESKTOP-549FNM1',
    USERDOMAIN_ROAMINGPROFILE: 'DESKTOP-549FNM1',
    USERNAME: 'ganes',
    USERPROFILE: 'C:\\Users\\ganes',
    windir: 'C:\\Windows',
    ZES_ENABLE_SYSMAN: '1'
  },
  title: `Command Prompt - node  --eval "console.log(require('process'))"`,
  argv: [
    'C:\\Users\\ganes\\OneDrive\\Documents\\binaries\\nodejs\\node.exe'
  ],
  execArgv: [ '--eval', "console.log(require('process'))" ],
  pid: 12420,
  ppid: 11424,
  execPath: 'C:\\Users\\ganes\\OneDrive\\Documents\\binaries\\nodejs\\node.exe',
  debugPort: 9229,
  argv0: 'node',
  _eval: "console.log(require('process'))",
  _preload_modules: [],
  report: [Getter],
  [Symbol(kCapture)]: false
}

C:\Users\ganes>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js.
Projects
None yet
Development

No branches or pull requests

3 participants