Bug 35723 - Refactoring: window.btoa() and window.atob() should be implemented on DOMWindow
Summary: Refactoring: window.btoa() and window.atob() should be implemented on DOMWindow
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC OS X 10.5
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-03-04 00:05 PST by Hajime Morrita
Modified: 2010-03-06 05:04 PST (History)
3 users (show)

See Also:


Attachments
patch v0 (12.84 KB, patch)
2010-03-04 01:35 PST, Hajime Morrita
no flags Details | Formatted Diff | Diff
v1; fix style violations (12.84 KB, patch)
2010-03-04 02:06 PST, Hajime Morrita
no flags Details | Formatted Diff | Diff
v2; follow the feedback, cleanup a little (12.65 KB, patch)
2010-03-04 18:04 PST, Hajime Morrita
no flags Details | Formatted Diff | Diff
v3; rename hasMultibyteCharacters to isSafeToConvertCharList (12.65 KB, patch)
2010-03-04 19:58 PST, Hajime Morrita
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Hajime Morrita 2010-03-04 00:05:20 PST
Currently window.btoa() and window.atob() are separetely implemented in both JSC and V8 binding.
They should share code as much as possible and the code should be on DOMWindow.
Comment 1 Hajime Morrita 2010-03-04 01:35:06 PST
Created attachment 49997 [details]
patch v0
Comment 2 WebKit Review Bot 2010-03-04 01:38:13 PST
Attachment 49997 [details] did not pass style-queue:

Failed to run "WebKitTools/Scripts/check-webkit-style" exit_code: 1
WebCore/page/DOMWindow.cpp:832:  Missing spaces around =  [whitespace/operators] [4]
WebCore/page/DOMWindow.cpp:832:  Missing spaces around <  [whitespace/operators] [3]
Total errors found: 2 in 7 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 3 Hajime Morrita 2010-03-04 02:06:23 PST
Created attachment 49998 [details]
v1; fix style violations
Comment 4 Darin Adler 2010-03-04 09:27:07 PST
Comment on attachment 49998 [details]
v1; fix style violations

> -    return jsString(exec, String(out.data(), out.size()));
> +    return jsString(exec, String(result.characters(), result.length()));

This is wrong. It makes an extra copy of the entire string! It should just be jsString(exec, result).
Comment 5 Hajime Morrita 2010-03-04 18:04:22 PST
Created attachment 50075 [details]
v2; follow the feedback, cleanup a little
Comment 6 Hajime Morrita 2010-03-04 18:06:23 PST
Thank you for reviewing quickly!

(In reply to comment #4)
> This is wrong. It makes an extra copy of the entire string! It should just be
> jsString(exec, result).
Fixed.
And removed unnecessary code that last patch has.
Comment 7 Darin Adler 2010-03-04 18:44:25 PST
Comment on attachment 50075 [details]
v2; follow the feedback, cleanup a little

> +static bool hasMultibyteCharacters(const String& string)
> +{
> +    for (unsigned i = 0; i < string.length(); i++) {
> +        if (string[i] > 0xFF)
> +            return true;
> +    }
> +
> +    return false;
> +}

This is not a great name for this function. I don’t really think of U+0040 as a “single byte” character nor do I think of U+0100 as “multi-byte”.

Patch otherwise seems OK.

r=me
Comment 8 Hajime Morrita 2010-03-04 19:58:59 PST
Created attachment 50083 [details]
v3; rename hasMultibyteCharacters to isSafeToConvertCharList
Comment 9 Hajime Morrita 2010-03-04 20:01:40 PST
Thank you for reviewing!

> This is not a great name for this function. I don’t really think of U+0040 as a
> “single byte” character nor do I think of U+0100 as “multi-byte”.
I agree that "multi-byte character" is not right. 
But I'm not sure if there is some good concept to represent this case.
So I chose the name intend to be valid locally in this context.
Comment 10 Darin Adler 2010-03-05 10:03:35 PST
Comment on attachment 50083 [details]
v3; rename hasMultibyteCharacters to isSafeToConvertCharList

> +static bool isSafeToConvertCharList(const String& string)

This is probably better than the old name, but I would have used a name like containsOnlyEightBitCharacters. Sorry I didn't suggest a name last time. r=me either with your name or with my suggested name.
Comment 11 WebKit Commit Bot 2010-03-06 05:03:58 PST
Comment on attachment 50083 [details]
v3; rename hasMultibyteCharacters to isSafeToConvertCharList

Clearing flags on attachment: 50083

Committed r55619: <http://trac.webkit.org/changeset/55619>
Comment 12 WebKit Commit Bot 2010-03-06 05:04:02 PST
All reviewed patches have been landed.  Closing bug.