RE: PLEASE HELP, PLEASE PRETTY PLEASE

"Snider, Sean" <[email protected]> Sat, 14 Dec 2002 17:51:33 -0800
Newsgroups gmane.comp.mozilla.devel.xpcom
Message-ID <[email protected]>
Thanks John:

I apologize for the lame subject line , just trying to get a response
(which sometimes can be tough), it won't happen again ;-).

Anwyay, okay I understand about the thread stuff now. . .thanks so much
for your help.

But as far as the wrappedJSObject stuff goes. .  I don't see how any of
the samples you pointed out apply.  (Of course I could just be missing
the point completely :)).  

The comments at
http://lxr.mozilla.org/seamonkey/source/js/src/xpconnect/idl/nsIXPConnec
t.idl#234

Seem to be more about a method of doing reflection on an XPCom component
that is written JS. (I.E so that you can enumerate the supposed methods
and properties of a particular component).  This is something that I was
unaware of and is useful, but doesn't really solve my problem.

So then I had a look at:
http://lxr.mozilla.org/seamonkey/source/modules/plugin/samples/4x-script
able/script-test.html#17

Which seemed to be more about what I was looking for.  In turn I changed
my code to look like this:

<script>
	function jsScriptObject(obj)
	{
	    // implementation detail, to allow unwrapping.
	    this.wrappedJSObject = obj;
	}
	jsScriptObject.prototype = {
	    getProperty : function(name)
	    {
	        return new jsScriptObject(this.wrappedJSObject[name]);
	    }
	    ,
	    setProperty : function(name, value)
	    {
	        this.wrappedJSObject[name] = value;
	    }
	    ,
	    evaluate : function(expression)
	    {
	        return new jsScriptObject(eval(expression));
	    }
	    ,
	    toString : function()
	    {
	        return this.wrappedJSObject.toString();
	    }
	    ,
	    toNumber : function()
	    {
	        return this.wrappedJSObject.valueOf();
	    }
	    ,
	    fromString : function(value)
	    {
	        return new jsScriptObject(value);
	    }
	    ,
	    fromNumber : function(value)
	    {
	        return new jsScriptObject(value);
	    }
	 };

	function testNSISupportsArray()
	{
		netscape.security.PrivilegeManager
			.enablePrivilege("UniversalXPConnect");
				
				
		const nsISupportsArray =
Components.interfaces.nsISupportsArray;
				
		var x =
Components.classes["@mozilla.org/supports-array;1"]
			.createInstance(nsISupportsArray);

		var t = new Object();
		t.sean = "snider";
		var y = new jsScriptObject(t);
				
		x.AppendElement(y);
				
		var z = x.GetElementAt(0);
				
		//NOW I should be able to access the properties I set in

		//y (z) through the wrapper methods
(~z.getProperty("sean"))
				
		alert(z); //still displays [xpconnect wrapper
nsISupports]!!
		alert(z.getProperty("sean")); //ERROR!!!!!!!!!
		/*
		Error: z.getProperty is not a function
		Source File:
file:///C:/Documents%20and%20Settings/ssnider/Desktop/test_bitwise.html
		Line: 68
		*/

///***********AAAAAAAARRRRRRRRRRGH!!!!!!!!!!!!!!!!!!************//
	};	
</script>
 
If you look the code I still have the same problem.  Basically I am
trying to hand a JS Object to an XPCom component (regardles of how the
component is implemented in C or JS) and the return that same JS Object
back out.  

Again, perhaps I am just not doing something correctly, can you tell
what I am doing wrong?

And again thanx a lot of the help. . . 

Sean Snider
Software Engineer I
604-456-3429
[email protected] 

-----Original Message-----
From: John Bandhauer [mailto:[email protected]] 
Sent: Saturday, December 14, 2002 4:10 PM
To: [email protected]
Subject: Re: PLEASE HELP, PLEASE PRETTY PLEASE

[from a previous anwser to this question...]

Read closely the rambling comment at:
http://lxr.mozilla.org/seamonkey/source/js/src/xpconnect/idl/nsIXPConnec
t.idl#234

And look at a couple of examples in .js and .html files here:
http://lxr.mozilla.org/seamonkey/search?string=wrappedJSObject

BTW, When asling for help, it is more polite to post with a 
subject line that suggests what you want rather than how much you 
want it. I expected to see spam based on the subject line but 
looked anyway.

John.

Sean wrote:
> Can someone tell me how to unwrap a JSObject that I pass into
> XPCom/XPConnect
> 
> For example: 
> 
>
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect")
;
> 
> 
> const nsISupportsArray = Components.interfaces.nsISupportsArray; 
> 
> var x =
Components.classes["@mozilla.org/supports-array;1"].createInstance(nsISu
pportsArray);
> 
> var y = new Object(); 
> y.foo = "Hello XPConnect!"; 
> 
> x.Append(y); 
> 
> //NOW I WANT TO GET MY OBJECT BACK!!! 
> 
> var z = x.GetElementAt(0); 
> 
> alert(z) //displays [xpconnect wrapper nsISupports] 
> alert(z.foo) //undefined ?????????? WHY???????? 
> 
> Thanx 
> Sean 
> [email protected]