SlideShare a Scribd company logo
How I learned to stop worrying and love embedding JavaScript
How I learned to stop worrying and
love embedding JavaScript
Kevin Read
@unverbraucht
kread@boerse-go.de
http://gplus.to/unverbraucht
Martin Kleinhans
@mklhs
mkleinhans@boerse-go.de
http://gplus.to/mklhs
How I learned to stop worrying and love embedding JavaScript
Welcome
Topic:
Reusing existing Javascript code by embedding it in
native applications.
Questions we aim to answer:
● Why? - Benefits.
● When? - Use cases and show-stoppers.
● How? - Architecture and implementation.
How I learned to stop worrying and love embedding JavaScript
Agenda
Introduction
Motivation
Embedding JavaScript
Implementation Specifics
Demo
Conclusion
How I learned to stop worrying and love embedding JavaScript
About us
Company: BörseGo AG
We operate finance-centric portals on
the web and mobile.
We also provide SAAS (e.g. to banks)
Focus on chart analysis and real-time data
Examples?
http://www.guidants.com/
http://www.godmode-trader.de/
How I learned to stop worrying and love embedding JavaScript
Agenda
Introduction
Motivation
Embedding JavaScript
Implementation Specifics
Demo
Conclusion
How I learned to stop worrying and love embedding JavaScript
Motivation
Goal: Create second-gen mobile apps for iOS and
Android (for now).
• Features needed:
– Real-time quotes
– Information on stocks..
– News
– Interactive Finance Charts
✔
✔
?
✔
How I learned to stop worrying and love embedding JavaScript
Motivation
“Web” charting is complex and powerful
– JS tool that renders via Canvas
– Real-time quotes via websocket
– Gazillion indicators and tools
– Interactive zoom/translate/…
=> Demo
Ideally, mobile contains the same features.
How I learned to stop worrying and love embedding JavaScript
Possible approaches - background
Data needed when considering implementation details:
• JS code has 35k LOC (w/o blank and comment)
• Two man years of work
• Extensive chart analysis knowledge and math skills
needed
• Code is updated frequently
• Backwards and (limited) forwards compatibility for
user-data needed
How I learned to stop worrying and love embedding JavaScript
Con
• Expensive and time-
consuming to
implement
• >= 3x maintenance
overhead
– All versions need to be
released in lock-step
Possible approaches: #1 - reimplement
Pro
• Native look & feel
• High performance
• Easy to integrate in
native apps
#1 Re-implement for all platforms natively
✘
How I learned to stop worrying and love embedding JavaScript
Possible approaches: #2 Simplified native version
#2 Re-implement only subset natively
Pro
• Native look & feel
• High performance
• Easy to integrate in
native apps
• Feasible amount of
work
Con
• User confusion and
dissatisfaction
• Loose main USP
✘
How I learned to stop worrying and love embedding JavaScript
Possible approaches: #3 - embed in web browser
#3 Embed web browser with existing JS
APP
WebView
JavaScript Interpreter
Existing JS code
HTML interface
mimicking native look & feel
How I learned to stop worrying and love embedding JavaScript
Con
• Performance issues
• Platform differences
– No calls from JS to
native on iOS!
• native look & feel
difficult
Possible approaches: #3 - embed in web browser
Pro
• Easy to get started
• Very high code re-use
#3 Embed web browser with existing JS
✘
How I learned to stop worrying and love embedding JavaScript
Possible approaches: #4 - embedding JavaScript VM
#4 Embed JS VM directly w/o browser
• Feasibility of approach proven by
– NodeJS
– Titanium
• For interactive apps only POC existed in 2012
How I learned to stop worrying and love embedding JavaScript
Con
• Initially high
implementation
overhead
• Platform differences
Pro
• High performance
• JS code reusable
• Native look & feel
achievable
• Code updates at
runtime
Possible approaches: #4 - embedding JavaScript VM
#4 Embed JS VM directly w/o browser
✔
How I learned to stop worrying and love embedding JavaScript
Agenda
Introduction
Motivation
Embedding JavaScript
Implementation Specifics
Demo
Conclusion
How I learned to stop worrying and love embedding JavaScript
Embedding JavaScript: #1 - Evaluating Code
Step #1:
Evaluating simple JavaScript Code
Core Component: JavaScript Interpreter
• Android: V8
• iOS: JavaScriptCore (JSC)
• No JIT (Sandbox restriction)
=> Provides basic language features only
How I learned to stop worrying and love embedding JavaScript
Embedding JavaScript: #1 - Evaluating Code
APP
JSContext
JavaScript Interpreter
function foo() {
return Math.min(1, 2);
}
Math, Date, String, Array, Object, ...
Code: API:
How I learned to stop worrying and love embedding JavaScript
Embedding JavaScript: #2 - Adding APIs
Step #2:
Extending Context with more APIs
APIs provided by Browser:
• console, setTimeout, setInterval,
requestAnimationFrame ...
Custom APIs:
=> NodeJS compatible module system
How I learned to stop worrying and love embedding JavaScript
Embedding JavaScript: #2 - Adding APIs
APP
JSContext
JavaScript Interpreter
var library = require(“foo”);
console.log( foo.bar() );
Math, Date, String, Array, Object, …
console, setInterval, setTimeout, …
requestAnimationFrame, …
require
Code: API:
Module*
How I learned to stop worrying and love embedding JavaScript
Embedding JavaScript: #3 - Required Modules
Step #3:
Identifying and implementing required modules
Charting needs:
• NO HTML / DOM!
• XMLHttpRequest (AJAX)
• WebSockets
• Canvas
How I learned to stop worrying and love embedding JavaScript
Embedding JavaScript: #3 - Required Modules
Canvas Module
• Renders to View objects in UI layer
• Implements full 2d-Context spec (almost)
• Backed by OpenGL ES
• Prototype: Own Implementation
• Switched to open source library: Ejecta
•Contributed & Ported to android
•Available on github
How I learned to stop worrying and love embedding JavaScript
Embedding JavaScript: #3 - Required Modules
APP
JSContext
JavaScript Interpreter
var canvas = new (require(“canvas”))(view);
var context = canvas.getContext(“2d”);
view.on(“redraw”) {
context.fillRect(0,0,50,50);
}
Math, Date, String, Array, Object, …
console, setInterval, setTimeout, …
require
Code: API:
Module*
ModuleCanvas
ModuleAJAX
…
JSView
How I learned to stop worrying and love embedding JavaScript
Agenda
Introduction
Motivation
Embedding JavaScript
Implementation Specifics
Demo
Conclusion
How I learned to stop worrying and love embedding JavaScript
Implementation Specifics: platform differences
Major platform differences
• Different JS Interpreters
• Different Languages (Java vs Obj-C)
• Different SDK (UI Toolkits, etc...)
• v8 is C++ => JNI (painful)
– Additional abstraction layer: 50% more LOC
• Android: OpenGL on own thread
– all extensions to v8 must be thread-safe
=> two separate frameworks
How I learned to stop worrying and love embedding JavaScript
Objective-C / C
JNI (C / C++)
Dalvik VM (Java)
Implementation Specifics: architectural differences
APP
JSContext
JavaScript Interpreter
Sample_Application.js
Browser
APP
JSContext
v8Helper
iOS AndroidWeb
JSView
ModulesModules
JSView
* *
How I learned to stop worrying and love embedding JavaScript
Implementation Specifics: v8 interpreter API
use namespace v8;
static Handle<Value> log(const Arguments& args) {
std::cout << “log: “ << *(String::Utf8Value(args[0]));
return v8::Undefined();
}
void main() {
Local<FunctionTemplate> console = FunctionTemplate::New();
console->Set("log", FunctionTemplate::New(log));
Handle<ObjectTemplate> global = ObjectTemplate::New();
global->Set(String::New("console"), console);
Context ctx = Context::New(NULL, global);
Script::Compile(
String::New(“console.log(‘Hello World!’);”),
String::New("demo.js")
)->Run();
}
v8 API
How I learned to stop worrying and love embedding JavaScript
var canvas, context;
function animate () {
context.fillStyle = “#f00”;
context.fillText(“Hello world!”, 10, 10);
};
function start ( view ) {
if ( view ) {
canvas = new (require(“canvas”))(view);
} else {
canvas = document.getElementById(“canvas”);
}
context = canvas.getContext(“2d”);
requestAnimationFrame(animate);
}
if ( typeof document != “undefined” ) {
start();
}
Implementation Specifics: sample Application
Sample.js
How I learned to stop worrying and love embedding JavaScript
:JS Code :JSContext :JSView :OpenGL
Implementation Specifics: rendering sequence
load script
requestAnimationFrame(cb) request view refresh
glDrawArrays, ...
run animation requests
execute JS (cb)
draw
flipPage
fillText
triangles added to list
How I learned to stop worrying and love embedding JavaScript
Agenda
Introduction
Motivation
Embedding JavaScript
Implementation Specifics
Demo
Conclusion
How I learned to stop worrying and love embedding JavaScript
Demo - Example #1
Example #1: Ejecta sample app
=> Graphically intense JS apps see big gains.
Android: Acer Iconia A100 (Tegra 2, Android 4)
• Chrome 29: 14 - 16 fps
• Embedded: ~45 fps
iOS: iPad Mini
• Safari: 17 fps
• Embedded: 60fps
+350%
+280%
How I learned to stop worrying and love embedding JavaScript
Demo - Example #2
Example #2: Guidants Mobile
• Universal App for Tablet/Smartphone
• For iOS and Android
• Uses multiple JavaScript-driven Views
• SAME JavaScript files used in
• App
• NodeJS
• Browser
How I learned to stop worrying and love embedding JavaScript
Agenda
Introduction
Motivation
Embedding JavaScript
Implementation Specifics
Demo
Conclusion
How I learned to stop worrying and love embedding JavaScript
• High gains with respect to
• Performance
• Integration with native UI as base for UX
• Most benefits when heavy lifting done outside of JS
• Possible high initial implementation overhead
Thanks!
Conclusion
Kevin Read
@unverbraucht
kread@boerse-go.de
http://gplus.to/unverbraucht
Martin Kleinhans
@mklhs
mkleinhans@boerse-go.de
http://gplus.to/mklhs
Slides:
bit.ly/myrjs
For code, go to:
github.com/godmodelabs/ejecta-v8

