jurassic
jurassic copied to clipboard
Make global function belong to window object
Hello. I have code:
function SetError(_if_gp) {
window.last_error = _if_gp;
}
window.SetError("err#1");
This code works fine in any browser, because all global objects treated as winows properties. Is there anyway to reproduce same behaviour in jurassic library?
I already created new class which represents Window object and which interhited from ObjectInstance
there is my solution:
public class Window : ObjectInstance
{
.......
protected override object GetMissingPropertyValue(string propertyName)
{
var has= _engine.HasGlobalValue(propertyName);
if (has)
{
var v= _engine.GetGlobalValue(propertyName);
return v;
}
....
}
}
Could you not just use this?
scriptEngine.SetGlobalValue("window", scriptEngine.Global);
@Gdocal I did what @paulbartrum has suggested. In navigators, the global object is the window object. Since the global object is created by the engine, I had to define all the methods/properties of the "window" by myself.
Hey i saw you asking this on Jint also, with which engine you think this is accomplished easier?
@KardoseR Both engines can do almost the same things. The principles are the same, they only differ in the code you write to apply them. I am working with both engines, and let developpers choose which one to choose.
@MaitreDede hi are you still working on this? which engine you are using the most as of now?
Hi @KardoseR like I said earlier, I used the simple shortcut scriptEngine.SetGlobalValue("window", scriptEngine.Global);.
My project is in standby mode since a few month, but I coded the ability to choose implementation of javascript engine (Jurassic or Jint) using dependency injection.