Skip to content

Commit b357323

Browse files
cpsievertjcheng5
authored andcommitted
Try evaluating code with parentheses before without parentheses, closes #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
1 parent 5b44e2a commit b357323

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

inst/NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
htmlwidgets 1.5.1.9000
2+
-------------------------------------------------------
3+
4+
* Fixed an issue with passing named function declarations to `JS()` and `onRender()` (introduced by v1.4). (#356)
5+
16
htmlwidgets 1.5.1
27
-------------------------------------------------------
38

inst/www/htmlwidgets.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,13 @@
249249
function tryEval(code) {
250250
var result = null;
251251
try {
252-
result = eval(code);
252+
result = eval("(" + code + ")");
253253
} catch(error) {
254254
if (!error instanceof SyntaxError) {
255255
throw error;
256256
}
257257
try {
258-
result = eval("(" + code + ")");
258+
result = eval(code);
259259
} catch(e) {
260260
if (e instanceof SyntaxError) {
261261
throw error;

0 commit comments

Comments
 (0)