javascript blob

Nov 3, 2014 at 5:59 PM
What method would be best to get a javascript blob object into a .net byte array?
Nov 4, 2014 at 12:12 PM
Hi Pretzelfisch,

The Blob object is part of the Web API. It isn't part of the JavaScript standard, and ClearScript doesn't provide it.

Did you mean ArrayBuffer by any chance?

Nov 7, 2014 at 6:08 PM
I think I can get the blob to a ArrayBuffer, will that map to a byte array?
Nov 10, 2014 at 3:20 AM
Hi again,

Generally speaking, ClearScript doesn't convert script objects to host objects automatically. Instead, it aims to allow hosts to manipulate script objects directly.

Here's a sample class that demonstrates reading bytes from an ArrayBuffer:
internal class ArrayBufferUtil {
    private readonly dynamic createUint8Array;
    public ArrayBufferUtil(ScriptEngine engine) {
        createUint8Array = engine.Evaluate(@"(function (arrayBuffer) {
            return new Uint8Array(arrayBuffer);
    public IEnumerable<byte> ToEnumerable(object arrayBuffer) {
        var uint8Array = createUint8Array(arrayBuffer);
        var length = Convert.ToInt32(uint8Array.length);
        for (var i = 0; i < length; i++) {
            yield return Convert.ToByte(uint8Array[i]);
And here's how you might use this class to provide a printArrayBuffer function for script code:
var util = new ArrayBufferUtil(engine);
engine.Script.printArrayBuffer = new Action<object>(arrayBuffer => {
    var bytes = util.ToEnumerable(arrayBuffer);
    Console.WriteLine(string.Join(",", bytes));
Note that this requires a host-to-engine round trip for each byte. For large buffers a more efficient approach might be to use an encoding such as Base64 to transfer all the data to the host in one hop.

Good luck!
Nov 13, 2014 at 3:21 PM

How to evaluate an expression and validate it using the ClearScript.
Nov 13, 2014 at 3:57 PM

You can call ScriptEngine.Evaluate() to evaluate a script code expression. What kind of validation are you looking for?

Nov 14, 2014 at 5:00 AM
Edited Nov 14, 2014 at 1:20 PM

Expression whether true or false ?? by using if condition.

like a javascript as below.


<a id="demo"></a>
<script> var a=1; var result; if(1==1) { result=true; } else {result=false;} document.getElementById("demo").innerHTML = result; </script> </body>

how can we do this by using ClearScript . And how to give the input by user for the expression ???
Nov 14, 2014 at 12:28 PM
Sure, here's a simple C# example:
using (var engine = new V8ScriptEngine()) {
    if (Convert.ToBoolean(engine.Evaluate("Math.PI > 3.0"))) {
        Console.WriteLine("Pi is greater than 3!");
As you can see, you can pass script expressions to ScriptEngine.Evaluate() and inspect or convert the result as necessary. Note that ClearScript provides access to script engines only; it doesn't process HTML or implement the Web API.

Good luck!
Nov 14, 2014 at 1:10 PM

Thank you. Can you give some example to access the function in CleaeScript as in javaScript like

function myfunction( ){

Nov 14, 2014 at 2:42 PM
Suppose you've defined a JavaScript function like this:
engine.Execute("function myFunction(a, b, c) { return a * b + c; }");
Here are a few ways to execute it from the host and print out the return value:
Console.WriteLine(engine.Script.myFunction(1, 2, 3));
Console.WriteLine(engine.Script["myFunction"](4, 5, 6));
Console.WriteLine(engine.Invoke("myFunction", new object[] { 7, 8, 9 }));
Nov 17, 2014 at 9:11 AM
Hi ,

How can we give input from user for the expression .

Thank you.
Nov 17, 2014 at 3:22 PM
Please elaborate. How are you gathering user input? How is it represented? How would you like to use it from script code?
Nov 18, 2014 at 10:04 AM

I have records with single field stored in list in a class i.e., name of person . Now i need to give the input expression to evaluate , and this input expression need to check for the records in list.

example :

Name is : siva
Name is : kumar

these are present in list, now we will give input expression name='siva' .

WriteLine("Enter input");
var input = ReadLine();

var result = engine.Evaluate(input = list.ToString());


Thank you .
Nov 18, 2014 at 12:40 PM
Edited Nov 18, 2014 at 12:41 PM

Sorry, still not clear:

var input = ReadLine();

var result = engine.Evaluate(input = list.ToString());

Are you expecting the user to enter the script to be executed? Or is the user typing in some data for the script to process?

Nov 19, 2014 at 9:39 AM
user is typing in some data for the script to process.
        using (var engine = new V8ScriptEngine())
            WriteLine("Enter input");
            var input = ReadLine(); 

            foreach (PersonList person in list)
             var output= engine.Evaluate((input) = (;
input is typing by user some data for the script to process i.e., name="siva"

Nov 19, 2014 at 1:40 PM
OK, it looks like you're trying to pass input and to a script function or expression.

If that's correct, there are many ways to do that. Several were already demonstrated (see the myFunction samples above).

Another possibility, if all the arguments are strings, is to insert the arguments into the script code itself:
engine.Evaluate(string.Format("myFunction('{0}', '{1}')", input,;
Good luck!
Nov 20, 2014 at 6:51 AM

Yes we are not also passing the input and but also comparing the them i.e., comparing the input to the list( .

Nov 20, 2014 at 3:06 PM
Hi nsivakumarreddy,

No matter what kind of data you need to pass to your script, you should be able to use one of the patterns above.

Please let us know if you have other questions.

Thank you!