Introducing JsRT – Embedding JavaScript on Windows

One of the most exciting things about the JavaScript language in the past few years has been the way it which it has been making a leap beyond the browser. The world generally under-appreciates the power of small, high-embeddable, and interactive languages, and it’s been heartening to see the great work of the node.js crew and others using JS for a wide variety of non-browser application. Lots of applications and platforms have hidden value inside of them that is almost entirely inaccessible until someone like JavaScript comes along and unlocks them, enabling regular people to do things that can almost seem magical. (I saw a lot of this early on in my career working on Access, which combined the power of a relational database with embedded BASIC.) It’s what drew me to the Chakra JavaScript runtime team a little over a year ago, when I was given the opportunity to explore some ideas around making JavaScript embeddable on the Windows platform.

Actually, I can hear some of you saying, “Hey, wait a minute! You can already embed JavaScript on Windows! You just use the IActiveScript APIs. Everybody knows that!” That’s true, but the IActiveScript APIs have two problems:

  1. They are COM based and require extensive use of IDispatch for communication between the JavaScript host and JavaScript code (which is an issue both in terms of coding and performance).
  2. They only work with the JavaScript engine that last shipped with IE8 (a.k.a. the “legacy engine”). The new Chakra engine, which has a high-performance GC and JIT compiler, does not officially support the IActiveScript interfaces. It talks to IE using a set of private (and IE-specific) interfaces.

However, I’m proud to announce that, as of the IE11 preview (released at build last week), Chakra now has a fully supported public API! It’s called the “JsRT API” (for “JavaScript RunTime API”) and it enables any application running on Windows to use the Chakra JavaScript engine. The APIs are all  regular Win32 APIs and are designed for ease-of-use and high-performance applications. Here are some technical details:

  • The JsRT APIs are part of IE11 and will be supported on any operating system that has IE11 installed on it. RIght now, that means Windows 8.1 and Windows Server 2012 R2. Once IE11 is released for them, it will also mean Windows 7 and Windows Server 2008 R2.
  • The Windows 8.1 SDK (included with the Visual Studio 2013 preview) includes the new header file jsrt.h and export library file jsrt.lib which you can use to compile against in C/C++ projects.
  • We don’t have an official CLR wrapper at this point, but we will be providing a code sample shortly that wraps all the JsRT APIs with P/Invoke calls.
  • The JsRT APIs are not supported in Windows Runtime applications. Because the Windows Runtime itself hosts Chakra, there are a number of important technical issues having to do with the way the system hosting and application hosting could interact that need to be solved. We won’t have solutions for these issues in the Windows 8.1 timeframe, unfortunately.

We’ll also be putting up code samples that show off all the basics of hosting Chakra, including some side benefits that you get for free from the rest of the Microsoft ecosystem:

  • The Visual Studio script debugger (or, really, any IActiveScript debugger) will work with a Chakra host. This includes breakpoints, locals inspection, stepping, etc. as well as some exciting new features for IE11 that I’ll talk about later.
  • The Visual Studio 2013 preview profiler will work with a Chakra host out of the box to profile JavaScript code.
  • The Visual Studio 2013 preview JavaScript memory analyzer will work with a Chakra host as well.

As you can see, there are a lot of capabilities available when you use Chakra inside of your application. This is just the introductory post, I’ll be talking in more detail in the coming weeks about all the cool things you can do with the runtime. But in the meantime, download the Windows 8.1 preview and the Visual Studio 2013 preview and get cracking!

You can always reach me on Twitter here.

6 thoughts on “Introducing JsRT – Embedding JavaScript on Windows

  1. Pingback: JsRT Samples and Documentation | Panopticon Central

  2. Raj Chaudhuri

    This is quite a co-incidence. Just yesterday, I was considering choices for an embedded scripting language, and was wondering if Chakra was supported by Active Scripting.

    Sadly, I won’t be able to use JsRT, as my requirement is immediate, and I need to support Windows 7 (and unofficially XP) today.

    Reply

Leave a Reply