Changeset 55619 in webkit


Ignore:
Timestamp:
Mar 6, 2010 5:03:52 AM (14 years ago)
Author:
eric@webkit.org
Message:

2010-03-06 MORITA Hajime <morrita@google.com>

Reviewed by Darin Adler.

Moved implementations of window.btoa() and window.atob() from
JSDOMWindow to DOMWindow, and make V8DOMWindow use DOMWindow
functions instead of having a separate implementation. As a side effect, the
error message has changed from "Cannot decode base64" to one that
indicates DOM Exception, which is compatible to Firefox.

Refactoring: window.btoa() and window.atob() should be implemented on DOMWindow
https://bugs.webkit.org/show_bug.cgi?id=35723

  • fast/dom/Window/atob-btoa-expected.txt: Rebaselined expectation due to change of error message.

2010-03-06 MORITA Hajime <morrita@google.com>

Reviewed by Darin Adler.

Moved implementations of window.btoa() and window.atob() from
JSDOMWindow to DOMWindow, and make V8DOMWindow use DOMWindow
functions instead of having a separate implementation. As a side effect, the
error message has changed from "Cannot decode base64" to one that
indicates DOM Exception, which is compatible to Firefox.

Refactoring: window.btoa() and window.atob() should be implemented on DOMWindow
https://bugs.webkit.org/show_bug.cgi?id=35723