More Related Content

PPTX
Angular js
PDF
Angular 2 : learn TypeScript already with Angular 1
PDF
Paris Web - Javascript as a programming language
PPT
Getting started with angular js
PDF
Unobtrusive JavaScript with jQuery
PDF
Multi modularized project setup with gulp, typescript and angular.js
PDF
Building a JavaScript Library
PDF
High Performance JavaScript - jQuery Conference SF Bay Area 2010
Angular js
Angular 2 : learn TypeScript already with Angular 1
Paris Web - Javascript as a programming language
Getting started with angular js
Unobtrusive JavaScript with jQuery
Multi modularized project setup with gulp, typescript and angular.js
Building a JavaScript Library
High Performance JavaScript - jQuery Conference SF Bay Area 2010

What's hot (20)

PDF
On Selecting JavaScript Frameworks (Women Who Code 10/15)
PDF
Usability in the GeoWeb
PPTX
Java vs javascript (XPages)
PDF
Maintainable Javascript carsonified
PDF
gDayX - Advanced angularjs
PDF
Building a Single-Page App: Backbone, Node.js, and Beyond
PPTX
Nightwatch JS for End to End Tests
PPTX
Node.JS error handling best practices
PPTX
Dev evening - MonoTouch, MonoDroid, Mvvm MvvmCross and databinding
PDF
High Performance JavaScript - WebDirections USA 2010
PDF
Performance, Games, and Distributed Testing in JavaScript
PDF
Web Development for UX Designers
PPTX
Java script unit testing
PDF
AngularJS - What is it & Why is it awesome ? (with demos)
PPTX
Testing Ext JS and Sencha Touch
PDF
Hands on Exploration of Page Objects and Abstraction Layers with Selenium Web...
PDF
Comparing Hot JavaScript Frameworks: AngularJS, Ember.js and React.js - Sprin...
PDF
Роман Лютиков "Web Apps Performance & JavaScript Compilers"
PDF
Angular mobile angular_u
PPT
JavaScript 2.0 in Dreamweaver CS4
On Selecting JavaScript Frameworks (Women Who Code 10/15)
Usability in the GeoWeb
Java vs javascript (XPages)
Maintainable Javascript carsonified
gDayX - Advanced angularjs
Building a Single-Page App: Backbone, Node.js, and Beyond
Nightwatch JS for End to End Tests
Node.JS error handling best practices
Dev evening - MonoTouch, MonoDroid, Mvvm MvvmCross and databinding
High Performance JavaScript - WebDirections USA 2010
Performance, Games, and Distributed Testing in JavaScript
Web Development for UX Designers
Java script unit testing
AngularJS - What is it & Why is it awesome ? (with demos)
Testing Ext JS and Sencha Touch
Hands on Exploration of Page Objects and Abstraction Layers with Selenium Web...
Comparing Hot JavaScript Frameworks: AngularJS, Ember.js and React.js - Sprin...
Роман Лютиков "Web Apps Performance & JavaScript Compilers"
Angular mobile angular_u
JavaScript 2.0 in Dreamweaver CS4
Ad

