Bug 42639 - Moves various exception code offsets to a central place.
Summary: Moves various exception code offsets to a central place.
Status: UNCONFIRMED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Other OS X 10.5
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-20 06:46 PDT by Marcus Bulach
Modified: 2010-10-11 10:58 PDT (History)
2 users (show)

See Also:


Attachments
Patch (19.48 KB, patch)
2010-07-20 06:55 PDT, Marcus Bulach
no flags Details | Formatted Diff | Diff
Patch (12.25 KB, patch)
2010-07-20 09:43 PDT, Marcus Bulach
abarth: review-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Marcus Bulach 2010-07-20 06:46:18 PDT
Moves various exception code offsets to a central place.
Comment 1 Marcus Bulach 2010-07-20 06:55:54 PDT
Created attachment 62071 [details]
Patch
Comment 2 Marcus Bulach 2010-07-20 07:04:13 PDT
Hi Darin,

This is a follow up on https://bugs.webkit.org/show_bug.cgi?id=42250
The proposed patch is not yet final in the sense that I'll replicate the same idea to a few other places (if it makes sense).

However, I'd appreciate your comments whether or not this is an improvement:
on one hand, it turns on compile-time checking for exception code on the IDL / WebCore, and also adds a centralized place for defining the offsets, hence avoiding possible clashes. On the other hand, it adds a small burden when setting the exception code, as it now needs to offset it (rather than just use the enum value).

Please, let me know your thoughts, and I'd be happy to do the same for the remaining classes.

Thanks!
Comment 3 Darin Adler 2010-07-20 08:17:59 PDT
(In reply to comment #2)
> On the other hand, it adds a small burden when setting the exception code, as it now needs to offset it (rather than just use the enum value).

What I’m concerned about ost is the risk of writing the code wrong and not knowing it's wrong.

It seems that now you could easily forget the offset entirely, or use the wrong offset with the wrong error code. Is there some way we can catch those mistakes at compile time?
Comment 4 Marcus Bulach 2010-07-20 09:02:58 PDT
(In reply to comment #3)
> (In reply to comment #2)
> > On the other hand, it adds a small burden when setting the exception code, as it now needs to offset it (rather than just use the enum value).
> 
> What I’m concerned about ost is the risk of writing the code wrong and not knowing it's wrong.

yep, that's why I didn't do on all classes at once.. ;)

> 
> It seems that now you could easily forget the offset entirely, or use the wrong offset with the wrong error code. Is there some way we can catch those mistakes at compile time?

yep, forgetting to offset is entirely possible (nit: use the wrong offset is detected at compile time though).

I'm not sure if it's possible to check that the offset is being added at compile time unless we make ExceptionCode generally more opaque, but that would be far too large for probably too little benefit.

one step back: another approach would be to have some attribute like "CheckEnumsWithOffset" in the IDL.
we could still benefit from compile-time check of values, have the offsets centralized, safe type-based range check, but at the expense of keeping the attribute in the IDL files.

let me try a quick draft on how it would look, I'll upload a new patch shortly (unless of course you think the IDL attribute is a bad idea..)
Comment 5 Darin Adler 2010-07-20 09:33:50 PDT
(In reply to comment #4)
> I'm not sure if it's possible to check that the offset is being added at compile time unless we make ExceptionCode generally more opaque, but that would be far too large for probably too little benefit.

I think making ExceptionCode be a struct holding an integer instead of actually being a raw int might be the right direction, and not such a giant project. We can phase it in, using things like a constructor taking and int and operator int at first, and then removing them.
Comment 6 Marcus Bulach 2010-07-20 09:43:51 PDT
Created attachment 62085 [details]
Patch
Comment 7 Marcus Bulach 2010-07-20 09:58:11 PDT
(In reply to comment #5)
> (In reply to comment #4)
> > I'm not sure if it's possible to check that the offset is being added at compile time unless we make ExceptionCode generally more opaque, but that would be far too large for probably too little benefit.
> 
> I think making ExceptionCode be a struct holding an integer instead of actually being a raw int might be the right direction, and not such a giant project. We can phase it in, using things like a constructor taking and int and operator int at first, and then removing them.

cool! I like doing such refactorings, will plan to do this soon (it's probably not a giant project, but requires some planning on my side..)

meanwhile, I think there's a low-hanging fruit here with the latest patch: it adds compile-time checks, without touching existing code (at the expense of having a new IDL attribute).
would you mind taking a quick look and let me know if you agree with such intermediate step? thanks!
Comment 8 Adam Barth 2010-10-10 11:34:53 PDT
Comment on attachment 62085 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=62085&action=review

I'm not sure why we want to make this change.  I like the idea of making ExceptionCode into a struct that has an int member.  That would seem to make it much easier to use the C++ type system to help us with correctness.

> WebCore/dom/ExceptionOffset.h:38
> +        EVENT_EXCEPTION_OFFSET = 100,
> +        EVENT_EXCEPTION_MAX = 199,
> +        RANGE_EXCEPTION_OFFSET = 200,
> +        RANGE_EXCEPTION_MAX = 299,
> +        XML_HTTP_REQUEST_EXCEPTION_OFFSET = 500,
> +        XML_HTTP_REQUEST_EXCEPTION_MAX = 699,

I'm not sure these are named correctly.  Do we use ALL_CAPS names for similar things?
Comment 9 Darin Adler 2010-10-11 10:58:34 PDT
Adam’s comment got my attention. Sorry I didn’t get around to reviewing more patches this weekend!

The general concept is that we should use ALL_CAPS only for:

    1) Something we’re implementing from a standard, such as the DOM API, that has that capitalization.

    2) Macros, especially non-function-style macros. The ALL_CAPS style there is to avoid having code actually be subject to macro expansion. Avoiding ALL_CAPS everywhere else means there is less chance of collision.

These new constants don’t fit either description so should not be ALL_CAPS.