No new test. No new functionality.

  • bindings/js/JSDOMWindowCustom.cpp: (WebCore::JSDOMWindow::atob): (WebCore::JSDOMWindow::btoa): Moved conversion code to DOMWindow and invoke it. Argument checking remains here.
  • bindings/v8/custom/V8DOMWindowCustom.cpp: (WebCore::V8DOMWindow::atobCallback): (WebCore::V8DOMWindow::btoaCallback): Remove conversion code and call DOMWindow APIs. Although argument checking remains here.
  • page/DOMWindow.cpp: (WebCore::hasMultibyteCharacters): (WebCore::DOMWindow::btoa): (WebCore::DOMWindow::atob):
  • page/DOMWindow.h: Moved Conversion code from JSDOMWindow, modifing to fit JSC independent.
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r55616 r55619  
     12010-03-06  MORITA Hajime  <morrita@google.com>
     2       
     3        Reviewed by Darin Adler.
     4
     5        Moved implementations of window.btoa() and window.atob() from
     6        JSDOMWindow to DOMWindow, and make V8DOMWindow use DOMWindow
     7        functions instead of having a separate implementation. As a side effect, the
     8        error message has changed from "Cannot decode base64" to one that
     9        indicates DOM Exception, which is compatible to Firefox.
     10       
     11        Refactoring: window.btoa() and window.atob() should be implemented on DOMWindow
     12        https://bugs.webkit.org/show_bug.cgi?id=35723
     13
     14        * fast/dom/Window/atob-btoa-expected.txt:
     15          Rebaselined expectation due to change of error message.
     16       
    1172010-03-06  Shu Chang  <Chang.Shu@nokia.com>
    218
  • trunk/LayoutTests/fast/dom/Window/atob-btoa-expected.txt

    r21931 r55619  
    2525PASS window.atob("") is ""
    2626PASS window.atob(null) is ""
    27 PASS window.atob(" YQ==") threw exception Error: Cannot decode base64.
    28 PASS window.atob("YQ==\u000a") threw exception Error: Cannot decode base64.
     27PASS window.atob(" YQ==") threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5.
     28PASS window.atob("YQ==\u000a") threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5.
    2929PASS window.atob("6ek=") is "éé"
    3030PASS window.atob("6ek") is "éé"
    3131PASS window.atob("gIE=") is "€"
    3232PASS window.atob("тест") threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5.
    33 PASS window.atob("z") threw exception Error: Cannot decode base64.
     33PASS window.atob("z") threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5.
    3434PASS window.atob("zz") is "Ï"
    3535PASS window.atob("zzz") is "Ï<"
    3636PASS window.atob("zzzz") is "Ï<ó"
    37 PASS window.atob("zzzzz") threw exception Error: Cannot decode base64.
    38 PASS window.atob("=") threw exception Error: Cannot decode base64.
    39 PASS window.atob("==") threw exception Error: Cannot decode base64.
    40 PASS window.atob("===") threw exception Error: Cannot decode base64.
    41 PASS window.atob("====") threw exception Error: Cannot decode base64.
    42 PASS window.atob("=====") threw exception Error: Cannot decode base64.
     37PASS window.atob("zzzzz") threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5.
     38PASS window.atob("=") threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5.
     39PASS window.atob("==") threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5.
     40PASS window.atob("===") threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5.
     41PASS window.atob("====") threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5.
     42PASS window.atob("=====") threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5.
    4343PASS window.atob is 0
    4444PASS typeof window.atob is "number"
  • trunk/WebCore/ChangeLog

    r55617 r55619  
     12010-03-06  MORITA Hajime  <morrita@google.com>
     2
     3        Reviewed by Darin Adler.
     4
     5        Moved implementations of window.btoa() and window.atob() from
     6        JSDOMWindow to DOMWindow, and make V8DOMWindow use DOMWindow
     7        functions instead of having a separate implementation. As a side effect, the
     8        error message has changed from "Cannot decode base64" to one that
     9        indicates DOM Exception, which is compatible to Firefox.
     10       
     11        Refactoring: window.btoa() and window.atob() should be implemented on DOMWindow
     12        https://bugs.webkit.org/show_bug.cgi?id=35723
     13
     14        No new test. No new functionality.
     15
     16        * bindings/js/JSDOMWindowCustom.cpp:
     17        (WebCore::JSDOMWindow::atob):
     18        (WebCore::JSDOMWindow::btoa):
     19        Moved conversion code to DOMWindow and invoke it. Argument
     20        checking remains here.
     21       
     22        * bindings/v8/custom/V8DOMWindowCustom.cpp:
     23        (WebCore::V8DOMWindow::atobCallback):
     24        (WebCore::V8DOMWindow::btoaCallback):
     25        Remove conversion code and call DOMWindow APIs. Although argument
     26        checking remains here.
     27       
     28        * page/DOMWindow.cpp:
     29        (WebCore::hasMultibyteCharacters):
     30        (WebCore::DOMWindow::btoa):
     31        (WebCore::DOMWindow::atob):
     32        * page/DOMWindow.h:
     33        Moved Conversion code from JSDOMWindow, modifing to fit JSC independent.
     34
    1352010-03-06  Yuta Kitamura  <yutak@chromium.org>
    236
  • trunk/WebCore/bindings/js/JSDOMWindowCustom.cpp

    r55598 r55619  
    2222
    2323#include "AtomicString.h"
    24 #include "Base64.h"
    2524#include "Chrome.h"
    2625#include "Database.h"
     
    946945    if (args.size() < 1)
    947946        return throwError(exec, SyntaxError, "Not enough arguments");
    948 
    949     JSValue v = args.at(0);
    950     if (v.isNull())
     947    if (args.at(0).isNull())
    951948        return jsEmptyString(exec);
    952949
    953     UString s = v.toString(exec);
    954     if (!s.is8Bit()) {
    955         setDOMException(exec, INVALID_CHARACTER_ERR);
    956         return jsUndefined();
    957     }
    958 
    959     Vector<char> in(s.size());
    960     for (unsigned i = 0; i < s.size(); ++i)
    961         in[i] = static_cast<char>(s.data()[i]);
    962     Vector<char> out;
    963 
    964     if (!base64Decode(in, out))
    965         return throwError(exec, GeneralError, "Cannot decode base64");
    966 
    967     return jsString(exec, String(out.data(), out.size()));
     950    ExceptionCode ec = 0;
     951    String result = impl()->atob(args.at(0).toString(exec), ec);
     952    setDOMException(exec, ec);
     953
     954    return jsString(exec, result);
    968955}
    969956
     
    972959    if (args.size() < 1)
    973960        return throwError(exec, SyntaxError, "Not enough arguments");
    974 
    975     JSValue v = args.at(0);
    976     if (v.isNull())
     961    if (args.at(0).isNull())
    977962        return jsEmptyString(exec);
    978963
    979     UString s = v.toString(exec);
    980     if (!s.is8Bit()) {
    981         setDOMException(exec, INVALID_CHARACTER_ERR);
    982         return jsUndefined();
    983     }
    984 
    985     Vector<char> in(s.size());
    986     for (unsigned i = 0; i < s.size(); ++i)
    987         in[i] = static_cast<char>(s.data()[i]);
    988     Vector<char> out;
    989 
    990     base64Encode(in, out);
    991 
    992     return jsString(exec, String(out.data(), out.size()));
     964    ExceptionCode ec = 0;
     965    String result = impl()->btoa(args.at(0).toString(exec), ec);
     966    setDOMException(exec, ec);
     967
     968    return jsString(exec, result);
    993969}
    994970
  • trunk/WebCore/bindings/v8/custom/V8DOMWindowCustom.cpp

    r55593 r55619  
    3232#include "V8DOMWindow.h"
    3333
    34 #include "Base64.h"
    3534#include "Chrome.h"
    3635#include "Database.h"
     
    149148}
    150149
    151 static bool isAscii(const String& str)
    152 {
    153     for (size_t i = 0; i < str.length(); i++) {
    154         if (str[i] > 0xFF)
    155             return false;
    156     }
    157     return true;
    158 }
    159 
    160 static v8::Handle<v8::Value> convertBase64(const String& str, bool encode)
    161 {
    162     if (!isAscii(str)) {
    163         V8Proxy::setDOMException(INVALID_CHARACTER_ERR);
    164         return notHandledByInterceptor();
    165     }
    166 
    167     Vector<char> inputCharacters(str.length());
    168     for (size_t i = 0; i < str.length(); i++)
    169         inputCharacters[i] = static_cast<char>(str[i]);
    170     Vector<char> outputCharacters;
    171 
    172     if (encode)
    173         base64Encode(inputCharacters, outputCharacters);
    174     else {
    175         if (!base64Decode(inputCharacters, outputCharacters))
    176             return throwError("Cannot decode base64", V8Proxy::GeneralError);
    177     }
    178 
    179     return v8String(String(outputCharacters.data(), outputCharacters.size()));
    180 }
    181 
    182150v8::Handle<v8::Value> V8DOMWindow::eventAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
    183151{
     
    379347    INC_STATS("DOM.DOMWindow.atob()");
    380348
     349    if (args.Length() < 1)
     350        return throwError("Not enough arguments", V8Proxy::SyntaxError);
    381351    if (args[0]->IsNull())
    382352        return v8String("");
    383     String str = toWebCoreString(args[0]);
    384353
    385354    DOMWindow* imp = V8DOMWindow::toNative(args.Holder());
    386 
    387     if (!V8BindingSecurity::canAccessFrame(V8BindingState::Only(), imp->frame(), true))
    388         return v8::Undefined();
     355    ExceptionCode ec = 0;
     356    String result = imp->atob(toWebCoreString(args[0]), ec);
     357    throwError(ec);
     358
     359    return v8String(result);
     360}
     361
     362v8::Handle<v8::Value> V8DOMWindow::btoaCallback(const v8::Arguments& args)
     363{
     364    INC_STATS("DOM.DOMWindow.btoa()");
    389365
    390366    if (args.Length() < 1)
    391367        return throwError("Not enough arguments", V8Proxy::SyntaxError);
    392 
    393     return convertBase64(str, false);
    394 }
    395 
    396 v8::Handle<v8::Value> V8DOMWindow::btoaCallback(const v8::Arguments& args)
    397 {
    398     INC_STATS("DOM.DOMWindow.btoa()");
    399 
    400368    if (args[0]->IsNull())
    401369        return v8String("");
    402     String str = toWebCoreString(args[0]);
    403370
    404371    DOMWindow* imp = V8DOMWindow::toNative(args.Holder());
    405 
    406     if (!V8BindingSecurity::canAccessFrame(V8BindingState::Only(), imp->frame(), true))
    407         return v8::Undefined();
    408 
    409     if (args.Length() < 1)
    410         return throwError("Not enough arguments", V8Proxy::SyntaxError);
    411 
    412     return convertBase64(str, true);
     372    ExceptionCode ec = 0;
     373    String result = imp->btoa(toWebCoreString(args[0]), ec);
     374    throwError(ec);
     375
     376    return v8String(result);
    413377}
    414378
  • trunk/WebCore/page/DOMWindow.cpp

    r55593 r55619  
    2727#include "DOMWindow.h"
    2828
     29#include "Base64.h"
    2930#include "BarInfo.h"
    3031#include "BeforeUnloadEvent.h"
     
    828829}
    829830
     831static bool isSafeToConvertCharList(const String& string)
     832{
     833    for (unsigned i = 0; i < string.length(); i++) {
     834        if (string[i] > 0xFF)
     835            return false;
     836    }
     837
     838    return true;
     839}
     840
     841String DOMWindow::btoa(const String& stringToEncode, ExceptionCode& ec)
     842{
     843    if (!isSafeToConvertCharList(stringToEncode)) {
     844        ec = INVALID_CHARACTER_ERR;
     845        return String();
     846    }
     847
     848    Vector<char> in;
     849    in.append(stringToEncode.characters(), stringToEncode.length());
     850    Vector<char> out;
     851
     852    base64Encode(in, out);
     853
     854    return String(out.data(), out.size());
     855}
     856
     857String DOMWindow::atob(const String& encodedString, ExceptionCode& ec)
     858{
     859    if (!isSafeToConvertCharList(encodedString)) {
     860        ec = INVALID_CHARACTER_ERR;
     861        return String();
     862    }
     863
     864    Vector<char> in;
     865    in.append(encodedString.characters(), encodedString.length());
     866    Vector<char> out;
     867
     868    if (!base64Decode(in, out)) {
     869        ec = INVALID_CHARACTER_ERR;
     870        return String();
     871    }
     872
     873    return String(out.data(), out.size());
     874}
     875
    830876bool DOMWindow::find(const String& string, bool caseSensitive, bool backwards, bool wrap, bool /*wholeWord*/, bool /*searchInFrames*/, bool /*showDialog*/) const
    831877{
  • trunk/WebCore/page/DOMWindow.h

    r55593 r55619  
    141141        bool confirm(const String& message);
    142142        String prompt(const String& message, const String& defaultValue);
     143        String btoa(const String& stringToEncode, ExceptionCode&);
     144        String atob(const String& encodedString, ExceptionCode&);
    143145
    144146        bool find(const String&, bool caseSensitive, bool backwards, bool wrap, bool wholeWord, bool searchInFrames, bool showDialog) const;
Note: See TracChangeset for help on using the changeset viewer.