Similar to Embedding V8 in Android apps with Ejecta-V8 (20)

PDF
The curious Life of JavaScript - Talk at SI-SE 2015
PDF
A call to JS Developers - Let’s stop trying to impress each other and start b...
PPTX
JS Fest 2018. Александр Скачков. WebAssembly vs JavaScript
PDF
Javascript Performance
PDF
High quality Front-End
PDF
Y U NO JS?
PDF
Node4J: Running Node.js in a JavaWorld
PPTX
Designing nlp-js-extension
PPTX
JS digest. April 2018
PPTX
JavaScript - Introduction
PPTX
Workshop Intro: FrontEnd General Overview
PDF
WebAssemlby vs JavaScript
PDF
How to build mobile API with Node.js
PDF
Node.js #digpen presentation
PPTX
Revolutionizing-User-Interactions-The-Role-of-JavaScript-in-Web-Development.pptx
PPTX
Browser Internals for JS Devs: WebU Toronto 2016 by Alex Blom
PPTX
JS digest, March 2017
PDF
Making ES6 available to all with ChakraCore
PDF
Breaking out of the endless callback look - #jsday Italy keynote
The curious Life of JavaScript - Talk at SI-SE 2015
A call to JS Developers - Let’s stop trying to impress each other and start b...
JS Fest 2018. Александр Скачков. WebAssembly vs JavaScript
Javascript Performance
High quality Front-End
Y U NO JS?
Node4J: Running Node.js in a JavaWorld
Designing nlp-js-extension
JS digest. April 2018
JavaScript - Introduction
Workshop Intro: FrontEnd General Overview
WebAssemlby vs JavaScript
How to build mobile API with Node.js
Node.js #digpen presentation
Revolutionizing-User-Interactions-The-Role-of-JavaScript-in-Web-Development.pptx
Browser Internals for JS Devs: WebU Toronto 2016 by Alex Blom
JS digest, March 2017
Making ES6 available to all with ChakraCore
Breaking out of the endless callback look - #jsday Italy keynote
Ad

