| OLD | NEW |
| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 StringBuffer Utils::StringBufferFromV8String(v8::Isolate* isolate, const v8::Loc
al<v8::Value>& value) | 44 StringBuffer Utils::StringBufferFromV8String(v8::Isolate* isolate, const v8::Loc
al<v8::Value>& value) |
| 45 { | 45 { |
| 46 v8::String::Utf8Value stringValue(isolate, value); | 46 v8::String::Utf8Value stringValue(isolate, value); |
| 47 if (stringValue.length()) | 47 if (stringValue.length()) |
| 48 return IFileSystem::IOBuffer(*stringValue, *stringValue + stringValue.length
()); | 48 return IFileSystem::IOBuffer(*stringValue, *stringValue + stringValue.length
()); |
| 49 else | 49 else |
| 50 return IFileSystem::IOBuffer(); | 50 return IFileSystem::IOBuffer(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 v8::Local<v8::String> Utils::ToV8String(v8::Isolate* isolate, const std::string&
str) | 53 v8::MaybeLocal<v8::String> Utils::ToV8String(v8::Isolate* isolate, const std::st
ring& str) |
| 54 { | 54 { |
| 55 return v8::String::NewFromUtf8(isolate, str.c_str(), | 55 return v8::String::NewFromUtf8(isolate, str.c_str(), |
| 56 v8::String::NewStringType::kNormalString, str.length()); | 56 v8::NewStringType::kNormal, str.length()); |
| 57 } | 57 } |
| 58 | 58 |
| 59 v8::Local<v8::String> Utils::StringBufferToV8String(v8::Isolate* isolate, const
StringBuffer& str) | 59 v8::MaybeLocal<v8::String> Utils::StringBufferToV8String(v8::Isolate* isolate, c
onst StringBuffer& str) |
| 60 { | 60 { |
| 61 return v8::String::NewFromUtf8(isolate, | 61 return v8::String::NewFromUtf8(isolate, |
| 62 reinterpret_cast<const char*>(str.data()), | 62 reinterpret_cast<const char*>(str.data()), |
| 63 v8::String::NewStringType::kNormalString, str.size()); | 63 v8::NewStringType::kNormal, str.size()); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void Utils::ThrowExceptionInJS(v8::Isolate* isolate, const std::string& str) | 66 void Utils::ThrowExceptionInJS(v8::Isolate* isolate, const std::string& str) |
| 67 { | 67 { |
| 68 isolate->ThrowException(Utils::ToV8String(isolate, str)); | 68 auto maybe = Utils::ToV8String(isolate, str); |
| 69 if (maybe.IsEmpty()) |
| 70 { |
| 71 isolate->ThrowException( |
| 72 Utils::ToV8String(isolate, "Unknown Exception").ToLocalChecked()); |
| 73 } |
| 74 else |
| 75 isolate->ThrowException(maybe.ToLocalChecked()); |
| 69 } | 76 } |
| 70 | 77 |
| 71 #ifdef _WIN32 | 78 #ifdef _WIN32 |
| 72 std::wstring Utils::ToUtf16String(const std::string& str) | 79 std::wstring Utils::ToUtf16String(const std::string& str) |
| 73 { | 80 { |
| 74 size_t length = str.size(); | 81 size_t length = str.size(); |
| 75 if (length == 0) | 82 if (length == 0) |
| 76 return std::wstring(); | 83 return std::wstring(); |
| 77 | 84 |
| 78 DWORD utf16StringLength = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), length,
NULL, 0); | 85 DWORD utf16StringLength = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), length,
NULL, 0); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 if (FAILED(hr)) | 122 if (FAILED(hr)) |
| 116 { | 123 { |
| 117 throw std::runtime_error("CanonizeUrl failed\n"); | 124 throw std::runtime_error("CanonizeUrl failed\n"); |
| 118 } | 125 } |
| 119 } | 126 } |
| 120 return canonizedUrl; | 127 return canonizedUrl; |
| 121 | 128 |
| 122 } | 129 } |
| 123 #endif | 130 #endif |
| 124 | 131 |
| OLD | NEW |