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. Remove accounts used by other applications in Windows 10 by CMD/Powershell script or...

    in AntiVirus, Firewalls and System Security
    Remove accounts used by other applications in Windows 10 by CMD/Powershell script or...: Hi there!So we're developing an application that works as a background service on Windows in case someone steal your laptop or PC. In order to protect personal information, we need to "remotely" and without the theft intervention, delete those accounts because the theft could...
  3. Remove accounts used by other applications in Windows 10 by CMD/Powershell script or...

    in Windows 10 Gaming
    Remove accounts used by other applications in Windows 10 by CMD/Powershell script or...: Hi there!So we're developing an application that works as a background service on Windows in case someone steal your laptop or PC. In order to protect personal information, we need to "remotely" and without the theft intervention, delete those accounts because the theft could...
  4. Remove accounts used by other applications in Windows 10 by CMD/Powershell script or...

    in Windows 10 Software and Apps
    Remove accounts used by other applications in Windows 10 by CMD/Powershell script or...: Hi there!So we're developing an application that works as a background service on Windows in case someone steal your laptop or PC. In order to protect personal information, we need to "remotely" and without the theft intervention, delete those accounts because the theft could...
  5. Windows 10 tweaker Sophia Script is turned into an application

    in Windows 10 News
    Windows 10 tweaker Sophia Script is turned into an application: Sophia Script, which was formerly known as Windows 10 Setup Script, is a powerful PowerShell script to modify settings of the Windows 10 operating system. The script requires that users go through it to enable or disable the tweaks to avoid future issues when using the...
  6. Powershell Script - Reinstalling Application

    in Windows 10 Support
    Powershell Script - Reinstalling Application: Hoping someone can assist, I'm trying to create a powershell script that uninstalls and then reinstalls an application, the new installer is using an executable file (.exe). I've been able to get the commands to run when opening Powershell as Admin and copying the code in...
  7. Using a "Keycomboout" Script

    in Windows 10 Software and Apps
    Using a "Keycomboout" Script: I got a question about editing a script within a software called Lemur. Thats the code explanation from the manual: keycomboout(target,ctrl,alt,shift,key); Thats my code: keycomboout(0,0,0,1,52); The Software is using the virtual keyboards numbers for the value "key". So I...
  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...