Changeset 55619 in webkit
- Timestamp:
- Mar 6, 2010 5:03:52 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r55616 r55619 1 2010-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 1 17 2010-03-06 Shu Chang <Chang.Shu@nokia.com> 2 18 -
trunk/LayoutTests/fast/dom/Window/atob-btoa-expected.txt
r21931 r55619 25 25 PASS window.atob("") is "" 26 26 PASS 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.27 PASS window.atob(" YQ==") threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5. 28 PASS window.atob("YQ==\u000a") threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5. 29 29 PASS window.atob("6ek=") is "éé" 30 30 PASS window.atob("6ek") is "éé" 31 31 PASS window.atob("gIE=") is "" 32 32 PASS window.atob("тест") threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5. 33 PASS window.atob("z") threw exception Error: Cannot decode base64.33 PASS window.atob("z") threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5. 34 34 PASS window.atob("zz") is "Ï" 35 35 PASS window.atob("zzz") is "Ï<" 36 36 PASS 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.37 PASS window.atob("zzzzz") threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5. 38 PASS window.atob("=") threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5. 39 PASS window.atob("==") threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5. 40 PASS window.atob("===") threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5. 41 PASS window.atob("====") threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5. 42 PASS window.atob("=====") threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5. 43 43 PASS window.atob is 0 44 44 PASS typeof window.atob is "number" -
trunk/WebCore/ChangeLog
r55617 r55619 1 2010-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 1 35 2010-03-06 Yuta Kitamura <yutak@chromium.org> 2 36 -
trunk/WebCore/bindings/js/JSDOMWindowCustom.cpp
r55598 r55619 22 22 23 23 #include "AtomicString.h" 24 #include "Base64.h"25 24 #include "Chrome.h" 26 25 #include "Database.h" … … 946 945 if (args.size() < 1) 947 946 return throwError(exec, SyntaxError, "Not enough arguments"); 948 949 JSValue v = args.at(0); 950 if (v.isNull()) 947 if (args.at(0).isNull()) 951 948 return jsEmptyString(exec); 952 949 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); 968 955 } 969 956 … … 972 959 if (args.size() < 1) 973 960 return throwError(exec, SyntaxError, "Not enough arguments"); 974 975 JSValue v = args.at(0); 976 if (v.isNull()) 961 if (args.at(0).isNull()) 977 962 return jsEmptyString(exec); 978 963 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); 993 969 } 994 970 -
trunk/WebCore/bindings/v8/custom/V8DOMWindowCustom.cpp
r55593 r55619 32 32 #include "V8DOMWindow.h" 33 33 34 #include "Base64.h"35 34 #include "Chrome.h" 36 35 #include "Database.h" … … 149 148 } 150 149 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 182 150 v8::Handle<v8::Value> V8DOMWindow::eventAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) 183 151 { … … 379 347 INC_STATS("DOM.DOMWindow.atob()"); 380 348 349 if (args.Length() < 1) 350 return throwError("Not enough arguments", V8Proxy::SyntaxError); 381 351 if (args[0]->IsNull()) 382 352 return v8String(""); 383 String str = toWebCoreString(args[0]);384 353 385 354 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 362 v8::Handle<v8::Value> V8DOMWindow::btoaCallback(const v8::Arguments& args) 363 { 364 INC_STATS("DOM.DOMWindow.btoa()"); 389 365 390 366 if (args.Length() < 1) 391 367 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 400 368 if (args[0]->IsNull()) 401 369 return v8String(""); 402 String str = toWebCoreString(args[0]);403 370 404 371 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); 413 377 } 414 378 -
trunk/WebCore/page/DOMWindow.cpp
r55593 r55619 27 27 #include "DOMWindow.h" 28 28 29 #include "Base64.h" 29 30 #include "BarInfo.h" 30 31 #include "BeforeUnloadEvent.h" … … 828 829 } 829 830 831 static 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 841 String 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 857 String 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 830 876 bool DOMWindow::find(const String& string, bool caseSensitive, bool backwards, bool wrap, bool /*wholeWord*/, bool /*searchInFrames*/, bool /*showDialog*/) const 831 877 { -
trunk/WebCore/page/DOMWindow.h
r55593 r55619 141 141 bool confirm(const String& message); 142 142 String prompt(const String& message, const String& defaultValue); 143 String btoa(const String& stringToEncode, ExceptionCode&); 144 String atob(const String& encodedString, ExceptionCode&); 143 145 144 146 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.