Windows 10: Using Chakra for Scripting Applications across Windows 10

Discus and support Using Chakra for Scripting Applications across Windows 10 in Windows 10 News to solve the problem; In Windows 10, the Chakra JavaScript engine powers Microsoft Edge and Windows applications written in HTML/CSS/JS. However with JavaScript’s increasing... Discussion in 'Windows 10 News' started by Brink, May 17, 2015.

  1. Brink
    Brink New Member

    Using Chakra for Scripting Applications across Windows 10


    By default, the JIT code emitted for the above function is optimized for execution speed and does not have any “script interruption” checks inserted by default. By executing the emitted code, a thread will become a runaway, making it impossible to break the loop.

    Developers can configure the runtime to allow such loops to be interrupted by passing the AllowScriptInterrupt flag when creating a runtime. When used, a supervisor thread can request that the runtime terminates execution by calling JsDisableRuntimeExecution at any point, which in turn terminates the script runtime and exits any executing code. The runtime can later be re-enabled by using the JsEnableRuntimeExecution function. This provides developers with a straightforward way to terminate script while keeping the script environment alive.

    Edge JSRT: Universal Windows Platform & ECMAScript6 support
    In Windows10, to align with the evergreen Microsoft Edge browser strategy, Chakra JavaScript engine has forked into two separate components (or binaries)

    • Jscript9.dll, a version of Chakra that is supported by IE11 and retains full backward compatibility
    • Chakra.dll, a version of Chakra that is supported by Microsoft Edge, will be actively developed and be ever evolving, just like the rendering engine for Microsoft Edge
    As a result of this change, JSRT APIs have also split into two

    • Legacy JSRT APIs, which use jscript9.dll and provide full backward compatibility for Classic (Win32) Windows applications that were built using JSRT APIs that shipped with Windows8.1/IE11
    • Edge JSRT APIs, which use Chakra.dll and become the actively developed JSRT APIs that leverage the continuous performance and language updates that will be coming to Chakra
    All of the design choices mentioned in the above section are still supported in Edge JSRT. However, unlike the legacy JSRT APIs, Edge JSRT APIs enable support for hosting Chakra in any Universal Windows applications providing scripts native access to the underlying platform, provide ECMAScript6 support on par with ES6 support enabled by default in Microsoft Edge, and enables debugging of scripts in Universal Windows applications via Visual Studio. The whitepaper on Targeting Edge vs. Legacy Engine with JSRT APIs provides more information about the API split and how to target Edge JSRT APIs.

    JSRT and Universal Windows Applications

    Universal Windows platform supported by Windows 10 allows developers to use the same code to build applications that run across a family of Windows 10 devices including Desktop, Mobile, Xbox, and IoT. To use Chakra for scriptability in Universal Windows applications, developers can use all the Edge JSRT APIs, with the exception of the following profiling APIs – JsStartProfiling, JsStopProfiling, JsEnumerateHeap, and JsIsEnumeratingHeap, which are currently supported only in Classic (Win32) Windows applications.

    The sample JavaScript console app showcases the use of Edge JSRT APIs in a Universal Windows application.

    Edge JSRT APIs also allow scripts to natively access UWP APIs. An example of this feature is the uwp npm package that allows UWP access in Node.js apps running on Windows 10 using Chakra. The JsProjectWinRTNamespace allows exposing a UWP namespace to scripts. The following example utilizes UWP APIs to create an http client to get content from Uri:

    Code: JsProjectWinRTNamespace(L"Windows.Foundation"); JsProjectWinRTNamespace(L"Windows.Web"); // Get content from an Uri. JsRunScript( L"var uri = new Windows.Foundation.Uri(\"http://somedatasource.com\"); " \ L"var httpClient = new Windows.Web.Http.HttpClient();" \ L"httpClient.getStringAsync(uri).done(function () { " \ L" // do something with the string content " \ L"}, onError); " \ L"function onError(reason) { " \ L" // error handling " \ L"}", JS_SOURCE_CONTEXT_NONE, L"", &result);[/quote] While Universal Windows applications have full support, to use asynchronous UWP APIs and events in a Classic (Win32) Windows application, a COM initialized delegate pumping mechanism needs to be enabled through JsSetProjectionEnqueueCallback. A sample is provided here.

    ECMAScript 6 Language Support
    ECMA-262 6th Edition (ES6) is the most significant update to the JavaScript language ever and brings various new capabilities and syntactic sugar to the language. By leveraging the ES6 functionality that is available in Chakra for Microsoft Edge, Edge JSRT allows executing simpler and more powerful JavaScript code like ES6 Arrow Function to write lexically-bound single-line anonymous functions and ES6 Promises to perform asynchronous tasks.

    Scripts using ES6 language features require no setup to run with Edge JSRT, except for ES6 Promises. For ES6 promises, a hosting application needs to provide an EnqueueJob abstract operation to queue up the promise tasks. JsSetPromiseContinuationCallback allows application to provide an EnqueueJob style callback to process the promise task queue. The following sample showcases how to store the promise tasks and execute them after the current execution context is finished:

    Code: static void CALLBACK PromiseContinuationCallback(JsValueRef task, void *callbackState) { // save async task in the callback. *(void **)callbackState = task; } void runPromiseSample() { JsValueRef result; JsValueRef task = JS_INVALID_REFERENCE; JsValueRef callback = JS_INVALID_REFERENCE; JsSetPromiseContinuationCallback(PromiseContinuationCallback, &callback); JsRunScript( L"//The JavaScript ES6 Promise code goes here" \ L"new Promise(" \ L" function(resolve, reject) {resolve('basic:success');}" \ L").then(function () {return new Promise(" \ L" function(resolve, reject) {resolve('second:success')}" \ L")});", JS_SOURCE_CONTEXT_NONE, L"", &result); // execute async tasks stored in callback while (callback! = JS_INVALID_REFERENCE) { task = callback; callback = JS_INVALID_REFERENCE; JsCallFunction(task, nullptr, 0, &result); } }[/quote] Apart from providing ES6 support for scripts, Edge JSRT also provides APIs to maneuver new ES6 types and objects, such as Symbol or TypedArray, in native code for better JS/native integration and performance.

    Debugging applications
    JSRT APIs support script debugging with Visual Studio. In legacy JSRT, the host needs to provide an IDebugApplication pointer to put the script context in debug mode. In Edge JSRT, instead of using IDebugApplication, scripts can be debugged using the following steps:

    • In Visual Studio, right click on your project -> Select “Properties” -> Select “Debugging” -> In “Debugger Type”, select “Script Only” or “Script and Native”.
    • In your application, after creating an execution context, call JsStartDebugging to put the current context in debug mode. When working with multiple contexts, JsStartDebugging should be called every time a new context is set as current context.
    • Debug the script!

    Summary

    We are excited to share some of the JSRT features that have been long completed – rental threading, script serialization, memory & CPU throttling, and the more recent Edge JSRT specific updates – availability in Universal Windows Applications, native UWP access and ECMAScript 6 language support. These changes put together make Chakra a great option to add scriptability to applications and services running on Windows10.

    The JSRT APIs with all features mentioned above are available in the latest Windows 10 Insider Preview and Windows SDK, which can be download from here. A sample Universal Windows application and the JSRT API documentation are resources that might be helpful to get started. We are eager to see applications use Chakra for scriptability and would love to hear your feedback to advance these APIs. You could reach us and share your feedback on Twitter at @MSEdgeDev or on Connect. Thanks!

    Limin Zhu, Program Manager, Chakra Team
    Gaurav Seth, Principal PM Manager, Chakra Team [/quote] Source: http://blogs.windows.com/msedgedev/2...ss-windows-10/

    :)
     
    Brink, May 17, 2015
    #1
  2. Robert Aldwinckle on forums, May 17, 2015
    #2
  3. windows10 default search engine

    is it possible to use chakra core as the default search engine in Windows10 instead of Bing??
     
    ADaleSmith, May 17, 2015
    #3
