Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: Transfer object as JavaScript object


You're already doing the right thing by using JSON to minimize hops across the .NET-V8 boundary.

Your next optimization might be to minimize your use of V8's JavaScript parser. To that end, consider wrapping someFunc in a helper that takes a JSON string and converts it via the JSON object:
dynamic someFuncHelper = Engine.Evaluate(@"
    (function (json) {
        return someFunc(JSON.parse(json));
Then, simply do this:
// Engine.Evaluate("someFunc(" + json + ")");
This way you're using an efficient, dedicated JSON parser to convert your object instead of V8's general-purpose JavaScript parser, which is much more complex. Don't forget to cache and reuse someFuncHelper to avoid re-parsing and recompiling the wrapper.

Good luck!

Viewing all articles
Browse latest Browse all 2297