diff --git a/Makefile b/Makefile index 2d1d5df..0563c08 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC=g++ -CFLAGS=-c -g -Wall -rdynamic +CFLAGS=-c -g -Wall -rdynamic -D_DEBUG LDFLAGS=-g -rdynamic SOURCES= \ diff --git a/TinyJS.cpp b/TinyJS.cpp index c1aa3fc..4a10f46 100755 --- a/TinyJS.cpp +++ b/TinyJS.cpp @@ -97,6 +97,7 @@ Version 0.30 : Rlyeh Mario's patch for Math Functions on VC++ Version 0.31 : Add exec() to TinyJS functions Now print quoted JSON that can be read by PHP/Python parsers + Fixed postfix increment operator NOTE: Constructing an array with an initial length 'Array(5)' doesn't work @@ -1751,8 +1752,11 @@ CScriptVarLink *CTinyJS::expression(bool &execute) { if (execute) { CScriptVar one(1); CScriptVar *res = a->var->mathsOp(&one, op==LEX_PLUSPLUS ? '+' : '-'); + CScriptVarLink *oldValue = new CScriptVarLink(a->var); // in-place add/subtract a->replaceWith(res); + CLEAN(a); + a = oldValue; } } else { CScriptVarLink *b = term(execute); diff --git a/run_tests.cpp b/run_tests.cpp index de04fcd..4e39803 100644 --- a/run_tests.cpp +++ b/run_tests.cpp @@ -36,6 +36,9 @@ #include #include +#ifdef MTRACE + #include +#endif //#define INSANE_MEMORY_DEBUG @@ -238,6 +241,9 @@ bool run_test(const char *filename) { int main(int argc, char **argv) { +#ifdef MTRACE + mtrace(); +#endif #ifdef INSANE_MEMORY_DEBUG memtracing_init(); #endif @@ -271,10 +277,15 @@ int main(int argc, char **argv) #ifdef INSANE_MEMORY_DEBUG memtracing_kill(); #endif -#ifdef _WIN32 + #ifdef _DEBUG + #ifdef _WIN32 _CrtDumpMemoryLeaks(); + #endif #endif +#ifdef MTRACE + muntrace(); #endif + return 0; } diff --git a/tests/test008.js b/tests/test008.js index 8596ee2..b0d5525 100644 --- a/tests/test008.js +++ b/tests/test008.js @@ -1,5 +1,5 @@ // functions in variables -var bob; +var bob = {}; bob.add = function(x,y) { return x+y; }; result = bob.add(3,6)==9; diff --git a/tests/test014.js b/tests/test014.js index 9c2bb30..5538c54 100644 --- a/tests/test014.js +++ b/tests/test014.js @@ -1,6 +1,7 @@ // Variable creation and scope from http://en.wikipedia.org/wiki/JavaScript_syntax x = 0; // A global variable var y = 'Hello!'; // Another global variable +z = 0; // yet another global variable function f(){ var z = 'foxes'; // A local variable diff --git a/tests/test017.js b/tests/test017.js index 0f6be1b..ebebe01 100644 --- a/tests/test017.js +++ b/tests/test017.js @@ -1,6 +1,6 @@ // references for arrays -var a; +var a = []; a[0] = 10; a[1] = 22; diff --git a/tests/test018.js b/tests/test018.js index 52da3d1..1432de0 100644 --- a/tests/test018.js +++ b/tests/test018.js @@ -1,7 +1,7 @@ // references with functions var a = 42; -var b; +var b = []; b[0] = 43; function foo(myarray) { diff --git a/tests/test023.js b/tests/test023.js index 619c486..b40d427 100644 --- a/tests/test023.js +++ b/tests/test023.js @@ -1,4 +1,5 @@ // mikael.kindborg@mobilesorcery.com - Function symbol is evaluated in bracket-less body of false if-statement +var foo; // a var is only created automated by assignment if (foo !== undefined) foo();