mirror of
https://github.com/espruino/Espruino.git
synced 2025-12-08 19:06:15 +00:00
stop eval in a switch statement from confusing parsing (Fix #845)
This commit is contained in:
parent
009af6f945
commit
fc260ebd4d
@ -29,6 +29,7 @@
|
||||
Fix negative Date to string code (fix #854)
|
||||
Convert type warnings to exceptions (to provide stack traces for problems)
|
||||
Add uncaughtException event (fix #846)
|
||||
Stop eval in a switch statement from confusing parsing (Fix #845)
|
||||
|
||||
1v85 : Ensure HttpServerResponse.writeHead actually sends the header right away
|
||||
- enables WebSocket Server support from JS
|
||||
|
||||
@ -2499,7 +2499,8 @@ JsVar *jspEvaluateVar(JsVar *str, JsVar *scope, uint16_t lineNumberOffset) {
|
||||
jslSetLex(oldLex);
|
||||
|
||||
// restore state and execInfo
|
||||
oldExecInfo.execute = execInfo.execute; // JSP_RESTORE_EXECUTE has made this ok.
|
||||
JsExecFlags mask = EXEC_FOR_INIT|EXEC_IN_LOOP|EXEC_IN_SWITCH;
|
||||
oldExecInfo.execute = (oldExecInfo.execute & mask) | (execInfo.execute & ~mask);
|
||||
execInfo = oldExecInfo;
|
||||
|
||||
// It may have returned a reference, but we just want the value...
|
||||
|
||||
@ -77,8 +77,8 @@ JsVar *jspGetPrototypeOwner(JsVar *proto);
|
||||
typedef enum {
|
||||
EXEC_NO = 0,
|
||||
EXEC_YES = 1,
|
||||
EXEC_BREAK = 2,
|
||||
EXEC_CONTINUE = 4,
|
||||
EXEC_BREAK = 2, // Have we had a 'break' keyword (so should skip to end of loop and exit)
|
||||
EXEC_CONTINUE = 4, // Have we had a 'continue' keywrord (so should skip to end of loop and restart)
|
||||
|
||||
EXEC_INTERRUPTED = 8, // true if execution has been interrupted
|
||||
EXEC_EXCEPTION = 16, // we had an exception, so don't execute until we hit a try/catch block
|
||||
|
||||
16
tests/test_eval_switch.js
Normal file
16
tests/test_eval_switch.js
Normal file
@ -0,0 +1,16 @@
|
||||
// https://github.com/espruino/Espruino/issues/845
|
||||
|
||||
function test(){
|
||||
switch ("a"){
|
||||
case "a":
|
||||
eval(1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
test();
|
||||
result = 1;
|
||||
} catch (e) {
|
||||
result = 0;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user