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

Show Runtime Values vs. defineProperty on globals #578

Open
oculus42 opened this issue Sep 11, 2023 · 1 comment
Open

Show Runtime Values vs. defineProperty on globals #578

oculus42 opened this issue Sep 11, 2023 · 1 comment

Comments

@oculus42
Copy link

oculus42 commented Sep 11, 2023

Hello! This is very minor and is only an issue with Show Runtime Values - Experimental checked, but I thought it would be worth reporting, mostly in case others come across it.

The conditions I've encountered may not be everything, but are fairly specific:

  • Show Runtime Values - Experimental is checked.
  • Object.defineProperty modifies a global value (e.g. Array.prototype)
  • defineProperty uses a getter, setter, or explicitly sets writable: false.
  • Any valid syntax follows the defineProperty call, even if it would throw an error.

When using defineProperty on a global like Array.prototype I encounter TypeError: Cannot redefine property: and execution stops, but only if there is code following the defineProperty call:

// Code before executes as expected and displays output
a = 2;

Object.defineProperty(Array.prototype, 'not', {
  get() { return false; },
});

// TypeError: Cannot redefine property: not
//  happens and execution stops if any code is after define
//  with valid syntax, even if it would throw an error
b;

The error does not happen with a local variable:

const a = { is: true };
// No error when defineProperty is on a local variable
Object.defineProperty(a, 'not', {
  get() { return !this.is; },
});

a.is; // true
a.not; // false

And an image demonstrating the error for completeness:
image

I'm not sure if this is a worth further research as it works properly when you turn off Show Runtime Values.

Thank you so much for making this amazing tool. I love it and regularly recommend it to others.

@lukehaas
Copy link
Owner

lukehaas commented Apr 5, 2024

@oculus42 this seems to be working ok now in the latest version of RunJS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants