Loading XPCOM component give TypeError in Linux Fedore Core 4, Firefox 1.5

RESOLVED INCOMPLETE

Status

()

Core
XPCOM
--
critical
RESOLVED INCOMPLETE
12 years ago
5 years ago

People

(Reporter: Susan Crayne, Unassigned)

Tracking

1.8 Branch
Other
Linux
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(URL)

(Reporter)

Description

12 years ago
User-Agent:       Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)
Build Identifier: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.4)

I am attempting to build the sample XPCOM from the website: http://www.iosart.com/firefox/xpcom/. It compiles, links, and executes in Firefox 1.5 on a Windows XP platform, using the Gecko 1.8b1 libraries. On Linux (Fedora Core 4), it compiles and links but an attempt to execute this Javascript line (In Firefox 1.5): 
obj = Components.classes[cid].createInstance(); 
fails with: 
TypeError: Components.classes[cid] has no properties. 
xpti.dat contains references to the component; compreg.dat does not. I have run ldd on the shared library and there appear to be no outstanding dependencies. This XPCOM was previously built with an earlier version of the Gecko library, and ran successfully under Firefox 1.07 on the same system.


Reproducible: Always

Steps to Reproduce:
1.Create Header and Typelib files
2.Compile, link, and copy XPCOM to component directory.
3. Open MyComponentTest.html and click on "GO" button

Actual Results:  
Alert box:  TypeError: Components.classes[cid] has no properties. 


Expected Results:  
alert box:  3+4=7

Header compilation script:
./xpidl -v -m header -I gecko-sdk-linux-1.8b1/idl  IMyComponent.idl
*****************************************
Typelib compilation script:
./xpidl -m typelib -I gecko-sdk-linux-1.8b1/idl IMyComponent.idl
*****************************************

IDL file (IMyComponent.idl):
#include "nsISupports.idl"

[scriptable, uuid(69B5C954-29F8-4bd6-932F-3304B18D4DA1)]
interface IMyComponent : nsISupports
{
  long Add(in long a, in long b);
};
*****************************************
Header generated from idl file (IMyComponent.h)
/*
 * DO NOT EDIT.  THIS FILE IS GENERATED FROM IMyComponent.idl
 */

#ifndef __gen_IMyComponent_h__
#define __gen_IMyComponent_h__


#ifndef __gen_nsISupports_h__
#include "nsISupports.h"
#endif

/* For IDL files that don't want to include root IDL files. */
#ifndef NS_NO_VTABLE
#define NS_NO_VTABLE
#endif

/* starting interface:    IMyComponent */
#define IMYCOMPONENT_IID_STR "69b5c954-29f8-4bd6-932f-3304b18d4da1"

#define IMYCOMPONENT_IID \
  {0x69b5c954, 0x29f8, 0x4bd6, \
    { 0x93, 0x2f, 0x33, 0x04, 0xb1, 0x8d, 0x4d, 0xa1 }}

class NS_NO_VTABLE IMyComponent : public nsISupports {
 public: 

  NS_DEFINE_STATIC_IID_ACCESSOR(IMYCOMPONENT_IID)

  /* long Add (in long a, in long b); */
  NS_IMETHOD Add(PRInt32 a, PRInt32 b, PRInt32 *_retval) = 0;

};

/* Use this macro when declaring classes that implement this interface. */
#define NS_DECL_IMYCOMPONENT \
  NS_IMETHOD Add(PRInt32 a, PRInt32 b, PRInt32 *_retval); 

/* Use this macro to declare functions that forward the behavior of this interface to another object. */
#define NS_FORWARD_IMYCOMPONENT(_to) \
  NS_IMETHOD Add(PRInt32 a, PRInt32 b, PRInt32 *_retval) { return _to Add(a, b, _retval); } 

/* Use this macro to declare functions that forward the behavior of this interface to another object in a safe way. */
#define NS_FORWARD_SAFE_IMYCOMPONENT(_to) \
  NS_IMETHOD Add(PRInt32 a, PRInt32 b, PRInt32 *_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->Add(a, b, _retval); } 

#if 0
/* Use the code below as a template for the implementation class for this interface. */

/* Header file */
class _MYCLASS_ : public IMyComponent
{
public:
  NS_DECL_ISUPPORTS
  NS_DECL_IMYCOMPONENT

  _MYCLASS_();

private:
  ~_MYCLASS_();

protected:
  /* additional members */
};

/* Implementation file */
NS_IMPL_ISUPPORTS1(_MYCLASS_, IMyComponent)

_MYCLASS_::_MYCLASS_()
{
  /* member initializers and constructor code */
}

_MYCLASS_::~_MYCLASS_()
{
  /* destructor code */
}

/* long Add (in long a, in long b); */
NS_IMETHODIMP _MYCLASS_::Add(PRInt32 a, PRInt32 b, PRInt32 *_retval)
{
    return NS_ERROR_NOT_IMPLEMENTED;
}

/* End of implementation class template. */
#endif


#endif /* __gen_IMyComponent_h__ */
*****************************************
makefile:
CXX   = c++
CPPFLAGS +=     -fno-rtti              \
		-fno-exceptions        \
		-shared  
 
