Edge JsRT: Universal Windows Platform

The last major chunk of new APIs in Edge JsRT relate to the Universal Windows Platform, or UWP. Hopefully, you’re familiar with the UWP already, but if not, the UWP is the “modern” way of building Windows applications that go into the Windows Store. (Thus, UWP apps are also called “Store apps”.) At it’s most basic, the UWP is a set of curated APIs that UWP applications can use to talk to the system. UWP APIs are built in a special way (similar to the way .NET APIs are built) that allow them to be written once and then be usable in C++/CX, JavaScript, and C#/VB.

The way that UWP APIs are exposed in each language is called projection. To make projection work, each language has a special piece of code that knows how to take a UWP API and make it appear correctly to programs written in that language. To turn on that special code in Chakra requires some calls that were not available to JsRT hosts in the past, but which have now been exposed in Edge JsRT. The main one is called JsProjectWinRTNamespace. (WinRT is yet another legacy name for the UWP.)

JsProjectWinRTNamespace will take a root UWP namespace (such as “Windows”) and project it into the current context, making that namespace available in the global JS namespace. Great, right! Well, there’s one catch: unless your host is a UWP application (i.e. a Store app), you can only project the Windows namespace. That’s because projecting anything outside of the Windows namespace requires loading some UWP component that supports that namespace. And UWP components can only be loaded by UWP applications. This is a somewhat entirely arbitrary restriction, but since the UWP platform is built that way, oh well. It does mean that non-UWP hosts can still get access to some useful UWP system APIs.

The other API is a little more esoteric, but still important. JsSetProjectionEnqueueCallback is needed to support asynchronous UWP APIs. If you’ve been following along at home, you’ll remember that my previous post talked about setting up a callback that allows asynchronous JavaScript APIs to let you know to run some code when an ES6 async API is finished. Well, this is basically the same thing, but for the UWP platform as opposed to ES6. So go back to read that post if you want to understand a bit more what this is for. The shape is slightly different (confusingly) but the purpose is basically the same.

You should also follow me on Twitter here.

Leave a Reply

Your email address will not be published. Required fields are marked *