Skip to content

Proxy get handler is used when evaluating the proxy #16483

Description

@kuanee
  • 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'

Activity

  1. changed the title [-]Proxy getter raises on evaluation of proxy[/-] [+]Proxy get handler is used when evaluating the proxy[/+] on Oct 25, 2017
  2. bnoordhuis commented on Oct 25, 2017

    @bnoordhuis
    Member

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

  3. vsemozhetbyt commented on Oct 25, 2017

    @vsemozhetbyt
    Contributor

    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'
  4. added
    replIssues and PRs related to the REPL subsystem.
    utilIssues and PRs related to the built-in util module.
    on Oct 25, 2017
  5. added a commit that references this issue on Oct 25, 2017
  6. bnoordhuis commented on Oct 25, 2017

    @bnoordhuis
    Member

    #16485 - possible solution.

  7. kuanee commented on Oct 25, 2017

    @kuanee
    Author

    yup, encountered this in repl. Thanks alot!

  8. added a commit that references this issue on Nov 7, 2017
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

    replIssues and PRs related to the REPL subsystem.utilIssues and PRs related to the built-in util module.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions