Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ScriptEngine.GetGlobalValue #217

Closed
ertant opened this issue Jul 8, 2022 · 1 comment
Closed

ScriptEngine.GetGlobalValue #217

ertant opened this issue Jul 8, 2022 · 1 comment
Labels

Comments

@ertant
Copy link

ertant commented Jul 8, 2022

Hi, ScriptEngine.GetGlobalValue method throws an JavaScriptException instead of null value for undefined values. I'm not sure is this normal but GetGlobalValue method documentation says "The value of the global variable, or null otherwise."

In method TypeConverter.ToObject(ScriptEngine engine, Object value) value is set to Undefined.Value.

Exception stack.

object
at Jurassic.TypeConverter.ToObject(ScriptEngine engine, Object value, Int32 lineNumber, String sourcePath, String functionName)
at Jurassic.TypeConverter.ToObject(ScriptEngine engine, Object value)
at Jurassic.TypeConverter.ConvertTo(ScriptEngine engine, Object value, Type type)
at Jurassic.TypeConverter.ConvertTo[T](ScriptEngine engine, Object value)
at Jurassic.ScriptEngine.GetGlobalValue[T](String variableName)

Workaround;

Calling Engine.GetGlobalValue("foo") as T resolves the problem instead of using the Engine.GetGlobalValue("foo")

@paulbartrum
Copy link
Owner

The doc comment is wrong, GetGlobalValue() never returns null. It normally won't throw though. The only time it should throw is if you call GetGlobalValue<ObjectInstance>() since undefined cannot be converted to an object (whereas it can be converted to a boolean, number or string).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants