shushanxingzhe / json-template

Automatically exported from code.google.com/p/json-template
0 stars 0 forks source link

The JS version is not reentrant -- thus impossible to have templates include other templates #30

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
The JS version is not reentrant -- thus impossible to have templates
include other templates. Things like the stack, which while hidden in a
module pattern, is still a global to the functions.

Original issue reported on code.google.com by sroussey on 15 Sep 2009 at 2:15

GoogleCodeExporter commented 8 years ago
Silly me, it is just global leakage..

_Execute should have:

var statement;

_DoSubstitute should have :

var i;

They were using globals and effecting the rendering (infinite loop).

Original comment by sroussey on 15 Sep 2009 at 3:16

GoogleCodeExporter commented 8 years ago
Nice catch, but what scope are 'statement' and 'i' being read from?  I don't 
see it.
 What environment are you running in, a browser?

It is definitely intended to be fully reentrant.

Original comment by gtempacc...@yahoo.com on 15 Sep 2009 at 3:23

GoogleCodeExporter commented 8 years ago
In a browser... and the statement and i are being read in those same 
functions... 
since I have templates including other templates, the same functions get 
called. So 
template A includes B which changes the i and statement such that when it gets 
back 
to A, it thinks it hasn't included B yet and starts all over again.

Original comment by sroussey on 15 Sep 2009 at 4:53

GoogleCodeExporter commented 8 years ago
OK, so in JavaScript, if you don't use "var", then the variables automatically 
become
globals?  Weird.

Do you have a snippet that can reproduce it?  I can certainly just add "var" to 
those
statements, but I would like a regression test too.  That can go here:

http://code.google.com/p/json-template/source/browse/trunk/javascript/browser_te
sts.py

The browser_tests.py file generates an HTML file (via jsontemplate_test.py
--browser-test-out-dir) that can be run in a browser.

Original comment by gtempacc...@yahoo.com on 15 Sep 2009 at 5:05

GoogleCodeExporter commented 8 years ago
var is the way to stop JS from moving up through all scopes to find the 
variable 
(thus is why and how closures work). A test would not be possible unless I 
added 
include functionality in the test...

Original comment by sroussey on 15 Sep 2009 at 5:12

GoogleCodeExporter commented 8 years ago
OK fixed at head: http://code.google.com/p/json-template/source/detail?r=280

Original comment by gtempacc...@yahoo.com on 15 Sep 2009 at 6:51