MIRROR: javascript for 馃悳's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at master 72 lines 2.0 kB view raw
1function assertEq(actual, expected, msg) { 2 if (actual !== expected) { 3 throw new Error(`${msg}: expected ${expected}, got ${actual}`); 4 } 5} 6 7function mappedRead(a) { 8 a = 2; 9 return arguments[0]; 10} 11 12function mappedWrite(a) { 13 arguments[0] = 2; 14 return a; 15} 16 17function strictSlice(path) { 18 "use strict"; 19 return { 20 argc: arguments.length, 21 tail: Array.prototype.slice.call(arguments, 1), 22 }; 23} 24 25function strictUnmappedRead(a) { 26 "use strict"; 27 a = 2; 28 return arguments[0]; 29} 30 31function strictUnmappedWrite(a) { 32 "use strict"; 33 arguments[0] = 2; 34 return a; 35} 36 37function directRead(a) { 38 return arguments[0] + a; 39} 40 41function arrowCapture(a) { 42 const read = () => arguments[0] + a; 43 return read(); 44} 45 46for (let i = 0; i < 500; i++) { 47 assertEq(mappedRead(1), 2, "warm mapped read"); 48 assertEq(mappedWrite(1), 2, "warm mapped write"); 49 assertEq(directRead(3), 6, "warm direct read"); 50 assertEq(arrowCapture(4), 8, "warm arrow capture"); 51 assertEq(strictUnmappedRead(1), 1, "warm strict unmapped read"); 52 assertEq(strictUnmappedWrite(1), 1, "warm strict unmapped write"); 53 const warmStrict = strictSlice("/", "mw"); 54 assertEq(warmStrict.argc, 2, "warm strict argc"); 55 assertEq(warmStrict.tail.length, 1, "warm strict tail length"); 56 assertEq(warmStrict.tail[0], "mw", "warm strict tail first"); 57} 58 59assertEq(mappedRead(1), 2, "hot mapped read"); 60assertEq(mappedWrite(1), 2, "hot mapped write"); 61assertEq(directRead(3), 6, "hot direct read"); 62assertEq(arrowCapture(4), 8, "hot arrow capture"); 63assertEq(strictUnmappedRead(1), 1, "hot strict unmapped read"); 64assertEq(strictUnmappedWrite(1), 1, "hot strict unmapped write"); 65 66const hotStrict = strictSlice("/route", "mw1", "mw2"); 67assertEq(hotStrict.argc, 3, "hot strict argc"); 68assertEq(hotStrict.tail.length, 2, "hot strict tail length"); 69assertEq(hotStrict.tail[0], "mw1", "hot strict tail first"); 70assertEq(hotStrict.tail[1], "mw2", "hot strict tail second"); 71 72console.log("OK: test_jit_arguments_object");