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

Rewriting eval causes scoped variables to not be recognized #377

Open
onsetsu opened this issue Jul 5, 2019 · 0 comments
Open

Rewriting eval causes scoped variables to not be recognized #377

onsetsu opened this issue Jul 5, 2019 · 0 comments

Comments

@onsetsu
Copy link
Contributor

onsetsu commented Jul 5, 2019

Consider the following code as running example:

(() => {
  let x = 42;
  return eval('x')
})()

It evaluates and returns the value of the scoped variable x.

However, once we alter this example only slightly, x will not be in the scope of the evaluation:

(() => {
  let x = 42;
  return (void 0, eval)('x')
})()

Inserting this SequenceExpression causes the following error:

Error: x is not defined
Evaluating workspacejs:09f31940-1ac0-43c1-bce8-132469645c6c/lively-kernel.org/lively4/aexpr/unnamed_module_9dd25e73_9d6f_4e56_b07c_398481bb3c5f
Loading workspacejs:09f31940-1ac0-43c1-bce8-132469645c6c/lively-kernel.org/lively4/aexpr/unnamed_module_9dd25e73_9d6f_4e56_b07c_398481bb3c5f

Note, that we can still evaluate code not related to locally scoped variables:

(() => {
  let x = 42;
  return (void 0, eval)('window')
})()

Not only a SequenceExpression breaks scope lookup; same goes for assigning eval to a local variable:

(() => {
  let x = 42;
  let ev = self.eval
  return ev('x')
})()

My current assumption is that the concrete syntax (the CallExpression eval(code)) makes the local scope available in the evaluated code.

We may mitigate this issue related to Active Expressions by not rewriting a global assess to the eval function.

onsetsu added a commit that referenced this issue Jul 5, 2019
SQUASHED: AUTO-COMMIT-demos-meta.md,AUTO-COMMIT-src-client-reactive-babel-plugin-active-expression-rewriting-index.js,AUTO-COMMIT-src-client-reactive-test-active-expression-rewriting-html.spec.js,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant