microsoft / Chakra-Samples

Repository for Chakra JavaScript engine related samples.
MIT License
216 stars 84 forks source link

Using ChakraCore for win 10 UWP apps #26

Closed SrinivasGourarum closed 8 years ago

SrinivasGourarum commented 8 years ago

I was exploring using ChakraCore instead of Chakra for UWP apps. I was doing it to leverage the new JsRT API to parse script as library(https://github.com/agarwal-sandeep/ChakraCore/commit/83b1bcf8221f8691e2c7ee6a01aafd122a6e5da4?diff=unified) which was merged into ChakraCore. After having added the ChakraCore.dll to the project, there were exceptions stating that the below APIs were undefined.

  1. JsSetProjectionEnqueueCallback.
  2. JsProjectWinRTNamespace.
  3. JsStartDebugging.

Is it recommended to use ChakraCore for UWP apps in windows 10? Or should we wait for the features added in ChakraCore to be available on Chakra which I believe happens with OS update?

Also script debugging seems to be not working with ChakraCore!!!

liminzhu commented 8 years ago

Hi @SrinivasGourarum. In general, we currently recommend using Chakra instead of ChakraCore for UWP apps. ChakraCore is the part of Chakra that has no ties with Windows, and as you saw some of the Windows related APIs are missing (winrt/uwp projection, debugging).

Specifically for debugging, our script debugging in Chakra (JsStartDebugging) is PDM-based, so that is not part of ChakraCore as well. However, we are actively working on a new set of debugging APIs in the JSRTDebugging branch. Note that this work is not finished yet and the API shape may change, so be cautious about taking dependencies. Do let us know your thoughts in case you've tried or plan to try the debugging APIs. The parse script as library work you experimented is part of the debugging effort.

Limin

SrinivasGourarum commented 8 years ago

I am assuming that once ChakraCore is released, we can have this feature(parse script as library) with Chakra as well. Meanwhile, in order to make our js files hidden from the user while debugging using Chakra for UWP apps on windows 10, we could replace the content of the js file (which we intend to hide while debugging script) with the base64 string of the serialized byte[].

byte[] serializeBuffer = JsSerializeScript(originalContent, buff, buffsize); string base64Str = Convert.ToBase64String(serializeBuffer);

This way we are able to hide the file from debugging. My question is if someone would be able to re-generate the original content of the file if they are able to access the base64Str? Do we need to have an additional encryption for the file?

We intend to use ChakraCore for older windows versions like windows phone 8.1 and windows 8.1. Having the capability to debug the script and other debugging apis for memory usage will definitely add on to the debugging experience.

liminzhu commented 8 years ago

I am assuming that once ChakraCore is released, we can have this feature(parse script as library) with Chakra as well.

JsParseScriptWithAttributes is in ChakraCore master so you can use it now. For Chakra you might need to wait a little longer for it to be supported in UWP.

Meanwhile, in order to make our js files hidden from the user while debugging using Chakra for UWP apps on windows 10, we could replace the content of the js file (which we intend to hide while debugging script) with the base64 string of the serialized byte[].

byte[] serializeBuffer = JsSerializeScript(originalContent, buff, buffsize); string base64Str = Convert.ToBase64String(serializeBuffer);

JsSerializeScript is not really designed as an encryption method. In fact, I believe if you Convert.FromBase64String(base64Str) to get the byte buffer and then call JsRunSerializedScript with the buffer, Chakra de-serialize and expose the original script to the debugger. So someone can still access the original script if he know what he's doing. JsParseScriptWithAttributes and JsParseScriptAttributeLibraryCode attribute will hide your code from debugger for you. However if you use Chakra in its current state you may need additional encryption.

We intend to use ChakraCore for older windows versions like windows phone 8.1 and windows 8.1. Having the capability to debug the script and other debugging apis for memory usage will definitely add on to the debugging experience.

I'm super glad to hear it! One of our purposes to open-source ChakraCore is to make it available for pre-Windows 10 OS as Chakra.dll is not there. As a quick status update for debugging, currently we have new debugging APIs in a PR against ChakraCore master. Profiling is something we don't have now but it's on our roadmap and we will definitely look into it.

SrinivasGourarum commented 8 years ago

Thanks @liminzhu. We would continue to use Chakra for windows 10 as recommended. I strongly urge you to bring in the api "JsParseScriptWithAttributes" to Chakra as early as possible. This will be useful in hiding host js files from debugging.

Also, is there any tentative timeframe around which we can expect ChakraCore to be released so that we can start taking dependencies?

liminzhu commented 8 years ago

Sorry for the late response @SrinivasGourarum.

Duly noted. we'll work on getting this API into Chakra and Windows. It probably will land in a Win10 insider preview build first, and then in the next windows release.

We are very close to finish release/1.2 for ChakraCore (maybe just in a few weeks). For now you can build from the release/1.2 branch, or use the preview bits from our myget feed.

SrinivasGourarum commented 8 years ago

Thanks @liminzhu. That's good to hear about ChakraCore. We will plan accordingly.