Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: src/Utils.h

Issue 29812649: Issue 6526 - *ToV8String() return MaybeLocal<> and check Call() return value (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Left Patch Set: Introduce CHECKED_TO_LOCAL_NOTHROW and use it. Created June 22, 2018, 3:49 p.m.
Right Patch Set: Wrap macro arguments in brackets. Created Aug. 6, 2018, 1:25 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/JsValue.cpp ('k') | src/Utils.cpp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 v8::MaybeLocal<T>&& value, const v8::TryCatch* tryCatch, 45 v8::MaybeLocal<T>&& value, const v8::TryCatch* tryCatch,
46 const char* filename, int line) 46 const char* filename, int line)
47 { 47 {
48 if (tryCatch) 48 if (tryCatch)
49 CheckTryCatch(isolate, *tryCatch); 49 CheckTryCatch(isolate, *tryCatch);
50 if (value.IsEmpty()) 50 if (value.IsEmpty())
51 throw AdblockPlus::JsError("Empty value at ", filename, line); 51 throw AdblockPlus::JsError("Empty value at ", filename, line);
52 return value.ToLocalChecked(); 52 return value.ToLocalChecked();
53 } 53 }
54 54
55 #define CHECKED_TO_LOCAL(isolate, value, tryCatch) \ 55 #define CHECKED_TO_LOCAL_WITH_TRY_CATCH(isolate, value, tryCatch) \
56 AdblockPlus::Utils::CheckedToLocal(isolate, value, &tryCatch, __FILE__, __LI NE__) 56 AdblockPlus::Utils::CheckedToLocal((isolate), (value), &(tryCatch), __FILE__ , __LINE__)
57 57
58 #define CHECKED_TO_LOCAL_NOTHROW(isolate, value) \ 58 #define CHECKED_TO_LOCAL(isolate, value) \
sergei 2018/07/05 08:39:00 What about adding something like NOTRYCATCH instea
hub 2018/07/11 02:11:02 Done.
59 AdblockPlus::Utils::CheckedToLocal(isolate, value, nullptr, __FILE__, __LINE __) 59 AdblockPlus::Utils::CheckedToLocal((isolate), (value), nullptr, __FILE__, __ LINE__)
60 60
61 std::string FromV8String(v8::Isolate* isolate, const v8::Local<v8::Value>& v alue); 61 std::string FromV8String(v8::Isolate* isolate, const v8::Local<v8::Value>& v alue);
62 StringBuffer StringBufferFromV8String(v8::Isolate* isolate, const v8::Local< v8::Value>& value); 62 StringBuffer StringBufferFromV8String(v8::Isolate* isolate, const v8::Local< v8::Value>& value);
63 v8::MaybeLocal<v8::String> ToV8String(v8::Isolate* isolate, const std::strin g& str); 63 v8::MaybeLocal<v8::String> ToV8String(v8::Isolate* isolate, const std::strin g& str);
64 v8::MaybeLocal<v8::String> StringBufferToV8String(v8::Isolate* isolate, cons t StringBuffer& bytes); 64 v8::MaybeLocal<v8::String> StringBufferToV8String(v8::Isolate* isolate, cons t StringBuffer& bytes);
65 void ThrowExceptionInJS(v8::Isolate* isolate, const std::string& str); 65 void ThrowExceptionInJS(v8::Isolate* isolate, const std::string& str);
66 66
67 // Code for templated function has to be in a header file, can't be in .cpp 67 // Code for templated function has to be in a header file, can't be in .cpp
68 template<class T> 68 template<class T>
69 T TrimString(const T& text) 69 T TrimString(const T& text)
70 { 70 {
71 // Via http://stackoverflow.com/questions/216823/whats-the-best-way-to-tri m-stdstring 71 // Via http://stackoverflow.com/questions/216823/whats-the-best-way-to-tri m-stdstring
72 T trimmed(text); 72 T trimmed(text);
73 trimmed.erase(trimmed.begin(), std::find_if(trimmed.begin(), trimmed.end() , std::not1(std::ptr_fun<int, int>(std::isspace)))); 73 trimmed.erase(trimmed.begin(), std::find_if(trimmed.begin(), trimmed.end() , std::not1(std::ptr_fun<int, int>(std::isspace))));
74 trimmed.erase(std::find_if(trimmed.rbegin(), trimmed.rend(), std::not1(std ::ptr_fun<int, int>(std::isspace))).base(), trimmed.end()); 74 trimmed.erase(std::find_if(trimmed.rbegin(), trimmed.rend(), std::not1(std ::ptr_fun<int, int>(std::isspace))).base(), trimmed.end());
75 return trimmed; 75 return trimmed;
76 } 76 }
77 #ifdef _WIN32 77 #ifdef _WIN32
78 std::wstring ToUtf16String(const std::string& str); 78 std::wstring ToUtf16String(const std::string& str);
79 std::string ToUtf8String(const std::wstring& str); 79 std::string ToUtf8String(const std::wstring& str);
80 std::wstring CanonizeUrl(const std::wstring& url); 80 std::wstring CanonizeUrl(const std::wstring& url);
81 #endif 81 #endif
82 } 82 }
83 } 83 }
84 84
85 #endif 85 #endif
LEFTRIGHT

Powered by Google App Engine
This is Rietveld