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

Side by Side Diff: src/Utils.h

Issue 29812649: Issue 6526 - *ToV8String() return MaybeLocal<> and check Call() return value (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Created June 21, 2018, 11:17 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 if (value.IsEmpty()) 49 if (value.IsEmpty())
50 throw AdblockPlus::JsError("Empty value at ", filename, line); 50 throw AdblockPlus::JsError("Empty value at ", filename, line);
51 return value.ToLocalChecked(); 51 return value.ToLocalChecked();
52 } 52 }
53 53
54 #define CHECKED_TO_LOCAL(isolate, value, tryCatch) \ 54 #define CHECKED_TO_LOCAL(isolate, value, tryCatch) \
55 AdblockPlus::Utils::CheckedToLocal(isolate, value, tryCatch, __FILE__, __LIN E__) 55 AdblockPlus::Utils::CheckedToLocal(isolate, value, tryCatch, __FILE__, __LIN E__)
56 56
57 std::string FromV8String(v8::Isolate* isolate, const v8::Local<v8::Value>& v alue); 57 std::string FromV8String(v8::Isolate* isolate, const v8::Local<v8::Value>& v alue);
58 StringBuffer StringBufferFromV8String(v8::Isolate* isolate, const v8::Local< v8::Value>& value); 58 StringBuffer StringBufferFromV8String(v8::Isolate* isolate, const v8::Local< v8::Value>& value);
59 v8::Local<v8::String> ToV8String(v8::Isolate* isolate, const std::string& st r); 59 v8::MaybeLocal<v8::String> ToV8String(v8::Isolate* isolate, const std::strin g& str);
60 v8::Local<v8::String> StringBufferToV8String(v8::Isolate* isolate, const Str ingBuffer& bytes); 60 v8::MaybeLocal<v8::String> StringBufferToV8String(v8::Isolate* isolate, cons t StringBuffer& bytes);
61 void ThrowExceptionInJS(v8::Isolate* isolate, const std::string& str); 61 void ThrowExceptionInJS(v8::Isolate* isolate, const std::string& str);
62 62
63 // Code for templated function has to be in a header file, can't be in .cpp 63 // Code for templated function has to be in a header file, can't be in .cpp
64 template<class T> 64 template<class T>
65 T TrimString(const T& text) 65 T TrimString(const T& text)
66 { 66 {
67 // Via http://stackoverflow.com/questions/216823/whats-the-best-way-to-tri m-stdstring 67 // Via http://stackoverflow.com/questions/216823/whats-the-best-way-to-tri m-stdstring
68 T trimmed(text); 68 T trimmed(text);
69 trimmed.erase(trimmed.begin(), std::find_if(trimmed.begin(), trimmed.end() , std::not1(std::ptr_fun<int, int>(std::isspace)))); 69 trimmed.erase(trimmed.begin(), std::find_if(trimmed.begin(), trimmed.end() , std::not1(std::ptr_fun<int, int>(std::isspace))));
70 trimmed.erase(std::find_if(trimmed.rbegin(), trimmed.rend(), std::not1(std ::ptr_fun<int, int>(std::isspace))).base(), trimmed.end()); 70 trimmed.erase(std::find_if(trimmed.rbegin(), trimmed.rend(), std::not1(std ::ptr_fun<int, int>(std::isspace))).base(), trimmed.end());
71 return trimmed; 71 return trimmed;
72 } 72 }
73 #ifdef _WIN32 73 #ifdef _WIN32
74 std::wstring ToUtf16String(const std::string& str); 74 std::wstring ToUtf16String(const std::string& str);
75 std::string ToUtf8String(const std::wstring& str); 75 std::string ToUtf8String(const std::wstring& str);
76 std::wstring CanonizeUrl(const std::wstring& url); 76 std::wstring CanonizeUrl(const std::wstring& url);
77 #endif 77 #endif
78 } 78 }
79 } 79 }
80 80
81 #endif 81 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld