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

A possible bug about calling eval in strict mode #102

Closed
YaoHouyou opened this issue Sep 5, 2019 · 4 comments
Closed

A possible bug about calling eval in strict mode #102

YaoHouyou opened this issue Sep 5, 2019 · 4 comments
Labels
bug Something isn't working

Comments

@YaoHouyou
Copy link

Version: 3ed8340

Testcase:

var NISLFuzzingFunc = function() {
    "use strict";
    eval("var public = 1;");
};
NISLFuzzingFunc();

Command:

./build/bin/hermes -w testcase.js

Output:

Expected output:

Throw SyntaxError on Line 3

Description:

According to the ES standard, eval code is strict mode code if the call to eval is contained in strict mode code. In the testcase above, the eval code should be strict mode code, and the reserved word "public" cannot be used as a variable name in strict mode, so a SyntaxError should be thrown on Line 3. However, Hermes did not throw any exceptions when running the above testcase.
The reference of the ES standard is as follows:
http://www.ecma-international.org/ecma-262/6.0/index.html#sec-strict-mode-code

@ykabusalah
Copy link

Can I take this?

@tmikov
Copy link
Contributor

tmikov commented Sep 5, 2019

@YaoHouyou thank you for catching this! It does indeed look like a bug. BTW, please keep in mind that Hermes does not currently fully support local eval(), so for example it can't access local variables.

@tmikov tmikov added the bug Something isn't working label Sep 5, 2019
@tmikov
Copy link
Contributor

tmikov commented Sep 5, 2019

@ykabusalah we are happy to accept community contributions.

While conceptually simple, fixing this issue requires changes in several places in the compiler and the interpreter, so it may be challenging if you are not already familiar with the code base. Here is what we need to do: we need to add a new operand "strictMode" to the DirectEvalInst instruction, which we then have to pass as an additional parameter to evalInEnvironment().

If you like, feel free to give it a try.

mganandraj pushed a commit to mganandraj/hermes that referenced this issue Jun 22, 2022
- Disable Stats Timer (fixes facebook#92)
- Include revision as part of product version in addition to suffix (fixes facebook#91)
- Include license file in NuGet (fixes facebook#98)
- Add Source Link to linker (fixes facebook#102)

This is ported from the v0.11 branch. We bump the version up to 0.12 (even though no such version exists in upstream) to signal we're no longer compatible with 0.11 (and RN 0.68).
@fbmal7
Copy link
Contributor

fbmal7 commented Apr 6, 2023

Propagating function strictness to direct evals is now implemented in f6b56d3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants