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.master
parent
1a2eb0333e
commit
feef1c5455
@ -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;
|
@ -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;
|
@ -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;
|
@ -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;
|
@ -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;
|
@ -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;
|
Loading…
Reference in new issue