Javascript error typeerror components.classes[cid] is undefined

javascript error typeerror components.classes[cid] is undefined

Hi Could you please help me " Instantiate JavaScript XPCOM Component from C++ XPCOM Component/ C++ Code" I have tried one same code given below. HellowWorld.js. Re: TypeError: Components.classes[TvtPwmComponent_CID] is undefined. I have a T400. I use firefox and have been getting this error message since FF last. Javascript Application pop up error on website load after page is loaded saying: TypeError: Components.classes[cid] is undefined.

Javascript error typeerror components.classes[cid] is undefined - assured, what

Oke, Sob kali ini tutorial Jagoan Hosting membahas permasalahan Error Undefined Index/Variable. Pasti sekarang kamu lagi main-main sama bahasa pemrograman PHP kan?

Nah di PHP itu ada dua jenis method yaitu $_POST dan $_GET. Kedua method ini biasanya digunakan untuk mendapatkan value dari user melalui sebuah form. Ketika pakai method ini biasanya muncul deh error bernama Notice: Undefined Index

Beberapa Penyebab

1) Pada beberapa server pengambilan $_GET secara langsung jika valuenya kosong dapat menimbulkan error.

2) Karena nama variabel yang kita sebutkan pada baris yang muncul saat error tidak dikenal.

 

Error Undefined Index

Undefined index istilahnya adalah sebuah 'notice' atau pemberitahuan (termasuk level ringan jika dibanding Warning), jenisnya seperti ini:

“Notice: Undefined variable”,

“Notice: Undefined index” dan “Notice: Undefined offset”.

Nah karena skala levelnya ringan, maka ada dua cara untuk mengatasi 'notice' tersebut:

1) Abaikan saja noticenya

2) Perbaiki noticenya

 

Cara Mengabaikan Notice: Undefined Index

Kamu bisa mengabaikan informasi ini dengan menggunakan fitur error_reporting. Ide besarnya adalah men-setting error_reporting menjadi E_ALL & ~E_NOTICE.

1) php.ini

Kalo kamu hosting di Jagoanhosting kamu bisa mengubah error_reporting menjadi E_ALL & ~E_NOTICE dengan menggunakan panduan mengubah konfigurasi PHP 

Cara lain adalah edit file php.ini di hosting kamu, cari "error_reporting" defaultnya biasanya E_ALL nah itu diganti jadi E_ALL & ~E_NOTICE.

Contoh default:

error_reporting = E_ALL

Ganti ke:

error_reporting = E_ALL & ~E_NOTICE

Sekarang yang tampil adalah semua error kecuali level 'Notice'.

 

2) Coding PHP

Kalau kamu gak ada akses ke php.ini, kamu tetep bisa mengabaikan error tersebut dengan menambahkan baris kode kedalam sebuah page php tersebut.

<?php error_reporting (E_ALL ^ E_NOTICE); ?>

Sekarang yang tampil adalah semua error kecuali level 'Notice'.

 

Cara Memperbaiki Notice: Undefined Index

Jenis error ini muncul di method $ _POST dan $ _GET, ketika kamu pakai index atau variabel yang belum diset dikedua method tadi, tapi kamu udah pakai valuenya di kode PHPmu.

Contoh:

Di contoh ini kita pakai dua variabel 'nama' dan 'umur' tapi yang di masukkan cuma value 'nama' melalui method $_GET, itu kenapa akhirnya muncul error

http://namadomain.com/index.php?nama=rama

<?php $nama = $_GET['nama']; $umur = $_GET['umur']; echo $nama; echo $umur; ?>

Output:

Notice: Undefined index: umur \index.php on line 5

Solusi:

Untuk mengatasi error tersebut kamu bisa menggunakan fungsi isset() , ini contohnya berdasarkan contoh error baris kode diatas.

http://namadomain.com/index.php?nama=rama

<?php if(isset($_GET['nama'])){ $nama = $_GET['nama']; }else{ $nama = "Nama tidak diset di Method GET"; } if(isset($_GET['umur'])){ $umur = $_GET['umur']; }else{ $umur = "<br>Umur tidak diset di Method GET "; } echo $nama; echo $umur; ?>

Output:

rama Umur tidak diset di Method GET

 

