many many changes. Too many to enumerate them here. New main-features: - injected a tokenizer between Lexer and Executer. this makes the two-pass-mode obsolete. the first pass is done by the tokenizer. - add 'with' and 'let' statements. - fixed and optimized the prototype- and scope-chain - added accessors like: { get test(){ return this.test_var; } , test_var : 5 } - and many more i wish you a happy new year 2012 ardimaster
parent
91b9188045
commit
f275444f82
@ -0,0 +1,80 @@
|
||||
// switch-case-tests
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
// switch-test 1: case with break;
|
||||
////////////////////////////////////////////////////
|
||||
var a1=5;
|
||||
var b1=6;
|
||||
var r1=0;
|
||||
|
||||
switch(a1+5){
|
||||
case 6:
|
||||
r1 = 2;
|
||||
break;
|
||||
case b1+4:
|
||||
r1 = 42;
|
||||
break;
|
||||
case 7:
|
||||
r1 = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
// switch-test 2: case with out break;
|
||||
////////////////////////////////////////////////////
|
||||
var a2=5;
|
||||
var b2=6;
|
||||
var r2=0;
|
||||
|
||||
switch(a2+4){
|
||||
case 6:
|
||||
r2 = 2;
|
||||
break;
|
||||
case b2+3:
|
||||
r2 = 40;
|
||||
//break;
|
||||
case 7:
|
||||
r2 += 2;
|
||||
break;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
// switch-test 3: case with default;
|
||||
////////////////////////////////////////////////////
|
||||
var a3=5;
|
||||
var b3=6;
|
||||
var r3=0;
|
||||
|
||||
switch(a3+44){
|
||||
case 6:
|
||||
r3 = 2;
|
||||
break;
|
||||
case b3+3:
|
||||
r3 = 1;
|
||||
break;
|
||||
default:
|
||||
r3 = 42;
|
||||
break;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
// switch-test 4: case default before case;
|
||||
////////////////////////////////////////////////////
|
||||
var a4=5;
|
||||
var b4=6;
|
||||
var r4=0;
|
||||
|
||||
switch(a4+44){
|
||||
default:
|
||||
r4 = 42;
|
||||
break;
|
||||
case 6:
|
||||
r4 = 2;
|
||||
break;
|
||||
case b4+3:
|
||||
r4 = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
result = r1 == 42 && r2 == 42 && r3 == 42 && r4 == 42;
|
@ -0,0 +1,23 @@
|
||||
// built-in functions
|
||||
|
||||
foo = "foo bar stuff";
|
||||
// 42-tiny-js change begin --->
|
||||
// in JavaScript this function is called Math.random()
|
||||
//r = Math.rand();
|
||||
r = Math.random();
|
||||
//<--- 42-tiny-js change end
|
||||
|
||||
parsed = Integer.parseInt("42");
|
||||
|
||||
aStr = "ABCD";
|
||||
aChar = aStr.charAt(0);
|
||||
|
||||
obj1 = new Object();
|
||||
obj1.food = "cake";
|
||||
obj1.desert = "pie";
|
||||
|
||||
obj2 = obj1.clone();
|
||||
obj2.food = "kittens";
|
||||
|
||||
result = foo.length==13 && foo.indexOf("bar")==4 && foo.substring(8,13)=="stuff" && parsed==42 &&
|
||||
Integer.valueOf(aChar)==65 && obj1.food=="cake" && obj2.desert=="pie";
|
@ -1,9 +1,10 @@
|
||||
/* Javascript eval */
|
||||
|
||||
// 42-tiny-js change begin --->
|
||||
// in JavaScript eval is not a JSON-parser
|
||||
// in JavaScript eval is not JSON.parse
|
||||
// use parentheses or JSON.parse instead
|
||||
//myfoo = eval("{ foo: 42 }");
|
||||
myfoo = eval("tmp = { foo: 42 }");
|
||||
myfoo = eval("("+"{ foo: 42 }"+")");
|
||||
//<--- 42-tiny-js change end
|
||||
|
||||
result = eval("4*10+2")==42 && myfoo.foo==42;
|
||||
|
@ -0,0 +1,15 @@
|
||||
/* Javascript eval */
|
||||
|
||||
mystructure = { a:39, b:3, addStuff : function(c,d) { return c+d; } };
|
||||
|
||||
mystring = JSON.stringify(mystructure, undefined);
|
||||
|
||||
// 42-tiny-js change begin --->
|
||||
// in JavaScript eval is not JSON.parse
|
||||
// use parentheses or JSON.parse instead
|
||||
//mynewstructure = eval(mystring);
|
||||
mynewstructure = eval("("+mystring+")");
|
||||
mynewstructure2 = JSON.parse(mystring);
|
||||
//<--- 42-tiny-js change end
|
||||
|
||||
result = mynewstructure.addStuff(mynewstructure.a, mynewstructure.b) == 42 && mynewstructure2.addStuff(mynewstructure2.a, mynewstructure2.b) == 42;
|
@ -0,0 +1,13 @@
|
||||
function Foo() {
|
||||
this.__proto__ = Foo.prototype;
|
||||
}
|
||||
Foo.prototype = { value : function() { return this.x + this.y; } };
|
||||
|
||||
var a = { __proto__ : Foo.prototype, x: 1, y: 2 };
|
||||
var b = new Foo();
|
||||
b.x = 2;
|
||||
b.y = 3;
|
||||
|
||||
var result1 = a.value();
|
||||
var result2 = b.value();
|
||||
result = result1==3 && result2==5;
|
Loading…
Reference in new issue