Karl Dahlke <[email protected]> writes:

> The guide talks about local variables, parameters, returns,
> heap, but nothing about global or static.

Ok, here's my suggestion.
Actually I've been implementing it along with my other work on html.cpp
and buffers.c.
Let's get rid of the global jwin altogether.
It duplicates the data in cw->jsw.  There's always going to be
a current edbrowse window, and that window's jsc and jsw should never go
out of sync with the globals jcx and jwin.
Instead of the globals, let's pack all of this JS stuff into an opaque
struct on the heap, with a pointer stored in ebWindow, like so:

/* file eb.h */
/* Forward decl, fully declared in js.h. */
struct ebJSState;

struct ebWindow {
...
    struct ebJSState *jsstate;
/* Struct is opaque outside js-related files. */
};

/* File js.h */
struct ebJSState {
    JSContext *jcx;
    jS::Heap<JSObject *> jwin;
    JS::Heap<JSObject *> jdoc;
};

So now jdoc and jwin are rooted.

We could keep using the jdoc and jwin globals, and use JS_AddObjectRoot
to root them, but I think the opaque struct is the safest bet.  It also
eliminates void pointers.
The jcx global is ok, but I'd argue for getting rid of it as well, since
it just duplicates the JSContext * from the current window.


-- Chris
_______________________________________________
Edbrowse-dev mailing list
[email protected]
http://lists.the-brannons.com/mailman/listinfo/edbrowse-dev

Reply via email to