Thema:

Using Chakra for Scripting Applications across Windows 10

Loading...
  1. Using Chakra for Scripting Applications across Windows 10 - Similar Threads - Using Chakra Scripting

  2. Updates Affecting Applications Across Entire Computer

    in Windows 10 Installation and Upgrade
    Updates Affecting Applications Across Entire Computer: Hello, Ever since I downloaded a large update on September 23rd, all my applications have been experiencing issues. Each application steam, discord, browser will either take a long time to load or when it opens it will all of a sudden stop responding for about a minute. It...
  3. Application Error 0xc000007b And Windows script host can not find script file

    in Windows 10 BSOD Crashes and Debugging
    Application Error 0xc000007b And Windows script host can not find script file: 1 please how do I resolve this issue, any time I try to open several applications it says "The application was unable to start correctly 0xc000007b. Click OK to close the application" 2 please how can I resolve this as well, whenever I start my computer it always show...
  4. Using paid apps across platforms.

    in Microsoft Windows 10 Store
    Using paid apps across platforms.: So, my brother has a game on his computer. My computer is better than his, therefore he wants to use my computer. He has Minecraft and he wants to play it on my computer and play it on his Vr headset. We can't seem to find out on how to install it on my computer. He fully...
  5. Enable Bitlocker by using a script

    in Windows 10 Customization
    Enable Bitlocker by using a script: Hi Everyone, My first post in here, hopefully you can help me out with this simple question. I've been able to create a GPO to deploy a script on all user machines and execute with a Scheduled Task with the use of SYSTEM permissions. Not a logon script etc. It works...
  6. Showing downloaded applications across accounts on the same computer

    in Windows 10 Software and Apps
    Showing downloaded applications across accounts on the same computer: I was just trying to download a game but was getting the same error over and over when trying to do it in different ways. The solution I did was making a new administrative account on the same computer to download it. I was able to download it on that account, and I thought...
  7. Windows 10 update KB4503327 (OS Build 17763.557) breaks application using MS Scripting Control

    in Windows 10 Installation and Upgrade
    Windows 10 update KB4503327 (OS Build 17763.557) breaks application using MS Scripting Control: Hello Folks - I just had my another computer updated with KB4503327 (OS Build 17763.557) which promise to update Security updates to Microsoft Scripting Engine, Internet Explorer, Microsoft Edge, Windows App Platform and Frameworks, Windows Input and Composition After this...
  8. One or more applications are using the iTunes scripting interface.

    in Windows 10 Software and Apps
    One or more applications are using the iTunes scripting interface.: Back when I got Windows 10 I started having this problem with iTunes that I didn't have before with 7. When I go to close iTunes it freezes and then this message pops up, "One or more applications are using the iTunes scripting interface. Are you sure you want to quit? If you...
  9. Bringing asm.js to the Chakra JavaScript engine in Windows 10

    in Windows 10 News
    Bringing asm.js to the Chakra JavaScript engine in Windows 10: Today we're excited to announce that we are moving asm.js to “In Development” at status.modern.ie. Support for asm.js has been one of the top 10 most-requested items at the IE Suggestion Box on UserVoice since we launched it in December. Delivering an interoperable & spec...
  10. Bringing Asm.js to Chakra and Microsoft Edge

    in Windows 10 News
    Bringing Asm.js to Chakra and Microsoft Edge: A couple of months back, we announced that we had started development on Asm.js. Support for Asm.js has been one of the top 10 most-requested items at the Microsoft Edge Developer Suggestion Box on UserVoice since we launched it in December 2014. Since that time, we’ve made...