Recently uploaded (20)

PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
history of c programming in notes for students .pptx
PPTX
Transform Your Business with a Software ERP System
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PDF
System and Network Administration Chapter 2
PDF
Digital Strategies for Manufacturing Companies
PPTX
L1 - Introduction to python Backend.pptx
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PPTX
CHAPTER 2 - PM Management and IT Context
Navsoft: AI-Powered Business Solutions & Custom Software Development
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
How to Migrate SBCGlobal Email to Yahoo Easily
2025 Textile ERP Trends: SAP, Odoo & Oracle
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Design an Analysis of Algorithms I-SECS-1021-03
history of c programming in notes for students .pptx
Transform Your Business with a Software ERP System
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
System and Network Administration Chapter 2
Digital Strategies for Manufacturing Companies
L1 - Introduction to python Backend.pptx
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Odoo Companies in India – Driving Business Transformation.pdf
VVF-Customer-Presentation2025-Ver1.9.pptx
Internet Downloader Manager (IDM) Crack 6.42 Build 41
wealthsignaloriginal-com-DS-text-... (1).pdf
CHAPTER 2 - PM Management and IT Context

Embedding V8 in Android apps with Ejecta-V8

  • 1. How I learned to stop worrying and love embedding JavaScript How I learned to stop worrying and love embedding JavaScript Kevin Read @unverbraucht kread@boerse-go.de http://gplus.to/unverbraucht Martin Kleinhans @mklhs mkleinhans@boerse-go.de http://gplus.to/mklhs
  • 2. How I learned to stop worrying and love embedding JavaScript Welcome Topic: Reusing existing Javascript code by embedding it in native applications. Questions we aim to answer: ● Why? - Benefits. ● When? - Use cases and show-stoppers. ● How? - Architecture and implementation.
  • 3. How I learned to stop worrying and love embedding JavaScript Agenda Introduction Motivation Embedding JavaScript Implementation Specifics Demo Conclusion
  • 4. How I learned to stop worrying and love embedding JavaScript About us Company: BörseGo AG We operate finance-centric portals on the web and mobile. We also provide SAAS (e.g. to banks) Focus on chart analysis and real-time data Examples? http://www.guidants.com/ http://www.godmode-trader.de/
  • 5. How I learned to stop worrying and love embedding JavaScript Agenda Introduction Motivation Embedding JavaScript Implementation Specifics Demo Conclusion
  • 6. How I learned to stop worrying and love embedding JavaScript Motivation Goal: Create second-gen mobile apps for iOS and Android (for now). • Features needed: – Real-time quotes – Information on stocks.. – News – Interactive Finance Charts ✔ ✔ ? ✔
  • 7. How I learned to stop worrying and love embedding JavaScript Motivation “Web” charting is complex and powerful – JS tool that renders via Canvas – Real-time quotes via websocket – Gazillion indicators and tools – Interactive zoom/translate/… => Demo Ideally, mobile contains the same features.
  • 8. How I learned to stop worrying and love embedding JavaScript Possible approaches - background Data needed when considering implementation details: • JS code has 35k LOC (w/o blank and comment) • Two man years of work • Extensive chart analysis knowledge and math skills needed • Code is updated frequently • Backwards and (limited) forwards compatibility for user-data needed
  • 9. How I learned to stop worrying and love embedding JavaScript Con • Expensive and time- consuming to implement • >= 3x maintenance overhead – All versions need to be released in lock-step Possible approaches: #1 - reimplement Pro • Native look & feel • High performance • Easy to integrate in native apps #1 Re-implement for all platforms natively ✘
  • 10. How I learned to stop worrying and love embedding JavaScript Possible approaches: #2 Simplified native version #2 Re-implement only subset natively Pro • Native look & feel • High performance • Easy to integrate in native apps • Feasible amount of work Con • User confusion and dissatisfaction • Loose main USP ✘
  • 11. How I learned to stop worrying and love embedding JavaScript Possible approaches: #3 - embed in web browser #3 Embed web browser with existing JS APP WebView JavaScript Interpreter Existing JS code HTML interface mimicking native look & feel
  • 12. How I learned to stop worrying and love embedding JavaScript Con • Performance issues • Platform differences – No calls from JS to native on iOS! • native look & feel difficult Possible approaches: #3 - embed in web browser Pro • Easy to get started • Very high code re-use #3 Embed web browser with existing JS ✘
  • 13. How I learned to stop worrying and love embedding JavaScript Possible approaches: #4 - embedding JavaScript VM #4 Embed JS VM directly w/o browser • Feasibility of approach proven by – NodeJS – Titanium • For interactive apps only POC existed in 2012
  • 14. How I learned to stop worrying and love embedding JavaScript Con • Initially high implementation overhead • Platform differences Pro • High performance • JS code reusable • Native look & feel achievable • Code updates at runtime Possible approaches: #4 - embedding JavaScript VM #4 Embed JS VM directly w/o browser ✔
  • 15. How I learned to stop worrying and love embedding JavaScript Agenda Introduction Motivation Embedding JavaScript Implementation Specifics Demo Conclusion
  • 16. How I learned to stop worrying and love embedding JavaScript Embedding JavaScript: #1 - Evaluating Code Step #1: Evaluating simple JavaScript Code Core Component: JavaScript Interpreter • Android: V8 • iOS: JavaScriptCore (JSC) • No JIT (Sandbox restriction) => Provides basic language features only
  • 17. How I learned to stop worrying and love embedding JavaScript Embedding JavaScript: #1 - Evaluating Code APP JSContext JavaScript Interpreter function foo() { return Math.min(1, 2); } Math, Date, String, Array, Object, ... Code: API:
  • 18. How I learned to stop worrying and love embedding JavaScript Embedding JavaScript: #2 - Adding APIs Step #2: Extending Context with more APIs APIs provided by Browser: • console, setTimeout, setInterval, requestAnimationFrame ... Custom APIs: => NodeJS compatible module system
  • 19. How I learned to stop worrying and love embedding JavaScript Embedding JavaScript: #2 - Adding APIs APP JSContext JavaScript Interpreter var library = require(“foo”); console.log( foo.bar() ); Math, Date, String, Array, Object, … console, setInterval, setTimeout, … requestAnimationFrame, … require Code: API: Module*
  • 20. How I learned to stop worrying and love embedding JavaScript Embedding JavaScript: #3 - Required Modules Step #3: Identifying and implementing required modules Charting needs: • NO HTML / DOM! • XMLHttpRequest (AJAX) • WebSockets • Canvas
  • 21. How I learned to stop worrying and love embedding JavaScript Embedding JavaScript: #3 - Required Modules Canvas Module • Renders to View objects in UI layer • Implements full 2d-Context spec (almost) • Backed by OpenGL ES • Prototype: Own Implementation • Switched to open source library: Ejecta •Contributed & Ported to android •Available on github
  • 22. How I learned to stop worrying and love embedding JavaScript Embedding JavaScript: #3 - Required Modules APP JSContext JavaScript Interpreter var canvas = new (require(“canvas”))(view); var context = canvas.getContext(“2d”); view.on(“redraw”) { context.fillRect(0,0,50,50); } Math, Date, String, Array, Object, … console, setInterval, setTimeout, … require Code: API: Module* ModuleCanvas ModuleAJAX … JSView
  • 23. How I learned to stop worrying and love embedding JavaScript Agenda Introduction Motivation Embedding JavaScript Implementation Specifics Demo Conclusion
  • 24. How I learned to stop worrying and love embedding JavaScript Implementation Specifics: platform differences Major platform differences • Different JS Interpreters • Different Languages (Java vs Obj-C) • Different SDK (UI Toolkits, etc...) • v8 is C++ => JNI (painful) – Additional abstraction layer: 50% more LOC • Android: OpenGL on own thread – all extensions to v8 must be thread-safe => two separate frameworks
  • 25. How I learned to stop worrying and love embedding JavaScript Objective-C / C JNI (C / C++) Dalvik VM (Java) Implementation Specifics: architectural differences APP JSContext JavaScript Interpreter Sample_Application.js Browser APP JSContext v8Helper iOS AndroidWeb JSView ModulesModules JSView * *
  • 26. How I learned to stop worrying and love embedding JavaScript Implementation Specifics: v8 interpreter API use namespace v8; static Handle<Value> log(const Arguments& args) { std::cout << “log: “ << *(String::Utf8Value(args[0])); return v8::Undefined(); } void main() { Local<FunctionTemplate> console = FunctionTemplate::New(); console->Set("log", FunctionTemplate::New(log)); Handle<ObjectTemplate> global = ObjectTemplate::New(); global->Set(String::New("console"), console); Context ctx = Context::New(NULL, global); Script::Compile( String::New(“console.log(‘Hello World!’);”), String::New("demo.js") )->Run(); } v8 API
  • 27. How I learned to stop worrying and love embedding JavaScript var canvas, context; function animate () { context.fillStyle = “#f00”; context.fillText(“Hello world!”, 10, 10); }; function start ( view ) { if ( view ) { canvas = new (require(“canvas”))(view); } else { canvas = document.getElementById(“canvas”); } context = canvas.getContext(“2d”); requestAnimationFrame(animate); } if ( typeof document != “undefined” ) { start(); } Implementation Specifics: sample Application Sample.js
  • 28. How I learned to stop worrying and love embedding JavaScript :JS Code :JSContext :JSView :OpenGL Implementation Specifics: rendering sequence load script requestAnimationFrame(cb) request view refresh glDrawArrays, ... run animation requests execute JS (cb) draw flipPage fillText triangles added to list
  • 29. How I learned to stop worrying and love embedding JavaScript Agenda Introduction Motivation Embedding JavaScript Implementation Specifics Demo Conclusion
  • 30. How I learned to stop worrying and love embedding JavaScript Demo - Example #1 Example #1: Ejecta sample app => Graphically intense JS apps see big gains. Android: Acer Iconia A100 (Tegra 2, Android 4) • Chrome 29: 14 - 16 fps • Embedded: ~45 fps iOS: iPad Mini • Safari: 17 fps • Embedded: 60fps +350% +280%
  • 31. How I learned to stop worrying and love embedding JavaScript Demo - Example #2 Example #2: Guidants Mobile • Universal App for Tablet/Smartphone • For iOS and Android • Uses multiple JavaScript-driven Views • SAME JavaScript files used in • App • NodeJS • Browser
  • 32. How I learned to stop worrying and love embedding JavaScript Agenda Introduction Motivation Embedding JavaScript Implementation Specifics Demo Conclusion
  • 33. How I learned to stop worrying and love embedding JavaScript • High gains with respect to • Performance • Integration with native UI as base for UX • Most benefits when heavy lifting done outside of JS • Possible high initial implementation overhead Thanks! Conclusion Kevin Read @unverbraucht kread@boerse-go.de http://gplus.to/unverbraucht Martin Kleinhans @mklhs mkleinhans@boerse-go.de http://gplus.to/mklhs Slides: bit.ly/myrjs For code, go to: github.com/godmodelabs/ejecta-v8