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: Ok, I don't think this is actually a problem with ClearScript - it occurs to me that this is probably "just" a javascript engine, and does not include an implementation of the DOM. I was actually able to run the script like I wanted with a very simple modification: public class JsWindow { public object zxcvbn { get; set; } } public class RunScripts { using (var engine = new V8ScriptEngine()) { engine.AddHostObject("window", HostItemFlags.GlobalMembers, new JsWindow()); engine.Execute(ZxcvbnScript); var result = engine.Script.zxcvbn(password, penalties); } }

Viewing all articles
Browse latest Browse all 2297

Latest Images

Trending Articles





Latest Images