I'm writing an app using XULRunner.  We have a set of C++-written
components managing the "Model" part of "Model-View-Controller", and
are using JS and XUL for the View and Controller part of the system.

We have a need to associate XUL elements, JS methods, and similar
information to each model object, and would like these to persist
across accesses to the model.  There are several ways for us to access
model objects from other model objects, and we need to be able to use
the same UI-specific JS properties regardless of how we get there.

We have done a similar thing with DOM nodes, using "node.myProperty =
foo()" and then however we access that particular DOM node, the
myProperty property retains its value.

When we try associating the data we want the same way with our model
objects, we get "cannot modify properties of a wrappednative" errors.

I recall seeing a doc on one of the Mozilla websites that said that JS
is supposed to allow us to do this, it doesn't work in Mozilla yet,
and that it only works with DOM because of a special-purpose hack in
the JS engine to allow it to work.  Are there any suggested
workarounds at this point?

We have thought of using a hash to associate a JS-side object with a C+
+-side model, but we can see that causing memory leaks -- the JS-side
objects will remain in memory as long as the hash does, and they will
hold a reference to the C++-side objects.  We have thought of adding a
readonly attribute to the XPCOM interface and setting it equal to the
JS-side object, but I'm not sure what type would work for the
attribute, or if we could move the JS object back and forth across the
XPCOM interface and retain its full JS capabilities.

_______________________________________________
dev-tech-xpcom mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-xpcom

Reply via email to