From e801e842a7acbae9b0b8022b1c54a6960a279b62 Mon Sep 17 00:00:00 2001 From: Phillip Johnsen Date: Fri, 15 May 2015 23:09:15 +0200 Subject: [PATCH] Bugfix for view context cache picking methods from Object.prototype instead of the view. Fixes #442 --- mustache.js | 2 +- test/_files/avoids_obj_prototype_in_view_cache.js | 4 ++++ test/_files/avoids_obj_prototype_in_view_cache.mustache | 1 + test/_files/avoids_obj_prototype_in_view_cache.txt | 1 + 4 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 test/_files/avoids_obj_prototype_in_view_cache.js create mode 100644 test/_files/avoids_obj_prototype_in_view_cache.mustache create mode 100644 test/_files/avoids_obj_prototype_in_view_cache.txt diff --git a/mustache.js b/mustache.js index 602d7b3..67c222d 100644 --- a/mustache.js +++ b/mustache.js @@ -356,7 +356,7 @@ var cache = this.cache; var value; - if (name in cache) { + if (cache.hasOwnProperty(name)) { value = cache[name]; } else { var context = this, names, index, lookupHit = false; diff --git a/test/_files/avoids_obj_prototype_in_view_cache.js b/test/_files/avoids_obj_prototype_in_view_cache.js new file mode 100644 index 0000000..2ab58cd --- /dev/null +++ b/test/_files/avoids_obj_prototype_in_view_cache.js @@ -0,0 +1,4 @@ +({ + valueOf: 'Avoids methods', + watch: 'in Object.prototype' +}) diff --git a/test/_files/avoids_obj_prototype_in_view_cache.mustache b/test/_files/avoids_obj_prototype_in_view_cache.mustache new file mode 100644 index 0000000..f6e469b --- /dev/null +++ b/test/_files/avoids_obj_prototype_in_view_cache.mustache @@ -0,0 +1 @@ +{{valueOf}} {{watch}} \ No newline at end of file diff --git a/test/_files/avoids_obj_prototype_in_view_cache.txt b/test/_files/avoids_obj_prototype_in_view_cache.txt new file mode 100644 index 0000000..2621d99 --- /dev/null +++ b/test/_files/avoids_obj_prototype_in_view_cache.txt @@ -0,0 +1 @@ +Avoids methods in Object.prototype \ No newline at end of file