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

Make global function belong to window object #102

Open
Gdocal opened this issue Jun 7, 2017 · 7 comments
Open

Make global function belong to window object #102

Gdocal opened this issue Jun 7, 2017 · 7 comments
Labels

Comments

@Gdocal
Copy link

Gdocal commented Jun 7, 2017

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

@Gdocal Gdocal closed this as completed Jun 7, 2017
@Gdocal Gdocal reopened this Jun 7, 2017
@Gdocal
Copy link
Author

Gdocal commented Jun 7, 2017

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;
            }
             ....
       }
}

@paulbartrum
Copy link
Owner

Could you not just use this?

scriptEngine.SetGlobalValue("window", scriptEngine.Global);

@maitredede
Copy link

@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.

@KardoseR
Copy link

KardoseR commented Jul 5, 2017

Hey i saw you asking this on Jint also, with which engine you think this is accomplished easier?

@maitredede
Copy link

@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.

@KardoseR
Copy link

@maitredede hi are you still working on this? which engine you are using the most as of now?

@maitredede
Copy link

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.

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

4 participants