GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — REPL crashes after let process; · Issue #6802 · nodejs/node

REPL crashes after let process; #6802

New issue
Copy link
New issue
Copy link
Closed
Closed
REPL crashes after let process;#6802
Copy link
Labels
confirmed-bugIssues and PRs for confirmed bugs.replIssues and PRs related to the REPL subsystem.

Description

@mik-jozef
mik-jozef
opened on May 17, 2016
Issue body actions
  • Version: v6.0.0
  • Platform: Windows 10 64bit
  • Subsystem: REPL

Steps to replicate:

  1. Open REPL
  2. Type "let process;"

Node crashes instead of displaying something like TypeError: Identifier 'process' has already been declared.

Reacted by Daijiro Wachi

Activity

Next
  1. addaleax
    added
    child_processIssues and PRs related to the child_process subsystem.
    replIssues and PRs related to the REPL subsystem.
    and removed
    child_processIssues and PRs related to the child_process subsystem.
    on May 17, 2016
  2. bnoordhuis commented on May 17, 2016

    @bnoordhuis
    bnoordhuis
    on May 17, 2016
    Member
    More actions

    let process is basically equivalent to process = undefined because it runs in the top-level (i.e., global) scope.

    The REPL (and node in general) will let you do that but it won't end well. let Object or let Array have the same issue. I don't know if I'd say this is an actual bug, just mildly unexpected behavior.

  3. mik-jozef commented on May 17, 2016

    @mik-jozef
    mik-jozef
    on May 17, 2016
    Author
    More actions

    But why crash instead of displaying an error as if I typed "let x" two times?

  4. Fishrock123 commented on May 17, 2016

    @Fishrock123
    Fishrock123
    on May 17, 2016
    Contributor
    More actions

    Interesting. var process; doesn't crash. Here's the stack:

    > var process
    undefined
    > let process
    undefined
    domain.js:99
            process._emittingTopLevelDomainError = false;
                                                 ^
    
    TypeError: Cannot set property '_emittingTopLevelDomainError' of undefined
        at Domain.errorHandler [as _errorHandler] (domain.js:99:46)
        at process._fatalException (node.js:265:33)
    
  5. jasnell commented on May 17, 2016

    @jasnell
    jasnell
    on May 17, 2016
    Member
    More actions

    More interesting is that var process; does not actually redefine process

    > var process;
    undefined
    > process;
    { process object output }
    

    As @bnoordhuis indicates, I don't think this is an actual bug but it is rather odd.

  6. Fishrock123 commented on May 17, 2016

    @Fishrock123
    Fishrock123
    on May 17, 2016
    Contributor
    More actions

    cc @nodejs/v8 probably

  7. Fishrock123
    added
    v8 engineIssues and PRs related to the V8 dependency.
    on May 17, 2016
  8. bnoordhuis commented on May 17, 2016

    @bnoordhuis
    bnoordhuis
    on May 17, 2016
    Member
    More actions

    More interesting is that var process; does not actually redefine process

    That's consistent with var semantics, it reuses the existing 'slot' if there is one.

    The undefined return value that the REPL prints is because var process; is a statement that doesn't produce a value.

  9. addaleax commented on May 17, 2016

    @addaleax
    addaleax
    on May 17, 2016
    Member
    More actions

    Confirmed that this would be fixed by #5703 while going through the open PRs.

  10. lance commented on May 18, 2016

    @lance
    lance
    on May 18, 2016
    Member
    More actions

    This does not seem like a bug to me.

    > let process;

    This creates a process variable in the current lexical environment, shadowing the global process object. It's uninitialized, therefore undefined, but node depends on the process object, and now it's undefined. There is no way to recover from this.

    @mik-jozef what would you suggest, display an error and then what? There's no way to continue with process now undefined. You could isolate this assignment in its own lexical environment, similar to this below, but there is no way at the top level to set process to something else and expect it to not be broken.

    > function foo() {
    ... let process;
    ... console.log(process.nextTick);
    ... }
    undefined
    > console.log(process.nextTick);
    [Function: nextTick]
    undefined
    > foo();
    TypeError: Cannot read property 'nextTick' of undefined
        at foo (repl:3:20)
        at repl:1:1
        at REPLServer.defaultEval (repl.js:272:27)
        at bound (domain.js:280:14)
        at REPLServer.runBound [as eval] (domain.js:293:12)
        at REPLServer.<anonymous> (repl.js:441:10)
        at emitOne (events.js:101:20)
        at REPLServer.emit (events.js:188:7)
        at REPLServer.Interface._onLine (readline.js:219:10)
        at REPLServer.Interface._line (readline.js:561:8)
    >  console.log(process.nextTick)
    [Function: nextTick]
    undefined
    >
    

    As for var process, as @bnoordhuis said, this is how var works. From the ES2015 spec, "Within the scope of any VariableEnvironment a common BindingIdentifier may appear in more than one VariableDeclaration but those declarations collective define only one variable." So just typing var process doesn't do anything at all, really. Try typing var process = undefined and you'll find that the behavior is the same as that of let because now that common variable name has been redefined.

    @addaleax I'm not sure how #5703 would affect this. In fact, all of the examples I've shown in this comment were run on that branch. Can you help me understand what would be different here?

  11. cjihrig commented on May 18, 2016

    @cjihrig
    cjihrig
    on May 18, 2016
    Contributor
    More actions

    By not using the global context, you can define a variable named process without overwriting Node's global.

  12. lance commented on May 18, 2016

    @lance
    lance
    on May 18, 2016
    Member
    More actions

    @cjihrig ok that makes sense, of course. I'll take a look at the PR and write a test.

  13. bnoordhuis
    removed
    v8 engineIssues and PRs related to the V8 dependency.
    on Jun 27, 2016
  14. 11 remaining items

  15. TimothyGu commented on Jul 17, 2017

    @TimothyGu
    TimothyGu
    on Jul 17, 2017
    Member
    More actions

    @benjamingr Huh? Is that related to this issue?

  16. benjamingr commented on Jul 17, 2017

    @benjamingr
    benjamingr
    on Jul 17, 2017
    Member
    More actions

    @TimothyGu sorry - wrong PR :D

    Reacted by Timothy Gu and Gibson Fahnestock
  17. benjamingr commented on Jul 19, 2017

    @benjamingr
    benjamingr
    on Jul 19, 2017
    Member
    More actions

    I guess the only argument against doing that is that there might be a legitimate reason for someone to modify/overwrite the process object. IDK if there is one.

    The possibility kind of sways me from warning to fix this. Just like we don't guard against people modifying process or anything else inside Node - I don't think the REPL should be special - and while ES scoping rules are quirky here they are ES scoping rules.

  18. gibfahn commented on Jul 20, 2017

    @gibfahn
    gibfahn
    on Jul 20, 2017
    Member
    More actions

    Maybe the repl could just print a warning if you change any of the built-in objects, e.g.:

    Doing this overwrites a global object, which can destroy this REPL instance. I hope you know what you're doing!

    We could also in theory have an Are you sure you want to do this? Enter/Ctrl+C prompt, but I think I'd be -1 on that, it'd be a pain, and reopening the repl isn't exactly a big problem.

    I'm assuming the issue is people not realising that process is a built-in object, so printing a warning should be enough.

  19. lance commented on Nov 21, 2017

    @lance
    lance
    on Nov 21, 2017
    Member
    More actions

    My instinct is to consider this not a bug and leave it as-is. There is no way to recover if the user sets or undefines the global process object. It would be possible check for this assignment in the REPL code and recover somewhat gracefully by printing a warning, as you suggest @gibfahn. Naively, that would mean adding code to the REPL to parse each line looking for the assignment. But why should code in the REPL be treated differently than in a standard runtime? I don't think it's a good idea.

    The only reasonable approach, IMO is to define global.process as a const at startup. The process object is created here and set in the environment through a series of macros. Unwinding all of that and treating process differently is perhaps beyond my pay grade at the moment. :)

    I recommend closing this issue.

  20. addaleax
    added a commit that references this issue on Nov 21, 2017

    lib: add `process` to internal module wrapper

    a5511e4
  21. addaleax commented on Nov 21, 2017

    @addaleax
    addaleax
    on Nov 21, 2017
    Member
    More actions

    @lance Thanks for commenting here – I think this might actually be easily fixed now that we have a different module wrapper for built-ins? PR to try it out @ #17198

    Reacted by Lance Ball and Jozef Mikušinec
  22. addaleax
    closed this as completedin e8a26e7on Nov 28, 2017
  23. apapirovski
    added a commit that references this issue on Feb 26, 2018

    lib: add `process` to internal module wrapper

    af42919
  24. addaleax
    added 2 commits that reference this issue on Feb 26, 2018

    lib: add `process` to internal module wrapper

    337d529

    lib: add `process` to internal module wrapper

    c7b66d0
  25. MylesBorins
    added a commit that references this issue on Feb 26, 2018

    lib: add `process` to internal module wrapper

    738b0a1
  26. sjarmak
    added a commit that references this issue on Jul 27, 2026

    lib: add `process` to internal module wrapper

    e8a26e7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues and PRs for confirmed bugs.replIssues and PRs related to the REPL subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.