Closed Bug 789382 Opened 12 years ago Closed 12 years ago

nsIScriptError methods init() & initWithWindowID() should take nsAString, rather than wchar / PRUnichar*

Categories

(Core :: XPConnect, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla18

People

(Reporter: dholbert, Assigned: dholbert)

References

Details

Attachments

(2 files, 2 obsolete files)

As bz noted in bug 786108 comment 9, it's a little counterproductive that nsIScriptError's init() and initWithWindowID() methods take PRUnichar* -- they could just as easily take nsAString, which would be more abstract & could allow for string-sharing in some cases.

Filing this bug on making that change.
Blocks: 786108
Attached patch Patch 1: Change API & Impl (obsolete) — Splinter Review
I'm splitting this into two patches, for (hopefully) clearer/easier reviewing:
  Patch 1) The changes to the IDL & the impl.
  Patch 2) The changes to all the client code.

I believe Patch 1 needs sr (as an API change), but patch 2 doesn't.

(I intend to fold the two patches together before I land, since Patch 1 by itself won't successfully build.)
Attachment #659117 - Flags: superreview?
Attachment #659117 - Flags: review?(bzbarsky)
Attachment #659117 - Flags: superreview? → superreview?(benjamin)
Attachment #659117 - Attachment filename: 788862-changeAPI.patch → 789382-changeAPI.patch
Attached patch Patch 2: Changes to client code (obsolete) — Splinter Review
This patch was pretty mechanical -- basically just:
  s/foo.get()/foo/
  s/rawString/nsDependentString(rawString)/
  s/nullptr/EmptyString()/

There are also a few static_casts sprinkled in, for strictness -- replacing reinterpret_casts and C-style casts, since we don't need the power of reinterpret_cast / c-style casts in those spots.

(I also simplified for consistency in a few places -- e.g. just calling NS_ConvertUTF8toUTF16() directly in mozJSComponentLoader.cpp's call to init(), since that's shorter & it's the pattern we follow almost everywhere.  Also one old nullcheck-after-new.)

CAVEAT: I haven't tested this yet; I've just confirmed that it successfully builds. :)
Attachment #659123 - Flags: review?(bzbarsky)
Note: The s/nullptr/EmptyString()/ changes are fine (won't change behavior) because nsScriptError::InitWithWindowID() just calls e.g. mSourceLine.Assign(sourceLine), and Assign() ends up truncating & returning when it's passed a null pointer:
https://mxr.mozilla.org/mozilla-central/source/xpcom/string/src/nsTSubstring.cpp?mark=297-301#295
Forgot to rev the uuid -- fixed in this new version.
Attachment #659117 - Attachment is obsolete: true
Attachment #659117 - Flags: superreview?(benjamin)
Attachment #659117 - Flags: review?(bzbarsky)
Attachment #659124 - Flags: superreview?(benjamin)
Attachment #659124 - Flags: review?(bzbarsky)
Comment on attachment 659124 [details] [diff] [review]
Patch 1 v2: Change API & Impl

r=me
Attachment #659124 - Flags: review?(bzbarsky) → review+
(I imagine this will break some comm-central code -- this will probably need a corresponding comm-central bug & patch.)
Comment on attachment 659123 [details] [diff] [review]
Patch 2: Changes to client code

Please test on try.  Going from const jschar* to const PRUnichar* used to require a reinterpret_cast on some platforms, iirc.

In the XBL_ProtoErrorReporter I'm a little worried about ucmessage or uclinebuf being null.  Can they be?  Some other places certainly null-check at least ucmessage.

Similar in the IndexedDatabaseManager.

And the component loader.

And XPCComponents.

And XPCConvert (just uclinebuf).

r=me with those fixed or the worry allayed.
Attachment #659123 - Flags: review?(bzbarsky) → review+
(In reply to Boris Zbarsky (:bz) from comment #7)
> Comment on attachment 659123 [details] [diff] [review]
> Patch 2: Changes to client code
> 
> Please test on try.  Going from const jschar* to const PRUnichar* used to
> require a reinterpret_cast on some platforms, iirc.

I don't think that's an issue anymore -- in at least some of the patch's chunks, we were already using static_cast for that conversion, so that shouldn't cause problems. (that's what tipped me off that we could use reinterpret_cast, and I changed it for consistency)

(I'll look into the other null-checks & address them as-needed -- thanks for bringing that up! I'd assumed that nsDependentString(nsnull) would do the right thing & produce an empty string, but it looks like that'll assert, so we do need to be sure we're not passing in null there.)

FWIW: The (non-Android) Try builders didn't quite finish the full build process, due to issues in "make package" & friends, due to .jsm files needing updates to their nsIScriptError usage I believe.  For reference, the try push was:
 https://tbpl.mozilla.org/?tree=Try&rev=03bc6d4c751c
and from a quick grep, it looks like e.g.
 https://mxr.mozilla.org/mozilla-central/source/browser/devtools/tilt/TiltUtils.jsm#72
will need an update, and others as well.

So, I'll include a third patch for _JS_ client code.
That's really odd.  JS should have been completely unaffected, since JS strings will Just Work and XPConnect will convert JS null to an empty AString....  I wonder whether the JS callers had "undefined" there or something?
I actually think the jsm files are fine after all -- it was likely that we were running a packaging tool *to package those files*, and that packaging tool involves one of the tweaked C++ classes, it crashed on a null pointer due to the null-checks mentioned in comment 7.
(or rather, due to the _lack_ of those null-checks)
(In reply to Boris Zbarsky (:bz) from comment #7)
> Comment on attachment 659123 [details] [diff] [review]
> In the XBL_ProtoErrorReporter I'm a little worried about ucmessage or
> uclinebuf being null.  Can they be?

I think they can be. They're initialized to null (from the struct getting a memset(0)), in at least some cases, and we do have null-checks elsewhere, so might as well null-check them here.

So: added null-checks there.

> Similar in the IndexedDatabaseManager.

We're OK there, because both of the strings come from an nsString.  I've now just replaced the nsDependentString(buf) invocation with the actual nsString ("errorName") there, and I added an assertion that the other one is non-null (which we're guaranteed from how it's set, in FillScriptErrorEvent, here:
>  aEvent->fileName = mFilename.get();
https://mxr.mozilla.org/mozilla-central/source/dom/indexedDB/IDBRequest.cpp?mark=227-227#223

And mFilename is a (concrete) nsString, declared here:
https://mxr.mozilla.org/mozilla-central/source/dom/indexedDB/IDBRequest.h#103

so its .get() method should return non-null.

> And the component loader.

Added null-checks.

> And XPCComponents.

Added null-checks.

> And XPCConvert (just uclinebuf).

Added null-check for uclinebuf.

> r=me with those fixed or the worry allayed.

Thanks! Carrying forward r+, -- all of the above is fixed except for the IndexedDatabaseManager chunk, and hopefully I allayed your worries there?
Attachment #659123 - Attachment is obsolete: true
Attachment #659334 - Flags: review+
Sounds good!
Attachment #659334 - Attachment description: patch 2 v2: Changes to client code → patch 2 v2: Changes to client code [r=bz]
Attachment #659124 - Flags: superreview?(benjamin) → superreview+
https://hg.mozilla.org/mozilla-central/rev/70a0eda09c3c
Status: ASSIGNED → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla18
Depends on: 790015
>(I imagine this will break some comm-central code -- this will probably need a
> corresponding comm-central bug & patch.)
Oh it did, and it does. Please file necessary comm-central bugs instead of waiting for us to discover stuff like this by having our trees catch fire.
Blocks: 790157
Oops! Very sorry about that -- I forgot about that impact of this bug at some point after posting that comment.

I've filed bug 790157 to fix comm-central, and I can look into fixing it tomorrow morning.  Should I back out in the meantime?  (if so, I can do that in the morning)

(I don't see burning over on https://tbpl.mozilla.org/?tree=Thunderbird-Trunk , but maybe that's because this hasn't been merged there yet?  I don't really know how comm-central TBPL / build mechanics work.)
> (I don't see burning over on https://tbpl.mozilla.org/?tree=Thunderbird-Trunk)
It appear to affect only Lightning. However Lightning is pretty integral to Thunderbird. See Bug 790015.
No longer depends on: 790015
Blocks: 790015
No longer blocks: 790157
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: