Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

Commented Unassigned: ClearScript not finding function added dynamically to window object [31]

0
0
ClearScript apparently can't find a function added dynamically to the window object.

In a regular html file, I can call "var passwordAnalysis = zxcvbn($(this).val(), penalties);" just fine.

However, I am trying to execute https://raw.github.com/lowe/zxcvbn/master/zxcvbn.js inside a C# project.

I always get the exception:

ScriptEngineException: TypeError: Method or property not found.

I suspect it is because the zxcvbn method is added dynamically.

C# Code is as follows:

using Microsoft.ClearScript;
using Microsoft.ClearScript.V8;

public class RunScripts
{
public void GetPasswordStrength(string password, string[] penalties)
{
using (var engine = new V8ScriptEngine())
{
engine.Execute(ZxcvbnScript);

var result = engine.Script.zxcvbn(password, penalties);
//or
var result = engine.Script.zxcvbn(password);
//or
var result = engine.Script.zxcvbn(password);
}
}
}
Comments: I had actually moved to using an ExpandoObject to add the host object, but not adding a host object at all is even better. Thanks for the tip!

Viewing all articles
Browse latest Browse all 2297

Latest Images

Trending Articles





Latest Images