nsIWindowsRegKey feedback

NEW
Unassigned

Status

()

Core
XPCOM
13 years ago
10 years ago

People

(Reporter: Henrik Gemal, Unassigned)

Tracking

Trunk
x86
Windows XP
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

13 years ago
I'm the developer of Launchy which uses the nsIWindowsRegKey and I have some
feedback:

1) first of all why do opening a key that doesn't exist throw an exception?
The extension.js doesnt wrap the call in a try and catch so this will produce an
JS error.

2) why do reading a value that doesn't exist throw an exception?

3) why cant I do this:
var tmp = key.open(this._rootKey, path, nsIWindowsRegKey.ACCESS_READ);
var x = tmp.valueCount;
I'm getting tmp has no properties

4) any chance you could add
HKEY_CURRENT_CONFIG
and
HKEY_USERS
to
http://lxr.mozilla.org/mozilla/source/xpcom/ds/nsIWindowsRegKey.idl#60
> 1) first of all why do opening a key that doesn't exist throw an exception?

what else should it do?

> 2) why do reading a value that doesn't exist throw an exception?

what else should it do?

>var tmp = key.open(this._rootKey, path, nsIWindowsRegKey.ACCESS_READ);
>var x = tmp.valueCount;
>I'm getting tmp has no properties

open does not return a value; access key.valueCount instead.
Assignee: nobody → dougt
Component: OS Integration → XPCOM
Product: Firefox → Core
QA Contact: os.integration → xpcom
Version: unspecified → Trunk

Comment 2

13 years ago
(In reply to comment #1)
> > 1) first of all why do opening a key that doesn't exist throw an exception?
> 
> what else should it do?

return false
 
Firefox has this in "nsExtensionManager.js"
var path = "SOFTWARE\\" + appVendor + appName + "\\Extensions";
var key = Components.classes["@mozilla.org/windows-registry-key;1"]            
         .createInstance(nsIWindowsRegKey);
key.open(this._rootKey, path, nsIWindowsRegKey.ACCESS_READ);

if the ckey doesn't exist the function will die

> > 2) why do reading a value that doesn't exist throw an exception?
> 
> what else should it do?

return false
 
> >var tmp = key.open(this._rootKey, path, nsIWindowsRegKey.ACCESS_READ);
> >var x = tmp.valueCount;
> >I'm getting tmp has no properties
> 
> open does not return a value; access key.valueCount instead.

ok
>> > 2) why do reading a value that doesn't exist throw an exception?
>> 
>> what else should it do?
>return false

can't, it already returns the value. you would prefer an out parameter for the
value?

Comment 4

13 years ago
Henrik,

Thanks for taking the time to provide this feedback.


> 1) first of all why do opening a key that doesn't exist throw an exception?
> The extension.js doesnt wrap the call in a try and catch so this will produce an
> JS error.

I'm not sure where to find "extension.js"... did you mean nsExtensionManager.js?
 When I wrote some JS code to use this interface, I added a try-catch block to
handle exceptions, see:
http://lxr.mozilla.org/mozilla/source/toolkit/mozapps/extensions/src/nsExtensionManager.js.in#1163

I personally think this is a fine use of exception handling.  Java similarly
throws exceptions when files cannot be opened or other resources cannot be
found.  This seems like a consistent programming model to me.  Arguably, some
people prefer to avoid exception handling, but oh well.  This seems like an API
that is at least easy to use from either C++ or Javascript, so I'm happy with it.


> 2) why do reading a value that doesn't exist throw an exception?

You may avoid exception handling by calling the hasValue() method before reading
a registry value.


> 4) any chance you could add
> HKEY_CURRENT_CONFIG
> and
> HKEY_USERS

I had those originally, but I didn't think they would be useful ;-)  Guess I was
wrong.  In any case, you can add them yourself until I add them to the
interface.  The values are just 32-bit integers, so you can easily encode them
yourself:

  const HKEY_USERS          = 0x80000003;
  const HKEY_CURRENT_CONFIG = 0x80000005;

The point is that there are many other special values that may be supported by
Windows XP or Longhorn when it ships, and this interface allows you to access
those root keys provided you know the value for them.

Comment 5

13 years ago
Hi there.

I was just trying to help an extension writer figure out some random errors
they were getting in the "nsIWindowsRegKey" interface and I thought I would drop
a line here.

The extension which you can download is called "Navigational Sounds", a Windows
extension that plays the correct system-defined "Navigation Start" and "...End"
events when you click on a link in the main browser window (as IE, Explorer and
all the other Windows components do).

However, this extension frequently throws an error to the JavaScript console
complaining about "nsIWindowsRegKey.open" failing with error "0x80004005". I
saw no evidence of this being a user-generated error, however in "Windows.h"
it is a COM/OLE error "E_FAIL", a generic failure code.

Is there a reason that this error is being received when it appears that the
parameters to the call appear correct?

Cheers.

Comment 6

13 years ago
> complaining about "nsIWindowsRegKey.open" failing with error "0x80004005". I
> saw no evidence of this being a user-generated error, however in "Windows.h"

By "windows.h", I actually meant "winerror.h", called from "windows.h", the header
file that ships with any of the big vendors C/C++ compilers (Visual Studio, C++
Builder, etc).

Comment 7

13 years ago
E_FAIL maps to NS_ERROR_FAILURE in the Mozilla codebase.  You can see that if
RegOpenKeyEx fails, nsIWindowsRegistryKey::open will throw NS_ERROR_FAILURE:
http://lxr.mozilla.org/mozilla/source/xpcom/ds/nsWindowsRegKey.cpp#159

When using nsIWindowsRegistryKey from script, it is important to wrap the open
call in a "try { ... } catch (e) { ... }" block.

Comment 8

11 years ago
mass reassigning to nobody.
Assignee: dougt → nobody
You need to log in before you can comment on or make changes to this bug.