Skip to content

Commit

Permalink
Try evaluating code with parentheses before without parentheses, closes
Browse files Browse the repository at this point in the history
#356. (#357)

The problem with evaluating without parentheses first is that named function declarations are valid expressions that return undefined (whereas evaluating with parentheses returns the function, as expected).

It's true there may be weird corner-cases where switching this order leads to something else that's undesirable, but we've been operating with the 'with parentheses' model for so long that switching the ordering now will minimize backward-compatibility issues
  • Loading branch information
cpsievert authored and jcheng5 committed Nov 8, 2019
1 parent 5b44e2a commit b357323
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions inst/NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
htmlwidgets 1.5.1.9000
-------------------------------------------------------

* Fixed an issue with passing named function declarations to `JS()` and `onRender()` (introduced by v1.4). (#356)

htmlwidgets 1.5.1
-------------------------------------------------------

Expand Down
4 changes: 2 additions & 2 deletions inst/www/htmlwidgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,13 @@
function tryEval(code) {
var result = null;
try {
result = eval(code);
result = eval("(" + code + ")");
} catch(error) {
if (!error instanceof SyntaxError) {
throw error;
}
try {
result = eval("(" + code + ")");
result = eval(code);
} catch(e) {
if (e instanceof SyntaxError) {
throw error;
Expand Down

0 comments on commit b357323

Please sign in to comment.