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

Proxy get handler is used when evaluating the proxy #16483

Closed
kuanee opened this issue Oct 25, 2017 · 4 comments
Closed

Proxy get handler is used when evaluating the proxy #16483

kuanee opened this issue Oct 25, 2017 · 4 comments
Labels
repl Issues and PRs related to the REPL subsystem. util Issues and PRs related to the built-in util module.

Comments

@kuanee
Copy link

kuanee commented Oct 25, 2017

  • Version: v8.7.0

The defined 'not ready' error is raised when evaluating the proxy. This error does not occur in chrome or firefox consoles.

const o1 = {
      ready: false
    };

setTimeout(() => {
  o1.ready = true;
}, 1000000000);

const handler = {
  get(target, propKey, receiver) {
    if (target.ready == false) {
      throw new Error('not ready');
    } else {
      return 'ready'
    }
  }
};

const proxy = new Proxy(o1, handler);

proxy; // raises 'not ready'
@kuanee kuanee changed the title Proxy getter raises on evaluation of proxy Proxy get handler is used when evaluating the proxy Oct 25, 2017
@bnoordhuis
Copy link
Member

I think missing from your description is that it happens in the REPL?

@vsemozhetbyt
Copy link
Contributor

vsemozhetbyt commented Oct 25, 2017

There are some properties that are requested during REPL evaluation of an Object. You can filter them out:

'use strict';

const util = require('util');

const o1 = {
  ready: false,
};

setTimeout(() => {
  o1.ready = true;
}, 1000000000);

const handler = {
  get(target, propKey, receiver) {
    const filter = ['inspect', util.inspect.custom, Symbol.iterator];
    if (!filter.includes(propKey)) {
      if (target.ready === false) {
        throw new Error('not ready');
      } else {
        return 'ready';
      }
    }
  },
};

const proxy = new Proxy(o1, handler);

proxy; // does not raise 'not ready'

@vsemozhetbyt vsemozhetbyt added repl Issues and PRs related to the REPL subsystem. util Issues and PRs related to the built-in util module. labels Oct 25, 2017
bnoordhuis added a commit to bnoordhuis/io.js that referenced this issue Oct 25, 2017
@bnoordhuis
Copy link
Member

#16485 - possible solution.

@kuanee
Copy link
Author

kuanee commented Oct 25, 2017

yup, encountered this in repl. Thanks alot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
repl Issues and PRs related to the REPL subsystem. util Issues and PRs related to the built-in util module.
Projects
None yet
Development

No branches or pull requests

3 participants