Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error rendering values as a result of a string function. #52

Merged
merged 2 commits into from
Oct 28, 2015

Conversation

briantani
Copy link

If we define as vm that assigns the result of a string function, the render method fails stating this error:

 TypeError: Cannot assign to read only property 'eval' of monica

This happens on references.js, in the getPropMethod. Line 273, when trying to set baseRef.eval property.

This test case highlights the issue.

Other information

node versions I see the issue present itself:
v4.2.1
v3.3.0

It does not seem to happen with node version 0.10.25. Maybe it's a bit more lax regarding this kind of attribution?

Maybe this pull request can help fix the code. I'll take a look at it as well, but I imagine you guys would know best.

…his test.

     TypeError: Cannot assign to read only property 'eval' of monica

It happens on references.js, in the getPropMethod. Line 273, when trying to set baseRef.eval property.
@briantani
Copy link
Author

The integration test running version v2.5.0 also reproduces the issue.

@briantani briantani closed this Oct 28, 2015
@briantani briantani reopened this Oct 28, 2015
…ejs enforces this by causing any attribution to fail.

By limiting the changes to eval only to object types we avoid the problem.
@shepherdwind
Copy link
Owner

Thank for you pr. That evel method is for rerender something, such as you can define the include method yourself.

baseRef.eval = function() {
return that.eval.apply(that, arguments);
};
if(typeof baseRef === 'object'){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If baseRef equal null, this will throw error too.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

If you want to be efficient, you might check for falsy values before calling typeof. That way, if baseRef is falsy a typeof evaluation is not necessary, as objects are always truthy.

if (baseRef && typeof baseRef === 'object') {

@shepherdwind
Copy link
Owner

👍

The other problem of null, I will fix is. You find a bug, and fix it very well, ths.

shepherdwind added a commit that referenced this pull request Oct 28, 2015
error rendering values as a result of a string function.
@shepherdwind shepherdwind merged commit 319c464 into shepherdwind:master Oct 28, 2015
@shepherdwind
Copy link
Owner

0.7.2 published

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants