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

Allow "Await Debugger" in V8 at any time, rather than just on startup #121

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

grumpydev
Copy link

In our application we execute a lot of global/system scripts before we get to the "user" scripts, and most of the time its only those later scripts that we care about debugging, and normally only specific methods inside those user scripts, so pausing execution on startup is a little "heavy handed". Currently I am working around this by manually poking the flag in the V8ScriptEngine with reflection:

                var field = engine.GetType().GetField("awaitDebuggerAndPause",
                    BindingFlags.NonPublic | BindingFlags.Instance);

                field.SetValue(engine, true);

This works fine, but thought it would be nice to make this a supported thing to do, so this PR adds a single method to V8ScriptEngine that lets you set this flag on demand. Its a method rather than just setting the property directly because using a property setter feels like the caller has the responsibility to flip it back afterwards, but the script engine does that itself on next execution.

I haven't added any tests for this because I couldn't see how (other than changing the visibility of the field, which felt icky), but its only a 3 line method so hopefully that's ok :)

@grumpydev
Copy link
Author

It also appears that using "Invoke" doesn't check or use the awaitDebuggerAndPause flag, which means I have to "wrap" executing the function and use Execute, from looking at the code I can't see any reason why adding this in would cause problems, I'll do so if you think its ok?

@ClearScriptLib
Copy link
Collaborator

Hi @grumpydev,

Thanks for your contribution!

It also appears that using "Invoke" doesn't check or use the awaitDebuggerAndPause flag

Quite correct. In fact, ClearScript provides many ways to enter V8's interpreter, and most of them do not honor that flag. Exposing it may work in your scenario, but there may be a more robust and generally useful way to provide the behavior you're looking for. We'll take a look.

Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants