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: Prevent REPL crash when tab-completed with Proxy objects by thefourtheye · Pull Request #2120 · nodejs/node

Conversation

@thefourtheye

@thefourtheye thefourtheye commented Jul 7, 2015

Copy link
Copy Markdown
Contributor

If the proxy objects don't have a valid hasOwnPropertyNames trap,
REPL crashes with a TypeError, as per the bug report
#2119

> var proxy = Proxy.create({ fix: function() { return {}; } });
undefined
> proxy.<tab>
TypeError: Proxy handler #<Object> has no 'getOwnPropertyNames' trap
    at Function.getOwnPropertyNames (native)
    at repl.js:644:40
    at REPLServer.defaultEval (repl.js:169:5)
    at bound (domain.js:254:14)
    at REPLServer.runBound [as eval] (domain.js:267:12)
    at REPLServer.complete (repl.js:639:14)
    at REPLServer.complete [as completer] (repl.js:207:10)
    at REPLServer.Interface._tabComplete (readline.js:377:8)
    at REPLServer.Interface._ttyWrite (readline.js:845:14)
    at ReadStream.onkeypress (readline.js:105:10)

This patch traps the error thrown and issues Error message.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@thefourtheye

thefourtheye commented Jul 7, 2015

Copy link
Copy Markdown
Contributor Author

I don't know how to write a test for this, as we need to

  1. enable --harmony-proxies
  2. do tab complete

I am not sure how to do both of them in the same test.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@evanlucas

evanlucas commented Jul 7, 2015

Copy link
Copy Markdown
Contributor

To force the flags, take a look at https://github.com/nodejs/io.js/blob/master/test/sequential/test-debug-args.js#L2

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rlidwka

rlidwka commented Jul 7, 2015

Copy link
Copy Markdown
Contributor

Can something else except proxy objects cause TypeError? That error check seems a bit too broad.

Also, I'm not sure adding an error message is useful. Maybe just silencing that particular error would be better.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thefourtheye

thefourtheye commented Jul 7, 2015

Copy link
Copy Markdown
Contributor Author

@evanlucas I tried that now and it doesn't work. This is the patch which I tried,

diff --git a/test/parallel/test-repl-tab-complete.js b/test/parallel/test-repl-tab-complete.js
index 1bf0c70..c560a3f 100644
--- a/test/parallel/test-repl-tab-complete.js
+++ b/test/parallel/test-repl-tab-complete.js
@@ -1,4 +1,6 @@
 'use strict';
+// Flags: --harmony-proxies
+
 var common = require('../common');
 var assert = require('assert');
 var util = require('util');
@@ -242,3 +244,14 @@ testMe.complete('cus', function(error, data) {
   completionCount++;
   assert.deepEqual(data, [['custom'], 'cus']);
 });
+
+// Make sure tab completion doesn't crash REPL with proxy objects
+putIn.run(['.clear']);
+
+putIn.run([
+  'var proxy = Proxy.create({});'
+]);
+
+testMe.complete('proxy.', function(error, data) {
+  console.error(arguments);
+});

It still throws a ReferenceError for Proxy. Is there anything else I need to include?

@rlidwka We can tighten the error checking, but silencing it will not give a hint to the user. Will that be okay?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@evanlucas

evanlucas commented Jul 7, 2015

Copy link
Copy Markdown
Contributor

Did you still get the ReferenceError running it with python tools/test.py?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mscdex mscdex added the repl Issues and PRs related to the REPL subsystem. label Jul 7, 2015
@thefourtheye

thefourtheye commented Jul 7, 2015

Copy link
Copy Markdown
Contributor Author

@evanlucas Awesome, it works :-) Thanks for the help. I removed the error check as suggested by @rlidwka now.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thefourtheye
thefourtheye force-pushed the fix-repl-proxy-completion branch from 46d7896 to df87261 Compare July 7, 2015 13:05
cjihrig
cjihrig reviewed Jul 7, 2015
View reviewed changes
Comment thread test/parallel/test-repl-tab-complete.js Outdated

@cjihrig cjihrig Jul 7, 2015

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use either the referenceErrors or completionCount variable here (see the rest of the test). This test is known to fail silently.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@thefourtheye thefourtheye Jul 7, 2015

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cjihrig Oh, why not common.mustCall then? That should work here, right? I think that would make the tests better, without explicitly counting.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@cjihrig cjihrig Jul 7, 2015

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should work for the tests using completionCount.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@thefourtheye thefourtheye Jul 7, 2015

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cjihrig Can you PTAL at #2122? I PRed that idea.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@cjihrig