Setting Blank Index

Pendekatan lain dengan sengaja setting dengan blank index, contohnya seperti ini:

// contoh menggunakan $_POST $name = isset($_POST['nama']) ? $_POST['nama'] : ''; $name = isset($_POST['umur']) ? $_POST['umur'] : ''; // contoh menggunakan $_GET $name = isset($_GET['nama']) ? $_GET['nama'] : ''; $name = isset($_GET['umur']) ? $_GET['umur'] : '';

 

Cara Memperbaiki Notice: Undefined Variable

Pemberitahuan atau 'notice' ini muncul ketika kamu pakai variabel di PHP tapi belum kamu set valuenya.

Contoh:

<?php $name='RAMA'; echo $nama; echo $umur; ?>

Output:

Notice: Undefined variable: umur in namadomain.com\index.php on line 7

Contoh diatas kita menampilkan value yang disimpan di 'nama' dan 'umur' tapi kita belum set isi variabel 'umur' nya.

Solusi:

Untuk mengatasi error ini, kamu bisa definisikan variabel global dan gunakan fungsi isset() untuk ngecek sudah diset valuenya atau belum.

<?php global $nama; global $umur; echo $nama; ?> <?php if(isset($nama)){echo $nama;} if(isset($umur)){echo $umur;} ?> <?php // Set Blank Variabel   $nama = isset($nama) ? $nama : ''; $umur= isset($umur) ? $umur: ''; ?>
Triangle) {\ // ... }

The

renderObject function takes an input parameter . , , and are types, and is called the union operator. can be of type , , or . However, the union of shapes cannot be expressed using an interface.

Interfaces are used for defining a contract regarding the shape of an object; hence they cannot be used with the union of multiple shapes. Even a class cannot implement a type that describes a union of shapes. This is one of the important functional differences between interfaces and type alias.

When we define two interfaces with the same name, both of them gets merged into one. The resulting interface will have properties from both the interfaces. However, the compiler will complain if we try to define multiple types with the same name.

Hybrid types in interfaces

In JavaScript, functions are also considered as objects and so it is valid to add properties even on function literals like this:

function manufactureCar (type) { const model = function getModel (type) { console.log('inside getModel function') // get the model of type as mentioned in the argument } model.getCustomerDetails = function () { console.log('inside customer details function') // get the details of customer who has purchased this model } model.price = 100000 model.trackDelivery = function () { console.log('inside trackDelivery function') // track the delivery of the model } return model } let tesla = manufactureCar('tesla') tesla() // tesla is a function tesla.getCustomerDetails() // getCustomerDetails is a property defined on function

As you can see from the above code, the variable is assigned a value of function and , are attached as properties on the . This is a common pattern in JavaScript. How do we define this pattern with TypeScript interfaces?

interface CarDelivery { (string): TeslaModelS, getCustomerDetails (): string, price: number, trackDelivery (): string } function manufactureCar (type: string): CarDelivery { const model = <CarDelivery> function (type: string) { // get the model of type as mentioned in the argument } model.getCustomerDetails = function () { // get the details of customer who has purchased this model return 'customer details' } model.price = 100000 model.trackDelivery = function () { // track the delivery of the model return 'tracking address' } return model } let tesla = manufactureCar('tesla') tesla() // tesla is a function tesla.getCustomerDetails() // getCustomerDetails is a property defined on function

The object of type is returned from the function. The interface helps in maintaining the shape of the object returned from the function. It makes sure that all the mandatory properties of the model — , , and — are present in the model.

How to use generics in interfaces

Generics in TypeScript are used when we have to create generic components that can work on multiple data types. For example, we don’t want to restrict our function to accept only as the input parameter. It should scale as per the use-case and accept a range of types.

Let’s write code for implementing a stack that handles generic data types:

interface StackSpec<T> { (elements: Array<T>): void } function Stack<T> (elements) { this.elements = elements this.head = elements.length - 1 this.push = function (number): void { this.elements[this.head] = number this.head++ } this.pop = function <T>(): T { this.elements.splice(-1, 1) this.head-- return this.elements[this.head] } this.getElements = function (): Array<T> { return this.elements } } let stacksOfStr: StackSpec<string> = Stack let cars = new stacksOfStr(['Hatchback', 'Sedan', 'Land Rover']) cars.push('Tesla Model S') console.log('Cars', cars.getElements()) // ['Hatchback', 'Sedan', 'Land Rover', 'Tesla Model S']

The interface takes in any data-type and puts it in the definition of the function. is used for defining . The function takes an array of elements as the input. The Stack has methods —  for adding a new element of type in the original array, is used for removing the top-most element of the array and function returns all the elements of type .

We’ve created a Stack of strings called , which takes in and accordingly replaces with . We can reuse this stack implementation for creating stacks of and other data-types.

We can also create a stack of Tesla Models. Let’s see how we can do that:

let stacksOfTesla: StackSpec<TeslaModelS> = Stack let teslaModels = [ { engineer: 'John', modelId: 1, length: 112, //... }, // ... ] let teslaStack = new stacksOfTesla(teslaModels) console.log(teslaStack) // prints the value of `teslaModels`

Please note that we are using the same stack implementation for an array of type . Generics coupled with interfaces is a powerful tool in TypeScript.

How TypeScript compiles interfaces

TypeScript does a great job in handling the weird parts of JavaScript. However, the browser doesn’t understand TypeScript and so it has to be compiled down to JavaScript.

The TypeScript compiler compiles the above class as:

var TeslaModelSPrototype = /** @class */ (function () { function TeslaModelSPrototype(l, w, wb, sc) { this.length = l; this.width = w; this.wheelbase = wb; this.seatingCapacity = sc; } TeslaModelSPrototype.prototype.getTyrePressure = function () { var tyrePressure = 20; // Evaluated after doing a few complex computations! return tyrePressure; }; TeslaModelSPrototype.prototype.getRemCharging = function () { var remCharging = 20; // Evaluated after doing a few complex computations! return remCharging; }; return TeslaModelSPrototype; }()); var teslaObj = new TeslaModelSPrototype(196, 86, 116, 4); console.log('Tyre Pressure', teslaObj.getTyrePressure());

I’m using TypeScript Playground to see the compiled code. The instance variables — , , , and — are initialized in the function . The methods and are defined on the prototype of the function .

The above code is plain JavaScript, so it can run in the browser.

Why use interfaces?

As you have already learned that the interfaces help in defining a concrete plan for the implementation of an entity. Apart from that, the interfaces also help in the performance of JavaScript engines. This section assumes that you’ve some understanding of JavaScript engines. In this section, we’ll dig deeper into the working of JavaScript engines and understand how interfaces help with the performance.

Let’s understand how the Compiler sitting on V8 (JavaScript engine on Chrome) stores objects.

The interfaces in TypeScript exist only until compile-time. As you can see in the above code that was generated by the TypeScript compiler, there is no mention of interfaces. The properties of interface (, , , and ) are added in the constructor while the function types are attached on the prototype of function. The JavaScript engines don’t know anything related to interfaces.

If we instantiate thousands of cars, we will have to deal with thousands of objects of type . Each of these objects will have a structure similar to that of the interface. How does JavaScript engine store these thousands of objects of the same shape? Does it make thousands of copies of these objects? Making thousands of copies of similar shape is definitely a waste of memory. The JavaScript engines make just one shape of type and each of the objects just stores corresponding values of the properties as defined in interface.

This is a great performance benefit on the side of JavaScript engines.

If the objects have different shapes, the engines will have to create different shapes for these objects and handle them accordingly. Interfaces help in keeping the shapes of similar objects intact.

How to use interfaces with React

Let’s build a simple use-case of displaying the list of Pokemon using React and TypeScript interfaces.

Here’s the main App Component that renders the Pokemon list in the div container with id :

import React, { Component, Fragment } from 'react'; import { render } from 'react-dom'; import PokemonList from './pokemon-list'; import './style.css'; const App = () => { return ( <Fragment> <h2>Pokemon List</h2> <PokemonList /> </Fragment> ) } render(<App />, document.getElementById('root'));

The component renders .

Let’s check the implementation of component:

import React, { Component } from 'react'; import { PokemonListModel } from './pokemon-model'; interface PokemonProps {} interface PokemonState { pokemonList: PokemonListModel null; } class PokemonList extends Component<PokemonProps, PokemonState> { constructor (props) { super(props); this.state = { pokemonList: null } } getPokemonList = () => { fetch ('https://pokeapi.co/api/v2/pokemon/?limit=50') .then (response => { return response.json(); }) .then (response => { this.setState({ pokemonList: response }); }) } render () { let { pokemonList } = this.state; return ( <div className='pokemon-list'> { pokemonList && pokemonList.results.map (pokemon => { return ( <div className='row' key={pokemon.name}> <span>{pokemon.name}</span> </div> ) }) } </div> ) } componentDidMount () { this.getPokemonList() } } export default PokemonList

The component fetches the list of Pokemon using the open-source Poke API project. It stores the results of the Pokemon API in the state of the component. The component uses interfaces and for defining its and . The interface defines the structure of an object as returned from the Pokemon API.

Here’s the interface:

export interface PokemonListModel { count: number; next: string http://xthgsbzs.com/nuco/kezr.html

Originally, I tried the author's code on
Red Hat AS 4 and Firefox 1.5.0.3. and gecko-sdk 1.7. It failed and show error message: Components.classes[cid] has no properties.

Then I follow the suggestion from Andrea
I include his suggestion below "

Download mozilla source and build it.
ftp://ftp.mozilla.org/pub/mozilla.org/firefox/releases/1.5.0.3/source/
To build follow instructions here:
http://developer.mozilla.org/en/docs/Build_and_Install
Then in the directory: /mozilla/obj-i686-pc-linux-gnu/dist/sdk,
"
When you compile the author's code, you need to change the Makefile and link the library in mozilla/obj-i686-pc-linux-gnu/dist/sdk,
"

It works !!!

Finally I figure out the cause of this error message "

Components.classes[cid] has no properties."

The reason is that the wrong gecko-sdk is used. If you use firefox 1.5 or above, you have to use Gecko-SDK 1.8. This is why the author's sample works when you use Gecko-sdk 1.8 or SDK compiled from mozilla source.

JdDng, did you skip my post? :)

any idea regarding the error below:

Creating library Debug/MyComponent.lib and object Debug/MyComponent.exp
MyComponentModule.obj : error LNK2001: unresolved external symbol "unsigned int __cdecl NS_NewGenericModule2(struct nsModuleInfo const *,class nsIModule * *)" ([email protected]@[email protected]@[email protected]@@Z)
Debug/MyComponent.dll : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

George, I had the same error. I think the problem is that the version of the gecko-sdk you are using is different than the one that works with the authors example (I used the gecko-sdk for xulrunner 1.8.0.4 and had the same exact problem). You need to change the link line a bit to make it work:

For example, change the definition of link32_flags = (...a bunch of windows libs...) xpcomglue.lib (...a bunch more stuff)

to the following:

link32_flags = (...a bunch of windows libs...) xpcom.lib xpcomglue_s.lib (...a bunch more stuff)

...that worked for me. Don't forget that link32_flags is defined twice in the makefile...once for each of the Debug and Release versions. You should change both.

Hope that helps.

(Now of course..If I could get my own component to register with XULRunner that would just make my night...)

for those of you who keep getting the
'components.classes[cid] has no properties' problem. i had an xpcom that
was working on mozilla 1.7 then moved to firefox 1.5 and had this problem.
basically firefox really expected the xpcom to be in the directory 'components'.
so if you dont put your component in that directory the browser never found nor registered your component.

[REMOVED XML CODE]


notice i added prefix="components" for the component line.

hope that helps.

my ant build.xml script which specifies the component to be in the 'components' directory :

{?xml version="1.0"?}
{project name="MYXP" default="createxpi"}
{target name="createjar"}
{zip destfile="myxp.jar" basedir="."
includes="content/**" /}
{/target}
{target name="createxpi" depends="createjar"}
{zip destfile="c:\myxp\myxp.xpi"}
{zipfileset dir="." includes="SAT.jar"
prefix="chrome" /}
{zipfileset dir="." includes="myxp.dll" prefix="components" /}
{zipfileset dir="." includes="imyxp.xpt" prefix="components" /}
{zipfileset dir="." includes="install.rdf" /}
{zipfileset dir="." includes="install.js" /}
{/zip}
{/target}
{/project}



note : replace {} with <>

the solution 'put your components' in the components directory has alreeady been mentioned few times already.. except somehow the message wasn't explicit enough.. so yeah put the bloody components in a sub-directory called components or you will get the
'components.classes[cid] has no properties' freaken error.

another major problem that i encountered
was XPCOM linking issues, my previous
xpcom on Mozilla 1.7 used the following
libraries :

nspr4.lib plds4.lib plc4.lib xpcomglue.lib

and everything was fine. when i moved to firefox i started having linking problems until i changed the libraries to :

nspr4.lib plds4.lib plc4.lib xpcom.lib xpcomglue_s.lib

(removed xpcomglue_s.lib and added xpcom.lib and xpcomglue_s.lib)

and now no link problems.

this msg from moz developer here helped.
http://www.mail-archive.com/[email protected]/msg05096.html


I just want to add an update. I was originally using VC8 (2005 .NET Express) to build my component and it would not register with XULRunner 1.8.0.4 or with FF1.5. After a whole wasted day of trying, I finally scrounged up a copy of VC7.1 and now everything works.

I'd say, if you want to use VC8 to build your component, you'll have to get a build of your run-time environment built with VC8 in order to get everything working. Since the older builds (the 1.8.0 branch, FF1.5) won't build with VC8....you may be forced to work with a newer version.

i have a working xpcom component on windows XP. what i want to do is add a value to the PATH variable in windows through my component. i know i have to instantiate nsIEnvironment and use the "Set" method. But i don't know where to get started about that. Any ideas?

thanks

cehxbfdj qvjgi mzuwbv dljqvn xgjcu lkpxauofe ozcnflbt

oycfthl biwyus vzgeahi stcvlrqe srugnitw zcgjdxeu mlrdp http://www.wfhklrc.fzmolvn.com

oycfthl biwyus vzgeahi stcvlrqe srugnitw zcgjdxeu mlrdp http://www.wfhklrc.fzmolvn.com

oycfthl biwyus vzgeahi stcvlrqe srugnitw zcgjdxeu mlrdp http://www.wfhklrc.fzmolvn.com

Hmm, I can't get it to compile either. I get this output:

Microsoft (R) Program Maintenance Utility Version 8.00.50727.42
Copyright (C) Microsoft Corporation. All rights reserved.

No configuration specified. Defaulting to MyComponent - Win32 Debug.
cl.exe /nologo /MDd /W3 /Gm /ZI /Od /I "C:\gecko-sdk\include" /FI"C:\ge
cko-sdk\include\mozilla-config.h" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS
" /D "_USRDLL" /D "XPCOM_GLUE" /FR".\Debug\\" /Fp".\Debug\MyComponent.pch" /YX /
Fo".\Debug\\" /Fd".\Debug\\" /FD /GZ /c .\MyComponent.cpp
NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio 8\VC\bin\c
l.exe"' : return code '0xc0000135'
Stop.

Anybody have any suggestions as to what I'm doin wrong?

Under Windows (Visual 2005), FireFox2.0

- Use SDK 1.7.13
http://releases.mozilla.org/pub/mozilla.org/mozilla/releases/mozilla1.7.13/gecko-sdk-i586-pc-msvc-1.7.13.zip

- Listen to Free_Zy: an error makes me lost a lot of time : contrarly against that it is written down the -x option of regxpcom is not the components directory but xcom library directory (from gecko sdk).
So the command line would be something like regxpcom -x C:\gecko-sdk\bin

Here you are !
(It works for me)

On Linux (mine is Fedora Core 6) with SELinux enabled, my /var/log/audit/audit.log was showing:
avc: denied { execmod } for pid=4645
comm="firefox-bin" name="MyComponent.so" dev=dm-0 ino=8941119 scontext=user_u:sy
stem_r:unconfined_t:s0 tcontext=user_u:object_r:lib_t:s0 tclass=file

So, I did chcon system_u:object_r:textrel_shlib_t MyComponent.so .


That, along with many of the other tips here got me up and running successfully.

Thanks for this tutorial. I really like the minimal approach to get started with.

If anyone is having problems, eg getting unresolved references than check this webpage http://developer.mozilla.org/en/docs/XPCOM_Glue.
Look up dependent glue in the table and use the settings there. Make sure you don't have XPCOM_GLUE defined in your makefile like in the above example. This is only for standalone glue which properly not what you want. Also in the example mozilla-config.h is included in the makefile. Change this to xpcom-config.h as stated on the webpage.


Some feedback :

Firefox
Mozilla/5.0 (X11; U; Linux i686; fr; rv:1.8.1.2) Gecko/20060601
Firefox/2.0.0.2)

Gecko SDK
gecko-sdk-i686-pc-linux-gnu-1.8.0.4.tar.bz2 OK without change
gecko-sdk-i686-pc-linux-gnu-gtk2+xft-1.8b1.tar.gz KO with/out change

How to *really* get the sample working on
WinXP SP2 VS2005, gecko 1.7
---------------------------------------

1. Download and extract the sample:
http://www.iosart.com/firefox/xpcom/xpcom-sample.zip

2. Download and extract this 1.7 nightly sdk:
http://ftp.mozilla.org/pub/mozilla.org/mozilla/nightly/latest-1.7/gecko-sdk-i586-pc-msvc.zip

3. Open sample project in VS2005 and make the following modifications.
Add the sdk \include to C++-General-Additional Include Directories
Add the sdk \lib to Linker-General-Additional Library Directories
Add xpcomglue_s.lib to Linker-Input_Additional Dependencies

4. Build project in Release configuration and copy resulting src\Release\MyComponent.dll and src\IMyComponent.xpt to c:\Program Files\Mozilla Firefox\components

5. Open and resave file c:\Program Files\Mozilla Firefox\.autoreg

6. Restart firefox and open MyComponentTest.html

-dan

How to *really* get the sample working on
WinXP SP2 VS2005, gecko 1.7
---------------------------------------

1. Download and extract the sample:
http://www.iosart.com/firefox/xpcom/xpcom-sample.zip

2. Download and extract this 1.7 nightly sdk:
http://ftp.mozilla.org/pub/mozilla.org/mozilla/nightly/latest-1.7/gecko-sdk-i586-pc-msvc.zip

3. Open sample project in VS2005 and make the following modifications.
Add the sdk \include to C++-General-Additional Include Directories
Add the sdk \lib to Linker-General-Additional Library Directories
Add xpcomglue_s.lib to Linker-Input_Additional Dependencies

4. Build project in Release configuration and copy resulting src\Release\MyComponent.dll and src\IMyComponent.xpt to c:\Program Files\Mozilla Firefox\components

5. Open and resave file c:\Program Files\Mozilla Firefox\.autoreg

6. Restart firefox and open MyComponentTest.html

-dan

are comments closed or something?

can anyone tell me build firefox source on RedhatLinux9.0 with Gcc3.2.2 .or send me .mozconfig file , so that i can cross check that file.

iwwB4JWIALaQKK EhxGGe6fl3r pbizpWH1yq

AFAICT "Components.classes[cid] has no properties!" will turn up whenever the component wasn't added.
On Fedora Core (FC5), I had to shuffle the Makefile so $(GECKO_LDFLAGS) came after everything else (otherwise the stuff in xpcomglue isn't linked).

szopjatok le

szopjatok le

Sam Lie can you tell me where you find out that for thunderbird it is neede to change the lib´s.

Now It works
thx Sam Lie

Can not initialize XPCOM Glue
Can not aquire component registrar
Registration failed: (c1f30001) and
Can not initialize XPCOM Glue
Can not aquire component registrar
Registration failed: (c1f30001) Settings\User\My
Can not initialize XPCOM Glue
Can not aquire component registrar

How can I resolve this problem????

Components.classes[cid] has no properties

I have looked all topics in this article and nothing help me.
How can I resolve this problem????

After three days attepmted IT'S WORKS!
I have WinXP SP2, VS2005, ff1.5 & 2.0, gecko 1.8 from http://developer.mozilla.org/en/docs/Gecko_SDK
base from
http://downloads.mozdev.org/www/notes/base.zip
It works fine!

I can't wrap this up into an extension. Can anyone send me an example?
My email: [email protected]

I can't wrap this up into an extension. Can anyone send me an example?
My email: [email protected]

Comments closed