shannonmoeller / handlebars-layouts

Handlebars helpers which implement layout blocks similar to Jinja, Nunjucks (Swig), Pug (Jade), and Twig.

Home Page:http://npm.im/handlebars-layouts

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError: arg.hasOwnProperty is not a function

joonas-lahtinen opened this issue · comments

When used together with Express.js and when passing res.locals as the template context which uses handlebars-layouts, the following error happens:

TypeError: arg.hasOwnProperty is not a function
    at mixin ([snip]/node_modules/handlebars-layouts/index.js:72:12)

As can be seen from the code, hasOwnProperty is expected to be a function in the objects:

if (arg.hasOwnProperty(key)) {
    target[key] = arg[key];
}

But this is not the case with Express.js:

// express/lib/middleware/init.js
res.locals = res.locals || Object.create(null);

Where the prototype of the res.locals is not Object.

What is the value of arg at that point?

Value is res.locals from Express.js, I sent a PR for the change required and added tests for it.