Hi Jan,
Thank you so much for the response. I've played with it a bit, and so far the
results are encouraging!
Just in case somebody needs to do something similar, this is my first attempt
code that works on a couple of smaller examples (but i still have to check,
tweak and improve it).
Once again, thank you!
RootedId fcID(cx, NameToId(cx->names()._FC_ID));
RootedValue fcIdValue(cx);
fcIdValue.setInt32(1);
RootedObject metaObject(cx, NewDenseEmptyArray(cx)); //change to object creation
RootedObject rootedJsObject(cx, jsObject);
baseops::SetPropertyHelper<SequentialExecution>(cx, metaObject, metaObject,
fcID, baseops::Qualified, &fcIdValue, true);
js::SetObjectMetadata(cx, rootedJsObject, metaObject);
Then later the value can be obtained with:
RootedObject metaObject(cx, js::GetObjectMetadata(obj));
if(metaObject != nullptr)
{
RootedId fcID(cx, NameToId(cx->names()._FC_ID));
RootedValue fcIdValueRooted(cx);
JSObject::getGeneric(cx, metaObject, metaObject, fcID, &fcIdValueRooted);
fcIdValueRooted.toInt32(); //get id
}
On Thursday, August 21, 2014 12:23:11 PM UTC+2, Jan de Mooij wrote:
> Hi Josip,
>
>
>
> In newer versions of SpiderMonkey you can use the object metadata callback.
>
> This allows you to associate extra data (like an ID) with an object when
>
> it's allocated. The JS shell has some testing functions
>
> (setObjectMetadataCallback, getObjectMetadata, setObjectMetadata) in
>
> builtin/TestingFunctions.cpp that show you how you can use them.
>
>
>
> The default ShellObjectMetadataCallback stores an ID + stack trace for each
>
> object, you could do something like that and then call
>
> GetObjectMetadata(JSObject*) to get the metadata when you need it.
>
>
>
> Jan
>
>
>
>
>
> On Thu, Aug 21, 2014 at 11:49 AM, Josip Maras <[email protected]> wrote:
>
>
>
> > Hi,
>
> >
>
> > I'm trying to use Firefox to do some dynamic analysis with the end goal of
>
> > creating a dependency graph for a particular execution (
>
> > http://marjan.fesb.hr/~jomaras/documents/IdentifyingCodeofIndividualFeaturesinClientsideWebApplications.pdf
>
> > ).
>
> >
>
> > To do this, I would like to assign a unique ID to each object created
>
> > during script execution. I've tried extending JsObject, ObjectImpl with an
>
> > additional ID property, but this always fails - it takes me down a rabbit
>
> > hole filled with compiler errors, assertion fails, and runtime errors (this
>
> > is most likely due to my inexperience with such advanced c++ code).
>
> >
>
> > I would be extremely grateful if someone could provide some points on what
>
> > is an OK way to add a unique ID to each created object. Ideally, this ID
>
> > should be accessible in the main interpreter loop, so that i can establish
>
> > dependencies when an object's property is accessed, when an object is used
>
> > as a function context, etc.
>
> >
>
> > Thank you!
>
> >
>
> > Josip
>
> > _______________________________________________
>
> > dev-tech-js-engine-internals mailing list
>
> > [email protected]
>
> > https://lists.mozilla.org/listinfo/dev-tech-js-engine-internals
>
> >
_______________________________________________
dev-tech-js-engine-internals mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-internals