Skip to content

Commit

Permalink
Fix issue knockout#71 (minified version behaves differently from unmi…
Browse files Browse the repository at this point in the history
…nified version)
  • Loading branch information
SteveSanderson committed Apr 27, 2011
1 parent 50ef0bd commit 666c396
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
6 changes: 5 additions & 1 deletion build/output/knockout-latest.debug.js
Expand Up @@ -161,9 +161,13 @@ ko.utils = new (function () {
}, },


evalWithinScope: function (expression, scope) { evalWithinScope: function (expression, scope) {
// Always do the evaling within a "new Function" to block access to parent scope
if (scope === undefined) if (scope === undefined)
return (new Function("return " + expression))(); return (new Function("return " + expression))();
with (scope) { return eval("(" + expression + ")"); }
// Ensure "expression" is flattened into a source code string *before* it runs, otherwise
// the variable name "expression" itself will clash with a subproperty called "expression"
return (new Function("sc", "with(sc) { return (" + expression + ") }"))(scope);
}, },


domNodeIsContainedBy: function (node, containedByNode) { domNodeIsContainedBy: function (node, containedByNode) {
Expand Down
18 changes: 9 additions & 9 deletions build/output/knockout-latest.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion src/utils.js
Expand Up @@ -145,9 +145,13 @@ ko.utils = new (function () {
}, },


evalWithinScope: function (expression, scope) { evalWithinScope: function (expression, scope) {
// Always do the evaling within a "new Function" to block access to parent scope
if (scope === undefined) if (scope === undefined)
return (new Function("return " + expression))(); return (new Function("return " + expression))();
with (scope) { return eval("(" + expression + ")"); }
// Ensure "expression" is flattened into a source code string *before* it runs, otherwise
// the variable name "expression" itself will clash with a subproperty called "expression"
return (new Function("sc", "with(sc) { return (" + expression + ") }"))(scope);
}, },


domNodeIsContainedBy: function (node, containedByNode) { domNodeIsContainedBy: function (node, containedByNode) {
Expand Down

0 comments on commit 666c396

Please sign in to comment.