Jassa la GeekMeet Bucuresti

686 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
686
On SlideShare
0
From Embeds
0
Number of Embeds
131
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • SpiderMonkey C API created by Mozilla Rhino JAVA API created by Mozilla V8 C++ API created by Google KJS ->WebKit used in Safari
  • SpiderMonkey C API created by Mozilla Rhino JAVA API created by Mozilla V8 C++ API created by Google KJS ->WebKit used in Safari
  • Jassa la GeekMeet Bucuresti

    1. 1. The One Script ...language, to rule them all...
    2. 2. JaSSa JavaScript on ServerSide Alexandru NOVAC [email_address] Zitec.com CTO & Founding Partner * Click here if you do not want to see more ads
    3. 3. JavaScript Trivia <ul><li>Creator: </li></ul><ul><li>- Brendan Eich, Mozilla CTO </li></ul><ul><li>  </li></ul><ul><li>Previous aliases: </li></ul><ul><li>- Mocha </li></ul><ul><li>- LiveScript </li></ul><ul><li>  </li></ul><ul><li>DoB: </li></ul><ul><li>- work started in '95 </li></ul><ul><li>- available since '96  </li></ul><ul><li>(Netscape Navigator 2.0) </li></ul><ul><li>ECMA Standard: </li></ul><ul><li>- 1997 - got an ugly code name, (mostly thanks to Microsoft): ECMAScript  </li></ul>Some JavaScript Offsprings:   - Mozilla's SpiderMonkey    - Microsoft's JScript   - Adobe's ActionScript 3   - Nokia's (formerly Trolltech's) QtScript   - Apple's Safari uses JavaScriptCore   - Last but definitely not least: Google's V8 Engine (1337)
    4. 4. ServerSide JavaScript <ul><li>Why Oh Why? </li></ul><ul><ul><li>Web GUI is mostly based on HTML, CSS AND JavaSscript </li></ul></ul><ul><li>  </li></ul><ul><ul><li>  Flash GUI is now using ActionScript 3 (ECMAScript) </li></ul></ul><ul><li>  </li></ul><ul><ul><li>Lots of server-side options: PHP, Python, Ruby, ASP.NET etc. </li></ul></ul><ul><li>  </li></ul><ul><ul><li>Why use another language? </li></ul></ul><ul><ul><li>Why duplicate code (eg. form validations) </li></ul></ul><ul><li>Previous Art </li></ul><ul><ul><li>jaxer (Mozilla + SpiderMonkey) </li></ul></ul><ul><li>  </li></ul><ul><ul><li>jslibs (SpiderMonkey DirectX)  </li></ul></ul><ul><li>  </li></ul><ul><ul><li>mod_js </li></ul></ul><ul><li>  </li></ul><ul><ul><li>jsext </li></ul></ul><ul><li>  </li></ul><ul><ul><li>v8cgi  (V8 CGI, FastCGI, apache module) </li></ul></ul>
    5. 5. Tactical Analysis <ul><li>Advantages: </li></ul><ul><li>  </li></ul><ul><ul><li>a language  well known  to decent web developers (?)  </li></ul></ul><ul><li>  </li></ul><ul><ul><li>ability to use the same code on server-side and client-side </li></ul></ul><ul><li>  </li></ul><ul><ul><li>smooth communication via JSON   </li></ul></ul><ul><li>  </li></ul><ul><ul><li>built-in XML support through E4X (SpiderMonkey only) </li></ul></ul><ul><li>  </li></ul><ul><ul><li>Speed (will see later on) </li></ul></ul><ul><li>Drawbacks: </li></ul><ul><ul><li>early stage  </li></ul></ul><ul><li>  </li></ul><ul><ul><li>various implementations that are very different </li></ul></ul><ul><li>  </li></ul><ul><ul><li>no unified set of classes/interfaces to access external libraries like mysql, pgsql, curl etc.  </li></ul></ul><ul><ul><li>scripts wrote for one implementation won't work on another :( </li></ul></ul>
    6. 6. The JavaScript Engine <ul><li>Mozilla's SpiderMonkey & Google's V8 </li></ul><ul><ul><li>language constructs </li></ul></ul><ul><ul><li>basic types functionality ( integers, strings, arrays ) </li></ul></ul><ul><ul><li>the ability to embed it into your own application </li></ul></ul><ul><ul><li>the ability to expose functionality from the application to the scripting environment. </li></ul></ul>
    7. 7. JASSA Goals <3 <ul><li>Covered or initiated: </li></ul><ul><ul><li>access to the server environment </li></ul></ul><ul><ul><li>access to the HTTP request and response </li></ul></ul><ul><ul><li>expose various libraries (MySQL, CURL etc) </li></ul></ul><ul><ul><li>make it easy to create extensions </li></ul></ul><ul><ul><li>group features into namespaces (db, net, system) </li></ul></ul><ul><li>To Do List: </li></ul><ul><ul><li>expose system functionality (sockets, system calls) </li></ul></ul><ul><ul><li>performance! </li></ul></ul>
    8. 8. Accessing a MySQL DB <ul><li> var print = jassa.response.append; </li></ul><ul><li>var db = new jassa.MySQL(); </li></ul><ul><li>db.connect( 'localhost' , 'root' , '' , 'jassa' ); </li></ul><ul><li>var contacts = db.getAll( 'SELECT * FROM contacts' , true ); </li></ul><ul><li>print( '<table> ' ); </li></ul><ul><li>for( var idx in contacts ) { </li></ul><ul><li>var contact = contacts[idx]; </li></ul><ul><li>print( '<tr>' ); </li></ul><ul><li>for( var idxo in contact ) { </li></ul><ul><li>print( '<td>' + contact[idxo] + '</td>' ); </li></ul><ul><li>} </li></ul><ul><li>print( '</tr> ' ); </li></ul><ul><li>} </li></ul><ul><li>print( '</table> '); </li></ul>
    9. 9. Using CURL & XML <ul><li>var print = jassa.response.append; </li></ul><ul><li>print( 'Retrieving BNR Exchange Rates via CURL...<br /> ' ); </li></ul><ul><li>var c = new jassa.CURL(); </li></ul><ul><li>c.setURL( 'http://www.bnr.ro/nbrfxrates.xml' ); </li></ul><ul><li>c.perform(); </li></ul><ul><li>var rate = new XML( c.response.body ); </li></ul><ul><li>var ns = new Namespace( 'http://www.bnr.ro/xsd' ); </li></ul><ul><li>var eur = rate..ns::Rate.(@currency == &quot;EUR&quot;); </li></ul><ul><li>print( '1EUR = ' + eur + 'RON' ); </li></ul>
    10. 10. How it Works
    11. 11. JASSA Performance
    12. 12. JASSA Performance
    13. 13. K.Thx.Bye. <ul><li>Many thanks to: </li></ul><ul><ul><li>Everyone that made JavaScript possible </li></ul></ul><ul><ul><li>GoogleDocs which made this presentation possible </li></ul></ul>CAN I HAS QUESTIONS? #followfriday @acidtrix & @zitec on Twitter

    ×