Hello All,
I have been experiencing some difficulties in using spidermonkey to generate
a proper hierarchy between different Objects.
I first Create a global Object and Initailize all the standard classes.
glob = JS_NewObject(cx, &base_class, NULL, NULL);
if (!glob)
return 1;
if (!JS_InitStandardClasses(cx, glob))
return 1;
Then I use javascript to create a child Object called application in the
global object.
strcpy(scripttext, "var application = new Object()" );
if (!JS_EvaluateScript(cx, glob, scripttext, strlen(scripttext), NULL,
NULL, &result0))
return 1;
Then i Create a new Object called document as the child of application
object.
strcpy(scripttext, "var document = new Object()" );
if (!JS_EvaluateScript(cx, application, scripttext, strlen(scripttext),
NULL, NULL, &result0))
return 1;
Now if i try to Get the parent of the document object it is the global
object and not the applicatoin object as it should be.
j12 = JS_GetParent(cx, dialog);
if (j12 == application)
printf("The Parent is Correct");
if (j12 == glob)
printf("The Parent is incorrect ");
If However, I explicitly set the parent of the document object using
JS_SetParent(cx, document, application);
Then the correct parent is application not global object as it should be.
Can anyone explain this? Is this a known bug or am i doing something wrong.
Thanks,
Rahul