cjihrig commented Jul 7, 2015

Copy link
Copy Markdown
Contributor

This can no longer be merged.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cjihrig

cjihrig commented Jul 7, 2015

Copy link
Copy Markdown
Contributor

Not a huge fan of just dropping errors, but it's also just REPL tab completion. LGTM

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thefourtheye
thefourtheye force-pushed the fix-repl-proxy-completion branch 3 times, most recently from b77a4c9 to c598b9a Compare July 7, 2015 16:43
@thefourtheye
repl: Prevent REPL crash when tab-completed with Proxy objects
fc1ae90
If the proxy objects don't have a valid `hasOwnPropertyNames` trap,
REPL crashes with a `TypeError`, as per the bug report
nodejs#2119

    > var proxy = Proxy.create({ fix: function() { return {}; } });
    undefined
    > proxy.<tab>
    TypeError: Proxy handler #<Object> has no 'getOwnPropertyNames' trap
        at Function.getOwnPropertyNames (native)
        at repl.js:644:40
        at REPLServer.defaultEval (repl.js:169:5)
        at bound (domain.js:254:14)
        at REPLServer.runBound [as eval] (domain.js:267:12)
        at REPLServer.complete (repl.js:639:14)
        at REPLServer.complete [as completer] (repl.js:207:10)
        at REPLServer.Interface._tabComplete (readline.js:377:8)
        at REPLServer.Interface._ttyWrite (readline.js:845:14)
        at ReadStream.onkeypress (readline.js:105:10)

This patch traps the error thrown and suppresses it.
@thefourtheye
thefourtheye force-pushed the fix-repl-proxy-completion branch from c598b9a to fc1ae90 Compare July 7, 2015 17:02
@thefourtheye

thefourtheye commented Jul 7, 2015

Copy link
Copy Markdown
Contributor Author

@cjihrig Thanks for reviewing and notifying about the merge conflict :-)

I rebased and squashed the commits.

@rlidwka @evanlucas PTAL :-)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thefourtheye thefourtheye changed the title repl: throw error when tab-completed with Proxy objects repl: Prevent REPL crash when tab-completed with Proxy objects Jul 7, 2015
@evanlucas

evanlucas commented Jul 10, 2015

Copy link
Copy Markdown
Contributor

CI: https://jenkins-iojs.nodesource.com/job/iojs+any-pr+multi/139/

LGTM if CI is happy

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

evanlucas pushed a commit that referenced this pull request Jul 10, 2015
@thefourtheye @evanlucas
repl: Prevent crash when tab-completed with Proxy
59f6b5d
If the proxy objects don't have a valid `hasOwnPropertyNames` trap,
REPL crashes with a `TypeError`, as per the bug report
#2119

    > var proxy = Proxy.create({ fix: function() { return {}; } });
    undefined
    > proxy.<tab>
    TypeError: Proxy handler #<Object> has no 'getOwnPropertyNames' trap
        at Function.getOwnPropertyNames (native)
        at repl.js:644:40
        at REPLServer.defaultEval (repl.js:169:5)
        at bound (domain.js:254:14)
        at REPLServer.runBound [as eval] (domain.js:267:12)
        at REPLServer.complete (repl.js:639:14)
        at REPLServer.complete [as completer] (repl.js:207:10)
        at REPLServer.Interface._tabComplete (readline.js:377:8)
        at REPLServer.Interface._ttyWrite (readline.js:845:14)
        at ReadStream.onkeypress (readline.js:105:10)

This patch traps the error thrown and suppresses it.

PR-URL: #2120
Fixes: #2119
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
@evanlucas

evanlucas commented Jul 10, 2015

Copy link
Copy Markdown
Contributor

Landed in 59f6b5d with a slightly modified commit message to conform to the collaborator guidelines. Thanks @thefourtheye!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@evanlucas evanlucas closed this Jul 10, 2015
@thefourtheye
thefourtheye deleted the fix-repl-proxy-completion branch July 10, 2015 13:02
@thefourtheye

thefourtheye commented Jul 10, 2015

Copy link
Copy Markdown
Contributor Author

@evanlucas Thanks :-) Can we close the actual bug report now itself or we ll wait for the fix to be released?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@evanlucas

evanlucas commented Jul 10, 2015

Copy link
Copy Markdown
Contributor

Good call. I forgot about that. Done

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thefourtheye thefourtheye mentioned this pull request Jul 16, 2015
Release Proposal: v2.4.0 #2189
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

repl Issues and PRs related to the REPL subsystem.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@thefourtheye @evanlucas @rlidwka @cjihrig @mscdex
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.