# Change this to point at your Gecko SDK directory. 
GECKO_SDK_PATH = gecko-sdk-linux-1.8b1
 
# GCC only define which allows us to not have to #include mozilla-config 
# in every .cpp file.  If your not using GCC remove this line and add 
# #include "mozilla-config.h" to each of your .cpp files. 
GECKO_CONFIG_INCLUDE = -include mozilla-config.h 
 
GECKO_DEFINES  = -DMOZILLA_STRICT_API -DIMYCOMPONENT_EXPORTS -DLINUX -g3
 
GECKO_INCLUDES = -I $(GECKO_SDK_PATH)/include 
 
GECKO_LDFLAGS =  -L $(GECKO_SDK_PATH)/lib -L $(GECKO_SDK_PATH)/bin -L/usr/lib -lxpcomglue_s \
                 -lnspr4      \
                 -lplds4  -libmeci   

FILES = MyComponent.cpp MyComponentModule.cpp 
 
TARGET = libMyComponent.so

build: 
	$(CXX) -Wall -Os -o $(TARGET) $(GECKO_CONFIG_INCLUDE) $(GECKO_DEFINES) $(GECKO_INCLUDES) $(GECKO_LDFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(FILES)
	chmod +x $(TARGET)

clean: 
	rm $(TARGET)
*****************************************
MyComponent.cpp:
#include "MyComponent.h"

NS_IMPL_ISUPPORTS1(MyComponent, IMyComponent)

MyComponent::MyComponent()
{
  /* member initializers and constructor code */
}

MyComponent::~MyComponent()
{
  /* destructor code */
}

/* long Add (in long a, in long b); */
NS_IMETHODIMP MyComponent::Add(PRInt32 a, PRInt32 b, PRInt32 *_retval)
{
	*_retval = a + b;
	return NS_OK;
}
*****************************************
MyComponent.h:
#ifndef _MY_COMPONENT_H_
#define _MY_COMPONENT_H_

#include "IMyComponent.h"

#define MY_COMPONENT_CONTRACTID "@mozilla.org/accessibilityWorks/MyComponent;1"
#define MY_COMPONENT_CLASSNAME "A Simple XPCOM Sample"

// {0929D734-8B93-45cb-8B87-07D350A9B52F}
#define MY_COMPONENT_CID { 0x929d734, 0x8b93, 0x45cb, { 0x8b, 0x87, 0x7, 0xd3, 0x50, 0xa9, 0xb5, 0x2f } }

/* Header file */
class MyComponent : public IMyComponent
{
public:
  NS_DECL_ISUPPORTS
  NS_DECL_IMYCOMPONENT

  MyComponent();
  virtual ~MyComponent();
  /* additional members */
};


#endif //_MY_COMPONENT_H_
*****************************************
MyComponentModule.cpp:
#include "nsIGenericFactory.h"
#include "MyComponent.h"

NS_GENERIC_FACTORY_CONSTRUCTOR(MyComponent)

static nsModuleComponentInfo components[] =
{
    {
       MY_COMPONENT_CLASSNAME, 
       MY_COMPONENT_CID,
       MY_COMPONENT_CONTRACTID,
       MyComponentConstructor,
    }
};

NS_IMPL_NSGETMODULE("MyComponentsModule", components) 
*****************************************
MyComponentTest.html:
<HTML>
<SCRIPT>
function MyComponentTestGo() {
	try {
		netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
		const cid = "@mozilla.org/accessibilityWorks/MyComponent;1";
		obj = Components.classes[cid].createInstance();
		alert("In MyComponentTestGo, created Instance");
		obj = obj.QueryInterface(Components.interfaces.IMyComponent);
		alert("In MyComponentTestGo, did QueryInterface");
	} catch (err) {
		alert("In MyComponentTestGo, " + err);
		return;
	}
	var res = obj.Add(3, 4);
	alert('Performing 3+4. Returned ' + res + '.');
}

</SCRIPT>
<BODY>
<BUTTON ONCLICK="MyComponentTestGo();">Go</BUTTON>
</BODY>
</HTML>
(Reporter)

Comment 1

12 years ago
I was able to work around this problem by compiling Firefox and using the Gecko sdk from that compile.  The version I compiled was:

http://ftp.mozilla.org/pub/mozilla.org/firefox/releases/1.5.0.1/source/

So this should be a simple matter of replacing the sdk in 

gecko-sdk-i686-pc-linux-gnu-1.8b1.tar.gz 

with this one, assuming that the version I compiled works with other Linuxes as well.

Susan
(Reporter)

Comment 2

12 years ago
When I recompiled the Gecko SDK and used it to link my XPCOM, I still got the TypeError, but the XPCOM worked.  So the TypeError is due to something else entirely.  Previously, I got the TypeError, AND the createInstance() failed.
Component: General → XPCOM
Product: Firefox → Core
Version: unspecified → 1.8 Branch
QA Contact: general → xpcom
Is this still an issue in Firefox 3.5?

If it is not, we should set the resolution of the bug to WORKSFORME.
no response
Status: UNCONFIRMED → RESOLVED
Last Resolved: 5 years ago
Resolution: --- → INCOMPLETE
You need to log in before you can comment on or make changes to this bug.