Closed Bug 679031 Opened 9 years ago Closed 9 years ago

Expose jsdbg2 Debugger object as an XPCOM component


(Core :: JavaScript Engine, defect)

Not set





(Reporter: jorendorff, Assigned: jorendorff)



(Keywords: dev-doc-complete)


(1 file, 3 obsolete files)

Dave Camp wrote code to do this. It works like so:

  var xpcDebugger = Cc[";1"].getService(Ci.nsIJSDebugger);

The addClass() method modifies the current global, adding a Debugger constructor. Then you can do stuff like:

  var dbg = new Debugger(anyContentWindow);
  dbg.onDebuggerStatement = function (frame) {
      alert("this is your debugger speaking");
  anyContentWindow.setTimeout("debugger;", 0);

We have the code, with some tests even. We can expose this stuff to extension developers for FF8.
Attached patch WIP 1 (obsolete) — Splinter Review
This is what Dave Camp hacked together. I got several useful comments on IRC about the approach, so I'm going to rearrange it completely and post a new patch. :)
Assignee: general → jorendorff
Note that I've updated these tests to work with the new Debugger API (onDebuggerStatement, etc.) in bug 676605. The fixes are still a WIP, but you can find them in my patch queue:
Duplicate of this bug: 677389
Attached patch WIP 2 (obsolete) — Splinter Review
This one passes tests. The new .jsm was one of the IRC recommendations I got.

The other is to move the whole thing under the js/ directory. I think maybe js/components/{ctypes,debugger,reflect}, though I'll do the other two separately.
Attachment #553224 - Attachment is obsolete: true
Attached patch v3 (obsolete) — Splinter Review
I don't know who likes to give reviews and super-reviews on new components like this. Feel free to dodge, as long as there's someone standing behind you.
Attachment #553305 - Attachment is obsolete: true
Attachment #553992 - Flags: superreview?(benjamin)
Attachment #553992 - Flags: review?(ted.mielczarek)
Comment on attachment 553992 [details] [diff] [review]

Please use straight js/debugger. components/ is an unfortunate artifact of directory history we should avoid.
Attachment #553992 - Flags: superreview?(benjamin) → superreview+
I don't want to use js/debugger because that directory name looks like there might be something interesting in there, which would be totally untrue--it's just unloved glue code.

So following tense negotiations on IRC, bsmedberg and I have settled on
js/ductwork/debugger. Seriously.

Later I'll move toolkit/ctypes and toolkit/reflect under js/ductwork, and we can then happily forget about them until the revolution comes.
Carrying forward bsmedberg's sr+.
Attachment #553992 - Attachment is obsolete: true
Attachment #553992 - Flags: review?(ted.mielczarek)
Attachment #554366 - Flags: superreview+
Attachment #554366 - Flags: review?(ted.mielczarek)
Actually it's not quite the same. v4 removes enter/exitNestedEventLoop and eventLoopNestLevel, at dcamp's encouragement.
Comment on attachment 554366 [details] [diff] [review]
v4 - same as v3 but rename js/components to js/ductwork

Review of attachment 554366 [details] [diff] [review]:

::: js/ductwork/
@@ +19,5 @@
> +# the Initial Developer. All Rights Reserved.
> +#
> +# Contributor(s):
> +#  Brian Ryner <>
> +#  Benjamin Smedberg <>

I'm sure you copy-pasted these from somewhere, but you can probably remove the contributors from these new files you're adding, since they're pretty much all yours. Also, change copyright dates to 2011 while you're copy-pasting?

::: js/ductwork/debugger/
@@ +55,5 @@
> +
> +CPPSRCS = \
> +    nsJSDebugger.cpp \
> +    $(NULL)

Two-space indent after line continuations, please.

@@ +64,5 @@
> +    $(NULL)
> +
> +	jsdebugger.jsm \
> +	$(NULL)

Two-space, as above, and please don't use actual tabs in Makefiles except before rule commands where they're required.

@@ +72,5 @@
> +	$(NULL)
> +
> +    DIRS += tests
> +endif

It's not really typical to indent inside conditionals in Makefiles, but I don't have strong feelings against it if you like it.

::: toolkit/components/ctypes/ctypes.jsm
@@ +52,5 @@
> +// Initialize the Debugger object. You do not need to do this yourself.
> +const init = Components.classes[";1"].createInstance(Components.interfaces.nsIJSDebugger);
> +init.addClass();
> +Debugger.util = init;

Is there a reason this has a two-step init? I assume addClass adds Debugger, but why can't it setup its own .util?

Not super-worried about this, this is all awful ductwork that we really ought to rip out and replace with something better.

::: js/ductwork/debugger/nsJSDebugger.cpp
@@ +1,1 @@
> +/* -*-  Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */

Dare to dream and leave off the ns prefix?

::: js/ductwork/debugger/tests/
@@ +44,5 @@
> +include $(DEPTH)/config/
> +
> +MODULE          = test_debugger
> +

You could feasibly move this up a level and just have XPCSHELL_TESTS = tests in js/ductwork/debugger/, which would save us a make invocation.
Attachment #554366 - Flags: review?(ted.mielczarek) → review+
OK, I made all those changes, except that

(In reply to Ted Mielczarek [:ted, :luser] from comment #10)
> Is there a reason this has a two-step init? I assume addClass adds Debugger,
> but why can't it setup its own .util?

I ripped this out in v4.

I'll land this tonight.
I backed it out. The test fails! Which is pretty annoying--it doesn't fail here. I'll look at it tomorrow morning.
Whiteboard: [inbound]
Ted figured it out for me. It was failing only after 'make package', due to a missing manifest entry for an xpt file.

So I added that, confirmed with Try server, and pushed.
Whiteboard: [inbound]
Closed: 9 years ago
OS: Mac OS X → All
Hardware: x86 → All
Resolution: --- → FIXED
Whiteboard: [inbound]
Target Milestone: --- → mozilla9
Version: Other Branch → Trunk
Blocks: 683894
Keywords: dev-doc-needed
Added a doc for the IJSDebugger interface, which strongly recommends not using it.
You need to log in before you can comment on or make changes to this bug.