Changeset 55637 in webkit


Ignore:
Timestamp:
Mar 7, 2010 5:26:57 PM (14 years ago)
Author:
weinig@apple.com
Message:

Remove inconsistent "Too few arguments" handling for window.atob() and window.btoa()
https://bugs.webkit.org/show_bug.cgi?id=35848

Reviewed by Dan Bernstein.

WebCore:

  • Take the opportunity to fully autogenerate window.atob() and window.btoa().
  • bindings/js/JSDOMWindowCustom.cpp:
  • page/DOMWindow.cpp:

(WebCore::DOMWindow::btoa):
(WebCore::DOMWindow::atob):

  • page/DOMWindow.idl:

LayoutTests:

  • fast/dom/Window/atob-btoa-expected.txt:
  • fast/dom/Window/atob-btoa.html:
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r55636 r55637  
     12010-03-07  Sam Weinig  <sam@webkit.org>
     2
     3        Reviewed by Dan Bernstein.
     4
     5        Remove inconsistent "Too few arguments" handling for window.atob() and window.btoa()
     6        https://bugs.webkit.org/show_bug.cgi?id=35848
     7
     8        * fast/dom/Window/atob-btoa-expected.txt:
     9        * fast/dom/Window/atob-btoa.html:
     10
    1112010-03-07  Dan Bernstein  <mitz@apple.com>
    212
  • trunk/LayoutTests/fast/dom/Window/atob-btoa-expected.txt

    r55619 r55637  
    1212PASS window.btoa("abcdef") is "YWJjZGVm"
    1313PASS typeof window.btoa is "function"
    14 PASS window.btoa() threw exception SyntaxError: Not enough arguments.
     14PASS window.btoa() is "dW5kZWZpbmVk"
    1515PASS window.btoa("") is ""
    1616PASS window.btoa(null) is ""
     17PASS window.btoa(undefined) is "dW5kZWZpbmVk"
    1718PASS window.btoa(window) is "W29iamVjdCBET01XaW5kb3dd"
    1819PASS window.btoa("éé") is "6ek="
     
    2223PASS typeof window.btoa is "number"
    2324PASS typeof window.atob is "function"
    24 PASS window.atob() threw exception SyntaxError: Not enough arguments.
     25PASS window.atob() threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5.
    2526PASS window.atob("") is ""
    2627PASS window.atob(null) is ""
     28PASS window.atob(undefined) threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5.
    2729PASS window.atob(" YQ==") threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5.
    2830PASS window.atob("YQ==\u000a") threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5.
  • trunk/LayoutTests/fast/dom/Window/atob-btoa.html

    r21931 r55637  
    2323
    2424shouldBe('typeof window.btoa', '"function"');
    25 shouldThrow('window.btoa()');
     25shouldBe('window.btoa()', '"dW5kZWZpbmVk"');
    2626shouldBe('window.btoa("")', '""');
    2727shouldBe('window.btoa(null)', '""');
     28shouldBe('window.btoa(undefined)', '"dW5kZWZpbmVk"');
    2829shouldBe('window.btoa(window)', '"W29iamVjdCBET01XaW5kb3dd"'); // "[object DOMWindow]"
    2930shouldBe('window.btoa("éé")', '"6ek="');
     
    3536
    3637shouldBe('typeof window.atob', '"function"');
    37 shouldThrow('window.atob()');
     38shouldThrow('window.atob()'); // 'undefined'
    3839shouldBe('window.atob("")', '""');
    3940shouldBe('window.atob(null)', '""');
     41shouldThrow('window.atob(undefined)');
    4042shouldThrow('window.atob(" YQ==")');
    4143shouldThrow('window.atob("YQ==\\u000a")');
  • trunk/WebCore/ChangeLog

    r55636 r55637  
     12010-03-07  Sam Weinig  <sam@webkit.org>
     2
     3        Reviewed by Dan Bernstein.
     4
     5        Remove inconsistent "Too few arguments" handling for window.atob() and window.btoa()
     6        https://bugs.webkit.org/show_bug.cgi?id=35848
     7
     8        - Take the opportunity to fully autogenerate window.atob() and window.btoa().
     9
     10        * bindings/js/JSDOMWindowCustom.cpp:
     11        * page/DOMWindow.cpp:
     12        (WebCore::DOMWindow::btoa):
     13        (WebCore::DOMWindow::atob):
     14        * page/DOMWindow.idl:
     15
    1162010-03-07  Dan Bernstein  <mitz@apple.com>
    217
  • trunk/WebCore/bindings/js/JSDOMWindowCustom.cpp

    r55635 r55637  
    938938}
    939939
    940 JSValue JSDOMWindow::atob(ExecState* exec, const ArgList& args)
    941 {
    942     if (args.size() < 1)
    943         return throwError(exec, SyntaxError, "Not enough arguments");
    944     if (args.at(0).isNull())
    945         return jsEmptyString(exec);
    946 
    947     ExceptionCode ec = 0;
    948     String result = impl()->atob(args.at(0).toString(exec), ec);
    949     setDOMException(exec, ec);
    950 
    951     return jsString(exec, result);
    952 }
    953 
    954 JSValue JSDOMWindow::btoa(ExecState* exec, const ArgList& args)
    955 {
    956     if (args.size() < 1)
    957         return throwError(exec, SyntaxError, "Not enough arguments");
    958     if (args.at(0).isNull())
    959         return jsEmptyString(exec);
    960 
    961     ExceptionCode ec = 0;
    962     String result = impl()->btoa(args.at(0).toString(exec), ec);
    963     setDOMException(exec, ec);
    964 
    965     return jsString(exec, result);
    966 }
    967 
    968940JSValue JSDOMWindow::addEventListener(ExecState* exec, const ArgList& args)
    969941{
  • trunk/WebCore/page/DOMWindow.cpp

    r55635 r55637  
    840840String DOMWindow::btoa(const String& stringToEncode, ExceptionCode& ec)
    841841{
     842    if (stringToEncode.isNull())
     843        return String();
     844
    842845    if (!isSafeToConvertCharList(stringToEncode)) {
    843846        ec = INVALID_CHARACTER_ERR;
     
    856859String DOMWindow::atob(const String& encodedString, ExceptionCode& ec)
    857860{
     861    if (encodedString.isNull())
     862        return String();
     863
    858864    if (!isSafeToConvertCharList(encodedString)) {
    859865        ec = INVALID_CHARACTER_ERR;
  • trunk/WebCore/page/DOMWindow.idl

    r55635 r55637  
    205205
    206206        // Base64
    207         [Custom] DOMString atob(in DOMString string)
     207        DOMString atob(in [ConvertNullToNullString] DOMString string)
    208208            raises(DOMException);
    209         [Custom] DOMString btoa(in DOMString string)
     209        DOMString btoa(in [ConvertNullToNullString] DOMString string)
    210210            raises(DOMException);
    211211
Note: See TracChangeset for help on using the changeset viewer.