From feef1c54559ebeb6d3f2eeb3537bc6466a7b27af Mon Sep 17 00:00:00 2001 From: "armin@diedering.de" Date: Thu, 8 Dec 2011 16:26:03 +0000 Subject: [PATCH] 42tiny-js: 42tiny-js is partially more JavaScript compliant as the trunk-tiny-js e.g.: trunk-tiny-js creates a var always when its needed but 42tiny-js only if the var the left-hand-side of an assignment-operator. Test-scripts: Some test-scripts in the "tests"-folder are not JavaScript compliant. I have add new scripts according to the schematic: name.js -> name.42.js run_tests: run_tests is changed to prefer the ???.42.js files. Also run_tests is changed to run scripts in the "tests/42tests" folder after finished the tests from the "tests"-folder. --- tests/test008.42.js | 8 ++++++++ tests/test014.42.js | 17 +++++++++++++++++ tests/test017.42.js | 15 +++++++++++++++ tests/test018.42.js | 21 +++++++++++++++++++++ tests/test021.42.js | 9 +++++++++ tests/test023.42.js | 8 ++++++++ 6 files changed, 78 insertions(+) create mode 100644 tests/test008.42.js create mode 100644 tests/test014.42.js create mode 100644 tests/test017.42.js create mode 100644 tests/test018.42.js create mode 100644 tests/test021.42.js create mode 100644 tests/test023.42.js diff --git a/tests/test008.42.js b/tests/test008.42.js new file mode 100644 index 0000000..29f0e28 --- /dev/null +++ b/tests/test008.42.js @@ -0,0 +1,8 @@ +// functions in variables +// 42-tiny-js change begin ---> +//var bob; // in JavaScript it's not allowed to add a child to a var with type "undefined" +var bob = {}; +//<--- 42-tiny-js change end +bob.add = function(x,y) { return x+y; }; + +result = bob.add(3,6)==9; diff --git a/tests/test014.42.js b/tests/test014.42.js new file mode 100644 index 0000000..7f2fec3 --- /dev/null +++ b/tests/test014.42.js @@ -0,0 +1,17 @@ +// Variable creation and scope from http://en.wikipedia.org/wiki/JavaScript_syntax +x = 0; // A global variable +var y = 'Hello!'; // Another global variable +// 42-tiny-js change begin ---> +z = 0; // a var is only created automated by assignment +//<--- 42-tiny-js change end +function f(){ + var z = 'foxes'; // A local variable + twenty = 20; // Global because keyword var is not used + return x; // We can use x here because it is global +} +// The value of z is no longer available + + +// testing +blah = f(); +result = blah==0 && z!='foxes' && twenty==20; diff --git a/tests/test017.42.js b/tests/test017.42.js new file mode 100644 index 0000000..923d0e7 --- /dev/null +++ b/tests/test017.42.js @@ -0,0 +1,15 @@ +// references for arrays + +// 42-tiny-js change begin ---> +//var a; // in JavaScript it's not allowed to add properies to a var with type "undefined" +var a = []; +//<--- 42-tiny-js change end + +a[0] = 10; +a[1] = 22; + +b = a; + +b[0] = 5; + +result = a[0]==5 && a[1]==22 && b[1]==22; diff --git a/tests/test018.42.js b/tests/test018.42.js new file mode 100644 index 0000000..fbebb4e --- /dev/null +++ b/tests/test018.42.js @@ -0,0 +1,21 @@ +// references with functions + +var a = 42; +// 42-tiny-js change begin ---> +//var b; // in JavaScript it's not allowed to add properties to a var with type "undefined" +var b = []; +//<--- 42-tiny-js change end +b[0] = 43; + +function foo(myarray) { + myarray[0]++; +} + +function bar(myvalue) { + myvalue++; +} + +foo(b); +bar(a); + +result = a==42 && b[0]==44; diff --git a/tests/test021.42.js b/tests/test021.42.js new file mode 100644 index 0000000..a11cc73 --- /dev/null +++ b/tests/test021.42.js @@ -0,0 +1,9 @@ +/* Javascript eval */ + +// 42-tiny-js change begin ---> +// in JavaScript eval is not a JSON-parser +//myfoo = eval("{ foo: 42 }"); +myfoo = eval("tmp = { foo: 42 }"); +//<--- 42-tiny-js change end + +result = eval("4*10+2")==42 && myfoo.foo==42; diff --git a/tests/test023.42.js b/tests/test023.42.js new file mode 100644 index 0000000..b0ecb14 --- /dev/null +++ b/tests/test023.42.js @@ -0,0 +1,8 @@ +// mikael.kindborg@mobilesorcery.com - Function symbol is evaluated in bracket-less body of false if-statement +// 42-tiny-js change begin ---> +var foo; // a var is only created automated by assignment +//<--- 42-tiny-js change end + +if (foo !== undefined) foo(); + +result = 1;